@snowcone-app/canvas 0.46.2 → 0.46.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/{CanvasRenderer-B8BADU_r.js → CanvasRenderer-CmIQSVCK.js} +4 -4
  2. package/dist/{CanvasRenderer-B8BADU_r.js.map → CanvasRenderer-CmIQSVCK.js.map} +1 -1
  3. package/dist/{ContextualToolbars-5tHC6s0Y.js → ContextualToolbars-Dmo86Wd2.js} +323 -322
  4. package/dist/{ContextualToolbars-5tHC6s0Y.js.map → ContextualToolbars-Dmo86Wd2.js.map} +1 -1
  5. package/dist/{EditorCanvasImpl-Cd_umlTI.js → EditorCanvasImpl-BHa8q4iO.js} +16 -15
  6. package/dist/{EditorCanvasImpl-Cd_umlTI.js.map → EditorCanvasImpl-BHa8q4iO.js.map} +1 -1
  7. package/dist/{ExportManager-xRsXgyNo.js → ExportManager-DEJgxB0S.js} +79 -78
  8. package/dist/{ExportManager-xRsXgyNo.js.map → ExportManager-DEJgxB0S.js.map} +1 -1
  9. package/dist/{FontAnalyzer-Ds3Wdba7.js → FontAnalyzer-CLMJi2Sw.js} +374 -409
  10. package/dist/FontAnalyzer-CLMJi2Sw.js.map +1 -0
  11. package/dist/{ImagePanel-bW3yr6Ac.js → ImagePanel-4fHABjNT.js} +6 -6
  12. package/dist/{ImagePanel-bW3yr6Ac.js.map → ImagePanel-4fHABjNT.js.map} +1 -1
  13. package/dist/{SnowconeCanvas-crxPwbib.js → SnowconeCanvas-GPag5BXG.js} +10 -10
  14. package/dist/{SnowconeCanvas-crxPwbib.js.map → SnowconeCanvas-GPag5BXG.js.map} +1 -1
  15. package/dist/advanced.mjs +54 -54
  16. package/dist/core/image-adjustments.d.ts +2 -4
  17. package/dist/core/masked-crop.d.ts +3 -55
  18. package/dist/{custom-icons-DQRp8GhF.js → custom-icons-Dt0Y4VSn.js} +2 -2
  19. package/dist/{custom-icons-DQRp8GhF.js.map → custom-icons-Dt0Y4VSn.js.map} +1 -1
  20. package/dist/design-builder-HKRo18WT.js +1798 -0
  21. package/dist/design-builder-HKRo18WT.js.map +1 -0
  22. package/dist/{embed-DvN5BVmQ.js → embed-DhjsJ3ni.js} +698 -688
  23. package/dist/embed-DhjsJ3ni.js.map +1 -0
  24. package/dist/embed.mjs +35 -36
  25. package/dist/embed.mjs.map +1 -1
  26. package/dist/{export-worker.bundle.string-BL30CYzH.js → export-worker.bundle.string-CyMb_XjB.js} +27 -25
  27. package/dist/{export-worker.bundle.string-BL30CYzH.js.map → export-worker.bundle.string-CyMb_XjB.js.map} +1 -1
  28. package/dist/{guards-DwYEoqcn.js → guards-Dk86a-kH.js} +2 -2
  29. package/dist/{guards-DwYEoqcn.js.map → guards-Dk86a-kH.js.map} +1 -1
  30. package/dist/index.mjs +43 -43
  31. package/dist/internals.mjs +150 -149
  32. package/dist/internals.mjs.map +1 -1
  33. package/dist/rendering/serialize-for-server.d.ts +4 -91
  34. package/dist/state/CanvasStateV1.d.ts +1 -363
  35. package/dist/{CanvasStateV1-BlDWgOzV.js → template-fields-CKEuUmTM.js} +1997 -1835
  36. package/dist/template-fields-CKEuUmTM.js.map +1 -0
  37. package/dist/testing.mjs +61 -60
  38. package/dist/testing.mjs.map +1 -1
  39. package/dist/{useCommands-F-b_SwW-.js → useCommands-BI7O5Lf0.js} +225 -225
  40. package/dist/{useCommands-F-b_SwW-.js.map → useCommands-BI7O5Lf0.js.map} +1 -1
  41. package/dist/{usePieceGuideBundle-BWdobHQE.js → usePieceGuideBundle-DJfjOVEd.js} +2 -2
  42. package/dist/{usePieceGuideBundle-BWdobHQE.js.map → usePieceGuideBundle-DJfjOVEd.js.map} +1 -1
  43. package/dist/utils/custom-fonts.d.ts +2 -16
  44. package/dist/{validation-hn5ZX8Po.js → validation-au_-Sj-A.js} +11 -11
  45. package/dist/{validation-hn5ZX8Po.js.map → validation-au_-Sj-A.js.map} +1 -1
  46. package/dist/workers/export-worker.bundle.string.d.ts +1 -1
  47. package/example/package.json +1 -1
  48. package/package.json +5 -4
  49. package/dist/CanvasStateV1-BlDWgOzV.js.map +0 -1
  50. package/dist/FontAnalyzer-Ds3Wdba7.js.map +0 -1
  51. package/dist/design-builder-sH53Og6j.js +0 -1870
  52. package/dist/design-builder-sH53Og6j.js.map +0 -1
  53. package/dist/embed-DvN5BVmQ.js.map +0 -1
  54. package/dist/template-fields-BaQG0CJY.js +0 -559
  55. package/dist/template-fields-BaQG0CJY.js.map +0 -1
package/dist/testing.mjs CHANGED
@@ -1,51 +1,52 @@
1
- import { E as A, s as S, f as y } from "./design-builder-sH53Og6j.js";
2
- import { g as re, h as ie, r as ae } from "./design-builder-sH53Og6j.js";
3
- import { fetchMockupImage as b, isSnowconeSdkError as _, RenderSession as R, mintRealtimeGrant as I } from "@snowcone-app/sdk";
4
- import { e as D, A as T, q as k, I as F, t as m } from "./FontAnalyzer-Ds3Wdba7.js";
1
+ import { E as A, f as y } from "./design-builder-HKRo18WT.js";
2
+ import { g as ie, h as oe, r as ae } from "./design-builder-HKRo18WT.js";
3
+ import { fetchMockupImage as S, isSnowconeSdkError as b, RenderSession as _, mintRealtimeGrant as R } from "@snowcone-app/sdk";
4
+ import { e as I, A as D, o as T, I as k, q as m } from "./FontAnalyzer-CLMJi2Sw.js";
5
+ import { serializeStateForServer as F } from "@snowcone-app/design/wire";
5
6
  import { jsx as u } from "react/jsx-runtime";
6
7
  import { useState as x } from "react";
7
8
  import { T as p } from "./ThemeContext-Rjz25x9X.js";
8
- const K = ({
9
+ const G = ({
9
10
  children: t,
10
11
  initialElements: n = [],
11
12
  initialArtboards: e,
12
13
  initialSelection: r = null,
13
14
  initialMultiSelection: i = [],
14
- initialArtboardConfig: a = {}
15
+ initialArtboardConfig: o = {}
15
16
  }) => {
16
17
  const [l] = x(() => {
17
- const o = new D();
18
+ const a = new I();
18
19
  return e && e.length > 0 ? e.forEach((c) => {
19
- o.createArtboard({
20
+ a.createArtboard({
20
21
  name: c.name,
21
22
  width: c.width,
22
23
  height: c.height,
23
24
  backgroundColor: c.backgroundColor
24
25
  });
25
- }) : o.createArtboard({
26
+ }) : a.createArtboard({
26
27
  name: "Test Artboard",
27
28
  width: 1200,
28
29
  height: 1200,
29
30
  backgroundColor: "#FFFFFF",
30
- ...a
31
- }), o;
31
+ ...o
32
+ }), a;
32
33
  });
33
34
  return /* @__PURE__ */ u(p, { children: /* @__PURE__ */ u(
34
35
  A,
35
36
  {
36
- initialArtboardConfig: a,
37
+ initialArtboardConfig: o,
37
38
  children: t
38
39
  }
39
40
  ) });
40
- }, G = ({
41
+ }, J = ({
41
42
  children: t,
42
43
  initialElements: n = [],
43
44
  initialSelection: e = null,
44
45
  initialMultiSelection: r = [],
45
46
  initialArtboardConfig: i = {}
46
47
  }) => /* @__PURE__ */ u(p, { children: /* @__PURE__ */ u(A, { initialArtboardConfig: i, children: t }) });
47
- function J(t = "custom", n = {}) {
48
- const e = k(t);
48
+ function W(t = "custom", n = {}) {
49
+ const e = T(t);
49
50
  if (!e || !e.Component)
50
51
  throw new Error(`Transform type "${t}" not found in registry`);
51
52
  return new e.Component({
@@ -61,8 +62,8 @@ function J(t = "custom", n = {}) {
61
62
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- test utility: overrides merge Partial<TextElement> properties with config, which are structurally compatible but not type-assignable
62
63
  });
63
64
  }
64
- function W(t = {}) {
65
- return new F({
65
+ function j(t = {}) {
66
+ return new k({
66
67
  imageUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
67
68
  imageAspectRatio: 1,
68
69
  x: 100,
@@ -71,8 +72,8 @@ function W(t = {}) {
71
72
  ...t
72
73
  });
73
74
  }
74
- function j(t = {}) {
75
- return new T({
75
+ function q(t = {}) {
76
+ return new D({
76
77
  name: "Test Artboard",
77
78
  width: 1200,
78
79
  height: 1200,
@@ -90,11 +91,11 @@ async function U(t, n = 5e3, e = 100) {
90
91
  await new Promise((i) => setTimeout(i, e));
91
92
  }
92
93
  }
93
- async function q(t, n = 5e3) {
94
+ async function z(t, n = 5e3) {
94
95
  let e = null;
95
96
  return await U(() => !1, n), e;
96
97
  }
97
- function z(t, n = {}) {
98
+ function Q(t, n = {}) {
98
99
  const e = new KeyboardEvent("keydown", {
99
100
  key: t,
100
101
  ctrlKey: n.ctrl,
@@ -106,11 +107,11 @@ function z(t, n = {}) {
106
107
  });
107
108
  document.dispatchEvent(e);
108
109
  }
109
- function Q(t = 800, n = 600) {
110
+ function V(t = 800, n = 600) {
110
111
  const e = document.createElement("canvas");
111
112
  return e.width = t, e.height = n, e;
112
113
  }
113
- function V(t, n) {
114
+ function Y(t, n) {
114
115
  Object.entries(n).forEach(([e, r]) => {
115
116
  if (t[e] !== r)
116
117
  throw new Error(
@@ -118,7 +119,7 @@ function V(t, n) {
118
119
  );
119
120
  });
120
121
  }
121
- function Y(t) {
122
+ function H(t) {
122
123
  const n = t.getBoundingBox();
123
124
  return {
124
125
  x: n.x,
@@ -130,8 +131,8 @@ function Y(t) {
130
131
  function N(t) {
131
132
  let n = !1;
132
133
  const e = t.elements.map((r) => {
133
- const i = r.name, a = r.text;
134
- return !i || typeof a != "string" ? r : (n = !0, { ...r, text: `ASSERT_RENDERS_${i.toUpperCase()}` });
134
+ const i = r.name, o = r.text;
135
+ return !i || typeof o != "string" ? r : (n = !0, { ...r, text: `ASSERT_RENDERS_${i.toUpperCase()}` });
135
136
  });
136
137
  if (!n)
137
138
  throw new m(
@@ -148,40 +149,40 @@ function M(t, n) {
148
149
  return !0;
149
150
  }
150
151
  async function E(t, n, e, r, i) {
151
- const a = t();
152
+ const o = t();
152
153
  try {
153
- return await new Promise((l, o) => {
154
+ return await new Promise((l, a) => {
154
155
  const c = setTimeout(() => {
155
- o(
156
+ a(
156
157
  new m("E_RENDER_FAILED", `the ${i} render produced no mockup within ${r}ms.`, {
157
158
  phase: i,
158
159
  timeoutMs: r
159
160
  })
160
161
  );
161
162
  }, r);
162
- a.onMockups((s) => {
163
+ o.onMockups((s) => {
163
164
  const d = s.find((h) => h.imageUrl);
164
165
  d && (clearTimeout(c), l(d));
165
- }), a.onError((s) => {
166
- clearTimeout(c), o(new m("E_RENDER_FAILED", `the ${i} render failed: ${s}`, { phase: i, error: s }));
167
- }), a.renderState(n, S(e)).catch((s) => {
166
+ }), o.onError((s) => {
167
+ clearTimeout(c), a(new m("E_RENDER_FAILED", `the ${i} render failed: ${s}`, { phase: i, error: s }));
168
+ }), o.renderState(n, F(e)).catch((s) => {
168
169
  clearTimeout(c);
169
170
  const d = s instanceof Error ? s.message : String(s);
170
- o(new m("E_RENDER_FAILED", `the ${i} render failed to dispatch: ${d}`, { phase: i, error: d }));
171
+ a(new m("E_RENDER_FAILED", `the ${i} render failed to dispatch: ${d}`, { phase: i, error: d }));
171
172
  });
172
173
  });
173
174
  } finally {
174
- a.close();
175
+ o.close();
175
176
  }
176
177
  }
177
178
  async function w(t, n, e) {
178
179
  try {
179
- const r = await b(t, {
180
+ const r = await S(t, {
180
181
  ...e.fetchImpl ? { fetchImpl: e.fetchImpl } : {}
181
182
  });
182
183
  return { bytes: r.bytes, kind: r.kind };
183
184
  } catch (r) {
184
- throw _(r) ? r.code === "ASSET_FORBIDDEN" ? new m(
185
+ throw b(r) ? r.code === "ASSET_FORBIDDEN" ? new m(
185
186
  "E_ASSET_FORBIDDEN",
186
187
  `the shop's asset-origin allowlist denied an asset in this design (${n} render). Allow the asset's origin on the shop (or host it on the shop's storage origin).`,
187
188
  { phase: n, url: t, failedAssets: r.data.failedAssets, docSlug: "embed-mode" }
@@ -192,18 +193,18 @@ async function w(t, n, e) {
192
193
  }) : r;
193
194
  }
194
195
  }
195
- async function H(t, n, e) {
196
- const r = e.timeoutMs ?? 3e4, i = t.toJSON(), a = i.activeArtboard, l = (e.mutate ?? N)(i), o = e.grant, c = typeof o == "function" ? o : o ? () => Promise.resolve(o) : () => I({
196
+ async function X(t, n, e) {
197
+ const r = e.timeoutMs ?? 3e4, i = t.toJSON(), o = i.activeArtboard, l = (e.mutate ?? N)(i), a = e.grant, c = typeof a == "function" ? a : a ? () => Promise.resolve(a) : () => R({
197
198
  shop: e.shop,
198
199
  ...e.apiKey ? { apiKey: e.apiKey } : {},
199
200
  ...e.grantBase ? { base: e.grantBase } : {},
200
201
  ...e.fetchImpl ? { fetch: e.fetchImpl } : {}
201
- }), s = () => new R({
202
+ }), s = () => new _({
202
203
  shop: e.shop,
203
204
  product: n,
204
205
  ...e.wsUrl ? { wsUrl: e.wsUrl } : {},
205
206
  getToken: c
206
- }), d = await E(s, a, i, r, "seed"), h = await w(d.imageUrl, "seed", e), g = await E(s, a, l, r, "mutated"), f = await w(g.imageUrl, "mutated", e);
207
+ }), d = await E(s, o, i, r, "seed"), h = await w(d.imageUrl, "seed", e), g = await E(s, o, l, r, "mutated"), f = await w(g.imageUrl, "mutated", e);
207
208
  if (M(h.bytes, f.bytes))
208
209
  throw new m(
209
210
  "E_BINDING_INERT",
@@ -221,35 +222,35 @@ async function H(t, n, e) {
221
222
  };
222
223
  }
223
224
  const v = "https://assets.test-403.invalid/denied.png";
224
- function X() {
225
+ function Z() {
225
226
  return y({ name: "Front", width: 1e3, height: 1e3 }).background(v, { aspectRatio: 1, name: "art" }).text("ALLOWLIST DENIAL FIXTURE", { anchor: "top", name: "headline" });
226
227
  }
227
- function Z() {
228
+ function ee() {
228
229
  return y({ name: "Front", width: 1e3, height: 1e3 }).text("YOUR NAME", { anchor: "center", name: "name" });
229
230
  }
230
- function ee(t = "failing-grant fixture: grant endpoint unavailable") {
231
+ function te(t = "failing-grant fixture: grant endpoint unavailable") {
231
232
  return () => Promise.reject(new Error(t));
232
233
  }
233
234
  export {
234
- K as MockEditorProvider,
235
- G as MockEditorProviderWithState,
235
+ G as MockEditorProvider,
236
+ J as MockEditorProviderWithState,
236
237
  v as TEST_403_ASSET_URL,
237
- V as assertElementProperties,
238
- H as assertRenders,
239
- j as createMockArtboard,
240
- Q as createMockCanvas,
241
- J as createMockElement,
242
- W as createMockImageElement,
243
- re as expectNoEditorErrors,
244
- ee as failingGrant,
245
- ie as getContainedEditorErrors,
246
- Y as getElementBounds,
238
+ Y as assertElementProperties,
239
+ X as assertRenders,
240
+ q as createMockArtboard,
241
+ V as createMockCanvas,
242
+ W as createMockElement,
243
+ j as createMockImageElement,
244
+ ie as expectNoEditorErrors,
245
+ te as failingGrant,
246
+ oe as getContainedEditorErrors,
247
+ H as getElementBounds,
247
248
  N as mutateNamedTextLayers,
248
249
  ae as resetContainedEditorErrors,
249
- z as simulateKeyPress,
250
- X as test403Design,
251
- Z as testIncompleteDesign,
250
+ Q as simulateKeyPress,
251
+ Z as test403Design,
252
+ ee as testIncompleteDesign,
252
253
  U as waitFor,
253
- q as waitForExport
254
+ z as waitForExport
254
255
  };
255
256
  //# sourceMappingURL=testing.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.mjs","sources":["../src/testing/MockEditorProvider.tsx","../src/testing/utils.ts","../src/testing/assertRenders.ts","../src/testing/failureFixtures.ts"],"sourcesContent":["/**\n * MockEditorProvider - Lightweight mock for testing custom components\n * Compatible with Vitest (does not require Jest)\n *\n * @example\n * ```tsx\n * import { render } from '@testing-library/react';\n * import { MockEditorProvider } from '@snowcone-app/canvas/embed';\n *\n * test('my component renders', () => {\n * render(\n * <MockEditorProvider>\n * <MyCustomComponent />\n * </MockEditorProvider>\n * );\n * });\n * ```\n */\n\nimport React, { useState, ReactNode } from 'react';\nimport { EditorProvider } from '../contexts/EditorContext.js';\nimport { ThemeProvider } from '../contexts/ThemeContext.js';\nimport { ArtboardManager } from '../core/ArtboardManager.js';\nimport { ArtboardElement } from '../core/ArtboardElement.js';\nimport type { TextElement } from '../core/TextElement.js';\nimport type { ImageElement } from '../core/ImageElement.js';\nimport type { GroupElement } from '../core/GroupElement.js';\nimport type { ShapeElement } from '../core/ShapeElement.js';\n\nexport type MockEditorElement = TextElement | ImageElement | GroupElement | ShapeElement;\n\nexport interface MockEditorProviderProps {\n children: ReactNode;\n\n /**\n * Initial elements to populate the editor\n */\n initialElements?: MockEditorElement[];\n\n /**\n * Initial artboards (default: one artboard)\n */\n initialArtboards?: ArtboardElement[];\n\n /**\n * Initial selection\n */\n initialSelection?: string | null;\n\n /**\n * Initial multi-selection\n */\n initialMultiSelection?: string[];\n\n /**\n * Initial artboard configuration\n */\n initialArtboardConfig?: {\n name?: string;\n width?: number;\n height?: number;\n backgroundColor?: string;\n };\n}\n\n/**\n * MockEditorProvider - Wraps EditorProvider with test-friendly defaults\n *\n * This is a lightweight wrapper that provides the same EditorContext\n * as the real app, making it perfect for testing custom components.\n */\nexport const MockEditorProvider: React.FC<MockEditorProviderProps> = ({\n children,\n initialElements: _initialElements = [],\n initialArtboards,\n initialSelection: _initialSelection = null,\n initialMultiSelection: _initialMultiSelection = [],\n initialArtboardConfig = {},\n}) => {\n // Create artboard manager if artboards provided\n const [_artboardManager] = useState(() => {\n const manager = new ArtboardManager();\n\n if (initialArtboards && initialArtboards.length > 0) {\n // Use provided artboards\n initialArtboards.forEach(artboard => {\n manager.createArtboard({\n name: artboard.name,\n width: artboard.width,\n height: artboard.height,\n backgroundColor: artboard.backgroundColor,\n });\n });\n } else {\n // Create default artboard\n manager.createArtboard({\n name: 'Test Artboard',\n width: 1200,\n height: 1200,\n backgroundColor: '#FFFFFF',\n ...initialArtboardConfig,\n });\n }\n\n return manager;\n });\n\n // Simple wrapper that passes children through to real EditorProvider\n // The EditorProvider will handle all the state management\n // ThemeProvider is required because CanvasEditor uses useTheme()\n return (\n <ThemeProvider>\n <EditorProvider\n initialArtboardConfig={initialArtboardConfig}\n >\n {children}\n </EditorProvider>\n </ThemeProvider>\n );\n};\n\n/**\n * MockEditorProviderWithState - For tests that need to control state directly\n *\n * Use this when you need fine-grained control over the editor state.\n * Most tests should use the simpler MockEditorProvider above.\n */\nexport const MockEditorProviderWithState: React.FC<MockEditorProviderProps> = ({\n children,\n initialElements: _initialElements = [],\n initialSelection: _initialSelection = null,\n initialMultiSelection: _initialMultiSelection = [],\n initialArtboardConfig = {},\n}) => {\n return (\n <ThemeProvider>\n <EditorProvider initialArtboardConfig={initialArtboardConfig}>\n {children}\n </EditorProvider>\n </ThemeProvider>\n );\n};\n","/**\n * Testing Utilities - Helpers for creating mock elements and artboards\n * Compatible with Vitest\n */\n\nimport { TextElement } from '../core/TextElement.js';\nimport { ImageElement } from '../core/ImageElement.js';\nimport { ArtboardElement } from '../core/ArtboardElement.js';\nimport { getTransformById } from '../transforms/registry.js';\nimport type { TransformType, ImageElementConfig } from '../types/index.js';\n\n/**\n * Create a mock text element with sensible defaults\n *\n * @example\n * ```tsx\n * const element = createMockElement('custom', {\n * text: 'Hello World',\n * fontSize: 48,\n * fontColor: '#FF0000'\n * });\n * ```\n */\nexport function createMockElement(\n transformType: TransformType = 'custom',\n overrides: Partial<TextElement> = {}\n): TextElement {\n // Get the correct concrete class from registry\n const transformDef = getTransformById(transformType);\n if (!transformDef || !transformDef.Component) {\n throw new Error(`Transform type \"${transformType}\" not found in registry`);\n }\n\n // Create element using the concrete class\n const element = new transformDef.Component({\n transformType,\n text: 'Test Text',\n fontSize: 32,\n color: '#000000',\n fontFamily: 'Arial',\n x: 100,\n y: 100,\n rotation: 0,\n ...overrides,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- test utility: overrides merge Partial<TextElement> properties with config, which are structurally compatible but not type-assignable\n } as any);\n\n return element as TextElement;\n}\n\n/**\n * Create a mock image element\n *\n * @example\n * ```tsx\n * const image = createMockImageElement({\n * imageUrl: 'data:image/png;base64,...',\n * width: 200,\n * height: 200\n * });\n * ```\n */\nexport function createMockImageElement(\n overrides: Partial<ImageElementConfig> = {}\n): ImageElement {\n const element = new ImageElement({\n imageUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==',\n imageAspectRatio: 1,\n x: 100,\n y: 100,\n rotation: 0,\n ...overrides,\n });\n\n return element;\n}\n\n/**\n * Create a mock artboard\n *\n * @example\n * ```tsx\n * const artboard = createMockArtboard({\n * name: 'Front',\n * width: 1200,\n * height: 1200,\n * backgroundColor: '#FFFFFF'\n * });\n * ```\n */\nexport function createMockArtboard(\n overrides: Partial<{\n name: string;\n width: number;\n height: number;\n x: number;\n y: number;\n backgroundColor: string;\n }> = {}\n): ArtboardElement {\n const artboard = new ArtboardElement({\n name: 'Test Artboard',\n width: 1200,\n height: 1200,\n x: 0,\n y: 0,\n backgroundColor: '#FFFFFF',\n ...overrides,\n });\n\n return artboard;\n}\n\n/**\n * Wait for a condition to become true\n * Useful for async testing\n *\n * @example\n * ```tsx\n * await waitFor(() => screen.getByText('Loaded'), 5000);\n * ```\n */\nexport async function waitFor(\n condition: () => boolean,\n timeout = 5000,\n interval = 100\n): Promise<void> {\n const startTime = Date.now();\n\n while (!condition()) {\n if (Date.now() - startTime > timeout) {\n throw new Error(`Timeout waiting for condition after ${timeout}ms`);\n }\n await new Promise(resolve => setTimeout(resolve, interval));\n }\n}\n\n/**\n * Wait for an export to complete\n * Polls until dataUrl is available\n *\n * @example\n * ```tsx\n * const dataUrl = await waitForExport('artboard-1', 5000);\n * expect(dataUrl).toContain('data:image/png');\n * ```\n */\nexport async function waitForExport(\n _artboardId: string,\n timeout = 5000\n): Promise<string | null> {\n let dataUrl: string | null = null;\n\n await waitFor(() => {\n // Check if export completed (this would need to be implemented based on your export state)\n // For now, just return false as a placeholder\n return false;\n }, timeout);\n\n return dataUrl;\n}\n\n/**\n * Simulate a keyboard event\n * Useful for testing keyboard shortcuts\n *\n * @example\n * ```tsx\n * simulateKeyPress('c', { meta: true }); // Cmd+C\n * ```\n */\nexport function simulateKeyPress(\n key: string,\n options: {\n ctrl?: boolean;\n shift?: boolean;\n alt?: boolean;\n meta?: boolean;\n } = {}\n): void {\n const event = new KeyboardEvent('keydown', {\n key,\n ctrlKey: options.ctrl,\n shiftKey: options.shift,\n altKey: options.alt,\n metaKey: options.meta,\n bubbles: true,\n cancelable: true,\n });\n\n document.dispatchEvent(event);\n}\n\n/**\n * Create a mock canvas element for testing\n * Returns an HTMLCanvasElement with mocked context\n *\n * @example\n * ```tsx\n * const canvas = createMockCanvas(800, 600);\n * const ctx = canvas.getContext('2d');\n * ```\n */\nexport function createMockCanvas(\n width = 800,\n height = 600\n): HTMLCanvasElement {\n const canvas = document.createElement('canvas');\n canvas.width = width;\n canvas.height = height;\n\n return canvas;\n}\n\n/**\n * Assert that an element has certain properties\n * Useful for programmatic assertions\n *\n * @example\n * ```tsx\n * assertElementProperties(element, {\n * text: 'Hello',\n * fontSize: 48,\n * fontColor: '#FF0000'\n * });\n * ```\n */\nexport function assertElementProperties(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Test utility: accepts any element type and checks arbitrary properties\n element: any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Test utility: expected values can be any type\n expected: Record<string, any>\n): void {\n Object.entries(expected).forEach(([key, value]) => {\n if (element[key] !== value) {\n throw new Error(\n `Expected element.${key} to be ${value}, got ${element[key]}`\n );\n }\n });\n}\n\n/**\n * Get element bounding box for testing\n * Returns computed bounds from the element\n *\n * @example\n * ```tsx\n * const bounds = getElementBounds(element);\n * expect(bounds.width).toBeGreaterThan(0);\n * ```\n */\nexport function getElementBounds(element: TextElement | ImageElement): {\n x: number;\n y: number;\n width: number;\n height: number;\n} {\n const bbox = element.getBoundingBox();\n\n return {\n x: bbox.x,\n y: bbox.y,\n width: bbox.width,\n height: bbox.height,\n };\n}\n","/**\n * `assertRenders(design, product, opts)` — the TWO-RENDER live contract check\n * (agent-DX decision F4, ADR-0085 plan).\n *\n * WHY TWO RENDERS: \"the URL returns an image\" can't catch a DEAD BINDING — a\n * wrong layer name still renders the seed beautifully. So this renders the\n * design twice: once as seeded, once with the personalization bindings\n * mutated, and asserts the encoded image BYTES differ (mockup delivery is\n * deterministic per state, so byte-identical means pixel-identical means the\n * mutation never reached the render).\n *\n * What it proves, in order:\n * 1. the seed design renders: HTTP 200 + real raster bytes (non-blank);\n * 2. the mutated design renders the same way;\n * 3. the two renders DIFFER — the binding is alive.\n *\n * Failures are the structured error contract (E3), never prose-only:\n * - `E_ASSET_FORBIDDEN` — the shop's asset-origin allowlist denied a design\n * asset (translated from the server's 403; `data.failedAssets` names it);\n * - `E_RENDER_FAILED` — render error / timeout / non-image response;\n * - `E_BINDING_INERT` — both renders byte-identical (dead binding);\n * - `E_NO_MUTABLE_BINDING` — nothing to mutate and no `mutate` given.\n * - The SDK's `SHOP_NOT_PROPAGATED` passes through: a freshly minted shop\n * that never becomes visible is an environment fault, named as such.\n *\n * This talks to the REAL realtime render path (network). Use it in nightly /\n * acceptance jobs and agent verify loops — per-PR unit tests should mock the\n * SDK transport instead (plan: per-PR replay, nightly network-real).\n */\n\nimport {\n RenderSession,\n fetchMockupImage,\n mintRealtimeGrant,\n type MockupResult,\n type RealtimeGrant,\n type RenderProduct,\n} from '@snowcone-app/sdk';\nimport { isSnowconeSdkError } from '@snowcone-app/sdk';\nimport { serializeStateForServer } from '../rendering/serialize-for-server.js';\nimport { EditorError } from '../errors/editorError.js';\nimport type { DesignState } from '../components/editor/designStateStore.js';\n\n/** Anything `design()` produces (or a compatible shape). */\nexport interface RenderableDesign {\n toJSON(): DesignState;\n}\n\nexport interface AssertRendersOptions {\n /** Publishable shop id (= shop.id). */\n shop: string;\n /** Secret API key (sk_) for the grant; omit for the keyless publishable\n * path (sandbox/trial shops — the F1 bootstrap default). */\n apiKey?: string;\n /** Pre-fetched grant or grant factory — overrides the mint entirely. */\n grant?: RealtimeGrant | (() => Promise<RealtimeGrant>);\n /** Backend base for the keyless/sk grant mint (defaults to prod). */\n grantBase?: string;\n /** Override the realtime WS endpoint. */\n wsUrl?: string;\n /**\n * Produce the mutated state for the second render. Default: rewrite the\n * text of EVERY named text layer to a sentinel (`ASSERT_RENDERS_<name>`).\n * Throws `E_NO_MUTABLE_BINDING` if the design has no named text layer and\n * no override is given.\n */\n mutate?: (seed: DesignState) => DesignState;\n /** Per-render timeout (ms). Default 30_000. */\n timeoutMs?: number;\n /** Override fetch for the image downloads (tests). */\n fetchImpl?: typeof fetch;\n}\n\nexport interface AssertRendersResult {\n /** The seed render's mockup URL + encoded size. */\n seed: { url: string; bytes: number; kind: string };\n /** The mutated render's mockup URL + encoded size. */\n mutated: { url: string; bytes: number; kind: string };\n}\n\n/** Default mutation: every NAMED text layer gets a sentinel value. */\nexport function mutateNamedTextLayers(seed: DesignState): DesignState {\n let mutatedAny = false;\n const elements = seed.elements.map((el) => {\n const name = (el as { name?: string }).name;\n const text = (el as { text?: string }).text;\n if (!name || typeof text !== 'string') return el;\n mutatedAny = true;\n return { ...el, text: `ASSERT_RENDERS_${name.toUpperCase()}` } as typeof el;\n });\n if (!mutatedAny) {\n throw new EditorError(\n 'E_NO_MUTABLE_BINDING',\n 'this design has no NAMED text layer to mutate for the two-render check. Name one ' +\n '(design().text(\"…\", { name: \"headline\" })) or pass opts.mutate to define the mutation.',\n { docSlug: 'embed-mode' },\n );\n }\n return { ...seed, elements };\n}\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.byteLength !== b.byteLength) return false;\n for (let i = 0; i < a.byteLength; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\n/**\n * Render one state on a FRESH session and resolve the first mockup result.\n * One session per render on purpose: a session keeps emitting trailing mockup\n * results (multi-mockup products emit per scene), so reusing it for the\n * second render could resolve the mutated phase with a stale seed emission —\n * and with content-addressed delivery a dead binding makes the two\n * indistinguishable by URL. A fresh session has no history to confuse.\n */\nasync function renderOnce(\n makeSession: () => RenderSession,\n placement: string,\n state: DesignState,\n timeoutMs: number,\n label: 'seed' | 'mutated',\n): Promise<MockupResult> {\n const session = makeSession();\n try {\n return await new Promise<MockupResult>((resolve, reject) => {\n const timer = setTimeout(() => {\n reject(\n new EditorError('E_RENDER_FAILED', `the ${label} render produced no mockup within ${timeoutMs}ms.`, {\n phase: label,\n timeoutMs,\n }),\n );\n }, timeoutMs);\n session.onMockups((results) => {\n const withImage = results.find((r) => r.imageUrl);\n if (!withImage) return;\n clearTimeout(timer);\n resolve(withImage);\n });\n session.onError((message) => {\n clearTimeout(timer);\n reject(new EditorError('E_RENDER_FAILED', `the ${label} render failed: ${message}`, { phase: label, error: message }));\n });\n void session.renderState(placement, serializeStateForServer(state)).catch((err) => {\n clearTimeout(timer);\n const message = err instanceof Error ? err.message : String(err);\n reject(new EditorError('E_RENDER_FAILED', `the ${label} render failed to dispatch: ${message}`, { phase: label, error: message }));\n });\n });\n } finally {\n session.close();\n }\n}\n\n/** Fetch + validate one rendered image, translating SDK failures (asset-403 →\n * `E_ASSET_FORBIDDEN`) into the editor error contract. */\nasync function fetchRender(url: string, label: 'seed' | 'mutated', opts: AssertRendersOptions): Promise<{ bytes: Uint8Array; kind: string }> {\n try {\n const img = await fetchMockupImage(url, {\n ...(opts.fetchImpl ? { fetchImpl: opts.fetchImpl } : {}),\n });\n return { bytes: img.bytes, kind: img.kind };\n } catch (err) {\n if (isSnowconeSdkError(err)) {\n if (err.code === 'ASSET_FORBIDDEN') {\n throw new EditorError(\n 'E_ASSET_FORBIDDEN',\n `the shop's asset-origin allowlist denied an asset in this design (${label} render). ` +\n `Allow the asset's origin on the shop (or host it on the shop's storage origin).`,\n { phase: label, url, failedAssets: err.data.failedAssets, docSlug: 'embed-mode' },\n );\n }\n if (err.code === 'SHOP_NOT_PROPAGATED') throw err; // already structured + named\n throw new EditorError('E_RENDER_FAILED', `the ${label} render's image fetch failed: ${err.message}`, {\n phase: label,\n url,\n ...err.data,\n });\n }\n throw err;\n }\n}\n\n/**\n * Prove a design + product render AND that the design's bindings are alive\n * (two-render contract). See the module doc for the failure catalog.\n *\n * Stable since ADR-0085 P4 (the default editor is rebuilt from this public\n * surface, CI-gated); additive-only from here.\n */\nexport async function assertRenders(\n design: RenderableDesign,\n product: RenderProduct,\n opts: AssertRendersOptions,\n): Promise<AssertRendersResult> {\n const timeoutMs = opts.timeoutMs ?? 30_000;\n const seed = design.toJSON();\n const placement = seed.activeArtboard;\n const mutated = (opts.mutate ?? mutateNamedTextLayers)(seed);\n\n const grant = opts.grant;\n const getToken =\n typeof grant === 'function'\n ? grant\n : grant\n ? () => Promise.resolve(grant)\n : () =>\n mintRealtimeGrant({\n shop: opts.shop,\n ...(opts.apiKey ? { apiKey: opts.apiKey } : {}),\n ...(opts.grantBase ? { base: opts.grantBase } : {}),\n ...(opts.fetchImpl ? { fetch: opts.fetchImpl } : {}),\n });\n\n const makeSession = () =>\n new RenderSession({\n shop: opts.shop,\n product,\n ...(opts.wsUrl ? { wsUrl: opts.wsUrl } : {}),\n getToken,\n });\n\n const seedResult = await renderOnce(makeSession, placement, seed, timeoutMs, 'seed');\n const seedImage = await fetchRender(seedResult.imageUrl!, 'seed', opts);\n\n const mutatedResult = await renderOnce(makeSession, placement, mutated, timeoutMs, 'mutated');\n const mutatedImage = await fetchRender(mutatedResult.imageUrl!, 'mutated', opts);\n\n if (bytesEqual(seedImage.bytes, mutatedImage.bytes)) {\n throw new EditorError(\n 'E_BINDING_INERT',\n 'the mutated render is byte-identical to the seed render — the mutation never reached ' +\n 'the server, so the binding under test is DEAD. Usual causes: the mutated layer name ' +\n \"doesn't exist in the design (check design.layer() names), or opts.mutate returned the \" +\n 'seed unchanged.',\n {\n seedUrl: seedResult.imageUrl,\n mutatedUrl: mutatedResult.imageUrl,\n bytes: seedImage.bytes.byteLength,\n docSlug: 'embed-mode',\n },\n );\n }\n\n return {\n seed: { url: seedResult.imageUrl!, bytes: seedImage.bytes.byteLength, kind: seedImage.kind },\n mutated: { url: mutatedResult.imageUrl!, bytes: mutatedImage.bytes.byteLength, kind: mutatedImage.kind },\n };\n}\n","/**\n * Deterministic failure-mode fixtures (ADR-0085 plan, P2 — the magic-test-card\n * equivalent): trigger each commerce/render failure ON DEMAND so integrators\n * build their error UI against real failures instead of waiting for prod to\n * produce one.\n *\n * These are the CLIENT-ACHIEVABLE fixtures — each works against any shop\n * (including a fresh sandbox shop) with no server cooperation:\n *\n * - {@link test403Design} — asset-origin allowlist denial. References an\n * asset on an origin no shop allowlists, so the server's asset fetch is\n * denied deterministically. Surfaces as a render error (live path) or\n * `E_ASSET_FORBIDDEN` from `assertRenders`.\n * - {@link testIncompleteDesign} — Buy completeness failure. A design whose\n * only personalization layer still carries its seed value, so\n * `<Editor.Buy>` gates with `layer-seed:<name>` (and `layer:<name>` once\n * cleared). Pair with `<Editor.TextField layer={d.layer('name')} />`.\n * - {@link failingGrant} — grant failure. A grant factory that always\n * rejects; pass as `<Editor.Root grant={failingGrant()}>` to exercise the\n * \"grant fetch fails\" surface (`onRenderError` + the Preview's\n * `data-sc-part=\"preview-error\"` state).\n *\n * Server-triggered fixtures (a `test-slow` product for the timeout path, a\n * forced render-error token) need render-edge cooperation and are tracked\n * separately — they are NOT silently stubbed here.\n */\n\nimport { design } from '../design/design-builder.js';\nimport type { RealtimeGrant } from '@snowcone-app/sdk';\n\n/**\n * An origin that is deliberately on NO shop's asset-origin allowlist. The\n * `.invalid` TLD is reserved (RFC 2606) — it can never resolve, and the\n * allowlist check denies it before any fetch is attempted, so the failure is\n * deterministic and free.\n */\nexport const TEST_403_ASSET_URL = 'https://assets.test-403.invalid/denied.png';\n\n/**\n * A design whose background asset the shop's allowlist is guaranteed to deny —\n * the deterministic allowlist-denial (403) trigger.\n */\nexport function test403Design() {\n return design({ name: 'Front', width: 1000, height: 1000 })\n .background(TEST_403_ASSET_URL, { aspectRatio: 1, name: 'art' })\n .text('ALLOWLIST DENIAL FIXTURE', { anchor: 'top', name: 'headline' });\n}\n\n/**\n * A design that gates `<Editor.Buy>` out of the box: its one personalization\n * layer (`'name'`, seed `'YOUR NAME'`) is required and still equals its seed,\n * so Buy renders `data-sc-buy-state=\"incomplete\"` with\n * `data-sc-buy-missing=\"layer-seed:name\"` until a real value is typed.\n */\nexport function testIncompleteDesign() {\n return design({ name: 'Front', width: 1000, height: 1000 })\n .text('YOUR NAME', { anchor: 'center', name: 'name' });\n}\n\n/**\n * A grant factory that always rejects — the deterministic \"grant fetch\n * failed\" trigger. The rejection reason is stable for assertions.\n */\nexport function failingGrant(reason = 'failing-grant fixture: grant endpoint unavailable'): () => Promise<RealtimeGrant> {\n return () => Promise.reject(new Error(reason));\n}\n"],"names":["MockEditorProvider","children","_initialElements","initialArtboards","_initialSelection","_initialMultiSelection","initialArtboardConfig","_artboardManager","useState","manager","ArtboardManager","artboard","ThemeProvider","jsx","EditorProvider","MockEditorProviderWithState","createMockElement","transformType","overrides","transformDef","getTransformById","createMockImageElement","ImageElement","createMockArtboard","ArtboardElement","waitFor","condition","timeout","interval","startTime","resolve","waitForExport","_artboardId","dataUrl","simulateKeyPress","key","options","event","createMockCanvas","width","height","canvas","assertElementProperties","element","expected","value","getElementBounds","bbox","mutateNamedTextLayers","seed","mutatedAny","elements","el","name","text","EditorError","bytesEqual","a","b","i","renderOnce","makeSession","placement","state","timeoutMs","label","session","reject","timer","results","withImage","r","message","serializeStateForServer","err","fetchRender","url","opts","img","fetchMockupImage","isSnowconeSdkError","assertRenders","design","product","mutated","grant","getToken","mintRealtimeGrant","RenderSession","seedResult","seedImage","mutatedResult","mutatedImage","TEST_403_ASSET_URL","test403Design","testIncompleteDesign","failingGrant","reason"],"mappings":";;;;;;;AAuEO,MAAMA,IAAwD,CAAC;AAAA,EACpE,UAAAC;AAAA,EACA,iBAAiBC,IAAmB,CAAA;AAAA,EACpC,kBAAAC;AAAA,EACA,kBAAkBC,IAAoB;AAAA,EACtC,uBAAuBC,IAAyB,CAAA;AAAA,EAChD,uBAAAC,IAAwB,CAAA;AAC1B,MAAM;AAEJ,QAAM,CAACC,CAAgB,IAAIC,EAAS,MAAM;AACxC,UAAMC,IAAU,IAAIC,EAAA;AAEpB,WAAIP,KAAoBA,EAAiB,SAAS,IAEhDA,EAAiB,QAAQ,CAAAQ,MAAY;AACnC,MAAAF,EAAQ,eAAe;AAA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,SAASkC,EAAW;AAAA,QACpB,YAAYE,EAAc;AAAA,QAC1B,OAAOD,EAAU,MAAM;AAAA,QACvB,SAAS;AAAA,MAAA;AAAA,IACX;AAIJ,SAAO;AAAA,IACL,MAAM,EAAE,KAAKD,EAAW,UAAW,OAAOC,EAAU,MAAM,YAAY,MAAMA,EAAU,KAAA;AAAA,IACtF,SAAS,EAAE,KAAKC,EAAc,UAAW,OAAOC,EAAa,MAAM,YAAY,MAAMA,EAAa,KAAA;AAAA,EAAK;AAE3G;ACtNO,MAAMC,IAAqB;AAM3B,SAASC,IAAgB;AAC9B,SAAOZ,EAAO,EAAE,MAAM,SAAS,OAAO,KAAM,QAAQ,IAAA,CAAM,EACvD,WAAWW,GAAoB,EAAE,aAAa,GAAG,MAAM,MAAA,CAAO,EAC9D,KAAK,4BAA4B,EAAE,QAAQ,OAAO,MAAM,WAAA,CAAY;AACzE;AAQO,SAASE,IAAuB;AACrC,SAAOb,EAAO,EAAE,MAAM,SAAS,OAAO,KAAM,QAAQ,IAAA,CAAM,EACvD,KAAK,aAAa,EAAE,QAAQ,UAAU,MAAM,QAAQ;AACzD;AAMO,SAASc,GAAaC,IAAS,qDAAmF;AACvH,SAAO,MAAM,QAAQ,OAAO,IAAI,MAAMA,CAAM,CAAC;AAC/C;"}
1
+ {"version":3,"file":"testing.mjs","sources":["../src/testing/MockEditorProvider.tsx","../src/testing/utils.ts","../src/testing/assertRenders.ts","../src/testing/failureFixtures.ts"],"sourcesContent":["/**\n * MockEditorProvider - Lightweight mock for testing custom components\n * Compatible with Vitest (does not require Jest)\n *\n * @example\n * ```tsx\n * import { render } from '@testing-library/react';\n * import { MockEditorProvider } from '@snowcone-app/canvas/embed';\n *\n * test('my component renders', () => {\n * render(\n * <MockEditorProvider>\n * <MyCustomComponent />\n * </MockEditorProvider>\n * );\n * });\n * ```\n */\n\nimport React, { useState, ReactNode } from 'react';\nimport { EditorProvider } from '../contexts/EditorContext.js';\nimport { ThemeProvider } from '../contexts/ThemeContext.js';\nimport { ArtboardManager } from '../core/ArtboardManager.js';\nimport { ArtboardElement } from '../core/ArtboardElement.js';\nimport type { TextElement } from '../core/TextElement.js';\nimport type { ImageElement } from '../core/ImageElement.js';\nimport type { GroupElement } from '../core/GroupElement.js';\nimport type { ShapeElement } from '../core/ShapeElement.js';\n\nexport type MockEditorElement = TextElement | ImageElement | GroupElement | ShapeElement;\n\nexport interface MockEditorProviderProps {\n children: ReactNode;\n\n /**\n * Initial elements to populate the editor\n */\n initialElements?: MockEditorElement[];\n\n /**\n * Initial artboards (default: one artboard)\n */\n initialArtboards?: ArtboardElement[];\n\n /**\n * Initial selection\n */\n initialSelection?: string | null;\n\n /**\n * Initial multi-selection\n */\n initialMultiSelection?: string[];\n\n /**\n * Initial artboard configuration\n */\n initialArtboardConfig?: {\n name?: string;\n width?: number;\n height?: number;\n backgroundColor?: string;\n };\n}\n\n/**\n * MockEditorProvider - Wraps EditorProvider with test-friendly defaults\n *\n * This is a lightweight wrapper that provides the same EditorContext\n * as the real app, making it perfect for testing custom components.\n */\nexport const MockEditorProvider: React.FC<MockEditorProviderProps> = ({\n children,\n initialElements: _initialElements = [],\n initialArtboards,\n initialSelection: _initialSelection = null,\n initialMultiSelection: _initialMultiSelection = [],\n initialArtboardConfig = {},\n}) => {\n // Create artboard manager if artboards provided\n const [_artboardManager] = useState(() => {\n const manager = new ArtboardManager();\n\n if (initialArtboards && initialArtboards.length > 0) {\n // Use provided artboards\n initialArtboards.forEach(artboard => {\n manager.createArtboard({\n name: artboard.name,\n width: artboard.width,\n height: artboard.height,\n backgroundColor: artboard.backgroundColor,\n });\n });\n } else {\n // Create default artboard\n manager.createArtboard({\n name: 'Test Artboard',\n width: 1200,\n height: 1200,\n backgroundColor: '#FFFFFF',\n ...initialArtboardConfig,\n });\n }\n\n return manager;\n });\n\n // Simple wrapper that passes children through to real EditorProvider\n // The EditorProvider will handle all the state management\n // ThemeProvider is required because CanvasEditor uses useTheme()\n return (\n <ThemeProvider>\n <EditorProvider\n initialArtboardConfig={initialArtboardConfig}\n >\n {children}\n </EditorProvider>\n </ThemeProvider>\n );\n};\n\n/**\n * MockEditorProviderWithState - For tests that need to control state directly\n *\n * Use this when you need fine-grained control over the editor state.\n * Most tests should use the simpler MockEditorProvider above.\n */\nexport const MockEditorProviderWithState: React.FC<MockEditorProviderProps> = ({\n children,\n initialElements: _initialElements = [],\n initialSelection: _initialSelection = null,\n initialMultiSelection: _initialMultiSelection = [],\n initialArtboardConfig = {},\n}) => {\n return (\n <ThemeProvider>\n <EditorProvider initialArtboardConfig={initialArtboardConfig}>\n {children}\n </EditorProvider>\n </ThemeProvider>\n );\n};\n","/**\n * Testing Utilities - Helpers for creating mock elements and artboards\n * Compatible with Vitest\n */\n\nimport { TextElement } from '../core/TextElement.js';\nimport { ImageElement } from '../core/ImageElement.js';\nimport { ArtboardElement } from '../core/ArtboardElement.js';\nimport { getTransformById } from '../transforms/registry.js';\nimport type { TransformType, ImageElementConfig } from '../types/index.js';\n\n/**\n * Create a mock text element with sensible defaults\n *\n * @example\n * ```tsx\n * const element = createMockElement('custom', {\n * text: 'Hello World',\n * fontSize: 48,\n * fontColor: '#FF0000'\n * });\n * ```\n */\nexport function createMockElement(\n transformType: TransformType = 'custom',\n overrides: Partial<TextElement> = {}\n): TextElement {\n // Get the correct concrete class from registry\n const transformDef = getTransformById(transformType);\n if (!transformDef || !transformDef.Component) {\n throw new Error(`Transform type \"${transformType}\" not found in registry`);\n }\n\n // Create element using the concrete class\n const element = new transformDef.Component({\n transformType,\n text: 'Test Text',\n fontSize: 32,\n color: '#000000',\n fontFamily: 'Arial',\n x: 100,\n y: 100,\n rotation: 0,\n ...overrides,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- test utility: overrides merge Partial<TextElement> properties with config, which are structurally compatible but not type-assignable\n } as any);\n\n return element as TextElement;\n}\n\n/**\n * Create a mock image element\n *\n * @example\n * ```tsx\n * const image = createMockImageElement({\n * imageUrl: 'data:image/png;base64,...',\n * width: 200,\n * height: 200\n * });\n * ```\n */\nexport function createMockImageElement(\n overrides: Partial<ImageElementConfig> = {}\n): ImageElement {\n const element = new ImageElement({\n imageUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==',\n imageAspectRatio: 1,\n x: 100,\n y: 100,\n rotation: 0,\n ...overrides,\n });\n\n return element;\n}\n\n/**\n * Create a mock artboard\n *\n * @example\n * ```tsx\n * const artboard = createMockArtboard({\n * name: 'Front',\n * width: 1200,\n * height: 1200,\n * backgroundColor: '#FFFFFF'\n * });\n * ```\n */\nexport function createMockArtboard(\n overrides: Partial<{\n name: string;\n width: number;\n height: number;\n x: number;\n y: number;\n backgroundColor: string;\n }> = {}\n): ArtboardElement {\n const artboard = new ArtboardElement({\n name: 'Test Artboard',\n width: 1200,\n height: 1200,\n x: 0,\n y: 0,\n backgroundColor: '#FFFFFF',\n ...overrides,\n });\n\n return artboard;\n}\n\n/**\n * Wait for a condition to become true\n * Useful for async testing\n *\n * @example\n * ```tsx\n * await waitFor(() => screen.getByText('Loaded'), 5000);\n * ```\n */\nexport async function waitFor(\n condition: () => boolean,\n timeout = 5000,\n interval = 100\n): Promise<void> {\n const startTime = Date.now();\n\n while (!condition()) {\n if (Date.now() - startTime > timeout) {\n throw new Error(`Timeout waiting for condition after ${timeout}ms`);\n }\n await new Promise(resolve => setTimeout(resolve, interval));\n }\n}\n\n/**\n * Wait for an export to complete\n * Polls until dataUrl is available\n *\n * @example\n * ```tsx\n * const dataUrl = await waitForExport('artboard-1', 5000);\n * expect(dataUrl).toContain('data:image/png');\n * ```\n */\nexport async function waitForExport(\n _artboardId: string,\n timeout = 5000\n): Promise<string | null> {\n let dataUrl: string | null = null;\n\n await waitFor(() => {\n // Check if export completed (this would need to be implemented based on your export state)\n // For now, just return false as a placeholder\n return false;\n }, timeout);\n\n return dataUrl;\n}\n\n/**\n * Simulate a keyboard event\n * Useful for testing keyboard shortcuts\n *\n * @example\n * ```tsx\n * simulateKeyPress('c', { meta: true }); // Cmd+C\n * ```\n */\nexport function simulateKeyPress(\n key: string,\n options: {\n ctrl?: boolean;\n shift?: boolean;\n alt?: boolean;\n meta?: boolean;\n } = {}\n): void {\n const event = new KeyboardEvent('keydown', {\n key,\n ctrlKey: options.ctrl,\n shiftKey: options.shift,\n altKey: options.alt,\n metaKey: options.meta,\n bubbles: true,\n cancelable: true,\n });\n\n document.dispatchEvent(event);\n}\n\n/**\n * Create a mock canvas element for testing\n * Returns an HTMLCanvasElement with mocked context\n *\n * @example\n * ```tsx\n * const canvas = createMockCanvas(800, 600);\n * const ctx = canvas.getContext('2d');\n * ```\n */\nexport function createMockCanvas(\n width = 800,\n height = 600\n): HTMLCanvasElement {\n const canvas = document.createElement('canvas');\n canvas.width = width;\n canvas.height = height;\n\n return canvas;\n}\n\n/**\n * Assert that an element has certain properties\n * Useful for programmatic assertions\n *\n * @example\n * ```tsx\n * assertElementProperties(element, {\n * text: 'Hello',\n * fontSize: 48,\n * fontColor: '#FF0000'\n * });\n * ```\n */\nexport function assertElementProperties(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Test utility: accepts any element type and checks arbitrary properties\n element: any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Test utility: expected values can be any type\n expected: Record<string, any>\n): void {\n Object.entries(expected).forEach(([key, value]) => {\n if (element[key] !== value) {\n throw new Error(\n `Expected element.${key} to be ${value}, got ${element[key]}`\n );\n }\n });\n}\n\n/**\n * Get element bounding box for testing\n * Returns computed bounds from the element\n *\n * @example\n * ```tsx\n * const bounds = getElementBounds(element);\n * expect(bounds.width).toBeGreaterThan(0);\n * ```\n */\nexport function getElementBounds(element: TextElement | ImageElement): {\n x: number;\n y: number;\n width: number;\n height: number;\n} {\n const bbox = element.getBoundingBox();\n\n return {\n x: bbox.x,\n y: bbox.y,\n width: bbox.width,\n height: bbox.height,\n };\n}\n","/**\n * `assertRenders(design, product, opts)` — the TWO-RENDER live contract check\n * (agent-DX decision F4, ADR-0085 plan).\n *\n * WHY TWO RENDERS: \"the URL returns an image\" can't catch a DEAD BINDING — a\n * wrong layer name still renders the seed beautifully. So this renders the\n * design twice: once as seeded, once with the personalization bindings\n * mutated, and asserts the encoded image BYTES differ (mockup delivery is\n * deterministic per state, so byte-identical means pixel-identical means the\n * mutation never reached the render).\n *\n * What it proves, in order:\n * 1. the seed design renders: HTTP 200 + real raster bytes (non-blank);\n * 2. the mutated design renders the same way;\n * 3. the two renders DIFFER — the binding is alive.\n *\n * Failures are the structured error contract (E3), never prose-only:\n * - `E_ASSET_FORBIDDEN` — the shop's asset-origin allowlist denied a design\n * asset (translated from the server's 403; `data.failedAssets` names it);\n * - `E_RENDER_FAILED` — render error / timeout / non-image response;\n * - `E_BINDING_INERT` — both renders byte-identical (dead binding);\n * - `E_NO_MUTABLE_BINDING` — nothing to mutate and no `mutate` given.\n * - The SDK's `SHOP_NOT_PROPAGATED` passes through: a freshly minted shop\n * that never becomes visible is an environment fault, named as such.\n *\n * This talks to the REAL realtime render path (network). Use it in nightly /\n * acceptance jobs and agent verify loops — per-PR unit tests should mock the\n * SDK transport instead (plan: per-PR replay, nightly network-real).\n */\n\nimport {\n RenderSession,\n fetchMockupImage,\n mintRealtimeGrant,\n type MockupResult,\n type RealtimeGrant,\n type RenderProduct,\n} from '@snowcone-app/sdk';\nimport { isSnowconeSdkError } from '@snowcone-app/sdk';\nimport { serializeStateForServer } from '../rendering/serialize-for-server.js';\nimport { EditorError } from '../errors/editorError.js';\nimport type { DesignState } from '../components/editor/designStateStore.js';\n\n/** Anything `design()` produces (or a compatible shape). */\nexport interface RenderableDesign {\n toJSON(): DesignState;\n}\n\nexport interface AssertRendersOptions {\n /** Publishable shop id (= shop.id). */\n shop: string;\n /** Secret API key (sk_) for the grant; omit for the keyless publishable\n * path (sandbox/trial shops — the F1 bootstrap default). */\n apiKey?: string;\n /** Pre-fetched grant or grant factory — overrides the mint entirely. */\n grant?: RealtimeGrant | (() => Promise<RealtimeGrant>);\n /** Backend base for the keyless/sk grant mint (defaults to prod). */\n grantBase?: string;\n /** Override the realtime WS endpoint. */\n wsUrl?: string;\n /**\n * Produce the mutated state for the second render. Default: rewrite the\n * text of EVERY named text layer to a sentinel (`ASSERT_RENDERS_<name>`).\n * Throws `E_NO_MUTABLE_BINDING` if the design has no named text layer and\n * no override is given.\n */\n mutate?: (seed: DesignState) => DesignState;\n /** Per-render timeout (ms). Default 30_000. */\n timeoutMs?: number;\n /** Override fetch for the image downloads (tests). */\n fetchImpl?: typeof fetch;\n}\n\nexport interface AssertRendersResult {\n /** The seed render's mockup URL + encoded size. */\n seed: { url: string; bytes: number; kind: string };\n /** The mutated render's mockup URL + encoded size. */\n mutated: { url: string; bytes: number; kind: string };\n}\n\n/** Default mutation: every NAMED text layer gets a sentinel value. */\nexport function mutateNamedTextLayers(seed: DesignState): DesignState {\n let mutatedAny = false;\n const elements = seed.elements.map((el) => {\n const name = (el as { name?: string }).name;\n const text = (el as { text?: string }).text;\n if (!name || typeof text !== 'string') return el;\n mutatedAny = true;\n return { ...el, text: `ASSERT_RENDERS_${name.toUpperCase()}` } as typeof el;\n });\n if (!mutatedAny) {\n throw new EditorError(\n 'E_NO_MUTABLE_BINDING',\n 'this design has no NAMED text layer to mutate for the two-render check. Name one ' +\n '(design().text(\"…\", { name: \"headline\" })) or pass opts.mutate to define the mutation.',\n { docSlug: 'embed-mode' },\n );\n }\n return { ...seed, elements };\n}\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.byteLength !== b.byteLength) return false;\n for (let i = 0; i < a.byteLength; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\n/**\n * Render one state on a FRESH session and resolve the first mockup result.\n * One session per render on purpose: a session keeps emitting trailing mockup\n * results (multi-mockup products emit per scene), so reusing it for the\n * second render could resolve the mutated phase with a stale seed emission —\n * and with content-addressed delivery a dead binding makes the two\n * indistinguishable by URL. A fresh session has no history to confuse.\n */\nasync function renderOnce(\n makeSession: () => RenderSession,\n placement: string,\n state: DesignState,\n timeoutMs: number,\n label: 'seed' | 'mutated',\n): Promise<MockupResult> {\n const session = makeSession();\n try {\n return await new Promise<MockupResult>((resolve, reject) => {\n const timer = setTimeout(() => {\n reject(\n new EditorError('E_RENDER_FAILED', `the ${label} render produced no mockup within ${timeoutMs}ms.`, {\n phase: label,\n timeoutMs,\n }),\n );\n }, timeoutMs);\n session.onMockups((results) => {\n const withImage = results.find((r) => r.imageUrl);\n if (!withImage) return;\n clearTimeout(timer);\n resolve(withImage);\n });\n session.onError((message) => {\n clearTimeout(timer);\n reject(new EditorError('E_RENDER_FAILED', `the ${label} render failed: ${message}`, { phase: label, error: message }));\n });\n void session.renderState(placement, serializeStateForServer(state)).catch((err) => {\n clearTimeout(timer);\n const message = err instanceof Error ? err.message : String(err);\n reject(new EditorError('E_RENDER_FAILED', `the ${label} render failed to dispatch: ${message}`, { phase: label, error: message }));\n });\n });\n } finally {\n session.close();\n }\n}\n\n/** Fetch + validate one rendered image, translating SDK failures (asset-403 →\n * `E_ASSET_FORBIDDEN`) into the editor error contract. */\nasync function fetchRender(url: string, label: 'seed' | 'mutated', opts: AssertRendersOptions): Promise<{ bytes: Uint8Array; kind: string }> {\n try {\n const img = await fetchMockupImage(url, {\n ...(opts.fetchImpl ? { fetchImpl: opts.fetchImpl } : {}),\n });\n return { bytes: img.bytes, kind: img.kind };\n } catch (err) {\n if (isSnowconeSdkError(err)) {\n if (err.code === 'ASSET_FORBIDDEN') {\n throw new EditorError(\n 'E_ASSET_FORBIDDEN',\n `the shop's asset-origin allowlist denied an asset in this design (${label} render). ` +\n `Allow the asset's origin on the shop (or host it on the shop's storage origin).`,\n { phase: label, url, failedAssets: err.data.failedAssets, docSlug: 'embed-mode' },\n );\n }\n if (err.code === 'SHOP_NOT_PROPAGATED') throw err; // already structured + named\n throw new EditorError('E_RENDER_FAILED', `the ${label} render's image fetch failed: ${err.message}`, {\n phase: label,\n url,\n ...err.data,\n });\n }\n throw err;\n }\n}\n\n/**\n * Prove a design + product render AND that the design's bindings are alive\n * (two-render contract). See the module doc for the failure catalog.\n *\n * Stable since ADR-0085 P4 (the default editor is rebuilt from this public\n * surface, CI-gated); additive-only from here.\n */\nexport async function assertRenders(\n design: RenderableDesign,\n product: RenderProduct,\n opts: AssertRendersOptions,\n): Promise<AssertRendersResult> {\n const timeoutMs = opts.timeoutMs ?? 30_000;\n const seed = design.toJSON();\n const placement = seed.activeArtboard;\n const mutated = (opts.mutate ?? mutateNamedTextLayers)(seed);\n\n const grant = opts.grant;\n const getToken =\n typeof grant === 'function'\n ? grant\n : grant\n ? () => Promise.resolve(grant)\n : () =>\n mintRealtimeGrant({\n shop: opts.shop,\n ...(opts.apiKey ? { apiKey: opts.apiKey } : {}),\n ...(opts.grantBase ? { base: opts.grantBase } : {}),\n ...(opts.fetchImpl ? { fetch: opts.fetchImpl } : {}),\n });\n\n const makeSession = () =>\n new RenderSession({\n shop: opts.shop,\n product,\n ...(opts.wsUrl ? { wsUrl: opts.wsUrl } : {}),\n getToken,\n });\n\n const seedResult = await renderOnce(makeSession, placement, seed, timeoutMs, 'seed');\n const seedImage = await fetchRender(seedResult.imageUrl!, 'seed', opts);\n\n const mutatedResult = await renderOnce(makeSession, placement, mutated, timeoutMs, 'mutated');\n const mutatedImage = await fetchRender(mutatedResult.imageUrl!, 'mutated', opts);\n\n if (bytesEqual(seedImage.bytes, mutatedImage.bytes)) {\n throw new EditorError(\n 'E_BINDING_INERT',\n 'the mutated render is byte-identical to the seed render — the mutation never reached ' +\n 'the server, so the binding under test is DEAD. Usual causes: the mutated layer name ' +\n \"doesn't exist in the design (check design.layer() names), or opts.mutate returned the \" +\n 'seed unchanged.',\n {\n seedUrl: seedResult.imageUrl,\n mutatedUrl: mutatedResult.imageUrl,\n bytes: seedImage.bytes.byteLength,\n docSlug: 'embed-mode',\n },\n );\n }\n\n return {\n seed: { url: seedResult.imageUrl!, bytes: seedImage.bytes.byteLength, kind: seedImage.kind },\n mutated: { url: mutatedResult.imageUrl!, bytes: mutatedImage.bytes.byteLength, kind: mutatedImage.kind },\n };\n}\n","/**\n * Deterministic failure-mode fixtures (ADR-0085 plan, P2 — the magic-test-card\n * equivalent): trigger each commerce/render failure ON DEMAND so integrators\n * build their error UI against real failures instead of waiting for prod to\n * produce one.\n *\n * These are the CLIENT-ACHIEVABLE fixtures — each works against any shop\n * (including a fresh sandbox shop) with no server cooperation:\n *\n * - {@link test403Design} — asset-origin allowlist denial. References an\n * asset on an origin no shop allowlists, so the server's asset fetch is\n * denied deterministically. Surfaces as a render error (live path) or\n * `E_ASSET_FORBIDDEN` from `assertRenders`.\n * - {@link testIncompleteDesign} — Buy completeness failure. A design whose\n * only personalization layer still carries its seed value, so\n * `<Editor.Buy>` gates with `layer-seed:<name>` (and `layer:<name>` once\n * cleared). Pair with `<Editor.TextField layer={d.layer('name')} />`.\n * - {@link failingGrant} — grant failure. A grant factory that always\n * rejects; pass as `<Editor.Root grant={failingGrant()}>` to exercise the\n * \"grant fetch fails\" surface (`onRenderError` + the Preview's\n * `data-sc-part=\"preview-error\"` state).\n *\n * Server-triggered fixtures (a `test-slow` product for the timeout path, a\n * forced render-error token) need render-edge cooperation and are tracked\n * separately — they are NOT silently stubbed here.\n */\n\nimport { design } from '../design/design-builder.js';\nimport type { RealtimeGrant } from '@snowcone-app/sdk';\n\n/**\n * An origin that is deliberately on NO shop's asset-origin allowlist. The\n * `.invalid` TLD is reserved (RFC 2606) — it can never resolve, and the\n * allowlist check denies it before any fetch is attempted, so the failure is\n * deterministic and free.\n */\nexport const TEST_403_ASSET_URL = 'https://assets.test-403.invalid/denied.png';\n\n/**\n * A design whose background asset the shop's allowlist is guaranteed to deny —\n * the deterministic allowlist-denial (403) trigger.\n */\nexport function test403Design() {\n return design({ name: 'Front', width: 1000, height: 1000 })\n .background(TEST_403_ASSET_URL, { aspectRatio: 1, name: 'art' })\n .text('ALLOWLIST DENIAL FIXTURE', { anchor: 'top', name: 'headline' });\n}\n\n/**\n * A design that gates `<Editor.Buy>` out of the box: its one personalization\n * layer (`'name'`, seed `'YOUR NAME'`) is required and still equals its seed,\n * so Buy renders `data-sc-buy-state=\"incomplete\"` with\n * `data-sc-buy-missing=\"layer-seed:name\"` until a real value is typed.\n */\nexport function testIncompleteDesign() {\n return design({ name: 'Front', width: 1000, height: 1000 })\n .text('YOUR NAME', { anchor: 'center', name: 'name' });\n}\n\n/**\n * A grant factory that always rejects — the deterministic \"grant fetch\n * failed\" trigger. The rejection reason is stable for assertions.\n */\nexport function failingGrant(reason = 'failing-grant fixture: grant endpoint unavailable'): () => Promise<RealtimeGrant> {\n return () => Promise.reject(new Error(reason));\n}\n"],"names":["MockEditorProvider","children","_initialElements","initialArtboards","_initialSelection","_initialMultiSelection","initialArtboardConfig","_artboardManager","useState","manager","ArtboardManager","artboard","ThemeProvider","jsx","EditorProvider","MockEditorProviderWithState","createMockElement","transformType","overrides","transformDef","getTransformById","createMockImageElement","ImageElement","createMockArtboard","ArtboardElement","waitFor","condition","timeout","interval","startTime","resolve","waitForExport","_artboardId","dataUrl","simulateKeyPress","key","options","event","createMockCanvas","width","height","canvas","assertElementProperties","element","expected","value","getElementBounds","bbox","mutateNamedTextLayers","seed","mutatedAny","elements","el","name","text","EditorError","bytesEqual","a","b","i","renderOnce","makeSession","placement","state","timeoutMs","label","session","reject","timer","results","withImage","r","message","serializeStateForServer","err","fetchRender","url","opts","img","fetchMockupImage","isSnowconeSdkError","assertRenders","design","product","mutated","grant","getToken","mintRealtimeGrant","RenderSession","seedResult","seedImage","mutatedResult","mutatedImage","TEST_403_ASSET_URL","test403Design","testIncompleteDesign","failingGrant","reason"],"mappings":";;;;;;;;AAuEO,MAAMA,IAAwD,CAAC;AAAA,EACpE,UAAAC;AAAA,EACA,iBAAiBC,IAAmB,CAAA;AAAA,EACpC,kBAAAC;AAAA,EACA,kBAAkBC,IAAoB;AAAA,EACtC,uBAAuBC,IAAyB,CAAA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