@pygmalionjs/pygmalion 0.2.11 → 0.2.12

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.
@@ -1,151 +1,1768 @@
1
- import { jsx as Z } from "react/jsx-runtime";
2
- import { i as le, g as ce, e as v, b as de, a as ue, c as fe, d as he, f as pe, h as me, j as ge, k as ye, l as we, m as be, n as ve, o as L, S as Se, A as Pe, p as K, q as Oe, r as Ie, t as Ee, u as Ne, v as Ae, w as Re, x as De, y as X } from "./App-CyLtIqGh.js";
3
- import { D as Ye, z as We, B as Ze, C as Ke, E as Xe, G as er, H as rr, I as tr, J as nr, K as sr, L as ir, M as ar } from "./App-CyLtIqGh.js";
4
- import { useMemo as ee, useState as Q, useRef as re, useCallback as j, useEffect as B } from "react";
5
- const te = /^[a-f0-9]{64}$/, Te = /^\/__pygmalion-qa\/artifacts\/[A-Za-z0-9_-]{8,120}\.png$/, _e = /^p\d+$/;
6
- function V(r) {
7
- return typeof r == "string" && Te.test(r) ? r : void 0;
8
- }
9
- function ne(r, e) {
10
- const s = new URL(r, e);
11
- return s.search = "", s.hash = "", s.pathname.endsWith("/") || (s.pathname = `${s.pathname}/`), s.href;
12
- }
13
- function z(r) {
14
- if (!r || typeof r != "object" || Array.isArray(r)) return null;
15
- const e = r;
16
- return typeof e.domStructureHash != "string" || !te.test(e.domStructureHash) || typeof e.screenshotHash != "string" || !te.test(e.screenshotHash) ? null : {
17
- domStructureHash: e.domStructureHash,
18
- screenshotHash: e.screenshotHash,
19
- ...V(e.screenshotUrl) ? { screenshotUrl: V(e.screenshotUrl) } : {}
1
+ import { jsxs as O, jsx as w } from "react/jsx-runtime";
2
+ import { b as V, m as He, v as Ke, c as qe, i as Ge, g as Le, e as K, d as Ve, a as Je, f as We, h as Qe, j as Xe, k as Ye, l as Ze, n as et, o as tt, p as nt, q as rt, r as ot, t as Y, S as st, A as it, u as ve, w as at, x as ct, y as lt, z as dt, B as ft, C as ut, D as pt, E as Ie } from "./App-B0w9z2Br.js";
3
+ import { G as $n, H as Mn, I as Tn, J as Dn, K as kn, L as zn, M as _n, O as Fn, P as jn, Q as Bn, R as Un, T as Hn, U as Kn, V as qn, W as Gn, X as Ln, Y as Vn } from "./App-B0w9z2Br.js";
4
+ import { createElement as xe, useMemo as Pe, useState as te, useRef as Ee, useCallback as Z, useEffect as ee } from "react";
5
+ function pe(e, t = /* @__PURE__ */ new Set()) {
6
+ if (e == null || typeof e == "string" || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e))
7
+ return e;
8
+ if (Array.isArray(e))
9
+ return e.map((n) => pe(n, t));
10
+ if (typeof e != "object") return null;
11
+ if (t.has(e))
12
+ throw new Error("A storyboard recipe cannot contain circular references.");
13
+ t.add(e);
14
+ const r = {};
15
+ for (const n of Object.keys(e).sort()) {
16
+ const o = e[n];
17
+ o !== void 0 && (r[n] = pe(o, t));
18
+ }
19
+ return t.delete(e), r;
20
+ }
21
+ function ht(e) {
22
+ return JSON.stringify(
23
+ pe({
24
+ version: 1,
25
+ route: e.route ?? null,
26
+ componentName: e.componentName ?? null,
27
+ gallery: e.gallery ?? [],
28
+ viewport: {
29
+ width: e.width ?? null,
30
+ height: e.height ?? null,
31
+ frameSizeMode: e.frameSizeMode ?? null,
32
+ heightMode: e.heightMode ?? null,
33
+ maxHeight: e.maxHeight ?? null
34
+ },
35
+ environment: e.environment ?? null,
36
+ preset: e.preset ?? null,
37
+ interactions: e.interactions ?? [],
38
+ assertions: e.assertions ?? []
39
+ })
40
+ );
41
+ }
42
+ function z(e) {
43
+ return [...new Set([...e].map((t) => t == null ? void 0 : t.trim()).filter(Boolean))].sort((t, r) => t.localeCompare(r));
44
+ }
45
+ function mt(e, t) {
46
+ var n;
47
+ return ((n = e.id) == null ? void 0 : n.trim()) || `edge:${t + 1}`;
48
+ }
49
+ function gt(e) {
50
+ const t = [...e.screens].sort((n, o) => n.id.localeCompare(o.id)), r = t[0].id;
51
+ return {
52
+ id: `story:${r}`,
53
+ canonicalScreenId: r,
54
+ screenIds: t.map((n) => n.id),
55
+ names: z(t.map((n) => n.name)),
56
+ recipeKey: e.recipeKey,
57
+ routes: z(t.map((n) => n.route)),
58
+ scenarioIds: z(
59
+ t.flatMap((n) => [
60
+ n.scenarioId,
61
+ ...n.scenarioIds ?? []
62
+ ])
63
+ ),
64
+ sourceKeys: z(t.map((n) => n.sourcePath)),
65
+ flows: z(t.map((n) => n.flow)),
66
+ states: z(t.map((n) => n.state))
20
67
  };
21
68
  }
22
- function se(r) {
23
- if (!r || typeof r != "object" || Array.isArray(r)) return null;
24
- const e = r;
25
- return !Number.isSafeInteger(e.width) || !Number.isSafeInteger(e.height) || Number(e.width) < 1 || Number(e.height) < 1 || Number(e.width) > 65536 || Number(e.height) > 65536 ? null : { width: Number(e.width), height: Number(e.height) };
69
+ function Ne(e) {
70
+ return [
71
+ e.code,
72
+ e.edgeId,
73
+ e.nodeId,
74
+ e.screenId,
75
+ e.scenarioId
76
+ ].join(":");
26
77
  }
27
- function xe(r) {
28
- if (!r || typeof r != "object" || Array.isArray(r)) return null;
29
- const e = r, s = se(e.before), i = se(e.after);
30
- if (!s || !i || !Number.isSafeInteger(e.changedPixels) || !Number.isSafeInteger(e.totalPixels) || Number(e.changedPixels) < 0 || Number(e.totalPixels) < 1 || Number(e.changedPixels) > Number(e.totalPixels) || typeof e.threshold != "number" || !Number.isFinite(e.threshold) || e.threshold < 0 || e.threshold > 1)
31
- return null;
32
- const t = e.heatmapUrl == null ? null : V(e.heatmapUrl) ?? null;
78
+ function yt(e) {
79
+ var g, I;
80
+ const t = [], r = [], n = /* @__PURE__ */ new Map();
81
+ for (const i of e.screens) {
82
+ const l = i.id.trim();
83
+ if (!l || n.has(l)) {
84
+ t.push({
85
+ code: "duplicate-screen-id",
86
+ severity: "error",
87
+ message: l ? `Multiple storyboard screens use the id "${l}".` : "A storyboard screen has an empty id.",
88
+ screenId: l || void 0
89
+ });
90
+ continue;
91
+ }
92
+ const f = l === i.id ? i : { ...i, id: l };
93
+ n.set(l, f), r.push(f);
94
+ }
95
+ const o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set();
96
+ for (const i of r) {
97
+ let l;
98
+ try {
99
+ if (l = (e.recipeKey ?? ht)(i), !l.trim()) throw new Error("Recipe keys cannot be empty.");
100
+ } catch (y) {
101
+ s.add(i.id), t.push({
102
+ code: "invalid-recipe",
103
+ severity: "error",
104
+ message: y instanceof Error ? y.message : "Storyboard recipe identity could not be created.",
105
+ screenId: i.id
106
+ }), l = `invalid:${i.id}`;
107
+ }
108
+ const f = o.get(l);
109
+ f ? f.screens.push(i) : o.set(l, { recipeKey: l, screens: [i] });
110
+ }
111
+ const a = [...o.values()].map(gt).sort((i, l) => i.id.localeCompare(l.id)), c = {};
112
+ for (const i of a)
113
+ for (const l of i.screenIds) c[l] = i.id;
114
+ const d = new Map(a.map((i) => [i.id, i])), h = /* @__PURE__ */ new Map();
115
+ for (const i of e.assets ?? []) {
116
+ const l = h.get(i.pageId);
117
+ l ? l.push(i) : h.set(i.pageId, [i]);
118
+ }
119
+ const u = a.map((i) => {
120
+ const l = i.screenIds.flatMap(
121
+ (f) => h.get(f) ?? []
122
+ );
123
+ return {
124
+ ...i,
125
+ scenarioIds: z([
126
+ ...i.scenarioIds,
127
+ ...l.map((f) => f.scenarioId)
128
+ ]),
129
+ sourceKeys: z([
130
+ ...i.sourceKeys,
131
+ ...l.map((f) => f.sourcePath)
132
+ ])
133
+ };
134
+ }), b = /* @__PURE__ */ new Map();
135
+ for (const i of u)
136
+ for (const l of i.routes) {
137
+ const f = b.get(l);
138
+ f ? f.push(i.id) : b.set(l, [i.id]);
139
+ }
140
+ const P = (i, l, f) => {
141
+ const y = i.trim(), D = c[y] ?? (d.has(y) ? y : null);
142
+ if (D) return D;
143
+ const H = z(b.get(y) ?? []);
144
+ return H.length === 1 ? H[0] : H.length > 1 ? (t.push({
145
+ code: f === "source" ? "ambiguous-edge-source" : "ambiguous-edge-target",
146
+ severity: "error",
147
+ message: `Storyboard edge "${l}" references an ambiguous ${f} route.`,
148
+ edgeId: l,
149
+ screenId: y || void 0
150
+ }), null) : (t.push({
151
+ code: f === "source" ? "unknown-edge-source" : "unknown-edge-target",
152
+ severity: "error",
153
+ message: `Storyboard edge "${l}" references an unknown ${f}.`,
154
+ edgeId: l,
155
+ screenId: y || void 0
156
+ }), null);
157
+ }, E = [], m = /* @__PURE__ */ new Map(), N = [
158
+ ["explicit", e.explicitEdges ?? []],
159
+ ["inferred", e.inferredEdges ?? []]
160
+ ];
161
+ let p = 0;
162
+ for (const [i, l] of N)
163
+ for (const f of l) {
164
+ const y = mt(f, p);
165
+ p += 1;
166
+ const D = P(f.from, y, "source"), H = P(f.to, y, "target");
167
+ if (!D || !H || D === H) continue;
168
+ const de = `${D}\0${H}`, X = m.get(de);
169
+ if (X) {
170
+ if (!X.sourceEdgeIds.includes(y)) {
171
+ const be = {
172
+ ...X,
173
+ sourceEdgeIds: z([
174
+ ...X.sourceEdgeIds,
175
+ y
176
+ ])
177
+ };
178
+ m.set(de, be);
179
+ const Se = E.indexOf(X);
180
+ Se >= 0 && (E[Se] = be);
181
+ }
182
+ continue;
183
+ }
184
+ const we = {
185
+ id: y,
186
+ from: D,
187
+ to: H,
188
+ kind: ((g = f.kind) == null ? void 0 : g.trim()) || void 0,
189
+ label: ((I = f.label) == null ? void 0 : I.trim()) || void 0,
190
+ origin: i,
191
+ sourceEdgeIds: [y]
192
+ };
193
+ m.set(de, we), E.push(we);
194
+ }
195
+ E.sort(
196
+ (i, l) => `${i.from}:${i.to}:${i.id}`.localeCompare(`${l.from}:${l.to}:${l.id}`)
197
+ );
198
+ const $ = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new Map();
199
+ for (const i of E) {
200
+ const l = R.get(i.from);
201
+ l ? l.push(i) : R.set(i.from, [i]);
202
+ const f = $.get(i.to);
203
+ f ? f.push(i) : $.set(i.to, [i]);
204
+ }
205
+ const T = [];
206
+ for (const i of e.startScreenIds ?? []) {
207
+ const l = i.trim(), f = c[l] ?? (d.has(l) ? l : null);
208
+ if (!f) {
209
+ t.push({
210
+ code: "unknown-start-screen",
211
+ severity: "error",
212
+ message: `Storyboard start references an unknown screen "${l}".`,
213
+ screenId: l || void 0
214
+ });
215
+ continue;
216
+ }
217
+ T.push(f);
218
+ }
219
+ const M = new Set(T);
220
+ let A = z(T);
221
+ A.length || (A = u.filter((i) => {
222
+ var l;
223
+ return (((l = $.get(i.id)) == null ? void 0 : l.length) ?? 0) === 0;
224
+ }).map((i) => i.id).sort((i, l) => i.localeCompare(l))), !A.length && u.length && (A = [u[0].id]);
225
+ const S = /* @__PURE__ */ new Set(), C = [...A];
226
+ for (; C.length; ) {
227
+ const i = C.shift();
228
+ if (!S.has(i)) {
229
+ S.add(i);
230
+ for (const l of R.get(i) ?? []) C.push(l.to);
231
+ }
232
+ }
233
+ const F = u.filter((i) => {
234
+ var f, y;
235
+ const l = (((f = $.get(i.id)) == null ? void 0 : f.length) ?? 0) === 0 && (((y = R.get(i.id)) == null ? void 0 : y.length) ?? 0) === 0 && !M.has(i.id);
236
+ return !S.has(i.id) || l && u.length > 1;
237
+ });
238
+ for (const i of F)
239
+ for (const l of i.screenIds)
240
+ t.push({
241
+ code: "disconnected-screen",
242
+ severity: "warning",
243
+ message: `Storyboard screen "${l}" is not connected to a graph branch.`,
244
+ screenId: l,
245
+ nodeId: i.id
246
+ });
247
+ const B = /* @__PURE__ */ new Map();
248
+ for (const i of u)
249
+ for (const l of i.sourceKeys) {
250
+ const f = B.get(l) ?? {
251
+ nodeIds: /* @__PURE__ */ new Set(),
252
+ screenIds: /* @__PURE__ */ new Set()
253
+ };
254
+ f.nodeIds.add(i.id);
255
+ for (const y of i.screenIds) f.screenIds.add(y);
256
+ B.set(l, f);
257
+ }
258
+ const W = [...B.entries()].map(([i, l]) => ({
259
+ sourceKey: i,
260
+ nodeIds: [...l.nodeIds].sort((f, y) => f.localeCompare(y)),
261
+ screenIds: [...l.screenIds].sort((f, y) => f.localeCompare(y)),
262
+ shared: l.nodeIds.size > 1
263
+ })).sort((i, l) => i.sourceKey.localeCompare(l.sourceKey)), q = u.map((i) => {
264
+ const l = [...R.get(i.id) ?? []].sort(
265
+ (f, y) => f.id.localeCompare(y.id)
266
+ );
267
+ return {
268
+ nodeId: i.id,
269
+ edgeIds: l.map((f) => f.id),
270
+ targetNodeIds: z(l.map((f) => f.to))
271
+ };
272
+ }).filter((i) => i.targetNodeIds.length > 1).sort((i, l) => i.nodeId.localeCompare(l.nodeId)), G = new Set(
273
+ u.flatMap((i) => i.scenarioIds)
274
+ ), x = new Set(
275
+ (e.nonVisualScenarioIds ?? []).map((i) => i.trim())
276
+ ), j = z(
277
+ (e.scenarios ?? []).map((i) => i.id)
278
+ ), k = j.filter(
279
+ (i) => !G.has(i) && !x.has(i)
280
+ );
281
+ for (const i of k)
282
+ t.push({
283
+ code: "missing-code-scenario",
284
+ severity: "warning",
285
+ message: `Code scenario "${i}" is not represented in the storyboard.`,
286
+ scenarioId: i
287
+ });
288
+ t.sort(
289
+ (i, l) => Ne(i).localeCompare(Ne(l))
290
+ );
291
+ const Q = z(
292
+ F.flatMap((i) => i.screenIds)
293
+ ), v = {
294
+ screens: r.length,
295
+ canonicalNodes: u.length,
296
+ mergedScreens: Math.max(0, r.length - u.length),
297
+ edges: E.length,
298
+ connectedNodes: u.length - F.length,
299
+ disconnectedScreens: Q,
300
+ codeScenarios: j.length,
301
+ representedScenarios: j.filter(
302
+ (i) => G.has(i)
303
+ ).length,
304
+ missingScenarios: k,
305
+ complete: Q.length === 0 && k.length === 0 && !t.some((i) => i.severity === "error") && s.size === 0
306
+ };
33
307
  return {
34
- before: s,
35
- after: i,
36
- dimensionsMatch: s.width === i.width && s.height === i.height,
37
- changedPixels: Number(e.changedPixels),
38
- totalPixels: Number(e.totalPixels),
39
- diffRatio: Number(e.changedPixels) / Number(e.totalPixels),
40
- threshold: e.threshold,
41
- heatmapUrl: t
308
+ version: 1,
309
+ nodes: u,
310
+ edges: E,
311
+ aliases: Object.fromEntries(
312
+ Object.entries(c).sort(([i], [l]) => i.localeCompare(l))
313
+ ),
314
+ sourceGroups: W,
315
+ startNodeIds: A,
316
+ branches: q,
317
+ warnings: t,
318
+ coverage: v
42
319
  };
43
320
  }
44
- function Fe(r, e) {
45
- if (!r || typeof r != "object" || Array.isArray(r)) return null;
46
- const s = r;
47
- if (typeof s.id != "string" || !s.id) return null;
48
- const i = z(s), t = z(s.before) ?? i;
321
+ function wt(e) {
322
+ return e ? JSON.parse(JSON.stringify(e)) : void 0;
323
+ }
324
+ function oe(e) {
325
+ if (Array.isArray(e)) return e.map(oe);
326
+ if (e && typeof e == "object") {
327
+ const t = Object.entries(e).filter(([, r]) => r !== void 0).sort(([r], [n]) => r.localeCompare(n)).map(([r, n]) => [r, oe(n)]).filter(([, r]) => r !== void 0);
328
+ return t.length ? Object.fromEntries(t) : void 0;
329
+ }
330
+ return e;
331
+ }
332
+ function Ce(e) {
333
+ return JSON.stringify(oe(e ?? null));
334
+ }
335
+ function bt(e) {
336
+ return !!(e && typeof e == "object" && !Array.isArray(e));
337
+ }
338
+ function U(e) {
339
+ const t = e == null ? void 0 : e.trim();
49
340
  if (!t) return null;
50
- const d = z(s.after);
51
- if (e === "changed" && !d) return null;
52
- const h = d ? xe(s.pixelDiff) : null;
53
- return {
341
+ let r = t;
342
+ try {
343
+ /^[a-z][a-z\d+.-]*:\/\//i.test(t) && (r = new URL(t).pathname);
344
+ } catch {
345
+ return null;
346
+ }
347
+ return r = r.split(/[?#]/, 1)[0].replace(/\/{2,}/g, "/"), r.startsWith("/") || (r = `/${r}`), r.length > 1 && (r = r.replace(/\/+$/, "")), r || "/";
348
+ }
349
+ function De(e) {
350
+ return `source-route:${encodeURIComponent(e)}`;
351
+ }
352
+ function ye(e, t) {
353
+ const r = e.split("/").filter(Boolean), n = t.split("/").filter(Boolean);
354
+ let o = 0;
355
+ for (let s = 0; s < r.length; s += 1) {
356
+ const a = r[s];
357
+ if (a === "*" || a.startsWith("*")) return !0;
358
+ const c = n[o];
359
+ if (!(a.endsWith("?") && c == null)) {
360
+ if (c == null || !a.startsWith(":") && a !== c) return !1;
361
+ o += 1;
362
+ }
363
+ }
364
+ return o === n.length;
365
+ }
366
+ function Re(e, t) {
367
+ const r = U(e);
368
+ if (!r) return [];
369
+ const n = t.get(r);
370
+ return n && !/[:*]/.test(r) ? [n] : [
371
+ ...new Set(
372
+ [...t.entries()].filter(([o]) => ye(r, o)).map(([, o]) => o)
373
+ )
374
+ ].sort((o, s) => o.localeCompare(s));
375
+ }
376
+ function St(e) {
377
+ var r;
378
+ const t = /* @__PURE__ */ new Map();
379
+ for (const n of e ?? []) {
380
+ const o = U(n.path);
381
+ !o || t.has(o) || t.set(o, {
382
+ id: De(o),
383
+ name: o,
384
+ section: "Source routes",
385
+ codeName: ((r = n.id) == null ? void 0 : r.trim()) || void 0
386
+ });
387
+ }
388
+ return [...t.values()].sort((n, o) => n.id.localeCompare(o.id));
389
+ }
390
+ function vt(e, t, r) {
391
+ return (e ?? []).flatMap((n, o) => {
392
+ var u, b, P;
393
+ const s = (u = n.from) == null ? void 0 : u.trim(), a = (b = n.to) == null ? void 0 : b.trim();
394
+ if (!s || !a || n.unresolvedTarget) return [];
395
+ const c = r.has(s) ? [s] : Re(s, t), d = r.has(a) ? [a] : Re(a, t);
396
+ if (!c.length || !d.length) return [];
397
+ const h = ((P = n.id) == null ? void 0 : P.trim()) || `discovery-edge:${o + 1}`;
398
+ return c.flatMap(
399
+ (E, m) => d.map((N, p) => {
400
+ var $, R;
401
+ return {
402
+ id: c.length === 1 && d.length === 1 ? h : `${h}:${m + 1}:${p + 1}`,
403
+ from: E,
404
+ to: N,
405
+ kind: (($ = n.kind) == null ? void 0 : $.trim()) || void 0,
406
+ label: ((R = n.label) == null ? void 0 : R.trim()) || void 0
407
+ };
408
+ })
409
+ );
410
+ });
411
+ }
412
+ function It(e, t, r) {
413
+ const n = U(e.route);
414
+ if (!n) return [];
415
+ const o = t.filter(
416
+ (c) => {
417
+ const d = U(c.route);
418
+ return d ? ye(d, n) : !1;
419
+ }
420
+ );
421
+ if (!o.length) return [];
422
+ const s = Ce(
423
+ He(r, e.environment)
424
+ ), a = o.filter(
425
+ (c) => Ce(c.environment) === s
426
+ );
427
+ return [
428
+ ...new Set(
429
+ a.map((c) => {
430
+ var d;
431
+ return (d = c.scenarioId) == null ? void 0 : d.trim();
432
+ }).filter((c) => !!c)
433
+ )
434
+ ].sort((c, d) => c.localeCompare(d));
435
+ }
436
+ function xt(e, t) {
437
+ const r = e.some((s) => s.importKind != null), n = t.candidates ?? [], o = ze(t);
438
+ return e.filter(
439
+ (s) => r ? s.importKind === "screens" : !!s.route
440
+ ).map((s) => ({
54
441
  id: s.id,
55
- before: t,
56
- ...d ? { after: d } : {},
57
- ...d ? {
58
- domChanged: t.domStructureHash !== d.domStructureHash,
59
- screenshotChanged: t.screenshotHash !== d.screenshotHash
442
+ name: s.name,
443
+ section: s.section ?? s.canvas ?? "Screens",
444
+ componentName: s.componentName,
445
+ gallery: s.gallery,
446
+ route: s.route,
447
+ path: s.path,
448
+ publish: s.publish,
449
+ width: s.width,
450
+ height: s.height,
451
+ frameSizeMode: s.frameSizeMode,
452
+ heightMode: s.heightMode,
453
+ maxHeight: s.maxHeight,
454
+ flow: s.flow,
455
+ scenario: s.scenario,
456
+ state: s.state,
457
+ scenarioId: s.scenarioId,
458
+ scenarioIds: It(s, n, o),
459
+ interactions: s.interactions,
460
+ environment: s.environment,
461
+ preset: s.preset,
462
+ assertions: s.assertions,
463
+ sourcePath: [...s.sourcePaths ?? []].filter(Boolean).sort((a, c) => a.localeCompare(c))[0]
464
+ }));
465
+ }
466
+ function le(e, t) {
467
+ var c, d, h, u;
468
+ const r = (((c = e.interactions) == null ? void 0 : c.length) ?? 0) - (((d = t.interactions) == null ? void 0 : d.length) ?? 0);
469
+ if (r !== 0) return r;
470
+ const n = (h = e.scenarioIds) != null && h.includes("environment:baseline") ? 0 : 1, o = (u = t.scenarioIds) != null && u.includes("environment:baseline") ? 0 : 1;
471
+ if (n !== o) return n - o;
472
+ const s = !e.environment && !e.preset ? 0 : 1, a = !t.environment && !t.preset ? 0 : 1;
473
+ return s !== a ? s - a : e.id.localeCompare(t.id);
474
+ }
475
+ function Pt(e) {
476
+ const t = /* @__PURE__ */ new Map();
477
+ for (const r of e) {
478
+ const n = U(r.route);
479
+ if (!n) continue;
480
+ const o = t.get(n);
481
+ o ? o.push(r) : t.set(n, [r]);
482
+ }
483
+ return new Map(
484
+ [...t.entries()].map(([r, n]) => {
485
+ const o = [...n].sort(le);
486
+ return [r, o[0].id];
487
+ })
488
+ );
489
+ }
490
+ function Et(e) {
491
+ return e.action === "wait" ? null : JSON.stringify(
492
+ oe({
493
+ action: e.action,
494
+ selector: e.selector,
495
+ text: e.text,
496
+ exact: e.exact,
497
+ index: e.index,
498
+ waitState: e.waitState,
499
+ value: e.value,
500
+ key: e.key,
501
+ storage: e.storage,
502
+ optional: e.optional
503
+ })
504
+ );
505
+ }
506
+ function ke(e) {
507
+ return (e.interactions ?? []).map(Et).filter((t) => t != null);
508
+ }
509
+ function Nt(e, t) {
510
+ return e.length < t.length && e.every((r, n) => r === t[n]);
511
+ }
512
+ function Ct(e, t) {
513
+ const r = /* @__PURE__ */ new Map();
514
+ for (const n of e) {
515
+ const o = U(n.route);
516
+ if (!o) continue;
517
+ const s = `${o}\0${ke(n).join("")}`, a = r.get(s);
518
+ a ? a.push(n) : r.set(s, [n]);
519
+ }
520
+ return [...r.values()].flatMap((n) => {
521
+ if (n.length < 2) return [];
522
+ const o = U(n[0].route), s = t.get(o), a = n.find((c) => c.id === s) ?? [...n].sort(le)[0];
523
+ return n.filter((c) => c.id !== a.id).sort((c, d) => c.id.localeCompare(d.id)).map((c) => ({
524
+ id: `discovery-variant:${encodeURIComponent(a.id)}:${encodeURIComponent(c.id)}`,
525
+ from: a.id,
526
+ to: c.id,
527
+ kind: "variant"
528
+ }));
529
+ });
530
+ }
531
+ function Rt(e, t) {
532
+ const r = /* @__PURE__ */ new Map();
533
+ for (const n of e) {
534
+ const o = U(n.route);
535
+ if (!o) continue;
536
+ const s = r.get(o);
537
+ s ? s.push(n) : r.set(o, [n]);
538
+ }
539
+ return [...r.entries()].flatMap(([n, o]) => {
540
+ const s = new Map(
541
+ o.map((d) => [d.id, ke(d)])
542
+ ), a = t.get(n), c = o.find(
543
+ (d) => d.id === a
544
+ );
545
+ return o.flatMap((d) => {
546
+ const h = s.get(d.id);
547
+ if (!h.length) return [];
548
+ const b = o.filter(
549
+ (P) => Nt(
550
+ s.get(P.id),
551
+ h
552
+ )
553
+ ).sort((P, E) => {
554
+ const m = s.get(E.id).length - s.get(P.id).length;
555
+ if (m !== 0) return m;
556
+ const N = P.flow && P.flow === d.flow ? 0 : 1, p = E.flow && E.flow === d.flow ? 0 : 1;
557
+ if (N !== p) return N - p;
558
+ const $ = P.section && P.section === d.section ? 0 : 1, R = E.section && E.section === d.section ? 0 : 1;
559
+ if ($ !== R) return $ - R;
560
+ const T = P.id === a ? 0 : 1, M = E.id === a ? 0 : 1;
561
+ return T !== M ? T - M : le(P, E);
562
+ })[0];
563
+ return b ? [
564
+ {
565
+ id: `discovery-recipe:${encodeURIComponent(b.id)}:${encodeURIComponent(d.id)}`,
566
+ from: b.id,
567
+ to: d.id,
568
+ kind: "recipe-step"
569
+ }
570
+ ] : c && c.id !== d.id && s.get(c.id).join("") !== h.join("") ? [
571
+ {
572
+ id: `discovery-route-case:${encodeURIComponent(c.id)}:${encodeURIComponent(d.id)}`,
573
+ from: c.id,
574
+ to: d.id,
575
+ kind: "route-case"
576
+ }
577
+ ] : [];
578
+ });
579
+ });
580
+ }
581
+ function At(e) {
582
+ var r;
583
+ const t = /* @__PURE__ */ new Map();
584
+ for (const n of e) {
585
+ const o = (r = n.flow) == null ? void 0 : r.trim();
586
+ if (!o) continue;
587
+ const s = t.get(o);
588
+ s ? s.push(n) : t.set(o, [n]);
589
+ }
590
+ return [...t.values()].flatMap((n) => {
591
+ const o = n[0], s = /* @__PURE__ */ new Map();
592
+ for (const a of n) {
593
+ const c = U(a.route);
594
+ if (!c) continue;
595
+ const d = s.get(c);
596
+ d ? d.push(a) : s.set(c, [a]);
597
+ }
598
+ return s.size < 2 ? [] : [...s.values()].flatMap((a) => {
599
+ const c = [...a].sort(
600
+ le
601
+ )[0];
602
+ return c.id === o.id ? [] : [
603
+ {
604
+ id: `discovery-flow-route:${encodeURIComponent(o.id)}:${encodeURIComponent(c.id)}`,
605
+ from: o.id,
606
+ to: c.id,
607
+ kind: "flow-route"
608
+ }
609
+ ];
610
+ });
611
+ });
612
+ }
613
+ function Ot(e, t, r) {
614
+ const n = new Set(
615
+ (t.routes ?? []).map((o) => U(o.path)).filter((o) => !!o)
616
+ );
617
+ return e.map((o) => {
618
+ const s = U(o.route);
619
+ if (!s || r.get(s) !== o.id)
620
+ return o;
621
+ const a = [...n].filter(
622
+ (c) => ye(c, s)
623
+ );
624
+ return a.length ? {
625
+ ...o,
626
+ scenarioIds: [
627
+ .../* @__PURE__ */ new Set([
628
+ ...o.scenarioIds ?? [],
629
+ ...a.map(De)
630
+ ])
631
+ ].sort((c, d) => c.localeCompare(d))
632
+ } : o;
633
+ });
634
+ }
635
+ function $t(e, t) {
636
+ var h, u, b, P, E;
637
+ const r = new Set(e.map((m) => m.id)), n = new Map(
638
+ e.map((m, N) => [m.id, N])
639
+ ), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
640
+ for (const m of r)
641
+ o.set(m, /* @__PURE__ */ new Set()), s.set(m, /* @__PURE__ */ new Set()), a.set(m, /* @__PURE__ */ new Set());
642
+ for (const m of t)
643
+ !r.has(m.from) || !r.has(m.to) || ((h = o.get(m.to)) == null || h.add(m.from), (u = s.get(m.from)) == null || u.add(m.to), (b = a.get(m.from)) == null || b.add(m.to), (P = a.get(m.to)) == null || P.add(m.from));
644
+ const c = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set();
645
+ for (const m of r) {
646
+ if (d.has(m)) continue;
647
+ const N = [], p = [m];
648
+ for (; p.length; ) {
649
+ const S = p.shift();
650
+ if (!d.has(S)) {
651
+ d.add(S), N.push(S);
652
+ for (const C of a.get(S) ?? [])
653
+ d.has(C) || p.push(C);
654
+ }
655
+ }
656
+ if (N.length === 1 && (((E = a.get(N[0])) == null ? void 0 : E.size) ?? 0) === 0)
657
+ continue;
658
+ const $ = N.filter((S) => {
659
+ var C;
660
+ return (((C = o.get(S)) == null ? void 0 : C.size) ?? 0) === 0;
661
+ }).sort(
662
+ (S, C) => (n.get(S) ?? Number.MAX_SAFE_INTEGER) - (n.get(C) ?? Number.MAX_SAFE_INTEGER) || S.localeCompare(C)
663
+ ), R = [...N].sort(
664
+ (S, C) => (n.get(S) ?? Number.MAX_SAFE_INTEGER) - (n.get(C) ?? Number.MAX_SAFE_INTEGER) || S.localeCompare(C)
665
+ )[0];
666
+ if (!R) continue;
667
+ const T = [R], M = /* @__PURE__ */ new Set(), A = (S) => {
668
+ const C = [S];
669
+ for (; C.length; ) {
670
+ const F = C.shift();
671
+ if (!M.has(F)) {
672
+ M.add(F);
673
+ for (const B of s.get(F) ?? [])
674
+ M.has(B) || C.push(B);
675
+ }
676
+ }
677
+ };
678
+ A(R);
679
+ for (const S of $)
680
+ M.has(S) || (T.push(S), A(S));
681
+ for (const S of T)
682
+ c.add(S);
683
+ }
684
+ return [...c].sort(
685
+ (m, N) => (n.get(m) ?? Number.MAX_SAFE_INTEGER) - (n.get(N) ?? Number.MAX_SAFE_INTEGER) || m.localeCompare(N)
686
+ );
687
+ }
688
+ function ze(e) {
689
+ var t, r;
690
+ return wt(
691
+ (r = (t = e.scenarios) == null ? void 0 : t.find(
692
+ (n) => n.id === "environment:baseline"
693
+ )) == null ? void 0 : r.environment
694
+ );
695
+ }
696
+ function Mt(e) {
697
+ const t = xt(
698
+ e.pages,
699
+ e.manifest
700
+ ), r = Pt(t), n = Ot(
701
+ t,
702
+ e.manifest,
703
+ r
704
+ ), s = [
705
+ ...vt(
706
+ e.manifest.edges,
707
+ r,
708
+ new Set(n.map((a) => a.id))
709
+ ),
710
+ ...Ct(n, r),
711
+ ...Rt(n, r),
712
+ ...At(n)
713
+ ];
714
+ return yt({
715
+ screens: n,
716
+ assets: e.assets,
717
+ scenarios: St(e.manifest.routes),
718
+ inferredEdges: s,
719
+ startScreenIds: $t(n, s)
720
+ });
721
+ }
722
+ async function _e(e) {
723
+ const r = await (e.fetcher ?? ((o, s) => fetch(o, s)))(e.endpoint, {
724
+ headers: { accept: "application/json" },
725
+ cache: "no-store",
726
+ signal: e.signal
727
+ });
728
+ if (!r.ok)
729
+ throw new Error(`Storyboard discovery failed (${r.status})`);
730
+ const n = await r.json();
731
+ if (!bt(n))
732
+ throw new Error("Storyboard discovery returned an invalid manifest.");
733
+ return {
734
+ manifest: n,
735
+ baselineEnvironment: ze(n),
736
+ graph: Mt({
737
+ manifest: n,
738
+ pages: e.pages,
739
+ assets: e.assets
740
+ })
741
+ };
742
+ }
743
+ async function mn(e) {
744
+ V(null);
745
+ try {
746
+ const t = await _e(e);
747
+ return V(t.graph), t;
748
+ } catch (t) {
749
+ throw V(null), t;
750
+ }
751
+ }
752
+ const Tt = "pygmalion-preview", Dt = "unknown", kt = 512, zt = 2048, _t = 8 * 1024 * 1024, Ft = 128 * 1024 * 1024, jt = /* @__PURE__ */ new Set([
753
+ "__proto__",
754
+ "constructor",
755
+ "prototype"
756
+ ]);
757
+ function J(e, t) {
758
+ const r = e.trim();
759
+ if (!r && t != null) return t;
760
+ if (re(r)) return r;
761
+ throw new TypeError("Preview identity must be a non-empty bounded string.");
762
+ }
763
+ function Bt(e) {
764
+ const t = e ?? 1;
765
+ if (!Number.isSafeInteger(t) || t < 1)
766
+ throw new TypeError(
767
+ "Preview recipe version must be a positive safe integer."
768
+ );
769
+ return t;
770
+ }
771
+ function he(e, t = /* @__PURE__ */ new Set()) {
772
+ if (e == null || typeof e == "string" || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e))
773
+ return e;
774
+ if (typeof e != "object") return null;
775
+ if (t.has(e))
776
+ throw new TypeError(
777
+ "Preview recipe identity cannot contain circular values."
778
+ );
779
+ if (t.add(e), Array.isArray(e)) {
780
+ const n = e.map((o) => he(o, t));
781
+ return t.delete(e), n;
782
+ }
783
+ const r = {};
784
+ for (const n of Object.keys(e).sort()) {
785
+ const o = e[n];
786
+ o !== void 0 && (r[n] = he(o, t));
787
+ }
788
+ return t.delete(e), r;
789
+ }
790
+ function Ut(e) {
791
+ let t = 2166136261, r = 2654435769;
792
+ for (let n = 0; n < e.length; n += 1) {
793
+ const o = e.charCodeAt(n);
794
+ t = Math.imul(t ^ o, 16777619), r = Math.imul(r ^ o + n, 2246822507);
795
+ }
796
+ return `${(t >>> 0).toString(16).padStart(8, "0")}${(r >>> 0).toString(16).padStart(8, "0")}`;
797
+ }
798
+ function Ht(e) {
799
+ if (!Array.isArray(e))
800
+ throw new TypeError("Preview recipes must be an array.");
801
+ const t = /* @__PURE__ */ new Set(), r = e.map(({ id: n, recipe: o }) => {
802
+ const s = J(n);
803
+ if (t.has(s))
804
+ throw new TypeError(`Duplicate preview recipe identity: ${s}`);
805
+ return t.add(s), {
806
+ id: s,
807
+ recipe: he(o)
808
+ };
809
+ });
810
+ return Ut(JSON.stringify(r));
811
+ }
812
+ function gn({
813
+ sourceRevision: e,
814
+ recipes: t,
815
+ recipeVersion: r,
816
+ scope: n = Tt
817
+ }) {
818
+ const o = J(n), s = J(
819
+ e,
820
+ Dt
821
+ ), a = Bt(r), c = Ht(t);
822
+ return `${o}:${encodeURIComponent(s)}:recipe-v${a}:${c}`;
823
+ }
824
+ function yn(e) {
825
+ return {
826
+ route: e.route,
827
+ path: e.path,
828
+ componentName: e.componentName,
829
+ gallery: e.gallery,
830
+ width: e.width,
831
+ height: e.height,
832
+ environment: e.environment,
833
+ preset: e.preset,
834
+ interactions: (e.interactions ?? []).map((t) => ({
835
+ action: t.action,
836
+ selector: t.selector,
837
+ text: t.text,
838
+ exact: t.exact,
839
+ index: t.index,
840
+ value: t.value,
841
+ key: t.key,
842
+ storage: t.storage,
843
+ optional: t.optional,
844
+ settleMs: t.settleMs,
845
+ timeoutMs: t.timeoutMs,
846
+ waitState: t.waitState
847
+ })),
848
+ assertions: e.assertions
849
+ };
850
+ }
851
+ function Kt({
852
+ endpoint: e,
853
+ fetcher: t,
854
+ captureBaseUrl: r
855
+ }) {
856
+ const n = e.trim();
857
+ if (!n)
858
+ throw new TypeError(
859
+ "Preview artifact endpoint must be a non-empty string."
860
+ );
861
+ const o = t ?? ((s, a) => fetch(s, a));
862
+ return async (s) => {
863
+ const a = new URLSearchParams({
864
+ namespace: s.namespace,
865
+ sourceRevision: s.sourceRevision
866
+ }), c = s.captureBaseUrl ?? r;
867
+ c && a.set("captureBaseUrl", c);
868
+ const d = n.includes("?") ? "&" : "?", h = await o(
869
+ `${n}${d}${a}`,
870
+ {
871
+ method: "GET",
872
+ headers: { accept: "application/json" },
873
+ cache: "no-store",
874
+ signal: s.signal
875
+ }
876
+ );
877
+ return h.ok ? h.json().catch(() => null) : null;
878
+ };
879
+ }
880
+ function se(e) {
881
+ if (!e || typeof e != "object" || Array.isArray(e)) return !1;
882
+ const t = Object.getPrototypeOf(e);
883
+ return t === Object.prototype || t === null;
884
+ }
885
+ function Fe(e) {
886
+ return new TextEncoder().encode(e).byteLength;
887
+ }
888
+ function re(e) {
889
+ return typeof e == "string" && e.length > 0 && e.length <= kt && e === e.trim() && !jt.has(e);
890
+ }
891
+ function qt(e) {
892
+ const t = /(?:expression\s*\(|-moz-binding\s*:|(?:^|[;{])\s*behavior\s*:)/i;
893
+ for (const r of e.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style\s*>/gi))
894
+ if (t.test(r[1] ?? "")) return !0;
895
+ for (const r of e.matchAll(
896
+ /\sstyle\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi
897
+ ))
898
+ if (t.test(r[1] ?? r[2] ?? r[3] ?? "")) return !0;
899
+ return !1;
900
+ }
901
+ function Gt(e) {
902
+ return typeof e != "string" || e.length === 0 || Fe(e) > _t ? !1 : !(/<\s*(?:script|iframe|object|embed|applet|portal)\b/i.test(e) || /<\s*meta\b[^>]*http-equiv\s*=\s*["']?\s*refresh\b/i.test(e) || /\s(?:on[a-z][\w:-]*|srcdoc)\s*=/i.test(e) || /\s(?:href|src|action|formaction|xlink:href)\s*=\s*(?:"\s*|'?\s*)(?:javascript|vbscript|data\s*:\s*text\/html)\s*:/i.test(
903
+ e
904
+ ) || qt(e));
905
+ }
906
+ function Lt(e) {
907
+ const t = [];
908
+ if (!se(e) || e.version !== 1)
909
+ return {
910
+ valid: !1,
911
+ artifact: null,
912
+ errors: [
913
+ "Preview artifact must be a version 1, version 2, or version 3 bundle."
914
+ ]
915
+ };
916
+ if (re(e.namespace) || t.push("Preview artifact namespace is invalid."), e.sourceRevision != null && !re(e.sourceRevision) && t.push("Preview artifact source revision is invalid."), !se(e.snapshots))
917
+ t.push("Preview artifact snapshots must be a record.");
918
+ else {
919
+ const r = Object.entries(e.snapshots);
920
+ r.length > zt && t.push("Preview artifact has too many frames.");
921
+ for (const [n, o] of r)
922
+ (!re(n) || !Gt(o)) && t.push(`Preview artifact frame "${n}" is invalid.`);
923
+ }
924
+ try {
925
+ Fe(JSON.stringify(e)) > Ft && t.push("Preview artifact exceeds the bundle byte limit.");
926
+ } catch {
927
+ t.push("Preview artifact is not serializable.");
928
+ }
929
+ return {
930
+ valid: t.length === 0,
931
+ artifact: t.length === 0 ? e : null,
932
+ errors: t
933
+ };
934
+ }
935
+ function Vt(e, t) {
936
+ const r = se(e) && e.version === 3 ? (() => {
937
+ const n = Ke(e);
938
+ return {
939
+ valid: n.valid,
940
+ artifact: n.valid ? e : null,
941
+ errors: n.errors
942
+ };
943
+ })() : se(e) && e.version === 2 ? (() => {
944
+ const n = qe(e);
945
+ return {
946
+ valid: n.valid,
947
+ artifact: n.valid ? e : null,
948
+ errors: n.errors
949
+ };
950
+ })() : Lt(e);
951
+ return !r.valid || !r.artifact ? {
952
+ valid: !1,
953
+ artifact: null,
954
+ reason: "invalid-bundle",
955
+ errors: r.errors
956
+ } : t && r.artifact.namespace !== J(t.namespace) ? {
957
+ valid: !1,
958
+ artifact: null,
959
+ reason: "namespace-mismatch",
960
+ errors: [
961
+ "Preview artifact namespace does not match the runtime namespace."
962
+ ]
963
+ } : t && r.artifact.sourceRevision !== J(t.sourceRevision) ? {
964
+ valid: !1,
965
+ artifact: null,
966
+ reason: "revision-mismatch",
967
+ errors: [
968
+ "Preview artifact source revision does not match the runtime revision."
969
+ ]
970
+ } : {
971
+ valid: !0,
972
+ artifact: r.artifact,
973
+ errors: []
974
+ };
975
+ }
976
+ async function Jt({
977
+ namespace: e,
978
+ sourceRevision: t,
979
+ transport: r,
980
+ signal: n
981
+ }) {
982
+ const o = {
983
+ namespace: J(e),
984
+ sourceRevision: J(t)
985
+ };
986
+ let s;
987
+ try {
988
+ s = await r({ ...o, signal: n });
989
+ } catch (c) {
990
+ if (n != null && n.aborted) throw c;
991
+ return { status: "unavailable", artifact: null, error: c };
992
+ }
993
+ if (s == null)
994
+ return { status: "unavailable", artifact: null };
995
+ const a = Vt(s, o);
996
+ return a.valid ? { status: "accepted", artifact: a.artifact } : {
997
+ status: "rejected",
998
+ artifact: null,
999
+ reason: a.reason,
1000
+ errors: a.errors
1001
+ };
1002
+ }
1003
+ const ie = "var(--pygmalion-catalog-surface, #ffffff)", ae = "var(--pygmalion-catalog-canvas, #f5f5f5)", me = "var(--pygmalion-catalog-border, #e5e7eb)", ce = "var(--pygmalion-catalog-text, #202124)", _ = "var(--pygmalion-catalog-muted, #6b7280)", Wt = "var(--pygmalion-catalog-header, #11182f)", Qt = "var(--pygmalion-catalog-accent, #7c6cf2)";
1004
+ function wn({
1005
+ title: e,
1006
+ eyebrow: t,
1007
+ description: r,
1008
+ version: n,
1009
+ meta: o,
1010
+ children: s,
1011
+ headerBackground: a = Wt,
1012
+ headerColor: c = "#ffffff",
1013
+ bodyBackground: d = ie,
1014
+ bodyGap: h = 40
1015
+ }) {
1016
+ return /* @__PURE__ */ O(
1017
+ "section",
1018
+ {
1019
+ "data-pygmalion-catalog-document": "",
1020
+ "data-pygmalion-content-bounds": "",
1021
+ style: {
1022
+ boxSizing: "border-box",
1023
+ display: "inline-flex",
1024
+ width: "max-content",
1025
+ maxWidth: "none",
1026
+ flexDirection: "column",
1027
+ overflow: "visible",
1028
+ color: ce,
1029
+ background: d,
1030
+ fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif"
1031
+ },
1032
+ children: [
1033
+ /* @__PURE__ */ O(
1034
+ "header",
1035
+ {
1036
+ style: {
1037
+ boxSizing: "border-box",
1038
+ display: "flex",
1039
+ alignItems: "flex-end",
1040
+ justifyContent: "space-between",
1041
+ gap: 48,
1042
+ padding: "44px 48px 48px",
1043
+ color: c,
1044
+ background: a
1045
+ },
1046
+ children: [
1047
+ /* @__PURE__ */ O("div", { style: { display: "flex", flexDirection: "column", gap: 10 }, children: [
1048
+ t ? /* @__PURE__ */ w(
1049
+ "div",
1050
+ {
1051
+ style: {
1052
+ color: "color-mix(in srgb, currentColor 68%, transparent)",
1053
+ fontSize: 12,
1054
+ fontWeight: 700,
1055
+ letterSpacing: "0.12em",
1056
+ textTransform: "uppercase"
1057
+ },
1058
+ children: t
1059
+ }
1060
+ ) : null,
1061
+ /* @__PURE__ */ w(
1062
+ "h1",
1063
+ {
1064
+ style: {
1065
+ margin: 0,
1066
+ fontSize: 60,
1067
+ fontWeight: 700,
1068
+ letterSpacing: "-0.045em",
1069
+ lineHeight: 0.96,
1070
+ whiteSpace: "nowrap"
1071
+ },
1072
+ children: e
1073
+ }
1074
+ ),
1075
+ r ? /* @__PURE__ */ w(
1076
+ "div",
1077
+ {
1078
+ style: {
1079
+ maxWidth: 640,
1080
+ color: "color-mix(in srgb, currentColor 72%, transparent)",
1081
+ fontSize: 13,
1082
+ lineHeight: 1.55
1083
+ },
1084
+ children: r
1085
+ }
1086
+ ) : null
1087
+ ] }),
1088
+ n || o ? /* @__PURE__ */ O(
1089
+ "div",
1090
+ {
1091
+ style: {
1092
+ display: "flex",
1093
+ alignItems: "flex-end",
1094
+ gap: 24,
1095
+ color: "color-mix(in srgb, currentColor 72%, transparent)",
1096
+ fontSize: 12,
1097
+ whiteSpace: "nowrap"
1098
+ },
1099
+ children: [
1100
+ n ? /* @__PURE__ */ w("span", { children: n }) : null,
1101
+ o ? /* @__PURE__ */ w("span", { children: o }) : null
1102
+ ]
1103
+ }
1104
+ ) : null
1105
+ ]
1106
+ }
1107
+ ),
1108
+ /* @__PURE__ */ w(
1109
+ "div",
1110
+ {
1111
+ "data-pygmalion-catalog-document-body": "",
1112
+ style: {
1113
+ boxSizing: "border-box",
1114
+ display: "inline-flex",
1115
+ flexDirection: "column",
1116
+ alignItems: "flex-start",
1117
+ gap: h,
1118
+ padding: 48,
1119
+ background: d
1120
+ },
1121
+ children: s
1122
+ }
1123
+ )
1124
+ ]
1125
+ }
1126
+ );
1127
+ }
1128
+ function bn({
1129
+ title: e,
1130
+ count: t,
1131
+ description: r,
1132
+ children: n,
1133
+ tone: o = "tinted"
1134
+ }) {
1135
+ return /* @__PURE__ */ O(
1136
+ "section",
1137
+ {
1138
+ "data-pygmalion-catalog-section": "",
1139
+ style: {
1140
+ boxSizing: "border-box",
1141
+ display: "inline-flex",
1142
+ width: "max-content",
1143
+ flexDirection: "column",
1144
+ alignItems: "flex-start",
1145
+ gap: 18,
1146
+ padding: o === "tinted" ? 24 : 0,
1147
+ background: o === "tinted" ? ae : "transparent"
1148
+ },
1149
+ children: [
1150
+ /* @__PURE__ */ O("header", { style: { display: "flex", alignItems: "baseline", gap: 8 }, children: [
1151
+ /* @__PURE__ */ w(
1152
+ "h2",
1153
+ {
1154
+ style: {
1155
+ margin: 0,
1156
+ fontSize: 15,
1157
+ fontWeight: 700,
1158
+ letterSpacing: "-0.01em"
1159
+ },
1160
+ children: e
1161
+ }
1162
+ ),
1163
+ typeof t == "number" ? /* @__PURE__ */ w("span", { style: { color: _, fontSize: 11 }, children: t }) : null
1164
+ ] }),
1165
+ r ? /* @__PURE__ */ w("div", { style: { marginTop: -10, color: _, fontSize: 11 }, children: r }) : null,
1166
+ n
1167
+ ]
1168
+ }
1169
+ );
1170
+ }
1171
+ function Sn({
1172
+ rows: e,
1173
+ columns: t,
1174
+ cornerLabel: r,
1175
+ renderCell: n,
1176
+ renderRowLabel: o = (d) => d,
1177
+ renderColumnLabel: s = (d) => d,
1178
+ boundary: a = !0,
1179
+ cellStyle: c
1180
+ }) {
1181
+ return /* @__PURE__ */ w(
1182
+ "div",
1183
+ {
1184
+ "data-pygmalion-catalog-matrix": "",
1185
+ style: {
1186
+ boxSizing: "border-box",
1187
+ display: "inline-block",
1188
+ width: "max-content",
1189
+ padding: a ? 16 : 0,
1190
+ border: a ? `1px dashed ${Qt}` : void 0,
1191
+ borderRadius: a ? 4 : void 0
1192
+ },
1193
+ children: /* @__PURE__ */ O(
1194
+ "table",
1195
+ {
1196
+ style: {
1197
+ width: "max-content",
1198
+ borderCollapse: "separate",
1199
+ borderSpacing: 0
1200
+ },
1201
+ children: [
1202
+ /* @__PURE__ */ w("thead", { children: /* @__PURE__ */ O("tr", { children: [
1203
+ /* @__PURE__ */ w(
1204
+ "th",
1205
+ {
1206
+ style: {
1207
+ padding: "0 16px 12px 0",
1208
+ color: _,
1209
+ fontSize: 10,
1210
+ fontWeight: 600,
1211
+ textAlign: "left",
1212
+ whiteSpace: "nowrap"
1213
+ },
1214
+ children: r
1215
+ }
1216
+ ),
1217
+ t.map((d) => /* @__PURE__ */ w(
1218
+ "th",
1219
+ {
1220
+ style: {
1221
+ padding: "0 16px 12px",
1222
+ color: _,
1223
+ fontSize: 10,
1224
+ fontWeight: 600,
1225
+ textAlign: "center",
1226
+ whiteSpace: "nowrap"
1227
+ },
1228
+ children: s(d)
1229
+ },
1230
+ d
1231
+ ))
1232
+ ] }) }),
1233
+ /* @__PURE__ */ w("tbody", { children: e.map((d) => /* @__PURE__ */ O("tr", { children: [
1234
+ /* @__PURE__ */ w(
1235
+ "th",
1236
+ {
1237
+ style: {
1238
+ padding: "12px 16px 12px 0",
1239
+ color: _,
1240
+ fontSize: 10,
1241
+ fontWeight: 600,
1242
+ textAlign: "left",
1243
+ whiteSpace: "nowrap"
1244
+ },
1245
+ children: o(d)
1246
+ }
1247
+ ),
1248
+ t.map((h) => /* @__PURE__ */ w(
1249
+ "td",
1250
+ {
1251
+ style: {
1252
+ padding: "12px 16px",
1253
+ textAlign: "center",
1254
+ verticalAlign: "middle",
1255
+ ...c
1256
+ },
1257
+ children: n(d, h)
1258
+ },
1259
+ h
1260
+ ))
1261
+ ] }, d)) })
1262
+ ]
1263
+ }
1264
+ )
1265
+ }
1266
+ );
1267
+ }
1268
+ function Xt(e) {
1269
+ return e.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").replace(/[^\p{L}\p{N}]+/gu, "-").replace(/^-+|-+$/g, "").toLowerCase() || "page";
1270
+ }
1271
+ function je(e, t, r = "PygmalionCatalog") {
1272
+ const n = (o) => Xt(o).replace(/-/g, "_");
1273
+ return `${r}_${n(e)}_${n(t)}`;
1274
+ }
1275
+ function Be(e, t) {
1276
+ return {
1277
+ id: e.id,
1278
+ name: e.name,
1279
+ section: e.section,
1280
+ pageId: t,
1281
+ sourcePath: e.sourcePath,
1282
+ codeName: e.codeName,
1283
+ description: e.description
1284
+ };
1285
+ }
1286
+ function Ue(e) {
1287
+ const t = /* @__PURE__ */ new Set();
1288
+ for (const r of e) {
1289
+ if (t.has(r.id))
1290
+ throw new Error(`Duplicate design catalog item id: ${r.id}`);
1291
+ t.add(r.id);
1292
+ }
1293
+ }
1294
+ function Yt(e, t, r) {
1295
+ return typeof e == "function" ? e(t, r) : e;
1296
+ }
1297
+ function Zt({
1298
+ page: e,
1299
+ items: t,
1300
+ renderPreview: r,
1301
+ secondaryLabel: n,
1302
+ minimumColumnWidth: o
1303
+ }) {
1304
+ return /* @__PURE__ */ O(
1305
+ "section",
1306
+ {
1307
+ "data-pygmalion-catalog-page": e.id,
1308
+ "data-pygmalion-content-bounds": "",
1309
+ style: {
1310
+ boxSizing: "border-box",
1311
+ display: "inline-block",
1312
+ width: "max-content",
1313
+ padding: 32,
1314
+ color: ce,
1315
+ background: ae,
1316
+ fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif"
1317
+ },
1318
+ children: [
1319
+ /* @__PURE__ */ O("header", { style: { marginBottom: 24 }, children: [
1320
+ /* @__PURE__ */ w("h1", { style: { margin: 0, fontSize: 24, lineHeight: 1.35 }, children: e.name }),
1321
+ /* @__PURE__ */ O("p", { style: { margin: "6px 0 0", color: _, fontSize: 13 }, children: [
1322
+ t.length,
1323
+ " assets"
1324
+ ] })
1325
+ ] }),
1326
+ /* @__PURE__ */ w(
1327
+ "div",
1328
+ {
1329
+ style: {
1330
+ display: "inline-grid",
1331
+ gridTemplateColumns: "repeat(6, max-content)",
1332
+ gap: 16
1333
+ },
1334
+ children: t.map((s) => /* @__PURE__ */ O(
1335
+ "article",
1336
+ {
1337
+ "data-pygmalion-catalog-item": s.id,
1338
+ style: {
1339
+ minWidth: o,
1340
+ width: o,
1341
+ padding: 16,
1342
+ border: `1px solid ${me}`,
1343
+ borderRadius: 12,
1344
+ background: ie
1345
+ },
1346
+ children: [
1347
+ /* @__PURE__ */ w(
1348
+ "div",
1349
+ {
1350
+ style: {
1351
+ display: "flex",
1352
+ minHeight: 64,
1353
+ alignItems: "center",
1354
+ justifyContent: "center",
1355
+ overflow: "hidden"
1356
+ },
1357
+ children: r(s)
1358
+ }
1359
+ ),
1360
+ /* @__PURE__ */ w(
1361
+ "div",
1362
+ {
1363
+ style: {
1364
+ marginTop: 12,
1365
+ overflow: "hidden",
1366
+ fontSize: 13,
1367
+ fontWeight: 600,
1368
+ textOverflow: "ellipsis",
1369
+ whiteSpace: "nowrap"
1370
+ },
1371
+ title: s.name,
1372
+ children: s.name
1373
+ }
1374
+ ),
1375
+ n ? /* @__PURE__ */ w("div", { style: { marginTop: 4, color: _, fontSize: 11, lineHeight: 1.45 }, children: n(s) }) : s.codeName ? /* @__PURE__ */ w(
1376
+ "div",
1377
+ {
1378
+ style: {
1379
+ marginTop: 4,
1380
+ overflow: "hidden",
1381
+ color: _,
1382
+ fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
1383
+ fontSize: 11,
1384
+ textOverflow: "ellipsis",
1385
+ whiteSpace: "nowrap"
1386
+ },
1387
+ title: s.codeName,
1388
+ children: s.codeName
1389
+ }
1390
+ ) : null
1391
+ ]
1392
+ },
1393
+ s.id
1394
+ ))
1395
+ }
1396
+ )
1397
+ ]
1398
+ }
1399
+ );
1400
+ }
1401
+ function vn(e) {
1402
+ Ue(e.items);
1403
+ const t = /* @__PURE__ */ new Map();
1404
+ for (const o of e.items) {
1405
+ const s = e.pageFor(o), a = t.get(s.id);
1406
+ if (a) {
1407
+ if (a.page.name !== s.name || a.page.section !== s.section)
1408
+ throw new Error(`Conflicting design catalog page descriptor: ${s.id}`);
1409
+ a.items.push(o);
1410
+ continue;
1411
+ }
1412
+ t.set(s.id, {
1413
+ page: s,
1414
+ items: [o],
1415
+ registryName: je(
1416
+ e.kind,
1417
+ s.id,
1418
+ e.registryPrefix
1419
+ )
1420
+ });
1421
+ }
1422
+ const r = {}, n = [];
1423
+ for (const o of t.values()) {
1424
+ const s = () => /* @__PURE__ */ w(
1425
+ Zt,
1426
+ {
1427
+ page: o.page,
1428
+ items: o.items,
1429
+ renderPreview: e.renderPreview,
1430
+ secondaryLabel: e.secondaryLabel,
1431
+ minimumColumnWidth: e.minimumColumnWidth ?? 152
1432
+ }
1433
+ );
1434
+ r[o.registryName] = {
1435
+ component: s,
1436
+ children: "none"
1437
+ };
1438
+ const a = Yt(e.frame, o.page, o.items);
1439
+ n.push({
1440
+ ...o.page,
1441
+ componentName: o.registryName,
1442
+ width: (a == null ? void 0 : a.width) ?? 1,
1443
+ height: (a == null ? void 0 : a.height) ?? 1,
1444
+ frameSizeMode: a ? "fixed" : "content"
1445
+ });
1446
+ }
1447
+ return {
1448
+ registry: r,
1449
+ collection: {
1450
+ expectedCount: e.expectedCount ?? e.items.length,
1451
+ assets: e.items.map((o) => Be(o, e.pageFor(o).id)),
1452
+ pages: n
1453
+ }
1454
+ };
1455
+ }
1456
+ function en(e, t = 60) {
1457
+ const r = Object.entries((e == null ? void 0 : e.props) ?? {}).filter(([, c]) => c.length > 0).sort(([c, d], [h, u]) => u.length - d.length || c.localeCompare(h)), n = r[0], o = r[1], s = Math.max(1, (n == null ? void 0 : n[1].length) ?? 1), a = o == null ? void 0 : o[1].slice(0, Math.max(1, Math.floor(t / s)));
1458
+ return {
1459
+ row: n,
1460
+ column: o ? [o[0], a ?? []] : void 0,
1461
+ fixed: r.slice(2).map(([c, d]) => [c, d[0]]),
1462
+ additional: r.slice(2)
1463
+ };
1464
+ }
1465
+ function tn(e, t, r, n) {
1466
+ return {
1467
+ ...e.defaultProps,
1468
+ ...Object.fromEntries(t.fixed),
1469
+ ...t.row && r ? { [t.row[0]]: r } : {},
1470
+ ...t.column && n ? { [t.column[0]]: n } : {}
1471
+ };
1472
+ }
1473
+ function nn({
1474
+ item: e,
1475
+ entry: t,
1476
+ maxVariantCells: r
1477
+ }) {
1478
+ var c, d;
1479
+ if (!t)
1480
+ return /* @__PURE__ */ O(
1481
+ "section",
1482
+ {
1483
+ "data-pygmalion-catalog-component": e.id,
1484
+ "data-pygmalion-content-bounds": "",
1485
+ style: {
1486
+ boxSizing: "border-box",
1487
+ display: "inline-block",
1488
+ width: "max-content",
1489
+ padding: 32,
1490
+ color: ce,
1491
+ background: ae
1492
+ },
1493
+ children: [
1494
+ /* @__PURE__ */ w("strong", { children: e.name }),
1495
+ /* @__PURE__ */ w("p", { style: { color: _ }, children: "The component is not registered." })
1496
+ ]
1497
+ }
1498
+ );
1499
+ const n = en(t, r), o = ((c = n.row) == null ? void 0 : c[1]) ?? [void 0], s = ((d = n.column) == null ? void 0 : d[1]) ?? [void 0], a = t.component;
1500
+ return /* @__PURE__ */ O(
1501
+ "section",
1502
+ {
1503
+ "data-pygmalion-catalog-component": e.id,
1504
+ "data-pygmalion-content-bounds": "",
1505
+ style: {
1506
+ boxSizing: "border-box",
1507
+ display: "inline-block",
1508
+ width: "max-content",
1509
+ padding: 32,
1510
+ color: ce,
1511
+ background: ae,
1512
+ fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif"
1513
+ },
1514
+ children: [
1515
+ /* @__PURE__ */ O("header", { style: { marginBottom: 24 }, children: [
1516
+ /* @__PURE__ */ w("h1", { style: { margin: 0, fontSize: 24 }, children: e.name }),
1517
+ e.sourcePath ? /* @__PURE__ */ w("p", { style: { margin: "6px 0 0", color: _, fontSize: 12 }, children: e.sourcePath }) : null
1518
+ ] }),
1519
+ /* @__PURE__ */ w(
1520
+ "div",
1521
+ {
1522
+ style: {
1523
+ display: "inline-grid",
1524
+ gridTemplateColumns: `repeat(${s.length}, max-content)`,
1525
+ gap: 12
1526
+ },
1527
+ children: o.flatMap(
1528
+ (h) => s.map((u) => {
1529
+ const b = tn(t, n, h, u), P = [
1530
+ n.row && h ? `${n.row[0]}=${h}` : "",
1531
+ n.column && u ? `${n.column[0]}=${u}` : ""
1532
+ ].filter(Boolean).join(" · ");
1533
+ return /* @__PURE__ */ O(
1534
+ "article",
1535
+ {
1536
+ style: {
1537
+ width: "max-content",
1538
+ padding: 16,
1539
+ border: `1px solid ${me}`,
1540
+ borderRadius: 10,
1541
+ background: ie
1542
+ },
1543
+ children: [
1544
+ P ? /* @__PURE__ */ w("div", { style: { marginBottom: 12, color: _, fontSize: 11 }, children: P }) : null,
1545
+ /* @__PURE__ */ w("div", { style: { display: "flex", minHeight: 44, alignItems: "center" }, children: xe(
1546
+ a,
1547
+ b,
1548
+ t.children === "text" ? t.defaultChildren ?? e.name : void 0
1549
+ ) })
1550
+ ]
1551
+ },
1552
+ `${h ?? "default"}:${u ?? "default"}`
1553
+ );
1554
+ })
1555
+ )
1556
+ }
1557
+ ),
1558
+ n.additional.map(([h, u]) => /* @__PURE__ */ O("section", { style: { marginTop: 20 }, children: [
1559
+ /* @__PURE__ */ w("h2", { style: { margin: "0 0 10px", color: _, fontSize: 12 }, children: h }),
1560
+ /* @__PURE__ */ w("div", { style: { display: "flex", flexWrap: "wrap", gap: 12 }, children: u.map((b) => /* @__PURE__ */ O(
1561
+ "article",
1562
+ {
1563
+ style: {
1564
+ padding: 16,
1565
+ border: `1px solid ${me}`,
1566
+ borderRadius: 10,
1567
+ background: ie
1568
+ },
1569
+ children: [
1570
+ /* @__PURE__ */ w("div", { style: { marginBottom: 12, color: _, fontSize: 11 }, children: b }),
1571
+ xe(
1572
+ a,
1573
+ { ...t.defaultProps, [h]: b },
1574
+ t.children === "text" ? t.defaultChildren ?? e.name : void 0
1575
+ )
1576
+ ]
1577
+ },
1578
+ b
1579
+ )) })
1580
+ ] }, h))
1581
+ ]
1582
+ }
1583
+ );
1584
+ }
1585
+ function In(e) {
1586
+ Ue(e.items);
1587
+ const t = {}, r = [], n = [], o = e.maxVariantCells ?? 60;
1588
+ for (const s of e.items) {
1589
+ const a = je(
1590
+ e.kind,
1591
+ s.id,
1592
+ e.registryPrefix
1593
+ ), c = e.registry[s.name], d = () => /* @__PURE__ */ w(
1594
+ nn,
1595
+ {
1596
+ item: s,
1597
+ entry: c,
1598
+ maxVariantCells: o
1599
+ }
1600
+ );
1601
+ t[a] = { component: d, children: "none" }, r.push({
1602
+ id: s.id,
1603
+ name: s.name,
1604
+ section: s.section,
1605
+ componentName: a,
1606
+ // The seed exists only long enough to mount the intrinsic max-content
1607
+ // catalog root. The editor replaces it with actual rendered DOM bounds.
1608
+ width: 1,
1609
+ height: 1,
1610
+ frameSizeMode: "content"
1611
+ }), n.push(Be(s, s.id));
1612
+ }
1613
+ return {
1614
+ registry: t,
1615
+ collection: {
1616
+ expectedCount: e.expectedCount ?? e.items.length,
1617
+ assets: n,
1618
+ pages: r
1619
+ }
1620
+ };
1621
+ }
1622
+ const Ae = /^[a-f0-9]{64}$/, rn = /^\/__pygmalion-qa\/artifacts\/[A-Za-z0-9_-]{8,120}\.png$/, on = /^p\d+$/;
1623
+ function ge(e) {
1624
+ return typeof e == "string" && rn.test(e) ? e : void 0;
1625
+ }
1626
+ function Oe(e, t) {
1627
+ const r = new URL(e, t);
1628
+ return r.search = "", r.hash = "", r.pathname.endsWith("/") || (r.pathname = `${r.pathname}/`), r.href;
1629
+ }
1630
+ function fe(e) {
1631
+ if (!e || typeof e != "object" || Array.isArray(e)) return null;
1632
+ const t = e;
1633
+ return typeof t.domStructureHash != "string" || !Ae.test(t.domStructureHash) || typeof t.screenshotHash != "string" || !Ae.test(t.screenshotHash) ? null : {
1634
+ domStructureHash: t.domStructureHash,
1635
+ screenshotHash: t.screenshotHash,
1636
+ ...ge(t.screenshotUrl) ? { screenshotUrl: ge(t.screenshotUrl) } : {}
1637
+ };
1638
+ }
1639
+ function $e(e) {
1640
+ if (!e || typeof e != "object" || Array.isArray(e)) return null;
1641
+ const t = e;
1642
+ return !Number.isSafeInteger(t.width) || !Number.isSafeInteger(t.height) || Number(t.width) < 1 || Number(t.height) < 1 || Number(t.width) > 65536 || Number(t.height) > 65536 ? null : { width: Number(t.width), height: Number(t.height) };
1643
+ }
1644
+ function sn(e) {
1645
+ if (!e || typeof e != "object" || Array.isArray(e)) return null;
1646
+ const t = e, r = $e(t.before), n = $e(t.after);
1647
+ if (!r || !n || !Number.isSafeInteger(t.changedPixels) || !Number.isSafeInteger(t.totalPixels) || Number(t.changedPixels) < 0 || Number(t.totalPixels) < 1 || Number(t.changedPixels) > Number(t.totalPixels) || typeof t.threshold != "number" || !Number.isFinite(t.threshold) || t.threshold < 0 || t.threshold > 1)
1648
+ return null;
1649
+ const o = t.heatmapUrl == null ? null : ge(t.heatmapUrl) ?? null;
1650
+ return {
1651
+ before: r,
1652
+ after: n,
1653
+ dimensionsMatch: r.width === n.width && r.height === n.height,
1654
+ changedPixels: Number(t.changedPixels),
1655
+ totalPixels: Number(t.totalPixels),
1656
+ diffRatio: Number(t.changedPixels) / Number(t.totalPixels),
1657
+ threshold: t.threshold,
1658
+ heatmapUrl: o
1659
+ };
1660
+ }
1661
+ function an(e, t) {
1662
+ if (!e || typeof e != "object" || Array.isArray(e)) return null;
1663
+ const r = e;
1664
+ if (typeof r.id != "string" || !r.id) return null;
1665
+ const n = fe(r), o = fe(r.before) ?? n;
1666
+ if (!o) return null;
1667
+ const s = fe(r.after);
1668
+ if (t === "changed" && !s) return null;
1669
+ const a = s ? sn(r.pixelDiff) : null;
1670
+ return {
1671
+ id: r.id,
1672
+ before: o,
1673
+ ...s ? { after: s } : {},
1674
+ ...s ? {
1675
+ domChanged: o.domStructureHash !== s.domStructureHash,
1676
+ screenshotChanged: o.screenshotHash !== s.screenshotHash
60
1677
  } : {},
61
- ...h ? { pixelDiff: h } : {}
1678
+ ...a ? { pixelDiff: a } : {}
62
1679
  };
63
1680
  }
64
- function ke(r, e = []) {
65
- const s = new Set(e), i = s.size > 0, t = /* @__PURE__ */ new Set(), d = [
66
- ...r.styles.map((h) => h.affectedFrames ?? []),
67
- ...r.texts.map((h) => h.affectedFrames ?? []),
68
- ...r.operations.map((h) => h.affectedFrames ?? [])
1681
+ function cn(e, t = []) {
1682
+ const r = new Set(t), n = r.size > 0, o = /* @__PURE__ */ new Set(), s = [
1683
+ ...e.styles.map((a) => a.affectedFrames ?? []),
1684
+ ...e.texts.map((a) => a.affectedFrames ?? []),
1685
+ ...e.operations.map((a) => a.affectedFrames ?? [])
69
1686
  ];
70
- for (const h of d)
71
- for (const u of h) {
72
- if (i && _e.test(u.id) && !s.has(u.id))
1687
+ for (const a of s)
1688
+ for (const c of a) {
1689
+ if (n && on.test(c.id) && !r.has(c.id))
73
1690
  throw new Error(
74
- `"Impact Screen"${u.name}"This internal editor ID (${u.id}) is used. A canonical screen ID is required.`
1691
+ `"Impact Screen"${c.name}"This internal editor ID (${c.id}) is used. A canonical screen ID is required.`
75
1692
  );
76
- !u.id || i && !s.has(u.id) || t.add(u.id);
1693
+ !c.id || n && !r.has(c.id) || o.add(c.id);
77
1694
  }
78
- return [...t].sort();
1695
+ return [...o].sort();
79
1696
  }
80
- async function ie(r, e, s) {
81
- const i = await r(`${e.replace(/\/$/, "")}/capture`, {
1697
+ async function Me(e, t, r) {
1698
+ const n = await e(`${t.replace(/\/$/, "")}/capture`, {
82
1699
  method: "POST",
83
1700
  headers: { "content-type": "application/json" },
84
- body: JSON.stringify(s)
85
- }), t = await i.json();
86
- if (!i.ok || t.ok === !1)
1701
+ body: JSON.stringify(r)
1702
+ }), o = await n.json();
1703
+ if (!n.ok || o.ok === !1)
87
1704
  throw new Error(
88
- typeof t.error == "string" ? t.error : `Pygmalion visual QA capture failed (${i.status})`
1705
+ typeof o.error == "string" ? o.error : `Pygmalion visual QA capture failed (${n.status})`
89
1706
  );
90
- if (typeof t.baselineId != "string" || !t.baselineId)
1707
+ if (typeof o.baselineId != "string" || !o.baselineId)
91
1708
  throw new Error("Pygmalion visual QA response has no baselineId");
92
- const d = Array.isArray(t.frames) ? t.frames.map((c) => Fe(c, s.phase)).filter((c) => c != null) : [], h = Array.isArray(t.failures) ? t.failures.map((c) => {
93
- if (!c || typeof c != "object" || Array.isArray(c)) return null;
94
- const g = c;
95
- return typeof g.id == "string" && typeof g.error == "string" ? { id: g.id, error: g.error } : null;
96
- }).filter((c) => c != null) : [], u = new Set(s.frameIds), I = new Set(d.map((c) => c.id)).size === d.length && d.every((c) => u.has(c.id)) && h.every((c) => u.has(c.id));
1709
+ const s = Array.isArray(o.frames) ? o.frames.map((u) => an(u, r.phase)).filter((u) => u != null) : [], a = Array.isArray(o.failures) ? o.failures.map((u) => {
1710
+ if (!u || typeof u != "object" || Array.isArray(u)) return null;
1711
+ const b = u;
1712
+ return typeof b.id == "string" && typeof b.error == "string" ? { id: b.id, error: b.error } : null;
1713
+ }).filter((u) => u != null) : [], c = new Set(r.frameIds), h = new Set(s.map((u) => u.id)).size === s.length && s.every((u) => c.has(u.id)) && a.every((u) => c.has(u.id));
97
1714
  return {
98
- phase: s.phase,
99
- baselineId: t.baselineId,
100
- complete: t.complete !== !1 && I && h.length === 0 && d.length === s.frameIds.length,
101
- frames: d,
102
- failures: h
1715
+ phase: r.phase,
1716
+ baselineId: o.baselineId,
1717
+ complete: o.complete !== !1 && h && a.length === 0 && s.length === r.frameIds.length,
1718
+ frames: s,
1719
+ failures: a
103
1720
  };
104
1721
  }
105
- const G = {
1722
+ const ue = {
106
1723
  mirror: "/__pygmalion-dev-control",
107
1724
  sessions: "/__pygmalion-design-session",
108
1725
  inspect: "/__pygmalion-inspect"
109
- }, $e = "pygmalion.designSessionId", Ce = "/__pygmalion-qa", J = /* @__PURE__ */ new Map();
110
- function ae() {
111
- var r;
112
- return typeof window < "u" && ((r = window.crypto) != null && r.randomUUID) ? window.crypto.randomUUID() : `pygmalion-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1726
+ }, ln = "pygmalion.designSessionId", dn = "/__pygmalion-qa", ne = /* @__PURE__ */ new Map();
1727
+ function Te() {
1728
+ var e;
1729
+ return typeof window < "u" && ((e = window.crypto) != null && e.randomUUID) ? window.crypto.randomUUID() : `pygmalion-${Date.now()}-${Math.random().toString(36).slice(2)}`;
113
1730
  }
114
- function je(r, e) {
1731
+ function fn(e, t) {
1732
+ if (e) return e;
1733
+ const r = ne.get(t);
115
1734
  if (r) return r;
116
- const s = J.get(e);
117
- if (s) return s;
118
1735
  try {
119
- const i = window.localStorage.getItem(e);
120
- if (i)
121
- return J.set(e, i), i;
122
- const t = ae();
123
- return window.localStorage.setItem(e, t), J.set(e, t), t;
1736
+ const n = window.localStorage.getItem(t);
1737
+ if (n)
1738
+ return ne.set(t, n), n;
1739
+ const o = Te();
1740
+ return window.localStorage.setItem(t, o), ne.set(t, o), o;
124
1741
  } catch {
125
- const i = ae();
126
- return J.set(e, i), i;
1742
+ const n = Te();
1743
+ return ne.set(t, n), n;
127
1744
  }
128
1745
  }
129
- async function O(r) {
130
- const e = await r.json();
131
- if (!r.ok) throw new Error(e.error ?? `Pygmalion request failed (${r.status})`);
132
- return e;
1746
+ async function L(e) {
1747
+ const t = await e.json();
1748
+ if (!e.ok) throw new Error(t.error ?? `Pygmalion request failed (${e.status})`);
1749
+ return t;
133
1750
  }
134
- function Je(r = {}) {
135
- var $, C, q, Y, W;
1751
+ function xn(e = {}) {
1752
+ var G, x, j, k, Q;
136
1753
  const {
137
- sessionId: e,
138
- sessionStorageKey: s = $e,
139
- autoStart: i = !0,
140
- fetcher: t = fetch,
141
- formatApplyMessage: d
142
- } = r, h = (($ = r.endpoints) == null ? void 0 : $.mirror) ?? G.mirror, u = ((C = r.endpoints) == null ? void 0 : C.sessions) ?? G.sessions, A = ((q = r.endpoints) == null ? void 0 : q.inspect) ?? G.inspect, I = r.visualQa != null, c = ((Y = r.visualQa) == null ? void 0 : Y.endpoint) ?? Ce, g = JSON.stringify(((W = r.visualQa) == null ? void 0 : W.eligibleFrameIds) ?? []), x = ee(
143
- () => JSON.parse(g),
144
- [g]
145
- ), H = ee(
146
- () => je(e, s),
147
- [e, s]
148
- ), [S, F] = Q({
1754
+ sessionId: t,
1755
+ sessionStorageKey: r = ln,
1756
+ autoStart: n = !0,
1757
+ fetcher: o = fetch,
1758
+ formatApplyMessage: s
1759
+ } = e, a = ((G = e.endpoints) == null ? void 0 : G.mirror) ?? ue.mirror, c = ((x = e.endpoints) == null ? void 0 : x.sessions) ?? ue.sessions, d = ((j = e.endpoints) == null ? void 0 : j.inspect) ?? ue.inspect, h = e.visualQa != null, u = ((k = e.visualQa) == null ? void 0 : k.endpoint) ?? dn, b = JSON.stringify(((Q = e.visualQa) == null ? void 0 : Q.eligibleFrameIds) ?? []), P = Pe(
1760
+ () => JSON.parse(b),
1761
+ [b]
1762
+ ), E = Pe(
1763
+ () => fn(t, r),
1764
+ [t, r]
1765
+ ), [m, N] = te({
149
1766
  state: "idle",
150
1767
  commit: null,
151
1768
  shortCommit: null,
@@ -154,309 +1771,344 @@ function Je(r = {}) {
154
1771
  warning: null,
155
1772
  error: null,
156
1773
  appOrigin: null
157
- }), [n, k] = Q(null), [R, D] = Q(null), E = re(null), y = re(null), T = j(
158
- async (o = !0) => {
159
- if (E.current) return E.current;
160
- const a = (async () => {
161
- F((l) => ({ ...l, state: "syncing", error: null }));
1774
+ }), [p, $] = te(null), [R, T] = te(null), M = Ee(null), A = Ee(null), S = Z(
1775
+ async (v = !0) => {
1776
+ if (M.current) return M.current;
1777
+ const g = (async () => {
1778
+ N((I) => ({ ...I, state: "syncing", error: null }));
162
1779
  try {
163
- let l = await t(`${h}/${o ? "refresh" : "status"}`, {
164
- method: o ? "POST" : "GET"
165
- }), f = await O(l);
166
- const w = Date.now();
167
- for (; !o && f.state === "syncing" && Date.now() - w < 12e4; )
168
- await new Promise((P) => window.setTimeout(P, 500)), l = await t(`${h}/status`), f = await O(l);
169
- if (f.state !== "ready" || !f.appOrigin || !f.commit)
170
- throw new Error(f.error ?? "Pygmalion could not prepare the source preview");
171
- const m = await O(
172
- await t(`${u}/open`, {
1780
+ let I = await o(`${a}/${v ? "refresh" : "status"}`, {
1781
+ method: v ? "POST" : "GET"
1782
+ }), i = await L(I);
1783
+ const l = Date.now();
1784
+ for (; !v && i.state === "syncing" && Date.now() - l < 12e4; )
1785
+ await new Promise((D) => window.setTimeout(D, 500)), I = await o(`${a}/status`), i = await L(I);
1786
+ if (i.state !== "ready" || !i.appOrigin || !i.commit)
1787
+ throw new Error(i.error ?? "Pygmalion could not prepare the source preview");
1788
+ const f = await L(
1789
+ await o(`${c}/open`, {
173
1790
  method: "POST",
174
1791
  headers: { "content-type": "application/json" },
175
- body: JSON.stringify({ sessionId: H, baseDevSha: f.commit })
1792
+ body: JSON.stringify({ sessionId: E, baseDevSha: i.commit })
176
1793
  })
177
1794
  );
178
- if (!m.ok || !m.session)
179
- throw new Error(m.error ?? "Pygmalion could not open the design session");
180
- let b = m.session;
181
- if (b.branchName) {
182
- const P = await O(
183
- await t(`${u}/check`, {
1795
+ if (!f.ok || !f.session)
1796
+ throw new Error(f.error ?? "Pygmalion could not open the design session");
1797
+ let y = f.session;
1798
+ if (y.branchName) {
1799
+ const D = await L(
1800
+ await o(`${c}/check`, {
184
1801
  method: "POST",
185
1802
  headers: { "content-type": "application/json" },
186
- body: JSON.stringify({ sessionId: b.id })
1803
+ body: JSON.stringify({ sessionId: y.id })
187
1804
  })
188
1805
  );
189
- if (!P.ok || !P.session)
190
- throw new Error(P.error ?? "Pygmalion could not check the design session");
191
- b = P.session;
1806
+ if (!D.ok || !D.session)
1807
+ throw new Error(D.error ?? "Pygmalion could not check the design session");
1808
+ y = D.session;
192
1809
  }
193
- F(f), k(b), D(b.appOrigin ?? f.appOrigin);
194
- } catch (l) {
195
- F((f) => ({
196
- ...f,
1810
+ N(i), $(y), T(y.appOrigin ?? i.appOrigin);
1811
+ } catch (I) {
1812
+ N((i) => ({
1813
+ ...i,
197
1814
  state: "error",
198
- error: l instanceof Error ? l.message : String(l)
1815
+ error: I instanceof Error ? I.message : String(I)
199
1816
  }));
200
1817
  }
201
1818
  })();
202
- E.current = a;
1819
+ M.current = g;
203
1820
  try {
204
- await a;
1821
+ await g;
205
1822
  } finally {
206
- E.current === a && (E.current = null);
1823
+ M.current === g && (M.current = null);
207
1824
  }
208
1825
  },
209
- [t, h, u, H]
210
- ), U = j(
211
- async (o) => {
212
- var m;
213
- if (!n) throw new Error("Pygmalion design session is not ready");
214
- const a = y.current;
215
- if (a && (a.sessionId !== n.id || a.baseDevSha !== n.baseDevSha || a.revision !== n.revision || a.fingerprint !== JSON.stringify(o)))
1826
+ [o, a, c, E]
1827
+ ), C = Z(
1828
+ async (v) => {
1829
+ var f;
1830
+ if (!p) throw new Error("Pygmalion design session is not ready");
1831
+ const g = A.current;
1832
+ if (g && (g.sessionId !== p.id || g.baseDevSha !== p.baseDevSha || g.revision !== p.revision || g.fingerprint !== JSON.stringify(v)))
216
1833
  throw new Error("The code diff you checked is out of date. Please check the diff for the current changes again.");
217
- const l = await O(
218
- await t(`${u}/apply-visual`, {
1834
+ const I = await L(
1835
+ await o(`${c}/apply-visual`, {
219
1836
  method: "POST",
220
1837
  headers: { "content-type": "application/json" },
221
1838
  body: JSON.stringify({
222
- sessionId: n.id,
223
- baseDevSha: n.baseDevSha,
224
- expectedRevision: n.revision,
225
- ...a ? { previewRevision: a.revision } : {},
226
- changes: o
1839
+ sessionId: p.id,
1840
+ baseDevSha: p.baseDevSha,
1841
+ expectedRevision: p.revision,
1842
+ ...g ? { previewRevision: g.revision } : {},
1843
+ changes: v
227
1844
  })
228
1845
  })
229
1846
  );
230
- if (!l.ok || !l.session)
231
- throw new Error(l.error ?? "Pygmalion could not apply the visual changes");
232
- k(l.session), l.session.appOrigin && D(l.session.appOrigin);
233
- const f = l.applied ?? o.styles.length + o.texts.length + o.operations.length;
234
- let w;
235
- if (a != null && a.qaBaselineId && ((m = a.qaFrameIds) != null && m.length) && l.session.appOrigin)
1847
+ if (!I.ok || !I.session)
1848
+ throw new Error(I.error ?? "Pygmalion could not apply the visual changes");
1849
+ $(I.session), I.session.appOrigin && T(I.session.appOrigin);
1850
+ const i = I.applied ?? v.styles.length + v.texts.length + v.operations.length;
1851
+ let l;
1852
+ if (g != null && g.qaBaselineId && ((f = g.qaFrameIds) != null && f.length) && I.session.appOrigin)
236
1853
  try {
237
- w = await ie(t, c, {
1854
+ l = await Me(o, u, {
238
1855
  phase: "changed",
239
- baselineId: a.qaBaselineId,
240
- basePath: ne(l.session.appOrigin, window.location.origin),
241
- frameIds: a.qaFrameIds
1856
+ baselineId: g.qaBaselineId,
1857
+ basePath: Oe(I.session.appOrigin, window.location.origin),
1858
+ frameIds: g.qaFrameIds
242
1859
  });
243
- } catch (b) {
244
- const P = b instanceof Error ? b.message : String(b);
245
- w = {
1860
+ } catch (y) {
1861
+ const D = y instanceof Error ? y.message : String(y);
1862
+ l = {
246
1863
  phase: "changed",
247
- baselineId: a.qaBaselineId,
1864
+ baselineId: g.qaBaselineId,
248
1865
  complete: !1,
249
1866
  frames: [],
250
- failures: a.qaFrameIds.map((oe) => ({ id: oe, error: P }))
1867
+ failures: g.qaFrameIds.map((H) => ({ id: H, error: D }))
251
1868
  };
252
1869
  }
253
- return y.current = null, {
254
- applied: f,
255
- branch: l.session.branchName ?? void 0,
256
- integration: l.session.integration.state,
257
- message: d == null ? void 0 : d(l.session, f),
258
- ...w ? { qa: w } : {}
1870
+ return A.current = null, {
1871
+ applied: i,
1872
+ branch: I.session.branchName ?? void 0,
1873
+ integration: I.session.integration.state,
1874
+ message: s == null ? void 0 : s(I.session, i),
1875
+ ...l ? { qa: l } : {}
259
1876
  };
260
1877
  },
261
- [t, d, c, n, u]
262
- ), _ = j(
263
- async (o) => {
264
- var m;
265
- if (!n) throw new Error("Pygmalion design session is not ready");
266
- y.current = null;
267
- const a = await O(
268
- await t(`${u}/preview-visual`, {
1878
+ [o, s, u, p, c]
1879
+ ), F = Z(
1880
+ async (v) => {
1881
+ var f;
1882
+ if (!p) throw new Error("Pygmalion design session is not ready");
1883
+ A.current = null;
1884
+ const g = await L(
1885
+ await o(`${c}/preview-visual`, {
269
1886
  method: "POST",
270
1887
  headers: { "content-type": "application/json" },
271
1888
  body: JSON.stringify({
272
- sessionId: n.id,
273
- baseDevSha: n.baseDevSha,
274
- expectedRevision: n.revision,
275
- changes: o
1889
+ sessionId: p.id,
1890
+ baseDevSha: p.baseDevSha,
1891
+ expectedRevision: p.revision,
1892
+ changes: v
276
1893
  })
277
1894
  })
278
1895
  );
279
- if (!a.ok || !Number.isSafeInteger(a.revision))
280
- throw new Error(a.error ?? "Pygmalion could not preview the visual changes");
281
- const l = I ? ke(o, x) : [];
282
- let f;
283
- const w = n.appOrigin ?? S.appOrigin;
284
- if (l.length > 0) {
285
- if (!w)
1896
+ if (!g.ok || !Number.isSafeInteger(g.revision))
1897
+ throw new Error(g.error ?? "Pygmalion could not preview the visual changes");
1898
+ const I = h ? cn(v, P) : [];
1899
+ let i;
1900
+ const l = p.appOrigin ?? m.appOrigin;
1901
+ if (I.length > 0) {
1902
+ if (!l)
286
1903
  throw new Error("Impact screen QA baseline preview not ready");
287
- if (f = await ie(t, c, {
1904
+ if (i = await Me(o, u, {
288
1905
  phase: "baseline",
289
- basePath: ne(w, window.location.origin),
290
- frameIds: l
291
- }), !f.complete)
1906
+ basePath: Oe(l, window.location.origin),
1907
+ frameIds: I
1908
+ }), !i.complete)
292
1909
  throw new Error(
293
- ((m = f.failures[0]) == null ? void 0 : m.error) ?? `Failed to capture ${l.length - f.frames.length} affected frames`
1910
+ ((f = i.failures[0]) == null ? void 0 : f.error) ?? `Failed to capture ${I.length - i.frames.length} affected frames`
294
1911
  );
295
1912
  }
296
- return y.current = {
297
- sessionId: n.id,
298
- baseDevSha: n.baseDevSha,
299
- revision: a.revision,
300
- fingerprint: JSON.stringify(o),
301
- ...f ? { qaBaselineId: f.baselineId, qaFrameIds: l } : {}
1913
+ return A.current = {
1914
+ sessionId: p.id,
1915
+ baseDevSha: p.baseDevSha,
1916
+ revision: g.revision,
1917
+ fingerprint: JSON.stringify(v),
1918
+ ...i ? { qaBaselineId: i.baselineId, qaFrameIds: I } : {}
302
1919
  }, {
303
- revision: a.revision,
304
- files: Array.isArray(a.files) ? a.files : [],
305
- affectedFiles: Array.isArray(a.affectedFiles) ? a.affectedFiles : [],
306
- ...f ? { qa: f } : {}
1920
+ revision: g.revision,
1921
+ files: Array.isArray(g.files) ? g.files : [],
1922
+ affectedFiles: Array.isArray(g.affectedFiles) ? g.affectedFiles : [],
1923
+ ...i ? { qa: i } : {}
307
1924
  };
308
1925
  },
309
1926
  [
310
- t,
311
- S.appOrigin,
312
- x,
313
- c,
314
- n,
1927
+ o,
1928
+ m.appOrigin,
1929
+ P,
315
1930
  u,
316
- I
1931
+ p,
1932
+ c,
1933
+ h
317
1934
  ]
318
- ), p = j(
319
- async (o) => {
320
- if (o.length === 0) return { files: [] };
321
- const a = await O(
322
- await t(`${A}/impact`, {
1935
+ ), B = Z(
1936
+ async (v) => {
1937
+ if (v.length === 0) return { files: [] };
1938
+ const g = await L(
1939
+ await o(`${d}/impact`, {
323
1940
  method: "POST",
324
1941
  headers: { "content-type": "application/json" },
325
- body: JSON.stringify({ componentFiles: o })
1942
+ body: JSON.stringify({ componentFiles: v })
326
1943
  })
327
1944
  );
328
- if (a.error || a.ok === !1)
329
- throw new Error(a.error ?? "Pygmalion could not calculate source impact");
330
- return { files: Array.isArray(a.files) ? a.files : [] };
1945
+ if (g.error || g.ok === !1)
1946
+ throw new Error(g.error ?? "Pygmalion could not calculate source impact");
1947
+ return { files: Array.isArray(g.files) ? g.files : [] };
331
1948
  },
332
- [t, A]
333
- ), N = j(async () => {
334
- if (!(n != null && n.canRevert) || !n.headSha)
1949
+ [o, d]
1950
+ ), W = Z(async () => {
1951
+ if (!(p != null && p.canRevert) || !p.headSha)
335
1952
  throw new Error("There are no reversible changes applied");
336
- const o = await O(
337
- await t(`${u}/revert-visual`, {
1953
+ const v = await L(
1954
+ await o(`${c}/revert-visual`, {
338
1955
  method: "POST",
339
1956
  headers: { "content-type": "application/json" },
340
1957
  body: JSON.stringify({
341
- sessionId: n.id,
342
- baseDevSha: n.baseDevSha,
343
- expectedRevision: n.revision,
344
- expectedHeadSha: n.headSha
1958
+ sessionId: p.id,
1959
+ baseDevSha: p.baseDevSha,
1960
+ expectedRevision: p.revision,
1961
+ expectedHeadSha: p.headSha
345
1962
  })
346
1963
  })
347
1964
  );
348
- if (!o.ok || o.reverted !== !0 || !o.operation || o.operation.kind !== "visual-revert" || !o.session)
349
- throw new Error(o.error ?? "Pygmalion could not revert the last visual change");
350
- return y.current = null, k(o.session), o.session.appOrigin && D(o.session.appOrigin), {
1965
+ if (!v.ok || v.reverted !== !0 || !v.operation || v.operation.kind !== "visual-revert" || !v.session)
1966
+ throw new Error(v.error ?? "Pygmalion could not revert the last visual change");
1967
+ return A.current = null, $(v.session), v.session.appOrigin && T(v.session.appOrigin), {
351
1968
  reverted: !0,
352
- operation: o.operation,
353
- session: o.session
1969
+ operation: v.operation,
1970
+ session: v.session
354
1971
  };
355
- }, [t, n, u]);
356
- B(() => {
357
- i && T(!1);
358
- }, [i, T]);
359
- const M = (n == null ? void 0 : n.appOrigin) ?? S.appOrigin ?? R;
1972
+ }, [o, p, c]);
1973
+ ee(() => {
1974
+ n && S(!1);
1975
+ }, [n, S]);
1976
+ const q = (p == null ? void 0 : p.appOrigin) ?? m.appOrigin ?? R;
360
1977
  return {
361
- mirror: S,
362
- session: n,
1978
+ mirror: m,
1979
+ session: p,
363
1980
  ready: R != null,
364
- appOrigin: M,
365
- previewRevision: `${(n == null ? void 0 : n.headSha) ?? (n == null ? void 0 : n.baseDevSha) ?? S.commit ?? "pending"}:${(n == null ? void 0 : n.revision) ?? 0}`,
366
- refresh: T,
367
- previewVisual: _,
368
- inspectImpact: p,
369
- applyVisual: U,
370
- revertLastVisual: N
1981
+ appOrigin: q,
1982
+ previewRevision: `${(p == null ? void 0 : p.headSha) ?? (p == null ? void 0 : p.baseDevSha) ?? m.commit ?? "pending"}:${(p == null ? void 0 : p.revision) ?? 0}`,
1983
+ refresh: S,
1984
+ previewVisual: F,
1985
+ inspectImpact: B,
1986
+ applyVisual: C,
1987
+ revertLastVisual: W
371
1988
  };
372
1989
  }
373
- const Qe = { editor: v, getObserverTree: ce, isObservableProp: le };
374
- function Be(r) {
375
- v.navigateToPageByName(r);
376
- }
377
- function Me() {
378
- v.openPreview();
379
- }
380
- function Le() {
381
- const r = K.entries.length > 0;
382
- return r && K.discardPending(), v.resetCurrentEdits() || r;
383
- }
384
- function ze({
385
- registry: r,
386
- tokens: e,
387
- initialPages: s,
388
- designImport: i,
389
- onTokensChange: t,
390
- appOrigin: d,
391
- previewRevision: h,
392
- previewCacheNamespace: u,
393
- previewArtifacts: A,
394
- previewConcurrency: I,
395
- previewOpen: c,
396
- onPreviewOpenChange: g,
397
- flowCanvas: x,
398
- onApply: H,
399
- onDesignChange: S,
400
- onInspectApply: F,
401
- onInspectPreview: n,
402
- onInspectImpact: k,
403
- storyboardDiscovery: R = !0,
404
- storyboardDiscoveryEndpoint: D = Se
1990
+ const Pn = {
1991
+ editor: K,
1992
+ getObserverTree: Le,
1993
+ isObservableProp: Ge
1994
+ };
1995
+ function En(e) {
1996
+ K.navigateToPageByName(e);
1997
+ }
1998
+ function Nn() {
1999
+ K.openPreview();
2000
+ }
2001
+ function Cn() {
2002
+ const e = ve.entries.length > 0;
2003
+ return e && ve.discardPending(), K.resetCurrentEdits() || e;
2004
+ }
2005
+ function Rn({
2006
+ registry: e,
2007
+ tokens: t,
2008
+ initialPages: r,
2009
+ designImport: n,
2010
+ onTokensChange: o,
2011
+ appOrigin: s,
2012
+ previewRevision: a,
2013
+ previewCacheNamespace: c,
2014
+ previewArtifacts: d,
2015
+ previewArtifactEndpoint: h,
2016
+ previewConcurrency: u,
2017
+ previewOpen: b,
2018
+ onPreviewOpenChange: P,
2019
+ flowCanvas: E,
2020
+ onApply: m,
2021
+ onDesignChange: N,
2022
+ onInspectApply: p,
2023
+ onInspectPreview: $,
2024
+ onInspectImpact: R,
2025
+ storyboardDiscovery: T = !0,
2026
+ storyboardDiscoveryEndpoint: M = st
405
2027
  }) {
406
- const [E, y] = Q(!R);
407
- i && (i.assertComplete(), de(i));
408
- const T = r ?? (i == null ? void 0 : i.getRegistry()), U = e ?? (i == null ? void 0 : i.getTokens()), _ = s ?? (i == null ? void 0 : i.getInitialPages());
409
- return T && ue(T), U && fe(U), Oe(t ?? null), d != null && he(d), h != null && pe(h), me(u), A && _ && ge(A, {
410
- namespace: u ?? "",
411
- previewRevision: Ee(),
412
- appOrigin: Ie(),
413
- pages: _.flatMap(
414
- (p) => p.route && p.importPageId ? [
2028
+ const [A, S] = te(!T), [C, F] = te();
2029
+ n && (n.assertComplete(), Ve(n));
2030
+ const B = e ?? (n == null ? void 0 : n.getRegistry()), W = t ?? (n == null ? void 0 : n.getTokens()), q = r ?? (n == null ? void 0 : n.getInitialPages());
2031
+ B && Je(B), W && We(W), at(o ?? null), s != null && Qe(s), a != null && Xe(a), Ye(c);
2032
+ const G = C ?? d;
2033
+ return G && q && A && Ze(G, {
2034
+ namespace: c ?? "",
2035
+ previewRevision: lt(),
2036
+ appOrigin: ct(),
2037
+ baselineEnvironment: et(),
2038
+ pages: q.flatMap(
2039
+ (x) => x.route && x.importPageId ? [
415
2040
  {
416
- canonicalId: p.importPageId,
417
- route: p.route,
418
- width: p.width,
419
- height: p.height,
420
- environment: p.environment,
421
- preset: p.preset,
422
- interactions: p.interactions,
423
- assertions: p.assertions
2041
+ canonicalId: x.importPageId,
2042
+ route: x.route,
2043
+ width: x.width,
2044
+ height: x.height,
2045
+ environment: x.environment,
2046
+ preset: x.preset,
2047
+ interactions: x.interactions,
2048
+ assertions: x.assertions
424
2049
  }
425
2050
  ] : []
426
2051
  )
427
- }), I != null && ye(I), Ne(g ?? null), x != null && we(x), Ae(H ?? null), Re(F ?? null), be(n ?? null), De(k ?? null), _ && v.initPagesFromComponents(_), B(() => {
428
- X(S ?? null);
429
- const p = ve(v);
2052
+ }), u != null && tt(u), dt(P ?? null), E != null && nt(E), ft(m ?? null), ut(p ?? null), rt($ ?? null), pt(R ?? null), q && K.initPagesFromComponents(q), ee(() => {
2053
+ Ie(N ?? null);
2054
+ const x = ot(K);
430
2055
  return () => {
431
- p(), X(null);
2056
+ x(), Ie(null);
432
2057
  };
433
- }, [S]), B(() => {
434
- let p = !0;
435
- return R ? (y(!1), fetch(D, {
436
- headers: { accept: "application/json" },
437
- cache: "no-store"
438
- }).then(async (N) => {
439
- if (!N.ok) throw new Error(`Storyboard discovery failed (${N.status})`);
440
- return N.json();
441
- }).then((N) => {
442
- var $, C;
443
- if (!p) return;
444
- const M = (C = ($ = N.scenarios) == null ? void 0 : $.find(
445
- (q) => q.id === "environment:baseline"
446
- )) == null ? void 0 : C.environment;
447
- L(M);
2058
+ }, [N]), ee(() => {
2059
+ if (F(void 0), !A || !h || !(c != null && c.trim()) || !(a != null && a.trim()))
2060
+ return;
2061
+ const x = new AbortController();
2062
+ return Jt({
2063
+ namespace: c,
2064
+ sourceRevision: a,
2065
+ transport: Kt({
2066
+ endpoint: h,
2067
+ captureBaseUrl: s
2068
+ }),
2069
+ signal: x.signal
2070
+ }).then((j) => {
2071
+ !x.signal.aborted && j.status === "accepted" && F(j.artifact);
2072
+ }), () => x.abort();
2073
+ }, [
2074
+ h,
2075
+ c,
2076
+ a,
2077
+ s,
2078
+ A
2079
+ ]), ee(() => {
2080
+ let x = !0;
2081
+ if (!T)
2082
+ return Y(void 0), S(!0), () => {
2083
+ x = !1;
2084
+ };
2085
+ const j = new AbortController();
2086
+ return S(!1), Y(void 0), V(null), _e({
2087
+ endpoint: M,
2088
+ signal: j.signal,
2089
+ pages: K.pages.map((k) => ({
2090
+ ...k,
2091
+ id: k.importPageId ?? k.id,
2092
+ importKind: k.importKind
2093
+ })),
2094
+ assets: (n == null ? void 0 : n.getAssets("screens")) ?? []
2095
+ }).then((k) => {
2096
+ x && (Y(k.baselineEnvironment), V(k.graph));
448
2097
  }).catch(() => {
449
- p && L(void 0);
2098
+ x && (Y(void 0), V(null));
450
2099
  }).finally(() => {
451
- p && y(!0);
2100
+ x && S(!0);
452
2101
  }), () => {
453
- p = !1;
454
- }) : (L(void 0), y(!0), () => {
455
- p = !1;
456
- });
457
- }, [R, D]), B(() => {
458
- c == null || c === v.previewOpen || (c ? v.openPreview({ notifyHost: !1 }) : v.closePreview({ notifyHost: !1 }));
459
- }, [c]), E ? /* @__PURE__ */ Z(Pe, {}) : /* @__PURE__ */ Z(
2102
+ x = !1, j.abort(), Y(void 0), V(null);
2103
+ };
2104
+ }, [
2105
+ n,
2106
+ r,
2107
+ T,
2108
+ M
2109
+ ]), ee(() => {
2110
+ b == null || b === K.previewOpen || (b ? K.openPreview({ notifyHost: !1 }) : K.closePreview({ notifyHost: !1 }));
2111
+ }, [b]), A ? /* @__PURE__ */ w(it, {}) : /* @__PURE__ */ w(
460
2112
  "div",
461
2113
  {
462
2114
  "data-pygmalion-storyboard-loading": "",
@@ -475,29 +2127,59 @@ function ze({
475
2127
  );
476
2128
  }
477
2129
  export {
478
- Ye as DESIGN_IMPORT_KINDS,
479
- ze as PygmalionEditor,
480
- Se as STORYBOARD_ENVIRONMENT_CONTROL,
481
- We as STORYBOARD_ENVIRONMENT_QUERY,
482
- Qe as __debug,
483
- Ze as applyTokenOverride,
484
- Ke as clearPygmalionPreviewCache,
485
- Xe as createDesignImportController,
486
- er as createDesignScreenCollection,
487
- rr as createStoryboardRouteUrl,
488
- tr as getRecommendedPygmalionPreviewConcurrency,
489
- nr as getStoryboardBaselineEnvironment,
490
- sr as mergeScreenPresets,
491
- ir as mergeStoryboardEnvironment,
492
- Be as pygmalionNavigate,
493
- Me as pygmalionOpenPreview,
494
- Le as pygmalionResetCurrentEdits,
495
- ar as resetTokenOverrides,
496
- ue as setComponentRegistry,
497
- he as setPygmalionAppOrigin,
498
- ye as setPygmalionPreviewConcurrency,
499
- pe as setPygmalionPreviewRevision,
500
- L as setStoryboardBaselineEnvironment,
501
- fe as setTokens,
502
- Je as usePygmalionProject
2130
+ $n as DESIGN_IMPORT_KINDS,
2131
+ wn as PygmalionCatalogDocument,
2132
+ Sn as PygmalionCatalogMatrix,
2133
+ bn as PygmalionCatalogSection,
2134
+ Rn as PygmalionEditor,
2135
+ st as STORYBOARD_ENVIRONMENT_CONTROL,
2136
+ Mn as STORYBOARD_ENVIRONMENT_QUERY,
2137
+ Pn as __debug,
2138
+ Tn as applyTokenOverride,
2139
+ Jt as bootstrapPreviewArtifact,
2140
+ Dn as clearPygmalionPreviewCache,
2141
+ In as createDesignComponentCatalog,
2142
+ en as createDesignComponentVariantMatrix,
2143
+ vn as createDesignGalleryCatalog,
2144
+ kn as createDesignImportController,
2145
+ zn as createDesignScreenCollection,
2146
+ Kt as createPreviewArtifactHttpTransport,
2147
+ gn as createPreviewCacheNamespace,
2148
+ Ht as createPreviewRecipeFingerprint,
2149
+ yn as createStoryboardCaptureRecipeIdentity,
2150
+ yt as createStoryboardGraph,
2151
+ Mt as createStoryboardGraphFromDiscovery,
2152
+ _n as createStoryboardGraphViewModel,
2153
+ Fn as createStoryboardRouteUrl,
2154
+ Xt as designCatalogKey,
2155
+ je as designCatalogRegistryName,
2156
+ jn as expandDesignScreenCasesViewports,
2157
+ Bn as expandDesignScreenCollectionViewports,
2158
+ Un as getRecommendedPygmalionPreviewConcurrency,
2159
+ et as getStoryboardBaselineEnvironment,
2160
+ ze as getStoryboardDiscoveryBaselineEnvironment,
2161
+ Hn as getStoryboardGraph,
2162
+ _e as loadStoryboardDiscovery,
2163
+ Kn as mergeScreenPresets,
2164
+ He as mergeStoryboardEnvironment,
2165
+ mn as publishStoryboardDiscovery,
2166
+ En as pygmalionNavigate,
2167
+ Nn as pygmalionOpenPreview,
2168
+ Cn as pygmalionResetCurrentEdits,
2169
+ qn as reconstructRoutePreviewArtifactScreenshotV3,
2170
+ Gn as reconstructRoutePreviewArtifactSnapshotV3,
2171
+ Ln as resetTokenOverrides,
2172
+ xt as resolveStoryboardScreenCases,
2173
+ Je as setComponentRegistry,
2174
+ Qe as setPygmalionAppOrigin,
2175
+ tt as setPygmalionPreviewConcurrency,
2176
+ Xe as setPygmalionPreviewRevision,
2177
+ Y as setStoryboardBaselineEnvironment,
2178
+ V as setStoryboardGraph,
2179
+ We as setTokens,
2180
+ ht as storyboardScreenRecipeKey,
2181
+ Vn as subscribeStoryboardGraph,
2182
+ xn as usePygmalionProject,
2183
+ Vt as validatePreviewArtifactBundle,
2184
+ Ke as validateRoutePreviewArtifactV3Browser
503
2185
  };