@lipsjs/lips 0.3.1 → 0.5.0
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/README.md +122 -9
- package/dist/lips.js +917 -669
- package/dist/lips.js.map +15 -12
- package/dist/lips.min.js +12 -12
- package/dist/lips.min.js.map +15 -12
- package/dist/lynx-background.min.js +3 -0
- package/dist/lynx-background.min.js.map +13 -0
- package/dist/lynx-main.min.js +3 -0
- package/dist/lynx-main.min.js.map +11 -0
- package/dist/lynx-plugin.mjs +1487 -0
- package/dist/lynx.min.js +8 -8
- package/dist/lynx.min.js.map +12 -10
- package/dist/mf2.min.js.map +1 -1
- package/dist/parts.min.js +100 -0
- package/dist/parts.min.js.map +19 -0
- package/dist/precompile.min.js +15 -15
- package/dist/precompile.min.js.map +8 -7
- package/dist/runtime.min.js +4 -4
- package/dist/runtime.min.js.map +11 -9
- package/dist/stylis.min.js.map +1 -1
- package/dist/types/component.d.ts +32 -0
- package/dist/types/ir/compiler.d.ts +2 -4
- package/dist/types/ir/facade.d.ts +63 -12
- package/dist/types/ir/host.d.ts +9 -1
- package/dist/types/ir/initial.d.ts +16 -0
- package/dist/types/ir/router.d.ts +2 -0
- package/dist/types/ir/tags.d.ts +16 -0
- package/dist/types/lips.d.ts +7 -7
- package/dist/types/lynx/a11y.d.ts +1 -0
- package/dist/types/lynx/background.d.ts +52 -3
- package/dist/types/lynx/components.d.ts +28 -0
- package/dist/types/lynx/main.d.ts +9 -5
- package/dist/types/lynx/plugin.d.ts +8 -0
- package/dist/types/lynx/protocol.d.ts +55 -4
- package/dist/types/lynx/style.d.ts +7 -0
- package/dist/types/lynx/template.d.ts +6 -0
- package/dist/types/lynx.d.ts +1 -0
- package/dist/types/parts/combobox.d.ts +40 -0
- package/dist/types/parts/date.d.ts +75 -0
- package/dist/types/parts/dialog.d.ts +42 -0
- package/dist/types/parts/icon.d.ts +31 -0
- package/dist/types/parts/layer.d.ts +28 -0
- package/dist/types/parts/list.d.ts +45 -0
- package/dist/types/parts/menu.d.ts +44 -0
- package/dist/types/parts/popover.d.ts +81 -0
- package/dist/types/parts/reveal.d.ts +24 -0
- package/dist/types/parts/toast.d.ts +36 -0
- package/dist/types/parts.d.ts +24 -0
- package/dist/types/precompile.d.ts +8 -11
- package/dist/types/runtime.d.ts +1 -0
- package/dist/types/types.d.ts +188 -57
- package/dist/untrusted.min.js +4 -4
- package/dist/untrusted.min.js.map +7 -7
- package/package.json +24 -3
- package/dist/types/i18n/formatters.d.ts +0 -3
package/dist/runtime.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
`,t:"\t",r:"\r",b:"\b",f:"\f",v:"\v","0":"\x00"};if(u==="u"){let d=t.slice(r+2,r+6);l+=String.fromCharCode(parseInt(d,16)||0),r+=6}else l+=h[u]??u,r+=2;continue}if(f===p){c=!0,r++;break}l+=f,r++}if(!c)e.push({code:"LIPS-E001",message:"Unterminated string literal",loc:{offset:o,length:r-o}});n.push({t:"str",value:l,start:o,end:r});continue}if(s(p)){let o=r;while(r<t.length&&a(t[r]))r++;n.push({t:"id",value:t.slice(o,r),start:o,end:r});continue}let i=Jt.find((o)=>t.startsWith(o,r));if(i==="?."&&/[0-9]/.test(t[r+2]??""))i="?";if(i){n.push({t:"punct",value:i,start:r,end:r+i.length}),r+=i.length;continue}e.push({code:"LIPS-E002",message:`Unexpected character '${p}'`,loc:{offset:r,length:1}}),r++}return n.push({t:"eof",value:"",start:t.length,end:t.length}),n}class vt{tokens;diagnostics;pos=0;constructor(t,e){this.tokens=t;this.diagnostics=e}peek(t=0){return this.tokens[Math.min(this.pos+t,this.tokens.length-1)]}next(){return this.tokens[this.pos++]??this.tokens[this.tokens.length-1]}at(t){let e=this.peek();return e.t==="punct"&&e.value===t}eat(t){if(this.at(t))return this.pos++,!0;return!1}error(t,e,n=this.peek()){return this.diagnostics.push({code:t,message:e,loc:{offset:n.start,length:Math.max(1,n.end-n.start)}}),{t:"error"}}expect(t,e){if(!this.eat(t))this.error(e,`Expected '${t}'`)}parse(){let t=this.assign();if(this.peek().t!=="eof")this.error("LIPS-E003",`Unexpected token '${this.peek().value}' after expression`);return t}isArrowAhead(){let t=this.peek();if(t.t==="id"){let e=this.peek(1);return e.t==="punct"&&e.value==="=>"}if(t.t==="punct"&&t.value==="("){let e=0,n=0;while(!0){let r=this.peek(n);if(r.t==="eof")return!1;if(r.t==="punct"&&r.value==="(")e++;if(r.t==="punct"&&r.value===")"){if(e--,e===0){let s=this.peek(n+1);return s.t==="punct"&&s.value==="=>"}}n++}}return!1}assign(){if(this.isArrowAhead()){let n=[];if(this.peek().t==="id")n.push(this.next().value);else{this.expect("(","LIPS-E004");while(!this.at(")")&&this.peek().t!=="eof"){let r=this.next();if(r.t!=="id")return this.error("LIPS-E005","Invalid arrow parameter",r);if(n.push(r.value),!this.eat(","))break}this.expect(")","LIPS-E004")}return this.expect("=>","LIPS-E004"),{t:"arrow",params:n,body:this.assign()}}let t=this.conditional(),e=this.peek();if(e.t==="punct"&&["=","+=","-=","*=","/=","%="].includes(e.value)){if(t.t!=="id"&&t.t!=="member")return this.error("LIPS-E006","Invalid assignment target",e);return this.next(),{t:"assign",op:e.value,target:t,value:this.assign()}}return t}conditional(){let t=this.nullish();if(this.eat("?")){let e=this.assign();return this.expect(":","LIPS-E007"),{t:"cond",test:t,cons:e,alt:this.assign()}}return t}nullish(){let t=this.or();while(this.at("??"))this.next(),t={t:"logic",op:"??",l:t,r:this.or()};return t}or(){let t=this.and();while(this.at("||"))this.next(),t={t:"logic",op:"||",l:t,r:this.and()};return t}and(){let t=this.equality();while(this.at("&&"))this.next(),t={t:"logic",op:"&&",l:t,r:this.equality()};return t}equality(){let t=this.relational();while(["===","!==","==","!="].some((e)=>this.at(e)))t={t:"bin",op:this.next().value,l:t,r:this.relational()};return t}relational(){let t=this.additive();while(["<=",">=","<",">"].some((e)=>this.at(e)))t={t:"bin",op:this.next().value,l:t,r:this.additive()};return t}additive(){let t=this.multiplicative();while(this.at("+")||this.at("-"))t={t:"bin",op:this.next().value,l:t,r:this.multiplicative()};return t}multiplicative(){let t=this.unary();while(this.at("*")||this.at("/")||this.at("%"))t={t:"bin",op:this.next().value,l:t,r:this.unary()};return t}unary(){if(this.at("!")||this.at("-")||this.at("+"))return{t:"unary",op:this.next().value,arg:this.unary()};if(this.at("++")||this.at("--")){let t=this.next().value,e=this.unary();if(e.t!=="id"&&e.t!=="member")return this.error("LIPS-E006","Invalid update target");return{t:"update",op:t,arg:e,prefix:!0}}return this.postfix()}postfix(){let t=this.callMember();if(this.at("++")||this.at("--")){let e=this.next().value;if(t.t!=="id"&&t.t!=="member")return this.error("LIPS-E006","Invalid update target");t={t:"update",op:e,arg:t,prefix:!1}}return t}callMember(){let t=this.primary();while(!0)if(this.eat(".")){let e=this.next();if(e.t!=="id")return this.error("LIPS-E008","Expected property name",e);t={t:"member",obj:t,prop:e.value,computed:!1,optional:!1,at:e.start}}else if(this.eat("?."))if(this.at("("))t={t:"call",callee:t,args:this.argList(),optional:!0};else if(this.eat("[")){let e=this.peek().start,n=this.assign();this.expect("]","LIPS-E009"),t={t:"member",obj:t,prop:n,computed:!0,optional:!0,at:e}}else{let e=this.next();if(e.t!=="id")return this.error("LIPS-E008","Expected property name",e);t={t:"member",obj:t,prop:e.value,computed:!1,optional:!0,at:e.start}}else if(this.eat("[")){let e=this.peek().start,n=this.assign();this.expect("]","LIPS-E009"),t={t:"member",obj:t,prop:n,computed:!0,optional:!1,at:e}}else if(this.at("("))t={t:"call",callee:t,args:this.argList(),optional:!1};else break;return t}argList(){this.expect("(","LIPS-E010");let t=[];while(!this.at(")")&&this.peek().t!=="eof")if(t.push(this.assign()),!this.eat(","))break;return this.expect(")","LIPS-E010"),t}primary(){let t=this.peek();if(t.t==="num")return this.next(),{t:"lit",v:parseFloat(t.value)};if(t.t==="str")return this.next(),{t:"lit",v:t.value};if(t.t==="id")switch(this.next(),t.value){case"true":return{t:"lit",v:!0};case"false":return{t:"lit",v:!1};case"null":return{t:"lit",v:null};case"undefined":return{t:"lit",v:void 0};case"NaN":return{t:"lit",v:NaN};case"Infinity":return{t:"lit",v:1/0};default:return{t:"id",name:t.value,at:t.start}}if(this.eat("(")){let e=this.assign();return this.expect(")","LIPS-E010"),e}if(this.eat("[")){let e=[];while(!this.at("]")&&this.peek().t!=="eof"){let n=this.eat("...");if(e.push({spread:n||void 0,value:this.assign()}),!this.eat(","))break}return this.expect("]","LIPS-E009"),{t:"arr",items:e}}if(this.eat("{")){let e=[];while(!this.at("}")&&this.peek().t!=="eof"){if(this.eat("..."))e.push({spread:!0,value:this.assign()});else{let n=this.next();if(n.t!=="id"&&n.t!=="str"&&n.t!=="num")return this.error("LIPS-E011","Invalid object key",n);if(this.eat(":"))e.push({key:String(n.value),value:this.assign(),at:n.start});else if(n.t==="id")e.push({key:n.value,value:{t:"id",name:n.value,at:n.start},at:n.start});else return this.error("LIPS-E011","Invalid shorthand property",n)}if(!this.eat(","))break}return this.expect("}","LIPS-E011"),{t:"obj",props:e}}return this.next(),this.error("LIPS-E012",t.t==="eof"?"Unexpected end of expression":`Unexpected token '${t.value}'`,t)}}function it(t){let e=[],n=Wt(t,e);return{ast:new vt(n,e).parse(),diagnostics:e}}function ot(t){let e=[],n=0,r=0;for(let s=0;s<t.length;s++){let a=t[s];if(a==="'"||a==='"'||a==="`"){s++;while(s<t.length&&t[s]!==a){if(t[s]==="\\")s++;s++}continue}if(a==="("||a==="["||a==="{")n++;else if(a===")"||a==="]"||a==="}")n--;else if(a===","&&n===0)e.push(t.slice(r,s)),r=s+1}return e.push(t.slice(r)),e.map((s)=>s.trim()).filter(Boolean)}var Et={__proto__:null,static:"__static",arguments:"__args__"};function b(t){switch(t.t){case"lit":if(typeof t.v==="string")return JSON.stringify(t.v);if(t.v===void 0)return"undefined";if(Number.isNaN(t.v))return"NaN";return String(t.v);case"id":return Et[t.name]??t.name;case"member":{let e=b(t.obj);if(t.computed)return`(${e})${t.optional?"?.":""}[${b(t.prop)}]`;return`(${e})${t.optional?"?.":"."}${t.prop}`}case"call":return`(${b(t.callee)})${t.optional?"?.":""}(${t.args.map(b).join(",")})`;case"unary":return`(${t.op}(${b(t.arg)}))`;case"update":return t.prefix?`(${t.op}${st(t.arg)})`:`(${st(t.arg)}${t.op})`;case"bin":return`((${b(t.l)})${t.op}(${b(t.r)}))`;case"logic":return`((${b(t.l)})${t.op}(${b(t.r)}))`;case"cond":return`((${b(t.test)})?(${b(t.cons)}):(${b(t.alt)}))`;case"assign":return`(${st(t.target)}${t.op}(${b(t.value)}))`;case"arrow":return`((${t.params.join(",")})=>(${b(t.body)}))`;case"arr":return`[${t.items.map((e)=>(e.spread?"...":"")+b(e.value)).join(",")}]`;case"obj":return`({${t.props.map((e)=>e.spread?`...${b(e.value)}`:`${JSON.stringify(e.key)}:${b(e.value)}`).join(",")}})`;case"error":return"undefined"}}function st(t){if(t.t==="id")return Et[t.name]??t.name;if(t.t==="member"){let e=b(t.obj);return t.computed?`${e}[${b(t.prop)}]`:`${e}.${t.prop}`}return b(t)}var mt=new Map,Vt=["state","input","context","__static","self"];function bt(t,e=[]){let n=`${e.join(",")}\x00${t}`,r=mt.get(n);if(r)return r;let{ast:s,diagnostics:a}=it(t);if(a.length)console.warn(`[lips-ir] expression diagnostics for "${t}":`,a);let p=`return (${b(s)});`,i=[...Vt,"__args__",...e],o=Function(...i,p),l={source:t,run(c){let f=c.scope||{};return o(c.state,c.input,c.context,c.static,c.self,c.arguments,...e.map((u)=>f[u]))}};return mt.set(n,l),l}var xt={__proto__:null,Math,JSON,Object,Array,String,Number,Boolean,Date,parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,console};function Rt(t,e){let n=e.scope||Object.create(null),r=(i,o)=>{for(let l of o)if(i in l)return l[i];if(i in n)return n[i];switch(i){case"state":return e.state;case"input":return e.input;case"context":return e.context;case"static":return e.static;case"self":return e.self;case"arguments":return e.arguments}if(i in xt)return xt[i];return},s=(i,o,l)=>{for(let c of l)if(i in c)return c[i]=o,o;return n[i]=o,o},a=(i,o)=>{switch(i.t){case"lit":return i.v;case"id":return r(i.name,o);case"member":{let l=a(i.obj,o);if(i.optional&&l==null)return;let c=i.computed?a(i.prop,o):i.prop;return l?.[c]}case"call":{if(i.callee.t==="member"){let c=a(i.callee.obj,o);if((i.callee.optional||i.optional)&&c==null)return;let f=i.callee.computed?a(i.callee.prop,o):i.callee.prop,u=c?.[f];if(i.optional&&u==null)return;return u.apply(c,i.args.map((h)=>a(h,o)))}let l=a(i.callee,o);if(i.optional&&l==null)return;return l(...i.args.map((c)=>a(c,o)))}case"unary":{let l=a(i.arg,o);switch(i.op){case"!":return!l;case"-":return-l;case"+":return+l}}case"update":{let l=a(i.arg,o),c=i.op==="++"?l+1:l-1;return p(i.arg,c,o),i.prefix?c:l}case"bin":{let l=a(i.l,o),c=a(i.r,o);switch(i.op){case"+":return l+c;case"-":return l-c;case"*":return l*c;case"/":return l/c;case"%":return l%c;case"<":return l<c;case">":return l>c;case"<=":return l<=c;case">=":return l>=c;case"==":return l==c;case"!=":return l!=c;case"===":return l===c;case"!==":return l!==c}return}case"logic":{let l=a(i.l,o);switch(i.op){case"&&":return l?a(i.r,o):l;case"||":return l?l:a(i.r,o);case"??":return l!=null?l:a(i.r,o)}}case"cond":return a(i.test,o)?a(i.cons,o):a(i.alt,o);case"assign":{let l=a(i.value,o);if(i.op!=="="){let c=a(i.target,o);switch(i.op){case"+=":l=c+l;break;case"-=":l=c-l;break;case"*=":l=c*l;break;case"/=":l=c/l;break;case"%=":l=c%l;break}}return p(i.target,l,o)}case"arrow":return(...l)=>{let c=Object.create(null);return i.params.forEach((f,u)=>c[f]=l[u]),a(i.body,[c,...o])};case"arr":{let l=[];for(let c of i.items){let f=a(c.value,o);c.spread?l.push(...f):l.push(f)}return l}case"obj":{let l={};for(let c of i.props)if(c.spread)Object.assign(l,a(c.value,o));else l[c.key]=a(c.value,o);return l}case"error":return}},p=(i,o,l)=>{if(i.t==="id")return s(i.name,o,l);if(i.t==="member"){let c=a(i.obj,l),f=i.computed?a(i.prop,l):i.prop;if(c!=null)c[f]=o;return o}return o};return a(t,[])}var L=null,D=0,W=new Set;function Gt(){while(W.size){let t=[...W];W.clear(),D++;try{for(let e of t)!e.disposed&&e.run()}finally{D--}}}function qt(t){D++;try{return t()}finally{D--,!D&&Gt()}}function C(t){let e=new Set,n=()=>{if(D){for(let p of e)W.add(p);return}for(let p of[...e])!p.disposed&&p.run()};return[()=>{if(L&&!L.disposed)e.add(L),L.deps.add(e);return t},(p)=>{if(Object.is(p,t))return;t=p,n()},()=>n()]}function R(t){let e={deps:new Set,disposed:!1,run(){if(e.disposed)return;for(let r of e.deps)r.delete(e);e.deps.clear();let n=L;L=e;try{t()}finally{L=n}}};return e.run(),{dispose(){e.disposed=!0;for(let n of e.deps)n.delete(e);e.deps.clear()}}}function w(t){let e=L;L=null;try{return t()}finally{L=e}}var St=Symbol("lips.reactive"),V=Symbol("lips.collection"),It=new WeakMap,ct=(t)=>t!==null&&typeof t==="object"&&(Array.isArray(t)||Object.getPrototypeOf(t)===Object.prototype),G=(t)=>t instanceof Map||t instanceof Set||!!(t&&typeof t==="object"&&t[V]),zt=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),Yt=new Set(["set","delete","clear","add"]),at=Symbol("lips.keys"),kt=new WeakMap;function Ct(t,e){let n=t[V];if(n)return n.notify.add(e),t;let r=It.get(t);if(r)return r[V].notify.add(e),r;let s={raw:t,notify:new Set([e])},a=()=>s.notify.forEach((i)=>i()),p=new Proxy(t,{get(i,o){if(o===V)return s;let l=i[o];if(typeof l!=="function")return l;if(typeof o==="string"&&Yt.has(o))return(...u)=>{let h=l.apply(i,u);return a(),h};let c=(u)=>ct(u)?pt(u,a):G(u)?Ct(u,a):u,f=i instanceof Map;if(o==="get")return(u)=>c(i.get(u));if(o==="forEach")return(u,h)=>i.forEach((d,g)=>u.call(h,c(d),g,p));if(o==="values"||!f&&(o==="keys"||o===Symbol.iterator))return function*(){for(let u of i.values())yield c(u)};if(o==="entries"||f&&o===Symbol.iterator)return f?function*(){for(let[u,h]of i.entries())yield[u,c(h)]}:function*(){for(let u of i.values())yield[c(u),c(u)]};return l.bind(i)}});return It.set(t,p),p}function Xt(t){let e=kt.get(t);if(e)return e;let n=new Map,r=(c)=>{let f=n.get(c);if(!f)f=C(0),n.set(c,f);f[0]()},s=(c)=>n.get(c)?.[2](),a=new Map,p=(c)=>{let f=a.get(c);if(!f)f=()=>s(c),a.set(c,f);return f},i=()=>qt(()=>{for(let c of n.values())c[2]()}),o=!1,l=new Proxy(t,{get(c,f){let u=c[f];if(typeof f==="symbol")return u;if(Array.isArray(c)&&zt.has(f)&&typeof u==="function")return(...h)=>{o=!0;try{return u.apply(c,h)}finally{o=!1,i()}};if(typeof u==="function")return u;return r(f),ct(u)||G(u)?pt(u,p(f)):u},set(c,f,u){let h=f in c,d=c[f];if(c[f]=u,o)return!0;if(!Object.is(d,u))s(f);if(!h)s(at),Array.isArray(c)&&s("length");return!0},deleteProperty(c,f){let u=f in c;if(delete c[f],!o&&u)s(f),s(at);return!0},has(c,f){return typeof f!=="symbol"&&r(f),f in c},ownKeys(c){return r(at),Reflect.ownKeys(c)}});return kt.set(t,l),l}function pt(t,e){if(G(t))return Ct(t,e);if(!ct(t))return t;return Xt(t)}function O(t,e=!1){if(t[St])return t;let n=new Map,r=(s,a)=>{let p=n.get(s);if(!p)p=C(a),n.set(s,p);return p};return new Proxy(t,{get(s,a){if(a===St)return!0;if(typeof a==="string"){let p=r(a,s[a]);return e?pt(p[0](),p[2]):p[0]()}return s[a]},set(s,a,p){let i=s[a];if(s[a]=p,typeof a!=="string")return!0;let o=r(a,p);return Object.is(i,p)&&G(p)?o[2]():o[1](p),!0},has(s,a){return a in s},deleteProperty(s,a){return delete s[a],typeof a==="string"&&n.get(a)?.[1](void 0),!0}})}var Tt=new WeakMap,lt={clone(t){let e=Tt.get(t);if(!e)e=document.createElement("template"),e.innerHTML=t.html,Tt.set(t,e);return e.content.cloneNode(!0)},fragment:()=>document.createDocumentFragment(),element:(t)=>document.createElement(t),text:(t)=>document.createTextNode(t),marker:(t)=>document.createComment(t),child:(t,e)=>t.childNodes[e],next:(t)=>t.nextSibling,range(t,e){let n=[];for(let r=t;r;r=r.nextSibling)if(n.push(r),r===e)break;return n},insert:(t,e,n)=>{t.insertBefore(e,n)},insertAfter(t,e){let n=t.parentNode;if(!n)return;let r=t;for(let s of e)n.insertBefore(s,r.nextSibling),r=s},remove:(t)=>t.remove(),isElement:(t)=>t.nodeType===1,connected:(t)=>t.isConnected,precedes:(t,e)=>!!(t.compareDocumentPosition(e)&4),attr:(t,e,n)=>n===null?t.removeAttribute(e):t.setAttribute(e,n),setText:(t,e)=>{t.data=e},content:(t,e)=>{t.textContent=e},html:(t,e)=>{t.innerHTML=e},styleVar:(t,e,n)=>n===null?t.style.removeProperty(e):t.style.setProperty(e,n),scope:(t,e)=>{t.hasAttribute("rel")||t.setAttribute("rel",e)},listen(t,e,n){return t.addEventListener(e,n),()=>t.removeEventListener(e,n)},keepFocus(){let t=document.activeElement;return()=>{t&&t.isConnected&&t!==document.activeElement&&t.focus()}}};function K(t){let e=t.split("-"),n=[];while(e.length)n.push(e.join("-")),e.pop(),e[e.length-1]?.length===1&&e.pop();return n}function q(t,e){let n=new Map(Object.entries(t.names).map(([r,s])=>[r.toLowerCase(),s]));for(let r of K(e.toLowerCase()))if(n.has(r))return n.get(r);return t.names[t.default]??""}var _=(t,e)=>t==null?t:("e"in t)?{$:e[t.e]}:t,ut=(t,e)=>({...t,e:e[t.e]});function z(t,e){switch(t.t){case"macro":return{t:t.t,name:t.name,args:t.args,sets:t.sets.map((n)=>("spread"in n)?{spread:e[n.spread]}:{name:n.name,ci:_(n.ci,e)}),block:A(t.block,e)};case"if":return{t:t.t,branches:t.branches.map((n)=>({when:n.when==null?null:e[n.when],block:A(n.block,e)}))};case"for":return{t:t.t,args:t.args,of:t.of===void 0?void 0:e[t.of],from:_(t.from,e),to:_(t.to,e),by:_(t.by,e),block:A(t.block,e)};case"switch":return{t:t.t,on:e[t.on],cases:t.cases.map((n)=>({is:n.is===null?null:_(n.is,e),block:A(n.block,e)}))};case"async":return{t:t.t,awaitE:e[t.awaitE],then:t.then&&{args:t.then.args,block:A(t.then.block,e)},catch:t.catch&&{args:t.catch.args,block:A(t.catch.block,e)},loading:t.loading&&A(t.loading,e)};case"let":return{t:t.t,const:t.const,vars:Object.fromEntries(Object.entries(t.vars).map(([n,r])=>[n,_(r,e)]))};case"log":return{t:t.t,e:e[t.e]};case"provide":return{t:t.t,vars:Object.fromEntries(Object.entries(t.vars).map(([n,r])=>[n,_(r,e)])),lang:_(t.lang,e),block:A(t.block,e)};case"comp":case"dynamic":return{t:t.t,name:t.t==="comp"?t.name:void 0,tag:t.t==="dynamic"?e[t.tag]:void 0,inputs:Object.fromEntries(Object.entries(t.inputs).map(([n,r])=>[n,_(r,e)])),spreads:t.spreads.map((n)=>e[n]),events:t.events.map((n)=>({name:n.name,e:e[n.e]})),contents:t.contents&&{args:t.contents.args,block:A(t.contents.block,e)}}}}var A=(t,e)=>({html:t.html,scope:t.scope,binds:t.binds.map((n)=>ut(n,e)),blocks:t.blocks.map((n)=>z(n,e))}),wt=(t,e,n,r)=>t.t===n.t&&JSON.stringify(z(t,e))===JSON.stringify(z(n,r)),Mt=(t,e,n,r)=>JSON.stringify(t.map((s)=>ut(s,e)))===JSON.stringify(n.map((s)=>ut(s,r))),Ot=(t,e,n,r)=>{let s=(a,p)=>JSON.stringify(a.blocks.filter((i)=>i.t==="let").map((i)=>z(i,p)));return s(t,e)===s(n,r)};var At=Symbol("lips.slot"),Zt=(t)=>!!t&&typeof t==="object"&&t[At]===!0;function Pt(t){let e=!1,n=!1,r=(s)=>typeof t.onError==="function"?t.onError(s):console.error("[lips:ir]",s);return{onError:r,ready(){n=!0},notifyUpdate(){if(!n||e)return;e=!0,Promise.resolve().then(()=>{e=!1;try{typeof t.onUpdate==="function"&&t.onUpdate(),typeof t.onRender==="function"&&t.onRender()}catch(s){r(s)}})}}}var X=[];function Bt(){let t=!0;while(t){t=!1;for(let e of[...X].reverse()){if(!e.live())continue;let n=X.indexOf(e);if(n<0)continue;X.splice(n,1),e.fn(),t=!0}}}var Lt=new Map;function Qt(t){let e=Lt.get(t);if(!e)e=it(t).ast,Lt.set(t,e);return e}var J=(t)=>t.join(",");function jt(t,e,n){let r=e;for(let s of n)r=t.child(r,s);return r}var H=(t,e)=>t.range(e.start,e.end),Nt=(t,e,n,r)=>r===e||t.precedes(e,r)&&t.precedes(r,n);function _t(t,e){e.gen++;for(let r of e.wiring)r();e.wiring=[];let n=t.fragment();for(let r of H(t,e.inst))t.insert(n,r,null)}function j(t,e,n){return t.insertAfter(e,H(t,n)),n}var ft=(t,e)=>H(t,e).filter((n)=>t.isElement(n));function $t(t,e,n){for(let r of ft(t,e))t.scope(r,n)}function te(t,e,n,r,s=""){for(let a of e)t.styleVar(a,n,r===null||r===void 0||r===!1?null:r+s)}function Ft(t,e,n,r,s){$t(t,n,r);let a=s.css?e.createStylesheet?.(r,s.css):void 0;return a?()=>a.clear():void 0}function ee(t){for(let e of t.bindHandles)e.dispose();for(let e of t.childHandles)e.dispose()}function T(t,e){if(!e)return;ee(e);for(let n of H(t,e))t.remove(n,!0)}var Y=(t,e,n,r)=>t.attr(e,n,r===!1||r==null?null:r===!0?"":String(r)),F=(t,e,n)=>Object.defineProperty(t,e,{get:n,enumerable:!0,configurable:!0}),ne=Symbol.for("lips.self"),Ht=Symbol("lips.ctx.layer");function re(t,e,n,r){for(let s=t;s;s=Object.getPrototypeOf(s)){let p=s[Ht]?.get(e);if(p){p(n);return}}r?.(e,n)}function Dt(t,e){let n=new Map,r=(o,...l)=>n.get(o)?.forEach((c)=>c(...l)),s,a=()=>null;return{proto:{[ne]:!0,get node(){let o=a();return o?ft(t,o):[]},get lang(){return e()},pick:(o)=>q(o,e()),emit:r,emitLocal:r,on(o,l){return n.set(o,[...n.get(o)||[],l]),s},once(o,l){let c=(...f)=>{s.off(o,c),l(...f)};return s.on(o,c)},off(o,l){if(!l)n.delete(o);else{let c=(n.get(o)||[]).filter((f)=>f!==l);c.length?n.set(o,c):n.delete(o)}return s}},bind:(o,l)=>(s=o,a=l,o)}}class Z{ir;options;hooks;live;constructor(t,e,n,r=[]){this.ir=t;this.options=e;this.hooks=n;this.live=r;this.h=e.host||lt}h;pool=null;salvaged=[];withSalvage(t,e){let n=this.pool;this.pool=t;try{return e()}finally{this.pool=n;for(let r of t)!r.claimed&&r.teardown()}}claim(t,e){let n=this.pool?.find((r)=>!r.claimed&&r.name===t&&r.key===e);if(!n)return;return n.claimed=!0,this.salvaged.push(t),n}keyOf(t,e,n){let r=t.key;return r===void 0?void 0:("lit"in r)?r.lit:w(()=>this.runner(r.e,n)(e))}guarded(t){let e=!0;return R(()=>{try{t()}catch(n){this.hooks?this.hooks.onError(n):console.error("[lips:ir]",n)}e?e=!1:this.hooks?.notifyUpdate()})}bindStyle(t,e,n){if(!t.binds.length)return()=>{};let r=ft(this.h,e),s=t.binds.map((a)=>{let p=this.srcRunner(t.exprs[a.e],[]);return this.guarded(()=>te(this.h,r,a.prop,p(n),a.u))});return()=>{for(let a of s)a.dispose()}}runner(t,e){return this.srcRunner(this.ir.exprs[t],e)}srcRunner(t,e){if(this.options.guard)return this.options.guard.run(t);if(this.options.mode==="interpreted"){let r=Qt(t);return(s)=>Rt(r,s)}let n=bt(t,e);return(r)=>n.run(r)}renderBlock(t,e){let n=this.h,r=n.clone(t),s=new Map,a=t.binds.map((u)=>{let h=jt(n,r,u.p);return s.set(J(u.p),h),h}),p=t.blocks.map((u)=>{let h=jt(n,r,u.p);return s.set(J(u.p),h),h}),i=n.marker("^"),o=n.marker("$");n.insert(r,o,null),n.insert(r,i,n.child(r,0));let l=Object.create(e.scope??null),c={...e,scope:l},f={start:i,end:o,block:t,exprs:this.ir.exprs,penv:e,benv:c,pathNodes:s,bindHandles:[],childHandles:[]};return t.blocks.forEach((u,h)=>{if(u.t!=="let")return;let d=[];for(let[g,v]of Object.entries(u.vars))if("lit"in v){let[y]=C(v.lit);F(l,g,y)}else{let[y,m]=C(void 0);F(l,g,y);let I=this.runner(v.e,t.scope);d.push(R(()=>m(I(c))).dispose)}f.childHandles[h]={child:u,exprs:this.ir.exprs,anchor:p[h],dispose:()=>d.forEach((g)=>g())}}),f.bindHandles=t.binds.map((u,h)=>this.bindOne(u,a[h],c,t.scope)),t.blocks.forEach((u,h)=>{if(u.t==="let")return;f.childHandles[h]={child:u,exprs:this.ir.exprs,anchor:p[h],dispose:this.execBlock(u,p[h],c,t.scope)}}),f}bindOne(t,e,n,r,s){let a=this.h;switch(t.t){case"text":{let p=s??a.text("");!s&&a.insertAfter(e,[p]);let i=this.runner(t.e,r),o=t.i18n?this.options.i18n:void 0,l=this.guarded(()=>{let c=i(n),f=c==null?"":String(c);a.setText(p,o?o.translate(f,t.ik,n.lang?.()):f)});return{bind:t,node:e,textNode:p,dispose:l.dispose}}case"attr":{let p=this.runner(t.e,r),i=t.i18n?this.options.i18n:void 0,o=this.guarded(()=>{let l=p(n);Y(a,e,t.name,i&&l!=null?i.translate(String(l),t.ik,n.lang?.()):l)});return{bind:t,node:e,dispose:o.dispose}}case"prop":{let p=this.runner(t.e,r);if(t.name==="format"){let o=t.ref||"",l=this.guarded(()=>{let c=p(n),f=this.options.i18n?.format(o,c,n.lang?.());a.content(e,f==null?"":String(f))});return{bind:t,node:e,dispose:l.dispose}}let i=this.guarded(()=>{let o=p(n),l=o==null?"":String(o);t.name==="html"&&a.html?a.html(e,l):a.content(e,l)});return{bind:t,node:e,dispose:i.dispose}}case"event":{let p=this.eventDispatcher(this.ir.exprs[t.e],r,n);return{bind:t,node:e,dispose:a.listen(e,t.name,p)}}case"spread":{let p=this.runner(t.e,r),i=new Set,o=this.guarded(()=>{let l=p(n)||{},c=new Set(Object.keys(l));for(let f of i)!c.has(f)&&a.attr(e,f,null);for(let f of c)Y(a,e,f,l[f]);i=c});return{bind:t,node:e,dispose:o.dispose}}}}swapBlock(t,e,n,r){if(t.block.html!==e.html||JSON.stringify(t.block.scope)!==JSON.stringify(e.scope)||!Ot(t.block,t.exprs,e,this.ir.exprs))return this.rebuild(t,e,n,r);if(!Mt(t.block.binds,t.exprs,e.binds,this.ir.exprs)){let s=e.binds.map((i)=>t.pathNodes.get(J(i.p)));if(s.some((i)=>!i))return this.rebuild(t,e,n,r);let a=new Map;t.bindHandles.forEach((i)=>i.textNode&&a.set(J(i.bind.p),i.textNode)),t.bindHandles.forEach((i)=>i.dispose());let p=new Set;t.bindHandles=e.binds.map((i,o)=>{let l=J(i.p),c=i.t==="text"?a.get(l):void 0;return c&&p.add(l),this.bindOne(i,s[o],t.benv,e.scope,c)}),a.forEach((i,o)=>!p.has(o)&&this.h.remove(i,!0)),n.push({kind:"binds",path:r})}for(let s=0;s<e.blocks.length;s++){let a=e.blocks[s],p=t.childHandles[s];if(a.t==="let")continue;if(p&&wt(p.child,p.exprs,a,this.ir.exprs))continue;let i=this.live.filter((o)=>Nt(this.h,p.anchor,t.childHandles[s+1]?.anchor??t.end,o.anchor));for(let o of i)_t(this.h,o);p?.dispose(),t.childHandles[s]={child:a,exprs:this.ir.exprs,anchor:p.anchor,dispose:this.withSalvage(i,()=>this.execBlock(a,p.anchor,t.benv,e.scope))},n.push({kind:"block",path:`${r}/${s}`})}return t.block=e,t.exprs=this.ir.exprs,t}rebuild(t,e,n,r){let s=this.live.filter((p)=>Nt(this.h,t.start,t.end,p.anchor));for(let p of s)_t(this.h,p);let a=this.withSalvage(s,()=>this.renderBlock(e,t.penv));return j(this.h,t.end,a),T(this.h,t),n.push({kind:"skeleton",path:r}),a}execBlock(t,e,n,r){let s=this.h,a=[];switch(t.t){case"if":{let p=t.branches.map((c)=>c.when!=null?this.runner(c.when,r):null),i=null,o=-2,l=R(()=>{let c=-1;for(let f=0;f<t.branches.length;f++){let u=p[f];if(!u||u(n)){c=f;break}}if(c===o)return;o=c,w(()=>{if(T(s,i),i=null,c>=0)i=j(s,e,this.renderBlock(t.branches[c].block,n))})});a.push(()=>{l.dispose(),T(s,i)});break}case"switch":{let p=this.runner(t.on,r),i=t.cases.map((f)=>f.is&&("e"in f.is)?this.runner(f.is.e,r):null),o=null,l=-2,c=R(()=>{let f=p(n),u=-1,h=-1;for(let d=0;d<t.cases.length;d++){let g=t.cases[d];if(g.is===null){h=d;continue}let v="lit"in g.is?g.is.lit:i[d](n);if(Array.isArray(v)?v.includes(f):v===f){u=d;break}}if(u===-1)u=h;if(u===l)return;l=u,w(()=>{if(T(s,o),o=null,u>=0)o=j(s,e,this.renderBlock(t.cases[u].block,n))})});a.push(()=>{c.dispose(),T(s,o)});break}case"macro":{let p=Object.create(n.scope??null),i=O({}),o={};for(let u of t.args)o[u]=C(void 0),F(p,u,o[u][0]);let l=t.sets.map((u)=>{if("spread"in u)return{kind:"spread",run:this.runner(u.spread,r)};if("lit"in u.ci){let d=u.ci.lit;return{kind:"value",name:u.name,value:()=>d}}let h=this.runner(u.ci.e,r);return{kind:"value",name:u.name,value:()=>h(n)}}),c=new Set;a.push(R(()=>{let u={};for(let h of l)if(h.kind==="spread"){let d=h.run(n);if(d&&typeof d==="object")for(let[g,v]of d instanceof Map?d:Object.entries(d))u[g]=v}else u[h.name]=h.value();w(()=>{for(let d of t.args)o[d][1](u[d]);let h=new Set(Object.keys(u));for(let d of c)!h.has(d)&&delete i[d];for(let d of h)i[d]=u[d];c=h})}).dispose);let f=j(s,e,this.renderBlock(t.block,{...n,arguments:i,scope:p}));a.push(()=>T(s,f));break}case"for":this.execFor(t,e,n,r,a);break;case"async":{let p=this.runner(t.awaitE,r),i=null,o=0,l=(f,u)=>{if(T(s,i),i=null,!f)return;let h="block"in f,d=Object.create(n.scope??null);if(h&&f.args[0]!==void 0){let[g]=C(u);F(d,f.args[0],g)}i=j(s,e,this.renderBlock(h?f.block:f,{...n,scope:d}))},c=R(()=>{let f=p(n),u=++o;w(()=>{t.loading?l(t.loading):l(void 0),Promise.resolve(f).then((h)=>u===o&&w(()=>l(t.then,h)),(h)=>u===o&&w(()=>l(t.catch,h)))})});a.push(()=>{o++,c.dispose(),T(s,i)});break}case"provide":{let p=Object.create(n.context??null),i=new Map;Object.defineProperty(p,Ht,{value:i});for(let[c,f]of Object.entries(t.vars)){let[u,h]=C("lit"in f?f.lit:void 0);if(F(p,c,u),i.set(c,h),"lit"in f)continue;let d=this.runner(f.e,r);a.push(R(()=>h(d(n))).dispose)}let o=n.lang;if(t.lang)if("lit"in t.lang){let c=String(t.lang.lit);o=()=>c}else{let[c,f]=C(void 0),u=this.runner(t.lang.e,r);a.push(R(()=>f(u(n))).dispose),o=()=>c()??n.lang?.()}let l=j(s,e,this.renderBlock(t.block,{...n,context:p,lang:o}));a.push(()=>T(s,l));break}case"log":{let p=ot(this.ir.exprs[t.e]).map((i)=>this.srcRunner(i,r));a.push(R(()=>console.log(...p.map((i)=>i(n)))).dispose);break}case"comp":{let p=this.options.components?.[t.name];p?this.execComponent(p,t,e,n,r,a,t.name):this.execElement(t,e,n,r,a);break}case"dynamic":{let p=this.runner(t.tag,r),i=[],o=Symbol("init"),l=R(()=>{let c=p(n);if(c===o)return;o=c,w(()=>{for(let u of i)u();if(i=[],c==null)return;if(Zt(c)){let u={};for(let[d,g]of Object.entries(t.inputs))u[d]="lit"in g?g.lit:this.runner(g.e,r)(n);let h=j(s,e,c.render(u));i.push(()=>T(s,h));return}let f=typeof c==="string"?this.options.components?.[c]:c&&typeof c==="object"?c.ir?c:this.options.resolveTemplate?.(c):void 0;if(f)this.execComponent(f,t,e,n,r,i,typeof c==="string"?c:"#dynamic");else if(typeof c==="string")this.execElement({...t,name:c},e,n,r,i)})});a.push(()=>{l.dispose();for(let c of i)c()});break}}return()=>a.forEach((p)=>p())}execFor(t,e,n,r,s){let a=this.h,p=t.of!==void 0?this.runner(t.of,r):null,i=t.by&&"e"in t.by?this.runner(t.by.e,r):null,o=t.by&&"lit"in t.by?String(t.by.lit).split("."):null,l=(g,v)=>g===void 0?void 0:("lit"in g)?g.lit:this.runner(g.e,r)(v),c=[],f=0,u=new Map,h=()=>{if(p===null){let y=Number(l(t.from,n)??0),m=Number(l(t.to,n)??y),I=y<=m,E=[];for(let S=y;I?S<=m:S>=m;I?S++:S--)E.push({key:S,values:[S]});return E}let g=p(n),v=(y,m,I)=>{if(i){let E=i(n);return typeof E==="function"?E(y,I):m}if(o)return o.reduce((E,S)=>E?.[S],y);return m};if(Array.isArray(g))return g.map((y,m)=>({key:v(y,m,m),values:[y,m]}));if(g instanceof Map)return[...g.entries()].map(([y,m],I)=>({key:y,values:[y,m,I]}));if(g instanceof Set)return[...g].map((y,m)=>({key:v(y,y,m),values:[y,m]}));if(g&&typeof g==="object")return Object.entries(g).map(([y,m],I)=>({key:y,values:[y,m,I]}));return[]},d=R(()=>{let g=h();w(()=>{let v=new Set,y=[],m=++f;for(let E of g){let S=E.key;if(v.has(S))console.warn(`<for> duplicate key '${String(S)}' — falling back to positional identity`),S=`#dup:${y.length}`;v.add(S);let P=u.get(S);if(P)P.sigs.forEach(([B,M,U],x)=>{let k=E.values[x];Object.is(B(),k)&&typeof k==="object"&&k!==null?U():M(k)}),P.pass=m,y.push(P);else{let B=Object.create(n.scope??null),M=E.values.map((k)=>C(k));t.args.forEach((k,N)=>M[N]&&F(B,k,M[N][0]));let U=this.renderBlock(t.block,{...n,scope:B}),x={key:S,sigs:M,inst:U,pass:m};u.set(S,x),y.push(x)}}for(let E of c)if(E.pass!==m)u.delete(E.key),T(a,E.inst);let I=e;for(let E of y){if(a.next(I)!==E.inst.start)j(a,I,E.inst);I=E.inst.end}c=y})});s.push(()=>{d.dispose();for(let g of c)T(a,g.inst);c=[],u.clear()})}wireInputs(t,e,n,r,s,a){for(let[p,i]of Object.entries(t.inputs))if(a?.add(p),"lit"in i)r[p]=i.lit;else{let o=this.runner(i.e,n);s.push(R(()=>r[p]=o(e)).dispose)}for(let p of t.spreads){let i=this.runner(p,n);s.push(R(()=>{let o=i(e)||{};w(()=>Object.entries(o).forEach(([l,c])=>{a?.add(l),r[l]=c}))}).dispose)}}wireEvents(t,e,n,r,s){t?.forEach((a)=>{let p=this.eventDispatcher(this.ir.exprs[a.e],n,e);r.on(a.name,p),s.push(()=>r.off(a.name,p))})}slotRenderer(t,e){let n=this;return{[At]:!0,args:t.args,render(r){let s=Object.create(e.scope??null);return t.args.forEach((a)=>{let[p]=C(r?.[a]);F(s,a,p)}),n.renderBlock(t.block,{...e,scope:s})}}}adoptComponent(t,e,n,r,s,a){let p=[],i=new Set;if(this.wireInputs(e,r,s,t.input,p,i),e.contents)t.input.renderer=this.slotRenderer(e.contents,r),i.add("renderer");for(let l of Object.keys(t.input))!i.has(l)&&delete t.input[l];this.wireEvents(e.events,r,s,t.self,p),t.wiring=p,t.anchor=n;let o=t.gen;j(this.h,n,t.inst),a.push(()=>{if(o!==t.gen)return;for(let l of t.wiring)l();t.wiring=[],t.teardown()})}execComponent(t,e,n,r,s,a,p){let i=this.pool?.length?this.claim(p,this.keyOf(e.inputs,r,s)):void 0;if(i)return this.adoptComponent(i,e,n,r,s,a);let o=O({}),l=[];if(this.wireInputs(e,r,s,o,l),e.contents)o.renderer=this.slotRenderer(e.contents,r);let c=O({...t.state||{}},t.deep??!1),f=null,u=this,h=Dt(this.h,()=>r.lang?.()??u.options.i18n?.lang()??""),d=h.bind(Object.assign(Object.create(h.proto),{...this.options.expose||{},state:c,input:o,static:t.statics,context:r.context,setContext(x,k){let N=(nt,rt)=>re(r.context,nt,rt,u.options.expose?.setContext);typeof x==="string"?N(x,k):Object.entries(x||{}).forEach(([nt,rt])=>N(nt,rt))}}),()=>f);t.handlers&&Object.entries(t.handlers).forEach(([x,k])=>d[x]=k.bind(d)),this.wireEvents(e.events,r,s,d,l);let g=Pt(d);try{typeof d.onCreate==="function"&&d.onCreate()}catch(x){g.onError(x)}try{Object.keys(o).length&&typeof d.onInput==="function"&&d.onInput(o)}catch(x){g.onError(x)}let v={state:c,input:o,context:r.context,lang:r.lang,static:t.statics,self:d,scope:void 0},y=new Z(t.ir,this.options,g),m=y.renderBlock(t.ir.root,v);f=m;let I=t.stylesheet?Ft(this.h,this.options,m,t.stylesheet.nsp||t.nsp||"lips",t.stylesheet):void 0,E=t.stylesheet?y.bindStyle(t.stylesheet,m,v):void 0;j(this.h,n,m),g.ready();try{typeof d.onMount==="function"&&d.onMount(),typeof d.onRender==="function"&&d.onRender(),d.emit("component:mount")}catch(x){g.onError(x)}let S;if(t.context?.length&&typeof d.onContext==="function"){let x=!0,{dispose:k}=R(()=>{for(let N of t.context)v.context?.[N];if(x){x=!1;return}w(()=>{try{d.onContext()}catch(N){g.onError(N)}})});S=k}let P=!1;X.push({live:()=>this.h.connected(m.start),fn:()=>{P=!0;try{typeof d.onAttach==="function"&&d.onAttach(),d.emit("component:attached")}catch(x){g.onError(x)}}}),this.h.connected(m.start)&&Bt();let B=!1,M={name:p,key:o.key,self:d,input:o,inst:m,anchor:n,wiring:l,gen:0,claimed:!1,teardown:()=>{if(B)return;B=!0;let x=this.live.indexOf(M);x>-1&&this.live.splice(x,1),S?.(),E?.(),I?.(),T(this.h,m);try{if(P)typeof d.onDetach==="function"&&d.onDetach(),d.emit("component:detached");typeof d.onDestroy==="function"&&d.onDestroy(),d.emit("component:destroy")}catch(k){g.onError(k)}}};this.live.push(M);let U=M.gen;a.push(()=>{if(U!==M.gen)return;for(let x of M.wiring)x();M.wiring=[],M.teardown()})}execElement(t,e,n,r,s){let a=this.h,p=a.element(t.name);for(let[i,o]of Object.entries(t.inputs))if("lit"in o)Y(a,p,i,o.lit);else{let l=this.runner(o.e,r);s.push(R(()=>Y(a,p,i,l(n))).dispose)}for(let i of t.events)s.push(a.listen(p,i.name,this.eventDispatcher(this.ir.exprs[i.e],r,n)));if(t.contents){let i=this.renderBlock(t.contents.block,n);for(let o of H(a,i))a.insert(p,o,null);s.push(()=>T(a,i))}a.insertAfter(e,[p]),s.push(()=>a.remove(p,!0))}eventDispatcher(t,e,n){let r=ot(t);return(...s)=>w(()=>{let a=(o)=>{let l;try{l=this.srcRunner(o,e)(n)}catch(c){l=void 0}if(typeof l!=="function"&&n.self&&!this.options.guard?.self(o)&&typeof n.self[o]==="function")l=n.self[o];return l};if(!r.length)return;let p=a(r[0]);if(typeof p!=="function")return;let i=r.slice(1).map((o)=>this.srcRunner(o,e)(n));p(...i,...s)})}}function dt(t,e={},n={}){let r=n.host||lt,s=O(e.state||{},e.deep??!1),a=e.input?O(e.input,e.deep??!1):void 0,p=null,i=Dt(r,()=>n.i18n?.lang()??""),o=i.bind(Object.assign(Object.create(i.proto),{state:s,input:a,static:e.static,...n.expose||{},...e.expose||{}}),()=>p);e.handlers&&Object.entries(e.handlers).forEach(([y,m])=>o[y]=m.bind(o));let l={state:s,input:a,context:e.context,static:e.static,self:o,scope:void 0},c=Pt(o);try{typeof o.onCreate==="function"&&o.onCreate()}catch(y){c.onError(y)}try{a&&Object.keys(a).length&&typeof o.onInput==="function"&&o.onInput(a)}catch(y){c.onError(y)}let f=new Z(t,n,c),u=f.renderBlock(t.root,l);p=u,c.ready();let h=e.stylesheet?Ft(r,n,u,e.stylesheet.nsp||e.nsp||"lips",e.stylesheet):void 0,d=e.stylesheet?f.bindStyle(e.stylesheet,u,l):void 0;try{typeof o.onMount==="function"&&o.onMount(),typeof o.onRender==="function"&&o.onRender()}catch(y){c.onError(y)}let g=!1,v=()=>{if(g)return;g=!0;try{typeof o.onAttach==="function"&&o.onAttach(),o.emit("component:attached")}catch(y){c.onError(y)}};return{state:s,self:o,get nodes(){return H(r,u)},mount(y){for(let m of H(r,u))r.insert(y,m,null);if(r.connected(u.start))v(),Bt()},swap(y){let m=[],I=r.keepFocus?.();if(f=new Z(y,n,c,f.live),u=f.swapBlock(u,y.root,m,"root"),p=u,e.stylesheet)$t(r,u,e.stylesheet.nsp||e.nsp||"lips"),d?.(),d=f.bindStyle(e.stylesheet,u,l);return I?.(),{changes:m,salvaged:f.salvaged}},dispose(){d?.(),h?.(),T(r,u);try{if(g)typeof o.onDetach==="function"&&o.onDetach(),o.emit("component:detached");typeof o.onDestroy==="function"&&o.onDestroy()}catch(y){c.onError(y)}}}}class Q{options={emit:!0};__events={};__once_events={};constructor(t){if(t)this.options=t}on(t,e){if(!Array.isArray(this.__events[t]))this.__events[t]=[];return this.__events[t].push(e),this}once(t,e){if(!Array.isArray(this.__once_events[t]))this.__once_events[t]=[];return this.__once_events[t].push(e),this}off(t,e){if(e){if(Array.isArray(this.__events[t]))this.__events[t]=this.__events[t].filter((n)=>n!==e),!this.__events[t].length&&delete this.__events[t];if(Array.isArray(this.__once_events[t]))this.__once_events[t]=this.__once_events[t].filter((n)=>n!==e),!this.__once_events[t].length&&delete this.__once_events[t]}else delete this.__events[t],delete this.__once_events[t];return this}emit(t,...e){if(!this.options.emit)return;let n=(s)=>{if(!s||typeof s!=="object")return s;if(typeof s.toJSON==="function")return s.toJSON();if(Array.isArray(s))return s.map(n);if(s.constructor===Object||s.constructor===void 0){let a={};for(let p in s)a[p]=n(s[p]);return a}return s},r=e.map(n);this.__events[t]?.forEach((s)=>s(...r)),this.__once_events[t]?.forEach((s)=>s(...r)),delete this.__once_events[t]}}class tt{nsp;settings;constructor(t,e){if(typeof t!=="string"||!t)throw Error("Undefined or invalid stylesheet namespace");this.nsp=t,this.settings=e||{},this.settings.sheet&&this.load(this.settings)}get rel(){return`${this.settings.meta?"@":""}${this.nsp}`}get styleElement(){return document.head.querySelector(`style[rel="${this.rel.replace(/["\\]/g,"\\$&")}"]`)}load(t){if(this.settings=t,!t.sheet)return;let e=this.styleElement;if(e)return e.setAttribute("dindex",String(Number(e.getAttribute("dindex")||0)+1)),e;let n=document.createElement("style");return n.setAttribute("rel",this.rel),n.setAttribute("dindex","0"),n.textContent=t.sheet,t.meta?document.head.prepend(n):document.head.appendChild(n),n}clear(){let t=this.styleElement;if(!t)return;let e=Number(t.getAttribute("dindex")||0);e<=0?t.remove():t.setAttribute("dindex",String(e-1))}}var se="en-US";class et{engine;currentLang;DICTIONARIES={};functions;onMissing;onError;onChange;loader;loading=new Map;formatters=new Map;constructor(t,e){this.engine=e;this.currentLang=t||typeof navigator<"u"&&navigator.language||se,this.functions={...e?.functions}}set lang(t){if(this.currentLang===t)return;this.currentLang=t}get lang(){return this.currentLang}setDictionary(t,e){if(!this.engine)throw Error(`[lips:i18n] <${t}> dictionary without a MessageFormat engine — pass \`messageFormat\` from '@lipsjs/lips/i18n' to new Lips()`);this.DICTIONARIES[t.toLowerCase()]=e,this.formatters.clear(),this.onChange?.()}has(t){return K(t.toLowerCase()).some((e)=>!!this.DICTIONARIES[e])}setLoader(t){return this.loader=t,this}load(t){return Promise.all(K(t).map((e)=>{let n=e.toLowerCase();if(this.DICTIONARIES[n]||!this.loader)return;let r=this.loading.get(n);if(!r)r=this.loader(e).then((s)=>{s&&this.setDictionary(e,s)}).catch((s)=>console.warn(`[lips:i18n] <${e}> dictionary failed to load —`,s)),this.loading.set(n,r);return r})).then(()=>{})}message(t,e){let n=`${e}
|
|
3
|
-
${t}`;if(this.formatters.has(n))return this.formatters.get(n);let r;for(let
|
|
1
|
+
var Zt=["===","!==","...","=>","==","!=","<=",">=","&&","||","??","?.","++","--","+=","-=","*=","/=","%=","+","-","*","/","%","<",">","!","?",":",".",",","(",")","[","]","{","}","="];function Qt(t,e){let n=[],r=0,i=(c)=>/[A-Za-z_$]/.test(c),a=(c)=>/[A-Za-z0-9_$]/.test(c);while(r<t.length){let c=t[r];if(/\s/.test(c)){r++;continue}if(/[0-9]/.test(c)||c==="."&&/[0-9]/.test(t[r+1])){let s=r;while(r<t.length&&/[0-9]/.test(t[r]))r++;if(t[r]==="."){r++;while(r<t.length&&/[0-9]/.test(t[r]))r++}if(t[r]==="e"||t[r]==="E"){if(r++,t[r]==="+"||t[r]==="-")r++;while(r<t.length&&/[0-9]/.test(t[r]))r++}n.push({t:"num",value:t.slice(s,r),start:s,end:r});continue}if(c==="'"||c==='"'){let s=r;r++;let l="",o=!1;while(r<t.length){let u=t[r];if(u==="\\"){let f=t[r+1],d={n:`
|
|
2
|
+
`,t:"\t",r:"\r",b:"\b",f:"\f",v:"\v","0":"\x00"};if(f==="u"){let h=t.slice(r+2,r+6);l+=String.fromCharCode(parseInt(h,16)||0),r+=6}else l+=d[f]??f,r+=2;continue}if(u===c){o=!0,r++;break}l+=u,r++}if(!o)e.push({code:"LIPS-E001",message:"Unterminated string literal",loc:{offset:s,length:r-s}});n.push({t:"str",value:l,start:s,end:r});continue}if(i(c)){let s=r;while(r<t.length&&a(t[r]))r++;n.push({t:"id",value:t.slice(s,r),start:s,end:r});continue}let p=Zt.find((s)=>t.startsWith(s,r));if(p==="?."&&/[0-9]/.test(t[r+2]??""))p="?";if(p){n.push({t:"punct",value:p,start:r,end:r+p.length}),r+=p.length;continue}e.push({code:"LIPS-E002",message:`Unexpected character '${c}'`,loc:{offset:r,length:1}}),r++}return n.push({t:"eof",value:"",start:t.length,end:t.length}),n}class Ct{tokens;diagnostics;pos=0;constructor(t,e){this.tokens=t;this.diagnostics=e}peek(t=0){return this.tokens[Math.min(this.pos+t,this.tokens.length-1)]}next(){return this.tokens[this.pos++]??this.tokens[this.tokens.length-1]}at(t){let e=this.peek();return e.t==="punct"&&e.value===t}eat(t){if(this.at(t))return this.pos++,!0;return!1}error(t,e,n=this.peek()){return this.diagnostics.push({code:t,message:e,loc:{offset:n.start,length:Math.max(1,n.end-n.start)}}),{t:"error"}}expect(t,e){if(!this.eat(t))this.error(e,`Expected '${t}'`)}parse(){let t=this.assign();if(this.peek().t!=="eof")this.error("LIPS-E003",`Unexpected token '${this.peek().value}' after expression`);return t}isArrowAhead(){let t=this.peek();if(t.t==="id"){let e=this.peek(1);return e.t==="punct"&&e.value==="=>"}if(t.t==="punct"&&t.value==="("){let e=0,n=0;while(!0){let r=this.peek(n);if(r.t==="eof")return!1;if(r.t==="punct"&&r.value==="(")e++;if(r.t==="punct"&&r.value===")"){if(e--,e===0){let i=this.peek(n+1);return i.t==="punct"&&i.value==="=>"}}n++}}return!1}assign(){if(this.isArrowAhead()){let n=[];if(this.peek().t==="id")n.push(this.next().value);else{this.expect("(","LIPS-E004");while(!this.at(")")&&this.peek().t!=="eof"){let r=this.next();if(r.t!=="id")return this.error("LIPS-E005","Invalid arrow parameter",r);if(n.push(r.value),!this.eat(","))break}this.expect(")","LIPS-E004")}return this.expect("=>","LIPS-E004"),{t:"arrow",params:n,body:this.assign()}}let t=this.conditional(),e=this.peek();if(e.t==="punct"&&["=","+=","-=","*=","/=","%="].includes(e.value)){if(t.t!=="id"&&t.t!=="member")return this.error("LIPS-E006","Invalid assignment target",e);return this.next(),{t:"assign",op:e.value,target:t,value:this.assign()}}return t}conditional(){let t=this.nullish();if(this.eat("?")){let e=this.assign();return this.expect(":","LIPS-E007"),{t:"cond",test:t,cons:e,alt:this.assign()}}return t}nullish(){let t=this.or();while(this.at("??"))this.next(),t={t:"logic",op:"??",l:t,r:this.or()};return t}or(){let t=this.and();while(this.at("||"))this.next(),t={t:"logic",op:"||",l:t,r:this.and()};return t}and(){let t=this.equality();while(this.at("&&"))this.next(),t={t:"logic",op:"&&",l:t,r:this.equality()};return t}equality(){let t=this.relational();while(["===","!==","==","!="].some((e)=>this.at(e)))t={t:"bin",op:this.next().value,l:t,r:this.relational()};return t}relational(){let t=this.additive();while(["<=",">=","<",">"].some((e)=>this.at(e)))t={t:"bin",op:this.next().value,l:t,r:this.additive()};return t}additive(){let t=this.multiplicative();while(this.at("+")||this.at("-"))t={t:"bin",op:this.next().value,l:t,r:this.multiplicative()};return t}multiplicative(){let t=this.unary();while(this.at("*")||this.at("/")||this.at("%"))t={t:"bin",op:this.next().value,l:t,r:this.unary()};return t}unary(){if(this.at("!")||this.at("-")||this.at("+"))return{t:"unary",op:this.next().value,arg:this.unary()};if(this.at("++")||this.at("--")){let t=this.next().value,e=this.unary();if(e.t!=="id"&&e.t!=="member")return this.error("LIPS-E006","Invalid update target");return{t:"update",op:t,arg:e,prefix:!0}}return this.postfix()}postfix(){let t=this.callMember();if(this.at("++")||this.at("--")){let e=this.next().value;if(t.t!=="id"&&t.t!=="member")return this.error("LIPS-E006","Invalid update target");t={t:"update",op:e,arg:t,prefix:!1}}return t}callMember(){let t=this.primary();while(!0)if(this.eat(".")){let e=this.next();if(e.t!=="id")return this.error("LIPS-E008","Expected property name",e);t={t:"member",obj:t,prop:e.value,computed:!1,optional:!1,at:e.start}}else if(this.eat("?."))if(this.at("("))t={t:"call",callee:t,args:this.argList(),optional:!0};else if(this.eat("[")){let e=this.peek().start,n=this.assign();this.expect("]","LIPS-E009"),t={t:"member",obj:t,prop:n,computed:!0,optional:!0,at:e}}else{let e=this.next();if(e.t!=="id")return this.error("LIPS-E008","Expected property name",e);t={t:"member",obj:t,prop:e.value,computed:!1,optional:!0,at:e.start}}else if(this.eat("[")){let e=this.peek().start,n=this.assign();this.expect("]","LIPS-E009"),t={t:"member",obj:t,prop:n,computed:!0,optional:!1,at:e}}else if(this.at("("))t={t:"call",callee:t,args:this.argList(),optional:!1};else break;return t}argList(){this.expect("(","LIPS-E010");let t=[];while(!this.at(")")&&this.peek().t!=="eof")if(t.push(this.assign()),!this.eat(","))break;return this.expect(")","LIPS-E010"),t}primary(){let t=this.peek();if(t.t==="num")return this.next(),{t:"lit",v:parseFloat(t.value)};if(t.t==="str")return this.next(),{t:"lit",v:t.value};if(t.t==="id")switch(this.next(),t.value){case"true":return{t:"lit",v:!0};case"false":return{t:"lit",v:!1};case"null":return{t:"lit",v:null};case"undefined":return{t:"lit",v:void 0};case"NaN":return{t:"lit",v:NaN};case"Infinity":return{t:"lit",v:1/0};default:return{t:"id",name:t.value,at:t.start}}if(this.eat("(")){let e=this.assign();return this.expect(")","LIPS-E010"),e}if(this.eat("[")){let e=[];while(!this.at("]")&&this.peek().t!=="eof"){let n=this.eat("...");if(e.push({spread:n||void 0,value:this.assign()}),!this.eat(","))break}return this.expect("]","LIPS-E009"),{t:"arr",items:e}}if(this.eat("{")){let e=[];while(!this.at("}")&&this.peek().t!=="eof"){if(this.eat("..."))e.push({spread:!0,value:this.assign()});else{let n=this.next();if(n.t!=="id"&&n.t!=="str"&&n.t!=="num")return this.error("LIPS-E011","Invalid object key",n);if(this.eat(":"))e.push({key:String(n.value),value:this.assign(),at:n.start});else if(n.t==="id")e.push({key:n.value,value:{t:"id",name:n.value,at:n.start},at:n.start});else return this.error("LIPS-E011","Invalid shorthand property",n)}if(!this.eat(","))break}return this.expect("}","LIPS-E011"),{t:"obj",props:e}}return this.next(),this.error("LIPS-E012",t.t==="eof"?"Unexpected end of expression":`Unexpected token '${t.value}'`,t)}}function pt(t){let e=[],n=Qt(t,e);return{ast:new Ct(n,e).parse(),diagnostics:e}}function lt(t){let e=[],n=0,r=0;for(let i=0;i<t.length;i++){let a=t[i];if(a==="'"||a==='"'||a==="`"){i++;while(i<t.length&&t[i]!==a){if(t[i]==="\\")i++;i++}continue}if(a==="("||a==="["||a==="{")n++;else if(a===")"||a==="]"||a==="}")n--;else if(a===","&&n===0)e.push(t.slice(r,i)),r=i+1}return e.push(t.slice(r)),e.map((i)=>i.trim()).filter(Boolean)}var wt={__proto__:null,static:"__static",arguments:"__args__"};function b(t){switch(t.t){case"lit":if(typeof t.v==="string")return JSON.stringify(t.v);if(t.v===void 0)return"undefined";if(Number.isNaN(t.v))return"NaN";return String(t.v);case"id":return wt[t.name]??t.name;case"member":{let e=Rt(t.obj);if(t.computed)return`${e}${t.optional?"?.":""}[${b(t.prop)}]`;return`${e}${t.optional?"?.":"."}${t.prop}`}case"call":return`${Rt(t.callee)}${t.optional?"?.":""}(${t.args.map(b).join(",")})`;case"unary":return`(${t.op}(${b(t.arg)}))`;case"update":return t.prefix?`(${t.op}${ct(t.arg)})`:`(${ct(t.arg)}${t.op})`;case"bin":return`((${b(t.l)})${t.op}(${b(t.r)}))`;case"logic":return`((${b(t.l)})${t.op}(${b(t.r)}))`;case"cond":return`((${b(t.test)})?(${b(t.cons)}):(${b(t.alt)}))`;case"assign":return`(${ct(t.target)}${t.op}(${b(t.value)}))`;case"arrow":return`((${t.params.join(",")})=>(${b(t.body)}))`;case"arr":return`[${t.items.map((e)=>(e.spread?"...":"")+b(e.value)).join(",")}]`;case"obj":return`({${t.props.map((e)=>e.spread?`...${b(e.value)}`:`${JSON.stringify(e.key)}:${b(e.value)}`).join(",")}})`;case"error":return"undefined"}}var Rt=(t)=>t.t==="member"||t.t==="call"||t.t==="id"?b(t):`(${b(t)})`;function ct(t){if(t.t==="id")return wt[t.name]??t.name;if(t.t==="member"){let e=b(t.obj);return t.computed?`${e}[${b(t.prop)}]`:`${e}.${t.prop}`}return b(t)}var It=new Map,te=["state","input","context","__static","self"];function Tt(t,e=[]){let n=`${e.join(",")}\x00${t}`,r=It.get(n);if(r)return r;let{ast:i,diagnostics:a}=pt(t);if(a.length)console.warn(`[lips-ir] expression diagnostics for "${t}":`,a);let c=`return (${b(i)});`,p=[...te,"__args__",...e],s=Function(...p,c),l={source:t,run(o){let u=o.scope||{};return s(o.state,o.input,o.context,o.static,o.self,o.arguments,...e.map((f)=>u[f]))}};return It.set(n,l),l}var kt={__proto__:null,Math,JSON,Object,Array,String,Number,Boolean,Date,parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,console},V=Symbol("lips.ended");function Ot(t,e){let n=e.scope||Object.create(null),r=(s,l)=>{for(let o of l)if(s in o)return o[s];if(s in n)return n[s];switch(s){case"state":return e.state;case"input":return e.input;case"context":return e.context;case"static":return e.static;case"self":return e.self;case"arguments":return e.arguments}if(s in kt)return kt[s];return},i=(s,l,o)=>{for(let u of o)if(s in u)return u[s]=l,l;return n[s]=l,l},a=(s,l)=>{switch(s.t){case"lit":return s.v;case"id":return r(s.name,l);case"member":case"call":{let o=c(s,l);return o===V?void 0:o}case"unary":{let o=a(s.arg,l);switch(s.op){case"!":return!o;case"-":return-o;case"+":return+o}}case"update":{let o=a(s.arg,l),u=s.op==="++"?o+1:o-1;return p(s.arg,u,l),s.prefix?u:o}case"bin":{let o=a(s.l,l),u=a(s.r,l);switch(s.op){case"+":return o+u;case"-":return o-u;case"*":return o*u;case"/":return o/u;case"%":return o%u;case"<":return o<u;case">":return o>u;case"<=":return o<=u;case">=":return o>=u;case"==":return o==u;case"!=":return o!=u;case"===":return o===u;case"!==":return o!==u}return}case"logic":{let o=a(s.l,l);switch(s.op){case"&&":return o?a(s.r,l):o;case"||":return o?o:a(s.r,l);case"??":return o!=null?o:a(s.r,l)}}case"cond":return a(s.test,l)?a(s.cons,l):a(s.alt,l);case"assign":{let o=a(s.value,l);if(s.op!=="="){let u=a(s.target,l);switch(s.op){case"+=":o=u+o;break;case"-=":o=u-o;break;case"*=":o=u*o;break;case"/=":o=u/o;break;case"%=":o=u%o;break}}return p(s.target,o,l)}case"arrow":return(...o)=>{let u=Object.create(null);return s.params.forEach((f,d)=>u[f]=o[d]),a(s.body,[u,...l])};case"arr":{let o=[];for(let u of s.items){let f=a(u.value,l);u.spread?o.push(...f):o.push(f)}return o}case"obj":{let o={};for(let u of s.props)if(u.spread)Object.assign(o,a(u.value,l));else o[u.key]=a(u.value,l);return o}case"error":return}},c=(s,l)=>{if(s.t!=="member"&&s.t!=="call")return a(s,l);let o=s.t==="member"?s:s.callee.t==="member"?s.callee:null,u,f;if(o){if(u=c(o.obj,l),u===V||o.optional&&u==null)return V;if(f=u[o.computed?a(o.prop,l):o.prop],s===o)return f}else if((f=c(s.callee,l))===V)return V;let d=s;return d.optional&&f==null?V:Reflect.apply(f,u,d.args.map((h)=>a(h,l)))},p=(s,l,o)=>{if(s.t==="id")return i(s.name,l,o);if(s.t==="member"){let u=a(s.obj,o),f=s.computed?a(s.prop,o):s.prop;if(u!=null)u[f]=l;return l}return l};return a(t,[])}var P=null,J=0,X=new Set;function ee(){while(X.size){let t=[...X];X.clear(),J++;try{for(let e of t)!e.disposed&&e.run()}finally{J--}}}function ne(t){J++;try{return t()}finally{J--,!J&&ee()}}function I(t){let e=new Set,n=()=>{if(J){for(let c of e)X.add(c);return}for(let c of[...e])!c.disposed&&c.run()};return[()=>{if(P&&!P.disposed)e.add(P),P.deps.add(e);return t},(c)=>{if(Object.is(c,t))return;t=c,n()},()=>n()]}function A(t){let e={deps:new Set,disposed:!1,run(){if(e.disposed)return;for(let r of e.deps)r.delete(e);e.deps.clear();let n=P;P=e;try{t()}finally{P=n}}};return e.run(),{dispose(){e.disposed=!0;for(let n of e.deps)n.delete(e);e.deps.clear()}}}function k(t){let e=P;P=null;try{return t()}finally{P=e}}var jt=Symbol("lips.reactive"),Y=Symbol("lips.collection"),Pt=new WeakMap,ft=(t)=>t!==null&&typeof t==="object"&&(Array.isArray(t)||Object.getPrototypeOf(t)===Object.prototype),Z=(t)=>t instanceof Map||t instanceof Set||!!(t&&typeof t==="object"&&t[Y]),re=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),se=new Set(["set","delete","clear","add"]),ut=Symbol("lips.keys"),Lt=new WeakMap;function Nt(t,e){let n=t[Y];if(n)return n.notify.add(e),t;let r=Pt.get(t);if(r)return r[Y].notify.add(e),r;let i={raw:t,notify:new Set([e])},a=()=>i.notify.forEach((p)=>p()),c=new Proxy(t,{get(p,s){if(s===Y)return i;let l=p[s];if(typeof l!=="function")return l;if(typeof s==="string"&&se.has(s))return(...f)=>{let d=l.apply(p,f);return a(),d};let o=(f)=>ft(f)?dt(f,a):Z(f)?Nt(f,a):f,u=p instanceof Map;if(s==="get")return(f)=>o(p.get(f));if(s==="forEach")return(f,d)=>p.forEach((h,g)=>f.call(d,o(h),g,c));if(s==="values"||!u&&(s==="keys"||s===Symbol.iterator))return function*(){for(let f of p.values())yield o(f)};if(s==="entries"||u&&s===Symbol.iterator)return u?function*(){for(let[f,d]of p.entries())yield[f,o(d)]}:function*(){for(let f of p.values())yield[o(f),o(f)]};return l.bind(p)}});return Pt.set(t,c),c}function ie(t){let e=Lt.get(t);if(e)return e;let n=new Map,r=(o)=>{let u=n.get(o);if(!u)u=I(0),n.set(o,u);u[0]()},i=(o)=>n.get(o)?.[2](),a=new Map,c=(o)=>{let u=a.get(o);if(!u)u=()=>i(o),a.set(o,u);return u},p=()=>ne(()=>{for(let o of n.values())o[2]()}),s=!1,l=new Proxy(t,{get(o,u){let f=o[u];if(typeof u==="symbol")return f;if(Array.isArray(o)&&re.has(u)&&typeof f==="function")return(...d)=>{s=!0;try{return f.apply(o,d)}finally{s=!1,p()}};if(typeof f==="function")return f;return r(u),ft(f)||Z(f)?dt(f,c(u)):f},set(o,u,f){let d=u in o,h=o[u];if(o[u]=f,s)return!0;if(!Object.is(h,f))i(u);if(!d)i(ut),Array.isArray(o)&&i("length");return!0},deleteProperty(o,u){let f=u in o;if(delete o[u],!s&&f)i(u),i(ut);return!0},has(o,u){return typeof u!=="symbol"&&r(u),u in o},ownKeys(o){return r(ut),Reflect.ownKeys(o)}});return Lt.set(t,l),l}function dt(t,e){if(Z(t))return Nt(t,e);if(!ft(t))return t;return ie(t)}function T(t,e=!1){if(t[jt])return t;let n=new Map,[r,,i]=I(0),a=(c,p)=>{let s=n.get(c);if(!s)s=I(p),n.set(c,s);return s};return new Proxy(t,{get(c,p){if(p===jt)return!0;if(typeof p==="string"){let s=a(p,c[p]);return e?dt(s[0](),s[2]):s[0]()}return c[p]},set(c,p,s){let l=p in c,o=c[p];if(c[p]=s,typeof p!=="string")return!0;l||i();let u=a(p,s);return Object.is(o,s)&&Z(s)?u[2]():u[1](s),!0},has(c,p){return p in c},ownKeys(c){return r(),Reflect.ownKeys(c)},deleteProperty(c,p){let s=p in c;return delete c[p],typeof p==="string"&&n.get(p)?.[1](void 0),s&&i(),!0}})}var Mt=new WeakMap,_t=(t)=>t!==null,oe={__proto__:null,value:(t)=>t??"",checked:_t,selected:_t},ht={clone(t){let e=Mt.get(t);if(!e)e=document.createElement("template"),e.innerHTML=t.html,Mt.set(t,e);return e.content.cloneNode(!0)},fragment:()=>document.createDocumentFragment(),element:(t)=>document.createElement(t),text:(t)=>document.createTextNode(t),marker:(t)=>document.createComment(t),child:(t,e)=>t.childNodes[e],next:(t)=>t.nextSibling,range(t,e){let n=[];for(let r=t;r;r=r.nextSibling)if(n.push(r),r===e)break;return n},insert:(t,e,n)=>{t.insertBefore(e,n)},insertAfter(t,e){let n=t.parentNode;if(!n)return;let r=t;for(let i of e)n.insertBefore(i,r.nextSibling),r=i},remove:(t)=>t.remove(),isElement:(t)=>t.nodeType===1,connected:(t)=>t.isConnected,precedes:(t,e)=>!!(t.compareDocumentPosition(e)&4),attr(t,e,n){n===null?t.removeAttribute(e):t.setAttribute(e,n);let r=oe[e];r&&e in t&&(t[e]=r(n))},setText:(t,e)=>{t.data=e},content:(t,e)=>{t.textContent=e},html:(t,e)=>{t.innerHTML=e},styleVar:(t,e,n)=>n===null?t.style.removeProperty(e):t.style.setProperty(e,n),scope:(t,e)=>{t.hasAttribute("rel")||t.setAttribute("rel",e)},listen(t,e,n){let r=e.split(".")[0],i=e.includes(".outside"),a=i?document:t,c=i||e.includes(".capture"),p=!i&&e.includes(".stop"),s=(l)=>i&&t.contains(l.target)||(p&&l.stopPropagation(),n(l));return a.addEventListener(r,s,c),()=>a.removeEventListener(r,s,c)},keepFocus(){let t=document.activeElement;return()=>{t&&t.isConnected&&t!==document.activeElement&&t.focus()}}};function q(t){let e=t.split("-"),n=[];while(e.length)n.push(e.join("-")),e.pop(),e[e.length-1]?.length===1&&e.pop();return n}function Q(t,e){let n=new Map(Object.entries(t.names).map(([r,i])=>[r.toLowerCase(),i]));for(let r of q(e.toLowerCase()))if(n.has(r))return n.get(r);return t.names[t.default]??""}var N=(t,e)=>t==null?t:("e"in t)?{$:e[t.e]}:t,gt=(t,e)=>({...t,e:e[t.e]});function tt(t,e){switch(t.t){case"macro":return{t:t.t,name:t.name,args:t.args,sets:t.sets.map((n)=>("spread"in n)?{spread:e[n.spread]}:{name:n.name,ci:N(n.ci,e)}),block:M(t.block,e)};case"if":return{t:t.t,branches:t.branches.map((n)=>({when:n.when==null?null:e[n.when],block:M(n.block,e)}))};case"for":return{t:t.t,args:t.args,of:t.of===void 0?void 0:e[t.of],from:N(t.from,e),to:N(t.to,e),by:N(t.by,e),block:M(t.block,e)};case"switch":return{t:t.t,on:e[t.on],cases:t.cases.map((n)=>({is:n.is===null?null:N(n.is,e),block:M(n.block,e)}))};case"async":return{t:t.t,awaitE:e[t.awaitE],then:t.then&&{args:t.then.args,block:M(t.then.block,e)},catch:t.catch&&{args:t.catch.args,block:M(t.catch.block,e)},loading:t.loading&&M(t.loading,e)};case"let":return{t:t.t,const:t.const,vars:Object.fromEntries(Object.entries(t.vars).map(([n,r])=>[n,N(r,e)]))};case"log":return{t:t.t,e:e[t.e]};case"provide":return{t:t.t,vars:Object.fromEntries(Object.entries(t.vars).map(([n,r])=>[n,N(r,e)])),lang:N(t.lang,e),block:M(t.block,e)};case"comp":case"dynamic":return{t:t.t,name:t.t==="comp"?t.name:void 0,tag:t.t==="dynamic"?e[t.tag]:void 0,inputs:Object.fromEntries(Object.entries(t.inputs).map(([n,r])=>[n,N(r,e)])),spreads:t.spreads.map((n)=>e[n]),events:t.events.map((n)=>({name:n.name,e:e[n.e]})),contents:t.contents&&{args:t.contents.args,block:M(t.contents.block,e)}}}}var M=(t,e)=>({html:t.html,scope:t.scope,binds:t.binds.map((n)=>gt(n,e)),blocks:t.blocks.map((n)=>tt(n,e))}),At=(t,e,n,r)=>t.t===n.t&&JSON.stringify(tt(t,e))===JSON.stringify(tt(n,r)),$t=(t,e,n,r)=>JSON.stringify(t.map((i)=>gt(i,e)))===JSON.stringify(n.map((i)=>gt(i,r))),Ht=(t,e,n,r)=>{let i=(a,c)=>JSON.stringify(a.blocks.filter((p)=>p.t==="let").map((p)=>tt(p,c)));return i(t,e)===i(n,r)};function O(t,e=new WeakMap){if(t===null||typeof t!=="object")return t;let n=t;if(e.has(n))return e.get(n);if(Array.isArray(n)){let a=[];e.set(n,a);for(let c of n)a.push(O(c,e));return a}if(n instanceof Map){let a=new Map;return e.set(n,a),n.forEach((c,p)=>a.set(O(p,e),O(c,e))),a}if(n instanceof Set){let a=new Set;return e.set(n,a),n.forEach((c)=>a.add(O(c,e))),a}if(n instanceof Date)return new Date(n.getTime());if(n instanceof RegExp)return new RegExp(n.source,n.flags);if(ArrayBuffer.isView(n))return new n.constructor(n);let r=Object.getPrototypeOf(n);if(r!==Object.prototype&&r!==null)return t;let i=Object.create(r);e.set(n,i);for(let a of Reflect.ownKeys(n)){let c=Object.getOwnPropertyDescriptor(n,a);"value"in c&&(c.value=O(c.value,e)),Object.defineProperty(i,a,c)}return i}var Wt=Symbol("lips.slot"),ae=(t)=>!!t&&typeof t==="object"&&t[Wt]===!0;function Vt(t,e,n){if(!e||typeof t.onInput!=="function")return()=>{};let r=!0,i=!1,a=!0,{dispose:c}=A(()=>{for(let p of Object.keys(e))e[p];if(r){r=!1;return}if(i)return;i=!0,Promise.resolve().then(()=>{if(i=!1,!a)return;k(()=>{try{t.onInput(e)}catch(p){n.onError(p)}})})});return()=>{a=!1,c()}}function Jt(t){let e=!1,n=!1,r=(i)=>typeof t.onError==="function"?t.onError(i):console.error("[lips:ir]",i);return{onError:r,ready(){n=!0},notifyUpdate(){if(!n||e)return;e=!0,Promise.resolve().then(()=>{e=!1;try{typeof t.onUpdate==="function"&&t.onUpdate(),typeof t.onRender==="function"&&t.onRender()}catch(i){r(i)}})}}}var z=[];function yt(){let t=!0;while(t){t=!1;for(let e of[...z].reverse()){if(!e.live())continue;let n=z.indexOf(e);if(n<0)continue;z.splice(n,1),e.fn(),t=!0}}}var Bt=new Map;function ce(t){let e=Bt.get(t);if(!e)e=pt(t).ast,Bt.set(t,e);return e}var G=(t)=>t.join(",");function Ft(t,e,n){let r=e;for(let i of n)r=t.child(r,i);return r}var D=(t,e)=>t.range(e.start,e.end),Dt=(t,e,n,r)=>r===e||t.precedes(e,r)&&t.precedes(r,n);function Kt(t,e){e.gen++;for(let r of e.wiring)r();e.wiring=[];let n=t.fragment();for(let r of D(t,e.inst))t.insert(n,r,null)}function L(t,e,n){return t.insertAfter(e,D(t,n)),z.length&&t.connected(e)&&yt(),n}var mt=(t,e)=>D(t,e).filter((n)=>t.isElement(n));function qt(t,e,n){for(let r of mt(t,e))t.scope(r,n)}function pe(t,e,n,r,i=""){for(let a of e)t.styleVar(a,n,r===null||r===void 0||r===!1?null:r+i)}function Gt(t,e,n,r,i){qt(t,n,r);let a=i.css?e.createStylesheet?.(r,i.css):void 0;return a?()=>a.clear():void 0}function le(t){for(let e of t.bindHandles)e.dispose();for(let e of t.childHandles)e.dispose()}function C(t,e){if(!e)return;le(e);for(let n of D(t,e))t.remove(n,!0)}var Ut=(t,e,n,r)=>{let i=t.self.refs||={},a="",c=()=>{i[a]===e&&delete i[a]},p=r(()=>{c(),i[a=String(n())]=e});return()=>{p.dispose(),c()}},et=(t,e,n,r)=>t.attr(e,n,r==null||r===!1&&!n.startsWith("aria-")?null:r===!0&&!n.startsWith("aria-")?"":String(r)),F=(t,e,n)=>Object.defineProperty(t,e,{get:n,enumerable:!0,configurable:!0}),ue=Symbol.for("lips.self"),zt=Symbol("lips.ctx.layer");function fe(t,e,n,r){for(let i=t;i;i=Object.getPrototypeOf(i)){let c=i[zt]?.get(e);if(c){c(n);return}}r?.(e,n)}function Xt(t,e){let n=new Map,r=(s,...l)=>n.get(s)?.forEach((o)=>o(...l)),i,a=()=>null;return{proto:{[ue]:!0,get node(){let s=a();return s?mt(t,s):[]},get lang(){return e()},pick:(s)=>Q(s,e()),emit:r,emitLocal:r,on(s,l){return n.set(s,[...n.get(s)||[],l]),i},once(s,l){let o=(...u)=>{i.off(s,o),l(...u)};return i.on(s,o)},off(s,l){if(!l)n.delete(s);else{let o=(n.get(s)||[]).filter((u)=>u!==l);o.length?n.set(s,o):n.delete(s)}return i}},bind:(s,l)=>(i=s,a=l,s)}}class nt{ir;options;hooks;live;constructor(t,e,n,r=[]){this.ir=t;this.options=e;this.hooks=n;this.live=r;this.h=e.host||ht}h;pool=null;salvaged=[];withSalvage(t,e){let n=this.pool;this.pool=t;try{return e()}finally{this.pool=n;for(let r of t)!r.claimed&&r.teardown()}}claim(t,e){let n=this.pool?.find((r)=>!r.claimed&&r.name===t&&r.key===e);if(!n)return;return n.claimed=!0,this.salvaged.push(t),n}keyOf(t,e,n){let r=t.key;return r===void 0?void 0:("lit"in r)?r.lit:k(()=>this.runner(r.e,n)(e))}guarded(t){let e=!0;return A(()=>{try{t()}catch(n){this.hooks?this.hooks.onError(n):console.error("[lips:ir]",n)}e?e=!1:this.hooks?.notifyUpdate()})}bindStyle(t,e,n){if(!t.binds.length)return()=>{};let r=mt(this.h,e),i=t.binds.map((a)=>{let c=this.srcRunner(t.exprs[a.e],[]);return this.guarded(()=>pe(this.h,r,a.prop,c(n),a.u))});return()=>{for(let a of i)a.dispose()}}runner(t,e){return this.srcRunner(this.ir.exprs[t],e)}srcRunner(t,e){if(this.options.guard)return this.options.guard.run(t);if(this.options.mode==="interpreted"){let r=ce(t);return(i)=>Ot(r,i)}let n=Tt(t,e);return(r)=>n.run(r)}renderBlock(t,e){let n=this.h,r=n.clone(t),i=new Map,a=t.binds.map((d)=>{let h=Ft(n,r,d.p);return i.set(G(d.p),h),h}),c=t.blocks.map((d)=>{let h=Ft(n,r,d.p);return i.set(G(d.p),h),h}),p=n.marker("^"),s=n.marker("$");n.insert(r,s,null),n.insert(r,p,n.child(r,0));let l=Object.create(e.scope??null),o={...e,scope:l},u={start:p,end:s,block:t,exprs:this.ir.exprs,penv:e,benv:o,pathNodes:i,bindHandles:[],childHandles:[]};t.blocks.forEach((d,h)=>{if(d.t!=="let")return;let g=[];for(let[m,x]of Object.entries(d.vars))if("lit"in x){let[E]=I(x.lit);F(l,m,E)}else{let[E,v]=I(void 0);F(l,m,E);let y=this.runner(x.e,t.scope);g.push(this.guarded(()=>v(y(o))).dispose)}u.childHandles[h]={child:d,exprs:this.ir.exprs,anchor:c[h],dispose:()=>g.forEach((m)=>m())}});let f=(d)=>d.t==="attr"&&d.name==="value";return u.bindHandles=t.binds.map((d,h)=>f(d)?null:this.bindOne(d,a[h],o,t.scope)),t.blocks.forEach((d,h)=>{if(d.t==="let")return;u.childHandles[h]={child:d,exprs:this.ir.exprs,anchor:c[h],dispose:this.execBlock(d,c[h],o,t.scope)}}),t.binds.forEach((d,h)=>{if(f(d))u.bindHandles[h]=this.bindOne(d,a[h],o,t.scope)}),u}bindOne(t,e,n,r,i){let a=this.h;switch(t.t){case"text":{let c=i??a.text("");!i&&a.insertAfter(e,[c]);let p=this.runner(t.e,r),s=t.i18n?this.options.i18n:void 0,l=this.guarded(()=>{let o=p(n),u=o==null?"":String(o);a.setText(c,s?s.translate(u,t.ik,n.lang?.()):u)});return{bind:t,node:e,textNode:c,dispose:l.dispose}}case"attr":{let c=this.runner(t.e,r),p=t.i18n?this.options.i18n:void 0,s=this.guarded(()=>{let l=c(n);et(a,e,t.name,p&&l!=null?p.translate(String(l),t.ik,n.lang?.()):l)});return{bind:t,node:e,dispose:s.dispose}}case"prop":{let c=this.runner(t.e,r);if(t.name==="ref")return{bind:t,node:e,dispose:Ut(n,e,()=>c(n),(s)=>this.guarded(s))};if(t.name==="format"){let s=t.ref||"",l=this.guarded(()=>{let o=c(n),u=this.options.i18n?.format(s,o,n.lang?.());a.content(e,u==null?"":String(u))});return{bind:t,node:e,dispose:l.dispose}}let p=this.guarded(()=>{let s=c(n),l=s==null?"":String(s);t.name==="html"&&a.html?a.html(e,l):a.content(e,l)});return{bind:t,node:e,dispose:p.dispose}}case"event":{let c=this.eventDispatcher(this.ir.exprs[t.e],r,n);return{bind:t,node:e,dispose:a.listen(e,t.name,c)}}case"spread":{let c=this.runner(t.e,r),p=new Set,s=this.guarded(()=>{let l=c(n)||{},o=new Set(Object.keys(l));for(let u of p)!o.has(u)&&a.attr(e,u,null);for(let u of o)et(a,e,u,l[u]);p=o});return{bind:t,node:e,dispose:s.dispose}}}}swapBlock(t,e,n,r){if(t.block.html!==e.html||JSON.stringify(t.block.scope)!==JSON.stringify(e.scope)||!Ht(t.block,t.exprs,e,this.ir.exprs))return this.rebuild(t,e,n,r);if(!$t(t.block.binds,t.exprs,e.binds,this.ir.exprs)){let i=e.binds.map((p)=>t.pathNodes.get(G(p.p)));if(i.some((p)=>!p))return this.rebuild(t,e,n,r);let a=new Map;t.bindHandles.forEach((p)=>p.textNode&&a.set(G(p.bind.p),p.textNode)),t.bindHandles.forEach((p)=>p.dispose());let c=new Set;t.bindHandles=e.binds.map((p,s)=>{let l=G(p.p),o=p.t==="text"?a.get(l):void 0;return o&&c.add(l),this.bindOne(p,i[s],t.benv,e.scope,o)}),a.forEach((p,s)=>!c.has(s)&&this.h.remove(p,!0)),n.push({kind:"binds",path:r})}for(let i=0;i<e.blocks.length;i++){let a=e.blocks[i],c=t.childHandles[i];if(a.t==="let")continue;if(c&&At(c.child,c.exprs,a,this.ir.exprs))continue;let p=this.live.filter((s)=>Dt(this.h,c.anchor,t.childHandles[i+1]?.anchor??t.end,s.anchor));for(let s of p)Kt(this.h,s);c?.dispose(),t.childHandles[i]={child:a,exprs:this.ir.exprs,anchor:c.anchor,dispose:this.withSalvage(p,()=>this.execBlock(a,c.anchor,t.benv,e.scope))},n.push({kind:"block",path:`${r}/${i}`})}return t.block=e,t.exprs=this.ir.exprs,t}rebuild(t,e,n,r){let i=this.live.filter((c)=>Dt(this.h,t.start,t.end,c.anchor));for(let c of i)Kt(this.h,c);let a=this.withSalvage(i,()=>this.renderBlock(e,t.penv));return L(this.h,t.end,a),C(this.h,t),n.push({kind:"skeleton",path:r}),a}execBlock(t,e,n,r){let i=this.h,a=[];switch(t.t){case"if":{let c=t.branches.map((o)=>o.when!=null?this.runner(o.when,r):null),p=null,s=-2,l=this.guarded(()=>{let o=-1;for(let u=0;u<t.branches.length;u++){let f=c[u];if(!f||f(n)){o=u;break}}if(o===s)return;s=o,k(()=>{if(C(i,p),p=null,o>=0)p=L(i,e,this.renderBlock(t.branches[o].block,n))})});a.push(()=>{l.dispose(),C(i,p)});break}case"switch":{let c=this.runner(t.on,r),p=t.cases.map((u)=>u.is&&("e"in u.is)?this.runner(u.is.e,r):null),s=null,l=-2,o=this.guarded(()=>{let u=c(n),f=-1,d=-1;for(let h=0;h<t.cases.length;h++){let g=t.cases[h];if(g.is===null){d=h;continue}let m="lit"in g.is?g.is.lit:p[h](n);if(Array.isArray(m)?m.includes(u):m===u){f=h;break}}if(f===-1)f=d;if(f===l)return;l=f,k(()=>{if(C(i,s),s=null,f>=0)s=L(i,e,this.renderBlock(t.cases[f].block,n))})});a.push(()=>{o.dispose(),C(i,s)});break}case"macro":{let c=Object.create(n.scope??null),p=T({}),s={};for(let f of t.args)s[f]=I(void 0),F(c,f,s[f][0]);let l=t.sets.map((f)=>{if("spread"in f)return{kind:"spread",run:this.runner(f.spread,r)};if("lit"in f.ci){let h=f.ci.lit;return{kind:"value",name:f.name,value:()=>h}}let d=this.runner(f.ci.e,r);return{kind:"value",name:f.name,value:()=>d(n)}}),o=new Set;a.push(this.guarded(()=>{let f={};for(let d of l)if(d.kind==="spread"){let h=d.run(n);if(h&&typeof h==="object")for(let[g,m]of h instanceof Map?h:Object.entries(h))f[g]=m}else f[d.name]=d.value();k(()=>{for(let h of t.args)s[h][1](f[h]);let d=new Set(Object.keys(f));for(let h of o)!d.has(h)&&delete p[h];for(let h of d)p[h]=f[h];o=d})}).dispose);let u=L(i,e,this.renderBlock(t.block,{...n,arguments:p,scope:c}));a.push(()=>C(i,u));break}case"for":this.execFor(t,e,n,r,a);break;case"async":{let c=this.runner(t.awaitE,r),p=null,s=0,l=(u,f)=>{if(C(i,p),p=null,!u)return;let d="block"in u,h=Object.create(n.scope??null);if(d&&u.args[0]!==void 0){let[g]=I(f);F(h,u.args[0],g)}p=L(i,e,this.renderBlock(d?u.block:u,{...n,scope:h}))},o=this.guarded(()=>{let u;try{u=c(n)}catch(d){u=Promise.reject(d)}let f=++s;k(()=>{t.loading?l(t.loading):l(void 0),Promise.resolve(u).then((d)=>f===s&&k(()=>l(t.then,d)),(d)=>f===s&&k(()=>l(t.catch,d)))})});a.push(()=>{s++,o.dispose(),C(i,p)});break}case"provide":{let c=Object.create(n.context??null),p=new Map;Object.defineProperty(c,zt,{value:p});for(let[o,u]of Object.entries(t.vars)){let[f,d]=I("lit"in u?u.lit:void 0);if(F(c,o,f),p.set(o,d),"lit"in u)continue;let h=this.runner(u.e,r);a.push(this.guarded(()=>d(h(n))).dispose)}let s=n.lang;if(t.lang)if("lit"in t.lang){let o=String(t.lang.lit);s=()=>o}else{let[o,u]=I(void 0),f=this.runner(t.lang.e,r);a.push(this.guarded(()=>u(f(n))).dispose),s=()=>o()??n.lang?.()}let l=L(i,e,this.renderBlock(t.block,{...n,context:c,lang:s}));a.push(()=>C(i,l));break}case"log":{let c=lt(this.ir.exprs[t.e]).map((p)=>this.srcRunner(p,r));a.push(this.guarded(()=>console.log(...c.map((p)=>p(n)))).dispose);break}case"comp":{let c=this.options.components?.[t.name];c?this.execComponent(c,t,e,n,r,a,t.name):this.execElement(t,e,n,r,a);break}case"dynamic":{let c=this.runner(t.tag,r),p=[],s=Symbol("init"),l=this.guarded(()=>{let o=c(n);if(o===s)return;s=o,k(()=>{for(let f of p)f();if(p=[],o==null)return;if(ae(o)){let f={};for(let[h,g]of Object.entries(t.inputs)){let m="lit"in g?void 0:this.runner(g.e,r);f[h]=m?()=>m(n):()=>g.lit}let d=L(i,e,o.render(f,n));p.push(()=>C(i,d));return}let u=typeof o==="string"?this.options.components?.[o]:o&&typeof o==="object"?o.ir?o:this.options.resolveTemplate?.(o):void 0;if(u)this.execComponent(u,t,e,n,r,p,typeof o==="string"?o:"#dynamic");else if(typeof o==="string")this.execElement({...t,name:o},e,n,r,p)})});a.push(()=>{l.dispose();for(let o of p)o()});break}}return()=>a.forEach((c)=>c())}execFor(t,e,n,r,i){let a=this.h,c=t.of!==void 0?this.runner(t.of,r):null,p=t.by&&"e"in t.by?this.runner(t.by.e,r):null,s=t.by&&"lit"in t.by?String(t.by.lit).split("."):null,l=(g,m)=>g===void 0?void 0:("lit"in g)?g.lit:this.runner(g.e,r)(m),o=[],u=0,f=new Map,d=()=>{if(c===null){let x=Number(l(t.from,n)??0),E=Number(l(t.to,n)??x),v=x<=E,y=[];for(let R=x;v?R<=E:R>=E;v?R++:R--)y.push({key:R,values:[R]});return y}let g=c(n),m=(x,E,v)=>{if(p){let y=p(n);return typeof y==="function"?y(x,v):E}if(s)return s.reduce((y,R)=>y?.[R],x);return E};if(Array.isArray(g))return g.map((x,E)=>({key:m(x,E,E),values:[x,E]}));if(g instanceof Map)return[...g.entries()].map(([x,E],v)=>({key:x,values:[x,E,v]}));if(g instanceof Set)return[...g].map((x,E)=>({key:m(x,x,E),values:[x,E]}));if(g&&typeof g==="object")return Object.entries(g).map(([x,E],v)=>({key:x,values:[x,E,v]}));return[]},h=this.guarded(()=>{let g=d();k(()=>{let m=new Set,x=[],E=++u;for(let y of g){let R=y.key;if(m.has(R))console.warn(`<for> duplicate key '${String(R)}' — falling back to positional identity`),R=`#dup:${x.length}`;m.add(R);let K=f.get(R);if(K)K.sigs.forEach(([H,_,U],w)=>{let j=y.values[w];Object.is(H(),j)&&typeof j==="object"&&j!==null?U():_(j)}),K.pass=E,x.push(K);else{let H=Object.create(n.scope??null),_=y.values.map((j)=>I(j));t.args.forEach((j,S)=>_[S]&&F(H,j,_[S][0]));let U=this.renderBlock(t.block,{...n,scope:H}),w={key:R,sigs:_,inst:U,pass:E};f.set(R,w),x.push(w)}}for(let y of o)if(y.pass!==E)f.delete(y.key),C(a,y.inst);let v=e;for(let y of x){if(a.next(v)!==y.inst.start)L(a,v,y.inst);v=y.inst.end}o=x})});i.push(()=>{h.dispose();for(let g of o)C(a,g.inst);o=[],f.clear()})}wireInputs(t,e,n,r,i,a){for(let[c,p]of Object.entries(t.inputs))if(a?.add(c),"lit"in p)r[c]=p.lit;else{let s=this.runner(p.e,n);i.push(this.guarded(()=>r[c]=s(e)).dispose)}for(let c of t.spreads){let p=this.runner(c,n);i.push(this.guarded(()=>{let s=p(e)||{};k(()=>Object.entries(s).forEach(([l,o])=>{a?.add(l),r[l]=o}))}).dispose)}}wireEvents(t,e,n,r,i){t?.forEach((a)=>{let c=this.eventDispatcher(this.ir.exprs[a.e],n,e);r.on(a.name,c),i.push(()=>r.off(a.name,c))})}slotRenderer(t,e){let n=this;return{[Wt]:!0,args:t.args,render(r,i){let a=Object.create(e.scope??null);return t.args.forEach((c)=>F(a,c,r?.[c]??(()=>{return}))),n.renderBlock(t.block,i?{...e,scope:a,context:i.context,lang:i.lang}:{...e,scope:a})}}}adoptComponent(t,e,n,r,i,a){let c=[],p=new Set;if(this.wireInputs(e,r,i,t.input,c,p),e.contents)t.input.renderer=this.slotRenderer(e.contents,r),p.add("renderer");for(let l of Object.keys(t.input))!p.has(l)&&delete t.input[l];this.wireEvents(e.events,r,i,t.self,c),t.wiring=c,t.anchor=n;let s=t.gen;L(this.h,n,t.inst),a.push(()=>{if(s!==t.gen)return;for(let l of t.wiring)l();t.wiring=[],t.teardown()})}execComponent(t,e,n,r,i,a,c){let p=this.pool?.length?this.claim(c,this.keyOf(e.inputs,r,i)):void 0;if(p)return this.adoptComponent(p,e,n,r,i,a);let s=T({}),l=[];if(this.wireInputs(e,r,i,s,l),e.contents)s.renderer=this.slotRenderer(e.contents,r);let o=T(O(t.state||{}),t.deep??!1),u=O(t.statics??{}),f=null,d=this,h=Xt(this.h,()=>r.lang?.()??d.options.i18n?.lang()??""),g=h.bind(Object.assign(Object.create(h.proto),{...this.options.expose||{},state:o,input:s,static:u,context:r.context,refs:{},setContext(S,B){let W=(ot,at)=>fe(r.context,ot,at,d.options.expose?.setContext);typeof S==="string"?W(S,B):Object.entries(S||{}).forEach(([ot,at])=>W(ot,at))}}),()=>f);t.handlers&&Object.entries(t.handlers).forEach(([S,B])=>g[S]=B.bind(g)),this.wireEvents(e.events,r,i,g,l);let m=Jt(g);try{typeof g.onCreate==="function"&&g.onCreate()}catch(S){m.onError(S)}try{Object.keys(s).length&&typeof g.onInput==="function"&&g.onInput(s)}catch(S){m.onError(S)}let x=Vt(g,s,m),E={state:o,input:s,context:r.context,lang:r.lang,static:u,self:g,scope:void 0},v=new nt(t.ir,this.options,m),y=v.renderBlock(t.ir.root,E);f=y;let R=t.stylesheet?Gt(this.h,this.options,y,t.stylesheet.nsp||t.nsp||"lips",t.stylesheet):void 0,K=t.stylesheet?v.bindStyle(t.stylesheet,y,E):void 0;L(this.h,n,y),m.ready();try{typeof g.onMount==="function"&&g.onMount(),typeof g.onRender==="function"&&g.onRender(),g.emit("component:mount")}catch(S){m.onError(S)}let H;if(t.context?.length&&typeof g.onContext==="function"){let S=!0,{dispose:B}=A(()=>{for(let W of t.context)E.context?.[W];if(S){S=!1;return}k(()=>{try{g.onContext()}catch(W){m.onError(W)}})});H=B}let _=!1;z.push({live:()=>this.h.connected(y.start),fn:()=>{_=!0;try{typeof g.onAttach==="function"&&g.onAttach(),g.emit("component:attached")}catch(S){m.onError(S)}}}),this.h.connected(y.start)&&yt();let U=!1,w={name:c,key:s.key,self:g,input:s,inst:y,anchor:n,wiring:l,gen:0,claimed:!1,teardown:()=>{if(U)return;U=!0;let S=this.live.indexOf(w);S>-1&&this.live.splice(S,1),H?.(),x(),K?.(),R?.(),C(this.h,y);try{if(_)typeof g.onDetach==="function"&&g.onDetach(),g.emit("component:detached");typeof g.onDestroy==="function"&&g.onDestroy(),g.emit("component:destroy")}catch(B){m.onError(B)}}};this.live.push(w);let j=w.gen;a.push(()=>{if(j!==w.gen)return;for(let S of w.wiring)S();w.wiring=[],w.teardown()})}execElement(t,e,n,r,i){let a=this.h,c=a.element(t.name);for(let[p,s]of Object.entries(t.inputs))if(p==="@ref"){let l="lit"in s?()=>s.lit:this.runner(s.e,r);i.push(Ut(n,c,()=>l(n),(o)=>this.guarded(o)))}else if(p[0]==="@")i.push(this.contentOf(c,p,s,n,r));else if("lit"in s)et(a,c,p,s.lit);else{let l=this.runner(s.e,r);i.push(this.guarded(()=>et(a,c,p,l(n))).dispose)}for(let p of t.events)i.push(a.listen(c,p.name,this.eventDispatcher(this.ir.exprs[p.e],r,n)));if(t.contents){let p=this.renderBlock(t.contents.block,n);for(let s of D(a,p))a.insert(c,s,null);i.push(()=>C(a,p))}a.insertAfter(e,[c]),i.push(()=>a.remove(c,!0))}contentOf(t,e,n,r,i){let a=this.h;if(e==="@format"){let{ref:p,e:s}="lit"in n?n.lit:{},l=s===void 0?()=>({}):this.runner(s,i);return this.guarded(()=>{let o=this.options.i18n?.format(p||"",l(r),r.lang?.());a.content(t,o==null?"":String(o))}).dispose}let c="lit"in n?()=>n.lit:this.runner(n.e,i);return this.guarded(()=>{let p=c(r),s=p==null?"":String(p);e==="@html"&&a.html?a.html(t,s):a.content(t,s)}).dispose}eventDispatcher(t,e,n){let r=lt(t),i=/^[A-Za-z_$][\w$]*$/.test(r[0]||"")&&!e.includes(r[0]);return(...a)=>k(()=>{let c=(l)=>{if(i&&n.self&&!this.options.guard?.self(l)&&typeof n.self[l]==="function")return n.self[l];try{return this.srcRunner(l,e)(n)}catch(o){return}};if(!r.length)return;let p=c(r[0]);if(typeof p!=="function")return;let s=(l)=>this.hooks?this.hooks.onError(l):console.error("[lips:ir]",l);try{let l=r.slice(1).map((u)=>this.srcRunner(u,e)(n)),o=p(...l,...a);o&&typeof o.then==="function"&&o.then(void 0,s)}catch(l){s(l)}})}}function xt(t,e={},n={}){let r=n.host||ht,i=T(e.state||{},e.deep??!1),a=T(e.input||{},e.deep??!1),c=e.static||{},p=null,s=Xt(r,()=>n.i18n?.lang()??""),l=s.bind(Object.assign(Object.create(s.proto),{state:i,input:a,static:c,refs:{},...n.expose||{},...e.expose||{}}),()=>p);e.handlers&&Object.entries(e.handlers).forEach(([v,y])=>l[v]=y.bind(l));let o={state:i,input:a,context:e.context,static:c,self:l,scope:void 0},u=Jt(l);try{typeof l.onCreate==="function"&&l.onCreate()}catch(v){u.onError(v)}try{Object.keys(a).length&&typeof l.onInput==="function"&&l.onInput(a)}catch(v){u.onError(v)}let f=Vt(l,a,u),d=new nt(t,n,u),h=d.renderBlock(t.root,o);p=h,u.ready();let g=e.stylesheet?Gt(r,n,h,e.stylesheet.nsp||e.nsp||"lips",e.stylesheet):void 0,m=e.stylesheet?d.bindStyle(e.stylesheet,h,o):void 0;try{typeof l.onMount==="function"&&l.onMount(),typeof l.onRender==="function"&&l.onRender()}catch(v){u.onError(v)}let x=!1,E=()=>{if(x)return;x=!0;try{typeof l.onAttach==="function"&&l.onAttach(),l.emit("component:attached")}catch(v){u.onError(v)}};return{state:i,self:l,get nodes(){return D(r,h)},mount(v){for(let y of D(r,h))r.insert(v,y,null);if(r.connected(h.start))E(),yt()},swap(v){let y=[],R=r.keepFocus?.();if(d=new nt(v,n,u,d.live),h=d.swapBlock(h,v.root,y,"root"),p=h,e.stylesheet)qt(r,h,e.stylesheet.nsp||e.nsp||"lips"),m?.(),m=d.bindStyle(e.stylesheet,h,o);return R?.(),{changes:y,salvaged:d.salvaged}},dispose(){f(),m?.(),g?.(),C(r,h);try{if(x)typeof l.onDetach==="function"&&l.onDetach(),l.emit("component:detached");typeof l.onDestroy==="function"&&l.onDestroy()}catch(v){u.onError(v)}}}}class rt{options={emit:!0};__events={};__once_events={};constructor(t){if(t)this.options=t}on(t,e){if(!Array.isArray(this.__events[t]))this.__events[t]=[];return this.__events[t].push(e),this}once(t,e){if(!Array.isArray(this.__once_events[t]))this.__once_events[t]=[];return this.__once_events[t].push(e),this}off(t,e){if(e){if(Array.isArray(this.__events[t]))this.__events[t]=this.__events[t].filter((n)=>n!==e),!this.__events[t].length&&delete this.__events[t];if(Array.isArray(this.__once_events[t]))this.__once_events[t]=this.__once_events[t].filter((n)=>n!==e),!this.__once_events[t].length&&delete this.__once_events[t]}else delete this.__events[t],delete this.__once_events[t];return this}emit(t,...e){if(!this.options.emit)return;let n=(i)=>{if(!i||typeof i!=="object")return i;if(typeof i.toJSON==="function")return i.toJSON();if(Array.isArray(i))return i.map(n);if(i.constructor===Object||i.constructor===void 0){let a={};for(let c in i)a[c]=n(i[c]);return a}return i},r=e.map(n);this.__events[t]?.forEach((i)=>i(...r)),this.__once_events[t]?.forEach((i)=>i(...r)),delete this.__once_events[t]}}class st{nsp;settings;constructor(t,e){if(typeof t!=="string"||!t)throw Error("Undefined or invalid stylesheet namespace");this.nsp=t,this.settings=e||{},this.settings.sheet&&this.load(this.settings)}get rel(){return`${this.settings.meta?"@":""}${this.nsp}`}get styleElement(){return document.head.querySelector(`style[rel="${this.rel.replace(/["\\]/g,"\\$&")}"]`)}load(t){if(this.settings=t,!t.sheet)return;let e=this.styleElement;if(e)return e.setAttribute("dindex",String(Number(e.getAttribute("dindex")||0)+1)),e;let n=document.createElement("style");return n.setAttribute("rel",this.rel),n.setAttribute("dindex","0"),n.textContent=t.sheet,t.meta?document.head.prepend(n):document.head.appendChild(n),n}clear(){let t=this.styleElement;if(!t)return;let e=Number(t.getAttribute("dindex")||0);e<=0?t.remove():t.setAttribute("dindex",String(e-1))}}var de="en-US";class it{engine;currentLang;DICTIONARIES={};functions;onMissing;onError;onChange;loader;loading=new Map;formatters=new Map;constructor(t,e){this.engine=e;this.currentLang=t||typeof navigator<"u"&&navigator.language||de,this.functions={...e?.functions}}set lang(t){if(this.currentLang===t)return;this.currentLang=t}get lang(){return this.currentLang}setDictionary(t,e){if(!this.engine)throw Error(`[lips:i18n] <${t}> dictionary without a MessageFormat engine — pass \`messageFormat\` from '@lipsjs/lips/i18n' to new Lips()`);this.DICTIONARIES[t.toLowerCase()]=e,this.formatters.clear(),this.onChange?.()}has(t){return q(t.toLowerCase()).some((e)=>!!this.DICTIONARIES[e])}setLoader(t){return this.loader=t,this}load(t){return Promise.all(q(t).map((e)=>{let n=e.toLowerCase();if(this.DICTIONARIES[n]||!this.loader)return;let r=this.loading.get(n);if(!r)r=this.loader(e).then((i)=>{i&&this.setDictionary(e,i)}).catch((i)=>console.warn(`[lips:i18n] <${e}> dictionary failed to load —`,i)),this.loading.set(n,r);return r})).then(()=>{})}message(t,e){let n=`${e}
|
|
3
|
+
${t}`;if(this.formatters.has(n))return this.formatters.get(n);let r;for(let i of q(e.toLowerCase())){let a=this.DICTIONARIES[i];if(!a||!Object.prototype.hasOwnProperty.call(a,t))continue;try{r=new this.engine.MessageFormat(e,a[t],{functions:this.functions})}catch(c){this.onError?.(c,t,e),r=null}break}return r!==void 0&&this.formatters.set(n,r),r}translate(t,e,n){let r=e||this.currentLang,i=n||t,a=this.message(i,r);if(a)t=a.format(void 0,(c)=>this.onError?.(c,i,r));else if(a===void 0&&n)this.onMissing?.(n,r);return{text:t,lang:r}}format(t,e,n){let r=n||this.currentLang,i=this.message(t,r);if(i)return i.format(e,(a)=>this.onError?.(a,t,r));i===void 0&&this.onMissing?.(t,r)}pick(t,e){return Q(t,e||this.currentLang)}}var vt=null;var Et=null;var he;var ge={};var ye=null;var me=["state","input","static","context","emit","on","once","off","node","lang","setContext","setLanguage","destroy","appendTo","prependTo","replaceWith","render","swap"],xe=new Set(me);function St(t){if(!t)return;for(let e of Object.keys(t))if(xe.has(e))throw Error(`Handler <${e}> is a reserved component member name`);return t}class Yt extends rt{lips;template;state;instance;contextWatcher;destroyed=!1;constructor(t,e,n,r,i,a){super();this.lips=t;this.template=n;let c=St(n.handler);this.state=T(O(n.state||{}),!0);let p=T({...r},!0),s=(o,...u)=>super.emit(o,...u);this.instance=xt(i,{state:this.state,input:p,context:t.getContext(),static:O(n.static??n._static),handlers:c,deep:!0,stylesheet:t.styleFor(e,n),nsp:e,expose:{emit(o,...u){this.emitLocal?.(o,...u),s(o,...u)},context:t.getContext()}},a);let l=n.watchContext;if(l?.length&&typeof c?.onContext==="function")this.contextWatcher=t.watchContext(l,()=>{try{c.onContext.call(this.instance.self)}catch(o){console.error("[lips:ir]",o)}});this.emit("component:mount")}emit(t,...e){return this.instance?.self?.emitLocal?.(t,...e),super.emit(t,...e)}get node(){return this.instance.nodes.filter((t)=>t.nodeType===1)}appendTo(t){let e=typeof t==="string"?document.querySelector(t):t;return e&&this.instance.mount(e),this}swap(t){return this.instance.swap(t)}destroy(){if(this.destroyed)return;this.destroyed=!0,this.contextWatcher?.(),this.instance.dispose(),this.emit("component:destroy")}}class bt{config;debug;store=new Map;plugins=new Map;irCache=new WeakMap;defCache=new WeakMap;styleCache=new WeakMap;context;__root;u;i18n;getLang;setLang;getRev;componentsProxy;constructor(t){this.config=t;if(this.u=t?.untrusted,this.debug=!!t?.debug,this.context=T({...t?.context||{}},!0),this.i18n=new it(t?.lang,t?.messageFormat??he),this.debug)this.i18n.onMissing=(c,p)=>console.warn(`[lips:i18n] no <${p}> entry for key "${c}"`),this.i18n.onError=(c,p,s)=>console.warn(`[lips:i18n] <${s}> message "${p}" —`,c);let[e,n]=I(this.i18n.lang);this.getLang=e,this.setLang=n;let[r,i]=I(0);this.getRev=r,this.i18n.onChange=()=>i(r()+1),vt&&Object.entries(ge).forEach(([c,p])=>this.register(c,p));let a=this;this.componentsProxy=new Proxy({},{get(c,p){let s=a.store.get(p);return s?a.defFor(p,s):void 0},has(c,p){return a.store.has(p)}})}register(t,e){let n=ye?.(t);if(n)throw Error(`[lips] <${t}> is ${n}: the compiler reads the tag as one, so a component of that name never renders. Register it under another name`);return St(e.handler),this.store.set(t,e),this}use(t,e){let n=this.plugins.get(t.name);if(n&&n!==t)throw Error(`[lips] two plugins named <${t.name}>: one is installed already`);if(n)return this;this.plugins.set(t.name,t),t.requires?.forEach((r)=>this.use(r));for(let[r,i]of Object.entries(t.components||{})){let a=this.store.get(r);if(a&&a!==i)throw Error(`[lips] <${r}> of plugin <${t.name}> is registered already, by something else`);this.register(r,i)}return t.install?.(this,e),this}unregister(t){return this.store.delete(t),this}has(t){return this.store.has(t)}compile(t){if(t.ir)return t.ir;let e=this.irCache.get(t);if(!e){if(!vt)throw Error("This build has no template compiler — templates must be precompiled to `ir` "+'(import from "@lipsjs/lips" instead of "@lipsjs/lips/runtime")');let n=vt(t.default||"",{macros:t.macros,check:this.u?.check});n.diagnostics.length&&console.warn("[lips:ir] template diagnostics —",n.diagnostics),e=n.ir,this.irCache.set(t,e)}return e}styleFor(t,e){if(e.style)return e.style;if(!e.stylesheet)return;if(!Et){console.warn(`[lips:ir] <${t}> stylesheet skipped — this build has no style compiler. `+'Precompile it to StyleIR, or import "@lipsjs/lips" instead of "@lipsjs/lips/runtime".');return}let n=this.styleCache.get(e);if(!n){let r=(this.u?this.u.style(Et):Et)(e.stylesheet,{nsp:t,layer:this.config?.styleLayer,preprocess:this.config?.stylePreprocessor});r.diagnostics.length&&console.warn("[lips:ir] style diagnostics —",r.diagnostics),n=r.ir,this.styleCache.set(e,n)}return n}unnamed(t){let e=this.anonymous.get(t);return!e&&this.anonymous.set(t,e=`dynamic-${++this.anonymousCount}`),e}anonymous=new WeakMap;anonymousCount=0;defFor(t,e){let n=this.defCache.get(e);if(!n)n={ir:this.compile(e),state:e.state,statics:e.static??e._static,context:e.watchContext,stylesheet:this.styleFor(t,e),nsp:t,handlers:St(e.handler),deep:!0},this.defCache.set(e,n);return n}render(t,e,n){let r={mode:this.config?.mode,components:this.componentsProxy,resolveTemplate:(i)=>i&&(typeof i.default==="string"||i.ir)?this.defFor(i.name||this.unnamed(i),i):void 0,expose:{setContext:(i,a)=>this.setContext(i,a),setLanguage:(i)=>this.setLanguage(i)},createStylesheet:(i,a)=>{let c=new st(i,{sheet:a});return{clear:()=>c.clear()}},i18n:{translate:(i,a,c)=>{let p=this.getLang();return this.getRev(),this.i18n.translate(i,c||p,a).text},format:(i,a,c)=>{let p=this.getLang();return this.getRev(),this.i18n.format(i,a,c||p)??""},lang:()=>this.getLang()}};return new Yt(this,t,e,n,this.compile(e),this.u?this.u.runtime(r):r)}root(t,e){let n=this.render("__ROOT__",t);return this.__root=n,n.appendTo(e),n}setLanguage(t){return this.i18n.lang=t,this.setLang(t),this.i18n.load(t),this}getLanguage(){return this.getLang()}useTranslator(t,e){let n=!0,{dispose:r}=A(()=>{let i=this.getLang();if(n){n=!1;return}(t==="*"||Array.isArray(t)&&t.includes(i))&&e(i)});return r}get ctx(){return this.context}getContext(){return this.context}setContext(t,e){typeof t==="string"?this.ctx[t]=e:Object.entries(t).forEach(([n,r])=>this.ctx[n]=r)}watchContext(t,e){let n=!0,{dispose:r}=A(()=>{t.forEach((i)=>this.ctx[i]),n?n=!1:e()});return r}useContext(t,e){return this.watchContext(t,()=>e(Object.fromEntries(t.map((n)=>[n,this.ctx[n]]))))}dispose(){this.__root?.destroy()}}function ve(t){return t?t:(e)=>e}var Ye=bt;export{ve as component,Ye as default,A as effect,T as reactive,xt as renderIR,I as signal,k as untrack};
|
|
4
4
|
|
|
5
|
-
//# debugId=
|
|
5
|
+
//# debugId=6531CAC0F96F11C964756E2164756E21
|