@lipsjs/lips 0.1.1 → 0.3.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.
Files changed (70) hide show
  1. package/README.md +185 -85
  2. package/dist/lips.js +6274 -0
  3. package/dist/lips.js.map +53 -0
  4. package/dist/lips.min.js +13 -2
  5. package/dist/lips.min.js.map +47 -43
  6. package/dist/mf2.min.js +4 -0
  7. package/dist/mf2.min.js.map +38 -0
  8. package/dist/precompile.min.js +23 -0
  9. package/dist/precompile.min.js.map +14 -0
  10. package/dist/runtime.min.js +5 -0
  11. package/dist/runtime.min.js.map +20 -0
  12. package/dist/stylis.min.js +3 -0
  13. package/dist/stylis.min.js.map +16 -0
  14. package/dist/types/events.d.ts +1 -1
  15. package/dist/types/i18n/engine.d.ts +14 -0
  16. package/dist/types/i18n/index.d.ts +122 -5
  17. package/dist/types/i18n/intl.d.ts +1 -0
  18. package/dist/types/i18n/lookup.d.ts +22 -0
  19. package/dist/types/ir/compiler.d.ts +226 -0
  20. package/dist/types/ir/expression.d.ts +149 -0
  21. package/dist/types/ir/facade.d.ts +138 -0
  22. package/dist/types/ir/host.d.ts +75 -0
  23. package/dist/types/ir/index.d.ts +18 -0
  24. package/dist/types/ir/parser.d.ts +124 -0
  25. package/dist/types/ir/policy.d.ts +95 -0
  26. package/dist/types/ir/router.d.ts +47 -0
  27. package/dist/types/ir/runtime.d.ts +130 -0
  28. package/dist/types/ir/signal.d.ts +28 -0
  29. package/dist/types/ir/style.d.ts +119 -0
  30. package/dist/types/ir/swap.d.ts +28 -0
  31. package/dist/types/ir/tree.d.ts +51 -0
  32. package/dist/types/lips.d.ts +33 -37
  33. package/dist/types/lynx/a11y.d.ts +61 -0
  34. package/dist/types/lynx/background.d.ts +71 -0
  35. package/dist/types/lynx/main.d.ts +46 -0
  36. package/dist/types/lynx/protocol.d.ts +52 -0
  37. package/dist/types/lynx/style.d.ts +49 -0
  38. package/dist/types/lynx/template.d.ts +37 -0
  39. package/dist/types/mf2.d.ts +14 -0
  40. package/dist/types/precompile.d.ts +85 -0
  41. package/dist/types/runtime.d.ts +16 -0
  42. package/dist/types/stylesheet.d.ts +21 -41
  43. package/dist/types/stylis.d.ts +2 -0
  44. package/dist/types/types.d.ts +176 -185
  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 +46 -10
  49. package/dist/test.component.min.js +0 -3
  50. package/dist/test.component.min.js.map +0 -50
  51. package/dist/test.stress.min.js +0 -476
  52. package/dist/test.stress.min.js.map +0 -50
  53. package/dist/types/component.d.ts +0 -107
  54. package/dist/types/constants.d.ts +0 -23
  55. package/dist/types/dws.d.ts +0 -14
  56. package/dist/types/iuc/index.d.ts +0 -25
  57. package/dist/types/iuc/tick.d.ts +0 -38
  58. package/dist/types/iuc.d.ts +0 -25
  59. package/dist/types/metrics.d.ts +0 -50
  60. package/dist/types/preprocess.d.ts +0 -2
  61. package/dist/types/signal.d.ts +0 -30
  62. package/dist/types/syntax/async.d.ts +0 -16
  63. package/dist/types/syntax/for.d.ts +0 -25
  64. package/dist/types/syntax/if.d.ts +0 -14
  65. package/dist/types/syntax/router.d.ts +0 -40
  66. package/dist/types/syntax/switch.d.ts +0 -16
  67. package/dist/types/tick.d.ts +0 -38
  68. package/dist/types/tps.d.ts +0 -11
  69. package/dist/types/uqs.d.ts +0 -37
  70. package/dist/types/utils.d.ts +0 -25
@@ -0,0 +1,5 @@
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};
4
+
5
+ //# debugId=79A374423A4F11A464756E2164756E21