@snowcone-app/canvas 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CanvasStateV1-BQD8fCBU.js +3699 -0
- package/dist/CanvasStateV1-BQD8fCBU.js.map +1 -0
- package/dist/ThemeContext-D9AaUw9v.js +1200 -0
- package/dist/ThemeContext-D9AaUw9v.js.map +1 -0
- package/dist/advanced.mjs +4 -4
- package/dist/api/embed.d.ts +14 -0
- package/dist/components/embed-realtime/RealtimeCanvas.d.ts +24 -1
- package/dist/contexts/EditorContext.d.ts +1 -0
- package/dist/embed.mjs +173 -158
- package/dist/embed.mjs.map +1 -1
- package/dist/index.mjs +47 -51
- package/dist/index.mjs.map +1 -1
- package/dist/internals.mjs +1 -1
- package/dist/rendering/PieceGuideRenderer.d.ts +2 -16
- package/dist/{template-fields-Dw-KK9DX.js → template-fields-PcSPApl5.js} +87 -82
- package/dist/template-fields-PcSPApl5.js.map +1 -0
- package/dist/testing.mjs +1 -1
- package/dist/utils/inkLuminance.d.ts +38 -0
- package/dist/{validation-BahKiJWj.js → validation-BpEod0Rn.js} +5570 -5590
- package/dist/validation-BpEod0Rn.js.map +1 -0
- package/package.json +3 -3
- package/dist/CanvasStateV1-CKsfggNP.js +0 -456
- package/dist/CanvasStateV1-CKsfggNP.js.map +0 -1
- package/dist/ThemeContext-Cl1JPVLZ.js +0 -1158
- package/dist/ThemeContext-Cl1JPVLZ.js.map +0 -1
- package/dist/schemas-B4UXytQB.js +0 -3250
- package/dist/schemas-B4UXytQB.js.map +0 -1
- package/dist/template-fields-Dw-KK9DX.js.map +0 -1
- package/dist/validation-BahKiJWj.js.map +0 -1
package/dist/embed.mjs
CHANGED
|
@@ -1,218 +1,233 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { b as
|
|
3
|
-
import { y as
|
|
4
|
-
import { jsx as
|
|
5
|
-
import { createContext as Q, useContext as X, useMemo as
|
|
6
|
-
import { assertVariantSelected as
|
|
7
|
-
import { u as
|
|
8
|
-
import { S as
|
|
9
|
-
import { D as
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { a as H, e as J } from "./validation-BpEod0Rn.js";
|
|
2
|
+
import { b as Ie, d as Te, u as xe, f as Me, g as Ue, h as Be } from "./validation-BpEod0Rn.js";
|
|
3
|
+
import { y as R } from "./HybridHistoryManager-NL3zyEl4.js";
|
|
4
|
+
import { jsx as $, Fragment as Y } from "react/jsx-runtime";
|
|
5
|
+
import { createContext as Q, useContext as X, useMemo as k, useRef as T, useState as O, useEffect as q, forwardRef as Z } from "react";
|
|
6
|
+
import { assertVariantSelected as ee, RenderSession as ne } from "@snowcone-app/sdk";
|
|
7
|
+
import { u as te, p as re } from "./usePieceGuideBundle-Cyl695jv.js";
|
|
8
|
+
import { S as se, s as ae } from "./template-fields-PcSPApl5.js";
|
|
9
|
+
import { D as Ne, T as Ge, d as Oe, r as qe, a as Ae, b as Fe, e as Pe, f as _e, g as je, h as Le, i as De, w as Ve } from "./template-fields-PcSPApl5.js";
|
|
10
|
+
import { u as We } from "./ThemeContext-D9AaUw9v.js";
|
|
11
|
+
import { s as He } from "./CanvasStateV1-BQD8fCBU.js";
|
|
12
|
+
const V = Q(void 0);
|
|
13
|
+
function F() {
|
|
14
|
+
const e = X(V);
|
|
13
15
|
if (!e)
|
|
14
16
|
throw new Error(
|
|
15
17
|
"useRealtimeMockups / <RealtimeCanvas> / <RealtimeMockup> must be rendered inside <RealtimeEmbed>. Wrap them: <RealtimeEmbed shop=… product=… design=… grantUrl=…>…</RealtimeEmbed>"
|
|
16
18
|
);
|
|
17
19
|
return e;
|
|
18
20
|
}
|
|
19
|
-
const
|
|
21
|
+
const w = "[RealtimeEmbed]";
|
|
20
22
|
function oe(e) {
|
|
21
|
-
var
|
|
22
|
-
if ((
|
|
23
|
-
return e.requiredPlacements.filter((
|
|
23
|
+
var o, i;
|
|
24
|
+
if ((o = e == null ? void 0 : e.requiredPlacements) != null && o.length)
|
|
25
|
+
return e.requiredPlacements.filter((r) => !r.autoFilledByVariant).map((r) => r.label);
|
|
24
26
|
const n = new Set(
|
|
25
|
-
(((
|
|
27
|
+
(((i = e == null ? void 0 : e.options) == null ? void 0 : i.combinations) ?? []).map((r) => r.variantId).filter((r) => typeof r == "string" && r !== "")
|
|
26
28
|
);
|
|
27
29
|
return !!(e != null && e.variantId) || n.size > 1 ? [] : (e == null ? void 0 : e.placements) ?? [];
|
|
28
30
|
}
|
|
29
|
-
function
|
|
30
|
-
var
|
|
31
|
-
if (e || console.error(`${
|
|
32
|
-
`${
|
|
33
|
-
), (
|
|
34
|
-
`${
|
|
31
|
+
function ie({ shop: e, product: n, design: t, hasGrant: o }) {
|
|
32
|
+
var d, s;
|
|
33
|
+
if (e || console.error(`${w} \`shop\` is required (your publishable shop id).`), o || console.error(
|
|
34
|
+
`${w} no grant source — pass \`grantUrl\` (a proxy to mintRealtimeGrant) or \`grant\`. Without it the session can never authorize and no mockup renders.`
|
|
35
|
+
), (d = n == null ? void 0 : n.mockupIds) != null && d.length || console.error(
|
|
36
|
+
`${w} product.mockupIds is empty — pass the catalog scene codes (product.mockups[].id) you want rendered, e.g. ["FV1qjO"].`
|
|
35
37
|
), n != null && n.options)
|
|
36
38
|
try {
|
|
37
|
-
|
|
38
|
-
} catch (
|
|
39
|
-
console.error(`${
|
|
39
|
+
ee(n);
|
|
40
|
+
} catch (a) {
|
|
41
|
+
console.error(`${w} ${a instanceof Error ? a.message : String(a)}`);
|
|
40
42
|
}
|
|
41
|
-
const
|
|
43
|
+
const i = t.toJSON(), r = i.activeArtboard, f = oe(n);
|
|
42
44
|
f.length > 1 && console.error(
|
|
43
|
-
`${
|
|
44
|
-
), (
|
|
45
|
-
`${
|
|
45
|
+
`${w} product ${n.productId} requires placements [${f.join(", ")}] but <RealtimeEmbed> renders a single placement ("${r}"). The render will time out waiting for the others. This product needs the eject path — see https://developers.snowcone.app/embed-mode#eject.`
|
|
46
|
+
), (s = n == null ? void 0 : n.placements) != null && s.length && !n.placements.includes(r) && console.warn(
|
|
47
|
+
`${w} the design's placement "${r}" is not in product.placements [${n.placements.join(", ")}]. The canvas artboard name and renderState placement must equal a real product placement label, or the server renders a blank mockup. Fix the \`name\` passed to design({ name }).`
|
|
46
48
|
);
|
|
47
|
-
const
|
|
49
|
+
const c = i.elements.map((a) => a.name).filter((a) => !!a), h = c.filter((a, b) => c.indexOf(a) !== b);
|
|
48
50
|
h.length && console.warn(
|
|
49
|
-
`${
|
|
51
|
+
`${w} duplicate layer name(s) [${[...new Set(h)].join(", ")}] — useTextBinding(name) / useImageBinding(name) bind to the FIRST match, so a duplicate name makes a control edit the wrong layer. Keep names unique.`
|
|
50
52
|
);
|
|
51
53
|
}
|
|
52
|
-
function
|
|
54
|
+
function ce(e) {
|
|
53
55
|
if ("grantUrl" in e && e.grantUrl)
|
|
54
56
|
return { grantUrl: e.grantUrl };
|
|
55
57
|
const n = e.grant;
|
|
56
58
|
return typeof n == "function" ? { getToken: n } : { getToken: () => Promise.resolve(n) };
|
|
57
59
|
}
|
|
58
|
-
const
|
|
59
|
-
function
|
|
60
|
-
return `[RealtimeEmbed] No mockup after ${Math.round(
|
|
60
|
+
const K = 8e3;
|
|
61
|
+
function le(e) {
|
|
62
|
+
return `[RealtimeEmbed] No mockup after ${Math.round(K / 1e3)}s. Common causes: a variant product missing \`variantId\` (pass \`product.options\` so the embed can flag it up front), a multi-placement product (the server waits for every required placement but <RealtimeEmbed> sends only "${e}" — pass \`product.requiredPlacements\` so this is flagged at mount; such products need the eject path), an unreachable or non-public asset URL in the design, or the placement "${e}" not existing on the product. The render may still arrive — this is a heads-up, not a failure.`;
|
|
61
63
|
}
|
|
62
|
-
function
|
|
63
|
-
const { shop: n, product:
|
|
64
|
-
if (!
|
|
65
|
-
const
|
|
66
|
-
return
|
|
67
|
-
}, [
|
|
68
|
-
|
|
69
|
-
const [
|
|
64
|
+
function Se(e) {
|
|
65
|
+
const { shop: n, product: t, design: o, throttleMs: i = 200, onMockups: r, onRenderError: f, wsUrl: c, services: h, children: d } = e, s = k(() => o.toJSON().activeArtboard, [o]), a = te(t.variantId ?? t.defaultGvid), b = k(() => {
|
|
66
|
+
if (!a) return null;
|
|
67
|
+
const u = o.toJSON().artboards[0];
|
|
68
|
+
return re(a, u) ?? null;
|
|
69
|
+
}, [a, o]), p = T(r), l = T(f);
|
|
70
|
+
p.current = r, l.current = f;
|
|
71
|
+
const [I, y] = O([]), [S, E] = O(!0), [P, x] = O(null), B = !!("grantUrl" in e && e.grantUrl || "grant" in e && e.grant), C = ce(e), W = "grantUrl" in C ? C.grantUrl : "getToken", N = `${t.productId}|${t.mockupIds.join(",")}|${t.variantId ?? ""}`, M = k(
|
|
70
72
|
() => {
|
|
71
73
|
try {
|
|
72
|
-
return { session: new
|
|
73
|
-
} catch (
|
|
74
|
-
return { error:
|
|
74
|
+
return { session: new ne({ shop: n, product: t, wsUrl: c, ...C }) };
|
|
75
|
+
} catch (u) {
|
|
76
|
+
return { error: u instanceof Error ? u.message : String(u) };
|
|
75
77
|
}
|
|
76
78
|
},
|
|
77
79
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
|
-
[n,
|
|
79
|
-
), g = "session" in
|
|
80
|
-
|
|
81
|
-
var
|
|
82
|
-
if (typeof
|
|
83
|
-
const m = `${n}|${
|
|
80
|
+
[n, N, s, c, W]
|
|
81
|
+
), g = "session" in M ? M.session : null, U = "error" in M ? M.error : null, _ = T(null);
|
|
82
|
+
q(() => {
|
|
83
|
+
var u;
|
|
84
|
+
if (typeof R < "u" && ((u = R.env) == null ? void 0 : u.NODE_ENV) !== "production") {
|
|
85
|
+
const m = `${n}|${N}|${s}|${B}`;
|
|
84
86
|
if (_.current === m) return;
|
|
85
|
-
_.current = m,
|
|
87
|
+
_.current = m, ie({ shop: n, product: t, design: o, hasGrant: B });
|
|
86
88
|
}
|
|
87
|
-
}, [n,
|
|
88
|
-
const
|
|
89
|
-
g && (
|
|
89
|
+
}, [n, N, s, B]);
|
|
90
|
+
const G = k(() => (u, m = i) => {
|
|
91
|
+
g && (x(null), E(!0), g.renderState(s, u, m).catch((v) => {
|
|
90
92
|
var D;
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
+
const L = v instanceof Error ? v.message : String(v);
|
|
94
|
+
x(L), E(!1), (D = l.current) == null || D.call(l, L);
|
|
93
95
|
}));
|
|
94
|
-
}, [g,
|
|
95
|
-
|
|
96
|
-
var
|
|
97
|
-
if (
|
|
98
|
-
|
|
96
|
+
}, [g, s, i]);
|
|
97
|
+
q(() => {
|
|
98
|
+
var u;
|
|
99
|
+
if (U) {
|
|
100
|
+
x(U), E(!1), (u = l.current) == null || u.call(l, U);
|
|
99
101
|
return;
|
|
100
102
|
}
|
|
101
103
|
if (g)
|
|
102
104
|
return g.onMockups((m) => {
|
|
103
|
-
var
|
|
104
|
-
|
|
105
|
+
var v;
|
|
106
|
+
y(m), E(!1), (v = p.current) == null || v.call(p, m);
|
|
105
107
|
}), g.onError((m) => {
|
|
106
|
-
var
|
|
107
|
-
|
|
108
|
-
}),
|
|
109
|
-
}, [g,
|
|
108
|
+
var v;
|
|
109
|
+
x(m), E(!1), (v = l.current) == null || v.call(l, m);
|
|
110
|
+
}), G(o.toServerRequest()), () => g.close();
|
|
111
|
+
}, [g, U]), q(() => {
|
|
110
112
|
var m;
|
|
111
|
-
if (
|
|
112
|
-
const
|
|
113
|
-
return () => clearTimeout(
|
|
114
|
-
}, [
|
|
115
|
-
const
|
|
113
|
+
if (!S || typeof R > "u" || ((m = R.env) == null ? void 0 : m.NODE_ENV) === "production") return;
|
|
114
|
+
const u = setTimeout(() => console.warn(le(s)), K);
|
|
115
|
+
return () => clearTimeout(u);
|
|
116
|
+
}, [S, s]);
|
|
117
|
+
const z = k(
|
|
116
118
|
() => ({
|
|
117
119
|
session: g,
|
|
118
|
-
design:
|
|
119
|
-
placement:
|
|
120
|
-
product:
|
|
121
|
-
mockups:
|
|
122
|
-
isRendering:
|
|
120
|
+
design: o,
|
|
121
|
+
placement: s,
|
|
122
|
+
product: t,
|
|
123
|
+
mockups: I,
|
|
124
|
+
isRendering: S,
|
|
123
125
|
error: P,
|
|
124
|
-
throttleMs:
|
|
125
|
-
pieceGuides:
|
|
126
|
-
pushRender:
|
|
126
|
+
throttleMs: i,
|
|
127
|
+
pieceGuides: b,
|
|
128
|
+
pushRender: G
|
|
127
129
|
}),
|
|
128
|
-
[g, s,
|
|
129
|
-
), j = /* @__PURE__ */
|
|
130
|
-
return h ? /* @__PURE__ */
|
|
131
|
-
}
|
|
132
|
-
function Se({
|
|
133
|
-
children: e,
|
|
134
|
-
kit: n = "embed-only",
|
|
135
|
-
inheritTheme: r = !0,
|
|
136
|
-
maxHeight: s,
|
|
137
|
-
services: l,
|
|
138
|
-
className: t,
|
|
139
|
-
style: f
|
|
140
|
-
}) {
|
|
141
|
-
const { design: i, placement: h, throttleMs: u, pieceGuides: a, pushRender: o } = q(), p = S(() => i.toJSON(), [i]);
|
|
142
|
-
return /* @__PURE__ */ y("div", { className: `sc-root${t ? ` ${t}` : ""}`, style: f, children: /* @__PURE__ */ y(
|
|
143
|
-
re,
|
|
144
|
-
{
|
|
145
|
-
kit: n,
|
|
146
|
-
inheritTheme: r,
|
|
147
|
-
services: l,
|
|
148
|
-
artboards: p.artboards,
|
|
149
|
-
activeArtboard: h,
|
|
150
|
-
initialElements: p.elements,
|
|
151
|
-
layoutConfig: s ? { maxHeight: s } : void 0,
|
|
152
|
-
overlay: e,
|
|
153
|
-
pieceGuides: a ?? void 0,
|
|
154
|
-
onChange: (v) => o(se(v), u)
|
|
155
|
-
}
|
|
156
|
-
) });
|
|
130
|
+
[g, o, s, t, I, S, P, i, b, G]
|
|
131
|
+
), j = /* @__PURE__ */ $(V.Provider, { value: z, children: d });
|
|
132
|
+
return h ? /* @__PURE__ */ $(H, { services: h, children: j }) : j;
|
|
157
133
|
}
|
|
158
|
-
const
|
|
159
|
-
function
|
|
160
|
-
|
|
134
|
+
const we = Z(
|
|
135
|
+
function({
|
|
136
|
+
children: n,
|
|
137
|
+
kit: t = "embed-only",
|
|
138
|
+
inheritTheme: o = !0,
|
|
139
|
+
maxHeight: i,
|
|
140
|
+
services: r,
|
|
141
|
+
onChange: f,
|
|
142
|
+
className: c,
|
|
143
|
+
style: h
|
|
144
|
+
}, d) {
|
|
145
|
+
const { design: s, placement: a, throttleMs: b, pieceGuides: p, pushRender: l } = F(), I = k(() => s.toJSON(), [s]), y = T(f);
|
|
146
|
+
return y.current = f, /* @__PURE__ */ $("div", { className: `sc-root${c ? ` ${c}` : ""}`, style: h, children: /* @__PURE__ */ $(
|
|
147
|
+
se,
|
|
148
|
+
{
|
|
149
|
+
ref: d,
|
|
150
|
+
kit: t,
|
|
151
|
+
inheritTheme: o,
|
|
152
|
+
services: r,
|
|
153
|
+
artboards: I.artboards,
|
|
154
|
+
activeArtboard: a,
|
|
155
|
+
initialElements: I.elements,
|
|
156
|
+
layoutConfig: i ? { maxHeight: i } : void 0,
|
|
157
|
+
overlay: n,
|
|
158
|
+
pieceGuides: p ?? void 0,
|
|
159
|
+
onChange: (S) => {
|
|
160
|
+
var E;
|
|
161
|
+
l(ae(S), b), (E = y.current) == null || E.call(y, S);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
) });
|
|
165
|
+
}
|
|
166
|
+
), ue = 1.2, A = [1200, 1400, 1600, 1800, 2e3, 2500, 3e3, 4e3];
|
|
167
|
+
function de(e) {
|
|
168
|
+
for (const n of A)
|
|
161
169
|
if (n >= e) return n;
|
|
162
|
-
return
|
|
170
|
+
return A[A.length - 1];
|
|
163
171
|
}
|
|
164
|
-
function
|
|
165
|
-
if (!(e > 0) || !(n > 0) || n <= e *
|
|
166
|
-
const
|
|
167
|
-
return `[RealtimeMockup] mockup rendered at ${e}px but displayed at ~${n} device px — the preview will look soft. Pass \`product.width\` (e.g. ${
|
|
172
|
+
function me(e, n) {
|
|
173
|
+
if (!(e > 0) || !(n > 0) || n <= e * ue) return null;
|
|
174
|
+
const t = de(n);
|
|
175
|
+
return `[RealtimeMockup] mockup rendered at ${e}px but displayed at ~${n} device px — the preview will look soft. Pass \`product.width\` (e.g. ${t}) on <RealtimeEmbed> for a crisp preview.`;
|
|
168
176
|
}
|
|
169
|
-
function
|
|
177
|
+
function ye({
|
|
170
178
|
mockupId: e,
|
|
171
179
|
fallback: n = null,
|
|
172
|
-
alt:
|
|
173
|
-
className:
|
|
174
|
-
style:
|
|
180
|
+
alt: t = "Live product mockup",
|
|
181
|
+
className: o,
|
|
182
|
+
style: i
|
|
175
183
|
}) {
|
|
176
|
-
const { mockups:
|
|
177
|
-
if (!(
|
|
178
|
-
return /* @__PURE__ */
|
|
179
|
-
const h = (
|
|
180
|
-
var
|
|
181
|
-
if (typeof
|
|
182
|
-
const
|
|
183
|
-
if (
|
|
184
|
-
const
|
|
185
|
-
|
|
184
|
+
const { mockups: r } = F(), f = T(/* @__PURE__ */ new Set()), c = e ? r.find((d) => d.mockupId === e && d.imageUrl) : r.find((d) => d.imageUrl);
|
|
185
|
+
if (!(c != null && c.imageUrl))
|
|
186
|
+
return /* @__PURE__ */ $(Y, { children: n });
|
|
187
|
+
const h = (d) => {
|
|
188
|
+
var l;
|
|
189
|
+
if (typeof R > "u" || ((l = R.env) == null ? void 0 : l.NODE_ENV) === "production" || typeof window > "u" || f.current.has(c.mockupId)) return;
|
|
190
|
+
const s = d.currentTarget, a = s.getBoundingClientRect().width;
|
|
191
|
+
if (a <= 0) return;
|
|
192
|
+
const b = Math.round(a * (window.devicePixelRatio || 1)), p = me(s.naturalWidth, b);
|
|
193
|
+
p && (f.current.add(c.mockupId), console.warn(p));
|
|
186
194
|
};
|
|
187
195
|
return (
|
|
188
196
|
// eslint-disable-next-line @next/next/no-img-element
|
|
189
|
-
/* @__PURE__ */
|
|
197
|
+
/* @__PURE__ */ $("img", { src: c.imageUrl, alt: t, className: o, style: i, onLoad: h })
|
|
190
198
|
);
|
|
191
199
|
}
|
|
192
|
-
function
|
|
193
|
-
const { mockups: e, isRendering: n, error:
|
|
194
|
-
return { mockups: e, isRendering: n, error:
|
|
200
|
+
function ke() {
|
|
201
|
+
const { mockups: e, isRendering: n, error: t } = F();
|
|
202
|
+
return { mockups: e, isRendering: n, error: t };
|
|
195
203
|
}
|
|
196
|
-
|
|
204
|
+
J();
|
|
197
205
|
export {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
206
|
+
H as CanvasServicesProvider,
|
|
207
|
+
Ne as DesignBuilder,
|
|
208
|
+
we as RealtimeCanvas,
|
|
209
|
+
Se as RealtimeEmbed,
|
|
210
|
+
ye as RealtimeMockup,
|
|
211
|
+
Ge as TEMPLATE_FIELDS_KEY,
|
|
212
|
+
Ie as createProxyGenerate,
|
|
213
|
+
Te as createProxyImageSearch,
|
|
214
|
+
Oe as design,
|
|
215
|
+
qe as readTemplateFields,
|
|
216
|
+
He as serializeState,
|
|
217
|
+
xe as useArtboards,
|
|
218
|
+
Me as useCanvasServices,
|
|
219
|
+
Ae as useColorBinding,
|
|
220
|
+
Fe as useCommands,
|
|
221
|
+
We as useEditor,
|
|
222
|
+
Pe as useElementByName,
|
|
223
|
+
Ue as useExport,
|
|
224
|
+
_e as useFontBinding,
|
|
225
|
+
je as useImageBinding,
|
|
226
|
+
Be as useLayers,
|
|
227
|
+
ke as useRealtimeMockups,
|
|
228
|
+
Le as useSelectedElement,
|
|
229
|
+
De as useTextBinding,
|
|
230
|
+
ie as validateEmbed,
|
|
231
|
+
Ve as withTemplateFields
|
|
217
232
|
};
|
|
218
233
|
//# sourceMappingURL=embed.mjs.map
|