sinho 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.js CHANGED
@@ -1002,14 +1002,14 @@ const If = (props) => {
1002
1002
  */
1003
1003
  const ElseIf = (props) => {
1004
1004
  const renderer = useRenderer();
1005
- const conditions = renderer._ifConditions;
1006
- const condition = useMemo(() => conditions.every((condition) => !condition()) &&
1007
- MaybeSignal.get(props.condition));
1008
- renderer._ifConditions = [...conditions, condition];
1009
- return runWithRenderer({ _ifConditions: [] }, () => createTemplate(() => {
1005
+ const prevConditions = renderer._ifConditions;
1006
+ const myCondition = MaybeSignal.upgrade(props.condition);
1007
+ const fullCondition = useMemo(() => prevConditions.every((condition) => !condition()) && myCondition());
1008
+ renderer._ifConditions = [...prevConditions, myCondition];
1009
+ return createTemplate(() => runWithRenderer({ _ifConditions: [] }, () => {
1010
1010
  const anchor = renderer._node(() => document.createComment(""));
1011
1011
  const nodes = [anchor, []];
1012
- const template = useMemo(() => condition() ? Fragment({ children: props.children }) : null);
1012
+ const template = useMemo(() => fullCondition() ? Fragment({ children: props.children }) : null);
1013
1013
  let subnodes = [];
1014
1014
  useEffect(() => {
1015
1015
  TemplateNodes.forEach(subnodes, (node) => node.parentNode?.removeChild(node));
@@ -1 +1 @@
1
- const t=t=>({t:t,o:[],i:[],l:{...t?.l},u(t){const n=o;o=this;try{return t()}finally{o=n}},h(){for(let t=this.i.length-1;t>=0;t--)this.i[t].h();this.i=[];for(let t=this.o.length-1;t>=0;t--){const n=this.o[t];n._?.(),n.u=()=>{},n.p.forEach((t=>t.o.delete(n))),n.p.clear()}this.o=[]}});let n,e,o=t(),s=!1;const r=()=>o,c=(t,o)=>{const r=()=>(!s&&n&&(n.p.add(r),r.o.add(n)),r.peek());r.o=new Set,r.peek=()=>t;const c=(n,s)=>{const l={...o,...s};if(l.equals??=(t,n)=>t===n,e){const o="function"==typeof n?n(r.peek()):n;!l?.force&&l.equals(o,r.peek())||(l?.force?t=o:e.m.push((()=>t=o)),l?.silent||r.o.forEach((t=>{t.v?e.S.add(t):e.o.add(t)})))}else i((()=>c(n,l)))};return[r,c]},i=t=>{if(e)return t();e={m:[],o:new Set,S:new Set};try{const n=t();return l(),n}finally{e=void 0}},l=()=>{for(;e&&e.m.length+e.o.size+e.S.size>0;){e.o.forEach((t=>t._?.())),e.m.forEach((t=>t())),e.m=[];const t=e.S.values().next().value??e.o.values().next().value;t&&(t.u(),e.S.delete(t),e.o.delete(t))}};let u=!1;const f=(t,e)=>{const r=!!e,c={M:o,v:u,p:new Set,u(){const o=n,c=s;n=this;try{this.p.forEach((t=>t.o.delete(this))),this.p.clear(),e&&(s=!1,e.forEach((t=>t()))),s=r,this._?.();const n=this.M.u((()=>i(t)));this._=n?()=>{this.M.u((()=>i(n))),this._=null}:null}finally{n=o,s=c}}};o.o.push(c),c.u(),c.p.size||c._||o.o.pop()},a=(t,n)=>{const[e,o]=c(void 0,n);let s=!0;u=!0;try{f((()=>{o(t,s?{force:!0}:{}),s=!1}))}finally{u=!1}return e},d=(n,s)=>{const r=e;e=void 0;const c=o,i=t(c);Object.assign(i.l,s?.details);try{c.i.push(i);return[i.u(n),()=>{const t=c.i.indexOf(i);t>=0&&c.i.splice(t,1),i.h()}]}finally{e=r}},h=(t,n)=>{const[e,o]=c(t,n);return e.set=o,e},_={upgrade:t=>()=>_.get(t),get:t=>"function"==typeof t?t():t,peek(t){const n=s;s=!0;try{return this.get(t)}finally{s=n}}},p=(t={})=>({k:[],C(t){return this.N?.next().value??t()},...t}),y=()=>{const t=r();return t.l.j??=p()},m=(t,n)=>{const e=y(),o=p({...e,...t}),[s,r]=d(n,{details:{j:o}});return f((()=>r)),s},w=t=>(t[0]??"").toLowerCase()+t.slice(1).replace(/[A-Z]/g,(t=>"-"+t.toLowerCase())),b=t=>t.startsWith("on:")?t.slice(3):w(t.slice(2)),v=Symbol(),g=(t,n)=>({[v]:Math.random().toString(36).slice(2),A:t,H:n}),x=t=>!!t?.[v],S=(t,n,e)=>{n.addEventListener(t[v],(t=>{const n=_.get(e);void 0!==n&&(t.stopPropagation(),t.detail(n))}))},M=t=>{const n=y();return a((()=>{let e=t.A;return n.L?.dispatchEvent(new CustomEvent(t[v],{detail:t=>e=t,bubbles:!0,composed:!0})),e}))};var k;!function(t){t.forEach=(n,e)=>n.forEach((n=>Array.isArray(n)?t.forEach(n,e):e(n))),t.last=(n,e=n.length-1)=>{if(n.length)for(let o=e;o>=0;o--){const e=n[o];if(!Array.isArray(e))return e;const s=t.last(e);if(s)return s}}}(k||(k={}));const C=t=>({build(){const n=t();return n.build?.()??n}}),E=(t,n)=>({T:"p",O:t,...n}),N=(t=CustomEvent)=>({T:"e",D:t}),j=Symbol();let A;const H=(t,n)=>{A?A.push([t,n]):f(t,n)},L=(t,n={},e={})=>{const o=[],s=new Map;for(const t in n){const e=n[t];if("p"==e.T&&e.attribute){"function"==typeof e.attribute&&(e.attribute={transform:e.attribute});const n=e.attribute={name:w(t),static:!1,transform:t=>t,...e.attribute};s.set(n.name,{name:t,meta:e}),n.static||o.push(n.name)}}e.shadow??={mode:"open"};class i extends HTMLElement{static[j]={I:t};static observedAttributes=o;props={};events={};[j]={};constructor(){super();for(const t in n){const e=n[t];if("p"==e.T){const n=x(e.O)?e.O:null,[o,s]=c(n?void 0:e.O);this.props[t]=o,n&&S(n,this,o),Object.defineProperty(this,t,{get:o.peek,set:t=>s((()=>t),{force:!0})})}else if("e"==e.T&&t.startsWith("on")){const n=b(t);this.events[t]=t=>this.dispatchEvent(new e.D(n,t))}}}connectedCallback(){const t=(n=this,e.shadow?n.shadowRoot??n.attachShadow(e.shadow):n);var n;this[j].$=d((()=>m({P:!1,L:this,N:t.childNodes.values()},(()=>{this[j].M=r();const n=A;A=[];try{k.forEach(this.render().build(),(n=>{t.append(n)})),A.forEach((([t,n])=>f(t,n)))}finally{A=n}}))))[1]}disconnectedCallback(){this[j].$?.()}attributeChangedCallback(t,n,e){const o=s.get(t);o&&(this[o.name]=null!=e?o.meta.attribute.transform.call(this,e):x(o.meta.O)?void 0:o.meta.O)}}return i},T=t=>!!t?.[j],O=(...t)=>{const[n,e]="string"==typeof t[0]?[t[0],t.slice(1)]:["",t];for(const t of e)customElements.define(n+t[j].I,t)},D=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,I=(t,n,e)=>{"-"==n[0]?t.style.setProperty(n,""+e):t.style[n]=null==e?"":"number"!=typeof e||D.test(n)?""+e:e+"px"},$=(t,n,e,o)=>{const s=null==e||!1===e&&!n.includes("-");if(n.startsWith("prop:"))t[n.slice(5)]=e;else if(n.startsWith("attr:"))n=n.slice(5),s?t.removeAttribute(n):t.setAttribute(n,e);else if(!["innerHTML","outerHTML"].includes(n)){if(!["tabIndex","role",...o?["width","height","href","list","form","download","rowSpan","colSpan"]:[]].includes(n)&&n in t)try{return void(t[n]=e)}catch(t){}"function"==typeof e||(s?t.removeAttribute(n):t.setAttribute(n,e))}},z=({text:t,marker:n})=>C((()=>{const e=y(),o=n&&e.C((()=>document.createComment(""))),s=e.C((()=>document.createTextNode("")));return f((()=>{const n=""+(_.get(t)??"");s.textContent!=n&&(s.textContent=n)})),o?[o,s]:[s]})),P=({children:t})=>C((()=>Array.isArray(t)?t.flatMap((t=>P({children:t}).build())):null==t?[]:["object"==typeof t?t.build():z({text:t}).build()])),V=(t,n,e,o)=>{const{ref:s,style:c,children:l,dangerouslySetInnerHTML:u,...a}=e;for(const n in c??{}){const e=c[n];f((()=>{I(t,n,_.get(e))}))}for(const n in a){const e=a[n];if(n.startsWith("on")){const o=r(),s=t=>{o.u((()=>i((()=>e(t)))))},c=b(n);f((()=>(t.addEventListener(c,s),()=>t.removeEventListener(c,s))))}else f((()=>{$(t,n,_.get(e),o)}))}return u&&f((()=>{const n=_.get(u).__html;t.innerHTML!=n&&(t.innerHTML=n)})),s&&f((()=>(s.set(t),()=>s.set(void 0)))),null!=e.children&&k.forEach(m({P:n,N:t.childNodes.values()},(()=>P({children:e.children}).build())),(n=>t.append(n))),t},Z=(t,n={},e)=>(null!=e&&(n.children=e),T(t)?((t,n)=>C((()=>{const e=y().C((()=>new t));return customElements.upgrade(e),V(e,!1,n),[e]})))(t,n):"function"==typeof t?C((()=>t(n))):((t,n={})=>C((()=>{const e=y(),o="svg"==t||!!e.P;return[V(e.C((()=>o?document.createElementNS("http://www.w3.org/2000/svg",t):document.createElement(t))),o,n,!0)]})))(t,n)),q=new Proxy(Z,{get:(t,n)=>(e,o)=>t(n,e,o)}),B=(t,n)=>{const[e,o]=c({V:[],Z:new Map},{force:!0});let s=new Map;return f((()=>{const e=[],r=s,c=((t,n)=>{const e=new Map;for(let o=0;o<t.length;o++){const s=n(t[o],o);if(e.has(s))throw Error(`Duplicate key '${s}'`);e.set(s,o)}return e})(t(),n),i=(t=NaN)=>e.map((t=>"r"==t.q?n=>n<t.B?n:n==t.B?NaN:n-1:"a"==t.q?n=>n<t.B?n:n+1:"m"==t.q?n=>t.F<=n&&n<t.G?n+1:n==t.G?t.F:n:t=>t)).reduce(((t,n)=>n(t)),t);for(const t of r.keys()){const n=i(r.get(t));c.has(t)||e.push({q:"r",J:t,B:n})}for(let o=0;o<t().length;o++){const s=n(t()[o],o),c=i(r.get(s));isNaN(c)?e.push({q:"a",J:s,B:o}):c!=o&&e.push({q:"m",J:s,G:c,F:o})}e.length>0&&o({V:e,Z:c}),s=c})),e},F=t=>C((()=>{const n=y(),e=_.upgrade(t.each??[]),o=n.C((()=>document.createComment(""))),s=t.key??((t,n)=>n),r=[o,[]],i=new Map,l=B(e,s),u=t=>k.last(r[1],t-1)??o;return f((()=>{for(const n of l().V)if("r"==n.q){const{K:t,$:e}=i.get(n.J)??{};e?.(),r[1].splice(n.B,1),k.forEach(t??[],(t=>t.parentNode?.removeChild(t))),i.delete(n.J)}else if("a"==n.q){let o;const[,s]=d((()=>{const[s,i]=c(n.B),[a,d]=c(e()[n.B]);f((()=>{0<=s()&&s()<e().length&&d((()=>e()[s()]))})),f((()=>{const t=l().Z.get(n.J);null!=t&&i(t)})),o=t.children?.(a,s,e).build()??[],r[1].splice(n.B,0,o);let h=u(n.B);k.forEach(o,(t=>{h.parentNode?.insertBefore(t,h.nextSibling),h=t}))}));i.set(n.J,{K:o,$:s})}else if("m"==n.q){const{K:t}=i.get(n.J)??{};r[1].splice(n.G,1),r[1].splice(n.F,0,t??[]);let e=u(n.F);k.forEach(t??[],(t=>{e.parentNode?.insertBefore(t,e.nextSibling),e=t}))}}),[l]),r})),G=t=>(y().k=[],J({condition:t.condition,children:t.children})),J=t=>{const n=y(),e=n.k,o=a((()=>e.every((t=>!t()))&&_.get(t.condition)));return n.k=[...e,o],m({k:[]},(()=>C((()=>{const e=n.C((()=>document.createComment(""))),s=[e,[]],r=a((()=>o()?P({children:t.children}):null));let c=[];return f((()=>{k.forEach(c,(t=>t.parentNode?.removeChild(t))),s[1]=[];const[,t]=d((()=>{c=r()?.build()??[],s[1]=c;let t=e;k.forEach(c,(n=>{t.parentNode?.insertBefore(n,t.nextSibling),t=n}))}));return t}),[r]),s}))))},K=({children:t})=>J({condition:!0,children:t}),Q=({mount:t,children:n})=>C((()=>m({N:void 0},(()=>{const e=P({children:n}).build();return f((()=>(k.forEach(e,(n=>t.appendChild(n))),()=>{k.forEach(e,(t=>t.parentNode?.removeChild(t)))})),[]),[]})))),R=Symbol(),U=new Map,W=t=>{const n=t.children;if("function"==typeof n){const e=Z("style",{},z({text:n,marker:!1}));return t.light?Q({mount:document.head,children:e}):e}if(n){const o=y(),s=t.light?document:o.L?.shadowRoot??document,r=((t,n,e)=>{if(!U.has(n)){const t=new CSSStyleSheet;t.replaceSync(n),U.set(n,{R:t,U:0})}const o=U.get(n);o.U++,t.has(n)||t.set(n,{R:o.R,U:0});const s=t.get(n);return s.U++,f((()=>()=>{--s.U||(t.delete(n),e()),--o.U||U.delete(n)})),s.R})((e=s,e[R]??=new Map),n,(()=>{s.adoptedStyleSheets=s.adoptedStyleSheets.filter((t=>t!=r))}));s.adoptedStyleSheets.push(r)}var e;return P({})},X=(t,...n)=>{const e=()=>t.reduce(((t,e,o)=>t+e+(_.get(n[o])??"")),"");return n.some((t=>"function"==typeof t))?e:e()},Y=(t,n,e)=>(n&&null!=e&&(n.key=e),Z(t,n));export{L as Component,K as Else,J as ElseIf,F as For,P as Fragment,G as If,_ as MaybeSignal,Q as Portal,W as Style,k as TemplateNodes,g as createContext,Z as createElement,X as css,O as defineComponents,N as event,l as flushBatch,q as h,T as isComponent,Y as jsx,Y as jsxDEV,Y as jsxs,E as prop,i as useBatch,M as useContext,H as useEffect,a as useMemo,h as useRef,c as useSignal,d as useSubscope};
1
+ const t=t=>({t:t,o:[],i:[],l:{...t?.l},u(t){const n=o;o=this;try{return t()}finally{o=n}},h(){for(let t=this.i.length-1;t>=0;t--)this.i[t].h();this.i=[];for(let t=this.o.length-1;t>=0;t--){const n=this.o[t];n._?.(),n.u=()=>{},n.p.forEach((t=>t.o.delete(n))),n.p.clear()}this.o=[]}});let n,e,o=t(),s=!1;const r=()=>o,c=(t,o)=>{const r=()=>(!s&&n&&(n.p.add(r),r.o.add(n)),r.peek());r.o=new Set,r.peek=()=>t;const c=(n,s)=>{const l={...o,...s};if(l.equals??=(t,n)=>t===n,e){const o="function"==typeof n?n(r.peek()):n;!l?.force&&l.equals(o,r.peek())||(l?.force?t=o:e.m.push((()=>t=o)),l?.silent||r.o.forEach((t=>{t.v?e.S.add(t):e.o.add(t)})))}else i((()=>c(n,l)))};return[r,c]},i=t=>{if(e)return t();e={m:[],o:new Set,S:new Set};try{const n=t();return l(),n}finally{e=void 0}},l=()=>{for(;e&&e.m.length+e.o.size+e.S.size>0;){e.o.forEach((t=>t._?.())),e.m.forEach((t=>t())),e.m=[];const t=e.S.values().next().value??e.o.values().next().value;t&&(t.u(),e.S.delete(t),e.o.delete(t))}};let u=!1;const f=(t,e)=>{const r=!!e,c={M:o,v:u,p:new Set,u(){const o=n,c=s;n=this;try{this.p.forEach((t=>t.o.delete(this))),this.p.clear(),e&&(s=!1,e.forEach((t=>t()))),s=r,this._?.();const n=this.M.u((()=>i(t)));this._=n?()=>{this.M.u((()=>i(n))),this._=null}:null}finally{n=o,s=c}}};o.o.push(c),c.u(),c.p.size||c._||o.o.pop()},a=(t,n)=>{const[e,o]=c(void 0,n);let s=!0;u=!0;try{f((()=>{o(t,s?{force:!0}:{}),s=!1}))}finally{u=!1}return e},d=(n,s)=>{const r=e;e=void 0;const c=o,i=t(c);Object.assign(i.l,s?.details);try{c.i.push(i);return[i.u(n),()=>{const t=c.i.indexOf(i);t>=0&&c.i.splice(t,1),i.h()}]}finally{e=r}},h=(t,n)=>{const[e,o]=c(t,n);return e.set=o,e},_={upgrade:t=>()=>_.get(t),get:t=>"function"==typeof t?t():t,peek(t){const n=s;s=!0;try{return this.get(t)}finally{s=n}}},p=(t={})=>({k:[],C(t){return this.N?.next().value??t()},...t}),y=()=>{const t=r();return t.l.j??=p()},m=(t,n)=>{const e=y(),o=p({...e,...t}),[s,r]=d(n,{details:{j:o}});return f((()=>r)),s},w=t=>(t[0]??"").toLowerCase()+t.slice(1).replace(/[A-Z]/g,(t=>"-"+t.toLowerCase())),b=t=>t.startsWith("on:")?t.slice(3):w(t.slice(2)),v=Symbol(),g=(t,n)=>({[v]:Math.random().toString(36).slice(2),A:t,H:n}),x=t=>!!t?.[v],S=(t,n,e)=>{n.addEventListener(t[v],(t=>{const n=_.get(e);void 0!==n&&(t.stopPropagation(),t.detail(n))}))},M=t=>{const n=y();return a((()=>{let e=t.A;return n.L?.dispatchEvent(new CustomEvent(t[v],{detail:t=>e=t,bubbles:!0,composed:!0})),e}))};var k;!function(t){t.forEach=(n,e)=>n.forEach((n=>Array.isArray(n)?t.forEach(n,e):e(n))),t.last=(n,e=n.length-1)=>{if(n.length)for(let o=e;o>=0;o--){const e=n[o];if(!Array.isArray(e))return e;const s=t.last(e);if(s)return s}}}(k||(k={}));const C=t=>({build(){const n=t();return n.build?.()??n}}),E=(t,n)=>({T:"p",O:t,...n}),N=(t=CustomEvent)=>({T:"e",D:t}),j=Symbol();let A;const H=(t,n)=>{A?A.push([t,n]):f(t,n)},L=(t,n={},e={})=>{const o=[],s=new Map;for(const t in n){const e=n[t];if("p"==e.T&&e.attribute){"function"==typeof e.attribute&&(e.attribute={transform:e.attribute});const n=e.attribute={name:w(t),static:!1,transform:t=>t,...e.attribute};s.set(n.name,{name:t,meta:e}),n.static||o.push(n.name)}}e.shadow??={mode:"open"};class i extends HTMLElement{static[j]={I:t};static observedAttributes=o;props={};events={};[j]={};constructor(){super();for(const t in n){const e=n[t];if("p"==e.T){const n=x(e.O)?e.O:null,[o,s]=c(n?void 0:e.O);this.props[t]=o,n&&S(n,this,o),Object.defineProperty(this,t,{get:o.peek,set:t=>s((()=>t),{force:!0})})}else if("e"==e.T&&t.startsWith("on")){const n=b(t);this.events[t]=t=>this.dispatchEvent(new e.D(n,t))}}}connectedCallback(){const t=(n=this,e.shadow?n.shadowRoot??n.attachShadow(e.shadow):n);var n;this[j].$=d((()=>m({P:!1,L:this,N:t.childNodes.values()},(()=>{this[j].M=r();const n=A;A=[];try{k.forEach(this.render().build(),(n=>{t.append(n)})),A.forEach((([t,n])=>f(t,n)))}finally{A=n}}))))[1]}disconnectedCallback(){this[j].$?.()}attributeChangedCallback(t,n,e){const o=s.get(t);o&&(this[o.name]=null!=e?o.meta.attribute.transform.call(this,e):x(o.meta.O)?void 0:o.meta.O)}}return i},T=t=>!!t?.[j],O=(...t)=>{const[n,e]="string"==typeof t[0]?[t[0],t.slice(1)]:["",t];for(const t of e)customElements.define(n+t[j].I,t)},D=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,I=(t,n,e)=>{"-"==n[0]?t.style.setProperty(n,""+e):t.style[n]=null==e?"":"number"!=typeof e||D.test(n)?""+e:e+"px"},$=(t,n,e,o)=>{const s=null==e||!1===e&&!n.includes("-");if(n.startsWith("prop:"))t[n.slice(5)]=e;else if(n.startsWith("attr:"))n=n.slice(5),s?t.removeAttribute(n):t.setAttribute(n,e);else if(!["innerHTML","outerHTML"].includes(n)){if(!["tabIndex","role",...o?["width","height","href","list","form","download","rowSpan","colSpan"]:[]].includes(n)&&n in t)try{return void(t[n]=e)}catch(t){}"function"==typeof e||(s?t.removeAttribute(n):t.setAttribute(n,e))}},z=({text:t,marker:n})=>C((()=>{const e=y(),o=n&&e.C((()=>document.createComment(""))),s=e.C((()=>document.createTextNode("")));return f((()=>{const n=""+(_.get(t)??"");s.textContent!=n&&(s.textContent=n)})),o?[o,s]:[s]})),P=({children:t})=>C((()=>Array.isArray(t)?t.flatMap((t=>P({children:t}).build())):null==t?[]:["object"==typeof t?t.build():z({text:t}).build()])),V=(t,n,e,o)=>{const{ref:s,style:c,children:l,dangerouslySetInnerHTML:u,...a}=e;for(const n in c??{}){const e=c[n];f((()=>{I(t,n,_.get(e))}))}for(const n in a){const e=a[n];if(n.startsWith("on")){const o=r(),s=t=>{o.u((()=>i((()=>e(t)))))},c=b(n);f((()=>(t.addEventListener(c,s),()=>t.removeEventListener(c,s))))}else f((()=>{$(t,n,_.get(e),o)}))}return u&&f((()=>{const n=_.get(u).__html;t.innerHTML!=n&&(t.innerHTML=n)})),s&&f((()=>(s.set(t),()=>s.set(void 0)))),null!=e.children&&k.forEach(m({P:n,N:t.childNodes.values()},(()=>P({children:e.children}).build())),(n=>t.append(n))),t},Z=(t,n={},e)=>(null!=e&&(n.children=e),T(t)?((t,n)=>C((()=>{const e=y().C((()=>new t));return customElements.upgrade(e),V(e,!1,n),[e]})))(t,n):"function"==typeof t?C((()=>t(n))):((t,n={})=>C((()=>{const e=y(),o="svg"==t||!!e.P;return[V(e.C((()=>o?document.createElementNS("http://www.w3.org/2000/svg",t):document.createElement(t))),o,n,!0)]})))(t,n)),q=new Proxy(Z,{get:(t,n)=>(e,o)=>t(n,e,o)}),B=(t,n)=>{const[e,o]=c({V:[],Z:new Map},{force:!0});let s=new Map;return f((()=>{const e=[],r=s,c=((t,n)=>{const e=new Map;for(let o=0;o<t.length;o++){const s=n(t[o],o);if(e.has(s))throw Error(`Duplicate key '${s}'`);e.set(s,o)}return e})(t(),n),i=(t=NaN)=>e.map((t=>"r"==t.q?n=>n<t.B?n:n==t.B?NaN:n-1:"a"==t.q?n=>n<t.B?n:n+1:"m"==t.q?n=>t.F<=n&&n<t.G?n+1:n==t.G?t.F:n:t=>t)).reduce(((t,n)=>n(t)),t);for(const t of r.keys()){const n=i(r.get(t));c.has(t)||e.push({q:"r",J:t,B:n})}for(let o=0;o<t().length;o++){const s=n(t()[o],o),c=i(r.get(s));isNaN(c)?e.push({q:"a",J:s,B:o}):c!=o&&e.push({q:"m",J:s,G:c,F:o})}e.length>0&&o({V:e,Z:c}),s=c})),e},F=t=>C((()=>{const n=y(),e=_.upgrade(t.each??[]),o=n.C((()=>document.createComment(""))),s=t.key??((t,n)=>n),r=[o,[]],i=new Map,l=B(e,s),u=t=>k.last(r[1],t-1)??o;return f((()=>{for(const n of l().V)if("r"==n.q){const{K:t,$:e}=i.get(n.J)??{};e?.(),r[1].splice(n.B,1),k.forEach(t??[],(t=>t.parentNode?.removeChild(t))),i.delete(n.J)}else if("a"==n.q){let o;const[,s]=d((()=>{const[s,i]=c(n.B),[a,d]=c(e()[n.B]);f((()=>{0<=s()&&s()<e().length&&d((()=>e()[s()]))})),f((()=>{const t=l().Z.get(n.J);null!=t&&i(t)})),o=t.children?.(a,s,e).build()??[],r[1].splice(n.B,0,o);let h=u(n.B);k.forEach(o,(t=>{h.parentNode?.insertBefore(t,h.nextSibling),h=t}))}));i.set(n.J,{K:o,$:s})}else if("m"==n.q){const{K:t}=i.get(n.J)??{};r[1].splice(n.G,1),r[1].splice(n.F,0,t??[]);let e=u(n.F);k.forEach(t??[],(t=>{e.parentNode?.insertBefore(t,e.nextSibling),e=t}))}}),[l]),r})),G=t=>(y().k=[],J({condition:t.condition,children:t.children})),J=t=>{const n=y(),e=n.k,o=_.upgrade(t.condition),s=a((()=>e.every((t=>!t()))&&o()));return n.k=[...e,o],C((()=>m({k:[]},(()=>{const e=n.C((()=>document.createComment(""))),o=[e,[]],r=a((()=>s()?P({children:t.children}):null));let c=[];return f((()=>{k.forEach(c,(t=>t.parentNode?.removeChild(t))),o[1]=[];const[,t]=d((()=>{c=r()?.build()??[],o[1]=c;let t=e;k.forEach(c,(n=>{t.parentNode?.insertBefore(n,t.nextSibling),t=n}))}));return t}),[r]),o}))))},K=({children:t})=>J({condition:!0,children:t}),Q=({mount:t,children:n})=>C((()=>m({N:void 0},(()=>{const e=P({children:n}).build();return f((()=>(k.forEach(e,(n=>t.appendChild(n))),()=>{k.forEach(e,(t=>t.parentNode?.removeChild(t)))})),[]),[]})))),R=Symbol(),U=new Map,W=t=>{const n=t.children;if("function"==typeof n){const e=Z("style",{},z({text:n,marker:!1}));return t.light?Q({mount:document.head,children:e}):e}if(n){const o=y(),s=t.light?document:o.L?.shadowRoot??document,r=((t,n,e)=>{if(!U.has(n)){const t=new CSSStyleSheet;t.replaceSync(n),U.set(n,{R:t,U:0})}const o=U.get(n);o.U++,t.has(n)||t.set(n,{R:o.R,U:0});const s=t.get(n);return s.U++,f((()=>()=>{--s.U||(t.delete(n),e()),--o.U||U.delete(n)})),s.R})((e=s,e[R]??=new Map),n,(()=>{s.adoptedStyleSheets=s.adoptedStyleSheets.filter((t=>t!=r))}));s.adoptedStyleSheets.push(r)}var e;return P({})},X=(t,...n)=>{const e=()=>t.reduce(((t,e,o)=>t+e+(_.get(n[o])??"")),"");return n.some((t=>"function"==typeof t))?e:e()},Y=(t,n,e)=>(n&&null!=e&&(n.key=e),Z(t,n));export{L as Component,K as Else,J as ElseIf,F as For,P as Fragment,G as If,_ as MaybeSignal,Q as Portal,W as Style,k as TemplateNodes,g as createContext,Z as createElement,X as css,O as defineComponents,N as event,l as flushBatch,q as h,T as isComponent,Y as jsx,Y as jsxDEV,Y as jsxs,E as prop,i as useBatch,M as useContext,H as useEffect,a as useMemo,h as useRef,c as useSignal,d as useSubscope};
@@ -1,5 +1,5 @@
1
1
  import { TemplateNodes, createTemplate } from "../template.js";
2
- import { MaybeSignal, useEffect, useMemo, useSubscope, } from "../scope.js";
2
+ import { MaybeSignal, useEffect, useMemo, useSubscope } from "../scope.js";
3
3
  import { runWithRenderer, useRenderer } from "../renderer.js";
4
4
  import { Fragment } from "./Fragment.js";
5
5
  /**
@@ -16,14 +16,14 @@ export const If = (props) => {
16
16
  */
17
17
  export const ElseIf = (props) => {
18
18
  const renderer = useRenderer();
19
- const conditions = renderer._ifConditions;
20
- const condition = useMemo(() => conditions.every((condition) => !condition()) &&
21
- MaybeSignal.get(props.condition));
22
- renderer._ifConditions = [...conditions, condition];
23
- return runWithRenderer({ _ifConditions: [] }, () => createTemplate(() => {
19
+ const prevConditions = renderer._ifConditions;
20
+ const myCondition = MaybeSignal.upgrade(props.condition);
21
+ const fullCondition = useMemo(() => prevConditions.every((condition) => !condition()) && myCondition());
22
+ renderer._ifConditions = [...prevConditions, myCondition];
23
+ return createTemplate(() => runWithRenderer({ _ifConditions: [] }, () => {
24
24
  const anchor = renderer._node(() => document.createComment(""));
25
25
  const nodes = [anchor, []];
26
- const template = useMemo(() => condition() ? Fragment({ children: props.children }) : null);
26
+ const template = useMemo(() => fullCondition() ? Fragment({ children: props.children }) : null);
27
27
  let subnodes = [];
28
28
  useEffect(() => {
29
29
  TemplateNodes.forEach(subnodes, (node) => node.parentNode?.removeChild(node));
@@ -1 +1 @@
1
- {"version":3,"file":"If.js","sourceRoot":"","sources":["../../src/intrinsic/If.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAiB,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EACL,WAAW,EAEX,SAAS,EACT,OAAO,EAEP,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAY,QAAQ,EAAE,MAA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
  _svg?: boolean;
6
6
  _nodes?: IterableIterator<Node>;
7
- _ifConditions: SignalLike<boolean | undefined>[];
7
+ _ifConditions: Readonly<SignalLike<boolean | undefined>[]>;
8
8
  _node<N extends Node>(fallback: () => N): N;
9
9
  }
10
10
  type RendererOverrides = Partial<Omit<Renderer, "_node">>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinho",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A lightweight signal-based library for building web components with a React-like API.",
5
5
  "keywords": [
6
6
  "ui",
@@ -1,13 +1,6 @@
1
1
  import type { FunctionalComponent } from "../component.js";
2
- import { TemplateNodes, createTemplate, type Template } from "../template.js";
3
- import {
4
- MaybeSignal,
5
- SignalLike,
6
- useEffect,
7
- useMemo,
8
- useSignal,
9
- useSubscope,
10
- } from "../scope.js";
2
+ import { TemplateNodes, createTemplate } from "../template.js";
3
+ import { MaybeSignal, useEffect, useMemo, useSubscope } from "../scope.js";
11
4
  import { runWithRenderer, useRenderer } from "../renderer.js";
12
5
  import { Children, Fragment } from "./Fragment.js";
13
6
 
@@ -33,21 +26,20 @@ export const ElseIf: FunctionalComponent<{
33
26
  children?: Children;
34
27
  }> = (props) => {
35
28
  const renderer = useRenderer();
36
- const conditions = renderer._ifConditions;
37
- const condition = useMemo(
38
- () =>
39
- conditions.every((condition) => !condition()) &&
40
- MaybeSignal.get<boolean | undefined>(props.condition),
29
+ const prevConditions = renderer._ifConditions;
30
+ const myCondition = MaybeSignal.upgrade<boolean | undefined>(props.condition);
31
+ const fullCondition = useMemo(
32
+ () => prevConditions.every((condition) => !condition()) && myCondition(),
41
33
  );
42
34
 
43
- renderer._ifConditions = [...conditions, condition];
35
+ renderer._ifConditions = [...prevConditions, myCondition];
44
36
 
45
- return runWithRenderer({ _ifConditions: [] }, () =>
46
- createTemplate(() => {
37
+ return createTemplate(() =>
38
+ runWithRenderer({ _ifConditions: [] }, () => {
47
39
  const anchor = renderer._node(() => document.createComment(""));
48
40
  const nodes: [Comment, TemplateNodes] = [anchor, []];
49
41
  const template = useMemo(() =>
50
- condition() ? Fragment({ children: props.children }) : null,
42
+ fullCondition() ? Fragment({ children: props.children }) : null,
51
43
  );
52
44
 
53
45
  let subnodes: TemplateNodes = [];
package/src/renderer.ts CHANGED
@@ -5,7 +5,7 @@ interface Renderer {
5
5
  _component?: Component;
6
6
  _svg?: boolean;
7
7
  _nodes?: IterableIterator<Node>;
8
- _ifConditions: SignalLike<boolean | undefined>[];
8
+ _ifConditions: Readonly<SignalLike<boolean | undefined>[]>;
9
9
 
10
10
  _node<N extends Node>(fallback: () => N): N;
11
11
  }