@varianta/sdk 0.1.1 → 0.1.3
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/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +86 -63
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +3 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/types/types/index.d.ts +3 -3
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/vanilla/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { forwardRef as
|
|
1
|
+
import { jsx as $ } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as Z, useRef as k, useEffect as L, useImperativeHandle as q, useState as S, useCallback as M } from "react";
|
|
3
3
|
class B {
|
|
4
4
|
constructor(e) {
|
|
5
5
|
this.animationFrameId = null, this.needsRender = !0, this.areas = [], this.contents = /* @__PURE__ */ new Map(), this.artboard = null, this.bgImageElement = null, this.loadedImages = /* @__PURE__ */ new Map(), this.loadingImages = /* @__PURE__ */ new Set(), this.zoom = 1, this.pan = { x: 0, y: 0 }, this.selectedAreaId = null, this.hoveredHandle = null, this.eventListeners = /* @__PURE__ */ new Map(), this.safeArea = null, this.safeAreaViolations = /* @__PURE__ */ new Set(), this.showAreaBorders = !0, this.areaSelectionEnabled = !0, this.renderLoop = () => {
|
|
@@ -198,24 +198,24 @@ class B {
|
|
|
198
198
|
return null;
|
|
199
199
|
const { location: n } = t, { x: r, y: s, width: a, height: o } = n;
|
|
200
200
|
if (i.type === "text") {
|
|
201
|
-
const d = i.offset || { x: 0, y: 0 }, l = i.scale ?? 1, h = i.rotation ?? 0, u = a * l, g = o * l, m = r + a / 2 + d.x,
|
|
201
|
+
const d = i.offset || { x: 0, y: 0 }, l = i.scale ?? 1, h = i.rotation ?? 0, u = a * l, g = o * l, m = r + a / 2 + d.x, f = s + o / 2 + d.y;
|
|
202
202
|
return {
|
|
203
203
|
x: m - u / 2,
|
|
204
|
-
y:
|
|
204
|
+
y: f - g / 2,
|
|
205
205
|
width: u,
|
|
206
206
|
height: g,
|
|
207
207
|
rotation: h,
|
|
208
208
|
centerX: m,
|
|
209
|
-
centerY:
|
|
209
|
+
centerY: f
|
|
210
210
|
};
|
|
211
211
|
} else if (i.type === "image") {
|
|
212
212
|
const d = this.loadedImages.get(e);
|
|
213
213
|
if (!d)
|
|
214
214
|
return null;
|
|
215
215
|
const l = i.offset || { x: 0, y: 0 }, h = i.scale ?? 1, u = i.rotation ?? 0, g = d.naturalWidth / d.naturalHeight, m = a / o;
|
|
216
|
-
let
|
|
217
|
-
g > m ? (
|
|
218
|
-
const v =
|
|
216
|
+
let f, y;
|
|
217
|
+
g > m ? (f = a, y = a / g) : (y = o, f = o * g);
|
|
218
|
+
const v = f * h, w = y * h, p = r + a / 2 + l.x, C = s + o / 2 + l.y;
|
|
219
219
|
return {
|
|
220
220
|
x: p - v / 2,
|
|
221
221
|
y: C - w / 2,
|
|
@@ -260,8 +260,8 @@ class B {
|
|
|
260
260
|
* Test if a point is inside rotated bounds
|
|
261
261
|
*/
|
|
262
262
|
isPointInBounds(e, t, i) {
|
|
263
|
-
const { centerX: n, centerY: r, width: s, height: a, rotation: o } = i, d = -o * Math.PI / 180, l = Math.cos(d), h = Math.sin(d), u = e - n, g = t - r, m = u * l - g * h,
|
|
264
|
-
return m >= -s / 2 && m <= s / 2 &&
|
|
263
|
+
const { centerX: n, centerY: r, width: s, height: a, rotation: o } = i, d = -o * Math.PI / 180, l = Math.cos(d), h = Math.sin(d), u = e - n, g = t - r, m = u * l - g * h, f = u * h + g * l;
|
|
264
|
+
return m >= -s / 2 && m <= s / 2 && f >= -a / 2 && f <= a / 2;
|
|
265
265
|
}
|
|
266
266
|
/**
|
|
267
267
|
* Get handle positions for the selected content
|
|
@@ -276,22 +276,22 @@ class B {
|
|
|
276
276
|
const n = this.getContentBounds(e);
|
|
277
277
|
if (!n)
|
|
278
278
|
return null;
|
|
279
|
-
const { centerX: r, centerY: s, width: a, height: o, rotation: d } = n, l = 6 / this.zoom, h = 30 / this.zoom, u = d * Math.PI / 180, g = Math.cos(u), m = Math.sin(u),
|
|
279
|
+
const { centerX: r, centerY: s, width: a, height: o, rotation: d } = n, l = 6 / this.zoom, h = 30 / this.zoom, u = d * Math.PI / 180, g = Math.cos(u), m = Math.sin(u), f = (v, w) => ({
|
|
280
280
|
x: r + v * g - w * m,
|
|
281
281
|
y: s + v * m + w * g
|
|
282
282
|
}), y = [];
|
|
283
283
|
if (i.type === "image" && t.imageOptions?.allowScaling || i.type === "text" && t.textOptions?.allowScaling) {
|
|
284
|
-
const v = a / 2, w = o / 2, p =
|
|
284
|
+
const v = a / 2, w = o / 2, p = f(-v, -w);
|
|
285
285
|
y.push({ type: "nw", ...p, radius: l });
|
|
286
|
-
const C =
|
|
286
|
+
const C = f(v, -w);
|
|
287
287
|
y.push({ type: "ne", ...C, radius: l });
|
|
288
|
-
const I =
|
|
288
|
+
const I = f(v, w);
|
|
289
289
|
y.push({ type: "se", ...I, radius: l });
|
|
290
|
-
const x =
|
|
290
|
+
const x = f(-v, w);
|
|
291
291
|
y.push({ type: "sw", ...x, radius: l });
|
|
292
292
|
}
|
|
293
293
|
if (i.type === "image" && t.imageOptions?.allowRotation || i.type === "text" && t.textOptions?.allowRotation) {
|
|
294
|
-
const v =
|
|
294
|
+
const v = f(0, -o / 2 - h);
|
|
295
295
|
y.push({ type: "rotate", ...v, radius: l });
|
|
296
296
|
}
|
|
297
297
|
return y;
|
|
@@ -353,7 +353,7 @@ class B {
|
|
|
353
353
|
const h = this.getContentBounds(l.id);
|
|
354
354
|
if (!h)
|
|
355
355
|
continue;
|
|
356
|
-
const { centerX: u, centerY: g, width: m, height:
|
|
356
|
+
const { centerX: u, centerY: g, width: m, height: f, rotation: y } = h, v = y * Math.PI / 180, w = Math.abs(Math.cos(v)), p = Math.abs(Math.sin(v)), C = m * w + f * p, I = m * p + f * w, x = u - C / 2, R = g - I / 2, D = u + C / 2, U = g + I / 2;
|
|
357
357
|
(x < s || R < a || D > o || U > d) && e.push(l.id);
|
|
358
358
|
}
|
|
359
359
|
return this.safeAreaViolations = new Set(e), this.requestRender(), e;
|
|
@@ -447,8 +447,8 @@ class B {
|
|
|
447
447
|
const l = this.areas.find((y) => y.id === e);
|
|
448
448
|
if (!l)
|
|
449
449
|
return;
|
|
450
|
-
const { ctx: h } = this, { x: u, y: g, width: m, height:
|
|
451
|
-
h.save(), h.strokeStyle = "#3b82f6", h.lineWidth = 2 / this.zoom, h.setLineDash([]), h.strokeRect(u, g, m,
|
|
450
|
+
const { ctx: h } = this, { x: u, y: g, width: m, height: f } = l.location;
|
|
451
|
+
h.save(), h.strokeStyle = "#3b82f6", h.lineWidth = 2 / this.zoom, h.setLineDash([]), h.strokeRect(u, g, m, f), h.restore();
|
|
452
452
|
return;
|
|
453
453
|
}
|
|
454
454
|
const { ctx: i } = this, { centerX: n, centerY: r, width: s, height: a, rotation: o } = t;
|
|
@@ -539,9 +539,9 @@ class B {
|
|
|
539
539
|
const { ctx: n } = this, { location: r } = e, { x: s, y: a, width: o, height: d } = r, l = t.offset || { x: 0, y: 0 }, h = t.scale ?? 1, u = t.rotation ?? 0;
|
|
540
540
|
n.save(), n.beginPath(), n.rect(s, a, o, d), n.clip();
|
|
541
541
|
const g = i.naturalWidth / i.naturalHeight, m = o / d;
|
|
542
|
-
let
|
|
543
|
-
g > m ? (
|
|
544
|
-
const v =
|
|
542
|
+
let f, y;
|
|
543
|
+
g > m ? (f = o, y = o / g) : (y = d, f = d * g);
|
|
544
|
+
const v = f * h, w = y * h, p = s + o / 2 + l.x, C = a + d / 2 + l.y;
|
|
545
545
|
n.translate(p, C), n.rotate(u * Math.PI / 180), n.drawImage(i, -v / 2, -w / 2, v, w), n.restore();
|
|
546
546
|
}
|
|
547
547
|
/**
|
|
@@ -569,29 +569,29 @@ class B {
|
|
|
569
569
|
return;
|
|
570
570
|
const l = d.offset || { x: 0, y: 0 }, h = d.scale ?? 1, u = d.rotation ?? 0, g = r + a / 2 + l.x, m = s + o / 2 + l.y;
|
|
571
571
|
e.save(), e.beginPath(), e.rect(r, s, a, o), e.clip(), e.translate(g, m), e.rotate(u * Math.PI / 180), e.scale(h, h), e.font = `${d.size}px ${d.font}, sans-serif`, e.fillStyle = d.color, e.textBaseline = "middle";
|
|
572
|
-
let
|
|
572
|
+
let f;
|
|
573
573
|
switch (d.align) {
|
|
574
574
|
case "left":
|
|
575
|
-
e.textAlign = "left",
|
|
575
|
+
e.textAlign = "left", f = -a / 2 + 10;
|
|
576
576
|
break;
|
|
577
577
|
case "right":
|
|
578
|
-
e.textAlign = "right",
|
|
578
|
+
e.textAlign = "right", f = a / 2 - 10;
|
|
579
579
|
break;
|
|
580
580
|
case "center":
|
|
581
581
|
default:
|
|
582
|
-
e.textAlign = "center",
|
|
582
|
+
e.textAlign = "center", f = 0;
|
|
583
583
|
break;
|
|
584
584
|
}
|
|
585
|
-
e.fillText(d.text,
|
|
585
|
+
e.fillText(d.text, f, 0), e.restore();
|
|
586
586
|
} else if (d.type === "image") {
|
|
587
587
|
const l = this.loadedImages.get(t.id);
|
|
588
588
|
if (!l)
|
|
589
589
|
return;
|
|
590
590
|
const h = d.offset || { x: 0, y: 0 }, u = d.scale ?? 1, g = d.rotation ?? 0;
|
|
591
591
|
e.save(), e.beginPath(), e.rect(r, s, a, o), e.clip();
|
|
592
|
-
const m = l.naturalWidth / l.naturalHeight,
|
|
592
|
+
const m = l.naturalWidth / l.naturalHeight, f = a / o;
|
|
593
593
|
let y, v;
|
|
594
|
-
m >
|
|
594
|
+
m > f ? (y = a, v = a / m) : (v = o, y = o * m);
|
|
595
595
|
const w = y * u, p = v * u, C = r + a / 2 + h.x, I = s + o / 2 + h.y;
|
|
596
596
|
e.translate(C, I), e.rotate(g * Math.PI / 180), e.drawImage(l, -w / 2, -p / 2, w, p), e.restore();
|
|
597
597
|
}
|
|
@@ -604,8 +604,8 @@ class B {
|
|
|
604
604
|
this.stop(), this.bgImageElement = null, this.loadedImages.clear(), this.loadingImages.clear(), this.eventListeners.clear();
|
|
605
605
|
}
|
|
606
606
|
}
|
|
607
|
-
function P(
|
|
608
|
-
const e =
|
|
607
|
+
function P(b) {
|
|
608
|
+
const e = b.textOptions;
|
|
609
609
|
return {
|
|
610
610
|
type: "text",
|
|
611
611
|
text: e?.defaultText || "",
|
|
@@ -615,11 +615,11 @@ function P(f) {
|
|
|
615
615
|
align: e?.defaultAlign || "center"
|
|
616
616
|
};
|
|
617
617
|
}
|
|
618
|
-
function A(
|
|
619
|
-
return
|
|
618
|
+
function A(b) {
|
|
619
|
+
return b.contentType === "text" || b.contentType === "both";
|
|
620
620
|
}
|
|
621
|
-
function O(
|
|
622
|
-
return
|
|
621
|
+
function O(b) {
|
|
622
|
+
return b.contentType === "image" || b.contentType === "both";
|
|
623
623
|
}
|
|
624
624
|
const Y = 50;
|
|
625
625
|
class j {
|
|
@@ -1157,23 +1157,23 @@ class J {
|
|
|
1157
1157
|
}
|
|
1158
1158
|
}
|
|
1159
1159
|
}
|
|
1160
|
-
function c(
|
|
1161
|
-
const i = document.createElement(
|
|
1160
|
+
function c(b, e, ...t) {
|
|
1161
|
+
const i = document.createElement(b);
|
|
1162
1162
|
return e && Object.entries(e).forEach(([n, r]) => {
|
|
1163
1163
|
n === "class" ? i.className = r : n in i ? i[n] = r : i.setAttribute(n, String(r));
|
|
1164
1164
|
}), t.forEach((n) => {
|
|
1165
1165
|
typeof n == "string" ? i.appendChild(document.createTextNode(n)) : i.appendChild(n);
|
|
1166
1166
|
}), i;
|
|
1167
1167
|
}
|
|
1168
|
-
function V(
|
|
1168
|
+
function V(b, e) {
|
|
1169
1169
|
let t = null, i = null;
|
|
1170
1170
|
const n = (...r) => {
|
|
1171
1171
|
i = r, t && clearTimeout(t), t = setTimeout(() => {
|
|
1172
|
-
i &&
|
|
1172
|
+
i && b(...i), t = null, i = null;
|
|
1173
1173
|
}, e);
|
|
1174
1174
|
};
|
|
1175
1175
|
return n.flush = () => {
|
|
1176
|
-
t && (clearTimeout(t), t = null), i && (
|
|
1176
|
+
t && (clearTimeout(t), t = null), i && (b(...i), i = null);
|
|
1177
1177
|
}, n.cancel = () => {
|
|
1178
1178
|
t && (clearTimeout(t), t = null), i = null;
|
|
1179
1179
|
}, n;
|
|
@@ -1510,16 +1510,16 @@ function re() {
|
|
|
1510
1510
|
function ae() {
|
|
1511
1511
|
return re() ? "meta" : "ctrl";
|
|
1512
1512
|
}
|
|
1513
|
-
function se(
|
|
1514
|
-
const n =
|
|
1513
|
+
function se(b, e, t, i) {
|
|
1514
|
+
const n = b / t, r = e / i;
|
|
1515
1515
|
return Math.min(n, r);
|
|
1516
1516
|
}
|
|
1517
|
-
function oe(
|
|
1518
|
-
const r = se(
|
|
1517
|
+
function oe(b, e, t = 8, i = 10, n = 300) {
|
|
1518
|
+
const r = se(b, e, t, i), s = r >= n;
|
|
1519
1519
|
return {
|
|
1520
1520
|
actualDPI: Math.round(r),
|
|
1521
1521
|
targetDPI: n,
|
|
1522
|
-
width:
|
|
1522
|
+
width: b,
|
|
1523
1523
|
height: e,
|
|
1524
1524
|
passed: s,
|
|
1525
1525
|
warning: s ? void 0 : `Image resolution is ${Math.round(r)} DPI at 100% scale. For best print quality, use images with at least ${n} DPI. This may result in pixelated or blurry prints.`
|
|
@@ -1945,11 +1945,11 @@ class he extends HTMLElement {
|
|
|
1945
1945
|
}
|
|
1946
1946
|
}
|
|
1947
1947
|
customElements.get("customizer-editor") || customElements.define("customizer-editor", he);
|
|
1948
|
-
function ce(
|
|
1949
|
-
const t = typeof
|
|
1948
|
+
function ce(b, e) {
|
|
1949
|
+
const t = typeof b == "string" ? document.querySelector(b) : b;
|
|
1950
1950
|
if (!t)
|
|
1951
1951
|
throw new Error(
|
|
1952
|
-
`Container not found: ${typeof
|
|
1952
|
+
`Container not found: ${typeof b == "string" ? b : "provided element is null"}`
|
|
1953
1953
|
);
|
|
1954
1954
|
const i = document.createElement("customizer-editor");
|
|
1955
1955
|
i.setAttribute("template-id", e.templateId), e.theme && i.setAttribute("theme", e.theme), e.mode && i.setAttribute("mode", e.mode), e.className && i.classList.add(e.className), i.style.width = "100%", i.style.height = "100%";
|
|
@@ -1994,17 +1994,40 @@ function ce(f, e) {
|
|
|
1994
1994
|
},
|
|
1995
1995
|
body: JSON.stringify({
|
|
1996
1996
|
templateId: e.templateId,
|
|
1997
|
-
|
|
1997
|
+
designJson: a
|
|
1998
1998
|
})
|
|
1999
1999
|
});
|
|
2000
2000
|
if (!d.ok) {
|
|
2001
|
-
const
|
|
2001
|
+
const f = await d.json().catch(() => ({
|
|
2002
2002
|
message: "Finalization failed"
|
|
2003
2003
|
}));
|
|
2004
|
-
throw new Error(
|
|
2004
|
+
throw new Error(f.message || "Finalization failed");
|
|
2005
2005
|
}
|
|
2006
2006
|
const l = await d.json();
|
|
2007
|
-
|
|
2007
|
+
let h = {
|
|
2008
|
+
designId: l.designId,
|
|
2009
|
+
status: l.status,
|
|
2010
|
+
proofUrl: l.proofUrl ?? null,
|
|
2011
|
+
errorMessage: l.errorMessage ?? null
|
|
2012
|
+
};
|
|
2013
|
+
const u = 1500, g = 40;
|
|
2014
|
+
let m = 0;
|
|
2015
|
+
for (; h.status === "processing" && m < g; ) {
|
|
2016
|
+
await new Promise((v) => setTimeout(v, u)), m++;
|
|
2017
|
+
const f = await fetch(
|
|
2018
|
+
`${o}/public/designs/${h.designId}/status`
|
|
2019
|
+
);
|
|
2020
|
+
if (!f.ok)
|
|
2021
|
+
throw new Error("Failed to check design status");
|
|
2022
|
+
const y = await f.json();
|
|
2023
|
+
h = {
|
|
2024
|
+
designId: y.designId,
|
|
2025
|
+
status: y.status,
|
|
2026
|
+
proofUrl: y.proofUrl ?? null,
|
|
2027
|
+
errorMessage: y.errorMessage ?? null
|
|
2028
|
+
};
|
|
2029
|
+
}
|
|
2030
|
+
return h.status === "processing" && (h = { ...h, status: "failed", errorMessage: "Render timed out" }), e.onFinalize && e.onFinalize(h), h;
|
|
2008
2031
|
} catch (d) {
|
|
2009
2032
|
const l = {
|
|
2010
2033
|
code: "FINALIZE_ERROR",
|
|
@@ -2076,8 +2099,8 @@ function ce(f, e) {
|
|
|
2076
2099
|
{ once: !0 }
|
|
2077
2100
|
), e.debug && (console.log("[Customizer SDK] Initialized with options:", e), console.log("[Customizer SDK] Instance:", s)), s;
|
|
2078
2101
|
}
|
|
2079
|
-
const ue =
|
|
2080
|
-
(
|
|
2102
|
+
const ue = Z(
|
|
2103
|
+
(b, e) => {
|
|
2081
2104
|
const {
|
|
2082
2105
|
templateId: t,
|
|
2083
2106
|
apiUrl: i,
|
|
@@ -2092,16 +2115,16 @@ const ue = $(
|
|
|
2092
2115
|
onLayerSelect: u,
|
|
2093
2116
|
onLayerAdd: g,
|
|
2094
2117
|
onLayerRemove: m,
|
|
2095
|
-
onLayerUpdate:
|
|
2118
|
+
onLayerUpdate: f,
|
|
2096
2119
|
onError: y,
|
|
2097
2120
|
onFinalize: v
|
|
2098
|
-
} =
|
|
2121
|
+
} = b, w = k(null), p = k(null), C = k({
|
|
2099
2122
|
onReady: l,
|
|
2100
2123
|
onChange: h,
|
|
2101
2124
|
onLayerSelect: u,
|
|
2102
2125
|
onLayerAdd: g,
|
|
2103
2126
|
onLayerRemove: m,
|
|
2104
|
-
onLayerUpdate:
|
|
2127
|
+
onLayerUpdate: f,
|
|
2105
2128
|
onError: y,
|
|
2106
2129
|
onFinalize: v
|
|
2107
2130
|
});
|
|
@@ -2112,11 +2135,11 @@ const ue = $(
|
|
|
2112
2135
|
onLayerSelect: u,
|
|
2113
2136
|
onLayerAdd: g,
|
|
2114
2137
|
onLayerRemove: m,
|
|
2115
|
-
onLayerUpdate:
|
|
2138
|
+
onLayerUpdate: f,
|
|
2116
2139
|
onError: y,
|
|
2117
2140
|
onFinalize: v
|
|
2118
2141
|
};
|
|
2119
|
-
}, [l, h, u, g, m,
|
|
2142
|
+
}, [l, h, u, g, m, f, y, v]), L(() => {
|
|
2120
2143
|
if (!w.current) return;
|
|
2121
2144
|
const I = {
|
|
2122
2145
|
templateId: t,
|
|
@@ -2224,7 +2247,7 @@ const ue = $(
|
|
|
2224
2247
|
}),
|
|
2225
2248
|
[]
|
|
2226
2249
|
// Empty deps is OK - we always read from instanceRef.current
|
|
2227
|
-
), /* @__PURE__ */
|
|
2250
|
+
), /* @__PURE__ */ $(
|
|
2228
2251
|
"div",
|
|
2229
2252
|
{
|
|
2230
2253
|
ref: w,
|
|
@@ -2239,12 +2262,12 @@ const ue = $(
|
|
|
2239
2262
|
}
|
|
2240
2263
|
);
|
|
2241
2264
|
ue.displayName = "Customizer";
|
|
2242
|
-
function me(
|
|
2265
|
+
function me(b = {}) {
|
|
2243
2266
|
const {
|
|
2244
2267
|
autoSave: e = !1,
|
|
2245
2268
|
autoSaveKey: t = "customizer-design",
|
|
2246
2269
|
autoSaveDebounce: i = 1e3
|
|
2247
|
-
} =
|
|
2270
|
+
} = b, n = k(null), [r, s] = S(null), [a, o] = S(!1), [d, l] = S(!1), [h, u] = S(null), [g, m] = S(!1), [f, y] = S(
|
|
2248
2271
|
null
|
|
2249
2272
|
), v = k(void 0);
|
|
2250
2273
|
L(() => {
|
|
@@ -2334,7 +2357,7 @@ function me(f = {}) {
|
|
|
2334
2357
|
canRedo: d,
|
|
2335
2358
|
selectedLayerId: h,
|
|
2336
2359
|
isFinalizing: g,
|
|
2337
|
-
finalizeResult:
|
|
2360
|
+
finalizeResult: f,
|
|
2338
2361
|
getDesign: w,
|
|
2339
2362
|
setDesign: p,
|
|
2340
2363
|
undo: C,
|