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

3 lines
9.9 KiB
JavaScript
Raw Normal View History

var w={isSignal(t){return!1},processReactiveAttribute(t,e,n,o){return n}};function j(t,e=!0){return e?Object.assign(w,t):(Object.setPrototypeOf(t,w),t)}function A(t){return w.isPrototypeOf(t)&&t!==w?t:w}function E(t){return typeof t>"u"}function k(t){let e=typeof t;return e!=="object"?e:t===null?"null":Object.prototype.toString.call(t)}function O(t,e){if(!t||!(t instanceof AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var F={setDeleteAttr:Q};function Q(t,e,n){if(Reflect.set(t,e,n),!!E(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 y=[{scope:document.body,namespace:"html",host:t=>t?t(document.body):document.body,prevent:!0}],z=t=>t==="svg"?"http://www.w3.org/2000/svg":t,h={get current(){return y[y.length-1]},get host(){return this.current.host},get namespace(){return this.current.namespace},set namespace(t){return this.current.namespace=z(t)},preventDefault(){let{current:t}=this;return t.prevent=!0,t},elNamespace(t){let e=this.namespace;return this.namespace=t,{append(...n){return h.namespace=e,n.length===1?n[0]:document.createDocumentFragment().append(...n)}}},get state(){return[...y]},push(t={}){return t.namespace&&(t.namespace=z(t.namespace)),y.push(Object.assign({},this.current,{prevent:!1},t))},pop(){return y.pop()}};function pt(t,e,...n){let o=A(this),{namespace:r}=h,c=0,s;switch((Object(e)!==e||o.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{c=1,h.push({scope:t,host:a=>a?(c===1?n.unshift(a):a(s),void 0):s}),s=t(e||void 0),(s instanceof HTMLElement?I:J)(s,"Attribute","dde-fun",t.name);break}case t==="#text":s=R.call(this,document.createTextNode(""),e);break;case t==="<>":s=R.call(this,document.createDocumentFragment(),e);break;case r!=="html":s=R.call(this,document.createElementNS(r,t),e);break;case!s:s=R.call(this,document.createElement(t),e)}return n.forEach(a=>a(s)),c&&h.pop(),c=2,s}var{setDeleteAttr:H}=F,C=new WeakMap;function R(t,...e){if(!e.length)return t;C.set(t,q(t,this));for(let[n,o]of Object.entries(Object.assign({},...e)))$.call(this,t,n,o);return C.delete(t),t}function $(t,e,n){let{setRemoveAttr:o,s:r}=q(t,this),c=this;n=r.processReactiveAttribute(t,e,n,(a,p)=>$.call(c,t,a,p));let[s]=e;if(s==="=")return o(e.slice(1),n);if(s===".")return U(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 H(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return T(r,n,U.bind(null,t[e]));case"ariaset":return T(r,n,(a,p)=>o("aria-"+a,p));case"classList":return X.call(c,t,n)}return Y(t,e)?H(t,e,n):o(e,n)}function q(t,e){if(C.has(t))return C.get(t);let o=(t instanceof SVGElement?J:I).bind(null,t,"Attribute"),r=A(e);return{setRemoveAttr:o,s:r}}function X(t,e){let n=A(this);return T(n,e,(o,r)=>t.classList.toggle(o,r===-1?void 0:!!r)),t}function ht(t){return Array.from(t.children).forEach(e=>e.remove()),t}function Y(t,e){if(!Reflect.has(t,e))return!1;let n=B(t,e);return!E(n.set)}function B(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||B(t,e)}function T(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 I(t,e,n,o){return t[(E(o)?"remove":"set")+e](n,G(o))}function J(t,e,n,o,r=null){return t[(E(o)?"remove":"set")+e+"NS"](r,n,G(o))}function U(t,e,n){if(Reflect.set(t,e,n),!!E(n))return Reflect.deleteProperty(t,e)}function bt(t,e,...n){let o=n.length?new CustomEvent(e,{detail:n[0]}):new Event(e);return t.dispatchEvent(o)}function v(t,e,n){return function(r){return r.addEventListener(t,e,n),r}}var L=et(),tt=new WeakSet;v.connected=function(t,e){let n="connected";return typeof e!="object"&
`),o=e.slice(e.indexOf("@"),e.indexOf(".js:")+4);this.stack=n.find(r=>!r.includes(o))}};function rt(t,e,n){let o=[];k(n)!=="[object Object]"&&(n={});let{onclear:r}=g.symbols;n[r]&&(o.push(n[r]),Reflect.deleteProperty(n,r));let{host:c}=h;return t[d]={value:e,actions:n,onclear:o,host:c,listeners:new Set,defined:new M},t.toJSON=()=>t(),Object.setPrototypeOf(t[d],nt),t}function ot(){return P[P.length-1]}function ct(t){if(!t[d])return;let{value:e,listeners:n}=t[d],o=ot();return o&&n.add(o),l.has(o)&&l.get(o).add(t),e}function st(t,e,n){if(!t[d])return;let o=t[d];if(!(!n&&o.value===e))return o.value=e,o.listeners.forEach(r=>r(e)),e}function W(t,e){if(t[d])return t[d].listeners.add(e)}function S(t,e,n){let o=t[d];if(!o)return;let r=o.listeners.delete(e);if(n&&!o.listeners.size){if(g.clear(t),!l.has(o))return r;let c=l.get(o);if(!l.has(c))return r;l.get(c).forEach(s=>S(s,c,!0))}return r}j(Z);export{g as S,R as assign,$ as assignAttribute,X as classListDeclarative,pt as createElement,bt as dispatchEvent,pt as el,ht as empty,N as isSignal,v as on,j as registerReactivity,h as scope};