diff --git a/dist/esm-with-signals.d.ts b/dist/esm-with-signals.d.ts index 5d2f226..cf835a7 100644 --- a/dist/esm-with-signals.d.ts +++ b/dist/esm-with-signals.d.ts @@ -214,7 +214,6 @@ export const scope: { export function customElementRender>>(target: ShadowRoot | EL, render: (props: P) => SupportedElement | DocumentFragment, props?: P | ((el: EL) => P)): EL; export function customElementWithDDE HTMLElement)>(custom_element: EL): EL; export function lifecyclesToEvents HTMLElement)>(custom_element: EL): EL; -export function observedAttributes(custom_element: HTMLElement): Record; /** * This is used primarly for server side rendering. To be sure that all async operations * are finished before the page is sent to the client. diff --git a/dist/esm-with-signals.js b/dist/esm-with-signals.js index fa2f192..53e4de3 100644 --- a/dist/esm-with-signals.js +++ b/dist/esm-with-signals.js @@ -32,8 +32,8 @@ function onAbort(signal2, listener) { }; } function observedAttributes(instance, observedAttribute2) { - const { observedAttributes: observedAttributes3 = [] } = instance.constructor; - return observedAttributes3.reduce(function(out, name) { + const { observedAttributes: observedAttributes2 = [] } = instance.constructor; + return observedAttributes2.reduce(function(out, name) { out[kebabToCamel(name)] = observedAttribute2(instance, name); return out; }, {}); @@ -545,7 +545,7 @@ function connectionsChangesObserverConstructor() { } // src/customElement.js -function customElementRender(target, render, props = observedAttributes2) { +function customElementRender(target, render, props = {}) { const custom_element = target.host || target; scope.push({ scope: custom_element, @@ -586,9 +586,6 @@ function wrapMethod(obj, method, apply) { obj[method] = new Proxy(obj[method] || (() => { }), { apply }); } -function observedAttributes2(instance) { - return observedAttributes(instance, (i, n) => i.getAttribute(n)); -} // src/events.js function dispatchEvent(name, options, host) { @@ -642,26 +639,6 @@ on.disconnectedAsAbort = function(host) { host(on.disconnected(() => a.abort())); return a.signal; }; -var els_attribute_store = /* @__PURE__ */ new WeakSet(); -on.attributeChanged = function(listener, options) { - if (typeof options !== "object") - options = {}; - return function registerElement(element) { - element.addEventListener(eva, listener, options); - if (element[keyLTE] || els_attribute_store.has(element)) - return element; - if (!enviroment.M) return element; - const observer = new enviroment.M(function(mutations) { - for (const { attributeName, target } of mutations) - target.dispatchEvent( - new CustomEvent(eva, { detail: [attributeName, target.getAttribute(attributeName)] }) - ); - }); - const c = onAbort(options.signal, () => observer.disconnect()); - if (c) observer.observe(element, { attributes: true }); - return element; - }; -}; // src/signals-lib/helpers.js var mark = "__dde_signal"; @@ -846,7 +823,7 @@ var key_attributes = "__dde_attributes"; signal.observedAttributes = function(element) { const store = element[key_attributes] = {}; const attrs = observedAttributes(element, observedAttribute(store)); - on.attributeChanged(function attributeChangeToSignal({ detail }) { + on(eva, function attributeChangeToSignal({ detail }) { /*! This maps attributes to signals (`S.observedAttributes`). Investigate `__dde_attributes` key of the element. */ const [name, value] = detail; @@ -997,7 +974,6 @@ export { elementAttribute, isSignal, lifecyclesToEvents, - observedAttributes2 as observedAttributes, on, queue, registerReactivity, diff --git a/dist/esm-with-signals.min.d.ts b/dist/esm-with-signals.min.d.ts index 5d2f226..cf835a7 100644 --- a/dist/esm-with-signals.min.d.ts +++ b/dist/esm-with-signals.min.d.ts @@ -214,7 +214,6 @@ export const scope: { export function customElementRender>>(target: ShadowRoot | EL, render: (props: P) => SupportedElement | DocumentFragment, props?: P | ((el: EL) => P)): EL; export function customElementWithDDE HTMLElement)>(custom_element: EL): EL; export function lifecyclesToEvents HTMLElement)>(custom_element: EL): EL; -export function observedAttributes(custom_element: HTMLElement): Record; /** * This is used primarly for server side rendering. To be sure that all async operations * are finished before the page is sent to the client. diff --git a/dist/esm-with-signals.min.js b/dist/esm-with-signals.min.js index b7c4be9..05ce9bc 100644 --- a/dist/esm-with-signals.min.js +++ b/dist/esm-with-signals.min.js @@ -1,4 +1,4 @@ -var Z=(...t)=>Object.prototype.hasOwnProperty.call(...t);function O(t){return typeof t>"u"}function nt(t){let e=typeof t;return e!=="object"?e:t===null?"null":Object.prototype.toString.call(t)}function S(t,e){return t instanceof e}function rt(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function w(t=null,e={}){return Object.create(t,e)}function m(...t){return Object.assign(...t)}function F(t,e){if(!t||!S(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}function I(t,e){let{observedAttributes:n=[]}=t.constructor;return n.reduce(function(r,o){return r[vt(o)]=e(t,o),r},{})}function vt(t){return t.replace(/-./g,e=>e[1].toUpperCase())}var P=class extends Error{constructor(){super();let[e,...n]=this.stack.split(` -`),r=e.slice(e.indexOf("@"),e.indexOf(".js:")+4),o=r.includes("src/helpers.js")?"src/":r;this.stack=n.find(c=>!c.includes(o))||e}get compact(){let{stack:e}=this;return e.slice(0,e.indexOf("@")+1)+"\u2026"+e.slice(e.lastIndexOf("/"))}};var j={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function G(t,e=!0){return e?m(j,t):(Object.setPrototypeOf(t,j),t)}function $(t){return rt(t,j)&&t!==j?t:j}var d={setDeleteAttr:mt,ssr:"",D:globalThis.document,F:globalThis.DocumentFragment,H:globalThis.HTMLElement,S:globalThis.SVGElement,M:globalThis.MutationObserver,q:t=>t||Promise.resolve()};function mt(t,e,n){if(Reflect.set(t,e,n),!!O(n)){if(Reflect.deleteProperty(t,e),S(t,d.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var D="__dde_lifecyclesToEvents",y="dde:connected",R="dde:disconnected",q="dde:attributeChanged";function Bt(t){return d.q(t)}var C=[{get scope(){return d.D.body},host:t=>t?t(d.D.body):d.D.body,prevent:!0}],x={get current(){return C[C.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...C]},push(t={}){return C.push(m({},this.current,{prevent:!1},t))},pushRoot(){return C.push(C[0])},pop(){if(C.length!==1)return C.pop()}};function ot(...t){return this.appendOriginal(...t),this}function xt(t){return t.append===ot||(t.appendOriginal=t.append,t.append=ot),t}var z;function W(t,e,...n){let r=$(this),o=0,c,s;switch((Object(e)!==e||r.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1;let i=(...h)=>h.length?(o===1?n.unshift(...h):h.forEach(v=>v(s)),void 0):s;x.push({scope:t,host:i}),c=t(e||void 0);let l=S(c,d.F);if(c.nodeName==="#comment")break;let E=W.mark({type:"component",name:t.name,host:l?"this":"parentElement"});c.prepend(E),l&&(s=E);break}case t==="#text":c=U.call(this,d.D.createTextNode(""),e);break;case(t==="<>"||!t):c=U.call(this,d.D.createDocumentFragment(),e);break;case!!z:c=U.call(this,d.D.createElementNS(z,t),e);break;case!c:c=U.call(this,d.D.createElement(t),e)}return xt(c),s||(s=c),n.forEach(i=>i(s)),o&&x.pop(),o=2,c}W.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=d.D.createComment(``);return e&&(r.end=d.D.createComment("")),r};function Jt(t){let e=this;return function(...r){z=t;let o=W.call(e,...r);return z=void 0,o}}function Zt(t,e=t){let n="\xB9\u2070",r="\u2713",o=Object.fromEntries(Array.from(e.querySelectorAll("slot")).filter(c=>!c.name.endsWith(n)).map(c=>[c.name+=n,c]));if(t.append=new Proxy(t.append,{apply(c,s,i){if(i[0]===e)return c.apply(t,i);for(let l of i){let E=(l.slot||"")+n;try{_t(l,"remove","slot")}catch{}let h=o[E];if(!h)return;h.name.startsWith(r)||(h.childNodes.forEach(v=>v.remove()),h.name=r+E),h.append(l)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}var H=new WeakMap,{setDeleteAttr:ct}=d;function U(t,...e){if(!e.length)return t;H.set(t,ut(t,this));for(let[n,r]of Object.entries(m({},...e)))it.call(this,t,n,r);return H.delete(t),t}function it(t,e,n){let{setRemoveAttr:r,s:o}=ut(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(i,l)=>it.call(c,t,i,l));let[s]=e;if(s==="=")return r(e.slice(1),n);if(s===".")return st(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 ct(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return V(o,e,t,n,st.bind(null,t[e]));case"ariaset":return V(o,e,t,n,(i,l)=>r("aria-"+i,l));case"classList":return Et.call(c,t,n)}return St(t,e)?ct(t,e,n):r(e,n)}function ut(t,e){if(H.has(t))return H.get(t);let r=(S(t,d.S)?At:wt).bind(null,t,"Attribute"),o=$(e);return{setRemoveAttr:r,s:o}}function Et(t,e){let n=$(this);return V(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function _t(t,e,n,r){return S(t,d.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function St(t,e){if(!(e in t))return!1;let n=ft(t,e);return!O(n.set)}function ft(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||ft(t,e)}function V(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([i,l]){i&&(i=new c(i),i.target=e,l=t.processReactiveAttribute(n,i,l,o),o(i,l))})}function wt(t,e,n,r){return t[(O(r)?"remove":"set")+e](n,r)}function At(t,e,n,r,o=null){return t[(O(r)?"remove":"set")+e+"NS"](o,n,r)}function st(t,e,n){if(Reflect.set(t,e,n),!!O(n))return Reflect.deleteProperty(t,e)}var L=d.M?yt():new Proxy({},{get(){return()=>{}}});function yt(){let t=new Map,e=!1,n=u=>function(a){for(let f of a)if(f.type==="childList"){if(h(f.addedNodes,!0)){u();continue}v(f.removedNodes,!0)&&u()}},r=new d.M(n(i));return{observe(u){let a=new d.M(n(()=>{}));return a.observe(u,{childList:!0,subtree:!0}),()=>a.disconnect()},onConnected(u,a){s();let f=c(u);f.connected.has(a)||(f.connected.add(a),f.length_c+=1)},offConnected(u,a){if(!t.has(u))return;let f=t.get(u);f.connected.has(a)&&(f.connected.delete(a),f.length_c-=1,o(u,f))},onDisconnected(u,a){s();let f=c(u);f.disconnected.has(a)||(f.disconnected.add(a),f.length_d+=1)},offDisconnected(u,a){if(!t.has(u))return;let f=t.get(u);f.disconnected.delete(a),f.length_d-=1,o(u,f)}};function o(u,a){a.length_c||a.length_d||(t.delete(u),i())}function c(u){if(t.has(u))return t.get(u);let a={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(u,a),a}function s(){e||(e=!0,r.observe(d.D.body,{childList:!0,subtree:!0}))}function i(){!e||t.size||(e=!1,r.disconnect())}function l(){return new Promise(function(u){(requestIdleCallback||requestAnimationFrame)(u)})}async function E(u){t.size>30&&await l();let a=[];if(!S(u,Node))return a;for(let f of t.keys())f===u||!S(f,Node)||u.contains(f)&&a.push(f);return a}function h(u,a){let f=!1;for(let _ of u){if(a&&E(_).then(h),!t.has(_))continue;let T=t.get(_);T.length_c&&(_.dispatchEvent(new Event(y)),T.connected=new WeakSet,T.length_c=0,T.length_d||t.delete(_),f=!0)}return f}function v(u,a){let f=!1;for(let _ of u)a&&E(_).then(v),!(!t.has(_)||!t.get(_).length_d)&&((globalThis.queueMicrotask||setTimeout)(N(_)),f=!0);return f}function N(u){return()=>{u.isConnected||(u.dispatchEvent(new Event(R)),t.delete(u))}}}function ee(t,e,n=Ot){let r=t.host||t;x.push({scope:r,host:(...s)=>s.length?s.forEach(i=>i(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[D];o||Ct(r);let c=e.call(r,n);return o||r.dispatchEvent(new Event(y)),t.nodeType===11&&typeof t.mode=="string"&&r.addEventListener(R,L.observe(t),{once:!0}),x.pop(),t.append(c)}function Ct(t){return K(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(y))}),K(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(R)))}),K(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(q,{detail:[o,c]})),e.apply(n,r)}),t.prototype[D]=!0,t}function K(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}function Ot(t){return I(t,(e,n)=>e.getAttribute(n))}function se(t,e,n){return typeof e=="function"&&(n=e,e=null),e||(e={}),function(o,...c){n&&(c.unshift(o),o=typeof n=="function"?n():n);let s=c.length?new CustomEvent(t,m({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(s)}}function A(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}var at=t=>m({},typeof t=="object"?t:null,{once:!0});A.connected=function(t,e){return e=at(e),function(r){return r.addEventListener(y,t,e),r[D]?r:r.isConnected?(r.dispatchEvent(new Event(y)),r):(F(e.signal,()=>L.offConnected(r,t))&&L.onConnected(r,t),r)}};A.disconnected=function(t,e){return e=at(e),function(r){return r.addEventListener(R,t,e),r[D]||F(e.signal,()=>L.offDisconnected(r,t))&&L.onDisconnected(r,t),r}};var Q=new WeakMap;A.disconnectedAsAbort=function(t){if(Q.has(t))return Q.get(t);let e=new AbortController;return Q.set(t,e),t(A.disconnected(()=>e.abort())),e.signal};var Dt=new WeakSet;A.attributeChanged=function(t,e){return typeof e!="object"&&(e={}),function(r){if(r.addEventListener(q,t,e),r[D]||Dt.has(r)||!d.M)return r;let o=new d.M(function(s){for(let{attributeName:i,target:l}of s)l.dispatchEvent(new CustomEvent(q,{detail:[i,l.getAttribute(i)]}))});return F(e.signal,()=>o.disconnect())&&o.observe(r,{attributes:!0}),r}};var p="__dde_signal",X=(()=>{let t=new Set,e=!1;function n(){e=!1;let r=t;t=new Set;for(let o of r){let c=o[p];c&&c.listeners.forEach(s=>s(c.value))}}return function(r){t.add(r),!e&&(e=!0,queueMicrotask(n))}})();var tt=w(null,{get:{value(){return lt(this)}},set:{value(...t){return bt(this,...t)}},toJSON:{value(){return lt(this)}},valueOf:{value(){return this[p]&&this[p].value}}}),Rt=w(tt,{set:{value(){}}});function B(t){return t&&t[p]}var J=[],b=new WeakMap;function g(t,e){if(typeof t!="function")return dt(!1,t,e);if(B(t))return t;let n=dt(!0);function r(){let[o,...c]=b.get(r);if(b.set(r,new Set([o])),J.push(r),bt(n,t()),J.pop(),!c.length)return;let s=b.get(r);for(let i of c)s.has(i)||M(i,r)}return b.set(n[p],r),b.set(r,new Set([n])),r(),n}g.action=function(t,e,...n){let r=t[p];if(!r)return;let{actions:o}=r;if(!o||!Z(o,e))throw new Error(`Action "${e}" not defined. See ${p}.actions.`);if(o[e].apply(r,n),r.skip)return delete r.skip;X(t)};g.on=function t(e,n,r={}){let{signal:o}=r;if(!(o&&o.aborted)){if(Array.isArray(e))return e.forEach(c=>t(c,n,r));et(e,n),o&&o.addEventListener("abort",()=>M(e,n))}};g.symbols={onclear:Symbol.for("Signal.onclear")};g.clear=function(...t){for(let n of t){let r=n[p];r&&(delete n.toJSON,r.onclear.forEach(o=>o.call(r)),e(n,r),delete n[p])}function e(n,r){r.listeners.forEach(o=>{if(r.listeners.delete(o),!b.has(o))return;let c=b.get(o);c.delete(n),!(c.size>1)&&(n.clear(...c),b.delete(o))})}};var k="__dde_reactive";function Lt(t=w()){return(e,n)=>Z(t,e)?t[e]:t[e]=n()}g.el=function(t,e){let n=W.mark({type:"reactive",source:new P().compact},!0),r=n.end,o=d.D.createDocumentFragment();o.append(n,r);let{current:c}=x,s=w(),i=l=>{if(!n.parentNode||!r.parentNode)return M(t,i);let E=Lt(s);s=w(),x.push(c);let h=e(l,function(a,f){return s[a]=E(a,f)});x.pop(),Array.isArray(h)||(h=[h]);let v=document.createComment("");h.push(v),n.after(...h);let N;for(;(N=v.nextSibling)&&N!==r;)N.remove();v.remove(),n.isConnected&&kt(c.host())};return et(t,i),ht(t,i,n,e),i(t.get()),c.host(A.disconnected(()=>s={})),o};function kt(t){!t||!t[k]||(requestIdleCallback||setTimeout)(function(){t[k]=t[k].filter(([e,n])=>n.isConnected?!0:(M(...e),!1))})}var Mt={_set(t){this.value=t}};function Nt(t){return function(e,n){let r=w(tt,{set:{value(...c){return e.setAttribute(n,...c)}}}),o=gt(r,e.getAttribute(n),Mt);return t[n]=o,o}}var Y="__dde_attributes";g.observedAttributes=function(t){let e=t[Y]={},n=I(t,Nt(e));return A.attributeChanged(function({detail:o}){/*! This maps attributes to signals (`S.observedAttributes`). - Investigate `__dde_attributes` key of the element. */let[c,s]=o,i=this[Y][c];if(i)return g.action(i,"_set",s)})(t),A.disconnected(function(){/*! This removes all signals mapped to attributes (`S.observedAttributes`). - Investigate `__dde_attributes` key of the element. */g.clear(...Object.values(this[Y]))})(t),n};var pt={isSignal:B,processReactiveAttribute(t,e,n,r){if(!B(n))return n;let o=c=>{if(!t.isConnected)return M(n,o);r(e,c)};return et(n,o),ht(n,o,t,e),n.get()}};function ht(t,e,...n){let{current:r}=x;r.host(function(o){if(o[k])return o[k].push([[t,e],...n]);o[k]=[],!r.prevent&&A.disconnected(()=>o[k].forEach(([[c,s]])=>M(c,s,c[p]&&c[p].host&&c[p].host()===o)))(o)})}var Tt=new FinalizationRegistry(function(t){g.clear({[p]:t})});function dt(t,e,n){let r=w(t?Rt:tt),o=gt(r,e,n,t);return Tt.register(o,o[p]),o}var Pt=m(w(),{stopPropagation(){this.skip=!0}});function gt(t,e,n,r=!1){let o=[];nt(n)!=="[object Object]"&&(n={});let{onclear:c}=g.symbols;n[c]&&(o.push(n[c]),delete n[c]);let{host:s}=x;return Reflect.defineProperty(t,p,{value:m(w(Pt),{value:e,actions:n,onclear:o,host:s,listeners:new Set,defined:new P().stack,readonly:r}),enumerable:!1,writable:!1,configurable:!0}),t}function jt(){return J[J.length-1]}function lt(t){if(!t[p])return;let{value:e,listeners:n}=t[p],r=jt();return r&&n.add(r),b.has(r)&&b.get(r).add(t),e}function bt(t,e,n){let r=t[p];if(!(!r||!n&&r.value===e))return r.value=e,X(t),e}function et(t,e){if(t[p])return t[p].listeners.add(e)}function M(t,e,n){let r=t[p];if(!r)return;let{listeners:o}=r,c=o.delete(e);if(!c||!n||o.size)return c;g.clear(t);let s=b.get(r);if(!s)return c;let i=b.get(s);if(!i)return c;for(let l of i)M(l,s,!0);return c}G(pt);export{g as S,U as assign,it as assignAttribute,xt as chainableAppend,Et as classListDeclarative,W as createElement,Jt as createElementNS,ee as customElementRender,Ct as customElementWithDDE,se as dispatchEvent,W as el,Jt as elNS,_t as elementAttribute,B as isSignal,Ct as lifecyclesToEvents,Ot as observedAttributes,A as on,Bt as queue,G as registerReactivity,x as scope,g as signal,Zt as simulateSlots}; +var B=(...t)=>Object.prototype.hasOwnProperty.call(...t);function O(t){return typeof t>"u"}function et(t){let e=typeof t;return e!=="object"?e:t===null?"null":Object.prototype.toString.call(t)}function S(t,e){return t instanceof e}function nt(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function w(t=null,e={}){return Object.create(t,e)}function b(...t){return Object.assign(...t)}function J(t,e){if(!t||!S(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}function rt(t,e){let{observedAttributes:n=[]}=t.constructor;return n.reduce(function(r,o){return r[vt(o)]=e(t,o),r},{})}function vt(t){return t.replace(/-./g,e=>e[1].toUpperCase())}var P=class extends Error{constructor(){super();let[e,...n]=this.stack.split(` +`),r=e.slice(e.indexOf("@"),e.indexOf(".js:")+4),o=r.includes("src/helpers.js")?"src/":r;this.stack=n.find(c=>!c.includes(o))||e}get compact(){let{stack:e}=this;return e.slice(0,e.indexOf("@")+1)+"\u2026"+e.slice(e.lastIndexOf("/"))}};var q={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function Z(t,e=!0){return e?b(q,t):(Object.setPrototypeOf(t,q),t)}function W(t){return nt(t,q)&&t!==q?t:q}var d={setDeleteAttr:bt,ssr:"",D:globalThis.document,F:globalThis.DocumentFragment,H:globalThis.HTMLElement,S:globalThis.SVGElement,M:globalThis.MutationObserver,q:t=>t||Promise.resolve()};function bt(t,e,n){if(Reflect.set(t,e,n),!!O(n)){if(Reflect.deleteProperty(t,e),S(t,d.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var N="__dde_lifecyclesToEvents",y="dde:connected",D="dde:disconnected",F="dde:attributeChanged";function zt(t){return d.q(t)}var C=[{get scope(){return d.D.body},host:t=>t?t(d.D.body):d.D.body,prevent:!0}],x={get current(){return C[C.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...C]},push(t={}){return C.push(b({},this.current,{prevent:!1},t))},pushRoot(){return C.push(C[0])},pop(){if(C.length!==1)return C.pop()}};function ot(...t){return this.appendOriginal(...t),this}function xt(t){return t.append===ot||(t.appendOriginal=t.append,t.append=ot),t}var $;function j(t,e,...n){let r=W(this),o=0,c,s;switch((Object(e)!==e||r.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1;let i=(...h)=>h.length?(o===1?n.unshift(...h):h.forEach(v=>v(s)),void 0):s;x.push({scope:t,host:i}),c=t(e||void 0);let p=S(c,d.F);if(c.nodeName==="#comment")break;let E=j.mark({type:"component",name:t.name,host:p?"this":"parentElement"});c.prepend(E),p&&(s=E);break}case t==="#text":c=I.call(this,d.D.createTextNode(""),e);break;case(t==="<>"||!t):c=I.call(this,d.D.createDocumentFragment(),e);break;case!!$:c=I.call(this,d.D.createElementNS($,t),e);break;case!c:c=I.call(this,d.D.createElement(t),e)}return xt(c),s||(s=c),n.forEach(i=>i(s)),o&&x.pop(),o=2,c}j.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=d.D.createComment(``);return e&&(r.end=d.D.createComment("")),r};function Ht(t){let e=this;return function(...r){$=t;let o=j.call(e,...r);return $=void 0,o}}function Bt(t,e=t){let n="\xB9\u2070",r="\u2713",o=Object.fromEntries(Array.from(e.querySelectorAll("slot")).filter(c=>!c.name.endsWith(n)).map(c=>[c.name+=n,c]));if(t.append=new Proxy(t.append,{apply(c,s,i){if(i[0]===e)return c.apply(t,i);for(let p of i){let E=(p.slot||"")+n;try{_t(p,"remove","slot")}catch{}let h=o[E];if(!h)return;h.name.startsWith(r)||(h.childNodes.forEach(v=>v.remove()),h.name=r+E),h.append(p)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}var U=new WeakMap,{setDeleteAttr:ct}=d;function I(t,...e){if(!e.length)return t;U.set(t,ut(t,this));for(let[n,r]of Object.entries(b({},...e)))it.call(this,t,n,r);return U.delete(t),t}function it(t,e,n){let{setRemoveAttr:r,s:o}=ut(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(i,p)=>it.call(c,t,i,p));let[s]=e;if(s==="=")return r(e.slice(1),n);if(s===".")return st(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 ct(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return G(o,e,t,n,st.bind(null,t[e]));case"ariaset":return G(o,e,t,n,(i,p)=>r("aria-"+i,p));case"classList":return Et.call(c,t,n)}return St(t,e)?ct(t,e,n):r(e,n)}function ut(t,e){if(U.has(t))return U.get(t);let r=(S(t,d.S)?At:wt).bind(null,t,"Attribute"),o=W(e);return{setRemoveAttr:r,s:o}}function Et(t,e){let n=W(this);return G(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function _t(t,e,n,r){return S(t,d.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function St(t,e){if(!(e in t))return!1;let n=ft(t,e);return!O(n.set)}function ft(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||ft(t,e)}function G(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([i,p]){i&&(i=new c(i),i.target=e,p=t.processReactiveAttribute(n,i,p,o),o(i,p))})}function wt(t,e,n,r){return t[(O(r)?"remove":"set")+e](n,r)}function At(t,e,n,r,o=null){return t[(O(r)?"remove":"set")+e+"NS"](o,n,r)}function st(t,e,n){if(Reflect.set(t,e,n),!!O(n))return Reflect.deleteProperty(t,e)}var R=d.M?yt():new Proxy({},{get(){return()=>{}}});function yt(){let t=new Map,e=!1,n=u=>function(a){for(let f of a)if(f.type==="childList"){if(h(f.addedNodes,!0)){u();continue}v(f.removedNodes,!0)&&u()}},r=new d.M(n(i));return{observe(u){let a=new d.M(n(()=>{}));return a.observe(u,{childList:!0,subtree:!0}),()=>a.disconnect()},onConnected(u,a){s();let f=c(u);f.connected.has(a)||(f.connected.add(a),f.length_c+=1)},offConnected(u,a){if(!t.has(u))return;let f=t.get(u);f.connected.has(a)&&(f.connected.delete(a),f.length_c-=1,o(u,f))},onDisconnected(u,a){s();let f=c(u);f.disconnected.has(a)||(f.disconnected.add(a),f.length_d+=1)},offDisconnected(u,a){if(!t.has(u))return;let f=t.get(u);f.disconnected.delete(a),f.length_d-=1,o(u,f)}};function o(u,a){a.length_c||a.length_d||(t.delete(u),i())}function c(u){if(t.has(u))return t.get(u);let a={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(u,a),a}function s(){e||(e=!0,r.observe(d.D.body,{childList:!0,subtree:!0}))}function i(){!e||t.size||(e=!1,r.disconnect())}function p(){return new Promise(function(u){(requestIdleCallback||requestAnimationFrame)(u)})}async function E(u){t.size>30&&await p();let a=[];if(!S(u,Node))return a;for(let f of t.keys())f===u||!S(f,Node)||u.contains(f)&&a.push(f);return a}function h(u,a){let f=!1;for(let _ of u){if(a&&E(_).then(h),!t.has(_))continue;let M=t.get(_);M.length_c&&(_.dispatchEvent(new Event(y)),M.connected=new WeakSet,M.length_c=0,M.length_d||t.delete(_),f=!0)}return f}function v(u,a){let f=!1;for(let _ of u)a&&E(_).then(v),!(!t.has(_)||!t.get(_).length_d)&&((globalThis.queueMicrotask||setTimeout)(T(_)),f=!0);return f}function T(u){return()=>{u.isConnected||(u.dispatchEvent(new Event(D)),t.delete(u))}}}function Yt(t,e,n={}){let r=t.host||t;x.push({scope:r,host:(...s)=>s.length?s.forEach(i=>i(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[N];o||Ct(r);let c=e.call(r,n);return o||r.dispatchEvent(new Event(y)),t.nodeType===11&&typeof t.mode=="string"&&r.addEventListener(D,R.observe(t),{once:!0}),x.pop(),t.append(c)}function Ct(t){return V(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(y))}),V(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(D)))}),V(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(F,{detail:[o,c]})),e.apply(n,r)}),t.prototype[N]=!0,t}function V(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}function ce(t,e,n){return typeof e=="function"&&(n=e,e=null),e||(e={}),function(o,...c){n&&(c.unshift(o),o=typeof n=="function"?n():n);let s=c.length?new CustomEvent(t,b({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(s)}}function A(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}var at=t=>b({},typeof t=="object"?t:null,{once:!0});A.connected=function(t,e){return e=at(e),function(r){return r.addEventListener(y,t,e),r[N]?r:r.isConnected?(r.dispatchEvent(new Event(y)),r):(J(e.signal,()=>R.offConnected(r,t))&&R.onConnected(r,t),r)}};A.disconnected=function(t,e){return e=at(e),function(r){return r.addEventListener(D,t,e),r[N]||J(e.signal,()=>R.offDisconnected(r,t))&&R.onDisconnected(r,t),r}};var K=new WeakMap;A.disconnectedAsAbort=function(t){if(K.has(t))return K.get(t);let e=new AbortController;return K.set(t,e),t(A.disconnected(()=>e.abort())),e.signal};var l="__dde_signal",Q=(()=>{let t=new Set,e=!1;function n(){e=!1;let r=t;t=new Set;for(let o of r){let c=o[l];c&&c.listeners.forEach(s=>s(c.value))}}return function(r){t.add(r),!e&&(e=!0,queueMicrotask(n))}})();var Y=w(null,{get:{value(){return lt(this)}},set:{value(...t){return mt(this,...t)}},toJSON:{value(){return lt(this)}},valueOf:{value(){return this[l]&&this[l].value}}}),Ot=w(Y,{set:{value(){}}});function z(t){return t&&t[l]}var H=[],m=new WeakMap;function g(t,e){if(typeof t!="function")return dt(!1,t,e);if(z(t))return t;let n=dt(!0);function r(){let[o,...c]=m.get(r);if(m.set(r,new Set([o])),H.push(r),mt(n,t()),H.pop(),!c.length)return;let s=m.get(r);for(let i of c)s.has(i)||k(i,r)}return m.set(n[l],r),m.set(r,new Set([n])),r(),n}g.action=function(t,e,...n){let r=t[l];if(!r)return;let{actions:o}=r;if(!o||!B(o,e))throw new Error(`Action "${e}" not defined. See ${l}.actions.`);if(o[e].apply(r,n),r.skip)return delete r.skip;Q(t)};g.on=function t(e,n,r={}){let{signal:o}=r;if(!(o&&o.aborted)){if(Array.isArray(e))return e.forEach(c=>t(c,n,r));tt(e,n),o&&o.addEventListener("abort",()=>k(e,n))}};g.symbols={onclear:Symbol.for("Signal.onclear")};g.clear=function(...t){for(let n of t){let r=n[l];r&&(delete n.toJSON,r.onclear.forEach(o=>o.call(r)),e(n,r),delete n[l])}function e(n,r){r.listeners.forEach(o=>{if(r.listeners.delete(o),!m.has(o))return;let c=m.get(o);c.delete(n),!(c.size>1)&&(n.clear(...c),m.delete(o))})}};var L="__dde_reactive";function Dt(t=w()){return(e,n)=>B(t,e)?t[e]:t[e]=n()}g.el=function(t,e){let n=j.mark({type:"reactive",source:new P().compact},!0),r=n.end,o=d.D.createDocumentFragment();o.append(n,r);let{current:c}=x,s=w(),i=p=>{if(!n.parentNode||!r.parentNode)return k(t,i);let E=Dt(s);s=w(),x.push(c);let h=e(p,function(a,f){return s[a]=E(a,f)});x.pop(),Array.isArray(h)||(h=[h]);let v=document.createComment("");h.push(v),n.after(...h);let T;for(;(T=v.nextSibling)&&T!==r;)T.remove();v.remove(),n.isConnected&&Rt(c.host())};return tt(t,i),ht(t,i,n,e),i(t.get()),c.host(A.disconnected(()=>s={})),o};function Rt(t){!t||!t[L]||(requestIdleCallback||setTimeout)(function(){t[L]=t[L].filter(([e,n])=>n.isConnected?!0:(k(...e),!1))})}var Lt={_set(t){this.value=t}};function kt(t){return function(e,n){let r=w(Y,{set:{value(...c){return e.setAttribute(n,...c)}}}),o=gt(r,e.getAttribute(n),Lt);return t[n]=o,o}}var X="__dde_attributes";g.observedAttributes=function(t){let e=t[X]={},n=rt(t,kt(e));return A(F,function({detail:o}){/*! This maps attributes to signals (`S.observedAttributes`). + Investigate `__dde_attributes` key of the element. */let[c,s]=o,i=this[X][c];if(i)return g.action(i,"_set",s)})(t),A.disconnected(function(){/*! This removes all signals mapped to attributes (`S.observedAttributes`). + Investigate `__dde_attributes` key of the element. */g.clear(...Object.values(this[X]))})(t),n};var pt={isSignal:z,processReactiveAttribute(t,e,n,r){if(!z(n))return n;let o=c=>{if(!t.isConnected)return k(n,o);r(e,c)};return tt(n,o),ht(n,o,t,e),n.get()}};function ht(t,e,...n){let{current:r}=x;r.host(function(o){if(o[L])return o[L].push([[t,e],...n]);o[L]=[],!r.prevent&&A.disconnected(()=>o[L].forEach(([[c,s]])=>k(c,s,c[l]&&c[l].host&&c[l].host()===o)))(o)})}var Nt=new FinalizationRegistry(function(t){g.clear({[l]:t})});function dt(t,e,n){let r=w(t?Ot:Y),o=gt(r,e,n,t);return Nt.register(o,o[l]),o}var Tt=b(w(),{stopPropagation(){this.skip=!0}});function gt(t,e,n,r=!1){let o=[];et(n)!=="[object Object]"&&(n={});let{onclear:c}=g.symbols;n[c]&&(o.push(n[c]),delete n[c]);let{host:s}=x;return Reflect.defineProperty(t,l,{value:b(w(Tt),{value:e,actions:n,onclear:o,host:s,listeners:new Set,defined:new P().stack,readonly:r}),enumerable:!1,writable:!1,configurable:!0}),t}function Mt(){return H[H.length-1]}function lt(t){if(!t[l])return;let{value:e,listeners:n}=t[l],r=Mt();return r&&n.add(r),m.has(r)&&m.get(r).add(t),e}function mt(t,e,n){let r=t[l];if(!(!r||!n&&r.value===e))return r.value=e,Q(t),e}function tt(t,e){if(t[l])return t[l].listeners.add(e)}function k(t,e,n){let r=t[l];if(!r)return;let{listeners:o}=r,c=o.delete(e);if(!c||!n||o.size)return c;g.clear(t);let s=m.get(r);if(!s)return c;let i=m.get(s);if(!i)return c;for(let p of i)k(p,s,!0);return c}Z(pt);export{g as S,I as assign,it as assignAttribute,xt as chainableAppend,Et as classListDeclarative,j as createElement,Ht as createElementNS,Yt as customElementRender,Ct as customElementWithDDE,ce as dispatchEvent,j as el,Ht as elNS,_t as elementAttribute,z as isSignal,Ct as lifecyclesToEvents,A as on,zt as queue,Z as registerReactivity,x as scope,g as signal,Bt as simulateSlots}; diff --git a/dist/esm.d.ts b/dist/esm.d.ts index 7a33885..cdb2000 100644 --- a/dist/esm.d.ts +++ b/dist/esm.d.ts @@ -213,7 +213,6 @@ export const scope: { export function customElementRender>>(target: ShadowRoot | EL, render: (props: P) => SupportedElement | DocumentFragment, props?: P | ((el: EL) => P)): EL; export function customElementWithDDE HTMLElement)>(custom_element: EL): EL; export function lifecyclesToEvents HTMLElement)>(custom_element: EL): EL; -export function observedAttributes(custom_element: HTMLElement): Record; /** * This is used primarly for server side rendering. To be sure that all async operations * are finished before the page is sent to the client. diff --git a/dist/esm.js b/dist/esm.js index 6a6a6cb..857673a 100644 --- a/dist/esm.js +++ b/dist/esm.js @@ -21,16 +21,6 @@ function onAbort(signal, listener) { signal.removeEventListener("abort", listener); }; } -function observedAttributes(instance, observedAttribute) { - const { observedAttributes: observedAttributes3 = [] } = instance.constructor; - return observedAttributes3.reduce(function(out, name) { - out[kebabToCamel(name)] = observedAttribute(instance, name); - return out; - }, {}); -} -function kebabToCamel(name) { - return name.replace(/-./g, (x) => x[1].toUpperCase()); -} // src/signals-lib/common.js var signals_global = { @@ -522,7 +512,7 @@ function connectionsChangesObserverConstructor() { } // src/customElement.js -function customElementRender(target, render, props = observedAttributes2) { +function customElementRender(target, render, props = {}) { const custom_element = target.host || target; scope.push({ scope: custom_element, @@ -563,9 +553,6 @@ function wrapMethod(obj, method, apply) { obj[method] = new Proxy(obj[method] || (() => { }), { apply }); } -function observedAttributes2(instance) { - return observedAttributes(instance, (i, n) => i.getAttribute(n)); -} // src/events.js function dispatchEvent(name, options, host) { @@ -619,26 +606,6 @@ on.disconnectedAsAbort = function(host) { host(on.disconnected(() => a.abort())); return a.signal; }; -var els_attribute_store = /* @__PURE__ */ new WeakSet(); -on.attributeChanged = function(listener, options) { - if (typeof options !== "object") - options = {}; - return function registerElement(element) { - element.addEventListener(eva, listener, options); - if (element[keyLTE] || els_attribute_store.has(element)) - return element; - if (!enviroment.M) return element; - const observer = new enviroment.M(function(mutations) { - for (const { attributeName, target } of mutations) - target.dispatchEvent( - new CustomEvent(eva, { detail: [attributeName, target.getAttribute(attributeName)] }) - ); - }); - const c = onAbort(options.signal, () => observer.disconnect()); - if (c) observer.observe(element, { attributes: true }); - return element; - }; -}; export { assign, assignAttribute, @@ -653,7 +620,6 @@ export { createElementNS as elNS, elementAttribute, lifecyclesToEvents, - observedAttributes2 as observedAttributes, on, queue, registerReactivity, diff --git a/dist/esm.min.d.ts b/dist/esm.min.d.ts index 7a33885..cdb2000 100644 --- a/dist/esm.min.d.ts +++ b/dist/esm.min.d.ts @@ -213,7 +213,6 @@ export const scope: { export function customElementRender>>(target: ShadowRoot | EL, render: (props: P) => SupportedElement | DocumentFragment, props?: P | ((el: EL) => P)): EL; export function customElementWithDDE HTMLElement)>(custom_element: EL): EL; export function lifecyclesToEvents HTMLElement)>(custom_element: EL): EL; -export function observedAttributes(custom_element: HTMLElement): Record; /** * This is used primarly for server side rendering. To be sure that all async operations * are finished before the page is sent to the client. diff --git a/dist/esm.min.js b/dist/esm.min.js index c4a75a9..0603caa 100644 --- a/dist/esm.min.js +++ b/dist/esm.min.js @@ -1 +1 @@ -function w(t){return typeof t>"u"}function b(t,e){return t instanceof e}function F(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function v(...t){return Object.assign(...t)}function R(t,e){if(!t||!b(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}function I(t,e){let{observedAttributes:n=[]}=t.constructor;return n.reduce(function(r,o){return r[J(o)]=e(t,o),r},{})}function J(t){return t.replace(/-./g,e=>e[1].toUpperCase())}var O={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function K(t,e=!0){return e?v(O,t):(Object.setPrototypeOf(t,O),t)}function T(t){return F(t,O)&&t!==O?t:O}var a={setDeleteAttr:Q,ssr:"",D:globalThis.document,F:globalThis.DocumentFragment,H:globalThis.HTMLElement,S:globalThis.SVGElement,M:globalThis.MutationObserver,q:t=>t||Promise.resolve()};function Q(t,e,n){if(Reflect.set(t,e,n),!!w(n)){if(Reflect.deleteProperty(t,e),b(t,a.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var A="__dde_lifecyclesToEvents",m="dde:connected",_="dde:disconnected",D="dde:attributeChanged";function gt(t){return a.q(t)}var x=[{get scope(){return a.D.body},host:t=>t?t(a.D.body):a.D.body,prevent:!0}],S={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(v({},this.current,{prevent:!1},t))},pushRoot(){return x.push(x[0])},pop(){if(x.length!==1)return x.pop()}};function $(...t){return this.appendOriginal(...t),this}function X(t){return t.append===$||(t.appendOriginal=t.append,t.append=$),t}var P;function k(t,e,...n){let r=T(this),o=0,c,d;switch((Object(e)!==e||r.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1;let f=(...l)=>l.length?(o===1?n.unshift(...l):l.forEach(E=>E(d)),void 0):d;S.push({scope:t,host:f}),c=t(e||void 0);let p=b(c,a.F);if(c.nodeName==="#comment")break;let g=k.mark({type:"component",name:t.name,host:p?"this":"parentElement"});c.prepend(g),p&&(d=g);break}case t==="#text":c=N.call(this,a.D.createTextNode(""),e);break;case(t==="<>"||!t):c=N.call(this,a.D.createDocumentFragment(),e);break;case!!P:c=N.call(this,a.D.createElementNS(P,t),e);break;case!c:c=N.call(this,a.D.createElement(t),e)}return X(c),d||(d=c),n.forEach(f=>f(d)),o&&S.pop(),o=2,c}k.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=a.D.createComment(``);return e&&(r.end=a.D.createComment("")),r};function vt(t){let e=this;return function(...r){P=t;let o=k.call(e,...r);return P=void 0,o}}function mt(t,e=t){let n="\xB9\u2070",r="\u2713",o=Object.fromEntries(Array.from(e.querySelectorAll("slot")).filter(c=>!c.name.endsWith(n)).map(c=>[c.name+=n,c]));if(t.append=new Proxy(t.append,{apply(c,d,f){if(f[0]===e)return c.apply(t,f);for(let p of f){let g=(p.slot||"")+n;try{tt(p,"remove","slot")}catch{}let l=o[g];if(!l)return;l.name.startsWith(r)||(l.childNodes.forEach(E=>E.remove()),l.name=r+g),l.append(p)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}var M=new WeakMap,{setDeleteAttr:U}=a;function N(t,...e){if(!e.length)return t;M.set(t,B(t,this));for(let[n,r]of Object.entries(v({},...e)))z.call(this,t,n,r);return M.delete(t),t}function z(t,e,n){let{setRemoveAttr:r,s:o}=B(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(f,p)=>z.call(c,t,f,p));let[d]=e;if(d==="=")return r(e.slice(1),n);if(d===".")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(),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 U(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return j(o,e,t,n,H.bind(null,t[e]));case"ariaset":return j(o,e,t,n,(f,p)=>r("aria-"+f,p));case"classList":return Y.call(c,t,n)}return et(t,e)?U(t,e,n):r(e,n)}function B(t,e){if(M.has(t))return M.get(t);let r=(b(t,a.S)?rt:nt).bind(null,t,"Attribute"),o=T(e);return{setRemoveAttr:r,s:o}}function Y(t,e){let n=T(this);return j(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function tt(t,e,n,r){return b(t,a.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function et(t,e){if(!(e in t))return!1;let n=Z(t,e);return!w(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 j(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([f,p]){f&&(f=new c(f),f.target=e,p=t.processReactiveAttribute(n,f,p,o),o(f,p))})}function nt(t,e,n,r){return t[(w(r)?"remove":"set")+e](n,r)}function rt(t,e,n,r,o=null){return t[(w(r)?"remove":"set")+e+"NS"](o,n,r)}function H(t,e,n){if(Reflect.set(t,e,n),!!w(n))return Reflect.deleteProperty(t,e)}var C=a.M?ot():new Proxy({},{get(){return()=>{}}});function ot(){let t=new Map,e=!1,n=s=>function(u){for(let i of u)if(i.type==="childList"){if(l(i.addedNodes,!0)){s();continue}E(i.removedNodes,!0)&&s()}},r=new a.M(n(f));return{observe(s){let u=new a.M(n(()=>{}));return u.observe(s,{childList:!0,subtree:!0}),()=>u.disconnect()},onConnected(s,u){d();let i=c(s);i.connected.has(u)||(i.connected.add(u),i.length_c+=1)},offConnected(s,u){if(!t.has(s))return;let i=t.get(s);i.connected.has(u)&&(i.connected.delete(u),i.length_c-=1,o(s,i))},onDisconnected(s,u){d();let i=c(s);i.disconnected.has(u)||(i.disconnected.add(u),i.length_d+=1)},offDisconnected(s,u){if(!t.has(s))return;let i=t.get(s);i.disconnected.delete(u),i.length_d-=1,o(s,i)}};function o(s,u){u.length_c||u.length_d||(t.delete(s),f())}function c(s){if(t.has(s))return t.get(s);let u={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(s,u),u}function d(){e||(e=!0,r.observe(a.D.body,{childList:!0,subtree:!0}))}function f(){!e||t.size||(e=!1,r.disconnect())}function p(){return new Promise(function(s){(requestIdleCallback||requestAnimationFrame)(s)})}async function g(s){t.size>30&&await p();let u=[];if(!b(s,Node))return u;for(let i of t.keys())i===s||!b(i,Node)||s.contains(i)&&u.push(i);return u}function l(s,u){let i=!1;for(let h of s){if(u&&g(h).then(l),!t.has(h))continue;let y=t.get(h);y.length_c&&(h.dispatchEvent(new Event(m)),y.connected=new WeakSet,y.length_c=0,y.length_d||t.delete(h),i=!0)}return i}function E(s,u){let i=!1;for(let h of s)u&&g(h).then(E),!(!t.has(h)||!t.get(h).length_d)&&((globalThis.queueMicrotask||setTimeout)(V(h)),i=!0);return i}function V(s){return()=>{s.isConnected||(s.dispatchEvent(new Event(_)),t.delete(s))}}}function Ot(t,e,n=st){let r=t.host||t;S.push({scope:r,host:(...d)=>d.length?d.forEach(f=>f(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[A];o||ct(r);let c=e.call(r,n);return o||r.dispatchEvent(new Event(m)),t.nodeType===11&&typeof t.mode=="string"&&r.addEventListener(_,C.observe(t),{once:!0}),S.pop(),t.append(c)}function ct(t){return W(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(m))}),W(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(_)))}),W(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(D,{detail:[o,c]})),e.apply(n,r)}),t.prototype[A]=!0,t}function W(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}function st(t){return I(t,(e,n)=>e.getAttribute(n))}function Tt(t,e,n){return typeof e=="function"&&(n=e,e=null),e||(e={}),function(o,...c){n&&(c.unshift(o),o=typeof n=="function"?n():n);let d=c.length?new CustomEvent(t,v({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(d)}}function L(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}var G=t=>v({},typeof t=="object"?t:null,{once:!0});L.connected=function(t,e){return e=G(e),function(r){return r.addEventListener(m,t,e),r[A]?r:r.isConnected?(r.dispatchEvent(new Event(m)),r):(R(e.signal,()=>C.offConnected(r,t))&&C.onConnected(r,t),r)}};L.disconnected=function(t,e){return e=G(e),function(r){return r.addEventListener(_,t,e),r[A]||R(e.signal,()=>C.offDisconnected(r,t))&&C.onDisconnected(r,t),r}};var q=new WeakMap;L.disconnectedAsAbort=function(t){if(q.has(t))return q.get(t);let e=new AbortController;return q.set(t,e),t(L.disconnected(()=>e.abort())),e.signal};var it=new WeakSet;L.attributeChanged=function(t,e){return typeof e!="object"&&(e={}),function(r){if(r.addEventListener(D,t,e),r[A]||it.has(r)||!a.M)return r;let o=new a.M(function(d){for(let{attributeName:f,target:p}of d)p.dispatchEvent(new CustomEvent(D,{detail:[f,p.getAttribute(f)]}))});return R(e.signal,()=>o.disconnect())&&o.observe(r,{attributes:!0}),r}};export{N as assign,z as assignAttribute,X as chainableAppend,Y as classListDeclarative,k as createElement,vt as createElementNS,Ot as customElementRender,ct as customElementWithDDE,Tt as dispatchEvent,k as el,vt as elNS,tt as elementAttribute,ct as lifecyclesToEvents,st as observedAttributes,L as on,gt as queue,K as registerReactivity,S as scope,mt as simulateSlots}; +function w(t){return typeof t>"u"}function g(t,e){return t instanceof e}function W(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function v(...t){return Object.assign(...t)}function P(t,e){if(!t||!g(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var C={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function V(t,e=!0){return e?v(C,t):(Object.setPrototypeOf(t,C),t)}function S(t){return W(t,C)&&t!==C?t:C}var a={setDeleteAttr:J,ssr:"",D:globalThis.document,F:globalThis.DocumentFragment,H:globalThis.HTMLElement,S:globalThis.SVGElement,M:globalThis.MutationObserver,q:t=>t||Promise.resolve()};function J(t,e,n){if(Reflect.set(t,e,n),!!w(n)){if(Reflect.deleteProperty(t,e),g(t,a.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var O="__dde_lifecyclesToEvents",m="dde:connected",_="dde:disconnected",F="dde:attributeChanged";function pt(t){return a.q(t)}var x=[{get scope(){return a.D.body},host:t=>t?t(a.D.body):a.D.body,prevent:!0}],D={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(v({},this.current,{prevent:!1},t))},pushRoot(){return x.push(x[0])},pop(){if(x.length!==1)return x.pop()}};function I(...t){return this.appendOriginal(...t),this}function K(t){return t.append===I||(t.appendOriginal=t.append,t.append=I),t}var R;function j(t,e,...n){let r=S(this),o=0,c,d;switch((Object(e)!==e||r.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1;let f=(...l)=>l.length?(o===1?n.unshift(...l):l.forEach(E=>E(d)),void 0):d;D.push({scope:t,host:f}),c=t(e||void 0);let p=g(c,a.F);if(c.nodeName==="#comment")break;let b=j.mark({type:"component",name:t.name,host:p?"this":"parentElement"});c.prepend(b),p&&(d=b);break}case t==="#text":c=L.call(this,a.D.createTextNode(""),e);break;case(t==="<>"||!t):c=L.call(this,a.D.createDocumentFragment(),e);break;case!!R:c=L.call(this,a.D.createElementNS(R,t),e);break;case!c:c=L.call(this,a.D.createElement(t),e)}return K(c),d||(d=c),n.forEach(f=>f(d)),o&&D.pop(),o=2,c}j.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=a.D.createComment(``);return e&&(r.end=a.D.createComment("")),r};function lt(t){let e=this;return function(...r){R=t;let o=j.call(e,...r);return R=void 0,o}}function ht(t,e=t){let n="\xB9\u2070",r="\u2713",o=Object.fromEntries(Array.from(e.querySelectorAll("slot")).filter(c=>!c.name.endsWith(n)).map(c=>[c.name+=n,c]));if(t.append=new Proxy(t.append,{apply(c,d,f){if(f[0]===e)return c.apply(t,f);for(let p of f){let b=(p.slot||"")+n;try{X(p,"remove","slot")}catch{}let l=o[b];if(!l)return;l.name.startsWith(r)||(l.childNodes.forEach(E=>E.remove()),l.name=r+b),l.append(p)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}var T=new WeakMap,{setDeleteAttr:$}=a;function L(t,...e){if(!e.length)return t;T.set(t,z(t,this));for(let[n,r]of Object.entries(v({},...e)))H.call(this,t,n,r);return T.delete(t),t}function H(t,e,n){let{setRemoveAttr:r,s:o}=z(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(f,p)=>H.call(c,t,f,p));let[d]=e;if(d==="=")return r(e.slice(1),n);if(d===".")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(),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 $(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return M(o,e,t,n,U.bind(null,t[e]));case"ariaset":return M(o,e,t,n,(f,p)=>r("aria-"+f,p));case"classList":return Q.call(c,t,n)}return Y(t,e)?$(t,e,n):r(e,n)}function z(t,e){if(T.has(t))return T.get(t);let r=(g(t,a.S)?et:tt).bind(null,t,"Attribute"),o=S(e);return{setRemoveAttr:r,s:o}}function Q(t,e){let n=S(this);return M(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function X(t,e,n,r){return g(t,a.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function Y(t,e){if(!(e in t))return!1;let n=B(t,e);return!w(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 M(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([f,p]){f&&(f=new c(f),f.target=e,p=t.processReactiveAttribute(n,f,p,o),o(f,p))})}function tt(t,e,n,r){return t[(w(r)?"remove":"set")+e](n,r)}function et(t,e,n,r,o=null){return t[(w(r)?"remove":"set")+e+"NS"](o,n,r)}function U(t,e,n){if(Reflect.set(t,e,n),!!w(n))return Reflect.deleteProperty(t,e)}var A=a.M?nt():new Proxy({},{get(){return()=>{}}});function nt(){let t=new Map,e=!1,n=s=>function(u){for(let i of u)if(i.type==="childList"){if(l(i.addedNodes,!0)){s();continue}E(i.removedNodes,!0)&&s()}},r=new a.M(n(f));return{observe(s){let u=new a.M(n(()=>{}));return u.observe(s,{childList:!0,subtree:!0}),()=>u.disconnect()},onConnected(s,u){d();let i=c(s);i.connected.has(u)||(i.connected.add(u),i.length_c+=1)},offConnected(s,u){if(!t.has(s))return;let i=t.get(s);i.connected.has(u)&&(i.connected.delete(u),i.length_c-=1,o(s,i))},onDisconnected(s,u){d();let i=c(s);i.disconnected.has(u)||(i.disconnected.add(u),i.length_d+=1)},offDisconnected(s,u){if(!t.has(s))return;let i=t.get(s);i.disconnected.delete(u),i.length_d-=1,o(s,i)}};function o(s,u){u.length_c||u.length_d||(t.delete(s),f())}function c(s){if(t.has(s))return t.get(s);let u={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(s,u),u}function d(){e||(e=!0,r.observe(a.D.body,{childList:!0,subtree:!0}))}function f(){!e||t.size||(e=!1,r.disconnect())}function p(){return new Promise(function(s){(requestIdleCallback||requestAnimationFrame)(s)})}async function b(s){t.size>30&&await p();let u=[];if(!g(s,Node))return u;for(let i of t.keys())i===s||!g(i,Node)||s.contains(i)&&u.push(i);return u}function l(s,u){let i=!1;for(let h of s){if(u&&b(h).then(l),!t.has(h))continue;let y=t.get(h);y.length_c&&(h.dispatchEvent(new Event(m)),y.connected=new WeakSet,y.length_c=0,y.length_d||t.delete(h),i=!0)}return i}function E(s,u){let i=!1;for(let h of s)u&&b(h).then(E),!(!t.has(h)||!t.get(h).length_d)&&((globalThis.queueMicrotask||setTimeout)(G(h)),i=!0);return i}function G(s){return()=>{s.isConnected||(s.dispatchEvent(new Event(_)),t.delete(s))}}}function _t(t,e,n={}){let r=t.host||t;D.push({scope:r,host:(...d)=>d.length?d.forEach(f=>f(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[O];o||rt(r);let c=e.call(r,n);return o||r.dispatchEvent(new Event(m)),t.nodeType===11&&typeof t.mode=="string"&&r.addEventListener(_,A.observe(t),{once:!0}),D.pop(),t.append(c)}function rt(t){return k(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(m))}),k(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(_)))}),k(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(F,{detail:[o,c]})),e.apply(n,r)}),t.prototype[O]=!0,t}function k(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}function St(t,e,n){return typeof e=="function"&&(n=e,e=null),e||(e={}),function(o,...c){n&&(c.unshift(o),o=typeof n=="function"?n():n);let d=c.length?new CustomEvent(t,v({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(d)}}function N(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}var Z=t=>v({},typeof t=="object"?t:null,{once:!0});N.connected=function(t,e){return e=Z(e),function(r){return r.addEventListener(m,t,e),r[O]?r:r.isConnected?(r.dispatchEvent(new Event(m)),r):(P(e.signal,()=>A.offConnected(r,t))&&A.onConnected(r,t),r)}};N.disconnected=function(t,e){return e=Z(e),function(r){return r.addEventListener(_,t,e),r[O]||P(e.signal,()=>A.offDisconnected(r,t))&&A.onDisconnected(r,t),r}};var q=new WeakMap;N.disconnectedAsAbort=function(t){if(q.has(t))return q.get(t);let e=new AbortController;return q.set(t,e),t(N.disconnected(()=>e.abort())),e.signal};export{L as assign,H as assignAttribute,K as chainableAppend,Q as classListDeclarative,j as createElement,lt as createElementNS,_t as customElementRender,rt as customElementWithDDE,St as dispatchEvent,j as el,lt as elNS,X as elementAttribute,rt as lifecyclesToEvents,N as on,pt as queue,V as registerReactivity,D as scope,ht as simulateSlots}; diff --git a/dist/iife-with-signals.d.ts b/dist/iife-with-signals.d.ts index 2ba7d95..b461bd9 100644 --- a/dist/iife-with-signals.d.ts +++ b/dist/iife-with-signals.d.ts @@ -214,7 +214,6 @@ export const scope: { export function customElementRender>>(target: ShadowRoot | EL, render: (props: P) => SupportedElement | DocumentFragment, props?: P | ((el: EL) => P)): EL; export function customElementWithDDE HTMLElement)>(custom_element: EL): EL; export function lifecyclesToEvents HTMLElement)>(custom_element: EL): EL; -export function observedAttributes(custom_element: HTMLElement): Record; /** * This is used primarly for server side rendering. To be sure that all async operations * are finished before the page is sent to the client. diff --git a/dist/iife-with-signals.js b/dist/iife-with-signals.js index 3b4c152..09a63b5 100644 --- a/dist/iife-with-signals.js +++ b/dist/iife-with-signals.js @@ -35,7 +35,6 @@ var DDE = (() => { elementAttribute: () => elementAttribute, isSignal: () => isSignal, lifecyclesToEvents: () => lifecyclesToEvents, - observedAttributes: () => observedAttributes2, on: () => on, queue: () => queue, registerReactivity: () => registerReactivity, @@ -78,8 +77,8 @@ var DDE = (() => { }; } function observedAttributes(instance, observedAttribute2) { - const { observedAttributes: observedAttributes3 = [] } = instance.constructor; - return observedAttributes3.reduce(function(out, name) { + const { observedAttributes: observedAttributes2 = [] } = instance.constructor; + return observedAttributes2.reduce(function(out, name) { out[kebabToCamel(name)] = observedAttribute2(instance, name); return out; }, {}); @@ -591,7 +590,7 @@ var DDE = (() => { } // src/customElement.js - function customElementRender(target, render, props = observedAttributes2) { + function customElementRender(target, render, props = {}) { const custom_element = target.host || target; scope.push({ scope: custom_element, @@ -632,9 +631,6 @@ var DDE = (() => { obj[method] = new Proxy(obj[method] || (() => { }), { apply }); } - function observedAttributes2(instance) { - return observedAttributes(instance, (i, n) => i.getAttribute(n)); - } // src/events.js function dispatchEvent(name, options, host) { @@ -688,26 +684,6 @@ var DDE = (() => { host(on.disconnected(() => a.abort())); return a.signal; }; - var els_attribute_store = /* @__PURE__ */ new WeakSet(); - on.attributeChanged = function(listener, options) { - if (typeof options !== "object") - options = {}; - return function registerElement(element) { - element.addEventListener(eva, listener, options); - if (element[keyLTE] || els_attribute_store.has(element)) - return element; - if (!enviroment.M) return element; - const observer = new enviroment.M(function(mutations) { - for (const { attributeName, target } of mutations) - target.dispatchEvent( - new CustomEvent(eva, { detail: [attributeName, target.getAttribute(attributeName)] }) - ); - }); - const c = onAbort(options.signal, () => observer.disconnect()); - if (c) observer.observe(element, { attributes: true }); - return element; - }; - }; // src/signals-lib/helpers.js var mark = "__dde_signal"; @@ -892,7 +868,7 @@ var DDE = (() => { signal.observedAttributes = function(element) { const store = element[key_attributes] = {}; const attrs = observedAttributes(element, observedAttribute(store)); - on.attributeChanged(function attributeChangeToSignal({ detail }) { + on(eva, function attributeChangeToSignal({ detail }) { /*! This maps attributes to signals (`S.observedAttributes`). Investigate `__dde_attributes` key of the element. */ const [name, value] = detail; diff --git a/dist/iife-with-signals.min.d.ts b/dist/iife-with-signals.min.d.ts index 2ba7d95..b461bd9 100644 --- a/dist/iife-with-signals.min.d.ts +++ b/dist/iife-with-signals.min.d.ts @@ -214,7 +214,6 @@ export const scope: { export function customElementRender>>(target: ShadowRoot | EL, render: (props: P) => SupportedElement | DocumentFragment, props?: P | ((el: EL) => P)): EL; export function customElementWithDDE HTMLElement)>(custom_element: EL): EL; export function lifecyclesToEvents HTMLElement)>(custom_element: EL): EL; -export function observedAttributes(custom_element: HTMLElement): Record; /** * This is used primarly for server side rendering. To be sure that all async operations * are finished before the page is sent to the client. diff --git a/dist/iife-with-signals.min.js b/dist/iife-with-signals.min.js index 7adc820..50074dc 100644 --- a/dist/iife-with-signals.min.js +++ b/dist/iife-with-signals.min.js @@ -1,4 +1,4 @@ -var DDE=(()=>{var G=Object.defineProperty;var wt=Object.getOwnPropertyDescriptor;var At=Object.getOwnPropertyNames;var yt=Object.prototype.hasOwnProperty;var Ct=(t,e)=>{for(var n in e)G(t,n,{get:e[n],enumerable:!0})},Ot=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of At(e))!yt.call(t,o)&&o!==n&&G(t,o,{get:()=>e[o],enumerable:!(r=wt(e,o))||r.enumerable});return t};var Dt=t=>Ot(G({},"__esModule",{value:!0}),t);var Vt={};Ct(Vt,{S:()=>g,assign:()=>F,assignAttribute:()=>Q,chainableAppend:()=>ft,classListDeclarative:()=>dt,createElement:()=>N,createElementNS:()=>Mt,customElementRender:()=>Wt,customElementWithDDE:()=>ht,dispatchEvent:()=>Ft,el:()=>N,elNS:()=>Mt,elementAttribute:()=>lt,isSignal:()=>I,lifecyclesToEvents:()=>ht,observedAttributes:()=>gt,on:()=>E,queue:()=>kt,registerReactivity:()=>z,scope:()=>b,signal:()=>g,simulateSlots:()=>Nt});var V=(...t)=>Object.prototype.hasOwnProperty.call(...t);function O(t){return typeof t>"u"}function ot(t){let e=typeof t;return e!=="object"?e:t===null?"null":Object.prototype.toString.call(t)}function w(t,e){return t instanceof e}function ct(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function A(t=null,e={}){return Object.create(t,e)}function x(...t){return Object.assign(...t)}function $(t,e){if(!t||!w(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}function U(t,e){let{observedAttributes:n=[]}=t.constructor;return n.reduce(function(r,o){return r[Rt(o)]=e(t,o),r},{})}function Rt(t){return t.replace(/-./g,e=>e[1].toUpperCase())}var j=class extends Error{constructor(){super();let[e,...n]=this.stack.split(` -`),r=e.slice(e.indexOf("@"),e.indexOf(".js:")+4),o=r.includes("src/helpers.js")?"src/":r;this.stack=n.find(c=>!c.includes(o))||e}get compact(){let{stack:e}=this;return e.slice(0,e.indexOf("@")+1)+"\u2026"+e.slice(e.lastIndexOf("/"))}};var q={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function z(t,e=!0){return e?x(q,t):(Object.setPrototypeOf(t,q),t)}function H(t){return ct(t,q)&&t!==q?t:q}var d={setDeleteAttr:Lt,ssr:"",D:globalThis.document,F:globalThis.DocumentFragment,H:globalThis.HTMLElement,S:globalThis.SVGElement,M:globalThis.MutationObserver,q:t=>t||Promise.resolve()};function Lt(t,e,n){if(Reflect.set(t,e,n),!!O(n)){if(Reflect.deleteProperty(t,e),w(t,d.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var D="__dde_lifecyclesToEvents",y="dde:connected",R="dde:disconnected",W="dde:attributeChanged";function kt(t){return d.q(t)}var C=[{get scope(){return d.D.body},host:t=>t?t(d.D.body):d.D.body,prevent:!0}],b={get current(){return C[C.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...C]},push(t={}){return C.push(x({},this.current,{prevent:!1},t))},pushRoot(){return C.push(C[0])},pop(){if(C.length!==1)return C.pop()}};function st(...t){return this.appendOriginal(...t),this}function ft(t){return t.append===st||(t.appendOriginal=t.append,t.append=st),t}var B;function N(t,e,...n){let r=H(this),o=0,c,s;switch((Object(e)!==e||r.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1;let i=(...h)=>h.length?(o===1?n.unshift(...h):h.forEach(m=>m(s)),void 0):s;b.push({scope:t,host:i}),c=t(e||void 0);let l=w(c,d.F);if(c.nodeName==="#comment")break;let _=N.mark({type:"component",name:t.name,host:l?"this":"parentElement"});c.prepend(_),l&&(s=_);break}case t==="#text":c=F.call(this,d.D.createTextNode(""),e);break;case(t==="<>"||!t):c=F.call(this,d.D.createDocumentFragment(),e);break;case!!B:c=F.call(this,d.D.createElementNS(B,t),e);break;case!c:c=F.call(this,d.D.createElement(t),e)}return ft(c),s||(s=c),n.forEach(i=>i(s)),o&&b.pop(),o=2,c}N.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=d.D.createComment(``);return e&&(r.end=d.D.createComment("")),r};function Mt(t){let e=this;return function(...r){B=t;let o=N.call(e,...r);return B=void 0,o}}function Nt(t,e=t){let n="\xB9\u2070",r="\u2713",o=Object.fromEntries(Array.from(e.querySelectorAll("slot")).filter(c=>!c.name.endsWith(n)).map(c=>[c.name+=n,c]));if(t.append=new Proxy(t.append,{apply(c,s,i){if(i[0]===e)return c.apply(t,i);for(let l of i){let _=(l.slot||"")+n;try{lt(l,"remove","slot")}catch{}let h=o[_];if(!h)return;h.name.startsWith(r)||(h.childNodes.forEach(m=>m.remove()),h.name=r+_),h.append(l)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}var J=new WeakMap,{setDeleteAttr:it}=d;function F(t,...e){if(!e.length)return t;J.set(t,at(t,this));for(let[n,r]of Object.entries(x({},...e)))Q.call(this,t,n,r);return J.delete(t),t}function Q(t,e,n){let{setRemoveAttr:r,s:o}=at(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(i,l)=>Q.call(c,t,i,l));let[s]=e;if(s==="=")return r(e.slice(1),n);if(s===".")return ut(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 it(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return K(o,e,t,n,ut.bind(null,t[e]));case"ariaset":return K(o,e,t,n,(i,l)=>r("aria-"+i,l));case"classList":return dt.call(c,t,n)}return Tt(t,e)?it(t,e,n):r(e,n)}function at(t,e){if(J.has(t))return J.get(t);let r=(w(t,d.S)?jt:Pt).bind(null,t,"Attribute"),o=H(e);return{setRemoveAttr:r,s:o}}function dt(t,e){let n=H(this);return K(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function lt(t,e,n,r){return w(t,d.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function Tt(t,e){if(!(e in t))return!1;let n=pt(t,e);return!O(n.set)}function pt(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||pt(t,e)}function K(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([i,l]){i&&(i=new c(i),i.target=e,l=t.processReactiveAttribute(n,i,l,o),o(i,l))})}function Pt(t,e,n,r){return t[(O(r)?"remove":"set")+e](n,r)}function jt(t,e,n,r,o=null){return t[(O(r)?"remove":"set")+e+"NS"](o,n,r)}function ut(t,e,n){if(Reflect.set(t,e,n),!!O(n))return Reflect.deleteProperty(t,e)}var L=d.M?qt():new Proxy({},{get(){return()=>{}}});function qt(){let t=new Map,e=!1,n=u=>function(a){for(let f of a)if(f.type==="childList"){if(h(f.addedNodes,!0)){u();continue}m(f.removedNodes,!0)&&u()}},r=new d.M(n(i));return{observe(u){let a=new d.M(n(()=>{}));return a.observe(u,{childList:!0,subtree:!0}),()=>a.disconnect()},onConnected(u,a){s();let f=c(u);f.connected.has(a)||(f.connected.add(a),f.length_c+=1)},offConnected(u,a){if(!t.has(u))return;let f=t.get(u);f.connected.has(a)&&(f.connected.delete(a),f.length_c-=1,o(u,f))},onDisconnected(u,a){s();let f=c(u);f.disconnected.has(a)||(f.disconnected.add(a),f.length_d+=1)},offDisconnected(u,a){if(!t.has(u))return;let f=t.get(u);f.disconnected.delete(a),f.length_d-=1,o(u,f)}};function o(u,a){a.length_c||a.length_d||(t.delete(u),i())}function c(u){if(t.has(u))return t.get(u);let a={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(u,a),a}function s(){e||(e=!0,r.observe(d.D.body,{childList:!0,subtree:!0}))}function i(){!e||t.size||(e=!1,r.disconnect())}function l(){return new Promise(function(u){(requestIdleCallback||requestAnimationFrame)(u)})}async function _(u){t.size>30&&await l();let a=[];if(!w(u,Node))return a;for(let f of t.keys())f===u||!w(f,Node)||u.contains(f)&&a.push(f);return a}function h(u,a){let f=!1;for(let S of u){if(a&&_(S).then(h),!t.has(S))continue;let P=t.get(S);P.length_c&&(S.dispatchEvent(new Event(y)),P.connected=new WeakSet,P.length_c=0,P.length_d||t.delete(S),f=!0)}return f}function m(u,a){let f=!1;for(let S of u)a&&_(S).then(m),!(!t.has(S)||!t.get(S).length_d)&&((globalThis.queueMicrotask||setTimeout)(T(S)),f=!0);return f}function T(u){return()=>{u.isConnected||(u.dispatchEvent(new Event(R)),t.delete(u))}}}function Wt(t,e,n=gt){let r=t.host||t;b.push({scope:r,host:(...s)=>s.length?s.forEach(i=>i(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[D];o||ht(r);let c=e.call(r,n);return o||r.dispatchEvent(new Event(y)),t.nodeType===11&&typeof t.mode=="string"&&r.addEventListener(R,L.observe(t),{once:!0}),b.pop(),t.append(c)}function ht(t){return X(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(y))}),X(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(R)))}),X(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(W,{detail:[o,c]})),e.apply(n,r)}),t.prototype[D]=!0,t}function X(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}function gt(t){return U(t,(e,n)=>e.getAttribute(n))}function Ft(t,e,n){return typeof e=="function"&&(n=e,e=null),e||(e={}),function(o,...c){n&&(c.unshift(o),o=typeof n=="function"?n():n);let s=c.length?new CustomEvent(t,x({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(s)}}function E(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}var bt=t=>x({},typeof t=="object"?t:null,{once:!0});E.connected=function(t,e){return e=bt(e),function(r){return r.addEventListener(y,t,e),r[D]?r:r.isConnected?(r.dispatchEvent(new Event(y)),r):($(e.signal,()=>L.offConnected(r,t))&&L.onConnected(r,t),r)}};E.disconnected=function(t,e){return e=bt(e),function(r){return r.addEventListener(R,t,e),r[D]||$(e.signal,()=>L.offDisconnected(r,t))&&L.onDisconnected(r,t),r}};var Y=new WeakMap;E.disconnectedAsAbort=function(t){if(Y.has(t))return Y.get(t);let e=new AbortController;return Y.set(t,e),t(E.disconnected(()=>e.abort())),e.signal};var It=new WeakSet;E.attributeChanged=function(t,e){return typeof e!="object"&&(e={}),function(r){if(r.addEventListener(W,t,e),r[D]||It.has(r)||!d.M)return r;let o=new d.M(function(s){for(let{attributeName:i,target:l}of s)l.dispatchEvent(new CustomEvent(W,{detail:[i,l.getAttribute(i)]}))});return $(e.signal,()=>o.disconnect())&&o.observe(r,{attributes:!0}),r}};var p="__dde_signal",tt=(()=>{let t=new Set,e=!1;function n(){e=!1;let r=t;t=new Set;for(let o of r){let c=o[p];c&&c.listeners.forEach(s=>s(c.value))}}return function(r){t.add(r),!e&&(e=!0,queueMicrotask(n))}})();var nt=A(null,{get:{value(){return mt(this)}},set:{value(...t){return St(this,...t)}},toJSON:{value(){return mt(this)}},valueOf:{value(){return this[p]&&this[p].value}}}),$t=A(nt,{set:{value(){}}});function I(t){return t&&t[p]}var Z=[],v=new WeakMap;function g(t,e){if(typeof t!="function")return vt(!1,t,e);if(I(t))return t;let n=vt(!0);function r(){let[o,...c]=v.get(r);if(v.set(r,new Set([o])),Z.push(r),St(n,t()),Z.pop(),!c.length)return;let s=v.get(r);for(let i of c)s.has(i)||M(i,r)}return v.set(n[p],r),v.set(r,new Set([n])),r(),n}g.action=function(t,e,...n){let r=t[p];if(!r)return;let{actions:o}=r;if(!o||!V(o,e))throw new Error(`Action "${e}" not defined. See ${p}.actions.`);if(o[e].apply(r,n),r.skip)return delete r.skip;tt(t)};g.on=function t(e,n,r={}){let{signal:o}=r;if(!(o&&o.aborted)){if(Array.isArray(e))return e.forEach(c=>t(c,n,r));rt(e,n),o&&o.addEventListener("abort",()=>M(e,n))}};g.symbols={onclear:Symbol.for("Signal.onclear")};g.clear=function(...t){for(let n of t){let r=n[p];r&&(delete n.toJSON,r.onclear.forEach(o=>o.call(r)),e(n,r),delete n[p])}function e(n,r){r.listeners.forEach(o=>{if(r.listeners.delete(o),!v.has(o))return;let c=v.get(o);c.delete(n),!(c.size>1)&&(n.clear(...c),v.delete(o))})}};var k="__dde_reactive";function Ut(t=A()){return(e,n)=>V(t,e)?t[e]:t[e]=n()}g.el=function(t,e){let n=N.mark({type:"reactive",source:new j().compact},!0),r=n.end,o=d.D.createDocumentFragment();o.append(n,r);let{current:c}=b,s=A(),i=l=>{if(!n.parentNode||!r.parentNode)return M(t,i);let _=Ut(s);s=A(),b.push(c);let h=e(l,function(a,f){return s[a]=_(a,f)});b.pop(),Array.isArray(h)||(h=[h]);let m=document.createComment("");h.push(m),n.after(...h);let T;for(;(T=m.nextSibling)&&T!==r;)T.remove();m.remove(),n.isConnected&&zt(c.host())};return rt(t,i),Et(t,i,n,e),i(t.get()),c.host(E.disconnected(()=>s={})),o};function zt(t){!t||!t[k]||(requestIdleCallback||setTimeout)(function(){t[k]=t[k].filter(([e,n])=>n.isConnected?!0:(M(...e),!1))})}var Ht={_set(t){this.value=t}};function Bt(t){return function(e,n){let r=A(nt,{set:{value(...c){return e.setAttribute(n,...c)}}}),o=_t(r,e.getAttribute(n),Ht);return t[n]=o,o}}var et="__dde_attributes";g.observedAttributes=function(t){let e=t[et]={},n=U(t,Bt(e));return E.attributeChanged(function({detail:o}){/*! This maps attributes to signals (`S.observedAttributes`). - Investigate `__dde_attributes` key of the element. */let[c,s]=o,i=this[et][c];if(i)return g.action(i,"_set",s)})(t),E.disconnected(function(){/*! This removes all signals mapped to attributes (`S.observedAttributes`). - Investigate `__dde_attributes` key of the element. */g.clear(...Object.values(this[et]))})(t),n};var xt={isSignal:I,processReactiveAttribute(t,e,n,r){if(!I(n))return n;let o=c=>{if(!t.isConnected)return M(n,o);r(e,c)};return rt(n,o),Et(n,o,t,e),n.get()}};function Et(t,e,...n){let{current:r}=b;r.host(function(o){if(o[k])return o[k].push([[t,e],...n]);o[k]=[],!r.prevent&&E.disconnected(()=>o[k].forEach(([[c,s]])=>M(c,s,c[p]&&c[p].host&&c[p].host()===o)))(o)})}var Jt=new FinalizationRegistry(function(t){g.clear({[p]:t})});function vt(t,e,n){let r=A(t?$t:nt),o=_t(r,e,n,t);return Jt.register(o,o[p]),o}var Zt=x(A(),{stopPropagation(){this.skip=!0}});function _t(t,e,n,r=!1){let o=[];ot(n)!=="[object Object]"&&(n={});let{onclear:c}=g.symbols;n[c]&&(o.push(n[c]),delete n[c]);let{host:s}=b;return Reflect.defineProperty(t,p,{value:x(A(Zt),{value:e,actions:n,onclear:o,host:s,listeners:new Set,defined:new j().stack,readonly:r}),enumerable:!1,writable:!1,configurable:!0}),t}function Gt(){return Z[Z.length-1]}function mt(t){if(!t[p])return;let{value:e,listeners:n}=t[p],r=Gt();return r&&n.add(r),v.has(r)&&v.get(r).add(t),e}function St(t,e,n){let r=t[p];if(!(!r||!n&&r.value===e))return r.value=e,tt(t),e}function rt(t,e){if(t[p])return t[p].listeners.add(e)}function M(t,e,n){let r=t[p];if(!r)return;let{listeners:o}=r,c=o.delete(e);if(!c||!n||o.size)return c;g.clear(t);let s=v.get(r);if(!s)return c;let i=v.get(s);if(!i)return c;for(let l of i)M(l,s,!0);return c}z(xt);return Dt(Vt);})(); +var DDE=(()=>{var J=Object.defineProperty;var St=Object.getOwnPropertyDescriptor;var wt=Object.getOwnPropertyNames;var At=Object.prototype.hasOwnProperty;var yt=(t,e)=>{for(var n in e)J(t,n,{get:e[n],enumerable:!0})},Ct=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of wt(e))!At.call(t,o)&&o!==n&&J(t,o,{get:()=>e[o],enumerable:!(r=St(e,o))||r.enumerable});return t};var Ot=t=>Ct(J({},"__esModule",{value:!0}),t);var Zt={};yt(Zt,{S:()=>g,assign:()=>W,assignAttribute:()=>K,chainableAppend:()=>ft,classListDeclarative:()=>dt,createElement:()=>T,createElementNS:()=>kt,customElementRender:()=>jt,customElementWithDDE:()=>ht,dispatchEvent:()=>Wt,el:()=>T,elNS:()=>kt,elementAttribute:()=>lt,isSignal:()=>F,lifecyclesToEvents:()=>ht,on:()=>A,queue:()=>Lt,registerReactivity:()=>I,scope:()=>m,signal:()=>g,simulateSlots:()=>Nt});var Z=(...t)=>Object.prototype.hasOwnProperty.call(...t);function O(t){return typeof t>"u"}function rt(t){let e=typeof t;return e!=="object"?e:t===null?"null":Object.prototype.toString.call(t)}function S(t,e){return t instanceof e}function ot(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function w(t=null,e={}){return Object.create(t,e)}function x(...t){return Object.assign(...t)}function G(t,e){if(!t||!S(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}function ct(t,e){let{observedAttributes:n=[]}=t.constructor;return n.reduce(function(r,o){return r[Dt(o)]=e(t,o),r},{})}function Dt(t){return t.replace(/-./g,e=>e[1].toUpperCase())}var q=class extends Error{constructor(){super();let[e,...n]=this.stack.split(` +`),r=e.slice(e.indexOf("@"),e.indexOf(".js:")+4),o=r.includes("src/helpers.js")?"src/":r;this.stack=n.find(c=>!c.includes(o))||e}get compact(){let{stack:e}=this;return e.slice(0,e.indexOf("@")+1)+"\u2026"+e.slice(e.lastIndexOf("/"))}};var j={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function I(t,e=!0){return e?x(j,t):(Object.setPrototypeOf(t,j),t)}function $(t){return ot(t,j)&&t!==j?t:j}var d={setDeleteAttr:Rt,ssr:"",D:globalThis.document,F:globalThis.DocumentFragment,H:globalThis.HTMLElement,S:globalThis.SVGElement,M:globalThis.MutationObserver,q:t=>t||Promise.resolve()};function Rt(t,e,n){if(Reflect.set(t,e,n),!!O(n)){if(Reflect.deleteProperty(t,e),S(t,d.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var N="__dde_lifecyclesToEvents",y="dde:connected",D="dde:disconnected",U="dde:attributeChanged";function Lt(t){return d.q(t)}var C=[{get scope(){return d.D.body},host:t=>t?t(d.D.body):d.D.body,prevent:!0}],m={get current(){return C[C.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...C]},push(t={}){return C.push(x({},this.current,{prevent:!1},t))},pushRoot(){return C.push(C[0])},pop(){if(C.length!==1)return C.pop()}};function st(...t){return this.appendOriginal(...t),this}function ft(t){return t.append===st||(t.appendOriginal=t.append,t.append=st),t}var z;function T(t,e,...n){let r=$(this),o=0,c,s;switch((Object(e)!==e||r.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1;let i=(...h)=>h.length?(o===1?n.unshift(...h):h.forEach(b=>b(s)),void 0):s;m.push({scope:t,host:i}),c=t(e||void 0);let p=S(c,d.F);if(c.nodeName==="#comment")break;let E=T.mark({type:"component",name:t.name,host:p?"this":"parentElement"});c.prepend(E),p&&(s=E);break}case t==="#text":c=W.call(this,d.D.createTextNode(""),e);break;case(t==="<>"||!t):c=W.call(this,d.D.createDocumentFragment(),e);break;case!!z:c=W.call(this,d.D.createElementNS(z,t),e);break;case!c:c=W.call(this,d.D.createElement(t),e)}return ft(c),s||(s=c),n.forEach(i=>i(s)),o&&m.pop(),o=2,c}T.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=d.D.createComment(``);return e&&(r.end=d.D.createComment("")),r};function kt(t){let e=this;return function(...r){z=t;let o=T.call(e,...r);return z=void 0,o}}function Nt(t,e=t){let n="\xB9\u2070",r="\u2713",o=Object.fromEntries(Array.from(e.querySelectorAll("slot")).filter(c=>!c.name.endsWith(n)).map(c=>[c.name+=n,c]));if(t.append=new Proxy(t.append,{apply(c,s,i){if(i[0]===e)return c.apply(t,i);for(let p of i){let E=(p.slot||"")+n;try{lt(p,"remove","slot")}catch{}let h=o[E];if(!h)return;h.name.startsWith(r)||(h.childNodes.forEach(b=>b.remove()),h.name=r+E),h.append(p)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}var H=new WeakMap,{setDeleteAttr:it}=d;function W(t,...e){if(!e.length)return t;H.set(t,at(t,this));for(let[n,r]of Object.entries(x({},...e)))K.call(this,t,n,r);return H.delete(t),t}function K(t,e,n){let{setRemoveAttr:r,s:o}=at(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(i,p)=>K.call(c,t,i,p));let[s]=e;if(s==="=")return r(e.slice(1),n);if(s===".")return ut(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 it(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return V(o,e,t,n,ut.bind(null,t[e]));case"ariaset":return V(o,e,t,n,(i,p)=>r("aria-"+i,p));case"classList":return dt.call(c,t,n)}return Tt(t,e)?it(t,e,n):r(e,n)}function at(t,e){if(H.has(t))return H.get(t);let r=(S(t,d.S)?Pt:Mt).bind(null,t,"Attribute"),o=$(e);return{setRemoveAttr:r,s:o}}function dt(t,e){let n=$(this);return V(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function lt(t,e,n,r){return S(t,d.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function Tt(t,e){if(!(e in t))return!1;let n=pt(t,e);return!O(n.set)}function pt(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||pt(t,e)}function V(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([i,p]){i&&(i=new c(i),i.target=e,p=t.processReactiveAttribute(n,i,p,o),o(i,p))})}function Mt(t,e,n,r){return t[(O(r)?"remove":"set")+e](n,r)}function Pt(t,e,n,r,o=null){return t[(O(r)?"remove":"set")+e+"NS"](o,n,r)}function ut(t,e,n){if(Reflect.set(t,e,n),!!O(n))return Reflect.deleteProperty(t,e)}var R=d.M?qt():new Proxy({},{get(){return()=>{}}});function qt(){let t=new Map,e=!1,n=u=>function(a){for(let f of a)if(f.type==="childList"){if(h(f.addedNodes,!0)){u();continue}b(f.removedNodes,!0)&&u()}},r=new d.M(n(i));return{observe(u){let a=new d.M(n(()=>{}));return a.observe(u,{childList:!0,subtree:!0}),()=>a.disconnect()},onConnected(u,a){s();let f=c(u);f.connected.has(a)||(f.connected.add(a),f.length_c+=1)},offConnected(u,a){if(!t.has(u))return;let f=t.get(u);f.connected.has(a)&&(f.connected.delete(a),f.length_c-=1,o(u,f))},onDisconnected(u,a){s();let f=c(u);f.disconnected.has(a)||(f.disconnected.add(a),f.length_d+=1)},offDisconnected(u,a){if(!t.has(u))return;let f=t.get(u);f.disconnected.delete(a),f.length_d-=1,o(u,f)}};function o(u,a){a.length_c||a.length_d||(t.delete(u),i())}function c(u){if(t.has(u))return t.get(u);let a={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(u,a),a}function s(){e||(e=!0,r.observe(d.D.body,{childList:!0,subtree:!0}))}function i(){!e||t.size||(e=!1,r.disconnect())}function p(){return new Promise(function(u){(requestIdleCallback||requestAnimationFrame)(u)})}async function E(u){t.size>30&&await p();let a=[];if(!S(u,Node))return a;for(let f of t.keys())f===u||!S(f,Node)||u.contains(f)&&a.push(f);return a}function h(u,a){let f=!1;for(let _ of u){if(a&&E(_).then(h),!t.has(_))continue;let P=t.get(_);P.length_c&&(_.dispatchEvent(new Event(y)),P.connected=new WeakSet,P.length_c=0,P.length_d||t.delete(_),f=!0)}return f}function b(u,a){let f=!1;for(let _ of u)a&&E(_).then(b),!(!t.has(_)||!t.get(_).length_d)&&((globalThis.queueMicrotask||setTimeout)(M(_)),f=!0);return f}function M(u){return()=>{u.isConnected||(u.dispatchEvent(new Event(D)),t.delete(u))}}}function jt(t,e,n={}){let r=t.host||t;m.push({scope:r,host:(...s)=>s.length?s.forEach(i=>i(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[N];o||ht(r);let c=e.call(r,n);return o||r.dispatchEvent(new Event(y)),t.nodeType===11&&typeof t.mode=="string"&&r.addEventListener(D,R.observe(t),{once:!0}),m.pop(),t.append(c)}function ht(t){return Q(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(y))}),Q(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(D)))}),Q(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(U,{detail:[o,c]})),e.apply(n,r)}),t.prototype[N]=!0,t}function Q(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}function Wt(t,e,n){return typeof e=="function"&&(n=e,e=null),e||(e={}),function(o,...c){n&&(c.unshift(o),o=typeof n=="function"?n():n);let s=c.length?new CustomEvent(t,x({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(s)}}function A(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}var gt=t=>x({},typeof t=="object"?t:null,{once:!0});A.connected=function(t,e){return e=gt(e),function(r){return r.addEventListener(y,t,e),r[N]?r:r.isConnected?(r.dispatchEvent(new Event(y)),r):(G(e.signal,()=>R.offConnected(r,t))&&R.onConnected(r,t),r)}};A.disconnected=function(t,e){return e=gt(e),function(r){return r.addEventListener(D,t,e),r[N]||G(e.signal,()=>R.offDisconnected(r,t))&&R.onDisconnected(r,t),r}};var X=new WeakMap;A.disconnectedAsAbort=function(t){if(X.has(t))return X.get(t);let e=new AbortController;return X.set(t,e),t(A.disconnected(()=>e.abort())),e.signal};var l="__dde_signal",Y=(()=>{let t=new Set,e=!1;function n(){e=!1;let r=t;t=new Set;for(let o of r){let c=o[l];c&&c.listeners.forEach(s=>s(c.value))}}return function(r){t.add(r),!e&&(e=!0,queueMicrotask(n))}})();var et=w(null,{get:{value(){return vt(this)}},set:{value(...t){return _t(this,...t)}},toJSON:{value(){return vt(this)}},valueOf:{value(){return this[l]&&this[l].value}}}),Ft=w(et,{set:{value(){}}});function F(t){return t&&t[l]}var B=[],v=new WeakMap;function g(t,e){if(typeof t!="function")return mt(!1,t,e);if(F(t))return t;let n=mt(!0);function r(){let[o,...c]=v.get(r);if(v.set(r,new Set([o])),B.push(r),_t(n,t()),B.pop(),!c.length)return;let s=v.get(r);for(let i of c)s.has(i)||k(i,r)}return v.set(n[l],r),v.set(r,new Set([n])),r(),n}g.action=function(t,e,...n){let r=t[l];if(!r)return;let{actions:o}=r;if(!o||!Z(o,e))throw new Error(`Action "${e}" not defined. See ${l}.actions.`);if(o[e].apply(r,n),r.skip)return delete r.skip;Y(t)};g.on=function t(e,n,r={}){let{signal:o}=r;if(!(o&&o.aborted)){if(Array.isArray(e))return e.forEach(c=>t(c,n,r));nt(e,n),o&&o.addEventListener("abort",()=>k(e,n))}};g.symbols={onclear:Symbol.for("Signal.onclear")};g.clear=function(...t){for(let n of t){let r=n[l];r&&(delete n.toJSON,r.onclear.forEach(o=>o.call(r)),e(n,r),delete n[l])}function e(n,r){r.listeners.forEach(o=>{if(r.listeners.delete(o),!v.has(o))return;let c=v.get(o);c.delete(n),!(c.size>1)&&(n.clear(...c),v.delete(o))})}};var L="__dde_reactive";function It(t=w()){return(e,n)=>Z(t,e)?t[e]:t[e]=n()}g.el=function(t,e){let n=T.mark({type:"reactive",source:new q().compact},!0),r=n.end,o=d.D.createDocumentFragment();o.append(n,r);let{current:c}=m,s=w(),i=p=>{if(!n.parentNode||!r.parentNode)return k(t,i);let E=It(s);s=w(),m.push(c);let h=e(p,function(a,f){return s[a]=E(a,f)});m.pop(),Array.isArray(h)||(h=[h]);let b=document.createComment("");h.push(b),n.after(...h);let M;for(;(M=b.nextSibling)&&M!==r;)M.remove();b.remove(),n.isConnected&&$t(c.host())};return nt(t,i),xt(t,i,n,e),i(t.get()),c.host(A.disconnected(()=>s={})),o};function $t(t){!t||!t[L]||(requestIdleCallback||setTimeout)(function(){t[L]=t[L].filter(([e,n])=>n.isConnected?!0:(k(...e),!1))})}var Ut={_set(t){this.value=t}};function zt(t){return function(e,n){let r=w(et,{set:{value(...c){return e.setAttribute(n,...c)}}}),o=Et(r,e.getAttribute(n),Ut);return t[n]=o,o}}var tt="__dde_attributes";g.observedAttributes=function(t){let e=t[tt]={},n=ct(t,zt(e));return A(U,function({detail:o}){/*! This maps attributes to signals (`S.observedAttributes`). + Investigate `__dde_attributes` key of the element. */let[c,s]=o,i=this[tt][c];if(i)return g.action(i,"_set",s)})(t),A.disconnected(function(){/*! This removes all signals mapped to attributes (`S.observedAttributes`). + Investigate `__dde_attributes` key of the element. */g.clear(...Object.values(this[tt]))})(t),n};var bt={isSignal:F,processReactiveAttribute(t,e,n,r){if(!F(n))return n;let o=c=>{if(!t.isConnected)return k(n,o);r(e,c)};return nt(n,o),xt(n,o,t,e),n.get()}};function xt(t,e,...n){let{current:r}=m;r.host(function(o){if(o[L])return o[L].push([[t,e],...n]);o[L]=[],!r.prevent&&A.disconnected(()=>o[L].forEach(([[c,s]])=>k(c,s,c[l]&&c[l].host&&c[l].host()===o)))(o)})}var Ht=new FinalizationRegistry(function(t){g.clear({[l]:t})});function mt(t,e,n){let r=w(t?Ft:et),o=Et(r,e,n,t);return Ht.register(o,o[l]),o}var Bt=x(w(),{stopPropagation(){this.skip=!0}});function Et(t,e,n,r=!1){let o=[];rt(n)!=="[object Object]"&&(n={});let{onclear:c}=g.symbols;n[c]&&(o.push(n[c]),delete n[c]);let{host:s}=m;return Reflect.defineProperty(t,l,{value:x(w(Bt),{value:e,actions:n,onclear:o,host:s,listeners:new Set,defined:new q().stack,readonly:r}),enumerable:!1,writable:!1,configurable:!0}),t}function Jt(){return B[B.length-1]}function vt(t){if(!t[l])return;let{value:e,listeners:n}=t[l],r=Jt();return r&&n.add(r),v.has(r)&&v.get(r).add(t),e}function _t(t,e,n){let r=t[l];if(!(!r||!n&&r.value===e))return r.value=e,Y(t),e}function nt(t,e){if(t[l])return t[l].listeners.add(e)}function k(t,e,n){let r=t[l];if(!r)return;let{listeners:o}=r,c=o.delete(e);if(!c||!n||o.size)return c;g.clear(t);let s=v.get(r);if(!s)return c;let i=v.get(s);if(!i)return c;for(let p of i)k(p,s,!0);return c}I(bt);return Ot(Zt);})(); diff --git a/dist/iife.d.ts b/dist/iife.d.ts index 69b37a8..90eed40 100644 --- a/dist/iife.d.ts +++ b/dist/iife.d.ts @@ -213,7 +213,6 @@ export const scope: { export function customElementRender>>(target: ShadowRoot | EL, render: (props: P) => SupportedElement | DocumentFragment, props?: P | ((el: EL) => P)): EL; export function customElementWithDDE HTMLElement)>(custom_element: EL): EL; export function lifecyclesToEvents HTMLElement)>(custom_element: EL): EL; -export function observedAttributes(custom_element: HTMLElement): Record; /** * This is used primarly for server side rendering. To be sure that all async operations * are finished before the page is sent to the client. diff --git a/dist/iife.js b/dist/iife.js index ffb44a0..bc8ad95 100644 --- a/dist/iife.js +++ b/dist/iife.js @@ -33,7 +33,6 @@ var DDE = (() => { elNS: () => createElementNS, elementAttribute: () => elementAttribute, lifecyclesToEvents: () => lifecyclesToEvents, - observedAttributes: () => observedAttributes2, on: () => on, queue: () => queue, registerReactivity: () => registerReactivity, @@ -64,16 +63,6 @@ var DDE = (() => { signal.removeEventListener("abort", listener); }; } - function observedAttributes(instance, observedAttribute) { - const { observedAttributes: observedAttributes3 = [] } = instance.constructor; - return observedAttributes3.reduce(function(out, name) { - out[kebabToCamel(name)] = observedAttribute(instance, name); - return out; - }, {}); - } - function kebabToCamel(name) { - return name.replace(/-./g, (x) => x[1].toUpperCase()); - } // src/signals-lib/common.js var signals_global = { @@ -565,7 +554,7 @@ var DDE = (() => { } // src/customElement.js - function customElementRender(target, render, props = observedAttributes2) { + function customElementRender(target, render, props = {}) { const custom_element = target.host || target; scope.push({ scope: custom_element, @@ -606,9 +595,6 @@ var DDE = (() => { obj[method] = new Proxy(obj[method] || (() => { }), { apply }); } - function observedAttributes2(instance) { - return observedAttributes(instance, (i, n) => i.getAttribute(n)); - } // src/events.js function dispatchEvent(name, options, host) { @@ -662,25 +648,5 @@ var DDE = (() => { host(on.disconnected(() => a.abort())); return a.signal; }; - var els_attribute_store = /* @__PURE__ */ new WeakSet(); - on.attributeChanged = function(listener, options) { - if (typeof options !== "object") - options = {}; - return function registerElement(element) { - element.addEventListener(eva, listener, options); - if (element[keyLTE] || els_attribute_store.has(element)) - return element; - if (!enviroment.M) return element; - const observer = new enviroment.M(function(mutations) { - for (const { attributeName, target } of mutations) - target.dispatchEvent( - new CustomEvent(eva, { detail: [attributeName, target.getAttribute(attributeName)] }) - ); - }); - const c = onAbort(options.signal, () => observer.disconnect()); - if (c) observer.observe(element, { attributes: true }); - return element; - }; - }; return __toCommonJS(index_exports); })(); diff --git a/dist/iife.min.d.ts b/dist/iife.min.d.ts index 69b37a8..90eed40 100644 --- a/dist/iife.min.d.ts +++ b/dist/iife.min.d.ts @@ -213,7 +213,6 @@ export const scope: { export function customElementRender>>(target: ShadowRoot | EL, render: (props: P) => SupportedElement | DocumentFragment, props?: P | ((el: EL) => P)): EL; export function customElementWithDDE HTMLElement)>(custom_element: EL): EL; export function lifecyclesToEvents HTMLElement)>(custom_element: EL): EL; -export function observedAttributes(custom_element: HTMLElement): Record; /** * This is used primarly for server side rendering. To be sure that all async operations * are finished before the page is sent to the client. diff --git a/dist/iife.min.js b/dist/iife.min.js index 30b300a..cc3c822 100644 --- a/dist/iife.min.js +++ b/dist/iife.min.js @@ -1 +1 @@ -var DDE=(()=>{var k=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var ct=(t,e)=>{for(var n in e)k(t,n,{get:e[n],enumerable:!0})},st=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of rt(e))!ot.call(t,o)&&o!==n&&k(t,o,{get:()=>e[o],enumerable:!(r=nt(e,o))||r.enumerable});return t};var it=t=>st(k({},"__esModule",{value:!0}),t);var Et={};ct(Et,{assign:()=>R,assignAttribute:()=>q,chainableAppend:()=>G,classListDeclarative:()=>J,createElement:()=>j,createElementNS:()=>dt,customElementRender:()=>vt,customElementWithDDE:()=>X,dispatchEvent:()=>mt,el:()=>j,elNS:()=>dt,elementAttribute:()=>K,lifecyclesToEvents:()=>X,observedAttributes:()=>Y,on:()=>O,queue:()=>at,registerReactivity:()=>H,scope:()=>y,simulateSlots:()=>pt});function w(t){return typeof t>"u"}function b(t,e){return t instanceof e}function $(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function v(...t){return Object.assign(...t)}function T(t,e){if(!t||!b(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}function U(t,e){let{observedAttributes:n=[]}=t.constructor;return n.reduce(function(r,o){return r[ut(o)]=e(t,o),r},{})}function ut(t){return t.replace(/-./g,e=>e[1].toUpperCase())}var S={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function H(t,e=!0){return e?v(S,t):(Object.setPrototypeOf(t,S),t)}function N(t){return $(t,S)&&t!==S?t:S}var a={setDeleteAttr:ft,ssr:"",D:globalThis.document,F:globalThis.DocumentFragment,H:globalThis.HTMLElement,S:globalThis.SVGElement,M:globalThis.MutationObserver,q:t=>t||Promise.resolve()};function ft(t,e,n){if(Reflect.set(t,e,n),!!w(n)){if(Reflect.deleteProperty(t,e),b(t,a.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var A="__dde_lifecyclesToEvents",m="dde:connected",_="dde:disconnected",L="dde:attributeChanged";function at(t){return a.q(t)}var x=[{get scope(){return a.D.body},host:t=>t?t(a.D.body):a.D.body,prevent:!0}],y={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(v({},this.current,{prevent:!1},t))},pushRoot(){return x.push(x[0])},pop(){if(x.length!==1)return x.pop()}};function z(...t){return this.appendOriginal(...t),this}function G(t){return t.append===z||(t.appendOriginal=t.append,t.append=z),t}var P;function j(t,e,...n){let r=N(this),o=0,c,d;switch((Object(e)!==e||r.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1;let f=(...l)=>l.length?(o===1?n.unshift(...l):l.forEach(E=>E(d)),void 0):d;y.push({scope:t,host:f}),c=t(e||void 0);let p=b(c,a.F);if(c.nodeName==="#comment")break;let g=j.mark({type:"component",name:t.name,host:p?"this":"parentElement"});c.prepend(g),p&&(d=g);break}case t==="#text":c=R.call(this,a.D.createTextNode(""),e);break;case(t==="<>"||!t):c=R.call(this,a.D.createDocumentFragment(),e);break;case!!P:c=R.call(this,a.D.createElementNS(P,t),e);break;case!c:c=R.call(this,a.D.createElement(t),e)}return G(c),d||(d=c),n.forEach(f=>f(d)),o&&y.pop(),o=2,c}j.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=a.D.createComment(``);return e&&(r.end=a.D.createComment("")),r};function dt(t){let e=this;return function(...r){P=t;let o=j.call(e,...r);return P=void 0,o}}function pt(t,e=t){let n="\xB9\u2070",r="\u2713",o=Object.fromEntries(Array.from(e.querySelectorAll("slot")).filter(c=>!c.name.endsWith(n)).map(c=>[c.name+=n,c]));if(t.append=new Proxy(t.append,{apply(c,d,f){if(f[0]===e)return c.apply(t,f);for(let p of f){let g=(p.slot||"")+n;try{K(p,"remove","slot")}catch{}let l=o[g];if(!l)return;l.name.startsWith(r)||(l.childNodes.forEach(E=>E.remove()),l.name=r+g),l.append(p)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}var M=new WeakMap,{setDeleteAttr:B}=a;function R(t,...e){if(!e.length)return t;M.set(t,V(t,this));for(let[n,r]of Object.entries(v({},...e)))q.call(this,t,n,r);return M.delete(t),t}function q(t,e,n){let{setRemoveAttr:r,s:o}=V(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(f,p)=>q.call(c,t,f,p));let[d]=e;if(d==="=")return r(e.slice(1),n);if(d===".")return Z(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 B(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return W(o,e,t,n,Z.bind(null,t[e]));case"ariaset":return W(o,e,t,n,(f,p)=>r("aria-"+f,p));case"classList":return J.call(c,t,n)}return lt(t,e)?B(t,e,n):r(e,n)}function V(t,e){if(M.has(t))return M.get(t);let r=(b(t,a.S)?bt:ht).bind(null,t,"Attribute"),o=N(e);return{setRemoveAttr:r,s:o}}function J(t,e){let n=N(this);return W(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function K(t,e,n,r){return b(t,a.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function lt(t,e){if(!(e in t))return!1;let n=Q(t,e);return!w(n.set)}function Q(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||Q(t,e)}function W(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([f,p]){f&&(f=new c(f),f.target=e,p=t.processReactiveAttribute(n,f,p,o),o(f,p))})}function ht(t,e,n,r){return t[(w(r)?"remove":"set")+e](n,r)}function bt(t,e,n,r,o=null){return t[(w(r)?"remove":"set")+e+"NS"](o,n,r)}function Z(t,e,n){if(Reflect.set(t,e,n),!!w(n))return Reflect.deleteProperty(t,e)}var C=a.M?gt():new Proxy({},{get(){return()=>{}}});function gt(){let t=new Map,e=!1,n=s=>function(u){for(let i of u)if(i.type==="childList"){if(l(i.addedNodes,!0)){s();continue}E(i.removedNodes,!0)&&s()}},r=new a.M(n(f));return{observe(s){let u=new a.M(n(()=>{}));return u.observe(s,{childList:!0,subtree:!0}),()=>u.disconnect()},onConnected(s,u){d();let i=c(s);i.connected.has(u)||(i.connected.add(u),i.length_c+=1)},offConnected(s,u){if(!t.has(s))return;let i=t.get(s);i.connected.has(u)&&(i.connected.delete(u),i.length_c-=1,o(s,i))},onDisconnected(s,u){d();let i=c(s);i.disconnected.has(u)||(i.disconnected.add(u),i.length_d+=1)},offDisconnected(s,u){if(!t.has(s))return;let i=t.get(s);i.disconnected.delete(u),i.length_d-=1,o(s,i)}};function o(s,u){u.length_c||u.length_d||(t.delete(s),f())}function c(s){if(t.has(s))return t.get(s);let u={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(s,u),u}function d(){e||(e=!0,r.observe(a.D.body,{childList:!0,subtree:!0}))}function f(){!e||t.size||(e=!1,r.disconnect())}function p(){return new Promise(function(s){(requestIdleCallback||requestAnimationFrame)(s)})}async function g(s){t.size>30&&await p();let u=[];if(!b(s,Node))return u;for(let i of t.keys())i===s||!b(i,Node)||s.contains(i)&&u.push(i);return u}function l(s,u){let i=!1;for(let h of s){if(u&&g(h).then(l),!t.has(h))continue;let D=t.get(h);D.length_c&&(h.dispatchEvent(new Event(m)),D.connected=new WeakSet,D.length_c=0,D.length_d||t.delete(h),i=!0)}return i}function E(s,u){let i=!1;for(let h of s)u&&g(h).then(E),!(!t.has(h)||!t.get(h).length_d)&&((globalThis.queueMicrotask||setTimeout)(et(h)),i=!0);return i}function et(s){return()=>{s.isConnected||(s.dispatchEvent(new Event(_)),t.delete(s))}}}function vt(t,e,n=Y){let r=t.host||t;y.push({scope:r,host:(...d)=>d.length?d.forEach(f=>f(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[A];o||X(r);let c=e.call(r,n);return o||r.dispatchEvent(new Event(m)),t.nodeType===11&&typeof t.mode=="string"&&r.addEventListener(_,C.observe(t),{once:!0}),y.pop(),t.append(c)}function X(t){return F(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(m))}),F(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(_)))}),F(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(L,{detail:[o,c]})),e.apply(n,r)}),t.prototype[A]=!0,t}function F(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}function Y(t){return U(t,(e,n)=>e.getAttribute(n))}function mt(t,e,n){return typeof e=="function"&&(n=e,e=null),e||(e={}),function(o,...c){n&&(c.unshift(o),o=typeof n=="function"?n():n);let d=c.length?new CustomEvent(t,v({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(d)}}function O(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}var tt=t=>v({},typeof t=="object"?t:null,{once:!0});O.connected=function(t,e){return e=tt(e),function(r){return r.addEventListener(m,t,e),r[A]?r:r.isConnected?(r.dispatchEvent(new Event(m)),r):(T(e.signal,()=>C.offConnected(r,t))&&C.onConnected(r,t),r)}};O.disconnected=function(t,e){return e=tt(e),function(r){return r.addEventListener(_,t,e),r[A]||T(e.signal,()=>C.offDisconnected(r,t))&&C.onDisconnected(r,t),r}};var I=new WeakMap;O.disconnectedAsAbort=function(t){if(I.has(t))return I.get(t);let e=new AbortController;return I.set(t,e),t(O.disconnected(()=>e.abort())),e.signal};var xt=new WeakSet;O.attributeChanged=function(t,e){return typeof e!="object"&&(e={}),function(r){if(r.addEventListener(L,t,e),r[A]||xt.has(r)||!a.M)return r;let o=new a.M(function(d){for(let{attributeName:f,target:p}of d)p.dispatchEvent(new CustomEvent(L,{detail:[f,p.getAttribute(f)]}))});return T(e.signal,()=>o.disconnect())&&o.observe(r,{attributes:!0}),r}};return it(Et);})(); +var DDE=(()=>{var M=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var et=Object.getOwnPropertyNames;var nt=Object.prototype.hasOwnProperty;var rt=(t,e)=>{for(var n in e)M(t,n,{get:e[n],enumerable:!0})},ot=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of et(e))!nt.call(t,o)&&o!==n&&M(t,o,{get:()=>e[o],enumerable:!(r=tt(e,o))||r.enumerable});return t};var ct=t=>ot(M({},"__esModule",{value:!0}),t);var bt={};rt(bt,{assign:()=>S,assignAttribute:()=>q,chainableAppend:()=>Z,classListDeclarative:()=>V,createElement:()=>P,createElementNS:()=>ut,customElementRender:()=>ht,customElementWithDDE:()=>Q,dispatchEvent:()=>gt,el:()=>P,elNS:()=>ut,elementAttribute:()=>J,lifecyclesToEvents:()=>Q,on:()=>L,queue:()=>it,registerReactivity:()=>$,scope:()=>y,simulateSlots:()=>ft});function w(t){return typeof t>"u"}function g(t,e){return t instanceof e}function I(t,e){return Object.prototype.isPrototypeOf.call(e,t)}function v(...t){return Object.assign(...t)}function j(t,e){if(!t||!g(t,AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var D={isSignal(t){return!1},processReactiveAttribute(t,e,n,r){return n}};function $(t,e=!0){return e?v(D,t):(Object.setPrototypeOf(t,D),t)}function R(t){return I(t,D)&&t!==D?t:D}var a={setDeleteAttr:st,ssr:"",D:globalThis.document,F:globalThis.DocumentFragment,H:globalThis.HTMLElement,S:globalThis.SVGElement,M:globalThis.MutationObserver,q:t=>t||Promise.resolve()};function st(t,e,n){if(Reflect.set(t,e,n),!!w(n)){if(Reflect.deleteProperty(t,e),g(t,a.H)&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var O="__dde_lifecyclesToEvents",m="dde:connected",_="dde:disconnected",U="dde:attributeChanged";function it(t){return a.q(t)}var x=[{get scope(){return a.D.body},host:t=>t?t(a.D.body):a.D.body,prevent:!0}],y={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(v({},this.current,{prevent:!1},t))},pushRoot(){return x.push(x[0])},pop(){if(x.length!==1)return x.pop()}};function H(...t){return this.appendOriginal(...t),this}function Z(t){return t.append===H||(t.appendOriginal=t.append,t.append=H),t}var T;function P(t,e,...n){let r=R(this),o=0,c,d;switch((Object(e)!==e||r.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1;let f=(...l)=>l.length?(o===1?n.unshift(...l):l.forEach(E=>E(d)),void 0):d;y.push({scope:t,host:f}),c=t(e||void 0);let p=g(c,a.F);if(c.nodeName==="#comment")break;let b=P.mark({type:"component",name:t.name,host:p?"this":"parentElement"});c.prepend(b),p&&(d=b);break}case t==="#text":c=S.call(this,a.D.createTextNode(""),e);break;case(t==="<>"||!t):c=S.call(this,a.D.createDocumentFragment(),e);break;case!!T:c=S.call(this,a.D.createElementNS(T,t),e);break;case!c:c=S.call(this,a.D.createElement(t),e)}return Z(c),d||(d=c),n.forEach(f=>f(d)),o&&y.pop(),o=2,c}P.mark=function(t,e=!1){t=Object.entries(t).map(([o,c])=>o+`="${c}"`).join(" ");let n=e?"":"/",r=a.D.createComment(``);return e&&(r.end=a.D.createComment("")),r};function ut(t){let e=this;return function(...r){T=t;let o=P.call(e,...r);return T=void 0,o}}function ft(t,e=t){let n="\xB9\u2070",r="\u2713",o=Object.fromEntries(Array.from(e.querySelectorAll("slot")).filter(c=>!c.name.endsWith(n)).map(c=>[c.name+=n,c]));if(t.append=new Proxy(t.append,{apply(c,d,f){if(f[0]===e)return c.apply(t,f);for(let p of f){let b=(p.slot||"")+n;try{J(p,"remove","slot")}catch{}let l=o[b];if(!l)return;l.name.startsWith(r)||(l.childNodes.forEach(E=>E.remove()),l.name=r+b),l.append(p)}return t.append=c,t}}),t!==e){let c=Array.from(t.childNodes);t.append(...c)}return e}var N=new WeakMap,{setDeleteAttr:z}=a;function S(t,...e){if(!e.length)return t;N.set(t,G(t,this));for(let[n,r]of Object.entries(v({},...e)))q.call(this,t,n,r);return N.delete(t),t}function q(t,e,n){let{setRemoveAttr:r,s:o}=G(t,this),c=this;n=o.processReactiveAttribute(t,e,n,(f,p)=>q.call(c,t,f,p));let[d]=e;if(d==="=")return r(e.slice(1),n);if(d===".")return B(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 z(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return k(o,e,t,n,B.bind(null,t[e]));case"ariaset":return k(o,e,t,n,(f,p)=>r("aria-"+f,p));case"classList":return V.call(c,t,n)}return at(t,e)?z(t,e,n):r(e,n)}function G(t,e){if(N.has(t))return N.get(t);let r=(g(t,a.S)?pt:dt).bind(null,t,"Attribute"),o=R(e);return{setRemoveAttr:r,s:o}}function V(t,e){let n=R(this);return k(n,"classList",t,e,(r,o)=>t.classList.toggle(r,o===-1?void 0:!!o)),t}function J(t,e,n,r){return g(t,a.H)?t[e+"Attribute"](n,r):t[e+"AttributeNS"](null,n,r)}function at(t,e){if(!(e in t))return!1;let n=K(t,e);return!w(n.set)}function K(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||K(t,e)}function k(t,e,n,r,o){let c=String;if(!(typeof r!="object"||r===null))return Object.entries(r).forEach(function([f,p]){f&&(f=new c(f),f.target=e,p=t.processReactiveAttribute(n,f,p,o),o(f,p))})}function dt(t,e,n,r){return t[(w(r)?"remove":"set")+e](n,r)}function pt(t,e,n,r,o=null){return t[(w(r)?"remove":"set")+e+"NS"](o,n,r)}function B(t,e,n){if(Reflect.set(t,e,n),!!w(n))return Reflect.deleteProperty(t,e)}var A=a.M?lt():new Proxy({},{get(){return()=>{}}});function lt(){let t=new Map,e=!1,n=s=>function(u){for(let i of u)if(i.type==="childList"){if(l(i.addedNodes,!0)){s();continue}E(i.removedNodes,!0)&&s()}},r=new a.M(n(f));return{observe(s){let u=new a.M(n(()=>{}));return u.observe(s,{childList:!0,subtree:!0}),()=>u.disconnect()},onConnected(s,u){d();let i=c(s);i.connected.has(u)||(i.connected.add(u),i.length_c+=1)},offConnected(s,u){if(!t.has(s))return;let i=t.get(s);i.connected.has(u)&&(i.connected.delete(u),i.length_c-=1,o(s,i))},onDisconnected(s,u){d();let i=c(s);i.disconnected.has(u)||(i.disconnected.add(u),i.length_d+=1)},offDisconnected(s,u){if(!t.has(s))return;let i=t.get(s);i.disconnected.delete(u),i.length_d-=1,o(s,i)}};function o(s,u){u.length_c||u.length_d||(t.delete(s),f())}function c(s){if(t.has(s))return t.get(s);let u={connected:new WeakSet,length_c:0,disconnected:new WeakSet,length_d:0};return t.set(s,u),u}function d(){e||(e=!0,r.observe(a.D.body,{childList:!0,subtree:!0}))}function f(){!e||t.size||(e=!1,r.disconnect())}function p(){return new Promise(function(s){(requestIdleCallback||requestAnimationFrame)(s)})}async function b(s){t.size>30&&await p();let u=[];if(!g(s,Node))return u;for(let i of t.keys())i===s||!g(i,Node)||s.contains(i)&&u.push(i);return u}function l(s,u){let i=!1;for(let h of s){if(u&&b(h).then(l),!t.has(h))continue;let C=t.get(h);C.length_c&&(h.dispatchEvent(new Event(m)),C.connected=new WeakSet,C.length_c=0,C.length_d||t.delete(h),i=!0)}return i}function E(s,u){let i=!1;for(let h of s)u&&b(h).then(E),!(!t.has(h)||!t.get(h).length_d)&&((globalThis.queueMicrotask||setTimeout)(Y(h)),i=!0);return i}function Y(s){return()=>{s.isConnected||(s.dispatchEvent(new Event(_)),t.delete(s))}}}function ht(t,e,n={}){let r=t.host||t;y.push({scope:r,host:(...d)=>d.length?d.forEach(f=>f(r)):r}),typeof n=="function"&&(n=n.call(r,r));let o=r[O];o||Q(r);let c=e.call(r,n);return o||r.dispatchEvent(new Event(m)),t.nodeType===11&&typeof t.mode=="string"&&r.addEventListener(_,A.observe(t),{once:!0}),y.pop(),t.append(c)}function Q(t){return W(t.prototype,"connectedCallback",function(e,n,r){e.apply(n,r),n.dispatchEvent(new Event(m))}),W(t.prototype,"disconnectedCallback",function(e,n,r){e.apply(n,r),(globalThis.queueMicrotask||setTimeout)(()=>!n.isConnected&&n.dispatchEvent(new Event(_)))}),W(t.prototype,"attributeChangedCallback",function(e,n,r){let[o,,c]=r;n.dispatchEvent(new CustomEvent(U,{detail:[o,c]})),e.apply(n,r)}),t.prototype[O]=!0,t}function W(t,e,n){t[e]=new Proxy(t[e]||(()=>{}),{apply:n})}function gt(t,e,n){return typeof e=="function"&&(n=e,e=null),e||(e={}),function(o,...c){n&&(c.unshift(o),o=typeof n=="function"?n():n);let d=c.length?new CustomEvent(t,v({detail:c[0]},e)):new Event(t,e);return o.dispatchEvent(d)}}function L(t,e,n){return function(o){return o.addEventListener(t,e,n),o}}var X=t=>v({},typeof t=="object"?t:null,{once:!0});L.connected=function(t,e){return e=X(e),function(r){return r.addEventListener(m,t,e),r[O]?r:r.isConnected?(r.dispatchEvent(new Event(m)),r):(j(e.signal,()=>A.offConnected(r,t))&&A.onConnected(r,t),r)}};L.disconnected=function(t,e){return e=X(e),function(r){return r.addEventListener(_,t,e),r[O]||j(e.signal,()=>A.offDisconnected(r,t))&&A.onDisconnected(r,t),r}};var F=new WeakMap;L.disconnectedAsAbort=function(t){if(F.has(t))return F.get(t);let e=new AbortController;return F.set(t,e),t(L.disconnected(()=>e.abort())),e.signal};return ct(bt);})(); diff --git a/docs/components/examples/customElement/intro.js b/docs/components/examples/customElement/intro.js index 9b7833e..36d74d9 100644 --- a/docs/components/examples/customElement/intro.js +++ b/docs/components/examples/customElement/intro.js @@ -2,7 +2,6 @@ import { customElementRender, customElementWithDDE, - observedAttributes, } from "deka-dom-el"; /** @type {ddePublicElementTagNameMap} */ import { S } from "deka-dom-el/signals"; diff --git a/docs/components/examples/customElement/observedAttributes.js b/docs/components/examples/customElement/observedAttributes.js index 44f902e..1c232ae 100644 --- a/docs/components/examples/customElement/observedAttributes.js +++ b/docs/components/examples/customElement/observedAttributes.js @@ -1,7 +1,6 @@ import { customElementRender, customElementWithDDE, - observedAttributes, el, on, scope, } from "deka-dom-el"; import { S } from "deka-dom-el/signals"; @@ -9,7 +8,6 @@ export class HTMLCustomElement extends HTMLElement{ static tagName= "custom-element"; static observedAttributes= [ "attr" ]; connectedCallback(){ - console.log(observedAttributes(this)); customElementRender( this.attachShadow({ mode: "open" }), ddeComponent, diff --git a/docs/components/examples/events/live-cycle.js b/docs/components/examples/events/live-cycle.js index 166f856..726d490 100644 --- a/docs/components/examples/events/live-cycle.js +++ b/docs/components/examples/events/live-cycle.js @@ -3,7 +3,6 @@ const paragraph= el("p", "See live-cycle events in console.", el=> log({ type: "dde:created", detail: el }), on.connected(log), on.disconnected(log), - on.attributeChanged(log)); document.body.append( paragraph, diff --git a/docs/components/mnemonic/customElement-init.js b/docs/components/mnemonic/customElement-init.js index 301f3e2..f8aa3ae 100644 --- a/docs/components/mnemonic/customElement-init.js +++ b/docs/components/mnemonic/customElement-init.js @@ -11,10 +11,6 @@ export function mnemonic(){ el("code", "customElementWithDDE()"), " — register to DDE library, see also `lifecyclesToEvents`, can be also used as decorator", ), - el("li").append( - el("code", "observedAttributes()"), - " — returns record of observed attributes (keys uses camelCase)", - ), el("li").append( el("code", "S.observedAttributes()"), " — returns record of observed attributes (keys uses camelCase and values are signals)", @@ -32,4 +28,4 @@ export function mnemonic(){ " — simulate slots for “dde”/functional components", ), ); -} +} \ No newline at end of file diff --git a/docs/p03-events.html.js b/docs/p03-events.html.js index ec9b62d..7f44ac5 100644 --- a/docs/p03-events.html.js +++ b/docs/p03-events.html.js @@ -165,9 +165,6 @@ export function page({ pkg, info }){ el("dt", t`on.disconnected(callback)`), el("dd", t`Fires when the element is removed from the DOM`), - - el("dt", t`on.attributeChanged(callback, attributeName)`), - el("dd", t`Fires when the specified attribute changes`) ) ), el(example, { src: fileURL("./components/examples/events/live-cycle.js"), page_id }), diff --git a/docs/p06-customElement.html.js b/docs/p06-customElement.html.js index 71445a4..0e432d8 100644 --- a/docs/p06-customElement.html.js +++ b/docs/p06-customElement.html.js @@ -115,7 +115,7 @@ export function page({ pkg, info }){ el("dt", t`Usage`), el("dd", t`customElementWithDDE(YourElementClass)`), el("dt", t`Benefits`), - el("dd", t`Allows using on.connected(), on.disconnected(), etc. with your element`) + el("dd", t`Allows using on.connected(), on.disconnected() or S.observedAttributes().`) ) ), el(example, { src: fileURL("./components/examples/customElement/customElementWithDDE.js"), page_id }), @@ -142,7 +142,8 @@ export function page({ pkg, info }){ el("ol").append( el("li", t`Target (usually this or this.shadowRoot)`), el("li", t`Component function that returns a DOM tree`), - el("li", t`Optional: Attributes transformer function (default or S.observedAttributes)`) + el("li", t`Optional: Attributes transformer function (empty by default or + S.observedAttributes)`) ) ), el("dt", t`Returns`), @@ -169,7 +170,8 @@ export function page({ pkg, info }){ `), el("ol").append( el("li").append(...T` - ${el("code", "observedAttributes")} - Passes attributes as regular values (static) + Using standard attribute access (${el("code", "this.getAttribute()")}) - Passes attributes as + regular values (static) `), el("li").append(...T` ${el("code", "S.observedAttributes")} - Transforms attributes into signals (reactive) @@ -177,7 +179,7 @@ export function page({ pkg, info }){ ) ), el("p").append(...T` - Using ${el("code", "S.observedAttributes")} creates a reactive connection between your element's attributes + Using the ${el("code", "S.observedAttributes")} creates a reactive connection between your element's attributes and its internal rendering. When attributes change, your component automatically updates! `), el(example, { src: fileURL("./components/examples/customElement/observedAttributes.js"), page_id }), diff --git a/index.d.ts b/index.d.ts index cba4bea..1a94076 100644 --- a/index.d.ts +++ b/index.d.ts @@ -262,7 +262,6 @@ export function customElementRender< ): EL export function customElementWithDDE HTMLElement)>(custom_element: EL): EL export function lifecyclesToEvents HTMLElement)>(custom_element: EL): EL -export function observedAttributes(custom_element: HTMLElement): Record /** * This is used primarly for server side rendering. To be sure that all async operations diff --git a/package.json b/package.json index 066a3b9..b0282ff 100644 --- a/package.json +++ b/package.json @@ -100,5 +100,6 @@ "jshint": "~2.13", "nodejsscript": "^1.0.2", "size-limit-node-esbuild": "~0.3" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/src/customElement.js b/src/customElement.js index 33eb0ee..0d21650 100644 --- a/src/customElement.js +++ b/src/customElement.js @@ -7,10 +7,10 @@ import { c_ch_o } from "./events-observer.js"; * * @param {Element|ShadowRoot} target - The custom element or shadow root to render into * @param {Function} render - The render function that returns content - * @param {Function|Object} [props=observedAttributes] - Props to pass to the render function + * @param {Function|Object} [props= {}] - Props to pass to the render function * @returns {Node} The rendered content */ -export function customElementRender(target, render, props= observedAttributes){ +export function customElementRender(target, render, props= {}){ const custom_element= target.host || target; scope.push({ scope: custom_element, @@ -69,15 +69,3 @@ export { lifecyclesToEvents as customElementWithDDE }; function wrapMethod(obj, method, apply){ obj[method]= new Proxy(obj[method] || (()=> {}), { apply }); } - -import { observedAttributes as oA } from "./helpers.js"; - -/** - * Gets observed attributes for a custom element - * - * @param {Element} instance - Custom element instance - * @returns {Object} Object mapping camelCase attribute names to their values - */ -export function observedAttributes(instance){ - return oA(instance, (i, n)=> i.getAttribute(n)); -} diff --git a/src/events.js b/src/events.js index 49d0b27..972c42f 100644 --- a/src/events.js +++ b/src/events.js @@ -106,35 +106,3 @@ on.disconnectedAsAbort= function(host){ host(on.disconnected(()=> a.abort())); return a.signal; }; - -/** Store for elements with attribute observers */ -const els_attribute_store= new WeakSet(); - -/** - * Creates a function to register attribute change event listeners - * - * @param {Function} listener - Event handler - * @param {Object} [options] - Event listener options - * @returns {Function} Function that registers the attribute change listener - */ -on.attributeChanged= function(listener, options){ - if(typeof options !== "object") - options= {}; - return function registerElement(element){ - element.addEventListener(eva, listener, options); - if(element[keyLTE] || els_attribute_store.has(element)) - return element; - - if(!env.M) return element; - - const observer= new env.M(function(mutations){ - for(const { attributeName, target } of mutations) - target.dispatchEvent( - new CustomEvent(eva, { detail: [ attributeName, target.getAttribute(attributeName) ] })); - }); - const c= onAbort(options.signal, ()=> observer.disconnect()); - if(c) observer.observe(element, { attributes: true }); - //TODO: clean up when element disconnected - return element; - }; -}; diff --git a/src/signals-lib/signals-lib.js b/src/signals-lib/signals-lib.js index e2ae1de..690ae77 100644 --- a/src/signals-lib/signals-lib.js +++ b/src/signals-lib/signals-lib.js @@ -159,7 +159,7 @@ signal.clear= function(...signals){ }; /** Property key for tracking reactive elements */ const key_reactive= "__dde_reactive"; -import { enviroment as env } from "../dom-common.js"; +import { enviroment as env, eva } from "../dom-common.js"; import { el } from "../dom.js"; import { scope } from "../dom.js"; import { on } from "../events.js"; @@ -265,7 +265,7 @@ const key_attributes= "__dde_attributes"; signal.observedAttributes= function(element){ const store= element[key_attributes]= {}; const attrs= observedAttributes(element, observedAttribute(store)); - on.attributeChanged(function attributeChangeToSignal({ detail }){ + on(eva, function attributeChangeToSignal({ detail }){ /*! This maps attributes to signals (`S.observedAttributes`). Investigate `__dde_attributes` key of the element. */ const [ name, value ]= detail;