@snowcone-app/canvas 0.41.3 → 0.41.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.
- 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-C9tFMK5q.js} +3 -3
- package/dist/{CanvasStateV1-BJ5-75NN.js.map → CanvasStateV1-C9tFMK5q.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-CKqnla_y.js} +26 -26
- package/dist/EditorCanvasImpl-CKqnla_y.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-BSFMazgl.js +1098 -0
- package/dist/SnowconeCanvas-BSFMazgl.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-builder-BFM94eA9.js +1859 -0
- package/dist/design-builder-BFM94eA9.js.map +1 -0
- package/dist/{embed-GXevsHX5.js → embed-KG_YnRHA.js} +10 -10
- package/dist/{embed-GXevsHX5.js.map → embed-KG_YnRHA.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-C0qoE_ZH.js} +32 -32
- package/dist/{template-fields-tobyHoMe.js.map → template-fields-C0qoE_ZH.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 +4 -4
- 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-KG_YnRHA.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-C0qoE_ZH.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-C9tFMK5q.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-BSFMazgl.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-C0qoE_ZH.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-C9tFMK5q.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-C9tFMK5q.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,YAAYD,EAAU,YAAY,MAAM,GACzDG,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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,IAAsBf,EAAQ,SAASa,GAGvCG,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,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,16 +1,16 @@
|
|
|
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, n as bt, l as p, u as z, e as yt } from "./CanvasStateV1-
|
|
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, n as bt, l as p, u as z, e as yt } from "./CanvasStateV1-C9tFMK5q.js";
|
|
7
7
|
function R(s) {
|
|
8
8
|
return s.text;
|
|
9
9
|
}
|
|
10
10
|
function x(s) {
|
|
11
11
|
return s.name;
|
|
12
12
|
}
|
|
13
|
-
class
|
|
13
|
+
class jt {
|
|
14
14
|
constructor(t) {
|
|
15
15
|
this.listeners = /* @__PURE__ */ new Set(), this.getState = () => this.state, this.subscribe = (o) => (this.listeners.add(o), () => this.listeners.delete(o)), this.state = t;
|
|
16
16
|
const e = /* @__PURE__ */ new Map();
|
|
@@ -138,7 +138,7 @@ function vt(s, t) {
|
|
|
138
138
|
n === "variantId" || n === "price" || (typeof i == "string" ? o[n] = i : typeof i == "number" && (o[n] = String(i)));
|
|
139
139
|
return o;
|
|
140
140
|
}
|
|
141
|
-
class
|
|
141
|
+
class Pt {
|
|
142
142
|
constructor(t) {
|
|
143
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 = vt(t, this.combos);
|
|
144
144
|
}
|
|
@@ -237,7 +237,7 @@ class Wt {
|
|
|
237
237
|
for (const t of [...this.listeners]) t();
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
function
|
|
240
|
+
function Wt() {
|
|
241
241
|
const { selectedElement: s } = ot();
|
|
242
242
|
return s ?? null;
|
|
243
243
|
}
|
|
@@ -278,7 +278,7 @@ function Y(s, t, e, o) {
|
|
|
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)
|
|
@@ -292,7 +292,7 @@ const Ot = {
|
|
|
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(
|
|
@@ -329,8 +329,8 @@ const St = () => {
|
|
|
329
329
|
}, Dt = [];
|
|
330
330
|
function Kt(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();
|
|
@@ -374,8 +374,8 @@ function Tt(s, t, e) {
|
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
376
|
function Ht(s, t) {
|
|
377
|
-
|
|
378
|
-
const e = (t == null ? void 0 : t.fit) ?? "cover", { elementStore: o, setElements: n } = O(), i =
|
|
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,19 +390,19 @@ 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 } =
|
|
397
|
+
const W = c.current.get(D.id);
|
|
398
|
+
if (!W) continue;
|
|
399
|
+
const { width: K, height: H } = W, h = D.clone();
|
|
400
400
|
h.imageLoaded = !1, h.imageElement = null, h.isCropping = !1, h.imageUrl = d, e === "cover" ? (h.preserveDimensions = !0, h.onLoadCallback = (u) => {
|
|
401
401
|
const E = u.imageAspectRatio || 1, g = Tt(K, H, E);
|
|
402
|
-
u.transformData.width = g.width, u.transformData.height = g.height, u.transformData.cropX = g.cropX, u.transformData.cropY = g.cropY, u.transformData.cropWidth = g.cropWidth, u.transformData.cropHeight = g.cropHeight,
|
|
402
|
+
u.transformData.width = g.width, u.transformData.height = g.height, u.transformData.cropX = g.cropX, u.transformData.cropY = g.cropY, u.transformData.cropWidth = g.cropWidth, u.transformData.cropHeight = g.cropHeight, P(D, u);
|
|
403
403
|
}) : (h.preserveDimensions = !1, h.onLoadCallback = (u) => {
|
|
404
404
|
const E = u.transformData.width, g = u.transformData.height, w = Math.min(K / E, H / g, 1);
|
|
405
|
-
w < 1 && (u.transformData.width = E * w, u.transformData.height = g * w), u.transformData.cropX = 0, u.transformData.cropY = 0, u.transformData.cropWidth = 1, u.transformData.cropHeight = 1,
|
|
405
|
+
w < 1 && (u.transformData.width = E * w, u.transformData.height = g * w), u.transformData.cropX = 0, u.transformData.cropY = 0, u.transformData.cropWidth = 1, u.transformData.cropHeight = 1, P(D, u);
|
|
406
406
|
}), h.loadImage(d);
|
|
407
407
|
}
|
|
408
408
|
},
|
|
@@ -438,13 +438,13 @@ function At(s, t, e) {
|
|
|
438
438
|
}
|
|
439
439
|
function Vt(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) {
|
|
@@ -459,12 +459,12 @@ function Vt(s) {
|
|
|
459
459
|
);
|
|
460
460
|
return c.length === 0 ? { color: n, setColor: l, elements: Bt, isConnected: !1 } : { color: n, setColor: l, elements: c, isConnected: !0 };
|
|
461
461
|
}
|
|
462
|
-
const
|
|
463
|
-
},
|
|
462
|
+
const kt = () => {
|
|
463
|
+
}, _t = [];
|
|
464
464
|
function Gt(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:
|
|
479
|
+
return Y("font", e, t, n.length > 0), n.length === 0 ? { fontFamily: "", setFontFamily: kt, element: null, elements: _t, isConnected: !1 } : {
|
|
480
480
|
fontFamily: n[0].fontFamily,
|
|
481
481
|
setFontFamily: i,
|
|
482
482
|
element: n[0],
|
|
@@ -540,17 +540,17 @@ function Jt(s, t) {
|
|
|
540
540
|
return { ...s, [nt]: t };
|
|
541
541
|
}
|
|
542
542
|
export {
|
|
543
|
-
|
|
544
|
-
|
|
543
|
+
Pt as C,
|
|
544
|
+
jt as D,
|
|
545
545
|
nt as T,
|
|
546
546
|
qt as a,
|
|
547
547
|
Gt as b,
|
|
548
548
|
Ht as c,
|
|
549
|
-
|
|
549
|
+
Wt as d,
|
|
550
550
|
Kt as e,
|
|
551
551
|
J as f,
|
|
552
552
|
zt as r,
|
|
553
553
|
Vt as u,
|
|
554
554
|
Jt as w
|
|
555
555
|
};
|
|
556
|
-
//# sourceMappingURL=template-fields-
|
|
556
|
+
//# sourceMappingURL=template-fields-C0qoE_ZH.js.map
|