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-with-signals.js

5 lines
11 KiB
JavaScript
Raw Normal View History

var y={isSignal(t){return!1},processReactiveAttribute(t,e,n,o){return n}};function M(t,e=!0){return e?Object.assign(y,t):(Object.setPrototypeOf(t,y),t)}function R(t){return y.isPrototypeOf(t)&&t!==y?t:y}function _(t){return typeof t>"u"}function F(t){let e=typeof t;return e!=="object"?e:t===null?"null":Object.prototype.toString.call(t)}function C(t,e){if(!t||!(t instanceof AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var U={setDeleteAttr:X};function X(t,e,n){if(Reflect.set(t,e,n),!!_(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 w=[{scope:document.body,host:t=>t?t(document.body):document.body,prevent:!0}],E={get current(){return w[w.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...w]},push(t={}){return w.push(Object.assign({},this.current,{prevent:!1},t))},pop(){return w.pop()}},L;function v(t,e,...n){let o=R(this),r=0,c,s;switch((Object(e)!==e||o.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{r=1,E.push({scope:t,host:l=>l?(r===1?n.unshift(l):l(s),void 0):s}),c=t(e||void 0);let a=c instanceof DocumentFragment,d=v.mark({type:"component",name:t.name,host:a?"this":c.nodeName==="#comment"?"previousLater":"parentElement"});c.prepend(d),a&&(s=d);break}case t==="#text":c=N.call(this,document.createTextNode(""),e);break;case(t==="<>"||!t):c=N.call(this,document.createDocumentFragment(),e);break;case L:c=N.call(this,document.createElementNS(L,t),e);break;case!c:c=N.call(this,document.createElement(t),e)}return rt(c),s||(s=c),n.forEach(a=>a(s)),r&&E.pop(),r=2,c}v.mark=function(t,e=!1){t=Object.entries(t).map(([r,c])=>r+`="${c}"`).join(" ");let n=e?"":"/",o=document.createComment(`<dde:mark ${t}${n}>`);return e||(o.end=document.createComment("</dde:mark>")),o};v.later=function(){let t=v.mark({type:"later"});return t.append=t.prepend=function(...e){return t.after(...e),t},t};function bt(t){let e=this;return function(...o){L=t;let r=v.call(e,...o);return L=void 0,r}}var{setDeleteAttr:q}=U,j=new WeakMap;function N(t,...e){if(!e.length)return t;j.set(t,J(t,this));for(let[n,o]of Object.entries(Object.assign({},...e)))I.call(this,t,n,o);return j.delete(t),t}function I(t,e,n){let{setRemoveAttr:o,s:r}=J(t,this),c=this;n=r.processReactiveAttribute(t,e,n,(a,d)=>I.call(c,t,a,d));let[s]=e;if(s==="=")return o(e.slice(1),n);if(s===".")return H(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 q(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return W(r,n,H.bind(null,t[e]));case"ariaset":return W(r,n,(a,d)=>o("aria-"+a,d));case"classList":return Y.call(c,t,n)}return tt(t,e)?q(t,e,n):o(e,n)}function J(t,e){if(j.has(t))return j.get(t);let o=(t instanceof SVGElement?nt:et).bind(null,t,"Attribute"),r=R(e);return{setRemoveAttr:o,s:r}}function Y(t,e){let n=R(this);return W(n,e,(o,r)=>t.classList.toggle(o,r===-1?void 0:!!r)),t}function _t(t){return Array.from(t.children).forEach(e=>e.remove()),t}function tt(t,e){if(!Reflect.has(t,e))return!1;let n=Z(t,e);return!_(n.set)}function Z(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||Z(t,e)}function W(t,e,n){if(!(typeof e!="object"||e===null))return Object.entries(e).forEach(function([r,c]){r&&(c=t.processReactiveAttribute(e,r,c,n),n(r,c))})}function G(t){return Array.isArray(t)?t.filter(Boolean).join(" "):t}function et(t,e,n,o){return t[(_(o)?"remove":"set")+e](n,G(o))}function nt(t,e,n,o,r=null){return t[(_(o)?"remove":"set")+e+"NS"](r,n,G(o))}function H(t,e,n){if(Reflect.set(t,e,n),!!_(n))return Reflect.deleteProperty(t,e)}function B(...t){return this.appendOrig(...t),this}function rt(t){return t.append===B||(t.appendOrig=t.append,t.append=B),t}fu
* Investigate `__dde_attributes` key of the element.*/let[a,d]=s,l=r[A][a];if(l)return l(d)})(r),m.disconnected(function(){/*! This removes all signals mapped to attributes (`S.attribute`).
* Investigate `__dde_attributes` key of the element.*/g.clear(...Object.values(r[A])),o=null})(r),r}),new Proxy(n,{apply(r,c,s){if(!s.length)return r();if(!o)return;let a=s[0];return o instanceof HTMLElement?o.setAttribute(t,a):o.setAttributeNS(null,t,a)}})};g.clear=function(...t){for(let n of t){Reflect.deleteProperty(n,"toJSON");let o=n[p];o.onclear.forEach(r=>r.call(o)),e(n,o),Reflect.deleteProperty(n,p)}function e(n,o){o.listeners.forEach(r=>{if(o.listeners.delete(r),!h.has(r))return;let c=h.get(r);c.delete(n),!(c.size>1)&&(g.clear(...c),h.delete(r))})}};var k="__dde_reactive";g.el=function(t,e){let n=v.mark({type:"reactive"},!1),o=n.end,r=document.createDocumentFragment();r.append(n,o);let{current:c}=E,s=a=>{if(!n.parentNode||!o.parentNode)return O(t,s);E.push(c);let d=e(a);E.pop(),Array.isArray(d)||(d=[d]);let l=n;for(;(l=n.nextSibling)!==o;)l.remove();n.after(...d)};return z(t,s),Q(t,s,n,e),s(t()),r};var K={isSignal:D,processReactiveAttribute(t,e,n,o){if(!D(n))return n;let r=c=>o(e,c);return z(n,r),Q(n,r,t,e),n()}};function Q(t,e,...n){let{current:o}=E;o.prevent||o.host(function(r){r[k]||(r[k]=[],m.disconnected(()=>r[k].forEach(([[c,s]])=>O(c,s,c[p]?.host()===r)))(r)),r[k].push([[t,e],...n])})}function V(t,e){let n=(...o)=>o.length?at(n,...o):ft(n);return it(n,t,e)}var st=Object.assign(Object.create(null),{stopPropagation(){this.skip=!0}}),$=class extends Error{constructor(){super();let[e,...n]=this.stack.split(`
`),o=e.slice(e.indexOf("@"),e.indexOf(".js:")+4);this.stack=n.find(r=>!r.includes(o))}};function it(t,e,n){let o=[];F(n)!=="[object Object]"&&(n={});let{onclear:r}=g.symbols;n[r]&&(o.push(n[r]),Reflect.deleteProperty(n,r));let{host:c}=E;return Reflect.defineProperty(t,p,{value:{value:e,actions:n,onclear:o,host:c,listeners:new Set,defined:new $},enumerable:!1,writable:!1,configurable:!0}),t.toJSON=()=>t(),Object.setPrototypeOf(t[p],st),t}function ut(){return T[T.length-1]}function ft(t){if(!t[p])return;let{value:e,listeners:n}=t[p],o=ut();return o&&n.add(o),h.has(o)&&h.get(o).add(t),e}function at(t,e,n){if(!t[p])return;let o=t[p];if(!(!n&&o.value===e))return o.value=e,o.listeners.forEach(r=>r(e)),e}function z(t,e){if(t[p])return t[p].listeners.add(e)}function O(t,e,n){let o=t[p];if(!o)return;let r=o.listeners.delete(e);if(n&&!o.listeners.size){if(g.clear(t),!h.has(o))return r;let c=h.get(o);if(!h.has(c))return r;h.get(c).forEach(s=>O(s,c,!0))}return r}M(K);export{g as S,N as assign,I as assignAttribute,Y as classListDeclarative,v as createElement,bt as createElementNS,xt as dispatchEvent,v as el,bt as elNS,_t as empty,D as isSignal,m as on,M as registerReactivity,E as scope};