@lipsjs/lips 0.3.0 → 0.4.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 (46) hide show
  1. package/README.md +123 -9
  2. package/dist/lips.js +915 -669
  3. package/dist/lips.js.map +15 -12
  4. package/dist/lips.min.js +12 -12
  5. package/dist/lips.min.js.map +15 -12
  6. package/dist/lynx-background.min.js +3 -0
  7. package/dist/lynx-background.min.js.map +13 -0
  8. package/dist/lynx-main.min.js +3 -0
  9. package/dist/lynx-main.min.js.map +11 -0
  10. package/dist/lynx-plugin.mjs +1487 -0
  11. package/dist/lynx.min.js +51 -0
  12. package/dist/lynx.min.js.map +18 -0
  13. package/dist/mf2.min.js.map +1 -1
  14. package/dist/parts.min.js +19 -0
  15. package/dist/parts.min.js.map +11 -0
  16. package/dist/precompile.min.js +15 -15
  17. package/dist/precompile.min.js.map +8 -7
  18. package/dist/runtime.min.js +4 -4
  19. package/dist/runtime.min.js.map +11 -9
  20. package/dist/stylis.min.js.map +1 -1
  21. package/dist/types/component.d.ts +32 -0
  22. package/dist/types/ir/compiler.d.ts +2 -4
  23. package/dist/types/ir/facade.d.ts +63 -12
  24. package/dist/types/ir/host.d.ts +9 -1
  25. package/dist/types/ir/initial.d.ts +16 -0
  26. package/dist/types/ir/router.d.ts +2 -0
  27. package/dist/types/ir/tags.d.ts +16 -0
  28. package/dist/types/lips.d.ts +7 -7
  29. package/dist/types/lynx/a11y.d.ts +1 -0
  30. package/dist/types/lynx/background.d.ts +52 -3
  31. package/dist/types/lynx/main.d.ts +9 -5
  32. package/dist/types/lynx/plugin.d.ts +8 -0
  33. package/dist/types/lynx/protocol.d.ts +55 -4
  34. package/dist/types/lynx/style.d.ts +7 -0
  35. package/dist/types/lynx/template.d.ts +6 -0
  36. package/dist/types/lynx.d.ts +22 -0
  37. package/dist/types/parts/menu.d.ts +44 -0
  38. package/dist/types/parts/popover.d.ts +83 -0
  39. package/dist/types/parts.d.ts +16 -0
  40. package/dist/types/precompile.d.ts +8 -11
  41. package/dist/types/runtime.d.ts +1 -0
  42. package/dist/types/types.d.ts +181 -57
  43. package/dist/untrusted.min.js +4 -4
  44. package/dist/untrusted.min.js.map +7 -7
  45. package/package.json +29 -3
  46. package/dist/types/i18n/formatters.d.ts +0 -3
package/dist/lips.min.js CHANGED
@@ -1,14 +1,14 @@
1
- var Jn=["===","!==","...","=>","==","!=","<=",">=","&&","||","??","?.","++","--","+=","-=","*=","/=","%=","+","-","*","/","%","<",">","!","?",":",".",",","(",")","[","]","{","}","="];function Yn(t,e){let n=[],r=0,s=(a)=>/[A-Za-z_$]/.test(a),i=(a)=>/[A-Za-z0-9_$]/.test(a);while(r<t.length){let a=t[r];if(/\s/.test(a)){r++;continue}if(/[0-9]/.test(a)||a==="."&&/[0-9]/.test(t[r+1])){let c=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(c,r),start:c,end:r});continue}if(a==="'"||a==='"'){let c=r;r++;let p="",l=!1;while(r<t.length){let u=t[r];if(u==="\\"){let f=t[r+1],m={n:`
2
- `,t:"\t",r:"\r",b:"\b",f:"\f",v:"\v","0":"\x00"};if(f==="u"){let g=t.slice(r+2,r+6);p+=String.fromCharCode(parseInt(g,16)||0),r+=6}else p+=m[f]??f,r+=2;continue}if(u===a){l=!0,r++;break}p+=u,r++}if(!l)e.push({code:"LIPS-E001",message:"Unterminated string literal",loc:{offset:c,length:r-c}});n.push({t:"str",value:p,start:c,end:r});continue}if(s(a)){let c=r;while(r<t.length&&i(t[r]))r++;n.push({t:"id",value:t.slice(c,r),start:c,end:r});continue}let o=Jn.find((c)=>t.startsWith(c,r));if(o==="?."&&/[0-9]/.test(t[r+2]??""))o="?";if(o){n.push({t:"punct",value:o,start:r,end:r+o.length}),r+=o.length;continue}e.push({code:"LIPS-E002",message:`Unexpected character '${a}'`,loc:{offset:r,length:1}}),r++}return n.push({t:"eof",value:"",start:t.length,end:t.length}),n}class je{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 X(t){let e=[],n=Yn(t,e);return{ast:new je(n,e).parse(),diagnostics:e}}function oe(t){let e=[],n=0,r=0;for(let s=0;s<t.length;s++){let i=t[s];if(i==="'"||i==='"'||i==="`"){s++;while(s<t.length&&t[s]!==i){if(t[s]==="\\")s++;s++}continue}if(i==="("||i==="["||i==="{")n++;else if(i===")"||i==="]"||i==="}")n--;else if(i===","&&n===0)e.push(t.slice(r,s)),r=s+1}return e.push(t.slice(r)),e.map((s)=>s.trim()).filter(Boolean)}function Ae(t){let e=new Set,n=(r,s)=>{switch(r.t){case"id":!s.has(r.name)&&e.add(r.name);return;case"member":n(r.obj,s),typeof r.prop!=="string"&&n(r.prop,s);return;case"call":n(r.callee,s),r.args.forEach((i)=>n(i,s));return;case"unary":case"update":n(r.arg,s);return;case"bin":case"logic":n(r.l,s),n(r.r,s);return;case"cond":n(r.test,s),n(r.cons,s),n(r.alt,s);return;case"assign":n(r.target,s),n(r.value,s);return;case"arrow":n(r.body,new Set([...s,...r.params]));return;case"arr":r.items.forEach((i)=>n(i.value,s));return;case"obj":r.props.forEach((i)=>n(i.value,s));return}};return n(t,new Set),[...e]}var _e={__proto__:null,static:"__static",arguments:"__args__"};function j(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 _e[t.name]??t.name;case"member":{let e=j(t.obj);if(t.computed)return`(${e})${t.optional?"?.":""}[${j(t.prop)}]`;return`(${e})${t.optional?"?.":"."}${t.prop}`}case"call":return`(${j(t.callee)})${t.optional?"?.":""}(${t.args.map(j).join(",")})`;case"unary":return`(${t.op}(${j(t.arg)}))`;case"update":return t.prefix?`(${t.op}${ie(t.arg)})`:`(${ie(t.arg)}${t.op})`;case"bin":return`((${j(t.l)})${t.op}(${j(t.r)}))`;case"logic":return`((${j(t.l)})${t.op}(${j(t.r)}))`;case"cond":return`((${j(t.test)})?(${j(t.cons)}):(${j(t.alt)}))`;case"assign":return`(${ie(t.target)}${t.op}(${j(t.value)}))`;case"arrow":return`((${t.params.join(",")})=>(${j(t.body)}))`;case"arr":return`[${t.items.map((e)=>(e.spread?"...":"")+j(e.value)).join(",")}]`;case"obj":return`({${t.props.map((e)=>e.spread?`...${j(e.value)}`:`${JSON.stringify(e.key)}:${j(e.value)}`).join(",")}})`;case"error":return"undefined"}}function ie(t){if(t.t==="id")return _e[t.name]??t.name;if(t.t==="member"){let e=j(t.obj);return t.computed?`${e}[${j(t.prop)}]`:`${e}.${t.prop}`}return j(t)}var Ne=new Map,Qn=["state","input","context","__static","self"];function ae(t,e=[]){let n=`${e.join(",")}\x00${t}`,r=Ne.get(n);if(r)return r;let{ast:s,diagnostics:i}=X(t);if(i.length)console.warn(`[lips-ir] expression diagnostics for "${t}":`,i);let a=`return (${j(s)});`,o=[...Qn,"__args__",...e],c=Function(...o,a),p={source:t,run(l){let u=l.scope||{};return c(l.state,l.input,l.context,l.static,l.self,l.arguments,...e.map((f)=>u[f]))}};return Ne.set(n,p),p}var $e={__proto__:null,Math,JSON,Object,Array,String,Number,Boolean,Date,parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,console};function ce(t,e){let n=e.scope||Object.create(null),r=(o,c)=>{for(let p of c)if(o in p)return p[o];if(o in n)return n[o];switch(o){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(o in $e)return $e[o];return},s=(o,c,p)=>{for(let l of p)if(o in l)return l[o]=c,c;return n[o]=c,c},i=(o,c)=>{switch(o.t){case"lit":return o.v;case"id":return r(o.name,c);case"member":{let p=i(o.obj,c);if(o.optional&&p==null)return;let l=o.computed?i(o.prop,c):o.prop;return p?.[l]}case"call":{if(o.callee.t==="member"){let l=i(o.callee.obj,c);if((o.callee.optional||o.optional)&&l==null)return;let u=o.callee.computed?i(o.callee.prop,c):o.callee.prop,f=l?.[u];if(o.optional&&f==null)return;return f.apply(l,o.args.map((m)=>i(m,c)))}let p=i(o.callee,c);if(o.optional&&p==null)return;return p(...o.args.map((l)=>i(l,c)))}case"unary":{let p=i(o.arg,c);switch(o.op){case"!":return!p;case"-":return-p;case"+":return+p}}case"update":{let p=i(o.arg,c),l=o.op==="++"?p+1:p-1;return a(o.arg,l,c),o.prefix?l:p}case"bin":{let p=i(o.l,c),l=i(o.r,c);switch(o.op){case"+":return p+l;case"-":return p-l;case"*":return p*l;case"/":return p/l;case"%":return p%l;case"<":return p<l;case">":return p>l;case"<=":return p<=l;case">=":return p>=l;case"==":return p==l;case"!=":return p!=l;case"===":return p===l;case"!==":return p!==l}return}case"logic":{let p=i(o.l,c);switch(o.op){case"&&":return p?i(o.r,c):p;case"||":return p?p:i(o.r,c);case"??":return p!=null?p:i(o.r,c)}}case"cond":return i(o.test,c)?i(o.cons,c):i(o.alt,c);case"assign":{let p=i(o.value,c);if(o.op!=="="){let l=i(o.target,c);switch(o.op){case"+=":p=l+p;break;case"-=":p=l-p;break;case"*=":p=l*p;break;case"/=":p=l/p;break;case"%=":p=l%p;break}}return a(o.target,p,c)}case"arrow":return(...p)=>{let l=Object.create(null);return o.params.forEach((u,f)=>l[u]=p[f]),i(o.body,[l,...c])};case"arr":{let p=[];for(let l of o.items){let u=i(l.value,c);l.spread?p.push(...u):p.push(u)}return p}case"obj":{let p={};for(let l of o.props)if(l.spread)Object.assign(p,i(l.value,c));else p[l.key]=i(l.value,c);return p}case"error":return}},a=(o,c,p)=>{if(o.t==="id")return s(o.name,c,p);if(o.t==="member"){let l=i(o.obj,p),u=o.computed?i(o.prop,p):o.prop;if(l!=null)l[u]=c;return c}return c};return i(t,[])}var J=null,ht=0,Tt=new Set;function Xn(){while(Tt.size){let t=[...Tt];Tt.clear(),ht++;try{for(let e of t)!e.disposed&&e.run()}finally{ht--}}}function pe(t){ht++;try{return t()}finally{ht--,!ht&&Xn()}}function F(t){let e=new Set,n=()=>{if(ht){for(let a of e)Tt.add(a);return}for(let a of[...e])!a.disposed&&a.run()};return[()=>{if(J&&!J.disposed)e.add(J),J.deps.add(e);return t},(a)=>{if(Object.is(a,t))return;t=a,n()},()=>n()]}function A(t){let e={deps:new Set,disposed:!1,run(){if(e.disposed)return;for(let r of e.deps)r.delete(e);e.deps.clear();let n=J;J=e;try{t()}finally{J=n}}};return e.run(),{dispose(){e.disposed=!0;for(let n of e.deps)n.delete(e);e.deps.clear()}}}function V(t){let e=J;J=null;try{return t()}finally{J=e}}var De=Symbol("lips.reactive"),Mt=Symbol("lips.collection"),Be=new WeakMap,ue=(t)=>t!==null&&typeof t==="object"&&(Array.isArray(t)||Object.getPrototypeOf(t)===Object.prototype),Pt=(t)=>t instanceof Map||t instanceof Set||!!(t&&typeof t==="object"&&t[Mt]),tr=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),er=new Set(["set","delete","clear","add"]),le=Symbol("lips.keys"),Fe=new WeakMap;function He(t,e){let n=t[Mt];if(n)return n.notify.add(e),t;let r=Be.get(t);if(r)return r[Mt].notify.add(e),r;let s={raw:t,notify:new Set([e])},i=()=>s.notify.forEach((o)=>o()),a=new Proxy(t,{get(o,c){if(c===Mt)return s;let p=o[c];if(typeof p!=="function")return p;if(typeof c==="string"&&er.has(c))return(...f)=>{let m=p.apply(o,f);return i(),m};let l=(f)=>ue(f)?fe(f,i):Pt(f)?He(f,i):f,u=o instanceof Map;if(c==="get")return(f)=>l(o.get(f));if(c==="forEach")return(f,m)=>o.forEach((g,b)=>f.call(m,l(g),b,a));if(c==="values"||!u&&(c==="keys"||c===Symbol.iterator))return function*(){for(let f of o.values())yield l(f)};if(c==="entries"||u&&c===Symbol.iterator)return u?function*(){for(let[f,m]of o.entries())yield[f,l(m)]}:function*(){for(let f of o.values())yield[l(f),l(f)]};return p.bind(o)}});return Be.set(t,a),a}function nr(t){let e=Fe.get(t);if(e)return e;let n=new Map,r=(l)=>{let u=n.get(l);if(!u)u=F(0),n.set(l,u);u[0]()},s=(l)=>n.get(l)?.[2](),i=new Map,a=(l)=>{let u=i.get(l);if(!u)u=()=>s(l),i.set(l,u);return u},o=()=>pe(()=>{for(let l of n.values())l[2]()}),c=!1,p=new Proxy(t,{get(l,u){let f=l[u];if(typeof u==="symbol")return f;if(Array.isArray(l)&&tr.has(u)&&typeof f==="function")return(...m)=>{c=!0;try{return f.apply(l,m)}finally{c=!1,o()}};if(typeof f==="function")return f;return r(u),ue(f)||Pt(f)?fe(f,a(u)):f},set(l,u,f){let m=u in l,g=l[u];if(l[u]=f,c)return!0;if(!Object.is(g,f))s(u);if(!m)s(le),Array.isArray(l)&&s("length");return!0},deleteProperty(l,u){let f=u in l;if(delete l[u],!c&&f)s(u),s(le);return!0},has(l,u){return typeof u!=="symbol"&&r(u),u in l},ownKeys(l){return r(le),Reflect.ownKeys(l)}});return Fe.set(t,p),p}function fe(t,e){if(Pt(t))return He(t,e);if(!ue(t))return t;return nr(t)}function Z(t,e=!1){if(t[De])return t;let n=new Map,r=(s,i)=>{let a=n.get(s);if(!a)a=F(i),n.set(s,a);return a};return new Proxy(t,{get(s,i){if(i===De)return!0;if(typeof i==="string"){let a=r(i,s[i]);return e?fe(a[0](),a[2]):a[0]()}return s[i]},set(s,i,a){let o=s[i];if(s[i]=a,typeof i!=="string")return!0;let c=r(i,a);return Object.is(o,a)&&Pt(a)?c[2]():c[1](a),!0},has(s,i){return i in s},deleteProperty(s,i){return delete s[i],typeof i==="string"&&n.get(i)?.[1](void 0),!0}})}var Ve=new WeakMap,he={clone(t){let e=Ve.get(t);if(!e)e=document.createElement("template"),e.innerHTML=t.html,Ve.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 yt(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 Ot(t,e){let n=new Map(Object.entries(t.names).map(([r,s])=>[r.toLowerCase(),s]));for(let r of yt(e.toLowerCase()))if(n.has(r))return n.get(r);return t.names[t.default]??""}var tt=(t,e)=>t==null?t:("e"in t)?{$:e[t.e]}:t,ge=(t,e)=>({...t,e:e[t.e]});function Lt(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:tt(n.ci,e)}),block:et(t.block,e)};case"if":return{t:t.t,branches:t.branches.map((n)=>({when:n.when==null?null:e[n.when],block:et(n.block,e)}))};case"for":return{t:t.t,args:t.args,of:t.of===void 0?void 0:e[t.of],from:tt(t.from,e),to:tt(t.to,e),by:tt(t.by,e),block:et(t.block,e)};case"switch":return{t:t.t,on:e[t.on],cases:t.cases.map((n)=>({is:n.is===null?null:tt(n.is,e),block:et(n.block,e)}))};case"async":return{t:t.t,awaitE:e[t.awaitE],then:t.then&&{args:t.then.args,block:et(t.then.block,e)},catch:t.catch&&{args:t.catch.args,block:et(t.catch.block,e)},loading:t.loading&&et(t.loading,e)};case"let":return{t:t.t,const:t.const,vars:Object.fromEntries(Object.entries(t.vars).map(([n,r])=>[n,tt(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,tt(r,e)])),lang:tt(t.lang,e),block:et(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,tt(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:et(t.contents.block,e)}}}}var et=(t,e)=>({html:t.html,scope:t.scope,binds:t.binds.map((n)=>ge(n,e)),blocks:t.blocks.map((n)=>Lt(n,e))}),Ue=(t,e,n,r)=>t.t===n.t&&JSON.stringify(Lt(t,e))===JSON.stringify(Lt(n,r)),We=(t,e,n,r)=>JSON.stringify(t.map((s)=>ge(s,e)))===JSON.stringify(n.map((s)=>ge(s,r))),qe=(t,e,n,r)=>{let s=(i,a)=>JSON.stringify(i.blocks.filter((o)=>o.t==="let").map((o)=>Lt(o,a)));return s(t,e)===s(n,r)};var Je=Symbol("lips.slot"),rr=(t)=>!!t&&typeof t==="object"&&t[Je]===!0;function Ye(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 $t=[];function Qe(){let t=!0;while(t){t=!1;for(let e of[...$t].reverse()){if(!e.live())continue;let n=$t.indexOf(e);if(n<0)continue;$t.splice(n,1),e.fn(),t=!0}}}var Ke=new Map;function sr(t){let e=Ke.get(t);if(!e)e=X(t).ast,Ke.set(t,e);return e}var bt=(t)=>t.join(",");function Ze(t,e,n){let r=e;for(let s of n)r=t.child(r,s);return r}var at=(t,e)=>t.range(e.start,e.end),Ge=(t,e,n,r)=>r===e||t.precedes(e,r)&&t.precedes(r,n);function ze(t,e){e.gen++;for(let r of e.wiring)r();e.wiring=[];let n=t.fragment();for(let r of at(t,e.inst))t.insert(n,r,null)}function Y(t,e,n){return t.insertAfter(e,at(t,n)),n}var me=(t,e)=>at(t,e).filter((n)=>t.isElement(n));function Xe(t,e,n){for(let r of me(t,e))t.scope(r,n)}function ir(t,e,n,r,s=""){for(let i of e)t.styleVar(i,n,r===null||r===void 0||r===!1?null:r+s)}function tn(t,e,n,r,s){Xe(t,n,r);let i=s.css?e.createStylesheet?.(r,s.css):void 0;return i?()=>i.clear():void 0}function or(t){for(let e of t.bindHandles)e.dispose();for(let e of t.childHandles)e.dispose()}function U(t,e){if(!e)return;or(e);for(let n of at(t,e))t.remove(n,!0)}var Nt=(t,e,n,r)=>t.attr(e,n,r===!1||r==null?null:r===!0?"":String(r)),ot=(t,e,n)=>Object.defineProperty(t,e,{get:n,enumerable:!0,configurable:!0}),ar=Symbol.for("lips.self"),en=Symbol("lips.ctx.layer");function cr(t,e,n,r){for(let s=t;s;s=Object.getPrototypeOf(s)){let a=s[en]?.get(e);if(a){a(n);return}}r?.(e,n)}function nn(t,e){let n=new Map,r=(c,...p)=>n.get(c)?.forEach((l)=>l(...p)),s,i=()=>null;return{proto:{[ar]:!0,get node(){let c=i();return c?me(t,c):[]},get lang(){return e()},pick:(c)=>Ot(c,e()),emit:r,emitLocal:r,on(c,p){return n.set(c,[...n.get(c)||[],p]),s},once(c,p){let l=(...u)=>{s.off(c,l),p(...u)};return s.on(c,l)},off(c,p){if(!p)n.delete(c);else{let l=(n.get(c)||[]).filter((u)=>u!==p);l.length?n.set(c,l):n.delete(c)}return s}},bind:(c,p)=>(s=c,i=p,c)}}class jt{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||he}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:V(()=>this.runner(r.e,n)(e))}guarded(t){let e=!0;return A(()=>{try{t()}catch(n){this.hooks?this.hooks.onError(n):console.error("[lips:ir]",n)}e?e=!1:this.hooks?.notifyUpdate()})}bindStyle(t,e,n){if(!t.binds.length)return()=>{};let r=me(this.h,e),s=t.binds.map((i)=>{let a=this.srcRunner(t.exprs[i.e],[]);return this.guarded(()=>ir(this.h,r,i.prop,a(n),i.u))});return()=>{for(let i of s)i.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=sr(t);return(s)=>ce(r,s)}let n=ae(t,e);return(r)=>n.run(r)}renderBlock(t,e){let n=this.h,r=n.clone(t),s=new Map,i=t.binds.map((f)=>{let m=Ze(n,r,f.p);return s.set(bt(f.p),m),m}),a=t.blocks.map((f)=>{let m=Ze(n,r,f.p);return s.set(bt(f.p),m),m}),o=n.marker("^"),c=n.marker("$");n.insert(r,c,null),n.insert(r,o,n.child(r,0));let p=Object.create(e.scope??null),l={...e,scope:p},u={start:o,end:c,block:t,exprs:this.ir.exprs,penv:e,benv:l,pathNodes:s,bindHandles:[],childHandles:[]};return t.blocks.forEach((f,m)=>{if(f.t!=="let")return;let g=[];for(let[b,k]of Object.entries(f.vars))if("lit"in k){let[h]=F(k.lit);ot(p,b,h)}else{let[h,x]=F(void 0);ot(p,b,h);let R=this.runner(k.e,t.scope);g.push(A(()=>x(R(l))).dispose)}u.childHandles[m]={child:f,exprs:this.ir.exprs,anchor:a[m],dispose:()=>g.forEach((b)=>b())}}),u.bindHandles=t.binds.map((f,m)=>this.bindOne(f,i[m],l,t.scope)),t.blocks.forEach((f,m)=>{if(f.t==="let")return;u.childHandles[m]={child:f,exprs:this.ir.exprs,anchor:a[m],dispose:this.execBlock(f,a[m],l,t.scope)}}),u}bindOne(t,e,n,r,s){let i=this.h;switch(t.t){case"text":{let a=s??i.text("");!s&&i.insertAfter(e,[a]);let o=this.runner(t.e,r),c=t.i18n?this.options.i18n:void 0,p=this.guarded(()=>{let l=o(n),u=l==null?"":String(l);i.setText(a,c?c.translate(u,t.ik,n.lang?.()):u)});return{bind:t,node:e,textNode:a,dispose:p.dispose}}case"attr":{let a=this.runner(t.e,r),o=t.i18n?this.options.i18n:void 0,c=this.guarded(()=>{let p=a(n);Nt(i,e,t.name,o&&p!=null?o.translate(String(p),t.ik,n.lang?.()):p)});return{bind:t,node:e,dispose:c.dispose}}case"prop":{let a=this.runner(t.e,r);if(t.name==="format"){let c=t.ref||"",p=this.guarded(()=>{let l=a(n),u=this.options.i18n?.format(c,l,n.lang?.());i.content(e,u==null?"":String(u))});return{bind:t,node:e,dispose:p.dispose}}let o=this.guarded(()=>{let c=a(n),p=c==null?"":String(c);t.name==="html"&&i.html?i.html(e,p):i.content(e,p)});return{bind:t,node:e,dispose:o.dispose}}case"event":{let a=this.eventDispatcher(this.ir.exprs[t.e],r,n);return{bind:t,node:e,dispose:i.listen(e,t.name,a)}}case"spread":{let a=this.runner(t.e,r),o=new Set,c=this.guarded(()=>{let p=a(n)||{},l=new Set(Object.keys(p));for(let u of o)!l.has(u)&&i.attr(e,u,null);for(let u of l)Nt(i,e,u,p[u]);o=l});return{bind:t,node:e,dispose:c.dispose}}}}swapBlock(t,e,n,r){if(t.block.html!==e.html||JSON.stringify(t.block.scope)!==JSON.stringify(e.scope)||!qe(t.block,t.exprs,e,this.ir.exprs))return this.rebuild(t,e,n,r);if(!We(t.block.binds,t.exprs,e.binds,this.ir.exprs)){let s=e.binds.map((o)=>t.pathNodes.get(bt(o.p)));if(s.some((o)=>!o))return this.rebuild(t,e,n,r);let i=new Map;t.bindHandles.forEach((o)=>o.textNode&&i.set(bt(o.bind.p),o.textNode)),t.bindHandles.forEach((o)=>o.dispose());let a=new Set;t.bindHandles=e.binds.map((o,c)=>{let p=bt(o.p),l=o.t==="text"?i.get(p):void 0;return l&&a.add(p),this.bindOne(o,s[c],t.benv,e.scope,l)}),i.forEach((o,c)=>!a.has(c)&&this.h.remove(o,!0)),n.push({kind:"binds",path:r})}for(let s=0;s<e.blocks.length;s++){let i=e.blocks[s],a=t.childHandles[s];if(i.t==="let")continue;if(a&&Ue(a.child,a.exprs,i,this.ir.exprs))continue;let o=this.live.filter((c)=>Ge(this.h,a.anchor,t.childHandles[s+1]?.anchor??t.end,c.anchor));for(let c of o)ze(this.h,c);a?.dispose(),t.childHandles[s]={child:i,exprs:this.ir.exprs,anchor:a.anchor,dispose:this.withSalvage(o,()=>this.execBlock(i,a.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((a)=>Ge(this.h,t.start,t.end,a.anchor));for(let a of s)ze(this.h,a);let i=this.withSalvage(s,()=>this.renderBlock(e,t.penv));return Y(this.h,t.end,i),U(this.h,t),n.push({kind:"skeleton",path:r}),i}execBlock(t,e,n,r){let s=this.h,i=[];switch(t.t){case"if":{let a=t.branches.map((l)=>l.when!=null?this.runner(l.when,r):null),o=null,c=-2,p=A(()=>{let l=-1;for(let u=0;u<t.branches.length;u++){let f=a[u];if(!f||f(n)){l=u;break}}if(l===c)return;c=l,V(()=>{if(U(s,o),o=null,l>=0)o=Y(s,e,this.renderBlock(t.branches[l].block,n))})});i.push(()=>{p.dispose(),U(s,o)});break}case"switch":{let a=this.runner(t.on,r),o=t.cases.map((u)=>u.is&&("e"in u.is)?this.runner(u.is.e,r):null),c=null,p=-2,l=A(()=>{let u=a(n),f=-1,m=-1;for(let g=0;g<t.cases.length;g++){let b=t.cases[g];if(b.is===null){m=g;continue}let k="lit"in b.is?b.is.lit:o[g](n);if(Array.isArray(k)?k.includes(u):k===u){f=g;break}}if(f===-1)f=m;if(f===p)return;p=f,V(()=>{if(U(s,c),c=null,f>=0)c=Y(s,e,this.renderBlock(t.cases[f].block,n))})});i.push(()=>{l.dispose(),U(s,c)});break}case"macro":{let a=Object.create(n.scope??null),o=Z({}),c={};for(let f of t.args)c[f]=F(void 0),ot(a,f,c[f][0]);let p=t.sets.map((f)=>{if("spread"in f)return{kind:"spread",run:this.runner(f.spread,r)};if("lit"in f.ci){let g=f.ci.lit;return{kind:"value",name:f.name,value:()=>g}}let m=this.runner(f.ci.e,r);return{kind:"value",name:f.name,value:()=>m(n)}}),l=new Set;i.push(A(()=>{let f={};for(let m of p)if(m.kind==="spread"){let g=m.run(n);if(g&&typeof g==="object")for(let[b,k]of g instanceof Map?g:Object.entries(g))f[b]=k}else f[m.name]=m.value();V(()=>{for(let g of t.args)c[g][1](f[g]);let m=new Set(Object.keys(f));for(let g of l)!m.has(g)&&delete o[g];for(let g of m)o[g]=f[g];l=m})}).dispose);let u=Y(s,e,this.renderBlock(t.block,{...n,arguments:o,scope:a}));i.push(()=>U(s,u));break}case"for":this.execFor(t,e,n,r,i);break;case"async":{let a=this.runner(t.awaitE,r),o=null,c=0,p=(u,f)=>{if(U(s,o),o=null,!u)return;let m="block"in u,g=Object.create(n.scope??null);if(m&&u.args[0]!==void 0){let[b]=F(f);ot(g,u.args[0],b)}o=Y(s,e,this.renderBlock(m?u.block:u,{...n,scope:g}))},l=A(()=>{let u=a(n),f=++c;V(()=>{t.loading?p(t.loading):p(void 0),Promise.resolve(u).then((m)=>f===c&&V(()=>p(t.then,m)),(m)=>f===c&&V(()=>p(t.catch,m)))})});i.push(()=>{c++,l.dispose(),U(s,o)});break}case"provide":{let a=Object.create(n.context??null),o=new Map;Object.defineProperty(a,en,{value:o});for(let[l,u]of Object.entries(t.vars)){let[f,m]=F("lit"in u?u.lit:void 0);if(ot(a,l,f),o.set(l,m),"lit"in u)continue;let g=this.runner(u.e,r);i.push(A(()=>m(g(n))).dispose)}let c=n.lang;if(t.lang)if("lit"in t.lang){let l=String(t.lang.lit);c=()=>l}else{let[l,u]=F(void 0),f=this.runner(t.lang.e,r);i.push(A(()=>u(f(n))).dispose),c=()=>l()??n.lang?.()}let p=Y(s,e,this.renderBlock(t.block,{...n,context:a,lang:c}));i.push(()=>U(s,p));break}case"log":{let a=oe(this.ir.exprs[t.e]).map((o)=>this.srcRunner(o,r));i.push(A(()=>console.log(...a.map((o)=>o(n)))).dispose);break}case"comp":{let a=this.options.components?.[t.name];a?this.execComponent(a,t,e,n,r,i,t.name):this.execElement(t,e,n,r,i);break}case"dynamic":{let a=this.runner(t.tag,r),o=[],c=Symbol("init"),p=A(()=>{let l=a(n);if(l===c)return;c=l,V(()=>{for(let f of o)f();if(o=[],l==null)return;if(rr(l)){let f={};for(let[g,b]of Object.entries(t.inputs))f[g]="lit"in b?b.lit:this.runner(b.e,r)(n);let m=Y(s,e,l.render(f));o.push(()=>U(s,m));return}let u=typeof l==="string"?this.options.components?.[l]:l&&typeof l==="object"?l.ir?l:this.options.resolveTemplate?.(l):void 0;if(u)this.execComponent(u,t,e,n,r,o,typeof l==="string"?l:"#dynamic");else if(typeof l==="string")this.execElement({...t,name:l},e,n,r,o)})});i.push(()=>{p.dispose();for(let l of o)l()});break}}return()=>i.forEach((a)=>a())}execFor(t,e,n,r,s){let i=this.h,a=t.of!==void 0?this.runner(t.of,r):null,o=t.by&&"e"in t.by?this.runner(t.by.e,r):null,c=t.by&&"lit"in t.by?String(t.by.lit).split("."):null,p=(b,k)=>b===void 0?void 0:("lit"in b)?b.lit:this.runner(b.e,r)(k),l=[],u=0,f=new Map,m=()=>{if(a===null){let h=Number(p(t.from,n)??0),x=Number(p(t.to,n)??h),R=h<=x,C=[];for(let v=h;R?v<=x:v>=x;R?v++:v--)C.push({key:v,values:[v]});return C}let b=a(n),k=(h,x,R)=>{if(o){let C=o(n);return typeof C==="function"?C(h,R):x}if(c)return c.reduce((C,v)=>C?.[v],h);return x};if(Array.isArray(b))return b.map((h,x)=>({key:k(h,x,x),values:[h,x]}));if(b instanceof Map)return[...b.entries()].map(([h,x],R)=>({key:h,values:[h,x,R]}));if(b instanceof Set)return[...b].map((h,x)=>({key:k(h,h,x),values:[h,x]}));if(b&&typeof b==="object")return Object.entries(b).map(([h,x],R)=>({key:h,values:[h,x,R]}));return[]},g=A(()=>{let b=m();V(()=>{let k=new Set,h=[],x=++u;for(let C of b){let v=C.key;if(k.has(v))console.warn(`<for> duplicate key '${String(v)}' — falling back to positional identity`),v=`#dup:${h.length}`;k.add(v);let d=f.get(v);if(d)d.sigs.forEach(([E,M,z],P)=>{let D=C.values[P];Object.is(E(),D)&&typeof D==="object"&&D!==null?z():M(D)}),d.pass=x,h.push(d);else{let E=Object.create(n.scope??null),M=C.values.map((D)=>F(D));t.args.forEach((D,B)=>M[B]&&ot(E,D,M[B][0]));let z=this.renderBlock(t.block,{...n,scope:E}),P={key:v,sigs:M,inst:z,pass:x};f.set(v,P),h.push(P)}}for(let C of l)if(C.pass!==x)f.delete(C.key),U(i,C.inst);let R=e;for(let C of h){if(i.next(R)!==C.inst.start)Y(i,R,C.inst);R=C.inst.end}l=h})});s.push(()=>{g.dispose();for(let b of l)U(i,b.inst);l=[],f.clear()})}wireInputs(t,e,n,r,s,i){for(let[a,o]of Object.entries(t.inputs))if(i?.add(a),"lit"in o)r[a]=o.lit;else{let c=this.runner(o.e,n);s.push(A(()=>r[a]=c(e)).dispose)}for(let a of t.spreads){let o=this.runner(a,n);s.push(A(()=>{let c=o(e)||{};V(()=>Object.entries(c).forEach(([p,l])=>{i?.add(p),r[p]=l}))}).dispose)}}wireEvents(t,e,n,r,s){t?.forEach((i)=>{let a=this.eventDispatcher(this.ir.exprs[i.e],n,e);r.on(i.name,a),s.push(()=>r.off(i.name,a))})}slotRenderer(t,e){let n=this;return{[Je]:!0,args:t.args,render(r){let s=Object.create(e.scope??null);return t.args.forEach((i)=>{let[a]=F(r?.[i]);ot(s,i,a)}),n.renderBlock(t.block,{...e,scope:s})}}}adoptComponent(t,e,n,r,s,i){let a=[],o=new Set;if(this.wireInputs(e,r,s,t.input,a,o),e.contents)t.input.renderer=this.slotRenderer(e.contents,r),o.add("renderer");for(let p of Object.keys(t.input))!o.has(p)&&delete t.input[p];this.wireEvents(e.events,r,s,t.self,a),t.wiring=a,t.anchor=n;let c=t.gen;Y(this.h,n,t.inst),i.push(()=>{if(c!==t.gen)return;for(let p of t.wiring)p();t.wiring=[],t.teardown()})}execComponent(t,e,n,r,s,i,a){let o=this.pool?.length?this.claim(a,this.keyOf(e.inputs,r,s)):void 0;if(o)return this.adoptComponent(o,e,n,r,s,i);let c=Z({}),p=[];if(this.wireInputs(e,r,s,c,p),e.contents)c.renderer=this.slotRenderer(e.contents,r);let l=Z({...t.state||{}},t.deep??!1),u=null,f=this,m=nn(this.h,()=>r.lang?.()??f.options.i18n?.lang()??""),g=m.bind(Object.assign(Object.create(m.proto),{...this.options.expose||{},state:l,input:c,static:t.statics,context:r.context,setContext(P,D){let B=(dt,pt)=>cr(r.context,dt,pt,f.options.expose?.setContext);typeof P==="string"?B(P,D):Object.entries(P||{}).forEach(([dt,pt])=>B(dt,pt))}}),()=>u);t.handlers&&Object.entries(t.handlers).forEach(([P,D])=>g[P]=D.bind(g)),this.wireEvents(e.events,r,s,g,p);let b=Ye(g);try{typeof g.onCreate==="function"&&g.onCreate()}catch(P){b.onError(P)}try{Object.keys(c).length&&typeof g.onInput==="function"&&g.onInput(c)}catch(P){b.onError(P)}let k={state:l,input:c,context:r.context,lang:r.lang,static:t.statics,self:g,scope:void 0},h=new jt(t.ir,this.options,b),x=h.renderBlock(t.ir.root,k);u=x;let R=t.stylesheet?tn(this.h,this.options,x,t.stylesheet.nsp||t.nsp||"lips",t.stylesheet):void 0,C=t.stylesheet?h.bindStyle(t.stylesheet,x,k):void 0;Y(this.h,n,x),b.ready();try{typeof g.onMount==="function"&&g.onMount(),typeof g.onRender==="function"&&g.onRender(),g.emit("component:mount")}catch(P){b.onError(P)}let v;if(t.context?.length&&typeof g.onContext==="function"){let P=!0,{dispose:D}=A(()=>{for(let B of t.context)k.context?.[B];if(P){P=!1;return}V(()=>{try{g.onContext()}catch(B){b.onError(B)}})});v=D}let d=!1;$t.push({live:()=>this.h.connected(x.start),fn:()=>{d=!0;try{typeof g.onAttach==="function"&&g.onAttach(),g.emit("component:attached")}catch(P){b.onError(P)}}}),this.h.connected(x.start)&&Qe();let E=!1,M={name:a,key:c.key,self:g,input:c,inst:x,anchor:n,wiring:p,gen:0,claimed:!1,teardown:()=>{if(E)return;E=!0;let P=this.live.indexOf(M);P>-1&&this.live.splice(P,1),v?.(),C?.(),R?.(),U(this.h,x);try{if(d)typeof g.onDetach==="function"&&g.onDetach(),g.emit("component:detached");typeof g.onDestroy==="function"&&g.onDestroy(),g.emit("component:destroy")}catch(D){b.onError(D)}}};this.live.push(M);let z=M.gen;i.push(()=>{if(z!==M.gen)return;for(let P of M.wiring)P();M.wiring=[],M.teardown()})}execElement(t,e,n,r,s){let i=this.h,a=i.element(t.name);for(let[o,c]of Object.entries(t.inputs))if("lit"in c)Nt(i,a,o,c.lit);else{let p=this.runner(c.e,r);s.push(A(()=>Nt(i,a,o,p(n))).dispose)}for(let o of t.events)s.push(i.listen(a,o.name,this.eventDispatcher(this.ir.exprs[o.e],r,n)));if(t.contents){let o=this.renderBlock(t.contents.block,n);for(let c of at(i,o))i.insert(a,c,null);s.push(()=>U(i,o))}i.insertAfter(e,[a]),s.push(()=>i.remove(a,!0))}eventDispatcher(t,e,n){let r=oe(t);return(...s)=>V(()=>{let i=(c)=>{let p;try{p=this.srcRunner(c,e)(n)}catch(l){p=void 0}if(typeof p!=="function"&&n.self&&!this.options.guard?.self(c)&&typeof n.self[c]==="function")p=n.self[c];return p};if(!r.length)return;let a=i(r[0]);if(typeof a!=="function")return;let o=r.slice(1).map((c)=>this.srcRunner(c,e)(n));a(...o,...s)})}}function At(t,e={},n={}){let r=n.host||he,s=Z(e.state||{},e.deep??!1),i=e.input?Z(e.input,e.deep??!1):void 0,a=null,o=nn(r,()=>n.i18n?.lang()??""),c=o.bind(Object.assign(Object.create(o.proto),{state:s,input:i,static:e.static,...n.expose||{},...e.expose||{}}),()=>a);e.handlers&&Object.entries(e.handlers).forEach(([h,x])=>c[h]=x.bind(c));let p={state:s,input:i,context:e.context,static:e.static,self:c,scope:void 0},l=Ye(c);try{typeof c.onCreate==="function"&&c.onCreate()}catch(h){l.onError(h)}try{i&&Object.keys(i).length&&typeof c.onInput==="function"&&c.onInput(i)}catch(h){l.onError(h)}let u=new jt(t,n,l),f=u.renderBlock(t.root,p);a=f,l.ready();let m=e.stylesheet?tn(r,n,f,e.stylesheet.nsp||e.nsp||"lips",e.stylesheet):void 0,g=e.stylesheet?u.bindStyle(e.stylesheet,f,p):void 0;try{typeof c.onMount==="function"&&c.onMount(),typeof c.onRender==="function"&&c.onRender()}catch(h){l.onError(h)}let b=!1,k=()=>{if(b)return;b=!0;try{typeof c.onAttach==="function"&&c.onAttach(),c.emit("component:attached")}catch(h){l.onError(h)}};return{state:s,self:c,get nodes(){return at(r,f)},mount(h){for(let x of at(r,f))r.insert(h,x,null);if(r.connected(f.start))k(),Qe()},swap(h){let x=[],R=r.keepFocus?.();if(u=new jt(h,n,l,u.live),f=u.swapBlock(f,h.root,x,"root"),a=f,e.stylesheet)Xe(r,f,e.stylesheet.nsp||e.nsp||"lips"),g?.(),g=u.bindStyle(e.stylesheet,f,p);return R?.(),{changes:x,salvaged:u.salvaged}},dispose(){g?.(),m?.(),U(r,f);try{if(b)typeof c.onDetach==="function"&&c.onDetach(),c.emit("component:detached");typeof c.onDestroy==="function"&&c.onDestroy()}catch(h){l.onError(h)}}}}class _t{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 i={};for(let a in s)i[a]=n(s[a]);return i}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 Dt{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 lr="en-US";class Bt{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||lr,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 yt(t.toLowerCase()).some((e)=>!!this.DICTIONARIES[e])}setLoader(t){return this.loader=t,this}load(t){return Promise.all(yt(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 yt(e.toLowerCase())){let i=this.DICTIONARIES[s];if(!i||!Object.prototype.hasOwnProperty.call(i,t))continue;try{r=new this.engine.MessageFormat(e,i[t],{functions:this.functions})}catch(a){this.onError?.(a,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,i=this.message(s,r);if(i)t=i.format(void 0,(a)=>this.onError?.(a,s,r));else if(i===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,(i)=>this.onError?.(i,t,r));s===void 0&&this.onMissing?.(t,r)}pick(t,e){return Ot(t,e||this.currentLang)}}var Ft=null;function rn(t){Ft=t}var Ht=null;function sn(t){Ht=t}var on;function an(t){on=t}var cn={};function ln(t,e){cn[t]=e}var pr=new Set(["state","input","static","context","emit","on","once","off","node","lang","setContext","setLanguage","destroy","appendTo","prependTo","replaceWith","render","swap"]);function pn(t){if(!t)return;for(let e of Object.keys(t))if(pr.has(e))throw Error(`Handler <${e}> is a reserved component member name`);return t}class un extends _t{lips;template;state;instance;contextWatcher;destroyed=!1;constructor(t,e,n,r,s,i){super();this.lips=t;this.template=n;let a=pn(n.handler);this.state=Z({...n.state||{}},!0);let o=r?Z({...r},!0):void 0,c=(l,...u)=>super.emit(l,...u);this.instance=At(s,{state:this.state,input:o,context:t.getContext(),static:n.static??n._static,handlers:a,deep:!0,stylesheet:t.styleFor(e,n),nsp:e,expose:{emit(l,...u){this.emitLocal?.(l,...u),c(l,...u)},context:t.getContext()}},i);let p=n.watchContext??n.context;if(p?.length&&typeof a?.onContext==="function")this.contextWatcher=t.watchContext(p,()=>{try{a.onContext.call(this.instance.self)}catch(l){console.error("[lips:ir]",l)}});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 de{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=Z({...t?.context||{}},!0),this.i18n=new Bt(t?.lang,t?.messageFormat??on),this.debug)this.i18n.onMissing=(a,o)=>console.warn(`[lips:i18n] no <${o}> entry for key "${a}"`),this.i18n.onError=(a,o,c)=>console.warn(`[lips:i18n] <${c}> message "${o}" —`,a);let[e,n]=F(this.i18n.lang);this.getLang=e,this.setLang=n;let[r,s]=F(0);this.getRev=r,this.i18n.onChange=()=>s(r()+1),Ft&&Object.entries(cn).forEach(([a,o])=>this.register(a,o));let i=this;this.componentsProxy=new Proxy({},{get(a,o){let c=i.store.get(o);return c?i.defFor(o,c):void 0},has(a,o){return i.store.has(o)}})}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(!Ft)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=Ft(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(!Ht){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(Ht):Ht)(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:pn(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,i)=>this.setContext(s,i),setLanguage:(s)=>this.setLanguage(s)},createStylesheet:(s,i)=>{let a=new Dt(s,{sheet:i});return{clear:()=>a.clear()}},i18n:{translate:(s,i,a)=>{let o=this.getLang();return this.getRev(),this.i18n.translate(s,a||o,i).text},format:(s,i,a)=>{let o=this.getLang();return this.getRev(),this.i18n.format(s,i,a||o)??""},lang:()=>this.getLang()}};return new un(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}=A(()=>{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}=A(()=>{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 ur=globalThis,Vt=ur.Intl??={},fn=(t)=>(Array.isArray(t)?t:t?[t]:[]).map(String),ye=(t)=>class{options;constructor(e,n){this.options={...n,locale:fn(e)[0]??"und"}}static supportedLocalesOf(e){return fn(e)}resolvedOptions(){return this.options}format(e){return t(e)}formatToParts(e){return[{type:"literal",value:t(e)}]}select(){return"other"}};Vt.Locale??=class{baseName;language;constructor(t){this.baseName=String(t),this.language=this.baseName.split("-")[0]}maximize(){return this}toString(){return this.baseName}};Vt.NumberFormat??=ye(String);Vt.PluralRules??=ye(String);Vt.DateTimeFormat??=ye((t)=>{let e=new Date(t);return isNaN(e.getTime())?String(t):e.toISOString()});var hn=/^[\u061c\u200e\u200f\u2066-\u2069]+/,gn=/^[-.+0-9A-Z_a-z\u{a1}-\u{61b}\u{61d}-\u{167f}\u{1681}-\u{1fff}\u{200b}-\u{200d}\u{2010}-\u{2027}\u{2030}-\u{205e}\u{2060}-\u{2065}\u{206a}-\u{2fff}\u{3001}-\u{d7ff}\u{e000}-\u{fdcf}\u{fdf0}-\u{fffd}\u{10000}-\u{1fffd}\u{20000}-\u{2fffd}\u{30000}-\u{3fffd}\u{40000}-\u{4fffd}\u{50000}-\u{5fffd}\u{60000}-\u{6fffd}\u{70000}-\u{7fffd}\u{80000}-\u{8fffd}\u{90000}-\u{9fffd}\u{a0000}-\u{afffd}\u{b0000}-\u{bfffd}\u{c0000}-\u{cfffd}\u{d0000}-\u{dfffd}\u{e0000}-\u{efffd}\u{f0000}-\u{ffffd}\u{100000}-\u{10fffd}]+/u,fr=/^[-.0-9]/;function mn(t,e){let n=e,r=t.slice(n).match(hn);if(r)n+=r[0].length;let s=t.slice(n).match(gn);if(!s)return null;let i=s[0];if(fr.test(i))return null;n+=i.length;let a=t.slice(n).match(hn);if(a)n+=a[0].length;return{value:i.normalize(),end:n}}var dn=(t,e)=>t.slice(e).match(gn)?.[0]??"";var yn=Symbol.for("CST");class nt extends Error{type;constructor(t,e){super(e);this.type=t}}class ct extends nt{start;end;constructor(t,e,n,r){let s=r?`Missing ${r}`:t;if(e>=0)s+=` at ${e}`;super(t,s);this.start=e,this.end=n??e+1}}class Ut extends ct{constructor(t,e){let{start:n,end:r}=e[yn]??{start:-1,end:-1};super(t,n,r)}}class G extends nt{source;cause;constructor(t,e,n,r){super(t,e);if(this.source=n,r!==void 0)this.cause=r}}class L extends nt{source;cause;constructor(t,e){super(t,e);this.source="�"}}var bn=new Set("؜‎‏⁦⁧⁨⁩"),xn=new Set(`
4
- \r  `),y,w,xt=(t,e)=>new ct("missing-syntax",t,t+e.length,e),W=(...t)=>new ct(...t);function gt(t,e){if(w.startsWith(t,y)){if(e)y+=t.length}else throw xt(y,t)}function be(t){y=0,w=t;let e=mr();if(w.startsWith(".match",y))return hr(e);let n=e.length>0||w.startsWith("{{",y);if(!n&&y>0)y=0;let r=kn(n);if(n){if(_(),y<w.length)throw W("extra-content",y,w.length)}return{type:"message",declarations:e,pattern:r}}function hr(t){y+=6,_(!0);let e=[];while(w[y]==="$")e.push(En()),_(!0);if(e.length===0)throw W("empty-token",y);let n=[];while(y<w.length)n.push(gr()),_();return{type:"select",declarations:t,selectors:e,variants:n}}function gr(){let t=[];while(y<w.length){_(t.length?"{":!1);let e=w[y];if(e==="{")break;if(e==="*")t.push({type:"*"}),y+=1;else{let n=ve(!0);n.value=n.value.normalize(),t.push(n)}}return{keys:t,value:kn(!0)}}function kn(t){if(t)if(w.startsWith("{{",y))y+=2;else throw xt(y,"{{");let e=[];t:while(y<w.length)switch(w[y]){case"{":{e.push(xe(!0));break}case"}":if(!t)throw W("parse-error",y);break t;default:e.push(xr())}if(t)if(w.startsWith("}}",y))y+=2;else throw xt(y,"}}");return e}function mr(){let t=[];_();t:while(w[y]==="."){switch(w.substr(y,6)){case".input":t.push(dr());break;case".local":t.push(yr());break;case".match":break t;default:throw W("parse-error",y)}_()}return t}function dr(){y+=6,_(),gt("{",!1);let t=y,e=xe(!1);if(e.type==="expression"&&e.arg?.type==="variable")return{type:"input",name:e.arg.name,value:e};throw W("bad-input-expression",t,y)}function yr(){y+=6,_(!0),gt("$",!0);let t=qt();_(),gt("=",!0),_(),gt("{",!1);let e=xe(!1);return{type:"local",name:t,value:e}}function xe(t){let e=y;y+=1,_();let n=Sn(!1);if(n)_("}");let r=w[y],s,i;switch(r){case"@":case"}":break;case":":{y+=1,s={type:"function",name:Wt()};let o=vn();if(o)s.options=o;break}case"#":case"/":{if(n||!t)throw W("parse-error",y);y+=1,i={type:"markup",kind:r==="#"?"open":"close",name:Wt()};let c=vn();if(c)i.options=c;break}default:throw W("parse-error",y)}let a=br();if(i?.kind==="open"&&w[y]==="/")i.kind="standalone",y+=1;if(gt("}",!0),s){let o=n?{type:"expression",arg:n,functionRef:s}:{type:"expression",functionRef:s};if(a)o.attributes=a;return o}if(i){if(a)i.attributes=a;return i}if(!n)throw W("empty-token",e,y);return a?{type:"expression",arg:n,attributes:a}:{type:"expression",arg:n}}function vn(){_("/}");let t={},e=!0;while(y<w.length){let n=w[y];if(n==="@"||n==="/"||n==="}")break;let r=y,s=Wt();if(Object.hasOwn(t,s))throw W("duplicate-option-name",r,y);_(),gt("=",!0),_(),t[s]=Sn(!0),e=!1,_("/}")}return e?null:t}function br(){let t={},e=!0;while(w[y]==="@"){let n=y;y+=1;let r=Wt();if(Object.hasOwn(t,r))throw W("duplicate-attribute",n,y);if(_("=/}"),w[y]==="=")y+=1,_(),t[r]=ve(!0),_("/}");else t[r]=!0;e=!1}return e?null:t}function xr(){let t="",e=y;t:for(;e<w.length;++e)switch(w[e]){case"\\":{let n=w[e+1];if(!"\\{|}".includes(n))throw W("bad-escape",e,e+2);t+=w.substring(y,e)+n,e+=1,y=e+1;break}case"{":case"}":break t}return t+=w.substring(y,e),y=e,t}function Sn(t){return w[y]==="$"?En():ve(t)}function En(){return y+=1,{type:"variable",name:qt()}}function ve(t){if(w[y]==="|")return vr();let e=dn(w,y);if(!e)if(t)throw W("empty-token",y);else return;return y+=e.length,{type:"literal",value:e}}function vr(){y+=1;let t="";for(let e=y;e<w.length;++e)switch(w[e]){case"\\":{let n=w[e+1];if(!"\\{|}".includes(n))throw W("bad-escape",e,e+2);t+=w.substring(y,e)+n,e+=1,y=e+1;break}case"|":return t+=w.substring(y,e),y=e+1,{type:"literal",value:t}}throw xt(w.length,"|")}function Wt(){let t=qt();if(w[y]===":")return y+=1,t+":"+qt();return t}function qt(){let t=mn(w,y);if(!t)throw W("empty-token",y);return y=t.end,t.value}function _(t=!1){let e=w[y],n=!1;if(t){while(bn.has(e))e=w[++y];while(xn.has(e))e=w[++y],n=!0}while(bn.has(e)||xn.has(e))e=w[++y];if(t&&!n&&(t===!0||!t.includes(w[y])))throw xt(y,"' '")}function ke(t,e){let{node:n,pattern:r}=e,{functionRef:s=n,attributes:i=null,declaration:a=n,expression:o=n,key:c=n,markup:p=n,options:l=null,value:u=n,variant:f=n}=e,m=(h,x)=>{if(h){let R=l?.(h,x);if(u)for(let C of Object.values(h))u(C,x,"option");R?.()}},g=(h,x)=>{if(h){let R=i?.(h,x);if(u){for(let C of Object.values(h))if(C!==!0)u(C,x,"attribute")}R?.()}},b=(h,x)=>{if(typeof h==="object"){let R;switch(h.type){case"expression":{if(R=o?.(h,x),h.arg)u?.(h.arg,x,"arg");if(h.functionRef){let C=s?.(h.functionRef,x,h.arg);m(h.functionRef.options,x),C?.()}g(h.attributes,x);break}case"markup":{R=p?.(h,x),m(h.options,x),g(h.attributes,x);break}}R?.()}},k=(h)=>{let x=r?.(h);for(let R of h)b(R,"placeholder");x?.()};for(let h of t.declarations){let x=a?.(h);if(h.value)b(h.value,"declaration");x?.()}if(t.type==="message")k(t.pattern);else{if(u)for(let h of t.selectors)u(h,"selector","arg");for(let h of t.variants){let x=f?.(h);if(c)h.keys.forEach(c);k(h.value),x?.()}}}function Se(t,e=(n,r)=>{throw new Ut(n,r)}){let n=0,r=null,s=new Set,i=new Set,a=new Set,o=new Set,c=new Set,p=new Set,l=!0;if(ke(t,{declaration(u){if(!u.name)return;if(u.value.functionRef||u.type==="local"&&u.value.arg?.type==="variable"&&s.has(u.value.arg.name))s.add(u.name);if(u.type==="local")o.add(u.name);return l=u.type==="local",()=>{if(i.has(u.name))e("duplicate-declaration",u);else i.add(u.name)}},expression({functionRef:u}){if(u)a.add(u.name)},value(u,f,m){if(u.type!=="variable")return;switch(c.add(u.name),f){case"declaration":if(m!=="arg"||l)i.add(u.name);break;case"selector":if(n+=1,r=u,!s.has(u.name))e("missing-selector-annotation",u)}},variant(u){let{keys:f}=u;if(f.length!==n)e("key-mismatch",u);let m=JSON.stringify(f.map((g)=>g.type==="literal"?g.value:0));if(p.has(m))e("duplicate-variant",u);else p.add(m);r&&=f.every((g)=>g.type==="*")?null:u}}),r)e("missing-fallback",r);for(let u of o)c.delete(u);return{functions:a,variables:c}}var Ee="⁦",we="⁧",vt="⁨",kt="⁩";function rt(t){if(t)try{if(typeof t==="string")t=new Intl.Locale(t);let e=t.getTextInfo?.()??t.textInfo;if(e?.direction)return e.direction;let n=t.maximize().script;if(n)return"Adlm,Arab,Hebr,Mand,Nkoo,Rohg,Syrc,Thaa".includes(n)?"rtl":"ltr"}catch{}return"auto"}function Ie(t){if(t&&typeof t==="object")t=t.valueOf();if(typeof t==="boolean")return t;if(t&&typeof t==="object")t=String(t);if(t==="true")return!0;if(t==="false")return!1;throw RangeError("Not a boolean")}function q(t){if(t&&typeof t==="object")t=t.valueOf();if(t&&typeof t==="object")t=String(t);if(typeof t==="string"&&/^(0|[1-9][0-9]*)$/.test(t))t=Number(t);if(typeof t==="number"&&t>=0&&Number.isInteger(t))return t;throw RangeError("Not a positive integer")}function H(t){if(t&&typeof t==="object")t=t.valueOf();if(typeof t==="string")return t;if(t&&typeof t==="object")return String(t);throw RangeError("Not a string")}function Q(t){let e=void 0;if(typeof t==="object"){let n=t?.valueOf;if(typeof n==="function")e=t.options,t=n.call(t)}if(typeof t==="string")try{t=JSON.parse(t)}catch{}if(typeof t!=="bigint"&&typeof t!=="number")throw new L("bad-operand","Input is not numeric");return{value:t,options:e}}function st(t,e,n,r){let{dir:s,locales:i}=t;if(n.useGrouping==="never")n.useGrouping=!1;if(r&&"select"in n&&!t.literalOptionKeys.has("select"))t.onError("bad-option","The option select may only be set by a literal value"),r=!1;let a,o,c,p;return{type:"number",get dir(){if(s==null)a??=Intl.NumberFormat.supportedLocalesOf(i,n)[0],s=rt(a);return s},get options(){return{...n}},selectKey:r?(l)=>{let u=e;if(n.style==="percent")if(typeof u==="bigint")u*=100n;else u*=100;let f=String(u);if(l.has(f))return f;if(n.select==="exact")return null;let m=n.select?{...n,select:void 0,type:n.select}:n;return c??=new Intl.PluralRules(i,m).select(Number(u)),l.has(c)?c:null}:void 0,toParts(){o??=new Intl.NumberFormat(i,n);let l=o.formatToParts(e);return a??=o.resolvedOptions().locale,s??=rt(a),s==="ltr"||s==="rtl"?[{type:"number",dir:s,locale:a,parts:l}]:[{type:"number",locale:a,parts:l}]},toString(){return o??=new Intl.NumberFormat(i,n),p??=o.format(e),p},valueOf:()=>e}}function Kt(t,e,n){let r=Q(n),s=r.value,i=Object.assign({},r.options,{localeMatcher:t.localeMatcher,style:"decimal"});for(let[a,o]of Object.entries(e)){if(o===void 0)continue;try{switch(a){case"minimumIntegerDigits":case"minimumFractionDigits":case"maximumFractionDigits":case"minimumSignificantDigits":case"maximumSignificantDigits":case"roundingIncrement":i[a]=q(o);break;case"roundingMode":case"roundingPriority":case"select":case"signDisplay":case"trailingZeroDisplay":case"useGrouping":i[a]=H(o)}}catch{t.onError("bad-option",`Value ${o} is not valid for :number option ${a}`)}}return st(t,s,i,!0)}function wn(t,e,n){let r=Q(n),s=Number.isFinite(r.value)?Math.round(r.value):r.value,i=Object.assign({},r.options,{maximumFractionDigits:0,minimumFractionDigits:void 0,minimumSignificantDigits:void 0,style:"decimal"});for(let[a,o]of Object.entries(e)){if(o===void 0)continue;try{switch(a){case"minimumIntegerDigits":case"maximumSignificantDigits":i[a]=q(o);break;case"select":case"signDisplay":case"useGrouping":i[a]=H(o)}}catch{t.onError("bad-option",`Value ${o} is not valid for :integer option ${a}`)}}return st(t,s,i,!0)}function In(t,e,n){let r=Q(n),s=Object.assign({},r.options,{localeMatcher:t.localeMatcher,style:"currency"});for(let[i,a]of Object.entries(e)){if(a===void 0)continue;try{switch(i){case"currency":case"currencySign":case"roundingMode":case"roundingPriority":case"trailingZeroDisplay":case"useGrouping":s[i]=H(a);break;case"minimumIntegerDigits":case"minimumSignificantDigits":case"maximumSignificantDigits":case"roundingIncrement":s[i]=q(a);break;case"currencyDisplay":{let o=H(a);if(o==="never")t.onError("unsupported-operation",'Currency display "never" is not yet supported');else s[i]=o;break}case"fractionDigits":{let o=H(a);if(o==="auto")s.minimumFractionDigits=void 0,s.maximumFractionDigits=void 0;else{let c=q(o);s.minimumFractionDigits=c,s.maximumFractionDigits=c}break}}}catch{t.onError("bad-option",`Value ${a} is not valid for :currency option ${i}`)}}if(!s.currency)throw new L("bad-operand","A currency code is required for :currency");return st(t,r.value,s,!1)}var Ir=new Set(["weekday","day-weekday","month-day","month-day-weekday","year-month-day","year-month-day-weekday"]),Rr=new Set(["long","medium","short"]),Cr=new Set(["hour","minute","second"]),Tr=new Set(["long","short"]),Rn=(t,e,n)=>Re("datetime",t,e,n),Cn=(t,e,n)=>Re("date",t,e,n),Tn=(t,e,n)=>Re("time",t,e,n);function Re(t,e,n,r){let s={localeMatcher:e.localeMatcher},i=r;if(typeof i==="object"&&i!==null){let l=i.options;if(l){if(s.calendar=l.calendar,t!=="date")s.hour12=l.hour12;s.timeZone=l.timeZone}if(typeof i.valueOf==="function")i=i.valueOf()}switch(typeof i){case"number":case"string":i=new Date(i)}if(!(i instanceof Date)||isNaN(i.getTime()))throw new L("bad-operand","Input is not a valid date");if(n.calendar!==void 0)try{s.calendar=H(n.calendar)}catch{e.onError("bad-option",`Invalid :${t} calendar option value`)}if(n.hour12!==void 0&&t!=="date")try{s.hour12=Ie(n.hour12)}catch{e.onError("bad-option",`Invalid :${t} hour12 option value`)}if(n.timeZone!==void 0){let l;try{l=H(n.timeZone)}catch{e.onError("bad-option",`Invalid :${t} timeZone option value`)}if(l==="input"){if(s.timeZone===void 0)e.onError("bad-operand",`Missing input timeZone value for :${t}`)}else if(l!==void 0){if(s.timeZone!==void 0&&l!==s.timeZone)throw new L("bad-option","Time zone conversion is not supported");s.timeZone=l}}if(t!=="time"){let l=t==="date"?"fields":"dateFields",u=t==="date"?"length":"dateLength",f=Zt(e,n,l,Ir)??"year-month-day",m=Zt(e,n,u,Rr),g=new Set(f.split("-"));if(g.has("year"))s.year="numeric";if(g.has("month"))s.month=m==="long"?"long":m==="short"?"numeric":"short";if(g.has("day"))s.day="numeric";if(g.has("weekday"))s.weekday=m==="long"?"long":"short"}if(t!=="date"){switch(Zt(e,n,t==="time"?"precision":"timePrecision",Cr)){case"hour":s.hour="numeric";break;case"second":s.hour="numeric",s.minute="numeric",s.second="numeric";break;default:s.hour="numeric",s.minute="numeric"}s.timeZoneName=Zt(e,n,"timeZoneStyle",Tr)}let a=new Intl.DateTimeFormat(e.locales,s),o=e.dir,c,p;return{type:"datetime",get dir(){if(o==null)c??=a.resolvedOptions().locale,o=rt(c);return o},get options(){return{...s}},toParts(){let l=a.formatToParts(i);return c??=a.resolvedOptions().locale,o??=rt(c),o==="ltr"||o==="rtl"?[{type:"datetime",dir:o,locale:c,parts:l}]:[{type:"datetime",locale:c,parts:l}]},toString(){return p??=a.format(i),p},valueOf:()=>i}}function Zt(t,e,n,r){let s=e[n];if(s!==void 0)try{let i=H(s);if(r&&!r.has(i))throw Error();return i}catch{t.onError("bad-option",`Invalid value for ${n} option`)}return}function Mn(t,e,n){let{value:r,options:s}=Q(n),i;try{i="add"in e?q(e.add):-1}catch{throw new L("bad-option",`Value ${e.add} is not valid for :offset option add`)}let a;try{a="subtract"in e?q(e.subtract):-1}catch{throw new L("bad-option",`Value ${e.subtract} is not valid for :offset option subtract`)}if(i<0===a<0)throw new L("bad-option",'Exactly one of "add" or "subtract" is required as an :offset option');let o=i<0?-a:i;if(typeof r==="number")r+=o;else r+=BigInt(o);return Kt(t,{},{valueOf:()=>r,options:s})}function Pn(t,e,n){let r=Q(n),s=Object.assign({},r.options,{localeMatcher:t.localeMatcher,style:"percent"});for(let[i,a]of Object.entries(e)){if(a===void 0)continue;try{switch(i){case"roundingMode":case"roundingPriority":case"signDisplay":case"trailingZeroDisplay":case"useGrouping":s[i]=H(a);break;case"minimumFractionDigits":case"maximumFractionDigits":case"minimumSignificantDigits":case"maximumSignificantDigits":s[i]=q(a);break}}catch{t.onError("bad-option",`Value ${a} is not valid for :percent option ${i}`)}}return st(t,r.value,s,!0)}function Gt(t,e,n){let r=n===void 0?"":String(n),s=r.normalize();return{type:"string",dir:t.dir??"auto",selectKey:(i)=>i.has(s)?s:null,toParts(){let{dir:i}=t,a=t.locales[0];return i==="ltr"||i==="rtl"?[{type:"string",dir:i,locale:a,value:r}]:[{type:"string",locale:a,value:r}]},toString:()=>r,valueOf:()=>r}}function On(t,e,n){let r=Q(n),s=Object.assign({},r.options,{localeMatcher:t.localeMatcher,style:"unit"});for(let[i,a]of Object.entries(e)){if(a===void 0)continue;try{switch(i){case"signDisplay":case"roundingMode":case"roundingPriority":case"trailingZeroDisplay":case"unit":case"unitDisplay":case"useGrouping":s[i]=H(a);break;case"minimumIntegerDigits":case"minimumFractionDigits":case"maximumFractionDigits":case"minimumSignificantDigits":case"maximumSignificantDigits":case"roundingIncrement":s[i]=q(a);break}}catch(o){if(o instanceof nt)t.onError(o);else t.onError("bad-option",`Value ${a} is not valid for :currency option ${i}`)}}if(!s.unit)throw new L("bad-operand","A unit identifier is required for :unit");return st(t,r.value,s,!1)}var St={currency:In,integer:wn,number:Kt,offset:Mn,percent:Pn,string:Gt};St=Object.freeze(Object.assign(Object.create(null),St));var zt={date:Cn,datetime:Rn,time:Tn,unit:On};zt=Object.freeze(Object.assign(Object.create(null),zt));var Et=Symbol("bidi-isolate");var wt=(t="�")=>({type:"fallback",source:t,toParts:()=>[{type:"fallback",source:t}],toString:()=>`{${t}}`});var Ln=(t,e)=>({type:"unknown",source:t,dir:"auto",toParts:()=>[{type:"unknown",value:e}],toString:()=>String(e),valueOf:()=>e});class lt{#t;#e;#n;dir;id;constructor(t,e,n){this.#t=t,this.#n=e,this.dir=void 0;let r=n&&Object.hasOwn(n,"u:dir")?n["u:dir"]:void 0;if(r){let i=String(it(t,r));if(i==="ltr"||i==="rtl"||i==="auto")this.dir=i;else if(i!=="inherit"){let a=new L("bad-option","Unsupported value for u:dir option");a.source=mt(r),t.onError(a)}}let s=n&&Object.hasOwn(n,"u:id")?n["u:id"]:void 0;if(this.id=s?String(it(t,s)):void 0,n){this.#e=new Set;for(let[i,a]of Object.entries(n))if(a.type==="literal")this.#e.add(i)}}get literalOptionKeys(){return new Set(this.#e)}get localeMatcher(){return this.#t.localeMatcher}get locales(){return this.#t.locales.map(String)}onError(t,e){let n;if(t instanceof L)n=t;else if(typeof t==="string"&&typeof e==="string")n=new L(t,e);else n=new L("function-error",String(t)),n.cause=t;n.source=this.#n,this.#t.onError(n)}}function Nn(t,e,{name:n,options:r}){let s=`:${n}`,i=mt(e)??s;try{let a=e?[it(t,e)]:[],o=t.functions[n];if(!o)throw new G("unknown-function",`Unknown function ${s}`,i);let c=new lt(t,i,r),p=Mr(t,r),l=o(c,p,...a);if(l===null||typeof l!=="object"||typeof l.type!=="string")throw new G("bad-function-result",`Function ${s} did not return a MessageValue`,i);let u={source:i};if(c.dir)u.dir=c.dir,u[Et]=!0;if(c.id&&typeof l.toParts==="function")u.toParts=()=>{let f=l.toParts();for(let m of f)m.id=c.id;return f};return{...l,...u}}catch(a){return t.onError(a instanceof nt?a:new G("bad-function-result",String(a),i,a)),wt(i)}}function Mr(t,e){let n=Object.create(null);if(e){for(let[r,s]of Object.entries(e))if(!r.startsWith("u:"))n[r]=it(t,s)}return n}function It(t,{arg:e,functionRef:n}){if(n)return Nn(t,e,n);switch(e?.type){case"literal":{let r=`|${e.value}|`,s=new lt(t,r),i=Gt(s,{},e.value);return i.source=r,i}case"variable":return Jt(t,e);default:throw Error(`Unsupported expression: ${e?.type}`)}}class Yt{expression;scope;constructor(t,e){this.expression=t,this.scope=e}}var Pr=(t)=>t!==null&&(typeof t==="object"||typeof t==="function");function $n(t,e){if(Pr(t)){if(e in t)return t[e];let n=e.split(".");for(let r=n.length-1;r>0;--r){let s=n.slice(0,r).join(".");if(s in t){let i=n.slice(r).join(".");return $n(t[s],i)}}for(let[r,s]of Object.entries(t))if(r.normalize()===e)return s}return}function Ce(t,{name:e}){let n=$n(t.scope,e);if(n===void 0){let r="$"+e,s=`Variable not available: ${r}`;t.onError(new G("unresolved-variable",s,r))}else if(n instanceof Yt){let r=It(n.scope?{...t,scope:n.scope}:t,n.expression);return t.scope[e]=r,t.localVars.add(r),r}return n}function Jt(t,e){let n="$"+e.name,r=Ce(t,e);if(r===void 0)return wt(n);let s=typeof r;if(s==="object"){let c=r;if(c.type==="fallback")return wt(n);if(t.localVars.has(c))return c.source=n,c;if(r instanceof Number)s="number";else if(r instanceof String)s="string"}let i;switch(s){case"bigint":case"number":i=t.functions.number;break;case"string":i=t.functions.string;break;default:return Ln(n,r)}let a=new lt(t,n),o=i(a,{},r);return o.source=n,o}function it(t,e){switch(e.type){case"literal":return e.value;case"variable":return Ce(t,e);default:throw Error(`Unsupported value: ${e.type}`)}}function mt(t){switch(t?.type){case"literal":return"|"+t.value.replaceAll("\\","\\\\").replaceAll("|","\\|")+"|";case"variable":return"$"+t.name;default:return}}function Te(t,{kind:e,name:n,options:r}){let s={type:"markup",kind:e,name:n},i=r?Object.entries(r):null;if(i?.length){s.options={};for(let[a,o]of i)if(a==="u:dir"){let c=new L("bad-option",`The option ${a} is not valid for markup`);c.source=mt(o),t.onError(c)}else{let c=it(t,o);if(typeof c==="object"&&typeof c?.valueOf==="function")c=c.valueOf();if(a==="u:id")s.id=String(c);else s.options[a]=c}}return s}function Me(t,e){if(e.type==="message")return e.pattern;let n=e.selectors.map((i)=>{let a=Jt(t,i),o;if(typeof a.selectKey==="function")o=a.selectKey.bind(a);else t.onError(new G("bad-selector","Selector does not support selection",a.source)),o=()=>null;return{selectKey:o,source:a.source,best:null,keys:null}}),r=e.variants;t:for(let i=0;i<n.length;++i){let a=n[i];if(!a.keys){a.keys=new Set;for(let{keys:o}of r){let c=o[i];if(!c)break t;if(c.type!=="*")a.keys.add(c.value)}}try{a.best=a.keys.size?a.selectKey(a.keys):null}catch(o){t.onError(new G("bad-selector","Selection failed",a.source,o)),a.selectKey=()=>null,a.best=null}if(r=r.filter((o)=>{let c=o.keys[i];if(c.type==="*")return a.best==null;return a.best===c.value}),r.length===0){if(i===0)break;let o=n[i-1];if(o.best==null)o.keys?.clear();else o.keys?.delete(o.best);for(let c=i;c<n.length;++c)n[c].keys=null;r=e.variants,i=-1}}let s=r[0];if(!s)return t.onError(new G("no-match","No variant was selected!?",".match")),[];return s.value}class Qt{#t;#e;#n;#s;#r;#i;constructor(t,e,n){this.#t=n?.bidiIsolation!=="none",this.#n=n?.localeMatcher??"best fit",this.#s=Array.isArray(t)?t.map((r)=>new Intl.Locale(r)):t?[new Intl.Locale(t)]:[],this.#e=n?.dir??rt(this.#s[0]),this.#r=typeof e==="string"?be(e):e,Se(this.#r),this.#i=n?.functions?Object.assign(Object.create(null),St,n.functions):St}format(t,e){let n=this.#o(t,e),r="";for(let s of Me(n,this.#r))if(typeof s==="string")r+=s;else if(s.type==="markup")Te(n,s);else{let i;try{if(i=It(n,s),typeof i.toString==="function")if(this.#t&&(this.#e!=="ltr"||i.dir!=="ltr"||i[Et])){let a=i.dir==="ltr"?Ee:i.dir==="rtl"?we:vt;r+=a+i.toString()+kt}else r+=i.toString();else{let a=new L("not-formattable","Message part is not formattable");throw a.source=i.source,a}}catch(a){n.onError(a);let o=`{${i?.source??"�"}}`;r+=this.#t?vt+o+kt:o}}return r}formatToParts(t,e){let n=this.#o(t,e),r=[];for(let s of Me(n,this.#r))if(typeof s==="string")r.push({type:"text",value:s});else if(s.type==="markup")r.push(Te(n,s));else{let i;try{if(i=It(n,s),typeof i.toParts==="function"){let a=i.toParts();if(this.#t&&(this.#e!=="ltr"||i.dir!=="ltr"||i[Et])){let o=i.dir==="ltr"?Ee:i.dir==="rtl"?we:vt;r.push({type:"bidiIsolation",value:o},...a,{type:"bidiIsolation",value:kt})}else r.push(...a)}else{let a=new L("not-formattable","Message part is not formattable");throw a.source=i.source,a}}catch(a){n.onError(a);let o={type:"fallback",source:i?.source??"�"};if(this.#t)r.push({type:"bidiIsolation",value:vt},o,{type:"bidiIsolation",value:kt});else r.push(o)}}return r}#o(t,e=(n)=>{try{process.emitWarning(n)}catch{console.warn(n)}}){let n={...t};for(let s of this.#r.declarations)n[s.name]=new Yt(s.value,s.type==="input"?t??{}:void 0);return{onError:e,localeMatcher:this.#n,locales:this.#s,localVars:new WeakSet,functions:this.#i,scope:n}}}var jn={MessageFormat:Qt,functions:zt};var Or=null;var Lr=/^[-\w]+$/,Fn=/^(%|[a-zA-Z]+)/,An=["<number>","0"];function te(t,e){let n=t[e];e++;while(e<t.length){if(t[e]==="\\"){e+=2;continue}if(t[e]===n)return e+1;e++}return e}function Hn(t,e){let n=t.indexOf("*/",e+2);return n<0?t.length:n+2}function Nr(t,e){let n=t.indexOf(`
5
- `,e+2);return n<0?t.length:n}var $r=(t)=>t.replace(/["\\]/g,"\\$&");function Xt(t,e,n){let r=1,s=-1;for(let i=0;i<e;i++)if(t[i]===`
6
- `)r++,s=i;return{line:r,col:e-s,offset:e,length:n}}function Pe(t,e){let n=e+1,r=0,s=!1,i=!1;while(n<t.length){let o=t[n];if(o==='"'||o==="'"){n=te(t,n);continue}if(o==="{"||o===";")return null;if(o==="}")break;if(o==="("||o==="[")r++;else if(o===")"||o==="]")r--;else if(r===0){if(o==="?")s=!0;else if(o===":"&&!s)i=!0}n++}if(n>=t.length||i)return null;let a=t.slice(e+1,n).trim();return a?{end:n,expr:a}:null}var jr=new Set(["state","input","static","context","self"]);function Ar(t,e,n,r){let s=[],i=e,a=e,o=0;while(i<t.length){let c=t[i];if(c==='"'||c==="'"){i=te(t,i);continue}if(c==="/"&&t[i+1]==="*"){let p=Hn(t,i);if(!n)s.push(t.slice(a,i)," "),a=p;i=p;continue}if(c==="("){o++,i++;continue}if(c===")"){o--,i++;continue}if(o===0&&(c===";"||c==="}"))return s.push(t.slice(a,i)),{end:i,parts:s};if(c==="{"){let p=Pe(t,i);if(!p)return t.indexOf("}",i+1)<0&&r?.(i),null;s.push(t.slice(a,i));let l=Fn.exec(t.slice(p.end+1)),u=l?l[1]:"";s.push({expr:p.expr,unit:u,at:i}),i=p.end+1+u.length,a=i;continue}i++}return s.some((c)=>typeof c!=="string")&&r?.(e),null}var _r=/^@(-\w+-)?(keyframes|font-face|property|counter-style|font-feature-values|font-palette-values|page|view-transition|position-try|color-profile|function)\b/i,_n=/^@(import|charset|namespace)\b/i,Dr=/^@(media|supports|container|layer|scope|starting-style|document)\b/i,Br=/^([a-zA-Z_*\\]|[^\x00-\x7f])/,Fr=/^(?:[-\w*|]|[^\x00-\x7f]|\\[\s\S])+/,Hr=/&[-_]/,Vn=/\s/,Dn=/[{};]/,Bn=/[-\w]/,Un=/"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'/g,Vr=new RegExp(`(${Un.source})|\\s+`,"g"),Ur=/\/\*[\s\S]*?\*\//g,Wr=/^@layer\b/i,qr=(t)=>t.replace(Vr,(e,n)=>n||" ");function Kr(t){let e=[],n=0,r=0;for(let s=0;s<t.length;s++){let i=t[s];if(i==="\\"){s++;continue}if(i==='"'||i==="'"){s=te(t,s)-1;continue}if(i==="("||i==="[")r++;else if(i===")"||i==="]")r--;else if(i===","&&!r)e.push(t.slice(n,s)),n=s+1}return e.push(t.slice(n)),e.map((s)=>{let i=s.trimStart(),a=i.length;while(a&&Vn.test(i[a-1])&&i[a-2]!=="\\")a--;if(i=i.slice(0,a),!Br.test(i))return i;return i.includes("&")?i.replace(Fr,":is($&)"):`& ${i}`}).join(",")}function Zr(t,e,n,r){let s=[],i=[],a=[],o=`--${e.nsp.replace(/[^a-zA-Z0-9_-]/g,"-")}`,c=(S,O,I,T,N)=>r.push({code:S,severity:"error",message:O,hint:N,loc:Xt(t,I,T)}),p=(S,O,I,T,N)=>r.push({code:S,severity:"warning",message:O,hint:N,loc:Xt(t,I,T)}),l=(S,O,I,T)=>e.lint?.(S,T)?.forEach((N)=>r.push({...N,loc:Xt(t,O,I-O)})),u=(S)=>{let O=s.indexOf(S);if(O<0)O=s.push(S)-1;return O},f=(S)=>{let{ast:O,diagnostics:I}=X(S.expr),T=S.expr.length+2;if(I.length){c("LIPS-S004",`Invalid expression: ${I[0].message}`,S.at,T);return}for(let N of Ae(O))if(!jr.has(N)&&!(N in globalThis))c("LIPS-S003",`'${N}' is not readable from a stylesheet`,S.at,T,"Stylesheets see state, input, static, context and self — not <for> iterators or <let> names, "+"which are local to a template position.");S.unit&&O.t==="lit"&&typeof O.v==="string"&&p("LIPS-S005",`Unit '${S.unit}' after a string value`,S.at,T,`A unit suffix multiplies a number: drop the unit, or return ${S.unit==="%"?"50":"8"} instead of a string.`)},m="",g="",b="",k=!1,h=(S)=>{if(!S)return;if(k&&b&&!Dn.test(b)&&!Dn.test(S[0]))g+=" ";k=!1,g+=S,b=S[S.length-1]},x=(S)=>{m+=g+S,g="",b=S,k=!1},R=()=>{let S=g;return g=b="",k=!1,S},C=(S)=>":"+(qr(S).trim()||" "),v=0,d=0,E=0,M="",z="",P="",D=!1,B=[{ctx:e.meta?"top":"style"}],dt=()=>{let S=B[B.length-1],O=g,I;if(S.ctx==="opaque"||l(O,E,v),O[0]==="@")if(S.ctx!=="opaque"&&_r.test(O))I={ctx:"opaque",hoist:m.length};else if(Dr.test(O))I={ctx:S.ctx,group:O,at:m.length};else I={ctx:"opaque"};else{if(S.ctx==="style"){if(n)Hr.test(O.replace(Un,""))&&p("LIPS-S008",`'${O}' joins '&' to a name`,E,v-E,"Native nesting cannot: write the full selector, or use stylisPreprocessor."),g=Kr(O)}I={ctx:S.ctx==="opaque"?"opaque":"style"}}B.push(I),x("{"),I.group&&(I.body=m.length)},pt=()=>{let S=B.pop();if(S.group&&!g&&m.length===S.body&&!Wr.test(S.group)){m=m.slice(0,S.at),b="",k=!1;return}if(x("}"),S.hoist===void 0)return;let O=m.slice(S.hoist),I=B.filter((ut)=>ut.group),T=I.map((ut)=>ut.group).join("{"),N="}".repeat(I.length);m=m.slice(0,S.hoist),b="",z=T&&T===P?z.slice(0,z.length-N.length)+O+N:z+I.map((ut)=>ut.group+"{").join("")+O+N,P=T};while(v<t.length){let S=t[v];if(S==="\\"){h(t.slice(v,v+2)),v+=2;continue}let O=S==="/"&&!t.slice(E,v).trim();if(S==="/"&&(t[v+1]==="*"||t[v+1]==="/"&&O)){let I=t[v+1]==="/",T=I?Nr(t,v):Hn(t,v);if(!I&&!n)g?h(t.slice(v,T)):m+=t.slice(v,T);else Bn.test(b)&&Bn.test(t[T]||"")&&(k=!0);O&&(E=T),v=T;continue}if(S==='"'||S==="'"){let I=te(t,v);h(t.slice(v,I)),v=I;continue}if(Vn.test(S)){E===v&&E++,k=!0,v++;continue}if(S==="(")d++;else if(S===")")d--;if(S===":"&&d===0){let I=t.slice(E,v).replace(Ur,"").trim();if(Lr.test(I)){let T=Ar(t,v+1,!n,(N)=>{D=!0,c("LIPS-S004","Unterminated interpolation",N,t.length-N,"Close the expression with `}`.")});if(T){let N=T.parts.filter((K)=>typeof K!=="string");for(let K of N)f(K);if(k=!1,I.startsWith("--")&&N.length===1&&!N[0].unit&&T.parts.every((K)=>typeof K!=="string"||!K.trim())){i.push({prop:I,e:u(N[0].expr)}),R(),v=T.end+(t[T.end]===";"?1:0),E=v;continue}let Ct="";for(let K of T.parts){if(typeof K==="string"){Ct+=K;continue}let Le=u(K.expr),ft=`${o}-${Le}`;if(!i.some((se)=>se.prop===ft)){if(i.push({prop:ft,e:Le}),K.unit&&!a.some((se)=>se.name===ft))a.push({name:ft,syntax:An[0],inherits:!0,initial:An[1]})}Ct+=K.unit?`calc(var(${ft}) * 1${K.unit})`:`var(${ft})`}l(I,E,T.end,Ct),h(C(Ct)),v=T.end;continue}}}if(S==="{"){if(d>0){let I=Pe(t,v);if(I){c("LIPS-S002","Interpolation in an at-rule condition",v,I.end-v+1,"Media and container conditions cannot read custom properties. Keep the condition static.");let T=Fn.exec(t.slice(I.end+1));v=I.end+1+(T?T[1].length:0);continue}}if(!t.slice(E,v).trim()){let I=Pe(t,v);if(I){c("LIPS-S001","Interpolation in a selector",v,I.end-v+1,"Selectors are static in Layer 1. Bind a value inside the rule instead."),v=I.end+1,E=v;continue}}dt(),E=++v;continue}if(S==="}"){if(B.length>1)pt();else p("LIPS-S007","Unmatched `}` dropped",v,1),g&&x(";");E=++v;continue}if(S===";"){if(g[0]==="@"&&l(g,E,v),B.length===1&&_n.test(g))M+=R()+";";else x(";");E=++v;continue}h(S),v++}if(B.length>1){D||p("LIPS-S007","Unclosed `{` closed at the end",t.length,0);while(B.length>1)pt()}return _n.test(g)&&(M+=R()+";"),x(""),{css:m,statements:M,hoisted:z,exprs:s,binds:i,props:a}}function ee(t,e){let n=[],r=e.preprocess||Or,{css:s,statements:i,hoisted:a,exprs:o,binds:c,props:p}=Zr(t,e,!r,n),l={v:1,nsp:e.nsp,css:"",exprs:[],binds:[]},u=e.meta||!s?s:`${e.scope||`[rel="${$r(e.nsp)}"]`}{${s}}`,f=a+u,m=e.layer?`@layer ${e.layer}{${f}}`:f,g;try{g=r?r(m):m}catch(h){return n.push({code:"LIPS-S006",severity:"error",message:`Style compilation failed: ${h.message}`,loc:Xt(t,0,t.length)}),{ir:l,diagnostics:n}}let b=p.map((h)=>`@property ${h.name}{syntax:"${h.syntax}";inherits:${h.inherits};initial-value:${h.initial}}`).join(""),k={v:1,nsp:e.nsp,css:i+b+g,exprs:o,binds:c};if(p.length)k.props=p;return{ir:k,diagnostics:n}}var Gr=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),zr=new Set(["pre","textarea"]),Wn=new Set(["if","else-if","switch","log"]),Jr={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'","&nbsp;":" "};function ne(t){return t.replace(/&(?:amp|lt|gt|quot|#39|nbsp);/g,(e)=>Jr[e])}class Oe{src;pos=0;lineStarts=null;diagnostics=[];constructor(t){this.src=t}locate(t){if(!this.lineStarts){this.lineStarts=[0];for(let r=0;r<this.src.length;r++)if(this.src[r]===`
7
- `)this.lineStarts.push(r+1)}let e=0,n=this.lineStarts.length-1;while(e<n){let r=e+n+1>>1;this.lineStarts[r]<=t?e=r:n=r-1}return{line:e+1,col:t-this.lineStarts[e]+1}}report(t,e,n,r,s=1,i){let{line:a,col:o}=this.locate(r);this.diagnostics.push({code:t,severity:e,message:n,hint:i,loc:{line:a,col:o,offset:r,length:s}})}eof(){return this.pos>=this.src.length}peek(t=0){return this.src[this.pos+t]}startsWith(t){return this.src.startsWith(t,this.pos)}skipSpace(){while(!this.eof()&&/\s/.test(this.src[this.pos]))this.pos++}scanBalanced(t,e){let n=this.pos,r=0;while(!this.eof()){let s=this.src[this.pos];if(s==="'"||s==='"'||s==="`"){this.pos++;while(!this.eof()&&this.src[this.pos]!==s){if(this.src[this.pos]==="\\")this.pos++;this.pos++}this.pos++;continue}if(r===0&&s===t){let i=this.src.slice(n,this.pos);return this.pos++,{content:i,loc:{offset:n,length:i.length}}}if(s==="("||s==="["||s==="{")r++;else if(s===")"||s==="]"||s==="}"){if(r===0&&s!==t){this.report(e,"error",`Unbalanced '${s}'`,this.pos),this.pos++;continue}r--}this.pos++}return this.report(e,"error",`Unterminated — expected '${t}'`,n,this.pos-n),null}parse(){let t=[];while(!this.eof())if(t.push(...this.parseNodes([])),this.startsWith("</")){let e=this.pos;this.pos+=2;while(!this.eof()&&this.peek()!==">")this.pos++;!this.eof()&&this.pos++,this.report("LIPS-P005","error",`Stray closing tag ${this.src.slice(e,this.pos)}`,e,this.pos-e)}return{root:{t:"fragment",children:t,loc:{offset:0,length:this.src.length}},diagnostics:this.diagnostics}}parseNodes(t){let e=[];while(!this.eof()){if(this.startsWith("</"))break;let n=this.pos;if(this.peek()==="<"&&this.peek(1)!==void 0){let r=this.parseTag(t);r&&e.push(r)}else{let r=this.parseText(t);r&&e.push(r)}if(this.pos===n)this.pos++}return e}parseText(t){let e=this.pos,n=[],r="";while(!this.eof()&&this.peek()!=="<"){if(this.peek()==="{"){this.pos++;let o=this.scanBalanced("}","LIPS-P007");if(o)r&&n.push(r),r="",n.push({expr:o.content.trim(),loc:o.loc});continue}r+=this.peek(),this.pos++}r&&n.push(r);let s={offset:e,length:this.pos-e};if(n.some((o)=>typeof o!=="string"))return{t:"interp",parts:n.map((o)=>typeof o==="string"?ne(o):o),loc:s};let i=n.length?n[0]:"",a=t.some((o)=>zr.has(o));if(!i||!a&&!i.trim())return null;return{t:"text",value:ne(i),loc:s}}parseTag(t){let e=this.pos;if(this.startsWith("<!--")){let i=this.src.indexOf("-->",this.pos+4);if(i===-1)return this.report("LIPS-P003","error","Unterminated comment",e,this.src.length-e),this.pos=this.src.length,null;let a=this.src.slice(this.pos+4,i);return this.pos=i+3,{t:"comment",value:a,loc:{offset:e,length:this.pos-e}}}if(this.startsWith("<>")){this.pos+=2;let i=[];while(!0)if(i.push(...this.parseNodes([...t,"#fragment"])),this.closeStatus("#fragment",e,t)!=="stray")break;return{t:"fragment",children:i,loc:{offset:e,length:this.pos-e}}}if(this.startsWith("<{")){this.pos+=2;let i=this.scanBalanced("}","LIPS-P008");if(!i)return null;let a={t:"element",tag:"#dynamic",dynamicTag:{expr:i.content.trim(),loc:i.loc},attrs:[],children:[],selfClosed:!1,loc:{offset:e,length:0}};return this.finishTag(a,t,e),a}this.pos++;let n=this.pos;while(!this.eof()&&/[A-Za-z0-9_-]/.test(this.peek()))this.pos++;let r=this.src.slice(n,this.pos);if(!r||!/^[A-Za-z]/.test(r))return this.report("LIPS-P002","error","Invalid tag name",e,this.pos-e+1),{t:"text",value:"<",loc:{offset:e,length:1}};let s={t:"element",tag:r.toLowerCase(),attrs:[],children:[],selfClosed:!1,loc:{offset:e,length:0}};if(this.peek()==="(")if(Wn.has(s.tag)){this.pos++;let i=this.scanBalanced(")","LIPS-P012");i&&(s.head={expr:i.content.trim(),loc:i.loc})}else this.report("LIPS-P011","error",`Head expression is not allowed on <${s.tag}>`,this.pos,1,`Only ${[...Wn].map((i)=>`<${i}(…)>`).join(", ")} take a head`);return this.finishTag(s,t,e),s}finishTag(t,e,n){if(this.parseAttrs(t),t.selfClosed||Gr.has(t.tag)){t.selfClosed=!0,t.loc={offset:n,length:this.pos-n};return}let r=t.tag==="#dynamic"?"#dynamic":t.tag;t.children=[];while(!0)if(t.children.push(...this.parseNodes([...e,r])),this.closeStatus(r,n,e)!=="stray")break;t.loc={offset:n,length:this.pos-n}}closeStatus(t,e,n){if(this.eof())return this.report("LIPS-P006","error",`Unclosed <${t==="#fragment"?"":t}> — reached end of template`,e,1,`Add </${t==="#fragment"||t==="#dynamic"?"":t}>`),"eof";if(!this.startsWith("</"))return"closed";let r=this.pos;if(this.pos+=2,this.peek()===">"){if(this.pos++,t!=="#fragment"&&t!=="#dynamic")this.report("LIPS-P004","warning",`Generic '</>' closes <${t}>`,r,3,`Prefer </${t}>`);return"closed"}let s=this.pos;while(!this.eof()&&/[A-Za-z0-9_-]/.test(this.peek()))this.pos++;let i=this.src.slice(s,this.pos).toLowerCase();if(this.skipSpace(),this.peek()===">"?this.pos++:this.report("LIPS-P001","error","Malformed closing tag",r,this.pos-r),i===t)return"closed";if(n.includes(i))return this.report("LIPS-P004","warning",`</${i}> auto-closes <${t}>`,r,this.pos-r,`Add the missing </${t}> before </${i}>`),this.pos=r,"ancestor";return this.report("LIPS-P005","error",`Stray closing tag </${i}> — <${t}> is open`,r,this.pos-r),"stray"}parseAttrs(t){while(!0){if(this.skipSpace(),this.eof()){this.report("LIPS-P001","error","Unexpected end of template inside tag",t.loc.offset);return}if(this.startsWith("/>")){this.pos+=2,t.selfClosed=!0;return}if(this.peek()===">"){this.pos++;return}let e=this.pos;if(this.startsWith("...")){this.pos+=3;let i=this.readUnquotedValue();t.attrs.push({k:"spread",source:i,loc:{offset:e,length:this.pos-e}});continue}if(this.peek()==="["){this.pos++;let i=this.scanBalanced("]","LIPS-P009");if(i){let a=i.content.split(",").map((o)=>o.trim()).filter(Boolean);t.attrs.push({k:"args",names:a,loc:{offset:e,length:this.pos-e}})}continue}let n=!1;if(this.peek()==="!")n=!0,this.pos++;let r=this.pos;while(!this.eof()&&/[^\s=/>()]/.test(this.peek()))this.pos++;let s=this.src.slice(r,this.pos);if(!s){this.report("LIPS-P009","error",`Invalid attribute syntax at '${this.peek()}'`,this.pos),this.pos++;continue}if(this.peek()==="("){this.pos++;let i=this.scanBalanced(")","LIPS-P010"),a=i?i.content.trim():"",o={offset:e,length:this.pos-e};s.startsWith("on-")?t.attrs.push({k:"event",name:s.slice(3),source:a,loc:o}):t.attrs.push({k:"fn",name:s,source:a,loc:o});continue}if(this.peek()==="="){this.pos++,this.parseAttrValue(t,s,e);continue}t.attrs.push({k:"bool",name:s,value:!n,loc:{offset:e,length:this.pos-e}})}}parseAttrValue(t,e,n){let r=this.peek();if(r==='"'||r==="'"){this.pos++;let i=this.pos,a=[],o="";while(!this.eof()&&this.peek()!==r){if(this.peek()==="{"){this.pos++;let p=this.scanBalanced("}","LIPS-P007");if(p)o&&a.push(o),o="",a.push({expr:p.content.trim(),loc:p.loc});continue}o+=this.peek(),this.pos++}o&&a.push(o),this.eof()?this.report("LIPS-P010","error",`Unterminated value for '${e}'`,i,this.pos-i):this.pos++;let c={offset:n,length:this.pos-n};a.some((p)=>typeof p!=="string")?t.attrs.push({k:"interp",name:e,parts:a.map((p)=>typeof p==="string"?ne(p):p),loc:c}):t.attrs.push({k:"literal",name:e,value:ne(a[0]??""),loc:c});return}if(r==="{"){this.pos++;let i=this.scanBalanced("}","LIPS-P007");t.attrs.push({k:"expr",name:e,source:i?i.content.trim():"",loc:{offset:n,length:this.pos-n}});return}let s=this.readUnquotedValue();s?t.attrs.push({k:"expr",name:e,source:s,loc:{offset:n,length:this.pos-n}}):this.report("LIPS-P010","error",`Missing value for attribute '${e}'`,n)}readUnquotedValue(){let t=this.pos,e=0;while(!this.eof()){let n=this.peek();if(n==="'"||n==='"'||n==="`"){this.pos++;while(!this.eof()&&this.peek()!==n){if(this.peek()==="\\")this.pos++;this.pos++}this.pos++;continue}if(e===0){if(/\s/.test(n)||n===">")break;if(n==="/"&&this.peek(1)===">")break}if(n==="("||n==="["||n==="{")e++;else if(n===")"||n==="]"||n==="}")e--;this.pos++}return this.src.slice(t,this.pos).trim()}}function Rt(t){return new Oe(t||"").parse()}function qn(t){let e=Yr(t||""),n=(t||"").slice(0,e).trimEnd(),r=(t||"").slice(e),s=new Oe(r).parse(),i=n?n.split(`
8
- `).length+(/\n\s*\n$/.test(t.slice(0,e))?1:0):0;return s.diagnostics.forEach((a)=>{a.loc.line+=n?t.slice(0,e).split(`
9
- `).length-1:0,a.loc.offset+=e}),{script:n,...s}}function Yr(t){let e=0,n=!0;for(let r=0;r<t.length;r++){let s=t[r];if(s==="'"||s==='"'||s==="`"){let i=s;r++;while(r<t.length&&t[r]!==i){if(t[r]==="\\")r++;r++}n=!1;continue}if(s==="/"&&t[r+1]==="/"){while(r<t.length&&t[r]!==`
1
+ var cr=["===","!==","...","=>","==","!=","<=",">=","&&","||","??","?.","++","--","+=","-=","*=","/=","%=","+","-","*","/","%","<",">","!","?",":",".",",","(",")","[","]","{","}","="];function lr(t,e){let n=[],r=0,s=(o)=>/[A-Za-z_$]/.test(o),i=(o)=>/[A-Za-z0-9_$]/.test(o);while(r<t.length){let o=t[r];if(/\s/.test(o)){r++;continue}if(/[0-9]/.test(o)||o==="."&&/[0-9]/.test(t[r+1])){let c=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(c,r),start:c,end:r});continue}if(o==="'"||o==='"'){let c=r;r++;let p="",l=!1;while(r<t.length){let u=t[r];if(u==="\\"){let f=t[r+1],h={n:`
2
+ `,t:"\t",r:"\r",b:"\b",f:"\f",v:"\v","0":"\x00"};if(f==="u"){let d=t.slice(r+2,r+6);p+=String.fromCharCode(parseInt(d,16)||0),r+=6}else p+=h[f]??f,r+=2;continue}if(u===o){l=!0,r++;break}p+=u,r++}if(!l)e.push({code:"LIPS-E001",message:"Unterminated string literal",loc:{offset:c,length:r-c}});n.push({t:"str",value:p,start:c,end:r});continue}if(s(o)){let c=r;while(r<t.length&&i(t[r]))r++;n.push({t:"id",value:t.slice(c,r),start:c,end:r});continue}let a=cr.find((c)=>t.startsWith(c,r));if(a==="?."&&/[0-9]/.test(t[r+2]??""))a="?";if(a){n.push({t:"punct",value:a,start:r,end:r+a.length}),r+=a.length;continue}e.push({code:"LIPS-E002",message:`Unexpected character '${o}'`,loc:{offset:r,length:1}}),r++}return n.push({t:"eof",value:"",start:t.length,end:t.length}),n}class Ve{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 et(t){let e=[],n=lr(t,e);return{ast:new Ve(n,e).parse(),diagnostics:e}}function ae(t){let e=[],n=0,r=0;for(let s=0;s<t.length;s++){let i=t[s];if(i==="'"||i==='"'||i==="`"){s++;while(s<t.length&&t[s]!==i){if(t[s]==="\\")s++;s++}continue}if(i==="("||i==="["||i==="{")n++;else if(i===")"||i==="]"||i==="}")n--;else if(i===","&&n===0)e.push(t.slice(r,s)),r=s+1}return e.push(t.slice(r)),e.map((s)=>s.trim()).filter(Boolean)}function Ue(t){let e=new Set,n=(r,s)=>{switch(r.t){case"id":!s.has(r.name)&&e.add(r.name);return;case"member":n(r.obj,s),typeof r.prop!=="string"&&n(r.prop,s);return;case"call":n(r.callee,s),r.args.forEach((i)=>n(i,s));return;case"unary":case"update":n(r.arg,s);return;case"bin":case"logic":n(r.l,s),n(r.r,s);return;case"cond":n(r.test,s),n(r.cons,s),n(r.alt,s);return;case"assign":n(r.target,s),n(r.value,s);return;case"arrow":n(r.body,new Set([...s,...r.params]));return;case"arr":r.items.forEach((i)=>n(i.value,s));return;case"obj":r.props.forEach((i)=>n(i.value,s));return}};return n(t,new Set),[...e]}var We={__proto__:null,static:"__static",arguments:"__args__"};function j(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 We[t.name]??t.name;case"member":{let e=Fe(t.obj);if(t.computed)return`${e}${t.optional?"?.":""}[${j(t.prop)}]`;return`${e}${t.optional?"?.":"."}${t.prop}`}case"call":return`${Fe(t.callee)}${t.optional?"?.":""}(${t.args.map(j).join(",")})`;case"unary":return`(${t.op}(${j(t.arg)}))`;case"update":return t.prefix?`(${t.op}${oe(t.arg)})`:`(${oe(t.arg)}${t.op})`;case"bin":return`((${j(t.l)})${t.op}(${j(t.r)}))`;case"logic":return`((${j(t.l)})${t.op}(${j(t.r)}))`;case"cond":return`((${j(t.test)})?(${j(t.cons)}):(${j(t.alt)}))`;case"assign":return`(${oe(t.target)}${t.op}(${j(t.value)}))`;case"arrow":return`((${t.params.join(",")})=>(${j(t.body)}))`;case"arr":return`[${t.items.map((e)=>(e.spread?"...":"")+j(e.value)).join(",")}]`;case"obj":return`({${t.props.map((e)=>e.spread?`...${j(e.value)}`:`${JSON.stringify(e.key)}:${j(e.value)}`).join(",")}})`;case"error":return"undefined"}}var Fe=(t)=>t.t==="member"||t.t==="call"||t.t==="id"?j(t):`(${j(t)})`;function oe(t){if(t.t==="id")return We[t.name]??t.name;if(t.t==="member"){let e=j(t.obj);return t.computed?`${e}[${j(t.prop)}]`:`${e}.${t.prop}`}return j(t)}var Be=new Map,pr=["state","input","context","__static","self"];function ce(t,e=[]){let n=`${e.join(",")}\x00${t}`,r=Be.get(n);if(r)return r;let{ast:s,diagnostics:i}=et(t);if(i.length)console.warn(`[lips-ir] expression diagnostics for "${t}":`,i);let o=`return (${j(s)});`,a=[...pr,"__args__",...e],c=Function(...a,o),p={source:t,run(l){let u=l.scope||{};return c(l.state,l.input,l.context,l.static,l.self,l.arguments,...e.map((f)=>u[f]))}};return Be.set(n,p),p}var He={__proto__:null,Math,JSON,Object,Array,String,Number,Boolean,Date,parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,console},gt=Symbol("lips.ended");function le(t,e){let n=e.scope||Object.create(null),r=(c,p)=>{for(let l of p)if(c in l)return l[c];if(c in n)return n[c];switch(c){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(c in He)return He[c];return},s=(c,p,l)=>{for(let u of l)if(c in u)return u[c]=p,p;return n[c]=p,p},i=(c,p)=>{switch(c.t){case"lit":return c.v;case"id":return r(c.name,p);case"member":case"call":{let l=o(c,p);return l===gt?void 0:l}case"unary":{let l=i(c.arg,p);switch(c.op){case"!":return!l;case"-":return-l;case"+":return+l}}case"update":{let l=i(c.arg,p),u=c.op==="++"?l+1:l-1;return a(c.arg,u,p),c.prefix?u:l}case"bin":{let l=i(c.l,p),u=i(c.r,p);switch(c.op){case"+":return l+u;case"-":return l-u;case"*":return l*u;case"/":return l/u;case"%":return l%u;case"<":return l<u;case">":return l>u;case"<=":return l<=u;case">=":return l>=u;case"==":return l==u;case"!=":return l!=u;case"===":return l===u;case"!==":return l!==u}return}case"logic":{let l=i(c.l,p);switch(c.op){case"&&":return l?i(c.r,p):l;case"||":return l?l:i(c.r,p);case"??":return l!=null?l:i(c.r,p)}}case"cond":return i(c.test,p)?i(c.cons,p):i(c.alt,p);case"assign":{let l=i(c.value,p);if(c.op!=="="){let u=i(c.target,p);switch(c.op){case"+=":l=u+l;break;case"-=":l=u-l;break;case"*=":l=u*l;break;case"/=":l=u/l;break;case"%=":l=u%l;break}}return a(c.target,l,p)}case"arrow":return(...l)=>{let u=Object.create(null);return c.params.forEach((f,h)=>u[f]=l[h]),i(c.body,[u,...p])};case"arr":{let l=[];for(let u of c.items){let f=i(u.value,p);u.spread?l.push(...f):l.push(f)}return l}case"obj":{let l={};for(let u of c.props)if(u.spread)Object.assign(l,i(u.value,p));else l[u.key]=i(u.value,p);return l}case"error":return}},o=(c,p)=>{if(c.t!=="member"&&c.t!=="call")return i(c,p);let l=c.t==="member"?c:c.callee.t==="member"?c.callee:null,u,f;if(l){if(u=o(l.obj,p),u===gt||l.optional&&u==null)return gt;if(f=u[l.computed?i(l.prop,p):l.prop],c===l)return f}else if((f=o(c.callee,p))===gt)return gt;let h=c;return h.optional&&f==null?gt:Reflect.apply(f,u,h.args.map((d)=>i(d,p)))},a=(c,p,l)=>{if(c.t==="id")return s(c.name,p,l);if(c.t==="member"){let u=i(c.obj,l),f=c.computed?i(c.prop,l):c.prop;if(u!=null)u[f]=p;return p}return p};return i(t,[])}var J=null,mt=0,Lt=new Set;function ur(){while(Lt.size){let t=[...Lt];Lt.clear(),mt++;try{for(let e of t)!e.disposed&&e.run()}finally{mt--}}}function ue(t){mt++;try{return t()}finally{mt--,!mt&&ur()}}function A(t){let e=new Set,n=()=>{if(mt){for(let o of e)Lt.add(o);return}for(let o of[...e])!o.disposed&&o.run()};return[()=>{if(J&&!J.disposed)e.add(J),J.deps.add(e);return t},(o)=>{if(Object.is(o,t))return;t=o,n()},()=>n()]}function nt(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=J;J=e;try{t()}finally{J=n}}};return e.run(),{dispose(){e.disposed=!0;for(let n of e.deps)n.delete(e);e.deps.clear()}}}function D(t){let e=J;J=null;try{return t()}finally{J=e}}var Ke=Symbol("lips.reactive"),Nt=Symbol("lips.collection"),qe=new WeakMap,fe=(t)=>t!==null&&typeof t==="object"&&(Array.isArray(t)||Object.getPrototypeOf(t)===Object.prototype),Mt=(t)=>t instanceof Map||t instanceof Set||!!(t&&typeof t==="object"&&t[Nt]),fr=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),hr=new Set(["set","delete","clear","add"]),pe=Symbol("lips.keys"),Ze=new WeakMap;function Ge(t,e){let n=t[Nt];if(n)return n.notify.add(e),t;let r=qe.get(t);if(r)return r[Nt].notify.add(e),r;let s={raw:t,notify:new Set([e])},i=()=>s.notify.forEach((a)=>a()),o=new Proxy(t,{get(a,c){if(c===Nt)return s;let p=a[c];if(typeof p!=="function")return p;if(typeof c==="string"&&hr.has(c))return(...f)=>{let h=p.apply(a,f);return i(),h};let l=(f)=>fe(f)?he(f,i):Mt(f)?Ge(f,i):f,u=a instanceof Map;if(c==="get")return(f)=>l(a.get(f));if(c==="forEach")return(f,h)=>a.forEach((d,y)=>f.call(h,l(d),y,o));if(c==="values"||!u&&(c==="keys"||c===Symbol.iterator))return function*(){for(let f of a.values())yield l(f)};if(c==="entries"||u&&c===Symbol.iterator)return u?function*(){for(let[f,h]of a.entries())yield[f,l(h)]}:function*(){for(let f of a.values())yield[l(f),l(f)]};return p.bind(a)}});return qe.set(t,o),o}function dr(t){let e=Ze.get(t);if(e)return e;let n=new Map,r=(l)=>{let u=n.get(l);if(!u)u=A(0),n.set(l,u);u[0]()},s=(l)=>n.get(l)?.[2](),i=new Map,o=(l)=>{let u=i.get(l);if(!u)u=()=>s(l),i.set(l,u);return u},a=()=>ue(()=>{for(let l of n.values())l[2]()}),c=!1,p=new Proxy(t,{get(l,u){let f=l[u];if(typeof u==="symbol")return f;if(Array.isArray(l)&&fr.has(u)&&typeof f==="function")return(...h)=>{c=!0;try{return f.apply(l,h)}finally{c=!1,a()}};if(typeof f==="function")return f;return r(u),fe(f)||Mt(f)?he(f,o(u)):f},set(l,u,f){let h=u in l,d=l[u];if(l[u]=f,c)return!0;if(!Object.is(d,f))s(u);if(!h)s(pe),Array.isArray(l)&&s("length");return!0},deleteProperty(l,u){let f=u in l;if(delete l[u],!c&&f)s(u),s(pe);return!0},has(l,u){return typeof u!=="symbol"&&r(u),u in l},ownKeys(l){return r(pe),Reflect.ownKeys(l)}});return Ze.set(t,p),p}function he(t,e){if(Mt(t))return Ge(t,e);if(!fe(t))return t;return dr(t)}function Z(t,e=!1){if(t[Ke])return t;let n=new Map,[r,,s]=A(0),i=(o,a)=>{let c=n.get(o);if(!c)c=A(a),n.set(o,c);return c};return new Proxy(t,{get(o,a){if(a===Ke)return!0;if(typeof a==="string"){let c=i(a,o[a]);return e?he(c[0](),c[2]):c[0]()}return o[a]},set(o,a,c){let p=a in o,l=o[a];if(o[a]=c,typeof a!=="string")return!0;p||s();let u=i(a,c);return Object.is(l,c)&&Mt(c)?u[2]():u[1](c),!0},has(o,a){return a in o},ownKeys(o){return r(),Reflect.ownKeys(o)},deleteProperty(o,a){let c=a in o;return delete o[a],typeof a==="string"&&n.get(a)?.[1](void 0),c&&s(),!0}})}var ze=new WeakMap,Je=(t)=>t!==null,gr={__proto__:null,value:(t)=>t??"",checked:Je,selected:Je},de={clone(t){let e=ze.get(t);if(!e)e=document.createElement("template"),e.innerHTML=t.html,ze.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);let r=gr[e];r&&e in t&&(t[e]=r(n))},setText:(t,e)=>{t.data=e},content:(t,e)=>{t.textContent=e},html:(t,e)=>{t.innerHTML=e},styleVar:(t,e,n)=>n===null?t.style.removeProperty(e):t.style.setProperty(e,n),scope:(t,e)=>{t.hasAttribute("rel")||t.setAttribute("rel",e)},listen(t,e,n){let r=e.split(".")[0],s=e.includes(".outside"),i=s?document:t,o=s||e.includes(".capture"),a=!s&&e.includes(".stop"),c=(p)=>s&&t.contains(p.target)||(a&&p.stopPropagation(),n(p));return i.addEventListener(r,c,o),()=>i.removeEventListener(r,c,o)},keepFocus(){let t=document.activeElement;return()=>{t&&t.isConnected&&t!==document.activeElement&&t.focus()}}};function xt(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 $t(t,e){let n=new Map(Object.entries(t.names).map(([r,s])=>[r.toLowerCase(),s]));for(let r of xt(e.toLowerCase()))if(n.has(r))return n.get(r);return t.names[t.default]??""}var rt=(t,e)=>t==null?t:("e"in t)?{$:e[t.e]}:t,ge=(t,e)=>({...t,e:e[t.e]});function jt(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:rt(n.ci,e)}),block:st(t.block,e)};case"if":return{t:t.t,branches:t.branches.map((n)=>({when:n.when==null?null:e[n.when],block:st(n.block,e)}))};case"for":return{t:t.t,args:t.args,of:t.of===void 0?void 0:e[t.of],from:rt(t.from,e),to:rt(t.to,e),by:rt(t.by,e),block:st(t.block,e)};case"switch":return{t:t.t,on:e[t.on],cases:t.cases.map((n)=>({is:n.is===null?null:rt(n.is,e),block:st(n.block,e)}))};case"async":return{t:t.t,awaitE:e[t.awaitE],then:t.then&&{args:t.then.args,block:st(t.then.block,e)},catch:t.catch&&{args:t.catch.args,block:st(t.catch.block,e)},loading:t.loading&&st(t.loading,e)};case"let":return{t:t.t,const:t.const,vars:Object.fromEntries(Object.entries(t.vars).map(([n,r])=>[n,rt(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,rt(r,e)])),lang:rt(t.lang,e),block:st(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,rt(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:st(t.contents.block,e)}}}}var st=(t,e)=>({html:t.html,scope:t.scope,binds:t.binds.map((n)=>ge(n,e)),blocks:t.blocks.map((n)=>jt(n,e))}),Ye=(t,e,n,r)=>t.t===n.t&&JSON.stringify(jt(t,e))===JSON.stringify(jt(n,r)),Xe=(t,e,n,r)=>JSON.stringify(t.map((s)=>ge(s,e)))===JSON.stringify(n.map((s)=>ge(s,r))),Qe=(t,e,n,r)=>{let s=(i,o)=>JSON.stringify(i.blocks.filter((a)=>a.t==="let").map((a)=>jt(a,o)));return s(t,e)===s(n,r)};function z(t,e=new WeakMap){if(t===null||typeof t!=="object")return t;let n=t;if(e.has(n))return e.get(n);if(Array.isArray(n)){let i=[];e.set(n,i);for(let o of n)i.push(z(o,e));return i}if(n instanceof Map){let i=new Map;return e.set(n,i),n.forEach((o,a)=>i.set(z(a,e),z(o,e))),i}if(n instanceof Set){let i=new Set;return e.set(n,i),n.forEach((o)=>i.add(z(o,e))),i}if(n instanceof Date)return new Date(n.getTime());if(n instanceof RegExp)return new RegExp(n.source,n.flags);if(ArrayBuffer.isView(n))return new n.constructor(n);let r=Object.getPrototypeOf(n);if(r!==Object.prototype&&r!==null)return t;let s=Object.create(r);e.set(n,s);for(let i of Reflect.ownKeys(n)){let o=Object.getOwnPropertyDescriptor(n,i);"value"in o&&(o.value=z(o.value,e)),Object.defineProperty(s,i,o)}return s}var on=Symbol("lips.slot"),mr=(t)=>!!t&&typeof t==="object"&&t[on]===!0;function an(t,e,n){if(!e||typeof t.onInput!=="function")return()=>{};let r=!0,s=!1,i=!0,{dispose:o}=nt(()=>{for(let a of Object.keys(e))e[a];if(r){r=!1;return}if(s)return;s=!0,Promise.resolve().then(()=>{if(s=!1,!i)return;D(()=>{try{t.onInput(e)}catch(a){n.onError(a)}})})});return()=>{i=!1,o()}}function cn(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 St=[];function me(){let t=!0;while(t){t=!1;for(let e of[...St].reverse()){if(!e.live())continue;let n=St.indexOf(e);if(n<0)continue;St.splice(n,1),e.fn(),t=!0}}}var tn=new Map;function yr(t){let e=tn.get(t);if(!e)e=et(t).ast,tn.set(t,e);return e}var vt=(t)=>t.join(",");function en(t,e,n){let r=e;for(let s of n)r=t.child(r,s);return r}var pt=(t,e)=>t.range(e.start,e.end),nn=(t,e,n,r)=>r===e||t.precedes(e,r)&&t.precedes(r,n);function rn(t,e){e.gen++;for(let r of e.wiring)r();e.wiring=[];let n=t.fragment();for(let r of pt(t,e.inst))t.insert(n,r,null)}function Y(t,e,n){return t.insertAfter(e,pt(t,n)),St.length&&t.connected(e)&&me(),n}var ye=(t,e)=>pt(t,e).filter((n)=>t.isElement(n));function ln(t,e,n){for(let r of ye(t,e))t.scope(r,n)}function br(t,e,n,r,s=""){for(let i of e)t.styleVar(i,n,r===null||r===void 0||r===!1?null:r+s)}function pn(t,e,n,r,s){ln(t,n,r);let i=s.css?e.createStylesheet?.(r,s.css):void 0;return i?()=>i.clear():void 0}function xr(t){for(let e of t.bindHandles)e.dispose();for(let e of t.childHandles)e.dispose()}function H(t,e){if(!e)return;xr(e);for(let n of pt(t,e))t.remove(n,!0)}var sn=(t,e,n,r)=>{let s=t.self.refs||={},i="",o=()=>{s[i]===e&&delete s[i]},a=r(()=>{o(),s[i=String(n())]=e});return()=>{a.dispose(),o()}},_t=(t,e,n,r)=>t.attr(e,n,r==null||r===!1&&!n.startsWith("aria-")?null:r===!0&&!n.startsWith("aria-")?"":String(r)),lt=(t,e,n)=>Object.defineProperty(t,e,{get:n,enumerable:!0,configurable:!0}),vr=Symbol.for("lips.self"),un=Symbol("lips.ctx.layer");function Sr(t,e,n,r){for(let s=t;s;s=Object.getPrototypeOf(s)){let o=s[un]?.get(e);if(o){o(n);return}}r?.(e,n)}function fn(t,e){let n=new Map,r=(c,...p)=>n.get(c)?.forEach((l)=>l(...p)),s,i=()=>null;return{proto:{[vr]:!0,get node(){let c=i();return c?ye(t,c):[]},get lang(){return e()},pick:(c)=>$t(c,e()),emit:r,emitLocal:r,on(c,p){return n.set(c,[...n.get(c)||[],p]),s},once(c,p){let l=(...u)=>{s.off(c,l),p(...u)};return s.on(c,l)},off(c,p){if(!p)n.delete(c);else{let l=(n.get(c)||[]).filter((u)=>u!==p);l.length?n.set(c,l):n.delete(c)}return s}},bind:(c,p)=>(s=c,i=p,c)}}class At{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||de}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:D(()=>this.runner(r.e,n)(e))}guarded(t){let e=!0;return nt(()=>{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=ye(this.h,e),s=t.binds.map((i)=>{let o=this.srcRunner(t.exprs[i.e],[]);return this.guarded(()=>br(this.h,r,i.prop,o(n),i.u))});return()=>{for(let i of s)i.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=yr(t);return(s)=>le(r,s)}let n=ce(t,e);return(r)=>n.run(r)}renderBlock(t,e){let n=this.h,r=n.clone(t),s=new Map,i=t.binds.map((h)=>{let d=en(n,r,h.p);return s.set(vt(h.p),d),d}),o=t.blocks.map((h)=>{let d=en(n,r,h.p);return s.set(vt(h.p),d),d}),a=n.marker("^"),c=n.marker("$");n.insert(r,c,null),n.insert(r,a,n.child(r,0));let p=Object.create(e.scope??null),l={...e,scope:p},u={start:a,end:c,block:t,exprs:this.ir.exprs,penv:e,benv:l,pathNodes:s,bindHandles:[],childHandles:[]};t.blocks.forEach((h,d)=>{if(h.t!=="let")return;let y=[];for(let[x,g]of Object.entries(h.vars))if("lit"in g){let[S]=A(g.lit);lt(p,x,S)}else{let[S,E]=A(void 0);lt(p,x,S);let w=this.runner(g.e,t.scope);y.push(this.guarded(()=>E(w(l))).dispose)}u.childHandles[d]={child:h,exprs:this.ir.exprs,anchor:o[d],dispose:()=>y.forEach((x)=>x())}});let f=(h)=>h.t==="attr"&&h.name==="value";return u.bindHandles=t.binds.map((h,d)=>f(h)?null:this.bindOne(h,i[d],l,t.scope)),t.blocks.forEach((h,d)=>{if(h.t==="let")return;u.childHandles[d]={child:h,exprs:this.ir.exprs,anchor:o[d],dispose:this.execBlock(h,o[d],l,t.scope)}}),t.binds.forEach((h,d)=>{if(f(h))u.bindHandles[d]=this.bindOne(h,i[d],l,t.scope)}),u}bindOne(t,e,n,r,s){let i=this.h;switch(t.t){case"text":{let o=s??i.text("");!s&&i.insertAfter(e,[o]);let a=this.runner(t.e,r),c=t.i18n?this.options.i18n:void 0,p=this.guarded(()=>{let l=a(n),u=l==null?"":String(l);i.setText(o,c?c.translate(u,t.ik,n.lang?.()):u)});return{bind:t,node:e,textNode:o,dispose:p.dispose}}case"attr":{let o=this.runner(t.e,r),a=t.i18n?this.options.i18n:void 0,c=this.guarded(()=>{let p=o(n);_t(i,e,t.name,a&&p!=null?a.translate(String(p),t.ik,n.lang?.()):p)});return{bind:t,node:e,dispose:c.dispose}}case"prop":{let o=this.runner(t.e,r);if(t.name==="ref")return{bind:t,node:e,dispose:sn(n,e,()=>o(n),(c)=>this.guarded(c))};if(t.name==="format"){let c=t.ref||"",p=this.guarded(()=>{let l=o(n),u=this.options.i18n?.format(c,l,n.lang?.());i.content(e,u==null?"":String(u))});return{bind:t,node:e,dispose:p.dispose}}let a=this.guarded(()=>{let c=o(n),p=c==null?"":String(c);t.name==="html"&&i.html?i.html(e,p):i.content(e,p)});return{bind:t,node:e,dispose:a.dispose}}case"event":{let o=this.eventDispatcher(this.ir.exprs[t.e],r,n);return{bind:t,node:e,dispose:i.listen(e,t.name,o)}}case"spread":{let o=this.runner(t.e,r),a=new Set,c=this.guarded(()=>{let p=o(n)||{},l=new Set(Object.keys(p));for(let u of a)!l.has(u)&&i.attr(e,u,null);for(let u of l)_t(i,e,u,p[u]);a=l});return{bind:t,node:e,dispose:c.dispose}}}}swapBlock(t,e,n,r){if(t.block.html!==e.html||JSON.stringify(t.block.scope)!==JSON.stringify(e.scope)||!Qe(t.block,t.exprs,e,this.ir.exprs))return this.rebuild(t,e,n,r);if(!Xe(t.block.binds,t.exprs,e.binds,this.ir.exprs)){let s=e.binds.map((a)=>t.pathNodes.get(vt(a.p)));if(s.some((a)=>!a))return this.rebuild(t,e,n,r);let i=new Map;t.bindHandles.forEach((a)=>a.textNode&&i.set(vt(a.bind.p),a.textNode)),t.bindHandles.forEach((a)=>a.dispose());let o=new Set;t.bindHandles=e.binds.map((a,c)=>{let p=vt(a.p),l=a.t==="text"?i.get(p):void 0;return l&&o.add(p),this.bindOne(a,s[c],t.benv,e.scope,l)}),i.forEach((a,c)=>!o.has(c)&&this.h.remove(a,!0)),n.push({kind:"binds",path:r})}for(let s=0;s<e.blocks.length;s++){let i=e.blocks[s],o=t.childHandles[s];if(i.t==="let")continue;if(o&&Ye(o.child,o.exprs,i,this.ir.exprs))continue;let a=this.live.filter((c)=>nn(this.h,o.anchor,t.childHandles[s+1]?.anchor??t.end,c.anchor));for(let c of a)rn(this.h,c);o?.dispose(),t.childHandles[s]={child:i,exprs:this.ir.exprs,anchor:o.anchor,dispose:this.withSalvage(a,()=>this.execBlock(i,o.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((o)=>nn(this.h,t.start,t.end,o.anchor));for(let o of s)rn(this.h,o);let i=this.withSalvage(s,()=>this.renderBlock(e,t.penv));return Y(this.h,t.end,i),H(this.h,t),n.push({kind:"skeleton",path:r}),i}execBlock(t,e,n,r){let s=this.h,i=[];switch(t.t){case"if":{let o=t.branches.map((l)=>l.when!=null?this.runner(l.when,r):null),a=null,c=-2,p=this.guarded(()=>{let l=-1;for(let u=0;u<t.branches.length;u++){let f=o[u];if(!f||f(n)){l=u;break}}if(l===c)return;c=l,D(()=>{if(H(s,a),a=null,l>=0)a=Y(s,e,this.renderBlock(t.branches[l].block,n))})});i.push(()=>{p.dispose(),H(s,a)});break}case"switch":{let o=this.runner(t.on,r),a=t.cases.map((u)=>u.is&&("e"in u.is)?this.runner(u.is.e,r):null),c=null,p=-2,l=this.guarded(()=>{let u=o(n),f=-1,h=-1;for(let d=0;d<t.cases.length;d++){let y=t.cases[d];if(y.is===null){h=d;continue}let x="lit"in y.is?y.is.lit:a[d](n);if(Array.isArray(x)?x.includes(u):x===u){f=d;break}}if(f===-1)f=h;if(f===p)return;p=f,D(()=>{if(H(s,c),c=null,f>=0)c=Y(s,e,this.renderBlock(t.cases[f].block,n))})});i.push(()=>{l.dispose(),H(s,c)});break}case"macro":{let o=Object.create(n.scope??null),a=Z({}),c={};for(let f of t.args)c[f]=A(void 0),lt(o,f,c[f][0]);let p=t.sets.map((f)=>{if("spread"in f)return{kind:"spread",run:this.runner(f.spread,r)};if("lit"in f.ci){let d=f.ci.lit;return{kind:"value",name:f.name,value:()=>d}}let h=this.runner(f.ci.e,r);return{kind:"value",name:f.name,value:()=>h(n)}}),l=new Set;i.push(this.guarded(()=>{let f={};for(let h of p)if(h.kind==="spread"){let d=h.run(n);if(d&&typeof d==="object")for(let[y,x]of d instanceof Map?d:Object.entries(d))f[y]=x}else f[h.name]=h.value();D(()=>{for(let d of t.args)c[d][1](f[d]);let h=new Set(Object.keys(f));for(let d of l)!h.has(d)&&delete a[d];for(let d of h)a[d]=f[d];l=h})}).dispose);let u=Y(s,e,this.renderBlock(t.block,{...n,arguments:a,scope:o}));i.push(()=>H(s,u));break}case"for":this.execFor(t,e,n,r,i);break;case"async":{let o=this.runner(t.awaitE,r),a=null,c=0,p=(u,f)=>{if(H(s,a),a=null,!u)return;let h="block"in u,d=Object.create(n.scope??null);if(h&&u.args[0]!==void 0){let[y]=A(f);lt(d,u.args[0],y)}a=Y(s,e,this.renderBlock(h?u.block:u,{...n,scope:d}))},l=this.guarded(()=>{let u;try{u=o(n)}catch(h){u=Promise.reject(h)}let f=++c;D(()=>{t.loading?p(t.loading):p(void 0),Promise.resolve(u).then((h)=>f===c&&D(()=>p(t.then,h)),(h)=>f===c&&D(()=>p(t.catch,h)))})});i.push(()=>{c++,l.dispose(),H(s,a)});break}case"provide":{let o=Object.create(n.context??null),a=new Map;Object.defineProperty(o,un,{value:a});for(let[l,u]of Object.entries(t.vars)){let[f,h]=A("lit"in u?u.lit:void 0);if(lt(o,l,f),a.set(l,h),"lit"in u)continue;let d=this.runner(u.e,r);i.push(this.guarded(()=>h(d(n))).dispose)}let c=n.lang;if(t.lang)if("lit"in t.lang){let l=String(t.lang.lit);c=()=>l}else{let[l,u]=A(void 0),f=this.runner(t.lang.e,r);i.push(this.guarded(()=>u(f(n))).dispose),c=()=>l()??n.lang?.()}let p=Y(s,e,this.renderBlock(t.block,{...n,context:o,lang:c}));i.push(()=>H(s,p));break}case"log":{let o=ae(this.ir.exprs[t.e]).map((a)=>this.srcRunner(a,r));i.push(this.guarded(()=>console.log(...o.map((a)=>a(n)))).dispose);break}case"comp":{let o=this.options.components?.[t.name];o?this.execComponent(o,t,e,n,r,i,t.name):this.execElement(t,e,n,r,i);break}case"dynamic":{let o=this.runner(t.tag,r),a=[],c=Symbol("init"),p=this.guarded(()=>{let l=o(n);if(l===c)return;c=l,D(()=>{for(let f of a)f();if(a=[],l==null)return;if(mr(l)){let f={};for(let[d,y]of Object.entries(t.inputs)){let x="lit"in y?void 0:this.runner(y.e,r);f[d]=x?()=>x(n):()=>y.lit}let h=Y(s,e,l.render(f,n));a.push(()=>H(s,h));return}let u=typeof l==="string"?this.options.components?.[l]:l&&typeof l==="object"?l.ir?l:this.options.resolveTemplate?.(l):void 0;if(u)this.execComponent(u,t,e,n,r,a,typeof l==="string"?l:"#dynamic");else if(typeof l==="string")this.execElement({...t,name:l},e,n,r,a)})});i.push(()=>{p.dispose();for(let l of a)l()});break}}return()=>i.forEach((o)=>o())}execFor(t,e,n,r,s){let i=this.h,o=t.of!==void 0?this.runner(t.of,r):null,a=t.by&&"e"in t.by?this.runner(t.by.e,r):null,c=t.by&&"lit"in t.by?String(t.by.lit).split("."):null,p=(y,x)=>y===void 0?void 0:("lit"in y)?y.lit:this.runner(y.e,r)(x),l=[],u=0,f=new Map,h=()=>{if(o===null){let g=Number(p(t.from,n)??0),S=Number(p(t.to,n)??g),E=g<=S,w=[];for(let v=g;E?v<=S:v>=S;E?v++:v--)w.push({key:v,values:[v]});return w}let y=o(n),x=(g,S,E)=>{if(a){let w=a(n);return typeof w==="function"?w(g,E):S}if(c)return c.reduce((w,v)=>w?.[v],g);return S};if(Array.isArray(y))return y.map((g,S)=>({key:x(g,S,S),values:[g,S]}));if(y instanceof Map)return[...y.entries()].map(([g,S],E)=>({key:g,values:[g,S,E]}));if(y instanceof Set)return[...y].map((g,S)=>({key:x(g,g,S),values:[g,S]}));if(y&&typeof y==="object")return Object.entries(y).map(([g,S],E)=>({key:g,values:[g,S,E]}));return[]},d=this.guarded(()=>{let y=h();D(()=>{let x=new Set,g=[],S=++u;for(let w of y){let v=w.key;if(x.has(v))console.warn(`<for> duplicate key '${String(v)}' — falling back to positional identity`),v=`#dup:${g.length}`;x.add(v);let m=f.get(v);if(m)m.sigs.forEach(([I,N,q],B)=>{let W=w.values[B];Object.is(I(),W)&&typeof W==="object"&&W!==null?q():N(W)}),m.pass=S,g.push(m);else{let I=Object.create(n.scope??null),N=w.values.map((W)=>A(W));t.args.forEach((W,P)=>N[P]&&lt(I,W,N[P][0]));let q=this.renderBlock(t.block,{...n,scope:I}),B={key:v,sigs:N,inst:q,pass:S};f.set(v,B),g.push(B)}}for(let w of l)if(w.pass!==S)f.delete(w.key),H(i,w.inst);let E=e;for(let w of g){if(i.next(E)!==w.inst.start)Y(i,E,w.inst);E=w.inst.end}l=g})});s.push(()=>{d.dispose();for(let y of l)H(i,y.inst);l=[],f.clear()})}wireInputs(t,e,n,r,s,i){for(let[o,a]of Object.entries(t.inputs))if(i?.add(o),"lit"in a)r[o]=a.lit;else{let c=this.runner(a.e,n);s.push(this.guarded(()=>r[o]=c(e)).dispose)}for(let o of t.spreads){let a=this.runner(o,n);s.push(this.guarded(()=>{let c=a(e)||{};D(()=>Object.entries(c).forEach(([p,l])=>{i?.add(p),r[p]=l}))}).dispose)}}wireEvents(t,e,n,r,s){t?.forEach((i)=>{let o=this.eventDispatcher(this.ir.exprs[i.e],n,e);r.on(i.name,o),s.push(()=>r.off(i.name,o))})}slotRenderer(t,e){let n=this;return{[on]:!0,args:t.args,render(r,s){let i=Object.create(e.scope??null);return t.args.forEach((o)=>lt(i,o,r?.[o]??(()=>{return}))),n.renderBlock(t.block,s?{...e,scope:i,context:s.context,lang:s.lang}:{...e,scope:i})}}}adoptComponent(t,e,n,r,s,i){let o=[],a=new Set;if(this.wireInputs(e,r,s,t.input,o,a),e.contents)t.input.renderer=this.slotRenderer(e.contents,r),a.add("renderer");for(let p of Object.keys(t.input))!a.has(p)&&delete t.input[p];this.wireEvents(e.events,r,s,t.self,o),t.wiring=o,t.anchor=n;let c=t.gen;Y(this.h,n,t.inst),i.push(()=>{if(c!==t.gen)return;for(let p of t.wiring)p();t.wiring=[],t.teardown()})}execComponent(t,e,n,r,s,i,o){let a=this.pool?.length?this.claim(o,this.keyOf(e.inputs,r,s)):void 0;if(a)return this.adoptComponent(a,e,n,r,s,i);let c=Z({}),p=[];if(this.wireInputs(e,r,s,c,p),e.contents)c.renderer=this.slotRenderer(e.contents,r);let l=Z(z(t.state||{}),t.deep??!1),u=z(t.statics??{}),f=null,h=this,d=fn(this.h,()=>r.lang?.()??h.options.i18n?.lang()??""),y=d.bind(Object.assign(Object.create(d.proto),{...this.options.expose||{},state:l,input:c,static:u,context:r.context,setContext(P,Q){let tt=(k,O)=>Sr(r.context,k,O,h.options.expose?.setContext);typeof P==="string"?tt(P,Q):Object.entries(P||{}).forEach(([k,O])=>tt(k,O))}}),()=>f);t.handlers&&Object.entries(t.handlers).forEach(([P,Q])=>y[P]=Q.bind(y)),this.wireEvents(e.events,r,s,y,p);let x=cn(y);try{typeof y.onCreate==="function"&&y.onCreate()}catch(P){x.onError(P)}try{Object.keys(c).length&&typeof y.onInput==="function"&&y.onInput(c)}catch(P){x.onError(P)}let g=an(y,c,x),S={state:l,input:c,context:r.context,lang:r.lang,static:u,self:y,scope:void 0},E=new At(t.ir,this.options,x),w=E.renderBlock(t.ir.root,S);f=w;let v=t.stylesheet?pn(this.h,this.options,w,t.stylesheet.nsp||t.nsp||"lips",t.stylesheet):void 0,m=t.stylesheet?E.bindStyle(t.stylesheet,w,S):void 0;Y(this.h,n,w),x.ready();try{typeof y.onMount==="function"&&y.onMount(),typeof y.onRender==="function"&&y.onRender(),y.emit("component:mount")}catch(P){x.onError(P)}let I;if(t.context?.length&&typeof y.onContext==="function"){let P=!0,{dispose:Q}=nt(()=>{for(let tt of t.context)S.context?.[tt];if(P){P=!1;return}D(()=>{try{y.onContext()}catch(tt){x.onError(tt)}})});I=Q}let N=!1;St.push({live:()=>this.h.connected(w.start),fn:()=>{N=!0;try{typeof y.onAttach==="function"&&y.onAttach(),y.emit("component:attached")}catch(P){x.onError(P)}}}),this.h.connected(w.start)&&me();let q=!1,B={name:o,key:c.key,self:y,input:c,inst:w,anchor:n,wiring:p,gen:0,claimed:!1,teardown:()=>{if(q)return;q=!0;let P=this.live.indexOf(B);P>-1&&this.live.splice(P,1),I?.(),g(),m?.(),v?.(),H(this.h,w);try{if(N)typeof y.onDetach==="function"&&y.onDetach(),y.emit("component:detached");typeof y.onDestroy==="function"&&y.onDestroy(),y.emit("component:destroy")}catch(Q){x.onError(Q)}}};this.live.push(B);let W=B.gen;i.push(()=>{if(W!==B.gen)return;for(let P of B.wiring)P();B.wiring=[],B.teardown()})}execElement(t,e,n,r,s){let i=this.h,o=i.element(t.name);for(let[a,c]of Object.entries(t.inputs))if(a==="@ref"){let p="lit"in c?()=>c.lit:this.runner(c.e,r);s.push(sn(n,o,()=>p(n),(l)=>this.guarded(l)))}else if(a[0]==="@")s.push(this.contentOf(o,a,c,n,r));else if("lit"in c)_t(i,o,a,c.lit);else{let p=this.runner(c.e,r);s.push(this.guarded(()=>_t(i,o,a,p(n))).dispose)}for(let a of t.events)s.push(i.listen(o,a.name,this.eventDispatcher(this.ir.exprs[a.e],r,n)));if(t.contents){let a=this.renderBlock(t.contents.block,n);for(let c of pt(i,a))i.insert(o,c,null);s.push(()=>H(i,a))}i.insertAfter(e,[o]),s.push(()=>i.remove(o,!0))}contentOf(t,e,n,r,s){let i=this.h;if(e==="@format"){let{ref:a,e:c}="lit"in n?n.lit:{},p=c===void 0?()=>({}):this.runner(c,s);return this.guarded(()=>{let l=this.options.i18n?.format(a||"",p(r),r.lang?.());i.content(t,l==null?"":String(l))}).dispose}let o="lit"in n?()=>n.lit:this.runner(n.e,s);return this.guarded(()=>{let a=o(r),c=a==null?"":String(a);e==="@html"&&i.html?i.html(t,c):i.content(t,c)}).dispose}eventDispatcher(t,e,n){let r=ae(t),s=/^[A-Za-z_$][\w$]*$/.test(r[0]||"")&&!e.includes(r[0]);return(...i)=>D(()=>{let o=(p)=>{if(s&&n.self&&!this.options.guard?.self(p)&&typeof n.self[p]==="function")return n.self[p];try{return this.srcRunner(p,e)(n)}catch(l){return}};if(!r.length)return;let a=o(r[0]);if(typeof a!=="function")return;let c=(p)=>this.hooks?this.hooks.onError(p):console.error("[lips:ir]",p);try{let p=r.slice(1).map((u)=>this.srcRunner(u,e)(n)),l=a(...p,...i);l&&typeof l.then==="function"&&l.then(void 0,c)}catch(p){c(p)}})}}function Dt(t,e={},n={}){let r=n.host||de,s=Z(e.state||{},e.deep??!1),i=Z(e.input||{},e.deep??!1),o=e.static||{},a=null,c=fn(r,()=>n.i18n?.lang()??""),p=c.bind(Object.assign(Object.create(c.proto),{state:s,input:i,static:o,...n.expose||{},...e.expose||{}}),()=>a);e.handlers&&Object.entries(e.handlers).forEach(([E,w])=>p[E]=w.bind(p));let l={state:s,input:i,context:e.context,static:o,self:p,scope:void 0},u=cn(p);try{typeof p.onCreate==="function"&&p.onCreate()}catch(E){u.onError(E)}try{Object.keys(i).length&&typeof p.onInput==="function"&&p.onInput(i)}catch(E){u.onError(E)}let f=an(p,i,u),h=new At(t,n,u),d=h.renderBlock(t.root,l);a=d,u.ready();let y=e.stylesheet?pn(r,n,d,e.stylesheet.nsp||e.nsp||"lips",e.stylesheet):void 0,x=e.stylesheet?h.bindStyle(e.stylesheet,d,l):void 0;try{typeof p.onMount==="function"&&p.onMount(),typeof p.onRender==="function"&&p.onRender()}catch(E){u.onError(E)}let g=!1,S=()=>{if(g)return;g=!0;try{typeof p.onAttach==="function"&&p.onAttach(),p.emit("component:attached")}catch(E){u.onError(E)}};return{state:s,self:p,get nodes(){return pt(r,d)},mount(E){for(let w of pt(r,d))r.insert(E,w,null);if(r.connected(d.start))S(),me()},swap(E){let w=[],v=r.keepFocus?.();if(h=new At(E,n,u,h.live),d=h.swapBlock(d,E.root,w,"root"),a=d,e.stylesheet)ln(r,d,e.stylesheet.nsp||e.nsp||"lips"),x?.(),x=h.bindStyle(e.stylesheet,d,l);return v?.(),{changes:w,salvaged:h.salvaged}},dispose(){f(),x?.(),y?.(),H(r,d);try{if(g)typeof p.onDetach==="function"&&p.onDetach(),p.emit("component:detached");typeof p.onDestroy==="function"&&p.onDestroy()}catch(E){u.onError(E)}}}}class Ft{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 i={};for(let o in s)i[o]=n(s[o]);return i}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 Bt{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 kr="en-US";class Ht{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||kr,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 xt(t.toLowerCase()).some((e)=>!!this.DICTIONARIES[e])}setLoader(t){return this.loader=t,this}load(t){return Promise.all(xt(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 xt(e.toLowerCase())){let i=this.DICTIONARIES[s];if(!i||!Object.prototype.hasOwnProperty.call(i,t))continue;try{r=new this.engine.MessageFormat(e,i[t],{functions:this.functions})}catch(o){this.onError?.(o,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,i=this.message(s,r);if(i)t=i.format(void 0,(o)=>this.onError?.(o,s,r));else if(i===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,(i)=>this.onError?.(i,t,r));s===void 0&&this.onMissing?.(t,r)}pick(t,e){return $t(t,e||this.currentLang)}}var Vt=null;function hn(t){Vt=t}var Ut=null;function dn(t){Ut=t}var gn;function mn(t){gn=t}var yn={};function bn(t,e){yn[t]=e}var xn=null;function vn(t){xn=t}var Er=["state","input","static","context","emit","on","once","off","node","lang","setContext","setLanguage","destroy","appendTo","prependTo","replaceWith","render","swap"],wr=new Set(Er);function be(t){if(!t)return;for(let e of Object.keys(t))if(wr.has(e))throw Error(`Handler <${e}> is a reserved component member name`);return t}class Sn extends Ft{lips;template;state;instance;contextWatcher;destroyed=!1;constructor(t,e,n,r,s,i){super();this.lips=t;this.template=n;let o=be(n.handler);this.state=Z(z(n.state||{}),!0);let a=Z({...r},!0),c=(l,...u)=>super.emit(l,...u);this.instance=Dt(s,{state:this.state,input:a,context:t.getContext(),static:z(n.static??n._static),handlers:o,deep:!0,stylesheet:t.styleFor(e,n),nsp:e,expose:{emit(l,...u){this.emitLocal?.(l,...u),c(l,...u)},context:t.getContext()}},i);let p=n.watchContext;if(p?.length&&typeof o?.onContext==="function")this.contextWatcher=t.watchContext(p,()=>{try{o.onContext.call(this.instance.self)}catch(l){console.error("[lips:ir]",l)}});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 xe{config;debug;store=new Map;plugins=new Map;irCache=new WeakMap;defCache=new WeakMap;styleCache=new WeakMap;context;__root;u;i18n;getLang;setLang;getRev;componentsProxy;constructor(t){this.config=t;if(this.u=t?.untrusted,this.debug=!!t?.debug,this.context=Z({...t?.context||{}},!0),this.i18n=new Ht(t?.lang,t?.messageFormat??gn),this.debug)this.i18n.onMissing=(o,a)=>console.warn(`[lips:i18n] no <${a}> entry for key "${o}"`),this.i18n.onError=(o,a,c)=>console.warn(`[lips:i18n] <${c}> message "${a}" —`,o);let[e,n]=A(this.i18n.lang);this.getLang=e,this.setLang=n;let[r,s]=A(0);this.getRev=r,this.i18n.onChange=()=>s(r()+1),Vt&&Object.entries(yn).forEach(([o,a])=>this.register(o,a));let i=this;this.componentsProxy=new Proxy({},{get(o,a){let c=i.store.get(a);return c?i.defFor(a,c):void 0},has(o,a){return i.store.has(a)}})}register(t,e){let n=xn?.(t);if(n)throw Error(`[lips] <${t}> is ${n}: the compiler reads the tag as one, so a component of that name never renders. Register it under another name`);return be(e.handler),this.store.set(t,e),this}use(t,e){let n=this.plugins.get(t.name);if(n&&n!==t)throw Error(`[lips] two plugins named <${t.name}>: one is installed already`);if(n)return this;this.plugins.set(t.name,t),t.requires?.forEach((r)=>this.use(r));for(let[r,s]of Object.entries(t.components||{})){let i=this.store.get(r);if(i&&i!==s)throw Error(`[lips] <${r}> of plugin <${t.name}> is registered already, by something else`);this.register(r,s)}return t.install?.(this,e),this}unregister(t){return this.store.delete(t),this}has(t){return this.store.has(t)}compile(t){if(t.ir)return t.ir;let e=this.irCache.get(t);if(!e){if(!Vt)throw Error("This build has no template compiler — templates must be precompiled to `ir` "+'(import from "@lipsjs/lips" instead of "@lipsjs/lips/runtime")');let n=Vt(t.default||"",{macros:t.macros,check:this.u?.check});n.diagnostics.length&&console.warn("[lips:ir] template diagnostics —",n.diagnostics),e=n.ir,this.irCache.set(t,e)}return e}styleFor(t,e){if(e.style)return e.style;if(!e.stylesheet)return;if(!Ut){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(Ut):Ut)(e.stylesheet,{nsp:t,layer:this.config?.styleLayer,preprocess:this.config?.stylePreprocessor});r.diagnostics.length&&console.warn("[lips:ir] style diagnostics —",r.diagnostics),n=r.ir,this.styleCache.set(e,n)}return n}unnamed(t){let e=this.anonymous.get(t);return!e&&this.anonymous.set(t,e=`dynamic-${++this.anonymousCount}`),e}anonymous=new WeakMap;anonymousCount=0;defFor(t,e){let n=this.defCache.get(e);if(!n)n={ir:this.compile(e),state:e.state,statics:e.static??e._static,context:e.watchContext,stylesheet:this.styleFor(t,e),nsp:t,handlers:be(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||this.unnamed(s),s):void 0,expose:{setContext:(s,i)=>this.setContext(s,i),setLanguage:(s)=>this.setLanguage(s)},createStylesheet:(s,i)=>{let o=new Bt(s,{sheet:i});return{clear:()=>o.clear()}},i18n:{translate:(s,i,o)=>{let a=this.getLang();return this.getRev(),this.i18n.translate(s,o||a,i).text},format:(s,i,o)=>{let a=this.getLang();return this.getRev(),this.i18n.format(s,i,o||a)??""},lang:()=>this.getLang()}};return new Sn(this,t,e,n,this.compile(e),this.u?this.u.runtime(r):r)}root(t,e){let n=this.render("__ROOT__",t);return this.__root=n,n.appendTo(e),n}setLanguage(t){return this.i18n.lang=t,this.setLang(t),this.i18n.load(t),this}getLanguage(){return this.getLang()}useTranslator(t,e){let n=!0,{dispose:r}=nt(()=>{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}=nt(()=>{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 ve=new Set(["if","else-if","else","for","switch","async","let","const","log","context","i18n"]),Se=new Set(["case","default","then","catch","loading"]),ke=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","menu","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","svg","circle","clippath","defs","ellipse","foreignobject","g","image","line","lineargradient","marker","mask","path","pattern","polygon","polyline","radialgradient","rect","stop","symbol","text","tspan","use"]);function kn(t){let e=t.toLowerCase();return ke.has(e)?"an HTML or SVG element":ve.has(e)||Se.has(e)||e==="macro"?"a template syntax tag":void 0}var Ir=globalThis,Wt=Ir.Intl??={},En=(t)=>(Array.isArray(t)?t:t?[t]:[]).map(String),Ee=(t)=>class{options;constructor(e,n){this.options={...n,locale:En(e)[0]??"und"}}static supportedLocalesOf(e){return En(e)}resolvedOptions(){return this.options}format(e){return t(e)}formatToParts(e){return[{type:"literal",value:t(e)}]}select(){return"other"}};Wt.Locale??=class{baseName;language;constructor(t){this.baseName=String(t),this.language=this.baseName.split("-")[0]}maximize(){return this}toString(){return this.baseName}};Wt.NumberFormat??=Ee(String);Wt.PluralRules??=Ee(String);Wt.DateTimeFormat??=Ee((t)=>{let e=new Date(t);return isNaN(e.getTime())?String(t):e.toISOString()});var wn=/^[\u061c\u200e\u200f\u2066-\u2069]+/,In=/^[-.+0-9A-Z_a-z\u{a1}-\u{61b}\u{61d}-\u{167f}\u{1681}-\u{1fff}\u{200b}-\u{200d}\u{2010}-\u{2027}\u{2030}-\u{205e}\u{2060}-\u{2065}\u{206a}-\u{2fff}\u{3001}-\u{d7ff}\u{e000}-\u{fdcf}\u{fdf0}-\u{fffd}\u{10000}-\u{1fffd}\u{20000}-\u{2fffd}\u{30000}-\u{3fffd}\u{40000}-\u{4fffd}\u{50000}-\u{5fffd}\u{60000}-\u{6fffd}\u{70000}-\u{7fffd}\u{80000}-\u{8fffd}\u{90000}-\u{9fffd}\u{a0000}-\u{afffd}\u{b0000}-\u{bfffd}\u{c0000}-\u{cfffd}\u{d0000}-\u{dfffd}\u{e0000}-\u{efffd}\u{f0000}-\u{ffffd}\u{100000}-\u{10fffd}]+/u,Rr=/^[-.0-9]/;function Rn(t,e){let n=e,r=t.slice(n).match(wn);if(r)n+=r[0].length;let s=t.slice(n).match(In);if(!s)return null;let i=s[0];if(Rr.test(i))return null;n+=i.length;let o=t.slice(n).match(wn);if(o)n+=o[0].length;return{value:i.normalize(),end:n}}var Cn=(t,e)=>t.slice(e).match(In)?.[0]??"";var Pn=Symbol.for("CST");class it extends Error{type;constructor(t,e){super(e);this.type=t}}class ut extends it{start;end;constructor(t,e,n,r){let s=r?`Missing ${r}`:t;if(e>=0)s+=` at ${e}`;super(t,s);this.start=e,this.end=n??e+1}}class Kt extends ut{constructor(t,e){let{start:n,end:r}=e[Pn]??{start:-1,end:-1};super(t,n,r)}}class G extends it{source;cause;constructor(t,e,n,r){super(t,e);if(this.source=n,r!==void 0)this.cause=r}}class L extends it{source;cause;constructor(t,e){super(t,e);this.source="�"}}var On=new Set("؜‎‏⁦⁧⁨⁩"),Tn=new Set(`
4
+ \r  `),b,R,kt=(t,e)=>new ut("missing-syntax",t,t+e.length,e),V=(...t)=>new ut(...t);function yt(t,e){if(R.startsWith(t,b)){if(e)b+=t.length}else throw kt(b,t)}function we(t){b=0,R=t;let e=Or();if(R.startsWith(".match",b))return Cr(e);let n=e.length>0||R.startsWith("{{",b);if(!n&&b>0)b=0;let r=Nn(n);if(n){if(_(),b<R.length)throw V("extra-content",b,R.length)}return{type:"message",declarations:e,pattern:r}}function Cr(t){b+=6,_(!0);let e=[];while(R[b]==="$")e.push($n()),_(!0);if(e.length===0)throw V("empty-token",b);let n=[];while(b<R.length)n.push(Pr()),_();return{type:"select",declarations:t,selectors:e,variants:n}}function Pr(){let t=[];while(b<R.length){_(t.length?"{":!1);let e=R[b];if(e==="{")break;if(e==="*")t.push({type:"*"}),b+=1;else{let n=Re(!0);n.value=n.value.normalize(),t.push(n)}}return{keys:t,value:Nn(!0)}}function Nn(t){if(t)if(R.startsWith("{{",b))b+=2;else throw kt(b,"{{");let e=[];t:while(b<R.length)switch(R[b]){case"{":{e.push(Ie(!0));break}case"}":if(!t)throw V("parse-error",b);break t;default:e.push(Mr())}if(t)if(R.startsWith("}}",b))b+=2;else throw kt(b,"}}");return e}function Or(){let t=[];_();t:while(R[b]==="."){switch(R.substr(b,6)){case".input":t.push(Tr());break;case".local":t.push(Lr());break;case".match":break t;default:throw V("parse-error",b)}_()}return t}function Tr(){b+=6,_(),yt("{",!1);let t=b,e=Ie(!1);if(e.type==="expression"&&e.arg?.type==="variable")return{type:"input",name:e.arg.name,value:e};throw V("bad-input-expression",t,b)}function Lr(){b+=6,_(!0),yt("$",!0);let t=Zt();_(),yt("=",!0),_(),yt("{",!1);let e=Ie(!1);return{type:"local",name:t,value:e}}function Ie(t){let e=b;b+=1,_();let n=Mn(!1);if(n)_("}");let r=R[b],s,i;switch(r){case"@":case"}":break;case":":{b+=1,s={type:"function",name:qt()};let a=Ln();if(a)s.options=a;break}case"#":case"/":{if(n||!t)throw V("parse-error",b);b+=1,i={type:"markup",kind:r==="#"?"open":"close",name:qt()};let c=Ln();if(c)i.options=c;break}default:throw V("parse-error",b)}let o=Nr();if(i?.kind==="open"&&R[b]==="/")i.kind="standalone",b+=1;if(yt("}",!0),s){let a=n?{type:"expression",arg:n,functionRef:s}:{type:"expression",functionRef:s};if(o)a.attributes=o;return a}if(i){if(o)i.attributes=o;return i}if(!n)throw V("empty-token",e,b);return o?{type:"expression",arg:n,attributes:o}:{type:"expression",arg:n}}function Ln(){_("/}");let t={},e=!0;while(b<R.length){let n=R[b];if(n==="@"||n==="/"||n==="}")break;let r=b,s=qt();if(Object.hasOwn(t,s))throw V("duplicate-option-name",r,b);_(),yt("=",!0),_(),t[s]=Mn(!0),e=!1,_("/}")}return e?null:t}function Nr(){let t={},e=!0;while(R[b]==="@"){let n=b;b+=1;let r=qt();if(Object.hasOwn(t,r))throw V("duplicate-attribute",n,b);if(_("=/}"),R[b]==="=")b+=1,_(),t[r]=Re(!0),_("/}");else t[r]=!0;e=!1}return e?null:t}function Mr(){let t="",e=b;t:for(;e<R.length;++e)switch(R[e]){case"\\":{let n=R[e+1];if(!"\\{|}".includes(n))throw V("bad-escape",e,e+2);t+=R.substring(b,e)+n,e+=1,b=e+1;break}case"{":case"}":break t}return t+=R.substring(b,e),b=e,t}function Mn(t){return R[b]==="$"?$n():Re(t)}function $n(){return b+=1,{type:"variable",name:Zt()}}function Re(t){if(R[b]==="|")return $r();let e=Cn(R,b);if(!e)if(t)throw V("empty-token",b);else return;return b+=e.length,{type:"literal",value:e}}function $r(){b+=1;let t="";for(let e=b;e<R.length;++e)switch(R[e]){case"\\":{let n=R[e+1];if(!"\\{|}".includes(n))throw V("bad-escape",e,e+2);t+=R.substring(b,e)+n,e+=1,b=e+1;break}case"|":return t+=R.substring(b,e),b=e+1,{type:"literal",value:t}}throw kt(R.length,"|")}function qt(){let t=Zt();if(R[b]===":")return b+=1,t+":"+Zt();return t}function Zt(){let t=Rn(R,b);if(!t)throw V("empty-token",b);return b=t.end,t.value}function _(t=!1){let e=R[b],n=!1;if(t){while(On.has(e))e=R[++b];while(Tn.has(e))e=R[++b],n=!0}while(On.has(e)||Tn.has(e))e=R[++b];if(t&&!n&&(t===!0||!t.includes(R[b])))throw kt(b,"' '")}function Ce(t,e){let{node:n,pattern:r}=e,{functionRef:s=n,attributes:i=null,declaration:o=n,expression:a=n,key:c=n,markup:p=n,options:l=null,value:u=n,variant:f=n}=e,h=(g,S)=>{if(g){let E=l?.(g,S);if(u)for(let w of Object.values(g))u(w,S,"option");E?.()}},d=(g,S)=>{if(g){let E=i?.(g,S);if(u){for(let w of Object.values(g))if(w!==!0)u(w,S,"attribute")}E?.()}},y=(g,S)=>{if(typeof g==="object"){let E;switch(g.type){case"expression":{if(E=a?.(g,S),g.arg)u?.(g.arg,S,"arg");if(g.functionRef){let w=s?.(g.functionRef,S,g.arg);h(g.functionRef.options,S),w?.()}d(g.attributes,S);break}case"markup":{E=p?.(g,S),h(g.options,S),d(g.attributes,S);break}}E?.()}},x=(g)=>{let S=r?.(g);for(let E of g)y(E,"placeholder");S?.()};for(let g of t.declarations){let S=o?.(g);if(g.value)y(g.value,"declaration");S?.()}if(t.type==="message")x(t.pattern);else{if(u)for(let g of t.selectors)u(g,"selector","arg");for(let g of t.variants){let S=f?.(g);if(c)g.keys.forEach(c);x(g.value),S?.()}}}function Pe(t,e=(n,r)=>{throw new Kt(n,r)}){let n=0,r=null,s=new Set,i=new Set,o=new Set,a=new Set,c=new Set,p=new Set,l=!0;if(Ce(t,{declaration(u){if(!u.name)return;if(u.value.functionRef||u.type==="local"&&u.value.arg?.type==="variable"&&s.has(u.value.arg.name))s.add(u.name);if(u.type==="local")a.add(u.name);return l=u.type==="local",()=>{if(i.has(u.name))e("duplicate-declaration",u);else i.add(u.name)}},expression({functionRef:u}){if(u)o.add(u.name)},value(u,f,h){if(u.type!=="variable")return;switch(c.add(u.name),f){case"declaration":if(h!=="arg"||l)i.add(u.name);break;case"selector":if(n+=1,r=u,!s.has(u.name))e("missing-selector-annotation",u)}},variant(u){let{keys:f}=u;if(f.length!==n)e("key-mismatch",u);let h=JSON.stringify(f.map((d)=>d.type==="literal"?d.value:0));if(p.has(h))e("duplicate-variant",u);else p.add(h);r&&=f.every((d)=>d.type==="*")?null:u}}),r)e("missing-fallback",r);for(let u of a)c.delete(u);return{functions:o,variables:c}}var Oe="⁦",Te="⁧",Et="⁨",wt="⁩";function ot(t){if(t)try{if(typeof t==="string")t=new Intl.Locale(t);let e=t.getTextInfo?.()??t.textInfo;if(e?.direction)return e.direction;let n=t.maximize().script;if(n)return"Adlm,Arab,Hebr,Mand,Nkoo,Rohg,Syrc,Thaa".includes(n)?"rtl":"ltr"}catch{}return"auto"}function Le(t){if(t&&typeof t==="object")t=t.valueOf();if(typeof t==="boolean")return t;if(t&&typeof t==="object")t=String(t);if(t==="true")return!0;if(t==="false")return!1;throw RangeError("Not a boolean")}function U(t){if(t&&typeof t==="object")t=t.valueOf();if(t&&typeof t==="object")t=String(t);if(typeof t==="string"&&/^(0|[1-9][0-9]*)$/.test(t))t=Number(t);if(typeof t==="number"&&t>=0&&Number.isInteger(t))return t;throw RangeError("Not a positive integer")}function F(t){if(t&&typeof t==="object")t=t.valueOf();if(typeof t==="string")return t;if(t&&typeof t==="object")return String(t);throw RangeError("Not a string")}function X(t){let e=void 0;if(typeof t==="object"){let n=t?.valueOf;if(typeof n==="function")e=t.options,t=n.call(t)}if(typeof t==="string")try{t=JSON.parse(t)}catch{}if(typeof t!=="bigint"&&typeof t!=="number")throw new L("bad-operand","Input is not numeric");return{value:t,options:e}}function at(t,e,n,r){let{dir:s,locales:i}=t;if(n.useGrouping==="never")n.useGrouping=!1;if(r&&"select"in n&&!t.literalOptionKeys.has("select"))t.onError("bad-option","The option select may only be set by a literal value"),r=!1;let o,a,c,p;return{type:"number",get dir(){if(s==null)o??=Intl.NumberFormat.supportedLocalesOf(i,n)[0],s=ot(o);return s},get options(){return{...n}},selectKey:r?(l)=>{let u=e;if(n.style==="percent")if(typeof u==="bigint")u*=100n;else u*=100;let f=String(u);if(l.has(f))return f;if(n.select==="exact")return null;let h=n.select?{...n,select:void 0,type:n.select}:n;return c??=new Intl.PluralRules(i,h).select(Number(u)),l.has(c)?c:null}:void 0,toParts(){a??=new Intl.NumberFormat(i,n);let l=a.formatToParts(e);return o??=a.resolvedOptions().locale,s??=ot(o),s==="ltr"||s==="rtl"?[{type:"number",dir:s,locale:o,parts:l}]:[{type:"number",locale:o,parts:l}]},toString(){return a??=new Intl.NumberFormat(i,n),p??=a.format(e),p},valueOf:()=>e}}function Gt(t,e,n){let r=X(n),s=r.value,i=Object.assign({},r.options,{localeMatcher:t.localeMatcher,style:"decimal"});for(let[o,a]of Object.entries(e)){if(a===void 0)continue;try{switch(o){case"minimumIntegerDigits":case"minimumFractionDigits":case"maximumFractionDigits":case"minimumSignificantDigits":case"maximumSignificantDigits":case"roundingIncrement":i[o]=U(a);break;case"roundingMode":case"roundingPriority":case"select":case"signDisplay":case"trailingZeroDisplay":case"useGrouping":i[o]=F(a)}}catch{t.onError("bad-option",`Value ${a} is not valid for :number option ${o}`)}}return at(t,s,i,!0)}function jn(t,e,n){let r=X(n),s=Number.isFinite(r.value)?Math.round(r.value):r.value,i=Object.assign({},r.options,{maximumFractionDigits:0,minimumFractionDigits:void 0,minimumSignificantDigits:void 0,style:"decimal"});for(let[o,a]of Object.entries(e)){if(a===void 0)continue;try{switch(o){case"minimumIntegerDigits":case"maximumSignificantDigits":i[o]=U(a);break;case"select":case"signDisplay":case"useGrouping":i[o]=F(a)}}catch{t.onError("bad-option",`Value ${a} is not valid for :integer option ${o}`)}}return at(t,s,i,!0)}function _n(t,e,n){let r=X(n),s=Object.assign({},r.options,{localeMatcher:t.localeMatcher,style:"currency"});for(let[i,o]of Object.entries(e)){if(o===void 0)continue;try{switch(i){case"currency":case"currencySign":case"roundingMode":case"roundingPriority":case"trailingZeroDisplay":case"useGrouping":s[i]=F(o);break;case"minimumIntegerDigits":case"minimumSignificantDigits":case"maximumSignificantDigits":case"roundingIncrement":s[i]=U(o);break;case"currencyDisplay":{let a=F(o);if(a==="never")t.onError("unsupported-operation",'Currency display "never" is not yet supported');else s[i]=a;break}case"fractionDigits":{let a=F(o);if(a==="auto")s.minimumFractionDigits=void 0,s.maximumFractionDigits=void 0;else{let c=U(a);s.minimumFractionDigits=c,s.maximumFractionDigits=c}break}}}catch{t.onError("bad-option",`Value ${o} is not valid for :currency option ${i}`)}}if(!s.currency)throw new L("bad-operand","A currency code is required for :currency");return at(t,r.value,s,!1)}var Fr=new Set(["weekday","day-weekday","month-day","month-day-weekday","year-month-day","year-month-day-weekday"]),Br=new Set(["long","medium","short"]),Hr=new Set(["hour","minute","second"]),Vr=new Set(["long","short"]),An=(t,e,n)=>Ne("datetime",t,e,n),Dn=(t,e,n)=>Ne("date",t,e,n),Fn=(t,e,n)=>Ne("time",t,e,n);function Ne(t,e,n,r){let s={localeMatcher:e.localeMatcher},i=r;if(typeof i==="object"&&i!==null){let l=i.options;if(l){if(s.calendar=l.calendar,t!=="date")s.hour12=l.hour12;s.timeZone=l.timeZone}if(typeof i.valueOf==="function")i=i.valueOf()}switch(typeof i){case"number":case"string":i=new Date(i)}if(!(i instanceof Date)||isNaN(i.getTime()))throw new L("bad-operand","Input is not a valid date");if(n.calendar!==void 0)try{s.calendar=F(n.calendar)}catch{e.onError("bad-option",`Invalid :${t} calendar option value`)}if(n.hour12!==void 0&&t!=="date")try{s.hour12=Le(n.hour12)}catch{e.onError("bad-option",`Invalid :${t} hour12 option value`)}if(n.timeZone!==void 0){let l;try{l=F(n.timeZone)}catch{e.onError("bad-option",`Invalid :${t} timeZone option value`)}if(l==="input"){if(s.timeZone===void 0)e.onError("bad-operand",`Missing input timeZone value for :${t}`)}else if(l!==void 0){if(s.timeZone!==void 0&&l!==s.timeZone)throw new L("bad-option","Time zone conversion is not supported");s.timeZone=l}}if(t!=="time"){let l=t==="date"?"fields":"dateFields",u=t==="date"?"length":"dateLength",f=zt(e,n,l,Fr)??"year-month-day",h=zt(e,n,u,Br),d=new Set(f.split("-"));if(d.has("year"))s.year="numeric";if(d.has("month"))s.month=h==="long"?"long":h==="short"?"numeric":"short";if(d.has("day"))s.day="numeric";if(d.has("weekday"))s.weekday=h==="long"?"long":"short"}if(t!=="date"){switch(zt(e,n,t==="time"?"precision":"timePrecision",Hr)){case"hour":s.hour="numeric";break;case"second":s.hour="numeric",s.minute="numeric",s.second="numeric";break;default:s.hour="numeric",s.minute="numeric"}s.timeZoneName=zt(e,n,"timeZoneStyle",Vr)}let o=new Intl.DateTimeFormat(e.locales,s),a=e.dir,c,p;return{type:"datetime",get dir(){if(a==null)c??=o.resolvedOptions().locale,a=ot(c);return a},get options(){return{...s}},toParts(){let l=o.formatToParts(i);return c??=o.resolvedOptions().locale,a??=ot(c),a==="ltr"||a==="rtl"?[{type:"datetime",dir:a,locale:c,parts:l}]:[{type:"datetime",locale:c,parts:l}]},toString(){return p??=o.format(i),p},valueOf:()=>i}}function zt(t,e,n,r){let s=e[n];if(s!==void 0)try{let i=F(s);if(r&&!r.has(i))throw Error();return i}catch{t.onError("bad-option",`Invalid value for ${n} option`)}return}function Bn(t,e,n){let{value:r,options:s}=X(n),i;try{i="add"in e?U(e.add):-1}catch{throw new L("bad-option",`Value ${e.add} is not valid for :offset option add`)}let o;try{o="subtract"in e?U(e.subtract):-1}catch{throw new L("bad-option",`Value ${e.subtract} is not valid for :offset option subtract`)}if(i<0===o<0)throw new L("bad-option",'Exactly one of "add" or "subtract" is required as an :offset option');let a=i<0?-o:i;if(typeof r==="number")r+=a;else r+=BigInt(a);return Gt(t,{},{valueOf:()=>r,options:s})}function Hn(t,e,n){let r=X(n),s=Object.assign({},r.options,{localeMatcher:t.localeMatcher,style:"percent"});for(let[i,o]of Object.entries(e)){if(o===void 0)continue;try{switch(i){case"roundingMode":case"roundingPriority":case"signDisplay":case"trailingZeroDisplay":case"useGrouping":s[i]=F(o);break;case"minimumFractionDigits":case"maximumFractionDigits":case"minimumSignificantDigits":case"maximumSignificantDigits":s[i]=U(o);break}}catch{t.onError("bad-option",`Value ${o} is not valid for :percent option ${i}`)}}return at(t,r.value,s,!0)}function Jt(t,e,n){let r=n===void 0?"":String(n),s=r.normalize();return{type:"string",dir:t.dir??"auto",selectKey:(i)=>i.has(s)?s:null,toParts(){let{dir:i}=t,o=t.locales[0];return i==="ltr"||i==="rtl"?[{type:"string",dir:i,locale:o,value:r}]:[{type:"string",locale:o,value:r}]},toString:()=>r,valueOf:()=>r}}function Vn(t,e,n){let r=X(n),s=Object.assign({},r.options,{localeMatcher:t.localeMatcher,style:"unit"});for(let[i,o]of Object.entries(e)){if(o===void 0)continue;try{switch(i){case"signDisplay":case"roundingMode":case"roundingPriority":case"trailingZeroDisplay":case"unit":case"unitDisplay":case"useGrouping":s[i]=F(o);break;case"minimumIntegerDigits":case"minimumFractionDigits":case"maximumFractionDigits":case"minimumSignificantDigits":case"maximumSignificantDigits":case"roundingIncrement":s[i]=U(o);break}}catch(a){if(a instanceof it)t.onError(a);else t.onError("bad-option",`Value ${o} is not valid for :currency option ${i}`)}}if(!s.unit)throw new L("bad-operand","A unit identifier is required for :unit");return at(t,r.value,s,!1)}var It={currency:_n,integer:jn,number:Gt,offset:Bn,percent:Hn,string:Jt};It=Object.freeze(Object.assign(Object.create(null),It));var Yt={date:Dn,datetime:An,time:Fn,unit:Vn};Yt=Object.freeze(Object.assign(Object.create(null),Yt));var Rt=Symbol("bidi-isolate");var Ct=(t="�")=>({type:"fallback",source:t,toParts:()=>[{type:"fallback",source:t}],toString:()=>`{${t}}`});var Un=(t,e)=>({type:"unknown",source:t,dir:"auto",toParts:()=>[{type:"unknown",value:e}],toString:()=>String(e),valueOf:()=>e});class ft{#t;#e;#n;dir;id;constructor(t,e,n){this.#t=t,this.#n=e,this.dir=void 0;let r=n&&Object.hasOwn(n,"u:dir")?n["u:dir"]:void 0;if(r){let i=String(ct(t,r));if(i==="ltr"||i==="rtl"||i==="auto")this.dir=i;else if(i!=="inherit"){let o=new L("bad-option","Unsupported value for u:dir option");o.source=bt(r),t.onError(o)}}let s=n&&Object.hasOwn(n,"u:id")?n["u:id"]:void 0;if(this.id=s?String(ct(t,s)):void 0,n){this.#e=new Set;for(let[i,o]of Object.entries(n))if(o.type==="literal")this.#e.add(i)}}get literalOptionKeys(){return new Set(this.#e)}get localeMatcher(){return this.#t.localeMatcher}get locales(){return this.#t.locales.map(String)}onError(t,e){let n;if(t instanceof L)n=t;else if(typeof t==="string"&&typeof e==="string")n=new L(t,e);else n=new L("function-error",String(t)),n.cause=t;n.source=this.#n,this.#t.onError(n)}}function Wn(t,e,{name:n,options:r}){let s=`:${n}`,i=bt(e)??s;try{let o=e?[ct(t,e)]:[],a=t.functions[n];if(!a)throw new G("unknown-function",`Unknown function ${s}`,i);let c=new ft(t,i,r),p=Ur(t,r),l=a(c,p,...o);if(l===null||typeof l!=="object"||typeof l.type!=="string")throw new G("bad-function-result",`Function ${s} did not return a MessageValue`,i);let u={source:i};if(c.dir)u.dir=c.dir,u[Rt]=!0;if(c.id&&typeof l.toParts==="function")u.toParts=()=>{let f=l.toParts();for(let h of f)h.id=c.id;return f};return{...l,...u}}catch(o){return t.onError(o instanceof it?o:new G("bad-function-result",String(o),i,o)),Ct(i)}}function Ur(t,e){let n=Object.create(null);if(e){for(let[r,s]of Object.entries(e))if(!r.startsWith("u:"))n[r]=ct(t,s)}return n}function Pt(t,{arg:e,functionRef:n}){if(n)return Wn(t,e,n);switch(e?.type){case"literal":{let r=`|${e.value}|`,s=new ft(t,r),i=Jt(s,{},e.value);return i.source=r,i}case"variable":return Xt(t,e);default:throw Error(`Unsupported expression: ${e?.type}`)}}class Qt{expression;scope;constructor(t,e){this.expression=t,this.scope=e}}var Wr=(t)=>t!==null&&(typeof t==="object"||typeof t==="function");function Kn(t,e){if(Wr(t)){if(e in t)return t[e];let n=e.split(".");for(let r=n.length-1;r>0;--r){let s=n.slice(0,r).join(".");if(s in t){let i=n.slice(r).join(".");return Kn(t[s],i)}}for(let[r,s]of Object.entries(t))if(r.normalize()===e)return s}return}function Me(t,{name:e}){let n=Kn(t.scope,e);if(n===void 0){let r="$"+e,s=`Variable not available: ${r}`;t.onError(new G("unresolved-variable",s,r))}else if(n instanceof Qt){let r=Pt(n.scope?{...t,scope:n.scope}:t,n.expression);return t.scope[e]=r,t.localVars.add(r),r}return n}function Xt(t,e){let n="$"+e.name,r=Me(t,e);if(r===void 0)return Ct(n);let s=typeof r;if(s==="object"){let c=r;if(c.type==="fallback")return Ct(n);if(t.localVars.has(c))return c.source=n,c;if(r instanceof Number)s="number";else if(r instanceof String)s="string"}let i;switch(s){case"bigint":case"number":i=t.functions.number;break;case"string":i=t.functions.string;break;default:return Un(n,r)}let o=new ft(t,n),a=i(o,{},r);return a.source=n,a}function ct(t,e){switch(e.type){case"literal":return e.value;case"variable":return Me(t,e);default:throw Error(`Unsupported value: ${e.type}`)}}function bt(t){switch(t?.type){case"literal":return"|"+t.value.replaceAll("\\","\\\\").replaceAll("|","\\|")+"|";case"variable":return"$"+t.name;default:return}}function $e(t,{kind:e,name:n,options:r}){let s={type:"markup",kind:e,name:n},i=r?Object.entries(r):null;if(i?.length){s.options={};for(let[o,a]of i)if(o==="u:dir"){let c=new L("bad-option",`The option ${o} is not valid for markup`);c.source=bt(a),t.onError(c)}else{let c=ct(t,a);if(typeof c==="object"&&typeof c?.valueOf==="function")c=c.valueOf();if(o==="u:id")s.id=String(c);else s.options[o]=c}}return s}function je(t,e){if(e.type==="message")return e.pattern;let n=e.selectors.map((i)=>{let o=Xt(t,i),a;if(typeof o.selectKey==="function")a=o.selectKey.bind(o);else t.onError(new G("bad-selector","Selector does not support selection",o.source)),a=()=>null;return{selectKey:a,source:o.source,best:null,keys:null}}),r=e.variants;t:for(let i=0;i<n.length;++i){let o=n[i];if(!o.keys){o.keys=new Set;for(let{keys:a}of r){let c=a[i];if(!c)break t;if(c.type!=="*")o.keys.add(c.value)}}try{o.best=o.keys.size?o.selectKey(o.keys):null}catch(a){t.onError(new G("bad-selector","Selection failed",o.source,a)),o.selectKey=()=>null,o.best=null}if(r=r.filter((a)=>{let c=a.keys[i];if(c.type==="*")return o.best==null;return o.best===c.value}),r.length===0){if(i===0)break;let a=n[i-1];if(a.best==null)a.keys?.clear();else a.keys?.delete(a.best);for(let c=i;c<n.length;++c)n[c].keys=null;r=e.variants,i=-1}}let s=r[0];if(!s)return t.onError(new G("no-match","No variant was selected!?",".match")),[];return s.value}class te{#t;#e;#n;#s;#r;#i;constructor(t,e,n){this.#t=n?.bidiIsolation!=="none",this.#n=n?.localeMatcher??"best fit",this.#s=Array.isArray(t)?t.map((r)=>new Intl.Locale(r)):t?[new Intl.Locale(t)]:[],this.#e=n?.dir??ot(this.#s[0]),this.#r=typeof e==="string"?we(e):e,Pe(this.#r),this.#i=n?.functions?Object.assign(Object.create(null),It,n.functions):It}format(t,e){let n=this.#o(t,e),r="";for(let s of je(n,this.#r))if(typeof s==="string")r+=s;else if(s.type==="markup")$e(n,s);else{let i;try{if(i=Pt(n,s),typeof i.toString==="function")if(this.#t&&(this.#e!=="ltr"||i.dir!=="ltr"||i[Rt])){let o=i.dir==="ltr"?Oe:i.dir==="rtl"?Te:Et;r+=o+i.toString()+wt}else r+=i.toString();else{let o=new L("not-formattable","Message part is not formattable");throw o.source=i.source,o}}catch(o){n.onError(o);let a=`{${i?.source??"�"}}`;r+=this.#t?Et+a+wt:a}}return r}formatToParts(t,e){let n=this.#o(t,e),r=[];for(let s of je(n,this.#r))if(typeof s==="string")r.push({type:"text",value:s});else if(s.type==="markup")r.push($e(n,s));else{let i;try{if(i=Pt(n,s),typeof i.toParts==="function"){let o=i.toParts();if(this.#t&&(this.#e!=="ltr"||i.dir!=="ltr"||i[Rt])){let a=i.dir==="ltr"?Oe:i.dir==="rtl"?Te:Et;r.push({type:"bidiIsolation",value:a},...o,{type:"bidiIsolation",value:wt})}else r.push(...o)}else{let o=new L("not-formattable","Message part is not formattable");throw o.source=i.source,o}}catch(o){n.onError(o);let a={type:"fallback",source:i?.source??"�"};if(this.#t)r.push({type:"bidiIsolation",value:Et},a,{type:"bidiIsolation",value:wt});else r.push(a)}}return r}#o(t,e=(n)=>{try{process.emitWarning(n)}catch{console.warn(n)}}){let n={...t};for(let s of this.#r.declarations)n[s.name]=new Qt(s.value,s.type==="input"?t??{}:void 0);return{onError:e,localeMatcher:this.#n,locales:this.#s,localVars:new WeakSet,functions:this.#i,scope:n}}}var qn={MessageFormat:te,functions:Yt};var Kr=null;var qr=/^[-\w]+$/,Yn=/^(%|[a-zA-Z]+)/,Zn=["<number>","0"];function ne(t,e){let n=t[e];e++;while(e<t.length){if(t[e]==="\\"){e+=2;continue}if(t[e]===n)return e+1;e++}return e}function Xn(t,e){let n=t.indexOf("*/",e+2);return n<0?t.length:n+2}function Zr(t,e){let n=t.indexOf(`
5
+ `,e+2);return n<0?t.length:n}var Gr=(t)=>t.replace(/["\\]/g,"\\$&");function ee(t,e,n){let r=1,s=-1;for(let i=0;i<e;i++)if(t[i]===`
6
+ `)r++,s=i;return{line:r,col:e-s,offset:e,length:n}}function _e(t,e){let n=e+1,r=0,s=!1,i=!1;while(n<t.length){let a=t[n];if(a==='"'||a==="'"){n=ne(t,n);continue}if(a==="{"||a===";")return null;if(a==="}")break;if(a==="("||a==="[")r++;else if(a===")"||a==="]")r--;else if(r===0){if(a==="?")s=!0;else if(a===":"&&!s)i=!0}n++}if(n>=t.length||i)return null;let o=t.slice(e+1,n).trim();return o?{end:n,expr:o}:null}var zr=new Set(["state","input","static","context","self"]);function Jr(t,e,n,r){let s=[],i=e,o=e,a=0;while(i<t.length){let c=t[i];if(c==='"'||c==="'"){i=ne(t,i);continue}if(c==="/"&&t[i+1]==="*"){let p=Xn(t,i);if(!n)s.push(t.slice(o,i)," "),o=p;i=p;continue}if(c==="("){a++,i++;continue}if(c===")"){a--,i++;continue}if(a===0&&(c===";"||c==="}"))return s.push(t.slice(o,i)),{end:i,parts:s};if(c==="{"){let p=_e(t,i);if(!p)return t.indexOf("}",i+1)<0&&r?.(i),null;s.push(t.slice(o,i));let l=Yn.exec(t.slice(p.end+1)),u=l?l[1]:"";s.push({expr:p.expr,unit:u,at:i}),i=p.end+1+u.length,o=i;continue}i++}return s.some((c)=>typeof c!=="string")&&r?.(e),null}var Yr=/^@(-\w+-)?(keyframes|font-face|property|counter-style|font-feature-values|font-palette-values|page|view-transition|position-try|color-profile|function)\b/i,Gn=/^@(import|charset|namespace)\b/i,Xr=/^@(media|supports|container|layer|scope|starting-style|document)\b/i,Qr=/^([a-zA-Z_*\\]|[^\x00-\x7f])/,ts=/^(?:[-\w*|]|[^\x00-\x7f]|\\[\s\S])+/,es=/&[-_]/,Qn=/\s/,zn=/[{};]/,Jn=/[-\w]/,tr=/"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'/g,ns=new RegExp(`(${tr.source})|\\s+`,"g"),rs=/\/\*[\s\S]*?\*\//g,ss=/^@layer\b/i,is=(t)=>t.replace(ns,(e,n)=>n||" ");function os(t){let e=[],n=0,r=0;for(let s=0;s<t.length;s++){let i=t[s];if(i==="\\"){s++;continue}if(i==='"'||i==="'"){s=ne(t,s)-1;continue}if(i==="("||i==="[")r++;else if(i===")"||i==="]")r--;else if(i===","&&!r)e.push(t.slice(n,s)),n=s+1}return e.push(t.slice(n)),e.map((s)=>{let i=s.trimStart(),o=i.length;while(o&&Qn.test(i[o-1])&&i[o-2]!=="\\")o--;if(i=i.slice(0,o),!Qr.test(i))return i;return i.includes("&")?i.replace(ts,":is($&)"):`& ${i}`}).join(",")}function as(t,e,n,r){let s=[],i=[],o=[],a=`--${e.nsp.replace(/[^a-zA-Z0-9_-]/g,"-")}`,c=(k,O,C,T,M)=>r.push({code:k,severity:"error",message:O,hint:M,loc:ee(t,C,T)}),p=(k,O,C,T,M)=>r.push({code:k,severity:"warning",message:O,hint:M,loc:ee(t,C,T)}),l=(k,O,C,T)=>e.lint?.(k,T)?.forEach((M)=>r.push({...M,loc:ee(t,O,C-O)})),u=(k)=>{let O=s.indexOf(k);if(O<0)O=s.push(k)-1;return O},f=(k)=>{let{ast:O,diagnostics:C}=et(k.expr),T=k.expr.length+2;if(C.length){c("LIPS-S004",`Invalid expression: ${C[0].message}`,k.at,T);return}for(let M of Ue(O))if(!zr.has(M)&&!(M in globalThis))c("LIPS-S003",`'${M}' is not readable from a stylesheet`,k.at,T,"Stylesheets see state, input, static, context and self — not <for> iterators or <let> names, "+"which are local to a template position.");k.unit&&O.t==="lit"&&typeof O.v==="string"&&p("LIPS-S005",`Unit '${k.unit}' after a string value`,k.at,T,`A unit suffix multiplies a number: drop the unit, or return ${k.unit==="%"?"50":"8"} instead of a string.`)},h="",d="",y="",x=!1,g=(k)=>{if(!k)return;if(x&&y&&!zn.test(y)&&!zn.test(k[0]))d+=" ";x=!1,d+=k,y=k[k.length-1]},S=(k)=>{h+=d+k,d="",y=k,x=!1},E=()=>{let k=d;return d=y="",x=!1,k},w=(k)=>":"+(is(k).trim()||" "),v=0,m=0,I=0,N="",q="",B="",W=!1,P=[{ctx:e.meta?"top":"style"}],Q=()=>{let k=P[P.length-1],O=d,C;if(k.ctx==="opaque"||l(O,I,v),O[0]==="@")if(k.ctx!=="opaque"&&Yr.test(O))C={ctx:"opaque",hoist:h.length};else if(Xr.test(O))C={ctx:k.ctx,group:O,at:h.length};else C={ctx:"opaque"};else{if(k.ctx==="style"){if(n)es.test(O.replace(tr,""))&&p("LIPS-S008",`'${O}' joins '&' to a name`,I,v-I,"Native nesting cannot: write the full selector, or use stylisPreprocessor."),d=os(O)}C={ctx:k.ctx==="opaque"?"opaque":"style"}}P.push(C),S("{"),C.group&&(C.body=h.length)},tt=()=>{let k=P.pop();if(k.group&&!d&&h.length===k.body&&!ss.test(k.group)){h=h.slice(0,k.at),y="",x=!1;return}if(S("}"),k.hoist===void 0)return;let O=h.slice(k.hoist),C=P.filter((ht)=>ht.group),T=C.map((ht)=>ht.group).join("{"),M="}".repeat(C.length);h=h.slice(0,k.hoist),y="",q=T&&T===B?q.slice(0,q.length-M.length)+O+M:q+C.map((ht)=>ht.group+"{").join("")+O+M,B=T};while(v<t.length){let k=t[v];if(k==="\\"){g(t.slice(v,v+2)),v+=2;continue}let O=k==="/"&&!t.slice(I,v).trim();if(k==="/"&&(t[v+1]==="*"||t[v+1]==="/"&&O)){let C=t[v+1]==="/",T=C?Zr(t,v):Xn(t,v);if(!C&&!n)d?g(t.slice(v,T)):h+=t.slice(v,T);else Jn.test(y)&&Jn.test(t[T]||"")&&(x=!0);O&&(I=T),v=T;continue}if(k==='"'||k==="'"){let C=ne(t,v);g(t.slice(v,C)),v=C;continue}if(Qn.test(k)){I===v&&I++,x=!0,v++;continue}if(k==="(")m++;else if(k===")")m--;if(k===":"&&m===0){let C=t.slice(I,v).replace(rs,"").trim();if(qr.test(C)){let T=Jr(t,v+1,!n,(M)=>{W=!0,c("LIPS-S004","Unterminated interpolation",M,t.length-M,"Close the expression with `}`.")});if(T){let M=T.parts.filter((K)=>typeof K!=="string");for(let K of M)f(K);if(x=!1,C.startsWith("--")&&M.length===1&&!M[0].unit&&T.parts.every((K)=>typeof K!=="string"||!K.trim())){i.push({prop:C,e:u(M[0].expr)}),E(),v=T.end+(t[T.end]===";"?1:0),I=v;continue}let Tt="";for(let K of T.parts){if(typeof K==="string"){Tt+=K;continue}let De=u(K.expr),dt=`${a}-${De}`;if(!i.some((ie)=>ie.prop===dt)){if(i.push({prop:dt,e:De}),K.unit&&!o.some((ie)=>ie.name===dt))o.push({name:dt,syntax:Zn[0],inherits:!0,initial:Zn[1]})}Tt+=K.unit?`calc(var(${dt}) * 1${K.unit})`:`var(${dt})`}l(C,I,T.end,Tt),g(w(Tt)),v=T.end;continue}}}if(k==="{"){if(m>0){let C=_e(t,v);if(C){c("LIPS-S002","Interpolation in an at-rule condition",v,C.end-v+1,"Media and container conditions cannot read custom properties. Keep the condition static.");let T=Yn.exec(t.slice(C.end+1));v=C.end+1+(T?T[1].length:0);continue}}if(!t.slice(I,v).trim()){let C=_e(t,v);if(C){c("LIPS-S001","Interpolation in a selector",v,C.end-v+1,"Selectors are static in Layer 1. Bind a value inside the rule instead."),v=C.end+1,I=v;continue}}Q(),I=++v;continue}if(k==="}"){if(P.length>1)tt();else p("LIPS-S007","Unmatched `}` dropped",v,1),d&&S(";");I=++v;continue}if(k===";"){if(d[0]==="@"&&l(d,I,v),P.length===1&&Gn.test(d))N+=E()+";";else S(";");I=++v;continue}g(k),v++}if(P.length>1){W||p("LIPS-S007","Unclosed `{` closed at the end",t.length,0);while(P.length>1)tt()}return Gn.test(d)&&(N+=E()+";"),S(""),{css:h,statements:N,hoisted:q,exprs:s,binds:i,props:o}}function re(t,e){let n=[],r=e.preprocess||Kr,{css:s,statements:i,hoisted:o,exprs:a,binds:c,props:p}=as(t,e,!r,n),l={v:1,nsp:e.nsp,css:"",exprs:[],binds:[]},u=e.meta||!s?s:`${e.scope||`[rel="${Gr(e.nsp)}"]`}{${s}}`,f=o+u,h=e.layer?`@layer ${e.layer}{${f}}`:f,d;try{d=r?r(h):h}catch(g){return n.push({code:"LIPS-S006",severity:"error",message:`Style compilation failed: ${g.message}`,loc:ee(t,0,t.length)}),{ir:l,diagnostics:n}}let y=p.map((g)=>`@property ${g.name}{syntax:"${g.syntax}";inherits:${g.inherits};initial-value:${g.initial}}`).join(""),x={v:1,nsp:e.nsp,css:i+y+d,exprs:a,binds:c};if(p.length)x.props=p;return{ir:x,diagnostics:n}}var cs=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),ls=new Set(["pre","textarea"]),er=new Set(["if","else-if","switch","log"]),nr={__proto__:null,amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" "},ps=/&(?:#(\d+)|#[xX]([0-9a-fA-F]+)|([A-Za-z][A-Za-z0-9]*));/g;function us(t,e){return t.replace(ps,(n,r,s,i,o)=>{if(i===void 0){let a=r!==void 0?parseInt(r,10):parseInt(s,16);return a>0&&a<=1114111?String.fromCodePoint(a):n}if(i in nr)return nr[i];return e?.(i,o),n})}class Ae{src;pos=0;lineStarts=null;diagnostics=[];constructor(t){this.src=t}locate(t){if(!this.lineStarts){this.lineStarts=[0];for(let r=0;r<this.src.length;r++)if(this.src[r]===`
7
+ `)this.lineStarts.push(r+1)}let e=0,n=this.lineStarts.length-1;while(e<n){let r=e+n+1>>1;this.lineStarts[r]<=t?e=r:n=r-1}return{line:e+1,col:t-this.lineStarts[e]+1}}report(t,e,n,r,s=1,i){let{line:o,col:a}=this.locate(r);this.diagnostics.push({code:t,severity:e,message:n,hint:i,loc:{line:o,col:a,offset:r,length:s}})}decode(t,e){return us(t,(n,r)=>this.report("LIPS-P013","warning",`&${n}; is not decoded`,e+r,n.length+2,"Write the character, or its number: &#169;"))}eof(){return this.pos>=this.src.length}peek(t=0){return this.src[this.pos+t]}startsWith(t){return this.src.startsWith(t,this.pos)}skipSpace(){while(!this.eof()&&/\s/.test(this.src[this.pos]))this.pos++}scanBalanced(t,e){let n=this.pos,r=0;while(!this.eof()){let s=this.src[this.pos];if(s==="'"||s==='"'||s==="`"){this.pos++;while(!this.eof()&&this.src[this.pos]!==s){if(this.src[this.pos]==="\\")this.pos++;this.pos++}this.pos++;continue}if(r===0&&s===t){let i=this.src.slice(n,this.pos);return this.pos++,{content:i,loc:{offset:n,length:i.length}}}if(s==="("||s==="["||s==="{")r++;else if(s===")"||s==="]"||s==="}"){if(r===0&&s!==t){this.report(e,"error",`Unbalanced '${s}'`,this.pos),this.pos++;continue}r--}this.pos++}return this.report(e,"error",`Unterminated — expected '${t}'`,n,this.pos-n),null}parse(){let t=[];while(!this.eof())if(t.push(...this.parseNodes([])),this.startsWith("</")){let e=this.pos;this.pos+=2;while(!this.eof()&&this.peek()!==">")this.pos++;!this.eof()&&this.pos++,this.report("LIPS-P005","error",`Stray closing tag ${this.src.slice(e,this.pos)}`,e,this.pos-e)}return{root:{t:"fragment",children:t,loc:{offset:0,length:this.src.length}},diagnostics:this.diagnostics}}parseNodes(t){let e=[];while(!this.eof()){if(this.startsWith("</"))break;let n=this.pos;if(this.peek()==="<"&&this.peek(1)!==void 0){let r=this.parseTag(t);r&&e.push(r)}else{let r=this.parseText(t);r&&e.push(r)}if(this.pos===n)this.pos++}return e}parseText(t){let e=this.pos,n=[],r="";while(!this.eof()&&this.peek()!=="<"){if(this.peek()==="{"){this.pos++;let a=this.scanBalanced("}","LIPS-P007");if(a)r&&n.push(r),r="",n.push({expr:a.content.trim(),loc:a.loc});continue}r+=this.peek(),this.pos++}r&&n.push(r);let s={offset:e,length:this.pos-e};if(n.some((a)=>typeof a!=="string"))return{t:"interp",parts:n.map((a)=>typeof a==="string"?this.decode(a,e):a),loc:s};let i=n.length?n[0]:"",o=t.some((a)=>ls.has(a));if(!i||!o&&!i.trim())return null;return{t:"text",value:this.decode(i,e),loc:s}}parseTag(t){let e=this.pos;if(this.startsWith("<!--")){let i=this.src.indexOf("-->",this.pos+4);if(i===-1)return this.report("LIPS-P003","error","Unterminated comment",e,this.src.length-e),this.pos=this.src.length,null;let o=this.src.slice(this.pos+4,i);return this.pos=i+3,{t:"comment",value:o,loc:{offset:e,length:this.pos-e}}}if(this.startsWith("<>")){this.pos+=2;let i=[];while(!0)if(i.push(...this.parseNodes([...t,"#fragment"])),this.closeStatus("#fragment",e,t)!=="stray")break;return{t:"fragment",children:i,loc:{offset:e,length:this.pos-e}}}if(this.startsWith("<{")){this.pos+=2;let i=this.scanBalanced("}","LIPS-P008");if(!i)return null;let o={t:"element",tag:"#dynamic",dynamicTag:{expr:i.content.trim(),loc:i.loc},attrs:[],children:[],selfClosed:!1,loc:{offset:e,length:0}};return this.finishTag(o,t,e),o}this.pos++;let n=this.pos;while(!this.eof()&&/[A-Za-z0-9_-]/.test(this.peek()))this.pos++;let r=this.src.slice(n,this.pos);if(!r||!/^[A-Za-z]/.test(r))return this.report("LIPS-P002","error","Invalid tag name",e,this.pos-e+1),{t:"text",value:"<",loc:{offset:e,length:1}};let s={t:"element",tag:r.toLowerCase(),attrs:[],children:[],selfClosed:!1,loc:{offset:e,length:0}};if(this.peek()==="(")if(er.has(s.tag)){this.pos++;let i=this.scanBalanced(")","LIPS-P012");i&&(s.head={expr:i.content.trim(),loc:i.loc})}else this.report("LIPS-P011","error",`Head expression is not allowed on <${s.tag}>`,this.pos,1,`Only ${[...er].map((i)=>`<${i}(…)>`).join(", ")} take a head`);return this.finishTag(s,t,e),s}finishTag(t,e,n){if(this.parseAttrs(t),t.selfClosed||cs.has(t.tag)){t.selfClosed=!0,t.loc={offset:n,length:this.pos-n};return}let r=t.tag==="#dynamic"?"#dynamic":t.tag;t.children=[];while(!0)if(t.children.push(...this.parseNodes([...e,r])),this.closeStatus(r,n,e)!=="stray")break;t.loc={offset:n,length:this.pos-n}}closeStatus(t,e,n){if(this.eof())return this.report("LIPS-P006","error",`Unclosed <${t==="#fragment"?"":t}> — reached end of template`,e,1,`Add </${t==="#fragment"||t==="#dynamic"?"":t}>`),"eof";if(!this.startsWith("</"))return"closed";let r=this.pos;if(this.pos+=2,this.peek()===">"){if(this.pos++,t!=="#fragment"&&t!=="#dynamic")this.report("LIPS-P004","warning",`Generic '</>' closes <${t}>`,r,3,`Prefer </${t}>`);return"closed"}let s=this.pos;while(!this.eof()&&/[A-Za-z0-9_-]/.test(this.peek()))this.pos++;let i=this.src.slice(s,this.pos).toLowerCase();if(this.skipSpace(),this.peek()===">"?this.pos++:this.report("LIPS-P001","error","Malformed closing tag",r,this.pos-r),i===t)return"closed";if(n.includes(i))return this.report("LIPS-P004","warning",`</${i}> auto-closes <${t}>`,r,this.pos-r,`Add the missing </${t}> before </${i}>`),this.pos=r,"ancestor";return this.report("LIPS-P005","error",`Stray closing tag </${i}> — <${t}> is open`,r,this.pos-r),"stray"}parseAttrs(t){while(!0){if(this.skipSpace(),this.eof()){this.report("LIPS-P001","error","Unexpected end of template inside tag",t.loc.offset);return}if(this.startsWith("/>")){this.pos+=2,t.selfClosed=!0;return}if(this.peek()===">"){this.pos++;return}let e=this.pos;if(this.startsWith("...")){this.pos+=3;let i=this.readUnquotedValue();t.attrs.push({k:"spread",source:i,loc:{offset:e,length:this.pos-e}});continue}if(this.peek()==="["){this.pos++;let i=this.scanBalanced("]","LIPS-P009");if(i){let o=i.content.split(",").map((a)=>a.trim()).filter(Boolean);t.attrs.push({k:"args",names:o,loc:{offset:e,length:this.pos-e}})}continue}let n=!1;if(this.peek()==="!")n=!0,this.pos++;let r=this.pos;while(!this.eof()&&/[^\s=/>()]/.test(this.peek()))this.pos++;let s=this.src.slice(r,this.pos);if(!s){this.report("LIPS-P009","error",`Invalid attribute syntax at '${this.peek()}'`,this.pos),this.pos++;continue}if(this.peek()==="("){this.pos++;let i=this.scanBalanced(")","LIPS-P010"),o=i?i.content.trim():"",a={offset:e,length:this.pos-e};s.startsWith("on-")?t.attrs.push({k:"event",name:s.slice(3),source:o,loc:a}):t.attrs.push({k:"fn",name:s,source:o,loc:a});continue}if(this.peek()==="="){this.pos++,this.parseAttrValue(t,s,e);continue}t.attrs.push({k:"bool",name:s,value:!n,loc:{offset:e,length:this.pos-e}})}}parseAttrValue(t,e,n){let r=this.peek();if(r==='"'||r==="'"){this.pos++;let i=this.pos,o=[],a="";while(!this.eof()&&this.peek()!==r){if(this.peek()==="{"){this.pos++;let p=this.scanBalanced("}","LIPS-P007");if(p)a&&o.push(a),a="",o.push({expr:p.content.trim(),loc:p.loc});continue}a+=this.peek(),this.pos++}a&&o.push(a),this.eof()?this.report("LIPS-P010","error",`Unterminated value for '${e}'`,i,this.pos-i):this.pos++;let c={offset:n,length:this.pos-n};o.some((p)=>typeof p!=="string")?t.attrs.push({k:"interp",name:e,parts:o.map((p)=>typeof p==="string"?this.decode(p,i):p),loc:c}):t.attrs.push({k:"literal",name:e,value:this.decode(o[0]??"",i),loc:c});return}if(r==="{"){this.pos++;let i=this.scanBalanced("}","LIPS-P007");t.attrs.push({k:"expr",name:e,source:i?i.content.trim():"",loc:{offset:n,length:this.pos-n}});return}let s=this.readUnquotedValue();s?t.attrs.push({k:"expr",name:e,source:s,loc:{offset:n,length:this.pos-n}}):this.report("LIPS-P010","error",`Missing value for attribute '${e}'`,n)}readUnquotedValue(){let t=this.pos,e=0;while(!this.eof()){let n=this.peek();if(n==="'"||n==='"'||n==="`"){this.pos++;while(!this.eof()&&this.peek()!==n){if(this.peek()==="\\")this.pos++;this.pos++}this.pos++;continue}if(e===0){if(/\s/.test(n)||n===">")break;if(n==="/"&&this.peek(1)===">")break}if(n==="("||n==="["||n==="{")e++;else if(n===")"||n==="]"||n==="}")e--;this.pos++}return this.src.slice(t,this.pos).trim()}}function Ot(t){return new Ae(t||"").parse()}function rr(t){let e=fs(t||""),n=(t||"").slice(0,e).trimEnd(),r=(t||"").slice(e),s=new Ae(r).parse(),i=n?n.split(`
8
+ `).length+(/\n\s*\n$/.test(t.slice(0,e))?1:0):0;return s.diagnostics.forEach((o)=>{o.loc.line+=n?t.slice(0,e).split(`
9
+ `).length-1:0,o.loc.offset+=e}),{script:n,...s}}function fs(t){let e=0,n=!0;for(let r=0;r<t.length;r++){let s=t[r];if(s==="'"||s==='"'||s==="`"){let i=s;r++;while(r<t.length&&t[r]!==i){if(t[r]==="\\")r++;r++}n=!1;continue}if(s==="/"&&t[r+1]==="/"){while(r<t.length&&t[r]!==`
10
10
  `)r++;n=!0;continue}if(s==="/"&&t[r+1]==="*"){let i=t.indexOf("*/",r+2);r=i===-1?t.length:i+1;continue}if(s===`
11
- `){n=!0;continue}if(n&&e===0&&s==="<"&&/[A-Za-z{>!]/.test(t[r+1]||""))return r;if(s==="("||s==="["||s==="{")e++;else if(s===")"||s==="]"||s==="}")e=Math.max(0,e-1);if(!/\s/.test(s))n=!1}return 0}var Qr="<!--$-->",Xr=new Set(["if","else-if","else","for","switch","async","let","const","log","context","i18n"]),ts=new Set(["case","default","then","catch","loading"]),es=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","menu","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","svg","circle","clippath","defs","ellipse","foreignobject","g","image","line","lineargradient","marker","mask","path","pattern","polygon","polyline","radialgradient","rect","stop","symbol","text","tspan","use"]),ns=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),rs=(t)=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),ss=(t)=>t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;"),Kn=(t)=>t!==""&&!isNaN(Number(t)),Zn=(t)=>{let e=t.trim(),n=0;for(let r=0;r<e.length;r++){let s=e[r];if(s==="'"||s==='"'||s==="`"){r++;while(r<e.length&&e[r]!==s){if(e[r]==="\\")r++;r++}continue}if(s==="("||s==="["||s==="{")n++;else if(s===")"||s==="]"||s==="}"){if(n--,n===0&&e[0]==="{"&&r===e.length-1)return Zn(e.slice(1,-1))}else if(n===0){if(s==="?")return!1;if(s===":")return!0}}return!1},is=(t)=>{if(t.k==="expr")return t.source;if(t.k!=="interp")return"";let e=t.parts.filter((n)=>typeof n!=="string");return e.length===1&&t.parts.every((n)=>typeof n!=="string"||!n.trim())?e[0].expr:""};class Gn{src;macros;tree;exprs=[];exprIndex=new Map;lineStarts=null;macroStack=[];diagnostics=[];constructor(t,e=new Map,n=!1){this.src=t;this.macros=e;this.tree=n}locate(t){if(!this.lineStarts){this.lineStarts=[0];for(let r=0;r<this.src.length;r++)if(this.src[r]===`
12
- `)this.lineStarts.push(r+1)}let e=0,n=this.lineStarts.length-1;while(e<n){let r=e+n+1>>1;this.lineStarts[r]<=t?e=r:n=r-1}return{line:e+1,col:t-this.lineStarts[e]+1}}report(t,e,n,r,s=1,i){let{line:a,col:o}=this.locate(r);this.diagnostics.push({code:t,severity:e,message:n,hint:i,loc:{line:a,col:o,offset:r,length:s}})}expr(t,e){let n=this.exprIndex.get(t);if(n!==void 0)return n;let{diagnostics:r}=X(t);for(let i of r){let a=(e?.offset??0)+i.loc.offset;this.report(i.code,"error",i.message,a,i.loc.length)}let s=this.exprs.length;return this.exprs.push(t),this.exprIndex.set(t,s),s}synth(t){let e=this.exprIndex.get(t);if(e!==void 0)return e;let n=this.exprs.length;return this.exprs.push(t),this.exprIndex.set(t,n),n}concat(t){t.filter((n)=>typeof n!=="string").forEach((n)=>{let{diagnostics:r}=X(n.expr);for(let s of r)this.report(s.code,"error",s.message,n.loc.offset+s.loc.offset,s.loc.length)});let e=t.map((n)=>typeof n==="string"?JSON.stringify(n):`((${n.expr})??"")`).join("+");return this.synth(e)}compInput(t){switch(t.k){case"literal":return{lit:t.value};case"bool":return{lit:t.value};case"expr":return{e:this.expr(t.source,t.loc)};case"interp":return{e:this.concat(t.parts)}}}compile(t){return{v:1,exprs:this.exprs,root:this.block(t,[])}}block(t,e){let n={html:"",scope:[...e],binds:[],blocks:[]},r=[],s=this.tree,i=[],a=(o,c,p,l=!1,u)=>{let f=0,m=!1,g=()=>(r.push(Qr),s&&p.push(0),m=!1,[...c,f++]);for(let b=0;b<o.length;b++){let k=o[b];switch(k.t){case"text":{if(l){let h={t:"text",p:g(),e:this.synth(JSON.stringify(k.value)),i18n:1};if(u)h.ik=u;n.binds.push(h);break}if(r.push(rs(k.value)),s&&(m?p[p.length-1]+=k.value:p.push(k.value)),!m)f++;m=!0;break}case"comment":{if(s)break;let h=k.value.replace(/--/g,"- -");r.push(`<!--${/^-?>/.test(h)?" "+h:h}-->`),m=!1,f++;break}case"interp":{let h={t:"text",p:g(),e:this.concat(k.parts)};if(l)h.i18n=1;if(l&&u)h.ik=u;n.binds.push(h);break}case"fragment":{o=[...o.slice(0,b),...k.children,...o.slice(b+1)],b--;break}case"element":{if(Xr.has(k.tag)){if(this.controlBlock(k,o,b,g(),n,e),k.tag==="if"){let h=b+1;while(h<o.length){let x=o[h];if(x.t==="element"&&(x.tag==="else-if"||x.tag==="else"))h++;else break}o=[...o.slice(0,b+1),...o.slice(h)]}break}if(ts.has(k.tag)){this.report("LIPS-C002","error",`<${k.tag}> is only valid inside its parent construct`,k.loc.offset,k.loc.length);break}if(k.tag==="#dynamic"){n.blocks.push(this.compLike(k,g(),e,"dynamic"));break}if(this.macros.has(k.tag)){let h=this.macroCall(k,g(),e);h&&n.blocks.push(h);break}if(!es.has(k.tag)){n.blocks.push(this.compLike(k,g(),e,"comp"));break}this.emitElement(k,c,f++,r,n,a,p),m=!1;break}}}};if(a(t,[],i),n.html=r.join(""),s)n.nodes=i;return n}emitElement(t,e,n,r,s,i,a){let o=[...e,n],c=`<${t.tag}`,p=[t.tag],l={},u=(d,E)=>{Object.prototype.hasOwnProperty.call(l,d)||(l[d]=E)};this.tree&&a.push(p);let f=t.attrs.filter((d)=>("name"in d)),m=f.some((d)=>d.name==="i18n"&&(d.k==="bool"&&d.value||d.k==="literal")),g=(d)=>m&&(d==="title"||d==="placeholder"),b=(d)=>{let E=f.find((M)=>M.name===d&&M.k==="literal");return E&&"value"in E&&E.value?String(E.value):void 0},k=b("i18n"),h=(d)=>b(`i18n-${d}`);!m&&f.some((d)=>d.name.startsWith("i18n-"))&&this.report("LIPS-C014","warning",`i18n-* key on <${t.tag}> without the 'i18n' marker — the attribute will not be translated`,t.loc.offset,t.loc.length);for(let d of t.attrs){if(this.tree&&"name"in d&&d.name==="@html"){this.report("LIPS-C021","error",`@html on <${t.tag}>: the 'tree' target has no HTML parser`,d.loc.offset,d.loc.length,"Write the markup in the template, or use @text");continue}if("name"in d&&d.name==="style"){let E=is(d);if(E&&Zn(E)){this.report("LIPS-C019","error",`style= on <${t.tag}> takes CSS text, not an object literal`,d.loc.offset,d.loc.length,'Write the declarations as CSS — style="border: 2px solid gray; margin: 3rem" — '+`and interpolate values into it where they vary: style="margin: {state.gap}rem". Styles that need pseudo-classes, media queries or keyframes belong in the component's stylesheet.`);continue}}if(this.quotedEvent(t.tag,d))continue;switch(d.k){case"literal":if(d.name==="@format"){s.binds.push(this.formatBind(o,d));break}if(d.name.startsWith("@")){s.binds.push({t:"prop",p:o,name:d.name.slice(1),e:this.synth(JSON.stringify(d.value))});break}if(d.name==="i18n"||d.name.startsWith("i18n-"))break;if(g(d.name)){let E={t:"attr",p:o,name:d.name,e:this.synth(JSON.stringify(d.value)),i18n:1},M=h(d.name);if(M)E.ik=M;s.binds.push(E);break}c+=` ${d.name}="${ss(d.value)}"`,u(d.name,d.value);break;case"bool":if(d.name!=="i18n"&&d.value)c+=` ${d.name}`,u(d.name,"");break;case"expr":{if(d.name==="@format"){s.binds.push(this.formatBind(o,d));break}if(d.name.startsWith("@")){s.binds.push({t:"prop",p:o,name:d.name.slice(1),e:this.expr(d.source,d.loc)});break}let E={t:"attr",p:o,name:d.name,e:this.expr(d.source,d.loc)};if(g(d.name)){E.i18n=1;let M=h(d.name);if(M)E.ik=M}s.binds.push(E);break}case"interp":{if(d.name==="@format"){s.binds.push(this.formatBind(o,d));break}if(d.name.startsWith("@")){s.binds.push({t:"prop",p:o,name:d.name.slice(1),e:this.concat(d.parts)});break}let E={t:"attr",p:o,name:d.name,e:this.concat(d.parts)};if(g(d.name)){E.i18n=1;let M=h(d.name);if(M)E.ik=M}s.binds.push(E);break}case"event":s.binds.push({t:"event",p:o,name:d.name,e:this.synth(d.source)});break;case"spread":s.binds.push({t:"spread",p:o,e:this.expr(d.source,d.loc)});break;case"fn":this.report("LIPS-C007","warning",`Callable attribute '${d.name}(…)' has no meaning on <${t.tag}>`,d.loc.offset,d.loc.length);break;case"args":this.report("LIPS-C008","warning",`Iterator arguments are not applicable to <${t.tag}>`,d.loc.offset,d.loc.length);break}}if(Object.keys(l).length&&(p[1]=l),ns.has(t.tag)){r.push(c+">");return}r.push(c+">");let R=k,C=t.children.filter((d)=>d.t==="text"||d.t==="interp");if(R&&(C.length>1||C.some((d)=>d.t==="interp")))this.report("LIPS-C015","error",`<${t.tag} i18n="${R}"> keys text that is not a single fixed string. Use @format="${R}, { … }" for interpolated text.`,t.loc.offset,t.loc.length),R=void 0;let v=[];if(t.children.length&&i(t.children,o,v,m,R),v.length)p[1]=l,p[2]=v;r.push(`</${t.tag}>`)}formatBind(t,e){let n=e.k==="literal"?e.value:e.k==="expr"?e.source:e.parts.map((a)=>typeof a==="string"?a:`{${a.expr}}`).join(""),r=n.indexOf(",");if(r===-1)return this.report("LIPS-C012","error",'@format expects "reference, { params }"',e.loc.offset,e.loc.length),{t:"prop",p:t,name:"format",e:this.synth("({})"),ref:n.trim()};let s=n.slice(0,r).trim(),i=n.slice(r+1).trim();return{t:"prop",p:t,name:"format",e:this.expr(i,e.loc),ref:s}}attrsOf(t){let e=new Map,n=[];for(let r of t.attrs)if(r.k==="args")n.push(...r.names);else if("name"in r)e.set(r.name,r);return{byName:e,args:n}}controlBlock(t,e,n,r,s,i){switch(t.tag){case"if":{let a=[{when:t.head?this.expr(t.head.expr,t.head.loc):this.missingHead(t),block:this.block(t.children,i)}];for(let o=n+1;o<e.length;o++){let c=e[o];if(c.t!=="element")break;if(c.tag==="else-if")a.push({when:c.head?this.expr(c.head.expr,c.head.loc):this.missingHead(c),block:this.block(c.children,i)});else if(c.tag==="else"){a.push({when:null,block:this.block(c.children,i)});break}else break}s.blocks.push({t:"if",p:r,branches:a});break}case"else-if":case"else":this.report("LIPS-C001","error",`<${t.tag}> without a preceding <if>`,t.loc.offset,t.loc.length);break;case"for":{let{byName:a,args:o}=this.attrsOf(t),c=a.get("in"),p=a.get("from"),l=a.get("to"),u=a.get("by");if(!c&&!p){this.report("LIPS-C004","error","<for> requires 'in' or 'from'/'to'",t.loc.offset,t.loc.length);break}let f={t:"for",p:r,args:o,block:this.block(t.children,[...i,...o])};if(c&&c.k==="expr")f.of=this.expr(c.source,c.loc);if(p)f.from=this.numInput(p);if(l)f.to=this.numInput(l);if(u&&(u.k==="literal"||u.k==="expr"))f.by=u.k==="literal"?{lit:u.value}:{e:this.expr(u.source,u.loc)};s.blocks.push(f);break}case"switch":{let a=t.head?this.expr(t.head.expr,t.head.loc):this.missingHead(t),o=[];for(let c of t.children){if(c.t!=="element")continue;if(c.tag==="case"){let{byName:p}=this.attrsOf(c),l=p.get("is");if(!l||l.k!=="literal"&&l.k!=="expr"){this.report("LIPS-C004","error","<case> requires an 'is' attribute",c.loc.offset,c.loc.length);continue}o.push({is:l.k==="literal"?{lit:l.value}:{e:this.expr(l.source,l.loc)},block:this.block(c.children,i)})}else if(c.tag==="default")o.push({is:null,block:this.block(c.children,i)});else this.report("LIPS-C003","error","Only <case>/<default> are valid inside <switch>",c.loc.offset,c.loc.length)}s.blocks.push({t:"switch",p:r,on:a,cases:o});break}case"async":{let a=t.attrs.find((c)=>c.k==="fn"&&c.name==="await");if(!a){this.report("LIPS-C004","error","<async> requires await(…)",t.loc.offset,t.loc.length);break}let o={t:"async",p:r,awaitE:this.expr(a.source,a.loc)};for(let c of t.children){if(c.t!=="element")continue;let{args:p}=this.attrsOf(c);if(c.tag==="then")o.then={args:p,block:this.block(c.children,[...i,...p])};else if(c.tag==="catch")o.catch={args:p,block:this.block(c.children,[...i,...p])};else if(c.tag==="loading")o.loading=this.block(c.children,i);else this.report("LIPS-C003","error","Only <then>/<catch>/<loading> are valid inside <async>",c.loc.offset,c.loc.length)}s.blocks.push(o);break}case"let":case"const":{let a={};for(let o of t.attrs){if(o.k==="spread"){this.report("LIPS-C013","error",`Spread is not supported on <${t.tag}> — scope names must be known at compile time`,o.loc.offset,o.loc.length,`Assign it to one variable: <${t.tag} obj={ ${o.source} }/> and read obj.<key>`);continue}if(o.k==="literal"||o.k==="expr"||o.k==="interp"||o.k==="bool")a[o.name]=this.compInput(o),!s.scope.includes(o.name)&&s.scope.push(o.name),!i.includes(o.name)&&i.push(o.name)}s.blocks.push({t:"let",p:r,const:t.tag==="const",vars:a});break}case"log":s.blocks.push({t:"log",p:r,e:t.head?this.synth(t.head.expr):this.missingHead(t)});break;case"context":{let a={};for(let o of t.attrs){if(o.k==="spread"){this.report("LIPS-C016","error","Spread is not supported on <context> — provided keys must be known at compile time",o.loc.offset,o.loc.length,"Provide them one by one: <context a=obj.a b=obj.b>");continue}if(o.k==="literal"||o.k==="expr"||o.k==="interp"||o.k==="bool")a[o.name]=this.compInput(o)}if(!Object.keys(a).length)this.report("LIPS-C017","warning","<context> provides nothing — it renders its children unchanged",t.loc.offset,t.loc.length);s.blocks.push({t:"provide",p:r,vars:a,block:this.block(t.children,i)});break}case"i18n":{let{byName:a}=this.attrsOf(t),o=a.get("lang");if(!o){this.report("LIPS-C018","error","<i18n> requires a 'lang' attribute: <i18n lang=state.docLang>",t.loc.offset,t.loc.length);break}s.blocks.push({t:"provide",p:r,vars:{},lang:this.compInput(o),block:this.block(t.children,i)});break}}}missingHead(t){return this.report("LIPS-C004","error",`<${t.tag}> requires a head expression: <${t.tag}( … )>`,t.loc.offset,t.loc.length),this.synth("undefined")}numInput(t){if(t.k==="literal")return{lit:Kn(t.value)?Number(t.value):t.value};if(t.k==="expr")return Kn(t.source)?{lit:Number(t.source)}:{e:this.expr(t.source,t.loc)};return{lit:void 0}}macroCall(t,e,n){let r=this.macros.get(t.tag);if(this.macroStack.includes(r.name))return this.report("LIPS-C009","error",`Recursive macro <${r.name}> (${[...this.macroStack,r.name].join(" → ")})`,t.loc.offset,t.loc.length),null;let s=[];for(let a of t.attrs)if(a.k==="literal"||a.k==="expr"||a.k==="interp"||a.k==="bool")s.push({name:a.name,ci:this.compInput(a)});else if(a.k==="spread")s.push({spread:this.expr(a.source,a.loc)});this.macroStack.push(r.name);let i=this.block(r.children,[...n,...r.argv]);return this.macroStack.pop(),{t:"macro",p:e,name:r.name,sets:s,args:r.argv,block:i}}quotedEvent(t,e){if(!("name"in e)||!e.name.startsWith("on-"))return!1;return this.report("LIPS-C020","error",`${e.name}="…" on <${t}> wires no listener`,e.loc.offset,e.loc.length,`Handlers use the instruction form: ${e.name}( … ). `+"Quoted, it is an ordinary attribute — the handler never runs and the source is emitted into the DOM."),!0}compLike(t,e,n,r){let s={},i=[],a=[],o=[];for(let p of t.attrs){if(p.k!=="event"&&this.quotedEvent(t.tag,p))continue;switch(p.k){case"literal":case"bool":case"expr":case"interp":s[p.name]=this.compInput(p);break;case"event":a.push({name:p.name,e:this.synth(p.source)});break;case"spread":i.push(this.expr(p.source,p.loc));break;case"args":o=[...o,...p.names];break;case"fn":s[p.name]={e:this.expr(p.source,p.loc)};break}}let c=t.children.length?{args:o,block:this.block(t.children,[...n,...o])}:void 0;return r==="comp"?{t:"comp",p:e,name:t.tag,inputs:s,spreads:i,events:a,contents:c}:{t:"dynamic",p:e,tag:this.expr(t.dynamicTag.expr,t.dynamicTag.loc),inputs:s,spreads:i,events:a,contents:c}}}function os(t,e,n){let r=new Map;if(!t?.trim())return r;let s=Rt(t);e.push(...s.diagnostics),n?.(s.root.children,e,t);for(let i of s.root.children){if(i.t!=="element")continue;if(i.tag!=="macro"){e.push({code:"LIPS-C010",severity:"warning",message:`Only <macro> definitions are allowed in the macros source — ignoring <${i.tag}>`,loc:{line:1,col:1,offset:i.loc.offset,length:i.loc.length}});continue}let a="",o=[];for(let c of i.attrs)if(c.k==="args")o.push(...c.names);else if(c.k==="literal"&&c.name==="name")a=c.value;if(!a){e.push({code:"LIPS-C011",severity:"error",message:"<macro> requires a name attribute",loc:{line:1,col:1,offset:i.loc.offset,length:i.loc.length}});continue}r.set(a.toLowerCase(),{name:a,argv:o,children:i.children})}return r}function re(t,e){let n=[],r=os(e?.macros||"",n,e?.check),s=Rt(t);e?.check?.(s.root.children,n,t),e?.transform?.(s.root.children,n);let i=new Gn(t,r,e?.target==="tree");return{ir:i.compile(s.root.children),diagnostics:[...n,...s.diagnostics,...i.diagnostics]}}function as(t){try{return decodeURIComponent(t)}catch(e){return t}}var cs=(t)=>Object.fromEntries(new URLSearchParams(t)),zn={state:{page:null,params:{},query:{}},handler:{onCreate(){this.__routes=[],this.__defaultPath=null,this.__currentRoute=null,this.__global=!1},onInput(){this.processor(this.input)},processor(t){if(!t?.routes)return;if(t.global)this.__global=!0;if(this.__routes=t.routes.map(({path:e,template:n,default:r})=>{if(r)this.__defaultPath=e;let s=e.match(/:[^\/]*(\/|$)/gi)||[],i=e.replaceAll("/","\\/").replaceAll(/:[^\/]*(\/|$)/gi,"([^\\/]+)(?:\\/|$)");return{path:e,template:n,default:r,pathVars:s,pathRegex:new RegExp(`${i}$`,"i")}}),t.global){let e=window.location.pathname;this.__defaultPath=this.__defaultPath&&e==="/"&&e!==this.__defaultPath?this.__defaultPath:e?e+window.location.search:this.__routes[0]?.path}},onAttach(){if(this.input?.global)window.navigate=this.navigate.bind(this),window.addEventListener("popstate",(t)=>t.state&&this.navigate(t.state.path,!0));typeof this.setContext==="function"&&this.setContext("navigate",this.navigate.bind(this)),this.__defaultPath&&this.navigate(this.__defaultPath)},navigate(t,e){!e&&this.__global&&history.pushState({path:t},"",t);let n=String(t).split("?");t=n[0];let r=n[1]?cs(n[1]):{},s=null;if(this.__currentRoute)s={path:this.__currentRoute.path,params:this.state.params},this.emit("before",{fromState:s,toState:{path:t,query:r}});let i=this.match(t);if(!i){this.__currentRoute=null,this.state.params={},this.state.query={},this.state.page=null,this.emit("not-found",t);return}let{route:a,params:o}=i;this.emit("after",{fromState:s,toState:{path:a.path,params:o,query:r}}),this.__currentRoute=a,this.state.params=o,this.state.query=r,this.state.page=a.template},match(t){let e={};for(let n of this.__routes){let r=t.match(n.pathRegex);if(r===null||r.index!==0)continue;for(let s=0;s+1<r.length&&s<n.pathVars.length;s++)e[n.pathVars[s].replaceAll(/[\/:]/g,"")]=as(r[s+1]);return{route:n,params:e}}return!1}},default:"<{state.page} params=state.params query=state.query/>"};rn(re);sn(ee);an(jn);ln("router",zn);var pa=de;export{pe as batch,ee as compileStyle,re as compileTemplate,pa as default,A as effect,qn as parseSFC,Rt as parseTemplate,Z as reactive,At as renderIR,F as signal,V as untrack};
11
+ `){n=!0;continue}if(n&&e===0&&s==="<"&&/[A-Za-z{>!]/.test(t[r+1]||""))return r;if(s==="("||s==="["||s==="{")e++;else if(s===")"||s==="]"||s==="}")e=Math.max(0,e-1);if(!/\s/.test(s))n=!1}return 0}var hs="<!--$-->",ds=new Set(["stop","capture","outside"]),gs=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),ms=(t)=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),ys=(t)=>t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;"),sr=(t)=>t!==""&&!isNaN(Number(t)),ir=(t)=>{let e=t.trim(),n=0;for(let r=0;r<e.length;r++){let s=e[r];if(s==="'"||s==='"'||s==="`"){r++;while(r<e.length&&e[r]!==s){if(e[r]==="\\")r++;r++}continue}if(s==="("||s==="["||s==="{")n++;else if(s===")"||s==="]"||s==="}"){if(n--,n===0&&e[0]==="{"&&r===e.length-1)return ir(e.slice(1,-1))}else if(n===0){if(s==="?")return!1;if(s===":")return!0}}return!1},bs=(t)=>{if(t.k==="expr")return t.source;if(t.k!=="interp")return"";let e=t.parts.filter((n)=>typeof n!=="string");return e.length===1&&t.parts.every((n)=>typeof n!=="string"||!n.trim())?e[0].expr:""};class or{src;macros;tree;exprs=[];exprIndex=new Map;lineStarts=null;macroStack=[];diagnostics=[];constructor(t,e=new Map,n=!1){this.src=t;this.macros=e;this.tree=n}locate(t){if(!this.lineStarts){this.lineStarts=[0];for(let r=0;r<this.src.length;r++)if(this.src[r]===`
12
+ `)this.lineStarts.push(r+1)}let e=0,n=this.lineStarts.length-1;while(e<n){let r=e+n+1>>1;this.lineStarts[r]<=t?e=r:n=r-1}return{line:e+1,col:t-this.lineStarts[e]+1}}report(t,e,n,r,s=1,i){let{line:o,col:a}=this.locate(r);this.diagnostics.push({code:t,severity:e,message:n,hint:i,loc:{line:o,col:a,offset:r,length:s}})}expr(t,e){let n=this.exprIndex.get(t);if(n!==void 0)return n;let{diagnostics:r}=et(t);for(let i of r){let o=(e?.offset??0)+i.loc.offset;this.report(i.code,"error",i.message,o,i.loc.length)}let s=this.exprs.length;return this.exprs.push(t),this.exprIndex.set(t,s),s}synth(t){let e=this.exprIndex.get(t);if(e!==void 0)return e;let n=this.exprs.length;return this.exprs.push(t),this.exprIndex.set(t,n),n}concat(t){t.filter((n)=>typeof n!=="string").forEach((n)=>{let{diagnostics:r}=et(n.expr);for(let s of r)this.report(s.code,"error",s.message,n.loc.offset+s.loc.offset,s.loc.length)});let e=t.map((n)=>typeof n==="string"?JSON.stringify(n):`((${n.expr})??"")`).join("+");return this.synth(e)}compInput(t){switch(t.k){case"literal":return{lit:t.value};case"bool":return{lit:t.value};case"expr":return{e:this.expr(t.source,t.loc)};case"interp":return{e:this.concat(t.parts)}}}compile(t){return{v:1,exprs:this.exprs,root:this.block(t,[])}}block(t,e){let n={html:"",scope:[...e],binds:[],blocks:[]},r=[],s=this.tree,i=[],o=(a,c,p,l=!1,u)=>{let f=0,h=!1,d=()=>(r.push(hs),s&&p.push(0),h=!1,[...c,f++]);for(let y=0;y<a.length;y++){let x=a[y];switch(x.t){case"text":{if(l){let g={t:"text",p:d(),e:this.synth(JSON.stringify(x.value)),i18n:1};if(u)g.ik=u;n.binds.push(g);break}if(r.push(ms(x.value)),s&&(h?p[p.length-1]+=x.value:p.push(x.value)),!h)f++;h=!0;break}case"comment":{if(s)break;let g=x.value.replace(/--/g,"- -");r.push(`<!--${/^-?>/.test(g)?" "+g:g}-->`),h=!1,f++;break}case"interp":{let g={t:"text",p:d(),e:this.concat(x.parts)};if(l)g.i18n=1;if(l&&u)g.ik=u;n.binds.push(g);break}case"fragment":{a=[...a.slice(0,y),...x.children,...a.slice(y+1)],y--;break}case"element":{if(ve.has(x.tag)){if(this.controlBlock(x,a,y,d(),n,e),x.tag==="if"){let g=y+1;while(g<a.length){let S=a[g];if(S.t==="element"&&(S.tag==="else-if"||S.tag==="else"))g++;else break}a=[...a.slice(0,y+1),...a.slice(g)]}break}if(Se.has(x.tag)){this.report("LIPS-C002","error",`<${x.tag}> is only valid inside its parent construct`,x.loc.offset,x.loc.length);break}if(x.tag==="#dynamic"){n.blocks.push(this.compLike(x,d(),e,"dynamic"));break}if(this.macros.has(x.tag)){let g=this.macroCall(x,d(),e);g&&n.blocks.push(g);break}if(!ke.has(x.tag)){n.blocks.push(this.compLike(x,d(),e,"comp"));break}this.emitElement(x,c,f++,r,n,o,p),h=!1;break}}}};if(o(t,[],i),n.html=r.join(""),s)n.nodes=i;return n}emitElement(t,e,n,r,s,i,o){let a=[...e,n],c=`<${t.tag}`,p=[t.tag],l={},u=(m,I)=>{Object.prototype.hasOwnProperty.call(l,m)||(l[m]=I)};this.tree&&o.push(p);let f=t.attrs.filter((m)=>("name"in m)),h=f.some((m)=>m.name==="i18n"&&(m.k==="bool"&&m.value||m.k==="literal")),d=(m)=>h&&(m==="title"||m==="placeholder"),y=(m)=>{let I=f.find((N)=>N.name===m&&N.k==="literal");return I&&"value"in I&&I.value?String(I.value):void 0},x=y("i18n"),g=(m)=>y(`i18n-${m}`);!h&&f.some((m)=>m.name.startsWith("i18n-"))&&this.report("LIPS-C014","warning",`i18n-* key on <${t.tag}> without the 'i18n' marker — the attribute will not be translated`,t.loc.offset,t.loc.length);for(let m of t.attrs){if(this.tree&&"name"in m&&m.name==="@html"){this.report("LIPS-C021","error",`@html on <${t.tag}>: the 'tree' target has no HTML parser`,m.loc.offset,m.loc.length,"Write the markup in the template, or use @text");continue}if("name"in m&&m.name==="style"){let I=bs(m);if(I&&ir(I)){this.report("LIPS-C019","error",`style= on <${t.tag}> takes CSS text, not an object literal`,m.loc.offset,m.loc.length,'Write the declarations as CSS — style="border: 2px solid gray; margin: 3rem" — '+`and interpolate values into it where they vary: style="margin: {state.gap}rem". Styles that need pseudo-classes, media queries or keyframes belong in the component's stylesheet.`);continue}}if(this.quotedEvent(t.tag,m))continue;switch(m.k){case"literal":if(m.name==="@format"){s.binds.push(this.formatBind(a,m));break}if(m.name.startsWith("@")){s.binds.push({t:"prop",p:a,name:m.name.slice(1),e:this.synth(JSON.stringify(m.value))});break}if(m.name==="i18n"||m.name.startsWith("i18n-"))break;if(d(m.name)){let I={t:"attr",p:a,name:m.name,e:this.synth(JSON.stringify(m.value)),i18n:1},N=g(m.name);if(N)I.ik=N;s.binds.push(I);break}c+=` ${m.name}="${ys(m.value)}"`,u(m.name,m.value);break;case"bool":if(m.name!=="i18n"&&m.value)c+=` ${m.name}`,u(m.name,"");break;case"expr":{if(m.name==="@format"){s.binds.push(this.formatBind(a,m));break}if(m.name.startsWith("@")){s.binds.push({t:"prop",p:a,name:m.name.slice(1),e:this.expr(m.source,m.loc)});break}let I={t:"attr",p:a,name:m.name,e:this.expr(m.source,m.loc)};if(d(m.name)){I.i18n=1;let N=g(m.name);if(N)I.ik=N}s.binds.push(I);break}case"interp":{if(m.name==="@format"){s.binds.push(this.formatBind(a,m));break}if(m.name.startsWith("@")){s.binds.push({t:"prop",p:a,name:m.name.slice(1),e:this.concat(m.parts)});break}let I={t:"attr",p:a,name:m.name,e:this.concat(m.parts)};if(d(m.name)){I.i18n=1;let N=g(m.name);if(N)I.ik=N}s.binds.push(I);break}case"event":this.modifiers(m),s.binds.push({t:"event",p:a,name:m.name,e:this.synth(m.source)});break;case"spread":s.binds.push({t:"spread",p:a,e:this.expr(m.source,m.loc)});break;case"fn":this.report("LIPS-C007","warning",`Callable attribute '${m.name}(…)' has no meaning on <${t.tag}>`,m.loc.offset,m.loc.length);break;case"args":this.report("LIPS-C008","warning",`Iterator arguments are not applicable to <${t.tag}>`,m.loc.offset,m.loc.length);break}}if(Object.keys(l).length&&(p[1]=l),gs.has(t.tag)){r.push(c+">");return}r.push(c+">");let E=x,w=t.children.filter((m)=>m.t==="text"||m.t==="interp");if(E&&(w.length>1||w.some((m)=>m.t==="interp")))this.report("LIPS-C015","error",`<${t.tag} i18n="${E}"> keys text that is not a single fixed string. Use @format="${E}, { … }" for interpolated text.`,t.loc.offset,t.loc.length),E=void 0;let v=[];if(t.children.length&&i(t.children,a,v,h,E),v.length)p[1]=l,p[2]=v;r.push(`</${t.tag}>`)}formatBind(t,e){let n=e.k==="literal"?e.value:e.k==="expr"?e.source:e.parts.map((o)=>typeof o==="string"?o:`{${o.expr}}`).join(""),r=n.indexOf(",");if(r===-1)return this.report("LIPS-C012","error",'@format expects "reference, { params }"',e.loc.offset,e.loc.length),{t:"prop",p:t,name:"format",e:this.synth("({})"),ref:n.trim()};let s=n.slice(0,r).trim(),i=n.slice(r+1).trim();return{t:"prop",p:t,name:"format",e:this.expr(i,e.loc),ref:s}}attrsOf(t){let e=new Map,n=[];for(let r of t.attrs)if(r.k==="args")n.push(...r.names);else if("name"in r)e.set(r.name,r);return{byName:e,args:n}}controlBlock(t,e,n,r,s,i){switch(t.tag){case"if":{let o=[{when:t.head?this.expr(t.head.expr,t.head.loc):this.missingHead(t),block:this.block(t.children,i)}];for(let a=n+1;a<e.length;a++){let c=e[a];if(c.t!=="element")break;if(c.tag==="else-if")o.push({when:c.head?this.expr(c.head.expr,c.head.loc):this.missingHead(c),block:this.block(c.children,i)});else if(c.tag==="else"){o.push({when:null,block:this.block(c.children,i)});break}else break}s.blocks.push({t:"if",p:r,branches:o});break}case"else-if":case"else":this.report("LIPS-C001","error",`<${t.tag}> without a preceding <if>`,t.loc.offset,t.loc.length);break;case"for":{let{byName:o,args:a}=this.attrsOf(t),c=o.get("in"),p=o.get("from"),l=o.get("to"),u=o.get("by");if(!c&&!p){this.report("LIPS-C004","error","<for> requires 'in' or 'from'/'to'",t.loc.offset,t.loc.length);break}let f={t:"for",p:r,args:a,block:this.block(t.children,[...i,...a])};if(c){let h=this.valueOf(c);h===void 0?this.report("LIPS-C004","error","<for in=…> takes an expression: in=state.items",c.loc.offset,c.loc.length):f.of=this.expr(h,c.loc)}if(p)f.from=this.numInput(p);if(l)f.to=this.numInput(l);if(u){let h=u.k==="literal"?void 0:this.valueOf(u);u.k==="literal"?f.by={lit:u.value}:h===void 0?this.report("LIPS-C004","error","<for by=…> takes a key path or an expression",u.loc.offset,u.loc.length):f.by={e:this.expr(h,u.loc)}}s.blocks.push(f);break}case"switch":{let o=t.head?this.expr(t.head.expr,t.head.loc):this.missingHead(t),a=[];for(let c of t.children){if(c.t!=="element")continue;if(c.tag==="case"){let{byName:p}=this.attrsOf(c),l=p.get("is");if(!l||l.k!=="literal"&&l.k!=="expr"){this.report("LIPS-C004","error","<case> requires an 'is' attribute",c.loc.offset,c.loc.length);continue}a.push({is:l.k==="literal"?{lit:l.value}:{e:this.expr(l.source,l.loc)},block:this.block(c.children,i)})}else if(c.tag==="default")a.push({is:null,block:this.block(c.children,i)});else this.report("LIPS-C003","error","Only <case>/<default> are valid inside <switch>",c.loc.offset,c.loc.length)}s.blocks.push({t:"switch",p:r,on:o,cases:a});break}case"async":{let o=t.attrs.find((c)=>c.k==="fn"&&c.name==="await");if(!o){this.report("LIPS-C004","error","<async> requires await(…)",t.loc.offset,t.loc.length);break}let a={t:"async",p:r,awaitE:this.expr(o.source,o.loc)};for(let c of t.children){if(c.t!=="element")continue;let{args:p}=this.attrsOf(c);if(c.tag==="then")a.then={args:p,block:this.block(c.children,[...i,...p])};else if(c.tag==="catch")a.catch={args:p,block:this.block(c.children,[...i,...p])};else if(c.tag==="loading")a.loading=this.block(c.children,i);else this.report("LIPS-C003","error","Only <then>/<catch>/<loading> are valid inside <async>",c.loc.offset,c.loc.length)}s.blocks.push(a);break}case"let":case"const":{let o={};for(let a of t.attrs){if(a.k==="spread"){this.report("LIPS-C013","error",`Spread is not supported on <${t.tag}> — scope names must be known at compile time`,a.loc.offset,a.loc.length,`Assign it to one variable: <${t.tag} obj={ ${a.source} }/> and read obj.<key>`);continue}if(a.k==="literal"||a.k==="expr"||a.k==="interp"||a.k==="bool")o[a.name]=this.compInput(a),!s.scope.includes(a.name)&&s.scope.push(a.name),!i.includes(a.name)&&i.push(a.name)}s.blocks.push({t:"let",p:r,const:t.tag==="const",vars:o});break}case"log":s.blocks.push({t:"log",p:r,e:t.head?this.synth(t.head.expr):this.missingHead(t)});break;case"context":{let o={};for(let a of t.attrs){if(a.k==="spread"){this.report("LIPS-C016","error","Spread is not supported on <context> — provided keys must be known at compile time",a.loc.offset,a.loc.length,"Provide them one by one: <context a=obj.a b=obj.b>");continue}if(a.k==="literal"||a.k==="expr"||a.k==="interp"||a.k==="bool")o[a.name]=this.compInput(a)}if(!Object.keys(o).length)this.report("LIPS-C017","warning","<context> provides nothing — it renders its children unchanged",t.loc.offset,t.loc.length);s.blocks.push({t:"provide",p:r,vars:o,block:this.block(t.children,i)});break}case"i18n":{let{byName:o}=this.attrsOf(t),a=o.get("lang");if(!a){this.report("LIPS-C018","error","<i18n> requires a 'lang' attribute: <i18n lang=state.docLang>",t.loc.offset,t.loc.length);break}s.blocks.push({t:"provide",p:r,vars:{},lang:this.compInput(a),block:this.block(t.children,i)});break}}}missingHead(t){return this.report("LIPS-C004","error",`<${t.tag}> requires a head expression: <${t.tag}( … )>`,t.loc.offset,t.loc.length),this.synth("undefined")}numInput(t){if(t.k==="literal")return{lit:sr(t.value)?Number(t.value):t.value};let e=this.valueOf(t);if(e!==void 0)return sr(e)?{lit:Number(e)}:{e:this.expr(e,t.loc)};return"name"in t&&this.report("LIPS-C004","error",`<for ${t.name}=…> takes a number or an expression`,t.loc.offset,t.loc.length),{lit:void 0}}valueOf(t){if(t.k==="expr")return t.source;if(t.k==="interp"&&t.parts.length===1&&typeof t.parts[0]!=="string")return t.parts[0].expr}macroCall(t,e,n){let r=this.macros.get(t.tag);if(this.macroStack.includes(r.name))return this.report("LIPS-C009","error",`Recursive macro <${r.name}> (${[...this.macroStack,r.name].join(" → ")})`,t.loc.offset,t.loc.length),null;let s=[];for(let o of t.attrs)if(o.k==="literal"||o.k==="expr"||o.k==="interp"||o.k==="bool")s.push({name:o.name,ci:this.compInput(o)});else if(o.k==="spread")s.push({spread:this.expr(o.source,o.loc)});else if(o.k==="event")this.report("LIPS-C023","error",`on-${o.name}( … ) on the macro <${t.tag}> wires no listener`,o.loc.offset,o.loc.length,"Pass the handler as an argument (fn=self.pick) and wire it in the body");t.children.length&&this.report("LIPS-C024","error",`<${t.tag}> is a macro: what it encloses is not rendered`,t.loc.offset,t.loc.length,"A component takes content: <{input.renderer}/>"),this.macroStack.push(r.name);let i=this.block(r.children,[...n,...r.argv]);return this.macroStack.pop(),{t:"macro",p:e,name:r.name,sets:s,args:r.argv,block:i}}quotedEvent(t,e){if(!("name"in e)||!e.name.startsWith("on-"))return!1;return this.report("LIPS-C020","error",`${e.name}="…" on <${t}> wires no listener`,e.loc.offset,e.loc.length,`Handlers use the instruction form: ${e.name}( … ). `+"Quoted, it is an ordinary attribute — the handler never runs and the source is emitted into the DOM."),!0}modifiers(t,e){let n=t.name.split(".").slice(1),r=n.find((s)=>!ds.has(s));(r||e&&n[0])&&this.report("LIPS-C022",r?"error":"warning",r?`Unknown event modifier .${r}: use .stop, .capture or .outside`:`.${n[0]} does nothing on a component's event`,t.loc.offset,t.loc.length)}compLike(t,e,n,r){let s={},i=[],o=[],a=[];for(let p of t.attrs){if(p.k!=="event"&&this.quotedEvent(t.tag,p))continue;switch(p.k){case"literal":case"bool":case"expr":case"interp":if(p.name==="@format"&&p.k!=="bool"){let{ref:l,e:u}=this.formatBind(e,p);s[p.name]={lit:{ref:l,e:u}};break}s[p.name]=this.compInput(p);break;case"event":this.modifiers(p,r==="comp"),o.push({name:p.name,e:this.synth(p.source)});break;case"spread":i.push(this.expr(p.source,p.loc));break;case"args":a=[...a,...p.names];break;case"fn":s[p.name]={e:this.expr(p.source,p.loc)};break}}let c=t.children.length?{args:a,block:this.block(t.children,[...n,...a])}:void 0;return r==="comp"?{t:"comp",p:e,name:t.tag,inputs:s,spreads:i,events:o,contents:c}:{t:"dynamic",p:e,tag:this.expr(t.dynamicTag.expr,t.dynamicTag.loc),inputs:s,spreads:i,events:o,contents:c}}}function xs(t,e,n){let r=new Map;if(!t?.trim())return r;let s=Ot(t);e.push(...s.diagnostics),n?.(s.root.children,e,t);for(let i of s.root.children){if(i.t!=="element")continue;if(i.tag!=="macro"){e.push({code:"LIPS-C010",severity:"warning",message:`Only <macro> definitions are allowed in the macros source — ignoring <${i.tag}>`,loc:{line:1,col:1,offset:i.loc.offset,length:i.loc.length}});continue}let o="",a=[];for(let c of i.attrs)if(c.k==="args")a.push(...c.names);else if(c.k==="literal"&&c.name==="name")o=c.value;if(!o){e.push({code:"LIPS-C011",severity:"error",message:"<macro> requires a name attribute",loc:{line:1,col:1,offset:i.loc.offset,length:i.loc.length}});continue}r.set(o.toLowerCase(),{name:o,argv:a,children:i.children})}return r}function se(t,e){let n=[],r=xs(e?.macros||"",n,e?.check),s=Ot(t);e?.check?.(s.root.children,n,t),e?.transform?.(s.root.children,n);let i=new or(t,r,e?.target==="tree");return{ir:i.compile(s.root.children),diagnostics:[...n,...s.diagnostics,...i.diagnostics]}}function vs(t){try{return decodeURIComponent(t)}catch(e){return t}}var Ss=(t)=>Object.fromEntries(new URLSearchParams(t)),ar={state:{page:null,params:{},query:{}},handler:{onCreate(){this.__routes=[],this.__defaultPath=null,this.__currentRoute=null,this.__global=!1},onInput(){this.processor(this.input)},processor(t){if(!t?.routes)return;if(t.global)this.__global=!0;if(this.__routes=t.routes.map(({path:e,template:n,default:r})=>{if(r)this.__defaultPath=e;let s=e.match(/:[^\/]*(\/|$)/gi)||[],i=e.replaceAll("/","\\/").replaceAll(/:[^\/]*(\/|$)/gi,"([^\\/]+)(?:\\/|$)");return{path:e,template:n,default:r,pathVars:s,pathRegex:new RegExp(`${i}$`,"i")}}),t.global){let e=window.location.pathname;this.__defaultPath=this.__defaultPath&&e==="/"&&e!==this.__defaultPath?this.__defaultPath:e?e+window.location.search:this.__routes[0]?.path}},onAttach(){if(this.input?.global)window.navigate=this.__navigate=this.navigate.bind(this),this.__popstate=(t)=>t.state&&this.navigate(t.state.path,!0),window.addEventListener("popstate",this.__popstate);typeof this.setContext==="function"&&this.setContext("navigate",this.navigate.bind(this)),this.__initial=!0,this.__defaultPath&&this.navigate(this.__defaultPath),this.__initial=!1},onDestroy(){this.__popstate&&window.removeEventListener("popstate",this.__popstate),this.__navigate&&window.navigate===this.__navigate&&delete window.navigate},navigate(t,e){!e&&this.__global&&history[this.__initial?"replaceState":"pushState"]({path:t},"",t);let n=String(t).split("?");t=n[0];let r=n[1]?Ss(n[1]):{},s=null;if(this.__currentRoute)s={path:this.__currentRoute.path,params:this.state.params},this.emit("before",{fromState:s,toState:{path:t,query:r}});let i=this.match(t);if(!i){this.__currentRoute=null,this.state.params={},this.state.query={},this.state.page=null,this.emit("not-found",t);return}let{route:o,params:a}=i;this.emit("after",{fromState:s,toState:{path:o.path,params:a,query:r}}),this.__currentRoute=o,this.state.params=a,this.state.query=r,this.state.page=o.template},match(t){let e={};for(let n of this.__routes){let r=t.match(n.pathRegex);if(r===null||r.index!==0)continue;for(let s=0;s+1<r.length&&s<n.pathVars.length;s++)e[n.pathVars[s].replaceAll(/[\/:]/g,"")]=vs(r[s+1]);return{route:n,params:e}}return!1}},default:"<{state.page} params=state.params query=state.query/>"};function ks(t){return t?t:(e)=>e}hn(se);dn(re);mn(qn);vn(kn);bn("router",ar);var Na=xe;export{ue as batch,re as compileStyle,se as compileTemplate,ks as component,Na as default,nt as effect,rr as parseSFC,Ot as parseTemplate,Z as reactive,Dt as renderIR,A as signal,D as untrack};
13
13
 
14
- //# debugId=B396D5F1D77B979464756E2164756E21
14
+ //# debugId=A586C899E541D75464756E2164756E21