@liiift-studio/threadtext 0.1.0 → 0.2.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/README.md +20 -13
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +462 -374
- package/dist/threadtext.webflow.min.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import { jsx as
|
|
3
|
-
const
|
|
1
|
+
import { useRef as Tt, useLayoutEffect as Se, useEffect as ne, forwardRef as Ae, useCallback as Fe } from "react";
|
|
2
|
+
import { jsx as Le } from "react/jsx-runtime";
|
|
3
|
+
const zt = {
|
|
4
4
|
/** Base canvas: the baked satin stitches (transparent ground). */
|
|
5
5
|
bg: "tt-bg",
|
|
6
6
|
/** Overlay canvas: cursor sheen (`mix-blend-mode: screen`). */
|
|
@@ -8,95 +8,98 @@ const Bt = {
|
|
|
8
8
|
/** Blinking text caret shown in editable mode. */
|
|
9
9
|
caret: "tt-caret"
|
|
10
10
|
};
|
|
11
|
-
function
|
|
12
|
-
let
|
|
13
|
-
return
|
|
11
|
+
function nt(x, o) {
|
|
12
|
+
let r = Math.imul(x | 0, 374761393) + Math.imul(o | 0, 668265263) | 0;
|
|
13
|
+
return r = Math.imul(r ^ r >>> 13, 1274126177), ((r ^ r >>> 16) >>> 0) / 4294967295;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
const
|
|
17
|
-
return
|
|
15
|
+
function oe(x, o) {
|
|
16
|
+
const r = Math.floor(x), l = Math.floor(o), c = x - r, s = o - l, h = c * c * (3 - 2 * c), L = s * s * (3 - 2 * s), S = nt(r, l), P = nt(r + 1, l), f = nt(r, l + 1), m = nt(r + 1, l + 1);
|
|
17
|
+
return S + (P - S) * h + (f - S) * L + (S - P - f + m) * h * L;
|
|
18
18
|
}
|
|
19
|
-
const
|
|
20
|
-
function
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
for (let
|
|
24
|
-
let
|
|
25
|
-
for (;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
for (let
|
|
31
|
-
for (;
|
|
32
|
-
|
|
19
|
+
const St = 1e20;
|
|
20
|
+
function re(x, o, r, l, c) {
|
|
21
|
+
let s = 0;
|
|
22
|
+
l[0] = 0, c[0] = -St, c[1] = St;
|
|
23
|
+
for (let h = 1; h < o; h++) {
|
|
24
|
+
let L = (x[h] + h * h - (x[l[s]] + l[s] * l[s])) / (2 * h - 2 * l[s]);
|
|
25
|
+
for (; L <= c[s]; )
|
|
26
|
+
s--, L = (x[h] + h * h - (x[l[s]] + l[s] * l[s])) / (2 * h - 2 * l[s]);
|
|
27
|
+
s++, l[s] = h, c[s] = L, c[s + 1] = St;
|
|
28
|
+
}
|
|
29
|
+
s = 0;
|
|
30
|
+
for (let h = 0; h < o; h++) {
|
|
31
|
+
for (; c[s + 1] < h; ) s++;
|
|
32
|
+
r[h] = (h - l[s]) * (h - l[s]) + x[l[s]];
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
const
|
|
37
|
-
for (let
|
|
38
|
-
const
|
|
39
|
-
for (let
|
|
40
|
-
for (let
|
|
41
|
-
|
|
42
|
-
for (let
|
|
43
|
-
}
|
|
44
|
-
for (let
|
|
45
|
-
for (let
|
|
46
|
-
|
|
47
|
-
for (let
|
|
48
|
-
}
|
|
49
|
-
const
|
|
50
|
-
for (let
|
|
51
|
-
return
|
|
35
|
+
function Re(x, o, r) {
|
|
36
|
+
const l = new Float64Array(o * r);
|
|
37
|
+
for (let f = 0; f < o * r; f++) l[f] = x[f] ? St : 0;
|
|
38
|
+
const c = Math.max(o, r), s = new Float64Array(c), h = new Float64Array(c), L = new Int32Array(c), S = new Float64Array(c + 1);
|
|
39
|
+
for (let f = 0; f < o; f++) {
|
|
40
|
+
for (let m = 0; m < r; m++) s[m] = l[m * o + f];
|
|
41
|
+
re(s, r, h, L, S);
|
|
42
|
+
for (let m = 0; m < r; m++) l[m * o + f] = h[m];
|
|
43
|
+
}
|
|
44
|
+
for (let f = 0; f < r; f++) {
|
|
45
|
+
for (let m = 0; m < o; m++) s[m] = l[f * o + m];
|
|
46
|
+
re(s, o, h, L, S);
|
|
47
|
+
for (let m = 0; m < o; m++) l[f * o + m] = h[m];
|
|
48
|
+
}
|
|
49
|
+
const P = new Float32Array(o * r);
|
|
50
|
+
for (let f = 0; f < o * r; f++) P[f] = Math.sqrt(l[f]);
|
|
51
|
+
return P;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
let
|
|
55
|
-
const
|
|
56
|
-
for (let
|
|
57
|
-
for (let
|
|
58
|
-
const
|
|
59
|
-
let
|
|
60
|
-
for (let
|
|
61
|
-
for (let
|
|
62
|
-
|
|
53
|
+
function ie(x, o, r, l, c) {
|
|
54
|
+
let s = Float32Array.from(x);
|
|
55
|
+
const h = new Float32Array(o * r), L = 1 / (2 * l + 1), S = (P, f) => P < 0 ? 0 : P > f ? f : P;
|
|
56
|
+
for (let P = 0; P < c; P++) {
|
|
57
|
+
for (let f = 0; f < r; f++) {
|
|
58
|
+
const m = f * o;
|
|
59
|
+
let B = 0;
|
|
60
|
+
for (let q = -l; q <= l; q++) B += s[m + S(q, o - 1)];
|
|
61
|
+
for (let q = 0; q < o; q++)
|
|
62
|
+
h[m + q] = B * L, B += s[m + S(q + l + 1, o - 1)] - s[m + S(q - l, o - 1)];
|
|
63
63
|
}
|
|
64
|
-
for (let
|
|
65
|
-
let
|
|
66
|
-
for (let
|
|
67
|
-
for (let
|
|
68
|
-
|
|
64
|
+
for (let f = 0; f < o; f++) {
|
|
65
|
+
let m = 0;
|
|
66
|
+
for (let B = -l; B <= l; B++) m += h[S(B, r - 1) * o + f];
|
|
67
|
+
for (let B = 0; B < r; B++)
|
|
68
|
+
s[B * o + f] = m * L, m += h[S(B + l + 1, r - 1) * o + f] - h[S(B - l, r - 1) * o + f];
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
return
|
|
71
|
+
return s;
|
|
72
72
|
}
|
|
73
|
-
function
|
|
74
|
-
if (!
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
let
|
|
78
|
-
if (
|
|
79
|
-
const
|
|
80
|
-
if (!Number.isNaN(
|
|
73
|
+
function ae(x, o) {
|
|
74
|
+
if (!x) return o;
|
|
75
|
+
const r = x.trim();
|
|
76
|
+
if (r[0] === "#") {
|
|
77
|
+
let c = r.slice(1);
|
|
78
|
+
if (c.length === 3 && (c = c[0] + c[0] + c[1] + c[1] + c[2] + c[2]), c.length >= 6) {
|
|
79
|
+
const s = parseInt(c.slice(0, 2), 16), h = parseInt(c.slice(2, 4), 16), L = parseInt(c.slice(4, 6), 16);
|
|
80
|
+
if (!Number.isNaN(s) && !Number.isNaN(h) && !Number.isNaN(L)) return [s, h, L];
|
|
81
81
|
}
|
|
82
|
-
return
|
|
82
|
+
return o;
|
|
83
83
|
}
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
return [Math.round(
|
|
84
|
+
const l = r.match(/rgba?\(([^)]+)\)/i);
|
|
85
|
+
if (l) {
|
|
86
|
+
const c = l[1].split(",").map((s) => parseFloat(s));
|
|
87
|
+
if (c.length >= 3 && c.slice(0, 3).every((s) => !Number.isNaN(s)))
|
|
88
|
+
return [Math.round(c[0]), Math.round(c[1]), Math.round(c[2])];
|
|
89
89
|
}
|
|
90
|
-
return
|
|
90
|
+
return o;
|
|
91
91
|
}
|
|
92
|
-
function
|
|
93
|
-
return
|
|
92
|
+
function J(x) {
|
|
93
|
+
return x < 0 ? 0 : x > 255 ? 255 : Math.round(x);
|
|
94
94
|
}
|
|
95
|
-
function
|
|
96
|
-
return
|
|
95
|
+
function Et(x, o, r) {
|
|
96
|
+
return x < o ? o : x > r ? r : x;
|
|
97
97
|
}
|
|
98
|
-
function
|
|
99
|
-
|
|
98
|
+
function le(x) {
|
|
99
|
+
return (x.split(",")[0] || "serif").trim().replace(/^["']|["']$/g, "");
|
|
100
|
+
}
|
|
101
|
+
function Ie(x, o) {
|
|
102
|
+
if (typeof window > "u" || typeof document > "u" || !x)
|
|
100
103
|
return { setText() {
|
|
101
104
|
}, replay() {
|
|
102
105
|
}, resize() {
|
|
@@ -104,390 +107,475 @@ function pe(m, e) {
|
|
|
104
107
|
}, focus() {
|
|
105
108
|
}, destroy() {
|
|
106
109
|
}, get text() {
|
|
107
|
-
return
|
|
110
|
+
return o.text ?? "";
|
|
108
111
|
} };
|
|
109
|
-
let
|
|
110
|
-
const
|
|
111
|
-
let
|
|
112
|
-
function
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
let
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
let
|
|
122
|
-
const
|
|
123
|
-
let
|
|
124
|
-
function
|
|
125
|
-
const t =
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
112
|
+
let r = o.text ?? "", l = o.font ?? "Georgia, serif", c = Et(o.weight ?? 680, 1, 1e3), s = Et(o.fill ?? 0.9, 0.05, 1), h = Math.max(1, o.sewRate ?? 110), L = o.sewStyle === "hand" ? "hand" : "machine", S = o.sheen ?? !0, P = o.animate ?? !0, f = o.editable ?? !1, m = o.pitch, B = o.onTextChange, q = le(l);
|
|
113
|
+
const gt = o.reducedMotion ?? !!(window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches);
|
|
114
|
+
let N = ae(o.threadColor ?? "#fffbf3", [255, 251, 243]), ft = [0, 0, 0], U = [0, 0, 0];
|
|
115
|
+
function dt(t) {
|
|
116
|
+
N = ae(t, [255, 251, 243]), ft = [N[0] * 0.585, N[1] * 0.585, N[2] * 0.585], U = [N[0] * 0.47, N[1] * 0.47, N[2] * 0.47];
|
|
117
|
+
}
|
|
118
|
+
dt(o.threadColor ?? "#fffbf3");
|
|
119
|
+
const Y = [];
|
|
120
|
+
let O, k;
|
|
121
|
+
x instanceof HTMLCanvasElement ? (O = x, k = x.parentElement ?? x) : (k = x, O = document.createElement("canvas"), Y.push(O), k.appendChild(O)), O.classList.add(zt.bg);
|
|
122
|
+
const X = document.createElement("canvas");
|
|
123
|
+
Y.push(X), X.classList.add(zt.fx), k.appendChild(X), getComputedStyle(k).position === "static" && (k.style.position = "relative"), O.style.display = "block", O.style.width = "100%", Object.assign(X.style, { position: "absolute", inset: "0", width: "100%", pointerEvents: "none", mixBlendMode: "screen" });
|
|
124
|
+
let w = null, F = null, W = !1, d = 0, g = 0, ot = 0, At = 0, rt = 4, it = [], ut = 0, ht = 0, qt = -1, _t = "", Gt = -1, Ut = -1, Ft = new Uint8Array(0), Lt = new Float32Array(0), pt = new Float32Array(0), wt = new Float32Array(0), Q = null, at = null, Mt = null, lt = [], tt = 3;
|
|
125
|
+
const I = { rows: [], idx: 0, acc: 0, rate: 0, on: !1 }, H = { x: 0, y: 0, set: !1 };
|
|
126
|
+
let et = !0, Rt = 0, mt = !1, yt = 0, K = !1, Z = !1;
|
|
127
|
+
function ce() {
|
|
128
|
+
const t = k.getBoundingClientRect(), e = Math.max(1, Math.round(t.width || Math.min(window.innerWidth * 0.95, 1240))), i = r || "Ag", u = O.getContext("2d");
|
|
129
|
+
u && (u.textBaseline = "middle");
|
|
130
|
+
let T = 100;
|
|
131
|
+
u && (u.font = `${c} 100px ${l}`, T = u.measureText(i).width || 100);
|
|
132
|
+
const C = Math.max(8, 100 * (e * s) / T);
|
|
133
|
+
let b = C * 0.62, A = C * 0.62, E = e * s;
|
|
134
|
+
if (u) {
|
|
135
|
+
u.font = `${c} ${C}px ${l}`;
|
|
136
|
+
const a = u.measureText(i);
|
|
137
|
+
E = a.width || E, a.actualBoundingBoxAscent > 0 && (b = a.actualBoundingBoxAscent), a.actualBoundingBoxDescent > 0 && (A = a.actualBoundingBoxDescent);
|
|
133
138
|
}
|
|
134
|
-
const
|
|
135
|
-
let
|
|
136
|
-
for (;
|
|
137
|
-
|
|
138
|
-
for (const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
function
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
function
|
|
146
|
-
const t = Math.max(7,
|
|
147
|
-
|
|
148
|
-
for (let
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
if (!
|
|
153
|
-
|
|
139
|
+
const M = Math.max(1, Math.round(2 * Math.max(b, A) * 1.1));
|
|
140
|
+
let n = Math.min(window.devicePixelRatio || 1, 1.7);
|
|
141
|
+
for (; e * n * M * n > 9e5 && n > 0.4; ) n -= 0.1;
|
|
142
|
+
d = Math.max(1, Math.round(e * n)), g = Math.max(1, Math.round(M * n)), ot = Math.max(4, Math.round(C * n)), At = Math.round(d / 2 - E * n / 2);
|
|
143
|
+
for (const a of [O, X])
|
|
144
|
+
a.width = d, a.height = g, a.style.height = M + "px";
|
|
145
|
+
k.style.height = M + "px", rt = m ?? Math.max(3, g * 95e-4);
|
|
146
|
+
}
|
|
147
|
+
function se() {
|
|
148
|
+
at && Gt === d && Ut === g || (at = document.createElement("canvas"), at.width = d, at.height = g, Mt = at.getContext("2d", { willReadFrequently: !0 }), Gt = d, Ut = g);
|
|
149
|
+
}
|
|
150
|
+
function Xt() {
|
|
151
|
+
const t = Math.max(7, rt * 2.5), e = Math.max(3.2, rt * 1.3);
|
|
152
|
+
ut = Math.ceil(t) + 2, ht = Math.ceil(e) + 2, it = [];
|
|
153
|
+
for (let i = 0; i < 20; i++) {
|
|
154
|
+
const u = 0.34 + i / 19 * 0.82, T = document.createElement("canvas");
|
|
155
|
+
T.width = ut, T.height = ht;
|
|
156
|
+
const C = T.getContext("2d");
|
|
157
|
+
if (!C) {
|
|
158
|
+
it.push(T);
|
|
154
159
|
continue;
|
|
155
160
|
}
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
|
|
161
|
+
const b = ut / 2, A = ht / 2, E = C.createLinearGradient(0, A - e / 2, 0, A + e / 2), M = (R, $) => `rgba(${J(R[0] * u)},${J(R[1] * u)},${J(R[2] * u)},${$})`;
|
|
162
|
+
E.addColorStop(0, M(U, 0)), E.addColorStop(0.16, M(ft, 1)), E.addColorStop(0.5, M(N, 1)), E.addColorStop(0.84, M(ft, 1)), E.addColorStop(1, M(U, 0)), C.fillStyle = E, C.beginPath();
|
|
163
|
+
const n = e / 2;
|
|
164
|
+
C.moveTo(b - t / 2 + n, A - n), C.lineTo(b + t / 2 - n, A - n), C.arc(b + t / 2 - n, A, n, -Math.PI / 2, Math.PI / 2), C.lineTo(b - t / 2 + n, A + n), C.arc(b - t / 2 + n, A, n, Math.PI / 2, -Math.PI / 2), C.closePath(), C.fill(), C.globalCompositeOperation = "destination-in";
|
|
165
|
+
const a = C.createLinearGradient(b - t / 2, 0, b + t / 2, 0);
|
|
166
|
+
a.addColorStop(0, "rgba(0,0,0,0)"), a.addColorStop(0.22, "rgba(0,0,0,1)"), a.addColorStop(0.78, "rgba(0,0,0,1)"), a.addColorStop(1, "rgba(0,0,0,0)"), C.fillStyle = a, C.fillRect(0, 0, ut, ht), it.push(T);
|
|
162
167
|
}
|
|
168
|
+
qt = rt, _t = N.join(",");
|
|
163
169
|
}
|
|
164
|
-
function
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
function fe() {
|
|
171
|
+
it.length && qt === rt && _t === N.join(",") || Xt();
|
|
172
|
+
}
|
|
173
|
+
function de() {
|
|
174
|
+
if (!Mt) return;
|
|
175
|
+
const t = Mt;
|
|
176
|
+
t.clearRect(0, 0, d, g), t.fillStyle = "#fff", t.textAlign = "left", t.textBaseline = "middle", t.font = `${c} ${ot}px ${l}`, t.fillText(r, At, g * 0.5);
|
|
177
|
+
const e = t.getImageData(0, 0, d, g).data, i = new Uint8Array(d * g);
|
|
178
|
+
for (let y = 0; y < g; y++) for (let p = 0; p < d; p++) {
|
|
179
|
+
const v = y * d + p, _ = e[v * 4 + 3] / 255, z = oe(p * 0.5, y * 0.5) * 0.22 + oe(p * 1.8, y * 1.8) * 0.1;
|
|
180
|
+
i[v] = _ > 0.5 + (z - 0.16) ? 1 : 0;
|
|
172
181
|
}
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
for (let
|
|
176
|
-
const
|
|
177
|
-
v
|
|
182
|
+
Ft = i;
|
|
183
|
+
const u = Re(i, d, g), T = new Float32Array(d * g);
|
|
184
|
+
for (let y = 1; y < g - 1; y++) for (let p = 1; p < d - 1; p++) {
|
|
185
|
+
const v = y * d + p;
|
|
186
|
+
T[v] = (u[v] * 4 + u[v - 1] + u[v + 1] + u[v - d] + u[v + d]) / 8;
|
|
178
187
|
}
|
|
179
|
-
const
|
|
180
|
-
for (let
|
|
181
|
-
const
|
|
182
|
-
if (!
|
|
183
|
-
const
|
|
184
|
-
|
|
188
|
+
const C = new Float32Array(d * g), b = new Float32Array(d * g), A = new Float32Array(d * g), E = new Float32Array(d * g);
|
|
189
|
+
for (let y = 1; y < g - 1; y++) for (let p = 1; p < d - 1; p++) {
|
|
190
|
+
const v = y * d + p;
|
|
191
|
+
if (!i[v]) continue;
|
|
192
|
+
const _ = (T[v + 1] - T[v - 1]) * 0.5, z = (T[v + d] - T[v - d]) * 0.5;
|
|
193
|
+
A[v] = _, E[v] = z, C[v] = _ * _ - z * z, b[v] = 2 * _ * z;
|
|
185
194
|
}
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
for (let
|
|
189
|
-
if (!
|
|
190
|
-
const
|
|
191
|
-
|
|
195
|
+
const M = Math.max(7, Math.round(g * 0.05)), n = ie(C, d, g, M, 2), a = ie(b, d, g, M, 2);
|
|
196
|
+
pt = new Float32Array(d * g), wt = new Float32Array(d * g);
|
|
197
|
+
for (let y = 0; y < d * g; y++) {
|
|
198
|
+
if (!i[y]) continue;
|
|
199
|
+
const p = 0.5 * Math.atan2(a[y], n[y]);
|
|
200
|
+
pt[y] = Math.cos(p), wt[y] = Math.sin(p);
|
|
192
201
|
}
|
|
193
|
-
const
|
|
194
|
-
for (let
|
|
195
|
-
const
|
|
196
|
-
if (!
|
|
197
|
-
let
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
let
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
let
|
|
205
|
-
|
|
206
|
-
const
|
|
207
|
-
|
|
202
|
+
const R = Math.max(9, g * 0.04), $ = new Float32Array(d * g), G = -0.45, V = -0.62, D = 0.64;
|
|
203
|
+
for (let y = 1; y < g - 1; y++) for (let p = 1; p < d - 1; p++) {
|
|
204
|
+
const v = y * d + p;
|
|
205
|
+
if (!i[v]) continue;
|
|
206
|
+
let _ = A[v], z = E[v];
|
|
207
|
+
const xt = Math.hypot(_, z) || 1;
|
|
208
|
+
_ /= xt, z /= xt;
|
|
209
|
+
const Wt = T[v], te = (1 - Math.min(Wt / R, 1)) * 1.25;
|
|
210
|
+
let Nt = -_ * te, Ot = -z * te;
|
|
211
|
+
const ee = 1.5, Dt = Math.hypot(Nt, Ot, ee);
|
|
212
|
+
Nt /= Dt, Ot /= Dt;
|
|
213
|
+
let jt = Nt * G + Ot * V + ee / Dt * D;
|
|
214
|
+
jt < 0 && (jt = 0);
|
|
215
|
+
const Ee = Math.min(1, 0.45 + 0.55 * Math.min(Wt / (R * 0.7), 1));
|
|
216
|
+
$[v] = Math.min(1.12, (0.5 + 0.75 * jt) * Ee);
|
|
208
217
|
}
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
if (
|
|
212
|
-
const
|
|
213
|
-
for (let
|
|
214
|
-
|
|
218
|
+
Lt = $, Q = document.createElement("canvas"), Q.width = d, Q.height = g;
|
|
219
|
+
const j = Q.getContext("2d");
|
|
220
|
+
if (j) {
|
|
221
|
+
const y = j.createImageData(d, g);
|
|
222
|
+
for (let p = 0; p < d * g; p++) i[p] && (y.data[p * 4] = 255, y.data[p * 4 + 1] = 255, y.data[p * 4 + 2] = 255, y.data[p * 4 + 3] = 255);
|
|
223
|
+
j.putImageData(y, 0, 0);
|
|
215
224
|
}
|
|
216
225
|
}
|
|
217
|
-
function
|
|
218
|
-
const t = Math.max(1.6,
|
|
219
|
-
|
|
220
|
-
const
|
|
221
|
-
for (let
|
|
222
|
-
const
|
|
223
|
-
if (
|
|
224
|
-
const
|
|
225
|
-
if (!
|
|
226
|
-
const
|
|
227
|
-
let
|
|
228
|
-
|
|
226
|
+
function ue() {
|
|
227
|
+
const t = Math.max(1.6, rt * 0.6);
|
|
228
|
+
tt = t;
|
|
229
|
+
const e = [];
|
|
230
|
+
for (let i = 0; i < g; i += t) for (let u = 0; u < d; u += t) {
|
|
231
|
+
const T = (nt(Math.floor(u), Math.floor(i)) - 0.5) * t * 0.9, C = (nt(Math.floor(i), Math.floor(u)) - 0.5) * t * 0.9, b = Math.round(u + T), A = Math.round(i + C);
|
|
232
|
+
if (b < 1 || A < 1 || b >= d - 1 || A >= g - 1) continue;
|
|
233
|
+
const E = A * d + b;
|
|
234
|
+
if (!Ft[E]) continue;
|
|
235
|
+
const M = Math.atan2(wt[E], pt[E]), n = 0.86 + nt(b * 7, A * 13) * 0.18;
|
|
236
|
+
let a = Lt[E] * n;
|
|
237
|
+
a = a < 0 ? 0 : a > 1.12 ? 1.12 : a, e.push({ x: b, y: A, ang: M, idx: Math.min(19, Math.max(0, Math.round(a / 1.12 * 19))) });
|
|
229
238
|
}
|
|
230
|
-
|
|
239
|
+
lt = e;
|
|
231
240
|
}
|
|
232
|
-
function
|
|
233
|
-
t.save(), t.translate(
|
|
241
|
+
function Kt(t, e) {
|
|
242
|
+
t.save(), t.translate(e.x, e.y), t.rotate(e.ang), t.drawImage(it[e.idx], -ut / 2, -ht / 2), t.restore();
|
|
234
243
|
}
|
|
235
|
-
function
|
|
236
|
-
const t =
|
|
244
|
+
function It() {
|
|
245
|
+
const t = O.getContext("2d");
|
|
237
246
|
if (t)
|
|
238
|
-
for (const
|
|
247
|
+
for (const e of lt) Kt(t, e);
|
|
239
248
|
}
|
|
240
|
-
function
|
|
241
|
-
const t =
|
|
242
|
-
t && t.clearRect(0, 0,
|
|
249
|
+
function $t() {
|
|
250
|
+
const t = O.getContext("2d");
|
|
251
|
+
t && t.clearRect(0, 0, d, g);
|
|
243
252
|
}
|
|
244
|
-
function
|
|
253
|
+
function he(t) {
|
|
245
254
|
if (!t.length) return [];
|
|
246
|
-
const
|
|
247
|
-
t.forEach((
|
|
248
|
-
const
|
|
249
|
-
let
|
|
250
|
-
|
|
255
|
+
const e = Math.max(4, tt * 1.5), i = /* @__PURE__ */ new Map(), u = (M, n) => M + "," + n;
|
|
256
|
+
t.forEach((M, n) => {
|
|
257
|
+
const a = u(Math.floor(M.x / e), Math.floor(M.y / e));
|
|
258
|
+
let R = i.get(a);
|
|
259
|
+
R || i.set(a, R = []), R.push(n);
|
|
251
260
|
});
|
|
252
|
-
const
|
|
253
|
-
function
|
|
254
|
-
const
|
|
255
|
-
for (let
|
|
256
|
-
const
|
|
257
|
-
if (
|
|
258
|
-
for (const
|
|
259
|
-
if (
|
|
260
|
-
const
|
|
261
|
-
|
|
261
|
+
const T = tt * 1.8 * (tt * 1.8);
|
|
262
|
+
function C(M) {
|
|
263
|
+
const n = t[M], a = Math.floor(n.x / e), R = Math.floor(n.y / e), $ = [];
|
|
264
|
+
for (let G = -1; G <= 1; G++) for (let V = -1; V <= 1; V++) {
|
|
265
|
+
const D = i.get(u(a + G, R + V));
|
|
266
|
+
if (D)
|
|
267
|
+
for (const j of D) {
|
|
268
|
+
if (j === M) continue;
|
|
269
|
+
const y = t[j].x - n.x, p = t[j].y - n.y;
|
|
270
|
+
y * y + p * p <= T && $.push(j);
|
|
262
271
|
}
|
|
263
272
|
}
|
|
264
|
-
return
|
|
273
|
+
return $;
|
|
265
274
|
}
|
|
266
|
-
const
|
|
267
|
-
for (const
|
|
268
|
-
if (
|
|
269
|
-
let
|
|
270
|
-
for (
|
|
271
|
-
|
|
272
|
-
const
|
|
273
|
-
for (const
|
|
274
|
-
|
|
275
|
+
const b = new Uint8Array(t.length), A = [], E = t.map((M, n) => n).sort((M, n) => t[M].x + t[M].y - (t[n].x + t[n].y));
|
|
276
|
+
for (const M of E) {
|
|
277
|
+
if (b[M]) continue;
|
|
278
|
+
let n = [M];
|
|
279
|
+
for (b[M] = 1; n.length; ) {
|
|
280
|
+
A.push(n.map((R) => t[R]));
|
|
281
|
+
const a = [];
|
|
282
|
+
for (const R of n) for (const $ of C(R)) b[$] || (b[$] = 1, a.push($));
|
|
283
|
+
n = a;
|
|
275
284
|
}
|
|
276
285
|
}
|
|
277
|
-
return
|
|
286
|
+
return A;
|
|
278
287
|
}
|
|
279
|
-
function
|
|
280
|
-
if (
|
|
281
|
-
|
|
288
|
+
function me(t) {
|
|
289
|
+
if (!t.length) return [];
|
|
290
|
+
const e = Math.max(4, tt * 1.5), i = /* @__PURE__ */ new Map(), u = (n, a) => n + "," + a;
|
|
291
|
+
t.forEach((n, a) => {
|
|
292
|
+
const R = u(Math.floor(n.x / e), Math.floor(n.y / e));
|
|
293
|
+
let $ = i.get(R);
|
|
294
|
+
$ || i.set(R, $ = []), $.push(a);
|
|
295
|
+
});
|
|
296
|
+
const T = tt * 1.8 * (tt * 1.8), C = (n) => {
|
|
297
|
+
const a = t[n], R = u(Math.floor(a.x / e), Math.floor(a.y / e)), $ = i.get(R);
|
|
298
|
+
if (!$) return;
|
|
299
|
+
const G = $.indexOf(n);
|
|
300
|
+
G >= 0 && $.splice(G, 1), $.length || i.delete(R);
|
|
301
|
+
};
|
|
302
|
+
function b(n) {
|
|
303
|
+
const a = t[n], R = Math.floor(a.x / e), $ = Math.floor(a.y / e);
|
|
304
|
+
let G = -1, V = 1 / 0;
|
|
305
|
+
for (let D = -1; D <= 1; D++) for (let j = -1; j <= 1; j++) {
|
|
306
|
+
const y = i.get(u(R + D, $ + j));
|
|
307
|
+
if (y)
|
|
308
|
+
for (const p of y) {
|
|
309
|
+
const v = t[p].x - a.x, _ = t[p].y - a.y, z = v * v + _ * _;
|
|
310
|
+
z <= T && z < V && (V = z, G = p);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return G;
|
|
314
|
+
}
|
|
315
|
+
function A(n) {
|
|
316
|
+
const a = t[n], R = Math.floor(a.x / e), $ = Math.floor(a.y / e);
|
|
317
|
+
let G = -1, V = 1 / 0;
|
|
318
|
+
for (let D = 1; D < 512; D++) {
|
|
319
|
+
for (let j = -D; j <= D; j++) for (let y = -D; y <= D; y++) {
|
|
320
|
+
if (Math.max(Math.abs(j), Math.abs(y)) !== D) continue;
|
|
321
|
+
const p = i.get(u(R + j, $ + y));
|
|
322
|
+
if (p)
|
|
323
|
+
for (const v of p) {
|
|
324
|
+
const _ = t[v].x - a.x, z = t[v].y - a.y, xt = _ * _ + z * z;
|
|
325
|
+
xt < V && (V = xt, G = v);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (G >= 0 && D > Math.ceil(Math.sqrt(V) / e) + 1) break;
|
|
329
|
+
}
|
|
330
|
+
return G;
|
|
331
|
+
}
|
|
332
|
+
let E = 0;
|
|
333
|
+
for (let n = 1; n < t.length; n++) t[n].x + t[n].y < t[E].x + t[E].y && (E = n);
|
|
334
|
+
const M = [t[E]];
|
|
335
|
+
C(E);
|
|
336
|
+
for (let n = 1; n < t.length; n++) {
|
|
337
|
+
let a = b(E);
|
|
338
|
+
if (a < 0 && (a = A(E)), a < 0) break;
|
|
339
|
+
M.push(t[a]), C(a), E = a;
|
|
340
|
+
}
|
|
341
|
+
return M;
|
|
342
|
+
}
|
|
343
|
+
function ye() {
|
|
344
|
+
if ($t(), gt || !P) {
|
|
345
|
+
It(), I.on = !1;
|
|
282
346
|
return;
|
|
283
347
|
}
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
function
|
|
287
|
-
const
|
|
288
|
-
if (
|
|
289
|
-
for (t >
|
|
290
|
-
const
|
|
291
|
-
for (const
|
|
348
|
+
L === "hand" ? (I.rows = me(lt).map((t) => [t]), I.rate = Math.max(h, lt.length / 3.2)) : (I.rows = he(lt), I.rate = h), I.idx = 0, I.acc = 0, I.on = I.rows.length > 0;
|
|
349
|
+
}
|
|
350
|
+
function xe(t) {
|
|
351
|
+
const e = O.getContext("2d");
|
|
352
|
+
if (e)
|
|
353
|
+
for (t > I.rows.length && (t = I.rows.length); I.idx < t; ) {
|
|
354
|
+
const i = I.rows[I.idx++];
|
|
355
|
+
for (const u of i) Kt(e, u);
|
|
292
356
|
}
|
|
293
357
|
}
|
|
294
|
-
function
|
|
295
|
-
const
|
|
296
|
-
if (!
|
|
297
|
-
const
|
|
298
|
-
|
|
358
|
+
function ge(t, e) {
|
|
359
|
+
const i = X.getContext("2d");
|
|
360
|
+
if (!i || (i.clearRect(0, 0, d, g), !S || !Q)) return;
|
|
361
|
+
const u = d * 0.32, T = i.createRadialGradient(t, e, 0, t, e, u);
|
|
362
|
+
T.addColorStop(0, "rgba(255,250,238,0.18)"), T.addColorStop(0.5, "rgba(255,250,238,0.055)"), T.addColorStop(1, "rgba(255,250,238,0)"), i.fillStyle = T, i.fillRect(0, 0, d, g), i.globalCompositeOperation = "destination-in", i.drawImage(Q, 0, 0), i.globalCompositeOperation = "source-over";
|
|
299
363
|
}
|
|
300
|
-
function
|
|
301
|
-
|
|
364
|
+
function pe() {
|
|
365
|
+
F || !f || (F = document.createElement("span"), F.className = zt.caret, F.setAttribute("aria-hidden", "true"), Object.assign(F.style, { position: "absolute", pointerEvents: "none", borderRadius: "1px", opacity: "0", background: `rgb(${J(N[0])},${J(N[1])},${J(N[2])})` }), k.appendChild(F), Y.push(F));
|
|
302
366
|
}
|
|
303
|
-
function
|
|
304
|
-
if (!
|
|
305
|
-
const t =
|
|
367
|
+
function kt() {
|
|
368
|
+
if (!f || !F) return;
|
|
369
|
+
const t = O.getContext("2d");
|
|
306
370
|
if (!t) return;
|
|
307
|
-
t.font = `${
|
|
308
|
-
const
|
|
309
|
-
|
|
371
|
+
t.font = `${c} ${ot}px ${l}`;
|
|
372
|
+
const e = t.measureText(r).width, i = (O.clientWidth || d) / d, u = ot * 0.7;
|
|
373
|
+
F.style.left = (At + e + ot * 0.05) * i + "px", F.style.top = 0.5 * (O.clientHeight || g) - u * i / 2 + "px", F.style.height = u * i + "px", F.style.width = Math.max(2, Math.round(ot * 0.02 * i)) + "px", F.style.background = `rgb(${J(N[0])},${J(N[1])},${J(N[2])})`;
|
|
310
374
|
}
|
|
311
|
-
function
|
|
312
|
-
|
|
375
|
+
function ct() {
|
|
376
|
+
K || mt || (mt = !0, yt = 0, Rt = requestAnimationFrame(Vt));
|
|
377
|
+
}
|
|
378
|
+
function Vt(t) {
|
|
379
|
+
if (K) {
|
|
380
|
+
mt = !1;
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
313
383
|
yt || (yt = t);
|
|
314
|
-
const
|
|
315
|
-
yt = t,
|
|
384
|
+
const e = Math.min(0.25, (t - yt) / 1e3);
|
|
385
|
+
yt = t, I.on && (I.acc += I.rate * e, xe(I.acc), I.idx >= I.rows.length && (I.on = !1)), et && Q && (ge(H.set ? H.x : d * 0.5, H.set ? H.y : g * 0.45), et = !1);
|
|
386
|
+
const i = f && W;
|
|
387
|
+
if (F && (F.style.opacity = i && Math.floor(t / 530) % 2 === 0 ? "1" : "0"), !I.on && !et && !i) {
|
|
388
|
+
mt = !1;
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
Rt = requestAnimationFrame(Vt);
|
|
316
392
|
}
|
|
317
|
-
function
|
|
318
|
-
const
|
|
319
|
-
|
|
393
|
+
function Ct(t) {
|
|
394
|
+
const e = k.getBoundingClientRect();
|
|
395
|
+
H.x = (t.clientX - e.left) / (e.width || 1) * d, H.y = (t.clientY - e.top) / (e.height || 1) * g, H.set = !0, et = !0, ct();
|
|
320
396
|
}
|
|
321
|
-
function
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
if (t.key === "Enter") {
|
|
328
|
-
t.preventDefault(), Rt.replay();
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
[...t.key].length === 1 && (t.preventDefault(), Ft(o + t.key, !0));
|
|
332
|
-
}
|
|
397
|
+
function vt() {
|
|
398
|
+
H.set = !1, et = !0, ct();
|
|
399
|
+
}
|
|
400
|
+
function we() {
|
|
401
|
+
w && Ht(w.value, !0);
|
|
333
402
|
}
|
|
334
|
-
function
|
|
335
|
-
|
|
403
|
+
function Me(t) {
|
|
404
|
+
t.key === "Enter" && (t.preventDefault(), Bt.replay());
|
|
336
405
|
}
|
|
337
|
-
function
|
|
338
|
-
|
|
406
|
+
function Ce() {
|
|
407
|
+
W = !0, ct();
|
|
339
408
|
}
|
|
340
|
-
function
|
|
341
|
-
|
|
409
|
+
function ve() {
|
|
410
|
+
W = !1, F && (F.style.opacity = "0");
|
|
342
411
|
}
|
|
343
|
-
function
|
|
344
|
-
|
|
412
|
+
function Yt(t) {
|
|
413
|
+
t === f && w || (f = t, t ? (w || (w = document.createElement("input"), w.type = "text", w.value = r, w.maxLength = 64, w.setAttribute("aria-label", "Embroidered text — type to change it"), w.setAttribute("autocomplete", "off"), w.setAttribute("autocapitalize", "off"), w.spellcheck = !1, Object.assign(w.style, { position: "absolute", inset: "0", width: "100%", height: "100%", margin: "0", padding: "0", border: "0", outline: "none", background: "transparent", color: "transparent", caretColor: "transparent", font: "inherit", textAlign: "center", cursor: "text" }), w.addEventListener("input", we), w.addEventListener("keydown", Me), w.addEventListener("focus", Ce), w.addEventListener("blur", ve), k.appendChild(w), Y.push(w)), pe(), kt()) : (w && (w.remove(), w = null), W = !1, F && (F.style.opacity = "0")));
|
|
345
414
|
}
|
|
346
|
-
function
|
|
347
|
-
if (t !==
|
|
348
|
-
if (
|
|
349
|
-
|
|
415
|
+
function be(t) {
|
|
416
|
+
if (t !== S)
|
|
417
|
+
if (S = t, t)
|
|
418
|
+
k.addEventListener("pointermove", Ct, { passive: !0 }), k.addEventListener("pointerleave", vt, { passive: !0 }), H.set = !1, et = !0, ct();
|
|
350
419
|
else {
|
|
351
|
-
|
|
352
|
-
const
|
|
353
|
-
|
|
420
|
+
k.removeEventListener("pointermove", Ct), k.removeEventListener("pointerleave", vt);
|
|
421
|
+
const e = X.getContext("2d");
|
|
422
|
+
e && e.clearRect(0, 0, d, g);
|
|
354
423
|
}
|
|
355
424
|
}
|
|
356
|
-
function
|
|
357
|
-
|
|
425
|
+
function st(t) {
|
|
426
|
+
ce(), se(), fe(), de(), ue(), t ? ye() : ($t(), It(), I.on = !1), w && w.value !== r && (w.value = r), kt(), et = !0, ct();
|
|
358
427
|
}
|
|
359
|
-
function
|
|
360
|
-
t = t ?? "", !(t ===
|
|
428
|
+
function Ht(t, e) {
|
|
429
|
+
t = t ?? "", !(t === r && Z) && (r = t, Z && (st(!1), e && B && B(r)));
|
|
361
430
|
}
|
|
362
|
-
|
|
363
|
-
function
|
|
364
|
-
const
|
|
365
|
-
let
|
|
431
|
+
const bt = /* @__PURE__ */ new Set();
|
|
432
|
+
function Jt(t, e, i) {
|
|
433
|
+
const u = `${e} 200px ${t}`;
|
|
434
|
+
let T = !1;
|
|
366
435
|
try {
|
|
367
|
-
|
|
436
|
+
T = !!document.fonts && document.fonts.check(u);
|
|
368
437
|
} catch {
|
|
369
|
-
|
|
438
|
+
T = !0;
|
|
370
439
|
}
|
|
371
|
-
if (!document.fonts ||
|
|
372
|
-
|
|
440
|
+
if (!document.fonts || T) {
|
|
441
|
+
i();
|
|
373
442
|
return;
|
|
374
443
|
}
|
|
375
|
-
let
|
|
376
|
-
const
|
|
377
|
-
|
|
444
|
+
let C = !1, b;
|
|
445
|
+
const A = () => {
|
|
446
|
+
C || (C = !0, clearTimeout(b), bt.delete(b), K || i());
|
|
378
447
|
};
|
|
379
|
-
document.fonts.load(
|
|
380
|
-
}
|
|
381
|
-
function
|
|
382
|
-
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
let
|
|
386
|
-
function
|
|
387
|
-
clearTimeout(
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
448
|
+
document.fonts.load(u, r).then(() => document.fonts.ready).then(A, A), b = setTimeout(A, 1500), bt.add(b);
|
|
449
|
+
}
|
|
450
|
+
function Te() {
|
|
451
|
+
K || (st(!0), Z = !0);
|
|
452
|
+
}
|
|
453
|
+
f && (f = !1, Yt(!0)), S && (k.addEventListener("pointermove", Ct, { passive: !0 }), k.addEventListener("pointerleave", vt, { passive: !0 })), Jt(q, c, Te);
|
|
454
|
+
let Pt, Qt = -1;
|
|
455
|
+
function Zt() {
|
|
456
|
+
clearTimeout(Pt), Pt = setTimeout(() => {
|
|
457
|
+
if (K || !Z) return;
|
|
458
|
+
const t = Math.round(k.getBoundingClientRect().width);
|
|
459
|
+
t !== Qt && (Qt = t, st(!1));
|
|
460
|
+
}, 200);
|
|
461
|
+
}
|
|
462
|
+
window.addEventListener("resize", Zt);
|
|
463
|
+
const Bt = {
|
|
391
464
|
get text() {
|
|
392
|
-
return
|
|
465
|
+
return r;
|
|
393
466
|
},
|
|
394
467
|
setText(t) {
|
|
395
|
-
if (!
|
|
396
|
-
if (!
|
|
397
|
-
|
|
468
|
+
if (!K) {
|
|
469
|
+
if (!Z) {
|
|
470
|
+
r = t ?? "", w && (w.value = r);
|
|
398
471
|
return;
|
|
399
472
|
}
|
|
400
|
-
|
|
473
|
+
Ht(t, !1);
|
|
401
474
|
}
|
|
402
475
|
},
|
|
403
476
|
replay() {
|
|
404
|
-
|
|
477
|
+
K || !Z || st(!0);
|
|
405
478
|
},
|
|
406
479
|
resize() {
|
|
407
|
-
|
|
480
|
+
K || !Z || st(!1);
|
|
408
481
|
},
|
|
409
482
|
update(t) {
|
|
410
|
-
if (
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
483
|
+
if (K) return;
|
|
484
|
+
t.text !== void 0 && Bt.setText(t.text);
|
|
485
|
+
let e = !1, i = !1;
|
|
486
|
+
if (t.font !== void 0 && t.font !== l && (l = t.font, q = le(l), e = !0), t.weight !== void 0) {
|
|
487
|
+
const u = Et(t.weight, 1, 1e3);
|
|
488
|
+
u !== c && (c = u, e = !0);
|
|
489
|
+
}
|
|
490
|
+
if (t.fill !== void 0) {
|
|
491
|
+
const u = Et(t.fill, 0.05, 1);
|
|
492
|
+
u !== s && (s = u, e = !0);
|
|
493
|
+
}
|
|
494
|
+
t.pitch !== void 0 && t.pitch !== m && (m = t.pitch, e = !0), t.threadColor !== void 0 && (dt(t.threadColor), i = !0), t.sewRate !== void 0 && (h = Math.max(1, t.sewRate)), t.sewStyle !== void 0 && (L = t.sewStyle === "hand" ? "hand" : "machine"), t.animate !== void 0 && (P = t.animate), t.onTextChange !== void 0 && (B = t.onTextChange), t.sheen !== void 0 && be(t.sheen), t.editable !== void 0 && Yt(t.editable), Z && (e ? Jt(q, c, () => {
|
|
495
|
+
K || st(!1);
|
|
496
|
+
}) : i && (Xt(), $t(), It(), kt(), ct()));
|
|
415
497
|
},
|
|
416
498
|
focus() {
|
|
417
|
-
!
|
|
499
|
+
!K && f && (w == null || w.focus());
|
|
418
500
|
},
|
|
419
501
|
destroy() {
|
|
420
|
-
if (!
|
|
421
|
-
|
|
422
|
-
for (const t of
|
|
423
|
-
|
|
502
|
+
if (!K) {
|
|
503
|
+
K = !0, mt = !1, cancelAnimationFrame(Rt), clearTimeout(Pt);
|
|
504
|
+
for (const t of bt) clearTimeout(t);
|
|
505
|
+
bt.clear(), window.removeEventListener("resize", Zt), k.removeEventListener("pointermove", Ct), k.removeEventListener("pointerleave", vt);
|
|
506
|
+
for (const t of Y) t.remove();
|
|
507
|
+
it = [], lt = [], I.rows = [], Ft = new Uint8Array(0), Lt = new Float32Array(0), pt = new Float32Array(0), wt = new Float32Array(0), Q = at = null, Mt = null, F = null, w = null;
|
|
424
508
|
}
|
|
425
509
|
}
|
|
426
510
|
};
|
|
427
|
-
return
|
|
511
|
+
return Bt;
|
|
428
512
|
}
|
|
429
|
-
function
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
const
|
|
433
|
-
|
|
434
|
-
const { text:
|
|
435
|
-
return
|
|
436
|
-
const
|
|
437
|
-
if (!
|
|
438
|
-
const
|
|
439
|
-
...
|
|
513
|
+
function $e(x) {
|
|
514
|
+
const o = Tt(null), r = Tt(null), l = Tt(x);
|
|
515
|
+
l.current = x;
|
|
516
|
+
const c = Tt(x.onTextChange);
|
|
517
|
+
c.current = x.onTextChange;
|
|
518
|
+
const { text: s, font: h, weight: L, threadColor: S, pitch: P, fill: f, animate: m, sewStyle: B, sewRate: q, sheen: gt, editable: N, reducedMotion: ft } = x;
|
|
519
|
+
return Se(() => {
|
|
520
|
+
const U = o.current;
|
|
521
|
+
if (!U) return;
|
|
522
|
+
const dt = Ie(U, {
|
|
523
|
+
...l.current,
|
|
440
524
|
// Stable callback wrapper so typing edits always reach the latest handler.
|
|
441
|
-
onTextChange: (
|
|
442
|
-
var
|
|
443
|
-
return (
|
|
525
|
+
onTextChange: (w) => {
|
|
526
|
+
var F;
|
|
527
|
+
return (F = c.current) == null ? void 0 : F.call(c, w);
|
|
444
528
|
}
|
|
445
529
|
});
|
|
446
|
-
|
|
447
|
-
let
|
|
448
|
-
return typeof ResizeObserver < "u" && (
|
|
449
|
-
const
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
return
|
|
530
|
+
r.current = dt;
|
|
531
|
+
let Y = 0, O = 0, k = !0, X;
|
|
532
|
+
return typeof ResizeObserver < "u" && (X = new ResizeObserver((w) => {
|
|
533
|
+
const F = Math.round(w[0].contentRect.width);
|
|
534
|
+
if (k) {
|
|
535
|
+
k = !1, O = F;
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
F !== O && (O = F, cancelAnimationFrame(Y), Y = requestAnimationFrame(() => {
|
|
539
|
+
var W;
|
|
540
|
+
return (W = r.current) == null ? void 0 : W.resize();
|
|
453
541
|
}));
|
|
454
|
-
}),
|
|
455
|
-
|
|
542
|
+
}), X.observe(U)), () => {
|
|
543
|
+
X == null || X.disconnect(), cancelAnimationFrame(Y), dt.destroy(), r.current = null;
|
|
456
544
|
};
|
|
457
|
-
}, [
|
|
458
|
-
var
|
|
459
|
-
(
|
|
460
|
-
}, [
|
|
461
|
-
var
|
|
462
|
-
(
|
|
463
|
-
}, [
|
|
545
|
+
}, [ft]), ne(() => {
|
|
546
|
+
var U;
|
|
547
|
+
(U = r.current) == null || U.update({ font: h, weight: L, threadColor: S, pitch: P, fill: f, animate: m, sewStyle: B, sewRate: q, sheen: gt, editable: N });
|
|
548
|
+
}, [h, L, S, P, f, m, B, q, gt, N]), ne(() => {
|
|
549
|
+
var U;
|
|
550
|
+
(U = r.current) == null || U.setText(s);
|
|
551
|
+
}, [s]), o;
|
|
464
552
|
}
|
|
465
|
-
const
|
|
466
|
-
function({ className:
|
|
467
|
-
const
|
|
468
|
-
(
|
|
469
|
-
|
|
553
|
+
const ke = Ae(
|
|
554
|
+
function({ className: o, style: r, as: l = "div", "aria-label": c, role: s, "aria-describedby": h, ...L }, S) {
|
|
555
|
+
const P = $e(L), f = Fe(
|
|
556
|
+
(m) => {
|
|
557
|
+
P.current = m, typeof S == "function" ? S(m) : S && (S.current = m);
|
|
470
558
|
},
|
|
471
559
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
472
|
-
[
|
|
560
|
+
[P, S]
|
|
473
561
|
);
|
|
474
|
-
return /* @__PURE__ */
|
|
475
|
-
|
|
562
|
+
return /* @__PURE__ */ Le(
|
|
563
|
+
l,
|
|
476
564
|
{
|
|
477
|
-
ref:
|
|
478
|
-
className:
|
|
479
|
-
style:
|
|
480
|
-
role:
|
|
481
|
-
"aria-label":
|
|
482
|
-
"aria-describedby":
|
|
565
|
+
ref: f,
|
|
566
|
+
className: o,
|
|
567
|
+
style: r,
|
|
568
|
+
role: L.editable ? s : s ?? "img",
|
|
569
|
+
"aria-label": L.editable ? c : c ?? L.text,
|
|
570
|
+
"aria-describedby": h
|
|
483
571
|
}
|
|
484
572
|
);
|
|
485
573
|
}
|
|
486
574
|
);
|
|
487
|
-
|
|
575
|
+
ke.displayName = "ThreadText";
|
|
488
576
|
export {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
577
|
+
zt as THREAD_TEXT_CLASSES,
|
|
578
|
+
ke as ThreadText,
|
|
579
|
+
Ie as createThreadText,
|
|
580
|
+
$e as useThreadText
|
|
493
581
|
};
|