@nova-energy/openamx 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -14
- package/dist/editor/highlighting.js +11 -1
- package/dist/parser/parseStatements.js +40 -0
- package/dist/renderer/chartModel.js +1 -0
- package/dist/renderer/diagramBrowserRuntime.js +1 -1
- package/dist/renderer/renderHtml.js +24 -7
- package/dist/renderer/reportDocx.js +13 -4
- package/dist/renderer/reportPdf.js +2 -0
- package/dist/runtime/evaluateExpression.js +64 -32
- package/dist/runtime/externalUnits.js +21 -6
- package/dist/runtime/inputData.js +7 -2
- package/dist/runtime/measurement.js +28 -1
- package/dist/runtime/outputData.js +5 -3
- package/dist/typechecker/checkDocument.js +152 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,17 +21,16 @@ not certified risk models or industry standards.
|
|
|
21
21
|
results as JSON or CSV.
|
|
22
22
|
- **Build visual explanations.** Create tables, charts, and formula-driven 2D
|
|
23
23
|
diagrams alongside the narrative.
|
|
24
|
-
- **Use the latest language additions.** V0.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
type predicates, mathematical functions, text helpers, and
|
|
29
|
-
|
|
30
|
-
include record inheritance, enums, and braced conditionals.
|
|
24
|
+
- **Use the latest language additions.** V0.19 lets charts omit their data table
|
|
25
|
+
with `showTable false` (the omitted default) and adds affine offset units for
|
|
26
|
+
Celsius/Fahrenheit-style conversions. V0.18 adds diagram-local loops and
|
|
27
|
+
conditionals, V0.16 adds statement-bodied functions, and V0.14 adds runtime
|
|
28
|
+
type predicates, mathematical functions, text helpers, and numeric formatting.
|
|
29
|
+
Earlier additions include record inheritance, enums, and braced conditionals.
|
|
31
30
|
- **Publish reports in familiar formats.** Render standalone, offline HTML or
|
|
32
|
-
export PDF and DOCX. Charts are interactive in HTML
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
export PDF and DOCX. Charts are interactive in HTML, while `showTable true`
|
|
32
|
+
or a true Boolean expression retains their data table across HTML, PDF, and
|
|
33
|
+
DOCX. Omitted or false chart tables are genuinely absent from those outputs.
|
|
35
34
|
- **Choose your authoring environment.** Use the command-line interface (CLI),
|
|
36
35
|
the offline-first desktop workbench, or the VS Code extension.
|
|
37
36
|
|
|
@@ -137,8 +136,12 @@ unified HTML/PDF/DOCX export workflow.
|
|
|
137
136
|
numbered path from the first computable document to a complete report.
|
|
138
137
|
- [First computable document](examples/01_First_Computable_Document.amx) is
|
|
139
138
|
the guide's small, input-free first lesson.
|
|
139
|
+
- [Measurements and units](examples/05_Measurements_and_Units.amx) covers affine
|
|
140
|
+
temperature conversions, PI/E declarations, subtraction, and physical aggregates.
|
|
140
141
|
- [Mapped data and validation](examples/06_Mapped_Data_and_Validation.amx)
|
|
141
142
|
introduces explicit JSON/CSV input mappings.
|
|
143
|
+
- [Tables, charts, and named outputs](examples/07_Tables_Charts_and_Named_Outputs.amx)
|
|
144
|
+
demonstrates omitted, false, true, and expression-controlled chart tables.
|
|
142
145
|
- [Complete asset screening report](examples/12_Complete_Asset_Screening_Report.amx)
|
|
143
146
|
is the guided destination; [route measurements](examples/13_Route_Measurement_Report.amx),
|
|
144
147
|
the [battery-resistor circuit](examples/14_Battery_Resistor_Circuit.amx), and
|
|
@@ -155,10 +158,13 @@ Read the [V0.9 language specification](docs/language-spec-v0.9.md) and
|
|
|
155
158
|
[V0.9 migration guide](docs/migrating-to-v0.9.md), then the additive
|
|
156
159
|
[V0.12 language specification](docs/language-spec-v0.12.md),
|
|
157
160
|
[V0.13 diagram specification](docs/language-spec-v0.13.md), and
|
|
158
|
-
[V0.14 language specification](docs/language-spec-v0.14.md)
|
|
159
|
-
[V0.16 language specification](docs/language-spec-v0.16.md),
|
|
160
|
-
[V0.18 diagram generation specification](docs/language-spec-v0.18.md)
|
|
161
|
-
|
|
161
|
+
[V0.14 language specification](docs/language-spec-v0.14.md), the
|
|
162
|
+
[V0.16 language specification](docs/language-spec-v0.16.md), the
|
|
163
|
+
[V0.18 diagram generation specification](docs/language-spec-v0.18.md), and the
|
|
164
|
+
additive [V0.19 rendering and affine-unit specification](docs/language-spec-v0.19.md)
|
|
165
|
+
for the current language contract. V0.19 omits chart data tables by default;
|
|
166
|
+
authors that intentionally retain one use `showTable true` or another Boolean
|
|
167
|
+
expression that resolves true. Browse the [examples](examples/) and
|
|
162
168
|
[documentation](docs/). The
|
|
163
169
|
[desktop guide](desktop-app/README.md) and
|
|
164
170
|
[VS Code guide](vscode-extension/README.md) cover their respective tools.
|
|
@@ -93,6 +93,7 @@ export function editorHighlightFacts(text, document) {
|
|
|
93
93
|
break;
|
|
94
94
|
case "binaryExpression":
|
|
95
95
|
expression(node.left);
|
|
96
|
+
add(node.operatorSource, node.operator, "keyword");
|
|
96
97
|
expression(node.right);
|
|
97
98
|
break;
|
|
98
99
|
case "typeTestExpression":
|
|
@@ -275,8 +276,17 @@ export function editorHighlightFacts(text, document) {
|
|
|
275
276
|
else
|
|
276
277
|
node.body.statements.forEach(statement);
|
|
277
278
|
}
|
|
278
|
-
else if (node.type === "tableDeclaration" || node.type === "chartDeclaration")
|
|
279
|
+
else if (node.type === "tableDeclaration" || node.type === "chartDeclaration") {
|
|
279
280
|
add(node.bindingSource, node.binding, "reference");
|
|
281
|
+
if (node.type === "chartDeclaration") {
|
|
282
|
+
for (const option of node.options) {
|
|
283
|
+
if (option.type === "chartShowTableOption") {
|
|
284
|
+
add(option.source, "showTable", "keyword");
|
|
285
|
+
expression(option.expression);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
280
290
|
else if (node.type === "showStatement")
|
|
281
291
|
add(node.nameSource, node.name, "reference");
|
|
282
292
|
else if (node.type === "assignmentStatement" || node.type === "compoundAssignmentStatement") {
|
|
@@ -533,6 +533,46 @@ function parseVisualization(lines, startIndex, source, exported) {
|
|
|
533
533
|
options.push({ type: 'viewTitleOption', value: match[1].slice(1, -1), source: optionSource });
|
|
534
534
|
continue;
|
|
535
535
|
}
|
|
536
|
+
if (/^\s*showTable\b/.test(line)) {
|
|
537
|
+
match = line.match(/^(\s*)showTable[ \t]+(.*?)[ \t]*$/);
|
|
538
|
+
if (!match || !match[2].trim())
|
|
539
|
+
return syntaxError('Invalid chart option', optionSource);
|
|
540
|
+
const expressionText = match[2].trimEnd();
|
|
541
|
+
const expressionOffset = line.indexOf(expressionText, match[1].length + 'showTable'.length);
|
|
542
|
+
const expressionSource = { line: optionSource.line, column: expressionOffset + 1 };
|
|
543
|
+
let expression;
|
|
544
|
+
try {
|
|
545
|
+
expression = parseExpression(expressionText, expressionSource);
|
|
546
|
+
}
|
|
547
|
+
catch (error) {
|
|
548
|
+
if (error instanceof AmxError)
|
|
549
|
+
throw error;
|
|
550
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
551
|
+
let errorOffset = 0;
|
|
552
|
+
if (message.startsWith('Unexpected input after expression')) {
|
|
553
|
+
for (let index = 1; index < expressionText.length; index++) {
|
|
554
|
+
if (!/\s/.test(expressionText[index]))
|
|
555
|
+
continue;
|
|
556
|
+
const prefix = expressionText.slice(0, index).trimEnd();
|
|
557
|
+
try {
|
|
558
|
+
parseExpression(prefix);
|
|
559
|
+
errorOffset = index + expressionText.slice(index).search(/\S/);
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
catch {
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return syntaxError(message, {
|
|
567
|
+
line: expressionSource.line,
|
|
568
|
+
column: expressionSource.column + errorOffset
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
options.push({
|
|
572
|
+
type: 'chartShowTableOption', expression, source: optionSource
|
|
573
|
+
});
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
536
576
|
if (header[1] === 'chart' && (match = line.match(new RegExp(`^\\s*description\\s*:\\s*${quoted}\\s*$`)))) {
|
|
537
577
|
options.push({ type: 'viewDescriptionOption', value: match[1].slice(1, -1), source: optionSource });
|
|
538
578
|
continue;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const diagramBrowserRuntime = "(()=>{class M extends Error{code;file;line;column;declarationSource;fieldSource;diagnostics;constructor(e,n){super(e.message);this.name=\"AmxError\",this.code=e.code,this.file=e.file,this.line=e.line,this.column=e.column,this.declarationSource=e.declarationSource,this.fieldSource=e.fieldSource,this.diagnostics=n}}function q(e,n,t={}){return{code:e,message:n,...t}}function B(e){let n=e[0]??q(\"AMX4001\",\"Input validation failed\");throw new M(n,e)}function w(e,n,t,r,i){throw new M({code:e,message:n,file:r,line:t?.line,column:t?.column,declarationSource:i})}function E(e,n,t){throw new M({code:\"AMX1009\",message:e,file:t,line:n?.line,column:n?.column})}function ln(e,n,t){return{code:\"AMX1004\",message:`Undefined identifier '${e}'`,file:t,line:n?.line,column:n?.column}}function ce(e,n,t){let r=ln(e,n,t);throw new M(r)}function ue(e,n){throw new M({code:\"AMX1005\",message:\"Range bounds must be finite integers\",file:n,line:e?.line,column:e?.column})}function $e(e,n){throw new M({code:\"AMX1006\",message:\"For loops require a list or range value\",file:n,line:e?.line,column:e?.column})}function Fe(e,n){throw new M({code:\"AMX1007\",message:\"Return is only valid inside an expression-form for loop\",file:n,line:e?.line,column:e?.column})}function Re(e,n){throw new M({code:\"AMXF4002\",message:\"Function finished without returning a valid expression\",file:n,line:e?.line,column:e?.column})}function S(e,n,t){throw new M({code:\"AMX1008\",message:e,file:t,line:n?.line,column:n?.column})}var Le=new WeakMap;function z(e,n){Le.set(e,n)}function I(e,n){return Le.get(e)??n}class j{store=new Map;recordTypes;enumDeclarations=new Map;enumValues=new Map;functions;bindingTypes=new Map;dimensionRegistry;viewDefinitions=new Map;viewEmissions=[];diagramEmissions=[];immutableValues=new WeakSet;currentDocumentNodeIndex=-1;currentStatementIndex=-1;validationMode=\"aggregate\";constructor(e=new Map,n=new Map,t){this.recordTypes=e,this.functions=n,this.dimensionRegistry=t}createCallFrame(e){let n=new j(this.recordTypes,this.functions,this.dimensionRegistry);n.validationMode=this.validationMode;for(let[t,r]of this.bindingTypes)n.bindingTypes.set(t,r);for(let[t,r]of this.enumDeclarations)n.enumDeclarations.set(t,r);for(let[t,r]of this.enumValues)n.enumValues.set(t,r);for(let[t,r]of Object.entries(e))if(n.set(t,r),this.isImmutable(r))n.markImmutable(r);return n}set(e,n){this.store.set(e,n)}markImmutable(e){let n=(t)=>{if(!t||typeof t!==\"object\"||this.immutableValues.has(t))return;if(this.immutableValues.add(t),Array.isArray(t))t.forEach(n);else Object.values(t).forEach(n)};n(e)}isImmutable(e){return!!e&&typeof e===\"object\"&&this.immutableValues.has(e)}update(e,n,t,r){if(!this.store.has(e))ce(e,t,r);this.store.set(e,n)}delete(e){this.store.delete(e)}get(e,n,t){if(!this.store.has(e))ce(e,n,t);return this.store.get(e)}has(e){return this.store.has(e)}toObject(){let e={};for(let[n,t]of this.store.entries())e[n]=t;return e}clear(){this.store.clear(),this.immutableValues=new WeakSet,this.viewDefinitions.clear(),this.viewEmissions.length=0,this.diagramEmissions.length=0}}function g(e){return!!e&&typeof e===\"object\"&&e.__amxMeasurement===!0&&typeof e.value===\"number\"&&!!e.unit}function ze(e){return Object.freeze(Object.fromEntries(e))}function le(e){let n=[...e].filter((i)=>i.exponent!==0).sort((i,o)=>i.identity<o.identity?-1:i.identity>o.identity?1:0),t=n.filter((i)=>i.exponent>0).map((i)=>`${i.name}${i.exponent===1?\"\":` ^ ${i.exponent}`}`),r=n.filter((i)=>i.exponent<0).map((i)=>`${i.name}${i.exponent===-1?\"\":` ^ ${-i.exponent}`}`);return`${t.length?t.join(\" * \"):\"1\"}${r.length?` / ${r.join(\" * \")}`:\"\"}`}function K(e){let n=[{identity:e.identity,name:e.name,exponent:1}];return Object.freeze({scale:e.scale,vector:ze(e.vector),factors:Object.freeze(n),text:e.name})}function mn(e,n,t){let r=new Map;for(let i of e.factors)r.set(i.identity,{...i});for(let i of n.factors){let o=r.get(i.identity);r.set(i.identity,{identity:i.identity,name:i.name,exponent:(o?.exponent??0)+i.exponent*t})}return[...r.values()].filter((i)=>i.exponent!==0)}function dn(e,n,t){let r={...e.vector};for(let[i,o]of Object.entries(n.vector)){let a=(r[i]??0)+o*t;if(a)r[i]=a;else delete r[i]}return r}function je(e,n,t=!1){let r=t?-1:1,i=mn(e,n,r);return Object.freeze({scale:t?e.scale/n.scale:e.scale*n.scale,vector:Object.freeze(dn(e,n,r)),factors:Object.freeze(i),text:le(i)})}function me(e,n){let t=e.factors.map((r)=>({...r,exponent:r.exponent*n})).filter((r)=>r.exponent!==0);return Object.freeze({scale:Math.pow(e.scale,n),vector:Object.freeze(Object.fromEntries(Object.entries(e.vector).map(([r,i])=>[r,i*n]).filter(([,r])=>r!==0))),factors:Object.freeze(t),text:le(t)})}function A(e,n){return Object.freeze({__amxMeasurement:!0,value:e,unit:n})}function J(e,n){let t=[];for(let[r,i]of[...e].sort(([o],[a])=>o<a?-1:o>a?1:0)){let o=n.baseUnits.get(r);if(!o)throw Error(`No visible canonical base unit for dimension identity ${r}`);t.push({identity:o.identity,name:o.name,exponent:i})}return Object.freeze({scale:1,vector:ze(e),factors:Object.freeze(t),text:le(t)})}function Xe(e,n){let t=new Map;for(let[l,u]of Object.entries(e.unit.vector)){if(u%2!==0)throw Error(\"sqrt requires integral measurement dimension exponents\");t.set(l,u/2)}let r=e.value*e.unit.scale,i=Math.sqrt(r);if(!Number.isFinite(i))return A(i,J(t,n));let o=Math.sqrt(e.unit.scale),a=[...n.units.values()].find((l)=>l.scale===o&&l.vector.size===t.size&&[...t].every(([u,c])=>l.vector.get(u)===c));if(a)return A(i/a.scale,K(a));let s=J(t,n);return A(i,s)}function Q(e,n,t,r){if(!Array.isArray(e)){let i=t?` at line ${t.line}`:\"\";throw new M({code:\"AMX2001\",message:`${n} expects a list${i}`,file:r,line:t?.line,column:t?.column})}return e}function N(e,n,t,r){if(typeof e===\"number\")return e;if(typeof e===\"boolean\")return e?1:0;if(typeof e===\"string\"){let o=Number(e);if(!Number.isNaN(o))return o}let i=t?` at line ${t.line}`:\"\";throw new M({code:\"AMX2002\",message:`${n} requires a numeric value${i}`,file:r,line:t?.line,column:t?.column})}function X(e,n,t,r,i){if(e.length!==n){let o=r?` at line ${r.line}`:\"\";throw new M({code:\"AMX2003\",message:`${t} expects ${n} argument(s), got ${e.length}${o}`,file:i,line:r?.line,column:r?.column})}}function fn(e,n,t,r,i){if(e.length<n){let o=r?` at line ${r.line}`:\"\";throw new M({code:\"AMX2003\",message:`${t} expects at least ${n} argument(s), got ${e.length}${o}`,file:i,line:r?.line,column:r?.column})}}var Ue={sin:{evaluate:Math.sin,accepts:Number.isFinite},cos:{evaluate:Math.cos,accepts:Number.isFinite},tan:{evaluate:Math.tan,accepts:Number.isFinite},asin:{evaluate:Math.asin,accepts:(e)=>Number.isFinite(e)&&e>=-1&&e<=1},acos:{evaluate:Math.acos,accepts:(e)=>Number.isFinite(e)&&e>=-1&&e<=1},atan:{evaluate:Math.atan,accepts:Number.isFinite},sinh:{evaluate:Math.sinh,accepts:Number.isFinite},cosh:{evaluate:Math.cosh,accepts:Number.isFinite},tanh:{evaluate:Math.tanh,accepts:Number.isFinite},asinh:{evaluate:Math.asinh,accepts:Number.isFinite},acosh:{evaluate:Math.acosh,accepts:(e)=>Number.isFinite(e)&&e>=1},atanh:{evaluate:Math.atanh,accepts:(e)=>Number.isFinite(e)&&e>-1&&e<1},ln:{evaluate:Math.log,accepts:(e)=>Number.isFinite(e)&&e>0},log:{evaluate:Math.log10,accepts:(e)=>Number.isFinite(e)&&e>0},exp:{evaluate:Math.exp,accepts:Number.isFinite}};function qe(e){return Object.hasOwn(Ue,e)}function Ve(e,n,t,r){return new M({code:e,message:n,file:r,line:t?.line,column:t?.column})}function k(e,n,t,r){return new M({code:e,message:n,file:r,line:t?.line,column:t?.column})}function de(e){if(e===null)return\"null\";if(g(e))return\"Measurement\";if(Array.isArray(e))return\"list\";if(typeof e===\"number\")return\"Number\";if(typeof e===\"string\")return\"String\";if(typeof e===\"boolean\")return\"Boolean\";return typeof e}function ee(e,n,t,r,i,o){if(n.length<t||n.length>r)throw k(\"AMX3004\",`Invalid arity for '${e}'`,i,o)}function Oe(e,n,t,r){if(typeof n!==\"string\")throw k(\"AMX3002\",`${e} requires a String, got ${de(n)}`,t,r);return n}function Ce(e){return e>=9&&e<=13||e===32||e===133||e===160||e===5760||e>=8192&&e<=8202||e===8232||e===8233||e===8239||e===8287||e===12288}function pn(e){let n=Array.from(e),t=0,r=n.length;while(t<r&&Ce(n[t].codePointAt(0)))t++;while(r>t&&Ce(n[r-1].codePointAt(0)))r--;return n.slice(t,r).join(\"\")}function gn(e,n,t){if(typeof e!==\"string\")throw k(\"AMXSL004\",\"Incorrect formatting pattern\",n,t);let r=/^([$€£])?(#,##0|0)(?:\\.(0{1,6}))?(%)?$/.exec(e);if(!r)throw k(\"AMXSL004\",\"Incorrect formatting pattern\",n,t);return{currency:r[1]??\"\",grouped:r[2]===\"#,##0\",precision:r[3]?.length??0,percent:r[4]===\"%\"}}function yn(e,n,t){switch(e){case\"en-US\":return{decimal:\".\",group:\",\"};case\"de-DE\":return{decimal:\",\",group:\".\"};case\"fr-FR\":return{decimal:\",\",group:\" \"};default:throw k(\"AMXSL005\",\"Formatting locale is malformed or unsupported\",n,t)}}function bn(e,n){let[t,r]=Math.abs(e).toString().toLowerCase().split(\"e\"),i=r===void 0?0:Number(r),[o,a=\"\"]=t.split(\".\"),s=`${o}${a}`.replace(/^0+(?=\\d)/,\"\"),l=BigInt(s||\"0\"),u=n+i-a.length;if(u>=0)return l*10n**BigInt(u);let c=10n**BigInt(-u),m=l/c,d=l%c;return m+(d*2n>=c?1n:0n)}function hn(e,n){return e.replace(/\\B(?=(\\d{3})+(?!\\d))/g,n)}function wn(e,n,t){let r=n.percent?e*100:e,i=r<0,o=10n**BigInt(n.precision),a=bn(r,n.precision),s=(a/o).toString(),l=n.precision?`${t.decimal}${(a%o).toString().padStart(n.precision,\"0\")}`:\"\",u=n.grouped?hn(s,t.group):s;return`${i?\"-\":\"\"}${n.currency}${u}${l}${n.percent?\"%\":\"\"}`}function _(e,n,t,r,i=[]){let o=(s)=>i[s]??t;if(e===\"len\"){ee(e,n,1,1,t,r);let s=n[0];if(typeof s===\"string\")return Array.from(s).length;if(Array.isArray(s))return s.length;throw k(\"AMX3002\",`len requires a String or list, got ${de(s)}`,o(0),r)}if(e===\"trim\")return ee(e,n,1,1,t,r),pn(Oe(e,n[0],o(0),r));if(e===\"left\"||e===\"right\"){ee(e,n,1,2,t,r);let s=Array.from(Oe(e,n[0],o(0),r)),l=n.length===1?1:n[1];if(typeof l!==\"number\"||!Number.isFinite(l)||!Number.isInteger(l)||l<0)throw k(\"AMXSL003\",\"Invalid text slice count\",o(1),r);let u=Math.min(l,s.length);return e===\"left\"?s.slice(0,u).join(\"\"):s.slice(s.length-u).join(\"\")}if(e===\"format\"){ee(e,n,2,3,t,r);let s=n[0],l=o(0);if(typeof s!==\"number\"&&!g(s))throw k(\"AMX3002\",`format expects a Number or Measurement, got ${de(s)}`,l,r);let u=g(s)?s.value:s;if(!Number.isFinite(u))throw k(\"AMXSL006\",\"Input is non-finite\",l,r);let c=gn(n[1],o(1),r),m=yn(n.length===3?n[2]:\"en-US\",o(2),r);if(c.percent&&!Number.isFinite(u*100))throw k(\"AMXSL006\",\"Input is non-finite\",l,r);let d=wn(u,c,m);return g(s)?`${d} ${s.unit.text}`:d}let a=Ue[e];if(a){if(n.length!==1)throw new M({code:\"AMX3004\",message:`Invalid arity for '${e}'`,file:r,line:t?.line,column:t?.column});let s=n[0];if(typeof s!==\"number\"){let u=s===null?\"null\":Array.isArray(s)?\"list\":typeof s===\"object\"?\"Measurement\":typeof s===\"string\"?\"String\":typeof s===\"boolean\"?\"Boolean\":typeof s;throw new M({code:\"AMX3002\",message:`Expected Number or dimensionless Measurement, got ${u}`,file:r,line:t?.line,column:t?.column})}if(!a.accepts(s))throw Ve(\"AMXSL001\",\"Invalid input for mathematical function\",t,r);let l=a.evaluate(s);if(!Number.isFinite(l))throw Ve(\"AMXSL002\",\"Function evaluation results in infinite result\",t,r);return l}switch(e){case\"sum\":return X(n,1,\"sum\",t,r),Q(n[0],\"sum\",t,r).reduce((u,c)=>u+N(c,\"sum element\",t,r),0);case\"min\":{X(n,1,\"min\",t,r);let l=Q(n[0],\"min\",t,r);if(l.length===0){let u=t?` at line ${t.line}`:\"\";throw new M({code:\"AMX2004\",message:`min of empty list${u}`,file:r,line:t?.line,column:t?.column})}return l.reduce((u,c)=>Math.min(u,N(c,\"min element\",t,r)),Number.POSITIVE_INFINITY)}case\"max\":{X(n,1,\"max\",t,r);let l=Q(n[0],\"max\",t,r);if(l.length===0){let u=t?` at line ${t.line}`:\"\";throw new M({code:\"AMX2004\",message:`max of empty list${u}`,file:r,line:t?.line,column:t?.column})}return l.reduce((u,c)=>Math.max(u,N(c,\"max element\",t,r)),Number.NEGATIVE_INFINITY)}case\"mean\":{X(n,1,\"mean\",t,r);let l=Q(n[0],\"mean\",t,r);if(l.length===0){let c=t?` at line ${t.line}`:\"\";throw new M({code:\"AMX2004\",message:`mean of empty list${c}`,file:r,line:t?.line,column:t?.column})}return l.reduce((c,m)=>c+N(m,\"mean element\",t,r),0)/l.length}case\"round\":{fn(n,1,\"round\",t,r);let l=N(n[0],\"round value\",t,r),u=n.length>1?N(n[1],\"round digits\",t,r):0,c=Math.pow(10,Math.trunc(u));return Math.round(l*c)/c}case\"abs\":{X(n,1,\"abs\",t,r);let l=N(n[0],\"abs value\",t,r);return Math.abs(l)}case\"sqrt\":{X(n,1,\"sqrt\",t,r);let l=N(n[0],\"sqrt value\",t,r);if(l<0){let u=t?` at line ${t.line}`:\"\";throw new M({code:\"AMX2005\",message:`sqrt of negative value${u}`,file:r,line:t?.line,column:t?.column})}return Math.sqrt(l)}case\"pow\":{X(n,2,\"pow\",t,r);let l=N(n[0],\"pow base\",t,r),u=N(n[1],\"pow exponent\",t,r);return Math.pow(l,u)}default:let s=t?` at line ${t.line}`:\"\";throw new M({code:\"AMX2000\",message:`Unknown function '${e}'${s}`,file:r,line:t?.line,column:t?.column})}}function V(e,n,t,r,i,o){let a=[],s=(u,c,m,d,f)=>{let p=q(\"AMX4003\",u,{file:i,line:r?.line,column:r?.column,dataPath:d,expected:fe(c),actual:ge(m),fieldSource:f});if(a.push(p),t.validationMode===\"fail-fast\")B([p])},l=(u,c,m,d)=>{if(c.kind===\"null\"){if(u!==null)s(\"Expected null\",c,u,m,d);return}if(c.kind===\"nullable\"){if(u!==null)l(u,c.element,m,d);return}if(c.kind===\"list\"){if(!Array.isArray(u)){s(\"Expected a list value\",c,u,m,d);return}u.forEach((h,D)=>l(h,c.element,`${m}[${D}]`,d));return}if(c.kind===\"measurement\"){if(!g(u)){s(\"Expected a measurement value\",c,u,m,d);return}let h=u.unit.vector;if(Object.keys(h).length!==c.vector.size||[...c.vector].some(([D,L])=>h[D]!==L))s(\"Measurement dimension does not match the declared dimension\",c,u,m,d);if(!Number.isFinite(u.value)||!Number.isFinite(u.value*u.unit.scale))s(\"Measurement value must be finite\",c,u,m,d);return}if(c.kind!==\"named\")return;if(c.name===\"Number\"){if(typeof u!==\"number\"||!Number.isFinite(u))s(\"Expected a finite Number value\",c,u,m,d);return}if(c.name===\"String\"||c.name===\"DateTime\"){if(typeof u!==\"string\")s(`Expected a ${c.name} value`,c,u,m,d);else if(c.name===\"DateTime\"&&!Pe(u))s(\"Invalid RFC 3339 DateTime value\",c,u,m,d);return}if(c.name===\"Boolean\"){if(typeof u!==\"boolean\")s(\"Expected a Boolean value\",c,u,m,d);return}let f=t.recordTypes.get(c.name);if(!f||typeof u!==\"object\"||u===null||Array.isArray(u)){s(`Expected a ${c.name} record`,c,u,m,d);return}let p=u,b=new Set(f.fields.map((h)=>h.name));for(let h of f.fields){let D=I(h,t.dimensionRegistry);if(!Object.prototype.hasOwnProperty.call(p,h.name))s(`Missing computed field '${h.name}'`,P(h.annotation,D),\"missing\",`${m}.${h.name}`,h.source);else l(p[h.name],P(h.annotation,D),`${m}.${h.name}`,h.source)}for(let h of Object.keys(p).filter((D)=>!b.has(D)).sort())s(`Unknown computed field '${h}'`,c,p[h],`${m}.${h}`,d)};if(l(e,n,o),a.length)B(a)}function Mn(e,n,t){if(!e.defaultExpression)return null;let r=n.dimensionRegistry;n.dimensionRegistry=I(e,r);try{return y(e.defaultExpression,n,t)}finally{n.dimensionRegistry=r}}function P(e,n){let t=n instanceof j?n.dimensionRegistry:n;if(e.type===\"namedType\"){let i=t?.dimensions.get(e.name);return i?{kind:\"measurement\",vector:i.vector}:{kind:\"named\",name:e.name}}let r=P(e.element,t);return e.type===\"listType\"?{kind:\"list\",element:r}:{kind:\"nullable\",element:r}}function fe(e){if(e.kind===\"named\")return e.name;if(e.kind===\"measurement\")return\"measurement\";if(e.kind===\"null\")return\"null\";return e.kind===\"list\"?`${fe(e.element)}[]`:`${fe(e.element)}?`}function ge(e){if(typeof e===\"number\"&&!Number.isFinite(e))return String(e);let n;try{n=JSON.stringify(e)??String(e)}catch{n=String(e)}return n.replace(/[\\x00-\\x1f\\x7f]/g,(t)=>`\\\\u${t.charCodeAt(0).toString(16).padStart(4,\"0\")}`).slice(0,160)}function W(e,n){return Object.keys(e.unit.vector).length===n.size&&[...n].every(([t,r])=>e.unit.vector[t]===r)}function Pe(e){let n=e.match(/^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(?:\\.\\d{1,9})?(Z|[+-]\\d{2}:\\d{2})$/);if(!n)return!1;let[,t,r,i,o,a,s,l]=n,u=new Date(0);return u.setUTCFullYear(+t,+r-1,+i),u.getUTCFullYear()===+t&&u.getUTCMonth()===+r-1&&u.getUTCDate()===+i&&+o<=23&&+a<=59&&+s<=59&&(l===\"Z\"||+l.slice(1,3)<=23&&+l.slice(4)<=59)}function ne(e,n,t,r,i=t.dimensionRegistry){if(n.type===\"nullableType\")return e===null||ne(e,n.element,t,r,i);if(n.type===\"listType\")return Array.isArray(e)&&e.every((u)=>ne(u,n.element,t,r,i));let o=n.name,a=i?.dimensions.get(o);if(a)return g(e)&&W(e,a.vector);if(o===\"Number\")return typeof e===\"number\";if(o===\"String\")return typeof e===\"string\";if(o===\"Boolean\")return typeof e===\"boolean\";if(o===\"DateTime\")return typeof e===\"string\"&&Pe(e);let s=t.enumDeclarations.get(o);if(s){if(typeof e!==\"number\"&&typeof e!==\"string\")return!1;if(!s.resolvedValues)throw Error(`Enum '${o}' has not been resolved`);return s.resolvedValues.includes(e)}let l=t.recordTypes.get(o);if(l){if(typeof e!==\"object\"||e===null||Array.isArray(e)||g(e))return!1;let u=e;return l.fields.every((c)=>{if(!Object.prototype.hasOwnProperty.call(u,c.name))return c.optional;return ne(u[c.name],c.annotation,t,r,I(c,i))})}return w(\"AMX3001\",`Unknown type '${o}'`,n.source,r)}function y(e,n,t){switch(e.type){case\"nullLiteral\":return null;case\"recordConstructor\":{let r=n.recordTypes.get(e.name);if(!r)throw Error(`Unknown record type '${e.name}'`);let i=new Map(e.fields.map((a)=>[a.name,y(a.expression,n,t)])),o={};for(let a of r.fields)o[a.name]=i.has(a.name)?i.get(a.name):a.defaultExpression?Mn(a,n,t):null;return V(o,{kind:\"named\",name:e.name},n,e.source,t,`record ${e.name}`),o}case\"fieldAccess\":{if(e.receiver.type===\"identifier\"){let r=n.enumValues.get(e.receiver.name);if(r)return r[e.field]}return y(e.receiver,n,t)[e.field]}case\"listAccess\":return kn(e,n,t);case\"numberLiteral\":return e.value;case\"stringLiteral\":return e.value;case\"stringInterpolation\":return e.parts.map((r)=>{if(typeof r===\"string\")return r;let i=y(r,n,t);if(i===null)return\"null\";if(typeof i===\"string\"||typeof i===\"number\")return String(i);if(typeof i===\"boolean\")return i?\"true\":\"false\";if(g(i))return`${String(i.value)} ${i.unit.text}`;return w(\"AMX3007\",\"Only String, Number, Boolean, measurement, and null values can be interpolated\",r.source,t)}).join(\"\");case\"booleanLiteral\":return e.value;case\"identifier\":if(e.name===\"PI\")return Math.PI;if(e.name===\"E\")return Math.E;return n.get(e.name,e.source,t);case\"measurementAttachment\":{let r=y(e.value,n,t),i=n.dimensionRegistry?.units.get(e.unit);if(!i)return w(\"AMX3008\",`Unknown or invisible unit '${e.unit}'`,e.unitSource??e.source,t);if(typeof r!==\"number\")return w(\"AMX3007\",\"Unit attachment requires a Number expression\",e.source,t);let o=A(r,K(i));if(!Number.isFinite(o.value*o.unit.scale))E(\"Measurement physical value must be finite\",e.source,t);return o}case\"measurementConversion\":{let r=y(e.value,n,t),i=n.dimensionRegistry?.units.get(e.unit);if(!i)return w(\"AMX3008\",`Unknown or invisible unit '${e.unit}'`,e.unitSource??e.source,t);if(!g(r)||!W(r,i.vector))return w(\"AMX3007\",`Cannot convert value to unit '${e.unit}'`,e.source,t);let o=r.value*r.unit.scale/i.scale;if(!Number.isFinite(o))E(\"Converted measurement value must be finite\",e.source,t);return A(o,K(i))}case\"binaryExpression\":return vn(e,n,t);case\"typeTestExpression\":return ne(y(e.value,n,t),e.target,n,t);case\"unaryExpression\":return En(e,n,t);case\"conditionalExpression\":return An(e,n,t);case\"bracedIfExpression\":return Sn(e,n,t);case\"listLiteral\":return Nn(e,n,t);case\"functionCall\":return In(e,n,t);case\"rangeExpression\":return Xn(e,n,t);case\"forExpression\":return On(e,n,t);case\"matchExpression\":return xn(e,n,t);default:throw Error(`Unsupported expression node type: ${e}`)}}function xn(e,n,t){let r=y(e.expression,n,t);for(let i of e.cases)if(r===i.value.value)return y(i.expression,n,t);return y(e.defaultExpression,n,t)}function vn(e,n,t){let r=y(e.left,n,t),i=y(e.right,n,t),o=e.operatorSource??e.source;switch(e.operator){case\"+\":case\"-\":{if(g(r)||g(i)){if(!g(r)||!g(i)||!W(r,new Map(Object.entries(i.unit.vector))))return w(\"AMX3007\",\"Addition and subtraction require compatible measurements\",o,t);let l=r.value*r.unit.scale,u=i.value*i.unit.scale,c=e.operator===\"+\"?l+u:l-u,m=c/r.unit.scale;if(!Number.isFinite(m)||!Number.isFinite(c))E(\"Measurement arithmetic result must be finite\",o,t);return A(m,r.unit)}let a=x(r,e.left),s=x(i,e.right);return e.operator===\"+\"?a+s:a-s}case\"*\":case\"/\":{if(g(r)||g(i)){let l={scale:1,vector:{},factors:[],text:\"1\"},u=g(r)?r:void 0,c=g(i)?i:void 0,m=u?u.value:x(r,e.left),d=c?c.value:x(i,e.right),f=u?.unit??l,p=c?.unit??l,b=d*p.scale;if(e.operator===\"/\"&&b===0)E(\"Measurement division by zero\",o,t);let h=je(f,p,e.operator===\"/\"),D=e.operator===\"/\"?m*f.scale/b:m*f.scale*d*p.scale;if(h.vector&&Object.keys(h.vector).length===0){if(!Number.isFinite(D))E(\"Measurement arithmetic result must be finite\",o,t);return D}let L=e.operator===\"/\"?m/d:m*d;if(!Number.isFinite(h.scale)||h.scale<=0||!Number.isFinite(L)||!Number.isFinite(D))E(\"Measurement arithmetic result must be finite\",o,t);return A(L,h)}let a=x(r,e.left),s=x(i,e.right);return e.operator===\"*\"?a*s:a/s}case\"%\":{let a=x(r,e.left),s=x(i,e.right);return a%s}case\"^\":{if(g(r)){let l=x(i,e.right);if(!Number.isSafeInteger(l))return w(\"AMX3007\",\"A dimensional power exponent must be an integer literal\",e.right.source,t);if(r.value===0&&l<0)E(\"Zero measurement cannot be raised to a negative power\",o,t);let u=me(r.unit,l),c=Math.pow(r.value,l);if(!Number.isFinite(c)||!Number.isFinite(u.scale))E(\"Measurement power result must be finite\",o,t);if(Object.keys(u.vector).length===0)return c*u.scale;return A(c,u)}let a=x(r,e.left),s=x(i,e.right);return Math.pow(a,s)}case\"==\":if(g(r)&&g(i))return W(r,new Map(Object.entries(i.unit.vector)))&&r.value*r.unit.scale===i.value*i.unit.scale;return r===i;case\"!=\":if(g(r)&&g(i))return!W(r,new Map(Object.entries(i.unit.vector)))||r.value*r.unit.scale!==i.value*i.unit.scale;return r!==i;case\">\":if(g(r)&&g(i))return r.value*r.unit.scale>i.value*i.unit.scale;return x(r,e.left)>x(i,e.right);case\">=\":if(g(r)&&g(i))return r.value*r.unit.scale>=i.value*i.unit.scale;return x(r,e.left)>=x(i,e.right);case\"<\":if(g(r)&&g(i))return r.value*r.unit.scale<i.value*i.unit.scale;return x(r,e.left)<x(i,e.right);case\"<=\":if(g(r)&&g(i))return r.value*r.unit.scale<=i.value*i.unit.scale;return x(r,e.left)<=x(i,e.right);case\"and\":return T(r)&&T(i);case\"or\":return T(r)||T(i);default:throw Error(`Unsupported binary operator: ${e.operator}`)}}function En(e,n,t){let r=y(e.argument,n,t);if(e.operator===\"-\"){if(g(r))return A(-r.value,r.unit);return-x(r,e.argument)}if(e.operator===\"not\")return!T(r);throw Error(`Unsupported unary operator: ${e.operator}`)}function An(e,n,t){let r=y(e.test,n,t);return T(r)?y(e.consequent,n,t):y(e.alternate,n,t)}class ye{value;constructor(e){this.value=e}}class be{value;constructor(e){this.value=e}}class he{value;constructor(e){this.value=e}}var We=new WeakMap,He=new WeakMap,we=new WeakMap,te=new WeakMap;function Me(e,n,t){e.set(n,(e.get(n)??0)+1);try{return t()}finally{let r=e.get(n)-1;if(r)e.set(n,r);else e.delete(n)}}function Dn(e,n){let t=te.get(n),r=t?.[t.length-1];if(!r||r.has(e))return;let i=n.has(e);r.set(e,{existed:i,value:i?n.get(e):void 0})}function xe(e,n,t){let r=te.get(n)??[],i=new Map;r.push(i),te.set(n,r);try{ve(e,n,t)}finally{r.pop();for(let[o,a]of i)if(a.existed)n.set(o,a.value);else n.delete(o);if(!r.length)te.delete(n)}}function Sn(e,n,t){let r=T(y(e.test,n,t))?e.consequent:e.alternate,i=r===e.consequent?e.consequentSource:e.alternateSource;try{Me(We,n,()=>xe(r,n,t))}catch(o){if(o instanceof ye)return o.value;throw o}return w(\"AMX3021\",\"Every possible path in an if expression must return a value\",i??e.source,t)}function Nn(e,n,t){return e.elements.map((r)=>y(r,n,t))}function kn(e,n,t){let r=y(e.receiver,n,t),i=y(e.index,n,t);if(!Array.isArray(r))S(\"List access requires a list value\",e.source,t);if(typeof i!==\"number\"||!Number.isFinite(i)||!Number.isInteger(i)||i<1)S(`List index must be a positive integer; got ${ge(i)}`,e.index.source??e.source,t);if(i>r.length)S(`List index ${i} is out of bounds for length ${r.length}; expected 1..${r.length}`,e.index.source??e.source,t);return r[i-1]}function re(e,n){if(e.type===\"binaryExpression\")return re(e.left,n)??e.operatorSource??e.source??n;if(e.type===\"unaryExpression\"){let t=re(e.argument,n);if(t)return{line:t.line,column:Math.max(1,t.column-(e.operator===\"not\"?3:1))}}if(e.type===\"measurementAttachment\"||e.type===\"measurementConversion\")return re(e.value,n)??e.source??n;return e.source??n}function _e(e){return Array.isArray(e)?e.map(_e):e}function Tn(e){return e.kind===\"list\"||e.kind===\"nullable\"&&e.element.kind===\"list\"}function In(e,n,t){let r=e.arguments.map((a)=>y(a,n,t)),i=n.functions.get(e.callee);if(i){let a=I(i,n.dimensionRegistry),s={};i.parameters.forEach((m,d)=>{let f=P(m.annotation,a);V(r[d],f,n,e.arguments[d]?.source??e.source,t,`function ${e.callee}.${m.name}`);let p=r[d];s[m.name]=Tn(f)&&p!==null?_e(p):p});let l=n.createCallFrame(s);l.dimensionRegistry=a,i.parameters.forEach((m)=>{l.bindingTypes.set(m.name,P(m.annotation,a))});let u,c=i.body;if(c.kind===\"expression\")u=y(c.expression,l,t);else{let m=!1;try{Me(we,l,()=>ve(c.statements,l,t))}catch(d){if(!(d instanceof he))throw d;m=!0,u=d.value}if(!m)Re(c.closingSource,t)}return V(u,P(i.returnType,a),n,e.source,t,`function ${e.callee} return`),u}let o=r[0];if([\"sum\",\"mean\",\"min\",\"max\"].includes(e.callee)&&Array.isArray(o)&&(o.length>0&&g(o[0]))){let a=o,s=a[0];for(let c of a){if(!W(s,new Map(Object.entries(c.unit.vector))))return w(\"AMX3007\",`${e.callee} requires compatible measurement dimensions`,e.source,t);if(Array.isArray(o)&&o.length>0&&typeof o[0]===\"number\"&&[\"sum\",\"mean\",\"min\",\"max\"].includes(e.callee))return _(e.callee,r,e.source,t)}if(e.callee===\"min\"||e.callee===\"max\"){if(!a.length)return _(e.callee,r,e.source,t);return a.reduce((c,m)=>(e.callee===\"min\"?m.value*m.unit.scale<c.value*c.unit.scale:m.value*m.unit.scale>c.value*c.unit.scale)?m:c)}let l=a.reduce((c,m)=>c+m.value*m.unit.scale,0),u=(e.callee===\"mean\"?l/a.length:l)/s.unit.scale;if(!Number.isFinite(u))E(`${e.callee} result must be finite`,e.source,t);return A(u,s.unit)}if(e.callee===\"sum\"&&Array.isArray(o)&&o.length===0&&e.arguments[0]?.type===\"identifier\"){let a=n.bindingTypes.get(e.arguments[0].name);if(a?.kind===\"list\"&&a.element.kind===\"measurement\"&&n.dimensionRegistry)return A(0,J(a.element.vector,n.dimensionRegistry))}if(g(r[0])){let a=r[0];if(qe(e.callee)){if(Object.keys(a.unit.vector).length!==0)return w(\"AMX3007\",`'${e.callee}' requires a Number or dimensionless Measurement`,e.arguments[0]?.source??e.source,t);return _(e.callee,[a.value*a.unit.scale],e.source,t)}switch(e.callee){case\"abs\":return A(Math.abs(a.value),a.unit);case\"round\":{let s=r.length>1?x(r[1],e.arguments[1]):0,l=Math.pow(10,Math.trunc(s)),u=Math.round(a.value*l)/l;if(!Number.isFinite(u))E(\"round result must be finite\",e.source,t);return A(u,a.unit)}case\"sqrt\":{if(a.value*a.unit.scale<0)E(\"sqrt of a negative measurement value\",e.source,t);if(!n.dimensionRegistry)throw Error(\"Measurement registry is unavailable during sqrt evaluation\");try{let l=Xe(a,n.dimensionRegistry);if(!Number.isFinite(l.value)||!Number.isFinite(l.unit.scale))E(\"sqrt result must be finite\",e.source,t);if(Object.keys(l.unit.vector).length===0)return l.value*l.unit.scale;return l}catch(l){if(l instanceof Error&&l.message.startsWith(\"sqrt requires\"))return w(\"AMX3007\",l.message,e.source,t);throw l}}case\"pow\":{let s=x(r[1],e.arguments[1]);if(!Number.isSafeInteger(s))return w(\"AMX3007\",\"A dimensional pow exponent must be an integer literal\",e.arguments[1]?.source,t);if(a.value===0&&s<0)E(\"Zero measurement cannot be raised to a negative power\",e.source,t);let l=me(a.unit,s),u=Math.pow(a.value,s);if(!Number.isFinite(u)||!Number.isFinite(l.scale))E(\"pow result must be finite\",e.source,t);if(!Object.keys(l.vector).length)return u*l.scale;return A(u,l)}}}return _(e.callee,r,e.source,t,e.arguments.map((a)=>re(a,e.source)))}function x(e,n){if(typeof e===\"number\")return e;if(typeof e===\"boolean\")return e?1:0;if(typeof e===\"string\"){let i=Number(e);if(!Number.isNaN(i))return i}let t=n?.source,r=t?` at line ${t.line}`:\"\";throw Error(`Cannot convert value to number${r}`)}function T(e){if(typeof e===\"boolean\")return e;if(typeof e===\"number\")return e!==0;if(typeof e===\"string\")return e.length>0;if(Array.isArray(e))return e.length>0;if(e&&typeof e===\"object\")return!0;return!1}function ve(e,n,t){let r=n.currentStatementIndex;try{for(let i=0;i<e.length;i++)n.currentStatementIndex=i,Ye(e[i],n,t)}finally{n.currentStatementIndex=r}}function H(e){if(g(e))return`${e.value} ${e.unit.text}`;if(Array.isArray(e))return Object.freeze(e.map(H));if(e&&typeof e===\"object\"){let n={};for(let[t,r]of Object.entries(e))n[t]=H(r);return Object.freeze(n)}return e}function $n(e,n,t,r){let i=n.viewDefinitions.get(e);if(!i)return w(\"AMX3001\",`Unknown visualization '${e}'`,r,t);let o=n.get(i.binding,i.bindingSource,t);if(!Array.isArray(o)){let m=q(\"AMX4003\",`Visualization '${e}' requires a list value`,{file:t,line:i.bindingSource?.line,column:i.bindingSource?.column,dataPath:`visualization ${e}`,expected:\"list\",actual:Array.isArray(o)?\"list\":typeof o});B([m])}let a,s,l,u;if(i.type===\"chartDeclaration\"){let m=i.options.find((f)=>f.type===\"chartFieldOption\"&&f.role===\"labels\");if(m?.type===\"chartFieldOption\"){let f=n.get(m.field,m.fieldSource,t);if(!Array.isArray(f)||!f.every((p)=>typeof p===\"string\")){let p=q(\"AMX4003\",`Chart '${e}' labels must be a String[] value`,{file:t,line:m.source?.line,column:m.source?.column,dataPath:`visualization ${e}.labels`,expected:\"String[]\",actual:Array.isArray(f)?\"invalid list value\":typeof f});B([p])}if(f.length!==o.length){let p=q(\"AMX4003\",`Chart '${e}' has ${o.length} values but ${f.length} labels`,{file:t,line:m.source?.line,column:m.source?.column,dataPath:`visualization ${e}.labels`,expected:`${o.length} labels`,actual:`${f.length} labels`});B([p])}a=H(f)}let d=Fn(o,i,e,t);u=d.data,s=d.headings,l=d.measurementDescriptors}else u=H(o);let c={name:e,data:u,documentNodeIndex:n.currentDocumentNodeIndex,statementIndex:n.currentStatementIndex,source:r};return i.type===\"tableDeclaration\"?Object.freeze({kind:\"table\",...c,declaration:i}):Object.freeze({kind:\"chart\",...c,declaration:i,...a?{labels:a}:{},...s?{headings:s}:{},...l?.length?{measurementDescriptors:l}:{}})}function Fn(e,n,t,r){let i=n.kind===\"scatter\",o=i?n.options.filter((c)=>c.type===\"chartFieldOption\"&&(c.role===\"x\"||c.role===\"y\")).map((c)=>({role:c.role,field:c.field,label:c.role,source:c.source})):n.options.filter((c)=>c.type===\"chartSeriesOption\").map((c)=>({role:\"series\",field:c.field,label:c.label,source:c.source})),a=o.map((c)=>{let m=c.field,d=e.map((b)=>b!==null&&typeof b===\"object\"&&!Array.isArray(b)&&!g(b)?b[m??\"\"]:m===void 0?b:void 0),f=d.find((b)=>b!==null&&b!==void 0),p=g(f)?f:void 0;for(let b of d){if(b===null||b===void 0)continue;if(p){if(!g(b)||!Ge(b,p))w(\"AMX3007\",`Chart '${t}' contains incompatible measurement dimensions`,c.source,r,n.source)}else if(g(b))w(\"AMX3007\",`Chart '${t}' mixes measurements with non-measurement values`,c.source,r,n.source)}return p}),s=i?[\"x\",\"y\"].map((c,m)=>a[m]?`${c} (${a[m].unit.text})`:c).concat(\"group\"):[\"label\",...o.flatMap((c,m)=>c.role===\"series\"?[a[m]?`${c.label} (${a[m].unit.text})`:c.label]:[])],l=o.flatMap((c,m)=>{let d=a[m]?.unit;if(!d)return[];return[Object.freeze({role:c.role,...c.field===void 0?{}:{field:c.field},label:c.label,unit:Object.freeze({text:d.text,scale:d.scale,vector:Object.freeze({...d.vector}),factors:Object.freeze(d.factors.map((f)=>Object.freeze({...f})))})})]}),u=e.map((c)=>{if(c!==null&&typeof c===\"object\"&&!Array.isArray(c)&&!g(c)){let m={};for(let[d,f]of Object.entries(c)){let p=o.findIndex((b)=>b.field===d);m[d]=p<0?H(f):Be(f,a[p],t,o[p]?.source,n,r)}return Object.freeze(m)}return Be(c,a[0],t,o[0]?.source,n,r)});return{data:Object.freeze(u),headings:Object.freeze(s),measurementDescriptors:Object.freeze(l)}}function Be(e,n,t,r,i,o){if(e===null||e===void 0)return null;if(!n)return H(e);if(!g(e)||!Ge(e,n))w(\"AMX3007\",`Chart '${t}' contains an incompatible measurement value`,r,o,i.source);let a=e.value*e.unit.scale/n.unit.scale;if(!Number.isFinite(a))w(\"AMX3007\",`Chart '${t}' measurement cannot be normalized to its first display unit`,r,o,i.source);return a}function Ge(e,n){let t=Object.entries(e.unit.vector);return t.length===Object.keys(n.unit.vector).length&&t.every(([r,i])=>n.unit.vector[r]===i)}function Ye(e,n,t){switch(e.type){case\"importDeclaration\":case\"exportNamesDeclaration\":return;case\"dimensionDeclaration\":case\"unitDeclaration\":return;case\"inputDeclaration\":return;case\"tableDeclaration\":case\"chartDeclaration\":n.viewDefinitions.set(e.name,e);return;case\"diagramDeclaration\":n.diagramEmissions.push({model:Je(e,n,t,n.currentDocumentNodeIndex,n.currentStatementIndex)});return;case\"showStatement\":n.viewEmissions.push($n(e.name,n,t,e.source));return;case\"typeDeclaration\":n.recordTypes.set(e.name,e);return;case\"enumDeclaration\":{let r=e.resolvedValues??e.members.map((o,a)=>{if(!o.value)return a+1;if(o.value.type===\"numberLiteral\"||o.value.type===\"stringLiteral\")return o.value.value;return w(\"AMX3020\",\"Only constant values can be assigned to enum members\",o.valueSource??o.value.source,t)}),i={};e.members.forEach((o,a)=>{i[o.name]=r[a]}),n.enumDeclarations.set(e.name,e),n.enumValues.set(e.name,i);return}case\"functionDeclaration\":n.functions.set(e.name,e);return;case\"variableDeclaration\":{Dn(e.name,n);let r=y(e.expression,n,t),i=n.bindingTypes.get(e.name);if(i)V(r,i,n,e.source,t,e.name);n.set(e.name,r)}return;case\"assignmentStatement\":{let r=y(e.expression,n,t),i=n.bindingTypes.get(e.name);if(i)V(r,i,n,e.source,t,e.name);n.update(e.name,r,e.source,t);return}case\"compoundAssignmentStatement\":{let r=y({type:\"binaryExpression\",operator:\"+\",left:{type:\"identifier\",name:e.name,source:e.source},right:e.expression,source:e.source},n,t),i=n.bindingTypes.get(e.name);if(i)V(r,i,n,e.source,t,e.name);n.update(e.name,r,e.source,t);return}case\"addStatement\":zn(e,n,t);return;case\"removeStatement\":jn(e,n,t);return;case\"forStatement\":Vn(e,n,t);return;case\"bracedIfStatement\":Rn(e,n,t);return;case\"returnStatement\":if(We.has(n))throw new ye(y(e.expression,n,t));if(He.has(n))throw new be(y(e.expression,n,t));if(we.has(n))throw new he(y(e.expression,n,t));Fe(e.source,t)}}function Rn(e,n,t){let r=T(y(e.test,n,t))?e.consequent:e.alternate;if(r)xe(r,n,t)}function Ze(e,n,t,r){let i=n.get(e,t,r);if(!Array.isArray(i))S(`Mutation target '${e}' is not a list`,t,r);if(n.isImmutable(i))S(`Cannot mutate immutable imported list '${e}'`,t,r);return i}function Ln(e,n){let t=n.bindingTypes.get(e);return t?.kind===\"list\"?t.element:void 0}function pe(e,n,t,r){if(typeof e!==\"number\"||!Number.isFinite(e)||!Number.isInteger(e)||e<1)S(`${n} must be a positive integer; got ${ge(e)}`,t,r);return e}function zn(e,n,t){let r=Ze(e.name,n,e.source,t),i=y(e.value,n,t),o=Ln(e.name,n);if(o)V(i,o,n,e.value.source??e.source,t,`${e.name} element`);let a=e.index?pe(y(e.index,n,t),\"Insertion position\",e.index.source??e.source,t):r.length+1;if(a>r.length+1)S(`Insertion position ${a} is out of bounds for length ${r.length}; expected 1..${r.length+1}`,e.index?.source??e.source,t);r.splice(a-1,0,i)}function jn(e,n,t){let r=Ze(e.name,n,e.source,t),i=pe(y(e.count,n,t),\"Removal count\",e.count.source??e.source,t);if(r.length===0)S(\"Cannot remove from an empty list\",e.source,t);if(!e.index){r.pop();return}let o=pe(y(e.index,n,t),\"Removal position\",e.index.source??e.source,t);if(o>r.length)S(`Removal position ${o} is out of bounds for length ${r.length}; expected 1..${r.length}`,e.index.source??e.source,t);if(i>r.length-o+1)S(`Removal interval ${o}..${o+i-1} exceeds list length ${r.length}`,e.count.source??e.source,t);r.splice(o-1,i)}function Xn(e,n,t){let r=y(e.start,n,t),i=y(e.end,n,t);if(typeof r!==\"number\"||!Number.isFinite(r)||!Number.isInteger(r)||typeof i!==\"number\"||!Number.isFinite(i)||!Number.isInteger(i))ue(e.source,t);let o=[],a=r<=i?1:-1;for(let s=r;a>0?s<=i:s>=i;s+=a)if(o.push(s),s+a===s&&s!==i)ue(e.source,t);return o}function Vn(e,n,t){let r=ie(e.iterable,n,t);G(e.variable,r,n,()=>{if(we.has(n))xe(e.body,n,t);else ve(e.body,n,t)})}function On(e,n,t){let r=ie(e.iterable,n,t),i=[];return Me(He,n,()=>G(e.variable,r,n,()=>{for(let o of e.body)if(o.type===\"returnStatement\")i.push(y(o.expression,n,t));else try{Ye(o,n,t)}catch(a){if(a instanceof be)i.push(a.value);else throw a}})),i}function ie(e,n,t){let r=y(e,n,t);if(!Array.isArray(r))$e(e.source,t);return r.slice()}function G(e,n,t,r){let i=t.has(e),o=i?t.get(e):void 0;try{for(let a of n)t.set(e,a),r()}finally{if(i)t.set(e,o);else t.delete(e)}}var Ae=new WeakMap,De=new WeakMap;function Ke(e){return e.some((n)=>n.type!==\"diagramElement\")}function Cn(e){if(Ke(e.declaration.content))throw Error(\"Version 1 control-bearing diagram models are missing expanded instances.\")}function F(e){if(!Array.isArray(e)||typeof e[0]!==\"string\")throw Error(\"Invalid serialized diagram value.\");switch(e[0]){case\"undefined\":if(e.length!==1)throw Error(\"Invalid serialized undefined diagram value.\");return;case\"null\":if(e.length!==1)throw Error(\"Invalid serialized null diagram value.\");return null;case\"boolean\":if(e.length!==2||typeof e[1]!==\"boolean\")throw Error(\"Invalid serialized boolean diagram value.\");return e[1];case\"number\":if(e.length!==2)throw Error(\"Invalid serialized number diagram value.\");if(e[1]===\"nan\")return NaN;if(e[1]===\"positive-infinity\")return 1/0;if(e[1]===\"negative-infinity\")return-1/0;if(typeof e[1]!==\"number\")throw Error(\"Invalid serialized number diagram value.\");return e[1];case\"string\":if(e.length!==2||typeof e[1]!==\"string\")throw Error(\"Invalid serialized string diagram value.\");return e[1];case\"array\":if(e.length!==2||!Array.isArray(e[1]))throw Error(\"Invalid serialized array diagram value.\");return e[1].map(F);case\"object\":{if(e.length!==2||!Array.isArray(e[1]))throw Error(\"Invalid serialized object diagram value.\");let n=e[1].map((t)=>{if(!Array.isArray(t)||t.length!==2||typeof t[0]!==\"string\")throw Error(\"Invalid serialized object entry in diagram value.\");return[t[0],F(t[1])]});return Object.fromEntries(n)}case\"map\":if(e.length!==2||!Array.isArray(e[1]))throw Error(\"Invalid serialized map diagram value.\");return new Map(e[1].map((n)=>{if(!Array.isArray(n)||n.length!==2)throw Error(\"Invalid serialized map entry in diagram value.\");return[F(n[0]),F(n[1])]}));case\"set\":if(e.length!==2||!Array.isArray(e[1]))throw Error(\"Invalid serialized set diagram value.\");return new Set(e[1].map(F));default:throw Error(\"Unknown serialized diagram value type.\")}}function Y(e,n){if(!(e instanceof Map))throw Error(`Invalid serialized diagram context map '${n}'.`);for(let t of e.keys())if(typeof t!==\"string\")throw Error(`Invalid key in serialized diagram context map '${n}'.`);return e}function Ee(e,n=new Set){if(e===void 0||e===null||typeof e===\"boolean\"||typeof e===\"number\"||typeof e===\"string\")return;if(!e||typeof e!==\"object\")throw Error(\"Unsupported serialized diagram instance binding value.\");if(n.has(e))throw Error(\"Serialized diagram instance binding contains a cyclic value.\");n.add(e);try{if(Array.isArray(e)){e.forEach((r)=>Ee(r,n));return}let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)throw Error(\"Unsupported serialized diagram instance binding value.\");Object.values(e).forEach((r)=>Ee(r,n))}finally{n.delete(e)}}function Un(e,n){if(!Array.isArray(n))throw Error(\"Invalid serialized diagram instance source path.\");let t=e,r=0,i=!1,o=[];while(r<n.length){let a=n[r++];if(!a||typeof a!==\"object\"||Array.isArray(a)||a.type!==\"content\"||!Number.isSafeInteger(a.index)||a.index<0)throw Error(\"Invalid serialized diagram instance source path.\");let s=t[a.index];if(!s)throw Error(\"Serialized diagram instance source path does not resolve.\");if(s.type===\"diagramElement\"){if(r!==n.length)throw Error(\"Serialized diagram instance source path continues past a primitive.\");return{element:s,bindingNames:o,controlOriginating:i}}if(i=!0,s.type===\"diagramForBlock\"){o.push(s.variable),t=s.content;continue}let l=n[r++];if(!l||typeof l!==\"object\"||Array.isArray(l)||l.type!==\"branch\"||l.branch!==\"consequent\"&&l.branch!==\"alternate\")throw Error(\"Invalid serialized diagram instance branch path.\");if(t=l.branch===\"consequent\"?s.consequent:s.alternate??[],l.branch===\"alternate\"&&!s.alternate)throw Error(\"Serialized diagram instance source path does not resolve.\")}throw Error(\"Serialized diagram instance source path does not resolve to a primitive.\")}function qn(e,n){if(!Array.isArray(n))throw Error(\"Invalid serialized diagram instance list.\");let t=0,r=n.map((i,o)=>{if(!i||typeof i!==\"object\"||Array.isArray(i)||!(\"identity\"in i)||!(\"bindings\"in i)||!Number.isSafeInteger(i.identity)||i.identity!==o||!Array.isArray(i.bindings))throw Error(\"Invalid serialized diagram instance descriptor.\");let a=i,s=a.bindings,l=Un(e,a.sourcePath);if(l.controlOriginating&&++t>nn)throw Error(\"Serialized diagram instance list exceeds the generated element limit.\");if(s.length!==l.bindingNames.length)throw Error(\"Serialized diagram instance has incomplete loop bindings.\");let u=s.map((c,m)=>{if(!c||typeof c!==\"object\"||Array.isArray(c)||!(\"name\"in c)||!(\"value\"in c))throw Error(\"Invalid serialized diagram instance loop binding.\");let d=c;if(d.name!==l.bindingNames[m]||typeof d.name!==\"string\")throw Error(\"Invalid serialized diagram instance loop binding.\");let f=F(d.value);return Ee(f),Object.freeze({name:d.name,value:f})});return Object.freeze({identity:a.identity,element:l.element,bindings:Object.freeze(u)})});return Object.freeze(r)}function Qe(e){let n=JSON.parse(e);if(!n||typeof n!==\"object\"||Array.isArray(n)||!(\"version\"in n)||n.version!==1&&n.version!==2||!(\"model\"in n)||!(\"context\"in n))throw Error(\"Invalid serialized diagram model envelope.\");let t=n,r=t.version;if(r===2){if(!Array.isArray(t.instances))throw Error(\"Invalid serialized diagram instance list.\");if(!Number.isSafeInteger(t.instanceCount)||t.instanceCount!==t.instances.length)throw Error(\"Serialized diagram instance count does not match its payload.\")}let i=F(t.model),o=F(t.context);if(!i||typeof i!==\"object\"||Array.isArray(i)||!o||typeof o!==\"object\"||Array.isArray(o))throw Error(\"Invalid serialized diagram model or evaluation context.\");let a=oe(i);if(!a.declaration||!Array.isArray(a.declaration.content))throw Error(\"Invalid serialized diagram declaration.\");let s=r===1?(Cn(a),tn(a.declaration.content)):qn(a.declaration.content,t.instances),l=o;if(!l.values||typeof l.values!==\"object\"||Array.isArray(l.values)||!Array.isArray(l.immutableValues)||!l.declarationRegistries||!Array.isArray(l.declarationRegistries.records)||!Array.isArray(l.declarationRegistries.functions)||l.validationMode!==\"aggregate\"&&l.validationMode!==\"fail-fast\")throw Error(\"Invalid serialized diagram evaluation context.\");let u=Y(l.recordTypes,\"recordTypes\"),c=Y(l.functions,\"functions\"),m=new j(u,c,l.dimensionRegistry);m.validationMode=l.validationMode;for(let[d,f]of Object.entries(l.values))if(m.set(d,f),l.immutableValues.includes(d))m.markImmutable(f);for(let[d,f]of Y(l.enumDeclarations,\"enumDeclarations\"))m.enumDeclarations.set(d,f);for(let[d,f]of Y(l.enumValues,\"enumValues\"))m.enumValues.set(d,f);for(let[d,f]of Y(l.bindingTypes,\"bindingTypes\"))m.bindingTypes.set(d,f);for(let d of l.declarationRegistries.records){let f=u.get(d.name);if(!f||!Array.isArray(d.fields))throw Error(\"Invalid serialized record declaration registry.\");if(d.declaration)z(f,d.declaration);let p=f.declaredFields??f.fields;if(p.length!==d.fields.length)throw Error(\"Serialized record field registry does not match its declaration.\");d.fields.forEach((b,h)=>{if(b)z(p[h],b)})}for(let d of l.declarationRegistries.functions){let f=c.get(d.name);if(!f)throw Error(\"Invalid serialized function declaration registry.\");if(d.declaration)z(f,d.declaration)}return Ae.set(a,m),De.set(a,s),a}function v(e,n=new Map){if(!e||typeof e!==\"object\")return e;let t=n.get(e);if(t)return t;if(Array.isArray(e)){let i=[];n.set(e,i);for(let o of e)i.push(v(o,n));return i}if(e instanceof Map){let i=new Map;n.set(e,i);for(let[o,a]of e)i.set(v(o,n),v(a,n));return i}if(e instanceof Set){let i=new Set;n.set(e,i);for(let o of e)i.add(v(o,n));return i}let r={};n.set(e,r);for(let[i,o]of Object.entries(e))r[i]=v(o,n);return r}function oe(e,n=new Set){if(!e||typeof e!==\"object\"||n.has(e))return e;if(n.add(e),Array.isArray(e))e.forEach((t)=>oe(t,n));else if(!(e instanceof Map)&&!(e instanceof Set))Object.values(e).forEach((t)=>oe(t,n));return Object.freeze(e)}function en(e){let n=v(e.recordTypes),t=v(e.functions),r=e.dimensionRegistry?v(e.dimensionRegistry):void 0,i=new j(n,t,r);i.validationMode=e.validationMode;for(let[o,a]of e.recordTypes){let s=n.get(o),l=I(a,e.dimensionRegistry);if(l)z(s,v(l));let u=a.declaredFields??a.fields,c=s.declaredFields??s.fields;for(let m=0;m<u.length;m++){let d=I(u[m],e.dimensionRegistry);if(d&&c[m])z(c[m],v(d))}}for(let[o,a]of e.functions){let s=I(a,e.dimensionRegistry);if(s)z(t.get(o),v(s))}for(let[o,a]of e.enumDeclarations)i.enumDeclarations.set(o,v(a));for(let[o,a]of e.enumValues)i.enumValues.set(o,v(a));for(let[o,a]of e.bindingTypes)i.bindingTypes.set(o,v(a));for(let[o,a]of Object.entries(e.toObject())){let s=v(a);if(i.set(o,s),e.isImmutable(a))i.markImmutable(s)}return i}var nn=64;function tn(e){if(Ke(e))throw Error(\"Control-bearing diagram models are missing their expanded per-instance bindings.\");return Object.freeze(e.map((n,t)=>{if(n.type!==\"diagramElement\")throw Error(\"Unexpected diagram control in static content.\");return Object.freeze({identity:t,element:n,bindings:Object.freeze([])})}))}function Bn(e,n,t){let r=[],i=[],o=0,a=(s,l)=>{for(let u of s){if(u.type===\"diagramElement\"){if(l){if(o>=nn)w(\"AMXD6004\",\"Number of elements in this diagram exceed the maximum (64)\",u.source??u.nameSource,t);o++}r.push(Object.freeze({identity:r.length,element:u,bindings:Object.freeze(i.map((m)=>Object.freeze({name:m.name,value:v(m.value)})))}));continue}if(u.type===\"diagramForBlock\"){let m=ie(u.iterable,n,t);G(u.variable,m,n,()=>{i.push({name:u.variable,value:n.get(u.variable)});try{a(u.content,!0)}finally{i.pop()}});continue}let c=T(y(u.test,n,t))?u.consequent:u.alternate;if(c)a(c,!0)}};return a(e,!1),Object.freeze(r)}function rn(e,n,t,r=0){if(r>=e.length)return t();let i,o=e[r];return G(o.name,[o.value],n,()=>{i=rn(e,n,t,r+1)}),i}function O(e,n){let t=e.properties.find((r)=>r.name===n);if(!t)throw Error(`Type checker accepted missing diagram property '${n}'`);return t}function Pn(e,n,t,r,i,o){let a=O(e,n),s=y(a.expression,t,r);if(typeof s!==\"number\"||!Number.isFinite(s)){if(s===1/0&&o===i.to)w(\"AMXD010\",\"Infinity value calculated for time upper bound\",a.valueSource??a.source,r);if(s===1/0&&o>i.from&&o<i.to)w(\"AMXD011\",\"Expression produces an infinite result\",a.valueSource??a.source,r);w(\"AMXD008\",\"Invalid primitive geometry\",a.valueSource??a.source,r)}return s}function on(e,n,t,r,i,o){if(typeof t!==\"number\"||!Number.isFinite(t)||t<n.from||t>n.to)w(\"AMXD004\",\"Invalid time bounds\",e.times[0]?.source??e.source,o);let a=en(i);a.set(n.variable,t);let s=(u)=>{let c=(f)=>Pn(u,f,a,o,n,t),m=(f)=>{let p=O(u,f).expression;if(p.type!==\"stringLiteral\")throw Error(\"Type checker accepted a non-literal diagram style\");return p.value},d=()=>{let f=O(u,\"lineWidth\").expression;if(f.type!==\"numberLiteral\")throw Error(\"Type checker accepted a non-literal line width\");return f.value};try{switch(u.primitive){case\"line\":{let f=u.properties.find((b)=>b.name===\"arrow\")?.expression,p=f?.type===\"stringLiteral\"?f.value:\"none\";return Object.freeze({primitive:\"line\",name:u.name,source:u.source,x1:c(\"x1\"),y1:c(\"y1\"),x2:c(\"x2\"),y2:c(\"y2\"),stroke:m(\"stroke\"),lineWidth:d(),arrow:p})}case\"rectangle\":{let f=c(\"width\"),p=c(\"height\");if(f<=0)w(\"AMXD008\",\"Invalid primitive geometry\",O(u,\"width\").valueSource,o);if(p<=0)w(\"AMXD008\",\"Invalid primitive geometry\",O(u,\"height\").valueSource,o);let b=u.properties.some((h)=>h.name===\"fill\")?m(\"fill\"):void 0;return Object.freeze({primitive:\"rectangle\",name:u.name,source:u.source,x:c(\"x\"),y:c(\"y\"),width:f,height:p,stroke:m(\"stroke\"),...b===void 0?{}:{fill:b},lineWidth:d()})}case\"circle\":{let f=c(\"r\");if(f<=0)w(\"AMXD008\",\"Invalid primitive geometry\",O(u,\"r\").valueSource,o);let p=u.properties.some((b)=>b.name===\"fill\")?m(\"fill\"):void 0;return Object.freeze({primitive:\"circle\",name:u.name,source:u.source,cx:c(\"cx\"),cy:c(\"cy\"),r:f,stroke:m(\"stroke\"),...p===void 0?{}:{fill:p},lineWidth:d()})}case\"text\":{let f=O(u,\"value\"),p=y(f.expression,a,o);if(typeof p!==\"string\")w(\"AMX3002\",\"Expected String, got non-String value\",f.valueSource,o);return Object.freeze({primitive:\"text\",name:u.name,source:u.source,x:c(\"x\"),y:c(\"y\"),value:p,fill:m(\"fill\")})}default:throw Error(`Type checker accepted unsupported diagram primitive '${u.primitive}'`)}}catch(f){if(f instanceof M&&t!==n.from&&f.code!==\"AMXD008\"&&f.code!==\"AMXD010\"&&f.code!==\"AMXD011\")throw new M({code:\"AMXD009\",message:`Frame evaluation leads to invalid results. The underlying error is: ${f.message}`,file:f.file??o,line:f.line??u.source?.line,column:f.column??u.source?.column});throw f}},l=r.map((u)=>rn(u.bindings,a,()=>s(u.element)));return Object.freeze({time:t,elements:Object.freeze(l)})}function Z(e,n,t,r,i,o){let a=y(e,n,t);if(typeof a!==\"number\"||!Number.isFinite(a)||(r===\"AMXD003\"||r===\"AMXD014\"||r===\"AMXD005\")&&a<=0)w(r,i,o,t);return a}function Je(e,n,t,r,i){let o=oe(v(e)),a=en(n),s=(Te)=>{let Ie=o.properties.find((un)=>un.name===Te);if(!Ie)throw Error(`Type checker accepted missing diagram property '${Te}'`);return Ie},l=s(\"width\"),u=s(\"height\"),c=Z(l.expression,a,t,\"AMXD003\",\"Canvas width is invalid\",l.valueSource),m=Z(u.expression,a,t,\"AMXD014\",\"Canvas height is invalid\",u.valueSource),d=s(\"title\").expression,f=s(\"description\").expression;if(d.type!==\"stringLiteral\"||f.type!==\"stringLiteral\")throw Error(\"Type checker accepted a non-literal diagram title or description\");let p=o.times[0],b=Z(p.from,a,t,\"AMXD004\",\"Invalid time bounds\",p.fromSource??p.source),h=Z(p.to,a,t,\"AMXD004\",\"Invalid time bounds\",p.toSource??p.source);if(b>=h)w(\"AMXD004\",\"Invalid time bounds\",p.source??o.source,t);let D=Z(p.duration,a,t,\"AMXD005\",\"Invalid playback duration value\",p.durationSource??p.source),L=Object.freeze({variable:p.name,from:b,to:h,duration:D}),ke=Bn(o.content,a,t),cn=on(o,L,b,ke,a,t),se=Object.freeze({name:o.name,title:d.value,description:f.value,canvas:Object.freeze({width:c,height:m,coordinates:\"bottom-left-y-up\"}),timeline:L,declaration:o,initialFrame:cn,source:o.source,file:t,documentNodeIndex:r,statementIndex:i});return Ae.set(se,a),De.set(se,ke),se}function an(e,n,t=e.file){let r=Ae.get(e);if(!r)throw Error(\"Diagram model has no captured AMX evaluation context\");let i=De.get(e)??tn(e.declaration.content);return on(e.declaration,e.timeline,n,i,r,t)}var Wn=\"http://www.w3.org/2000/svg\",Se=new Set;function R(e,n={}){let t=document.createElementNS(Wn,e);for(let[r,i]of Object.entries(n))t.setAttribute(r,String(i));return t}function Hn(e,n,t){e.setAttribute(\"x\",String(n)),e.setAttribute(\"y\",String(t)),e.setAttribute(\"transform\",`translate(0 ${2*t}) scale(1 -1)`)}function _n(e,n){let{model:t,canvas:r}=e,i=R(\"defs\"),o=R(\"marker\",{id:`${r.dataset.diagramId}-arrowhead`,markerWidth:6,markerHeight:6,refX:10,refY:5,orient:\"auto-start-reverse\",markerUnits:\"strokeWidth\",viewBox:\"0 0 10 10\"});o.append(R(\"path\",{d:\"M 0 0 L 10 5 L 0 10 z\",fill:\"context-stroke\"})),i.append(o);let a=R(\"g\",{transform:`translate(0 ${t.canvas.height}) scale(1 -1)`});for(let s of n.elements)if(s.primitive===\"line\"){let l=R(\"line\",{x1:s.x1,y1:s.y1,x2:s.x2,y2:s.y2,stroke:s.stroke,\"stroke-width\":s.lineWidth,\"stroke-linecap\":\"round\"});if(l.setAttribute(\"data-diagram-element\",s.name),s.arrow===\"start\"||s.arrow===\"both\")l.setAttribute(\"marker-start\",`url(#${r.dataset.diagramId}-arrowhead)`);if(s.arrow===\"end\"||s.arrow===\"both\")l.setAttribute(\"marker-end\",`url(#${r.dataset.diagramId}-arrowhead)`);a.append(l)}else if(s.primitive===\"rectangle\"){let l=R(\"rect\",{x:s.x,y:s.y,width:s.width,height:s.height,stroke:s.stroke,fill:s.fill??\"none\",\"stroke-width\":s.lineWidth});l.setAttribute(\"data-diagram-element\",s.name),a.append(l)}else if(s.primitive===\"circle\"){let l=R(\"circle\",{cx:s.cx,cy:s.cy,r:s.r,stroke:s.stroke,fill:s.fill??\"none\",\"stroke-width\":s.lineWidth});l.setAttribute(\"data-diagram-element\",s.name),a.append(l)}else{let l=R(\"text\",{fill:s.fill,\"font-family\":\"sans-serif\",\"font-size\":12});Hn(l,s.x,s.y),l.setAttribute(\"data-diagram-element\",s.name),l.textContent=s.value,a.append(l)}r.replaceChildren(i,a),r.removeAttribute(\"aria-hidden\")}function Ne(e){window.dispatchEvent(new CustomEvent(\"openamx-diagram-frame\",{detail:e}))}async function Gn(e){if(e.dataset.encoding!==\"gzip-base64\")throw Error(\"Unsupported diagram data encoding.\");let n=atob(e.textContent??\"\"),t=new Uint8Array(n.length);for(let i=0;i<n.length;i++)t[i]=n.charCodeAt(i);let r=new Blob([t]).stream().pipeThrough(new DecompressionStream(\"gzip\"));return Qe(await new Response(r).text())}function ae(e){let n=e.model.title,t=e.time.toFixed(3).toString();e.playButton.textContent=e.running?\"Pause\":\"Play\",e.playButton.setAttribute(\"aria-label\",`${e.running?\"Pause\":\"Play\"} ${n}`),e.scrubber.value=String(e.time),e.scrubber.setAttribute(\"aria-valuetext\",t),e.timeOutput.value=t,e.timeOutput.textContent=t}function C(e){if(e.running=!1,e.animationFrame!==void 0)cancelAnimationFrame(e.animationFrame);e.animationFrame=void 0,ae(e)}function U(e,n){e.time=n,ae(e);try{let t=an(e.model,n);if(_n(e,t),e.alert.hidden=!0,e.alert.textContent=\"\",e.failed)e.failed=!1,Ne({version:1,type:\"diagram-recovered\",diagramId:e.canvas.dataset.diagramId});return!0}catch(t){C(e),e.canvas.replaceChildren(),e.canvas.setAttribute(\"aria-hidden\",\"true\"),e.failed=!0;let r=t instanceof M?{code:t.code,message:t.message,file:t.file??e.model.file,line:t.line??e.model.source?.line,column:t.column??e.model.source?.column}:{code:\"DIAGRAM_RUNTIME\",message:\"The diagram frame could not be evaluated.\",file:e.model.file,line:e.model.source?.line,column:e.model.source?.column},i=r.file?`${r.file}${r.line?`:${r.line}${r.column?`:${r.column}`:\"\"}`:\"\"}`:r.line?`${r.line}${r.column?`:${r.column}`:\"\"}`:\"\";return e.alert.textContent=`${r.code}: ${r.message}${i?` (${i})`:\"\"}`,e.alert.hidden=!1,Ne({version:1,type:\"diagram-error\",diagramId:e.canvas.dataset.diagramId,...r}),!1}}function Yn(e){if(e.running||e.failed)return;if(e.time>=e.model.timeline.to){if(!e.canvas.closest(\"[data-openamx-diagram]\")?.querySelector(\"[data-diagram-loop]\")?.checked)return;U(e,e.model.timeline.from)}e.running=!0,e.startedAt=performance.now()-(e.time-e.model.timeline.from)/(e.model.timeline.to-e.model.timeline.from)*e.model.timeline.duration*1000,ae(e),e.animationFrame=requestAnimationFrame((n)=>sn(e,n))}function sn(e,n){if(!e.running||!document.contains(e.canvas)){C(e);return}let t=e.model.timeline.duration,r=(n-e.startedAt)/1000/t;if(r>=1){if(!(e.canvas.closest(\"[data-openamx-diagram]\")?.querySelector(\"[data-diagram-loop]\")?.checked??!1)){U(e,e.model.timeline.to),C(e);return}if(!U(e,e.model.timeline.from))return;e.startedAt=n}else{let i=e.model.timeline.from,o=e.model.timeline.to,a=r<=0?i:i*(1-r)+o*r;if(!U(e,a))return}e.animationFrame=requestAnimationFrame((i)=>sn(e,i))}async function Zn(e){let n=e.querySelector(\"[data-diagram-model]\"),t=e.querySelector(\"[data-diagram-canvas]\"),r=e.querySelector(\"[data-diagram-play]\"),i=e.querySelector(\"[data-diagram-reset]\"),o=e.querySelector(\"[data-diagram-scrubber]\"),a=e.querySelector(\"[data-diagram-loop]\"),s=e.querySelector(\"[data-diagram-time]\"),l=e.querySelector(\"[data-diagram-error]\");if(!n||!t||!r||!i||!o||!a||!s||!l)throw Error(\"Diagram HTML is missing required runtime elements.\");let u=await Gn(n);t.dataset.diagramId=e.dataset.diagramId;let c={model:u,canvas:t,playButton:r,scrubber:o,timeOutput:s,alert:l,running:!1,failed:!1,time:u.timeline.from,startedAt:0};Se.add(c),ae(c),r.addEventListener(\"click\",()=>{if(c.running)C(c);else Yn(c)}),i.addEventListener(\"click\",()=>{C(c),U(c,u.timeline.from)}),o.addEventListener(\"input\",()=>{let m=Number(o.value);C(c),U(c,m)}),U(c,u.timeline.from)}async function Jn(){for(let e of Array.from(document.querySelectorAll(\"[data-openamx-diagram]\")))try{await Zn(e)}catch(n){let t=e.querySelector(\"[data-diagram-error]\");if(!t)throw n;t.textContent=`DIAGRAM_RUNTIME: ${n instanceof Error?n.message:\"The diagram could not be initialized.\"}`,t.hidden=!1,Ne({version:1,type:\"diagram-error\",diagramId:e.dataset.diagramId??\"\",code:\"DIAGRAM_RUNTIME\",message:t.textContent})}}document.addEventListener(\"DOMContentLoaded\",()=>{Jn()},{once:!0});window.addEventListener(\"pagehide\",()=>{for(let e of Se)C(e);Se.clear()},{once:!0});})();\n";
|
|
1
|
+
const diagramBrowserRuntime = "(()=>{class x extends Error{code;file;line;column;declarationSource;fieldSource;diagnostics;constructor(e,n){super(e.message);this.name=\"AmxError\",this.code=e.code,this.file=e.file,this.line=e.line,this.column=e.column,this.declarationSource=e.declarationSource,this.fieldSource=e.fieldSource,this.diagnostics=n}}function P(e,n,t={}){return{code:e,message:n,...t}}function W(e){let n=e[0]??P(\"AMX4001\",\"Input validation failed\");throw new x(n,e)}function w(e,n,t,r,i){throw new x({code:e,message:n,file:r,line:t?.line,column:t?.column,declarationSource:i})}function D(e,n,t){throw new x({code:\"AMX1009\",message:e,file:t,line:n?.line,column:n?.column})}function fn(e,n,t){return{code:\"AMX1004\",message:`Undefined identifier '${e}'`,file:t,line:n?.line,column:n?.column}}function de(e,n,t){let r=fn(e,n,t);throw new x(r)}function fe(e,n){throw new x({code:\"AMX1005\",message:\"Range bounds must be finite integers\",file:n,line:e?.line,column:e?.column})}function Le(e,n){throw new x({code:\"AMX1006\",message:\"For loops require a list or range value\",file:n,line:e?.line,column:e?.column})}function Xe(e,n){throw new x({code:\"AMX1007\",message:\"Return is only valid inside an expression-form for loop\",file:n,line:e?.line,column:e?.column})}function ze(e,n){throw new x({code:\"AMXF4002\",message:\"Function finished without returning a valid expression\",file:n,line:e?.line,column:e?.column})}function k(e,n,t){throw new x({code:\"AMX1008\",message:e,file:t,line:n?.line,column:n?.column})}var Ve=new WeakMap;function V(e,n){Ve.set(e,n)}function R(e,n){return Ve.get(e)??n}class j{store=new Map;recordTypes;enumDeclarations=new Map;enumValues=new Map;functions;bindingTypes=new Map;dimensionRegistry;viewDefinitions=new Map;viewEmissions=[];diagramEmissions=[];immutableValues=new WeakSet;currentDocumentNodeIndex=-1;currentStatementIndex=-1;validationMode=\"aggregate\";constructor(e=new Map,n=new Map,t){this.recordTypes=e,this.functions=n,this.dimensionRegistry=t}createCallFrame(e){let n=new j(this.recordTypes,this.functions,this.dimensionRegistry);n.validationMode=this.validationMode;for(let[t,r]of this.bindingTypes)n.bindingTypes.set(t,r);for(let[t,r]of this.enumDeclarations)n.enumDeclarations.set(t,r);for(let[t,r]of this.enumValues)n.enumValues.set(t,r);for(let[t,r]of Object.entries(e))if(n.set(t,r),this.isImmutable(r))n.markImmutable(r);return n}set(e,n){this.store.set(e,n)}markImmutable(e){let n=(t)=>{if(!t||typeof t!==\"object\"||this.immutableValues.has(t))return;if(this.immutableValues.add(t),Array.isArray(t))t.forEach(n);else Object.values(t).forEach(n)};n(e)}isImmutable(e){return!!e&&typeof e===\"object\"&&this.immutableValues.has(e)}update(e,n,t,r){if(!this.store.has(e))de(e,t,r);this.store.set(e,n)}delete(e){this.store.delete(e)}get(e,n,t){if(!this.store.has(e))de(e,n,t);return this.store.get(e)}has(e){return this.store.has(e)}toObject(){let e={};for(let[n,t]of this.store.entries())e[n]=t;return e}clear(){this.store.clear(),this.immutableValues=new WeakSet,this.viewDefinitions.clear(),this.viewEmissions.length=0,this.diagramEmissions.length=0}}function b(e){return!!e&&typeof e===\"object\"&&e.__amxMeasurement===!0&&typeof e.value===\"number\"&&!!e.unit}function je(e){return Object.freeze(Object.fromEntries(e))}function pe(e){let n=[...e].filter((i)=>i.exponent!==0).sort((i,o)=>i.identity<o.identity?-1:i.identity>o.identity?1:0),t=n.filter((i)=>i.exponent>0).map((i)=>`${i.name}${i.exponent===1?\"\":` ^ ${i.exponent}`}`),r=n.filter((i)=>i.exponent<0).map((i)=>`${i.name}${i.exponent===-1?\"\":` ^ ${-i.exponent}`}`);return`${t.length?t.join(\" * \"):\"1\"}${r.length?` / ${r.join(\" * \")}`:\"\"}`}function te(e){let n=[{identity:e.identity,name:e.name,exponent:1}];return Object.freeze({scale:e.scale,offset:e.offset,vector:je(e.vector),factors:Object.freeze(n),text:e.name})}function pn(e,n){return e*n.scale+n.offset}function gn(e,n){return(e-n.offset)/n.scale}function M(e){return pn(e.value,e.unit)}function Z(e,n){return gn(e,n)}function N(e){return e.offset!==0}function yn(e,n,t){let r=new Map;for(let i of e.factors)r.set(i.identity,{...i});for(let i of n.factors){let o=r.get(i.identity);r.set(i.identity,{identity:i.identity,name:i.name,exponent:(o?.exponent??0)+i.exponent*t})}return[...r.values()].filter((i)=>i.exponent!==0)}function bn(e,n,t){let r={...e.vector};for(let[i,o]of Object.entries(n.vector)){let a=(r[i]??0)+o*t;if(a)r[i]=a;else delete r[i]}return r}function Oe(e,n,t=!1){if(N(e)||N(n))throw Error(\"Affine measurement units cannot be composed\");let r=t?-1:1,i=yn(e,n,r);return Object.freeze({scale:t?e.scale/n.scale:e.scale*n.scale,offset:0,vector:Object.freeze(bn(e,n,r)),factors:Object.freeze(i),text:pe(i)})}function ge(e,n){if(N(e))throw Error(\"Affine measurement units may not be powered\");let t=e.factors.map((r)=>({...r,exponent:r.exponent*n})).filter((r)=>r.exponent!==0);return Object.freeze({scale:Math.pow(e.scale,n),offset:e.offset,vector:Object.freeze(Object.fromEntries(Object.entries(e.vector).map(([r,i])=>[r,i*n]).filter(([,r])=>r!==0))),factors:Object.freeze(t),text:pe(t)})}function S(e,n){return Object.freeze({__amxMeasurement:!0,value:e,unit:n})}function ne(e,n){let t=[];for(let[r,i]of[...e].sort(([o],[a])=>o<a?-1:o>a?1:0)){let o=n.baseUnits.get(r);if(!o)throw Error(`No visible canonical base unit for dimension identity ${r}`);t.push({identity:o.identity,name:o.name,exponent:i})}return Object.freeze({scale:1,offset:0,vector:je(e),factors:Object.freeze(t),text:pe(t)})}function Ce(e,n){if(N(e.unit))throw Error(\"Affine measurement sqrt is not supported\");let t=new Map;for(let[l,u]of Object.entries(e.unit.vector)){if(u%2!==0)throw Error(\"sqrt requires integral measurement dimension exponents\");t.set(l,u/2)}let r=M(e),i=Math.sqrt(r);if(!Number.isFinite(i))return S(i,ne(t,n));let o=Math.sqrt(e.unit.scale),a=[...n.units.values()].find((l)=>l.scale===o&&l.vector.size===t.size&&[...t].every(([u,c])=>l.vector.get(u)===c));if(a)return S(i/a.scale,te(a));let s=ne(t,n);return S(i,s)}function re(e,n,t,r){if(!Array.isArray(e)){let i=t?` at line ${t.line}`:\"\";throw new x({code:\"AMX2001\",message:`${n} expects a list${i}`,file:r,line:t?.line,column:t?.column})}return e}function T(e,n,t,r){if(typeof e===\"number\")return e;if(typeof e===\"boolean\")return e?1:0;if(typeof e===\"string\"){let o=Number(e);if(!Number.isNaN(o))return o}let i=t?` at line ${t.line}`:\"\";throw new x({code:\"AMX2002\",message:`${n} requires a numeric value${i}`,file:r,line:t?.line,column:t?.column})}function O(e,n,t,r,i){if(e.length!==n){let o=r?` at line ${r.line}`:\"\";throw new x({code:\"AMX2003\",message:`${t} expects ${n} argument(s), got ${e.length}${o}`,file:i,line:r?.line,column:r?.column})}}function hn(e,n,t,r,i){if(e.length<n){let o=r?` at line ${r.line}`:\"\";throw new x({code:\"AMX2003\",message:`${t} expects at least ${n} argument(s), got ${e.length}${o}`,file:i,line:r?.line,column:r?.column})}}var Pe={sin:{evaluate:Math.sin,accepts:Number.isFinite},cos:{evaluate:Math.cos,accepts:Number.isFinite},tan:{evaluate:Math.tan,accepts:Number.isFinite},asin:{evaluate:Math.asin,accepts:(e)=>Number.isFinite(e)&&e>=-1&&e<=1},acos:{evaluate:Math.acos,accepts:(e)=>Number.isFinite(e)&&e>=-1&&e<=1},atan:{evaluate:Math.atan,accepts:Number.isFinite},sinh:{evaluate:Math.sinh,accepts:Number.isFinite},cosh:{evaluate:Math.cosh,accepts:Number.isFinite},tanh:{evaluate:Math.tanh,accepts:Number.isFinite},asinh:{evaluate:Math.asinh,accepts:Number.isFinite},acosh:{evaluate:Math.acosh,accepts:(e)=>Number.isFinite(e)&&e>=1},atanh:{evaluate:Math.atanh,accepts:(e)=>Number.isFinite(e)&&e>-1&&e<1},ln:{evaluate:Math.log,accepts:(e)=>Number.isFinite(e)&&e>0},log:{evaluate:Math.log10,accepts:(e)=>Number.isFinite(e)&&e>0},exp:{evaluate:Math.exp,accepts:Number.isFinite}};function We(e){return Object.hasOwn(Pe,e)}function Ue(e,n,t,r){return new x({code:e,message:n,file:r,line:t?.line,column:t?.column})}function I(e,n,t,r){return new x({code:e,message:n,file:r,line:t?.line,column:t?.column})}function ye(e){if(e===null)return\"null\";if(b(e))return\"Measurement\";if(Array.isArray(e))return\"list\";if(typeof e===\"number\")return\"Number\";if(typeof e===\"string\")return\"String\";if(typeof e===\"boolean\")return\"Boolean\";return typeof e}function ie(e,n,t,r,i,o){if(n.length<t||n.length>r)throw I(\"AMX3004\",`Invalid arity for '${e}'`,i,o)}function qe(e,n,t,r){if(typeof n!==\"string\")throw I(\"AMX3002\",`${e} requires a String, got ${ye(n)}`,t,r);return n}function Be(e){return e>=9&&e<=13||e===32||e===133||e===160||e===5760||e>=8192&&e<=8202||e===8232||e===8233||e===8239||e===8287||e===12288}function wn(e){let n=Array.from(e),t=0,r=n.length;while(t<r&&Be(n[t].codePointAt(0)))t++;while(r>t&&Be(n[r-1].codePointAt(0)))r--;return n.slice(t,r).join(\"\")}function Mn(e,n,t){if(typeof e!==\"string\")throw I(\"AMXSL004\",\"Incorrect formatting pattern\",n,t);let r=/^([$€£])?(#,##0|0)(?:\\.(0{1,6}))?(%)?$/.exec(e);if(!r)throw I(\"AMXSL004\",\"Incorrect formatting pattern\",n,t);return{currency:r[1]??\"\",grouped:r[2]===\"#,##0\",precision:r[3]?.length??0,percent:r[4]===\"%\"}}function xn(e,n,t){switch(e){case\"en-US\":return{decimal:\".\",group:\",\"};case\"de-DE\":return{decimal:\",\",group:\".\"};case\"fr-FR\":return{decimal:\",\",group:\" \"};default:throw I(\"AMXSL005\",\"Formatting locale is malformed or unsupported\",n,t)}}function En(e,n){let[t,r]=Math.abs(e).toString().toLowerCase().split(\"e\"),i=r===void 0?0:Number(r),[o,a=\"\"]=t.split(\".\"),s=`${o}${a}`.replace(/^0+(?=\\d)/,\"\"),l=BigInt(s||\"0\"),u=n+i-a.length;if(u>=0)return l*10n**BigInt(u);let c=10n**BigInt(-u),m=l/c,d=l%c;return m+(d*2n>=c?1n:0n)}function An(e,n){return e.replace(/\\B(?=(\\d{3})+(?!\\d))/g,n)}function vn(e,n,t){let r=n.percent?e*100:e,i=r<0,o=10n**BigInt(n.precision),a=En(r,n.precision),s=(a/o).toString(),l=n.precision?`${t.decimal}${(a%o).toString().padStart(n.precision,\"0\")}`:\"\",u=n.grouped?An(s,t.group):s;return`${i?\"-\":\"\"}${n.currency}${u}${l}${n.percent?\"%\":\"\"}`}function J(e,n,t,r,i=[]){let o=(s)=>i[s]??t;if(e===\"len\"){ie(e,n,1,1,t,r);let s=n[0];if(typeof s===\"string\")return Array.from(s).length;if(Array.isArray(s))return s.length;throw I(\"AMX3002\",`len requires a String or list, got ${ye(s)}`,o(0),r)}if(e===\"trim\")return ie(e,n,1,1,t,r),wn(qe(e,n[0],o(0),r));if(e===\"left\"||e===\"right\"){ie(e,n,1,2,t,r);let s=Array.from(qe(e,n[0],o(0),r)),l=n.length===1?1:n[1];if(typeof l!==\"number\"||!Number.isFinite(l)||!Number.isInteger(l)||l<0)throw I(\"AMXSL003\",\"Invalid text slice count\",o(1),r);let u=Math.min(l,s.length);return e===\"left\"?s.slice(0,u).join(\"\"):s.slice(s.length-u).join(\"\")}if(e===\"format\"){ie(e,n,2,3,t,r);let s=n[0],l=o(0);if(typeof s!==\"number\"&&!b(s))throw I(\"AMX3002\",`format expects a Number or Measurement, got ${ye(s)}`,l,r);let u=b(s)?s.value:s;if(!Number.isFinite(u))throw I(\"AMXSL006\",\"Input is non-finite\",l,r);let c=Mn(n[1],o(1),r),m=xn(n.length===3?n[2]:\"en-US\",o(2),r);if(c.percent&&!Number.isFinite(u*100))throw I(\"AMXSL006\",\"Input is non-finite\",l,r);let d=vn(u,c,m);return b(s)?`${d} ${s.unit.text}`:d}let a=Pe[e];if(a){if(n.length!==1)throw new x({code:\"AMX3004\",message:`Invalid arity for '${e}'`,file:r,line:t?.line,column:t?.column});let s=n[0];if(typeof s!==\"number\"){let u=s===null?\"null\":Array.isArray(s)?\"list\":typeof s===\"object\"?\"Measurement\":typeof s===\"string\"?\"String\":typeof s===\"boolean\"?\"Boolean\":typeof s;throw new x({code:\"AMX3002\",message:`Expected Number or dimensionless Measurement, got ${u}`,file:r,line:t?.line,column:t?.column})}if(!a.accepts(s))throw Ue(\"AMXSL001\",\"Invalid input for mathematical function\",t,r);let l=a.evaluate(s);if(!Number.isFinite(l))throw Ue(\"AMXSL002\",\"Function evaluation results in infinite result\",t,r);return l}switch(e){case\"sum\":return O(n,1,\"sum\",t,r),re(n[0],\"sum\",t,r).reduce((u,c)=>u+T(c,\"sum element\",t,r),0);case\"min\":{O(n,1,\"min\",t,r);let l=re(n[0],\"min\",t,r);if(l.length===0){let u=t?` at line ${t.line}`:\"\";throw new x({code:\"AMX2004\",message:`min of empty list${u}`,file:r,line:t?.line,column:t?.column})}return l.reduce((u,c)=>Math.min(u,T(c,\"min element\",t,r)),Number.POSITIVE_INFINITY)}case\"max\":{O(n,1,\"max\",t,r);let l=re(n[0],\"max\",t,r);if(l.length===0){let u=t?` at line ${t.line}`:\"\";throw new x({code:\"AMX2004\",message:`max of empty list${u}`,file:r,line:t?.line,column:t?.column})}return l.reduce((u,c)=>Math.max(u,T(c,\"max element\",t,r)),Number.NEGATIVE_INFINITY)}case\"mean\":{O(n,1,\"mean\",t,r);let l=re(n[0],\"mean\",t,r);if(l.length===0){let c=t?` at line ${t.line}`:\"\";throw new x({code:\"AMX2004\",message:`mean of empty list${c}`,file:r,line:t?.line,column:t?.column})}return l.reduce((c,m)=>c+T(m,\"mean element\",t,r),0)/l.length}case\"round\":{hn(n,1,\"round\",t,r);let l=T(n[0],\"round value\",t,r),u=n.length>1?T(n[1],\"round digits\",t,r):0,c=Math.pow(10,Math.trunc(u));return Math.round(l*c)/c}case\"abs\":{O(n,1,\"abs\",t,r);let l=T(n[0],\"abs value\",t,r);return Math.abs(l)}case\"sqrt\":{O(n,1,\"sqrt\",t,r);let l=T(n[0],\"sqrt value\",t,r);if(l<0){let u=t?` at line ${t.line}`:\"\";throw new x({code:\"AMX2005\",message:`sqrt of negative value${u}`,file:r,line:t?.line,column:t?.column})}return Math.sqrt(l)}case\"pow\":{O(n,2,\"pow\",t,r);let l=T(n[0],\"pow base\",t,r),u=T(n[1],\"pow exponent\",t,r);return Math.pow(l,u)}default:let s=t?` at line ${t.line}`:\"\";throw new x({code:\"AMX2000\",message:`Unknown function '${e}'${s}`,file:r,line:t?.line,column:t?.column})}}function C(e,n,t,r,i,o){let a=[],s=(u,c,m,d,f)=>{let p=P(\"AMX4003\",u,{file:i,line:r?.line,column:r?.column,dataPath:d,expected:be(c),actual:we(m),fieldSource:f});if(a.push(p),t.validationMode===\"fail-fast\")W([p])},l=(u,c,m,d)=>{if(c.kind===\"null\"){if(u!==null)s(\"Expected null\",c,u,m,d);return}if(c.kind===\"nullable\"){if(u!==null)l(u,c.element,m,d);return}if(c.kind===\"list\"){if(!Array.isArray(u)){s(\"Expected a list value\",c,u,m,d);return}u.forEach((h,v)=>l(h,c.element,`${m}[${v}]`,d));return}if(c.kind===\"measurement\"){if(!b(u)){s(\"Expected a measurement value\",c,u,m,d);return}let h=u.unit.vector;if(Object.keys(h).length!==c.vector.size||[...c.vector].some(([v,L])=>h[v]!==L))s(\"Measurement dimension does not match the declared dimension\",c,u,m,d);if(!Number.isFinite(u.value)||!Number.isFinite(M(u)))s(\"Measurement value must be finite\",c,u,m,d);return}if(c.kind!==\"named\")return;if(c.name===\"Number\"){if(typeof u!==\"number\"||!Number.isFinite(u))s(\"Expected a finite Number value\",c,u,m,d);return}if(c.name===\"String\"||c.name===\"DateTime\"){if(typeof u!==\"string\")s(`Expected a ${c.name} value`,c,u,m,d);else if(c.name===\"DateTime\"&&!_e(u))s(\"Invalid RFC 3339 DateTime value\",c,u,m,d);return}if(c.name===\"Boolean\"){if(typeof u!==\"boolean\")s(\"Expected a Boolean value\",c,u,m,d);return}let f=t.recordTypes.get(c.name);if(!f||typeof u!==\"object\"||u===null||Array.isArray(u)){s(`Expected a ${c.name} record`,c,u,m,d);return}let p=u,g=new Set(f.fields.map((h)=>h.name));for(let h of f.fields){let v=R(h,t.dimensionRegistry);if(!Object.prototype.hasOwnProperty.call(p,h.name))s(`Missing computed field '${h.name}'`,H(h.annotation,v),\"missing\",`${m}.${h.name}`,h.source);else l(p[h.name],H(h.annotation,v),`${m}.${h.name}`,h.source)}for(let h of Object.keys(p).filter((v)=>!g.has(v)).sort())s(`Unknown computed field '${h}'`,c,p[h],`${m}.${h}`,d)};if(l(e,n,o),a.length)W(a)}function Dn(e,n,t){if(!e.defaultExpression)return null;let r=n.dimensionRegistry;n.dimensionRegistry=R(e,r);try{return y(e.defaultExpression,n,t)}finally{n.dimensionRegistry=r}}function H(e,n){let t=n instanceof j?n.dimensionRegistry:n;if(e.type===\"namedType\"){let i=t?.dimensions.get(e.name);return i?{kind:\"measurement\",vector:i.vector}:{kind:\"named\",name:e.name}}let r=H(e.element,t);return e.type===\"listType\"?{kind:\"list\",element:r}:{kind:\"nullable\",element:r}}function be(e){if(e.kind===\"named\")return e.name;if(e.kind===\"measurement\")return\"measurement\";if(e.kind===\"null\")return\"null\";return e.kind===\"list\"?`${be(e.element)}[]`:`${be(e.element)}?`}function we(e){if(typeof e===\"number\"&&!Number.isFinite(e))return String(e);let n;try{n=JSON.stringify(e)??String(e)}catch{n=String(e)}return n.replace(/[\\x00-\\x1f\\x7f]/g,(t)=>`\\\\u${t.charCodeAt(0).toString(16).padStart(4,\"0\")}`).slice(0,160)}function _(e,n){return Object.keys(e.unit.vector).length===n.size&&[...n].every(([t,r])=>e.unit.vector[t]===r)}function _e(e){let n=e.match(/^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(?:\\.\\d{1,9})?(Z|[+-]\\d{2}:\\d{2})$/);if(!n)return!1;let[,t,r,i,o,a,s,l]=n,u=new Date(0);return u.setUTCFullYear(+t,+r-1,+i),u.getUTCFullYear()===+t&&u.getUTCMonth()===+r-1&&u.getUTCDate()===+i&&+o<=23&&+a<=59&&+s<=59&&(l===\"Z\"||+l.slice(1,3)<=23&&+l.slice(4)<=59)}function oe(e,n,t,r,i=t.dimensionRegistry){if(n.type===\"nullableType\")return e===null||oe(e,n.element,t,r,i);if(n.type===\"listType\")return Array.isArray(e)&&e.every((u)=>oe(u,n.element,t,r,i));let o=n.name,a=i?.dimensions.get(o);if(a)return b(e)&&_(e,a.vector);if(o===\"Number\")return typeof e===\"number\";if(o===\"String\")return typeof e===\"string\";if(o===\"Boolean\")return typeof e===\"boolean\";if(o===\"DateTime\")return typeof e===\"string\"&&_e(e);let s=t.enumDeclarations.get(o);if(s){if(typeof e!==\"number\"&&typeof e!==\"string\")return!1;if(!s.resolvedValues)throw Error(`Enum '${o}' has not been resolved`);return s.resolvedValues.includes(e)}let l=t.recordTypes.get(o);if(l){if(typeof e!==\"object\"||e===null||Array.isArray(e)||b(e))return!1;let u=e;return l.fields.every((c)=>{if(!Object.prototype.hasOwnProperty.call(u,c.name))return c.optional;return oe(u[c.name],c.annotation,t,r,R(c,i))})}return w(\"AMX3001\",`Unknown type '${o}'`,n.source,r)}function y(e,n,t){switch(e.type){case\"nullLiteral\":return null;case\"recordConstructor\":{let r=n.recordTypes.get(e.name);if(!r)throw Error(`Unknown record type '${e.name}'`);let i=new Map(e.fields.map((a)=>[a.name,y(a.expression,n,t)])),o={};for(let a of r.fields)o[a.name]=i.has(a.name)?i.get(a.name):a.defaultExpression?Dn(a,n,t):null;return C(o,{kind:\"named\",name:e.name},n,e.source,t,`record ${e.name}`),o}case\"fieldAccess\":{if(e.receiver.type===\"identifier\"){let r=n.enumValues.get(e.receiver.name);if(r)return r[e.field]}return y(e.receiver,n,t)[e.field]}case\"listAccess\":return Rn(e,n,t);case\"numberLiteral\":return e.value;case\"stringLiteral\":return e.value;case\"stringInterpolation\":return e.parts.map((r)=>{if(typeof r===\"string\")return r;let i=y(r,n,t);if(i===null)return\"null\";if(typeof i===\"string\"||typeof i===\"number\")return String(i);if(typeof i===\"boolean\")return i?\"true\":\"false\";if(b(i))return`${String(i.value)} ${i.unit.text}`;return w(\"AMX3007\",\"Only String, Number, Boolean, measurement, and null values can be interpolated\",r.source,t)}).join(\"\");case\"booleanLiteral\":return e.value;case\"identifier\":if(e.name===\"PI\")return Math.PI;if(e.name===\"E\")return Math.E;return n.get(e.name,e.source,t);case\"measurementAttachment\":{let r=y(e.value,n,t),i=n.dimensionRegistry?.units.get(e.unit);if(!i)return w(\"AMX3008\",`Unknown or invisible unit '${e.unit}'`,e.unitSource??e.source,t);if(typeof r!==\"number\")return w(\"AMX3007\",\"Unit attachment requires a Number expression\",e.source,t);let o=S(r,te(i));if(!Number.isFinite(M(o)))D(\"Measurement physical value must be finite\",e.source,t);return o}case\"measurementConversion\":{let r=y(e.value,n,t),i=n.dimensionRegistry?.units.get(e.unit);if(!i)return w(\"AMX3008\",`Unknown or invisible unit '${e.unit}'`,e.unitSource??e.source,t);if(!b(r)||!_(r,i.vector))return w(\"AMX3007\",`Cannot convert value to unit '${e.unit}'`,e.source,t);let o=te(i),a=Z(M(r),o);if(!Number.isFinite(a))D(\"Converted measurement value must be finite\",e.source,t);return S(a,o)}case\"binaryExpression\":return Nn(e,n,t);case\"typeTestExpression\":return oe(y(e.value,n,t),e.target,n,t);case\"unaryExpression\":return kn(e,n,t);case\"conditionalExpression\":return Tn(e,n,t);case\"bracedIfExpression\":return $n(e,n,t);case\"listLiteral\":return Fn(e,n,t);case\"functionCall\":return Xn(e,n,t);case\"rangeExpression\":return qn(e,n,t);case\"forExpression\":return Pn(e,n,t);case\"matchExpression\":return Sn(e,n,t);default:throw Error(`Unsupported expression node type: ${e}`)}}function Sn(e,n,t){let r=y(e.expression,n,t);for(let i of e.cases)if(r===i.value.value)return y(i.expression,n,t);return y(e.defaultExpression,n,t)}function Nn(e,n,t){let r=y(e.left,n,t),i=y(e.right,n,t),o=e.operatorSource??e.source;switch(e.operator){case\"+\":case\"-\":{if(b(r)||b(i)){if(!b(r)||!b(i)||!_(r,new Map(Object.entries(i.unit.vector))))return w(\"AMX3007\",\"Addition and subtraction require compatible measurements\",o,t);if(e.operator===\"+\"&&(N(r.unit)||N(i.unit)))return w(\"AMX3007\",\"Direct addition of affine measurements is not supported\",o,t);let l=M(r),u=M(i),c=e.operator===\"+\"?l+u:l-u,m=e.operator===\"+\"?Z(c,r.unit):c/r.unit.scale;if(!Number.isFinite(m)||!Number.isFinite(c))D(\"Measurement arithmetic result must be finite\",o,t);return S(m,r.unit)}let a=E(r,e.left),s=E(i,e.right);return e.operator===\"+\"?a+s:a-s}case\"*\":case\"/\":{if(b(r)||b(i)){let l={scale:1,offset:0,vector:{},factors:[],text:\"1\"},u=b(r)?r:void 0,c=b(i)?i:void 0;if(u&&N(u.unit)||c&&N(c.unit))return w(\"AMX3007\",e.operator===\"*\"?\"Affine measurement multiplication is not supported\":\"Affine measurement division is not supported\",o,t);let m=u?u.value:E(r,e.left),d=c?c.value:E(i,e.right),f=u?.unit??l,p=c?.unit??l,g=u?M(u):m,h=c?M(c):d;if(e.operator===\"/\"&&h===0)D(\"Measurement division by zero\",o,t);let v=Oe(f,p,e.operator===\"/\"),L=e.operator===\"/\"?g/h:g*h;if(v.vector&&Object.keys(v.vector).length===0){if(!Number.isFinite(L))D(\"Measurement arithmetic result must be finite\",o,t);return L}let Y=e.operator===\"/\"?m/d:m*d;if(!Number.isFinite(v.scale)||v.scale<=0||!Number.isFinite(Y)||!Number.isFinite(L))D(\"Measurement arithmetic result must be finite\",o,t);return S(Y,v)}let a=E(r,e.left),s=E(i,e.right);return e.operator===\"*\"?a*s:a/s}case\"%\":{let a=E(r,e.left),s=E(i,e.right);return a%s}case\"^\":{if(b(r)){if(N(r.unit))return w(\"AMX3007\",\"Affine measurement powers are not supported\",o,t);let l=E(i,e.right);if(!Number.isSafeInteger(l))return w(\"AMX3007\",\"A dimensional power exponent must be an integer literal\",e.right.source,t);if(r.value===0&&l<0)D(\"Zero measurement cannot be raised to a negative power\",o,t);let u=ge(r.unit,l),c=Math.pow(r.value,l);if(!Number.isFinite(c)||!Number.isFinite(u.scale))D(\"Measurement power result must be finite\",o,t);let m=S(c,u);if(Object.keys(u.vector).length===0)return M(m);return m}let a=E(r,e.left),s=E(i,e.right);return Math.pow(a,s)}case\"==\":if(b(r)&&b(i))return _(r,new Map(Object.entries(i.unit.vector)))&&M(r)===M(i);return r===i;case\"!=\":if(b(r)&&b(i))return!_(r,new Map(Object.entries(i.unit.vector)))||M(r)!==M(i);return r!==i;case\">\":if(b(r)&&b(i))return M(r)>M(i);return E(r,e.left)>E(i,e.right);case\">=\":if(b(r)&&b(i))return M(r)>=M(i);return E(r,e.left)>=E(i,e.right);case\"<\":if(b(r)&&b(i))return M(r)<M(i);return E(r,e.left)<E(i,e.right);case\"<=\":if(b(r)&&b(i))return M(r)<=M(i);return E(r,e.left)<=E(i,e.right);case\"and\":return F(r)&&F(i);case\"or\":return F(r)||F(i);default:throw Error(`Unsupported binary operator: ${e.operator}`)}}function kn(e,n,t){let r=y(e.argument,n,t);if(e.operator===\"-\"){if(b(r))return S(-r.value,r.unit);return-E(r,e.argument)}if(e.operator===\"not\")return!F(r);throw Error(`Unsupported unary operator: ${e.operator}`)}function Tn(e,n,t){let r=y(e.test,n,t);return F(r)?y(e.consequent,n,t):y(e.alternate,n,t)}class Me{value;constructor(e){this.value=e}}class xe{value;constructor(e){this.value=e}}class Ee{value;constructor(e){this.value=e}}var Ge=new WeakMap,Ye=new WeakMap,Ae=new WeakMap,ae=new WeakMap;function ve(e,n,t){e.set(n,(e.get(n)??0)+1);try{return t()}finally{let r=e.get(n)-1;if(r)e.set(n,r);else e.delete(n)}}function In(e,n){let t=ae.get(n),r=t?.[t.length-1];if(!r||r.has(e))return;let i=n.has(e);r.set(e,{existed:i,value:i?n.get(e):void 0})}function De(e,n,t){let r=ae.get(n)??[],i=new Map;r.push(i),ae.set(n,r);try{Se(e,n,t)}finally{r.pop();for(let[o,a]of i)if(a.existed)n.set(o,a.value);else n.delete(o);if(!r.length)ae.delete(n)}}function $n(e,n,t){let r=F(y(e.test,n,t))?e.consequent:e.alternate,i=r===e.consequent?e.consequentSource:e.alternateSource;try{ve(Ge,n,()=>De(r,n,t))}catch(o){if(o instanceof Me)return o.value;throw o}return w(\"AMX3021\",\"Every possible path in an if expression must return a value\",i??e.source,t)}function Fn(e,n,t){return e.elements.map((r)=>y(r,n,t))}function Rn(e,n,t){let r=y(e.receiver,n,t),i=y(e.index,n,t);if(!Array.isArray(r))k(\"List access requires a list value\",e.source,t);if(typeof i!==\"number\"||!Number.isFinite(i)||!Number.isInteger(i)||i<1)k(`List index must be a positive integer; got ${we(i)}`,e.index.source??e.source,t);if(i>r.length)k(`List index ${i} is out of bounds for length ${r.length}; expected 1..${r.length}`,e.index.source??e.source,t);return r[i-1]}function se(e,n){if(e.type===\"binaryExpression\")return se(e.left,n)??e.operatorSource??e.source??n;if(e.type===\"unaryExpression\"){let t=se(e.argument,n);if(t)return{line:t.line,column:Math.max(1,t.column-(e.operator===\"not\"?3:1))}}if(e.type===\"measurementAttachment\"||e.type===\"measurementConversion\")return se(e.value,n)??e.source??n;return e.source??n}function Ze(e){return Array.isArray(e)?e.map(Ze):e}function Ln(e){return e.kind===\"list\"||e.kind===\"nullable\"&&e.element.kind===\"list\"}function Xn(e,n,t){let r=e.arguments.map((a)=>y(a,n,t)),i=n.functions.get(e.callee);if(i){let a=R(i,n.dimensionRegistry),s={};i.parameters.forEach((m,d)=>{let f=H(m.annotation,a);C(r[d],f,n,e.arguments[d]?.source??e.source,t,`function ${e.callee}.${m.name}`);let p=r[d];s[m.name]=Ln(f)&&p!==null?Ze(p):p});let l=n.createCallFrame(s);l.dimensionRegistry=a,i.parameters.forEach((m)=>{l.bindingTypes.set(m.name,H(m.annotation,a))});let u,c=i.body;if(c.kind===\"expression\")u=y(c.expression,l,t);else{let m=!1;try{ve(Ae,l,()=>Se(c.statements,l,t))}catch(d){if(!(d instanceof Ee))throw d;m=!0,u=d.value}if(!m)ze(c.closingSource,t)}return C(u,H(i.returnType,a),n,e.source,t,`function ${e.callee} return`),u}let o=r[0];if([\"sum\",\"mean\",\"min\",\"max\"].includes(e.callee)&&Array.isArray(o)&&(o.length>0&&b(o[0]))){let a=o,s=a[0];for(let m of a){if(!_(s,new Map(Object.entries(m.unit.vector))))return w(\"AMX3007\",`${e.callee} requires compatible measurement dimensions`,e.source,t);if(Array.isArray(o)&&o.length>0&&typeof o[0]===\"number\"&&[\"sum\",\"mean\",\"min\",\"max\"].includes(e.callee))return J(e.callee,r,e.source,t)}if(e.callee===\"min\"||e.callee===\"max\"){if(!a.length)return J(e.callee,r,e.source,t);return a.reduce((m,d)=>(e.callee===\"min\"?M(d)<M(m):M(d)>M(m))?d:m)}let l=a.reduce((m,d)=>m+M(d),0),u=e.callee===\"mean\"?l/a.length:l,c=Z(u,s.unit);if(!Number.isFinite(l)||!Number.isFinite(u)||!Number.isFinite(c))D(`${e.callee} result must be finite`,e.source,t);return S(c,s.unit)}if(e.callee===\"sum\"&&Array.isArray(o)&&o.length===0&&e.arguments[0]?.type===\"identifier\"){let a=n.bindingTypes.get(e.arguments[0].name);if(a?.kind===\"list\"&&a.element.kind===\"measurement\"&&n.dimensionRegistry)return S(0,ne(a.element.vector,n.dimensionRegistry))}if(b(r[0])){let a=r[0];if(We(e.callee)){if(Object.keys(a.unit.vector).length!==0)return w(\"AMX3007\",`'${e.callee}' requires a Number or dimensionless Measurement`,e.arguments[0]?.source??e.source,t);return J(e.callee,[M(a)],e.source,t)}switch(e.callee){case\"abs\":return S(Math.abs(a.value),a.unit);case\"round\":{let s=r.length>1?E(r[1],e.arguments[1]):0,l=Math.pow(10,Math.trunc(s)),u=Math.round(a.value*l)/l;if(!Number.isFinite(u))D(\"round result must be finite\",e.source,t);return S(u,a.unit)}case\"sqrt\":{if(N(a.unit))return w(\"AMX3007\",\"Affine measurement sqrt is not supported\",e.source,t);if(M(a)<0)D(\"sqrt of a negative measurement value\",e.source,t);if(!n.dimensionRegistry)throw Error(\"Measurement registry is unavailable during sqrt evaluation\");try{let l=Ce(a,n.dimensionRegistry);if(!Number.isFinite(l.value)||!Number.isFinite(l.unit.scale))D(\"sqrt result must be finite\",e.source,t);if(Object.keys(l.unit.vector).length===0)return M(l);return l}catch(l){if(l instanceof Error&&l.message.startsWith(\"sqrt requires\"))return w(\"AMX3007\",l.message,e.source,t);throw l}}case\"pow\":{if(N(a.unit))return w(\"AMX3007\",\"Affine measurement powers are not supported\",e.source,t);let s=E(r[1],e.arguments[1]);if(!Number.isSafeInteger(s))return w(\"AMX3007\",\"A dimensional pow exponent must be an integer literal\",e.arguments[1]?.source,t);if(a.value===0&&s<0)D(\"Zero measurement cannot be raised to a negative power\",e.source,t);let l=ge(a.unit,s),u=Math.pow(a.value,s);if(!Number.isFinite(u)||!Number.isFinite(l.scale))D(\"pow result must be finite\",e.source,t);let c=S(u,l);if(!Object.keys(l.vector).length)return M(c);return c}}}return J(e.callee,r,e.source,t,e.arguments.map((a)=>se(a,e.source)))}function E(e,n){if(typeof e===\"number\")return e;if(typeof e===\"boolean\")return e?1:0;if(typeof e===\"string\"){let i=Number(e);if(!Number.isNaN(i))return i}let t=n?.source,r=t?` at line ${t.line}`:\"\";throw Error(`Cannot convert value to number${r}`)}function F(e){if(typeof e===\"boolean\")return e;if(typeof e===\"number\")return e!==0;if(typeof e===\"string\")return e.length>0;if(Array.isArray(e))return e.length>0;if(e&&typeof e===\"object\")return!0;return!1}function Se(e,n,t){let r=n.currentStatementIndex;try{for(let i=0;i<e.length;i++)n.currentStatementIndex=i,Ke(e[i],n,t)}finally{n.currentStatementIndex=r}}function G(e){if(b(e))return`${e.value} ${e.unit.text}`;if(Array.isArray(e))return Object.freeze(e.map(G));if(e&&typeof e===\"object\"){let n={};for(let[t,r]of Object.entries(e))n[t]=G(r);return Object.freeze(n)}return e}function zn(e,n,t,r){let i=n.viewDefinitions.get(e);if(!i)return w(\"AMX3001\",`Unknown visualization '${e}'`,r,t);let o=n.get(i.binding,i.bindingSource,t);if(!Array.isArray(o)){let d=P(\"AMX4003\",`Visualization '${e}' requires a list value`,{file:t,line:i.bindingSource?.line,column:i.bindingSource?.column,dataPath:`visualization ${e}`,expected:\"list\",actual:Array.isArray(o)?\"list\":typeof o});W([d])}let a,s,l,u=!1,c;if(i.type===\"chartDeclaration\"){let d=i.options.find((g)=>g.type===\"chartShowTableOption\");if(d?.type===\"chartShowTableOption\"){let g=y(d.expression,n,t);if(typeof g!==\"boolean\")w(\"AMX3002\",`Expected Boolean, got ${typeof g}`,d.expression.source,t);u=g}let f=i.options.find((g)=>g.type===\"chartFieldOption\"&&g.role===\"labels\");if(f?.type===\"chartFieldOption\"){let g=n.get(f.field,f.fieldSource,t);if(!Array.isArray(g)||!g.every((h)=>typeof h===\"string\")){let h=P(\"AMX4003\",`Chart '${e}' labels must be a String[] value`,{file:t,line:f.source?.line,column:f.source?.column,dataPath:`visualization ${e}.labels`,expected:\"String[]\",actual:Array.isArray(g)?\"invalid list value\":typeof g});W([h])}if(g.length!==o.length){let h=P(\"AMX4003\",`Chart '${e}' has ${o.length} values but ${g.length} labels`,{file:t,line:f.source?.line,column:f.source?.column,dataPath:`visualization ${e}.labels`,expected:`${o.length} labels`,actual:`${g.length} labels`});W([h])}a=G(g)}let p=Vn(o,i,e,t);c=p.data,s=p.headings,l=p.measurementDescriptors}else c=G(o);let m={name:e,data:c,documentNodeIndex:n.currentDocumentNodeIndex,statementIndex:n.currentStatementIndex,source:r};return i.type===\"tableDeclaration\"?Object.freeze({kind:\"table\",...m,declaration:i}):Object.freeze({kind:\"chart\",...m,declaration:i,showTable:u,...a?{labels:a}:{},...s?{headings:s}:{},...l?.length?{measurementDescriptors:l}:{}})}function Vn(e,n,t,r){let i=n.kind===\"scatter\",o=i?n.options.filter((c)=>c.type===\"chartFieldOption\"&&(c.role===\"x\"||c.role===\"y\")).map((c)=>({role:c.role,field:c.field,label:c.role,source:c.source})):n.options.filter((c)=>c.type===\"chartSeriesOption\").map((c)=>({role:\"series\",field:c.field,label:c.label,source:c.source})),a=o.map((c)=>{let m=c.field,d=e.map((g)=>g!==null&&typeof g===\"object\"&&!Array.isArray(g)&&!b(g)?g[m??\"\"]:m===void 0?g:void 0),f=d.find((g)=>g!==null&&g!==void 0),p=b(f)?f:void 0;for(let g of d){if(g===null||g===void 0)continue;if(p){if(!b(g)||!Je(g,p))w(\"AMX3007\",`Chart '${t}' contains incompatible measurement dimensions`,c.source,r,n.source)}else if(b(g))w(\"AMX3007\",`Chart '${t}' mixes measurements with non-measurement values`,c.source,r,n.source)}return p}),s=i?[\"x\",\"y\"].map((c,m)=>a[m]?`${c} (${a[m].unit.text})`:c).concat(\"group\"):[\"label\",...o.flatMap((c,m)=>c.role===\"series\"?[a[m]?`${c.label} (${a[m].unit.text})`:c.label]:[])],l=o.flatMap((c,m)=>{let d=a[m]?.unit;if(!d)return[];return[Object.freeze({role:c.role,...c.field===void 0?{}:{field:c.field},label:c.label,unit:Object.freeze({text:d.text,scale:d.scale,vector:Object.freeze({...d.vector}),factors:Object.freeze(d.factors.map((f)=>Object.freeze({...f})))})})]}),u=e.map((c)=>{if(c!==null&&typeof c===\"object\"&&!Array.isArray(c)&&!b(c)){let m={};for(let[d,f]of Object.entries(c)){let p=o.findIndex((g)=>g.field===d);m[d]=p<0?G(f):He(f,a[p],t,o[p]?.source,n,r)}return Object.freeze(m)}return He(c,a[0],t,o[0]?.source,n,r)});return{data:Object.freeze(u),headings:Object.freeze(s),measurementDescriptors:Object.freeze(l)}}function He(e,n,t,r,i,o){if(e===null||e===void 0)return null;if(!n)return G(e);if(!b(e)||!Je(e,n))w(\"AMX3007\",`Chart '${t}' contains an incompatible measurement value`,r,o,i.source);let a=Z(M(e),n.unit);if(!Number.isFinite(a))w(\"AMX3007\",`Chart '${t}' measurement cannot be normalized to its first display unit`,r,o,i.source);return a}function Je(e,n){let t=Object.entries(e.unit.vector);return t.length===Object.keys(n.unit.vector).length&&t.every(([r,i])=>n.unit.vector[r]===i)}function Ke(e,n,t){switch(e.type){case\"importDeclaration\":case\"exportNamesDeclaration\":return;case\"dimensionDeclaration\":case\"unitDeclaration\":return;case\"inputDeclaration\":return;case\"tableDeclaration\":case\"chartDeclaration\":n.viewDefinitions.set(e.name,e);return;case\"diagramDeclaration\":n.diagramEmissions.push({model:en(e,n,t,n.currentDocumentNodeIndex,n.currentStatementIndex)});return;case\"showStatement\":n.viewEmissions.push(zn(e.name,n,t,e.source));return;case\"typeDeclaration\":n.recordTypes.set(e.name,e);return;case\"enumDeclaration\":{let r=e.resolvedValues??e.members.map((o,a)=>{if(!o.value)return a+1;if(o.value.type===\"numberLiteral\"||o.value.type===\"stringLiteral\")return o.value.value;return w(\"AMX3020\",\"Only constant values can be assigned to enum members\",o.valueSource??o.value.source,t)}),i={};e.members.forEach((o,a)=>{i[o.name]=r[a]}),n.enumDeclarations.set(e.name,e),n.enumValues.set(e.name,i);return}case\"functionDeclaration\":n.functions.set(e.name,e);return;case\"variableDeclaration\":{In(e.name,n);let r=y(e.expression,n,t),i=n.bindingTypes.get(e.name);if(i)C(r,i,n,e.source,t,e.name);n.set(e.name,r)}return;case\"assignmentStatement\":{let r=y(e.expression,n,t),i=n.bindingTypes.get(e.name);if(i)C(r,i,n,e.source,t,e.name);n.update(e.name,r,e.source,t);return}case\"compoundAssignmentStatement\":{let r=y({type:\"binaryExpression\",operator:\"+\",left:{type:\"identifier\",name:e.name,source:e.source},right:e.expression,source:e.source},n,t),i=n.bindingTypes.get(e.name);if(i)C(r,i,n,e.source,t,e.name);n.update(e.name,r,e.source,t);return}case\"addStatement\":Cn(e,n,t);return;case\"removeStatement\":Un(e,n,t);return;case\"forStatement\":Bn(e,n,t);return;case\"bracedIfStatement\":jn(e,n,t);return;case\"returnStatement\":if(Ge.has(n))throw new Me(y(e.expression,n,t));if(Ye.has(n))throw new xe(y(e.expression,n,t));if(Ae.has(n))throw new Ee(y(e.expression,n,t));Xe(e.source,t)}}function jn(e,n,t){let r=F(y(e.test,n,t))?e.consequent:e.alternate;if(r)De(r,n,t)}function Qe(e,n,t,r){let i=n.get(e,t,r);if(!Array.isArray(i))k(`Mutation target '${e}' is not a list`,t,r);if(n.isImmutable(i))k(`Cannot mutate immutable imported list '${e}'`,t,r);return i}function On(e,n){let t=n.bindingTypes.get(e);return t?.kind===\"list\"?t.element:void 0}function he(e,n,t,r){if(typeof e!==\"number\"||!Number.isFinite(e)||!Number.isInteger(e)||e<1)k(`${n} must be a positive integer; got ${we(e)}`,t,r);return e}function Cn(e,n,t){let r=Qe(e.name,n,e.source,t),i=y(e.value,n,t),o=On(e.name,n);if(o)C(i,o,n,e.value.source??e.source,t,`${e.name} element`);let a=e.index?he(y(e.index,n,t),\"Insertion position\",e.index.source??e.source,t):r.length+1;if(a>r.length+1)k(`Insertion position ${a} is out of bounds for length ${r.length}; expected 1..${r.length+1}`,e.index?.source??e.source,t);r.splice(a-1,0,i)}function Un(e,n,t){let r=Qe(e.name,n,e.source,t),i=he(y(e.count,n,t),\"Removal count\",e.count.source??e.source,t);if(r.length===0)k(\"Cannot remove from an empty list\",e.source,t);if(!e.index){r.pop();return}let o=he(y(e.index,n,t),\"Removal position\",e.index.source??e.source,t);if(o>r.length)k(`Removal position ${o} is out of bounds for length ${r.length}; expected 1..${r.length}`,e.index.source??e.source,t);if(i>r.length-o+1)k(`Removal interval ${o}..${o+i-1} exceeds list length ${r.length}`,e.count.source??e.source,t);r.splice(o-1,i)}function qn(e,n,t){let r=y(e.start,n,t),i=y(e.end,n,t);if(typeof r!==\"number\"||!Number.isFinite(r)||!Number.isInteger(r)||typeof i!==\"number\"||!Number.isFinite(i)||!Number.isInteger(i))fe(e.source,t);let o=[],a=r<=i?1:-1;for(let s=r;a>0?s<=i:s>=i;s+=a)if(o.push(s),s+a===s&&s!==i)fe(e.source,t);return o}function Bn(e,n,t){let r=ce(e.iterable,n,t);K(e.variable,r,n,()=>{if(Ae.has(n))De(e.body,n,t);else Se(e.body,n,t)})}function Pn(e,n,t){let r=ce(e.iterable,n,t),i=[];return ve(Ye,n,()=>K(e.variable,r,n,()=>{for(let o of e.body)if(o.type===\"returnStatement\")i.push(y(o.expression,n,t));else try{Ke(o,n,t)}catch(a){if(a instanceof xe)i.push(a.value);else throw a}})),i}function ce(e,n,t){let r=y(e,n,t);if(!Array.isArray(r))Le(e.source,t);return r.slice()}function K(e,n,t,r){let i=t.has(e),o=i?t.get(e):void 0;try{for(let a of n)t.set(e,a),r()}finally{if(i)t.set(e,o);else t.delete(e)}}var ke=new WeakMap,Te=new WeakMap;function nn(e){return e.some((n)=>n.type!==\"diagramElement\")}function Wn(e){if(nn(e.declaration.content))throw Error(\"Version 1 control-bearing diagram models are missing expanded instances.\")}function X(e){if(!Array.isArray(e)||typeof e[0]!==\"string\")throw Error(\"Invalid serialized diagram value.\");switch(e[0]){case\"undefined\":if(e.length!==1)throw Error(\"Invalid serialized undefined diagram value.\");return;case\"null\":if(e.length!==1)throw Error(\"Invalid serialized null diagram value.\");return null;case\"boolean\":if(e.length!==2||typeof e[1]!==\"boolean\")throw Error(\"Invalid serialized boolean diagram value.\");return e[1];case\"number\":if(e.length!==2)throw Error(\"Invalid serialized number diagram value.\");if(e[1]===\"nan\")return NaN;if(e[1]===\"positive-infinity\")return 1/0;if(e[1]===\"negative-infinity\")return-1/0;if(typeof e[1]!==\"number\")throw Error(\"Invalid serialized number diagram value.\");return e[1];case\"string\":if(e.length!==2||typeof e[1]!==\"string\")throw Error(\"Invalid serialized string diagram value.\");return e[1];case\"array\":if(e.length!==2||!Array.isArray(e[1]))throw Error(\"Invalid serialized array diagram value.\");return e[1].map(X);case\"object\":{if(e.length!==2||!Array.isArray(e[1]))throw Error(\"Invalid serialized object diagram value.\");let n=e[1].map((t)=>{if(!Array.isArray(t)||t.length!==2||typeof t[0]!==\"string\")throw Error(\"Invalid serialized object entry in diagram value.\");return[t[0],X(t[1])]});return Object.fromEntries(n)}case\"map\":if(e.length!==2||!Array.isArray(e[1]))throw Error(\"Invalid serialized map diagram value.\");return new Map(e[1].map((n)=>{if(!Array.isArray(n)||n.length!==2)throw Error(\"Invalid serialized map entry in diagram value.\");return[X(n[0]),X(n[1])]}));case\"set\":if(e.length!==2||!Array.isArray(e[1]))throw Error(\"Invalid serialized set diagram value.\");return new Set(e[1].map(X));default:throw Error(\"Unknown serialized diagram value type.\")}}function Q(e,n){if(!(e instanceof Map))throw Error(`Invalid serialized diagram context map '${n}'.`);for(let t of e.keys())if(typeof t!==\"string\")throw Error(`Invalid key in serialized diagram context map '${n}'.`);return e}function Ne(e,n=new Set){if(e===void 0||e===null||typeof e===\"boolean\"||typeof e===\"number\"||typeof e===\"string\")return;if(!e||typeof e!==\"object\")throw Error(\"Unsupported serialized diagram instance binding value.\");if(n.has(e))throw Error(\"Serialized diagram instance binding contains a cyclic value.\");n.add(e);try{if(Array.isArray(e)){e.forEach((r)=>Ne(r,n));return}let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)throw Error(\"Unsupported serialized diagram instance binding value.\");Object.values(e).forEach((r)=>Ne(r,n))}finally{n.delete(e)}}function Hn(e,n){if(!Array.isArray(n))throw Error(\"Invalid serialized diagram instance source path.\");let t=e,r=0,i=!1,o=[];while(r<n.length){let a=n[r++];if(!a||typeof a!==\"object\"||Array.isArray(a)||a.type!==\"content\"||!Number.isSafeInteger(a.index)||a.index<0)throw Error(\"Invalid serialized diagram instance source path.\");let s=t[a.index];if(!s)throw Error(\"Serialized diagram instance source path does not resolve.\");if(s.type===\"diagramElement\"){if(r!==n.length)throw Error(\"Serialized diagram instance source path continues past a primitive.\");return{element:s,bindingNames:o,controlOriginating:i}}if(i=!0,s.type===\"diagramForBlock\"){o.push(s.variable),t=s.content;continue}let l=n[r++];if(!l||typeof l!==\"object\"||Array.isArray(l)||l.type!==\"branch\"||l.branch!==\"consequent\"&&l.branch!==\"alternate\")throw Error(\"Invalid serialized diagram instance branch path.\");if(t=l.branch===\"consequent\"?s.consequent:s.alternate??[],l.branch===\"alternate\"&&!s.alternate)throw Error(\"Serialized diagram instance source path does not resolve.\")}throw Error(\"Serialized diagram instance source path does not resolve to a primitive.\")}function _n(e,n){if(!Array.isArray(n))throw Error(\"Invalid serialized diagram instance list.\");let t=0,r=n.map((i,o)=>{if(!i||typeof i!==\"object\"||Array.isArray(i)||!(\"identity\"in i)||!(\"bindings\"in i)||!Number.isSafeInteger(i.identity)||i.identity!==o||!Array.isArray(i.bindings))throw Error(\"Invalid serialized diagram instance descriptor.\");let a=i,s=a.bindings,l=Hn(e,a.sourcePath);if(l.controlOriginating&&++t>on)throw Error(\"Serialized diagram instance list exceeds the generated element limit.\");if(s.length!==l.bindingNames.length)throw Error(\"Serialized diagram instance has incomplete loop bindings.\");let u=s.map((c,m)=>{if(!c||typeof c!==\"object\"||Array.isArray(c)||!(\"name\"in c)||!(\"value\"in c))throw Error(\"Invalid serialized diagram instance loop binding.\");let d=c;if(d.name!==l.bindingNames[m]||typeof d.name!==\"string\")throw Error(\"Invalid serialized diagram instance loop binding.\");let f=X(d.value);return Ne(f),Object.freeze({name:d.name,value:f})});return Object.freeze({identity:a.identity,element:l.element,bindings:Object.freeze(u)})});return Object.freeze(r)}function tn(e){let n=JSON.parse(e);if(!n||typeof n!==\"object\"||Array.isArray(n)||!(\"version\"in n)||n.version!==1&&n.version!==2||!(\"model\"in n)||!(\"context\"in n))throw Error(\"Invalid serialized diagram model envelope.\");let t=n,r=t.version;if(r===2){if(!Array.isArray(t.instances))throw Error(\"Invalid serialized diagram instance list.\");if(!Number.isSafeInteger(t.instanceCount)||t.instanceCount!==t.instances.length)throw Error(\"Serialized diagram instance count does not match its payload.\")}let i=X(t.model),o=X(t.context);if(!i||typeof i!==\"object\"||Array.isArray(i)||!o||typeof o!==\"object\"||Array.isArray(o))throw Error(\"Invalid serialized diagram model or evaluation context.\");let a=ue(i);if(!a.declaration||!Array.isArray(a.declaration.content))throw Error(\"Invalid serialized diagram declaration.\");let s=r===1?(Wn(a),an(a.declaration.content)):_n(a.declaration.content,t.instances),l=o;if(!l.values||typeof l.values!==\"object\"||Array.isArray(l.values)||!Array.isArray(l.immutableValues)||!l.declarationRegistries||!Array.isArray(l.declarationRegistries.records)||!Array.isArray(l.declarationRegistries.functions)||l.validationMode!==\"aggregate\"&&l.validationMode!==\"fail-fast\")throw Error(\"Invalid serialized diagram evaluation context.\");let u=Q(l.recordTypes,\"recordTypes\"),c=Q(l.functions,\"functions\"),m=new j(u,c,l.dimensionRegistry);m.validationMode=l.validationMode;for(let[d,f]of Object.entries(l.values))if(m.set(d,f),l.immutableValues.includes(d))m.markImmutable(f);for(let[d,f]of Q(l.enumDeclarations,\"enumDeclarations\"))m.enumDeclarations.set(d,f);for(let[d,f]of Q(l.enumValues,\"enumValues\"))m.enumValues.set(d,f);for(let[d,f]of Q(l.bindingTypes,\"bindingTypes\"))m.bindingTypes.set(d,f);for(let d of l.declarationRegistries.records){let f=u.get(d.name);if(!f||!Array.isArray(d.fields))throw Error(\"Invalid serialized record declaration registry.\");if(d.declaration)V(f,d.declaration);let p=f.declaredFields??f.fields;if(p.length!==d.fields.length)throw Error(\"Serialized record field registry does not match its declaration.\");d.fields.forEach((g,h)=>{if(g)V(p[h],g)})}for(let d of l.declarationRegistries.functions){let f=c.get(d.name);if(!f)throw Error(\"Invalid serialized function declaration registry.\");if(d.declaration)V(f,d.declaration)}return ke.set(a,m),Te.set(a,s),a}function A(e,n=new Map){if(!e||typeof e!==\"object\")return e;let t=n.get(e);if(t)return t;if(Array.isArray(e)){let i=[];n.set(e,i);for(let o of e)i.push(A(o,n));return i}if(e instanceof Map){let i=new Map;n.set(e,i);for(let[o,a]of e)i.set(A(o,n),A(a,n));return i}if(e instanceof Set){let i=new Set;n.set(e,i);for(let o of e)i.add(A(o,n));return i}let r={};n.set(e,r);for(let[i,o]of Object.entries(e))r[i]=A(o,n);return r}function ue(e,n=new Set){if(!e||typeof e!==\"object\"||n.has(e))return e;if(n.add(e),Array.isArray(e))e.forEach((t)=>ue(t,n));else if(!(e instanceof Map)&&!(e instanceof Set))Object.values(e).forEach((t)=>ue(t,n));return Object.freeze(e)}function rn(e){let n=A(e.recordTypes),t=A(e.functions),r=e.dimensionRegistry?A(e.dimensionRegistry):void 0,i=new j(n,t,r);i.validationMode=e.validationMode;for(let[o,a]of e.recordTypes){let s=n.get(o),l=R(a,e.dimensionRegistry);if(l)V(s,A(l));let u=a.declaredFields??a.fields,c=s.declaredFields??s.fields;for(let m=0;m<u.length;m++){let d=R(u[m],e.dimensionRegistry);if(d&&c[m])V(c[m],A(d))}}for(let[o,a]of e.functions){let s=R(a,e.dimensionRegistry);if(s)V(t.get(o),A(s))}for(let[o,a]of e.enumDeclarations)i.enumDeclarations.set(o,A(a));for(let[o,a]of e.enumValues)i.enumValues.set(o,A(a));for(let[o,a]of e.bindingTypes)i.bindingTypes.set(o,A(a));for(let[o,a]of Object.entries(e.toObject())){let s=A(a);if(i.set(o,s),e.isImmutable(a))i.markImmutable(s)}return i}var on=64;function an(e){if(nn(e))throw Error(\"Control-bearing diagram models are missing their expanded per-instance bindings.\");return Object.freeze(e.map((n,t)=>{if(n.type!==\"diagramElement\")throw Error(\"Unexpected diagram control in static content.\");return Object.freeze({identity:t,element:n,bindings:Object.freeze([])})}))}function Gn(e,n,t){let r=[],i=[],o=0,a=(s,l)=>{for(let u of s){if(u.type===\"diagramElement\"){if(l){if(o>=on)w(\"AMXD6004\",\"Number of elements in this diagram exceed the maximum (64)\",u.source??u.nameSource,t);o++}r.push(Object.freeze({identity:r.length,element:u,bindings:Object.freeze(i.map((m)=>Object.freeze({name:m.name,value:A(m.value)})))}));continue}if(u.type===\"diagramForBlock\"){let m=ce(u.iterable,n,t);K(u.variable,m,n,()=>{i.push({name:u.variable,value:n.get(u.variable)});try{a(u.content,!0)}finally{i.pop()}});continue}let c=F(y(u.test,n,t))?u.consequent:u.alternate;if(c)a(c,!0)}};return a(e,!1),Object.freeze(r)}function sn(e,n,t,r=0){if(r>=e.length)return t();let i,o=e[r];return K(o.name,[o.value],n,()=>{i=sn(e,n,t,r+1)}),i}function U(e,n){let t=e.properties.find((r)=>r.name===n);if(!t)throw Error(`Type checker accepted missing diagram property '${n}'`);return t}function Yn(e,n,t,r,i,o){let a=U(e,n),s=y(a.expression,t,r);if(typeof s!==\"number\"||!Number.isFinite(s)){if(s===1/0&&o===i.to)w(\"AMXD010\",\"Infinity value calculated for time upper bound\",a.valueSource??a.source,r);if(s===1/0&&o>i.from&&o<i.to)w(\"AMXD011\",\"Expression produces an infinite result\",a.valueSource??a.source,r);w(\"AMXD008\",\"Invalid primitive geometry\",a.valueSource??a.source,r)}return s}function cn(e,n,t,r,i,o){if(typeof t!==\"number\"||!Number.isFinite(t)||t<n.from||t>n.to)w(\"AMXD004\",\"Invalid time bounds\",e.times[0]?.source??e.source,o);let a=rn(i);a.set(n.variable,t);let s=(u)=>{let c=(f)=>Yn(u,f,a,o,n,t),m=(f)=>{let p=U(u,f).expression;if(p.type!==\"stringLiteral\")throw Error(\"Type checker accepted a non-literal diagram style\");return p.value},d=()=>{let f=U(u,\"lineWidth\").expression;if(f.type!==\"numberLiteral\")throw Error(\"Type checker accepted a non-literal line width\");return f.value};try{switch(u.primitive){case\"line\":{let f=u.properties.find((g)=>g.name===\"arrow\")?.expression,p=f?.type===\"stringLiteral\"?f.value:\"none\";return Object.freeze({primitive:\"line\",name:u.name,source:u.source,x1:c(\"x1\"),y1:c(\"y1\"),x2:c(\"x2\"),y2:c(\"y2\"),stroke:m(\"stroke\"),lineWidth:d(),arrow:p})}case\"rectangle\":{let f=c(\"width\"),p=c(\"height\");if(f<=0)w(\"AMXD008\",\"Invalid primitive geometry\",U(u,\"width\").valueSource,o);if(p<=0)w(\"AMXD008\",\"Invalid primitive geometry\",U(u,\"height\").valueSource,o);let g=u.properties.some((h)=>h.name===\"fill\")?m(\"fill\"):void 0;return Object.freeze({primitive:\"rectangle\",name:u.name,source:u.source,x:c(\"x\"),y:c(\"y\"),width:f,height:p,stroke:m(\"stroke\"),...g===void 0?{}:{fill:g},lineWidth:d()})}case\"circle\":{let f=c(\"r\");if(f<=0)w(\"AMXD008\",\"Invalid primitive geometry\",U(u,\"r\").valueSource,o);let p=u.properties.some((g)=>g.name===\"fill\")?m(\"fill\"):void 0;return Object.freeze({primitive:\"circle\",name:u.name,source:u.source,cx:c(\"cx\"),cy:c(\"cy\"),r:f,stroke:m(\"stroke\"),...p===void 0?{}:{fill:p},lineWidth:d()})}case\"text\":{let f=U(u,\"value\"),p=y(f.expression,a,o);if(typeof p!==\"string\")w(\"AMX3002\",\"Expected String, got non-String value\",f.valueSource,o);return Object.freeze({primitive:\"text\",name:u.name,source:u.source,x:c(\"x\"),y:c(\"y\"),value:p,fill:m(\"fill\")})}default:throw Error(`Type checker accepted unsupported diagram primitive '${u.primitive}'`)}}catch(f){if(f instanceof x&&t!==n.from&&f.code!==\"AMXD008\"&&f.code!==\"AMXD010\"&&f.code!==\"AMXD011\")throw new x({code:\"AMXD009\",message:`Frame evaluation leads to invalid results. The underlying error is: ${f.message}`,file:f.file??o,line:f.line??u.source?.line,column:f.column??u.source?.column});throw f}},l=r.map((u)=>sn(u.bindings,a,()=>s(u.element)));return Object.freeze({time:t,elements:Object.freeze(l)})}function ee(e,n,t,r,i,o){let a=y(e,n,t);if(typeof a!==\"number\"||!Number.isFinite(a)||(r===\"AMXD003\"||r===\"AMXD014\"||r===\"AMXD005\")&&a<=0)w(r,i,o,t);return a}function en(e,n,t,r,i){let o=ue(A(e)),a=rn(n),s=(Fe)=>{let Re=o.properties.find((dn)=>dn.name===Fe);if(!Re)throw Error(`Type checker accepted missing diagram property '${Fe}'`);return Re},l=s(\"width\"),u=s(\"height\"),c=ee(l.expression,a,t,\"AMXD003\",\"Canvas width is invalid\",l.valueSource),m=ee(u.expression,a,t,\"AMXD014\",\"Canvas height is invalid\",u.valueSource),d=s(\"title\").expression,f=s(\"description\").expression;if(d.type!==\"stringLiteral\"||f.type!==\"stringLiteral\")throw Error(\"Type checker accepted a non-literal diagram title or description\");let p=o.times[0],g=ee(p.from,a,t,\"AMXD004\",\"Invalid time bounds\",p.fromSource??p.source),h=ee(p.to,a,t,\"AMXD004\",\"Invalid time bounds\",p.toSource??p.source);if(g>=h)w(\"AMXD004\",\"Invalid time bounds\",p.source??o.source,t);let v=ee(p.duration,a,t,\"AMXD005\",\"Invalid playback duration value\",p.durationSource??p.source),L=Object.freeze({variable:p.name,from:g,to:h,duration:v}),Y=Gn(o.content,a,t),mn=cn(o,L,g,Y,a,t),me=Object.freeze({name:o.name,title:d.value,description:f.value,canvas:Object.freeze({width:c,height:m,coordinates:\"bottom-left-y-up\"}),timeline:L,declaration:o,initialFrame:mn,source:o.source,file:t,documentNodeIndex:r,statementIndex:i});return ke.set(me,a),Te.set(me,Y),me}function un(e,n,t=e.file){let r=ke.get(e);if(!r)throw Error(\"Diagram model has no captured AMX evaluation context\");let i=Te.get(e)??an(e.declaration.content);return cn(e.declaration,e.timeline,n,i,r,t)}var Zn=\"http://www.w3.org/2000/svg\",Ie=new Set;function z(e,n={}){let t=document.createElementNS(Zn,e);for(let[r,i]of Object.entries(n))t.setAttribute(r,String(i));return t}function Jn(e,n,t){e.setAttribute(\"x\",String(n)),e.setAttribute(\"y\",String(t)),e.setAttribute(\"transform\",`translate(0 ${2*t}) scale(1 -1)`)}function Kn(e,n){let{model:t,canvas:r}=e,i=z(\"defs\"),o=z(\"marker\",{id:`${r.dataset.diagramId}-arrowhead`,markerWidth:6,markerHeight:6,refX:10,refY:5,orient:\"auto-start-reverse\",markerUnits:\"strokeWidth\",viewBox:\"0 0 10 10\"});o.append(z(\"path\",{d:\"M 0 0 L 10 5 L 0 10 z\",fill:\"context-stroke\"})),i.append(o);let a=z(\"g\",{transform:`translate(0 ${t.canvas.height}) scale(1 -1)`});for(let s of n.elements)if(s.primitive===\"line\"){let l=z(\"line\",{x1:s.x1,y1:s.y1,x2:s.x2,y2:s.y2,stroke:s.stroke,\"stroke-width\":s.lineWidth,\"stroke-linecap\":\"round\"});if(l.setAttribute(\"data-diagram-element\",s.name),s.arrow===\"start\"||s.arrow===\"both\")l.setAttribute(\"marker-start\",`url(#${r.dataset.diagramId}-arrowhead)`);if(s.arrow===\"end\"||s.arrow===\"both\")l.setAttribute(\"marker-end\",`url(#${r.dataset.diagramId}-arrowhead)`);a.append(l)}else if(s.primitive===\"rectangle\"){let l=z(\"rect\",{x:s.x,y:s.y,width:s.width,height:s.height,stroke:s.stroke,fill:s.fill??\"none\",\"stroke-width\":s.lineWidth});l.setAttribute(\"data-diagram-element\",s.name),a.append(l)}else if(s.primitive===\"circle\"){let l=z(\"circle\",{cx:s.cx,cy:s.cy,r:s.r,stroke:s.stroke,fill:s.fill??\"none\",\"stroke-width\":s.lineWidth});l.setAttribute(\"data-diagram-element\",s.name),a.append(l)}else{let l=z(\"text\",{fill:s.fill,\"font-family\":\"sans-serif\",\"font-size\":12});Jn(l,s.x,s.y),l.setAttribute(\"data-diagram-element\",s.name),l.textContent=s.value,a.append(l)}r.replaceChildren(i,a),r.removeAttribute(\"aria-hidden\")}function $e(e){window.dispatchEvent(new CustomEvent(\"openamx-diagram-frame\",{detail:e}))}async function Qn(e){if(e.dataset.encoding!==\"gzip-base64\")throw Error(\"Unsupported diagram data encoding.\");let n=atob(e.textContent??\"\"),t=new Uint8Array(n.length);for(let i=0;i<n.length;i++)t[i]=n.charCodeAt(i);let r=new Blob([t]).stream().pipeThrough(new DecompressionStream(\"gzip\"));return tn(await new Response(r).text())}function le(e){let n=e.model.title,t=e.time.toFixed(3).toString();e.playButton.textContent=e.running?\"Pause\":\"Play\",e.playButton.setAttribute(\"aria-label\",`${e.running?\"Pause\":\"Play\"} ${n}`),e.scrubber.value=String(e.time),e.scrubber.setAttribute(\"aria-valuetext\",t),e.timeOutput.value=t,e.timeOutput.textContent=t}function q(e){if(e.running=!1,e.animationFrame!==void 0)cancelAnimationFrame(e.animationFrame);e.animationFrame=void 0,le(e)}function B(e,n){e.time=n,le(e);try{let t=un(e.model,n);if(Kn(e,t),e.alert.hidden=!0,e.alert.textContent=\"\",e.failed)e.failed=!1,$e({version:1,type:\"diagram-recovered\",diagramId:e.canvas.dataset.diagramId});return!0}catch(t){q(e),e.canvas.replaceChildren(),e.canvas.setAttribute(\"aria-hidden\",\"true\"),e.failed=!0;let r=t instanceof x?{code:t.code,message:t.message,file:t.file??e.model.file,line:t.line??e.model.source?.line,column:t.column??e.model.source?.column}:{code:\"DIAGRAM_RUNTIME\",message:\"The diagram frame could not be evaluated.\",file:e.model.file,line:e.model.source?.line,column:e.model.source?.column},i=r.file?`${r.file}${r.line?`:${r.line}${r.column?`:${r.column}`:\"\"}`:\"\"}`:r.line?`${r.line}${r.column?`:${r.column}`:\"\"}`:\"\";return e.alert.textContent=`${r.code}: ${r.message}${i?` (${i})`:\"\"}`,e.alert.hidden=!1,$e({version:1,type:\"diagram-error\",diagramId:e.canvas.dataset.diagramId,...r}),!1}}function et(e){if(e.running||e.failed)return;if(e.time>=e.model.timeline.to){if(!e.canvas.closest(\"[data-openamx-diagram]\")?.querySelector(\"[data-diagram-loop]\")?.checked)return;B(e,e.model.timeline.from)}e.running=!0,e.startedAt=performance.now()-(e.time-e.model.timeline.from)/(e.model.timeline.to-e.model.timeline.from)*e.model.timeline.duration*1000,le(e),e.animationFrame=requestAnimationFrame((n)=>ln(e,n))}function ln(e,n){if(!e.running||!document.contains(e.canvas)){q(e);return}let t=e.model.timeline.duration,r=(n-e.startedAt)/1000/t;if(r>=1){if(!(e.canvas.closest(\"[data-openamx-diagram]\")?.querySelector(\"[data-diagram-loop]\")?.checked??!1)){B(e,e.model.timeline.to),q(e);return}if(!B(e,e.model.timeline.from))return;e.startedAt=n}else{let i=e.model.timeline.from,o=e.model.timeline.to,a=r<=0?i:i*(1-r)+o*r;if(!B(e,a))return}e.animationFrame=requestAnimationFrame((i)=>ln(e,i))}async function nt(e){let n=e.querySelector(\"[data-diagram-model]\"),t=e.querySelector(\"[data-diagram-canvas]\"),r=e.querySelector(\"[data-diagram-play]\"),i=e.querySelector(\"[data-diagram-reset]\"),o=e.querySelector(\"[data-diagram-scrubber]\"),a=e.querySelector(\"[data-diagram-loop]\"),s=e.querySelector(\"[data-diagram-time]\"),l=e.querySelector(\"[data-diagram-error]\");if(!n||!t||!r||!i||!o||!a||!s||!l)throw Error(\"Diagram HTML is missing required runtime elements.\");let u=await Qn(n);t.dataset.diagramId=e.dataset.diagramId;let c={model:u,canvas:t,playButton:r,scrubber:o,timeOutput:s,alert:l,running:!1,failed:!1,time:u.timeline.from,startedAt:0};Ie.add(c),le(c),r.addEventListener(\"click\",()=>{if(c.running)q(c);else et(c)}),i.addEventListener(\"click\",()=>{q(c),B(c,u.timeline.from)}),o.addEventListener(\"input\",()=>{let m=Number(o.value);q(c),B(c,m)}),B(c,u.timeline.from)}async function tt(){for(let e of Array.from(document.querySelectorAll(\"[data-openamx-diagram]\")))try{await nt(e)}catch(n){let t=e.querySelector(\"[data-diagram-error]\");if(!t)throw n;t.textContent=`DIAGRAM_RUNTIME: ${n instanceof Error?n.message:\"The diagram could not be initialized.\"}`,t.hidden=!1,$e({version:1,type:\"diagram-error\",diagramId:e.dataset.diagramId??\"\",code:\"DIAGRAM_RUNTIME\",message:t.textContent})}}document.addEventListener(\"DOMContentLoaded\",()=>{tt()},{once:!0});window.addEventListener(\"pagehide\",()=>{for(let e of Ie)q(e);Ie.clear()},{once:!0});})();\n";
|
|
2
2
|
export default diagramBrowserRuntime;
|
|
@@ -370,15 +370,18 @@ function renderChart(emission, identity) {
|
|
|
370
370
|
const zoomControls = browserModel.zoomable
|
|
371
371
|
? `<div class="openamx-chart-controls" role="group" aria-label="Chart zoom controls"><button type="button" data-zoom="out" aria-label="Zoom out">Zoom out</button><button type="button" data-zoom="in" aria-label="Zoom in">Zoom in</button><button type="button" data-zoom="reset">Reset zoom</button></div>`
|
|
372
372
|
: '';
|
|
373
|
+
const tableRelation = model.showTable ? ` ${id}-table-caption` : '';
|
|
373
374
|
const textRows = model.table.rows.map(row => `<tr>${row.values.map(value => `<td>${renderNarrativeText(formatAmxValue(value))}</td>`).join('')}</tr>`).join('');
|
|
375
|
+
const table = model.showTable
|
|
376
|
+
? ` <table class="openamx-chart-data" id="${id}"><caption id="${id}-table-caption">${escapeHtml(model.table.caption)}</caption><thead><tr>${model.table.headings.map(value => `<th scope="col">${escapeHtml(value)}</th>`).join('')}</tr></thead><tbody>${textRows}</tbody></table>\n`
|
|
377
|
+
: '';
|
|
374
378
|
const data = safeJson(browserModel);
|
|
375
379
|
return `<figure class="openamx-view openamx-chart" id="${id}-figure" data-openamx-chart aria-labelledby="${titleId}" aria-describedby="${descriptionId} ${summaryId}">
|
|
376
380
|
<figcaption><strong id="${titleId}">${escapeHtml(model.title)}</strong><span id="${descriptionId}">${escapeHtml(model.description)}</span></figcaption>
|
|
377
|
-
<p id="${summaryId}" class="sr-only">${escapeHtml(
|
|
381
|
+
<p id="${summaryId}" class="sr-only">${escapeHtml(browserModel.accessibility.summary)}</p>
|
|
378
382
|
${seriesControls}${zoomControls}
|
|
379
|
-
<div id="${id}-plot" class="openamx-chart-plot" role="img" aria-label="${escapeHtml(model.title)}" aria-describedby="${descriptionId} ${summaryId}
|
|
380
|
-
<
|
|
381
|
-
<script type="application/json" data-chart-model>${data}</script>
|
|
383
|
+
<div id="${id}-plot" class="openamx-chart-plot" role="img" aria-label="${escapeHtml(model.title)}" aria-describedby="${descriptionId} ${summaryId}${tableRelation}"></div>
|
|
384
|
+
${table} <script type="application/json" data-chart-model>${data}</script>
|
|
382
385
|
</figure>`;
|
|
383
386
|
}
|
|
384
387
|
function serializeChartModel(model) {
|
|
@@ -390,17 +393,31 @@ function serializeChartModel(model) {
|
|
|
390
393
|
const zoom = [{ type: 'inside', xAxisIndex: 0, ...(model.kind === 'scatter' ? { yAxisIndex: 0 } : {}), filterMode: 'none', zoomOnMouseWheel: true, moveOnMouseMove: true, moveOnMouseWheel: true }];
|
|
391
394
|
optionProperty(option, 'dataZoom', zoom);
|
|
392
395
|
}
|
|
396
|
+
const needsRowLabels = model.kind === 'bar' || model.kind === 'column'
|
|
397
|
+
|| model.kind === 'line' && isCategoryAxis(model.option.xAxis);
|
|
393
398
|
return {
|
|
394
399
|
kind: model.kind,
|
|
395
400
|
title: model.title,
|
|
396
401
|
description: model.description,
|
|
402
|
+
showTable: model.showTable,
|
|
397
403
|
dimensions: model.dimensions,
|
|
398
404
|
option,
|
|
399
405
|
formatterPaths,
|
|
400
|
-
|
|
406
|
+
...(model.showTable
|
|
407
|
+
? { table: model.table, accessibility: model.accessibility }
|
|
408
|
+
: {
|
|
409
|
+
...(needsRowLabels ? {
|
|
410
|
+
rowLabels: Object.fromEntries(model.table.rows.map(row => [row.id, String(row.values[0] ?? '')]))
|
|
411
|
+
} : {}),
|
|
412
|
+
accessibility: {
|
|
413
|
+
role: model.accessibility.role,
|
|
414
|
+
title: model.accessibility.title,
|
|
415
|
+
description: model.accessibility.description,
|
|
416
|
+
summary: `${model.table.rows.length} source rows; ${model.plottedPointCount} plotted points.${model.dateTimePresentation ? ' DateTime values are presented in UTC ISO 8601 format; source order is preserved.' : ''}`
|
|
417
|
+
}
|
|
418
|
+
}),
|
|
401
419
|
series: model.series,
|
|
402
420
|
axes: model.axes,
|
|
403
|
-
accessibility: model.accessibility,
|
|
404
421
|
plottedPointCount: model.plottedPointCount,
|
|
405
422
|
...(model.emptyState ? { emptyState: model.emptyState } : {}),
|
|
406
423
|
...(model.dateTimePresentation ? { dateTimePresentation: model.dateTimePresentation } : {}),
|
|
@@ -476,7 +493,7 @@ const charts=new Map();
|
|
|
476
493
|
const escapeHtml=value=>String(value??'').replace(/[&<>"']/g,char=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[char]));
|
|
477
494
|
const iso=value=>{const date=new Date(typeof value==='number'?value:Date.parse(value));return Number.isNaN(date.getTime())?'':date.toISOString()};
|
|
478
495
|
const locate=(object,path)=>path.slice(2).split('.').reduce((current,key)=>current==null?undefined:current[/^\\d+$/.test(key)?Number(key):key],object);
|
|
479
|
-
const rowLabel=(value,model)=>{const row=model.table
|
|
496
|
+
const rowLabel=(value,model)=>{const id=String(value);if(model.rowLabels&&Object.prototype.hasOwnProperty.call(model.rowLabels,id))return model.rowLabels[id];const row=model.table?.rows.find(item=>item.id===id);return row?String(row.values[0]??''):String(value??'')};
|
|
480
497
|
const axisLabel=(value,model)=>model.dateTimePresentation?iso(value):rowLabel(value,model);
|
|
481
498
|
const formatTooltip=(input,model)=>{const entries=(Array.isArray(input)?input:[input]).filter(item=>item&&typeof item==='object');return entries.map(entry=>{const series=model.series.find(item=>item.id===entry.seriesId||item.name===entry.seriesName);const values=Array.isArray(entry.value)?entry.value:[];if(model.kind==='scatter'){const x=values[0]??null,y=values[1]??null;const xUnit=model.axes.find(item=>item.role==='x')?.name,yUnit=model.axes.find(item=>item.role==='y')?.name;return '<div><strong>'+escapeHtml(entry.seriesName||'')+'</strong><br>x: '+escapeHtml(x)+(xUnit?' '+escapeHtml(xUnit):'')+'<br>y: '+escapeHtml(y)+(yUnit?' '+escapeHtml(yUnit):'')+'</div>'}const rawCategory=entry.axisValue??values[0]??entry.name;const category=model.dateTimePresentation?iso(rawCategory):rowLabel(rawCategory,model);const value=model.kind==='line'?values[1]:entry.value;const categoryUnit=model.kind==='line'?model.axes.find(item=>item.role==='x')?.name:undefined;const coordinate=escapeHtml(category)+(categoryUnit?' '+escapeHtml(categoryUnit):'');return '<div><strong>'+escapeHtml(entry.seriesName||'')+'</strong><br>'+coordinate+': '+escapeHtml(value)+(series?.unit?.text?' '+escapeHtml(series.unit.text):'')+'</div>'}).join('')};
|
|
482
499
|
const setZoom=(chart,zoom)=>{const current=chart.getOption().dataZoom?.[0]??{start:0,end:100};chart.setOption({dataZoom:[{...current,...zoom}]})};
|
|
@@ -419,7 +419,9 @@ function addChart(children, emission, identity) {
|
|
|
419
419
|
return;
|
|
420
420
|
}
|
|
421
421
|
const description = [
|
|
422
|
-
...plotted.omittedSeries.map(name =>
|
|
422
|
+
...plotted.omittedSeries.map(name => model.showTable
|
|
423
|
+
? `Series "${name}" has no plottable coordinates and is listed only in the complete data table.`
|
|
424
|
+
: `Series "${name}" has no plottable coordinates and is omitted from the chart.`),
|
|
423
425
|
...(plotted.hasGaps ? ['Null gaps break the line; continued segments are hidden from the legend.'] : [])
|
|
424
426
|
];
|
|
425
427
|
const run = new ChartRun({
|
|
@@ -438,7 +440,9 @@ function addChart(children, emission, identity) {
|
|
|
438
440
|
});
|
|
439
441
|
children.push(new Paragraph({ children: [run] }));
|
|
440
442
|
if (plotted.omittedSeries.length > 0) {
|
|
441
|
-
children.push(new Paragraph(
|
|
443
|
+
children.push(new Paragraph(model.showTable
|
|
444
|
+
? `Series with no plottable coordinates, shown only in the complete table: ${plotted.omittedSeries.join(', ')}.`
|
|
445
|
+
: `Series with no plottable coordinates, omitted from the chart: ${plotted.omittedSeries.join(', ')}.`));
|
|
442
446
|
}
|
|
443
447
|
addChartTable(children, model);
|
|
444
448
|
return;
|
|
@@ -518,6 +522,8 @@ function addNoChartAlternative(children, model, notice) {
|
|
|
518
522
|
addChartTable(children, model);
|
|
519
523
|
}
|
|
520
524
|
function addChartTable(children, model) {
|
|
525
|
+
if (!model.showTable)
|
|
526
|
+
return;
|
|
521
527
|
const header = new TableRow({
|
|
522
528
|
tableHeader: true,
|
|
523
529
|
cantSplit: true,
|
|
@@ -539,10 +545,13 @@ function addChartTable(children, model) {
|
|
|
539
545
|
}));
|
|
540
546
|
}
|
|
541
547
|
function chartAltText(model, details = []) {
|
|
548
|
+
const summary = model.showTable
|
|
549
|
+
? model.accessibility.summary
|
|
550
|
+
: `${model.table.rows.length} source rows; ${model.plottedPointCount} plotted points.${model.dateTimePresentation ? ' DateTime values are presented in UTC ISO 8601 format; source order is preserved.' : ''}`;
|
|
542
551
|
return {
|
|
543
|
-
name: model.accessibility.tableId,
|
|
552
|
+
name: model.showTable ? model.accessibility.tableId : model.accessibility.title,
|
|
544
553
|
title: model.accessibility.title,
|
|
545
|
-
description: [model.accessibility.description,
|
|
554
|
+
description: [model.accessibility.description, summary, ...details].join(' ')
|
|
546
555
|
};
|
|
547
556
|
}
|
|
548
557
|
function chartTitle(model, accent) {
|