@dfosco/tiny-canvas 3.10.0 → 3.11.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tiny-canvas.js +194 -192
- package/package.json +1 -1
package/dist/tiny-canvas.js
CHANGED
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import xt, { useRef as
|
|
1
|
+
import { jsx as rt } from "react/jsx-runtime";
|
|
2
|
+
import xt, { useRef as G, useState as J, useEffect as nt, Children as Ct, useCallback as It } from "react";
|
|
3
3
|
var gt = { dragStart: !0 }, pt = { delay: 0, distance: 3 };
|
|
4
|
-
function
|
|
5
|
-
let
|
|
4
|
+
function Tt(t, e = {}) {
|
|
5
|
+
let r, a, { bounds: s, axis: d = "both", gpuAcceleration: i = !0, legacyTranslate: f = !1, transform: v, applyUserSelectHack: M = !0, disabled: A = !1, ignoreMultitouch: I = !1, recomputeBounds: D = gt, grid: R, threshold: b = pt, position: E, cancel: L, handle: X, defaultClass: c = "neodrag", defaultClassDragging: N = "neodrag-dragging", defaultClassDragged: O = "neodrag-dragged", defaultPosition: p = { x: 0, y: 0 }, onDragStart: o, onDrag: w, onDragEnd: H } = e, S = !1, T = !1, j = 0, $ = !1, g = !1, x = 0, Y = 0, B = 0, U = 0, ot = 0, at = 0, { x: z, y: V } = E ? { x: (E == null ? void 0 : E.x) ?? 0, y: (E == null ? void 0 : E.y) ?? 0 } : p;
|
|
6
6
|
ut(z, V);
|
|
7
|
-
let P,
|
|
8
|
-
|
|
7
|
+
let P, k, F, st, it, vt = "", Nt = !!E;
|
|
8
|
+
D = { ...gt, ...D }, b = { ...pt, ...b ?? {} };
|
|
9
9
|
let W = /* @__PURE__ */ new Set();
|
|
10
|
-
function bt(
|
|
11
|
-
|
|
12
|
-
lt("neodrag:start",
|
|
13
|
-
})(
|
|
10
|
+
function bt(n) {
|
|
11
|
+
S && !T && g && $ && it && (T = !0, (function(u) {
|
|
12
|
+
lt("neodrag:start", o, u);
|
|
13
|
+
})(n), _.add(N), M && (vt = ct.userSelect, ct.userSelect = "none"));
|
|
14
14
|
}
|
|
15
|
-
const ct = document.body.style,
|
|
16
|
-
function ut(
|
|
15
|
+
const ct = document.body.style, _ = t.classList;
|
|
16
|
+
function ut(n = x, u = Y) {
|
|
17
17
|
if (!v) {
|
|
18
18
|
if (f) {
|
|
19
|
-
let
|
|
20
|
-
return K(t, "transform",
|
|
19
|
+
let y = `${+n}px, ${+u}px`;
|
|
20
|
+
return K(t, "transform", i ? `translate3d(${y}, 0)` : `translate(${y})`);
|
|
21
21
|
}
|
|
22
|
-
return K(t, "translate", `${+
|
|
22
|
+
return K(t, "translate", `${+n}px ${+u}px`);
|
|
23
23
|
}
|
|
24
|
-
const m = v({ offsetX:
|
|
24
|
+
const m = v({ offsetX: n, offsetY: u, rootNode: t });
|
|
25
25
|
mt(m) && K(t, "transform", m);
|
|
26
26
|
}
|
|
27
|
-
function lt(
|
|
28
|
-
const
|
|
29
|
-
return { offsetX:
|
|
27
|
+
function lt(n, u, m) {
|
|
28
|
+
const y = /* @__PURE__ */ (function(h) {
|
|
29
|
+
return { offsetX: x, offsetY: Y, rootNode: t, currentNode: it, event: h };
|
|
30
30
|
})(m);
|
|
31
|
-
t.dispatchEvent(new CustomEvent(
|
|
31
|
+
t.dispatchEvent(new CustomEvent(n, { detail: y })), u == null || u(y);
|
|
32
32
|
}
|
|
33
33
|
const Z = addEventListener, dt = new AbortController(), ft = { signal: dt.signal, capture: !1 };
|
|
34
34
|
function Et() {
|
|
35
|
-
let
|
|
36
|
-
return isNaN(
|
|
35
|
+
let n = t.offsetWidth / k.width;
|
|
36
|
+
return isNaN(n) && (n = 1), n;
|
|
37
37
|
}
|
|
38
|
-
return K(t, "touch-action", "none"), Z("pointerdown", ((
|
|
39
|
-
if (
|
|
40
|
-
if (W.add(
|
|
41
|
-
if (
|
|
42
|
-
if (
|
|
43
|
-
if (!
|
|
44
|
-
if (
|
|
45
|
-
if (Array.isArray(
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
return Array.from(
|
|
49
|
-
})(
|
|
50
|
-
if (!
|
|
51
|
-
if (
|
|
52
|
-
if (Array.isArray(
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
return Array.from(
|
|
56
|
-
})(
|
|
57
|
-
const
|
|
58
|
-
if (!
|
|
59
|
-
var
|
|
60
|
-
return
|
|
61
|
-
})) || Dt(st, [
|
|
62
|
-
it =
|
|
63
|
-
const { clientX: m, clientY:
|
|
64
|
-
|
|
65
|
-
}), ft), Z("pointermove", ((
|
|
66
|
-
if (!
|
|
67
|
-
if (!
|
|
68
|
-
if (
|
|
69
|
-
const
|
|
70
|
-
Math.sqrt(
|
|
38
|
+
return K(t, "touch-action", "none"), Z("pointerdown", ((n) => {
|
|
39
|
+
if (A || n.button === 2) return;
|
|
40
|
+
if (W.add(n.pointerId), I && W.size > 1) return n.preventDefault();
|
|
41
|
+
if (D.dragStart && (P = yt(s, t)), mt(X) && mt(L) && X === L) throw new Error("`handle` selector can't be same as `cancel` selector");
|
|
42
|
+
if (_.add(c), F = (function(l, C) {
|
|
43
|
+
if (!l) return [C];
|
|
44
|
+
if (ht(l)) return [l];
|
|
45
|
+
if (Array.isArray(l)) return l;
|
|
46
|
+
const q = C.querySelectorAll(l);
|
|
47
|
+
if (q === null) throw new Error("Selector passed for `handle` option should be child of the element on which the action is applied");
|
|
48
|
+
return Array.from(q.values());
|
|
49
|
+
})(X, t), st = (function(l, C) {
|
|
50
|
+
if (!l) return [];
|
|
51
|
+
if (ht(l)) return [l];
|
|
52
|
+
if (Array.isArray(l)) return l;
|
|
53
|
+
const q = C.querySelectorAll(l);
|
|
54
|
+
if (q === null) throw new Error("Selector passed for `cancel` option should be child of the element on which the action is applied");
|
|
55
|
+
return Array.from(q.values());
|
|
56
|
+
})(L, t), r = /(both|x)/.test(d), a = /(both|y)/.test(d), Dt(st, F)) throw new Error("Element being dragged can't be a child of the element on which `cancel` is applied");
|
|
57
|
+
const u = n.composedPath()[0];
|
|
58
|
+
if (!F.some(((l) => {
|
|
59
|
+
var C;
|
|
60
|
+
return l.contains(u) || ((C = l.shadowRoot) == null ? void 0 : C.contains(u));
|
|
61
|
+
})) || Dt(st, [u])) return;
|
|
62
|
+
it = F.length === 1 ? t : F.find(((l) => l.contains(u))), S = !0, j = Date.now(), b.delay || ($ = !0), k = t.getBoundingClientRect();
|
|
63
|
+
const { clientX: m, clientY: y } = n, h = Et();
|
|
64
|
+
r && (B = m - z / h), a && (U = y - V / h), P && (ot = m - k.left, at = y - k.top);
|
|
65
|
+
}), ft), Z("pointermove", ((n) => {
|
|
66
|
+
if (!S || I && W.size > 1) return;
|
|
67
|
+
if (!T) {
|
|
68
|
+
if ($ || Date.now() - j >= b.delay && ($ = !0, bt(n)), !g) {
|
|
69
|
+
const h = n.clientX - B, l = n.clientY - U;
|
|
70
|
+
Math.sqrt(h ** 2 + l ** 2) >= b.distance && (g = !0, bt(n));
|
|
71
71
|
}
|
|
72
|
-
if (!
|
|
72
|
+
if (!T) return;
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
let
|
|
76
|
-
const
|
|
74
|
+
D.drag && (P = yt(s, t)), n.preventDefault(), k = t.getBoundingClientRect();
|
|
75
|
+
let u = n.clientX, m = n.clientY;
|
|
76
|
+
const y = Et();
|
|
77
77
|
if (P) {
|
|
78
|
-
const
|
|
79
|
-
|
|
78
|
+
const h = { left: P.left + ot, top: P.top + at, right: P.right + ot - k.width, bottom: P.bottom + at - k.height };
|
|
79
|
+
u = St(u, h.left, h.right), m = St(m, h.top, h.bottom);
|
|
80
80
|
}
|
|
81
|
-
if (Array.isArray(
|
|
82
|
-
let [
|
|
83
|
-
if (isNaN(+
|
|
84
|
-
if (isNaN(+
|
|
85
|
-
let
|
|
86
|
-
[
|
|
81
|
+
if (Array.isArray(R)) {
|
|
82
|
+
let [h, l] = R;
|
|
83
|
+
if (isNaN(+h) || h < 0) throw new Error("1st argument of `grid` must be a valid positive number");
|
|
84
|
+
if (isNaN(+l) || l < 0) throw new Error("2nd argument of `grid` must be a valid positive number");
|
|
85
|
+
let C = u - B, q = m - U;
|
|
86
|
+
[C, q] = Rt([h / y, l / y], C, q), u = B + C, m = U + q;
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
}), ft), Z("pointerup", ((
|
|
90
|
-
W.delete(
|
|
91
|
-
}), ft), { destroy: () => dt.abort(), update: (
|
|
92
|
-
var m,
|
|
93
|
-
d =
|
|
94
|
-
const
|
|
95
|
-
|
|
88
|
+
r && (x = Math.round((u - B) * y)), a && (Y = Math.round((m - U) * y)), z = x, V = Y, lt("neodrag", w, n), ut();
|
|
89
|
+
}), ft), Z("pointerup", ((n) => {
|
|
90
|
+
W.delete(n.pointerId), S && (T && (Z("click", ((u) => u.stopPropagation()), { once: !0, signal: dt.signal, capture: !0 }), D.dragEnd && (P = yt(s, t)), _.remove(N), _.add(O), M && (ct.userSelect = vt), lt("neodrag:end", H, n), r && (B = x), a && (U = Y)), S = !1, T = !1, $ = !1, g = !1);
|
|
91
|
+
}), ft), { destroy: () => dt.abort(), update: (n) => {
|
|
92
|
+
var m, y;
|
|
93
|
+
d = n.axis || "both", A = n.disabled ?? !1, I = n.ignoreMultitouch ?? !1, X = n.handle, s = n.bounds, D = n.recomputeBounds ?? gt, L = n.cancel, M = n.applyUserSelectHack ?? !0, R = n.grid, i = n.gpuAcceleration ?? !0, f = n.legacyTranslate ?? !1, v = n.transform, b = { ...pt, ...n.threshold ?? {} };
|
|
94
|
+
const u = _.contains(O);
|
|
95
|
+
_.remove(c, O), c = n.defaultClass ?? "neodrag", N = n.defaultClassDragging ?? "neodrag-dragging", O = n.defaultClassDragged ?? "neodrag-dragged", _.add(c), u && _.add(O), Nt && (z = x = ((m = n.position) == null ? void 0 : m.x) ?? x, V = Y = ((y = n.position) == null ? void 0 : y.y) ?? Y, ut());
|
|
96
96
|
} };
|
|
97
97
|
}
|
|
98
|
-
var St = (t, e,
|
|
99
|
-
const s = (d,
|
|
100
|
-
return [s(
|
|
101
|
-
}, Dt = (t, e) => t.some(((
|
|
102
|
-
function
|
|
98
|
+
var St = (t, e, r) => Math.min(Math.max(t, e), r), mt = (t) => typeof t == "string", Rt = ([t, e], r, a) => {
|
|
99
|
+
const s = (d, i) => i === 0 ? 0 : Math.ceil(d / i) * i;
|
|
100
|
+
return [s(r, t), s(a, e)];
|
|
101
|
+
}, Dt = (t, e) => t.some(((r) => e.some(((a) => r.contains(a)))));
|
|
102
|
+
function yt(t, e) {
|
|
103
103
|
if (t === void 0) return;
|
|
104
|
-
if (
|
|
104
|
+
if (ht(t)) return t.getBoundingClientRect();
|
|
105
105
|
if (typeof t == "object") {
|
|
106
|
-
const { top: a = 0, left: s = 0, right: d = 0, bottom:
|
|
107
|
-
return { top: a, right: window.innerWidth - d, bottom: window.innerHeight -
|
|
106
|
+
const { top: a = 0, left: s = 0, right: d = 0, bottom: i = 0 } = t;
|
|
107
|
+
return { top: a, right: window.innerWidth - d, bottom: window.innerHeight - i, left: s };
|
|
108
108
|
}
|
|
109
109
|
if (t === "parent") return e.parentNode.getBoundingClientRect();
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
112
|
-
return
|
|
110
|
+
const r = document.querySelector(t);
|
|
111
|
+
if (r === null) throw new Error("The selector provided for bound doesn't exists in the document.");
|
|
112
|
+
return r.getBoundingClientRect();
|
|
113
113
|
}
|
|
114
|
-
var K = (t, e,
|
|
114
|
+
var K = (t, e, r) => t.style.setProperty(e, r), ht = (t) => t instanceof HTMLElement;
|
|
115
115
|
function tt(t) {
|
|
116
116
|
return t == null || typeof t == "string" || t instanceof HTMLElement ? t : "current" in t ? t.current : Array.isArray(t) ? t.map(((e) => e instanceof HTMLElement ? e : e.current)) : void 0;
|
|
117
117
|
}
|
|
118
|
-
function
|
|
119
|
-
const
|
|
120
|
-
let { onDragStart: f, onDrag: v, onDragEnd:
|
|
121
|
-
function
|
|
122
|
-
|
|
118
|
+
function Lt(t, e = {}) {
|
|
119
|
+
const r = G(), [a, s] = J(!1), [d, i] = J();
|
|
120
|
+
let { onDragStart: f, onDrag: v, onDragEnd: M, handle: A, cancel: I } = e, D = tt(A), R = tt(I);
|
|
121
|
+
function b(c, N) {
|
|
122
|
+
i(c), N == null || N(c);
|
|
123
123
|
}
|
|
124
|
-
function
|
|
125
|
-
s(!0),
|
|
124
|
+
function E(c) {
|
|
125
|
+
s(!0), b(c, f);
|
|
126
126
|
}
|
|
127
|
-
function
|
|
128
|
-
|
|
127
|
+
function L(c) {
|
|
128
|
+
b(c, v);
|
|
129
129
|
}
|
|
130
|
-
function
|
|
131
|
-
s(!1),
|
|
130
|
+
function X(c) {
|
|
131
|
+
s(!1), b(c, M);
|
|
132
132
|
}
|
|
133
|
-
return
|
|
133
|
+
return nt((() => {
|
|
134
134
|
if (typeof window > "u") return;
|
|
135
|
-
const
|
|
136
|
-
if (!
|
|
137
|
-
({ onDragStart: f, onDrag: v, onDragEnd:
|
|
138
|
-
const { update:
|
|
139
|
-
return
|
|
140
|
-
}), []),
|
|
141
|
-
var
|
|
142
|
-
(
|
|
135
|
+
const c = t.current;
|
|
136
|
+
if (!c) return;
|
|
137
|
+
({ onDragStart: f, onDrag: v, onDragEnd: M } = e);
|
|
138
|
+
const { update: N, destroy: O } = Tt(c, { ...e, handle: D, cancel: R, onDragStart: E, onDrag: L, onDragEnd: X });
|
|
139
|
+
return r.current = N, O;
|
|
140
|
+
}), []), nt((() => {
|
|
141
|
+
var c;
|
|
142
|
+
(c = r.current) == null || c.call(r, { ...e, handle: tt(A), cancel: tt(I), onDragStart: E, onDrag: L, onDragEnd: X });
|
|
143
143
|
}), [e]), { isDragging: a, dragState: d };
|
|
144
144
|
}
|
|
145
145
|
const Q = "tiny-canvas-queue";
|
|
@@ -153,39 +153,39 @@ function Mt() {
|
|
|
153
153
|
return localStorage.setItem(Q, JSON.stringify([])), [];
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
|
-
const
|
|
156
|
+
const Xt = (t) => {
|
|
157
157
|
if (!t) return null;
|
|
158
158
|
let e = null;
|
|
159
|
-
const
|
|
159
|
+
const r = (a) => {
|
|
160
160
|
if (a.props && a.props.id) {
|
|
161
161
|
e = a.props.id;
|
|
162
162
|
return;
|
|
163
163
|
}
|
|
164
|
-
a.props && a.props.children && xt.Children.forEach(a.props.children,
|
|
164
|
+
a.props && a.props.children && xt.Children.forEach(a.props.children, r);
|
|
165
165
|
};
|
|
166
|
-
return
|
|
166
|
+
return r(t), e;
|
|
167
167
|
};
|
|
168
|
-
function
|
|
168
|
+
function Yt(t) {
|
|
169
169
|
let e = 5381;
|
|
170
|
-
for (let
|
|
171
|
-
e = (e << 5) + e + t.charCodeAt(
|
|
170
|
+
for (let r = 0; r < t.length; r++)
|
|
171
|
+
e = (e << 5) + e + t.charCodeAt(r) >>> 0;
|
|
172
172
|
return e.toString(16).padStart(8, "0");
|
|
173
173
|
}
|
|
174
174
|
function At(t) {
|
|
175
175
|
var d;
|
|
176
176
|
if (t == null || typeof t == "boolean") return "";
|
|
177
177
|
if (typeof t == "string" || typeof t == "number") return "#text";
|
|
178
|
-
const e = t.type,
|
|
179
|
-
if (a == null) return
|
|
178
|
+
const e = t.type, r = typeof e == "function" ? e.displayName || e.name || "Anonymous" : typeof e == "string" ? e : "Fragment", a = (d = t.props) == null ? void 0 : d.children;
|
|
179
|
+
if (a == null) return r;
|
|
180
180
|
const s = [];
|
|
181
|
-
return xt.Children.forEach(a, (
|
|
182
|
-
const f = At(
|
|
181
|
+
return xt.Children.forEach(a, (i) => {
|
|
182
|
+
const f = At(i);
|
|
183
183
|
f && s.push(f);
|
|
184
|
-
}), s.length ? `${
|
|
184
|
+
}), s.length ? `${r}(${s.join(",")})` : r;
|
|
185
185
|
}
|
|
186
|
-
const
|
|
187
|
-
const
|
|
188
|
-
return `tc-${
|
|
186
|
+
const Pt = (t, e) => {
|
|
187
|
+
const r = At(t);
|
|
188
|
+
return `tc-${Yt(r)}-${e}`;
|
|
189
189
|
}, Ft = (t) => {
|
|
190
190
|
try {
|
|
191
191
|
return Mt().reduce((a, s) => (a[s.id] = { id: s.id, x: s.x, y: s.y }, a), {})[t] || { x: 0, y: 0 };
|
|
@@ -198,16 +198,16 @@ const Yt = (t, e) => {
|
|
|
198
198
|
} catch (t) {
|
|
199
199
|
console.error("LocalStorage is not available:", t);
|
|
200
200
|
}
|
|
201
|
-
}, qt = (t, e,
|
|
201
|
+
}, qt = (t, e, r) => {
|
|
202
202
|
try {
|
|
203
|
-
const a = Mt(), s = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-"), d = { id: t, x: e, y:
|
|
204
|
-
|
|
203
|
+
const a = Mt(), s = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-"), d = { id: t, x: e, y: r, time: s }, i = a.findIndex((f) => f.id === t);
|
|
204
|
+
i >= 0 ? a[i] = d : a.push(d), localStorage.setItem(Q, JSON.stringify(a));
|
|
205
205
|
} catch (a) {
|
|
206
206
|
console.error("Error saving drag position:", a);
|
|
207
207
|
}
|
|
208
208
|
}, Ot = 250, wt = 4, $t = 20, et = 1.5, _t = 150, Ht = 8;
|
|
209
|
-
function kt({ children: t, dragId: e, initialPosition:
|
|
210
|
-
const d =
|
|
209
|
+
function kt({ children: t, dragId: e, initialPosition: r, onDragEnd: a, handle: s }) {
|
|
210
|
+
const d = G(null), i = r || { x: 0, y: 0 }, f = G(i), v = G(!1), [M, A] = J(!1), I = G({
|
|
211
211
|
timer: null,
|
|
212
212
|
startX: 0,
|
|
213
213
|
startY: 0,
|
|
@@ -215,65 +215,67 @@ function kt({ children: t, dragId: e, initialPosition: o, onDragEnd: a, handle:
|
|
|
215
215
|
distanceMet: !1,
|
|
216
216
|
active: !1,
|
|
217
217
|
lastEvent: null
|
|
218
|
-
}), [
|
|
218
|
+
}), [D, R] = J(i), [b, E] = J(i);
|
|
219
|
+
r && (r.x !== b.x || r.y !== b.y) && (E(r), R(r));
|
|
220
|
+
const [L, X] = J(
|
|
219
221
|
() => Math.random() < 0.5 ? -et : et
|
|
220
222
|
);
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
|
|
223
|
+
nt(() => {
|
|
224
|
+
const p = d.current;
|
|
225
|
+
if (p && e && (i.x !== 0 || i.y !== 0)) {
|
|
226
|
+
p.classList.add("tc-on-translation");
|
|
227
|
+
const o = setTimeout(() => {
|
|
228
|
+
p.classList.remove("tc-on-translation");
|
|
227
229
|
}, Ot * 4);
|
|
228
230
|
return () => {
|
|
229
|
-
clearTimeout(
|
|
231
|
+
clearTimeout(o);
|
|
230
232
|
};
|
|
231
233
|
}
|
|
232
|
-
}, [e,
|
|
233
|
-
const
|
|
234
|
-
if (!
|
|
235
|
-
const
|
|
234
|
+
}, [e, i.x, i.y]), nt(() => {
|
|
235
|
+
const p = d.current;
|
|
236
|
+
if (!p || !s) return;
|
|
237
|
+
const o = I.current;
|
|
236
238
|
let w = null;
|
|
237
|
-
function
|
|
238
|
-
const
|
|
239
|
-
return
|
|
239
|
+
function H(g) {
|
|
240
|
+
const x = p.querySelector(s);
|
|
241
|
+
return x && x.contains(g.target);
|
|
240
242
|
}
|
|
241
|
-
function
|
|
242
|
-
if (
|
|
243
|
+
function S(g) {
|
|
244
|
+
if (g === w) {
|
|
243
245
|
w = null;
|
|
244
246
|
return;
|
|
245
247
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
+
H(g) && (g.stopImmediatePropagation(), o.active = !0, o.delayMet = !1, o.distanceMet = !1, o.startX = g.clientX, o.startY = g.clientY, o.target = g.target, o.pointerId = g.pointerId, o.button = g.button, o.pointerType = g.pointerType, clearTimeout(o.timer), o.timer = setTimeout(() => {
|
|
249
|
+
o.delayMet = !0, T();
|
|
248
250
|
}, _t));
|
|
249
251
|
}
|
|
250
|
-
function
|
|
251
|
-
if (
|
|
252
|
-
const
|
|
252
|
+
function T() {
|
|
253
|
+
if (o.delayMet && o.distanceMet && o.active && o.target) {
|
|
254
|
+
const g = new PointerEvent("pointerdown", {
|
|
253
255
|
bubbles: !0,
|
|
254
256
|
cancelable: !0,
|
|
255
|
-
pointerId:
|
|
256
|
-
clientX:
|
|
257
|
-
clientY:
|
|
258
|
-
button:
|
|
259
|
-
pointerType:
|
|
257
|
+
pointerId: o.pointerId,
|
|
258
|
+
clientX: o.startX,
|
|
259
|
+
clientY: o.startY,
|
|
260
|
+
button: o.button,
|
|
261
|
+
pointerType: o.pointerType
|
|
260
262
|
});
|
|
261
|
-
w =
|
|
263
|
+
w = g, o.target.dispatchEvent(g), o.target = null;
|
|
262
264
|
}
|
|
263
265
|
}
|
|
264
|
-
function
|
|
265
|
-
if (!
|
|
266
|
-
const
|
|
267
|
-
Math.hypot(
|
|
266
|
+
function j(g) {
|
|
267
|
+
if (!o.active || o.distanceMet) return;
|
|
268
|
+
const x = g.clientX - o.startX, Y = g.clientY - o.startY;
|
|
269
|
+
Math.hypot(x, Y) >= Ht && (o.distanceMet = !0, T());
|
|
268
270
|
}
|
|
269
|
-
function
|
|
270
|
-
clearTimeout(
|
|
271
|
+
function $() {
|
|
272
|
+
clearTimeout(o.timer), o.active = !1, o.target = null;
|
|
271
273
|
}
|
|
272
|
-
return
|
|
273
|
-
|
|
274
|
+
return p.addEventListener("pointerdown", S, !0), document.addEventListener("pointermove", j), document.addEventListener("pointerup", $), () => {
|
|
275
|
+
p.removeEventListener("pointerdown", S, !0), document.removeEventListener("pointermove", j), document.removeEventListener("pointerup", $), clearTimeout(o.timer);
|
|
274
276
|
};
|
|
275
277
|
}, [s]);
|
|
276
|
-
const { isDragging:
|
|
278
|
+
const { isDragging: c } = Lt(d, {
|
|
277
279
|
axis: "both",
|
|
278
280
|
bounds: "parent",
|
|
279
281
|
defaultClass: "tc-drag",
|
|
@@ -281,32 +283,32 @@ function kt({ children: t, dragId: e, initialPosition: o, onDragEnd: a, handle:
|
|
|
281
283
|
defaultClassDragged: "tc-off",
|
|
282
284
|
applyUserSelectHack: !0,
|
|
283
285
|
...s ? { handle: s } : {},
|
|
284
|
-
position: { x:
|
|
286
|
+
position: { x: D.x, y: D.y },
|
|
285
287
|
onDragStart: () => {
|
|
286
|
-
f.current =
|
|
288
|
+
f.current = D, v.current = !1, A(!1);
|
|
287
289
|
},
|
|
288
|
-
onDrag: ({ offsetX:
|
|
289
|
-
const w =
|
|
290
|
-
!v.current &&
|
|
290
|
+
onDrag: ({ offsetX: p, offsetY: o }) => {
|
|
291
|
+
const w = p - f.current.x, H = o - f.current.y, S = Math.hypot(w, H);
|
|
292
|
+
!v.current && S >= wt && (v.current = !0), !M && S >= $t && A(!0), R({ x: Math.max(0, p), y: Math.max(0, o) });
|
|
291
293
|
},
|
|
292
|
-
onDragEnd: (
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
(v.current || Math.hypot(
|
|
294
|
+
onDragEnd: (p) => {
|
|
295
|
+
const o = Math.max(0, p.offsetX), w = Math.max(0, p.offsetY);
|
|
296
|
+
R({ x: o, y: w }), X(Math.random() < 0.5 ? -et : et), A(!1);
|
|
297
|
+
const H = o - f.current.x, S = w - f.current.y;
|
|
298
|
+
(v.current || Math.hypot(H, S) >= wt) && (e && qt(e, o, w), a == null || a(e, { x: o, y: w }));
|
|
297
299
|
}
|
|
298
|
-
}),
|
|
299
|
-
return /* @__PURE__ */
|
|
300
|
+
}), N = c && M ? `${L}deg` : "0deg";
|
|
301
|
+
return /* @__PURE__ */ rt(
|
|
300
302
|
"article",
|
|
301
303
|
{
|
|
302
304
|
ref: d,
|
|
303
|
-
style: { cursor: s ?
|
|
304
|
-
children: /* @__PURE__ */
|
|
305
|
+
style: { cursor: s ? c ? "grabbing" : void 0 : c ? "grabbing" : "grab" },
|
|
306
|
+
children: /* @__PURE__ */ rt(
|
|
305
307
|
"div",
|
|
306
308
|
{
|
|
307
309
|
className: "tc-draggable-inner",
|
|
308
310
|
style: {
|
|
309
|
-
transform:
|
|
311
|
+
transform: c ? `rotate(${N})` : void 0,
|
|
310
312
|
transition: "transform ease-in-out 150ms"
|
|
311
313
|
},
|
|
312
314
|
children: t
|
|
@@ -317,8 +319,8 @@ function kt({ children: t, dragId: e, initialPosition: o, onDragEnd: a, handle:
|
|
|
317
319
|
}
|
|
318
320
|
function Bt(t) {
|
|
319
321
|
var a, s;
|
|
320
|
-
const e = Number((a = t == null ? void 0 : t.props) == null ? void 0 : a["data-tc-x"]),
|
|
321
|
-
return Number.isFinite(e) && Number.isFinite(
|
|
322
|
+
const e = Number((a = t == null ? void 0 : t.props) == null ? void 0 : a["data-tc-x"]), r = Number((s = t == null ? void 0 : t.props) == null ? void 0 : s["data-tc-y"]);
|
|
323
|
+
return Number.isFinite(e) && Number.isFinite(r) ? { x: Math.max(0, e), y: Math.max(0, r) } : null;
|
|
322
324
|
}
|
|
323
325
|
function Ut(t) {
|
|
324
326
|
var e;
|
|
@@ -327,27 +329,27 @@ function Ut(t) {
|
|
|
327
329
|
function Qt({
|
|
328
330
|
children: t,
|
|
329
331
|
dotted: e = !1,
|
|
330
|
-
grid:
|
|
332
|
+
grid: r = !1,
|
|
331
333
|
gridSize: a,
|
|
332
334
|
colorMode: s = "auto",
|
|
333
335
|
onDragEnd: d
|
|
334
336
|
}) {
|
|
335
|
-
return /* @__PURE__ */
|
|
337
|
+
return /* @__PURE__ */ rt(
|
|
336
338
|
"main",
|
|
337
339
|
{
|
|
338
340
|
className: "tc-canvas",
|
|
339
|
-
"data-dotted": e ||
|
|
341
|
+
"data-dotted": e || r || void 0,
|
|
340
342
|
"data-color-mode": s !== "auto" ? s : void 0,
|
|
341
343
|
children: Ct.map(t, (f, v) => {
|
|
342
|
-
const
|
|
343
|
-
return /* @__PURE__ */
|
|
344
|
+
const M = Xt(f) ?? Pt(f, v), A = Bt(f), I = Ut(f);
|
|
345
|
+
return /* @__PURE__ */ rt(
|
|
344
346
|
kt,
|
|
345
347
|
{
|
|
346
348
|
gridSize: a,
|
|
347
|
-
dragId:
|
|
348
|
-
initialPosition:
|
|
349
|
+
dragId: M,
|
|
350
|
+
initialPosition: A,
|
|
349
351
|
onDragEnd: d,
|
|
350
|
-
handle:
|
|
352
|
+
handle: I,
|
|
351
353
|
children: f
|
|
352
354
|
},
|
|
353
355
|
v
|
|
@@ -357,7 +359,7 @@ function Qt({
|
|
|
357
359
|
);
|
|
358
360
|
}
|
|
359
361
|
function zt({ reload: t = !1 } = {}) {
|
|
360
|
-
return
|
|
362
|
+
return It(() => {
|
|
361
363
|
try {
|
|
362
364
|
localStorage.removeItem("tiny-canvas-queue");
|
|
363
365
|
} catch (e) {
|
|
@@ -369,8 +371,8 @@ function zt({ reload: t = !1 } = {}) {
|
|
|
369
371
|
export {
|
|
370
372
|
Qt as Canvas,
|
|
371
373
|
kt as Draggable,
|
|
372
|
-
|
|
373
|
-
|
|
374
|
+
Xt as findDragId,
|
|
375
|
+
Pt as generateDragId,
|
|
374
376
|
Ft as getQueue,
|
|
375
377
|
Gt as refreshStorage,
|
|
376
378
|
qt as saveDrag,
|