@kayr/umbika-web-renderer 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +46 -2
- package/THIRD_PARTY_LICENSES.txt +20 -0
- package/dist/browser/umbika.min.css +23 -0
- package/dist/browser/umbika.min.d.mts +437 -0
- package/dist/browser/umbika.min.d.ts +437 -0
- package/dist/browser/umbika.min.js +60 -0
- package/dist/browser/umbika.min.mjs +60 -0
- package/dist/casconda.d.ts +2 -0
- package/dist/casconda.d.ts.map +1 -0
- package/dist/contracts.d.ts +165 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/dom-identity.d.ts +17 -0
- package/dist/dom-identity.d.ts.map +1 -0
- package/dist/field-presentation.d.ts +26 -0
- package/dist/field-presentation.d.ts.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/layout.d.ts +25 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/mount.d.ts +14 -0
- package/dist/mount.d.ts.map +1 -0
- package/dist/render-nodes.d.ts +18 -0
- package/dist/render-nodes.d.ts.map +1 -0
- package/dist/renderers/multi-select.d.ts +18 -0
- package/dist/renderers/multi-select.d.ts.map +1 -0
- package/dist/renderers/object.d.ts +6 -0
- package/dist/renderers/object.d.ts.map +1 -0
- package/dist/renderers/output.d.ts +6 -0
- package/dist/renderers/output.d.ts.map +1 -0
- package/dist/renderers/select.d.ts +6 -0
- package/dist/renderers/select.d.ts.map +1 -0
- package/dist/renderers/table.d.ts +6 -0
- package/dist/renderers/table.d.ts.map +1 -0
- package/dist/renderers/text.d.ts +8 -0
- package/dist/renderers/text.d.ts.map +1 -0
- package/dist/row-details.d.ts +89 -0
- package/dist/row-details.d.ts.map +1 -0
- package/dist/standalone/contracts.d.ts +77 -0
- package/dist/standalone/contracts.d.ts.map +1 -0
- package/dist/standalone/index.d.ts +7 -0
- package/dist/standalone/index.d.ts.map +1 -0
- package/dist/standalone/mount.d.ts +9 -0
- package/dist/standalone/mount.d.ts.map +1 -0
- package/dist/summary.d.ts +29 -0
- package/dist/summary.d.ts.map +1 -0
- package/dist/tags.d.ts +32 -0
- package/dist/tags.d.ts.map +1 -0
- package/package.json +78 -4
- package/src/casconda.js +10 -0
- package/src/contracts.js +79 -0
- package/src/dom-identity.js +31 -0
- package/src/field-presentation.js +71 -0
- package/src/index.js +9 -0
- package/src/layout.js +176 -0
- package/src/mount.js +569 -0
- package/src/render-nodes.js +77 -0
- package/src/renderers/multi-select.js +211 -0
- package/src/renderers/object.js +43 -0
- package/src/renderers/output.js +87 -0
- package/src/renderers/select.js +104 -0
- package/src/renderers/table.js +344 -0
- package/src/renderers/text.js +82 -0
- package/src/row-details.js +305 -0
- package/src/standalone/contracts.js +22 -0
- package/src/standalone/index.js +5 -0
- package/src/standalone/mount.js +128 -0
- package/src/summary.js +135 -0
- package/src/tags.js +69 -0
- package/styles/base.css +432 -0
- package/styles/standalone.css +2 -0
- package/styles/themes/default.css +99 -0
- package/vendor/LICENSE +21 -0
- package/vendor/README.md +33 -0
- package/vendor/casconda.min.d.mts +340 -0
- package/vendor/casconda.min.d.ts +340 -0
- package/vendor/casconda.min.mjs +1 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*! Umbika and Casconda
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2026 Kayr
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
|
|
24
|
+
Copyright (c) 2013 Stephen Oney, https://ericsmekens.github.io/jsep/
|
|
25
|
+
|
|
26
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
27
|
+
a copy of this software and associated documentation files (the
|
|
28
|
+
"Software"), to deal in the Software without restriction, including
|
|
29
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
30
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
31
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
32
|
+
the following conditions:
|
|
33
|
+
|
|
34
|
+
The above copyright notice and this permission notice shall be
|
|
35
|
+
included in all copies or substantial portions of the Software.
|
|
36
|
+
|
|
37
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
38
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
39
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
40
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
41
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
42
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
43
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
44
|
+
*/
|
|
45
|
+
"use strict";var Umbika=(()=>{var nt=Object.defineProperty;var $n=Object.getOwnPropertyDescriptor;var Cn=Object.getOwnPropertyNames;var Sn=Object.prototype.hasOwnProperty;var jn=(e,t)=>{for(var r in t)nt(e,r,{get:t[r],enumerable:!0})},An=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Cn(t))!Sn.call(e,i)&&i!==r&&nt(e,i,{get:()=>t[i],enumerable:!(n=$n(t,i))||n.enumerable});return e};var Tn=e=>An(nt({},"__esModule",{value:!0}),e);var wo={};jn(wo,{FormLanguageError:()=>W,mount:()=>kn});function ie(e,t,r,n){return Dn(n),it(e,t,r,n,[])}function it(e,t,r,n,i){let o=[...i,...n],[a,...s]=n,l=e.find(f=>f.id===a);if(!l||!a)return ye(o);let c=B(i,a);switch(l.type){case"object":{let f=t[l.id];return Pn(f)?s.length===0?{kind:"object",node:l,path:c,values:f}:it(l.children,f,r,s,c):ye(o)}case"table":{let f=t[l.id];if(!Array.isArray(f))return ye(o);if(s.length===0)return{kind:"table",node:l,path:c,rows:f};let[p,...g]=s,E=f.findIndex(y=>r.get(y)===p),v=f[E];if(E===-1||!v||!p)return ye(o);let $=B(c,p);return g.length===0?{kind:"row",node:l,path:$,rows:f,index:E,row:v}:it(l.children,v,r,g,$)}default:return s.length>0?ye(o):{kind:"leaf",node:l,path:c,parentValues:t}}}function je(e,t,r,n){let i=ie(e,t,r,n);if(i.kind!=="leaf")throw new Error(`field path ${JSON.stringify(n)} identifies a ${i.kind}`);return i}function zt(e,t,r,n){let i=ie(e,t,r,n);if(i.kind!=="table")throw new Error(`table path ${JSON.stringify(n)} identifies a ${i.kind}`);return i}function Wt(e,t,r,n){let i=ie(e,t,r,n);if(i.kind!=="row")throw new Error(`row path ${JSON.stringify(n)} identifies a ${i.kind}`);return i}function Y(e,t){let r=e.get(t);if(!r)throw new Error("missing identity for table row");return r}function N(e){return JSON.stringify(e)}function B(e,t){return e.length===0?[t]:[e[0],...e.slice(1),t]}function oe(e){return[e[0],...e.slice(1)]}function Dn(e){if(!Array.isArray(e)||e.length===0||e.some(t=>typeof t!="string"||t.length===0))throw new TypeError("field path must be a non-empty array of ID segments")}function ye(e){throw new Error(`unknown field path ${JSON.stringify(e)}`)}function Pn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Jt(e){if(e!==null&&typeof e=="object"&&!Array.isArray(e)&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null)&&!Object.hasOwn(e,"value"))throw new TypeError("rich input must have an own value property");let t=structuredClone(e),r=t!==null&&typeof t=="object"&&!Array.isArray(t)&&Object.hasOwn(t,"value")?t.value:t;return{value:t,answer:r}}function Ht(e,t){if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(typeof e[r]!="string"||typeof t[r]!="string"||e[r]!==t[r])return!1;return!0}return e!==null&&typeof e=="object"||t!==null&&typeof t=="object"?!1:Object.is(e,t)}function ot(e,t){if(e!==null&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function")throw new TypeError(`${t} must complete synchronously`);return e}function Kt(e){let t=e.split(".");if(t.some(r=>r.trim()===""))throw new TypeError(`malformed reference ${e}`);return t}function Xt(e,t,r,n,i,o,a){let s=[];for(let E=r.context;E;E=E.parent)E.kind!=="table"&&s.push(E);function l(E){let v=s[E];if(v)return new Proxy(Object.create(null),{get($,y){return y==="current"?v.data:y==="parent"?l(E+1):y==="form"?r.form:typeof y=="string"?v.data[y]:void 0},ownKeys(){return[...new Set([...Reflect.ownKeys(v.data),"current","parent","form"])]},getOwnPropertyDescriptor($,y){if(y==="current"||y==="parent"||y==="form"||Object.hasOwn(v.data,y))return{configurable:!0,enumerable:!0}}})}let c={vars:r.vars,value:t,current:r.parent,parent:l(1),form:r.form,context:r.context};function f(E){let v=Kt(E);if(!["value","current","parent","form","context","vars"].includes(v[0]??""))throw new TypeError(`unknown input scope root ${v[0]}`);let $=c;for(let y of v)$=$?.[y];return $}function p(E){let v=Kt(E),$=0;if(v[0]==="form")$=s.length-1,v.shift();else if(v[0]==="current")v.shift();else for(;v[0]==="parent";)$++,v.shift();let y=s[$];if(!y)throw new Error(`destination ${E} traverses above root`);if(v.length===0)throw new Error(`destination ${E} identifies a container`);return[...y.path,...v]}function g(E,v){let $=!0;function y(){if(!$)throw new Error("input setter facade has expired")}function A(){throw y(),new Error("input setter cannot mutate structure, descriptors or prototypes")}function O(x,S=!1){return new Proxy(Object.create(null),{get(b,u){if(y(),typeof u!="string")return;if(S){let d=s.findIndex(_=>N(_.path)===N(x));if(u==="current")return O(x);if(u==="form")return O([],!0);if(u==="parent"){let _=s[d+1];return _?O(_.path,!0):void 0}}let h=x.length?ie(n,i,o,x):void 0;if(h?.kind==="table"){if(u==="length")return h.rows.length;let d=/^(0|[1-9]\d*)$/.test(u)?h.rows[Number(u)]:void 0;if(!d)throw new Error(`unknown table position ${u}`);return O([...x,Y(o,d)])}let w=[...x,u],m=ie(n,i,o,w);return m.kind==="leaf"?structuredClone(m.parentValues[m.node.id]):O(w)},set(b,u,h){return y(),typeof u!="string"||S&&["current","parent","form"].includes(u)?A():(a([...x,u],h),!0)},deleteProperty:A,defineProperty:A,setPrototypeOf:A,preventExtensions:A})}try{ot(E(O(s[0]?.path??[],!0),v),"setter")}finally{$=!1}}if(e.node.type!=="calculated")for(let[E,v]of(e.node.onChange?.copy??[]).entries()){let $="when";try{let y=typeof v.when=="function"?ot(v.when(c),"when"):v.when??!0;if(typeof y!="boolean")throw new TypeError("when must return a boolean");if(!y)continue;$="value";let A=typeof v.value=="function"?ot(v.value(c),"resolver"):f(v.value);$="destination",typeof v.to=="function"?g(v.to,A):a(p(v.to),A)}catch(y){let A=new Error(`input ${N(e.path)} copy ${E} ${$}${typeof v.to=="string"?` (${v.to})`:" (setter)"}: ${y instanceof Error?y.message:String(y)}`,{cause:y});throw Object.assign(A,{sourcePath:[...e.path],actionIndex:E,stage:$,destination:v.to}),A}}}function Qt(e,t){let r=new Map,n=[];function i(o,a){let s=N(a);if(r.has(s))return r.get(s);let l=n.findIndex(f=>N(f)===s);if(l!==-1){let f=[...n.slice(l),a];throw new Error(`Circular calculation: ${f.map(N).join(" \u2192 ")}`)}let c=e.get(s);if(!c)throw new Error(`missing calculation scope for ${s}`);n.push(a);try{let f=o.calculate(c);return In(f,a),r.set(s,f),f}finally{n.pop()}}return{resolve:i,clearCalculatedValues(){for(let{node:o,parentValues:a}of t.values())delete a[o.id]},resolveAllCalculations(){for(let{node:o,path:a}of t.values())i(o,a)},commitCalculatedResults(){for(let[o,a]of r){let s=t.get(o);if(!s)throw new Error(`missing calculated field for ${o}`);s.parentValues[s.node.id]=a}}}}function In(e,t){if(e!=null&&typeof e!="string"&&typeof e!="number"&&typeof e!="boolean")throw new TypeError(`calculation at ${JSON.stringify(t)} must return a primitive value`)}function Yt(e,t,r){return{relevant:r,required:r&&at(e.required,!1,t,"required"),readOnly:e.type==="calculated"||r&&er(e,t)}}function we(e,t){return at(e.relevant,!0,t,"relevant")}function Gt(e,t,r){let n=e;for(let i=0;i<t.length;i+=1){let o=n.find(({id:l})=>l===t[i]),a=N(t.slice(0,i+1)),s=r.get(a);if(!o||!s)throw new Error(`missing condition scope for ${a}`);if(!we(o,s))return!1;if(o.type==="object"||o.type==="table")n=o.children,o.type==="table"&&(i+=1);else return er(o,s)}throw new Error(`missing field for ${N(t)}`)}function er(e,t){return at(e.readOnly,!1,t,"readOnly")}function tr(e,t,r,n){let i=new Map,o=new WeakMap,a=new Map,s=new Map,l=null,c=O(e,t,[]),f={kind:"form",data:c,path:[],parent:null,id:null,index:null,previous:null};a.set(N([]),f);function p(x,S,b,u,h){for(let w of x){let m=B(h,w.id),d=N(m);if(g(w,b,u,m,d),w.type==="calculated"&&E(w,S,m,d),w.type==="object"){v(w,S,u,m,d);continue}w.type==="table"&&$(w,S,u,m,d)}}function g(x,S,b,u,h){if(i.has(h))return;let w={form:c,parent:S,context:b,vars:n};if(x.type==="table"){i.set(h,Object.freeze({...w,get value(){return S[x.id]},get rows(){return S[x.id]}}));return}let m=Object.freeze({...w,get value(){return S[x.id]}});i.set(h,m),x.type==="object"&&x.validate!==void 0&&o.set(m,Rn(x.validate,u,m))}function E(x,S,b,u){s.set(u,{node:x,path:b,parentValues:S})}function v(x,S,b,u,h){let w=S[x.id],m=a.get(h);m||(m={kind:"object",data:O(x.children,w,u),path:u,parent:b,id:null,index:null,previous:null},a.set(h,m)),p(x.children,w,m.data,m,u)}function $(x,S,b,u,h){let w=S[x.id],m=a.get(h);m||(m={kind:"table",data:[],path:u,parent:b,id:null,index:null,previous:null},a.set(h,m));let d=[];for(let j of w){let R=y(x,w,j,m,u),k=R.data;d.push(k),p(x.children,j,k,R,R.path)}let _=m.data;_.splice(0,_.length,...d)}function y(x,S,b,u,h){let w=Y(r,b),m=B(h,w),d=N(m),_=a.get(d);return _||(_={kind:"row",data:O(x.children,b,m),path:m,parent:u,id:w,get index(){return S.indexOf(b)},get previous(){let j=S.indexOf(b);if(j<=0)return null;let R=S[j-1],k=Y(r,R);return a.get(N(B(h,k)))??null}},a.set(d,_)),_}function A(){s.clear(),p(e,t,c,f,[])}return A(),{scopesByPath:i,objectValidators:o,beginEvaluation(){return l=Qt(i,s),l},endEvaluation(){l=null},sync:A,removeBelow(x){Zt(i,x),Zt(a,x)}};function O(x,S,b){let u=Object.create(null);for(let h of x){let w=B(b,h.id);Object.defineProperty(u,h.id,{enumerable:!0,get(){return h.type==="calculated"&&l?l.resolve(h,w):h.type==="object"||h.type==="table"?a.get(N(w))?.data:Object.hasOwn(S,h.id)?S[h.id]:void 0}})}for(let h of Object.keys(S))Object.hasOwn(u,h)||Object.defineProperty(u,h,{enumerable:!0,get(){return S[h]}});return u}}function Rn(e,t,r){let n,i=Object.freeze({form:r.form,parent:r.parent,context:r.context,vars:r.vars,get value(){return r.value},isRelevant(o){if(!n)throw new Error("isRelevant is only available during object validation");let a=typeof o=="string"?n.get(N(B(t,o))):void 0;if(a===void 0)throw new Error(`object ${N(t)} has no direct child ${JSON.stringify(o)}`);return a}});return o=>{n=o;try{return e(i)}finally{n=void 0}}}function Zt(e,t){for(let r of e.keys()){let n=JSON.parse(r);n.length>=t.length&&t.every((i,o)=>n[o]===i)&&e.delete(r)}}function at(e,t,r,n){if(e===void 0)return t;if(typeof e=="boolean")return e;if(typeof e!="function")throw new TypeError(`${n} condition must be a boolean or function`);let i=e(r);if(typeof i!="boolean")throw new TypeError(`${n} condition must return a boolean`);return i}function rr(e,t,r,n,i=[]){let{value:o}=n;if(e.type==="multi-select"){if(o==null||Array.isArray(o)&&o.length===0)return r?[ce(t,"required",`${e.label} is required.`)]:[];if(!Array.isArray(o)||Nn(o))return[ce(t,"type",`${e.label} must be a list of option values.`)];if(new Set(o).size!==o.length||o.some(c=>!i.some(f=>f.value===c)))return[ce(t,"option",`${e.label} must contain only available options without duplicates.`)]}else{if(o==null||o==="")return r?[ce(t,"required",`${e.label} is required.`)]:[];if(e.type==="text"&&typeof o!="string")return[ce(t,"type",`${e.label} must be text.`)];if(e.type==="select"&&!i.some(s=>s.value===o))return[ce(t,"option",`${e.label} must be one of the available options.`)]}if(e.validate===void 0)return[];let a;switch(e.type){case"multi-select":a=e.validate(n);break;case"calculated":a=e.validate(n);break;default:a=e.validate(n)}return Ae(a,t,"field")}function Ae(e,t,r){if(e===void 0)return[];if(typeof e=="string"&&e.length>0)return[ce(t,"custom",e)];throw e instanceof Promise&&e.catch(()=>{}),new TypeError(`custom validator for ${r} ${JSON.stringify(t)} must return undefined or a non-empty string`)}function Nn(e){for(let t of e)if(typeof t!="string")return!0;return!1}function ce(e,t,r){return{path:[...e],code:t,message:r}}function Pe(e){nr(e,[])}function nr(e,t){let r=new Set;for(let n=0;n<e.length;n+=1){let i=e[n],o=t.length===0?`field ${n+1}`:`field ${n+1} under ${Te(t)}`;if(!De(i))throw new TypeError(`${o} must be an object`);if(typeof i.id!="string"||i.id.trim()==="")throw new TypeError(`${o} must have a non-empty id`);let a=[...t,i.id],s=t.length===0?`field "${i.id}"`:`field ${Te(a)}`;if(i.id==="__proto__")throw new TypeError(`${s} uses reserved id "__proto__"`);if(r.has(i.id))throw t.length>0?new TypeError(`parent ${Te(t)} has duplicate sibling id "${i.id}"`):new TypeError(`${s} has a duplicate id`);if(r.add(i.id),st(s,"relevant",i.relevant),Mn(s,i),i.type==="object"||i.type==="table"){Ln(i,a),nr(i.children,a);continue}if(typeof i.label!="string"||i.label.trim()==="")throw new TypeError(`${s} must have a non-empty label`);if(i.type==="calculated"){qn(s,i);continue}if(st(s,"required",i.required),st(s,"readOnly",i.readOnly),i.type!=="text"&&i.type!=="select"&&i.type!=="multi-select")throw new TypeError(`${s} has an unsupported type`);lt(s,i.validate),(i.type==="select"||i.type==="multi-select")&&typeof i.options!="function"&&ct(s,i.options,!1)}}function qn(e,t){if(typeof t.calculate!="function")throw new TypeError(`${e} calculate must be a function`);if(Object.hasOwn(t,"required"))throw new TypeError(`${e} must not declare required`);if(Object.hasOwn(t,"readOnly"))throw new TypeError(`${e} must not declare readOnly`);if(Object.hasOwn(t,"options"))throw new TypeError(`${e} must not declare options`);lt(e,t.validate)}function Ln(e,t){let r=`${e.type} ${Te(t)}`;if(e.label!==void 0&&(typeof e.label!="string"||e.label.trim()===""))throw new TypeError(`${r} label must be a non-empty string`);if(Object.hasOwn(e,"required"))throw new TypeError(`${r} must not declare required`);if(Object.hasOwn(e,"readOnly"))throw new TypeError(`${r} must not declare readOnly`);if(lt(r,e.validate),!Array.isArray(e.children))throw new TypeError(`${r} must have a children array`)}function lt(e,t){if(t!==void 0&&typeof t!="function")throw new TypeError(`${e} validate must be a function`)}function Te(e){return JSON.stringify(e)}function st(e,t,r){if(r!==void 0&&typeof r!="boolean"&&typeof r!="function")throw new TypeError(`${e} ${t} must be a boolean or function`)}function ct(e,t,r=!1){if(!Array.isArray(t)||!r&&t.length===0)throw new TypeError(`${e} must have at least one option`);let n=new Set;for(let i=0;i<t.length;i+=1){let o=t[i],a=`${e} option ${i+1}`;if(!De(o))throw new TypeError(`${a} must be an object`);if(typeof o.value!="string"||o.value.trim()==="")throw new TypeError(`${a} must have a non-empty string value`);if(n.has(o.value))throw new TypeError(`${e} has duplicate option value "${o.value}"`);if(n.add(o.value),typeof o.label!="string"||o.label.trim()==="")throw new TypeError(`${a} must have a non-empty label`)}}function De(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Mn(e,t){if(!Object.hasOwn(t,"onChange"))return;if(!["text","select","multi-select"].includes(String(t.type)))throw new TypeError(`${e} must not declare onChange`);let r=t.onChange;if(!De(r)||!Array.isArray(r.copy))throw new TypeError(`${e} onChange.copy must be an array`);for(let[n,i]of r.copy.entries()){if(!De(i))throw new TypeError(`${e} copy ${n} must be an object`);for(let o of["to","value"])if(!Object.hasOwn(i,o)||!(typeof i[o]=="function"||typeof i[o]=="string"&&i[o].trim()!==""))throw new TypeError(`${e} copy ${n} ${o} must be a reference or function`);if(Object.hasOwn(i,"when")&&typeof i.when!="boolean"&&typeof i.when!="function")throw new TypeError(`${e} copy ${n} when must be a boolean or function`)}}function ir(e,t,r){if(typeof e.options!="function")return e.options;let n=`field ${JSON.stringify(r)}`,i;try{i=e.options(t)}catch(a){throw new Error(`${n} options evaluation failed`,{cause:a})}if(i!=null&&(typeof i=="object"||typeof i=="function")&&typeof i.then=="function")throw new TypeError(`${n} options must complete synchronously`);let o=i??[];ct(n,o,!0);try{return structuredClone(o)}catch(a){throw new TypeError(`${n} options must have cloneable metadata`,{cause:a})}}function or(e,t,r,n,i){let o=new Map,a=new Map,s=[];function l(f,p,g,E){let v=[];for(let $ of f){let y=B(g,$.id),A=N(y),O=n.get(A);if(!O)throw new Error(`missing condition scope for ${A}`);if($.type==="object"){let w=p[$.id],m=E&&we($,O);a.set(A,m);let d=l($.children,w,y,m);if(!m)continue;let _=Ae(i.get(O)?.(a),y,"object");s.push(..._),(d.length>0||_.length>0)&&v.push({kind:"object",id:$.id,...$.label===void 0?{}:{label:$.label},path:y,errors:_,children:d});continue}if($.type==="table"){let w=p[$.id],m=E&&we($,O);a.set(A,m);let d=m?Fn($,y,O):[];s.push(...d);let _=w.map(j=>{let R=Y(r,j),k=B(y,R);return{id:R,path:k,children:l($.children,j,k,m)}});m&&v.push({kind:"table",id:$.id,...$.label===void 0?{}:{label:$.label},path:y,errors:d,rows:_});continue}let x=E&&we($,O),S=x&&($.type==="select"||$.type==="multi-select")?ir($,O,y):void 0,b=Yt($,O,x);a.set(A,b.relevant);let u=O.value,h=b.relevant?rr($,y,b.required,O,S):[];o.set(A,{...b,errors:h,...S===void 0?{}:{options:S}}),s.push(...h),b.relevant&&v.push({kind:"leaf",field:$,path:y,value:u,required:b.required,readOnly:b.readOnly,errors:h,...S===void 0?{}:{options:S}})}return v}let c=l(e,t,[],!0);return{fieldsByPath:o,relevanceByPath:a,activeFields:c,errors:s,valid:s.length===0}}function Fn(e,t,r){return Ae(e.validate?.(r),t,"table")}function Ie(e){return e.map(ut)}function ut(e){if(e.type==="object"||e.type==="table")return{...e,children:Ie(e.children)};let t={...e};return e.type!=="calculated"&&e.onChange&&(t.onChange={copy:e.onChange.copy.map(r=>({...r}))}),e.type==="select"||e.type==="multi-select"?{...t,options:typeof e.options=="function"?e.options:structuredClone(e.options)}:t}function ar(e,t,r,n){return ft(e,t,[],r,n)}function ft(e,t,r,n,i){let o=Object.create(null);for(let s of e)o[s.id]=s;let a={};for(let s of Object.keys(t)){let l=o[s];if(!l){Re(a,s,structuredClone(t[s]));continue}let c=B(r,l.id);if(Bn(i,c)){if(l.type==="object"){Re(a,s,ft(l.children,t[s],c,n,i));continue}if(l.type==="table"){let p=t[s];Re(a,s,p.map(g=>{let E=B(c,Y(n,g));return ft(l.children,g,E,n,i)}));continue}Re(a,s,structuredClone(t[s]))}}return a}function Re(e,t,r){Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0})}function Bn(e,t){let r=N(t),n=e.get(r);if(n===void 0)throw new Error(`missing relevance evaluation for field path ${r}`);return n}function sr(e,t,r){let n=structuredClone(t),i=new WeakMap;return Ne(e,t,n,[],{rowIdentities:i,allocateRowId:r}),{answers:n,rowIdentities:i}}function lr(e,t,r,n,i){if(!dt(t))throw new TypeError(`row data for table ${JSON.stringify(r)} must be an object`);let o=structuredClone(t),a=n(),s=B(r,a),l={rowIdentities:i,allocateRowId:n};return i.set(o,a),Ne(e.children,t,o,s,l),{row:o,rowId:a}}function Ne(e,t,r,n,i){for(let o of e){if(o.type==="calculated"){delete r[o.id];continue}if(o.type!=="object"&&o.type!=="table")continue;let a=B(n,o.id),s=Object.hasOwn(t,o.id)?t[o.id]:void 0,l=Object.hasOwn(r,o.id)?r[o.id]:void 0;if(o.type==="object"){let p=Un(s,a),g=l??{};r[o.id]=g,Ne(o.children,p,g,a,i);continue}let c=Vn(s,a),f=l??[];r[o.id]=f;for(let[p,g]of c.entries()){let E=f[p];i.rowIdentities.has(E)&&(E=structuredClone(g),f[p]=E);let v=i.allocateRowId();i.rowIdentities.set(E,v),Ne(o.children,g,E,B(a,v),i)}}}function Un(e,t){if(e===void 0)return{};if(!dt(e))throw new TypeError(`data at ${JSON.stringify(t)} must be an object`);return e}function Vn(e,t){if(e===void 0)return[];if(!Array.isArray(e))throw new TypeError(`data at ${JSON.stringify(t)} must be an array`);for(let r=0;r<e.length;r+=1)if(!dt(e[r]))throw new TypeError(`data at ${JSON.stringify([...t,r])} must be a row object`);return e}function dt(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}var cr=new WeakSet;function de(e){if(e!==null&&typeof e=="object"&&cr.has(e))return e;let t=new Set;function r(i,o){if(i===null||typeof i=="string"||typeof i=="boolean"||typeof i=="number"&&Number.isFinite(i))return i;if(typeof i!="object")throw new TypeError(`${o} must contain only JSON-compatible values`);if(t.has(i))throw new TypeError(`${o} must not contain cycles`);if(!Array.isArray(i)&&![Object.prototype,null].includes(Object.getPrototypeOf(i)))throw new TypeError(`${o} must contain only plain records and arrays`);t.add(i);let a=Array.isArray(i)?[]:Object.create(null);if(Array.isArray(i)&&Array.from({length:i.length},(s,l)=>l).some(s=>!Object.hasOwn(i,s)))throw new TypeError(`${o} must not contain sparse arrays`);for(let s of Reflect.ownKeys(i)){if(Array.isArray(i)&&s==="length")continue;let l=Object.getOwnPropertyDescriptor(i,s);if(typeof s!="string"||!l?.enumerable||!Object.hasOwn(l,"value"))throw new TypeError(`${o} must contain only enumerable data properties`);a[s]=r(i[s],`${o}.${s}`)}return t.delete(i),Object.freeze(a)}if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError("vars must be a JSON-compatible object");let n=r(e,"vars");return cr.add(n),n}function fr({schema:e,data:t={},vars:r={}}){if(!Array.isArray(e))throw new TypeError("schema must be an array");if(typeof t!="object"||t===null||Array.isArray(t))throw new TypeError("data must be an object");Pe(e);let n=de(r),i=Ie(e),o=1,a=()=>`row-${o++}`,{answers:s,rowIdentities:l}=sr(i,t,a),c=new Set,f=new Set,p=!1,g=tr(i,s,l,n),E,v=!1;function $(){if(v)throw new Error("reentrant public mutation during input is unsupported")}function y(){E=void 0,g.sync(),x(m=>{m.clearCalculatedValues()})}function A(m,d){let _=h(m);_.parentValues[_.node.id]=structuredClone(d)}function O(){E=void 0,g.sync(),x(m=>{m.clearCalculatedValues(),m.resolveAllCalculations();let d=or(i,s,l,g.scopesByPath,g.objectValidators);m.commitCalculatedResults(),E=d})}function x(m){let d=g.beginEvaluation();try{return m(d)}finally{g.endEvaluation()}}function S(){if(!E)throw new Error("form evaluation is unavailable; mutate form state to retry evaluation");return E}function b(m){let d=ie(i,s,l,m);if(d.kind==="leaf")throw new Error(`section path ${JSON.stringify(m)} identifies a leaf`);let _=S(),j=d.kind==="row"?d.path.slice(0,-1):d.path,R=_.relevanceByPath.get(N(j));if(R===void 0)throw new Error(`missing relevance evaluation for section ${N(d.path)}`);let k=_.errors.filter(C=>dr(C.path,d.path));return{section:d,relevant:R,errors:k}}function u(m){if(p||c.has(N(m)))return!0;for(let d=m.length;d>0;d--)if(f.has(N(m.slice(0,d))))return!0;return!1}function h(m){let d=je(i,s,l,m);if(d.node.type==="calculated")throw new Error(`calculated field path ${JSON.stringify(d.path)} is read-only`);return d}function w(m){let d=h(m);if(!d.node.readOnly)return d;let _=N(d.path),j;if(E){let R=E.fieldsByPath.get(_);if(!R)throw new Error(`missing evaluation for field path ${_}`);j=R.readOnly}else j=x(()=>Gt(i,d.path,g.scopesByPath));if(j)throw new Error(`field path ${_} is read-only`);return d}return O(),{getFields(){return Ie(i)},getActiveFields(){return pt(S().activeFields,c,u)},getValue(m){let d=je(i,s,l,m);return structuredClone(d.parentValues[d.node.id])},input(m,d){$();let _=w(m),j=Jt(d),R=!Ht(_.parentValues[_.node.id],j.answer);y(),v=!0;try{if(A(_.path,j.answer),R){let k=g.scopesByPath.get(N(_.path));if(!k)throw new Error("missing input source scope");Xt(_,j.value,k,i,s,l,A)}O()}finally{v=!1}},setValue(m,d){$();let _=w(m),j=structuredClone(d);_.parentValues[_.node.id]=j,O()},appendRow(m,d={}){$();let _=zt(i,s,l,m),j=lr(_.node,d,_.path,a,l);return _.rows.push(j.row),O(),j.rowId},removeRow(m){$();let d=Wt(i,s,l,m);d.rows.splice(d.index,1),ur(c,d.path),ur(f,d.path),g.removeBelow(d.path),O()},touch(m){$();let d=h(m);c.add(N(d.path))},getFieldState(m){let d=je(i,s,l,m),_=N(d.path),j=S().fieldsByPath.get(_);if(!j)throw new Error(`missing evaluation for field path ${_}`);let{relevant:R,required:k,readOnly:C,errors:P,options:q}=j,L=c.has(_);return{field:ut(d.node),...q===void 0?{}:{options:structuredClone(q)},path:oe(d.path),value:structuredClone(d.parentValues[d.node.id]),touched:L,relevant:R,required:k,readOnly:C,valid:P.length===0,errors:u(d.path)?structuredClone(P):[]}},getSectionState(m){let{section:d,relevant:_,errors:j}=b(m),R=j.filter(C=>C.path.length===d.path.length),k={path:oe(d.path),relevant:_,ownValid:R.length===0,valid:j.length===0,errors:u(d.path)?structuredClone(R):[],subtreeErrors:structuredClone(j.filter(C=>u(C.path)))};return d.kind!=="table"?{...k,kind:d.kind}:{...k,kind:"table",rows:d.rows.map(C=>{let P=Y(l,C);return{id:P,path:B(d.path,P)}})}},isValid(){return S().valid},validate(){$();let{valid:m,errors:d}=S();return p=!0,{valid:m,errors:structuredClone(d)}},validateSection(m){$();let{section:d,relevant:_,errors:j}=b(m);return _&&f.add(N(d.path)),{valid:j.length===0,errors:structuredClone(j)}},getData(){return structuredClone(s)},getVars(){return structuredClone(n)},getSubmissionData(){return ar(i,s,l,S().relevanceByPath)}}}function pt(e,t,r){return e.map(i=>{let o=r(i.path)?structuredClone(i.errors):[];if(i.kind==="object"){let c=pt(i.children,t,r);return c.length===0&&o.length===0?null:{type:"object",id:i.id,...i.label===void 0?{}:{label:i.label},path:oe(i.path),errors:o,children:c}}if(i.kind==="table")return{type:"table",id:i.id,...i.label===void 0?{}:{label:i.label},path:oe(i.path),valid:i.errors.length===0,errors:o,rows:i.rows.map(c=>({type:"row",id:c.id,path:oe(c.path),children:pt(c.children,t,r)}))};let a=structuredClone(i.value);if(i.field.type==="calculated")return{type:"calculated",id:i.field.id,label:i.field.label,path:oe(i.path),value:a,valid:i.errors.length===0,errors:o};let s=t.has(N(i.path)),l={id:i.field.id,label:i.field.label,path:oe(i.path),value:a,touched:s,required:i.required,readOnly:i.readOnly,valid:i.errors.length===0,errors:o};return i.field.type==="select"||i.field.type==="multi-select"?{...l,type:i.field.type,options:structuredClone(i.options??[])}:{...l,type:"text"}}).filter(i=>i!==null)}function ur(e,t){for(let r of e.keys())dr(JSON.parse(r),t)&&e.delete(r)}function dr(e,t){return e.length>=t.length&&t.every((r,n)=>e[n]===r)}var ht=class{add(t,r,n){if(typeof arguments[0]!="string")for(let i in arguments[0])this.add(i,arguments[0][i],arguments[1]);else(Array.isArray(t)?t:[t]).forEach(function(i){this[i]=this[i]||[],r&&this[i][n?"unshift":"push"](r)},this)}run(t,r){this[t]=this[t]||[],this[t].forEach(function(n){n.call(r&&r.context?r.context:r,r)})}},mt=class{constructor(t){this.jsep=t,this.registered={}}register(...t){t.forEach(r=>{if(typeof r!="object"||!r.name||!r.init)throw new Error("Invalid JSEP plugin format");this.registered[r.name]||(r.init(this.jsep),this.registered[r.name]=r)})}},K=class e{static get version(){return"1.4.0"}static toString(){return"JavaScript Expression Parser (JSEP) v"+e.version}static addUnaryOp(t){return e.max_unop_len=Math.max(t.length,e.max_unop_len),e.unary_ops[t]=1,e}static addBinaryOp(t,r,n){return e.max_binop_len=Math.max(t.length,e.max_binop_len),e.binary_ops[t]=r,n?e.right_associative.add(t):e.right_associative.delete(t),e}static addIdentifierChar(t){return e.additional_identifier_chars.add(t),e}static addLiteral(t,r){return e.literals[t]=r,e}static removeUnaryOp(t){return delete e.unary_ops[t],t.length===e.max_unop_len&&(e.max_unop_len=e.getMaxKeyLen(e.unary_ops)),e}static removeAllUnaryOps(){return e.unary_ops={},e.max_unop_len=0,e}static removeIdentifierChar(t){return e.additional_identifier_chars.delete(t),e}static removeBinaryOp(t){return delete e.binary_ops[t],t.length===e.max_binop_len&&(e.max_binop_len=e.getMaxKeyLen(e.binary_ops)),e.right_associative.delete(t),e}static removeAllBinaryOps(){return e.binary_ops={},e.max_binop_len=0,e}static removeLiteral(t){return delete e.literals[t],e}static removeAllLiterals(){return e.literals={},e}get char(){return this.expr.charAt(this.index)}get code(){return this.expr.charCodeAt(this.index)}constructor(t){this.expr=t,this.index=0}static parse(t){return new e(t).parse()}static getMaxKeyLen(t){return Math.max(0,...Object.keys(t).map(r=>r.length))}static isDecimalDigit(t){return t>=48&&t<=57}static binaryPrecedence(t){return e.binary_ops[t]||0}static isIdentifierStart(t){return t>=65&&t<=90||t>=97&&t<=122||t>=128&&!e.binary_ops[String.fromCharCode(t)]||e.additional_identifier_chars.has(String.fromCharCode(t))}static isIdentifierPart(t){return e.isIdentifierStart(t)||e.isDecimalDigit(t)}throwError(t){let r=new Error(t+" at character "+this.index);throw r.index=this.index,r.description=t,r}runHook(t,r){if(e.hooks[t]){let n={context:this,node:r};return e.hooks.run(t,n),n.node}return r}searchHook(t){if(e.hooks[t]){let r={context:this};return e.hooks[t].find(function(n){return n.call(r.context,r),r.node}),r.node}}gobbleSpaces(){let t=this.code;for(;t===e.SPACE_CODE||t===e.TAB_CODE||t===e.LF_CODE||t===e.CR_CODE;)t=this.expr.charCodeAt(++this.index);this.runHook("gobble-spaces")}parse(){this.runHook("before-all");let t=this.gobbleExpressions(),r=t.length===1?t[0]:{type:e.COMPOUND,body:t};return this.runHook("after-all",r)}gobbleExpressions(t){let r=[],n,i;for(;this.index<this.expr.length;)if(n=this.code,n===e.SEMCOL_CODE||n===e.COMMA_CODE)this.index++;else if(i=this.gobbleExpression())r.push(i);else if(this.index<this.expr.length){if(n===t)break;this.throwError('Unexpected "'+this.char+'"')}return r}gobbleExpression(){let t=this.searchHook("gobble-expression")||this.gobbleBinaryExpression();return this.gobbleSpaces(),this.runHook("after-expression",t)}gobbleBinaryOp(){this.gobbleSpaces();let t=this.expr.substr(this.index,e.max_binop_len),r=t.length;for(;r>0;){if(e.binary_ops.hasOwnProperty(t)&&(!e.isIdentifierStart(this.code)||this.index+t.length<this.expr.length&&!e.isIdentifierPart(this.expr.charCodeAt(this.index+t.length))))return this.index+=r,t;t=t.substr(0,--r)}return!1}gobbleBinaryExpression(){let t,r,n,i,o,a,s,l,c;if(a=this.gobbleToken(),!a||(r=this.gobbleBinaryOp(),!r))return a;for(o={value:r,prec:e.binaryPrecedence(r),right_a:e.right_associative.has(r)},s=this.gobbleToken(),s||this.throwError("Expected expression after "+r),i=[a,o,s];r=this.gobbleBinaryOp();){if(n=e.binaryPrecedence(r),n===0){this.index-=r.length;break}o={value:r,prec:n,right_a:e.right_associative.has(r)},c=r;let f=p=>o.right_a&&p.right_a?n>p.prec:n<=p.prec;for(;i.length>2&&f(i[i.length-2]);)s=i.pop(),r=i.pop().value,a=i.pop(),t={type:e.BINARY_EXP,operator:r,left:a,right:s},i.push(t);t=this.gobbleToken(),t||this.throwError("Expected expression after "+c),i.push(o,t)}for(l=i.length-1,t=i[l];l>1;)t={type:e.BINARY_EXP,operator:i[l-1].value,left:i[l-2],right:t},l-=2;return t}gobbleToken(){let t,r,n,i;if(this.gobbleSpaces(),i=this.searchHook("gobble-token"),i)return this.runHook("after-token",i);if(t=this.code,e.isDecimalDigit(t)||t===e.PERIOD_CODE)return this.gobbleNumericLiteral();if(t===e.SQUOTE_CODE||t===e.DQUOTE_CODE)i=this.gobbleStringLiteral();else if(t===e.OBRACK_CODE)i=this.gobbleArray();else{for(r=this.expr.substr(this.index,e.max_unop_len),n=r.length;n>0;){if(e.unary_ops.hasOwnProperty(r)&&(!e.isIdentifierStart(this.code)||this.index+r.length<this.expr.length&&!e.isIdentifierPart(this.expr.charCodeAt(this.index+r.length)))){this.index+=n;let o=this.gobbleToken();return o||this.throwError("missing unaryOp argument"),this.runHook("after-token",{type:e.UNARY_EXP,operator:r,argument:o,prefix:!0})}r=r.substr(0,--n)}e.isIdentifierStart(t)?(i=this.gobbleIdentifier(),e.literals.hasOwnProperty(i.name)?i={type:e.LITERAL,value:e.literals[i.name],raw:i.name}:i.name===e.this_str&&(i={type:e.THIS_EXP})):t===e.OPAREN_CODE&&(i=this.gobbleGroup())}return i?(i=this.gobbleTokenProperty(i),this.runHook("after-token",i)):this.runHook("after-token",!1)}gobbleTokenProperty(t){this.gobbleSpaces();let r=this.code;for(;r===e.PERIOD_CODE||r===e.OBRACK_CODE||r===e.OPAREN_CODE||r===e.QUMARK_CODE;){let n;if(r===e.QUMARK_CODE){if(this.expr.charCodeAt(this.index+1)!==e.PERIOD_CODE)break;n=!0,this.index+=2,this.gobbleSpaces(),r=this.code}this.index++,r===e.OBRACK_CODE?(t={type:e.MEMBER_EXP,computed:!0,object:t,property:this.gobbleExpression()},t.property||this.throwError('Unexpected "'+this.char+'"'),this.gobbleSpaces(),r=this.code,r!==e.CBRACK_CODE&&this.throwError("Unclosed ["),this.index++):r===e.OPAREN_CODE?t={type:e.CALL_EXP,arguments:this.gobbleArguments(e.CPAREN_CODE),callee:t}:(r===e.PERIOD_CODE||n)&&(n&&this.index--,this.gobbleSpaces(),t={type:e.MEMBER_EXP,computed:!1,object:t,property:this.gobbleIdentifier()}),n&&(t.optional=!0),this.gobbleSpaces(),r=this.code}return t}gobbleNumericLiteral(){let t="",r,n;for(;e.isDecimalDigit(this.code);)t+=this.expr.charAt(this.index++);if(this.code===e.PERIOD_CODE)for(t+=this.expr.charAt(this.index++);e.isDecimalDigit(this.code);)t+=this.expr.charAt(this.index++);if(r=this.char,r==="e"||r==="E"){for(t+=this.expr.charAt(this.index++),r=this.char,(r==="+"||r==="-")&&(t+=this.expr.charAt(this.index++));e.isDecimalDigit(this.code);)t+=this.expr.charAt(this.index++);e.isDecimalDigit(this.expr.charCodeAt(this.index-1))||this.throwError("Expected exponent ("+t+this.char+")")}return n=this.code,e.isIdentifierStart(n)?this.throwError("Variable names cannot start with a number ("+t+this.char+")"):(n===e.PERIOD_CODE||t.length===1&&t.charCodeAt(0)===e.PERIOD_CODE)&&this.throwError("Unexpected period"),{type:e.LITERAL,value:parseFloat(t),raw:t}}gobbleStringLiteral(){let t="",r=this.index,n=this.expr.charAt(this.index++),i=!1;for(;this.index<this.expr.length;){let o=this.expr.charAt(this.index++);if(o===n){i=!0;break}else if(o==="\\")switch(o=this.expr.charAt(this.index++),o){case"n":t+=`
|
|
46
|
+
`;break;case"r":t+="\r";break;case"t":t+=" ";break;case"b":t+="\b";break;case"f":t+="\f";break;case"v":t+="\v";break;default:t+=o}else t+=o}return i||this.throwError('Unclosed quote after "'+t+'"'),{type:e.LITERAL,value:t,raw:this.expr.substring(r,this.index)}}gobbleIdentifier(){let t=this.code,r=this.index;for(e.isIdentifierStart(t)?this.index++:this.throwError("Unexpected "+this.char);this.index<this.expr.length&&(t=this.code,e.isIdentifierPart(t));)this.index++;return{type:e.IDENTIFIER,name:this.expr.slice(r,this.index)}}gobbleArguments(t){let r=[],n=!1,i=0;for(;this.index<this.expr.length;){this.gobbleSpaces();let o=this.code;if(o===t){n=!0,this.index++,t===e.CPAREN_CODE&&i&&i>=r.length&&this.throwError("Unexpected token "+String.fromCharCode(t));break}else if(o===e.COMMA_CODE){if(this.index++,i++,i!==r.length){if(t===e.CPAREN_CODE)this.throwError("Unexpected token ,");else if(t===e.CBRACK_CODE)for(let a=r.length;a<i;a++)r.push(null)}}else if(r.length!==i&&i!==0)this.throwError("Expected comma");else{let a=this.gobbleExpression();(!a||a.type===e.COMPOUND)&&this.throwError("Expected comma"),r.push(a)}}return n||this.throwError("Expected "+String.fromCharCode(t)),r}gobbleGroup(){this.index++;let t=this.gobbleExpressions(e.CPAREN_CODE);if(this.code===e.CPAREN_CODE)return this.index++,t.length===1?t[0]:t.length?{type:e.SEQUENCE_EXP,expressions:t}:!1;this.throwError("Unclosed (")}gobbleArray(){return this.index++,{type:e.ARRAY_EXP,elements:this.gobbleArguments(e.CBRACK_CODE)}}},zn=new ht;Object.assign(K,{hooks:zn,plugins:new mt(K),COMPOUND:"Compound",SEQUENCE_EXP:"SequenceExpression",IDENTIFIER:"Identifier",MEMBER_EXP:"MemberExpression",LITERAL:"Literal",THIS_EXP:"ThisExpression",CALL_EXP:"CallExpression",UNARY_EXP:"UnaryExpression",BINARY_EXP:"BinaryExpression",ARRAY_EXP:"ArrayExpression",TAB_CODE:9,LF_CODE:10,CR_CODE:13,SPACE_CODE:32,PERIOD_CODE:46,COMMA_CODE:44,SQUOTE_CODE:39,DQUOTE_CODE:34,OPAREN_CODE:40,CPAREN_CODE:41,OBRACK_CODE:91,CBRACK_CODE:93,QUMARK_CODE:63,SEMCOL_CODE:59,COLON_CODE:58,unary_ops:{"-":1,"!":1,"~":1,"+":1},binary_ops:{"||":1,"??":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10,"**":11},right_associative:new Set(["**"]),additional_identifier_chars:new Set(["$","_"]),literals:{true:!0,false:!1,null:null},this_str:"this"});K.max_unop_len=K.getMaxKeyLen(K.unary_ops);K.max_binop_len=K.getMaxKeyLen(K.binary_ops);var Q=e=>new K(e).parse(),Wn=Object.getOwnPropertyNames(class{});Object.getOwnPropertyNames(K).filter(e=>!Wn.includes(e)&&Q[e]===void 0).forEach(e=>{Q[e]=K[e]});Q.Jsep=K;var Kn="ConditionalExpression",Jn={name:"ternary",init(e){e.hooks.add("after-expression",function(r){if(r.node&&this.code===e.QUMARK_CODE){this.index++;let n=r.node,i=this.gobbleExpression();if(i||this.throwError("Expected expression"),this.gobbleSpaces(),this.code===e.COLON_CODE){this.index++;let o=this.gobbleExpression();if(o||this.throwError("Expected expression"),r.node={type:Kn,test:n,consequent:i,alternate:o},n.operator&&e.binary_ops[n.operator]<=.9){let a=n;for(;a.right.operator&&e.binary_ops[a.right.operator]<=.9;)a=a.right;r.node.test=a.right,a.right=r.node,r.node=n}}else this.throwError("Expected :")}})}};Q.plugins.register(Jn);var Hn={or:1,and:2,"=":3,"!=":3,"<":4,"<=":4,">":4,">=":4,"+":5,"-":5,"*":6,"/":6,"%":6};Q.removeAllBinaryOps();for(let[e,t]of Object.entries(Hn))Q.addBinaryOp(e,t);Q.removeAllUnaryOps();for(let e of["+","-","!"])Q.addUnaryOp(e);Q.removeAllLiterals();for(let[e,t]of Object.entries({true:!0,false:!1,null:null,undefined:void 0}))Q.addLiteral(e,t);function bt(e){if(!e.slice(1).trim())throw new SyntaxError("Empty formula");return Q(e.slice(1))}var M={kind:"open"},J={kind:"scalar"};function ue(e){let t=e.flatMap(r=>r.choices??[r]);return t.length===1?t[0]??M:{kind:"choices",choices:t}}function ge(e){return e.choices?ue(e.choices.map(ge)):e.element??M}function yt(e){if(e.choices)return ue(e.choices.map(yt));if(e.kind==="declared-vars")throw new TypeError("Declared vars require a literal first-level member");return e.kind==="array"?ge(e):M}function qe(e,t){let r=new Map,n=new Set(t.flatMap(o=>o!=null&&typeof o=="object"?Object.keys(o):[])),i={kind:"record",members:r,ownKeys:n};for(let o of e){let a=t.filter(c=>c!=null&&Object.hasOwn(c,o.id)).map(c=>c[o.id]),s=o.id,l=J;o.type==="object"?l=qe(o.children,a):o.type==="table"?l={kind:"array",element:qe(o.children,a.flatMap(c=>Array.isArray(c)?c:[]))}:o.type==="multi-select"&&(l={kind:"array",element:J}),r.set(s,l)}return i}function pe(e){if(Array.isArray(e)){let t=e.map(pe);return{kind:"array",element:ue(t),elements:t}}return e!==null&&typeof e=="object"?{kind:"vars-record",members:new Map(Object.entries(e).map(([t,r])=>[t,pe(r)]))}:J}function pr(e){return{kind:"declared-vars",members:new Map(e.map(t=>[t,M]))}}function Xn(e){if(["__proto__","prototype","constructor"].includes(String(e)))throw new TypeError(`Forbidden property ${e}`)}function ee(e,t,r,n=!1){Xn(t);let i=String(t);if(e.choices)return ue(e.choices.map(o=>ee(o,t,r,n)));if(e.kind==="context"){if(i==="data")return e.data??M;if(i==="parent")return e.parent??M;if(i==="previous")return e;if(["kind","id","index"].includes(i))return J;if(i==="path")return{kind:"array",element:J};throw new TypeError(`Unknown context member ${i}`)}if(e.kind==="ancestor")return i==="current"?e.data??M:i==="parent"?e.parent??M:i==="form"?e.members?.get("form")??M:ee(e.data??M,t,r,n);if(e.kind==="array"){if(i==="length")return J;if(/^-?(0|[1-9]\d*)$/.test(i))return e.elements?.[Number(i)]??e.element??M;throw new TypeError(`Unknown array member ${i}`)}if(e.kind==="record"){let o=e.members?.get(i);if(o)return o;if(n?r!=null&&Object.hasOwn(r,i):e.ownKeys?.has(i))return M;throw new TypeError(`Unknown schema member ${i}`)}if(["vars-record","declared-vars"].includes(e.kind)){let o=e.members?.get(i);if(o)return o;if(n)return M;throw new TypeError(`Unknown vars member ${i}`)}return M}function Le(e,t,r){if(typeof r!="string"&&typeof r!="number")throw new TypeError("Member key must be a string or number");let n=ee(t,r,e,!0);if(e==null)return{value:void 0,descriptor:n};if(typeof e=="string"||Array.isArray(e)){if(r==="length"||/^-?(0|[1-9]\d*)$/.test(String(r)))return{value:e[r],descriptor:n};throw new TypeError(`Unsupported array/string member ${r}`)}if(typeof e!="object")throw new TypeError(`Cannot traverse scalar at ${r}`);return["context","ancestor"].includes(t.kind)||["record","vars-record"].includes(t.kind)&&t.members?.has(String(r))||Object.hasOwn(e,r)?{value:e[r],descriptor:n}:{value:void 0,descriptor:n}}function hr(e,t,r,n,i,o,a){let s=new Map([["form",e],["parent",t],["context",r],["vars",a]]);if(i){s.set("current",t),s.set("value",M);let l=[];for(let f=r.parent;f;f=f.parent)f.data?.kind!=="array"&&l.push(f.data??M);let c;for(let f of l.reverse())c={kind:"ancestor",data:f,...c?{parent:c}:{},members:new Map([["form",e]])};s.set("parent",c??M)}else if(o==="validate"){let l=t.members?.get(n.id)??M;s.set(n.type==="table"?"rows":"value",l),n.type==="object"&&l.members&&s.set("isRelevant",{kind:"helper",members:l.members})}return s}var Qn=e=>e.type==="Literal"&&["string","number"].includes(typeof e.value)?e.value:void 0;function mr(e){let t=e,r=[];if(t.type==="Literal"&&typeof t.value=="string"?r=[t.value]:t.type==="ArrayExpression"&&(r=t.elements.map(n=>n?.type==="Literal"?n.value:void 0)),!r.length||r.some(n=>typeof n!="string"||!n.length))throw new TypeError("Selector must be a literal field ID or non-empty string path array");return r}function H(e,t){if(!e||e.optional)throw new TypeError("Unsupported expression syntax");let r=e;switch(r.type){case"Literal":if(typeof r.value=="number"&&!Number.isFinite(r.value))throw new TypeError("Non-finite number literal");return J;case"Identifier":{if(r.name.startsWith("$")){if(r.name.length===1||r.name.slice(1).includes("$"))throw new TypeError("Invalid $field shorthand");return ee(t.get("parent")??M,r.name.slice(1))}let n=t.get(r.name);if(!n||n.kind==="helper")throw new TypeError(`Unknown scope root ${r.name}`);return n}case"ArrayExpression":{let n=r.elements.map(i=>H(i,t));return{kind:"array",elements:n,element:ue(n)}}case"MemberExpression":{let n=H(r.object,t);r.computed&&H(r.property,t);let i=r.computed?Qn(r.property):r.property.name;return i===void 0?yt(n):ee(n,i)}case"UnaryExpression":if(!["+","-","!"].includes(r.operator))throw new TypeError(`Unsupported operator ${r.operator}`);return H(r.argument,t),J;case"BinaryExpression":if(!["+","-","*","/","%","<","<=",">",">=","=","!=","and","or"].includes(r.operator))throw new TypeError(`Unsupported operator ${r.operator}`);return H(r.left,t),H(r.right,t),J;case"ConditionalExpression":return H(r.test,t),ue([H(r.consequent,t),H(r.alternate,t)]);case"CallExpression":{let n=r.callee.type==="Identifier"?r.callee.name:"";if(n==="isRelevant"){let o=t.get(n);if(!o)throw new TypeError("isRelevant is only available in object validation");let[a]=r.arguments;if(r.arguments.length!==1||a?.type!=="Literal"||typeof a.value!="string")throw new TypeError("isRelevant requires one literal string child ID");if(!o.members?.has(a.value))throw new TypeError(`Unknown direct child ${JSON.stringify(a.value)}`);return J}if(!["sum","count","unique"].includes(n))throw new TypeError(`Unsupported helper call ${n||"method"}`);if(r.arguments.length<1||r.arguments.length>(n==="count"?1:2))throw new TypeError(`${n} has incorrect argument count`);let i=H(r.arguments[0],t);if(r.arguments.length===2){let o=ge(i);for(let a of mr(r.arguments[1]))o=ee(o,a)}return J}default:throw new TypeError(`Unsupported AST node ${r.type}`)}}var br=e=>e==null||typeof e=="string"&&!e.trim();function Me(e){if(!br(e)){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(e.trim())&&Number.isFinite(Number(e)))return Number(e);throw new TypeError(`Invalid numeric operand ${String(e)}`)}}var wt=e=>e===null||["undefined","string","number","boolean"].includes(typeof e);function gt(e,t,r){let n=e,i=a=>gt(a,t,r),o=(a,s=J)=>({value:a,descriptor:s});switch(n.type){case"Literal":return o(n.value);case"Identifier":return n.name.startsWith("$")?Le(t.parent,r.get("parent")??M,n.name.slice(1)):o(t[n.name],r.get(n.name));case"ArrayExpression":{let a=n.elements.map(s=>i(s));return o(a.map(s=>s.value),{kind:"array",elements:a.map(s=>s.descriptor)})}case"MemberExpression":{let a=i(n.object);return Le(a.value,a.descriptor,n.computed?i(n.property).value:n.property.name)}case"UnaryExpression":{let a=i(n.argument).value;if(n.operator==="!")return o(!a);let s=Me(a);return o(s===void 0?void 0:n.operator==="-"?-s:s)}case"ConditionalExpression":return i(i(n.test).value?n.consequent:n.alternate);case"BinaryExpression":{let a=i(n.left).value;if(n.operator==="and")return o(!!a&&!!i(n.right).value);if(n.operator==="or")return o(!!a||!!i(n.right).value);let s=i(n.right).value;if(["=","!="].includes(n.operator)){if(!wt(a)||!wt(s))throw new TypeError("Equality requires primitive operands");return o(n.operator==="="?a===s:a!==s)}let l=Me(a),c=Me(s);if(l===void 0||c===void 0){let p=["<","<=",">",">="].includes(n.operator);return o(p?!1:void 0)}if(["/","%"].includes(n.operator)&&c===0)throw new TypeError("Division/remainder by zero");let f;switch(n.operator){case"<":return o(l<c);case"<=":return o(l<=c);case">":return o(l>c);case">=":return o(l>=c);case"+":f=l+c;break;case"-":f=l-c;break;case"*":f=l*c;break;case"/":f=l/c;break;default:f=l%c}if(!Number.isFinite(f))throw new TypeError("Non-finite arithmetic result");return o(f)}case"CallExpression":{let a=n.callee.name;if(a==="isRelevant"){let v=n.arguments[0];return o(t.isRelevant(v.value))}let s=i(n.arguments[0]),l=s.value??[];if(!Array.isArray(l))throw new TypeError(`${a} requires an array collection`);if(a==="count")return o(l.length);let c=n.arguments.length===2?mr(n.arguments[1]):[],f=ge(s.descriptor);for(let v of c)f=ee(f,v);let p=0,g=new Set,E=!0;for(let[v,$]of l.entries()){let y=o($,ee(s.descriptor,v,l,!0));for(let A of c)y=Le(y.value,y.descriptor,A);if(!br(y.value))if(a==="unique"){if(!wt(y.value))throw new TypeError("unique requires primitive selected values");g.has(y.value)&&(E=!1),g.add(y.value)}else{let A;try{A=Me(y.value)}catch{continue}if(p+=A??0,!Number.isFinite(p))throw new TypeError("sum overflow produced a non-finite result")}}return o(a==="unique"?E:p)}default:throw new TypeError(`Unsupported AST node ${n.type}`)}}var yr=["relevant","required","readOnly"],wr=[...yr,"calculate","validate"];function ve({schema:e,data:t={},varsShape:r,executable:n=!0,locateFormulaError:i}){Pe(vr(e));let o=qe(e,[t]),a={formShape:o,varsShape:r,executable:n,locateFormulaError:i},s={kind:"context",data:o};return e.map(l=>gr(l,s,[],a))}function gr(e,t,r,n){let i=e,o=i.id,a=[...r,i.id];if(i.type!=="calculated"&&typeof i.calculate=="string"&&i.calculate.startsWith("="))throw vt(new TypeError("calculate is only supported on calculated fields"),a,"calculate",i.calculate);function s(c,f,p=!1){if(typeof c!="string"||!c.startsWith("="))return c;let g=hr(n.formShape,t.data,t,i,p,f,n.varsShape);return Zn({formula:c,roots:g,property:f,definitionPath:a,nodeId:o,executable:n.executable,locateFormulaError:n.locateFormulaError})}let l={...i};for(let c of wr)Object.hasOwn(i,c)&&(l[c]=s(i[c],c));if(i.onChange&&(l.onChange={...i.onChange,copy:i.onChange.copy.map((c,f)=>{let p={...c};return Object.hasOwn(c,"when")&&(p.when=s(c.when,`onChange.copy[${f}].when`,!0)),p.value=s(c.value,`onChange.copy[${f}].value`,!0),p})}),(i.type==="select"||i.type==="multi-select")&&(typeof i.options=="string"&&i.options.startsWith("=")?l.options=s(i.options,"options"):typeof i.options=="function"?l.options=i.options:l.options=structuredClone(i.options)),i.type==="object"||i.type==="table"){let c=t.data.members?.get(i.id);if(!c)throw new Error("Missing declared descriptor");let f={kind:"context",data:c,parent:t},p=i.type==="table"?{kind:"context",data:c.element??c,parent:f}:f;l.children=i.children.map(g=>gr(g,p,a,n))}return l}function Zn({formula:e,roots:t,property:r,definitionPath:n,nodeId:i,executable:o,locateFormulaError:a}){let s;try{s=bt(e),H(s,t)}catch(l){let c=a?.({cause:l,schemaPath:n,property:r,formula:e,check(p){H(bt(p),t)}}),f=vt(c?.cause??l,n,r,e);throw c?.location!==void 0&&Object.assign(f,{preparationLocation:c.location}),f}return o?l=>{let c=[...l.context.path,i];try{let f=gt(s,l,t).value;return Yn(r,f),f}catch(f){throw vt(f,n,r,e,c)}}:e}function Yn(e,t){if(yr.includes(e)||e.endsWith(".when")){if(typeof t!="boolean")throw new TypeError("Condition must return a boolean");return}if(e==="calculate"){if(t!==null&&!["undefined","string","number","boolean"].includes(typeof t))throw new TypeError("Calculation must return a primitive value");if(typeof t=="number"&&!Number.isFinite(t))throw new TypeError("Calculation must return a finite number");return}if(e==="validate"&&t!==void 0&&(typeof t!="string"||!t.length))throw new TypeError("Validator must return undefined or a non-empty message string")}function Fe(e){return typeof e=="string"&&e.startsWith("=")?()=>{}:e}function vr(e){return e.map(t=>{let r=t;if(r===null||typeof r!="object")return r;let n={...r};for(let i of wr)Object.hasOwn(r,i)&&(n[i]=Fe(r[i]));return["select","multi-select"].includes(r.type)&&typeof r.options=="string"&&r.options.startsWith("=")&&(n.options=Fe(r.options)),Array.isArray(r.children)&&(n.children=vr(r.children)),r.onChange&&Array.isArray(r.onChange.copy)&&(n.onChange={...r.onChange,copy:r.onChange.copy.map(i=>{if(!i||typeof i!="object")return i;let o={...i};return Object.hasOwn(i,"when")&&(o.when=Fe(i.when)),o.value=Fe(i.value),o})}),n})}function vt(e,t,r,n,i){let o=e&&typeof e=="object"&&"index"in e?e.index:void 0,a=new Error(`Expression ${JSON.stringify(t)} ${r} ${JSON.stringify(n)}${i?` at ${JSON.stringify(i)}`:""}${o===void 0?"":` offset ${o}`}: ${e instanceof Error?e.message:String(e)}`,{cause:e});return Object.assign(a,{schemaPath:[...t],property:r,formula:n,...i?{instancePath:[...i]}:{},...o===void 0?{}:{offset:o}})}function Er({schema:e,data:t={},vars:r={}}){if(!Array.isArray(e))throw new TypeError("schema must be an array");if(typeof t!="object"||t===null||Array.isArray(t))throw new TypeError("data must be an object");let n=de(r);return fr({schema:ve({schema:e,data:t,varsShape:pe(n)}),data:t,vars:n})}function xr(e,t){let r=Math.max(0,Math.min(t,e.length)),n=1,i=1;for(let o=0;o<r;o+=1)e[o]===`
|
|
47
|
+
`?(n+=1,i=1):i+=1;return Object.freeze({offset:r,line:n,column:i})}function Gn(e,t,r){return Object.freeze({start:xr(e,t),end:xr(e,Math.max(t,r))})}function I(e,t,r,n){return Object.freeze({category:t,message:r,range:Gn(e,n.start,n.end)})}var W=class extends Error{diagnostics=Object.freeze([]);constructor(t,r={}){super(t.length===1?t[0]?.message:`Form language compilation failed with ${t.length} diagnostics`,r),this.name="FormLanguageError",Object.defineProperty(this,"diagnostics",{value:Object.freeze([...t]),enumerable:!0,writable:!1,configurable:!1})}};var Ee=new Set(["text","select","multi-select"]);function kr(e,t){let r=[],n=t.declarations.filter(O=>O.kind==="vars"),i=t.declarations.filter(O=>O.kind==="content");for(let O of n.slice(1))r.push(I(e,"declaration","Only one vars block is allowed",O));for(let O of i.slice(1))r.push(I(e,"declaration","Only one content block is allowed",O));let o=[],a=new Set;for(let O of n.slice(0,1))for(let x of O.names)a.has(x.value)?r.push(I(e,"declaration",`Duplicate var ${x.value}`,x)):(a.add(x.value),o.push(x.value));let s=new Map;for(let O of i.slice(0,1))for(let x of O.entries)s.has(x.name.value)?r.push(I(e,"declaration",`Duplicate content ${x.name.value}`,x.name)):s.set(x.name.value,x.value.value);function l(O,x){if(!O)return;let S=O.kind==="content"?s.get(O.name):O.value;return O.kind==="content"&&S===void 0&&r.push(I(e,"declaration",`Unknown content ${O.name}`,O)),typeof S=="string"&&!S.trim()&&r.push(I(e,"declaration",`${x} must be non-empty`,O)),S??""}let c=t.declarations.filter(O=>O.kind==="node"),f=new Map,p=new Map,g=new Map,E=(O,x)=>`${JSON.stringify(O)}:${x}`;function v(O,x,S){let b=new Set;return O.map(u=>{let h=[...x,u.id.value];p.set(JSON.stringify(h),u),b.has(u.id.value)&&r.push(I(e,"schema",`Duplicate sibling ID ${u.id.value}`,u.id)),b.add(u.id.value),u.id.value==="__proto__"&&r.push(I(e,"schema",'Reserved ID "__proto__"',u.id));let w={type:u.type,id:u.id.value};u.label&&(w.label=l(u.label,"Label")),(Ee.has(u.type)||u.type==="calculated")&&!u.label&&r.push(I(e,"declaration",`${u.type} requires a label`,u)),u.marker&&(Ee.has(u.type)?w.required=!0:r.push(I(e,"declaration",`Required marker is not supported on ${u.type}`,u)));let m=new Map;for(let d of u.properties??[])m.has(d.name)?r.push(I(e,"declaration",`Duplicate ${d.name} property`,d)):m.set(d.name,d),["required","readOnly"].includes(d.name)&&!Ee.has(u.type)?r.push(I(e,"declaration",`${d.name} is not supported on ${u.type}`,d)):(w[d.name]=`=${d.expression.value}`,f.set(E(h,d.name),d.expression));if(u.marker&&m.has("required")&&r.push(I(e,"declaration","Required marker conflicts with required property",m.get("required"))),u.calculate&&(w.calculate=`=${u.calculate.value}`,f.set(E(h,"calculate"),u.calculate)),u.options)if(["select","multi-select"].includes(u.type)||r.push(I(e,"declaration",`options is not supported on ${u.type}`,u.options)),u.options.kind==="formula")w.options=`=${u.options.expression.value}`,f.set(E(h,"options"),u.options.expression);else{let d=new Set;w.options=u.options.entries.map(_=>(_.value.value.trim()||r.push(I(e,"declaration","Option value must be non-empty",_.value)),d.has(_.value.value)&&r.push(I(e,"declaration",`Duplicate option value ${_.value.value}`,_.value)),d.add(_.value.value),{value:_.value.value,label:l(_.label,"Option label")}))}else["select","multi-select"].includes(u.type)&&r.push(I(e,"declaration",`${u.type} requires exactly one options source`,u));if(u.children?.length&&!["object","table"].includes(u.type)&&r.push(I(e,"declaration",`Nested declarations are not supported on ${u.type}`,u.children[0])),["object","table"].includes(u.type)){let d=[u.children,...S];w.children=v(u.children??[],h,d)}if(u.validations?.length){let d="undefined",_=[];for(let j=u.validations.length-1;j>=0;j-=1){let R=u.validations[j],k=l(R.message,"Validation message");_.unshift({formula:`=${R.predicate.value}`,range:R.predicate}),d=`(${R.predicate.value}) ? (${d}) : ${JSON.stringify(k)}`}w.validate=`=${d}`,g.set(E(h,"validate"),_),f.set(E(h,"validate"),{start:u.validations[0].start,end:u.validations.at(-1).end})}return u.copies?.length&&(Ee.has(u.type)||r.push(I(e,"declaration",`copy is not supported on ${u.type}`,u.copies[0])),w.onChange={copy:u.copies.map((d,_)=>($(d.destination,S,O),f.set(E(h,`onChange.copy[${_}].value`),d.value),d.when&&f.set(E(h,`onChange.copy[${_}].when`),d.when),{value:`=${d.value.value}`,to:d.destination.value,...d.when?{when:`=${d.when.value}`}:{}}))}),w})}function $(O,x,S){let b=O.value.split("."),u=0;if(b[0]==="form")u=x.length-1,b.shift();else if(b[0]==="current")b.shift();else for(;b[0]==="parent";)u+=1,b.shift();let h=x[u]??(u===0?S:void 0);if(!h||!b.length){r.push(I(e,"declaration",`Unsupported copy destination ${O.value}`,O));return}let w=h,m;for(let[d,_]of b.entries()){if(m=w.find(j=>j.id.value===_),!m||m.type==="table")break;if(d<b.length-1){if(m.type!=="object"){m=void 0;break}w=m.children??[]}}(!m||!Ee.has(m.type))&&r.push(I(e,"declaration",`Copy destination must identify an existing editable field: ${O.value}`,O))}let y=v(c,[],[c]);if(r.length)throw new W(r);return{compiled:{id:t.id,version:1,vars:Object.freeze(o),schema:y},ruleRanges:f,nodeRanges:p,formulaFragments:g}}var Be=class{constructor(t){this.source=t,this.offset=0}get eof(){return this.offset>=this.source.length}peek(t=1){return this.source.slice(this.offset,this.offset+t)}skip(t=!0){for(;!this.eof;)if(this.peek()==="#")for(;!this.eof&&this.peek()!==`
|
|
48
|
+
`;)this.offset+=1;else if(/[ \t\r]/.test(this.peek())||t&&this.peek()===`
|
|
49
|
+
`)this.offset+=1;else break}take(t){return this.source.startsWith(t,this.offset)?(this.offset+=t.length,!0):!1}word(){let t=this.offset,r=/^[A-Za-z_][A-Za-z0-9_]*/.exec(this.source.slice(t));if(r)return this.offset+=r[0].length,{value:r[0],start:t,end:this.offset}}number(){let t=this.offset,r=/^\d+/.exec(this.source.slice(t));if(r)return this.offset+=r[0].length,{value:Number(r[0]),start:t,end:this.offset}}string(){let t=this.offset;if(this.peek(3)==='"""')return this.tripleString();if(!this.take('"'))return;let r=!1;for(;!this.eof;){let n=this.peek();if(this.offset+=1,!r&&n==='"'){let i=this.source.slice(t,this.offset);try{return{value:JSON.parse(i),start:t,end:this.offset}}catch{throw Object.assign(new SyntaxError("Invalid quoted string"),{start:t,end:this.offset})}}if(!r&&n===`
|
|
50
|
+
`){this.offset-=1;break}r=!r&&n==="\\",n!=="\\"&&(r=!1)}throw Object.assign(new SyntaxError("Unterminated quoted string"),{start:t,end:this.offset})}tripleString(){let t=this.offset;for(this.offset+=3;this.peek()===" "||this.peek()===" ";)this.offset+=1;if(this.take("\r"),!this.take(`
|
|
51
|
+
`))throw Object.assign(new SyntaxError("Triple-quoted opening delimiter must end its line"),{start:t,end:this.offset});let r=this.offset,n=-1;for(;!this.eof;){let c=this.offset,f=this.source.indexOf(`
|
|
52
|
+
`,c),p=f<0?this.source.length:f;if(this.source.slice(c,p).trim()==='"""'){n=c,this.offset=p;break}this.offset=f<0?this.source.length:f+1}if(n<0)throw Object.assign(new SyntaxError("Unterminated triple-quoted string"),{start:t,end:this.offset});let i=this.source.slice(r,n);i.endsWith(`
|
|
53
|
+
`)&&(i=i.slice(0,-1));let o=i.split(`
|
|
54
|
+
`),a=o.filter(c=>c.trim()).map(c=>/^\s*/.exec(c)?.[0].length??0),s=a.length?Math.min(...a):0;if(i=o.map(c=>c.trim()?c.slice(s):"").join(`
|
|
55
|
+
`),this.source.slice(n,this.offset).trim()!=='"""')throw Object.assign(new SyntaxError("Triple-quoted closing delimiter must be on its own line"),{start:n,end:this.offset});return{value:i,start:t,end:this.offset}}expression(t="line"){this.skip(!1);let r=this.offset,n=0,i=0,o=!1,a;for(;!this.eof;){let l=this.peek();if(a){this.offset+=1,!o&&l===a&&(a=void 0),o=!o&&l==="\\",l!=="\\"&&(o=!1);continue}if(l==='"'||l==="'"){a=l,this.offset+=1;continue}if(l==="("?n+=1:l===")"?n-=1:l==="["?i+=1:l==="]"&&(i-=1),n<0||i<0)throw Object.assign(new SyntaxError("Unbalanced expression delimiter"),{start:r,end:this.offset+1});if(n===0&&i===0&&(t==="arrow"&&this.peek(2)==="->"||t==="otherwise"&&!/[A-Za-z0-9_]/.test(this.source[this.offset-1]??"")&&/^otherwise\b/.test(this.source.slice(this.offset))||l===`
|
|
56
|
+
`||l==="}"||l==="#"))break;this.offset+=1}if(n||i||a)throw Object.assign(new SyntaxError("Unbalanced expression delimiter"),{start:r,end:this.offset});let s=this.offset;for(;s>r&&/\s/.test(this.source[s-1]??"");)s-=1;return{value:this.source.slice(r,s),start:r,end:s}}recover(){for(;!this.eof&&![`
|
|
57
|
+
`,"}"].includes(this.peek());)this.offset+=1;this.peek()===`
|
|
58
|
+
`&&(this.offset+=1)}};var Or=new Set(["select","multi-select","calculated","object","table"]),ei=new Set(["number","group","section"]),Ue=new Set(["form","vars","content","options","required","relevant","validate","otherwise","copy","when",...Or]),ae=class extends Error{};function _r(e){if(typeof e!="string")throw new TypeError("source must be a string");let t=new Be(e),r=[];function n(b,u,h){throw r.push(I(e,b,u,h)),new ae}function i(b,u){t.skip();let h=t.offset;t.take(b)||n("syntax",u,{start:h,end:h+1})}function o(b){t.skip();let u=t.word();return u||n("syntax",b,{start:t.offset,end:t.offset+1}),u}function a(){let b=t.offset;if(t.word()?.value!=="content"||!t.take(".")){t.offset=b;return}let h=t.word();return h||n("syntax","Expected content name",{start:b,end:t.offset}),{kind:"content",name:h.value,start:b,end:h.end}}function s(b,u=!1){t.skip();let h=a();if(h)return h;try{let w=t.string();return w||n("syntax",b,{start:t.offset,end:t.offset+1}),!u&&t.source.slice(w.start,w.start+3)==='"""'&&n("declaration","Triple-quoted content is only supported in the content block",w),{kind:"string",...w}}catch(w){if(w instanceof ae)throw w;let m=w;n("syntax",w instanceof Error?w.message:String(w),{start:m.start??t.offset,end:m.end??t.offset})}}function l(b="line"){try{let u=t.expression(b);return u.value.trim()||n("syntax","Expected expression",u),u}catch(u){if(u instanceof ae)throw u;let h=u;n("syntax",u instanceof Error?u.message:String(u),{start:h.start??t.offset,end:h.end??t.offset})}}function c(){let b=t.offset;i("{","Expected '{' after vars");let u=[];for(;!t.eof;){if(t.skip(),t.take("}"))return{kind:"vars",names:u,start:b,end:t.offset};let h=o("Expected variable name");Ue.has(h.value)&&r.push(I(e,"declaration",`Reserved variable name ${h.value}`,h)),u.push(h)}n("syntax","Unterminated vars block",{start:b,end:t.offset})}function f(){let b=t.offset;i("{","Expected '{' after content");let u=[];for(;!t.eof;){if(t.skip(),t.take("}"))return{kind:"content",entries:u,start:b,end:t.offset};let h=o("Expected content name");Ue.has(h.value)&&r.push(I(e,"declaration",`Reserved content name ${h.value}`,h));let w=s("Expected quoted content",!0);u.push({name:h,value:w,start:h.start,end:w.end})}n("syntax","Unterminated content block",{start:b,end:t.offset})}function p(){let b=t.offset;if(t.skip(),t.take("="))return{kind:"formula",expression:l(),start:b,end:t.offset};i("{","Expected '=' or '{' after options");let u=[];for(;!t.eof;){if(t.skip(),t.take("}"))return{kind:"literal",entries:u,start:b,end:t.offset};let h=t.offset,w;try{w=t.string()}catch(d){let _=d;n("syntax",d instanceof Error?d.message:String(d),{start:_.start??h,end:_.end??t.offset})}w&&t.source.slice(w.start,w.start+3)==='"""'&&n("declaration","Triple-quoted option values are not supported",w),w||(w=o("Expected option value"));let m=s("Expected option label");u.push({value:w,label:m,start:h,end:m.end})}n("syntax","Unterminated options block",{start:b,end:t.offset})}function g(b){t.skip(),t.take("=")||n("syntax","Expected '=' after validate",{start:t.offset,end:t.offset+1});let u=l("otherwise");t.skip(!1),t.word()?.value!=="otherwise"&&n("syntax","Expected 'otherwise' after validation predicate",{start:t.offset,end:t.offset+1});let w=s("Expected validation message");return{predicate:u,message:w,start:b,end:w.end}}function E(b){let u=l("arrow");t.take("->")||n("syntax","Expected '->' in copy declaration",{start:t.offset,end:t.offset+2}),t.skip(!1);let h=t.offset,m=/^(?:[A-Za-z_][A-Za-z0-9_]*)(?:\.[A-Za-z_][A-Za-z0-9_]*)*/.exec(e.slice(t.offset))?.[0];m||n("declaration","Copy destination must be a dotted path",{start:h,end:h+1}),t.offset+=m.length;let d={value:m,start:h,end:t.offset};for(;t.peek()===" "||t.peek()===" "||t.peek()==="\r";)t.offset+=1;if(t.peek()==="#")for(;!t.eof&&t.peek()!==`
|
|
59
|
+
`;)t.offset+=1;t.peek()===`
|
|
60
|
+
`&&(t.offset+=1);let _=t.offset;t.skip(!1);let j=t.word(),R;return j?.value==="when"?(t.skip(),t.take("=")||n("syntax","Expected '=' after when",j),R=l()):t.offset=_,{value:u,destination:d,...R?{when:R}:{},start:b,end:R?.end??d.end}}function v(b){for(i("{",`Expected '{' after ${b.type} declaration`),b.properties=[],b.validations=[],b.copies=[],b.children=[];!t.eof;){if(t.skip(),t.take("}")){b.end=t.offset;return}let u=t.offset;try{if(t.peek()==="*"){b.children.push($());continue}let h=t.word();if(h||n("syntax","Expected declaration",{start:u,end:u+1}),["required","relevant","readOnly"].includes(h.value)){if(t.skip(),!t.take("=")){if(h.value==="readOnly"){t.offset=u,b.children.push($());continue}n("syntax",`Expected '=' after ${h.value}`,h)}b.properties.push({name:h.value,expression:l(),start:u,end:t.offset})}else h.value==="options"?(b.options&&n("declaration","Duplicate options declaration",h),b.options=p()):h.value==="validate"?b.validations.push(g(u)):h.value==="copy"?b.copies.push(E(u)):(t.skip(!1),t.peek()==="="&&n("declaration",`Unsupported property ${h.value}`,h),t.offset=u,b.children.push($()))}catch(h){if(!(h instanceof ae))throw h;t.recover()}}n("syntax",`Unterminated ${b.type} block`,{start:b.start,end:t.offset})}function $(){t.skip();let b=t.offset,u=!1,h=!1;t.take("*")&&(u=!0,h=!0,t.skip(!1));let w;/^multi-select\b/.test(e.slice(t.offset))?(w={value:"multi-select",start:t.offset,end:t.offset+12},t.offset=w.end):w=o("Expected field declaration"),ei.has(w.value)&&n("declaration",`Unsupported declaration type ${w.value}`,w);let m="text";Or.has(w.value)&&(m=w.value,h&&n("declaration","Required marker must immediately precede the field ID",{start:b,end:w.end}),t.skip(),t.take("*")&&(u&&n("declaration","Duplicate required marker",{start:t.offset-1,end:t.offset}),u=!0,t.skip(!1)),w=o("Expected field ID")),Ue.has(w.value)&&n("declaration",`Reserved declaration identifier ${w.value}`,w);let d=w,_;m==="object"||m==="table"?(t.skip(),_=t.peek()==="{"?void 0:s("Expected quoted label or '{'")):_=s("Expected field label");let j={kind:"node",type:m,id:d,label:_,marker:u,start:b,end:_?.end??d.end};return t.skip(),m==="calculated"?(t.take("=")||n("declaration","Calculated field requires '= <expression>'",{start:t.offset,end:t.offset+1}),j.calculate=l(),j.end=j.calculate.end,t.skip(),t.peek()==="{"&&v(j)):m==="object"||m==="table"?v(j):(t.skip(),t.peek()==="{"?v(j):(j.properties=[],j.validations=[],j.copies=[],j.children=[])),j}t.skip();let y=t.offset,A=t.word();A?.value!=="form"&&r.push(I(e,"syntax","Document must begin with 'form 1 <id>'",{start:y,end:A?.end??y+1})),t.skip();let O=t.number();O?O.value!==1&&r.push(I(e,"declaration",`Unsupported language version ${O.value}`,O)):r.push(I(e,"syntax","Expected language version",{start:t.offset,end:t.offset+1})),t.skip();let x=t.word();x?Ue.has(x.value)&&r.push(I(e,"declaration",`Reserved document ID ${x.value}`,x)):r.push(I(e,"syntax","Expected document ID",{start:t.offset,end:t.offset+1})),t.recover();let S=[];for(;!t.eof&&(t.skip(),!t.eof);){let b=t.offset;if(t.peek()==="*"){try{S.push($())}catch(h){if(!(h instanceof ae))throw h;t.recover()}continue}let u=t.word();if(!u){r.push(I(e,"syntax","Unexpected token",{start:b,end:b+1})),t.peek()==="}"?t.offset+=1:t.recover();continue}try{u.value==="vars"?S.push(c()):u.value==="content"?S.push(f()):(t.offset=b,S.push($()))}catch(h){if(!(h instanceof ae))throw h;t.recover()}}if(r.length)throw new W(r);return{id:x?.value??"",version:1,declarations:S,start:y,end:e.length}}function ti(e){let t=_r(e),r=kr(e,t);try{let n=ve({schema:r.compiled.schema,varsShape:pr(r.compiled.vars),executable:!1,locateFormulaError:Sr(r)});return{...r,compiled:{...r.compiled,schema:n},document:t}}catch(n){throw jr(e,r,n)}}function Cr({source:e,data:t={},vars:r={}}){let n=ti(e);if(r===null||typeof r!="object"||Array.isArray(r))throw new W([I(e,"vars","vars must be a JSON-compatible object",n.document)]);let i=n.document.declarations.find(s=>s.kind==="vars"),o=[];for(let s of n.compiled.vars)if(!Object.hasOwn(r,s)){let l=i?.names.find(c=>c.value===s)??n.document;o.push(I(e,"vars",`Missing declared var ${s}`,l))}if(o.length)throw new W(o);let a;try{a=de(r)}catch(s){throw $r(e,n,s)}try{ve({schema:n.compiled.schema,data:t,varsShape:pe(a),executable:!1,locateFormulaError:Sr(n)})}catch(s){throw $r(e,n,s)}try{return Er({schema:n.compiled.schema,data:t,vars:a})}catch(s){throw s instanceof W?s:jr(e,n,s)}}function Sr(e){return t=>{let r=`${JSON.stringify(t.schemaPath)}:${t.property}`;for(let n of e.formulaFragments.get(r)??[])try{t.check(n.formula)}catch(i){return{cause:i,location:n.range}}}}function $r(e,t,r){let n=t.document.declarations.find(i=>i.kind==="vars");return new W([I(e,"vars",r instanceof Error?r.message:String(r),n??t.document)],{cause:r})}function jr(e,t,r){let n=r,i=n.schemaPath&&n.property?`${JSON.stringify(n.schemaPath)}:${n.property}`:void 0,o=n.preparationLocation??(i?t.ruleRanges.get(i):void 0);!o&&n.schemaPath&&(o=t.nodeRanges.get(JSON.stringify(n.schemaPath)));let a=o??t.document??{start:0,end:e.length},s=typeof n.offset=="number"?Math.min(a.end,a.start+n.offset):a.start,l=n.schemaPath&&n.property?"expression":"schema";return new W([I(e,l,n.message??String(r),{start:s,end:typeof n.offset=="number"?Math.min(a.end,s+1):a.end})],{cause:r})}var ke=new WeakMap,Oe=new WeakMap;function ri(e){let t=ke.get(e);if(t){for(let n of t)n.elem.removeEventListener(n.type,n.listener,n.capture);ke.delete(e)}let r=Oe.get(e);if(r){for(let n of r)n();Oe.delete(e)}}function Ot(e){let t=Array.from(e.childNodes);ri(e),t.forEach(r=>{Ot(r)})}var F={clear(e){for(Array.from(e.childNodes).forEach(t=>Ot(t));e.firstChild;)e.removeChild(e.firstChild)},remove(e){Ot(e),e.parentNode?.removeChild(e)},append(e,t){typeof t=="string"?e.appendChild(document.createTextNode(t)):Array.isArray(t)?t.forEach(r=>e.appendChild(r)):e.appendChild(t)},set(e,t){return this.clear(e),this.append(e,t)},addCleanup(e,t){Oe.has(e)?Oe.get(e).push(t):Oe.set(e,[t])},subscribe(e,t,r){this.addCleanup(e,t.subscribe(r))},addEventListener(e,t,r,n){let i=typeof n=="boolean"?n:!!n?.capture;e.addEventListener(t,r,n);let o=e;return ke.has(o)?ke.get(o).push({elem:e,type:t,listener:r,capture:i}):ke.set(o,[{elem:e,type:t,listener:r,capture:i}]),o}},te=class{constructor(){this._listeners=[]}get(){throw new Error("Watchable#get() is abstract; override in subclass")}_notify(e){this._listeners.forEach(t=>t(e))}notify(){this._notify(this.get())}subscribe(e){return this._listeners.push(e),()=>{this._listeners=this._listeners.filter(t=>t!==e)}}},Dr=class extends te{constructor({r:e,w:t}){super(),this._reader=e,this._writer=t}get(){return this._reader()}set(e){this._writer(e),this._notify(this.get())}orElse(e){return this.get()||e}orElseGet(e){return this.get()||e()}toString(){return this.get()}},ni=class extends te{constructor(e){super(),this._unsubs=e.map(t=>t.subscribe(r=>{this._notify(t)}))}subscribe(e){let t=super.subscribe(e);return()=>{t(),this._listeners.length===0&&(this._unsubs.forEach(r=>r()),this._unsubs=[])}}};function G(e,t=void 0){return t===void 0?ii(e):new Dr({r:()=>e[t],w:r=>e[t]=r})}function ii(e){return new Dr({r:()=>e,w:t=>e=t})}function Pr(...e){return new ni(e)}var oi=class extends te{constructor(e,t){super(),this._fn=e,this._sources=t,this._unsubs=[]}get(){return this._fn()}orElse(e){return this.get()||e}orElseGet(e){return this.get()||e()}toString(){return this.get()}subscribe(e){this._listeners.length===0&&(this._unsubs=this._sources.map(r=>r.subscribe(()=>this._notify(this.get()))));let t=super.subscribe(e);return()=>{t(),this._listeners.length===0&&(this._unsubs.forEach(r=>r()),this._unsubs=[])}}};function z(e,...t){return new oi(e,t)}var Ve={capture:!0};function ai(e,t,r){let n=t(r);return F.subscribe(e,r,()=>{let i=t(r);F.set(e,i)}),F.set(e,n),e}function si(e,t,r="change"){return e.checked=t.get(),F.addEventListener(e,r,n=>t.set(n.target.checked),Ve),F.subscribe(e,t,n=>e.checked=n),e}function li(e,t,r="change"){return e.checked=t.get()===e.value,F.addEventListener(e,r,n=>t.set(n.target.value),Ve),F.subscribe(e,t,n=>{e.checked=n===e.value}),e}function ci(e){if(!(e instanceof te)||!("set"in e)||typeof e.set!="function")throw new TypeError("bind.ref must be a writable Watchable")}function ui(e){if(!(e instanceof te))throw new TypeError("bind.source must be a Watchable")}function fi({ref:e,source:t,read:r}){if(r!==void 0&&t===void 0)throw new TypeError("bind.read requires bind.source");if(r!==void 0&&typeof r!="function")throw new TypeError("bind.read must be a function");if(t!==void 0&&ui(t),r!==void 0&&t===e)throw new TypeError("bind.read requires bind.source and bind.ref to be different Watchables")}function Ir(e,t="text"){let r=pi(e),{ref:n,source:i,read:o}=r;if(ci(n),t==="checkbox"||t==="radio"){if(i!==void 0||o!==void 0)throw new TypeError("bind.source and bind.read are only supported for scalar value controls")}else fi(r);return r}function di(e,{ref:t,source:r,read:n,event:i="input"}){let o=r??t,a=n??(E=>E),s,l=!1,c=0,f=E=>{let v=a(E);e.value=v??"",s=e.value,l=!1,c++},p=()=>{l=e.value!==s},g=()=>{if(p(),!l)return;let E=e.value,v=c;t.set(E),c===v&&(s=E,l=!1)};return f(o.get()),F.subscribe(e,o,f),i==="input"?F.addEventListener(e,"input",g,Ve):(F.addEventListener(e,"input",p),F.addEventListener(e,i,g,Ve)),e}function pi(e){return e&&"ref"in e?e:{ref:e}}function hi(e,t){if(e.type==="file")throw new TypeError("File input binding is unsupported");if(e.type==="select-multiple")throw new TypeError("Multiple-select binding is unsupported");let r=e.type==="checkbox"||e.type==="radio"?e.type:"text",n=Ir(t,r),{ref:i,event:o}=n;switch(e.type){case"checkbox":return si(e,i,o);case"radio":return li(e,i,o);default:return di(e,n)}}function mi(...e){let t=[];for(let r=0;r<e.length;r=r+2){let n=e[r],i=e[r+1];if(!$t(At,_t)(n))throw new Error("matcher at ["+r+"] must be a list of functions or a single function");if(!_t(i))throw new Error("func at ["+(r+1)+"] must be a function");let o=n.filter(l=>!l.__isVarg).length,a=o<n.length,s=l=>(a?l.length>=o:l.length===o)&&n.every((c,f)=>c.__isVarg?c(l.slice(f)):c(l[f]));t.push({isMatch:s,func:i})}return(...r)=>{for(let n=0;n<t.length;n++){let i=t[n];if(i.isMatch(r))return i.func(...r)}throw new Error("no function found that can handle the arguments: "+r)}}var he=e=>t=>typeof t===e,bi=e=>e instanceof Map,At=e=>Array.isArray(e),_t=he("function"),yi=he("number"),wi=he("string"),gi=he("boolean"),vi=he("symbol"),Ei=he("bigint"),Rr=e=>e===void 0,Nr=e=>e===null,xe=e=>Rr(e)||Nr(e),Ar=e=>!xe(e),xi=e=>typeof e=="object"&&!Nr(e)&&!At(e),Tr=(...e)=>t=>e.every(r=>r(t)),$t=(...e)=>t=>e.some(r=>r(t)),ki=e=>t=>!e(t),Oi=e=>Object.assign(t=>e?t.every(e):!0,{__isVarg:!0}),_i=e=>t=>t instanceof e,$i=()=>!0,T={arr:()=>At,map:()=>bi,any:()=>$i,func:()=>_t,num:()=>yi,str:()=>wi,bool:()=>gi,bigint:()=>Ei,sym:()=>vi,undef:()=>Rr,obj:()=>xi,nil:e=>xe(e)?xe:$t(xe,e),notNil:e=>xe(e)?Ar:Tr(Ar,e),matcher:mi,rest:Oi,eq:e=>t=>t===e,or:$t,and:Tr,not:ki,instOf:_i};function Ci(){return Math.random().toString(36).substring(7)}var qr=T.instOf(te),Lr=T.func(),Si=class extends te{constructor(e){super(),this.value=e}get(){return this.value}subscribe(e){return this.disposed?()=>{}:super.subscribe(e)}_publish(e){this.disposed||(this.value=e,this._notify(e))}_dispose(){this.disposed||(this.disposed=!0,this.value=void 0,this._listeners=[])}};function ji(e,t,r,n){t.id||(t.id=Ci);let[i,o]=r,a=qr(i)?i:G(i),s=Lr(t.id)?t.id:g=>g[t.id],l=new Map,c=g=>(l.get(g)||l.set(g,s(g)),g),f=g=>l.get(g),p=(g,E)=>{let v=e(o(g,E),n);return v.dataset.__vid=f(g),v};return F.subscribe(n,a,()=>{let g=a.get(),E=new Set(g),v=new Map(g.map(y=>(c(y),[f(y),y])));for(let y of l.keys())E.has(y)||l.delete(y);let $=n.childNodes;for(let y=$.length-1;y>=0;y--){let A=$[y];v.has(A.dataset.__vid)||F.remove(A)}for(let y=0;y<g.length;y++){let A=g[y],O=$[y];O?O.dataset.__vid!==f(A)&&n.insertBefore(p(A,y),O):n.appendChild(p(A,y))}}),a.get().map((g,E)=>p(c(g),E))}function Ai(e,t,r,n){if(!Object.prototype.hasOwnProperty.call(t,"id"))throw new Error("foreach resource mode requires an explicit id selector");let[i,o]=r,a=qr(i)?i:G(i),s=Lr(t.id)?t.id:y=>y[t.id],l=new Map,c=document.createComment("foreach:start"),f=document.createComment("foreach:end"),p=y=>{let A=y.map((x,S)=>({item:x,index:S,key:s(x)})),O=new Set;for(let{key:x}of A){if(x==null)throw new Error("foreach resource mode id selector returned a null or undefined key");if(O.has(x))throw new Error("foreach requires unique keys");O.add(x)}return A},g=y=>y.resource._dispose(),E=(y,A,O)=>{let x=new Si(y),S=e(o(y,A,x),n);S.dataset.__vid=String(O);let b={node:S,resource:x};return l.set(O,b),b},v=()=>{let y=f.parentNode;if(!y||c.parentNode!==y)return;let A=p(a.get()),O=new Set(A.map(({key:S})=>S));for(let[S,b]of l)O.has(S)||(l.delete(S),F.remove(b.node),g(b));let x=c.nextSibling;A.forEach(({item:S,index:b,key:u})=>{let h=l.get(u);h?h.resource._publish(S):h=E(S,b,u),h.node!==x&&y.insertBefore(h.node,x),x=h.node.nextSibling})},$=p(a.get()).map(({item:y,index:A,key:O})=>E(y,A,O).node);return F.subscribe(f,a,v),F.addCleanup(f,()=>{for(let y of l.values())g(y);l.clear()}),[c,...$,f]}function Ti(e,t,r,n){return t.resource===!0?Ai(e,t,r,n):ji(e,t,r,n)}var Di=e=>({__condaReactiveText:e}),Pi=e=>({__condaReactiveProperty:e}),Ii=e=>({__condaReactiveAttribute:e}),Et=(e,t)=>t===void 0?e:z(()=>t(e.get()),e),D=Object.freeze({text:(e,t)=>Di(Et(e,t)),prop:(e,t)=>Pi(Et(e,t)),attr:(e,t)=>Ii(Et(e,t))}),Ct=e=>e?.__condaReactiveText,Mr=e=>e?.__condaReactiveProperty,Fr=e=>e?.__condaReactiveAttribute,Ri=T.or(T.str(),T.num(),T.bool(),T.bigint(),T.sym()),xt={text:{event:"input"},checkbox:{event:"change"},radio:{event:"change"}},Ni=new Set(["button","checkbox","color","date","datetime-local","email","file","hidden","image","month","number","password","radio","range","reset","search","submit","tel","text","time","url","week"]),qi=new Set(["hidden","button","submit","reset","image"]),kt=T.and(T.obj(),T.not(T.or(T.instOf(te),T.instOf(jt),T.instOf(HTMLElement),T.instOf(DocumentFragment),e=>!!Ct(e)))),Li=T.matcher([T.str()],e=>({attrs:{},children:[]}),[T.str(),kt],(e,t)=>({attrs:t,children:[]}),[T.str(),kt,T.instOf(jt)],(e,t,r)=>({attrs:t,children:r._elems}),[T.str(),kt,T.rest()],(e,t,...r)=>({attrs:t,children:[...r]}),[T.str(),T.instOf(jt)],(e,t)=>({attrs:{},children:t._elems}),[T.str(),T.rest()],(e,...t)=>({attrs:{},children:[...t]}));function Mi(e={}){let t=e.bindings??{};return{bindings:{text:{...xt.text,...t.text},checkbox:{...xt.checkbox,...t.checkbox},radio:{...xt.radio,...t.radio}}}}function St(e){let t=Mr(e),r=Fr(e),n=t??r;return n?n.get():e}function Fi(e){if(!("type"in e))return"text";let t=String(St(e.type)).toLowerCase();return Ni.has(t)?t:"text"}function Bi(e,t){let r=e.tagName?.toLowerCase();if(r==="input"){let n=Fi(t);return n==="file"?{kind:"unsupported",type:n}:n==="checkbox"||n==="radio"?{kind:n,type:n}:{kind:qi.has(n)?"native":"scalar",type:n}}return r==="textarea"?{kind:"scalar"}:r==="select"?{kind:St(t.multiple)?"unsupported":"scalar",type:St(t.multiple)?"multiple":"single"}:{kind:"other"}}function Ui(e,t,r){let n=Bi(t,e),i=Object.prototype.hasOwnProperty.call(e,"value"),o=Object.prototype.hasOwnProperty.call(e,"bind");if(n.kind==="scalar"&&i)throw new TypeError("Editable scalar controls cannot declare value; use bind instead");if(n.kind==="unsupported"&&o)throw new TypeError(n.type==="file"?"File input binding is unsupported":"Multiple-select binding is unsupported");if(!o)return null;let a=n.kind==="checkbox"||n.kind==="radio"?n.kind:"text";return Ir(Vi(e.bind,r.bindings[a]),a)}function Vi(e,t){return e&&"ref"in e?{...t,...e}:{...t,ref:e}}function ze(e){let t=Mi(e);function r(a,s){return a.map(l=>o(l,s)).flat()}function n(a,s){let l=Ui(a,s,t);for(let c of Object.keys(a)){if(c==="bind")continue;let f=Mr(a[c]),p=Fr(a[c]);if(f)s[c]=f.get(),F.subscribe(s,f,g=>s[c]=g);else if(p){let g=E=>E==null||E===!1?s.removeAttribute(c):s.setAttribute(c,String(E));g(p.get()),F.subscribe(s,p,g)}else c==="onmount"?queueMicrotask(()=>a[c](s)):c.startsWith("on")?F.addEventListener(s,c.substring(2).toLowerCase(),a[c]):c in s?s[c]=a[c]:s.setAttribute(c,a[c])}return l&&(()=>hi(s,l))}function i(a,s){let{attrs:l,children:c}=Li.apply(null,a),f=l.watch;Array.isArray(f)&&(f=Pr(...f)),delete l.watch;let p=a[0],g;switch(p){case"foreach":return Ti(o,l,c,s);case"frag":g=document.createDocumentFragment();break;default:g=document.createElement(p)}let E=n(l,g);if(f)ai(g,()=>r(c,g),f);else for(let v of r(c,g))g.appendChild(v);return E?.(),g}let o=T.matcher([T.and(T.obj(),a=>!!Ct(a)),T.any()],a=>{let s=Ct(a),l=document.createTextNode(s.get());return F.subscribe(l,s,c=>l.data=c),l},[Ri,T.any()],(a,s)=>document.createTextNode(a),[T.func(),T.any()],(a,s)=>o(a(),s),[T.or(T.instOf(HTMLElement),T.instOf(DocumentFragment)),T.any()],(a,s)=>a,[T.instOf(te),T.any()],(a,s)=>o(a.get(),s),[T.any(),T.any()],(a,s)=>i(a,s),[T.any()],a=>i(a,null));return{render:o}}var zi=ze(),Wi=zi.render,Tt=new Proxy({},{get(e,t){return(...r)=>[t,...r]}});function jt(e){this._elems=e}function Dt(e){F.remove(e)}function re(e,t,r){let n=We(e),i=r.map(We).join(".");return`umbika-${n}-${t}-${i}`}function V(e,t,r){let n=We(e),i=r.map(We).join(".");return`umbika-${n}-${t}-${i}`}function _e(e){return e.path.map(t=>`${t.length}:${t}`).join("|")}function We(e){return encodeURIComponent(e).replaceAll(".","%2E")}function Br(e,t){if(e===void 0)return Object.freeze({tables:Object.freeze([])});if(!Pt(e))throw new TypeError("layout must be an object");if(e.tables!==void 0&&!Array.isArray(e.tables))throw new TypeError("layout.tables must be an array");let r=new Set,n=(e.tables??[]).map((i,o)=>{let a=`layout table ${o+1}`;if(!Pt(i))throw new TypeError(`${a} must be an object`);let s=zr(i.path,`${a} path`),l=Ke(s);if(r.has(l))throw new TypeError(`${a} duplicates ${Je(s)}`);r.add(l);let c=Vr(t,s,`${a} path`);if(c.type!=="table")throw new TypeError(`${a} path ${Je(s)} must identify a table`);if(i.mode!=="cards"&&i.mode!=="table")throw new TypeError(`${a} mode must be "cards" or "table"`);let f=Ki(i.columns,c.children,a);return Object.freeze({path:s,mode:i.mode,columns:f})});return Object.freeze({tables:Object.freeze(n)})}function Ur(e){if(e===void 0)return"default";if(typeof e!="string"||!/^[A-Za-z][A-Za-z0-9_-]*$/.test(e))throw new TypeError("theme must start with a letter and contain only letters, numbers, hyphens, or underscores");return e}function me(e,t){let r=Ke(t);return e.tables.find(n=>Ke(n.path)===r)}function Ki(e,t,r){if(e===void 0)return;if(!Array.isArray(e))throw new TypeError(`${r} columns must be an array`);if(e.length===0||e.length>4)throw new TypeError(`${r} columns must contain one to four entries`);let n=new Set;return Object.freeze(e.map((i,o)=>{let a=`${r} column ${o+1}`;if(!Pt(i))throw new TypeError(`${a} must be an object`);let s=zr(i.path,`${a} path`),l=Ke(s);if(n.has(l))throw new TypeError(`${a} duplicates ${Je(s)}`);n.add(l);let c=Vr(t,s,`${a} path`);if(c.type==="object"||c.type==="table")throw new TypeError(`${a} must identify a summary field`);if(i.label!==void 0&&(typeof i.label!="string"||i.label.trim()===""))throw new TypeError(`${a} label must be a non-empty string`);if(i.align!==void 0&&i.align!=="start"&&i.align!=="center"&&i.align!=="end")throw new TypeError(`${a} align must be "start", "center", or "end"`);return Object.freeze({key:l,path:s,label:i.label??c.label,align:i.align??"start"})}))}function Vr(e,t,r){let n=e,i;for(let o of t){if(i=n.find(a=>a.id===o),!i)throw new TypeError(`${r} ${Je(t)} does not exist`);n=i.type==="object"||i.type==="table"?i.children:[]}return i}function zr(e,t){if(!Array.isArray(e)||e.length===0||e.some(r=>typeof r!="string"||r.trim()===""))throw new TypeError(`${t} must be a non-empty path of non-empty strings`);return Object.freeze([...e])}function Ke(e){return e.map(t=>`${t.length}:${t}`).join("|")}function Je(e){return JSON.stringify(e)}function Pt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var Ji=Tt,{article:Wr,button:Z,caption:Kr,dialog:Jr,div:U,fieldset:He,foreach:X,form:Hr,frag:Xr,h2:Qr,h3:Zr,input:Xe,label:Qe,legend:Ze,li:Yr,option:It,output:Gr,p:fe,section:en,select:tn,ul:rn,table:nn,tbody:on,td:Rt,th:Nt,thead:an,tr:qt}=Ji;function se(e,t,r){let n=re(e,"control",t.path),i=re(e,"description",t.path),o=re(e,"errors",t.path);return{control:n,describedBy:`${i} ${o}`,label:Qe({class:"umbika-field__label",for:n},D.text(r,a=>a&&"label"in a?a.label:"")),legend:Ze({class:"umbika-field__label"},D.text(r,a=>a&&"label"in a?a.label:"")),descriptionId:i,errors:$e(o,r)}}function $e(e,t){return rn({id:e,class:"umbika-field__errors","aria-live":"polite",watch:t},()=>Xr(...(t.get()?.errors??[]).map(r=>Yr(r.message))))}function le(e,t){return fe({id:e,class:"umbika-field__description"},t)}function Ce(e){return e==null||e===""?"\u2014":String(e)}function sn(e,t){let r=e.get();if(!r||r.type!=="object")return"";let n=V(t.instanceId,"errors",r.path),i=z(()=>{let o=e.get();return o?.type==="object"?o.children:[]},e);return He({id:V(t.instanceId,"object",r.path),class:"umbika-object","data-umbika-kind":"object","aria-describedby":n,tabindex:"-1","data-umbika-invalid":D.attr(e,o=>o?.type==="object"&&o.errors.length>0?"true":"false")},Ze({class:"umbika-object__heading"},D.text(e,o=>o?.type==="object"?o.label??o.id:"")),$e(n,e),t.renderNodes(i,t.definitionPath))}function ln(e,t){let r=e.get();if(!r||r.type!=="multi-select")return"";let n=se(t.instanceId,r,e),i=z(()=>Qi(e.get()),e);return He({id:n.control,class:"umbika-field umbika-multi-select","data-umbika-kind":"multi-select","data-umbika-required":D.attr(e,o=>String(o?.type==="multi-select"&&o.required)),"data-umbika-invalid":D.attr(e,o=>String(o?.type==="multi-select"&&o.errors.length>0)),"aria-invalid":D.attr(e,o=>String(o?.type==="multi-select"&&o.errors.length>0)),"aria-describedby":n.describedBy},n.legend,le(n.descriptionId,"Choose any options that apply"),U({class:"umbika-multi-select__choices"},X({id:"value",resource:!0},i,(o,a,s)=>Hi(r.path,o,s,e,t))),Z({type:"button",class:"umbika-action umbika-multi-select__clear",hidden:D.prop(e,o=>o?.type!=="multi-select"||o.required),disabled:D.prop(e,o=>o?.type!=="multi-select"||!Array.isArray(o.value)||o.value.length===0),onclick:()=>{let o=e.get();!o||o.type!=="multi-select"||o.required||t.commitMultiSelect?.(o.path,[])}},"Clear selection"),n.errors)}function Hi(e,t,r,n,i){let o=re(i.instanceId,"choice",[...e,t.value]);return Qe({class:D.attr(r,a=>a?.unavailable?"umbika-multi-select__choice umbika-multi-select__choice--unavailable":"umbika-multi-select__choice"),"data-umbika-choice":t.value,"data-umbika-unavailable":D.attr(r,a=>String(a?.unavailable===!0)),for:o},Xe({id:o,class:"umbika-field__control umbika-multi-select__control",type:"checkbox",value:t.value,checked:D.prop(n,a=>a?.type==="multi-select"&&Array.isArray(a.value)?a.value.includes(t.value):!1),onchange:a=>{let s=n.get(),l=a.currentTarget;if(!s||s.type!=="multi-select"||!(l instanceof HTMLInputElement))return;let c=t.value,f=Xi(s.value,c,l.checked);i.commitMultiSelect?.(s.path,f)}}),D.text(r,a=>a?`${a.label}${a.unavailable?" \u2014 unavailable":""}`:""))}function Xi(e,t,r){let n=Array.isArray(e)?e.filter((i,o,a)=>typeof i=="string"&&a.indexOf(i)===o):[];return r?n.includes(t)?n:[...n,t]:n.filter(i=>i!==t)}function Qi(e){if(!e||e.type!=="multi-select")return[];let t=new Set(e.options.map(i=>i.value)),r=e.options.map(i=>Object.freeze({...i,unavailable:!1}));if(!Array.isArray(e.value))return r;let n=new Set(t);for(let i of e.value)typeof i!="string"||n.has(i)||(n.add(i),r.push(Object.freeze({value:i,label:i,unavailable:!0})));return r}function un(e,t){let r=e.get();if(!r||!("value"in r))return"";let n=r.type==="calculated",i=se(t.instanceId,r,e);return U({class:n?"umbika-field umbika-field--calculated":"umbika-field","data-umbika-kind":r.type,"data-umbika-readonly":"true"},i.label,le(i.descriptionId,n?"Calculated automatically":"Read only"),Gr({id:i.control,class:n?"umbika-calculated":"umbika-field__output",tabindex:"-1","aria-live":"polite","aria-invalid":D.attr(e,o=>String(o&&"value"in o&&o.errors.length>0)),"aria-describedby":i.describedBy},D.text(e,o=>o&&"value"in o?Zi(o):"")),i.errors)}function Zi(e){return e.type==="select"&&typeof e.value=="string"&&e.value!==""?cn(e.options,e.value):e.type==="multi-select"&&Array.isArray(e.value)?Ce(e.value.map(t=>cn(e.options,t)).join(", ")):Ce(e.value)}function cn(e,t){return e.find(r=>r.value===t)?.label??`${String(t)} (unavailable)`}function dn(e,t){let r=e.get();if(!r||r.type!=="select")return"";let n=se(t.instanceId,r,e),i=G(fn(r.value)),o=z(()=>{let a=e.get();return a?.type==="select"?a.options:[]},e);return i.subscribe(a=>{let s=e.get();!s||s.type!=="select"||t.commitSelect?.(s.path,String(a)===""?void 0:s.options.find(l=>l.value===String(a)))}),U({class:"umbika-field","data-umbika-kind":"select"},n.label,le(n.descriptionId,"Choose one option"),tn({id:n.control,class:"umbika-field__control",bind:{ref:i,source:e,read:a=>a?.type==="select"?fn(a.value):"",event:"change"},required:D.prop(e,a=>a?.type==="select"?a.required:!1),"aria-required":D.attr(e,a=>String(a?.type==="select"&&a.required)),"aria-invalid":D.attr(e,a=>String(a?.type==="select"&&a.errors.length>0)),"aria-describedby":n.describedBy},It({value:""},"Select\u2026"),X({id:"value",resource:!0},o,(a,s,l)=>It({value:a.value},D.text(l,c=>c?.label??"")))),n.errors)}function fn(e){return e==null?"":String(e)}function Ye(e){let t=0;for(let r of e)if(t+=r.errors.length,r.type==="object")t+=Ye(r.children);else if(r.type==="table")for(let n of r.rows)t+=Ye(n.children);return t}function Ge(e,t){if(t)return t;let r=[],n=new Set;for(let i of e)if(pn(i.children,[],r,n),r.length===4)break;return r}function et(e,t){let r=hn(e.children,t);if(!r)return{available:!1,display:"\u2014"};let n=Yi(r);return{available:!0,display:Ce(n)}}function tt(e,t){for(let r of t){let n=et(e,r.path);if(n.available)return n}return{available:!1,display:"row"}}function pn(e,t,r,n){for(let i of e){if(r.length===4)return;let o=[...t,i.id];if(i.type==="object"){pn(i.children,o,r,n);continue}if(i.type==="table")continue;let a=Gi(o);n.has(a)||(n.add(a),r.push(Object.freeze({key:a,path:Object.freeze(o),label:i.label,align:"start"})))}}function hn(e,t){let[r,...n]=t;if(r===void 0)return;let i=e.find(o=>o.id===r);if(i)return n.length>0?i.type==="object"?hn(i.children,n):void 0:i.type==="text"||i.type==="select"||i.type==="multi-select"||i.type==="calculated"?i:void 0}function Yi(e){return e.type==="select"?e.options.find(t=>t.value===e.value)?.label??e.value:e.type!=="multi-select"||!Array.isArray(e.value)?e.value:e.value.map(t=>typeof t=="string"?e.options.find(r=>r.value===t)?.label??`${t} (unavailable)`:String(t)).join(", ")}function Gi(e){return e.map(t=>`${t.length}:${t}`).join("|")}function mn(e,t){let r=e.get();if(!r||r.type!=="table")return"";let n=r.label??r.id,i=V(t.instanceId,"table-title",r.path),o=V(t.instanceId,"add-row",r.path),a=V(t.instanceId,"table-errors",r.path),s=me(t.layout,t.definitionPath),l=s?.mode??"cards",c=z(()=>{let p=e.get();return p?.type==="table"?p.rows:[]},e),f=z(()=>{let p=e.get();return Ge(p?.type==="table"?p.rows:[],s?.columns)},e);return en({id:V(t.instanceId,"table",r.path),class:l==="table"?"umbika-table umbika-table--summary":"umbika-table","data-umbika-kind":"table","aria-labelledby":i,"aria-describedby":a,tabindex:"-1","data-umbika-invalid":D.attr(e,p=>p?.type==="table"&&p.errors.length>0?"true":"false")},Qr({id:i,class:"umbika-table__heading"},D.text(e,p=>p?.type==="table"?p.label??p.id:"")),l==="table"?to(e,c,f,n,t):eo(c,n,t),fe({class:"umbika-table__empty"},D.text(e,p=>p?.type==="table"&&p.rows.length===0?`No ${n} rows.`:"")),$e(a,e),Z({id:o,class:"umbika-table__add-row",type:"button","aria-label":`Add row to ${n}`,onclick:()=>{let p=e.get();p?.type==="table"&&t.appendRow?.(p.path,l==="table",o,t.definitionPath)}},"Add row"))}function eo(e,t,r){return U({class:"umbika-table__rows"},X({id:_e,resource:!0},e,(n,i,o)=>{let a=z(()=>o.get()?.children??[],o);return Wr({id:V(r.instanceId,"row",n.path),class:"umbika-table__row","data-umbika-row-id":n.id,"aria-label":`${t} row`},U({class:"umbika-table__fields"},r.renderNodes(a,r.definitionPath)),Z({class:"umbika-table__remove-row",type:"button","aria-label":`Remove row from ${t}`,onclick:()=>{let s=o.get();s&&r.removeRow?.(s.path)}},"Remove row"))}))}function to(e,t,r,n,i){return U({class:"umbika-data-table__overflow"},nn({class:"umbika-data-table"},Kr({class:"umbika-visually-hidden"},n),an(qt(X({id:"key",resource:!0},r,(o,a,s)=>Nt({scope:"col","data-umbika-align":D.attr(s,l=>l?.align??"start")},D.text(s,l=>l?.label??""))),Nt({scope:"col",class:"umbika-data-table__actions"},"Actions"))),on(X({id:_e,resource:!0},t,(o,a,s)=>ro(o,s,e,r,n,i)))))}function ro(e,t,r,n,i,o){let a=V(o.instanceId,"row",e.path),s=V(o.instanceId,"edit-row",e.path),l=V(o.instanceId,"row-errors",e.path),c=z(()=>Ye(t.get()?.children??[]),t),f=p=>{let g=t.get();g&&o.openRow?.(g.path,p,o.definitionPath)};return qt({id:a,class:"umbika-data-table__row","data-umbika-row-id":e.id,"aria-describedby":l,"data-umbika-invalid":D.attr(c,p=>p>0?"true":"false")},X({id:"key",resource:!0},n,(p,g,E)=>Rt({"data-umbika-align":D.attr(E,v=>v?.align??"start"),"aria-label":D.attr(t,v=>v&&et(v,p.path).available?null:"Unavailable")},D.text(t,v=>v?et(v,p.path).display:"\u2014"))),Rt({class:"umbika-data-table__actions"},fe({id:l,class:"umbika-data-table__row-errors","aria-live":"polite"},D.text(c,p=>p>0?`${p} ${p===1?"error":"errors"}`:"")),Z({id:s,type:"button",class:"umbika-data-table__edit","aria-label":D.attr(t,p=>p?no(p,n.get(),i):`Edit row in ${i}`),"aria-describedby":l,onclick:()=>f(s)},"Edit")))}function no(e,t,r){let n=tt(e,t);return n.available?`Edit ${n.display} in ${r}`:`Edit row in ${r}`}function yn(e,t){let r=e.get();if(!r||r.type!=="text")return"";let n=se(t.instanceId,r,e),i=G(bn(r.value));return i.subscribe(o=>{let a=e.get();!a||a.type!=="text"||t.setText?.(a.path,String(o))}),U({class:"umbika-field","data-umbika-kind":"text"},n.label,le(n.descriptionId,"Text response"),Xe({id:n.control,class:"umbika-field__control",type:"text",bind:{ref:i,source:e,read:o=>o?.type==="text"?bn(o.value):"",event:"blur"},required:D.prop(e,o=>o?.type==="text"?o.required:!1),"aria-required":D.attr(e,o=>String(o?.type==="text"&&o.required)),"aria-invalid":D.attr(e,o=>String(o?.type==="text"&&o.errors.length>0)),"aria-describedby":n.describedBy,onblur:()=>{let o=e.get();!o||o.type!=="text"||t.touchText?.(o.path)}}),n.errors)}function bn(e){return e==null?"":String(e)}function Lt(e,t,r=[]){return X({id:n=>`${"readOnly"in n&&n.readOnly?"output:":""}${_e(n)}`,resource:!0},e,(n,i,o)=>{let a=Object.freeze({...t,definitionPath:Object.freeze([...r,n.id])});return io(o,a)})}function io(e,t){let r=e.get();if(!r)return"";if(r.type==="calculated"||"readOnly"in r&&r.readOnly)return un(e,t);switch(r.type){case"object":return sn(e,t);case"table":return mn(e,t);case"text":return yn(e,t);case"select":return dn(e,t);case"multi-select":return ln(e,t);default:return oo(r)}}function oo(e){let t=typeof e=="object"&&e!==null&&"type"in e?String(e.type):"unknown";throw new TypeError(`Unsupported active node type: ${t}`)}function wn(e,t){return Mt(e,t,[],[])}function gn(e,t){if(!t)return null;let r=[];for(let n of t.frames){if(!wn(e,n.rowPath))break;r.push(n)}return r.length>0?Object.freeze({frames:Object.freeze(r)}):null}function ao(e,t,r){if(!t?.frames.length)return null;let n=[];for(let l of t.frames){let c=wn(e,l.rowPath);if(!c)break;let f=Ge([c.row],me(r,c.definitionPath)?.columns),p=tt(c.row,f);n.push({detail:c,frame:l,primary:p})}let i=n.at(-1);if(!i)return null;let o=`${i.detail.tableName} row`,a=i.primary.available?i.primary.display:o,s=i.frame.origin==="new";return Object.freeze({current:Object.freeze({...i,name:a}),depth:n.length,title:s?`Add row to ${i.detail.tableName}`:`Edit ${a}`,trail:Object.freeze(n.flatMap(l=>[l.detail.tableName,l.primary.available?l.primary.display:`${l.detail.tableName} row`])),secondary:s?"cancel":n.length>1?"back":"close"})}function vn(e,t,r,n){let i=V(r.instanceId,"workspace-title",["active-row"]),o=V(r.instanceId,"workspace-location",["active-row"]),a=z(()=>{let s=e.get(),l=ao(t.get(),s,r.layout);return l?[l]:[]},e,t);return Jr({class:"umbika-workspace","aria-labelledby":i,"aria-describedby":o,oncancel:s=>{s.preventDefault(),n.escape()}},U({class:"umbika-workspace__contents"},X({id:s=>so(s.current.frame.rowPath),resource:!0},a,(s,l,c)=>{let f=z(()=>c.get()?.current.detail.row.children??[],c),p=s.current;return U({class:p.frame.origin==="new"?"umbika-workspace__panel umbika-workspace__panel--new":"umbika-workspace__panel","data-umbika-workspace-depth":String(s.depth)},U({class:"umbika-workspace__header"},Zr({id:i,class:"umbika-workspace__title",tabindex:"-1"},s.title),fe({id:o,class:"umbika-workspace__hierarchy","aria-label":"Workspace hierarchy"},s.trail.join(" / ")),p.frame.origin==="existing"?U({class:"umbika-workspace__actions umbika-workspace__navigation"},s.depth>1?Z({type:"button",class:"umbika-workspace__back",onclick:n.back},"Back"):"",Z({type:"button",class:"umbika-workspace__done",onclick:n.close},"Close")):""),U({class:"umbika-workspace__fields"},r.renderNodes(f,p.detail.definitionPath)),p.frame.origin==="new"?U({class:"umbika-workspace__confirmation-footer"},Z({type:"button",class:"umbika-workspace__discard",onpointerdown:g=>g.preventDefault(),onclick:n.cancel},"Cancel"),Z({type:"button",class:"umbika-workspace__keep",onclick:n.add},`Add row to ${p.detail.tableName}`)):U({class:"umbika-workspace__danger-area"},Z({type:"button",class:"umbika-workspace__remove","aria-label":`Remove ${p.name} from ${p.detail.tableName}`,onpointerdown:g=>g.preventDefault(),onclick:n.remove},"Remove row")))})))}function so(e){return e.map(t=>`${t.length}:${t}`).join("|")}function Mt(e,t,r,n){for(let i of e){let o=[...r,i.id];if(i.type==="object"){let a=Mt(i.children,t,o,n);if(a)return a;continue}if(i.type==="table")for(let a of i.rows){let s=[...n,a.path];if(lo(a.path,t))return Object.freeze({row:a,definitionPath:Object.freeze(o),parentRowPath:n.at(-1),table:i,tableName:i.label??i.id});let l=Mt(a.children,t,o,s);if(l)return l}}}function lo(e,t){return e.length===t.length&&e.every((r,n)=>r===t[n])}var co=1;function Ft(e,t){if(!(e instanceof Element))throw new TypeError("target must be a DOM Element");if(!t||typeof t.form?.getActiveFields!="function")throw new TypeError("options.form must be a form-engine form");let r=t.instanceId??`web-form-${co++}`;if(r.trim().length===0)throw new TypeError("instanceId must not be empty");let n=Br(t.layout,t.form.getFields()),i=Ur(t.theme),o=!1,a=!1,s=G(t.form.getActiveFields()),l=G(null),c,f,p=()=>{if(o)return;let k=f?.contains(document.activeElement)?document.activeElement:null,C=c?.contains(k),P=t.form.getActiveFields(),q=l.get(),L=gn(P,q);L!==q&&l.set(L),s.set(P),E(),k instanceof HTMLElement&&!k.isConnected&&(C&&c?.open?A():v(q?.frames.at(-1)?.openedBy))};function g(k){let C=document.activeElement;if(C instanceof HTMLInputElement&&C.type==="text"&&!C.disabled&&!C.readOnly&&f?.contains(C)){a=!k;try{C.blur()}finally{a=!1}}}function E(){l.get()?.frames.length?c?.open||(typeof c?.showModal=="function"?c.showModal():c?.setAttribute("open","")):c?.open&&(typeof c.close=="function"?c.close():c.removeAttribute("open"))}function v(k){if(o||!f)return;let P=(k?$(k):null)??f.querySelector('input:not([disabled]), select:not([disabled]), button:not([disabled]), [tabindex="0"]')??f.querySelector("output.umbika-field__output");P instanceof HTMLElement&&P.focus()}function $(k){return f?f.querySelector(`#${ho(k)}`):null}function y(k,C=!1){o||(l.set(k.length?Object.freeze({frames:Object.freeze(k.map(uo))}):null),E(),C&&A())}function A(){let C=c?.querySelector(".umbika-workspace__fields input:not([disabled]), .umbika-workspace__fields select:not([disabled])")??c?.querySelector(".umbika-workspace__title");C instanceof HTMLElement&&C.focus()}function O(k,C,P,q){if(o)return;let L=Bt(k,P,C,q),ne=l.get()?.frames??[],Vt=ne.at(-1),_n=Vt&&En(k,Vt.rowPath)?[...ne,L]:[L];y(_n,!0)}function x(k){let C=l.get();if(!C)return;let P=C.frames[0]?.openedBy;k&&g(!0),y([]),v(P)}function S(){let k=l.get();if(!k||k.frames.length<2)return;let C=k.frames.at(-1);g(!0),y(k.frames.slice(0,-1)),v(C?.openedBy)}function b(k){let C=l.get(),P=C?.frames.at(-1);if(!C||!P)return;k||g(!0);let q=C.frames.slice(0,-1);y(q),k&&(t.form.removeRow(rt(P.rowPath)),p()),v(P.openedBy)}function u(){b(!0)}function h(){let k=l.get(),C=k?.frames.at(-1);!k||!C||(C.origin==="new"?b(!0):k.frames.length>1?S():x(!0))}let w=Object.freeze({instanceId:r,definitionPath:Object.freeze([]),layout:n,setText(k,C){o||t.form.input(k,C)},touchText(k){o||(t.form.touch(k),a||p())},commitSelect(k,C){o||(t.form.input(k,C),t.form.touch(k),p())},commitMultiSelect(k,C){o||(t.form.input(k,[...C]),t.form.touch(k),p())},appendRow(k,C,P,q){if(o)return;let L=rt(k),be=t.form.appendRow(L);p(),C&&O(rt([...L,be]),P,q,"new")},removeRow(k){if(o)return;let C=rt(k),P=l.get(),q=P?.frames.find(L=>En(L.rowPath,C));if(P&&q){let L=P.frames.slice(0,P.frames.indexOf(q));y(L)}t.form.removeRow(C),p(),v(q?.openedBy)},openRow(k,C,P){O(k,C,P,"existing")},renderNodes(k,C=[]){return Lt(k,w,C)}}),m=ze({bindings:{text:{event:"blur"}}});c=m.render(vn(l,s,w,{close:()=>x(!0),back:S,add:()=>b(!1),cancel:()=>b(!0),remove:u,escape:h})),c.addEventListener("keydown",R),f=m.render(Hr({class:"umbika-form","data-umbika-instance":r,"data-umbika-theme":i,novalidate:!0,onsubmit:k=>{if(k.preventDefault(),o)return;g(!1);let C=t.form.validate();p(),j(s.get()),t.onSubmit?.({validation:C})}},Lt(s,w),c)),e.appendChild(f);let d=f;function _(k){if(o||!fo(k))return!1;let C=Se(s.get(),n,r,L=>po(L.path,k));if(!C||!("readOnly"in C.node)||C.node.readOnly)return!1;y(C.frames);let P=$(re(r,"control",C.node.path)),q=C.node.type==="multi-select"?P?.querySelector('input[type="checkbox"]:not([disabled])'):P;return q instanceof HTMLElement?(q.focus(),!0):!1}function j(k){let C=Se(k,n,r,ne=>ne.errors.length>0);if(!C)return;C.node.type==="object"&&(C=Se(k,n,r,ne=>"readOnly"in ne&&!ne.readOnly&&ne.errors.length>0)??C),y(C.frames);let{type:P,path:q}=C.node,L=$(P==="object"||P==="table"?V(r,P,q):re(r,"control",q)),be=C.node.type==="multi-select"&&!C.node.readOnly?L?.querySelector('input[type="checkbox"]:not([disabled])'):L;be instanceof HTMLElement&&be.focus()}function R(k){if(o||k.key!=="Tab"||!c?.open)return;let C=Array.from(c.querySelectorAll('button:not([disabled]), input:not([disabled]), select:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(L=>L instanceof HTMLElement&&L.getAttribute("aria-hidden")!=="true");if(C.length===0){k.preventDefault(),c.focus();return}let P=C[0],q=C.at(-1);if(!k.shiftKey&&document.activeElement===q||k.shiftKey&&document.activeElement===P){k.preventDefault();let L=k.shiftKey?q:P;L instanceof HTMLElement&&L.focus()}}return{root:d,refresh:p,focus:_,dispose(){o||(o=!0,l.set(null),c?.removeEventListener("keydown",R),Dt(d),c=void 0,f=void 0)}}}function uo(e){return Bt(e.rowPath,e.definitionPath,e.openedBy,e.origin)}function Bt(e,t,r,n){return Object.freeze({rowPath:Object.freeze([...e]),definitionPath:Object.freeze([...t]),openedBy:r,origin:n})}function rt(e){return[...e]}function Se(e,t,r,n,i=[],o=[]){for(let a of e){let s=[...i,a.id];if(n(a))return{node:a,frames:o};if(a.type==="object"){let l=Se(a.children,t,r,n,s,o);if(l)return l}else if(a.type==="table"){let l=me(t,s)?.mode==="table";for(let c of a.rows){let f=l?[...o,Bt(c.path,s,V(r,"edit-row",c.path),"existing")]:o,p=Se(c.children,t,r,n,s,f);if(p)return p}}}}function fo(e){return Array.isArray(e)&&e.length>0&&e.every(t=>typeof t=="string"&&t.length>0)}function En(e,t){return e.length>=t.length&&t.every((r,n)=>e[n]===r)}function po(e,t){return e.length===t.length&&e.every((r,n)=>r===t[n])}function ho(e){return globalThis.CSS?.escape?globalThis.CSS.escape(e):e.replace(/[^A-Za-z0-9_-]/g,t=>`\\${t.codePointAt(0)?.toString(16)} `)}function kn(e,t){let r=mo(e),n=bo(t),i=Cr({source:n.source,...n.vars===void 0?{}:{vars:n.vars},...n.data===void 0?{}:{data:n.data}}),o=n.onSubmit,a=yo(o,n.submitLabel),s=Ft(r,{form:i,...n.instanceId===void 0?{}:{instanceId:n.instanceId},...n.layout===void 0?{}:{layout:n.layout},...n.theme===void 0?{}:{theme:n.theme},...o===void 0?{}:{onSubmit:({validation:l})=>{l.valid&&o(i.getSubmissionData())}}});try{a&&s.root.append(a)}catch(l){throw xn(a),s.dispose(),l}return{form:i,root:s.root,refresh:()=>s.refresh(),focus:l=>s.focus(l),dispose(){xn(a),s.dispose()}}}function mo(e){let t=typeof e=="string"?document.querySelector(e):e;if(!(t instanceof HTMLElement))throw new TypeError("target must resolve to an HTMLElement");return t}function bo(e){if(!Ut(e))throw new TypeError("options must be an object");if(typeof e.source!="string")throw new TypeError("options.source must be a string");if(e.vars!==void 0&&!Ut(e.vars))throw new TypeError("options.vars must be an object");if(e.data!==void 0&&!Ut(e.data))throw new TypeError("options.data must be an object");if(e.onSubmit!==void 0&&typeof e.onSubmit!="function")throw new TypeError("options.onSubmit must be a function");if(e.submitLabel!==void 0&&(typeof e.submitLabel!="string"||e.submitLabel.trim()===""))throw new TypeError("options.submitLabel must be a non-empty string");return e}function yo(e,t){if(!e)return;let r=document.createElement("button");return r.type="submit",r.className="umbika-action umbika-standalone-submit",r.textContent=t??"Submit",r.addEventListener("mousedown",On),r}function On(e){e.preventDefault()}function xn(e){e&&(e.removeEventListener("mousedown",On),e.remove())}function Ut(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}return Tn(wo);})();
|