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

5 lines
13 KiB
JavaScript
Raw Normal View History

2024-01-31 14:41:18 +01:00
var D={isObservable(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function $(t,e=!0){return e?Object.assign(D,t):(Object.setPrototypeOf(t,D),t)}function P(t){return D.isPrototypeOf(t)&&t!==D?t:D}function w(t){return typeof t>"u"}function Z(t){let e=typeof t;return e!=="object"?e:t===null?"null":Object.prototype.toString.call(t)}function T(t,e){if(!t||!(t instanceof AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}function j(t,e){let{observedAttributes:n=[]}=t.constructor;return n.reduce(function(r,o){return Reflect.set(r,it(o),e(t,o)),r},{})}function it(t){return t.replace(/-./g,e=>e[1].toUpperCase())}var d={setDeleteAttr:ut,ssr:"",D:globalThis.document,F:globalThis.DocumentFragment,H:globalThis.HTMLElement,S:globalThis.SVGElement,M:globalThis.MutationObserver};function ut(t,e,n){if(Reflect.set(t,e,n),!!w(n)){if(Reflect.deleteProperty(t,e),t instanceof d.H&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var A="__dde_lifecycleToEvents";var x=[{get scope(){return d.D.body},host:t=>t?t(d.D.body):d.D.body,prevent:!0}],v={get current(){return x[x.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...x]},push(t={}){return x.push(Object.assign({},this.current,{prevent:!1},t))},pushRoot(){return x.push(x[0])},pop(){if(x.length!==1)return x.pop()}};function G(...t){return this.appendOriginal(...t),this}function ft(t){return t.append===G||(t.appendOriginal=t.append,t.append=G),t}var M;function L(t,e,...n){let r=P(this),o=0,c,s;switch((Object(e)!==e||r.isObservable(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1,v.push({scope:t,host:(...l)=>l.length?(o===1?n.unshift(...l):l.forEach(b=>b(s)),void 0):s}),c=t(e||void 0);let f=c instanceof d.F;if(c.nodeName==="#comment")break;let p=L.mark({type:"component",name:t.name,host:f?"this":"parentElement"});c.prepend(p),f&&(s=p);break}case t==="#text":c=k.call(this,d.D.createTextNode(""),e);break;case(t==="<>"||!t):c=k.call(this,d.D.createDocumentFragment(),e);break;case!!M:c=k.call(this,d.D.createElementNS(M,t),e);break;case!c:c=k.call(this,d.D.createElement(t),e)}return ft(c),s||(s=c),n.forEach(f=>f(s)),o&&v.pop(),o=2,c}function Lt(t,e=t,n=void 0){let r=Symbol.for("default"),o=Array.from(e.querySelectorAll("slot")).reduce((s,f)=>Reflect.set(s,f.name||r,f)&&s,{}),c=Reflect.has(o,r);if(t.append=new Proxy(t.append,{apply(s,f,p){if(!p.length)return t;let l=d.D.createDocumentFragment();for(let b of p){if(!b||!b.slot){c&&l.appendChild(b);continue}let R=b.slot,N=o[R];pt(b,"remove","slot"),N&&(at(N,b,n),Reflect.deleteProperty(o,R))}return c&&(o[r].replaceWith(l),Reflect.deleteProperty(o,r)),t.append=s,t}}),t!==e){let s=Array.from(t.childNodes);s.forEach(f=>f.remove()),t.append(...s)}return e}function at(t,e,n){n&&n(t,e);try{t.replaceWith(k(e,{className:[e.className,t.className],dataset:{...t.dataset}}))}catch{t.replaceWith(e)}}L.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=d.D.createComment(`<dde:mark ${t}${d.ssr}${n}>`);return e&&(r.end=d.D.createComment("</dde:mark>")),r};function Nt(t){let e=this;return function(...r){M=t;let o=L.call(e,...r);return M=void 0,o}}var W=new WeakMap,{setDeleteAttr:V}=d;function k(t,...e){if(!e.length)return t;W.set(t,X(t,this));for(let[n,r]of Object.entries(Object.assign({},...e)))Q.call(this,t,n,r);return W.delete(t),t}function Q(t,e,n){let{setRemoveAttr:r,s:o}=X(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(f,p)=>Q.call(c,t,f,p));let[s]=e;if(s==="=")return r(e.slice(1),n);if(s===".")return K(t,e.slice(1),n);if(/(aria|data)([A-Z])/.test(e))return e=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),r(e,n);switch(e==="className"&&(e="class"),e){case"xlink:href":return r(e,n,"http://www.w3.org/1999/xlink");case"textContent":return V(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return U(o,n,K.bind(null,t[e]));case"ariaset":return U(o,n,(f,p)=>r("aria-"+f,p));
* Investigate `__dde_attributes` key of the element.*/let[c,s]=o,f=this[B][c];if(f)return E.action(f,"_set",s)})(t),y.disconnected(function(){/*! This removes all observables mapped to attributes (`O.observedAttributes`).
* Investigate `__dde_attributes` key of the element.*/E.clear(...Object.values(this[B]))})(t),n};var rt={isObservable:q,processReactiveAttribute(t,e,n,r){if(!q(n))return n;let o=c=>{if(!t.isConnected)return C(n,o);r(e,c)};return J(n,o),ot(n,o,t,e),n()}};function ot(t,e,...n){let{current:r}=v;r.prevent||r.host(function(o){o[_]||(o[_]=[],y.disconnected(()=>o[_].forEach(([[c,s]])=>C(c,s,c[h]?.host()===o)))(o)),o[_].push([[t,e],...n])})}function et(t,e,n){let r=t?()=>nt(r):(...o)=>o.length?st(r,...o):nt(r);return ct(r,e,n)}var At=Object.assign(Object.create(null),{stopPropagation(){this.skip=!0}}),I=class extends Error{constructor(){super();let[e,...n]=this.stack.split(`
`),r=e.slice(e.indexOf("@"),e.indexOf(".js:")+4);this.stack=n.find(o=>!o.includes(r))}};function ct(t,e,n){let r=[];Z(n)!=="[object Object]"&&(n={});let{onclear:o}=E.symbols;n[o]&&(r.push(n[o]),Reflect.deleteProperty(n,o));let{host:c}=v;return Reflect.defineProperty(t,h,{value:{value:e,actions:n,onclear:r,host:c,listeners:new Set,defined:new I},enumerable:!1,writable:!1,configurable:!0}),t.toJSON=()=>t(),Object.setPrototypeOf(t[h],At),t}function Ot(){return F[F.length-1]}function nt(t){if(!t[h])return;let{value:e,listeners:n}=t[h],r=Ot();return r&&n.add(r),g.has(r)&&g.get(r).add(t),e}function st(t,e,n){if(!t[h])return;let r=t[h];if(!(!n&&r.value===e))return r.value=e,r.listeners.forEach(o=>o(e)),e}function J(t,e){if(t[h])return t[h].listeners.add(e)}function C(t,e,n){let r=t[h];if(!r)return;let o=r.listeners.delete(e);if(n&&!r.listeners.size){if(E.clear(t),!g.has(r))return o;let c=g.get(r);if(!g.has(c))return o;g.get(c).forEach(s=>C(s,c,!0))}return o}$(rt);export{E as O,k as assign,Q as assignAttribute,ft as chainableAppend,dt as classListDeclarative,L as createElement,Nt as createElementNS,Ut as customElementRender,gt as customElementWithDDE,It as dispatchEvent,L as el,Nt as elNS,pt as elementAttribute,Pt as empty,q as isObservable,gt as lifecycleToEvents,E as observable,Et as observedAttributes,y as on,$ as registerReactivity,v as scope,Lt as simulateSlots};