@snowcone-app/canvas 0.41.4 → 0.42.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/{CanvasRenderer-JcBrIZ6I.js → CanvasRenderer-3M-52sAd.js} +4 -4
- package/dist/{CanvasRenderer-JcBrIZ6I.js.map → CanvasRenderer-3M-52sAd.js.map} +1 -1
- package/dist/{CanvasStateV1-BJ5-75NN.js → CanvasStateV1-BQ3cbxt2.js} +5 -4
- package/dist/{CanvasStateV1-BJ5-75NN.js.map → CanvasStateV1-BQ3cbxt2.js.map} +1 -1
- package/dist/{ContextualToolbars-wmbHxn5a.js → ContextualToolbars-B2LTNu7r.js} +358 -358
- package/dist/{ContextualToolbars-wmbHxn5a.js.map → ContextualToolbars-B2LTNu7r.js.map} +1 -1
- package/dist/{EditorCanvasImpl-CSDnCIpN.js → EditorCanvasImpl-VJ7kBhXB.js} +26 -26
- package/dist/EditorCanvasImpl-VJ7kBhXB.js.map +1 -0
- package/dist/{ExportManager-CHlByUYV.js → ExportManager-9_RjQEv0.js} +2 -2
- package/dist/{ExportManager-CHlByUYV.js.map → ExportManager-9_RjQEv0.js.map} +1 -1
- package/dist/{FontAnalyzer-Bj2KrX80.js → FontAnalyzer-Ch1jgTq7.js} +88 -68
- package/dist/FontAnalyzer-Ch1jgTq7.js.map +1 -0
- package/dist/ImagePanel-DY9Ve3X7.js +1016 -0
- package/dist/{ImagePanel-0ZwDDaCy.js.map → ImagePanel-DY9Ve3X7.js.map} +1 -1
- package/dist/SnowconeCanvas-BzOy46Yw.js +1098 -0
- package/dist/SnowconeCanvas-BzOy46Yw.js.map +1 -0
- package/dist/advanced.mjs +44 -44
- package/dist/api/stable.d.ts +1 -1
- package/dist/components/embed/SnowconeCanvas.d.ts +15 -0
- package/dist/components/embed/kernel.d.ts +3 -1
- package/dist/core/ArtboardElement.d.ts +2 -0
- package/dist/core/ArtboardManager.d.ts +11 -0
- package/dist/{custom-icons-up58ZbC9.js → custom-icons-D_XezOul.js} +2 -2
- package/dist/{custom-icons-up58ZbC9.js.map → custom-icons-D_XezOul.js.map} +1 -1
- package/dist/design/template-fields.d.ts +12 -0
- package/dist/design-builder-BFM94eA9.js +1859 -0
- package/dist/design-builder-BFM94eA9.js.map +1 -0
- package/dist/{embed-GXevsHX5.js → embed-5W-gg9dt.js} +10 -10
- package/dist/{embed-GXevsHX5.js.map → embed-5W-gg9dt.js.map} +1 -1
- package/dist/embed.mjs +12 -12
- package/dist/{guards-CQeF53PN.js → guards-D_mw4DgS.js} +2 -2
- package/dist/{guards-CQeF53PN.js.map → guards-D_mw4DgS.js.map} +1 -1
- package/dist/index.mjs +9 -9
- package/dist/internals.mjs +6 -6
- package/dist/{placement-D31o3YYC.js → placement-tSiIVhrL.js} +3 -3
- package/dist/{placement-D31o3YYC.js.map → placement-tSiIVhrL.js.map} +1 -1
- package/dist/placement.mjs +2 -2
- package/dist/{template-fields-tobyHoMe.js → template-fields-CQURvcab.js} +80 -78
- package/dist/{template-fields-tobyHoMe.js.map → template-fields-CQURvcab.js.map} +1 -1
- package/dist/testing.mjs +3 -3
- package/dist/{useCommands-Cm3mDB-l.js → useCommands-DSapP-w1.js} +7 -7
- package/dist/{useCommands-Cm3mDB-l.js.map → useCommands-DSapP-w1.js.map} +1 -1
- package/dist/{usePieceGuideBundle-BTnUn33k.js → usePieceGuideBundle-oBykb3X8.js} +2 -2
- package/dist/{usePieceGuideBundle-BTnUn33k.js.map → usePieceGuideBundle-oBykb3X8.js.map} +1 -1
- package/dist/utils/newImagePlacement.d.ts +56 -0
- package/dist/{validation-D4zxugNJ.js → validation-D6zVSeTh.js} +307 -307
- package/dist/{validation-D4zxugNJ.js.map → validation-D6zVSeTh.js.map} +1 -1
- package/dist/vendor/ui/primitives/badge.d.ts +1 -1
- package/dist/vendor/ui/primitives/link.d.ts +1 -1
- package/dist/vendor/ui/primitives/spinner.d.ts +1 -1
- package/example/package.json +1 -1
- package/package.json +2 -2
- package/dist/EditorCanvasImpl-CSDnCIpN.js.map +0 -1
- package/dist/FontAnalyzer-Bj2KrX80.js.map +0 -1
- package/dist/ImagePanel-0ZwDDaCy.js +0 -984
- package/dist/SnowconeCanvas-BZk7PRpk.js +0 -1215
- package/dist/SnowconeCanvas-BZk7PRpk.js.map +0 -1
- package/dist/design-builder-DUEwCUmA.js +0 -1676
- package/dist/design-builder-DUEwCUmA.js.map +0 -1
package/dist/embed.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { C as a, g as t, h as o, K as r, N as i, O as n, P as d, Q as m, R as u, b as l, a as E, j as c, k as p, l as g } from "./useCommands-
|
|
2
|
-
import { E as C, R as S, a as T, b as f, S as P, c as R, d as b, e as B, f as
|
|
3
|
-
import { t as M, Y as j } from "./FontAnalyzer-
|
|
4
|
-
import { D as N, e as Y,
|
|
5
|
-
import { D as O, T as Q, r as V, u as q, a as U, b as W, c as X, d as Z, e as $, w as ee } from "./template-fields-
|
|
6
|
-
import { G as ae, H as te, J as oe, K as re } from "./ExportManager-
|
|
7
|
-
import { s as ne } from "./CanvasStateV1-
|
|
1
|
+
import { C as a, g as t, h as o, K as r, N as i, O as n, P as d, Q as m, R as u, b as l, a as E, j as c, k as p, l as g } from "./useCommands-DSapP-w1.js";
|
|
2
|
+
import { E as C, R as S, a as T, b as f, S as P, c as R, d as b, e as B, f as k, g as v, i as y, h as F, p as h, s as D, j as I, k as K, l as L, v as w } from "./embed-5W-gg9dt.js";
|
|
3
|
+
import { t as M, Y as j } from "./FontAnalyzer-Ch1jgTq7.js";
|
|
4
|
+
import { D as N, e as Y, m as _, k as z, b as H } from "./design-builder-BFM94eA9.js";
|
|
5
|
+
import { D as O, T as Q, r as V, u as q, a as U, b as W, c as X, d as Z, e as $, w as ee } from "./template-fields-CQURvcab.js";
|
|
6
|
+
import { G as ae, H as te, J as oe, K as re } from "./ExportManager-9_RjQEv0.js";
|
|
7
|
+
import { s as ne } from "./CanvasStateV1-BQ3cbxt2.js";
|
|
8
8
|
export {
|
|
9
9
|
a as CanvasServicesProvider,
|
|
10
10
|
N as DesignBuilder,
|
|
@@ -19,16 +19,16 @@ export {
|
|
|
19
19
|
R as auditEditor,
|
|
20
20
|
b as bundleToRenderConfig,
|
|
21
21
|
B as bundleVariantToken,
|
|
22
|
-
|
|
22
|
+
k as collectEmbedIssues,
|
|
23
23
|
t as createProxyGenerate,
|
|
24
24
|
o as createProxyImageSearch,
|
|
25
25
|
ae as customFontRegistry,
|
|
26
26
|
Y as design,
|
|
27
27
|
r as editorElementKind,
|
|
28
28
|
te as ensureCustomFontsLoaded,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
v as formatBuyPrice,
|
|
30
|
+
y as isBundleProduct,
|
|
31
|
+
F as isBundleRenderProduct,
|
|
32
32
|
_ as isColorToken,
|
|
33
33
|
j as isEditorError,
|
|
34
34
|
i as isGroupElement,
|
|
@@ -38,7 +38,7 @@ export {
|
|
|
38
38
|
m as isShapeElement,
|
|
39
39
|
u as isTextElement,
|
|
40
40
|
oe as loadCustomFont,
|
|
41
|
-
|
|
41
|
+
h as productToRenderConfig,
|
|
42
42
|
V as readTemplateFields,
|
|
43
43
|
re as registerCustomFonts,
|
|
44
44
|
ne as serializeState,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as n, I as t, P as a, S as s, T as i } from "./FontAnalyzer-
|
|
1
|
+
import { G as n, I as t, P as a, S as s, T as i } from "./FontAnalyzer-Ch1jgTq7.js";
|
|
2
2
|
function r(e) {
|
|
3
3
|
return e instanceof i;
|
|
4
4
|
}
|
|
@@ -21,4 +21,4 @@ export {
|
|
|
21
21
|
r as d,
|
|
22
22
|
m as i
|
|
23
23
|
};
|
|
24
|
-
//# sourceMappingURL=guards-
|
|
24
|
+
//# sourceMappingURL=guards-D_mw4DgS.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guards-
|
|
1
|
+
{"version":3,"file":"guards-D_mw4DgS.js","sources":["../src/types/guards.ts"],"sourcesContent":["/**\n * Type guards for EditorElement discrimination\n *\n * These guards use instanceof checks against the concrete element classes,\n * matching the pattern established in EditorContext.tsx. They accept\n * BaseElement | EditorElement | undefined | null for maximum flexibility\n * at call sites.\n */\n\nimport { BaseElement } from '../core/BaseElement.js';\nimport { TextElement } from '../core/TextElement.js';\nimport { ImageElement } from '../core/ImageElement.js';\nimport { GroupElement } from '../core/GroupElement.js';\nimport { ShapeElement } from '../core/ShapeElement.js';\nimport { PathElement } from '../core/PathElement.js';\n\ntype Narrowable = BaseElement | TextElement | ImageElement | GroupElement | ShapeElement | PathElement | undefined | null;\n\n/**\n * Type guard: checks if an element is a TextElement (or any text-based transform subclass).\n *\n * TextElement is the base class for all text transforms (custom, circle, arch, wave, etc.),\n * so this returns true for any text-based element regardless of its specific transformType.\n */\nexport function isTextElement(element: Narrowable): element is TextElement {\n return element instanceof TextElement;\n}\n\n/**\n * Type guard: checks if an element is an ImageElement.\n */\nexport function isImageElement(element: Narrowable): element is ImageElement {\n return element instanceof ImageElement;\n}\n\n/**\n * Type guard: checks if an element is a GroupElement.\n */\nexport function isGroupElement(element: Narrowable): element is GroupElement {\n return element instanceof GroupElement;\n}\n\n/**\n * Type guard: checks if an element is a ShapeElement.\n */\nexport function isShapeElement(element: Narrowable): element is ShapeElement {\n return element instanceof ShapeElement;\n}\n\n/**\n * Type guard: checks if an element is a PathElement.\n */\nexport function isPathElement(element: Narrowable): element is PathElement {\n return element instanceof PathElement;\n}\n"],"names":["isTextElement","element","TextElement","isImageElement","ImageElement","isGroupElement","GroupElement","isShapeElement","ShapeElement","isPathElement","PathElement"],"mappings":";AAwBO,SAASA,EAAcC,GAA6C;AACzE,SAAOA,aAAmBC;AAC5B;AAKO,SAASC,EAAeF,GAA8C;AAC3E,SAAOA,aAAmBG;AAC5B;AAKO,SAASC,EAAeJ,GAA8C;AAC3E,SAAOA,aAAmBK;AAC5B;AAKO,SAASC,EAAeN,GAA8C;AAC3E,SAAOA,aAAmBO;AAC5B;AAKO,SAASC,EAAcR,GAA6C;AACzE,SAAOA,aAAmBS;AAC5B;"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { e as u } from "./useCommands-
|
|
2
|
-
import { C as c, f as x, g as I, h as v, b as A, a as g, j as T, k as B, l as P } from "./useCommands-
|
|
3
|
-
import { E as F, S as L, S as _, u as O, a as R } from "./SnowconeCanvas-
|
|
4
|
-
import { b as m, d } from "./design-builder-
|
|
5
|
-
import { C as z, D as w, e as K, s as D } from "./design-builder-
|
|
6
|
-
import { T as V, r as b, u as h, a as G, b as H, c as U, d as Y, e as Z, w as j } from "./template-fields-
|
|
7
|
-
import { A as J, C as q, E as Q, M as W, P as X, r as $, v as ee } from "./validation-
|
|
8
|
-
import { G as ae, H as te, J as oe, K as re } from "./ExportManager-
|
|
1
|
+
import { e as u } from "./useCommands-DSapP-w1.js";
|
|
2
|
+
import { C as c, f as x, g as I, h as v, b as A, a as g, j as T, k as B, l as P } from "./useCommands-DSapP-w1.js";
|
|
3
|
+
import { E as F, S as L, S as _, u as O, a as R } from "./SnowconeCanvas-BzOy46Yw.js";
|
|
4
|
+
import { b as m, d } from "./design-builder-BFM94eA9.js";
|
|
5
|
+
import { C as z, D as w, e as K, s as D } from "./design-builder-BFM94eA9.js";
|
|
6
|
+
import { T as V, r as b, u as h, a as G, b as H, c as U, d as Y, e as Z, w as j } from "./template-fields-CQURvcab.js";
|
|
7
|
+
import { A as J, C as q, E as Q, M as W, P as X, r as $, v as ee } from "./validation-D6zVSeTh.js";
|
|
8
|
+
import { G as ae, H as te, J as oe, K as re } from "./ExportManager-9_RjQEv0.js";
|
|
9
9
|
import { c as ie, e as ue } from "./compose-DtQL_oit.js";
|
|
10
|
-
import { d as de, m as Ce, s as Se, v as Ee } from "./CanvasStateV1-
|
|
10
|
+
import { d as de, m as Ce, s as Se, v as Ee } from "./CanvasStateV1-BQ3cbxt2.js";
|
|
11
11
|
function E() {
|
|
12
12
|
const { isCanvasReady: e } = m();
|
|
13
13
|
return e;
|
package/dist/internals.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { A as rr, a as or, C as sr, I as er, R as tr, S as nr, T as ar } from "./CanvasRenderer-
|
|
2
|
-
import { r as k } from "./ExportManager-
|
|
3
|
-
import { D as hr, a as cr, I as dr, W as fr, b as gr, c as lr, d as ur, e as pr, f as yr, g as kr, h as vr, i as wr, j as Cr, k as Mr, l as Tr, m as Sr, n as br, o as Pr, p as Ir, q as mr, s as Ar, t as Rr, u as Wr, v as Er, w as Or, x as Hr, y as jr, z as Fr, A as Lr, B as Xr, C as zr, F as Nr } from "./ExportManager-
|
|
4
|
-
import { i as H, a as j, c as F, r as L, b as X } from "./FontAnalyzer-
|
|
5
|
-
import { d as Br, e as Kr, f as Ur, C as Yr, g as Jr, E as Vr, F as qr, H as Gr, L as Qr, h as Zr, W as $r, j as xr, k as Dr, l as ro, m as oo, n as so, o as eo, s as to, w as no } from "./FontAnalyzer-
|
|
6
|
-
import { A as io, a as ho, C as co, S as fo } from "./CanvasStateV1-
|
|
1
|
+
import { A as rr, a as or, C as sr, I as er, R as tr, S as nr, T as ar } from "./CanvasRenderer-3M-52sAd.js";
|
|
2
|
+
import { r as k } from "./ExportManager-9_RjQEv0.js";
|
|
3
|
+
import { D as hr, a as cr, I as dr, W as fr, b as gr, c as lr, d as ur, e as pr, f as yr, g as kr, h as vr, i as wr, j as Cr, k as Mr, l as Tr, m as Sr, n as br, o as Pr, p as Ir, q as mr, s as Ar, t as Rr, u as Wr, v as Er, w as Or, x as Hr, y as jr, z as Fr, A as Lr, B as Xr, C as zr, F as Nr } from "./ExportManager-9_RjQEv0.js";
|
|
4
|
+
import { i as H, a as j, c as F, r as L, b as X } from "./FontAnalyzer-Ch1jgTq7.js";
|
|
5
|
+
import { d as Br, e as Kr, f as Ur, C as Yr, g as Jr, E as Vr, F as qr, H as Gr, L as Qr, h as Zr, W as $r, j as xr, k as Dr, l as ro, m as oo, n as so, o as eo, s as to, w as no } from "./FontAnalyzer-Ch1jgTq7.js";
|
|
6
|
+
import { A as io, a as ho, C as co, S as fo } from "./CanvasStateV1-BQ3cbxt2.js";
|
|
7
7
|
const z = F("image-adjustments"), v = 1e-3;
|
|
8
8
|
function N(r, o) {
|
|
9
9
|
const { brightness: a, contrast: s, saturation: h } = o, e = a * s, t = 127.5 * (1 - s), f = Math.abs(e - 1) > v || Math.abs(t) > v, i = new Uint8ClampedArray(256);
|
|
@@ -95,8 +95,8 @@ function W(h, t) {
|
|
|
95
95
|
return { width: t.width, height: f, cropX: 0, cropY: (1 - d) / 2, cropWidth: 1, cropHeight: d, centerX: e, centerY: a };
|
|
96
96
|
}
|
|
97
97
|
export {
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
H as a,
|
|
99
|
+
W as c,
|
|
100
100
|
E as g
|
|
101
101
|
};
|
|
102
|
-
//# sourceMappingURL=placement-
|
|
102
|
+
//# sourceMappingURL=placement-tSiIVhrL.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"placement-D31o3YYC.js","sources":["../src/utils/ArtworkPlacement.ts"],"sourcesContent":["/**\n * ArtworkPlacement - Utility for calculating artwork position and scale\n *\n * Uses \"cover\" logic (like CSS object-fit: cover) to ensure artwork fills\n * the entire artboard while maintaining aspect ratio.\n */\n\n/**\n * 9-point alignment options for positioning artwork\n */\nexport type Alignment = 'tl' | 't' | 'tr' | 'l' | 'c' | 'r' | 'bl' | 'b' | 'br';\n\n/**\n * Scale mode for artwork placement\n * - \"cover\" (default): fills entire area, may crop (like CSS object-fit: cover)\n * - \"contain\": fits entirely inside area, may have empty space (like CSS object-fit: contain)\n */\nexport type ScaleMode = 'cover' | 'contain';\n\n/**\n * Placement configuration for artwork positioning\n */\nexport interface PlacementConfig {\n /** Artboard width in pixels */\n width: number;\n /** Artboard height in pixels */\n height: number;\n /** User scale multiplier (default: 1) */\n scale?: number;\n /** 9-point alignment (default: \"c\" for center) */\n align?: Alignment;\n /** X offset in range -1 to 1 (default: 0) */\n offsetX?: number;\n /** Y offset in range -1 to 1 (default: 0) */\n offsetY?: number;\n /** Scale mode: \"cover\" fills area (may crop), \"contain\" fits inside (may have space). Default: \"cover\" */\n scaleMode?: ScaleMode;\n /** Top margin in pixels (reduces available area in contain mode) */\n marginTop?: number;\n /** Right margin in pixels (reduces available area in contain mode) */\n marginRight?: number;\n /** Bottom margin in pixels (reduces available area in contain mode) */\n marginBottom?: number;\n /** Left margin in pixels (reduces available area in contain mode) */\n marginLeft?: number;\n}\n\n/**\n * Result of artwork placement calculation\n */\nexport interface ArtworkPlacementResult {\n /** Final scale to apply to artwork */\n scale: number;\n /** Final artwork dimensions after scaling */\n width: number;\n height: number;\n /** Position to draw artwork (relative to artboard origin) */\n x: number;\n y: number;\n /** Debug information */\n debug: {\n coverScale: number;\n userScale: number;\n overflow: { x: number; y: number };\n alignment: string;\n appliedOffset: { x: number; y: number };\n };\n}\n\n/**\n * Map string alignment values to 9-point grid\n */\nexport const alignmentMap: Record<string, Alignment> = {\n // Vertical alignments (map to top/center/bottom center)\n 'far-top': 't',\n 'top': 't',\n 'center': 'c',\n 'bottom': 'b',\n 'far-bottom': 'b',\n // Horizontal alignments (map to left/center/right middle)\n 'far-left': 'l',\n 'left': 'l',\n 'right': 'r',\n 'far-right': 'r',\n // Direct 9-point values\n 'tl': 'tl',\n 't': 't',\n 'tr': 'tr',\n 'l': 'l',\n 'c': 'c',\n 'r': 'r',\n 'bl': 'bl',\n 'b': 'b',\n 'br': 'br',\n};\n\n/**\n * Get Alignment from string (supports various naming conventions)\n */\nexport function getAlignment(value: string | Alignment | undefined): Alignment {\n if (!value) return 'c';\n return alignmentMap[value] || 'c';\n}\n\n/**\n * Calculates how to size and position artwork on an artboard\n * Uses \"cover\" logic (like CSS object-fit: cover) to ensure artwork fills the entire area\n *\n * @param artwork - The artwork dimensions\n * @param placement - The placement configuration\n * @returns Positioning and scaling information\n *\n * @example\n * const result = calculateArtworkPlacement(\n * { width: 1000, height: 1000 }, // Square artwork\n * { width: 500, height: 800 } // Tall artboard\n * );\n * // Result: artwork scaled to 800x800, positioned at x: -150, y: 0\n */\nexport function calculateArtworkPlacement(\n artwork: { width: number; height: number },\n placement: PlacementConfig\n): ArtworkPlacementResult {\n // Step 1: Calculate base scale based on scale mode\n const mode = placement.scaleMode || 'cover';\n\n // Margins reduce available area (only in contain mode)\n const mTop = (mode === 'contain' ? placement.marginTop : 0) || 0;\n const mRight = (mode === 'contain' ? placement.marginRight : 0) || 0;\n const mBottom = (mode === 'contain' ? placement.marginBottom : 0) || 0;\n const mLeft = (mode === 'contain' ? placement.marginLeft : 0) || 0;\n\n const effectiveWidth = placement.width - mLeft - mRight;\n const effectiveHeight = placement.height - mTop - mBottom;\n\n const scaleX = effectiveWidth / artwork.width;\n const scaleY = effectiveHeight / artwork.height;\n\n // \"cover\": use LARGER scale so artwork fills entire area (may crop)\n // \"contain\": use SMALLER scale so artwork fits entirely inside (may have space)\n const coverScale = mode === 'contain'\n ? Math.min(scaleX, scaleY)\n : Math.max(scaleX, scaleY);\n\n // Step 2: Apply user's custom scale multiplier\n const userScale = placement.scale || 1;\n const finalScale = coverScale * userScale;\n\n // Step 3: Calculate final artwork dimensions after scaling\n const scaledArtworkWidth = artwork.width * finalScale;\n const scaledArtworkHeight = artwork.height * finalScale;\n\n // Step 4: Calculate base position using alignment\n const alignment = placement.align || 'c'; // default to center\n let x = 0;\n let y = 0;\n\n // Calculate the \"overflow\" relative to effective area\n // In contain mode with margins, overflow is relative to the margin-bounded area\n const overflowX = scaledArtworkWidth - effectiveWidth;\n const overflowY = scaledArtworkHeight - effectiveHeight;\n\n // Apply 9-point alignment\n switch (alignment) {\n // Top row\n case 'tl': // Top-Left\n x = 0;\n y = 0;\n break;\n case 't': // Top-Center\n x = -overflowX / 2;\n y = 0;\n break;\n case 'tr': // Top-Right\n x = -overflowX;\n y = 0;\n break;\n\n // Middle row\n case 'l': // Middle-Left\n x = 0;\n y = -overflowY / 2;\n break;\n case 'c': // Center (default)\n default:\n x = -overflowX / 2;\n y = -overflowY / 2;\n break;\n case 'r': // Middle-Right\n x = -overflowX;\n y = -overflowY / 2;\n break;\n\n // Bottom row\n case 'bl': // Bottom-Left\n x = 0;\n y = -overflowY;\n break;\n case 'b': // Bottom-Center\n x = -overflowX / 2;\n y = -overflowY;\n break;\n case 'br': // Bottom-Right\n x = -overflowX;\n y = -overflowY;\n break;\n }\n\n // Step 5: Apply margin offsets (shift positions into margin-bounded area)\n x += mLeft;\n y += mTop;\n\n // Step 6: Apply user offsets\n // Offsets are in range -1 to 1, so convert to pixel values\n const offsetX = placement.offsetX || 0;\n const offsetY = placement.offsetY || 0;\n\n // The \"range\" is how far we can move the artwork\n const xRange = overflowX;\n const yRange = overflowY;\n\n x += offsetX * xRange;\n y += offsetY * yRange;\n\n // Round to whole pixels\n x = Math.round(x);\n y = Math.round(y);\n\n return {\n // Final scale to apply to artwork\n scale: finalScale,\n\n // Final artwork dimensions after scaling\n width: Math.round(scaledArtworkWidth),\n height: Math.round(scaledArtworkHeight),\n\n // Position to draw artwork (relative to artboard origin)\n x,\n y,\n\n // Debug info\n debug: {\n coverScale,\n userScale,\n overflow: { x: overflowX, y: overflowY },\n alignment,\n appliedOffset: { x: offsetX * xRange, y: offsetY * yRange },\n },\n };\n}\n\n/** A box inside an artboard, in artboard pixels (x, y from the artboard's top-left). */\nexport interface ImageRegion {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * An image of aspect `imageAspect` (width / height) covering `region` and CROPPED to it: the uncropped display size\n * the editor stores, the centred crop (fractions of the image, 0 to 1), and the centre of what is seen.\n *\n * For an artboard that holds several print panels side by side (a tote's back and front on one sheet): the first\n * picture goes on EACH panel whole, as the print and the mockup put it, and never over the sheet as one. Cropped,\n * because a picture that merely covered its panel would hang over into the panel beside it.\n */\nexport function coverRegion(imageAspect: number, region: ImageRegion): {\n width: number;\n height: number;\n cropX: number;\n cropY: number;\n cropWidth: number;\n cropHeight: number;\n centerX: number;\n centerY: number;\n} {\n if (!(imageAspect > 0) || !(region.width > 0) || !(region.height > 0)) {\n throw new Error(`E_IMAGE_REGION: an image of aspect ${imageAspect} cannot cover a ${region.width}x${region.height} region`);\n }\n const centerX = region.x + region.width / 2;\n const centerY = region.y + region.height / 2;\n if (imageAspect >= region.width / region.height) {\n // wider than the panel: its sides are cropped\n const width = region.height * imageAspect;\n const cropWidth = region.width / width;\n return { width, height: region.height, cropX: (1 - cropWidth) / 2, cropY: 0, cropWidth, cropHeight: 1, centerX, centerY };\n }\n const height = region.width / imageAspect;\n const cropHeight = region.height / height;\n return { width: region.width, height, cropX: 0, cropY: (1 - cropHeight) / 2, cropWidth: 1, cropHeight, centerX, centerY };\n}\n"],"names":["alignmentMap","getAlignment","value","calculateArtworkPlacement","artwork","placement","mode","mTop","mRight","mBottom","mLeft","effectiveWidth","effectiveHeight","scaleX","scaleY","coverScale","userScale","finalScale","scaledArtworkWidth","scaledArtworkHeight","alignment","x","y","overflowX","overflowY","offsetX","offsetY","xRange","yRange","coverRegion","imageAspect","region","centerX","centerY","width","cropWidth","height","cropHeight"],"mappings":"AAwEO,MAAMA,IAA0C;AAAA;AAAA,EAErD,WAAW;AAAA,EACX,KAAO;AAAA,EACP,QAAU;AAAA,EACV,QAAU;AAAA,EACV,cAAc;AAAA;AAAA,EAEd,YAAY;AAAA,EACZ,MAAQ;AAAA,EACR,OAAS;AAAA,EACT,aAAa;AAAA;AAAA,EAEb,IAAM;AAAA,EACN,GAAK;AAAA,EACL,IAAM;AAAA,EACN,GAAK;AAAA,EACL,GAAK;AAAA,EACL,GAAK;AAAA,EACL,IAAM;AAAA,EACN,GAAK;AAAA,EACL,IAAM;AACR;AAKO,SAASC,EAAaC,GAAkD;AAC7E,SAAKA,KACEF,EAAaE,CAAK,KAAK;AAChC;AAiBO,SAASC,EACdC,GACAC,GACwB;AAExB,QAAMC,IAAOD,EAAU,aAAa,SAG9BE,KAAQD,MAAS,YAAY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,GACxBO,IAAaN,EAAO,SAASK;AACnC,SAAO,EAAE,OAAOL,EAAO,OAAO,QAAAK,GAAQ,OAAO,GAAG,QAAQ,IAAIC,KAAc,GAAG,WAAW,GAAG,YAAAA,GAAY,SAAAL,GAAS,SAAAC,EAAA;AAClH;"}
|
|
1
|
+
{"version":3,"file":"placement-tSiIVhrL.js","sources":["../src/utils/ArtworkPlacement.ts"],"sourcesContent":["/**\n * ArtworkPlacement - Utility for calculating artwork position and scale\n *\n * Uses \"cover\" logic (like CSS object-fit: cover) to ensure artwork fills\n * the entire artboard while maintaining aspect ratio.\n */\n\n/**\n * 9-point alignment options for positioning artwork\n */\nexport type Alignment = 'tl' | 't' | 'tr' | 'l' | 'c' | 'r' | 'bl' | 'b' | 'br';\n\n/**\n * Scale mode for artwork placement\n * - \"cover\" (default): fills entire area, may crop (like CSS object-fit: cover)\n * - \"contain\": fits entirely inside area, may have empty space (like CSS object-fit: contain)\n */\nexport type ScaleMode = 'cover' | 'contain';\n\n/**\n * Placement configuration for artwork positioning\n */\nexport interface PlacementConfig {\n /** Artboard width in pixels */\n width: number;\n /** Artboard height in pixels */\n height: number;\n /** User scale multiplier (default: 1) */\n scale?: number;\n /** 9-point alignment (default: \"c\" for center) */\n align?: Alignment;\n /** X offset in range -1 to 1 (default: 0) */\n offsetX?: number;\n /** Y offset in range -1 to 1 (default: 0) */\n offsetY?: number;\n /** Scale mode: \"cover\" fills area (may crop), \"contain\" fits inside (may have space). Default: \"cover\" */\n scaleMode?: ScaleMode;\n /** Top margin in pixels (reduces available area in contain mode) */\n marginTop?: number;\n /** Right margin in pixels (reduces available area in contain mode) */\n marginRight?: number;\n /** Bottom margin in pixels (reduces available area in contain mode) */\n marginBottom?: number;\n /** Left margin in pixels (reduces available area in contain mode) */\n marginLeft?: number;\n}\n\n/**\n * Result of artwork placement calculation\n */\nexport interface ArtworkPlacementResult {\n /** Final scale to apply to artwork */\n scale: number;\n /** Final artwork dimensions after scaling */\n width: number;\n height: number;\n /** Position to draw artwork (relative to artboard origin) */\n x: number;\n y: number;\n /** Debug information */\n debug: {\n coverScale: number;\n userScale: number;\n overflow: { x: number; y: number };\n alignment: string;\n appliedOffset: { x: number; y: number };\n };\n}\n\n/**\n * Map string alignment values to 9-point grid\n */\nexport const alignmentMap: Record<string, Alignment> = {\n // Vertical alignments (map to top/center/bottom center)\n 'far-top': 't',\n 'top': 't',\n 'center': 'c',\n 'bottom': 'b',\n 'far-bottom': 'b',\n // Horizontal alignments (map to left/center/right middle)\n 'far-left': 'l',\n 'left': 'l',\n 'right': 'r',\n 'far-right': 'r',\n // Direct 9-point values\n 'tl': 'tl',\n 't': 't',\n 'tr': 'tr',\n 'l': 'l',\n 'c': 'c',\n 'r': 'r',\n 'bl': 'bl',\n 'b': 'b',\n 'br': 'br',\n};\n\n/**\n * Get Alignment from string (supports various naming conventions)\n */\nexport function getAlignment(value: string | Alignment | undefined): Alignment {\n if (!value) return 'c';\n return alignmentMap[value] || 'c';\n}\n\n/**\n * Calculates how to size and position artwork on an artboard\n * Uses \"cover\" logic (like CSS object-fit: cover) to ensure artwork fills the entire area\n *\n * @param artwork - The artwork dimensions\n * @param placement - The placement configuration\n * @returns Positioning and scaling information\n *\n * @example\n * const result = calculateArtworkPlacement(\n * { width: 1000, height: 1000 }, // Square artwork\n * { width: 500, height: 800 } // Tall artboard\n * );\n * // Result: artwork scaled to 800x800, positioned at x: -150, y: 0\n */\nexport function calculateArtworkPlacement(\n artwork: { width: number; height: number },\n placement: PlacementConfig\n): ArtworkPlacementResult {\n // Step 1: Calculate base scale based on scale mode\n const mode = placement.scaleMode || 'cover';\n\n // Margins reduce available area (only in contain mode)\n const mTop = (mode === 'contain' ? placement.marginTop : 0) || 0;\n const mRight = (mode === 'contain' ? placement.marginRight : 0) || 0;\n const mBottom = (mode === 'contain' ? placement.marginBottom : 0) || 0;\n const mLeft = (mode === 'contain' ? placement.marginLeft : 0) || 0;\n\n const effectiveWidth = placement.width - mLeft - mRight;\n const effectiveHeight = placement.height - mTop - mBottom;\n\n const scaleX = effectiveWidth / artwork.width;\n const scaleY = effectiveHeight / artwork.height;\n\n // \"cover\": use LARGER scale so artwork fills entire area (may crop)\n // \"contain\": use SMALLER scale so artwork fits entirely inside (may have space)\n const coverScale = mode === 'contain'\n ? Math.min(scaleX, scaleY)\n : Math.max(scaleX, scaleY);\n\n // Step 2: Apply user's custom scale multiplier\n const userScale = placement.scale || 1;\n const finalScale = coverScale * userScale;\n\n // Step 3: Calculate final artwork dimensions after scaling\n const scaledArtworkWidth = artwork.width * finalScale;\n const scaledArtworkHeight = artwork.height * finalScale;\n\n // Step 4: Calculate base position using alignment\n const alignment = placement.align || 'c'; // default to center\n let x = 0;\n let y = 0;\n\n // Calculate the \"overflow\" relative to effective area\n // In contain mode with margins, overflow is relative to the margin-bounded area\n const overflowX = scaledArtworkWidth - effectiveWidth;\n const overflowY = scaledArtworkHeight - effectiveHeight;\n\n // Apply 9-point alignment\n switch (alignment) {\n // Top row\n case 'tl': // Top-Left\n x = 0;\n y = 0;\n break;\n case 't': // Top-Center\n x = -overflowX / 2;\n y = 0;\n break;\n case 'tr': // Top-Right\n x = -overflowX;\n y = 0;\n break;\n\n // Middle row\n case 'l': // Middle-Left\n x = 0;\n y = -overflowY / 2;\n break;\n case 'c': // Center (default)\n default:\n x = -overflowX / 2;\n y = -overflowY / 2;\n break;\n case 'r': // Middle-Right\n x = -overflowX;\n y = -overflowY / 2;\n break;\n\n // Bottom row\n case 'bl': // Bottom-Left\n x = 0;\n y = -overflowY;\n break;\n case 'b': // Bottom-Center\n x = -overflowX / 2;\n y = -overflowY;\n break;\n case 'br': // Bottom-Right\n x = -overflowX;\n y = -overflowY;\n break;\n }\n\n // Step 5: Apply margin offsets (shift positions into margin-bounded area)\n x += mLeft;\n y += mTop;\n\n // Step 6: Apply user offsets\n // Offsets are in range -1 to 1, so convert to pixel values\n const offsetX = placement.offsetX || 0;\n const offsetY = placement.offsetY || 0;\n\n // The \"range\" is how far we can move the artwork\n const xRange = overflowX;\n const yRange = overflowY;\n\n x += offsetX * xRange;\n y += offsetY * yRange;\n\n // Round to whole pixels\n x = Math.round(x);\n y = Math.round(y);\n\n return {\n // Final scale to apply to artwork\n scale: finalScale,\n\n // Final artwork dimensions after scaling\n width: Math.round(scaledArtworkWidth),\n height: Math.round(scaledArtworkHeight),\n\n // Position to draw artwork (relative to artboard origin)\n x,\n y,\n\n // Debug info\n debug: {\n coverScale,\n userScale,\n overflow: { x: overflowX, y: overflowY },\n alignment,\n appliedOffset: { x: offsetX * xRange, y: offsetY * yRange },\n },\n };\n}\n\n/** A box inside an artboard, in artboard pixels (x, y from the artboard's top-left). */\nexport interface ImageRegion {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * An image of aspect `imageAspect` (width / height) covering `region` and CROPPED to it: the uncropped display size\n * the editor stores, the centred crop (fractions of the image, 0 to 1), and the centre of what is seen.\n *\n * For an artboard that holds several print panels side by side (a tote's back and front on one sheet): the first\n * picture goes on EACH panel whole, as the print and the mockup put it, and never over the sheet as one. Cropped,\n * because a picture that merely covered its panel would hang over into the panel beside it.\n */\nexport function coverRegion(imageAspect: number, region: ImageRegion): {\n width: number;\n height: number;\n cropX: number;\n cropY: number;\n cropWidth: number;\n cropHeight: number;\n centerX: number;\n centerY: number;\n} {\n if (!(imageAspect > 0) || !(region.width > 0) || !(region.height > 0)) {\n throw new Error(`E_IMAGE_REGION: an image of aspect ${imageAspect} cannot cover a ${region.width}x${region.height} region`);\n }\n const centerX = region.x + region.width / 2;\n const centerY = region.y + region.height / 2;\n if (imageAspect >= region.width / region.height) {\n // wider than the panel: its sides are cropped\n const width = region.height * imageAspect;\n const cropWidth = region.width / width;\n return { width, height: region.height, cropX: (1 - cropWidth) / 2, cropY: 0, cropWidth, cropHeight: 1, centerX, centerY };\n }\n const height = region.width / imageAspect;\n const cropHeight = region.height / height;\n return { width: region.width, height, cropX: 0, cropY: (1 - cropHeight) / 2, cropWidth: 1, cropHeight, centerX, centerY };\n}\n"],"names":["alignmentMap","getAlignment","value","calculateArtworkPlacement","artwork","placement","mode","mTop","mRight","mBottom","mLeft","effectiveWidth","effectiveHeight","scaleX","scaleY","coverScale","userScale","finalScale","scaledArtworkWidth","scaledArtworkHeight","alignment","x","y","overflowX","overflowY","offsetX","offsetY","xRange","yRange","coverRegion","imageAspect","region","centerX","centerY","width","cropWidth","height","cropHeight"],"mappings":"AAwEO,MAAMA,IAA0C;AAAA;AAAA,EAErD,WAAW;AAAA,EACX,KAAO;AAAA,EACP,QAAU;AAAA,EACV,QAAU;AAAA,EACV,cAAc;AAAA;AAAA,EAEd,YAAY;AAAA,EACZ,MAAQ;AAAA,EACR,OAAS;AAAA,EACT,aAAa;AAAA;AAAA,EAEb,IAAM;AAAA,EACN,GAAK;AAAA,EACL,IAAM;AAAA,EACN,GAAK;AAAA,EACL,GAAK;AAAA,EACL,GAAK;AAAA,EACL,IAAM;AAAA,EACN,GAAK;AAAA,EACL,IAAM;AACR;AAKO,SAASC,EAAaC,GAAkD;AAC7E,SAAKA,KACEF,EAAaE,CAAK,KAAK;AAChC;AAiBO,SAASC,EACdC,GACAC,GACwB;AAExB,QAAMC,IAAOD,EAAU,aAAa,SAG9BE,KAAQD,MAAS,YAAYD,EAAU,YAAY,MAAM,GACzDG,KAAUF,MAAS,YAAYD,EAAU,cAAc,MAAM,GAC7DI,KAAWH,MAAS,YAAYD,EAAU,eAAe,MAAM,GAC/DK,KAASJ,MAAS,YAAYD,EAAU,aAAa,MAAM,GAE3DM,IAAiBN,EAAU,QAAQK,IAAQF,GAC3CI,IAAkBP,EAAU,SAASE,IAAOE,GAE5CI,IAASF,IAAiBP,EAAQ,OAClCU,IAASF,IAAkBR,EAAQ,QAInCW,IAAaT,MAAS,YACxB,KAAK,IAAIO,GAAQC,CAAM,IACvB,KAAK,IAAID,GAAQC,CAAM,GAGrBE,IAAYX,EAAU,SAAS,GAC/BY,IAAaF,IAAaC,GAG1BE,IAAqBd,EAAQ,QAAQa,GACrCE,IA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AAAA,MACA,WAAAC;AAAA,MACA,UAAU,EAAE,GAAGO,GAAW,GAAGC,EAAA;AAAA,MAC7B,WAAAJ;AAAA,MACA,eAAe,EAAE,GAAGK,IAAUE,GAAQ,GAAGD,IAAUE,EAAA;AAAA,IAAO;AAAA,EAC5D;AAEJ;AAkBO,SAASC,EAAYC,GAAqBC,GAS/C;AACA,MAAI,EAAED,IAAc,MAAM,EAAEC,EAAO,QAAQ,MAAM,EAAEA,EAAO,SAAS;AACjE,UAAM,IAAI,MAAM,sCAAsCD,CAAW,mBAAmBC,EAAO,KAAK,IAAIA,EAAO,MAAM,SAAS;AAE5H,QAAMC,IAAUD,EAAO,IAAIA,EAAO,QAAQ,GACpCE,IAAUF,EAAO,IAAIA,EAAO,SAAS;AAC3C,MAAID,KAAeC,EAAO,QAAQA,EAAO,QAAQ;AAE/C,UAAMG,IAAQH,EAAO,SAASD,GACxBK,IAAYJ,EAAO,QAAQG;AACjC,WAAO,EAAE,OAAAA,GAAO,QAAQH,EAAO,QAAQ,QAAQ,IAAII,KAAa,GAAG,OAAO,GAAG,WAAAA,GAAW,YAAY,GAAG,SAAAH,GAAS,SAAAC,EAAA;AAAA,EAClH;AACA,QAAMG,IAASL,EAAO,QAAQD,GACxBO,IAAaN,EAAO,SAASK;AACnC,SAAO,EAAE,OAAOL,EAAO,OAAO,QAAAK,GAAQ,OAAO,GAAG,QAAQ,IAAIC,KAAc,GAAG,WAAW,GAAG,YAAAA,GAAY,SAAAL,GAAS,SAAAC,EAAA;AAClH;"}
|
package/dist/placement.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as v, p as V, T, I as M, z as st } from "./FontAnalyzer-
|
|
2
|
-
import {
|
|
1
|
+
import { t as v, p as V, T, I as M, z as st } from "./FontAnalyzer-Ch1jgTq7.js";
|
|
2
|
+
import { j as G, b as ot, k as it, u as O, a as B, m as rt } from "./design-builder-BFM94eA9.js";
|
|
3
3
|
import { toOptionAttributes as at, toCombinations as ct, getMissingSelections as lt, validateProductSelection as mt, findBestCombination as F, computeDisabledChoices as ft } from "@snowcone-app/sdk";
|
|
4
|
-
import { useEffect as ut, useContext as Z, useId as dt, useLayoutEffect as ht, useRef as C, useMemo as A, useCallback as
|
|
5
|
-
import { E as tt, U as gt } from "./useCommands-
|
|
6
|
-
import { b as pt, o as $, c as f,
|
|
4
|
+
import { useEffect as ut, useContext as Z, useId as dt, useLayoutEffect as ht, useRef as C, useMemo as A, useCallback as k, useState as q } from "react";
|
|
5
|
+
import { E as tt, U as gt } from "./useCommands-DSapP-w1.js";
|
|
6
|
+
import { b as pt, o as $, c as f, e as bt, l as h, n as yt, u as z, f as vt } from "./CanvasStateV1-BQ3cbxt2.js";
|
|
7
7
|
function R(s) {
|
|
8
8
|
return s.text;
|
|
9
9
|
}
|
|
@@ -129,7 +129,7 @@ class Pt {
|
|
|
129
129
|
function J(s) {
|
|
130
130
|
return (s.choices ?? []).map((t) => typeof t == "string" ? t : t.label ?? "").filter((t) => t !== "");
|
|
131
131
|
}
|
|
132
|
-
function
|
|
132
|
+
function Nt(s, t) {
|
|
133
133
|
if (!s.variantId) return {};
|
|
134
134
|
const e = t.find((n) => n.variantId === s.variantId);
|
|
135
135
|
if (!e) return {};
|
|
@@ -140,7 +140,7 @@ function vt(s, t) {
|
|
|
140
140
|
}
|
|
141
141
|
class Wt {
|
|
142
142
|
constructor(t) {
|
|
143
|
-
this.quantity = 1, this.version = 0, this.listeners = /* @__PURE__ */ new Set(), this.getVersion = () => this.version, this.subscribe = (e) => (this.listeners.add(e), () => this.listeners.delete(e)), this.product = t, this.attrs = at({ options: t.options }), this.combos = ct({ options: t.options }), this.selection =
|
|
143
|
+
this.quantity = 1, this.version = 0, this.listeners = /* @__PURE__ */ new Set(), this.getVersion = () => this.version, this.subscribe = (e) => (this.listeners.add(e), () => this.listeners.delete(e)), this.product = t, this.attrs = at({ options: t.options }), this.combos = ct({ options: t.options }), this.selection = Nt(t, this.combos);
|
|
144
144
|
}
|
|
145
145
|
getAttributes() {
|
|
146
146
|
return this.attrs;
|
|
@@ -237,19 +237,19 @@ class Wt {
|
|
|
237
237
|
for (const t of [...this.listeners]) t();
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
function
|
|
240
|
+
function Kt() {
|
|
241
241
|
const { selectedElement: s } = ot();
|
|
242
242
|
return s ?? null;
|
|
243
243
|
}
|
|
244
|
-
const
|
|
244
|
+
const $t = 3e3, X = {
|
|
245
245
|
text: "useTextBinding",
|
|
246
246
|
image: "useImageBinding",
|
|
247
247
|
font: "useFontBinding"
|
|
248
|
-
},
|
|
248
|
+
}, xt = {
|
|
249
249
|
text: "setText",
|
|
250
250
|
image: "setImageUrl",
|
|
251
251
|
font: "setFontFamily"
|
|
252
|
-
},
|
|
252
|
+
}, Ct = {
|
|
253
253
|
text: "text",
|
|
254
254
|
image: "image",
|
|
255
255
|
font: "text"
|
|
@@ -257,8 +257,8 @@ const Nt = 3e3, X = {
|
|
|
257
257
|
function Q(s) {
|
|
258
258
|
return s instanceof T ? "text" : s instanceof M ? "image" : "other";
|
|
259
259
|
}
|
|
260
|
-
function
|
|
261
|
-
const o = `[${X[s]}]`, n = `the binding is dead (isConnected: false, ${
|
|
260
|
+
function Ot(s, t, e) {
|
|
261
|
+
const o = `[${X[s]}]`, n = `the binding is dead (isConnected: false, ${xt[s]} is a no-op)`, i = Ct[s], a = e.getAllByName(t);
|
|
262
262
|
if (a.length > 0) {
|
|
263
263
|
const l = [...new Set(a.map(Q))], m = i === "text" ? "image" : "text", N = l.length === 1 && l[0] === m ? ` Bind it with ${X[m]}("${t}") instead.` : "";
|
|
264
264
|
return `${o} the layer named "${t}" is ${l.join("/")}, not ${i} — ${n}.${N}`;
|
|
@@ -273,12 +273,12 @@ function Y(s, t, e, o) {
|
|
|
273
273
|
const n = `${s}:${t}`;
|
|
274
274
|
if (U.has(n)) return;
|
|
275
275
|
const i = setTimeout(() => {
|
|
276
|
-
U.has(n) || (U.add(n), console.warn(
|
|
277
|
-
},
|
|
276
|
+
U.has(n) || (U.add(n), console.warn(Ot(s, t, e)));
|
|
277
|
+
}, $t);
|
|
278
278
|
return () => clearTimeout(i);
|
|
279
279
|
}, [s, t, e, o]);
|
|
280
280
|
}
|
|
281
|
-
function
|
|
281
|
+
function _(s) {
|
|
282
282
|
const t = Z(tt), e = dt();
|
|
283
283
|
ht(() => {
|
|
284
284
|
if (t)
|
|
@@ -288,16 +288,16 @@ function k(s) {
|
|
|
288
288
|
function L(s) {
|
|
289
289
|
return s instanceof T ? "text" : s instanceof M ? "image" : null;
|
|
290
290
|
}
|
|
291
|
-
const
|
|
291
|
+
const St = {
|
|
292
292
|
text: "useTextBinding / useFontBinding",
|
|
293
293
|
image: "useImageBinding"
|
|
294
294
|
};
|
|
295
|
-
function
|
|
295
|
+
function j(s, t, e) {
|
|
296
296
|
const o = it(s), n = o ? s.name : s, i = Z(tt), a = C(null);
|
|
297
297
|
if (o && s.kind !== t)
|
|
298
298
|
throw new v(
|
|
299
299
|
"E_LAYER_WRONG_KIND",
|
|
300
|
-
`layer "${n}" is a ${s.kind} token — this hook binds ${t} layers only (use ${
|
|
300
|
+
`layer "${n}" is a ${s.kind} token — this hook binds ${t} layers only (use ${St[s.kind]}).`,
|
|
301
301
|
{ layerName: n, actualKind: s.kind, expectedKind: t, docSlug: "embed-mode" }
|
|
302
302
|
);
|
|
303
303
|
if (o && i && a.current !== n) {
|
|
@@ -325,12 +325,12 @@ function P(s, t, e) {
|
|
|
325
325
|
}
|
|
326
326
|
return n;
|
|
327
327
|
}
|
|
328
|
-
const
|
|
329
|
-
},
|
|
330
|
-
function
|
|
328
|
+
const Dt = () => {
|
|
329
|
+
}, Et = [];
|
|
330
|
+
function Ht(s) {
|
|
331
331
|
const { elementStore: t } = O();
|
|
332
|
-
|
|
333
|
-
const e =
|
|
332
|
+
_("useTextBinding()");
|
|
333
|
+
const e = j(s, "text", t), { executeElementUpdate: o } = B(), n = A(() => t.getAllByName(e).filter((r) => r instanceof T), [t, e]), i = k(
|
|
334
334
|
(a) => {
|
|
335
335
|
for (const r of n) {
|
|
336
336
|
const c = r.clone();
|
|
@@ -339,7 +339,7 @@ function Kt(s) {
|
|
|
339
339
|
},
|
|
340
340
|
[n, o]
|
|
341
341
|
);
|
|
342
|
-
return Y("text", e, t, n.length > 0), n.length === 0 ? { text: "", setText:
|
|
342
|
+
return Y("text", e, t, n.length > 0), n.length === 0 ? { text: "", setText: Dt, element: null, elements: Et, isConnected: !1 } : {
|
|
343
343
|
text: n[0].getText(),
|
|
344
344
|
setText: i,
|
|
345
345
|
element: n[0],
|
|
@@ -347,9 +347,9 @@ function Kt(s) {
|
|
|
347
347
|
isConnected: !0
|
|
348
348
|
};
|
|
349
349
|
}
|
|
350
|
-
const
|
|
351
|
-
},
|
|
352
|
-
function
|
|
350
|
+
const It = () => {
|
|
351
|
+
}, Tt = [];
|
|
352
|
+
function Bt(s, t, e) {
|
|
353
353
|
const o = s / t;
|
|
354
354
|
if (e >= o) {
|
|
355
355
|
const n = t, i = n * e, a = s / i;
|
|
@@ -373,9 +373,9 @@ function Tt(s, t, e) {
|
|
|
373
373
|
};
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
|
-
function
|
|
377
|
-
|
|
378
|
-
const e = (t == null ? void 0 : t.fit) ?? "cover", { elementStore: o, setElements: n } = O(), i =
|
|
376
|
+
function Vt(s, t) {
|
|
377
|
+
_("useImageBinding()");
|
|
378
|
+
const e = (t == null ? void 0 : t.fit) ?? "cover", { elementStore: o, setElements: n } = O(), i = j(s, "image", o), { executeElementUpdate: a } = B(), r = A(() => o.getAllByName(i).filter((b) => b instanceof M), [o, i]), c = C(/* @__PURE__ */ new Map());
|
|
379
379
|
for (const d of r)
|
|
380
380
|
if (!c.current.has(d.id)) {
|
|
381
381
|
const b = d.transformData;
|
|
@@ -390,26 +390,26 @@ function Ht(s, t) {
|
|
|
390
390
|
m.current = a;
|
|
391
391
|
const N = C(n);
|
|
392
392
|
N.current = n;
|
|
393
|
-
const S =
|
|
393
|
+
const S = k(
|
|
394
394
|
(d) => {
|
|
395
|
-
const b = l.current,
|
|
395
|
+
const b = l.current, P = m.current;
|
|
396
396
|
for (const D of b) {
|
|
397
|
-
const
|
|
398
|
-
if (!
|
|
399
|
-
const { width: K, height: H } =
|
|
400
|
-
|
|
401
|
-
const E = u.imageAspectRatio || 1,
|
|
402
|
-
u.transformData.width =
|
|
403
|
-
}) : (
|
|
404
|
-
const E = u.transformData.width,
|
|
405
|
-
w < 1 && (u.transformData.width = E * w, u.transformData.height =
|
|
406
|
-
}),
|
|
397
|
+
const W = c.current.get(D.id);
|
|
398
|
+
if (!W) continue;
|
|
399
|
+
const { width: K, height: H } = W, g = D.clone();
|
|
400
|
+
g.imageLoaded = !1, g.imageElement = null, g.isCropping = !1, g.imageUrl = d, e === "cover" ? (g.preserveDimensions = !0, g.onLoadCallback = (u) => {
|
|
401
|
+
const E = u.imageAspectRatio || 1, p = Bt(K, H, E);
|
|
402
|
+
u.transformData.width = p.width, u.transformData.height = p.height, u.transformData.cropX = p.cropX, u.transformData.cropY = p.cropY, u.transformData.cropWidth = p.cropWidth, u.transformData.cropHeight = p.cropHeight, P(D, u);
|
|
403
|
+
}) : (g.preserveDimensions = !1, g.onLoadCallback = (u) => {
|
|
404
|
+
const E = u.transformData.width, p = u.transformData.height, w = Math.min(K / E, H / p, 1);
|
|
405
|
+
w < 1 && (u.transformData.width = E * w, u.transformData.height = p * w), u.transformData.cropX = 0, u.transformData.cropY = 0, u.transformData.cropWidth = 1, u.transformData.cropHeight = 1, P(D, u);
|
|
406
|
+
}), g.loadImage(d);
|
|
407
407
|
}
|
|
408
408
|
},
|
|
409
409
|
[e]
|
|
410
410
|
// Stable deps only — imageElements/executeElementUpdate/setElements accessed via refs
|
|
411
411
|
);
|
|
412
|
-
return Y("image", i, o, r.length > 0), r.length === 0 ? { imageUrl: "", setImageUrl:
|
|
412
|
+
return Y("image", i, o, r.length > 0), r.length === 0 ? { imageUrl: "", setImageUrl: It, element: null, elements: Tt, isConnected: !1 } : {
|
|
413
413
|
imageUrl: r[0].imageUrl,
|
|
414
414
|
setImageUrl: S,
|
|
415
415
|
element: r[0],
|
|
@@ -417,7 +417,7 @@ function Ht(s, t) {
|
|
|
417
417
|
isConnected: !0
|
|
418
418
|
};
|
|
419
419
|
}
|
|
420
|
-
const
|
|
420
|
+
const At = [];
|
|
421
421
|
function I(s) {
|
|
422
422
|
let t = s.trim().toUpperCase();
|
|
423
423
|
return t.length === 4 && t.startsWith("#") && (t = "#" + t[1] + t[1] + t[2] + t[2] + t[3] + t[3]), t;
|
|
@@ -430,26 +430,26 @@ function et(s, t) {
|
|
|
430
430
|
const e = s;
|
|
431
431
|
return y(e.color, t) || y((o = e.transformData) == null ? void 0 : o.fillColor, t) || y((n = e.transformData) == null ? void 0 : n.strokeColor, t) || ((i = e.stroke) == null ? void 0 : i.enabled) === !0 && y(e.stroke.color, t);
|
|
432
432
|
}
|
|
433
|
-
function
|
|
433
|
+
function kt(s, t, e) {
|
|
434
434
|
var a, r, c;
|
|
435
435
|
if (!et(s, t)) return null;
|
|
436
436
|
const o = s.clone(), n = s, i = o;
|
|
437
437
|
return y(n.color, t) && (typeof i.setColor == "function" ? i.setColor(e) : i.color = e), y((a = n.transformData) == null ? void 0 : a.fillColor, t) && (i.transformData = { ...i.transformData, fillColor: e }), y((r = n.transformData) == null ? void 0 : r.strokeColor, t) && (i.transformData = { ...i.transformData, strokeColor: e }), ((c = n.stroke) == null ? void 0 : c.enabled) === !0 && y(n.stroke.color, t) && (i.stroke = { ...i.stroke, color: e }), o;
|
|
438
438
|
}
|
|
439
|
-
function
|
|
439
|
+
function Gt(s) {
|
|
440
440
|
const t = rt(s) ? s.value : s, { elementStore: e } = O(), { executeElementUpdate: o } = B();
|
|
441
|
-
|
|
441
|
+
_("useColorBinding()");
|
|
442
442
|
const [n, i] = q(() => I(t)), [a, r] = q(t);
|
|
443
443
|
t !== a && (r(t), i(I(t)));
|
|
444
444
|
const c = A(
|
|
445
445
|
() => e.getAll().filter((m) => et(m, n)),
|
|
446
446
|
[e, n]
|
|
447
|
-
), l =
|
|
447
|
+
), l = k(
|
|
448
448
|
(m) => {
|
|
449
449
|
const N = I(m);
|
|
450
450
|
if (N !== n) {
|
|
451
451
|
for (const S of e.getAll()) {
|
|
452
|
-
const d =
|
|
452
|
+
const d = kt(S, n, m);
|
|
453
453
|
d && o(S, d);
|
|
454
454
|
}
|
|
455
455
|
i(N);
|
|
@@ -457,14 +457,14 @@ function Vt(s) {
|
|
|
457
457
|
},
|
|
458
458
|
[e, n, o]
|
|
459
459
|
);
|
|
460
|
-
return c.length === 0 ? { color: n, setColor: l, elements:
|
|
460
|
+
return c.length === 0 ? { color: n, setColor: l, elements: At, isConnected: !1 } : { color: n, setColor: l, elements: c, isConnected: !0 };
|
|
461
461
|
}
|
|
462
462
|
const _t = () => {
|
|
463
|
-
},
|
|
464
|
-
function
|
|
463
|
+
}, wt = [];
|
|
464
|
+
function qt(s) {
|
|
465
465
|
const { elementStore: t } = O();
|
|
466
|
-
|
|
467
|
-
const e =
|
|
466
|
+
_("useFontBinding()");
|
|
467
|
+
const e = j(s, "text", t), { executeElementUpdate: o } = B(), n = A(() => t.getAllByName(e).filter((r) => r instanceof T), [t, e]), i = k(
|
|
468
468
|
(a) => {
|
|
469
469
|
gt.loadGoogleFontByName(a);
|
|
470
470
|
for (const r of n) {
|
|
@@ -476,7 +476,7 @@ function Gt(s) {
|
|
|
476
476
|
},
|
|
477
477
|
[n, o]
|
|
478
478
|
);
|
|
479
|
-
return Y("font", e, t, n.length > 0), n.length === 0 ? { fontFamily: "", setFontFamily: _t, element: null, elements:
|
|
479
|
+
return Y("font", e, t, n.length > 0), n.length === 0 ? { fontFamily: "", setFontFamily: _t, element: null, elements: wt, isConnected: !1 } : {
|
|
480
480
|
fontFamily: n[0].fontFamily,
|
|
481
481
|
setFontFamily: i,
|
|
482
482
|
element: n[0],
|
|
@@ -484,73 +484,75 @@ function Gt(s) {
|
|
|
484
484
|
isConnected: !0
|
|
485
485
|
};
|
|
486
486
|
}
|
|
487
|
-
function
|
|
487
|
+
function zt(s) {
|
|
488
488
|
const { elementStore: t } = O();
|
|
489
489
|
return s ? t.getByName(s) ?? null : null;
|
|
490
490
|
}
|
|
491
|
-
const nt = "personalization",
|
|
491
|
+
const nt = "personalization", Ft = pt("type", [
|
|
492
492
|
$({
|
|
493
|
-
type:
|
|
493
|
+
type: h("text"),
|
|
494
494
|
name: f().min(1),
|
|
495
495
|
label: f(),
|
|
496
496
|
placeholder: f().optional(),
|
|
497
|
-
maxLength:
|
|
497
|
+
maxLength: yt().int().positive().optional(),
|
|
498
|
+
fit: h("shrink").optional(),
|
|
499
|
+
sample: bt().optional(),
|
|
498
500
|
artboard: f().min(1).optional(),
|
|
499
501
|
group: f().optional()
|
|
500
502
|
}),
|
|
501
503
|
$({
|
|
502
|
-
type:
|
|
504
|
+
type: h("image"),
|
|
503
505
|
name: f().min(1),
|
|
504
506
|
label: f(),
|
|
505
507
|
placeholder: f().optional(),
|
|
506
|
-
fit: z([
|
|
508
|
+
fit: z([h("cover"), h("contain")]).optional(),
|
|
507
509
|
artboard: f().min(1).optional(),
|
|
508
510
|
group: f().optional()
|
|
509
511
|
}),
|
|
510
512
|
$({
|
|
511
|
-
type:
|
|
513
|
+
type: h("color"),
|
|
512
514
|
color: f().min(1),
|
|
513
515
|
label: f(),
|
|
514
516
|
artboard: f().min(1).optional(),
|
|
515
517
|
group: f().optional()
|
|
516
518
|
}),
|
|
517
519
|
$({
|
|
518
|
-
type:
|
|
520
|
+
type: h("select"),
|
|
519
521
|
name: f().min(1),
|
|
520
522
|
label: f(),
|
|
521
|
-
property: z([
|
|
522
|
-
options:
|
|
523
|
+
property: z([h("text"), h("imageUrl"), h("fontFamily")]),
|
|
524
|
+
options: vt($({ label: f(), value: f() })).min(1),
|
|
523
525
|
artboard: f().min(1).optional(),
|
|
524
526
|
group: f().optional()
|
|
525
527
|
})
|
|
526
528
|
]);
|
|
527
|
-
function
|
|
529
|
+
function Jt(s) {
|
|
528
530
|
if (!s || typeof s != "object") return [];
|
|
529
531
|
const t = s[nt];
|
|
530
532
|
if (!Array.isArray(t)) return [];
|
|
531
533
|
const e = [];
|
|
532
534
|
for (const o of t) {
|
|
533
535
|
if (!o || typeof o != "object") continue;
|
|
534
|
-
const n = "type" in o ? o : { ...o, type: "text" }, i =
|
|
536
|
+
const n = "type" in o ? o : { ...o, type: "text" }, i = Ft.safeParse(n);
|
|
535
537
|
i.success && e.push(i.data);
|
|
536
538
|
}
|
|
537
539
|
return e;
|
|
538
540
|
}
|
|
539
|
-
function
|
|
541
|
+
function Xt(s, t) {
|
|
540
542
|
return { ...s, [nt]: t };
|
|
541
543
|
}
|
|
542
544
|
export {
|
|
543
545
|
Wt as C,
|
|
544
546
|
Pt as D,
|
|
545
547
|
nt as T,
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
548
|
+
zt as a,
|
|
549
|
+
qt as b,
|
|
550
|
+
Vt as c,
|
|
551
|
+
Kt as d,
|
|
552
|
+
Ht as e,
|
|
551
553
|
J as f,
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
554
|
+
Jt as r,
|
|
555
|
+
Gt as u,
|
|
556
|
+
Xt as w
|
|
555
557
|
};
|
|
556
|
-
//# sourceMappingURL=template-fields-
|
|
558
|
+
//# sourceMappingURL=template-fields-CQURvcab.js.map
|