1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-22 07:49:38 +01:00
deka-dom-el/dist/dde.js

18 lines
6.9 KiB
JavaScript
Raw Normal View History

//deka-dom-el library is available via global namespace `dde`
(()=> {
2023-11-08 19:09:39 +01:00
var m={isSignal(t){return!1},processReactiveAttribute(t,e,n,o){return n}};function $(t,e=!0){return e?Object.assign(m,t):(Object.setPrototypeOf(t,m),t)}function _(t){return m.isPrototypeOf(t)&&t!==m?t:m}function g(t){return typeof t>"u"}function x(t,e){if(!t||!(t instanceof AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var L={setDeleteAttr:U};function U(t,e,n){if(Reflect.set(t,e,n),!!g(n)){if(Reflect.deleteProperty(t,e),t instanceof HTMLElement&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var v=[{scope:document.body,host:t=>t?t(document.body):document.body,prevent:!0,inherit_host:!1}],S={get current(){return v[v.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...v]},push(t={}){return v.push(Object.assign({},this.current,{prevent:!1},t))},pop(){return v.pop()}},A;function E(t,e,...n){let o=_(this),r=0,s,f;switch((Object(e)!==e||o.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{r=1;let{inherit_host:d,host:p}=S.current,l=d?p:c=>c?(r===1?n.unshift(c):c(f),void 0):f;S.push({scope:t,host:l,inherit_host:d}),s=t(e||void 0);let h=s instanceof DocumentFragment,i=E.mark({type:"component",name:t.name,host:h?"this":s.nodeName==="#comment"?"previousLater":"parentElement"});s.prepend(i),h&&(f=i);break}case t==="#text":s=w.call(this,document.createTextNode(""),e);break;case(t==="<>"||!t):s=w.call(this,document.createDocumentFragment(),e);break;case A:s=w.call(this,document.createElementNS(A,t),e);break;case!s:s=w.call(this,document.createElement(t),e)}return B(s),f||(f=s),n.forEach(d=>d(f)),r&&S.pop(),r=2,s}E.mark=function(t,e=!1){t=Object.entries(t).map(([r,s])=>r+`="${s}"`).join(" ");let n=e?"":"/",o=document.createComment(`<dde:mark ${t}${n}>`);return e||(o.end=document.createComment("</dde:mark>")),o};E.later=function(){let t=E.mark({type:"later"});return t.append=t.prepend=function(...e){return t.after(...e),t},t};function Q(t){let e=this;return function(...o){A=t;let r=E.call(e,...o);return A=void 0,r}}var{setDeleteAttr:N}=L,O=new WeakMap;function w(t,...e){if(!e.length)return t;O.set(t,T(t,this));for(let[n,o]of Object.entries(Object.assign({},...e)))P.call(this,t,n,o);return O.delete(t),t}function P(t,e,n){let{setRemoveAttr:o,s:r}=T(t,this),s=this;n=r.processReactiveAttribute(t,e,n,(d,p)=>P.call(s,t,d,p));let[f]=e;if(f==="=")return o(e.slice(1),n);if(f===".")return D(t,e.slice(1),n);if(/(aria|data)([A-Z])/.test(e))return e=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),o(e,n);switch(e==="className"&&(e="class"),e){case"xlink:href":return o(e,n,"http://www.w3.org/1999/xlink");case"textContent":return N(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return R(r,n,D.bind(null,t[e]));case"ariaset":return R(r,n,(d,p)=>o("aria-"+d,p));case"classList":return q.call(s,t,n)}return z(t,e)?N(t,e,n):o(e,n)}function T(t,e){if(O.has(t))return O.get(t);let o=(t instanceof SVGElement?k:F).bind(null,t,"Attribute"),r=_(e);return{setRemoveAttr:o,s:r}}function q(t,e){let n=_(this);return R(n,e,(o,r)=>t.classList.toggle(o,r===-1?void 0:!!r)),t}function Y(t){return Array.from(t.children).forEach(e=>e.remove()),t}function z(t,e){if(!Reflect.has(t,e))return!1;let n=W(t,e);return!g(n.set)}function W(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||W(t,e)}function R(t,e,n){if(!(typeof e!="object"||e===null))return Object.entries(e).forEach(function([r,s]){r&&(s=t.processReactiveAttribute(e,r,s,n),n(r,s))})}function M(t){return Array.isArray(t)?t.filter(Boolean).join(" "):t}function F(t,e,n,o){return t[(g(o)?"remove":"set")+e](n,M(o))}function k(t,e,n,o,r=null){return t[(g(o)?"remove":"set")+e+"NS"](r,n,M(o))}function D(t,e,n){if(Reflect.set(t,e,n),!!g(n))return Reflect.deleteProperty(t,e)}function j(...t){return this.appendOrig(...t),this}function B(t){return t.append===j||(t.appendOrig=t.append,t.append=j),t}function nt(t,e,...n){let o=n.length?
globalThis.dde= {assign: w,
assignAttribute: P,
classListDeclarative: q,
createElement: E,
createElementNS: Q,
dispatchEvent: nt,
el: E,
elNS: Q,
empty: Y,
2023-11-08 19:09:39 +01:00
on: y,
registerReactivity: $,
2023-11-08 19:09:39 +01:00
scope: S
};
})();