@getrheo/contracts 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/animations.d.ts +226 -0
  2. package/dist/animations.js +1160 -0
  3. package/dist/animations.js.map +1 -0
  4. package/dist/appIntegrations.d.ts +175 -0
  5. package/dist/appIntegrations.js +60 -0
  6. package/dist/appIntegrations.js.map +1 -0
  7. package/dist/billingPeriod.d.ts +26 -0
  8. package/dist/billingPeriod.js +39 -0
  9. package/dist/billingPeriod.js.map +1 -0
  10. package/dist/canvasEditorGates.d.ts +81 -0
  11. package/dist/canvasEditorGates.js +1460 -0
  12. package/dist/canvasEditorGates.js.map +1 -0
  13. package/dist/constants/index.d.ts +30 -0
  14. package/dist/constants/index.js +67 -0
  15. package/dist/constants/index.js.map +1 -0
  16. package/dist/dashboard.d.ts +181856 -0
  17. package/dist/dashboard.js +3348 -0
  18. package/dist/dashboard.js.map +1 -0
  19. package/dist/decisions.d.ts +575 -0
  20. package/dist/decisions.js +1209 -0
  21. package/dist/decisions.js.map +1 -0
  22. package/dist/events.d.ts +231 -0
  23. package/dist/events.js +63 -0
  24. package/dist/events.js.map +1 -0
  25. package/dist/experiments-DN8pQa_D.d.ts +530 -0
  26. package/dist/externalSurfaceIntegrations.d.ts +20 -0
  27. package/dist/externalSurfaceIntegrations.js +49 -0
  28. package/dist/externalSurfaceIntegrations.js.map +1 -0
  29. package/dist/externalSurfaces.d.ts +177 -0
  30. package/dist/externalSurfaces.js +1190 -0
  31. package/dist/externalSurfaces.js.map +1 -0
  32. package/dist/fields.d.ts +8 -0
  33. package/dist/fields.js +15 -0
  34. package/dist/fields.js.map +1 -0
  35. package/dist/flowManifestSchema-CtqygXCK.d.ts +50857 -0
  36. package/dist/flowTemplateComments.d.ts +23 -0
  37. package/dist/flowTemplateComments.js +14 -0
  38. package/dist/flowTemplateComments.js.map +1 -0
  39. package/dist/flowTemplates.d.ts +22 -0
  40. package/dist/flowTemplates.js +73 -0
  41. package/dist/flowTemplates.js.map +1 -0
  42. package/dist/identity.d.ts +35 -0
  43. package/dist/identity.js +18 -0
  44. package/dist/identity.js.map +1 -0
  45. package/dist/imageContentType.d.ts +11 -0
  46. package/dist/imageContentType.js +54 -0
  47. package/dist/imageContentType.js.map +1 -0
  48. package/dist/index.d.ts +224 -0
  49. package/dist/index.js +4557 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/layerUnion-BzXoAJLY.d.ts +34 -0
  52. package/dist/layers.d.ts +89844 -0
  53. package/dist/layers.js +1507 -0
  54. package/dist/layers.js.map +1 -0
  55. package/dist/layout-D0LpaKG-.d.ts +12896 -0
  56. package/dist/localized.d.ts +17 -0
  57. package/dist/localized.js +18 -0
  58. package/dist/localized.js.map +1 -0
  59. package/dist/manifest.d.ts +22192 -0
  60. package/dist/manifest.js +2163 -0
  61. package/dist/manifest.js.map +1 -0
  62. package/dist/media.d.ts +53 -0
  63. package/dist/media.js +55 -0
  64. package/dist/media.js.map +1 -0
  65. package/dist/planEntitlements.d.ts +65 -0
  66. package/dist/planEntitlements.js +117 -0
  67. package/dist/planEntitlements.js.map +1 -0
  68. package/dist/publish-exports.json +102 -0
  69. package/dist/screens.d.ts +33586 -0
  70. package/dist/screens.js +1439 -0
  71. package/dist/screens.js.map +1 -0
  72. package/dist/sdk.d.ts +145942 -0
  73. package/dist/sdk.js +3424 -0
  74. package/dist/sdk.js.map +1 -0
  75. package/dist/sdkAttributes.d.ts +11 -0
  76. package/dist/sdkAttributes.js +17 -0
  77. package/dist/sdkAttributes.js.map +1 -0
  78. package/dist/workspaceCapabilities.d.ts +15 -0
  79. package/dist/workspaceCapabilities.js +116 -0
  80. package/dist/workspaceCapabilities.js.map +1 -0
  81. package/package.json +162 -0
@@ -0,0 +1,2163 @@
1
+ import { z } from 'zod';
2
+
3
+ // src/manifest/version.ts
4
+ var MANIFEST_SCHEMA_VERSION = 7;
5
+ var ThemeSchema = z.object({
6
+ primary: z.string().optional(),
7
+ primaryForeground: z.string().optional(),
8
+ background: z.string().optional(),
9
+ foreground: z.string().optional(),
10
+ accent: z.string().optional(),
11
+ borderRadius: z.number().optional(),
12
+ fontFamily: z.string().optional()
13
+ });
14
+ var BuilderMetaSchema = z.object({
15
+ layout: z.object({
16
+ nodes: z.array(
17
+ z.object({
18
+ id: z.string(),
19
+ kind: z.enum(["screen", "decision"]).optional(),
20
+ x: z.number(),
21
+ y: z.number()
22
+ })
23
+ ).optional(),
24
+ canvas: z.object({
25
+ zoom: z.number().optional(),
26
+ x: z.number().optional(),
27
+ y: z.number().optional()
28
+ }).optional()
29
+ }).optional()
30
+ }).passthrough().optional();
31
+
32
+ // src/layers/layerSchemaRef.ts
33
+ var layerSchemaStore = {};
34
+ var LocaleCode = z.string().regex(/^[a-z]{2}(-[A-Z]{2})?$/, 'locale must be like "en" or "en-US"');
35
+ var LocalizedTextSchema = z.object({
36
+ default: z.string().min(1, "default copy is required"),
37
+ translations: z.record(LocaleCode, z.string()).optional()
38
+ });
39
+
40
+ // src/hyperlinkHref.ts
41
+ var parseHyperlinkHref = (raw) => {
42
+ const t = raw.trim();
43
+ if (!t) return { ok: false };
44
+ let u;
45
+ try {
46
+ u = new URL(t);
47
+ } catch {
48
+ return { ok: false };
49
+ }
50
+ const scheme = u.protocol.replace(/:$/, "").toLowerCase();
51
+ if (scheme === "https") {
52
+ if (!u.hostname) return { ok: false };
53
+ return { ok: true, scheme: "https", host: u.hostname };
54
+ }
55
+ if (scheme === "mailto") {
56
+ return { ok: true, scheme: "mailto" };
57
+ }
58
+ return { ok: false };
59
+ };
60
+
61
+ // src/constants/index.ts
62
+ var FIELD_CLASSIFICATIONS = ["safe", "sensitive"];
63
+ var MEDIA_TYPES = ["image", "font", "lottie", "video"];
64
+
65
+ // src/media.ts
66
+ var MediaTypeSchema = z.enum(MEDIA_TYPES);
67
+ var MediaReferenceSchema = z.object({
68
+ mediaAssetId: z.string().uuid()
69
+ });
70
+ z.object({
71
+ id: z.string().uuid(),
72
+ orgId: z.string().uuid(),
73
+ type: MediaTypeSchema,
74
+ url: z.string().url(),
75
+ name: z.string().nullable().optional(),
76
+ contentType: z.string(),
77
+ sizeBytes: z.number().int().nonnegative(),
78
+ archivedAt: z.string().datetime().nullable().optional(),
79
+ createdAt: z.string().datetime()
80
+ });
81
+ var LayerIdSchema = z.string().min(1).max(64).regex(/^lyr_[a-z0-9_]+$/i, "layer id must look like lyr_<id>");
82
+ var ScreenIdSchema = z.string().min(1).max(64).regex(/^scr_[a-z0-9_]+$/i, "screen id must look like scr_<id>");
83
+ var RESTING_MOTION_PRESETS = ["translate", "bounce", "scale", "pulse", "rotate"];
84
+ var RestingMotionPresetSchema = z.enum(RESTING_MOTION_PRESETS);
85
+ var RESTING_MOTION_SCALE_DIRECTIONS = ["up", "down"];
86
+ var RestingMotionScaleDirectionSchema = z.enum(RESTING_MOTION_SCALE_DIRECTIONS);
87
+ var RESTING_MOTION_ROTATE_DIRECTIONS = ["clockwise", "counterclockwise"];
88
+ var RestingMotionRotateDirectionSchema = z.enum(RESTING_MOTION_ROTATE_DIRECTIONS);
89
+ var RestingMotionSchema = z.object({
90
+ preset: RestingMotionPresetSchema,
91
+ /**
92
+ * Timeline segment length (ms): motion is active from start until
93
+ * start + durationMs. When {@link loop} is true, the preset pattern repeats
94
+ * every {@link cycleDurationMs} (or preset default) within this window.
95
+ */
96
+ durationMs: z.number().int().min(200).max(2e4).optional(),
97
+ /** When true, repeat the motion pattern within the timeline segment; default is one shot. */
98
+ loop: z.boolean().optional(),
99
+ /**
100
+ * Duration (ms) of one full pattern cycle when looping. Defaults per {@link RESTING_MOTION_DEFAULT_DURATION_MS}.
101
+ */
102
+ cycleDurationMs: z.number().int().min(200).max(2e4).optional(),
103
+ intensity: z.number().min(0).max(2).optional(),
104
+ /** Bounce preset only: vertical lift in px. When omitted, uses `14 * intensity` (default intensity 1 → 14). */
105
+ bounceAmplitudePx: z.number().min(1).max(80).optional(),
106
+ /** Scale preset: grow (+) or shrink (−) toward a peak, then return to 100%. */
107
+ scaleDirection: RestingMotionScaleDirectionSchema.optional(),
108
+ /**
109
+ * Scale preset: when true (default), each cycle goes rest → peak scale → rest.
110
+ * When false, ramps rest → peak and holds; with loop, the next cycle restarts from rest.
111
+ */
112
+ scaleSpringBack: z.boolean().optional(),
113
+ /**
114
+ * Scale preset: magnitude in % — growth above 100% (up to +400% = 5× at peak) or shrink toward
115
+ * 100%− (up to 90% so peak can be 10% size). See authoring caps in the layer editor.
116
+ */
117
+ scalePercent: z.number().min(0).max(400).optional(),
118
+ /**
119
+ * Scale preset: ms for one full out-and-back (rest → peak → rest). Timeline bar still sets
120
+ * {@link durationMs} (when the layer may animate); this controls how fast each cycle runs.
121
+ */
122
+ scalePatternDurationMs: z.number().int().min(200).max(2e4).optional(),
123
+ /** @deprecated Use {@link scalePercent} + {@link scaleDirection}. Kept for legacy manifests. */
124
+ scaleUpPercent: z.number().min(0).max(400).optional(),
125
+ /** @deprecated Use {@link scalePercent} + {@link scaleDirection}. Kept for legacy manifests. */
126
+ scaleDownPercent: z.number().min(0).max(90).optional(),
127
+ /**
128
+ * @deprecated Legacy vertical-only float (px). Prefer {@link translatePeakXPercent} / {@link translatePeakYPercent}.
129
+ */
130
+ translateRangePx: z.number().min(0).max(40).optional(),
131
+ /** @deprecated Legacy peak offsets in px. Prefer {@link translatePeakXPercent} / {@link translatePeakYPercent}. */
132
+ translatePeakXPx: z.number().min(-200).max(200).optional(),
133
+ /** @deprecated Legacy peak offsets in px. Prefer {@link translatePeakXPercent} / {@link translatePeakYPercent}. */
134
+ translatePeakYPx: z.number().min(-200).max(200).optional(),
135
+ /** Translate preset: peak X offset as % of the layer box (−200–200). Scaled by intensity. */
136
+ translatePeakXPercent: z.number().min(-200).max(200).optional(),
137
+ /** Translate preset: peak Y offset as % of the layer box (−200–200). Scaled by intensity. */
138
+ translatePeakYPercent: z.number().min(-200).max(200).optional(),
139
+ /**
140
+ * Translate preset: when true (default), each cycle goes rest → peak offset → rest. When false, ramp to
141
+ * peak and hold; with loop, the next cycle restarts from the origin.
142
+ */
143
+ translateSpringBack: z.boolean().optional(),
144
+ /** Rotate preset: target rotation in degrees (0–360), scaled by intensity. */
145
+ rotateMaxDeg: z.number().min(0).max(360).optional(),
146
+ /** Rotate preset: spin direction; omitted or `clockwise` → positive angles (default). */
147
+ rotateDirection: RestingMotionRotateDirectionSchema.optional(),
148
+ /**
149
+ * Rotate preset: when true (default), each cycle oscillates 0° → peak → 0°.
150
+ * When false, each cycle ramps 0° → peak and holds; with loop, the next cycle snaps to 0° and ramps again.
151
+ */
152
+ rotateSpringBack: z.boolean().optional(),
153
+ /** Pulse preset: minimum opacity at the dip (0–1). Omitted → `1 - 0.38 * intensity`. */
154
+ pulseMinOpacity: z.number().min(0).max(1).optional(),
155
+ /** Ms after the last mount/stagger clip ends before motion applies (authoring + scrub). */
156
+ delayMsAfterMountEnd: z.number().int().min(0).max(6e4).optional(),
157
+ /**
158
+ * Absolute start time (ms from screen mount). When set, overrides
159
+ * {@link delayMsAfterMountEnd} + mount-clip end so motion can sit between
160
+ * clips (e.g. after first entry, before exit) when multiple mounts exist.
161
+ */
162
+ timelineStartMs: z.number().int().min(0).max(36e5).optional()
163
+ }).strict();
164
+ var RestingMotionEntrySchema = RestingMotionSchema.extend({
165
+ id: z.string().min(1)
166
+ });
167
+
168
+ // src/layers/base.ts
169
+ var baseLayerShape = {
170
+ id: LayerIdSchema,
171
+ name: z.string().max(80).optional(),
172
+ restingMotion: RestingMotionSchema.optional(),
173
+ restingMotions: z.array(RestingMotionEntrySchema).optional()
174
+ };
175
+ var ThemedColorModesSchema = z.object({
176
+ light: z.string().min(1).optional(),
177
+ dark: z.string().min(1).optional()
178
+ }).strict().refine((o) => o.light !== void 0 || o.dark !== void 0, {
179
+ message: "at least one of light or dark is required"
180
+ });
181
+ var ThemedColorSchema = z.union([z.string().min(1), ThemedColorModesSchema]);
182
+ var WIDTH_PRESETS = ["auto", "full", "1/2", "1/3", "2/3", "1/4", "3/4"];
183
+ var WidthValueSchema = z.union([z.enum(WIDTH_PRESETS), z.number().int().min(0).max(2e3)]);
184
+ var HEIGHT_PRESETS = ["auto", "full", "fill"];
185
+ var CommonLayoutHeightSchema = z.union([
186
+ z.enum(HEIGHT_PRESETS),
187
+ z.number().int().min(0).max(2e3)
188
+ ]);
189
+
190
+ // src/layers/styleCommon.ts
191
+ var NonNegativePxSchema = z.number().int().min(0);
192
+ var PaddingSchema = z.object({
193
+ t: NonNegativePxSchema.optional(),
194
+ r: NonNegativePxSchema.optional(),
195
+ b: NonNegativePxSchema.optional(),
196
+ l: NonNegativePxSchema.optional()
197
+ }).partial();
198
+ var BorderSchema = z.object({
199
+ width: z.number().int().min(0).max(20).optional(),
200
+ color: ThemedColorSchema.optional()
201
+ }).partial();
202
+ var DropShadowSchema = z.object({
203
+ offsetX: z.number().int().min(-100).max(100).optional(),
204
+ offsetY: z.number().int().min(-100).max(100).optional(),
205
+ blur: z.number().int().min(0).max(100).optional(),
206
+ spread: z.number().int().min(-50).max(50).optional(),
207
+ color: ThemedColorSchema.optional(),
208
+ opacity: z.number().min(0).max(1).optional()
209
+ }).partial();
210
+ var CommonStyleSchema = z.object({
211
+ padding: PaddingSchema.optional(),
212
+ margin: PaddingSchema.optional(),
213
+ radius: z.number().int().min(0).max(96).optional(),
214
+ background: ThemedColorSchema.optional(),
215
+ border: BorderSchema.optional(),
216
+ shadow: DropShadowSchema.optional(),
217
+ opacity: z.number().min(0).max(1).optional(),
218
+ width: WidthValueSchema.optional(),
219
+ /** Omit for normal flow; `'absolute'` removes the layer from flex flow (non-root only). */
220
+ position: z.literal("absolute").optional(),
221
+ /** Pixel insets when `position === 'absolute'` (same shape as padding). */
222
+ inset: PaddingSchema.optional(),
223
+ zIndex: z.number().int().min(-999).max(999).optional(),
224
+ /** Static rotation in degrees (CSS `rotate`); not timeline animation. */
225
+ rotate: z.number().min(-360).max(360).optional(),
226
+ /** Cross-axis size: `auto` (hug), `full`/`fill` (parent height), or fixed px. No fractions. */
227
+ height: CommonLayoutHeightSchema.optional(),
228
+ /** Stroke thickness in px for layers that render a stroke primitive (e.g. loader ring). */
229
+ strokeWidth: z.number().int().min(0).max(64).optional()
230
+ }).partial();
231
+ var TextStyleSchema = CommonStyleSchema.extend({
232
+ /**
233
+ * Logical font family: manifest `theme.fontFamily` when omitted, {@link TEXT_FONT_FAMILY_SYSTEM_UI}
234
+ * for the platform stack, or a custom name (matches `Branding.fontFamilies[].name` for uploaded fonts).
235
+ */
236
+ fontFamily: z.string().min(1).max(128).optional(),
237
+ fontSize: z.number().int().min(8).max(96).optional(),
238
+ fontWeight: z.number().int().min(100).max(900).optional(),
239
+ color: ThemedColorSchema.optional(),
240
+ align: z.enum(["left", "center", "right"]).optional(),
241
+ lineHeight: z.number().min(0.8).max(3).optional(),
242
+ /** Multiplier (0–1) applied to the resolved background color alpha only; text stays fully opaque unless `opacity` is set. */
243
+ backgroundOpacity: z.number().min(0).max(1).optional()
244
+ });
245
+ var ImageStyleSchema = CommonStyleSchema.extend({
246
+ fit: z.enum(["cover", "contain", "fill"]).optional(),
247
+ aspectRatio: z.number().positive().max(10).optional()
248
+ });
249
+ var IconStyleSchema = CommonStyleSchema.extend({
250
+ color: ThemedColorSchema.optional()
251
+ });
252
+ var ICON_FAMILIES = ["ionicons"];
253
+ var ButtonStyleSchema = CommonStyleSchema.extend({
254
+ fontSize: z.number().int().min(8).max(96).optional(),
255
+ fontWeight: z.number().int().min(100).max(900).optional(),
256
+ color: ThemedColorSchema.optional(),
257
+ align: z.enum(["left", "center", "right"]).optional()
258
+ });
259
+ var BUTTON_LAYER_VARIANTS = ["primary", "secondary", "ghost", "destructive"];
260
+ var ButtonLayerVariantSchema = z.enum(BUTTON_LAYER_VARIANTS);
261
+ var CommonStyleBreakpointsSchema = z.object({
262
+ sm: CommonStyleSchema.partial().optional(),
263
+ md: CommonStyleSchema.partial().optional(),
264
+ lg: CommonStyleSchema.partial().optional(),
265
+ xl: CommonStyleSchema.partial().optional(),
266
+ "2xl": CommonStyleSchema.partial().optional()
267
+ }).partial().optional();
268
+ var TextStyleBreakpointsSchema = z.object({
269
+ sm: TextStyleSchema.partial().optional(),
270
+ md: TextStyleSchema.partial().optional(),
271
+ lg: TextStyleSchema.partial().optional(),
272
+ xl: TextStyleSchema.partial().optional(),
273
+ "2xl": TextStyleSchema.partial().optional()
274
+ }).partial().optional();
275
+ var ImageStyleBreakpointsSchema = z.object({
276
+ sm: ImageStyleSchema.partial().optional(),
277
+ md: ImageStyleSchema.partial().optional(),
278
+ lg: ImageStyleSchema.partial().optional(),
279
+ xl: ImageStyleSchema.partial().optional(),
280
+ "2xl": ImageStyleSchema.partial().optional()
281
+ }).partial().optional();
282
+ var IconStyleBreakpointsSchema = z.object({
283
+ sm: IconStyleSchema.partial().optional(),
284
+ md: IconStyleSchema.partial().optional(),
285
+ lg: IconStyleSchema.partial().optional(),
286
+ xl: IconStyleSchema.partial().optional(),
287
+ "2xl": IconStyleSchema.partial().optional()
288
+ }).partial().optional();
289
+ var ButtonStyleBreakpointsSchema = z.object({
290
+ sm: ButtonStyleSchema.partial().optional(),
291
+ md: ButtonStyleSchema.partial().optional(),
292
+ lg: ButtonStyleSchema.partial().optional(),
293
+ xl: ButtonStyleSchema.partial().optional(),
294
+ "2xl": ButtonStyleSchema.partial().optional()
295
+ }).partial().optional();
296
+ var StackLayoutBreakpointPatchSchema = z.object({
297
+ gap: NonNegativePxSchema.optional(),
298
+ direction: z.enum(["vertical", "horizontal"]).optional()
299
+ }).partial();
300
+ var StackLayoutBreakpointsSchema = z.object({
301
+ sm: StackLayoutBreakpointPatchSchema.optional(),
302
+ md: StackLayoutBreakpointPatchSchema.optional(),
303
+ lg: StackLayoutBreakpointPatchSchema.optional(),
304
+ xl: StackLayoutBreakpointPatchSchema.optional(),
305
+ "2xl": StackLayoutBreakpointPatchSchema.optional()
306
+ }).partial().optional();
307
+ var ButtonLayoutBreakpointPatchSchema = z.object({
308
+ gap: NonNegativePxSchema.optional(),
309
+ direction: z.enum(["vertical", "horizontal"]).optional()
310
+ }).partial();
311
+ var ButtonLayoutBreakpointsSchema = z.object({
312
+ sm: ButtonLayoutBreakpointPatchSchema.optional(),
313
+ md: ButtonLayoutBreakpointPatchSchema.optional(),
314
+ lg: ButtonLayoutBreakpointPatchSchema.optional(),
315
+ xl: ButtonLayoutBreakpointPatchSchema.optional(),
316
+ "2xl": ButtonLayoutBreakpointPatchSchema.optional()
317
+ }).partial().optional();
318
+ var OS_PERMISSION_KEYS = [
319
+ "notifications",
320
+ "camera",
321
+ "microphone",
322
+ "photo_library",
323
+ "contacts",
324
+ "calendar",
325
+ "reminders",
326
+ "location_when_in_use",
327
+ "location_always",
328
+ "motion",
329
+ "bluetooth",
330
+ "app_tracking_transparency",
331
+ "speech_recognition",
332
+ "face_id",
333
+ "health_kit",
334
+ "media_library",
335
+ "local_network",
336
+ "nearby_interactions",
337
+ "nfc",
338
+ "full_screen_intent_android",
339
+ "sms_android",
340
+ "phone_android"
341
+ ];
342
+ var OsPermissionKeySchema = z.enum(OS_PERMISSION_KEYS);
343
+ var PERMISSION_CAPTURE_FIELD_KEY_PREFIX = "permission:";
344
+ var permissionCaptureFieldKey = (key) => `${PERMISSION_CAPTURE_FIELD_KEY_PREFIX}${key}`;
345
+ var PERMISSION_OUTCOME_VALUES = ["granted", "denied", "blocked"];
346
+ z.enum(PERMISSION_OUTCOME_VALUES);
347
+ var OS_PERMISSION_OUTCOME_CONTINUE = "continue";
348
+ var OS_PERMISSION_OUTCOME_END = "end";
349
+ var OsPermissionOutcomeBranchTargetSchema = z.union([
350
+ ScreenIdSchema,
351
+ z.literal(OS_PERMISSION_OUTCOME_CONTINUE),
352
+ z.literal(OS_PERMISSION_OUTCOME_END)
353
+ ]);
354
+ var OsPermissionOutcomesSchema = z.object({
355
+ granted: OsPermissionOutcomeBranchTargetSchema,
356
+ denied: OsPermissionOutcomeBranchTargetSchema,
357
+ blocked: OsPermissionOutcomeBranchTargetSchema
358
+ }).strict();
359
+ var APP_REVIEW_OUTCOMES = ["not_shown", "dismissed"];
360
+ z.enum(APP_REVIEW_OUTCOMES);
361
+ var ButtonActionSchema = z.discriminatedUnion("kind", [
362
+ z.object({ kind: z.literal("none") }),
363
+ z.object({ kind: z.literal("continue") }),
364
+ z.object({ kind: z.literal("skip") }),
365
+ z.object({ kind: z.literal("end_flow") }),
366
+ z.object({
367
+ kind: z.literal("go_back_one_screen"),
368
+ fallbackScreenId: ScreenIdSchema.optional()
369
+ }),
370
+ z.object({ kind: z.literal("go_to_step"), screenId: ScreenIdSchema }),
371
+ z.object({
372
+ kind: z.literal("request_os_permission"),
373
+ permissionKey: OsPermissionKeySchema,
374
+ outcomes: OsPermissionOutcomesSchema
375
+ }),
376
+ z.object({
377
+ kind: z.literal("play_media"),
378
+ targetLayerIds: z.array(z.string().min(1)).min(1)
379
+ }),
380
+ z.object({ kind: z.literal("request_app_review") })
381
+ ]);
382
+ var TEXT_INPUT_TYPES = ["plain", "email", "phone", "url", "multiline"];
383
+ var TextInputTypeSchema = z.enum(TEXT_INPUT_TYPES);
384
+ var COUNTER_DISPLAY_KINDS = ["number", "time"];
385
+ var COUNTER_TIME_FORMATS = ["mm_ss", "hh_mm_ss", "dd_hh_mm_ss"];
386
+ var CheckboxGlyphStyleSchema = z.object({
387
+ /** Square edge length in px. */
388
+ size: z.number().int().min(8).max(128).optional(),
389
+ radius: z.number().int().min(0).max(96).optional(),
390
+ background: ThemedColorSchema.optional(),
391
+ border: BorderSchema.optional(),
392
+ shadow: DropShadowSchema.optional(),
393
+ opacity: z.number().min(0).max(1).optional(),
394
+ /** Fill color for the check mark when checked. */
395
+ checkColor: ThemedColorSchema.optional()
396
+ }).partial();
397
+ var OAUTH_LOGIN_PRESETS = ["github", "google", "apple"];
398
+ var OAuthPresetButtonChromeSchema = CommonStyleSchema.pick({
399
+ width: true,
400
+ padding: true,
401
+ margin: true,
402
+ radius: true
403
+ }).partial();
404
+ var OAuthPresetButtonChromeBreakpointsSchema = z.object({
405
+ sm: OAuthPresetButtonChromeSchema.partial().optional(),
406
+ md: OAuthPresetButtonChromeSchema.partial().optional(),
407
+ lg: OAuthPresetButtonChromeSchema.partial().optional(),
408
+ xl: OAuthPresetButtonChromeSchema.partial().optional(),
409
+ "2xl": OAuthPresetButtonChromeSchema.partial().optional()
410
+ }).partial().optional();
411
+ var EMAIL_PASSWORD_AUTH_MODES = ["sign_in", "sign_up"];
412
+ var EMAIL_PASSWORD_SLOTS = ["email", "password", "confirm"];
413
+
414
+ // src/layers/kinds/chrome.ts
415
+ var lazyLayer = () => layerSchemaStore.schema;
416
+ var ButtonLayerSchema = z.object({
417
+ ...baseLayerShape,
418
+ kind: z.literal("button"),
419
+ children: z.lazy(() => z.array(lazyLayer())),
420
+ action: ButtonActionSchema,
421
+ variant: ButtonLayerVariantSchema,
422
+ direction: z.enum(["vertical", "horizontal"]).optional(),
423
+ gap: z.number().int().min(0).optional(),
424
+ align: z.enum(["start", "center", "end", "stretch"]).optional(),
425
+ distribution: z.enum(["start", "center", "end", "between", "around"]).optional(),
426
+ style: ButtonStyleSchema.optional(),
427
+ styleBreakpoints: ButtonStyleBreakpointsSchema,
428
+ buttonLayoutBreakpoints: ButtonLayoutBreakpointsSchema
429
+ });
430
+ var BackButtonLayerSchema = z.object({
431
+ ...baseLayerShape,
432
+ kind: z.literal("back_button"),
433
+ children: z.lazy(() => z.array(lazyLayer())),
434
+ variant: ButtonLayerVariantSchema,
435
+ direction: z.enum(["vertical", "horizontal"]).optional(),
436
+ gap: z.number().int().min(0).optional(),
437
+ align: z.enum(["start", "center", "end", "stretch"]).optional(),
438
+ distribution: z.enum(["start", "center", "end", "between", "around"]).optional(),
439
+ style: ButtonStyleSchema.optional(),
440
+ styleBreakpoints: ButtonStyleBreakpointsSchema,
441
+ buttonLayoutBreakpoints: ButtonLayoutBreakpointsSchema,
442
+ fallbackScreenId: ScreenIdSchema.optional()
443
+ });
444
+ var ProgressLayerSchema = z.object({
445
+ ...baseLayerShape,
446
+ kind: z.literal("progress"),
447
+ trackColor: ThemedColorSchema.optional(),
448
+ fillColor: ThemedColorSchema.optional(),
449
+ style: CommonStyleSchema.optional()
450
+ });
451
+ var LoaderOnCompleteSchema = z.discriminatedUnion("mode", [
452
+ z.object({ mode: z.literal("none") }),
453
+ z.object({ mode: z.literal("next") }),
454
+ z.object({ mode: z.literal("screen"), screenId: ScreenIdSchema })
455
+ ]);
456
+ var LoaderLayerSchema = z.object({
457
+ ...baseLayerShape,
458
+ kind: z.literal("loader"),
459
+ variant: z.enum(["linear", "circular"]).optional(),
460
+ targetPercent: z.number().int().min(0).max(100).optional(),
461
+ fillDelayMs: z.number().int().min(0).max(1e4).optional(),
462
+ durationMs: z.number().int().min(0).max(36e5).optional(),
463
+ onComplete: LoaderOnCompleteSchema.optional(),
464
+ trackColor: ThemedColorSchema.optional(),
465
+ trackOpacity: z.number().min(0).max(1).optional(),
466
+ fillColor: ThemedColorSchema.optional(),
467
+ /** Horizontal alignment of the bar or ring within the layer box (default start). */
468
+ align: z.enum(["start", "center", "end"]).optional(),
469
+ style: CommonStyleSchema.optional()
470
+ }).superRefine((data, ctx) => {
471
+ if (data.variant !== "circular") return;
472
+ const w = data.style?.width;
473
+ const h = data.style?.height;
474
+ if (typeof w === "number" && typeof h === "number" && w !== h) {
475
+ ctx.addIssue({
476
+ code: z.ZodIssueCode.custom,
477
+ message: "circular loader requires style.width === style.height",
478
+ path: ["style", "height"]
479
+ });
480
+ }
481
+ });
482
+ var CounterLayerSchema = z.object({
483
+ ...baseLayerShape,
484
+ kind: z.literal("counter"),
485
+ startValue: z.number().finite(),
486
+ endValue: z.number().finite(),
487
+ durationMs: z.number().int().min(0).max(36e5).optional(),
488
+ delayMs: z.number().int().min(0).max(36e5).optional(),
489
+ decimalPlaces: z.number().int().min(0).max(10).optional(),
490
+ displayKind: z.enum(COUNTER_DISPLAY_KINDS).optional(),
491
+ timeFormat: z.enum(COUNTER_TIME_FORMATS).optional(),
492
+ style: TextStyleSchema.optional(),
493
+ styleBreakpoints: TextStyleBreakpointsSchema
494
+ });
495
+ var CheckboxLayerSchema = z.object({
496
+ ...baseLayerShape,
497
+ kind: z.literal("checkbox"),
498
+ fieldKey: z.string().min(1),
499
+ blocking: z.boolean().optional(),
500
+ uncheckedStyle: CheckboxGlyphStyleSchema.optional(),
501
+ checkedStyle: CheckboxGlyphStyleSchema.optional(),
502
+ style: CommonStyleSchema.optional(),
503
+ styleBreakpoints: CommonStyleBreakpointsSchema
504
+ });
505
+
506
+ // src/layers/kinds/layout.ts
507
+ var lazyLayer2 = () => layerSchemaStore.schema;
508
+ var StackLayerSchema = z.object({
509
+ ...baseLayerShape,
510
+ kind: z.literal("stack"),
511
+ style: CommonStyleSchema.optional(),
512
+ styleBreakpoints: CommonStyleBreakpointsSchema,
513
+ stackLayoutBreakpoints: StackLayoutBreakpointsSchema,
514
+ selectedStyle: CommonStyleSchema.optional(),
515
+ direction: z.enum(["vertical", "horizontal"]),
516
+ gap: z.number().int().min(0).optional(),
517
+ align: z.enum(["start", "center", "end", "stretch"]).optional(),
518
+ justify: z.enum(["start", "center", "end"]).optional(),
519
+ distribution: z.enum(["start", "center", "end", "between", "around"]).optional(),
520
+ wrap: z.boolean().optional(),
521
+ children: z.lazy(() => z.array(lazyLayer2()))
522
+ });
523
+ var TextLayerSchema = z.object({
524
+ ...baseLayerShape,
525
+ kind: z.literal("text"),
526
+ text: LocalizedTextSchema,
527
+ style: TextStyleSchema.optional(),
528
+ styleBreakpoints: TextStyleBreakpointsSchema
529
+ });
530
+ var migrateLegacyHyperlinkForParse = (raw) => {
531
+ if (!raw || typeof raw !== "object") return raw;
532
+ const o = raw;
533
+ if (o.kind !== "hyperlink") return raw;
534
+ const existing = o.children;
535
+ if (Array.isArray(existing) && existing.length > 0) return raw;
536
+ const idSrc = typeof o.id === "string" ? o.id.replace(/[^a-zA-Z0-9_]/g, "_") : "lyr_hyperlink";
537
+ const textChildId = `${idSrc}_lnktxt`.slice(0, 64);
538
+ const children = [
539
+ {
540
+ id: textChildId,
541
+ kind: "text",
542
+ text: o.text ?? { default: "Link" },
543
+ ...typeof o.style === "object" && o.style !== null ? { style: o.style } : {},
544
+ ...typeof o.styleBreakpoints === "object" && o.styleBreakpoints !== null ? { styleBreakpoints: o.styleBreakpoints } : {}
545
+ }
546
+ ];
547
+ const next = {
548
+ ...o,
549
+ children
550
+ };
551
+ delete next.text;
552
+ delete next.style;
553
+ delete next.styleBreakpoints;
554
+ return next;
555
+ };
556
+ var HyperlinkLayerSchemaInner = z.object({
557
+ ...baseLayerShape,
558
+ kind: z.literal("hyperlink"),
559
+ href: z.string().min(1).max(2048),
560
+ children: z.lazy(() => z.array(lazyLayer2()).min(1)),
561
+ direction: z.enum(["vertical", "horizontal"]).optional(),
562
+ gap: z.number().int().min(0).optional(),
563
+ align: z.enum(["start", "center", "end", "stretch"]).optional(),
564
+ distribution: z.enum(["start", "center", "end", "between", "around"]).optional(),
565
+ wrap: z.boolean().optional(),
566
+ style: CommonStyleSchema.optional(),
567
+ styleBreakpoints: CommonStyleBreakpointsSchema
568
+ }).superRefine((data, ctx) => {
569
+ const p = parseHyperlinkHref(data.href.trim());
570
+ if (!p.ok) {
571
+ ctx.addIssue({
572
+ code: z.ZodIssueCode.custom,
573
+ message: "hyperlink href must be a valid https: or mailto: URL",
574
+ path: ["href"]
575
+ });
576
+ }
577
+ });
578
+ var HyperlinkLayerSchema = z.preprocess(
579
+ migrateLegacyHyperlinkForParse,
580
+ HyperlinkLayerSchemaInner
581
+ );
582
+ var ImageLayerSchema = z.object({
583
+ ...baseLayerShape,
584
+ kind: z.literal("image"),
585
+ media: MediaReferenceSchema.optional(),
586
+ alt: z.string().max(280).optional(),
587
+ style: ImageStyleSchema.optional(),
588
+ styleBreakpoints: ImageStyleBreakpointsSchema
589
+ });
590
+ var LottieLayerSchema = z.object({
591
+ ...baseLayerShape,
592
+ kind: z.literal("lottie"),
593
+ media: MediaReferenceSchema.optional(),
594
+ loop: z.boolean().optional(),
595
+ autoPlay: z.boolean().optional(),
596
+ triggerLayerId: z.string().min(1).optional(),
597
+ onComplete: LoaderOnCompleteSchema.optional(),
598
+ style: ImageStyleSchema.optional(),
599
+ styleBreakpoints: ImageStyleBreakpointsSchema
600
+ });
601
+ var VideoLayerSchema = z.object({
602
+ ...baseLayerShape,
603
+ kind: z.literal("video"),
604
+ media: MediaReferenceSchema.optional(),
605
+ loop: z.boolean().optional(),
606
+ autoPlay: z.boolean().optional(),
607
+ triggerLayerId: z.string().min(1).optional(),
608
+ onComplete: LoaderOnCompleteSchema.optional(),
609
+ audioEnabled: z.boolean().optional(),
610
+ style: ImageStyleSchema.optional(),
611
+ styleBreakpoints: ImageStyleBreakpointsSchema
612
+ });
613
+ var IconLayerSchema = z.object({
614
+ ...baseLayerShape,
615
+ kind: z.literal("icon"),
616
+ family: z.enum(ICON_FAMILIES),
617
+ iconName: z.string().min(1).max(128),
618
+ style: IconStyleSchema.optional(),
619
+ styleBreakpoints: IconStyleBreakpointsSchema
620
+ });
621
+ var lazyLayer3 = () => layerSchemaStore.schema;
622
+ var OAuthProviderPresetLayerSchema = z.object({
623
+ ...baseLayerShape,
624
+ kind: z.literal("oauth_provider"),
625
+ variant: z.literal("preset"),
626
+ provider: z.enum(OAUTH_LOGIN_PRESETS),
627
+ label: LocalizedTextSchema.optional(),
628
+ style: OAuthPresetButtonChromeSchema.optional(),
629
+ styleBreakpoints: OAuthPresetButtonChromeBreakpointsSchema.optional()
630
+ });
631
+ var migrateOAuthProviderCustomIncoming = (raw) => {
632
+ if (!raw || typeof raw !== "object") return raw;
633
+ const o = raw;
634
+ if (o.kind !== "oauth_provider" || o.variant !== "custom") return raw;
635
+ const ch = o.children;
636
+ if (Array.isArray(ch) && ch.length > 0) {
637
+ const next2 = { ...o };
638
+ if (next2.buttonVariant === void 0) next2.buttonVariant = "secondary";
639
+ return next2;
640
+ }
641
+ const pid = typeof o.id === "string" ? o.id : "lyr_oauth_custom";
642
+ const slug = pid.replace(/[^a-z0-9_]/gi, "_").slice(0, 40) || "oauth";
643
+ const label = o.label ?? { default: "Custom" };
644
+ let family = o.family ?? "ionicons";
645
+ let iconName = o.iconName ?? "shield-outline";
646
+ if (family === "sf_symbol") {
647
+ family = "ionicons";
648
+ iconName = "star-outline";
649
+ }
650
+ const cid = slug;
651
+ const iconId = `lyr_${cid}_ico`.slice(0, 64);
652
+ const textId = `lyr_${cid}_txt`.slice(0, 64);
653
+ const next = { ...o };
654
+ delete next.label;
655
+ delete next.family;
656
+ delete next.iconName;
657
+ return {
658
+ ...next,
659
+ buttonVariant: o.buttonVariant ?? "secondary",
660
+ children: [
661
+ { id: iconId, kind: "icon", family, iconName },
662
+ { id: textId, kind: "text", text: label }
663
+ ]
664
+ };
665
+ };
666
+ var OAuthProviderCustomLayerSchemaValidated = z.object({
667
+ ...baseLayerShape,
668
+ kind: z.literal("oauth_provider"),
669
+ variant: z.literal("custom"),
670
+ rowId: z.string().uuid(),
671
+ buttonVariant: ButtonLayerVariantSchema,
672
+ direction: z.enum(["vertical", "horizontal"]).optional(),
673
+ gap: z.number().int().min(0).optional(),
674
+ align: z.enum(["start", "center", "end", "stretch"]).optional(),
675
+ distribution: z.enum(["start", "center", "end", "between", "around"]).optional(),
676
+ children: z.lazy(() => z.array(lazyLayer3()).min(1)),
677
+ style: ButtonStyleSchema.optional(),
678
+ styleBreakpoints: ButtonStyleBreakpointsSchema,
679
+ buttonLayoutBreakpoints: ButtonLayoutBreakpointsSchema
680
+ });
681
+ var OAuthProviderCustomLayerSchema = z.preprocess(
682
+ migrateOAuthProviderCustomIncoming,
683
+ OAuthProviderCustomLayerSchemaValidated
684
+ );
685
+ var OAuthProviderLayerSchema = z.union([
686
+ OAuthProviderPresetLayerSchema,
687
+ OAuthProviderCustomLayerSchema
688
+ ]);
689
+ var OAuthLoginPresetProviderSchema = z.object({
690
+ type: z.literal("preset"),
691
+ provider: z.enum(OAUTH_LOGIN_PRESETS)
692
+ });
693
+ var OAuthLoginCustomProviderSchema = z.object({
694
+ type: z.literal("custom"),
695
+ rowId: z.string().uuid(),
696
+ label: LocalizedTextSchema,
697
+ family: z.enum(ICON_FAMILIES),
698
+ iconName: z.string().min(1).max(128)
699
+ });
700
+ var OAuthLoginProviderSchema = z.discriminatedUnion("type", [
701
+ OAuthLoginPresetProviderSchema,
702
+ OAuthLoginCustomProviderSchema
703
+ ]);
704
+ var oauthLoginChildrenUniquePresets = (children, ctx) => {
705
+ const seen = /* @__PURE__ */ new Set();
706
+ for (let i = 0; i < children.length; i++) {
707
+ const c = children[i];
708
+ if (!c || c.kind !== "oauth_provider" || c.variant !== "preset") continue;
709
+ const preset = c.provider;
710
+ if (seen.has(preset)) {
711
+ ctx.addIssue({
712
+ code: z.ZodIssueCode.custom,
713
+ message: `duplicate OAuth preset "${preset}"`,
714
+ path: ["children", i, "provider"]
715
+ });
716
+ return;
717
+ }
718
+ seen.add(preset);
719
+ }
720
+ };
721
+ var migrateOAuthLoginIncoming = (raw) => {
722
+ if (!raw || typeof raw !== "object") return raw;
723
+ const o = raw;
724
+ if (o.kind !== "oauth_login") return raw;
725
+ if (Array.isArray(o.children) && o.children.length > 0) return raw;
726
+ const provs = o.providers;
727
+ if (!Array.isArray(provs) || provs.length === 0) return raw;
728
+ const pid = typeof o.id === "string" ? o.id : "lyr_oauth_legacy";
729
+ const slug = pid.replace(/^lyr_/i, "").replace(/[^a-z0-9_]/gi, "_").replace(/^_+/, "").slice(0, 48) || "oauth";
730
+ const children = provs.map((p, idx) => {
731
+ const prov = p ?? {};
732
+ const cid = `lyr_${slug}_opr_${idx}`.slice(0, 64);
733
+ if (prov.type === "preset") {
734
+ return {
735
+ id: cid,
736
+ kind: "oauth_provider",
737
+ variant: "preset",
738
+ provider: prov.provider
739
+ };
740
+ }
741
+ return {
742
+ id: cid,
743
+ kind: "oauth_provider",
744
+ variant: "custom",
745
+ rowId: String(prov.rowId),
746
+ buttonVariant: "secondary",
747
+ children: [
748
+ {
749
+ id: `${cid}_ico`.slice(0, 64),
750
+ kind: "icon",
751
+ family: prov.family ?? "ionicons",
752
+ iconName: String(prov.iconName ?? "shield")
753
+ },
754
+ {
755
+ id: `${cid}_txt`.slice(0, 64),
756
+ kind: "text",
757
+ text: prov.label ?? { default: "Custom" }
758
+ }
759
+ ]
760
+ };
761
+ });
762
+ const { providers: _omit, ...rest } = o;
763
+ return { ...rest, children };
764
+ };
765
+ var OAuthLoginLayerSchemaValidated = z.object({
766
+ ...baseLayerShape,
767
+ kind: z.literal("oauth_login"),
768
+ children: z.lazy(
769
+ () => z.array(OAuthProviderLayerSchema).min(1).superRefine(oauthLoginChildrenUniquePresets)
770
+ ),
771
+ gap: z.number().int().min(0).optional(),
772
+ align: z.enum(["start", "center", "end", "stretch"]).optional(),
773
+ style: CommonStyleSchema.optional(),
774
+ styleBreakpoints: CommonStyleBreakpointsSchema
775
+ });
776
+ var OAuthLoginLayerSchema = z.preprocess(
777
+ migrateOAuthLoginIncoming,
778
+ OAuthLoginLayerSchemaValidated
779
+ );
780
+ z.array(OAuthLoginProviderSchema).min(1).superRefine((providers, ctx) => {
781
+ const seen = /* @__PURE__ */ new Set();
782
+ for (let i = 0; i < providers.length; i++) {
783
+ const p = providers[i];
784
+ if (!p || p.type !== "preset") continue;
785
+ const preset = p.provider;
786
+ if (seen.has(preset)) {
787
+ ctx.addIssue({
788
+ code: z.ZodIssueCode.custom,
789
+ message: `duplicate OAuth preset "${preset}"`,
790
+ path: [i, "provider"]
791
+ });
792
+ return;
793
+ }
794
+ seen.add(preset);
795
+ }
796
+ });
797
+ var FIELD_KEY_RE = /^[a-z][a-z0-9_]*$/;
798
+ var FieldKeySchema = z.string().min(1).max(64).regex(FIELD_KEY_RE, "field key must be snake_case");
799
+ var FieldClassificationSchema = z.enum(FIELD_CLASSIFICATIONS);
800
+
801
+ // src/layers/kinds/auth/emailPasswordAuth.ts
802
+ var lazyLayer4 = () => layerSchemaStore.schema;
803
+ var EmailPasswordAuthModeSchema = z.enum(EMAIL_PASSWORD_AUTH_MODES);
804
+ var migrateEmailPasswordAuthIncoming = (raw) => {
805
+ if (!raw || typeof raw !== "object") return raw;
806
+ const o = raw;
807
+ if (o.kind !== "email_password_auth") return raw;
808
+ if (Array.isArray(o.children) && o.children.length > 0) return raw;
809
+ const idBase = typeof o.id === "string" ? o.id : "lyr_email_password_auth";
810
+ const slugRaw = idBase.replace(/^lyr_/i, "").replace(/[^a-z0-9_]/gi, "_");
811
+ const slug = slugRaw.length > 0 ? slugRaw.slice(0, 40) : "ep_auth";
812
+ const mode = o.mode === "sign_up" ? "sign_up" : "sign_in";
813
+ const pickLt = (v, fallback) => v && typeof v === "object" && v !== null && "default" in v ? v : { default: fallback };
814
+ const mkField = (suf, slot, labelSource, fallbackPlaceholder) => ({
815
+ id: `lyr_${slug}_fld_${suf}`.slice(0, 64),
816
+ kind: "email_password_field",
817
+ slot,
818
+ ...labelSource ? { placeholder: pickLt(labelSource, fallbackPlaceholder) } : { placeholder: { default: fallbackPlaceholder } },
819
+ children: []
820
+ });
821
+ const children = [];
822
+ children.push(mkField("email", "email", o.emailLabel, "Email"));
823
+ children.push(mkField("pw", "password", o.passwordLabel, "Password"));
824
+ if (mode === "sign_up") {
825
+ children.push(mkField("cf", "confirm", o.confirmPasswordLabel, "Confirm password"));
826
+ }
827
+ const submitLbl = o.submitLabel ?? { default: mode === "sign_in" ? "Sign in" : "Create account" };
828
+ children.push({
829
+ id: `lyr_${slug}_submit`.slice(0, 64),
830
+ kind: "email_password_submit",
831
+ buttonVariant: "primary",
832
+ direction: "horizontal",
833
+ align: "center",
834
+ distribution: "center",
835
+ gap: 8,
836
+ children: [
837
+ {
838
+ id: `lyr_${slug}_submit_txt`.slice(0, 64),
839
+ kind: "text",
840
+ text: submitLbl
841
+ }
842
+ ]
843
+ });
844
+ const {
845
+ emailLabel: _e,
846
+ passwordLabel: _p,
847
+ confirmPasswordLabel: _c,
848
+ submitLabel: _s,
849
+ ...rest
850
+ } = o;
851
+ return { ...rest, mode, children };
852
+ };
853
+ var refineEmailPasswordAuthChildren = (data, ctx) => {
854
+ const fields = data.children.filter((c) => c.kind === "email_password_field");
855
+ const submits = data.children.filter((c) => c.kind === "email_password_submit");
856
+ const slotSeen = /* @__PURE__ */ new Set();
857
+ for (const f of fields) {
858
+ if (slotSeen.has(f.slot)) {
859
+ ctx.addIssue({
860
+ code: z.ZodIssueCode.custom,
861
+ message: `duplicate email_password_field slot "${f.slot}"`,
862
+ path: ["children"]
863
+ });
864
+ }
865
+ slotSeen.add(f.slot);
866
+ }
867
+ const slotHas = new Set(fields.map((f) => f.slot));
868
+ const requiredSlots = data.mode === "sign_up" ? ["email", "password", "confirm"] : ["email", "password"];
869
+ for (const s of requiredSlots) {
870
+ if (!slotHas.has(s)) {
871
+ ctx.addIssue({
872
+ code: z.ZodIssueCode.custom,
873
+ message: data.mode === "sign_up" ? `sign_up requires an email_password_field with slot "${s}"` : `sign_in requires an email_password_field with slot "${s}"`,
874
+ path: ["children"]
875
+ });
876
+ }
877
+ }
878
+ if (data.mode === "sign_in" && slotHas.has("confirm")) {
879
+ ctx.addIssue({
880
+ code: z.ZodIssueCode.custom,
881
+ message: 'sign_in must not include email_password_field with slot "confirm"',
882
+ path: ["children"]
883
+ });
884
+ }
885
+ if (submits.length !== 1) {
886
+ ctx.addIssue({
887
+ code: z.ZodIssueCode.custom,
888
+ message: `email_password_auth must have exactly one email_password_submit (found ${submits.length})`,
889
+ path: ["children"]
890
+ });
891
+ }
892
+ };
893
+ var EmailPasswordFieldLayerSchema = z.object({
894
+ ...baseLayerShape,
895
+ kind: z.literal("email_password_field"),
896
+ slot: z.enum(EMAIL_PASSWORD_SLOTS),
897
+ placeholder: LocalizedTextSchema.optional(),
898
+ children: z.lazy(() => z.array(lazyLayer4())).optional(),
899
+ style: CommonStyleSchema.optional(),
900
+ styleBreakpoints: CommonStyleBreakpointsSchema
901
+ });
902
+ var EmailPasswordSubmitLayerSchema = z.object({
903
+ ...baseLayerShape,
904
+ kind: z.literal("email_password_submit"),
905
+ buttonVariant: ButtonLayerVariantSchema,
906
+ direction: z.enum(["vertical", "horizontal"]).optional(),
907
+ gap: z.number().int().min(0).optional(),
908
+ align: z.enum(["start", "center", "end", "stretch"]).optional(),
909
+ distribution: z.enum(["start", "center", "end", "between", "around"]).optional(),
910
+ children: z.lazy(() => z.array(lazyLayer4()).min(1)),
911
+ style: ButtonStyleSchema.optional(),
912
+ styleBreakpoints: ButtonStyleBreakpointsSchema,
913
+ buttonLayoutBreakpoints: ButtonLayoutBreakpointsSchema
914
+ });
915
+ var EmailPasswordAuthLayerSchemaValidated = z.object({
916
+ ...baseLayerShape,
917
+ kind: z.literal("email_password_auth"),
918
+ mode: EmailPasswordAuthModeSchema,
919
+ fieldKey: FieldKeySchema,
920
+ minPasswordLength: z.number().int().min(4).max(128).optional(),
921
+ children: z.lazy(
922
+ () => z.array(z.union([EmailPasswordFieldLayerSchema, EmailPasswordSubmitLayerSchema])).min(1)
923
+ ),
924
+ gap: z.number().int().min(0).optional(),
925
+ align: z.enum(["start", "center", "end", "stretch"]).optional(),
926
+ style: CommonStyleSchema.optional(),
927
+ styleBreakpoints: CommonStyleBreakpointsSchema
928
+ }).superRefine(refineEmailPasswordAuthChildren);
929
+ var EmailPasswordAuthLayerSchema = z.preprocess(
930
+ migrateEmailPasswordAuthIncoming,
931
+ EmailPasswordAuthLayerSchemaValidated
932
+ );
933
+ var ChoiceOptionBindingSchema = z.object({
934
+ optionId: z.string().min(1).max(64),
935
+ rootLayerId: LayerIdSchema
936
+ });
937
+ var BranchConditionSchema = z.object({
938
+ choiceId: z.string().min(1),
939
+ goTo: ScreenIdSchema
940
+ });
941
+ var ChoiceBranchingSchema = z.object({
942
+ enabled: z.boolean(),
943
+ conditions: z.array(BranchConditionSchema)
944
+ });
945
+
946
+ // src/layers/kinds/input.ts
947
+ var lazyLayer5 = () => layerSchemaStore.schema;
948
+ var ChoiceChildrenAndBindingsRefinement = (data, ctx) => {
949
+ const childIds = /* @__PURE__ */ new Set();
950
+ for (const c of data.children) {
951
+ if (childIds.has(c.id)) {
952
+ ctx.addIssue({
953
+ code: z.ZodIssueCode.custom,
954
+ message: `duplicate option child id "${c.id}"`,
955
+ path: ["children"]
956
+ });
957
+ }
958
+ childIds.add(c.id);
959
+ }
960
+ const seenOptionIds = /* @__PURE__ */ new Set();
961
+ const seenRootIds = /* @__PURE__ */ new Set();
962
+ for (const b of data.optionBindings) {
963
+ if (seenOptionIds.has(b.optionId)) {
964
+ ctx.addIssue({
965
+ code: z.ZodIssueCode.custom,
966
+ message: `duplicate optionId "${b.optionId}" in optionBindings`,
967
+ path: ["optionBindings"]
968
+ });
969
+ }
970
+ seenOptionIds.add(b.optionId);
971
+ if (seenRootIds.has(b.rootLayerId)) {
972
+ ctx.addIssue({
973
+ code: z.ZodIssueCode.custom,
974
+ message: `duplicate rootLayerId "${b.rootLayerId}" in optionBindings`,
975
+ path: ["optionBindings"]
976
+ });
977
+ }
978
+ seenRootIds.add(b.rootLayerId);
979
+ if (!childIds.has(b.rootLayerId)) {
980
+ ctx.addIssue({
981
+ code: z.ZodIssueCode.custom,
982
+ message: `optionBindings rootLayerId "${b.rootLayerId}" does not match any direct child stack`,
983
+ path: ["optionBindings"]
984
+ });
985
+ }
986
+ }
987
+ if (data.optionBindings.length !== data.children.length) {
988
+ ctx.addIssue({
989
+ code: z.ZodIssueCode.custom,
990
+ message: "optionBindings length must equal children length",
991
+ path: ["optionBindings"]
992
+ });
993
+ }
994
+ };
995
+ var SingleChoiceLayerSchema = z.object({
996
+ ...baseLayerShape,
997
+ kind: z.literal("single_choice"),
998
+ fieldKey: FieldKeySchema,
999
+ children: z.lazy(
1000
+ () => z.array(StackLayerSchema).min(2)
1001
+ ),
1002
+ optionBindings: z.array(ChoiceOptionBindingSchema).min(2),
1003
+ branching: ChoiceBranchingSchema,
1004
+ direction: z.enum(["vertical", "horizontal", "grid"]).optional(),
1005
+ gap: z.number().int().min(0).optional(),
1006
+ columns: z.number().int().min(1).max(12).optional(),
1007
+ style: CommonStyleSchema.optional(),
1008
+ styleBreakpoints: CommonStyleBreakpointsSchema
1009
+ });
1010
+ var MultipleChoiceLayerSchema = z.object({
1011
+ ...baseLayerShape,
1012
+ kind: z.literal("multiple_choice"),
1013
+ fieldKey: FieldKeySchema,
1014
+ children: z.lazy(
1015
+ () => z.array(StackLayerSchema).min(2)
1016
+ ),
1017
+ optionBindings: z.array(ChoiceOptionBindingSchema).min(2),
1018
+ minSelections: z.number().int().nonnegative().optional(),
1019
+ maxSelections: z.number().int().positive().optional(),
1020
+ branching: ChoiceBranchingSchema,
1021
+ direction: z.enum(["vertical", "horizontal", "grid"]).optional(),
1022
+ gap: z.number().int().min(0).optional(),
1023
+ columns: z.number().int().min(1).max(12).optional(),
1024
+ style: CommonStyleSchema.optional(),
1025
+ styleBreakpoints: CommonStyleBreakpointsSchema
1026
+ });
1027
+ var validateChoiceChildrenAndBindings = ChoiceChildrenAndBindingsRefinement;
1028
+ var TextInputLayerSchema = z.object({
1029
+ ...baseLayerShape,
1030
+ kind: z.literal("text_input"),
1031
+ fieldKey: FieldKeySchema,
1032
+ placeholder: LocalizedTextSchema.optional(),
1033
+ inputType: TextInputTypeSchema.optional(),
1034
+ required: z.boolean().optional(),
1035
+ minLength: z.number().int().min(0).max(2e3).optional(),
1036
+ maxLength: z.number().int().positive().max(2e3).optional(),
1037
+ classification: FieldClassificationSchema,
1038
+ children: z.lazy(() => z.array(lazyLayer5())).optional(),
1039
+ style: CommonStyleSchema.optional()
1040
+ });
1041
+ var ScaleInputLabelStyleSchema = z.object({
1042
+ fontFamily: z.string().min(1).max(128).optional(),
1043
+ fontSize: z.number().int().min(8).max(96).optional(),
1044
+ fontWeight: z.number().int().min(100).max(900).optional(),
1045
+ color: ThemedColorSchema.optional(),
1046
+ align: z.enum(["left", "center", "right"]).optional(),
1047
+ lineHeight: z.number().min(0.8).max(3).optional(),
1048
+ opacity: z.number().min(0).max(1).optional()
1049
+ }).partial();
1050
+ var ScaleInputLayerSchema = z.object({
1051
+ ...baseLayerShape,
1052
+ kind: z.literal("scale_input"),
1053
+ fieldKey: FieldKeySchema,
1054
+ min: z.number(),
1055
+ max: z.number(),
1056
+ step: z.number().positive().optional(),
1057
+ defaultValue: z.number().optional(),
1058
+ minLabel: LocalizedTextSchema.optional(),
1059
+ maxLabel: LocalizedTextSchema.optional(),
1060
+ labelStyle: ScaleInputLabelStyleSchema.optional(),
1061
+ valueStyle: ScaleInputLabelStyleSchema.optional(),
1062
+ showLabels: z.boolean().optional(),
1063
+ showValue: z.boolean().optional(),
1064
+ trackHeight: z.number().int().min(2).max(32).optional(),
1065
+ trackColor: ThemedColorSchema.optional(),
1066
+ fillColor: ThemedColorSchema.optional(),
1067
+ thumbSize: z.number().int().min(8).max(48).optional(),
1068
+ thumbColor: ThemedColorSchema.optional(),
1069
+ children: z.lazy(() => z.array(lazyLayer5())).optional(),
1070
+ style: CommonStyleSchema.optional()
1071
+ });
1072
+ var CarouselIndicatorsStyleSchema = z.object({
1073
+ width: z.number().int().min(1).max(64).optional(),
1074
+ height: z.number().int().min(1).max(64).optional(),
1075
+ defaultColor: ThemedColorSchema.optional(),
1076
+ defaultOpacity: z.number().min(0).max(1).optional(),
1077
+ activeColor: ThemedColorSchema.optional(),
1078
+ activeOpacity: z.number().min(0).max(1).optional(),
1079
+ activeWidth: z.number().int().min(1).max(64).optional(),
1080
+ activeHeight: z.number().int().min(1).max(64).optional(),
1081
+ border: BorderSchema.optional(),
1082
+ activeBorder: BorderSchema.optional()
1083
+ }).partial();
1084
+ var CarouselPageControlSchema = z.object({
1085
+ position: z.enum(["top", "bottom"]),
1086
+ spacing: z.number().int().min(0).optional(),
1087
+ padding: PaddingSchema.optional(),
1088
+ margin: PaddingSchema.optional(),
1089
+ indicators: CarouselIndicatorsStyleSchema.optional(),
1090
+ border: BorderSchema.optional(),
1091
+ shadow: DropShadowSchema.optional()
1092
+ });
1093
+ var CarouselLayerSchema = z.object({
1094
+ ...baseLayerShape,
1095
+ kind: z.literal("carousel"),
1096
+ slides: z.lazy(() => z.array(StackLayerSchema).min(1)),
1097
+ pageAlignment: z.enum(["top", "center", "bottom"]).optional(),
1098
+ pageSpacing: z.number().int().min(0).optional(),
1099
+ pagePeek: z.number().int().min(0).max(400).optional(),
1100
+ openOn: z.number().int().min(0).optional(),
1101
+ loop: z.boolean().optional(),
1102
+ autoAdvance: z.boolean().optional(),
1103
+ autoAdvanceMs: z.number().int().min(500).max(6e4).optional(),
1104
+ pageControl: CarouselPageControlSchema.optional(),
1105
+ style: CommonStyleSchema.optional(),
1106
+ styleBreakpoints: CommonStyleBreakpointsSchema
1107
+ });
1108
+
1109
+ // src/layers/initLayerSchema.ts
1110
+ layerSchemaStore.schema = z.lazy(
1111
+ () => z.union([
1112
+ StackLayerSchema,
1113
+ TextLayerSchema,
1114
+ HyperlinkLayerSchema,
1115
+ ImageLayerSchema,
1116
+ LottieLayerSchema,
1117
+ VideoLayerSchema,
1118
+ IconLayerSchema,
1119
+ ButtonLayerSchema,
1120
+ BackButtonLayerSchema,
1121
+ ProgressLayerSchema,
1122
+ LoaderLayerSchema,
1123
+ CounterLayerSchema,
1124
+ CheckboxLayerSchema,
1125
+ SingleChoiceLayerSchema,
1126
+ MultipleChoiceLayerSchema,
1127
+ TextInputLayerSchema,
1128
+ ScaleInputLayerSchema,
1129
+ OAuthLoginLayerSchema,
1130
+ OAuthProviderPresetLayerSchema,
1131
+ OAuthProviderCustomLayerSchema,
1132
+ EmailPasswordAuthLayerSchema,
1133
+ EmailPasswordFieldLayerSchema,
1134
+ EmailPasswordSubmitLayerSchema,
1135
+ CarouselLayerSchema
1136
+ ])
1137
+ );
1138
+
1139
+ // src/layers/tree.ts
1140
+ var STYLE_BREAKPOINT_KEYS = ["sm", "md", "lg", "xl", "2xl"];
1141
+ var commonStyleHasAbsolutePosition = (style, breakpoints) => {
1142
+ if (style?.position === "absolute") return true;
1143
+ if (!breakpoints) return false;
1144
+ for (const k of STYLE_BREAKPOINT_KEYS) {
1145
+ if (breakpoints[k]?.position === "absolute") return true;
1146
+ }
1147
+ return false;
1148
+ };
1149
+ var layerHasAbsolutePositionAuthored = (layer) => {
1150
+ switch (layer.kind) {
1151
+ case "stack":
1152
+ return commonStyleHasAbsolutePosition(layer.style, layer.styleBreakpoints) || layer.selectedStyle?.position === "absolute";
1153
+ case "text":
1154
+ case "counter":
1155
+ return commonStyleHasAbsolutePosition(layer.style, layer.styleBreakpoints);
1156
+ case "image":
1157
+ case "lottie":
1158
+ case "video":
1159
+ return commonStyleHasAbsolutePosition(layer.style, layer.styleBreakpoints);
1160
+ case "icon":
1161
+ return commonStyleHasAbsolutePosition(layer.style, layer.styleBreakpoints);
1162
+ case "button":
1163
+ case "back_button":
1164
+ case "hyperlink":
1165
+ return commonStyleHasAbsolutePosition(layer.style, layer.styleBreakpoints);
1166
+ case "progress":
1167
+ case "loader":
1168
+ return commonStyleHasAbsolutePosition(layer.style, void 0);
1169
+ case "text_input":
1170
+ case "scale_input":
1171
+ return commonStyleHasAbsolutePosition(layer.style, void 0);
1172
+ case "oauth_provider":
1173
+ if (layer.variant === "preset") {
1174
+ return commonStyleHasAbsolutePosition(layer.style, layer.styleBreakpoints);
1175
+ }
1176
+ return commonStyleHasAbsolutePosition(layer.style, layer.styleBreakpoints);
1177
+ case "oauth_login":
1178
+ return commonStyleHasAbsolutePosition(layer.style, layer.styleBreakpoints);
1179
+ case "email_password_auth":
1180
+ return commonStyleHasAbsolutePosition(layer.style, layer.styleBreakpoints);
1181
+ case "email_password_field":
1182
+ return commonStyleHasAbsolutePosition(layer.style, layer.styleBreakpoints);
1183
+ case "email_password_submit":
1184
+ return commonStyleHasAbsolutePosition(layer.style, layer.styleBreakpoints);
1185
+ case "carousel":
1186
+ return commonStyleHasAbsolutePosition(layer.style, void 0);
1187
+ case "checkbox":
1188
+ case "single_choice":
1189
+ case "multiple_choice":
1190
+ return commonStyleHasAbsolutePosition(layer.style, layer.styleBreakpoints);
1191
+ default:
1192
+ return false;
1193
+ }
1194
+ };
1195
+
1196
+ // src/layers/layerUnion.ts
1197
+ var isInputLayer = (l) => l.kind === "single_choice" || l.kind === "multiple_choice" || l.kind === "text_input" || l.kind === "scale_input";
1198
+
1199
+ // src/decisions.ts
1200
+ var DecisionNodeIdSchema = z.string().min(1).max(64).regex(/^dec_[a-z0-9_]+$/i, "decision node id must look like dec_<id>");
1201
+ var ExternalSurfaceJumpIdSchema = z.string().min(1).max(64).regex(/^surf_[a-z0-9_]+$/i, "external surface node id must look like surf_<id>");
1202
+ var EXTERNAL_SURFACE_NO_NEXT = "__onb_surface_no_next__";
1203
+ var ExternalSurfaceTerminalTargetSchema = z.literal(EXTERNAL_SURFACE_NO_NEXT);
1204
+ var FlowJumpTargetSchema = ScreenIdSchema.or(DecisionNodeIdSchema).or(ExternalSurfaceJumpIdSchema).or(ExternalSurfaceTerminalTargetSchema).nullable();
1205
+ var DecisionBuiltinNameSchema = z.enum(["locale", "platform"]);
1206
+ var DecisionVariableRefSchema = z.discriminatedUnion("kind", [
1207
+ z.object({ kind: z.literal("builtin"), name: DecisionBuiltinNameSchema }),
1208
+ z.object({ kind: z.literal("sdk"), key: z.string().min(1).max(128) }),
1209
+ z.object({ kind: z.literal("field"), fieldKey: z.string().min(1).max(128) })
1210
+ ]);
1211
+ var DecisionStringPredicateSchema = z.discriminatedUnion("op", [
1212
+ z.object({ op: z.literal("eq"), value: z.string() }),
1213
+ z.object({ op: z.literal("neq"), value: z.string() }),
1214
+ z.object({ op: z.literal("contains"), value: z.string() })
1215
+ ]);
1216
+ var DecisionNumberPredicateSchema = z.discriminatedUnion("op", [
1217
+ z.object({ op: z.literal("eq"), value: z.number() }),
1218
+ z.object({ op: z.literal("neq"), value: z.number() }),
1219
+ z.object({ op: z.literal("lt"), value: z.number() }),
1220
+ z.object({ op: z.literal("lte"), value: z.number() }),
1221
+ z.object({ op: z.literal("gt"), value: z.number() }),
1222
+ z.object({ op: z.literal("gte"), value: z.number() })
1223
+ ]);
1224
+ var DecisionChoicePredicateSchema = z.discriminatedUnion("op", [
1225
+ z.object({ op: z.literal("eq"), optionId: z.string().min(1) }),
1226
+ z.object({ op: z.literal("one_of"), optionIds: z.array(z.string().min(1)).min(1) })
1227
+ ]);
1228
+ var DecisionMultiPredicateSchema = z.discriminatedUnion("op", [
1229
+ z.object({
1230
+ op: z.literal("intersects"),
1231
+ optionIds: z.array(z.string().min(1)).min(1)
1232
+ }),
1233
+ z.object({
1234
+ op: z.literal("contains_all"),
1235
+ optionIds: z.array(z.string().min(1)).min(1)
1236
+ }),
1237
+ z.object({
1238
+ op: z.literal("subset_of"),
1239
+ optionIds: z.array(z.string().min(1)).min(1)
1240
+ })
1241
+ ]);
1242
+ var DecisionBooleanPredicateSchema = z.discriminatedUnion("op", [
1243
+ z.object({ op: z.literal("eq"), value: z.boolean() }),
1244
+ z.object({ op: z.literal("neq"), value: z.boolean() })
1245
+ ]);
1246
+ var DecisionPredicatePayloadSchema = z.discriminatedUnion("type", [
1247
+ z.object({ type: z.literal("string"), pred: DecisionStringPredicateSchema }),
1248
+ z.object({ type: z.literal("number"), pred: DecisionNumberPredicateSchema }),
1249
+ z.object({ type: z.literal("boolean"), pred: DecisionBooleanPredicateSchema }),
1250
+ z.object({ type: z.literal("choice"), pred: DecisionChoicePredicateSchema }),
1251
+ z.object({ type: z.literal("multi"), pred: DecisionMultiPredicateSchema })
1252
+ ]);
1253
+ var DecisionExprSchema = z.lazy(
1254
+ () => z.discriminatedUnion("kind", [
1255
+ z.object({ kind: z.literal("empty") }),
1256
+ z.object({
1257
+ kind: z.literal("group"),
1258
+ op: z.enum(["and", "or"]),
1259
+ children: z.array(DecisionExprSchema).min(1)
1260
+ }),
1261
+ z.object({
1262
+ kind: z.literal("predicate"),
1263
+ variable: DecisionVariableRefSchema,
1264
+ predicate: DecisionPredicatePayloadSchema
1265
+ })
1266
+ ])
1267
+ );
1268
+ var DecisionCaseSchema = z.object({
1269
+ id: z.string().min(1).max(80),
1270
+ /** Display label in the editor (e.g. “Engaged users”). */
1271
+ name: z.string().min(1).max(80).optional(),
1272
+ expression: DecisionExprSchema,
1273
+ next: FlowJumpTargetSchema
1274
+ });
1275
+ var DecisionNodeSchema = z.object({
1276
+ id: DecisionNodeIdSchema,
1277
+ name: z.string().min(1).max(80).optional(),
1278
+ cases: z.array(DecisionCaseSchema).min(1).max(16),
1279
+ elseNext: FlowJumpTargetSchema
1280
+ });
1281
+ var migrateLegacyDecisionNodeInPlace = (node) => {
1282
+ if (!node || typeof node !== "object") return;
1283
+ if (Array.isArray(node.cases)) return;
1284
+ if (!("expression" in node)) return;
1285
+ const id = typeof node.id === "string" ? node.id : "dec_unknown";
1286
+ const expression = node.expression;
1287
+ const onTrue = "onTrue" in node ? node.onTrue ?? null : null;
1288
+ const onFalse = "onFalse" in node ? node.onFalse ?? null : null;
1289
+ delete node.expression;
1290
+ delete node.onTrue;
1291
+ delete node.onFalse;
1292
+ node.cases = [
1293
+ {
1294
+ id: `${id}_case_0`,
1295
+ name: "Group 1",
1296
+ expression,
1297
+ next: onTrue
1298
+ }
1299
+ ];
1300
+ node.elseNext = onFalse;
1301
+ };
1302
+ var collectDecisionSdkKeys = (expr) => {
1303
+ const out = [];
1304
+ const walk = (e) => {
1305
+ if (e.kind === "empty") return;
1306
+ if (e.kind === "predicate") {
1307
+ if (e.variable.kind === "sdk") out.push(e.variable.key);
1308
+ return;
1309
+ }
1310
+ for (const c of e.children) walk(c);
1311
+ };
1312
+ walk(expr);
1313
+ return out;
1314
+ };
1315
+ var collectDecisionFieldKeys = (expr) => {
1316
+ const out = [];
1317
+ const walk = (e) => {
1318
+ if (e.kind === "empty") return;
1319
+ if (e.kind === "predicate") {
1320
+ if (e.variable.kind === "field") out.push(e.variable.fieldKey);
1321
+ return;
1322
+ }
1323
+ for (const c of e.children) walk(c);
1324
+ };
1325
+ walk(expr);
1326
+ return out;
1327
+ };
1328
+ var collectDecisionFieldKeysFromNode = (node) => {
1329
+ const seen = /* @__PURE__ */ new Set();
1330
+ for (const c of node.cases) {
1331
+ for (const k of collectDecisionFieldKeys(c.expression)) seen.add(k);
1332
+ }
1333
+ return [...seen];
1334
+ };
1335
+
1336
+ // src/manifest/migrate.ts
1337
+ var migrateLayerInPlace = (layer) => {
1338
+ if (!layer || typeof layer !== "object") return;
1339
+ const l = layer;
1340
+ if (l.kind === "progress_bar") {
1341
+ l.kind = "progress";
1342
+ }
1343
+ if (l.kind === "icon" && l.family === "sf_symbol") {
1344
+ l.family = "ionicons";
1345
+ l.iconName = "star-outline";
1346
+ }
1347
+ if (l.kind === "button") {
1348
+ const hasChildren = Array.isArray(l.children);
1349
+ const hasLegacyLabel = !!l.label && typeof l.label === "object";
1350
+ if (!hasChildren && hasLegacyLabel) {
1351
+ const id = typeof l.id === "string" ? `${l.id}_text` : "lyr_btn_text";
1352
+ l.children = [
1353
+ {
1354
+ id,
1355
+ kind: "text",
1356
+ text: l.label
1357
+ }
1358
+ ];
1359
+ delete l.label;
1360
+ } else if (!hasChildren) {
1361
+ l.children = [];
1362
+ }
1363
+ }
1364
+ if (l.kind === "hyperlink") {
1365
+ const hasKids = Array.isArray(l.children) && l.children.length > 0;
1366
+ const hasLegacyText = l.text !== void 0 && l.text !== null;
1367
+ if (!hasKids && hasLegacyText) {
1368
+ const baseId = typeof l.id === "string" ? `${l.id}_lnktxt` : "lyr_hyperlink_lnktxt";
1369
+ const row = {
1370
+ id: String(baseId).slice(0, 64),
1371
+ kind: "text",
1372
+ text: l.text
1373
+ };
1374
+ if (l.style !== void 0) row.style = l.style;
1375
+ if (l.styleBreakpoints !== void 0) row.styleBreakpoints = l.styleBreakpoints;
1376
+ l.children = [row];
1377
+ delete l.text;
1378
+ delete l.style;
1379
+ delete l.styleBreakpoints;
1380
+ } else if (!Array.isArray(l.children)) {
1381
+ l.children = [];
1382
+ }
1383
+ }
1384
+ if (l.kind === "stack" && Array.isArray(l.children)) {
1385
+ for (const c of l.children) migrateLayerInPlace(c);
1386
+ } else if (l.kind === "carousel" && Array.isArray(l.slides)) {
1387
+ for (const s of l.slides) migrateLayerInPlace(s);
1388
+ } else if (l.kind === "button" && Array.isArray(l.children)) {
1389
+ for (const c of l.children) migrateLayerInPlace(c);
1390
+ } else if (l.kind === "back_button" && Array.isArray(l.children)) {
1391
+ for (const c of l.children) migrateLayerInPlace(c);
1392
+ } else if (l.kind === "hyperlink" && Array.isArray(l.children)) {
1393
+ for (const c of l.children) migrateLayerInPlace(c);
1394
+ } else if (l.kind === "oauth_login" && Array.isArray(l.children)) {
1395
+ for (const c of l.children) migrateLayerInPlace(c);
1396
+ } else if (l.kind === "oauth_provider" && l.variant === "custom" && Array.isArray(l.children)) {
1397
+ for (const c of l.children) migrateLayerInPlace(c);
1398
+ } else if (l.kind === "email_password_auth" && Array.isArray(l.children)) {
1399
+ for (const c of l.children) migrateLayerInPlace(c);
1400
+ } else if (l.kind === "email_password_field" && Array.isArray(l.children)) {
1401
+ for (const c of l.children) migrateLayerInPlace(c);
1402
+ } else if (l.kind === "email_password_submit" && Array.isArray(l.children)) {
1403
+ for (const c of l.children) migrateLayerInPlace(c);
1404
+ }
1405
+ };
1406
+ var migrateScreenInPlace = (screen) => {
1407
+ if (!screen || typeof screen !== "object") return;
1408
+ const s = screen;
1409
+ if (s.regions) {
1410
+ if (s.regions.header) migrateLayerInPlace(s.regions.header);
1411
+ if (s.regions.body) migrateLayerInPlace(s.regions.body);
1412
+ if (s.regions.footer) migrateLayerInPlace(s.regions.footer);
1413
+ }
1414
+ if (s.animations === void 0) {
1415
+ delete s.animations;
1416
+ }
1417
+ };
1418
+ var migrateManifestInPlace = (data) => {
1419
+ if (!data || typeof data !== "object") return data;
1420
+ const d = data;
1421
+ if (Array.isArray(d.screens)) {
1422
+ for (const s of d.screens) migrateScreenInPlace(s);
1423
+ }
1424
+ if (!Array.isArray(d.decisionNodes)) d.decisionNodes = [];
1425
+ if (Array.isArray(d.decisionNodes)) {
1426
+ for (const node of d.decisionNodes) {
1427
+ if (node && typeof node === "object") {
1428
+ migrateLegacyDecisionNodeInPlace(node);
1429
+ }
1430
+ }
1431
+ }
1432
+ if (!Array.isArray(d.externalSurfaceNodes)) d.externalSurfaceNodes = [];
1433
+ if (!Array.isArray(d.sdkAttributeKeys)) d.sdkAttributeKeys = [];
1434
+ if (d.schemaVersion === 6) d.schemaVersion = MANIFEST_SCHEMA_VERSION;
1435
+ if (d.schemaVersion === 5) d.schemaVersion = MANIFEST_SCHEMA_VERSION;
1436
+ if (d.schemaVersion === 4) d.schemaVersion = MANIFEST_SCHEMA_VERSION;
1437
+ return data;
1438
+ };
1439
+ var migrateLegacyManifest = (raw) => {
1440
+ if (!raw || typeof raw !== "object") return raw;
1441
+ const clone = JSON.parse(JSON.stringify(raw));
1442
+ return migrateManifestInPlace(clone);
1443
+ };
1444
+ var ScreenBackgroundFitSchema = z.enum(["cover", "contain", "fill"]);
1445
+ var ScreenBackgroundScrimSchema = z.object({
1446
+ color: ThemedColorSchema.optional(),
1447
+ opacity: z.number().min(0).max(1).optional()
1448
+ }).partial();
1449
+ var screenBackgroundMediaShape = {
1450
+ media: MediaReferenceSchema.optional(),
1451
+ fit: ScreenBackgroundFitSchema.optional(),
1452
+ opacity: z.number().min(0).max(1).optional(),
1453
+ scrim: ScreenBackgroundScrimSchema.optional()
1454
+ };
1455
+ var ScreenBackgroundColorFillSchema = z.object({
1456
+ kind: z.literal("color"),
1457
+ color: ThemedColorSchema.optional(),
1458
+ opacity: z.number().min(0).max(1).optional()
1459
+ });
1460
+ var ScreenBackgroundImageFillSchema = z.object({
1461
+ kind: z.literal("image"),
1462
+ ...screenBackgroundMediaShape
1463
+ });
1464
+ var ScreenBackgroundVideoFillSchema = z.object({
1465
+ kind: z.literal("video"),
1466
+ ...screenBackgroundMediaShape,
1467
+ loop: z.boolean().optional(),
1468
+ autoPlay: z.boolean().optional(),
1469
+ triggerLayerId: z.string().min(1).optional(),
1470
+ onComplete: LoaderOnCompleteSchema.optional(),
1471
+ audioEnabled: z.boolean().optional()
1472
+ });
1473
+ var ScreenBackgroundFillSchema = z.discriminatedUnion("kind", [
1474
+ ScreenBackgroundColorFillSchema,
1475
+ ScreenBackgroundImageFillSchema,
1476
+ ScreenBackgroundVideoFillSchema
1477
+ ]);
1478
+ var ScreenBackgroundFillPatchSchema = z.object({
1479
+ color: ThemedColorSchema.optional(),
1480
+ fit: ScreenBackgroundFitSchema.optional(),
1481
+ opacity: z.number().min(0).max(1).optional(),
1482
+ scrim: ScreenBackgroundScrimSchema.optional(),
1483
+ loop: z.boolean().optional(),
1484
+ autoPlay: z.boolean().optional(),
1485
+ triggerLayerId: z.string().min(1).optional(),
1486
+ onComplete: LoaderOnCompleteSchema.optional(),
1487
+ audioEnabled: z.boolean().optional()
1488
+ }).partial();
1489
+ var ScreenContainerBreakpointPatchSchema = z.object({
1490
+ padding: PaddingSchema.optional(),
1491
+ margin: PaddingSchema.optional(),
1492
+ insetSafeArea: z.boolean().optional(),
1493
+ backgroundFillPatch: ScreenBackgroundFillPatchSchema.optional()
1494
+ }).partial();
1495
+ var ScreenContainerStyleBreakpointsSchema = z.object({
1496
+ sm: ScreenContainerBreakpointPatchSchema.optional(),
1497
+ md: ScreenContainerBreakpointPatchSchema.optional(),
1498
+ lg: ScreenContainerBreakpointPatchSchema.optional(),
1499
+ xl: ScreenContainerBreakpointPatchSchema.optional(),
1500
+ "2xl": ScreenContainerBreakpointPatchSchema.optional()
1501
+ }).partial().optional();
1502
+ var ANIMATABLE_PROPERTIES = [
1503
+ "opacity",
1504
+ "translateX",
1505
+ "translateY",
1506
+ "scale"
1507
+ ];
1508
+ var AnimatablePropertySchema = z.enum(ANIMATABLE_PROPERTIES);
1509
+ var EASING_TOKENS = [
1510
+ "linear",
1511
+ "ease-in",
1512
+ "ease-out",
1513
+ "ease-in-out",
1514
+ "standard",
1515
+ "emphasized"
1516
+ ];
1517
+ var EasingTokenSchema = z.enum(EASING_TOKENS);
1518
+ var KeyframeSchema = z.object({
1519
+ t: z.number().min(0).max(1),
1520
+ value: z.number(),
1521
+ /** Easing applied from this keyframe to the next; defaults to linear. */
1522
+ easing: EasingTokenSchema.optional()
1523
+ }).strict();
1524
+ var KeyframeTrackSchema = z.object({
1525
+ property: AnimatablePropertySchema,
1526
+ keyframes: z.array(KeyframeSchema).min(2)
1527
+ }).strict().superRefine((track, ctx) => {
1528
+ let last = -Infinity;
1529
+ for (const k of track.keyframes) {
1530
+ if (k.t < last) {
1531
+ ctx.addIssue({
1532
+ code: z.ZodIssueCode.custom,
1533
+ message: `keyframe times must be monotonically non-decreasing on track "${track.property}"`
1534
+ });
1535
+ return;
1536
+ }
1537
+ last = k.t;
1538
+ }
1539
+ if (track.keyframes[0].t !== 0) {
1540
+ ctx.addIssue({
1541
+ code: z.ZodIssueCode.custom,
1542
+ message: `track "${track.property}" first keyframe must start at t=0`
1543
+ });
1544
+ }
1545
+ if (track.keyframes[track.keyframes.length - 1].t !== 1) {
1546
+ ctx.addIssue({
1547
+ code: z.ZodIssueCode.custom,
1548
+ message: `track "${track.property}" last keyframe must end at t=1`
1549
+ });
1550
+ }
1551
+ });
1552
+ var ANIMATION_TRIGGERS = ["mount", "stagger", "unmount"];
1553
+ var AnimationTriggerSchema = z.enum(ANIMATION_TRIGGERS);
1554
+ var AnimationClipSchema = z.object({
1555
+ id: z.string().min(1).max(64),
1556
+ targetLayerId: LayerIdSchema,
1557
+ trigger: AnimationTriggerSchema,
1558
+ /** Position in the screen's stagger order. Required when trigger is `stagger`. */
1559
+ staggerIndex: z.number().int().min(0).max(64).optional(),
1560
+ /** Total clip duration in milliseconds (renderer scales 0..1 keyframes by this). */
1561
+ durationMs: z.number().int().min(0).max(36e5),
1562
+ /** Pre-roll delay before the clip begins, in ms. Stagger adds on top of this. */
1563
+ delayMs: z.number().int().min(0).max(36e5).optional(),
1564
+ tracks: z.array(KeyframeTrackSchema).min(1)
1565
+ }).strict().superRefine((clip, ctx) => {
1566
+ if (clip.trigger === "unmount" && clip.staggerIndex !== void 0) {
1567
+ ctx.addIssue({
1568
+ code: z.ZodIssueCode.custom,
1569
+ message: `clip "${clip.id}" with trigger "unmount" must not set staggerIndex`,
1570
+ path: ["staggerIndex"]
1571
+ });
1572
+ }
1573
+ if (clip.trigger === "stagger" && clip.staggerIndex === void 0) {
1574
+ ctx.addIssue({
1575
+ code: z.ZodIssueCode.custom,
1576
+ message: `clip "${clip.id}" with trigger "stagger" must define staggerIndex`,
1577
+ path: ["staggerIndex"]
1578
+ });
1579
+ }
1580
+ const seenProps = /* @__PURE__ */ new Set();
1581
+ for (const track of clip.tracks) {
1582
+ if (seenProps.has(track.property)) {
1583
+ ctx.addIssue({
1584
+ code: z.ZodIssueCode.custom,
1585
+ message: `clip "${clip.id}" has duplicate track for property "${track.property}"`
1586
+ });
1587
+ }
1588
+ seenProps.add(track.property);
1589
+ }
1590
+ });
1591
+ var ScreenStaggerSchema = z.object({
1592
+ /** Per-index delay multiplier in ms. */
1593
+ stepMs: z.number().int().min(0).max(2e3)
1594
+ }).strict();
1595
+
1596
+ // src/screens.ts
1597
+ var ScreenNextSchema = z.object({
1598
+ default: FlowJumpTargetSchema
1599
+ });
1600
+ var ScreenRegionsSchema = z.object({
1601
+ header: StackLayerSchema.optional(),
1602
+ body: StackLayerSchema,
1603
+ footer: StackLayerSchema.optional()
1604
+ });
1605
+ var ScreenContainerStyleSchema = z.object({
1606
+ padding: PaddingSchema.optional(),
1607
+ margin: PaddingSchema.optional(),
1608
+ /** When true, runtimes add device safe-area insets to shell padding (in addition to manual padding). */
1609
+ insetSafeArea: z.boolean().optional(),
1610
+ backgroundFill: ScreenBackgroundFillSchema.optional()
1611
+ }).partial();
1612
+ var ScreenSchema = z.object({
1613
+ id: ScreenIdSchema,
1614
+ name: z.string().min(1).max(80),
1615
+ regions: ScreenRegionsSchema,
1616
+ next: ScreenNextSchema,
1617
+ /** Ordered animation clips bound to layers on this screen. */
1618
+ animations: z.array(AnimationClipSchema).optional(),
1619
+ /** Defaults for clips with `trigger: stagger`. */
1620
+ stagger: ScreenStaggerSchema.optional(),
1621
+ /** Chrome on the outer screen container (wraps all regions). */
1622
+ containerStyle: ScreenContainerStyleSchema.optional(),
1623
+ containerStyleBreakpoints: ScreenContainerStyleBreakpointsSchema
1624
+ });
1625
+ var walkScreenLayersWithLayoutContext = (screen, fn) => {
1626
+ const visit = (l, ctx) => {
1627
+ fn(l, ctx);
1628
+ const childCtx = (opts = {}) => ({
1629
+ region: ctx.region,
1630
+ isRegionRoot: false,
1631
+ insideChoiceOption: opts.insideChoiceOption ?? ctx.insideChoiceOption,
1632
+ parentKind: l.kind
1633
+ });
1634
+ if (l.kind === "stack") {
1635
+ for (const c of l.children) visit(c, childCtx());
1636
+ } else if (l.kind === "carousel") {
1637
+ for (const s of l.slides) visit(s, childCtx());
1638
+ } else if (l.kind === "button" || l.kind === "back_button") {
1639
+ for (const c of l.children) visit(c, childCtx());
1640
+ } else if (l.kind === "hyperlink") {
1641
+ for (const c of l.children) visit(c, childCtx());
1642
+ } else if (l.kind === "single_choice" || l.kind === "multiple_choice") {
1643
+ for (const c of l.children) {
1644
+ visit(c, childCtx({ insideChoiceOption: true }));
1645
+ }
1646
+ } else if (l.kind === "text_input" || l.kind === "scale_input") {
1647
+ for (const c of l.children ?? []) visit(c, childCtx());
1648
+ } else if (l.kind === "oauth_login") {
1649
+ for (const c of l.children) visit(c, childCtx());
1650
+ } else if (l.kind === "oauth_provider" && l.variant === "custom") {
1651
+ for (const c of l.children) visit(c, childCtx());
1652
+ } else if (l.kind === "email_password_auth") {
1653
+ for (const c of l.children) visit(c, childCtx());
1654
+ } else if (l.kind === "email_password_field") {
1655
+ for (const c of l.children ?? []) visit(c, childCtx());
1656
+ } else if (l.kind === "email_password_submit") {
1657
+ for (const c of l.children) visit(c, childCtx());
1658
+ }
1659
+ };
1660
+ const regionCtx = (region) => ({
1661
+ region,
1662
+ isRegionRoot: true,
1663
+ insideChoiceOption: false,
1664
+ parentKind: null
1665
+ });
1666
+ if (screen.regions.header) visit(screen.regions.header, regionCtx("header"));
1667
+ visit(screen.regions.body, regionCtx("body"));
1668
+ if (screen.regions.footer) visit(screen.regions.footer, regionCtx("footer"));
1669
+ };
1670
+ var walkScreenLayers = (screen, fn) => {
1671
+ const visit = (l) => {
1672
+ fn(l);
1673
+ if (l.kind === "stack") l.children.forEach(visit);
1674
+ else if (l.kind === "carousel") l.slides.forEach(visit);
1675
+ else if (l.kind === "button") l.children.forEach(visit);
1676
+ else if (l.kind === "back_button") l.children.forEach(visit);
1677
+ else if (l.kind === "hyperlink") l.children.forEach(visit);
1678
+ else if (l.kind === "single_choice" || l.kind === "multiple_choice") {
1679
+ l.children.forEach(visit);
1680
+ } else if (l.kind === "text_input" || l.kind === "scale_input") {
1681
+ l.children?.forEach(visit);
1682
+ } else if (l.kind === "oauth_login") {
1683
+ l.children.forEach(visit);
1684
+ } else if (l.kind === "oauth_provider" && l.variant === "custom") {
1685
+ l.children.forEach(visit);
1686
+ } else if (l.kind === "email_password_auth") {
1687
+ l.children.forEach(visit);
1688
+ } else if (l.kind === "email_password_field") {
1689
+ l.children?.forEach(visit);
1690
+ } else if (l.kind === "email_password_submit") {
1691
+ l.children.forEach(visit);
1692
+ }
1693
+ };
1694
+ if (screen.regions.header) visit(screen.regions.header);
1695
+ visit(screen.regions.body);
1696
+ if (screen.regions.footer) visit(screen.regions.footer);
1697
+ };
1698
+ var ExternalSurfaceNodeIdSchema = z.string().min(1).max(64).regex(/^surf_[a-z0-9_]+$/i, "external surface node id must look like surf_<id>");
1699
+ var NORMALIZED_SURFACE_OUTCOMES = [
1700
+ "purchase_completed",
1701
+ "purchase_cancelled",
1702
+ "dismissed",
1703
+ "failed",
1704
+ "restore_completed"
1705
+ ];
1706
+ z.enum(NORMALIZED_SURFACE_OUTCOMES);
1707
+ z.enum(["unspecified", "revenuecat"]);
1708
+ var UnspecifiedExternalSurfaceConfigSchema = z.object({
1709
+ provider: z.literal("unspecified")
1710
+ });
1711
+ var RevenueCatSurfacePresentationSchema = z.enum(["paywall", "paywall_if_needed"]);
1712
+ var RevenueCatSurfaceConfigSchema = z.object({
1713
+ provider: z.literal("revenuecat"),
1714
+ offeringId: z.string().min(1).max(128).optional(),
1715
+ placementId: z.string().min(1).max(128).optional(),
1716
+ presentation: RevenueCatSurfacePresentationSchema.optional()
1717
+ });
1718
+ var ExternalSurfaceConfigSchema = z.discriminatedUnion("provider", [
1719
+ UnspecifiedExternalSurfaceConfigSchema,
1720
+ RevenueCatSurfaceConfigSchema
1721
+ ]);
1722
+ var ExternalSurfaceOutcomesMapSchema = z.object({
1723
+ purchase_completed: FlowJumpTargetSchema.optional(),
1724
+ purchase_cancelled: FlowJumpTargetSchema.optional(),
1725
+ dismissed: FlowJumpTargetSchema.optional(),
1726
+ failed: FlowJumpTargetSchema.optional(),
1727
+ restore_completed: FlowJumpTargetSchema.optional()
1728
+ }).strict();
1729
+ var ExternalSurfaceNodeSchema = z.object({
1730
+ id: ExternalSurfaceNodeIdSchema,
1731
+ name: z.string().min(1).max(80).optional(),
1732
+ config: ExternalSurfaceConfigSchema,
1733
+ /** Per-outcome jump targets. Outcomes not listed here fall through to `fallback`. */
1734
+ outcomes: ExternalSurfaceOutcomesMapSchema,
1735
+ /** Required: used for any outcome not in `outcomes` (e.g. provider quirks, unmapped events). */
1736
+ fallback: FlowJumpTargetSchema
1737
+ });
1738
+
1739
+ // src/manifest/flowManifestObjectBaseSchema.ts
1740
+ var FlowManifestObjectBaseSchema = z.object({
1741
+ flowId: z.string().uuid(),
1742
+ /** Manifest schema version — see {@link MANIFEST_SCHEMA_VERSION}. */
1743
+ schemaVersion: z.literal(MANIFEST_SCHEMA_VERSION).optional(),
1744
+ version: z.number().int().positive(),
1745
+ defaultLocale: LocaleCode,
1746
+ locales: z.array(LocaleCode),
1747
+ /** When null, the draft has no wired entry target (builder connects the canvas entry node). */
1748
+ entryScreenId: z.union([z.string().min(1), z.null()]),
1749
+ screens: z.array(ScreenSchema),
1750
+ decisionNodes: z.union([z.array(DecisionNodeSchema), z.undefined()]).transform((x) => x ?? []),
1751
+ externalSurfaceNodes: z.union([z.array(ExternalSurfaceNodeSchema), z.undefined()]).transform((x) => x ?? []),
1752
+ sdkAttributeKeys: z.union([z.array(z.string().min(1).max(128)), z.undefined()]).transform((x) => x ?? []),
1753
+ theme: ThemeSchema.optional(),
1754
+ builderMeta: BuilderMetaSchema
1755
+ });
1756
+
1757
+ // src/sdkAttributes.ts
1758
+ var RESERVED_RC_SDK_KEYS = [
1759
+ /** Last RC event observed by the SDK (e.g. `purchase_completed`, `purchase_cancelled`). */
1760
+ "onb_rc_last_event",
1761
+ /** Product identifier from the most recent successful purchase. */
1762
+ "onb_rc_last_product_id",
1763
+ /** Period type (`normal`, `intro`, `trial`) from the most recent purchase. */
1764
+ "onb_rc_last_period_type",
1765
+ /** RevenueCat offering id surfaced by the most recent paywall presentation. */
1766
+ "onb_rc_last_offering_id"
1767
+ ];
1768
+ var RESERVED_SDK_KEYS_SET = new Set(RESERVED_RC_SDK_KEYS);
1769
+ var isReservedSdkKey = (key) => RESERVED_SDK_KEYS_SET.has(key);
1770
+
1771
+ // src/manifest/refineManifestGraph.ts
1772
+ var buildManifestJumpTargets = (manifest) => {
1773
+ const screenIds = new Set(manifest.screens.map((s) => s.id));
1774
+ const decisionIds = new Set(manifest.decisionNodes.map((d) => d.id));
1775
+ const surfaceIds = new Set(manifest.externalSurfaceNodes.map((s) => s.id));
1776
+ return /* @__PURE__ */ new Set([
1777
+ ...screenIds,
1778
+ ...decisionIds,
1779
+ ...surfaceIds,
1780
+ EXTERNAL_SURFACE_NO_NEXT
1781
+ ]);
1782
+ };
1783
+ var refineManifestGraph = (manifest, ctx, jumpTargets) => {
1784
+ const screenIds = /* @__PURE__ */ new Set();
1785
+ for (const s of manifest.screens) {
1786
+ if (screenIds.has(s.id)) {
1787
+ ctx.addIssue({
1788
+ code: z.ZodIssueCode.custom,
1789
+ message: `duplicate screen id "${s.id}"`,
1790
+ path: ["screens"]
1791
+ });
1792
+ }
1793
+ screenIds.add(s.id);
1794
+ }
1795
+ const decisionIds = new Set(manifest.decisionNodes.map((d) => d.id));
1796
+ const surfaceIds = new Set(manifest.externalSurfaceNodes.map((s) => s.id));
1797
+ if (manifest.entryScreenId != null && !jumpTargets.has(manifest.entryScreenId)) {
1798
+ ctx.addIssue({
1799
+ code: z.ZodIssueCode.custom,
1800
+ message: `entryScreenId "${manifest.entryScreenId}" not found in screens, decisionNodes, or externalSurfaceNodes`,
1801
+ path: ["entryScreenId"]
1802
+ });
1803
+ }
1804
+ const seenDecisionId = /* @__PURE__ */ new Set();
1805
+ const sdkAllow = new Set(manifest.sdkAttributeKeys);
1806
+ manifest.decisionNodes.forEach((dn, di) => {
1807
+ if (seenDecisionId.has(dn.id)) {
1808
+ ctx.addIssue({
1809
+ code: z.ZodIssueCode.custom,
1810
+ message: `duplicate decision node id "${dn.id}"`,
1811
+ path: ["decisionNodes", di]
1812
+ });
1813
+ }
1814
+ seenDecisionId.add(dn.id);
1815
+ if (screenIds.has(dn.id)) {
1816
+ ctx.addIssue({
1817
+ code: z.ZodIssueCode.custom,
1818
+ message: `decision node id "${dn.id}" collides with a screen id`,
1819
+ path: ["decisionNodes", di]
1820
+ });
1821
+ }
1822
+ if (surfaceIds.has(dn.id)) {
1823
+ ctx.addIssue({
1824
+ code: z.ZodIssueCode.custom,
1825
+ message: `decision node id "${dn.id}" collides with an external surface id`,
1826
+ path: ["decisionNodes", di]
1827
+ });
1828
+ }
1829
+ dn.cases.forEach((c, ci) => {
1830
+ if (c.next != null && !jumpTargets.has(c.next)) {
1831
+ ctx.addIssue({
1832
+ code: z.ZodIssueCode.custom,
1833
+ message: `decision "${dn.id}" case "${c.id}" next "${c.next}" not found`,
1834
+ path: ["decisionNodes", di, "cases", ci, "next"]
1835
+ });
1836
+ }
1837
+ for (const sk of collectDecisionSdkKeys(c.expression)) {
1838
+ if (isReservedSdkKey(sk)) continue;
1839
+ if (!sdkAllow.has(sk)) {
1840
+ ctx.addIssue({
1841
+ code: z.ZodIssueCode.custom,
1842
+ message: `decision "${dn.id}" case "${c.id}" references sdk key "${sk}" not in sdkAttributeKeys`,
1843
+ path: ["decisionNodes", di, "cases", ci, "expression"]
1844
+ });
1845
+ }
1846
+ }
1847
+ });
1848
+ if (dn.elseNext != null && !jumpTargets.has(dn.elseNext)) {
1849
+ ctx.addIssue({
1850
+ code: z.ZodIssueCode.custom,
1851
+ message: `decision "${dn.id}" elseNext "${dn.elseNext}" not found`,
1852
+ path: ["decisionNodes", di, "elseNext"]
1853
+ });
1854
+ }
1855
+ });
1856
+ const seenSurfaceId = /* @__PURE__ */ new Set();
1857
+ manifest.externalSurfaceNodes.forEach((sn, si) => {
1858
+ if (seenSurfaceId.has(sn.id)) {
1859
+ ctx.addIssue({
1860
+ code: z.ZodIssueCode.custom,
1861
+ message: `duplicate external surface id "${sn.id}"`,
1862
+ path: ["externalSurfaceNodes", si]
1863
+ });
1864
+ }
1865
+ seenSurfaceId.add(sn.id);
1866
+ if (screenIds.has(sn.id)) {
1867
+ ctx.addIssue({
1868
+ code: z.ZodIssueCode.custom,
1869
+ message: `external surface id "${sn.id}" collides with a screen id`,
1870
+ path: ["externalSurfaceNodes", si]
1871
+ });
1872
+ }
1873
+ if (decisionIds.has(sn.id)) {
1874
+ ctx.addIssue({
1875
+ code: z.ZodIssueCode.custom,
1876
+ message: `external surface id "${sn.id}" collides with a decision node id`,
1877
+ path: ["externalSurfaceNodes", si]
1878
+ });
1879
+ }
1880
+ for (const [outcome, target] of Object.entries(sn.outcomes)) {
1881
+ if (target != null && !jumpTargets.has(target)) {
1882
+ ctx.addIssue({
1883
+ code: z.ZodIssueCode.custom,
1884
+ message: `external surface "${sn.id}" outcome "${outcome}" target "${target}" not found`,
1885
+ path: ["externalSurfaceNodes", si, "outcomes", outcome]
1886
+ });
1887
+ }
1888
+ }
1889
+ if (sn.fallback != null && !jumpTargets.has(sn.fallback)) {
1890
+ ctx.addIssue({
1891
+ code: z.ZodIssueCode.custom,
1892
+ message: `external surface "${sn.id}" fallback "${sn.fallback}" not found`,
1893
+ path: ["externalSurfaceNodes", si, "fallback"]
1894
+ });
1895
+ }
1896
+ });
1897
+ return { screenIds, decisionIds, surfaceIds };
1898
+ };
1899
+ var refineManifestScreens = (manifest, ctx, jumpTargets, screenIds, allFieldKeys) => {
1900
+ const layerIds = /* @__PURE__ */ new Set();
1901
+ manifest.screens.forEach((screen, screenIdx) => {
1902
+ let inputCount = 0;
1903
+ const layerIdsForScreen = /* @__PURE__ */ new Set();
1904
+ walkScreenLayers(screen, (l) => {
1905
+ layerIdsForScreen.add(l.id);
1906
+ });
1907
+ walkScreenLayers(screen, (l) => {
1908
+ if (layerIds.has(l.id)) {
1909
+ ctx.addIssue({
1910
+ code: z.ZodIssueCode.custom,
1911
+ message: `duplicate layer id "${l.id}"`,
1912
+ path: ["screens", screenIdx, "regions"]
1913
+ });
1914
+ }
1915
+ layerIds.add(l.id);
1916
+ if (isInputLayer(l)) {
1917
+ inputCount += 1;
1918
+ if (allFieldKeys.has(l.fieldKey)) {
1919
+ ctx.addIssue({
1920
+ code: z.ZodIssueCode.custom,
1921
+ message: `duplicate fieldKey "${l.fieldKey}" across screens or on the same screen`,
1922
+ path: ["screens", screenIdx]
1923
+ });
1924
+ }
1925
+ allFieldKeys.set(l.fieldKey, screen.id);
1926
+ }
1927
+ if (l.kind === "checkbox") {
1928
+ if (allFieldKeys.has(l.fieldKey)) {
1929
+ ctx.addIssue({
1930
+ code: z.ZodIssueCode.custom,
1931
+ message: `duplicate fieldKey "${l.fieldKey}" across screens or on the same screen`,
1932
+ path: ["screens", screenIdx]
1933
+ });
1934
+ }
1935
+ allFieldKeys.set(l.fieldKey, screen.id);
1936
+ }
1937
+ if (l.kind === "button" && l.action.kind === "request_os_permission") {
1938
+ const fk = permissionCaptureFieldKey(l.action.permissionKey);
1939
+ if (!allFieldKeys.has(fk)) allFieldKeys.set(fk, screen.id);
1940
+ }
1941
+ });
1942
+ if (inputCount > 1) {
1943
+ ctx.addIssue({
1944
+ code: z.ZodIssueCode.custom,
1945
+ message: `screen "${screen.id}" has ${inputCount} input layers (max 1 allowed)`,
1946
+ path: ["screens", screenIdx, "regions"]
1947
+ });
1948
+ }
1949
+ walkScreenLayersWithLayoutContext(screen, (l, layoutCtx) => {
1950
+ if (!layerHasAbsolutePositionAuthored(l)) return;
1951
+ if (layoutCtx.isRegionRoot) {
1952
+ ctx.addIssue({
1953
+ code: z.ZodIssueCode.custom,
1954
+ message: `layer "${l.id}" cannot use absolute positioning on a screen region root`,
1955
+ path: ["screens", screenIdx, "regions"]
1956
+ });
1957
+ }
1958
+ if (layoutCtx.insideChoiceOption) {
1959
+ ctx.addIssue({
1960
+ code: z.ZodIssueCode.custom,
1961
+ message: `layer "${l.id}" cannot use absolute positioning inside a choice option`,
1962
+ path: ["screens", screenIdx, "regions"]
1963
+ });
1964
+ }
1965
+ });
1966
+ walkScreenLayersWithLayoutContext(screen, (l, layoutCtx) => {
1967
+ if (l.kind === "oauth_provider" && layoutCtx.parentKind !== "oauth_login") {
1968
+ ctx.addIssue({
1969
+ code: z.ZodIssueCode.custom,
1970
+ message: `OAuth button "${l.id}" must be nested under an OAuth login layer`,
1971
+ path: ["screens", screenIdx, "regions"]
1972
+ });
1973
+ }
1974
+ if ((l.kind === "email_password_field" || l.kind === "email_password_submit") && layoutCtx.parentKind !== "email_password_auth") {
1975
+ ctx.addIssue({
1976
+ code: z.ZodIssueCode.custom,
1977
+ message: `Layer "${l.id}" (${l.kind}) must be nested under an Email / password login layer`,
1978
+ path: ["screens", screenIdx, "regions"]
1979
+ });
1980
+ }
1981
+ });
1982
+ const nextDefault = screen.next.default;
1983
+ if (nextDefault && !jumpTargets.has(nextDefault)) {
1984
+ ctx.addIssue({
1985
+ code: z.ZodIssueCode.custom,
1986
+ message: `screen "${screen.id}" next.default "${nextDefault}" not found`,
1987
+ path: ["screens", screenIdx, "next", "default"]
1988
+ });
1989
+ }
1990
+ walkScreenLayers(screen, (l) => {
1991
+ if (l.kind === "single_choice" || l.kind === "multiple_choice") {
1992
+ validateChoiceChildrenAndBindings(
1993
+ { children: l.children, optionBindings: l.optionBindings },
1994
+ ctx
1995
+ );
1996
+ const knownOptionIds = new Set(l.optionBindings.map((b) => b.optionId));
1997
+ for (const cond of l.branching.conditions) {
1998
+ if (!screenIds.has(cond.goTo)) {
1999
+ ctx.addIssue({
2000
+ code: z.ZodIssueCode.custom,
2001
+ message: `screen "${screen.id}" branch condition "${cond.choiceId}" -> "${cond.goTo}" not found`,
2002
+ path: ["screens", screenIdx]
2003
+ });
2004
+ }
2005
+ if (!knownOptionIds.has(cond.choiceId)) {
2006
+ ctx.addIssue({
2007
+ code: z.ZodIssueCode.custom,
2008
+ message: `screen "${screen.id}" branch condition references unknown choice "${cond.choiceId}"`,
2009
+ path: ["screens", screenIdx]
2010
+ });
2011
+ }
2012
+ }
2013
+ }
2014
+ if (l.kind === "button" && l.action.kind === "go_to_step") {
2015
+ if (!screenIds.has(l.action.screenId)) {
2016
+ ctx.addIssue({
2017
+ code: z.ZodIssueCode.custom,
2018
+ message: `screen "${screen.id}" button action go_to_step "${l.action.screenId}" not found`,
2019
+ path: ["screens", screenIdx]
2020
+ });
2021
+ }
2022
+ }
2023
+ if (l.kind === "button" && l.action.kind === "go_back_one_screen" && manifest.entryScreenId != null && screen.id === manifest.entryScreenId) {
2024
+ ctx.addIssue({
2025
+ code: z.ZodIssueCode.custom,
2026
+ message: `screen "${screen.id}" is the flow entry screen; buttons cannot use go_back_one_screen`,
2027
+ path: ["screens", screenIdx]
2028
+ });
2029
+ }
2030
+ if (l.kind === "button" && l.action.kind === "request_os_permission") {
2031
+ for (const [label, sid] of [
2032
+ ["granted", l.action.outcomes.granted],
2033
+ ["denied", l.action.outcomes.denied],
2034
+ ["blocked", l.action.outcomes.blocked]
2035
+ ]) {
2036
+ if (sid === OS_PERMISSION_OUTCOME_END) ; else if (sid === OS_PERMISSION_OUTCOME_CONTINUE) {
2037
+ const def = screen.next.default;
2038
+ if (def != null && !jumpTargets.has(def)) {
2039
+ ctx.addIssue({
2040
+ code: z.ZodIssueCode.custom,
2041
+ message: `screen "${screen.id}" request_os_permission outcomes.${label} uses default next (continue) but screen.next.default "${def}" is not a valid target`,
2042
+ path: ["screens", screenIdx]
2043
+ });
2044
+ }
2045
+ } else if (!jumpTargets.has(sid)) {
2046
+ ctx.addIssue({
2047
+ code: z.ZodIssueCode.custom,
2048
+ message: `screen "${screen.id}" request_os_permission outcomes.${label} "${sid}" not found`,
2049
+ path: ["screens", screenIdx]
2050
+ });
2051
+ }
2052
+ }
2053
+ }
2054
+ if (l.kind === "back_button" && l.fallbackScreenId && !screenIds.has(l.fallbackScreenId)) {
2055
+ ctx.addIssue({
2056
+ code: z.ZodIssueCode.custom,
2057
+ message: `screen "${screen.id}" back_button fallback "${l.fallbackScreenId}" not found`,
2058
+ path: ["screens", screenIdx]
2059
+ });
2060
+ }
2061
+ if (l.kind === "button" && l.action.kind === "go_back_one_screen" && l.action.fallbackScreenId && !screenIds.has(l.action.fallbackScreenId)) {
2062
+ ctx.addIssue({
2063
+ code: z.ZodIssueCode.custom,
2064
+ message: `screen "${screen.id}" button go_back_one_screen fallback "${l.action.fallbackScreenId}" not found`,
2065
+ path: ["screens", screenIdx]
2066
+ });
2067
+ }
2068
+ if (l.kind === "text_input") {
2069
+ const minL = l.minLength;
2070
+ const maxL = l.maxLength;
2071
+ if (minL !== void 0 && maxL !== void 0 && minL > maxL) {
2072
+ ctx.addIssue({
2073
+ code: z.ZodIssueCode.custom,
2074
+ message: `text_input "${l.id}" minLength cannot exceed maxLength`,
2075
+ path: ["screens", screenIdx]
2076
+ });
2077
+ }
2078
+ }
2079
+ if (l.kind === "scale_input") {
2080
+ if (l.min >= l.max) {
2081
+ ctx.addIssue({
2082
+ code: z.ZodIssueCode.custom,
2083
+ message: `scale_input "${l.id}" max must be greater than min`,
2084
+ path: ["screens", screenIdx]
2085
+ });
2086
+ }
2087
+ const step = l.step ?? 1;
2088
+ if (l.defaultValue !== void 0) {
2089
+ if (l.defaultValue < l.min || l.defaultValue > l.max) {
2090
+ ctx.addIssue({
2091
+ code: z.ZodIssueCode.custom,
2092
+ message: `scale_input "${l.id}" defaultValue must be between min and max`,
2093
+ path: ["screens", screenIdx]
2094
+ });
2095
+ } else {
2096
+ const rem = (l.defaultValue - l.min) / step;
2097
+ if (Math.abs(rem - Math.round(rem)) > 1e-6) {
2098
+ ctx.addIssue({
2099
+ code: z.ZodIssueCode.custom,
2100
+ message: `scale_input "${l.id}" defaultValue must align with min and step`,
2101
+ path: ["screens", screenIdx]
2102
+ });
2103
+ }
2104
+ }
2105
+ }
2106
+ }
2107
+ });
2108
+ if (screen.animations) {
2109
+ const clipIds = /* @__PURE__ */ new Set();
2110
+ for (const clip of screen.animations) {
2111
+ if (clipIds.has(clip.id)) {
2112
+ ctx.addIssue({
2113
+ code: z.ZodIssueCode.custom,
2114
+ message: `screen "${screen.id}" has duplicate clip id "${clip.id}"`,
2115
+ path: ["screens", screenIdx, "animations"]
2116
+ });
2117
+ }
2118
+ clipIds.add(clip.id);
2119
+ if (!layerIdsForScreen.has(clip.targetLayerId)) {
2120
+ ctx.addIssue({
2121
+ code: z.ZodIssueCode.custom,
2122
+ message: `clip "${clip.id}" targets layer "${clip.targetLayerId}" not on screen "${screen.id}"`,
2123
+ path: ["screens", screenIdx, "animations"]
2124
+ });
2125
+ }
2126
+ }
2127
+ }
2128
+ });
2129
+ };
2130
+
2131
+ // src/manifest/refineFlowManifest.ts
2132
+ var refineFlowManifest = (manifest, ctx) => {
2133
+ const jumpTargets = buildManifestJumpTargets(manifest);
2134
+ const { screenIds } = refineManifestGraph(manifest, ctx, jumpTargets);
2135
+ const allFieldKeys = /* @__PURE__ */ new Map();
2136
+ refineManifestScreens(manifest, ctx, jumpTargets, screenIds, allFieldKeys);
2137
+ manifest.decisionNodes.forEach((dn, di) => {
2138
+ for (const fk of collectDecisionFieldKeysFromNode(dn)) {
2139
+ if (!allFieldKeys.has(fk)) {
2140
+ ctx.addIssue({
2141
+ code: z.ZodIssueCode.custom,
2142
+ message: `decision "${dn.id}" references unknown fieldKey "${fk}"`,
2143
+ path: ["decisionNodes", di, "cases"]
2144
+ });
2145
+ }
2146
+ }
2147
+ });
2148
+ if (manifest.locales.length > 0 && !manifest.locales.includes(manifest.defaultLocale)) {
2149
+ ctx.addIssue({
2150
+ code: z.ZodIssueCode.custom,
2151
+ message: `defaultLocale "${manifest.defaultLocale}" must be in locales`,
2152
+ path: ["defaultLocale"]
2153
+ });
2154
+ }
2155
+ };
2156
+
2157
+ // src/manifest/flowManifestSchema.ts
2158
+ var FlowManifestObjectSchema = FlowManifestObjectBaseSchema.superRefine(refineFlowManifest);
2159
+ var FlowManifestSchema = FlowManifestObjectSchema;
2160
+
2161
+ export { BuilderMetaSchema, FlowManifestObjectBaseSchema, FlowManifestObjectSchema, FlowManifestSchema, MANIFEST_SCHEMA_VERSION, ThemeSchema, migrateLegacyManifest };
2162
+ //# sourceMappingURL=manifest.js.map
2163
+ //# sourceMappingURL=manifest.js.map