reactive-md 0.9.3 → 0.10.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/CHANGELOG-ch.md +34 -0
- package/CHANGELOG.md +34 -0
- package/README-ch.md +7 -7
- package/README-en.md +7 -7
- package/README.md +7 -7
- package/THIRD_PARTY_NOTICES.md +0 -57
- package/cli/help.mjs +6 -4
- package/cli/init.mjs +1 -1
- package/cli/migrate.mjs +1 -1
- package/dist-library/{LocalDocumentView-D6zQkTkt.js → LocalDocumentView-CP2QG86k.js} +46 -44
- package/dist-library/{LocalDocumentViewCore-CmJhemcA.js → LocalDocumentViewCore-Cd6yMEkg.js} +284 -265
- package/dist-library/{LocalReactiveDocumentCore-lAKOGAZ7.js → LocalReactiveDocumentCore-VuYpZqdn.js} +7 -7
- package/dist-library/LocalStaticDocumentView-DfX6bemE.js +147 -0
- package/dist-library/authoring-Bwu_zCWs.js +768 -0
- package/dist-library/choice-values-BItGjPD2.js +58 -0
- package/dist-library/compile-B35rfzKr.js +1742 -0
- package/dist-library/{compile-cache-key-6GgpETz_.js → compile-cache-key-D21X2Obx.js} +5 -5
- package/dist-library/{compiler-DLkKUK4t.js → compiler-DBwLawMZ.js} +4 -4
- package/dist-library/{compiler-core-Niqhp9wV.js → compiler-core-kkDiQ1RK.js} +3146 -2055
- package/dist-library/{component-kernel-IG4wOO0i.js → component-kernel-CsJSabHX.js} +42 -26
- package/dist-library/{component-state-Ht-hOK0W.js → component-state-Da0G8Ajc.js} +1 -1
- package/dist-library/{component-utils-eSj5IdG4.js → component-utils-ZM3jUJNy.js} +80 -79
- package/dist-library/conditional-branches-CIhJXasR.js +17 -0
- package/dist-library/{config-validation-Cpol91_M.js → config-validation-DbmsWAEV.js} +165 -152
- package/dist-library/{controls-B-CLSK8Q.js → controls-DRy5rzzN.js} +271 -228
- package/dist-library/{coordinate-PyLPMIQK.js → coordinate-c54pHfgf.js} +29 -29
- package/dist-library/data-table-CSAkm1eU.js +290 -0
- package/dist-library/data-table-model-DruztQFt.js +391 -0
- package/dist-library/{data-visuals-_Z7QqYTk.js → data-visuals-rZQUeQM0.js} +14 -14
- package/dist-library/{default-components-jugH7Ubr.js → default-components-B-39etG9.js} +233 -71
- package/dist-library/{default-config-DIrRpuQz.js → default-config-CCa8rm2k.js} +236 -216
- package/dist-library/default-options-By16CVw1.js +131 -0
- package/dist-library/{default-registry-BlloaZi7.js → default-registry-DXJy66xj.js} +3 -3
- package/dist-library/{default-schema-Ch-Vznpm.js → default-schema-CeYiEW1K.js} +3 -3
- package/dist-library/display-Bb6hAG5T.js +2065 -0
- package/dist-library/{document-theme-DBAfnk7y.js → document-theme-CJvN-nC1.js} +190 -3
- package/dist-library/{export-heVBqgxA.js → export-BSV4E0jv.js} +105 -106
- package/dist-library/font-aliases-CKYjwn4o.js +4 -0
- package/dist-library/{gallery-Q6VPS2ep.js → gallery-DM2yTVZJ.js} +1 -1
- package/dist-library/{html-CCnvzan1.js → html-CY9mC3Sr.js} +5 -5
- package/dist-library/{incremental-Bzvh8_lB.js → incremental-B-wW4H3F.js} +251 -245
- package/dist-library/{display-y4v9v0Qd.js → katex-4ukd4ZxT.js} +1555 -3618
- package/dist-library/layout-CPQggKxk.js +592 -0
- package/dist-library/{layout-BnfDeUNy.js → layout-CaDWsDof.js} +1 -1
- package/dist-library/{math-view-B0jthpRw.js → math-view-CyGTS6kv.js} +1 -1
- package/dist-library/{mount-preset-C_i37FvY.js → mount-preset-DtrCX4G8.js} +4 -4
- package/dist-library/{numeric-sliders-CkWS0-ja.js → numeric-sliders-BmJ1LCLx.js} +190 -190
- package/dist-library/{observability-CYLuvFfL.js → observability-BVQ16ByQ.js} +5 -4
- package/dist-library/{package-core-9UK5ZdqB.js → package-core-Cu_r_qs7.js} +7 -6
- package/dist-library/{parser-9yNJxGip.js → parser-BHl9Lxbw.js} +2 -2
- package/dist-library/{parser-standard-BPIy4HOu.js → parser-standard-DDAKv_DZ.js} +247 -247
- package/dist-library/{plugin-packs-CZb46nuv.js → plugin-packs-CkI0floL.js} +3 -3
- package/dist-library/{preset-core-BW3NWZJ9.js → preset-core-BKPbH_Nv.js} +377 -306
- package/dist-library/{props-pJRrfDc6.js → props-0iDqxlTk.js} +56 -61
- package/dist-library/{react-BSo0o998.js → react-74jdGBmu.js} +2 -2
- package/dist-library/reactive-md-authoring.js +277 -269
- package/dist-library/reactive-md-build.js +327 -33
- package/dist-library/reactive-md-compiler-session.js +3 -3
- package/dist-library/reactive-md-compiler-standard.js +10 -10
- package/dist-library/reactive-md-compiler.js +3 -3
- package/dist-library/reactive-md-contracts.js +4 -4
- package/dist-library/reactive-md-default-packs.js +4 -3
- package/dist-library/reactive-md-default-preset.js +3 -3
- package/dist-library/reactive-md-export.js +6 -6
- package/dist-library/reactive-md-minimal-preset.js +3 -2
- package/dist-library/reactive-md-minimal-react-preset.js +18 -17
- package/dist-library/reactive-md-minimal.css +1 -1
- package/dist-library/reactive-md-observability.js +2 -2
- package/dist-library/reactive-md-pack-style-manifest.js +8 -0
- package/dist-library/reactive-md-plugin-chart.js +13 -9
- package/dist-library/reactive-md-plugin-data.js +4 -4
- package/dist-library/reactive-md-plugin-diagram.js +3 -3
- package/dist-library/reactive-md-plugin-forms.js +5 -5
- package/dist-library/reactive-md-plugin-gallery.js +3 -3
- package/dist-library/reactive-md-plugin-navigation.js +10 -10
- package/dist-library/reactive-md-plugin-network.js +5 -5
- package/dist-library/reactive-md-plugin-plot.js +4 -4
- package/dist-library/reactive-md-react-component-accordion.js +3 -3
- package/dist-library/reactive-md-react-component-alert.js +3 -3
- package/dist-library/reactive-md-react-component-anchor.js +3 -3
- package/dist-library/reactive-md-react-component-badge.js +3 -3
- package/dist-library/reactive-md-react-component-card.js +3 -3
- package/dist-library/reactive-md-react-component-chart.js +2 -2
- package/dist-library/reactive-md-react-component-checkbox.js +2 -2
- package/dist-library/reactive-md-react-component-checklist.js +2 -2
- package/dist-library/reactive-md-react-component-choices.js +2 -2
- package/dist-library/reactive-md-react-component-column.js +1 -1
- package/dist-library/reactive-md-react-component-coordinate.js +2 -2
- package/dist-library/reactive-md-react-component-counter.js +2 -2
- package/dist-library/reactive-md-react-component-data-table.js +2 -2
- package/dist-library/reactive-md-react-component-date.js +2 -2
- package/dist-library/reactive-md-react-component-diagram.js +2 -2
- package/dist-library/reactive-md-react-component-disclosure.js +3 -3
- package/dist-library/reactive-md-react-component-edge.js +1 -1
- package/dist-library/reactive-md-react-component-else.js +10 -0
- package/dist-library/reactive-md-react-component-gallery-item.js +2 -2
- package/dist-library/reactive-md-react-component-gallery.js +2 -2
- package/dist-library/reactive-md-react-component-grid.js +3 -3
- package/dist-library/reactive-md-react-component-if.js +3 -3
- package/dist-library/reactive-md-react-component-input.js +2 -2
- package/dist-library/reactive-md-react-component-jump.js +3 -3
- package/dist-library/reactive-md-react-component-multi-select.js +2 -2
- package/dist-library/reactive-md-react-component-node.js +2 -2
- package/dist-library/reactive-md-react-component-number.js +2 -2
- package/dist-library/reactive-md-react-component-option.js +1 -1
- package/dist-library/reactive-md-react-component-panel.js +3 -3
- package/dist-library/reactive-md-react-component-plot.js +2 -2
- package/dist-library/reactive-md-react-component-progress.js +2 -2
- package/dist-library/reactive-md-react-component-quiz.js +2 -2
- package/dist-library/reactive-md-react-component-radio-group.js +2 -2
- package/dist-library/reactive-md-react-component-range-slider.js +2 -2
- package/dist-library/reactive-md-react-component-section.js +3 -3
- package/dist-library/reactive-md-react-component-select.js +2 -2
- package/dist-library/reactive-md-react-component-slider.js +2 -2
- package/dist-library/reactive-md-react-component-step.js +3 -3
- package/dist-library/reactive-md-react-component-steps.js +3 -3
- package/dist-library/reactive-md-react-component-tab.js +3 -3
- package/dist-library/reactive-md-react-component-table.js +2 -2
- package/dist-library/reactive-md-react-component-tabs.js +3 -3
- package/dist-library/reactive-md-react-component-text.js +3 -3
- package/dist-library/reactive-md-react-component-textarea.js +2 -2
- package/dist-library/reactive-md-react-component-timeline.js +2 -2
- package/dist-library/reactive-md-react-component-timer.js +2 -2
- package/dist-library/reactive-md-react-component-toggle.js +2 -2
- package/dist-library/reactive-md-react-component-tooltip.js +3 -3
- package/dist-library/reactive-md-react-component-validation.js +3 -3
- package/dist-library/reactive-md-react-minimal.js +4 -4
- package/dist-library/reactive-md-react-pack-controls.js +4 -4
- package/dist-library/reactive-md-react-pack-data.js +3 -3
- package/dist-library/reactive-md-react-pack-layout.js +25 -24
- package/dist-library/reactive-md-react-pack-visuals.js +2 -2
- package/dist-library/reactive-md-react-packed.js +6 -6
- package/dist-library/reactive-md-react-server.js +37 -36
- package/dist-library/reactive-md-react-static-server.js +2 -2
- package/dist-library/reactive-md-react-static.js +1 -1
- package/dist-library/reactive-md-react-unstyled.js +12 -12
- package/dist-library/reactive-md-react.js +12 -12
- package/dist-library/reactive-md-scan.js +1 -1
- package/dist-library/reactive-md-sdk.js +23 -9
- package/dist-library/reactive-md-standalone-configured.js +2 -2
- package/dist-library/reactive-md-standalone-host.js +2 -2
- package/dist-library/reactive-md-testing-browser.js +2 -2
- package/dist-library/reactive-md-testing-react.js +6 -6
- package/dist-library/reactive-md-testing.js +6 -6
- package/dist-library/reactive-md-vite.js +25 -9
- package/dist-library/reactive-md-worker-pool.js +3 -3
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +52 -43
- package/dist-library/{registry-core-CziAIP5P.js → registry-core-DxEaxhJ6.js} +3 -2
- package/dist-library/{render-nodes-DKjg_TR1.js → render-nodes-B6j6Ip5I.js} +766 -731
- package/dist-library/{requirements-DhIkxAbl.js → requirements-C56sFIEs.js} +2 -2
- package/dist-library/{resources-B_nbROgj.js → resources-6VaNgk-h.js} +2 -2
- package/dist-library/rmd-pack-layout.css +9 -0
- package/dist-library/rmd-pack-resource-layout.css +9 -0
- package/dist-library/runtime-BHeuLOv_.js +1369 -0
- package/dist-library/{runtime-requirement-C4-vNcf5.js → runtime-requirement-DzPO8raU.js} +166 -163
- package/dist-library/{schema-core-4sd1Vu7V.js → schema-core-CDXfxdID.js} +24 -1
- package/dist-library/{sdk-core-BLsW9cCy.js → sdk-core-CnE-n0Z7.js} +469 -314
- package/dist-library/{session-core-DLBRPV7f.js → session-core-C071yQwV.js} +140 -127
- package/dist-library/{validation-XXlb-spV.js → sha256-utf16-Bmandi_H.js} +392 -315
- package/dist-library/shareable-CHCDnl6j.js +844 -0
- package/dist-library/types/authoring/catalog.d.ts +3 -1
- package/dist-library/types/authoring/index.d.ts +1 -1
- package/dist-library/types/components/chart/default-chart-types.d.ts +3 -0
- package/dist-library/types/components/chart/default-chart.d.ts +7 -0
- package/dist-library/types/components/entries/else.d.ts +3 -0
- package/dist-library/types/components/layout/layout.d.ts +5 -0
- package/dist-library/types/components/shared/visuals.d.ts +1 -1
- package/dist-library/types/components/table/data-table-model.d.ts +95 -2
- package/dist-library/types/components/table/data-table.d.ts +2 -2
- package/dist-library/types/contracts/component-kernel.d.ts +5 -0
- package/dist-library/types/contracts/font-aliases.d.ts +18 -0
- package/dist-library/types/contracts/number-literal.d.ts +2 -0
- package/dist-library/types/contracts/sha256-utf16.d.ts +2 -0
- package/dist-library/types/export/index.d.ts +4 -1
- package/dist-library/types/local/compilation/compiler-choices.d.ts +4 -0
- package/dist-library/types/local/compilation/compiler-declarations.d.ts +2 -1
- package/dist-library/types/local/compilation/compiler-expressions.d.ts +12 -1
- package/dist-library/types/local/compilation/compiler-macros.d.ts +18 -0
- package/dist-library/types/local/compilation/compiler-structure.d.ts +8 -2
- package/dist-library/types/local/compilation/compiler-tables.d.ts +1 -0
- package/dist-library/types/local/compilation/compiler-validation.d.ts +11 -0
- package/dist-library/types/local/compilation/compiler-values.d.ts +1 -2
- package/dist-library/types/local/configuration/diagnostic-messages.d.ts +173 -2
- package/dist-library/types/local/configuration/diagnostic-runtime-messages.d.ts +40 -0
- package/dist-library/types/local/evaluation/choice-values.d.ts +22 -0
- package/dist-library/types/local/evaluation/computations.d.ts +13 -5
- package/dist-library/types/local/evaluation/dataset.d.ts +4 -0
- package/dist-library/types/local/evaluation/expression/collection-functions.d.ts +13 -0
- package/dist-library/types/local/evaluation/expression/compile.d.ts +11 -4
- package/dist-library/types/local/evaluation/expression/data-functions.d.ts +23 -0
- package/dist-library/types/local/evaluation/expression/evaluation.d.ts +3 -1
- package/dist-library/types/local/evaluation/expression/internal-names.d.ts +8 -0
- package/dist-library/types/local/evaluation/expression/syntax.d.ts +19 -2
- package/dist-library/types/local/evaluation/expression/transform-budget.d.ts +13 -0
- package/dist-library/types/local/evaluation/expression/values.d.ts +9 -1
- package/dist-library/types/local/evaluation/validation.d.ts +8 -6
- package/dist-library/types/local/index.d.ts +4 -3
- package/dist-library/types/local/parsing/conditional-branches.d.ts +4 -0
- package/dist-library/types/local/parsing/source-revision.d.ts +3 -0
- package/dist-library/types/local/runtime/runtime-choices.d.ts +11 -0
- package/dist-library/types/local/runtime/runtime.d.ts +3 -1
- package/dist-library/types/local/runtime/state.d.ts +30 -15
- package/dist-library/types/local/source/authoring-requirements.d.ts +3 -0
- package/dist-library/types/local/source/authoring-syntax.d.ts +3 -2
- package/dist-library/types/local/source/authoring.d.ts +10 -0
- package/dist-library/types/local/source/source-migration.d.ts +1 -0
- package/dist-library/types/local/types.d.ts +33 -2
- package/dist-library/types/react/component-api.d.ts +21 -2
- package/dist-library/types/react/component-utils.d.ts +11 -0
- package/dist-library/types/react/font-aliases.d.ts +2 -0
- package/dist-library/types/react/package-core.d.ts +3 -0
- package/dist-library/types/react/rendering/document/validation-state.d.ts +1 -1
- package/dist-library/types/react/rendering/document/view-revision.d.ts +3 -12
- package/dist-library/types/react/rendering/table/data-table.d.ts +1 -1
- package/dist-library/types/react/sdk-core.d.ts +3 -1
- package/dist-library/types/sdk/assembly.d.ts +3 -0
- package/dist-library/types/sdk/font.d.ts +13 -0
- package/dist-library/types/sdk/index.d.ts +1 -0
- package/dist-library/types/sdk/theme.d.ts +5 -0
- package/dist-library/types/sdk/types.d.ts +6 -0
- package/dist-library/types/sdk/version.d.ts +1 -1
- package/dist-library/types/shareable.d.ts +15 -3
- package/dist-library/types/standalone/prepare.d.ts +4 -2
- package/dist-library/types/standalone/session-core.d.ts +4 -1
- package/dist-library/types/vite/index.d.ts +3 -0
- package/dist-library/types/vite/registration.d.ts +1 -0
- package/dist-library/{types-Bza88SGK.js → types-B4qG8J4S.js} +1 -1
- package/dist-library/types-FYhRWRn9.js +3 -0
- package/dist-library/use-hydrated-D1gFY2Dq.js +2655 -0
- package/dist-library/validation-DRuW0Wl9.js +433 -0
- package/dist-library/{version-B0G1699c.js → version-4wzhbvDG.js} +1 -1
- package/dist-library/{visual-helpers-CRmaqCHX.js → visual-helpers-UU6xiL8g.js} +3 -3
- package/dist-library/visuals-7xzoL9ql.js +49340 -0
- package/dist-library/{worker-D6WMV8xJ.js → worker-3ldRjOEG.js} +9 -9
- package/dist-standalone/reactive-md-standalone.css +1 -1
- package/dist-standalone/reactive-md-standalone.js +128 -368
- package/docs/README-ch.md +3 -1
- package/docs/README.md +3 -1
- package/docs/compatibility/api-stability-ch.md +1 -1
- package/docs/compatibility/api-stability-en.md +1 -1
- package/docs/compatibility/compatibility-ch.md +15 -15
- package/docs/compatibility/compatibility-en.md +15 -15
- package/docs/compatibility/compatibility-manifest.schema.json +3 -2
- package/docs/compatibility/deprecation-ch.md +2 -2
- package/docs/compatibility/deprecation-en.md +2 -2
- package/docs/compatibility/source-versioning-ch.md +22 -14
- package/docs/compatibility/source-versioning-en.md +22 -13
- package/docs/compatibility/support-matrix-ch.md +4 -3
- package/docs/compatibility/support-matrix-en.md +4 -3
- package/docs/development/component-development-ch.md +2 -2
- package/docs/development/component-development-en.md +2 -2
- package/docs/development/component-protocol-ch.md +18 -18
- package/docs/development/component-protocol-en.md +14 -14
- package/docs/guides/local-guide-ch.md +109 -20
- package/docs/guides/local-guide-en.md +109 -20
- package/docs/integration/author-tools-ch.md +1 -1
- package/docs/integration/author-tools-en.md +1 -1
- package/docs/integration/editor-ch.md +3 -3
- package/docs/integration/editor-en.md +3 -3
- package/docs/integration/extension-sdk-ch.md +29 -3
- package/docs/integration/extension-sdk-en.md +29 -3
- package/docs/integration/local-integration-ch.md +3 -3
- package/docs/integration/local-integration-en.md +3 -3
- package/docs/integration/pdf-export-ch.md +42 -0
- package/docs/integration/pdf-export-en.md +42 -0
- package/docs/integration/shareable-export-ch.md +11 -19
- package/docs/integration/shareable-export-en.md +11 -19
- package/docs/reference/diagnostics-counting-ch.md +24 -1
- package/docs/reference/diagnostics-counting-en.md +24 -1
- package/docs/reference/local-interaction-syntax-ch.md +222 -33
- package/docs/reference/local-interaction-syntax-en.md +220 -31
- package/docs/reference/public-api-ch.md +24 -18
- package/docs/reference/public-api-en.md +24 -18
- package/docs/reference/theme-protocol-ch.md +1 -1
- package/docs/reference/theme-protocol-en.md +1 -1
- package/docs/releases/release-0.10.0-ch.md +45 -0
- package/docs/releases/release-0.10.0-en.md +45 -0
- package/examples/conformance/README-ch.md +3 -3
- package/examples/conformance/README.md +3 -3
- package/examples/conformance/local-draft-4.json +441 -0
- package/examples/integration/README-ch.md +3 -3
- package/examples/integration/README.md +3 -3
- package/examples/integration/chat-session/package.json +1 -1
- package/examples/local/README-ch.md +1 -1
- package/examples/local/README.md +1 -1
- package/package.json +6 -1
- package/dist-library/LocalStaticDocumentView-2J7w0sKm.js +0 -143
- package/dist-library/authoring-B14SsOXZ.js +0 -893
- package/dist-library/compile-D50B5_Ww.js +0 -1249
- package/dist-library/computations-CffoW7Ff.js +0 -340
- package/dist-library/data-table-Kv_ZA2Z2.js +0 -297
- package/dist-library/default-options-DU5dxuU6.js +0 -125
- package/dist-library/layout-BfUzzO2b.js +0 -553
- package/dist-library/runtime-CuJndKqK.js +0 -1289
- package/dist-library/shareable-C6mUerpQ.js +0 -817
- package/dist-library/types-daDo2c_w.js +0 -3
- package/dist-library/use-hydrated-W-laKPhY.js +0 -22975
- package/dist-library/visuals-CoVSjVD8.js +0 -49159
|
@@ -1,1249 +0,0 @@
|
|
|
1
|
-
import { C as e, T as t, o as n } from "./limits-CFERRrlC.js";
|
|
2
|
-
import { _ as r, l as i, o as a } from "./document-theme-DBAfnk7y.js";
|
|
3
|
-
// src/local/evaluation/expression/values.ts
|
|
4
|
-
var o = class extends Error {
|
|
5
|
-
offset;
|
|
6
|
-
code;
|
|
7
|
-
constructor(e, t, n = 0) {
|
|
8
|
-
super(t), this.name = "LocalExpressionError", this.code = e, this.offset = n;
|
|
9
|
-
}
|
|
10
|
-
}, s = /* @__PURE__ */ "abs.sqrt.floor.ceil.round.min.max.pow.sin.cos.tan.asin.acos.atan.exp.log.len.contains.clamp.sum.average.minOf.maxOf.formatNumber.formatPercent.formatScientific.formatCurrency.trim.lower.upper.startsWith.endsWith.replace.slice.dateCompare.dateDiff".split("."), c = new Set(s), l = /* @__PURE__ */ new Map([["pi", Math.PI], ["e", Math.E]]), u = /* @__PURE__ */ new Set([
|
|
11
|
-
"__proto__",
|
|
12
|
-
"prototype",
|
|
13
|
-
"constructor"
|
|
14
|
-
]), ee = /* @__PURE__ */ new Set([
|
|
15
|
-
"string",
|
|
16
|
-
"number",
|
|
17
|
-
"boolean",
|
|
18
|
-
"null",
|
|
19
|
-
"array",
|
|
20
|
-
"number-array"
|
|
21
|
-
]), te = /* @__PURE__ */ new Set([
|
|
22
|
-
...s,
|
|
23
|
-
"x",
|
|
24
|
-
"y",
|
|
25
|
-
"pi",
|
|
26
|
-
"e",
|
|
27
|
-
"true",
|
|
28
|
-
"false",
|
|
29
|
-
"null",
|
|
30
|
-
...u
|
|
31
|
-
]), ne = 4e3, d = e;
|
|
32
|
-
function f(r) {
|
|
33
|
-
if (r.length > 1e4) return {
|
|
34
|
-
code: "expression-budget",
|
|
35
|
-
...i("local.budget.value.array", { limit: n }),
|
|
36
|
-
message: `Array exceeds the ${n}-item limit.`
|
|
37
|
-
};
|
|
38
|
-
let a = null, o = 0;
|
|
39
|
-
for (let n of r) if (typeof n == "string") {
|
|
40
|
-
if (a === "number") return {
|
|
41
|
-
code: "expression-value",
|
|
42
|
-
key: "error.array.homogeneous",
|
|
43
|
-
message: "Array elements must all be strings or all be numbers."
|
|
44
|
-
};
|
|
45
|
-
if (a = "string", n.length > 1e5) return {
|
|
46
|
-
code: "expression-budget",
|
|
47
|
-
...i("local.budget.value.array-member", { limit: e }),
|
|
48
|
-
message: `Array member exceeds the ${e}-character limit.`
|
|
49
|
-
};
|
|
50
|
-
if (o += n.length, o > 1e5) return {
|
|
51
|
-
code: "expression-budget",
|
|
52
|
-
...i("local.budget.value.array-contents", { limit: t }),
|
|
53
|
-
message: `Array contents exceed the ${t}-character limit.`
|
|
54
|
-
};
|
|
55
|
-
} else if (typeof n == "number") {
|
|
56
|
-
if (a === "string") return {
|
|
57
|
-
code: "expression-value",
|
|
58
|
-
key: "error.array.homogeneous",
|
|
59
|
-
message: "Array elements must all be strings or all be numbers."
|
|
60
|
-
};
|
|
61
|
-
if (a = "number", !Number.isFinite(n)) return {
|
|
62
|
-
code: "expression-value",
|
|
63
|
-
key: "error.array.finite",
|
|
64
|
-
message: "Array members must be finite numbers."
|
|
65
|
-
};
|
|
66
|
-
} else return {
|
|
67
|
-
code: "expression-value",
|
|
68
|
-
key: "error.array.members",
|
|
69
|
-
message: "Array members must be strings or finite numbers."
|
|
70
|
-
};
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
function p(t) {
|
|
74
|
-
if (typeof t == "string") return t.length > 1e5 ? i("local.budget.value.string", { limit: e }) : null;
|
|
75
|
-
if (Array.isArray(t)) {
|
|
76
|
-
let e = f(t);
|
|
77
|
-
return e ? i(e.key, e.params) : null;
|
|
78
|
-
}
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
function m(e) {
|
|
82
|
-
let t = p(e);
|
|
83
|
-
return t ? a(t) : null;
|
|
84
|
-
}
|
|
85
|
-
// src/local/evaluation/expression/syntax.ts
|
|
86
|
-
var re = /^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/, h = /[A-Za-z_]/, ie = /[A-Za-z0-9_]/;
|
|
87
|
-
function ae(e) {
|
|
88
|
-
let t = [], n = 0;
|
|
89
|
-
for (; n < e.length;) {
|
|
90
|
-
let r = e[n];
|
|
91
|
-
if (/\s/.test(r)) {
|
|
92
|
-
n += 1;
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
if (r >= "0" && r <= "9" || r === "." && /[0-9]/.test(e[n + 1] ?? "")) {
|
|
96
|
-
let r = re.exec(e.slice(n));
|
|
97
|
-
if (!r) throw new o("expression-syntax", "Invalid number.", n);
|
|
98
|
-
let i = r[0], a = Number(i);
|
|
99
|
-
if (!Number.isFinite(a)) throw new o("expression-number", `Number must be finite: ${i}.`, n);
|
|
100
|
-
t.push({
|
|
101
|
-
kind: "number",
|
|
102
|
-
value: i,
|
|
103
|
-
start: n,
|
|
104
|
-
number: a
|
|
105
|
-
}), n += i.length;
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
if (r === "\"" || r === "'") {
|
|
109
|
-
let i = n, a = r, s = "", c = n + 1, l = !1;
|
|
110
|
-
for (; c < e.length;) {
|
|
111
|
-
let t = e[c];
|
|
112
|
-
if (t === a) {
|
|
113
|
-
l = !0, c += 1;
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
if (t === "\n" || t === "\r") throw new o("expression-string", "String literals cannot span lines.", i);
|
|
117
|
-
if (t === "\\") {
|
|
118
|
-
let t = e[c + 1];
|
|
119
|
-
if (t === void 0) break;
|
|
120
|
-
switch (t) {
|
|
121
|
-
case "\\":
|
|
122
|
-
s += "\\";
|
|
123
|
-
break;
|
|
124
|
-
case "'":
|
|
125
|
-
s += "'";
|
|
126
|
-
break;
|
|
127
|
-
case "\"":
|
|
128
|
-
s += "\"";
|
|
129
|
-
break;
|
|
130
|
-
case "n":
|
|
131
|
-
s += "\n";
|
|
132
|
-
break;
|
|
133
|
-
case "t":
|
|
134
|
-
s += " ";
|
|
135
|
-
break;
|
|
136
|
-
default: throw new o("expression-string", `Unsupported escape \\${t}.`, c);
|
|
137
|
-
}
|
|
138
|
-
c += 2;
|
|
139
|
-
} else s += t, c += 1;
|
|
140
|
-
}
|
|
141
|
-
if (!l) throw new o("expression-string", "Unterminated string literal.", i);
|
|
142
|
-
if (s.length > d) throw new o("expression-budget", "String literal exceeds the length limit.", i);
|
|
143
|
-
t.push({
|
|
144
|
-
kind: "string",
|
|
145
|
-
value: s,
|
|
146
|
-
start: i
|
|
147
|
-
}), n = c;
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
if (h.test(r)) {
|
|
151
|
-
let r = n + 1;
|
|
152
|
-
for (; r < e.length && ie.test(e[r]);) r += 1;
|
|
153
|
-
t.push({
|
|
154
|
-
kind: "ident",
|
|
155
|
-
value: e.slice(n, r),
|
|
156
|
-
start: n
|
|
157
|
-
}), n = r;
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
let i = e.slice(n, n + 2);
|
|
161
|
-
if (e.startsWith("!==", n) || e.startsWith("===", n)) throw new o("expression-syntax", `Unsupported operator ${e.slice(n, n + 3)}.`, n);
|
|
162
|
-
if (i === "==" || i === "!=" || i === "<=" || i === ">=" || i === "&&" || i === "||") t.push({
|
|
163
|
-
kind: "punct",
|
|
164
|
-
value: i,
|
|
165
|
-
start: n
|
|
166
|
-
}), n += 2;
|
|
167
|
-
else if ("+-*/%()!<>?:,[]".includes(r)) t.push({
|
|
168
|
-
kind: "punct",
|
|
169
|
-
value: r,
|
|
170
|
-
start: n
|
|
171
|
-
}), n += 1;
|
|
172
|
-
else throw r === "=" ? new o("expression-assignment", "Assignments are not supported.", n) : r === "." ? new o("expression-property", "Property access is not supported.", n) : r === "&" || r === "|" ? new o("expression-syntax", `Use ${r}${r} for logical operations.`, n) : new o("expression-syntax", `Unrecognized character "${r}".`, n);
|
|
173
|
-
}
|
|
174
|
-
return t.push({
|
|
175
|
-
kind: "eof",
|
|
176
|
-
value: "",
|
|
177
|
-
start: e.length
|
|
178
|
-
}), t;
|
|
179
|
-
}
|
|
180
|
-
var oe = {
|
|
181
|
-
abs: [1, 1],
|
|
182
|
-
sqrt: [1, 1],
|
|
183
|
-
floor: [1, 1],
|
|
184
|
-
ceil: [1, 1],
|
|
185
|
-
round: [1, 1],
|
|
186
|
-
min: [1, 2 ** 53 - 1],
|
|
187
|
-
max: [1, 2 ** 53 - 1],
|
|
188
|
-
pow: [2, 2],
|
|
189
|
-
sin: [1, 1],
|
|
190
|
-
cos: [1, 1],
|
|
191
|
-
tan: [1, 1],
|
|
192
|
-
asin: [1, 1],
|
|
193
|
-
acos: [1, 1],
|
|
194
|
-
atan: [1, 1],
|
|
195
|
-
exp: [1, 1],
|
|
196
|
-
log: [1, 1],
|
|
197
|
-
len: [1, 1],
|
|
198
|
-
contains: [2, 2],
|
|
199
|
-
clamp: [3, 3],
|
|
200
|
-
sum: [1, 1],
|
|
201
|
-
average: [1, 1],
|
|
202
|
-
minOf: [1, 1],
|
|
203
|
-
maxOf: [1, 1],
|
|
204
|
-
formatNumber: [1, 4],
|
|
205
|
-
formatPercent: [1, 3],
|
|
206
|
-
formatScientific: [1, 3],
|
|
207
|
-
formatCurrency: [1, 4],
|
|
208
|
-
trim: [1, 1],
|
|
209
|
-
lower: [1, 1],
|
|
210
|
-
upper: [1, 1],
|
|
211
|
-
startsWith: [2, 2],
|
|
212
|
-
endsWith: [2, 2],
|
|
213
|
-
replace: [3, 3],
|
|
214
|
-
slice: [2, 3],
|
|
215
|
-
dateCompare: [2, 2],
|
|
216
|
-
dateDiff: [2, 3]
|
|
217
|
-
};
|
|
218
|
-
function se(e) {
|
|
219
|
-
let t = 0, n = [{
|
|
220
|
-
node: e,
|
|
221
|
-
depth: 1
|
|
222
|
-
}];
|
|
223
|
-
for (; n.length > 0;) {
|
|
224
|
-
let { node: e, depth: r } = n.pop();
|
|
225
|
-
switch (r > t && (t = r), e.kind) {
|
|
226
|
-
case "unary":
|
|
227
|
-
n.push({
|
|
228
|
-
node: e.operand,
|
|
229
|
-
depth: r + 1
|
|
230
|
-
});
|
|
231
|
-
break;
|
|
232
|
-
case "binary":
|
|
233
|
-
n.push({
|
|
234
|
-
node: e.left,
|
|
235
|
-
depth: r + 1
|
|
236
|
-
}), n.push({
|
|
237
|
-
node: e.right,
|
|
238
|
-
depth: r + 1
|
|
239
|
-
});
|
|
240
|
-
break;
|
|
241
|
-
case "conditional":
|
|
242
|
-
n.push({
|
|
243
|
-
node: e.test,
|
|
244
|
-
depth: r + 1
|
|
245
|
-
}), n.push({
|
|
246
|
-
node: e.consequent,
|
|
247
|
-
depth: r + 1
|
|
248
|
-
}), n.push({
|
|
249
|
-
node: e.alternate,
|
|
250
|
-
depth: r + 1
|
|
251
|
-
});
|
|
252
|
-
break;
|
|
253
|
-
case "call":
|
|
254
|
-
for (let t of e.args) n.push({
|
|
255
|
-
node: t,
|
|
256
|
-
depth: r + 1
|
|
257
|
-
});
|
|
258
|
-
break;
|
|
259
|
-
case "array":
|
|
260
|
-
for (let t of e.elements) n.push({
|
|
261
|
-
node: t,
|
|
262
|
-
depth: r + 1
|
|
263
|
-
});
|
|
264
|
-
break;
|
|
265
|
-
case "index": n.push({
|
|
266
|
-
node: e.target,
|
|
267
|
-
depth: r + 1
|
|
268
|
-
}), n.push({
|
|
269
|
-
node: e.index,
|
|
270
|
-
depth: r + 1
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
return t;
|
|
275
|
-
}
|
|
276
|
-
var ce = class {
|
|
277
|
-
tokens;
|
|
278
|
-
position = 0;
|
|
279
|
-
nodeCount = 0;
|
|
280
|
-
dependencyNames = [];
|
|
281
|
-
dependencySet = /* @__PURE__ */ new Set();
|
|
282
|
-
dependencyStarts = /* @__PURE__ */ new Map();
|
|
283
|
-
constructor(e) {
|
|
284
|
-
this.tokens = ae(e);
|
|
285
|
-
}
|
|
286
|
-
get dependencies() {
|
|
287
|
-
return this.dependencyNames;
|
|
288
|
-
}
|
|
289
|
-
get dependencyOffsets() {
|
|
290
|
-
return this.dependencyStarts;
|
|
291
|
-
}
|
|
292
|
-
parse() {
|
|
293
|
-
if (this.peek().kind === "eof") throw new o("expression-empty", "Expression is empty.", 0);
|
|
294
|
-
let e = this.parseConditional(0), t = this.peek();
|
|
295
|
-
if (t.kind !== "eof") throw new o("expression-syntax", `Unexpected content "${t.value}".`, t.start);
|
|
296
|
-
if (se(e) > 200) throw new o("expression-budget", "Expression is nested too deeply.", e.start);
|
|
297
|
-
return e;
|
|
298
|
-
}
|
|
299
|
-
peek() {
|
|
300
|
-
return this.tokens[this.position];
|
|
301
|
-
}
|
|
302
|
-
next() {
|
|
303
|
-
let e = this.tokens[this.position];
|
|
304
|
-
return this.position += 1, e;
|
|
305
|
-
}
|
|
306
|
-
isPunct(e) {
|
|
307
|
-
let t = this.peek();
|
|
308
|
-
return t.kind === "punct" && t.value === e;
|
|
309
|
-
}
|
|
310
|
-
expect(e) {
|
|
311
|
-
let t = this.peek();
|
|
312
|
-
if (t.kind !== "punct" || t.value !== e) throw new o("expression-syntax", `Missing "${e}".`, t.start);
|
|
313
|
-
return this.next();
|
|
314
|
-
}
|
|
315
|
-
node(e, t, n) {
|
|
316
|
-
if (this.nodeCount += 1, this.nodeCount > 2e3) throw new o("expression-budget", "Expression is too complex.", n);
|
|
317
|
-
if (t > 100) throw new o("expression-budget", "Expression is nested too deeply.", n);
|
|
318
|
-
return e;
|
|
319
|
-
}
|
|
320
|
-
parseConditional(e) {
|
|
321
|
-
let t = this.parseOr(e);
|
|
322
|
-
if (!this.isPunct("?")) return t;
|
|
323
|
-
let n = t.start;
|
|
324
|
-
this.next();
|
|
325
|
-
let r = this.parseConditional(e + 1);
|
|
326
|
-
this.expect(":");
|
|
327
|
-
let i = this.parseConditional(e + 1);
|
|
328
|
-
return this.node({
|
|
329
|
-
kind: "conditional",
|
|
330
|
-
test: t,
|
|
331
|
-
consequent: r,
|
|
332
|
-
alternate: i,
|
|
333
|
-
start: n
|
|
334
|
-
}, e, n);
|
|
335
|
-
}
|
|
336
|
-
parseOr(e) {
|
|
337
|
-
let t = this.parseAnd(e);
|
|
338
|
-
for (; this.isPunct("||");) {
|
|
339
|
-
let n = t.start;
|
|
340
|
-
this.next();
|
|
341
|
-
let r = this.parseAnd(e);
|
|
342
|
-
t = this.node({
|
|
343
|
-
kind: "binary",
|
|
344
|
-
operator: "||",
|
|
345
|
-
left: t,
|
|
346
|
-
right: r,
|
|
347
|
-
start: n
|
|
348
|
-
}, e, n);
|
|
349
|
-
}
|
|
350
|
-
return t;
|
|
351
|
-
}
|
|
352
|
-
parseAnd(e) {
|
|
353
|
-
let t = this.parseEquality(e);
|
|
354
|
-
for (; this.isPunct("&&");) {
|
|
355
|
-
let n = t.start;
|
|
356
|
-
this.next();
|
|
357
|
-
let r = this.parseEquality(e);
|
|
358
|
-
t = this.node({
|
|
359
|
-
kind: "binary",
|
|
360
|
-
operator: "&&",
|
|
361
|
-
left: t,
|
|
362
|
-
right: r,
|
|
363
|
-
start: n
|
|
364
|
-
}, e, n);
|
|
365
|
-
}
|
|
366
|
-
return t;
|
|
367
|
-
}
|
|
368
|
-
parseEquality(e) {
|
|
369
|
-
let t = this.parseRelational(e);
|
|
370
|
-
for (; this.isPunct("==") || this.isPunct("!=");) {
|
|
371
|
-
let n = t.start, r = this.next().value, i = this.parseRelational(e);
|
|
372
|
-
t = this.node({
|
|
373
|
-
kind: "binary",
|
|
374
|
-
operator: r,
|
|
375
|
-
left: t,
|
|
376
|
-
right: i,
|
|
377
|
-
start: n
|
|
378
|
-
}, e, n);
|
|
379
|
-
}
|
|
380
|
-
return t;
|
|
381
|
-
}
|
|
382
|
-
parseRelational(e) {
|
|
383
|
-
let t = this.parseAdditive(e);
|
|
384
|
-
for (; this.isPunct("<") || this.isPunct("<=") || this.isPunct(">") || this.isPunct(">=");) {
|
|
385
|
-
let n = t.start, r = this.next().value, i = this.parseAdditive(e);
|
|
386
|
-
t = this.node({
|
|
387
|
-
kind: "binary",
|
|
388
|
-
operator: r,
|
|
389
|
-
left: t,
|
|
390
|
-
right: i,
|
|
391
|
-
start: n
|
|
392
|
-
}, e, n);
|
|
393
|
-
}
|
|
394
|
-
return t;
|
|
395
|
-
}
|
|
396
|
-
parseAdditive(e) {
|
|
397
|
-
let t = this.parseMultiplicative(e);
|
|
398
|
-
for (; this.isPunct("+") || this.isPunct("-");) {
|
|
399
|
-
let n = t.start, r = this.next().value, i = this.parseMultiplicative(e);
|
|
400
|
-
t = this.node({
|
|
401
|
-
kind: "binary",
|
|
402
|
-
operator: r,
|
|
403
|
-
left: t,
|
|
404
|
-
right: i,
|
|
405
|
-
start: n
|
|
406
|
-
}, e, n);
|
|
407
|
-
}
|
|
408
|
-
return t;
|
|
409
|
-
}
|
|
410
|
-
parseMultiplicative(e) {
|
|
411
|
-
let t = this.parseUnary(e);
|
|
412
|
-
for (; this.isPunct("*") || this.isPunct("/") || this.isPunct("%");) {
|
|
413
|
-
let n = t.start, r = this.next().value, i = this.parseUnary(e);
|
|
414
|
-
t = this.node({
|
|
415
|
-
kind: "binary",
|
|
416
|
-
operator: r,
|
|
417
|
-
left: t,
|
|
418
|
-
right: i,
|
|
419
|
-
start: n
|
|
420
|
-
}, e, n);
|
|
421
|
-
}
|
|
422
|
-
return t;
|
|
423
|
-
}
|
|
424
|
-
parseUnary(e) {
|
|
425
|
-
let t = this.peek();
|
|
426
|
-
if (t.kind === "punct" && (t.value === "-" || t.value === "+" || t.value === "!")) {
|
|
427
|
-
this.next();
|
|
428
|
-
let n = this.parseUnary(e + 1);
|
|
429
|
-
return this.node({
|
|
430
|
-
kind: "unary",
|
|
431
|
-
operator: t.value,
|
|
432
|
-
operand: n,
|
|
433
|
-
start: t.start
|
|
434
|
-
}, e, t.start);
|
|
435
|
-
}
|
|
436
|
-
return this.parsePrimary(e);
|
|
437
|
-
}
|
|
438
|
-
parsePrimary(e) {
|
|
439
|
-
let t = this.parseAtom(e);
|
|
440
|
-
for (; this.isPunct("[");) {
|
|
441
|
-
let n = t.start;
|
|
442
|
-
this.next();
|
|
443
|
-
let r = this.parseConditional(e + 1);
|
|
444
|
-
this.expect("]"), t = this.node({
|
|
445
|
-
kind: "index",
|
|
446
|
-
target: t,
|
|
447
|
-
index: r,
|
|
448
|
-
start: n
|
|
449
|
-
}, e, n);
|
|
450
|
-
}
|
|
451
|
-
return t;
|
|
452
|
-
}
|
|
453
|
-
parseAtom(e) {
|
|
454
|
-
let t = this.peek();
|
|
455
|
-
if (t.kind === "number") return this.next(), this.node({
|
|
456
|
-
kind: "literal",
|
|
457
|
-
value: t.number,
|
|
458
|
-
start: t.start
|
|
459
|
-
}, e, t.start);
|
|
460
|
-
if (t.kind === "string") return this.next(), this.node({
|
|
461
|
-
kind: "literal",
|
|
462
|
-
value: t.value,
|
|
463
|
-
start: t.start
|
|
464
|
-
}, e, t.start);
|
|
465
|
-
if (t.kind === "ident") {
|
|
466
|
-
this.next();
|
|
467
|
-
let n = t.value;
|
|
468
|
-
if (this.isPunct("(")) {
|
|
469
|
-
if (!c.has(n)) throw new o("expression-unknown-function", `Unknown function "${n}".`, t.start);
|
|
470
|
-
this.next();
|
|
471
|
-
let r = [];
|
|
472
|
-
if (!this.isPunct(")")) for (r.push(this.parseConditional(e + 1)); this.isPunct(",");) this.next(), r.push(this.parseConditional(e + 1));
|
|
473
|
-
this.expect(")");
|
|
474
|
-
let [i, a] = oe[n];
|
|
475
|
-
if (r.length < i || r.length > a) throw new o("expression-arity", `Function ${n} expects ${i === a ? `${i} ${i === 1 ? "argument" : "arguments"}` : i === 1 ? "at least one argument" : `${i}–${a} arguments`}.`, t.start);
|
|
476
|
-
return this.node({
|
|
477
|
-
kind: "call",
|
|
478
|
-
name: n,
|
|
479
|
-
args: r,
|
|
480
|
-
start: t.start
|
|
481
|
-
}, e, t.start);
|
|
482
|
-
}
|
|
483
|
-
if (n === "true" || n === "false") return this.node({
|
|
484
|
-
kind: "literal",
|
|
485
|
-
value: n === "true",
|
|
486
|
-
start: t.start
|
|
487
|
-
}, e, t.start);
|
|
488
|
-
if (n === "null") return this.node({
|
|
489
|
-
kind: "literal",
|
|
490
|
-
value: null,
|
|
491
|
-
start: t.start
|
|
492
|
-
}, e, t.start);
|
|
493
|
-
let r = l.get(n);
|
|
494
|
-
if (r !== void 0) return this.node({
|
|
495
|
-
kind: "literal",
|
|
496
|
-
value: r,
|
|
497
|
-
start: t.start
|
|
498
|
-
}, e, t.start);
|
|
499
|
-
if (u.has(n)) throw new o("expression-forbidden-name", `Name "${n}" is not allowed.`, t.start);
|
|
500
|
-
if (c.has(n)) throw new o("expression-syntax", `Function ${n} must be called with parentheses.`, t.start);
|
|
501
|
-
return this.dependencySet.has(n) || (this.dependencySet.add(n), this.dependencyNames.push(n), this.dependencyStarts.set(n, t.start)), this.node({
|
|
502
|
-
kind: "reference",
|
|
503
|
-
name: n,
|
|
504
|
-
start: t.start
|
|
505
|
-
}, e, t.start);
|
|
506
|
-
}
|
|
507
|
-
if (t.kind === "punct" && t.value === "(") {
|
|
508
|
-
this.next();
|
|
509
|
-
let t = this.parseConditional(e + 1);
|
|
510
|
-
return this.expect(")"), t;
|
|
511
|
-
}
|
|
512
|
-
if (t.kind === "punct" && t.value === "[") {
|
|
513
|
-
this.next();
|
|
514
|
-
let n = [];
|
|
515
|
-
if (!this.isPunct("]")) for (n.push(this.parseConditional(e + 1)); this.isPunct(",");) this.next(), n.push(this.parseConditional(e + 1));
|
|
516
|
-
return this.expect("]"), this.node({
|
|
517
|
-
kind: "array",
|
|
518
|
-
elements: n,
|
|
519
|
-
start: t.start
|
|
520
|
-
}, e, t.start);
|
|
521
|
-
}
|
|
522
|
-
throw new o("expression-syntax", "Expected an expression.", t.start);
|
|
523
|
-
}
|
|
524
|
-
}, g = class extends Error {
|
|
525
|
-
code;
|
|
526
|
-
constructor(e, t) {
|
|
527
|
-
super(t), this.name = "LocalFunctionError", this.code = e;
|
|
528
|
-
}
|
|
529
|
-
}, _ = [
|
|
530
|
-
"en-US",
|
|
531
|
-
"zh-CN",
|
|
532
|
-
"de-DE",
|
|
533
|
-
"fr-FR",
|
|
534
|
-
"ja-JP"
|
|
535
|
-
], le = new Set(_), ue = /^[A-Z]{3}$/, v = 20, de = { signDisplay: "negative" };
|
|
536
|
-
function y(e) {
|
|
537
|
-
throw new g("expression-domain", e);
|
|
538
|
-
}
|
|
539
|
-
function b(t, n) {
|
|
540
|
-
if (t.length > 1e5) throw new g("expression-budget", `${n} exceeds the ${e}-character limit.`);
|
|
541
|
-
return t;
|
|
542
|
-
}
|
|
543
|
-
function x(e) {
|
|
544
|
-
return le.has(e) || y(`Unsupported locale "${e}"; expected one of ${_.join(", ")}.`), e;
|
|
545
|
-
}
|
|
546
|
-
function S(e, t) {
|
|
547
|
-
return (!Number.isInteger(e) || e < 0 || e > v) && y(`${t} digits must be an integer from 0 to ${v}.`), e;
|
|
548
|
-
}
|
|
549
|
-
function C(e) {
|
|
550
|
-
if (!Number.isFinite(e)) throw new g("expression-number", "Value must be a finite number.");
|
|
551
|
-
return e;
|
|
552
|
-
}
|
|
553
|
-
function w(e, t, n, r, i) {
|
|
554
|
-
let a;
|
|
555
|
-
try {
|
|
556
|
-
a = new Intl.NumberFormat(e, {
|
|
557
|
-
...t,
|
|
558
|
-
...de
|
|
559
|
-
});
|
|
560
|
-
} catch {
|
|
561
|
-
a = void 0;
|
|
562
|
-
}
|
|
563
|
-
return a === void 0 && y(i), b(a.format(n), r);
|
|
564
|
-
}
|
|
565
|
-
function fe(e, t = 2, n = "en-US", r = !0) {
|
|
566
|
-
let i = x(n), a = S(t, "formatNumber");
|
|
567
|
-
return typeof r != "boolean" && y("formatNumber grouping must be a boolean."), e === null ? "" : w(i, {
|
|
568
|
-
useGrouping: r,
|
|
569
|
-
minimumFractionDigits: a,
|
|
570
|
-
maximumFractionDigits: a,
|
|
571
|
-
roundingMode: "halfExpand"
|
|
572
|
-
}, C(e), "Formatted number", `Cannot format a number for locale "${i}".`);
|
|
573
|
-
}
|
|
574
|
-
function pe(e, t = 0, n = "en-US") {
|
|
575
|
-
let r = x(n), i = S(t, "formatPercent");
|
|
576
|
-
return e === null ? "" : w(r, {
|
|
577
|
-
style: "percent",
|
|
578
|
-
minimumFractionDigits: i,
|
|
579
|
-
maximumFractionDigits: i,
|
|
580
|
-
roundingMode: "halfExpand"
|
|
581
|
-
}, C(e), "Formatted percentage", `Cannot format a percentage for locale "${r}".`);
|
|
582
|
-
}
|
|
583
|
-
function me(e, t = 2, n = "en-US") {
|
|
584
|
-
let r = x(n), i = S(t, "formatScientific");
|
|
585
|
-
return e === null ? "" : w(r, {
|
|
586
|
-
notation: "scientific",
|
|
587
|
-
minimumFractionDigits: i,
|
|
588
|
-
maximumFractionDigits: i,
|
|
589
|
-
roundingMode: "halfExpand"
|
|
590
|
-
}, C(e), "Formatted number", `Cannot format a number for locale "${r}".`);
|
|
591
|
-
}
|
|
592
|
-
function he(e, t = "USD", n = 2, r = "en-US") {
|
|
593
|
-
let i = x(r);
|
|
594
|
-
ue.test(t) || y(`Currency "${t}" must be a three-letter uppercase code such as "USD".`);
|
|
595
|
-
let a = S(n, "formatCurrency");
|
|
596
|
-
return e === null ? "" : w(i, {
|
|
597
|
-
style: "currency",
|
|
598
|
-
currency: t,
|
|
599
|
-
minimumFractionDigits: a,
|
|
600
|
-
maximumFractionDigits: a,
|
|
601
|
-
roundingMode: "halfExpand"
|
|
602
|
-
}, C(e), "Formatted currency", `Currency code "${t}" is not accepted by Intl.`);
|
|
603
|
-
}
|
|
604
|
-
// src/local/evaluation/expression/inference.ts
|
|
605
|
-
function T(e) {
|
|
606
|
-
switch (e) {
|
|
607
|
-
case "string": return "string";
|
|
608
|
-
case "number": return "number";
|
|
609
|
-
case "boolean": return "boolean";
|
|
610
|
-
case "null": return "null";
|
|
611
|
-
case "array": return "array";
|
|
612
|
-
case "number-array": return "number array";
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
function E(e) {
|
|
616
|
-
return e === null ? "null" : Array.isArray(e) ? "array" : typeof e == "boolean" ? "boolean" : typeof e == "number" ? "number" : "string";
|
|
617
|
-
}
|
|
618
|
-
function D(e, t) {
|
|
619
|
-
throw new o("expression-type", e, t);
|
|
620
|
-
}
|
|
621
|
-
function O(e, t, n, r) {
|
|
622
|
-
e !== t && D(`${r}, got ${T(e)}.`, n);
|
|
623
|
-
}
|
|
624
|
-
function ge(e, t) {
|
|
625
|
-
return e === t ? e : e === "null" ? t : t === "null" ? e : null;
|
|
626
|
-
}
|
|
627
|
-
function k(e, t) {
|
|
628
|
-
switch (e.kind) {
|
|
629
|
-
case "literal": return E(e.value);
|
|
630
|
-
case "reference": {
|
|
631
|
-
if (typeof t != "object" || !t || !Object.prototype.hasOwnProperty.call(t, e.name)) throw new o("expression-unknown-name", `Variable "${e.name}" is not declared.`, e.start);
|
|
632
|
-
let n = t[e.name];
|
|
633
|
-
if (typeof n != "string" || !ee.has(n)) throw new o("expression-value", `Variable "${e.name}" has an invalid type.`, e.start);
|
|
634
|
-
return n;
|
|
635
|
-
}
|
|
636
|
-
case "unary": {
|
|
637
|
-
let n = k(e.operand, t);
|
|
638
|
-
return e.operator === "!" ? (O(n, "boolean", e.start, "Logical not requires a boolean"), "boolean") : (O(n, "number", e.start, `Unary ${e.operator} requires a number`), "number");
|
|
639
|
-
}
|
|
640
|
-
case "binary": {
|
|
641
|
-
let n = k(e.left, t), r = k(e.right, t);
|
|
642
|
-
switch (e.operator) {
|
|
643
|
-
case "+": return n === "number" && r === "number" ? "number" : n === "string" && r === "string" ? "string" : D(`Operator "+" requires two numbers or two strings, got ${T(n)} and ${T(r)}.`, e.start);
|
|
644
|
-
case "-":
|
|
645
|
-
case "*":
|
|
646
|
-
case "/":
|
|
647
|
-
case "%": return O(n, "number", e.start, `Operator "${e.operator}" requires a number`), O(r, "number", e.start, `Operator "${e.operator}" requires a number`), "number";
|
|
648
|
-
case "<":
|
|
649
|
-
case "<=":
|
|
650
|
-
case ">":
|
|
651
|
-
case ">=": return n === "number" && r === "number" || n === "string" && r === "string" ? "boolean" : D(`Comparison operator "${e.operator}" requires two numbers or two strings, got ${T(n)} and ${T(r)}.`, e.start);
|
|
652
|
-
case "==":
|
|
653
|
-
case "!=": return n !== r && n !== "null" && r !== "null" ? D(`Equality comparison requires matching types, got ${T(n)} and ${T(r)}.`, e.start) : "boolean";
|
|
654
|
-
case "&&":
|
|
655
|
-
case "||": return O(n, "boolean", e.start, "Logical operators require booleans"), O(r, "boolean", e.start, "Logical operators require booleans"), "boolean";
|
|
656
|
-
}
|
|
657
|
-
break;
|
|
658
|
-
}
|
|
659
|
-
case "array": {
|
|
660
|
-
if (e.elements.length === 0) return "number-array";
|
|
661
|
-
let n = null;
|
|
662
|
-
for (let r of e.elements) {
|
|
663
|
-
let e = k(r, t);
|
|
664
|
-
if (e !== "string" && e !== "number") return D(`Array literals require string or number elements, got ${T(e)}.`, r.start);
|
|
665
|
-
if (n === null) n = e;
|
|
666
|
-
else if (n !== e) return D(`Array literals require elements of one type, got ${T(n)} and ${T(e)}.`, r.start);
|
|
667
|
-
}
|
|
668
|
-
return n === "string" ? "array" : "number-array";
|
|
669
|
-
}
|
|
670
|
-
case "index": {
|
|
671
|
-
let n = k(e.target, t);
|
|
672
|
-
return O(k(e.index, t), "number", e.start, "Array index must be a number"), n === "array" ? "string" : n === "number-array" ? "number" : D(`Index access requires an array, got ${T(n)}.`, e.start);
|
|
673
|
-
}
|
|
674
|
-
case "conditional": {
|
|
675
|
-
O(k(e.test, t), "boolean", e.start, "Conditional test must be a boolean");
|
|
676
|
-
let n = k(e.consequent, t), r = k(e.alternate, t);
|
|
677
|
-
if (n === "array" && e.alternate.kind === "array" && e.alternate.elements.length === 0 || r === "array" && e.consequent.kind === "array" && e.consequent.elements.length === 0) return "array";
|
|
678
|
-
let i = ge(n, r);
|
|
679
|
-
return i === null ? D(`Conditional branches must have matching types or one null, got ${T(n)} and ${T(r)}.`, e.start) : i;
|
|
680
|
-
}
|
|
681
|
-
case "call": {
|
|
682
|
-
let n = e.args.map((e) => k(e, t));
|
|
683
|
-
switch (e.name) {
|
|
684
|
-
case "abs":
|
|
685
|
-
case "sqrt":
|
|
686
|
-
case "floor":
|
|
687
|
-
case "ceil":
|
|
688
|
-
case "round":
|
|
689
|
-
case "sin":
|
|
690
|
-
case "cos":
|
|
691
|
-
case "tan":
|
|
692
|
-
case "asin":
|
|
693
|
-
case "acos":
|
|
694
|
-
case "atan":
|
|
695
|
-
case "exp":
|
|
696
|
-
case "log": return O(n[0], "number", e.start, `Function ${e.name} requires a number`), "number";
|
|
697
|
-
case "min":
|
|
698
|
-
case "max":
|
|
699
|
-
case "pow":
|
|
700
|
-
case "clamp":
|
|
701
|
-
for (let t of n) O(t, "number", e.start, `Function ${e.name} requires a number`);
|
|
702
|
-
return "number";
|
|
703
|
-
case "len": return n[0] !== "string" && n[0] !== "array" && n[0] !== "number-array" && D(`Function len requires a string or array, got ${T(n[0])}.`, e.start), "number";
|
|
704
|
-
case "contains":
|
|
705
|
-
if (n[0] === "number-array") return O(n[1], "number", e.start, "Function contains requires a numeric member"), "boolean";
|
|
706
|
-
if (n[0] === "string" || n[0] === "array") return O(n[1], "string", e.start, "Function contains requires a string member"), "boolean";
|
|
707
|
-
D(`Function contains requires a string or array, got ${T(n[0])}.`, e.start);
|
|
708
|
-
break;
|
|
709
|
-
case "sum":
|
|
710
|
-
case "average":
|
|
711
|
-
case "minOf":
|
|
712
|
-
case "maxOf": return O(n[0], "number-array", e.start, `Function ${e.name} requires a numeric array`), "number";
|
|
713
|
-
case "formatNumber":
|
|
714
|
-
case "formatPercent":
|
|
715
|
-
case "formatScientific": return n[0] !== "number" && n[0] !== "null" && D(`Function ${e.name} requires a number or null, got ${T(n[0])}.`, e.start), n[1] !== void 0 && O(n[1], "number", e.start, `Function ${e.name} requires numeric fraction digits`), n[2] !== void 0 && O(n[2], "string", e.start, `Function ${e.name} requires a string locale`), e.name === "formatNumber" && n[3] !== void 0 && O(n[3], "boolean", e.start, "Function formatNumber requires a boolean grouping flag"), "string";
|
|
716
|
-
case "formatCurrency": return n[0] !== "number" && n[0] !== "null" && D(`Function formatCurrency requires a number or null, got ${T(n[0])}.`, e.start), n[1] !== void 0 && O(n[1], "string", e.start, "Function formatCurrency requires a string currency code"), n[2] !== void 0 && O(n[2], "number", e.start, "Function formatCurrency requires numeric fraction digits"), n[3] !== void 0 && O(n[3], "string", e.start, "Function formatCurrency requires a string locale"), "string";
|
|
717
|
-
case "trim":
|
|
718
|
-
case "lower":
|
|
719
|
-
case "upper": return O(n[0], "string", e.start, `Function ${e.name} requires a string`), "string";
|
|
720
|
-
case "startsWith":
|
|
721
|
-
case "endsWith": return O(n[0], "string", e.start, `Function ${e.name} requires a string`), O(n[1], "string", e.start, `Function ${e.name} requires a string search value`), "boolean";
|
|
722
|
-
case "replace": return O(n[0], "string", e.start, "Function replace requires a string"), O(n[1], "string", e.start, "Function replace requires a string search value"), O(n[2], "string", e.start, "Function replace requires a string replacement"), "string";
|
|
723
|
-
case "slice": return O(n[0], "string", e.start, "Function slice requires a string"), O(n[1], "number", e.start, "Function slice requires a numeric start index"), n[2] !== void 0 && O(n[2], "number", e.start, "Function slice requires a numeric end index"), "string";
|
|
724
|
-
case "dateCompare": return O(n[0], "string", e.start, "Function dateCompare requires a date string"), O(n[1], "string", e.start, "Function dateCompare requires a date string"), "number";
|
|
725
|
-
case "dateDiff": return O(n[0], "string", e.start, "Function dateDiff requires a date string"), O(n[1], "string", e.start, "Function dateDiff requires a date string"), n[2] !== void 0 && O(n[2], "string", e.start, "Function dateDiff requires a string unit"), "number";
|
|
726
|
-
}
|
|
727
|
-
break;
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
throw new o("expression-type", "Unsupported expression.", 0);
|
|
731
|
-
}
|
|
732
|
-
// src/local/evaluation/expression/collection-functions.ts
|
|
733
|
-
function A() {
|
|
734
|
-
throw new g("expression-number", "The result is not a finite number.");
|
|
735
|
-
}
|
|
736
|
-
function j(e) {
|
|
737
|
-
if (!Number.isFinite(e)) throw new g("expression-value", "Numeric array members must be finite numbers.");
|
|
738
|
-
return e;
|
|
739
|
-
}
|
|
740
|
-
function M(e) {
|
|
741
|
-
let t = 0;
|
|
742
|
-
for (let n of e) t += j(n);
|
|
743
|
-
return Number.isFinite(t) || A(), t;
|
|
744
|
-
}
|
|
745
|
-
function _e(e) {
|
|
746
|
-
if (e.length === 0) return null;
|
|
747
|
-
let t = M(e) / e.length;
|
|
748
|
-
return Number.isFinite(t) || A(), t;
|
|
749
|
-
}
|
|
750
|
-
function N(e) {
|
|
751
|
-
if (e.length === 0) return null;
|
|
752
|
-
let t = j(e[0]);
|
|
753
|
-
for (let n = 1; n < e.length; n += 1) {
|
|
754
|
-
let r = j(e[n]);
|
|
755
|
-
r < t && (t = r);
|
|
756
|
-
}
|
|
757
|
-
return t;
|
|
758
|
-
}
|
|
759
|
-
function P(e) {
|
|
760
|
-
if (e.length === 0) return null;
|
|
761
|
-
let t = j(e[0]);
|
|
762
|
-
for (let n = 1; n < e.length; n += 1) {
|
|
763
|
-
let r = j(e[n]);
|
|
764
|
-
r > t && (t = r);
|
|
765
|
-
}
|
|
766
|
-
return t;
|
|
767
|
-
}
|
|
768
|
-
// src/local/evaluation/expression/data-functions.ts
|
|
769
|
-
function F(e) {
|
|
770
|
-
throw new g("expression-domain", e);
|
|
771
|
-
}
|
|
772
|
-
function I(e) {
|
|
773
|
-
return b(e.trim(), "trim result");
|
|
774
|
-
}
|
|
775
|
-
function ve(e) {
|
|
776
|
-
return b(e.toLowerCase(), "lower result");
|
|
777
|
-
}
|
|
778
|
-
function ye(e) {
|
|
779
|
-
return b(e.toUpperCase(), "upper result");
|
|
780
|
-
}
|
|
781
|
-
function be(e, t) {
|
|
782
|
-
return e.startsWith(t);
|
|
783
|
-
}
|
|
784
|
-
function xe(e, t) {
|
|
785
|
-
return e.endsWith(t);
|
|
786
|
-
}
|
|
787
|
-
function Se(t, n, r) {
|
|
788
|
-
n.length === 0 && F("replace search text must not be empty.");
|
|
789
|
-
let i = r.length - n.length;
|
|
790
|
-
if (i > 0) {
|
|
791
|
-
let r = 0, a = 0;
|
|
792
|
-
for (;;) {
|
|
793
|
-
let e = t.indexOf(n, a);
|
|
794
|
-
if (e < 0) break;
|
|
795
|
-
r += 1, a = e + n.length;
|
|
796
|
-
}
|
|
797
|
-
if (t.length + r * i > 1e5) throw new g("expression-budget", `replace result would exceed the ${e}-character limit.`);
|
|
798
|
-
}
|
|
799
|
-
let a = "", o = 0;
|
|
800
|
-
for (;;) {
|
|
801
|
-
let e = t.indexOf(n, o);
|
|
802
|
-
if (e < 0) break;
|
|
803
|
-
a += t.slice(o, e), a += r, o = e + n.length;
|
|
804
|
-
}
|
|
805
|
-
return a += t.slice(o), b(a, "replace result");
|
|
806
|
-
}
|
|
807
|
-
function L(e, t) {
|
|
808
|
-
return e < 0 ? Math.max(t + e, 0) : Math.min(e, t);
|
|
809
|
-
}
|
|
810
|
-
function Ce(e, t, n) {
|
|
811
|
-
Number.isInteger(t) || F("slice start must be an integer."), n !== void 0 && !Number.isInteger(n) && F("slice end must be an integer.");
|
|
812
|
-
let r = Array.from(e), i = r.length, a = L(t, i), o = n === void 0 ? i : L(n, i);
|
|
813
|
-
return o <= a ? "" : b(r.slice(a, o).join(""), "slice result");
|
|
814
|
-
}
|
|
815
|
-
var we = /* @__PURE__ */ new Map([
|
|
816
|
-
["days", 864e5],
|
|
817
|
-
["hours", 36e5],
|
|
818
|
-
["minutes", 6e4],
|
|
819
|
-
["seconds", 1e3],
|
|
820
|
-
["milliseconds", 1]
|
|
821
|
-
]), Te = "days, hours, minutes, seconds or milliseconds";
|
|
822
|
-
function R(e) {
|
|
823
|
-
let t = Oe(e);
|
|
824
|
-
if (t === null) throw new g("expression-domain", `Date "${e}" must be a valid YYYY-MM-DD calendar date in years 0001-9999.`);
|
|
825
|
-
return t;
|
|
826
|
-
}
|
|
827
|
-
function Ee(e, t) {
|
|
828
|
-
let n = R(e), r = R(t);
|
|
829
|
-
return n === r ? 0 : n < r ? -1 : 1;
|
|
830
|
-
}
|
|
831
|
-
function De(e, t, n = "days") {
|
|
832
|
-
let r = we.get(n);
|
|
833
|
-
return r === void 0 && F(`dateDiff unit must be ${Te}.`), (R(e) - R(t)) / r;
|
|
834
|
-
}
|
|
835
|
-
function Oe(e) {
|
|
836
|
-
let t = /^(\d{4})-(\d{2})-(\d{2})$/.exec(e);
|
|
837
|
-
if (!t) return null;
|
|
838
|
-
let n = Number(t[1]), r = Number(t[2]), i = Number(t[3]);
|
|
839
|
-
if (n < 1 || r < 1 || r > 12 || i < 1 || i > 31) return null;
|
|
840
|
-
let a = /* @__PURE__ */ new Date(0);
|
|
841
|
-
return a.setUTCFullYear(n, r - 1, i), a.getUTCFullYear() === n && a.getUTCMonth() === r - 1 && a.getUTCDate() === i ? a.getTime() : null;
|
|
842
|
-
}
|
|
843
|
-
// src/local/evaluation/expression/evaluation.ts
|
|
844
|
-
function z(e, t, n = "expression-eval") {
|
|
845
|
-
throw new o(n, e, t);
|
|
846
|
-
}
|
|
847
|
-
function ke(e) {
|
|
848
|
-
if (typeof e != "object" || !e || Array.isArray(e)) throw new o("expression-value", "Expression environment must be an object.", 0);
|
|
849
|
-
}
|
|
850
|
-
function Ae(e, t, n) {
|
|
851
|
-
if (e === null) return null;
|
|
852
|
-
if (typeof e == "string") {
|
|
853
|
-
let r = m(e);
|
|
854
|
-
if (r) throw new o("expression-budget", `Variable "${t}": ${r}`, n);
|
|
855
|
-
return e;
|
|
856
|
-
}
|
|
857
|
-
if (typeof e == "boolean") return e;
|
|
858
|
-
if (typeof e == "number") {
|
|
859
|
-
if (!Number.isFinite(e)) throw new o("expression-value", `Variable "${t}" must be a finite number.`, n);
|
|
860
|
-
return e;
|
|
861
|
-
}
|
|
862
|
-
if (Array.isArray(e)) {
|
|
863
|
-
let r = f(e);
|
|
864
|
-
if (r) throw new o(r.code, `Variable "${t}": ${r.message}`, n);
|
|
865
|
-
return e;
|
|
866
|
-
}
|
|
867
|
-
throw new o("expression-value", `Variable "${t}" has an invalid value type.`, n);
|
|
868
|
-
}
|
|
869
|
-
function je(e, t, n) {
|
|
870
|
-
return ke(e), Object.prototype.hasOwnProperty.call(e, t) || z(`Variable "${t}" is not declared.`, n, "expression-unknown-name"), Ae(e[t], t, n);
|
|
871
|
-
}
|
|
872
|
-
function B(e, t, n = "Expected a number") {
|
|
873
|
-
return typeof e == "number" && Number.isFinite(e) || z(`${n}.`, t, "expression-type"), e;
|
|
874
|
-
}
|
|
875
|
-
function V(e, t, n = "Expected a boolean") {
|
|
876
|
-
return typeof e != "boolean" && z(`${n}.`, t, "expression-type"), e;
|
|
877
|
-
}
|
|
878
|
-
function H(e, t, n = "Expected a string") {
|
|
879
|
-
return typeof e != "string" && z(`${n}.`, t, "expression-type"), e;
|
|
880
|
-
}
|
|
881
|
-
function U(e, t, n) {
|
|
882
|
-
Array.isArray(e) || z(`${n}.`, t, "expression-type");
|
|
883
|
-
for (let r of e) typeof r == "number" && Number.isFinite(r) || z(`${n}.`, t, "expression-type");
|
|
884
|
-
return e;
|
|
885
|
-
}
|
|
886
|
-
function Me(e, t) {
|
|
887
|
-
let n = f(e);
|
|
888
|
-
return n && z(n.message, t, n.code), e;
|
|
889
|
-
}
|
|
890
|
-
function W(e, t) {
|
|
891
|
-
try {
|
|
892
|
-
return t();
|
|
893
|
-
} catch (t) {
|
|
894
|
-
throw t instanceof g ? new o(t.code, t.message, e) : t;
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
function G(e, t) {
|
|
898
|
-
return Number.isNaN(e) && z("The result is undefined.", t, "expression-domain"), Number.isFinite(e) || z("The result is not a finite number.", t, "expression-number"), e;
|
|
899
|
-
}
|
|
900
|
-
function Ne(e, t) {
|
|
901
|
-
let n = Array.from(e), r = Array.from(t), i = Math.min(n.length, r.length);
|
|
902
|
-
for (let e = 0; e < i; e += 1) {
|
|
903
|
-
let t = n[e].codePointAt(0), i = r[e].codePointAt(0);
|
|
904
|
-
if (t !== i) return t < i ? -1 : 1;
|
|
905
|
-
}
|
|
906
|
-
return n.length === r.length ? 0 : n.length < r.length ? -1 : 1;
|
|
907
|
-
}
|
|
908
|
-
function Pe(e, t) {
|
|
909
|
-
if (e === t) return !0;
|
|
910
|
-
if (Array.isArray(e) && Array.isArray(t)) {
|
|
911
|
-
if (e.length !== t.length) return !1;
|
|
912
|
-
for (let n = 0; n < e.length; n += 1) if (e[n] !== t[n]) return !1;
|
|
913
|
-
return !0;
|
|
914
|
-
}
|
|
915
|
-
return !1;
|
|
916
|
-
}
|
|
917
|
-
function Fe(e, t) {
|
|
918
|
-
return K(e, t, { steps: 0 }, 1);
|
|
919
|
-
}
|
|
920
|
-
function K(e, t, n, i) {
|
|
921
|
-
switch (n.steps += 1, n.steps > 1e4 && z("Expression evaluation exceeded the step limit.", e.start, "expression-budget"), i > 250 && z("Expression evaluation is nested too deeply.", e.start, "expression-budget"), e.kind) {
|
|
922
|
-
case "literal": return e.value;
|
|
923
|
-
case "reference": return je(t, e.name, e.start);
|
|
924
|
-
case "unary": {
|
|
925
|
-
let r = K(e.operand, t, n, i + 1);
|
|
926
|
-
if (e.operator === "!") return !V(r, e.start, "Logical not requires a boolean");
|
|
927
|
-
let a = B(r, e.start, `Unary ${e.operator} requires a number`);
|
|
928
|
-
return G(e.operator === "-" ? -a : a, e.start);
|
|
929
|
-
}
|
|
930
|
-
case "binary": {
|
|
931
|
-
if (e.operator === "&&" || e.operator === "||") {
|
|
932
|
-
let r = V(K(e.left, t, n, i + 1), e.start, "Logical operators require booleans");
|
|
933
|
-
return e.operator === "&&" && !r ? !1 : e.operator === "||" && r ? !0 : V(K(e.right, t, n, i + 1), e.start, "Logical operators require booleans");
|
|
934
|
-
}
|
|
935
|
-
let r = K(e.left, t, n, i + 1), a = K(e.right, t, n, i + 1);
|
|
936
|
-
switch (e.operator) {
|
|
937
|
-
case "+":
|
|
938
|
-
if (typeof r == "number" && typeof a == "number") return G(r + a, e.start);
|
|
939
|
-
if (typeof r == "string" && typeof a == "string") {
|
|
940
|
-
let t = r + a;
|
|
941
|
-
return t.length > d && z("String result exceeds the length limit.", e.start, "expression-budget"), t;
|
|
942
|
-
}
|
|
943
|
-
z("Operator \"+\" requires two numbers or two strings.", e.start, "expression-type");
|
|
944
|
-
case "-":
|
|
945
|
-
case "*":
|
|
946
|
-
case "/":
|
|
947
|
-
case "%": {
|
|
948
|
-
let t = B(r, e.start, `Operator "${e.operator}" requires a number`), n = B(a, e.start, `Operator "${e.operator}" requires a number`);
|
|
949
|
-
return (e.operator === "/" || e.operator === "%") && n === 0 && z("Division by zero.", e.start, "expression-divide-by-zero"), G(e.operator === "-" ? t - n : e.operator === "*" ? t * n : e.operator === "/" ? t / n : t % n, e.start);
|
|
950
|
-
}
|
|
951
|
-
case "==":
|
|
952
|
-
case "!=": {
|
|
953
|
-
let t = E(r), n = E(a);
|
|
954
|
-
t !== n && t !== "null" && n !== "null" && z("Equality comparison requires matching types.", e.start, "expression-type");
|
|
955
|
-
let i = Pe(r, a);
|
|
956
|
-
return e.operator === "==" ? i : !i;
|
|
957
|
-
}
|
|
958
|
-
case "<":
|
|
959
|
-
case "<=":
|
|
960
|
-
case ">":
|
|
961
|
-
case ">=": {
|
|
962
|
-
let t;
|
|
963
|
-
return typeof r == "number" && typeof a == "number" ? t = r === a ? 0 : r < a ? -1 : 1 : typeof r == "string" && typeof a == "string" ? t = Ne(r, a) : z(`Comparison operator "${e.operator}" requires two numbers or two strings.`, e.start, "expression-type"), e.operator === "<" ? t < 0 : e.operator === "<=" ? t <= 0 : e.operator === ">" ? t > 0 : t >= 0;
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
break;
|
|
967
|
-
}
|
|
968
|
-
case "conditional": return K(V(K(e.test, t, n, i + 1), e.start, "Conditional test must be a boolean") ? e.consequent : e.alternate, t, n, i + 1);
|
|
969
|
-
case "array": {
|
|
970
|
-
let r = [];
|
|
971
|
-
for (let a of e.elements) r.push(K(a, t, n, i + 1));
|
|
972
|
-
return Me(r, e.start);
|
|
973
|
-
}
|
|
974
|
-
case "index": {
|
|
975
|
-
let r = K(e.target, t, n, i + 1), a = B(K(e.index, t, n, i + 1), e.start, "Array index must be a number");
|
|
976
|
-
return Number.isSafeInteger(a) || z("Array index must be a finite integer.", e.start, "expression-index"), Array.isArray(r) || z("Index access requires an array.", e.start, "expression-type"), a < 0 || a >= r.length ? null : r[a];
|
|
977
|
-
}
|
|
978
|
-
case "call": {
|
|
979
|
-
let a = e.args.map((e) => K(e, t, n, i + 1));
|
|
980
|
-
switch (e.name) {
|
|
981
|
-
case "abs":
|
|
982
|
-
case "sqrt":
|
|
983
|
-
case "floor":
|
|
984
|
-
case "ceil":
|
|
985
|
-
case "round":
|
|
986
|
-
case "sin":
|
|
987
|
-
case "cos":
|
|
988
|
-
case "tan":
|
|
989
|
-
case "asin":
|
|
990
|
-
case "acos":
|
|
991
|
-
case "atan":
|
|
992
|
-
case "exp":
|
|
993
|
-
case "log": {
|
|
994
|
-
let t = B(a[0], e.start, `Function ${e.name} requires a number`);
|
|
995
|
-
e.name === "sqrt" && t < 0 && z("sqrt requires a non-negative argument.", e.start, "expression-domain"), e.name === "log" && t <= 0 && z("log requires a positive argument.", e.start, "expression-domain"), (e.name === "asin" || e.name === "acos") && (t < -1 || t > 1) && z(`${e.name} requires an argument between -1 and 1.`, e.start, "expression-domain");
|
|
996
|
-
let n;
|
|
997
|
-
switch (e.name) {
|
|
998
|
-
case "abs":
|
|
999
|
-
n = Math.abs(t);
|
|
1000
|
-
break;
|
|
1001
|
-
case "sqrt":
|
|
1002
|
-
n = Math.sqrt(t);
|
|
1003
|
-
break;
|
|
1004
|
-
case "floor":
|
|
1005
|
-
n = Math.floor(t);
|
|
1006
|
-
break;
|
|
1007
|
-
case "ceil":
|
|
1008
|
-
n = Math.ceil(t);
|
|
1009
|
-
break;
|
|
1010
|
-
case "round":
|
|
1011
|
-
n = Math.round(t);
|
|
1012
|
-
break;
|
|
1013
|
-
case "sin":
|
|
1014
|
-
n = Math.sin(t);
|
|
1015
|
-
break;
|
|
1016
|
-
case "cos":
|
|
1017
|
-
n = Math.cos(t);
|
|
1018
|
-
break;
|
|
1019
|
-
case "tan":
|
|
1020
|
-
n = Math.tan(t);
|
|
1021
|
-
break;
|
|
1022
|
-
case "asin":
|
|
1023
|
-
n = Math.asin(t);
|
|
1024
|
-
break;
|
|
1025
|
-
case "acos":
|
|
1026
|
-
n = Math.acos(t);
|
|
1027
|
-
break;
|
|
1028
|
-
case "atan":
|
|
1029
|
-
n = Math.atan(t);
|
|
1030
|
-
break;
|
|
1031
|
-
case "exp":
|
|
1032
|
-
n = Math.exp(t);
|
|
1033
|
-
break;
|
|
1034
|
-
default: n = Math.log(t);
|
|
1035
|
-
}
|
|
1036
|
-
return G(n, e.start);
|
|
1037
|
-
}
|
|
1038
|
-
case "min":
|
|
1039
|
-
case "max": {
|
|
1040
|
-
let t = B(a[0], e.start, `Function ${e.name} requires a number`);
|
|
1041
|
-
for (let n = 1; n < a.length; n += 1) {
|
|
1042
|
-
let r = B(a[n], e.start, `Function ${e.name} requires a number`);
|
|
1043
|
-
t = e.name === "min" ? Math.min(t, r) : Math.max(t, r);
|
|
1044
|
-
}
|
|
1045
|
-
return G(t, e.start);
|
|
1046
|
-
}
|
|
1047
|
-
case "pow": return G(B(a[0], e.start, "Function pow requires a number") ** +B(a[1], e.start, "Function pow requires a number"), e.start);
|
|
1048
|
-
case "clamp": {
|
|
1049
|
-
let t = B(a[0], e.start, "Function clamp requires a number"), n = B(a[1], e.start, "Function clamp requires a number"), r = B(a[2], e.start, "Function clamp requires a number");
|
|
1050
|
-
return n > r && z("clamp lower bound cannot exceed upper bound.", e.start, "expression-domain"), G(Math.min(r, Math.max(n, t)), e.start);
|
|
1051
|
-
}
|
|
1052
|
-
case "len": {
|
|
1053
|
-
let t = a[0];
|
|
1054
|
-
if (typeof t == "string") return r(t);
|
|
1055
|
-
if (Array.isArray(t)) return t.length;
|
|
1056
|
-
z("Function len requires a string or array.", e.start, "expression-type");
|
|
1057
|
-
}
|
|
1058
|
-
case "contains": {
|
|
1059
|
-
let t = a[0], n = a[1];
|
|
1060
|
-
if (typeof t == "string") return t.includes(H(n, e.start, "Function contains requires a string member"));
|
|
1061
|
-
if (Array.isArray(t)) {
|
|
1062
|
-
if (typeof n == "string") {
|
|
1063
|
-
for (let n of t) typeof n != "string" && z("Function contains requires a string member for a string array.", e.start, "expression-type");
|
|
1064
|
-
return t.includes(n);
|
|
1065
|
-
}
|
|
1066
|
-
if (typeof n == "number" && Number.isFinite(n)) {
|
|
1067
|
-
for (let n of t) typeof n != "number" && z("Function contains requires a numeric member for a numeric array.", e.start, "expression-type");
|
|
1068
|
-
return t.includes(n);
|
|
1069
|
-
}
|
|
1070
|
-
z("Function contains requires a string or numeric member.", e.start, "expression-type");
|
|
1071
|
-
}
|
|
1072
|
-
z("Function contains requires a string or array.", e.start, "expression-type");
|
|
1073
|
-
}
|
|
1074
|
-
case "sum": {
|
|
1075
|
-
let t = U(a[0], e.start, "Function sum requires a numeric array");
|
|
1076
|
-
return W(e.start, () => M(t));
|
|
1077
|
-
}
|
|
1078
|
-
case "average": {
|
|
1079
|
-
let t = U(a[0], e.start, "Function average requires a numeric array");
|
|
1080
|
-
return W(e.start, () => _e(t));
|
|
1081
|
-
}
|
|
1082
|
-
case "minOf": {
|
|
1083
|
-
let t = U(a[0], e.start, "Function minOf requires a numeric array");
|
|
1084
|
-
return W(e.start, () => N(t));
|
|
1085
|
-
}
|
|
1086
|
-
case "maxOf": {
|
|
1087
|
-
let t = U(a[0], e.start, "Function maxOf requires a numeric array");
|
|
1088
|
-
return W(e.start, () => P(t));
|
|
1089
|
-
}
|
|
1090
|
-
case "formatNumber": {
|
|
1091
|
-
let t = a[0] === null ? null : B(a[0], e.start, "Function formatNumber requires a number or null"), n = a[1] === void 0 ? 2 : B(a[1], e.start, "Function formatNumber requires numeric fraction digits"), r = a[2] === void 0 ? "en-US" : H(a[2], e.start, "Function formatNumber requires a string locale"), i = a[3] === void 0 || V(a[3], e.start, "Function formatNumber requires a boolean grouping flag");
|
|
1092
|
-
return W(e.start, () => fe(t, n, r, i));
|
|
1093
|
-
}
|
|
1094
|
-
case "formatPercent": {
|
|
1095
|
-
let t = a[0] === null ? null : B(a[0], e.start, "Function formatPercent requires a number or null"), n = a[1] === void 0 ? 0 : B(a[1], e.start, "Function formatPercent requires numeric fraction digits"), r = a[2] === void 0 ? "en-US" : H(a[2], e.start, "Function formatPercent requires a string locale");
|
|
1096
|
-
return W(e.start, () => pe(t, n, r));
|
|
1097
|
-
}
|
|
1098
|
-
case "formatScientific": {
|
|
1099
|
-
let t = a[0] === null ? null : B(a[0], e.start, "Function formatScientific requires a number or null"), n = a[1] === void 0 ? 2 : B(a[1], e.start, "Function formatScientific requires numeric fraction digits"), r = a[2] === void 0 ? "en-US" : H(a[2], e.start, "Function formatScientific requires a string locale");
|
|
1100
|
-
return W(e.start, () => me(t, n, r));
|
|
1101
|
-
}
|
|
1102
|
-
case "formatCurrency": {
|
|
1103
|
-
let t = a[0] === null ? null : B(a[0], e.start, "Function formatCurrency requires a number or null"), n = a[1] === void 0 ? "USD" : H(a[1], e.start, "Function formatCurrency requires a string currency code"), r = a[2] === void 0 ? 2 : B(a[2], e.start, "Function formatCurrency requires numeric fraction digits"), i = a[3] === void 0 ? "en-US" : H(a[3], e.start, "Function formatCurrency requires a string locale");
|
|
1104
|
-
return W(e.start, () => he(t, n, r, i));
|
|
1105
|
-
}
|
|
1106
|
-
case "trim": return W(e.start, () => I(H(a[0], e.start, "Function trim requires a string")));
|
|
1107
|
-
case "lower": return W(e.start, () => ve(H(a[0], e.start, "Function lower requires a string")));
|
|
1108
|
-
case "upper": return W(e.start, () => ye(H(a[0], e.start, "Function upper requires a string")));
|
|
1109
|
-
case "startsWith": return W(e.start, () => be(H(a[0], e.start, "Function startsWith requires a string"), H(a[1], e.start, "Function startsWith requires a string search value")));
|
|
1110
|
-
case "endsWith": return W(e.start, () => xe(H(a[0], e.start, "Function endsWith requires a string"), H(a[1], e.start, "Function endsWith requires a string search value")));
|
|
1111
|
-
case "replace": {
|
|
1112
|
-
let t = H(a[0], e.start, "Function replace requires a string"), n = H(a[1], e.start, "Function replace requires a string search value"), r = H(a[2], e.start, "Function replace requires a string replacement");
|
|
1113
|
-
return W(e.start, () => Se(t, n, r));
|
|
1114
|
-
}
|
|
1115
|
-
case "slice": {
|
|
1116
|
-
let t = H(a[0], e.start, "Function slice requires a string"), n = B(a[1], e.start, "Function slice requires a numeric start index"), r = a[2] === void 0 ? void 0 : B(a[2], e.start, "Function slice requires a numeric end index");
|
|
1117
|
-
return W(e.start, () => Ce(t, n, r));
|
|
1118
|
-
}
|
|
1119
|
-
case "dateCompare": {
|
|
1120
|
-
let t = H(a[0], e.start, "Function dateCompare requires a date string"), n = H(a[1], e.start, "Function dateCompare requires a date string");
|
|
1121
|
-
return W(e.start, () => Ee(t, n));
|
|
1122
|
-
}
|
|
1123
|
-
case "dateDiff": {
|
|
1124
|
-
let t = H(a[0], e.start, "Function dateDiff requires a date string"), n = H(a[1], e.start, "Function dateDiff requires a date string"), r = a[2] === void 0 ? "days" : H(a[2], e.start, "Function dateDiff requires a string unit");
|
|
1125
|
-
return W(e.start, () => De(t, n, r));
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
break;
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
throw new o("expression-eval", "Unsupported expression.", 0);
|
|
1132
|
-
}
|
|
1133
|
-
// src/local/evaluation/expression/compile.ts
|
|
1134
|
-
var q = e, Ie = 500, J = /* @__PURE__ */ new Map(), Y = /* @__PURE__ */ new WeakMap();
|
|
1135
|
-
function Le(e, t) {
|
|
1136
|
-
return Y.get(e)?.get(t);
|
|
1137
|
-
}
|
|
1138
|
-
function X(e) {
|
|
1139
|
-
if (typeof e != "string") throw new o("expression-syntax", "Expression must be a string.", 0);
|
|
1140
|
-
if (e.length > 4e3) throw new o("expression-budget", `Expression exceeds the ${ne}-character limit.`, 0);
|
|
1141
|
-
let t = J.get(e);
|
|
1142
|
-
if (t) return t;
|
|
1143
|
-
let n = new ce(e), r = n.parse(), i = [...n.dependencies], a = Object.freeze({
|
|
1144
|
-
source: e,
|
|
1145
|
-
dependencies: i,
|
|
1146
|
-
evaluate(e) {
|
|
1147
|
-
return Fe(r, e);
|
|
1148
|
-
},
|
|
1149
|
-
inferType(e) {
|
|
1150
|
-
return k(r, e);
|
|
1151
|
-
}
|
|
1152
|
-
});
|
|
1153
|
-
if (J.size >= Ie) {
|
|
1154
|
-
let e = J.keys().next().value;
|
|
1155
|
-
e !== void 0 && J.delete(e);
|
|
1156
|
-
}
|
|
1157
|
-
return Y.set(a, n.dependencyOffsets), J.set(e, a), a;
|
|
1158
|
-
}
|
|
1159
|
-
function Z(e) {
|
|
1160
|
-
if (e.length > q) throw new o("expression-budget", "Interpolation template exceeds the length limit.", 0);
|
|
1161
|
-
let t = [], n = 0;
|
|
1162
|
-
for (;;) {
|
|
1163
|
-
let r = e.indexOf("{{", n);
|
|
1164
|
-
if (r < 0) {
|
|
1165
|
-
n < e.length && t.push({
|
|
1166
|
-
kind: "text",
|
|
1167
|
-
value: e.slice(n)
|
|
1168
|
-
});
|
|
1169
|
-
break;
|
|
1170
|
-
}
|
|
1171
|
-
r > n && t.push({
|
|
1172
|
-
kind: "text",
|
|
1173
|
-
value: e.slice(n, r)
|
|
1174
|
-
});
|
|
1175
|
-
let i = r + 2, a = "", s = !1;
|
|
1176
|
-
for (; i < e.length;) {
|
|
1177
|
-
let t = e[i];
|
|
1178
|
-
if (a !== "") {
|
|
1179
|
-
if (t === "\\") {
|
|
1180
|
-
i += 2;
|
|
1181
|
-
continue;
|
|
1182
|
-
}
|
|
1183
|
-
t === a && (a = ""), i += 1;
|
|
1184
|
-
} else if (t === "\"" || t === "'") a = t, i += 1;
|
|
1185
|
-
else {
|
|
1186
|
-
if (t === "{" && e[i + 1] === "{") throw new o("expression-interpolation", "Interpolations cannot be nested.", i);
|
|
1187
|
-
if (t === "}" && e[i + 1] === "}") {
|
|
1188
|
-
s = !0;
|
|
1189
|
-
break;
|
|
1190
|
-
}
|
|
1191
|
-
i += 1;
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
if (!s) throw new o("expression-interpolation", "Interpolation is missing }}.", r);
|
|
1195
|
-
let c = e.slice(r + 2, i);
|
|
1196
|
-
if (c.trim() === "") throw new o("expression-empty", "Interpolation expression is empty.", r + 2);
|
|
1197
|
-
t.push({
|
|
1198
|
-
kind: "expression",
|
|
1199
|
-
source: c,
|
|
1200
|
-
start: r + 2
|
|
1201
|
-
}), n = i + 2;
|
|
1202
|
-
}
|
|
1203
|
-
return t;
|
|
1204
|
-
}
|
|
1205
|
-
function Q(e) {
|
|
1206
|
-
try {
|
|
1207
|
-
return X(e.source);
|
|
1208
|
-
} catch (t) {
|
|
1209
|
-
throw t instanceof o ? new o(t.code, t.message, e.start + t.offset) : t;
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
function $(e, t, n) {
|
|
1213
|
-
try {
|
|
1214
|
-
return e.evaluate(t);
|
|
1215
|
-
} catch (e) {
|
|
1216
|
-
throw e instanceof o ? new o(e.code, e.message, n + e.offset) : e;
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
function Re(e, t) {
|
|
1220
|
-
if (e === null) return "";
|
|
1221
|
-
if (typeof e == "string") return e;
|
|
1222
|
-
if (typeof e == "number") {
|
|
1223
|
-
if (!Number.isFinite(e)) throw new o("expression-value", "Cannot display a non-finite number.", t);
|
|
1224
|
-
return String(e);
|
|
1225
|
-
}
|
|
1226
|
-
if (typeof e == "boolean") return e ? "true" : "false";
|
|
1227
|
-
throw Array.isArray(e) ? new o("expression-type", "Cannot insert an array as text; convert it with a function such as len first.", t) : new o("expression-type", "Cannot display this value as text.", t);
|
|
1228
|
-
}
|
|
1229
|
-
function ze(e, t) {
|
|
1230
|
-
let n = [], r = 0;
|
|
1231
|
-
for (let i of e) {
|
|
1232
|
-
let e;
|
|
1233
|
-
if (e = i.kind === "text" ? i.value : Re($(Q(i), t, i.start), i.start), r += e.length, r > d) throw new o("expression-budget", "Interpolation result exceeds the length limit.", 0);
|
|
1234
|
-
n.push(e);
|
|
1235
|
-
}
|
|
1236
|
-
return n.join("");
|
|
1237
|
-
}
|
|
1238
|
-
function Be(e, t) {
|
|
1239
|
-
if (typeof e != "string") throw new o("expression-interpolation", "Interpolation template must be a string.", 0);
|
|
1240
|
-
if (e.length > q) throw new o("expression-budget", `Interpolation template exceeds the ${q}-character limit.`, 0);
|
|
1241
|
-
return e.includes("{{") ? ze(Z(e), t) : e;
|
|
1242
|
-
}
|
|
1243
|
-
function Ve(e) {
|
|
1244
|
-
if (typeof e != "string") throw new o("expression-interpolation", "Interpolation template must be a string.", 0);
|
|
1245
|
-
let t = /* @__PURE__ */ new Set();
|
|
1246
|
-
for (let n of Z(e)) if (n.kind === "expression") for (let e of Q(n).dependencies) t.add(e);
|
|
1247
|
-
return [...t];
|
|
1248
|
-
}
|
|
1249
|
-
export { o as a, p as c, Ve as i, Le as n, te as o, Be as r, m as s, X as t };
|