@gramlot/gramlot 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gramlot.js +30 -30
- package/dist/gramlot.min.js +6 -6
- package/package.json +2 -2
- package/src/binding/ask-dialog.js +1 -1
- package/src/binding/runtime.js +15 -15
- package/src/builder/gramlot-builder.js +2 -2
- package/src/builder/source.js +1 -1
- package/src/handlers/subscriptions-handler.js +2 -2
- package/src/index-page-runtime.js +2 -2
package/dist/gramlot.min.js
CHANGED
|
@@ -19,8 +19,8 @@ ${a}`),a}_bagToXml(e=null,t=!1,n=0){let i=[];for(let s of this._nodes)i.push((t?
|
|
|
19
19
|
${f}
|
|
20
20
|
${" ".repeat(i)}</${a}>`:`<${a}${l}>${f}</${a}>`:t===null||t.includes(a)?`<${a}${l}/>`:`<${a}${l}></${a}>`}if(u==null||u==="")return t===null||t.includes(a)?`<${a}${l}/>`:`<${a}${l}></${a}>`;let c=u instanceof Date&&!Number.isNaN(u.getTime())?Wh(u):String(u),d=this._escapeXml(c);return`<${a}${l}>${d}</${a}>`}_sanitizeTag(e){return e?e.replace(/[^a-zA-Z0-9_\-.:]/g,"_"):"_none_"}_escapeXml(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}_escapeAttr(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}static fromXml(e,t={}){let{tagAttribute:n=null}=t,i;if(typeof DOMParser<"u"){i=new DOMParser().parseFromString(e,"application/xml");let a=i.querySelector("parsererror");if(a)throw new Error(`XML parse error: ${a.textContent}`)}else i=new Tu.DOMParser().parseFromString(e,"application/xml");return this._xmlElementToBag(i.documentElement,n)}static _xmlElementToBag(e,t=null){let n=new this,i=Array.from(e.childNodes).filter(s=>s.nodeType===1);for(let s of i){let a=s.tagName,o={};for(let m=0;m<s.attributes.length;m++){let g=s.attributes[m];o[g.name]=g.value}let l=Qi(o._resolver);l&&delete o._resolver;let u=String(o._T||"").toUpperCase()==="BAG";Object.assign(o,$a(o));let c=a;"_tag"in o&&(c=o._tag,delete o._tag),t&&t in o&&(c=o[t],delete o[t]);let d=c,f=1;for(;n.getNode(c);)c=`${d}_${f++}`;let p=Array.from(s.childNodes).filter(m=>m.nodeType===1),h;if(p.length>0||u){let m=this._xmlElementToBag(s,t);h=n.setItem(c,m,Object.keys(o).length>0?o:null)}else{let m=s.textContent||"";h=n.setItem(c,m,Object.keys(o).length>0?o:null)}l&&(h.resolver=l),h.xmlTag=a}return n}static async fromUrl(e,t={}){let{timeout:n=30}=t,i={};n&&(i.signal=AbortSignal.timeout(n*1e3));let s=await fetch(e,i),a=s.headers.get("content-type")||"",o=await s.text();if(a.includes("json"))return r.fromTytx(o);if(a.includes("xml"))return r.fromXml(o);let l=o.trim();if(l.startsWith("<"))return r.fromXml(o);if(l.startsWith("{")||l.startsWith("["))return r.fromTytx(o);throw new Rn(`Unsupported content-type: ${a}`)}toJson(e=!0){let t=[];for(let n of this._nodes)t.push(this._nodeToJsonDict(n,e));return e?ne(t):JSON.stringify(t)}_nodeToJsonDict(e,t){let n=e.resolver?null:e.getValue(!0);if(n&&typeof n._nodeToJsonDict=="function"){let s=[];for(let a of n._nodes)s.push(n._nodeToJsonDict(a,t));n=s}let i={label:e.label,value:n,attr:es(e.attr)};return e.nodeTag!==null&&(i.tag=e.nodeTag),e.resolver&&(i.resolver=Bn(e.resolver)),i}static fromJson(e,t={}){return xu||(console.warn("Bag.fromJson is deprecated; use Bag.fromTytx"),xu=!0),this.fromTytx(e,"json",t)}toStringTree(e=!0,t=null,n="",i=!0){t===null&&(t=new Map);let s=[],a=[...this._nodes];for(let o=0;o<a.length;o++){let l=a[o],u=o===a.length-1,c=l.getValue(e),d=l.getAttr(),f="",p=Object.keys(d);p.length>0&&(f=" ["+p.map(b=>`${b}=${JSON.stringify(d[b])}`).join(", ")+"]");let h=u?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",m=n+(u?" ":"\u2502 ");if(c instanceof r){let g=l,b=c.backref?"(*)":"";if(t.has(g))s.push(`${n}${h}${l.label}${b}${f} \u2192 (circular ref)`);else{t.set(g,l.label),s.push(`${n}${h}${l.label}${b}${f}`);let y=c.toStringTree(e,t,m,u);y&&s.push(y)}}else{let g;if(c===null)g="null";else if(c===void 0)g="undefined";else if(c instanceof ArrayBuffer||c instanceof Uint8Array){let b=new TextDecoder("utf-8",{fatal:!1}),y=c instanceof ArrayBuffer?new Uint8Array(c):c;g=b.decode(y)}else typeof c=="string"?c.length>50?g=JSON.stringify(c.slice(0,47)+"..."):g=JSON.stringify(c):g=String(c);s.push(`${n}${h}${l.label}: ${g}${f}`)}}return s.join(`
|
|
21
21
|
`)}toString(e=!0,t=null,n=""){t||(t=new Set);let i=[],s=[...this._nodes];for(let a=0;a<s.length;a++){let o=s[a],l=a===s.length-1,u=o.getValue(e),c="",d=o.attr;d&&Object.keys(d).length>0&&(c=` [${Object.entries(d).map(([m,g])=>`${m}=${JSON.stringify(g)}`).join(", ")}]`);let f=l?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",p=n+(l?" ":"\u2502 ");if(u&&typeof u._htraverse=="function"){let h=o;if(t.has(h))i.push(`${n}${f}${o.label}${c} \u2192 (circular ref)`);else{t.add(h),i.push(`${n}${f}${o.label}${c}`);let m=u.toString(e,t,p);m&&i.push(m)}}else{let h;u==null?h="null":typeof u=="string"&&u.length>50?h=JSON.stringify(u.slice(0,47)+"..."):typeof u=="string"?h=JSON.stringify(u):h=String(u),i.push(`${n}${f}${o.label}: ${h}${c}`)}}return i.join(`
|
|
22
|
-
`)}},Rn=class extends Error{constructor(e){super(e),this.name="BagException"}};ie.registerBagClass(V);Ra(V,"X",r=>r._toTytxPayload(),r=>V._fromTytxPayload(r));Xt(V.tytxSuffix,{...qe(V.tytxSuffix),Bag:V});var Cu=new Set(["False","None","True","and","as","assert","async","await","break","class","continue","def","del","elif","else","except","finally","for","from","global","if","import","in","is","lambda","nonlocal","not","or","pass","raise","return","try","while","with","yield"]);function Su(r){return r.endsWith("_")&&Cu.has(r.slice(0,-1))?r.slice(0,-1):r}function Nu(r){let e=Su(r);return e!==r?e:r.startsWith("_")&&Cu.has(r.slice(1))?r.slice(1):r}function Mn(r,{renderTag:e=null,ns:t=null,dialectName:n=null}={}){let i=e||r;if(!i)return i;if(i=Su(i),t&&!e){let s=`${n}_`;i.startsWith(s)&&(i=i.slice(s.length)),i=`${t}:${i}`}return i}var qr=Symbol("value"),Zt=new Set(["_meta","datapath","node_id","ns","form","formId","_anchor","updateOn"]);function xe(r){return Object.entries(r||{}).filter(([e])=>!Zt.has(e)).map(([e,t])=>[Nu(e),t])}var Ce=class extends Ge{constructor(e,t,n=null,i=null,s=null,a=null,o=null){super(e,t,n,i,s,a,o),this._builder=e?._insertingBuilder??e?._builder??null,this._targetId=null}get builder(){if(this._builder)return this._builder;let e=this.parentBag;return e?e._builder:null}get data(){return this.builder.data}get rootBuilder(){return this.parentBag.root._builder}_getMeta(e){let t=this.getAttr("_meta")||{},n=e.split(",").map(i=>i.trim());return n.length===1?t[n[0]]!==void 0?t[n[0]]:null:n.map(i=>t[i]!==void 0?t[i]:null)}pointerType(e){return typeof e=="string"&&(e[0]==="^"||e[0]==="=")&&!e.startsWith("==")?e[0]:null}pointers(){this.builder.validateCustomTypes(this);let e=[];for(let[t,n]of Object.entries(this.getAttr()||{}))this.pointerType(n)==="^"&&e.push([t,n.split(":",1)[0]]);return this.pointerType(this.value)==="^"&&e.push(["",this.value.split(":",1)[0]]),e}fixedAttrItems(){return xe(this.getAttr())}runtimeToEvaluate(){let e=new Map(this.fixedAttrItems());return e.set(qr,this.value),e}absDatapath(e){let t=e;this.pointerType(e)&&(e=(Y(e)?.pointer??e).slice(1));let n=null;return e.includes("?")&&([e,n]=e.split("?",2)),e.startsWith("#")?this._finalizeAbsPath(this._resolveSymbolicDatapath(e,t),n):(e.startsWith(".")&&(e=this._composeRelativeDatapath(e,t)),this._finalizeAbsPath(e,n))}_finalizeAbsPath(e,t){return e=this._collapseParentDatapath(e,e),t?`${e}?${t}`:e}_composeRelativeDatapath(e,t){let n=this;for(;n!==null&&e.startsWith(".");){let i=n.getAttr("datapath");i!=null&&(e=e==="."?i:i+e),n=n.parentNode}if(e.startsWith("."))throw new Error(`unresolved relative datapath: ${t}`);return e}_collapseParentDatapath(e,t){let n=[];for(let i of e.split("."))if(i==="#parent"){if(n.length===0)throw new Error(`#parent has no segment to cancel: ${t}`);n.pop()}else n.push(i);return n.join(".")}_resolveSymbolicDatapath(e,t){let n=e.slice(1),i=n.indexOf("."),s=i===-1?n:n.slice(0,i),a=i===-1?"":n.slice(i+1),o;if(s==="FORM")o=this._findMarkedDatapathAncestor(!0,!1,t);else if(s==="ANCHOR")o=this._findMarkedDatapathAncestor(!1,!0,t);else{let l=this.rootBuilder;if(!l)throw new Error(`#<id>: cannot resolve ${t} on a node without builder`);if(o=l.source.getNodeByAttr("node_id",s),o==null)throw new Error(`#<id>: cannot resolve ${t}`)}return o.absDatapath(a?`.${a}`:".")}_findMarkedDatapathAncestor(e,t,n){let i=this;for(;i!=null;){let a=i.getAttr()||{};if(e&&(a.formId!=null||a.form===!0)||t&&"_anchor"in a)return i;i=i.parentNode}let s=e?"FORM":"ANCHOR";throw new Error(`#${s}: no marked ancestor found for ${n}`)}getRelativeData(e,t=null,{autocreate:n=!1}={}){let i=this.data,s=this.absDatapath(e);return n&&i.getItem(s)==null&&i.setItem(s,t),i.getItem(s,t)}setRelativeData(e,t,{attributes:n=null,fired:i=!1,reason:s=null}={}){let a=this.data,o=this.absDatapath(e);a.setItem(o,t,n,">",!1,!0,s===null?!0:s,i)}fireEvent(e,t=!0,{attributes:n=null,reason:i=null}={}){this.setRelativeData(e,t,{attributes:n,fired:!0,reason:i})}SET(e,t){this.setRelativeData(e,t)}GET(e){return this.getRelativeData(e)}PUT(e,t){this.setRelativeData(e,t,{reason:!1})}FIRE(e,t=!0){this.setRelativeData(e,t,{fired:!0})}},N=class r extends V{constructor(e=null,t=null){super(e),this._builder=t,this._insertingBuilder=null}get nodeClass(){return Ce}_setBuilderItem(e,t,n,...i){let s=t?.map(([o])=>[o,o._builder])||null;if(t)for(let[o,l]of t)o._builder=l;let a=this._insertingBuilder;this._insertingBuilder=e;try{return this.setItem(n,...i)}catch(o){if(this.node(n)==null&&s)for(let[l,u]of s)l._builder=u;throw o}finally{this._insertingBuilder=a}}bindBuilder(e){if(!e)throw new Error("SourceBag.bindBuilder requires a builder");let t=this._builderBindingPlan(e);for(let[n,i]of t)n._builder=i;return this.setBackref(),this}_builderBindingPlan(e){let t=[],n=new WeakSet,i=(s,a)=>{if(n.has(s))throw new Error("source contains a cyclic or shared SourceBag branch");n.add(s),t.push([s,a]);for(let o of s.getNodes()){let l=a,u=o._getMeta("subbuilder");u!=null&&(l=a._resolveSubbuilderReference(u,o.getAttr()||{},o.nodeTag)),t.push([o,l]);let c=o.getValue(!0);c instanceof r&&i(c,l)}};return i(this,e),t}};if((qe(N.tytxSuffix).SourceBag??N)!==N)throw new Error("TYTX subtype name 'SourceBag' is already registered for another class");Xt(N.tytxSuffix,{...qe(N.tytxSuffix),SourceBag:N});function Zh(r){if(r.length===0)return{value:null,attrs:{}};let e=r[0];if(e!==null&&typeof e=="object"){let t=Object.getPrototypeOf(e);if(t===Object.prototype||t===null)return{value:null,attrs:e}}return{value:e,attrs:r[1]||{}}}var Jh=new Set(["then","toJSON"]),Iu=new WeakMap;function me(r){return Iu.get(r)||r}function $n(r){if(r==null)return r;r=me(r);let e=r._builder||r.parentBag&&r.parentBag._builder;return e?e.wrapSource(r):r}function Bu(r,e){let t=e instanceof V,n=new Proxy(e,{get(i,s){if(typeof s=="symbol"||s.startsWith("_")||Jh.has(s))return Reflect.get(i,s,i);let a=r.schemaTag(s);if(t&&a)return Ou(r,i,a,t);if(s in i){let l=Reflect.get(i,s,i);return typeof l=="function"?l.bind(i):l}if(a)return Ou(r,i,a,t);let o=r.containerMethod(s);if(o)return(...l)=>r[o](r.wrapSource(i),...l)}});return Iu.set(n,e),n}function Ou(r,e,t,n){return(...i)=>{let{value:s,attrs:a}=Zh(i),o=n?r.bagCall(e,t,s,a):r.commandOnNode(e,t,s,a);return o.builder.wrapSource(o)}}function ja(r,e,{transport:t="json"}={}){let n=Z(r,t==="json"?null:t);if(!(n instanceof N))throw new TypeError("TYTX payload did not decode to SourceBag");return n.bindBuilder(e)}var Mu=/^[A-Za-z_][A-Za-z0-9_]*$/,Kh=new Set(["positional_only","positional_or_keyword","keyword_only","var_positional","var_keyword"]),Qh=new Set(["framework","value","attribute"]),em=new Map([["builtins.str",r=>typeof r=="string"],["builtins.int",r=>Number.isInteger(r)],["builtins.float",r=>typeof r=="number"&&Number.isFinite(r)],["builtins.bool",r=>typeof r=="boolean"],["builtins.list",r=>Array.isArray(r)],["builtins.dict",r=>r!==null&&typeof r=="object"&&!Array.isArray(r)],["builtins.tuple",r=>Array.isArray(r)],["builtins.set",r=>Array.isArray(r)||r instanceof Set],["builtins.NoneType",r=>r===null],["builtins.object",r=>!0]]);function Kt(r){return r!==null&&typeof r=="object"&&!Array.isArray(r)}function T(r,e){throw new TypeError(`${r}: ${e}`)}function ot(r,e,t,n){Kt(r)||T(n,"must be an object");for(let i of Object.keys(r))e.includes(i)||T(n,`unknown field '${i}'`);for(let i of t)Object.hasOwn(r,i)||T(n,`missing field '${i}'`)}function Qt(r,e){if(!(r===null||typeof r=="string"||typeof r=="boolean")&&!(typeof r=="number"&&Number.isFinite(r))){if(Array.isArray(r))return r.forEach((t,n)=>Qt(t,`${e}[${n}]`));if(Kt(r))return Object.entries(r).forEach(([t,n])=>Qt(n,`${e}.${t}`));T(e,"must be lossless JSON data")}}function tm(r,e){let t="",n=!1;for(let i=0;i<r.length;i++){let s=r[i];if(s==="\\"){t+=s+(r[++i]??"");continue}s==="["&&(n=!0),!n&&s==="."&&!(e&16)?t+="[^\\n]":!n&&s==="^"&&e&8?t+="(?:^|(?<=\\n))":!n&&s==="$"?t+=e&8?"(?=\\n|(?![\\s\\S]))":"(?=\\n?(?![\\s\\S]))":t+=s,s==="]"&&(n=!1)}return t}function Jt(r,e,t=!1,n=null){if(r===null)return null;switch(ot(r,["kind","dtype","module","name","origin","arguments","items","values","base","metadata","pattern","flags","ge","le","gt","lt","value"],["kind"],e),r.kind){case"custom":return ot(r,["kind","name"],["kind","name"],e),n||T(e,"custom references require a catalog; nested catalog references are unsupported"),n.resolve(r.name,e);case"dtype":{ot(r,["kind","dtype"],["kind","dtype"],e);let i=r.dtype;typeof i!="string"&&T(e,"dtype must be a string");let s=Nn(i);return!s&&i!=="NN"&&T(e,`unknown dtype '${i}'`),{...r,test:o=>i==="NN"?o===null:i==="N"?ve(o)&&!["NaN","Infinity","-Infinity"].includes(o.toString()):s===Number?typeof o=="number"&&Number.isFinite(o)&&(i!=="L"||Number.isInteger(o)):s===String?typeof o=="string":s===Boolean?typeof o=="boolean":s===Date?o instanceof Date&&Number.isFinite(o.getTime()):s===Object?Kt(o)&&[Object.prototype,null].includes(Object.getPrototypeOf(o)):o instanceof s}}case"any":return{...r,test:i=>!0};case"type":{(typeof r.module!="string"||typeof r.name!="string")&&T(e,"type requires string module/name");let i=`${r.module}.${r.name}`;if(i==="collections.abc.Callable")return{...r,test:a=>typeof a=="function",portable:!1};let s=em.get(i);return s||T(e,`unsupported type '${i}'`),{...r,test:s}}case"union":{(!Array.isArray(r.items)||!r.items.length)&&T(e,"union items must be non-empty");let i=r.items.map((s,a)=>Jt(s,`${e}.items[${a}]`,!0,n));return{...r,items:i,inputConstraint:i.some(s=>s.inputConstraint),test:s=>i.some(a=>a.test&&a.test(s))}}case"literal":return Array.isArray(r.values)||T(e,"literal values must be an array"),r.values.forEach((i,s)=>Qt(i,`${e}.values[${s}]`)),{...r,test:i=>r.values.some(s=>Object.is(s,i))};case"annotated":{Array.isArray(r.metadata)||T(e,"annotated metadata must be an array"),r.metadata.some(a=>!["regex","range","value"].includes(a?.kind))&&T(e,"unsupported annotation metadata kind");let i=Jt(r.base,`${e}.base`,!0,n),s=r.metadata.map((a,o)=>Jt(a,`${e}.metadata[${o}]`,!0,n));return{...r,base:i,metadata:s,inputConstraint:i.inputConstraint,test:a=>i.test(a)&&s.every(o=>!o.test||o.test(a))}}case"range":{for(let i of["ge","le","gt","lt"])Object.hasOwn(r,i)||T(e,`range missing '${i}'`);for(let i of["ge","le","gt","lt"])r[i]!==null&&(typeof r[i]!="number"||!Number.isFinite(r[i]))&&T(e,`${i} must be finite number or null`);return{...r,test:i=>typeof i=="number"&&(r.ge===null||i>=r.ge)&&(r.le===null||i<=r.le)&&(r.gt===null||i>r.gt)&&(r.lt===null||i<r.lt)}}case"regex":{(typeof r.pattern!="string"||!Number.isInteger(r.flags)||r.flags<0)&&T(e,"regex requires pattern and non-negative integer flags");let i=r.flags&-59;i&&T(e,`unsupported Python regex flags ${i}`),r.flags&2&&T(e,"IGNORECASE is not portable across Python and JavaScript Unicode rules"),/\\[AZzUwWdDsSabBN0-9]|\(\?P[<=!]|\(\?\(|\(\?>|\(\?#|\(\?[aiLmsux-]|[+*?}]\+|\{,/.test(r.pattern.replaceAll(String.raw`[\s\S]`,"."))&&T(e,"regex uses a non-portable construct or character class");let s="uy";r.flags&16&&(s+="s");let a;try{a=new RegExp(`(?:${tm(r.pattern,r.flags)})(?![\\s\\S])`,s)}catch(o){T(e,`invalid portable regex: ${o.message}`)}return{...r,test:o=>typeof o!="string"?!1:(a.lastIndex=0,a.test(o))}}case"value":return Qt(r.value,`${e}.value`),{...r};case"generic":{let i=Jt(r.origin,`${e}.origin`,!0,n);(r.origin?.kind!=="type"||r.origin.module!=="builtins"||!["list","dict","tuple","set"].includes(r.origin.name))&&T(e,"only list, dict, tuple and set generic origins are supported"),Array.isArray(r.arguments)||T(e,"generic arguments must be an array");let s=r.arguments.map((a,o)=>Jt(a,`${e}.arguments[${o}]`,!0,n));return{...r,origin:i,arguments:s,inputConstraint:s.some(a=>a.inputConstraint),test:a=>i.test(a)&&rm(r.origin,s,a)}}case"arguments":T(e,"Callable argument-list descriptors are not supported by Python validation");case"ellipsis":return t||T(e,"ellipsis is only valid as a nested descriptor"),{...r};default:T(e,`unknown annotation kind '${r.kind}'`)}}function rm(r,e,t){let n=`${r.module}.${r.name}`;return n==="builtins.tuple"&&e.length&&e[1]?.kind!=="ellipsis"?t.length===e.length&&t.every((i,s)=>e[s].test(i)):n==="builtins.list"||n==="builtins.set"||n==="builtins.tuple"?[...t].every(i=>!e[0]?.test||e[0].test(i)):n==="builtins.dict"?Object.entries(t).every(([i,s])=>(!e[0]?.test||e[0].test(i))&&(!e[1]?.test||e[1].test(s))):!1}function $u(r,e){if(r===null)return null;if(typeof r!="string"&&T(e,"must be string or null"),r==="")return new Map;let t=new Map;for(let n of r.split(",")){let i=n.trim();/^[A-Za-z_][A-Za-z0-9_]*\[\]$/.test(i)&&T(e,`invalid cardinality item '${n}'`);let s=i.match(/^([A-Za-z_][A-Za-z0-9_]*|\*)(?:\[(?:(\d+)|(?:(\d*):(\d*)))\])?$/);s||T(e,`invalid cardinality item '${n}'`);let[,a,o,l,u]=s;t.has(a)&&T(e,`duplicate tag '${a}'`);let c=0,d=1/0;i.includes("[")&&(i.includes(":")?(c=l?Number(l):0,d=u?Number(u):1/0):c=d=Number(o)),d<c&&T(e,`maximum ${d} is below minimum ${c}`),t.set(a,{min:c,max:d})}return t.has("*")&&t.size>1&&T(e,"wildcard '*' cannot be combined with named tags"),t}function Fu(r,e){if(r===null)return null;typeof r!="string"&&T(e,"must be string or null");let t=new Set;for(let n of r.split(",")){let i=n.trim();i&&((!Mu.test(i)||t.has(i))&&T(e,`invalid or duplicate parent '${n}'`),t.add(i))}return t}function nm(r,e,t){if(r===null)return null;ot(r,["parameters","accepts_var_keyword","accepts_var_positional"],[],e);let n=r.parameters??[];Array.isArray(n)||T(e,"parameters must be an array"),r={parameters:n,accepts_var_keyword:n.some(l=>l.kind==="var_keyword"),accepts_var_positional:n.some(l=>l.kind==="var_positional"),...r},(!Array.isArray(r.parameters)||typeof r.accepts_var_keyword!="boolean"||typeof r.accepts_var_positional!="boolean")&&T(e,"invalid signature descriptor");let i=new Set,s=!1,a=!1,o=r.parameters.map((l,u)=>{let c=`${e}.parameters[${u}]`;return ot(l,["name","kind","role","annotation","has_default","default"],["name","kind","role","annotation","has_default"],c),(typeof l.name!="string"||!Mu.test(l.name)||i.has(l.name))&&T(c,"invalid or duplicate parameter name"),i.add(l.name),(!Kh.has(l.kind)||!Qh.has(l.role)||typeof l.has_default!="boolean")&&T(c,"invalid kind, role, or has_default"),l.has_default!==Object.hasOwn(l,"default")&&T(c,"default presence must equal has_default"),l.has_default&&Qt(l.default,`${c}.default`),s||=l.kind==="var_keyword",a||=l.kind==="var_positional",{...l,annotation:Jt(l.annotation,`${c}.annotation`,!1,t)}});return(s!==r.accepts_var_keyword||a!==r.accepts_var_positional)&&T(e,"variadic summary flags do not match parameters"),{...r,parameters:o}}function Ru(r,e,t,n){let i=["doc","sub_tags","parent_tags","inherits_from","ns","attributes",...t?["node_label","collection_key"]:[],"_meta"];ot(r,i,[],e),r={...Object.fromEntries(i.map(s=>[s,null])),...r};for(let s of["doc","inherits_from","ns",...t?["node_label","collection_key"]:[]])r[s]!==null&&typeof r[s]!="string"&&T(e,`${s} must be string or null`);return r._meta!==null&&(Kt(r._meta)||T(e,"_meta must be object or null"),Qt(r._meta,`${e}._meta`)),$u(r.sub_tags,`${e}.sub_tags`),Fu(r.parent_tags,`${e}.parent_tags`),{...r,attributes:nm(r.attributes,`${e}.attributes`,n)}}function Lu(r){return r?r.split(",").map(e=>e.trim()).filter(Boolean):[]}function Pu(r,e){let t={...e};for(let[n,i]of Object.entries(r))n==="inherits_from"||n.startsWith("_")||t[n]||(t[n]=i);return t._meta={...r._meta||{},...e._meta||{}},t}function ju(r){let e={...r};return e._subSpec=Object.hasOwn(e,"sub_tags")?$u(e.sub_tags,"resolved.sub_tags"):null,e._parentSpec=Object.hasOwn(e,"parent_tags")?Fu(e.parent_tags,"resolved.parent_tags"):null,e}function Uu(r,e,t,n){if(t.get(r)===1&&T(n,`inheritance cycle at '${r}'`),t.get(r)===2)return e[r];let i=e[r];i||T(n,`unknown abstract '${r}'`),t.set(r,1);let s={...i};for(let a of Lu(i.inherits_from))s=Pu(Uu(a,e,t,n),s);return s=ju(s),t.set(r,2),e[r]=s,s}function Ua({abstracts:r={},elements:e={}}){let t={...r},n=new Map;for(let s of Object.keys(t))Uu(s,t,n,`abstracts.${s}.inherits_from`);let i={};for(let[s,a]of Object.entries(e)){let o={...a};for(let l of Lu(a.inherits_from)){let u=t[l];u||T(`elements.${s}.inherits_from`,`unknown abstract '${l}'`),o=Pu(u,o)}i[s]=ju(o)}return{abstracts:t,elements:i}}function qa(r){ot(r,["document_format","grammar","abstracts","elements","custom_types"],["document_format","grammar","abstracts","elements"],"grammar document"),ot(r.document_format,["name","version"],["name","version"],"document_format"),(r.document_format.name!=="builder_grammar"||!["1.1","1.2"].includes(r.document_format.version))&&T("document_format","expected builder_grammar version 1.1 or 1.2"),ot(r.grammar,["name","version","title","description"],["name","version","title","description"],"grammar"),(typeof r.grammar.name!="string"||!r.grammar.name)&&T("grammar.name","must be non-empty string");for(let i of["version","title","description"])r.grammar[i]!==null&&typeof r.grammar[i]!="string"&&T(`grammar.${i}`,"must be string or null");(!Kt(r.abstracts)||!Kt(r.elements))&&T("grammar document","abstracts/elements must be objects"),Object.hasOwn(r,"custom_types")&&r.document_format.version!=="1.2"&&T("custom_types","requires version 1.2");let e=Vr.fromJSON(r.custom_types??{}),t={};for(let[i,s]of Object.entries(r.abstracts))(!i||i.startsWith("_"))&&T("abstracts",`invalid public name '${i}'`),t[i]=Ru(s,`abstracts.${i}`,!1,e);let n={};for(let[i,s]of Object.entries(r.elements))(!i||i.startsWith("_"))&&T("elements",`invalid public name '${i}'`),n[i]=Ru(s,`elements.${i}`,!0,e);return{grammar:structuredClone(r.grammar),abstracts:t,elements:n}}function qu(r,e,t,n){let i=e.attributes;if(!i)return;let s={...n};t!=null&&(s.node_value=t);let a=new Set(i.parameters.filter(u=>u.role==="attribute").map(u=>u.name)),o=new Set(["node_label","node_position","node_id","target_id","datapath","iterate","store","_tag","_meta","ns"]);if(!i.accepts_var_keyword)for(let u of Object.keys(n))!a.has(u)&&!o.has(u)&&T(r,`unknown attribute '${u}'`);let l=e._meta?.component?i.parameters.find(u=>u.role!=="framework"&&["positional_only","positional_or_keyword"].includes(u.kind))?.name:null;for(let u of i.parameters){if(u.name===l||u.role==="framework"||u.kind.startsWith("var_"))continue;let c=Object.hasOwn(s,u.name);!c&&!u.has_default&&T(r,`missing required ${u.role} '${u.name}'`),c&&u.annotation!==null&&(!u.annotation.test||!u.annotation.test(s[u.name]))&&T(r,`invalid value for ${u.role} '${u.name}'`)}}var Vr=class r{#e=new Map;#t=new Map;register(e,t,n){let i=new Map([[String,"str"],[Number,"float"],["string","str"],["integer","int"],["number","float"]]),s=i.has(t)?{kind:"type",module:"builtins",name:i.get(t)}:t;return this.#r(e,{kind:"annotated",base:s,metadata:[n]})}#r(e,t){(typeof e!="string"||!/^[A-Za-z][A-Za-z0-9_]*$/.test(e)||e in this||["to_dict","from_dict"].includes(e)||im.has(e))&&T("custom_types",`invalid, reserved or duplicate name '${e}'`),ot(t,["kind","base","metadata"],["kind","base","metadata"],`custom_types.${e}`),(t.kind!=="annotated"||!Array.isArray(t.metadata)||t.metadata.length!==1||!["regex","range"].includes(t.metadata[0]?.kind))&&T(`custom_types.${e}`,"requires an annotated base with one Regex or Range validator");let n=t.metadata[0].kind==="regex"?["str"]:["int","float"];(t.base?.kind!=="type"||t.base.module!=="builtins"||!n.includes(t.base.name))&&T(`custom_types.${e}`,"portable Regex requires str; portable Range requires int or float"),Qt(t,`custom_types.${e}`);let i=structuredClone(t),s=Jt(i,`custom_types.${e}`),a=Object.freeze({kind:"custom",name:e});return Object.defineProperty(this,e,{value:a,enumerable:!0}),this.#e.set(e,i),this.#t.set(e,{...a,inputConstraint:!0,test:s.test}),a}resolve(e,t="custom_types"){return this.#t.has(e)||T(t,`unknown custom type '${e}'`),{...this.#t.get(e)}}validate(e,t){return this.resolve(e).test(t)||T(`custom_types.${e}`,"invalid input value"),!0}toJSON(){return structuredClone(Object.fromEntries(this.#e))}static fromJSON(e){Kt(e)||T("custom_types","must be an object");let t=new r;for(let[n,i]of Object.entries(e))t.#r(n,i);return t}},im=new Set("False None True and as assert async await break class continue def del elif else except finally for from global if import in is lambda nonlocal not or pass raise return try while with yield".split(" "));function Vu(r,e,t,n){let i=e?.attributes;if(i)for(let s of i.parameters){if(!s.annotation?.inputConstraint||s.role==="framework"||["var_keyword","var_positional"].includes(s.kind))continue;let a=s.role==="value"?t:n[s.name];a!==void 0&&(s.annotation.test(a)||T(r,`invalid input for '${s.name}' (custom type)`))}}function zu(r,e,t=[]){if(e===null)return structuredClone(r);if(t.length===2&&t[0]==="custom_types"&&r!==void 0){if(!Va(r,e))throw new TypeError(`conflicting custom type '${t[1]}'`);return structuredClone(r)}if(t.length===2&&["abstracts","elements"].includes(t[0]))return structuredClone(e);if(ht(r)&&ht(e)){let n=structuredClone(r);for(let[i,s]of Object.entries(e))s!==null&&Object.defineProperty(n,i,{value:zu(n[i],s,[...t,i]),enumerable:!0,writable:!0,configurable:!0});return n}return structuredClone(e)}function Va(r,e){return Object.is(r,e)?!0:Array.isArray(r)&&Array.isArray(e)?r.length===e.length&&r.every((t,n)=>Va(t,e[n])):ht(r)&&ht(e)?Object.keys(r).length===Object.keys(e).length&&Object.keys(r).every(t=>Object.hasOwn(e,t)&&Va(r[t],e[t])):!1}function ht(r){return r!==null&&typeof r=="object"&&!Array.isArray(r)&&Object.getPrototypeOf(r)===Object.prototype}function za(r){if(!(r===null||typeof r=="string"||typeof r=="boolean")&&!(typeof r=="number"&&Number.isFinite(r))){if(Array.isArray(r)){r.forEach(za);return}if(ht(r)){Object.values(r).forEach(za);return}throw new TypeError("collection must contain only finite JSON values")}}var mt=class r{#e;constructor(e){za(e);let t=["document_format","grammar","abstracts","elements"];if(!ht(e)||Object.keys(e).some(i=>![...t,"custom_types"].includes(i))||t.some(i=>!Object.hasOwn(e,i)))throw new TypeError("collection requires document_format, grammar, abstracts and elements");let n=e.document_format;if(!ht(n)||Object.keys(n).length!==2||n.name!=="builder_grammar"||!["1.1","1.2"].includes(n.version))throw new TypeError("expected builder_grammar version 1.1 or 1.2");for(let i of["grammar","abstracts","elements"])if(!ht(e[i]))throw new TypeError(`${i} must be an object`);if(Object.hasOwn(e,"custom_types")&&(n.version!=="1.2"||!ht(e.custom_types)))throw new TypeError("custom_types requires an object catalog and version 1.2");this.#e=structuredClone(e)}update(e){let t=new r(e),n=zu(this.#e,t.#e);return(this.#e.document_format.version==="1.2"||t.#e.document_format.version==="1.2")&&(n.document_format.version="1.2"),this.#e=n,this}toDocument(){return structuredClone(this.#e)}};var er=class{static renderType="string";static mode=null;constructor(e){this._builder=e,this.renders=new Map([[e,this]])}get builder(){return this._builder}get renderType(){return this.constructor.renderType}get mode(){return this.constructor.mode}addRender(e,t){this.renders.set(e,t)}getRender(e){let t=this.renders.get(e);if(t!==void 0)return t;let n=e.getRenderer();return this.renders.set(e,n),n}render(e,t={}){let n=e.builder,[i,s]=n.runtimeValues(e);if(e._getMeta("data_element"))return null;if(e._getMeta("component"))return this._renderComponent(e,s,t);let a=this.getRender(n),o;return[o,s]=a._handleMeta(e,s),e._getMeta("subbuilder")||(s=a.adaptAttrs(s)),e.value instanceof N&&(i=this.renderChildren(e.value,t)),a.renderedItem(e,i,s,{tag:o,...t})}renderChildren(e,t={}){let n=[];for(let i of e.getNodes()){let s=this.render(i,t);s!==null&&(Array.isArray(s)?n.push(...s):n.push(s))}return n}_renderComponent(e,t,n){let[i,s,a,o]=this._expansionInputs(e,t);if(!Object.hasOwn(e.getAttr(),"iterate"))return this._expandBlock(e,i,a,o,n);if(s==null)return[];if(!(s instanceof V))throw new TypeError(`component '${e.nodeTag}': iterate must resolve to a Bag, got ${s?.constructor?.name||typeof s}`);return s.getNodes().map(l=>this._expandBlock(e,i,a,{node_label:l.label},n))}_expansionInputs(e,t){let n=e.builder,i=n.componentMethod(e.nodeTag),s=i&&n[i];if(typeof s!="function")throw new Error(`component '${e.nodeTag}' has no implementation`);let a=t.iterate;delete t.iterate,delete t.store;let o=e.getAttr("iterate")||e.getAttr("store");o!=null?(e.pointerType(o)&&(o=o.slice(1)),o.startsWith(".")&&(o=e._composeRelativeDatapath(o,o))):o=null;for(let l of Object.keys(t)){let u=e.getAttr(l);e.pointerType(u)==="^"&&(t[l]=`^${e.absDatapath(u)}`)}return[s,a,o,t]}_expandBlock(e,t,n,i,s){let a=e.builder._expansionRoot(n);t.call(e.builder,$n(a),i);let o=a.getNodes();if(o.length!==1)throw new Error(`component '${e.nodeTag}' must build a tree, not a forest: ${o.length} root nodes`);let l={...s,depthOffset:this._nodeDepth(e,s.depthOffset||0)};return this.render(o[0],l)}preprocess(e){return e}renderedItem(e,t,n,i){throw new Error(`${this.constructor.name} does not implement renderedItem`)}_handleMeta(e,t){let[n,i]=e._getMeta("render_tag,render_attributes"),s=Mn(e.nodeTag,{renderTag:n,ns:e.getAttr("ns"),dialectName:e.builder?.constructor._name});if(!s)throw new Error(`node ${e.label} has no tag to render (no render_tag, no node_tag)`);return i&&(t={...t,...i}),[s,t]}adaptAttrs(e){return e}adapt(e){let t=`${this.builder.constructor._name}_`;return e.startsWith(t)?e.slice(t.length):e}finalize(e,t=null,n={}){let i=this._composeStringFragments(e);if(t==null)return i;if(typeof t=="string")throw new TypeError("string render targets require filesystem support, which is unavailable in the portable renderer; pass a callable or writable target instead");if(typeof t.full=="function"&&typeof t.write!="function")return t.full(i),null;if(typeof t.write=="function")return t.write(i),null;if(typeof t=="function")return t(i),null;throw new TypeError("render target must be writable (.write), callable, or expose .full")}_composeStringFragments(e){if(!Array.isArray(e))return e;if(e.some(t=>typeof t!="string"))throw new TypeError("String composition requires string fragments; object renderers must define their own composition");return e.join("")}_escapeText(e){return String(e).replaceAll("&","&").replaceAll("<","<").replaceAll(">",">")}_escapeAttr(e){return this._escapeText(e).replaceAll('"',""")}_nodeDepth(e,t=0){let i=((e.fullpath||"").match(/\./g)||[]).length;return Math.max(i-1,0)+t}};var tr=class extends er{static mode="xml";renderedItem(e,t,n,{tag:i,pretty:s=!1,depthOffset:a=0}={}){let o=this._formatAttrs(n),l=s?" ".repeat(this._nodeDepth(e,a)):"",u=s?`
|
|
23
|
-
`:"";if(Array.isArray(t)){let c=this._composeStringFragments(t);return`${l}<${i}${o}>${u}${c}${l}</${i}>${u}`}return t==null?`${l}<${i}${o}></${i}>${u}`:`${l}<${i}${o}>${this._escapeText(t)}</${i}>${u}`}finalize(e,t=null,{docHeader:n=null}={}){let i=this._composeStringFragments(e);return n===!0?i=`<?xml version='1.0' encoding='UTF-8'?>${i}`:typeof n=="string"&&(i=n+i),super.finalize(i,t)}_formatAttrs(e){return Object.entries(e||{}).map(([t,n])=>` ${t.startsWith("xmlns_")?`xmlns:${t.slice(6)}`:t}="${this._escapeAttr(n)}"`).join("")}};var Hu={document_format:{name:"builder_grammar",version:"1.1"},grammar:{name:"base",version:null,title:null,description:null},abstracts:{},elements:{dataSetter:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"destination",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"value",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1},{name:"attr",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataFormula:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"destination",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"func",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"collections.abc",name:"Callable"}]},has_default:!1},{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataController:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"func",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"collections.abc",name:"Callable"}]},has_default:!1},{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}}}};function Wu(r){let e=[];for(;r&&r!==Function.prototype;)e.push(r),r=Object.getPrototypeOf(r);return e.reverse()}function am(r){let e=Object.create(null),t=(n,i)=>{let s=n.toLowerCase(),a=e[s];if(a!==void 0&&a!==i)throw new Error(`container '${n}' is already tied to implementation method '${a}' (cannot rebind to '${i}')`);e[s]=i};for(let n of Wu(r))if(Object.hasOwn(n,"containers"))for(let i of n.containers||[])t(i,i);return e}function Fn(r){let e=Object.create(null);for(let t of Object.keys(r)){let n=t.toLowerCase();if(Object.hasOwn(e,n))throw new Error(`element declaration '${t}' has a case-insensitive collision with '${e[n]}'`);e[n]=t}return e}var Ln="_root_",Pn="_root_",Gu=new Set(["destination","func","value","_on_start"]),Se=class r{static _sourceClass=N;static registerBuilder(e){if(typeof e!="function"||!(e.prototype instanceof r))throw new TypeError("registerBuilder requires a BuilderBase subclass");let t=e._name;if(typeof t!="string"||!t)throw new TypeError("registered builders require a non-empty static _name");let n=r._registry.get(t);if(n&&n!==e)throw new Error(`Builder name '${t}' is already registered to ${n.name}; cannot register ${e.name}`);return r._registry.set(t,e),e}static getBuilderClass(e){let t=r._registry.get(e);if(!t)throw new Error(`No builder registered with name '${e}'`);return t}constructor(e=null){this.name=e||this.constructor._name,this._dataroot=new V,this._dataroot.setBackref(),this._dataroot.setItem(Pn,new V),this.data=this._dataroot.getItem(Pn),this._defaultTargets=new Map,this.materialized=Object.create(null),this._collection=null,this._schemaOverride=null,this._tagNamesOverride=null,this._componentMap=null,this._targetSerial=0,this._subbuilders=new Map,this._sourceHandles=new WeakMap;let t=this.constructor._sourceClass;this._sourceroot=new t(null,this),this._sourceroot.setBackref(),this._sourceroot.setItem(Ln,new t(null,this)),this.source=this._sourceroot.getItem(Ln)}wrapSource(e){if(e=me(e),!(e instanceof N)&&!(e instanceof Ce))throw new TypeError("wrapSource requires a SourceBag or SourceBagNode");let t=this._sourceHandles.get(e);return t||(t=Bu(this,e),this._sourceHandles.set(e,t)),t}get root(){return this.wrapSource(this.source)}getSubbuilder(e){if(typeof e!="string"||!e||e.includes(":"))throw new Error(`unsupported subbuilder reference '${e}'`);let t=this._subbuilders.get(e);if(!t){let n=r.getBuilderClass(e);t=new n,this._subbuilders.set(e,t)}return t._dataroot=this._dataroot,t.data=this.data,t}_resolveSubbuilderReference(e,t,n){if(typeof e!="string"||!e)throw new Error(`'${n}': subbuilder declaration must be a non-empty string`);if(e.includes(":"))throw new Error(`'${n}': runtime subbuilder reference '${e}' is unsupported`);return this.getSubbuilder(e)}static defineGrammar(e){let t=this._classCollection,n=t?new mt(t.toDocument()).update(e):new mt(e),i=qa(n.toDocument()),s=Ua(i),a=Fn(s.elements);this._classCollection=n,this._classSchema=s.elements,this._abstracts=s.abstracts,this._tagNames=a}static{this.defineGrammar(Hu)}get _containers(){return am(this.constructor)}containerMethod(e){return this._containers[e.toLowerCase()]||null}componentMethod(e){return this._componentMap?.[e.toLowerCase()]||null}get schema(){return this._schemaOverride||this.constructor._classSchema||{}}get schemaTagNames(){return this._schemaOverride?this._tagNamesOverride??=Fn(this.schema):this.constructor._tagNames??=Fn(this.schema)}schemaTag(e){let t=e.toLowerCase(),n=this.schemaTagNames[t];if(n)return n;let i=`${this.constructor._name}_`;return t.startsWith(i)&&this.schemaTagNames[t.slice(i.length)]||null}loadGrammar(e,{replace:t=!1}={}){let n=this._collection||this.constructor._classCollection,i=t?new mt(e):new mt(n.toDocument()).update(e),s=qa(i.toDocument()),a=Ua(s),o=Fn(a.elements);return this._collection=i,this._schemaOverride=a.elements,this._tagNamesOverride=o,this}validateCustomTypes(e){let t=e.parentBag?.parentNode?.builder||e.parentBag?._builder,n=t&&t!==this&&t.schema[e.nodeTag]?._meta?.subbuilder?t:this;Vu(e.nodeTag,n.schema[e.nodeTag],e.value,e.getAttr()||{})}validateNodeValues(e,t,n={}){let i=this.schemaTag(e);if(!i)throw new Error(`unknown element '${e}'`);return qu(i,this.schema[i],t,n),!0}validateNode(e,{value:t,attrs:n,childTags:i}={}){if(!e||typeof e.nodeTag!="string")throw new TypeError("validateNode requires a source node");let s=t!==void 0?t:e.value instanceof N?null:e.value;this.validateNodeValues(e.nodeTag,s,n||e.getAttr?.()||{});let a=this.schema[this.schemaTag(e.nodeTag)],o=i||(e.value instanceof N?e.value.getNodes().map(l=>l.nodeTag):null);return o&&this._validateChildren(e.nodeTag,a,o,!1),!0}validateChildren(e,t,{includeMinimum:n=!1}={}){let i=this.schemaTag(e);if(!i)throw new Error(`unknown element '${e}'`);if(!Array.isArray(t)||t.some(s=>typeof s!="string"))throw new TypeError("childTags must be an array of strings");return this._validateChildren(i,this.schema[i],t,n)}validateParent(e,t=null){let n=this.schemaTag(e);if(!n)throw new Error(`unknown element '${e}'`);let i=this.schema[n];if(!this._countsForGrammar(i))return!0;let s=i._parentSpec;if(s==null||s.has("*"))return!0;if(t===null)throw new Error(`'${n}' requires a declared parent`);let a=this.schemaTag(t);if(!a)throw new Error(`unknown parent element '${t}'`);return this._validateParent(n,i,a),!0}bagCall(e,t,n,i){return this.setChild(e,t,n,i)}commandOnNode(e,t,n,i){if(e=me(e),e.value instanceof N)return this.setChild(e.value,t,n,i);let s=e.value,a=new e.parentBag.constructor(null,e.builder||this),o=this.setChild(a,t,n,i,e);return this.promoteNodeValue(e,s,a),o}promoteNodeValue(e,t,n){e.setValue(n)}setChild(e,t,n,i,s=null){let a={...i},o=this.schema[t];if(!o)throw new Error(`unknown element '${t}'`);this.validateNodeValues(t,n,a);let l=o._meta?.subbuilder,c=(l==null?null:this._resolveSubbuilderReference(l,a,t))||this,d=n instanceof N?n._builderBindingPlan(c):null,f=s?.rootBuilder||e.root._builder||this;if(a.node_id!=null&&f.source.getNodeByAttr("node_id",a.node_id))throw new Error(`Duplicate node_id '${a.node_id}'`);n instanceof N&&this._validateChildren(t,o,n.getNodes().map(v=>v.nodeTag),!1);let p=s||e.parentNode,h=p?.nodeTag?this.schema[p.nodeTag]:null;if(h&&!p._getMeta("subbuilder")&&this._countsForGrammar(o))this._validateParent(t,o,p.nodeTag),this._validateChildren(p.nodeTag,h,[...e.getNodes().map(v=>v.nodeTag),t],!1);else if(!h&&!p?._getMeta("subbuilder")&&o._parentSpec!=null&&this._countsForGrammar(o))throw new Error(`'${t}' requires a declared parent`);o._meta&&!("_meta"in a)&&(a._meta=o._meta),o.ns&&!("ns"in a)&&(a.ns=o.ns);let m=a.node_position;delete a.node_position;let g=a.node_label;delete a.node_label;let b;if(h?.collection_key){if(g!=null)throw new Error(`'${t}': node_label is not allowed in a collection`);b=this._collectionLabel(h.collection_key,t,a)}else{let v=h?._subSpec?.get(t);if(v&&v.max===1){if(g!=null)throw new Error(`'${t}': node_label is not allowed on a singleton`);b=t}else b=g||o.node_label||this._autoLabel(e,t)}if(e.node(b)!=null)throw new Error(`duplicate node label '${b}'`);return e._setBuilderItem(c,d,b,n,a,m||">",!1,!0,null,!1,!0,null,t)}_countsForGrammar(e){let t=e?._meta||{};return!(t.data_element||t.subbuilder||t.component)}_validateParent(e,t,n){let i=t._parentSpec;if(!(i==null||i.has("*")||!this._countsForGrammar(t))&&!i.has(n))throw new Error(`'${e}' not allowed as child of '${n}'`)}_validateChildren(e,t,n,i){let s=t._subSpec;if(s==null||s.has("*")||t._meta?.subbuilder)return[];let a=new Map;for(let o of n){let l=this.schema[o];if(l&&!this._countsForGrammar(l))continue;let u=s.get(o);if(!u)throw new Error(`'${o}' not allowed as child of '${e}'`);let c=(a.get(o)||0)+1;if(a.set(o,c),c>u.max)throw new Error(`too many '${o}' in '${e}'`)}return i?[...s].filter(([o,l])=>(a.get(o)||0)<l.min).map(([o])=>o):[]}_collectionLabel(e,t,n){let i=s=>{if(n[s]===null||n[s]===void 0)throw new Error(`'${t}': collection key needs attribute '${s}'`);return String(n[s])};return e.includes("${")?e.replace(/\$\{([^}]+)\}/g,(s,a)=>i(a)):i(e)}validateSource(){let e=[],t=(n,i="")=>{for(let s of n.getNodes()){let a=i?`${i}.${s.label}`:s.label,o=s.builder;o.validateCustomTypes(s);let l=o.schema[s.nodeTag];if(l&&!s._getMeta("data_element,subbuilder,component").some(Boolean)){let u=s.value instanceof N?s.value.getNodes().map(d=>d.nodeTag):[],c=o._validateChildren(s.nodeTag,l,u,!0);c.length&&e.push([a,c])}s.value instanceof N&&t(s.value,a)}};return t(this.source),e}_autoLabel(e,t){let n=0;for(;e.node(`${t}_${n}`)!==null&&e.node(`${t}_${n}`)!==void 0;)n+=1;return`${t}_${n}`}nodeById(e){let t=this.source.getNodeByAttr("node_id",e);if(t==null)throw new Error(`node_id not found: ${e}`);return t.builder.wrapSource(t)}runtimeValues(e){e.builder.validateCustomTypes(e);let t=new Map,n={},i=e.runtimeToEvaluate(),s=new Set(i.keys()),a=new Map([...Object.entries(e.getAttr()),...e.fixedAttrItems()]);for(let[c,d]of[...i])if(!(typeof c!="string"||!Y(d)))for(let f of Qe(e,d))i.has(f)||i.set(f,a.get(f));let o=e._getMeta("data_element");for(let[c,d]of i){if(d instanceof ie){t.set(c,d.resolve());continue}let f=typeof c=="string"?Y(d)?.pointer??d:d;if(!e.pointerType(f)){t.set(c,typeof c=="string"&&typeof d=="string"&&d.startsWith("==")?null:d);continue}let p=e.absDatapath(f);if(t.set(c,this.data.getItem(p)),!o&&!p.includes("?")&&c===qr){let h=this.data.getNode(p);h&&Object.assign(n,h.getAttr("_wdg"))}}let l=Eo(i,t,(c,d,f,p)=>this.evaluatePointerExpression(e,c,d,f,p)),u=l.get(qr);l.delete(qr);for(let c of l.keys())s.has(c)||l.delete(c);return[u,{...Object.fromEntries(l),...n}]}evaluatePointerExpression(e,t,n,i,s){return null}targetId(e){if(e._targetId)return e._targetId;let t=e.rootBuilder;return e.parentBag.root!==t.source.root?null:(t._targetSerial+=1,e._targetId=`n${t._targetSerial}`,e._targetId)}get dataLogic(){if(!this._dataLogic){let e=this._buildDataLogic();this._dataLogic=Array.isArray(e)?e:[e]}return this._dataLogic}_buildDataLogic(){return this}_resolveLogicFunc(e){if(typeof e=="function")return e;if(typeof e!="string")throw new Error("data-element func must be a name or a function");for(let t of this.dataLogic){let i=(typeof t=="function"?t:t.constructor)[e];if(typeof i=="function")return i}throw new Error(`data-element func '${e}' not found on any data_logic source`)}_bindings(e){let[,t]=this.runtimeValues(e),n={};for(let[i,s]of Object.entries(t))Gu.has(i)||(n[i]=s);return n}computeLogic(e){for(let t of e)this._computeNode(t)}_computeNode(e){let t=e.getAttr()||{};if(e.nodeTag==="dataSetter"){let n={};for(let[i,s]of Object.entries(t))i!=="destination"&&i!=="value"&&!i.startsWith("_")&&(n[i]=s);e.setRelativeData(t.destination,t.value,{attributes:Object.keys(n).length?n:null})}else if(e.nodeTag==="dataFormula"){let n=this._resolveLogicFunc(t.func);e.setRelativeData(t.destination,n(this._bindings(e)))}else e.nodeTag==="dataController"&&this._resolveLogicFunc(t.func)(e,this._bindings(e))}_dataElementNodes(){let e=[],t=n=>{for(let i of n.getNodes())i._getMeta("data_element")&&e.push(i),i.value instanceof N&&t(i.value)};return t(this.source),e}setup(e){}main(e){throw new Error(`${this.constructor.name}.main() not implemented: a bare builder is grammar, not a renderable page`)}_resolveComponents(){let e={};for(let o of Wu(this.constructor))if(Object.hasOwn(o,"components"))for(let l of o.components||[])e[l]=l;if(!Object.keys(e).length)return;let t={...this.schema},n={};for(let[o,l]of Object.entries(e))t[o]={sub_tags:"",_meta:{component:!0}},n[o.toLowerCase()]=l;let i=Fn(t),s=this._collection||this.constructor._classCollection,a=s.toDocument();a.abstracts={},a.elements=Object.fromEntries(Object.keys(e).map(o=>[o,t[o]])),this._collection=new mt(s.toDocument()).update(a),this._schemaOverride=t,this._componentMap=n,this._tagNamesOverride=i}_expansionRoot(e=null){let t=this.constructor._sourceClass,n=new t(null,this);return n.setBackref(),n.setItem(Ln,new t(null,this),e?{datapath:e}:null),n.getItem(Ln)}create(){this.setup(this.data),this._resolveComponents(),this.main(this.root),this.computeLogic(this._dataElementNodes())}get renderer_xml(){return new tr(this)}getRenderer(e=null){e??=this.constructor._defaultRenderMode;let t=this[`renderer_${e}`];if(!t)throw new Error(`${this.constructor.name} does not expose renderer_${e}`);return t}materialize(e=null,t={}){e??=this.constructor._defaultRenderMode;let n=this.getRenderer(e),i=n.renderChildren(n.preprocess(this.source),t);return this.materialized[e]=i,i}setRenderTarget(e,t=null){t??=this.constructor._defaultRenderMode,this._defaultTargets.set(t,e)}render({mode:e=null,target:t=null,...n}={}){e??=this.constructor._defaultRenderMode;let i=this.getRenderer(e);if(t===!1&&i.renderType!=="string")throw new TypeError("target=false is not valid for an object renderer");let s=t===!1?null:t||this._defaultTargets.get(i.mode)||null,a={...s?.renderOpts,...n};return i.finalize(this.materialize(e,a),s,a)}};Se._registry=new Map;var om=new Set(["short","medium","long","full"]),lm=/('(?:[^']|'')*'|[a-zA-Z]+|[^a-zA-Z']+)/g;function um(r,e){if(!(r instanceof Date))throw new TypeError("Temporal formats require a typed Date value");if(!Number.isFinite(r.getTime()))throw new RangeError("Invalid date");let t=e||ne(r).split("::").at(-1);if(!["D","H","DH","DHZ"].includes(t))throw new RangeError(`Unsupported temporal dtype: ${t}`);return t}function cm(r,e,t,n){let i=e.match(lm)||[];if(i.join("")!==e)throw new RangeError("Unclosed format literal");let s=(c,d=2)=>String(c).padStart(d,"0"),a=c=>new Intl.DateTimeFormat(t,{timeZone:"UTC",...c}).format(r),u={...n==="H"?{}:{y:()=>String(r.getUTCFullYear()),yy:()=>s(r.getUTCFullYear()%100),yyyy:()=>s(r.getUTCFullYear(),4),M:()=>String(r.getUTCMonth()+1),MM:()=>s(r.getUTCMonth()+1),MMM:()=>a({month:"short"}),MMMM:()=>a({month:"long"}),d:()=>String(r.getUTCDate()),dd:()=>s(r.getUTCDate()),EEE:()=>a({weekday:"short"}),EEEE:()=>a({weekday:"long"})},...n==="D"?{}:{H:()=>String(r.getUTCHours()),HH:()=>s(r.getUTCHours()),h:()=>String(r.getUTCHours()%12||12),hh:()=>s(r.getUTCHours()%12||12),m:()=>String(r.getUTCMinutes()),mm:()=>s(r.getUTCMinutes()),s:()=>String(r.getUTCSeconds()),ss:()=>s(r.getUTCSeconds()),a:()=>new Intl.DateTimeFormat(t,{hour:"numeric",hour12:!0,timeZone:"UTC"}).formatToParts(r).find(c=>c.type==="dayPeriod").value}};return i.map(c=>{if(c.startsWith("'"))return c==="''"?"'":c.slice(1,-1).replaceAll("''","'");if(!/^[a-zA-Z]/.test(c))return c;if(!u[c])throw new RangeError(`Unsupported date format token: ${c}`);return u[c]()}).join("")}function Xu(r,{format:e,mask:t,locale:n,dtype:i,places:s}={}){let a=r==null?"":String(r);if(r!=null&&r!==""&&(e!=null&&e!==""||s!=null))if(typeof r=="number"||ve(r))a=fm(r,{format:e,locale:n,places:s});else{let o=um(r,i);if(om.has(e)){let l={timeZone:"UTC"};o!=="H"&&(l.dateStyle=e),o!=="D"&&(l.timeStyle=e),a=new Intl.DateTimeFormat(n||void 0,l).format(r)}else a=cm(r,String(e),n||void 0,o)}return t==null?a:String(t).replaceAll("%s",()=>a)}function dm({format:r="decimal",places:e}={}){let t={maximumFractionDigits:20};if(!r||r==="decimal")t.style="decimal";else if(r==="percent")t.style="percent";else if(r==="scientific")t.notation="scientific";else{let n=/^(0|#,##0)(?:\.(0*)(#*))?$/.exec(r);if(!n||r.includes(".")&&!n[2]&&!n[3])throw new RangeError(`Unsupported number format: ${r}`);t.useGrouping=n[1].includes(","),t.minimumFractionDigits=(n[2]||"").length,t.maximumFractionDigits=(n[2]||"").length+(n[3]||"").length}if(e!=null&&e!==""){let n=Number(e);if(!Number.isInteger(n)||n<0||n>20)throw new RangeError("places must be an integer from 0 to 20");t.minimumFractionDigits=n,t.maximumFractionDigits=n}return t}function fm(r,e={}){if(typeof r!="number"&&!ve(r))throw new TypeError("Number formatting requires a Number or Decimal");if(!Number.isFinite(Number(r)))throw new RangeError("Number must be finite");let t=new Intl.NumberFormat(e.locale||void 0,dm(e));if(ve(r)&&new Intl.NumberFormat("en",{useGrouping:!1}).format("9007199254740993")!=="9007199254740993")throw new Error("This browser cannot format Decimal values without precision loss");return t.format(ve(r)?r.toString():r)}var pm=new Set(["style","script"]),hm=new Set(["allowfullscreen","async","autofocus","autoplay","checked","controls","default","defer","disabled","formnovalidate","inert","ismap","itemscope","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"]),Yu=new Set(["width","height","top","left","right","bottom","padding","margin","border","position","display","overflow","float","clear","resize","z_index","min_width","min_height","max_width","max_height","color","background","font","text","line_height","white_space","vertical_align","flex","gap","row_gap","column_gap","grid","align_content","justify_content","align_items","justify_items","visibility","opacity","cursor"]),jn=new Set(["rounded","gradient","shadow","transform","transition","zoom","filter"]),Zu=r=>r===!0?"true":r===!1?"false":String(r),ts=r=>typeof r=="number"&&Number.isFinite(r)?`${r}px`:String(r);function mm(r){if(Yu.has(r))return!0;for(let e of Yu)if(r.startsWith(`${e}_`))return!0;return!1}function gm(r){let e=new Map;if(!r)return e;let t=[],n=0,i=null,s=!1,a=!1,o=0,l=String(r);for(let u=0;u<l.length;u+=1){let c=l[u],d=l[u+1];if(a){c==="*"&&d==="/"&&(a=!1,u+=1);continue}if(s){s=!1;continue}if(c==="\\"){s=!0;continue}if(i){c===i&&(i=null);continue}c==='"'||c==="'"?i=c:c==="/"&&d==="*"?(a=!0,u+=1):"([{".includes(c)?o+=1:")]}".includes(c)&&o>0?o-=1:c===";"&&o===0&&(t.push(l.slice(n,u)),n=u+1)}t.push(l.slice(n));for(let u of t){let c=u.trim();if(!c)continue;let d=c.indexOf(":");if(d<0)throw new TypeError(`malformed style declaration '${c}'`);e.set(c.slice(0,d).trim(),c.slice(d+1).trim())}return e}var rr=class extends er{static mode="html";renderedItem(e,t,n,{tag:i,xml:s=!0,pretty:a=!1,depthOffset:o=0,includeDatapath:l=!1}={}){e.parentNode?._getMeta("subbuilder")==="html"&&(n={xmlns:"http://www.w3.org/1999/xhtml",...n});let{format:c,mask:d,locale:f,places:p,dtype:h,...m}=n;!Array.isArray(t)&&(c!=null||d!=null||p!=null)&&(t=Xu(t,{format:c,mask:d,places:p,dtype:h,locale:this._displayLocale(e,f)}));let g=this._formatAttrs(m);if(l){if(!Object.hasOwn(n,"id")){let x=this.builder.targetId(e);x!==null&&(g+=` id="${this._htmlAttrValue(x)}"`)}for(let[x,$]of Object.entries(e.getAttr()))e.pointerType($)&&(g+=` data-${this.adapt(x)}-pointer="${this._htmlAttrValue(e.absDatapath($))}"`)}let b=a?" ".repeat(this._nodeDepth(e,o)):"",y=a?`
|
|
22
|
+
`)}},Rn=class extends Error{constructor(e){super(e),this.name="BagException"}};ie.registerBagClass(V);Ra(V,"X",r=>r._toTytxPayload(),r=>V._fromTytxPayload(r));Xt(V.tytxSuffix,{...qe(V.tytxSuffix),Bag:V});var Cu=new Set(["False","None","True","and","as","assert","async","await","break","class","continue","def","del","elif","else","except","finally","for","from","global","if","import","in","is","lambda","nonlocal","not","or","pass","raise","return","try","while","with","yield"]);function Su(r){return r.endsWith("_")&&Cu.has(r.slice(0,-1))?r.slice(0,-1):r}function Nu(r){let e=Su(r);return e!==r?e:r.startsWith("_")&&Cu.has(r.slice(1))?r.slice(1):r}function Mn(r,{renderTag:e=null,ns:t=null,dialectName:n=null}={}){let i=e||r;if(!i)return i;if(i=Su(i),t&&!e){let s=`${n}_`;i.startsWith(s)&&(i=i.slice(s.length)),i=`${t}:${i}`}return i}var qr=Symbol("value"),Zt=new Set(["_meta","datapath","nodeId","ns","form","formId","_anchor","updateOn"]);function xe(r){return Object.entries(r||{}).filter(([e])=>!Zt.has(e)).map(([e,t])=>[Nu(e),t])}var Ce=class extends Ge{constructor(e,t,n=null,i=null,s=null,a=null,o=null){super(e,t,n,i,s,a,o),this._builder=e?._insertingBuilder??e?._builder??null,this._targetId=null}get builder(){if(this._builder)return this._builder;let e=this.parentBag;return e?e._builder:null}get data(){return this.builder.data}get rootBuilder(){return this.parentBag.root._builder}_getMeta(e){let t=this.getAttr("_meta")||{},n=e.split(",").map(i=>i.trim());return n.length===1?t[n[0]]!==void 0?t[n[0]]:null:n.map(i=>t[i]!==void 0?t[i]:null)}pointerType(e){return typeof e=="string"&&(e[0]==="^"||e[0]==="=")&&!e.startsWith("==")?e[0]:null}pointers(){this.builder.validateCustomTypes(this);let e=[];for(let[t,n]of Object.entries(this.getAttr()||{}))this.pointerType(n)==="^"&&e.push([t,n.split(":",1)[0]]);return this.pointerType(this.value)==="^"&&e.push(["",this.value.split(":",1)[0]]),e}fixedAttrItems(){return xe(this.getAttr())}runtimeToEvaluate(){let e=new Map(this.fixedAttrItems());return e.set(qr,this.value),e}absDatapath(e){let t=e;this.pointerType(e)&&(e=(Y(e)?.pointer??e).slice(1));let n=null;return e.includes("?")&&([e,n]=e.split("?",2)),e.startsWith("#")?this._finalizeAbsPath(this._resolveSymbolicDatapath(e,t),n):(e.startsWith(".")&&(e=this._composeRelativeDatapath(e,t)),this._finalizeAbsPath(e,n))}_finalizeAbsPath(e,t){return e=this._collapseParentDatapath(e,e),t?`${e}?${t}`:e}_composeRelativeDatapath(e,t){let n=this;for(;n!==null&&e.startsWith(".");){let i=n.getAttr("datapath");i!=null&&(e=e==="."?i:i+e),n=n.parentNode}if(e.startsWith("."))throw new Error(`unresolved relative datapath: ${t}`);return e}_collapseParentDatapath(e,t){let n=[];for(let i of e.split("."))if(i==="#parent"){if(n.length===0)throw new Error(`#parent has no segment to cancel: ${t}`);n.pop()}else n.push(i);return n.join(".")}_resolveSymbolicDatapath(e,t){let n=e.slice(1),i=n.indexOf("."),s=i===-1?n:n.slice(0,i),a=i===-1?"":n.slice(i+1),o;if(s==="FORM")o=this._findMarkedDatapathAncestor(!0,!1,t);else if(s==="ANCHOR")o=this._findMarkedDatapathAncestor(!1,!0,t);else{let l=this.rootBuilder;if(!l)throw new Error(`#<id>: cannot resolve ${t} on a node without builder`);if(o=l.source.getNodeByAttr("nodeId",s),o==null)throw new Error(`#<id>: cannot resolve ${t}`)}return o.absDatapath(a?`.${a}`:".")}_findMarkedDatapathAncestor(e,t,n){let i=this;for(;i!=null;){let a=i.getAttr()||{};if(e&&(a.formId!=null||a.form===!0)||t&&"_anchor"in a)return i;i=i.parentNode}let s=e?"FORM":"ANCHOR";throw new Error(`#${s}: no marked ancestor found for ${n}`)}getRelativeData(e,t=null,{autocreate:n=!1}={}){let i=this.data,s=this.absDatapath(e);return n&&i.getItem(s)==null&&i.setItem(s,t),i.getItem(s,t)}setRelativeData(e,t,{attributes:n=null,fired:i=!1,reason:s=null}={}){let a=this.data,o=this.absDatapath(e);a.setItem(o,t,n,">",!1,!0,s===null?!0:s,i)}fireEvent(e,t=!0,{attributes:n=null,reason:i=null}={}){this.setRelativeData(e,t,{attributes:n,fired:!0,reason:i})}SET(e,t){this.setRelativeData(e,t)}GET(e){return this.getRelativeData(e)}PUT(e,t){this.setRelativeData(e,t,{reason:!1})}FIRE(e,t=!0){this.setRelativeData(e,t,{fired:!0})}},N=class r extends V{constructor(e=null,t=null){super(e),this._builder=t,this._insertingBuilder=null}get nodeClass(){return Ce}_setBuilderItem(e,t,n,...i){let s=t?.map(([o])=>[o,o._builder])||null;if(t)for(let[o,l]of t)o._builder=l;let a=this._insertingBuilder;this._insertingBuilder=e;try{return this.setItem(n,...i)}catch(o){if(this.node(n)==null&&s)for(let[l,u]of s)l._builder=u;throw o}finally{this._insertingBuilder=a}}bindBuilder(e){if(!e)throw new Error("SourceBag.bindBuilder requires a builder");let t=this._builderBindingPlan(e);for(let[n,i]of t)n._builder=i;return this.setBackref(),this}_builderBindingPlan(e){let t=[],n=new WeakSet,i=(s,a)=>{if(n.has(s))throw new Error("source contains a cyclic or shared SourceBag branch");n.add(s),t.push([s,a]);for(let o of s.getNodes()){let l=a,u=o._getMeta("subbuilder");u!=null&&(l=a._resolveSubbuilderReference(u,o.getAttr()||{},o.nodeTag)),t.push([o,l]);let c=o.getValue(!0);c instanceof r&&i(c,l)}};return i(this,e),t}};if((qe(N.tytxSuffix).SourceBag??N)!==N)throw new Error("TYTX subtype name 'SourceBag' is already registered for another class");Xt(N.tytxSuffix,{...qe(N.tytxSuffix),SourceBag:N});function Zh(r){if(r.length===0)return{value:null,attrs:{}};let e=r[0];if(e!==null&&typeof e=="object"){let t=Object.getPrototypeOf(e);if(t===Object.prototype||t===null)return{value:null,attrs:e}}return{value:e,attrs:r[1]||{}}}var Jh=new Set(["then","toJSON"]),Iu=new WeakMap;function me(r){return Iu.get(r)||r}function $n(r){if(r==null)return r;r=me(r);let e=r._builder||r.parentBag&&r.parentBag._builder;return e?e.wrapSource(r):r}function Bu(r,e){let t=e instanceof V,n=new Proxy(e,{get(i,s){if(typeof s=="symbol"||s.startsWith("_")||Jh.has(s))return Reflect.get(i,s,i);let a=r.schemaTag(s);if(t&&a)return Ou(r,i,a,t);if(s in i){let l=Reflect.get(i,s,i);return typeof l=="function"?l.bind(i):l}if(a)return Ou(r,i,a,t);let o=r.containerMethod(s);if(o)return(...l)=>r[o](r.wrapSource(i),...l)}});return Iu.set(n,e),n}function Ou(r,e,t,n){return(...i)=>{let{value:s,attrs:a}=Zh(i),o=n?r.bagCall(e,t,s,a):r.commandOnNode(e,t,s,a);return o.builder.wrapSource(o)}}function ja(r,e,{transport:t="json"}={}){let n=Z(r,t==="json"?null:t);if(!(n instanceof N))throw new TypeError("TYTX payload did not decode to SourceBag");return n.bindBuilder(e)}var Mu=/^[A-Za-z_][A-Za-z0-9_]*$/,Kh=new Set(["positional_only","positional_or_keyword","keyword_only","var_positional","var_keyword"]),Qh=new Set(["framework","value","attribute"]),em=new Map([["builtins.str",r=>typeof r=="string"],["builtins.int",r=>Number.isInteger(r)],["builtins.float",r=>typeof r=="number"&&Number.isFinite(r)],["builtins.bool",r=>typeof r=="boolean"],["builtins.list",r=>Array.isArray(r)],["builtins.dict",r=>r!==null&&typeof r=="object"&&!Array.isArray(r)],["builtins.tuple",r=>Array.isArray(r)],["builtins.set",r=>Array.isArray(r)||r instanceof Set],["builtins.NoneType",r=>r===null],["builtins.object",r=>!0]]);function Kt(r){return r!==null&&typeof r=="object"&&!Array.isArray(r)}function T(r,e){throw new TypeError(`${r}: ${e}`)}function ot(r,e,t,n){Kt(r)||T(n,"must be an object");for(let i of Object.keys(r))e.includes(i)||T(n,`unknown field '${i}'`);for(let i of t)Object.hasOwn(r,i)||T(n,`missing field '${i}'`)}function Qt(r,e){if(!(r===null||typeof r=="string"||typeof r=="boolean")&&!(typeof r=="number"&&Number.isFinite(r))){if(Array.isArray(r))return r.forEach((t,n)=>Qt(t,`${e}[${n}]`));if(Kt(r))return Object.entries(r).forEach(([t,n])=>Qt(n,`${e}.${t}`));T(e,"must be lossless JSON data")}}function tm(r,e){let t="",n=!1;for(let i=0;i<r.length;i++){let s=r[i];if(s==="\\"){t+=s+(r[++i]??"");continue}s==="["&&(n=!0),!n&&s==="."&&!(e&16)?t+="[^\\n]":!n&&s==="^"&&e&8?t+="(?:^|(?<=\\n))":!n&&s==="$"?t+=e&8?"(?=\\n|(?![\\s\\S]))":"(?=\\n?(?![\\s\\S]))":t+=s,s==="]"&&(n=!1)}return t}function Jt(r,e,t=!1,n=null){if(r===null)return null;switch(ot(r,["kind","dtype","module","name","origin","arguments","items","values","base","metadata","pattern","flags","ge","le","gt","lt","value"],["kind"],e),r.kind){case"custom":return ot(r,["kind","name"],["kind","name"],e),n||T(e,"custom references require a catalog; nested catalog references are unsupported"),n.resolve(r.name,e);case"dtype":{ot(r,["kind","dtype"],["kind","dtype"],e);let i=r.dtype;typeof i!="string"&&T(e,"dtype must be a string");let s=Nn(i);return!s&&i!=="NN"&&T(e,`unknown dtype '${i}'`),{...r,test:o=>i==="NN"?o===null:i==="N"?ve(o)&&!["NaN","Infinity","-Infinity"].includes(o.toString()):s===Number?typeof o=="number"&&Number.isFinite(o)&&(i!=="L"||Number.isInteger(o)):s===String?typeof o=="string":s===Boolean?typeof o=="boolean":s===Date?o instanceof Date&&Number.isFinite(o.getTime()):s===Object?Kt(o)&&[Object.prototype,null].includes(Object.getPrototypeOf(o)):o instanceof s}}case"any":return{...r,test:i=>!0};case"type":{(typeof r.module!="string"||typeof r.name!="string")&&T(e,"type requires string module/name");let i=`${r.module}.${r.name}`;if(i==="collections.abc.Callable")return{...r,test:a=>typeof a=="function",portable:!1};let s=em.get(i);return s||T(e,`unsupported type '${i}'`),{...r,test:s}}case"union":{(!Array.isArray(r.items)||!r.items.length)&&T(e,"union items must be non-empty");let i=r.items.map((s,a)=>Jt(s,`${e}.items[${a}]`,!0,n));return{...r,items:i,inputConstraint:i.some(s=>s.inputConstraint),test:s=>i.some(a=>a.test&&a.test(s))}}case"literal":return Array.isArray(r.values)||T(e,"literal values must be an array"),r.values.forEach((i,s)=>Qt(i,`${e}.values[${s}]`)),{...r,test:i=>r.values.some(s=>Object.is(s,i))};case"annotated":{Array.isArray(r.metadata)||T(e,"annotated metadata must be an array"),r.metadata.some(a=>!["regex","range","value"].includes(a?.kind))&&T(e,"unsupported annotation metadata kind");let i=Jt(r.base,`${e}.base`,!0,n),s=r.metadata.map((a,o)=>Jt(a,`${e}.metadata[${o}]`,!0,n));return{...r,base:i,metadata:s,inputConstraint:i.inputConstraint,test:a=>i.test(a)&&s.every(o=>!o.test||o.test(a))}}case"range":{for(let i of["ge","le","gt","lt"])Object.hasOwn(r,i)||T(e,`range missing '${i}'`);for(let i of["ge","le","gt","lt"])r[i]!==null&&(typeof r[i]!="number"||!Number.isFinite(r[i]))&&T(e,`${i} must be finite number or null`);return{...r,test:i=>typeof i=="number"&&(r.ge===null||i>=r.ge)&&(r.le===null||i<=r.le)&&(r.gt===null||i>r.gt)&&(r.lt===null||i<r.lt)}}case"regex":{(typeof r.pattern!="string"||!Number.isInteger(r.flags)||r.flags<0)&&T(e,"regex requires pattern and non-negative integer flags");let i=r.flags&-59;i&&T(e,`unsupported Python regex flags ${i}`),r.flags&2&&T(e,"IGNORECASE is not portable across Python and JavaScript Unicode rules"),/\\[AZzUwWdDsSabBN0-9]|\(\?P[<=!]|\(\?\(|\(\?>|\(\?#|\(\?[aiLmsux-]|[+*?}]\+|\{,/.test(r.pattern.replaceAll(String.raw`[\s\S]`,"."))&&T(e,"regex uses a non-portable construct or character class");let s="uy";r.flags&16&&(s+="s");let a;try{a=new RegExp(`(?:${tm(r.pattern,r.flags)})(?![\\s\\S])`,s)}catch(o){T(e,`invalid portable regex: ${o.message}`)}return{...r,test:o=>typeof o!="string"?!1:(a.lastIndex=0,a.test(o))}}case"value":return Qt(r.value,`${e}.value`),{...r};case"generic":{let i=Jt(r.origin,`${e}.origin`,!0,n);(r.origin?.kind!=="type"||r.origin.module!=="builtins"||!["list","dict","tuple","set"].includes(r.origin.name))&&T(e,"only list, dict, tuple and set generic origins are supported"),Array.isArray(r.arguments)||T(e,"generic arguments must be an array");let s=r.arguments.map((a,o)=>Jt(a,`${e}.arguments[${o}]`,!0,n));return{...r,origin:i,arguments:s,inputConstraint:s.some(a=>a.inputConstraint),test:a=>i.test(a)&&rm(r.origin,s,a)}}case"arguments":T(e,"Callable argument-list descriptors are not supported by Python validation");case"ellipsis":return t||T(e,"ellipsis is only valid as a nested descriptor"),{...r};default:T(e,`unknown annotation kind '${r.kind}'`)}}function rm(r,e,t){let n=`${r.module}.${r.name}`;return n==="builtins.tuple"&&e.length&&e[1]?.kind!=="ellipsis"?t.length===e.length&&t.every((i,s)=>e[s].test(i)):n==="builtins.list"||n==="builtins.set"||n==="builtins.tuple"?[...t].every(i=>!e[0]?.test||e[0].test(i)):n==="builtins.dict"?Object.entries(t).every(([i,s])=>(!e[0]?.test||e[0].test(i))&&(!e[1]?.test||e[1].test(s))):!1}function $u(r,e){if(r===null)return null;if(typeof r!="string"&&T(e,"must be string or null"),r==="")return new Map;let t=new Map;for(let n of r.split(",")){let i=n.trim();/^[A-Za-z_][A-Za-z0-9_]*\[\]$/.test(i)&&T(e,`invalid cardinality item '${n}'`);let s=i.match(/^([A-Za-z_][A-Za-z0-9_]*|\*)(?:\[(?:(\d+)|(?:(\d*):(\d*)))\])?$/);s||T(e,`invalid cardinality item '${n}'`);let[,a,o,l,u]=s;t.has(a)&&T(e,`duplicate tag '${a}'`);let c=0,d=1/0;i.includes("[")&&(i.includes(":")?(c=l?Number(l):0,d=u?Number(u):1/0):c=d=Number(o)),d<c&&T(e,`maximum ${d} is below minimum ${c}`),t.set(a,{min:c,max:d})}return t.has("*")&&t.size>1&&T(e,"wildcard '*' cannot be combined with named tags"),t}function Fu(r,e){if(r===null)return null;typeof r!="string"&&T(e,"must be string or null");let t=new Set;for(let n of r.split(",")){let i=n.trim();i&&((!Mu.test(i)||t.has(i))&&T(e,`invalid or duplicate parent '${n}'`),t.add(i))}return t}function nm(r,e,t){if(r===null)return null;ot(r,["parameters","accepts_var_keyword","accepts_var_positional"],[],e);let n=r.parameters??[];Array.isArray(n)||T(e,"parameters must be an array"),r={parameters:n,accepts_var_keyword:n.some(l=>l.kind==="var_keyword"),accepts_var_positional:n.some(l=>l.kind==="var_positional"),...r},(!Array.isArray(r.parameters)||typeof r.accepts_var_keyword!="boolean"||typeof r.accepts_var_positional!="boolean")&&T(e,"invalid signature descriptor");let i=new Set,s=!1,a=!1,o=r.parameters.map((l,u)=>{let c=`${e}.parameters[${u}]`;return ot(l,["name","kind","role","annotation","has_default","default"],["name","kind","role","annotation","has_default"],c),(typeof l.name!="string"||!Mu.test(l.name)||i.has(l.name))&&T(c,"invalid or duplicate parameter name"),i.add(l.name),(!Kh.has(l.kind)||!Qh.has(l.role)||typeof l.has_default!="boolean")&&T(c,"invalid kind, role, or has_default"),l.has_default!==Object.hasOwn(l,"default")&&T(c,"default presence must equal has_default"),l.has_default&&Qt(l.default,`${c}.default`),s||=l.kind==="var_keyword",a||=l.kind==="var_positional",{...l,annotation:Jt(l.annotation,`${c}.annotation`,!1,t)}});return(s!==r.accepts_var_keyword||a!==r.accepts_var_positional)&&T(e,"variadic summary flags do not match parameters"),{...r,parameters:o}}function Ru(r,e,t,n){let i=["doc","sub_tags","parent_tags","inherits_from","ns","attributes",...t?["node_label","collection_key"]:[],"_meta"];ot(r,i,[],e),r={...Object.fromEntries(i.map(s=>[s,null])),...r};for(let s of["doc","inherits_from","ns",...t?["node_label","collection_key"]:[]])r[s]!==null&&typeof r[s]!="string"&&T(e,`${s} must be string or null`);return r._meta!==null&&(Kt(r._meta)||T(e,"_meta must be object or null"),Qt(r._meta,`${e}._meta`)),$u(r.sub_tags,`${e}.sub_tags`),Fu(r.parent_tags,`${e}.parent_tags`),{...r,attributes:nm(r.attributes,`${e}.attributes`,n)}}function Lu(r){return r?r.split(",").map(e=>e.trim()).filter(Boolean):[]}function Pu(r,e){let t={...e};for(let[n,i]of Object.entries(r))n==="inherits_from"||n.startsWith("_")||t[n]||(t[n]=i);return t._meta={...r._meta||{},...e._meta||{}},t}function ju(r){let e={...r};return e._subSpec=Object.hasOwn(e,"sub_tags")?$u(e.sub_tags,"resolved.sub_tags"):null,e._parentSpec=Object.hasOwn(e,"parent_tags")?Fu(e.parent_tags,"resolved.parent_tags"):null,e}function Uu(r,e,t,n){if(t.get(r)===1&&T(n,`inheritance cycle at '${r}'`),t.get(r)===2)return e[r];let i=e[r];i||T(n,`unknown abstract '${r}'`),t.set(r,1);let s={...i};for(let a of Lu(i.inherits_from))s=Pu(Uu(a,e,t,n),s);return s=ju(s),t.set(r,2),e[r]=s,s}function Ua({abstracts:r={},elements:e={}}){let t={...r},n=new Map;for(let s of Object.keys(t))Uu(s,t,n,`abstracts.${s}.inherits_from`);let i={};for(let[s,a]of Object.entries(e)){let o={...a};for(let l of Lu(a.inherits_from)){let u=t[l];u||T(`elements.${s}.inherits_from`,`unknown abstract '${l}'`),o=Pu(u,o)}i[s]=ju(o)}return{abstracts:t,elements:i}}function qa(r){ot(r,["document_format","grammar","abstracts","elements","custom_types"],["document_format","grammar","abstracts","elements"],"grammar document"),ot(r.document_format,["name","version"],["name","version"],"document_format"),(r.document_format.name!=="builder_grammar"||!["1.1","1.2"].includes(r.document_format.version))&&T("document_format","expected builder_grammar version 1.1 or 1.2"),ot(r.grammar,["name","version","title","description"],["name","version","title","description"],"grammar"),(typeof r.grammar.name!="string"||!r.grammar.name)&&T("grammar.name","must be non-empty string");for(let i of["version","title","description"])r.grammar[i]!==null&&typeof r.grammar[i]!="string"&&T(`grammar.${i}`,"must be string or null");(!Kt(r.abstracts)||!Kt(r.elements))&&T("grammar document","abstracts/elements must be objects"),Object.hasOwn(r,"custom_types")&&r.document_format.version!=="1.2"&&T("custom_types","requires version 1.2");let e=Vr.fromJSON(r.custom_types??{}),t={};for(let[i,s]of Object.entries(r.abstracts))(!i||i.startsWith("_"))&&T("abstracts",`invalid public name '${i}'`),t[i]=Ru(s,`abstracts.${i}`,!1,e);let n={};for(let[i,s]of Object.entries(r.elements))(!i||i.startsWith("_"))&&T("elements",`invalid public name '${i}'`),n[i]=Ru(s,`elements.${i}`,!0,e);return{grammar:structuredClone(r.grammar),abstracts:t,elements:n}}function qu(r,e,t,n){let i=e.attributes;if(!i)return;let s={...n};t!=null&&(s.node_value=t);let a=new Set(i.parameters.filter(u=>u.role==="attribute").map(u=>u.name)),o=new Set(["node_label","node_position","nodeId","target_id","datapath","iterate","store","_tag","_meta","ns"]);if(!i.accepts_var_keyword)for(let u of Object.keys(n))!a.has(u)&&!o.has(u)&&T(r,`unknown attribute '${u}'`);let l=e._meta?.component?i.parameters.find(u=>u.role!=="framework"&&["positional_only","positional_or_keyword"].includes(u.kind))?.name:null;for(let u of i.parameters){if(u.name===l||u.role==="framework"||u.kind.startsWith("var_"))continue;let c=Object.hasOwn(s,u.name);!c&&!u.has_default&&T(r,`missing required ${u.role} '${u.name}'`),c&&u.annotation!==null&&(!u.annotation.test||!u.annotation.test(s[u.name]))&&T(r,`invalid value for ${u.role} '${u.name}'`)}}var Vr=class r{#e=new Map;#t=new Map;register(e,t,n){let i=new Map([[String,"str"],[Number,"float"],["string","str"],["integer","int"],["number","float"]]),s=i.has(t)?{kind:"type",module:"builtins",name:i.get(t)}:t;return this.#r(e,{kind:"annotated",base:s,metadata:[n]})}#r(e,t){(typeof e!="string"||!/^[A-Za-z][A-Za-z0-9_]*$/.test(e)||e in this||["to_dict","from_dict"].includes(e)||im.has(e))&&T("custom_types",`invalid, reserved or duplicate name '${e}'`),ot(t,["kind","base","metadata"],["kind","base","metadata"],`custom_types.${e}`),(t.kind!=="annotated"||!Array.isArray(t.metadata)||t.metadata.length!==1||!["regex","range"].includes(t.metadata[0]?.kind))&&T(`custom_types.${e}`,"requires an annotated base with one Regex or Range validator");let n=t.metadata[0].kind==="regex"?["str"]:["int","float"];(t.base?.kind!=="type"||t.base.module!=="builtins"||!n.includes(t.base.name))&&T(`custom_types.${e}`,"portable Regex requires str; portable Range requires int or float"),Qt(t,`custom_types.${e}`);let i=structuredClone(t),s=Jt(i,`custom_types.${e}`),a=Object.freeze({kind:"custom",name:e});return Object.defineProperty(this,e,{value:a,enumerable:!0}),this.#e.set(e,i),this.#t.set(e,{...a,inputConstraint:!0,test:s.test}),a}resolve(e,t="custom_types"){return this.#t.has(e)||T(t,`unknown custom type '${e}'`),{...this.#t.get(e)}}validate(e,t){return this.resolve(e).test(t)||T(`custom_types.${e}`,"invalid input value"),!0}toJSON(){return structuredClone(Object.fromEntries(this.#e))}static fromJSON(e){Kt(e)||T("custom_types","must be an object");let t=new r;for(let[n,i]of Object.entries(e))t.#r(n,i);return t}},im=new Set("False None True and as assert async await break class continue def del elif else except finally for from global if import in is lambda nonlocal not or pass raise return try while with yield".split(" "));function Vu(r,e,t,n){let i=e?.attributes;if(i)for(let s of i.parameters){if(!s.annotation?.inputConstraint||s.role==="framework"||["var_keyword","var_positional"].includes(s.kind))continue;let a=s.role==="value"?t:n[s.name];a!==void 0&&(s.annotation.test(a)||T(r,`invalid input for '${s.name}' (custom type)`))}}function zu(r,e,t=[]){if(e===null)return structuredClone(r);if(t.length===2&&t[0]==="custom_types"&&r!==void 0){if(!Va(r,e))throw new TypeError(`conflicting custom type '${t[1]}'`);return structuredClone(r)}if(t.length===2&&["abstracts","elements"].includes(t[0]))return structuredClone(e);if(ht(r)&&ht(e)){let n=structuredClone(r);for(let[i,s]of Object.entries(e))s!==null&&Object.defineProperty(n,i,{value:zu(n[i],s,[...t,i]),enumerable:!0,writable:!0,configurable:!0});return n}return structuredClone(e)}function Va(r,e){return Object.is(r,e)?!0:Array.isArray(r)&&Array.isArray(e)?r.length===e.length&&r.every((t,n)=>Va(t,e[n])):ht(r)&&ht(e)?Object.keys(r).length===Object.keys(e).length&&Object.keys(r).every(t=>Object.hasOwn(e,t)&&Va(r[t],e[t])):!1}function ht(r){return r!==null&&typeof r=="object"&&!Array.isArray(r)&&Object.getPrototypeOf(r)===Object.prototype}function za(r){if(!(r===null||typeof r=="string"||typeof r=="boolean")&&!(typeof r=="number"&&Number.isFinite(r))){if(Array.isArray(r)){r.forEach(za);return}if(ht(r)){Object.values(r).forEach(za);return}throw new TypeError("collection must contain only finite JSON values")}}var mt=class r{#e;constructor(e){za(e);let t=["document_format","grammar","abstracts","elements"];if(!ht(e)||Object.keys(e).some(i=>![...t,"custom_types"].includes(i))||t.some(i=>!Object.hasOwn(e,i)))throw new TypeError("collection requires document_format, grammar, abstracts and elements");let n=e.document_format;if(!ht(n)||Object.keys(n).length!==2||n.name!=="builder_grammar"||!["1.1","1.2"].includes(n.version))throw new TypeError("expected builder_grammar version 1.1 or 1.2");for(let i of["grammar","abstracts","elements"])if(!ht(e[i]))throw new TypeError(`${i} must be an object`);if(Object.hasOwn(e,"custom_types")&&(n.version!=="1.2"||!ht(e.custom_types)))throw new TypeError("custom_types requires an object catalog and version 1.2");this.#e=structuredClone(e)}update(e){let t=new r(e),n=zu(this.#e,t.#e);return(this.#e.document_format.version==="1.2"||t.#e.document_format.version==="1.2")&&(n.document_format.version="1.2"),this.#e=n,this}toDocument(){return structuredClone(this.#e)}};var er=class{static renderType="string";static mode=null;constructor(e){this._builder=e,this.renders=new Map([[e,this]])}get builder(){return this._builder}get renderType(){return this.constructor.renderType}get mode(){return this.constructor.mode}addRender(e,t){this.renders.set(e,t)}getRender(e){let t=this.renders.get(e);if(t!==void 0)return t;let n=e.getRenderer();return this.renders.set(e,n),n}render(e,t={}){let n=e.builder,[i,s]=n.runtimeValues(e);if(e._getMeta("data_element"))return null;if(e._getMeta("component"))return this._renderComponent(e,s,t);let a=this.getRender(n),o;return[o,s]=a._handleMeta(e,s),e._getMeta("subbuilder")||(s=a.adaptAttrs(s)),e.value instanceof N&&(i=this.renderChildren(e.value,t)),a.renderedItem(e,i,s,{tag:o,...t})}renderChildren(e,t={}){let n=[];for(let i of e.getNodes()){let s=this.render(i,t);s!==null&&(Array.isArray(s)?n.push(...s):n.push(s))}return n}_renderComponent(e,t,n){let[i,s,a,o]=this._expansionInputs(e,t);if(!Object.hasOwn(e.getAttr(),"iterate"))return this._expandBlock(e,i,a,o,n);if(s==null)return[];if(!(s instanceof V))throw new TypeError(`component '${e.nodeTag}': iterate must resolve to a Bag, got ${s?.constructor?.name||typeof s}`);return s.getNodes().map(l=>this._expandBlock(e,i,a,{node_label:l.label},n))}_expansionInputs(e,t){let n=e.builder,i=n.componentMethod(e.nodeTag),s=i&&n[i];if(typeof s!="function")throw new Error(`component '${e.nodeTag}' has no implementation`);let a=t.iterate;delete t.iterate,delete t.store;let o=e.getAttr("iterate")||e.getAttr("store");o!=null?(e.pointerType(o)&&(o=o.slice(1)),o.startsWith(".")&&(o=e._composeRelativeDatapath(o,o))):o=null;for(let l of Object.keys(t)){let u=e.getAttr(l);e.pointerType(u)==="^"&&(t[l]=`^${e.absDatapath(u)}`)}return[s,a,o,t]}_expandBlock(e,t,n,i,s){let a=e.builder._expansionRoot(n);t.call(e.builder,$n(a),i);let o=a.getNodes();if(o.length!==1)throw new Error(`component '${e.nodeTag}' must build a tree, not a forest: ${o.length} root nodes`);let l={...s,depthOffset:this._nodeDepth(e,s.depthOffset||0)};return this.render(o[0],l)}preprocess(e){return e}renderedItem(e,t,n,i){throw new Error(`${this.constructor.name} does not implement renderedItem`)}_handleMeta(e,t){let[n,i]=e._getMeta("render_tag,render_attributes"),s=Mn(e.nodeTag,{renderTag:n,ns:e.getAttr("ns"),dialectName:e.builder?.constructor._name});if(!s)throw new Error(`node ${e.label} has no tag to render (no render_tag, no node_tag)`);return i&&(t={...t,...i}),[s,t]}adaptAttrs(e){return e}adapt(e){let t=`${this.builder.constructor._name}_`;return e.startsWith(t)?e.slice(t.length):e}finalize(e,t=null,n={}){let i=this._composeStringFragments(e);if(t==null)return i;if(typeof t=="string")throw new TypeError("string render targets require filesystem support, which is unavailable in the portable renderer; pass a callable or writable target instead");if(typeof t.full=="function"&&typeof t.write!="function")return t.full(i),null;if(typeof t.write=="function")return t.write(i),null;if(typeof t=="function")return t(i),null;throw new TypeError("render target must be writable (.write), callable, or expose .full")}_composeStringFragments(e){if(!Array.isArray(e))return e;if(e.some(t=>typeof t!="string"))throw new TypeError("String composition requires string fragments; object renderers must define their own composition");return e.join("")}_escapeText(e){return String(e).replaceAll("&","&").replaceAll("<","<").replaceAll(">",">")}_escapeAttr(e){return this._escapeText(e).replaceAll('"',""")}_nodeDepth(e,t=0){let i=((e.fullpath||"").match(/\./g)||[]).length;return Math.max(i-1,0)+t}};var tr=class extends er{static mode="xml";renderedItem(e,t,n,{tag:i,pretty:s=!1,depthOffset:a=0}={}){let o=this._formatAttrs(n),l=s?" ".repeat(this._nodeDepth(e,a)):"",u=s?`
|
|
23
|
+
`:"";if(Array.isArray(t)){let c=this._composeStringFragments(t);return`${l}<${i}${o}>${u}${c}${l}</${i}>${u}`}return t==null?`${l}<${i}${o}></${i}>${u}`:`${l}<${i}${o}>${this._escapeText(t)}</${i}>${u}`}finalize(e,t=null,{docHeader:n=null}={}){let i=this._composeStringFragments(e);return n===!0?i=`<?xml version='1.0' encoding='UTF-8'?>${i}`:typeof n=="string"&&(i=n+i),super.finalize(i,t)}_formatAttrs(e){return Object.entries(e||{}).map(([t,n])=>` ${t.startsWith("xmlns_")?`xmlns:${t.slice(6)}`:t}="${this._escapeAttr(n)}"`).join("")}};var Hu={document_format:{name:"builder_grammar",version:"1.1"},grammar:{name:"base",version:null,title:null,description:null},abstracts:{},elements:{dataSetter:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"destination",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"value",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1},{name:"attr",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataFormula:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"destination",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"func",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"collections.abc",name:"Callable"}]},has_default:!1},{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataController:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"func",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"collections.abc",name:"Callable"}]},has_default:!1},{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}}}};function Wu(r){let e=[];for(;r&&r!==Function.prototype;)e.push(r),r=Object.getPrototypeOf(r);return e.reverse()}function am(r){let e=Object.create(null),t=(n,i)=>{let s=n.toLowerCase(),a=e[s];if(a!==void 0&&a!==i)throw new Error(`container '${n}' is already tied to implementation method '${a}' (cannot rebind to '${i}')`);e[s]=i};for(let n of Wu(r))if(Object.hasOwn(n,"containers"))for(let i of n.containers||[])t(i,i);return e}function Fn(r){let e=Object.create(null);for(let t of Object.keys(r)){let n=t.toLowerCase();if(Object.hasOwn(e,n))throw new Error(`element declaration '${t}' has a case-insensitive collision with '${e[n]}'`);e[n]=t}return e}var Ln="_root_",Pn="_root_",Gu=new Set(["destination","func","value","_on_start"]),Se=class r{static _sourceClass=N;static registerBuilder(e){if(typeof e!="function"||!(e.prototype instanceof r))throw new TypeError("registerBuilder requires a BuilderBase subclass");let t=e._name;if(typeof t!="string"||!t)throw new TypeError("registered builders require a non-empty static _name");let n=r._registry.get(t);if(n&&n!==e)throw new Error(`Builder name '${t}' is already registered to ${n.name}; cannot register ${e.name}`);return r._registry.set(t,e),e}static getBuilderClass(e){let t=r._registry.get(e);if(!t)throw new Error(`No builder registered with name '${e}'`);return t}constructor(e=null){this.name=e||this.constructor._name,this._dataroot=new V,this._dataroot.setBackref(),this._dataroot.setItem(Pn,new V),this.data=this._dataroot.getItem(Pn),this._defaultTargets=new Map,this.materialized=Object.create(null),this._collection=null,this._schemaOverride=null,this._tagNamesOverride=null,this._componentMap=null,this._targetSerial=0,this._subbuilders=new Map,this._sourceHandles=new WeakMap;let t=this.constructor._sourceClass;this._sourceroot=new t(null,this),this._sourceroot.setBackref(),this._sourceroot.setItem(Ln,new t(null,this)),this.source=this._sourceroot.getItem(Ln)}wrapSource(e){if(e=me(e),!(e instanceof N)&&!(e instanceof Ce))throw new TypeError("wrapSource requires a SourceBag or SourceBagNode");let t=this._sourceHandles.get(e);return t||(t=Bu(this,e),this._sourceHandles.set(e,t)),t}get root(){return this.wrapSource(this.source)}getSubbuilder(e){if(typeof e!="string"||!e||e.includes(":"))throw new Error(`unsupported subbuilder reference '${e}'`);let t=this._subbuilders.get(e);if(!t){let n=r.getBuilderClass(e);t=new n,this._subbuilders.set(e,t)}return t._dataroot=this._dataroot,t.data=this.data,t}_resolveSubbuilderReference(e,t,n){if(typeof e!="string"||!e)throw new Error(`'${n}': subbuilder declaration must be a non-empty string`);if(e.includes(":"))throw new Error(`'${n}': runtime subbuilder reference '${e}' is unsupported`);return this.getSubbuilder(e)}static defineGrammar(e){let t=this._classCollection,n=t?new mt(t.toDocument()).update(e):new mt(e),i=qa(n.toDocument()),s=Ua(i),a=Fn(s.elements);this._classCollection=n,this._classSchema=s.elements,this._abstracts=s.abstracts,this._tagNames=a}static{this.defineGrammar(Hu)}get _containers(){return am(this.constructor)}containerMethod(e){return this._containers[e.toLowerCase()]||null}componentMethod(e){return this._componentMap?.[e.toLowerCase()]||null}get schema(){return this._schemaOverride||this.constructor._classSchema||{}}get schemaTagNames(){return this._schemaOverride?this._tagNamesOverride??=Fn(this.schema):this.constructor._tagNames??=Fn(this.schema)}schemaTag(e){let t=e.toLowerCase(),n=this.schemaTagNames[t];if(n)return n;let i=`${this.constructor._name}_`;return t.startsWith(i)&&this.schemaTagNames[t.slice(i.length)]||null}loadGrammar(e,{replace:t=!1}={}){let n=this._collection||this.constructor._classCollection,i=t?new mt(e):new mt(n.toDocument()).update(e),s=qa(i.toDocument()),a=Ua(s),o=Fn(a.elements);return this._collection=i,this._schemaOverride=a.elements,this._tagNamesOverride=o,this}validateCustomTypes(e){let t=e.parentBag?.parentNode?.builder||e.parentBag?._builder,n=t&&t!==this&&t.schema[e.nodeTag]?._meta?.subbuilder?t:this;Vu(e.nodeTag,n.schema[e.nodeTag],e.value,e.getAttr()||{})}validateNodeValues(e,t,n={}){let i=this.schemaTag(e);if(!i)throw new Error(`unknown element '${e}'`);return qu(i,this.schema[i],t,n),!0}validateNode(e,{value:t,attrs:n,childTags:i}={}){if(!e||typeof e.nodeTag!="string")throw new TypeError("validateNode requires a source node");let s=t!==void 0?t:e.value instanceof N?null:e.value;this.validateNodeValues(e.nodeTag,s,n||e.getAttr?.()||{});let a=this.schema[this.schemaTag(e.nodeTag)],o=i||(e.value instanceof N?e.value.getNodes().map(l=>l.nodeTag):null);return o&&this._validateChildren(e.nodeTag,a,o,!1),!0}validateChildren(e,t,{includeMinimum:n=!1}={}){let i=this.schemaTag(e);if(!i)throw new Error(`unknown element '${e}'`);if(!Array.isArray(t)||t.some(s=>typeof s!="string"))throw new TypeError("childTags must be an array of strings");return this._validateChildren(i,this.schema[i],t,n)}validateParent(e,t=null){let n=this.schemaTag(e);if(!n)throw new Error(`unknown element '${e}'`);let i=this.schema[n];if(!this._countsForGrammar(i))return!0;let s=i._parentSpec;if(s==null||s.has("*"))return!0;if(t===null)throw new Error(`'${n}' requires a declared parent`);let a=this.schemaTag(t);if(!a)throw new Error(`unknown parent element '${t}'`);return this._validateParent(n,i,a),!0}bagCall(e,t,n,i){return this.setChild(e,t,n,i)}commandOnNode(e,t,n,i){if(e=me(e),e.value instanceof N)return this.setChild(e.value,t,n,i);let s=e.value,a=new e.parentBag.constructor(null,e.builder||this),o=this.setChild(a,t,n,i,e);return this.promoteNodeValue(e,s,a),o}promoteNodeValue(e,t,n){e.setValue(n)}setChild(e,t,n,i,s=null){let a={...i},o=this.schema[t];if(!o)throw new Error(`unknown element '${t}'`);this.validateNodeValues(t,n,a);let l=o._meta?.subbuilder,c=(l==null?null:this._resolveSubbuilderReference(l,a,t))||this,d=n instanceof N?n._builderBindingPlan(c):null,f=s?.rootBuilder||e.root._builder||this;if(a.nodeId!=null&&f.source.getNodeByAttr("nodeId",a.nodeId))throw new Error(`Duplicate nodeId '${a.nodeId}'`);n instanceof N&&this._validateChildren(t,o,n.getNodes().map(v=>v.nodeTag),!1);let p=s||e.parentNode,h=p?.nodeTag?this.schema[p.nodeTag]:null;if(h&&!p._getMeta("subbuilder")&&this._countsForGrammar(o))this._validateParent(t,o,p.nodeTag),this._validateChildren(p.nodeTag,h,[...e.getNodes().map(v=>v.nodeTag),t],!1);else if(!h&&!p?._getMeta("subbuilder")&&o._parentSpec!=null&&this._countsForGrammar(o))throw new Error(`'${t}' requires a declared parent`);o._meta&&!("_meta"in a)&&(a._meta=o._meta),o.ns&&!("ns"in a)&&(a.ns=o.ns);let m=a.node_position;delete a.node_position;let g=a.node_label;delete a.node_label;let b;if(h?.collection_key){if(g!=null)throw new Error(`'${t}': node_label is not allowed in a collection`);b=this._collectionLabel(h.collection_key,t,a)}else{let v=h?._subSpec?.get(t);if(v&&v.max===1){if(g!=null)throw new Error(`'${t}': node_label is not allowed on a singleton`);b=t}else b=g||o.node_label||this._autoLabel(e,t)}if(e.node(b)!=null)throw new Error(`duplicate node label '${b}'`);return e._setBuilderItem(c,d,b,n,a,m||">",!1,!0,null,!1,!0,null,t)}_countsForGrammar(e){let t=e?._meta||{};return!(t.data_element||t.subbuilder||t.component)}_validateParent(e,t,n){let i=t._parentSpec;if(!(i==null||i.has("*")||!this._countsForGrammar(t))&&!i.has(n))throw new Error(`'${e}' not allowed as child of '${n}'`)}_validateChildren(e,t,n,i){let s=t._subSpec;if(s==null||s.has("*")||t._meta?.subbuilder)return[];let a=new Map;for(let o of n){let l=this.schema[o];if(l&&!this._countsForGrammar(l))continue;let u=s.get(o);if(!u)throw new Error(`'${o}' not allowed as child of '${e}'`);let c=(a.get(o)||0)+1;if(a.set(o,c),c>u.max)throw new Error(`too many '${o}' in '${e}'`)}return i?[...s].filter(([o,l])=>(a.get(o)||0)<l.min).map(([o])=>o):[]}_collectionLabel(e,t,n){let i=s=>{if(n[s]===null||n[s]===void 0)throw new Error(`'${t}': collection key needs attribute '${s}'`);return String(n[s])};return e.includes("${")?e.replace(/\$\{([^}]+)\}/g,(s,a)=>i(a)):i(e)}validateSource(){let e=[],t=(n,i="")=>{for(let s of n.getNodes()){let a=i?`${i}.${s.label}`:s.label,o=s.builder;o.validateCustomTypes(s);let l=o.schema[s.nodeTag];if(l&&!s._getMeta("data_element,subbuilder,component").some(Boolean)){let u=s.value instanceof N?s.value.getNodes().map(d=>d.nodeTag):[],c=o._validateChildren(s.nodeTag,l,u,!0);c.length&&e.push([a,c])}s.value instanceof N&&t(s.value,a)}};return t(this.source),e}_autoLabel(e,t){let n=0;for(;e.node(`${t}_${n}`)!==null&&e.node(`${t}_${n}`)!==void 0;)n+=1;return`${t}_${n}`}nodeById(e){let t=this.source.getNodeByAttr("nodeId",e);if(t==null)throw new Error(`nodeId not found: ${e}`);return t.builder.wrapSource(t)}runtimeValues(e){e.builder.validateCustomTypes(e);let t=new Map,n={},i=e.runtimeToEvaluate(),s=new Set(i.keys()),a=new Map([...Object.entries(e.getAttr()),...e.fixedAttrItems()]);for(let[c,d]of[...i])if(!(typeof c!="string"||!Y(d)))for(let f of Qe(e,d))i.has(f)||i.set(f,a.get(f));let o=e._getMeta("data_element");for(let[c,d]of i){if(d instanceof ie){t.set(c,d.resolve());continue}let f=typeof c=="string"?Y(d)?.pointer??d:d;if(!e.pointerType(f)){t.set(c,typeof c=="string"&&typeof d=="string"&&d.startsWith("==")?null:d);continue}let p=e.absDatapath(f);if(t.set(c,this.data.getItem(p)),!o&&!p.includes("?")&&c===qr){let h=this.data.getNode(p);h&&Object.assign(n,h.getAttr("_wdg"))}}let l=Eo(i,t,(c,d,f,p)=>this.evaluatePointerExpression(e,c,d,f,p)),u=l.get(qr);l.delete(qr);for(let c of l.keys())s.has(c)||l.delete(c);return[u,{...Object.fromEntries(l),...n}]}evaluatePointerExpression(e,t,n,i,s){return null}targetId(e){if(e._targetId)return e._targetId;let t=e.rootBuilder;return e.parentBag.root!==t.source.root?null:(t._targetSerial+=1,e._targetId=`n${t._targetSerial}`,e._targetId)}get dataLogic(){if(!this._dataLogic){let e=this._buildDataLogic();this._dataLogic=Array.isArray(e)?e:[e]}return this._dataLogic}_buildDataLogic(){return this}_resolveLogicFunc(e){if(typeof e=="function")return e;if(typeof e!="string")throw new Error("data-element func must be a name or a function");for(let t of this.dataLogic){let i=(typeof t=="function"?t:t.constructor)[e];if(typeof i=="function")return i}throw new Error(`data-element func '${e}' not found on any data_logic source`)}_bindings(e){let[,t]=this.runtimeValues(e),n={};for(let[i,s]of Object.entries(t))Gu.has(i)||(n[i]=s);return n}computeLogic(e){for(let t of e)this._computeNode(t)}_computeNode(e){let t=e.getAttr()||{};if(e.nodeTag==="dataSetter"){let n={};for(let[i,s]of Object.entries(t))i!=="destination"&&i!=="value"&&!i.startsWith("_")&&(n[i]=s);e.setRelativeData(t.destination,t.value,{attributes:Object.keys(n).length?n:null})}else if(e.nodeTag==="dataFormula"){let n=this._resolveLogicFunc(t.func);e.setRelativeData(t.destination,n(this._bindings(e)))}else e.nodeTag==="dataController"&&this._resolveLogicFunc(t.func)(e,this._bindings(e))}_dataElementNodes(){let e=[],t=n=>{for(let i of n.getNodes())i._getMeta("data_element")&&e.push(i),i.value instanceof N&&t(i.value)};return t(this.source),e}setup(e){}main(e){throw new Error(`${this.constructor.name}.main() not implemented: a bare builder is grammar, not a renderable page`)}_resolveComponents(){let e={};for(let o of Wu(this.constructor))if(Object.hasOwn(o,"components"))for(let l of o.components||[])e[l]=l;if(!Object.keys(e).length)return;let t={...this.schema},n={};for(let[o,l]of Object.entries(e))t[o]={sub_tags:"",_meta:{component:!0}},n[o.toLowerCase()]=l;let i=Fn(t),s=this._collection||this.constructor._classCollection,a=s.toDocument();a.abstracts={},a.elements=Object.fromEntries(Object.keys(e).map(o=>[o,t[o]])),this._collection=new mt(s.toDocument()).update(a),this._schemaOverride=t,this._componentMap=n,this._tagNamesOverride=i}_expansionRoot(e=null){let t=this.constructor._sourceClass,n=new t(null,this);return n.setBackref(),n.setItem(Ln,new t(null,this),e?{datapath:e}:null),n.getItem(Ln)}create(){this.setup(this.data),this._resolveComponents(),this.main(this.root),this.computeLogic(this._dataElementNodes())}get renderer_xml(){return new tr(this)}getRenderer(e=null){e??=this.constructor._defaultRenderMode;let t=this[`renderer_${e}`];if(!t)throw new Error(`${this.constructor.name} does not expose renderer_${e}`);return t}materialize(e=null,t={}){e??=this.constructor._defaultRenderMode;let n=this.getRenderer(e),i=n.renderChildren(n.preprocess(this.source),t);return this.materialized[e]=i,i}setRenderTarget(e,t=null){t??=this.constructor._defaultRenderMode,this._defaultTargets.set(t,e)}render({mode:e=null,target:t=null,...n}={}){e??=this.constructor._defaultRenderMode;let i=this.getRenderer(e);if(t===!1&&i.renderType!=="string")throw new TypeError("target=false is not valid for an object renderer");let s=t===!1?null:t||this._defaultTargets.get(i.mode)||null,a={...s?.renderOpts,...n};return i.finalize(this.materialize(e,a),s,a)}};Se._registry=new Map;var om=new Set(["short","medium","long","full"]),lm=/('(?:[^']|'')*'|[a-zA-Z]+|[^a-zA-Z']+)/g;function um(r,e){if(!(r instanceof Date))throw new TypeError("Temporal formats require a typed Date value");if(!Number.isFinite(r.getTime()))throw new RangeError("Invalid date");let t=e||ne(r).split("::").at(-1);if(!["D","H","DH","DHZ"].includes(t))throw new RangeError(`Unsupported temporal dtype: ${t}`);return t}function cm(r,e,t,n){let i=e.match(lm)||[];if(i.join("")!==e)throw new RangeError("Unclosed format literal");let s=(c,d=2)=>String(c).padStart(d,"0"),a=c=>new Intl.DateTimeFormat(t,{timeZone:"UTC",...c}).format(r),u={...n==="H"?{}:{y:()=>String(r.getUTCFullYear()),yy:()=>s(r.getUTCFullYear()%100),yyyy:()=>s(r.getUTCFullYear(),4),M:()=>String(r.getUTCMonth()+1),MM:()=>s(r.getUTCMonth()+1),MMM:()=>a({month:"short"}),MMMM:()=>a({month:"long"}),d:()=>String(r.getUTCDate()),dd:()=>s(r.getUTCDate()),EEE:()=>a({weekday:"short"}),EEEE:()=>a({weekday:"long"})},...n==="D"?{}:{H:()=>String(r.getUTCHours()),HH:()=>s(r.getUTCHours()),h:()=>String(r.getUTCHours()%12||12),hh:()=>s(r.getUTCHours()%12||12),m:()=>String(r.getUTCMinutes()),mm:()=>s(r.getUTCMinutes()),s:()=>String(r.getUTCSeconds()),ss:()=>s(r.getUTCSeconds()),a:()=>new Intl.DateTimeFormat(t,{hour:"numeric",hour12:!0,timeZone:"UTC"}).formatToParts(r).find(c=>c.type==="dayPeriod").value}};return i.map(c=>{if(c.startsWith("'"))return c==="''"?"'":c.slice(1,-1).replaceAll("''","'");if(!/^[a-zA-Z]/.test(c))return c;if(!u[c])throw new RangeError(`Unsupported date format token: ${c}`);return u[c]()}).join("")}function Xu(r,{format:e,mask:t,locale:n,dtype:i,places:s}={}){let a=r==null?"":String(r);if(r!=null&&r!==""&&(e!=null&&e!==""||s!=null))if(typeof r=="number"||ve(r))a=fm(r,{format:e,locale:n,places:s});else{let o=um(r,i);if(om.has(e)){let l={timeZone:"UTC"};o!=="H"&&(l.dateStyle=e),o!=="D"&&(l.timeStyle=e),a=new Intl.DateTimeFormat(n||void 0,l).format(r)}else a=cm(r,String(e),n||void 0,o)}return t==null?a:String(t).replaceAll("%s",()=>a)}function dm({format:r="decimal",places:e}={}){let t={maximumFractionDigits:20};if(!r||r==="decimal")t.style="decimal";else if(r==="percent")t.style="percent";else if(r==="scientific")t.notation="scientific";else{let n=/^(0|#,##0)(?:\.(0*)(#*))?$/.exec(r);if(!n||r.includes(".")&&!n[2]&&!n[3])throw new RangeError(`Unsupported number format: ${r}`);t.useGrouping=n[1].includes(","),t.minimumFractionDigits=(n[2]||"").length,t.maximumFractionDigits=(n[2]||"").length+(n[3]||"").length}if(e!=null&&e!==""){let n=Number(e);if(!Number.isInteger(n)||n<0||n>20)throw new RangeError("places must be an integer from 0 to 20");t.minimumFractionDigits=n,t.maximumFractionDigits=n}return t}function fm(r,e={}){if(typeof r!="number"&&!ve(r))throw new TypeError("Number formatting requires a Number or Decimal");if(!Number.isFinite(Number(r)))throw new RangeError("Number must be finite");let t=new Intl.NumberFormat(e.locale||void 0,dm(e));if(ve(r)&&new Intl.NumberFormat("en",{useGrouping:!1}).format("9007199254740993")!=="9007199254740993")throw new Error("This browser cannot format Decimal values without precision loss");return t.format(ve(r)?r.toString():r)}var pm=new Set(["style","script"]),hm=new Set(["allowfullscreen","async","autofocus","autoplay","checked","controls","default","defer","disabled","formnovalidate","inert","ismap","itemscope","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"]),Yu=new Set(["width","height","top","left","right","bottom","padding","margin","border","position","display","overflow","float","clear","resize","z_index","min_width","min_height","max_width","max_height","color","background","font","text","line_height","white_space","vertical_align","flex","gap","row_gap","column_gap","grid","align_content","justify_content","align_items","justify_items","visibility","opacity","cursor"]),jn=new Set(["rounded","gradient","shadow","transform","transition","zoom","filter"]),Zu=r=>r===!0?"true":r===!1?"false":String(r),ts=r=>typeof r=="number"&&Number.isFinite(r)?`${r}px`:String(r);function mm(r){if(Yu.has(r))return!0;for(let e of Yu)if(r.startsWith(`${e}_`))return!0;return!1}function gm(r){let e=new Map;if(!r)return e;let t=[],n=0,i=null,s=!1,a=!1,o=0,l=String(r);for(let u=0;u<l.length;u+=1){let c=l[u],d=l[u+1];if(a){c==="*"&&d==="/"&&(a=!1,u+=1);continue}if(s){s=!1;continue}if(c==="\\"){s=!0;continue}if(i){c===i&&(i=null);continue}c==='"'||c==="'"?i=c:c==="/"&&d==="*"?(a=!0,u+=1):"([{".includes(c)?o+=1:")]}".includes(c)&&o>0?o-=1:c===";"&&o===0&&(t.push(l.slice(n,u)),n=u+1)}t.push(l.slice(n));for(let u of t){let c=u.trim();if(!c)continue;let d=c.indexOf(":");if(d<0)throw new TypeError(`malformed style declaration '${c}'`);e.set(c.slice(0,d).trim(),c.slice(d+1).trim())}return e}var rr=class extends er{static mode="html";renderedItem(e,t,n,{tag:i,xml:s=!0,pretty:a=!1,depthOffset:o=0,includeDatapath:l=!1}={}){e.parentNode?._getMeta("subbuilder")==="html"&&(n={xmlns:"http://www.w3.org/1999/xhtml",...n});let{format:c,mask:d,locale:f,places:p,dtype:h,...m}=n;!Array.isArray(t)&&(c!=null||d!=null||p!=null)&&(t=Xu(t,{format:c,mask:d,places:p,dtype:h,locale:this._displayLocale(e,f)}));let g=this._formatAttrs(m);if(l){if(!Object.hasOwn(n,"id")){let x=this.builder.targetId(e);x!==null&&(g+=` id="${this._htmlAttrValue(x)}"`)}for(let[x,$]of Object.entries(e.getAttr()))e.pointerType($)&&(g+=` data-${this.adapt(x)}-pointer="${this._htmlAttrValue(e.absDatapath($))}"`)}let b=a?" ".repeat(this._nodeDepth(e,o)):"",y=a?`
|
|
24
24
|
`:"";if(e._getMeta("void"))return`${b}<${i}${g}${s?"/":""}>${y}`;if(Array.isArray(t)){let x=this._composeStringFragments(t);return`${b}<${i}${g}>${y}${x}${b}</${i}>${y}`}if(t==null)return`${b}<${i}${g}></${i}>${y}`;let v=typeof t=="string"&&t.endsWith("::HTML")?t.slice(0,-6):pm.has(i)?String(t):this._escapeText(t);return`${b}<${i}${g}>${v}</${i}>${y}`}_displayLocale(e,t){if(t)return t;for(let n=e.parentNode;n;n=n.parentNode){let i=n.getAttr("locale");if(i==null)continue;let s=n.pointerType(i)?n.data.getItem(n.absDatapath(i)):i;if(s)return s}}adaptAttrs(e){let t={},n={};for(let[s,a]of Object.entries(e||{}))if(s.startsWith(`${this.builder.constructor._name}_`))t[this.adapt(s)]=a;else if(s==="dtype")t.dtype=a;else{if(this.builder.constructor.retainedAttrPrefixes.some(o=>s.startsWith(o)))continue;this._isStyleContribution(s)?n[s]=a:t[s]=a}let i=this._adaptStyle(n);return i&&(t.style=i),t}_isStyleContribution(e){if(e==="style"||e.startsWith("style_")||jn.has(e))return!0;let t=e.includes("_")?e.slice(0,e.indexOf("_")):null;return t!==null&&jn.has(t)||mm(e)}_adaptStyle(e){let t=gm(e.style),n=new Map,i=new Map;for(let[s,a]of Object.entries(e))if(s!=="style")if(s.startsWith("style_"))t.set(s.slice(6).replaceAll("_","-"),Zu(a));else if(jn.has(s))n.set(s,a);else{let o=s.indexOf("_"),l=o<0?s:s.slice(0,o);o>=0&&jn.has(l)?(i.has(l)||i.set(l,{}),i.get(l)[s.slice(o+1)]=a):t.set(s.replaceAll("_","-"),Zu(a))}for(let s of jn)(n.has(s)||i.has(s))&&this[`_macro_${s}`](n.get(s),i.get(s)||{},t);return[...t].map(([s,a])=>`${s}: ${a}`).join("; ")}_formatAttrs(e){let t=[];for(let[n,i]of Object.entries(e||{}))hm.has(n)?i&&t.push(` ${n}`):t.push(` ${n}="${this._htmlAttrValue(i)}"`);return t.join("")}_htmlAttrValue(e){return(e===!0?"true":e===!1?"false":String(e)).replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""")}_macro_rounded(e,t,n){let i=e===void 0?{}:{top_left:e,top_right:e,bottom_left:e,bottom_right:e};for(let[s,a]of Object.entries(t))if(s==="top"||s==="bottom")i[`${s}_left`]=a,i[`${s}_right`]=a;else if(s==="left"||s==="right")i[`top_${s}`]=a,i[`bottom_${s}`]=a;else if(["top_left","top_right","bottom_left","bottom_right"].includes(s))i[s]=a;else throw new TypeError(`rounded: unknown sub-kwarg '${s}'`);for(let[s,a]of Object.entries(i))n.set(`border-${s.replaceAll("_","-")}-radius`,ts(a))}_macro_transform(e,t,n){let i=e===void 0?[]:[String(e)];for(let[s,a]of Object.entries(t))s==="rotate"?i.push(`rotate(${a}deg)`):s==="scale"||s==="translate"?i.push(`${s}(${a})`):s==="translate_x"?i.push(`translateX(${ts(a)})`):s==="translate_y"?i.push(`translateY(${ts(a)})`):s==="skew_x"?i.push(`skewX(${a}deg)`):s==="skew_y"?i.push(`skewY(${a}deg)`):i.push(`${s.replaceAll("_","-")}(${a})`);i.length&&n.set("transform",i.join(" "))}_macro_filter(e,t,n){let i=e===void 0?[]:[String(e)];for(let[s,a]of Object.entries(t))s==="rotate"?i.push(`hue-rotate(${a}deg)`):s==="blur"?i.push(`blur(${ts(a)})`):s==="drop_shadow"?i.push(`drop-shadow(${a})`):i.push(`${s.replaceAll("_","-")}(${a})`);i.length&&n.set("filter",i.join(" "))}_macro_transition(e,t,n){e!==void 0&&n.set("transition",String(e));for(let[i,s]of Object.entries(t))n.set(`transition-${i.replaceAll("_","-")}`,String(s))}_macro_zoom(e,t,n){e!==void 0&&n.set("zoom",String(e))}_macro_shadow(e,t,n){e!==void 0&&n.set("box-shadow",String(e));for(let[i,s]of Object.entries(t))n.set(`box-shadow-${i.replaceAll("_","-")}`,String(s))}_macro_gradient(e,t,n){e!==void 0&&n.set("background-image",String(e))}};var bm=new Set(["alignment_baseline","baseline_shift","clip_path","clip_rule","color_interpolation","color_interpolation_filters","dominant_baseline","fill_opacity","fill_rule","flood_color","flood_opacity","font_family","font_size","font_size_adjust","font_stretch","font_style","font_variant","font_weight","glyph_orientation_horizontal","glyph_orientation_vertical","image_rendering","letter_spacing","lighting_color","marker_end","marker_mid","marker_start","overline_position","overline_thickness","paint_order","pointer_events","shape_rendering","stop_color","stop_opacity","strikethrough_position","strikethrough_thickness","stroke_dasharray","stroke_dashoffset","stroke_linecap","stroke_linejoin","stroke_miterlimit","stroke_opacity","stroke_width","text_anchor","text_decoration","text_rendering","underline_position","underline_thickness","unicode_bidi","word_spacing","writing_mode"]);function rs(r){return Object.fromEntries(Object.entries(r||{}).map(([e,t])=>[bm.has(e)?e.replaceAll("_","-"):e,t]))}var nr=class extends tr{static mode="svg";adaptAttrs(e){return rs(e)}};var Ju={document_format:{name:"builder_grammar",version:"1.1"},grammar:{name:"html",version:null,title:null,description:null},abstracts:{},elements:{svg:{doc:"Switch to the SVG dialect from this node down (BLD.2).\n\n A sub-builder element: ``_meta['subbuilder']`` switches the active\n dialect to SVG from this node down. No ``render_tag``: ``<svg>`` is\n emitted verbatim (HTML5 has a native ``<svg>`` tag).",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{subbuilder:"svg"}},a:{doc:null,sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},abbr:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},address:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},area:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{void:!0}},article:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},aside:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},audio:{doc:null,sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},b:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},base:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{void:!0}},bdi:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},bdo:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},blockquote:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},body:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},br:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{void:!0}},button:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},canvas:{doc:null,sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},caption:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},cite:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},code:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},col:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{void:!0}},colgroup:{doc:null,sub_tags:"col,script,template",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},data:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},datalist:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,option,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},dd:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},del_:{doc:null,sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},details:{doc:null,sub_tags:"summary[0:1],a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},dfn:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},dialog:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},div:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},dl:{doc:null,sub_tags:"dd,div,dt,script,template",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},dt:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},em:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},embed:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{void:!0}},fieldset:{doc:null,sub_tags:"legend[0:1],a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},figcaption:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},figure:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figcaption[0:1],figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},footer:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},form:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},h1:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},h2:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},h3:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},h4:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},h5:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},h6:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},head:{doc:null,sub_tags:"base[0:1],link,meta,noscript,script,style,template,title[0:1]",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},header:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},hgroup:{doc:null,sub_tags:"h1,h2,h3,h4,h5,h6,p,script,template",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},hr:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{void:!0}},html:{doc:null,sub_tags:"head[0:1],body[0:1]",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},i:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},iframe:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},img:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{void:!0}},input:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{void:!0}},ins:{doc:null,sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},kbd:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},label:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},legend:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,h1,h2,h3,h4,h5,h6,hgroup,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},li:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},link:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{void:!0}},main:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},map:{doc:null,sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},mark:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},menu:{doc:null,sub_tags:"li,script,template",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},meta:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{void:!0}},meter:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},nav:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},noscript:{doc:null,sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},object:{doc:null,sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},ol:{doc:null,sub_tags:"li,script,template",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},optgroup:{doc:null,sub_tags:"div,legend,noscript,option,script,template",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},option:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,div,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},output:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},p:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},picture:{doc:null,sub_tags:"img[0:1],script,source,template",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},pre:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},progress:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},q:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},rp:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},rt:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},ruby:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},s:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},samp:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},script:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},search:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},section:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},select:{doc:null,sub_tags:"button,div,hr,noscript,optgroup,option,script,template",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},slot:{doc:null,sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},small:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},source:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{void:!0}},span:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},strong:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},style:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},sub:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},summary:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,h1,h2,h3,h4,h5,h6,hgroup,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},sup:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},table:{doc:null,sub_tags:"caption[0:1],colgroup,script,tbody,template,tfoot[0:1],thead[0:1],tr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},tbody:{doc:null,sub_tags:"script,template,tr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},td:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},template:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,caption,cite,code,col,colgroup,data,datalist,del_,details,dfn,dialog,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,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,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,source,span,strong,style,sub,summary,sup,table,tbody,td,template,textarea,tfoot,th,thead,time,tr,track,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},textarea:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},tfoot:{doc:null,sub_tags:"script,template,tr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},th:{doc:null,sub_tags:"a,abbr,address,area,article,aside,audio,b,bdi,bdo,blockquote,br,button,canvas,cite,code,data,datalist,del_,details,dfn,dialog,div,dl,em,embed,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,kbd,label,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,output,p,picture,pre,progress,q,ruby,s,samp,script,search,section,select,selectedcontent,slot,small,span,strong,style,sub,sup,table,template,textarea,time,u,ul,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},thead:{doc:null,sub_tags:"script,template,tr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},time:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},title:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},tr:{doc:null,sub_tags:"script,td,template,th",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},track:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{void:!0}},u:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},ul:{doc:null,sub_tags:"li,script,template",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},var:{doc:null,sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},video:{doc:null,sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},wbr:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{void:!0}},selectedcontent:{doc:"Mirror of the selected option for Customizable Select (HTML 2024).",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},dataSetter:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"destination",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"value",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1},{name:"attr",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataFormula:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"destination",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"func",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"collections.abc",name:"Callable"}]},has_default:!1},{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataController:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"func",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"collections.abc",name:"Callable"}]},has_default:!1},{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}}}};var Mt=class extends Se{static _name="html";static _defaultRenderMode="html";static retainedAttrPrefixes=["validate_","dtype"];static{this.defineGrammar(Ju)}get renderer_html(){return new rr(this)}};Se.registerBuilder(Mt);var Ku={document_format:{name:"builder_grammar",version:"1.1"},grammar:{name:"svg",version:null,title:null,description:null},abstracts:{graphics:{doc:"SVG graphics content: any graphical element.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},_meta:null},containerElement:{doc:"SVG container content: elements that can hold children.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},_meta:null}},elements:{html:{doc:"Switch to the HTML dialect from this node down (BLD.2).\n\n A sub-builder element: ``_meta['subbuilder']`` switches the active\n dialect to HTML from this node down. The source tag ``html`` is\n rendered as ``_meta['render_tag']`` (``<foreignObject>``) carrying\n ``_meta['render_attributes']`` (the SVG namespace). The immediate\n HTML child declares XHTML so both sides of the XML boundary retain\n their native namespace.\n ",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{subbuilder:"html",render_tag:"foreignObject",render_attributes:{xmlns:"http://www.w3.org/2000/svg"}}},svg:{doc:"Root SVG container or nested SVG viewport.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},g:{doc:"Group container for applying transforms and styles.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},defs:{doc:"Container for referenced elements (gradients, patterns, etc.).",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},symbol:{doc:"Reusable graphical template, rendered only when referenced by <use>.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},use:{doc:"Reference and render a <symbol> or other element.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},rect:{doc:"Rectangle.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},circle:{doc:"Circle.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},ellipse:{doc:"Ellipse.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},line:{doc:"Line segment between two points.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},polyline:{doc:"Open shape of connected line segments.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},polygon:{doc:"Closed shape of connected line segments.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},path:{doc:"Arbitrary shape defined by path commands (d attribute).",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},image:{doc:"Embedded raster image.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},text:{doc:"Text block. Contains text content and optional <tspan>/<textPath>.",sub_tags:"tspan,textPath",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},tspan:{doc:"Inline text span within <text>.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},textPath:{doc:"Text rendered along a path shape.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},linearGradient:{doc:"Linear gradient definition. Place inside <defs>.",sub_tags:"stop",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},radialGradient:{doc:"Radial gradient definition. Place inside <defs>.",sub_tags:"stop",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},stop:{doc:"Gradient stop (color and offset).",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},pattern:{doc:"Tile pattern definition. Place inside <defs>.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},clipPath:{doc:"Clipping path definition.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},mask:{doc:"Alpha mask definition.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},marker:{doc:"Marker symbol for line endpoints or vertices.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},filter:{doc:"Filter effect container. Place inside <defs>.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feGaussianBlur:{doc:"Gaussian blur filter primitive.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feOffset:{doc:"Offset filter primitive.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feBlend:{doc:"Blend filter primitive.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feColorMatrix:{doc:"Color matrix filter primitive.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feComposite:{doc:"Composite filter primitive.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feFlood:{doc:"Flood fill filter primitive.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feMerge:{doc:"Merge filter primitive (container for feMergeNode).",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feMergeNode:{doc:"Single input for feMerge.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feDropShadow:{doc:"Drop shadow filter primitive (SVG 2).",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feDiffuseLighting:{doc:"Diffuse lighting filter primitive.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feSpecularLighting:{doc:"Specular lighting filter primitive.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},fePointLight:{doc:"Point light source for lighting filters.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feDistantLight:{doc:"Distant light source for lighting filters.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feSpotLight:{doc:"Spot light source for lighting filters.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feMorphology:{doc:"Morphology filter primitive (erode/dilate).",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feTurbulence:{doc:"Turbulence noise filter primitive.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feDisplacementMap:{doc:"Displacement map filter primitive.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feConvolveMatrix:{doc:"Convolution matrix filter primitive.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feImage:{doc:"Image filter primitive.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},feTile:{doc:"Tile filter primitive.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},animate:{doc:"Animate an attribute over time.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},animateTransform:{doc:"Animate a transform attribute.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},animateMotion:{doc:"Animate motion along a path.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},set:{doc:"Set an attribute to a value for a duration.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},title:{doc:"Accessible title (tooltip in browsers).",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},desc:{doc:"Accessible description.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},metadata:{doc:"Metadata container (RDF, Dublin Core, etc.).",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},a:{doc:"Hyperlink wrapper.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},foreignObject:{doc:"Container for non-SVG content (HTML, MathML).",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},switch:{doc:"Conditional processing (renders first matching child).",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null},dataSetter:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"destination",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"value",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1},{name:"attr",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataFormula:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"destination",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"func",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"collections.abc",name:"Callable"}]},has_default:!1},{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataController:{doc:null,sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"func",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"collections.abc",name:"Callable"}]},has_default:!1},{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}}}};var $t=class extends Se{static _name="svg";static _defaultRenderMode="svg";static{this.defineGrammar(Ku)}get renderer_svg(){return new nr(this)}};Se.registerBuilder($t);var ir=class r{#e;constructor(e,t=0){this.pattern=e,this.flags=t,this.#e=Vr.fromJSON({nameSyntax:{kind:"annotated",base:{kind:"type",module:"builtins",name:"str"},metadata:[this.toJSON()]}}).resolve("nameSyntax").test,Object.freeze(this)}static fromJSON(e){if((e!==null&&typeof e=="object"?Object.keys(e).sort():[]).join()!=="flags,kind,pattern"||e.kind!=="regex")throw new TypeError(`A name syntax is {kind: 'regex', pattern, flags}, not ${JSON.stringify(e)}`);return new r(e.pattern,e.flags)}toJSON(){return{kind:"regex",pattern:this.pattern,flags:this.flags}}matches(e){return this.#e(e)}},Un=new ir(String.raw`[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*`);var Le=class{constructor(e){this.gramlot=e}};var ym=/^[a-z][.0-9_a-z\-\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]*$/u,vm=new Set(["annotation-xml","color-profile","font-face","font-face-src","font-face-uri","font-face-format","font-face-name","missing-glyph"]);function gt(r){let e=r.code;if(typeof e!="string"||ym.exec(e)?.[0]!==e||!e.includes("-")||vm.has(e))throw new TypeError("webcomponent: code must be a literal custom-element name");return e}function Ha(r){for(let e of Object.values(r))e&&typeof e=="object"&&Ha(e);return Object.freeze(r)}function Qu(r){if(typeof r.dtype!="string"&&!Array.isArray(r.dtype))throw new TypeError("Component parameter requires dtype");let e=(Array.isArray(r.dtype)?r.dtype:[r.dtype]).map(t=>({kind:"dtype",dtype:t}));return r.nullable&&e.push({kind:"dtype",dtype:"NN"}),r.binding&&r.dtype!=="T"&&e.push({kind:"annotated",base:{kind:"dtype",dtype:"T"},metadata:[{kind:"regex",pattern:"^[\\^=].+",flags:0}]}),e.length===1?e[0]:{kind:"union",items:e}}function zr({name:r,tag:e,base:t,mixins:n=[],parameters:i={},subTags:s="",presentationDefaults:a=[],dataScope:o=!1,command:l=!1,childParameters:u={},sourceContext:c=!1,implementation:d}){if(gt({code:e}),!/^[a-zA-Z][a-zA-Z0-9]*$/.test(r))throw new TypeError("Invalid component authoring name");let f={...t.parameters};for(let p of n)for(let[h,m]of Object.entries(p.parameters)){if(Object.hasOwn(f,h))throw new Error(`Duplicate mixin parameter: ${h}`);f[h]=m}Object.assign(f,i);for(let p of Object.values(f))Qu(p);return Object.freeze({name:r,tag:e,base:t,subTags:s,presentationDefaults:Object.freeze([...a]),dataScope:o,command:l,mixins:Object.freeze([...n]),parameters:Ha(structuredClone(f)),childParameters:Ha(structuredClone(u)),sourceContext:c,implementation:d})}var sr=class{#e=new WeakMap;constructor({name:e,components:t}){this.name=e,this.components=Object.freeze([...t]);let n=new Set,i=new Set;for(let s of t){if(n.has(s.name.toLowerCase())||i.has(s.tag))throw new Error(`Duplicate component: ${s.name}`);n.add(s.name.toLowerCase()),i.add(s.tag)}}toDocument(){return{document_format:{name:"builder_grammar",version:"1.1"},grammar:{name:this.name,version:null,title:this.name,description:null},abstracts:{},elements:Object.fromEntries(this.components.map(e=>[e.name,{doc:null,sub_tags:e.subTags,parent_tags:null,inherits_from:null,ns:null,node_label:null,collection_key:null,attributes:{parameters:[...Object.entries(e.parameters).map(([t,n])=>({name:t,kind:"keyword_only",role:"attribute",annotation:Qu(n),has_default:!0,default:n.default??null})),{name:"attr",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},_meta:{render_tag:e.tag,gramlot_component:{parameters:structuredClone(e.parameters),presentationDefaults:[...e.presentationDefaults],dataScope:e.dataScope,command:e.command,...Object.keys(e.childParameters).length?{childParameters:structuredClone(e.childParameters)}:{},...e.sourceContext?{sourceContext:!0}:{}}}}]))}}register(e){if(this.#e.has(e))return;let t=[];for(let n of this.components){if(e.customElements.get(n.tag))throw new Error(`Custom element already registered: ${n.tag}`);let i=n.base(e.HTMLElement);for(let a of n.mixins)i=a(i);let s=n.implementation(i);Object.defineProperty(s,"gramlotComponent",{value:n}),t.push([n.tag,s])}for(let[n,i]of t)e.customElements.define(n,i);this.#e.set(e,t)}};function ec(r){return new sr(r)}function ns(r,e){return r.parameters=Object.fromEntries(Object.entries(r.constructor.gramlotComponent.parameters).map(([t,n])=>[t,Object.hasOwn(e,t)?e[t]:n.default])),Object.fromEntries(Object.entries(e).filter(([t])=>!Object.hasOwn(r.parameters,t)))}function tc(r){if(r==="")return[];let e=new Set;return r.split(",").map(t=>{let n=t.indexOf(":"),i=n<0?t:t.slice(0,n),s=n<0?t:t.slice(n+1);if(!i||e.has(i))throw new Error("Invalid or duplicate choice code");return e.add(i),{id:i,caption:s}})}function is(r){return class extends r{constructor(){super();let e=this.attachShadow({mode:"open"}),t=this.ownerDocument.createElement("style");t.textContent=`:host{display:inline-block;font:inherit} *,*::before,*::after{box-sizing:border-box}
|
|
25
25
|
input,textarea{font:inherit;max-width:100%} .control-box{min-width:0;color:var(--gramlot-ink,CanvasText)}
|
|
26
26
|
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]),textarea{
|
|
@@ -55,13 +55,13 @@ ${" ".repeat(i)}</${a}>`:`<${a}${l}>${f}</${a}>`:t===null||t.includes(a)?`<${a}
|
|
|
55
55
|
:host([role=menuitem]){display:block} :host([role=menuitem]) button{width:100%;justify-content:start;border:0;background:transparent}
|
|
56
56
|
:host([role=separator]){display:block;border-top:1px solid var(--gramlot-border-control,#888);margin:.25em}
|
|
57
57
|
:host([role=separator]) button{display:none}`,this.shadowRoot.append(t)}get disabled(){return this.control.disabled}set disabled(e){this.control.disabled=!!e}projectAttributes(e,t){let n=super.projectAttributes(e,t);return this.control.disabled=!!this.parameters.disabled,this.control.readOnly=!!this.parameters.readonly,this.icon.textContent=this.parameters.icon??"",e["aria-label"]!=null?this.control.setAttribute("aria-label",e["aria-label"]):this.control.removeAttribute("aria-label"),n}attachCommand(){}releaseCommand(){}commandTarget(){return this}prepareCommand(){return!this.disabled}}}qn.parameters={disabled:{dtype:"B",default:!1,binding:"read"},icon:{dtype:"T",default:"",binding:"read"}};var Am=zr({name:"button",tag:"gramlot-button",base:qn,command:!0,subTags:"*",implementation:r=>class extends r{}}),xm=zr({name:"toggleButton",tag:"gramlot-toggle-button",base:qn,command:!0,subTags:"*",parameters:{value:{dtype:"B",default:!1,binding:"twoWay"},readonly:{dtype:"B",default:!1,binding:"read"}},implementation:r=>class extends r{#e=!1;constructor(){super();let e=this.ownerDocument.createElement("span");e.className="led",e.setAttribute("aria-hidden","true"),this.control.prepend(e),this.writeControlValue(!1)}get commitOnChange(){return!0}readControlValue(){return this.#e}writeControlValue(e){this.#e=e,this.control.setAttribute("aria-pressed",String(e))}prepareCommand(e){return!super.prepareCommand(e)||this.control.readOnly?!1:(this.writeControlValue(!this.#e),this.control.dispatchEvent(new this.ownerDocument.defaultView.Event("change")),!0)}}});function Tm(r){return class extends r{constructor(){super(),this.attachShadow({mode:"open"}).append(this.ownerDocument.createElement("slot"))}connectedCallback(){this.slot="menu",this.setAttribute("role","menu")}projectAttributes(e){return ns(this,e)}}}var Dm=zr({name:"menu",tag:"gramlot-menu",base:Tm,subTags:"menuline",implementation:r=>class extends r{}}),Cm=zr({name:"menuline",tag:"gramlot-menu-line",base:qn,command:!0,subTags:"*",parameters:{code:{dtype:"T",nullable:!0}},implementation:r=>class extends r{attachCommand(){let e=this.textContent.trim()==="-";if(!e&&!this.parameters.code)throw new TypeError("menuline requires a stable code");this.setAttribute("role",e?"separator":"menuitem"),this.control.tabIndex=-1,this.disabled||=e}get disabled(){return super.disabled||!!this.closest("gramlot-drop-down-button")?.parameters.disabled}set disabled(e){super.disabled=e}prepareCommand(e){return super.prepareCommand(e)?(this.closest("gramlot-drop-down-button").selectCommand(this,e.shiftKey),!0):!1}}}),Sm=zr({name:"dropDownButton",tag:"gramlot-drop-down-button",base:qn,command:!0,subTags:"*",parameters:{persist:{dtype:"B",default:!1}},implementation:r=>class extends r{#e=null;#t=null;#r=null;#i=null;#n;#s;#a;constructor(){super();let e=this.ownerDocument;this.control.classList.add("split"),this.#a=e.createElement("span"),this.#a.hidden=!0,this.control.append(this.#a),this.#s=e.createElement("button"),this.#s.type="button",this.#s.className="arrow",this.#s.textContent="\u25BE",this.#s.setAttribute("aria-label","Open menu"),this.#s.setAttribute("aria-haspopup","menu"),this.#s.setAttribute("aria-expanded","false"),this.controlBox.append(this.#s),this.#n=e.createElement("div"),this.#n.className="popup",this.#n.id="menu",this.#n.setAttribute("popover","auto"),this.#s.setAttribute("aria-controls","menu");let t=e.createElement("slot");t.name="menu",this.#n.append(t),this.shadowRoot.append(this.#n),this.#s.addEventListener("click",n=>{n.stopPropagation(),this.#n.matches(":popover-open")?this.closeMenu():this.openMenu()}),this.#s.addEventListener("keydown",n=>{(n.key==="ArrowDown"||n.key==="ArrowUp")&&(n.preventDefault(),this.openMenu(n.key==="ArrowUp"))}),this.addEventListener("keydown",n=>{if(!this.#n.matches(":popover-open"))return;let i=this.menuItems.filter(o=>!o.disabled),s=i.indexOf(n.composedPath().find(o=>i.includes(o))),a;n.key==="ArrowDown"&&(a=(s+1)%i.length),n.key==="ArrowUp"&&(a=(s-1+i.length)%i.length),n.key==="Home"&&(a=0),n.key==="End"&&(a=i.length-1),a!==void 0&&(n.preventDefault(),i[a]?.focus()),(n.key==="Escape"||n.key==="Tab")&&(n.key==="Escape"&&n.preventDefault(),this.closeMenu())}),this.#n.addEventListener("toggle",()=>{let n=this.#n.matches(":popover-open");this.#s.setAttribute("aria-expanded",String(n)),n||(this.#r?.abort(),this.#r=null)})}get menuItems(){return[...this.querySelectorAll(":scope > gramlot-menu > gramlot-menu-line")]}projectAttributes(e,t){let n=super.projectAttributes(e,t);return this.#s.disabled=this.disabled,this.disabled&&this.#n.matches(":popover-open")&&this.closeMenu(),this.#o(),n}attachCommand(){if(this.parameters.persist){if(!this.id)throw new TypeError("dropDownButton persist requires an explicit id");this.#i=`gramlot:command:${this.ownerDocument.location.pathname}${this.ownerDocument.location.search}:${this.id}`;try{this.#e=this.ownerDocument.defaultView.localStorage.getItem(this.#i)}catch{}}this.#o(),this.#t=new this.ownerDocument.defaultView.MutationObserver(()=>this.#o()),this.#t.observe(this,{childList:!0,subtree:!0,characterData:!0})}releaseCommand(){this.#t?.disconnect(),this.#t=null,this.#r?.abort(),this.#r=null,this.#n.matches(":popover-open")&&this.#n.hidePopover()}commandTarget(e){return e?.composedPath().includes(this.#n)?null:this.menuItems.find(t=>t.parameters.code===this.#e)??this}selectCommand(e,t){if(t){if(this.#e=e.parameters.code,this.#i)try{this.ownerDocument.defaultView.localStorage.setItem(this.#i,this.#e)}catch{}this.#o()}this.closeMenu()}#o(){let e=this.menuItems.filter(i=>i.parameters.code).map(i=>i.parameters.code);if(new Set(e).size!==e.length)throw new TypeError("Dropdown menu codes must be unique");let t=this.commandTarget(),n=t!==this;this.caption.hidden=n,this.#a.hidden=!n,this.#a.textContent=n?t.textContent:"",this.icon.textContent=n?t.parameters.icon:this.parameters.icon}openMenu(e=!1){if(this.disabled)return;let t=this.menuItems.filter(s=>!s.disabled);if(!t.length)return;this.#n.showPopover(),this.#s.setAttribute("aria-expanded","true");let n=()=>rc(this.#n,this.controlBox);n(),this.#r?.abort(),this.#r=new this.ownerDocument.defaultView.AbortController;let i={signal:this.#r.signal,capture:!0};this.ownerDocument.defaultView.addEventListener("resize",n,i),this.ownerDocument.addEventListener("scroll",n,i),t[e?t.length-1:0].focus()}closeMenu(){this.#n.matches(":popover-open")&&(this.#n.hidePopover(),this.#s.setAttribute("aria-expanded","false"),this.#r?.abort(),this.#r=null,this.#s.focus())}}}),ss=ec({name:"buttons",components:[Am,xm,Sm,Dm,Cm]});function nc(r){if(r!=null&&(typeof r!="string"||/[{}]/.test(r.replaceAll("{}",""))))throw new RangeError("This formatter mask supports only {} placeholders")}function os(r,e){return nc(e),e==null?r:e.replaceAll("{}",()=>r)}function Nm(r){if(r instanceof Date)return Ot(r);if(ve(r))return"N";if(typeof r=="number")return Number.isInteger(r)?"L":"R";throw new TypeError("Formatting requires finite JavaScript numbers, TYTX Decimal values or valid Date objects")}function Om(r,e,{pattern:t="short",locale:n,timeZone:i}){if(!["short","medium","long","full"].includes(t))throw new RangeError("Temporal formatting currently supports short, medium, long and full only");if(e==="DHZ"&&(typeof i!="string"||!i))throw new TypeError("DHZ formatting currently requires an explicit timeZone");let s={timeZone:e==="DHZ"?i:"UTC"};return e!=="H"&&(s.dateStyle=t),e!=="D"&&(s.timeStyle=t),new Intl.DateTimeFormat(n,s).format(r)}function as(r){let e=/^(-|\()?(#,##0|0+)(?:\.(0*#*))?(\))?$/.exec(r);if(!e||e[1]==="("!=(e[4]===")")||r.endsWith("."))throw new RangeError(`Unsupported numeric pattern section: ${r}`);let t=e[3]??"";return{prefix:e[1]??"",suffix:e[4]??"",intl:{useGrouping:e[2].startsWith("#,##")?"always":!1,minimumIntegerDigits:e[2].replace("#,##","").length,minimumFractionDigits:t.replaceAll("#","").length,maximumFractionDigits:t.length}}}function Im(r){let e=r.split(";");if(e.length>3)throw new RangeError("Numeric patterns support at most three sections");let t=as(e[0]);if(t.prefix||t.suffix)throw new RangeError("Positive-section affixes are not implemented");let n=e.length===3?e[1]:null;n!==null&&n!==""&&n!=="-"&&as(n);let i=e.length>1?as(e.at(-1)):null;return{positive:t,zero:n,negative:i}}function ic(r,e={},t={}){if(r===null)return"";if(typeof e=="string"&&(e={pattern:e}),!e||typeof e!="object"||Array.isArray(e))throw new TypeError("Format options must be a pattern string or an options object");for(let g of Object.keys(e))if(!["pattern","locale","mask","dtype","timeZone"].includes(g))throw new RangeError(`Unsupported format option: ${g}`);e={...e,locale:e.locale??t.locale,timeZone:e.timeZone??t.timeZone};let n=e.dtype===void 0?Nm(r):e.dtype,i=["D","H","DHZ"].includes(n);if(!i&&!["L","R","N"].includes(n))throw new RangeError(`Unsupported format dtype: ${n}`);if(i){if(!(r instanceof Date)||!Number.isFinite(r.getTime()))throw new TypeError(`${n} requires a valid Date object`)}else if(!(typeof r=="number"&&Number.isFinite(r))&&!(ve(r)&&!["NaN","Infinity","-Infinity"].includes(r.toString())))throw new TypeError(`${n} formatting requires finite JavaScript numbers or TYTX Decimal values`);if(n==="L"&&!Number.isInteger(r))throw new TypeError("L formatting requires an integer");let{pattern:s,locale:a,mask:o}=e;if(!i&&typeof s!="string")throw new TypeError("Numeric formatting currently requires an explicit pattern");if(typeof a!="string"||!a)throw new TypeError("Formatting currently requires an explicit locale");if(!(i?Intl.DateTimeFormat:Intl.NumberFormat).supportedLocalesOf([a]).length)throw new RangeError(`Unsupported format locale: ${a}`);if(nc(o),i){let g=Om(r,n,e);return os(g,o)}let{positive:u,zero:c,negative:d}=Im(s),f=ve(r),p=f?r.eq(0):r===0,h=f?r.lt(0):r<0;if(f&&new Intl.NumberFormat("en",{useGrouping:!1}).format("9007199254740993")!=="9007199254740993")throw new Error("This browser cannot format Decimal without precision loss");let m;if(p&&c!==null){if(c==="")return"";if(c==="-")m="-";else{let g=as(c);m=g.prefix+new Intl.NumberFormat(a,g.intl).format(0)+g.suffix}}else{let g=h&&d?d:u,b=f?(h&&d?r.abs():r).toString():h&&d?-r:r===0?0:r;m=g.prefix+new Intl.NumberFormat(a,u.intl).format(b)+g.suffix}return os(m,o)}var Ye="http://www.w3.org/1999/xhtml",Vn="http://www.w3.org/2000/svg",Bm=new Set(["default","default_value","live","group","visible","action","fire","ask","_ask","_ask_if","_ask_title","_ask_onCancel","if","else","_init","_onStart","_onBuilt","_delay","_timing","_userChanges","remote","_cachedRemote","_onRemote","_onCalling","onClose"]),Rm=["default_","attr_","fire_","connect_on","subscribe_","selfsubscribe_","formsubscribe_","remote_"],Mm={table:["width","border"],editor:["height"],embed:["width","height"],img:["width","height"],canvas:["width","height"]},$m=["format","mask","locale","timeZone","places","dtype"],Fm=new Set(["href","src","formaction","xlink:href","xlink_href"]);function Ft(r){return Object.fromEntries(Object.entries(r).filter(([e,t])=>!(t&&typeof t=="object"&&Object.hasOwn(t,"$gramlotRef"))&&!Bm.has(e)&&!Rm.some(n=>e.startsWith(n))))}function Wr(r,e,t=[]){for(let[n,i]of Object.entries(e)){let s=t.find(o=>n.startsWith(o))??"",a=n.slice(s.length);if(["style","class","_class"].includes(a)&&i!=null&&typeof i!="string")throw new TypeError(`${r.nodeTag} '${r.label}': '${n}' must be a string or null`)}}function Gr(r,e,t=[]){if(e.onClose!=null&&!r.parentNode?._getMeta("gramlot_component")?.childParameters?.onClose)throw new Error("onClose is only supported on a tab/stack panel");for(let[n,i]of Object.entries(Xr(Ft(e)))){let s=t.find(o=>n.startsWith(o)),a=s?n.slice(s.length):n;if(/^on./i.test(a))throw new Error(`${r.nodeTag} '${r.label}': '${n}' has the form of a native event handler, run by the browser outside Gramlot; write connect_${a} for an event, or rename the attribute`);if(Fm.has(a.toLowerCase())&&Lm(i))throw new Error(`${r.nodeTag} '${r.label}': '${n}' holds a javascript: URL, run by the browser as code; write connect_onclick or the action of a button instead`)}}function Lm(r){return typeof r=="string"&&/^javascript:/i.test(r.replace(/[\t\n\r]/g,"").replace(/^[\u0000-\u0020]+/,""))}function sc(r,e,t=[]){if(r.nodeTag!=="iframe")return e;let n=o=>{let l=t.find(u=>o.startsWith(u))??"";return[l,o.slice(l.length).toLowerCase()]},i=Object.fromEntries(xe(r.getAttr())),s=[...Object.keys(i),...Object.keys(e)].find(o=>n(o)[1]==="srcdoc");if(s===void 0||Object.keys(i).some(o=>n(o)[1]==="sandbox")||r.pointerType(r.value)===null&&!(Object.hasOwn(i,s)&&(r.pointerType(i[s])!==null||Ze(i[s]))))return e;let a=Object.fromEntries(Object.entries(e).filter(([o])=>n(o)[1]!=="sandbox"));return{[`${n(s)[0]}sandbox`]:"",...a}}function Xr(r){return Object.fromEntries(Object.entries(r).filter(([,e])=>e!=null))}function zn(r){return Object.fromEntries(Object.entries(r).map(([e,t])=>e.startsWith("xmlns_")?[`xmlns:${e.slice(6)}`,t]:e.startsWith("data_")||e.startsWith("aria_")?[e.replaceAll("_","-"),t]:[e,t]))}function ls(r){let{_meta:e,...t}=r;return zn(Xr(Ft(t)))}function ac(r,e){let t=Mm[String(r).toLowerCase()]??[],n={},i={};for(let[s,a]of Object.entries(e))t.includes(s)?i[s]=a:n[s]=a;return[n,i]}function Hr(r){return String(r)}function Hn(r,e,t=null){let n={...e},{mask:i,format:s,locale:a,timeZone:o,dtype:l,places:u}=n;for(let d of $m)delete n[d];let c=d=>{if(t&&s!=null){if(u!=null)throw new RangeError("places is not implemented; specify precision in format");return t(d,{pattern:s,mask:i,...a==null?{}:{locale:a},...o==null?{}:{timeZone:o},...l==null?{}:{dtype:l}})}if(typeof d=="boolean"&&(d=Hr(d)),i==null)return d;let f=d==null?"":Hr(d);return f===""?f:os(f,i)};return Array.isArray(r)?(Object.hasOwn(n,"_text")&&(n._text=c(n._text)),[r,n]):[c(r),n]}function Ze(r){return typeof r=="string"&&r.startsWith("==")}function Pm(r,e,t=r){let n=new Map,i=new Set,s=new Map;for(let[o,l]of e){if(typeof o!="string")continue;let u=Y(l)?.pointer??l;s.set(o,u instanceof ie?u.resolve():r.pointerType(u)?t.getRelativeData(u):Ze(u)?null:u)}let a=o=>{if(n.has(o))return n.get(o);if(!e.has(o))throw new Error(`Source attribute '${o}' does not exist`);if(i.has(o))throw new Error(`cyclic attribute dependency: ${[...i,o].join(" -> ")}`);i.add(o);let l=e.get(o),u=Y(l),c=u?s.get(o):null,d,f=p=>p?a(p):c;try{if(u)if(u.expression){let p=rn(u.body),h=p.slots.map(f);d=r.rootBuilder.evaluatePointerExpression(r,o,l,p,h)}else d=tn(u.body,f),c==null&&(d=null);else d=s.get(o);return n.set(o,d),d}finally{i.delete(o)}};return{resolve:a}}function Lt(r,e,t=r){let n=new Map([...Object.entries(r.getAttr()),...xe(r.getAttr())]);return Pm(r,n,t).resolve(e)}var jm={dataFormula:["formula","_if","_else","_ask_if","_ask_onCancel"],dataController:["script","_if","_else","_ask_if","_ask_onCancel"],dataRpc:["_ask_if","_ask_onCancel","_if","_else","_onCalling","_onResult","_onError"],dataRemote:["_if","_else","_onCalling"]},Wa=["_cachedRemote","_if","_else","_onRemote","_onCalling","_delay","_timing","_userChanges"],Um=["_if","_else","_onRemote","_onCalling"],Ga=class{#e;#t=null;#r=null;#i=!1;constructor(e){this.#e=e}get inflight(){return this.#t?.view??null}get pending(){let e=this.#r;return e?Object.freeze({method:e.method,get params(){return Z(e.text)}}):null}calling(e){if(!e)return!0;let t=!1,n=this.#i;this.#i=!0;try{t=e()!==!1}finally{this.#i=n,!t&&!this.#t&&this.#n()}return t}submit(e,t,n){try{let i=ne(t);return this.#t?this.#r?Promise.resolve(void 0):new Promise((s,a)=>{this.#r={method:e,text:i,perform:n,resolve:s,reject:a}}):(this.#r?.resolve(void 0),this.#r=null,this.#s(e,t,i,n))}catch(i){return Promise.reject(i)}}submitSync(e,t){if(this.#t)throw new Error("A synchronous call cannot start while a request of the node is in flight");if(!this.#e.matches(e))throw new TypeError(`Method name must match ${this.#e.pattern}, not ${JSON.stringify(e)}`);return t()}#n(){let e=this.#r;if(!e)return;this.#r=null;let t;try{t=this.#s(e.method,Z(e.text),e.text,e.perform)}catch(n){t=Promise.reject(n)}t.then(e.resolve,e.reject)}#s(e,t,n,i){if(!this.#e.matches(e))return Promise.reject(new TypeError(`Method name must match ${this.#e.pattern}, not ${JSON.stringify(e)}`));let s=new AbortController,a={method:e,params:t,text:n,controller:s,ignored:!1};a.view=Object.freeze({method:e,get params(){return Z(n)},sentAt:Date.now(),cancel:()=>this.#o(a)}),this.#t=a,s.signal.addEventListener("abort",()=>this.#a(a),{once:!0});let o;try{o=Promise.resolve(i(a))}catch(l){o=Promise.reject(l)}return o.then(()=>this.#a(a),()=>this.#a(a)),o}#a(e){this.#t===e&&(this.#t=null,this.#n())}#o(e){this.#t===e&&(e.ignored=!0,this.#t=null,this.#i||this.#n())}};function oc(r){return typeof r=="string"&&r.startsWith("==")}var ar=class extends Ce{#e=new Set;#t=null;#r=null;get requests(){return this.#r??=new Ga(this.rootBuilder.nameSyntax)}codeAttributes(){let e=[...jm[this.nodeTag]??[],...Object.entries(this.parentNode?._getMeta("gramlot_component")?.childParameters??{}).filter(([,n])=>n.inline).map(([n])=>n),...this._getMeta("gramlot_component")?.command?["action","_ask_if"]:[],...typeof this.getAttr("remote")=="string"?Um:[]],t=[];for(let[n,i]of Object.entries(this.getAttr()??{}))typeof i=="string"&&(e.includes(n)||n==="validate_call"||n==="validate__onResult"||n==="validate_onAccept"||n==="validate_onReject"||/^validate_\w+_if$/.test(n)||n.startsWith("connect_on")||n.startsWith("subscribe_")||n.startsWith("selfsubscribe_"))&&t.push([n,i]);for(let n of["ask","_ask"]){let i=this.getAttr(n);if(i&&typeof i=="object")for(let s of["_if","askIf"])typeof i[s]=="string"&&t.push([`${n}.${s}`,i[s]])}for(let[n,i]of xe(this.getAttr()))oc(i)&&t.push([n,i]);return oc(this.staticValue)&&t.push(["",this.staticValue]),t}activateCode(){let e=new Map;for(let[t,n]of this.codeAttributes()){if(this.pointerType(n))throw new Error(`${this.nodeTag} '${this.label}': '${t}' is inline code and cannot be the pointer '${n}'; inline code is never read from Data`);e.set(t,n)}for(let[t,n]of[...xe(this.getAttr()),["datapath",this.getAttr("datapath")]])Y(n)?.expression&&e.set(t,n);this.#t=e}activatedCode(e){return this.#t?.get(e)??null}remote(e,t={}){let n=this.rootBuilder.nameSyntax;if(typeof e!="string"||!(this.pointerType(e)||n.matches(e)))throw new TypeError(`${this.nodeTag} '${this.label}': remote name must be a pointer or match ${n.pattern}, not ${JSON.stringify(e)}`);let i=Object.keys(t).find(a=>a.startsWith("_")&&!Wa.includes(a));if(i)throw new TypeError(`${this.nodeTag} '${this.label}': remote parameter '${i}' is not accepted; the control attributes are ${Wa.join(", ")}`);let s={remote:e};for(let[a,o]of Object.entries(t))s[Wa.includes(a)?a:`remote_${a}`]=o;return this.setAttr(s),$n(this)}publish(e,t={}){return this.builder.binding.subscriptions.publishNode(this,e,t)}pointers(){let e=this.getAttr("datapath"),t=Y(e)?Qe(this,e):new Set,n=super.pointers().filter(([i,s])=>!t.has(i)&&!this.#s(i,s)).map(([i,s])=>[i,Y(s)?.pointer??s]);for(let i of t){let s=this.getAttr(i);this.pointerType(s)==="^"&&n.push(["datapath",Y(s)?.pointer??s])}return n}runtimeToEvaluate(){let e=super.runtimeToEvaluate();for(let[t,n]of e)if(this.pointerType(n)){if(Y(n)){if(typeof t!="string")throw new Error(`${this.nodeTag} '${this.label}': pointer suffixes belong to attributes; use format/mask for node text`);this.absDatapath(n)===null&&e.set(t,new Yt(()=>Lt(this,t)));continue}this.#s(t,n)?e.set(t,n.slice(1)):this.absDatapath(n)===null&&e.set(t,null)}return e}pathAttribute(e){let t=this.getAttr(e);return Y(t)?Lt(this,e):this.pointerType(t)&&this.#s(e,t)?t.slice(1):t}getRelativeData(e,t=null,n={}){return this.absDatapath(e)===null?null:super.getRelativeData(e,t,n)}setRelativeData(e,t,n={}){this.#a(e),super.setRelativeData(e,t,n)}PUT(e,t){this.#a(e),this.data.setItem(this.absDatapath(e),t,null,">",!1,!0,this,!1,!1)}FIRE(e,t=!0,n=null){t===null&&(t=!0),this.#a(e);let i=this.absDatapath(e);if(i.includes("?")){this.#i(i,t);return}this.data.getNode(i)?.setValue(null,!1);try{this.fireEvent(e,t,{attributes:n})}finally{this.data.getNode(i)?.setValue(null,!1)}}#i(e,t){let[n,i]=e.split("?",2),s=this.data;s.getNode(n)?.setAttr({[i]:null},!1);try{let a=s.getNode(n);a?a.setValue(a.staticValue,!0,{[i]:t},!0,!0,!0,!0):s.setItem(n,null,{[i]:t},">",!0,!0,!0,!0)}finally{s.getNode(n)?.setAttr({[i]:null},!1)}}FIRE_AFTER(e,t=!0,n=10){this.#a(e);let i=this.rootBuilder?.binding?.bindingFor(this)??null,s=null,a=setTimeout(()=>{s?.(),this.FIRE(e,t)},n);return s=i?.track(()=>clearTimeout(a))??null,()=>{clearTimeout(a),s?.()}}absDatapath(e){e=Y(e)?.pointer??e;let t=this.pointerType(e)?e.slice(1):e;if(t.startsWith("#")&&t.includes("?")){let[n,i]=t.split("?",2),s=super.absDatapath(n);return s===null?null:`${s}?${i}`}return super.absDatapath(e)}_composeRelativeDatapath(e,t){let n=this;for(;n!==null&&e.startsWith(".");){let i=n.getAttr("datapath");if(this.pointerType(i)&&(i=this.#n(n,i),i===null))return null;if(i!=null&&(e=e==="."?i:i+e),e.startsWith("#"))return n.parentNode._resolveSymbolicDatapath(e,t);n=n.parentNode}if(e.startsWith("."))throw new Error(`unresolved relative datapath: ${t}`);return e}_finalizeAbsPath(e,t){return e===null?null:super._finalizeAbsPath(e,t)}_resolveSymbolicDatapath(e,t){let n=e.slice(1).split(".",1)[0];if(n==="FORM"||n==="ANCHOR")return super._resolveSymbolicDatapath(e,t);let i=this.rootBuilder?.binding;if(!i)return super._resolveSymbolicDatapath(e,t);let s=i.nodeIds.get(n);if(!s)throw new Error(`#<id>: cannot resolve ${t}`);let a=e.slice(n.length+2);return s.absDatapath(a?`.${a}`:".")}#n(e,t){if(Y(t)){let s=Lt(e,"datapath",e.parentNode);return s==null||s===""?null:s}let n=e.parentNode.absDatapath(t);if(n===null)return null;let i=this.data.getItem(n);return i==null||i===""?null:i}#s(e,t){return Y(t)||typeof e!="string"||!e.endsWith("_path")?!1:(this.#e.has(e)||(this.#e.add(e),console.warn(`${this.nodeTag} '${this.label}': '${e}' holds a bare Data path; the pointer symbol of '${t}' is removed`)),!0)}#a(e){if(this.absDatapath(e)===null)throw new Error(`${this.nodeTag} '${this.label}': write on a null path: '${e}'`)}},ge=class r extends N{get nodeClass(){return ar}authorizedCopy(e){let t=new this.constructor;for(let n of this.getNodes()){let i=n.getAttr("auth")??null;if(i!==null){if(typeof i!="string")throw new TypeError(`${n.nodeTag} '${n.label}': 'auth' must be a string rule, not ${typeof i}`);if(e(i)!==null)continue}let s=n.staticValue;s instanceof r&&(s=s.authorizedCopy(e));let{auth:a,...o}=n.getAttr(),l=t.setItem(n.label,s,o,">",!1,!1,null,!1,!0,null,n.nodeTag);l.xmlTag=n.xmlTag}return t}activateCode(){for(let e of this.getNodes())e.activateCode(),e.staticValue instanceof r&&e.staticValue.activateCode();return this}};if((qe(ge.tytxSuffix).GramlotBuilderBag??ge)!==ge)throw new Error("TYTX subtype name 'GramlotBuilderBag' is already registered for another class");Xt(ge.tytxSuffix,{...qe(ge.tytxSuffix),GramlotBuilderBag:ge});var qm=new Set(["animate","animateMotion","animateTransform","circle","ellipse","feBlend","feColorMatrix","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feGaussianBlur","feImage","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","image","line","metadata","path","polygon","polyline","rect","set","stop","use"]),Wn=class extends nr{constructor(e,t){super(e),this._owner=t}get owner(){return this._owner}_handleMeta(e,t){let n=this.owner.evaluateExpressions(e,t);Gr(e,n);let[i,s]=super._handleMeta(e,n);return Wr(e,s),e._getMeta("subbuilder")?[i,rs(ls(s))]:[i,s]}adaptAttrs(e){let{_meta:t,...n}=e;return zn(super.adaptAttrs(Xr(Ft(n))))}renderedItem(e,t,n,i={}){if(this.owner.renderType==="object")return this.owner.renderedItem(e,t,n,i);let{_text:s,...a}=n;return t=this.owner.expressionValue(e,t),Array.isArray(t)&&s!=null&&(t=[this._escapeText(Hr(s)),...t]),qm.has(i.tag)?`${i.pretty?" ".repeat(this._nodeDepth(e,i.depthOffset??0)):""}<${i.tag}${this._formatAttrs(a)} />${i.pretty?`
|
|
58
|
-
`:""}`:super.renderedItem(e,t,a,i)}};var or=class extends rr{#e=new WeakMap;#t=new WeakMap;get inlineCompiler(){return null}getRender(e){return this.renders.has(e)||(e instanceof Mt?this.addRender(e,this):e instanceof $t&&this.addRender(e,new Wn(e,this))),super.getRender(e)}render(e,t={}){if(e._getMeta("data_element"))return null;let[n,i]=e.rootBuilder.runtimeValues(e),s=this.getRender(e.builder),[a,o]=s._handleMeta(e,i);return e._getMeta("subbuilder")||(o=s.adaptAttrs(o)),s.renderedItem(e,e.value instanceof N?this.renderChildren(e.value,t):n,o,{tag:a,...t})}_handleMeta(e,t){let n=this.builder.constructor.dialectPrefixes,i=this.evaluateExpressions(e,t);Gr(e,i,n);let[s,a]=super._handleMeta(e,sc(e,i,n));if(Wr(e,a,n),e.nodeTag==="webcomponent"){s=gt(e.getAttr());let{code:u,...c}=a;a=c}if(e._getMeta("subbuilder")){let u=ls(a);return e._getMeta("subbuilder")==="html"&&(u.xmlns=Vn),[s,u]}let[o,l]=ac(s,a);return Object.keys(l).length&&this.#e.set(e,l),[s,o]}evaluateExpressions(e,t){let n=this.inlineCompiler,i=(a,o)=>n?n.compileExpression(e,a,o)(t):null,s={...t};for(let[a,o]of xe(e.getAttr()))Ze(o)&&Object.hasOwn(s,a)&&(s[a]=i(a,o));return Ze(e.value)&&this.#t.set(e,i("",e.value)),s}expressionValue(e,t){return Ze(e.value)?this.#t.get(e)??null:t}restoreNativeAttributes(e,t){let n=this.#e.get(e);return n?(this.#e.delete(e),{...t,...Xr(n)}):t}adaptAttrs(e){let{_meta:t,...n}=e,i=`${this.builder.constructor._name}_`,s=this.builder.constructor.dialectPrefixes,a={},o={};for(let[l,u]of Object.entries(Ft(n))){if(u==null)continue;if(l.startsWith(i))throw new Error(`${l}: the attribute prefix '${i}' is not accepted; use the prefix '${s[0]}'`);let c=s.find(d=>l.startsWith(d));c?a[l.slice(c.length)]=u:o[l]=u}return zn({...super.adaptAttrs(o),...a})}renderedItem(e,t,n,i={}){let s;[t,s]=Hn(this.expressionValue(e,t),this.restoreNativeAttributes(e,n));let{_text:a,...o}=s;Array.isArray(t)&&a!=null&&(t=[this._escapeText(Hr(a)),...t]);let l=e.parentNode?._getMeta("subbuilder")==="html"?{xmlns:Ye,...o}:o;return super.renderedItem(e,t,l,i)}finalize(e,t=null,n={}){if(!n.doctype)return super.finalize(e,t,n);let i=this._composeStringFragments(e),s=this.builder.source.getNodes().filter(a=>!a._getMeta("data_element"));return s.length===1&&s[0].nodeTag==="html"||(i=`<html>${i}</html>`),super.finalize(`<!doctype html>${i}`,t,n)}};var lc={document_format:{name:"builder_grammar",version:"1.1"},grammar:{name:"binding",version:null,title:"Gramlot binding",description:"Gramlot Data declarations and the plain HTML button; loaded after the HTML grammar."},abstracts:{},elements:{dataSetter:{doc:"Initial Data value, written literally at destination_path.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"destination_path",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"value",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"any"},has_default:!0,default:null},{name:"attr",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataFormula:{doc:"Computed Data value written at result_path; formula is inline, func is a name.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"result_path",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"formula",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"builtins",name:"NoneType"}]},has_default:!0,default:null},{name:"func",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"builtins",name:"NoneType"}]},has_default:!0,default:null},{name:"params",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataController:{doc:"Side effects on Data; script is inline, func is a name.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"script",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"builtins",name:"NoneType"}]},has_default:!0,default:null},{name:"func",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"builtins",name:"NoneType"}]},has_default:!0,default:null},{name:"params",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataRpc:{doc:"Server endpoint called through gramlot.rpc; the value is written at result_path when given.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"method",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"result_path",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"builtins",name:"NoneType"}]},has_default:!0,default:null},{name:"timeout",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"int"},{kind:"type",module:"builtins",name:"float"},{kind:"type",module:"builtins",name:"NoneType"}]},has_default:!0,default:null},{name:"params",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataRemote:{doc:"Data node resolved by a server endpoint through gramlot.rpc, on first read and again when cacheTime expires; with sync (default) the read waits for the answer when the transport supports it.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"destination_path",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"method",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"cacheTime",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"int"},{kind:"type",module:"builtins",name:"float"},{kind:"type",module:"builtins",name:"NoneType"}]},has_default:!0,default:null},{name:"sync",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"bool"},has_default:!0,default:!0},{name:"params",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},html_button:{doc:"Plain native HTML button without Gramlot click mechanisms.",sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{render_tag:"button"}}}};var uc={document_format:{name:"builder_grammar",version:"1.1"},grammar:{name:"webcomponent",version:null,title:"Gramlot webcomponent",description:"An explicitly loaded autonomous custom element."},abstracts:{},elements:{webcomponent:{doc:"Create the custom-element tag named by literal code.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"code",kind:"keyword_only",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"attr",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null}}};function Me(){return Array.from(globalThis.crypto.getRandomValues(new Uint8Array(16)),r=>r.toString(16).padStart(2,"0")).join("")}var Hm="data is forbidden: write dataSetter for a Data value or html_data for the HTML5 <data> element",Wm=new Set,Gm=new Set(["serverpath","dbenv","shared_id"]),Xm=["formsubscribe_"],Ym={dataSetter:"destination_path",dataFormula:"result_path",dataRpc:"result_path",dataRemote:"destination_path"},Zm={dataFormula:"formula",dataController:"script"};function cc(r,e){if(["input","textarea","select","webcomponent"].includes(r)&&Y(e.value))return"'value' does not accept pointer suffixes; use an ordinary value pointer";if(r==="html_button"&&Object.keys(e).some(i=>["action","ask","_delay","fire"].includes(i)||i.startsWith("fire_")))return"plain HTML button: use button for action, ask, fire or _delay";if(Object.hasOwn(e,"ask")&&!["button","toggleButton","dropDownButton","menuline"].includes(r))return"'ask' is supported on buttons";if(Object.hasOwn(e,"_ask")&&!["dataController","dataFormula","dataRpc"].includes(r))return"'_ask' requires a controller, formula or RPC";if(["dataSetter","dataRemote"].includes(r)&&Object.keys(e).some(i=>i.startsWith("subscribe_")||i.startsWith("selfsubscribe_")))return"topic subscriptions are supported on controllers, formulas, RPCs and rendered elements";let t=Ym[r];if(t&&String(e[t]??"").includes("?"))return`'${t}' does not accept '?attr': '${e[t]}'`;let n=Zm[r];return n&&e[n]!=null&&e.func!=null?`'func' and '${n}' cannot be declared on the same node`:n&&e._if!=null&&e.func!=null?"'_if' is inline and cannot be declared with 'func': write the condition in the method":null}function dc(r){return Object.keys(r).find(e=>Gm.has(e)||Xm.some(t=>e.startsWith(t)))}var Je=class r extends Mt{static _name="gramlot";static _sourceClass=ge;static{this.defineGrammar(lc)}static{this.defineGrammar(uc)}static{this.defineGrammar(ss.toDocument())}static get dialectPrefixes(){let e=[];for(let t=Object.getPrototypeOf(r);t&&t!==Function.prototype;t=Object.getPrototypeOf(t))Object.hasOwn(t,"_name")&&t._name&&e.push(`${t._name}_`);return e}constructor(e=null,{collections:t=[],auth:n=null,nameSyntax:i=Un}={}){if(!(i instanceof ir))throw new TypeError(`nameSyntax must be a NameSyntax, not ${i}`);super(e),this._binding=null,this._auth=n,this._nameSyntax=i;for(let s of t)this.loadCollection(s)}get auth(){return this._auth}get nameSyntax(){return this._nameSyntax}get binding(){return this._binding}set binding(e){this._binding=e}evaluatePointerExpression(e,t,n,i,s){return this.binding?this.binding.inlineCompiler.compilePointerExpression(e,t,n,i.text)(s):null}nodeById(e){if(!this.binding)return super.nodeById(e);let t=this.binding.nodeIds.get(e);if(!t)throw new Error(`node_id not found: ${e}`);return t.builder.wrapSource(t)}loadCollection(e){return this.loadGrammar(e instanceof sr?e.toDocument():e),this}schemaTag(e){let t=e.toLowerCase(),n=r.dialectPrefixes;if(t.startsWith(`${r._name}_`))throw new Error(`${e}: the tag prefix '${r._name}_' is not accepted; use the prefix '${n[0]}'`);if(Wm.has(t))throw new Error(`${e}: excluded from Gramlot`);let i=this.schemaTagNames[t];if(i)return i;for(let s of n)if(t.startsWith(s)&&this.schemaTagNames[t.slice(s.length)])return t;return null}bagCall(e,t,n,i){return super.bagCall(e,this.#e(t),n,i)}commandOnNode(e,t,n,i){return super.commandOnNode(e,this.#e(t),n,i)}validateNodeValues(e,t,n={}){if(this.schema[e]?._meta?.gramlot_component&&Y(n.value))throw new Error("'value' does not accept pointer suffixes");e==="webcomponent"&>(n);let i=dc(n);if(i)throw new Error(`${e}: attribute '${i}' is excluded from Gramlot`);let s=cc(e,n);if(s)throw new Error(`${e}: ${s}`);return super.validateNodeValues(e,t,n)}validateNode(e,t={}){if(e._getMeta("gramlot_component")&&Y((t.attrs??e.getAttr()).value))throw new Error("'value' does not accept pointer suffixes");e.nodeTag==="webcomponent"&>(t.attrs??e.getAttr());let n=dc(t.attrs??e.getAttr());if(n)throw new Error(`${e.nodeTag} '${e.label}': attribute '${n}' is excluded from Gramlot`);let i=cc(e.nodeTag,t.attrs??e.getAttr());if(i)throw new Error(`${e.nodeTag} '${e.label}': ${i}`);return super.validateNode(e,t)}_validateChildren(e,t,n,i){return super._validateChildren(e,t,n.map(s=>s==="html_button"?"button":s),i)}_countsForGrammar(e){return e===this.schema.button||!e?._meta?.gramlot_component&&e!==this.schema.webcomponent&&super._countsForGrammar(e)}setChild(e,t,n,i,s=null){i=Object.fromEntries(Object.entries(i??{}).map(([l,u])=>[l,me(u)instanceof Ce?this.reference(u):u]));let o=t==="dataSetter"&&i?.value!==null&&typeof i?.value=="object"&&Object.getPrototypeOf(i.value)===Object.prototype?{...i,value:new V(i.value)}:i;return super.setChild(e,t,n,o,s)}#e(e){if(e==="data")throw new Error(Hm);if(this.schemaTagNames[e.toLowerCase()]===e)return e;let t=r.dialectPrefixes.find(n=>e.startsWith(n));return this.schemaTagNames[e.slice(t.length)]}get renderer_html(){return new or(this)}create(){this.setup(this.data),this.main(this.root)}computeLogic(){}promoteNodeValue(e,t,n){let i=t!=null?{_text:t}:null;e.setValue(n,!0,i,!0)}reference(e,t="node"){if(e=me(e),!(e instanceof Ce)||!["node","dom"].includes(t))throw new TypeError("Reference requires an element and node/dom kind");let n=e.getAttr("__ref");return n==null&&(n=Me(),e.setAttr({__ref:n})),{$gramlotRef:n,kind:t}}toTytx(){return ne(this.auth===null?this.source:this.source.authorizedCopy(this.auth))}};var Jm=new Set(["input","select","textarea"]),Km=["type","multiple","group"];function fc(r,e){let t=r.getAttr(e);return r.pointerType(t)?r.getRelativeData(t):t}var Te=class r{static liveWrites=!1;static writesDefault=!0;static preservesUnchangedValue=!1;#e;#t=!1;#r;#i;#n=!1;#s=!1;#a=!1;static for(e,t){let n=r.classFor(t.element,t.attrs);return n?new n(e,t):null}static classFor(e,t){if(e.namespaceURI!==Ye)return null;if(e.constructor.gramlotComponent)return e.constructor.gramlotComponent.parameters.value?.binding!=="twoWay"?null:e.control.type==="radio"?Ka:Xa;if(e.localName==="textarea")return lt;if(e.localName==="select")return Gn;if(e.localName!=="input")return null;let n=t.type==null?"text":String(t.type).toLowerCase();return Object.hasOwn(pc,n)?pc[n]:lt}static shape(e,t){return e?.constructor.gramlotComponent?.parameters.value?.binding==="twoWay"&&e.control.type==="radio"?JSON.stringify([t.group??null]):e?.namespaceURI!==Ye||!Jm.has(e.localName)?null:JSON.stringify(Km.map(n=>t[n]??null))}constructor(e,t){this.#r=e,this.#i=t}get binding(){return this.#r}get element(){return this.#i.element}get node(){return this.binding.node}get eventElement(){return this.element}get resolved(){return this.#i.resolved}get live(){return!!this.resolved.live}get writeEvent(){return this.constructor.liveWrites&&this.live?"input":"change"}project(e,t){if(this.#s){this.#a=!0;return}this.constructor.preservesUnchangedValue&&this.#t&&this.same(this.#e,e)||(this.#e=e,this.#t=!0,!(this.#n&&this.same(this.read(),e))&&(this.constructor.writesDefault&&!this.node.pointerType(this.node.getAttr("value"))&&this.writeDefault(e),this.write(e)))}read(){return this.element.value}write(e){let t=e==null?"":String(e);this.element.value!==t&&(this.element.value=t)}writeDefault(e){let t=e==null?"":String(e);this.element.localName==="textarea"?this.#i.text.data!==t&&(this.#i.text.data=t):this.element.defaultValue!==t&&(this.element.defaultValue=t)}same(e,t){return Object.is(e,t)}commit(e,t=this.read()){if(!this.binding.closed){this.#n=!0;try{this.binding.runtime.renderer.html.writeParameter(this.node,"value",t)}finally{this.#n=!1}}}attach(){for(let e of["input","change","compositionstart","compositionend"])this.eventElement.addEventListener(e,this)}detach(){for(let e of["input","change","compositionstart","compositionend"])this.eventElement.removeEventListener(e,this);this.#a=!1}refresh(){}handleEvent(e){if(!this.binding.closed){if(e.type==="compositionstart"){this.#s=!0;return}if(e.type==="compositionend"){this.#s=!1,this.writeEvent==="input"&&this.commit(e),this.#a&&(this.#a=!1,this.binding.runtime.renderer.project(this.node));return}this.#s||e.isComposing||e.type===this.writeEvent&&this.commit(e)}}},Xa=class extends Te{static writesDefault=!1;static preservesUnchangedValue=!0;get eventElement(){return this.element.control}attach(){this.element.setPageContext(hc(this)),super.attach()}project(e,t){this.element.shouldProjectControlValue(e)&&super.project(e,t)}same(e,t){return this.element.sameControlValue(e,t)}detach(){this.element.releaseControl(),super.detach()}commit(e){this.binding.closed||this.element.control.disabled||this.element.control.readOnly||mc(this.element,this.element.acceptControlValue(),t=>super.commit(e,t.value))}get writeEvent(){if(this.element.commitOnChange)return"change";let e=this.element.control;return this.live&&(e.localName==="textarea"||["text","password","range","color"].includes(e.type))?"input":"change"}read(){return this.element.readControlValue()}write(e){this.element.writeControlValue(e)}handleEvent(e){if(super.handleEvent(e),!e.composed&&!this.binding.closed&&["input","change"].includes(e.type)){let t=this.element.ownerDocument.defaultView.Event;this.element.dispatchEvent(new t(e.type,{bubbles:!0,composed:!0}))}}},lt=class extends Te{static liveWrites=!0},Ya=class extends Te{static liveWrites=!0;read(){return this.element.value===""?null:Number(this.element.value)}commit(e){this.element.validity.badInput||super.commit(e)}},Za=class extends Te{static liveWrites=!0;read(){return Number(this.element.value)}},Gn=class extends Te{static writesDefault=!1;read(){return this.element.multiple?[...this.element.selectedOptions].map(e=>e.value):this.element.selectedIndex===-1?null:this.element.value}write(e){let t=this.element;if(t.multiple){if(e!=null&&!Array.isArray(e))throw new TypeError(`${this.node.nodeTag} '${this.node.label}': a multiple select requires an array`);let n=new Set((e??[]).map(String));for(let i of t.options){let s=n.has(i.value);i.selected!==s&&(i.selected=s)}}else e==null?t.selectedIndex!==-1&&(t.selectedIndex=-1):(t.selectedIndex===-1||t.value!==String(e))&&(t.value=String(e))}same(e,t){return Array.isArray(e)?Array.isArray(t)&&t.length===e.length&&t.every((n,i)=>Object.is(n,e[i])):super.same(e,t)}},lr=class extends Te{read(){return this.element.value===""?null:this.element.value}},Ja=class extends Te{},us=class extends Te{static writesDefault=!1;read(){return this.element.checked}write(e){let t=!!e;this.element.checked!==t&&(this.element.checked=t)}same(e,t){return e===!!t}attach(){let e=this.node;if(e.getAttr("checked")!=null&&e.pointerType(e.getAttr("value"))==="^")throw new TypeError(`${e.nodeTag} '${e.label}': checked and a ^ value are two sources`);super.attach()}},cs=class extends us{#e=null;#t=!1;get groups(){return this.binding.runtime.renderer.radioGroups}attach(){let e=this.node,t=this.resolved.group??null,n=Qa(e);if(t!=null){if(e.getAttr("name")!=null)throw new TypeError(`${e.nodeTag} '${e.label}': name and group are two names`);this.#r(t,n)}super.attach(),t!=null&&(this.#e=this.groups.join(this,t,n),this.element.setAttribute("name",this.#e))}detach(){this.#e!==null&&(this.groups.leave(this),this.element.removeAttribute("name"),this.#e=null),super.detach()}refresh(){if(this.#e===null)return;let e=this.resolved.group,t=Qa(this.node);this.groups.nameOf(e,t)!==this.#e&&(this.#r(e,t),this.groups.leave(this),this.#e=this.groups.join(this,e,t),this.element.setAttribute("name",this.#e))}#r(e,t){let n=this.node;if(fc(n,"value")&&this.groups.peersOf(e,t).some(i=>!i.binding.closed&&i.read()))throw new Error(`${n.nodeTag} '${n.label}': several true values in radio group '${e}'`)}project(e,t){let n=!this.#t;this.#t=!0;let i=this.read();super.project(e,t),!n&&!i&&this.read()&&this.turnOffPeers()}commit(e){let t=this.read();super.commit(e),t&&!this.binding.closed&&this.turnOffPeers()}turnOffPeers(){if(this.#e!==null)for(let e of this.groups.peers(this)){if(this.binding.closed)return;e.binding.closed||(e.element.checked&&(e.element.checked=!1),fc(e.node,"value")&&e.commit(null))}}},Ka=class extends cs{static writesDefault=!1;get host(){return super.element}get element(){return this.host.control}project(e,t){this.host.shouldProjectControlValue(e)&&super.project(e,t)}commit(e){this.binding.closed||this.element.disabled||this.element.readOnly||mc(this.host,this.host.acceptControlValue(),()=>super.commit(e))}read(){return this.host.readControlValue()}write(e){this.host.writeControlValue(e)}attach(){this.host.setPageContext(hc(this)),super.attach(),this.element.addEventListener("keydown",this)}detach(){this.host.releaseControl(),this.element.removeEventListener("keydown",this),super.detach()}handleEvent(e){if(!this.binding.closed){if(e.type==="keydown"){if(this.resolved.group==null||!["ArrowLeft","ArrowUp","ArrowRight","ArrowDown"].includes(e.key))return;let t=this.groups.peersOf(this.resolved.group,Qa(this.node)).filter(a=>!a.binding.closed&&!a.element.disabled),n=t.indexOf(this);if(n<0)return;e.preventDefault();let i=["ArrowLeft","ArrowUp"].includes(e.key)?-1:1,s=t[(n+i+t.length)%t.length];s.element.focus(),s.element.click();return}if(super.handleEvent(e),!e.composed&&!this.binding.closed&&["input","change"].includes(e.type)){let t=this.host.ownerDocument.defaultView.Event;this.host.dispatchEvent(new t(e.type,{bubbles:!0,composed:!0}))}}}},ds=class{#e;#t=new Map;#r=new Map;#i=new WeakMap;#n=0;constructor(e){this.#e=e}join(e,t,n){let i=this.nameOf(t,n);return this.#t.has(i)||this.#t.set(i,new Set),this.#t.get(i).add(e),this.#r.set(e,i),i}leave(e){let t=this.#r.get(e);this.#r.delete(e);let n=this.#t.get(t);n?.delete(e),n?.size===0&&this.#t.delete(t)}peers(e){let t=this.#r.get(e);return[...this.#t.get(t)??[]].filter(n=>n!==e)}peersOf(e,t){return[...this.#t.get(this.nameOf(e,t))??[]]}nameOf(e,t){t!==null&&!this.#i.has(t)&&this.#i.set(t,this.#n++);let n=t===null?"page":`form${this.#i.get(t)}`;return`gramlot-${this.#e.instanceId}-${n}-${e}`}};function Qa(r){for(let e=r;e;e=e.parentNode){let t=e.getAttr()??{};if(t.formId!=null||t.form===!0)return e}return null}var pc={text:lt,password:lt,email:lt,url:lt,tel:lt,search:lt,number:Ya,range:Za,color:Ja,date:lr,time:lr,month:lr,week:lr,"datetime-local":lr,checkbox:us,radio:cs,hidden:null,file:null,button:null,submit:null,reset:null,image:null};function hc(r){let{binding:e,node:t}=r,n=e.runtime.gramlot,i=(s,a,o,l=!1)=>{if(!l&&/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(a)){let{group:u,method:c}=n.src.logicRegistry.resolve(a,t);return c.call(u,t,o)}return e.runtime.inlineCompiler.compile(t,s,a,Object.keys(o),l?`return (${a});`:a)(o)};return{locale:n.locale,timeZone:n.timeZone,createDecimal:It,isDecimal:ve,getDecimalLibrary:Ba,isActive:()=>!e.closed,callLogic:(s,a)=>{let{group:o,method:l}=n.src.logicRegistry.resolve(s,t);return l.call(o,t,a)},format:(s,a)=>n.format(s,a),invoke:i,remote:(s,a,o)=>n.rpc.call("data",s,a,{signal:o}),validationCurrent:()=>{let s=t.getAttr("value"),a=t.pointerType(s)?t.absDatapath(s):null;return()=>!e.closed&&t.getAttr("value")===s&&(a===null||t.absDatapath(s)===a)},finishValidation:({ok:s,result:a,rules:o})=>{if(e.closed)return;if(s)for(let u of a.datachanges)t.getRelativeData(".").update(u);let l=s?"validate_onAccept":"validate_onReject";if(o[l]){let u=c=>console.error("Validation notification failed:",c);try{let c=Object.fromEntries(Object.entries(o).map(([f,p])=>[f.slice(9),p])),d=i(l,o[l],{value:a.value,result:a,validations:c,userChange:!0});d instanceof Promise&&d.catch(u)}catch(c){u(c)}}},checkDataPatch:s=>{if(!(s instanceof V))throw new TypeError("Validation data changes must be a Bag.");if(!(t.getRelativeData(".")instanceof V))throw new TypeError("Validation data changes require a Bag datapath.")}}}function mc(r,e,t){let n=i=>{i.ok&&i.isCurrent()&&(t(i),r.finishValidation(i))};e instanceof Promise?e.then(n).catch(i=>console.error("Validation notification failed:",i)):n(e)}var eo=Symbol("source text"),gc={xmlns:"http://www.w3.org/2000/xmlns/",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},Qm=new Set(["allowFullscreen","async","autofocus","autoplay","checked","controls","default","defer","disabled","formNoValidate","hidden","inert","isMap","itemscope","loop","multiple","muted","noModule","noValidate","open","playsInline","readOnly","required","reversed","selected"]),eg=new Set(["checked","muted","selected","value"]),tg=new Map([["allowfullscreen","allowFullscreen"],["formnovalidate","formNoValidate"],["ismap","isMap"],["nomodule","noModule"],["novalidate","noValidate"],["playsinline","playsInline"],["readonly","readOnly"]]);function rg(r){let e=r.replace(/-([a-z])/g,(t,n)=>n.toUpperCase());return tg.get(e.toLowerCase())??e}var fs=class{constructor({metadataAttributes:e=[],invokeScript:t=null}={}){this.invokeScript=t,this.metadataAttributes=new Set([...Zt,"_text",...e])}definition(e){let t=e.builder,i={...t.schema[t.schemaTag(e.nodeTag)]._meta,...e.getAttr("_meta")},s=e.nodeTag==="webcomponent"?gt(e.getAttr()):Mn(e.nodeTag,{renderTag:i.render_tag,ns:e.getAttr("ns"),dialectName:t.constructor._name}),a=s==="foreignObject"?Vn:i.render_attributes?.xmlns??e.getAttr("xmlns")??(t instanceof $t?Vn:Ye);return{meta:i,namespace:a,tag:s}}validate(e,t=e.builder){let n=e.value instanceof N,i=n?e.getAttr("_text"):e.value;if(i!=null&&!["string","number","boolean"].includes(typeof i))throw new TypeError("HTML text must be scalar");for(let[o,l]of Object.entries(e.attr))if(!(o==="value"&&this.definition(e).meta.gramlot_component)&&!(this.metadataAttributes.has(o)||["ask","_ask"].includes(o)||l&&typeof l=="object"&&Object.hasOwn(l,"$gramlotRef"))&&l!=null&&!["string","number","boolean"].includes(typeof l))throw new TypeError(`HTML attribute ${o} must be scalar`);let s=Object.fromEntries(Object.entries(e.attr).filter(([o])=>!this.metadataAttributes.has(o))),a=n?e.value.getNodes().map(o=>o.nodeTag).filter(Boolean):[];t.validateNode(e,{value:i,attrs:s,childTags:a})}create(e,t,n=null,i=e.attr,s=null){let{tag:a,namespace:o,meta:l}=this.definition(e);n??=a;let u=o===Ye?t.createElement(n):t.createElementNS(o,n);if(l.gramlot_component&&u.constructor.gramlotComponent?.tag!==n)throw new Error(`Component collection must be activated before rendering ${n}`);l.gramlot_component?.dataScope&&(u.readDataScope=()=>{if(!e.getAttr("datapath"))throw new Error("Data scope requires an explicit datapath");return e.getRelativeData(".")}),l.gramlot_component?.sourceContext&&u.setSourceContext({publish:(f,p)=>e.publish(f,p),writeParameter:(f,p)=>this.writeParameter(e,f,p)});let c=t.createTextNode(this.text(e));(o!==Ye||!l.void)&&u.append(c);let d={element:u,text:c,tag:n};return this.update(d,e,i,eo,s),d}matches(e,t){let{tag:n,namespace:i}=this.definition(t);return(i===Ye?e.tag.toLowerCase()===n.toLowerCase():e.tag===n)&&e.element.namespaceURI===i}writeParameter(e,t,n){let i=e.getAttr(t);e.pointerType(i)==="^"&&!Y(i)&&!Object.is(e.getRelativeData(i.slice(1)),n)&&e.setRelativeData(i.slice(1),n)}compose(e,t,n){e.text.data=t??"";for(let i of n)e.element.append(i)}update(e,t,n=t.attr,i=eo,s=null){let{element:a,text:o}=e,l=a.namespaceURI===Ye,u=this.definition(t).meta.render_attributes??{},c=e.attrs??{},d=g=>(Gr(t,g,t.builder.constructor.dialectPrefixes),Wr(t,g,t.builder.constructor.dialectPrefixes),t.builder.renderer_html.adaptAttrs(g)),f=t.parentNode;f?._getMeta("gramlot_component")?.childParameters&&(n=a.ownerDocument.defaultView.customElements.get(f._getMeta("render_tag")).projectChild(a,n,{adapt:d,invoke:(b,y,v)=>this.invokeScript(t,b,y,v),publish:(b,y)=>t.publish(b,y),publishParent:(b,y)=>f.publish(b,y),writeParameter:(b,y)=>this.writeParameter(t,b,y),remove:()=>t.parentBag.popNode(t.label)})),this.definition(t).meta.gramlot_component&&(n=a.projectAttributes(n,d)),n=Object.fromEntries(xe({...n,...u}));let p=Te.classFor(a,n)!==null;i===eo&&(i=this.text(t));let h=i==null?"":String(i);o.data!==h&&(o.data=h);let m=[...new Set([...Object.keys(c),...Object.keys(n)])];m.sort((g,b)=>(b==="sandbox")-(g==="sandbox"));for(let g of m){if(this.metadataAttributes.has(g)||["ask","_ask"].includes(g)||p&&g==="value")continue;let b=n[g],y=g,v=rg(y),x=l&&Qm.has(v)&&typeof a[v]=="boolean",$=y==="xmlns"?"xmlns":y.includes(":")?y.split(":")[0]:"",D=Object.hasOwn(gc,$)?gc[$]:null;if(Object.is(c[g],b)||(b==null||x&&!b?D?a.removeAttributeNS(D,y.split(":").at(-1)):a.removeAttribute(y):D?a.setAttributeNS(D,y,String(b)):a.setAttribute(y,x?"":String(b))),l&&(x||eg.has(v))&&v in a){let J=v==="value"?b==null?"":String(b):!!b;a[v]!==J&&(a[v]=J)}}s===!1?a.style.visibility!=="hidden"&&(a.style.visibility="hidden"):e.visible===!1&&(n.style==null?a.removeAttribute("style"):a.setAttribute("style",String(n.style))),e.visible=s,e.attrs=n}text(e){return e.value instanceof N?e.getAttr("_text")==null?"":String(e.attr._text):e.value==null?"":String(e.value)}};var ps=class r{#e;#t;#r=null;#i=0;static for(e,t){return t.element?.constructor.gramlotComponent?.command?new r(e,t):null}constructor(e,t){this.#e=e,this.#t=t}get binding(){return this.#e}get node(){return this.binding.node}get element(){return this.#t.element}get controllers(){let e=this.node.value;return e?.getNodes?e.getNodes().filter(t=>t.nodeTag==="dataController"||t.nodeTag==="dataRpc"):[]}get mechanism(){let e=this.node,t=this.controllers;if(t.length>1)throw new Error(`${e.nodeTag} '${e.label}': several dataController or dataRpc children; a button has one click mechanism`);let n=e.getAttr()??{},i=[];if(t.length&&i.push("controller"),n.action!=null&&i.push("action"),bc(n).length&&i.push("fire"),i.length>1)throw new Error(`${e.nodeTag} '${e.label}': ${i.join(" and ")} together; a button has one click mechanism`);return i[0]??null}attach(){this.refresh(),this.element.activateCommand=e=>this.onClick(e),this.element.attachCommand(),this.element.addEventListener("click",this)}refresh(){this.mechanism&&this.node.getAttr("type")==null&&this.element.getAttribute("type")!=="button"&&this.element.setAttribute("type","button")}detach(){this.element.removeEventListener("click",this),this.element.releaseCommand(),delete this.element.activateCommand,this.#r?.()}handleEvent(e){this.onClick(e)}onClick(e){if(this.binding.closed||this.element.disabled)return;let t=this.element.commandTarget(e);if(t===null)return;if(t!==this.element)return e.stopPropagation(),t.activateCommand(e);if(!this.element.prepareCommand(e)||!this.mechanism||(e.stopPropagation(),this.element.disabled))return;let i=this.binding.countClick(),s=this.node;for(;s&&s.getAttr("_delay")==null;)s=s.parentNode;let a=s?s.rootBuilder.runtimeValues(s)[1]._delay:0;if(a>0){let o=this.#i+1;this.#r?.(),this.#i=o;let l=setTimeout(()=>{u(),this.#r=null,this.#i=0,this.#n(e,o)},a),u=this.binding.track(()=>this.#r?.());this.#r=()=>{clearTimeout(l),u(),this.#r=null,this.#i=0};return}return this.#r?.(),this.#n(e,i)}#n(e,t){if(this.binding.closed||this.element.disabled)return;let n=this.mechanism;if(!n)return;let i=this.node,s=ng(e);if(n==="controller")this.binding.runtime.bindingFor(this.controllers[0])?.providers[0]?.invoke({kind:"click",event:e,counter:t});else if(n==="action"){let a=()=>{let[,c]=i.rootBuilder.runtimeValues(i),d=Object.fromEntries(Object.entries(c).filter(([f])=>f!=="ask"));return{...this.binding.runtime.renderer.references.resolveArguments(d),event:e,_counter:t,modifiers:s}},o=c=>{if(this.binding.closed||this.element.disabled||c===null)return;let d={...a(),...c};c&&(d._askResult=c),this.binding.runtime.inlineCompiler.compile(i,"action",i.getAttr("action"),Object.keys(d))(d)},l=i.getAttr("ask"),u=this.binding.runtime.askDialog;if(l&&u.required(this.binding,l,a(),"ask"))return u.show(this.binding,l,a()).then(o);o(void 0)}else{let a={modifier:s,_counter:t},o=i.getAttr("fire");if(o!=null){i.FIRE(o,s||!0,a);return}for(let[l,u]of bc(i.getAttr())){if(this.binding.closed)return;i.FIRE(u,l.slice(5),a)}}}};function bc(r){return Object.entries(r??{}).filter(([e,t])=>t!=null&&(e==="fire"||e.startsWith("fire_")))}function ng(r){return["shift","ctrl","alt","meta"].filter(e=>r[`${e}Key`]).map(e=>e[0].toUpperCase()+e.slice(1)).join("")}var hs="connect_on",ig=/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/,Xn=class{#e;#t;#r;#i;#n;static declared(e){return Object.entries(e.getAttr()??{}).filter(([t,n])=>t.startsWith(hs)&&t.length>hs.length&&n!=null).map(([t,n])=>[t,t.slice(hs.length).toLowerCase(),n])}constructor(e,t,n,i,s=`${hs}${n}`){this.#e=e,this.#t=t,this.#r=n,this.#i=i,this.#n=s}get binding(){return this.#e}get node(){return this.binding.node}get element(){return this.#t.element}get eventName(){return this.#r}get handler(){return this.#i}get attribute(){return this.#n}attach(){this.element.addEventListener(this.eventName,this)}detach(){this.element.removeEventListener(this.eventName,this)}handleEvent(e){if(this.binding.closed)return;let t=this.node,n=this.binding.runtime;if(ig.test(this.handler)){let{group:i,method:s}=n.logicRegistry.resolve(this.handler,t);s.call(i,t,e);return}n.inlineCompiler.compile(t,this.attribute,this.handler,["event"])({event:e})}};function Yr(r,e=new Set){if(!r||typeof r!="object")return;let t=r.ownerDocument?.defaultView?.Node??r.defaultView?.Node;if(me(r)instanceof Ce||t&&r instanceof t)throw new TypeError("Live Source/DOM references cannot cross a transport boundary");if(e.has(r))throw new TypeError("Transport data cannot contain circular references");e.add(r);let n=r instanceof V?r.getNodes().flatMap(i=>[i.staticValue,i.getAttr()]):Object.values(r);for(let i of n)Yr(i,e);e.delete(r)}var Yn=class{constructor(e=null){this.entries=new Map,this.sourceRoot=e}validate(e,t=new Set){let n=new Map,i=s=>{for(let a of s.getNodes()){let o=a.getAttr("__ref");if(o){if(n.has(o))throw new Error("Duplicate Source reference");let l=this.entries.get(o);if(e!==this.sourceRoot&&l&&l.node!==a&&!t.has(l.node))throw new Error("Duplicate Source reference");n.set(o,a)}a.value instanceof N&&i(a.value)}};i(e)}register(e,t){let n=e.getAttr("__ref");if(n){if(this.entries.has(n))throw new Error(`Duplicate Source reference: ${n}`);this.entries.set(n,{node:e,dom:t})}}remove(e){for(let[t,n]of this.entries)n.node===e&&this.entries.delete(t)}resolveArguments(e){return Object.fromEntries(Object.entries(e).map(([t,n])=>[t,n&&typeof n=="object"&&Object.hasOwn(n,"$gramlotRef")?this.resolve(n):n]))}resolve(e){if(!e||!["node","dom"].includes(e.kind))throw new TypeError("Expected a node or DOM reference");let t=this.entries.get(e.$gramlotRef);if(!t)throw new Error("Source reference is not mounted");return t[e.kind]}};var ms=class{constructor(e=null,t=null){this.parent=e,this.segment=t,this.children=new Map,this.registrations=new Set}},to=class{#e;#t;#r;#i;#n;#s=!0;constructor(e,{path:t,attr:n,recipient:i,order:s}){this.#e=e,this.#t=t,this.#r=n,this.#i=i,this.#n=s}get router(){return this.#e}get path(){return this.#t}get attr(){return this.#r}get recipient(){return this.#i}get active(){return this.#s}get order(){return this.#n}close(){this.active&&(this.#s=!1,this.router.unregister(this))}},ro=class{constructor({evt:e,node:t,path:n,oldvalue:i,attrsDiff:s,reason:a,fired:o,level:l,registration:u}){this.evt=e,this.node=t,this.path=n,this.oldvalue=i,this.attrsDiff=s,this.reason=a,this.fired=o,this.level=l,this.registration=u}},gs=class{#e;#t=new ms;#r=new Map;#i=0;#n=0;constructor(e){this.#e=e}get runtime(){return this.#e}get size(){return this.#i}register({path:e,attr:t=null,recipient:n}){if(typeof e!="string"||e==="")throw new TypeError(`A Data registration requires a path: ${e}`);let i=this.#t;for(let a of e.split(".")){let o=i.children.get(a);o||(o=new ms(i,a),i.children.set(a,o)),i=o}this.#n+=1;let s=new to(this,{path:e,attr:t,recipient:n,order:this.#n});return i.registrations.add(s),this.#r.set(s,i),this.#i+=1,s}unregister(e){let t=this.#r.get(e);if(t)for(this.#r.delete(e),t.registrations.delete(e),this.#i-=1;t.parent&&!t.children.size&&!t.registrations.size;)t.parent.children.delete(t.segment),t=t.parent}deliver(e){let{pathlist:t}=e;if(!t?.length||t[0]!==Pn||e.reason==="autocreate")return;let n=t.slice(1),i=e.evt==="ins"||e.evt==="del";for(let s of Array.isArray(e.node)?e.node:[e.node]){let a=i?[...n,s.label]:n,o=a.join(".");for(let[l,u]of this.#s(a,e))l.active&&l.recipient.receive(new ro({evt:e.evt,node:s,path:o,oldvalue:e.oldvalue??null,attrsDiff:e.attrs_diff??null,reason:e.reason??null,fired:e.fired??!1,level:u,registration:l}))}}#s(e,t){let n=[],i=this.#t;for(let a of e){for(let o of i.registrations)i!==this.#t&&this.#a(o,"child",t)&&n.push([o,"child"]);if(i=i.children.get(a),!i)return n.sort(([o],[l])=>o.order-l.order)}for(let a of i.registrations)this.#a(a,"node",t)&&n.push([a,"node"]);let s=[...i.children.values()];for(;s.length;){let a=s.pop();for(let o of a.registrations)this.#a(o,"container",t)&&n.push([o,"container"]);s.push(...a.children.values())}return n.sort(([a],[o])=>a.order-o.order)}#a(e,t,n){let{evt:i}=n;return e.attr===null?i==="upd_attrs"?!1:!(t==="child"&&n.fired):t==="child"?!1:t==="container"?i!=="upd_attrs":i==="ins"||i==="del"?!0:Object.hasOwn(n.attrs_diff??{},e.attr)}};var bs=class{#e;constructor(e){this.#e=e}get runtime(){return this.#e}install(e){let t=Zn(e),n=this.setterNodes(e);io(e);for(let i of n){let s=this.runtime.openBinding(i);s.hasStamp("installed")||(this.applySetter(i),s.stamp("installed"))}this.applyDefaults(t.filter(i=>i.nodeTag&&!i._getMeta("data_element")))}setterNodes(e){return Zn(e).filter(t=>t.nodeTag==="dataSetter")}applySetter(e){let t=e.absDatapath(e.pathAttribute("destination_path"));if(t===null)return;let n=e.getAttr("value")??null,i=ag(e.getAttr()),s=this.runtime.data;if(n!==null)s.setItem(t,n,i,">",!1,!0,e),n instanceof V&&e.setAttr({value:null},!1);else{let a=s.getNode(t);a?i&&a.setAttr(i,!0):s.setItem(t,null,i,">",!1,!0,e)}}applyDefaults(e){for(let t of e){let n=t.getAttr();for(let[i,s]of Object.entries(n)){if(!sg(t,i,s))continue;let a=i==="value"?n.default_value??n.default:n[`default_${i}`];a!=null&&this.#t(t,s,a)}this.#r(t,n)}}#t(e,t,n){let i=e.absDatapath(t);if(i===null)return;let[s,a=null]=i.split("?",2),o=this.runtime.data,l=o.getNode(s);if(a===null){if(l&&l.value!==null&&l.value!==void 0)return;o.setItem(s,n,null,">",!1,!0,e)}else if(l){let u=l.getAttr(a);u==null&&l.setAttr({[a]:n},!0)}else o.setItem(s,null,{[a]:n},">",!1,!0,e)}#r(e,t){let n={};for(let[a,o]of Object.entries(t))a.startsWith("attr_")&&(n[a.slice(5)]=Y(o)?Lt(e,a):e.pointerType(o)?e.getRelativeData(o):o);if(!Object.keys(n).length)return;let i=[t.value,t.src].find(a=>e.pointerType(a));if(!i)return;let s=e.absDatapath(i);s!==null&&this.runtime.data.getNode(s.split("?",1)[0])?.setAttr(n,!0,!0,!1)}};function sg(r,e,t){return e==="_meta"||Zt.has(e)||e==="default"||e.startsWith("default_")||e.startsWith("attr_")||e.endsWith("_path")?!1:r.pointerType(t)!==null}function ag(r){let e={};for(let[t,n]of Object.entries(Ft(r??{})))Zt.has(t)||t.startsWith("_")||t==="destination_path"||t==="value"||n!=null&&(e[t]=n);return Object.keys(e).length?e:null}function og(r){let e=r.builder;if(!(e instanceof Je))throw new Error(`dataSetter '${r.label}': dataSetter is not supported inside ${e.constructor._name}`)}function io(r){for(let e of Zn(r))e.nodeTag==="dataSetter"&&og(e),fg(e)}var lg=["_init","_onStart","_onBuilt","_delay","_timing","_userChanges"],ug=new Set(["dataFormula","dataController","dataRpc","dataRemote"]),cg=["_onCalling","_onResult","_onError"],dg=["_delay","_timing","_userChanges"],no=["_init","_onBuilt","_onStart"];function fg(r){let e=s=>r.getAttr(s)!==null&&r.getAttr(s)!==void 0,t=!r._getMeta("data_element")&&typeof r.getAttr("remote")=="string";if(r.nodeTag!=="dataRpc"){let s=cg.find(a=>e(a)&&!(a==="_onCalling"&&(r.nodeTag==="dataRemote"||t)));if(s){let a=s==="_onCalling"?"dataRpc, dataRemote and remote":"dataRpc";throw new Error(`${r.nodeTag??"fragment"} '${r.label}': '${s}' is allowed only on ${a}`)}}if(ug.has(r.nodeTag)){let s=Object.entries(r.getAttr()).find(([,o])=>Ze(o));if(s)throw new Error(`${r.nodeTag} '${r.label}': '${s[0]}' is a == expression, not accepted on ${r.nodeTag}`);let a=r.nodeTag==="dataRemote"?no.find(e):null;if(a)throw new Error(`dataRemote '${r.label}': '${a}' is not accepted on dataRemote, its resolver loads when the Data is read`);for(let o of no){let l=r.getAttr(o);if(!(l==null||typeof l=="boolean"||typeof l=="number"))throw new Error(`${r.nodeTag} '${r.label}': '${o}' accepts true, false, null or a number, not ${JSON.stringify(l)}`)}return}let n=lg.find(s=>e(s)&&!(s==="_delay"&&!r._getMeta("data_element")&&r.nodeTag!=="html_button")&&!(t&&dg.includes(s)));if(!n)return;let i=no.includes(n)?"dataFormula, dataController and dataRpc":"dataFormula, dataController, dataRpc and dataRemote";throw new Error(`${r.nodeTag??"fragment"} '${r.label}': '${n}' is allowed only on ${i}`)}function Zn(r){if(r instanceof N)return r.getNodes().flatMap(t=>Zn(t));let e=[r];return r.value instanceof N&&e.push(...Zn(r.value)),e}var _s=class extends ie{static classKwargs={...ie.classKwargs,asBag:!1};static internalParams=new Set([...ie.internalParams,"binding","method","params","onCalling","onError","sync"]);constructor({binding:e,method:t,params:n,cacheTime:i,onCalling:s=null,onError:a,sync:o=!1}){super({cacheTime:i??-1}),this.binding=e,this.sync=o,this.method=t,this.params=n,this.onCalling=s,this.onError=a,this.loading=null,this.loaded=!1,this.writing=!1}resolve(e={}){let{static:t=!1}=e;return t||this.loading||this.writing?this.cachedValue:this.sync?this.expired&&!this.binding.node.requests.calling(this.onCalling)?this.cachedValue:super.resolve(e):(this.expired&&this.refresh(),this.cachedValue)}load(){let e;try{e=this.binding.callSync("data",this.method,this.params)}catch(t){this.onError(t)}return this.loaded=!0,e}refresh(){let e=this.binding.node.requests;if(!e.calling(this.onCalling))return null;let t=e.submit(this.method,this.params,i=>this.#t(i)),n=()=>{this.loading===t&&(this.loading=null)};return t.then(n,n),this.loading=t,t.catch(i=>{i?.name!=="AbortError"&&this.onError(i)}),t}#e(){let e={...this._kw};for(let[t,n]of Object.entries(this.node?.attr??{}))this.constructor.internalParams.has(t)||(e[t]=n);return this._computeEffectiveFingerprint(e)}async#t(e){let t=this.binding;if(t.closed)return;let n=this.#e(),i=await t.call("data",e);if(!(t.closed||e.ignored)){this._lastUpdate=Date.now(),this._lastEffectiveFingerprint=n,this.loaded=!0,this.writing=!0;try{this.node?this.node.setValue(i,this.cacheTime!==0):this.cachedValue=i}finally{this.writing=!1}return i}}};var pg=new Set(["destination_path","result_path","func","formula","script","if","else","_init","_onStart","_onBuilt","_delay","_timing","_userChanges","_ask","_ask_if","_ask_title","_ask_onCancel","method","timeout","_onCalling","_onResult","_onError","cacheTime","sync"]),Jn=class{#e;#t=null;#r=null;constructor(e){this.#e=e}get binding(){return this.#e}debounce(e,t){this.#r?.();let n=null,i=setTimeout(()=>{n(),this.#r=null,t()},e);n=this.binding.track(()=>clearTimeout(i)),this.#r=()=>{clearTimeout(i),n(),this.#r=null}}startTiming(e,t){if(this.#t?.(),!(e>0))return;let n=setInterval(t,e*1e3),i=this.binding.track(()=>clearInterval(n));this.#t=()=>{clearInterval(n),i(),this.#t=null}}cancel(){this.#r?.(),this.#t?.()}},Zr=class{#e;#t=[];#r=new Set;#i;#n=null;#s=!1;constructor(e){this.#e=e,this.#i=new Jn(e),e.track(()=>{this.cancel(),this.#p(),this.#f()})}get binding(){return this.#e}get node(){return this.binding.node}get kind(){throw new Error("Provider.kind is defined by FormulaProvider, ControllerProvider, RpcProvider and RemoteProvider")}register(){let e=this.node,t=e.getAttr("_onStart");if(typeof t=="number"&&!(Number.isFinite(t)&&t>=0))throw new Error(`${e.nodeTag} '${e.label}': _onStart must be true or a delay in ms not below 0: ${t}`);this.#p();let n=this.binding.runtime.router,i=Qe(e,e.getAttr("_timing"));for(let[s,a]of e.pointers()){if(s==="datapath")continue;let o=e.absDatapath(a);if(o===null)continue;let[l,u=null]=o.split("?",2),c=n.register({path:l,attr:u,recipient:this});this.#t.push(c),(s==="_timing"||i.has(s))&&this.#r.add(c)}this.#t.push(...this.binding.runtime.subscriptions.subscribeNode(e,(s,a,o)=>l=>{let u={kind:"subscription",topic:o,payload:l};if(this.#o("_userChanges")&&o!=="node")return;let c=this.#o("_delay");c>0?this.#i.debounce(c,()=>this.invoke(u)):this.invoke(u)})),this.#a(),this.kind==="remote"&&this.invoke({kind:"install",change:null})}receive(e){if(this.#r.has(e.registration)){this.#a();return}if(this.#o("_userChanges")&&e.level!=="node")return;let t={kind:"data",change:e},n=this.#o("_delay");n>0?this.#i.debounce(n,()=>this.invoke(t)):this.invoke(t)}invoke(e){if(this.binding.closed)return;let t=this.node,n=this.kind==="formula",i=this.kind==="rpc",s=this.kind==="remote",a=this.readArguments(e);e.askResult&&(Object.assign(a,e.askResult),a._askResult=e.askResult);let o=t.getAttr("_ask"),l=this.binding.runtime.askDialog;if(o&&!e.askDone&&l.required(this.binding,o,a,"_ask"))return l.show(this.binding,o,a,t.getAttr("_ask_title")??"Warning").then(h=>{if(!this.binding.closed){if(h===null){let m=t.getAttr("_ask_onCancel");m&&this.#l("_ask_onCancel",m,m,a,!0);return}return this.invoke({...e,askDone:!0,askResult:h})}});let[u,c]=[n?"formula":"script",t.getAttr(n?"formula":"script")],d=t.getAttr("_if");if(d&&!this.#l("_if",d,`return (${d})`,a,!1)){if(s&&this.#f(),[u,c]=["_else",t.getAttr("_else")],!c)return;if(i||s){this.#l(u,c,c,a,!0);return}}if(i)return this.#d(a);if(s)return this.#u(a);let f=t.getAttr("func"),p;if(c)p=this.#l(u,c,n?`return ${c}`:c,a,!0);else if(f==null){if(!n)return;p=new V(ws(a))}else{let{group:h,method:m}=this.binding.runtime.logicRegistry.resolve(f,t);p=n?m.call(h,a):m.call(h,t,a)}n&&t.setRelativeData(t.pathAttribute("result_path"),p)}readArguments(e){let t=this.node,[,n]=t.rootBuilder.runtimeValues(t),i=Object.fromEntries(Object.entries(n).filter(([l])=>!pg.has(l)&&!l.startsWith("subscribe_")&&!l.startsWith("selfsubscribe_"))),s={...e.kind==="subscription"?e.payload:{},...this.binding.runtime.renderer.references.resolveArguments(i)};e.kind==="subscription"&&(s._subscription_kwargs=e.payload);let a=e.change??null,o=a?a.level:e.kind==="subscription"?e.topic:e.kind;return s._node=a?a.node:null,s._triggerpars={kw:a,trigger_reason:o},s._reason=o,e.kind==="click"&&Object.assign(s,hg(e)),s}cancel(){this.#i.cancel()}#a(){this.#i.startTiming(this.#o("_timing"),()=>this.invoke({kind:"timing",change:null}))}#o(e){let t=this.node,n=t.getAttr(e);return Y(n)?Lt(t,e):t.pointerType(n)?t.getRelativeData(n):n??null}#l(e,t,n,i,s){let a=[...s?["_kwargs"]:[],..._c,...wc,...Object.keys(ws(i))];return this.binding.runtime.inlineCompiler.compile(this.node,e,t,a,n)({...i,_kwargs:i})}async#d(e){let t=this.node,[n,i,s]=["_onCalling","_onResult","_onError"].map(o=>t.getAttr(o)),a=t.requests;if(a.calling(n?()=>this.#l("_onCalling",n,n,e,!0):null))return a.submit(this.#o("method"),ws(e),o=>this.#m(o,e,i,s))}async#m(e,t,n,i){if(this.binding.closed)return;let s=this.node,a=this.#o("timeout"),o=a>0?setTimeout(()=>{let c=new Error(`${s.nodeTag} '${s.label}': no answer within ${a} ms`);c.name="TimeoutError",e.controller.abort(c)},a):null,l;try{l={result:await this.binding.call("data",e)}}catch(c){l={error:c}}if(clearTimeout(o),this.binding.closed||e.ignored)return;if("error"in l){if(!i)throw l.error;this.#l("_onError",i,i,{...t,error:l.error},!0);return}let{result:u}=l;s.getAttr("result_path")!=null&&s.setRelativeData(s.pathAttribute("result_path"),u),n&&this.#l("_onResult",n,n,{...t,result:u},!0)}#u(e){this.#f();let t=this.#s;this.#s=!1;let n=this.node,i=n.absDatapath(n.pathAttribute("destination_path"));if(i===null)return;let s=n.getAttr("_onCalling"),a=new _s({binding:this.binding,method:this.#o("method"),params:ws(e),cacheTime:this.#o("cacheTime"),sync:this.#o("sync")!==!1&&this.binding.runtime.gramlot.rpc.supportsCallSync,onCalling:s?()=>this.#l("_onCalling",s,s,e,!0):null,onError:o=>{throw new Error(`${n.nodeTag} '${n.label}': dataRemote '${a.method}' failed: ${o.message}`,{cause:o})}});this.binding.runtime.data.setResolver(i,a),this.#n={path:i,resolver:a},t&&a.refresh()}#f(){if(!this.#n)return;let{path:e,resolver:t}=this.#n;this.#n=null,this.#s=t.loaded||t.loading!==null;let n=this.binding.runtime.data.getNode(e);n?.resolver===t&&(n.resolver=null)}#p(){for(let e of this.#t.splice(0))e.close();this.#r.clear()}},ys=class extends Zr{get kind(){return"formula"}},vs=class extends Zr{get kind(){return"controller"}},ks=class extends Zr{get kind(){return"rpc"}},Es=class extends Zr{get kind(){return"remote"}},_c=["_node","_triggerpars","_reason","_subscription_kwargs","_askResult"],wc=["_evt","button_counter","button_shift","button_ctrl","button_alt","button_meta"];function ws(r){let e={...r};for(let t of[..._c,...wc])delete e[t];return e}function hg({event:r,counter:e}){return{_evt:r,button_counter:e,button_shift:!!r.shiftKey,button_ctrl:!!r.ctrlKey,button_alt:!!r.altKey,button_meta:!!r.metaKey}}var mg=[[null,/(\W|^)GET (?:\s*)(\^?[\w.#@$?-]+)/g,"$1this.GET('$2')"],[/;SET/g,/(\W|^)SET (?:\s*)(\^?[\w.#@$?-]+)(?:\s*)=(?:\s*)([^;\r\n]*)(;?)/gm,"$1this.SET('$2', $3)$4 "],[/;PUT/g,/(\W|^)PUT (?:\s*)(\^?[\w.#@$?-]+)(?:\s*)=(?:\s*)([^;\r\n]*)(;?)/gm,"$1this.PUT('$2', $3)$4 "],[/;FIRE_AFTER/g,/(\W|^)FIRE_AFTER (?:\s*)(\^?[\w.#@$?-]+)(?:\s*)=(?:\s*)([^;\r\n]*)(;?)/g,"$1this.FIRE_AFTER('$2', $3)$4 "],[/;FIRE_AFTER/g,/(\W|^)FIRE_AFTER (?:\s*)(\^?[\w.#@$?-]+)(?:\s*)(;?)/g,"$1this.FIRE_AFTER('$2')$3 "],[/;FIRE/g,/(\W|^)FIRE (?:\s*)(\^?[\w.#@$?-]+)(?:\s*)=(?:\s*)([^;\r\n]*)(;?)/g,"$1this.FIRE('$2', $3)$4 "],[/;FIRE/g,/(\W|^)FIRE (?:\s*)(\^?[\w.#@$?-]+)(?:\s*)(;?)/g,"$1this.FIRE('$2')$3 "]],gg=/(\W|^)PUBLISH (?:\s*)(\^?[\w.#@$?-]+)/,bg=new Set(["arguments","await","break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","eval","export","extends","false","finally","for","function","if","implements","import","in","instanceof","interface","let","new","null","package","private","protected","public","return","static","super","switch","this","throw","true","try","typeof","var","void","while","with","yield"]),As=class{#e;#t=new Map;constructor(e){this.#e=e}get runtime(){return this.#e}get size(){return[...this.#t.values()].reduce((e,t)=>e+t.size,0)}preprocess(e,t,n){let i=n.trim();if(gg.test(i))throw new Error(`${Kn(e,t)}: the PUBLISH macro is excluded from Gramlot`);let s=i.replace(/\$(\d+)/g,(a,o)=>`arguments[${parseInt(o,10)-1}]`);for(let[a,o,l]of mg)a&&(s=s.replace(a,`; ${a.source.slice(1)}`)),s=s.replace(o,l);return s!==i&&console.warn(`${Kn(e,t)}: legacy macros are deprecated; write this.GET(path), this.SET(path, value), this.PUT(path, value), this.FIRE(path, value), this.FIRE_AFTER(path, value) and arguments[n] in place of GET, SET, PUT, FIRE, FIRE_AFTER and $n`),s}compile(e,t,n,i,s=n){if(e.activatedCode(t)!==n)throw new Error(`${Kn(e,t)}: inline code runs only as received with the Source (main or a remote Source); a text written later is not run: use named logic`);let a=this.#t.get(e);a||(a=new Map,this.#t.set(e,a),this.runtime.bindingFor(e).track(()=>this.release(e)));let o=a.get(t);o?.source!==s&&(o={source:s,text:this.preprocess(e,t,s),key:null,run:null},a.set(t,o));let l=i.filter(_g),u=l.join(",");if(o.key!==u){let c=wg(e,t,o.text,l);o.key=u,o.run=d=>c.apply(e,l.map(f=>d[f]))}return o.run}compileExpression(e,t,n){let i=n.slice(2).trim(),s=xe(e.getAttr()).filter(([,o])=>!Ze(o)),a=this.compile(e,t,n,[...s.map(([o])=>o).filter(o=>o!=="_F"),"_F"],`return ${i}`);return o=>{let l={};for(let[u,c]of s)Object.hasOwn(o,u)?l[u]=o[u]:l[u]=e.pointerType(c)?e.getRelativeData(c):c;return a({...l,_F:(u,c)=>this.runtime.gramlot.format(u,c)})}}compilePointerExpression(e,t,n,i){let s=this.compile(e,t,n,["_pointerValues","_F"],`return (${i}
|
|
58
|
+
`:""}`:super.renderedItem(e,t,a,i)}};var or=class extends rr{#e=new WeakMap;#t=new WeakMap;get inlineCompiler(){return null}getRender(e){return this.renders.has(e)||(e instanceof Mt?this.addRender(e,this):e instanceof $t&&this.addRender(e,new Wn(e,this))),super.getRender(e)}render(e,t={}){if(e._getMeta("data_element"))return null;let[n,i]=e.rootBuilder.runtimeValues(e),s=this.getRender(e.builder),[a,o]=s._handleMeta(e,i);return e._getMeta("subbuilder")||(o=s.adaptAttrs(o)),s.renderedItem(e,e.value instanceof N?this.renderChildren(e.value,t):n,o,{tag:a,...t})}_handleMeta(e,t){let n=this.builder.constructor.dialectPrefixes,i=this.evaluateExpressions(e,t);Gr(e,i,n);let[s,a]=super._handleMeta(e,sc(e,i,n));if(Wr(e,a,n),e.nodeTag==="webcomponent"){s=gt(e.getAttr());let{code:u,...c}=a;a=c}if(e._getMeta("subbuilder")){let u=ls(a);return e._getMeta("subbuilder")==="html"&&(u.xmlns=Vn),[s,u]}let[o,l]=ac(s,a);return Object.keys(l).length&&this.#e.set(e,l),[s,o]}evaluateExpressions(e,t){let n=this.inlineCompiler,i=(a,o)=>n?n.compileExpression(e,a,o)(t):null,s={...t};for(let[a,o]of xe(e.getAttr()))Ze(o)&&Object.hasOwn(s,a)&&(s[a]=i(a,o));return Ze(e.value)&&this.#t.set(e,i("",e.value)),s}expressionValue(e,t){return Ze(e.value)?this.#t.get(e)??null:t}restoreNativeAttributes(e,t){let n=this.#e.get(e);return n?(this.#e.delete(e),{...t,...Xr(n)}):t}adaptAttrs(e){let{_meta:t,...n}=e,i=`${this.builder.constructor._name}_`,s=this.builder.constructor.dialectPrefixes,a={},o={};for(let[l,u]of Object.entries(Ft(n))){if(u==null)continue;if(l.startsWith(i))throw new Error(`${l}: the attribute prefix '${i}' is not accepted; use the prefix '${s[0]}'`);let c=s.find(d=>l.startsWith(d));c?a[l.slice(c.length)]=u:o[l]=u}return zn({...super.adaptAttrs(o),...a})}renderedItem(e,t,n,i={}){let s;[t,s]=Hn(this.expressionValue(e,t),this.restoreNativeAttributes(e,n));let{_text:a,...o}=s;Array.isArray(t)&&a!=null&&(t=[this._escapeText(Hr(a)),...t]);let l=e.parentNode?._getMeta("subbuilder")==="html"?{xmlns:Ye,...o}:o;return super.renderedItem(e,t,l,i)}finalize(e,t=null,n={}){if(!n.doctype)return super.finalize(e,t,n);let i=this._composeStringFragments(e),s=this.builder.source.getNodes().filter(a=>!a._getMeta("data_element"));return s.length===1&&s[0].nodeTag==="html"||(i=`<html>${i}</html>`),super.finalize(`<!doctype html>${i}`,t,n)}};var lc={document_format:{name:"builder_grammar",version:"1.1"},grammar:{name:"binding",version:null,title:"Gramlot binding",description:"Gramlot Data declarations and the plain HTML button; loaded after the HTML grammar."},abstracts:{},elements:{dataSetter:{doc:"Initial Data value, written literally at destination_path.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"destination_path",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"value",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"any"},has_default:!0,default:null},{name:"attr",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataFormula:{doc:"Computed Data value written at result_path; formula is inline, func is a name.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"result_path",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"formula",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"builtins",name:"NoneType"}]},has_default:!0,default:null},{name:"func",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"builtins",name:"NoneType"}]},has_default:!0,default:null},{name:"params",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataController:{doc:"Side effects on Data; script is inline, func is a name.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"script",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"builtins",name:"NoneType"}]},has_default:!0,default:null},{name:"func",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"builtins",name:"NoneType"}]},has_default:!0,default:null},{name:"params",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataRpc:{doc:"Server endpoint called through gramlot.rpc; the value is written at result_path when given.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"method",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"result_path",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"str"},{kind:"type",module:"builtins",name:"NoneType"}]},has_default:!0,default:null},{name:"timeout",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"int"},{kind:"type",module:"builtins",name:"float"},{kind:"type",module:"builtins",name:"NoneType"}]},has_default:!0,default:null},{name:"params",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},dataRemote:{doc:"Data node resolved by a server endpoint through gramlot.rpc, on first read and again when cacheTime expires; with sync (default) the read waits for the answer when the transport supports it.",sub_tags:"",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"destination_path",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"method",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"cacheTime",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"union",items:[{kind:"type",module:"builtins",name:"int"},{kind:"type",module:"builtins",name:"float"},{kind:"type",module:"builtins",name:"NoneType"}]},has_default:!0,default:null},{name:"sync",kind:"positional_or_keyword",role:"attribute",annotation:{kind:"type",module:"builtins",name:"bool"},has_default:!0,default:!0},{name:"params",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{data_element:!0}},html_button:{doc:"Plain native HTML button without Gramlot click mechanisms.",sub_tags:"a,abbr,area,audio,b,bdi,bdo,br,button,canvas,cite,code,data,datalist,del_,dfn,em,embed,i,iframe,img,input,ins,kbd,label,link,map,mark,meta,meter,noscript,object,output,picture,progress,q,ruby,s,samp,script,select,selectedcontent,slot,small,span,strong,sub,sup,template,textarea,time,u,var,video,wbr",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"kwargs",kind:"var_keyword",role:"attribute",annotation:null,has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:{render_tag:"button"}}}};var uc={document_format:{name:"builder_grammar",version:"1.1"},grammar:{name:"webcomponent",version:null,title:"Gramlot webcomponent",description:"An explicitly loaded autonomous custom element."},abstracts:{},elements:{webcomponent:{doc:"Create the custom-element tag named by literal code.",sub_tags:"*",parent_tags:null,inherits_from:null,ns:null,attributes:{parameters:[{name:"code",kind:"keyword_only",role:"attribute",annotation:{kind:"type",module:"builtins",name:"str"},has_default:!1},{name:"attr",kind:"var_keyword",role:"attribute",annotation:{kind:"any"},has_default:!1}],accepts_var_keyword:!0,accepts_var_positional:!1},node_label:null,collection_key:null,_meta:null}}};function Me(){return Array.from(globalThis.crypto.getRandomValues(new Uint8Array(16)),r=>r.toString(16).padStart(2,"0")).join("")}var Hm="data is forbidden: write dataSetter for a Data value or html_data for the HTML5 <data> element",Wm=new Set,Gm=new Set(["serverpath","dbenv","shared_id"]),Xm=["formsubscribe_"],Ym={dataSetter:"destination_path",dataFormula:"result_path",dataRpc:"result_path",dataRemote:"destination_path"},Zm={dataFormula:"formula",dataController:"script"};function cc(r,e){if(["input","textarea","select","webcomponent"].includes(r)&&Y(e.value))return"'value' does not accept pointer suffixes; use an ordinary value pointer";if(r==="html_button"&&Object.keys(e).some(i=>["action","ask","_delay","fire"].includes(i)||i.startsWith("fire_")))return"plain HTML button: use button for action, ask, fire or _delay";if(Object.hasOwn(e,"ask")&&!["button","toggleButton","dropDownButton","menuline"].includes(r))return"'ask' is supported on buttons";if(Object.hasOwn(e,"_ask")&&!["dataController","dataFormula","dataRpc"].includes(r))return"'_ask' requires a controller, formula or RPC";if(["dataSetter","dataRemote"].includes(r)&&Object.keys(e).some(i=>i.startsWith("subscribe_")||i.startsWith("selfsubscribe_")))return"topic subscriptions are supported on controllers, formulas, RPCs and rendered elements";let t=Ym[r];if(t&&String(e[t]??"").includes("?"))return`'${t}' does not accept '?attr': '${e[t]}'`;let n=Zm[r];return n&&e[n]!=null&&e.func!=null?`'func' and '${n}' cannot be declared on the same node`:n&&e._if!=null&&e.func!=null?"'_if' is inline and cannot be declared with 'func': write the condition in the method":null}function dc(r){return Object.keys(r).find(e=>Gm.has(e)||Xm.some(t=>e.startsWith(t)))}var Je=class r extends Mt{static _name="gramlot";static _sourceClass=ge;static{this.defineGrammar(lc)}static{this.defineGrammar(uc)}static{this.defineGrammar(ss.toDocument())}static get dialectPrefixes(){let e=[];for(let t=Object.getPrototypeOf(r);t&&t!==Function.prototype;t=Object.getPrototypeOf(t))Object.hasOwn(t,"_name")&&t._name&&e.push(`${t._name}_`);return e}constructor(e=null,{collections:t=[],auth:n=null,nameSyntax:i=Un}={}){if(!(i instanceof ir))throw new TypeError(`nameSyntax must be a NameSyntax, not ${i}`);super(e),this._binding=null,this._auth=n,this._nameSyntax=i;for(let s of t)this.loadCollection(s)}get auth(){return this._auth}get nameSyntax(){return this._nameSyntax}get binding(){return this._binding}set binding(e){this._binding=e}evaluatePointerExpression(e,t,n,i,s){return this.binding?this.binding.inlineCompiler.compilePointerExpression(e,t,n,i.text)(s):null}nodeById(e){if(!this.binding)return super.nodeById(e);let t=this.binding.nodeIds.get(e);if(!t)throw new Error(`nodeId not found: ${e}`);return t.builder.wrapSource(t)}loadCollection(e){return this.loadGrammar(e instanceof sr?e.toDocument():e),this}schemaTag(e){let t=e.toLowerCase(),n=r.dialectPrefixes;if(t.startsWith(`${r._name}_`))throw new Error(`${e}: the tag prefix '${r._name}_' is not accepted; use the prefix '${n[0]}'`);if(Wm.has(t))throw new Error(`${e}: excluded from Gramlot`);let i=this.schemaTagNames[t];if(i)return i;for(let s of n)if(t.startsWith(s)&&this.schemaTagNames[t.slice(s.length)])return t;return null}bagCall(e,t,n,i){return super.bagCall(e,this.#e(t),n,i)}commandOnNode(e,t,n,i){return super.commandOnNode(e,this.#e(t),n,i)}validateNodeValues(e,t,n={}){if(this.schema[e]?._meta?.gramlot_component&&Y(n.value))throw new Error("'value' does not accept pointer suffixes");e==="webcomponent"&>(n);let i=dc(n);if(i)throw new Error(`${e}: attribute '${i}' is excluded from Gramlot`);let s=cc(e,n);if(s)throw new Error(`${e}: ${s}`);return super.validateNodeValues(e,t,n)}validateNode(e,t={}){if(e._getMeta("gramlot_component")&&Y((t.attrs??e.getAttr()).value))throw new Error("'value' does not accept pointer suffixes");e.nodeTag==="webcomponent"&>(t.attrs??e.getAttr());let n=dc(t.attrs??e.getAttr());if(n)throw new Error(`${e.nodeTag} '${e.label}': attribute '${n}' is excluded from Gramlot`);let i=cc(e.nodeTag,t.attrs??e.getAttr());if(i)throw new Error(`${e.nodeTag} '${e.label}': ${i}`);return super.validateNode(e,t)}_validateChildren(e,t,n,i){return super._validateChildren(e,t,n.map(s=>s==="html_button"?"button":s),i)}_countsForGrammar(e){return e===this.schema.button||!e?._meta?.gramlot_component&&e!==this.schema.webcomponent&&super._countsForGrammar(e)}setChild(e,t,n,i,s=null){i=Object.fromEntries(Object.entries(i??{}).map(([l,u])=>[l,me(u)instanceof Ce?this.reference(u):u]));let o=t==="dataSetter"&&i?.value!==null&&typeof i?.value=="object"&&Object.getPrototypeOf(i.value)===Object.prototype?{...i,value:new V(i.value)}:i;return super.setChild(e,t,n,o,s)}#e(e){if(e==="data")throw new Error(Hm);if(this.schemaTagNames[e.toLowerCase()]===e)return e;let t=r.dialectPrefixes.find(n=>e.startsWith(n));return this.schemaTagNames[e.slice(t.length)]}get renderer_html(){return new or(this)}create(){this.setup(this.data),this.main(this.root)}computeLogic(){}promoteNodeValue(e,t,n){let i=t!=null?{_text:t}:null;e.setValue(n,!0,i,!0)}reference(e,t="node"){if(e=me(e),!(e instanceof Ce)||!["node","dom"].includes(t))throw new TypeError("Reference requires an element and node/dom kind");let n=e.getAttr("__ref");return n==null&&(n=Me(),e.setAttr({__ref:n})),{$gramlotRef:n,kind:t}}toTytx(){return ne(this.auth===null?this.source:this.source.authorizedCopy(this.auth))}};var Jm=new Set(["input","select","textarea"]),Km=["type","multiple","group"];function fc(r,e){let t=r.getAttr(e);return r.pointerType(t)?r.getRelativeData(t):t}var Te=class r{static liveWrites=!1;static writesDefault=!0;static preservesUnchangedValue=!1;#e;#t=!1;#r;#i;#n=!1;#s=!1;#a=!1;static for(e,t){let n=r.classFor(t.element,t.attrs);return n?new n(e,t):null}static classFor(e,t){if(e.namespaceURI!==Ye)return null;if(e.constructor.gramlotComponent)return e.constructor.gramlotComponent.parameters.value?.binding!=="twoWay"?null:e.control.type==="radio"?Ka:Xa;if(e.localName==="textarea")return lt;if(e.localName==="select")return Gn;if(e.localName!=="input")return null;let n=t.type==null?"text":String(t.type).toLowerCase();return Object.hasOwn(pc,n)?pc[n]:lt}static shape(e,t){return e?.constructor.gramlotComponent?.parameters.value?.binding==="twoWay"&&e.control.type==="radio"?JSON.stringify([t.group??null]):e?.namespaceURI!==Ye||!Jm.has(e.localName)?null:JSON.stringify(Km.map(n=>t[n]??null))}constructor(e,t){this.#r=e,this.#i=t}get binding(){return this.#r}get element(){return this.#i.element}get node(){return this.binding.node}get eventElement(){return this.element}get resolved(){return this.#i.resolved}get live(){return!!this.resolved.live}get writeEvent(){return this.constructor.liveWrites&&this.live?"input":"change"}project(e,t){if(this.#s){this.#a=!0;return}this.constructor.preservesUnchangedValue&&this.#t&&this.same(this.#e,e)||(this.#e=e,this.#t=!0,!(this.#n&&this.same(this.read(),e))&&(this.constructor.writesDefault&&!this.node.pointerType(this.node.getAttr("value"))&&this.writeDefault(e),this.write(e)))}read(){return this.element.value}write(e){let t=e==null?"":String(e);this.element.value!==t&&(this.element.value=t)}writeDefault(e){let t=e==null?"":String(e);this.element.localName==="textarea"?this.#i.text.data!==t&&(this.#i.text.data=t):this.element.defaultValue!==t&&(this.element.defaultValue=t)}same(e,t){return Object.is(e,t)}commit(e,t=this.read()){if(!this.binding.closed){this.#n=!0;try{this.binding.runtime.renderer.html.writeParameter(this.node,"value",t)}finally{this.#n=!1}}}attach(){for(let e of["input","change","compositionstart","compositionend"])this.eventElement.addEventListener(e,this)}detach(){for(let e of["input","change","compositionstart","compositionend"])this.eventElement.removeEventListener(e,this);this.#a=!1}refresh(){}handleEvent(e){if(!this.binding.closed){if(e.type==="compositionstart"){this.#s=!0;return}if(e.type==="compositionend"){this.#s=!1,this.writeEvent==="input"&&this.commit(e),this.#a&&(this.#a=!1,this.binding.runtime.renderer.project(this.node));return}this.#s||e.isComposing||e.type===this.writeEvent&&this.commit(e)}}},Xa=class extends Te{static writesDefault=!1;static preservesUnchangedValue=!0;get eventElement(){return this.element.control}attach(){this.element.setPageContext(hc(this)),super.attach()}project(e,t){this.element.shouldProjectControlValue(e)&&super.project(e,t)}same(e,t){return this.element.sameControlValue(e,t)}detach(){this.element.releaseControl(),super.detach()}commit(e){this.binding.closed||this.element.control.disabled||this.element.control.readOnly||mc(this.element,this.element.acceptControlValue(),t=>super.commit(e,t.value))}get writeEvent(){if(this.element.commitOnChange)return"change";let e=this.element.control;return this.live&&(e.localName==="textarea"||["text","password","range","color"].includes(e.type))?"input":"change"}read(){return this.element.readControlValue()}write(e){this.element.writeControlValue(e)}handleEvent(e){if(super.handleEvent(e),!e.composed&&!this.binding.closed&&["input","change"].includes(e.type)){let t=this.element.ownerDocument.defaultView.Event;this.element.dispatchEvent(new t(e.type,{bubbles:!0,composed:!0}))}}},lt=class extends Te{static liveWrites=!0},Ya=class extends Te{static liveWrites=!0;read(){return this.element.value===""?null:Number(this.element.value)}commit(e){this.element.validity.badInput||super.commit(e)}},Za=class extends Te{static liveWrites=!0;read(){return Number(this.element.value)}},Gn=class extends Te{static writesDefault=!1;read(){return this.element.multiple?[...this.element.selectedOptions].map(e=>e.value):this.element.selectedIndex===-1?null:this.element.value}write(e){let t=this.element;if(t.multiple){if(e!=null&&!Array.isArray(e))throw new TypeError(`${this.node.nodeTag} '${this.node.label}': a multiple select requires an array`);let n=new Set((e??[]).map(String));for(let i of t.options){let s=n.has(i.value);i.selected!==s&&(i.selected=s)}}else e==null?t.selectedIndex!==-1&&(t.selectedIndex=-1):(t.selectedIndex===-1||t.value!==String(e))&&(t.value=String(e))}same(e,t){return Array.isArray(e)?Array.isArray(t)&&t.length===e.length&&t.every((n,i)=>Object.is(n,e[i])):super.same(e,t)}},lr=class extends Te{read(){return this.element.value===""?null:this.element.value}},Ja=class extends Te{},us=class extends Te{static writesDefault=!1;read(){return this.element.checked}write(e){let t=!!e;this.element.checked!==t&&(this.element.checked=t)}same(e,t){return e===!!t}attach(){let e=this.node;if(e.getAttr("checked")!=null&&e.pointerType(e.getAttr("value"))==="^")throw new TypeError(`${e.nodeTag} '${e.label}': checked and a ^ value are two sources`);super.attach()}},cs=class extends us{#e=null;#t=!1;get groups(){return this.binding.runtime.renderer.radioGroups}attach(){let e=this.node,t=this.resolved.group??null,n=Qa(e);if(t!=null){if(e.getAttr("name")!=null)throw new TypeError(`${e.nodeTag} '${e.label}': name and group are two names`);this.#r(t,n)}super.attach(),t!=null&&(this.#e=this.groups.join(this,t,n),this.element.setAttribute("name",this.#e))}detach(){this.#e!==null&&(this.groups.leave(this),this.element.removeAttribute("name"),this.#e=null),super.detach()}refresh(){if(this.#e===null)return;let e=this.resolved.group,t=Qa(this.node);this.groups.nameOf(e,t)!==this.#e&&(this.#r(e,t),this.groups.leave(this),this.#e=this.groups.join(this,e,t),this.element.setAttribute("name",this.#e))}#r(e,t){let n=this.node;if(fc(n,"value")&&this.groups.peersOf(e,t).some(i=>!i.binding.closed&&i.read()))throw new Error(`${n.nodeTag} '${n.label}': several true values in radio group '${e}'`)}project(e,t){let n=!this.#t;this.#t=!0;let i=this.read();super.project(e,t),!n&&!i&&this.read()&&this.turnOffPeers()}commit(e){let t=this.read();super.commit(e),t&&!this.binding.closed&&this.turnOffPeers()}turnOffPeers(){if(this.#e!==null)for(let e of this.groups.peers(this)){if(this.binding.closed)return;e.binding.closed||(e.element.checked&&(e.element.checked=!1),fc(e.node,"value")&&e.commit(null))}}},Ka=class extends cs{static writesDefault=!1;get host(){return super.element}get element(){return this.host.control}project(e,t){this.host.shouldProjectControlValue(e)&&super.project(e,t)}commit(e){this.binding.closed||this.element.disabled||this.element.readOnly||mc(this.host,this.host.acceptControlValue(),()=>super.commit(e))}read(){return this.host.readControlValue()}write(e){this.host.writeControlValue(e)}attach(){this.host.setPageContext(hc(this)),super.attach(),this.element.addEventListener("keydown",this)}detach(){this.host.releaseControl(),this.element.removeEventListener("keydown",this),super.detach()}handleEvent(e){if(!this.binding.closed){if(e.type==="keydown"){if(this.resolved.group==null||!["ArrowLeft","ArrowUp","ArrowRight","ArrowDown"].includes(e.key))return;let t=this.groups.peersOf(this.resolved.group,Qa(this.node)).filter(a=>!a.binding.closed&&!a.element.disabled),n=t.indexOf(this);if(n<0)return;e.preventDefault();let i=["ArrowLeft","ArrowUp"].includes(e.key)?-1:1,s=t[(n+i+t.length)%t.length];s.element.focus(),s.element.click();return}if(super.handleEvent(e),!e.composed&&!this.binding.closed&&["input","change"].includes(e.type)){let t=this.host.ownerDocument.defaultView.Event;this.host.dispatchEvent(new t(e.type,{bubbles:!0,composed:!0}))}}}},ds=class{#e;#t=new Map;#r=new Map;#i=new WeakMap;#n=0;constructor(e){this.#e=e}join(e,t,n){let i=this.nameOf(t,n);return this.#t.has(i)||this.#t.set(i,new Set),this.#t.get(i).add(e),this.#r.set(e,i),i}leave(e){let t=this.#r.get(e);this.#r.delete(e);let n=this.#t.get(t);n?.delete(e),n?.size===0&&this.#t.delete(t)}peers(e){let t=this.#r.get(e);return[...this.#t.get(t)??[]].filter(n=>n!==e)}peersOf(e,t){return[...this.#t.get(this.nameOf(e,t))??[]]}nameOf(e,t){t!==null&&!this.#i.has(t)&&this.#i.set(t,this.#n++);let n=t===null?"page":`form${this.#i.get(t)}`;return`gramlot-${this.#e.instanceId}-${n}-${e}`}};function Qa(r){for(let e=r;e;e=e.parentNode){let t=e.getAttr()??{};if(t.formId!=null||t.form===!0)return e}return null}var pc={text:lt,password:lt,email:lt,url:lt,tel:lt,search:lt,number:Ya,range:Za,color:Ja,date:lr,time:lr,month:lr,week:lr,"datetime-local":lr,checkbox:us,radio:cs,hidden:null,file:null,button:null,submit:null,reset:null,image:null};function hc(r){let{binding:e,node:t}=r,n=e.runtime.gramlot,i=(s,a,o,l=!1)=>{if(!l&&/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(a)){let{group:u,method:c}=n.src.logicRegistry.resolve(a,t);return c.call(u,t,o)}return e.runtime.inlineCompiler.compile(t,s,a,Object.keys(o),l?`return (${a});`:a)(o)};return{locale:n.locale,timeZone:n.timeZone,createDecimal:It,isDecimal:ve,getDecimalLibrary:Ba,isActive:()=>!e.closed,callLogic:(s,a)=>{let{group:o,method:l}=n.src.logicRegistry.resolve(s,t);return l.call(o,t,a)},format:(s,a)=>n.format(s,a),invoke:i,remote:(s,a,o)=>n.rpc.call("data",s,a,{signal:o}),validationCurrent:()=>{let s=t.getAttr("value"),a=t.pointerType(s)?t.absDatapath(s):null;return()=>!e.closed&&t.getAttr("value")===s&&(a===null||t.absDatapath(s)===a)},finishValidation:({ok:s,result:a,rules:o})=>{if(e.closed)return;if(s)for(let u of a.datachanges)t.getRelativeData(".").update(u);let l=s?"validate_onAccept":"validate_onReject";if(o[l]){let u=c=>console.error("Validation notification failed:",c);try{let c=Object.fromEntries(Object.entries(o).map(([f,p])=>[f.slice(9),p])),d=i(l,o[l],{value:a.value,result:a,validations:c,userChange:!0});d instanceof Promise&&d.catch(u)}catch(c){u(c)}}},checkDataPatch:s=>{if(!(s instanceof V))throw new TypeError("Validation data changes must be a Bag.");if(!(t.getRelativeData(".")instanceof V))throw new TypeError("Validation data changes require a Bag datapath.")}}}function mc(r,e,t){let n=i=>{i.ok&&i.isCurrent()&&(t(i),r.finishValidation(i))};e instanceof Promise?e.then(n).catch(i=>console.error("Validation notification failed:",i)):n(e)}var eo=Symbol("source text"),gc={xmlns:"http://www.w3.org/2000/xmlns/",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},Qm=new Set(["allowFullscreen","async","autofocus","autoplay","checked","controls","default","defer","disabled","formNoValidate","hidden","inert","isMap","itemscope","loop","multiple","muted","noModule","noValidate","open","playsInline","readOnly","required","reversed","selected"]),eg=new Set(["checked","muted","selected","value"]),tg=new Map([["allowfullscreen","allowFullscreen"],["formnovalidate","formNoValidate"],["ismap","isMap"],["nomodule","noModule"],["novalidate","noValidate"],["playsinline","playsInline"],["readonly","readOnly"]]);function rg(r){let e=r.replace(/-([a-z])/g,(t,n)=>n.toUpperCase());return tg.get(e.toLowerCase())??e}var fs=class{constructor({metadataAttributes:e=[],invokeScript:t=null}={}){this.invokeScript=t,this.metadataAttributes=new Set([...Zt,"_text",...e])}definition(e){let t=e.builder,i={...t.schema[t.schemaTag(e.nodeTag)]._meta,...e.getAttr("_meta")},s=e.nodeTag==="webcomponent"?gt(e.getAttr()):Mn(e.nodeTag,{renderTag:i.render_tag,ns:e.getAttr("ns"),dialectName:t.constructor._name}),a=s==="foreignObject"?Vn:i.render_attributes?.xmlns??e.getAttr("xmlns")??(t instanceof $t?Vn:Ye);return{meta:i,namespace:a,tag:s}}validate(e,t=e.builder){let n=e.value instanceof N,i=n?e.getAttr("_text"):e.value;if(i!=null&&!["string","number","boolean"].includes(typeof i))throw new TypeError("HTML text must be scalar");for(let[o,l]of Object.entries(e.attr))if(!(o==="value"&&this.definition(e).meta.gramlot_component)&&!(this.metadataAttributes.has(o)||["ask","_ask"].includes(o)||l&&typeof l=="object"&&Object.hasOwn(l,"$gramlotRef"))&&l!=null&&!["string","number","boolean"].includes(typeof l))throw new TypeError(`HTML attribute ${o} must be scalar`);let s=Object.fromEntries(Object.entries(e.attr).filter(([o])=>!this.metadataAttributes.has(o))),a=n?e.value.getNodes().map(o=>o.nodeTag).filter(Boolean):[];t.validateNode(e,{value:i,attrs:s,childTags:a})}create(e,t,n=null,i=e.attr,s=null){let{tag:a,namespace:o,meta:l}=this.definition(e);n??=a;let u=o===Ye?t.createElement(n):t.createElementNS(o,n);if(l.gramlot_component&&u.constructor.gramlotComponent?.tag!==n)throw new Error(`Component collection must be activated before rendering ${n}`);l.gramlot_component?.dataScope&&(u.readDataScope=()=>{if(!e.getAttr("datapath"))throw new Error("Data scope requires an explicit datapath");return e.getRelativeData(".")}),l.gramlot_component?.sourceContext&&u.setSourceContext({publish:(f,p)=>e.publish(f,p),writeParameter:(f,p)=>this.writeParameter(e,f,p)});let c=t.createTextNode(this.text(e));(o!==Ye||!l.void)&&u.append(c);let d={element:u,text:c,tag:n};return this.update(d,e,i,eo,s),d}matches(e,t){let{tag:n,namespace:i}=this.definition(t);return(i===Ye?e.tag.toLowerCase()===n.toLowerCase():e.tag===n)&&e.element.namespaceURI===i}writeParameter(e,t,n){let i=e.getAttr(t);e.pointerType(i)==="^"&&!Y(i)&&!Object.is(e.getRelativeData(i.slice(1)),n)&&e.setRelativeData(i.slice(1),n)}compose(e,t,n){e.text.data=t??"";for(let i of n)e.element.append(i)}update(e,t,n=t.attr,i=eo,s=null){let{element:a,text:o}=e,l=a.namespaceURI===Ye,u=this.definition(t).meta.render_attributes??{},c=e.attrs??{},d=g=>(Gr(t,g,t.builder.constructor.dialectPrefixes),Wr(t,g,t.builder.constructor.dialectPrefixes),t.builder.renderer_html.adaptAttrs(g)),f=t.parentNode;f?._getMeta("gramlot_component")?.childParameters&&(n=a.ownerDocument.defaultView.customElements.get(f._getMeta("render_tag")).projectChild(a,n,{adapt:d,invoke:(b,y,v)=>this.invokeScript(t,b,y,v),publish:(b,y)=>t.publish(b,y),publishParent:(b,y)=>f.publish(b,y),writeParameter:(b,y)=>this.writeParameter(t,b,y),remove:()=>t.parentBag.popNode(t.label)})),this.definition(t).meta.gramlot_component&&(n=a.projectAttributes(n,d)),n=Object.fromEntries(xe({...n,...u}));let p=Te.classFor(a,n)!==null;i===eo&&(i=this.text(t));let h=i==null?"":String(i);o.data!==h&&(o.data=h);let m=[...new Set([...Object.keys(c),...Object.keys(n)])];m.sort((g,b)=>(b==="sandbox")-(g==="sandbox"));for(let g of m){if(this.metadataAttributes.has(g)||["ask","_ask"].includes(g)||p&&g==="value")continue;let b=n[g],y=g,v=rg(y),x=l&&Qm.has(v)&&typeof a[v]=="boolean",$=y==="xmlns"?"xmlns":y.includes(":")?y.split(":")[0]:"",D=Object.hasOwn(gc,$)?gc[$]:null;if(Object.is(c[g],b)||(b==null||x&&!b?D?a.removeAttributeNS(D,y.split(":").at(-1)):a.removeAttribute(y):D?a.setAttributeNS(D,y,String(b)):a.setAttribute(y,x?"":String(b))),l&&(x||eg.has(v))&&v in a){let J=v==="value"?b==null?"":String(b):!!b;a[v]!==J&&(a[v]=J)}}s===!1?a.style.visibility!=="hidden"&&(a.style.visibility="hidden"):e.visible===!1&&(n.style==null?a.removeAttribute("style"):a.setAttribute("style",String(n.style))),e.visible=s,e.attrs=n}text(e){return e.value instanceof N?e.getAttr("_text")==null?"":String(e.attr._text):e.value==null?"":String(e.value)}};var ps=class r{#e;#t;#r=null;#i=0;static for(e,t){return t.element?.constructor.gramlotComponent?.command?new r(e,t):null}constructor(e,t){this.#e=e,this.#t=t}get binding(){return this.#e}get node(){return this.binding.node}get element(){return this.#t.element}get controllers(){let e=this.node.value;return e?.getNodes?e.getNodes().filter(t=>t.nodeTag==="dataController"||t.nodeTag==="dataRpc"):[]}get mechanism(){let e=this.node,t=this.controllers;if(t.length>1)throw new Error(`${e.nodeTag} '${e.label}': several dataController or dataRpc children; a button has one click mechanism`);let n=e.getAttr()??{},i=[];if(t.length&&i.push("controller"),n.action!=null&&i.push("action"),bc(n).length&&i.push("fire"),i.length>1)throw new Error(`${e.nodeTag} '${e.label}': ${i.join(" and ")} together; a button has one click mechanism`);return i[0]??null}attach(){this.refresh(),this.element.activateCommand=e=>this.onClick(e),this.element.attachCommand(),this.element.addEventListener("click",this)}refresh(){this.mechanism&&this.node.getAttr("type")==null&&this.element.getAttribute("type")!=="button"&&this.element.setAttribute("type","button")}detach(){this.element.removeEventListener("click",this),this.element.releaseCommand(),delete this.element.activateCommand,this.#r?.()}handleEvent(e){this.onClick(e)}onClick(e){if(this.binding.closed||this.element.disabled)return;let t=this.element.commandTarget(e);if(t===null)return;if(t!==this.element)return e.stopPropagation(),t.activateCommand(e);if(!this.element.prepareCommand(e)||!this.mechanism||(e.stopPropagation(),this.element.disabled))return;let i=this.binding.countClick(),s=this.node;for(;s&&s.getAttr("_delay")==null;)s=s.parentNode;let a=s?s.rootBuilder.runtimeValues(s)[1]._delay:0;if(a>0){let o=this.#i+1;this.#r?.(),this.#i=o;let l=setTimeout(()=>{u(),this.#r=null,this.#i=0,this.#n(e,o)},a),u=this.binding.track(()=>this.#r?.());this.#r=()=>{clearTimeout(l),u(),this.#r=null,this.#i=0};return}return this.#r?.(),this.#n(e,i)}#n(e,t){if(this.binding.closed||this.element.disabled)return;let n=this.mechanism;if(!n)return;let i=this.node,s=ng(e);if(n==="controller")this.binding.runtime.bindingFor(this.controllers[0])?.providers[0]?.invoke({kind:"click",event:e,counter:t});else if(n==="action"){let a=()=>{let[,c]=i.rootBuilder.runtimeValues(i),d=Object.fromEntries(Object.entries(c).filter(([f])=>f!=="ask"));return{...this.binding.runtime.renderer.references.resolveArguments(d),event:e,_counter:t,modifiers:s}},o=c=>{if(this.binding.closed||this.element.disabled||c===null)return;let d={...a(),...c};c&&(d._askResult=c),this.binding.runtime.inlineCompiler.compile(i,"action",i.getAttr("action"),Object.keys(d))(d)},l=i.getAttr("ask"),u=this.binding.runtime.askDialog;if(l&&u.required(this.binding,l,a(),"ask"))return u.show(this.binding,l,a()).then(o);o(void 0)}else{let a={modifier:s,_counter:t},o=i.getAttr("fire");if(o!=null){i.FIRE(o,s||!0,a);return}for(let[l,u]of bc(i.getAttr())){if(this.binding.closed)return;i.FIRE(u,l.slice(5),a)}}}};function bc(r){return Object.entries(r??{}).filter(([e,t])=>t!=null&&(e==="fire"||e.startsWith("fire_")))}function ng(r){return["shift","ctrl","alt","meta"].filter(e=>r[`${e}Key`]).map(e=>e[0].toUpperCase()+e.slice(1)).join("")}var hs="connect_on",ig=/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/,Xn=class{#e;#t;#r;#i;#n;static declared(e){return Object.entries(e.getAttr()??{}).filter(([t,n])=>t.startsWith(hs)&&t.length>hs.length&&n!=null).map(([t,n])=>[t,t.slice(hs.length).toLowerCase(),n])}constructor(e,t,n,i,s=`${hs}${n}`){this.#e=e,this.#t=t,this.#r=n,this.#i=i,this.#n=s}get binding(){return this.#e}get node(){return this.binding.node}get element(){return this.#t.element}get eventName(){return this.#r}get handler(){return this.#i}get attribute(){return this.#n}attach(){this.element.addEventListener(this.eventName,this)}detach(){this.element.removeEventListener(this.eventName,this)}handleEvent(e){if(this.binding.closed)return;let t=this.node,n=this.binding.runtime;if(ig.test(this.handler)){let{group:i,method:s}=n.logicRegistry.resolve(this.handler,t);s.call(i,t,e);return}n.inlineCompiler.compile(t,this.attribute,this.handler,["event"])({event:e})}};function Yr(r,e=new Set){if(!r||typeof r!="object")return;let t=r.ownerDocument?.defaultView?.Node??r.defaultView?.Node;if(me(r)instanceof Ce||t&&r instanceof t)throw new TypeError("Live Source/DOM references cannot cross a transport boundary");if(e.has(r))throw new TypeError("Transport data cannot contain circular references");e.add(r);let n=r instanceof V?r.getNodes().flatMap(i=>[i.staticValue,i.getAttr()]):Object.values(r);for(let i of n)Yr(i,e);e.delete(r)}var Yn=class{constructor(e=null){this.entries=new Map,this.sourceRoot=e}validate(e,t=new Set){let n=new Map,i=s=>{for(let a of s.getNodes()){let o=a.getAttr("__ref");if(o){if(n.has(o))throw new Error("Duplicate Source reference");let l=this.entries.get(o);if(e!==this.sourceRoot&&l&&l.node!==a&&!t.has(l.node))throw new Error("Duplicate Source reference");n.set(o,a)}a.value instanceof N&&i(a.value)}};i(e)}register(e,t){let n=e.getAttr("__ref");if(n){if(this.entries.has(n))throw new Error(`Duplicate Source reference: ${n}`);this.entries.set(n,{node:e,dom:t})}}remove(e){for(let[t,n]of this.entries)n.node===e&&this.entries.delete(t)}resolveArguments(e){return Object.fromEntries(Object.entries(e).map(([t,n])=>[t,n&&typeof n=="object"&&Object.hasOwn(n,"$gramlotRef")?this.resolve(n):n]))}resolve(e){if(!e||!["node","dom"].includes(e.kind))throw new TypeError("Expected a node or DOM reference");let t=this.entries.get(e.$gramlotRef);if(!t)throw new Error("Source reference is not mounted");return t[e.kind]}};var ms=class{constructor(e=null,t=null){this.parent=e,this.segment=t,this.children=new Map,this.registrations=new Set}},to=class{#e;#t;#r;#i;#n;#s=!0;constructor(e,{path:t,attr:n,recipient:i,order:s}){this.#e=e,this.#t=t,this.#r=n,this.#i=i,this.#n=s}get router(){return this.#e}get path(){return this.#t}get attr(){return this.#r}get recipient(){return this.#i}get active(){return this.#s}get order(){return this.#n}close(){this.active&&(this.#s=!1,this.router.unregister(this))}},ro=class{constructor({evt:e,node:t,path:n,oldvalue:i,attrsDiff:s,reason:a,fired:o,level:l,registration:u}){this.evt=e,this.node=t,this.path=n,this.oldvalue=i,this.attrsDiff=s,this.reason=a,this.fired=o,this.level=l,this.registration=u}},gs=class{#e;#t=new ms;#r=new Map;#i=0;#n=0;constructor(e){this.#e=e}get runtime(){return this.#e}get size(){return this.#i}register({path:e,attr:t=null,recipient:n}){if(typeof e!="string"||e==="")throw new TypeError(`A Data registration requires a path: ${e}`);let i=this.#t;for(let a of e.split(".")){let o=i.children.get(a);o||(o=new ms(i,a),i.children.set(a,o)),i=o}this.#n+=1;let s=new to(this,{path:e,attr:t,recipient:n,order:this.#n});return i.registrations.add(s),this.#r.set(s,i),this.#i+=1,s}unregister(e){let t=this.#r.get(e);if(t)for(this.#r.delete(e),t.registrations.delete(e),this.#i-=1;t.parent&&!t.children.size&&!t.registrations.size;)t.parent.children.delete(t.segment),t=t.parent}deliver(e){let{pathlist:t}=e;if(!t?.length||t[0]!==Pn||e.reason==="autocreate")return;let n=t.slice(1),i=e.evt==="ins"||e.evt==="del";for(let s of Array.isArray(e.node)?e.node:[e.node]){let a=i?[...n,s.label]:n,o=a.join(".");for(let[l,u]of this.#s(a,e))l.active&&l.recipient.receive(new ro({evt:e.evt,node:s,path:o,oldvalue:e.oldvalue??null,attrsDiff:e.attrs_diff??null,reason:e.reason??null,fired:e.fired??!1,level:u,registration:l}))}}#s(e,t){let n=[],i=this.#t;for(let a of e){for(let o of i.registrations)i!==this.#t&&this.#a(o,"child",t)&&n.push([o,"child"]);if(i=i.children.get(a),!i)return n.sort(([o],[l])=>o.order-l.order)}for(let a of i.registrations)this.#a(a,"node",t)&&n.push([a,"node"]);let s=[...i.children.values()];for(;s.length;){let a=s.pop();for(let o of a.registrations)this.#a(o,"container",t)&&n.push([o,"container"]);s.push(...a.children.values())}return n.sort(([a],[o])=>a.order-o.order)}#a(e,t,n){let{evt:i}=n;return e.attr===null?i==="upd_attrs"?!1:!(t==="child"&&n.fired):t==="child"?!1:t==="container"?i!=="upd_attrs":i==="ins"||i==="del"?!0:Object.hasOwn(n.attrs_diff??{},e.attr)}};var bs=class{#e;constructor(e){this.#e=e}get runtime(){return this.#e}install(e){let t=Zn(e),n=this.setterNodes(e);io(e);for(let i of n){let s=this.runtime.openBinding(i);s.hasStamp("installed")||(this.applySetter(i),s.stamp("installed"))}this.applyDefaults(t.filter(i=>i.nodeTag&&!i._getMeta("data_element")))}setterNodes(e){return Zn(e).filter(t=>t.nodeTag==="dataSetter")}applySetter(e){let t=e.absDatapath(e.pathAttribute("destination_path"));if(t===null)return;let n=e.getAttr("value")??null,i=ag(e.getAttr()),s=this.runtime.data;if(n!==null)s.setItem(t,n,i,">",!1,!0,e),n instanceof V&&e.setAttr({value:null},!1);else{let a=s.getNode(t);a?i&&a.setAttr(i,!0):s.setItem(t,null,i,">",!1,!0,e)}}applyDefaults(e){for(let t of e){let n=t.getAttr();for(let[i,s]of Object.entries(n)){if(!sg(t,i,s))continue;let a=i==="value"?n.default_value??n.default:n[`default_${i}`];a!=null&&this.#t(t,s,a)}this.#r(t,n)}}#t(e,t,n){let i=e.absDatapath(t);if(i===null)return;let[s,a=null]=i.split("?",2),o=this.runtime.data,l=o.getNode(s);if(a===null){if(l&&l.value!==null&&l.value!==void 0)return;o.setItem(s,n,null,">",!1,!0,e)}else if(l){let u=l.getAttr(a);u==null&&l.setAttr({[a]:n},!0)}else o.setItem(s,null,{[a]:n},">",!1,!0,e)}#r(e,t){let n={};for(let[a,o]of Object.entries(t))a.startsWith("attr_")&&(n[a.slice(5)]=Y(o)?Lt(e,a):e.pointerType(o)?e.getRelativeData(o):o);if(!Object.keys(n).length)return;let i=[t.value,t.src].find(a=>e.pointerType(a));if(!i)return;let s=e.absDatapath(i);s!==null&&this.runtime.data.getNode(s.split("?",1)[0])?.setAttr(n,!0,!0,!1)}};function sg(r,e,t){return e==="_meta"||Zt.has(e)||e==="default"||e.startsWith("default_")||e.startsWith("attr_")||e.endsWith("_path")?!1:r.pointerType(t)!==null}function ag(r){let e={};for(let[t,n]of Object.entries(Ft(r??{})))Zt.has(t)||t.startsWith("_")||t==="destination_path"||t==="value"||n!=null&&(e[t]=n);return Object.keys(e).length?e:null}function og(r){let e=r.builder;if(!(e instanceof Je))throw new Error(`dataSetter '${r.label}': dataSetter is not supported inside ${e.constructor._name}`)}function io(r){for(let e of Zn(r))e.nodeTag==="dataSetter"&&og(e),fg(e)}var lg=["_init","_onStart","_onBuilt","_delay","_timing","_userChanges"],ug=new Set(["dataFormula","dataController","dataRpc","dataRemote"]),cg=["_onCalling","_onResult","_onError"],dg=["_delay","_timing","_userChanges"],no=["_init","_onBuilt","_onStart"];function fg(r){let e=s=>r.getAttr(s)!==null&&r.getAttr(s)!==void 0,t=!r._getMeta("data_element")&&typeof r.getAttr("remote")=="string";if(r.nodeTag!=="dataRpc"){let s=cg.find(a=>e(a)&&!(a==="_onCalling"&&(r.nodeTag==="dataRemote"||t)));if(s){let a=s==="_onCalling"?"dataRpc, dataRemote and remote":"dataRpc";throw new Error(`${r.nodeTag??"fragment"} '${r.label}': '${s}' is allowed only on ${a}`)}}if(ug.has(r.nodeTag)){let s=Object.entries(r.getAttr()).find(([,o])=>Ze(o));if(s)throw new Error(`${r.nodeTag} '${r.label}': '${s[0]}' is a == expression, not accepted on ${r.nodeTag}`);let a=r.nodeTag==="dataRemote"?no.find(e):null;if(a)throw new Error(`dataRemote '${r.label}': '${a}' is not accepted on dataRemote, its resolver loads when the Data is read`);for(let o of no){let l=r.getAttr(o);if(!(l==null||typeof l=="boolean"||typeof l=="number"))throw new Error(`${r.nodeTag} '${r.label}': '${o}' accepts true, false, null or a number, not ${JSON.stringify(l)}`)}return}let n=lg.find(s=>e(s)&&!(s==="_delay"&&!r._getMeta("data_element")&&r.nodeTag!=="html_button")&&!(t&&dg.includes(s)));if(!n)return;let i=no.includes(n)?"dataFormula, dataController and dataRpc":"dataFormula, dataController, dataRpc and dataRemote";throw new Error(`${r.nodeTag??"fragment"} '${r.label}': '${n}' is allowed only on ${i}`)}function Zn(r){if(r instanceof N)return r.getNodes().flatMap(t=>Zn(t));let e=[r];return r.value instanceof N&&e.push(...Zn(r.value)),e}var _s=class extends ie{static classKwargs={...ie.classKwargs,asBag:!1};static internalParams=new Set([...ie.internalParams,"binding","method","params","onCalling","onError","sync"]);constructor({binding:e,method:t,params:n,cacheTime:i,onCalling:s=null,onError:a,sync:o=!1}){super({cacheTime:i??-1}),this.binding=e,this.sync=o,this.method=t,this.params=n,this.onCalling=s,this.onError=a,this.loading=null,this.loaded=!1,this.writing=!1}resolve(e={}){let{static:t=!1}=e;return t||this.loading||this.writing?this.cachedValue:this.sync?this.expired&&!this.binding.node.requests.calling(this.onCalling)?this.cachedValue:super.resolve(e):(this.expired&&this.refresh(),this.cachedValue)}load(){let e;try{e=this.binding.callSync("data",this.method,this.params)}catch(t){this.onError(t)}return this.loaded=!0,e}refresh(){let e=this.binding.node.requests;if(!e.calling(this.onCalling))return null;let t=e.submit(this.method,this.params,i=>this.#t(i)),n=()=>{this.loading===t&&(this.loading=null)};return t.then(n,n),this.loading=t,t.catch(i=>{i?.name!=="AbortError"&&this.onError(i)}),t}#e(){let e={...this._kw};for(let[t,n]of Object.entries(this.node?.attr??{}))this.constructor.internalParams.has(t)||(e[t]=n);return this._computeEffectiveFingerprint(e)}async#t(e){let t=this.binding;if(t.closed)return;let n=this.#e(),i=await t.call("data",e);if(!(t.closed||e.ignored)){this._lastUpdate=Date.now(),this._lastEffectiveFingerprint=n,this.loaded=!0,this.writing=!0;try{this.node?this.node.setValue(i,this.cacheTime!==0):this.cachedValue=i}finally{this.writing=!1}return i}}};var pg=new Set(["destination_path","result_path","func","formula","script","if","else","_init","_onStart","_onBuilt","_delay","_timing","_userChanges","_ask","_ask_if","_ask_title","_ask_onCancel","method","timeout","_onCalling","_onResult","_onError","cacheTime","sync"]),Jn=class{#e;#t=null;#r=null;constructor(e){this.#e=e}get binding(){return this.#e}debounce(e,t){this.#r?.();let n=null,i=setTimeout(()=>{n(),this.#r=null,t()},e);n=this.binding.track(()=>clearTimeout(i)),this.#r=()=>{clearTimeout(i),n(),this.#r=null}}startTiming(e,t){if(this.#t?.(),!(e>0))return;let n=setInterval(t,e*1e3),i=this.binding.track(()=>clearInterval(n));this.#t=()=>{clearInterval(n),i(),this.#t=null}}cancel(){this.#r?.(),this.#t?.()}},Zr=class{#e;#t=[];#r=new Set;#i;#n=null;#s=!1;constructor(e){this.#e=e,this.#i=new Jn(e),e.track(()=>{this.cancel(),this.#p(),this.#f()})}get binding(){return this.#e}get node(){return this.binding.node}get kind(){throw new Error("Provider.kind is defined by FormulaProvider, ControllerProvider, RpcProvider and RemoteProvider")}register(){let e=this.node,t=e.getAttr("_onStart");if(typeof t=="number"&&!(Number.isFinite(t)&&t>=0))throw new Error(`${e.nodeTag} '${e.label}': _onStart must be true or a delay in ms not below 0: ${t}`);this.#p();let n=this.binding.runtime.router,i=Qe(e,e.getAttr("_timing"));for(let[s,a]of e.pointers()){if(s==="datapath")continue;let o=e.absDatapath(a);if(o===null)continue;let[l,u=null]=o.split("?",2),c=n.register({path:l,attr:u,recipient:this});this.#t.push(c),(s==="_timing"||i.has(s))&&this.#r.add(c)}this.#t.push(...this.binding.runtime.subscriptions.subscribeNode(e,(s,a,o)=>l=>{let u={kind:"subscription",topic:o,payload:l};if(this.#o("_userChanges")&&o!=="node")return;let c=this.#o("_delay");c>0?this.#i.debounce(c,()=>this.invoke(u)):this.invoke(u)})),this.#a(),this.kind==="remote"&&this.invoke({kind:"install",change:null})}receive(e){if(this.#r.has(e.registration)){this.#a();return}if(this.#o("_userChanges")&&e.level!=="node")return;let t={kind:"data",change:e},n=this.#o("_delay");n>0?this.#i.debounce(n,()=>this.invoke(t)):this.invoke(t)}invoke(e){if(this.binding.closed)return;let t=this.node,n=this.kind==="formula",i=this.kind==="rpc",s=this.kind==="remote",a=this.readArguments(e);e.askResult&&(Object.assign(a,e.askResult),a._askResult=e.askResult);let o=t.getAttr("_ask"),l=this.binding.runtime.askDialog;if(o&&!e.askDone&&l.required(this.binding,o,a,"_ask"))return l.show(this.binding,o,a,t.getAttr("_ask_title")??"Warning").then(h=>{if(!this.binding.closed){if(h===null){let m=t.getAttr("_ask_onCancel");m&&this.#l("_ask_onCancel",m,m,a,!0);return}return this.invoke({...e,askDone:!0,askResult:h})}});let[u,c]=[n?"formula":"script",t.getAttr(n?"formula":"script")],d=t.getAttr("_if");if(d&&!this.#l("_if",d,`return (${d})`,a,!1)){if(s&&this.#f(),[u,c]=["_else",t.getAttr("_else")],!c)return;if(i||s){this.#l(u,c,c,a,!0);return}}if(i)return this.#d(a);if(s)return this.#u(a);let f=t.getAttr("func"),p;if(c)p=this.#l(u,c,n?`return ${c}`:c,a,!0);else if(f==null){if(!n)return;p=new V(ws(a))}else{let{group:h,method:m}=this.binding.runtime.logicRegistry.resolve(f,t);p=n?m.call(h,a):m.call(h,t,a)}n&&t.setRelativeData(t.pathAttribute("result_path"),p)}readArguments(e){let t=this.node,[,n]=t.rootBuilder.runtimeValues(t),i=Object.fromEntries(Object.entries(n).filter(([l])=>!pg.has(l)&&!l.startsWith("subscribe_")&&!l.startsWith("selfsubscribe_"))),s={...e.kind==="subscription"?e.payload:{},...this.binding.runtime.renderer.references.resolveArguments(i)};e.kind==="subscription"&&(s._subscription_kwargs=e.payload);let a=e.change??null,o=a?a.level:e.kind==="subscription"?e.topic:e.kind;return s._node=a?a.node:null,s._triggerpars={kw:a,trigger_reason:o},s._reason=o,e.kind==="click"&&Object.assign(s,hg(e)),s}cancel(){this.#i.cancel()}#a(){this.#i.startTiming(this.#o("_timing"),()=>this.invoke({kind:"timing",change:null}))}#o(e){let t=this.node,n=t.getAttr(e);return Y(n)?Lt(t,e):t.pointerType(n)?t.getRelativeData(n):n??null}#l(e,t,n,i,s){let a=[...s?["_kwargs"]:[],..._c,...wc,...Object.keys(ws(i))];return this.binding.runtime.inlineCompiler.compile(this.node,e,t,a,n)({...i,_kwargs:i})}async#d(e){let t=this.node,[n,i,s]=["_onCalling","_onResult","_onError"].map(o=>t.getAttr(o)),a=t.requests;if(a.calling(n?()=>this.#l("_onCalling",n,n,e,!0):null))return a.submit(this.#o("method"),ws(e),o=>this.#m(o,e,i,s))}async#m(e,t,n,i){if(this.binding.closed)return;let s=this.node,a=this.#o("timeout"),o=a>0?setTimeout(()=>{let c=new Error(`${s.nodeTag} '${s.label}': no answer within ${a} ms`);c.name="TimeoutError",e.controller.abort(c)},a):null,l;try{l={result:await this.binding.call("data",e)}}catch(c){l={error:c}}if(clearTimeout(o),this.binding.closed||e.ignored)return;if("error"in l){if(!i)throw l.error;this.#l("_onError",i,i,{...t,error:l.error},!0);return}let{result:u}=l;s.getAttr("result_path")!=null&&s.setRelativeData(s.pathAttribute("result_path"),u),n&&this.#l("_onResult",n,n,{...t,result:u},!0)}#u(e){this.#f();let t=this.#s;this.#s=!1;let n=this.node,i=n.absDatapath(n.pathAttribute("destination_path"));if(i===null)return;let s=n.getAttr("_onCalling"),a=new _s({binding:this.binding,method:this.#o("method"),params:ws(e),cacheTime:this.#o("cacheTime"),sync:this.#o("sync")!==!1&&this.binding.runtime.gramlot.rpc.supportsCallSync,onCalling:s?()=>this.#l("_onCalling",s,s,e,!0):null,onError:o=>{throw new Error(`${n.nodeTag} '${n.label}': dataRemote '${a.method}' failed: ${o.message}`,{cause:o})}});this.binding.runtime.data.setResolver(i,a),this.#n={path:i,resolver:a},t&&a.refresh()}#f(){if(!this.#n)return;let{path:e,resolver:t}=this.#n;this.#n=null,this.#s=t.loaded||t.loading!==null;let n=this.binding.runtime.data.getNode(e);n?.resolver===t&&(n.resolver=null)}#p(){for(let e of this.#t.splice(0))e.close();this.#r.clear()}},ys=class extends Zr{get kind(){return"formula"}},vs=class extends Zr{get kind(){return"controller"}},ks=class extends Zr{get kind(){return"rpc"}},Es=class extends Zr{get kind(){return"remote"}},_c=["_node","_triggerpars","_reason","_subscription_kwargs","_askResult"],wc=["_evt","button_counter","button_shift","button_ctrl","button_alt","button_meta"];function ws(r){let e={...r};for(let t of[..._c,...wc])delete e[t];return e}function hg({event:r,counter:e}){return{_evt:r,button_counter:e,button_shift:!!r.shiftKey,button_ctrl:!!r.ctrlKey,button_alt:!!r.altKey,button_meta:!!r.metaKey}}var mg=[[null,/(\W|^)GET (?:\s*)(\^?[\w.#@$?-]+)/g,"$1this.GET('$2')"],[/;SET/g,/(\W|^)SET (?:\s*)(\^?[\w.#@$?-]+)(?:\s*)=(?:\s*)([^;\r\n]*)(;?)/gm,"$1this.SET('$2', $3)$4 "],[/;PUT/g,/(\W|^)PUT (?:\s*)(\^?[\w.#@$?-]+)(?:\s*)=(?:\s*)([^;\r\n]*)(;?)/gm,"$1this.PUT('$2', $3)$4 "],[/;FIRE_AFTER/g,/(\W|^)FIRE_AFTER (?:\s*)(\^?[\w.#@$?-]+)(?:\s*)=(?:\s*)([^;\r\n]*)(;?)/g,"$1this.FIRE_AFTER('$2', $3)$4 "],[/;FIRE_AFTER/g,/(\W|^)FIRE_AFTER (?:\s*)(\^?[\w.#@$?-]+)(?:\s*)(;?)/g,"$1this.FIRE_AFTER('$2')$3 "],[/;FIRE/g,/(\W|^)FIRE (?:\s*)(\^?[\w.#@$?-]+)(?:\s*)=(?:\s*)([^;\r\n]*)(;?)/g,"$1this.FIRE('$2', $3)$4 "],[/;FIRE/g,/(\W|^)FIRE (?:\s*)(\^?[\w.#@$?-]+)(?:\s*)(;?)/g,"$1this.FIRE('$2')$3 "]],gg=/(\W|^)PUBLISH (?:\s*)(\^?[\w.#@$?-]+)/,bg=new Set(["arguments","await","break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","eval","export","extends","false","finally","for","function","if","implements","import","in","instanceof","interface","let","new","null","package","private","protected","public","return","static","super","switch","this","throw","true","try","typeof","var","void","while","with","yield"]),As=class{#e;#t=new Map;constructor(e){this.#e=e}get runtime(){return this.#e}get size(){return[...this.#t.values()].reduce((e,t)=>e+t.size,0)}preprocess(e,t,n){let i=n.trim();if(gg.test(i))throw new Error(`${Kn(e,t)}: the PUBLISH macro is excluded from Gramlot`);let s=i.replace(/\$(\d+)/g,(a,o)=>`arguments[${parseInt(o,10)-1}]`);for(let[a,o,l]of mg)a&&(s=s.replace(a,`; ${a.source.slice(1)}`)),s=s.replace(o,l);return s!==i&&console.warn(`${Kn(e,t)}: legacy macros are deprecated; write this.GET(path), this.SET(path, value), this.PUT(path, value), this.FIRE(path, value), this.FIRE_AFTER(path, value) and arguments[n] in place of GET, SET, PUT, FIRE, FIRE_AFTER and $n`),s}compile(e,t,n,i,s=n){if(e.activatedCode(t)!==n)throw new Error(`${Kn(e,t)}: inline code runs only as received with the Source (main or a remote Source); a text written later is not run: use named logic`);let a=this.#t.get(e);a||(a=new Map,this.#t.set(e,a),this.runtime.bindingFor(e).track(()=>this.release(e)));let o=a.get(t);o?.source!==s&&(o={source:s,text:this.preprocess(e,t,s),key:null,run:null},a.set(t,o));let l=i.filter(_g),u=l.join(",");if(o.key!==u){let c=wg(e,t,o.text,l);o.key=u,o.run=d=>c.apply(e,l.map(f=>d[f]))}return o.run}compileExpression(e,t,n){let i=n.slice(2).trim(),s=xe(e.getAttr()).filter(([,o])=>!Ze(o)),a=this.compile(e,t,n,[...s.map(([o])=>o).filter(o=>o!=="_F"),"_F"],`return ${i}`);return o=>{let l={};for(let[u,c]of s)Object.hasOwn(o,u)?l[u]=o[u]:l[u]=e.pointerType(c)?e.getRelativeData(c):c;return a({...l,_F:(u,c)=>this.runtime.gramlot.format(u,c)})}}compilePointerExpression(e,t,n,i){let s=this.compile(e,t,n,["_pointerValues","_F"],`return (${i}
|
|
59
59
|
)`);return a=>s({_pointerValues:a,_F:(o,l)=>this.runtime.gramlot.format(o,l)})}release(e,t=null){if(t===null){this.#t.delete(e);return}let n=this.#t.get(e);if(n)for(let i of t){n.delete(i);for(let[s]of xe({[i]:null}))n.delete(s)}}};function _g(r){return/^[A-Za-z_$][\w$]*$/.test(r)&&!bg.has(r)}function Kn(r,e){return`${r.nodeTag} '${r.label}' ${e?`'${e}'`:"node value"}`}function wg(r,e,t,n){try{return t.startsWith("function")?new Function(`return (${t}
|
|
60
60
|
)`)():new Function(...n,`${t}
|
|
61
61
|
`)}catch(i){throw i instanceof EvalError?new EvalError(`${Kn(r,e)}: inline code blocked by the Content Security Policy of the page (no 'unsafe-eval'); move the code to named logic (a method of the page's class Logic) or serve the page with the permissive CSP profile, which allows 'unsafe-eval'`,{cause:i}):new SyntaxError(`${Kn(r,e)}: ${i.message} in the inline code:
|
|
62
|
-
${t}`,{cause:i})}}var xs=class{#e;#t;#r=null;#i=null;constructor(e){this.#e=e,this.#t=new Jn(e)}get binding(){return this.#e}get node(){return this.binding.node}get closed(){return this.binding.closed}register(){this.#t.startTiming(this.#s("_timing"),()=>this.update())}receive(e){if(this.#s("_userChanges")&&e.level!=="node")return;let t=this.#s("_delay");t>0?this.#t.debounce(t,()=>this.update()):this.update()}async update(){if(this.closed||!this.binding.hasStamp("start"))return;let e=this.node,[,t]=e.rootBuilder.runtimeValues(e),n=t.remote,i={};for(let[l,u]of Object.entries(t))l.startsWith("remote_")&&(i[l.slice(7)]=u);let s=e.getAttr("_if");if(s&&!this.#a("_if",s,`return (${s})`,i)){let l=e.getAttr("_else");l&&this.#a("_else",l,l,i);return}let a;try{let l=ne(i);if(t._cachedRemote&&this.#n(n,l))return;let u=e.getAttr("_onCalling");if(!e.requests.calling(u?()=>this.#a("_onCalling",u,u,i):null))return;a=await this.binding.runtime.gramlot.src.remoteSource(e,n,i)}catch(l){throw new Error(`${e.nodeTag} '${e.label}': remote '${n}' failed: ${l.message}`,{cause:l})}let o=e.getAttr("_onRemote");a&&o&&this.#a("_onRemote",o,o,i)}fragmentMounted(e,t){this.#r=e,this.#i=t}#n(e,t){let n=this.node.requests.inflight;return n?n.method===e&&ne(n.params)===t:e===this.#r&&t===this.#i}#s(e){let[,t]=this.node.rootBuilder.runtimeValues(this.node);return t[e]??null}#a(e,t,n,i){return this.binding.runtime.inlineCompiler.compile(this.node,e,t,Object.keys(i),n)(i)}};var yg=new Set(["title","msg","fields","_if","askIf"]),vg=new Set(["name","lbl","tag","type","default_value","required","min","max","step","placeholder"]),Ts=class{#e;#t=null;#r=new Map;constructor(e){this.#e=e}get runtime(){return this.#e}required(e,t,n,i){let s=(a,o)=>typeof o=="boolean"?o:e.runtime.inlineCompiler.compile(e.node,a,o,Object.keys(n),`return (${o});`)(n);if(typeof t=="string"){let a=e.node.getAttr("_ask_if");return!a||!!s("_ask_if",a)}return t?.askIf&&s(`${i}.askIf`,t.askIf),!t?._if||!!s(`${i}._if`,t._if)}show(e,t,n,i="Parameters"){let s=typeof t=="string"?{msg:t,title:i}:t;if(!s||typeof s!="object"||Array.isArray(s))throw new TypeError("ask requires text or a parameter description");for(let d of Object.keys(s))if(!yg.has(d))throw new Error(`Unsupported ask option: ${d}`);let a=s.fields??[];if(!Array.isArray(a))throw new TypeError("ask fields must be an array");let o=new Set;for(let d of a){if(!d||!/^[A-Za-z_]\w*$/.test(d.name)||o.has(d.name))throw new Error("ask fields require distinct simple names");o.add(d.name);for(let f of Object.keys(d))if(!vg.has(f))throw new Error(`Unsupported ask field option: ${f}`);if(d.tag&&!["input","textarea"].includes(d.tag))throw new Error(`Unsupported ask widget: ${d.tag}`);if(d.type&&!["text","number","date","checkbox","email","password","url","tel"].includes(d.type))throw new Error(`Unsupported ask input type: ${d.type}`)}let l=this.runtime.gramlot,u=this.#i(),c=this.#r;return new Promise((d,f)=>{let p=`ask_${Me()}`,h=!1,m=()=>{},g=(b,y=null)=>{if(h)return;h=!0;let v=b?Object.fromEntries(a.map(x=>[x.name,l.data.getItem(`${p}.${x.name}`)])):null;c.delete(p),m();try{l.src.source.popNode(p),l.data.getNode(p)&&l.data.popNode(p),y?f(y):d(v)}catch(x){f(x)}};c.set(p,{finish:g}),m=e.track(()=>g(!1));try{let b=new Je,y=b.root.dialog({node_id:p,datapath:p,request:p,connect_oncancel:`${u}.cancel`,connect_onclose:`${u}.cancel`,class:"gramlot-ask","aria-labelledby":`${p}_title`,style:"border:1px solid #aab4c2;border-radius:8px;padding:16px;max-width:32rem;width:calc(100% - 48px);font:inherit;"});y.h2(s.title??i,{id:`${p}_title`,style:"font-size:1.1em;margin:0 0 12px;"}),s.msg&&y.p(s.msg);let v=y.form({request:p,connect_onsubmit:`${u}.confirm`});for(let D of a){v.dataSetter({destination_path:`.${D.name}`,value:Object.hasOwn(n,D.name)?n[D.name]:D.default_value??(D.type==="checkbox"?!1:"")});let J=v.div({style:"margin:8px 0;"});J.html_label(D.lbl??D.name,{for:`${p}_${D.name}`,style:"display:block;margin-bottom:4px;"});let G={id:`${p}_${D.name}`,value:`^.${D.name}`,live:!0};for(let re of["required","min","max","step","placeholder"])D[re]!==void 0&&(G[re]=D[re]);D.tag==="textarea"?J.textarea(G):J.input({...G,type:D.type??"text"})}let x=v.div({style:"display:flex;justify-content:flex-end;gap:8px;margin-top:16px;"});x.html_button("Cancel",{type:"button",request:p,connect_onclick:`${u}.cancel`}),x.html_button("Confirm",{type:"submit",autofocus:a.length===0}),l.src.source.setItem(p,l.src.prepareSource(b.source));let $=l.src.binding.nodeIds.get(p);l.dom.getDomNode($).showModal()}catch(b){g(!1,b)}})}#i(){if(this.#t===null){let e=`ask_${Me()}`,t=this.#r;class n{confirm(s,a){a.preventDefault(),t.get(s.getAttr("request"))?.finish(!0)}cancel(s,a){a.preventDefault(),t.get(s.getAttr("request"))?.finish(!1)}}this.runtime.logicRegistry.register(n,{group:e,resource:"gramlot:ask"}),this.#t=e}return this.#t}};var yc={dataFormula:ys,dataController:vs,dataRpc:ks,dataRemote:Es},kg=["datapath","_anchor","node_id","form","formId"],Jr=class{#e;#t=new Map;#r=new Map;#i;#n;#s;#a;#o;#l=`gramlot-data-${Me()}`;#d=!1;constructor(e,{subscriptions:t}){this.#e=e,this.#o=t,this.#i=new gs(this),this.#n=new bs(this),this.#s=new As(this),this.#a=new Ts(this)}get gramlot(){return this.#e}get subscriptions(){return this.#o}get builder(){return this.gramlot.src.builder}get renderer(){return this.gramlot.src.renderer}get logicRegistry(){return this.gramlot.src.logicRegistry}get data(){return this.builder.data}get root(){return this.data.parent}get size(){return this.#t.size}get disposed(){return this.#d}get router(){return this.#i}get installer(){return this.#n}get inlineCompiler(){return this.#s}get askDialog(){return this.#a}get nodeIds(){return this.#r}attach(){this.root.subscribe(this.#l,{any:e=>this.receiveData(e)})}receiveData(e){this.router.deliver(e)}bindingFor(e){return this.#t.get(e)??null}openBinding(e){if(this.disposed)throw new Error("BindingRuntime is disposed");let t=this.bindingFor(e);return t||(t=new so(this,e),this.#t.set(e,t)),t}closeBranch(e){let t=[];if(e.value instanceof N)for(let i of e.value.getNodes())try{this.closeBranch(i)}catch(s){t.push(s)}let n=this.bindingFor(e);if(n){this.#t.delete(e);let i=e.getAttr("node_id");this.nodeIds.get(i)===e&&this.nodeIds.delete(i);try{n.close()}catch(s){t.push(s)}}if(t.length)throw new AggregateError(t,"Source branch close failed")}rebindBranch(e){let t=this.#h(e);for(let n of t)this.bindingFor(n)?.rebind();for(let n of t)this.renderer.project(n);for(let n of t)this.bindingFor(n)?.remote?.update()}handleSourceEvent(e){let{evt:t,node:n}=e,i=[],s=a=>{try{this.closeBranch(a)}catch(o){i.push(o)}};try{if(t==="ins")this.#m(n);else if(t==="del")for(let a of Array.isArray(n)?n:[n])s(a);else if(t==="upd_value"||t==="upd_value_attr"){if(e.oldvalue instanceof N)for(let a of e.oldvalue.getNodes())s(a);this.inlineCompiler.release(n,[""]),t==="upd_value_attr"?this.#p(n,e.attrs_diff):this.#c(n).rebind(),n.value instanceof N&&this.#m(n.value)}else if(t==="upd_attrs")this.#p(n,e.attrs_diff);else throw new Error(`Unsupported Source event: ${t}`)}catch(a){throw i.length?new AggregateError([...i,a],"Source event failed"):a}return i}branchBuilt(e){let t=[];for(let n of this.#h(e)){let i=this.bindingFor(n);!i||i.hasStamp("built")||!this.renderer.attached(n)||(i.stamp("built"),t.push(i))}for(let n of t)this.renderer.attached(n.node)&&this.#f(n,"built","_onBuilt");if(this.gramlot.state==="started")for(let n of t)this.renderer.attached(n.node)&&this.#u(n)}pageStarted(){for(let e of[...this.#t.values()])!e.closed&&e.hasStamp("built")&&this.#u(e)}dispose(){if(this.disposed)return;this.#d=!0,this.root.unsubscribe(this.#l,{any:!0}),this.nodeIds.clear();let e=[];for(let[t,n]of[...this.#t.entries()].reverse()){this.#t.delete(t);try{n.close()}catch(i){e.push(i)}}if(e.length)throw new AggregateError(e,"Binding cleanup failed")}#m(e){if(!(e instanceof N)&&this.bindingFor(e))return;let t=e instanceof N?e.getNodes().flatMap(s=>this.#h(s)):this.#h(e),n=new Set(t.filter(s=>this.bindingFor(s))),i=new Map;for(let s of t){let a=s.getAttr("node_id");if(a!=null){if(i.has(a)||this.nodeIds.has(a)&&this.nodeIds.get(a)!==s)throw new Error(`Duplicate node_id '${a}'`);i.set(a,s)}}for(let[s,a]of i)this.nodeIds.set(s,a);try{this.installer.install(e);for(let s of t)this.openBinding(s);for(let s of t)this.bindingFor(s).registerPointers()}catch(s){let a=[s];for(let o of t.filter(l=>!n.has(l)).reverse()){let l=o.getAttr("node_id");i.get(l)===o&&this.nodeIds.get(l)===o&&this.nodeIds.delete(l);let u=this.bindingFor(o);if(u){this.#t.delete(o);try{u.close()}catch(c){a.push(c)}}}throw a.length>1?new AggregateError(a,"Source branch installation failed"):s}for(let s of t){let a=this.bindingFor(s);if(!(!a||a.hasStamp("init")||!this.renderer.attached(s))&&(a.stamp("init"),vc(s.getAttr("_init"))))for(let o of a.providers)o.invoke({kind:"init",change:null})}}#u(e){e.hasStamp("start")||(e.stamp("start"),this.#f(e,"start","_onStart"),e.remote?.update())}#f(e,t,n){let i=e.node.getAttr(n);if(vc(i))for(let s of e.providers){if(typeof i!="number"||i<=0){s.invoke({kind:t,change:null});continue}let a=null,o=setTimeout(()=>{a(),s.invoke({kind:t,change:null})},i);a=e.track(()=>clearTimeout(o))}}#p(e,t){let n=this.#c(e);if(this.inlineCompiler.release(e,Object.keys(t)),Object.hasOwn(t,"node_id")){let{old:i,new:s}=t.node_id;if(s!=null&&this.nodeIds.has(s)&&this.nodeIds.get(s)!==e)throw new Error(`Duplicate node_id '${s}'`);this.nodeIds.get(i)===e&&this.nodeIds.delete(i),s!=null&&this.nodeIds.set(s,e)}kg.some(i=>Object.hasOwn(t,i))?this.rebindBranch(e):n.rebind()}#c(e){let t=this.bindingFor(e);if(!t)throw new Error(`${e.nodeTag??"fragment"} '${e.label}': the node has no NodeBinding (its installation failed); remove it from the Source and insert it again`);return t}#h(e){let t=[e];if(e.value instanceof N)for(let n of e.value.getNodes())t.push(...this.#h(n));return t}};function vc(r){return r===!0||typeof r=="number"}var so=class{#e;#t;#r=!1;#i=[];#n=[];#s=new Set;#a=null;#o=null;#l=new Set;#d=new Set;#m=0;#u=new Set;constructor(e,t){this.#e=e,this.#t=t}get runtime(){return this.#e}get node(){return this.#t}get closed(){return this.#r}get registrations(){return[...this.#n]}get providers(){return this.#a?[this.#a]:[]}get remote(){return this.#o}get clickCount(){return this.#m}countClick(){return++this.#m}hasStamp(e){return this.#s.has(e)}stamp(e){this.#s.add(e)}registerPointers(){this.node._getMeta("data_element")&&(this.runtime.renderer.references.remove(this.node),this.runtime.renderer.references.register(this.node,null));let e=this.node,t=e._getMeta("data_element");if(t&&!yc[e.nodeTag])return;!t&&typeof e.getAttr("remote")=="string"&&(this.#o??=new xs(this));let n=new Set,i=this.remote?Qe(e,e.getAttr("_timing")):new Set;if(this.remote){for(let[s,a]of Object.entries(e.getAttr()))if(s.startsWith("remote_"))for(let o of Qe(e,a))n.add(o)}for(let[s,a]of e.pointers()){if(t&&s!=="datapath")continue;let l=(s==="datapath"?e.parentNode:e).absDatapath(a);if(l===null)continue;let[u,c=null]=l.split("?",2),d=this.runtime.router.register({path:u,attr:c,recipient:this});this.#n.push(d),s==="datapath"&&this.#u.add(d),this.remote&&(s==="remote"||s.startsWith("remote_")||n.has(s))&&this.#l.add(d),this.remote&&(s==="_timing"||i.has(s))&&this.#d.add(d)}if(!t){this.#f(),this.remote?.register();return}this.#a??=new yc[e.nodeTag](this),this.#a.register()}#f(){let e=this.node;this.#n.push(...this.runtime.subscriptions.subscribeNode(e,(t,n)=>{if(typeof n!="string"||!n)throw new TypeError(`${t} requires a handler`);return i=>{if(this.closed)return;if(/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/.test(n)){let{group:l,method:u}=this.runtime.logicRegistry.resolve(n,e);return u.call(l,e,i)}let[,s]=e.rootBuilder.runtimeValues(e),a=Object.fromEntries(Object.entries(s).filter(([l])=>!l.startsWith("subscribe_")&&!l.startsWith("selfsubscribe_"))),o={...this.runtime.renderer.references.resolveArguments(a),p_0:i};return this.runtime.inlineCompiler.compile(e,t,n,Object.keys(o))(o)}}))}rebind(){this.#p(),this.registerPointers()}receive(e){if(this.#u.has(e.registration)){this.runtime.rebindBranch(this.node);return}this.#l.has(e.registration)&&this.remote.receive(e),this.#d.has(e.registration)&&this.remote.register(),this.runtime.renderer.project(this.node,e)}track(e){if(this.closed)throw new Error(`NodeBinding of '${this.node.label}' is closed`);return this.#i.push(e),()=>{let t=this.#i.indexOf(e);t!==-1&&this.#i.splice(t,1)}}async call(e,t){let{controller:n}=t,i=this.track(()=>n.abort());try{let s=await this.runtime.gramlot.rpc.call(e,t.method,t.params,{signal:n.signal});if(n.signal.aborted)throw n.signal.reason;return s}finally{i()}}callSync(e,t,n){return this.node.requests.submitSync(t,()=>this.runtime.gramlot.rpc.callSync(e,t,n))}close(){if(this.closed)return;this.#r=!0,this.node._getMeta("data_element")&&this.runtime.renderer.references.remove(this.node),this.#p();let e=[];for(let t of this.#i.splice(0).reverse())try{t()}catch(n){e.push(n)}if(e.length)throw new AggregateError(e,`NodeBinding of '${this.node.label}' cleanup failed`)}#p(){for(let e of this.#n.splice(0))e.close();this.#u.clear(),this.#l.clear(),this.#d.clear()}};var Qn=class extends or{static renderType="object";#e=new Set;#t=new WeakMap;#r=new WeakMap;#i=new WeakMap;constructor(e,t,n,{binding:i}={}){if(super(e),!(e instanceof Se)||!(t instanceof ge)||n?.nodeType!==1)throw new TypeError("GramlotRenderer requires a BuilderBase, GramlotBuilderBag and HTML destination");if(!(i instanceof Jr))throw new TypeError("GramlotRenderer requires a BindingRuntime");if(!(t._builder instanceof Se))throw new TypeError("SourceBag requires builder ownership");this._binding=i,this.source=t,this.destination=n,this.html=new fs({metadataAttributes:["__ref"],invokeScript:(s,a,o,l)=>this.inlineCompiler.compile(s,a,o,s.parentNode._getMeta("gramlot_component").childParameters[a].inline)(l)}),this.records=new Map,this.references=new Yn(t),this.pending=[],this.building=!1,this.disposed=!1,this.elements=new WeakMap,this.instanceId=Me(),this.radioGroups=new ds(this),this.subscription=`html-source-renderer-${this.instanceId}`,t.subscribe(this.subscription,{any:s=>this.receive(s)})}get binding(){return this._binding}get inlineCompiler(){return this.binding.inlineCompiler}evaluateExpressions(e,t){let n=this.#r.get(e)??super.evaluateExpressions(e,t),i=e._getMeta("gramlot_component");if(i?.presentationDefaults.length){let s=e.getAttr();this.#i.set(e,Object.fromEntries(Object.entries(n).filter(([a])=>Object.hasOwn(s,a)&&i.presentationDefaults.some(o=>a.startsWith(o)))))}if(i&&(i.parameters.value?.binding==="twoWay"||i.presentationDefaults.length)){let s=[];for(let a=e.parentNode;a;a=a.parentNode)this.#i.has(a)&&s.unshift(this.#i.get(a));n=Object.assign({},...s,n)}return this.#r.delete(e),this.#t.set(e,n),n}render(e,t={}){if(!(e instanceof ar))throw new TypeError("Source children must be GramlotBuilderBagNodes");if(e._getMeta("data_element")||!this.binding.bindingFor(e)&&this.#o(e))return null;if(e.nodeTag)this.html.validate(e,e._getMeta("subbuilder")?e.parentBag._builder:e.builder);else if(!(e.value instanceof N))throw new TypeError("Source fragments must contain child SourceBags");return e.nodeTag?super.render(e,t):this.renderFragment(e,t)}renderFragment(e,{document:t=this.destination.ownerDocument,...n}={}){let i=t.createDocumentFragment(),s={node:e,binding:this.#c(e),container:null,parent:null,children:new Set,cleanup:[],start:t.createComment("source-fragment"),end:t.createComment("/source-fragment")};this.records.set(e,s),this.elements.set(i,s),i.append(s.start);for(let a of e.value.getNodes()){let o=this.render(a,{document:t,...n});if(o===null)continue;i.append(o);let l=this.elements.get(o);l&&(l.parent=s,s.children.add(a))}return i.append(s.end),i}renderedItem(e,t,n,{tag:i,document:s=this.destination.ownerDocument}={}){let a=n;t=this.expressionValue(e,t),this.getRender(e.builder)===this&&(a=this.restoreNativeAttributes(e,n),e._getMeta("gramlot_component")||([t,a]=Hn(t,a,(p,h)=>this._binding.gramlot.format(p,h)))),a=this.componentAttributes(e,a);let o=Array.isArray(t)?t:[],l=Array.isArray(t)?a._text:t,u=this.#t.get(e),c={node:e,binding:this.#c(e),container:null,parent:null,children:new Set,cleanup:[],resolved:u,...this.html.create(e,s,i,a,u.visible??null)};this.html.compose(c,l,o),c.shape=Te.shape(c.element,u),this.records.set(e,c),this.elements.set(c.element,c);let d=Te.for(c.binding,c);d&&(c.control=d,d.attach(),c.cleanup.push(()=>d.detach()),this.#u(c,e,a,null));let f=ps.for(c.binding,c);f&&(c.button=f,f.attach(),c.cleanup.push(()=>f.detach())),this.#f(c),this.references?.register(e,c.element);for(let p of o){let h=this.elements.get(p);h&&(h.parent=c,h.container=c.element,c.children.add(h.node))}return c.element}validateCandidate(e,{replacingNode:t=null}={}){if(!(e instanceof ge))throw new TypeError("Source values must be GramlotBuilderBags");let n=new Set,i=s=>{if(!n.has(s)){n.add(s);for(let a of this.records.get(s)?.children??[])i(a);if(s.value instanceof N)for(let a of s.value.getNodes())i(a)}};for(let s of this.records.get(t)?.children??[])i(s);if(t?.value instanceof N)for(let s of t.value.getNodes())i(s);return this.#n(e,t?t.nodeTag:null),io(e),this.references?.validate(e,n),e}#n(e,t=null){let n=new Set,i=(s,a=null)=>{if(!(s instanceof ge)||n.has(s))throw new TypeError("Source values must be unshared, acyclic GramlotBuilderBags");if(!(s._builder instanceof Se))throw new TypeError("SourceBag requires builder ownership");n.add(s);for(let o of s.getNodes()){if(!(o instanceof ar))throw new TypeError("Source children must be GramlotBuilderBagNodes");if(!(o.builder instanceof Se))throw new TypeError("SourceBagNode requires builder ownership");if(o.resolver)throw new TypeError("Source resolvers are outside this port");if(o._getMeta("data_element"))o.builder.validateNode(o);else if(o.nodeTag){let l=o._getMeta("subbuilder")?s._builder:o.builder;this.html.validate(o,l),o._getMeta("subbuilder")||o.builder.validateParent(o.nodeTag,a)}else{if(!(o.value instanceof N))throw new TypeError("Source fragments must contain child SourceBags");if(Object.keys(o.attr).some(l=>l!=="_meta"))throw new TypeError("Fragment attributes are unsupported")}o.value instanceof N&&i(o.value,o._getMeta("subbuilder")?null:o.nodeTag??a)}};i(e,t)}freeze(e){e=me(e);let t=this.records.get(e);if(!t||this.disposed)throw new Error("Freeze requires a mounted Source node");t.frozen=!0}unfreeze(e){e=me(e);let t=this.records.get(e);if(!t||this.disposed)throw new Error("Unfreeze requires a mounted Source node");let n=i=>{delete i.frozen;for(let s of i.children)n(this.records.get(s))};n(t),!this.#s(e)&&(this.attached(e)?this.#h(e):this.remove(e))}#s(e){for(;e;){let t=this.records.get(e);if(t?.frozen)return!0;e=e.parentBag?.parentNode??t?.parent?.node}return!1}receive(e){if(!this.disposed){if(Array.isArray(e.node)){let t=e.node.filter(n=>!this.#e.has(n));if(!t.length)return;e={...e,node:t}}else if(this.#e.has(e.node))return;if(this.pending.push(e),!this.building){this.building=!0;try{for(;this.pending.length;){let t=this.pending.shift();if(t.evt!=="del"&&!this.attached(t.node))continue;t.evt!=="del"&&t.evt!=="upd_attrs"&&this.#l(t);let n=this.binding.handleSourceEvent(t);try{this.#a(t,n)}catch(i){if(!n.length)throw i;n.push(i)}if(n.length)throw n.length===1?n[0]:new AggregateError(n,"Source cleanup failed")}}catch(t){throw this.pending.length=0,t}finally{this.building=!1}}}}#a(e,t){if(e.evt==="del"){for(let n of Array.isArray(e.node)?e.node:[e.node]){if(this.#s(n))continue;let i=this.records.get(n)?.parent??null;try{this.remove(n)}catch(s){t.push(s)}this.#p(i)}return}if(!this.#s(e.node))if(e.evt==="ins")this.insert(e.node);else if(e.evt.startsWith("upd_"))this.update(e.node,e.evt);else throw new Error(`Unsupported Source event: ${e.evt}`)}attached(e){let t=e.parentBag;for(;t&&t!==this.source;)t=t.parentNode?.parentBag;return t===this.source}#o(e){let t=new Set(this.pending.flatMap(n=>Array.isArray(n.node)?n.node:[n.node]));for(let n=e;n;n=n.parentBag?.parentNode)if(t.has(n))return!0;return!1}#l(e){let t=n=>{if(!(n instanceof ar))throw new TypeError("Source children must be GramlotBuilderBagNodes");if(n.value instanceof N){if(!(n.value instanceof ge))throw new TypeError("Source values must be GramlotBuilderBags");for(let i of n.value.getNodes())t(i)}};t(e.node)}insert(e){if(!this.attached(e)||this.records.has(e))return;if(e._getMeta("data_element")){this.records.get(e.parentBag?.parentNode)?.button?.refresh(),this.binding.branchBuilt(e);return}let t=this.records.get(e.parentBag?.parentNode),n=t?.element??t?.container??this.destination,i=e.parentBag.getNodes(),s=t?.end??null;for(let a=i.indexOf(e)+1;a<i.length;a++){let o=this.records.get(i[a]);if(o){s=o.element??o.start;break}}this.buildNode(e,n,s,t)}buildNode(e,t,n=null,i=null){this.#e.add(e);let s;try{s=this.render(e,{document:t.ownerDocument})}catch(o){this.#d(e,o)}finally{this.#e.delete(e)}let a=this.records.get(e);return t.insertBefore(s,n),a.parent=i,this.assignContainer(a,t),i?.children.add(e),this.#p(i),this.binding.branchBuilt(e),a}#d(e,t){let n=[t],i=[],s=a=>{if(i.push(a),a.value instanceof N)for(let o of a.value.getNodes())s(o)};s(e);for(let a of i.reverse())try{this.remove(a)}catch(o){n.push(o)}throw n.length===1?t:new AggregateError(n,"Source build and cleanup failed")}assignContainer(e,t){e.container=t;let n=e.element??t;for(let i of e.children){let s=this.records.get(i);s&&this.assignContainer(s,n)}}update(e,t){let n=this.records.get(e);if(!n){this.insert(e);return}let i=e.value==null||["string","number","boolean"].includes(typeof e.value),s=t==="upd_value"&&i&&n.element&&n.children.size===0&&this.html.matches(n,e);(t==="upd_attrs"||s)&&n.element&&this.html.matches(n,e)?(e.nodeTag&&this.html.validate(e,e._getMeta("subbuilder")?e.parentBag._builder:e.builder),this.project(e),t==="upd_attrs"&&this.records.get(e)===n&&(this.references?.remove(e),this.references?.register(e,n.element))):this.#h(e)}project(e,t=null){let n=this.records.get(e);if(!n?.element)return;let i=this.getRender(e.builder),s=this.#i.get(e),[a,o]=e.rootBuilder.runtimeValues(e),[,l]=i._handleMeta(e,o),u=this.#t.get(e);if(n.shape!==Te.shape(n.element,u)){if(this.#s(e))return;this.#r.set(e,u);try{this.#h(e)}finally{this.#r.delete(e)}return}n.resolved=u;let c=e._getMeta("subbuilder")?l:i.adaptAttrs(l),d=e.value instanceof N,f=d?[]:this.expressionValue(e,a);i===this&&(c=this.restoreNativeAttributes(e,c),e._getMeta("gramlot_component")||([f,c]=Hn(f,c,(h,m)=>this._binding.gramlot.format(h,m)))),c=this.componentAttributes(e,c),this.html.update(n,e,c,d?c._text:f,u.visible??null),this.#u(n,e,c,t),n.control?.refresh(),n.button?.refresh(),this.#f(n);let p=this.#i.get(e);if(p){let h=new Set([...Object.keys(s??{}),...Object.keys(p)].filter(m=>!Object.is(s?.[m],p[m])));h.size&&this.#m(e,h)}(n.element.localName==="option"||n.element.localName==="optgroup")&&this.#p(n.parent)}#m(e,t){if(e.value instanceof N)for(let n of e.value.getNodes()){let i=n._getMeta("gramlot_component"),s=n.getAttr(),a=t;i?.presentationDefaults.length?a=new Set([...t].filter(o=>!Object.hasOwn(s,o))):i?.parameters.value?.binding==="twoWay"&&[...t].some(o=>!Object.hasOwn(s,o))&&this.project(n),a.size&&this.#m(n,a)}}componentAttributes(e,t){let n=e._getMeta("gramlot_component"),i=e.parentNode?._getMeta("gramlot_component")?.childParameters;if(!n&&!i)return t;let s=this.#t.get(e),a=Object.fromEntries([...new Set([...Object.keys(n?.parameters??{}),...Object.keys(i??{}),...Object.keys(s).filter(o=>o.startsWith("validate_"))])].filter(o=>Object.hasOwn(s,o)).map(o=>[o,s[o]]));return{...t,...a}}#u(e,t,n,i){if(!e.control)return;let s=t.getAttr("value")!=null;(s||e.valueDeclared)&&e.control.project(n.value??null,i),e.valueDeclared=s}#f(e){let t=new Map(Xn.declared(e.node).map(n=>[n[0],n]));if(!e.events){if(!t.size)return;e.events=new Map,e.cleanup.push(()=>{for(let n of e.events.values())n.detach();e.events.clear()})}for(let[n,i]of[...e.events])t.get(n)?.[2]!==i.handler&&(i.detach(),e.events.delete(n));for(let[n,[,i,s]]of t){if(e.events.has(n))continue;let a=new Xn(e.binding,e,i,s,n);a.attach(),e.events.set(n,a)}}#p(e){for(let t=e;t;t=t.parent){if(t.control instanceof Gn){this.project(t.node);return}if(t.element&&t.element.localName!=="optgroup")return}}getDomNode(e){let t=me(e),n=this.records.get(t);return n&&this.attached(t)?n.element??null:null}getBaseSourceNode(e){for(let t=e;t;t=t.parentNode){let n=t.nodeType===1?this.elements.get(t):null;if(n)return this.attached(n.node)?n.node:null}return null}#c(e){let t=this.binding.bindingFor(e);if(!t)throw new Error(`${e.nodeTag??"fragment"} '${e.label}': rendered without an open NodeBinding`);return t}#h(e){let t=this.records.get(e),n=t.element?.nextSibling??t.end?.nextSibling??null,i=t.container,s=t.parent,a=null;try{this.remove(e)}catch(o){a=o}try{this.buildNode(e,i,n,s)}catch(o){throw a?new AggregateError([a,o],"Source replacement cleanup and commit failed"):o}if(a)throw a}onDispose(e,t){let n=this.records.get(e);if(!n)throw new Error("Source node is not mounted");return n.cleanup.push(t),()=>{let i=n.cleanup.indexOf(t);i!==-1&&n.cleanup.splice(i,1)}}remove(e){let t=this.records.get(e);if(!t)return;let n=[];for(let i of[...t.children])try{this.remove(i)}catch(s){n.push(s)}for(let i of t.cleanup.splice(0).reverse())try{i()}catch(s){n.push(s)}if(this.references?.remove(e),t.element&&this.elements.delete(t.element),t.element?.remove(),t.start?.remove(),t.end?.remove(),t.parent?.children.delete(e),this.records.delete(e),this.#t.delete(e),this.#i.delete(e),n.length)throw new AggregateError(n,"Source cleanup failed")}dispose(){if(this.disposed)return;this.disposed=!0,this.source.unsubscribe(this.subscription,{any:!0}),this.pending.length=0;let e=[],t=[...this.records.entries()].filter(([,n])=>!n.parent).map(([n])=>n);for(let n of t)try{this.remove(n)}catch(i){e.push(i)}if(e.length)throw new AggregateError(e,"Renderer cleanup failed")}};var Eg=new Set(["page","constructor"]);function kc(r,e){if(r===null)return[];let t=r.split("/");for(let n of t)if(Eg.has(n))throw new Error(`${e}: a logic group cannot be named '${n}' (group '${r}')`);return t}var Ag=new Set(["return","typeof","instanceof","in","of","new","delete","void","throw","case","do","else","yield","await"]);function xg(r){return/^[\w$]/.test(r)?Ag.has(r):r!==")"&&r!=="]"}function Tg(r,e){let t=!1;for(let n=e+1;n<r.length;n++){let i=r[n];if(i===`
|
|
62
|
+
${t}`,{cause:i})}}var xs=class{#e;#t;#r=null;#i=null;constructor(e){this.#e=e,this.#t=new Jn(e)}get binding(){return this.#e}get node(){return this.binding.node}get closed(){return this.binding.closed}register(){this.#t.startTiming(this.#s("_timing"),()=>this.update())}receive(e){if(this.#s("_userChanges")&&e.level!=="node")return;let t=this.#s("_delay");t>0?this.#t.debounce(t,()=>this.update()):this.update()}async update(){if(this.closed||!this.binding.hasStamp("start"))return;let e=this.node,[,t]=e.rootBuilder.runtimeValues(e),n=t.remote,i={};for(let[l,u]of Object.entries(t))l.startsWith("remote_")&&(i[l.slice(7)]=u);let s=e.getAttr("_if");if(s&&!this.#a("_if",s,`return (${s})`,i)){let l=e.getAttr("_else");l&&this.#a("_else",l,l,i);return}let a;try{let l=ne(i);if(t._cachedRemote&&this.#n(n,l))return;let u=e.getAttr("_onCalling");if(!e.requests.calling(u?()=>this.#a("_onCalling",u,u,i):null))return;a=await this.binding.runtime.gramlot.src.remoteSource(e,n,i)}catch(l){throw new Error(`${e.nodeTag} '${e.label}': remote '${n}' failed: ${l.message}`,{cause:l})}let o=e.getAttr("_onRemote");a&&o&&this.#a("_onRemote",o,o,i)}fragmentMounted(e,t){this.#r=e,this.#i=t}#n(e,t){let n=this.node.requests.inflight;return n?n.method===e&&ne(n.params)===t:e===this.#r&&t===this.#i}#s(e){let[,t]=this.node.rootBuilder.runtimeValues(this.node);return t[e]??null}#a(e,t,n,i){return this.binding.runtime.inlineCompiler.compile(this.node,e,t,Object.keys(i),n)(i)}};var yg=new Set(["title","msg","fields","_if","askIf"]),vg=new Set(["name","lbl","tag","type","default_value","required","min","max","step","placeholder"]),Ts=class{#e;#t=null;#r=new Map;constructor(e){this.#e=e}get runtime(){return this.#e}required(e,t,n,i){let s=(a,o)=>typeof o=="boolean"?o:e.runtime.inlineCompiler.compile(e.node,a,o,Object.keys(n),`return (${o});`)(n);if(typeof t=="string"){let a=e.node.getAttr("_ask_if");return!a||!!s("_ask_if",a)}return t?.askIf&&s(`${i}.askIf`,t.askIf),!t?._if||!!s(`${i}._if`,t._if)}show(e,t,n,i="Parameters"){let s=typeof t=="string"?{msg:t,title:i}:t;if(!s||typeof s!="object"||Array.isArray(s))throw new TypeError("ask requires text or a parameter description");for(let d of Object.keys(s))if(!yg.has(d))throw new Error(`Unsupported ask option: ${d}`);let a=s.fields??[];if(!Array.isArray(a))throw new TypeError("ask fields must be an array");let o=new Set;for(let d of a){if(!d||!/^[A-Za-z_]\w*$/.test(d.name)||o.has(d.name))throw new Error("ask fields require distinct simple names");o.add(d.name);for(let f of Object.keys(d))if(!vg.has(f))throw new Error(`Unsupported ask field option: ${f}`);if(d.tag&&!["input","textarea"].includes(d.tag))throw new Error(`Unsupported ask widget: ${d.tag}`);if(d.type&&!["text","number","date","checkbox","email","password","url","tel"].includes(d.type))throw new Error(`Unsupported ask input type: ${d.type}`)}let l=this.runtime.gramlot,u=this.#i(),c=this.#r;return new Promise((d,f)=>{let p=`ask_${Me()}`,h=!1,m=()=>{},g=(b,y=null)=>{if(h)return;h=!0;let v=b?Object.fromEntries(a.map(x=>[x.name,l.data.getItem(`${p}.${x.name}`)])):null;c.delete(p),m();try{l.src.source.popNode(p),l.data.getNode(p)&&l.data.popNode(p),y?f(y):d(v)}catch(x){f(x)}};c.set(p,{finish:g}),m=e.track(()=>g(!1));try{let b=new Je,y=b.root.dialog({nodeId:p,datapath:p,request:p,connect_oncancel:`${u}.cancel`,connect_onclose:`${u}.cancel`,class:"gramlot-ask","aria-labelledby":`${p}_title`,style:"border:1px solid #aab4c2;border-radius:8px;padding:16px;max-width:32rem;width:calc(100% - 48px);font:inherit;"});y.h2(s.title??i,{id:`${p}_title`,style:"font-size:1.1em;margin:0 0 12px;"}),s.msg&&y.p(s.msg);let v=y.form({request:p,connect_onsubmit:`${u}.confirm`});for(let D of a){v.dataSetter({destination_path:`.${D.name}`,value:Object.hasOwn(n,D.name)?n[D.name]:D.default_value??(D.type==="checkbox"?!1:"")});let J=v.div({style:"margin:8px 0;"});J.html_label(D.lbl??D.name,{for:`${p}_${D.name}`,style:"display:block;margin-bottom:4px;"});let G={id:`${p}_${D.name}`,value:`^.${D.name}`,live:!0};for(let re of["required","min","max","step","placeholder"])D[re]!==void 0&&(G[re]=D[re]);D.tag==="textarea"?J.textarea(G):J.input({...G,type:D.type??"text"})}let x=v.div({style:"display:flex;justify-content:flex-end;gap:8px;margin-top:16px;"});x.html_button("Cancel",{type:"button",request:p,connect_onclick:`${u}.cancel`}),x.html_button("Confirm",{type:"submit",autofocus:a.length===0}),l.src.source.setItem(p,l.src.prepareSource(b.source));let $=l.src.binding.nodeIds.get(p);l.dom.getDomNode($).showModal()}catch(b){g(!1,b)}})}#i(){if(this.#t===null){let e=`ask_${Me()}`,t=this.#r;class n{confirm(s,a){a.preventDefault(),t.get(s.getAttr("request"))?.finish(!0)}cancel(s,a){a.preventDefault(),t.get(s.getAttr("request"))?.finish(!1)}}this.runtime.logicRegistry.register(n,{group:e,resource:"gramlot:ask"}),this.#t=e}return this.#t}};var yc={dataFormula:ys,dataController:vs,dataRpc:ks,dataRemote:Es},kg=["datapath","_anchor","nodeId","form","formId"],Jr=class{#e;#t=new Map;#r=new Map;#i;#n;#s;#a;#o;#l=`gramlot-data-${Me()}`;#d=!1;constructor(e,{subscriptions:t}){this.#e=e,this.#o=t,this.#i=new gs(this),this.#n=new bs(this),this.#s=new As(this),this.#a=new Ts(this)}get gramlot(){return this.#e}get subscriptions(){return this.#o}get builder(){return this.gramlot.src.builder}get renderer(){return this.gramlot.src.renderer}get logicRegistry(){return this.gramlot.src.logicRegistry}get data(){return this.builder.data}get root(){return this.data.parent}get size(){return this.#t.size}get disposed(){return this.#d}get router(){return this.#i}get installer(){return this.#n}get inlineCompiler(){return this.#s}get askDialog(){return this.#a}get nodeIds(){return this.#r}attach(){this.root.subscribe(this.#l,{any:e=>this.receiveData(e)})}receiveData(e){this.router.deliver(e)}bindingFor(e){return this.#t.get(e)??null}openBinding(e){if(this.disposed)throw new Error("BindingRuntime is disposed");let t=this.bindingFor(e);return t||(t=new so(this,e),this.#t.set(e,t)),t}closeBranch(e){let t=[];if(e.value instanceof N)for(let i of e.value.getNodes())try{this.closeBranch(i)}catch(s){t.push(s)}let n=this.bindingFor(e);if(n){this.#t.delete(e);let i=e.getAttr("nodeId");this.nodeIds.get(i)===e&&this.nodeIds.delete(i);try{n.close()}catch(s){t.push(s)}}if(t.length)throw new AggregateError(t,"Source branch close failed")}rebindBranch(e){let t=this.#h(e);for(let n of t)this.bindingFor(n)?.rebind();for(let n of t)this.renderer.project(n);for(let n of t)this.bindingFor(n)?.remote?.update()}handleSourceEvent(e){let{evt:t,node:n}=e,i=[],s=a=>{try{this.closeBranch(a)}catch(o){i.push(o)}};try{if(t==="ins")this.#m(n);else if(t==="del")for(let a of Array.isArray(n)?n:[n])s(a);else if(t==="upd_value"||t==="upd_value_attr"){if(e.oldvalue instanceof N)for(let a of e.oldvalue.getNodes())s(a);this.inlineCompiler.release(n,[""]),t==="upd_value_attr"?this.#p(n,e.attrs_diff):this.#c(n).rebind(),n.value instanceof N&&this.#m(n.value)}else if(t==="upd_attrs")this.#p(n,e.attrs_diff);else throw new Error(`Unsupported Source event: ${t}`)}catch(a){throw i.length?new AggregateError([...i,a],"Source event failed"):a}return i}branchBuilt(e){let t=[];for(let n of this.#h(e)){let i=this.bindingFor(n);!i||i.hasStamp("built")||!this.renderer.attached(n)||(i.stamp("built"),t.push(i))}for(let n of t)this.renderer.attached(n.node)&&this.#f(n,"built","_onBuilt");if(this.gramlot.state==="started")for(let n of t)this.renderer.attached(n.node)&&this.#u(n)}pageStarted(){for(let e of[...this.#t.values()])!e.closed&&e.hasStamp("built")&&this.#u(e)}dispose(){if(this.disposed)return;this.#d=!0,this.root.unsubscribe(this.#l,{any:!0}),this.nodeIds.clear();let e=[];for(let[t,n]of[...this.#t.entries()].reverse()){this.#t.delete(t);try{n.close()}catch(i){e.push(i)}}if(e.length)throw new AggregateError(e,"Binding cleanup failed")}#m(e){if(!(e instanceof N)&&this.bindingFor(e))return;let t=e instanceof N?e.getNodes().flatMap(s=>this.#h(s)):this.#h(e),n=new Set(t.filter(s=>this.bindingFor(s))),i=new Map;for(let s of t){let a=s.getAttr("nodeId");if(a!=null){if(i.has(a)||this.nodeIds.has(a)&&this.nodeIds.get(a)!==s)throw new Error(`Duplicate nodeId '${a}'`);i.set(a,s)}}for(let[s,a]of i)this.nodeIds.set(s,a);try{this.installer.install(e);for(let s of t)this.openBinding(s);for(let s of t)this.bindingFor(s).registerPointers()}catch(s){let a=[s];for(let o of t.filter(l=>!n.has(l)).reverse()){let l=o.getAttr("nodeId");i.get(l)===o&&this.nodeIds.get(l)===o&&this.nodeIds.delete(l);let u=this.bindingFor(o);if(u){this.#t.delete(o);try{u.close()}catch(c){a.push(c)}}}throw a.length>1?new AggregateError(a,"Source branch installation failed"):s}for(let s of t){let a=this.bindingFor(s);if(!(!a||a.hasStamp("init")||!this.renderer.attached(s))&&(a.stamp("init"),vc(s.getAttr("_init"))))for(let o of a.providers)o.invoke({kind:"init",change:null})}}#u(e){e.hasStamp("start")||(e.stamp("start"),this.#f(e,"start","_onStart"),e.remote?.update())}#f(e,t,n){let i=e.node.getAttr(n);if(vc(i))for(let s of e.providers){if(typeof i!="number"||i<=0){s.invoke({kind:t,change:null});continue}let a=null,o=setTimeout(()=>{a(),s.invoke({kind:t,change:null})},i);a=e.track(()=>clearTimeout(o))}}#p(e,t){let n=this.#c(e);if(this.inlineCompiler.release(e,Object.keys(t)),Object.hasOwn(t,"nodeId")){let{old:i,new:s}=t.nodeId;if(s!=null&&this.nodeIds.has(s)&&this.nodeIds.get(s)!==e)throw new Error(`Duplicate nodeId '${s}'`);this.nodeIds.get(i)===e&&this.nodeIds.delete(i),s!=null&&this.nodeIds.set(s,e)}kg.some(i=>Object.hasOwn(t,i))?this.rebindBranch(e):n.rebind()}#c(e){let t=this.bindingFor(e);if(!t)throw new Error(`${e.nodeTag??"fragment"} '${e.label}': the node has no NodeBinding (its installation failed); remove it from the Source and insert it again`);return t}#h(e){let t=[e];if(e.value instanceof N)for(let n of e.value.getNodes())t.push(...this.#h(n));return t}};function vc(r){return r===!0||typeof r=="number"}var so=class{#e;#t;#r=!1;#i=[];#n=[];#s=new Set;#a=null;#o=null;#l=new Set;#d=new Set;#m=0;#u=new Set;constructor(e,t){this.#e=e,this.#t=t}get runtime(){return this.#e}get node(){return this.#t}get closed(){return this.#r}get registrations(){return[...this.#n]}get providers(){return this.#a?[this.#a]:[]}get remote(){return this.#o}get clickCount(){return this.#m}countClick(){return++this.#m}hasStamp(e){return this.#s.has(e)}stamp(e){this.#s.add(e)}registerPointers(){this.node._getMeta("data_element")&&(this.runtime.renderer.references.remove(this.node),this.runtime.renderer.references.register(this.node,null));let e=this.node,t=e._getMeta("data_element");if(t&&!yc[e.nodeTag])return;!t&&typeof e.getAttr("remote")=="string"&&(this.#o??=new xs(this));let n=new Set,i=this.remote?Qe(e,e.getAttr("_timing")):new Set;if(this.remote){for(let[s,a]of Object.entries(e.getAttr()))if(s.startsWith("remote_"))for(let o of Qe(e,a))n.add(o)}for(let[s,a]of e.pointers()){if(t&&s!=="datapath")continue;let l=(s==="datapath"?e.parentNode:e).absDatapath(a);if(l===null)continue;let[u,c=null]=l.split("?",2),d=this.runtime.router.register({path:u,attr:c,recipient:this});this.#n.push(d),s==="datapath"&&this.#u.add(d),this.remote&&(s==="remote"||s.startsWith("remote_")||n.has(s))&&this.#l.add(d),this.remote&&(s==="_timing"||i.has(s))&&this.#d.add(d)}if(!t){this.#f(),this.remote?.register();return}this.#a??=new yc[e.nodeTag](this),this.#a.register()}#f(){let e=this.node;this.#n.push(...this.runtime.subscriptions.subscribeNode(e,(t,n)=>{if(typeof n!="string"||!n)throw new TypeError(`${t} requires a handler`);return i=>{if(this.closed)return;if(/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/.test(n)){let{group:l,method:u}=this.runtime.logicRegistry.resolve(n,e);return u.call(l,e,i)}let[,s]=e.rootBuilder.runtimeValues(e),a=Object.fromEntries(Object.entries(s).filter(([l])=>!l.startsWith("subscribe_")&&!l.startsWith("selfsubscribe_"))),o={...this.runtime.renderer.references.resolveArguments(a),p_0:i};return this.runtime.inlineCompiler.compile(e,t,n,Object.keys(o))(o)}}))}rebind(){this.#p(),this.registerPointers()}receive(e){if(this.#u.has(e.registration)){this.runtime.rebindBranch(this.node);return}this.#l.has(e.registration)&&this.remote.receive(e),this.#d.has(e.registration)&&this.remote.register(),this.runtime.renderer.project(this.node,e)}track(e){if(this.closed)throw new Error(`NodeBinding of '${this.node.label}' is closed`);return this.#i.push(e),()=>{let t=this.#i.indexOf(e);t!==-1&&this.#i.splice(t,1)}}async call(e,t){let{controller:n}=t,i=this.track(()=>n.abort());try{let s=await this.runtime.gramlot.rpc.call(e,t.method,t.params,{signal:n.signal});if(n.signal.aborted)throw n.signal.reason;return s}finally{i()}}callSync(e,t,n){return this.node.requests.submitSync(t,()=>this.runtime.gramlot.rpc.callSync(e,t,n))}close(){if(this.closed)return;this.#r=!0,this.node._getMeta("data_element")&&this.runtime.renderer.references.remove(this.node),this.#p();let e=[];for(let t of this.#i.splice(0).reverse())try{t()}catch(n){e.push(n)}if(e.length)throw new AggregateError(e,`NodeBinding of '${this.node.label}' cleanup failed`)}#p(){for(let e of this.#n.splice(0))e.close();this.#u.clear(),this.#l.clear(),this.#d.clear()}};var Qn=class extends or{static renderType="object";#e=new Set;#t=new WeakMap;#r=new WeakMap;#i=new WeakMap;constructor(e,t,n,{binding:i}={}){if(super(e),!(e instanceof Se)||!(t instanceof ge)||n?.nodeType!==1)throw new TypeError("GramlotRenderer requires a BuilderBase, GramlotBuilderBag and HTML destination");if(!(i instanceof Jr))throw new TypeError("GramlotRenderer requires a BindingRuntime");if(!(t._builder instanceof Se))throw new TypeError("SourceBag requires builder ownership");this._binding=i,this.source=t,this.destination=n,this.html=new fs({metadataAttributes:["__ref"],invokeScript:(s,a,o,l)=>this.inlineCompiler.compile(s,a,o,s.parentNode._getMeta("gramlot_component").childParameters[a].inline)(l)}),this.records=new Map,this.references=new Yn(t),this.pending=[],this.building=!1,this.disposed=!1,this.elements=new WeakMap,this.instanceId=Me(),this.radioGroups=new ds(this),this.subscription=`html-source-renderer-${this.instanceId}`,t.subscribe(this.subscription,{any:s=>this.receive(s)})}get binding(){return this._binding}get inlineCompiler(){return this.binding.inlineCompiler}evaluateExpressions(e,t){let n=this.#r.get(e)??super.evaluateExpressions(e,t),i=e._getMeta("gramlot_component");if(i?.presentationDefaults.length){let s=e.getAttr();this.#i.set(e,Object.fromEntries(Object.entries(n).filter(([a])=>Object.hasOwn(s,a)&&i.presentationDefaults.some(o=>a.startsWith(o)))))}if(i&&(i.parameters.value?.binding==="twoWay"||i.presentationDefaults.length)){let s=[];for(let a=e.parentNode;a;a=a.parentNode)this.#i.has(a)&&s.unshift(this.#i.get(a));n=Object.assign({},...s,n)}return this.#r.delete(e),this.#t.set(e,n),n}render(e,t={}){if(!(e instanceof ar))throw new TypeError("Source children must be GramlotBuilderBagNodes");if(e._getMeta("data_element")||!this.binding.bindingFor(e)&&this.#o(e))return null;if(e.nodeTag)this.html.validate(e,e._getMeta("subbuilder")?e.parentBag._builder:e.builder);else if(!(e.value instanceof N))throw new TypeError("Source fragments must contain child SourceBags");return e.nodeTag?super.render(e,t):this.renderFragment(e,t)}renderFragment(e,{document:t=this.destination.ownerDocument,...n}={}){let i=t.createDocumentFragment(),s={node:e,binding:this.#c(e),container:null,parent:null,children:new Set,cleanup:[],start:t.createComment("source-fragment"),end:t.createComment("/source-fragment")};this.records.set(e,s),this.elements.set(i,s),i.append(s.start);for(let a of e.value.getNodes()){let o=this.render(a,{document:t,...n});if(o===null)continue;i.append(o);let l=this.elements.get(o);l&&(l.parent=s,s.children.add(a))}return i.append(s.end),i}renderedItem(e,t,n,{tag:i,document:s=this.destination.ownerDocument}={}){let a=n;t=this.expressionValue(e,t),this.getRender(e.builder)===this&&(a=this.restoreNativeAttributes(e,n),e._getMeta("gramlot_component")||([t,a]=Hn(t,a,(p,h)=>this._binding.gramlot.format(p,h)))),a=this.componentAttributes(e,a);let o=Array.isArray(t)?t:[],l=Array.isArray(t)?a._text:t,u=this.#t.get(e),c={node:e,binding:this.#c(e),container:null,parent:null,children:new Set,cleanup:[],resolved:u,...this.html.create(e,s,i,a,u.visible??null)};this.html.compose(c,l,o),c.shape=Te.shape(c.element,u),this.records.set(e,c),this.elements.set(c.element,c);let d=Te.for(c.binding,c);d&&(c.control=d,d.attach(),c.cleanup.push(()=>d.detach()),this.#u(c,e,a,null));let f=ps.for(c.binding,c);f&&(c.button=f,f.attach(),c.cleanup.push(()=>f.detach())),this.#f(c),this.references?.register(e,c.element);for(let p of o){let h=this.elements.get(p);h&&(h.parent=c,h.container=c.element,c.children.add(h.node))}return c.element}validateCandidate(e,{replacingNode:t=null}={}){if(!(e instanceof ge))throw new TypeError("Source values must be GramlotBuilderBags");let n=new Set,i=s=>{if(!n.has(s)){n.add(s);for(let a of this.records.get(s)?.children??[])i(a);if(s.value instanceof N)for(let a of s.value.getNodes())i(a)}};for(let s of this.records.get(t)?.children??[])i(s);if(t?.value instanceof N)for(let s of t.value.getNodes())i(s);return this.#n(e,t?t.nodeTag:null),io(e),this.references?.validate(e,n),e}#n(e,t=null){let n=new Set,i=(s,a=null)=>{if(!(s instanceof ge)||n.has(s))throw new TypeError("Source values must be unshared, acyclic GramlotBuilderBags");if(!(s._builder instanceof Se))throw new TypeError("SourceBag requires builder ownership");n.add(s);for(let o of s.getNodes()){if(!(o instanceof ar))throw new TypeError("Source children must be GramlotBuilderBagNodes");if(!(o.builder instanceof Se))throw new TypeError("SourceBagNode requires builder ownership");if(o.resolver)throw new TypeError("Source resolvers are outside this port");if(o._getMeta("data_element"))o.builder.validateNode(o);else if(o.nodeTag){let l=o._getMeta("subbuilder")?s._builder:o.builder;this.html.validate(o,l),o._getMeta("subbuilder")||o.builder.validateParent(o.nodeTag,a)}else{if(!(o.value instanceof N))throw new TypeError("Source fragments must contain child SourceBags");if(Object.keys(o.attr).some(l=>l!=="_meta"))throw new TypeError("Fragment attributes are unsupported")}o.value instanceof N&&i(o.value,o._getMeta("subbuilder")?null:o.nodeTag??a)}};i(e,t)}freeze(e){e=me(e);let t=this.records.get(e);if(!t||this.disposed)throw new Error("Freeze requires a mounted Source node");t.frozen=!0}unfreeze(e){e=me(e);let t=this.records.get(e);if(!t||this.disposed)throw new Error("Unfreeze requires a mounted Source node");let n=i=>{delete i.frozen;for(let s of i.children)n(this.records.get(s))};n(t),!this.#s(e)&&(this.attached(e)?this.#h(e):this.remove(e))}#s(e){for(;e;){let t=this.records.get(e);if(t?.frozen)return!0;e=e.parentBag?.parentNode??t?.parent?.node}return!1}receive(e){if(!this.disposed){if(Array.isArray(e.node)){let t=e.node.filter(n=>!this.#e.has(n));if(!t.length)return;e={...e,node:t}}else if(this.#e.has(e.node))return;if(this.pending.push(e),!this.building){this.building=!0;try{for(;this.pending.length;){let t=this.pending.shift();if(t.evt!=="del"&&!this.attached(t.node))continue;t.evt!=="del"&&t.evt!=="upd_attrs"&&this.#l(t);let n=this.binding.handleSourceEvent(t);try{this.#a(t,n)}catch(i){if(!n.length)throw i;n.push(i)}if(n.length)throw n.length===1?n[0]:new AggregateError(n,"Source cleanup failed")}}catch(t){throw this.pending.length=0,t}finally{this.building=!1}}}}#a(e,t){if(e.evt==="del"){for(let n of Array.isArray(e.node)?e.node:[e.node]){if(this.#s(n))continue;let i=this.records.get(n)?.parent??null;try{this.remove(n)}catch(s){t.push(s)}this.#p(i)}return}if(!this.#s(e.node))if(e.evt==="ins")this.insert(e.node);else if(e.evt.startsWith("upd_"))this.update(e.node,e.evt);else throw new Error(`Unsupported Source event: ${e.evt}`)}attached(e){let t=e.parentBag;for(;t&&t!==this.source;)t=t.parentNode?.parentBag;return t===this.source}#o(e){let t=new Set(this.pending.flatMap(n=>Array.isArray(n.node)?n.node:[n.node]));for(let n=e;n;n=n.parentBag?.parentNode)if(t.has(n))return!0;return!1}#l(e){let t=n=>{if(!(n instanceof ar))throw new TypeError("Source children must be GramlotBuilderBagNodes");if(n.value instanceof N){if(!(n.value instanceof ge))throw new TypeError("Source values must be GramlotBuilderBags");for(let i of n.value.getNodes())t(i)}};t(e.node)}insert(e){if(!this.attached(e)||this.records.has(e))return;if(e._getMeta("data_element")){this.records.get(e.parentBag?.parentNode)?.button?.refresh(),this.binding.branchBuilt(e);return}let t=this.records.get(e.parentBag?.parentNode),n=t?.element??t?.container??this.destination,i=e.parentBag.getNodes(),s=t?.end??null;for(let a=i.indexOf(e)+1;a<i.length;a++){let o=this.records.get(i[a]);if(o){s=o.element??o.start;break}}this.buildNode(e,n,s,t)}buildNode(e,t,n=null,i=null){this.#e.add(e);let s;try{s=this.render(e,{document:t.ownerDocument})}catch(o){this.#d(e,o)}finally{this.#e.delete(e)}let a=this.records.get(e);return t.insertBefore(s,n),a.parent=i,this.assignContainer(a,t),i?.children.add(e),this.#p(i),this.binding.branchBuilt(e),a}#d(e,t){let n=[t],i=[],s=a=>{if(i.push(a),a.value instanceof N)for(let o of a.value.getNodes())s(o)};s(e);for(let a of i.reverse())try{this.remove(a)}catch(o){n.push(o)}throw n.length===1?t:new AggregateError(n,"Source build and cleanup failed")}assignContainer(e,t){e.container=t;let n=e.element??t;for(let i of e.children){let s=this.records.get(i);s&&this.assignContainer(s,n)}}update(e,t){let n=this.records.get(e);if(!n){this.insert(e);return}let i=e.value==null||["string","number","boolean"].includes(typeof e.value),s=t==="upd_value"&&i&&n.element&&n.children.size===0&&this.html.matches(n,e);(t==="upd_attrs"||s)&&n.element&&this.html.matches(n,e)?(e.nodeTag&&this.html.validate(e,e._getMeta("subbuilder")?e.parentBag._builder:e.builder),this.project(e),t==="upd_attrs"&&this.records.get(e)===n&&(this.references?.remove(e),this.references?.register(e,n.element))):this.#h(e)}project(e,t=null){let n=this.records.get(e);if(!n?.element)return;let i=this.getRender(e.builder),s=this.#i.get(e),[a,o]=e.rootBuilder.runtimeValues(e),[,l]=i._handleMeta(e,o),u=this.#t.get(e);if(n.shape!==Te.shape(n.element,u)){if(this.#s(e))return;this.#r.set(e,u);try{this.#h(e)}finally{this.#r.delete(e)}return}n.resolved=u;let c=e._getMeta("subbuilder")?l:i.adaptAttrs(l),d=e.value instanceof N,f=d?[]:this.expressionValue(e,a);i===this&&(c=this.restoreNativeAttributes(e,c),e._getMeta("gramlot_component")||([f,c]=Hn(f,c,(h,m)=>this._binding.gramlot.format(h,m)))),c=this.componentAttributes(e,c),this.html.update(n,e,c,d?c._text:f,u.visible??null),this.#u(n,e,c,t),n.control?.refresh(),n.button?.refresh(),this.#f(n);let p=this.#i.get(e);if(p){let h=new Set([...Object.keys(s??{}),...Object.keys(p)].filter(m=>!Object.is(s?.[m],p[m])));h.size&&this.#m(e,h)}(n.element.localName==="option"||n.element.localName==="optgroup")&&this.#p(n.parent)}#m(e,t){if(e.value instanceof N)for(let n of e.value.getNodes()){let i=n._getMeta("gramlot_component"),s=n.getAttr(),a=t;i?.presentationDefaults.length?a=new Set([...t].filter(o=>!Object.hasOwn(s,o))):i?.parameters.value?.binding==="twoWay"&&[...t].some(o=>!Object.hasOwn(s,o))&&this.project(n),a.size&&this.#m(n,a)}}componentAttributes(e,t){let n=e._getMeta("gramlot_component"),i=e.parentNode?._getMeta("gramlot_component")?.childParameters;if(!n&&!i)return t;let s=this.#t.get(e),a=Object.fromEntries([...new Set([...Object.keys(n?.parameters??{}),...Object.keys(i??{}),...Object.keys(s).filter(o=>o.startsWith("validate_"))])].filter(o=>Object.hasOwn(s,o)).map(o=>[o,s[o]]));return{...t,...a}}#u(e,t,n,i){if(!e.control)return;let s=t.getAttr("value")!=null;(s||e.valueDeclared)&&e.control.project(n.value??null,i),e.valueDeclared=s}#f(e){let t=new Map(Xn.declared(e.node).map(n=>[n[0],n]));if(!e.events){if(!t.size)return;e.events=new Map,e.cleanup.push(()=>{for(let n of e.events.values())n.detach();e.events.clear()})}for(let[n,i]of[...e.events])t.get(n)?.[2]!==i.handler&&(i.detach(),e.events.delete(n));for(let[n,[,i,s]]of t){if(e.events.has(n))continue;let a=new Xn(e.binding,e,i,s,n);a.attach(),e.events.set(n,a)}}#p(e){for(let t=e;t;t=t.parent){if(t.control instanceof Gn){this.project(t.node);return}if(t.element&&t.element.localName!=="optgroup")return}}getDomNode(e){let t=me(e),n=this.records.get(t);return n&&this.attached(t)?n.element??null:null}getBaseSourceNode(e){for(let t=e;t;t=t.parentNode){let n=t.nodeType===1?this.elements.get(t):null;if(n)return this.attached(n.node)?n.node:null}return null}#c(e){let t=this.binding.bindingFor(e);if(!t)throw new Error(`${e.nodeTag??"fragment"} '${e.label}': rendered without an open NodeBinding`);return t}#h(e){let t=this.records.get(e),n=t.element?.nextSibling??t.end?.nextSibling??null,i=t.container,s=t.parent,a=null;try{this.remove(e)}catch(o){a=o}try{this.buildNode(e,i,n,s)}catch(o){throw a?new AggregateError([a,o],"Source replacement cleanup and commit failed"):o}if(a)throw a}onDispose(e,t){let n=this.records.get(e);if(!n)throw new Error("Source node is not mounted");return n.cleanup.push(t),()=>{let i=n.cleanup.indexOf(t);i!==-1&&n.cleanup.splice(i,1)}}remove(e){let t=this.records.get(e);if(!t)return;let n=[];for(let i of[...t.children])try{this.remove(i)}catch(s){n.push(s)}for(let i of t.cleanup.splice(0).reverse())try{i()}catch(s){n.push(s)}if(this.references?.remove(e),t.element&&this.elements.delete(t.element),t.element?.remove(),t.start?.remove(),t.end?.remove(),t.parent?.children.delete(e),this.records.delete(e),this.#t.delete(e),this.#i.delete(e),n.length)throw new AggregateError(n,"Source cleanup failed")}dispose(){if(this.disposed)return;this.disposed=!0,this.source.unsubscribe(this.subscription,{any:!0}),this.pending.length=0;let e=[],t=[...this.records.entries()].filter(([,n])=>!n.parent).map(([n])=>n);for(let n of t)try{this.remove(n)}catch(i){e.push(i)}if(e.length)throw new AggregateError(e,"Renderer cleanup failed")}};var Eg=new Set(["page","constructor"]);function kc(r,e){if(r===null)return[];let t=r.split("/");for(let n of t)if(Eg.has(n))throw new Error(`${e}: a logic group cannot be named '${n}' (group '${r}')`);return t}var Ag=new Set(["return","typeof","instanceof","in","of","new","delete","void","throw","case","do","else","yield","await"]);function xg(r){return/^[\w$]/.test(r)?Ag.has(r):r!==")"&&r!=="]"}function Tg(r,e){let t=!1;for(let n=e+1;n<r.length;n++){let i=r[n];if(i===`
|
|
63
63
|
`)return-1;if(i==="\\"){n++;continue}if(i==="[")t=!0;else if(i==="]")t=!1;else if(i==="/"&&!t)return n}return-1}function Dg(r){let e=0,t="",n="";for(let i=r.indexOf("{");i<r.length;i++){let s=r[i];if(s==="/"&&r[i+1]==="/"){if(i=r.indexOf(`
|
|
64
|
-
`,i),i<0)break;continue}if(s==="/"&&r[i+1]==="*"){let a=r.indexOf("*/",i+2);if(a>=0){i=a+1;continue}}if(s==="/"&&xg(n)){let a=Tg(r,i);if(a>=0){i=a,n=")";continue}}if(s==='"'||s==="'"||s==="`"){let a=i+1;for(;a<r.length&&r[a]!==s;)a+=r[a]==="\\"?2:1;e===1&&(t+=r.slice(i+1,a)==="constructor"?" constructor":' ""'),i=a,n=")";continue}if(/[\w$]/.test(s)){let a=i+1;for(;a<r.length&&/[\w$]/.test(r[a]);)a++;e===1&&(t+=r.slice(i,a)),n=r.slice(i,a),i=a-1;continue}if(/\s/.test(s)||(n=s),s==="{"){++e===2&&(t+=" {}");continue}if(s==="}"){e--;continue}e===1&&(t+=s)}return/(?<![\w$.#])(?<!\bstatic\s+)constructor\s*\(/.test(t)}function Ec(r,e){if(r===void 0)return[];if(typeof r!="function"||!/^class\b/.test(Function.prototype.toString.call(r)))throw new Error(`${e}: the module exports no class Logic`);if(Object.getPrototypeOf(r)!==Function.prototype||Object.getPrototypeOf(r.prototype)!==Object.prototype)throw new Error(`${e}: class Logic cannot extend another class`);if(Dg(Function.prototype.toString.call(r)))throw new Error(`${e}: class Logic cannot declare a constructor; state lives on the group or the page`);let t=[];for(let n of Reflect.ownKeys(r.prototype)){if(n==="constructor")continue;if(typeof n=="symbol")throw new Error(`${e}: class Logic cannot declare symbol keys (${String(n)})`);let i=Object.getOwnPropertyDescriptor(r.prototype,n);if(i.get||i.set)throw new Error(`${e}: class Logic cannot declare the accessor '${n}'`);if(typeof i.value!="function")throw new Error(`${e}: Logic.prototype.${n} is not a method`);if(n==="page")throw new Error(`${e}: a logic method cannot be named 'page'`);t.push([n,i.value])}return t}function Ac(r,e,t){Object.defineProperty(r,e,{value:t,writable:!0,enumerable:!0,configurable:!0})}var ur=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get page(){return this.#t}},Kr=class{#e;#t=new Map;constructor(e){this.#e=e,e.logic=new ur(this,e)}get gramlot(){return this.#e}static check(e){let t=new Map;for(let{group:n,resource:i}of e){let s=kc(n,i);for(let a=0;a<s.length;a++){let o=s.slice(0,a).join("/");t.has(o)||t.set(o,new Set),t.get(o).add(s[a])}}for(let{logicClass:n,group:i,resource:s}of e){let a=t.get(i??"")??new Set;for(let[o]of Ec(n,s))if(a.has(o))throw new Error(`${s}: the logic method '${o}' has the name of a child group`)}}register(e,{group:t=null,resource:n}){let i=kc(t,n),s=Ec(e,n),a=this.#e.logic;for(let o of i){let l=Object.getOwnPropertyDescriptor(a,o)?.value;if(l===void 0){let u=new ur(this,this.#e);Ac(a,o,u),a=u}else if(l instanceof ur)a=l;else throw new Error(`${n}: the group '${o}' has the name of a logic method`)}for(let[o,l]of s){if(Object.getOwnPropertyDescriptor(a,o)?.value instanceof ur)throw new Error(`${n}: the logic method '${o}' has the name of a child group`);Ac(a,o,l)}this.#t.has(a)||this.#t.set(a,[]),this.#t.get(a).push(n)}resolve(e,t){let n=e.split("."),i=n.pop(),s=this.#e.logic;for(let o=0;o<n.length;o++)if(s=Object.getOwnPropertyDescriptor(s,n[o])?.value,!(s instanceof ur))throw new Error(`${t.nodeTag} '${t.label}': named logic '${e}' not found: no resource was registered for the group '${n.slice(0,o+1).join("/")}'`);let a=Object.getOwnPropertyDescriptor(s,i)?.value;if(typeof a!="function"){let o=this.#t.get(s)??[],l=n.length?`the group '${n.join("/")}'`:"the page logic";throw new Error(`${t.nodeTag} '${t.label}': named logic '${e}' not found: ${l} has no method '${i}' (resources: ${o.join(", ")||"none"})`)}return{group:s,method:a}}};var ei=class extends Le{constructor(e,{collections:t,destination:n,subscriptions:i,nameSyntax:s}){super(e),e.src=this,this.logicRegistry=new Kr(e),this.builder=new Je(null,{collections:t,nameSyntax:s}),this.binding=new Jr(e,{subscriptions:i}),this.builder.binding=this.binding,this.binding.attach(),this.source=this.builder.source,this.renderer=new Qn(this.builder,this.source,n,{binding:this.binding})}startSource(e){if(!["ready","failed"].includes(this.gramlot.state))throw new Error(`Cannot start embedded Source while Gramlot is ${this.gramlot.state}`);try{return this.mountMainSource(e)}catch(t){throw this.gramlot.state="failed",t}}mountMainSource(e){let t=this.prepareSource(e);this.renderer.validateCandidate(t);try{this.source.setItem("main",t)}catch(n){throw this.binding.bindingFor(this.source.getNode("main"))||this.source.popNode("main"),n}return this.gramlot.state="started",this.binding.pageStarted(),this.binding.subscriptions.ready(),this.gramlot}prepareSource(e,t=this.builder){if(e instanceof N){if(!(e instanceof ge))throw new TypeError("Source values must be GramlotBuilderBags");return e.bindBuilder(t).activateCode()}if(typeof e!="string")throw new TypeError("Source value did not decode to SourceBag");let n=ja(e,t);if(!(n instanceof ge))throw new TypeError("Source values must be GramlotBuilderBags");return n.activateCode()}async remoteSource(e,t,n={}){if(!this.gramlot.rpc.transport?.call)throw new Error("Remote Source is unavailable without a server transport");let s=this.binding.bindingFor(e);if(this.gramlot.state!=="started"||!s)throw new Error("Remote Source target is not mounted");return await e.requests.submit(t,n,a=>this.#e(e,s,a))??!1}async#e(e,t,n){if(t.closed||this.gramlot.state==="disposed")return!1;let i=!1,s=()=>this.gramlot.state!=="disposed"&&!n.ignored&&!t.closed;try{let a=await t.call("source",n);if(!s())return!1;let o=this.prepareSource(a,e.builder);return s()?(this.renderer.validateCandidate(o,{replacingNode:e}),i=!0,e.setValue(o,!0,{_text:null},!0),t.remote?.fragmentMounted(n.method,n.text),!0):!1}catch(a){if(!i&&!s())return!1;throw a}}};var ti=class extends Error{name="RpcError";constructor({code:e,name:t,message:n,details:i}){super(n),this.code=e,this.remoteName=t,i!==void 0&&(this.details=i)}},ri=class extends Le{constructor(e,{rpcUrl:t,closeUrl:n,document:i,transport:s}){super(e),this.transport=s===!1?null:s??e.serverAdapter.createTransport({rpcUrl:t,closeUrl:n,document:i}),this.remoteRequests=new Map}get supportsCallSync(){return this.transport?.supportsCallSync===!0}callSync(e,t,n={}){if(!this.supportsCallSync)throw new Error(`rpc '${t}': the transport of this page has no synchronous call`);if(Yr(n),this.gramlot.abort.signal.aborted)throw this.gramlot.abort.signal.reason;let i=Me(),s=Z(this.transport.callSync(ne({id:i,pageId:this.gramlot.pageId,contentType:e,name:t,params:n})));if(s.id!==i)throw new Error("rpc response id mismatch");if(s.error)throw new ti(s.error);return s.value}async call(e,t,n={},{signal:i=null}={}){if(!this.transport?.call)throw new Error(`rpc '${t}' is unavailable without a server transport`);Yr(n);let s=Me(),a=ne({id:s,pageId:this.gramlot.pageId,contentType:e,name:t,params:n}),o=i?[this.gramlot.abort.signal,i]:[this.gramlot.abort.signal],l=o.find(f=>f.aborted);if(l)throw l.reason;let u=new AbortController,c=f=>u.abort(f.target.reason);for(let f of o)f.addEventListener("abort",c,{once:!0});let d=new Promise((f,p)=>{u.signal.addEventListener("abort",()=>{this.remoteRequests.delete(s),p(u.signal.reason)},{once:!0})});this.remoteRequests.set(s,u);try{let f=Z(await Promise.race([this.transport.call(a,u.signal),d]));if(f.id!==s)throw new Error("rpc response id mismatch");if(f.error)throw new ti(f.error);return f.value}finally{this.remoteRequests.delete(s);for(let f of o)f.removeEventListener("abort",c)}}};var ni=class extends Le{setTouchMode(e="auto"){if(!["auto","on","off"].includes(e))throw new TypeError(`Invalid touch mode: ${e}`);let t=this.gramlot.src.renderer.destination.ownerDocument.documentElement;e==="auto"?t.removeAttribute("data-gramlot-touch"):t.setAttribute("data-gramlot-touch",e)}reference(e){return this.gramlot.src.renderer.references.resolve(e)}getBaseSourceNode(e){return this.gramlot.src.renderer.getBaseSourceNode(e)}getDomNode(e){return this.gramlot.src.renderer.getDomNode(e)}};var xc="gramlot:publish",Ds=class{#e;#t;#r;#i=Me();#n=new Map;#s=!1;#a;#o;#l;#d;constructor(e,t){this.#e=e,this.#r=t,this.#t=t.defaultView,this.#a=i=>this.#p(i),this.#o=i=>{if(i.target?.localName!=="iframe")return;let s=this.#g(i.target);s&&(this.#u(s.window),this.#c(s,{kind:"hello"}))},this.#t.addEventListener("message",this.#a),this.#l=()=>this.#m(),this.#d=()=>this.ready(),this.#t.addEventListener("pagehide",this.#l),this.#t.addEventListener("pageshow",this.#d),t.addEventListener("load",this.#o,!0);let n=this.#h();n&&this.#c(n,{kind:"hello"})}ready(){if(this.#s||this.#e.state!=="started")return;let e=this.#h();e&&this.#c(e,{kind:"ready"});for(let t of this.#r.getElementsByTagName("iframe")){let n=this.#g(t);n&&this.#c(n,{kind:"hello"})}}prepare(e,t){let n=[];if(e.parent){let a=this.#h();if(!a)throw new Error("This page has no parent frame");n.push(a)}if(e.iframe!==void 0){let a=e.iframe,o=me(a),l=typeof a=="string"?this.#r.getElementById(a):o instanceof Ce?this.#e.dom.getDomNode(o):null,u=this.#g(l);if(!u)throw new Error("iframe destination must be an active Gramlot iframe ID or Source reference");n.push(u)}let i=n.map(a=>{let o=this.#n.get(a.window);if(!o||o.origin!==a.origin)throw new Error("Destination page is not ready");return{...a,session:o.session}});Yr(t);let s=ne(t);return()=>{if(!this.#s)for(let a of i){let o=this.#_(a.window);if(!o||o.origin!==a.origin||this.#n.get(a.window)?.session!==a.session)throw new Error("Destination page disconnected before publication");this.#c(a,{kind:"publish",recipient:a.session,topic:e.topic,wire:s})}}}dispose(){this.#s||(this.#m(),this.#s=!0,this.#t.removeEventListener("message",this.#a),this.#t.removeEventListener("pagehide",this.#l),this.#t.removeEventListener("pageshow",this.#d),this.#r.removeEventListener("load",this.#o,!0))}#m(){for(let[e,t]of this.#n)this.#c({window:e,origin:t.origin},{kind:"close"});for(let e of this.#n.keys())this.#u(e)}#u(e){this.#n.get(e)?.release?.(),this.#n.delete(e)}#f(e,t){this.#u(e.window);let n={session:t,origin:e.origin};e.node&&(n.release=this.#e.src.binding.bindingFor(e.node).track(()=>{this.#c(e,{kind:"close"}),this.#u(e.window)})),this.#n.set(e.window,n)}#p(e){if(this.#s||e.data?.type!==xc)return;let t=this.#_(e.source);if(!t||e.origin!==t.origin)return;let n=e.data;if(!(typeof n.session!="string"||!n.session)){if(n.kind==="hello")this.#u(t.window),n.ready===!0&&this.#f(t,n.session),this.#e.state==="started"&&this.#c(t,{kind:"ready"});else if(n.kind==="ready"){let i=this.#n.get(t.window)?.session!==n.session;this.#f(t,n.session),i&&this.#e.state==="started"&&this.#c(t,{kind:"ready"})}else if(n.kind==="close")this.#n.get(t.window)?.session===n.session&&this.#u(t.window);else if(n.kind==="publish"){if(this.#e.state!=="started"||n.recipient!==this.#i||this.#n.get(t.window)?.session!==n.session||typeof n.topic!="string"||!n.topic||typeof n.wire!="string")return;this.#e.publish(n.topic,Z(n.wire))}}}#c(e,t){e.window.postMessage({type:xc,session:this.#i,ready:this.#e.state==="started",...t},e.origin==="null"?"*":e.origin)}#h(){let e=this.#t.parent;return e===this.#t?null:{window:e,origin:this.#b(this.#r.referrer||this.#r.baseURI)}}#g(e){if(e?.localName!=="iframe"||!e.isConnected||!e.contentWindow)return null;let t=this.#e.dom.getBaseSourceNode(e);if(!t||!this.#e.src.binding.bindingFor(t)||this.#e.dom.getDomNode(t)!==e)return null;let n=e.getAttribute("sandbox"),s=n!==null&&!n.split(/\s+/).includes("allow-same-origin")?"null":this.#b(e.hasAttribute("srcdoc")?this.#r.baseURI:e.getAttribute("src")||this.#r.baseURI);return{window:e.contentWindow,origin:s,node:t}}#b(e){let t=new URL(e,this.#r.baseURI);return t.protocol==="file:"?"null":t.origin}#_(e){let t=this.#h();if(t?.window===e)return t;for(let n of this.#r.getElementsByTagName("iframe")){let i=this.#g(n);if(i?.window===e)return i}return null}};var Cs=class extends Le{#e=new Map;#t=new WeakSet;#r=new WeakMap;#i=0;#n=!1;#s;attach(e){this.#s=new Ds(this.gramlot,e)}ready(){this.#s.ready()}subscribe(e,t){if(this.#l(),this.#o(e),typeof t!="function")throw new TypeError("subscribe requires a callback");let n=Object.freeze({});return this.#t.add(n),this.#e.has(e)||this.#e.set(e,new Map),this.#e.get(e).set(n,t),n}unsubscribe(e){if(!this.#t.has(e))throw new TypeError("Unknown subscription registration");for(let[t,n]of this.#e)n.delete(e)&&!n.size&&this.#e.delete(t)}publish(e,t={}){if(this.#l(),!t||typeof t!="object"||Array.isArray(t))throw new TypeError("publish requires one object of named data");if(typeof e=="string")return this.#a(e,t);if(!e||typeof e!="object"||Array.isArray(e))throw new TypeError("publish requires a topic string or descriptor");if(Object.keys(e).some(s=>!["topic","nodeId","parent","iframe"].includes(s)))throw new Error("This publication route is not implemented yet");if(this.#o(e.topic),e.parent!==void 0&&typeof e.parent!="boolean")throw new TypeError("parent must be boolean");if(e.iframe==="*")throw new Error("Recursive iframe broadcast is not implemented yet");if((e.parent||e.iframe!==void 0)&&Object.hasOwn(e,"nodeId"))throw new Error("Interframe node addressing is not implemented yet");let i=e.parent||e.iframe!==void 0?this.#s.prepare(e,t):null;if(Object.hasOwn(e,"nodeId")){let s=this.gramlot.src.binding.nodeIds.get(e.nodeId);if(!s)throw new Error(`node_id not found: ${e.nodeId}`);return this.publishNode(s,e.topic,t)}this.#a(e.topic,t),i?.()}topicFor(e,t){this.#o(t),e=me(e);let n=this.gramlot.src.binding.bindingFor(e);if(!n||n.closed)throw new Error("Topic target is not an active Source node of this page");let i=e.getAttr("node_id");return i==null&&(this.#r.has(e)||this.#r.set(e,`gramlot-self-${++this.#i}`),i=this.#r.get(e)),`${i}_${t}`}publishNode(e,t,n={}){return this.publish(this.topicFor(e,t),n)}subscribeNode(e,t){let n=[];for(let[i,s]of Object.entries(e.getAttr())){let a=i.startsWith("selfsubscribe_")?"selfsubscribe_":i.startsWith("subscribe_")?"subscribe_":null;if(!a)continue;let o=a==="selfsubscribe_"?this.topicFor(e,i.slice(a.length)):i.slice(a.length);this.#o(o),n.push([o,t(i,s,o)])}return this.#l(),n.map(([i,s])=>{let a=this.subscribe(i,s);return{close:()=>this.unsubscribe(a)}})}dispose(){this.#n=!0,this.#s.dispose(),this.#e.clear()}#a(e,t){this.#o(e);let n=this.#e.get(e);if(n)for(let[i,s]of[...n]){if(this.#n)break;n.has(i)&&s(t)}}#o(e){if(typeof e!="string"||!e)throw new TypeError("A topic must be a nonempty string")}#l(){if(this.#n)throw new Error("Gramlot subscriptions are disposed")}};var Tc=2e3;function Cg(r){if(!(r instanceof Date))return String(r??"");let e=r.toISOString();return e.endsWith("T00:00:00.000Z")?e.slice(0,10):e}var ii=class{constructor(e,t){this.gramlot=e,this.document=t}branch(e){let t=this.gramlot.data.getItem(e);if(!(t instanceof V))throw new Error(`gramlot.utl.inout: no data Bag at '${e}'`);return t}mailText(e){let t=[],n=(i,s)=>{for(let a of i.getNodes()){let o=s+a.label;a.value instanceof V?n(a.value,`${o}.`):t.push(`${o}: ${Cg(a.value)}`)}};return n(this.branch(e),""),t.join(`
|
|
64
|
+
`,i),i<0)break;continue}if(s==="/"&&r[i+1]==="*"){let a=r.indexOf("*/",i+2);if(a>=0){i=a+1;continue}}if(s==="/"&&xg(n)){let a=Tg(r,i);if(a>=0){i=a,n=")";continue}}if(s==='"'||s==="'"||s==="`"){let a=i+1;for(;a<r.length&&r[a]!==s;)a+=r[a]==="\\"?2:1;e===1&&(t+=r.slice(i+1,a)==="constructor"?" constructor":' ""'),i=a,n=")";continue}if(/[\w$]/.test(s)){let a=i+1;for(;a<r.length&&/[\w$]/.test(r[a]);)a++;e===1&&(t+=r.slice(i,a)),n=r.slice(i,a),i=a-1;continue}if(/\s/.test(s)||(n=s),s==="{"){++e===2&&(t+=" {}");continue}if(s==="}"){e--;continue}e===1&&(t+=s)}return/(?<![\w$.#])(?<!\bstatic\s+)constructor\s*\(/.test(t)}function Ec(r,e){if(r===void 0)return[];if(typeof r!="function"||!/^class\b/.test(Function.prototype.toString.call(r)))throw new Error(`${e}: the module exports no class Logic`);if(Object.getPrototypeOf(r)!==Function.prototype||Object.getPrototypeOf(r.prototype)!==Object.prototype)throw new Error(`${e}: class Logic cannot extend another class`);if(Dg(Function.prototype.toString.call(r)))throw new Error(`${e}: class Logic cannot declare a constructor; state lives on the group or the page`);let t=[];for(let n of Reflect.ownKeys(r.prototype)){if(n==="constructor")continue;if(typeof n=="symbol")throw new Error(`${e}: class Logic cannot declare symbol keys (${String(n)})`);let i=Object.getOwnPropertyDescriptor(r.prototype,n);if(i.get||i.set)throw new Error(`${e}: class Logic cannot declare the accessor '${n}'`);if(typeof i.value!="function")throw new Error(`${e}: Logic.prototype.${n} is not a method`);if(n==="page")throw new Error(`${e}: a logic method cannot be named 'page'`);t.push([n,i.value])}return t}function Ac(r,e,t){Object.defineProperty(r,e,{value:t,writable:!0,enumerable:!0,configurable:!0})}var ur=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get page(){return this.#t}},Kr=class{#e;#t=new Map;constructor(e){this.#e=e,e.logic=new ur(this,e)}get gramlot(){return this.#e}static check(e){let t=new Map;for(let{group:n,resource:i}of e){let s=kc(n,i);for(let a=0;a<s.length;a++){let o=s.slice(0,a).join("/");t.has(o)||t.set(o,new Set),t.get(o).add(s[a])}}for(let{logicClass:n,group:i,resource:s}of e){let a=t.get(i??"")??new Set;for(let[o]of Ec(n,s))if(a.has(o))throw new Error(`${s}: the logic method '${o}' has the name of a child group`)}}register(e,{group:t=null,resource:n}){let i=kc(t,n),s=Ec(e,n),a=this.#e.logic;for(let o of i){let l=Object.getOwnPropertyDescriptor(a,o)?.value;if(l===void 0){let u=new ur(this,this.#e);Ac(a,o,u),a=u}else if(l instanceof ur)a=l;else throw new Error(`${n}: the group '${o}' has the name of a logic method`)}for(let[o,l]of s){if(Object.getOwnPropertyDescriptor(a,o)?.value instanceof ur)throw new Error(`${n}: the logic method '${o}' has the name of a child group`);Ac(a,o,l)}this.#t.has(a)||this.#t.set(a,[]),this.#t.get(a).push(n)}resolve(e,t){let n=e.split("."),i=n.pop(),s=this.#e.logic;for(let o=0;o<n.length;o++)if(s=Object.getOwnPropertyDescriptor(s,n[o])?.value,!(s instanceof ur))throw new Error(`${t.nodeTag} '${t.label}': named logic '${e}' not found: no resource was registered for the group '${n.slice(0,o+1).join("/")}'`);let a=Object.getOwnPropertyDescriptor(s,i)?.value;if(typeof a!="function"){let o=this.#t.get(s)??[],l=n.length?`the group '${n.join("/")}'`:"the page logic";throw new Error(`${t.nodeTag} '${t.label}': named logic '${e}' not found: ${l} has no method '${i}' (resources: ${o.join(", ")||"none"})`)}return{group:s,method:a}}};var ei=class extends Le{constructor(e,{collections:t,destination:n,subscriptions:i,nameSyntax:s}){super(e),e.src=this,this.logicRegistry=new Kr(e),this.builder=new Je(null,{collections:t,nameSyntax:s}),this.binding=new Jr(e,{subscriptions:i}),this.builder.binding=this.binding,this.binding.attach(),this.source=this.builder.source,this.renderer=new Qn(this.builder,this.source,n,{binding:this.binding})}startSource(e){if(!["ready","failed"].includes(this.gramlot.state))throw new Error(`Cannot start embedded Source while Gramlot is ${this.gramlot.state}`);try{return this.mountMainSource(e)}catch(t){throw this.gramlot.state="failed",t}}mountMainSource(e){let t=this.prepareSource(e);this.renderer.validateCandidate(t);try{this.source.setItem("main",t)}catch(n){throw this.binding.bindingFor(this.source.getNode("main"))||this.source.popNode("main"),n}return this.gramlot.state="started",this.binding.pageStarted(),this.binding.subscriptions.ready(),this.gramlot}prepareSource(e,t=this.builder){if(e instanceof N){if(!(e instanceof ge))throw new TypeError("Source values must be GramlotBuilderBags");return e.bindBuilder(t).activateCode()}if(typeof e!="string")throw new TypeError("Source value did not decode to SourceBag");let n=ja(e,t);if(!(n instanceof ge))throw new TypeError("Source values must be GramlotBuilderBags");return n.activateCode()}async remoteSource(e,t,n={}){if(!this.gramlot.rpc.transport?.call)throw new Error("Remote Source is unavailable without a server transport");let s=this.binding.bindingFor(e);if(this.gramlot.state!=="started"||!s)throw new Error("Remote Source target is not mounted");return await e.requests.submit(t,n,a=>this.#e(e,s,a))??!1}async#e(e,t,n){if(t.closed||this.gramlot.state==="disposed")return!1;let i=!1,s=()=>this.gramlot.state!=="disposed"&&!n.ignored&&!t.closed;try{let a=await t.call("source",n);if(!s())return!1;let o=this.prepareSource(a,e.builder);return s()?(this.renderer.validateCandidate(o,{replacingNode:e}),i=!0,e.setValue(o,!0,{_text:null},!0),t.remote?.fragmentMounted(n.method,n.text),!0):!1}catch(a){if(!i&&!s())return!1;throw a}}};var ti=class extends Error{name="RpcError";constructor({code:e,name:t,message:n,details:i}){super(n),this.code=e,this.remoteName=t,i!==void 0&&(this.details=i)}},ri=class extends Le{constructor(e,{rpcUrl:t,closeUrl:n,document:i,transport:s}){super(e),this.transport=s===!1?null:s??e.serverAdapter.createTransport({rpcUrl:t,closeUrl:n,document:i}),this.remoteRequests=new Map}get supportsCallSync(){return this.transport?.supportsCallSync===!0}callSync(e,t,n={}){if(!this.supportsCallSync)throw new Error(`rpc '${t}': the transport of this page has no synchronous call`);if(Yr(n),this.gramlot.abort.signal.aborted)throw this.gramlot.abort.signal.reason;let i=Me(),s=Z(this.transport.callSync(ne({id:i,pageId:this.gramlot.pageId,contentType:e,name:t,params:n})));if(s.id!==i)throw new Error("rpc response id mismatch");if(s.error)throw new ti(s.error);return s.value}async call(e,t,n={},{signal:i=null}={}){if(!this.transport?.call)throw new Error(`rpc '${t}' is unavailable without a server transport`);Yr(n);let s=Me(),a=ne({id:s,pageId:this.gramlot.pageId,contentType:e,name:t,params:n}),o=i?[this.gramlot.abort.signal,i]:[this.gramlot.abort.signal],l=o.find(f=>f.aborted);if(l)throw l.reason;let u=new AbortController,c=f=>u.abort(f.target.reason);for(let f of o)f.addEventListener("abort",c,{once:!0});let d=new Promise((f,p)=>{u.signal.addEventListener("abort",()=>{this.remoteRequests.delete(s),p(u.signal.reason)},{once:!0})});this.remoteRequests.set(s,u);try{let f=Z(await Promise.race([this.transport.call(a,u.signal),d]));if(f.id!==s)throw new Error("rpc response id mismatch");if(f.error)throw new ti(f.error);return f.value}finally{this.remoteRequests.delete(s);for(let f of o)f.removeEventListener("abort",c)}}};var ni=class extends Le{setTouchMode(e="auto"){if(!["auto","on","off"].includes(e))throw new TypeError(`Invalid touch mode: ${e}`);let t=this.gramlot.src.renderer.destination.ownerDocument.documentElement;e==="auto"?t.removeAttribute("data-gramlot-touch"):t.setAttribute("data-gramlot-touch",e)}reference(e){return this.gramlot.src.renderer.references.resolve(e)}getBaseSourceNode(e){return this.gramlot.src.renderer.getBaseSourceNode(e)}getDomNode(e){return this.gramlot.src.renderer.getDomNode(e)}};var xc="gramlot:publish",Ds=class{#e;#t;#r;#i=Me();#n=new Map;#s=!1;#a;#o;#l;#d;constructor(e,t){this.#e=e,this.#r=t,this.#t=t.defaultView,this.#a=i=>this.#p(i),this.#o=i=>{if(i.target?.localName!=="iframe")return;let s=this.#g(i.target);s&&(this.#u(s.window),this.#c(s,{kind:"hello"}))},this.#t.addEventListener("message",this.#a),this.#l=()=>this.#m(),this.#d=()=>this.ready(),this.#t.addEventListener("pagehide",this.#l),this.#t.addEventListener("pageshow",this.#d),t.addEventListener("load",this.#o,!0);let n=this.#h();n&&this.#c(n,{kind:"hello"})}ready(){if(this.#s||this.#e.state!=="started")return;let e=this.#h();e&&this.#c(e,{kind:"ready"});for(let t of this.#r.getElementsByTagName("iframe")){let n=this.#g(t);n&&this.#c(n,{kind:"hello"})}}prepare(e,t){let n=[];if(e.parent){let a=this.#h();if(!a)throw new Error("This page has no parent frame");n.push(a)}if(e.iframe!==void 0){let a=e.iframe,o=me(a),l=typeof a=="string"?this.#r.getElementById(a):o instanceof Ce?this.#e.dom.getDomNode(o):null,u=this.#g(l);if(!u)throw new Error("iframe destination must be an active Gramlot iframe ID or Source reference");n.push(u)}let i=n.map(a=>{let o=this.#n.get(a.window);if(!o||o.origin!==a.origin)throw new Error("Destination page is not ready");return{...a,session:o.session}});Yr(t);let s=ne(t);return()=>{if(!this.#s)for(let a of i){let o=this.#_(a.window);if(!o||o.origin!==a.origin||this.#n.get(a.window)?.session!==a.session)throw new Error("Destination page disconnected before publication");this.#c(a,{kind:"publish",recipient:a.session,topic:e.topic,wire:s})}}}dispose(){this.#s||(this.#m(),this.#s=!0,this.#t.removeEventListener("message",this.#a),this.#t.removeEventListener("pagehide",this.#l),this.#t.removeEventListener("pageshow",this.#d),this.#r.removeEventListener("load",this.#o,!0))}#m(){for(let[e,t]of this.#n)this.#c({window:e,origin:t.origin},{kind:"close"});for(let e of this.#n.keys())this.#u(e)}#u(e){this.#n.get(e)?.release?.(),this.#n.delete(e)}#f(e,t){this.#u(e.window);let n={session:t,origin:e.origin};e.node&&(n.release=this.#e.src.binding.bindingFor(e.node).track(()=>{this.#c(e,{kind:"close"}),this.#u(e.window)})),this.#n.set(e.window,n)}#p(e){if(this.#s||e.data?.type!==xc)return;let t=this.#_(e.source);if(!t||e.origin!==t.origin)return;let n=e.data;if(!(typeof n.session!="string"||!n.session)){if(n.kind==="hello")this.#u(t.window),n.ready===!0&&this.#f(t,n.session),this.#e.state==="started"&&this.#c(t,{kind:"ready"});else if(n.kind==="ready"){let i=this.#n.get(t.window)?.session!==n.session;this.#f(t,n.session),i&&this.#e.state==="started"&&this.#c(t,{kind:"ready"})}else if(n.kind==="close")this.#n.get(t.window)?.session===n.session&&this.#u(t.window);else if(n.kind==="publish"){if(this.#e.state!=="started"||n.recipient!==this.#i||this.#n.get(t.window)?.session!==n.session||typeof n.topic!="string"||!n.topic||typeof n.wire!="string")return;this.#e.publish(n.topic,Z(n.wire))}}}#c(e,t){e.window.postMessage({type:xc,session:this.#i,ready:this.#e.state==="started",...t},e.origin==="null"?"*":e.origin)}#h(){let e=this.#t.parent;return e===this.#t?null:{window:e,origin:this.#b(this.#r.referrer||this.#r.baseURI)}}#g(e){if(e?.localName!=="iframe"||!e.isConnected||!e.contentWindow)return null;let t=this.#e.dom.getBaseSourceNode(e);if(!t||!this.#e.src.binding.bindingFor(t)||this.#e.dom.getDomNode(t)!==e)return null;let n=e.getAttribute("sandbox"),s=n!==null&&!n.split(/\s+/).includes("allow-same-origin")?"null":this.#b(e.hasAttribute("srcdoc")?this.#r.baseURI:e.getAttribute("src")||this.#r.baseURI);return{window:e.contentWindow,origin:s,node:t}}#b(e){let t=new URL(e,this.#r.baseURI);return t.protocol==="file:"?"null":t.origin}#_(e){let t=this.#h();if(t?.window===e)return t;for(let n of this.#r.getElementsByTagName("iframe")){let i=this.#g(n);if(i?.window===e)return i}return null}};var Cs=class extends Le{#e=new Map;#t=new WeakSet;#r=new WeakMap;#i=0;#n=!1;#s;attach(e){this.#s=new Ds(this.gramlot,e)}ready(){this.#s.ready()}subscribe(e,t){if(this.#l(),this.#o(e),typeof t!="function")throw new TypeError("subscribe requires a callback");let n=Object.freeze({});return this.#t.add(n),this.#e.has(e)||this.#e.set(e,new Map),this.#e.get(e).set(n,t),n}unsubscribe(e){if(!this.#t.has(e))throw new TypeError("Unknown subscription registration");for(let[t,n]of this.#e)n.delete(e)&&!n.size&&this.#e.delete(t)}publish(e,t={}){if(this.#l(),!t||typeof t!="object"||Array.isArray(t))throw new TypeError("publish requires one object of named data");if(typeof e=="string")return this.#a(e,t);if(!e||typeof e!="object"||Array.isArray(e))throw new TypeError("publish requires a topic string or descriptor");if(Object.keys(e).some(s=>!["topic","nodeId","parent","iframe"].includes(s)))throw new Error("This publication route is not implemented yet");if(this.#o(e.topic),e.parent!==void 0&&typeof e.parent!="boolean")throw new TypeError("parent must be boolean");if(e.iframe==="*")throw new Error("Recursive iframe broadcast is not implemented yet");if((e.parent||e.iframe!==void 0)&&Object.hasOwn(e,"nodeId"))throw new Error("Interframe node addressing is not implemented yet");let i=e.parent||e.iframe!==void 0?this.#s.prepare(e,t):null;if(Object.hasOwn(e,"nodeId")){let s=this.gramlot.src.binding.nodeIds.get(e.nodeId);if(!s)throw new Error(`nodeId not found: ${e.nodeId}`);return this.publishNode(s,e.topic,t)}this.#a(e.topic,t),i?.()}topicFor(e,t){this.#o(t),e=me(e);let n=this.gramlot.src.binding.bindingFor(e);if(!n||n.closed)throw new Error("Topic target is not an active Source node of this page");let i=e.getAttr("nodeId");return i==null&&(this.#r.has(e)||this.#r.set(e,`gramlot-self-${++this.#i}`),i=this.#r.get(e)),`${i}_${t}`}publishNode(e,t,n={}){return this.publish(this.topicFor(e,t),n)}subscribeNode(e,t){let n=[];for(let[i,s]of Object.entries(e.getAttr())){let a=i.startsWith("selfsubscribe_")?"selfsubscribe_":i.startsWith("subscribe_")?"subscribe_":null;if(!a)continue;let o=a==="selfsubscribe_"?this.topicFor(e,i.slice(a.length)):i.slice(a.length);this.#o(o),n.push([o,t(i,s,o)])}return this.#l(),n.map(([i,s])=>{let a=this.subscribe(i,s);return{close:()=>this.unsubscribe(a)}})}dispose(){this.#n=!0,this.#s.dispose(),this.#e.clear()}#a(e,t){this.#o(e);let n=this.#e.get(e);if(n)for(let[i,s]of[...n]){if(this.#n)break;n.has(i)&&s(t)}}#o(e){if(typeof e!="string"||!e)throw new TypeError("A topic must be a nonempty string")}#l(){if(this.#n)throw new Error("Gramlot subscriptions are disposed")}};var Tc=2e3;function Cg(r){if(!(r instanceof Date))return String(r??"");let e=r.toISOString();return e.endsWith("T00:00:00.000Z")?e.slice(0,10):e}var ii=class{constructor(e,t){this.gramlot=e,this.document=t}branch(e){let t=this.gramlot.data.getItem(e);if(!(t instanceof V))throw new Error(`gramlot.utl.inout: no data Bag at '${e}'`);return t}mailText(e){let t=[],n=(i,s)=>{for(let a of i.getNodes()){let o=s+a.label;a.value instanceof V?n(a.value,`${o}.`):t.push(`${o}: ${Cg(a.value)}`)}};return n(this.branch(e),""),t.join(`
|
|
65
65
|
`)}mailtoUrl(e,t){let n=`mailto:${encodeURIComponent(t)}?subject=${encodeURIComponent(this.document.title)}&body=${encodeURIComponent(this.mailText(e))}`;if(n.length>Tc)throw new Error(`gramlot.utl.inout.sendMail: the email of '${e}' is ${n.length} characters long, over the mailto: limit of ${Tc}; send it with sendHttp or save it as a file`);return n}sendMail(e,t){this.open(this.mailtoUrl(e,t))}async sendHttp(e,t){let n=JSON.stringify(this.branch(e).asDict(!1,!1,!0)),i=await this.document.defaultView.fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:n});if(!i.ok)throw new Error(`gramlot.utl.inout.sendHttp: ${t} answered ${i.status}`);return i}save(e,t){this.saveText(this.branch(e).toTytx(),t,"application/json")}restore(e){let t=this.document.createElement("input");return t.type="file",t.accept=".json,application/json",new Promise((n,i)=>{t.addEventListener("change",async()=>{try{let s=Z(await t.files[0].text());if(!(s instanceof V))throw new TypeError("the file must contain a typed Bag");this.gramlot.data.setItem(e,s),n(s)}catch(s){i(new Error(`gramlot.utl.inout.restore: the file is not a saved Gramlot branch: ${s.message}`,{cause:s}))}},{once:!0}),t.click()})}download(e,t,n){if(!["json","xml"].includes(n))throw new Error(`gramlot.utl.inout.download: format '${n}' is not 'json' or 'xml'`);let i=this.branch(e);if(n==="json")this.saveText(i.toJson(!1),t,"application/json");else{let s=e.split(".").at(-1);this.saveText(`<?xml version='1.0' encoding='UTF-8'?>
|
|
66
66
|
<${s}>${i.toXml()}</${s}>`,t,"application/xml")}}saveText(e,t,n){let i=this.document.defaultView,s=i.URL.createObjectURL(new i.Blob([e],{type:n}));this.open(s,t),i.setTimeout(()=>i.URL.revokeObjectURL(s),1e3)}open(e,t=null){let n=this.document.createElement("a");n.href=e,t!==null&&(n.download=t),n.click()}};var si=class extends Le{constructor(e,t){super(e),this.inout=new ii(e,t)}};var ai=class{constructor({pageId:e,rpcUrl:t="/gramlot/rpc",closeUrl:n="/gramlot/close",rootId:i="gramlot-root",capabilities:s=[],element:a=null,document:o=a?.ownerDocument??globalThis.document,transport:l=null,collections:u=[],locale:c=null,timeZone:d=null,devices:f=[],serverAdapter:p=new wt,nameSyntax:h=null}={}){ss.register(o.defaultView);for(let g of u)g instanceof sr&&g.register(o.defaultView);this.pageId=e;let m=c==null||d==null?o.defaultView.Intl.DateTimeFormat().resolvedOptions():null;this.devices=Object.freeze([...f]),this.locale=c??m.locale,this.timeZone=d??m.timeZone,Object.defineProperty(this,"_subscriptions",{value:new Cs(this)}),this.capabilities=Object.freeze([...s]),this.serverAdapter=p,this.src=new ei(this,{collections:u,destination:a??o.getElementById(i),subscriptions:this._subscriptions,nameSyntax:h===null?Un:ir.fromJSON(h)}),this.data=this.src.builder.data,this.rpc=new ri(this,{rpcUrl:t,closeUrl:n,document:o,transport:l}),this.dom=new ni(this),this.utl=new si(this,o),this.state="ready",this._subscriptions.attach(o),this.abort=new AbortController,this.rpc.transport&&(this.pagehide=g=>{g.persisted||this.dispose({beacon:!0})},o.defaultView.addEventListener("pagehide",this.pagehide),this.window=o.defaultView)}publish(e,t={}){return this._subscriptions.publish(e,t)}subscribe(e,t){return this._subscriptions.subscribe(e,t)}unsubscribe(e){this._subscriptions.unsubscribe(e)}format(e,t){return ic(e,t,{locale:this.locale,timeZone:this.timeZone})}start(){return this.state==="disposed"?Promise.reject(new Error("Gramlot is disposed")):this.rpc.transport?this.loading?this.loading:this.state==="started"?Promise.resolve(this):(this.state="loading",this.loading=this.loadMain().finally(()=>{this.loading=null}),this.loading):Promise.reject(new Error("This Gramlot instance has no server transport"))}async loadMain(){let e;try{e=await this.rpc.call("source","main")}catch(t){throw this.state==="disposed"?new Error("Gramlot was disposed during main",{cause:t}):(this.state="failed",t)}if(this.state==="disposed")throw new Error("Gramlot was disposed during main");try{return this.src.mountMainSource(e)}catch(t){throw this.state!=="disposed"&&(this.state="failed"),t}}dispose({beacon:e=!1}={}){if(this.state!=="disposed"){this.state="disposed",this._subscriptions.dispose(),this.pagehide&&this.window.removeEventListener("pagehide",this.pagehide),this.abort.abort();try{try{this.src.binding.dispose()}finally{this.src.renderer.dispose()}}finally{this.rpc.transport&&(this.rpc.transport.close(this.pageId,{beacon:e}),this.rpc.transport.dispose())}}}};var ao=class{constructor({config:e,resources:t,document:n=globalThis.document}){this.config=e,this.resources=t,this.document=n,this.serverAdapter=new wt}async run(){let{config:e,resources:t,document:n}=this,i=n.defaultView;t.serverAdapter!==void 0&&(this.serverAdapter=await this.loadServerAdapter(t.serverAdapter));for(let c of t.css){let d=n.createElement("link");d.rel="stylesheet",d.href=c,n.head.append(d)}let s=!1,a=c=>{c.persisted||s||(s=!0,this.closePage())};i.addEventListener("pagehide",a);let o,l;try{let c=await Promise.allSettled(t.js.map(({url:d})=>import(new URL(d,n.baseURI).href)));if(s||(o=t.js.map(({url:d,group:f},p)=>{let h=c[p];if(h.status==="rejected")throw new Error(`${d}: import failed: ${h.reason?.message??h.reason}`,{cause:h.reason});return{logicClass:h.value.Logic,group:f,resource:d}}),Kr.check(o),l=await Promise.all((t.collections??[]).map(async d=>{try{return(await import(new URL(d,n.baseURI).href)).default}catch(f){throw new Error(`${d}: collection import failed: ${f.message}`,{cause:f})}})),s))return null;for(let d of l)d.register(i)}catch(c){throw this.closePage(),c}finally{i.removeEventListener("pagehide",a)}let u=new ai({...e,document:n,serverAdapter:this.serverAdapter,collections:[...e.collections??[],...l.map(c=>c.toDocument())]});for(let{logicClass:c,group:d,resource:f}of o)u.src.logicRegistry.register(c,{group:d,resource:f});return i.gramlot=u,await u.start(),u}async loadServerAdapter(e){let t;try{t=await import(new URL(e,this.document.baseURI).href)}catch(n){throw new Error(`${e}: server adapter import failed: ${n.message}`,{cause:n})}return new t.default}closePage(){let e=this.serverAdapter.createTransport({...this.config,document:this.document});e.close(this.config.pageId,{beacon:!0}),e.dispose()}};var Ss=Symbol("gramlot.source"),oo=Symbol("gramlot.endpoint"),Sg=new Map([[Ss,"registerSource"],[oo,"registerEndpoint"]]);function Dc(r,e,t,n){let i=Sg.get(t);if(e==="main")throw new TypeError(`${i} cannot declare main`);let s=Object.getOwnPropertyDescriptor(r.prototype,e)?.value;if(typeof s!="function")throw new TypeError(`${i} requires an own method of ${r.name}: ${String(e)}`);if(s[t])throw new TypeError(`${t===Ss?"Source method":"Endpoint"} already registered: ${e}`);if(s[Ss]||s[oo])throw new TypeError(`${e} is declared both as Source method and endpoint`);s[t]={auth:n}}var Ns=class{static registerSource(e,{auth:t=null}={}){Dc(this,e,Ss,t)}static registerEndpoint(e,{auth:t=null}={}){Dc(this,e,oo,t)}},oi=class extends Ns{static title="Gramlot";static devices=[];static locale=null;static timeZone=null;static installable=!1;static appIcon=null;manifest({baseUrl:e="./"}={}){let{title:t,appIcon:n}=this.constructor;if(typeof n!="string"||!n)throw new TypeError("An installable Page needs appIcon");return{id:e,name:t,short_name:t,start_url:e,scope:e,display:"standalone",icons:[{src:e+n.replace(/^\/+/,""),sizes:"512x512",type:"image/png"}]}}static css=[];static css_theme=null;static css_requires="";static js_requires="";static sourceBuilder=Je;main(e){throw new Error("Page.main(root) must be implemented")}};var Os=class extends oi{static title="Application";static logoUrl="";static shellId="index";static navigation=[];static css=["/themes/gramlot-index/theme.css"];main(e){let t=this.constructor.navigation,n=e.div({class:"index-shell",id:this.constructor.shellId});this.header(n);let i=n.aside({class:"index-sidebar",id:"index-sidebar"}),s=i.header();this.constructor.logoUrl&&s.img({src:this.constructor.logoUrl,alt:this.constructor.title,class:"index-logo"}),s.h1(this.constructor.title);let a=i.nav({"aria-label":"Pages"}).ul({class:"index-list"});for(let f of t){let p=a.li().details({open:f===t[0]});p.summary({tabindex:-1}).a(f.title,{id:`open-${f.key}`,href:`#panel-${f.key}`,class:"index-family",aria_current:null,tabindex:-1});let h=p.ul({class:"index-list"});for(let m of f.children)h.li().a(m.title,{id:`open-${m.key}`,href:m.url,aria_current:null,tabindex:-1})}n.div({class:"index-divider",id:"index-sidebar-divider",role:"separator",aria_orientation:"vertical",tabindex:0,aria_label:"Resize sidebar",aria_controls:"index-sidebar",aria_valuemin:120,aria_valuemax:460,aria_valuenow:240});let o=n.main({class:"index-main"}),l=o.div({class:"index-tabs",role:"tablist",aria_label:"Open pages"});l.html_button("Introduction",{type:"button",role:"tab",id:"tab-intro",aria_controls:"panel-intro",aria_selected:"true",tabindex:-1,hidden:!1});for(let f of t)for(let{key:p,title:h}of[f,...f.children])l.html_button(h,{type:"button",role:"tab",id:`tab-${p}`,aria_controls:`panel-${p}`,aria_selected:"false",tabindex:-1,hidden:!0});let u=o.div({class:"index-panels"}),c=u.section({id:"panel-intro",class:"index-intro",role:"tabpanel",aria_labelledby:"tab-intro",hidden:!1});this.introduction(c);for(let f of t){let p=u.section({id:`panel-${f.key}`,class:"index-category",role:"tabpanel",aria_labelledby:`tab-${f.key}`,hidden:!0});this.groupPanel(p,f);for(let h of f.children)this.panel(u,h)}let d=n.footer({class:"index-footer"});this.footer(d),this.behavior(n)}header(e){}behavior(e){e.dataController({func:"indexMount",_onStart:!0,shell_id:this.constructor.shellId})}introduction(e){e.h2(this.constructor.title),e.p("Choose a page from the navigation. Open pages remain available in tabs.")}groupPanel(e,t){e.h2(t.title)}footer(e){let t=e.div({class:"index-theme"});t.html_label("Theme",{for:"index-appearance"});let n=t.select({id:"index-appearance",value:"compact"});n.option("Base",{value:"base",selected:!1}),n.option("Compact",{value:"compact",selected:!0}),n.option("mimi",{value:"mimi"}),n.option("joanna",{value:"joanna"});let i=e.div({class:"index-theme"});i.html_label("Color mode",{for:"index-theme"});let s=i.select({id:"index-theme",value:"light"});s.option("Light",{value:"light",selected:!0}),s.option("Dark",{value:"dark",selected:!1});let o=e.div({class:"index-keyboard"}).html_label({for:"keyboard-navigation"});if(o.input({type:"checkbox",id:"keyboard-navigation",checked:!1}),o.span("Keyboard navigation"),this.constructor.installable){let l=e.details({class:"index-install"});l.summary("Install app"),l.html_button("Install",{type:"button",id:"index-install-button",hidden:!0}),l.p("",{id:"index-install-status",role:"status"}),l.p("Chrome: use Install page as app in the browser menu. Safari on macOS Sonoma or later: File > Add to Dock."),l.p("Use HTTPS or localhost. For a static export, serve the directory; direct file opening is not installable. Keep the server running for hosted pages.")}}panel(e,t){e.section({id:`panel-${t.key}`,class:"index-panel",role:"tabpanel",aria_labelledby:`tab-${t.key}`,hidden:!0}).iframe({id:`frame-${t.key}`,title:t.title,name:`page-${t.key}`})}};var lo={base:"",compact:`/* Gramlot Compact: load after gramlot-base/theme.css. Colors and behavior stay in Base. */
|
|
67
67
|
@layer gramlot.tokens {
|
|
@@ -444,7 +444,7 @@ ${t}`,{cause:i})}}var xs=class{#e;#t;#r=null;#i=null;constructor(e){this.#e=e,th
|
|
|
444
444
|
@layer gramlot.utilities {
|
|
445
445
|
.card { box-shadow: var(--gramlot-shadow); }
|
|
446
446
|
}
|
|
447
|
-
`};var uo="index:theme-ready",co="index:theme-set",Is=new Set(["light","dark"]),Bs=new Set(["base","compact","mimi","joanna"]);function fo(r,e,t=()=>{},n=()=>{},{containerLayout:i=!1,state:s=null,createEntry:a=null,onLoad:o=()=>{}}={}){if(a&&!i)throw new TypeError("Deferred index entries require containerLayout");let l=r.records.get(e).element,u=l.ownerDocument,c=u.defaultView,d=w=>u.getElementById(w),f=w=>r.elements.get(w).node,p=(w,j)=>f(w).setAttr(j),h=d("keyboard-navigation"),m=d("index-theme"),g=d("index-appearance"),b=d("index-sidebar"),y=d("index-sidebar-divider"),v=d("index-navigation-toggle"),x=d("index-code-toggle"),$=d("index-code"),D=d("index-code-divider"),J=`gramlot.${l.id}.preferences:${c.location.pathname}`,G={};try{let w=JSON.parse(c.localStorage.getItem(J));w!==null&&typeof w=="object"&&!Array.isArray(w)&&(G=w)}catch(w){if(w.name!=="SyntaxError"&&w.name!=="SecurityError")throw w}let re=(w,j,k)=>{if(!(!w||!k.has(j))){p(w,{value:j});for(let S of w.options)p(S,{selected:S.value===j})}};re(m,G.theme,Is),re(g,G.appearance,Bs);let Ve=[...l.querySelectorAll(".index-sidebar details")],ae=e.builder.data.constructor,E=s??new ae,he=new ae;E.setItem("opened",he),E.setItem("keyboard",h?.checked??!1),E.setItem("theme",m?.value??"light"),E.setItem("appearance",g?.value??"compact"),E.setItem("navigationVisible",G.navigationVisible!==!1),E.setItem("codeVisible",G.codeVisible!==!1);let U=()=>{try{c.localStorage.setItem(J,JSON.stringify({theme:E.getItem("theme"),appearance:E.getItem("appearance"),sidebarWidth:E.getItem("preferredSidebarWidth"),codeWidth:E.getItem("preferredCodeWidth"),navigationVisible:E.getItem("navigationVisible"),codeVisible:E.getItem("codeVisible")}))}catch(w){if(w.name!=="SecurityError"&&w.name!=="QuotaExceededError")throw w}},X=new Map,B=[],Pt=e.builder.wrapSource(e.value).style(lo[g?.value??"compact"]),$e=null,Ne=!1,ut=null,q=u.documentElement.getAttribute("data-theme"),P=(w,j,k)=>{w&&(w.addEventListener(j,k),B.push(()=>w.removeEventListener(j,k)))},Ke=()=>{if(!$e)return;let{handle:w,pointerId:j}=$e;$e=null,Ne||p(l,{data_resizing:null}),w.hasPointerCapture(j)&&w.releasePointerCapture(j)},bt=()=>{if(!Ne){Ne=!0,ut=null,Ke();for(let w of B.reverse())w();Pt.parentBag&&Pt.parentBag.popNode(Pt.label),q==null?u.documentElement.removeAttribute("data-theme"):u.documentElement.setAttribute("data-theme",q)}},Ms=w=>w.contentWindow.postMessage({type:co,theme:E.getItem("theme"),appearance:E.getItem("appearance")},"*"),$s=()=>{u.documentElement.setAttribute("data-theme",E.getItem("theme")),Pt.setValue(lo[E.getItem("appearance")]);for(let{frame:w}of X.values())w&&Ms(w)},Fs=()=>t(X,E.getItem("active")),di=()=>{if(v){let w=E.getItem("navigationVisible");p(b,i?{drawer:w?!0:"close"}:{hidden:!w}),i||p(y,{hidden:!w}),p(v,{aria_expanded:String(w)}),p(l,{data_navigation_hidden:String(!w)})}if($){let w=!!X.get(E.getItem("active"))?.code,j=w&&E.getItem("codeVisible");p($,i?{hidden:!w,drawer:j?!0:"close"}:{hidden:!j}),i||p(D,{hidden:!j}),p(x,{disabled:!w,aria_expanded:String(j)}),p(l,{data_code_visible:String(j)})}},mo=w=>{w.panel=d(`panel-${w.key}`),w.tab=i?w.panel:d(`tab-${w.key}`),w.code=d(`codepane-${w.key}`),w.key!=="intro"&&(n(w,{byId:d,node:f,set:p,listen:P}),w.frame=d(`frame-${w.key}`),w.frame&&P(w.frame,"load",()=>Ms(w.frame)))},go=w=>{he.getItem(w.key)||(he.setItem(w.key,!0),p(i?w.panel:w.tab,{hidden:!1}),w.frame&&p(w.frame,{src:w.open.getAttribute("href")}))},Ls=!1;function mr(w){if(Ls||Ne)return;let j=X.get(w);if(j){if(E.setItem("requested",w),!j.panel){o(w,"loading"),j.loading||(j.loading=Promise.resolve().then(()=>{if(!Ne)return a(j)}).then(()=>{Ne||(mo(j),go(j),E.getItem("requested")===w&&(o(w,"ready"),mr(w)))}).catch(k=>{!Ne&&E.getItem("requested")===w&&o(w,"error",k)}).finally(()=>{j.loading=null}));return}o(w,"ready"),Ls=!0;try{let k=X.get(w);go(k),k.family&&p(k.family,{open:!0});for(let[S,z]of X){let ee=S===w;i||(p(z.tab,{aria_selected:String(ee),tabindex:ee&&E.getItem("keyboard")?0:-1}),p(z.panel,{hidden:!ee})),z.code&&p(z.code,{hidden:!ee}),z.open&&p(z.open,{aria_current:ee?"page":null})}E.getItem("active")!==w&&E.setItem("active",w),di(),Fs()}finally{Ls=!1}}}let bo=()=>Math.max(120,Math.min(460,Math.floor(c.innerWidth*.6))),_o=()=>p(l,{style:`--sidebar-width: ${E.getItem("sidebarWidth")}px; --code-width: ${E.getItem("codeWidth")??420}px`}),fi=(w,j=!1)=>{let k=bo(),S=Math.max(120,Math.min(k,w));E.setItem("sidebarWidth",S),_o(),p(y,{aria_valuenow:S,aria_valuemax:k}),j&&(E.setItem("preferredSidebarWidth",S),U())},wo=()=>Math.max(200,Math.floor(c.innerWidth*.6)),pi=(w,j=!1)=>{let k=wo(),S=Math.max(200,Math.min(k,w));E.setItem("codeWidth",S),_o(),p(D,{aria_valuenow:S,aria_valuemax:k}),j&&(E.setItem("preferredCodeWidth",S),U())},yo=(w,j,k)=>{j.button===0&&(Ke(),w.setPointerCapture(j.pointerId),$e={handle:w,pointerId:j.pointerId,move:k},p(l,{data_resizing:"true"}),j.preventDefault())};try{let w=d("index-install-button");if(w&&(P(c,"beforeinstallprompt",k=>{k.preventDefault(),ut=k,p(w,{hidden:!1,disabled:!1})}),P(c,"appinstalled",()=>{ut=null,p(w,{hidden:!0}),f(d("index-install-status")).setValue("App installed.")}),P(w,"click",async()=>{if(!ut)return;let k=ut;ut=null,p(w,{disabled:!0});try{await k.prompt();let{outcome:S}=await k.userChoice;Ne||f(d("index-install-status")).setValue(S==="accepted"?"Installation accepted.":"Installation cancelled. You can also use the browser menu.")}catch(S){Ne||f(d("index-install-status")).setValue(`Installation failed: ${S.message}`)}finally{Ne||p(w,{hidden:!0})}})),p(l,{data_resizing:null}),i){let k=r.binding.gramlot;for(let[ee,be,Ps]of[[b,"navigationVisible","sidebarWidth"],[$,"codeVisible","codeWidth"]]){let gr=f(ee),br=G[Ps];typeof br=="number"&&Number.isFinite(br)&&br>0&&p(ee,{width:`${br}px`});let Rc=k.subscribe(`${gr.getAttr("node_id")}_closable_change`,({open:Qr})=>{gr.getAttr("hidden")===!0||gr.getAttr("drawer")===!1||(E.setItem(be,Qr),p(ee,{drawer:Qr?!0:"close"}),p(be==="navigationVisible"?v:x,{aria_expanded:String(Qr)}),p(l,{[be==="navigationVisible"?"data_navigation_hidden":"data_code_visible"]:String(be==="navigationVisible"?!Qr:Qr)}),U())});B.push(()=>k.unsubscribe(Rc))}let S=l.querySelector("[data-index-regions]"),z=k.subscribe(`${f(S).getAttr("node_id")}_splitter_resize`,({region:ee,size:be})=>{p(ee==="left"?b:$,{width:be}),E.setItem(ee==="left"?"preferredSidebarWidth":"preferredCodeWidth",Number.parseFloat(be)),U()});B.push(()=>k.unsubscribe(z)),E.setItem("preferredSidebarWidth",G.sidebarWidth),E.setItem("preferredCodeWidth",G.codeWidth)}else{let k=G.sidebarWidth,S=typeof k=="number"&&Number.isFinite(k)&&k>=120&&k<=460?k:b.getBoundingClientRect().width||Number(y.getAttribute("aria-valuenow"));E.setItem("preferredSidebarWidth",S),fi(S)}if(P(v,"click",()=>{E.setItem("navigationVisible",!E.getItem("navigationVisible")),di(),U()}),P(x,"click",()=>{E.setItem("codeVisible",!E.getItem("codeVisible")),di(),U()}),!i&&D){let k=G.codeWidth,S=typeof k=="number"&&Number.isFinite(k)&&k>=200?k:420;E.setItem("preferredCodeWidth",S),pi(S),P(D,"keydown",z=>{let ee=E.getItem("codeWidth"),be=z.key==="ArrowLeft"?ee+10:z.key==="ArrowRight"?ee-10:z.key==="Home"?200:z.key==="End"?wo():null;be!=null&&(z.preventDefault(),pi(be,!0))}),P(D,"pointerdown",z=>yo(D,z,ee=>pi(Math.round(l.getBoundingClientRect().right-ee),!0))),P(D,"lostpointercapture",()=>{$e?.handle===D&&Ke()}),P(c,"resize",()=>pi(E.getItem("preferredCodeWidth")))}i||(P(y,"keydown",k=>{let S=E.getItem("sidebarWidth"),z=k.key==="ArrowLeft"?S-10:k.key==="ArrowRight"?S+10:k.key==="Home"?120:k.key==="End"?bo():null;z!=null&&(k.preventDefault(),fi(z,!0))}),P(y,"pointerdown",k=>yo(y,k,S=>fi(Math.round(S-l.getBoundingClientRect().left),!0))),P(y,"lostpointercapture",()=>{$e?.handle===y&&Ke()}),P(c,"resize",()=>fi(E.getItem("preferredSidebarWidth"))));let j=a?[d("panel-intro"),...l.querySelectorAll('.index-sidebar a[id^="open-"]')]:i?d("index-pages").children:l.querySelectorAll(".index-tabs button");for(let k of j){let S=k.id.slice(a&&k.id.startsWith("open-")?5:i?6:4),z={key:S,tab:k,panel:d(`panel-${S}`),code:d(`codepane-${S}`),open:S==="intro"?null:d(`open-${S}`)};X.set(S,z),z.panel&&(i?f(z.panel).getAttr("hidden")!==!0:!k.hidden)&&he.setItem(S,!0),!i&&k.getAttribute("aria-selected")==="true"&&E.setItem("active",S),i||P(k,"click",()=>mr(S)),z.open&&P(z.open,"click",ee=>{ee.preventDefault(),mr(S)}),i||P(k,"keydown",ee=>{if(!E.getItem("keyboard")||!["ArrowLeft","ArrowRight","Home","End"].includes(ee.key))return;let be=[...X.keys()].filter(br=>he.getItem(br)),Ps=be.indexOf(S),gr=ee.key==="Home"?0:ee.key==="End"?be.length-1:(Ps+(ee.key==="ArrowRight"?1:-1)+be.length)%be.length;ee.preventDefault(),mr(be[gr]),X.get(be[gr]).tab.focus()}),S!=="intro"&&(z.family=z.open.closest("details"),z.panel&&mo(z))}if(i){let k=d("index-pages");P(k,"click",z=>{z.target===k&&z.composedPath().some(ee=>ee instanceof c.Element&&ee.getAttribute("role")==="tab")&&mr(E.getItem("active"))});let S=`${l.id}-selection`;E.subscribe(S,{any:z=>{z.node===E.getNode("active")&&mr(E.getItem("active"))}}),B.push(()=>E.unsubscribe(S,{any:!0}))}P(u,"pointermove",k=>{!$e||k.pointerId!==$e.pointerId||$e.move(k.clientX)});for(let k of["pointerup","pointercancel"])P(u,k,S=>{$e&&S.pointerId===$e.pointerId&&Ke()});for(let k of Ve)P(k,"toggle",()=>p(k,{open:k.open}));P(h,"change",()=>{E.setItem("keyboard",h?.checked??!1),p(h,{checked:h?.checked??!1});for(let[k,S]of X)S.open&&p(S.open,{tabindex:h?.checked??!1?0:-1}),i||p(S.tab,{tabindex:(h?.checked??!1)&&k===E.getItem("active")?0:-1})}),P(g,"change",()=>{if(!Bs.has(g?.value??"compact"))throw new Error("Unknown index appearance");E.setItem("appearance",g?.value??"compact"),p(g,{value:g?.value??"compact"});for(let k of g.options)p(k,{selected:k.value===(g?.value??"compact")});$s(),U()}),P(m,"change",()=>{if(!Is.has(m?.value??"light"))throw new Error("Index theme must be light or dark");E.setItem("theme",m?.value??"light"),p(m,{value:m?.value??"light"});for(let k of m.options)p(k,{selected:k.value===(m?.value??"light")});$s(),U()}),P(c,"message",k=>{if(k.data?.type===uo){for(let{frame:S}of X.values())if(S&&S.contentWindow===k.source){Ms(S),Fs();break}}}),$s(),di(),Fs(),r.onDispose(e,bt)}catch(w){throw bt(),w}return{dispose:bt}}var Rs=class{indexMount(e,{shell_id:t}){let n=this.page.src.renderer,i=n.destination.ownerDocument.getElementById(t);this.index=fo(n,n.elements.get(i).node)}};function cr(r,e){return e===2?r%4===0&&(r%100!==0||r%400===0)?29:28:[4,6,9,11].includes(e)?30:31}function Pe(r,e,t){if(![r,e,t].every(Number.isInteger)||r<1||r>9999||e<1||e>12||t<1||t>cr(r,e))throw new RangeError("Date must exist in Gregorian years 0001\u20139999.");return`${String(r).padStart(4,"0")}-${String(e).padStart(2,"0")}-${String(t).padStart(2,"0")}`}function dr(r){if(typeof r!="string"||!/^\d{4}-\d{2}-\d{2}$/.test(r))throw new RangeError("Expected a civil date in YYYY-MM-DD format.");let e=r.split("-").map(Number);return Pe(...e),e}function li(r,e,t){let n=r-1,i=365*n+Math.floor(n/4)-Math.floor(n/100)+Math.floor(n/400)+t-1;for(let s=1;s<e;s++)i+=cr(r,s);return i}function ui(r,e){let t=li(...dr(r))+e;if(!Number.isSafeInteger(t)||t<0||t>li(9999,12,31))throw new RangeError("Date offset exceeds Gregorian years 0001\u20139999.");let n=1,i=1e4;for(;i-n>1;){let a=Math.floor((n+i)/2);li(a,1,1)<=t?n=a:i=a}t-=li(n,1,1);let s=1;for(;t>=cr(n,s);)t-=cr(n,s++);return Pe(n,s,t+1)}function po(r){return ui(r,-(li(...dr(r))%7))}function Cc(r,e,t=0,n=1){let i=r*12+e-1+t,s=Math.floor(i/12),a=(i%12+12)%12+1,o=i+n-1,l=Math.floor(o/12),u=(o%12+12)%12+1;return{start:Pe(s,a,1),end:Pe(l,u,cr(l,u))}}var ho={it:{months:{gennaio:1,febbraio:2,marzo:3,aprile:4,maggio:5,giugno:6,luglio:7,agosto:8,settembre:9,ottobre:10,novembre:11,dicembre:12,gen:1,feb:2,mar:3,apr:4,mag:5,giu:6,lug:7,ago:8,set:9,ott:10,nov:11,dic:12},weekdays:{luned\u00EC:0,marted\u00EC:1,mercoled\u00EC:2,gioved\u00EC:3,venerd\u00EC:4,sabato:5,domenica:6,lun:0,mar:1,mer:2,gio:3,ven:4,sab:5,dom:6},quarters:{"1\xBA trimestre":1,"2\xBA trimestre":2,"3\xBA trimestre":3,"4\xBA trimestre":4,"1\xB0 trimestre":1,"2\xB0 trimestre":2,"3\xB0 trimestre":3,"4\xB0 trimestre":4,t1:1,t2:2,t3:3,t4:4,q1:1,q2:2,q3:3,q4:4},keywords:{today:["oggi"],yesterday:["ieri"],tomorrow:["domani"],this_week:["questa settimana","settimana"],last_week:["settimana scorsa"],next_week:["settimana prossima"],this_month:["questo mese","mese"],last_month:["mese scorso"],next_month:["mese prossimo"],last:["scorso","scorsa"],next:["prossimo","prossima"],articles:["il","lo","la"],from:["da","dal","dalla","tra","fra"],to:["a","al","alla","e"],no_period:["-","senza periodo","sempre"]},date_order:{default:"DMY"}},en:{months:{january:1,february:2,march:3,april:4,may:5,june:6,july:7,august:8,september:9,october:10,november:11,december:12,jan:1,feb:2,mar:3,apr:4,jun:6,jul:7,aug:8,sep:9,oct:10,nov:11,dec:12},weekdays:{monday:0,tuesday:1,wednesday:2,thursday:3,friday:4,saturday:5,sunday:6,mon:0,tue:1,wed:2,thu:3,fri:4,sat:5,sun:6},quarters:{"1st quarter":1,"2nd quarter":2,"3rd quarter":3,"4th quarter":4,q1:1,q2:2,q3:3,q4:4},keywords:{today:["today"],yesterday:["yesterday"],tomorrow:["tomorrow"],this_week:["this week","week"],last_week:["last week"],next_week:["next week"],this_month:["this month","month"],last_month:["last month"],next_month:["next month"],last:["last"],next:["next"],articles:["the"],from:["from","between"],to:["to","and"],no_period:["no period","always"]},date_order:{default:"MDY",GB:"DMY",AU:"DMY",IE:"DMY",NZ:"DMY",IN:"DMY"}}};function Sc(r){if(typeof r!="string")throw new RangeError("A supported locale is required.");let e=r.replaceAll("-","_"),t=e.indexOf("_"),n=(t<0?e:e.slice(0,t)).toLowerCase(),i=(t<0?"":e.slice(t+1)).toUpperCase();if(!Object.hasOwn(ho,n))throw new RangeError(`Unsupported locale: ${r}`);let s=ho[n];return{dictionary:s,phrases:o=>[...new Set([...s.keywords[o],...ho.en.keywords[o]])],order:s.date_order[i]??s.date_order.default}}var fr=/^(?:\d{4}|\d{2})$/,Nc=/^\d{1,2}$/,ci=(r,e)=>({ok:!1,error:{code:r,message:e}}),hr=(r="UNRECOGNIZED_EXPRESSION",e="Text is not a supported date expression.")=>{throw Object.assign(new SyntaxError(e),{code:r})},Bc=(r,e)=>Object.hasOwn(r,e);function pr(r,e){if(r.length===4)return Number(r);let t=e.year+e.twoDigitYearAhead-100;return t+((Number(r)-t)%100+100)%100}function Ng(r,e){if(r.includes(";")){let i=r.split(";").map(s=>s.trim());return i.length!==2?hr("INVALID_RANGE","A range must have exactly two endpoints."):{bounds:i,range:!0}}if(e.phrases("no_period").includes(r))return{bounds:["",""],range:!0};let t=e.phrases("to"),n=e.phrases("from");for(let i of t)if(r.startsWith(`${i} `))return{bounds:["",r.slice(i.length+1).trim()],range:!0};for(let i of t){let s=` ${i} `;if(!r.includes(s))continue;for(let o of n)if(r.startsWith(`${o} `)){r=r.slice(o.length+1);break}let a=r.split(s).map(o=>o.trim());return a.length!==2?hr("INVALID_RANGE","A range must have exactly two endpoints."):{bounds:a,range:!0}}for(let i of n)if(r.startsWith(`${i} `))return{bounds:[r.slice(i.length+1).trim(),""],range:!0};return{bounds:[r,r],range:!1}}function Og(r,e,t){let n=[[r,0]],i=/^(.+?)\s*([+-])\s*(\d+)$/.exec(r);i&&n.push([i[1],Number(i[2]+i[3])]);let s={today:0,yesterday:-1,tomorrow:1,this_week:0,last_week:-1,next_week:1,this_month:0,last_month:-1,next_month:1};for(let[a,o]of n)for(let[l,u]of Object.entries(s))if(e.phrases(l).includes(a)){if(l.endsWith("_week"))return ui(po(e.workdate),(u+o)*7+(t?6:0));if(l.endsWith("_month")){let c=Cc(e.year,e.month,u+o);return t?c.end:c.start}return ui(e.workdate,u+o)}return null}function Ig(r,e,t){let n=Object.entries(e.dictionary.quarters).sort((i,s)=>s[0].length-i[0].length);for(let[i,s]of n){let a;if(r===i)a=null;else if(r.startsWith(i)&&fr.test(r.slice(i.length).trim()))a=pr(r.slice(i.length).trim(),e);else if(r.endsWith(i)&&fr.test(r.slice(0,-i.length).trim()))a=pr(r.slice(0,-i.length).trim(),e);else continue;return{year:a,month:t?s*3:s*3-2}}return null}function Oc(r,e){if(Bc(e.months,r))return e.months[r];let t=/^m(\d{1,2})$/.exec(r);return t&&Number(t[1])>=1&&Number(t[1])<=12?Number(t[1]):null}function Bg(r,e){let t=r.split(/\s+/),n=t.map((u,c)=>Oc(u,e.dictionary)?c:-1).filter(u=>u>=0);if(!n.length)return null;if(n.length!==1)return hr();let i=n[0],s=Oc(t[i],e.dictionary),a=t.slice(0,i),o=t.slice(i+1),l=[...a,...o];if(l.length===1&&e.phrases("last").includes(l[0]))return{year:e.year-(s>e.month?1:0),month:s};if(l.length===1&&e.phrases("next").includes(l[0]))return{year:e.year+(s<e.month?1:0),month:s};if(!l.length)return{year:null,month:s};if(!a.length&&o.length===1&&fr.test(o[0]))return{year:pr(o[0],e),month:s};if(a.length===1&&Nc.test(a[0])){if(!o.length)return Pe(e.year,s,Number(a[0]));if(o.length===1&&fr.test(o[0]))return Pe(pr(o[0],e),s,Number(a[0]))}return!a.length&&o.length===2&&Nc.test(o[0])&&fr.test(o[1])?Pe(pr(o[1],e),s,Number(o[0])):hr()}function Rg(r,e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(r);if(t)return Pe(...t.slice(1).map(Number));let n=/^(\d{1,4})[/\-. ]+(\d{1,4})[/\-. ]+(\d{1,4})$/.exec(r),i={};if(n)e.order.split("").forEach((o,l)=>{i[o]=n[l+1]});else if(/^(?:\d{6}|\d{8})$/.test(r)){let o=r.length===8?4:2;for(let l of e.order){let u=l==="Y"?o:2;i[l]=r.slice(0,u),r=r.slice(u)}}else return null;if(!fr.test(i.Y)||i.D.length>2||i.M.length>2)return hr();let s=Number(i.D),a=Number(i.M);return n&&a>12&&s<=12&&([s,a]=[a,s]),Pe(pr(i.Y,e),a,s)}function Ic(r,e,t){if(!r)return null;let n=e.phrases("articles");if(r=r.split(/\s+/).filter(s=>!n.includes(s)).join(" "),!r)return hr();if(fr.test(r))return Pe(pr(r,e),t?12:1,t?31:1);let i=Og(r,e,t)??Ig(r,e,t)??Bg(r,e);return i!==null?i:Bc(e.dictionary.weekdays,r)?ui(po(e.workdate),e.dictionary.weekdays[r]):Rg(r,e)??hr()}function Mg(r,e,t){if(r===null||typeof r=="string")return r;let n=r.year??t.year,i=typeof e=="string"?dr(e)[0]:e?.year,s=typeof e=="string"?dr(e)[1]:e?.month;return i&&(n>i&&(n=i),n===i&&r.month>s&&n--),Pe(n,r.month,1)}function $g(r,e,t){if(r===null||typeof r=="string")return r;let n=r.year??t.year;if(e!==null){let[i,s]=dr(e);n<i&&(n=i),n===i&&s>r.month&&n++}return Pe(n,r.month,cr(n,r.month))}function Fg(r,e={}){if(!e||typeof e!="object"||Array.isArray(e))return ci("INVALID_CONTEXT","Options must provide a civil workdate and supported locale.");let t;try{let{locale:n="it-IT",workdate:i,twoDigitYearAhead:s=20}=e,[a,o]=dr(i);if(!Number.isInteger(s)||s<0||s>99)throw new RangeError("twoDigitYearAhead must be an integer from 0 to 99.");t={...Sc(n),workdate:i,year:a,month:o,twoDigitYearAhead:s}}catch(n){return ci("INVALID_CONTEXT",n.message)}if(typeof r!="string")return ci("INVALID_INPUT","Expression must be a string.");try{let n=r.toLowerCase().trim().replaceAll(",",""),{bounds:i,range:s}=Ng(n,t),a=Ic(i[1],t,!0),o=Ic(i[0],t,!1),l=Mg(o,a,t),u=$g(a,l,t);return!s&&typeof o=="string"&&l===u?{ok:!0,kind:"date",date:l}:{ok:!0,kind:"period",start:l,end:u}}catch(n){if(n instanceof RangeError)return ci("INVALID_DATE",n.message);if(n instanceof SyntaxError)return ci(n.code,n.message);throw n}}export{V as Bag,Ge as BagNode,ni as DomHandler,Ns as Exposed,ai as Gramlot,Je as GramlotBuilder,or as GramlotHtmlRenderer,Qn as GramlotRenderer,Wn as GramlotSvgRenderer,Le as Handler,en as HttpTransport,ii as InOut,Rs as IndexLogic,Os as IndexPage,oi as Page,ao as PageBootstrap,Yn as References,ti as RpcError,ri as RpcHandler,wt as ServerAdapter,ei as SourceHandler,si as UtilitiesHandler,It as createDecimal,fo as mountIndexPage,Fg as parseDateExpression};
|
|
447
|
+
`};var uo="index:theme-ready",co="index:theme-set",Is=new Set(["light","dark"]),Bs=new Set(["base","compact","mimi","joanna"]);function fo(r,e,t=()=>{},n=()=>{},{containerLayout:i=!1,state:s=null,createEntry:a=null,onLoad:o=()=>{}}={}){if(a&&!i)throw new TypeError("Deferred index entries require containerLayout");let l=r.records.get(e).element,u=l.ownerDocument,c=u.defaultView,d=w=>u.getElementById(w),f=w=>r.elements.get(w).node,p=(w,j)=>f(w).setAttr(j),h=d("keyboard-navigation"),m=d("index-theme"),g=d("index-appearance"),b=d("index-sidebar"),y=d("index-sidebar-divider"),v=d("index-navigation-toggle"),x=d("index-code-toggle"),$=d("index-code"),D=d("index-code-divider"),J=`gramlot.${l.id}.preferences:${c.location.pathname}`,G={};try{let w=JSON.parse(c.localStorage.getItem(J));w!==null&&typeof w=="object"&&!Array.isArray(w)&&(G=w)}catch(w){if(w.name!=="SyntaxError"&&w.name!=="SecurityError")throw w}let re=(w,j,k)=>{if(!(!w||!k.has(j))){p(w,{value:j});for(let S of w.options)p(S,{selected:S.value===j})}};re(m,G.theme,Is),re(g,G.appearance,Bs);let Ve=[...l.querySelectorAll(".index-sidebar details")],ae=e.builder.data.constructor,E=s??new ae,he=new ae;E.setItem("opened",he),E.setItem("keyboard",h?.checked??!1),E.setItem("theme",m?.value??"light"),E.setItem("appearance",g?.value??"compact"),E.setItem("navigationVisible",G.navigationVisible!==!1),E.setItem("codeVisible",G.codeVisible!==!1);let U=()=>{try{c.localStorage.setItem(J,JSON.stringify({theme:E.getItem("theme"),appearance:E.getItem("appearance"),sidebarWidth:E.getItem("preferredSidebarWidth"),codeWidth:E.getItem("preferredCodeWidth"),navigationVisible:E.getItem("navigationVisible"),codeVisible:E.getItem("codeVisible")}))}catch(w){if(w.name!=="SecurityError"&&w.name!=="QuotaExceededError")throw w}},X=new Map,B=[],Pt=e.builder.wrapSource(e.value).style(lo[g?.value??"compact"]),$e=null,Ne=!1,ut=null,q=u.documentElement.getAttribute("data-theme"),P=(w,j,k)=>{w&&(w.addEventListener(j,k),B.push(()=>w.removeEventListener(j,k)))},Ke=()=>{if(!$e)return;let{handle:w,pointerId:j}=$e;$e=null,Ne||p(l,{data_resizing:null}),w.hasPointerCapture(j)&&w.releasePointerCapture(j)},bt=()=>{if(!Ne){Ne=!0,ut=null,Ke();for(let w of B.reverse())w();Pt.parentBag&&Pt.parentBag.popNode(Pt.label),q==null?u.documentElement.removeAttribute("data-theme"):u.documentElement.setAttribute("data-theme",q)}},Ms=w=>w.contentWindow.postMessage({type:co,theme:E.getItem("theme"),appearance:E.getItem("appearance")},"*"),$s=()=>{u.documentElement.setAttribute("data-theme",E.getItem("theme")),Pt.setValue(lo[E.getItem("appearance")]);for(let{frame:w}of X.values())w&&Ms(w)},Fs=()=>t(X,E.getItem("active")),di=()=>{if(v){let w=E.getItem("navigationVisible");p(b,i?{drawer:w?!0:"close"}:{hidden:!w}),i||p(y,{hidden:!w}),p(v,{aria_expanded:String(w)}),p(l,{data_navigation_hidden:String(!w)})}if($){let w=!!X.get(E.getItem("active"))?.code,j=w&&E.getItem("codeVisible");p($,i?{hidden:!w,drawer:j?!0:"close"}:{hidden:!j}),i||p(D,{hidden:!j}),p(x,{disabled:!w,aria_expanded:String(j)}),p(l,{data_code_visible:String(j)})}},mo=w=>{w.panel=d(`panel-${w.key}`),w.tab=i?w.panel:d(`tab-${w.key}`),w.code=d(`codepane-${w.key}`),w.key!=="intro"&&(n(w,{byId:d,node:f,set:p,listen:P}),w.frame=d(`frame-${w.key}`),w.frame&&P(w.frame,"load",()=>Ms(w.frame)))},go=w=>{he.getItem(w.key)||(he.setItem(w.key,!0),p(i?w.panel:w.tab,{hidden:!1}),w.frame&&p(w.frame,{src:w.open.getAttribute("href")}))},Ls=!1;function mr(w){if(Ls||Ne)return;let j=X.get(w);if(j){if(E.setItem("requested",w),!j.panel){o(w,"loading"),j.loading||(j.loading=Promise.resolve().then(()=>{if(!Ne)return a(j)}).then(()=>{Ne||(mo(j),go(j),E.getItem("requested")===w&&(o(w,"ready"),mr(w)))}).catch(k=>{!Ne&&E.getItem("requested")===w&&o(w,"error",k)}).finally(()=>{j.loading=null}));return}o(w,"ready"),Ls=!0;try{let k=X.get(w);go(k),k.family&&p(k.family,{open:!0});for(let[S,z]of X){let ee=S===w;i||(p(z.tab,{aria_selected:String(ee),tabindex:ee&&E.getItem("keyboard")?0:-1}),p(z.panel,{hidden:!ee})),z.code&&p(z.code,{hidden:!ee}),z.open&&p(z.open,{aria_current:ee?"page":null})}E.getItem("active")!==w&&E.setItem("active",w),di(),Fs()}finally{Ls=!1}}}let bo=()=>Math.max(120,Math.min(460,Math.floor(c.innerWidth*.6))),_o=()=>p(l,{style:`--sidebar-width: ${E.getItem("sidebarWidth")}px; --code-width: ${E.getItem("codeWidth")??420}px`}),fi=(w,j=!1)=>{let k=bo(),S=Math.max(120,Math.min(k,w));E.setItem("sidebarWidth",S),_o(),p(y,{aria_valuenow:S,aria_valuemax:k}),j&&(E.setItem("preferredSidebarWidth",S),U())},wo=()=>Math.max(200,Math.floor(c.innerWidth*.6)),pi=(w,j=!1)=>{let k=wo(),S=Math.max(200,Math.min(k,w));E.setItem("codeWidth",S),_o(),p(D,{aria_valuenow:S,aria_valuemax:k}),j&&(E.setItem("preferredCodeWidth",S),U())},yo=(w,j,k)=>{j.button===0&&(Ke(),w.setPointerCapture(j.pointerId),$e={handle:w,pointerId:j.pointerId,move:k},p(l,{data_resizing:"true"}),j.preventDefault())};try{let w=d("index-install-button");if(w&&(P(c,"beforeinstallprompt",k=>{k.preventDefault(),ut=k,p(w,{hidden:!1,disabled:!1})}),P(c,"appinstalled",()=>{ut=null,p(w,{hidden:!0}),f(d("index-install-status")).setValue("App installed.")}),P(w,"click",async()=>{if(!ut)return;let k=ut;ut=null,p(w,{disabled:!0});try{await k.prompt();let{outcome:S}=await k.userChoice;Ne||f(d("index-install-status")).setValue(S==="accepted"?"Installation accepted.":"Installation cancelled. You can also use the browser menu.")}catch(S){Ne||f(d("index-install-status")).setValue(`Installation failed: ${S.message}`)}finally{Ne||p(w,{hidden:!0})}})),p(l,{data_resizing:null}),i){let k=r.binding.gramlot;for(let[ee,be,Ps]of[[b,"navigationVisible","sidebarWidth"],[$,"codeVisible","codeWidth"]]){let gr=f(ee),br=G[Ps];typeof br=="number"&&Number.isFinite(br)&&br>0&&p(ee,{width:`${br}px`});let Rc=k.subscribe(`${gr.getAttr("nodeId")}_closable_change`,({open:Qr})=>{gr.getAttr("hidden")===!0||gr.getAttr("drawer")===!1||(E.setItem(be,Qr),p(ee,{drawer:Qr?!0:"close"}),p(be==="navigationVisible"?v:x,{aria_expanded:String(Qr)}),p(l,{[be==="navigationVisible"?"data_navigation_hidden":"data_code_visible"]:String(be==="navigationVisible"?!Qr:Qr)}),U())});B.push(()=>k.unsubscribe(Rc))}let S=l.querySelector("[data-index-regions]"),z=k.subscribe(`${f(S).getAttr("nodeId")}_splitter_resize`,({region:ee,size:be})=>{p(ee==="left"?b:$,{width:be}),E.setItem(ee==="left"?"preferredSidebarWidth":"preferredCodeWidth",Number.parseFloat(be)),U()});B.push(()=>k.unsubscribe(z)),E.setItem("preferredSidebarWidth",G.sidebarWidth),E.setItem("preferredCodeWidth",G.codeWidth)}else{let k=G.sidebarWidth,S=typeof k=="number"&&Number.isFinite(k)&&k>=120&&k<=460?k:b.getBoundingClientRect().width||Number(y.getAttribute("aria-valuenow"));E.setItem("preferredSidebarWidth",S),fi(S)}if(P(v,"click",()=>{E.setItem("navigationVisible",!E.getItem("navigationVisible")),di(),U()}),P(x,"click",()=>{E.setItem("codeVisible",!E.getItem("codeVisible")),di(),U()}),!i&&D){let k=G.codeWidth,S=typeof k=="number"&&Number.isFinite(k)&&k>=200?k:420;E.setItem("preferredCodeWidth",S),pi(S),P(D,"keydown",z=>{let ee=E.getItem("codeWidth"),be=z.key==="ArrowLeft"?ee+10:z.key==="ArrowRight"?ee-10:z.key==="Home"?200:z.key==="End"?wo():null;be!=null&&(z.preventDefault(),pi(be,!0))}),P(D,"pointerdown",z=>yo(D,z,ee=>pi(Math.round(l.getBoundingClientRect().right-ee),!0))),P(D,"lostpointercapture",()=>{$e?.handle===D&&Ke()}),P(c,"resize",()=>pi(E.getItem("preferredCodeWidth")))}i||(P(y,"keydown",k=>{let S=E.getItem("sidebarWidth"),z=k.key==="ArrowLeft"?S-10:k.key==="ArrowRight"?S+10:k.key==="Home"?120:k.key==="End"?bo():null;z!=null&&(k.preventDefault(),fi(z,!0))}),P(y,"pointerdown",k=>yo(y,k,S=>fi(Math.round(S-l.getBoundingClientRect().left),!0))),P(y,"lostpointercapture",()=>{$e?.handle===y&&Ke()}),P(c,"resize",()=>fi(E.getItem("preferredSidebarWidth"))));let j=a?[d("panel-intro"),...l.querySelectorAll('.index-sidebar a[id^="open-"]')]:i?d("index-pages").children:l.querySelectorAll(".index-tabs button");for(let k of j){let S=k.id.slice(a&&k.id.startsWith("open-")?5:i?6:4),z={key:S,tab:k,panel:d(`panel-${S}`),code:d(`codepane-${S}`),open:S==="intro"?null:d(`open-${S}`)};X.set(S,z),z.panel&&(i?f(z.panel).getAttr("hidden")!==!0:!k.hidden)&&he.setItem(S,!0),!i&&k.getAttribute("aria-selected")==="true"&&E.setItem("active",S),i||P(k,"click",()=>mr(S)),z.open&&P(z.open,"click",ee=>{ee.preventDefault(),mr(S)}),i||P(k,"keydown",ee=>{if(!E.getItem("keyboard")||!["ArrowLeft","ArrowRight","Home","End"].includes(ee.key))return;let be=[...X.keys()].filter(br=>he.getItem(br)),Ps=be.indexOf(S),gr=ee.key==="Home"?0:ee.key==="End"?be.length-1:(Ps+(ee.key==="ArrowRight"?1:-1)+be.length)%be.length;ee.preventDefault(),mr(be[gr]),X.get(be[gr]).tab.focus()}),S!=="intro"&&(z.family=z.open.closest("details"),z.panel&&mo(z))}if(i){let k=d("index-pages");P(k,"click",z=>{z.target===k&&z.composedPath().some(ee=>ee instanceof c.Element&&ee.getAttribute("role")==="tab")&&mr(E.getItem("active"))});let S=`${l.id}-selection`;E.subscribe(S,{any:z=>{z.node===E.getNode("active")&&mr(E.getItem("active"))}}),B.push(()=>E.unsubscribe(S,{any:!0}))}P(u,"pointermove",k=>{!$e||k.pointerId!==$e.pointerId||$e.move(k.clientX)});for(let k of["pointerup","pointercancel"])P(u,k,S=>{$e&&S.pointerId===$e.pointerId&&Ke()});for(let k of Ve)P(k,"toggle",()=>p(k,{open:k.open}));P(h,"change",()=>{E.setItem("keyboard",h?.checked??!1),p(h,{checked:h?.checked??!1});for(let[k,S]of X)S.open&&p(S.open,{tabindex:h?.checked??!1?0:-1}),i||p(S.tab,{tabindex:(h?.checked??!1)&&k===E.getItem("active")?0:-1})}),P(g,"change",()=>{if(!Bs.has(g?.value??"compact"))throw new Error("Unknown index appearance");E.setItem("appearance",g?.value??"compact"),p(g,{value:g?.value??"compact"});for(let k of g.options)p(k,{selected:k.value===(g?.value??"compact")});$s(),U()}),P(m,"change",()=>{if(!Is.has(m?.value??"light"))throw new Error("Index theme must be light or dark");E.setItem("theme",m?.value??"light"),p(m,{value:m?.value??"light"});for(let k of m.options)p(k,{selected:k.value===(m?.value??"light")});$s(),U()}),P(c,"message",k=>{if(k.data?.type===uo){for(let{frame:S}of X.values())if(S&&S.contentWindow===k.source){Ms(S),Fs();break}}}),$s(),di(),Fs(),r.onDispose(e,bt)}catch(w){throw bt(),w}return{dispose:bt}}var Rs=class{indexMount(e,{shell_id:t}){let n=this.page.src.renderer,i=n.destination.ownerDocument.getElementById(t);this.index=fo(n,n.elements.get(i).node)}};function cr(r,e){return e===2?r%4===0&&(r%100!==0||r%400===0)?29:28:[4,6,9,11].includes(e)?30:31}function Pe(r,e,t){if(![r,e,t].every(Number.isInteger)||r<1||r>9999||e<1||e>12||t<1||t>cr(r,e))throw new RangeError("Date must exist in Gregorian years 0001\u20139999.");return`${String(r).padStart(4,"0")}-${String(e).padStart(2,"0")}-${String(t).padStart(2,"0")}`}function dr(r){if(typeof r!="string"||!/^\d{4}-\d{2}-\d{2}$/.test(r))throw new RangeError("Expected a civil date in YYYY-MM-DD format.");let e=r.split("-").map(Number);return Pe(...e),e}function li(r,e,t){let n=r-1,i=365*n+Math.floor(n/4)-Math.floor(n/100)+Math.floor(n/400)+t-1;for(let s=1;s<e;s++)i+=cr(r,s);return i}function ui(r,e){let t=li(...dr(r))+e;if(!Number.isSafeInteger(t)||t<0||t>li(9999,12,31))throw new RangeError("Date offset exceeds Gregorian years 0001\u20139999.");let n=1,i=1e4;for(;i-n>1;){let a=Math.floor((n+i)/2);li(a,1,1)<=t?n=a:i=a}t-=li(n,1,1);let s=1;for(;t>=cr(n,s);)t-=cr(n,s++);return Pe(n,s,t+1)}function po(r){return ui(r,-(li(...dr(r))%7))}function Cc(r,e,t=0,n=1){let i=r*12+e-1+t,s=Math.floor(i/12),a=(i%12+12)%12+1,o=i+n-1,l=Math.floor(o/12),u=(o%12+12)%12+1;return{start:Pe(s,a,1),end:Pe(l,u,cr(l,u))}}var ho={it:{months:{gennaio:1,febbraio:2,marzo:3,aprile:4,maggio:5,giugno:6,luglio:7,agosto:8,settembre:9,ottobre:10,novembre:11,dicembre:12,gen:1,feb:2,mar:3,apr:4,mag:5,giu:6,lug:7,ago:8,set:9,ott:10,nov:11,dic:12},weekdays:{luned\u00EC:0,marted\u00EC:1,mercoled\u00EC:2,gioved\u00EC:3,venerd\u00EC:4,sabato:5,domenica:6,lun:0,mar:1,mer:2,gio:3,ven:4,sab:5,dom:6},quarters:{"1\xBA trimestre":1,"2\xBA trimestre":2,"3\xBA trimestre":3,"4\xBA trimestre":4,"1\xB0 trimestre":1,"2\xB0 trimestre":2,"3\xB0 trimestre":3,"4\xB0 trimestre":4,t1:1,t2:2,t3:3,t4:4,q1:1,q2:2,q3:3,q4:4},keywords:{today:["oggi"],yesterday:["ieri"],tomorrow:["domani"],this_week:["questa settimana","settimana"],last_week:["settimana scorsa"],next_week:["settimana prossima"],this_month:["questo mese","mese"],last_month:["mese scorso"],next_month:["mese prossimo"],last:["scorso","scorsa"],next:["prossimo","prossima"],articles:["il","lo","la"],from:["da","dal","dalla","tra","fra"],to:["a","al","alla","e"],no_period:["-","senza periodo","sempre"]},date_order:{default:"DMY"}},en:{months:{january:1,february:2,march:3,april:4,may:5,june:6,july:7,august:8,september:9,october:10,november:11,december:12,jan:1,feb:2,mar:3,apr:4,jun:6,jul:7,aug:8,sep:9,oct:10,nov:11,dec:12},weekdays:{monday:0,tuesday:1,wednesday:2,thursday:3,friday:4,saturday:5,sunday:6,mon:0,tue:1,wed:2,thu:3,fri:4,sat:5,sun:6},quarters:{"1st quarter":1,"2nd quarter":2,"3rd quarter":3,"4th quarter":4,q1:1,q2:2,q3:3,q4:4},keywords:{today:["today"],yesterday:["yesterday"],tomorrow:["tomorrow"],this_week:["this week","week"],last_week:["last week"],next_week:["next week"],this_month:["this month","month"],last_month:["last month"],next_month:["next month"],last:["last"],next:["next"],articles:["the"],from:["from","between"],to:["to","and"],no_period:["no period","always"]},date_order:{default:"MDY",GB:"DMY",AU:"DMY",IE:"DMY",NZ:"DMY",IN:"DMY"}}};function Sc(r){if(typeof r!="string")throw new RangeError("A supported locale is required.");let e=r.replaceAll("-","_"),t=e.indexOf("_"),n=(t<0?e:e.slice(0,t)).toLowerCase(),i=(t<0?"":e.slice(t+1)).toUpperCase();if(!Object.hasOwn(ho,n))throw new RangeError(`Unsupported locale: ${r}`);let s=ho[n];return{dictionary:s,phrases:o=>[...new Set([...s.keywords[o],...ho.en.keywords[o]])],order:s.date_order[i]??s.date_order.default}}var fr=/^(?:\d{4}|\d{2})$/,Nc=/^\d{1,2}$/,ci=(r,e)=>({ok:!1,error:{code:r,message:e}}),hr=(r="UNRECOGNIZED_EXPRESSION",e="Text is not a supported date expression.")=>{throw Object.assign(new SyntaxError(e),{code:r})},Bc=(r,e)=>Object.hasOwn(r,e);function pr(r,e){if(r.length===4)return Number(r);let t=e.year+e.twoDigitYearAhead-100;return t+((Number(r)-t)%100+100)%100}function Ng(r,e){if(r.includes(";")){let i=r.split(";").map(s=>s.trim());return i.length!==2?hr("INVALID_RANGE","A range must have exactly two endpoints."):{bounds:i,range:!0}}if(e.phrases("no_period").includes(r))return{bounds:["",""],range:!0};let t=e.phrases("to"),n=e.phrases("from");for(let i of t)if(r.startsWith(`${i} `))return{bounds:["",r.slice(i.length+1).trim()],range:!0};for(let i of t){let s=` ${i} `;if(!r.includes(s))continue;for(let o of n)if(r.startsWith(`${o} `)){r=r.slice(o.length+1);break}let a=r.split(s).map(o=>o.trim());return a.length!==2?hr("INVALID_RANGE","A range must have exactly two endpoints."):{bounds:a,range:!0}}for(let i of n)if(r.startsWith(`${i} `))return{bounds:[r.slice(i.length+1).trim(),""],range:!0};return{bounds:[r,r],range:!1}}function Og(r,e,t){let n=[[r,0]],i=/^(.+?)\s*([+-])\s*(\d+)$/.exec(r);i&&n.push([i[1],Number(i[2]+i[3])]);let s={today:0,yesterday:-1,tomorrow:1,this_week:0,last_week:-1,next_week:1,this_month:0,last_month:-1,next_month:1};for(let[a,o]of n)for(let[l,u]of Object.entries(s))if(e.phrases(l).includes(a)){if(l.endsWith("_week"))return ui(po(e.workdate),(u+o)*7+(t?6:0));if(l.endsWith("_month")){let c=Cc(e.year,e.month,u+o);return t?c.end:c.start}return ui(e.workdate,u+o)}return null}function Ig(r,e,t){let n=Object.entries(e.dictionary.quarters).sort((i,s)=>s[0].length-i[0].length);for(let[i,s]of n){let a;if(r===i)a=null;else if(r.startsWith(i)&&fr.test(r.slice(i.length).trim()))a=pr(r.slice(i.length).trim(),e);else if(r.endsWith(i)&&fr.test(r.slice(0,-i.length).trim()))a=pr(r.slice(0,-i.length).trim(),e);else continue;return{year:a,month:t?s*3:s*3-2}}return null}function Oc(r,e){if(Bc(e.months,r))return e.months[r];let t=/^m(\d{1,2})$/.exec(r);return t&&Number(t[1])>=1&&Number(t[1])<=12?Number(t[1]):null}function Bg(r,e){let t=r.split(/\s+/),n=t.map((u,c)=>Oc(u,e.dictionary)?c:-1).filter(u=>u>=0);if(!n.length)return null;if(n.length!==1)return hr();let i=n[0],s=Oc(t[i],e.dictionary),a=t.slice(0,i),o=t.slice(i+1),l=[...a,...o];if(l.length===1&&e.phrases("last").includes(l[0]))return{year:e.year-(s>e.month?1:0),month:s};if(l.length===1&&e.phrases("next").includes(l[0]))return{year:e.year+(s<e.month?1:0),month:s};if(!l.length)return{year:null,month:s};if(!a.length&&o.length===1&&fr.test(o[0]))return{year:pr(o[0],e),month:s};if(a.length===1&&Nc.test(a[0])){if(!o.length)return Pe(e.year,s,Number(a[0]));if(o.length===1&&fr.test(o[0]))return Pe(pr(o[0],e),s,Number(a[0]))}return!a.length&&o.length===2&&Nc.test(o[0])&&fr.test(o[1])?Pe(pr(o[1],e),s,Number(o[0])):hr()}function Rg(r,e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(r);if(t)return Pe(...t.slice(1).map(Number));let n=/^(\d{1,4})[/\-. ]+(\d{1,4})[/\-. ]+(\d{1,4})$/.exec(r),i={};if(n)e.order.split("").forEach((o,l)=>{i[o]=n[l+1]});else if(/^(?:\d{6}|\d{8})$/.test(r)){let o=r.length===8?4:2;for(let l of e.order){let u=l==="Y"?o:2;i[l]=r.slice(0,u),r=r.slice(u)}}else return null;if(!fr.test(i.Y)||i.D.length>2||i.M.length>2)return hr();let s=Number(i.D),a=Number(i.M);return n&&a>12&&s<=12&&([s,a]=[a,s]),Pe(pr(i.Y,e),a,s)}function Ic(r,e,t){if(!r)return null;let n=e.phrases("articles");if(r=r.split(/\s+/).filter(s=>!n.includes(s)).join(" "),!r)return hr();if(fr.test(r))return Pe(pr(r,e),t?12:1,t?31:1);let i=Og(r,e,t)??Ig(r,e,t)??Bg(r,e);return i!==null?i:Bc(e.dictionary.weekdays,r)?ui(po(e.workdate),e.dictionary.weekdays[r]):Rg(r,e)??hr()}function Mg(r,e,t){if(r===null||typeof r=="string")return r;let n=r.year??t.year,i=typeof e=="string"?dr(e)[0]:e?.year,s=typeof e=="string"?dr(e)[1]:e?.month;return i&&(n>i&&(n=i),n===i&&r.month>s&&n--),Pe(n,r.month,1)}function $g(r,e,t){if(r===null||typeof r=="string")return r;let n=r.year??t.year;if(e!==null){let[i,s]=dr(e);n<i&&(n=i),n===i&&s>r.month&&n++}return Pe(n,r.month,cr(n,r.month))}function Fg(r,e={}){if(!e||typeof e!="object"||Array.isArray(e))return ci("INVALID_CONTEXT","Options must provide a civil workdate and supported locale.");let t;try{let{locale:n="it-IT",workdate:i,twoDigitYearAhead:s=20}=e,[a,o]=dr(i);if(!Number.isInteger(s)||s<0||s>99)throw new RangeError("twoDigitYearAhead must be an integer from 0 to 99.");t={...Sc(n),workdate:i,year:a,month:o,twoDigitYearAhead:s}}catch(n){return ci("INVALID_CONTEXT",n.message)}if(typeof r!="string")return ci("INVALID_INPUT","Expression must be a string.");try{let n=r.toLowerCase().trim().replaceAll(",",""),{bounds:i,range:s}=Ng(n,t),a=Ic(i[1],t,!0),o=Ic(i[0],t,!1),l=Mg(o,a,t),u=$g(a,l,t);return!s&&typeof o=="string"&&l===u?{ok:!0,kind:"date",date:l}:{ok:!0,kind:"period",start:l,end:u}}catch(n){if(n instanceof RangeError)return ci("INVALID_DATE",n.message);if(n instanceof SyntaxError)return ci(n.code,n.message);throw n}}export{V as Bag,Ge as BagNode,ni as DomHandler,Ns as Exposed,ai as Gramlot,Je as GramlotBuilder,or as GramlotHtmlRenderer,Qn as GramlotRenderer,Wn as GramlotSvgRenderer,Le as Handler,en as HttpTransport,ii as InOut,Rs as IndexLogic,Os as IndexPage,oi as Page,ao as PageBootstrap,Yn as References,ti as RpcError,ri as RpcHandler,wt as ServerAdapter,ei as SourceHandler,si as UtilitiesHandler,It as createDecimal,fo as mountIndexPage,Fg as parseDateExpression};
|
|
448
448
|
/*! Bundled license information:
|
|
449
449
|
|
|
450
450
|
decimal.js/decimal.mjs:
|