fig-tree-evaluator 3.0.0-preview.7 → 3.0.0-preview.9
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/build/authoring/index.js +1 -1
- package/build/chunks/engine.js +1 -1
- package/build/chunks/shared.js +1 -1
- package/build/format/index.js +1 -1
- package/build/index.d.ts +6 -6
- package/build/index.js +1 -1
- package/build/migrate/index.js +1 -1
- package/package.json +1 -1
package/build/chunks/engine.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,i as t,k as r,f as a,d as n,D as o,E as s,g as i,c as l,n as c,o as u,h as d,S as p,q as f,e as m,p as h,s as v,u as y,j as g,v as b,w,r as k,t as $,l as x,R as j,F as O,x as P,b as A,y as S,z as D,W as C,A as N,B as z,G as T}from"./shared.js";const E={ok:!0},q=e=>null===e?"null":Array.isArray(e)?"array":typeof e,M=(e,t)=>({ok:!1,expected:e,actual:q(t)}),F=(t,r)=>{switch(r){case"any":return!0;case"string":return"string"==typeof t;case"number":return"number"==typeof t;case"integer":return"number"==typeof t&&Number.isInteger(t);case"boolean":return"boolean"==typeof t;case"array":return Array.isArray(t);case"object":return e(t);case"null":return null===t;default:return!1}},R=e=>"null"===e||"any"===e||!!Array.isArray(e)&&(e.includes("null")||e.includes("any")),I=/*#__PURE__*/new Set(["any","string","number","boolean","array","object","null","integer"]),V=t=>{if("string"==typeof t)return I.has(t);if(Array.isArray(t))return t.length>0&&t.every(e=>"string"==typeof e&&I.has(e));if(e(t)&&"literal"in t){const e=t.literal;return Array.isArray(e)&&e.length>0&&e.every(e=>["string","number","boolean"].includes(typeof e))}return!1},L=(e,r)=>{if(t(r)){if(-1!==r.literal.indexOf(e))return E;const t=r.literal.map(e=>JSON.stringify(e)).join(", ");return M(`one of ${t}`,e)}return"string"==typeof r?F(e,r)?E:M(r,e):r.some(t=>F(e,t))?E:M(r.join(" | "),e)},J=(e,t)=>{if(void 0!==t.length){if(!Array.isArray(e))return M("array",e);if(e.length!==t.length)return{ok:!1,expected:`array of length ${t.length}`,actual:`array of length ${e.length}`}}if(t.homogeneous){if(!Array.isArray(e))return M("array",e);const r=t.homogeneous;if(e.length>0){if(void 0===r.find(t=>e.every(e=>F(e,t))))return{ok:!1,expected:`homogeneous array of ${r.join(" | ")}`,actual:W(e)}}}if(t.elementShape){if(!Array.isArray(e))return M("array",e);for(let r=0;r<e.length;r++){const a=K(e[r],t.elementShape);if(!a.ok)return a}}return E},W=e=>{const t=q(e[0]),r=e.find(e=>q(e)!==t);return void 0===r?`array of ${t}`:`${q(r)} beside ${t}`},B=["length","homogeneous","elementShape"],U=t=>{if(!e(t))return M("a constraints object",t);for(const e of Object.keys(t))if(!B.includes(e))return{ok:!1,expected:`one of ${B.join(", ")}`,actual:e};const{length:r,homogeneous:a,elementShape:n}=t;if(void 0!==r&&(!Number.isInteger(r)||r<0))return M("a non-negative integer length",r);if(!(void 0===a||Array.isArray(a)&&V(a)))return M("a non-empty array of basic types",a);if(void 0!==n){if(!e(n))return M("an object of declarations",n);for(const[t,r]of Object.entries(n)){if(!e(r))return M(`a declaration for "${t}"`,r);if(void 0!==r.type&&!V(r.type))return M(`a vocabulary type for "${t}"`,r.type);if(void 0!==r.required&&"boolean"!=typeof r.required)return M(`a boolean "required" for "${t}"`,r.required);if(void 0!==r.constraints){const e=U(r.constraints);if(!e.ok)return e}}}return E},K=(t,r)=>{if(!e(t))return M("object",t);const a=Object.keys(r);for(let e=0;e<a.length;e++){const n=a[e],o=r[n],s=Object.prototype.hasOwnProperty.call(t,n),i=!1!==o.required;if(s){if(void 0!==o.type){const e=L(t[n],o.type);if(!e.ok)return e}if(void 0!==o.constraints){const e=J(t[n],o.constraints);if(!e.ok)return e}}else if(i)return{ok:!1,expected:`property "${n}"`,actual:"missing"}}return E},G=(e,t,r)=>{if(!r||!Array.isArray(e))return J(e,t);const{length:a,...n}=t;if(void 0!==a){const t=J(e,{length:a});if(!t.ok)return t}return J(e.filter(e=>null!==e),n)},_=["logic","comparison","math","string","array","data","io","other"],H=Symbol("fig-tree:EvaluationData"),Q=Symbol("fig-tree:validated-operator"),X=e=>"object"==typeof e&&null!==e&&!0===e[Q],Y="<array>",Z="<object>",ee=e=>null===e?"":"string"==typeof e?e:"number"==typeof e?String(e):"boolean"==typeof e?e?"true":"false":Array.isArray(e)?Y:Z,te=e=>null!==e&&"object"==typeof e,re="a composite element renders as a placeholder, never as text — drill in, or join it explicitly",ae=[!1,null,0,""],ne=e=>-1===ae.indexOf(e),oe=(e,t)=>"number"==typeof e&&"number"==typeof t?e<t?-1:e>t?1:0:se(String(e),String(t)),se=(e,t)=>{const r=Array.from(e),a=Array.from(t),n=Math.min(r.length,a.length);for(let e=0;e<n;e++){const t=r[e].codePointAt(0),n=a[e].codePointAt(0);if(t!==n)return t<n?-1:1}return r.length===a.length?0:r.length<a.length?-1:1},ie=e=>e.trim(),le=/\s+$/,ce=/^\s+/,ue=e=>e.replace(le,""),de=e=>e.replace(ce,""),pe=e=>Array.from(e),fe=(e,t)=>{const[r,a]=String(e).split("e"),n=void 0!==a?Number(a)+t:t;return Number(`${r}e${n}`)},me=Object.prototype.hasOwnProperty,he=(e,t)=>{for(const r of e.keys())if(ve(r,t))return r},ve=(e,t)=>{let r,a,n;if(e===t)return!0;if(e&&t&&(r=e.constructor)===t.constructor){if(r===Date)return e.getTime()===t.getTime();if(r===RegExp)return e.toString()===t.toString();if(r===Array){if((a=e.length)===t.length)for(;a--&&ve(e[a],t[a]););return-1===a}if(r===Set){if(e.size!==t.size)return!1;for(a of e){if(n=a,n&&"object"==typeof n&&(n=he(t,n),!n))return!1;if(!t.has(n))return!1}return!0}if(r===Map){if(e.size!==t.size)return!1;for(a of e){if(n=a[0],n&&"object"==typeof n&&(n=he(t,n),!n))return!1;if(!ve(a[1],t.get(n)))return!1}return!0}if(r===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(r===DataView){if((a=e.byteLength)===t.byteLength)for(;a--&&e.getInt8(a)===t.getInt8(a););return-1===a}if(ArrayBuffer.isView(e)){if((a=e.byteLength)===t.byteLength)for(;a--&&e[a]===t[a];);return-1===a}if(!r||"object"==typeof e){for(r in a=0,e){if(me.call(e,r)&&++a&&!me.call(t,r))return!1;if(!(r in t)||!ve(e[r],t[r]))return!1}return Object.keys(t).length===a}}return e!=e&&t!=t},ye=e=>!e.includes("{")&&!e.includes("}")&&(e.startsWith("$")?e.length>1:r(e).ok),ge=e=>{const t=[];let r="";const a=()=>{""!==r&&(t.push({kind:"text",text:r}),r="")};let n=0;for(;n<e.length;){const o=e[n];if("%"===o){let s=n+1;for(;s<e.length&&e[s]>="0"&&e[s]<="9";)s++;if(s>n+1){const r=e.slice(n,s);a(),t.push({kind:"positional",raw:r,index:Number(r.slice(1))}),n=s;continue}r+=o,n++;continue}if("{"===o&&"{"===e[n+1]){const o=e.indexOf("}}",n+2);if(-1!==o){const r=e.slice(n+2,o);if(ye(r)){a(),t.push({kind:"named",raw:e.slice(n,o+2),body:r}),n=o+2;continue}}r+="{{",n+=2;continue}r+=o,n++}return a(),t},be=(e,t)=>{const r={registry:t,maxDepth:0};return{constant:we(r,e,0),depth:r.maxDepth}},we=(e,t,r)=>{if(r>o)return!1;if(r>e.maxDepth&&(e.maxDepth=r),void 0===t)return!1;if("string"==typeof t){const e=a(t).kind;return"plain"===e||"unrecognized"===e}if(Array.isArray(t)){for(let a=0;a<t.length;a++)if(!we(e,t[a],r+1))return!1;return!0}if(n(t)){for(const r in t){if("operator"===r||"fragment"===r||"vars"===r||"//"===r)return!1;if(r.startsWith("$")&&ke(e.registry,r.slice(1)))return!1}for(const a in t)if(!we(e,t[a],r+1))return!1;return!0}return!0},ke=(e,t)=>"literal"===t||void 0!==Nr(e,t)||e.fragments.has(t),$e=(e,t)=>({parent:e,key:t}),xe=e=>{const t=[];for(let r=e;null!==r;r=r.parent)t.push(r.key);return t.reverse()},je=e=>{e.sort((e,t)=>e.order-t.order)},Oe=e=>e.some(({issue:e})=>"error"===e.severity),Pe=e=>{const t=e.entry.definition.parameters.as;if("structural"!==t?.evaluation)return null;const r=e.params.as;return"constant"===r?.kind&&"string"==typeof r.value?r.value:null},Ae=(e,t,r)=>void 0===r?null===e:("element"===t?e:`${e??""}Index`)===r,Se=(e,t,r)=>{"__proto__"===t?Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0}):e[t]=r},De=(e,t,r)=>{const a=new Set;let n=e;return t.forEach((e,t)=>{n=Ce(n,e.at,r[t],a)}),n},Ce=(e,t,r,a)=>{const n=Ne(e,a),[o,...s]=t;return Se(n,o,0===s.length?r:Ce(n[o],s,r,a)),n},Ne=(e,t)=>{if(t.has(e))return e;const r=Array.isArray(e)?[...e]:{...e};return t.add(r),r},ze=/*#__PURE__*/new Set(["data","vars","params","element","index","d","v","p","e","i"]),Te=(e,t,r={})=>{const a={registry:t,recognizes:e=>ke(t,e),issues:[],order:0,nodeCount:0,maxDepth:0,dataPaths:new Map,dynamic:!1,operators:new Set,fragmentNames:new Set,fragmentCalls:[],dataReads:[],identityOnly:!1,scope:{bindings:[]},asNames:new Set,unrecognized:[],hasNoCache:!1},n=(r.basePath??[]).reduce($e,null),o=Fe(a,e,n,0);qe(a);const s=jt(a,o);je(a.issues);const i=Oe(a.issues),l={nodeCount:a.nodeCount,maxDepth:a.maxDepth,dependencies:{dataPaths:a.dataPaths,dynamic:a.dynamic,operators:[...a.operators],fragments:[...a.fragmentNames]},identityOnly:a.identityOnly};return{root:o,holes:s,issues:a.issues,hasErrors:i,timeoutShielded:s.every(e=>void 0!==e.timeoutFallback),own:l,...Ee(l,a.fragmentCalls,t.fragments),fragmentCalls:a.fragmentCalls,dataReads:a.dataReads,hasNoCache:a.hasNoCache}},Ee=(e,t,r)=>{if(0===t.length)return e;const a=new Map(e.dependencies.dataPaths),n=new Set(e.dependencies.operators),o=new Set(e.dependencies.fragments);let{nodeCount:s,maxDepth:i,identityOnly:l}=e,c=e.dependencies.dynamic;for(const e of t){const t=r.get(e.name);if(void 0!==t){s+=t.nodeCount,i=Math.max(i,e.depth+t.maxDepth),l||=t.identityOnly,c||=t.dependencies.dynamic;for(const[e,r]of t.dependencies.dataPaths)a.set(e,r);for(const e of t.dependencies.operators)n.add(e);for(const e of t.dependencies.fragments)o.add(e)}}return{nodeCount:s,maxDepth:i,identityOnly:l,dependencies:{dataPaths:a,dynamic:c,operators:[...n],fragments:[...o]}}},qe=e=>{if(0!==e.asNames.size)for(const{token:t,issue:r,raw:a}of e.unrecognized)e.asNames.has(t)&&(r.issue={...r.issue,severity:"error",code:s.unresolvedBinding,message:`'${a}' names an iterator binding, but no enclosing iterator binds it here`})},Me=(e,t,r,a,n,o,s={})=>{const i={severity:t,code:r,message:a,path:xe(n)};void 0!==s.operator&&(i.operator=s.operator),void 0!==s.parameter&&(i.parameter=s.parameter),void 0!==s.suggestion&&(i.suggestion=s.suggestion);const l={issue:i,order:o};return e.issues.push(l),l},Fe=(e,t,r,a)=>{const n=e.order++;if(a>e.maxDepth&&(e.maxDepth=a),a>o)return Me(e,"error",s.depthCeiling,`the expression nests deeper than the engine's ceiling of ${o} levels — descent stopped here`,r,n),e.nodeCount++,Ve(t,r,n);const i=Re(e,t,r,a,n);return"operator"!==i.kind&&"fragmentCall"!==i.kind&&"reference"!==i.kind&&"invalid"!==i.kind||e.nodeCount++,i},Re=(e,t,r,a,o)=>null==t?Ie(t??null,r,o):"number"==typeof t||"boolean"==typeof t?Ie(t,r,o):"string"==typeof t?Le(e,t,r,o):Array.isArray(t)?Je(e,t,r,a,o):n(t)?We(e,t,r,a,o):(e.identityOnly=!0,Ie(t,r,o)),Ie=(e,t,r)=>({kind:"constant",value:e,path:t,order:r}),Ve=(e,t,r)=>({kind:"invalid",raw:e,path:t,order:r}),Le=(e,t,r,n)=>{const o=a(t,e.scope);switch(o.kind){case"plain":return Ie(t,r,n);case"unrecognized":{const a=Me(e,"warning",s.unrecognizedIdentifier,`'${t}' matches no reference namespace and will pass through as data`,r,n),o=i(t);return null!==o&&e.unrecognized.push({token:o.token,issue:a,raw:t}),Ie(t,r,n)}case"invalid":return Me(e,"error",o.code??s.invalidReference,`'${t}': ${o.reason}`,r,n),Ve(t,r,n);case"reference":{const{namespace:a,segments:s,drill:i,binding:l}=o;return void 0!==l?{kind:"reference",namespace:a,segments:s,raw:t,binding:l,path:r,order:n}:("data"===a&&(0===s.length?e.dynamic=!0:et(e,s,i.startsWith(".")?i.slice(1):void 0,r)),{kind:"reference",namespace:a,segments:s,raw:t,path:r,order:n})}}},Je=(e,t,r,a,n)=>{const o=Array.from(t,(t,n)=>({key:n,rawChild:t,node:Fe(e,t,$e(r,n),a+1)}));return xt(e,t,o,!0,!1,void 0,r,n)},We=(e,t,r,a,n)=>{const o=l(t,e.recognizes);switch(o.kind){case"malformed":return Me(e,"error",s.malformedNode,o.message,r,n),Ve(t,r,n);case"operator":return Be(e,t,r,a,n);case"fragment":return vt(e,t,r,a,n);case"shorthand":return ct(e,t,o.key,r,a,n);case"plain":return kt(e,t,r,a,n)}},Be=(e,t,r,a,n)=>{const o=t.operator;if("string"!=typeof o)return Me(e,"error",s.malformedNode,"the 'operator' value must be a literal string",r,n),Ve(t,r,n);if("literal"===o)return ht(e,t,t.value,"value"in t,r,n);const i=Nr(e.registry,o);if(void 0===i){const a=f(o,At(e));return Me(e,"error",s.unknownOperator,`'${o}' names no registered operator${a?` — did you mean '${a}'?`:""}`,r,n,{suggestion:a}),Ve(t,r,n)}const l=Ue(e,i,r,n),c=[];for(const o in t){const i=t[o];"operator"!==o&&"//"!==o&&void 0!==i&&(Ke(e,l,o,i,r,a,n)||("parameters"!==o?_e(e,l,c,o,i,$e(r,o),n):Me(e,"error",s.malformedNode,"'parameters' is reserved and unused on operator nodes",$e(r,o),n,{operator:l.name})))}return He(e,l,c,a,n),l},Ue=(e,t,r,a)=>(e.operators.add(t.definition.name),{kind:"operator",name:t.definition.name,entry:t,params:{},path:r,order:a}),Ke=(e,t,r,a,n,o,s)=>"fallback"===r?(t.fallback=Fe(e,a,$e(n,"fallback"),o+1),!0):"noCache"===r?(Ge(e,t,a,n,s),!0):"vars"===r&&(t.vars=wt(e,a,n,o,s),!0),Ge=(e,t,r,a,n)=>{!0===r?(t.noCache=!0,e.hasNoCache=!0):Me(e,"error",s.malformedNode,"'noCache' takes only the literal true — it is settled before the subtree runs",$e(a,"noCache"),n,"operator"===t.kind?{operator:t.name}:{})},_e=(e,t,r,a,n,o,i)=>{if(void 0===t.entry.definition.parameters[a]){const r=f(a,Object.keys(t.entry.definition.parameters));return void Me(e,"error",s.unknownNodeKey,`'${a}' is not a parameter of '${t.name}'${r?` — did you mean '${r}'?`:""}`,o,i,{operator:t.name,parameter:a,suggestion:r})}r.push({name:a,kind:"value",value:n,path:o})},He=(e,t,r,a,n)=>{const o=t.entry.definition,s=o.resolution.perElement.length>0;let i;if(s){const a=r.find(e=>"as"===e.name&&"structural"===o.parameters.as?.evaluation&&"value"===e.kind);void 0!==a&&"value"===a.kind&&(i=lt(e,t,a.value,a.path,n))}for(const n of r){const r=o.parameters[n.name]?.evaluation;"perElement"!==r&&(t.params[n.name]=rt(e,n,r,a))}if(s){void 0!==i&&e.scope.bindings.push(i);for(const n of r){const r=o.parameters[n.name]?.evaluation;"perElement"===r&&(t.params[n.name]=rt(e,n,r,a))}void 0!==i&&e.scope.bindings.pop()}tt(e,t),Qe(e,t)},Qe=(e,t)=>{if("buildString"!==t.name)return;((e,t)=>{const r=t.params.substitutions;if(void 0===r)return;const a="constant"===r.kind?r.value:"skeleton"===r.kind?r.skeleton:void 0;(Array.isArray(a)||n(a))&&Object.values(a).some(te)&&Me(e,"error",s.operatorValidate,re,r.path,r.order,{operator:t.name,parameter:"substitutions"})})(e,t);const r=t.params.template;if("constant"!==r?.kind||"string"!=typeof r.value)return;const a=ge(r.value).filter(e=>"text"!==e.kind);if(0===a.length)return;const o=t.params.substitutions,i=(e=>{if(void 0===e)return{mode:"absent"};if("constant"===e.kind)return Array.isArray(e.value)?{mode:"array",length:e.value.length}:n(e.value)?{mode:"object",keys:new Set(Object.keys(e.value))}:{mode:"dynamic"};if("skeleton"===e.kind){const{skeleton:t,holes:r}=e;if(Array.isArray(t))return{mode:"array",length:t.length};if(n(t)){const e=new Set(Object.keys(t));for(const t of r)e.add(String(t.at[0]));return{mode:"object",keys:e}}}return{mode:"dynamic"}})(o);if(Ye(e,t,r,a,i),"absent"!==i.mode&&"object"!==i.mode)return;const l=[],c=new Set;for(const t of a){if("named"!==t.kind||!t.body.startsWith("$"))continue;if(c.has(t.body))continue;const a=Le(e,t.body,r.path,e.order++);"reference"===a.kind&&(e.nodeCount++,c.add(t.body),l.push({path:r.path,at:[t.body],node:a}))}0!==l.length&&(t.params.substitutions=Xe(e,t,o,l))},Xe=(e,t,r,a)=>{const n="skeleton"===r?.kind?{...r,skeleton:{...r.skeleton},holes:[...r.holes]}:{kind:"skeleton",skeleton:"constant"===r?.kind?{...r.value}:{},holes:[],path:r?.path??$e(t.path,"substitutions"),order:r?.order??e.order++};return n.holes.push(...a),n},Ye=(e,t,r,a,n)=>{const o=(a,n)=>Me(e,"warning",a,n,r.path,r.order,{operator:t.name}),i=(e,t)=>o(s.unboundToken,`'${e}' binds to nothing and renders as its own text${t}`),l=e=>{for(const t of e)o(s.unusedSubstitution,`substitution ${t} is never named by the template`)};if("array"!==n.mode&&"dynamic"!==n.mode||a.some(e=>"named"===e.kind&&e.body.startsWith("$"))&&o(s.inertReferenceToken,`a reference token needs the named face — beside ${"array"===n.mode?"positional substitutions":"a dynamically supplied map"} it is not recognized and renders as its own text`),"array"===n.mode){const e=new Set,t=[];for(const r of a)"positional"===r.kind&&(r.index>=1&&r.index<=n.length?e.add(r.index):t.push(r));const r=[];for(let t=1;t<=n.length;t++)e.has(t)||r.push(String(t));if(0===t.length)return void l(r);const o=0===n.length?"there are no substitutions":1===n.length?"there is only 1 substitution":`there are only ${n.length} substitutions`;for(const e of t)i(e.raw,` — ${e.index<1?"numbering starts at %1":o}${Ze(r)}`);return}if("object"===n.mode){const e=new Set,t=[];for(const r of a)"named"===r.kind&&(n.keys.has(r.body)?e.add(r.body):r.body.startsWith("$")||t.push(r.raw));const r=[...n.keys].filter(t=>!e.has(t)).map(e=>`'${e}'`);0===t.length&&l(r);for(const e of t)i(e,Ze(r))}},Ze=e=>{if(0===e.length)return"";if(1===e.length)return`, and substitution ${e[0]} is unused`;const t=e[e.length-1];return`, and substitutions ${e.slice(0,-1).join(", ")} and ${t} are unused`},et=(e,t,r,a)=>{let n,o;void 0!==r&&c(r)?(n=r,o=t):(o=u(t),n=d(o)),e.dataPaths.set(n,o),e.dataReads.push({kind:"path",key:n,segments:o,path:a})},tt=(e,t)=>{if("get"!==t.name||void 0!==t.params.from)return;const r=t.params.path;if(void 0!==r)if("constant"===r.kind)try{const a="string"==typeof r.value?g(r.value):r.value;if(!Array.isArray(a)||!a.every(b))return void(e.dynamic=!0);if(0===a.length)return void(e.dynamic=!0);et(e,a,"string"==typeof r.value?r.value:void 0,t.path)}catch{e.dynamic=!0}else e.dynamic=!0},rt=(e,t,r,a)=>{if("lazyElements"===r||"race"===r){const r=st(e,t,a);if(null!==r)return r}if("lazyEntries"===r){const r=it(e,t,a);if(null!==r)return r}return"value"===t.kind?Fe(e,t.value,t.path,a+1):at(e,t,a)},at=(e,t,r)=>{const{order:a,containerDepth:n}=nt(e,r),o=ot(e,t.elements,t.basePath,t.offset,n);return xt(e,t.elements,o,!0,!1,void 0,t.basePath,a)},nt=(e,t)=>{const r=e.order++,a=t+1;return a>e.maxDepth&&(e.maxDepth=a),{order:r,containerDepth:a}},ot=(e,t,r,a,n)=>Array.from(t,(t,o)=>({key:o,rawChild:t,node:Fe(e,t,$e(r,a+o),n+1)})),st=(e,t,r)=>{const a="slice"===t.kind?t.elements:t.value;if(!Array.isArray(a))return null;const n="slice"===t.kind?t.basePath:t.path,o="slice"===t.kind?t.offset:0,{order:s,containerDepth:i}=nt(e,r),l=ot(e,a,n,o,i);if(l.every(e=>"constant"===e.node.kind))return xt(e,a,l,!0,!1,void 0,n,s);return{kind:"elements",nodes:l.map(e=>e.node),path:n,order:s}},it=(e,t,r)=>{if("value"!==t.kind)return null;const a=t.value;if(!n(a)||m(a,e.recognizes))return null;const{order:o,containerDepth:s}=nt(e,r),{entries:i,vars:l,changed:c}=$t(e,a,t.path,s,o);if(i.every(e=>"constant"===e.node.kind))return xt(e,a,i,!1,c,l,t.path,o);const u={};for(const{key:e,node:t}of i)u[String(e)]=t;const d={kind:"entries",entries:u,path:t.path,order:o};return void 0!==l&&(d.vars=l),d},lt=(e,t,n,o,i)=>{const l=r=>{Me(e,"error",s.invalidAs,r,o,i,{operator:t.name})};if("string"!=typeof n||"plain"!==a(n).kind)return l("'as' must be a literal name — a dynamic value cannot be statically resolved");const c=r(n);if(!c.ok)return l(`'${n}' is not a legal binding name — ${c.reason}`);const u=[n,w(n)];for(const t of u){if(ze.has(t))return l(`'${n}' collides with the reserved namespace word '${t}'`);if(null!==y(t,e.scope.bindings))return l(`'${n}' collides with an enclosing 'as' binding ('${t}')`)}for(const t of u)e.asNames.add(t);return n},ct=(e,t,r,a,n,o)=>{const i=r.slice(1),l="literal"===i,c=!l&&e.registry.fragments.has(i);for(const n in t)if(n!==r&&!p.has(n))return Me(e,"error",s.malformedNode,`'${n}' may not sit beside the shorthand key '${r}' — reserved modifiers only`,$e(a,n),o),Ve(t,a,o);const u=t[r],d=$e(a,r);if(l){for(const r of["fallback","vars","noCache"])r in t&&Me(e,"warning",s.uselessModifier,`'${r}' on 'literal' is dead — contents are never evaluated`,$e(a,r),o);return ht(e,t,u,!0,a,o)}if(c)return yt(e,t,i,u,a,n,o);const f=Nr(e.registry,i),m=Ue(e,f,a,o);for(const s in t){const i=t[s];s!==r&&"//"!==s&&void 0!==i&&Ke(e,m,s,i,a,n,o)}const h=[];return ut(e,m,h,u,d,o),He(e,m,h,n,o),m},ut=(e,t,r,a,o,s)=>{if(Array.isArray(a))pt(e,t,r,a,o,s);else if(!n(a)||m(a,e.recognizes))dt(e,t,r,a,o,s);else for(const n in a){const i=a[n];"//"!==n&&void 0!==i&&_e(e,t,r,n,i,$e(o,n),s)}},dt=(e,t,r,a,n,o)=>{const s=v(t.entry.definition);null!==s?r.push({name:s,kind:"value",value:a,path:n}):ft(e,t,n,o)},pt=(e,t,r,a,n,o)=>{const s=t.entry.definition,i=h(s,a.length);if(null===i)return void mt(e,t,a,n,o);const l=s.positionalParams;for(let e=0;e<i.bound;e++)r.push({name:l[e],kind:"value",value:a[e],path:$e(n,e)});const{restAt:c}=i;null!==c&&r.push({name:s.restParam,kind:"slice",elements:0===c?a:a.slice(c),basePath:n,offset:c})},ft=(e,t,r,a)=>Me(e,"error",s.positionalArity,`'${t.name}' takes no positional arguments — use the named form`,r,a,{operator:t.name}),mt=(e,t,r,a,n)=>{const o=t.entry.definition.positionalParams;if(void 0===o)return void ft(e,t,a,n);const i=o.length;Me(e,"error",s.positionalArity,`'${t.name}' takes at most ${i} positional argument${1===i?"":"s"} (${o.join(", ")}), got ${r.length}`,a,n,{operator:t.name})},ht=(e,t,r,a,n,o)=>{if("operator"in t){for(const r in t)"operator"!==r&&"value"!==r&&"//"!==r&&("fallback"!==r&&"vars"!==r&&"noCache"!==r?Me(e,"error",s.unknownNodeKey,`'${r}' is not a key of 'literal' — content goes in 'value'`,$e(n,r),o,{operator:"literal"}):Me(e,"warning",s.uselessModifier,`'${r}' on 'literal' is dead — contents are never evaluated`,$e(n,r),o));if(!a)return Me(e,"error",s.malformedNode,"'literal' requires its content in 'value'",n,o,{operator:"literal"}),Ve(t,n,o)}return Ie(r,n,o)},vt=(e,t,r,a,n)=>{const o=t.fragment;if("string"!=typeof o)return Me(e,"error",s.malformedNode,"the 'fragment' value must be a literal string",r,n),Ve(t,r,n);const i={kind:"fragmentCall",name:o,argumentsMode:"static",path:r,order:n};gt(e,i,a);for(const o in t){const l=t[o];"fragment"!==o&&"//"!==o&&void 0!==l&&("parameters"!==o?"fallback"!==o?"vars"!==o?"noCache"!==o?Me(e,"error",s.unknownNodeKey,`'${o}' is not a key of a fragment call — arguments live only in 'parameters'`,$e(r,o),n):Ge(e,i,l,r,n):i.vars=wt(e,l,r,a,n):i.fallback=Fe(e,l,$e(r,"fallback"),a+1):bt(e,i,l,$e(r,"parameters"),a,n))}return i},yt=(e,t,r,a,o,i,l)=>{const c={kind:"fragmentCall",name:r,argumentsMode:"static",path:o,order:l};gt(e,c,i);for(const a in t){const n=t[a];a!==`$${r}`&&"//"!==a&&void 0!==n&&("fallback"===a&&(c.fallback=Fe(e,n,$e(o,"fallback"),i+1)),"noCache"===a&&Ge(e,c,n,o,l),"vars"===a&&(c.vars=wt(e,n,o,i,l)))}return n(a)?bt(e,c,a,$e(o,`$${r}`),i,l):Me(e,"error",s.malformedNode,`fragments have no single-value or positional form — '$${r}' takes a named-arguments object`,$e(o,`$${r}`),l),c},gt=(e,t,r)=>{const{name:a,path:n,order:o}=t;e.fragmentNames.add(a);const i=e.registry.fragments.get(a);if(void 0===i){const t=f(a,e.registry.fragments.keys());return void Me(e,"error",s.unknownFragment,`'${a}' names no registered fragment${t?` — did you mean '${t}'?`:""}`,n,o,{suggestion:t})}t.entry=i,e.fragmentCalls.push({name:a,depth:r}),e.dataReads.push({kind:"call",fragment:i,path:n})},bt=(e,t,r,o,i,l)=>{if(void 0!==r){if(m(r,e.recognizes)||"string"==typeof r&&"reference"===a(r).kind)return t.argumentsMode="dynamic",t.parameters=Fe(e,r,o,i+1),void(e.dynamic=!0);if(n(r)){const a={};for(const t in r){const n=r[t];"//"!==t&&void 0!==n&&(a[t]=Fe(e,n,$e(o,t),i+1))}return void(t.parameters=a)}Me(e,"error",s.malformedNode,"a fragment's 'parameters' must be a named-arguments object or a node computing one",o,l)}},wt=(e,t,a,o,i)=>{const l=$e(a,"vars");if(!n(t))return void Me(e,"error",s.invalidVars,"a 'vars' block must be an object of name → expression entries",l,i);const c={};for(const a in t){const n=t[a];if("//"===a||void 0===n)continue;const u=$e(l,a),d=r(a);d.ok?c[a]=Fe(e,n,u,o+1):Me(e,"error",s.invalidName,`'${a}' is not a legal var name — ${d.reason}`,u,i)}return c},kt=(e,t,r,a,n)=>{const{entries:o,vars:s,changed:i}=$t(e,t,r,a,n);return xt(e,t,o,!1,i,s,r,n)},$t=(e,t,r,a,n)=>{let o,i=!1;const l=[];for(const c in t){const u=t[c];if("//"!==c)if("vars"!==c)if(void 0!==u){if(c.startsWith("$")){const t=f(c.slice(1),At(e));Me(e,"warning",s.unrecognizedIdentifier,`'${c}' is not a registered operator or fragment and will pass through as data${t?` — did you mean '$${t}'?`:""}`,$e(r,c),n,{suggestion:void 0===t?void 0:`$${t}`})}l.push({key:c,rawChild:u,node:Fe(e,u,$e(r,c),a+1)})}else i=!0;else o=wt(e,u,r,a,n),i=!0;else i=!0}return{entries:l,vars:o,changed:i}},xt=(e,t,r,a,n,o,i,l)=>{const c=[],u=a?new Array(r.length):{};let d=n;for(const{key:e,rawChild:t,node:a}of r)"constant"!==a.kind?(d=!0,"skeleton"!==a.kind||void 0!==a.vars?c.push({path:a.path,at:[e],node:a}):(Se(u,e,a.skeleton),c.push(...a.holes.map(t=>({...t,at:[e,...t.at]}))))):(Se(u,e,a.value),a.value!==t&&(d=!0));if(0===c.length)return void 0!==o&&Object.keys(o).length>0&&Me(e,"warning",s.unreferencedVar,"this vars block declares names nothing in its scope references",$e(i,"vars"),l),Ie(d||void 0!==o?u:t,i,l);const p={kind:"skeleton",skeleton:u,holes:c,path:i,order:l};return void 0!==o&&(p.vars=o),p},jt=(e,t)=>"constant"===t.kind?[]:"skeleton"===t.kind?t.holes.map(t=>({node:t.node,...Ot(e,t.node)})):[{node:t,...Ot(e,t)}],Ot=(e,t)=>{const r=Pt(e,t);return void 0===r?{}:{timeoutFallback:r}},Pt=(e,t)=>{if("operator"===t.kind||"fragmentCall"===t.kind){if(void 0!==t.fallback)return"constant"===t.fallback.kind?{value:t.fallback.value}:void 0;if("operator"===t.kind){const r=t.entry.instanceDefaults;return void 0!==r&&"fallback"in r&&be(r.fallback,e.registry).constant?{value:r.fallback}:void 0}return t.entry?.timeoutFallback}},At=e=>[...e.registry.operators.keys(),...e.registry.aliases.keys(),...e.registry.fragments.keys()],St=e=>{switch(e.kind){case"operator":return e.entry.definition.returns;case"fragmentCall":return e.entry?.returns??"any";case"skeleton":return Array.isArray(e.skeleton)?"array":"object";case"constant":return Dt(e.value);default:return"any"}},Dt=t=>{if(null===t)return"null";if(Array.isArray(t))return"array";if(e(t))return"object";switch(typeof t){case"string":return"string";case"number":return"number";case"boolean":return"boolean";default:return"any"}},Ct=/*#__PURE__*/Object.freeze({parsePath:g,resolvePath:k,checkType:L,checkConstraints:J,describeType:q,renderText:ee,isTruthy:ne}),Nt=(e,t={})=>{Tt({artifact:e,context:t,varsFrames:[],iteratorFrames:[]},e.root),je(e.issues),e.hasErrors=Oe(e.issues)},zt=(e,t,r,a,n,o,s={})=>{const i={severity:t,code:r,message:a,path:xe(n)};void 0!==s.operator&&(i.operator=s.operator),void 0!==s.fragment&&(i.fragment=s.fragment),void 0!==s.parameter&&(i.parameter=s.parameter),void 0!==s.suggestion&&(i.suggestion=s.suggestion),e.artifact.issues.push({issue:i,order:o})},Tt=(e,t)=>{switch(t.kind){case"constant":case"invalid":return;case"reference":return void Bt(e,t);case"skeleton":{const r=_t(e,t.vars,t.path);for(const r of t.holes)Tt(e,r.node);return void Ht(e,r)}case"fragmentCall":return void Jt(e,t);case"elements":for(const r of t.nodes)Tt(e,r);return;case"entries":{const r=_t(e,t.vars,t.path);for(const r in t.entries)Tt(e,t.entries[r]);return void Ht(e,r)}case"operator":return void qt(e,t)}return t},Et=e=>"kind"in e&&"string"==typeof e.kind,qt=(e,t)=>{const r=_t(e,t.vars,t.path);void 0!==t.fallback&&Tt(e,t.fallback);const a=t.entry.definition,n=Lt(t);for(const[r,o]of a.resolution.entries){const a=t.params[r];void 0!==a?Ft(e,n,r,o,a,Mt(t,r)):o.required&&zt(e,"error",s.missingRequired,`'${t.name}' requires '${r}'`,t.path,t.order,{operator:t.name,parameter:r})}Wt(e,t);const o=[];for(const r in t.params){const n=t.params[r];"perElement"===a.parameters[r]?.evaluation?o.push([r,n]):Tt(e,n)}if(o.length>0){const r={as:Pe(t),referenced:!1};e.iteratorFrames.push(r);for(const[,t]of o)Tt(e,t);e.iteratorFrames.pop(),r.referenced||zt(e,"warning",s.deadBinding,`'${t.name}' binds ${null===r.as?"$element / $index":`$${r.as}`} but its 'each' references neither`,t.path,t.order,{operator:t.name})}Ht(e,r)},Mt=(e,t)=>{const{definition:r,instanceDefaults:a}=e.entry;if(void 0!==r.parameters[t]?.elementNullPolicy)return!1;for(const[n,o]of r.resolution.entries){if(!o.replacesNullAt?.includes(t))continue;const r=e.params[n];if(void 0===r){if(void 0!==a&&Object.hasOwn(a,n)&&null!==a[n])return!0}else if("constant"!==r.kind||null!==r.value)return!0}return!1},Ft=(e,t,r,a,n,o=!1)=>{if("elements"===n.kind){const o=a.constraints?.length;return void(void 0!==o&&n.nodes.length!==o&&zt(e,"error",s.typeCheck,`'${t.label}.${r}': expected ${o} element${1===o?"":"s"}, received ${n.nodes.length}`,n.path,n.order,{...t.extra,parameter:r}))}if("constant"!==n.kind&&"structural"===a.evaluation&&"as"!==r)return void zt(e,"error",s.typeCheck,`'${t.label}.${r}' is structural — it requires a literal value`,n.path,n.order,{...t.extra,parameter:r});const i=`'${t.label}.${r}'`,l=It(a,n,o);void 0!==l&&zt(e,"error",l.code,l.code===s.returnsMismatch?`${l.reason} — it can never satisfy ${i}`:`${i}: ${l.reason}`,n.path,n.order,{...t.extra,parameter:r});let c=n;for(;"operator"===c.kind||"fragmentCall"===c.kind;){const n=c.fallback;if(void 0===n)return void("operator"===c.kind&&Rt(e,t,r,a,c,o));const l=It(a,n,o);void 0!==l&&zt(e,"warning",s.fallbackMismatch,`this fallback can never satisfy ${i}: ${l.reason}`,n.path,n.order,{...t.extra,parameter:r}),c=n}},Rt=(e,t,r,a,n,o)=>{const i=n.entry.instanceDefaults;if(void 0===i||!Object.hasOwn(i,"fallback"))return;const l=Vt(a,i.fallback,o);void 0!==l&&zt(e,"warning",s.fallbackMismatch,`'${n.name}' falls back to its operatorDefaults fallback, which can never satisfy '${t.label}.${r}': ${l.reason}`,n.path,n.order,{...t.extra,parameter:r})},It=(e,t,r)=>{switch(t.kind){case"constant":return Vt(e,t.value,r);case"operator":case"fragmentCall":{if("fragmentCall"===t.kind&&void 0===t.entry)return;const r=St(t);if($(r,e.type))return;const a="operator"===t.kind?`'${t.name}'`:`fragment '${t.name}'`;return{code:s.returnsMismatch,reason:`${a} returns ${JSON.stringify(r)}`}}case"skeleton":{const r=L(Array.isArray(t.skeleton)?[]:{},e.type);return r.ok?void 0:{code:s.typeCheck,reason:`expected ${r.expected}, received ${r.actual}`}}default:return}},Vt=(e,t,r)=>{if(null===t&&(r||!e.required&&!R(e.type)))return;const a=L(t,e.type);if(!a.ok)return{code:s.typeCheck,reason:`expected ${a.expected}, received ${a.actual}`};if(void 0===e.constraints)return;const n=G(t,e.constraints,void 0!==e.elementNullPolicy);return n.ok?void 0:{code:s.typeCheck,reason:`expected ${n.expected}, received ${n.actual}`}},Lt=e=>({label:e.name,extra:{operator:e.name}}),Jt=(e,t)=>{const r=_t(e,t.vars,t.path);void 0!==t.fallback&&Tt(e,t.fallback);const a=t.entry?.parameters,n=void 0===t.parameters||Et(t.parameters)?void 0:t.parameters;if(void 0!==a&&"static"===t.argumentsMode){const r={label:t.name,extra:{fragment:t.name}};for(const o in a){const i=a[o],l=n?.[o];void 0!==l?Ft(e,r,o,i,l):i.required&&zt(e,"error",s.missingRequired,`fragment '${t.name}' – requires '${o}'`,t.path,t.order,{fragment:t.name,parameter:o})}if(void 0!==n)for(const r in n){const o=n[r];if(void 0===a[r]){const n=f(r,Object.keys(a));zt(e,"error",s.unknownNodeKey,`fragment '${t.name}' declares no parameter '${r}'${n?` — did you mean '${n}'?`:""}`,o.path,o.order,{parameter:r,suggestion:n})}}}if(void 0!==t.parameters)if(Et(t.parameters))Tt(e,t.parameters);else for(const r in t.parameters)Tt(e,t.parameters[r]);Ht(e,r)},Wt=(e,t)=>{const r=t.entry.definition.validate;if(void 0===r)return;const a={};for(const e in t.params){const r=t.params[e];"constant"===r.kind&&(a[e]=r.value)}let n;try{n=r(a,Ct)}catch(r){return void zt(e,"error",s.operatorValidate,`'${t.name}' validate hook threw: ${r.message}`,t.path,t.order,{operator:t.name})}for(const r of n){const a=void 0!==r.parameter?t.params[r.parameter]:void 0;zt(e,r.severity,s.operatorValidate,r.message,a?.path??t.path,t.order,{operator:t.name,...void 0!==r.parameter?{parameter:r.parameter}:{}})}},Bt=(e,t)=>{switch(t.namespace){case"data":return;case"vars":return void Ut(e,t);case"params":return void Kt(e,t);case"element":case"index":return void Gt(e,t,t.namespace)}},Ut=(e,t)=>{const r=t.segments[0],a="string"==typeof r?r:void 0;if(void 0!==a)for(let t=e.varsFrames.length-1;t>=0;t--){const r=e.varsFrames[t],n=r.names.get(a);if(void 0!==n){if(n.referenced=!0,null!==r.currentVar){const e=r.edges.get(r.currentVar)??new Set;e.add(a),r.edges.set(r.currentVar,e)}return}}zt(e,"error",s.unresolvedVar,`'${t.raw}': no var '${a??""}' is declared in scope`,t.path,t.order)},Kt=(e,t)=>{const r=e.context.fragmentParams;if(void 0===r)return void zt(e,"error",s.unresolvedParam,`'${t.raw}': $params is only available inside a fragment body`,t.path,t.order);if(0===t.segments.length)return;const a=t.segments[0];"string"==typeof a&&r.has(a)||zt(e,"error",s.unresolvedParam,`'${t.raw}': the fragment declares no parameter '${String(a)}'`,t.path,t.order)},Gt=(e,t,r)=>{for(let a=e.iteratorFrames.length-1;a>=0;a--){const n=e.iteratorFrames[a];if(Ae(n.as,r,t.binding))return void(n.referenced=!0)}zt(e,"error",s.unresolvedBinding,`'${t.raw}' resolves against no enclosing iterator here`,t.path,t.order)},_t=(e,t,r)=>{if(void 0===t)return null;const a={names:new Map,currentVar:null,edges:new Map},n=$e(r,"vars");for(const r in t){const o=t[r],i=$e(n,r);for(const t of e.varsFrames)if(t.names.has(r)){zt(e,"warning",s.shadowedVar,`'${r}' shadows a var of the same name from an enclosing scope`,i,o.order);break}a.names.set(r,{node:o,declaredAt:i,order:o.order,referenced:!1})}e.varsFrames.push(a);for(const[t,r]of a.names)a.currentVar=t,Tt(e,r.node),a.currentVar=null;return a},Ht=(e,t)=>{if(null!==t){e.varsFrames.pop();for(const[r,a]of t.names)a.referenced||zt(e,"warning",s.unreferencedVar,`'${r}' is declared but never referenced in its scope`,a.declaredAt,a.order);Qt(e,t)}},Qt=(e,t)=>{const r=new Set,a=new Set,n=new Set,o=e=>{if(a.has(e))return!1;if(r.has(e))return!0;r.add(e);for(const n of t.edges.get(e)??[])if(o(n))return r.delete(e),a.add(e),!0;return r.delete(e),a.add(e),!1};for(const r of t.names.keys())if(!a.has(r)&&!n.has(r)&&o(r)){const a=t.names.get(r);zt(e,"error",s.varCycle,`'${r}' participates in a vars cycle — a var may not depend on itself`,a.declaredAt,a.order),n.add(r)}},Xt={capable:!1,effective:!1,disabled:[]},Yt={capable:!0,effective:!0,disabled:[]},Zt=e=>{const{effective:t}=er(e,e.root,!1);return je(e.issues),t},er=(e,t,r)=>{switch(t.kind){case"constant":case"reference":return Xt;case"invalid":return Yt;case"skeleton":return or(e,[...t.holes.map(e=>e.node),...sr(t.vars)],r);case"elements":return or(e,t.nodes,r);case"entries":return or(e,[...Object.values(t.entries),...sr(t.vars)],r);case"operator":return tr(e,t,Ar(t.entry),r);case"fragmentCall":return tr(e,t,t.entry?.caches??!0,r)}return t},tr=(e,t,r,a)=>{const n=!0===t.noCache,o=or(e,nr(t),a||n),s=r||o.capable,i=rr(t),l=void 0===i?o.disabled:[i,...o.disabled];return n&&a?ir(e,t,"'noCache' is redundant — an enclosing node already sets it"):n&&!s&&ir(e,t,l.length>0?`'noCache' is redundant — caching is already disabled for ${ar(l)}`:"'noCache' is dead — nothing beneath this node caches"),{capable:s,effective:!n&&(r||o.effective),disabled:l}},rr=e=>"operator"===e.kind&&e.entry.definition.cache&&!Ar(e.entry)?e.entry.definition.name:void 0,ar=e=>{const t=[...new Set(e)].map(e=>`'${e}'`);return t.length<2?t.join(""):`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`},nr=e=>{const t=[];return"operator"===e.kind?t.push(...Object.values(e.params)):void 0!==e.parameters&&("dynamic"===e.argumentsMode?t.push(e.parameters):t.push(...Object.values(e.parameters))),void 0!==e.fallback&&t.push(e.fallback),t.push(...sr(e.vars)),t},or=(e,t,r)=>{const a={capable:!1,effective:!1,disabled:[]};for(const n of t){const{capable:t,effective:o,disabled:s}=er(e,n,r);a.capable||=t,a.effective||=o,a.disabled.push(...s)}return a},sr=e=>void 0===e?[]:Object.values(e),ir=(e,t,r)=>{const a={severity:"warning",code:s.uselessModifier,message:r,path:xe($e(t.path,"noCache"))};"operator"===t.kind?a.operator=t.name:a.fragment=t.name,e.issues.push({issue:a,order:t.order})};class lr{max;entries=new Map;constructor(e){this.max=e,cr(e)}get size(){return this.entries.size}get(e){if(!this.entries.has(e))return;const t=this.entries.get(e);return this.entries.delete(e),this.entries.set(e,t),t}set(e,t){this.entries.delete(e),this.entries.set(e,t),this.entries.size>this.max&&this.evictOldest()}delete(e){this.entries.delete(e)}clear(){this.entries.clear()}resize(e){for(cr(e),this.max=e;this.entries.size>this.max;)this.evictOldest()}evictOldest(){const e=this.entries.keys().next();!0!==e.done&&this.entries.delete(e.value)}}const cr=e=>{if(!Number.isInteger(e)||e<1)throw new RangeError("LRU bound must be a positive integer")},ur=Symbol("fig-tree:lazy-handle"),dr="~",pr=(e,t)=>{if(t>o)return"refused";switch(typeof e){case"boolean":return"json";case"string":return e.length>4096?"serializer":"json";case"number":return Number.isFinite(e)&&!Object.is(e,-0)?"json":"serializer";case"undefined":return"serializer";case"object":break;default:return"refused"}if(null===e)return"json";if(Array.isArray(e)){for(let r=0;r<e.length;r++){const a=pr(e[r],t+1);if("json"!==a)return a}return"json"}if(!n(e))return"refused";for(const r in e){if(r.length>4096)return"serializer";const a=pr(e[r],t+1);if("json"!==a)return a}return"json"},fr=(e,t)=>mr(e,0,t)?t.join(""):void 0,mr=(e,t,r)=>{if(t>o)return!1;if(null===e)return vr(r,"n");if(void 0===e)return vr(r,"u");switch(typeof e){case"boolean":return vr(r,e?"t":"f");case"number":return hr(e,r);case"string":return vr(r,`s${e.length}:${e}`);case"object":break;default:return!1}if(Array.isArray(e)){r.push("[");for(const a of e)if(!mr(a,t+1,r))return!1;return vr(r,"]")}if(!n(e)||ur in e)return!1;r.push("{");for(const a in e)if(r.push(`s${a.length}:${a}`),!mr(e[a],t+1,r))return!1;return vr(r,"}")},hr=(e,t)=>Number.isNaN(e)?vr(t,"N"):e===1/0?vr(t,"I"):e===-1/0?vr(t,"J"):Object.is(e,-0)?vr(t,"#-0"):vr(t,`#${String(e)}`),vr=(e,t)=>(e.push(t),!0);class yr{deps;identity=new WeakMap;content=new lr(200);constructor(e){this.deps=e}resolve(e){const t="object"==typeof e&&null!==e?e:void 0;if(void 0!==t){const e=this.identity.get(t);if(void 0!==e)return e}const r=this.deps.probe(e);if(r.constant){const e={kind:"inert",depth:r.depth};return void 0!==t&&this.identity.set(t,e),e}const a=void 0===t?void 0:(e=>{const t=pr(e,0);return"json"===t?JSON.stringify(e):"serializer"===t?fr(e,[dr]):void 0})(e),n=void 0===a?void 0:this.content.get(a),o=n??this.deps.compile(e),s={kind:"artifact",artifact:o};return void 0!==t&&this.identity.set(t,s),void 0!==a&&void 0===n&&!o.identityOnly&&o.holes.length>0&&this.content.set(a,o),s}}const gr=/*#__PURE__*/new Set(["type","required","default","description","metadata","constraints"]),br=/*#__PURE__*/new Set(["expression","parameters","description","metadata"]),wr=(t,a,n)=>{const o=(...e)=>["fragments",t,...e],i=r(t);if(!i.ok)return void n(s.invalidName,`'${t}' is not a legal fragment name: ${i.reason}`,o());if(x.has(t))return void n(s.reservedName,`'${t}' is a reserved name and may not name a fragment`,o());if(!e(a))return void n(s.invalidDefinition,`fragment '${t}' must be a wrapper object: { expression, parameters?, description?, metadata? }`,o());if(!("expression"in a))return void n(s.invalidDefinition,`fragment '${t}' has no 'expression'`,o());for(const e of Object.keys(a))br.has(e)||n(s.invalidDefinition,`'${e}' is not a key of a fragment definition`,o(e));const l={name:t,parameters:{},body:{kind:"constant",value:null,path:null,order:0},returns:"any",warnings:[],nodeCount:0,maxDepth:0,dependencies:{dataPaths:new Map,dynamic:!1,operators:[],fragments:[]},identityOnly:!1,caches:!1};if(void 0!==a.description&&("string"!=typeof a.description?n(s.invalidDefinition,"'description' must be a string",o("description")):l.description=a.description),void 0!==a.metadata&&(e(a.metadata)?l.metadata=a.metadata:n(s.invalidDefinition,"'metadata' must be a plain object",o("metadata"))),void 0!==a.parameters)if(e(a.parameters))for(const[e,t]of Object.entries(a.parameters)){const r=kr(e,t,o,n);void 0!==r&&(l.parameters[e]=r)}else n(s.invalidDefinition,"'parameters' must be a plain object",o("parameters"));return l},kr=(t,a,n,o)=>{const i=n("parameters",t),l=r(t);if(!l.ok)return void o(s.invalidName,`'${t}' is not a legal parameter name: ${l.reason}`,i);if(j.has(t))return void o(s.reservedName,`'${t}' is a reserved node key and may not name a parameter`,i);if(!e(a))return void o(s.invalidDefinition,`the declaration of '${t}' must be an object`,i);for(const e of Object.keys(a))gr.has(e)||o(s.invalidDefinition,`'${e}' is not a key of a parameter declaration`,[...i,e]);const c=a.type??"any";if(!V(c))return void o(s.invalidDefinition,`'${t}' declares an unknown type`,[...i,"type"]);if(void 0!==a.required&&"boolean"!=typeof a.required)return void o(s.invalidDefinition,"'required' must be a boolean",[...i,"required"]);let u;if(void 0!==a.constraints){const e=U(a.constraints);if(!e.ok)return void o(s.invalidDefinition,`'${t}' declares invalid constraints: expected ${e.expected}, got ${e.actual}`,[...i,"constraints"]);u=a.constraints}const d="default"in a;if(d&&!0===a.required)return void o(s.invalidDefinition,`'${t}' is declared required and also declares a default — the default could never apply`,[...i,"default"]);if(d){const e=L(a.default,c);if(!e.ok)return void o(s.typeCheck,`the default for '${t}' does not satisfy its declared type: expected ${e.expected}, got ${e.actual}`,[...i,"default"]);if(void 0!==u){const e=J(a.default,u);if(!e.ok)return void o(s.typeCheck,`the default for '${t}' violates its declared constraints: expected ${e.expected}, got ${e.actual}`,[...i,"default"])}}const p={type:c,required:a.required??!d};return d&&(p.default=a.default),"string"==typeof a.description&&(p.description=a.description),e(a.metadata)&&(p.metadata=a.metadata),void 0!==u&&(p.constraints=u),p},$r=e=>{const t=new Set,r=new Set,a=e=>{if(r.has(e.name)||t.has(e.name))return;t.add(e.name);const n=e.body;"fragmentCall"===n.kind&&void 0!==n.entry&&a(n.entry),e.returns=St(n),t.delete(e.name),r.add(e.name)};for(const t of e.fragments.values())a(t)},xr=(e,t)=>{const r=[],a=new Set,n=new Set,o=i=>{const l=r.indexOf(i);if(-1!==l){const e=[...r.slice(l),i],a=[...e].sort().join("\0");return n.has(a)||t(s.fragmentCycle,`fragment '${i}' reaches itself: ${e.join(" → ")} — recursion is not supported`,["fragments",i]),void n.add(a)}if(!a.has(i)){r.push(i);for(const t of e.get(i)?.fragmentCalls??[])o(t.name);r.pop(),a.add(i)}};for(const t of e.keys())o(t);return 0===n.size},jr=(e,t)=>{const r=new Set,a=n=>{if(r.has(n))return;r.add(n);const o=e.fragments.get(n),s=t.get(n);if(void 0===o||void 0===s)return;for(const e of s.fragmentCalls)a(e.name);const i=Ee(s.own,s.fragmentCalls,e.fragments);o.nodeCount=i.nodeCount,o.maxDepth=i.maxDepth,o.dependencies=i.dependencies,o.identityOnly=i.identityOnly,o.caches=Zt(s),o.timeoutFallback=Or(s,e.fragments)};for(const e of t.keys())a(e)},Or=(e,t)=>{const{root:r,holes:a}=e;if(0===a.length)return;const n=[];for(const e of a){const r=Pr(e,t);if(void 0===r)return;n.push(r.value)}return"skeleton"===r.kind?{value:De(r.skeleton,r.holes,n)}:{value:n[0]}},Pr=(e,t)=>{if(void 0!==e.timeoutFallback)return e.timeoutFallback;const{node:r}=e;return"fragmentCall"===r.kind&&void 0===r.fallback?t.get(r.name)?.timeoutFallback:void 0},Ar=e=>e.definition.cache&&!0!==e.instanceDefaults?.noCache,Sr=["fallback","noCache"],Dr=t=>{const r=[],a=(e,t,a,n)=>{r.push({severity:"error",code:e,message:t,path:a,...void 0!==n?{operator:n}:{}})},n={operators:new Map,aliases:new Map,fragments:new Map},{operators:o,aliases:i}=n,l=new Map,c=(e,t,r)=>{const n=l.get(e);return void 0!==n?(a(s.duplicateOperator,`'${e}' is already registered (by '${n}') — one namespace, no silent precedence`,t,r),!1):(l.set(e,r),!0)},u=(e,t)=>{if("function"==typeof e)return void a(s.invalidOptions,`operators[${t[1]}]${t.length>2?`[${t[2]}]`:""} is a function — factories must be called: httpOperators(client)`,t);if(!X(e))return void a(s.invalidOptions,"every operators entry must be built with defineOperator() — a plain definition object is not accepted",t);const{name:r,alias:n}=e,l=c(r,t,r),u=void 0===n||c(n,t,r);l&&u&&(o.set(r,{definition:e}),void 0!==n&&i.set(n,r))};return Array.isArray(t.operators)?t.operators.forEach((e,t)=>{Array.isArray(e)?e.forEach((e,r)=>{Array.isArray(e)?a(s.invalidOptions,"'operators' is flattened one level only — arrays may not nest deeper",["operators",t,r]):u(e,["operators",t,r])}):u(e,["operators",t])}):a(s.invalidOptions,"'operators' must be an array",["operators"]),void 0!==t.operatorDefaults&&Cr(t.operatorDefaults,o,i,a),((t,r,a,n,o)=>{if(void 0===t)return;if(!e(t))return void n(s.invalidOptions,"'fragments' must be a plain object",["fragments"]);for(const[e,o]of Object.entries(t)){const t=wr(e,o,n);void 0!==t&&a(e,["fragments",e])&&r.fragments.set(e,t)}const i=new Map;for(const[e,a]of r.fragments){const n=t[e],o=Te(n.expression,r,{basePath:["expression"]});a.body=o.root,i.set(e,o)}$r(r);for(const[e,t]of r.fragments){const r=i.get(e);Nt(r,{fragmentParams:new Set(Object.keys(t.parameters))});for(const{issue:t}of r.issues){const r=t.path[t.path.length-1],a=t.code===s.unrecognizedIdentifier&&o?.has(r);("error"===t.severity||a)&&n(a?s.unknownFragment:t.code,a?`fragment '${e}' calls '${r.slice(1)}', which this update removes`:`fragment '${e}': ${t.message}`,["fragments",e,...t.path])}}xr(i,n)&&jr(r,i);for(const[e,t]of r.fragments)for(const{issue:r}of i.get(e).issues)if("error"!==r.severity){const e={...r,path:[...r.path]};Object.freeze(e.path),t.warnings.push(Object.freeze(e))}})(t.fragments,n,(e,t)=>c(e,t,e),a,t.removedFragments),r.length>0&&(e=>{const[t]=e,r=e.length-1,a=r>0?`${t.message} (+ ${r} more issue${1===r?"":"s"})`:t.message;throw new O({code:s.invalidOptions,message:a,path:t.path,...void 0!==t.operator?{operator:t.operator}:{},issues:e})})(r),n},Cr=(t,r,a,n)=>{if(e(t))for(const[o,i]of Object.entries(t)){const t=["operatorDefaults",o],l=r.get(o);if(void 0===l){const e=a.get(o);void 0!==e?n(s.invalidOptions,`'operatorDefaults' keys are canonical names — use '${e}', not its alias '${o}'`,t,e):n(s.unknownOperator,`'${o}' names no registered operator`,t);continue}if(!e(i)){n(s.invalidOptions,`the defaults for '${o}' must be a plain object`,t,o);continue}let c=!0;for(const[e,r]of Object.entries(i)){const a=[...t,e];if(Sr.includes(e)){"noCache"===e&&(!0!==r?(n(s.invalidOptions,"the 'noCache' modifier takes only the literal true",a,o),c=!1):l.definition.cache||(n(s.invalidOptions,`'noCache' on '${o}', which never caches — its definition does not declare 'cache: true'`,a,o),c=!1));continue}const i=l.definition.parameters[e];if(void 0===i){n(s.invalidOptions,`'${e}' names no declared parameter of '${o}' (nor 'fallback'/'noCache')`,a,o),c=!1;continue}if(i.required){n(s.invalidOptions,`'${e}' is a required parameter of '${o}' — operatorDefaults may only target optional parameters`,a,o),c=!1;continue}const u=L(r,i.type);if(u.ok){if(void 0!==i.constraints){const t=J(r,i.constraints);t.ok||(n(s.typeCheck,`the default for '${o}.${e}' violates its declared constraints: expected ${t.expected}, got ${t.actual}`,a,o),c=!1)}}else n(s.typeCheck,`the default for '${o}.${e}' does not satisfy its declared type: expected ${u.expected}, got ${u.actual}`,a,o),c=!1}c&&(l.instanceDefaults=Object.freeze({...i}))}else n(s.invalidOptions,"'operatorDefaults' must be a plain object",["operatorDefaults"])},Nr=(e,t)=>{const r=e.operators.get(t);if(void 0!==r)return r;const a=e.aliases.get(t);return void 0!==a?e.operators.get(a):void 0},zr="fig-tree:scope-settled",Tr="fig-tree:request-expired",Er="fig-tree:evaluation-timeout";class qr{parent;controller;upstream;forward;settled=!1;verified=-1;clock;constructor(e){this.parent=e,this.clock=void 0===e?{epoch:0}:e.clock}get aborted(){return void 0!==this.controller?this.controller.signal.aborted:!!this.settled||this.verified!==this.clock.epoch&&(!(void 0===this.parent||!this.parent.aborted)||(this.verified=this.clock.epoch,!1))}get reason(){return void 0!==this.controller?this.controller.signal.reason:this.settled?zr:this.parent?.reason}get signal(){if(void 0===this.controller){const e=new AbortController;if(this.controller=e,this.settled)e.abort(zr);else if(void 0!==this.parent){const t=this.parent.signal;t.aborted?e.abort(t.reason):(this.upstream=t,this.forward=()=>e.abort(t.reason),t.addEventListener("abort",this.forward,{once:!0}))}}return this.controller.signal}settle(){this.settled||(this.settled=!0,this.clock.epoch+=1,void 0!==this.controller&&(void 0!==this.upstream&&void 0!==this.forward&&this.upstream.removeEventListener("abort",this.forward),this.controller.abort(zr)))}}const Mr=(e,t)=>({get aborted(){return e.aborted},get reason(){return e.reason},signal:e,clock:t.clock,settle:P}),Fr=(e,t,r)=>{const a=void 0===e?(()=>{const e=new AbortController;return{signal:e.signal,abort:t=>e.abort(t),settle:()=>e.abort(zr)}})():(e=>{const t=new AbortController;e.aborted&&t.abort(e.reason);const r=()=>t.abort(e.reason);return e.addEventListener("abort",r,{once:!0}),{signal:t.signal,abort:e=>t.abort(e),settle:()=>{e.removeEventListener("abort",r),t.abort(zr)}}})(e),{signal:n}=a;let o;const s=new Promise((e,t)=>{o=t});s.catch(P);const i=()=>o(n.reason);n.aborted?i():n.addEventListener("abort",i,{once:!0});const l=void 0===t?void 0:setTimeout(()=>a.abort(r),Math.min(t,2147483647));return{signal:n,expiry:s,settle:()=>{void 0!==l&&clearTimeout(l),n.removeEventListener("abort",i),a.settle()}}},Rr=(e,t)=>Fr(e,t,Tr),Ir=(e,t)=>(r,a)=>{const n=(o=[e.operator,e.fingerprint,r],fr(o,[]));var o;return void 0===n?a():(async(e,t,r,a)=>{const n=e.generation,o=await e.lookup(t);if(a?.({type:"cache",hit:o.hit}),o.hit)return o.value;const s=await r();return await e.write(t,s,n),s})(t,n,a,e.note)},Vr=/*#__PURE__*/Object.freeze({}),Lr=(e,t)=>!0!==t||!0===e.noCache?e:{...e,noCache:t};class Jr{options;cache;trace;#e;constructor(e,t,r,a){this.options=t,this.cache=r,this.trace=a,this.#e=e}get signal(){return this.#e.signal}}const Wr={memo:(e,t)=>t()},Br={note:P},Ur=Symbol("fig-tree:internal-error"),Kr=e=>ta(`[fig-tree internal] ${e}`,Ur),Gr=e=>aa(e,Ur),_r=Symbol("fig-tree:cancelled"),Hr=()=>ta("[fig-tree] evaluation cancelled",_r),Qr=e=>aa(e,_r),Xr=(e,t,r)=>e.rootScope.aborted?Yr(e.rootScope.reason,t,r):e.abortScope.aborted?Hr():void 0,Yr=(e,t,r)=>e===zr?Hr():Zr(e,xe(t),{operator:r}),Zr=(e,t,r={})=>{const{operator:a,ms:n}=r,o=e===Er,i=void 0===n?"":`${n}ms `;return new O({code:o?s.timeout:s.aborted,message:o?`evaluation exceeded its ${i}timeout`:"evaluation was aborted by the caller",path:t,...void 0!==a?{operator:a}:{}})},ea=e=>A(e)&&(e.code===s.aborted||e.code===s.timeout),ta=(e,t)=>{const r=new Error(e);return ra(r,t),r},ra=(e,t)=>{e[t]=!0},aa=(e,t)=>e instanceof Error&&!0===e[t],na=()=>performance.now(),oa=e=>{const t=new Map,r=new WeakMap,a=new WeakSet;let n;const o=(e,r,n)=>{const o=t.get(e);if(void 0===o)return;t.delete(e),a.has(e)||("fallback"!==e.status&&(e.status=r),void 0!==n.error&&void 0===e.error&&(e.error=n.error),"failed"!==r&&"cancelled"!==r&&(e.value=n.value),void 0!==n.elapsed&&(e.elapsed=n.elapsed));const s=[...o.children,...sa(o)];s.length>0&&(e.children=s.sort((e,t)=>e.order-t.order||e.index-t.index).map(e=>e.entry))},s=(e,t)=>{(e.events??=[]).push(t)},i=(e,a,o,s)=>{const i=fa(e),l=ma(e),c={path:xe(e.path),kind:da(e),status:"value",...void 0!==o?{source:o}:{},...void 0!==i?{operator:i}:{},...void 0!==l?{ref:l}:{},...void 0!==s?.var?{var:s.var}:{}};return t.set(c,{node:e,children:[],seen:new Set,started:na()}),r.set(e,c),((e,r,a)=>{if(void 0===e)return void(n=r.entry);const o=t.get(e);void 0!==o&&(o.children.push(r),o.seen.add(a))})(a,{entry:c,order:e.order,index:s?.index??0},e),c};return{enter:(e,t,r,a)=>i(e,t,void 0!==r?{fragment:r.fragment}:void 0,a),settle:o,markFallback:(e,t)=>{e.status="fallback",e.error=t},note:s,markShielded:(e,n,l)=>{const c=r.get(e),u=void 0===c?void 0:t.get(c);if(void 0===c||void 0===u)return;a.add(c),c.status="fallback",c.error=n,c.value=l,c.elapsed=na()-u.started,s(c,{type:"shielded-fallback"});const d=pa(e);void 0!==d&&o(i(d,c,c.source,void 0),"value",{value:l})},finish:()=>{for(const e of[...t.keys()].reverse())o(e,"cancelled",{});return void 0!==n&&e.length>0&&(n.warnings=e),n}}},sa=e=>ia(e.node).filter(t=>!e.seen.has(t)).map(e=>({entry:{path:xe(e.path),kind:da(e),status:"skipped"},order:e.order,index:0})),ia=e=>{switch(e.kind){case"operator":return[...Object.values(e.params).flatMap(la),...void 0!==e.fallback?[e.fallback]:[],...Object.values(e.vars??{})];case"fragmentCall":return[...ca(e.parameters),...void 0!==e.fallback?[e.fallback]:[],...Object.values(e.vars??{}),...void 0!==e.entry?[e.entry.body]:[]];case"skeleton":return[...e.holes.map(e=>e.node),...Object.values(e.vars??{})];case"elements":return e.nodes;case"entries":return Object.values(e.entries);default:return[]}},la=e=>"elements"===e.kind||"entries"===e.kind?ia(e):[e],ca=e=>void 0===e?[]:ua(e)?[e]:Object.values(e),ua=e=>"string"==typeof e.kind,da=e=>{switch(e.kind){case"operator":return"operator";case"fragmentCall":return"fragment";case"reference":return"reference";case"skeleton":return"skeleton";default:return"literal"}},pa=e=>"operator"===e.kind||"fragmentCall"===e.kind?e.fallback:void 0,fa=e=>"operator"===e.kind||"fragmentCall"===e.kind?e.name:void 0,ma=e=>"reference"===e.kind?e.raw:void 0,ha=(e,t)=>{if(void 0===t)return e;const r={parent:e.scope,vars:new Map},a={...e,scope:r};for(const[e,n]of Object.entries(t))r.vars.set(e,S(()=>rn(n,a,{var:e})));return a},va=async(e,t,r,a,n)=>{const o={...r,params:"dynamic"===e.argumentsMode?await ga(e,t,a):ya(e,t,a),frame:n};delete o.scope,delete o.bindings;const s=await rn(t.body,o);return void 0===s?null:s},ya=(e,t,r)=>{const a=e.parameters??{},n=new Map;for(const[o,s]of Object.entries(t.parameters)){const t=a[o],i=S(async()=>{if(void 0===t)return ba(e,o,s,r);let a;try{a=await rn(t,r)}catch(e){throw ja(e,r.frame)}return wa(e,o,s,a,t.path,r)});n.set(o,()=>{const e=i();return e.catch(P),e})}return n},ga=async(t,r,a)=>{const n=t.parameters;let o;try{o=await rn(n,a)}catch(e){throw ja(e,a.frame)}if(!e(o))throw ja(ka(t,s.typeCheck,`'parameters' must evaluate to an object, received ${$a(o)}`,n.path),a.frame);const i=new Map;for(const[e,s]of Object.entries(r.parameters)){const r=Object.hasOwn(o,e)?wa(t,e,s,o[e],n.path,a):ba(t,e,s,a,n.path);i.set(e,()=>Promise.resolve(r))}return i},ba=(e,t,r,a,n=e.path)=>{if(!r.required)return r.default??null;throw ja(ka(e,s.missingRequired,`requires '${t}'`,n),a.frame)},wa=(e,t,r,a,n,o)=>{const i=void 0===a?null:a;if(null===i&&!r.required&&!R(r.type))return r.default??null;const l=L(i,r.type);if(!l.ok)throw ja(ka(e,s.typeCheck,`parameter '${t}': expected ${l.expected}, received ${l.actual}`,n),o.frame);if(void 0!==r.constraints){const a=J(i,r.constraints);if(!a.ok)throw ja(ka(e,s.typeCheck,`parameter '${t}': expected ${a.expected}, received ${a.actual}`,n),o.frame)}return i},ka=(e,t,r,a)=>new O({code:t,message:`fragment '${e.name}' – ${r}`,path:xe(a)}),$a=e=>null===e?"null":Array.isArray(e)?"array":typeof e,xa=Symbol("fig-tree:anchored"),ja=(e,t)=>!A(e)||aa(e,xa)?e:(ra(e,xa),void 0===t||(e.fragment=t.fragment,e.fragmentPath=e.path,e.path=xe(t.callPath)),e);class Oa extends Error{code;errorData;constructor(e,t={}){super(e),this.name="OperatorFailure",void 0!==t.code&&(this.code=t.code),void 0!==t.errorData&&(this.errorData=t.errorData)}}const Pa=e=>e instanceof Oa,Aa=(e,t,r)=>Da(Array.from({length:e},(e,a)=>Sa(a,()=>t(a),r)),e),Sa=async(e,t,r)=>{try{return{index:e,ok:!0,value:r(await t())}}catch(t){return{index:e,ok:!1,error:t}}},Da=(e,t)=>{const r=new Map(e.map((e,t)=>[t,e]));return{[ur]:!0,length:t,async*[Symbol.asyncIterator](){for(;r.size>0;){const e=await Promise.race(r.values());r.delete(e.index),yield e}}}},Ca=e=>({[ur]:!0,evaluate:S(e)}),Na=e=>({[ur]:!0,evaluate:()=>Promise.resolve(e)}),za=(e,t,r,a,n)=>Ca(async()=>Ta(await rn(e,n),t,r,a)),Ta=(e,t,r,a)=>{const n=L(e,a.type);if(!n.ok)throw Ra(t,r,n);if(null!==e&&void 0!==a.constraints){const n=G(e,a.constraints,void 0!==a.elementNullPolicy);if(!n.ok)throw Ra(t,r,n)}return a.truthiness?Ja(e,a.type):e},Ea=(e,t,r,a,n,o)=>{const s=Array.isArray(t)?t:[],i=Pe(r),l=new Map,c=t=>{const c=l.get(t);if(void 0!==c)return c;const u=(async()=>Ta(await rn(e,((e,t,r,a)=>({...e,bindings:{parent:e.bindings,as:t,element:r,index:a}}))(o,i,s[t],t),{index:t}),r,a,n))();return u.catch(P),l.set(t,u),u};return{[ur]:!0,evaluate:c,settle:()=>Aa(s.length,c,e=>e)}},qa=(e,t)=>t.truthiness?ne(e):e,Ma=(e,t,r)=>{if("lazyElements"===t.evaluation&&"elements"===e.kind)return e.nodes.map((e,a)=>Ca(async()=>qa(await rn(e,r,{index:a}),t)));if("race"===t.evaluation&&"elements"===e.kind)return((e,t,r)=>Aa(e.length,r=>rn(e[r],t,{index:r}),r))(e.nodes,r,e=>qa(e,t));if("lazyEntries"===t.evaluation&&"entries"===e.kind){const a=ha(r,e.vars),n={};for(const[r,o]of Object.entries(e.entries))n[r]=Ca(async()=>qa(await rn(o,a),t));return n}},Fa=(e,t)=>{switch(t.evaluation){case"lazyElements":return e.map(e=>Na(qa(e,t)));case"race":return((e,t)=>Aa(e.length,t=>Promise.resolve(e[t]),t))(e,e=>qa(e,t));case"lazyEntries":{const r={};for(const[a,n]of Object.entries(e))r[a]=Na(qa(n,t));return r}case"lazy":return Na(e);default:return e}},Ra=(e,t,r)=>new O({code:s.typeCheck,message:`${e.name} – parameter '${t}': expected ${r.expected}, received ${r.actual}`,path:xe(e.path),operator:e.name}),Ia=(e,t,r)=>{if("string"==typeof t.nullPolicy)return t.nullPolicy;const a=t.nullPolicy,n=e.entry.definition.parameters[a.selector],o=r[a.selector],s=L(o,n.type);if(!s.ok)throw Ra(e,a.selector,s);const i=a.table.find(e=>e.value===o);if(void 0===i)throw Kr(`no null-policy row for ${e.name}.${a.selector}`);return i.policy},Va=async(t,r,a)=>{if(void 0!==r.elementNullPolicy){if(Array.isArray(t)&&t.includes(null)){const e=await a();return t.map(t=>null===t?e:t)}if(e(t)&&Object.values(t).includes(null)){const e=await a(),r={};for(const[a,n]of Object.entries(t))r[a]=null===n?e:n;return r}return t}return null===t?a():t},La=t=>Array.isArray(t)?t.includes(null):!!e(t)&&Object.values(t).includes(null),Ja=(t,r)=>{if((e=>!("object"==typeof e&&!Array.isArray(e))&&(Array.isArray(e)?e:[e]).every(e=>"array"===e||"object"===e))(r)){if(Array.isArray(t))return t.map(ne);if(e(t)){const e={};for(const[r,a]of Object.entries(t))e[r]=ne(a);return e}}return ne(t)},Wa=async(e,t)=>{const{params:r,propagate:a}=await(async(e,t)=>{const{definition:r,instanceDefaults:a}=e.entry,{entries:n,whole:o,perElement:s}=r.resolution,i=[],l=[],c={};let u;const d={};for(const[r,o]of n){const n=e.params[r];switch(o.evaluation){case"eager":void 0!==n&&(i.push(r),l.push(rn(n,t)));break;case"structural":"constant"===n?.kind&&(c[r]=n.value);break;case"lazy":if(void 0!==o.replacesNullAt){const e=void 0!==n?S(()=>rn(n,t)):void 0!==a&&Object.hasOwn(a,r)?S(()=>a[r]):void 0;if(void 0!==e)for(const t of o.replacesNullAt)(u??={})[t]=e;break}void 0!==n&&(d[r]=za(n,e,r,o,t));break;case"lazyElements":case"lazyEntries":case"race":{if(void 0===n)break;const e=Ma(n,o,t);if(void 0!==e){d[r]=e;break}i.push(r),l.push(rn(n,t));break}case"perElement":break;default:o.evaluation}}if(l.length>0)if(1===l.length){const e=l[0];c[i[0]]=D(e)?await e:e}else{const e=await Promise.all(l);i.forEach((t,r)=>{c[t]=e[r]})}for(const[e,r]of o){if(Object.hasOwn(d,e))continue;const n=c[e];(void 0===n||null===n&&!r.required&&!R(r.type))&&(void 0!==a&&Object.hasOwn(a,e)?c[e]=a[e]:"default"in r?c[e]=r.default===H?t.data:r.default:delete c[e])}for(const[t,r]of o){if(Object.hasOwn(d,t))continue;let a=c[t];if(void 0===a)continue;const n=u?.[t];void 0!==n&&(a=await Va(a,r,n));const o="eager"!==r.evaluation&&"structural"!==r.evaluation;if(null===a&&R(r.type)&&!o&&"propagate"===Ia(e,r,c))return{params:d,propagate:!0};if("propagate"===r.elementNullPolicy&&La(a))return{params:d,propagate:!0};a=Ta(a,e,t,r),d[t]=Fa(a,r)}for(const[r,a]of s){if(void 0===a.over)throw Kr(`parameter '${r}' of '${e.name}' declares perElement without 'over'`);const n=e.params[r];void 0!==n&&(d[r]=Ea(n,d[a.over],e,r,a,t))}return{params:d,propagate:!1}})(e,t);if(a)return null;const{definition:n}=e.entry,o=!0!==t.noCache&&Ar(e.entry),s=Ua(n,r),i=void 0===s?void 0:Rr(t.abortScope.signal,s),l=void 0===i?t:{...t,abortScope:Mr(i.signal,t.abortScope)},c=(e=>{const{trace:t,traceParent:r}=e;if(void 0!==t&&void 0!==r)return e=>{t.note(r,e)}})(t),u=((e,t,r,a)=>new Jr(e.abortScope,e.options,r?{memo:Ir({operator:t.name,fingerprint:t.fingerprint,note:a},e.cache)}:Wr,void 0===a?Br:{note:a}))(l,n,o,c);try{return await Ba(e,t,r,u,i)}catch(r){throw Ka(r,e,t,i,s)}finally{i?.settle()}},Ba=async(e,t,r,a,n)=>{const o=Xr(t,e.path,e.name);if(void 0!==o)throw o;const s=Promise.resolve(e.entry.definition.evaluate(r,a));return void 0===n?_a(await s,e):(s.catch(P),_a(await Promise.race([s,n.expiry]),e))},Ua=(e,t)=>{const r=e.timeoutParam;if(null===r)return;const a=t[r];return"number"==typeof a&&a>0?a:void 0},Ka=(e,t,r,a,n)=>{if(Gr(e)||Qr(e))return e;const o=Xr(r,t.path,t.name);return void 0!==o?o:a?.signal.reason===Tr?new Oa(`request exceeded its ${String(n)}ms timeout`,{code:s.requestTimeout}):e},Ga=(e,t)=>{const r=e.fallback;if(void 0!==r)return()=>rn(r,t);const a=e.entry.instanceDefaults;return void 0!==a&&Object.hasOwn(a,"fallback")?()=>a.fallback:void 0},_a=(e,t)=>{if(void 0===e)return null;if("number"==typeof e&&!Number.isFinite(e))throw new O({code:s.nonFiniteResult,message:`${t.name} – produced a non-finite number (${String(e)})`,path:xe(t.path),operator:t.name});if("object"==typeof(r=e)&&null!==r&&!0===r[ur])throw new O({code:s.escapedHandle,message:`${t.name} – returned a lazy handle instead of evaluating it`,path:xe(t.path),operator:t.name});var r;return e},Ha=(e,t)=>{if(A(e))return e;if(Pa(e))return new O({code:e.code??s.operatorFailure,message:`${t.name} – ${e.message}`,path:xe(t.path),operator:t.name,...void 0!==e.errorData?{errorData:e.errorData}:{}});const r=e instanceof Error?e.message:String(e);return new O({code:s.operatorFailure,message:`${t.name} – ${r}`,path:xe(t.path),operator:t.name})},Qa=(e,t)=>0===e.segments.length?t.data:en(t.data,e.segments,e,t,"is absent from the evaluation data"),Xa=async(e,t)=>{const[r,...a]=e.segments,n="string"==typeof r?((e,t)=>{for(let r=e;void 0!==r;r=r.parent){const e=r.vars.get(t);if(void 0!==e)return e}})(t.scope,r):void 0;if("string"!=typeof r||void 0===n)throw Kr(`'${e.raw}': no var named '${String(r)}' is in scope — the static gate should have refused it`);const o=await n();return 0===a.length?tn(o):en(o,a,e,t,`is absent from the value of '$vars.${r}'`)},Ya=async(e,t)=>{const r=t.params;if(void 0===r)throw Kr(`'${e.raw}': $params outside a fragment body — the static gate should have refused it`);const[a,...n]=e.segments;if(void 0===a){const e={};return await Promise.all([...r].map(async([t,r])=>{e[t]=tn(await r())})),e}const o="string"==typeof a?r.get(a):void 0;if(void 0===o)throw Kr(`'${e.raw}': the fragment declares no parameter '${String(a)}' — the static gate should have refused it`);const s=await o();return 0===n.length?tn(s):en(s,n,e,t,`is absent from the value of '$params.${String(a)}'`)},Za=(e,t)=>{const r=e.namespace,a=((e,t,r)=>{for(let a=e;void 0!==a;a=a.parent)if(Ae(a.as,t,r))return a})(t.bindings,r,e.binding);if(void 0===a)throw Kr(`'${e.raw}': no enclosing iterator binds it — the static gate should have refused it`);return"index"===r?a.index:0===e.segments.length?tn(a.element):en(a.element,e.segments,e,t,`is absent from '${e.raw.split(".")[0]}'`)},en=(e,t,r,a,n)=>{const o=k(e,t);if(o.found)return tn(o.value);if(!a.strictDataPaths)return null;throw new O({code:s.missingDataPath,message:`'${r.raw}' ${n} (strictDataPaths)`,path:xe(r.path)})},tn=e=>void 0===e?null:e,rn=(e,t,r)=>void 0!==t.trace?an(e,t,t.trace,r):t.abortScope.aborted?Promise.reject(Xr(t,e.path)):nn(e,t),an=async(e,t,r,a)=>{const n=r.enter(e,t.traceParent,t.frame,a),o=na();try{if(t.abortScope.aborted)throw Xr(t,e.path);const a=await nn(e,{...t,traceParent:n});return r.settle(n,"value",{value:a,elapsed:na()-o}),a}catch(e){throw r.settle(n,Qr(e)?"cancelled":"failed",{...A(e)?{error:e}:{},elapsed:na()-o}),e}},nn=(e,t)=>{try{switch(e.kind){case"constant":return e.value;case"reference":return((e,t)=>{switch(e.namespace){case"data":return Qa(e,t);case"vars":return Xa(e,t);case"params":return Ya(e,t);case"element":case"index":return Za(e,t)}})(e,t);case"skeleton":return on(e,t);case"operator":return(async(e,t)=>{const r=ha(Lr(t,e.noCache),e.vars),a=e.entry.definition.deliversLazily?new qr(r.abortScope):void 0,n=void 0===a?r:{...r,abortScope:a};try{try{return await Wa(e,n)}finally{a?.settle()}}catch(a){if(Gr(a)||Qr(a)||ea(a))throw a;const n=Ha(a,e),o=Ga(e,r);if(void 0===o)throw n;try{const e=await o();return void 0!==t.trace&&void 0!==t.traceParent&&t.trace.markFallback(t.traceParent,n),e}catch(t){if(Gr(t)||Qr(t)||ea(t))throw t;const r=Ha(t,e);throw void 0===r.cause&&(r.cause=n),r}}})(e,t);case"fragmentCall":return(async(e,t)=>{const{entry:r}=e;if(void 0===r)throw Kr(`fragment call '${e.name}' resolved to nothing — the static gate should have refused it`);const a=ha(Lr(t,e.noCache),e.vars),n=new qr(a.abortScope),o={fragment:e.name,callPath:t.frame?.callPath??e.path},s={...a,abortScope:n};try{try{return await va(e,r,s,a,o)}finally{n.settle()}}catch(r){if(Gr(r)||Qr(r)||ea(r))throw r;const n=ja(r,o),{fallback:s}=e;if(void 0===s)throw n;try{const e=await rn(s,a);return void 0!==t.trace&&void 0!==t.traceParent&&A(n)&&t.trace.markFallback(t.traceParent,n),e}catch(e){if(Gr(e)||Qr(e)||ea(e))throw e;const r=ja(e,t.frame);throw A(r)&&void 0===r.cause&&(r.cause=n),r}}})(e,t);case"elements":case"entries":throw Kr(`a '${e.kind}' parameter value reached the node dispatch — parameter resolution consumes these, and nothing else may hold one`);case"invalid":throw Kr("an invalid node reached evaluation — the static gate should have refused it")}}catch(e){return Promise.reject(e)}},on=async(e,t)=>{const r=t.rootBoundary,a=void 0===r?t:{...t,rootBoundary:void 0},n=ha(a,e.vars),o=e.holes.map(e=>void 0===r?rn(e.node,n):r(()=>rn(e.node,n),e.node)),s=o.some(D)?await Promise.all(o):o;return De(e.skeleton,e.holes,s)},sn=async(e,t,r)=>{const{timeout:a,signal:n}=t,o=e.holes.length>0,s=void 0!==a||void 0!==n?Fr(n,a,Er):void 0,i=void 0!==s?((e,t)=>{const r={epoch:0};return e.addEventListener("abort",()=>{r.epoch+=1},{once:!0}),{get aborted(){return e.aborted},get reason(){return e.reason},signal:e,clock:r,settle:t}})(s.signal,s.settle):new qr(void 0),l=void 0!==s&&void 0!==a&&e.timeoutShielded&&o,c=!0===t.trace?oa(e.issues.map(e=>e.issue).filter(e=>"error"!==e.severity)):void 0,u=((e,t,r,a)=>({options:e,data:e.data??Vr,abortScope:r,rootScope:r,cache:t,strictDataPaths:e.strictDataPaths??!1,...void 0!==a?{trace:a}:{}}))(t,r,i,c),d=l?cn(e,s.expiry,a,c):void 0,p=void 0!==d&&"skeleton"!==e.root.kind,f=void 0===d||p?u:{...u,rootBoundary:d};try{if(i.aborted)throw Zr(i.reason,[]);const t=()=>p&&void 0!==d?d(()=>rn(e.root,f),e.root):rn(e.root,f),r=await(l||void 0===s?t():ln(t,s,a));return void 0!==c?{result:r,trace:c.finish()}:{result:r}}catch(e){throw void 0!==c&&A(e)&&void 0===e.trace&&(e.trace=c.finish()),e}finally{i.settle()}},ln=(e,t,r)=>Promise.race([e(),t.expiry.catch(e=>{throw Zr(e,[],{ms:r})})]),cn=(e,t,r,a)=>{const n=new Map(e.holes.map(e=>[e.node,e]));return(e,o)=>{const s=n.get(o);if(void 0===s)throw Kr(`the hole boundary was handed the node at ${JSON.stringify(xe(o.path))}, which is not one of the artifact's holes`);let i=!1;const l=Promise.resolve(e()).then(e=>(i=!0,e));return Promise.race([l,t.catch(e=>{if(e!==Er)throw Zr(e,[]);if(i)return;const t=dn(s);return a?.markShielded(s.node,un(s,e,r),t),t})])}},un=(e,t,r)=>{const{node:a}=e,n="operator"===a.kind?a.name:void 0;return Zr(t,xe(a.path),{operator:n,ms:r})},dn=e=>{if(void 0===e.timeoutFallback)throw Kr("a shielded artifact has a hole with no static fallback");return e.timeoutFallback.value},pn={hit:!1},fn=e=>{if(void 0===e)return{maxSize:50,maxTime:1800};if(!n(e))throw hn("'cache' must be an object");const{store:t,maxSize:r,maxTime:a}=e;if(void 0!==t&&!mn(t))throw hn("'cache.store' must provide get, set, delete and clear methods");if(void 0!==r&&(!Number.isInteger(r)||r<1))throw hn("'cache.maxSize' must be a positive integer");if(void 0!==a&&("number"!=typeof a||a<=0||Number.isNaN(a)))throw hn("'cache.maxTime' must be a positive number of seconds, or Infinity");return{...void 0!==t?{store:t}:{},maxSize:r??50,maxTime:a??1800}},mn=e=>"object"==typeof e&&null!==e&&["get","set","delete","clear"].every(t=>"function"==typeof e[t]),hn=e=>new O({code:s.invalidOptions,message:e,path:[]});class vn{store;own;maxTime;current=0;constructor(e){void 0===e.store?(this.own=new lr(e.maxSize),this.store=this.own):this.store=e.store,this.maxTime=e.maxTime}get generation(){return this.current}async lookup(e){let t;try{t=await this.store.get(e)}catch{return pn}return n(r=t)&&"ft3"===r.fig&&"number"==typeof r.generation?t.generation<this.current||yn(t)?(this.drop(e),pn):{hit:!0,value:t.value}:pn;var r}async write(e,t,r){if(r!==this.current)return;const a={fig:"ft3",value:t,generation:r,...Number.isFinite(this.maxTime)?{expiresAt:Date.now()+1e3*this.maxTime}:{}};try{await this.store.set(e,a)}catch{}}clear(){this.current+=1;try{Promise.resolve(this.store.clear()).catch(P)}catch{}}configure(e){void 0!==e.store&&e.store!==this.store&&(this.store=e.store,this.own=void 0),this.maxTime=e.maxTime,this.own?.resize(e.maxSize)}drop(e){try{Promise.resolve(this.store.delete(e)).catch(P)}catch{}}}const yn=e=>void 0!==e.expiresAt&&e.expiresAt<=Date.now(),gn=e=>e===C?0:"number"==typeof e?1:2,bn=e=>({data:{paths:[...e.dataPaths].sort(([,e],[,t])=>((e,t)=>{const r=Math.min(e.length,t.length);for(let a=0;a<r;a++){const r=e[a],n=t[a];if(r===n)continue;const o=gn(r)-gn(n);return 0!==o?o:"number"==typeof r&&"number"==typeof n?r-n:r<n?-1:1}return e.length-t.length})(e,t)).map(([e])=>e),dynamic:e.dynamic},operators:[...e.operators],fragments:[...e.fragments]}),wn=(e,t)=>{const r={};for(const[a,n]of Object.entries(e)){const e={...n};void 0!==t&&Object.hasOwn(t,a)&&(e.instanceDefault=t[a]),r[a]=e}return r},kn=(e,t)=>{const r=[];return void 0!==t.maxDepth&&e.maxDepth>t.maxDepth&&r.push($n(e.maxDepth,t.maxDepth)),void 0!==t.maxNodes&&e.nodeCount>t.maxNodes&&r.push({severity:"error",code:s.maxNodesExceeded,message:`the expression holds ${e.nodeCount} evaluable nodes — maxNodes is ${t.maxNodes}`,path:[]}),r},$n=(e,t)=>({severity:"error",code:s.maxDepthExceeded,message:`the expression nests ${e} levels deep — maxDepth is ${t}`,path:[]}),xn=(e,t,r)=>{const a=[...kn(e,t),...e.issues.map(r)];return void 0!==t.data&&a.push(...jn(e.dataReads,t.data)),a},jn=(e,t)=>{const r=new Map,a=new Map,n=[],o=(e,o,i,l)=>{let c=r.get(e);if(void 0===c&&(c=k(t,o).found,r.set(e,c)),c)return;let u=a.get(i.path);if(void 0===u&&a.set(i.path,u=new Set),u.has(e))return;u.add(e);const d=void 0===l?"":` (read by fragment '${l}')`;n.push({severity:"warning",code:s.missingDataPath,message:`'${N(o)}' is absent from the supplied sample data${d}`,path:xe(i.path)})};for(const t of e)if("path"===t.kind)o(t.key,t.segments,t,void 0);else for(const[e,r]of t.fragment.dependencies.dataPaths)o(e,r,t,t.fragment.name);return n},On="...",Pn=/*#__PURE__*/new Set(["propagate","value"]),An=e=>e,Sn=e=>{const t={};for(const[r,a]of Object.entries(e.parameters))t[r]=a.type??"any";const r=Dn(e.parameters,t,(t,r,a)=>{throw new O({code:t,message:r,path:a,operator:e.name})});return Cn(e,r)},Dn=(e,r,a)=>{const n=Object.entries(r).filter(([,e])=>t(e)).map(([e])=>e),o=new Map;for(const[i,l]of Object.entries(e)){if("function"!=typeof l.nullPolicy)continue;const e=["parameters",i,"nullPolicy"];if(1!==n.length){a(s.invalidNullPolicy,`a conditional 'nullPolicy' requires exactly one literal-union parameter in the definition — found ${n.length}`,e,i);continue}const c=n[0],u=r[c];if(!t(u))continue;const d=[];let p=!0;for(const t of u.literal){let r;try{r=l.nullPolicy(t)}catch(r){a(s.invalidNullPolicy,`the conditional 'nullPolicy' threw during compilation for member ${JSON.stringify(t)}: ${String(r)}`,e,i),p=!1;break}if("string"!=typeof r||!Pn.has(r)){a(s.invalidNullPolicy,`the conditional 'nullPolicy' must return 'propagate' or 'value' for every member — got ${JSON.stringify(r)} for ${JSON.stringify(t)}`,e,i),p=!1;break}d.push({value:t,policy:r})}p&&o.set(i,{selector:c,table:d})}return o},Cn=(e,t)=>{const r={};for(const[a,n]of Object.entries(e.parameters)){const e=t.get(a),o="string"==typeof n.nullPolicy?n.nullPolicy:void 0,s=n.type??"any",i=!0===n.truthiness&&R(s)?"value":"propagate",l={type:zn(s),required:n.required??!("default"in n),evaluation:n.evaluation??"eager",truthiness:n.truthiness??!1,nullPolicy:e??o??i};"default"in n&&(l.default=n.default),void 0!==n.description&&(l.description=n.description),void 0!==n.metadata&&(l.metadata=n.metadata),void 0!==n.elementNullPolicy&&(l.elementNullPolicy=n.elementNullPolicy),void 0!==n.constraints&&(l.constraints=Tn(n.constraints)),void 0!==n.over&&(l.over=n.over),void 0!==n.replacesNullAt&&(l.replacesNullAt=[...n.replacesNullAt]),r[a]=l}const a=e.positionalParams?.at(-1),n=a?.startsWith(On)?a.slice(3):null,o={[Q]:!0,name:e.name,category:e.category,description:e.description,parameters:r,resolution:En(r),restParam:n,deliversLazily:Object.values(r).some(e=>"eager"!==e.evaluation&&"structural"!==e.evaluation),timeoutParam:e.timeoutParam??null,cache:!0===e.cache,fingerprint:"",evaluate:e.evaluate,returns:void 0!==e.returns?zn(e.returns):"any"};return void 0!==e.alias&&(o.alias=e.alias),void 0!==e.metadata&&(o.metadata=e.metadata),void 0!==e.positionalParams&&(o.positionalParams=[...e.positionalParams]),void 0!==e.validate&&(o.validate=e.validate),void 0!==e.analysis&&(o.analysis=Tn(e.analysis)),o.fingerprint=Nn(o),qn(o)},Nn=e=>z(JSON.stringify([e.name,e.parameters,e.positionalParams,e.restParam,e.returns,e.cache,e.timeoutParam,e.evaluate,e.validate],(e,t)=>"function"==typeof t||"symbol"==typeof t||t instanceof RegExp?String(t):t)),zn=e=>"string"==typeof e?e:t(e)?{literal:[...e.literal]}:[...e],Tn=t=>{if(Array.isArray(t))return t.map(Tn);if(e(t)){const e={};for(const[r,a]of Object.entries(t))e[r]=Tn(a);return e}return t},En=e=>{const t=Object.entries(e);return{entries:t,whole:t.filter(([,e])=>void 0===e.replacesNullAt&&"perElement"!==e.evaluation),perElement:t.filter(([,e])=>"perElement"===e.evaluation)}},qn=e=>{for(const t of Object.values(e.parameters))"string"!=typeof t.type&&Object.freeze(t.type),"object"==typeof t.type&&"literal"in t.type&&Object.freeze(t.type.literal),"object"==typeof t.nullPolicy&&(t.nullPolicy.table.forEach(e=>Object.freeze(e)),Object.freeze(t.nullPolicy.table),Object.freeze(t.nullPolicy)),void 0!==t.constraints&&Mn(t.constraints),void 0!==t.replacesNullAt&&Object.freeze(t.replacesNullAt),Object.freeze(t);Object.freeze(e.parameters);for(const t of Object.values(e.resolution))t.forEach(e=>Object.freeze(e)),Object.freeze(t);return Object.freeze(e.resolution),"string"!=typeof e.returns&&Object.freeze(e.returns),void 0!==e.positionalParams&&Object.freeze(e.positionalParams),Object.freeze(e)},Mn=t=>{Array.isArray(t)?(t.forEach(Mn),Object.freeze(t)):e(t)&&(Object.values(t).forEach(Mn),Object.freeze(t))},Fn=e=>{if(Array.isArray(e))return e;try{return g(e)}catch(e){throw new Oa(e.message)}},Rn=(e,t)=>{if("string"!=typeof e)return[];try{return g(e),[]}catch(e){return[{severity:"error",parameter:t,message:e.message}]}},In=e=>Array.isArray(e.values)&&0===e.values.length?[{severity:"error",parameter:"values",message:"an empty values array has no result — supply at least one value"}]:[],Vn=e=>t=>{const r=t[e];return Array.isArray(r)&&0===r.length?[{severity:"warning",parameter:e,message:`an empty ${e} array is a dead expression — the result is always the identity`}]:[]},Ln=/*#__PURE__*/Vn("values"),Jn=/*#__PURE__*/Vn("input"),Wn=/*#__PURE__*/Vn("entries"),Bn=e=>Array.isArray(e.values)&&e.values.length<2?[{severity:"warning",parameter:"values",message:"fewer than two values is a dead comparison — the result never varies"}]:[],Un=(e,t)=>new Oa(`${e} of nothing — the values array is empty${void 0!==t?`; ${t}`:""}`,{code:s.emptyAggregate}),Kn=async(e,t)=>{const r=[];for await(const a of e){if(a.ok&&a.value===t)return t;a.ok||r.push(a)}if(r.length>0)throw r.sort((e,t)=>e.index-t.index),Gn(r);return!t},Gn=e=>{const[t,...r]=e,a=r.map(e=>e.error).filter(A);return a.length>0&&A(t.error)&&void 0===t.error.related&&(t.error.related=a),t.error},_n=async e=>{const t=new Array(e.length);let r=0;for await(const a of e){t[a.index]=a;for(let e=t[r];void 0!==e;e=t[r]){if(!e.ok)throw e.error;r+=1}}return t.map(e=>e?.value)},Hn=(e,t)=>{const r=e=>t&&"string"==typeof e?e.toLowerCase():e;if(e.length<2)return!0;const a=r(e[0]);return e.every(e=>ve(r(e),a))},Qn={values:{type:"array",elementNullPolicy:"value",description:"The values compared; null is comparable (null equals null)"},caseInsensitive:{type:"boolean",default:!1,description:"Fold string operands to one case before comparing (shallow)"}},Xn={name:"equal",alias:"=",category:"comparison",description:"Are all the values equal? Deep, structural, key-order-insensitive; a cross-type comparison is false",parameters:Qn,positionalParams:["...values"],returns:"boolean",validate:Bn,evaluate:({values:e,caseInsensitive:t})=>Hn(e,t)},Yn={name:"notEqual",alias:"!=",category:"comparison",description:'Are the values NOT all equal? The exact negation of equal (never "all distinct")',parameters:Qn,positionalParams:["...values"],returns:"boolean",validate:Bn,evaluate:({values:e,caseInsensitive:t})=>!Hn(e,t)},Zn=(e,t,r,a)=>({name:e,alias:t,category:"comparison",description:r,parameters:{values:{type:"array",elementNullPolicy:"propagate",constraints:{length:2,homogeneous:["number","string"]},description:"Exactly two operands: both numbers, or both strings (codepoint order)"},nullValueDefault:{type:["number","string"],required:!1,evaluation:"lazy",replacesNullAt:["values"],description:"Replaces a null operand before comparing"}},positionalParams:["...values"],returns:"boolean",evaluate:({values:e})=>{const[t,r]=e;return a(oe(t,r))}}),eo=/*#__PURE__*/Zn("greaterThan",">","Is the first value strictly greater than the second?",e=>e>0),to=/*#__PURE__*/Zn("greaterThanOrEqual",">=","Is the first value greater than or equal to the second?",e=>e>=0),ro=/*#__PURE__*/Zn("lessThan","<","Is the first value strictly less than the second?",e=>e<0),ao=/*#__PURE__*/Zn("lessThanOrEqual","<=","Is the first value less than or equal to the second?",e=>e<=0),no={number:()=>0,string:()=>"",array:()=>[],object:()=>({})},oo=t=>"number"==typeof t?"number":"string"==typeof t?"string":Array.isArray(t)?"array":e(t)?"object":void 0,so={name:"plus",alias:"+",category:"math",description:"Add numbers, concatenate strings or arrays, or shallow-merge objects — all operands must share one type",parameters:{values:{type:"array",elementNullPolicy:"propagate",constraints:{homogeneous:["number","string","array","object"]},description:"The operands; homogeneous: all numbers, strings, arrays or objects"},expect:{type:{literal:["number","string","array","object"]},required:!1,description:"Pin the mode: every operand must be this type, and an empty input yields its identity"},nullValueDefault:{type:["number","string","array","object"],required:!1,evaluation:"lazy",replacesNullAt:["values"],description:"Replaces any null operand before the addition"}},positionalParams:["...values"],returns:["number","string","array","object"],validate:({values:e,expect:t})=>void 0!==t?Ln({values:e}):In({values:e}),evaluate:({values:e,expect:t})=>{if(0===e.length){if(void 0===t)throw Un("the sum","pin the mode with 'expect' to get its identity");return no[t]()}const r=t??oo(e[0]),a=e.find(e=>oo(e)!==r);if(void 0!==a)throw n=`all operands must be ${r}s — received ${q(a)}`,new Oa(n,{code:s.typeCheck});var n;switch(r){case"number":return e.reduce((e,t)=>e+t,0);case"string":return e.join("");case"array":return e.flat(1);case"object":return Object.assign({},...e)}}},io={name:"subtract",alias:"-",category:"math",description:"Subtract one number from another",parameters:{value:{type:["number","null"],description:"The main operand"},minus:{type:["number","null"],description:"The amount subtracted from value"}},positionalParams:["value","minus"],returns:"number",evaluate:({value:e,minus:t})=>e-t},lo={name:"divide",alias:"/",category:"math",description:"Divide one number by another — true division; zero divisors fail",parameters:{value:{type:["number","null"],description:"The main operand"},by:{type:["number","null"],description:"The divisor"}},positionalParams:["value","by"],returns:"number",evaluate:({value:e,by:t})=>e/t},co={name:"modulo",category:"math",description:"The floored remainder: the result takes the sign of mod, so modulo(-7, 3) is 2",parameters:{value:{type:["number","null"],description:"The main operand"},mod:{type:["number","null"],description:"The modulus"}},positionalParams:["value","mod"],returns:"number",evaluate:({value:e,mod:t})=>(e%t+t)%t},uo={name:"multiply",alias:"*",category:"math",description:"Multiply numbers together — an empty input is 1, the empty product",parameters:{values:{type:"array",elementNullPolicy:"propagate",constraints:{homogeneous:["number"]},description:"The factors"},nullValueDefault:{type:"number",required:!1,evaluation:"lazy",replacesNullAt:["values"],description:"Replaces any null factor before multiplying"}},positionalParams:["...values"],returns:"number",validate:Ln,evaluate:({values:e})=>e.reduce((e,t)=>e*t,1)},po={name:"power",alias:"^",category:"math",description:"Raise a base to an exponent — overflow and complex results fail",parameters:{base:{type:["number","null"],description:"The number to raise"},exponent:{type:["number","null"],description:"The power to raise it to"}},positionalParams:["base","exponent"],returns:"number",evaluate:({base:e,exponent:t})=>e**t},fo={name:"round",category:"math",description:"Round to a number of decimal places — ties go half away from zero; negative decimals round to tens, hundreds, …",parameters:{value:{type:["number","null"],description:"The number to round"},decimals:{type:"integer",default:0,description:"Decimal places to keep; negative values round to powers of ten"}},positionalParams:["value","decimals"],returns:"number",evaluate:({value:e,decimals:t})=>((e,t=0)=>{if(!Number.isFinite(e))return e;const r=e<0?-1:1,a=Math.round(fe(Math.abs(e),t));return r*fe(a,-t)})(e,t)},mo=(e,t,r,a,n="number")=>({name:e,category:"math",description:t,parameters:{value:{type:["number","null"],description:r}},positionalParams:["value"],returns:n,evaluate:({value:e})=>a(e)}),ho=/*#__PURE__*/mo("floor","Round down toward negative infinity","The number to round down",Math.floor,"integer"),vo=/*#__PURE__*/mo("ceil","Round up toward positive infinity","The number to round up",Math.ceil,"integer"),yo=/*#__PURE__*/mo("abs","The absolute value","The number",Math.abs),go=(e,t,r,a)=>({name:e,category:"math",description:r,parameters:{values:{type:"array",elementNullPolicy:"propagate",constraints:{homogeneous:["number","string"]},description:"The candidates: all numbers, or all strings (codepoint order)"},nullValueDefault:{type:["number","string"],required:!1,evaluation:"lazy",replacesNullAt:["values"],description:"Replaces any null candidate before comparing"}},positionalParams:["...values"],returns:["number","string"],validate:In,evaluate:({values:e})=>{const r=e;if(0===r.length)throw Un(t);return r.reduce((e,t)=>a(oe(t,e))?t:e)}}),bo=(e,t,r,a)=>({name:e,category:"string",description:t,parameters:{value:{type:["string","null"],description:r}},positionalParams:["value"],returns:"string",evaluate:({value:e})=>a(e)}),wo={name:"split",category:"string",description:"Divide a string on a delimiter into an array of pieces — empty pieces are kept; an empty delimiter splits into code points",parameters:{value:{type:["string","null"],description:"The string to divide"},delimiter:{type:"string",default:" ",description:'Split on each occurrence; "" splits into code points'},trim:{type:"boolean",default:!0,description:"Trim whitespace from each piece"}},positionalParams:["value","delimiter"],returns:"array",evaluate:({value:e,delimiter:t,trim:r})=>{const a=""===t?pe(e):e.split(t);return r?a.map(ie):a}},ko=e=>Array.isArray(e.values)&&e.values.some(te)?[{severity:"error",parameter:"values",message:re}]:[],$o={name:"join",category:"string",description:"Render array elements to text and concatenate them with a delimiter",parameters:{values:{type:"array",elementNullPolicy:"value",description:'Elements of any type, rendered by the stringification table; a null renders "" and still occupies its slot'},delimiter:{type:"string",default:" ",description:"Placed between each adjacent pair — shares its contract with split"},nullValueDefault:{type:["string","number","boolean"],required:!1,evaluation:"lazy",replacesNullAt:["values"],description:'Rendered in place of a null element, instead of ""'}},positionalParams:["...values"],returns:"string",validate:e=>[...Ln(e),...ko(e)],evaluate:({values:e,delimiter:t},r)=>e.map((e,t)=>{const a=`[${t}]`;return null===e?r.trace.note({type:"render",token:a,rendered:"empty"}):te(e)&&r.trace.note({type:"render",token:a,rendered:"placeholder"}),ee(e)}).join(t)},xo=e=>{const t=new Set,r=[];for(const a of e)if("imsu".includes(a)){if(t.has(a))return`duplicate regex flag '${a}'`;t.add(a)}else r.includes(a)||r.push(a);if(0===r.length)return;const a=r.includes("g")||r.includes("y")?" — all matches is mode: 'match'":"";return`unknown regex flag${1===r.length?"":"s"}: ${r.join(", ")}${a}`},jo={type:"array",description:"The collection iterated over; a null input is a type error"},Oo={type:"string",required:!1,evaluation:"structural",description:"Rename the bindings: as: 'row' binds $row and $rowIndex"},Po={type:"array",required:!1,evaluation:"lazy",replacesNullAt:["input"],description:"Used as the collection when input evaluates to null — typically []"},Ao={type:"any",evaluation:"perElement",over:"input",description:"The predicate, per element — a truthiness position, so null is falsy",truthiness:!0},So={name:"get",category:"data",description:"Read a path out of the evaluation data, or out of a supplied object — the dynamic face of a $data reference",parameters:{path:{type:["string","array","null"],description:"Dot and bracket segments, quoted keys and the [*] projection — or an array of segments, taken verbatim"},from:{type:"any",nullPolicy:"value",default:H,description:"The object searched instead of the evaluation data — replace, never merge; a null source is one where every path is missing"},default:{type:"any",required:!1,evaluation:"lazy",description:"The answer when the path is missing — a stored null passes through unchanged (firstOf replaces one); supplying it also opts out of strictDataPaths"}},positionalParams:T,returns:"any",validate:({path:e})=>Rn(e,"path"),evaluate:({path:e,from:t,default:r},a)=>{const n=k(t,Fn(e));if(n.found)return void 0===n.value?null:n.value;if(void 0!==r)return r.evaluate();if(a.options.strictDataPaths)throw new Oa(`'${Do(e)}' is missing (strictDataPaths)`,{code:s.missingDataPath});return null}},Do=e=>"string"==typeof e?e:e.map(e=>String(e)).join("."),Co={name:"buildObject",category:"data",description:"Assemble an object from computed key/value entries — for keys known only at runtime",parameters:{entries:{type:"array",constraints:{elementShape:{key:{type:["string","number","boolean"]},value:{type:"any"}}},description:'Objects with a "key" and a "value"; a null value keeps its key'}},positionalParams:["...entries"],returns:"object",validate:e=>[...Wn(e),...No(e)],evaluate:({entries:e},t)=>{const r={};for(const a of e){const e=ee(a.key);Object.hasOwn(r,e)&&t.trace.note({type:"key-overwrite",key:e}),r[e]=a.value}return r}},No=e=>{const t=e.entries;if(!Array.isArray(t))return[];const r=new Set,a=new Set,n=[];for(const e of t){const t=e?.key;if("string"!=typeof t&&"number"!=typeof t&&"boolean"!=typeof t)continue;const o=ee(t);r.has(o)&&!a.has(o)&&(a.add(o),n.push({severity:"warning",parameter:"entries",message:`duplicate key '${o}' — the last entry wins and the earlier one is dead`})),r.add(o)}return n},zo=(e,t)=>new Oa(`cannot convert ${q(e)} to ${t}`),To=/*#__PURE__*/[{name:"and",category:"logic",description:"True when every value is truthy — operands run in parallel",parameters:{values:{type:"array",truthiness:!0,evaluation:"race",description:"Operands, judged by FigTree truthiness; null is falsy"}},positionalParams:["...values"],returns:"boolean",validate:Ln,evaluate:({values:e})=>Kn(e,!1)},{name:"or",category:"logic",description:"True when any value is truthy — operands run in parallel",parameters:{values:{type:"array",truthiness:!0,evaluation:"race",description:"Operands, judged by FigTree truthiness; null is falsy"}},positionalParams:["...values"],returns:"boolean",validate:Ln,evaluate:({values:e})=>Kn(e,!0)},{name:"not",alias:"!",category:"logic",description:"Negate the truthiness of a value",parameters:{value:{type:"any",truthiness:!0,description:"Judged by FigTree truthiness; null is falsy, so not(null) is true"}},positionalParams:["value"],returns:"boolean",evaluate:({value:e})=>!e},{name:"if",alias:"?",category:"logic",description:"Choose between two branches — only the chosen branch evaluates",parameters:{condition:{type:"any",truthiness:!0,description:"Judged by FigTree truthiness; null is falsy"},then:{type:"any",evaluation:"lazy",description:"The value when the condition holds"},else:{type:"any",evaluation:"lazy",default:null,description:"The value when it does not; omitted means null"}},positionalParams:["condition","then","else"],evaluate:({condition:e,then:t,else:r})=>e?t.evaluate():r.evaluate()},{name:"match",category:"logic",description:"Dispatch on a value — only the matching branch evaluates",parameters:{value:{type:["string","number","boolean","null"],nullPolicy:"value",description:"Matched against branch keys by its canonical string form"},branches:{type:"object",evaluation:"lazyEntries",description:"A literal map of branches, or an expression computing one"},default:{type:"any",required:!1,evaluation:"lazy",description:"The branch taken when none matches; absent means failure"}},positionalParams:["value","branches","default"],evaluate:({value:e,branches:t,default:r})=>{const a=null===e?null:ee(e);if(null!==a&&Object.hasOwn(t,a))return t[a].evaluate();if(void 0!==r)return r.evaluate();throw new Oa(`no branch matches ${null===a?"null":`'${a}'`}, and no default was supplied`)}},{name:"firstOf",category:"logic",description:"The first candidate that is not null (SQL COALESCE) — later candidates never evaluate",parameters:{values:{type:"array",evaluation:"lazyElements",description:"Candidates, tried in order; only null is skipped"}},positionalParams:["...values"],validate:Ln,evaluate:async({values:e})=>{for(const t of e){const e=await t.evaluate();if(null!==e)return e}return null}},Xn,Yn,eo,to,ro,ao,so,io,uo,lo,co,po,fo,ho,vo,yo,/*#__PURE__*/go("min","the minimum","The smallest of the values — numbers numerically, strings in codepoint order",e=>e<0),/*#__PURE__*/go("max","the maximum","The largest of the values — numbers numerically, strings in codepoint order",e=>e>0),{name:"buildString",category:"string",description:"Render a template, filling its tokens — the result is always a string",parameters:{template:{type:["string","null"],description:"The text, with %N or {{name}} tokens; in a literal template, {{$data.x}} is that reference"},substitutions:{type:["array","object"],default:[],elementNullPolicy:"value",description:"An array pairs with %N tokens, an object with {{name}} tokens; the mode dispatches on which arrives"},trim:{type:"boolean",default:!1,description:"Trim whitespace from each rendered value, never from the template text"},closeGaps:{type:"boolean",default:!1,description:"A value that renders empty also takes one run of adjacent template whitespace"},nullValueDefault:{type:["string","number","boolean"],required:!1,evaluation:"lazy",replacesNullAt:["substitutions"],description:'Rendered in place of a null value, instead of ""'}},positionalParams:["template","...substitutions"],returns:"string",evaluate:({template:e,substitutions:t,trim:r,closeGaps:a},n)=>{const o=Array.isArray(t)?t:void 0,s=void 0===o?t:void 0,i=[];for(const t of ge(e)){if("text"===t.kind){i.push({text:t.text,site:!1});continue}if(!("positional"===t.kind?void 0!==o&&t.index>=1&&t.index<=o.length:void 0!==s&&Object.hasOwn(s,t.body))){n.trace.note({type:"render",token:t.raw,rendered:"literal"}),i.push({text:t.raw,site:!1});continue}const e="positional"===t.kind?o[t.index-1]:s[t.body],a=ee(e);te(e)&&n.trace.note({type:"render",token:t.raw,rendered:"placeholder"});const l=r?ie(a):a;""===l&&n.trace.note({type:"render",token:t.raw,rendered:"empty"}),i.push({text:l,site:!0,token:t.raw})}if(a)for(const e of(e=>{const t=[];for(let r=0;r<e.length;r++){const a=e[r];if(!a.site||""!==a.text)continue;const n=e[r-1];if(void 0!==n&&!n.site){const e=ue(n.text);if(e!==n.text){n.text=e,t.push(a.token);continue}}const o=e[r+1];if(void 0!==o&&!o.site){const e=de(o.text);e!==o.text&&t.push(a.token),o.text=e}}return t})(i))n.trace.note({type:"render",token:e,rendered:"gap-closed"});return i.map(e=>e.text).join("")}},wo,$o,/*#__PURE__*/bo("lower","Lowercase a string — Unicode default case mapping, locale-independent","The string to lowercase",e=>e.toLowerCase()),/*#__PURE__*/bo("upper","Uppercase a string — Unicode default case mapping, locale-independent","The string to uppercase",e=>e.toUpperCase()),/*#__PURE__*/bo("trim","Strip whitespace (the JS trim set) from both ends of a string","The string to trim",ie),{name:"regex",category:"string",description:"Test, extract or match a string against a regular expression",parameters:{value:{type:["string","null"],description:"The subject string"},pattern:{type:["string","null"],description:"The regular expression source"},flags:{type:"string",default:"",description:"The admitted subset: i, m, s, u"},mode:{type:{literal:["test","extract","match"]},default:"test",description:"test gives a boolean, extract the first matching substring, match every one of them"},noMatchDefault:{type:["string","null"],required:!1,default:null,nullPolicy:"value",evaluation:"lazy",description:"The extract answer when nothing matches — a matched empty string still passes through"}},positionalParams:["value","pattern"],returns:["boolean","string","array","null"],validate:({pattern:e,flags:t})=>{const r=[],a="string"==typeof t?xo(t):void 0;if(void 0!==a&&r.push({severity:"error",parameter:"flags",message:a}),"string"==typeof e)try{new RegExp(e,"string"==typeof t&&void 0===a?t:"")}catch(e){r.push({severity:"error",parameter:"pattern",message:`pattern does not compile: ${e.message}`})}return r},evaluate:({value:e,pattern:t,flags:r,mode:a,noMatchDefault:n})=>{const o=xo(r);if(void 0!==o)throw new Oa(o);const s=e=>{try{return new RegExp(t,r+e)}catch(e){throw new Oa(`pattern does not compile: ${e.message}`)}};switch(a){case"test":return s("").test(e);case"extract":{const t=s("").exec(e);return null===t?n.evaluate():t[0]}case"match":return[...e.matchAll(s("g"))].map(e=>e[0])}}},{name:"length",category:"array",description:"An array's element count, or a string's Unicode code-point count",parameters:{value:{type:["string","array","null"],description:"The array or string measured"}},positionalParams:["...value"],returns:"integer",evaluate:({value:e})=>"string"==typeof e?pe(e).length:e.length},{name:"map",category:"array",description:"Transform every element of an array",parameters:{input:jo,as:Oo,nullInputDefault:Po,each:{type:"any",evaluation:"perElement",over:"input",description:"Evaluated per element, with $element and $index bound"}},positionalParams:["input","each"],returns:"array",validate:Jn,evaluate:({each:e})=>_n(e.settle())},{name:"filter",category:"array",description:"Keep the elements of an array whose predicate is truthy",parameters:{input:jo,as:Oo,nullInputDefault:Po,each:Ao},positionalParams:["input","each"],returns:"array",validate:Jn,evaluate:async({input:e,each:t})=>{const r=await _n(t.settle());return e.filter((e,t)=>r[t])}},{name:"find",category:"array",description:"The first element of an array whose predicate is truthy",parameters:{input:jo,as:Oo,nullInputDefault:Po,each:Ao,noMatchDefault:{type:"any",required:!1,default:null,evaluation:"lazy",description:"The answer when nothing matches; a found null passes through unchanged"}},positionalParams:["input","each"],validate:Jn,evaluate:async({input:e,each:t,noMatchDefault:r})=>{const a=new Array(e.length);let n=0;for await(const r of t.settle()){a[r.index]=r;for(let t=a[n];void 0!==t;t=a[n]){if(!t.ok)throw t.error;if(!0===t.value)return e[n];n+=1}}return r.evaluate()}},{name:"some",category:"array",description:"True when any element satisfies the predicate",parameters:{input:jo,as:Oo,nullInputDefault:Po,each:Ao},positionalParams:["input","each"],returns:"boolean",validate:Jn,evaluate:({each:e})=>Kn(e.settle(),!0)},{name:"every",category:"array",description:"True when every element satisfies the predicate",parameters:{input:jo,as:Oo,nullInputDefault:Po,each:Ao},positionalParams:["input","each"],returns:"boolean",validate:Jn,evaluate:({each:e})=>Kn(e.settle(),!1)},So,Co,{name:"convert",category:"other",description:"Convert a value to a number, string, boolean or array — strict: a failed conversion is an error, never a guess",parameters:{value:{type:"any",nullPolicy:e=>"boolean"===e?"value":"propagate",description:"The value to convert; null propagates except for boolean, where it is false"},to:{type:{literal:["number","string","boolean","array"]},description:"The target type"}},positionalParams:["value","to"],returns:["number","string","boolean","array"],evaluate:({value:t,to:r})=>{switch(r){case"number":if("number"==typeof t)return t;if("boolean"==typeof t)return t?1:0;if("string"==typeof t){const e=t.trim(),r=""===e?NaN:Number(e);if(Number.isNaN(r))throw new Oa(`'${t}' is not a numeric string — use regex to extract a number from text`);return r}throw zo(t,"number");case"string":if(Array.isArray(t)||e(t))throw new Oa(`cannot convert ${q(t)} to string — a cast is not a render; use buildString or join`);if("object"==typeof t)throw zo(t,"string");return ee(t);case"boolean":if("string"==typeof t){const e=t.trim().toLowerCase();if("true"===e)return!0;if("false"===e)return!1}return ne(t);case"array":return Array.isArray(t)?t:[t]}}}].map(Sn),Eo="3.0.0-preview.7",qo=(e,t)=>{const r=((e,t)=>{const r={...e};for(const[e,a]of Object.entries(t)){if(void 0===a)continue;if(null===a){delete r[e];continue}if("data"===e||!n(a)){r[e]=a;continue}const t=r[e],o=n(t)?{...t}:{};for(const[e,t]of Object.entries(a))void 0!==t&&(null===t?delete o[e]:o[e]=t);r[e]=o}return r})(null===e?{}:e.options,t);Go(r);const a=Mo(r);if(null!==e&&!(e=>void 0!==e.operators||void 0!==e.fragments||void 0!==e.operatorDefaults)(t))return{options:r,evaluation:a,registry:e.registry,compileCache:e.compileCache};const o=Dr({operators:r.operators??[To],...void 0!==r.operatorDefaults?{operatorDefaults:r.operatorDefaults}:{},...void 0!==r.fragments?{fragments:r.fragments}:{},removedFragments:new Set(Object.entries(t.fragments??{}).flatMap(([t,r])=>null===r&&e?.registry.fragments.has(t)?[`$${t}`]:[]))});return{options:r,evaluation:a,registry:o,compileCache:new yr({compile:e=>Fo(e,o),probe:e=>be(e,o)})}},Mo=e=>{const t={...e};return delete t.operators,delete t.fragments,t},Fo=(e,t)=>{const r=Te(e,t);return Nt(r),r.hasNoCache&&Zt(r),r};class Ro{state;results;version=Eo;constructor(e={}){this.state=qo(null,e),this.results=new vn(fn(this.state.options.cache))}updateOptions(e={}){const t=qo(this.state,e),r=fn(t.options.cache);this.state=t,this.results.configure(r)}clearCache(){this.results.clear()}getOptions(){return(e=>{const t={};for(const[r,a]of Object.entries(e))t[r]=n(a)?{...a}:a;return t})(this.state.evaluation)}getOperators(){return[...this.state.registry.operators.values()].map(e=>{const{definition:t,instanceDefaults:r}=e,a={name:t.name,category:t.category,description:t.description,parameters:wn(t.parameters,r),restParam:t.restParam,timeoutParam:t.timeoutParam,cache:t.cache,returns:t.returns,hasValidate:void 0!==t.validate};return void 0!==t.alias&&(a.alias=t.alias),void 0!==t.metadata&&(a.metadata=t.metadata),void 0!==t.positionalParams&&(a.positionalParams=t.positionalParams),void 0!==r&&(!0===r.noCache&&(a.instanceNoCache=!0),Object.hasOwn(r,"fallback")&&(a.instanceFallback=r.fallback)),a})}getFragments(){return[...this.state.registry.fragments.values()].map(e=>{const t={name:e.name,parameters:Object.fromEntries(Object.entries(e.parameters).map(([e,t])=>[e,{...t}])),returns:e.returns,warnings:[...e.warnings],dependencies:bn(e.dependencies),caches:e.caches};return void 0!==e.description&&(t.description=e.description),void 0!==e.metadata&&(t.metadata=e.metadata),t})}validate(e,t){const r=void 0===t?this.state.evaluation:Uo(this.state.evaluation,t),a=Fo(e,this.state.registry),n=xn(a,r,e=>e.issue);return{valid:!n.some(e=>"error"===e.severity),issues:n}}getDependencies(e){return bn(Te(e,this.state.registry).dependencies)}isEvaluable(e){const t=Te(e,this.state.registry);return t.holes.length>0||t.hasErrors}evaluate(e,t){const{state:r}=this;return Io(r.evaluation,this.results,e,t,()=>r.compileCache.resolve(e),()=>Fo(e,r.registry))}compile(e){const{state:t}=this;return Wo(e,t.compileCache.resolve(e),t.evaluation,t.registry,this.results)}}const Io=async(e,t,r,a,n,o)=>{const s=void 0===a?e:Uo(e,a),i=n(),l="inert"===i.kind&&!0===s.trace?{kind:"artifact",artifact:o()}:i;if("inert"===l.kind){if(void 0!==s.maxDepth&&l.depth>s.maxDepth){const e=$n(l.depth,s.maxDepth);throw Ho(e,[e])}return r}const{artifact:c}=l;if(c.hasErrors||void 0!==s.maxDepth||void 0!==s.maxNodes){const e=[...kn(c,s),...c.issues.map(e=>e.issue)],t=e.find(e=>"error"===e.severity);if(void 0!==t)throw Ho(t,e)}const u=await sn(c,s,t);return!0===s.trace?u:u.result};let Vo;const Lo=(e,t)=>Vo?.(e,t);class Jo{#t;#r;#a;#n;#o;#s;#i;constructor(e,t,r,a,n){this.#t=e,this.#r=t,this.#a=r,this.#n=a,this.#o=n,Vo??=(e,t)=>{if("object"!=typeof e||null===e||!(#r in e))return;const r=void 0===t?e.#a:Uo(e.#a,t);return{expression:e.#t,artifact:e.#l(),options:r}}}get expression(){return this.#t}get issues(){return this.#i??=this.#l().issues.map(e=>e.issue)}get hasErrors(){return this.#l().hasErrors}evaluate(e){return Io(this.#a,this.#o,this.#t,e,()=>this.#r,()=>this.#l())}getDependencies(){return bn(this.#l().dependencies)}#l(){return"artifact"===this.#r.kind?this.#r.artifact:this.#s??=Fo(this.#t,this.#n)}}const Wo=(e,t,r,a,n)=>new Jo(e,t,r,a,n),Bo=/*#__PURE__*/new Set(Object.keys({data:0,signal:0,timeout:0,trace:0})),Uo=(e,t)=>{let r;for(const a in t){const n=t[a];if(void 0!==n){if(!Bo.has(a))throw Ko(a);r??={...e},r[a]=n}}return void 0===r?e:(Go(t),r)},Ko=e=>new O({code:s.invalidOptions,message:`'${e}' is not a per-call option — a call may supply data, signal, timeout and trace; configure the rest at construction or via updateOptions()`,path:[]}),Go=e=>{const{timeout:t,signal:r}=e;if(void 0!==t&&("number"!=typeof t||!Number.isFinite(t)||t<=0))throw new O({code:s.invalidOptions,message:"'timeout' must be a positive number of milliseconds",path:[]});if(void 0!==r&&!_o(r))throw new O({code:s.invalidOptions,message:"'signal' must be an AbortSignal",path:[]})},_o=e=>"object"==typeof e&&null!==e&&"boolean"==typeof e.aborted&&"function"==typeof e.addEventListener&&"function"==typeof e.removeEventListener,Ho=(e,t)=>new O({code:e.code,message:e.message,path:e.path,...void 0!==e.operator?{operator:e.operator}:{},issues:t});export{xn as A,Y as B,Z as C,oe as D,H as E,Ro as F,ve as G,Pn as N,_ as O,On as R,G as a,R as b,L as c,To as d,Pa as e,Ae as f,Lo as g,V as h,ne as i,X as j,U as k,J as l,Dn as m,Cn as n,Oa as o,Fn as p,ee as q,Pe as r,De as s,xe as t,q as u,Ct as v,Sn as w,An as x,Rn as y,Eo as z};
|
|
1
|
+
import{a as e,i as t,l as r,f as a,d as n,D as o,E as s,g as i,c as l,o as c,q as u,h as d,S as p,u as f,e as m,p as h,s as v,j as y,n as g,v as b,k as w,w as k,x as $,r as x,t as j,m as O,R as P,F as A,y as C,b as D,z as S,A as N,W as z,B as T,C as E,G as q}from"./shared.js";const M={ok:!0},F=e=>null===e?"null":Array.isArray(e)?"array":typeof e,R=(e,t)=>({ok:!1,expected:e,actual:F(t)}),I=(t,r)=>{switch(r){case"any":return!0;case"string":return"string"==typeof t;case"number":return"number"==typeof t;case"integer":return"number"==typeof t&&Number.isInteger(t);case"boolean":return"boolean"==typeof t;case"array":return Array.isArray(t);case"object":return e(t);case"null":return null===t;default:return!1}},V=e=>"null"===e||"any"===e||!!Array.isArray(e)&&(e.includes("null")||e.includes("any")),L=/*#__PURE__*/new Set(["any","string","number","boolean","array","object","null","integer"]),W=t=>{if("string"==typeof t)return L.has(t);if(Array.isArray(t))return t.length>0&&t.every(e=>"string"==typeof e&&L.has(e));if(e(t)&&"literal"in t){const e=t.literal;return Array.isArray(e)&&e.length>0&&e.every(e=>["string","number","boolean"].includes(typeof e))}return!1},J=(e,r)=>{if(t(r)){if(-1!==r.literal.indexOf(e))return M;const t=r.literal.map(e=>JSON.stringify(e)).join(", ");return R(`one of ${t}`,e)}return"string"==typeof r?I(e,r)?M:R(r,e):r.some(t=>I(e,t))?M:R(r.join(" | "),e)},B=(e,t)=>{if(void 0!==t.length){if(!Array.isArray(e))return R("array",e);if(e.length!==t.length)return{ok:!1,expected:`array of length ${t.length}`,actual:`array of length ${e.length}`}}if(t.homogeneous){if(!Array.isArray(e))return R("array",e);const r=t.homogeneous;if(e.length>0){if(void 0===r.find(t=>e.every(e=>I(e,t))))return{ok:!1,expected:`homogeneous array of ${r.join(" | ")}`,actual:U(e)}}}if(t.elementShape){if(!Array.isArray(e))return R("array",e);for(let r=0;r<e.length;r++){const a=_(e[r],t.elementShape);if(!a.ok)return a}}return M},U=e=>{const t=F(e[0]),r=e.find(e=>F(e)!==t);return void 0===r?`array of ${t}`:`${F(r)} beside ${t}`},K=["length","homogeneous","elementShape"],G=t=>{if(!e(t))return R("a constraints object",t);for(const e of Object.keys(t))if(!K.includes(e))return{ok:!1,expected:`one of ${K.join(", ")}`,actual:e};const{length:r,homogeneous:a,elementShape:n}=t;if(void 0!==r&&(!Number.isInteger(r)||r<0))return R("a non-negative integer length",r);if(!(void 0===a||Array.isArray(a)&&W(a)))return R("a non-empty array of basic types",a);if(void 0!==n){if(!e(n))return R("an object of declarations",n);for(const[t,r]of Object.entries(n)){if(!e(r))return R(`a declaration for "${t}"`,r);if(void 0!==r.type&&!W(r.type))return R(`a vocabulary type for "${t}"`,r.type);if(void 0!==r.required&&"boolean"!=typeof r.required)return R(`a boolean "required" for "${t}"`,r.required);if(void 0!==r.constraints){const e=G(r.constraints);if(!e.ok)return e}}}return M},_=(t,r)=>{if(!e(t))return R("object",t);const a=Object.keys(r);for(let e=0;e<a.length;e++){const n=a[e],o=r[n],s=Object.prototype.hasOwnProperty.call(t,n),i=!1!==o.required;if(s){if(void 0!==o.type){const e=J(t[n],o.type);if(!e.ok)return e}if(void 0!==o.constraints){const e=B(t[n],o.constraints);if(!e.ok)return e}}else if(i)return{ok:!1,expected:`property "${n}"`,actual:"missing"}}return M},H=(e,t,r)=>{if(!r||!Array.isArray(e))return B(e,t);const{length:a,...n}=t;if(void 0!==a){const t=B(e,{length:a});if(!t.ok)return t}return B(e.filter(e=>null!==e),n)},Q=["logic","comparison","math","string","array","data","io","other"],X=Symbol("fig-tree:EvaluationData"),Y=Symbol("fig-tree:validated-operator"),Z=e=>"object"==typeof e&&null!==e&&!0===e[Y],ee="<array>",te="<object>",re=e=>null===e?"":"string"==typeof e?e:"number"==typeof e?String(e):"boolean"==typeof e?e?"true":"false":Array.isArray(e)?ee:te,ae=e=>null!==e&&"object"==typeof e,ne="a composite element renders as a placeholder, never as text — drill in, or join it explicitly",oe=[!1,null,0,""],se=e=>-1===oe.indexOf(e),ie=(e,t)=>"number"==typeof e&&"number"==typeof t?e<t?-1:e>t?1:0:le(String(e),String(t)),le=(e,t)=>{const r=Array.from(e),a=Array.from(t),n=Math.min(r.length,a.length);for(let e=0;e<n;e++){const t=r[e].codePointAt(0),n=a[e].codePointAt(0);if(t!==n)return t<n?-1:1}return r.length===a.length?0:r.length<a.length?-1:1},ce=e=>e.trim(),ue=/\s+$/,de=/^\s+/,pe=e=>e.replace(ue,""),fe=e=>e.replace(de,""),me=e=>Array.from(e),he=(e,t)=>{const[r,a]=String(e).split("e"),n=void 0!==a?Number(a)+t:t;return Number(`${r}e${n}`)},ve=Object.prototype.hasOwnProperty,ye=(e,t)=>{for(const r of e.keys())if(ge(r,t))return r},ge=(e,t)=>{let r,a,n;if(e===t)return!0;if(e&&t&&(r=e.constructor)===t.constructor){if(r===Date)return e.getTime()===t.getTime();if(r===RegExp)return e.toString()===t.toString();if(r===Array){if((a=e.length)===t.length)for(;a--&&ge(e[a],t[a]););return-1===a}if(r===Set){if(e.size!==t.size)return!1;for(a of e){if(n=a,n&&"object"==typeof n&&(n=ye(t,n),!n))return!1;if(!t.has(n))return!1}return!0}if(r===Map){if(e.size!==t.size)return!1;for(a of e){if(n=a[0],n&&"object"==typeof n&&(n=ye(t,n),!n))return!1;if(!ge(a[1],t.get(n)))return!1}return!0}if(r===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(r===DataView){if((a=e.byteLength)===t.byteLength)for(;a--&&e.getInt8(a)===t.getInt8(a););return-1===a}if(ArrayBuffer.isView(e)){if((a=e.byteLength)===t.byteLength)for(;a--&&e[a]===t[a];);return-1===a}if(!r||"object"==typeof e){for(r in a=0,e){if(ve.call(e,r)&&++a&&!ve.call(t,r))return!1;if(!(r in t)||!ge(e[r],t[r]))return!1}return Object.keys(t).length===a}}return e!=e&&t!=t},be=e=>!e.includes("{")&&!e.includes("}")&&(e.startsWith("$")?e.length>1:r(e).ok),we=e=>{const t=[];let r="";const a=()=>{""!==r&&(t.push({kind:"text",text:r}),r="")};let n=0;for(;n<e.length;){const o=e[n];if("%"===o){let s=n+1;for(;s<e.length&&e[s]>="0"&&e[s]<="9";)s++;if(s>n+1){const r=e.slice(n,s);a(),t.push({kind:"positional",raw:r,index:Number(r.slice(1))}),n=s;continue}r+=o,n++;continue}if("{"===o&&"{"===e[n+1]){const o=e.indexOf("}}",n+2);if(-1!==o){const r=e.slice(n+2,o);if(be(r)){a(),t.push({kind:"named",raw:e.slice(n,o+2),body:r}),n=o+2;continue}}r+="{{",n+=2;continue}r+=o,n++}return a(),t},ke=e=>{const t={maxDepth:0};return{constant:$e(t,e,0),depth:t.maxDepth}},$e=(e,t,r)=>{if(r>o)return!1;if(r>e.maxDepth&&(e.maxDepth=r),void 0===t)return!1;if("string"==typeof t){const e=a(t).kind;return"plain"===e||"unrecognized"===e}if(Array.isArray(t)){for(let a=0;a<t.length;a++)if(!$e(e,t[a],r+1))return!1;return!0}if(n(t)){for(const e in t){if("operator"===e||"fragment"===e||"vars"===e||"//"===e)return!1;if(e.startsWith("$"))return!1}for(const a in t)if(!$e(e,t[a],r+1))return!1;return!0}return!0},xe=(e,t)=>({parent:e,key:t}),je=e=>{const t=[];for(let r=e;null!==r;r=r.parent)t.push(r.key);return t.reverse()},Oe=e=>{e.sort((e,t)=>e.order-t.order)},Pe=e=>e.some(({issue:e})=>"error"===e.severity),Ae=e=>{const t=e.entry.definition.parameters.as;if("structural"!==t?.evaluation)return null;const r=e.params.as;return"constant"===r?.kind&&"string"==typeof r.value?r.value:null},Ce=(e,t,r)=>void 0===r?null===e:("element"===t?e:`${e??""}Index`)===r,De=(e,t,r)=>{"__proto__"===t?Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0}):e[t]=r},Se=(e,t,r)=>{const a=new Set;let n=e;return t.forEach((e,t)=>{n=Ne(n,e.at,r[t],a)}),n},Ne=(e,t,r,a)=>{const n=ze(e,a),[o,...s]=t;return De(n,o,0===s.length?r:Ne(n[o],s,r,a)),n},ze=(e,t)=>{if(t.has(e))return e;const r=Array.isArray(e)?[...e]:{...e};return t.add(r),r},Te=/*#__PURE__*/new Set(["data","vars","params","element","index","d","v","p","e","i"]),Ee=(e,t,r={})=>{const a={registry:t,recognizes:e=>((e,t)=>"literal"===t||void 0!==Er(e,t)||e.fragments.has(t))(t,e),issues:[],order:0,nodeCount:0,maxDepth:0,dataPaths:new Map,dynamic:!1,operators:new Set,fragmentNames:new Set,fragmentCalls:[],dataReads:[],identityOnly:!1,scope:{bindings:[]},asNames:new Set,unrecognized:[],hasNoCache:!1},n=(r.basePath??[]).reduce(xe,null),o=Re(a,e,n,0);Me(a);const s=At(o);Oe(a.issues);const i=Pe(a.issues),l={nodeCount:a.nodeCount,maxDepth:a.maxDepth,dependencies:{dataPaths:a.dataPaths,dynamic:a.dynamic,operators:[...a.operators],fragments:[...a.fragmentNames]},identityOnly:a.identityOnly};return{root:o,holes:s,issues:a.issues,hasErrors:i,timeoutShielded:s.every(e=>void 0!==e.timeoutFallback),own:l,...qe(l,a.fragmentCalls,t.fragments),fragmentCalls:a.fragmentCalls,dataReads:a.dataReads,hasNoCache:a.hasNoCache}},qe=(e,t,r)=>{if(0===t.length)return e;const a=new Map(e.dependencies.dataPaths),n=new Set(e.dependencies.operators),o=new Set(e.dependencies.fragments);let{nodeCount:s,maxDepth:i,identityOnly:l}=e,c=e.dependencies.dynamic;for(const e of t){const t=r.get(e.name);if(void 0!==t){s+=t.nodeCount,i=Math.max(i,e.depth+t.maxDepth),l||=t.identityOnly,c||=t.dependencies.dynamic;for(const[e,r]of t.dependencies.dataPaths)a.set(e,r);for(const e of t.dependencies.operators)n.add(e);for(const e of t.dependencies.fragments)o.add(e)}}return{nodeCount:s,maxDepth:i,identityOnly:l,dependencies:{dataPaths:a,dynamic:c,operators:[...n],fragments:[...o]}}},Me=e=>{if(0!==e.asNames.size)for(const{token:t,issue:r,raw:a}of e.unrecognized)e.asNames.has(t)&&(r.issue={...r.issue,severity:"error",code:s.unresolvedBinding,message:`'${a}' names an iterator binding, but no enclosing iterator binds it here`})},Fe=(e,t,r,a,n,o,s={})=>{const i={severity:t,code:r,message:a,path:je(n)};void 0!==s.operator&&(i.operator=s.operator),void 0!==s.parameter&&(i.parameter=s.parameter),void 0!==s.suggestion&&(i.suggestion=s.suggestion);const l={issue:i,order:o};return e.issues.push(l),l},Re=(e,t,r,a)=>{const n=e.order++;if(a>e.maxDepth&&(e.maxDepth=a),a>o)return Fe(e,"error",s.depthCeiling,`the expression nests deeper than the engine's ceiling of ${o} levels — descent stopped here`,r,n),e.nodeCount++,Le(t,r,n);const i=Ie(e,t,r,a,n);return"operator"!==i.kind&&"fragmentCall"!==i.kind&&"reference"!==i.kind&&"invalid"!==i.kind||e.nodeCount++,i},Ie=(e,t,r,a,o)=>null==t?Ve(t??null,r,o):"number"==typeof t||"boolean"==typeof t?Ve(t,r,o):"string"==typeof t?We(e,t,r,o):Array.isArray(t)?Je(e,t,r,a,o):n(t)?Be(e,t,r,a,o):(e.identityOnly=!0,Ve(t,r,o)),Ve=(e,t,r)=>({kind:"constant",value:e,path:t,order:r}),Le=(e,t,r)=>({kind:"invalid",raw:e,path:t,order:r}),We=(e,t,r,n)=>{const o=a(t,e.scope);switch(o.kind){case"plain":return Ve(t,r,n);case"unrecognized":{const a=Fe(e,"warning",s.unrecognizedIdentifier,`'${t}' matches no reference namespace and will pass through as data`,r,n),o=i(t);return null!==o&&e.unrecognized.push({token:o.token,issue:a,raw:t}),Ve(t,r,n)}case"invalid":return Fe(e,"error",o.code??s.invalidReference,`'${t}': ${o.reason}`,r,n),Le(t,r,n);case"reference":{const{namespace:a,segments:s,drill:i,binding:l}=o;return void 0!==l?{kind:"reference",namespace:a,segments:s,raw:t,binding:l,path:r,order:n}:("data"===a&&(0===s.length?e.dynamic=!0:at(e,s,i.startsWith(".")?i.slice(1):void 0,r)),{kind:"reference",namespace:a,segments:s,raw:t,path:r,order:n})}}},Je=(e,t,r,a,n)=>{const o=Array.from(t,(t,n)=>({key:n,rawChild:t,node:Re(e,t,xe(r,n),a+1)}));return Pt(e,t,o,!0,!1,void 0,r,n)},Be=(e,t,r,a,n)=>{const o=l(t,e.recognizes);switch(o.kind){case"malformed":return Fe(e,"error",s.malformedNode,o.message,r,n),Le(t,r,n);case"operator":return Ue(e,t,r,a,n);case"fragment":return bt(e,t,r,a,n);case"shorthand":return pt(e,t,o.key,r,a,n);case"plain":return jt(e,t,r,a,n)}},Ue=(e,t,r,a,n)=>{const o=t.operator;if("string"!=typeof o)return Fe(e,"error",s.malformedNode,"the 'operator' value must be a literal string",r,n),Le(t,r,n);if("literal"===o)return gt(e,t,t.value,"value"in t,r,n);const i=Er(e.registry,o);if(void 0===i){const a=f(o,St(e));return Fe(e,"error",s.unknownOperator,`'${o}' names no registered operator${a?` — did you mean '${a}'?`:""}`,r,n,{suggestion:a}),Le(t,r,n)}const l=Ke(e,i,r,n),c=[];for(const o in t){const i=t[o];"operator"!==o&&"//"!==o&&void 0!==i&&(Ge(e,l,o,i,r,a,n)||("parameters"!==o?He(e,l,c,o,i,xe(r,o),n):Fe(e,"error",s.malformedNode,"'parameters' is reserved and unused on operator nodes",xe(r,o),n,{operator:l.name})))}return Qe(e,l,c,a,n),l},Ke=(e,t,r,a)=>(e.operators.add(t.definition.name),{kind:"operator",name:t.definition.name,entry:t,params:{},path:r,order:a}),Ge=(e,t,r,a,n,o,s)=>"fallback"===r?(t.fallback=Re(e,a,xe(n,"fallback"),o+1),!0):"noCache"===r?(_e(e,t,a,n,s),!0):"vars"===r&&(t.vars=xt(e,a,n,o,s),!0),_e=(e,t,r,a,n)=>{!0===r?(t.noCache=!0,e.hasNoCache=!0):Fe(e,"error",s.malformedNode,"'noCache' takes only the literal true — it is settled before the subtree runs",xe(a,"noCache"),n,"operator"===t.kind?{operator:t.name}:{})},He=(e,t,r,a,n,o,i)=>{if(void 0===t.entry.definition.parameters[a]){const r=f(a,Object.keys(t.entry.definition.parameters));return void Fe(e,"error",s.unknownNodeKey,`'${a}' is not a parameter of '${t.name}'${r?` — did you mean '${r}'?`:""}`,o,i,{operator:t.name,parameter:a,suggestion:r})}r.push({name:a,kind:"value",value:n,path:o})},Qe=(e,t,r,a,n)=>{const o=t.entry.definition,s=o.resolution.perElement.length>0;let i;if("get"===t.name&&Xe(e,t,r),s){const a=r.find(e=>"as"===e.name&&"structural"===o.parameters.as?.evaluation&&"value"===e.kind);void 0!==a&&"value"===a.kind&&(i=dt(e,t,a.value,a.path,n))}for(const n of r){const r=o.parameters[n.name]?.evaluation;"perElement"!==r&&(t.params[n.name]=ot(e,n,r,a))}if(s){void 0!==i&&e.scope.bindings.push(i);for(const n of r){const r=o.parameters[n.name]?.evaluation;"perElement"===r&&(t.params[n.name]=ot(e,n,r,a))}void 0!==i&&e.scope.bindings.pop()}nt(e,t),Ze(e,t)},Xe=(e,t,r)=>{const a=r.findIndex(e=>"from"===e.name),n=r[a];if("value"!==n?.kind||"string"!=typeof n.value)return;const o=y(n.value);if("data"===o&&r.splice(a,1),"vars"!==o&&"params"!==o)return;const i=r.find(e=>"path"===e.name),l="value"===i?.kind?Ye(e,i.value):null;if(null===l||"value"!==i?.kind){if("vars"!==o)return;const i=e.order++;return Fe(e,"error",s.bareVars,`'${n.value}': with 'from: ${n.value}' the path's first key names the var, so the path must be written out and start with a key`,n.path,i,{operator:"get",parameter:"from"}),r.splice(a,1),void(t.params.from=Le(n.value,n.path,i))}const[c,...u]=l;n.value=g(o,[c]),i.value=Array.isArray(i.value)?u:d(u)},Ye=(e,t)=>{const r=t=>{if("string"!=typeof t)return k(t);const{kind:r}=a(t,e.scope);return"plain"===r||"unrecognized"===r};try{const e=Array.isArray(t)?t.every(r)&&t:"string"==typeof t&&r(t)&&w(t);return e&&"string"==typeof e[0]?e:null}catch{return null}},Ze=(e,t)=>{if("buildString"!==t.name)return;((e,t)=>{const r=t.params.substitutions;if(void 0===r)return;const a="constant"===r.kind?r.value:"skeleton"===r.kind?r.skeleton:void 0;(Array.isArray(a)||n(a))&&Object.values(a).some(ae)&&Fe(e,"error",s.operatorValidate,ne,r.path,r.order,{operator:t.name,parameter:"substitutions"})})(e,t);const r=t.params.template;if("constant"!==r?.kind||"string"!=typeof r.value)return;const a=we(r.value).filter(e=>"text"!==e.kind);if(0===a.length)return;const o=t.params.substitutions,i=(e=>{if(void 0===e)return{mode:"absent"};if("constant"===e.kind)return Array.isArray(e.value)?{mode:"array",length:e.value.length}:n(e.value)?{mode:"object",keys:new Set(Object.keys(e.value))}:{mode:"dynamic"};if("skeleton"===e.kind){const{skeleton:t,holes:r}=e;if(Array.isArray(t))return{mode:"array",length:t.length};if(n(t)){const e=new Set(Object.keys(t));for(const t of r)e.add(String(t.at[0]));return{mode:"object",keys:e}}}return{mode:"dynamic"}})(o);if(tt(e,t,r,a,i),"absent"!==i.mode&&"object"!==i.mode)return;const l=[],c=new Set;for(const t of a){if("named"!==t.kind||!t.body.startsWith("$"))continue;if(c.has(t.body))continue;const a=We(e,t.body,r.path,e.order++);"reference"===a.kind&&(e.nodeCount++,c.add(t.body),l.push({path:r.path,at:[t.body],node:a}))}0!==l.length&&(t.params.substitutions=et(e,t,o,l))},et=(e,t,r,a)=>{const n="skeleton"===r?.kind?{...r,skeleton:{...r.skeleton},holes:[...r.holes]}:{kind:"skeleton",skeleton:"constant"===r?.kind?{...r.value}:{},holes:[],path:r?.path??xe(t.path,"substitutions"),order:r?.order??e.order++};return n.holes.push(...a),n},tt=(e,t,r,a,n)=>{const o=(a,n)=>Fe(e,"warning",a,n,r.path,r.order,{operator:t.name}),i=(e,t)=>o(s.unboundToken,`'${e}' binds to nothing and renders as its own text${t}`),l=e=>{for(const t of e)o(s.unusedSubstitution,`substitution ${t} is never named by the template`)};if("array"!==n.mode&&"dynamic"!==n.mode||a.some(e=>"named"===e.kind&&e.body.startsWith("$"))&&o(s.inertReferenceToken,`a reference token needs the named face — beside ${"array"===n.mode?"positional substitutions":"a dynamically supplied map"} it is not recognized and renders as its own text`),"array"===n.mode){const e=new Set,t=[];for(const r of a)"positional"===r.kind&&(r.index>=1&&r.index<=n.length?e.add(r.index):t.push(r));const r=[];for(let t=1;t<=n.length;t++)e.has(t)||r.push(String(t));if(0===t.length)return void l(r);const o=0===n.length?"there are no substitutions":1===n.length?"there is only 1 substitution":`there are only ${n.length} substitutions`;for(const e of t)i(e.raw,` — ${e.index<1?"numbering starts at %1":o}${rt(r)}`);return}if("object"===n.mode){const e=new Set,t=[];for(const r of a)"named"===r.kind&&(n.keys.has(r.body)?e.add(r.body):r.body.startsWith("$")||t.push(r.raw));const r=[...n.keys].filter(t=>!e.has(t)).map(e=>`'${e}'`);0===t.length&&l(r);for(const e of t)i(e,rt(r))}},rt=e=>{if(0===e.length)return"";if(1===e.length)return`, and substitution ${e[0]} is unused`;const t=e[e.length-1];return`, and substitutions ${e.slice(0,-1).join(", ")} and ${t} are unused`},at=(e,t,r,a)=>{let n,o;void 0!==r&&c(r)?(n=r,o=t):(o=u(t),n=d(o)),e.dataPaths.set(n,o),e.dataReads.push({kind:"path",key:n,segments:o,path:a})},nt=(e,t)=>{if("get"!==t.name||void 0!==t.params.from)return;const r=t.params.path;if(void 0!==r)if("constant"===r.kind)try{const a="string"==typeof r.value?w(r.value):r.value;if(!Array.isArray(a)||!a.every(k))return void(e.dynamic=!0);if(0===a.length)return void(e.dynamic=!0);at(e,a,"string"==typeof r.value?r.value:void 0,t.path)}catch{e.dynamic=!0}else e.dynamic=!0},ot=(e,t,r,a)=>{if("lazyElements"===r||"race"===r){const r=ct(e,t,a);if(null!==r)return r}if("lazyEntries"===r){const r=ut(e,t,a);if(null!==r)return r}return"value"===t.kind?Re(e,t.value,t.path,a+1):st(e,t,a)},st=(e,t,r)=>{const{order:a,containerDepth:n}=it(e,r),o=lt(e,t.elements,t.basePath,t.offset,n);return Pt(e,t.elements,o,!0,!1,void 0,t.basePath,a)},it=(e,t)=>{const r=e.order++,a=t+1;return a>e.maxDepth&&(e.maxDepth=a),{order:r,containerDepth:a}},lt=(e,t,r,a,n)=>Array.from(t,(t,o)=>({key:o,rawChild:t,node:Re(e,t,xe(r,a+o),n+1)})),ct=(e,t,r)=>{const a="slice"===t.kind?t.elements:t.value;if(!Array.isArray(a))return null;const n="slice"===t.kind?t.basePath:t.path,o="slice"===t.kind?t.offset:0,{order:s,containerDepth:i}=it(e,r),l=lt(e,a,n,o,i);if(l.every(e=>"constant"===e.node.kind))return Pt(e,a,l,!0,!1,void 0,n,s);return{kind:"elements",nodes:l.map(e=>e.node),path:n,order:s}},ut=(e,t,r)=>{if("value"!==t.kind)return null;const a=t.value;if(!n(a)||m(a,e.recognizes))return null;const{order:o,containerDepth:s}=it(e,r),{entries:i,vars:l,changed:c}=Ot(e,a,t.path,s,o,!0);if(i.every(e=>"constant"===e.node.kind))return Pt(e,a,i,!1,c,l,t.path,o);const u={};for(const{key:e,node:t}of i)u[String(e)]=t;const d={kind:"entries",entries:u,path:t.path,order:o};return void 0!==l&&(d.vars=l),d},dt=(e,t,n,o,i)=>{const l=r=>{Fe(e,"error",s.invalidAs,r,o,i,{operator:t.name})};if("string"!=typeof n||"plain"!==a(n).kind)return l("'as' must be a literal name — a dynamic value cannot be statically resolved");const c=r(n);if(!c.ok)return l(`'${n}' is not a legal binding name — ${c.reason}`);const u=[n,$(n)];for(const t of u){if(Te.has(t))return l(`'${n}' collides with the reserved namespace word '${t}'`);if(null!==b(t,e.scope.bindings))return l(`'${n}' collides with an enclosing 'as' binding ('${t}')`)}for(const t of u)e.asNames.add(t);return n},pt=(e,t,r,a,n,o)=>{const i=r.slice(1),l="literal"===i,c=!l&&e.registry.fragments.has(i);for(const n in t)if(n!==r&&!p.has(n))return Fe(e,"error",s.malformedNode,`'${n}' may not sit beside the shorthand key '${r}' — reserved modifiers only`,xe(a,n),o),Le(t,a,o);const u=t[r],d=xe(a,r);if(l){for(const r of["fallback","vars","noCache"])r in t&&Fe(e,"warning",s.uselessModifier,`'${r}' on 'literal' is dead — contents are never evaluated`,xe(a,r),o);return gt(e,t,u,!0,a,o)}if(c)return wt(e,t,i,u,a,n,o);const f=Er(e.registry,i),m=Ke(e,f,a,o);for(const s in t){const i=t[s];s!==r&&"//"!==s&&void 0!==i&&Ge(e,m,s,i,a,n,o)}const h=[];return ft(e,m,h,u,d,o),Qe(e,m,h,n,o),m},ft=(e,t,r,a,o,s)=>{if(Array.isArray(a))ht(e,t,r,a,o,s);else if(!n(a)||m(a,e.recognizes))mt(e,t,r,a,o,s);else for(const n in a){const i=a[n];"//"!==n&&void 0!==i&&He(e,t,r,n,i,xe(o,n),s)}},mt=(e,t,r,a,n,o)=>{const s=v(t.entry.definition);null!==s?r.push({name:s,kind:"value",value:a,path:n}):vt(e,t,n,o)},ht=(e,t,r,a,n,o)=>{const s=t.entry.definition,i=h(s,a.length);if(null===i)return void yt(e,t,a,n,o);const l=s.positionalParams;for(let e=0;e<i.bound;e++)r.push({name:l[e],kind:"value",value:a[e],path:xe(n,e)});const{restAt:c}=i;null!==c&&r.push({name:s.restParam,kind:"slice",elements:0===c?a:a.slice(c),basePath:n,offset:c})},vt=(e,t,r,a)=>Fe(e,"error",s.positionalArity,`'${t.name}' takes no positional arguments — use the named form`,r,a,{operator:t.name}),yt=(e,t,r,a,n)=>{const o=t.entry.definition.positionalParams;if(void 0===o)return void vt(e,t,a,n);const i=o.length;Fe(e,"error",s.positionalArity,`'${t.name}' takes at most ${i} positional argument${1===i?"":"s"} (${o.join(", ")}), got ${r.length}`,a,n,{operator:t.name})},gt=(e,t,r,a,n,o)=>{if("operator"in t){for(const r in t)"operator"!==r&&"value"!==r&&"//"!==r&&("fallback"!==r&&"vars"!==r&&"noCache"!==r?Fe(e,"error",s.unknownNodeKey,`'${r}' is not a key of 'literal' — content goes in 'value'`,xe(n,r),o,{operator:"literal"}):Fe(e,"warning",s.uselessModifier,`'${r}' on 'literal' is dead — contents are never evaluated`,xe(n,r),o));if(!a)return Fe(e,"error",s.malformedNode,"'literal' requires its content in 'value'",n,o,{operator:"literal"}),Le(t,n,o)}return Ve(r,n,o)},bt=(e,t,r,a,n)=>{const o=t.fragment;if("string"!=typeof o)return Fe(e,"error",s.malformedNode,"the 'fragment' value must be a literal string",r,n),Le(t,r,n);const i={kind:"fragmentCall",name:o,argumentsMode:"static",path:r,order:n};kt(e,i,a);for(const o in t){const l=t[o];"fragment"!==o&&"//"!==o&&void 0!==l&&("parameters"!==o?"fallback"!==o?"vars"!==o?"noCache"!==o?Fe(e,"error",s.unknownNodeKey,`'${o}' is not a key of a fragment call — arguments live only in 'parameters'`,xe(r,o),n):_e(e,i,l,r,n):i.vars=xt(e,l,r,a,n):i.fallback=Re(e,l,xe(r,"fallback"),a+1):$t(e,i,l,xe(r,"parameters"),a,n))}return i},wt=(e,t,r,a,o,i,l)=>{const c={kind:"fragmentCall",name:r,argumentsMode:"static",path:o,order:l};kt(e,c,i);for(const a in t){const n=t[a];a!==`$${r}`&&"//"!==a&&void 0!==n&&("fallback"===a&&(c.fallback=Re(e,n,xe(o,"fallback"),i+1)),"noCache"===a&&_e(e,c,n,o,l),"vars"===a&&(c.vars=xt(e,n,o,i,l)))}return n(a)?$t(e,c,a,xe(o,`$${r}`),i,l):Fe(e,"error",s.malformedNode,`fragments have no single-value or positional form — '$${r}' takes a named-arguments object`,xe(o,`$${r}`),l),c},kt=(e,t,r)=>{const{name:a,path:n,order:o}=t;e.fragmentNames.add(a);const i=e.registry.fragments.get(a);if(void 0===i){const t=f(a,e.registry.fragments.keys());return void Fe(e,"error",s.unknownFragment,`'${a}' names no registered fragment${t?` — did you mean '${t}'?`:""}`,n,o,{suggestion:t})}t.entry=i,e.fragmentCalls.push({name:a,depth:r}),e.dataReads.push({kind:"call",fragment:i,path:n})},$t=(e,t,r,o,i,l)=>{if(void 0!==r){if(m(r,e.recognizes)||"string"==typeof r&&"reference"===a(r).kind)return t.argumentsMode="dynamic",t.parameters=Re(e,r,o,i+1),void(e.dynamic=!0);if(n(r)){const a={};for(const t in r){const n=r[t];"//"!==t&&void 0!==n&&(a[t]=Re(e,n,xe(o,t),i+1))}return void(t.parameters=a)}Fe(e,"error",s.malformedNode,"a fragment's 'parameters' must be a named-arguments object or a node computing one",o,l)}},xt=(e,t,a,o,i)=>{const l=xe(a,"vars");if(!n(t))return void Fe(e,"error",s.invalidVars,"a 'vars' block must be an object of name → expression entries",l,i);const c={};for(const a in t){const n=t[a];if("//"===a||void 0===n)continue;const u=xe(l,a),d=r(a);d.ok?c[a]=Re(e,n,u,o+1):Fe(e,"error",s.invalidName,`'${a}' is not a legal var name — ${d.reason}`,u,i)}return c},jt=(e,t,r,a,n)=>{const{entries:o,vars:s,changed:i}=Ot(e,t,r,a,n);return Pt(e,t,o,!1,i,s,r,n)},Ot=(e,t,r,a,n,o=!1)=>{let i,l=!1;const c=[];for(const u in t){const d=t[u];if("//"!==u)if("vars"!==u)if(void 0!==d){if(u.startsWith("$")){const t=f(u.slice(1),St(e)),a=void 0!==t?` — did you mean '$${t}'?`:o?"":" — data with a '$' key goes inside 'literal'";Fe(e,o?"warning":"error",s.unrecognizedIdentifier,`'${u}' is not a registered operator or fragment${o?", so it is a plain key":""}${a}`,xe(r,u),n,{suggestion:void 0===t?void 0:`$${t}`})}c.push({key:u,rawChild:d,node:Re(e,d,xe(r,u),a+1)})}else l=!0;else i=xt(e,d,r,a,n),l=!0;else l=!0}return{entries:c,vars:i,changed:l}},Pt=(e,t,r,a,n,o,i,l)=>{const c=[],u=a?new Array(r.length):{};let d=n;for(const{key:e,rawChild:t,node:a}of r)"constant"!==a.kind?(d=!0,"skeleton"!==a.kind||void 0!==a.vars?c.push({path:a.path,at:[e],node:a}):(De(u,e,a.skeleton),c.push(...a.holes.map(t=>({...t,at:[e,...t.at]}))))):(De(u,e,a.value),a.value!==t&&(d=!0));if(0===c.length)return void 0!==o&&Object.keys(o).length>0&&Fe(e,"warning",s.unreferencedVar,"this vars block declares names nothing in its scope references",xe(i,"vars"),l),Ve(d||void 0!==o?u:t,i,l);const p={kind:"skeleton",skeleton:u,holes:c,path:i,order:l};return void 0!==o&&(p.vars=o),p},At=(e,t=[])=>{if("skeleton"===e.kind)for(const r of e.holes)At(r.node,t);else if("constant"!==e.kind){const r=Ct(e);t.push(void 0===r?{node:e}:{node:e,timeoutFallback:r})}return t},Ct=e=>{if("operator"===e.kind||"fragmentCall"===e.kind){if(void 0!==e.fallback)return"constant"===e.fallback.kind?{value:e.fallback.value}:void 0;if("operator"===e.kind){const t=e.entry.hostDefaults;return void 0!==t&&Object.hasOwn(t,"fallback")?{value:t.fallback}:void 0}return e.entry?.timeoutFallback}},Dt=new WeakMap,St=e=>{const t=Dt.get(e.registry);if(void 0!==t)return t;const r=[...e.registry.operators.keys(),...e.registry.aliases.keys(),...e.registry.fragments.keys()];return Dt.set(e.registry,r),r},Nt=e=>{switch(e.kind){case"operator":return e.entry.definition.returns;case"fragmentCall":return e.entry?.returns??"any";case"skeleton":return Array.isArray(e.skeleton)?"array":"object";case"constant":return zt(e.value);default:return"any"}},zt=t=>{if(null===t)return"null";if(Array.isArray(t))return"array";if(e(t))return"object";switch(typeof t){case"string":return"string";case"number":return"number";case"boolean":return"boolean";default:return"any"}},Tt=/*#__PURE__*/Object.freeze({parsePath:w,resolvePath:x,checkType:J,checkConstraints:B,describeType:F,renderText:re,isTruthy:se}),Et=(e,t={})=>{Mt({artifact:e,context:t,varsFrames:[],iteratorFrames:[]},e.root),Oe(e.issues),e.hasErrors=Pe(e.issues)},qt=(e,t,r,a,n,o,s={})=>{const i={severity:t,code:r,message:a,path:je(n)};void 0!==s.operator&&(i.operator=s.operator),void 0!==s.fragment&&(i.fragment=s.fragment),void 0!==s.parameter&&(i.parameter=s.parameter),void 0!==s.suggestion&&(i.suggestion=s.suggestion),e.artifact.issues.push({issue:i,order:o})},Mt=(e,t)=>{switch(t.kind){case"constant":case"invalid":return;case"reference":return void Gt(e,t);case"skeleton":{const r=Xt(e,t.vars,t.path);for(const r of t.holes)Mt(e,r.node);return void Yt(e,r)}case"fragmentCall":return void Ut(e,t);case"elements":for(const r of t.nodes)Mt(e,r);return;case"entries":{const r=Xt(e,t.vars,t.path);for(const r in t.entries)Mt(e,t.entries[r]);return void Yt(e,r)}case"operator":return void Rt(e,t)}return t},Ft=e=>"kind"in e&&"string"==typeof e.kind,Rt=(e,t)=>{const r=Xt(e,t.vars,t.path);void 0!==t.fallback&&Mt(e,t.fallback);const a=t.entry.definition,n=Bt(t);for(const[r,o]of a.resolution.entries){const a=t.params[r];void 0!==a?Vt(e,n,r,o,a,It(t,r)):o.required&&qt(e,"error",s.missingRequired,`'${t.name}' requires '${r}'`,t.path,t.order,{operator:t.name,parameter:r})}Kt(e,t);const o=[];for(const r in t.params){const n=t.params[r];"perElement"===a.parameters[r]?.evaluation?o.push([r,n]):Mt(e,n)}if(o.length>0){const r={as:Ae(t),referenced:!1};e.iteratorFrames.push(r);for(const[,t]of o)Mt(e,t);e.iteratorFrames.pop(),r.referenced||qt(e,"warning",s.deadBinding,`'${t.name}' binds ${null===r.as?"$element / $index":`$${r.as}`} but its 'each' references neither`,t.path,t.order,{operator:t.name})}Yt(e,r)},It=(e,t)=>{const{definition:r,hostDefaults:a}=e.entry;if(void 0!==r.parameters[t]?.elementNullPolicy)return!1;for(const[n,o]of r.resolution.entries){if(!o.replacesNullAt?.includes(t))continue;const r=e.params[n];if(void 0===r){if(void 0!==a&&Object.hasOwn(a,n)&&null!==a[n])return!0}else if("constant"!==r.kind||null!==r.value)return!0}return!1},Vt=(e,t,r,a,n,o=!1)=>{if("elements"===n.kind){const o=a.constraints?.length;return void(void 0!==o&&n.nodes.length!==o&&qt(e,"error",s.typeCheck,`'${t.label}.${r}': expected ${o} element${1===o?"":"s"}, received ${n.nodes.length}`,n.path,n.order,{...t.extra,parameter:r}))}if("constant"!==n.kind&&"structural"===a.evaluation&&"as"!==r)return void qt(e,"error",s.typeCheck,`'${t.label}.${r}' is structural — it requires a literal value`,n.path,n.order,{...t.extra,parameter:r});const i=`'${t.label}.${r}'`,l=Wt(a,n,o);void 0!==l&&qt(e,"error",l.code,l.code===s.returnsMismatch?`${l.reason} — it can never satisfy ${i}`:`${i}: ${l.reason}`,n.path,n.order,{...t.extra,parameter:r});let c=n;for(;"operator"===c.kind||"fragmentCall"===c.kind;){const n=c.fallback;if(void 0===n)return void("operator"===c.kind&&Lt(e,t,r,a,c,o));const l=Wt(a,n,o);void 0!==l&&qt(e,"warning",s.fallbackMismatch,`this fallback can never satisfy ${i}: ${l.reason}`,n.path,n.order,{...t.extra,parameter:r}),c=n}},Lt=(e,t,r,a,n,o)=>{const i=n.entry.hostDefaults;if(void 0===i||!Object.hasOwn(i,"fallback"))return;const l=Jt(a,i.fallback,o);void 0!==l&&qt(e,"warning",s.fallbackMismatch,`'${n.name}' falls back to its operatorDefaults fallback, which can never satisfy '${t.label}.${r}': ${l.reason}`,n.path,n.order,{...t.extra,parameter:r})},Wt=(e,t,r)=>{switch(t.kind){case"constant":return Jt(e,t.value,r);case"operator":case"fragmentCall":{if("fragmentCall"===t.kind&&void 0===t.entry)return;const r=Nt(t);if(j(r,e.type))return;const a="operator"===t.kind?`'${t.name}'`:`fragment '${t.name}'`;return{code:s.returnsMismatch,reason:`${a} returns ${JSON.stringify(r)}`}}case"skeleton":{const r=J(Array.isArray(t.skeleton)?[]:{},e.type);return r.ok?void 0:{code:s.typeCheck,reason:`expected ${r.expected}, received ${r.actual}`}}default:return}},Jt=(e,t,r)=>{if(null===t&&(r||!e.required&&!V(e.type)))return;const a=J(t,e.type);if(!a.ok)return{code:s.typeCheck,reason:`expected ${a.expected}, received ${a.actual}`};if(void 0===e.constraints)return;const n=H(t,e.constraints,void 0!==e.elementNullPolicy);return n.ok?void 0:{code:s.typeCheck,reason:`expected ${n.expected}, received ${n.actual}`}},Bt=e=>({label:e.name,extra:{operator:e.name}}),Ut=(e,t)=>{const r=Xt(e,t.vars,t.path);void 0!==t.fallback&&Mt(e,t.fallback);const a=t.entry?.parameters,n=void 0===t.parameters||Ft(t.parameters)?void 0:t.parameters;if(void 0!==a&&"static"===t.argumentsMode){const r={label:t.name,extra:{fragment:t.name}};for(const o in a){const i=a[o],l=n?.[o];void 0!==l?Vt(e,r,o,i,l):i.required&&qt(e,"error",s.missingRequired,`fragment '${t.name}' – requires '${o}'`,t.path,t.order,{fragment:t.name,parameter:o})}if(void 0!==n)for(const r in n){const o=n[r];if(void 0===a[r]){const n=f(r,Object.keys(a));qt(e,"error",s.unknownNodeKey,`fragment '${t.name}' declares no parameter '${r}'${n?` — did you mean '${n}'?`:""}`,o.path,o.order,{parameter:r,suggestion:n})}}}if(void 0!==t.parameters)if(Ft(t.parameters))Mt(e,t.parameters);else for(const r in t.parameters)Mt(e,t.parameters[r]);Yt(e,r)},Kt=(e,t)=>{const r=t.entry.definition.validate;if(void 0===r)return;const a={};for(const e in t.params){const r=t.params[e];"constant"===r.kind&&(a[e]=r.value)}let n;try{n=r(a,Tt)}catch(r){return void qt(e,"error",s.operatorValidate,`'${t.name}' validate hook threw: ${r.message}`,t.path,t.order,{operator:t.name})}for(const r of n){const a=void 0!==r.parameter?t.params[r.parameter]:void 0;qt(e,r.severity,s.operatorValidate,r.message,a?.path??t.path,t.order,{operator:t.name,...void 0!==r.parameter?{parameter:r.parameter}:{}})}},Gt=(e,t)=>{switch(t.namespace){case"data":return;case"vars":return void _t(e,t);case"params":return void Ht(e,t);case"element":case"index":return void Qt(e,t,t.namespace)}},_t=(e,t)=>{const r=t.segments[0],a="string"==typeof r?r:void 0;if(void 0!==a)for(let t=e.varsFrames.length-1;t>=0;t--){const r=e.varsFrames[t],n=r.names.get(a);if(void 0!==n){if(n.referenced=!0,null!==r.currentVar){const e=r.edges.get(r.currentVar)??new Set;e.add(a),r.edges.set(r.currentVar,e)}return}}qt(e,"error",s.unresolvedVar,`'${t.raw}': no var '${a??""}' is declared in scope`,t.path,t.order)},Ht=(e,t)=>{const r=e.context.fragmentParams;if(void 0===r)return void qt(e,"error",s.unresolvedParam,`'${t.raw}': $params is only available inside a fragment body`,t.path,t.order);if(0===t.segments.length)return;const a=t.segments[0];"string"==typeof a&&r.has(a)||qt(e,"error",s.unresolvedParam,`'${t.raw}': the fragment declares no parameter '${String(a)}'`,t.path,t.order)},Qt=(e,t,r)=>{for(let a=e.iteratorFrames.length-1;a>=0;a--){const n=e.iteratorFrames[a];if(Ce(n.as,r,t.binding))return void(n.referenced=!0)}qt(e,"error",s.unresolvedBinding,`'${t.raw}' resolves against no enclosing iterator here`,t.path,t.order)},Xt=(e,t,r)=>{if(void 0===t)return null;const a={names:new Map,currentVar:null,edges:new Map},n=xe(r,"vars");for(const r in t){const o=t[r],i=xe(n,r);for(const t of e.varsFrames)if(t.names.has(r)){qt(e,"warning",s.shadowedVar,`'${r}' shadows a var of the same name from an enclosing scope`,i,o.order);break}a.names.set(r,{node:o,declaredAt:i,order:o.order,referenced:!1})}e.varsFrames.push(a);for(const[t,r]of a.names)a.currentVar=t,Mt(e,r.node),a.currentVar=null;return a},Yt=(e,t)=>{if(null!==t){e.varsFrames.pop();for(const[r,a]of t.names)a.referenced||qt(e,"warning",s.unreferencedVar,`'${r}' is declared but never referenced in its scope`,a.declaredAt,a.order);Zt(e,t)}},Zt=(e,t)=>{const r=new Map([...t.names.keys()].map((e,t)=>[e,t])),a=[],n=new Set,o=new Set,i=new Set,l=c=>{if(!o.has(c))if(n.has(c))(a=>{const n=[...a].sort((e,t)=>r.get(e)-r.get(t)),o=n.join("\0");if(i.has(o))return;i.add(o);const l=n.map(e=>`'${e}'`),c=1===l.length?`${l[0]} depends on itself`:`${l.slice(0,-1).join(", ")} and ${l[l.length-1]} form a vars cycle — a var may not depend on itself`,u=t.names.get(n[0]);qt(e,"error",s.varCycle,c,u.declaredAt,u.order)})(a.slice(a.indexOf(c)));else{n.add(c),a.push(c);for(const e of t.edges.get(c)??[])l(e);a.pop(),n.delete(c),o.add(c)}};for(const e of t.names.keys())l(e)},er={capable:!1,effective:!1,disabled:[]},tr={capable:!0,effective:!0,disabled:[]},rr=e=>{const{effective:t}=ar(e,e.root,!1);return Oe(e.issues),t},ar=(e,t,r)=>{switch(t.kind){case"constant":case"reference":return er;case"invalid":return tr;case"skeleton":return lr(e,[...t.holes.map(e=>e.node),...cr(t.vars)],r);case"elements":return lr(e,t.nodes,r);case"entries":return lr(e,[...Object.values(t.entries),...cr(t.vars)],r);case"operator":return nr(e,t,Sr(t.entry),r);case"fragmentCall":return nr(e,t,t.entry?.caches??!0,r)}return t},nr=(e,t,r,a)=>{const n=!0===t.noCache,o=lr(e,ir(t),a||n),s=r||o.capable,i=or(t),l=void 0===i?o.disabled:[i,...o.disabled];return n&&a?ur(e,t,"'noCache' is redundant — an enclosing node already sets it"):n&&!s&&ur(e,t,l.length>0?`'noCache' is redundant — caching is already disabled for ${sr(l)}`:"'noCache' is dead — nothing beneath this node caches"),{capable:s,effective:!n&&(r||o.effective),disabled:l}},or=e=>"operator"===e.kind&&e.entry.definition.cache&&!Sr(e.entry)?e.entry.definition.name:void 0,sr=e=>{const t=[...new Set(e)].map(e=>`'${e}'`);return t.length<2?t.join(""):`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`},ir=e=>{const t=[];return"operator"===e.kind?t.push(...Object.values(e.params)):void 0!==e.parameters&&("dynamic"===e.argumentsMode?t.push(e.parameters):t.push(...Object.values(e.parameters))),void 0!==e.fallback&&t.push(e.fallback),t.push(...cr(e.vars)),t},lr=(e,t,r)=>{const a={capable:!1,effective:!1,disabled:[]};for(const n of t){const{capable:t,effective:o,disabled:s}=ar(e,n,r);a.capable||=t,a.effective||=o,a.disabled.push(...s)}return a},cr=e=>void 0===e?[]:Object.values(e),ur=(e,t,r)=>{const a={severity:"warning",code:s.uselessModifier,message:r,path:je(xe(t.path,"noCache"))};"operator"===t.kind?a.operator=t.name:a.fragment=t.name,e.issues.push({issue:a,order:t.order})};class dr{max;entries=new Map;constructor(e){this.max=e,pr(e)}get size(){return this.entries.size}get(e){if(!this.entries.has(e))return;const t=this.entries.get(e);return this.entries.delete(e),this.entries.set(e,t),t}set(e,t){this.entries.delete(e),this.entries.set(e,t),this.entries.size>this.max&&this.evictOldest()}delete(e){this.entries.delete(e)}clear(){this.entries.clear()}resize(e){for(pr(e),this.max=e;this.entries.size>this.max;)this.evictOldest()}evictOldest(){const e=this.entries.keys().next();!0!==e.done&&this.entries.delete(e.value)}}const pr=e=>{if(!Number.isInteger(e)||e<1)throw new RangeError("LRU bound must be a positive integer")},fr=Symbol("fig-tree:lazy-handle"),mr="~",hr=(e,t)=>{if(t>o)return"refused";switch(typeof e){case"boolean":return"json";case"string":return e.length>4096?"serializer":"json";case"number":return Number.isFinite(e)&&!Object.is(e,-0)?"json":"serializer";case"undefined":return"serializer";case"object":break;default:return"refused"}if(null===e)return"json";if(Array.isArray(e)){for(let r=0;r<e.length;r++){const a=hr(e[r],t+1);if("json"!==a)return a}return"json"}if(!n(e))return"refused";for(const r in e){if(r.length>4096)return"serializer";const a=hr(e[r],t+1);if("json"!==a)return a}return"json"},vr=(e,t)=>yr(e,0,t)?t.join(""):void 0,yr=(e,t,r)=>{if(t>o)return!1;if(null===e)return br(r,"n");if(void 0===e)return br(r,"u");switch(typeof e){case"boolean":return br(r,e?"t":"f");case"number":return gr(e,r);case"string":return br(r,`s${e.length}:${e}`);case"object":break;default:return!1}if(Array.isArray(e)){r.push("[");for(const a of e)if(!yr(a,t+1,r))return!1;return br(r,"]")}if(!n(e)||fr in e)return!1;r.push("{");for(const a in e)if(r.push(`s${a.length}:${a}`),!yr(e[a],t+1,r))return!1;return br(r,"}")},gr=(e,t)=>Number.isNaN(e)?br(t,"N"):e===1/0?br(t,"I"):e===-1/0?br(t,"J"):Object.is(e,-0)?br(t,"#-0"):br(t,`#${String(e)}`),br=(e,t)=>(e.push(t),!0);class wr{deps;identity=new WeakMap;content=new dr(200);constructor(e){this.deps=e}resolve(e){const t="object"==typeof e&&null!==e?e:void 0;if(void 0!==t){const e=this.identity.get(t);if(void 0!==e)return e}const r=this.deps.probe(e);if(r.constant){const e={kind:"inert",depth:r.depth};return void 0!==t&&this.identity.set(t,e),e}const a=void 0===t?void 0:(e=>{const t=hr(e,0);return"json"===t?JSON.stringify(e):"serializer"===t?vr(e,[mr]):void 0})(e),n=void 0===a?void 0:this.content.get(a),o=n??this.deps.compile(e),s={kind:"artifact",artifact:o};return void 0!==t&&this.identity.set(t,s),void 0!==a&&void 0===n&&!o.identityOnly&&o.holes.length>0&&this.content.set(a,o),s}}const kr=/*#__PURE__*/new Set(["type","required","default","description","metadata","constraints"]),$r=/*#__PURE__*/new Set(["expression","parameters","description","metadata"]),xr=(t,a,n)=>{const o=(...e)=>["fragments",t,...e],i=r(t);if(!i.ok)return void n(s.invalidName,`'${t}' is not a legal fragment name: ${i.reason}`,o());if(O.has(t))return void n(s.reservedName,`'${t}' is a reserved name and may not name a fragment`,o());if(!e(a))return void n(s.invalidDefinition,`fragment '${t}' must be a wrapper object: { expression, parameters?, description?, metadata? }`,o());if(!("expression"in a))return void n(s.invalidDefinition,`fragment '${t}' has no 'expression'`,o());for(const e of Object.keys(a))$r.has(e)||n(s.invalidDefinition,`'${e}' is not a key of a fragment definition`,o(e));const l={name:t,parameters:{},body:{kind:"constant",value:null,path:null,order:0},returns:"any",warnings:[],nodeCount:0,maxDepth:0,dependencies:{dataPaths:new Map,dynamic:!1,operators:[],fragments:[]},identityOnly:!1,caches:!1};if(void 0!==a.description&&("string"!=typeof a.description?n(s.invalidDefinition,"'description' must be a string",o("description")):l.description=a.description),void 0!==a.metadata&&(e(a.metadata)?l.metadata=a.metadata:n(s.invalidDefinition,"'metadata' must be a plain object",o("metadata"))),void 0!==a.parameters)if(e(a.parameters))for(const[e,t]of Object.entries(a.parameters)){const r=jr(e,t,o,n);void 0!==r&&(l.parameters[e]=r)}else n(s.invalidDefinition,"'parameters' must be a plain object",o("parameters"));return l},jr=(t,a,n,o)=>{const i=n("parameters",t),l=r(t);if(!l.ok)return void o(s.invalidName,`'${t}' is not a legal parameter name: ${l.reason}`,i);if(P.has(t))return void o(s.reservedName,`'${t}' is a reserved node key and may not name a parameter`,i);if(!e(a))return void o(s.invalidDefinition,`the declaration of '${t}' must be an object`,i);for(const e of Object.keys(a))kr.has(e)||o(s.invalidDefinition,`'${e}' is not a key of a parameter declaration`,[...i,e]);const c=a.type??"any";if(!W(c))return void o(s.invalidDefinition,`'${t}' declares an unknown type`,[...i,"type"]);if(void 0!==a.required&&"boolean"!=typeof a.required)return void o(s.invalidDefinition,"'required' must be a boolean",[...i,"required"]);let u;if(void 0!==a.constraints){const e=G(a.constraints);if(!e.ok)return void o(s.invalidDefinition,`'${t}' declares invalid constraints: expected ${e.expected}, got ${e.actual}`,[...i,"constraints"]);u=a.constraints}const d="default"in a;if(d&&!0===a.required)return void o(s.invalidDefinition,`'${t}' is declared required and also declares a default — the default could never apply`,[...i,"default"]);if(d){const e=J(a.default,c);if(!e.ok)return void o(s.typeCheck,`the default for '${t}' does not satisfy its declared type: expected ${e.expected}, got ${e.actual}`,[...i,"default"]);if(void 0!==u){const e=B(a.default,u);if(!e.ok)return void o(s.typeCheck,`the default for '${t}' violates its declared constraints: expected ${e.expected}, got ${e.actual}`,[...i,"default"])}}const p={type:c,required:a.required??!d};return d&&(p.default=a.default),"string"==typeof a.description&&(p.description=a.description),e(a.metadata)&&(p.metadata=a.metadata),void 0!==u&&(p.constraints=u),p},Or=e=>{const t=new Set,r=new Set,a=e=>{if(r.has(e.name)||t.has(e.name))return;t.add(e.name);const n=e.body;"fragmentCall"===n.kind&&void 0!==n.entry&&a(n.entry),e.returns=Nt(n),t.delete(e.name),r.add(e.name)};for(const t of e.fragments.values())a(t)},Pr=(e,t)=>{const r=[],a=new Set,n=new Set,o=i=>{const l=r.indexOf(i);if(-1!==l){const e=[...r.slice(l),i],a=[...e].sort().join("\0");return n.has(a)||t(s.fragmentCycle,`fragment '${i}' reaches itself: ${e.join(" → ")} — recursion is not supported`,["fragments",i]),void n.add(a)}if(!a.has(i)){r.push(i);for(const t of e.get(i)?.fragmentCalls??[])o(t.name);r.pop(),a.add(i)}};for(const t of e.keys())o(t);return 0===n.size},Ar=(e,t)=>{const r=new Set,a=n=>{if(r.has(n))return;r.add(n);const o=e.fragments.get(n),s=t.get(n);if(void 0===o||void 0===s)return;for(const e of s.fragmentCalls)a(e.name);const i=qe(s.own,s.fragmentCalls,e.fragments);o.nodeCount=i.nodeCount,o.maxDepth=i.maxDepth,o.dependencies=i.dependencies,o.identityOnly=i.identityOnly,o.caches=rr(s),o.timeoutFallback=Cr(s,e.fragments)};for(const e of t.keys())a(e)},Cr=(e,t)=>{const{root:r,holes:a}=e;if(0===a.length)return;const n=[];for(const e of a){const r=Dr(e,t);if(void 0===r)return;n.push(r.value)}let o=0;const s=e=>"skeleton"===e.kind?Se(e.skeleton,e.holes,e.holes.map(e=>s(e.node))):n[o++];return{value:s(r)}},Dr=(e,t)=>{if(void 0!==e.timeoutFallback)return e.timeoutFallback;const{node:r}=e;return"fragmentCall"===r.kind&&void 0===r.fallback?t.get(r.name)?.timeoutFallback:void 0},Sr=e=>e.definition.cache&&!0!==e.hostDefaults?.noCache,Nr=["fallback","noCache"],zr=t=>{const r=[],a=(e,t,a,n)=>{r.push({severity:"error",code:e,message:t,path:a,...void 0!==n?{operator:n}:{}})},n={operators:new Map,aliases:new Map,fragments:new Map},{operators:o,aliases:i}=n,l=new Map,c=(e,t,r)=>{const n=l.get(e);return void 0!==n?(a(s.duplicateOperator,`'${e}' is already registered (by '${n}') — one namespace, no silent precedence`,t,r),!1):(l.set(e,r),!0)},u=(e,t)=>{if("function"==typeof e)return void a(s.invalidOptions,`operators[${t[1]}]${t.length>2?`[${t[2]}]`:""} is a function — factories must be called: httpOperators(client)`,t);if(!Z(e))return void a(s.invalidOptions,"every operators entry must be built with defineOperator() — a plain definition object is not accepted",t);const{name:r,alias:n}=e,l=c(r,t,r),u=void 0===n||c(n,t,r);l&&u&&(o.set(r,{definition:e}),void 0!==n&&i.set(n,r))};return Array.isArray(t.operators)?t.operators.forEach((e,t)=>{Array.isArray(e)?e.forEach((e,r)=>{Array.isArray(e)?a(s.invalidOptions,"'operators' is flattened one level only — arrays may not nest deeper",["operators",t,r]):u(e,["operators",t,r])}):u(e,["operators",t])}):a(s.invalidOptions,"'operators' must be an array",["operators"]),void 0!==t.operatorDefaults&&Tr(t.operatorDefaults,o,i,a),((t,r,a,n)=>{if(void 0===t)return;if(!e(t))return void n(s.invalidOptions,"'fragments' must be a plain object",["fragments"]);for(const[e,o]of Object.entries(t)){const t=xr(e,o,n);void 0!==t&&a(e,["fragments",e])&&r.fragments.set(e,t)}const o=new Map;for(const[e,a]of r.fragments){const n=t[e],s=Ee(n.expression,r,{basePath:["expression"]});a.body=s.root,o.set(e,s)}Or(r);for(const[e,t]of r.fragments){const r=o.get(e);Et(r,{fragmentParams:new Set(Object.keys(t.parameters))});for(const{issue:t}of r.issues)"error"===t.severity&&n(t.code,`fragment '${e}': ${t.message}`,["fragments",e,...t.path])}Pr(o,n)&&Ar(r,o);for(const[e,t]of r.fragments)for(const{issue:r}of o.get(e).issues)if("error"!==r.severity){const e={...r,path:[...r.path]};Object.freeze(e.path),t.warnings.push(Object.freeze(e))}})(t.fragments,n,(e,t)=>c(e,t,e),a),r.length>0&&(e=>{const[t]=e,r=e.length-1,a=r>0?`${t.message} (+ ${r} more issue${1===r?"":"s"})`:t.message;throw new A({code:s.invalidOptions,message:a,path:t.path,...void 0!==t.operator?{operator:t.operator}:{},issues:e})})(r),n},Tr=(t,r,a,n)=>{if(e(t))for(const[o,i]of Object.entries(t)){const t=["operatorDefaults",o],l=r.get(o);if(void 0===l){const e=a.get(o);void 0!==e?n(s.invalidOptions,`'operatorDefaults' keys are canonical names — use '${e}', not its alias '${o}'`,t,e):n(s.unknownOperator,`'${o}' names no registered operator`,t);continue}if(!e(i)){n(s.invalidOptions,`the defaults for '${o}' must be a plain object`,t,o);continue}let c=!0;for(const[e,r]of Object.entries(i)){const a=[...t,e];if(Nr.includes(e)){"fallback"!==e||ke(r).constant||(n(s.invalidOptions,`the default fallback for '${o}' must be a constant value — it is returned as written, never evaluated`,a,o),c=!1),"noCache"===e&&(!0!==r?(n(s.invalidOptions,"the 'noCache' modifier takes only the literal true",a,o),c=!1):l.definition.cache||(n(s.invalidOptions,`'noCache' on '${o}', which never caches — its definition does not declare 'cache: true'`,a,o),c=!1));continue}const i=l.definition.parameters[e];if(void 0===i){n(s.invalidOptions,`'${e}' names no declared parameter of '${o}' (nor 'fallback'/'noCache')`,a,o),c=!1;continue}if(i.required){n(s.invalidOptions,`'${e}' is a required parameter of '${o}' — operatorDefaults may only target optional parameters`,a,o),c=!1;continue}const u=J(r,i.type);if(u.ok){if(void 0!==i.constraints){const t=B(r,i.constraints);t.ok||(n(s.typeCheck,`the default for '${o}.${e}' violates its declared constraints: expected ${t.expected}, got ${t.actual}`,a,o),c=!1)}}else n(s.typeCheck,`the default for '${o}.${e}' does not satisfy its declared type: expected ${u.expected}, got ${u.actual}`,a,o),c=!1}c&&(l.hostDefaults=Object.freeze({...i}))}else n(s.invalidOptions,"'operatorDefaults' must be a plain object",["operatorDefaults"])},Er=(e,t)=>{const r=e.operators.get(t);if(void 0!==r)return r;const a=e.aliases.get(t);return void 0!==a?e.operators.get(a):void 0},qr="fig-tree:scope-settled",Mr="fig-tree:request-expired",Fr="fig-tree:evaluation-timeout";class Rr{parent;controller;upstream;forward;settled=!1;verified=-1;clock;constructor(e){this.parent=e,this.clock=void 0===e?{epoch:0}:e.clock}get aborted(){return void 0!==this.controller?this.controller.signal.aborted:!!this.settled||this.verified!==this.clock.epoch&&(!(void 0===this.parent||!this.parent.aborted)||(this.verified=this.clock.epoch,!1))}get reason(){return void 0!==this.controller?this.controller.signal.reason:this.settled?qr:this.parent?.reason}get signal(){if(void 0===this.controller){const e=new AbortController;if(this.controller=e,this.settled)e.abort(qr);else if(void 0!==this.parent){const t=this.parent.signal;t.aborted?e.abort(t.reason):(this.upstream=t,this.forward=()=>e.abort(t.reason),t.addEventListener("abort",this.forward,{once:!0}))}}return this.controller.signal}settle(){this.settled||(this.settled=!0,this.clock.epoch+=1,void 0!==this.controller&&(void 0!==this.upstream&&void 0!==this.forward&&this.upstream.removeEventListener("abort",this.forward),this.controller.abort(qr)))}}const Ir=(e,t)=>({get aborted(){return e.aborted},get reason(){return e.reason},signal:e,clock:t.clock,settle:C}),Vr=(e,t,r)=>{const a=void 0===e?(()=>{const e=new AbortController;return{signal:e.signal,abort:t=>e.abort(t),settle:()=>e.abort(qr)}})():(e=>{const t=new AbortController;e.aborted&&t.abort(e.reason);const r=()=>t.abort(e.reason);return e.addEventListener("abort",r,{once:!0}),{signal:t.signal,abort:e=>t.abort(e),settle:()=>{e.removeEventListener("abort",r),t.abort(qr)}}})(e),{signal:n}=a;let o;const s=new Promise((e,t)=>{o=t});s.catch(C);const i=()=>o(n.reason);n.aborted?i():n.addEventListener("abort",i,{once:!0});const l=void 0===t?void 0:setTimeout(()=>a.abort(r),Math.min(t,2147483647));return{signal:n,expiry:s,settle:()=>{void 0!==l&&clearTimeout(l),n.removeEventListener("abort",i),a.settle()}}},Lr=(e,t)=>Vr(e,t,Mr),Wr=(e,t)=>(r,a)=>{const n=(o=[e.operator,e.fingerprint,r],vr(o,[]));var o;return void 0===n?a():(async(e,t,r,a)=>{const n=e.generation,o=await e.lookup(t);if(a?.({type:"cache",hit:o.hit}),o.hit)return o.value;const s=await r();return await e.write(t,s,n),s})(t,n,a,e.note)},Jr=/*#__PURE__*/Object.freeze({}),Br=(e,t)=>!0!==t||!0===e.noCache?e:{...e,noCache:t};class Ur{options;cache;trace;#e;constructor(e,t,r,a){this.options=t,this.cache=r,this.trace=a,this.#e=e}get signal(){return this.#e.signal}}const Kr={memo:(e,t)=>t()},Gr={note:C},_r=Symbol("fig-tree:internal-error"),Hr=e=>na(`[fig-tree internal] ${e}`,_r),Qr=e=>sa(e,_r),Xr=Symbol("fig-tree:cancelled"),Yr=()=>na("[fig-tree] evaluation cancelled",Xr),Zr=e=>sa(e,Xr),ea=(e,t,r)=>e.rootScope.aborted?ta(e.rootScope.reason,t,r):e.abortScope.aborted?Yr():void 0,ta=(e,t,r)=>e===qr?Yr():ra(e,je(t),{operator:r}),ra=(e,t,r={})=>{const{operator:a,ms:n}=r,o=e===Fr,i=void 0===n?"":`${n}ms `;return new A({code:o?s.timeout:s.aborted,message:o?`evaluation exceeded its ${i}timeout`:"evaluation was aborted by the caller",path:t,...void 0!==a?{operator:a}:{}})},aa=e=>D(e)&&(e.code===s.aborted||e.code===s.timeout),na=(e,t)=>{const r=new Error(e);return oa(r,t),r},oa=(e,t)=>{e[t]=!0},sa=(e,t)=>e instanceof Error&&!0===e[t],ia=()=>performance.now(),la=e=>{const t=new Map,r=new WeakMap,a=new WeakSet;let n;const o=(e,r,n)=>{const o=t.get(e);if(void 0===o)return;t.delete(e),a.has(e)||("fallback"!==e.status&&(e.status=r),void 0!==n.error&&void 0===e.error&&(e.error=n.error),"failed"!==r&&"cancelled"!==r&&(e.value=n.value),void 0!==n.elapsed&&(e.elapsed=n.elapsed));const s=[...o.children,...ca(o)];s.length>0&&(e.children=s.sort((e,t)=>e.order-t.order||e.index-t.index).map(e=>e.entry))},s=(e,t)=>{(e.events??=[]).push(t)},i=(e,a,o,s)=>{const i=va(e),l=ya(e),c={path:je(e.path),kind:ma(e),status:"value",...void 0!==o?{source:o}:{},...void 0!==i?{operator:i}:{},...void 0!==l?{ref:l}:{},...void 0!==s?.var?{var:s.var}:{}};return t.set(c,{node:e,children:[],seen:new Set,started:ia()}),r.set(e,c),((e,r,a)=>{if(void 0===e)return void(n=r.entry);const o=t.get(e);void 0!==o&&(o.children.push(r),o.seen.add(a))})(a,{entry:c,order:e.order,index:s?.index??0},e),c};return{enter:(e,t,r,a)=>i(e,t,void 0!==r?{fragment:r.fragment}:void 0,a),settle:o,markFallback:(e,t)=>{e.status="fallback",e.error=t},note:s,markShielded:(e,n,l)=>{const c=r.get(e),u=void 0===c?void 0:t.get(c);if(void 0===c||void 0===u)return;a.add(c),c.status="fallback",c.error=n,c.value=l,c.elapsed=ia()-u.started,s(c,{type:"shielded-fallback"});const d=ha(e);void 0!==d&&o(i(d,c,c.source,void 0),"value",{value:l})},finish:()=>{for(const e of[...t.keys()].reverse())o(e,"cancelled",{});return void 0!==n&&e.length>0&&(n.warnings=e),n}}},ca=e=>ua(e.node).filter(t=>!e.seen.has(t)).map(e=>({entry:{path:je(e.path),kind:ma(e),status:"skipped"},order:e.order,index:0})),ua=e=>{switch(e.kind){case"operator":return[...Object.values(e.params).flatMap(da),...void 0!==e.fallback?[e.fallback]:[],...Object.values(e.vars??{})];case"fragmentCall":return[...pa(e.parameters),...void 0!==e.fallback?[e.fallback]:[],...Object.values(e.vars??{}),...void 0!==e.entry?[e.entry.body]:[]];case"skeleton":return[...e.holes.map(e=>e.node),...Object.values(e.vars??{})];case"elements":return e.nodes;case"entries":return Object.values(e.entries);default:return[]}},da=e=>"elements"===e.kind||"entries"===e.kind?ua(e):[e],pa=e=>void 0===e?[]:fa(e)?[e]:Object.values(e),fa=e=>"string"==typeof e.kind,ma=e=>{switch(e.kind){case"operator":return"operator";case"fragmentCall":return"fragment";case"reference":return"reference";case"skeleton":return"skeleton";default:return"literal"}},ha=e=>"operator"===e.kind||"fragmentCall"===e.kind?e.fallback:void 0,va=e=>"operator"===e.kind||"fragmentCall"===e.kind?e.name:void 0,ya=e=>"reference"===e.kind?e.raw:void 0,ga=(e,t)=>{if(void 0===t)return e;const r={parent:e.scope,vars:new Map},a={...e,scope:r};for(const[e,n]of Object.entries(t))r.vars.set(e,S(()=>on(n,a,{var:e})));return a},ba=async(e,t,r,a,n)=>{const o={...r,params:"dynamic"===e.argumentsMode?await ka(e,t,a):wa(e,t,a),frame:n};delete o.scope,delete o.bindings;const s=await on(t.body,o);return void 0===s?null:s},wa=(e,t,r)=>{const a=e.parameters??{},n=new Map;for(const[o,s]of Object.entries(t.parameters)){const t=a[o],i=S(async()=>{if(void 0===t)return $a(e,o,s,r);let a;try{a=await on(t,r)}catch(e){throw Aa(e,r.frame)}return xa(e,o,s,a,t.path,r)});n.set(o,()=>{const e=i();return e.catch(C),e})}return n},ka=async(t,r,a)=>{const n=t.parameters;let o;try{o=await on(n,a)}catch(e){throw Aa(e,a.frame)}if(!e(o))throw Aa(ja(t,s.typeCheck,`'parameters' must evaluate to an object, received ${Oa(o)}`,n.path),a.frame);const i=new Map;for(const[e,s]of Object.entries(r.parameters)){const r=Object.hasOwn(o,e)?xa(t,e,s,o[e],n.path,a):$a(t,e,s,a,n.path);i.set(e,()=>Promise.resolve(r))}return i},$a=(e,t,r,a,n=e.path)=>{if(!r.required)return r.default??null;throw Aa(ja(e,s.missingRequired,`requires '${t}'`,n),a.frame)},xa=(e,t,r,a,n,o)=>{const i=void 0===a?null:a;if(null===i&&!r.required&&!V(r.type))return r.default??null;const l=J(i,r.type);if(!l.ok)throw Aa(ja(e,s.typeCheck,`parameter '${t}': expected ${l.expected}, received ${l.actual}`,n),o.frame);if(void 0!==r.constraints){const a=B(i,r.constraints);if(!a.ok)throw Aa(ja(e,s.typeCheck,`parameter '${t}': expected ${a.expected}, received ${a.actual}`,n),o.frame)}return i},ja=(e,t,r,a)=>new A({code:t,message:`fragment '${e.name}' – ${r}`,path:je(a)}),Oa=e=>null===e?"null":Array.isArray(e)?"array":typeof e,Pa=Symbol("fig-tree:anchored"),Aa=(e,t)=>!D(e)||sa(e,Pa)?e:(oa(e,Pa),void 0===t||(e.fragment=t.fragment,e.fragmentPath=e.path,e.path=je(t.callPath)),e);class Ca extends Error{code;errorData;constructor(e,t={}){super(e),this.name="OperatorFailure",void 0!==t.code&&(this.code=t.code),void 0!==t.errorData&&(this.errorData=t.errorData)}}const Da=e=>e instanceof Ca,Sa=(e,t,r)=>za(Array.from({length:e},(e,a)=>Na(a,()=>t(a),r)),e),Na=async(e,t,r)=>{try{return{index:e,ok:!0,value:r(await t())}}catch(t){return{index:e,ok:!1,error:t}}},za=(e,t)=>{const r=new Map(e.map((e,t)=>[t,e]));return{[fr]:!0,length:t,async*[Symbol.asyncIterator](){for(;r.size>0;){const e=await Promise.race(r.values());r.delete(e.index),yield e}}}},Ta=e=>({[fr]:!0,evaluate:S(e)}),Ea=e=>({[fr]:!0,evaluate:()=>Promise.resolve(e)}),qa=(e,t,r,a,n)=>Ta(async()=>Ma(await on(e,n),t,r,a)),Ma=(e,t,r,a)=>{const n=J(e,a.type);if(!n.ok)throw La(t,r,n);if(null!==e&&void 0!==a.constraints){const n=H(e,a.constraints,void 0!==a.elementNullPolicy);if(!n.ok)throw La(t,r,n)}return a.truthiness?Ua(e,a.type):e},Fa=(e,t,r,a,n,o)=>{const s=Array.isArray(t)?t:[],i=Ae(r),l=new Map,c=t=>{const c=l.get(t);if(void 0!==c)return c;const u=(async()=>Ma(await on(e,((e,t,r,a)=>({...e,bindings:{parent:e.bindings,as:t,element:r,index:a}}))(o,i,s[t],t),{index:t}),r,a,n))();return u.catch(C),l.set(t,u),u};return{[fr]:!0,evaluate:c,settle:()=>Sa(s.length,c,e=>e)}},Ra=(e,t)=>t.truthiness?se(e):e,Ia=(e,t,r)=>{if("lazyElements"===t.evaluation&&"elements"===e.kind)return e.nodes.map((e,a)=>Ta(async()=>Ra(await on(e,r,{index:a}),t)));if("race"===t.evaluation&&"elements"===e.kind)return((e,t,r)=>Sa(e.length,r=>on(e[r],t,{index:r}),r))(e.nodes,r,e=>Ra(e,t));if("lazyEntries"===t.evaluation&&"entries"===e.kind){const a=ga(r,e.vars),n={};for(const[r,o]of Object.entries(e.entries))n[r]=Ta(async()=>Ra(await on(o,a),t));return n}},Va=(e,t)=>{switch(t.evaluation){case"lazyElements":return e.map(e=>Ea(Ra(e,t)));case"race":return((e,t)=>Sa(e.length,t=>Promise.resolve(e[t]),t))(e,e=>Ra(e,t));case"lazyEntries":{const r={};for(const[a,n]of Object.entries(e))r[a]=Ea(Ra(n,t));return r}case"lazy":return Ea(e);default:return e}},La=(e,t,r)=>new A({code:s.typeCheck,message:`${e.name} – parameter '${t}': expected ${r.expected}, received ${r.actual}`,path:je(e.path),operator:e.name}),Wa=(e,t,r)=>{if("string"==typeof t.nullPolicy)return t.nullPolicy;const a=t.nullPolicy,n=e.entry.definition.parameters[a.selector],o=r[a.selector],s=J(o,n.type);if(!s.ok)throw La(e,a.selector,s);const i=a.table.find(e=>e.value===o);if(void 0===i)throw Hr(`no null-policy row for ${e.name}.${a.selector}`);return i.policy},Ja=async(t,r,a)=>{if(void 0!==r.elementNullPolicy){if(Array.isArray(t)&&t.includes(null)){const e=await a();return t.map(t=>null===t?e:t)}if(e(t)&&Object.values(t).includes(null)){const e=await a(),r={};for(const[a,n]of Object.entries(t))r[a]=null===n?e:n;return r}return t}return null===t?a():t},Ba=t=>Array.isArray(t)?t.includes(null):!!e(t)&&Object.values(t).includes(null),Ua=(t,r)=>{if((e=>!("object"==typeof e&&!Array.isArray(e))&&(Array.isArray(e)?e:[e]).every(e=>"array"===e||"object"===e))(r)){if(Array.isArray(t))return t.map(se);if(e(t)){const e={};for(const[r,a]of Object.entries(t))e[r]=se(a);return e}}return se(t)},Ka=async(e,t)=>{const{params:r,propagate:a}=await(async(e,t)=>{const{definition:r,hostDefaults:a}=e.entry,{entries:n,whole:o,perElement:s}=r.resolution,i=[],l=[],c={};let u;const d={};for(const[r,o]of n){const n=e.params[r];switch(o.evaluation){case"eager":void 0!==n&&(i.push(r),l.push(on(n,t)));break;case"structural":"constant"===n?.kind&&(c[r]=n.value);break;case"lazy":if(void 0!==o.replacesNullAt){const e=void 0!==n?S(()=>on(n,t)):void 0!==a&&Object.hasOwn(a,r)?S(()=>a[r]):void 0;if(void 0!==e)for(const t of o.replacesNullAt)(u??={})[t]=e;break}void 0!==n&&(d[r]=qa(n,e,r,o,t));break;case"lazyElements":case"lazyEntries":case"race":{if(void 0===n)break;const e=Ia(n,o,t);if(void 0!==e){d[r]=e;break}i.push(r),l.push(on(n,t));break}case"perElement":break;default:o.evaluation}}if(l.length>0)if(1===l.length){const e=l[0];c[i[0]]=N(e)?await e:e}else{const e=await Promise.all(l);i.forEach((t,r)=>{c[t]=e[r]})}for(const[e,r]of o){if(Object.hasOwn(d,e))continue;const n=c[e];(void 0===n||null===n&&!r.required&&!V(r.type))&&(void 0!==a&&Object.hasOwn(a,e)?c[e]=a[e]:"default"in r?c[e]=r.default===X?t.data:r.default:delete c[e])}for(const[t,r]of o){if(Object.hasOwn(d,t))continue;let a=c[t];if(void 0===a)continue;const n=u?.[t];void 0!==n&&(a=await Ja(a,r,n));const o="eager"!==r.evaluation&&"structural"!==r.evaluation;if(null===a&&V(r.type)&&!o&&"propagate"===Wa(e,r,c))return{params:d,propagate:!0};if("propagate"===r.elementNullPolicy&&Ba(a))return{params:d,propagate:!0};a=Ma(a,e,t,r),d[t]=Va(a,r)}for(const[r,a]of s){if(void 0===a.over)throw Hr(`parameter '${r}' of '${e.name}' declares perElement without 'over'`);const n=e.params[r];void 0!==n&&(d[r]=Fa(n,d[a.over],e,r,a,t))}return{params:d,propagate:!1}})(e,t);if(a)return null;const{definition:n}=e.entry,o=!0!==t.noCache&&Sr(e.entry),s=_a(n,r),i=void 0===s?void 0:Lr(t.abortScope.signal,s),l=void 0===i?t:{...t,abortScope:Ir(i.signal,t.abortScope)},c=(e=>{const{trace:t,traceParent:r}=e;if(void 0!==t&&void 0!==r)return e=>{t.note(r,e)}})(t),u=((e,t,r,a)=>new Ur(e.abortScope,e.options,r?{memo:Wr({operator:t.name,fingerprint:t.fingerprint,note:a},e.cache)}:Kr,void 0===a?Gr:{note:a}))(l,n,o,c);try{return await Ga(e,t,r,u,i)}catch(r){throw Ha(r,e,t,i,s)}finally{i?.settle()}},Ga=async(e,t,r,a,n)=>{const o=ea(t,e.path,e.name);if(void 0!==o)throw o;const s=Promise.resolve(e.entry.definition.evaluate(r,a));return void 0===n?Xa(await s,e):(s.catch(C),Xa(await Promise.race([s,n.expiry]),e))},_a=(e,t)=>{const r=e.timeoutParam;if(null===r)return;const a=t[r];return"number"==typeof a&&a>0?a:void 0},Ha=(e,t,r,a,n)=>{if(Qr(e)||Zr(e))return e;const o=ea(r,t.path,t.name);return void 0!==o?o:a?.signal.reason===Mr?new Ca(`request exceeded its ${String(n)}ms timeout`,{code:s.requestTimeout}):e},Qa=(e,t)=>{const r=e.fallback;if(void 0!==r)return()=>on(r,t);const a=e.entry.hostDefaults;return void 0!==a&&Object.hasOwn(a,"fallback")?()=>a.fallback:void 0},Xa=(e,t)=>{if(void 0===e)return null;if("number"==typeof e&&!Number.isFinite(e))throw new A({code:s.nonFiniteResult,message:`${t.name} – produced a non-finite number (${String(e)})`,path:je(t.path),operator:t.name});if("object"==typeof(r=e)&&null!==r&&!0===r[fr])throw new A({code:s.escapedHandle,message:`${t.name} – returned a lazy handle instead of evaluating it`,path:je(t.path),operator:t.name});var r;return e},Ya=(e,t)=>{if(D(e))return e;if(Da(e))return new A({code:e.code??s.operatorFailure,message:`${t.name} – ${e.message}`,path:je(t.path),operator:t.name,...void 0!==e.errorData?{errorData:e.errorData}:{}});const r=e instanceof Error?e.message:String(e);return new A({code:s.operatorFailure,message:`${t.name} – ${r}`,path:je(t.path),operator:t.name})},Za=(e,t)=>0===e.segments.length?t.data:an(t.data,e.segments,e,t,"is absent from the evaluation data"),en=async(e,t)=>{const[r,...a]=e.segments,n="string"==typeof r?((e,t)=>{for(let r=e;void 0!==r;r=r.parent){const e=r.vars.get(t);if(void 0!==e)return e}})(t.scope,r):void 0;if("string"!=typeof r||void 0===n)throw Hr(`'${e.raw}': no var named '${String(r)}' is in scope — the static gate should have refused it`);const o=await n();return 0===a.length?nn(o):an(o,a,e,t,`is absent from the value of '$vars.${r}'`)},tn=async(e,t)=>{const r=t.params;if(void 0===r)throw Hr(`'${e.raw}': $params outside a fragment body — the static gate should have refused it`);const[a,...n]=e.segments;if(void 0===a){const e={};return await Promise.all([...r].map(async([t,r])=>{e[t]=nn(await r())})),e}const o="string"==typeof a?r.get(a):void 0;if(void 0===o)throw Hr(`'${e.raw}': the fragment declares no parameter '${String(a)}' — the static gate should have refused it`);const s=await o();return 0===n.length?nn(s):an(s,n,e,t,`is absent from the value of '$params.${String(a)}'`)},rn=(e,t)=>{const r=e.namespace,a=((e,t,r)=>{for(let a=e;void 0!==a;a=a.parent)if(Ce(a.as,t,r))return a})(t.bindings,r,e.binding);if(void 0===a)throw Hr(`'${e.raw}': no enclosing iterator binds it — the static gate should have refused it`);return"index"===r?a.index:0===e.segments.length?nn(a.element):an(a.element,e.segments,e,t,`is absent from '${e.raw.split(".")[0]}'`)},an=(e,t,r,a,n)=>{const o=x(e,t);if(o.found)return nn(o.value);if(!a.strictDataPaths)return null;throw new A({code:s.missingDataPath,message:`'${r.raw}' ${n} (strictDataPaths)`,path:je(r.path)})},nn=e=>void 0===e?null:e,on=(e,t,r)=>void 0!==t.trace?sn(e,t,t.trace,r):t.abortScope.aborted?Promise.reject(ea(t,e.path)):ln(e,t),sn=async(e,t,r,a)=>{const n=r.enter(e,t.traceParent,t.frame,a),o=ia();try{if(t.abortScope.aborted)throw ea(t,e.path);const a=await ln(e,{...t,traceParent:n});return r.settle(n,"value",{value:a,elapsed:ia()-o}),a}catch(e){throw r.settle(n,Zr(e)?"cancelled":"failed",{...D(e)?{error:e}:{},elapsed:ia()-o}),e}},ln=(e,t)=>{try{switch(e.kind){case"constant":return e.value;case"reference":return((e,t)=>{switch(e.namespace){case"data":return Za(e,t);case"vars":return en(e,t);case"params":return tn(e,t);case"element":case"index":return rn(e,t)}})(e,t);case"skeleton":return cn(e,t);case"operator":return(async(e,t)=>{const r=ga(Br(t,e.noCache),e.vars),a=e.entry.definition.deliversLazily?new Rr(r.abortScope):void 0,n=void 0===a?r:{...r,abortScope:a};try{try{return await Ka(e,n)}finally{a?.settle()}}catch(a){if(Qr(a)||Zr(a)||aa(a))throw a;const n=Ya(a,e),o=Qa(e,r);if(void 0===o)throw n;try{const e=await o();return void 0!==t.trace&&void 0!==t.traceParent&&t.trace.markFallback(t.traceParent,n),e}catch(t){if(Qr(t)||Zr(t)||aa(t))throw t;const r=Ya(t,e);throw void 0===r.cause&&(r.cause=n),r}}})(e,t);case"fragmentCall":return(async(e,t)=>{const{entry:r}=e;if(void 0===r)throw Hr(`fragment call '${e.name}' resolved to nothing — the static gate should have refused it`);const a=ga(Br(t,e.noCache),e.vars),n=new Rr(a.abortScope),o={fragment:e.name,callPath:t.frame?.callPath??e.path},s={...a,abortScope:n};try{try{return await ba(e,r,s,a,o)}finally{n.settle()}}catch(r){if(Qr(r)||Zr(r)||aa(r))throw r;const n=Aa(r,o),{fallback:s}=e;if(void 0===s)throw n;try{const e=await on(s,a);return void 0!==t.trace&&void 0!==t.traceParent&&D(n)&&t.trace.markFallback(t.traceParent,n),e}catch(e){if(Qr(e)||Zr(e)||aa(e))throw e;const r=Aa(e,t.frame);throw D(r)&&void 0===r.cause&&(r.cause=n),r}}})(e,t);case"elements":case"entries":throw Hr(`a '${e.kind}' parameter value reached the node dispatch — parameter resolution consumes these, and nothing else may hold one`);case"invalid":throw Hr("an invalid node reached evaluation — the static gate should have refused it")}}catch(e){return Promise.reject(e)}},cn=async(e,t)=>{const r=t.rootBoundary,a=void 0===r?t:{...t,rootBoundary:void 0},n=ga(a,e.vars),o=e.holes.map(({node:e})=>void 0===r?on(e,n):"skeleton"===e.kind?on(e,{...n,rootBoundary:r}):r(()=>on(e,n),e)),s=o.some(N)?await Promise.all(o):o;return Se(e.skeleton,e.holes,s)},un=async(e,t,r)=>{const{timeout:a,signal:n}=t,o=e.holes.length>0,s=void 0!==a||void 0!==n?Vr(n,a,Fr):void 0,i=void 0!==s?((e,t)=>{const r={epoch:0};return e.addEventListener("abort",()=>{r.epoch+=1},{once:!0}),{get aborted(){return e.aborted},get reason(){return e.reason},signal:e,clock:r,settle:t}})(s.signal,s.settle):new Rr(void 0),l=void 0!==s&&void 0!==a&&e.timeoutShielded&&o,c=!0===t.trace?la(e.issues.map(e=>e.issue).filter(e=>"error"!==e.severity)):void 0,u=((e,t,r,a)=>({options:e,data:e.data??Jr,abortScope:r,rootScope:r,cache:t,strictDataPaths:e.strictDataPaths??!1,...void 0!==a?{trace:a}:{}}))(t,r,i,c),d=l?pn(e,s.expiry,a,c):void 0,p=void 0!==d&&"skeleton"!==e.root.kind,f=void 0===d||p?u:{...u,rootBoundary:d};try{if(i.aborted)throw ra(i.reason,[]);const t=()=>p&&void 0!==d?d(()=>on(e.root,f),e.root):on(e.root,f),r=await(l||void 0===s?t():dn(t,s,a));return void 0!==c?{result:r,trace:c.finish()}:{result:r}}catch(e){throw void 0!==c&&D(e)&&void 0===e.trace&&(e.trace=c.finish()),e}finally{i.settle()}},dn=(e,t,r)=>Promise.race([e(),t.expiry.catch(e=>{throw ra(e,[],{ms:r})})]),pn=(e,t,r,a)=>{const n=new Map(e.holes.map(e=>[e.node,e]));return(e,o)=>{const s=n.get(o);if(void 0===s)throw Hr(`the hole boundary was handed the node at ${JSON.stringify(je(o.path))}, which is not one of the artifact's holes`);let i=!1;const l=Promise.resolve(e()).then(e=>(i=!0,e));return Promise.race([l,t.catch(e=>{if(e!==Fr)throw ra(e,[]);if(i)return;const t=mn(s);return a?.markShielded(s.node,fn(s,e,r),t),t})])}},fn=(e,t,r)=>{const{node:a}=e,n="operator"===a.kind?a.name:void 0;return ra(t,je(a.path),{operator:n,ms:r})},mn=e=>{if(void 0===e.timeoutFallback)throw Hr("a shielded artifact has a hole with no static fallback");return e.timeoutFallback.value},hn={hit:!1},vn=e=>{if(void 0===e)return{maxSize:50,maxTime:1800};if(!n(e))throw gn("'cache' must be an object");const{store:t,maxSize:r,maxTime:a}=e;if(void 0!==t&&!yn(t))throw gn("'cache.store' must provide get, set, delete and clear methods");if(void 0!==r&&(!Number.isInteger(r)||r<1))throw gn("'cache.maxSize' must be a positive integer");if(void 0!==a&&("number"!=typeof a||a<=0||Number.isNaN(a)))throw gn("'cache.maxTime' must be a positive number of seconds, or Infinity");return{...void 0!==t?{store:t}:{},maxSize:r??50,maxTime:a??1800}},yn=e=>"object"==typeof e&&null!==e&&["get","set","delete","clear"].every(t=>"function"==typeof e[t]),gn=e=>new A({code:s.invalidOptions,message:e,path:[]});class bn{store;own;maxTime;current=0;constructor(e){void 0===e.store?(this.own=new dr(e.maxSize),this.store=this.own):this.store=e.store,this.maxTime=e.maxTime}get generation(){return this.current}async lookup(e){let t;try{t=await this.store.get(e)}catch{return hn}return n(r=t)&&"ft3"===r.fig&&"number"==typeof r.generation?t.generation<this.current||wn(t)?(this.drop(e),hn):{hit:!0,value:t.value}:hn;var r}async write(e,t,r){if(r!==this.current)return;const a={fig:"ft3",value:t,generation:r,...Number.isFinite(this.maxTime)?{expiresAt:Date.now()+1e3*this.maxTime}:{}};try{await this.store.set(e,a)}catch{}}clear(){this.current+=1;try{Promise.resolve(this.store.clear()).catch(C)}catch{}}configure(e){void 0!==e.store&&e.store!==this.store&&(this.store=e.store,this.own=void 0),this.maxTime=e.maxTime,this.own?.resize(e.maxSize)}drop(e){try{Promise.resolve(this.store.delete(e)).catch(C)}catch{}}}const wn=e=>void 0!==e.expiresAt&&e.expiresAt<=Date.now(),kn=e=>e===z?0:"number"==typeof e?1:2,$n=e=>({data:{paths:[...e.dataPaths].sort(([,e],[,t])=>((e,t)=>{const r=Math.min(e.length,t.length);for(let a=0;a<r;a++){const r=e[a],n=t[a];if(r===n)continue;const o=kn(r)-kn(n);return 0!==o?o:"number"==typeof r&&"number"==typeof n?r-n:r<n?-1:1}return e.length-t.length})(e,t)).map(([e])=>e),dynamic:e.dynamic},operators:[...e.operators],fragments:[...e.fragments]}),xn=(e,t)=>{const r={};for(const[a,n]of Object.entries(e)){const e={...n};void 0!==t&&Object.hasOwn(t,a)&&(e.hostDefault=t[a]),r[a]=e}return r},jn=(e,t)=>{const r=[];return void 0!==t.maxDepth&&e.maxDepth>t.maxDepth&&r.push(Pn(e.maxDepth,t.maxDepth)),void 0!==t.maxNodes&&e.nodeCount>t.maxNodes&&r.push({severity:"error",code:s.maxNodesExceeded,message:`the expression holds ${e.nodeCount} evaluable nodes — maxNodes is ${t.maxNodes}`,path:[]}),r},On=(e,t)=>e.hasErrors||void 0!==t.maxDepth||void 0!==t.maxNodes?[...jn(e,t),...e.issues.map(e=>e.issue)]:[],Pn=(e,t)=>({severity:"error",code:s.maxDepthExceeded,message:`the expression nests ${e} levels deep — maxDepth is ${t}`,path:[]}),An=(e,t,r)=>{const a=[...jn(e,t),...e.issues.map(r)];return void 0!==t.data&&a.push(...Cn(e.dataReads,t.data)),a},Cn=(e,t)=>{const r=new Map,a=new Map,n=[],o=(e,o,i,l)=>{let c=r.get(e);if(void 0===c&&(c=x(t,o).found,r.set(e,c)),c)return;let u=a.get(i.path);if(void 0===u&&a.set(i.path,u=new Set),u.has(e))return;u.add(e);const d=void 0===l?"":` (read by fragment '${l}')`;n.push({severity:"warning",code:s.missingDataPath,message:`'${T(o)}' is absent from the supplied sample data${d}`,path:je(i.path)})};for(const t of e)if("path"===t.kind)o(t.key,t.segments,t,void 0);else for(const[e,r]of t.fragment.dependencies.dataPaths)o(e,r,t,t.fragment.name);return n},Dn="...",Sn=/*#__PURE__*/new Set(["propagate","value"]),Nn=e=>e,zn=e=>{const t={};for(const[r,a]of Object.entries(e.parameters))t[r]=a.type??"any";const r=Tn(e.parameters,t,(t,r,a)=>{throw new A({code:t,message:r,path:a,operator:e.name})});return En(e,r)},Tn=(e,r,a)=>{const n=Object.entries(r).filter(([,e])=>t(e)).map(([e])=>e),o=new Map;for(const[i,l]of Object.entries(e)){if("function"!=typeof l.nullPolicy)continue;const e=["parameters",i,"nullPolicy"];if(1!==n.length){a(s.invalidNullPolicy,`a conditional 'nullPolicy' requires exactly one literal-union parameter in the definition — found ${n.length}`,e,i);continue}const c=n[0],u=r[c];if(!t(u))continue;const d=[];let p=!0;for(const t of u.literal){let r;try{r=l.nullPolicy(t)}catch(r){a(s.invalidNullPolicy,`the conditional 'nullPolicy' threw during compilation for member ${JSON.stringify(t)}: ${String(r)}`,e,i),p=!1;break}if("string"!=typeof r||!Sn.has(r)){a(s.invalidNullPolicy,`the conditional 'nullPolicy' must return 'propagate' or 'value' for every member — got ${JSON.stringify(r)} for ${JSON.stringify(t)}`,e,i),p=!1;break}d.push({value:t,policy:r})}p&&o.set(i,{selector:c,table:d})}return o},En=(e,t)=>{const r={};for(const[a,n]of Object.entries(e.parameters)){const e=t.get(a),o="string"==typeof n.nullPolicy?n.nullPolicy:void 0,s=n.type??"any",i=!0===n.truthiness&&V(s)?"value":"propagate",l={type:Mn(s),required:n.required??!("default"in n),evaluation:n.evaluation??"eager",truthiness:n.truthiness??!1,nullPolicy:e??o??i};"default"in n&&(l.default=n.default),void 0!==n.description&&(l.description=n.description),void 0!==n.metadata&&(l.metadata=n.metadata),void 0!==n.elementNullPolicy&&(l.elementNullPolicy=n.elementNullPolicy),void 0!==n.constraints&&(l.constraints=Fn(n.constraints)),void 0!==n.over&&(l.over=n.over),void 0!==n.replacesNullAt&&(l.replacesNullAt=[...n.replacesNullAt]),r[a]=l}const a=e.positionalParams?.at(-1),n=a?.startsWith(Dn)?a.slice(3):null,o={[Y]:!0,name:e.name,category:e.category,description:e.description,parameters:r,resolution:Rn(r),restParam:n,deliversLazily:Object.values(r).some(e=>"eager"!==e.evaluation&&"structural"!==e.evaluation),timeoutParam:e.timeoutParam??null,cache:!0===e.cache,fingerprint:"",evaluate:e.evaluate,returns:void 0!==e.returns?Mn(e.returns):"any"};return void 0!==e.alias&&(o.alias=e.alias),void 0!==e.metadata&&(o.metadata=e.metadata),void 0!==e.positionalParams&&(o.positionalParams=[...e.positionalParams]),void 0!==e.validate&&(o.validate=e.validate),void 0!==e.analysis&&(o.analysis=Fn(e.analysis)),o.fingerprint=qn(o),In(o)},qn=e=>E(JSON.stringify([e.name,e.parameters,e.positionalParams,e.restParam,e.returns,e.cache,e.timeoutParam,e.evaluate,e.validate],(e,t)=>"function"==typeof t||"symbol"==typeof t||t instanceof RegExp?String(t):t)),Mn=e=>"string"==typeof e?e:t(e)?{literal:[...e.literal]}:[...e],Fn=t=>{if(Array.isArray(t))return t.map(Fn);if(e(t)){const e={};for(const[r,a]of Object.entries(t))e[r]=Fn(a);return e}return t},Rn=e=>{const t=Object.entries(e);return{entries:t,whole:t.filter(([,e])=>void 0===e.replacesNullAt&&"perElement"!==e.evaluation),perElement:t.filter(([,e])=>"perElement"===e.evaluation)}},In=e=>{for(const t of Object.values(e.parameters))"string"!=typeof t.type&&Object.freeze(t.type),"object"==typeof t.type&&"literal"in t.type&&Object.freeze(t.type.literal),"object"==typeof t.nullPolicy&&(t.nullPolicy.table.forEach(e=>Object.freeze(e)),Object.freeze(t.nullPolicy.table),Object.freeze(t.nullPolicy)),void 0!==t.constraints&&Vn(t.constraints),void 0!==t.replacesNullAt&&Object.freeze(t.replacesNullAt),Object.freeze(t);Object.freeze(e.parameters);for(const t of Object.values(e.resolution))t.forEach(e=>Object.freeze(e)),Object.freeze(t);return Object.freeze(e.resolution),"string"!=typeof e.returns&&Object.freeze(e.returns),void 0!==e.positionalParams&&Object.freeze(e.positionalParams),Object.freeze(e)},Vn=t=>{Array.isArray(t)?(t.forEach(Vn),Object.freeze(t)):e(t)&&(Object.values(t).forEach(Vn),Object.freeze(t))},Ln=e=>{if(Array.isArray(e))return e;try{return w(e)}catch(e){throw new Ca(e.message)}},Wn=(e,t)=>{if("string"!=typeof e)return[];try{return w(e),[]}catch(e){return[{severity:"error",parameter:t,message:e.message}]}},Jn=e=>Array.isArray(e.values)&&0===e.values.length?[{severity:"error",parameter:"values",message:"an empty values array has no result — supply at least one value"}]:[],Bn=e=>t=>{const r=t[e];return Array.isArray(r)&&0===r.length?[{severity:"warning",parameter:e,message:`an empty ${e} array is a dead expression — the result is always the identity`}]:[]},Un=/*#__PURE__*/Bn("values"),Kn=/*#__PURE__*/Bn("input"),Gn=/*#__PURE__*/Bn("entries"),_n=e=>Array.isArray(e.values)&&e.values.length<2?[{severity:"warning",parameter:"values",message:"fewer than two values is a dead comparison — the result never varies"}]:[],Hn=(e,t)=>new Ca(`${e} of nothing — the values array is empty${void 0!==t?`; ${t}`:""}`,{code:s.emptyAggregate}),Qn=async(e,t)=>{const r=[];for await(const a of e){if(a.ok&&a.value===t)return t;a.ok||r.push(a)}if(r.length>0)throw r.sort((e,t)=>e.index-t.index),Xn(r);return!t},Xn=e=>{const[t,...r]=e,a=r.map(e=>e.error).filter(D);return a.length>0&&D(t.error)&&void 0===t.error.related&&(t.error.related=a),t.error},Yn=async e=>{const t=new Array(e.length);let r=0;for await(const a of e){t[a.index]=a;for(let e=t[r];void 0!==e;e=t[r]){if(!e.ok)throw e.error;r+=1}}return t.map(e=>e?.value)},Zn=(e,t)=>{const r=e=>t&&"string"==typeof e?e.toLowerCase():e;if(e.length<2)return!0;const a=r(e[0]);return e.every(e=>ge(r(e),a))},eo={values:{type:"array",elementNullPolicy:"value",description:"The values compared; null is comparable (null equals null)"},caseInsensitive:{type:"boolean",default:!1,description:"Fold string operands to one case before comparing (shallow)"}},to={name:"equal",alias:"=",category:"comparison",description:"Are all the values equal? Deep, structural, key-order-insensitive; a cross-type comparison is false",parameters:eo,positionalParams:["...values"],returns:"boolean",validate:_n,evaluate:({values:e,caseInsensitive:t})=>Zn(e,t)},ro={name:"notEqual",alias:"!=",category:"comparison",description:'Are the values NOT all equal? The exact negation of equal (never "all distinct")',parameters:eo,positionalParams:["...values"],returns:"boolean",validate:_n,evaluate:({values:e,caseInsensitive:t})=>!Zn(e,t)},ao=(e,t,r,a)=>({name:e,alias:t,category:"comparison",description:r,parameters:{values:{type:"array",elementNullPolicy:"propagate",constraints:{length:2,homogeneous:["number","string"]},description:"Exactly two operands: both numbers, or both strings (codepoint order)"},nullValueDefault:{type:["number","string"],required:!1,evaluation:"lazy",replacesNullAt:["values"],description:"Replaces a null operand before comparing"}},positionalParams:["...values"],returns:"boolean",evaluate:({values:e})=>{const[t,r]=e;return a(ie(t,r))}}),no=/*#__PURE__*/ao("greaterThan",">","Is the first value strictly greater than the second?",e=>e>0),oo=/*#__PURE__*/ao("greaterThanOrEqual",">=","Is the first value greater than or equal to the second?",e=>e>=0),so=/*#__PURE__*/ao("lessThan","<","Is the first value strictly less than the second?",e=>e<0),io=/*#__PURE__*/ao("lessThanOrEqual","<=","Is the first value less than or equal to the second?",e=>e<=0),lo={number:()=>0,string:()=>"",array:()=>[],object:()=>({})},co=t=>"number"==typeof t?"number":"string"==typeof t?"string":Array.isArray(t)?"array":e(t)?"object":void 0,uo={name:"plus",alias:"+",category:"math",description:"Add numbers, concatenate strings or arrays, or shallow-merge objects — all operands must share one type",parameters:{values:{type:"array",elementNullPolicy:"propagate",constraints:{homogeneous:["number","string","array","object"]},description:"The operands; homogeneous: all numbers, strings, arrays or objects"},expect:{type:{literal:["number","string","array","object"]},required:!1,description:"Pin the mode: every operand must be this type, and an empty input yields its identity"},nullValueDefault:{type:["number","string","array","object"],required:!1,evaluation:"lazy",replacesNullAt:["values"],description:"Replaces any null operand before the addition"}},positionalParams:["...values"],returns:["number","string","array","object"],validate:({values:e,expect:t})=>void 0!==t?Un({values:e}):Jn({values:e}),evaluate:({values:e,expect:t})=>{if(0===e.length){if(void 0===t)throw Hn("the sum","pin the mode with 'expect' to get its identity");return lo[t]()}const r=t??co(e[0]),a=e.find(e=>co(e)!==r);if(void 0!==a)throw n=`all operands must be ${r}s — received ${F(a)}`,new Ca(n,{code:s.typeCheck});var n;switch(r){case"number":return e.reduce((e,t)=>e+t,0);case"string":return e.join("");case"array":return e.flat(1);case"object":return Object.assign({},...e)}}},po={name:"subtract",alias:"-",category:"math",description:"Subtract one number from another",parameters:{value:{type:["number","null"],description:"The main operand"},minus:{type:["number","null"],description:"The amount subtracted from value"}},positionalParams:["value","minus"],returns:"number",evaluate:({value:e,minus:t})=>e-t},fo={name:"divide",alias:"/",category:"math",description:"Divide one number by another — true division; zero divisors fail",parameters:{value:{type:["number","null"],description:"The main operand"},by:{type:["number","null"],description:"The divisor"}},positionalParams:["value","by"],returns:"number",evaluate:({value:e,by:t})=>e/t},mo={name:"modulo",category:"math",description:"The floored remainder: the result takes the sign of mod, so modulo(-7, 3) is 2",parameters:{value:{type:["number","null"],description:"The main operand"},mod:{type:["number","null"],description:"The modulus"}},positionalParams:["value","mod"],returns:"number",evaluate:({value:e,mod:t})=>(e%t+t)%t},ho={name:"multiply",alias:"*",category:"math",description:"Multiply numbers together — an empty input is 1, the empty product",parameters:{values:{type:"array",elementNullPolicy:"propagate",constraints:{homogeneous:["number"]},description:"The factors"},nullValueDefault:{type:"number",required:!1,evaluation:"lazy",replacesNullAt:["values"],description:"Replaces any null factor before multiplying"}},positionalParams:["...values"],returns:"number",validate:Un,evaluate:({values:e})=>e.reduce((e,t)=>e*t,1)},vo={name:"power",alias:"^",category:"math",description:"Raise a base to an exponent — overflow and complex results fail",parameters:{base:{type:["number","null"],description:"The number to raise"},exponent:{type:["number","null"],description:"The power to raise it to"}},positionalParams:["base","exponent"],returns:"number",evaluate:({base:e,exponent:t})=>e**t},yo={name:"round",category:"math",description:"Round to a number of decimal places — ties go half away from zero; negative decimals round to tens, hundreds, …",parameters:{value:{type:["number","null"],description:"The number to round"},decimals:{type:"integer",default:0,description:"Decimal places to keep; negative values round to powers of ten"}},positionalParams:["value","decimals"],returns:"number",evaluate:({value:e,decimals:t})=>((e,t=0)=>{if(!Number.isFinite(e))return e;const r=e<0?-1:1,a=Math.round(he(Math.abs(e),t));return r*he(a,-t)})(e,t)},go=(e,t,r,a,n="number")=>({name:e,category:"math",description:t,parameters:{value:{type:["number","null"],description:r}},positionalParams:["value"],returns:n,evaluate:({value:e})=>a(e)}),bo=/*#__PURE__*/go("floor","Round down toward negative infinity","The number to round down",Math.floor,"integer"),wo=/*#__PURE__*/go("ceil","Round up toward positive infinity","The number to round up",Math.ceil,"integer"),ko=/*#__PURE__*/go("abs","The absolute value","The number",Math.abs),$o=(e,t,r,a)=>({name:e,category:"math",description:r,parameters:{values:{type:"array",elementNullPolicy:"propagate",constraints:{homogeneous:["number","string"]},description:"The candidates: all numbers, or all strings (codepoint order)"},nullValueDefault:{type:["number","string"],required:!1,evaluation:"lazy",replacesNullAt:["values"],description:"Replaces any null candidate before comparing"}},positionalParams:["...values"],returns:["number","string"],validate:Jn,evaluate:({values:e})=>{const r=e;if(0===r.length)throw Hn(t);return r.reduce((e,t)=>a(ie(t,e))?t:e)}}),xo=(e,t,r,a)=>({name:e,category:"string",description:t,parameters:{value:{type:["string","null"],description:r}},positionalParams:["value"],returns:"string",evaluate:({value:e})=>a(e)}),jo={name:"split",category:"string",description:"Divide a string on a delimiter into an array of pieces — empty pieces are kept; an empty delimiter splits into code points",parameters:{value:{type:["string","null"],description:"The string to divide"},delimiter:{type:"string",default:" ",description:'Split on each occurrence; "" splits into code points'},trim:{type:"boolean",default:!0,description:"Trim whitespace from each piece"}},positionalParams:["value","delimiter"],returns:"array",evaluate:({value:e,delimiter:t,trim:r})=>{const a=""===t?me(e):e.split(t);return r?a.map(ce):a}},Oo=e=>Array.isArray(e.values)&&e.values.some(ae)?[{severity:"error",parameter:"values",message:ne}]:[],Po={name:"join",category:"string",description:"Render array elements to text and concatenate them with a delimiter",parameters:{values:{type:"array",elementNullPolicy:"value",description:'Elements of any type, rendered by the stringification table; a null renders "" and still occupies its slot'},delimiter:{type:"string",default:" ",description:"Placed between each adjacent pair — shares its contract with split"},nullValueDefault:{type:["string","number","boolean"],required:!1,evaluation:"lazy",replacesNullAt:["values"],description:'Rendered in place of a null element, instead of ""'}},positionalParams:["...values"],returns:"string",validate:e=>[...Un(e),...Oo(e)],evaluate:({values:e,delimiter:t},r)=>e.map((e,t)=>{const a=`[${t}]`;return null===e?r.trace.note({type:"render",token:a,rendered:"empty"}):ae(e)&&r.trace.note({type:"render",token:a,rendered:"placeholder"}),re(e)}).join(t)},Ao=e=>{const t=new Set,r=[];for(const a of e)if("imsu".includes(a)){if(t.has(a))return`duplicate regex flag '${a}'`;t.add(a)}else r.includes(a)||r.push(a);if(0===r.length)return;const a=r.includes("g")||r.includes("y")?" — all matches is mode: 'match'":"";return`unknown regex flag${1===r.length?"":"s"}: ${r.join(", ")}${a}`},Co={type:"array",description:"The collection iterated over; a null input is a type error"},Do={type:"string",required:!1,evaluation:"structural",description:"Rename the bindings: as: 'row' binds $row and $rowIndex"},So={type:"array",required:!1,evaluation:"lazy",replacesNullAt:["input"],description:"Used as the collection when input evaluates to null — typically []"},No={type:"any",evaluation:"perElement",over:"input",description:"The predicate, per element — a truthiness position, so null is falsy",truthiness:!0},zo={name:"get",category:"data",description:"Read a path out of the evaluation data, or out of a supplied object — the dynamic face of a $data reference",parameters:{path:{type:["string","array","null"],description:"Dot and bracket segments, quoted keys and the [*] projection — or an array of segments, taken verbatim"},from:{type:"any",nullPolicy:"value",default:X,description:"The source the path reads: a value, or a bare namespace ($data, $vars, $params, $element) whose var or parameter name opens the path — replace, never merge; a null source misses every path"},default:{type:"any",required:!1,evaluation:"lazy",description:"The answer when the path is missing — a stored null passes through unchanged (firstOf replaces one); supplying it also opts out of strictDataPaths"}},positionalParams:q,returns:"any",validate:({path:e})=>Wn(e,"path"),evaluate:({path:e,from:t,default:r},a)=>{const n=x(t,Ln(e));if(n.found)return void 0===n.value?null:n.value;if(void 0!==r)return r.evaluate();if(a.options.strictDataPaths)throw new Ca(`'${To(e)}' is missing (strictDataPaths)`,{code:s.missingDataPath});return null}},To=e=>"string"==typeof e?e:e.map(e=>String(e)).join("."),Eo={name:"buildObject",category:"data",description:"Assemble an object from computed key/value entries — for keys known only at runtime",parameters:{entries:{type:"array",constraints:{elementShape:{key:{type:["string","number","boolean"]},value:{type:"any"}}},description:'Objects with a "key" and a "value"; a null value keeps its key'}},positionalParams:["...entries"],returns:"object",validate:e=>[...Gn(e),...qo(e)],evaluate:({entries:e},t)=>{const r={};for(const a of e){const e=re(a.key);Object.hasOwn(r,e)&&t.trace.note({type:"key-overwrite",key:e}),r[e]=a.value}return r}},qo=e=>{const t=e.entries;if(!Array.isArray(t))return[];const r=new Set,a=new Set,n=[];for(const e of t){const t=e?.key;if("string"!=typeof t&&"number"!=typeof t&&"boolean"!=typeof t)continue;const o=re(t);r.has(o)&&!a.has(o)&&(a.add(o),n.push({severity:"warning",parameter:"entries",message:`duplicate key '${o}' — the last entry wins and the earlier one is dead`})),r.add(o)}return n},Mo=(e,t)=>new Ca(`cannot convert ${F(e)} to ${t}`),Fo=/*#__PURE__*/[{name:"and",category:"logic",description:"True when every value is truthy — operands run in parallel",parameters:{values:{type:"array",truthiness:!0,evaluation:"race",description:"Operands, judged by FigTree truthiness; null is falsy"}},positionalParams:["...values"],returns:"boolean",validate:Un,evaluate:({values:e})=>Qn(e,!1)},{name:"or",category:"logic",description:"True when any value is truthy — operands run in parallel",parameters:{values:{type:"array",truthiness:!0,evaluation:"race",description:"Operands, judged by FigTree truthiness; null is falsy"}},positionalParams:["...values"],returns:"boolean",validate:Un,evaluate:({values:e})=>Qn(e,!0)},{name:"not",alias:"!",category:"logic",description:"Negate the truthiness of a value",parameters:{value:{type:"any",truthiness:!0,description:"Judged by FigTree truthiness; null is falsy, so not(null) is true"}},positionalParams:["value"],returns:"boolean",evaluate:({value:e})=>!e},{name:"if",alias:"?",category:"logic",description:"Choose between two branches — only the chosen branch evaluates",parameters:{condition:{type:"any",truthiness:!0,description:"Judged by FigTree truthiness; null is falsy"},then:{type:"any",evaluation:"lazy",description:"The value when the condition holds"},else:{type:"any",evaluation:"lazy",default:null,description:"The value when it does not; omitted means null"}},positionalParams:["condition","then","else"],evaluate:({condition:e,then:t,else:r})=>e?t.evaluate():r.evaluate()},{name:"match",category:"logic",description:"Dispatch on a value — only the matching branch evaluates",parameters:{value:{type:["string","number","boolean","null"],nullPolicy:"value",description:"Matched against branch keys by its canonical string form"},branches:{type:"object",evaluation:"lazyEntries",description:"A literal map of branches, or an expression computing one"},default:{type:"any",required:!1,evaluation:"lazy",description:"The branch taken when none matches; absent means failure"}},positionalParams:["value","branches","default"],evaluate:({value:e,branches:t,default:r})=>{const a=null===e?null:re(e);if(null!==a&&Object.hasOwn(t,a))return t[a].evaluate();if(void 0!==r)return r.evaluate();throw new Ca(`no branch matches ${null===a?"null":`'${a}'`}, and no default was supplied`)}},{name:"firstOf",category:"logic",description:"The first candidate that is not null (SQL COALESCE) — later candidates never evaluate",parameters:{values:{type:"array",evaluation:"lazyElements",description:"Candidates, tried in order; only null is skipped"}},positionalParams:["...values"],validate:Un,evaluate:async({values:e})=>{for(const t of e){const e=await t.evaluate();if(null!==e)return e}return null}},to,ro,no,oo,so,io,uo,po,ho,fo,mo,vo,yo,bo,wo,ko,/*#__PURE__*/$o("min","the minimum","The smallest of the values — numbers numerically, strings in codepoint order",e=>e<0),/*#__PURE__*/$o("max","the maximum","The largest of the values — numbers numerically, strings in codepoint order",e=>e>0),{name:"buildString",category:"string",description:"Render a template, filling its tokens — the result is always a string",parameters:{template:{type:["string","null"],description:"The text, with %N or {{name}} tokens; in a literal template, {{$data.x}} is that reference"},substitutions:{type:["array","object"],default:[],elementNullPolicy:"value",description:"An array pairs with %N tokens, an object with {{name}} tokens; the mode dispatches on which arrives"},trim:{type:"boolean",default:!1,description:"Trim whitespace from each rendered value, never from the template text"},closeGaps:{type:"boolean",default:!1,description:"A value that renders empty also takes one run of adjacent template whitespace"},nullValueDefault:{type:["string","number","boolean"],required:!1,evaluation:"lazy",replacesNullAt:["substitutions"],description:'Rendered in place of a null value, instead of ""'}},positionalParams:["template","...substitutions"],returns:"string",evaluate:({template:e,substitutions:t,trim:r,closeGaps:a},n)=>{const o=Array.isArray(t)?t:void 0,s=void 0===o?t:void 0,i=[];for(const t of we(e)){if("text"===t.kind){i.push({text:t.text,site:!1});continue}if(!("positional"===t.kind?void 0!==o&&t.index>=1&&t.index<=o.length:void 0!==s&&Object.hasOwn(s,t.body))){n.trace.note({type:"render",token:t.raw,rendered:"literal"}),i.push({text:t.raw,site:!1});continue}const e="positional"===t.kind?o[t.index-1]:s[t.body],a=re(e);ae(e)&&n.trace.note({type:"render",token:t.raw,rendered:"placeholder"});const l=r?ce(a):a;""===l&&n.trace.note({type:"render",token:t.raw,rendered:"empty"}),i.push({text:l,site:!0,token:t.raw})}if(a)for(const e of(e=>{const t=[];for(let r=0;r<e.length;r++){const a=e[r];if(!a.site||""!==a.text)continue;const n=e[r-1];if(void 0!==n&&!n.site){const e=pe(n.text);if(e!==n.text){n.text=e,t.push(a.token);continue}}const o=e[r+1];if(void 0!==o&&!o.site){const e=fe(o.text);e!==o.text&&t.push(a.token),o.text=e}}return t})(i))n.trace.note({type:"render",token:e,rendered:"gap-closed"});return i.map(e=>e.text).join("")}},jo,Po,/*#__PURE__*/xo("lower","Lowercase a string — Unicode default case mapping, locale-independent","The string to lowercase",e=>e.toLowerCase()),/*#__PURE__*/xo("upper","Uppercase a string — Unicode default case mapping, locale-independent","The string to uppercase",e=>e.toUpperCase()),/*#__PURE__*/xo("trim","Strip whitespace (the JS trim set) from both ends of a string","The string to trim",ce),{name:"regex",category:"string",description:"Test, extract or match a string against a regular expression",parameters:{value:{type:["string","null"],description:"The subject string"},pattern:{type:["string","null"],description:"The regular expression source"},flags:{type:"string",default:"",description:"The admitted subset: i, m, s, u"},mode:{type:{literal:["test","extract","match"]},default:"test",description:"test gives a boolean, extract the first matching substring, match every one of them"},noMatchDefault:{type:["string","null"],required:!1,default:null,nullPolicy:"value",evaluation:"lazy",description:"The extract answer when nothing matches — a matched empty string still passes through"}},positionalParams:["value","pattern"],returns:["boolean","string","array","null"],validate:({pattern:e,flags:t})=>{const r=[],a="string"==typeof t?Ao(t):void 0;if(void 0!==a&&r.push({severity:"error",parameter:"flags",message:a}),"string"==typeof e)try{new RegExp(e,"string"==typeof t&&void 0===a?t:"")}catch(e){r.push({severity:"error",parameter:"pattern",message:`pattern does not compile: ${e.message}`})}return r},evaluate:({value:e,pattern:t,flags:r,mode:a,noMatchDefault:n})=>{const o=Ao(r);if(void 0!==o)throw new Ca(o);const s=e=>{try{return new RegExp(t,r+e)}catch(e){throw new Ca(`pattern does not compile: ${e.message}`)}};switch(a){case"test":return s("").test(e);case"extract":{const t=s("").exec(e);return null===t?n.evaluate():t[0]}case"match":return[...e.matchAll(s("g"))].map(e=>e[0])}}},{name:"length",category:"array",description:"An array's element count, or a string's Unicode code-point count",parameters:{value:{type:["string","array","null"],description:"The array or string measured"}},positionalParams:["...value"],returns:"integer",evaluate:({value:e})=>"string"==typeof e?me(e).length:e.length},{name:"map",category:"array",description:"Transform every element of an array",parameters:{input:Co,as:Do,nullInputDefault:So,each:{type:"any",evaluation:"perElement",over:"input",description:"Evaluated per element, with $element and $index bound"}},positionalParams:["input","each"],returns:"array",validate:Kn,evaluate:({each:e})=>Yn(e.settle())},{name:"filter",category:"array",description:"Keep the elements of an array whose predicate is truthy",parameters:{input:Co,as:Do,nullInputDefault:So,each:No},positionalParams:["input","each"],returns:"array",validate:Kn,evaluate:async({input:e,each:t})=>{const r=await Yn(t.settle());return e.filter((e,t)=>r[t])}},{name:"find",category:"array",description:"The first element of an array whose predicate is truthy",parameters:{input:Co,as:Do,nullInputDefault:So,each:No,noMatchDefault:{type:"any",required:!1,default:null,evaluation:"lazy",description:"The answer when nothing matches; a found null passes through unchanged"}},positionalParams:["input","each"],validate:Kn,evaluate:async({input:e,each:t,noMatchDefault:r})=>{const a=new Array(e.length);let n=0;for await(const r of t.settle()){a[r.index]=r;for(let t=a[n];void 0!==t;t=a[n]){if(!t.ok)throw t.error;if(!0===t.value)return e[n];n+=1}}return r.evaluate()}},{name:"some",category:"array",description:"True when any element satisfies the predicate",parameters:{input:Co,as:Do,nullInputDefault:So,each:No},positionalParams:["input","each"],returns:"boolean",validate:Kn,evaluate:({each:e})=>Qn(e.settle(),!0)},{name:"every",category:"array",description:"True when every element satisfies the predicate",parameters:{input:Co,as:Do,nullInputDefault:So,each:No},positionalParams:["input","each"],returns:"boolean",validate:Kn,evaluate:({each:e})=>Qn(e.settle(),!1)},zo,Eo,{name:"convert",category:"other",description:"Convert a value to a number, string, boolean or array — strict: a failed conversion is an error, never a guess",parameters:{value:{type:"any",nullPolicy:e=>"boolean"===e?"value":"propagate",description:"The value to convert; null propagates except for boolean, where it is false"},to:{type:{literal:["number","string","boolean","array"]},description:"The target type"}},positionalParams:["value","to"],returns:["number","string","boolean","array"],evaluate:({value:t,to:r})=>{switch(r){case"number":if("number"==typeof t)return t;if("boolean"==typeof t)return t?1:0;if("string"==typeof t){const e=t.trim(),r=""===e?NaN:Number(e);if(Number.isNaN(r))throw new Ca(`'${t}' is not a numeric string — use regex to extract a number from text`);return r}throw Mo(t,"number");case"string":if(Array.isArray(t)||e(t))throw new Ca(`cannot convert ${F(t)} to string — a cast is not a render; use buildString or join`);if("object"==typeof t)throw Mo(t,"string");return re(t);case"boolean":if("string"==typeof t){const e=t.trim().toLowerCase();if("true"===e)return!0;if("false"===e)return!1}return se(t);case"array":return Array.isArray(t)?t:[t]}}}].map(zn),Ro="3.0.0-preview.9",Io=(e,t)=>{const r=((e,t)=>{const r={...e};for(const[e,a]of Object.entries(t)){if(void 0===a)continue;if(null===a){delete r[e];continue}if("data"===e||!n(a)){r[e]=a;continue}const t=r[e],o=n(t)?{...t}:{};for(const[e,t]of Object.entries(a))void 0!==t&&(null===t?delete o[e]:o[e]=t);r[e]=o}return r})(null===e?{}:e.options,t);Xo(r);const a=Vo(r);if(null!==e&&!(e=>void 0!==e.operators||void 0!==e.fragments||void 0!==e.operatorDefaults)(t))return{options:r,evaluation:a,registry:e.registry,compileCache:e.compileCache};const o=zr({operators:r.operators??[Fo],...void 0!==r.operatorDefaults?{operatorDefaults:r.operatorDefaults}:{},...void 0!==r.fragments?{fragments:r.fragments}:{}});return{options:r,evaluation:a,registry:o,compileCache:new wr({compile:e=>Lo(e,o),probe:ke})}},Vo=e=>{const t={...e};return delete t.operators,delete t.fragments,t},Lo=(e,t)=>{const r=Ee(e,t);return Et(r),r.hasNoCache&&rr(r),r};class Wo{state;results;version=Ro;constructor(e={}){this.state=Io(null,e),this.results=new bn(vn(this.state.options.cache))}updateOptions(e={}){const t=Io(this.state,e),r=vn(t.options.cache);this.state=t,this.results.configure(r)}clearCache(){this.results.clear()}getOptions(){return(e=>{const t={};for(const[r,a]of Object.entries(e))t[r]=n(a)?{...a}:a;return t})(this.state.evaluation)}getOperators(){return[...this.state.registry.operators.values()].map(e=>{const{definition:t,hostDefaults:r}=e,a={name:t.name,category:t.category,description:t.description,parameters:xn(t.parameters,r),restParam:t.restParam,timeoutParam:t.timeoutParam,cache:t.cache,returns:t.returns,hasValidate:void 0!==t.validate};return void 0!==t.alias&&(a.alias=t.alias),void 0!==t.metadata&&(a.metadata=t.metadata),void 0!==t.positionalParams&&(a.positionalParams=t.positionalParams),void 0!==r&&(!0===r.noCache&&(a.hostNoCache=!0),Object.hasOwn(r,"fallback")&&(a.hostFallback=r.fallback)),a})}getFragments(){return[...this.state.registry.fragments.values()].map(e=>{const t={name:e.name,parameters:Object.fromEntries(Object.entries(e.parameters).map(([e,t])=>[e,{...t}])),returns:e.returns,warnings:[...e.warnings],dependencies:$n(e.dependencies),caches:e.caches};return void 0!==e.description&&(t.description=e.description),void 0!==e.metadata&&(t.metadata=e.metadata),t})}validate(e,t){const r=void 0===t?this.state.evaluation:Ho(this.state.evaluation,t),a=Lo(e,this.state.registry),n=An(a,r,e=>e.issue);return{valid:!n.some(e=>"error"===e.severity),issues:n}}getDependencies(e){return $n(Ee(e,this.state.registry).dependencies)}isEvaluable(e){const t=Ee(e,this.state.registry);return t.holes.length>0||t.hasErrors}evaluate(e,t){const{state:r}=this;return Jo(r.evaluation,this.results,e,t,()=>r.compileCache.resolve(e),()=>Lo(e,r.registry))}compile(e){const{state:t}=this;return Go(e,t.compileCache.resolve(e),t.evaluation,t.registry,this.results)}}const Jo=async(e,t,r,a,n,o)=>{const s=void 0===a?e:Ho(e,a),i=n(),l="inert"===i.kind&&!0===s.trace?{kind:"artifact",artifact:o()}:i;if("inert"===l.kind){if(void 0!==s.maxDepth&&l.depth>s.maxDepth){const e=Pn(l.depth,s.maxDepth);throw Zo(e,[e])}return r}const{artifact:c}=l,u=On(c,s),d=u.find(e=>"error"===e.severity);if(void 0!==d)throw Zo(d,u);const p=await un(c,s,t);return!0===s.trace?p:p.result};let Bo;const Uo=(e,t)=>Bo?.(e,t);class Ko{#t;#r;#a;#n;#o;#s;#i;constructor(e,t,r,a,n){this.#t=e,this.#r=t,this.#a=r,this.#n=a,this.#o=n,Bo??=(e,t)=>{if("object"!=typeof e||null===e||!(#r in e))return;const r=void 0===t?e.#a:Ho(e.#a,t);return{expression:e.#t,artifact:e.#l(),options:r}}}get expression(){return this.#t}get issues(){return this.#i??=this.#l().issues.map(e=>e.issue)}get hasErrors(){return this.#l().hasErrors}evaluate(e){return Jo(this.#a,this.#o,this.#t,e,()=>this.#r,()=>this.#l())}getDependencies(){return $n(this.#l().dependencies)}#l(){return"artifact"===this.#r.kind?this.#r.artifact:this.#s??=Lo(this.#t,this.#n)}}const Go=(e,t,r,a,n)=>new Ko(e,t,r,a,n),_o=/*#__PURE__*/new Set(Object.keys({data:0,signal:0,timeout:0,trace:0})),Ho=(e,t)=>{let r;for(const a in t){const n=t[a];if(void 0!==n){if(!_o.has(a))throw Qo(a);r??={...e},r[a]=n}}return void 0===r?e:(Xo(t),r)},Qo=e=>new A({code:s.invalidOptions,message:`'${e}' is not a per-call option — a call may supply data, signal, timeout and trace; configure the rest at construction or via updateOptions()`,path:[]}),Xo=e=>{const{timeout:t,signal:r}=e;if(void 0!==t&&("number"!=typeof t||!Number.isFinite(t)||t<=0))throw new A({code:s.invalidOptions,message:"'timeout' must be a positive number of milliseconds",path:[]});if(void 0!==r&&!Yo(r))throw new A({code:s.invalidOptions,message:"'signal' must be an AbortSignal",path:[]})},Yo=e=>"object"==typeof e&&null!==e&&"boolean"==typeof e.aborted&&"function"==typeof e.addEventListener&&"function"==typeof e.removeEventListener,Zo=(e,t)=>new A({code:e.code,message:e.message,path:e.path,...void 0!==e.operator?{operator:e.operator}:{},issues:t});export{Ro as A,An as B,ee as C,te as D,X as E,Wo as F,ie as G,ge as H,Sn as N,Q as O,Dn as R,H as a,V as b,J as c,Fo as d,Da as e,Ce as f,Uo as g,On as h,se as i,W as j,Z as k,G as l,B as m,Tn as n,En as o,Ca as p,Ln as q,Ae as r,Se as s,je as t,re as u,Tt as v,F as w,zn as x,Nn as y,Wn as z};
|