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.
Files changed (299) hide show
  1. package/CHANGELOG-ch.md +34 -0
  2. package/CHANGELOG.md +34 -0
  3. package/README-ch.md +7 -7
  4. package/README-en.md +7 -7
  5. package/README.md +7 -7
  6. package/THIRD_PARTY_NOTICES.md +0 -57
  7. package/cli/help.mjs +6 -4
  8. package/cli/init.mjs +1 -1
  9. package/cli/migrate.mjs +1 -1
  10. package/dist-library/{LocalDocumentView-D6zQkTkt.js → LocalDocumentView-CP2QG86k.js} +46 -44
  11. package/dist-library/{LocalDocumentViewCore-CmJhemcA.js → LocalDocumentViewCore-Cd6yMEkg.js} +284 -265
  12. package/dist-library/{LocalReactiveDocumentCore-lAKOGAZ7.js → LocalReactiveDocumentCore-VuYpZqdn.js} +7 -7
  13. package/dist-library/LocalStaticDocumentView-DfX6bemE.js +147 -0
  14. package/dist-library/authoring-Bwu_zCWs.js +768 -0
  15. package/dist-library/choice-values-BItGjPD2.js +58 -0
  16. package/dist-library/compile-B35rfzKr.js +1742 -0
  17. package/dist-library/{compile-cache-key-6GgpETz_.js → compile-cache-key-D21X2Obx.js} +5 -5
  18. package/dist-library/{compiler-DLkKUK4t.js → compiler-DBwLawMZ.js} +4 -4
  19. package/dist-library/{compiler-core-Niqhp9wV.js → compiler-core-kkDiQ1RK.js} +3146 -2055
  20. package/dist-library/{component-kernel-IG4wOO0i.js → component-kernel-CsJSabHX.js} +42 -26
  21. package/dist-library/{component-state-Ht-hOK0W.js → component-state-Da0G8Ajc.js} +1 -1
  22. package/dist-library/{component-utils-eSj5IdG4.js → component-utils-ZM3jUJNy.js} +80 -79
  23. package/dist-library/conditional-branches-CIhJXasR.js +17 -0
  24. package/dist-library/{config-validation-Cpol91_M.js → config-validation-DbmsWAEV.js} +165 -152
  25. package/dist-library/{controls-B-CLSK8Q.js → controls-DRy5rzzN.js} +271 -228
  26. package/dist-library/{coordinate-PyLPMIQK.js → coordinate-c54pHfgf.js} +29 -29
  27. package/dist-library/data-table-CSAkm1eU.js +290 -0
  28. package/dist-library/data-table-model-DruztQFt.js +391 -0
  29. package/dist-library/{data-visuals-_Z7QqYTk.js → data-visuals-rZQUeQM0.js} +14 -14
  30. package/dist-library/{default-components-jugH7Ubr.js → default-components-B-39etG9.js} +233 -71
  31. package/dist-library/{default-config-DIrRpuQz.js → default-config-CCa8rm2k.js} +236 -216
  32. package/dist-library/default-options-By16CVw1.js +131 -0
  33. package/dist-library/{default-registry-BlloaZi7.js → default-registry-DXJy66xj.js} +3 -3
  34. package/dist-library/{default-schema-Ch-Vznpm.js → default-schema-CeYiEW1K.js} +3 -3
  35. package/dist-library/display-Bb6hAG5T.js +2065 -0
  36. package/dist-library/{document-theme-DBAfnk7y.js → document-theme-CJvN-nC1.js} +190 -3
  37. package/dist-library/{export-heVBqgxA.js → export-BSV4E0jv.js} +105 -106
  38. package/dist-library/font-aliases-CKYjwn4o.js +4 -0
  39. package/dist-library/{gallery-Q6VPS2ep.js → gallery-DM2yTVZJ.js} +1 -1
  40. package/dist-library/{html-CCnvzan1.js → html-CY9mC3Sr.js} +5 -5
  41. package/dist-library/{incremental-Bzvh8_lB.js → incremental-B-wW4H3F.js} +251 -245
  42. package/dist-library/{display-y4v9v0Qd.js → katex-4ukd4ZxT.js} +1555 -3618
  43. package/dist-library/layout-CPQggKxk.js +592 -0
  44. package/dist-library/{layout-BnfDeUNy.js → layout-CaDWsDof.js} +1 -1
  45. package/dist-library/{math-view-B0jthpRw.js → math-view-CyGTS6kv.js} +1 -1
  46. package/dist-library/{mount-preset-C_i37FvY.js → mount-preset-DtrCX4G8.js} +4 -4
  47. package/dist-library/{numeric-sliders-CkWS0-ja.js → numeric-sliders-BmJ1LCLx.js} +190 -190
  48. package/dist-library/{observability-CYLuvFfL.js → observability-BVQ16ByQ.js} +5 -4
  49. package/dist-library/{package-core-9UK5ZdqB.js → package-core-Cu_r_qs7.js} +7 -6
  50. package/dist-library/{parser-9yNJxGip.js → parser-BHl9Lxbw.js} +2 -2
  51. package/dist-library/{parser-standard-BPIy4HOu.js → parser-standard-DDAKv_DZ.js} +247 -247
  52. package/dist-library/{plugin-packs-CZb46nuv.js → plugin-packs-CkI0floL.js} +3 -3
  53. package/dist-library/{preset-core-BW3NWZJ9.js → preset-core-BKPbH_Nv.js} +377 -306
  54. package/dist-library/{props-pJRrfDc6.js → props-0iDqxlTk.js} +56 -61
  55. package/dist-library/{react-BSo0o998.js → react-74jdGBmu.js} +2 -2
  56. package/dist-library/reactive-md-authoring.js +277 -269
  57. package/dist-library/reactive-md-build.js +327 -33
  58. package/dist-library/reactive-md-compiler-session.js +3 -3
  59. package/dist-library/reactive-md-compiler-standard.js +10 -10
  60. package/dist-library/reactive-md-compiler.js +3 -3
  61. package/dist-library/reactive-md-contracts.js +4 -4
  62. package/dist-library/reactive-md-default-packs.js +4 -3
  63. package/dist-library/reactive-md-default-preset.js +3 -3
  64. package/dist-library/reactive-md-export.js +6 -6
  65. package/dist-library/reactive-md-minimal-preset.js +3 -2
  66. package/dist-library/reactive-md-minimal-react-preset.js +18 -17
  67. package/dist-library/reactive-md-minimal.css +1 -1
  68. package/dist-library/reactive-md-observability.js +2 -2
  69. package/dist-library/reactive-md-pack-style-manifest.js +8 -0
  70. package/dist-library/reactive-md-plugin-chart.js +13 -9
  71. package/dist-library/reactive-md-plugin-data.js +4 -4
  72. package/dist-library/reactive-md-plugin-diagram.js +3 -3
  73. package/dist-library/reactive-md-plugin-forms.js +5 -5
  74. package/dist-library/reactive-md-plugin-gallery.js +3 -3
  75. package/dist-library/reactive-md-plugin-navigation.js +10 -10
  76. package/dist-library/reactive-md-plugin-network.js +5 -5
  77. package/dist-library/reactive-md-plugin-plot.js +4 -4
  78. package/dist-library/reactive-md-react-component-accordion.js +3 -3
  79. package/dist-library/reactive-md-react-component-alert.js +3 -3
  80. package/dist-library/reactive-md-react-component-anchor.js +3 -3
  81. package/dist-library/reactive-md-react-component-badge.js +3 -3
  82. package/dist-library/reactive-md-react-component-card.js +3 -3
  83. package/dist-library/reactive-md-react-component-chart.js +2 -2
  84. package/dist-library/reactive-md-react-component-checkbox.js +2 -2
  85. package/dist-library/reactive-md-react-component-checklist.js +2 -2
  86. package/dist-library/reactive-md-react-component-choices.js +2 -2
  87. package/dist-library/reactive-md-react-component-column.js +1 -1
  88. package/dist-library/reactive-md-react-component-coordinate.js +2 -2
  89. package/dist-library/reactive-md-react-component-counter.js +2 -2
  90. package/dist-library/reactive-md-react-component-data-table.js +2 -2
  91. package/dist-library/reactive-md-react-component-date.js +2 -2
  92. package/dist-library/reactive-md-react-component-diagram.js +2 -2
  93. package/dist-library/reactive-md-react-component-disclosure.js +3 -3
  94. package/dist-library/reactive-md-react-component-edge.js +1 -1
  95. package/dist-library/reactive-md-react-component-else.js +10 -0
  96. package/dist-library/reactive-md-react-component-gallery-item.js +2 -2
  97. package/dist-library/reactive-md-react-component-gallery.js +2 -2
  98. package/dist-library/reactive-md-react-component-grid.js +3 -3
  99. package/dist-library/reactive-md-react-component-if.js +3 -3
  100. package/dist-library/reactive-md-react-component-input.js +2 -2
  101. package/dist-library/reactive-md-react-component-jump.js +3 -3
  102. package/dist-library/reactive-md-react-component-multi-select.js +2 -2
  103. package/dist-library/reactive-md-react-component-node.js +2 -2
  104. package/dist-library/reactive-md-react-component-number.js +2 -2
  105. package/dist-library/reactive-md-react-component-option.js +1 -1
  106. package/dist-library/reactive-md-react-component-panel.js +3 -3
  107. package/dist-library/reactive-md-react-component-plot.js +2 -2
  108. package/dist-library/reactive-md-react-component-progress.js +2 -2
  109. package/dist-library/reactive-md-react-component-quiz.js +2 -2
  110. package/dist-library/reactive-md-react-component-radio-group.js +2 -2
  111. package/dist-library/reactive-md-react-component-range-slider.js +2 -2
  112. package/dist-library/reactive-md-react-component-section.js +3 -3
  113. package/dist-library/reactive-md-react-component-select.js +2 -2
  114. package/dist-library/reactive-md-react-component-slider.js +2 -2
  115. package/dist-library/reactive-md-react-component-step.js +3 -3
  116. package/dist-library/reactive-md-react-component-steps.js +3 -3
  117. package/dist-library/reactive-md-react-component-tab.js +3 -3
  118. package/dist-library/reactive-md-react-component-table.js +2 -2
  119. package/dist-library/reactive-md-react-component-tabs.js +3 -3
  120. package/dist-library/reactive-md-react-component-text.js +3 -3
  121. package/dist-library/reactive-md-react-component-textarea.js +2 -2
  122. package/dist-library/reactive-md-react-component-timeline.js +2 -2
  123. package/dist-library/reactive-md-react-component-timer.js +2 -2
  124. package/dist-library/reactive-md-react-component-toggle.js +2 -2
  125. package/dist-library/reactive-md-react-component-tooltip.js +3 -3
  126. package/dist-library/reactive-md-react-component-validation.js +3 -3
  127. package/dist-library/reactive-md-react-minimal.js +4 -4
  128. package/dist-library/reactive-md-react-pack-controls.js +4 -4
  129. package/dist-library/reactive-md-react-pack-data.js +3 -3
  130. package/dist-library/reactive-md-react-pack-layout.js +25 -24
  131. package/dist-library/reactive-md-react-pack-visuals.js +2 -2
  132. package/dist-library/reactive-md-react-packed.js +6 -6
  133. package/dist-library/reactive-md-react-server.js +37 -36
  134. package/dist-library/reactive-md-react-static-server.js +2 -2
  135. package/dist-library/reactive-md-react-static.js +1 -1
  136. package/dist-library/reactive-md-react-unstyled.js +12 -12
  137. package/dist-library/reactive-md-react.js +12 -12
  138. package/dist-library/reactive-md-scan.js +1 -1
  139. package/dist-library/reactive-md-sdk.js +23 -9
  140. package/dist-library/reactive-md-standalone-configured.js +2 -2
  141. package/dist-library/reactive-md-standalone-host.js +2 -2
  142. package/dist-library/reactive-md-testing-browser.js +2 -2
  143. package/dist-library/reactive-md-testing-react.js +6 -6
  144. package/dist-library/reactive-md-testing.js +6 -6
  145. package/dist-library/reactive-md-vite.js +25 -9
  146. package/dist-library/reactive-md-worker-pool.js +3 -3
  147. package/dist-library/reactive-md.css +1 -1
  148. package/dist-library/reactive-md.js +52 -43
  149. package/dist-library/{registry-core-CziAIP5P.js → registry-core-DxEaxhJ6.js} +3 -2
  150. package/dist-library/{render-nodes-DKjg_TR1.js → render-nodes-B6j6Ip5I.js} +766 -731
  151. package/dist-library/{requirements-DhIkxAbl.js → requirements-C56sFIEs.js} +2 -2
  152. package/dist-library/{resources-B_nbROgj.js → resources-6VaNgk-h.js} +2 -2
  153. package/dist-library/rmd-pack-layout.css +9 -0
  154. package/dist-library/rmd-pack-resource-layout.css +9 -0
  155. package/dist-library/runtime-BHeuLOv_.js +1369 -0
  156. package/dist-library/{runtime-requirement-C4-vNcf5.js → runtime-requirement-DzPO8raU.js} +166 -163
  157. package/dist-library/{schema-core-4sd1Vu7V.js → schema-core-CDXfxdID.js} +24 -1
  158. package/dist-library/{sdk-core-BLsW9cCy.js → sdk-core-CnE-n0Z7.js} +469 -314
  159. package/dist-library/{session-core-DLBRPV7f.js → session-core-C071yQwV.js} +140 -127
  160. package/dist-library/{validation-XXlb-spV.js → sha256-utf16-Bmandi_H.js} +392 -315
  161. package/dist-library/shareable-CHCDnl6j.js +844 -0
  162. package/dist-library/types/authoring/catalog.d.ts +3 -1
  163. package/dist-library/types/authoring/index.d.ts +1 -1
  164. package/dist-library/types/components/chart/default-chart-types.d.ts +3 -0
  165. package/dist-library/types/components/chart/default-chart.d.ts +7 -0
  166. package/dist-library/types/components/entries/else.d.ts +3 -0
  167. package/dist-library/types/components/layout/layout.d.ts +5 -0
  168. package/dist-library/types/components/shared/visuals.d.ts +1 -1
  169. package/dist-library/types/components/table/data-table-model.d.ts +95 -2
  170. package/dist-library/types/components/table/data-table.d.ts +2 -2
  171. package/dist-library/types/contracts/component-kernel.d.ts +5 -0
  172. package/dist-library/types/contracts/font-aliases.d.ts +18 -0
  173. package/dist-library/types/contracts/number-literal.d.ts +2 -0
  174. package/dist-library/types/contracts/sha256-utf16.d.ts +2 -0
  175. package/dist-library/types/export/index.d.ts +4 -1
  176. package/dist-library/types/local/compilation/compiler-choices.d.ts +4 -0
  177. package/dist-library/types/local/compilation/compiler-declarations.d.ts +2 -1
  178. package/dist-library/types/local/compilation/compiler-expressions.d.ts +12 -1
  179. package/dist-library/types/local/compilation/compiler-macros.d.ts +18 -0
  180. package/dist-library/types/local/compilation/compiler-structure.d.ts +8 -2
  181. package/dist-library/types/local/compilation/compiler-tables.d.ts +1 -0
  182. package/dist-library/types/local/compilation/compiler-validation.d.ts +11 -0
  183. package/dist-library/types/local/compilation/compiler-values.d.ts +1 -2
  184. package/dist-library/types/local/configuration/diagnostic-messages.d.ts +173 -2
  185. package/dist-library/types/local/configuration/diagnostic-runtime-messages.d.ts +40 -0
  186. package/dist-library/types/local/evaluation/choice-values.d.ts +22 -0
  187. package/dist-library/types/local/evaluation/computations.d.ts +13 -5
  188. package/dist-library/types/local/evaluation/dataset.d.ts +4 -0
  189. package/dist-library/types/local/evaluation/expression/collection-functions.d.ts +13 -0
  190. package/dist-library/types/local/evaluation/expression/compile.d.ts +11 -4
  191. package/dist-library/types/local/evaluation/expression/data-functions.d.ts +23 -0
  192. package/dist-library/types/local/evaluation/expression/evaluation.d.ts +3 -1
  193. package/dist-library/types/local/evaluation/expression/internal-names.d.ts +8 -0
  194. package/dist-library/types/local/evaluation/expression/syntax.d.ts +19 -2
  195. package/dist-library/types/local/evaluation/expression/transform-budget.d.ts +13 -0
  196. package/dist-library/types/local/evaluation/expression/values.d.ts +9 -1
  197. package/dist-library/types/local/evaluation/validation.d.ts +8 -6
  198. package/dist-library/types/local/index.d.ts +4 -3
  199. package/dist-library/types/local/parsing/conditional-branches.d.ts +4 -0
  200. package/dist-library/types/local/parsing/source-revision.d.ts +3 -0
  201. package/dist-library/types/local/runtime/runtime-choices.d.ts +11 -0
  202. package/dist-library/types/local/runtime/runtime.d.ts +3 -1
  203. package/dist-library/types/local/runtime/state.d.ts +30 -15
  204. package/dist-library/types/local/source/authoring-requirements.d.ts +3 -0
  205. package/dist-library/types/local/source/authoring-syntax.d.ts +3 -2
  206. package/dist-library/types/local/source/authoring.d.ts +10 -0
  207. package/dist-library/types/local/source/source-migration.d.ts +1 -0
  208. package/dist-library/types/local/types.d.ts +33 -2
  209. package/dist-library/types/react/component-api.d.ts +21 -2
  210. package/dist-library/types/react/component-utils.d.ts +11 -0
  211. package/dist-library/types/react/font-aliases.d.ts +2 -0
  212. package/dist-library/types/react/package-core.d.ts +3 -0
  213. package/dist-library/types/react/rendering/document/validation-state.d.ts +1 -1
  214. package/dist-library/types/react/rendering/document/view-revision.d.ts +3 -12
  215. package/dist-library/types/react/rendering/table/data-table.d.ts +1 -1
  216. package/dist-library/types/react/sdk-core.d.ts +3 -1
  217. package/dist-library/types/sdk/assembly.d.ts +3 -0
  218. package/dist-library/types/sdk/font.d.ts +13 -0
  219. package/dist-library/types/sdk/index.d.ts +1 -0
  220. package/dist-library/types/sdk/theme.d.ts +5 -0
  221. package/dist-library/types/sdk/types.d.ts +6 -0
  222. package/dist-library/types/sdk/version.d.ts +1 -1
  223. package/dist-library/types/shareable.d.ts +15 -3
  224. package/dist-library/types/standalone/prepare.d.ts +4 -2
  225. package/dist-library/types/standalone/session-core.d.ts +4 -1
  226. package/dist-library/types/vite/index.d.ts +3 -0
  227. package/dist-library/types/vite/registration.d.ts +1 -0
  228. package/dist-library/{types-Bza88SGK.js → types-B4qG8J4S.js} +1 -1
  229. package/dist-library/types-FYhRWRn9.js +3 -0
  230. package/dist-library/use-hydrated-D1gFY2Dq.js +2655 -0
  231. package/dist-library/validation-DRuW0Wl9.js +433 -0
  232. package/dist-library/{version-B0G1699c.js → version-4wzhbvDG.js} +1 -1
  233. package/dist-library/{visual-helpers-CRmaqCHX.js → visual-helpers-UU6xiL8g.js} +3 -3
  234. package/dist-library/visuals-7xzoL9ql.js +49340 -0
  235. package/dist-library/{worker-D6WMV8xJ.js → worker-3ldRjOEG.js} +9 -9
  236. package/dist-standalone/reactive-md-standalone.css +1 -1
  237. package/dist-standalone/reactive-md-standalone.js +128 -368
  238. package/docs/README-ch.md +3 -1
  239. package/docs/README.md +3 -1
  240. package/docs/compatibility/api-stability-ch.md +1 -1
  241. package/docs/compatibility/api-stability-en.md +1 -1
  242. package/docs/compatibility/compatibility-ch.md +15 -15
  243. package/docs/compatibility/compatibility-en.md +15 -15
  244. package/docs/compatibility/compatibility-manifest.schema.json +3 -2
  245. package/docs/compatibility/deprecation-ch.md +2 -2
  246. package/docs/compatibility/deprecation-en.md +2 -2
  247. package/docs/compatibility/source-versioning-ch.md +22 -14
  248. package/docs/compatibility/source-versioning-en.md +22 -13
  249. package/docs/compatibility/support-matrix-ch.md +4 -3
  250. package/docs/compatibility/support-matrix-en.md +4 -3
  251. package/docs/development/component-development-ch.md +2 -2
  252. package/docs/development/component-development-en.md +2 -2
  253. package/docs/development/component-protocol-ch.md +18 -18
  254. package/docs/development/component-protocol-en.md +14 -14
  255. package/docs/guides/local-guide-ch.md +109 -20
  256. package/docs/guides/local-guide-en.md +109 -20
  257. package/docs/integration/author-tools-ch.md +1 -1
  258. package/docs/integration/author-tools-en.md +1 -1
  259. package/docs/integration/editor-ch.md +3 -3
  260. package/docs/integration/editor-en.md +3 -3
  261. package/docs/integration/extension-sdk-ch.md +29 -3
  262. package/docs/integration/extension-sdk-en.md +29 -3
  263. package/docs/integration/local-integration-ch.md +3 -3
  264. package/docs/integration/local-integration-en.md +3 -3
  265. package/docs/integration/pdf-export-ch.md +42 -0
  266. package/docs/integration/pdf-export-en.md +42 -0
  267. package/docs/integration/shareable-export-ch.md +11 -19
  268. package/docs/integration/shareable-export-en.md +11 -19
  269. package/docs/reference/diagnostics-counting-ch.md +24 -1
  270. package/docs/reference/diagnostics-counting-en.md +24 -1
  271. package/docs/reference/local-interaction-syntax-ch.md +222 -33
  272. package/docs/reference/local-interaction-syntax-en.md +220 -31
  273. package/docs/reference/public-api-ch.md +24 -18
  274. package/docs/reference/public-api-en.md +24 -18
  275. package/docs/reference/theme-protocol-ch.md +1 -1
  276. package/docs/reference/theme-protocol-en.md +1 -1
  277. package/docs/releases/release-0.10.0-ch.md +45 -0
  278. package/docs/releases/release-0.10.0-en.md +45 -0
  279. package/examples/conformance/README-ch.md +3 -3
  280. package/examples/conformance/README.md +3 -3
  281. package/examples/conformance/local-draft-4.json +441 -0
  282. package/examples/integration/README-ch.md +3 -3
  283. package/examples/integration/README.md +3 -3
  284. package/examples/integration/chat-session/package.json +1 -1
  285. package/examples/local/README-ch.md +1 -1
  286. package/examples/local/README.md +1 -1
  287. package/package.json +6 -1
  288. package/dist-library/LocalStaticDocumentView-2J7w0sKm.js +0 -143
  289. package/dist-library/authoring-B14SsOXZ.js +0 -893
  290. package/dist-library/compile-D50B5_Ww.js +0 -1249
  291. package/dist-library/computations-CffoW7Ff.js +0 -340
  292. package/dist-library/data-table-Kv_ZA2Z2.js +0 -297
  293. package/dist-library/default-options-DU5dxuU6.js +0 -125
  294. package/dist-library/layout-BfUzzO2b.js +0 -553
  295. package/dist-library/runtime-CuJndKqK.js +0 -1289
  296. package/dist-library/shareable-C6mUerpQ.js +0 -817
  297. package/dist-library/types-daDo2c_w.js +0 -3
  298. package/dist-library/use-hydrated-W-laKPhY.js +0 -22975
  299. package/dist-library/visuals-CoVSjVD8.js +0 -49159
@@ -0,0 +1,1742 @@
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-CJvN-nC1.js";
3
+ import { d as o, f as s, l as c, p as l } from "./choice-values-BItGjPD2.js";
4
+ // src/local/evaluation/expression/values.ts
5
+ var u = class extends Error {
6
+ offset;
7
+ code;
8
+ constructor(e, t, n = 0) {
9
+ super(t), this.name = "LocalExpressionError", this.code = e, this.offset = n;
10
+ }
11
+ }, d = /* @__PURE__ */ "abs.sqrt.floor.ceil.round.min.max.pow.sin.cos.tan.asin.acos.atan.exp.log.len.contains.clamp.number.string.sum.average.minOf.maxOf.range.join.split.formatNumber.formatPercent.formatScientific.formatCurrency.trim.lower.upper.startsWith.endsWith.replace.slice.ifBlank.dateCompare.dateDiff.dateAdd.formatDate.filter.map.sortBy.lookup".split("."), f = new Set(d), p = /* @__PURE__ */ new Map([["pi", Math.PI], ["e", Math.E]]), ee = /* @__PURE__ */ new Set([
12
+ "__proto__",
13
+ "prototype",
14
+ "constructor"
15
+ ]), te = /* @__PURE__ */ new Set([
16
+ "string",
17
+ "number",
18
+ "boolean",
19
+ "null",
20
+ "array",
21
+ "number-array"
22
+ ]), ne = /* @__PURE__ */ new Set([
23
+ "number",
24
+ "string",
25
+ "range",
26
+ "join",
27
+ "split",
28
+ "dateAdd",
29
+ "formatDate",
30
+ "ifBlank",
31
+ "filter",
32
+ "map",
33
+ "sortBy",
34
+ "lookup"
35
+ ]), re = /* @__PURE__ */ new Set([
36
+ ...d.filter((e) => !ne.has(e)),
37
+ "x",
38
+ "y",
39
+ "pi",
40
+ "e",
41
+ "true",
42
+ "false",
43
+ "null",
44
+ ...ee
45
+ ]), ie = 4e3, m = e;
46
+ function h(r) {
47
+ if (r.length > 1e4) return {
48
+ code: "expression-budget",
49
+ ...i("local.budget.value.array", { limit: n }),
50
+ message: `Array exceeds the ${n}-item limit.`
51
+ };
52
+ let a = null, o = 0;
53
+ for (let n of r) if (typeof n == "string") {
54
+ if (a === "number") return {
55
+ code: "expression-value",
56
+ key: "error.array.homogeneous",
57
+ message: "Array elements must all be strings or all be numbers."
58
+ };
59
+ if (a = "string", n.length > 1e5) return {
60
+ code: "expression-budget",
61
+ ...i("local.budget.value.array-member", { limit: e }),
62
+ message: `Array member exceeds the ${e}-character limit.`
63
+ };
64
+ if (o += n.length, o > 1e5) return {
65
+ code: "expression-budget",
66
+ ...i("local.budget.value.array-contents", { limit: t }),
67
+ message: `Array contents exceed the ${t}-character limit.`
68
+ };
69
+ } else if (typeof n == "number") {
70
+ if (a === "string") return {
71
+ code: "expression-value",
72
+ key: "error.array.homogeneous",
73
+ message: "Array elements must all be strings or all be numbers."
74
+ };
75
+ if (a = "number", !Number.isFinite(n)) return {
76
+ code: "expression-value",
77
+ key: "error.array.finite",
78
+ message: "Array members must be finite numbers."
79
+ };
80
+ } else return {
81
+ code: "expression-value",
82
+ key: "error.array.members",
83
+ message: "Array members must be strings or finite numbers."
84
+ };
85
+ return null;
86
+ }
87
+ function ae(t) {
88
+ if (typeof t == "string") return t.length > 1e5 ? i("local.budget.value.string", { limit: e }) : null;
89
+ if (Array.isArray(t)) {
90
+ let e = h(t);
91
+ return e ? i(e.key, e.params) : null;
92
+ }
93
+ return null;
94
+ }
95
+ function oe(e) {
96
+ let t = ae(e);
97
+ return t ? a(t) : null;
98
+ }
99
+ // src/local/evaluation/expression/syntax.ts
100
+ var se = /^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/, ce = /[A-Za-z_]/, le = /[A-Za-z0-9_]/;
101
+ function ue(e) {
102
+ let t = [], n = 0;
103
+ for (; n < e.length;) {
104
+ let r = e[n];
105
+ if (/\s/.test(r)) {
106
+ n += 1;
107
+ continue;
108
+ }
109
+ if (r >= "0" && r <= "9" || r === "." && /[0-9]/.test(e[n + 1] ?? "")) {
110
+ let r = se.exec(e.slice(n));
111
+ if (!r) throw new u("expression-syntax", "Invalid number.", n);
112
+ let i = r[0], a = Number(i);
113
+ if (!Number.isFinite(a)) throw new u("expression-number", `Number must be finite: ${i}.`, n);
114
+ t.push({
115
+ kind: "number",
116
+ value: i,
117
+ start: n,
118
+ number: a
119
+ }), n += i.length;
120
+ continue;
121
+ }
122
+ if (r === "\"" || r === "'") {
123
+ let i = n, a = r, o = "", s = n + 1, c = !1;
124
+ for (; s < e.length;) {
125
+ let t = e[s];
126
+ if (t === a) {
127
+ c = !0, s += 1;
128
+ break;
129
+ }
130
+ if (t === "\n" || t === "\r") throw new u("expression-string", "String literals cannot span lines.", i);
131
+ if (t === "\\") {
132
+ let t = e[s + 1];
133
+ if (t === void 0) break;
134
+ switch (t) {
135
+ case "\\":
136
+ o += "\\";
137
+ break;
138
+ case "'":
139
+ o += "'";
140
+ break;
141
+ case "\"":
142
+ o += "\"";
143
+ break;
144
+ case "n":
145
+ o += "\n";
146
+ break;
147
+ case "t":
148
+ o += " ";
149
+ break;
150
+ case "b":
151
+ o += "\b";
152
+ break;
153
+ case "f":
154
+ o += "\f";
155
+ break;
156
+ case "r":
157
+ o += "\r";
158
+ break;
159
+ case "u": {
160
+ let t = e.slice(s + 2, s + 6);
161
+ if (!/^[0-9a-f]{4}$/i.test(t)) throw new u("expression-string", "Use four hexadecimal digits after a Unicode escape.", s);
162
+ o += String.fromCharCode(parseInt(t, 16)), s += 4;
163
+ break;
164
+ }
165
+ default: throw new u("expression-string", `Unsupported escape \\${t}.`, s);
166
+ }
167
+ s += 2;
168
+ } else o += t, s += 1;
169
+ }
170
+ if (!c) throw new u("expression-string", "Unterminated string literal.", i);
171
+ if (o.length > m) throw new u("expression-budget", "String literal exceeds the length limit.", i);
172
+ t.push({
173
+ kind: "string",
174
+ value: o,
175
+ start: i
176
+ }), n = s;
177
+ continue;
178
+ }
179
+ if (r === "@") {
180
+ let r = c.exec(e.slice(n))?.[0];
181
+ if (r) {
182
+ t.push({
183
+ kind: "ident",
184
+ value: r,
185
+ start: n
186
+ }), n += r.length;
187
+ continue;
188
+ }
189
+ }
190
+ if (ce.test(r)) {
191
+ let r = n + 1;
192
+ for (; r < e.length && le.test(e[r]);) r += 1;
193
+ t.push({
194
+ kind: "ident",
195
+ value: e.slice(n, r),
196
+ start: n
197
+ }), n = r;
198
+ continue;
199
+ }
200
+ let i = e.slice(n, n + 2);
201
+ if (e.startsWith("!==", n) || e.startsWith("===", n)) throw new u("expression-syntax", `Unsupported operator ${e.slice(n, n + 3)}.`, n);
202
+ if (i === "==" || i === "!=" || i === "<=" || i === ">=" || i === "&&" || i === "||" || i === "??") t.push({
203
+ kind: "punct",
204
+ value: i,
205
+ start: n
206
+ }), n += 2;
207
+ else if ("+-*/%()!<>?:,[]".includes(r)) t.push({
208
+ kind: "punct",
209
+ value: r,
210
+ start: n
211
+ }), n += 1;
212
+ else throw r === "=" ? new u("expression-assignment", "Assignments are not supported.", n) : r === "." ? new u("expression-property", "Property access is not supported.", n) : r === "&" || r === "|" ? new u("expression-syntax", `Use ${r}${r} for logical operations.`, n) : new u("expression-syntax", `Unrecognized character "${r}".`, n);
213
+ }
214
+ return t.push({
215
+ kind: "eof",
216
+ value: "",
217
+ start: e.length
218
+ }), t;
219
+ }
220
+ function de(e, t) {
221
+ let n = "", r = 0;
222
+ return new g(e, (i, a) => {
223
+ n += e.slice(r, a) + t(i, a), r = a + i.length;
224
+ }).parse(), n + e.slice(r);
225
+ }
226
+ var fe = {
227
+ abs: [1, 1],
228
+ sqrt: [1, 1],
229
+ floor: [1, 1],
230
+ ceil: [1, 1],
231
+ round: [1, 2],
232
+ min: [1, 2 ** 53 - 1],
233
+ max: [1, 2 ** 53 - 1],
234
+ pow: [2, 2],
235
+ sin: [1, 1],
236
+ cos: [1, 1],
237
+ tan: [1, 1],
238
+ asin: [1, 1],
239
+ acos: [1, 1],
240
+ atan: [1, 1],
241
+ exp: [1, 1],
242
+ log: [1, 1],
243
+ len: [1, 1],
244
+ contains: [2, 2],
245
+ clamp: [3, 3],
246
+ number: [1, 1],
247
+ string: [1, 1],
248
+ sum: [1, 1],
249
+ average: [1, 1],
250
+ minOf: [1, 1],
251
+ maxOf: [1, 1],
252
+ range: [2, 3],
253
+ join: [1, 2],
254
+ split: [2, 2],
255
+ formatNumber: [1, 4],
256
+ formatPercent: [1, 3],
257
+ formatScientific: [1, 3],
258
+ formatCurrency: [1, 4],
259
+ trim: [1, 1],
260
+ lower: [1, 1],
261
+ upper: [1, 1],
262
+ startsWith: [2, 2],
263
+ endsWith: [2, 2],
264
+ replace: [3, 3],
265
+ slice: [2, 3],
266
+ ifBlank: [2, 2],
267
+ dateCompare: [2, 2],
268
+ dateDiff: [2, 3],
269
+ dateAdd: [2, 3],
270
+ formatDate: [1, 2],
271
+ filter: [2, 2],
272
+ map: [2, 2],
273
+ sortBy: [2, 3],
274
+ lookup: [3, 3]
275
+ }, pe = /* @__PURE__ */ new Set([
276
+ "filter",
277
+ "map",
278
+ "sortBy"
279
+ ]), me = /* @__PURE__ */ new Set(["item", "index"]);
280
+ function he(e) {
281
+ let t = 0, n = [{
282
+ node: e,
283
+ depth: 1
284
+ }];
285
+ for (; n.length > 0;) {
286
+ let { node: e, depth: r } = n.pop();
287
+ switch (r > t && (t = r), e.kind) {
288
+ case "unary":
289
+ n.push({
290
+ node: e.operand,
291
+ depth: r + 1
292
+ });
293
+ break;
294
+ case "binary":
295
+ n.push({
296
+ node: e.left,
297
+ depth: r + 1
298
+ }), n.push({
299
+ node: e.right,
300
+ depth: r + 1
301
+ });
302
+ break;
303
+ case "conditional":
304
+ n.push({
305
+ node: e.test,
306
+ depth: r + 1
307
+ }), n.push({
308
+ node: e.consequent,
309
+ depth: r + 1
310
+ }), n.push({
311
+ node: e.alternate,
312
+ depth: r + 1
313
+ });
314
+ break;
315
+ case "call":
316
+ for (let t of e.args) n.push({
317
+ node: t,
318
+ depth: r + 1
319
+ });
320
+ break;
321
+ case "array":
322
+ for (let t of e.elements) n.push({
323
+ node: t,
324
+ depth: r + 1
325
+ });
326
+ break;
327
+ case "index": n.push({
328
+ node: e.target,
329
+ depth: r + 1
330
+ }), n.push({
331
+ node: e.index,
332
+ depth: r + 1
333
+ });
334
+ }
335
+ }
336
+ return t;
337
+ }
338
+ var g = class {
339
+ onFreeReference;
340
+ tokens;
341
+ position = 0;
342
+ nodeCount = 0;
343
+ transformNesting = 0;
344
+ transformScopeDepth = 0;
345
+ dependencyNames = [];
346
+ dependencySet = /* @__PURE__ */ new Set();
347
+ dependencyStarts = /* @__PURE__ */ new Map();
348
+ constructor(e, t) {
349
+ this.onFreeReference = t, this.tokens = ue(e);
350
+ }
351
+ get dependencies() {
352
+ return this.dependencyNames;
353
+ }
354
+ get dependencyOffsets() {
355
+ return this.dependencyStarts;
356
+ }
357
+ parse() {
358
+ if (this.peek().kind === "eof") throw new u("expression-empty", "Expression is empty.", 0);
359
+ let e = this.parseConditional(0), t = this.peek();
360
+ if (t.kind !== "eof") throw new u("expression-syntax", `Unexpected content "${t.value}".`, t.start);
361
+ if (he(e) > 200) throw new u("expression-budget", "Expression is nested too deeply.", e.start);
362
+ return e;
363
+ }
364
+ peek() {
365
+ return this.tokens[this.position];
366
+ }
367
+ next() {
368
+ let e = this.tokens[this.position];
369
+ return this.position += 1, e;
370
+ }
371
+ isPunct(e) {
372
+ let t = this.peek();
373
+ return t.kind === "punct" && t.value === e;
374
+ }
375
+ expect(e) {
376
+ let t = this.peek();
377
+ if (t.kind !== "punct" || t.value !== e) throw new u("expression-syntax", `Missing "${e}".`, t.start);
378
+ return this.next();
379
+ }
380
+ node(e, t, n) {
381
+ if (this.nodeCount += 1, this.nodeCount > 2e3) throw new u("expression-budget", "Expression is too complex.", n);
382
+ if (t > 100) throw new u("expression-budget", "Expression is nested too deeply.", n);
383
+ return e;
384
+ }
385
+ parseConditional(e) {
386
+ let t = this.parseNullish(e);
387
+ if (!this.isPunct("?")) return t;
388
+ let n = t.start;
389
+ this.next();
390
+ let r = this.parseConditional(e + 1);
391
+ this.expect(":");
392
+ let i = this.parseConditional(e + 1);
393
+ return this.node({
394
+ kind: "conditional",
395
+ test: t,
396
+ consequent: r,
397
+ alternate: i,
398
+ start: n
399
+ }, e, n);
400
+ }
401
+ parseNullish(e) {
402
+ let t = this.parseOr(e);
403
+ for (; this.isPunct("??");) {
404
+ let n = t.start;
405
+ this.next();
406
+ let r = this.parseOr(e);
407
+ t = this.node({
408
+ kind: "binary",
409
+ operator: "??",
410
+ left: t,
411
+ right: r,
412
+ start: n
413
+ }, e, n);
414
+ }
415
+ return t;
416
+ }
417
+ parseOr(e) {
418
+ let t = this.parseAnd(e);
419
+ for (; this.isPunct("||");) {
420
+ let n = t.start;
421
+ this.next();
422
+ let r = this.parseAnd(e);
423
+ t = this.node({
424
+ kind: "binary",
425
+ operator: "||",
426
+ left: t,
427
+ right: r,
428
+ start: n
429
+ }, e, n);
430
+ }
431
+ return t;
432
+ }
433
+ parseAnd(e) {
434
+ let t = this.parseEquality(e);
435
+ for (; this.isPunct("&&");) {
436
+ let n = t.start;
437
+ this.next();
438
+ let r = this.parseEquality(e);
439
+ t = this.node({
440
+ kind: "binary",
441
+ operator: "&&",
442
+ left: t,
443
+ right: r,
444
+ start: n
445
+ }, e, n);
446
+ }
447
+ return t;
448
+ }
449
+ parseEquality(e) {
450
+ let t = this.parseRelational(e);
451
+ for (; this.isPunct("==") || this.isPunct("!=");) {
452
+ let n = t.start, r = this.next().value, i = this.parseRelational(e);
453
+ t = this.node({
454
+ kind: "binary",
455
+ operator: r,
456
+ left: t,
457
+ right: i,
458
+ start: n
459
+ }, e, n);
460
+ }
461
+ return t;
462
+ }
463
+ parseRelational(e) {
464
+ let t = this.parseAdditive(e);
465
+ for (; this.isPunct("<") || this.isPunct("<=") || this.isPunct(">") || this.isPunct(">=");) {
466
+ let n = t.start, r = this.next().value, i = this.parseAdditive(e);
467
+ t = this.node({
468
+ kind: "binary",
469
+ operator: r,
470
+ left: t,
471
+ right: i,
472
+ start: n
473
+ }, e, n);
474
+ }
475
+ return t;
476
+ }
477
+ parseAdditive(e) {
478
+ let t = this.parseMultiplicative(e);
479
+ for (; this.isPunct("+") || this.isPunct("-");) {
480
+ let n = t.start, r = this.next().value, i = this.parseMultiplicative(e);
481
+ t = this.node({
482
+ kind: "binary",
483
+ operator: r,
484
+ left: t,
485
+ right: i,
486
+ start: n
487
+ }, e, n);
488
+ }
489
+ return t;
490
+ }
491
+ parseMultiplicative(e) {
492
+ let t = this.parseUnary(e);
493
+ for (; this.isPunct("*") || this.isPunct("/") || this.isPunct("%");) {
494
+ let n = t.start, r = this.next().value, i = this.parseUnary(e);
495
+ t = this.node({
496
+ kind: "binary",
497
+ operator: r,
498
+ left: t,
499
+ right: i,
500
+ start: n
501
+ }, e, n);
502
+ }
503
+ return t;
504
+ }
505
+ parseUnary(e) {
506
+ let t = this.peek();
507
+ if (t.kind === "punct" && (t.value === "-" || t.value === "+" || t.value === "!")) {
508
+ this.next();
509
+ let n = this.parseUnary(e + 1);
510
+ return this.node({
511
+ kind: "unary",
512
+ operator: t.value,
513
+ operand: n,
514
+ start: t.start
515
+ }, e, t.start);
516
+ }
517
+ return this.parsePrimary(e);
518
+ }
519
+ parsePrimary(e) {
520
+ let t = this.parseAtom(e);
521
+ for (; this.isPunct("[");) {
522
+ let n = t.start;
523
+ this.next();
524
+ let r = this.parseConditional(e + 1);
525
+ this.expect("]"), t = this.node({
526
+ kind: "index",
527
+ target: t,
528
+ index: r,
529
+ start: n
530
+ }, e, n);
531
+ }
532
+ return t;
533
+ }
534
+ parseArguments(e) {
535
+ let t = [];
536
+ if (!this.isPunct(")")) for (t.push(this.parseConditional(e + 1)); this.isPunct(",");) this.next(), t.push(this.parseConditional(e + 1));
537
+ return t;
538
+ }
539
+ parseLookupArguments(e) {
540
+ let t = this.next();
541
+ if (t.kind !== "ident" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(t.value)) throw new u("expression-syntax", "The first argument to lookup must be a dataset name.", t.start);
542
+ let n = s(t.value);
543
+ return this.trackReference(n, t.start), this.expect(","), [this.node({
544
+ kind: "reference",
545
+ name: n,
546
+ start: t.start
547
+ }, e + 1, t.start), ...this.parseArguments(e)];
548
+ }
549
+ trackReference(e, t) {
550
+ this.onFreeReference?.(e, t, this.transformScopeDepth > 0), this.dependencySet.has(e) || (this.dependencySet.add(e), this.dependencyNames.push(e), this.dependencyStarts.set(e, t));
551
+ }
552
+ parseTransformArguments(e, t, n) {
553
+ this.transformNesting += 1;
554
+ try {
555
+ if (this.transformNesting > 3) throw new u("local.transform.depth", "Array transforms nest at most 3 deep.", t);
556
+ let r = [];
557
+ if (this.isPunct(")")) return r;
558
+ if (r.push(this.parseConditional(n + 1)), this.isPunct(",")) {
559
+ this.next(), this.transformScopeDepth += 1;
560
+ try {
561
+ r.push(this.parseConditional(n + 1));
562
+ } finally {
563
+ --this.transformScopeDepth;
564
+ }
565
+ for (; this.isPunct(",");) this.next(), r.push(this.parseConditional(n + 1));
566
+ }
567
+ if (e === "sortBy" && r.length > 2) {
568
+ let e = r[2];
569
+ if (e.kind !== "literal" || e.value !== "asc" && e.value !== "desc") throw new u("local.transform.order", "Function sortBy requires the literal order 'asc' or 'desc'.", e.start);
570
+ }
571
+ return r;
572
+ } finally {
573
+ --this.transformNesting;
574
+ }
575
+ }
576
+ parseAtom(e) {
577
+ let t = this.peek();
578
+ if (t.kind === "number") return this.next(), this.node({
579
+ kind: "literal",
580
+ value: t.number,
581
+ start: t.start
582
+ }, e, t.start);
583
+ if (t.kind === "string") return this.next(), this.node({
584
+ kind: "literal",
585
+ value: t.value,
586
+ start: t.start
587
+ }, e, t.start);
588
+ if (t.kind === "ident") {
589
+ this.next();
590
+ let n = t.value;
591
+ if (this.isPunct("(")) {
592
+ if (!f.has(n)) throw new u("expression-unknown-function", `Unknown function "${n}".`, t.start);
593
+ this.next();
594
+ let r = n === "lookup" ? this.parseLookupArguments(e) : pe.has(n) ? this.parseTransformArguments(n, t.start, e) : this.parseArguments(e);
595
+ this.expect(")");
596
+ let [i, a] = fe[n];
597
+ if (r.length < i || r.length > a) throw new u("expression-arity", `Function ${n} expects ${i === a ? `${i} ${i === 1 ? "argument" : "arguments"}` : i === 1 ? "at least one argument" : `${i}–${a} arguments`}.`, t.start);
598
+ return this.node({
599
+ kind: "call",
600
+ name: n,
601
+ args: r,
602
+ start: t.start
603
+ }, e, t.start);
604
+ }
605
+ if (n === "true" || n === "false") return this.node({
606
+ kind: "literal",
607
+ value: n === "true",
608
+ start: t.start
609
+ }, e, t.start);
610
+ if (n === "null") return this.node({
611
+ kind: "literal",
612
+ value: null,
613
+ start: t.start
614
+ }, e, t.start);
615
+ let r = p.get(n);
616
+ if (r !== void 0) return this.node({
617
+ kind: "literal",
618
+ value: r,
619
+ start: t.start
620
+ }, e, t.start);
621
+ if (ee.has(n)) throw new u("expression-forbidden-name", `Name "${n}" is not allowed.`, t.start);
622
+ if (f.has(n) && re.has(n)) throw new u("expression-syntax", `Function ${n} must be called with parentheses.`, t.start);
623
+ return this.transformScopeDepth > 0 && me.has(n) || this.trackReference(n, t.start), this.node({
624
+ kind: "reference",
625
+ name: n,
626
+ start: t.start
627
+ }, e, t.start);
628
+ }
629
+ if (t.kind === "punct" && t.value === "(") {
630
+ this.next();
631
+ let t = this.parseConditional(e + 1);
632
+ return this.expect(")"), t;
633
+ }
634
+ if (t.kind === "punct" && t.value === "[") {
635
+ this.next();
636
+ let n = [];
637
+ if (!this.isPunct("]")) for (n.push(this.parseConditional(e + 1)); this.isPunct(",");) this.next(), n.push(this.parseConditional(e + 1));
638
+ return this.expect("]"), this.node({
639
+ kind: "array",
640
+ elements: n,
641
+ start: t.start
642
+ }, e, t.start);
643
+ }
644
+ throw new u("expression-syntax", "Expected an expression.", t.start);
645
+ }
646
+ }, _ = class extends Error {
647
+ code;
648
+ constructor(e, t) {
649
+ super(t), this.name = "LocalFunctionError", this.code = e;
650
+ }
651
+ }, ge = [
652
+ "en-US",
653
+ "zh-CN",
654
+ "de-DE",
655
+ "fr-FR",
656
+ "ja-JP"
657
+ ], _e = new Set(ge), ve = /^[A-Z]{3}$/, ye = 20, be = 128, v = /* @__PURE__ */ new Map(), xe = { signDisplay: "negative" };
658
+ function y(e) {
659
+ throw new _("expression-domain", e);
660
+ }
661
+ function b(t, n) {
662
+ if (t.length > 1e5) throw new _("expression-budget", `${n} exceeds the ${e}-character limit.`);
663
+ return t;
664
+ }
665
+ function x(e) {
666
+ return _e.has(e) || y(`Unsupported locale "${e}"; expected one of ${ge.join(", ")}.`), e;
667
+ }
668
+ function S(e, t) {
669
+ return (!Number.isInteger(e) || e < 0 || e > ye) && y(`${t} digits must be an integer from 0 to ${ye}.`), e;
670
+ }
671
+ function C(e) {
672
+ if (!Number.isFinite(e)) throw new _("expression-number", "Value must be a finite number.");
673
+ return e;
674
+ }
675
+ function w(e, t, n, r, i) {
676
+ let a = JSON.stringify([e, t]), o = v.get(a);
677
+ if (!o) {
678
+ try {
679
+ o = new Intl.NumberFormat(e, {
680
+ ...t,
681
+ ...xe
682
+ });
683
+ } catch {
684
+ y(i);
685
+ }
686
+ if (v.size >= be) {
687
+ let e = v.keys().next().value;
688
+ e !== void 0 && v.delete(e);
689
+ }
690
+ v.set(a, o);
691
+ }
692
+ return b(o.format(n), r);
693
+ }
694
+ function Se(e, t = 2, n = "en-US", r = !0) {
695
+ let i = x(n), a = S(t, "formatNumber");
696
+ return typeof r != "boolean" && y("formatNumber grouping must be a boolean."), e === null ? "" : w(i, {
697
+ useGrouping: r,
698
+ minimumFractionDigits: a,
699
+ maximumFractionDigits: a,
700
+ roundingMode: "halfExpand"
701
+ }, C(e), "Formatted number", `Cannot format a number for locale "${i}".`);
702
+ }
703
+ function Ce(e, t = 0, n = "en-US") {
704
+ let r = x(n), i = S(t, "formatPercent");
705
+ return e === null ? "" : w(r, {
706
+ style: "percent",
707
+ minimumFractionDigits: i,
708
+ maximumFractionDigits: i,
709
+ roundingMode: "halfExpand"
710
+ }, C(e), "Formatted percentage", `Cannot format a percentage for locale "${r}".`);
711
+ }
712
+ function we(e, t = 2, n = "en-US") {
713
+ let r = x(n), i = S(t, "formatScientific");
714
+ return e === null ? "" : w(r, {
715
+ notation: "scientific",
716
+ minimumFractionDigits: i,
717
+ maximumFractionDigits: i,
718
+ roundingMode: "halfExpand"
719
+ }, C(e), "Formatted number", `Cannot format a number for locale "${r}".`);
720
+ }
721
+ function Te(e, t = "USD", n = 2, r = "en-US") {
722
+ let i = x(r);
723
+ ve.test(t) || y(`Currency "${t}" must be a three-letter uppercase code such as "USD".`);
724
+ let a = S(n, "formatCurrency");
725
+ return e === null ? "" : w(i, {
726
+ style: "currency",
727
+ currency: t,
728
+ minimumFractionDigits: a,
729
+ maximumFractionDigits: a,
730
+ roundingMode: "halfExpand"
731
+ }, C(e), "Formatted currency", `Currency code "${t}" is not accepted by Intl.`);
732
+ }
733
+ // src/local/evaluation/dataset.ts
734
+ function Ee(e, t) {
735
+ return JSON.stringify([e, t]);
736
+ }
737
+ function De(e, t) {
738
+ let n = 0, r = Math.floor(e.length / 2) - 1;
739
+ for (; n <= r;) {
740
+ let i = n + Math.floor((r - n) / 2), a = e[i * 2];
741
+ if (typeof a != "string") return null;
742
+ if (a === t) {
743
+ let t = e[i * 2 + 1];
744
+ return typeof t == "string" ? t : null;
745
+ }
746
+ a < t ? n = i + 1 : r = i - 1;
747
+ }
748
+ return null;
749
+ }
750
+ // src/local/evaluation/expression/inference.ts
751
+ function T(e) {
752
+ switch (e) {
753
+ case "string": return "string";
754
+ case "number": return "number";
755
+ case "boolean": return "boolean";
756
+ case "null": return "null";
757
+ case "array": return "array";
758
+ case "number-array": return "number array";
759
+ }
760
+ }
761
+ function E(e) {
762
+ return e === null ? "null" : Array.isArray(e) ? "array" : typeof e == "boolean" ? "boolean" : typeof e == "number" ? "number" : "string";
763
+ }
764
+ function D(e, t) {
765
+ throw new u("expression-type", e, t);
766
+ }
767
+ function O(e, t, n, r) {
768
+ e !== t && D(`${r}, got ${T(e)}.`, n);
769
+ }
770
+ function Oe(e, t) {
771
+ return e === t ? e : e === "null" ? t : t === "null" ? e : null;
772
+ }
773
+ function ke(e, t) {
774
+ let n = k(e.args[0], t);
775
+ if (n !== "array" && n !== "number-array") throw new u("local.transform.source", `Function ${e.name} requires a string or numeric array, got ${T(n)}.`, e.args[0].start);
776
+ let r = {
777
+ ...t,
778
+ item: n === "array" ? "string" : "number",
779
+ index: "number"
780
+ }, i = k(e.args[1], r);
781
+ if (e.name === "filter") {
782
+ if (i !== "boolean") throw new u("local.transform.predicate", `Function filter requires a boolean condition, got ${T(i)}.`, e.args[1].start);
783
+ return n;
784
+ }
785
+ if (e.name === "map") {
786
+ if (i !== "string" && i !== "number") throw new u("local.transform.projection", `Function map requires a string or number projection, got ${T(i)}.`, e.args[1].start);
787
+ return i === "string" ? "array" : "number-array";
788
+ }
789
+ if (i !== "string" && i !== "number") throw new u("local.transform.key", `Function sortBy requires a string or number key, got ${T(i)}.`, e.args[1].start);
790
+ return n;
791
+ }
792
+ function k(e, t) {
793
+ switch (e.kind) {
794
+ case "literal": return E(e.value);
795
+ case "reference": {
796
+ if (typeof t != "object" || !t || !Object.prototype.hasOwnProperty.call(t, e.name)) {
797
+ let t = o(e.name);
798
+ throw new u("expression-unknown-name", t === void 0 ? `Variable "${e.name}" is not declared.` : `Dataset "${t}" is not declared.`, e.start);
799
+ }
800
+ let n = t[e.name];
801
+ if (typeof n != "string" || !te.has(n)) throw new u("expression-value", `Variable "${e.name}" has an invalid type.`, e.start);
802
+ return n;
803
+ }
804
+ case "unary": {
805
+ let n = k(e.operand, t);
806
+ 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");
807
+ }
808
+ case "binary": {
809
+ let n = k(e.left, t), r = k(e.right, t);
810
+ switch (e.operator) {
811
+ 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);
812
+ case "-":
813
+ case "*":
814
+ case "/":
815
+ 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";
816
+ case "<":
817
+ case "<=":
818
+ case ">":
819
+ 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);
820
+ case "==":
821
+ case "!=": return n !== r && n !== "null" && r !== "null" ? D(`Equality comparison requires matching types, got ${T(n)} and ${T(r)}.`, e.start) : "boolean";
822
+ case "&&":
823
+ case "||": return O(n, "boolean", e.start, "Logical operators require booleans"), O(r, "boolean", e.start, "Logical operators require booleans"), "boolean";
824
+ case "??": {
825
+ if (n === "array" && e.right.kind === "array" && e.right.elements.length === 0 || r === "array" && e.left.kind === "array" && e.left.elements.length === 0) return "array";
826
+ let t = Oe(n, r);
827
+ return t === null ? D(`Operator "??" requires matching types or one null, got ${T(n)} and ${T(r)}.`, e.start) : t;
828
+ }
829
+ }
830
+ break;
831
+ }
832
+ case "array": {
833
+ if (e.elements.length === 0) return "number-array";
834
+ let n = null;
835
+ for (let r of e.elements) {
836
+ let e = k(r, t);
837
+ if (e !== "string" && e !== "number") return D(`Array literals require string or number elements, got ${T(e)}.`, r.start);
838
+ if (n === null) n = e;
839
+ else if (n !== e) return D(`Array literals require elements of one type, got ${T(n)} and ${T(e)}.`, r.start);
840
+ }
841
+ return n === "string" ? "array" : "number-array";
842
+ }
843
+ case "index": {
844
+ let n = k(e.target, t);
845
+ 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);
846
+ }
847
+ case "conditional": {
848
+ O(k(e.test, t), "boolean", e.start, "Conditional test must be a boolean");
849
+ let n = k(e.consequent, t), r = k(e.alternate, t);
850
+ 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";
851
+ let i = Oe(n, r);
852
+ return i === null ? D(`Conditional branches must have matching types or one null, got ${T(n)} and ${T(r)}.`, e.start) : i;
853
+ }
854
+ case "call": {
855
+ if (e.name === "filter" || e.name === "map" || e.name === "sortBy") return ke(e, t);
856
+ let n = e.args.map((e) => k(e, t));
857
+ switch (e.name) {
858
+ case "lookup": return O(n[0], "array", e.start, "Function lookup requires a dataset"), O(n[1], "string", e.args[1].start, "Function lookup requires a string row key"), O(n[2], "string", e.args[2].start, "Function lookup requires a string column name"), "string";
859
+ case "abs":
860
+ case "sqrt":
861
+ case "floor":
862
+ case "ceil":
863
+ case "sin":
864
+ case "cos":
865
+ case "tan":
866
+ case "asin":
867
+ case "acos":
868
+ case "atan":
869
+ case "exp":
870
+ case "log": return O(n[0], "number", e.start, `Function ${e.name} requires a number`), "number";
871
+ case "round": return O(n[0], "number", e.start, "Function round requires a number"), n[1] !== void 0 && O(n[1], "number", e.start, "Function round requires numeric fraction digits"), "number";
872
+ case "min":
873
+ case "max":
874
+ case "pow":
875
+ case "clamp":
876
+ for (let t of n) O(t, "number", e.start, `Function ${e.name} requires a number`);
877
+ return "number";
878
+ 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";
879
+ case "contains":
880
+ if (n[0] === "number-array") return O(n[1], "number", e.start, "Function contains requires a numeric member"), "boolean";
881
+ if (n[0] === "string" || n[0] === "array") return O(n[1], "string", e.start, "Function contains requires a string member"), "boolean";
882
+ D(`Function contains requires a string or array, got ${T(n[0])}.`, e.start);
883
+ break;
884
+ case "number": return O(n[0], "string", e.start, "Function number requires a string"), "number";
885
+ case "string": return n[0] !== "string" && n[0] !== "number" && n[0] !== "boolean" && n[0] !== "null" && D(`Function string requires a string, number, boolean or null, got ${T(n[0])}.`, e.start), "string";
886
+ case "join": return n[0] !== "array" && n[0] !== "number-array" && D(`Function join requires a string or numeric array, got ${T(n[0])}.`, e.start), n[1] !== void 0 && O(n[1], "string", e.start, "Function join requires a string separator"), "string";
887
+ case "split": return O(n[0], "string", e.start, "Function split requires a string"), O(n[1], "string", e.start, "Function split requires a string separator"), "array";
888
+ case "range":
889
+ for (let t of n) O(t, "number", e.start, "Function range requires numbers");
890
+ return "number-array";
891
+ case "sum":
892
+ case "average":
893
+ case "minOf":
894
+ case "maxOf": return O(n[0], "number-array", e.start, `Function ${e.name} requires a numeric array`), "number";
895
+ case "formatNumber":
896
+ case "formatPercent":
897
+ 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";
898
+ 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";
899
+ case "trim":
900
+ case "lower":
901
+ case "upper": return O(n[0], "string", e.start, `Function ${e.name} requires a string`), "string";
902
+ case "startsWith":
903
+ 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";
904
+ 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";
905
+ 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";
906
+ case "ifBlank": return O(n[0], "string", e.start, "Function ifBlank requires a string"), O(n[1], "string", e.start, "Function ifBlank requires a string fallback"), "string";
907
+ 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";
908
+ 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";
909
+ case "dateAdd": return O(n[0], "string", e.start, "Function dateAdd requires a date string"), O(n[1], "number", e.start, "Function dateAdd requires a numeric amount"), n[2] !== void 0 && O(n[2], "string", e.start, "Function dateAdd requires a string unit"), "string";
910
+ case "formatDate": return O(n[0], "string", e.start, "Function formatDate requires a date string"), n[1] !== void 0 && O(n[1], "string", e.start, "Function formatDate requires a string locale"), "string";
911
+ }
912
+ break;
913
+ }
914
+ }
915
+ throw new u("expression-type", "Unsupported expression.", 0);
916
+ }
917
+ // src/local/evaluation/expression/collection-functions.ts
918
+ function Ae() {
919
+ throw new _("expression-number", "The result is not a finite number.");
920
+ }
921
+ function A(e) {
922
+ if (!Number.isFinite(e)) throw new _("expression-value", "Numeric array members must be finite numbers.");
923
+ return e;
924
+ }
925
+ function je(e) {
926
+ let t = 0;
927
+ for (let n of e) t += A(n);
928
+ return Number.isFinite(t) || Ae(), t;
929
+ }
930
+ function Me(e) {
931
+ if (e.length === 0) return null;
932
+ let t = je(e) / e.length;
933
+ return Number.isFinite(t) || Ae(), t;
934
+ }
935
+ function Ne(e) {
936
+ if (e.length === 0) return null;
937
+ let t = A(e[0]);
938
+ for (let n = 1; n < e.length; n += 1) {
939
+ let r = A(e[n]);
940
+ r < t && (t = r);
941
+ }
942
+ return t;
943
+ }
944
+ function Pe(e) {
945
+ if (e.length === 0) return null;
946
+ let t = A(e[0]);
947
+ for (let n = 1; n < e.length; n += 1) {
948
+ let r = A(e[n]);
949
+ r > t && (t = r);
950
+ }
951
+ return t;
952
+ }
953
+ function Fe(e, t, r) {
954
+ if (!Number.isFinite(e) || !Number.isFinite(t) || !Number.isFinite(r)) throw new _("expression-value", "range bounds and step must be finite numbers.");
955
+ if (r === 0) throw new _("expression-domain", "range step must not be zero.");
956
+ let i = r > 0;
957
+ if (!((i ? t - e : e - t) > 0)) return [];
958
+ let a = [];
959
+ for (let o = 0;; o += 1) {
960
+ let s = e + o * r;
961
+ if (!Number.isFinite(s)) throw new _("expression-number", "The range value is not a finite number.");
962
+ if (!((i ? t - s : s - t) > 0)) break;
963
+ if (a.length > 0) {
964
+ let e = a[a.length - 1];
965
+ if (i ? !(s > e) : !(s < e)) throw new _("expression-domain", "range step is too small to advance at this magnitude.");
966
+ }
967
+ if (a.length >= 1e4) throw new _("expression-budget", `range result would exceed the ${n}-item limit.`);
968
+ a.push(s);
969
+ }
970
+ return a;
971
+ }
972
+ // src/local/evaluation/expression/data-functions.ts
973
+ function j(e) {
974
+ throw new _("expression-domain", e);
975
+ }
976
+ function M(e) {
977
+ return b(e.trim(), "trim result");
978
+ }
979
+ function Ie(e) {
980
+ return b(e.toLowerCase(), "lower result");
981
+ }
982
+ function Le(e) {
983
+ return b(e.toUpperCase(), "upper result");
984
+ }
985
+ function Re(e, t) {
986
+ return e.startsWith(t);
987
+ }
988
+ function ze(e, t) {
989
+ return e.endsWith(t);
990
+ }
991
+ function Be(t, n, r) {
992
+ n.length === 0 && j("replace search text must not be empty.");
993
+ let i = r.length - n.length;
994
+ if (i > 0) {
995
+ let r = 0, a = 0;
996
+ for (;;) {
997
+ let e = t.indexOf(n, a);
998
+ if (e < 0) break;
999
+ r += 1, a = e + n.length;
1000
+ }
1001
+ if (t.length + r * i > 1e5) throw new _("expression-budget", `replace result would exceed the ${e}-character limit.`);
1002
+ }
1003
+ let a = "", o = 0;
1004
+ for (;;) {
1005
+ let e = t.indexOf(n, o);
1006
+ if (e < 0) break;
1007
+ a += t.slice(o, e), a += r, o = e + n.length;
1008
+ }
1009
+ return a += t.slice(o), b(a, "replace result");
1010
+ }
1011
+ function Ve(e, t) {
1012
+ return e < 0 ? Math.max(t + e, 0) : Math.min(e, t);
1013
+ }
1014
+ function He(e, t, n) {
1015
+ Number.isInteger(t) || j("slice start must be an integer."), n !== void 0 && !Number.isInteger(n) && j("slice end must be an integer.");
1016
+ let r = Array.from(e), i = r.length, a = Ve(t, i), o = n === void 0 ? i : Ve(n, i);
1017
+ return o <= a ? "" : b(r.slice(a, o).join(""), "slice result");
1018
+ }
1019
+ var Ue = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/;
1020
+ function We(e) {
1021
+ let t = e.trim();
1022
+ t === "" && j("number requires a non-empty numeric string."), Ue.test(t) || j(`number cannot parse "${e}" as a decimal number.`);
1023
+ let n = Number(t);
1024
+ return Number.isFinite(n) || j("number result must be a finite number."), n;
1025
+ }
1026
+ function Ge(t, n) {
1027
+ let r = null, i = [], a = n.length * Math.max(0, t.length - 1);
1028
+ for (let n of t) {
1029
+ let t = typeof n == "string";
1030
+ if (!t && !(typeof n == "number" && Number.isFinite(n))) throw new _("expression-type", "join requires a string or numeric array.");
1031
+ if (r === null) r = !t;
1032
+ else if (r !== !t) throw new _("expression-type", "join requires an array with one member type.");
1033
+ let o = t ? n : String(n);
1034
+ if (i.push(o), a += o.length, a > 1e5) throw new _("expression-budget", `join result would exceed the ${e}-character limit.`);
1035
+ }
1036
+ return b(i.join(n), "join result");
1037
+ }
1038
+ function Ke(e, t) {
1039
+ if (t === "") {
1040
+ let t = Array.from(e);
1041
+ if (t.length > 1e4) throw new _("expression-budget", `split result would exceed the ${n}-item limit.`);
1042
+ return t;
1043
+ }
1044
+ let r = 1, i = 0;
1045
+ for (;;) {
1046
+ let n = e.indexOf(t, i);
1047
+ if (n < 0) break;
1048
+ r += 1, i = n + t.length;
1049
+ }
1050
+ if (r > 1e4) throw new _("expression-budget", `split result would exceed the ${n}-item limit.`);
1051
+ return e.split(t);
1052
+ }
1053
+ var N = 864e5, qe = /* @__PURE__ */ new Map([
1054
+ ["days", N],
1055
+ ["hours", 36e5],
1056
+ ["minutes", 6e4],
1057
+ ["seconds", 1e3],
1058
+ ["milliseconds", 1]
1059
+ ]), Je = "days, hours, minutes, seconds or milliseconds";
1060
+ function P(e) {
1061
+ let t = $e(e);
1062
+ if (t === null) throw new _("expression-domain", `Date "${e}" must be a valid YYYY-MM-DD calendar date in years 0001-9999.`);
1063
+ return t;
1064
+ }
1065
+ function Ye(e, t) {
1066
+ let n = P(e), r = P(t);
1067
+ return n === r ? 0 : n < r ? -1 : 1;
1068
+ }
1069
+ function Xe(e, t, n = "days") {
1070
+ let r = qe.get(n);
1071
+ return r === void 0 && j(`dateDiff unit must be ${Je}.`), (P(e) - P(t)) / r;
1072
+ }
1073
+ function Ze(e, t, n = "days") {
1074
+ let r = qe.get(n);
1075
+ r === void 0 && j(`dateAdd unit must be ${Je}.`), Number.isFinite(t) || j("dateAdd amount must be a finite number.");
1076
+ let i = N / r, a = Math.floor(t / i);
1077
+ t < a * i && --a;
1078
+ let o = new Date(P(e) + a * N);
1079
+ Number.isFinite(o.getTime()) || j("dateAdd result must be a valid calendar date.");
1080
+ let s;
1081
+ try {
1082
+ s = o.toISOString().slice(0, 10);
1083
+ } catch {
1084
+ j("dateAdd result must be a valid calendar date.");
1085
+ }
1086
+ return $e(s) === null && j("dateAdd result must stay within years 0001-9999."), s;
1087
+ }
1088
+ function Qe(e, t = "en-US") {
1089
+ let n = x(t), r = P(e), i;
1090
+ try {
1091
+ i = new Intl.DateTimeFormat(n, {
1092
+ dateStyle: "medium",
1093
+ timeZone: "UTC",
1094
+ calendar: "gregory"
1095
+ });
1096
+ } catch {
1097
+ i = void 0;
1098
+ }
1099
+ return i === void 0 && j(`Cannot format a date for locale "${n}".`), b(i.format(new Date(r)), "Formatted date");
1100
+ }
1101
+ function $e(e) {
1102
+ let t = /^(\d{4})-(\d{2})-(\d{2})$/.exec(e);
1103
+ if (!t) return null;
1104
+ let n = Number(t[1]), r = Number(t[2]), i = Number(t[3]);
1105
+ if (n < 1 || r < 1 || r > 12 || i < 1 || i > 31) return null;
1106
+ let a = /* @__PURE__ */ new Date(0);
1107
+ return a.setUTCFullYear(n, r - 1, i), a.getUTCFullYear() === n && a.getUTCMonth() === r - 1 && a.getUTCDate() === i ? a.getTime() : null;
1108
+ }
1109
+ // src/local/evaluation/expression/evaluation.ts
1110
+ var et = ["item", "index"];
1111
+ function F(e, t, n = "expression-eval") {
1112
+ throw new u(n, e, t);
1113
+ }
1114
+ function tt(e, t, n) {
1115
+ let r = 0;
1116
+ for (let e of t) typeof e == "string" && (r += e.length);
1117
+ I(e, t.length + r, n);
1118
+ }
1119
+ function I(e, t, n) {
1120
+ if (!(!e.active || t <= 0)) {
1121
+ if (e.transformWork += t, e.transformWork > 1e6) throw new u("local.budget.transform", "Array transform work exceeded the expression limit.", n);
1122
+ if (e.stage && (e.stage.work += t, e.stage.work > 5e6)) throw new u("local.budget.transform", "Array transform work exceeded the stage limit.", n);
1123
+ }
1124
+ }
1125
+ function nt(e) {
1126
+ if (typeof e != "object" || !e || Array.isArray(e)) throw new u("expression-value", "Expression environment must be an object.", 0);
1127
+ }
1128
+ function rt(e, t, n) {
1129
+ if (e === null) return null;
1130
+ if (typeof e == "string") {
1131
+ let r = oe(e);
1132
+ if (r) throw new u("expression-budget", `Variable "${t}": ${r}`, n);
1133
+ return e;
1134
+ }
1135
+ if (typeof e == "boolean") return e;
1136
+ if (typeof e == "number") {
1137
+ if (!Number.isFinite(e)) throw new u("expression-value", `Variable "${t}" must be a finite number.`, n);
1138
+ return e;
1139
+ }
1140
+ if (Array.isArray(e)) {
1141
+ let r = h(e);
1142
+ if (r) throw new u(r.code, `Variable "${t}": ${r.message}`, n);
1143
+ return e;
1144
+ }
1145
+ throw new u("expression-value", `Variable "${t}" has an invalid value type.`, n);
1146
+ }
1147
+ function it(e, t) {
1148
+ let n = e;
1149
+ for (; n !== null && n !== Object.prototype;) {
1150
+ if (Object.prototype.hasOwnProperty.call(n, t)) return !0;
1151
+ n = Object.getPrototypeOf(n);
1152
+ }
1153
+ return !1;
1154
+ }
1155
+ var L = null;
1156
+ function at() {
1157
+ return L;
1158
+ }
1159
+ function ot(e, t, n) {
1160
+ let r = L;
1161
+ L = n;
1162
+ try {
1163
+ return e[t];
1164
+ } finally {
1165
+ L = r;
1166
+ }
1167
+ }
1168
+ function st(e, t, n, r) {
1169
+ nt(e), it(e, t) || F(`Variable "${t}" is not declared.`, n, "expression-unknown-name");
1170
+ let i = l(t) ? ot(e, t, r.stage) : e[t];
1171
+ return (typeof i == "string" || Array.isArray(i)) && I(r, i.length, n), rt(i, t, n);
1172
+ }
1173
+ function R(e, t, n = "Expected a number") {
1174
+ return typeof e == "number" && Number.isFinite(e) || F(`${n}.`, t, "expression-type"), e;
1175
+ }
1176
+ function z(e, t, n = "Expected a boolean") {
1177
+ return typeof e != "boolean" && F(`${n}.`, t, "expression-type"), e;
1178
+ }
1179
+ function B(e, t, n = "Expected a string") {
1180
+ return typeof e != "string" && F(`${n}.`, t, "expression-type"), e;
1181
+ }
1182
+ function V(e, t, n, r) {
1183
+ Array.isArray(e) || F(`${n}.`, t, "expression-type"), I(r, e.length, t);
1184
+ for (let r of e) typeof r == "number" && Number.isFinite(r) || F(`${n}.`, t, "expression-type");
1185
+ return e;
1186
+ }
1187
+ function H(e, t) {
1188
+ let n = h(e);
1189
+ return n && F(n.message, t, n.code), e;
1190
+ }
1191
+ function U(e, t) {
1192
+ try {
1193
+ return t();
1194
+ } catch (t) {
1195
+ throw t instanceof _ ? new u(t.code, t.message, e) : t;
1196
+ }
1197
+ }
1198
+ function W(e, t) {
1199
+ return Number.isNaN(e) && F("The result is undefined.", t, "expression-domain"), Number.isFinite(e) || F("The result is not a finite number.", t, "expression-number"), e;
1200
+ }
1201
+ function ct(e, t, n) {
1202
+ (!Number.isInteger(t) || t < 0 || t > 20) && F("Function round digits must be an integer from 0 to 20.", n, "expression-domain");
1203
+ let r = 10 ** t;
1204
+ if (Math.abs(e) >= (2 ** 53 - 1) / r) return e;
1205
+ let i = e * r;
1206
+ return Number.isFinite(i) ? Math.round(i) / r : e;
1207
+ }
1208
+ function lt(e, t, n, r) {
1209
+ let i = 0, a = 0;
1210
+ for (; i < e.length && a < t.length;) {
1211
+ let o = e.codePointAt(i), s = t.codePointAt(a), c = o > 65535 ? 2 : 1, l = s > 65535 ? 2 : 1;
1212
+ if (I(n, c + l, r), o !== s) return o < s ? -1 : 1;
1213
+ i += c, a += l;
1214
+ }
1215
+ let o = e.length - i, s = t.length - a;
1216
+ return o === s ? 0 : o < s ? -1 : 1;
1217
+ }
1218
+ function ut(e, t) {
1219
+ if (e === t) return !0;
1220
+ if (Array.isArray(e) && Array.isArray(t)) {
1221
+ if (e.length !== t.length) return !1;
1222
+ for (let n = 0; n < e.length; n += 1) if (e[n] !== t[n]) return !1;
1223
+ return !0;
1224
+ }
1225
+ return !1;
1226
+ }
1227
+ function dt(e, t, n) {
1228
+ if (!Array.isArray(e)) throw new u("local.transform.source", `Function ${t.name} requires a string or numeric array.`, t.args[0].start);
1229
+ tt(n, e, t.args[0].start);
1230
+ let r = h(e);
1231
+ if (r) throw new u(r.code === "expression-budget" ? "expression-budget" : "local.transform.source", r.message, t.args[0].start);
1232
+ return e;
1233
+ }
1234
+ function ft(e) {
1235
+ let t = Object.create(e);
1236
+ for (let e of et) Object.defineProperty(t, e, {
1237
+ value: void 0,
1238
+ writable: !0,
1239
+ enumerable: !0,
1240
+ configurable: !0
1241
+ });
1242
+ return t;
1243
+ }
1244
+ function G(e, t) {
1245
+ if (e.iterations += 1, e.iterations > 5e4) throw new u("local.budget.transform", "Array transforms exceeded the iteration limit.", t);
1246
+ }
1247
+ function K(e, t, n, r) {
1248
+ let i = n.steps;
1249
+ n.steps = 0;
1250
+ try {
1251
+ return X(e, t, n, r);
1252
+ } finally {
1253
+ n.steps = i;
1254
+ }
1255
+ }
1256
+ function q(e, t, n) {
1257
+ tt(n, e, t);
1258
+ let r = h(e);
1259
+ return r && F(r.message, t, r.code), Object.freeze(e);
1260
+ }
1261
+ function J(e) {
1262
+ throw new u("local.transform.projection", "Function map requires string or finite number projections of one type.", e);
1263
+ }
1264
+ function Y(e) {
1265
+ throw new u("local.transform.key", "Function sortBy requires string or finite number keys of one type.", e);
1266
+ }
1267
+ function pt(e, t, n, r, i) {
1268
+ let a = Array(e), o = Array(e);
1269
+ for (let t = 0; t < e; t += 1) a[t] = t;
1270
+ for (let s = 1; s < e; s *= 2) for (let c = 0; c < e; c += s * 2) {
1271
+ let l = Math.min(c + s, e), u = Math.min(c + s * 2, e);
1272
+ if (l >= u) continue;
1273
+ let d = c, f = l, p = c;
1274
+ for (; d < l && f < u;) {
1275
+ I(r, 1, i);
1276
+ let e = t[a[d]], s = t[a[f]], c = typeof e == "string" ? lt(e, s, r, i) : e === s ? 0 : e < s ? -1 : 1, l = n === "desc" && c !== 0 ? -c : c;
1277
+ o[p] = l <= 0 ? a[d++] : a[f++], p += 1;
1278
+ }
1279
+ for (; d < l;) o[p] = a[d++], p += 1;
1280
+ for (; f < u;) o[p] = a[f++], p += 1;
1281
+ for (let e = c; e < u; e += 1) a[e] = o[e];
1282
+ }
1283
+ return a;
1284
+ }
1285
+ function mt(e, t, n, r, i) {
1286
+ let a = e.args[2], o = "asc";
1287
+ if (a !== void 0) {
1288
+ if (a.kind !== "literal" || a.value !== "asc" && a.value !== "desc") throw new u("local.transform.order", "Function sortBy requires the literal order 'asc' or 'desc'.", a.start);
1289
+ o = a.value;
1290
+ }
1291
+ let s = e.args[1], c = [], l = null, d = 0;
1292
+ for (let a = 0; a < t.length; a += 1) {
1293
+ G(r, e.start), n.item = t[a], n.index = a;
1294
+ let o = K(s, n, r, i + 1);
1295
+ if (typeof o == "string") {
1296
+ if (l === "number" && Y(s.start), l = "string", d += o.length, d > 1e5) throw new u("local.budget.transform", "Sort keys exceed the temporary key character limit.", e.start);
1297
+ I(r, o.length, e.start);
1298
+ } else typeof o == "number" && Number.isFinite(o) ? (l === "string" && Y(s.start), l = "number") : Y(s.start);
1299
+ c.push(o);
1300
+ }
1301
+ let f = pt(t.length, c, o, r, e.start), p = Array(t.length);
1302
+ for (let e = 0; e < t.length; e += 1) p[e] = t[f[e]];
1303
+ return q(p, e.start, r);
1304
+ }
1305
+ function ht(e, t, n, r) {
1306
+ let i = n.active;
1307
+ n.active = !0;
1308
+ try {
1309
+ nt(t);
1310
+ let i = dt(X(e.args[0], t, n, r + 1), e, n);
1311
+ if (i.length === 0) return Object.freeze([]);
1312
+ let a = ft(t), o = e.args[1];
1313
+ if (e.name === "filter") {
1314
+ let t = [];
1315
+ for (let s = 0; s < i.length; s += 1) {
1316
+ G(n, e.start), a.item = i[s], a.index = s;
1317
+ let c = K(o, a, n, r + 1);
1318
+ if (typeof c != "boolean") throw new u("local.transform.predicate", "Function filter requires a boolean condition.", o.start);
1319
+ c && t.push(i[s]);
1320
+ }
1321
+ return q(t, e.start, n);
1322
+ }
1323
+ if (e.name === "map") {
1324
+ let t = null, s = [];
1325
+ for (let c = 0; c < i.length; c += 1) {
1326
+ G(n, e.start), a.item = i[c], a.index = c;
1327
+ let l = K(o, a, n, r + 1);
1328
+ typeof l == "string" ? (t === "number" && J(o.start), t = "string") : typeof l == "number" && Number.isFinite(l) ? (t === "string" && J(o.start), t = "number") : J(o.start), s.push(l);
1329
+ }
1330
+ return q(s, e.start, n);
1331
+ }
1332
+ return mt(e, i, a, n, r);
1333
+ } finally {
1334
+ n.active = i;
1335
+ }
1336
+ }
1337
+ function gt(e, t, n) {
1338
+ return X(e, t, {
1339
+ steps: 0,
1340
+ transformWork: 0,
1341
+ iterations: 0,
1342
+ active: !1,
1343
+ stage: n ?? null
1344
+ }, 1);
1345
+ }
1346
+ function X(e, t, n, i) {
1347
+ switch (n.steps += 1, n.steps > 1e4 && F("Expression evaluation exceeded the step limit.", e.start, "expression-budget"), i > 250 && F("Expression evaluation is nested too deeply.", e.start, "expression-budget"), I(n, 1, e.start), e.kind) {
1348
+ case "literal": return e.value;
1349
+ case "reference": return st(t, e.name, e.start, n);
1350
+ case "unary": {
1351
+ let r = X(e.operand, t, n, i + 1);
1352
+ if (e.operator === "!") return !z(r, e.start, "Logical not requires a boolean");
1353
+ let a = R(r, e.start, `Unary ${e.operator} requires a number`);
1354
+ return W(e.operator === "-" ? -a : a, e.start);
1355
+ }
1356
+ case "binary": {
1357
+ if (e.operator === "&&" || e.operator === "||") {
1358
+ let r = z(X(e.left, t, n, i + 1), e.start, "Logical operators require booleans");
1359
+ return e.operator === "&&" && !r ? !1 : e.operator === "||" && r ? !0 : z(X(e.right, t, n, i + 1), e.start, "Logical operators require booleans");
1360
+ }
1361
+ if (e.operator === "??") {
1362
+ let r = X(e.left, t, n, i + 1);
1363
+ return r === null ? X(e.right, t, n, i + 1) : r;
1364
+ }
1365
+ let r = X(e.left, t, n, i + 1), a = X(e.right, t, n, i + 1);
1366
+ switch (e.operator) {
1367
+ case "+":
1368
+ if (typeof r == "number" && typeof a == "number") return W(r + a, e.start);
1369
+ if (typeof r == "string" && typeof a == "string") {
1370
+ let t = r.length + a.length;
1371
+ return I(n, t, e.start), t > m && F("String result exceeds the length limit.", e.start, "expression-budget"), r + a;
1372
+ }
1373
+ F("Operator \"+\" requires two numbers or two strings.", e.start, "expression-type");
1374
+ case "-":
1375
+ case "*":
1376
+ case "/":
1377
+ case "%": {
1378
+ let t = R(r, e.start, `Operator "${e.operator}" requires a number`), n = R(a, e.start, `Operator "${e.operator}" requires a number`);
1379
+ return (e.operator === "/" || e.operator === "%") && n === 0 && F("Division by zero.", e.start, "expression-divide-by-zero"), W(e.operator === "-" ? t - n : e.operator === "*" ? t * n : e.operator === "/" ? t / n : t % n, e.start);
1380
+ }
1381
+ case "==":
1382
+ case "!=": {
1383
+ let t = E(r), n = E(a);
1384
+ t !== n && t !== "null" && n !== "null" && F("Equality comparison requires matching types.", e.start, "expression-type");
1385
+ let i = ut(r, a);
1386
+ return e.operator === "==" ? i : !i;
1387
+ }
1388
+ case "<":
1389
+ case "<=":
1390
+ case ">":
1391
+ case ">=": {
1392
+ let t;
1393
+ return typeof r == "number" && typeof a == "number" ? t = r === a ? 0 : r < a ? -1 : 1 : typeof r == "string" && typeof a == "string" ? t = lt(r, a, n, e.start) : F(`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;
1394
+ }
1395
+ }
1396
+ break;
1397
+ }
1398
+ case "conditional": return X(z(X(e.test, t, n, i + 1), e.start, "Conditional test must be a boolean") ? e.consequent : e.alternate, t, n, i + 1);
1399
+ case "array": {
1400
+ let r = [];
1401
+ I(n, e.elements.length, e.start);
1402
+ for (let a of e.elements) r.push(X(a, t, n, i + 1));
1403
+ return H(r, e.start);
1404
+ }
1405
+ case "index": {
1406
+ I(n, 1, e.start);
1407
+ let r = X(e.target, t, n, i + 1), a = R(X(e.index, t, n, i + 1), e.start, "Array index must be a number");
1408
+ return Number.isSafeInteger(a) || F("Array index must be a finite integer.", e.start, "expression-index"), Array.isArray(r) || F("Index access requires an array.", e.start, "expression-type"), a < 0 || a >= r.length ? null : r[a];
1409
+ }
1410
+ case "call": {
1411
+ if (e.name === "lookup") {
1412
+ let r = e.args[0];
1413
+ r.kind === "reference" && it(t, r.name) || F(`Dataset "${(r.kind === "reference" ? o(r.name) : "") ?? ""}" is not declared.`, r.start, "expression-unknown-name");
1414
+ let a = t[r.name];
1415
+ Array.isArray(a) || F("Function lookup requires a dataset.", r.start, "expression-type");
1416
+ let s = B(X(e.args[1], t, n, i + 1), e.args[1].start, "Function lookup requires a string row key"), c = B(X(e.args[2], t, n, i + 1), e.args[2].start, "Function lookup requires a string column name");
1417
+ return I(n, s.length + c.length, e.start), rt(De(a, Ee(s, c)), "lookup", e.start);
1418
+ }
1419
+ if (e.name === "filter" || e.name === "map" || e.name === "sortBy") return ht(e, t, n, i);
1420
+ let a = e.args.map((e) => X(e, t, n, i + 1));
1421
+ switch (e.name) {
1422
+ case "abs":
1423
+ case "sqrt":
1424
+ case "floor":
1425
+ case "ceil":
1426
+ case "sin":
1427
+ case "cos":
1428
+ case "tan":
1429
+ case "asin":
1430
+ case "acos":
1431
+ case "atan":
1432
+ case "exp":
1433
+ case "log": {
1434
+ let t = R(a[0], e.start, `Function ${e.name} requires a number`);
1435
+ e.name === "sqrt" && t < 0 && F("sqrt requires a non-negative argument.", e.start, "expression-domain"), e.name === "log" && t <= 0 && F("log requires a positive argument.", e.start, "expression-domain"), (e.name === "asin" || e.name === "acos") && (t < -1 || t > 1) && F(`${e.name} requires an argument between -1 and 1.`, e.start, "expression-domain");
1436
+ let n;
1437
+ switch (e.name) {
1438
+ case "abs":
1439
+ n = Math.abs(t);
1440
+ break;
1441
+ case "sqrt":
1442
+ n = Math.sqrt(t);
1443
+ break;
1444
+ case "floor":
1445
+ n = Math.floor(t);
1446
+ break;
1447
+ case "ceil":
1448
+ n = Math.ceil(t);
1449
+ break;
1450
+ case "sin":
1451
+ n = Math.sin(t);
1452
+ break;
1453
+ case "cos":
1454
+ n = Math.cos(t);
1455
+ break;
1456
+ case "tan":
1457
+ n = Math.tan(t);
1458
+ break;
1459
+ case "asin":
1460
+ n = Math.asin(t);
1461
+ break;
1462
+ case "acos":
1463
+ n = Math.acos(t);
1464
+ break;
1465
+ case "atan":
1466
+ n = Math.atan(t);
1467
+ break;
1468
+ case "exp":
1469
+ n = Math.exp(t);
1470
+ break;
1471
+ default: n = Math.log(t);
1472
+ }
1473
+ return W(n, e.start);
1474
+ }
1475
+ case "round": {
1476
+ let t = R(a[0], e.start, "Function round requires a number");
1477
+ return a[1] === void 0 ? W(Math.round(t), e.start) : ct(t, R(a[1], e.start, "Function round requires numeric fraction digits"), e.start);
1478
+ }
1479
+ case "min":
1480
+ case "max": {
1481
+ let t = R(a[0], e.start, `Function ${e.name} requires a number`);
1482
+ for (let n = 1; n < a.length; n += 1) {
1483
+ let r = R(a[n], e.start, `Function ${e.name} requires a number`);
1484
+ t = e.name === "min" ? Math.min(t, r) : Math.max(t, r);
1485
+ }
1486
+ return W(t, e.start);
1487
+ }
1488
+ case "pow": return W(R(a[0], e.start, "Function pow requires a number") ** +R(a[1], e.start, "Function pow requires a number"), e.start);
1489
+ case "clamp": {
1490
+ let t = R(a[0], e.start, "Function clamp requires a number"), n = R(a[1], e.start, "Function clamp requires a number"), r = R(a[2], e.start, "Function clamp requires a number");
1491
+ return n > r && F("clamp lower bound cannot exceed upper bound.", e.start, "expression-domain"), W(Math.min(r, Math.max(n, t)), e.start);
1492
+ }
1493
+ case "len": {
1494
+ let t = a[0];
1495
+ if (typeof t == "string") return r(t);
1496
+ if (Array.isArray(t)) return t.length;
1497
+ F("Function len requires a string or array.", e.start, "expression-type");
1498
+ }
1499
+ case "contains": {
1500
+ let t = a[0], r = a[1];
1501
+ if (typeof t == "string") return I(n, t.length, e.start), t.includes(B(r, e.start, "Function contains requires a string member"));
1502
+ if (Array.isArray(t)) {
1503
+ if (I(n, t.length, e.start), typeof r == "string") {
1504
+ for (let n of t) typeof n != "string" && F("Function contains requires a string member for a string array.", e.start, "expression-type");
1505
+ return t.includes(r);
1506
+ }
1507
+ if (typeof r == "number" && Number.isFinite(r)) {
1508
+ for (let n of t) typeof n != "number" && F("Function contains requires a numeric member for a numeric array.", e.start, "expression-type");
1509
+ return t.includes(r);
1510
+ }
1511
+ F("Function contains requires a string or numeric member.", e.start, "expression-type");
1512
+ }
1513
+ F("Function contains requires a string or array.", e.start, "expression-type");
1514
+ }
1515
+ case "number": return U(e.start, () => We(B(a[0], e.start, "Function number requires a string")));
1516
+ case "string": {
1517
+ let t = a[0];
1518
+ return t === null ? "" : typeof t == "string" ? t : typeof t == "boolean" ? t ? "true" : "false" : typeof t == "number" && Number.isFinite(t) ? String(t) : F("Function string requires a string, number, boolean or null.", e.start, "expression-type");
1519
+ }
1520
+ case "join": {
1521
+ let t = a[0];
1522
+ Array.isArray(t) || F("Function join requires a string or numeric array.", e.start, "expression-type");
1523
+ let r = a[1] === void 0 ? "," : B(a[1], e.start, "Function join requires a string separator"), i = r.length * Math.max(0, t.length - 1);
1524
+ for (let e of t) typeof e == "string" ? i += e.length : typeof e == "number" && Number.isFinite(e) && (i += String(e).length);
1525
+ return I(n, i, e.start), U(e.start, () => Ge(t, r));
1526
+ }
1527
+ case "split": {
1528
+ let t = B(a[0], e.start, "Function split requires a string"), r = B(a[1], e.start, "Function split requires a string separator");
1529
+ return I(n, t.length, e.start), H(U(e.start, () => Ke(t, r)), e.start);
1530
+ }
1531
+ case "range": {
1532
+ let t = R(a[0], e.start, "Function range requires numbers"), r = R(a[1], e.start, "Function range requires numbers"), i = a[2] === void 0 ? 1 : R(a[2], e.start, "Function range requires numbers"), o = U(e.start, () => Fe(t, r, i));
1533
+ return I(n, o.length, e.start), H(o, e.start);
1534
+ }
1535
+ case "sum": {
1536
+ let t = V(a[0], e.start, "Function sum requires a numeric array", n);
1537
+ return U(e.start, () => je(t));
1538
+ }
1539
+ case "average": {
1540
+ let t = V(a[0], e.start, "Function average requires a numeric array", n);
1541
+ return U(e.start, () => Me(t));
1542
+ }
1543
+ case "minOf": {
1544
+ let t = V(a[0], e.start, "Function minOf requires a numeric array", n);
1545
+ return U(e.start, () => Ne(t));
1546
+ }
1547
+ case "maxOf": {
1548
+ let t = V(a[0], e.start, "Function maxOf requires a numeric array", n);
1549
+ return U(e.start, () => Pe(t));
1550
+ }
1551
+ case "formatNumber": {
1552
+ let t = a[0] === null ? null : R(a[0], e.start, "Function formatNumber requires a number or null"), n = a[1] === void 0 ? 2 : R(a[1], e.start, "Function formatNumber requires numeric fraction digits"), r = a[2] === void 0 ? "en-US" : B(a[2], e.start, "Function formatNumber requires a string locale"), i = a[3] === void 0 || z(a[3], e.start, "Function formatNumber requires a boolean grouping flag");
1553
+ return U(e.start, () => Se(t, n, r, i));
1554
+ }
1555
+ case "formatPercent": {
1556
+ let t = a[0] === null ? null : R(a[0], e.start, "Function formatPercent requires a number or null"), n = a[1] === void 0 ? 0 : R(a[1], e.start, "Function formatPercent requires numeric fraction digits"), r = a[2] === void 0 ? "en-US" : B(a[2], e.start, "Function formatPercent requires a string locale");
1557
+ return U(e.start, () => Ce(t, n, r));
1558
+ }
1559
+ case "formatScientific": {
1560
+ let t = a[0] === null ? null : R(a[0], e.start, "Function formatScientific requires a number or null"), n = a[1] === void 0 ? 2 : R(a[1], e.start, "Function formatScientific requires numeric fraction digits"), r = a[2] === void 0 ? "en-US" : B(a[2], e.start, "Function formatScientific requires a string locale");
1561
+ return U(e.start, () => we(t, n, r));
1562
+ }
1563
+ case "formatCurrency": {
1564
+ let t = a[0] === null ? null : R(a[0], e.start, "Function formatCurrency requires a number or null"), n = a[1] === void 0 ? "USD" : B(a[1], e.start, "Function formatCurrency requires a string currency code"), r = a[2] === void 0 ? 2 : R(a[2], e.start, "Function formatCurrency requires numeric fraction digits"), i = a[3] === void 0 ? "en-US" : B(a[3], e.start, "Function formatCurrency requires a string locale");
1565
+ return U(e.start, () => Te(t, n, r, i));
1566
+ }
1567
+ case "trim": return U(e.start, () => M(B(a[0], e.start, "Function trim requires a string")));
1568
+ case "lower": return U(e.start, () => Ie(B(a[0], e.start, "Function lower requires a string")));
1569
+ case "upper": return U(e.start, () => Le(B(a[0], e.start, "Function upper requires a string")));
1570
+ case "startsWith": return U(e.start, () => Re(B(a[0], e.start, "Function startsWith requires a string"), B(a[1], e.start, "Function startsWith requires a string search value")));
1571
+ case "endsWith": return U(e.start, () => ze(B(a[0], e.start, "Function endsWith requires a string"), B(a[1], e.start, "Function endsWith requires a string search value")));
1572
+ case "replace": {
1573
+ let t = B(a[0], e.start, "Function replace requires a string"), n = B(a[1], e.start, "Function replace requires a string search value"), r = B(a[2], e.start, "Function replace requires a string replacement");
1574
+ return U(e.start, () => Be(t, n, r));
1575
+ }
1576
+ case "slice": {
1577
+ let t = B(a[0], e.start, "Function slice requires a string"), n = R(a[1], e.start, "Function slice requires a numeric start index"), r = a[2] === void 0 ? void 0 : R(a[2], e.start, "Function slice requires a numeric end index");
1578
+ return U(e.start, () => He(t, n, r));
1579
+ }
1580
+ case "ifBlank": {
1581
+ let t = B(a[0], e.start, "Function ifBlank requires a string"), n = B(a[1], e.start, "Function ifBlank requires a string fallback");
1582
+ return U(e.start, () => {
1583
+ let e = M(t);
1584
+ return e === "" ? n : e;
1585
+ });
1586
+ }
1587
+ case "dateCompare": {
1588
+ let t = B(a[0], e.start, "Function dateCompare requires a date string"), n = B(a[1], e.start, "Function dateCompare requires a date string");
1589
+ return U(e.start, () => Ye(t, n));
1590
+ }
1591
+ case "dateDiff": {
1592
+ let t = B(a[0], e.start, "Function dateDiff requires a date string"), n = B(a[1], e.start, "Function dateDiff requires a date string"), r = a[2] === void 0 ? "days" : B(a[2], e.start, "Function dateDiff requires a string unit");
1593
+ return U(e.start, () => Xe(t, n, r));
1594
+ }
1595
+ case "dateAdd": {
1596
+ let t = B(a[0], e.start, "Function dateAdd requires a date string"), n = R(a[1], e.start, "Function dateAdd requires a numeric amount"), r = a[2] === void 0 ? "days" : B(a[2], e.start, "Function dateAdd requires a string unit");
1597
+ return U(e.start, () => Ze(t, n, r));
1598
+ }
1599
+ case "formatDate": {
1600
+ let t = B(a[0], e.start, "Function formatDate requires a date string"), n = a[1] === void 0 ? "en-US" : B(a[1], e.start, "Function formatDate requires a string locale");
1601
+ return U(e.start, () => Qe(t, n));
1602
+ }
1603
+ }
1604
+ break;
1605
+ }
1606
+ }
1607
+ throw new u("expression-eval", "Unsupported expression.", 0);
1608
+ }
1609
+ // src/local/evaluation/expression/transform-budget.ts
1610
+ function _t() {
1611
+ return { work: 0 };
1612
+ }
1613
+ var Z;
1614
+ function vt() {
1615
+ return Z;
1616
+ }
1617
+ function yt(e, t) {
1618
+ let n = Z;
1619
+ Z = e;
1620
+ try {
1621
+ return t();
1622
+ } finally {
1623
+ Z = n;
1624
+ }
1625
+ }
1626
+ // src/local/evaluation/expression/compile.ts
1627
+ var Q = e, bt = 500, $ = /* @__PURE__ */ new Map(), xt = /* @__PURE__ */ new WeakMap();
1628
+ function St(e, t) {
1629
+ return xt.get(e)?.get(t);
1630
+ }
1631
+ function Ct(e) {
1632
+ if (typeof e != "string") throw new u("expression-syntax", "Expression must be a string.", 0);
1633
+ if (e.length > 4e3) throw new u("expression-budget", `Expression exceeds the ${ie}-character limit.`, 0);
1634
+ let t = $.get(e);
1635
+ if (t) return t;
1636
+ let n = new g(e), r = n.parse(), i = [...n.dependencies], a = Object.freeze({
1637
+ source: e,
1638
+ dependencies: i,
1639
+ evaluate(e, t) {
1640
+ return gt(r, e, t);
1641
+ },
1642
+ inferType(e) {
1643
+ return k(r, e);
1644
+ }
1645
+ });
1646
+ if ($.size >= bt) {
1647
+ let e = $.keys().next().value;
1648
+ e !== void 0 && $.delete(e);
1649
+ }
1650
+ return xt.set(a, n.dependencyOffsets), $.set(e, a), a;
1651
+ }
1652
+ function wt(e) {
1653
+ if (e.length > Q) throw new u("expression-budget", "Interpolation template exceeds the length limit.", 0);
1654
+ let t = [], n = 0;
1655
+ for (;;) {
1656
+ let r = e.indexOf("{{", n);
1657
+ if (r < 0) {
1658
+ n < e.length && t.push({
1659
+ kind: "text",
1660
+ value: e.slice(n)
1661
+ });
1662
+ break;
1663
+ }
1664
+ r > n && t.push({
1665
+ kind: "text",
1666
+ value: e.slice(n, r)
1667
+ });
1668
+ let i = r + 2, a = "", o = !1;
1669
+ for (; i < e.length;) {
1670
+ let t = e[i];
1671
+ if (a !== "") {
1672
+ if (t === "\\") {
1673
+ i += 2;
1674
+ continue;
1675
+ }
1676
+ t === a && (a = ""), i += 1;
1677
+ } else if (t === "\"" || t === "'") a = t, i += 1;
1678
+ else {
1679
+ if (t === "{" && e[i + 1] === "{") throw new u("expression-interpolation", "Interpolations cannot be nested.", i);
1680
+ if (t === "}" && e[i + 1] === "}") {
1681
+ o = !0;
1682
+ break;
1683
+ }
1684
+ i += 1;
1685
+ }
1686
+ }
1687
+ if (!o) throw new u("expression-interpolation", "Interpolation is missing }}.", r);
1688
+ let s = e.slice(r + 2, i);
1689
+ if (s.trim() === "") throw new u("expression-empty", "Interpolation expression is empty.", r + 2);
1690
+ t.push({
1691
+ kind: "expression",
1692
+ source: s,
1693
+ start: r + 2
1694
+ }), n = i + 2;
1695
+ }
1696
+ return t;
1697
+ }
1698
+ function Tt(e) {
1699
+ try {
1700
+ return Ct(e.source);
1701
+ } catch (t) {
1702
+ throw t instanceof u ? new u(t.code, t.message, e.start + t.offset) : t;
1703
+ }
1704
+ }
1705
+ function Et(e, t, n, r) {
1706
+ try {
1707
+ return e.evaluate(t, r);
1708
+ } catch (e) {
1709
+ throw e instanceof u ? new u(e.code, e.message, n + e.offset) : e;
1710
+ }
1711
+ }
1712
+ function Dt(e, t) {
1713
+ if (e === null) return "";
1714
+ if (typeof e == "string") return e;
1715
+ if (typeof e == "number") {
1716
+ if (!Number.isFinite(e)) throw new u("expression-value", "Cannot display a non-finite number.", t);
1717
+ return String(e);
1718
+ }
1719
+ if (typeof e == "boolean") return e ? "true" : "false";
1720
+ throw Array.isArray(e) ? new u("expression-type", "Cannot insert an array as text; convert it with a function such as len first.", t) : new u("expression-type", "Cannot display this value as text.", t);
1721
+ }
1722
+ function Ot(e, t, n) {
1723
+ let r = [], i = 0;
1724
+ for (let a of e) {
1725
+ let e;
1726
+ if (e = a.kind === "text" ? a.value : Dt(Et(Tt(a), t, a.start, n), a.start), i += e.length, i > m) throw new u("expression-budget", "Interpolation result exceeds the length limit.", 0);
1727
+ r.push(e);
1728
+ }
1729
+ return r.join("");
1730
+ }
1731
+ function kt(e, t, n) {
1732
+ if (typeof e != "string") throw new u("expression-interpolation", "Interpolation template must be a string.", 0);
1733
+ if (e.length > Q) throw new u("expression-budget", `Interpolation template exceeds the ${Q}-character limit.`, 0);
1734
+ return e.includes("{{") ? Ot(wt(e), t, n) : e;
1735
+ }
1736
+ function At(e) {
1737
+ if (typeof e != "string") throw new u("expression-interpolation", "Interpolation template must be a string.", 0);
1738
+ let t = /* @__PURE__ */ new Set();
1739
+ for (let n of wt(e)) if (n.kind === "expression") for (let e of Tt(n).dependencies) t.add(e);
1740
+ return [...t];
1741
+ }
1742
+ export { u as _, _t as a, oe as b, at as c, Se as d, Ce as f, de as g, g as h, At as i, Ee as l, me as m, St as n, vt as o, we as p, kt as r, yt as s, Ct as t, Te as u, ie as v, ae as x, re as y };