@snowcone-app/canvas 0.27.0 → 0.29.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/ERROR_CONTRACT.md +13 -0
- package/dist/{CanvasRenderer-yszzrDfo.js → CanvasRenderer-_lFoIoz5.js} +916 -848
- package/dist/CanvasRenderer-_lFoIoz5.js.map +1 -0
- package/dist/{CanvasStateV1-BTbCD_xC.js → CanvasStateV1-BMxr6xb8.js} +7 -4
- package/dist/{CanvasStateV1-BTbCD_xC.js.map → CanvasStateV1-BMxr6xb8.js.map} +1 -1
- package/dist/ContextualToolbars-0jWvnQgp.js +5833 -0
- package/dist/ContextualToolbars-0jWvnQgp.js.map +1 -0
- package/dist/{EditorCanvasImpl-Ui8Ceb-h.js → EditorCanvasImpl-BNz8TPFs.js} +8 -8
- package/dist/{EditorCanvasImpl-Ui8Ceb-h.js.map → EditorCanvasImpl-BNz8TPFs.js.map} +1 -1
- package/dist/{ExportManager-BTcyj4cf.js → ExportManager-B8Td7uR5.js} +1051 -976
- package/dist/ExportManager-B8Td7uR5.js.map +1 -0
- package/dist/{FontAnalyzer-EF3gLPr8.js → FontAnalyzer-D4Sg-P6_.js} +1410 -1329
- package/dist/FontAnalyzer-D4Sg-P6_.js.map +1 -0
- package/dist/{ImagePanel-CIk6z41z.js → ImagePanel-CN2Bu3hf.js} +6 -6
- package/dist/{ImagePanel-CIk6z41z.js.map → ImagePanel-CN2Bu3hf.js.map} +1 -1
- package/dist/{SnowconeCanvas-DuWALOAt.js → SnowconeCanvas-CR_LdRFP.js} +27 -27
- package/dist/{SnowconeCanvas-DuWALOAt.js.map → SnowconeCanvas-CR_LdRFP.js.map} +1 -1
- package/dist/{UnifiedFontService-CHVYDBDW.js → UnifiedFontService-CgYnYTj7.js} +755 -713
- package/dist/UnifiedFontService-CgYnYTj7.js.map +1 -0
- package/dist/advanced.mjs +14 -14
- package/dist/components/MultiSelectionToolbar.d.ts +18 -0
- package/dist/components/toolbars/SecondaryPanels.d.ts +11 -0
- package/dist/components/ui/toolbar-button.d.ts +2 -0
- package/dist/core/GestureConstraints.d.ts +92 -0
- package/dist/core/InteractionStateMachine.d.ts +16 -2
- package/dist/core/ResizeHandler.d.ts +4 -1
- package/dist/core/ResizePipeline.d.ts +3 -0
- package/dist/core/TextElement.d.ts +13 -0
- package/dist/core/TextMetrics.d.ts +17 -3
- package/dist/core/rich-text-layout.d.ts +2 -0
- package/dist/core/text-spacing.d.ts +74 -0
- package/dist/{custom-icons-CcLMyybv.js → custom-icons-B5TRC1Ed.js} +2 -2
- package/dist/{custom-icons-CcLMyybv.js.map → custom-icons-B5TRC1Ed.js.map} +1 -1
- package/dist/{design-builder-cZY958Rw.js → design-builder-COj0zkxu.js} +2 -2
- package/dist/{design-builder-cZY958Rw.js.map → design-builder-COj0zkxu.js.map} +1 -1
- package/dist/{editorErrors-BhrZ_nwj.js → editorErrors-CCvoKj_P.js} +2 -2
- package/dist/editorErrors-CCvoKj_P.js.map +1 -0
- package/dist/{embed-CJswRZte.js → embed-BTRtoktw.js} +10 -10
- package/dist/{embed-CJswRZte.js.map → embed-BTRtoktw.js.map} +1 -1
- package/dist/embed.mjs +6 -6
- package/dist/errors/editorError.d.ts +7 -1
- package/dist/{guards-DIX8aXWM.js → guards-uQtEQJbs.js} +2 -2
- package/dist/{guards-DIX8aXWM.js.map → guards-uQtEQJbs.js.map} +1 -1
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useAlignDistribute.d.ts +19 -0
- package/dist/hooks/useTextToolbar.d.ts +8 -0
- package/dist/index.mjs +8 -8
- package/dist/internals.mjs +5 -5
- package/dist/rendering/renderer-types.d.ts +4 -0
- package/dist/rendering/rich-text-renderer.d.ts +4 -0
- package/dist/rendering/text-renderer.d.ts +4 -1
- package/dist/state/CanvasStateV1.d.ts +3 -0
- package/dist/{template-fields-BXl29sgh.js → template-fields-BLRp84Ny.js} +6 -6
- package/dist/{template-fields-BXl29sgh.js.map → template-fields-BLRp84Ny.js.map} +1 -1
- package/dist/testing.mjs +4 -4
- package/dist/types/index.d.ts +26 -0
- package/dist/{usePieceGuideBundle-DE21DQGZ.js → usePieceGuideBundle-CTQszfKA.js} +2 -2
- package/dist/{usePieceGuideBundle-DE21DQGZ.js.map → usePieceGuideBundle-CTQszfKA.js.map} +1 -1
- package/dist/utils/alignDistribute.d.ts +41 -0
- package/dist/utils/featureApplied.d.ts +6 -0
- package/dist/{validation-DGXAQmUC.js → validation-eCebhplp.js} +2991 -2956
- package/dist/validation-eCebhplp.js.map +1 -0
- package/dist/workers/export-worker.bundle.string.d.ts +1 -1
- package/example/package.json +1 -1
- package/package.json +1 -1
- package/dist/CanvasRenderer-yszzrDfo.js.map +0 -1
- package/dist/ContextualToolbars-BHjYsril.js +0 -5556
- package/dist/ContextualToolbars-BHjYsril.js.map +0 -1
- package/dist/ExportManager-BTcyj4cf.js.map +0 -1
- package/dist/FontAnalyzer-EF3gLPr8.js.map +0 -1
- package/dist/UnifiedFontService-CHVYDBDW.js.map +0 -1
- package/dist/editorErrors-BhrZ_nwj.js.map +0 -1
- package/dist/validation-DGXAQmUC.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { X as
|
|
2
|
-
import { T as
|
|
3
|
-
import { i as
|
|
4
|
-
const
|
|
1
|
+
import { X as oe, Y as ie, au as nt, Z as Ft, aH as ae, aF as re, ay as Ot, aE as le, ax as gt, aI as he, aJ as Yt, aK as ce, aL as de, c as Zt, aM as fe, aN as ge, aO as ue, aP as pe, a4 as Jt, a0 as Qt, a8 as pt, a1 as te, a2 as Lt, a9 as Gt, a7 as Pt, aa as Xt, a5 as ye, ab as be, aQ as Nt, aR as Se, aS as me, aT as Te, I as we, aU as ve, aV as Me, aW as tt } from "./FontAnalyzer-D4Sg-P6_.js";
|
|
2
|
+
import { T as Wt, a as xe, u as Ce, K as Re, z as At, L as Kt, M as ke, N as Pe, O as Ae } from "./ExportManager-B8Td7uR5.js";
|
|
3
|
+
import { i as Dt, a as Ee } from "./guards-uQtEQJbs.js";
|
|
4
|
+
const ct = {
|
|
5
5
|
// Canvas-specific
|
|
6
6
|
canvas: {
|
|
7
7
|
snapThreshold: 8,
|
|
@@ -15,30 +15,30 @@ const it = {
|
|
|
15
15
|
spacingLabelFontSize: 11,
|
|
16
16
|
spacingLabelFontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
|
|
17
17
|
}
|
|
18
|
-
},
|
|
19
|
-
function
|
|
20
|
-
return
|
|
18
|
+
}, He = 2, Rt = 6, Ie = 16, Be = 5, Le = 5, ee = 0.5;
|
|
19
|
+
function $t(v) {
|
|
20
|
+
return He / v;
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
return
|
|
22
|
+
function qe(v) {
|
|
23
|
+
return Rt / v;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
return
|
|
25
|
+
function We(v) {
|
|
26
|
+
return Ie / v;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
return [
|
|
28
|
+
function Ue(v) {
|
|
29
|
+
return [Be / v, Le / v];
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
const n =
|
|
34
|
-
|
|
31
|
+
function De(v, t, e, o) {
|
|
32
|
+
v.save();
|
|
33
|
+
const n = ee / o;
|
|
34
|
+
v.translate(t, e), v.scale(n, n), v.strokeStyle = "#000", v.lineWidth = 1.5, v.lineCap = "round", v.lineJoin = "round", v.translate(-12, -12), v.beginPath(), v.moveTo(21, 12), v.arc(12, 12, 9, 0, -Math.PI / 2, !0), v.bezierCurveTo(3.5, 4.5, 4, 6, 3, 8), v.stroke(), v.beginPath(), v.moveTo(3, 3), v.lineTo(3, 8), v.lineTo(8, 8), v.stroke(), v.beginPath(), v.moveTo(3, 12), v.arc(12, 12, 9, Math.PI, Math.PI / 2, !0), v.bezierCurveTo(20.5, 19.5, 20, 18, 21, 16), v.stroke(), v.beginPath(), v.moveTo(16, 16), v.lineTo(21, 16), v.lineTo(21, 21), v.stroke(), v.restore();
|
|
35
35
|
}
|
|
36
|
-
function
|
|
37
|
-
const i =
|
|
38
|
-
|
|
36
|
+
function Ze(v, t, e, o = 1, n = "#3b82f6", s = !1) {
|
|
37
|
+
const i = We(o);
|
|
38
|
+
v.save(), v.fillStyle = "#fff", v.strokeStyle = n, v.lineWidth = s ? $t(o) * 1.25 : $t(o), v.beginPath(), v.arc(t, e, i, 0, Math.PI * 2), v.fill(), v.stroke(), De(v, t, e, o), v.restore();
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
class
|
|
40
|
+
const jt = Rt * 2;
|
|
41
|
+
class Je {
|
|
42
42
|
constructor() {
|
|
43
43
|
this.resizeHandles = [], this.rotationHandle = null, this.elementRotation = 0, this.rotationAnchor = { x: 0, y: 0 };
|
|
44
44
|
}
|
|
@@ -50,13 +50,13 @@ class Ge {
|
|
|
50
50
|
update(t, e = 1) {
|
|
51
51
|
const n = "isCropping" in t && t.isCropping ? t.getBoundingBox() : t.getVisualBoundingBox(), s = t.getRotationAnchor(), i = t.getEnabledAnchors();
|
|
52
52
|
this.elementRotation = t.rotation, this.rotationAnchor = s;
|
|
53
|
-
const a =
|
|
53
|
+
const a = ct.canvas.selectionPadding, r = {
|
|
54
54
|
x: n.x - a,
|
|
55
55
|
y: n.y - a,
|
|
56
56
|
width: n.width + a * 2,
|
|
57
57
|
height: n.height + a * 2
|
|
58
|
-
}, l =
|
|
59
|
-
this.resizeHandles = l.filter((c) => !(!i.includes(c.anchor) || h && c.anchor.includes("middle"))), this.rotationHandle =
|
|
58
|
+
}, l = oe(r, t.rotation, s), h = Math.abs(t.rotation % 360) > 0.1;
|
|
59
|
+
this.resizeHandles = l.filter((c) => !(!i.includes(c.anchor) || h && c.anchor.includes("middle"))), this.rotationHandle = ie(
|
|
60
60
|
r,
|
|
61
61
|
t.rotation,
|
|
62
62
|
s,
|
|
@@ -71,8 +71,8 @@ class Ge {
|
|
|
71
71
|
this.resizeHandles.forEach((c) => {
|
|
72
72
|
if (a && r && c.anchor !== r.anchor)
|
|
73
73
|
return;
|
|
74
|
-
const d = !!(i && i.anchor === c.anchor),
|
|
75
|
-
this.renderResizeHandle(t, c, d,
|
|
74
|
+
const d = !!(i && i.anchor === c.anchor), f = !!(a && r && r.anchor === c.anchor);
|
|
75
|
+
this.renderResizeHandle(t, c, d, f, l);
|
|
76
76
|
}), h && e && this.rotationHandle && !n && !a && this.renderRotationHandle(t, this.rotationHandle, s, l), h && e && this.rotationHandle && n && this.renderRotationTooltip(t, this.rotationHandle, o, l);
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
@@ -85,10 +85,10 @@ class Ge {
|
|
|
85
85
|
if (e.anchor.includes("middle")) {
|
|
86
86
|
const l = e.anchor === "middle-top" || e.anchor === "middle-bottom";
|
|
87
87
|
t.translate(i, a), t.rotate(-this.elementRotation * Math.PI / 180), l && t.rotate(Math.PI / 2), t.translate(-i, -a);
|
|
88
|
-
const h =
|
|
89
|
-
t.fillStyle = "#fff", t.strokeStyle =
|
|
88
|
+
const h = jt * 0.6, c = jt * 1.4, d = h / 2, f = i - h / 2, b = a - c / 2;
|
|
89
|
+
t.fillStyle = "#fff", t.strokeStyle = nt(t.canvas), t.lineWidth = o || n ? 2.5 : 2, t.beginPath(), t.roundRect(f, b, h, c, d), t.fill(), t.stroke();
|
|
90
90
|
} else
|
|
91
|
-
t.fillStyle = "#fff", t.strokeStyle =
|
|
91
|
+
t.fillStyle = "#fff", t.strokeStyle = nt(t.canvas), t.lineWidth = o || n ? 2.5 : 2, t.beginPath(), t.arc(i, a, Rt, 0, Math.PI * 2), t.fill(), t.stroke();
|
|
92
92
|
t.restore();
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
@@ -97,9 +97,9 @@ class Ge {
|
|
|
97
97
|
*/
|
|
98
98
|
renderRotationHandle(t, e, o = !1, n = 1) {
|
|
99
99
|
t.save();
|
|
100
|
-
const s = e.x * n, i = e.y * n, a =
|
|
101
|
-
t.fillStyle = "#fff", t.strokeStyle =
|
|
102
|
-
const r =
|
|
100
|
+
const s = e.x * n, i = e.y * n, a = Rt * 2.67;
|
|
101
|
+
t.fillStyle = "#fff", t.strokeStyle = nt(t.canvas), t.lineWidth = o ? 2.5 : 2, t.beginPath(), t.arc(s, i, a, 0, Math.PI * 2), t.fill(), t.stroke();
|
|
102
|
+
const r = ee;
|
|
103
103
|
t.translate(s, i), t.scale(r, r), t.strokeStyle = "#000", t.lineWidth = 1.5, t.lineCap = "round", t.lineJoin = "round", t.translate(-12, -12), t.beginPath(), t.moveTo(21, 12), t.arc(12, 12, 9, 0, -Math.PI / 2, !0), t.bezierCurveTo(3.5, 4.5, 4, 6, 3, 8), t.stroke(), t.beginPath(), t.moveTo(3, 3), t.lineTo(3, 8), t.lineTo(8, 8), t.stroke(), t.beginPath(), t.moveTo(3, 12), t.arc(12, 12, 9, Math.PI, Math.PI / 2, !0), t.bezierCurveTo(20.5, 19.5, 20, 18, 21, 16), t.stroke(), t.beginPath(), t.moveTo(16, 16), t.lineTo(21, 16), t.lineTo(21, 21), t.stroke(), t.restore();
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
@@ -115,9 +115,9 @@ class Ge {
|
|
|
115
115
|
* @param zoom - Current zoom level (radius scales inversely with zoom)
|
|
116
116
|
*/
|
|
117
117
|
hitTestResize(t, e, o = 1) {
|
|
118
|
-
const n =
|
|
118
|
+
const n = re / o;
|
|
119
119
|
for (const s of this.resizeHandles)
|
|
120
|
-
if (
|
|
120
|
+
if (Ft(t, e, s.x, s.y, n))
|
|
121
121
|
return s;
|
|
122
122
|
return null;
|
|
123
123
|
}
|
|
@@ -127,8 +127,8 @@ class Ge {
|
|
|
127
127
|
*/
|
|
128
128
|
hitTestRotation(t, e, o = 1) {
|
|
129
129
|
if (!this.rotationHandle) return !1;
|
|
130
|
-
const n = (
|
|
131
|
-
return
|
|
130
|
+
const n = (Rt * 2.67 + 2) / o;
|
|
131
|
+
return Ft(t, e, this.rotationHandle.x, this.rotationHandle.y, n);
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
134
|
* Get rotation handle position (for React-based rendering)
|
|
@@ -143,7 +143,7 @@ class Ge {
|
|
|
143
143
|
*/
|
|
144
144
|
getCursor(t, e) {
|
|
145
145
|
const o = t.anchor.includes("middle") ? "edge" : "corner";
|
|
146
|
-
return
|
|
146
|
+
return ae(
|
|
147
147
|
t.x,
|
|
148
148
|
t.y,
|
|
149
149
|
this.rotationAnchor.x,
|
|
@@ -154,7 +154,33 @@ class Ge {
|
|
|
154
154
|
);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
|
|
157
|
+
const _e = 15;
|
|
158
|
+
function ze(v, t) {
|
|
159
|
+
return Math.abs(v) >= Math.abs(t) ? "x" : "y";
|
|
160
|
+
}
|
|
161
|
+
function Ve(v, t, e) {
|
|
162
|
+
return e != null && e.shift ? ze(v, t) === "x" ? { dx: v, dy: 0, lockedAxis: "y" } : { dx: 0, dy: t, lockedAxis: "x" } : { dx: v, dy: t, lockedAxis: null };
|
|
163
|
+
}
|
|
164
|
+
function Fe(v, t = _e) {
|
|
165
|
+
let o = (Math.round(v / t) * t % 360 + 360) % 360;
|
|
166
|
+
return o > 180 && (o -= 360), o === 0 ? 0 : o;
|
|
167
|
+
}
|
|
168
|
+
function Oe({
|
|
169
|
+
anchor: v,
|
|
170
|
+
startVisualWidth: t,
|
|
171
|
+
startVisualHeight: e,
|
|
172
|
+
newVisualWidth: o,
|
|
173
|
+
newVisualHeight: n
|
|
174
|
+
}) {
|
|
175
|
+
const s = t !== 0 ? t : 1, i = e !== 0 ? e : 1, a = o / s, r = n / i;
|
|
176
|
+
let l;
|
|
177
|
+
return v === "middle-left" || v === "middle-right" ? l = a : v === "middle-top" || v === "middle-bottom" ? l = r : l = Math.abs(a - 1) >= Math.abs(r - 1) ? a : r, {
|
|
178
|
+
scale: l,
|
|
179
|
+
newVisualWidth: t * l,
|
|
180
|
+
newVisualHeight: e * l
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
class Ye {
|
|
158
184
|
/**
|
|
159
185
|
* Calculate new dimensions and position for a resize operation
|
|
160
186
|
*/
|
|
@@ -164,64 +190,79 @@ class Be {
|
|
|
164
190
|
dx: o,
|
|
165
191
|
dy: n,
|
|
166
192
|
startData: s,
|
|
167
|
-
snapSystem: i
|
|
193
|
+
snapSystem: i,
|
|
194
|
+
modifiers: a
|
|
168
195
|
}) {
|
|
169
|
-
var
|
|
170
|
-
const
|
|
171
|
-
let
|
|
172
|
-
e.anchor.includes("right") ?
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
196
|
+
var F, W, q, J, E;
|
|
197
|
+
const l = new Ot(t).worldDeltaToLocal(o, n), h = l.dx, c = l.dy, d = s.visualWidth ?? s.width ?? 0, f = s.visualHeight ?? s.height ?? 0, b = s.width ?? 0, u = s.height ?? 0;
|
|
198
|
+
let p = d, g = f;
|
|
199
|
+
e.anchor.includes("right") ? p = d + h : e.anchor.includes("left") && (p = d - h), e.anchor !== "middle-left" && e.anchor !== "middle-right" && (e.anchor.includes("bottom") ? g = f + c : e.anchor.includes("top") && (g = f - c));
|
|
200
|
+
const y = (a == null ? void 0 : a.shift) === !0;
|
|
201
|
+
let S = null;
|
|
202
|
+
if (y) {
|
|
203
|
+
const z = Oe({
|
|
204
|
+
anchor: e.anchor,
|
|
205
|
+
startVisualWidth: d,
|
|
206
|
+
startVisualHeight: f,
|
|
207
|
+
newVisualWidth: p,
|
|
208
|
+
newVisualHeight: g
|
|
209
|
+
});
|
|
210
|
+
S = z.scale, p = z.newVisualWidth, g = z.newVisualHeight;
|
|
211
|
+
}
|
|
212
|
+
let m, w;
|
|
213
|
+
if (S !== null)
|
|
214
|
+
m = b * S, w = u * S;
|
|
215
|
+
else if (e.anchor === "middle-left" || e.anchor === "middle-right") {
|
|
216
|
+
const z = p - d;
|
|
217
|
+
m = b + z, w = u;
|
|
177
218
|
} else if (e.anchor === "middle-top" || e.anchor === "middle-bottom") {
|
|
178
|
-
const
|
|
179
|
-
|
|
219
|
+
const z = g - f;
|
|
220
|
+
m = b, w = u + z;
|
|
180
221
|
} else {
|
|
181
|
-
const
|
|
182
|
-
|
|
222
|
+
const z = p / d, N = g / f;
|
|
223
|
+
m = b * z, w = u * N;
|
|
183
224
|
}
|
|
184
|
-
const
|
|
185
|
-
let
|
|
225
|
+
const T = p, C = g;
|
|
226
|
+
let R = !1;
|
|
186
227
|
if (i && t.transformType === "image") {
|
|
187
|
-
const
|
|
188
|
-
if (
|
|
189
|
-
const
|
|
190
|
-
if (!!
|
|
191
|
-
const
|
|
192
|
-
(
|
|
228
|
+
const z = e.anchor ?? "", N = z === "top-left" || z === "top-right" || z === "bottom-left" || z === "bottom-right", Q = z.startsWith("crop-");
|
|
229
|
+
if (N && !Q) {
|
|
230
|
+
const B = (F = i.activeSnaps) == null ? void 0 : F.x, k = (W = i.activeSnaps) == null ? void 0 : W.y;
|
|
231
|
+
if (!!B || !!k) {
|
|
232
|
+
const G = [B, k].find(
|
|
233
|
+
(P) => typeof P == "object" && P !== null && "frozenWidth" in P
|
|
193
234
|
);
|
|
194
|
-
if (
|
|
195
|
-
const
|
|
196
|
-
let
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
235
|
+
if (G) {
|
|
236
|
+
const P = t, _ = s.transformData, j = G.frozenWidth ?? ((q = P.transformData) == null ? void 0 : q.width) ?? b, ot = P.imageAspectRatio || (_ != null && _.width && (_ != null && _.height) ? _.width / _.height : null);
|
|
237
|
+
let et = G.frozenHeight;
|
|
238
|
+
et == null && (ot && ot !== 0 ? et = j / ot : (J = P.transformData) != null && J.height ? et = P.transformData.height : et = u);
|
|
239
|
+
const lt = b !== 0 ? j / b : 1, Y = u !== 0 ? et / u : 1;
|
|
240
|
+
p = d * lt, g = f * Y, m = j, w = et, R = !0;
|
|
200
241
|
}
|
|
201
242
|
}
|
|
202
243
|
}
|
|
203
244
|
}
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
if (!e.anchor.includes("middle") && ((
|
|
207
|
-
const
|
|
208
|
-
|
|
245
|
+
m = Math.max(50, m), w = Math.max(40, w);
|
|
246
|
+
const x = t.clone(), H = x.resize(e.anchor, m, w, s);
|
|
247
|
+
if (!e.anchor.includes("middle") && ((E = x.stroke) != null && E.enabled) && s.strokeWidth !== void 0 && s.strokeWidth > 0) {
|
|
248
|
+
const z = s.width ?? 1, N = s.height ?? 1, Q = Math.sqrt(m / z * (w / N)), B = Math.max(1, Math.round(s.strokeWidth * Q * 10) / 10);
|
|
249
|
+
x.stroke = { ...x.stroke, width: B };
|
|
209
250
|
}
|
|
210
|
-
const
|
|
211
|
-
if (
|
|
212
|
-
const
|
|
251
|
+
const A = R || H === !1, I = e.anchor.includes("top") || e.anchor.includes("bottom"), L = "isCropping" in x && x.isCropping, D = "isGroup" in x && x.isGroup;
|
|
252
|
+
if (I && !L && !D) {
|
|
253
|
+
const z = t.getRotationAnchor(), N = this._calculateFixedCornerOffset({
|
|
213
254
|
element: t,
|
|
214
|
-
updatedElement:
|
|
255
|
+
updatedElement: x,
|
|
215
256
|
handle: e,
|
|
216
|
-
rotationAnchor:
|
|
257
|
+
rotationAnchor: z
|
|
217
258
|
});
|
|
218
|
-
|
|
259
|
+
x.x += N.x, x.y += N.y;
|
|
219
260
|
}
|
|
220
261
|
return {
|
|
221
|
-
element:
|
|
222
|
-
isFrozen:
|
|
262
|
+
element: x,
|
|
263
|
+
isFrozen: A,
|
|
223
264
|
// For snap system to detect break-free: dimensions before freeze was applied
|
|
224
|
-
unfrozenDimensions:
|
|
265
|
+
unfrozenDimensions: R ? { width: T, height: C } : void 0
|
|
225
266
|
};
|
|
226
267
|
}
|
|
227
268
|
/**
|
|
@@ -235,10 +276,10 @@ class Be {
|
|
|
235
276
|
handle: o,
|
|
236
277
|
rotationAnchor: n
|
|
237
278
|
}) {
|
|
238
|
-
const s = new
|
|
279
|
+
const s = new Ot(t), { cos: i, sin: a } = s.getRenderingCosSin(), r = t.getVisualBoundingBox(), l = e.getVisualBoundingBox(), h = n, c = e.getRotationAnchor(), d = this._getFixedLocalCoords(o.anchor, r.width, r.height), f = d.x, b = d.y, u = r.x - h.x, p = r.y - h.y, g = u + f, y = p + b, S = g * i - y * a, m = g * a + y * i, w = h.x + S, T = h.y + m, C = this._getFixedLocalCoords(o.anchor, l.width, l.height), R = C.x, x = C.y, H = l.x - c.x, M = l.y - c.y, A = H + R, I = M + x, L = A * i - I * a, D = A * a + I * i, F = c.x + L, W = c.y + D;
|
|
239
280
|
return {
|
|
240
|
-
x:
|
|
241
|
-
y:
|
|
281
|
+
x: w - F,
|
|
282
|
+
y: T - W
|
|
242
283
|
};
|
|
243
284
|
}
|
|
244
285
|
/**
|
|
@@ -276,7 +317,7 @@ class Be {
|
|
|
276
317
|
return n;
|
|
277
318
|
}
|
|
278
319
|
}
|
|
279
|
-
class
|
|
320
|
+
class Ge {
|
|
280
321
|
constructor() {
|
|
281
322
|
this.hooks = {
|
|
282
323
|
beforeResize: [],
|
|
@@ -331,9 +372,10 @@ class Le {
|
|
|
331
372
|
*/
|
|
332
373
|
executeResize(t) {
|
|
333
374
|
const e = this.runHooks("beforeResize", t);
|
|
334
|
-
let o =
|
|
375
|
+
let o = Ye.calculateResize({
|
|
335
376
|
...e,
|
|
336
|
-
snapSystem: t.snapSystem
|
|
377
|
+
snapSystem: t.snapSystem,
|
|
378
|
+
modifiers: t.modifiers
|
|
337
379
|
});
|
|
338
380
|
return o.handle = t.handle, o.startData = t.startData, o = this.runHooks("afterResize", o), o;
|
|
339
381
|
}
|
|
@@ -346,8 +388,8 @@ class Le {
|
|
|
346
388
|
return this.runHooks("afterPositionUpdate", o).position;
|
|
347
389
|
}
|
|
348
390
|
}
|
|
349
|
-
const
|
|
350
|
-
class
|
|
391
|
+
const Qe = new Ge();
|
|
392
|
+
class tn {
|
|
351
393
|
constructor(t = null) {
|
|
352
394
|
this.state = "IDLE", this.context = {
|
|
353
395
|
mode: null,
|
|
@@ -431,17 +473,24 @@ class Ne {
|
|
|
431
473
|
/**
|
|
432
474
|
* Update drag operation
|
|
433
475
|
* Returns updated position { x, y }
|
|
434
|
-
|
|
435
|
-
|
|
476
|
+
*
|
|
477
|
+
* `modifiers.shift` axis-locks the drag to the dominant axis
|
|
478
|
+
* (re-evaluated each move). Alignment snapping still runs on the
|
|
479
|
+
* free axis; on the locked axis the position is clamped back to the
|
|
480
|
+
* gesture-start value AFTER snapping, so a snap can never move the
|
|
481
|
+
* element off the locked axis. Read modifiers from the CURRENT
|
|
482
|
+
* pointer event — users press/release Shift mid-gesture.
|
|
483
|
+
*/
|
|
484
|
+
updateDrag(t, e, o = null, n) {
|
|
436
485
|
if (this.state !== "DRAGGING")
|
|
437
486
|
throw new Error("Cannot update drag: not in DRAGGING state");
|
|
438
|
-
const
|
|
439
|
-
let
|
|
487
|
+
const s = t - this.context.startX, i = e - this.context.startY, { dx: a, dy: r, lockedAxis: l } = Ve(s, i, n), h = this.context.startData;
|
|
488
|
+
let c = h.x + a, d = h.y + r;
|
|
440
489
|
if (this.snapHandler && this.snapHandler.snapPosition && this.context.element) {
|
|
441
|
-
const
|
|
442
|
-
|
|
490
|
+
const f = this.snapHandler.snapPosition({ x: c, y: d }, this.context.element, o);
|
|
491
|
+
c = f.x, d = f.y;
|
|
443
492
|
}
|
|
444
|
-
return { x:
|
|
493
|
+
return l === "x" ? c = h.x : l === "y" && (d = h.y), { x: c, y: d };
|
|
445
494
|
}
|
|
446
495
|
/**
|
|
447
496
|
* Start resize operation
|
|
@@ -541,13 +590,19 @@ class Ne {
|
|
|
541
590
|
/**
|
|
542
591
|
* Update rotation operation
|
|
543
592
|
* Returns updated rotation angle in degrees
|
|
593
|
+
*
|
|
594
|
+
* `modifiers.shift` snaps the result to 15° increments in stored
|
|
595
|
+
* (user-facing, sign-flipped — gotcha #15) degrees. The shift snap
|
|
596
|
+
* REPLACES the snapHandler's rotation snap while held: the 15° grid
|
|
597
|
+
* is a superset of the usual 0/90/180 magnets and must win
|
|
598
|
+
* deterministically. Read modifiers from the CURRENT pointer event.
|
|
544
599
|
*/
|
|
545
|
-
updateRotate(t, e, o, n) {
|
|
600
|
+
updateRotate(t, e, o, n, s) {
|
|
546
601
|
if (this.state !== "ROTATING")
|
|
547
602
|
throw new Error("Cannot update rotate: not in ROTATING state");
|
|
548
|
-
const
|
|
549
|
-
let
|
|
550
|
-
return
|
|
603
|
+
const i = this.context.startData, r = (le(o, n, t, e) - i.startAngle) * 180 / Math.PI;
|
|
604
|
+
let l = i.currentRotation - r;
|
|
605
|
+
return l = (l % 360 + 360) % 360, l > 180 && (l -= 360), s != null && s.shift ? Fe(l) : this.snapHandler && this.snapHandler.snapRotation && this.context.element ? this.snapHandler.snapRotation(l, this.context.element) : l;
|
|
551
606
|
}
|
|
552
607
|
/**
|
|
553
608
|
* Get rotation context
|
|
@@ -661,7 +716,7 @@ class Ne {
|
|
|
661
716
|
return this.context.mode;
|
|
662
717
|
}
|
|
663
718
|
}
|
|
664
|
-
class
|
|
719
|
+
class mt {
|
|
665
720
|
/**
|
|
666
721
|
* Resolve rotation anchor with clear precedence:
|
|
667
722
|
* 1. Transform's getRotationAnchor() if overridden
|
|
@@ -698,7 +753,7 @@ class bt {
|
|
|
698
753
|
rotation: this.resolve(t)
|
|
699
754
|
};
|
|
700
755
|
if (t.rotation !== 0) {
|
|
701
|
-
const n = o.rotation, s =
|
|
756
|
+
const n = o.rotation, s = gt.toRadiansInverse(t.rotation);
|
|
702
757
|
Object.keys(o).forEach((i) => {
|
|
703
758
|
if (i === "rotation") return;
|
|
704
759
|
const a = o[i], r = a.x - n.x, l = a.y - n.y, h = r * Math.cos(s) - l * Math.sin(s), c = r * Math.sin(s) + l * Math.cos(s);
|
|
@@ -769,7 +824,7 @@ class bt {
|
|
|
769
824
|
return Math.abs(n.x - o.x) > s || Math.abs(n.y - o.y) > s;
|
|
770
825
|
}
|
|
771
826
|
}
|
|
772
|
-
class
|
|
827
|
+
class qt {
|
|
773
828
|
constructor(t) {
|
|
774
829
|
this.cellSize = t, this.cells = /* @__PURE__ */ new Map(), this.idIndex = /* @__PURE__ */ new Map();
|
|
775
830
|
}
|
|
@@ -811,12 +866,12 @@ class Nt {
|
|
|
811
866
|
const s = [], i = Math.floor((t - o) / this.cellSize), a = Math.floor((t + o) / this.cellSize), r = Math.floor((e - o) / this.cellSize), l = Math.floor((e + o) / this.cellSize);
|
|
812
867
|
for (let h = i; h <= a; h++)
|
|
813
868
|
for (let c = r; c <= l; c++) {
|
|
814
|
-
const d = `${h},${c}`,
|
|
815
|
-
if (
|
|
816
|
-
for (const
|
|
817
|
-
if (n !== void 0 &&
|
|
818
|
-
const
|
|
819
|
-
|
|
869
|
+
const d = `${h},${c}`, f = this.cells.get(d);
|
|
870
|
+
if (f)
|
|
871
|
+
for (const b of f) {
|
|
872
|
+
if (n !== void 0 && b.id === n) continue;
|
|
873
|
+
const u = b.x - t, p = b.y - e;
|
|
874
|
+
u * u + p * p <= o * o && s.push(b);
|
|
820
875
|
}
|
|
821
876
|
}
|
|
822
877
|
return s;
|
|
@@ -865,32 +920,32 @@ class Nt {
|
|
|
865
920
|
return `${Math.floor(t / this.cellSize)},${Math.floor(e / this.cellSize)}`;
|
|
866
921
|
}
|
|
867
922
|
}
|
|
868
|
-
function
|
|
869
|
-
const t =
|
|
923
|
+
function ft(v) {
|
|
924
|
+
const t = v.transformData;
|
|
870
925
|
if (t && "width" in t && typeof t.width == "number")
|
|
871
926
|
return t.width;
|
|
872
927
|
}
|
|
873
|
-
function
|
|
874
|
-
const t =
|
|
928
|
+
function Tt(v) {
|
|
929
|
+
const t = v.transformData;
|
|
875
930
|
if (t && "height" in t && typeof t.height == "number")
|
|
876
931
|
return t.height;
|
|
877
932
|
}
|
|
878
|
-
function
|
|
879
|
-
const e =
|
|
933
|
+
function xt(v, t) {
|
|
934
|
+
const e = v.transformData;
|
|
880
935
|
return e && "width" in e ? (e.width = t, !0) : !1;
|
|
881
936
|
}
|
|
882
|
-
function
|
|
883
|
-
const e =
|
|
937
|
+
function Et(v, t) {
|
|
938
|
+
const e = v.transformData;
|
|
884
939
|
return e && "height" in e ? (e.height = t, !0) : !1;
|
|
885
940
|
}
|
|
886
|
-
class
|
|
941
|
+
class en {
|
|
887
942
|
constructor(t = {}) {
|
|
888
|
-
this._extraSnapRects = [], this.snapThreshold = t.snapThreshold ||
|
|
943
|
+
this._extraSnapRects = [], this.snapThreshold = t.snapThreshold || ct.canvas.snapThreshold, this.enabled = t.enabled !== !1, this.showGuides = t.showGuides !== !1, this.guides = [], this.activeSnaps = {
|
|
889
944
|
x: null,
|
|
890
945
|
// { snapTo: number, anchorKey: string, frozenFontSize: number, frozenWidth: number, frozenPosition: {x, y}, isPositionBasedSnap: boolean }
|
|
891
946
|
y: null
|
|
892
947
|
// { snapTo: number, anchorKey: string, frozenFontSize: number, frozenWidth: number, frozenPosition: {x, y}, isPositionBasedSnap: boolean }
|
|
893
|
-
}, this.stickyThreshold = t.stickyThreshold || 15, this._spatialGrid = new
|
|
948
|
+
}, this.stickyThreshold = t.stickyThreshold || 15, this._spatialGrid = new qt(Math.max(this.snapThreshold * 2, 16)), this._anchorMetadata = /* @__PURE__ */ new Map();
|
|
894
949
|
}
|
|
895
950
|
/**
|
|
896
951
|
* Enable or disable snapping
|
|
@@ -902,7 +957,7 @@ class Ke {
|
|
|
902
957
|
* Set snap threshold in pixels
|
|
903
958
|
*/
|
|
904
959
|
setSnapThreshold(t) {
|
|
905
|
-
this.snapThreshold = t, this._spatialGrid = new
|
|
960
|
+
this.snapThreshold = t, this._spatialGrid = new qt(Math.max(t * 2, 16));
|
|
906
961
|
}
|
|
907
962
|
/**
|
|
908
963
|
* Get current snap guides for rendering
|
|
@@ -941,7 +996,7 @@ class Ke {
|
|
|
941
996
|
_populateSpatialGrid(t) {
|
|
942
997
|
this._spatialGrid.clear(), this._anchorMetadata.clear();
|
|
943
998
|
for (const e of t) {
|
|
944
|
-
const o =
|
|
999
|
+
const o = mt.getSnapAnchors(e);
|
|
945
1000
|
for (const [n, s] of Object.entries(o)) {
|
|
946
1001
|
const i = `${e.id}:${n}`, a = {
|
|
947
1002
|
x: s.x,
|
|
@@ -990,73 +1045,73 @@ class Ke {
|
|
|
990
1045
|
return this.clearGuides(), t;
|
|
991
1046
|
const n = e.clone();
|
|
992
1047
|
n.x = t.x, n.y = t.y;
|
|
993
|
-
const s =
|
|
1048
|
+
const s = mt.getSnapAnchors(n), i = o.filter((y) => y.id !== e.id);
|
|
994
1049
|
this._populateSpatialGrid(i);
|
|
995
1050
|
let a = null, r = null, l = 1 / 0, h = 1 / 0;
|
|
996
|
-
const c = [], d = [],
|
|
997
|
-
for (const [y,
|
|
998
|
-
const
|
|
999
|
-
for (const
|
|
1000
|
-
const C = this._anchorMetadata.get(
|
|
1051
|
+
const c = [], d = [], f = [];
|
|
1052
|
+
for (const [y, S] of Object.entries(s)) {
|
|
1053
|
+
const m = this._spatialGrid.queryNearAxis("x", S.x, this.snapThreshold);
|
|
1054
|
+
for (const T of m) {
|
|
1055
|
+
const C = this._anchorMetadata.get(T.id);
|
|
1001
1056
|
if (!C) continue;
|
|
1002
|
-
const R = C.point, x = C.anchorKey,
|
|
1003
|
-
if (
|
|
1004
|
-
const
|
|
1057
|
+
const R = C.point, x = C.anchorKey, H = Math.abs(S.x - R.x);
|
|
1058
|
+
if (H < this.snapThreshold) {
|
|
1059
|
+
const M = {
|
|
1005
1060
|
snapTo: R.x,
|
|
1006
|
-
offset:
|
|
1061
|
+
offset: S.x - t.x,
|
|
1007
1062
|
// How far anchor is from element position
|
|
1008
|
-
distance:
|
|
1063
|
+
distance: H,
|
|
1009
1064
|
guide: {
|
|
1010
1065
|
type: "vertical",
|
|
1011
1066
|
x: R.x,
|
|
1012
|
-
y1: Math.min(
|
|
1013
|
-
y2: Math.max(
|
|
1067
|
+
y1: Math.min(S.y, R.y) - 50,
|
|
1068
|
+
y2: Math.max(S.y, R.y) + 50,
|
|
1014
1069
|
movingKey: y,
|
|
1015
1070
|
otherKey: x
|
|
1016
1071
|
}
|
|
1017
1072
|
};
|
|
1018
|
-
c.push(
|
|
1073
|
+
c.push(M), H < l && (l = H, a = M);
|
|
1019
1074
|
}
|
|
1020
1075
|
}
|
|
1021
|
-
const
|
|
1022
|
-
for (const
|
|
1023
|
-
const C = this._anchorMetadata.get(
|
|
1076
|
+
const w = this._spatialGrid.queryNearAxis("y", S.y, this.snapThreshold);
|
|
1077
|
+
for (const T of w) {
|
|
1078
|
+
const C = this._anchorMetadata.get(T.id);
|
|
1024
1079
|
if (!C) continue;
|
|
1025
|
-
const R = C.point, x = C.anchorKey,
|
|
1026
|
-
if (
|
|
1027
|
-
const
|
|
1080
|
+
const R = C.point, x = C.anchorKey, H = Math.abs(S.y - R.y);
|
|
1081
|
+
if (H < this.snapThreshold) {
|
|
1082
|
+
const M = {
|
|
1028
1083
|
snapTo: R.y,
|
|
1029
|
-
offset:
|
|
1030
|
-
distance:
|
|
1084
|
+
offset: S.y - t.y,
|
|
1085
|
+
distance: H,
|
|
1031
1086
|
guide: {
|
|
1032
1087
|
type: "horizontal",
|
|
1033
1088
|
y: R.y,
|
|
1034
|
-
x1: Math.min(
|
|
1035
|
-
x2: Math.max(
|
|
1089
|
+
x1: Math.min(S.x, R.x) - 50,
|
|
1090
|
+
x2: Math.max(S.x, R.x) + 50,
|
|
1036
1091
|
movingKey: y,
|
|
1037
1092
|
otherKey: x
|
|
1038
1093
|
}
|
|
1039
1094
|
};
|
|
1040
|
-
d.push(
|
|
1095
|
+
d.push(M), H < h && (h = H, r = M);
|
|
1041
1096
|
}
|
|
1042
1097
|
}
|
|
1043
1098
|
}
|
|
1044
|
-
let
|
|
1045
|
-
a && (
|
|
1046
|
-
const
|
|
1099
|
+
let b = t.x, u = t.y;
|
|
1100
|
+
a && (b = a.snapTo - a.offset), r && (u = r.snapTo - r.offset);
|
|
1101
|
+
const p = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map();
|
|
1047
1102
|
for (const y of c) {
|
|
1048
|
-
const
|
|
1049
|
-
(!
|
|
1103
|
+
const S = p.get(y.snapTo);
|
|
1104
|
+
(!S || y.distance < S.distance) && p.set(y.snapTo, y);
|
|
1050
1105
|
}
|
|
1051
1106
|
for (const y of d) {
|
|
1052
|
-
const
|
|
1053
|
-
(!
|
|
1107
|
+
const S = g.get(y.snapTo);
|
|
1108
|
+
(!S || y.distance < S.distance) && g.set(y.snapTo, y);
|
|
1054
1109
|
}
|
|
1110
|
+
for (const y of p.values())
|
|
1111
|
+
f.push(y.guide);
|
|
1055
1112
|
for (const y of g.values())
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
u.push(y.guide);
|
|
1059
|
-
return this.guides = u, { x: p, y: b };
|
|
1113
|
+
f.push(y.guide);
|
|
1114
|
+
return this.guides = f, { x: b, y: u };
|
|
1060
1115
|
}
|
|
1061
1116
|
/**
|
|
1062
1117
|
* Calculate what the frozen font size should be at the snap point
|
|
@@ -1067,7 +1122,7 @@ class Ke {
|
|
|
1067
1122
|
const i = n != null && n.anchor ? String(n.anchor) : "";
|
|
1068
1123
|
if (!(n && (i.includes("top") || i.includes("bottom"))))
|
|
1069
1124
|
return s.fontSize ?? 0;
|
|
1070
|
-
const r =
|
|
1125
|
+
const r = ft(t) ?? t.width ?? s.width;
|
|
1071
1126
|
let l = r;
|
|
1072
1127
|
i.includes("right") && e !== 0 ? l = r + e : i.includes("left") && e !== 0 && (l = r - e);
|
|
1073
1128
|
const h = l / s.width;
|
|
@@ -1079,7 +1134,7 @@ class Ke {
|
|
|
1079
1134
|
* Used for text elements where height is derived, not settable
|
|
1080
1135
|
*/
|
|
1081
1136
|
_isPositionBasedSnap(t, e) {
|
|
1082
|
-
return e === "x" ? !1 : e === "y" ? !(
|
|
1137
|
+
return e === "x" ? !1 : e === "y" ? !(Tt(t) !== void 0 || t.height !== void 0 && typeof t.height == "number") : !1;
|
|
1083
1138
|
}
|
|
1084
1139
|
/**
|
|
1085
1140
|
* Determine which snap keys to use based on the resize handle
|
|
@@ -1107,9 +1162,9 @@ class Ke {
|
|
|
1107
1162
|
for (const h of l) {
|
|
1108
1163
|
const c = this._anchorMetadata.get(h.id);
|
|
1109
1164
|
if (!c || !i.has(c.anchorKey)) continue;
|
|
1110
|
-
const d = c.point,
|
|
1111
|
-
|
|
1112
|
-
distance:
|
|
1165
|
+
const d = c.point, f = c.anchorKey, b = Math.abs(r.x - d.x);
|
|
1166
|
+
b < this.snapThreshold && s.push({
|
|
1167
|
+
distance: b,
|
|
1113
1168
|
snapTo: d.x,
|
|
1114
1169
|
currentValue: r.x,
|
|
1115
1170
|
guide: {
|
|
@@ -1118,7 +1173,7 @@ class Ke {
|
|
|
1118
1173
|
y1: Math.min(r.y, d.y) - 50,
|
|
1119
1174
|
y2: Math.max(r.y, d.y) + 50,
|
|
1120
1175
|
movingKey: a,
|
|
1121
|
-
otherKey:
|
|
1176
|
+
otherKey: f
|
|
1122
1177
|
}
|
|
1123
1178
|
});
|
|
1124
1179
|
}
|
|
@@ -1139,9 +1194,9 @@ class Ke {
|
|
|
1139
1194
|
for (const h of l) {
|
|
1140
1195
|
const c = this._anchorMetadata.get(h.id);
|
|
1141
1196
|
if (!c || !i.has(c.anchorKey)) continue;
|
|
1142
|
-
const d = c.point,
|
|
1143
|
-
|
|
1144
|
-
distance:
|
|
1197
|
+
const d = c.point, f = c.anchorKey, b = Math.abs(r.y - d.y);
|
|
1198
|
+
b < this.snapThreshold && s.push({
|
|
1199
|
+
distance: b,
|
|
1145
1200
|
snapTo: d.y,
|
|
1146
1201
|
currentValue: r.y,
|
|
1147
1202
|
guide: {
|
|
@@ -1150,7 +1205,7 @@ class Ke {
|
|
|
1150
1205
|
x1: Math.min(r.x, d.x) - 50,
|
|
1151
1206
|
x2: Math.max(r.x, d.x) + 50,
|
|
1152
1207
|
movingKey: a,
|
|
1153
|
-
otherKey:
|
|
1208
|
+
otherKey: f
|
|
1154
1209
|
}
|
|
1155
1210
|
});
|
|
1156
1211
|
}
|
|
@@ -1190,7 +1245,7 @@ class Ke {
|
|
|
1190
1245
|
for (const l of Object.values(o))
|
|
1191
1246
|
Math.abs(l.x - t.snapTo) < 5 && (a = Math.min(a, l.y), r = Math.max(r, l.y));
|
|
1192
1247
|
for (const l of n) {
|
|
1193
|
-
const h =
|
|
1248
|
+
const h = mt.getSnapAnchors(l);
|
|
1194
1249
|
for (const c of Object.values(h))
|
|
1195
1250
|
Math.abs(c.x - t.snapTo) < 5 && (a = Math.min(a, c.y), r = Math.max(r, c.y));
|
|
1196
1251
|
}
|
|
@@ -1212,7 +1267,7 @@ class Ke {
|
|
|
1212
1267
|
for (const l of Object.values(o))
|
|
1213
1268
|
Math.abs(l.y - t.snapTo) < 5 && (a = Math.min(a, l.x), r = Math.max(r, l.x));
|
|
1214
1269
|
for (const l of n) {
|
|
1215
|
-
const h =
|
|
1270
|
+
const h = mt.getSnapAnchors(l);
|
|
1216
1271
|
for (const c of Object.values(h))
|
|
1217
1272
|
Math.abs(c.y - t.snapTo) < 5 && (a = Math.min(a, c.x), r = Math.max(r, c.x));
|
|
1218
1273
|
}
|
|
@@ -1259,7 +1314,7 @@ class Ke {
|
|
|
1259
1314
|
* @returns {Object} { frozenWidth, frozenHeight } - Dimensions at snap point
|
|
1260
1315
|
*/
|
|
1261
1316
|
_calculateFrozenDimensionsAtSnap(t, e, o, n, s) {
|
|
1262
|
-
const i =
|
|
1317
|
+
const i = ft(t) ?? t.width ?? 0, a = Tt(t) ?? t.height ?? 0;
|
|
1263
1318
|
let r = i, l = a;
|
|
1264
1319
|
const h = t.transformType === "image", c = h ? t.imageAspectRatio || (i && a ? i / a : null) : null, d = n.toLowerCase();
|
|
1265
1320
|
return e === "x" ? d.includes("right") ? (r = i + o, h && c && (l = r / c)) : d.includes("left") && (r = i - o, h && c && (l = r / c)) : e === "y" && (d.includes("bottom") ? (l = a + o, h && c && (r = l * c)) : d.includes("top") && (l = a - o, h && c && (r = l * c))), { frozenWidth: r, frozenHeight: l };
|
|
@@ -1274,36 +1329,36 @@ class Ke {
|
|
|
1274
1329
|
if (r) {
|
|
1275
1330
|
const c = e[r.anchorKey];
|
|
1276
1331
|
if (c) {
|
|
1277
|
-
const d = t === "x" ? c.x : c.y,
|
|
1278
|
-
if (
|
|
1332
|
+
const d = t === "x" ? c.x : c.y, f = Math.abs(d - r.snapTo), b = this._getAdjustedStickyThreshold(t, n);
|
|
1333
|
+
if (f < b) {
|
|
1279
1334
|
if (l = r.snapTo - d, !(t === "y" && r.isPositionBasedSnap)) {
|
|
1280
|
-
const
|
|
1335
|
+
const p = this._calculateFrozenFontSizeAtSnap(
|
|
1281
1336
|
n,
|
|
1282
1337
|
t === "x" ? l : 0,
|
|
1283
1338
|
t === "y" ? l : 0,
|
|
1284
1339
|
s,
|
|
1285
1340
|
i
|
|
1286
1341
|
);
|
|
1287
|
-
|
|
1342
|
+
p !== r.frozenFontSize && (r.frozenFontSize = p);
|
|
1288
1343
|
}
|
|
1289
1344
|
h = this._createGuideForSnap(r, r.anchorKey, e, a, t);
|
|
1290
1345
|
} else {
|
|
1291
|
-
const
|
|
1346
|
+
const u = r;
|
|
1292
1347
|
if (this.activeSnaps[t] = null, o.length > 0 && o[0].distance < this.snapThreshold) {
|
|
1293
1348
|
h = o[0], l = h.snapTo - h.currentValue;
|
|
1294
|
-
const
|
|
1349
|
+
const p = u && u.anchorKey === h.guide.movingKey && Math.abs(u.snapTo - h.snapTo) < 1, g = p ? u.frozenFontSize : this._calculateFrozenFontSizeAtSnap(
|
|
1295
1350
|
n,
|
|
1296
1351
|
t === "x" ? l : 0,
|
|
1297
1352
|
t === "y" ? l : 0,
|
|
1298
1353
|
s,
|
|
1299
1354
|
i
|
|
1300
1355
|
), y = this._isPositionBasedSnap(n, t);
|
|
1301
|
-
let
|
|
1302
|
-
|
|
1356
|
+
let S;
|
|
1357
|
+
p ? S = u.frozenPosition : y ? S = {
|
|
1303
1358
|
x: t === "x" ? n.x + l : n.x,
|
|
1304
1359
|
y: t === "y" ? n.y + l : n.y
|
|
1305
|
-
} :
|
|
1306
|
-
const
|
|
1360
|
+
} : S = { x: n.x, y: n.y };
|
|
1361
|
+
const m = this._calculateFrozenDimensionsAtSnap(
|
|
1307
1362
|
n,
|
|
1308
1363
|
t,
|
|
1309
1364
|
l,
|
|
@@ -1313,10 +1368,10 @@ class Ke {
|
|
|
1313
1368
|
this.activeSnaps[t] = {
|
|
1314
1369
|
snapTo: h.snapTo,
|
|
1315
1370
|
anchorKey: h.guide.movingKey,
|
|
1316
|
-
frozenFontSize:
|
|
1317
|
-
frozenWidth:
|
|
1318
|
-
frozenHeight:
|
|
1319
|
-
frozenPosition:
|
|
1371
|
+
frozenFontSize: g,
|
|
1372
|
+
frozenWidth: m.frozenWidth,
|
|
1373
|
+
frozenHeight: m.frozenHeight,
|
|
1374
|
+
frozenPosition: S,
|
|
1320
1375
|
isPositionBasedSnap: y
|
|
1321
1376
|
};
|
|
1322
1377
|
}
|
|
@@ -1325,19 +1380,19 @@ class Ke {
|
|
|
1325
1380
|
this.activeSnaps[t] = null;
|
|
1326
1381
|
} else if (o.length > 0 && o[0].distance < this.snapThreshold) {
|
|
1327
1382
|
h = o[0], l = h.snapTo - h.currentValue;
|
|
1328
|
-
const c = this.activeSnaps[t], d = c && c.anchorKey === h.guide.movingKey && Math.abs(c.snapTo - h.snapTo) < 1,
|
|
1383
|
+
const c = this.activeSnaps[t], d = c && c.anchorKey === h.guide.movingKey && Math.abs(c.snapTo - h.snapTo) < 1, f = d ? c.frozenFontSize : this._calculateFrozenFontSizeAtSnap(
|
|
1329
1384
|
n,
|
|
1330
1385
|
t === "x" ? l : 0,
|
|
1331
1386
|
t === "y" ? l : 0,
|
|
1332
1387
|
s,
|
|
1333
1388
|
i
|
|
1334
|
-
),
|
|
1335
|
-
let
|
|
1336
|
-
d ?
|
|
1389
|
+
), b = this._isPositionBasedSnap(n, t);
|
|
1390
|
+
let u;
|
|
1391
|
+
d ? u = c.frozenPosition : b ? u = {
|
|
1337
1392
|
x: t === "x" ? n.x + l : n.x,
|
|
1338
1393
|
y: t === "y" ? n.y + l : n.y
|
|
1339
|
-
} :
|
|
1340
|
-
const
|
|
1394
|
+
} : u = { x: n.x, y: n.y };
|
|
1395
|
+
const p = this._calculateFrozenDimensionsAtSnap(
|
|
1341
1396
|
n,
|
|
1342
1397
|
t,
|
|
1343
1398
|
l,
|
|
@@ -1347,11 +1402,11 @@ class Ke {
|
|
|
1347
1402
|
this.activeSnaps[t] = {
|
|
1348
1403
|
snapTo: h.snapTo,
|
|
1349
1404
|
anchorKey: h.guide.movingKey,
|
|
1350
|
-
frozenFontSize:
|
|
1351
|
-
frozenWidth:
|
|
1352
|
-
frozenHeight:
|
|
1353
|
-
frozenPosition:
|
|
1354
|
-
isPositionBasedSnap:
|
|
1405
|
+
frozenFontSize: f,
|
|
1406
|
+
frozenWidth: p.frozenWidth,
|
|
1407
|
+
frozenHeight: p.frozenHeight,
|
|
1408
|
+
frozenPosition: u,
|
|
1409
|
+
isPositionBasedSnap: b
|
|
1355
1410
|
};
|
|
1356
1411
|
}
|
|
1357
1412
|
return { snapDelta: l, bestSnap: h };
|
|
@@ -1362,11 +1417,11 @@ class Ke {
|
|
|
1362
1417
|
_adjustElementForRightResize(t, e, o) {
|
|
1363
1418
|
const n = t.getVisualBoundingBox(), s = t.transformType === "image";
|
|
1364
1419
|
if (!s) {
|
|
1365
|
-
const i =
|
|
1366
|
-
i !== void 0 ?
|
|
1420
|
+
const i = ft(t);
|
|
1421
|
+
i !== void 0 ? xt(t, i + e) : t.width !== void 0 && (t.width += e);
|
|
1367
1422
|
}
|
|
1368
1423
|
if (o.anchor === "middle-right") {
|
|
1369
|
-
const i =
|
|
1424
|
+
const i = gt.toRadiansInverse(t.rotation), a = Math.cos(i), r = Math.sin(i);
|
|
1370
1425
|
t.x += e / 2 * a, t.y += e / 2 * r;
|
|
1371
1426
|
} else if (!s) {
|
|
1372
1427
|
const a = t.getVisualBoundingBox().x - n.x;
|
|
@@ -1379,11 +1434,11 @@ class Ke {
|
|
|
1379
1434
|
_adjustElementForLeftResize(t, e, o) {
|
|
1380
1435
|
const n = t.getVisualBoundingBox(), s = t.transformType === "image";
|
|
1381
1436
|
if (!s) {
|
|
1382
|
-
const i =
|
|
1383
|
-
i !== void 0 ?
|
|
1437
|
+
const i = ft(t);
|
|
1438
|
+
i !== void 0 ? xt(t, i - e) : t.width !== void 0 && (t.width -= e);
|
|
1384
1439
|
}
|
|
1385
1440
|
if (o.anchor === "middle-left") {
|
|
1386
|
-
const i =
|
|
1441
|
+
const i = gt.toRadiansInverse(t.rotation), a = Math.cos(i), r = Math.sin(i);
|
|
1387
1442
|
t.x += e / 2 * a, t.y += e / 2 * r;
|
|
1388
1443
|
} else if (t.x += e, !s) {
|
|
1389
1444
|
const i = t.getVisualBoundingBox(), a = i.x + i.width - (n.x + n.width);
|
|
@@ -1396,12 +1451,12 @@ class Ke {
|
|
|
1396
1451
|
_adjustElementForBottomResize(t, e, o) {
|
|
1397
1452
|
const n = t.getVisualBoundingBox(), s = t.transformType === "image";
|
|
1398
1453
|
if (!s) {
|
|
1399
|
-
const r =
|
|
1400
|
-
r !== void 0 ?
|
|
1454
|
+
const r = Tt(t);
|
|
1455
|
+
r !== void 0 ? Et(t, r + e) : t.height !== void 0 && (t.height += e);
|
|
1401
1456
|
}
|
|
1402
1457
|
const i = t.getVisualBoundingBox(), a = Math.abs(i.height - n.height) > 0.01;
|
|
1403
1458
|
if (o.anchor === "middle-bottom") {
|
|
1404
|
-
const r =
|
|
1459
|
+
const r = gt.toRadiansInverse(t.rotation), l = Math.cos(r), h = Math.sin(r);
|
|
1405
1460
|
t.x -= e / 2 * h, t.y += e / 2 * l;
|
|
1406
1461
|
} else if (!s && a) {
|
|
1407
1462
|
const r = i.y - n.y;
|
|
@@ -1414,12 +1469,12 @@ class Ke {
|
|
|
1414
1469
|
_adjustElementForTopResize(t, e, o) {
|
|
1415
1470
|
const n = t.getVisualBoundingBox(), s = t.transformType === "image";
|
|
1416
1471
|
if (!s) {
|
|
1417
|
-
const r =
|
|
1418
|
-
r !== void 0 ?
|
|
1472
|
+
const r = Tt(t);
|
|
1473
|
+
r !== void 0 ? Et(t, r - e) : t.height !== void 0 && (t.height -= e);
|
|
1419
1474
|
}
|
|
1420
1475
|
const i = t.getVisualBoundingBox(), a = Math.abs(i.height - n.height) > 0.01;
|
|
1421
1476
|
if (o.anchor === "middle-top") {
|
|
1422
|
-
const r =
|
|
1477
|
+
const r = gt.toRadiansInverse(t.rotation), l = Math.cos(r), h = Math.sin(r);
|
|
1423
1478
|
t.x -= e / 2 * h, t.y += e / 2 * l;
|
|
1424
1479
|
} else {
|
|
1425
1480
|
const r = !s && a;
|
|
@@ -1438,63 +1493,63 @@ class Ke {
|
|
|
1438
1493
|
* @returns {object} Modified resize result with adjusted element
|
|
1439
1494
|
*/
|
|
1440
1495
|
snapDimensions(t, e, o = null) {
|
|
1441
|
-
var
|
|
1496
|
+
var T, C, R, x, H;
|
|
1442
1497
|
if (!this.enabled || !e)
|
|
1443
1498
|
return this.clearGuides(), t;
|
|
1444
1499
|
const { element: n } = t, s = t.handle;
|
|
1445
1500
|
let i;
|
|
1446
1501
|
const a = n.transformType === "image", r = this.activeSnaps.x !== null || this.activeSnaps.y !== null;
|
|
1447
1502
|
if (a && r && t.isFrozen && t.unfrozenDimensions) {
|
|
1448
|
-
const
|
|
1449
|
-
if (
|
|
1450
|
-
const A = n.getVisualBoundingBox(),
|
|
1451
|
-
|
|
1503
|
+
const M = n.clone();
|
|
1504
|
+
if (M.transformData) {
|
|
1505
|
+
const A = n.getVisualBoundingBox(), I = A.width, L = A.height, D = (o == null ? void 0 : o.width) ?? n.width ?? 0, F = (o == null ? void 0 : o.height) ?? n.height ?? 0, W = (o == null ? void 0 : o.visualWidth) ?? I, q = (o == null ? void 0 : o.visualHeight) ?? L, J = t.unfrozenDimensions.width / W, E = t.unfrozenDimensions.height / q;
|
|
1506
|
+
xt(M, D * J), Et(M, F * E);
|
|
1452
1507
|
}
|
|
1453
|
-
i =
|
|
1508
|
+
i = mt.getSnapAnchors(M);
|
|
1454
1509
|
} else
|
|
1455
|
-
i =
|
|
1456
|
-
const l = e.filter((
|
|
1510
|
+
i = mt.getSnapAnchors(n);
|
|
1511
|
+
const l = e.filter((M) => M.id !== n.id);
|
|
1457
1512
|
if (l.length === 0)
|
|
1458
1513
|
return this.clearGuides(), t;
|
|
1459
1514
|
this._populateSpatialGrid(l);
|
|
1460
|
-
const h = this._getSnapKeysForHandle(s), c = this._getTargetSnapKeys(), d = this._findXSnaps(i, l, h, c),
|
|
1461
|
-
this._prioritizeSnaps(d, s, "x"), this._prioritizeSnaps(
|
|
1462
|
-
const
|
|
1463
|
-
y &&
|
|
1464
|
-
const
|
|
1465
|
-
if (a &&
|
|
1515
|
+
const h = this._getSnapKeysForHandle(s), c = this._getTargetSnapKeys(), d = this._findXSnaps(i, l, h, c), f = this._findYSnaps(i, l, h, c);
|
|
1516
|
+
this._prioritizeSnaps(d, s, "x"), this._prioritizeSnaps(f, s, "y");
|
|
1517
|
+
const b = this._processStickySnap("x", i, d, n, s, o, l), u = this._processStickySnap("y", i, f, n, s, o, l), p = b.snapDelta, g = u.snapDelta, y = b.bestSnap, S = u.bestSnap, m = [];
|
|
1518
|
+
y && m.push(y.guide), S && m.push(S.guide), this.guides = m, m.length > 0;
|
|
1519
|
+
const w = s && (s.anchor === "top-left" || s.anchor === "top-right" || s.anchor === "bottom-left" || s.anchor === "bottom-right");
|
|
1520
|
+
if (a && w && (p !== 0 || g !== 0))
|
|
1466
1521
|
return t;
|
|
1467
|
-
if (
|
|
1468
|
-
const
|
|
1469
|
-
if (!
|
|
1522
|
+
if (p !== 0 || g !== 0) {
|
|
1523
|
+
const M = n.clone(), A = this.activeSnaps.x || this.activeSnaps.y, I = (A == null ? void 0 : A.frozenFontSize) ?? n.fontSize ?? 0, L = (A == null ? void 0 : A.frozenWidth) ?? ft(n) ?? n.width ?? 0, D = (A == null ? void 0 : A.frozenHeight) ?? Tt(n) ?? n.height ?? 0, F = (A == null ? void 0 : A.frozenPosition) ?? { x: n.x, y: n.y }, W = M.isCropping && !String(s.anchor).startsWith("crop-");
|
|
1524
|
+
if (!W)
|
|
1470
1525
|
if (s && s.anchor) {
|
|
1471
|
-
if (
|
|
1472
|
-
const
|
|
1473
|
-
|
|
1526
|
+
if (p !== 0) {
|
|
1527
|
+
const B = (T = this.activeSnaps.x) == null ? void 0 : T.anchorKey, k = B == null ? void 0 : B.toLowerCase();
|
|
1528
|
+
k && k.includes("right") ? this._adjustElementForRightResize(M, p, s) : k && k.includes("left") ? this._adjustElementForLeftResize(M, p, s) : M.x += p;
|
|
1474
1529
|
}
|
|
1475
|
-
if (
|
|
1476
|
-
const
|
|
1477
|
-
|
|
1530
|
+
if (g !== 0) {
|
|
1531
|
+
const B = (C = this.activeSnaps.y) == null ? void 0 : C.anchorKey, k = B == null ? void 0 : B.toLowerCase();
|
|
1532
|
+
k && k.includes("bottom") ? this._adjustElementForBottomResize(M, g, s) : k && k.includes("top") ? this._adjustElementForTopResize(M, g, s) : M.y += g;
|
|
1478
1533
|
}
|
|
1479
1534
|
} else
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
const
|
|
1483
|
-
if (
|
|
1484
|
-
if (
|
|
1485
|
-
const
|
|
1486
|
-
let
|
|
1487
|
-
|
|
1488
|
-
const
|
|
1489
|
-
|
|
1535
|
+
M.x += p, M.y += g;
|
|
1536
|
+
M.fontSize !== void 0 && (M.fontSize = I);
|
|
1537
|
+
const q = M.transformType === "image", J = this.activeSnaps.x !== null || this.activeSnaps.y !== null;
|
|
1538
|
+
if (q && J) {
|
|
1539
|
+
if (ft(M) !== void 0) {
|
|
1540
|
+
const B = this.activeSnaps.x || this.activeSnaps.y;
|
|
1541
|
+
let k = L, O = D;
|
|
1542
|
+
B && (k = B.frozenWidth ?? k, O = B.frozenHeight ?? O);
|
|
1543
|
+
const G = ft(n), P = Tt(n), _ = M.imageAspectRatio || (G && P ? G / P : null);
|
|
1544
|
+
_ && _ !== 0 && (O = k / _), xt(M, k), Et(M, O), B && (B.frozenWidth = k, B.frozenHeight = O);
|
|
1490
1545
|
}
|
|
1491
1546
|
} else
|
|
1492
|
-
(((R = this.activeSnaps.y) == null ? void 0 : R.isPositionBasedSnap) || !1) && (
|
|
1493
|
-
const
|
|
1494
|
-
return (
|
|
1547
|
+
(((R = this.activeSnaps.y) == null ? void 0 : R.isPositionBasedSnap) || !1) && (ft(M) !== void 0 ? xt(M, L) : M.width !== void 0 && (M.width = L));
|
|
1548
|
+
const E = s && (s.anchor === "middle-left" || s.anchor === "middle-right"), z = s && (s.anchor === "middle-top" || s.anchor === "middle-bottom"), N = ((x = this.activeSnaps.x) == null ? void 0 : x.isPositionBasedSnap) || !1, Q = ((H = this.activeSnaps.y) == null ? void 0 : H.isPositionBasedSnap) || !1;
|
|
1549
|
+
return (p === 0 || N) && !E && !z && !W && (M.x = F.x), (g === 0 || Q) && !z && !E && !W && (M.y = F.y), {
|
|
1495
1550
|
...t,
|
|
1496
|
-
element:
|
|
1497
|
-
snapAdjustment: { dx:
|
|
1551
|
+
element: M,
|
|
1552
|
+
snapAdjustment: { dx: p, dy: g },
|
|
1498
1553
|
// Flag to indicate we're in sticky snap mode (used to freeze font size)
|
|
1499
1554
|
isInStickySnap: !0
|
|
1500
1555
|
};
|
|
@@ -1508,12 +1563,12 @@ class Ke {
|
|
|
1508
1563
|
if (!this.enabled) return t;
|
|
1509
1564
|
const n = [0, 45, 90, 135, 180, 225, 270, 315, 360], s = 5;
|
|
1510
1565
|
for (const i of n)
|
|
1511
|
-
if (
|
|
1566
|
+
if (he(t, i, s))
|
|
1512
1567
|
return i;
|
|
1513
1568
|
return t;
|
|
1514
1569
|
}
|
|
1515
1570
|
}
|
|
1516
|
-
class
|
|
1571
|
+
class nn {
|
|
1517
1572
|
constructor(t = {}) {
|
|
1518
1573
|
this.lastSnapTarget = null, this.detectionThreshold = t.detectionThreshold || 100, this.minDistance = t.minDistance || 10, this.enabled = t.enabled !== !1, this.showLabels = t.showLabels !== !1, this.indicators = [];
|
|
1519
1574
|
}
|
|
@@ -1548,106 +1603,106 @@ class $e {
|
|
|
1548
1603
|
snapToSpacing(t, e, o) {
|
|
1549
1604
|
if (!this.enabled || !o)
|
|
1550
1605
|
return t;
|
|
1551
|
-
const n =
|
|
1606
|
+
const n = Yt, s = o.filter((p) => p.id !== e.id);
|
|
1552
1607
|
if (s.length === 0)
|
|
1553
1608
|
return t;
|
|
1554
1609
|
const i = e.clone();
|
|
1555
1610
|
i.x = t.x, i.y = t.y;
|
|
1556
1611
|
const a = i.getVisualBoundingBox(), r = a.x - t.x, l = a.y - t.y;
|
|
1557
|
-
let h = t.x, c = t.y, d = !1,
|
|
1558
|
-
const
|
|
1559
|
-
const
|
|
1560
|
-
return !(a.x + a.width <
|
|
1612
|
+
let h = t.x, c = t.y, d = !1, f = !1;
|
|
1613
|
+
const b = s.filter((p) => {
|
|
1614
|
+
const g = p.getVisualBoundingBox();
|
|
1615
|
+
return !(a.x + a.width < g.x || a.x > g.x + g.width);
|
|
1561
1616
|
});
|
|
1562
|
-
if (
|
|
1563
|
-
const y =
|
|
1564
|
-
return y.y -
|
|
1565
|
-
}),
|
|
1566
|
-
let
|
|
1567
|
-
for (const
|
|
1568
|
-
const
|
|
1569
|
-
|
|
1617
|
+
if (b.sort((p, g) => {
|
|
1618
|
+
const y = p.getVisualBoundingBox(), S = g.getVisualBoundingBox();
|
|
1619
|
+
return y.y - S.y;
|
|
1620
|
+
}), b.length >= 1) {
|
|
1621
|
+
let p = null, g = null;
|
|
1622
|
+
for (const m of b) {
|
|
1623
|
+
const w = m.getVisualBoundingBox();
|
|
1624
|
+
w.y + w.height <= a.y ? (!p || w.y > p.getVisualBoundingBox().y) && (p = m) : w.y >= a.y + a.height && (!g || w.y < g.getVisualBoundingBox().y) && (g = m);
|
|
1570
1625
|
}
|
|
1571
1626
|
const y = [];
|
|
1572
|
-
for (let
|
|
1573
|
-
const
|
|
1627
|
+
for (let m = 0; m < b.length - 1; m++) {
|
|
1628
|
+
const w = b[m].getVisualBoundingBox(), C = b[m + 1].getVisualBoundingBox().y - (w.y + w.height);
|
|
1574
1629
|
y.push(C);
|
|
1575
1630
|
}
|
|
1576
|
-
let
|
|
1577
|
-
if (
|
|
1578
|
-
const
|
|
1579
|
-
for (const
|
|
1580
|
-
if (Math.abs(
|
|
1581
|
-
|
|
1631
|
+
let S = null;
|
|
1632
|
+
if (p) {
|
|
1633
|
+
const m = p.getVisualBoundingBox(), w = a.y - (m.y + m.height);
|
|
1634
|
+
for (const T of y)
|
|
1635
|
+
if (Math.abs(w - T) <= n) {
|
|
1636
|
+
S = T;
|
|
1582
1637
|
break;
|
|
1583
1638
|
}
|
|
1584
1639
|
}
|
|
1585
|
-
if (!
|
|
1586
|
-
const
|
|
1587
|
-
for (const
|
|
1588
|
-
if (Math.abs(
|
|
1589
|
-
|
|
1640
|
+
if (!S && g) {
|
|
1641
|
+
const w = g.getVisualBoundingBox().y - (a.y + a.height);
|
|
1642
|
+
for (const T of y)
|
|
1643
|
+
if (Math.abs(w - T) <= n) {
|
|
1644
|
+
S = T;
|
|
1590
1645
|
break;
|
|
1591
1646
|
}
|
|
1592
1647
|
}
|
|
1593
|
-
if (
|
|
1594
|
-
if (
|
|
1595
|
-
const
|
|
1596
|
-
Math.abs(
|
|
1648
|
+
if (S !== null && S > 0) {
|
|
1649
|
+
if (p) {
|
|
1650
|
+
const m = p.getVisualBoundingBox(), w = a.y - (m.y + m.height);
|
|
1651
|
+
Math.abs(w - S) <= n && (c = m.y + m.height + S - l, f = !0);
|
|
1597
1652
|
}
|
|
1598
|
-
if (!
|
|
1599
|
-
const
|
|
1600
|
-
Math.abs(
|
|
1653
|
+
if (!f && g) {
|
|
1654
|
+
const m = g.getVisualBoundingBox(), w = m.y - (a.y + a.height);
|
|
1655
|
+
Math.abs(w - S) <= n && (c = m.y - a.height - S - l, f = !0);
|
|
1601
1656
|
}
|
|
1602
1657
|
}
|
|
1603
1658
|
}
|
|
1604
|
-
const
|
|
1605
|
-
const
|
|
1606
|
-
return !(a.y + a.height <
|
|
1659
|
+
const u = s.filter((p) => {
|
|
1660
|
+
const g = p.getVisualBoundingBox();
|
|
1661
|
+
return !(a.y + a.height < g.y || a.y > g.y + g.height);
|
|
1607
1662
|
});
|
|
1608
|
-
if (
|
|
1609
|
-
const y =
|
|
1610
|
-
return y.x -
|
|
1611
|
-
}),
|
|
1612
|
-
let
|
|
1613
|
-
for (const
|
|
1614
|
-
const
|
|
1615
|
-
|
|
1663
|
+
if (u.sort((p, g) => {
|
|
1664
|
+
const y = p.getVisualBoundingBox(), S = g.getVisualBoundingBox();
|
|
1665
|
+
return y.x - S.x;
|
|
1666
|
+
}), u.length >= 1) {
|
|
1667
|
+
let p = null, g = null;
|
|
1668
|
+
for (const m of u) {
|
|
1669
|
+
const w = m.getVisualBoundingBox();
|
|
1670
|
+
w.x + w.width <= a.x ? (!p || w.x > p.getVisualBoundingBox().x) && (p = m) : w.x >= a.x + a.width && (!g || w.x < g.getVisualBoundingBox().x) && (g = m);
|
|
1616
1671
|
}
|
|
1617
1672
|
const y = [];
|
|
1618
|
-
for (let
|
|
1619
|
-
const
|
|
1673
|
+
for (let m = 0; m < u.length - 1; m++) {
|
|
1674
|
+
const w = u[m].getVisualBoundingBox(), C = u[m + 1].getVisualBoundingBox().x - (w.x + w.width);
|
|
1620
1675
|
y.push(C);
|
|
1621
1676
|
}
|
|
1622
|
-
let
|
|
1623
|
-
if (
|
|
1624
|
-
const
|
|
1625
|
-
for (const
|
|
1626
|
-
if (Math.abs(
|
|
1627
|
-
|
|
1677
|
+
let S = null;
|
|
1678
|
+
if (p) {
|
|
1679
|
+
const m = p.getVisualBoundingBox(), w = a.x - (m.x + m.width);
|
|
1680
|
+
for (const T of y)
|
|
1681
|
+
if (Math.abs(w - T) <= n) {
|
|
1682
|
+
S = T;
|
|
1628
1683
|
break;
|
|
1629
1684
|
}
|
|
1630
1685
|
}
|
|
1631
|
-
if (!
|
|
1632
|
-
const
|
|
1633
|
-
for (const
|
|
1634
|
-
if (Math.abs(
|
|
1635
|
-
|
|
1686
|
+
if (!S && g) {
|
|
1687
|
+
const w = g.getVisualBoundingBox().x - (a.x + a.width);
|
|
1688
|
+
for (const T of y)
|
|
1689
|
+
if (Math.abs(w - T) <= n) {
|
|
1690
|
+
S = T;
|
|
1636
1691
|
break;
|
|
1637
1692
|
}
|
|
1638
1693
|
}
|
|
1639
|
-
if (
|
|
1640
|
-
if (
|
|
1641
|
-
const
|
|
1642
|
-
Math.abs(
|
|
1694
|
+
if (S !== null && S > 0) {
|
|
1695
|
+
if (p) {
|
|
1696
|
+
const m = p.getVisualBoundingBox(), w = a.x - (m.x + m.width);
|
|
1697
|
+
Math.abs(w - S) <= n && (h = m.x + m.width + S - r, d = !0);
|
|
1643
1698
|
}
|
|
1644
|
-
if (!d &&
|
|
1645
|
-
const
|
|
1646
|
-
Math.abs(
|
|
1699
|
+
if (!d && g) {
|
|
1700
|
+
const m = g.getVisualBoundingBox(), w = m.x - (a.x + a.width);
|
|
1701
|
+
Math.abs(w - S) <= n && (h = m.x - a.width - S - r, d = !0);
|
|
1647
1702
|
}
|
|
1648
1703
|
}
|
|
1649
1704
|
}
|
|
1650
|
-
return this.lastSnapTarget = d ||
|
|
1705
|
+
return this.lastSnapTarget = d || f ? { x: h, y: c } : null, { x: h, y: c };
|
|
1651
1706
|
}
|
|
1652
1707
|
/**
|
|
1653
1708
|
* Detect spacing between a moving element and other elements
|
|
@@ -1663,8 +1718,8 @@ class $e {
|
|
|
1663
1718
|
return this.clearIndicators(), [];
|
|
1664
1719
|
const s = t.getVisualBoundingBox(), i = [], a = [], r = [], l = [];
|
|
1665
1720
|
for (const c of n) {
|
|
1666
|
-
const d = c.getVisualBoundingBox(),
|
|
1667
|
-
|
|
1721
|
+
const d = c.getVisualBoundingBox(), f = s.x - (d.x + d.width), b = d.x - (s.x + s.width), u = s.y - (d.y + d.height), p = d.y - (s.y + s.height), g = !(s.y + s.height < d.y || s.y > d.y + d.height), y = !(s.x + s.width < d.x || s.x > d.x + d.width);
|
|
1722
|
+
f >= this.minDistance && f < this.detectionThreshold && g && i.push({ element: c, distance: f }), b >= this.minDistance && b < this.detectionThreshold && g && a.push({ element: c, distance: b }), u >= this.minDistance && u < this.detectionThreshold && y && r.push({ element: c, distance: u }), p >= this.minDistance && p < this.detectionThreshold && y && l.push({ element: c, distance: p });
|
|
1668
1723
|
}
|
|
1669
1724
|
i.sort((c, d) => c.distance - d.distance), a.sort((c, d) => c.distance - d.distance), r.sort((c, d) => c.distance - d.distance), l.sort((c, d) => c.distance - d.distance);
|
|
1670
1725
|
const h = [];
|
|
@@ -1723,28 +1778,28 @@ class $e {
|
|
|
1723
1778
|
// bottom
|
|
1724
1779
|
) > i)
|
|
1725
1780
|
continue;
|
|
1726
|
-
let d = 0,
|
|
1781
|
+
let d = 0, f = !1, b = 0, u = 0, p = 0;
|
|
1727
1782
|
const y = -30 * (a % 2 === 0 ? 1 : -1);
|
|
1728
|
-
h.x >= n.x + n.width ? (d = h.x - (n.x + n.width), d >= this.minDistance && (
|
|
1783
|
+
h.x >= n.x + n.width ? (d = h.x - (n.x + n.width), d >= this.minDistance && (f = !0, b = n.x + n.width, u = h.x, p = (n.y + n.height / 2 + h.y + h.height / 2) / 2 + y)) : n.x >= h.x + h.width && (d = n.x - (h.x + h.width), d >= this.minDistance && (f = !0, b = h.x + h.width, u = n.x, p = (n.y + n.height / 2 + h.y + h.height / 2) / 2 + y)), f && (o.push({
|
|
1729
1784
|
type: "horizontal",
|
|
1730
1785
|
distance: Math.round(d),
|
|
1731
|
-
x1:
|
|
1732
|
-
x2:
|
|
1733
|
-
y:
|
|
1734
|
-
labelX: (
|
|
1735
|
-
labelY:
|
|
1786
|
+
x1: b,
|
|
1787
|
+
x2: u,
|
|
1788
|
+
y: p,
|
|
1789
|
+
labelX: (b + u) / 2,
|
|
1790
|
+
labelY: p,
|
|
1736
1791
|
isAltHover: !0
|
|
1737
1792
|
}), a++);
|
|
1738
|
-
let
|
|
1793
|
+
let S = 0, m = !1, w = 0, T = 0, C = 0;
|
|
1739
1794
|
const x = 30 * (r % 2 === 0 ? 1 : -1);
|
|
1740
|
-
h.y >= n.y + n.height ? (
|
|
1795
|
+
h.y >= n.y + n.height ? (S = h.y - (n.y + n.height), S >= this.minDistance && (m = !0, w = (n.x + n.width / 2 + h.x + h.width / 2) / 2 + x, T = n.y + n.height, C = h.y)) : n.y >= h.y + h.height && (S = n.y - (h.y + h.height), S >= this.minDistance && (m = !0, w = (n.x + n.width / 2 + h.x + h.width / 2) / 2 + x, T = h.y + h.height, C = n.y)), m && (o.push({
|
|
1741
1796
|
type: "vertical",
|
|
1742
|
-
distance: Math.round(
|
|
1743
|
-
x:
|
|
1744
|
-
y1:
|
|
1797
|
+
distance: Math.round(S),
|
|
1798
|
+
x: w,
|
|
1799
|
+
y1: T,
|
|
1745
1800
|
y2: C,
|
|
1746
|
-
labelX:
|
|
1747
|
-
labelY: (
|
|
1801
|
+
labelX: w,
|
|
1802
|
+
labelY: (T + C) / 2,
|
|
1748
1803
|
isAltHover: !0
|
|
1749
1804
|
}), r++);
|
|
1750
1805
|
}
|
|
@@ -1757,84 +1812,84 @@ class $e {
|
|
|
1757
1812
|
detectConsistentSpacing(t, e, o, n, s) {
|
|
1758
1813
|
const i = [], r = o[0], l = r.distance, h = r.element.getVisualBoundingBox(), c = this.checkIfWouldSnap(e, l, n, s);
|
|
1759
1814
|
if (this.addIndicatorForDirection(i, e, h, l, n, c), n === "left" || n === "right") {
|
|
1760
|
-
const d = s.filter((
|
|
1761
|
-
if (
|
|
1762
|
-
const
|
|
1763
|
-
return !(e.y + e.height <
|
|
1815
|
+
const d = s.filter((f) => {
|
|
1816
|
+
if (f.id === t.id) return !1;
|
|
1817
|
+
const b = f.getVisualBoundingBox();
|
|
1818
|
+
return !(e.y + e.height < b.y || e.y > b.y + b.height);
|
|
1764
1819
|
});
|
|
1765
|
-
if (d.sort((
|
|
1766
|
-
const
|
|
1767
|
-
return
|
|
1820
|
+
if (d.sort((f, b) => {
|
|
1821
|
+
const u = f.getVisualBoundingBox(), p = b.getVisualBoundingBox();
|
|
1822
|
+
return u.x - p.x;
|
|
1768
1823
|
}), n === "left")
|
|
1769
|
-
for (let
|
|
1770
|
-
const
|
|
1824
|
+
for (let f = 0; f < d.length - 1; f++) {
|
|
1825
|
+
const b = d[f], u = d[f + 1], p = b.getVisualBoundingBox(), g = u.getVisualBoundingBox(), y = g.x - (p.x + p.width);
|
|
1771
1826
|
if (Math.abs(y - l) <= 16 && y >= this.minDistance) {
|
|
1772
|
-
const
|
|
1827
|
+
const S = Math.max(p.y, g.y), m = Math.min(p.y + p.height, g.y + g.height), w = (S + m) / 2;
|
|
1773
1828
|
i.push({
|
|
1774
1829
|
type: "horizontal",
|
|
1775
1830
|
distance: Math.round(y),
|
|
1776
|
-
x1:
|
|
1777
|
-
x2:
|
|
1778
|
-
y:
|
|
1779
|
-
labelX: (
|
|
1780
|
-
labelY:
|
|
1831
|
+
x1: p.x + p.width,
|
|
1832
|
+
x2: g.x,
|
|
1833
|
+
y: w,
|
|
1834
|
+
labelX: (p.x + p.width + g.x) / 2,
|
|
1835
|
+
labelY: w
|
|
1781
1836
|
});
|
|
1782
1837
|
}
|
|
1783
1838
|
}
|
|
1784
1839
|
else
|
|
1785
|
-
for (let
|
|
1786
|
-
const
|
|
1840
|
+
for (let f = 0; f < d.length - 1; f++) {
|
|
1841
|
+
const b = d[f], u = d[f + 1], p = b.getVisualBoundingBox(), g = u.getVisualBoundingBox(), y = g.x - (p.x + p.width);
|
|
1787
1842
|
if (Math.abs(y - l) <= 16 && y >= this.minDistance) {
|
|
1788
|
-
const
|
|
1843
|
+
const S = Math.max(p.y, g.y), m = Math.min(p.y + p.height, g.y + g.height), w = (S + m) / 2;
|
|
1789
1844
|
i.push({
|
|
1790
1845
|
type: "horizontal",
|
|
1791
1846
|
distance: Math.round(y),
|
|
1792
|
-
x1:
|
|
1793
|
-
x2:
|
|
1794
|
-
y:
|
|
1795
|
-
labelX: (
|
|
1796
|
-
labelY:
|
|
1847
|
+
x1: p.x + p.width,
|
|
1848
|
+
x2: g.x,
|
|
1849
|
+
y: w,
|
|
1850
|
+
labelX: (p.x + p.width + g.x) / 2,
|
|
1851
|
+
labelY: w
|
|
1797
1852
|
});
|
|
1798
1853
|
}
|
|
1799
1854
|
}
|
|
1800
1855
|
} else {
|
|
1801
|
-
const d = s.filter((
|
|
1802
|
-
if (
|
|
1803
|
-
const
|
|
1804
|
-
return !(e.x + e.width <
|
|
1856
|
+
const d = s.filter((f) => {
|
|
1857
|
+
if (f.id === t.id) return !1;
|
|
1858
|
+
const b = f.getVisualBoundingBox();
|
|
1859
|
+
return !(e.x + e.width < b.x || e.x > b.x + b.width);
|
|
1805
1860
|
});
|
|
1806
|
-
if (d.sort((
|
|
1807
|
-
const
|
|
1808
|
-
return
|
|
1861
|
+
if (d.sort((f, b) => {
|
|
1862
|
+
const u = f.getVisualBoundingBox(), p = b.getVisualBoundingBox();
|
|
1863
|
+
return u.y - p.y;
|
|
1809
1864
|
}), n === "top")
|
|
1810
|
-
for (let
|
|
1811
|
-
const
|
|
1865
|
+
for (let f = 0; f < d.length - 1; f++) {
|
|
1866
|
+
const b = d[f], u = d[f + 1], p = b.getVisualBoundingBox(), g = u.getVisualBoundingBox(), y = g.y - (p.y + p.height);
|
|
1812
1867
|
if (Math.abs(y - l) <= 16 && y >= this.minDistance) {
|
|
1813
|
-
const
|
|
1868
|
+
const S = Math.max(p.x, g.x), m = Math.min(p.x + p.width, g.x + g.width), w = (S + m) / 2;
|
|
1814
1869
|
i.push({
|
|
1815
1870
|
type: "vertical",
|
|
1816
1871
|
distance: Math.round(y),
|
|
1817
|
-
x:
|
|
1818
|
-
y1:
|
|
1819
|
-
y2:
|
|
1820
|
-
labelX:
|
|
1821
|
-
labelY: (
|
|
1872
|
+
x: w,
|
|
1873
|
+
y1: p.y + p.height,
|
|
1874
|
+
y2: g.y,
|
|
1875
|
+
labelX: w,
|
|
1876
|
+
labelY: (p.y + p.height + g.y) / 2
|
|
1822
1877
|
});
|
|
1823
1878
|
}
|
|
1824
1879
|
}
|
|
1825
1880
|
else
|
|
1826
|
-
for (let
|
|
1827
|
-
const
|
|
1881
|
+
for (let f = 0; f < d.length - 1; f++) {
|
|
1882
|
+
const b = d[f], u = d[f + 1], p = b.getVisualBoundingBox(), g = u.getVisualBoundingBox(), y = g.y - (p.y + p.height);
|
|
1828
1883
|
if (Math.abs(y - l) <= 16 && y >= this.minDistance) {
|
|
1829
|
-
const
|
|
1884
|
+
const S = Math.max(p.x, g.x), m = Math.min(p.x + p.width, g.x + g.width), w = (S + m) / 2;
|
|
1830
1885
|
i.push({
|
|
1831
1886
|
type: "vertical",
|
|
1832
1887
|
distance: Math.round(y),
|
|
1833
|
-
x:
|
|
1834
|
-
y1:
|
|
1835
|
-
y2:
|
|
1836
|
-
labelX:
|
|
1837
|
-
labelY: (
|
|
1888
|
+
x: w,
|
|
1889
|
+
y1: p.y + p.height,
|
|
1890
|
+
y2: g.y,
|
|
1891
|
+
labelX: w,
|
|
1892
|
+
labelY: (p.y + p.height + g.y) / 2
|
|
1838
1893
|
});
|
|
1839
1894
|
}
|
|
1840
1895
|
}
|
|
@@ -1845,7 +1900,7 @@ class $e {
|
|
|
1845
1900
|
* Check if spacing would snap to a pattern
|
|
1846
1901
|
*/
|
|
1847
1902
|
checkIfWouldSnap(t, e, o, n) {
|
|
1848
|
-
const s =
|
|
1903
|
+
const s = Yt;
|
|
1849
1904
|
if (o === "top" || o === "bottom") {
|
|
1850
1905
|
const i = n.filter((a) => {
|
|
1851
1906
|
const r = a.getVisualBoundingBox();
|
|
@@ -1945,7 +2000,7 @@ class $e {
|
|
|
1945
2000
|
}
|
|
1946
2001
|
}
|
|
1947
2002
|
}
|
|
1948
|
-
const
|
|
2003
|
+
const _t = Zt("ArtboardRenderer"), Xe = {
|
|
1949
2004
|
showLabel: !0,
|
|
1950
2005
|
showBorder: !0,
|
|
1951
2006
|
borderColor: "",
|
|
@@ -1963,9 +2018,9 @@ const Wt = $t("ArtboardRenderer"), We = {
|
|
|
1963
2018
|
borderRadius: 0
|
|
1964
2019
|
// Default to no border radius (sharp corners)
|
|
1965
2020
|
};
|
|
1966
|
-
class
|
|
2021
|
+
class ne {
|
|
1967
2022
|
constructor(t = {}) {
|
|
1968
|
-
this.options = { ...
|
|
2023
|
+
this.options = { ...Xe, ...t };
|
|
1969
2024
|
}
|
|
1970
2025
|
/**
|
|
1971
2026
|
* Render an artboard
|
|
@@ -1987,10 +2042,10 @@ class Jt {
|
|
|
1987
2042
|
* Renders preset color as base layer, then texture on top
|
|
1988
2043
|
*/
|
|
1989
2044
|
renderTextureBackground(t, e) {
|
|
1990
|
-
const o =
|
|
2045
|
+
const o = Wt.getTexture(e.backgroundTexture), n = Wt.getTexturePresetColor(e.backgroundTexture);
|
|
1991
2046
|
if (t.fillStyle = n, t.fillRect(e.x, e.y, e.width, e.height), !o || !o.complete) {
|
|
1992
|
-
|
|
1993
|
-
|
|
2047
|
+
Wt.loadTexture(e.backgroundTexture).catch((s) => {
|
|
2048
|
+
_t.error("Failed to load texture:", s);
|
|
1994
2049
|
});
|
|
1995
2050
|
return;
|
|
1996
2051
|
}
|
|
@@ -2011,7 +2066,7 @@ class Jt {
|
|
|
2011
2066
|
* Render artboard border (respects clipShape and borderRadius option)
|
|
2012
2067
|
*/
|
|
2013
2068
|
renderBorder(t, e, o) {
|
|
2014
|
-
const { x: n, y: s, width: i, height: a, clipShape: r } = e, l = this.options.borderColor ||
|
|
2069
|
+
const { x: n, y: s, width: i, height: a, clipShape: r } = e, l = this.options.borderColor || ce(), h = this.options.selectedBorderColor || nt();
|
|
2015
2070
|
if (t.strokeStyle = o ? h : l, t.lineWidth = o ? this.options.selectedBorderWidth : this.options.borderWidth, t.beginPath(), !r || r === "rectangle")
|
|
2016
2071
|
if (this.options.borderRadius > 0) {
|
|
2017
2072
|
const c = Math.min(this.options.borderRadius, Math.min(i, a) / 2);
|
|
@@ -2019,8 +2074,8 @@ class Jt {
|
|
|
2019
2074
|
} else
|
|
2020
2075
|
t.rect(n, s, i, a);
|
|
2021
2076
|
else if (r === "circle") {
|
|
2022
|
-
const c = n + i / 2, d = s + a / 2,
|
|
2023
|
-
t.arc(c, d,
|
|
2077
|
+
const c = n + i / 2, d = s + a / 2, f = Math.min(i, a) / 2;
|
|
2078
|
+
t.arc(c, d, f, 0, Math.PI * 2);
|
|
2024
2079
|
} else if (typeof r == "object" && r.type === "rounded") {
|
|
2025
2080
|
const c = Math.min(r.radius, Math.min(i, a) / 2);
|
|
2026
2081
|
this.roundedRect(t, n, s, i, a, c);
|
|
@@ -2030,7 +2085,7 @@ class Jt {
|
|
|
2030
2085
|
t.save(), t.translate(n, s), t.stroke(c), t.restore();
|
|
2031
2086
|
return;
|
|
2032
2087
|
} catch (c) {
|
|
2033
|
-
|
|
2088
|
+
_t.warn("Invalid SVG path for border, falling back to rectangle:", c), t.rect(n, s, i, a);
|
|
2034
2089
|
}
|
|
2035
2090
|
t.stroke();
|
|
2036
2091
|
}
|
|
@@ -2040,7 +2095,7 @@ class Jt {
|
|
|
2040
2095
|
renderLabel(t, e, o) {
|
|
2041
2096
|
const n = this.options.labelFontSize, s = this.options.labelPadding, i = `${e.name} (${Math.round(e.width)} × ${Math.round(e.height)})`, a = e.x, r = e.y - s;
|
|
2042
2097
|
t.font = `${n}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;
|
|
2043
|
-
const l = this.options.selectedBorderColor ||
|
|
2098
|
+
const l = this.options.selectedBorderColor || nt(), h = this.options.labelColor || de();
|
|
2044
2099
|
t.fillStyle = o ? l : h, t.textAlign = "left", t.textBaseline = "bottom", t.fillText(i, a, r);
|
|
2045
2100
|
}
|
|
2046
2101
|
/**
|
|
@@ -2084,7 +2139,7 @@ class Jt {
|
|
|
2084
2139
|
t.translate(o, n), t.clip(r), t.translate(-o, -n);
|
|
2085
2140
|
return;
|
|
2086
2141
|
} catch (r) {
|
|
2087
|
-
|
|
2142
|
+
_t.warn("Invalid SVG path, falling back to rectangle:", r), t.rect(o, n, s, i);
|
|
2088
2143
|
}
|
|
2089
2144
|
t.clip();
|
|
2090
2145
|
}
|
|
@@ -2143,7 +2198,7 @@ class Jt {
|
|
|
2143
2198
|
* Use this when exporting to ensure preview background is never included
|
|
2144
2199
|
*/
|
|
2145
2200
|
static createForExport(t = {}) {
|
|
2146
|
-
return new
|
|
2201
|
+
return new ne({
|
|
2147
2202
|
...t,
|
|
2148
2203
|
showPreviewBackground: !1
|
|
2149
2204
|
// CRITICAL: Never show preview in exports
|
|
@@ -2156,15 +2211,15 @@ class Jt {
|
|
|
2156
2211
|
return !!(this.options.showPreviewBackground && t.previewBackgroundColor && t.previewBackgroundColor !== "transparent");
|
|
2157
2212
|
}
|
|
2158
2213
|
}
|
|
2159
|
-
class
|
|
2214
|
+
class wt {
|
|
2160
2215
|
/**
|
|
2161
2216
|
* Render selection box layer
|
|
2162
2217
|
*/
|
|
2163
2218
|
static renderSelectionLayer(t, e, o, n = 1) {
|
|
2164
2219
|
if (!e || e.visible === !1 || o && o.getMode() === "drag" || "isGroup" in e && e.isGroup) return;
|
|
2165
2220
|
const i = e.getVisualBoundingBox(), a = e.getRotationAnchor();
|
|
2166
|
-
t.save(), t.strokeStyle =
|
|
2167
|
-
const r =
|
|
2221
|
+
t.save(), t.strokeStyle = nt(t.canvas), t.lineWidth = 2, t.translate(a.x * n, a.y * n), t.rotate(gt.toRadians(e.rotation)), t.translate(-a.x * n, -a.y * n);
|
|
2222
|
+
const r = ct.canvas.selectionPadding;
|
|
2168
2223
|
t.strokeRect(
|
|
2169
2224
|
(i.x - r) * n,
|
|
2170
2225
|
(i.y - r) * n,
|
|
@@ -2180,22 +2235,22 @@ class mt {
|
|
|
2180
2235
|
if (!e || !(o != null && o.rotationHandle) || (n == null ? void 0 : n.getMode()) !== "resize") return;
|
|
2181
2236
|
const i = e.getVisualBoundingBox(), a = Math.round(i.width), r = Math.round(i.height), l = `${a} × ${r}`, h = o.rotationHandle, c = h.x * s, d = h.y * s - 20;
|
|
2182
2237
|
t.save(), t.font = "10px system-ui, -apple-system, sans-serif";
|
|
2183
|
-
const
|
|
2184
|
-
t.shadowColor =
|
|
2185
|
-
c -
|
|
2186
|
-
d -
|
|
2187
|
-
p,
|
|
2238
|
+
const b = t.measureText(l).width + 12, u = 18;
|
|
2239
|
+
t.shadowColor = fe(t.canvas), t.shadowBlur = 4, t.shadowOffsetY = 1, t.fillStyle = ge(t.canvas), t.beginPath(), t.roundRect(
|
|
2240
|
+
c - b / 2,
|
|
2241
|
+
d - u / 2,
|
|
2188
2242
|
b,
|
|
2243
|
+
u,
|
|
2189
2244
|
3
|
|
2190
2245
|
// Smaller border radius
|
|
2191
|
-
), t.fill(), t.shadowColor = "transparent", t.shadowBlur = 0, t.shadowOffsetY = 0, t.fillStyle =
|
|
2246
|
+
), t.fill(), t.shadowColor = "transparent", t.shadowBlur = 0, t.shadowOffsetY = 0, t.fillStyle = ue(t.canvas), t.textAlign = "center", t.textBaseline = "middle", t.fillText(l, c, d + 0.5), t.restore();
|
|
2192
2247
|
}
|
|
2193
2248
|
/**
|
|
2194
2249
|
* Render transform handles layer
|
|
2195
2250
|
*/
|
|
2196
2251
|
static renderHandlesLayer(t, e, o, n, s, i, a, r = 1, l = !0) {
|
|
2197
2252
|
if (!e || e.visible === !1 || a.getMode() === "drag") return;
|
|
2198
|
-
const c = i.type === "rotation-handle", d = i.type === "resize-handle" ? i.data : null,
|
|
2253
|
+
const c = i.type === "rotation-handle", d = i.type === "resize-handle" ? i.data : null, f = a.getMode() === "resize", b = f ? a.getActiveHandle() : null;
|
|
2199
2254
|
o.render(
|
|
2200
2255
|
t,
|
|
2201
2256
|
l,
|
|
@@ -2203,15 +2258,15 @@ class mt {
|
|
|
2203
2258
|
s,
|
|
2204
2259
|
c,
|
|
2205
2260
|
d,
|
|
2206
|
-
|
|
2207
|
-
|
|
2261
|
+
f,
|
|
2262
|
+
b,
|
|
2208
2263
|
r,
|
|
2209
2264
|
!0
|
|
2210
2265
|
// Render rotation handle on canvas (not React)
|
|
2211
2266
|
);
|
|
2212
2267
|
}
|
|
2213
2268
|
}
|
|
2214
|
-
class
|
|
2269
|
+
class Vt {
|
|
2215
2270
|
/**
|
|
2216
2271
|
* Render hover highlights layer with fade-in animation
|
|
2217
2272
|
* Outlines the actual element shape instead of a rectangular border
|
|
@@ -2226,14 +2281,14 @@ class _t {
|
|
|
2226
2281
|
const c = performance.now() - e.startTime;
|
|
2227
2282
|
h = Math.min(c / r, 1) * l;
|
|
2228
2283
|
}
|
|
2229
|
-
t.strokeStyle =
|
|
2284
|
+
t.strokeStyle = pe(t.canvas), t.globalAlpha = h, t.lineWidth = 3, this.renderElementOutline(t, a, s, i), t.restore();
|
|
2230
2285
|
}
|
|
2231
2286
|
/**
|
|
2232
2287
|
* Render outline for a specific element type
|
|
2233
2288
|
*/
|
|
2234
2289
|
static renderElementOutline(t, e, o = 1, n) {
|
|
2235
2290
|
const s = e.getRotationAnchor();
|
|
2236
|
-
t.translate(s.x * o, s.y * o), t.rotate(
|
|
2291
|
+
t.translate(s.x * o, s.y * o), t.rotate(gt.toRadians(e.rotation)), t.translate(-s.x * o, -s.y * o), e.transformType === "shape" ? this.renderShapeOutline(t, e, o) : e.transformType === "image" ? this.renderImageOutline(t, e, o) : e.transformType === "group" ? this.renderGroupOutline(t, e, o) : this.renderTextOutline(t, e, o, n);
|
|
2237
2292
|
}
|
|
2238
2293
|
/**
|
|
2239
2294
|
* Render outline for shape elements (star, rectangle, circle, etc.)
|
|
@@ -2243,12 +2298,12 @@ class _t {
|
|
|
2243
2298
|
const n = e.transformData, s = n.width * o, i = n.height * o, a = 2, l = a + a / 2;
|
|
2244
2299
|
switch (t.save(), t.translate(e.x * o, e.y * o), t.beginPath(), n.shapeType) {
|
|
2245
2300
|
case "rectangle": {
|
|
2246
|
-
const h = n.borderRadius || 0, c = -(s + l * 2) / 2, d = -(i + l * 2) / 2,
|
|
2301
|
+
const h = n.borderRadius || 0, c = -(s + l * 2) / 2, d = -(i + l * 2) / 2, f = s + l * 2, b = i + l * 2;
|
|
2247
2302
|
if (h > 0) {
|
|
2248
|
-
const
|
|
2249
|
-
t.roundRect(c, d,
|
|
2303
|
+
const u = Math.min(h / 100 * Math.min(f, b), f / 2, b / 2);
|
|
2304
|
+
t.roundRect(c, d, f, b, u);
|
|
2250
2305
|
} else
|
|
2251
|
-
t.rect(c, d,
|
|
2306
|
+
t.rect(c, d, f, b);
|
|
2252
2307
|
break;
|
|
2253
2308
|
}
|
|
2254
2309
|
case "circle": {
|
|
@@ -2269,24 +2324,24 @@ class _t {
|
|
|
2269
2324
|
// bottom-right
|
|
2270
2325
|
{ x: -h, y: c }
|
|
2271
2326
|
// bottom-left
|
|
2272
|
-
],
|
|
2273
|
-
const
|
|
2274
|
-
return { x:
|
|
2275
|
-
}),
|
|
2276
|
-
const
|
|
2327
|
+
], f = d.map((u, p) => {
|
|
2328
|
+
const g = d[(p + 1) % 3], y = g.x - u.x, S = g.y - u.y, m = Math.sqrt(y * y + S * S);
|
|
2329
|
+
return { x: S / m, y: -y / m };
|
|
2330
|
+
}), b = d.map((u, p) => {
|
|
2331
|
+
const g = f[(p + 2) % 3], y = f[p], S = g.x + y.x, m = g.y + y.y, w = Math.sqrt(S * S + m * m), T = (S * g.x + m * g.y) / w, C = l / T;
|
|
2277
2332
|
return {
|
|
2278
|
-
x:
|
|
2279
|
-
y:
|
|
2333
|
+
x: u.x + S / w * C,
|
|
2334
|
+
y: u.y + m / w * C
|
|
2280
2335
|
};
|
|
2281
2336
|
});
|
|
2282
|
-
t.moveTo(
|
|
2337
|
+
t.moveTo(b[0].x, b[0].y), t.lineTo(b[1].x, b[1].y), t.lineTo(b[2].x, b[2].y), t.closePath();
|
|
2283
2338
|
break;
|
|
2284
2339
|
}
|
|
2285
2340
|
case "star": {
|
|
2286
|
-
const h = n.points ?? 5, c = n.innerRadius ?? 0.4, d = Math.min(s, i) / 2 + l,
|
|
2287
|
-
for (let
|
|
2288
|
-
const
|
|
2289
|
-
|
|
2341
|
+
const h = n.points ?? 5, c = n.innerRadius ?? 0.4, d = Math.min(s, i) / 2 + l, f = d * c;
|
|
2342
|
+
for (let b = 0; b < h * 2; b++) {
|
|
2343
|
+
const u = b * Math.PI / h - Math.PI / 2, p = b % 2 === 0 ? d : f, g = p * Math.cos(u), y = p * Math.sin(u);
|
|
2344
|
+
b === 0 ? t.moveTo(g, y) : t.lineTo(g, y);
|
|
2290
2345
|
}
|
|
2291
2346
|
t.closePath();
|
|
2292
2347
|
break;
|
|
@@ -2294,8 +2349,8 @@ class _t {
|
|
|
2294
2349
|
case "polygon": {
|
|
2295
2350
|
const h = n.sides ?? 5, c = Math.min(s, i) / 2 + l;
|
|
2296
2351
|
for (let d = 0; d < h; d++) {
|
|
2297
|
-
const
|
|
2298
|
-
d === 0 ? t.moveTo(
|
|
2352
|
+
const f = d * 2 * Math.PI / h - Math.PI / 2, b = c * Math.cos(f), u = c * Math.sin(f);
|
|
2353
|
+
d === 0 ? t.moveTo(b, u) : t.lineTo(b, u);
|
|
2299
2354
|
}
|
|
2300
2355
|
t.closePath();
|
|
2301
2356
|
break;
|
|
@@ -2313,15 +2368,15 @@ class _t {
|
|
|
2313
2368
|
* Creates a ring effect with a gap between the element and the stroke
|
|
2314
2369
|
*/
|
|
2315
2370
|
static renderImageOutline(t, e, o) {
|
|
2316
|
-
var
|
|
2317
|
-
const n = e.getVisualBoundingBox(), s = n.width * o, i = n.height * o, a = ((
|
|
2371
|
+
var u;
|
|
2372
|
+
const n = e.getVisualBoundingBox(), s = n.width * o, i = n.height * o, a = ((u = e.transformData) == null ? void 0 : u.borderRadius) || 0, r = 2, h = r + r / 2;
|
|
2318
2373
|
t.save(), t.translate(e.x * o, e.y * o);
|
|
2319
|
-
const c = -(s + h * 2) / 2, d = -(i + h * 2) / 2,
|
|
2374
|
+
const c = -(s + h * 2) / 2, d = -(i + h * 2) / 2, f = s + h * 2, b = i + h * 2;
|
|
2320
2375
|
if (t.beginPath(), a > 0) {
|
|
2321
|
-
const
|
|
2322
|
-
t.roundRect(c, d,
|
|
2376
|
+
const p = Math.min(a / 100 * Math.min(f, b), f / 2, b / 2);
|
|
2377
|
+
t.roundRect(c, d, f, b, p);
|
|
2323
2378
|
} else
|
|
2324
|
-
t.rect(c, d,
|
|
2379
|
+
t.rect(c, d, f, b);
|
|
2325
2380
|
t.stroke(), t.restore();
|
|
2326
2381
|
}
|
|
2327
2382
|
/**
|
|
@@ -2354,120 +2409,129 @@ class _t {
|
|
|
2354
2409
|
*/
|
|
2355
2410
|
static renderHoverRingEffect(t, e, o) {
|
|
2356
2411
|
t.save(), t.translate(e.x * o, e.y * o), o !== 1 && t.scale(o, o);
|
|
2357
|
-
const n = e.fontSize, s = e.fontFamily, i = e.bold || !1, a = e.italic || !1, r = e.textAlign || "center", l =
|
|
2358
|
-
|
|
2359
|
-
const
|
|
2360
|
-
if (!
|
|
2412
|
+
const n = e.fontSize, s = e.fontFamily, i = e.bold || !1, a = e.italic || !1, r = e.textAlign || "center", l = Jt(n, s, i, a), h = n * (e.lineHeight ?? 1.2), c = e.letterSpacing ?? 0, d = 4 / o, f = 4 / o, b = document.createElement("canvas");
|
|
2413
|
+
b.width = t.canvas.width, b.height = t.canvas.height;
|
|
2414
|
+
const u = b.getContext("2d");
|
|
2415
|
+
if (!u) {
|
|
2361
2416
|
t.restore();
|
|
2362
2417
|
return;
|
|
2363
2418
|
}
|
|
2364
|
-
|
|
2365
|
-
const
|
|
2366
|
-
if (
|
|
2367
|
-
const g =
|
|
2368
|
-
g.forEach((
|
|
2419
|
+
u.setTransform(t.getTransform()), u.textBaseline = "alphabetic", u.lineJoin = "round";
|
|
2420
|
+
const p = e.getRichText ? e.getRichText() : null;
|
|
2421
|
+
if (p) {
|
|
2422
|
+
const g = Qt(p), y = [], S = [];
|
|
2423
|
+
g.forEach((T) => {
|
|
2369
2424
|
if (e.transformType === "custom" && e.transformData) {
|
|
2370
|
-
const
|
|
2425
|
+
const C = e.transformData.width - pt * 2, R = te(T, C, {
|
|
2371
2426
|
fontSize: n,
|
|
2372
2427
|
fontFamily: s,
|
|
2373
2428
|
bold: i,
|
|
2374
|
-
italic: a
|
|
2429
|
+
italic: a,
|
|
2430
|
+
letterSpacing: e.letterSpacing
|
|
2375
2431
|
});
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
isParagraphStart:
|
|
2379
|
-
isParagraphEnd:
|
|
2432
|
+
R.forEach((x, H) => {
|
|
2433
|
+
y.push(x), S.push({
|
|
2434
|
+
isParagraphStart: H === 0,
|
|
2435
|
+
isParagraphEnd: H === R.length - 1
|
|
2380
2436
|
});
|
|
2381
2437
|
});
|
|
2382
2438
|
} else
|
|
2383
|
-
|
|
2439
|
+
y.push(T), S.push({
|
|
2384
2440
|
isParagraphStart: !0,
|
|
2385
2441
|
isParagraphEnd: !0
|
|
2386
2442
|
});
|
|
2387
2443
|
});
|
|
2388
2444
|
let m;
|
|
2389
|
-
|
|
2390
|
-
const
|
|
2391
|
-
|
|
2392
|
-
var
|
|
2393
|
-
const
|
|
2394
|
-
let
|
|
2395
|
-
const
|
|
2396
|
-
let
|
|
2397
|
-
|
|
2398
|
-
const
|
|
2445
|
+
y.length === 0 ? m = 0 : y.length === 1 ? m = l.height : m = (y.length - 1) * h + l.height;
|
|
2446
|
+
const w = -m / 2;
|
|
2447
|
+
y.forEach((T, C) => {
|
|
2448
|
+
var q, J;
|
|
2449
|
+
const R = S[C].isParagraphStart, x = S[C].isParagraphEnd;
|
|
2450
|
+
let H = 0;
|
|
2451
|
+
const M = T.map((E) => E.text).join(""), A = ((q = M.match(/^ +/)) == null ? void 0 : q[0].length) || 0, I = ((J = M.match(/ +$/)) == null ? void 0 : J[0].length) || 0;
|
|
2452
|
+
let L = 0;
|
|
2453
|
+
T.forEach((E) => {
|
|
2454
|
+
const z = E.style.fontSize !== void 0 ? E.style.fontSize : n, N = E.style.fontFamily !== void 0 ? E.style.fontFamily : s, Q = E.style.bold !== void 0 ? E.style.bold : i, B = E.style.italic !== void 0 ? E.style.italic : a;
|
|
2399
2455
|
let k = E.text;
|
|
2400
|
-
const
|
|
2401
|
-
if (!
|
|
2402
|
-
const
|
|
2403
|
-
k = k.substring(
|
|
2456
|
+
const O = L, G = L + E.text.length;
|
|
2457
|
+
if (!R && A > 0 && O < A) {
|
|
2458
|
+
const P = Math.min(A - O, E.text.length);
|
|
2459
|
+
k = k.substring(P);
|
|
2404
2460
|
}
|
|
2405
|
-
if (!
|
|
2406
|
-
const
|
|
2407
|
-
if (
|
|
2408
|
-
const
|
|
2409
|
-
k = k.substring(0,
|
|
2461
|
+
if (!x && I > 0) {
|
|
2462
|
+
const P = M.length - I;
|
|
2463
|
+
if (G > P) {
|
|
2464
|
+
const _ = !R && O < A ? Math.min(A - O, E.text.length) : 0, j = Math.max(0, P - O - _);
|
|
2465
|
+
k = k.substring(0, j);
|
|
2410
2466
|
}
|
|
2411
2467
|
}
|
|
2412
|
-
k.length > 0
|
|
2468
|
+
if (k.length > 0) {
|
|
2469
|
+
const P = E.style.letterSpacing !== void 0 ? E.style.letterSpacing : c;
|
|
2470
|
+
t.save(), t.font = Lt(z, N, Q, B), H += Gt(t.measureText(k).width, k, P), t.restore();
|
|
2471
|
+
}
|
|
2472
|
+
L += E.text.length;
|
|
2413
2473
|
});
|
|
2414
|
-
const
|
|
2415
|
-
let
|
|
2416
|
-
r === "center" ?
|
|
2417
|
-
const
|
|
2418
|
-
|
|
2419
|
-
const
|
|
2474
|
+
const D = e.transformType === "custom" && e.transformData ? e.transformData.width - pt * 2 : void 0;
|
|
2475
|
+
let F;
|
|
2476
|
+
r === "center" ? F = -H / 2 : r === "right" ? F = D !== void 0 ? D / 2 - H : -H : F = D !== void 0 ? -D / 2 : 0;
|
|
2477
|
+
const W = w + l.ascent + C * h;
|
|
2478
|
+
L = 0, T.forEach((E) => {
|
|
2479
|
+
const z = E.style.fontSize !== void 0 ? E.style.fontSize : n, N = E.style.fontFamily !== void 0 ? E.style.fontFamily : s;
|
|
2420
2480
|
E.style.color !== void 0 ? E.style.color : e.color;
|
|
2421
|
-
const
|
|
2481
|
+
const Q = E.style.bold !== void 0 ? E.style.bold : i, B = E.style.italic !== void 0 ? E.style.italic : a;
|
|
2422
2482
|
let k = E.text;
|
|
2423
|
-
const
|
|
2424
|
-
if (!
|
|
2425
|
-
const
|
|
2426
|
-
k = k.substring(
|
|
2483
|
+
const O = L, G = L + E.text.length;
|
|
2484
|
+
if (!R && A > 0 && O < A) {
|
|
2485
|
+
const P = Math.min(A - O, E.text.length);
|
|
2486
|
+
k = k.substring(P);
|
|
2427
2487
|
}
|
|
2428
|
-
if (!
|
|
2429
|
-
const
|
|
2430
|
-
if (
|
|
2431
|
-
const
|
|
2432
|
-
k = k.substring(0,
|
|
2488
|
+
if (!x && I > 0) {
|
|
2489
|
+
const P = M.length - I;
|
|
2490
|
+
if (G > P) {
|
|
2491
|
+
const _ = !R && O < A ? Math.min(A - O, E.text.length) : 0, j = Math.max(0, P - O - _);
|
|
2492
|
+
k = k.substring(0, j);
|
|
2433
2493
|
}
|
|
2434
2494
|
}
|
|
2435
|
-
|
|
2495
|
+
if (L += E.text.length, k.length > 0) {
|
|
2496
|
+
const P = E.style.letterSpacing !== void 0 ? E.style.letterSpacing : c;
|
|
2497
|
+
u.font = Lt(z, N, Q, B), u.textAlign = "left", u.globalCompositeOperation = "source-over", u.strokeStyle = t.strokeStyle, u.globalAlpha = Math.min(t.globalAlpha * 1.6, 0.8), u.lineWidth = (f + d) * 2, Pt(u, k, F, W, P), u.globalCompositeOperation = "destination-out", u.globalAlpha = 1, u.lineWidth = f * 2, Pt(u, k, F, W, P), Xt(u, k, F, W, P), F += Gt(u.measureText(k).width, k, P);
|
|
2498
|
+
}
|
|
2436
2499
|
});
|
|
2437
2500
|
});
|
|
2438
2501
|
} else {
|
|
2439
|
-
t.font =
|
|
2440
|
-
let g,
|
|
2502
|
+
t.font = Lt(n, s, i, a), u.font = t.font, u.textAlign = r;
|
|
2503
|
+
let g, y;
|
|
2441
2504
|
if (e.transformType === "custom" && e.transformData) {
|
|
2442
|
-
const
|
|
2505
|
+
const R = e.transformData.width - pt * 2, { lines: x } = ye(
|
|
2443
2506
|
e.text,
|
|
2444
|
-
|
|
2507
|
+
R,
|
|
2445
2508
|
n,
|
|
2446
2509
|
s,
|
|
2447
2510
|
i,
|
|
2448
2511
|
a,
|
|
2449
2512
|
void 0,
|
|
2450
|
-
!0
|
|
2513
|
+
!0,
|
|
2514
|
+
{ letterSpacing: c, lineHeight: e.lineHeight }
|
|
2451
2515
|
);
|
|
2452
|
-
g =
|
|
2516
|
+
g = x;
|
|
2453
2517
|
} else {
|
|
2454
2518
|
g = e.text.split(`
|
|
2455
2519
|
`);
|
|
2456
|
-
const
|
|
2520
|
+
const R = e.text.includes(`
|
|
2457
2521
|
`);
|
|
2458
|
-
g =
|
|
2522
|
+
g = xe(g, R);
|
|
2459
2523
|
}
|
|
2460
|
-
g.length === 0 ?
|
|
2461
|
-
const
|
|
2462
|
-
`),
|
|
2463
|
-
let
|
|
2464
|
-
r === "center" ?
|
|
2465
|
-
const
|
|
2466
|
-
let
|
|
2467
|
-
|
|
2524
|
+
g.length === 0 ? y = 0 : g.length === 1 ? y = l.height : y = (g.length - 1) * h + l.height;
|
|
2525
|
+
const S = -y / 2, m = e.text.includes(`
|
|
2526
|
+
`), w = e.transformType === "custom" && e.transformData ? e.transformData.width : 0, T = -w / 2;
|
|
2527
|
+
let C = T + pt;
|
|
2528
|
+
r === "center" ? C = T + w / 2 : r === "right" && (C = T + w - pt), g.forEach((R, x) => {
|
|
2529
|
+
const H = S + l.ascent + x * h, M = m || x === 0, A = m || x === g.length - 1;
|
|
2530
|
+
let I = R;
|
|
2531
|
+
M || (I = I.replace(/^ +/, "")), A || (I = I.replace(/ +$/, "")), u.globalCompositeOperation = "source-over", u.strokeStyle = t.strokeStyle, u.globalAlpha = Math.min(t.globalAlpha * 1.6, 0.8), u.lineWidth = (f + d) * 2, u.lineJoin = "round", Pt(u, I, C, H, c), u.globalCompositeOperation = "destination-out", u.globalAlpha = 1, u.lineWidth = f * 2, Pt(u, I, C, H, c), Xt(u, I, C, H, c);
|
|
2468
2532
|
});
|
|
2469
2533
|
}
|
|
2470
|
-
t.setTransform(1, 0, 0, 1, 0, 0), t.drawImage(
|
|
2534
|
+
t.setTransform(1, 0, 0, 1, 0, 0), t.drawImage(b, 0, 0), t.restore();
|
|
2471
2535
|
}
|
|
2472
2536
|
/**
|
|
2473
2537
|
* HOVER RING EFFECT for transformed text (circle, wave, arch, lean, ascend, flag)
|
|
@@ -2501,13 +2565,13 @@ class _t {
|
|
|
2501
2565
|
t.transform(1, 0, Math.tan(y), 1, 0, 0), t.globalCompositeOperation = "source-over", t.strokeStyle = s, t.globalAlpha = 0.8, t.lineWidth = (n + o) * 2, t.lineJoin = "round", t.strokeText(i.text, 0, 0), t.globalCompositeOperation = "destination-out", t.globalAlpha = 1, t.lineWidth = n * 2, t.strokeText(i.text, 0, 0), t.fillText(i.text, 0, 0);
|
|
2502
2566
|
return;
|
|
2503
2567
|
}
|
|
2504
|
-
const
|
|
2505
|
-
t.translate(
|
|
2568
|
+
const f = i.text.split(""), b = f.map((g) => t.measureText(g).width), u = this.calculateCharPositions(e, f, b), p = (g) => {
|
|
2569
|
+
t.translate(g.x, g.y), g.angle && t.rotate(g.angle), g.skewY && t.transform(1, g.skewY, 0, 1, 0, 0);
|
|
2506
2570
|
};
|
|
2507
|
-
t.globalCompositeOperation = "source-over", t.strokeStyle = s, t.globalAlpha = 0.8, t.lineWidth = (n + o) * 2, t.lineJoin = "round",
|
|
2508
|
-
t.save(), g
|
|
2509
|
-
}), t.globalCompositeOperation = "destination-out", t.globalAlpha = 1, t.lineWidth = n * 2,
|
|
2510
|
-
t.save(), g
|
|
2571
|
+
t.globalCompositeOperation = "source-over", t.strokeStyle = s, t.globalAlpha = 0.8, t.lineWidth = (n + o) * 2, t.lineJoin = "round", u.forEach((g, y) => {
|
|
2572
|
+
t.save(), p(g), t.strokeText(f[y], 0, 0), t.restore();
|
|
2573
|
+
}), t.globalCompositeOperation = "destination-out", t.globalAlpha = 1, t.lineWidth = n * 2, u.forEach((g, y) => {
|
|
2574
|
+
t.save(), p(g), t.strokeText(f[y], 0, 0), t.fillText(f[y], 0, 0), t.restore();
|
|
2511
2575
|
});
|
|
2512
2576
|
}
|
|
2513
2577
|
/**
|
|
@@ -2527,14 +2591,14 @@ class _t {
|
|
|
2527
2591
|
if (t.reverse) {
|
|
2528
2592
|
let a = Math.PI / 2 + s / (2 * i);
|
|
2529
2593
|
e.forEach((r, l) => {
|
|
2530
|
-
const c = o[l] / i, d = Math.cos(a - c / 2) * i,
|
|
2531
|
-
n.push({ x: d, y:
|
|
2594
|
+
const c = o[l] / i, d = Math.cos(a - c / 2) * i, f = Math.sin(a - c / 2) * i, b = a - c / 2 - Math.PI / 2;
|
|
2595
|
+
n.push({ x: d, y: f, angle: b }), a -= c;
|
|
2532
2596
|
});
|
|
2533
2597
|
} else {
|
|
2534
2598
|
let a = -Math.PI / 2 - s / (2 * i);
|
|
2535
2599
|
e.forEach((r, l) => {
|
|
2536
|
-
const c = o[l] / i, d = Math.cos(a + c / 2) * i,
|
|
2537
|
-
n.push({ x: d, y:
|
|
2600
|
+
const c = o[l] / i, d = Math.cos(a + c / 2) * i, f = Math.sin(a + c / 2) * i, b = a + c / 2 + Math.PI / 2;
|
|
2601
|
+
n.push({ x: d, y: f, angle: b }), a += c;
|
|
2538
2602
|
});
|
|
2539
2603
|
}
|
|
2540
2604
|
return n;
|
|
@@ -2546,8 +2610,8 @@ class _t {
|
|
|
2546
2610
|
const s = [];
|
|
2547
2611
|
let a = -o.reduce((r, l) => r + l, 0) / 2;
|
|
2548
2612
|
return e.forEach((r, l) => {
|
|
2549
|
-
const h = o[l], c = a + h / 2, d = c / (n.width / 2),
|
|
2550
|
-
s.push({ x: c, y:
|
|
2613
|
+
const h = o[l], c = a + h / 2, d = c / (n.width / 2), f = n.amplitude * t.fontSize * Math.sin(n.frequency * Math.PI * d), b = n.amplitude * n.frequency * Math.PI * Math.cos(n.frequency * Math.PI * d);
|
|
2614
|
+
s.push({ x: c, y: f, angle: 0, skewY: b * be }), a += h;
|
|
2551
2615
|
}), s;
|
|
2552
2616
|
}
|
|
2553
2617
|
/**
|
|
@@ -2557,8 +2621,8 @@ class _t {
|
|
|
2557
2621
|
const s = [], i = o.reduce((l, h) => l + h, 0), a = n.width / 2;
|
|
2558
2622
|
let r = -i / 2;
|
|
2559
2623
|
return e.forEach((l, h) => {
|
|
2560
|
-
const c = o[h], d = r + c / 2,
|
|
2561
|
-
s.push({ x: d, y:
|
|
2624
|
+
const c = o[h], d = r + c / 2, f = d / a, b = (Math.pow(f, 2) - 1) * n.archHeight * t.fontSize, u = 2 * f * n.archHeight;
|
|
2625
|
+
s.push({ x: d, y: b, angle: 0, skewY: u * 0.3 }), r += c;
|
|
2562
2626
|
}), s;
|
|
2563
2627
|
}
|
|
2564
2628
|
/**
|
|
@@ -2579,8 +2643,8 @@ class _t {
|
|
|
2579
2643
|
const s = [], i = o.reduce((h, c) => h + c, 0), a = n.ascendAngle * Math.PI / 180, r = Math.tan(a);
|
|
2580
2644
|
let l = -i / 2;
|
|
2581
2645
|
return e.forEach((h, c) => {
|
|
2582
|
-
const d = o[c],
|
|
2583
|
-
s.push({ x:
|
|
2646
|
+
const d = o[c], f = l + d / 2, b = f * r;
|
|
2647
|
+
s.push({ x: f, y: b, angle: 0, skewY: r * 1 }), l += d;
|
|
2584
2648
|
}), s;
|
|
2585
2649
|
}
|
|
2586
2650
|
/**
|
|
@@ -2590,8 +2654,8 @@ class _t {
|
|
|
2590
2654
|
const s = [];
|
|
2591
2655
|
let a = -o.reduce((r, l) => r + l, 0) / 2;
|
|
2592
2656
|
return e.forEach((r, l) => {
|
|
2593
|
-
const h = o[l], c = a + h / 2, d = c / (n.width / 2),
|
|
2594
|
-
s.push({ x: c, y:
|
|
2657
|
+
const h = o[l], c = a + h / 2, d = c / (n.width / 2), f = Math.abs(d), b = n.amplitude * f, u = b * t.fontSize * Math.sin(n.frequency * Math.PI * d), p = b * n.frequency * Math.PI * Math.cos(n.frequency * Math.PI * d), g = n.amplitude * Math.sign(d) * Math.sin(n.frequency * Math.PI * d), y = p + g;
|
|
2658
|
+
s.push({ x: c, y: u, angle: 0, skewY: y * 0.3 }), a += h;
|
|
2595
2659
|
}), s;
|
|
2596
2660
|
}
|
|
2597
2661
|
}
|
|
@@ -2600,7 +2664,7 @@ class Ct {
|
|
|
2600
2664
|
* Render snap guides layer
|
|
2601
2665
|
*/
|
|
2602
2666
|
static renderSnapGuidesLayer(t, e = []) {
|
|
2603
|
-
e.length !== 0 && (t.save(), t.strokeStyle =
|
|
2667
|
+
e.length !== 0 && (t.save(), t.strokeStyle = nt(t.canvas), t.lineWidth = ct.canvas.snapGuideWidth, t.setLineDash(ct.canvas.snapGuideDash), e.forEach((o) => {
|
|
2604
2668
|
t.beginPath(), o.type === "vertical" ? (t.moveTo(o.x ?? 0, o.y1 ?? 0), t.lineTo(o.x ?? 0, o.y2 ?? 0)) : o.type === "horizontal" ? (t.moveTo(o.x1 ?? 0, o.y ?? 0), t.lineTo(o.x2 ?? 0, o.y ?? 0)) : (t.moveTo(o.x1 ?? 0, o.y1 ?? 0), t.lineTo(o.x2 ?? 0, o.y2 ?? 0)), t.stroke();
|
|
2605
2669
|
}), t.restore());
|
|
2606
2670
|
}
|
|
@@ -2609,8 +2673,8 @@ class Ct {
|
|
|
2609
2673
|
*/
|
|
2610
2674
|
static renderSpacingIndicatorsLayer(t, e = []) {
|
|
2611
2675
|
e.length !== 0 && (t.save(), t.setLineDash([]), e.forEach((o) => {
|
|
2612
|
-
const n =
|
|
2613
|
-
if (t.strokeStyle = n, t.fillStyle = n, t.lineWidth =
|
|
2676
|
+
const n = Nt(t.canvas);
|
|
2677
|
+
if (t.strokeStyle = n, t.fillStyle = n, t.lineWidth = ct.canvas.spacingIndicatorWidth, t.beginPath(), o.type === "horizontal") {
|
|
2614
2678
|
const s = o.x1 ?? 0, i = o.x2 ?? 0, a = o.y ?? 0;
|
|
2615
2679
|
t.moveTo(s, a), t.lineTo(i, a), t.stroke();
|
|
2616
2680
|
const r = 6;
|
|
@@ -2632,197 +2696,200 @@ class Ct {
|
|
|
2632
2696
|
*/
|
|
2633
2697
|
static renderDistanceLabel(t, e, o, n) {
|
|
2634
2698
|
const s = `${n}`;
|
|
2635
|
-
t.font = `600 ${
|
|
2636
|
-
const a = t.measureText(s).width, r =
|
|
2637
|
-
t.fillStyle =
|
|
2699
|
+
t.font = `600 ${ct.canvas.spacingLabelFontSize}px ${ct.canvas.spacingLabelFontFamily}`;
|
|
2700
|
+
const a = t.measureText(s).width, r = ct.canvas.spacingLabelFontSize, l = 4, h = a + l * 2, c = r + l * 2;
|
|
2701
|
+
t.fillStyle = Nt(t.canvas), t.beginPath(), t.roundRect(e - h / 2, o - c / 2, h, c, Se), t.fill(), t.fillStyle = me, t.textAlign = "center", t.textBaseline = "middle", t.fillText(s, e, o);
|
|
2638
2702
|
}
|
|
2639
2703
|
}
|
|
2640
|
-
class
|
|
2704
|
+
class zt {
|
|
2641
2705
|
/**
|
|
2642
2706
|
* Render edit mode features: cursor and text selection highlight
|
|
2643
2707
|
* This renders on the main canvas at world coordinates (same as the element)
|
|
2644
2708
|
*/
|
|
2645
2709
|
static renderEditModeLayer(t, e, o, n) {
|
|
2646
2710
|
if (!e || e.transformType === "image" || e.transformType === "group") return;
|
|
2647
|
-
const s = e, { cursorPosition: i, selectionStart: a, selectionEnd: r, editText: l, editRichText: h, cursorOpacity: c, isTouchDevice: d, selectionHandlePositionsRef:
|
|
2648
|
-
if (
|
|
2649
|
-
this.renderTransformEditModeLayer(t, s, o,
|
|
2711
|
+
const s = e, { cursorPosition: i, selectionStart: a, selectionEnd: r, editText: l, editRichText: h, cursorOpacity: c, isTouchDevice: d, selectionHandlePositionsRef: f } = o, b = n || 1, u = s.transformType;
|
|
2712
|
+
if (u === "circle" || u === "wave" || u === "arch" || u === "lean" || u === "ascend" || u === "flag") {
|
|
2713
|
+
this.renderTransformEditModeLayer(t, s, o, b);
|
|
2650
2714
|
return;
|
|
2651
2715
|
}
|
|
2652
|
-
const
|
|
2716
|
+
const p = s.fontSize || 24, g = s.fontFamily || "Arial", y = s.bold || !1, S = s.italic || !1, m = s.underline || !1, w = s.strikethrough || !1, T = s.textAlign || "center", C = s.letterSpacing ?? 0;
|
|
2653
2717
|
t.save(), t.translate(s.x, s.y), t.rotate(-s.rotation * Math.PI / 180);
|
|
2654
|
-
const
|
|
2655
|
-
let
|
|
2718
|
+
const R = Jt(p, g, y, S), x = R.height, H = p * (s.lineHeight ?? 1.2);
|
|
2719
|
+
let M, A, I;
|
|
2656
2720
|
if (h && s.transformType === "custom" && s.transformData.width) {
|
|
2657
|
-
const
|
|
2658
|
-
|
|
2659
|
-
const k =
|
|
2660
|
-
|
|
2661
|
-
const
|
|
2721
|
+
const B = s.transformData.width - pt * 2;
|
|
2722
|
+
I = B;
|
|
2723
|
+
const k = Qt(h);
|
|
2724
|
+
M = [], A = [], k.forEach((O) => {
|
|
2725
|
+
const G = te(O, B, {
|
|
2662
2726
|
fontSize: s.fontSize,
|
|
2663
2727
|
fontFamily: s.fontFamily,
|
|
2664
2728
|
bold: s.bold,
|
|
2665
|
-
italic: s.italic
|
|
2729
|
+
italic: s.italic,
|
|
2730
|
+
letterSpacing: s.letterSpacing
|
|
2666
2731
|
});
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
isParagraphStart:
|
|
2670
|
-
isParagraphEnd:
|
|
2732
|
+
G.forEach((P, _) => {
|
|
2733
|
+
M.push(P), A.push({
|
|
2734
|
+
isParagraphStart: _ === 0,
|
|
2735
|
+
isParagraphEnd: _ === G.length - 1
|
|
2671
2736
|
});
|
|
2672
2737
|
});
|
|
2673
2738
|
});
|
|
2674
2739
|
} else
|
|
2675
|
-
|
|
2740
|
+
M = l.split(`
|
|
2676
2741
|
`).map((k) => [
|
|
2677
2742
|
{
|
|
2678
2743
|
text: k,
|
|
2679
|
-
style: { fontSize:
|
|
2744
|
+
style: { fontSize: p, fontFamily: g, bold: y, italic: S }
|
|
2680
2745
|
}
|
|
2681
|
-
]),
|
|
2746
|
+
]), A = M.map(() => ({
|
|
2682
2747
|
isParagraphStart: !0,
|
|
2683
2748
|
// Each line is its own paragraph
|
|
2684
2749
|
isParagraphEnd: !0
|
|
2685
2750
|
}));
|
|
2686
|
-
const
|
|
2687
|
-
let
|
|
2688
|
-
const
|
|
2751
|
+
const L = M.length > 1 ? R.height + (M.length - 1) * H : R.height;
|
|
2752
|
+
let D = -L / 2, F = 0, W = D, q = x;
|
|
2753
|
+
const J = [];
|
|
2689
2754
|
let E = 0;
|
|
2690
|
-
|
|
2691
|
-
var
|
|
2692
|
-
const
|
|
2693
|
-
|
|
2694
|
-
Array.from(
|
|
2695
|
-
let
|
|
2755
|
+
M.forEach((B, k) => {
|
|
2756
|
+
var _, j;
|
|
2757
|
+
const O = A[k].isParagraphStart, G = A[k].isParagraphEnd, P = [];
|
|
2758
|
+
B.forEach((ot) => {
|
|
2759
|
+
Array.from(ot.text).forEach((lt) => {
|
|
2760
|
+
let Y = p, ht = g, it = y, U = S, st = C;
|
|
2696
2761
|
if (h && E < l.length) {
|
|
2697
2762
|
const Z = h.getStyleAt(E);
|
|
2698
|
-
|
|
2763
|
+
Y = Z.fontSize || p, ht = Z.fontFamily || g, it = Z.bold !== void 0 ? Z.bold : y, U = Z.italic !== void 0 ? Z.italic : S, st = Z.letterSpacing !== void 0 ? Z.letterSpacing : C;
|
|
2699
2764
|
}
|
|
2700
2765
|
t.save();
|
|
2701
|
-
const
|
|
2702
|
-
t.font = `${
|
|
2703
|
-
const
|
|
2704
|
-
t.restore(),
|
|
2766
|
+
const V = it ? "bold" : "normal", $ = U ? "italic" : "normal";
|
|
2767
|
+
t.font = `${$} ${V} ${Y}px "${ht}", Arial, sans-serif`;
|
|
2768
|
+
const at = t.measureText(lt).width + st;
|
|
2769
|
+
t.restore(), P.push({ char: lt, width: at, fontSize: Y, index: E }), E++;
|
|
2705
2770
|
});
|
|
2706
2771
|
});
|
|
2707
2772
|
{
|
|
2708
|
-
const
|
|
2709
|
-
let
|
|
2710
|
-
for (let
|
|
2711
|
-
!
|
|
2773
|
+
const ot = k === 0, et = k === M.length - 1, lt = P.map((V) => V.char).join(""), Y = ((_ = lt.match(/^ +/)) == null ? void 0 : _[0].length) || 0, ht = ((j = lt.match(/ +$/)) == null ? void 0 : j[0].length) || 0;
|
|
2774
|
+
let it = 0;
|
|
2775
|
+
for (let V = 0; V < P.length; V++)
|
|
2776
|
+
!ot && V < Y || !et && V >= P.length - ht || (it += P[V].width);
|
|
2712
2777
|
let U;
|
|
2713
|
-
|
|
2714
|
-
let
|
|
2715
|
-
for (let
|
|
2716
|
-
const
|
|
2717
|
-
|
|
2718
|
-
x:
|
|
2719
|
-
y:
|
|
2720
|
-
width:
|
|
2778
|
+
T === "center" ? U = -it / 2 : T === "right" ? U = I !== void 0 ? I / 2 - it : -it : U = I !== void 0 ? -I / 2 : 0;
|
|
2779
|
+
let st = U;
|
|
2780
|
+
for (let V = 0; V < P.length; V++) {
|
|
2781
|
+
const $ = P[V];
|
|
2782
|
+
J[$.index] = {
|
|
2783
|
+
x: st,
|
|
2784
|
+
y: D,
|
|
2785
|
+
width: $.width,
|
|
2721
2786
|
// All characters keep their width for cursor navigation
|
|
2722
|
-
height:
|
|
2723
|
-
},
|
|
2787
|
+
height: $.fontSize
|
|
2788
|
+
}, st += $.width;
|
|
2724
2789
|
}
|
|
2725
|
-
if (
|
|
2726
|
-
const
|
|
2727
|
-
if (i >=
|
|
2728
|
-
if (i ===
|
|
2729
|
-
|
|
2790
|
+
if (P.length > 0) {
|
|
2791
|
+
const V = P[0].index, $ = P[P.length - 1].index, ut = k < M.length - 1 && $ + 1 === E ? $ : $ + 1;
|
|
2792
|
+
if (i >= V && i <= ut)
|
|
2793
|
+
if (i === V)
|
|
2794
|
+
F = U, W = D, q = x;
|
|
2730
2795
|
else {
|
|
2731
|
-
let
|
|
2732
|
-
for (let
|
|
2733
|
-
const
|
|
2734
|
-
let
|
|
2735
|
-
if (
|
|
2736
|
-
const
|
|
2737
|
-
|
|
2796
|
+
let yt = 0;
|
|
2797
|
+
for (let rt = 0; rt < P.length && P[rt].index < i; rt++) {
|
|
2798
|
+
const dt = P[rt], bt = dt.char === " ";
|
|
2799
|
+
let St = !0;
|
|
2800
|
+
if (bt) {
|
|
2801
|
+
const kt = rt < Y, X = rt >= P.length - ht, vt = !O && Y > 0, Mt = !G && ht > 0;
|
|
2802
|
+
St = !(kt && vt || X && Mt);
|
|
2738
2803
|
}
|
|
2739
|
-
|
|
2804
|
+
St && (yt += dt.width);
|
|
2740
2805
|
}
|
|
2741
|
-
|
|
2806
|
+
F = U + yt, W = D, q = x;
|
|
2742
2807
|
}
|
|
2743
2808
|
}
|
|
2744
|
-
k <
|
|
2809
|
+
k < M.length - 1 && (D += H);
|
|
2745
2810
|
}
|
|
2746
2811
|
});
|
|
2747
|
-
const
|
|
2748
|
-
let
|
|
2749
|
-
if (
|
|
2750
|
-
const
|
|
2751
|
-
t.save(), t.fillStyle =
|
|
2752
|
-
let
|
|
2753
|
-
if (
|
|
2754
|
-
var
|
|
2755
|
-
const
|
|
2756
|
-
if (
|
|
2757
|
-
Array.from(U.text).forEach((
|
|
2758
|
-
const
|
|
2812
|
+
const z = a !== r;
|
|
2813
|
+
let N = null, Q = null;
|
|
2814
|
+
if (z) {
|
|
2815
|
+
const B = Math.min(a, r), k = Math.max(a, r);
|
|
2816
|
+
t.save(), t.fillStyle = Te(t.canvas);
|
|
2817
|
+
let O = 0, G = -L / 2;
|
|
2818
|
+
if (M.forEach((P, _) => {
|
|
2819
|
+
var ht, it;
|
|
2820
|
+
const j = A[_].isParagraphStart, ot = A[_].isParagraphEnd, et = _ === 0, lt = _ === M.length - 1, Y = [];
|
|
2821
|
+
if (P.forEach((U) => {
|
|
2822
|
+
Array.from(U.text).forEach((st) => {
|
|
2823
|
+
const V = U.style || {}, $ = V.fontSize !== void 0 ? V.fontSize : p, at = V.fontFamily !== void 0 ? V.fontFamily : g, Z = V.bold !== void 0 ? V.bold : y, ut = V.italic !== void 0 ? V.italic : S, yt = V.letterSpacing !== void 0 ? V.letterSpacing : C;
|
|
2759
2824
|
t.save();
|
|
2760
|
-
const
|
|
2761
|
-
t.font = `${
|
|
2762
|
-
const
|
|
2763
|
-
t.restore(),
|
|
2825
|
+
const rt = Z ? "bold" : "normal", dt = ut ? "italic" : "normal";
|
|
2826
|
+
t.font = `${dt} ${rt} ${$}px "${at}", Arial, sans-serif`;
|
|
2827
|
+
const bt = t.measureText(st).width + yt;
|
|
2828
|
+
t.restore(), Y.push({ char: st, index: O, width: bt, style: V }), O++;
|
|
2764
2829
|
});
|
|
2765
|
-
}),
|
|
2766
|
-
const U =
|
|
2767
|
-
if (k > U &&
|
|
2830
|
+
}), Y.length > 0) {
|
|
2831
|
+
const U = Y[0].index, st = Y[Y.length - 1].index;
|
|
2832
|
+
if (k > U && B <= st) {
|
|
2768
2833
|
t.save();
|
|
2769
|
-
const
|
|
2834
|
+
const V = Y.map((X) => X.char).join(""), $ = ((ht = V.match(/^ +/)) == null ? void 0 : ht[0].length) || 0, at = ((it = V.match(/ +$/)) == null ? void 0 : it[0].length) || 0;
|
|
2835
|
+
let Z = 0;
|
|
2836
|
+
for (let X = 0; X < Y.length; X++)
|
|
2837
|
+
!et && X < $ || !lt && X >= Y.length - at || (Z += Y[X].width);
|
|
2770
2838
|
let ut = 0;
|
|
2771
|
-
|
|
2772
|
-
|
|
2839
|
+
T === "center" ? ut = -Z / 2 : T === "right" && (ut = -Z);
|
|
2840
|
+
const yt = Math.max(B, U), rt = Math.min(k, st + 1);
|
|
2773
2841
|
let dt = 0;
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
for (let N = 0; N < G.length && G[N].index < pt; N++) {
|
|
2778
|
-
const Tt = G[N], vt = N < q, At = N >= G.length - Z, Et = !Y && q > 0, It = !at && Z > 0;
|
|
2779
|
-
!(vt && Et || At && It) && (rt += Tt.width);
|
|
2842
|
+
for (let X = 0; X < Y.length && Y[X].index < yt; X++) {
|
|
2843
|
+
const vt = Y[X], Mt = X < $, Ht = X >= Y.length - at, It = !j && $ > 0, Bt = !ot && at > 0;
|
|
2844
|
+
!(Mt && It || Ht && Bt) && (dt += vt.width);
|
|
2780
2845
|
}
|
|
2781
|
-
let
|
|
2782
|
-
for (let
|
|
2783
|
-
const
|
|
2784
|
-
!(
|
|
2846
|
+
let bt = 0;
|
|
2847
|
+
for (let X = 0; X < Y.length && Y[X].index < rt; X++) {
|
|
2848
|
+
const vt = Y[X], Mt = X < $, Ht = X >= Y.length - at, It = !j && $ > 0, Bt = !ot && at > 0;
|
|
2849
|
+
!(Mt && It || Ht && Bt) && (bt += vt.width);
|
|
2785
2850
|
}
|
|
2786
|
-
const
|
|
2787
|
-
t.fillRect(
|
|
2851
|
+
const St = ut + dt, kt = bt - dt;
|
|
2852
|
+
t.fillRect(St, G, kt, x), N === null && (N = { x: St, y: G }), Q = { x: St + kt, y: G + x }, t.restore();
|
|
2788
2853
|
}
|
|
2789
2854
|
}
|
|
2790
|
-
|
|
2855
|
+
_ < M.length - 1 && (G += H);
|
|
2791
2856
|
}), t.restore(), h) {
|
|
2792
2857
|
t.save();
|
|
2793
|
-
const
|
|
2794
|
-
|
|
2795
|
-
fontSize:
|
|
2796
|
-
fontFamily:
|
|
2858
|
+
const P = s.transformType === "custom" ? s.transformData : null, _ = P != null && P.width ? P.width - pt * 2 : void 0;
|
|
2859
|
+
Ce(t, h, {
|
|
2860
|
+
fontSize: p,
|
|
2861
|
+
fontFamily: g,
|
|
2797
2862
|
color: s.color || "#000000",
|
|
2798
2863
|
bold: y,
|
|
2799
|
-
italic:
|
|
2800
|
-
underline:
|
|
2801
|
-
strikethrough:
|
|
2802
|
-
textAlign:
|
|
2803
|
-
|
|
2864
|
+
italic: S,
|
|
2865
|
+
underline: m,
|
|
2866
|
+
strikethrough: w,
|
|
2867
|
+
textAlign: T,
|
|
2868
|
+
letterSpacing: s.letterSpacing,
|
|
2869
|
+
lineHeight: s.lineHeight
|
|
2870
|
+
}, _), t.restore();
|
|
2804
2871
|
}
|
|
2805
2872
|
}
|
|
2806
|
-
if (
|
|
2807
|
-
const
|
|
2873
|
+
if (z && d && N && Q) {
|
|
2874
|
+
const B = N, k = Q, O = 6 / b, G = 2 / b;
|
|
2808
2875
|
t.save();
|
|
2809
|
-
const
|
|
2810
|
-
t.fillStyle =
|
|
2811
|
-
const
|
|
2812
|
-
t.beginPath(), t.moveTo(
|
|
2876
|
+
const P = nt(t.canvas);
|
|
2877
|
+
t.fillStyle = P, t.strokeStyle = P, t.lineWidth = G, t.lineCap = "round";
|
|
2878
|
+
const _ = { x: B.x, y: B.y - O }, j = { x: k.x, y: k.y + O };
|
|
2879
|
+
t.beginPath(), t.moveTo(B.x, B.y), t.lineTo(B.x, B.y + x), t.stroke(), t.beginPath(), t.arc(_.x, _.y, O, 0, Math.PI * 2), t.fill(), t.strokeStyle = "white", t.lineWidth = 2 / b, t.stroke(), t.strokeStyle = P, t.lineWidth = G, t.beginPath(), t.moveTo(k.x, k.y - x), t.lineTo(k.x, k.y), t.stroke(), t.beginPath(), t.arc(j.x, j.y, O, 0, Math.PI * 2), t.fill(), t.strokeStyle = "white", t.lineWidth = 2 / b, t.stroke(), t.restore(), f && (f.current = {
|
|
2813
2880
|
start: {
|
|
2814
|
-
center:
|
|
2815
|
-
textEdge:
|
|
2881
|
+
center: _,
|
|
2882
|
+
textEdge: B
|
|
2816
2883
|
// Original selection edge (top-left of selection on first line)
|
|
2817
2884
|
},
|
|
2818
2885
|
end: {
|
|
2819
|
-
center:
|
|
2886
|
+
center: j,
|
|
2820
2887
|
textEdge: k
|
|
2821
2888
|
// Original selection edge (bottom-right of selection on last line)
|
|
2822
2889
|
}
|
|
2823
2890
|
});
|
|
2824
|
-
} else
|
|
2825
|
-
|
|
2891
|
+
} else f && (f.current = { start: null, end: null });
|
|
2892
|
+
!z && c > 0 && (t.save(), t.globalAlpha = c, t.strokeStyle = nt(t.canvas), t.lineWidth = 3 / b, t.lineCap = "round", t.beginPath(), t.moveTo(F, W), t.lineTo(F, W + q), t.stroke(), t.restore()), t.restore();
|
|
2826
2893
|
}
|
|
2827
2894
|
/**
|
|
2828
2895
|
* Render edit mode features for transformed text (circle, wave, arch, etc.)
|
|
@@ -2833,37 +2900,37 @@ class Dt {
|
|
|
2833
2900
|
t.save(), t.translate(e.x, e.y), t.rotate(-e.rotation * Math.PI / 180);
|
|
2834
2901
|
const c = l ? "bold" : "normal", d = h ? "italic" : "normal";
|
|
2835
2902
|
t.font = `${d} ${c} ${a}px ${r}`;
|
|
2836
|
-
const
|
|
2837
|
-
if (s >= 0 && s <=
|
|
2838
|
-
let
|
|
2903
|
+
const f = Array.from(e.text), b = f.map((p) => t.measureText(p).width), u = Vt.calculateCharPositions(e, f, b);
|
|
2904
|
+
if (s >= 0 && s <= f.length && i > 0) {
|
|
2905
|
+
let p;
|
|
2839
2906
|
if (s === 0)
|
|
2840
|
-
if (
|
|
2841
|
-
const y =
|
|
2842
|
-
|
|
2843
|
-
x: y.x - Math.cos(y.angle) * (
|
|
2844
|
-
y: y.y - Math.sin(y.angle) * (
|
|
2907
|
+
if (u.length > 0) {
|
|
2908
|
+
const y = u[0], S = b[0];
|
|
2909
|
+
p = {
|
|
2910
|
+
x: y.x - Math.cos(y.angle) * (S / 2),
|
|
2911
|
+
y: y.y - Math.sin(y.angle) * (S / 2),
|
|
2845
2912
|
angle: y.angle
|
|
2846
2913
|
};
|
|
2847
2914
|
} else
|
|
2848
|
-
|
|
2849
|
-
else if (s >=
|
|
2850
|
-
const y =
|
|
2851
|
-
|
|
2852
|
-
x: y.x + Math.cos(y.angle) * (
|
|
2853
|
-
y: y.y + Math.sin(y.angle) * (
|
|
2915
|
+
p = { x: 0, y: 0, angle: 0 };
|
|
2916
|
+
else if (s >= u.length) {
|
|
2917
|
+
const y = u[u.length - 1], S = b[b.length - 1];
|
|
2918
|
+
p = {
|
|
2919
|
+
x: y.x + Math.cos(y.angle) * (S / 2),
|
|
2920
|
+
y: y.y + Math.sin(y.angle) * (S / 2),
|
|
2854
2921
|
angle: y.angle
|
|
2855
2922
|
};
|
|
2856
2923
|
} else {
|
|
2857
|
-
const y =
|
|
2858
|
-
|
|
2859
|
-
x: y.x - Math.cos(y.angle) * (
|
|
2860
|
-
y: y.y - Math.sin(y.angle) * (
|
|
2924
|
+
const y = u[s], S = b[s];
|
|
2925
|
+
p = {
|
|
2926
|
+
x: y.x - Math.cos(y.angle) * (S / 2),
|
|
2927
|
+
y: y.y - Math.sin(y.angle) * (S / 2),
|
|
2861
2928
|
angle: y.angle
|
|
2862
2929
|
};
|
|
2863
2930
|
}
|
|
2864
|
-
t.save(), t.translate(
|
|
2865
|
-
const
|
|
2866
|
-
t.beginPath(), t.moveTo(0, -
|
|
2931
|
+
t.save(), t.translate(p.x, p.y), t.rotate(p.angle), t.globalAlpha = i, t.strokeStyle = nt(t.canvas), t.lineWidth = 2 / n;
|
|
2932
|
+
const g = a * 1.2;
|
|
2933
|
+
t.beginPath(), t.moveTo(0, -g / 2), t.lineTo(0, g / 2), t.stroke(), t.restore();
|
|
2867
2934
|
}
|
|
2868
2935
|
t.restore();
|
|
2869
2936
|
}
|
|
@@ -2872,28 +2939,28 @@ class Dt {
|
|
|
2872
2939
|
* Shows both image resize handles and crop handles
|
|
2873
2940
|
*/
|
|
2874
2941
|
static renderCropBoxLayer(t, e, o, n = 1) {
|
|
2875
|
-
if (!(e instanceof
|
|
2942
|
+
if (!(e instanceof we) || !e.isCropping) return;
|
|
2876
2943
|
const s = e, i = s.getCropBoxBounds();
|
|
2877
2944
|
if (!i) return;
|
|
2878
|
-
const a = 4 / n, r = 2 / n, l =
|
|
2879
|
-
t.save(), t.translate(e.x * n, e.y * n), t.rotate(
|
|
2880
|
-
const d = s.transformData.flipHorizontal ? -1 : 1,
|
|
2881
|
-
t.scale(d * n,
|
|
2882
|
-
const
|
|
2883
|
-
x:
|
|
2884
|
-
y:
|
|
2945
|
+
const a = 4 / n, r = 2 / n, l = ve / n, h = Me / n, c = 1 / n;
|
|
2946
|
+
t.save(), t.translate(e.x * n, e.y * n), t.rotate(gt.toRadians(e.rotation));
|
|
2947
|
+
const d = s.transformData.flipHorizontal ? -1 : 1, f = s.transformData.flipVertical ? -1 : 1;
|
|
2948
|
+
t.scale(d * n, f * n);
|
|
2949
|
+
const b = s.transformData.width * s.transformData.cropWidth, u = s.transformData.height * s.transformData.cropHeight, p = s.transformData.width / 2 - (s.transformData.cropX * s.transformData.width + b / 2), g = s.transformData.height / 2 - (s.transformData.cropY * s.transformData.height + u / 2), y = s.transformData.width / 2, S = s.transformData.height / 2, m = {
|
|
2950
|
+
x: p - y,
|
|
2951
|
+
y: g - S,
|
|
2885
2952
|
width: s.transformData.width,
|
|
2886
2953
|
height: s.transformData.height
|
|
2887
2954
|
};
|
|
2888
|
-
t.fillStyle = "rgba(0, 0, 0, 0.5)", i.y >
|
|
2889
|
-
const
|
|
2890
|
-
|
|
2891
|
-
const C = i.x + i.width, R =
|
|
2892
|
-
C < R && t.fillRect(C, i.y, R - C, i.height), t.strokeStyle =
|
|
2955
|
+
t.fillStyle = "rgba(0, 0, 0, 0.5)", i.y > m.y && t.fillRect(m.x, m.y, m.width, i.y - m.y);
|
|
2956
|
+
const w = i.y + i.height, T = m.y + m.height;
|
|
2957
|
+
w < T && t.fillRect(m.x, w, m.width, T - w), i.x > m.x && t.fillRect(m.x, i.y, i.x - m.x, i.height);
|
|
2958
|
+
const C = i.x + i.width, R = m.x + m.width;
|
|
2959
|
+
C < R && t.fillRect(C, i.y, R - C, i.height), t.strokeStyle = nt(t.canvas), t.lineWidth = r, t.strokeRect(i.x, i.y, i.width, i.height), t.strokeStyle = "rgba(255, 255, 255, 0.5)", t.lineWidth = c;
|
|
2893
2960
|
const x = i.width / 3;
|
|
2894
2961
|
t.beginPath(), t.moveTo(i.x + x, i.y), t.lineTo(i.x + x, i.y + i.height), t.moveTo(i.x + 2 * x, i.y), t.lineTo(i.x + 2 * x, i.y + i.height), t.stroke();
|
|
2895
|
-
const
|
|
2896
|
-
if (t.beginPath(), t.moveTo(i.x, i.y +
|
|
2962
|
+
const H = i.height / 3;
|
|
2963
|
+
if (t.beginPath(), t.moveTo(i.x, i.y + H), t.lineTo(i.x + i.width, i.y + H), t.moveTo(i.x, i.y + 2 * H), t.lineTo(i.x + i.width, i.y + 2 * H), t.stroke(), [
|
|
2897
2964
|
{ x: i.x, y: i.y },
|
|
2898
2965
|
// top-left
|
|
2899
2966
|
{ x: i.x + i.width, y: i.y },
|
|
@@ -2902,8 +2969,8 @@ class Dt {
|
|
|
2902
2969
|
// bottom-right
|
|
2903
2970
|
{ x: i.x, y: i.y + i.height }
|
|
2904
2971
|
// bottom-left
|
|
2905
|
-
].forEach((
|
|
2906
|
-
t.beginPath(), t.arc(
|
|
2972
|
+
].forEach((I) => {
|
|
2973
|
+
t.beginPath(), t.arc(I.x, I.y, l + 1 / n, 0, Math.PI * 2), t.fillStyle = "#bbb", t.fill(), t.beginPath(), t.arc(I.x, I.y, l, 0, Math.PI * 2), t.fillStyle = "#fff", t.fill();
|
|
2907
2974
|
}), [
|
|
2908
2975
|
{ x: i.x + i.width / 2, y: i.y, orientation: "horizontal" },
|
|
2909
2976
|
// top
|
|
@@ -2913,32 +2980,32 @@ class Dt {
|
|
|
2913
2980
|
// left
|
|
2914
2981
|
{ x: i.x + i.width, y: i.y + i.height / 2, orientation: "vertical" }
|
|
2915
2982
|
// right
|
|
2916
|
-
].forEach((
|
|
2917
|
-
let L,
|
|
2918
|
-
|
|
2919
|
-
const
|
|
2920
|
-
t.fillStyle = "#fff", t.fillRect(
|
|
2983
|
+
].forEach((I) => {
|
|
2984
|
+
let L, D;
|
|
2985
|
+
I.orientation === "horizontal" ? (L = h, D = a) : (L = a, D = h);
|
|
2986
|
+
const F = I.x - L / 2, W = I.y - D / 2;
|
|
2987
|
+
t.fillStyle = "#fff", t.fillRect(F, W, L, D), t.strokeStyle = "#bbb", t.lineWidth = c, t.strokeRect(F, W, L, D);
|
|
2921
2988
|
}), t.restore(), o && o.resizeHandles) {
|
|
2922
|
-
const
|
|
2923
|
-
(
|
|
2924
|
-
), L = s.getCropBoxWorldCorners(),
|
|
2925
|
-
|
|
2926
|
-
let
|
|
2989
|
+
const I = o.resizeHandles.filter(
|
|
2990
|
+
(W) => W.anchor === "top-left" || W.anchor === "top-right" || W.anchor === "bottom-left" || W.anchor === "bottom-right"
|
|
2991
|
+
), L = s.getCropBoxWorldCorners(), D = 6, F = 20;
|
|
2992
|
+
I.forEach((W) => {
|
|
2993
|
+
let q = !1;
|
|
2927
2994
|
if (L)
|
|
2928
|
-
for (const
|
|
2929
|
-
const
|
|
2930
|
-
if (Math.sqrt(
|
|
2931
|
-
|
|
2995
|
+
for (const J of L) {
|
|
2996
|
+
const E = W.x - J.x, z = W.y - J.y;
|
|
2997
|
+
if (Math.sqrt(E * E + z * z) < F) {
|
|
2998
|
+
q = !0;
|
|
2932
2999
|
break;
|
|
2933
3000
|
}
|
|
2934
3001
|
}
|
|
2935
|
-
|
|
3002
|
+
q || (t.save(), t.globalAlpha = 1, t.beginPath(), t.arc(W.x * n, W.y * n, D, 0, 2 * Math.PI), t.fillStyle = "#fff", t.fill(), t.strokeStyle = nt(t.canvas), t.lineWidth = 2, t.stroke(), t.restore());
|
|
2936
3003
|
});
|
|
2937
3004
|
}
|
|
2938
3005
|
}
|
|
2939
3006
|
}
|
|
2940
|
-
|
|
2941
|
-
const
|
|
3007
|
+
Ae();
|
|
3008
|
+
const Ne = Zt("CanvasRenderer"), K = class K {
|
|
2942
3009
|
/**
|
|
2943
3010
|
* Get a pooled offscreen canvas for clipping content, only recreating
|
|
2944
3011
|
* when dimensions change. Eliminates per-frame canvas allocation.
|
|
@@ -2962,7 +3029,7 @@ const De = $t("CanvasRenderer"), K = class K {
|
|
|
2962
3029
|
e.render(t, o, n);
|
|
2963
3030
|
} catch (s) {
|
|
2964
3031
|
const i = s instanceof Error ? s : new Error(String(s));
|
|
2965
|
-
|
|
3032
|
+
Ne.error(`Failed to render element ${e.id}:`, i), K.onRenderError && K.onRenderError({
|
|
2966
3033
|
category: "render",
|
|
2967
3034
|
message: `Failed to render element: ${i.message}`,
|
|
2968
3035
|
originalError: i,
|
|
@@ -2979,7 +3046,7 @@ const De = $t("CanvasRenderer"), K = class K {
|
|
|
2979
3046
|
* Used by knockout rendering system
|
|
2980
3047
|
*/
|
|
2981
3048
|
static renderElement(t, e, o = !0) {
|
|
2982
|
-
o && (t.save(), t.globalAlpha =
|
|
3049
|
+
o && (t.save(), t.globalAlpha = tt), e.render(t, !1, !1), o && t.restore();
|
|
2983
3050
|
}
|
|
2984
3051
|
/**
|
|
2985
3052
|
* Apply artboard clip path to the context, respecting clipShape.
|
|
@@ -3008,12 +3075,12 @@ const De = $t("CanvasRenderer"), K = class K {
|
|
|
3008
3075
|
try {
|
|
3009
3076
|
const l = new Path2D();
|
|
3010
3077
|
for (const h of a.pieces) {
|
|
3011
|
-
const c = new Path2D(h.d), d = h.rotation ?? 0,
|
|
3012
|
-
if (
|
|
3013
|
-
const
|
|
3014
|
-
|
|
3078
|
+
const c = new Path2D(h.d), d = h.rotation ?? 0, f = new DOMMatrix();
|
|
3079
|
+
if (f.translateSelf(h.x, h.y), d !== 0) {
|
|
3080
|
+
const b = (h.baseWidth ?? 0) / 2, u = (h.baseHeight ?? 0) / 2, p = d === 90 || d === 270, g = p ? h.baseHeight ?? 0 : h.baseWidth ?? 0, y = p ? h.baseWidth ?? 0 : h.baseHeight ?? 0;
|
|
3081
|
+
f.translateSelf(g / 2, y / 2), f.rotateSelf(d), f.translateSelf(-b, -u);
|
|
3015
3082
|
}
|
|
3016
|
-
l.addPath(c,
|
|
3083
|
+
l.addPath(c, f);
|
|
3017
3084
|
}
|
|
3018
3085
|
t.translate(o, n), t.clip(l), t.translate(-o, -n);
|
|
3019
3086
|
return;
|
|
@@ -3028,23 +3095,23 @@ const De = $t("CanvasRenderer"), K = class K {
|
|
|
3028
3095
|
*/
|
|
3029
3096
|
static renderElementWithOverflowDimming(t, e, o, n, s, i) {
|
|
3030
3097
|
const a = t.getTransform(), r = o.borderRadius || 0;
|
|
3031
|
-
t.save(), t.globalAlpha = 0.3 * (i ?
|
|
3032
|
-
const h = t.getTransform().inverse(), c = t.canvas.width, d = t.canvas.height,
|
|
3033
|
-
if (
|
|
3034
|
-
const
|
|
3035
|
-
|
|
3036
|
-
for (const
|
|
3037
|
-
const C = new Path2D(
|
|
3038
|
-
if (x.translateSelf(o.x +
|
|
3039
|
-
const
|
|
3040
|
-
x.translateSelf(
|
|
3098
|
+
t.save(), t.globalAlpha = 0.3 * (i ? tt : 1), t.filter = "blur(4px)", t.beginPath();
|
|
3099
|
+
const h = t.getTransform().inverse(), c = t.canvas.width, d = t.canvas.height, f = new DOMPoint(0, 0).matrixTransform(h), b = new DOMPoint(c, d).matrixTransform(h), u = Math.max(b.x - f.x, b.y - f.y), p = f.x - u, g = f.y - u, y = b.x + u, S = b.y + u, m = typeof o.clipShape == "object" && o.clipShape !== null && o.clipShape.type === "composite-path" ? o.clipShape : null;
|
|
3100
|
+
if (m) {
|
|
3101
|
+
const w = new Path2D();
|
|
3102
|
+
w.rect(p, g, y - p, S - g);
|
|
3103
|
+
for (const T of m.pieces) {
|
|
3104
|
+
const C = new Path2D(T.d), R = T.rotation ?? 0, x = new DOMMatrix();
|
|
3105
|
+
if (x.translateSelf(o.x + T.x, o.y + T.y), R !== 0) {
|
|
3106
|
+
const H = (T.baseWidth ?? 0) / 2, M = (T.baseHeight ?? 0) / 2, A = R === 90 || R === 270, I = A ? T.baseHeight ?? 0 : T.baseWidth ?? 0, L = A ? T.baseWidth ?? 0 : T.baseHeight ?? 0;
|
|
3107
|
+
x.translateSelf(I / 2, L / 2), x.rotateSelf(R), x.translateSelf(-H, -M);
|
|
3041
3108
|
}
|
|
3042
|
-
|
|
3109
|
+
w.addPath(C, x);
|
|
3043
3110
|
}
|
|
3044
|
-
t.clip(
|
|
3111
|
+
t.clip(w, "evenodd");
|
|
3045
3112
|
} else
|
|
3046
|
-
t.rect(
|
|
3047
|
-
e.render(t, !1, !1), t.restore(), t.save(), this.applyArtboardClipPath(t, o), i && (t.globalAlpha =
|
|
3113
|
+
t.rect(p, g, y - p, S - g), r > 0 ? t.roundRect(o.x, o.y, o.width, o.height, r) : t.rect(o.x, o.y, o.width, o.height), t.clip("evenodd");
|
|
3114
|
+
e.render(t, !1, !1), t.restore(), t.save(), this.applyArtboardClipPath(t, o), i && (t.globalAlpha = tt), e.render(t, n, s), t.restore(), t.setTransform(a);
|
|
3048
3115
|
}
|
|
3049
3116
|
/**
|
|
3050
3117
|
* Render all elements layer
|
|
@@ -3057,56 +3124,56 @@ const De = $t("CanvasRenderer"), K = class K {
|
|
|
3057
3124
|
*/
|
|
3058
3125
|
static renderElementsLayer(t, e, o, n, s, i, a, r = !0, l = !1, h = !1) {
|
|
3059
3126
|
const c = s != null && s.getMode() === "drag", d = s == null ? void 0 : s._activeChildContext;
|
|
3060
|
-
e !== K._cachedElementsRef && (K._cachedElementConfigs = e.map((
|
|
3061
|
-
const
|
|
3062
|
-
|
|
3063
|
-
var
|
|
3064
|
-
if (
|
|
3065
|
-
const
|
|
3066
|
-
|
|
3127
|
+
e !== K._cachedElementsRef && (K._cachedElementConfigs = e.map((g) => g.toJSON()), K._cachedElementMap = new Map(e.map((g) => [g.id, g])), K._cachedElementsRef = e);
|
|
3128
|
+
const f = K._cachedElementConfigs, b = K._cachedElementMap, u = K._knockoutRenderedIds;
|
|
3129
|
+
u.clear(), e.forEach((g, y) => {
|
|
3130
|
+
var S, m, w;
|
|
3131
|
+
if (g.blendMode === "knockout" || g.blendMode === "clip") {
|
|
3132
|
+
const T = f[y], C = g.blendMode === "knockout" ? "destination-out" : "destination-in", R = ((S = T.knockoutParts) == null ? void 0 : S.scope) || "group", x = f.findIndex((I) => I.id === T.id), H = ((m = T.knockoutParts) == null ? void 0 : m.fill) || ((w = T.knockoutParts) == null ? void 0 : w.stroke), M = R === "artboard" && x !== -1 ? f.slice(0, x) : [];
|
|
3133
|
+
H && (R === "artboard" || M.length > 0) && (M.forEach((I) => I.id && u.add(I.id)), Re(
|
|
3067
3134
|
t,
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
(
|
|
3071
|
-
const
|
|
3072
|
-
|
|
3135
|
+
T,
|
|
3136
|
+
f,
|
|
3137
|
+
(I, L) => {
|
|
3138
|
+
const D = L.id && b.get(L.id);
|
|
3139
|
+
D && this.renderElement(I, D, r);
|
|
3073
3140
|
},
|
|
3074
3141
|
i,
|
|
3075
3142
|
a,
|
|
3076
3143
|
C
|
|
3077
|
-
),
|
|
3144
|
+
), u.add(g.id));
|
|
3078
3145
|
}
|
|
3079
|
-
}), e.some((
|
|
3146
|
+
}), e.some((g) => !u.has(g.id) && g.isClipping) ? this._renderWithClipping(
|
|
3080
3147
|
t,
|
|
3081
3148
|
e,
|
|
3082
|
-
|
|
3149
|
+
u,
|
|
3083
3150
|
o,
|
|
3084
3151
|
n,
|
|
3085
3152
|
c,
|
|
3086
3153
|
d,
|
|
3087
|
-
|
|
3154
|
+
f,
|
|
3088
3155
|
r
|
|
3089
|
-
) : e.forEach((
|
|
3156
|
+
) : e.forEach((g) => {
|
|
3090
3157
|
var R, x;
|
|
3091
|
-
if (
|
|
3092
|
-
const y =
|
|
3093
|
-
if (
|
|
3094
|
-
|
|
3095
|
-
const
|
|
3096
|
-
r && (A.save(), A.globalAlpha =
|
|
3158
|
+
if (u.has(g.id) || g.visible === !1) return;
|
|
3159
|
+
const y = g.id === o, S = (n == null ? void 0 : n.type) === "element" && ((R = n == null ? void 0 : n.data) == null ? void 0 : R.id) === g.id, m = c && d && Dt(g) && g.id === o, w = y && !m, T = f[e.indexOf(g)], C = ((x = T == null ? void 0 : T.distressEffect) == null ? void 0 : x.enabled) && T.distressEffect.style === "custom" && T.distressEffect.textureUrl;
|
|
3160
|
+
if (T && T.masks && T.masks.length > 0)
|
|
3161
|
+
At(t, T, (H) => {
|
|
3162
|
+
const M = (A) => {
|
|
3163
|
+
r && (A.save(), A.globalAlpha = tt), this.safeRender(A, g, w, S), r && A.restore();
|
|
3097
3164
|
};
|
|
3098
3165
|
if (C) {
|
|
3099
|
-
const A =
|
|
3100
|
-
|
|
3166
|
+
const A = g.getVisualBoundingBox();
|
|
3167
|
+
Kt(H, T.distressEffect, A, M);
|
|
3101
3168
|
} else
|
|
3102
|
-
|
|
3169
|
+
M(H);
|
|
3103
3170
|
});
|
|
3104
3171
|
else if (C) {
|
|
3105
|
-
const
|
|
3106
|
-
|
|
3107
|
-
r && (
|
|
3172
|
+
const H = g.getVisualBoundingBox();
|
|
3173
|
+
Kt(t, T.distressEffect, H, (M) => {
|
|
3174
|
+
r && (M.save(), M.globalAlpha = tt), this.safeRender(M, g, w, S), r && M.restore();
|
|
3108
3175
|
});
|
|
3109
|
-
} else l && !h && a &&
|
|
3176
|
+
} else l && !h && a && w ? this.renderElementWithOverflowDimming(t, g, a, w, S, r) : l && a ? (t.save(), this.applyArtboardClipPath(t, a), r && (t.globalAlpha = tt), this.safeRender(t, g, w, S), t.restore()) : (r && (t.save(), t.globalAlpha = tt), this.safeRender(t, g, w, S), r && t.restore());
|
|
3110
3177
|
});
|
|
3111
3178
|
}
|
|
3112
3179
|
/**
|
|
@@ -3114,51 +3181,51 @@ const De = $t("CanvasRenderer"), K = class K {
|
|
|
3114
3181
|
* Elements with isClipping=true clip all elements below them
|
|
3115
3182
|
*/
|
|
3116
3183
|
static _renderWithClipping(t, e, o, n, s, i, a, r, l = !0) {
|
|
3117
|
-
var
|
|
3118
|
-
const h = t.canvas, c = h.width, d = h.height,
|
|
3119
|
-
let
|
|
3184
|
+
var g;
|
|
3185
|
+
const h = t.canvas, c = h.width, d = h.height, f = t.getTransform(), b = [];
|
|
3186
|
+
let u = [], p = [];
|
|
3120
3187
|
for (let y = 0; y < e.length; y++) {
|
|
3121
|
-
const
|
|
3122
|
-
o.has(
|
|
3123
|
-
content:
|
|
3124
|
-
mask:
|
|
3125
|
-
contentConfigs:
|
|
3126
|
-
maskConfig:
|
|
3127
|
-
}),
|
|
3128
|
-
content: [
|
|
3129
|
-
contentConfigs: [
|
|
3130
|
-
}) : (
|
|
3188
|
+
const S = e[y], m = r[y];
|
|
3189
|
+
o.has(S.id) || S.visible !== !1 && (S.isClipping ? u.length > 0 ? (b.push({
|
|
3190
|
+
content: u,
|
|
3191
|
+
mask: S,
|
|
3192
|
+
contentConfigs: p,
|
|
3193
|
+
maskConfig: m
|
|
3194
|
+
}), u = [], p = []) : b.push({
|
|
3195
|
+
content: [S],
|
|
3196
|
+
contentConfigs: [m]
|
|
3197
|
+
}) : (u.push(S), p.push(m)));
|
|
3131
3198
|
}
|
|
3132
|
-
|
|
3133
|
-
content:
|
|
3134
|
-
contentConfigs:
|
|
3199
|
+
u.length > 0 && b.push({
|
|
3200
|
+
content: u,
|
|
3201
|
+
contentConfigs: p
|
|
3135
3202
|
});
|
|
3136
|
-
for (const y of
|
|
3203
|
+
for (const y of b)
|
|
3137
3204
|
if (!y.mask)
|
|
3138
|
-
y.content.forEach((
|
|
3139
|
-
var
|
|
3140
|
-
const
|
|
3141
|
-
x && x.masks && x.masks.length > 0 ?
|
|
3142
|
-
l && (
|
|
3143
|
-
}) : (l && (t.save(), t.globalAlpha =
|
|
3205
|
+
y.content.forEach((S, m) => {
|
|
3206
|
+
var H;
|
|
3207
|
+
const w = S.id === n, T = (s == null ? void 0 : s.type) === "element" && ((H = s == null ? void 0 : s.data) == null ? void 0 : H.id) === S.id, C = i && a && Dt(S) && S.id === n, R = w && !C, x = y.contentConfigs[m];
|
|
3208
|
+
x && x.masks && x.masks.length > 0 ? At(t, x, (M) => {
|
|
3209
|
+
l && (M.save(), M.globalAlpha = tt), S.render(M, R, T), l && M.restore();
|
|
3210
|
+
}) : (l && (t.save(), t.globalAlpha = tt), S.render(t, R, T), l && t.restore());
|
|
3144
3211
|
});
|
|
3145
3212
|
else {
|
|
3146
|
-
const
|
|
3147
|
-
if (!
|
|
3148
|
-
|
|
3149
|
-
var
|
|
3150
|
-
const
|
|
3151
|
-
|
|
3152
|
-
l && (
|
|
3153
|
-
}) : (l && (
|
|
3213
|
+
const S = this._getContentCanvas(c, d), m = S.getContext("2d");
|
|
3214
|
+
if (!m) continue;
|
|
3215
|
+
m.setTransform(1, 0, 0, 1, 0, 0), m.clearRect(0, 0, c, d), m.globalCompositeOperation = "source-over", m.setTransform(f), y.content.forEach((x, H) => {
|
|
3216
|
+
var F;
|
|
3217
|
+
const M = x.id === n, A = (s == null ? void 0 : s.type) === "element" && ((F = s == null ? void 0 : s.data) == null ? void 0 : F.id) === x.id, I = i && a && Dt(x) && x.id === n, L = M && !I, D = y.contentConfigs[H];
|
|
3218
|
+
D && D.masks && D.masks.length > 0 ? At(m, D, (W) => {
|
|
3219
|
+
l && (W.save(), W.globalAlpha = tt), x.render(W, L, A), l && W.restore();
|
|
3220
|
+
}) : (l && (m.save(), m.globalAlpha = tt), x.render(m, L, A), l && m.restore());
|
|
3154
3221
|
});
|
|
3155
|
-
const
|
|
3156
|
-
if (!
|
|
3157
|
-
|
|
3158
|
-
const C = y.mask.id === n, R = (s == null ? void 0 : s.type) === "element" && ((
|
|
3159
|
-
y.maskConfig && y.maskConfig.masks && y.maskConfig.masks.length > 0 ?
|
|
3160
|
-
l && (x.save(), x.globalAlpha =
|
|
3161
|
-
}) : (l && (
|
|
3222
|
+
const w = this._getMaskCanvas(c, d), T = w.getContext("2d");
|
|
3223
|
+
if (!T) continue;
|
|
3224
|
+
T.setTransform(1, 0, 0, 1, 0, 0), T.clearRect(0, 0, c, d), T.globalCompositeOperation = "source-over", T.setTransform(f);
|
|
3225
|
+
const C = y.mask.id === n, R = (s == null ? void 0 : s.type) === "element" && ((g = s == null ? void 0 : s.data) == null ? void 0 : g.id) === y.mask.id;
|
|
3226
|
+
y.maskConfig && y.maskConfig.masks && y.maskConfig.masks.length > 0 ? At(T, y.maskConfig, (x) => {
|
|
3227
|
+
l && (x.save(), x.globalAlpha = tt), y.mask.render(x, C, R), l && x.restore();
|
|
3228
|
+
}) : (l && (T.save(), T.globalAlpha = tt), y.mask.render(T, C, R), l && T.restore()), m.globalCompositeOperation = "destination-in", m.setTransform(1, 0, 0, 1, 0, 0), m.drawImage(w, 0, 0), t.save(), t.setTransform(1, 0, 0, 1, 0, 0), t.drawImage(S, 0, 0), t.restore();
|
|
3162
3229
|
}
|
|
3163
3230
|
}
|
|
3164
3231
|
// =========================================================================
|
|
@@ -3190,21 +3257,21 @@ const De = $t("CanvasRenderer"), K = class K {
|
|
|
3190
3257
|
* @see SelectionRenderer.renderSelectionLayer
|
|
3191
3258
|
*/
|
|
3192
3259
|
static renderSelectionLayer(t, e, o, n = 1) {
|
|
3193
|
-
|
|
3260
|
+
wt.renderSelectionLayer(t, e, o, n);
|
|
3194
3261
|
}
|
|
3195
3262
|
/**
|
|
3196
3263
|
* Render position and size info below the selected element
|
|
3197
3264
|
* @see SelectionRenderer.renderPositionSizeInfo
|
|
3198
3265
|
*/
|
|
3199
3266
|
static renderPositionSizeInfo(t, e, o, n, s = 1) {
|
|
3200
|
-
|
|
3267
|
+
wt.renderPositionSizeInfo(t, e, o, n, s);
|
|
3201
3268
|
}
|
|
3202
3269
|
/**
|
|
3203
3270
|
* Render transform handles layer
|
|
3204
3271
|
* @see SelectionRenderer.renderHandlesLayer
|
|
3205
3272
|
*/
|
|
3206
3273
|
static renderHandlesLayer(t, e, o, n, s, i, a, r = 1, l = !0) {
|
|
3207
|
-
|
|
3274
|
+
wt.renderHandlesLayer(
|
|
3208
3275
|
t,
|
|
3209
3276
|
e,
|
|
3210
3277
|
o,
|
|
@@ -3221,14 +3288,14 @@ const De = $t("CanvasRenderer"), K = class K {
|
|
|
3221
3288
|
* @see HoverRenderer.renderHoverLayer
|
|
3222
3289
|
*/
|
|
3223
3290
|
static renderHoverLayer(t, e, o, n = !1, s = 1, i) {
|
|
3224
|
-
|
|
3291
|
+
Vt.renderHoverLayer(t, e, o, n, s, i);
|
|
3225
3292
|
}
|
|
3226
3293
|
/**
|
|
3227
3294
|
* Render crop box layer (for images in crop mode)
|
|
3228
3295
|
* @see EditModeRenderer.renderCropBoxLayer
|
|
3229
3296
|
*/
|
|
3230
3297
|
static renderCropBoxLayer(t, e, o, n = 1) {
|
|
3231
|
-
|
|
3298
|
+
zt.renderCropBoxLayer(t, e, o, n);
|
|
3232
3299
|
}
|
|
3233
3300
|
// =========================================================================
|
|
3234
3301
|
// Main Render Orchestration
|
|
@@ -3257,13 +3324,13 @@ const De = $t("CanvasRenderer"), K = class K {
|
|
|
3257
3324
|
artboardBackgroundColor: h,
|
|
3258
3325
|
artboard: c,
|
|
3259
3326
|
isPreview: d = !0,
|
|
3260
|
-
zoom:
|
|
3261
|
-
paddingOffset:
|
|
3262
|
-
showOverflowDimmed:
|
|
3263
|
-
suppressOverflowDim:
|
|
3264
|
-
distressTexture:
|
|
3327
|
+
zoom: f = 1,
|
|
3328
|
+
paddingOffset: b = { x: 0, y: 0 },
|
|
3329
|
+
showOverflowDimmed: u = !1,
|
|
3330
|
+
suppressOverflowDim: p = !1,
|
|
3331
|
+
distressTexture: g,
|
|
3265
3332
|
imageMask: y,
|
|
3266
|
-
editModeData:
|
|
3333
|
+
editModeData: S
|
|
3267
3334
|
}) {
|
|
3268
3335
|
if (this.renderElementsLayer(
|
|
3269
3336
|
t,
|
|
@@ -3274,33 +3341,33 @@ const De = $t("CanvasRenderer"), K = class K {
|
|
|
3274
3341
|
h,
|
|
3275
3342
|
c,
|
|
3276
3343
|
d,
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
),
|
|
3344
|
+
u,
|
|
3345
|
+
p
|
|
3346
|
+
), g != null && g.enabled && c && ke(t, g, c, h), y != null && y.enabled && c && Pe(t, y, c, h), i && S && n && zt.renderEditModeLayer(t, n, S, f), f !== 1) {
|
|
3280
3347
|
t.save();
|
|
3281
|
-
const C = t.getTransform().a /
|
|
3348
|
+
const C = t.getTransform().a / f, R = b.x * f * C, x = b.y * f * C;
|
|
3282
3349
|
t.setTransform(C, 0, 0, C, R, x);
|
|
3283
3350
|
}
|
|
3284
|
-
const
|
|
3285
|
-
...
|
|
3286
|
-
x:
|
|
3287
|
-
y:
|
|
3288
|
-
x1:
|
|
3289
|
-
y1:
|
|
3290
|
-
x2:
|
|
3291
|
-
y2:
|
|
3292
|
-
})),
|
|
3293
|
-
...
|
|
3294
|
-
x:
|
|
3295
|
-
y:
|
|
3296
|
-
x1:
|
|
3297
|
-
y1:
|
|
3298
|
-
x2:
|
|
3299
|
-
y2:
|
|
3300
|
-
labelX:
|
|
3301
|
-
labelY:
|
|
3351
|
+
const m = r.map((T) => ({
|
|
3352
|
+
...T,
|
|
3353
|
+
x: T.x !== void 0 ? T.x * f : void 0,
|
|
3354
|
+
y: T.y !== void 0 ? T.y * f : void 0,
|
|
3355
|
+
x1: T.x1 !== void 0 ? T.x1 * f : void 0,
|
|
3356
|
+
y1: T.y1 !== void 0 ? T.y1 * f : void 0,
|
|
3357
|
+
x2: T.x2 !== void 0 ? T.x2 * f : void 0,
|
|
3358
|
+
y2: T.y2 !== void 0 ? T.y2 * f : void 0
|
|
3359
|
+
})), w = l.map((T) => ({
|
|
3360
|
+
...T,
|
|
3361
|
+
x: T.x !== void 0 ? T.x * f : void 0,
|
|
3362
|
+
y: T.y !== void 0 ? T.y * f : void 0,
|
|
3363
|
+
x1: T.x1 !== void 0 ? T.x1 * f : void 0,
|
|
3364
|
+
y1: T.y1 !== void 0 ? T.y1 * f : void 0,
|
|
3365
|
+
x2: T.x2 !== void 0 ? T.x2 * f : void 0,
|
|
3366
|
+
y2: T.y2 !== void 0 ? T.y2 * f : void 0,
|
|
3367
|
+
labelX: T.labelX * f,
|
|
3368
|
+
labelY: T.labelY * f
|
|
3302
3369
|
}));
|
|
3303
|
-
Ct.renderSnapGuidesLayer(t,
|
|
3370
|
+
Ct.renderSnapGuidesLayer(t, m), Ct.renderSpacingIndicatorsLayer(t, w), f !== 1 && t.restore();
|
|
3304
3371
|
}
|
|
3305
3372
|
/**
|
|
3306
3373
|
* Single-selection interaction chrome: bbox, handles, position/size
|
|
@@ -3327,19 +3394,19 @@ const De = $t("CanvasRenderer"), K = class K {
|
|
|
3327
3394
|
isEditing: h,
|
|
3328
3395
|
isAltKeyPressed: c = !1,
|
|
3329
3396
|
artboardBackgroundColor: d,
|
|
3330
|
-
hoverClipArtboard:
|
|
3331
|
-
showRotationHandle:
|
|
3332
|
-
zoom:
|
|
3333
|
-
paddingOffset:
|
|
3397
|
+
hoverClipArtboard: f,
|
|
3398
|
+
showRotationHandle: b = !0,
|
|
3399
|
+
zoom: u = 1,
|
|
3400
|
+
paddingOffset: p = { x: 0, y: 0 }
|
|
3334
3401
|
}) {
|
|
3335
|
-
if (
|
|
3402
|
+
if (u !== 1) {
|
|
3336
3403
|
t.save();
|
|
3337
|
-
const
|
|
3338
|
-
t.setTransform(
|
|
3404
|
+
const S = t.getTransform().a / u, m = p.x * u * S, w = p.y * u * S;
|
|
3405
|
+
t.setTransform(S, 0, 0, S, m, w);
|
|
3339
3406
|
}
|
|
3340
|
-
if (e &&
|
|
3341
|
-
o &&
|
|
3342
|
-
else if (!l && n &&
|
|
3407
|
+
if (e && Ee(e) && e.isCropping)
|
|
3408
|
+
o && zt.renderCropBoxLayer(t, e, o, u);
|
|
3409
|
+
else if (!l && n && wt.renderSelectionLayer(t, e, n, u), o && n && wt.renderPositionSizeInfo(t, e, o, n, u), !l && o && n && wt.renderHandlesLayer(
|
|
3343
3410
|
t,
|
|
3344
3411
|
e,
|
|
3345
3412
|
o,
|
|
@@ -3347,33 +3414,34 @@ const De = $t("CanvasRenderer"), K = class K {
|
|
|
3347
3414
|
i,
|
|
3348
3415
|
a,
|
|
3349
3416
|
n,
|
|
3350
|
-
|
|
3351
|
-
|
|
3417
|
+
u,
|
|
3418
|
+
b
|
|
3352
3419
|
), !h) {
|
|
3353
|
-
if (
|
|
3420
|
+
if (f) {
|
|
3354
3421
|
t.save();
|
|
3355
|
-
const y =
|
|
3356
|
-
t.beginPath(), C > 0 ? t.roundRect(
|
|
3422
|
+
const y = f, S = y.x * u, m = y.y * u, w = y.width * u, T = y.height * u, C = (y.borderRadius ?? 0) * u;
|
|
3423
|
+
t.beginPath(), C > 0 ? t.roundRect(S, m, w, T, C) : t.rect(S, m, w, T), t.clip();
|
|
3357
3424
|
}
|
|
3358
|
-
|
|
3425
|
+
Vt.renderHoverLayer(t, a, r, c, u, d), f && t.restore();
|
|
3359
3426
|
}
|
|
3360
|
-
|
|
3427
|
+
u !== 1 && t.restore();
|
|
3361
3428
|
}
|
|
3362
3429
|
};
|
|
3363
3430
|
K._contentCanvas = null, K._contentCanvasSize = { width: 0, height: 0 }, K._maskCanvas = null, K._maskCanvasSize = { width: 0, height: 0 }, K._cachedElementsRef = null, K._cachedElementConfigs = null, K._cachedElementMap = null, K._knockoutRenderedIds = /* @__PURE__ */ new Set(), K.onRenderError = null;
|
|
3364
|
-
let
|
|
3431
|
+
let Ut = K;
|
|
3365
3432
|
export {
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3433
|
+
en as A,
|
|
3434
|
+
Ut as C,
|
|
3435
|
+
tn as I,
|
|
3436
|
+
Ge as R,
|
|
3437
|
+
nn as S,
|
|
3438
|
+
Je as T,
|
|
3439
|
+
ne as a,
|
|
3440
|
+
Ue as b,
|
|
3441
|
+
qe as c,
|
|
3442
|
+
Ve as d,
|
|
3443
|
+
Qe as e,
|
|
3444
|
+
$t as g,
|
|
3445
|
+
Ze as r
|
|
3378
3446
|
};
|
|
3379
|
-
//# sourceMappingURL=CanvasRenderer-
|
|
3447
|
+
//# sourceMappingURL=CanvasRenderer-_lFoIoz5.js.map
|