@fluidgrids/fe-sdk 0.0.0-stage → 2026.1203.8

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 (323) hide show
  1. package/README.md +564 -2
  2. package/dist/ActivityOptionsFields-C2u-hY2U.js +142 -0
  3. package/dist/AiStudioPage-B_hNTj-_.js +1137 -0
  4. package/dist/ApprovalInboxPage-ClITra3n.js +1312 -0
  5. package/dist/ChoiceSelect-LkK-uS9J.js +65 -0
  6. package/dist/ConfirmActionDialog-DHWTDRbp.js +31 -0
  7. package/dist/ConnectionFormDialog-C0kDgcrZ.js +153 -0
  8. package/dist/CreateFluidgridsTagDocument-Dtp9KPLJ.js +1055 -0
  9. package/dist/DataSinkDashboardPage-b4ezeqa6.js +278 -0
  10. package/dist/DataTablesPage-C1d9YGHz.js +5575 -0
  11. package/dist/DateTimeField-B1qR4ruo.js +51 -0
  12. package/dist/Disclosure-BNKij7-v.js +45 -0
  13. package/dist/ElementLibraryPage-8jNO6YmE.js +2256 -0
  14. package/dist/ElementLibrarySequenceDocument-B-W8SPzn.js +3979 -0
  15. package/dist/EnsureThemeProvider-BvlNjAd0.js +24 -0
  16. package/dist/EntityTagBadge-1OlP6p0c.js +25 -0
  17. package/dist/EntityTagPicker-BBrU5cE0.js +137 -0
  18. package/dist/ExecuteStepDocument-B4j1mdRT.js +189 -0
  19. package/dist/ExecutionDetailDocument-D6QuM-kp.js +875 -0
  20. package/dist/ExecutionDetailPage-D4CBtFdo.js +12217 -0
  21. package/dist/ExecutionDetailPage-DvQ667OE.d.ts +10 -0
  22. package/dist/ExecutionStatusBadge-BsDVor9t.js +221 -0
  23. package/dist/ExecutionsListDocument-Dan7ZiqB.js +459 -0
  24. package/dist/ExecutionsListPage-B3XT8ITL.js +4307 -0
  25. package/dist/FailureTriagePanel-DOJMaJ0n.js +1285 -0
  26. package/dist/FileDownloadUrlDocument-CVOYKcL5.js +92 -0
  27. package/dist/FluidGridsDocsLink-bX0Hnhxr.js +66 -0
  28. package/dist/FluidGridsMark-CE2blT7K.js +74 -0
  29. package/dist/HeldLoadRegion-BtTxbvOW.js +34 -0
  30. package/dist/HistoryPage-BLoRpJ1R.d.ts +6 -0
  31. package/dist/HistoryPage-BSBISXoj.js +2835 -0
  32. package/dist/Icon-BtQ0HXLh.js +160 -0
  33. package/dist/InsightsPage-D7ybj8N9.js +11245 -0
  34. package/dist/IsolationSetting-vy911E8b.js +1153 -0
  35. package/dist/LibraryParts-DOeNgR8A.js +413 -0
  36. package/dist/ManagedAiPolicyAuthority-BxwJ3ptd.js +40 -0
  37. package/dist/ManagedAiPolicyAuthority-DM3t3wNr.d.ts +18 -0
  38. package/dist/ManagedAiPolicyAuthorityContext-CNkxIOZ1.js +10 -0
  39. package/dist/McpTriggerServers-BCPCAOWB.js +459 -0
  40. package/dist/MissingNodesInstallModal-rO_SEDrC.js +224 -0
  41. package/dist/NavigationV2Provider-DCDt35eG.js +17 -0
  42. package/dist/NodeSchemaIntrospectionDocument-C1vAIcHd.js +95 -0
  43. package/dist/NodesPage-DEbnz9iU.d.ts +6 -0
  44. package/dist/NodesPage-O7KeeKtd.js +653 -0
  45. package/dist/OfflineIcon-TwMKYWjA.js +207 -0
  46. package/dist/OpenTemplateAsCodeButton-BhWJWIF3.js +94 -0
  47. package/dist/PaidTemplateConfirm-_G3ag6S4.js +28 -0
  48. package/dist/PublishCustomNodeAction-CIySbK4c.js +134 -0
  49. package/dist/RecordTaskDialog-BkpCDvhR.js +2078 -0
  50. package/dist/RunActionsMenu-DodOgIQm.js +59 -0
  51. package/dist/RunnerStatusPill-C1v967iq.js +24 -0
  52. package/dist/RunnersPage-dB0RSdY_.js +1929 -0
  53. package/dist/SandboxRuntimeExhaustedNotice-BFOIF93C.js +120 -0
  54. package/dist/SchedulesPage-DPWr1yvf.js +1607 -0
  55. package/dist/SearchBox-BGtYjvfs.js +49 -0
  56. package/dist/SequenceEditor-CFiHeHkR.js +497 -0
  57. package/dist/SettingsPage-0CQBNPZV.js +8695 -0
  58. package/dist/StewardPages-DAJhepen.js +47 -0
  59. package/dist/StewardRunImportPanel-Kva2DO0u.js +2844 -0
  60. package/dist/StoreTemplateCardCompact-CHn5kP7A.js +2166 -0
  61. package/dist/TagFilterSelect-CyA8QrS7.js +42 -0
  62. package/dist/TaskQueuesPage-DdnDCyat.js +3571 -0
  63. package/dist/TechnicalDetails-B0Oi4aZw.js +19 -0
  64. package/dist/TemplateConfigurationModal-CdvCYJLM.js +332 -0
  65. package/dist/TemplateDetailPanel-CbiKciuB.js +222 -0
  66. package/dist/TemplatePreview-cx7-NOeG.js +868 -0
  67. package/dist/TemplatesPage-BG3H-6v6.d.ts +10 -0
  68. package/dist/TemplatesPage-BVQpGYIV.js +3251 -0
  69. package/dist/TerminateExecutionDocument-B_HKNVrN.js +581 -0
  70. package/dist/TranslationBridge-Bd4aJKMs.d.ts +11 -0
  71. package/dist/TranslationBridge-Da-TPgQm.js +68 -0
  72. package/dist/TriggerWorkflowDocument-D9Km2Vv2.js +460 -0
  73. package/dist/UiSequencePickerSequenceDocument-BSYnSDV7.js +607 -0
  74. package/dist/UiStepScreenshot-Qh4QMyUp.js +146 -0
  75. package/dist/UsageTimeSeriesDocument-DcInx9-z.js +177 -0
  76. package/dist/VariablesPage-ChfGuW22.js +2243 -0
  77. package/dist/VersionDiffDialog-Bd2AeUwf.js +1702 -0
  78. package/dist/VersionLifecycleBar-BBeWVtz-.js +143 -0
  79. package/dist/WebhookDeliveriesPage-D66bua0j.js +1563 -0
  80. package/dist/WorkflowBuilder-B6wQD1TK.js +539 -0
  81. package/dist/WorkflowBuilder-DR4ku8Tr.js +1611 -0
  82. package/dist/WorkflowDefinitionDocument-DZLbTPUZ.js +321 -0
  83. package/dist/WorkflowEmbed-BXfFGy0i.js +708 -0
  84. package/dist/WorkflowEmbed-Cbqe1s1z.d.ts +6 -0
  85. package/dist/WorkflowPinnedDataDocument-BODT5omd.js +782 -0
  86. package/dist/WorkflowProposalCard-BruukdeF.js +96 -0
  87. package/dist/WorkflowProposalDocument-BdUbsrd0.js +620 -0
  88. package/dist/WorkflowSearchRedirect-C7zJ2MKH.js +40 -0
  89. package/dist/WorkflowSettingsDrawer-MVU1BKfY.d.ts +18 -0
  90. package/dist/WorkflowSettingsDrawer-gazs97WR.js +196 -0
  91. package/dist/WorkflowShareDialog-e8jJtLjU.js +469 -0
  92. package/dist/WorkflowVersionsDocument-DRVOp8Uj.js +3213 -0
  93. package/dist/WorkflowsList--hR2_8gf.js +4593 -0
  94. package/dist/WorkflowsList-CcNDQge5.d.ts +6 -0
  95. package/dist/WorkflowsListPageDocument-CnzcQm_o.js +934 -0
  96. package/dist/addonCatalog-CbZS4deh.js +58 -0
  97. package/dist/addonCatalog-sjlonAmR.d.ts +15 -0
  98. package/dist/addons.d.ts +3 -0
  99. package/dist/addons.js +4 -0
  100. package/dist/agent-form-Bfvm32j1.js +83 -0
  101. package/dist/agent-tools.d.ts +3 -0
  102. package/dist/agent-tools.js +5 -0
  103. package/dist/agentTools-CyL7DLOF.js +320 -0
  104. package/dist/ai-usage-BrxDgvdR.js +240 -0
  105. package/dist/aiCreditsBridge-BuE92tKo.js +49 -0
  106. package/dist/api-BKq-nIOZ.js +2286 -0
  107. package/dist/api-Ol7I8NxE.js +8289 -0
  108. package/dist/apollo-type-policies.d.ts +11 -0
  109. package/dist/apollo-type-policies.js +64 -0
  110. package/dist/askAboutBridge-ByYsQams.js +106 -0
  111. package/dist/askQuestions-Cmx7VnMm.js +742 -0
  112. package/dist/assert-rules-lfYEMc99.js +318 -0
  113. package/dist/assistant.d.ts +94 -0
  114. package/dist/assistant.js +99 -0
  115. package/dist/attach-node-helpers-HDKQOtrD.js +32 -0
  116. package/dist/badge-CXfPhoMH.js +26 -0
  117. package/dist/basil.generated-BK-EHbwN.js +10 -0
  118. package/dist/browser-steps-DMpS5TyB.js +533 -0
  119. package/dist/builderTimings-pvGnK1m-.js +510 -0
  120. package/dist/button-DG7y_FVJ.js +48 -0
  121. package/dist/canvasNoteTools-BxuP_AYO.js +137 -0
  122. package/dist/card-Bomy_1UG.js +44 -0
  123. package/dist/catalogGrid-BOrfMgi-.js +41 -0
  124. package/dist/channel-CPyQ1NR1.js +212 -0
  125. package/dist/chips-CvNrYJZa.js +27 -0
  126. package/dist/client-holder-C0M5Cfwl.js +68 -0
  127. package/dist/cn-QqidFIgr.js +10 -0
  128. package/dist/code-editor-diagnostics-Zr0cIcx1.js +46 -0
  129. package/dist/code-editor-field-x_JrY8KR.js +113 -0
  130. package/dist/codec-client-DPuD6mw7.js +515 -0
  131. package/dist/conditionBuilder-DwfEF0Q-.js +1144 -0
  132. package/dist/config-DO68jw5k.js +322 -0
  133. package/dist/constants-DgbVc24O.d.ts +296 -0
  134. package/dist/constants-DlRnHBfQ.js +217 -0
  135. package/dist/convert-browser-action-pfecelF7.js +347 -0
  136. package/dist/convert-dialog-B_o22NiJ.js +382 -0
  137. package/dist/create-workflow-first-Azg3JUdX.js +120 -0
  138. package/dist/definition-canvas-Bsda-rDT.js +31 -0
  139. package/dist/dialog-BVd152GS.js +94 -0
  140. package/dist/durable-nodes-BXyYCLxT.js +91 -0
  141. package/dist/duration-CDb7-mT_.js +33 -0
  142. package/dist/edge-mapper-wEAdGVU2.js +4477 -0
  143. package/dist/element-library-DkSlg_VE.js +727 -0
  144. package/dist/entities-I_0kio3q.js +38 -0
  145. package/dist/error-advice-QLr5NCm7.js +65 -0
  146. package/dist/errors-ClKb5sEt.js +188 -0
  147. package/dist/executions.d.ts +3 -0
  148. package/dist/executions.js +5 -0
  149. package/dist/feature-flags-B2qetXKd.js +385 -0
  150. package/dist/field-label-DPZRmE_B.js +153 -0
  151. package/dist/firstWorkflow-C_h0KMB2.js +133 -0
  152. package/dist/flags.d.ts +3 -0
  153. package/dist/flags.js +4 -0
  154. package/dist/flow-builder-DIvLOhz0.js +28038 -0
  155. package/dist/flow-store-holder-CUN7Terz.js +52 -0
  156. package/dist/fluent.generated-CA_e6-4l.js +14 -0
  157. package/dist/fluidgridsEvents-bbEQbwU6.js +175 -0
  158. package/dist/fluidgridsTheme-DUhvOgoy.js +297 -0
  159. package/dist/global-client-BQPuFrFa.js +433 -0
  160. package/dist/global-operations-BG6YgxrM.js +136 -0
  161. package/dist/graphql-types-UTYtujY9.js +21358 -0
  162. package/dist/history.d.ts +3 -0
  163. package/dist/history.js +4 -0
  164. package/dist/index-AoJAa5vU.d.ts +164958 -0
  165. package/dist/index-DEMT3iAM.d.ts +120 -0
  166. package/dist/index-ROZzNGyY.d.ts +76 -0
  167. package/dist/index.d.ts +20 -0
  168. package/dist/index.js +8123 -0
  169. package/dist/ion.generated-mbajjcAg.js +10 -0
  170. package/dist/label-Lzb8ZXf_.js +29 -0
  171. package/dist/labels-rXd9gYQz.js +1236 -0
  172. package/dist/liveCanvas-D5ytXDp8.js +103 -0
  173. package/dist/logos.generated-X6_0kjVR.js +21 -0
  174. package/dist/logs-panel-Cw0DkG0l.js +468 -0
  175. package/dist/lucide.generated-B6NVd3GT.js +29 -0
  176. package/dist/marksStore-a9oIMMot.js +175 -0
  177. package/dist/mcp-trigger-D0nRdvq5.js +307 -0
  178. package/dist/mdi.generated-D1BV74d6.js +292 -0
  179. package/dist/menus-CU3hDGYl.js +160 -0
  180. package/dist/mynaui.generated-DMWr5cXz.js +66 -0
  181. package/dist/navigation-v2.d.ts +3 -0
  182. package/dist/navigation-v2.js +5 -0
  183. package/dist/node-detail-view-Cgm5H1P-.js +1372 -0
  184. package/dist/node-editor-tab-body-CZ0fVuVP.js +187 -0
  185. package/dist/node-operation-selection-CdV3KI_V.js +3534 -0
  186. package/dist/node-registry-refresh-s3okf83X.js +27 -0
  187. package/dist/node-role-TMbnkmeP.js +132 -0
  188. package/dist/node-type-icon-BZa8n4iG.js +33 -0
  189. package/dist/nodes.d.ts +3 -0
  190. package/dist/nodes.js +4 -0
  191. package/dist/notesKey-5EaREBGA.js +12 -0
  192. package/dist/observability.d.ts +3 -0
  193. package/dist/observability.js +5 -0
  194. package/dist/offset-pages-zghoClB3.js +55 -0
  195. package/dist/operations-BBmT9ToP.js +663 -0
  196. package/dist/operations-WxRJWeqO.js +3133 -0
  197. package/dist/output-files-Ba8bu5lv.js +196 -0
  198. package/dist/page-operation-DrWuhd6Y.js +129 -0
  199. package/dist/page-twins.d.ts +13 -0
  200. package/dist/page-twins.js +186 -0
  201. package/dist/pageControlSpecs-DZJ9K37m.js +134 -0
  202. package/dist/pageControlsBridge-0pX9s-3k.js +54 -0
  203. package/dist/pageControlsBridge-DAuT3w7L.d.ts +36 -0
  204. package/dist/panels-PfBBAToE.js +346 -0
  205. package/dist/parts-B7fBcw-B.js +346 -0
  206. package/dist/popover-Dms9Vz3j.js +3389 -0
  207. package/dist/preloadable-lazy-Pp47mqQ9.js +65 -0
  208. package/dist/proactive.d.ts +66 -0
  209. package/dist/proactive.js +237 -0
  210. package/dist/quick-config-panel-DFd77xho.js +451 -0
  211. package/dist/quota-DeA_CJ2e.js +175 -0
  212. package/dist/quota.d.ts +3 -0
  213. package/dist/quota.js +4 -0
  214. package/dist/read-only-context-Dt9N9SIG.js +18 -0
  215. package/dist/relative-time-Dxt8ZIIu.js +55 -0
  216. package/dist/results-CwK_yDxK.js +325 -0
  217. package/dist/rolldown-runtime-hDbaFkMy.js +18 -0
  218. package/dist/route-data.d.ts +12 -0
  219. package/dist/route-data.js +69 -0
  220. package/dist/route-match-C-0_EnAt.d.ts +5 -0
  221. package/dist/route-match-DMkUICYV.js +41 -0
  222. package/dist/route-preload-C4DlGoCd.js +120 -0
  223. package/dist/run-display-UjLAoYqQ.js +81 -0
  224. package/dist/run-history-arGiHzGU.js +285 -0
  225. package/dist/run-list-links-DJn4Mf1T.js +98 -0
  226. package/dist/run-mode-USmM0-Uo.js +82 -0
  227. package/dist/run-parity-CWXqEJqM.js +144 -0
  228. package/dist/runsQuota-B6SyTbne.js +100 -0
  229. package/dist/runsQuota-DsniKiSg.d.ts +20 -0
  230. package/dist/safe-expression-Cw7-SCsm.js +1251 -0
  231. package/dist/save-status-store-C7nEYpfb.js +631 -0
  232. package/dist/schedule-panel-B4GYXzXQ.js +13774 -0
  233. package/dist/schedule-rules-ggVKRkBH.js +358 -0
  234. package/dist/secrets-Re_wSiE3.js +153 -0
  235. package/dist/settings.d.ts +4 -0
  236. package/dist/settings.js +6 -0
  237. package/dist/shared-DAWGGMSM.js +177 -0
  238. package/dist/sidebar-node-editor-6eSSgCzc.js +178 -0
  239. package/dist/solar.generated-CGYuUQAC.js +10 -0
  240. package/dist/stableTabbedDialog-BBhrfXGe.js +20 -0
  241. package/dist/start-url-CT6Yz96K.js +24 -0
  242. package/dist/status-CessxGpm.js +55 -0
  243. package/dist/store-icon-OctYp5zP.js +155 -0
  244. package/dist/styles-WGmTnZ2n.js +26 -0
  245. package/dist/styles.css +139 -0
  246. package/dist/svg-spinners.generated-CIPT7IhM.js +10 -0
  247. package/dist/template-code-CzN6JWNV.js +191 -0
  248. package/dist/template-graph-DLF9dygU.js +20 -0
  249. package/dist/template-preview-DcIIKOOL.js +32 -0
  250. package/dist/template-price-CdUHZRMF.js +40 -0
  251. package/dist/templates.d.ts +3 -0
  252. package/dist/templates.js +5 -0
  253. package/dist/theme-provider-CntfC4_i.js +23 -0
  254. package/dist/transient-DgZfhDfN.js +57 -0
  255. package/dist/typed-calls-C5tO03wq.js +26 -0
  256. package/dist/ui-script-By74Guk3.js +1094 -0
  257. package/dist/ui-script-editor-CqPu2bCN.js +2447 -0
  258. package/dist/ui-step-fix-8uM2_Hft.js +67 -0
  259. package/dist/ui-step-fix-store-CcO1FdRx.js +19 -0
  260. package/dist/ui-step-run-context-o7bLE6KP.js +46 -0
  261. package/dist/ui-target-editor-D2JhB_lD.js +673 -0
  262. package/dist/uiMarkTools-CSznnO1i.js +1054 -0
  263. package/dist/upgradePrompt-BAFBKKW5.js +72 -0
  264. package/dist/use-bare-node-registry-O6mKJO_n.js +11498 -0
  265. package/dist/use-browser-available-hj8wc3Kb.js +241 -0
  266. package/dist/use-edge-mapper-schemas-Bonofxow.js +496 -0
  267. package/dist/use-extension-bridge-B9ZreOkQ.js +608 -0
  268. package/dist/use-mobile-BTqCUjzS.js +27 -0
  269. package/dist/use-sdk-query-C697xZVv.js +116 -0
  270. package/dist/use-workflow-code-editor-CFoRFrZ5.js +753 -0
  271. package/dist/useActionParam-B2tU2BlY.js +85 -0
  272. package/dist/useAgentTokenStream-Bko_J0d0.js +4217 -0
  273. package/dist/useBrowserClients-3v95-gSh.js +103 -0
  274. package/dist/useCodeWorkflowInsights-w0tz9Ap_.js +600 -0
  275. package/dist/useConnections-DsgEJs05.js +439 -0
  276. package/dist/useDebouncedValue-BFekcv6n.js +18 -0
  277. package/dist/useDurableParity-8fnMZmBc.js +1787 -0
  278. package/dist/useEntityTags-D0spL6Ut.js +460 -0
  279. package/dist/useExecutions-2u5nGJJk.js +681 -0
  280. package/dist/useFluidGridsAnalytics-VM8lAi2x.js +238 -0
  281. package/dist/useGlobalStoreClient-BTdhkA2I.js +24 -0
  282. package/dist/useHumanRequests-zlYDp3l1.js +221 -0
  283. package/dist/useNavigationV2-C2WeqN7d.js +29 -0
  284. package/dist/useNavigationV2-DANUmg12.d.ts +9 -0
  285. package/dist/useObservability-BRlQ0tOA.js +285 -0
  286. package/dist/useRequestedProposal-B7uPXfZB.js +51 -0
  287. package/dist/useRunHistory-CXCMUPyf.js +2759 -0
  288. package/dist/useRunLive-D0JvVZT2.js +1060 -0
  289. package/dist/useRunnerList-Dbi59i1K.js +446 -0
  290. package/dist/useRunners-URUc5quU.js +173 -0
  291. package/dist/useRunsPage-DG656UCK.js +2709 -0
  292. package/dist/useVariables-BIelxcWr.js +463 -0
  293. package/dist/useVersionHistoryData-CTjqVw7l.js +292 -0
  294. package/dist/useWorkflowCodeExport-pqxyLHD1.js +522 -0
  295. package/dist/useWorkflowListExport-hcZNvTaB.js +232 -0
  296. package/dist/useWorkflowOrganization-CpBbOrs7.js +1772 -0
  297. package/dist/useWorkflowProposal-BH0VdNMA.js +3280 -0
  298. package/dist/useWorkflows-Cvg-Z_IE.js +1606 -0
  299. package/dist/utils-fvBb5qOD.js +89 -0
  300. package/dist/webhook-deliveries-AvQujaZy.js +99 -0
  301. package/dist/workflow-builder-CJygVkVv.d.ts +2 -0
  302. package/dist/workflow-builder.d.ts +3 -0
  303. package/dist/workflow-builder.js +8 -0
  304. package/dist/workflow-code-transfer-Bsy0JKAZ.js +323 -0
  305. package/dist/workflow-embed.d.ts +3 -0
  306. package/dist/workflow-embed.js +4 -0
  307. package/dist/workflow-git-sync--K9ZsPDC.js +263 -0
  308. package/dist/workflow-host.d.ts +6 -0
  309. package/dist/workflow-host.js +11 -0
  310. package/dist/workflow-pages-D-7ByLTB.d.ts +68 -0
  311. package/dist/workflow-pages.d.ts +3 -0
  312. package/dist/workflow-pages.js +115 -0
  313. package/dist/workflow-preview-canvas-CO8yzdE3.js +848 -0
  314. package/dist/workflow-preview.d.ts +65 -0
  315. package/dist/workflow-preview.js +4 -0
  316. package/dist/workflow-route.d.ts +33 -0
  317. package/dist/workflow-route.js +4 -0
  318. package/dist/workflow-save-state-D0l-DkLf.js +767 -0
  319. package/dist/workflow-transfer-CQnQC-ke.js +104 -0
  320. package/dist/workflowRouteData-BkfVOc-O.js +169 -0
  321. package/dist/workflows-list.d.ts +10 -0
  322. package/dist/workflows-list.js +5 -0
  323. package/package.json +320 -4
@@ -0,0 +1,1251 @@
1
+ "use client";
2
+ // src/builder/components/lib/safe-expression.ts
3
+ /**
4
+ * Safe expression interpreter for builder previews (BOFF-16938)
5
+ * =============================================================
6
+ * The builder previews `{{ }}` and `${...}` formulas while the author types.
7
+ * Those formulas come from workflow definitions, which can be imported,
8
+ * shared, pasted or published by someone else, so they are untrusted code.
9
+ * They used to be compiled with the Function constructor and run in the app page,
10
+ * next to the login tokens in `localStorage`. That allowed account takeover.
11
+ *
12
+ * This module never compiles or runs JavaScript. It parses a formula into a
13
+ * small syntax tree and walks that tree itself:
14
+ *
15
+ * - Names resolve only against the scope the caller passes in. `window`,
16
+ * `document`, `localStorage`, `fetch`, `globalThis` and `this` do not
17
+ * exist here.
18
+ * - Property reads refuse the keys that lead back to `Function` or to
19
+ * prototypes (`constructor`, `prototype`, `__proto__`, `__lookupGetter__`
20
+ * and the like), whether written as `.key` or computed as `["key"]`.
21
+ * - The globals handed to formulas are frozen facades, not the real
22
+ * `Object`, `Math`, `JSON`, ... objects, so a formula cannot reach
23
+ * `Object.getPrototypeOf` / `getOwnPropertyDescriptor` / `defineProperty`
24
+ * and cannot overwrite a method the rest of the app relies on.
25
+ * - Every value read, called or returned is checked against a set of
26
+ * host values that must never surface (`Function`, `eval`, `globalThis`,
27
+ * storage, network APIs), as a final layer behind the two above.
28
+ * - Assignment, `++`/`--`, `delete`, statement bodies, `this`, tagged
29
+ * templates, classes and function declarations are not part of the
30
+ * grammar at all.
31
+ * - A step budget, an input-length cap and a nesting cap bound the work.
32
+ *
33
+ * The supported grammar is the expression subset formulas use in practice:
34
+ * literals (numbers, strings, template literals, regular expressions),
35
+ * arrays and objects (with spread), member access and calls (with optional
36
+ * chaining), `new` for Date / Array / RegExp, unary, binary, logical and
37
+ * conditional operators, and arrow functions with an expression body.
38
+ *
39
+ * Real workflow execution never uses this: it runs server-side in the
40
+ * worker's vm sandbox. This is the browser preview only, and it needs no
41
+ * `'unsafe-eval'` in the Content-Security-Policy.
42
+ */
43
+ /** The formula is not valid in the supported expression grammar. */
44
+ var ExpressionSyntaxError = class extends Error {
45
+ constructor(message) {
46
+ super(message);
47
+ this.name = "ExpressionSyntaxError";
48
+ }
49
+ };
50
+ /** The formula tried to reach something formulas are not allowed to touch. */
51
+ var UnsafeExpressionError = class extends Error {
52
+ constructor(message) {
53
+ super(message);
54
+ this.name = "UnsafeExpressionError";
55
+ }
56
+ };
57
+ /** The formula did more work than a preview is allowed to do. */
58
+ var ExpressionBudgetError = class extends Error {
59
+ constructor(message) {
60
+ super(message);
61
+ this.name = "ExpressionBudgetError";
62
+ }
63
+ };
64
+ /** Longest formula the preview will parse. */
65
+ const MAX_EXPRESSION_LENGTH = 1e4;
66
+ /** Deepest syntax nesting the parser accepts (guards the call stack). */
67
+ const MAX_NESTING_DEPTH = 200;
68
+ /** Default number of evaluation steps before a preview gives up. */
69
+ const DEFAULT_MAX_STEPS = 1e5;
70
+ /** Longest first, so `===` wins over `==` and `=`. */
71
+ const PUNCTUATORS = [
72
+ ">>>",
73
+ "===",
74
+ "!==",
75
+ "...",
76
+ "**",
77
+ "?.",
78
+ "??",
79
+ "=>",
80
+ "==",
81
+ "!=",
82
+ "<=",
83
+ ">=",
84
+ "&&",
85
+ "||",
86
+ "<<",
87
+ ">>",
88
+ "++",
89
+ "--",
90
+ "+",
91
+ "-",
92
+ "*",
93
+ "/",
94
+ "%",
95
+ "<",
96
+ ">",
97
+ "!",
98
+ "~",
99
+ "&",
100
+ "|",
101
+ "^",
102
+ "?",
103
+ ":",
104
+ ",",
105
+ ".",
106
+ "(",
107
+ ")",
108
+ "[",
109
+ "]",
110
+ "{",
111
+ "}",
112
+ "=",
113
+ "`"
114
+ ];
115
+ /** Binary operator precedence (higher binds tighter). */
116
+ const BINARY_PRECEDENCE = {
117
+ "??": 1,
118
+ "||": 1,
119
+ "&&": 2,
120
+ "|": 3,
121
+ "^": 4,
122
+ "&": 5,
123
+ "==": 6,
124
+ "!=": 6,
125
+ "===": 6,
126
+ "!==": 6,
127
+ "<": 7,
128
+ ">": 7,
129
+ "<=": 7,
130
+ ">=": 7,
131
+ in: 7,
132
+ instanceof: 7,
133
+ "<<": 8,
134
+ ">>": 8,
135
+ ">>>": 8,
136
+ "+": 9,
137
+ "-": 9,
138
+ "*": 10,
139
+ "/": 10,
140
+ "%": 10,
141
+ "**": 11
142
+ };
143
+ /** Words that are syntax, not variable names. */
144
+ const UNSUPPORTED_WORDS = /* @__PURE__ */ new Set([
145
+ "this",
146
+ "super",
147
+ "function",
148
+ "class",
149
+ "delete",
150
+ "await",
151
+ "yield",
152
+ "async",
153
+ "import",
154
+ "export",
155
+ "var",
156
+ "let",
157
+ "const",
158
+ "return",
159
+ "if",
160
+ "else",
161
+ "for",
162
+ "while",
163
+ "do",
164
+ "switch",
165
+ "case",
166
+ "break",
167
+ "continue",
168
+ "throw",
169
+ "try",
170
+ "catch",
171
+ "finally",
172
+ "with",
173
+ "debugger"
174
+ ]);
175
+ const NAME_START = /[\p{L}\p{Nl}_$]/u;
176
+ const NAME_PART = /[\p{L}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}_$‌‍]/u;
177
+ const NUMBER_PATTERN = /^(?:0[xX][0-9a-fA-F]+|0[bB][01]+|0[oO][0-7]+|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)/;
178
+ var Parser = class {
179
+ src;
180
+ pos = 0;
181
+ depth = 0;
182
+ cached = null;
183
+ /** The position `cached` was lexed from; the cache is valid only there. */
184
+ cachedAt = -1;
185
+ constructor(src) {
186
+ this.src = src;
187
+ }
188
+ parse() {
189
+ const expression = this.parseExpression();
190
+ const rest = this.peek();
191
+ if (rest.kind !== "eof") throw this.unexpected(rest);
192
+ return expression;
193
+ }
194
+ skipTrivia() {
195
+ const { src } = this;
196
+ while (this.pos < src.length) {
197
+ const c = src[this.pos];
198
+ if (c === " " || c === " " || c === "\n" || c === "\r") this.pos++;
199
+ else if (c === "/" && src[this.pos + 1] === "/") {
200
+ const nl = src.indexOf("\n", this.pos + 2);
201
+ this.pos = nl === -1 ? src.length : nl + 1;
202
+ } else if (c === "/" && src[this.pos + 1] === "*") {
203
+ const close = src.indexOf("*/", this.pos + 2);
204
+ if (close === -1) throw new ExpressionSyntaxError("Unclosed comment");
205
+ this.pos = close + 2;
206
+ } else if (/\s/u.test(c)) this.pos++;
207
+ else break;
208
+ }
209
+ }
210
+ peek() {
211
+ if (this.cached && this.cachedAt === this.pos) return this.cached;
212
+ const from = this.pos;
213
+ this.skipTrivia();
214
+ const token = this.lex(this.pos);
215
+ this.pos = from;
216
+ this.cached = token;
217
+ this.cachedAt = from;
218
+ return token;
219
+ }
220
+ next() {
221
+ const token = this.peek();
222
+ this.pos = token.end;
223
+ this.cached = null;
224
+ return token;
225
+ }
226
+ isPunct(token, value) {
227
+ return token.kind === "punct" && token.value === value;
228
+ }
229
+ isName(token, value) {
230
+ return token.kind === "name" && token.value === value;
231
+ }
232
+ expectPunct(value) {
233
+ const token = this.next();
234
+ if (!this.isPunct(token, value)) throw new ExpressionSyntaxError(`Expected "${value}" but found ${this.describe(token)}`);
235
+ }
236
+ describe(token) {
237
+ return token.kind === "eof" ? "the end of the expression" : `"${this.src.slice(token.start, token.end)}"`;
238
+ }
239
+ unexpected(token) {
240
+ return new ExpressionSyntaxError(`Unexpected ${this.describe(token)}`);
241
+ }
242
+ lex(start) {
243
+ const { src } = this;
244
+ if (start >= src.length) return {
245
+ kind: "eof",
246
+ value: "",
247
+ start,
248
+ end: start
249
+ };
250
+ const c = src[start];
251
+ if (/\d/.test(c) || c === "." && /\d/.test(src[start + 1] ?? "")) {
252
+ const match = NUMBER_PATTERN.exec(src.slice(start));
253
+ if (!match) throw new ExpressionSyntaxError("Invalid number");
254
+ const end = start + match[0].length;
255
+ if (end < src.length && NAME_PART.test(src[end])) throw new ExpressionSyntaxError(`Invalid number "${src.slice(start, end + 1)}"`);
256
+ return {
257
+ kind: "num",
258
+ value: Number(match[0]),
259
+ start,
260
+ end
261
+ };
262
+ }
263
+ if (c === "\"" || c === "'") {
264
+ const { value, end } = this.readString(start, c);
265
+ return {
266
+ kind: "str",
267
+ value,
268
+ start,
269
+ end
270
+ };
271
+ }
272
+ if (NAME_START.test(c)) {
273
+ let end = start + 1;
274
+ while (end < src.length && NAME_PART.test(src[end])) end++;
275
+ return {
276
+ kind: "name",
277
+ value: src.slice(start, end),
278
+ start,
279
+ end
280
+ };
281
+ }
282
+ for (const punct of PUNCTUATORS) if (src.startsWith(punct, start)) {
283
+ if (punct === "?." && /\d/.test(src[start + 2] ?? "")) continue;
284
+ return {
285
+ kind: "punct",
286
+ value: punct,
287
+ start,
288
+ end: start + punct.length
289
+ };
290
+ }
291
+ throw new ExpressionSyntaxError(`Unexpected character "${c}"`);
292
+ }
293
+ /** Reads one escape sequence starting after the backslash. */
294
+ readEscape(at) {
295
+ const { src } = this;
296
+ const c = src[at];
297
+ switch (c) {
298
+ case "n": return {
299
+ value: "\n",
300
+ end: at + 1
301
+ };
302
+ case "t": return {
303
+ value: " ",
304
+ end: at + 1
305
+ };
306
+ case "r": return {
307
+ value: "\r",
308
+ end: at + 1
309
+ };
310
+ case "b": return {
311
+ value: "\b",
312
+ end: at + 1
313
+ };
314
+ case "f": return {
315
+ value: "\f",
316
+ end: at + 1
317
+ };
318
+ case "v": return {
319
+ value: "\v",
320
+ end: at + 1
321
+ };
322
+ case "0":
323
+ if (!/\d/.test(src[at + 1] ?? "")) return {
324
+ value: "\0",
325
+ end: at + 1
326
+ };
327
+ throw new ExpressionSyntaxError("Octal escapes are not supported");
328
+ case "x": {
329
+ const hex = src.slice(at + 1, at + 3);
330
+ if (!/^[0-9a-fA-F]{2}$/.test(hex)) throw new ExpressionSyntaxError("Invalid \\x escape");
331
+ return {
332
+ value: String.fromCharCode(parseInt(hex, 16)),
333
+ end: at + 3
334
+ };
335
+ }
336
+ case "u": {
337
+ if (src[at + 1] === "{") {
338
+ const close = src.indexOf("}", at + 2);
339
+ const hex = close === -1 ? "" : src.slice(at + 2, close);
340
+ const code = parseInt(hex, 16);
341
+ if (!/^[0-9a-fA-F]{1,6}$/.test(hex) || code > 1114111) throw new ExpressionSyntaxError("Invalid \\u{...} escape");
342
+ return {
343
+ value: String.fromCodePoint(code),
344
+ end: close + 1
345
+ };
346
+ }
347
+ const hex = src.slice(at + 1, at + 5);
348
+ if (!/^[0-9a-fA-F]{4}$/.test(hex)) throw new ExpressionSyntaxError("Invalid \\u escape");
349
+ return {
350
+ value: String.fromCharCode(parseInt(hex, 16)),
351
+ end: at + 5
352
+ };
353
+ }
354
+ case "\r": return {
355
+ value: "",
356
+ end: src[at + 1] === "\n" ? at + 2 : at + 1
357
+ };
358
+ case "\n":
359
+ case "\u2028":
360
+ case "\u2029": return {
361
+ value: "",
362
+ end: at + 1
363
+ };
364
+ case void 0: throw new ExpressionSyntaxError("Unterminated escape sequence");
365
+ default: return {
366
+ value: c,
367
+ end: at + 1
368
+ };
369
+ }
370
+ }
371
+ readString(start, quote) {
372
+ const { src } = this;
373
+ let value = "";
374
+ let at = start + 1;
375
+ while (at < src.length) {
376
+ const c = src[at];
377
+ if (c === quote) return {
378
+ value,
379
+ end: at + 1
380
+ };
381
+ if (c === "\n" || c === "\r") break;
382
+ if (c === "\\") {
383
+ const escaped = this.readEscape(at + 1);
384
+ value += escaped.value;
385
+ at = escaped.end;
386
+ } else {
387
+ value += c;
388
+ at++;
389
+ }
390
+ }
391
+ throw new ExpressionSyntaxError("Unterminated string");
392
+ }
393
+ enter() {
394
+ if (++this.depth > MAX_NESTING_DEPTH) throw new ExpressionSyntaxError("Expression is nested too deeply");
395
+ }
396
+ leave() {
397
+ this.depth--;
398
+ }
399
+ parseExpression() {
400
+ this.enter();
401
+ try {
402
+ if (this.isArrowAhead()) return this.parseArrow();
403
+ return this.parseConditional();
404
+ } finally {
405
+ this.leave();
406
+ }
407
+ }
408
+ /** Looks ahead (without consuming) for `x =>` or `(a, b) =>`. */
409
+ isArrowAhead() {
410
+ const savedPos = this.pos;
411
+ const savedCache = this.cached;
412
+ const savedCachedAt = this.cachedAt;
413
+ try {
414
+ const first = this.peek();
415
+ if (first.kind === "name" && !UNSUPPORTED_WORDS.has(first.value)) {
416
+ this.next();
417
+ return this.isPunct(this.peek(), "=>");
418
+ }
419
+ if (!this.isPunct(first, "(")) return false;
420
+ this.next();
421
+ if (this.isPunct(this.peek(), ")")) {
422
+ this.next();
423
+ return this.isPunct(this.peek(), "=>");
424
+ }
425
+ for (;;) {
426
+ if (this.peek().kind !== "name") return false;
427
+ this.next();
428
+ const sep = this.next();
429
+ if (this.isPunct(sep, ")")) break;
430
+ if (!this.isPunct(sep, ",")) return false;
431
+ }
432
+ return this.isPunct(this.peek(), "=>");
433
+ } catch {
434
+ return false;
435
+ } finally {
436
+ this.pos = savedPos;
437
+ this.cached = savedCache;
438
+ this.cachedAt = savedCachedAt;
439
+ }
440
+ }
441
+ parseArrow() {
442
+ const params = /* @__PURE__ */ new Set();
443
+ const first = this.next();
444
+ if (first.kind === "name") params.add(first.value);
445
+ else {
446
+ while (!this.isPunct(this.peek(), ")")) {
447
+ const param = this.next();
448
+ if (param.kind !== "name" || UNSUPPORTED_WORDS.has(param.value)) throw this.unexpected(param);
449
+ if (params.has(param.value)) throw new ExpressionSyntaxError(`Duplicate parameter name "${param.value}"`);
450
+ params.add(param.value);
451
+ if (this.isPunct(this.peek(), ",")) this.next();
452
+ }
453
+ this.next();
454
+ }
455
+ this.expectPunct("=>");
456
+ if (this.isPunct(this.peek(), "{")) throw new ExpressionSyntaxError("Arrow functions with a { } body are not supported in the preview; use an expression body, for example x => x * 2 or x => ({ id: x })");
457
+ return {
458
+ type: "Arrow",
459
+ params: [...params],
460
+ body: this.parseExpression()
461
+ };
462
+ }
463
+ parseConditional() {
464
+ const test = this.parseBinary(1);
465
+ if (!this.isPunct(this.peek(), "?")) return test;
466
+ this.next();
467
+ const consequent = this.parseExpression();
468
+ this.expectPunct(":");
469
+ return {
470
+ type: "Conditional",
471
+ test,
472
+ consequent,
473
+ alternate: this.parseExpression()
474
+ };
475
+ }
476
+ binaryOperator(token) {
477
+ if (token.kind === "punct" && token.value in BINARY_PRECEDENCE) return token.value;
478
+ if (token.kind === "name" && (token.value === "in" || token.value === "instanceof")) return token.value;
479
+ return null;
480
+ }
481
+ parseBinary(minPrecedence) {
482
+ this.enter();
483
+ try {
484
+ let left = this.parseUnary();
485
+ for (;;) {
486
+ const token = this.peek();
487
+ if (this.isPunct(token, "=")) throw new ExpressionSyntaxError("Assignment is not supported in expressions");
488
+ const operator = this.binaryOperator(token);
489
+ if (!operator) break;
490
+ const precedence = BINARY_PRECEDENCE[operator];
491
+ if (precedence < minPrecedence) break;
492
+ this.next();
493
+ const right = this.parseBinary(operator === "**" ? precedence : precedence + 1);
494
+ left = operator === "&&" || operator === "||" || operator === "??" ? {
495
+ type: "Logical",
496
+ operator,
497
+ left,
498
+ right
499
+ } : {
500
+ type: "Binary",
501
+ operator,
502
+ left,
503
+ right
504
+ };
505
+ }
506
+ return left;
507
+ } finally {
508
+ this.leave();
509
+ }
510
+ }
511
+ parseUnary() {
512
+ const token = this.peek();
513
+ if (this.isPunct(token, "++") || this.isPunct(token, "--")) throw new ExpressionSyntaxError(`"${token.value}" is not supported in expressions`);
514
+ const unaryOperator = token.kind === "punct" && [
515
+ "!",
516
+ "-",
517
+ "+",
518
+ "~"
519
+ ].includes(token.value) || token.kind === "name" && (token.value === "typeof" || token.value === "void") ? token.value : null;
520
+ if (unaryOperator !== null) {
521
+ this.next();
522
+ this.enter();
523
+ try {
524
+ return {
525
+ type: "Unary",
526
+ operator: unaryOperator,
527
+ argument: this.parseUnary()
528
+ };
529
+ } finally {
530
+ this.leave();
531
+ }
532
+ }
533
+ return this.parsePostfix();
534
+ }
535
+ parseArguments() {
536
+ this.expectPunct("(");
537
+ const args = [];
538
+ while (!this.isPunct(this.peek(), ")")) {
539
+ args.push(this.parseElement());
540
+ if (!this.isPunct(this.peek(), ")")) this.expectPunct(",");
541
+ }
542
+ this.next();
543
+ return args;
544
+ }
545
+ parseElement() {
546
+ if (this.isPunct(this.peek(), "...")) {
547
+ this.next();
548
+ return {
549
+ type: "Spread",
550
+ argument: this.parseExpression()
551
+ };
552
+ }
553
+ return this.parseExpression();
554
+ }
555
+ parsePropertyName() {
556
+ const token = this.next();
557
+ if (token.kind !== "name") throw this.unexpected(token);
558
+ return {
559
+ type: "Literal",
560
+ value: token.value
561
+ };
562
+ }
563
+ parseNew() {
564
+ this.next();
565
+ this.enter();
566
+ try {
567
+ let callee = this.isName(this.peek(), "new") ? this.parseNew() : this.parsePrimary();
568
+ for (;;) {
569
+ const token = this.peek();
570
+ if (this.isPunct(token, ".")) {
571
+ this.next();
572
+ callee = {
573
+ type: "Member",
574
+ object: callee,
575
+ property: this.parsePropertyName(),
576
+ computed: false,
577
+ optional: false
578
+ };
579
+ } else if (this.isPunct(token, "[")) {
580
+ this.next();
581
+ const property = this.parseExpression();
582
+ this.expectPunct("]");
583
+ callee = {
584
+ type: "Member",
585
+ object: callee,
586
+ property,
587
+ computed: true,
588
+ optional: false
589
+ };
590
+ } else break;
591
+ }
592
+ const args = this.isPunct(this.peek(), "(") ? this.parseArguments() : [];
593
+ return {
594
+ type: "New",
595
+ callee,
596
+ args
597
+ };
598
+ } finally {
599
+ this.leave();
600
+ }
601
+ }
602
+ parsePostfix() {
603
+ let expression = this.isName(this.peek(), "new") ? this.parseNew() : this.parsePrimary();
604
+ let hasOptional = false;
605
+ for (;;) {
606
+ const token = this.peek();
607
+ if (this.isPunct(token, ".")) {
608
+ this.next();
609
+ expression = {
610
+ type: "Member",
611
+ object: expression,
612
+ property: this.parsePropertyName(),
613
+ computed: false,
614
+ optional: false
615
+ };
616
+ } else if (this.isPunct(token, "?.")) {
617
+ this.next();
618
+ hasOptional = true;
619
+ const after = this.peek();
620
+ if (this.isPunct(after, "(")) expression = {
621
+ type: "Call",
622
+ callee: expression,
623
+ args: this.parseArguments(),
624
+ optional: true
625
+ };
626
+ else if (this.isPunct(after, "[")) {
627
+ this.next();
628
+ const property = this.parseExpression();
629
+ this.expectPunct("]");
630
+ expression = {
631
+ type: "Member",
632
+ object: expression,
633
+ property,
634
+ computed: true,
635
+ optional: true
636
+ };
637
+ } else expression = {
638
+ type: "Member",
639
+ object: expression,
640
+ property: this.parsePropertyName(),
641
+ computed: false,
642
+ optional: true
643
+ };
644
+ } else if (this.isPunct(token, "[")) {
645
+ this.next();
646
+ const property = this.parseExpression();
647
+ this.expectPunct("]");
648
+ expression = {
649
+ type: "Member",
650
+ object: expression,
651
+ property,
652
+ computed: true,
653
+ optional: false
654
+ };
655
+ } else if (this.isPunct(token, "(")) expression = {
656
+ type: "Call",
657
+ callee: expression,
658
+ args: this.parseArguments(),
659
+ optional: false
660
+ };
661
+ else if (this.isPunct(token, "++") || this.isPunct(token, "--")) throw new ExpressionSyntaxError(`"${token.value}" is not supported in expressions`);
662
+ else break;
663
+ }
664
+ return hasOptional ? {
665
+ type: "Chain",
666
+ expression
667
+ } : expression;
668
+ }
669
+ parsePrimary() {
670
+ this.skipTrivia();
671
+ const c = this.src[this.pos];
672
+ if (c === "`") return this.parseTemplate();
673
+ if (c === "/") return this.parseRegExp();
674
+ const token = this.next();
675
+ switch (token.kind) {
676
+ case "num":
677
+ case "str": return {
678
+ type: "Literal",
679
+ value: token.value
680
+ };
681
+ case "name":
682
+ if (token.value === "true") return {
683
+ type: "Literal",
684
+ value: true
685
+ };
686
+ if (token.value === "false") return {
687
+ type: "Literal",
688
+ value: false
689
+ };
690
+ if (token.value === "null") return {
691
+ type: "Literal",
692
+ value: null
693
+ };
694
+ if (UNSUPPORTED_WORDS.has(token.value)) throw new ExpressionSyntaxError(`"${token.value}" is not supported in expressions`);
695
+ return {
696
+ type: "Identifier",
697
+ name: token.value
698
+ };
699
+ case "punct":
700
+ if (token.value === "(") {
701
+ const inner = this.parseExpression();
702
+ this.expectPunct(")");
703
+ return inner;
704
+ }
705
+ if (token.value === "[") return this.parseArrayLiteral();
706
+ if (token.value === "{") return this.parseObjectLiteral();
707
+ throw this.unexpected(token);
708
+ default: throw this.unexpected(token);
709
+ }
710
+ }
711
+ parseArrayLiteral() {
712
+ const elements = [];
713
+ while (!this.isPunct(this.peek(), "]")) {
714
+ if (this.isPunct(this.peek(), ",")) throw new ExpressionSyntaxError("Array holes are not supported in expressions");
715
+ elements.push(this.parseElement());
716
+ if (!this.isPunct(this.peek(), "]")) this.expectPunct(",");
717
+ }
718
+ this.next();
719
+ return {
720
+ type: "ArrayLiteral",
721
+ elements
722
+ };
723
+ }
724
+ parseObjectLiteral() {
725
+ const properties = [];
726
+ while (!this.isPunct(this.peek(), "}")) {
727
+ if (this.isPunct(this.peek(), "...")) {
728
+ this.next();
729
+ properties.push({
730
+ type: "Spread",
731
+ argument: this.parseExpression()
732
+ });
733
+ } else {
734
+ const keyToken = this.next();
735
+ let key;
736
+ let computed = false;
737
+ if (keyToken.kind === "name") key = {
738
+ type: "Literal",
739
+ value: keyToken.value
740
+ };
741
+ else if (keyToken.kind === "str") key = {
742
+ type: "Literal",
743
+ value: keyToken.value
744
+ };
745
+ else if (keyToken.kind === "num") key = {
746
+ type: "Literal",
747
+ value: String(keyToken.value)
748
+ };
749
+ else if (this.isPunct(keyToken, "[")) {
750
+ key = this.parseExpression();
751
+ computed = true;
752
+ this.expectPunct("]");
753
+ } else throw this.unexpected(keyToken);
754
+ const after = this.peek();
755
+ if (this.isPunct(after, ":")) {
756
+ this.next();
757
+ properties.push({
758
+ type: "Property",
759
+ key,
760
+ computed,
761
+ value: this.parseExpression()
762
+ });
763
+ } else if (keyToken.kind === "name" && (this.isPunct(after, ",") || this.isPunct(after, "}"))) {
764
+ if (UNSUPPORTED_WORDS.has(keyToken.value)) throw this.unexpected(keyToken);
765
+ properties.push({
766
+ type: "Property",
767
+ key,
768
+ computed: false,
769
+ value: {
770
+ type: "Identifier",
771
+ name: keyToken.value
772
+ }
773
+ });
774
+ } else if (this.isPunct(after, "(")) throw new ExpressionSyntaxError("Object methods are not supported in expressions; use an arrow function value");
775
+ else throw this.unexpected(after);
776
+ }
777
+ if (!this.isPunct(this.peek(), "}")) this.expectPunct(",");
778
+ }
779
+ this.next();
780
+ return {
781
+ type: "ObjectLiteral",
782
+ properties
783
+ };
784
+ }
785
+ parseTemplate() {
786
+ const { src } = this;
787
+ this.pos++;
788
+ this.cached = null;
789
+ const quasis = [];
790
+ const expressions = [];
791
+ let chunk = "";
792
+ for (;;) {
793
+ if (this.pos >= src.length) throw new ExpressionSyntaxError("Unterminated template literal");
794
+ const c = src[this.pos];
795
+ if (c === "`") {
796
+ this.pos++;
797
+ quasis.push(chunk);
798
+ return {
799
+ type: "Template",
800
+ quasis,
801
+ expressions
802
+ };
803
+ }
804
+ if (c === "\\") {
805
+ const escaped = this.readEscape(this.pos + 1);
806
+ chunk += escaped.value;
807
+ this.pos = escaped.end;
808
+ } else if (c === "$" && src[this.pos + 1] === "{") {
809
+ quasis.push(chunk);
810
+ chunk = "";
811
+ this.pos += 2;
812
+ expressions.push(this.parseExpression());
813
+ const close = this.peek();
814
+ if (!this.isPunct(close, "}")) throw new ExpressionSyntaxError(`Expected "}" in template literal but found ${this.describe(close)}`);
815
+ this.pos = close.end;
816
+ this.cached = null;
817
+ } else {
818
+ chunk += c;
819
+ this.pos++;
820
+ }
821
+ }
822
+ }
823
+ parseRegExp() {
824
+ const { src } = this;
825
+ let at = this.pos + 1;
826
+ let inClass = false;
827
+ let pattern = "";
828
+ for (;;) {
829
+ const c = src[at];
830
+ if (c === void 0 || c === "\n" || c === "\r") throw new ExpressionSyntaxError("Unterminated regular expression");
831
+ if (c === "\\") {
832
+ pattern += c + (src[at + 1] ?? "");
833
+ at += 2;
834
+ continue;
835
+ }
836
+ if (c === "[") inClass = true;
837
+ else if (c === "]") inClass = false;
838
+ else if (c === "/" && !inClass) break;
839
+ pattern += c;
840
+ at++;
841
+ }
842
+ at++;
843
+ let flags = "";
844
+ while (at < src.length && /[a-z]/i.test(src[at])) flags += src[at++];
845
+ try {
846
+ new RegExp(pattern, flags);
847
+ } catch (error) {
848
+ throw new ExpressionSyntaxError(error instanceof Error ? error.message : "Invalid regular expression");
849
+ }
850
+ this.pos = at;
851
+ this.cached = null;
852
+ return {
853
+ type: "RegExpLiteral",
854
+ pattern,
855
+ flags
856
+ };
857
+ }
858
+ };
859
+ /** A frozen, prototype-less copy of selected members of a host object. */
860
+ function frozenFacade(members) {
861
+ const facade = Object.create(null);
862
+ for (const [key, value] of Object.entries(members)) facade[key] = value;
863
+ return Object.freeze(facade);
864
+ }
865
+ /** A frozen callable facade with static members attached. */
866
+ function callableFacade(call, statics) {
867
+ for (const [key, value] of Object.entries(statics)) Object.defineProperty(call, key, {
868
+ value,
869
+ enumerable: true
870
+ });
871
+ return Object.freeze(call);
872
+ }
873
+ function pick(source, keys) {
874
+ const out = {};
875
+ for (const key of keys) out[key] = source[key];
876
+ return out;
877
+ }
878
+ /**
879
+ * `Object.assign` for formulas: only onto a plain, unfrozen object or array,
880
+ * so it cannot change a function (a built-in method the app shares) or a
881
+ * frozen facade.
882
+ */
883
+ function safeAssign(target, ...sources) {
884
+ if (target === null || typeof target !== "object" || Object.isFrozen(target) || FORBIDDEN_VALUES.has(target)) throw new TypeError("Object.assign in expressions needs a plain object or array as its target");
885
+ return Object.assign(target, ...sources);
886
+ }
887
+ const SafeMath = frozenFacade(pick(Math, Object.getOwnPropertyNames(Math)));
888
+ const SafeJSON = frozenFacade({
889
+ parse: (text, reviver) => JSON.parse(String(text), typeof reviver === "function" ? reviver : void 0),
890
+ stringify: (value, replacer, space) => {
891
+ const indent = typeof space === "number" || typeof space === "string" ? space : void 0;
892
+ if (typeof replacer === "function") return JSON.stringify(value, replacer, indent);
893
+ if (Array.isArray(replacer)) return JSON.stringify(value, replacer, indent);
894
+ return JSON.stringify(value, void 0, indent);
895
+ }
896
+ });
897
+ const SafeObject = frozenFacade({
898
+ keys: (value) => Object.keys(Object(value)),
899
+ values: (value) => Object.values(Object(value)),
900
+ entries: (value) => Object.entries(Object(value)),
901
+ fromEntries: (entries) => Object.fromEntries(entries),
902
+ hasOwn: (value, key) => Object.prototype.hasOwnProperty.call(Object(value), String(key)),
903
+ is: (a, b) => Object.is(a, b),
904
+ assign: safeAssign
905
+ });
906
+ const SafeString = callableFacade((...args) => args.length ? String(args[0]) : "", pick(String, ["fromCharCode", "fromCodePoint"]));
907
+ const SafeNumber = callableFacade((...args) => args.length ? Number(args[0]) : 0, pick(Number, [
908
+ "isFinite",
909
+ "isInteger",
910
+ "isNaN",
911
+ "isSafeInteger",
912
+ "parseFloat",
913
+ "parseInt",
914
+ "EPSILON",
915
+ "MAX_SAFE_INTEGER",
916
+ "MIN_SAFE_INTEGER",
917
+ "MAX_VALUE",
918
+ "MIN_VALUE",
919
+ "NaN",
920
+ "NEGATIVE_INFINITY",
921
+ "POSITIVE_INFINITY"
922
+ ]));
923
+ const SafeBoolean = callableFacade((value) => Boolean(value), {});
924
+ const SafeArray = callableFacade((...args) => Array(...args), pick(Array, [
925
+ "isArray",
926
+ "from",
927
+ "of"
928
+ ]));
929
+ const SafeDate = callableFacade(() => (/* @__PURE__ */ new Date()).toString(), pick(Date, [
930
+ "now",
931
+ "parse",
932
+ "UTC"
933
+ ]));
934
+ const SafeRegExp = callableFacade((pattern, flags) => new RegExp(pattern instanceof RegExp ? pattern : String(pattern), flags === void 0 ? void 0 : String(flags)), {});
935
+ /** Facades that `new` may construct, mapped to the host constructor. */
936
+ const CONSTRUCTIBLE = /* @__PURE__ */ new Map([
937
+ [SafeDate, Date],
938
+ [SafeArray, Array],
939
+ [SafeRegExp, RegExp]
940
+ ]);
941
+ const noop = () => void 0;
942
+ /**
943
+ * The globals formulas may use. Frozen facades only: none of these is the
944
+ * real host object, so a formula can neither reach prototype tools such as
945
+ * `Object.getPrototypeOf` nor change what the rest of the app sees.
946
+ */
947
+ const SAFE_EXPRESSION_GLOBALS = Object.freeze({
948
+ undefined: void 0,
949
+ NaN: NaN,
950
+ Infinity: Infinity,
951
+ parseInt,
952
+ parseFloat,
953
+ isNaN,
954
+ isFinite,
955
+ encodeURIComponent,
956
+ decodeURIComponent,
957
+ encodeURI,
958
+ decodeURI,
959
+ Number: SafeNumber,
960
+ String: SafeString,
961
+ Boolean: SafeBoolean,
962
+ Array: SafeArray,
963
+ Object: SafeObject,
964
+ Date: SafeDate,
965
+ RegExp: SafeRegExp,
966
+ JSON: SafeJSON,
967
+ Math: SafeMath,
968
+ console: frozenFacade({
969
+ log: noop,
970
+ info: noop,
971
+ warn: noop,
972
+ error: noop
973
+ })
974
+ });
975
+ /** Property keys that lead to constructors, prototypes or accessors. */
976
+ const BLOCKED_KEYS = /* @__PURE__ */ new Set([
977
+ "constructor",
978
+ "prototype",
979
+ "__proto__",
980
+ "__defineGetter__",
981
+ "__defineSetter__",
982
+ "__lookupGetter__",
983
+ "__lookupSetter__",
984
+ "caller",
985
+ "callee",
986
+ "arguments"
987
+ ]);
988
+ function hostValue(read) {
989
+ try {
990
+ return read();
991
+ } catch {
992
+ return;
993
+ }
994
+ }
995
+ /**
996
+ * The host's global object, indexed by name. `typeof globalThis` has no index
997
+ * signature, so it is widened through `unknown` to read optional browser
998
+ * globals (window, storage, fetch) that may not exist in every runtime.
999
+ */
1000
+ const hostGlobals = globalThis;
1001
+ /**
1002
+ * Host values that must never be read, called or returned by a formula,
1003
+ * whatever path led to them. This is the last layer: the key block-list and
1004
+ * the facades above already keep formulas away from all of these.
1005
+ */
1006
+ const FORBIDDEN_VALUES = new Set([
1007
+ Function,
1008
+ Object.getPrototypeOf(async () => void 0)?.constructor,
1009
+ Object.getPrototypeOf(function* () {})?.constructor,
1010
+ Object.getPrototypeOf(async function* () {})?.constructor,
1011
+ Function.prototype,
1012
+ Object.prototype,
1013
+ Array.prototype,
1014
+ String.prototype,
1015
+ Number.prototype,
1016
+ Object,
1017
+ Reflect,
1018
+ Proxy,
1019
+ globalThis,
1020
+ hostValue(() => hostGlobals.eval),
1021
+ hostValue(() => hostGlobals.window),
1022
+ hostValue(() => hostGlobals.self),
1023
+ hostValue(() => hostGlobals.document),
1024
+ hostValue(() => hostGlobals.localStorage),
1025
+ hostValue(() => hostGlobals.sessionStorage),
1026
+ hostValue(() => hostGlobals.indexedDB),
1027
+ hostValue(() => hostGlobals.fetch),
1028
+ hostValue(() => hostGlobals.XMLHttpRequest),
1029
+ hostValue(() => hostGlobals.navigator),
1030
+ hostValue(() => hostGlobals.location)
1031
+ ].filter((value) => value !== void 0 && value !== null));
1032
+ function assertSafeKey(key) {
1033
+ if (BLOCKED_KEYS.has(key) || key.startsWith("__") && key.endsWith("__")) throw new UnsafeExpressionError(`Property "${key}" is not available in expressions`);
1034
+ }
1035
+ function guard(value) {
1036
+ if ((typeof value === "object" || typeof value === "function") && value !== null && FORBIDDEN_VALUES.has(value)) throw new UnsafeExpressionError("This value is not available in expressions");
1037
+ return value;
1038
+ }
1039
+ function toPropertyKey(value) {
1040
+ if (typeof value === "symbol") throw new UnsafeExpressionError("Symbol keys are not available in expressions");
1041
+ return String(value);
1042
+ }
1043
+ /** Marks an optional chain that hit null/undefined (becomes `undefined`). */
1044
+ const SHORT_CIRCUIT = Symbol("short-circuit");
1045
+ var Evaluator = class {
1046
+ root;
1047
+ maxSteps;
1048
+ steps = 0;
1049
+ constructor(root, maxSteps) {
1050
+ this.root = root;
1051
+ this.maxSteps = maxSteps;
1052
+ }
1053
+ run(node) {
1054
+ const value = this.evaluate(node, null);
1055
+ return value === SHORT_CIRCUIT ? void 0 : guard(value);
1056
+ }
1057
+ tick() {
1058
+ if (++this.steps > this.maxSteps) throw new ExpressionBudgetError("Expression needs too many steps to preview");
1059
+ }
1060
+ has(name, env) {
1061
+ for (let scope = env; scope; scope = scope.parent) if (scope.vars.has(name)) return true;
1062
+ return Object.prototype.hasOwnProperty.call(this.root, name);
1063
+ }
1064
+ lookup(name, env) {
1065
+ for (let scope = env; scope; scope = scope.parent) if (scope.vars.has(name)) return scope.vars.get(name);
1066
+ if (Object.prototype.hasOwnProperty.call(this.root, name)) return guard(this.root[name]);
1067
+ throw new ReferenceError(`${name} is not defined`);
1068
+ }
1069
+ readMember(object, key) {
1070
+ if (object === null || object === void 0) throw new TypeError(`Cannot read properties of ${String(object)} (reading '${key}')`);
1071
+ assertSafeKey(key);
1072
+ guard(object);
1073
+ return guard(object[key]);
1074
+ }
1075
+ memberKey(node, env) {
1076
+ return toPropertyKey(node.computed ? this.evaluate(node.property, env) : node.property.value);
1077
+ }
1078
+ spreadValues(value) {
1079
+ if (value === null || value === void 0 || typeof value[Symbol.iterator] !== "function") throw new TypeError(`${String(value)} is not iterable`);
1080
+ return Array.from(value, (item) => guard(item));
1081
+ }
1082
+ evaluateElements(elements, env) {
1083
+ const out = [];
1084
+ for (const element of elements) if (element.type === "Spread") out.push(...this.spreadValues(this.evaluate(element.argument, env)));
1085
+ else out.push(this.evaluate(element, env));
1086
+ return out;
1087
+ }
1088
+ evaluate(node, env) {
1089
+ this.tick();
1090
+ switch (node.type) {
1091
+ case "Literal": return node.value;
1092
+ case "Template": {
1093
+ let out = node.quasis[0] ?? "";
1094
+ node.expressions.forEach((expression, i) => {
1095
+ out += String(this.evaluate(expression, env));
1096
+ out += node.quasis[i + 1] ?? "";
1097
+ });
1098
+ return out;
1099
+ }
1100
+ case "RegExpLiteral": return new RegExp(node.pattern, node.flags);
1101
+ case "Identifier": return this.lookup(node.name, env);
1102
+ case "ArrayLiteral": return this.evaluateElements(node.elements, env);
1103
+ case "ObjectLiteral": {
1104
+ const out = {};
1105
+ const define = (key, value) => {
1106
+ Object.defineProperty(out, key, {
1107
+ value,
1108
+ enumerable: true,
1109
+ writable: true,
1110
+ configurable: true
1111
+ });
1112
+ };
1113
+ for (const property of node.properties) if (property.type === "Spread") {
1114
+ const source = this.evaluate(property.argument, env);
1115
+ if (source === null || source === void 0) continue;
1116
+ const boxed = Object(source);
1117
+ for (const key of Object.keys(boxed)) define(key, guard(boxed[key]));
1118
+ } else define(toPropertyKey(this.evaluate(property.key, env)), this.evaluate(property.value, env));
1119
+ return out;
1120
+ }
1121
+ case "Chain": {
1122
+ const value = this.evaluate(node.expression, env);
1123
+ return value === SHORT_CIRCUIT ? void 0 : value;
1124
+ }
1125
+ case "Member": {
1126
+ const object = this.evaluate(node.object, env);
1127
+ if (object === SHORT_CIRCUIT) return SHORT_CIRCUIT;
1128
+ if (node.optional && (object === null || object === void 0)) return SHORT_CIRCUIT;
1129
+ return this.readMember(object, this.memberKey(node, env));
1130
+ }
1131
+ case "Call": {
1132
+ let thisArg;
1133
+ let callee;
1134
+ if (node.callee.type === "Member") {
1135
+ const object = this.evaluate(node.callee.object, env);
1136
+ if (object === SHORT_CIRCUIT) return SHORT_CIRCUIT;
1137
+ if (node.callee.optional && (object === null || object === void 0)) return SHORT_CIRCUIT;
1138
+ thisArg = object;
1139
+ callee = this.readMember(object, this.memberKey(node.callee, env));
1140
+ } else {
1141
+ callee = this.evaluate(node.callee, env);
1142
+ if (callee === SHORT_CIRCUIT) return SHORT_CIRCUIT;
1143
+ }
1144
+ if (node.optional && (callee === null || callee === void 0)) return SHORT_CIRCUIT;
1145
+ if (typeof callee !== "function") throw new TypeError(`${describeCallee(node.callee)} is not a function`);
1146
+ guard(callee);
1147
+ const args = this.evaluateElements(node.args, env);
1148
+ return guard(Reflect.apply(callee, thisArg, args));
1149
+ }
1150
+ case "New": {
1151
+ const callee = this.evaluate(node.callee, env);
1152
+ const constructor = CONSTRUCTIBLE.get(callee);
1153
+ if (!constructor) throw new TypeError(`${describeCallee(node.callee)} cannot be used with "new" in expressions (only Date, Array and RegExp can)`);
1154
+ const args = this.evaluateElements(node.args, env);
1155
+ return guard(Reflect.construct(constructor, args));
1156
+ }
1157
+ case "Unary": {
1158
+ if (node.operator === "typeof") {
1159
+ if (node.argument.type === "Identifier" && !this.has(node.argument.name, env)) return "undefined";
1160
+ return typeof this.evaluate(node.argument, env);
1161
+ }
1162
+ const value = this.evaluate(node.argument, env);
1163
+ switch (node.operator) {
1164
+ case "!": return !value;
1165
+ case "-": return -value;
1166
+ case "+": return +value;
1167
+ case "~": return ~value;
1168
+ case "void": return;
1169
+ default: throw new ExpressionSyntaxError(`Unsupported operator "${node.operator}"`);
1170
+ }
1171
+ }
1172
+ case "Logical": {
1173
+ const left = this.evaluate(node.left, env);
1174
+ if (node.operator === "&&") return left ? this.evaluate(node.right, env) : left;
1175
+ if (node.operator === "||") return left ? left : this.evaluate(node.right, env);
1176
+ return left === null || left === void 0 ? this.evaluate(node.right, env) : left;
1177
+ }
1178
+ case "Binary": return applyBinary(node.operator, this.evaluate(node.left, env), this.evaluate(node.right, env));
1179
+ case "Conditional": return this.evaluate(node.test, env) ? this.evaluate(node.consequent, env) : this.evaluate(node.alternate, env);
1180
+ case "Arrow": {
1181
+ const { params, body } = node;
1182
+ return (...args) => {
1183
+ const vars = /* @__PURE__ */ new Map();
1184
+ params.forEach((param, i) => vars.set(param, args[i]));
1185
+ const value = this.evaluate(body, {
1186
+ vars,
1187
+ parent: env
1188
+ });
1189
+ return value === SHORT_CIRCUIT ? void 0 : value;
1190
+ };
1191
+ }
1192
+ }
1193
+ }
1194
+ };
1195
+ function describeCallee(node) {
1196
+ if (node.type === "Identifier") return node.name;
1197
+ if (node.type === "Member" && !node.computed) return `${describeCallee(node.object)}.${String(node.property.value)}`;
1198
+ return "expression";
1199
+ }
1200
+ function applyBinary(operator, left, right) {
1201
+ const l = left;
1202
+ const r = right;
1203
+ switch (operator) {
1204
+ case "+": return left + right;
1205
+ case "-": return l - r;
1206
+ case "*": return l * r;
1207
+ case "/": return l / r;
1208
+ case "%": return l % r;
1209
+ case "**": return l ** r;
1210
+ case "==": return left == right;
1211
+ case "!=": return left != right;
1212
+ case "===": return left === right;
1213
+ case "!==": return left !== right;
1214
+ case "<": return l < r;
1215
+ case ">": return l > r;
1216
+ case "<=": return l <= r;
1217
+ case ">=": return l >= r;
1218
+ case "<<": return l << r;
1219
+ case ">>": return l >> r;
1220
+ case ">>>": return l >>> r;
1221
+ case "&": return l & r;
1222
+ case "|": return l | r;
1223
+ case "^": return l ^ r;
1224
+ case "in":
1225
+ if (right === null || typeof right !== "object" && typeof right !== "function") throw new TypeError(`Cannot use 'in' operator to search in ${String(right)}`);
1226
+ return toPropertyKey(left) in right;
1227
+ case "instanceof":
1228
+ if (typeof right !== "function") throw new TypeError("Right-hand side of 'instanceof' is not callable");
1229
+ return left instanceof (CONSTRUCTIBLE.get(right) ?? right);
1230
+ default: throw new ExpressionSyntaxError(`Unsupported operator "${operator}"`);
1231
+ }
1232
+ }
1233
+ function parseExpressionSource(source) {
1234
+ if (source.length > 1e4) throw new ExpressionSyntaxError(`Expression is longer than ${MAX_EXPRESSION_LENGTH} characters`);
1235
+ return new Parser(source).parse();
1236
+ }
1237
+ /**
1238
+ * Evaluate one bare formula (no `{{ }}` / `${ }` wrapper) against `scope`.
1239
+ *
1240
+ * `scope` lists every name the formula may use; nothing else is reachable.
1241
+ * Spread {@link SAFE_EXPRESSION_GLOBALS} into it to offer the usual
1242
+ * built-ins. Throws on syntax errors, unsafe access, budget exhaustion and
1243
+ * ordinary run-time errors (a TypeError for reading a property of undefined,
1244
+ * for example), so callers can show the message.
1245
+ */
1246
+ function evaluateSafeExpression(source, scope, options = {}) {
1247
+ const tree = parseExpressionSource(source);
1248
+ return new Evaluator(scope, options.maxSteps ?? 1e5).run(tree);
1249
+ }
1250
+
1251
+ export { evaluateSafeExpression as n, SAFE_EXPRESSION_GLOBALS as t };