@pygmalionjs/pygmalion 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,35 +1,35 @@
1
- import { jsx as ae } from "react/jsx-runtime";
2
- import { i as oe, g as le, e as S, b as ce, a as de, c as ue, d as he, f as fe, h as pe, j as me, k as ge, l as ye, m as we, n as be, A as Se, o as M, p as ve, q as Pe, r as Ie, t as Oe, u as Ee, v as Ae, w as Ne, x as z } from "./App-D_6vGXDa.js";
3
- import { D as Ge, y as Ve, z as We, B as Ye, C as Ze, E as Xe, G as Ke } from "./App-D_6vGXDa.js";
4
- import { useMemo as G, useState as $, useRef as V, useCallback as x, useEffect as j } from "react";
5
- const W = /^[a-f0-9]{64}$/, De = /^\/__pygmalion-qa\/artifacts\/[A-Za-z0-9_-]{8,120}\.png$/, Te = /^p\d+$/;
6
- function q(r) {
7
- return typeof r == "string" && De.test(r) ? r : void 0;
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-XRuc9KYj.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-XRuc9KYj.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
8
  }
9
- function Y(r, e) {
9
+ function ne(r, e) {
10
10
  const s = new URL(r, e);
11
11
  return s.search = "", s.hash = "", s.pathname.endsWith("/") || (s.pathname = `${s.pathname}/`), s.href;
12
12
  }
13
- function C(r) {
13
+ function z(r) {
14
14
  if (!r || typeof r != "object" || Array.isArray(r)) return null;
15
15
  const e = r;
16
- return typeof e.domStructureHash != "string" || !W.test(e.domStructureHash) || typeof e.screenshotHash != "string" || !W.test(e.screenshotHash) ? null : {
16
+ return typeof e.domStructureHash != "string" || !te.test(e.domStructureHash) || typeof e.screenshotHash != "string" || !te.test(e.screenshotHash) ? null : {
17
17
  domStructureHash: e.domStructureHash,
18
18
  screenshotHash: e.screenshotHash,
19
- ...q(e.screenshotUrl) ? { screenshotUrl: q(e.screenshotUrl) } : {}
19
+ ...V(e.screenshotUrl) ? { screenshotUrl: V(e.screenshotUrl) } : {}
20
20
  };
21
21
  }
22
- function Z(r) {
22
+ function se(r) {
23
23
  if (!r || typeof r != "object" || Array.isArray(r)) return null;
24
24
  const e = r;
25
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) };
26
26
  }
27
- function Re(r) {
27
+ function xe(r) {
28
28
  if (!r || typeof r != "object" || Array.isArray(r)) return null;
29
- const e = r, s = Z(e.before), i = Z(e.after);
29
+ const e = r, s = se(e.before), i = se(e.after);
30
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
31
  return null;
32
- const t = e.heatmapUrl == null ? null : q(e.heatmapUrl) ?? null;
32
+ const t = e.heatmapUrl == null ? null : V(e.heatmapUrl) ?? null;
33
33
  return {
34
34
  before: s,
35
35
  after: i,
@@ -41,15 +41,15 @@ function Re(r) {
41
41
  heatmapUrl: t
42
42
  };
43
43
  }
44
- function xe(r, e) {
44
+ function Fe(r, e) {
45
45
  if (!r || typeof r != "object" || Array.isArray(r)) return null;
46
46
  const s = r;
47
47
  if (typeof s.id != "string" || !s.id) return null;
48
- const i = C(s), t = C(s.before) ?? i;
48
+ const i = z(s), t = z(s.before) ?? i;
49
49
  if (!t) return null;
50
- const d = C(s.after);
50
+ const d = z(s.after);
51
51
  if (e === "changed" && !d) return null;
52
- const f = d ? Re(s.pixelDiff) : null;
52
+ const h = d ? xe(s.pixelDiff) : null;
53
53
  return {
54
54
  id: s.id,
55
55
  before: t,
@@ -58,18 +58,18 @@ function xe(r, e) {
58
58
  domChanged: t.domStructureHash !== d.domStructureHash,
59
59
  screenshotChanged: t.screenshotHash !== d.screenshotHash
60
60
  } : {},
61
- ...f ? { pixelDiff: f } : {}
61
+ ...h ? { pixelDiff: h } : {}
62
62
  };
63
63
  }
64
- function Fe(r, e = []) {
64
+ function ke(r, e = []) {
65
65
  const s = new Set(e), i = s.size > 0, t = /* @__PURE__ */ new Set(), d = [
66
- ...r.styles.map((f) => f.affectedFrames ?? []),
67
- ...r.texts.map((f) => f.affectedFrames ?? []),
68
- ...r.operations.map((f) => f.affectedFrames ?? [])
66
+ ...r.styles.map((h) => h.affectedFrames ?? []),
67
+ ...r.texts.map((h) => h.affectedFrames ?? []),
68
+ ...r.operations.map((h) => h.affectedFrames ?? [])
69
69
  ];
70
- for (const f of d)
71
- for (const u of f) {
72
- if (i && Te.test(u.id) && !s.has(u.id))
70
+ for (const h of d)
71
+ for (const u of h) {
72
+ if (i && _e.test(u.id) && !s.has(u.id))
73
73
  throw new Error(
74
74
  `"Impact Screen"${u.name}"This internal editor ID (${u.id}) is used. A canonical screen ID is required.`
75
75
  );
@@ -77,7 +77,7 @@ function Fe(r, e = []) {
77
77
  }
78
78
  return [...t].sort();
79
79
  }
80
- async function X(r, e, s) {
80
+ async function ie(r, e, s) {
81
81
  const i = await r(`${e.replace(/\/$/, "")}/capture`, {
82
82
  method: "POST",
83
83
  headers: { "content-type": "application/json" },
@@ -89,63 +89,63 @@ async function X(r, e, s) {
89
89
  );
90
90
  if (typeof t.baselineId != "string" || !t.baselineId)
91
91
  throw new Error("Pygmalion visual QA response has no baselineId");
92
- const d = Array.isArray(t.frames) ? t.frames.map((c) => xe(c, s.phase)).filter((c) => c != null) : [], f = Array.isArray(t.failures) ? t.failures.map((c) => {
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
93
  if (!c || typeof c != "object" || Array.isArray(c)) return null;
94
- const y = c;
95
- return typeof y.id == "string" && typeof y.error == "string" ? { id: y.id, error: y.error } : null;
96
- }).filter((c) => c != null) : [], u = new Set(s.frameIds), O = new Set(d.map((c) => c.id)).size === d.length && d.every((c) => u.has(c.id)) && f.every((c) => u.has(c.id));
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));
97
97
  return {
98
98
  phase: s.phase,
99
99
  baselineId: t.baselineId,
100
- complete: t.complete !== !1 && O && f.length === 0 && d.length === s.frameIds.length,
100
+ complete: t.complete !== !1 && I && h.length === 0 && d.length === s.frameIds.length,
101
101
  frames: d,
102
- failures: f
102
+ failures: h
103
103
  };
104
104
  }
105
- const H = {
105
+ const G = {
106
106
  mirror: "/__pygmalion-dev-control",
107
107
  sessions: "/__pygmalion-design-session",
108
108
  inspect: "/__pygmalion-inspect"
109
- }, _e = "pygmalion.designSessionId", ke = "/__pygmalion-qa", _ = /* @__PURE__ */ new Map();
110
- function K() {
109
+ }, $e = "pygmalion.designSessionId", Ce = "/__pygmalion-qa", J = /* @__PURE__ */ new Map();
110
+ function ae() {
111
111
  var r;
112
112
  return typeof window < "u" && ((r = window.crypto) != null && r.randomUUID) ? window.crypto.randomUUID() : `pygmalion-${Date.now()}-${Math.random().toString(36).slice(2)}`;
113
113
  }
114
- function $e(r, e) {
114
+ function je(r, e) {
115
115
  if (r) return r;
116
- const s = _.get(e);
116
+ const s = J.get(e);
117
117
  if (s) return s;
118
118
  try {
119
119
  const i = window.localStorage.getItem(e);
120
120
  if (i)
121
- return _.set(e, i), i;
122
- const t = K();
123
- return window.localStorage.setItem(e, t), _.set(e, t), t;
121
+ return J.set(e, i), i;
122
+ const t = ae();
123
+ return window.localStorage.setItem(e, t), J.set(e, t), t;
124
124
  } catch {
125
- const i = K();
126
- return _.set(e, i), i;
125
+ const i = ae();
126
+ return J.set(e, i), i;
127
127
  }
128
128
  }
129
- async function I(r) {
129
+ async function O(r) {
130
130
  const e = await r.json();
131
131
  if (!r.ok) throw new Error(e.error ?? `Pygmalion request failed (${r.status})`);
132
132
  return e;
133
133
  }
134
- function qe(r = {}) {
135
- var U, J, Q, B, L;
134
+ function Je(r = {}) {
135
+ var $, C, q, Y, W;
136
136
  const {
137
137
  sessionId: e,
138
- sessionStorageKey: s = _e,
138
+ sessionStorageKey: s = $e,
139
139
  autoStart: i = !0,
140
140
  fetcher: t = fetch,
141
141
  formatApplyMessage: d
142
- } = r, f = ((U = r.endpoints) == null ? void 0 : U.mirror) ?? H.mirror, u = ((J = r.endpoints) == null ? void 0 : J.sessions) ?? H.sessions, E = ((Q = r.endpoints) == null ? void 0 : Q.inspect) ?? H.inspect, O = r.visualQa != null, c = ((B = r.visualQa) == null ? void 0 : B.endpoint) ?? ke, y = JSON.stringify(((L = r.visualQa) == null ? void 0 : L.eligibleFrameIds) ?? []), N = G(
143
- () => JSON.parse(y),
144
- [y]
145
- ), F = G(
146
- () => $e(e, s),
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
147
  [e, s]
148
- ), [v, D] = $({
148
+ ), [S, F] = Q({
149
149
  state: "idle",
150
150
  commit: null,
151
151
  shortCommit: null,
@@ -154,32 +154,32 @@ function qe(r = {}) {
154
154
  warning: null,
155
155
  error: null,
156
156
  appOrigin: null
157
- }), [n, T] = $(null), [R, A] = $(null), m = V(null), p = V(null), k = x(
157
+ }), [n, k] = Q(null), [R, D] = Q(null), E = re(null), y = re(null), T = j(
158
158
  async (o = !0) => {
159
- if (m.current) return m.current;
159
+ if (E.current) return E.current;
160
160
  const a = (async () => {
161
- D((l) => ({ ...l, state: "syncing", error: null }));
161
+ F((l) => ({ ...l, state: "syncing", error: null }));
162
162
  try {
163
- let l = await t(`${f}/${o ? "refresh" : "status"}`, {
163
+ let l = await t(`${h}/${o ? "refresh" : "status"}`, {
164
164
  method: o ? "POST" : "GET"
165
- }), h = await I(l);
165
+ }), f = await O(l);
166
166
  const w = Date.now();
167
- for (; !o && h.state === "syncing" && Date.now() - w < 12e4; )
168
- await new Promise((P) => window.setTimeout(P, 500)), l = await t(`${f}/status`), h = await I(l);
169
- if (h.state !== "ready" || !h.appOrigin || !h.commit)
170
- throw new Error(h.error ?? "Pygmalion could not prepare the source preview");
171
- const g = await I(
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
172
  await t(`${u}/open`, {
173
173
  method: "POST",
174
174
  headers: { "content-type": "application/json" },
175
- body: JSON.stringify({ sessionId: F, baseDevSha: h.commit })
175
+ body: JSON.stringify({ sessionId: H, baseDevSha: f.commit })
176
176
  })
177
177
  );
178
- if (!g.ok || !g.session)
179
- throw new Error(g.error ?? "Pygmalion could not open the design session");
180
- let b = g.session;
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
181
  if (b.branchName) {
182
- const P = await I(
182
+ const P = await O(
183
183
  await t(`${u}/check`, {
184
184
  method: "POST",
185
185
  headers: { "content-type": "application/json" },
@@ -190,31 +190,31 @@ function qe(r = {}) {
190
190
  throw new Error(P.error ?? "Pygmalion could not check the design session");
191
191
  b = P.session;
192
192
  }
193
- D(h), T(b), A(b.appOrigin ?? h.appOrigin);
193
+ F(f), k(b), D(b.appOrigin ?? f.appOrigin);
194
194
  } catch (l) {
195
- D((h) => ({
196
- ...h,
195
+ F((f) => ({
196
+ ...f,
197
197
  state: "error",
198
198
  error: l instanceof Error ? l.message : String(l)
199
199
  }));
200
200
  }
201
201
  })();
202
- m.current = a;
202
+ E.current = a;
203
203
  try {
204
204
  await a;
205
205
  } finally {
206
- m.current === a && (m.current = null);
206
+ E.current === a && (E.current = null);
207
207
  }
208
208
  },
209
- [t, f, u, F]
210
- ), ee = x(
209
+ [t, h, u, H]
210
+ ), U = j(
211
211
  async (o) => {
212
- var g;
212
+ var m;
213
213
  if (!n) throw new Error("Pygmalion design session is not ready");
214
- const a = p.current;
214
+ const a = y.current;
215
215
  if (a && (a.sessionId !== n.id || a.baseDevSha !== n.baseDevSha || a.revision !== n.revision || a.fingerprint !== JSON.stringify(o)))
216
216
  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 I(
217
+ const l = await O(
218
218
  await t(`${u}/apply-visual`, {
219
219
  method: "POST",
220
220
  headers: { "content-type": "application/json" },
@@ -229,15 +229,15 @@ function qe(r = {}) {
229
229
  );
230
230
  if (!l.ok || !l.session)
231
231
  throw new Error(l.error ?? "Pygmalion could not apply the visual changes");
232
- T(l.session), l.session.appOrigin && A(l.session.appOrigin);
233
- const h = l.applied ?? o.styles.length + o.texts.length + o.operations.length;
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
234
  let w;
235
- if (a != null && a.qaBaselineId && ((g = a.qaFrameIds) != null && g.length) && l.session.appOrigin)
235
+ if (a != null && a.qaBaselineId && ((m = a.qaFrameIds) != null && m.length) && l.session.appOrigin)
236
236
  try {
237
- w = await X(t, c, {
237
+ w = await ie(t, c, {
238
238
  phase: "changed",
239
239
  baselineId: a.qaBaselineId,
240
- basePath: Y(l.session.appOrigin, window.location.origin),
240
+ basePath: ne(l.session.appOrigin, window.location.origin),
241
241
  frameIds: a.qaFrameIds
242
242
  });
243
243
  } catch (b) {
@@ -247,24 +247,24 @@ function qe(r = {}) {
247
247
  baselineId: a.qaBaselineId,
248
248
  complete: !1,
249
249
  frames: [],
250
- failures: a.qaFrameIds.map((ie) => ({ id: ie, error: P }))
250
+ failures: a.qaFrameIds.map((oe) => ({ id: oe, error: P }))
251
251
  };
252
252
  }
253
- return p.current = null, {
254
- applied: h,
253
+ return y.current = null, {
254
+ applied: f,
255
255
  branch: l.session.branchName ?? void 0,
256
256
  integration: l.session.integration.state,
257
- message: d == null ? void 0 : d(l.session, h),
257
+ message: d == null ? void 0 : d(l.session, f),
258
258
  ...w ? { qa: w } : {}
259
259
  };
260
260
  },
261
261
  [t, d, c, n, u]
262
- ), re = x(
262
+ ), _ = j(
263
263
  async (o) => {
264
- var g;
264
+ var m;
265
265
  if (!n) throw new Error("Pygmalion design session is not ready");
266
- p.current = null;
267
- const a = await I(
266
+ y.current = null;
267
+ const a = await O(
268
268
  await t(`${u}/preview-visual`, {
269
269
  method: "POST",
270
270
  headers: { "content-type": "application/json" },
@@ -278,48 +278,48 @@ function qe(r = {}) {
278
278
  );
279
279
  if (!a.ok || !Number.isSafeInteger(a.revision))
280
280
  throw new Error(a.error ?? "Pygmalion could not preview the visual changes");
281
- const l = O ? Fe(o, N) : [];
282
- let h;
283
- const w = n.appOrigin ?? v.appOrigin;
281
+ const l = I ? ke(o, x) : [];
282
+ let f;
283
+ const w = n.appOrigin ?? S.appOrigin;
284
284
  if (l.length > 0) {
285
285
  if (!w)
286
286
  throw new Error("Impact screen QA baseline preview not ready");
287
- if (h = await X(t, c, {
287
+ if (f = await ie(t, c, {
288
288
  phase: "baseline",
289
- basePath: Y(w, window.location.origin),
289
+ basePath: ne(w, window.location.origin),
290
290
  frameIds: l
291
- }), !h.complete)
291
+ }), !f.complete)
292
292
  throw new Error(
293
- ((g = h.failures[0]) == null ? void 0 : g.error) ?? `Failed to capture ${l.length - h.frames.length} affected frames`
293
+ ((m = f.failures[0]) == null ? void 0 : m.error) ?? `Failed to capture ${l.length - f.frames.length} affected frames`
294
294
  );
295
295
  }
296
- return p.current = {
296
+ return y.current = {
297
297
  sessionId: n.id,
298
298
  baseDevSha: n.baseDevSha,
299
299
  revision: a.revision,
300
300
  fingerprint: JSON.stringify(o),
301
- ...h ? { qaBaselineId: h.baselineId, qaFrameIds: l } : {}
301
+ ...f ? { qaBaselineId: f.baselineId, qaFrameIds: l } : {}
302
302
  }, {
303
303
  revision: a.revision,
304
304
  files: Array.isArray(a.files) ? a.files : [],
305
305
  affectedFiles: Array.isArray(a.affectedFiles) ? a.affectedFiles : [],
306
- ...h ? { qa: h } : {}
306
+ ...f ? { qa: f } : {}
307
307
  };
308
308
  },
309
309
  [
310
310
  t,
311
- v.appOrigin,
312
- N,
311
+ S.appOrigin,
312
+ x,
313
313
  c,
314
314
  n,
315
315
  u,
316
- O
316
+ I
317
317
  ]
318
- ), te = x(
318
+ ), p = j(
319
319
  async (o) => {
320
320
  if (o.length === 0) return { files: [] };
321
- const a = await I(
322
- await t(`${E}/impact`, {
321
+ const a = await O(
322
+ await t(`${A}/impact`, {
323
323
  method: "POST",
324
324
  headers: { "content-type": "application/json" },
325
325
  body: JSON.stringify({ componentFiles: o })
@@ -329,11 +329,11 @@ function qe(r = {}) {
329
329
  throw new Error(a.error ?? "Pygmalion could not calculate source impact");
330
330
  return { files: Array.isArray(a.files) ? a.files : [] };
331
331
  },
332
- [t, E]
333
- ), ne = x(async () => {
332
+ [t, A]
333
+ ), N = j(async () => {
334
334
  if (!(n != null && n.canRevert) || !n.headSha)
335
335
  throw new Error("There are no reversible changes applied");
336
- const o = await I(
336
+ const o = await O(
337
337
  await t(`${u}/revert-visual`, {
338
338
  method: "POST",
339
339
  headers: { "content-type": "application/json" },
@@ -347,106 +347,157 @@ function qe(r = {}) {
347
347
  );
348
348
  if (!o.ok || o.reverted !== !0 || !o.operation || o.operation.kind !== "visual-revert" || !o.session)
349
349
  throw new Error(o.error ?? "Pygmalion could not revert the last visual change");
350
- return p.current = null, T(o.session), o.session.appOrigin && A(o.session.appOrigin), {
350
+ return y.current = null, k(o.session), o.session.appOrigin && D(o.session.appOrigin), {
351
351
  reverted: !0,
352
352
  operation: o.operation,
353
353
  session: o.session
354
354
  };
355
355
  }, [t, n, u]);
356
- j(() => {
357
- i && k(!1);
358
- }, [i, k]);
359
- const se = (n == null ? void 0 : n.appOrigin) ?? v.appOrigin ?? R;
356
+ B(() => {
357
+ i && T(!1);
358
+ }, [i, T]);
359
+ const M = (n == null ? void 0 : n.appOrigin) ?? S.appOrigin ?? R;
360
360
  return {
361
- mirror: v,
361
+ mirror: S,
362
362
  session: n,
363
363
  ready: R != null,
364
- appOrigin: se,
365
- previewRevision: `${(n == null ? void 0 : n.headSha) ?? (n == null ? void 0 : n.baseDevSha) ?? v.commit ?? "pending"}:${(n == null ? void 0 : n.revision) ?? 0}`,
366
- refresh: k,
367
- previewVisual: re,
368
- inspectImpact: te,
369
- applyVisual: ee,
370
- revertLastVisual: ne
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
371
371
  };
372
372
  }
373
- const Ue = { editor: S, getObserverTree: le, isObservableProp: oe };
374
- function Je(r) {
375
- S.navigateToPageByName(r);
373
+ const Qe = { editor: v, getObserverTree: ce, isObservableProp: le };
374
+ function Be(r) {
375
+ v.navigateToPageByName(r);
376
376
  }
377
- function Qe() {
378
- S.openPreview();
377
+ function Me() {
378
+ v.openPreview();
379
379
  }
380
- function Be() {
381
- const r = M.entries.length > 0;
382
- return r && M.discardPending(), S.resetCurrentEdits() || r;
380
+ function Le() {
381
+ const r = K.entries.length > 0;
382
+ return r && K.discardPending(), v.resetCurrentEdits() || r;
383
383
  }
384
- function Le({
384
+ function ze({
385
385
  registry: r,
386
386
  tokens: e,
387
387
  initialPages: s,
388
388
  designImport: i,
389
389
  onTokensChange: t,
390
390
  appOrigin: d,
391
- previewRevision: f,
391
+ previewRevision: h,
392
392
  previewCacheNamespace: u,
393
- previewArtifacts: E,
394
- previewConcurrency: O,
393
+ previewArtifacts: A,
394
+ previewConcurrency: I,
395
395
  previewOpen: c,
396
- onPreviewOpenChange: y,
397
- flowCanvas: N,
398
- onApply: F,
399
- onDesignChange: v,
400
- onInspectApply: D,
396
+ onPreviewOpenChange: g,
397
+ flowCanvas: x,
398
+ onApply: H,
399
+ onDesignChange: S,
400
+ onInspectApply: F,
401
401
  onInspectPreview: n,
402
- onInspectImpact: T
402
+ onInspectImpact: k,
403
+ storyboardDiscovery: R = !0,
404
+ storyboardDiscoveryEndpoint: D = Se
403
405
  }) {
404
- i && (i.assertComplete(), ce(i));
405
- const R = r ?? (i == null ? void 0 : i.getRegistry()), A = e ?? (i == null ? void 0 : i.getTokens()), m = s ?? (i == null ? void 0 : i.getInitialPages());
406
- return R && de(R), A && ue(A), ve(t ?? null), d != null && he(d), f != null && fe(f), pe(u), E && m && me(E, {
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, {
407
410
  namespace: u ?? "",
408
- previewRevision: Ie(),
409
- appOrigin: Pe(),
410
- pages: m.flatMap(
411
+ previewRevision: Ee(),
412
+ appOrigin: Ie(),
413
+ pages: _.flatMap(
411
414
  (p) => p.route && p.importPageId ? [
412
415
  {
413
416
  canonicalId: p.importPageId,
414
417
  route: p.route,
415
418
  width: p.width,
416
419
  height: p.height,
420
+ environment: p.environment,
417
421
  preset: p.preset,
418
422
  interactions: p.interactions,
419
423
  assertions: p.assertions
420
424
  }
421
425
  ] : []
422
426
  )
423
- }), O != null && ge(O), Oe(y ?? null), N != null && ye(N), Ee(F ?? null), Ae(D ?? null), we(n ?? null), Ne(T ?? null), m && S.initPagesFromComponents(m), j(() => {
424
- z(v ?? null);
425
- const p = be(S);
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);
426
430
  return () => {
427
- p(), z(null);
431
+ p(), X(null);
428
432
  };
429
- }, [v]), j(() => {
430
- c == null || c === S.previewOpen || (c ? S.openPreview({ notifyHost: !1 }) : S.closePreview({ notifyHost: !1 }));
431
- }, [c]), /* @__PURE__ */ ae(Se, {});
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);
448
+ }).catch(() => {
449
+ p && L(void 0);
450
+ }).finally(() => {
451
+ p && y(!0);
452
+ }), () => {
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(
460
+ "div",
461
+ {
462
+ "data-pygmalion-storyboard-loading": "",
463
+ role: "status",
464
+ style: {
465
+ display: "grid",
466
+ width: "100%",
467
+ height: "100%",
468
+ placeItems: "center",
469
+ color: "#777777",
470
+ background: "#f5f5f5",
471
+ font: "12px system-ui, sans-serif"
472
+ },
473
+ children: "Discovering storyboard branches"
474
+ }
475
+ );
432
476
  }
433
477
  export {
434
- Ge as DESIGN_IMPORT_KINDS,
435
- Le as PygmalionEditor,
436
- Ue as __debug,
437
- Ve as applyTokenOverride,
438
- We as clearPygmalionPreviewCache,
439
- Ye as createDesignImportController,
440
- Ze as createDesignScreenCollection,
441
- Xe as mergeScreenPresets,
442
- Je as pygmalionNavigate,
443
- Qe as pygmalionOpenPreview,
444
- Be as pygmalionResetCurrentEdits,
445
- Ke as resetTokenOverrides,
446
- de as setComponentRegistry,
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,
447
497
  he as setPygmalionAppOrigin,
448
- ge as setPygmalionPreviewConcurrency,
449
- fe as setPygmalionPreviewRevision,
450
- ue as setTokens,
451
- qe as usePygmalionProject
498
+ ye as setPygmalionPreviewConcurrency,
499
+ pe as setPygmalionPreviewRevision,
500
+ L as setStoryboardBaselineEnvironment,
501
+ fe as setTokens,
502
+ Je as usePygmalionProject
452
503
  };