@lipsjs/lips 0.2.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.
Files changed (48) hide show
  1. package/README.md +68 -1
  2. package/dist/lips.js +3532 -1094
  3. package/dist/lips.js.map +44 -19
  4. package/dist/lips.min.js +13 -9
  5. package/dist/lips.min.js.map +44 -19
  6. package/dist/lynx.min.js +51 -0
  7. package/dist/lynx.min.js.map +17 -0
  8. package/dist/mf2.min.js +4 -0
  9. package/dist/mf2.min.js.map +38 -0
  10. package/dist/precompile.min.js +19 -16
  11. package/dist/precompile.min.js.map +7 -6
  12. package/dist/runtime.min.js +4 -3
  13. package/dist/runtime.min.js.map +13 -12
  14. package/dist/stylis.min.js +3 -0
  15. package/dist/stylis.min.js.map +16 -0
  16. package/dist/types/i18n/engine.d.ts +14 -0
  17. package/dist/types/i18n/index.d.ts +122 -5
  18. package/dist/types/i18n/intl.d.ts +1 -0
  19. package/dist/types/i18n/lookup.d.ts +22 -0
  20. package/dist/types/ir/compiler.d.ts +75 -2
  21. package/dist/types/ir/expression.d.ts +32 -3
  22. package/dist/types/ir/facade.d.ts +74 -30
  23. package/dist/types/ir/host.d.ts +75 -0
  24. package/dist/types/ir/index.d.ts +5 -2
  25. package/dist/types/ir/policy.d.ts +95 -0
  26. package/dist/types/ir/runtime.d.ts +54 -19
  27. package/dist/types/ir/signal.d.ts +6 -4
  28. package/dist/types/ir/style.d.ts +119 -0
  29. package/dist/types/ir/swap.d.ts +5 -0
  30. package/dist/types/ir/tree.d.ts +51 -0
  31. package/dist/types/lips.d.ts +20 -3
  32. package/dist/types/lynx/a11y.d.ts +61 -0
  33. package/dist/types/lynx/background.d.ts +71 -0
  34. package/dist/types/lynx/main.d.ts +46 -0
  35. package/dist/types/lynx/protocol.d.ts +52 -0
  36. package/dist/types/lynx/style.d.ts +49 -0
  37. package/dist/types/lynx/template.d.ts +37 -0
  38. package/dist/types/lynx.d.ts +22 -0
  39. package/dist/types/mf2.d.ts +14 -0
  40. package/dist/types/precompile.d.ts +30 -5
  41. package/dist/types/runtime.d.ts +1 -1
  42. package/dist/types/stylesheet.d.ts +12 -16
  43. package/dist/types/stylis.d.ts +2 -0
  44. package/dist/types/types.d.ts +138 -11
  45. package/dist/types/untrusted.d.ts +17 -0
  46. package/dist/untrusted.min.js +5 -0
  47. package/dist/untrusted.min.js.map +13 -0
  48. package/package.json +25 -3
@@ -1,4 +1,5 @@
1
- var OJ=["===","!==","...","=>","==","!=","<=",">=","&&","||","??","?.","++","--","+=","-=","*=","/=","%=","+","-","*","/","%","<",">","!","?",":",".",",","(",")","[","]","{","}","="];function BJ(J,Q){let X=[],Z=0,z=(V)=>/[A-Za-z_$]/.test(V),W=(V)=>/[A-Za-z0-9_$]/.test(V);while(Z<J.length){let V=J[Z];if(/\s/.test(V)){Z++;continue}if(/[0-9]/.test(V)||V==="."&&/[0-9]/.test(J[Z+1])){let Y=Z;while(Z<J.length&&/[0-9]/.test(J[Z]))Z++;if(J[Z]==="."){Z++;while(Z<J.length&&/[0-9]/.test(J[Z]))Z++}if(J[Z]==="e"||J[Z]==="E"){if(Z++,J[Z]==="+"||J[Z]==="-")Z++;while(Z<J.length&&/[0-9]/.test(J[Z]))Z++}X.push({t:"num",value:J.slice(Y,Z),start:Y,end:Z});continue}if(V==="'"||V==='"'){let Y=Z;Z++;let $="",F=!1;while(Z<J.length){let D=J[Z];if(D==="\\"){let U=J[Z+1],K={n:`
2
- `,t:"\t",r:"\r",b:"\b",f:"\f",v:"\v","0":"\x00"};if(U==="u"){let M=J.slice(Z+2,Z+6);$+=String.fromCharCode(parseInt(M,16)||0),Z+=6}else $+=K[U]??U,Z+=2;continue}if(D===V){F=!0,Z++;break}$+=D,Z++}if(!F)Q.push({code:"LIPS-E001",message:"Unterminated string literal",loc:{offset:Y,length:Z-Y}});X.push({t:"str",value:$,start:Y,end:Z});continue}if(z(V)){let Y=Z;while(Z<J.length&&W(J[Z]))Z++;X.push({t:"id",value:J.slice(Y,Z),start:Y,end:Z});continue}let q=OJ.find((Y)=>J.startsWith(Y,Z));if(q==="?."&&/[0-9]/.test(J[Z+2]??""))q="?";if(q){X.push({t:"punct",value:q,start:Z,end:Z+q.length}),Z+=q.length;continue}Q.push({code:"LIPS-E002",message:`Unexpected character '${V}'`,loc:{offset:Z,length:1}}),Z++}return X.push({t:"eof",value:"",start:J.length,end:J.length}),X}class QJ{tokens;diagnostics;pos=0;constructor(J,Q){this.tokens=J;this.diagnostics=Q}peek(J=0){return this.tokens[Math.min(this.pos+J,this.tokens.length-1)]}next(){return this.tokens[this.pos++]??this.tokens[this.tokens.length-1]}at(J){let Q=this.peek();return Q.t==="punct"&&Q.value===J}eat(J){if(this.at(J))return this.pos++,!0;return!1}error(J,Q,X=this.peek()){return this.diagnostics.push({code:J,message:Q,loc:{offset:X.start,length:Math.max(1,X.end-X.start)}}),{t:"error"}}expect(J,Q){if(!this.eat(J))this.error(Q,`Expected '${J}'`)}parse(){let J=this.assign();if(this.peek().t!=="eof")this.error("LIPS-E003",`Unexpected token '${this.peek().value}' after expression`);return J}isArrowAhead(){let J=this.peek();if(J.t==="id"){let Q=this.peek(1);return Q.t==="punct"&&Q.value==="=>"}if(J.t==="punct"&&J.value==="("){let Q=0,X=0;while(!0){let Z=this.peek(X);if(Z.t==="eof")return!1;if(Z.t==="punct"&&Z.value==="(")Q++;if(Z.t==="punct"&&Z.value===")"){if(Q--,Q===0){let z=this.peek(X+1);return z.t==="punct"&&z.value==="=>"}}X++}}return!1}assign(){if(this.isArrowAhead()){let X=[];if(this.peek().t==="id")X.push(this.next().value);else{this.expect("(","LIPS-E004");while(!this.at(")")&&this.peek().t!=="eof"){let Z=this.next();if(Z.t!=="id")return this.error("LIPS-E005","Invalid arrow parameter",Z);if(X.push(Z.value),!this.eat(","))break}this.expect(")","LIPS-E004")}return this.expect("=>","LIPS-E004"),{t:"arrow",params:X,body:this.assign()}}let J=this.conditional(),Q=this.peek();if(Q.t==="punct"&&["=","+=","-=","*=","/=","%="].includes(Q.value)){if(J.t!=="id"&&J.t!=="member")return this.error("LIPS-E006","Invalid assignment target",Q);return this.next(),{t:"assign",op:Q.value,target:J,value:this.assign()}}return J}conditional(){let J=this.nullish();if(this.eat("?")){let Q=this.assign();return this.expect(":","LIPS-E007"),{t:"cond",test:J,cons:Q,alt:this.assign()}}return J}nullish(){let J=this.or();while(this.at("??"))this.next(),J={t:"logic",op:"??",l:J,r:this.or()};return J}or(){let J=this.and();while(this.at("||"))this.next(),J={t:"logic",op:"||",l:J,r:this.and()};return J}and(){let J=this.equality();while(this.at("&&"))this.next(),J={t:"logic",op:"&&",l:J,r:this.equality()};return J}equality(){let J=this.relational();while(["===","!==","==","!="].some((Q)=>this.at(Q)))J={t:"bin",op:this.next().value,l:J,r:this.relational()};return J}relational(){let J=this.additive();while(["<=",">=","<",">"].some((Q)=>this.at(Q)))J={t:"bin",op:this.next().value,l:J,r:this.additive()};return J}additive(){let J=this.multiplicative();while(this.at("+")||this.at("-"))J={t:"bin",op:this.next().value,l:J,r:this.multiplicative()};return J}multiplicative(){let J=this.unary();while(this.at("*")||this.at("/")||this.at("%"))J={t:"bin",op:this.next().value,l:J,r:this.unary()};return J}unary(){if(this.at("!")||this.at("-")||this.at("+"))return{t:"unary",op:this.next().value,arg:this.unary()};if(this.at("++")||this.at("--")){let J=this.next().value,Q=this.unary();if(Q.t!=="id"&&Q.t!=="member")return this.error("LIPS-E006","Invalid update target");return{t:"update",op:J,arg:Q,prefix:!0}}return this.postfix()}postfix(){let J=this.callMember();if(this.at("++")||this.at("--")){let Q=this.next().value;if(J.t!=="id"&&J.t!=="member")return this.error("LIPS-E006","Invalid update target");J={t:"update",op:Q,arg:J,prefix:!1}}return J}callMember(){let J=this.primary();while(!0)if(this.eat(".")){let Q=this.next();if(Q.t!=="id")return this.error("LIPS-E008","Expected property name",Q);J={t:"member",obj:J,prop:Q.value,computed:!1,optional:!1}}else if(this.eat("?."))if(this.at("("))J={t:"call",callee:J,args:this.argList(),optional:!0};else if(this.eat("[")){let Q=this.assign();this.expect("]","LIPS-E009"),J={t:"member",obj:J,prop:Q,computed:!0,optional:!0}}else{let Q=this.next();if(Q.t!=="id")return this.error("LIPS-E008","Expected property name",Q);J={t:"member",obj:J,prop:Q.value,computed:!1,optional:!0}}else if(this.eat("[")){let Q=this.assign();this.expect("]","LIPS-E009"),J={t:"member",obj:J,prop:Q,computed:!0,optional:!1}}else if(this.at("("))J={t:"call",callee:J,args:this.argList(),optional:!1};else break;return J}argList(){this.expect("(","LIPS-E010");let J=[];while(!this.at(")")&&this.peek().t!=="eof")if(J.push(this.assign()),!this.eat(","))break;return this.expect(")","LIPS-E010"),J}primary(){let J=this.peek();if(J.t==="num")return this.next(),{t:"lit",v:parseFloat(J.value)};if(J.t==="str")return this.next(),{t:"lit",v:J.value};if(J.t==="id")switch(this.next(),J.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:J.value}}if(this.eat("(")){let Q=this.assign();return this.expect(")","LIPS-E010"),Q}if(this.eat("[")){let Q=[];while(!this.at("]")&&this.peek().t!=="eof"){let X=this.eat("...");if(Q.push({spread:X||void 0,value:this.assign()}),!this.eat(","))break}return this.expect("]","LIPS-E009"),{t:"arr",items:Q}}if(this.eat("{")){let Q=[];while(!this.at("}")&&this.peek().t!=="eof"){if(this.eat("..."))Q.push({spread:!0,value:this.assign()});else{let X=this.next();if(X.t!=="id"&&X.t!=="str"&&X.t!=="num")return this.error("LIPS-E011","Invalid object key",X);if(this.eat(":"))Q.push({key:String(X.value),value:this.assign()});else if(X.t==="id")Q.push({key:X.value,value:{t:"id",name:X.value}});else return this.error("LIPS-E011","Invalid shorthand property",X)}if(!this.eat(","))break}return this.expect("}","LIPS-E011"),{t:"obj",props:Q}}return this.next(),this.error("LIPS-E012",J.t==="eof"?"Unexpected end of expression":`Unexpected token '${J.value}'`,J)}}function c(J){let Q=[],X=BJ(J,Q);return{ast:new QJ(X,Q).parse(),diagnostics:Q}}var XJ={static:"__static",arguments:"__args__"};function S(J){switch(J.t){case"lit":if(typeof J.v==="string")return JSON.stringify(J.v);if(J.v===void 0)return"undefined";if(Number.isNaN(J.v))return"NaN";return String(J.v);case"id":return XJ[J.name]??J.name;case"member":{let Q=S(J.obj);if(J.computed)return`(${Q})${J.optional?"?.":""}[${S(J.prop)}]`;return`(${Q})${J.optional?"?.":"."}${J.prop}`}case"call":return`(${S(J.callee)})${J.optional?"?.":""}(${J.args.map(S).join(",")})`;case"unary":return`(${J.op}(${S(J.arg)}))`;case"update":return J.prefix?`(${J.op}${r(J.arg)})`:`(${r(J.arg)}${J.op})`;case"bin":return`((${S(J.l)})${J.op}(${S(J.r)}))`;case"logic":return`((${S(J.l)})${J.op}(${S(J.r)}))`;case"cond":return`((${S(J.test)})?(${S(J.cons)}):(${S(J.alt)}))`;case"assign":return`(${r(J.target)}${J.op}(${S(J.value)}))`;case"arrow":return`((${J.params.join(",")})=>(${S(J.body)}))`;case"arr":return`[${J.items.map((Q)=>(Q.spread?"...":"")+S(Q.value)).join(",")}]`;case"obj":return`({${J.props.map((Q)=>Q.spread?`...${S(Q.value)}`:`${JSON.stringify(Q.key)}:${S(Q.value)}`).join(",")}})`;case"error":return"undefined"}}function r(J){if(J.t==="id")return XJ[J.name]??J.name;if(J.t==="member"){let Q=S(J.obj);return J.computed?`${Q}[${S(J.prop)}]`:`${Q}.${J.prop}`}return S(J)}var e=new Map,CJ=["state","input","context","__static","self"];function ZJ(J,Q=[]){let X=`${Q.join(",")}\x00${J}`,Z=e.get(X);if(Z)return Z;let{ast:z,diagnostics:W}=c(J);if(W.length)console.warn(`[lips-ir] expression diagnostics for "${J}":`,W);let V=`return (${S(z)});`,q=[...CJ,"__args__",...Q],Y=Function(...q,V),$={source:J,run(F){let D=F.scope||{};return Y(F.state,F.input,F.context,F.static,F.self,F.arguments,...Q.map((U)=>D[U]))}};return e.set(X,$),$}var JJ={Math,JSON,Object,Array,String,Number,Boolean,Date,parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,console};function $J(J,Q){let X=Q.scope||{},Z=(q,Y)=>{for(let $ of Y)if(q in $)return $[q];if(q in X)return X[q];switch(q){case"state":return Q.state;case"input":return Q.input;case"context":return Q.context;case"static":return Q.static;case"self":return Q.self;case"arguments":return Q.arguments}if(q in JJ)return JJ[q];return},z=(q,Y,$)=>{for(let F of $)if(q in F)return F[q]=Y,Y;return X[q]=Y,Y},W=(q,Y)=>{switch(q.t){case"lit":return q.v;case"id":return Z(q.name,Y);case"member":{let $=W(q.obj,Y);if(q.optional&&$==null)return;let F=q.computed?W(q.prop,Y):q.prop;return $?.[F]}case"call":{if(q.callee.t==="member"){let F=W(q.callee.obj,Y);if((q.callee.optional||q.optional)&&F==null)return;let D=q.callee.computed?W(q.callee.prop,Y):q.callee.prop,U=F?.[D];if(q.optional&&U==null)return;return U.apply(F,q.args.map((K)=>W(K,Y)))}let $=W(q.callee,Y);if(q.optional&&$==null)return;return $(...q.args.map((F)=>W(F,Y)))}case"unary":{let $=W(q.arg,Y);switch(q.op){case"!":return!$;case"-":return-$;case"+":return+$}}case"update":{let $=W(q.arg,Y),F=q.op==="++"?$+1:$-1;return V(q.arg,F,Y),q.prefix?F:$}case"bin":{let $=W(q.l,Y),F=W(q.r,Y);switch(q.op){case"+":return $+F;case"-":return $-F;case"*":return $*F;case"/":return $/F;case"%":return $%F;case"<":return $<F;case">":return $>F;case"<=":return $<=F;case">=":return $>=F;case"==":return $==F;case"!=":return $!=F;case"===":return $===F;case"!==":return $!==F}return}case"logic":{let $=W(q.l,Y);switch(q.op){case"&&":return $?W(q.r,Y):$;case"||":return $?$:W(q.r,Y);case"??":return $!=null?$:W(q.r,Y)}}case"cond":return W(q.test,Y)?W(q.cons,Y):W(q.alt,Y);case"assign":{let $=W(q.value,Y);if(q.op!=="="){let F=W(q.target,Y);switch(q.op){case"+=":$=F+$;break;case"-=":$=F-$;break;case"*=":$=F*$;break;case"/=":$=F/$;break;case"%=":$=F%$;break}}return V(q.target,$,Y)}case"arrow":return(...$)=>{let F={};return q.params.forEach((D,U)=>F[D]=$[U]),W(q.body,[F,...Y])};case"arr":{let $=[];for(let F of q.items){let D=W(F.value,Y);F.spread?$.push(...D):$.push(D)}return $}case"obj":{let $={};for(let F of q.props)if(F.spread)Object.assign($,W(F.value,Y));else $[F.key]=W(F.value,Y);return $}case"error":return}},V=(q,Y,$)=>{if(q.t==="id")return z(q.name,Y,$);if(q.t==="member"){let F=W(q.obj,$),D=q.computed?W(q.prop,$):q.prop;if(F!=null)F[D]=Y;return Y}return Y};return W(J,[])}var _=null;function A(J){let Q=new Set,X=()=>{for(let V of[...Q])!V.disposed&&V.run()};return[()=>{if(_&&!_.disposed)Q.add(_),_.deps.add(Q);return J},(V)=>{if(Object.is(V,J))return;J=V,X()},()=>X()]}function O(J){let Q={deps:new Set,disposed:!1,run(){if(Q.disposed)return;for(let Z of Q.deps)Z.delete(Q);Q.deps.clear();let X=_;_=Q;try{J()}finally{_=X}}};return Q.run(),{dispose(){Q.disposed=!0;for(let X of Q.deps)X.delete(Q);Q.deps.clear()}}}function I(J){let Q=_;_=null;try{return J()}finally{_=Q}}var WJ=Symbol("lips.reactive");function E(J,Q=!1){if(J[WJ])return J;let X=new Map,Z=Q?new WeakMap:null,z=(Y,$)=>{let F=X.get(Y);if(!F)F=A($),X.set(Y,F);return F},W=(Y)=>Y!==null&&typeof Y==="object"&&(Array.isArray(Y)||Object.getPrototypeOf(Y)===Object.prototype),V=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),q=(Y,$)=>{if(!Q||!W(Y))return Y;let F=Z.get(Y);if(F)return F;let D=!1,U=new Proxy(Y,{get(K,M){let H=K[M];if(Array.isArray(K)&&typeof M==="string"&&V.has(M)&&typeof H==="function")return(...L)=>{D=!0;try{return H.apply(K,L)}finally{D=!1,$()}};return W(H)?q(H,$):H},set(K,M,H){return K[M]=H,!D&&$(),!0},deleteProperty(K,M){return delete K[M],!D&&$(),!0}});return Z.set(Y,U),U};return new Proxy(J,{get(Y,$){if($===WJ)return!0;if(typeof $==="string"){let F=z($,Y[$]);return q(F[0](),F[2])}return Y[$]},set(Y,$,F){return Y[$]=F,typeof $==="string"&&z($,F)[1](F),!0},has(Y,$){return $ in Y},deleteProperty(Y,$){return delete Y[$],typeof $==="string"&&X.get($)?.[1](void 0),!0}})}var g=(J,Q)=>J==null?J:("e"in J)?{$:Q[J.e]}:J,a=(J,Q)=>({...J,e:Q[J.e]});function u(J,Q){switch(J.t){case"macro":return{t:J.t,name:J.name,args:J.args,vars:Object.fromEntries(Object.entries(J.vars).map(([X,Z])=>[X,g(Z,Q)])),block:y(J.block,Q)};case"if":return{t:J.t,branches:J.branches.map((X)=>({when:X.when==null?null:Q[X.when],block:y(X.block,Q)}))};case"for":return{t:J.t,args:J.args,of:J.of===void 0?void 0:Q[J.of],from:g(J.from,Q),to:g(J.to,Q),by:g(J.by,Q),block:y(J.block,Q)};case"switch":return{t:J.t,on:Q[J.on],cases:J.cases.map((X)=>({is:X.is===null?null:g(X.is,Q),block:y(X.block,Q)}))};case"async":return{t:J.t,awaitE:Q[J.awaitE],then:J.then&&{args:J.then.args,block:y(J.then.block,Q)},catch:J.catch&&{args:J.catch.args,block:y(J.catch.block,Q)},loading:J.loading&&y(J.loading,Q)};case"let":return{t:J.t,const:J.const,vars:Object.fromEntries(Object.entries(J.vars).map(([X,Z])=>[X,g(Z,Q)]))};case"log":return{t:J.t,e:Q[J.e]};case"comp":case"dynamic":return{t:J.t,name:J.t==="comp"?J.name:void 0,tag:J.t==="dynamic"?Q[J.tag]:void 0,inputs:Object.fromEntries(Object.entries(J.inputs).map(([X,Z])=>[X,g(Z,Q)])),spreads:J.spreads.map((X)=>Q[X]),events:J.events.map((X)=>({name:X.name,e:Q[X.e]})),contents:J.contents&&{args:J.contents.args,block:y(J.contents.block,Q)}}}}var y=(J,Q)=>({html:J.html,scope:J.scope,binds:J.binds.map((X)=>a(X,Q)),blocks:J.blocks.map((X)=>u(X,Q))}),qJ=(J,Q,X,Z)=>J.t===X.t&&JSON.stringify(u(J,Q))===JSON.stringify(u(X,Z)),zJ=(J,Q,X,Z)=>JSON.stringify(J.map((z)=>a(z,Q)))===JSON.stringify(X.map((z)=>a(z,Z))),YJ=(J,Q,X,Z)=>{let z=(W,V)=>JSON.stringify(W.blocks.filter((q)=>q.t==="let").map((q)=>u(q,V)));return z(J,Q)===z(X,Z)};var GJ=Symbol("lips.slot"),AJ=(J)=>!!J&&typeof J==="object"&&J[GJ]===!0;function UJ(J){let Q=!1,X=!1,Z=(z)=>typeof J.onError==="function"?J.onError(z):console.error("[lips:ir]",z);return{onError:Z,ready(){X=!0},notifyUpdate(){if(!X||Q)return;Q=!0,queueMicrotask(()=>{Q=!1;try{typeof J.onUpdate==="function"&&J.onUpdate(),typeof J.onRender==="function"&&J.onRender()}catch(z){Z(z)}})}}}var m=[];function HJ(){for(let J=m.length-1;J>=0;J--){let Q=m[J],X=Q.node();if(X&&X.isConnected)m.splice(J,1),Q.fn()}}var FJ=new Map;function IJ(J){let Q=FJ.get(J);if(!Q)Q=c(J).ast,FJ.set(J,Q);return Q}var VJ=new WeakMap;function EJ(J){let Q=VJ.get(J);if(!Q)Q=document.createElement("template"),Q.innerHTML=J.html,VJ.set(J,Q);return Q}var f=(J)=>J.join(",");function KJ(J,Q){let X=J;for(let Z of Q)X=X.childNodes[Z];return X}function C(J){let Q=[],X=J.start;while(X){if(Q.push(X),X===J.end)break;X=X.nextSibling}return Q}function R(J,Q){let X=J.parentNode;if(!X)return;let Z=J;for(let z of Q)X.insertBefore(z,Z.nextSibling),Z=z}function MJ(J,Q,X,Z){for(let W of C(Q))if(W.nodeType===1&&!W.hasAttribute("rel"))W.setAttribute("rel",X);let z=J.createStylesheet?.(X,Z);return z?()=>z.clear():void 0}function TJ(J){for(let Q of J.bindHandles)Q.dispose();for(let Q of J.childHandles)Q.dispose()}function B(J){if(!J)return;TJ(J);for(let Q of C(J))Q.remove()}function DJ(J){let Q=[],X=0,Z=0;for(let z=0;z<J.length;z++){let W=J[z];if(W==="'"||W==='"'||W==="`"){z++;while(z<J.length&&J[z]!==W){if(J[z]==="\\")z++;z++}continue}if(W==="("||W==="["||W==="{")X++;else if(W===")"||W==="]"||W==="}")X--;else if(W===","&&X===0)Q.push(J.slice(Z,z)),Z=z+1}return Q.push(J.slice(Z)),Q.map((z)=>z.trim()).filter(Boolean)}var h=(J,Q,X)=>{X===!1||X==null?J.removeAttribute(Q):J.setAttribute(Q,X===!0?"":String(X))},x=(J,Q,X)=>Object.defineProperty(J,Q,{get:X,enumerable:!0,configurable:!0});class v{ir;options;hooks;constructor(J,Q,X){this.ir=J;this.options=Q;this.hooks=X}guarded(J){let Q=!0;return O(()=>{try{J()}catch(X){this.hooks?this.hooks.onError(X):console.error("[lips:ir]",X)}Q?Q=!1:this.hooks?.notifyUpdate()})}runner(J,Q){return this.srcRunner(this.ir.exprs[J],Q)}srcRunner(J,Q){if(this.options.mode==="interpreted"){let Z=IJ(J);return(z)=>$J(Z,z)}let X=ZJ(J,Q);return(Z)=>X.run(Z)}renderBlock(J,Q){let X=EJ(J).content.cloneNode(!0),Z=new Map,z=J.binds.map((D)=>{let U=KJ(X,D.p);return Z.set(f(D.p),U),U}),W=J.blocks.map((D)=>{let U=KJ(X,D.p);return Z.set(f(D.p),U),U}),V=document.createComment("^"),q=document.createComment("$");X.insertBefore(V,X.firstChild),X.appendChild(q);let Y=Object.create(Q.scope??null),$={...Q,scope:Y},F={start:V,end:q,block:J,exprs:this.ir.exprs,penv:Q,benv:$,pathNodes:Z,bindHandles:[],childHandles:[]};return J.blocks.forEach((D,U)=>{if(D.t!=="let")return;let K=[];for(let[M,H]of Object.entries(D.vars))if("lit"in H){let[L]=A(H.lit);x(Y,M,L)}else{let[L,G]=A(void 0);x(Y,M,L);let P=this.runner(H.e,J.scope);K.push(O(()=>G(P($))).dispose)}F.childHandles[U]={child:D,exprs:this.ir.exprs,anchor:W[U],dispose:()=>K.forEach((M)=>M())}}),F.bindHandles=J.binds.map((D,U)=>this.bindOne(D,z[U],$,J.scope)),J.blocks.forEach((D,U)=>{if(D.t==="let")return;F.childHandles[U]={child:D,exprs:this.ir.exprs,anchor:W[U],dispose:this.execBlock(D,W[U],$,J.scope)}}),F}bindOne(J,Q,X,Z,z){switch(J.t){case"text":{let W=z??document.createTextNode("");!z&&R(Q,[W]);let V=this.runner(J.e,Z),q=J.i18n?this.options.i18n:void 0,Y=this.guarded(()=>{let $=V(X),F=$==null?"":String($);W.data=q?q.translate(F):F});return{bind:J,node:Q,textNode:W,dispose:Y.dispose}}case"attr":{let W=this.runner(J.e,Z),V=J.i18n?this.options.i18n:void 0,q=this.guarded(()=>{let Y=W(X);h(Q,J.name,V&&Y!=null?V.translate(String(Y)):Y)});return{bind:J,node:Q,dispose:q.dispose}}case"prop":{let W=this.runner(J.e,Z);if(J.name==="format"){let q=J.ref||"",Y=this.guarded(()=>{let $=W(X),F=this.options.i18n?.format(q,$);Q.textContent=F==null?"":String(F)});return{bind:J,node:Q,dispose:Y.dispose}}let V=this.guarded(()=>{let q=W(X);J.name==="html"?Q.innerHTML=q==null?"":String(q):Q.textContent=q==null?"":String(q)});return{bind:J,node:Q,dispose:V.dispose}}case"event":{let W=this.eventDispatcher(this.ir.exprs[J.e],Z,X);return Q.addEventListener(J.name,W),{bind:J,node:Q,dispose:()=>Q.removeEventListener(J.name,W)}}case"spread":{let W=this.runner(J.e,Z),V=new Set,q=this.guarded(()=>{let Y=W(X)||{},$=new Set(Object.keys(Y));for(let F of V)!$.has(F)&&Q.removeAttribute(F);for(let F of $)h(Q,F,Y[F]);V=$});return{bind:J,node:Q,dispose:q.dispose}}}}swapBlock(J,Q,X,Z){if(J.block.html!==Q.html||JSON.stringify(J.block.scope)!==JSON.stringify(Q.scope)||!YJ(J.block,J.exprs,Q,this.ir.exprs))return this.rebuild(J,Q,X,Z);if(!zJ(J.block.binds,J.exprs,Q.binds,this.ir.exprs)){let z=Q.binds.map((q)=>J.pathNodes.get(f(q.p)));if(z.some((q)=>!q))return this.rebuild(J,Q,X,Z);let W=new Map;J.bindHandles.forEach((q)=>q.textNode&&W.set(f(q.bind.p),q.textNode)),J.bindHandles.forEach((q)=>q.dispose());let V=new Set;J.bindHandles=Q.binds.map((q,Y)=>{let $=f(q.p),F=q.t==="text"?W.get($):void 0;return F&&V.add($),this.bindOne(q,z[Y],J.benv,Q.scope,F)}),W.forEach((q,Y)=>!V.has(Y)&&q.remove()),X.push({kind:"binds",path:Z})}for(let z=0;z<Q.blocks.length;z++){let W=Q.blocks[z],V=J.childHandles[z];if(W.t==="let")continue;if(V&&qJ(V.child,V.exprs,W,this.ir.exprs))continue;V?.dispose(),J.childHandles[z]={child:W,exprs:this.ir.exprs,anchor:V.anchor,dispose:this.execBlock(W,V.anchor,J.benv,Q.scope)},X.push({kind:"block",path:`${Z}/${z}`})}return J.block=Q,J.exprs=this.ir.exprs,J}rebuild(J,Q,X,Z){let z=this.renderBlock(Q,J.penv);return R(J.end,C(z)),B(J),X.push({kind:"skeleton",path:Z}),z}execBlock(J,Q,X,Z){let z=[];switch(J.t){case"if":{let W=J.branches.map(($)=>$.when!=null?this.runner($.when,Z):null),V=null,q=-2,Y=O(()=>{let $=-1;for(let F=0;F<J.branches.length;F++){let D=W[F];if(!D||D(X)){$=F;break}}if($===q)return;q=$,I(()=>{if(B(V),V=null,$>=0)V=this.renderBlock(J.branches[$].block,X),R(Q,C(V))})});z.push(()=>{Y.dispose(),B(V)});break}case"switch":{let W=this.runner(J.on,Z),V=J.cases.map((F)=>F.is&&("e"in F.is)?this.runner(F.is.e,Z):null),q=null,Y=-2,$=O(()=>{let F=W(X),D=-1,U=-1;for(let K=0;K<J.cases.length;K++){let M=J.cases[K];if(M.is===null){U=K;continue}let H="lit"in M.is?M.is.lit:V[K](X);if(Array.isArray(H)?H.includes(F):H===F){D=K;break}}if(D===-1)D=U;if(D===Y)return;Y=D,I(()=>{if(B(q),q=null,D>=0)q=this.renderBlock(J.cases[D].block,X),R(Q,C(q))})});z.push(()=>{$.dispose(),B(q)});break}case"macro":{let W=Object.create(X.scope??null),V=E({});for(let[Y,$]of Object.entries(J.vars)){if("lit"in $){if(V[Y]=$.lit,J.args.includes(Y)){let[K]=A($.lit);x(W,Y,K)}continue}let F=this.runner($.e,Z),[D,U]=A(void 0);if(J.args.includes(Y))x(W,Y,D);z.push(O(()=>{let K=F(X);U(K),V[Y]=K}).dispose)}let q=this.renderBlock(J.block,{...X,arguments:V,scope:W});R(Q,C(q)),z.push(()=>B(q));break}case"for":this.execFor(J,Q,X,Z,z);break;case"async":{let W=this.runner(J.awaitE,Z),V=null,q=0,Y=(F,D)=>{if(B(V),V=null,!F)return;let U="block"in F,K=Object.create(X.scope??null);if(U&&F.args[0]!==void 0){let[M]=A(D);x(K,F.args[0],M)}V=this.renderBlock(U?F.block:F,{...X,scope:K}),R(Q,C(V))},$=O(()=>{let F=W(X),D=++q;I(()=>{J.loading?Y(J.loading):Y(void 0),Promise.resolve(F).then((U)=>D===q&&I(()=>Y(J.then,U)),(U)=>D===q&&I(()=>Y(J.catch,U)))})});z.push(()=>{q++,$.dispose(),B(V)});break}case"log":{let W=DJ(this.ir.exprs[J.e]).map((V)=>this.srcRunner(V,Z));z.push(O(()=>console.log(...W.map((V)=>V(X)))).dispose);break}case"comp":{let W=this.options.components?.[J.name];W?this.execComponent(W,J,Q,X,Z,z):this.execElement(J,Q,X,Z,z);break}case"dynamic":{let W=this.runner(J.tag,Z),V=[],q=Symbol("init"),Y=O(()=>{let $=W(X);if($===q)return;q=$,I(()=>{for(let D of V)D();if(V=[],$==null)return;if(AJ($)){let D={};for(let[K,M]of Object.entries(J.inputs))D[K]="lit"in M?M.lit:this.runner(M.e,Z)(X);let U=$.render(D);R(Q,C(U)),V.push(()=>B(U));return}let F=typeof $==="string"?this.options.components?.[$]:$&&typeof $==="object"?$.ir?$:this.options.resolveTemplate?.($):void 0;if(F)this.execComponent(F,J,Q,X,Z,V);else if(typeof $==="string")this.execElement({...J,name:$},Q,X,Z,V)})});z.push(()=>{Y.dispose();for(let $ of V)$()});break}}return()=>z.forEach((W)=>W())}execFor(J,Q,X,Z,z){let W=J.of!==void 0?this.runner(J.of,Z):null,V=J.by&&"e"in J.by?this.runner(J.by.e,Z):null,q=J.by&&"lit"in J.by?String(J.by.lit).split("."):null,Y=(K,M)=>K===void 0?void 0:("lit"in K)?K.lit:this.runner(K.e,Z)(M),$=[],F=new Map,D=()=>{if(W===null){let H=Number(Y(J.from,X)??0),L=Number(Y(J.to,X)??H),G=H<=L,P=[];for(let j=H;G?j<=L:j>=L;G?j++:j--)P.push({key:j,values:[j]});return P}let K=W(X),M=(H,L,G)=>{if(V){let P=V(X);return typeof P==="function"?P(H,G):L}if(q)return q.reduce((P,j)=>P?.[j],H);return L};if(Array.isArray(K))return K.map((H,L)=>({key:M(H,L,L),values:[H,L]}));if(K instanceof Map)return[...K.entries()].map(([H,L],G)=>({key:H,values:[H,L,G]}));if(K&&typeof K==="object")return Object.entries(K).map(([H,L],G)=>({key:H,values:[H,L,G]}));return[]},U=O(()=>{let K=D();I(()=>{let M=new Set,H=[];for(let G of K){let P=G.key;if(M.has(P))console.warn(`<for> duplicate key '${String(P)}' — falling back to positional identity`),P=`#dup:${H.length}`;M.add(P);let j=F.get(P);if(j)j.sigs.forEach(([N,T,k],b)=>{let w=G.values[b];Object.is(N(),w)&&typeof w==="object"&&w!==null?k():T(w)}),H.push(j);else{let N=Object.create(X.scope??null),T=G.values.map((w)=>A(w));J.args.forEach((w,n)=>T[n]&&x(N,w,T[n][0]));let k=this.renderBlock(J.block,{...X,scope:N}),b={key:P,sigs:T,inst:k};F.set(P,b),H.push(b)}}for(let G of $)if(!H.includes(G))F.delete(G.key),B(G.inst);let L=Q;for(let G of H){if(L.nextSibling!==G.inst.start)R(L,C(G.inst));L=G.inst.end}$=H})});z.push(()=>{U.dispose();for(let K of $)B(K.inst);$=[],F.clear()})}execComponent(J,Q,X,Z,z,W){let V=E({});for(let[G,P]of Object.entries(Q.inputs))if("lit"in P)V[G]=P.lit;else{let j=this.runner(P.e,z);W.push(O(()=>V[G]=j(Z)).dispose)}for(let G of Q.spreads){let P=this.runner(G,z);W.push(O(()=>{let j=P(Z)||{};I(()=>Object.entries(j).forEach(([N,T])=>V[N]=T))}).dispose)}if(Q.contents){let G=this,P=Q.contents,j=Z;V.renderer={[GJ]:!0,args:P.args,render(N){let T=Object.create(j.scope??null);return P.args.forEach((k)=>{let[b]=A(N?.[k]);x(T,k,b)}),G.renderBlock(P.block,{...j,scope:T})}}}let q=E({...J.state||{}},J.deep??!1),Y=new Map,$={...this.options.expose||{},state:q,input:V,static:J.statics,context:Z.context,emit(G,...P){Y.get(G)?.forEach((j)=>j(...P))},on(G,P){return Y.set(G,[...Y.get(G)||[],P]),$},off(G){return Y.delete(G),$}};J.handlers&&Object.entries(J.handlers).forEach(([G,P])=>$[G]=P.bind($)),Q.events?.forEach((G)=>{let P=this.eventDispatcher(this.ir.exprs[G.e],z,Z);$.on(G.name,P)});let F=UJ($);try{typeof $.onCreate==="function"&&$.onCreate()}catch(G){F.onError(G)}try{Object.keys(V).length&&typeof $.onInput==="function"&&$.onInput()}catch(G){F.onError(G)}let D={state:q,input:V,context:Z.context,static:J.statics,self:$,scope:void 0},K=new v(J.ir,this.options,F).renderBlock(J.ir.root,D),M=J.stylesheet?MJ(this.options,K,J.nsp||"lips",J.stylesheet):void 0;R(X,C(K)),F.ready();try{typeof $.onMount==="function"&&$.onMount(),typeof $.onRender==="function"&&$.onRender()}catch(G){F.onError(G)}let H;if(J.context?.length&&typeof $.onContext==="function"&&this.options.watchContext)H=this.options.watchContext(J.context,()=>{try{$.onContext()}catch(G){F.onError(G)}});let L=!1;if(typeof $.onAttach==="function"||typeof $.onDetach==="function")m.push({node:()=>K.start,fn:()=>{L=!0;try{typeof $.onAttach==="function"&&$.onAttach()}catch(G){F.onError(G)}}}),K.start.isConnected&&HJ();W.push(()=>{H?.(),M?.(),B(K);try{L&&typeof $.onDetach==="function"&&$.onDetach(),typeof $.onDestroy==="function"&&$.onDestroy()}catch(G){F.onError(G)}})}execElement(J,Q,X,Z,z){let W=document.createElement(J.name);for(let[V,q]of Object.entries(J.inputs))if("lit"in q)h(W,V,q.lit);else{let Y=this.runner(q.e,Z);z.push(O(()=>h(W,V,Y(X))).dispose)}for(let V of J.events){let q=this.eventDispatcher(this.ir.exprs[V.e],Z,X);W.addEventListener(V.name,q),z.push(()=>W.removeEventListener(V.name,q))}if(J.contents){let V=this.renderBlock(J.contents.block,X);W.append(...C(V)),z.push(()=>B(V))}R(Q,[W]),z.push(()=>W.remove())}eventDispatcher(J,Q,X){let Z=DJ(J);return(...z)=>I(()=>{let W=(Y)=>{let $;try{$=this.srcRunner(Y,Q)(X)}catch(F){$=void 0}if(typeof $!=="function"&&X.self&&typeof X.self[Y]==="function")$=X.self[Y];return $};if(!Z.length)return;let V=W(Z[0]);if(typeof V!=="function")return;let q=Z.slice(1).map((Y)=>this.srcRunner(Y,Q)(X));V(...q,...z)})}}function o(J,Q={},X={}){let Z=E(Q.state||{},Q.deep??!1),z=Q.input?E(Q.input,Q.deep??!1):void 0,W={state:Z,input:z,static:Q.static,...Q.expose||{}};Q.handlers&&Object.entries(Q.handlers).forEach(([K,M])=>W[K]=M.bind(W));let V={state:Z,input:z,context:Q.context,static:Q.static,self:W,scope:void 0},q=UJ(W);try{typeof W.onCreate==="function"&&W.onCreate()}catch(K){q.onError(K)}try{z&&Object.keys(z).length&&typeof W.onInput==="function"&&W.onInput()}catch(K){q.onError(K)}let Y=new v(J,X,q),$=Y.renderBlock(J.root,V);q.ready();let F=Q.stylesheet?MJ(X,$,Q.nsp||"lips",Q.stylesheet):void 0;try{typeof W.onMount==="function"&&W.onMount(),typeof W.onRender==="function"&&W.onRender()}catch(K){q.onError(K)}let D=!1,U=()=>{if(D)return;D=!0;try{typeof W.onAttach==="function"&&W.onAttach()}catch(K){q.onError(K)}};return{state:Z,self:W,get nodes(){return C($)},mount(K){if(K.append(...C($)),$.start.isConnected)U(),HJ()},swap(K){let M=[];return Y=new v(K,X,q),$=Y.swapBlock($,K.root,M,"root"),{changes:M}},dispose(){F?.(),B($);try{D&&typeof W.onDetach==="function"&&W.onDetach(),typeof W.onDestroy==="function"&&W.onDestroy()}catch(K){q.onError(K)}}}}class p{options={emit:!0};__events={};__once_events={};constructor(J){if(J)this.options=J}on(J,Q){if(!Array.isArray(this.__events[J]))this.__events[J]=[];return this.__events[J].push(Q),this}once(J,Q){if(!Array.isArray(this.__once_events[J]))this.__once_events[J]=[];return this.__once_events[J].push(Q),this}off(J,Q){if(Q){if(Array.isArray(this.__events[J]))this.__events[J]=this.__events[J].filter((X)=>X!==Q),!this.__events[J].length&&delete this.__events[J];if(Array.isArray(this.__once_events[J]))this.__once_events[J]=this.__once_events[J].filter((X)=>X!==Q),!this.__once_events[J].length&&delete this.__once_events[J]}else delete this.__events[J],delete this.__once_events[J];return this}emit(J,...Q){if(!this.options.emit)return;let X=(z)=>{if(!z||typeof z!=="object")return z;if(typeof z.toJSON==="function")return z.toJSON();if(Array.isArray(z))return z.map(X);if(z.constructor===Object||z.constructor===void 0){let W={};for(let V in z)W[V]=X(z[V]);return W}return z},Z=Q.map(X);this.__events[J]?.forEach((z)=>z(...Z)),this.__once_events[J]?.forEach((z)=>z(...Z)),delete this.__once_events[J]}}var PJ=null;class i{nsp;settings;constructor(J,Q){if(typeof J!=="string"||!J)throw Error("Undefined or invalid stylesheet namespace");this.nsp=J,this.settings=Q||{},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}"]`)}load(J){if(this.settings=J,!J.sheet)return;if(!PJ){console.warn(`[lips] <${this.nsp}> stylesheet skipped — this build has no CSS preprocessor. `+'Use "@lipsjs/lips" (not "@lipsjs/lips/runtime") for source stylesheets.');return}let Q=this.styleElement;if(Q)return Q.setAttribute("dindex",String(Number(Q.getAttribute("dindex")||0)+1)),Q;let X=J.meta?J.sheet:`[rel="${this.nsp}"] { ${J.sheet} }`,Z;try{Z=PJ(X)}catch(W){throw Error(`Style compilation failed: ${W.message}`)}if(!Z)throw Error(`<${this.nsp}> stylesheet compilation produced no output`);let z=document.createElement("style");return z.setAttribute("rel",this.rel),z.setAttribute("dindex","0"),z.textContent=Z,J.meta?document.head.prepend(z):document.head.appendChild(z),z}clear(){let J=this.styleElement;if(!J)return;let Q=Number(J.getAttribute("dindex")||0);Q<=0?J.remove():J.setAttribute("dindex",String(Q-1))}}function d(J,Q){if(typeof J!=="string")return"";if(!Q)return J;return J.replace(/{(\w+)}/g,(X,Z)=>{return Q[Z]!==void 0?Q[Z].toString():`{${Z}}`})}var LJ=(J,Q,X,Z,z)=>{switch(J){case"plural":{if(typeof X==="string"){console.warn("Plural format value cannot be a string");return}if(Z.count===void 0){console.warn("Plural format requires <count> parameter or use * by default.");let q=X["*"];if(typeof q==="object")q=q[z||"*"];return d(q,Z)}if(typeof Z.count==="string")Z.count=Number(Z.count);let W="*";if(Z.count.toString()in X)W=Z.count.toString();let V=X[W]||X["*"];if(typeof V==="object")V=V[z||"*"];return d(V,Z)}case"condition":{if(typeof X==="string"){console.warn("Condition format value cannot be a string");return}let W;for(let V in X)try{if(Function("params",`with( params ){ return ${V}; }`)(Z||{})){W=X[V];break}}catch(q){console.warn(`Invalid <${Q}(${V})> condition expression`)}if(W===void 0)return;if(typeof W==="object")W=W[z||"*"];return d(W,Z)}case"variable":default:{let W=typeof X==="object"?X[z||"*"]:X;if(typeof W==="object"){console.warn(`Invalid <${Q}> variable variant definition`);return}return d(W,Z)}}};class l{currentLang=window.navigator.language;DICTIONARIES={};set lang(J){if(this.currentLang===J)return;this.currentLang=J}get lang(){return this.currentLang}setDictionary(J,Q){this.DICTIONARIES[J]=Q}translate(J,Q){if(Q&&this.currentLang===Q)return{text:J,lang:this.currentLang};Q=Q||this.currentLang;let[X,Z]=Q.split("-");if(this.DICTIONARIES[X]&&J in this.DICTIONARIES[X]){if(typeof this.DICTIONARIES[X][J]==="object"){let z=this.DICTIONARIES[X][J];J=z[Z||"*"]||z["*"]}else if(typeof this.DICTIONARIES[X][J]==="string")J=this.DICTIONARIES[X][J]}return{text:J,lang:Q}}format(J,Q,X){X=X||this.currentLang;let[Z,z]=X.split("-");if(!this.DICTIONARIES[Z]){console.warn(`Undefined <${X}> format dictionary`);return}if(!this.DICTIONARIES[Z][J]){console.warn(`Undefined <${X}[${J}]> format reference`);return}let W=this.DICTIONARIES[Z][J];if(typeof W==="string"){console.warn(`Invalid <${X}[${J}]> format reference. Expected object`);return}if(typeof W!=="object"||W===null||Array.isArray(W)){console.warn(`Invalid <${X}[${J}]> format value`);return}return LJ(W.type,J,W.value,Q,z)}}var t=null;var _J={};var RJ=new Set(["state","input","static","context","emit","on","once","off","node","destroy","appendTo","prependTo","replaceWith","render","swap"]);function jJ(J){if(!J)return;for(let Q of Object.keys(J))if(RJ.has(Q))throw Error(`Handler <${Q}> is a reserved component member name`);return J}class SJ extends p{lips;template;state;instance;contextWatcher;destroyed=!1;constructor(J,Q,X,Z,z,W){super();this.lips=J;this.template=X;let V=jJ(X.handler);this.state=E({...X.state||{}},!0);let q=Z?E({...Z},!0):void 0;if(this.instance=o(z,{state:this.state,input:q,context:J.getContext(),static:X._static,handlers:V,deep:!0,stylesheet:X.stylesheet,nsp:Q,expose:{emit:(Y,...$)=>this.emit(Y,...$),context:J.getContext()}},W),X.context?.length&&typeof V?.onContext==="function")this.contextWatcher=J.watchContext(X.context,()=>{try{V.onContext.call(this.instance.self)}catch(Y){console.error("[lips:ir]",Y)}});this.emit("component:mount")}get node(){return this.instance.nodes}appendTo(J){let Q=typeof J==="string"?document.querySelector(J):J;return Q&&this.instance.mount(Q),this}swap(J){return this.instance.swap(J)}destroy(){if(this.destroyed)return;this.destroyed=!0,this.contextWatcher?.(),this.instance.dispose(),this.emit("component:destroy")}}class s{config;debug;store=new Map;irCache=new WeakMap;defCache=new WeakMap;context;__root;i18n=new l;getLang;setLang;componentsProxy;constructor(J){this.config=J;this.debug=!!J?.debug,this.context=E({...J?.context||{}},!0);let[Q,X]=A(this.i18n.lang);this.getLang=Q,this.setLang=X,t&&Object.entries(_J).forEach(([z,W])=>this.register(z,W));let Z=this;this.componentsProxy=new Proxy({},{get(z,W){let V=Z.store.get(W);return V?Z.defFor(W,V):void 0},has(z,W){return Z.store.has(W)}})}register(J,Q){return this.store.set(J,Q),this}unregister(J){return this.store.delete(J),this}has(J){return this.store.has(J)}compile(J){if(J.ir)return J.ir;let Q=this.irCache.get(J);if(!Q){if(!t)throw Error("This build has no template compiler — templates must be precompiled to `ir` "+'(import from "@lipsjs/lips" instead of "@lipsjs/lips/runtime")');let X=t(J.default||"",{macros:J.macros});X.diagnostics.length&&console.warn("[lips:ir] template diagnostics —",X.diagnostics),Q=X.ir,this.irCache.set(J,Q)}return Q}defFor(J,Q){let X=this.defCache.get(Q);if(!X)X={ir:this.compile(Q),state:Q.state,statics:Q._static,context:Q.context,stylesheet:Q.stylesheet,nsp:J,handlers:jJ(Q.handler),deep:!0},this.defCache.set(Q,X);return X}render(J,Q,X){return new SJ(this,J,Q,X,this.compile(Q),{mode:this.config?.mode,components:this.componentsProxy,watchContext:(Z,z)=>this.watchContext(Z,z),resolveTemplate:(Z)=>Z&&(typeof Z.default==="string"||Z.ir)?this.defFor(Z.name||"dynamic",Z):void 0,expose:{setContext:(Z,z)=>this.setContext(Z,z)},createStylesheet:(Z,z)=>{let W=new i(Z,{sheet:z});return{clear:()=>W.clear()}},i18n:{translate:(Z)=>{return this.getLang(),this.i18n.translate(Z).text},format:(Z,z)=>{return this.getLang(),this.i18n.format(Z,z)??""}}})}root(J,Q){return this.__root=this.render("__ROOT__",J),this.__root.appendTo(Q),this.__root}setLanguage(J){this.i18n.lang=J,this.setLang(J)}getLanguage(){return this.getLang()}useTranslator(J,Q){let X=!0,{dispose:Z}=O(()=>{let z=this.getLang();if(X){X=!1;return}(J==="*"||Array.isArray(J)&&J.includes(z))&&Q(z)});return Z}getContext(){return this.context}setContext(J,Q){typeof J==="string"?this.context[J]=Q:Object.entries(J).forEach(([X,Z])=>this.context[X]=Z)}watchContext(J,Q){let X=!0,{dispose:Z}=O(()=>{J.forEach((z)=>this.context[z]),X?X=!1:Q()});return Z}useContext(J,Q){return this.watchContext(J,()=>Q(Object.fromEntries(J.map((X)=>[X,this.context[X]]))))}dispose(){this.__root?.destroy()}}var eJ=s;export{I as untrack,A as signal,o as renderIR,E as reactive,O as effect,eJ as default};
1
+ var Jt=["===","!==","...","=>","==","!=","<=",">=","&&","||","??","?.","++","--","+=","-=","*=","/=","%=","+","-","*","/","%","<",">","!","?",":",".",",","(",")","[","]","{","}","="];function Wt(t,e){let n=[],r=0,s=(p)=>/[A-Za-z_$]/.test(p),a=(p)=>/[A-Za-z0-9_$]/.test(p);while(r<t.length){let p=t[r];if(/\s/.test(p)){r++;continue}if(/[0-9]/.test(p)||p==="."&&/[0-9]/.test(t[r+1])){let o=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(o,r),start:o,end:r});continue}if(p==="'"||p==='"'){let o=r;r++;let l="",c=!1;while(r<t.length){let f=t[r];if(f==="\\"){let u=t[r+1],h={n:`
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 s of K(e.toLowerCase())){let a=this.DICTIONARIES[s];if(!a||!Object.prototype.hasOwnProperty.call(a,t))continue;try{r=new this.engine.MessageFormat(e,a[t],{functions:this.functions})}catch(p){this.onError?.(p,t,e),r=null}break}return r!==void 0&&this.formatters.set(n,r),r}translate(t,e,n){let r=e||this.currentLang,s=n||t,a=this.message(s,r);if(a)t=a.format(void 0,(p)=>this.onError?.(p,s,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,s=this.message(t,r);if(s)return s.format(e,(a)=>this.onError?.(a,t,r));s===void 0&&this.onMissing?.(t,r)}pick(t,e){return q(t,e||this.currentLang)}}var ht=null;var gt=null;var ie;var oe={};var ae=new Set(["state","input","static","context","emit","on","once","off","node","lang","setContext","setLanguage","destroy","appendTo","prependTo","replaceWith","render","swap"]);function Ut(t){if(!t)return;for(let e of Object.keys(t))if(ae.has(e))throw Error(`Handler <${e}> is a reserved component member name`);return t}class Kt extends Q{lips;template;state;instance;contextWatcher;destroyed=!1;constructor(t,e,n,r,s,a){super();this.lips=t;this.template=n;let p=Ut(n.handler);this.state=O({...n.state||{}},!0);let i=r?O({...r},!0):void 0,o=(c,...f)=>super.emit(c,...f);this.instance=dt(s,{state:this.state,input:i,context:t.getContext(),static:n.static??n._static,handlers:p,deep:!0,stylesheet:t.styleFor(e,n),nsp:e,expose:{emit(c,...f){this.emitLocal?.(c,...f),o(c,...f)},context:t.getContext()}},a);let l=n.watchContext??n.context;if(l?.length&&typeof p?.onContext==="function")this.contextWatcher=t.watchContext(l,()=>{try{p.onContext.call(this.instance.self)}catch(c){console.error("[lips:ir]",c)}});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 yt{config;debug;store=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=O({...t?.context||{}},!0),this.i18n=new et(t?.lang,t?.messageFormat??ie),this.debug)this.i18n.onMissing=(p,i)=>console.warn(`[lips:i18n] no <${i}> entry for key "${p}"`),this.i18n.onError=(p,i,o)=>console.warn(`[lips:i18n] <${o}> message "${i}" —`,p);let[e,n]=C(this.i18n.lang);this.getLang=e,this.setLang=n;let[r,s]=C(0);this.getRev=r,this.i18n.onChange=()=>s(r()+1),ht&&Object.entries(oe).forEach(([p,i])=>this.register(p,i));let a=this;this.componentsProxy=new Proxy({},{get(p,i){let o=a.store.get(i);return o?a.defFor(i,o):void 0},has(p,i){return a.store.has(i)}})}register(t,e){return this.store.set(t,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(!ht)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=ht(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(!gt){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(gt):gt)(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}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??e.context,stylesheet:this.styleFor(t,e),nsp:t,handlers:Ut(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:(s)=>s&&(typeof s.default==="string"||s.ir)?this.defFor(s.name||"dynamic",s):void 0,expose:{setContext:(s,a)=>this.setContext(s,a),setLanguage:(s)=>this.setLanguage(s)},createStylesheet:(s,a)=>{let p=new tt(s,{sheet:a});return{clear:()=>p.clear()}},i18n:{translate:(s,a,p)=>{let i=this.getLang();return this.getRev(),this.i18n.translate(s,p||i,a).text},format:(s,a,p)=>{let i=this.getLang();return this.getRev(),this.i18n.format(s,a,p||i)??""},lang:()=>this.getLang()}};return new Kt(this,t,e,n,this.compile(e),this.u?this.u.runtime(r):r)}root(t,e){return this.__root=this.render("__ROOT__",t),this.__root.appendTo(e),this.__root}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}=R(()=>{let s=this.getLang();if(n){n=!1;return}(t==="*"||Array.isArray(t)&&t.includes(s))&&e(s)});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}=R(()=>{t.forEach((s)=>this.ctx[s]),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()}}var _e=yt;export{_e as default,R as effect,O as reactive,dt as renderIR,C as signal,w as untrack};
3
4
 
4
- //# debugId=BD57D191358240F764756E2164756E21
5
+ //# debugId=79A374423A4F11A464756E2164756E21