diff --git a/packages/@hec.js/ui/dist/hec.esm.min.js b/packages/@hec.js/ui/dist/hec.esm.min.js index 6a3869a..5d717ec 100644 --- a/packages/@hec.js/ui/dist/hec.esm.min.js +++ b/packages/@hec.js/ui/dist/hec.esm.min.js @@ -1 +1 @@ -function W(t){let e=t.matchAll(/([^ {}\s]+)/g),a={meta:{},text:t,prop:null};for(let r of e)if(r[1].includes("=")){let n=r[1].split("=");a.meta[n[0]]=n[1].replaceAll(/'|"/g,"")}else a.prop=r[1];return a}var S={};var E=new WeakMap,k=t=>E.get(t),dt=t=>E.delete(t),j=t=>E.has(t),L=(t,e)=>{let a=k(t);a&&typeof a=="object"?E.set(t,Object.assign(a,e)):E.set(t,e)},d=t=>typeof t=="function"?d(t()):t;function h(t,e){let a=e.split(".");if(!e)return t;for(let r of a){if(["state"].includes(r)&&t?.state)return t[r];if(m(t)){let n=t()?.[r];if(m(n)){let o=new AbortController,c=b(n());n.subscribe({next:c},{signal:o.signal});let l=s=>{o.abort(),m(s[r])?(o=new AbortController,s[r].subscribe({next:c},{signal:o.signal}),c(s[r]())):c(s[r])};t.subscribe({next:l}),t=c}else t=t.map(o=>o&&o[r])}else if(typeof t=="function")t=d(t);else if(typeof t[r]<"u")typeof t[r]=="function"&&!m(t[r])?t=t[r].bind(t):t=t[r];else return}return t}function B(t,e){let a=e.split(".");if(!e)return!1;for(let r of a){if(["loading","error"].includes(r)&&t?.loading&&t?.error)return t[r];if(typeof t=="function")t=d(t);else if(typeof t[r]<"u")t=t[r];else return!1}return!0}var I={items:new Map,setItem(t,e){this.items.set(t,e.toString())},get length(){return this.items.keys().length},key(t){return Array.from(this.items.values()).at(t)},clear(){this.items.clear()},getItem(t){return this.items.get(t)},removeItem(t){this.items.delete(t)}},P=new Map;function rt(t){try{let e=window[t+"Storage"];return typeof e.length=="number"?e:I}catch{return I}}window.addEventListener("storage",t=>{if(!P.has(t.key))return;let e=P.get(t.key),a=t.storageArea.getItem(t.key);typeof a=="string"&&a!=="undefined"&&e.update(JSON.parse(a))});function b(t=null,e={}){if(e.id&&P.has(e.id))return P.get(e.id);let a=[],r=e.storage&&rt(e.storage),n=s=>{t=s,r&&r.setItem(e.id,JSON.stringify(t));for(let i of a)i.next(t)};function o(){return arguments.length&&t!==arguments[0]&&n(arguments[0]),t}let c=(s,i=null)=>{a.push(s),i?.signal.addEventListener("abort",()=>{let u=a.indexOf(s);u>-1&&a.splice(u,1)},{once:!0})};if(r){let s=r.getItem(e.id);n(typeof s=="string"&&s!=="undefined"?JSON.parse(s):t)}let l=Object.assign(o,{id:e.id,storage:e.storage,toString:()=>t.toString(),set:s=>t=s,update:n,subscribe:c,map:s=>{let i=b(s(t)),u=new AbortController,p=i.subscribe;return c({next:f=>i(s(f))},{signal:u.signal}),Object.assign(i,{set:()=>null,subscribe:(f,g)=>{p(f,g),g?.signal.addEventListener("abort",()=>u.abort())}})},filter:s=>{let i=b(s(t)?t:null);return c({next:u=>s(u)?i(u):null}),Object.assign(i,{set:()=>null})}});return e.id&&P.set(e.id,l),l}function nt(t,e=[],a=null){for(let r of e)r.subscribe({next:()=>a=t(a)});return t(a)}function bt(t,e=[],a=null){let r=b(null);return r(nt(n=>r(t(n)),e,a)),r}function at(t,e=null){let a=b(e),r=b("pending"),n=async()=>{try{r("pending"),a(await t()),r(null),delete a.error}catch(o){r("error"),a.error=o}return a()};return n(),Object.assign(a,{state:r,refetch:n})}function gt(t,e,a=null){let r=at(()=>e(d(t)),a);return m(t)&&t.subscribe({next:()=>r.refetch()}),r}var m=t=>t&&t.subscribe;var st=b({}),A=b(location.pathname);var y=document.querySelector('head meta[name="route"]');y||(y=document.createElement("meta"),y.name="route",y.content=location.pathname,document.head.append(y));var C=()=>{y.content="",A(location.pathname),st(Object.fromEntries(new URLSearchParams(location.search))),y.content=y.content||location.pathname};window.addEventListener("popstate",C);window.addEventListener("hashchange",C);var ot=window.history.pushState,it=window.history.replaceState;window.history.pushState=function(e,a,r){ot.call(window.history,e,a,r),C()};window.history.replaceState=function(e,a,r){it.call(window.history,e,a,r),C()};var M=new WeakMap,lt=new MutationObserver(t=>{for(let e of t)M.has(e.target)&&M.get(e.target)()}),R={select:"[data-match]",run:t=>{let e=t.dataset.match,a=o=>o.replace(/index\.*[a-z0-9]*$/gm,"");function r(){return a(new URL(t.dataset.route||t.getAttribute("href"),location.href).pathname)}let n=()=>{r()==a(location.pathname)?t.classList.add(e):t.classList.remove(e)};A.subscribe({next:n}),M.set(t,n),lt.observe(t,{attributes:!0,attributeFilter:["href","data-route"]}),n(),t.removeAttribute("data-match")}};var T={number:t=>t.valueAsNumber,date:t=>t.valueAsDate,text:t=>t.value,checkbox:t=>t.checked,"":t=>t.value},q={select:"[data-bind],[name]",run:(t,e)=>{let a=t.getAttribute("name")||t.dataset.bind,r=h(e,a);if(r){let n=o=>{t.type=="checkbox"?t.checked=o:t.value=o};n(d(r)),m(r)&&(r.subscribe({next:n}),t.addEventListener("input",()=>r(T[t.type]?.(t)??t.value)),t.addEventListener("change",()=>r(T[t.type]?.(t)??t.value)))}}};var N=new WeakMap,_=new IntersectionObserver(t=>{for(let e of t)if(e.isIntersecting&&N.has(e.target)){for(let a of N.get(e.target))a();N.delete(e.target),_.unobserve(e.target)}},{rootMargin:"256px"});function w(t){return new Promise(e=>{let a=N.get(t)??[];a.push(e),N.set(t,a),_.observe(t)})}var O=new WeakSet,H={select:"[data-include]",run:(t,e)=>{if(O.has(t)||t.children.length)return;O.add(t);let a=t.hasAttribute("data-lazy")&&t.closest("[hidden]"),r=async()=>{t.dispatchEvent(new CustomEvent("::load",{bubbles:!0}));let n=await fetch(t.dataset.include,{headers:{accept:"text/html,text/*"}});if(n.ok){let o=await n.text();t.dispatchEvent(new CustomEvent("::loaded",{bubbles:!0})),t.innerHTML=o;for(let c of t.childNodes)x(c,e);t.removeAttribute("data-include"),t.removeAttribute("data-lazy")}};t.hasAttribute("data-lazy")?w(t).then(r):r()}};var U=new WeakSet,$={select:"[data-for]",run:(t,e,a)=>{if(U.has(t))return;let r=t.dataset.for.replace("let","").split("of"),n=r[0].split(","),o=r.at(-1).trim(),c=n[0].trim()==o?"__e":n[0].trim(),l=n[1]?.trim()??"__i",s=h(e,o),i=document.createComment(t.dataset.for);t.replaceWith(i),O.add(t);let u=()=>{let f=i;for(;(f=f.nextSibling)&&(f instanceof HTMLElement&&f.dataset.for==t.dataset.for);)f=f.previousSibling,f.nextSibling.remove()},p=f=>{if(u(),!f||!f[Symbol.iterator])return console.warn("data-for: The value given is not iterable.",{key:o,value:f});for(let g=0,v=i;g{let a=h(e,t.dataset.if),r=document.createComment("if: "+t.dataset.if);t.replaceWith(r);let n=o=>{!t.parentNode&&o?(t.hidden=!1,r.after(t)):t.localName!="link"&&t.remove()};n(d(a)),m(a)&&a.subscribe({next:n})}};var V=new WeakSet,J={select:"[data-lazy]",run:(t,e,a)=>{if(V.has(t)||!t.childNodes.length)return;V.add(t);let r=t.dataset.lazy,n=()=>{t.removeAttribute("data-lazy");for(let o of t.childNodes)x(o,e)};r&&(t.addEventListener("::load",()=>t.classList.add(r),{once:!0}),t.addEventListener("::loaded",()=>t.classList.remove(r),{once:!0})),w(t).then(n),a()}};var D={select:"[data-on]",run:(t,e)=>{let a=r=>{let n=r.split(":"),o=n[0].trim(),c=n.at(-1).trim(),l=h(e,c);l&&t.addEventListener(o,l)};for(let r of t.dataset.on.split(","))a(r)}};var K=t=>{let e=document.createElement("link");Object.assign(e,t),e.rel="preload",document.head.append(e)};var G=new WeakSet,Q={select:"[data-preload]",run:t=>{if(G.has(t)||t.hidden)return;G.add(t);let e=()=>{let a=t.dataset.preload.split(",");for(let r of a){let n=r.split(":");K({href:n[0],as:n[1]??"fetch"})}};t.hasAttribute("data-lazy")?w(t).then(e):e()}};var ct=t=>{let e=t.dataset.route;for(;t=t.parentElement;)t.dataset.route&&(e=t.dataset.route+e);return e.replaceAll(/\/+/g,"/")},X={select:"[data-route]",run:async t=>{"URLPattern"in window||await import("https://kevinblt.github.io/hec/packages/@hec.js/ui/dist/urlpattnern.min.js");let e=ct(t),a=new URLPattern({pathname:e}),r=document.createComment("route: "+e);t.replaceWith(r);let n=()=>{let o=location.href.replace(/index\.*[a-z0-9]*$/gm,"");if(!t.parentNode&&a.test(o)){t.hidden=!1,r.after(t);let c=document.querySelector('head meta[name="route"]');c&&(c.content=a.pathname)}else t.localName!="link"&&t.remove()};A.subscribe({next:n}),n()}};var Y=[$,F,X,Q,H,D,q,R,J];var Z={};function ue(t,e={}){t instanceof URL&&(t=t.host==location.host?t.pathname:t.toString());let a=document.querySelector(`template[name="${t}"]`);if(!a){let r=document.querySelector('head meta[name="template-path"]');return Z[t]??=new Promise(async n=>{a=document.createElement("template"),a.setAttribute("id",t.toString()),a.innerHTML=await fetch(r?.content?.replaceAll("[name]",t.toString())??t).then(l=>l.text());let o=a.content.querySelectorAll('link[rel="stylesheet"][href]'),c=[];for(let l of o)c.push(fetch(l.href).then(s=>s.text()).then(s=>{let i=document.createElement("style");i.innerHTML=s,l.replaceWith(i)}));await Promise.all(c),document.body.append(a),n(a)}),Z[t].then(n=>x(n.content.cloneNode(!0),e))}return x(a.content.cloneNode(!0),e)}function fe(t,e={}){let a=document.createElement("template");return a.dataset.name="anonymous",a.innerHTML=t,x(a.content.cloneNode(!0),e)}function x(t,e={}){let a=(n,o)=>{let c=n.match(/{{[^}]+}}/g).map(W),l=n,s=()=>{n=l;for(let i of c){let u=d(i.value);n=n.replace(i.text,u??"")}return n};for(let i of c){let u=h(e,i.prop);if(u==null&&console.warn(`{{ ${i.prop} }}: No value for this key`,{key:i.prop,value:u}),m(u)){let p=u;for(let f in i.meta)if(S[f]){let g=S[f];p=p.map(v=>g({value:v,key:i.prop,param:i.meta[f],options:i.meta}))}i.value=p,p.subscribe({next:()=>o(s())})}else{let p=u;for(let f in i.meta)if(S[f]){let g=S[f];p=g({value:d(u),key:i.prop,param:i.meta[f],options:i.meta})}i.value=()=>p}}o(s())},r=(n,o=new WeakSet)=>{let c=!1;if(!(j(n)||o.has(n))){if(n.nodeName=="#document-fragment"&&L(n,e),n instanceof HTMLElement){let l=n.getAttributeNames();L(n,e);for(let s of Y)n.matches(s.select)&&s.run(n,e,()=>c=!0);for(let s of l){let i=n.getAttribute(s);i?.includes("{{")?a(i,u=>{u=u.trim().replace(/ +/," "),u===""?n.removeAttribute(s):n.setAttribute(s,u)}):n.localName.includes("-")&&B(e,i)&&n.setAttribute(s,`@parent.${i}`)}if(c)return}else if(n instanceof Text&&n.textContent.includes("{{")){let l=n.textContent.split(/{{|}}/g);for(let s=0,i=n,u;su.data=p.replaceAll("","")),o.add(u),i.after(u),i=u;n.remove()}o.add(n);for(let l of n.childNodes)r(l,o)}};return r(t,new WeakSet),t}function ge(t,e,a){customElements.define(t,class extends HTMLElement{static observedAttributes=Object.keys(e).map(r=>r.toLowerCase());#e=Object.fromEntries(Object.entries(e).map(r=>[r[0],b(r[1])]));#t={};#r=!1;#n=null;on(r,n,o=null){this.addEventListener(r,n,o)}querySelector(r){return this.shadowRoot.querySelector(r)}querySelectorAll(r){return this.shadowRoot.querySelectorAll(r)}async connectedCallback(){if(this.#n??=this.hasAttribute("data-lazy"),this.#n&&(await w(this),this.removeAttribute("data-lazy")),this.dispatchEvent(new CustomEvent("::load",{bubbles:!0})),this.#r){this.dispatchEvent(new CustomEvent("::loaded",{bubbles:!0})),this.dispatchEvent(new CustomEvent("::mount"));return}let r=this.shadowRoot??this.attachShadow({mode:"open"}),n=a(this.#e,this);(c=>{L(this,k(c)),this.dispatchEvent(new CustomEvent("::loaded",{bubbles:!0})),r.append(c),this.#r=!0,this.#t["::attributes"]=new AbortController;for(let l in e)this.hasAttribute(l)||this.setAttribute(l,e[l].toString()),this.#e[l].subscribe({next:s=>this.setAttribute(l,s.toString())},{signal:this.#t["::attributes"].signal});this.dispatchEvent(new CustomEvent("::mount"))})(n instanceof Promise?await n:n)}disconnectedCallback(){this.dispatchEvent(new CustomEvent("::unmount"))}#a(r=""){r=r.toLowerCase();for(let n in this.#e)if(n.toLowerCase()==r)return[e[n],this.#e[n]];return[null,null]}attributeChangedCallback(r,n,o){let[c,l]=this.#a(r);if(o.startsWith("@parent.")){let s=this.parentNode.host||this.parentNode,i=o.slice(8),u=h(k(s),i)??h(k(this),i);m(u)?(this.#t[c]?.abort(),this.#t[c]=new AbortController,l(d(u)),u.subscribe({next:l},{signal:this.#t[c].signal})):l(u)}else l(typeof c=="number"?parseFloat(o):o)}})}var tt=new WeakMap;function we(t,e=null){document.dispatchEvent(new CustomEvent(t,{detail:e}))}function ve(t,e){let a=r=>e(r.detail);tt.set(e,a),document.addEventListener(t,a)}function Se(t){return new Promise(e=>{let a=r=>e(r.detail);document.addEventListener(t,a,{once:!0})})}function Ee(t,e){document.removeEventListener(t,tt.get(e))}export{ge as component,dt as deletePropsOf,nt as effect,we as emit,W as expression,d as f,B as hasProp,j as hasProps,m as isSignal,bt as memo,Ee as off,ve as on,Se as once,S as pipes,Y as plugins,h as prop,k as propsOf,at as resource,gt as resourceBy,L as setPropsOf,b as signal,ue as templateByName,x as templateByNode,fe as templateByString}; +function W(t){let e=t.matchAll(/([^ {}\s]+)/g),a={meta:{},text:t,prop:null};for(let r of e)if(r[1].includes("=")){let n=r[1].split("=");a.meta[n[0]]=n[1].replaceAll(/'|"/g,"")}else a.prop=r[1];return a}var S={};var E=new WeakMap,k=t=>E.get(t),dt=t=>E.delete(t),j=t=>E.has(t),L=(t,e)=>{let a=k(t);a&&typeof a=="object"?E.set(t,Object.assign(a,e)):E.set(t,e)},d=t=>typeof t=="function"?d(t()):t;function h(t,e){let a=e.split(".");if(!e)return t;for(let r of a){if(["state"].includes(r)&&t?.state)return t[r];if(m(t)){let n=t()?.[r];if(m(n)){let o=new AbortController,l=b(n());n.subscribe({next:l},{signal:o.signal});let c=s=>{o.abort(),m(s[r])?(o=new AbortController,s[r].subscribe({next:l},{signal:o.signal}),l(s[r]())):l(s[r])};t.subscribe({next:c}),t=l}else t=t.map(o=>o&&o[r])}else if(typeof t=="function")t=d(t);else if(typeof t[r]<"u")typeof t[r]=="function"&&!m(t[r])?t=t[r].bind(t):t=t[r];else return}return t}function B(t,e){let a=e.split(".");if(!e)return!1;for(let r of a){if(["loading","error"].includes(r)&&t?.loading&&t?.error)return t[r];if(typeof t=="function")t=d(t);else if(typeof t[r]<"u")t=t[r];else return!1}return!0}var I={items:new Map,setItem(t,e){this.items.set(t,e.toString())},get length(){return this.items.keys().length},key(t){return Array.from(this.items.values()).at(t)},clear(){this.items.clear()},getItem(t){return this.items.get(t)},removeItem(t){this.items.delete(t)}},P=new Map;function rt(t){try{let e=window[t+"Storage"];return typeof e.length=="number"?e:I}catch{return I}}window.addEventListener("storage",t=>{if(!P.has(t.key))return;let e=P.get(t.key),a=t.storageArea.getItem(t.key);typeof a=="string"&&a!=="undefined"&&e.update(JSON.parse(a))});function b(t=null,e={}){if(e.id&&P.has(e.id))return P.get(e.id);let a=[],r=e.storage&&rt(e.storage),n=s=>{t=s,r&&r.setItem(e.id,JSON.stringify(t));for(let i of a)i.next(t)};function o(){return arguments.length&&t!==arguments[0]&&n(arguments[0]),t}let l=(s,i=null)=>{a.push(s),i?.signal.addEventListener("abort",()=>{let u=a.indexOf(s);u>-1&&a.splice(u,1)},{once:!0})};if(r){let s=r.getItem(e.id);n(typeof s=="string"&&s!=="undefined"?JSON.parse(s):t)}let c=Object.assign(o,{id:e.id,storage:e.storage,toString:()=>t.toString(),set:s=>t=s,update:n,subscribe:l,map:s=>{let i=b(s(t)),u=new AbortController,p=i.subscribe;return l({next:f=>i(s(f))},{signal:u.signal}),Object.assign(i,{set:()=>null,subscribe:(f,g)=>{p(f,g),g?.signal.addEventListener("abort",()=>u.abort())}})},filter:s=>{let i=b(s(t)?t:null);return l({next:u=>s(u)?i(u):null}),Object.assign(i,{set:()=>null})}});return e.id&&P.set(e.id,c),c}function nt(t,e=[],a=null){for(let r of e)r.subscribe({next:()=>a=t(a)});return t(a)}function bt(t,e=[],a=null){let r=b(null);return r(nt(n=>r(t(n)),e,a)),r}function at(t,e=null){let a=b(e),r=b("pending"),n=async()=>{try{r("pending"),a(await t()),r("ok"),delete a.error}catch(o){r("error"),a.error=o}return a()};return n(),Object.assign(a,{state:r,refetch:n})}function gt(t,e,a=null){let r=at(()=>e(d(t)),a);return m(t)&&t.subscribe({next:()=>r.refetch()}),r}var m=t=>t&&t.subscribe;var st=b({}),A=b(location.pathname);var y=document.querySelector('head meta[name="route"]');y||(y=document.createElement("meta"),y.name="route",y.content=location.pathname,document.head.append(y));var C=()=>{y.content="",A(location.pathname),st(Object.fromEntries(new URLSearchParams(location.search))),y.content=y.content||location.pathname};window.addEventListener("popstate",C);window.addEventListener("hashchange",C);var ot=window.history.pushState,it=window.history.replaceState;window.history.pushState=function(e,a,r){ot.call(window.history,e,a,r),C()};window.history.replaceState=function(e,a,r){it.call(window.history,e,a,r),C()};var M=new WeakMap,ct=new MutationObserver(t=>{for(let e of t)M.has(e.target)&&M.get(e.target)()}),R={select:"[data-match]",run:t=>{let e=t.dataset.match,a=o=>o.replace(/index\.*[a-z0-9]*$/gm,"");function r(){return a(new URL(t.dataset.route||t.getAttribute("href"),location.href).pathname)}let n=()=>{r()==a(location.pathname)?t.classList.add(e):t.classList.remove(e)};A.subscribe({next:n}),M.set(t,n),ct.observe(t,{attributes:!0,attributeFilter:["href","data-route"]}),n(),t.removeAttribute("data-match")}};var T={number:t=>t.valueAsNumber,date:t=>t.valueAsDate,text:t=>t.value,checkbox:t=>t.checked,"":t=>t.value},q={select:"[data-bind],[name]",run:(t,e)=>{let a=t.getAttribute("name")||t.dataset.bind,r=h(e,a);if(r){let n=o=>{t.type=="checkbox"?t.checked=o:t.value=o};n(d(r)),m(r)&&(r.subscribe({next:n}),t.addEventListener("input",()=>r(T[t.type]?.(t)??t.value)),t.addEventListener("change",()=>r(T[t.type]?.(t)??t.value)))}}};var N=new WeakMap,_=new IntersectionObserver(t=>{for(let e of t)if(e.isIntersecting&&N.has(e.target)){for(let a of N.get(e.target))a();N.delete(e.target),_.unobserve(e.target)}},{rootMargin:"256px"});function w(t){return new Promise(e=>{let a=N.get(t)??[];a.push(e),N.set(t,a),_.observe(t)})}var O=new WeakSet,H={select:"[data-include]",run:(t,e)=>{if(O.has(t)||t.children.length)return;O.add(t);let a=t.hasAttribute("data-lazy")&&t.closest("[hidden]"),r=async()=>{t.dispatchEvent(new CustomEvent("::load",{bubbles:!0}));let n=await fetch(t.dataset.include,{headers:{accept:"text/html,text/*"}});if(n.ok){let o=await n.text();t.dispatchEvent(new CustomEvent("::loaded",{bubbles:!0})),t.innerHTML=o;for(let l of t.childNodes)x(l,e);t.removeAttribute("data-include"),t.removeAttribute("data-lazy")}};t.hasAttribute("data-lazy")?w(t).then(r):r()}};var U=new WeakSet,$={select:"[data-for]",run:(t,e,a)=>{if(U.has(t))return;let r=t.dataset.for.replace("let","").split("of"),n=r[0].split(","),o=r.at(-1).trim(),l=n[0].trim()==o?"__e":n[0].trim(),c=n[1]?.trim()??"__i",s=h(e,o),i=document.createComment(t.dataset.for);t.replaceWith(i),O.add(t);let u=()=>{let f=i;for(;(f=f.nextSibling)&&(f instanceof HTMLElement&&f.dataset.for==t.dataset.for);)f=f.previousSibling,f.nextSibling.remove()},p=f=>{if(u(),!f||!f[Symbol.iterator])return console.warn("data-for: The value given is not iterable.",{key:o,value:f});for(let g=0,v=i;g{let a=h(e,t.dataset.if),r=document.createComment("if: "+t.dataset.if);t.replaceWith(r);let n=o=>{!t.parentNode&&o?(t.hidden=!1,r.after(t)):t.localName!="link"&&t.remove()};n(d(a)),m(a)&&a.subscribe({next:n})}};var V=new WeakSet,J={select:"[data-lazy]",run:(t,e,a)=>{if(V.has(t)||!t.childNodes.length)return;V.add(t);let r=t.dataset.lazy,n=()=>{t.removeAttribute("data-lazy");for(let o of t.childNodes)x(o,e)};r&&(t.addEventListener("::load",()=>t.classList.add(r),{once:!0}),t.addEventListener("::loaded",()=>t.classList.remove(r),{once:!0})),w(t).then(n),a()}};var D={select:"[data-on]",run:(t,e)=>{let a=r=>{let n=r.split(":"),o=n[0].trim(),l=n.at(-1).trim(),c=h(e,l);c&&t.addEventListener(o,c)};for(let r of t.dataset.on.split(","))a(r)}};var K=t=>{let e=document.createElement("link");Object.assign(e,t),e.rel="preload",document.head.append(e)};var G=new WeakSet,Q={select:"[data-preload]",run:t=>{if(G.has(t)||t.hidden)return;G.add(t);let e=()=>{let a=t.dataset.preload.split(",");for(let r of a){let n=r.split(":");K({href:n[0],as:n[1]??"fetch"})}};t.hasAttribute("data-lazy")?w(t).then(e):e()}};var lt=t=>{let e=t.dataset.route;for(;t=t.parentElement;)t.dataset.route&&(e=t.dataset.route+e);return e.replaceAll(/\/+/g,"/")},X={select:"[data-route]",run:async t=>{"URLPattern"in window||await import("https://kevinblt.github.io/hec/packages/@hec.js/ui/dist/urlpattnern.min.js");let e=lt(t),a=new URLPattern({pathname:e}),r=document.createComment("route: "+e);t.replaceWith(r);let n=()=>{let o=location.href.replace(/index\.*[a-z0-9]*$/gm,"");if(!t.parentNode&&a.test(o)){t.hidden=!1,r.after(t);let l=document.querySelector('head meta[name="route"]');l&&(l.content=a.pathname)}else t.localName!="link"&&t.remove()};A.subscribe({next:n}),n()}};var Y=[$,F,X,Q,H,D,q,R,J];var Z={};function ue(t,e={}){t instanceof URL&&(t=t.host==location.host?t.pathname:t.toString());let a=document.querySelector(`template[name="${t}"]`);if(!a){let r=document.querySelector('head meta[name="template-path"]');return Z[t]??=new Promise(async n=>{a=document.createElement("template"),a.setAttribute("id",t.toString()),a.innerHTML=await fetch(r?.content?.replaceAll("[name]",t.toString())??t).then(c=>c.text());let o=a.content.querySelectorAll('link[rel="stylesheet"][href]'),l=[];for(let c of o)l.push(fetch(c.href).then(s=>s.text()).then(s=>{let i=document.createElement("style");i.innerHTML=s,c.replaceWith(i)}));await Promise.all(l),document.body.append(a),n(a)}),Z[t].then(n=>x(n.content.cloneNode(!0),e))}return x(a.content.cloneNode(!0),e)}function fe(t,e={}){let a=document.createElement("template");return a.dataset.name="anonymous",a.innerHTML=t,x(a.content.cloneNode(!0),e)}function x(t,e={}){let a=(n,o)=>{let l=n.match(/{{[^}]+}}/g).map(W),c=n,s=()=>{n=c;for(let i of l){let u=d(i.value);n=n.replace(i.text,u??"")}return n};for(let i of l){let u=h(e,i.prop);if(u==null&&console.warn(`{{ ${i.prop} }}: No value for this key`,{key:i.prop,value:u}),m(u)){let p=u;for(let f in i.meta)if(S[f]){let g=S[f];p=p.map(v=>g({value:v,key:i.prop,param:i.meta[f],options:i.meta}))}i.value=p,p.subscribe({next:()=>o(s())})}else{let p=u;for(let f in i.meta)if(S[f]){let g=S[f];p=g({value:d(u),key:i.prop,param:i.meta[f],options:i.meta})}i.value=()=>p}}o(s())},r=(n,o=new WeakSet)=>{let l=!1;if(!(j(n)||o.has(n))){if(n.nodeName=="#document-fragment"&&L(n,e),n instanceof HTMLElement){let c=n.getAttributeNames();L(n,e);for(let s of Y)n.matches(s.select)&&s.run(n,e,()=>l=!0);for(let s of c){let i=n.getAttribute(s);i?.includes("{{")?a(i,u=>{u=u.trim().replace(/ +/," "),u===""?n.removeAttribute(s):n.setAttribute(s,u)}):n.localName.includes("-")&&B(e,i)&&n.setAttribute(s,`@parent.${i}`)}if(l)return}else if(n instanceof Text&&n.textContent.includes("{{")){let c=n.textContent.split(/{{|}}/g);for(let s=0,i=n,u;su.data=p.replaceAll("","")),o.add(u),i.after(u),i=u;n.remove()}o.add(n);for(let c of n.childNodes)r(c,o)}};return r(t,new WeakSet),t}function ge(t,e,a){customElements.define(t,class extends HTMLElement{static observedAttributes=Object.keys(e).map(r=>r.toLowerCase());#e=Object.fromEntries(Object.entries(e).map(r=>[r[0],b(r[1])]));#t={};#r=!1;#n=null;on(r,n,o=null){this.addEventListener(r,n,o)}querySelector(r){return this.shadowRoot.querySelector(r)}querySelectorAll(r){return this.shadowRoot.querySelectorAll(r)}async connectedCallback(){if(this.#n??=this.hasAttribute("data-lazy"),this.#n&&(await w(this),this.removeAttribute("data-lazy")),this.dispatchEvent(new CustomEvent("::load",{bubbles:!0})),this.#r){this.dispatchEvent(new CustomEvent("::loaded",{bubbles:!0})),this.dispatchEvent(new CustomEvent("::mount"));return}let r=this.shadowRoot??this.attachShadow({mode:"open"}),n=a(this.#e,this);(l=>{L(this,k(l)),this.dispatchEvent(new CustomEvent("::loaded",{bubbles:!0})),r.append(l),this.#r=!0,this.#t["::attributes"]=new AbortController;for(let c in e)this.hasAttribute(c)||this.setAttribute(c,e[c].toString()),this.#e[c].subscribe({next:s=>this.setAttribute(c,s.toString())},{signal:this.#t["::attributes"].signal});this.dispatchEvent(new CustomEvent("::mount"))})(n instanceof Promise?await n:n)}disconnectedCallback(){this.dispatchEvent(new CustomEvent("::unmount"))}#a(r=""){r=r.toLowerCase();for(let n in this.#e)if(n.toLowerCase()==r)return[e[n],this.#e[n]];return[null,null]}attributeChangedCallback(r,n,o){let[l,c]=this.#a(r);if(o.startsWith("@parent.")){let s=this.parentNode.host||this.parentNode,i=o.slice(8),u=h(k(s),i)??h(k(this),i);m(u)?(this.#t[l]?.abort(),this.#t[l]=new AbortController,c(d(u)),u.subscribe({next:c},{signal:this.#t[l].signal})):c(u)}else c(typeof l=="number"?parseFloat(o):o)}})}var tt=new WeakMap;function we(t,e=null){document.dispatchEvent(new CustomEvent(t,{detail:e}))}function ve(t,e){let a=r=>e(r.detail);tt.set(e,a),document.addEventListener(t,a)}function Se(t){return new Promise(e=>{let a=r=>e(r.detail);document.addEventListener(t,a,{once:!0})})}function Ee(t,e){document.removeEventListener(t,tt.get(e))}export{ge as component,dt as deletePropsOf,nt as effect,we as emit,W as expression,d as f,B as hasProp,j as hasProps,m as isSignal,bt as memo,Ee as off,ve as on,Se as once,S as pipes,Y as plugins,h as prop,k as propsOf,at as resource,gt as resourceBy,L as setPropsOf,b as signal,ue as templateByName,x as templateByNode,fe as templateByString}; diff --git a/packages/@hec.js/ui/dist/hec.min.js b/packages/@hec.js/ui/dist/hec.min.js index fb3fdf8..74b1857 100644 --- a/packages/@hec.js/ui/dist/hec.min.js +++ b/packages/@hec.js/ui/dist/hec.min.js @@ -1 +1 @@ -(()=>{var ot=Object.create;var z=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var lt=Object.getOwnPropertyNames;var ct=Object.getPrototypeOf,ut=Object.prototype.hasOwnProperty;var ft=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var mt=(t,e)=>{for(var n in e)z(t,n,{get:e[n],enumerable:!0})},dt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of lt(e))!ut.call(t,a)&&a!==n&&z(t,a,{get:()=>e[a],enumerable:!(r=it(e,a))||r.enumerable});return t};var pt=(t,e,n)=>(n=t!=null?ot(ct(t)):{},dt(e||!t||!t.__esModule?z(n,"default",{value:t,enumerable:!0}):n,t));var M={};mt(M,{component:()=>Pt,deletePropsOf:()=>ht,effect:()=>_,emit:()=>At,expression:()=>W,f:()=>d,hasProp:()=>T,hasProps:()=>j,isSignal:()=>m,memo:()=>gt,off:()=>Ot,on:()=>Nt,once:()=>Ct,pipes:()=>v,plugins:()=>I,prop:()=>h,propsOf:()=>S,resource:()=>H,resourceBy:()=>xt,setPropsOf:()=>E,signal:()=>b,templateByName:()=>kt,templateByNode:()=>x,templateByString:()=>Lt});function W(t){let e=t.matchAll(/([^ {}\s]+)/g),n={meta:{},text:t,prop:null};for(let r of e)if(r[1].includes("=")){let a=r[1].split("=");n.meta[a[0]]=a[1].replaceAll(/'|"/g,"")}else n.prop=r[1];return n}var v={};var L=new WeakMap,S=t=>L.get(t),ht=t=>L.delete(t),j=t=>L.has(t),E=(t,e)=>{let n=S(t);n&&typeof n=="object"?L.set(t,Object.assign(n,e)):L.set(t,e)},d=t=>typeof t=="function"?d(t()):t;function h(t,e){let n=e.split(".");if(!e)return t;for(let r of n){if(["state"].includes(r)&&t?.state)return t[r];if(m(t)){let a=t()?.[r];if(m(a)){let o=new AbortController,c=b(a());a.subscribe({next:c},{signal:o.signal});let l=s=>{o.abort(),m(s[r])?(o=new AbortController,s[r].subscribe({next:c},{signal:o.signal}),c(s[r]())):c(s[r])};t.subscribe({next:l}),t=c}else t=t.map(o=>o&&o[r])}else if(typeof t=="function")t=d(t);else if(typeof t[r]<"u")typeof t[r]=="function"&&!m(t[r])?t=t[r].bind(t):t=t[r];else return}return t}function T(t,e){let n=e.split(".");if(!e)return!1;for(let r of n){if(["loading","error"].includes(r)&&t?.loading&&t?.error)return t[r];if(typeof t=="function")t=d(t);else if(typeof t[r]<"u")t=t[r];else return!1}return!0}var q={items:new Map,setItem(t,e){this.items.set(t,e.toString())},get length(){return this.items.keys().length},key(t){return Array.from(this.items.values()).at(t)},clear(){this.items.clear()},getItem(t){return this.items.get(t)},removeItem(t){this.items.delete(t)}},P=new Map;function bt(t){try{let e=window[t+"Storage"];return typeof e.length=="number"?e:q}catch{return q}}window.addEventListener("storage",t=>{if(!P.has(t.key))return;let e=P.get(t.key),n=t.storageArea.getItem(t.key);typeof n=="string"&&n!=="undefined"&&e.update(JSON.parse(n))});function b(t=null,e={}){if(e.id&&P.has(e.id))return P.get(e.id);let n=[],r=e.storage&&bt(e.storage),a=s=>{t=s,r&&r.setItem(e.id,JSON.stringify(t));for(let i of n)i.next(t)};function o(){return arguments.length&&t!==arguments[0]&&a(arguments[0]),t}let c=(s,i=null)=>{n.push(s),i?.signal.addEventListener("abort",()=>{let u=n.indexOf(s);u>-1&&n.splice(u,1)},{once:!0})};if(r){let s=r.getItem(e.id);a(typeof s=="string"&&s!=="undefined"?JSON.parse(s):t)}let l=Object.assign(o,{id:e.id,storage:e.storage,toString:()=>t.toString(),set:s=>t=s,update:a,subscribe:c,map:s=>{let i=b(s(t)),u=new AbortController,p=i.subscribe;return c({next:f=>i(s(f))},{signal:u.signal}),Object.assign(i,{set:()=>null,subscribe:(f,g)=>{p(f,g),g?.signal.addEventListener("abort",()=>u.abort())}})},filter:s=>{let i=b(s(t)?t:null);return c({next:u=>s(u)?i(u):null}),Object.assign(i,{set:()=>null})}});return e.id&&P.set(e.id,l),l}function _(t,e=[],n=null){for(let r of e)r.subscribe({next:()=>n=t(n)});return t(n)}function gt(t,e=[],n=null){let r=b(null);return r(_(a=>r(t(a)),e,n)),r}function H(t,e=null){let n=b(e),r=b("pending"),a=async()=>{try{r("pending"),n(await t()),r(null),delete n.error}catch(o){r("error"),n.error=o}return n()};return a(),Object.assign(n,{state:r,refetch:a})}function xt(t,e,n=null){let r=H(()=>e(d(t)),n);return m(t)&&t.subscribe({next:()=>r.refetch()}),r}var m=t=>t&&t.subscribe;var yt=b({}),A=b(location.pathname);var y=document.querySelector('head meta[name="route"]');y||(y=document.createElement("meta"),y.name="route",y.content=location.pathname,document.head.append(y));var C=()=>{y.content="",A(location.pathname),yt(Object.fromEntries(new URLSearchParams(location.search))),y.content=y.content||location.pathname};window.addEventListener("popstate",C);window.addEventListener("hashchange",C);var wt=window.history.pushState,vt=window.history.replaceState;window.history.pushState=function(e,n,r){wt.call(window.history,e,n,r),C()};window.history.replaceState=function(e,n,r){vt.call(window.history,e,n,r),C()};var B=new WeakMap,St=new MutationObserver(t=>{for(let e of t)B.has(e.target)&&B.get(e.target)()}),U={select:"[data-match]",run:t=>{let e=t.dataset.match,n=o=>o.replace(/index\.*[a-z0-9]*$/gm,"");function r(){return n(new URL(t.dataset.route||t.getAttribute("href"),location.href).pathname)}let a=()=>{r()==n(location.pathname)?t.classList.add(e):t.classList.remove(e)};A.subscribe({next:a}),B.set(t,a),St.observe(t,{attributes:!0,attributeFilter:["href","data-route"]}),a(),t.removeAttribute("data-match")}};var $={number:t=>t.valueAsNumber,date:t=>t.valueAsDate,text:t=>t.value,checkbox:t=>t.checked,"":t=>t.value},F={select:"[data-bind],[name]",run:(t,e)=>{let n=t.getAttribute("name")||t.dataset.bind,r=h(e,n);if(r){let a=o=>{t.type=="checkbox"?t.checked=o:t.value=o};a(d(r)),m(r)&&(r.subscribe({next:a}),t.addEventListener("input",()=>r($[t.type]?.(t)??t.value)),t.addEventListener("change",()=>r($[t.type]?.(t)??t.value)))}}};var N=new WeakMap,V=new IntersectionObserver(t=>{for(let e of t)if(e.isIntersecting&&N.has(e.target)){for(let n of N.get(e.target))n();N.delete(e.target),V.unobserve(e.target)}},{rootMargin:"256px"});function w(t){return new Promise(e=>{let n=N.get(t)??[];n.push(e),N.set(t,n),V.observe(t)})}var O=new WeakSet,J={select:"[data-include]",run:(t,e)=>{if(O.has(t)||t.children.length)return;O.add(t);let n=t.hasAttribute("data-lazy")&&t.closest("[hidden]"),r=async()=>{t.dispatchEvent(new CustomEvent("::load",{bubbles:!0}));let a=await fetch(t.dataset.include,{headers:{accept:"text/html,text/*"}});if(a.ok){let o=await a.text();t.dispatchEvent(new CustomEvent("::loaded",{bubbles:!0})),t.innerHTML=o;for(let c of t.childNodes)x(c,e);t.removeAttribute("data-include"),t.removeAttribute("data-lazy")}};t.hasAttribute("data-lazy")?w(t).then(r):r()}};var D=new WeakSet,K={select:"[data-for]",run:(t,e,n)=>{if(D.has(t))return;let r=t.dataset.for.replace("let","").split("of"),a=r[0].split(","),o=r.at(-1).trim(),c=a[0].trim()==o?"__e":a[0].trim(),l=a[1]?.trim()??"__i",s=h(e,o),i=document.createComment(t.dataset.for);t.replaceWith(i),O.add(t);let u=()=>{let f=i;for(;(f=f.nextSibling)&&(f instanceof HTMLElement&&f.dataset.for==t.dataset.for);)f=f.previousSibling,f.nextSibling.remove()},p=f=>{if(u(),!f||!f[Symbol.iterator])return console.warn("data-for: The value given is not iterable.",{key:o,value:f});for(let g=0,k=i;g{let n=h(e,t.dataset.if),r=document.createComment("if: "+t.dataset.if);t.replaceWith(r);let a=o=>{!t.parentNode&&o?(t.hidden=!1,r.after(t)):t.localName!="link"&&t.remove()};a(d(n)),m(n)&&n.subscribe({next:a})}};var Q=new WeakSet,X={select:"[data-lazy]",run:(t,e,n)=>{if(Q.has(t)||!t.childNodes.length)return;Q.add(t);let r=t.dataset.lazy,a=()=>{t.removeAttribute("data-lazy");for(let o of t.childNodes)x(o,e)};r&&(t.addEventListener("::load",()=>t.classList.add(r),{once:!0}),t.addEventListener("::loaded",()=>t.classList.remove(r),{once:!0})),w(t).then(a),n()}};var Y={select:"[data-on]",run:(t,e)=>{let n=r=>{let a=r.split(":"),o=a[0].trim(),c=a.at(-1).trim(),l=h(e,c);l&&t.addEventListener(o,l)};for(let r of t.dataset.on.split(","))n(r)}};var Z=t=>{let e=document.createElement("link");Object.assign(e,t),e.rel="preload",document.head.append(e)};var tt=new WeakSet,et={select:"[data-preload]",run:t=>{if(tt.has(t)||t.hidden)return;tt.add(t);let e=()=>{let n=t.dataset.preload.split(",");for(let r of n){let a=r.split(":");Z({href:a[0],as:a[1]??"fetch"})}};t.hasAttribute("data-lazy")?w(t).then(e):e()}};var Et=t=>{let e=t.dataset.route;for(;t=t.parentElement;)t.dataset.route&&(e=t.dataset.route+e);return e.replaceAll(/\/+/g,"/")},rt={select:"[data-route]",run:async t=>{"URLPattern"in window||await import("https://kevinblt.github.io/hec/packages/@hec.js/ui/dist/urlpattnern.min.js");let e=Et(t),n=new URLPattern({pathname:e}),r=document.createComment("route: "+e);t.replaceWith(r);let a=()=>{let o=location.href.replace(/index\.*[a-z0-9]*$/gm,"");if(!t.parentNode&&n.test(o)){t.hidden=!1,r.after(t);let c=document.querySelector('head meta[name="route"]');c&&(c.content=n.pathname)}else t.localName!="link"&&t.remove()};A.subscribe({next:a}),a()}};var I=[K,G,rt,et,J,Y,F,U,X];var nt={};function kt(t,e={}){t instanceof URL&&(t=t.host==location.host?t.pathname:t.toString());let n=document.querySelector(`template[name="${t}"]`);if(!n){let r=document.querySelector('head meta[name="template-path"]');return nt[t]??=new Promise(async a=>{n=document.createElement("template"),n.setAttribute("id",t.toString()),n.innerHTML=await fetch(r?.content?.replaceAll("[name]",t.toString())??t).then(l=>l.text());let o=n.content.querySelectorAll('link[rel="stylesheet"][href]'),c=[];for(let l of o)c.push(fetch(l.href).then(s=>s.text()).then(s=>{let i=document.createElement("style");i.innerHTML=s,l.replaceWith(i)}));await Promise.all(c),document.body.append(n),a(n)}),nt[t].then(a=>x(a.content.cloneNode(!0),e))}return x(n.content.cloneNode(!0),e)}function Lt(t,e={}){let n=document.createElement("template");return n.dataset.name="anonymous",n.innerHTML=t,x(n.content.cloneNode(!0),e)}function x(t,e={}){let n=(a,o)=>{let c=a.match(/{{[^}]+}}/g).map(W),l=a,s=()=>{a=l;for(let i of c){let u=d(i.value);a=a.replace(i.text,u??"")}return a};for(let i of c){let u=h(e,i.prop);if(u==null&&console.warn(`{{ ${i.prop} }}: No value for this key`,{key:i.prop,value:u}),m(u)){let p=u;for(let f in i.meta)if(v[f]){let g=v[f];p=p.map(k=>g({value:k,key:i.prop,param:i.meta[f],options:i.meta}))}i.value=p,p.subscribe({next:()=>o(s())})}else{let p=u;for(let f in i.meta)if(v[f]){let g=v[f];p=g({value:d(u),key:i.prop,param:i.meta[f],options:i.meta})}i.value=()=>p}}o(s())},r=(a,o=new WeakSet)=>{let c=!1;if(!(j(a)||o.has(a))){if(a.nodeName=="#document-fragment"&&E(a,e),a instanceof HTMLElement){let l=a.getAttributeNames();E(a,e);for(let s of I)a.matches(s.select)&&s.run(a,e,()=>c=!0);for(let s of l){let i=a.getAttribute(s);i?.includes("{{")?n(i,u=>{u=u.trim().replace(/ +/," "),u===""?a.removeAttribute(s):a.setAttribute(s,u)}):a.localName.includes("-")&&T(e,i)&&a.setAttribute(s,`@parent.${i}`)}if(c)return}else if(a instanceof Text&&a.textContent.includes("{{")){let l=a.textContent.split(/{{|}}/g);for(let s=0,i=a,u;su.data=p.replaceAll("","")),o.add(u),i.after(u),i=u;a.remove()}o.add(a);for(let l of a.childNodes)r(l,o)}};return r(t,new WeakSet),t}function Pt(t,e,n){customElements.define(t,class extends HTMLElement{static observedAttributes=Object.keys(e).map(r=>r.toLowerCase());#e=Object.fromEntries(Object.entries(e).map(r=>[r[0],b(r[1])]));#t={};#r=!1;#n=null;on(r,a,o=null){this.addEventListener(r,a,o)}querySelector(r){return this.shadowRoot.querySelector(r)}querySelectorAll(r){return this.shadowRoot.querySelectorAll(r)}async connectedCallback(){if(this.#n??=this.hasAttribute("data-lazy"),this.#n&&(await w(this),this.removeAttribute("data-lazy")),this.dispatchEvent(new CustomEvent("::load",{bubbles:!0})),this.#r){this.dispatchEvent(new CustomEvent("::loaded",{bubbles:!0})),this.dispatchEvent(new CustomEvent("::mount"));return}let r=this.shadowRoot??this.attachShadow({mode:"open"}),a=n(this.#e,this);(c=>{E(this,S(c)),this.dispatchEvent(new CustomEvent("::loaded",{bubbles:!0})),r.append(c),this.#r=!0,this.#t["::attributes"]=new AbortController;for(let l in e)this.hasAttribute(l)||this.setAttribute(l,e[l].toString()),this.#e[l].subscribe({next:s=>this.setAttribute(l,s.toString())},{signal:this.#t["::attributes"].signal});this.dispatchEvent(new CustomEvent("::mount"))})(a instanceof Promise?await a:a)}disconnectedCallback(){this.dispatchEvent(new CustomEvent("::unmount"))}#a(r=""){r=r.toLowerCase();for(let a in this.#e)if(a.toLowerCase()==r)return[e[a],this.#e[a]];return[null,null]}attributeChangedCallback(r,a,o){let[c,l]=this.#a(r);if(o.startsWith("@parent.")){let s=this.parentNode.host||this.parentNode,i=o.slice(8),u=h(S(s),i)??h(S(this),i);m(u)?(this.#t[c]?.abort(),this.#t[c]=new AbortController,l(d(u)),u.subscribe({next:l},{signal:this.#t[c].signal})):l(u)}else l(typeof c=="number"?parseFloat(o):o)}})}var at=new WeakMap;function At(t,e=null){document.dispatchEvent(new CustomEvent(t,{detail:e}))}function Nt(t,e){let n=r=>e(r.detail);at.set(e,n),document.addEventListener(t,n)}function Ct(t){return new Promise(e=>{let n=r=>e(r.detail);document.addEventListener(t,n,{once:!0})})}function Ot(t,e){document.removeEventListener(t,at.get(e))}for(let t in M)globalThis[t]=M[t];})(); +(()=>{var ot=Object.create;var z=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var lt=Object.getOwnPropertyNames;var ct=Object.getPrototypeOf,ut=Object.prototype.hasOwnProperty;var ft=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var mt=(t,e)=>{for(var n in e)z(t,n,{get:e[n],enumerable:!0})},dt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of lt(e))!ut.call(t,a)&&a!==n&&z(t,a,{get:()=>e[a],enumerable:!(r=it(e,a))||r.enumerable});return t};var pt=(t,e,n)=>(n=t!=null?ot(ct(t)):{},dt(e||!t||!t.__esModule?z(n,"default",{value:t,enumerable:!0}):n,t));var M={};mt(M,{component:()=>Pt,deletePropsOf:()=>ht,effect:()=>_,emit:()=>At,expression:()=>W,f:()=>d,hasProp:()=>T,hasProps:()=>j,isSignal:()=>m,memo:()=>gt,off:()=>Ot,on:()=>Nt,once:()=>Ct,pipes:()=>v,plugins:()=>I,prop:()=>h,propsOf:()=>S,resource:()=>H,resourceBy:()=>xt,setPropsOf:()=>E,signal:()=>b,templateByName:()=>kt,templateByNode:()=>x,templateByString:()=>Lt});function W(t){let e=t.matchAll(/([^ {}\s]+)/g),n={meta:{},text:t,prop:null};for(let r of e)if(r[1].includes("=")){let a=r[1].split("=");n.meta[a[0]]=a[1].replaceAll(/'|"/g,"")}else n.prop=r[1];return n}var v={};var L=new WeakMap,S=t=>L.get(t),ht=t=>L.delete(t),j=t=>L.has(t),E=(t,e)=>{let n=S(t);n&&typeof n=="object"?L.set(t,Object.assign(n,e)):L.set(t,e)},d=t=>typeof t=="function"?d(t()):t;function h(t,e){let n=e.split(".");if(!e)return t;for(let r of n){if(["state"].includes(r)&&t?.state)return t[r];if(m(t)){let a=t()?.[r];if(m(a)){let o=new AbortController,c=b(a());a.subscribe({next:c},{signal:o.signal});let l=s=>{o.abort(),m(s[r])?(o=new AbortController,s[r].subscribe({next:c},{signal:o.signal}),c(s[r]())):c(s[r])};t.subscribe({next:l}),t=c}else t=t.map(o=>o&&o[r])}else if(typeof t=="function")t=d(t);else if(typeof t[r]<"u")typeof t[r]=="function"&&!m(t[r])?t=t[r].bind(t):t=t[r];else return}return t}function T(t,e){let n=e.split(".");if(!e)return!1;for(let r of n){if(["loading","error"].includes(r)&&t?.loading&&t?.error)return t[r];if(typeof t=="function")t=d(t);else if(typeof t[r]<"u")t=t[r];else return!1}return!0}var q={items:new Map,setItem(t,e){this.items.set(t,e.toString())},get length(){return this.items.keys().length},key(t){return Array.from(this.items.values()).at(t)},clear(){this.items.clear()},getItem(t){return this.items.get(t)},removeItem(t){this.items.delete(t)}},P=new Map;function bt(t){try{let e=window[t+"Storage"];return typeof e.length=="number"?e:q}catch{return q}}window.addEventListener("storage",t=>{if(!P.has(t.key))return;let e=P.get(t.key),n=t.storageArea.getItem(t.key);typeof n=="string"&&n!=="undefined"&&e.update(JSON.parse(n))});function b(t=null,e={}){if(e.id&&P.has(e.id))return P.get(e.id);let n=[],r=e.storage&&bt(e.storage),a=s=>{t=s,r&&r.setItem(e.id,JSON.stringify(t));for(let i of n)i.next(t)};function o(){return arguments.length&&t!==arguments[0]&&a(arguments[0]),t}let c=(s,i=null)=>{n.push(s),i?.signal.addEventListener("abort",()=>{let u=n.indexOf(s);u>-1&&n.splice(u,1)},{once:!0})};if(r){let s=r.getItem(e.id);a(typeof s=="string"&&s!=="undefined"?JSON.parse(s):t)}let l=Object.assign(o,{id:e.id,storage:e.storage,toString:()=>t.toString(),set:s=>t=s,update:a,subscribe:c,map:s=>{let i=b(s(t)),u=new AbortController,p=i.subscribe;return c({next:f=>i(s(f))},{signal:u.signal}),Object.assign(i,{set:()=>null,subscribe:(f,g)=>{p(f,g),g?.signal.addEventListener("abort",()=>u.abort())}})},filter:s=>{let i=b(s(t)?t:null);return c({next:u=>s(u)?i(u):null}),Object.assign(i,{set:()=>null})}});return e.id&&P.set(e.id,l),l}function _(t,e=[],n=null){for(let r of e)r.subscribe({next:()=>n=t(n)});return t(n)}function gt(t,e=[],n=null){let r=b(null);return r(_(a=>r(t(a)),e,n)),r}function H(t,e=null){let n=b(e),r=b("pending"),a=async()=>{try{r("pending"),n(await t()),r("ok"),delete n.error}catch(o){r("error"),n.error=o}return n()};return a(),Object.assign(n,{state:r,refetch:a})}function xt(t,e,n=null){let r=H(()=>e(d(t)),n);return m(t)&&t.subscribe({next:()=>r.refetch()}),r}var m=t=>t&&t.subscribe;var yt=b({}),A=b(location.pathname);var y=document.querySelector('head meta[name="route"]');y||(y=document.createElement("meta"),y.name="route",y.content=location.pathname,document.head.append(y));var C=()=>{y.content="",A(location.pathname),yt(Object.fromEntries(new URLSearchParams(location.search))),y.content=y.content||location.pathname};window.addEventListener("popstate",C);window.addEventListener("hashchange",C);var wt=window.history.pushState,vt=window.history.replaceState;window.history.pushState=function(e,n,r){wt.call(window.history,e,n,r),C()};window.history.replaceState=function(e,n,r){vt.call(window.history,e,n,r),C()};var B=new WeakMap,St=new MutationObserver(t=>{for(let e of t)B.has(e.target)&&B.get(e.target)()}),U={select:"[data-match]",run:t=>{let e=t.dataset.match,n=o=>o.replace(/index\.*[a-z0-9]*$/gm,"");function r(){return n(new URL(t.dataset.route||t.getAttribute("href"),location.href).pathname)}let a=()=>{r()==n(location.pathname)?t.classList.add(e):t.classList.remove(e)};A.subscribe({next:a}),B.set(t,a),St.observe(t,{attributes:!0,attributeFilter:["href","data-route"]}),a(),t.removeAttribute("data-match")}};var $={number:t=>t.valueAsNumber,date:t=>t.valueAsDate,text:t=>t.value,checkbox:t=>t.checked,"":t=>t.value},F={select:"[data-bind],[name]",run:(t,e)=>{let n=t.getAttribute("name")||t.dataset.bind,r=h(e,n);if(r){let a=o=>{t.type=="checkbox"?t.checked=o:t.value=o};a(d(r)),m(r)&&(r.subscribe({next:a}),t.addEventListener("input",()=>r($[t.type]?.(t)??t.value)),t.addEventListener("change",()=>r($[t.type]?.(t)??t.value)))}}};var N=new WeakMap,V=new IntersectionObserver(t=>{for(let e of t)if(e.isIntersecting&&N.has(e.target)){for(let n of N.get(e.target))n();N.delete(e.target),V.unobserve(e.target)}},{rootMargin:"256px"});function w(t){return new Promise(e=>{let n=N.get(t)??[];n.push(e),N.set(t,n),V.observe(t)})}var O=new WeakSet,J={select:"[data-include]",run:(t,e)=>{if(O.has(t)||t.children.length)return;O.add(t);let n=t.hasAttribute("data-lazy")&&t.closest("[hidden]"),r=async()=>{t.dispatchEvent(new CustomEvent("::load",{bubbles:!0}));let a=await fetch(t.dataset.include,{headers:{accept:"text/html,text/*"}});if(a.ok){let o=await a.text();t.dispatchEvent(new CustomEvent("::loaded",{bubbles:!0})),t.innerHTML=o;for(let c of t.childNodes)x(c,e);t.removeAttribute("data-include"),t.removeAttribute("data-lazy")}};t.hasAttribute("data-lazy")?w(t).then(r):r()}};var D=new WeakSet,K={select:"[data-for]",run:(t,e,n)=>{if(D.has(t))return;let r=t.dataset.for.replace("let","").split("of"),a=r[0].split(","),o=r.at(-1).trim(),c=a[0].trim()==o?"__e":a[0].trim(),l=a[1]?.trim()??"__i",s=h(e,o),i=document.createComment(t.dataset.for);t.replaceWith(i),O.add(t);let u=()=>{let f=i;for(;(f=f.nextSibling)&&(f instanceof HTMLElement&&f.dataset.for==t.dataset.for);)f=f.previousSibling,f.nextSibling.remove()},p=f=>{if(u(),!f||!f[Symbol.iterator])return console.warn("data-for: The value given is not iterable.",{key:o,value:f});for(let g=0,k=i;g{let n=h(e,t.dataset.if),r=document.createComment("if: "+t.dataset.if);t.replaceWith(r);let a=o=>{!t.parentNode&&o?(t.hidden=!1,r.after(t)):t.localName!="link"&&t.remove()};a(d(n)),m(n)&&n.subscribe({next:a})}};var Q=new WeakSet,X={select:"[data-lazy]",run:(t,e,n)=>{if(Q.has(t)||!t.childNodes.length)return;Q.add(t);let r=t.dataset.lazy,a=()=>{t.removeAttribute("data-lazy");for(let o of t.childNodes)x(o,e)};r&&(t.addEventListener("::load",()=>t.classList.add(r),{once:!0}),t.addEventListener("::loaded",()=>t.classList.remove(r),{once:!0})),w(t).then(a),n()}};var Y={select:"[data-on]",run:(t,e)=>{let n=r=>{let a=r.split(":"),o=a[0].trim(),c=a.at(-1).trim(),l=h(e,c);l&&t.addEventListener(o,l)};for(let r of t.dataset.on.split(","))n(r)}};var Z=t=>{let e=document.createElement("link");Object.assign(e,t),e.rel="preload",document.head.append(e)};var tt=new WeakSet,et={select:"[data-preload]",run:t=>{if(tt.has(t)||t.hidden)return;tt.add(t);let e=()=>{let n=t.dataset.preload.split(",");for(let r of n){let a=r.split(":");Z({href:a[0],as:a[1]??"fetch"})}};t.hasAttribute("data-lazy")?w(t).then(e):e()}};var Et=t=>{let e=t.dataset.route;for(;t=t.parentElement;)t.dataset.route&&(e=t.dataset.route+e);return e.replaceAll(/\/+/g,"/")},rt={select:"[data-route]",run:async t=>{"URLPattern"in window||await import("https://kevinblt.github.io/hec/packages/@hec.js/ui/dist/urlpattnern.min.js");let e=Et(t),n=new URLPattern({pathname:e}),r=document.createComment("route: "+e);t.replaceWith(r);let a=()=>{let o=location.href.replace(/index\.*[a-z0-9]*$/gm,"");if(!t.parentNode&&n.test(o)){t.hidden=!1,r.after(t);let c=document.querySelector('head meta[name="route"]');c&&(c.content=n.pathname)}else t.localName!="link"&&t.remove()};A.subscribe({next:a}),a()}};var I=[K,G,rt,et,J,Y,F,U,X];var nt={};function kt(t,e={}){t instanceof URL&&(t=t.host==location.host?t.pathname:t.toString());let n=document.querySelector(`template[name="${t}"]`);if(!n){let r=document.querySelector('head meta[name="template-path"]');return nt[t]??=new Promise(async a=>{n=document.createElement("template"),n.setAttribute("id",t.toString()),n.innerHTML=await fetch(r?.content?.replaceAll("[name]",t.toString())??t).then(l=>l.text());let o=n.content.querySelectorAll('link[rel="stylesheet"][href]'),c=[];for(let l of o)c.push(fetch(l.href).then(s=>s.text()).then(s=>{let i=document.createElement("style");i.innerHTML=s,l.replaceWith(i)}));await Promise.all(c),document.body.append(n),a(n)}),nt[t].then(a=>x(a.content.cloneNode(!0),e))}return x(n.content.cloneNode(!0),e)}function Lt(t,e={}){let n=document.createElement("template");return n.dataset.name="anonymous",n.innerHTML=t,x(n.content.cloneNode(!0),e)}function x(t,e={}){let n=(a,o)=>{let c=a.match(/{{[^}]+}}/g).map(W),l=a,s=()=>{a=l;for(let i of c){let u=d(i.value);a=a.replace(i.text,u??"")}return a};for(let i of c){let u=h(e,i.prop);if(u==null&&console.warn(`{{ ${i.prop} }}: No value for this key`,{key:i.prop,value:u}),m(u)){let p=u;for(let f in i.meta)if(v[f]){let g=v[f];p=p.map(k=>g({value:k,key:i.prop,param:i.meta[f],options:i.meta}))}i.value=p,p.subscribe({next:()=>o(s())})}else{let p=u;for(let f in i.meta)if(v[f]){let g=v[f];p=g({value:d(u),key:i.prop,param:i.meta[f],options:i.meta})}i.value=()=>p}}o(s())},r=(a,o=new WeakSet)=>{let c=!1;if(!(j(a)||o.has(a))){if(a.nodeName=="#document-fragment"&&E(a,e),a instanceof HTMLElement){let l=a.getAttributeNames();E(a,e);for(let s of I)a.matches(s.select)&&s.run(a,e,()=>c=!0);for(let s of l){let i=a.getAttribute(s);i?.includes("{{")?n(i,u=>{u=u.trim().replace(/ +/," "),u===""?a.removeAttribute(s):a.setAttribute(s,u)}):a.localName.includes("-")&&T(e,i)&&a.setAttribute(s,`@parent.${i}`)}if(c)return}else if(a instanceof Text&&a.textContent.includes("{{")){let l=a.textContent.split(/{{|}}/g);for(let s=0,i=a,u;su.data=p.replaceAll("","")),o.add(u),i.after(u),i=u;a.remove()}o.add(a);for(let l of a.childNodes)r(l,o)}};return r(t,new WeakSet),t}function Pt(t,e,n){customElements.define(t,class extends HTMLElement{static observedAttributes=Object.keys(e).map(r=>r.toLowerCase());#e=Object.fromEntries(Object.entries(e).map(r=>[r[0],b(r[1])]));#t={};#r=!1;#n=null;on(r,a,o=null){this.addEventListener(r,a,o)}querySelector(r){return this.shadowRoot.querySelector(r)}querySelectorAll(r){return this.shadowRoot.querySelectorAll(r)}async connectedCallback(){if(this.#n??=this.hasAttribute("data-lazy"),this.#n&&(await w(this),this.removeAttribute("data-lazy")),this.dispatchEvent(new CustomEvent("::load",{bubbles:!0})),this.#r){this.dispatchEvent(new CustomEvent("::loaded",{bubbles:!0})),this.dispatchEvent(new CustomEvent("::mount"));return}let r=this.shadowRoot??this.attachShadow({mode:"open"}),a=n(this.#e,this);(c=>{E(this,S(c)),this.dispatchEvent(new CustomEvent("::loaded",{bubbles:!0})),r.append(c),this.#r=!0,this.#t["::attributes"]=new AbortController;for(let l in e)this.hasAttribute(l)||this.setAttribute(l,e[l].toString()),this.#e[l].subscribe({next:s=>this.setAttribute(l,s.toString())},{signal:this.#t["::attributes"].signal});this.dispatchEvent(new CustomEvent("::mount"))})(a instanceof Promise?await a:a)}disconnectedCallback(){this.dispatchEvent(new CustomEvent("::unmount"))}#a(r=""){r=r.toLowerCase();for(let a in this.#e)if(a.toLowerCase()==r)return[e[a],this.#e[a]];return[null,null]}attributeChangedCallback(r,a,o){let[c,l]=this.#a(r);if(o.startsWith("@parent.")){let s=this.parentNode.host||this.parentNode,i=o.slice(8),u=h(S(s),i)??h(S(this),i);m(u)?(this.#t[c]?.abort(),this.#t[c]=new AbortController,l(d(u)),u.subscribe({next:l},{signal:this.#t[c].signal})):l(u)}else l(typeof c=="number"?parseFloat(o):o)}})}var at=new WeakMap;function At(t,e=null){document.dispatchEvent(new CustomEvent(t,{detail:e}))}function Nt(t,e){let n=r=>e(r.detail);at.set(e,n),document.addEventListener(t,n)}function Ct(t){return new Promise(e=>{let n=r=>e(r.detail);document.addEventListener(t,n,{once:!0})})}function Ot(t,e){document.removeEventListener(t,at.get(e))}for(let t in M)globalThis[t]=M[t];})(); diff --git a/packages/@hec.js/ui/lib/src/signal.js b/packages/@hec.js/ui/lib/src/signal.js index 6128594..6163edb 100644 --- a/packages/@hec.js/ui/lib/src/signal.js +++ b/packages/@hec.js/ui/lib/src/signal.js @@ -237,7 +237,7 @@ export function memo(fn, signals = [], value = null) { /** * @template T * @typedef {{ - * state: Signal<'pending' | 'error' | null>, + * state: Signal<'pending' | 'error' | 'loaded'>, * error?: string, * refetch: () => Promise * } & Signal} Resource @@ -264,7 +264,7 @@ export function resource(fetch, initialValue = null) { /** @type { Signal } */ const value = signal(initialValue); - /** @type { Signal<'pending' | 'error' | null> } */ + /** @type { Signal<'pending' | 'error' | 'loaded'> } */ const state = signal('pending'); const update = async () => { @@ -272,7 +272,7 @@ export function resource(fetch, initialValue = null) { try { state('pending'); value(await fetch()); - state(null); + state('loaded'); // @ts-ignore delete value.error;