@pebble-software/bonsai 0.0.8 → 0.1.1

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 (118) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +371 -88
  3. package/dist/ast.js +10 -0
  4. package/dist/ast.js.map +1 -0
  5. package/dist/chunks/builder.meta-WpXc5VBB.js +666 -0
  6. package/dist/chunks/builder.meta-WpXc5VBB.js.map +1 -0
  7. package/dist/chunks/button-jfJanilw.js +161 -0
  8. package/dist/chunks/button-jfJanilw.js.map +1 -0
  9. package/dist/chunks/create-renderer-DHneTPd-.js +280 -0
  10. package/dist/chunks/create-renderer-DHneTPd-.js.map +1 -0
  11. package/dist/chunks/index-DzpRdatr.js +359 -0
  12. package/dist/chunks/index-DzpRdatr.js.map +1 -0
  13. package/dist/chunks/render-shared-Ci28BpkI.js +1989 -0
  14. package/dist/chunks/render-shared-Ci28BpkI.js.map +1 -0
  15. package/dist/components/core/bonsai.d.ts +5 -0
  16. package/dist/components/core/render-shared.d.ts +123 -0
  17. package/dist/components/core/render-tree-client.d.ts +4 -0
  18. package/dist/components/core/render-tree-server.d.ts +2 -0
  19. package/dist/components/ui/a.d.ts +3 -0
  20. package/dist/components/ui/accordion.d.ts +17 -0
  21. package/dist/components/ui/alert-dialog.d.ts +23 -0
  22. package/dist/components/ui/alert.d.ts +12 -0
  23. package/dist/components/ui/avatar.d.ts +21 -0
  24. package/dist/components/ui/badge.d.ts +10 -0
  25. package/dist/components/ui/breadcrumb.d.ts +10 -0
  26. package/dist/components/ui/button.d.ts +14 -0
  27. package/dist/components/ui/calendar.d.ts +9 -0
  28. package/dist/components/ui/card.d.ts +15 -0
  29. package/dist/components/ui/checkbox.d.ts +7 -0
  30. package/dist/components/ui/collapsible.d.ts +5 -0
  31. package/dist/components/ui/combobox.d.ts +31 -0
  32. package/dist/components/ui/command.d.ts +23 -0
  33. package/dist/components/ui/dialog.d.ts +23 -0
  34. package/dist/components/ui/drawer.d.ts +22 -0
  35. package/dist/components/ui/dropdown-menu.d.ts +29 -0
  36. package/dist/components/ui/form.d.ts +24 -0
  37. package/dist/components/ui/h.d.ts +10 -0
  38. package/dist/components/ui/input-group.d.ts +18 -0
  39. package/dist/components/ui/input-otp.d.ts +11 -0
  40. package/dist/components/ui/input.d.ts +3 -0
  41. package/dist/components/ui/label.d.ts +10 -0
  42. package/dist/components/ui/loader.d.ts +14 -0
  43. package/dist/components/ui/p.d.ts +11 -0
  44. package/dist/components/ui/popover.d.ts +9 -0
  45. package/dist/components/ui/progress.d.ts +31 -0
  46. package/dist/components/ui/scroll-area.d.ts +13 -0
  47. package/dist/components/ui/select.d.ts +17 -0
  48. package/dist/components/ui/separator.d.ts +8 -0
  49. package/dist/components/ui/sidebar.d.ts +70 -0
  50. package/dist/components/ui/signature-pad.d.ts +7 -0
  51. package/dist/components/ui/skeleton.d.ts +7 -0
  52. package/dist/components/ui/switch.d.ts +8 -0
  53. package/dist/components/ui/table.d.ts +14 -0
  54. package/dist/components/ui/tabs.d.ts +15 -0
  55. package/dist/components/ui/textarea.d.ts +5 -0
  56. package/dist/components/ui/toast.d.ts +46 -0
  57. package/dist/components/ui/tooltip.d.ts +15 -0
  58. package/dist/constants.d.ts +1 -0
  59. package/dist/constants.js +11 -0
  60. package/dist/constants.js.map +1 -0
  61. package/dist/core.d.ts +12 -0
  62. package/dist/core.js +17 -0
  63. package/dist/core.js.map +1 -0
  64. package/dist/hooks/haptics.d.ts +8 -0
  65. package/dist/hooks/use-mobile.d.ts +1 -0
  66. package/dist/index.css +7 -0
  67. package/dist/index.d.ts +27 -339
  68. package/dist/index.js +532 -4297
  69. package/dist/index.js.map +1 -0
  70. package/dist/lib/ast/cache.d.ts +8 -0
  71. package/dist/lib/ast/evaluator.d.ts +2 -0
  72. package/dist/lib/ast/helpers.d.ts +2 -0
  73. package/dist/lib/ast/index.d.ts +29 -0
  74. package/dist/lib/ast/setup.d.ts +2 -0
  75. package/dist/lib/ast/types.d.ts +1 -0
  76. package/dist/lib/ast/utils.d.ts +4 -0
  77. package/dist/lib/haptics.d.ts +8 -0
  78. package/dist/lib/registry/drift.d.ts +17 -0
  79. package/dist/lib/registry/identity.d.ts +24 -0
  80. package/dist/lib/registry/json-schema-to-zod.d.ts +32 -0
  81. package/dist/lib/registry/manifest-schema.d.ts +62 -0
  82. package/dist/lib/registry/manifest.d.ts +26 -0
  83. package/dist/lib/registry/merge-generated.d.ts +7 -0
  84. package/dist/lib/registry/pebble-registry.d.ts +1 -0
  85. package/dist/lib/registry/types.d.ts +29 -0
  86. package/dist/lib/registry/validate.d.ts +18 -0
  87. package/dist/lib/renderer/compile-template.d.ts +70 -0
  88. package/dist/lib/ui/registry.d.ts +19 -0
  89. package/dist/lib/utils.d.ts +3 -0
  90. package/dist/library/constants/src/components.d.ts +59 -0
  91. package/dist/library/constants/src/index.d.ts +2 -0
  92. package/dist/library/constants/src/webhook-events.d.ts +6 -0
  93. package/dist/library/schemas/src/bonsai.schema.d.ts +24 -0
  94. package/dist/library/schemas/src/builder.meta.d.ts +26 -0
  95. package/dist/presets/calendar.js +374 -0
  96. package/dist/presets/calendar.js.map +1 -0
  97. package/dist/presets/signature.js +405 -0
  98. package/dist/presets/signature.js.map +1 -0
  99. package/dist/renderer/core-registry.d.ts +52 -0
  100. package/dist/renderer/create-renderer.d.ts +38 -0
  101. package/dist/renderer/presets/calendar.d.ts +5 -0
  102. package/dist/renderer/presets/signature.d.ts +6 -0
  103. package/dist/schemas.d.ts +2 -0
  104. package/dist/schemas.js +13 -0
  105. package/dist/schemas.js.map +1 -0
  106. package/dist/styles/css/base.css +144 -0
  107. package/dist/styles/css/fonts.css +25 -0
  108. package/dist/styles/css/maplibre.css +29 -0
  109. package/dist/styles/css/overrides.css +7 -0
  110. package/dist/styles/css/tailwind.css +1 -0
  111. package/dist/styles/css/theme.css +197 -0
  112. package/dist/styles/css/tw-animate.css +1 -0
  113. package/dist/styles/css/utilities.css +44 -0
  114. package/dist/styles/presets.json +20 -0
  115. package/dist/styles/vendor/maplibre-gl.css +701 -0
  116. package/dist/styles/vendor/tw-animate.css +692 -0
  117. package/dist/types.d.ts +1 -0
  118. package/package.json +64 -19
@@ -0,0 +1,280 @@
1
+ import { jsx as d } from "react/jsx-runtime";
2
+ import { createElement as h, memo as S, useCallback as N, useRef as m, useEffect as j, createContext as M, useContext as P } from "react";
3
+ import { i as T, B as O, r as b, j as w, k as D, l as V, m as y, n as $, o as W, p as E, q as A, V as L, s as q, t as J, v as z, f as F, b as G, w as H } from "./render-shared-Ci28BpkI.js";
4
+ import { proxy as Q, snapshot as v, subscribe as U, useSnapshot as X } from "valtio";
5
+ const Y = {
6
+ dataSlice(t, e, r) {
7
+ return V(t.dynamicKeys, (n) => n in r && n !== "data" ? r[n] : y(r.data ?? r, n));
8
+ },
9
+ rowCtx(t, e, r, n, o, s) {
10
+ const { as: a, indexAlias: i } = o, c = {
11
+ ...e,
12
+ data: {
13
+ ...e.data ?? e,
14
+ [a]: r,
15
+ ...i ? { [i]: n } : {}
16
+ }
17
+ }, u = s ? { ...t.scope, [a]: `${s}.${n}` } : t.scope;
18
+ return { data: c, scope: u };
19
+ },
20
+ renderChild(t, e, r, n, o) {
21
+ return /* @__PURE__ */ d(
22
+ K,
23
+ {
24
+ node: t,
25
+ index: e,
26
+ path: r,
27
+ data: n.data,
28
+ scope: n.scope
29
+ },
30
+ o
31
+ );
32
+ }
33
+ }, K = S(
34
+ ({ node: t, index: e = 0, path: r = "root", data: n, scope: o }) => {
35
+ const s = w(), a = N(() => {
36
+ }, []);
37
+ return D(
38
+ t,
39
+ e,
40
+ r,
41
+ { data: n, scope: o },
42
+ n,
43
+ s,
44
+ a,
45
+ Y
46
+ );
47
+ }
48
+ );
49
+ function Z({
50
+ template: t,
51
+ expiry: e,
52
+ data: r,
53
+ status: n = "pending",
54
+ render: o = "web",
55
+ as: s,
56
+ registry: a
57
+ }) {
58
+ const i = {
59
+ data: r ?? {},
60
+ expiry: e ?? "",
61
+ status: n,
62
+ submitting: !1
63
+ }, c = T(t).root, u = b(o, s);
64
+ return /* @__PURE__ */ d(O, { registry: a, render: o, children: h(
65
+ u,
66
+ {
67
+ "data-mode": o,
68
+ className: `group bonsai-root${o === "pdf" ? " w-full" : ""}`
69
+ },
70
+ /* @__PURE__ */ d(K, { node: c, index: 0, path: "root", data: i })
71
+ ) });
72
+ }
73
+ const _ = M(null);
74
+ function g() {
75
+ const t = P(_);
76
+ if (!t)
77
+ throw new Error("useBonsaiStore must be used within a <Bonsai> component");
78
+ return t;
79
+ }
80
+ function k() {
81
+ const t = g();
82
+ return N(
83
+ (e, r) => q(t.data, e, r),
84
+ [t]
85
+ );
86
+ }
87
+ function tt(t, e, r, n, o) {
88
+ const s = J(t);
89
+ return n && s in n ? t === s ? n[s] : void 0 : r && s in r ? y(e.data ?? e, z(t, r)) : o && Object.hasOwn(o, s) ? y(o, t) : t in e && t !== "data" ? e[t] : y(e.data ?? e, t);
90
+ }
91
+ const et = S(
92
+ ({ node: t, index: e = 0, path: r = "root", scope: n, indexScope: o, valueScope: s }) => {
93
+ const a = w(), i = t.source;
94
+ if (!i) return null;
95
+ if (t.isText)
96
+ return i;
97
+ try {
98
+ const c = t.type, u = W(a, c), p = E(t, e, r), f = A(t, {}, p);
99
+ if (t.isImage && (f.src === "" || f.src == null))
100
+ return null;
101
+ const l = t.children.length > 0 ? t.children.map(
102
+ (I, R) => C(
103
+ I,
104
+ R,
105
+ `${r}-${e}`,
106
+ n,
107
+ o,
108
+ s,
109
+ E(t, R, `${r}-${e}`)
110
+ )
111
+ ) : void 0, B = typeof u == "string" && L.has(u) ? void 0 : l;
112
+ return B !== void 0 ? h(u, f, B) : h(u, f);
113
+ } catch (c) {
114
+ return console.error(`Error at ${r}-${e}:`, c), null;
115
+ }
116
+ }
117
+ );
118
+ function C(t, e, r, n, o, s, a) {
119
+ return t.isStatic ? /* @__PURE__ */ d(
120
+ et,
121
+ {
122
+ node: t,
123
+ index: e,
124
+ path: r,
125
+ scope: n,
126
+ indexScope: o,
127
+ valueScope: s
128
+ },
129
+ a
130
+ ) : /* @__PURE__ */ d(
131
+ nt,
132
+ {
133
+ node: t,
134
+ index: e,
135
+ path: r,
136
+ scope: n,
137
+ indexScope: o,
138
+ valueScope: s
139
+ },
140
+ a
141
+ );
142
+ }
143
+ function x(t, e) {
144
+ if (!t || !Object.hasOwn(t, e)) return t;
145
+ const r = { ...t };
146
+ return delete r[e], r;
147
+ }
148
+ const rt = {
149
+ dataSlice(t, e, r) {
150
+ return V(
151
+ t.dynamicKeys,
152
+ (n) => tt(n, r, e.scope, e.indexScope, e.valueScope)
153
+ );
154
+ },
155
+ rowCtx(t, e, r, n, o, s) {
156
+ const { as: a, indexAlias: i } = o, c = i ? { ...t.indexScope, [i]: n } : t.indexScope;
157
+ return s ? {
158
+ scope: { ...t.scope, [a]: `${s}.${n}` },
159
+ indexScope: c,
160
+ valueScope: x(t.valueScope, a)
161
+ } : {
162
+ scope: x(t.scope, a),
163
+ indexScope: c,
164
+ valueScope: { ...t.valueScope, [a]: r }
165
+ };
166
+ },
167
+ renderChild(t, e, r, n, o) {
168
+ return C(t, e, r, n.scope, n.indexScope, n.valueScope, o);
169
+ }
170
+ }, nt = S(
171
+ ({ node: t, index: e = 0, path: r = "root", scope: n, indexScope: o, valueScope: s }) => {
172
+ const a = w(), i = g(), c = X(i, { sync: !0 }), u = k();
173
+ return D(
174
+ t,
175
+ e,
176
+ r,
177
+ { scope: n, indexScope: o, valueScope: s },
178
+ c,
179
+ a,
180
+ u,
181
+ rt
182
+ );
183
+ }
184
+ );
185
+ function ot({
186
+ captureUrl: t,
187
+ template: e,
188
+ render: r = "web",
189
+ as: n,
190
+ onSubmit: o,
191
+ onError: s,
192
+ registry: a
193
+ }) {
194
+ const i = g(), c = async (f) => {
195
+ if (f.preventDefault(), i.status === "pending" && !(!o && !t)) {
196
+ i.submitting = !0;
197
+ try {
198
+ if (o)
199
+ await o(v(i.data));
200
+ else {
201
+ const l = await fetch(t, {
202
+ method: "POST",
203
+ credentials: "include",
204
+ headers: {
205
+ "Content-Type": "application/json"
206
+ },
207
+ body: JSON.stringify({
208
+ data: i.data
209
+ })
210
+ });
211
+ if (!l.ok)
212
+ throw new Error(`Capture failed: ${l.status} ${l.statusText}`.trim());
213
+ }
214
+ i.status = "captured";
215
+ } catch (l) {
216
+ if (!s) throw l;
217
+ s(l);
218
+ } finally {
219
+ i.submitting = !1;
220
+ }
221
+ }
222
+ }, u = T(e).root, p = b(r, n);
223
+ return /* @__PURE__ */ d(O, { registry: a, render: r, children: h(
224
+ p,
225
+ {
226
+ "data-mode": r,
227
+ className: `group bonsai-root${r === "pdf" ? " w-full" : ""}`,
228
+ ...p === "form" ? { onSubmit: c } : {}
229
+ },
230
+ C(u, 0, "root", void 0, void 0, void 0, "root-0")
231
+ ) });
232
+ }
233
+ function st(t) {
234
+ const e = m(null), r = m(t.data), n = m(!1), o = m(t.onDataChange);
235
+ if (o.current = t.onDataChange, e.current === null)
236
+ e.current = Q({
237
+ status: t.status ?? "pending",
238
+ expiry: t.expiry ?? "",
239
+ data: $(t.data ?? {}),
240
+ submitting: !1
241
+ });
242
+ else if (!Object.is(r.current, t.data)) {
243
+ r.current = t.data, n.current = !0;
244
+ try {
245
+ e.current.data = $(t.data ?? {});
246
+ } finally {
247
+ n.current = !1;
248
+ }
249
+ }
250
+ const s = e.current;
251
+ return j(() => {
252
+ let a = v(s.data);
253
+ return U(
254
+ s,
255
+ () => {
256
+ const i = v(s.data);
257
+ i !== a && (a = i, !n.current && o.current?.(i));
258
+ },
259
+ !0
260
+ );
261
+ }, [s]), /* @__PURE__ */ d(_.Provider, { value: s, children: /* @__PURE__ */ d(ot, { ...t }) });
262
+ }
263
+ function at(t) {
264
+ return typeof window > "u" ? /* @__PURE__ */ d(Z, { ...t }) : /* @__PURE__ */ d(st, { ...t });
265
+ }
266
+ function lt(t = {}) {
267
+ const e = F(t.registry ?? G, {
268
+ components: t.components,
269
+ controlledInputs: t.controlledInputs
270
+ });
271
+ function r(n) {
272
+ return /* @__PURE__ */ d(H.Provider, { value: e, children: /* @__PURE__ */ d(at, { ...n }) });
273
+ }
274
+ return r.displayName = "Bonsai", { Bonsai: r };
275
+ }
276
+ export {
277
+ lt as c,
278
+ k as u
279
+ };
280
+ //# sourceMappingURL=create-renderer-DHneTPd-.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-renderer-DHneTPd-.js","sources":["../../src/components/core/render-tree-server.tsx","../../src/components/core/render-tree-client.tsx","../../src/components/core/bonsai.tsx","../../src/renderer/create-renderer.tsx"],"sourcesContent":["import { createElement, memo, useCallback } from \"react\";\nimport { type CompiledNode } from \"../../lib/renderer/compile-template\";\nimport { compileTemplate } from \"../../lib/renderer/compile-template\";\nimport {\n BonsaiRoot,\n useBonsaiRegistry,\n buildDataSlice,\n getValue,\n resolveWrapper,\n renderCompiledNode,\n type NodeCtx,\n type RenderStrategy,\n type BonsaiProps,\n} from \"./render-shared\";\n\ninterface RenderTreeServerProps {\n // Precompiled metadata for this node; `node.source` is the raw template node.\n node: CompiledNode;\n index?: number;\n path?: string;\n data: Record<string, any>;\n // Alias -> real store path prefix set by an ancestor `each` (e.g. { applicant: \"applicants.3\" }); SSR-only.\n scope?: Record<string, string>;\n}\n\n// SSR ctx is the prop-drilled global data object plus the current `each` scope.\ninterface ServerCtx extends NodeCtx {\n data: Record<string, any>;\n}\n\nconst SERVER_MODE: RenderStrategy<ServerCtx> = {\n dataSlice(node, _ctx, globalData) {\n return buildDataSlice(node.dynamicKeys, (key) => {\n if (key in globalData && key !== \"data\") return globalData[key];\n return getValue(globalData.data ?? globalData, key);\n });\n },\n rowCtx(ctx, globalData, item, i, each, realItemsPath) {\n const { as, indexAlias } = each;\n const rowData = {\n ...globalData,\n data: {\n ...(globalData.data ?? globalData),\n [as]: item,\n ...(indexAlias ? { [indexAlias]: i } : {}),\n },\n };\n const rowScope = realItemsPath\n ? { ...ctx.scope, [as]: `${realItemsPath}.${i}` }\n : ctx.scope;\n return { data: rowData, scope: rowScope };\n },\n renderChild(child, i, path, ctx, key) {\n return (\n <RenderTreeServer\n key={key}\n node={child}\n index={i}\n path={path}\n data={ctx.data}\n scope={ctx.scope}\n />\n );\n },\n};\n\n// SSR: single-pass render over a plain, prop-drilled object — no store, no snapshots.\nconst RenderTreeServer = memo(\n ({ node, index = 0, path = \"root\", data, scope }: RenderTreeServerProps) => {\n const registry = useBonsaiRegistry();\n const updateData = useCallback(() => {\n // Attached for the controlled-component contract but never invoked during SSR.\n }, []);\n\n return renderCompiledNode(\n node,\n index,\n path,\n { data, scope },\n data,\n registry,\n updateData,\n SERVER_MODE,\n );\n },\n);\n\nexport function BonsaiServer({\n template,\n expiry,\n data,\n status = \"pending\",\n render = \"web\",\n as,\n registry,\n}: BonsaiProps) {\n const ctx = {\n data: data ?? {},\n expiry: expiry ?? \"\",\n status,\n submitting: false,\n };\n\n // Cached by template identity, so N instances of the same template compile once.\n const root = compileTemplate(template).root;\n const Wrapper = resolveWrapper(render, as);\n\n return (\n <BonsaiRoot registry={registry} render={render}>\n {createElement(\n Wrapper,\n {\n \"data-mode\": render,\n className: `group bonsai-root${render === \"pdf\" ? \" w-full\" : \"\"}`,\n },\n <RenderTreeServer node={root} index={0} path=\"root\" data={ctx} />,\n )}\n </BonsaiRoot>\n );\n}\n","import {\n createContext,\n createElement,\n memo,\n useCallback,\n useContext,\n useEffect,\n useRef,\n type SubmitEvent,\n} from \"react\";\nimport { proxy, snapshot, subscribe, useSnapshot } from \"valtio\";\nimport { type CompiledNode } from \"../../lib/renderer/compile-template\";\nimport { compileTemplate } from \"../../lib/renderer/compile-template\";\nimport {\n BonsaiRoot,\n useBonsaiRegistry,\n VOID_ELEMENTS,\n getKey,\n getValue,\n setValue,\n resolveScopedPath,\n pathRoot,\n buildDataSlice,\n resolveElementType,\n prepareState,\n resolveWrapper,\n cloneData,\n renderCompiledNode,\n type NodeCtx,\n type RenderStrategy,\n type BonsaiProps,\n} from \"./render-shared\";\n\n// scope/indexScope/valueScope are the only things an `each` row hands its children on the live path —\n// store data is never prop-drilled (valueScope carries only computed-row items, which have no store path).\ninterface RenderTreeClientProps {\n node: CompiledNode;\n index?: number;\n path?: string;\n scope?: Record<string, string>;\n indexScope?: Record<string, number>;\n valueScope?: Record<string, unknown>;\n}\n\ntype BonsaiState = {\n status: string;\n expiry: string;\n data: Record<string, any>;\n submitting: boolean;\n};\n\nconst BonsaiContext = createContext<ReturnType<\n typeof proxy<BonsaiState>\n> | null>(null);\n\nfunction useBonsaiStore(): ReturnType<typeof proxy<BonsaiState>> {\n const store = useContext(BonsaiContext);\n if (!store) {\n throw new Error(\"useBonsaiStore must be used within a <Bonsai> component\");\n }\n return store;\n}\n\nexport function useUpdateData() {\n const store = useBonsaiStore();\n return useCallback(\n (path: string, value: any) => setValue(store.data, path, value),\n [store],\n );\n}\n\n// Live-path lookup: resolves each-scoped aliases at read time against a fresh snapshot.\nfunction resolveKeyValue(\n key: string,\n globalData: Record<string, any>,\n scope: Record<string, string> | undefined,\n indexScope: Record<string, number> | undefined,\n valueScope: Record<string, unknown> | undefined,\n): any {\n const root = pathRoot(key);\n\n if (indexScope && root in indexScope) {\n return key === root ? indexScope[root] : undefined;\n }\n\n if (scope && root in scope) {\n return getValue(globalData.data ?? globalData, resolveScopedPath(key, scope));\n }\n\n if (valueScope && Object.hasOwn(valueScope, root)) {\n return getValue(valueScope, key);\n }\n\n if (key in globalData && key !== \"data\") {\n return globalData[key];\n }\n\n return getValue(globalData.data ?? globalData, key);\n}\n\n// Children still go through `renderClientNode`, so a binding nested inside an unbound wrapper stays reactive.\nconst StaticNode = memo(\n ({ node, index = 0, path = \"root\", scope, indexScope, valueScope }: RenderTreeClientProps) => {\n const registry = useBonsaiRegistry();\n const tree = node.source;\n\n if (!tree) return null;\n if (node.isText) {\n // `isStatic` guarantees this has no `{{...}}` binding to evaluate.\n return tree as unknown as string;\n }\n\n try {\n const type = node.type;\n const ElementType = resolveElementType(registry, type);\n const key = getKey(node, index, path);\n const props = prepareState(node, {}, key);\n\n if (node.isImage && (props.src === \"\" || props.src == null)) {\n return null;\n }\n\n const childNodes =\n node.children.length > 0\n ? node.children.map((branch: CompiledNode, i: number) =>\n renderClientNode(\n branch,\n i,\n `${path}-${index}`,\n scope,\n indexScope,\n valueScope,\n getKey(node, i, `${path}-${index}`),\n ),\n )\n : undefined;\n\n const safeChildNodes =\n typeof ElementType === \"string\" && VOID_ELEMENTS.has(ElementType)\n ? undefined\n : childNodes;\n\n if (safeChildNodes !== undefined) {\n return createElement(ElementType, props, safeChildNodes);\n }\n return createElement(ElementType, props);\n } catch (error) {\n console.error(`Error at ${path}-${index}:`, error);\n return null;\n }\n },\n);\n\n// A plain function, not a hook, since it decides which component type to mount — always a safe conditional.\nfunction renderClientNode(\n node: CompiledNode,\n index: number,\n path: string,\n scope: Record<string, string> | undefined,\n indexScope: Record<string, number> | undefined,\n valueScope: Record<string, unknown> | undefined,\n key: string,\n): React.ReactNode {\n return node.isStatic ? (\n <StaticNode\n key={key}\n node={node}\n index={index}\n path={path}\n scope={scope}\n indexScope={indexScope}\n valueScope={valueScope}\n />\n ) : (\n <RenderTreeClient\n key={key}\n node={node}\n index={index}\n path={path}\n scope={scope}\n indexScope={indexScope}\n valueScope={valueScope}\n />\n );\n}\n\n// Client ctx carries only what an `each` row hands its children on this path — no data is prop-drilled.\ninterface ClientCtx extends NodeCtx {\n indexScope?: Record<string, number>;\n}\n\nfunction omitKey<T>(\n obj: Record<string, T> | undefined,\n key: string,\n): Record<string, T> | undefined {\n if (!obj || !Object.hasOwn(obj, key)) return obj;\n const rest = { ...obj };\n delete rest[key];\n return rest;\n}\n\nconst CLIENT_MODE: RenderStrategy<ClientCtx> = {\n dataSlice(node, ctx, globalData) {\n return buildDataSlice(node.dynamicKeys, (key) =>\n resolveKeyValue(key, globalData, ctx.scope, ctx.indexScope, ctx.valueScope),\n );\n },\n rowCtx(ctx, _globalData, item, i, each, realItemsPath) {\n const { as, indexAlias } = each;\n const rowIndexScope = indexAlias\n ? { ...ctx.indexScope, [indexAlias]: i }\n : ctx.indexScope;\n // A plain-path row resolves its alias against the store; a computed row has no store path, so it\n // carries the item itself. Each clears the alias from the other map so an inner alias shadows an outer one.\n if (realItemsPath) {\n return {\n scope: { ...ctx.scope, [as]: `${realItemsPath}.${i}` },\n indexScope: rowIndexScope,\n valueScope: omitKey(ctx.valueScope, as),\n };\n }\n return {\n scope: omitKey(ctx.scope, as),\n indexScope: rowIndexScope,\n valueScope: { ...ctx.valueScope, [as]: item },\n };\n },\n renderChild(child, i, path, ctx, key) {\n return renderClientNode(child, i, path, ctx.scope, ctx.indexScope, ctx.valueScope, key);\n },\n};\n\n// Client: every node calls useSnapshot itself, so it only re-renders when a path it actually reads changes.\nconst RenderTreeClient = memo(\n ({ node, index = 0, path = \"root\", scope, indexScope, valueScope }: RenderTreeClientProps) => {\n const registry = useBonsaiRegistry();\n const store = useBonsaiStore();\n // sync: true keeps the store write and its re-render in the same event, avoiding a one-tick display lag.\n const globalData = useSnapshot(store, { sync: true });\n const updateData = useUpdateData();\n\n return renderCompiledNode(\n node,\n index,\n path,\n { scope, indexScope, valueScope },\n globalData,\n registry,\n updateData,\n CLIENT_MODE,\n );\n },\n);\n\nexport function BonsaiClient({\n captureUrl,\n template,\n render = \"web\",\n as,\n onSubmit,\n onError,\n registry,\n}: BonsaiProps) {\n const store = useBonsaiStore();\n\n const submit = async (e: SubmitEvent) => {\n e.preventDefault();\n // Already captured/completed/revoked: nothing to send, and the lifecycle flags stay as they are.\n if (store.status !== \"pending\") return;\n // Display-only instance: nothing to submit to, so don't touch the lifecycle.\n if (!onSubmit && !captureUrl) return;\n\n store.submitting = true;\n try {\n if (onSubmit) {\n await onSubmit(snapshot(store.data) as Record<string, unknown>);\n } else {\n const res = await fetch(captureUrl!, {\n method: \"POST\",\n credentials: \"include\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n data: store.data,\n }),\n });\n // fetch only rejects on network failure; an error status must not count as captured.\n if (!res.ok) {\n throw new Error(`Capture failed: ${res.status} ${res.statusText}`.trim());\n }\n }\n\n store.status = \"captured\";\n } catch (error) {\n // Without an `onError`, this keeps the pre-existing behaviour of letting\n // the failure propagate out of the submit handler.\n if (!onError) throw error;\n onError(error);\n } finally {\n store.submitting = false;\n }\n };\n\n // Cached by template identity, so N instances of the same template compile once.\n const root = compileTemplate(template).root;\n const Wrapper = resolveWrapper(render, as);\n\n return (\n <BonsaiRoot registry={registry} render={render}>\n {createElement(\n Wrapper,\n {\n \"data-mode\": render,\n className: `group bonsai-root${render === \"pdf\" ? \" w-full\" : \"\"}`,\n ...(Wrapper === \"form\" ? { onSubmit: submit } : {}),\n },\n renderClientNode(root, 0, \"root\", undefined, undefined, undefined, \"root-0\"),\n )}\n </BonsaiRoot>\n );\n}\n\nexport function BonsaiProvider(props: BonsaiProps) {\n const storeRef = useRef<ReturnType<typeof proxy<BonsaiState>> | null>(null);\n // The `data` object identity this store was last seeded from.\n const seenDataRef = useRef<BonsaiProps[\"data\"]>(props.data);\n // Set while the provider itself writes to the store, so a parent-driven\n // resync isn't echoed back out through `onDataChange`.\n const resyncingRef = useRef(false);\n const onDataChangeRef = useRef(props.onDataChange);\n onDataChangeRef.current = props.onDataChange;\n\n if (storeRef.current === null) {\n storeRef.current = proxy<BonsaiState>({\n status: props.status ?? \"pending\",\n expiry: props.expiry ?? \"\",\n data: cloneData(props.data ?? {}),\n submitting: false,\n });\n } else if (!Object.is(seenDataRef.current, props.data)) {\n // A new `data` object arrived from the parent — adopt it. Same-reference\n // renders (including in-place mutations) are deliberately ignored.\n seenDataRef.current = props.data;\n resyncingRef.current = true;\n try {\n storeRef.current.data = cloneData(props.data ?? {});\n } finally {\n resyncingRef.current = false;\n }\n }\n\n const store = storeRef.current;\n\n useEffect(() => {\n // valtio only populates subscription `ops` when the (unstable) op tracking\n // is switched on globally, so changes are detected by snapshot identity\n // instead: `snapshot` is memoised per version, so an unchanged `data`\n // subtree returns the very same object and is filtered out here.\n //\n // Notify in sync: the resync flag below is only reliable if the callback\n // runs inside the write, not on a later microtask.\n let previous = snapshot(store.data);\n return subscribe(\n store,\n () => {\n const next = snapshot(store.data);\n if (next === previous) return;\n previous = next;\n // A parent-driven resync isn't a user edit — don't echo it back.\n if (resyncingRef.current) return;\n onDataChangeRef.current?.(next as Record<string, unknown>);\n },\n true,\n );\n }, [store]);\n\n return (\n <BonsaiContext.Provider value={store}>\n <BonsaiClient {...props} />\n </BonsaiContext.Provider>\n );\n}\n","import { BonsaiServer } from \"./render-tree-server\";\nimport { BonsaiProvider } from \"./render-tree-client\";\nimport type { BonsaiProps } from \"./render-shared\";\n\nexport {\n BonsaiRegistryContext,\n getValue,\n setValue,\n useBonsaiRenderMode,\n type BonsaiProps,\n type RenderMode,\n} from \"./render-shared\";\nexport { useUpdateData, BonsaiClient, BonsaiProvider } from \"./render-tree-client\";\nexport { BonsaiServer } from \"./render-tree-server\";\n\nexport function Bonsai(props: BonsaiProps) {\n if (typeof window === \"undefined\") {\n return <BonsaiServer {...props} />;\n }\n\n return <BonsaiProvider {...props} />;\n}\n","import {\n Bonsai as BonsaiRenderer,\n BonsaiRegistryContext,\n type BonsaiProps,\n} from \"../components/core/bonsai\";\nimport {\n coreRegistry,\n extendRegistry,\n type ComponentRegistry,\n type ControlledInputRegistry,\n} from \"./core-registry\";\nimport type { BonsaiRegistry } from \"../lib/registry/types\";\n\nexport interface BonsaiRendererOptions {\n /** Base registry. Defaults to the lightweight core registry. */\n registry?: BonsaiRegistry;\n /** Extra components layered over `registry` (they win on key collision). */\n components?: Partial<ComponentRegistry>;\n controlledInputs?: Partial<ControlledInputRegistry>;\n}\n\nexport interface BonsaiRendererInstance {\n Bonsai: React.ComponentType<BonsaiProps>;\n}\n\n/**\n * Builds a renderer bound to its own component registry.\n *\n * The registry is `options.registry` (the lightweight core set by default)\n * plus whatever components the caller supplies (caller entries win on key\n * collision); a `registry` prop on an individual `<Bonsai>` still overrides it. It is captured in a React context at\n * this call, so registries never leak between renderer instances and consumers\n * never have to mutate the exported `componentMap`.\n *\n * Heavy built-ins are opt-in via the presets in `renderer/presets/*`:\n *\n * ```ts\n * import { createBonsaiRenderer } from \"@pebble-software/bonsai/core\";\n * import { calendarPreset } from \"@pebble-software/bonsai/presets/calendar\";\n *\n * const { Bonsai } = createBonsaiRenderer({\n * components: { ...calendarPreset.components, rating: Rating },\n * controlledInputs: { ...calendarPreset.controlledInputs },\n * });\n * ```\n *\n * Call this at module scope: each call returns a fresh component type, so\n * calling it during render would remount the whole tree every time.\n */\nexport function createBonsaiRenderer(\n options: BonsaiRendererOptions = {},\n): BonsaiRendererInstance {\n // Cast: a `Partial<...>` widens values to `| undefined`, but it only ever\n // holds keys the caller actually supplied.\n const registry = extendRegistry(options.registry ?? coreRegistry, {\n components: options.components as ComponentRegistry | undefined,\n controlledInputs: options.controlledInputs as ControlledInputRegistry | undefined,\n });\n\n function Bonsai(props: BonsaiProps) {\n return (\n <BonsaiRegistryContext.Provider value={registry}>\n <BonsaiRenderer {...props} />\n </BonsaiRegistryContext.Provider>\n );\n }\n Bonsai.displayName = \"Bonsai\";\n\n return { Bonsai };\n}\n"],"names":["SERVER_MODE","node","_ctx","globalData","buildDataSlice","key","getValue","ctx","item","i","each","realItemsPath","as","indexAlias","rowData","rowScope","child","path","jsx","RenderTreeServer","memo","index","data","scope","registry","useBonsaiRegistry","updateData","useCallback","renderCompiledNode","BonsaiServer","template","expiry","status","render","root","compileTemplate","Wrapper","resolveWrapper","BonsaiRoot","createElement","BonsaiContext","createContext","useBonsaiStore","store","useContext","useUpdateData","value","setValue","resolveKeyValue","indexScope","valueScope","pathRoot","resolveScopedPath","StaticNode","tree","type","ElementType","resolveElementType","getKey","props","prepareState","childNodes","branch","renderClientNode","safeChildNodes","VOID_ELEMENTS","error","RenderTreeClient","omitKey","obj","rest","CLIENT_MODE","_globalData","rowIndexScope","useSnapshot","BonsaiClient","captureUrl","onSubmit","onError","submit","e","snapshot","res","BonsaiProvider","storeRef","useRef","seenDataRef","resyncingRef","onDataChangeRef","proxy","cloneData","useEffect","previous","subscribe","next","Bonsai","createBonsaiRenderer","options","extendRegistry","coreRegistry","BonsaiRegistryContext","BonsaiRenderer"],"mappings":";;;;AA8BA,MAAMA,IAAyC;AAAA,EAC7C,UAAUC,GAAMC,GAAMC,GAAY;AAChC,WAAOC,EAAeH,EAAK,aAAa,CAACI,MACnCA,KAAOF,KAAcE,MAAQ,SAAeF,EAAWE,CAAG,IACvDC,EAASH,EAAW,QAAQA,GAAYE,CAAG,CACnD;AAAA,EACH;AAAA,EACA,OAAOE,GAAKJ,GAAYK,GAAMC,GAAGC,GAAMC,GAAe;AACpD,UAAM,EAAE,IAAAC,GAAI,YAAAC,EAAA,IAAeH,GACrBI,IAAU;AAAA,MACd,GAAGX;AAAA,MACH,MAAM;AAAA,QACJ,GAAIA,EAAW,QAAQA;AAAA,QACvB,CAACS,CAAE,GAAGJ;AAAA,QACN,GAAIK,IAAa,EAAE,CAACA,CAAU,GAAGJ,EAAA,IAAM,CAAA;AAAA,MAAC;AAAA,IAC1C,GAEIM,IAAWJ,IACb,EAAE,GAAGJ,EAAI,OAAO,CAACK,CAAE,GAAG,GAAGD,CAAa,IAAIF,CAAC,GAAA,IAC3CF,EAAI;AACR,WAAO,EAAE,MAAMO,GAAS,OAAOC,EAAA;AAAA,EACjC;AAAA,EACA,YAAYC,GAAOP,GAAGQ,GAAMV,GAAKF,GAAK;AACpC,WACE,gBAAAa;AAAA,MAACC;AAAA,MAAA;AAAA,QAEC,MAAMH;AAAA,QACN,OAAOP;AAAA,QACP,MAAAQ;AAAA,QACA,MAAMV,EAAI;AAAA,QACV,OAAOA,EAAI;AAAA,MAAA;AAAA,MALNF;AAAA,IAAA;AAAA,EAQX;AACF,GAGMc,IAAmBC;AAAA,EACvB,CAAC,EAAE,MAAAnB,GAAM,OAAAoB,IAAQ,GAAG,MAAAJ,IAAO,QAAQ,MAAAK,GAAM,OAAAC,QAAmC;AAC1E,UAAMC,IAA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AAAzC,EAACiE,IAAA,EAAgB,GAAGxB,EAAA,CAAO;AACpC;AC4BO,SAASqC,GACdC,IAAiC,IACT;AAGxB,QAAMzE,IAAW0E,EAAeD,EAAQ,YAAYE,GAAc;AAAA,IAChE,YAAYF,EAAQ;AAAA,IACpB,kBAAkBA,EAAQ;AAAA,EAAA,CAC3B;AAED,WAASF,EAAOpC,GAAoB;AAClC,WACE,gBAAAzC,EAACkF,EAAsB,UAAtB,EAA+B,OAAO5E,GACrC,UAAA,gBAAAN,EAACmF,IAAA,EAAgB,GAAG1C,EAAA,CAAO,EAAA,CAC7B;AAAA,EAEJ;AACAoC,SAAAA,EAAO,cAAc,UAEd,EAAA,QAAEA,EAAA;AACX;"}
@@ -0,0 +1,359 @@
1
+ import w from "jsep";
2
+ import x from "@jsep-plugin/arrow";
3
+ class A {
4
+ cache = /* @__PURE__ */ new Map();
5
+ maxSize;
6
+ constructor(e) {
7
+ this.maxSize = e;
8
+ }
9
+ get(e) {
10
+ const t = this.cache.get(e);
11
+ return t !== void 0 && (this.cache.delete(e), this.cache.set(e, t)), t;
12
+ }
13
+ set(e, t) {
14
+ if (this.cache.delete(e), this.cache.set(e, t), this.cache.size > this.maxSize) {
15
+ const { value: n, done: s } = this.cache.keys().next();
16
+ s || this.cache.delete(n);
17
+ }
18
+ }
19
+ clear() {
20
+ this.cache.clear();
21
+ }
22
+ }
23
+ w.plugins.register(x);
24
+ const C = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
25
+ function m(r, e) {
26
+ if (r != null && !(typeof e == "string" && C.has(e)) && Object.prototype.hasOwnProperty.call(r, e))
27
+ return r[e];
28
+ }
29
+ function g(r) {
30
+ if (r.type === "Identifier") return r.name;
31
+ if (r.type === "MemberExpression") {
32
+ const e = g(r.object);
33
+ if (e == null) return null;
34
+ const t = r.property;
35
+ return r.computed ? t.type !== "Literal" ? null : `${e}[${JSON.stringify(t.value)}]` : t.type !== "Identifier" ? null : `${e}.${t.name}`;
36
+ }
37
+ return null;
38
+ }
39
+ function M(r) {
40
+ const e = r.match(/^[^.[]+/);
41
+ return e ? e[0] : r;
42
+ }
43
+ function E(r) {
44
+ const e = /* @__PURE__ */ new Set();
45
+ function t(n, s) {
46
+ if (n)
47
+ switch (n.type) {
48
+ case "Identifier": {
49
+ const i = n.name;
50
+ s.has(i) || e.add(i);
51
+ return;
52
+ }
53
+ case "MemberExpression": {
54
+ const i = g(n);
55
+ if (i != null) {
56
+ s.has(M(i)) || e.add(i);
57
+ return;
58
+ }
59
+ t(n.object, s), t(n.property, s);
60
+ return;
61
+ }
62
+ case "UnaryExpression":
63
+ t(n.argument, s);
64
+ return;
65
+ case "BinaryExpression":
66
+ t(n.left, s), t(n.right, s);
67
+ return;
68
+ case "ConditionalExpression":
69
+ t(n.test, s), t(n.consequent, s), t(n.alternate, s);
70
+ return;
71
+ case "ArrayExpression":
72
+ n.elements.forEach((i) => t(i, s));
73
+ return;
74
+ case "CallExpression": {
75
+ const i = n.callee;
76
+ i.type === "MemberExpression" && t(i.object, s), n.arguments.forEach((c) => {
77
+ if (c.type === "ArrowFunctionExpression") {
78
+ const a = new Set(s);
79
+ c.params?.forEach((l) => {
80
+ l.type === "Identifier" && a.add(l.name);
81
+ }), t(c.body, a);
82
+ } else
83
+ t(c, s);
84
+ });
85
+ return;
86
+ }
87
+ case "Compound":
88
+ n.body.forEach((i) => t(i, s));
89
+ return;
90
+ default:
91
+ return;
92
+ }
93
+ }
94
+ return t(r, /* @__PURE__ */ new Set()), Array.from(e);
95
+ }
96
+ const u = (r, e = 2) => String(r).padStart(e, "0");
97
+ function U(r) {
98
+ const e = r instanceof Date ? r : new Date(r);
99
+ return Number.isNaN(e.getTime()) ? null : e;
100
+ }
101
+ function f(r) {
102
+ const e = typeof r == "number" ? r : parseFloat(r);
103
+ return Number.isNaN(e) ? 0 : e;
104
+ }
105
+ function y(r) {
106
+ return r.flat(1 / 0).map(f);
107
+ }
108
+ const D = {
109
+ // Uses UTC getters so SSR and client render the same calendar date regardless of local timezone.
110
+ formatDate(r, e = "YYYY-MM-DD") {
111
+ const t = U(r);
112
+ if (!t) return "";
113
+ if (e === "short" || e === "medium" || e === "long" || e === "full")
114
+ return new Intl.DateTimeFormat("en-US", { dateStyle: e, timeZone: "UTC" }).format(t);
115
+ const n = {
116
+ YYYY: String(t.getUTCFullYear()),
117
+ MM: u(t.getUTCMonth() + 1),
118
+ DD: u(t.getUTCDate()),
119
+ HH: u(t.getUTCHours()),
120
+ mm: u(t.getUTCMinutes()),
121
+ ss: u(t.getUTCSeconds())
122
+ };
123
+ return e.replace(/YYYY|MM|DD|HH|mm|ss/g, (s) => n[s]);
124
+ },
125
+ formatCurrency(r, e = "USD", t = "en-US") {
126
+ const n = f(r);
127
+ return new Intl.NumberFormat(t, { style: "currency", currency: e }).format(n);
128
+ },
129
+ upper(r) {
130
+ return String(r ?? "").toUpperCase();
131
+ },
132
+ lower(r) {
133
+ return String(r ?? "").toLowerCase();
134
+ },
135
+ trim(r) {
136
+ return String(r ?? "").trim();
137
+ },
138
+ concat(...r) {
139
+ return r.map((e) => e ?? "").join("");
140
+ },
141
+ join(r, e = ", ") {
142
+ return Array.isArray(r) ? r.join(e) : "";
143
+ },
144
+ default(r, e) {
145
+ return r == null || r === "" ? e : r;
146
+ },
147
+ length(r) {
148
+ return typeof r == "string" || Array.isArray(r) ? r.length : 0;
149
+ },
150
+ count(r) {
151
+ return Array.isArray(r) ? r.length : 0;
152
+ },
153
+ sum(r) {
154
+ return Array.isArray(r) ? r.reduce((e, t) => e + f(t), 0) : 0;
155
+ },
156
+ min(...r) {
157
+ const e = y(r);
158
+ return e.length ? Math.min(...e) : void 0;
159
+ },
160
+ max(...r) {
161
+ const e = y(r);
162
+ return e.length ? Math.max(...e) : void 0;
163
+ },
164
+ round(r, e = 0) {
165
+ const t = 10 ** e;
166
+ return Math.round(f(r) * t) / t;
167
+ }
168
+ }, Y = /* @__PURE__ */ new Set(["map", "filter", "some", "every", "find"]);
169
+ function b(r, e, t) {
170
+ const n = { ...t };
171
+ return (r.params ?? []).forEach((s, i) => {
172
+ s.type === "Identifier" && (n[s.name] = e[i]);
173
+ }), o(r.body, n);
174
+ }
175
+ function o(r, e) {
176
+ switch (r.type) {
177
+ case "Literal":
178
+ return r.value;
179
+ case "Identifier":
180
+ return m(e, r.name);
181
+ case "MemberExpression": {
182
+ const t = o(r.object, e), n = r.property, s = r.computed ? o(n, e) : n.name;
183
+ return m(t, s);
184
+ }
185
+ case "UnaryExpression": {
186
+ const t = o(r.argument, e);
187
+ switch (r.operator) {
188
+ case "!":
189
+ return !t;
190
+ case "-":
191
+ return -t;
192
+ case "+":
193
+ return +t;
194
+ case "~":
195
+ return ~t;
196
+ default:
197
+ throw new Error(`Unknown unary operator: ${r.operator}`);
198
+ }
199
+ }
200
+ case "BinaryExpression": {
201
+ const t = r.operator;
202
+ if (t === "&&" || t === "||" || t === "??") {
203
+ const i = o(r.left, e);
204
+ return (t === "&&" ? !i : t === "||" ? !!i : i != null) ? i : o(r.right, e);
205
+ }
206
+ const n = o(r.left, e), s = o(r.right, e);
207
+ switch (t) {
208
+ case "===":
209
+ return n === s;
210
+ case "!==":
211
+ return n !== s;
212
+ case "==":
213
+ return n == s;
214
+ case "!=":
215
+ return n != s;
216
+ case "<":
217
+ return n < s;
218
+ case ">":
219
+ return n > s;
220
+ case "<=":
221
+ return n <= s;
222
+ case ">=":
223
+ return n >= s;
224
+ case "+":
225
+ return n + s;
226
+ case "-":
227
+ return n - s;
228
+ case "*":
229
+ return n * s;
230
+ case "/":
231
+ return n / s;
232
+ case "%":
233
+ return n % s;
234
+ case "**":
235
+ return n ** s;
236
+ case "&":
237
+ return n & s;
238
+ case "|":
239
+ return n | s;
240
+ case "^":
241
+ return n ^ s;
242
+ case "<<":
243
+ return n << s;
244
+ case ">>":
245
+ return n >> s;
246
+ case ">>>":
247
+ return n >>> s;
248
+ default:
249
+ throw new Error(`Unknown binary operator: ${t}`);
250
+ }
251
+ }
252
+ case "ConditionalExpression": {
253
+ const t = o(r.test, e);
254
+ return o(t ? r.consequent : r.alternate, e);
255
+ }
256
+ case "ArrayExpression":
257
+ return r.elements.map(
258
+ (t) => t ? o(t, e) : void 0
259
+ );
260
+ case "CallExpression": {
261
+ const t = r.callee, n = r.arguments;
262
+ if (t.type === "MemberExpression") {
263
+ if (t.computed || t.property.type !== "Identifier")
264
+ throw new Error(
265
+ "Method calls must use a fixed dot-notation method name"
266
+ );
267
+ const i = t.property.name;
268
+ if (!Y.has(i))
269
+ throw new Error(`Unknown array method: ${i}`);
270
+ const c = o(t.object, e);
271
+ if (!Array.isArray(c))
272
+ throw new Error(`.${i}() can only be called on an array`);
273
+ const [a] = n;
274
+ if (n.length !== 1 || a.type !== "ArrowFunctionExpression")
275
+ throw new Error(
276
+ `.${i}() requires a single arrow-function argument`
277
+ );
278
+ return c[i](
279
+ (l, S) => b(a, [l, S], e)
280
+ );
281
+ }
282
+ if (t.type !== "Identifier")
283
+ throw new Error(
284
+ "Function calls are only allowed via a bare helper name"
285
+ );
286
+ const s = D[t.name];
287
+ if (typeof s != "function")
288
+ throw new Error(`Unknown helper: ${t.name}`);
289
+ return s(...n.map((i) => o(i, e)));
290
+ }
291
+ default:
292
+ throw new Error(`Unsupported expression type: ${r.type}`);
293
+ }
294
+ }
295
+ const p = new A(250);
296
+ function h(r) {
297
+ let e = p.get(r);
298
+ return e || (e = w(r), p.set(r, e), e);
299
+ }
300
+ function $(r) {
301
+ if (!r || typeof r != "string")
302
+ return [];
303
+ if (!r.startsWith("{{") || !r.endsWith("}}"))
304
+ return [];
305
+ const e = r.slice(2, -2).trim();
306
+ if (!e)
307
+ return [];
308
+ try {
309
+ return E(h(e));
310
+ } catch (t) {
311
+ return console.error(`Error extracting variables from "${r}":`, t), [];
312
+ }
313
+ }
314
+ function T(r, e) {
315
+ if (!r || typeof r != "string" || !r.startsWith("{{") || !r.endsWith("}}"))
316
+ return r;
317
+ const t = r.slice(2, -2).trim();
318
+ if (t)
319
+ try {
320
+ return o(h(t), e);
321
+ } catch (n) {
322
+ console.error(`Error parsing expression "${r}":`, n);
323
+ return;
324
+ }
325
+ }
326
+ function j() {
327
+ p.clear();
328
+ }
329
+ function d(r) {
330
+ return typeof r == "string" && r.startsWith("{{") && r.endsWith("}}");
331
+ }
332
+ function F(r) {
333
+ if (!d(r)) return null;
334
+ const e = r.slice(2, -2).trim();
335
+ if (!e)
336
+ return { source: r, content: e, ast: null, error: null, variables: [] };
337
+ try {
338
+ const t = h(e);
339
+ return {
340
+ source: r,
341
+ content: e,
342
+ ast: t,
343
+ error: null,
344
+ variables: E(t)
345
+ };
346
+ } catch (t) {
347
+ return { source: r, content: e, ast: null, error: t, variables: [] };
348
+ }
349
+ }
350
+ export {
351
+ A as L,
352
+ j as a,
353
+ F as c,
354
+ $ as e,
355
+ d as i,
356
+ T as p,
357
+ g as s
358
+ };
359
+ //# sourceMappingURL=index-DzpRdatr.js.map