@snowcone-app/canvas 0.40.13 → 0.40.15
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/{EditorCanvasImpl-CP6ipFq_.js → EditorCanvasImpl-Bt-dfd8v.js} +3 -3
- package/dist/{EditorCanvasImpl-CP6ipFq_.js.map → EditorCanvasImpl-Bt-dfd8v.js.map} +1 -1
- package/dist/SnowconeCanvas-BZVuH85I.js +1134 -0
- package/dist/SnowconeCanvas-BZVuH85I.js.map +1 -0
- package/dist/advanced.mjs +2 -2
- package/dist/components/embed/SnowconeCanvas.d.ts +8 -0
- package/dist/{embed-CcKoxfdW.js → embed-Dzblbo8q.js} +2 -2
- package/dist/{embed-CcKoxfdW.js.map → embed-Dzblbo8q.js.map} +1 -1
- package/dist/embed.mjs +1 -1
- package/dist/index.mjs +2 -2
- package/dist/placement-D31o3YYC.js +102 -0
- package/dist/{placement-Br5jI_-u.js.map → placement-D31o3YYC.js.map} +1 -1
- package/dist/placement.mjs +1 -1
- package/dist/utils/ArtworkPlacement.d.ts +25 -0
- package/dist/utils/claimTouch.d.ts +16 -0
- package/dist/{validation-Q1_OcfJ_.js → validation-Ds2Df_gS.js} +890 -877
- package/dist/validation-Ds2Df_gS.js.map +1 -0
- package/example/package.json +1 -1
- package/package.json +3 -3
- package/dist/SnowconeCanvas-991f9eds.js +0 -1112
- package/dist/SnowconeCanvas-991f9eds.js.map +0 -1
- package/dist/placement-Br5jI_-u.js +0 -90
- package/dist/validation-Q1_OcfJ_.js.map +0 -1
package/dist/embed.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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-CLnk8kvW.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 v, g as y, i as F, h, p as k, s as D, j as I, k as K, l as L, v as w } from "./embed-
|
|
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 v, g as y, i as F, h, p as k, s as D, j as I, k as K, l as L, v as w } from "./embed-Dzblbo8q.js";
|
|
3
3
|
import { t as M, V as j } from "./FontAnalyzer-DWHS41ba.js";
|
|
4
4
|
import { D as N, e as V, h as _, i as z, b as H } from "./design-builder-CoCtjIwj.js";
|
|
5
5
|
import { D as O, T as Q, r as Y, u as q, a as U, b as W, c as X, d as Z, e as $, w as ee } from "./template-fields-BzAlpOEB.js";
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { e as u } from "./useCommands-CLnk8kvW.js";
|
|
2
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-CLnk8kvW.js";
|
|
3
|
-
import { E as F, S as L, S as _, u as O, a as R } from "./SnowconeCanvas-
|
|
3
|
+
import { E as F, S as L, S as _, u as O, a as R } from "./SnowconeCanvas-BZVuH85I.js";
|
|
4
4
|
import { b as m, d } from "./design-builder-CoCtjIwj.js";
|
|
5
5
|
import { C as z, D as w, e as K, s as D } from "./design-builder-CoCtjIwj.js";
|
|
6
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-BzAlpOEB.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-
|
|
7
|
+
import { A as J, C as q, E as Q, M as W, P as X, r as $, v as ee } from "./validation-Ds2Df_gS.js";
|
|
8
8
|
import { G as ae, H as te, J as oe, K as re } from "./ExportManager-DLOH2Kzk.js";
|
|
9
9
|
import { c as ie, e as ue } from "./compose-DtQL_oit.js";
|
|
10
10
|
import { d as de, m as Ce, s as Se, v as Ee } from "./CanvasStateV1-DwziqxMO.js";
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const y = {
|
|
2
|
+
// Vertical alignments (map to top/center/bottom center)
|
|
3
|
+
"far-top": "t",
|
|
4
|
+
top: "t",
|
|
5
|
+
center: "c",
|
|
6
|
+
bottom: "b",
|
|
7
|
+
"far-bottom": "b",
|
|
8
|
+
// Horizontal alignments (map to left/center/right middle)
|
|
9
|
+
"far-left": "l",
|
|
10
|
+
left: "l",
|
|
11
|
+
right: "r",
|
|
12
|
+
"far-right": "r",
|
|
13
|
+
// Direct 9-point values
|
|
14
|
+
tl: "tl",
|
|
15
|
+
t: "t",
|
|
16
|
+
tr: "tr",
|
|
17
|
+
l: "l",
|
|
18
|
+
c: "c",
|
|
19
|
+
r: "r",
|
|
20
|
+
bl: "bl",
|
|
21
|
+
b: "b",
|
|
22
|
+
br: "br"
|
|
23
|
+
};
|
|
24
|
+
function E(h) {
|
|
25
|
+
return h && y[h] || "c";
|
|
26
|
+
}
|
|
27
|
+
function H(h, t) {
|
|
28
|
+
const e = t.scaleMode || "cover", a = (e === "contain" ? t.marginTop : 0) || 0, f = (e === "contain" ? t.marginRight : 0) || 0, d = (e === "contain" ? t.marginBottom : 0) || 0, s = (e === "contain" ? t.marginLeft : 0) || 0, i = t.width - s - f, b = t.height - a - d, w = i / h.width, g = b / h.height, u = e === "contain" ? Math.min(w, g) : Math.max(w, g), k = t.scale || 1, l = u * k, M = h.width * l, v = h.height * l, x = t.align || "c";
|
|
29
|
+
let c = 0, o = 0;
|
|
30
|
+
const r = M - i, n = v - b;
|
|
31
|
+
switch (x) {
|
|
32
|
+
// Top row
|
|
33
|
+
case "tl":
|
|
34
|
+
c = 0, o = 0;
|
|
35
|
+
break;
|
|
36
|
+
case "t":
|
|
37
|
+
c = -r / 2, o = 0;
|
|
38
|
+
break;
|
|
39
|
+
case "tr":
|
|
40
|
+
c = -r, o = 0;
|
|
41
|
+
break;
|
|
42
|
+
// Middle row
|
|
43
|
+
case "l":
|
|
44
|
+
c = 0, o = -n / 2;
|
|
45
|
+
break;
|
|
46
|
+
case "c":
|
|
47
|
+
// Center (default)
|
|
48
|
+
default:
|
|
49
|
+
c = -r / 2, o = -n / 2;
|
|
50
|
+
break;
|
|
51
|
+
case "r":
|
|
52
|
+
c = -r, o = -n / 2;
|
|
53
|
+
break;
|
|
54
|
+
// Bottom row
|
|
55
|
+
case "bl":
|
|
56
|
+
c = 0, o = -n;
|
|
57
|
+
break;
|
|
58
|
+
case "b":
|
|
59
|
+
c = -r / 2, o = -n;
|
|
60
|
+
break;
|
|
61
|
+
case "br":
|
|
62
|
+
c = -r, o = -n;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
c += s, o += a;
|
|
66
|
+
const X = t.offsetX || 0, Y = t.offsetY || 0, m = r, R = n;
|
|
67
|
+
return c += X * m, o += Y * R, c = Math.round(c), o = Math.round(o), {
|
|
68
|
+
// Final scale to apply to artwork
|
|
69
|
+
scale: l,
|
|
70
|
+
// Final artwork dimensions after scaling
|
|
71
|
+
width: Math.round(M),
|
|
72
|
+
height: Math.round(v),
|
|
73
|
+
// Position to draw artwork (relative to artboard origin)
|
|
74
|
+
x: c,
|
|
75
|
+
y: o,
|
|
76
|
+
// Debug info
|
|
77
|
+
debug: {
|
|
78
|
+
coverScale: u,
|
|
79
|
+
userScale: k,
|
|
80
|
+
overflow: { x: r, y: n },
|
|
81
|
+
alignment: x,
|
|
82
|
+
appliedOffset: { x: X * m, y: Y * R }
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function W(h, t) {
|
|
87
|
+
if (!(h > 0) || !(t.width > 0) || !(t.height > 0))
|
|
88
|
+
throw new Error(`E_IMAGE_REGION: an image of aspect ${h} cannot cover a ${t.width}x${t.height} region`);
|
|
89
|
+
const e = t.x + t.width / 2, a = t.y + t.height / 2;
|
|
90
|
+
if (h >= t.width / t.height) {
|
|
91
|
+
const s = t.height * h, i = t.width / s;
|
|
92
|
+
return { width: s, height: t.height, cropX: (1 - i) / 2, cropY: 0, cropWidth: i, cropHeight: 1, centerX: e, centerY: a };
|
|
93
|
+
}
|
|
94
|
+
const f = t.width / h, d = t.height / f;
|
|
95
|
+
return { width: t.width, height: f, cropX: 0, cropY: (1 - d) / 2, cropWidth: 1, cropHeight: d, centerX: e, centerY: a };
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
W as a,
|
|
99
|
+
H as c,
|
|
100
|
+
E as g
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=placement-D31o3YYC.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"placement-Br5jI_-u.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"],"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"],"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,e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,IAAUrB,EAAU,WAAW,GAG/BsB,IAASJ,GACTK,IAASJ;AAEf,SAAAH,KAAKI,IAAUE,GACfL,KAAKI,IAAUE,GAGfP,IAAI,KAAK,MAAMA,CAAC,GAChBC,IAAI,KAAK,MAAMA,CAAC,GAET;AAAA;AAAA,IAEL,OAAOL;AAAA;AAAA,IAGP,OAAO,KAAK,MAAMC,CAAkB;AAAA,IACpC,QAAQ,KAAK,MAAMC,CAAmB;AAAA;AAAA,IAGtC,GAAAE;AAAA,IACA,GAAAC;AAAA;AAAA,IAGA,OAAO;AAAA,MACL,YAAAP;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;"}
|
|
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,KAAUF,MAAS,YAAYD,EAAU,cAAc,MAAM,GAC7DI,KAAWH,MAAS,YAAY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AAQ,IAAIC,KAAc,GAAG,WAAW,GAAG,YAAAA,GAAY,SAAAL,GAAS,SAAAC,EAAA;AAClH;"}
|
package/dist/placement.mjs
CHANGED
|
@@ -95,3 +95,28 @@ export declare function calculateArtworkPlacement(artwork: {
|
|
|
95
95
|
width: number;
|
|
96
96
|
height: number;
|
|
97
97
|
}, placement: PlacementConfig): ArtworkPlacementResult;
|
|
98
|
+
/** A box inside an artboard, in artboard pixels (x, y from the artboard's top-left). */
|
|
99
|
+
export interface ImageRegion {
|
|
100
|
+
x: number;
|
|
101
|
+
y: number;
|
|
102
|
+
width: number;
|
|
103
|
+
height: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* An image of aspect `imageAspect` (width / height) covering `region` and CROPPED to it: the uncropped display size
|
|
107
|
+
* the editor stores, the centred crop (fractions of the image, 0 to 1), and the centre of what is seen.
|
|
108
|
+
*
|
|
109
|
+
* For an artboard that holds several print panels side by side (a tote's back and front on one sheet): the first
|
|
110
|
+
* picture goes on EACH panel whole, as the print and the mockup put it, and never over the sheet as one. Cropped,
|
|
111
|
+
* because a picture that merely covered its panel would hang over into the panel beside it.
|
|
112
|
+
*/
|
|
113
|
+
export declare function coverRegion(imageAspect: number, region: ImageRegion): {
|
|
114
|
+
width: number;
|
|
115
|
+
height: number;
|
|
116
|
+
cropX: number;
|
|
117
|
+
cropY: number;
|
|
118
|
+
cropWidth: number;
|
|
119
|
+
cropHeight: number;
|
|
120
|
+
centerX: number;
|
|
121
|
+
centerY: number;
|
|
122
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make an element's touches its own.
|
|
3
|
+
*
|
|
4
|
+
* `touch-action: none` tells the BROWSER not to scroll or zoom on a touch. It says nothing to the app the page is
|
|
5
|
+
* shown in. In a sheet (the browser ChatGPT and other apps open a link in, on iOS), a downward drag on the canvas
|
|
6
|
+
* moved the design for a moment and was then taken by the sheet as "pull down to close": the page got
|
|
7
|
+
* `pointercancel` and the sheet slid away (Kevin, ChatGPT on iOS, 2026-11-18).
|
|
8
|
+
*
|
|
9
|
+
* What the app does listen to is a touch the page has claimed: a `touchmove` whose default is prevented, on an
|
|
10
|
+
* element that also has a non-passive `touchstart` listener (so the system waits for the page before starting a
|
|
11
|
+
* gesture of its own). `touchstart` itself is left alone: preventing it would take away the tap and double-tap the
|
|
12
|
+
* canvas uses.
|
|
13
|
+
*
|
|
14
|
+
* Returns the function that removes the listeners.
|
|
15
|
+
*/
|
|
16
|
+
export declare function claimTouch(element: HTMLElement): () => void;
|