@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
@@ -1,5 +1,5 @@
1
- var G=["===","!==","...","=>","==","!=","<=",">=","&&","||","??","?.","++","--","+=","-=","*=","/=","%=","+","-","*","/","%","<",">","!","?",":",".",",","(",")","[","]","{","}","="];function z(t,e){let r=[],s=0,f=(g)=>/[A-Za-z_$]/.test(g),m=(g)=>/[A-Za-z0-9_$]/.test(g);while(s<t.length){let g=t[s];if(/\s/.test(g)){s++;continue}if(/[0-9]/.test(g)||g==="."&&/[0-9]/.test(t[s+1])){let p=s;while(s<t.length&&/[0-9]/.test(t[s]))s++;if(t[s]==="."){s++;while(s<t.length&&/[0-9]/.test(t[s]))s++}if(t[s]==="e"||t[s]==="E"){if(s++,t[s]==="+"||t[s]==="-")s++;while(s<t.length&&/[0-9]/.test(t[s]))s++}r.push({t:"num",value:t.slice(p,s),start:p,end:s});continue}if(g==="'"||g==='"'){let p=s;s++;let l="",o=!1;while(s<t.length){let n=t[s];if(n==="\\"){let a=t[s+1],c={n:`
2
- `,t:"\t",r:"\r",b:"\b",f:"\f",v:"\v","0":"\x00"};if(a==="u"){let h=t.slice(s+2,s+6);l+=String.fromCharCode(parseInt(h,16)||0),s+=6}else l+=c[a]??a,s+=2;continue}if(n===g){o=!0,s++;break}l+=n,s++}if(!o)e.push({code:"LIPS-E001",message:"Unterminated string literal",loc:{offset:p,length:s-p}});r.push({t:"str",value:l,start:p,end:s});continue}if(f(g)){let p=s;while(s<t.length&&m(t[s]))s++;r.push({t:"id",value:t.slice(p,s),start:p,end:s});continue}let d=G.find((p)=>t.startsWith(p,s));if(d==="?."&&/[0-9]/.test(t[s+2]??""))d="?";if(d){r.push({t:"punct",value:d,start:s,end:s+d.length}),s+=d.length;continue}e.push({code:"LIPS-E002",message:`Unexpected character '${g}'`,loc:{offset:s,length:1}}),s++}return r.push({t:"eof",value:"",start:t.length,end:t.length}),r}class C{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,r=this.peek()){return this.diagnostics.push({code:t,message:e,loc:{offset:r.start,length:Math.max(1,r.end-r.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,r=0;while(!0){let s=this.peek(r);if(s.t==="eof")return!1;if(s.t==="punct"&&s.value==="(")e++;if(s.t==="punct"&&s.value===")"){if(e--,e===0){let f=this.peek(r+1);return f.t==="punct"&&f.value==="=>"}}r++}}return!1}assign(){if(this.isArrowAhead()){let r=[];if(this.peek().t==="id")r.push(this.next().value);else{this.expect("(","LIPS-E004");while(!this.at(")")&&this.peek().t!=="eof"){let s=this.next();if(s.t!=="id")return this.error("LIPS-E005","Invalid arrow parameter",s);if(r.push(s.value),!this.eat(","))break}this.expect(")","LIPS-E004")}return this.expect("=>","LIPS-E004"),{t:"arrow",params:r,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,r=this.assign();this.expect("]","LIPS-E009"),t={t:"member",obj:t,prop:r,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,r=this.assign();this.expect("]","LIPS-E009"),t={t:"member",obj:t,prop:r,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 r=this.eat("...");if(e.push({spread:r||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 r=this.next();if(r.t!=="id"&&r.t!=="str"&&r.t!=="num")return this.error("LIPS-E011","Invalid object key",r);if(this.eat(":"))e.push({key:String(r.value),value:this.assign(),at:r.start});else if(r.t==="id")e.push({key:r.value,value:{t:"id",name:r.value,at:r.start},at:r.start});else return this.error("LIPS-E011","Invalid shorthand property",r)}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 S(t){let e=[],r=z(t,e);return{ast:new C(r,e).parse(),diagnostics:e}}function A(t){let e=[],r=0,s=0;for(let f=0;f<t.length;f++){let m=t[f];if(m==="'"||m==='"'||m==="`"){f++;while(f<t.length&&t[f]!==m){if(t[f]==="\\")f++;f++}continue}if(m==="("||m==="["||m==="{")r++;else if(m===")"||m==="]"||m==="}")r--;else if(m===","&&r===0)e.push(t.slice(s,f)),s=f+1}return e.push(t.slice(s)),e.map((f)=>f.trim()).filter(Boolean)}var j=new Set(["if","else-if","else","for","switch","async","let","const","log","context","i18n"]),O=new Set(["case","default","then","catch","loading"]),L=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"]);var _=new WeakMap,M={clone(t){let e=_.get(t);if(!e)e=document.createElement("template"),e.innerHTML=t.html,_.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 r=[];for(let s=t;s;s=s.nextSibling)if(r.push(s),s===e)break;return r},insert:(t,e,r)=>{t.insertBefore(e,r)},insertAfter(t,e){let r=t.parentNode;if(!r)return;let s=t;for(let f of e)r.insertBefore(f,s.nextSibling),s=f},remove:(t)=>t.remove(),isElement:(t)=>t.nodeType===1,connected:(t)=>t.isConnected,precedes:(t,e)=>!!(t.compareDocumentPosition(e)&4),attr:(t,e,r)=>r===null?t.removeAttribute(e):t.setAttribute(e,r),setText:(t,e)=>{t.data=e},content:(t,e)=>{t.textContent=e},html:(t,e)=>{t.innerHTML=e},styleVar:(t,e,r)=>r===null?t.style.removeProperty(e):t.style.setProperty(e,r),scope:(t,e)=>{t.hasAttribute("rel")||t.setAttribute("rel",e)},listen(t,e,r){return t.addEventListener(e,r),()=>t.removeEventListener(e,r)},keepFocus(){let t=document.activeElement;return()=>{t&&t.isConnected&&t!==document.activeElement&&t.focus()}}};var J=Symbol.for("lips.self"),H=(t,e,r)=>{let s=t.slice(0,e).split(`
3
- `);return{line:s.length,col:s[s.length-1].length+1,offset:e,length:r}},k=(t,e,r)=>({code:t,message:e,hint:r}),w=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),U=new Set(["constructor","__proto__","prototype","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__","caller","callee"]),K=new Set(["script","iframe","frame","frameset","object","embed","applet","portal","fencedframe","base","link","meta","style","title","head","body","html","template","noscript","noembed","noframes","xmp","plaintext","animate","animatemotion","animatetransform","set"]),X=new Set(["href","src","action","formaction","xlink:href","poster","cite","background","longdesc","manifest","data","codebase","lowsrc","dynsrc","icon"]),Z=new Set(["http","https","mailto","tel"]),B={srcdoc:"It is a whole document, written into an attribute",is:"It makes the element one the page defined, running the page's code",form:"It joins a form of the host page by id"},W=new WeakSet,I=(t)=>(W.add(t),Object.freeze(t)),E=(t,e)=>Object.fromEntries(e.map((r)=>[r,t[r]])),P=(t,e={})=>I(Object.assign((...r)=>t(...r),e)),Y={Math:I(E(Math,Object.getOwnPropertyNames(Math))),JSON:I(E(JSON,["parse","stringify"])),Object:I(E(Object,["keys","values","entries","fromEntries"])),Array:I(E(Array,["isArray","from","of"])),String:P(String,E(String,["fromCharCode","fromCodePoint"])),Number:P(Number,E(Number,["isFinite","isInteger","isNaN","isSafeInteger","parseFloat","parseInt","EPSILON","MAX_SAFE_INTEGER","MIN_SAFE_INTEGER"])),Boolean:P(Boolean),Date:P(Date,E(Date,["now","parse","UTC"])),parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,encodeURI,decodeURI};function Q(t){let e="",r=0;while(r<t.length){let s=t[r];if(s==='"'||s==="'"){let f=r+1;while(f<t.length&&t[f]!==s)f+=t[f]==="\\"?2:1;e+=t.slice(r,f+1),r=f+1;continue}if(s==="/"&&t[r+1]==="*"){let f=t.indexOf("*/",r+2);r=f<0?t.length:f+2;continue}e+=s,r++}return e.replace(/\\(?:([\da-f]{1,6})[ \t\n\r\f]?|([^\n\r\f\da-f])|[\n\r\f])/gi,(s,f,m)=>f?String.fromCodePoint(Math.min(parseInt(f,16),1114111)||65533):m??"")}var tt=(t)=>t===globalThis||t===globalThis.eval||typeof t==="function"&&/^(Async|AsyncGenerator|Generator)?Function$/.test(t.name)&&t.prototype?.constructor===t||typeof Node==="function"&&t instanceof Node||typeof Event==="function"&&t instanceof Event||typeof EventTarget==="function"&&t instanceof EventTarget||typeof t==="object"&&(("nodeType"in t)&&("ownerDocument"in t)||t.window===t),T={globals:Y,member(t,e,r){if(U.has(t))return k("LIPS-U002",`'${t}' leads to prototypes and constructors, not data`,"An untrusted template reads and writes data; prototype machinery is not reachable");if(r!=null&&W.has(r)&&(e||!w(r,t)))return k("LIPS-U003",e?`Globals are read-only — '${t}' cannot be written`:`'${t}' is not offered`,"Offered: Math, JSON, Object.keys/values/entries/fromEntries, Array.isArray/from/of, String, Number, Boolean, Date, parseInt, parseFloat, isNaN, isFinite and the URI codecs")},self(t,e){if(e)return k("LIPS-U005",`self is read-only — '${t}' cannot be written`,"Write state instead: state.x = …");if(U.has(t))return this.member(t,!1);if(t==="node")return k("LIPS-U005","self.node holds the component's DOM nodes","An untrusted template reaches the page only through the template language")},value(t){if(t!==null&&(typeof t==="object"||typeof t==="function")&&tt(t))return k("LIPS-U004","A DOM node, window, event or code constructor cannot be held by an untrusted template","Hand the template data, not the platform object it came from")},event(t){let e=(r)=>r&&{value:r.value,checked:r.checked,name:r.name,id:r.id,type:r.type,tagName:r.tagName,dataset:{...r.dataset}};return{type:t.type,key:t.key,code:t.code,data:t.data,inputType:t.inputType,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey,repeat:t.repeat,button:t.button,buttons:t.buttons,clientX:t.clientX,clientY:t.clientY,deltaX:t.deltaX,deltaY:t.deltaY,target:e(t.target),currentTarget:e(t.currentTarget),preventDefault:()=>t.preventDefault(),stopPropagation:()=>t.stopPropagation()}},tag(t){let e=t.toLowerCase();if(K.has(e))return k("LIPS-U010",`<${e}> is refused in an untrusted template`,"It runs script, holds a document of its own, or acts on the whole page");if(e.includes("-"))return k("LIPS-U011",`<${e}> is a custom element`,"Custom elements run the page's own code — a Lips component the host registered renders instead")},component(t){if(t==="router")return k("LIPS-U012","<router> owns the page URL and window.navigate","Switch on state for pages — <switch( state.page )>; routing stays with the host")},attr(t,e,r){let s=e.toLowerCase();if(s.startsWith("on"))return k("LIPS-U020",`'${e}' is an event-handler attribute`,"Use the instruction form: on-click( … )");if(w(B,s))return k("LIPS-U021",`'${e}' is refused`,B[s]);if(r===void 0)return;if((s==="id"||s==="name")&&typeof document==="object"&&r in document)return k("LIPS-U022",`${s}="${r}" would shadow document.${r}`,"Choose another value");if(s==="style")return this.css(r);if(X.has(s))return this.url(r);if(s==="srcset"||s==="imagesrcset"||s==="ping")for(let f of r.split(s==="ping"?/\s+/:",")){let m=f.trim()?this.url(f.trim().split(/\s+/)[0]):void 0;if(m)return m}},url(t){let e=String(t).replace(/[\t\n\r]/g,"").replace(/^[\u0000- ]+/,""),r=/^([a-z][a-z\d+.-]*):/i.exec(e)?.[1].toLowerCase();if(!r||Z.has(r)||/^data:image\/(png|gif|jpe?g|webp|avif|bmp)[;,]/i.test(e))return;return k("LIPS-U030",`'${r}:' URLs are refused`,"Use a relative, http(s), mailto: or tel: URL — or a raster data:image")},css(t){let e=Q(t);if(/@import\b/i.test(e))return k("LIPS-U040","@import loads a stylesheet outside the component scope","Write the rules into the stylesheet itself");if(/(?:^|[^\w-])(?:-webkit-|-moz-)?(?:image-set|image|cross-fade|element)\(/i.test(e))return k("LIPS-U041","image-set(), image(), cross-fade() and element() load without url()","Use url( … ), which is held to the URL rule");for(let r of e.matchAll(/\b(?:url|src)\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))/gi)){let s=this.url((r[1]??r[2]??r[3]).trim());if(s)return s}},report(t){console.warn("[lips:untrusted]",t)}},et=new Set(["state","input","context","static","self","arguments"]),rt=new Set([...j,...O,"macro"]),R=new Set;function V(t,e,r,s,f=!1){let{ast:m,diagnostics:g}=S(e);if(g.length)return!0;let d=!0,p=(n,a=0,c=1)=>{if(n)d=!1,s(n,a,c)},l=(n,a)=>a.has(n)||r.has(n)||et.has(n)||w(t.globals,n);if(f&&m.t==="id"&&!l(m.name,R))return p(t.self(m.name),m.at,m.name.length),d;let o=(n,a,c=!1)=>{switch(n.t){case"id":l(n.name,a)||p(k("LIPS-U001",`'${n.name}' is not provided to an untrusted template`,"Expressions read state, input, context, static, self, their scope, and the globals the policy offers"),n.at,n.name.length);return;case"member":{o(n.obj,a),n.computed&&o(n.prop,a);let h=n.prop,i=!n.computed?n.prop:h.t==="lit"&&(typeof h.v==="string"||typeof h.v==="number")?String(h.v):void 0;if(i===void 0)return;let u=n.obj.t==="id"&&!a.has(n.obj.name)&&!r.has(n.obj.name)?n.obj.name:"";p(u==="self"?t.self(i,c):u&&w(t.globals,u)?t.member(i,c,t.globals[u]):t.member(i,c),n.at,i.length);return}case"call":o(n.callee,a),n.args.forEach((h)=>o(h,a));return;case"unary":o(n.arg,a);return;case"update":o(n.arg,a,!0);return;case"bin":case"logic":o(n.l,a),o(n.r,a);return;case"cond":o(n.test,a),o(n.cons,a),o(n.alt,a);return;case"assign":o(n.target,a,!0),o(n.value,a);return;case"arrow":o(n.body,new Set([...a,...n.params]));return;case"arr":n.items.forEach((h)=>o(h.value,a));return;case"obj":for(let h of n.props)h.key!==void 0&&p(t.member(h.key,!0),h.at,h.key.length),o(h.value,a)}};return o(m,R),d}function q(t=T){return(e,r,s)=>{let f=new Set,m=(i,u,b=1)=>r.push({...i,severity:"error",loc:H(s,u,b)}),g=(i,u)=>{let b=s.indexOf(i,u);return b<0?u:b},d=(i,u,b=!1)=>V(t,i,f,(x,y,v)=>m(x,u+y,v),b),p=(i,u,b=!0)=>{let x=!0,y=0;return A(i).forEach((v,N)=>{y=i.indexOf(v,y),x=d(v,u+y,b&&N===0)&&x,y+=v.length}),x},l=(i)=>{for(let u of i)if(typeof u!=="string"&&!d(u.expr,g(u.expr,u.loc.offset)))u.expr="undefined"},o=(i)=>L.has(i)?t.tag(i):t.component(i),n=(i)=>{for(let u of i){if(u.t==="fragment")n(u.children);if(u.t!=="element")continue;for(let b of u.attrs)b.k==="args"?b.names.forEach((x)=>f.add(x)):(u.tag==="let"||u.tag==="const")&&("name"in b)&&f.add(b.name);n(u.children)}},a=(i,u)=>{let b=i.loc.offset;switch(i.k){case"args":return!0;case"event":return p(i.source,g(i.source,b));case"spread":case"fn":return d(i.source,g(i.source,b))}if(u&&!/^(@(?!html$)|i18n(-|$))/.test(i.name)){let x=t.attr(u,i.name,i.k==="literal"?i.value:i.k==="bool"?"":void 0);if(x)return m(x,b,i.name.length),!1}if(i.name==="@format"){let x=i.k==="literal"?i.value:i.k==="expr"?i.source:i.k==="interp"?i.parts.map((v)=>typeof v==="string"?v:`{${v.expr}}`).join(""):"",y=x.slice(x.indexOf(",")+1).trim();return!x.includes(",")||d(y,g(y,b))}if(i.k==="expr"&&!d(i.source,g(i.source,b)))i.source="undefined";if(i.k==="interp")l(i.parts);return!0},c=(i)=>{let{tag:u}=i;if(u==="#dynamic"){let x=i.dynamicTag,y=g(x.expr,x.loc.offset);if(!d(x.expr,y))x.expr="undefined";else{let{ast:v}=S(x.expr),N=v.t==="lit"&&typeof v.v==="string"?o(v.v.toLowerCase()):void 0;if(N)return m(N,y,x.expr.length),!1}}else if(!rt.has(u)){let x=o(u);if(x)return m(x,i.loc.offset,u.length+1),!1}if(i.head){let x=i.head,y=g(x.expr,x.loc.offset);(u==="log"?p(x.expr,y,!1):d(x.expr,y))||(x.expr="undefined")}let b=L.has(u)?u:null;return i.attrs=i.attrs.filter((x)=>a(x,b)),!0},h=(i)=>{for(let u=0;u<i.length;u++){let b=i[u];if(b.t==="fragment")h(b.children);else if(b.t==="interp")l(b.parts);else if(b.t==="element")c(b)?h(b.children):i.splice(u--,1)}};n(e),h(e)}}var D=(t)=>Object.assign(Error(t.message),{name:"PolicyError"},t),F={"+":(t,e)=>t+e,"-":(t,e)=>t-e,"*":(t,e)=>t*e,"/":(t,e)=>t/e,"%":(t,e)=>t%e,"<":(t,e)=>t<e,">":(t,e)=>t>e,"<=":(t,e)=>t<=e,">=":(t,e)=>t>=e,"==":(t,e)=>t==e,"!=":(t,e)=>t!=e,"===":(t,e)=>t===e,"!==":(t,e)=>t!==e};function st(t){let e=(m)=>{if(m)throw D(m)},r=(m)=>(e(t.value(m)),m),s=(m)=>{if(typeof m==="string")return m;if(typeof m==="number")return String(m);throw D(k("LIPS-U002","A computed member must be a string or a number"))},f=(m,g,d)=>e(m!=null&&typeof m==="object"&&m[J]?t.self(g,d):t.member(g,d,m));return(m,g)=>{let d=g.scope,p=(n,a)=>{for(let c of a)if(n in c)return c[n];if(d&&n in d)return r(d[n]);switch(n){case"state":return g.state;case"input":return g.input;case"context":return g.context;case"static":return g.static;case"self":return g.self;case"arguments":return g.arguments}return w(t.globals,n)?t.globals[n]:void 0},l=(n,a,c)=>{if(n.t==="id"){let h=c.find((i)=>(n.name in i))??d;h&&(h[n.name]=a)}else if(n.t==="member"){let h=o(n.obj,c),i=s(n.computed?o(n.prop,c):n.prop);if(f(h,i,!0),h!=null)h[i]=a}return a},o=(n,a)=>{switch(n.t){case"lit":return n.v;case"id":return p(n.name,a);case"member":{let c=o(n.obj,a);if(n.optional&&c==null)return;let h=s(n.computed?o(n.prop,a):n.prop);return f(c,h,!1),c==null?void 0:r(c[h])}case"call":{let c=n.callee,h,i;if(c.t==="member"){if(h=o(c.obj,a),(c.optional||n.optional)&&h==null)return;let u=s(c.computed?o(c.prop,a):c.prop);f(h,u,!1),i=h==null?void 0:r(h[u])}else i=o(c,a);if(n.optional&&i==null)return;return r(Reflect.apply(i,h,n.args.map((u)=>o(u,a))))}case"unary":{let c=o(n.arg,a);return n.op==="!"?!c:n.op==="-"?-c:+c}case"update":{let c=o(n.arg,a),h=n.op==="++"?c+1:c-1;return l(n.arg,h,a),n.prefix?h:c}case"bin":return F[n.op](o(n.l,a),o(n.r,a));case"logic":{let c=o(n.l,a);return n.op==="&&"?c&&o(n.r,a):n.op==="||"?c||o(n.r,a):c??o(n.r,a)}case"cond":return o(n.test,a)?o(n.cons,a):o(n.alt,a);case"assign":return l(n.target,n.op==="="?o(n.value,a):F[n.op[0]](o(n.target,a),o(n.value,a)),a);case"arrow":return(...c)=>{let h=Object.create(null);return n.params.forEach((i,u)=>h[i]=r(c[u])),o(n.body,[h,...a])};case"arr":{let c=[];for(let h of n.items)h.spread?c.push(...o(h.value,a)):c.push(o(h.value,a));return c}case"obj":{let c={},h=(i,u)=>{f(c,i,!0),c[i]=u};for(let i of n.props){let u=o(i.value,a);if(!i.spread)h(i.key,u);else if(u!=null)for(let b of Object.keys(u))h(b,r(u[b]))}return c}}};return o(m,[])}}function nt(t,e=M){let r=new WeakMap,s=(p)=>(p&&t.report(p),!!p),f=(p)=>p.localName.toLowerCase(),m=(p,l)=>{let o=p.createElement("template");return o.setAttribute("data-lips-refused",l),o},g=(p)=>{for(let l of[...p.querySelectorAll("*")]){let o=f(l);if(s(t.tag(o))){let a=m(l.ownerDocument,o);a.append(...l.childNodes),l.replaceWith(a);continue}let n=!1;for(let{name:a,value:c}of[...l.attributes])if(s(t.attr(o,a,c)))l.removeAttribute(a),n||=a.toLowerCase()==="is";if(n){let a=l.ownerDocument.createElementNS(l.namespaceURI,l.localName);for(let c of[...l.attributes])a.setAttribute(c.name,c.value);a.append(...l.childNodes),l.replaceWith(a)}}},d=(p)=>{let l=document.createElement("template");return l.innerHTML=p,g(l.content),l};return{...e,clone(p){let l=r.get(p);if(!l)r.set(p,l=d(p.html));return l.content.cloneNode(!0)},element:(p)=>s(t.tag(p.toLowerCase()))?m(document,p):e.element(p),attr(p,l,o){e.attr(p,l,o!==null&&s(t.attr(f(p),l,o))?null:o)},html(p,l){s(t.attr(f(p),"@html",l))?e.content(p,""):p.replaceChildren(d(l).content)},styleVar(p,l,o){e.styleVar(p,l,o!==null&&s(t.css(o))?null:o)},listen:(p,l,o)=>e.listen(p,l,(n)=>o(t.event(n)))}}var it={ir:{v:1,exprs:[],root:{html:"",scope:[],binds:[],blocks:[]}}};function ot(t=T){let e=st(t),r=new Map,s=nt(t),f=new Set,m={run(g){let d=r.get(g);if(!d)r.set(g,d=S(g).ast);return(p)=>e(d,p)},self:(g)=>t.self(g)};return{check:q(t),style:(g)=>(d,p)=>{let l=g(d,{...p,lint(c,h){let i=h!==void 0?t.css(h):c[0]==="@"?t.css(c):void 0;return i&&[{...i,severity:"error"}]}}),o=(c,h,i)=>l.diagnostics.push({...c,severity:"error",loc:H(d,Math.max(h,0),i)}),n=!l.diagnostics.some((c)=>c.code.startsWith("LIPS-U"));for(let c of l.ir.exprs){let h=d.indexOf(c);n=V(t,c,R,(i,u,b)=>o(i,h+u,b))&&n}let a=n?t.css(l.ir.css):void 0;if(a&&o(a,0,0),!n||a)return{...l,ir:{...l.ir,css:"",binds:[],props:void 0}};return f.add(l.ir.css),l},runtime(g){let{components:d,createStylesheet:p}=g;return{...g,guard:m,host:s,components:d&&new Proxy(d,{get:(l,o)=>at(t,o)?it:l[o]}),createStylesheet:p&&((l,o)=>{if(f.has(o))return p(l,o);return t.report(k("LIPS-U042",`A stylesheet Lips did not compile cannot be checked — <${l}> ships unstyled`,"Send the stylesheet source; precompiled sheets are trusted output")),{clear(){}}})}}}}var at=(t,e)=>{let r=typeof e==="string"?t.component(e):void 0;return r&&t.report(r),!!r};export{q as checkTemplate,ot as untrusted,T as untrustedPolicy};
1
+ var z=["===","!==","...","=>","==","!=","<=",">=","&&","||","??","?.","++","--","+=","-=","*=","/=","%=","+","-","*","/","%","<",">","!","?",":",".",",","(",")","[","]","{","}","="];function q(t,e){let r=[],n=0,p=(g)=>/[A-Za-z_$]/.test(g),h=(g)=>/[A-Za-z0-9_$]/.test(g);while(n<t.length){let g=t[n];if(/\s/.test(g)){n++;continue}if(/[0-9]/.test(g)||g==="."&&/[0-9]/.test(t[n+1])){let l=n;while(n<t.length&&/[0-9]/.test(t[n]))n++;if(t[n]==="."){n++;while(n<t.length&&/[0-9]/.test(t[n]))n++}if(t[n]==="e"||t[n]==="E"){if(n++,t[n]==="+"||t[n]==="-")n++;while(n<t.length&&/[0-9]/.test(t[n]))n++}r.push({t:"num",value:t.slice(l,n),start:l,end:n});continue}if(g==="'"||g==='"'){let l=n;n++;let u="",a=!1;while(n<t.length){let s=t[n];if(s==="\\"){let o=t[n+1],c={n:`
2
+ `,t:"\t",r:"\r",b:"\b",f:"\f",v:"\v","0":"\x00"};if(o==="u"){let m=t.slice(n+2,n+6);u+=String.fromCharCode(parseInt(m,16)||0),n+=6}else u+=c[o]??o,n+=2;continue}if(s===g){a=!0,n++;break}u+=s,n++}if(!a)e.push({code:"LIPS-E001",message:"Unterminated string literal",loc:{offset:l,length:n-l}});r.push({t:"str",value:u,start:l,end:n});continue}if(p(g)){let l=n;while(n<t.length&&h(t[n]))n++;r.push({t:"id",value:t.slice(l,n),start:l,end:n});continue}let d=z.find((l)=>t.startsWith(l,n));if(d==="?."&&/[0-9]/.test(t[n+2]??""))d="?";if(d){r.push({t:"punct",value:d,start:n,end:n+d.length}),n+=d.length;continue}e.push({code:"LIPS-E002",message:`Unexpected character '${g}'`,loc:{offset:n,length:1}}),n++}return r.push({t:"eof",value:"",start:t.length,end:t.length}),r}class R{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,r=this.peek()){return this.diagnostics.push({code:t,message:e,loc:{offset:r.start,length:Math.max(1,r.end-r.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,r=0;while(!0){let n=this.peek(r);if(n.t==="eof")return!1;if(n.t==="punct"&&n.value==="(")e++;if(n.t==="punct"&&n.value===")"){if(e--,e===0){let p=this.peek(r+1);return p.t==="punct"&&p.value==="=>"}}r++}}return!1}assign(){if(this.isArrowAhead()){let r=[];if(this.peek().t==="id")r.push(this.next().value);else{this.expect("(","LIPS-E004");while(!this.at(")")&&this.peek().t!=="eof"){let n=this.next();if(n.t!=="id")return this.error("LIPS-E005","Invalid arrow parameter",n);if(r.push(n.value),!this.eat(","))break}this.expect(")","LIPS-E004")}return this.expect("=>","LIPS-E004"),{t:"arrow",params:r,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,r=this.assign();this.expect("]","LIPS-E009"),t={t:"member",obj:t,prop:r,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,r=this.assign();this.expect("]","LIPS-E009"),t={t:"member",obj:t,prop:r,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 r=this.eat("...");if(e.push({spread:r||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 r=this.next();if(r.t!=="id"&&r.t!=="str"&&r.t!=="num")return this.error("LIPS-E011","Invalid object key",r);if(this.eat(":"))e.push({key:String(r.value),value:this.assign(),at:r.start});else if(r.t==="id")e.push({key:r.value,value:{t:"id",name:r.value,at:r.start},at:r.start});else return this.error("LIPS-E011","Invalid shorthand property",r)}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 I(t){let e=[],r=q(t,e);return{ast:new R(r,e).parse(),diagnostics:e}}function _(t){let e=[],r=0,n=0;for(let p=0;p<t.length;p++){let h=t[p];if(h==="'"||h==='"'||h==="`"){p++;while(p<t.length&&t[p]!==h){if(t[p]==="\\")p++;p++}continue}if(h==="("||h==="["||h==="{")r++;else if(h===")"||h==="]"||h==="}")r--;else if(h===","&&r===0)e.push(t.slice(n,p)),n=p+1}return e.push(t.slice(n)),e.map((p)=>p.trim()).filter(Boolean)}var lt=Symbol("lips.ended");var O=new Set(["if","else-if","else","for","switch","async","let","const","log","context","i18n"]),A=new Set(["case","default","then","catch","loading"]),T=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"]);var C=new WeakMap,U=(t)=>t!==null,J={__proto__:null,value:(t)=>t??"",checked:U,selected:U},M={clone(t){let e=C.get(t);if(!e)e=document.createElement("template"),e.innerHTML=t.html,C.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 r=[];for(let n=t;n;n=n.nextSibling)if(r.push(n),n===e)break;return r},insert:(t,e,r)=>{t.insertBefore(e,r)},insertAfter(t,e){let r=t.parentNode;if(!r)return;let n=t;for(let p of e)r.insertBefore(p,n.nextSibling),n=p},remove:(t)=>t.remove(),isElement:(t)=>t.nodeType===1,connected:(t)=>t.isConnected,precedes:(t,e)=>!!(t.compareDocumentPosition(e)&4),attr(t,e,r){r===null?t.removeAttribute(e):t.setAttribute(e,r);let n=J[e];n&&e in t&&(t[e]=n(r))},setText:(t,e)=>{t.data=e},content:(t,e)=>{t.textContent=e},html:(t,e)=>{t.innerHTML=e},styleVar:(t,e,r)=>r===null?t.style.removeProperty(e):t.style.setProperty(e,r),scope:(t,e)=>{t.hasAttribute("rel")||t.setAttribute("rel",e)},listen(t,e,r){let n=e.split(".")[0],p=e.includes(".outside"),h=p?document:t,g=p||e.includes(".capture"),d=!p&&e.includes(".stop"),l=(u)=>p&&t.contains(u.target)||(d&&u.stopPropagation(),r(u));return h.addEventListener(n,l,g),()=>h.removeEventListener(n,l,g)},keepFocus(){let t=document.activeElement;return()=>{t&&t.isConnected&&t!==document.activeElement&&t.focus()}}};var X=Symbol.for("lips.self"),G=(t,e,r)=>{let n=t.slice(0,e).split(`
3
+ `);return{line:n.length,col:n[n.length-1].length+1,offset:e,length:r}},y=(t,e,r)=>({code:t,message:e,hint:r}),w=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),F=new Set(["constructor","__proto__","prototype","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__","caller","callee"]),Y=new Set(["script","iframe","frame","frameset","object","embed","applet","portal","fencedframe","base","link","meta","style","title","head","body","html","template","noscript","noembed","noframes","xmp","plaintext","animate","animatemotion","animatetransform","set"]),Z=new Set(["href","src","action","formaction","xlink:href","poster","cite","background","longdesc","manifest","data","codebase","lowsrc","dynsrc","icon"]),Q=new Set(["http","https","mailto","tel"]),D={srcdoc:"It is a whole document, written into an attribute",is:"It makes the element one the page defined, running the page's code",form:"It joins a form of the host page by id"},B=new WeakSet,k=(t)=>(B.add(t),Object.freeze(t)),S=(t,e)=>Object.fromEntries(e.map((r)=>[r,t[r]])),L=(t,e={})=>k(Object.assign((...r)=>t(...r),e)),tt={Math:k(S(Math,Object.getOwnPropertyNames(Math))),JSON:k(S(JSON,["parse","stringify"])),Object:k(S(Object,["keys","values","entries","fromEntries"])),Array:k(S(Array,["isArray","from","of"])),String:L(String,S(String,["fromCharCode","fromCodePoint"])),Number:L(Number,S(Number,["isFinite","isInteger","isNaN","isSafeInteger","parseFloat","parseInt","EPSILON","MAX_SAFE_INTEGER","MIN_SAFE_INTEGER"])),Boolean:L(Boolean),Date:L(Date,S(Date,["now","parse","UTC"])),parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,encodeURI,decodeURI};function et(t){let e="",r=0;while(r<t.length){let n=t[r];if(n==='"'||n==="'"){let p=r+1;while(p<t.length&&t[p]!==n)p+=t[p]==="\\"?2:1;e+=t.slice(r,p+1),r=p+1;continue}if(n==="/"&&t[r+1]==="*"){let p=t.indexOf("*/",r+2);r=p<0?t.length:p+2;continue}e+=n,r++}return e.replace(/\\(?:([\da-f]{1,6})[ \t\n\r\f]?|([^\n\r\f\da-f])|[\n\r\f])/gi,(n,p,h)=>p?String.fromCodePoint(Math.min(parseInt(p,16),1114111)||65533):h??"")}var rt=(t)=>t===globalThis||t===globalThis.eval||typeof t==="function"&&/^(Async|AsyncGenerator|Generator)?Function$/.test(t.name)&&t.prototype?.constructor===t||typeof Node==="function"&&t instanceof Node||typeof Event==="function"&&t instanceof Event||typeof EventTarget==="function"&&t instanceof EventTarget||typeof t==="object"&&(("nodeType"in t)&&("ownerDocument"in t)||t.window===t),P={globals:tt,member(t,e,r){if(F.has(t))return y("LIPS-U002",`'${t}' leads to prototypes and constructors, not data`,"An untrusted template reads and writes data; prototype machinery is not reachable");if(r!=null&&B.has(r)&&(e||!w(r,t)))return y("LIPS-U003",e?`Globals are read-only — '${t}' cannot be written`:`'${t}' is not offered`,"Offered: Math, JSON, Object.keys/values/entries/fromEntries, Array.isArray/from/of, String, Number, Boolean, Date, parseInt, parseFloat, isNaN, isFinite and the URI codecs")},self(t,e){if(e)return y("LIPS-U005",`self is read-only — '${t}' cannot be written`,"Write state instead: state.x = …");if(F.has(t))return this.member(t,!1);if(t==="node"||t==="refs")return y("LIPS-U005",`self.${t} holds the component's DOM nodes`,"An untrusted template reaches the page only through the template language")},value(t){if(t!==null&&(typeof t==="object"||typeof t==="function")&&rt(t))return y("LIPS-U004","A DOM node, window, event or code constructor cannot be held by an untrusted template","Hand the template data, not the platform object it came from")},event(t){let e=(r)=>r&&{value:r.value,checked:r.checked,name:r.name,id:r.id,type:r.type,tagName:r.tagName,dataset:{...r.dataset}};return{type:t.type,key:t.key,code:t.code,data:t.data,inputType:t.inputType,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey,repeat:t.repeat,button:t.button,buttons:t.buttons,clientX:t.clientX,clientY:t.clientY,deltaX:t.deltaX,deltaY:t.deltaY,target:e(t.target),currentTarget:e(t.currentTarget),preventDefault:()=>t.preventDefault(),stopPropagation:()=>t.stopPropagation()}},tag(t){let e=t.toLowerCase();if(Y.has(e))return y("LIPS-U010",`<${e}> is refused in an untrusted template`,"It runs script, holds a document of its own, or acts on the whole page");if(e.includes("-"))return y("LIPS-U011",`<${e}> is a custom element`,"Custom elements run the page's own code — a Lips component the host registered renders instead")},component(t){if(t==="router")return y("LIPS-U012","<router> owns the page URL and window.navigate","Switch on state for pages — <switch( state.page )>; routing stays with the host")},attr(t,e,r){let n=e.toLowerCase();if(n.startsWith("on"))return y("LIPS-U020",`'${e}' is an event-handler attribute`,"Use the instruction form: on-click( … )");if(w(D,n))return y("LIPS-U021",`'${e}' is refused`,D[n]);if(r===void 0)return;if((n==="id"||n==="name")&&typeof document==="object"&&r in document)return y("LIPS-U022",`${n}="${r}" would shadow document.${r}`,"Choose another value");if(n==="style")return this.css(r);if(Z.has(n))return this.url(r);if(n==="srcset"||n==="imagesrcset"||n==="ping")for(let p of r.split(n==="ping"?/\s+/:",")){let h=p.trim()?this.url(p.trim().split(/\s+/)[0]):void 0;if(h)return h}},url(t){let e=String(t).replace(/[\t\n\r]/g,"").replace(/^[\u0000- ]+/,""),r=/^([a-z][a-z\d+.-]*):/i.exec(e)?.[1].toLowerCase();if(!r||Q.has(r)||/^data:image\/(png|gif|jpe?g|webp|avif|bmp)[;,]/i.test(e))return;return y("LIPS-U030",`'${r}:' URLs are refused`,"Use a relative, http(s), mailto: or tel: URL — or a raster data:image")},css(t){let e=et(t);if(/@import\b/i.test(e))return y("LIPS-U040","@import loads a stylesheet outside the component scope","Write the rules into the stylesheet itself");if(/(?:^|[^\w-])(?:-webkit-|-moz-)?(?:image-set|image|cross-fade|element)\(/i.test(e))return y("LIPS-U041","image-set(), image(), cross-fade() and element() load without url()","Use url( … ), which is held to the URL rule");for(let r of e.matchAll(/\b(?:url|src)\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))/gi)){let n=this.url((r[1]??r[2]??r[3]).trim());if(n)return n}},report(t){console.warn("[lips:untrusted]",t)}},nt=new Set(["state","input","context","static","self","arguments"]),st=new Set([...O,...A,"macro"]),j=new Set;function W(t,e,r,n,p=!1){let{ast:h,diagnostics:g}=I(e);if(g.length)return!0;let d=!0,l=(s,o=0,c=1)=>{if(s)d=!1,n(s,o,c)},u=(s,o)=>o.has(s)||r.has(s)||nt.has(s)||w(t.globals,s);if(p&&h.t==="id"&&!u(h.name,j))return l(t.self(h.name),h.at,h.name.length),d;let a=(s,o,c=!1)=>{switch(s.t){case"id":u(s.name,o)||l(y("LIPS-U001",`'${s.name}' is not provided to an untrusted template`,"Expressions read state, input, context, static, self, their scope, and the globals the policy offers"),s.at,s.name.length);return;case"member":{a(s.obj,o),s.computed&&a(s.prop,o);let m=s.prop,i=!s.computed?s.prop:m.t==="lit"&&(typeof m.v==="string"||typeof m.v==="number")?String(m.v):void 0;if(i===void 0)return;let f=s.obj.t==="id"&&!o.has(s.obj.name)&&!r.has(s.obj.name)?s.obj.name:"";l(f==="self"?t.self(i,c):f&&w(t.globals,f)?t.member(i,c,t.globals[f]):t.member(i,c),s.at,i.length);return}case"call":a(s.callee,o),s.args.forEach((m)=>a(m,o));return;case"unary":a(s.arg,o);return;case"update":a(s.arg,o,!0);return;case"bin":case"logic":a(s.l,o),a(s.r,o);return;case"cond":a(s.test,o),a(s.cons,o),a(s.alt,o);return;case"assign":a(s.target,o,!0),a(s.value,o);return;case"arrow":a(s.body,new Set([...o,...s.params]));return;case"arr":s.items.forEach((m)=>a(m.value,o));return;case"obj":for(let m of s.props)m.key!==void 0&&l(t.member(m.key,!0),m.at,m.key.length),a(m.value,o)}};return a(h,j),d}function K(t=P){return(e,r,n)=>{let p=new Set,h=(i,f,b=1)=>r.push({...i,severity:"error",loc:G(n,f,b)}),g=(i,f)=>{let b=n.indexOf(i,f);return b<0?f:b},d=(i,f,b=!1)=>W(t,i,p,(x,E,v)=>h(x,f+E,v),b),l=(i,f,b=!0)=>{let x=!0,E=0;return _(i).forEach((v,N)=>{E=i.indexOf(v,E),x=d(v,f+E,b&&N===0)&&x,E+=v.length}),x},u=(i)=>{for(let f of i)if(typeof f!=="string"&&!d(f.expr,g(f.expr,f.loc.offset)))f.expr="undefined"},a=(i)=>T.has(i)?t.tag(i):t.component(i),s=(i)=>{for(let f of i){if(f.t==="fragment")s(f.children);if(f.t!=="element")continue;for(let b of f.attrs)b.k==="args"?b.names.forEach((x)=>p.add(x)):(f.tag==="let"||f.tag==="const")&&("name"in b)&&p.add(b.name);s(f.children)}},o=(i,f)=>{let b=i.loc.offset;switch(i.k){case"args":return!0;case"event":return l(i.source,g(i.source,b));case"spread":case"fn":return d(i.source,g(i.source,b))}if(f&&!/^(@(?!html$)|i18n(-|$))/.test(i.name)){let x=t.attr(f,i.name,i.k==="literal"?i.value:i.k==="bool"?"":void 0);if(x)return h(x,b,i.name.length),!1}if(i.name==="@format"){let x=i.k==="literal"?i.value:i.k==="expr"?i.source:i.k==="interp"?i.parts.map((v)=>typeof v==="string"?v:`{${v.expr}}`).join(""):"",E=x.slice(x.indexOf(",")+1).trim();return!x.includes(",")||d(E,g(E,b))}if(i.k==="expr"&&!d(i.source,g(i.source,b)))i.source="undefined";if(i.k==="interp")u(i.parts);return!0},c=(i)=>{let{tag:f}=i;if(f==="#dynamic"){let x=i.dynamicTag,E=g(x.expr,x.loc.offset);if(!d(x.expr,E))x.expr="undefined";else{let{ast:v}=I(x.expr),N=v.t==="lit"&&typeof v.v==="string"?a(v.v.toLowerCase()):void 0;if(N)return h(N,E,x.expr.length),!1}}else if(!st.has(f)){let x=a(f);if(x)return h(x,i.loc.offset,f.length+1),!1}if(i.head){let x=i.head,E=g(x.expr,x.loc.offset);(f==="log"?l(x.expr,E,!1):d(x.expr,E))||(x.expr="undefined")}let b=T.has(f)?f:null;return i.attrs=i.attrs.filter((x)=>o(x,b)),!0},m=(i)=>{for(let f=0;f<i.length;f++){let b=i[f];if(b.t==="fragment")m(b.children);else if(b.t==="interp")u(b.parts);else if(b.t==="element")c(b)?m(b.children):i.splice(f--,1)}};s(e),m(e)}}var H=(t)=>Object.assign(Error(t.message),{name:"PolicyError"},t),V={"+":(t,e)=>t+e,"-":(t,e)=>t-e,"*":(t,e)=>t*e,"/":(t,e)=>t/e,"%":(t,e)=>t%e,"<":(t,e)=>t<e,">":(t,e)=>t>e,"<=":(t,e)=>t<=e,">=":(t,e)=>t>=e,"==":(t,e)=>t==e,"!=":(t,e)=>t!=e,"===":(t,e)=>t===e,"!==":(t,e)=>t!==e};function it(t){let e=(h)=>{if(h)throw H(h)},r=(h)=>(e(t.value(h)),h),n=(h)=>{if(typeof h==="string")return h;if(typeof h==="number")return String(h);throw H(y("LIPS-U002","A computed member must be a string or a number"))},p=(h,g,d)=>e(h!=null&&typeof h==="object"&&h[X]?t.self(g,d):t.member(g,d,h));return(h,g)=>{let d=g.scope,l=(s,o)=>{for(let c of o)if(s in c)return c[s];if(d&&s in d)return r(d[s]);switch(s){case"state":return g.state;case"input":return g.input;case"context":return g.context;case"static":return g.static;case"self":return g.self;case"arguments":return g.arguments}return w(t.globals,s)?t.globals[s]:void 0},u=(s,o,c)=>{if(s.t==="id"){let m=c.find((i)=>(s.name in i))??d;m&&(m[s.name]=o)}else if(s.t==="member"){let m=a(s.obj,c),i=n(s.computed?a(s.prop,c):s.prop);if(p(m,i,!0),m!=null)m[i]=o}return o},a=(s,o)=>{switch(s.t){case"lit":return s.v;case"id":return l(s.name,o);case"member":{let c=a(s.obj,o);if(s.optional&&c==null)return;let m=n(s.computed?a(s.prop,o):s.prop);return p(c,m,!1),c==null?void 0:r(c[m])}case"call":{let c=s.callee,m,i;if(c.t==="member"){if(m=a(c.obj,o),(c.optional||s.optional)&&m==null)return;let f=n(c.computed?a(c.prop,o):c.prop);p(m,f,!1),i=m==null?void 0:r(m[f])}else i=a(c,o);if(s.optional&&i==null)return;return r(Reflect.apply(i,m,s.args.map((f)=>a(f,o))))}case"unary":{let c=a(s.arg,o);return s.op==="!"?!c:s.op==="-"?-c:+c}case"update":{let c=a(s.arg,o),m=s.op==="++"?c+1:c-1;return u(s.arg,m,o),s.prefix?m:c}case"bin":return V[s.op](a(s.l,o),a(s.r,o));case"logic":{let c=a(s.l,o);return s.op==="&&"?c&&a(s.r,o):s.op==="||"?c||a(s.r,o):c??a(s.r,o)}case"cond":return a(s.test,o)?a(s.cons,o):a(s.alt,o);case"assign":return u(s.target,s.op==="="?a(s.value,o):V[s.op[0]](a(s.target,o),a(s.value,o)),o);case"arrow":return(...c)=>{let m=Object.create(null);return s.params.forEach((i,f)=>m[i]=r(c[f])),a(s.body,[m,...o])};case"arr":{let c=[];for(let m of s.items)m.spread?c.push(...a(m.value,o)):c.push(a(m.value,o));return c}case"obj":{let c={},m=(i,f)=>{p(c,i,!0),c[i]=f};for(let i of s.props){let f=a(i.value,o);if(!i.spread)m(i.key,f);else if(f!=null)for(let b of Object.keys(f))m(b,r(f[b]))}return c}}};return a(h,[])}}function at(t,e=M){let r=new WeakMap,n=(l)=>(l&&t.report(l),!!l),p=(l)=>l.localName.toLowerCase(),h=(l,u)=>{let a=l.createElement("template");return a.setAttribute("data-lips-refused",u),a},g=(l)=>{for(let u of[...l.querySelectorAll("*")]){let a=p(u);if(n(t.tag(a))){let o=h(u.ownerDocument,a);o.append(...u.childNodes),u.replaceWith(o);continue}let s=!1;for(let{name:o,value:c}of[...u.attributes])if(n(t.attr(a,o,c)))u.removeAttribute(o),s||=o.toLowerCase()==="is";if(s){let o=u.ownerDocument.createElementNS(u.namespaceURI,u.localName);for(let c of[...u.attributes])o.setAttribute(c.name,c.value);o.append(...u.childNodes),u.replaceWith(o)}}},d=(l)=>{let u=document.createElement("template");return u.innerHTML=l,g(u.content),u};return{...e,clone(l){let u=r.get(l);if(!u)r.set(l,u=d(l.html));return u.content.cloneNode(!0)},element:(l)=>n(t.tag(l.toLowerCase()))?h(document,l):e.element(l),attr(l,u,a){e.attr(l,u,a!==null&&n(t.attr(p(l),u,a))?null:a)},html(l,u){n(t.attr(p(l),"@html",u))?e.content(l,""):l.replaceChildren(d(u).content)},styleVar(l,u,a){e.styleVar(l,u,a!==null&&n(t.css(a))?null:a)},listen:(l,u,a)=>e.listen(l,u,(s)=>a(t.event(s)))}}var ot={ir:{v:1,exprs:[],root:{html:"",scope:[],binds:[],blocks:[]}}};function ct(t=P){let e=it(t),r=new Map,n=at(t),p=new Set,h={run(g){let d=r.get(g);if(!d)r.set(g,d=I(g).ast);return(l)=>e(d,l)},self:(g)=>t.self(g)};return{check:K(t),style:(g)=>(d,l)=>{let u=g(d,{...l,lint(c,m){let i=m!==void 0?t.css(m):c[0]==="@"?t.css(c):void 0;return i&&[{...i,severity:"error"}]}}),a=(c,m,i)=>u.diagnostics.push({...c,severity:"error",loc:G(d,Math.max(m,0),i)}),s=!u.diagnostics.some((c)=>c.code.startsWith("LIPS-U"));for(let c of u.ir.exprs){let m=d.indexOf(c);s=W(t,c,j,(i,f,b)=>a(i,m+f,b))&&s}let o=s?t.css(u.ir.css):void 0;if(o&&a(o,0,0),!s||o)return{...u,ir:{...u.ir,css:"",binds:[],props:void 0}};return p.add(u.ir.css),u},runtime(g){let{components:d,createStylesheet:l}=g;return{...g,guard:h,host:n,components:d&&new Proxy(d,{get:(u,a)=>ut(t,a)?ot:u[a]}),createStylesheet:l&&((u,a)=>{if(p.has(a))return l(u,a);return t.report(y("LIPS-U042",`A stylesheet Lips did not compile cannot be checked — <${u}> ships unstyled`,"Send the stylesheet source; precompiled sheets are trusted output")),{clear(){}}})}}}}var ut=(t,e)=>{let r=typeof e==="string"?t.component(e):void 0;return r&&t.report(r),!!r};export{K as checkTemplate,ct as untrusted,P as untrustedPolicy};
4
4
 
5
- //# debugId=DD4429B74F5A6C4F64756E2164756E21
5
+ //# debugId=86138909CC04E89F64756E2164756E21