1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-22 16:55:23 +01:00
deka-dom-el/dist/esm.js

2 lines
8.9 KiB
JavaScript
Raw Normal View History

var m={isObservable(t){return!1},processReactiveAttribute(t,e,n,c){return n}};function q(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 v(t){return typeof t>"u"}function y(t,e){if(!t||!(t instanceof AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}function L(t,e){let{observedAttributes:n=[]}=t.constructor;return n.reduce(function(c,r){return Reflect.set(c,F(r),e(t,r)),c},{})}function F(t){return t.replace(/-./g,e=>e[1].toUpperCase())}var R={setDeleteAttr:z,ssr:""};function z(t,e,n){if(Reflect.set(t,e,n),!!v(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 b=[{scope:document.body,host:t=>t?t(document.body):document.body,custom_element:!1,prevent:!0}],g={get current(){return b[b.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...b]},push(t={}){return b.push(Object.assign({},this.current,{prevent:!1},t))},pushRoot(){return b.push(b[0])},pop(){if(b.length!==1)return b.pop()}};function P(...t){return this.appendOriginal(...t),this}function B(t){return t.append===P||(t.appendOriginal=t.append,t.append=P),t}var w;function N(t,e,...n){let c=_(this),r=0,o,s;switch((Object(e)!==e||c.isObservable(e))&&(e={textContent:e}),!0){case typeof t=="function":{r=1,g.push({scope:t,host:(...l)=>l.length?(r===1?n.unshift(...l):l.forEach(p=>p(s)),void 0):s}),o=t(e||void 0);let a=o instanceof DocumentFragment;if(o.nodeName==="#comment")break;let d=N.mark({type:"component",name:t.name,host:a?"this":"parentElement"});o.prepend(d),a&&(s=d);break}case t==="#text":o=x.call(this,document.createTextNode(""),e);break;case(t==="<>"||!t):o=x.call(this,document.createDocumentFragment(),e);break;case!!w:o=x.call(this,document.createElementNS(w,t),e);break;case!o:o=x.call(this,document.createElement(t),e)}return B(o),s||(s=o),n.forEach(a=>a(s)),r&&g.pop(),r=2,o}function ct(t,e=t,n=void 0){let c=Symbol.for("default"),r=Array.from(e.querySelectorAll("slot")).reduce((s,a)=>Reflect.set(s,a.name||c,a)&&s,{}),o=Reflect.has(r,c);if(t.append=new Proxy(t.append,{apply(s,a,d){if(!d.length)return t;let l=document.createDocumentFragment();for(let p of d){if(!p||!p.slot){o&&l.appendChild(p);continue}let i=p.slot,u=r[i];Z(p,"remove","slot"),u&&(H(u,p,n),Reflect.deleteProperty(r,i))}return o&&(r[c].replaceWith(l),Reflect.deleteProperty(r,c)),t.append=s,t}}),t!==e){let s=Array.from(t.childNodes);s.forEach(a=>a.remove()),t.append(...s)}return e}function H(t,e,n){n&&n(t,e);try{t.replaceWith(x(e,{className:[e.className,t.className],dataset:{...t.dataset}}))}catch{t.replaceWith(e)}}N.mark=function(t,e=!1){t=Object.entries(t).map(([r,o])=>r+`="${o}"`).join(" ");let n=e?"":"/",c=document.createComment(`<dde:mark ${t}${R.ssr}${n}>`);return e||(c.end=document.createComment("</dde:mark>")),c};function st(t){let e=this;return function(...c){w=t;let r=N.call(e,...c);return w=void 0,r}}var{setDeleteAttr:W}=R,C=new WeakMap;function x(t,...e){if(!e.length)return t;C.set(t,M(t,this));for(let[n,c]of Object.entries(Object.assign({},...e)))T.call(this,t,n,c);return C.delete(t),t}function T(t,e,n){let{setRemoveAttr:c,s:r}=M(t,this),o=this;n=r.processReactiveAttribute(t,e,n,(a,d)=>T.call(o,t,a,d));let[s]=e;if(s==="=")return c(e.slice(1),n);if(s===".")return j(t,e.slice(1),n);if(/(aria|data)([A-Z])/.test(e))return e=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),c(e,n);switch(e==="className"&&(e="class"),e){case"xlink:href":return c(e,n,"http://www.w3.org/1999/xlink");case"textContent":return W(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return S(r,n,j.bind(null,t[e]));case"ariaset":return S(r,n,(a,d)=>c("aria-"+a,d));case"classList":return I.call(o,t,n)}return G(t,e)?W(t,e,n):c(e,n)}function M(t,e){if(C.has(t))return C.get(t);let c=(t instanceof SVGElement?J:V).bind(null,t,"Attribute"),r=_(e);return{setRemoveAttr