@algorisys/tinyfly 0.87.0 → 0.88.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 +5 -4
- package/lib/addons/adapters.js +370 -310
- package/lib/addons/characters.js +1 -1
- package/lib/addons/load-scene-CQvcFWGJ.js +331 -0
- package/lib/addons/scene-3d.js +299 -215
- package/lib/browser/tinyfly-scene-3d.iife.js +2 -2
- package/lib/browser/tinyfly.iife.js +4 -4
- package/lib/browser/tinyfly.js +2968 -2866
- package/lib/browser/tinyfly.umd.js +4 -4
- package/lib/engine/tinyfly-engine.js +149 -106
- package/lib/engine/tinyfly-engine.umd.cjs +2 -2
- package/lib/headless/headless.js +3 -1
- package/lib/types/adapters/canvas/index.d.ts +1 -0
- package/lib/types/adapters/canvas/trail.d.ts +57 -0
- package/lib/types/browser/index.d.ts +2 -0
- package/lib/types/engine/path/index.d.ts +2 -0
- package/lib/types/engine/path/trail.d.ts +79 -0
- package/lib/types/headless/video-scene.d.ts +2 -0
- package/lib/types/scene-3d/resolve-scene.d.ts +6 -0
- package/lib/types/scene-3d/scene-3d-adapter.d.ts +9 -1
- package/lib/types/scene-3d/scene-types.d.ts +40 -1
- package/lib/types/scene-3d/strokes.d.ts +30 -0
- package/package.json +1 -1
- package/lib/addons/load-scene-vp14_Jj-.js +0 -324
package/lib/addons/adapters.js
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import { h as
|
|
2
|
-
import { D as
|
|
3
|
-
import { createTrack as
|
|
4
|
-
import { p as
|
|
5
|
-
import { c as
|
|
6
|
-
function
|
|
1
|
+
import { h as U, e as _, i as O, a as W, b as N, p as H, t as V, g as z, c as B, q, F as j, s as Z, d as J } from "./dom-adapter-Cphr2HZn.js";
|
|
2
|
+
import { D as Ce } from "./dom-adapter-Cphr2HZn.js";
|
|
3
|
+
import { createTrack as Q, parsePath as L, ribbon as K, ribbonHeadCap as ee, mat4 as b } from "@algorisys/tinyfly";
|
|
4
|
+
import { p as te, s as ie } from "./sketch-CYPUbk3Q.js";
|
|
5
|
+
import { c as Ie, a as Ye, b as _e } from "./sketch-CYPUbk3Q.js";
|
|
6
|
+
function oe(n) {
|
|
7
7
|
const e = /* @__PURE__ */ new Map();
|
|
8
|
-
for (const { name: t, element: i } of
|
|
9
|
-
e.set(t,
|
|
8
|
+
for (const { name: t, element: i } of n)
|
|
9
|
+
e.set(t, F(i));
|
|
10
10
|
return { measurements: e };
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
const i = t.duration ?? 600,
|
|
12
|
+
function se(n, e, t = {}) {
|
|
13
|
+
const i = t.duration ?? 600, o = t.easing ?? "ease-out", s = t.scale !== !1, a = t.idPrefix ?? "flip", r = [];
|
|
14
14
|
for (const { name: c, element: l } of e) {
|
|
15
|
-
const h =
|
|
15
|
+
const h = n.measurements.get(c);
|
|
16
16
|
if (!h) continue;
|
|
17
|
-
const f =
|
|
18
|
-
if ((
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
),
|
|
22
|
-
const
|
|
23
|
-
|
|
17
|
+
const f = F(l), m = h.left + h.width / 2 - (f.left + f.width / 2), u = h.top + h.height / 2 - (f.top + f.height / 2);
|
|
18
|
+
if ((m !== 0 || u !== 0) && r.push(
|
|
19
|
+
T(`${a}-${c}-x`, c, "x", m, 0, i, o),
|
|
20
|
+
T(`${a}-${c}-y`, c, "y", u, 0, i, o)
|
|
21
|
+
), s && f.width > 0 && f.height > 0) {
|
|
22
|
+
const p = h.width / f.width, d = h.height / f.height;
|
|
23
|
+
p !== 1 && r.push(T(`${a}-${c}-sx`, c, "scaleX", p, 1, i, o)), d !== 1 && r.push(T(`${a}-${c}-sy`, c, "scaleY", d, 1, i, o));
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
return
|
|
26
|
+
return r;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
const i =
|
|
30
|
-
return e(),
|
|
28
|
+
function Me(n, e, t = {}) {
|
|
29
|
+
const i = oe(n);
|
|
30
|
+
return e(), se(i, n, t);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
return
|
|
34
|
-
id:
|
|
32
|
+
function T(n, e, t, i, o, s, a) {
|
|
33
|
+
return Q({
|
|
34
|
+
id: n,
|
|
35
35
|
target: e,
|
|
36
36
|
property: t,
|
|
37
37
|
keyframes: [
|
|
38
38
|
{ time: 0, value: i },
|
|
39
|
-
{ time:
|
|
39
|
+
{ time: s, value: o, easing: a }
|
|
40
40
|
]
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
const e =
|
|
43
|
+
function F(n) {
|
|
44
|
+
const e = n;
|
|
45
45
|
if (typeof e.getBoundingClientRect != "function")
|
|
46
46
|
return { left: 0, top: 0, width: 0, height: 0 };
|
|
47
47
|
const t = e.getBoundingClientRect();
|
|
48
48
|
return { left: t.left, top: t.top, width: t.width, height: t.height };
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
const i = t.highlight ?? "#ffffff",
|
|
52
|
-
{ offset:
|
|
53
|
-
{ offset:
|
|
54
|
-
{ offset:
|
|
50
|
+
function G(n, e, t = {}) {
|
|
51
|
+
const i = t.highlight ?? "#ffffff", o = t.halfWidth ?? 0.12, s = -0.2 + n * 1.4, a = [{ offset: 0, color: e }], r = [
|
|
52
|
+
{ offset: s - o, color: e },
|
|
53
|
+
{ offset: s, color: i },
|
|
54
|
+
{ offset: s + o, color: e }
|
|
55
55
|
];
|
|
56
|
-
for (const c of
|
|
56
|
+
for (const c of r)
|
|
57
57
|
c.offset > 0 && c.offset < 1 && a.push(c);
|
|
58
58
|
return a.push({ offset: 1, color: e }), a.sort((c, l) => c.offset - l.offset), a;
|
|
59
59
|
}
|
|
60
|
-
const
|
|
61
|
-
function x(
|
|
60
|
+
const k = 12;
|
|
61
|
+
function x(n) {
|
|
62
62
|
const e = [];
|
|
63
63
|
let t, i = -1;
|
|
64
|
-
for (const
|
|
65
|
-
if (
|
|
66
|
-
(!t || i !==
|
|
64
|
+
for (const o of L(n).segments) {
|
|
65
|
+
if (o.type === "L") {
|
|
66
|
+
(!t || i !== o.subpath) && (t = { kind: "line", points: [{ x: o.startX, y: o.startY }], length: 0 }, i = o.subpath, e.push(t)), t.points.push({ x: o.endX, y: o.endY }), t.length += o.length;
|
|
67
67
|
continue;
|
|
68
68
|
}
|
|
69
69
|
t = void 0;
|
|
70
|
-
const [
|
|
71
|
-
for (let
|
|
72
|
-
const u =
|
|
70
|
+
const [s, a, r, c, l, h] = o.points, f = [];
|
|
71
|
+
for (let m = 0; m <= k; m++) {
|
|
72
|
+
const u = m / k, p = 1 - u;
|
|
73
73
|
f.push({
|
|
74
|
-
x:
|
|
75
|
-
y:
|
|
74
|
+
x: p * p * p * o.startX + 3 * p * p * u * s + 3 * p * u * u * r + u * u * u * l,
|
|
75
|
+
y: p * p * p * o.startY + 3 * p * p * u * a + 3 * p * u * u * c + u * u * u * h
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
e.push({ kind: "curve", points: f, length:
|
|
78
|
+
e.push({ kind: "curve", points: f, length: o.length });
|
|
79
79
|
}
|
|
80
80
|
return e;
|
|
81
81
|
}
|
|
82
|
-
function
|
|
83
|
-
const
|
|
84
|
-
if (
|
|
85
|
-
const a =
|
|
82
|
+
function ne(n, e, t, i, o = 0) {
|
|
83
|
+
const s = Math.max(0, Math.min(o, t / 2, i / 2));
|
|
84
|
+
if (s === 0) return x(`M${n},${e} H${n + t} V${e + i} H${n} Z`);
|
|
85
|
+
const a = n + t, r = e + i;
|
|
86
86
|
return x(
|
|
87
|
-
`M${
|
|
87
|
+
`M${n + s},${e} H${a - s} A${s},${s} 0 0 1 ${a},${e + s} V${r - s} A${s},${s} 0 0 1 ${a - s},${r} H${n + s} A${s},${s} 0 0 1 ${n},${r - s} V${e + s} A${s},${s} 0 0 1 ${n + s},${e} Z`
|
|
88
88
|
);
|
|
89
89
|
}
|
|
90
|
-
function
|
|
91
|
-
const
|
|
90
|
+
function M(n, e, t, i) {
|
|
91
|
+
const s = e.reduce((r, c) => r + c.length, 0) * Math.min(1, Math.max(0, t));
|
|
92
92
|
let a = 0;
|
|
93
|
-
i ||
|
|
94
|
-
for (const
|
|
95
|
-
const c =
|
|
96
|
-
if (a +=
|
|
97
|
-
|
|
93
|
+
i || n.beginPath();
|
|
94
|
+
for (const r of e) {
|
|
95
|
+
const c = r.length === 0 ? s >= a ? 1 : 0 : Math.min(1, Math.max(0, (s - a) / r.length));
|
|
96
|
+
if (a += r.length, i) {
|
|
97
|
+
r.kind === "curve" ? i.curve(r.points, c) : i.line(r.points, c);
|
|
98
98
|
continue;
|
|
99
99
|
}
|
|
100
100
|
if (c <= 0) continue;
|
|
101
|
-
const l =
|
|
102
|
-
|
|
103
|
-
for (const h of l.slice(1))
|
|
101
|
+
const l = te(r.points, c);
|
|
102
|
+
n.moveTo(l[0].x, l[0].y);
|
|
103
|
+
for (const h of l.slice(1)) n.lineTo(h.x, h.y);
|
|
104
104
|
}
|
|
105
|
-
i ||
|
|
105
|
+
i || n.stroke();
|
|
106
106
|
}
|
|
107
|
-
function
|
|
107
|
+
function g(n, e, t) {
|
|
108
108
|
if (typeof OffscreenCanvas < "u") return new OffscreenCanvas(e, t);
|
|
109
|
-
const i =
|
|
109
|
+
const i = n.canvas;
|
|
110
110
|
if (i?.ownerDocument) {
|
|
111
|
-
const
|
|
112
|
-
return
|
|
111
|
+
const o = i.ownerDocument.createElement("canvas");
|
|
112
|
+
return o.width = e, o.height = t, o;
|
|
113
113
|
}
|
|
114
114
|
try {
|
|
115
115
|
return i?.constructor ? new i.constructor(e, t) : null;
|
|
@@ -117,8 +117,8 @@ function F(r, e, t) {
|
|
|
117
117
|
return null;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
function
|
|
121
|
-
return typeof
|
|
120
|
+
function Se(n) {
|
|
121
|
+
return typeof n == "object" && n !== null && "type" in n;
|
|
122
122
|
}
|
|
123
123
|
class R {
|
|
124
124
|
targets = /* @__PURE__ */ new Map();
|
|
@@ -181,19 +181,19 @@ class R {
|
|
|
181
181
|
applyState(e) {
|
|
182
182
|
this.time = e.currentTime;
|
|
183
183
|
for (const [t, i] of e.values) {
|
|
184
|
-
const
|
|
185
|
-
if (!
|
|
186
|
-
const
|
|
187
|
-
for (const [
|
|
188
|
-
if (R.OFFSET_PROPERTIES.has(
|
|
189
|
-
|
|
190
|
-
else if (
|
|
191
|
-
|
|
184
|
+
const o = this.targets.get(t);
|
|
185
|
+
if (!o) continue;
|
|
186
|
+
const s = this.aliases.get(t) ?? t, a = this.animationOffsets.get(s) ?? { x: 0, y: 0 };
|
|
187
|
+
for (const [r, c] of i)
|
|
188
|
+
if (R.OFFSET_PROPERTIES.has(r) && typeof c == "number")
|
|
189
|
+
r === "x" || r === "motionPathX" ? a.x = c : (r === "y" || r === "motionPathY") && (a.y = c);
|
|
190
|
+
else if (o.type === "custom" && o.props && (r in o.props || o.acceptsProp?.(r)))
|
|
191
|
+
o.props[r] = c;
|
|
192
192
|
else {
|
|
193
|
-
const l = R.PROPERTY_MAP[
|
|
194
|
-
|
|
193
|
+
const l = R.PROPERTY_MAP[r] ?? r;
|
|
194
|
+
o[l] = c;
|
|
195
195
|
}
|
|
196
|
-
this.animationOffsets.set(
|
|
196
|
+
this.animationOffsets.set(s, a);
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
/**
|
|
@@ -210,32 +210,32 @@ class R {
|
|
|
210
210
|
for (const t of this.targetOrder) {
|
|
211
211
|
const i = this.targets.get(t);
|
|
212
212
|
if (!i) continue;
|
|
213
|
-
const
|
|
214
|
-
this.renderTarget(e, i,
|
|
213
|
+
const o = this.animationOffsets.get(t) ?? { x: 0, y: 0 };
|
|
214
|
+
this.renderTarget(e, i, o);
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
/**
|
|
218
218
|
* Render a single target.
|
|
219
219
|
*/
|
|
220
220
|
renderTarget(e, t, i) {
|
|
221
|
-
if (e.save(), t.opacity !== void 0 && (e.globalAlpha = t.opacity),
|
|
222
|
-
const
|
|
223
|
-
if (t.backfaceVisibility === "hidden" &&
|
|
221
|
+
if (e.save(), t.opacity !== void 0 && (e.globalAlpha = t.opacity), U(t)) {
|
|
222
|
+
const s = _(t, i, { x: this.getPivotX(t), y: this.getPivotY(t) });
|
|
223
|
+
if (t.backfaceVisibility === "hidden" && O(s)) {
|
|
224
224
|
e.restore();
|
|
225
225
|
return;
|
|
226
226
|
}
|
|
227
|
-
|
|
227
|
+
W(s) ? (e.transform(...N(s)), this.drawContent(e, t)) : this.drawInPerspective(e, t, s), e.restore();
|
|
228
228
|
return;
|
|
229
229
|
}
|
|
230
230
|
if ((i.x !== 0 || i.y !== 0) && e.translate(i.x, i.y), t.rotate !== void 0 || t.rotateX !== void 0 || t.rotateY !== void 0 || t.scale !== void 0 || t.scaleX !== void 0 || t.scaleY !== void 0 || t.skewX !== void 0 || t.skewY !== void 0) {
|
|
231
|
-
const
|
|
232
|
-
e.translate(
|
|
233
|
-
let
|
|
234
|
-
if (t.rotateX !== void 0 && (c *= Math.cos(t.rotateX * Math.PI / 180)), t.rotateY !== void 0 && (
|
|
231
|
+
const s = this.getPivotX(t), a = this.getPivotY(t);
|
|
232
|
+
e.translate(s, a), t.rotate !== void 0 && e.rotate(t.rotate * Math.PI / 180);
|
|
233
|
+
let r = t.scaleX ?? 1, c = t.scaleY ?? 1;
|
|
234
|
+
if (t.rotateX !== void 0 && (c *= Math.cos(t.rotateX * Math.PI / 180)), t.rotateY !== void 0 && (r *= Math.cos(t.rotateY * Math.PI / 180)), t.scale !== void 0 ? e.scale(t.scale, t.scale) : (r !== 1 || c !== 1) && e.scale(r, c), t.skewX !== void 0 || t.skewY !== void 0) {
|
|
235
235
|
const l = (t.skewX ?? 0) * Math.PI / 180, h = (t.skewY ?? 0) * Math.PI / 180;
|
|
236
236
|
e.transform(1, Math.tan(h), Math.tan(l), 1, 0, 0);
|
|
237
237
|
}
|
|
238
|
-
e.translate(-
|
|
238
|
+
e.translate(-s, -a);
|
|
239
239
|
}
|
|
240
240
|
this.drawContent(e, t), e.restore();
|
|
241
241
|
}
|
|
@@ -245,20 +245,20 @@ class R {
|
|
|
245
245
|
* there. The triangles overlap by a pixel so no anti-aliased seam shows.
|
|
246
246
|
*/
|
|
247
247
|
drawInPerspective(e, t, i) {
|
|
248
|
-
const
|
|
249
|
-
if (
|
|
250
|
-
|
|
248
|
+
const s = e.globalAlpha < 1 ? this.perspectiveLayer(e) : null;
|
|
249
|
+
if (s) {
|
|
250
|
+
s.ctx.setTransform(e.getTransform()), this.drawMesh(s.ctx, t, i), e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(s.canvas, 0, 0), e.restore();
|
|
251
251
|
return;
|
|
252
252
|
}
|
|
253
253
|
this.drawMesh(e, t, i);
|
|
254
254
|
}
|
|
255
255
|
drawMesh(e, t, i) {
|
|
256
|
-
const
|
|
257
|
-
for (const
|
|
258
|
-
const a =
|
|
256
|
+
const o = this.contentBounds(e, t);
|
|
257
|
+
for (const s of H(i, o)) {
|
|
258
|
+
const a = V(s.source, s.target);
|
|
259
259
|
if (!a) continue;
|
|
260
|
-
const [
|
|
261
|
-
e.save(), e.beginPath(), e.moveTo(
|
|
260
|
+
const [r, c, l] = z(s.target, 1);
|
|
261
|
+
e.save(), e.beginPath(), e.moveTo(r.x, r.y), e.lineTo(c.x, c.y), e.lineTo(l.x, l.y), e.closePath(), e.clip(), e.transform(...a), this.drawContent(e, t), e.restore();
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
/** A cleared offscreen canvas the size of `ctx`'s, reused frame to frame; null where none can be made. */
|
|
@@ -266,11 +266,11 @@ class R {
|
|
|
266
266
|
const t = e.canvas?.width ?? 0, i = e.canvas?.height ?? 0;
|
|
267
267
|
if (!(t > 0 && i > 0)) return null;
|
|
268
268
|
if (!this.layer || this.layer.width !== t || this.layer.height !== i) {
|
|
269
|
-
const
|
|
270
|
-
if (this.layer =
|
|
269
|
+
const s = g(e, t, i), a = s?.getContext("2d");
|
|
270
|
+
if (this.layer = s && a ? { canvas: s, ctx: a, width: t, height: i } : null, !this.layer) return null;
|
|
271
271
|
}
|
|
272
|
-
const
|
|
273
|
-
return
|
|
272
|
+
const o = this.layer.ctx;
|
|
273
|
+
return o.setTransform(1, 0, 0, 1, 0, 0), o.globalAlpha = 1, o.clearRect(0, 0, t, i), this.layer;
|
|
274
274
|
}
|
|
275
275
|
/**
|
|
276
276
|
* Everything a target paints, generously: its box, measured text, a path's
|
|
@@ -280,26 +280,26 @@ class R {
|
|
|
280
280
|
contentBounds(e, t) {
|
|
281
281
|
let i = this.getTargetBounds(t);
|
|
282
282
|
if (t.type === "text") {
|
|
283
|
-
const
|
|
284
|
-
e.save(), e.font = `${t.fontWeight ?? 400} ${
|
|
283
|
+
const s = t.fontSize ?? 16;
|
|
284
|
+
e.save(), e.font = `${t.fontWeight ?? 400} ${s}px ${t.fontFamily ?? "sans-serif"}`;
|
|
285
285
|
const a = e.measureText(t.text).width;
|
|
286
286
|
e.restore();
|
|
287
|
-
const
|
|
288
|
-
i = { x: c, y: l, width: a, height:
|
|
287
|
+
const r = t.textAlign ?? "left", c = r === "center" ? t.x - a / 2 : r === "right" ? t.x - a : t.x, l = (t.textBaseline ?? "top") === "top" ? t.y : t.y - s;
|
|
288
|
+
i = { x: c, y: l, width: a, height: s * 1.4 };
|
|
289
289
|
} else if (t.type === "path") {
|
|
290
|
-
const
|
|
291
|
-
for (const
|
|
292
|
-
|
|
293
|
-
for (let c = 0; c + 1 <
|
|
294
|
-
|
|
290
|
+
const s = [], a = [];
|
|
291
|
+
for (const r of L(t.d).segments) {
|
|
292
|
+
s.push(r.startX, r.endX), a.push(r.startY, r.endY);
|
|
293
|
+
for (let c = 0; c + 1 < r.points.length; c += 2)
|
|
294
|
+
s.push(r.points[c]), a.push(r.points[c + 1]);
|
|
295
295
|
}
|
|
296
|
-
if (
|
|
297
|
-
const
|
|
298
|
-
i = { x: t.x +
|
|
296
|
+
if (s.length > 0) {
|
|
297
|
+
const r = Math.min(...s), c = Math.min(...a);
|
|
298
|
+
i = { x: t.x + r, y: t.y + c, width: Math.max(...s) - r, height: Math.max(...a) - c };
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
|
-
const
|
|
302
|
-
return { x: i.x -
|
|
301
|
+
const o = (t.lineWidth ?? 1) + 2 + 3 * Math.max(t.blur ?? 0, t.glow ?? 0, t.shadowBlur ?? 0) + Math.max(Math.abs(t.shadowX ?? 0), Math.abs(t.shadowY ?? 0));
|
|
302
|
+
return { x: i.x - o, y: i.y - o, width: i.width + 2 * o, height: i.height + 2 * o };
|
|
303
303
|
}
|
|
304
304
|
/**
|
|
305
305
|
* Paint a target in the current transform: its fill and stroke styles,
|
|
@@ -307,10 +307,10 @@ class R {
|
|
|
307
307
|
*/
|
|
308
308
|
drawContent(e, t) {
|
|
309
309
|
t.fillStyle && (e.fillStyle = this.resolveFillStyle(e, t)), t.strokeStyle && (e.strokeStyle = t.strokeStyle), t.lineWidth !== void 0 && (e.lineWidth = t.lineWidth);
|
|
310
|
-
const i =
|
|
310
|
+
const i = B(t);
|
|
311
311
|
if (i && (e.filter = i), t.clipTop !== void 0 || t.clipRight !== void 0 || t.clipBottom !== void 0 || t.clipLeft !== void 0) {
|
|
312
|
-
const
|
|
313
|
-
e.beginPath(), e.rect(
|
|
312
|
+
const o = this.getTargetBounds(t), s = o.x + (t.clipLeft ?? 0) / 100 * o.width, a = o.x + o.width - (t.clipRight ?? 0) / 100 * o.width, r = o.y + (t.clipTop ?? 0) / 100 * o.height, c = o.y + o.height - (t.clipBottom ?? 0) / 100 * o.height;
|
|
313
|
+
e.beginPath(), e.rect(s, r, Math.max(0, a - s), Math.max(0, c - r)), e.clip();
|
|
314
314
|
}
|
|
315
315
|
switch (t.type) {
|
|
316
316
|
case "rect":
|
|
@@ -343,26 +343,26 @@ class R {
|
|
|
343
343
|
const i = t.fillStyle;
|
|
344
344
|
if (!i) return "transparent";
|
|
345
345
|
if (typeof i == "string") return i;
|
|
346
|
-
const
|
|
347
|
-
return i.type === "linear" ? this.createLinearGradient(e, i,
|
|
346
|
+
const o = this.getTargetBounds(t);
|
|
347
|
+
return i.type === "linear" ? this.createLinearGradient(e, i, o) : this.createRadialGradient(e, i, o);
|
|
348
348
|
}
|
|
349
349
|
/**
|
|
350
350
|
* Create a canvas linear gradient from a LinearGradient definition.
|
|
351
351
|
*/
|
|
352
352
|
createLinearGradient(e, t, i) {
|
|
353
|
-
const
|
|
353
|
+
const o = (t.angle - 90) * (Math.PI / 180), s = i.x + i.width / 2, a = i.y + i.height / 2, r = Math.max(i.width, i.height), c = s - Math.cos(o) * r / 2, l = a - Math.sin(o) * r / 2, h = s + Math.cos(o) * r / 2, f = a + Math.sin(o) * r / 2, m = e.createLinearGradient(c, l, h, f);
|
|
354
354
|
for (const u of t.stops)
|
|
355
|
-
|
|
356
|
-
return
|
|
355
|
+
m.addColorStop(u.offset, u.color);
|
|
356
|
+
return m;
|
|
357
357
|
}
|
|
358
358
|
/**
|
|
359
359
|
* Create a canvas radial gradient from a RadialGradient definition.
|
|
360
360
|
*/
|
|
361
361
|
createRadialGradient(e, t, i) {
|
|
362
|
-
const
|
|
362
|
+
const o = i.x + i.width * t.centerX, s = i.y + i.height * t.centerY, a = Math.max(i.width, i.height) * t.radius, r = e.createRadialGradient(o, s, 0, o, s, a);
|
|
363
363
|
for (const c of t.stops)
|
|
364
|
-
|
|
365
|
-
return
|
|
364
|
+
r.addColorStop(c.offset, c.color);
|
|
365
|
+
return r;
|
|
366
366
|
}
|
|
367
367
|
/**
|
|
368
368
|
* Get target bounding box for gradient calculations.
|
|
@@ -401,25 +401,25 @@ class R {
|
|
|
401
401
|
* Draw a shape outline-first: the fill (clean) once the outline is complete,
|
|
402
402
|
* then the outline up to `drawOn`, in pencil strokes when sketched.
|
|
403
403
|
*/
|
|
404
|
-
renderOutlined(e, t, i,
|
|
405
|
-
const
|
|
406
|
-
if (i && t.fillStyle &&
|
|
407
|
-
const a = t.sketch ?
|
|
408
|
-
a && (e.lineCap = t.lineCap ?? "round", e.lineJoin = t.lineJoin ?? "round"), s
|
|
404
|
+
renderOutlined(e, t, i, o) {
|
|
405
|
+
const s = Math.min(1, Math.max(0, t.drawOn ?? 1));
|
|
406
|
+
if (i && t.fillStyle && s >= 1 && i(), !t.strokeStyle || s <= 0) return;
|
|
407
|
+
const a = t.sketch ? ie(e, t.sketch, this.time) : void 0;
|
|
408
|
+
a && (e.lineCap = t.lineCap ?? "round", e.lineJoin = t.lineJoin ?? "round"), o(s, a);
|
|
409
409
|
}
|
|
410
410
|
/**
|
|
411
411
|
* Render a rectangle.
|
|
412
412
|
*/
|
|
413
413
|
renderRect(e, t) {
|
|
414
414
|
if (this.drawsOutline(t)) {
|
|
415
|
-
const { x: i, y:
|
|
415
|
+
const { x: i, y: o, width: s, height: a } = t;
|
|
416
416
|
return this.renderOutlined(
|
|
417
417
|
e,
|
|
418
418
|
t,
|
|
419
419
|
() => {
|
|
420
|
-
e.beginPath(), t.borderRadius && t.borderRadius > 0 ? this.roundRect(e, i,
|
|
420
|
+
e.beginPath(), t.borderRadius && t.borderRadius > 0 ? this.roundRect(e, i, o, s, a, t.borderRadius) : e.rect(i, o, s, a), e.fill();
|
|
421
421
|
},
|
|
422
|
-
(
|
|
422
|
+
(r, c) => M(e, ne(i, o, s, a, t.borderRadius), r, c)
|
|
423
423
|
);
|
|
424
424
|
}
|
|
425
425
|
e.beginPath(), t.borderRadius && t.borderRadius > 0 ? this.roundRect(e, t.x, t.y, t.width, t.height, t.borderRadius) : e.rect(t.x, t.y, t.width, t.height), t.fillStyle && e.fill(), t.strokeStyle && e.stroke(), e.closePath();
|
|
@@ -427,25 +427,25 @@ class R {
|
|
|
427
427
|
/**
|
|
428
428
|
* Draw a rounded rectangle path.
|
|
429
429
|
*/
|
|
430
|
-
roundRect(e, t, i,
|
|
431
|
-
const
|
|
432
|
-
e.moveTo(t +
|
|
430
|
+
roundRect(e, t, i, o, s, a) {
|
|
431
|
+
const r = Math.min(a, o / 2, s / 2);
|
|
432
|
+
e.moveTo(t + r, i), e.lineTo(t + o - r, i), e.arcTo(t + o, i, t + o, i + r, r), e.lineTo(t + o, i + s - r), e.arcTo(t + o, i + s, t + o - r, i + s, r), e.lineTo(t + r, i + s), e.arcTo(t, i + s, t, i + s - r, r), e.lineTo(t, i + r), e.arcTo(t, i, t + r, i, r);
|
|
433
433
|
}
|
|
434
434
|
/**
|
|
435
435
|
* Render a circle.
|
|
436
436
|
*/
|
|
437
437
|
renderCircle(e, t) {
|
|
438
438
|
if (this.drawsOutline(t)) {
|
|
439
|
-
const { x: i, y:
|
|
439
|
+
const { x: i, y: o, radius: s } = t;
|
|
440
440
|
return this.renderOutlined(
|
|
441
441
|
e,
|
|
442
442
|
t,
|
|
443
443
|
() => {
|
|
444
|
-
e.beginPath(), e.arc(i,
|
|
444
|
+
e.beginPath(), e.arc(i, o, s, 0, Math.PI * 2), e.fill();
|
|
445
445
|
},
|
|
446
|
-
(a,
|
|
447
|
-
if (
|
|
448
|
-
e.beginPath(), e.arc(i,
|
|
446
|
+
(a, r) => {
|
|
447
|
+
if (r) return r.circle(i, o, s, a);
|
|
448
|
+
e.beginPath(), e.arc(i, o, s, -Math.PI / 2, -Math.PI / 2 + Math.PI * 2 * a), e.stroke();
|
|
449
449
|
}
|
|
450
450
|
);
|
|
451
451
|
}
|
|
@@ -455,11 +455,11 @@ class R {
|
|
|
455
455
|
* Render text.
|
|
456
456
|
*/
|
|
457
457
|
renderText(e, t) {
|
|
458
|
-
const i = t.fontSize ?? 16,
|
|
459
|
-
if (e.font = `${
|
|
458
|
+
const i = t.fontSize ?? 16, o = t.fontFamily ?? "sans-serif", s = t.fontWeight ?? 400;
|
|
459
|
+
if (e.font = `${s} ${i}px ${o}`, e.textAlign = t.textAlign ?? "left", e.textBaseline = t.textBaseline ?? "top", t.fillStyle) {
|
|
460
460
|
if (t.shine !== void 0 && typeof t.fillStyle == "string") {
|
|
461
|
-
const a = e.measureText(t.text).width,
|
|
462
|
-
for (const h of
|
|
461
|
+
const a = e.measureText(t.text).width, r = t.textAlign ?? "left", c = r === "center" ? t.x - a / 2 : r === "right" ? t.x - a : t.x, l = e.createLinearGradient(c, t.y, c + a, t.y);
|
|
462
|
+
for (const h of G(t.shine, t.fillStyle))
|
|
463
463
|
l.addColorStop(h.offset, h.color);
|
|
464
464
|
e.fillStyle = l;
|
|
465
465
|
}
|
|
@@ -475,12 +475,12 @@ class R {
|
|
|
475
475
|
const i = [
|
|
476
476
|
{ x: t.x, y: t.y },
|
|
477
477
|
{ x: t.x2, y: t.y2 }
|
|
478
|
-
],
|
|
478
|
+
], o = Math.hypot(t.x2 - t.x, t.y2 - t.y);
|
|
479
479
|
return this.renderOutlined(
|
|
480
480
|
e,
|
|
481
481
|
t,
|
|
482
482
|
void 0,
|
|
483
|
-
(
|
|
483
|
+
(s, a) => M(e, [{ kind: "line", points: i, length: o }], s, a)
|
|
484
484
|
);
|
|
485
485
|
}
|
|
486
486
|
e.beginPath(), e.moveTo(t.x, t.y), e.lineTo(t.x2, t.y2), t.strokeStyle && e.stroke(), e.closePath();
|
|
@@ -496,7 +496,7 @@ class R {
|
|
|
496
496
|
e,
|
|
497
497
|
t,
|
|
498
498
|
() => e.fill(i),
|
|
499
|
-
(
|
|
499
|
+
(o, s) => M(e, x(t.d), o, s)
|
|
500
500
|
);
|
|
501
501
|
t.fillStyle && e.fill(i), t.strokeStyle && e.stroke(i);
|
|
502
502
|
}
|
|
@@ -506,13 +506,13 @@ class R {
|
|
|
506
506
|
renderImage(e, t) {
|
|
507
507
|
if (!t.image) return;
|
|
508
508
|
t.opacity !== void 0 && (e.globalAlpha = t.opacity);
|
|
509
|
-
const { x: i, y:
|
|
510
|
-
let
|
|
511
|
-
if (
|
|
512
|
-
const y =
|
|
513
|
-
|
|
509
|
+
const { x: i, y: o, width: s, height: a } = t, r = t.objectFit ?? "fill", c = t.borderRadius ?? 0, l = t.image, h = l.naturalWidth || l.videoWidth || l.width || s, f = l.naturalHeight || l.videoHeight || l.height || a;
|
|
510
|
+
let m = i, u = o, p = s, d = a;
|
|
511
|
+
if (r !== "fill" && h > 0 && f > 0) {
|
|
512
|
+
const y = r === "cover" ? Math.max(s / h, a / f) : Math.min(s / h, a / f);
|
|
513
|
+
p = h * y, d = f * y, m = i + (s - p) / 2, u = o + (a - d) / 2;
|
|
514
514
|
}
|
|
515
|
-
e.save(), e.beginPath(), c > 0 && typeof e.roundRect == "function" ? e.roundRect(i,
|
|
515
|
+
e.save(), e.beginPath(), c > 0 && typeof e.roundRect == "function" ? e.roundRect(i, o, s, a, c) : e.rect(i, o, s, a), e.clip(), e.drawImage(t.image, m, u, p, d), e.restore();
|
|
516
516
|
}
|
|
517
517
|
/**
|
|
518
518
|
* Render a custom target by calling its draw function in local coordinates.
|
|
@@ -615,56 +615,114 @@ class R {
|
|
|
615
615
|
*/
|
|
616
616
|
static loadImage(e) {
|
|
617
617
|
return new Promise((t, i) => {
|
|
618
|
-
const
|
|
619
|
-
|
|
618
|
+
const o = new Image();
|
|
619
|
+
o.onload = () => t(o), o.onerror = i, o.src = e;
|
|
620
620
|
});
|
|
621
621
|
}
|
|
622
622
|
}
|
|
623
|
-
function
|
|
624
|
-
const t =
|
|
625
|
-
for (let
|
|
626
|
-
const a =
|
|
627
|
-
if (h <=
|
|
628
|
-
const f = (h -
|
|
629
|
-
i[
|
|
623
|
+
function re(n, e) {
|
|
624
|
+
const t = n.length / 4, i = new Float32Array(t * 3), o = Math.min(0.999, Math.max(0, e));
|
|
625
|
+
for (let s = 0; s < t; s++) {
|
|
626
|
+
const a = n[s * 4] / 255, r = n[s * 4 + 1] / 255, c = n[s * 4 + 2] / 255, l = n[s * 4 + 3] / 255, h = Math.max(a, r, c);
|
|
627
|
+
if (h <= o) continue;
|
|
628
|
+
const f = (h - o) / (1 - o) * l / h;
|
|
629
|
+
i[s * 3] = a * f, i[s * 3 + 1] = r * f, i[s * 3 + 2] = c * f;
|
|
630
630
|
}
|
|
631
631
|
return i;
|
|
632
632
|
}
|
|
633
|
-
function
|
|
634
|
-
const
|
|
633
|
+
function E(n, e, t, i, o) {
|
|
634
|
+
const s = new Float32Array(n.length), a = o ? t : e, r = o ? e : t, c = (h, f) => (o ? h * e + f : f * e + h) * 3, l = i * 2 + 1;
|
|
635
635
|
for (let h = 0; h < a; h++)
|
|
636
636
|
for (let f = 0; f < 3; f++) {
|
|
637
|
-
let
|
|
638
|
-
for (let u = -i; u <= i; u++)
|
|
639
|
-
for (let u = 0; u <
|
|
640
|
-
|
|
641
|
-
const
|
|
642
|
-
|
|
637
|
+
let m = 0;
|
|
638
|
+
for (let u = -i; u <= i; u++) m += n[c(h, Math.min(r - 1, Math.max(0, u))) + f];
|
|
639
|
+
for (let u = 0; u < r; u++) {
|
|
640
|
+
s[c(h, u) + f] = m / l;
|
|
641
|
+
const p = n[c(h, Math.max(0, u - i)) + f], d = n[c(h, Math.min(r - 1, u + i + 1)) + f];
|
|
642
|
+
m += d - p;
|
|
643
643
|
}
|
|
644
644
|
}
|
|
645
|
-
return
|
|
645
|
+
return s;
|
|
646
646
|
}
|
|
647
|
-
function
|
|
648
|
-
const
|
|
649
|
-
let
|
|
647
|
+
function X(n, e, t, i) {
|
|
648
|
+
const o = Math.max(1, Math.round(i / Math.sqrt(3)));
|
|
649
|
+
let s = n;
|
|
650
650
|
for (let a = 0; a < 3; a++)
|
|
651
|
-
|
|
652
|
-
return
|
|
651
|
+
s = E(s, e, t, o, !0), s = E(s, e, t, o, !1);
|
|
652
|
+
return s;
|
|
653
653
|
}
|
|
654
|
-
function
|
|
655
|
-
const t =
|
|
656
|
-
if (!(i > 0 &&
|
|
657
|
-
const
|
|
654
|
+
function xe(n, e = {}) {
|
|
655
|
+
const t = n.canvas, i = t.width, o = t.height;
|
|
656
|
+
if (!(i > 0 && o > 0)) return;
|
|
657
|
+
const s = Math.max(1, Math.round(e.downsample ?? 4)), a = Math.max(1, Math.ceil(i / s)), r = Math.max(1, Math.ceil(o / s)), c = g(n, a, r), l = c?.getContext("2d");
|
|
658
658
|
if (!c || !l) return;
|
|
659
|
-
l.imageSmoothingEnabled = !0, l.drawImage(
|
|
660
|
-
const h =
|
|
661
|
-
for (let y = 0; y < a *
|
|
662
|
-
for (let w = 0; w < 3; w++)
|
|
663
|
-
|
|
659
|
+
l.imageSmoothingEnabled = !0, l.drawImage(n.canvas, 0, 0, a, r);
|
|
660
|
+
const h = re(l.getImageData(0, 0, a, r).data, e.threshold ?? 0.55), f = (e.radius ?? Math.max(i, o) * 0.02) / s, m = X(h, a, r, f), u = X(h, a, r, f * 3), p = e.halo ?? 0.6, d = l.createImageData(a, r);
|
|
661
|
+
for (let y = 0; y < a * r; y++) {
|
|
662
|
+
for (let w = 0; w < 3; w++) d.data[y * 4 + w] = Math.round(Math.min(1, m[y * 3 + w] + u[y * 3 + w] * p) * 255);
|
|
663
|
+
d.data[y * 4 + 3] = 255;
|
|
664
664
|
}
|
|
665
|
-
l.putImageData(
|
|
665
|
+
l.putImageData(d, 0, 0), n.save(), n.setTransform(1, 0, 0, 1, 0, 0), n.globalCompositeOperation = "lighter", n.globalAlpha = Math.max(0, e.strength ?? 0.9), n.imageSmoothingEnabled = !0, n.drawImage(c, 0, 0, i, o), n.restore();
|
|
666
666
|
}
|
|
667
|
-
|
|
667
|
+
function Re(n, e, t) {
|
|
668
|
+
const i = t.width ?? 6, o = t.taper ?? 1, s = t.fade ?? 1, a = t.opacity ?? 1, r = t.blend === "add";
|
|
669
|
+
if (n.save(), e.length >= 2) {
|
|
670
|
+
const l = le(e, i, o, s, a);
|
|
671
|
+
r ? (n.globalCompositeOperation = "lighter", A(n, l, t.color)) : ce(n, l, t.color);
|
|
672
|
+
}
|
|
673
|
+
const c = e[e.length - 1];
|
|
674
|
+
if (t.head && c && t.head.radius > 0) {
|
|
675
|
+
r && (n.globalCompositeOperation = "lighter");
|
|
676
|
+
const l = t.head.color ?? t.color, h = n.createRadialGradient(c.at.x, c.at.y, 0, c.at.x, c.at.y, t.head.radius);
|
|
677
|
+
h.addColorStop(0, l), h.addColorStop(0.35, l), h.addColorStop(1, ae(n, l)), n.globalAlpha = a, n.fillStyle = h, n.beginPath(), n.arc(c.at.x, c.at.y, t.head.radius, 0, Math.PI * 2), n.fill();
|
|
678
|
+
}
|
|
679
|
+
n.restore();
|
|
680
|
+
}
|
|
681
|
+
function ae(n, e) {
|
|
682
|
+
n.fillStyle = e;
|
|
683
|
+
const t = String(n.fillStyle), i = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i.exec(t);
|
|
684
|
+
if (i) return `rgba(${parseInt(i[1], 16)}, ${parseInt(i[2], 16)}, ${parseInt(i[3], 16)}, 0)`;
|
|
685
|
+
const o = /^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i.exec(t);
|
|
686
|
+
return o ? `rgba(${o[1]}, ${o[2]}, ${o[3]}, 0)` : "rgba(0, 0, 0, 0)";
|
|
687
|
+
}
|
|
688
|
+
function le(n, e, t, i, o) {
|
|
689
|
+
const s = n.map((l) => ({ x: l.at.x, y: l.at.y, width: e * (1 - t * l.age) })), a = K(s), r = ee(s) ?? void 0, c = [];
|
|
690
|
+
for (let l = 0; l + 1 < n.length; l++) {
|
|
691
|
+
const h = (n[l].age + n[l + 1].age) / 2, f = o * (1 - i * h);
|
|
692
|
+
if (f <= 0) continue;
|
|
693
|
+
const m = l + 2 === n.length;
|
|
694
|
+
c.push({ corners: [a.left[l], a.left[l + 1], a.right[l + 1], a.right[l]], alpha: f, ...m && r && { cap: r } });
|
|
695
|
+
}
|
|
696
|
+
return c;
|
|
697
|
+
}
|
|
698
|
+
function A(n, e, t) {
|
|
699
|
+
n.fillStyle = t;
|
|
700
|
+
for (const i of e) {
|
|
701
|
+
const [o, s, a, r] = i.corners;
|
|
702
|
+
n.globalAlpha = Math.min(1, i.alpha), n.beginPath(), n.moveTo(o.x, o.y), n.lineTo(s.x, s.y), i.cap && n.arc(i.cap.x, i.cap.y, i.cap.radius, i.cap.start, i.cap.start - Math.PI, !0), n.lineTo(a.x, a.y), n.lineTo(r.x, r.y), n.closePath(), n.fill();
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
function ce(n, e, t) {
|
|
706
|
+
const i = typeof n.getTransform == "function" ? n.getTransform() : null, o = (d) => i ? { x: i.a * d.x + i.c * d.y + i.e, y: i.b * d.x + i.d * d.y + i.f } : d, s = i ? Math.sqrt(Math.abs(i.a * i.d - i.b * i.c)) : 1, a = e.map((d) => ({
|
|
707
|
+
...d,
|
|
708
|
+
corners: d.corners.map(o),
|
|
709
|
+
...d.cap && { cap: { ...d.cap, ...o(d.cap), radius: d.cap.radius * s, start: d.cap.start + (i ? Math.atan2(i.b, i.a) : 0) } }
|
|
710
|
+
}));
|
|
711
|
+
let r = 1 / 0, c = 1 / 0, l = -1 / 0, h = -1 / 0;
|
|
712
|
+
for (const d of a) {
|
|
713
|
+
const y = d.cap ? [{ x: d.cap.x - d.cap.radius, y: d.cap.y - d.cap.radius }, { x: d.cap.x + d.cap.radius, y: d.cap.y + d.cap.radius }] : [];
|
|
714
|
+
for (const w of [...d.corners, ...y])
|
|
715
|
+
r = Math.min(r, w.x), c = Math.min(c, w.y), l = Math.max(l, w.x), h = Math.max(h, w.y);
|
|
716
|
+
}
|
|
717
|
+
if (!(l > r && h > c)) return;
|
|
718
|
+
const f = Math.floor(r) - 1, m = Math.floor(c) - 1, u = i ? g(n, Math.ceil(l) + 1 - f, Math.ceil(h) + 1 - m) : null, p = u?.getContext("2d");
|
|
719
|
+
if (!u || !p) {
|
|
720
|
+
A(n, e, t);
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
p.translate(-f, -m), p.globalCompositeOperation = "lighter", A(p, a, t), n.save(), n.setTransform(1, 0, 0, 1, 0, 0), n.globalAlpha = 1, n.drawImage(u, f, m), n.restore();
|
|
724
|
+
}
|
|
725
|
+
const S = "http://www.w3.org/2000/svg", he = /* @__PURE__ */ new Set([
|
|
668
726
|
"fill",
|
|
669
727
|
"stroke",
|
|
670
728
|
"d",
|
|
@@ -684,7 +742,7 @@ const M = "http://www.w3.org/2000/svg", oe = /* @__PURE__ */ new Set([
|
|
|
684
742
|
"height",
|
|
685
743
|
"viewBox",
|
|
686
744
|
"preserveAspectRatio"
|
|
687
|
-
]),
|
|
745
|
+
]), C = {
|
|
688
746
|
strokeWidth: "stroke-width",
|
|
689
747
|
strokeLinecap: "stroke-linecap",
|
|
690
748
|
strokeLinejoin: "stroke-linejoin",
|
|
@@ -695,7 +753,7 @@ const M = "http://www.w3.org/2000/svg", oe = /* @__PURE__ */ new Set([
|
|
|
695
753
|
strokeOpacity: "stroke-opacity",
|
|
696
754
|
borderRadius: "rx"
|
|
697
755
|
// Map CSS borderRadius to SVG rx
|
|
698
|
-
},
|
|
756
|
+
}, fe = /* @__PURE__ */ new Set([
|
|
699
757
|
"x",
|
|
700
758
|
// Position x treated as translateX
|
|
701
759
|
"y",
|
|
@@ -716,8 +774,8 @@ const M = "http://www.w3.org/2000/svg", oe = /* @__PURE__ */ new Set([
|
|
|
716
774
|
"motionPathX",
|
|
717
775
|
"motionPathY",
|
|
718
776
|
"motionPathRotate"
|
|
719
|
-
]),
|
|
720
|
-
class
|
|
777
|
+
]), ue = /* @__PURE__ */ new Set(["clipTop", "clipRight", "clipBottom", "clipLeft"]);
|
|
778
|
+
class Ae {
|
|
721
779
|
targets = /* @__PURE__ */ new Map();
|
|
722
780
|
/**
|
|
723
781
|
* Register an SVG element as an animation target.
|
|
@@ -748,8 +806,8 @@ class ve {
|
|
|
748
806
|
*/
|
|
749
807
|
applyState(e) {
|
|
750
808
|
for (const [t, i] of e.values) {
|
|
751
|
-
const
|
|
752
|
-
|
|
809
|
+
const o = this.targets.get(t);
|
|
810
|
+
o && this.applyProperties(o, i);
|
|
753
811
|
}
|
|
754
812
|
}
|
|
755
813
|
/**
|
|
@@ -757,25 +815,25 @@ class ve {
|
|
|
757
815
|
*/
|
|
758
816
|
applyProperties(e, t) {
|
|
759
817
|
const i = {};
|
|
760
|
-
let
|
|
761
|
-
const
|
|
818
|
+
let o = null;
|
|
819
|
+
const s = {}, a = {}, r = {};
|
|
762
820
|
let c = !1;
|
|
763
821
|
for (const [l, h] of t)
|
|
764
|
-
l !== "drawOn" && (
|
|
765
|
-
if (Object.keys(i).length > 0 ||
|
|
766
|
-
const l = this.buildCssTransformString(i,
|
|
767
|
-
e.style.transform = l,
|
|
822
|
+
l !== "drawOn" && (fe.has(l) ? i[l] = h : l === "quaternion" ? o = q(h) : l === "originX" || l === "originY" ? typeof h == "number" && (s[l] = h) : l === "perspective" ? typeof h == "number" && (i.perspective = h) : ue.has(l) ? typeof h == "number" && (a[l] = h) : j.has(l) ? (r[l] = h, c = !0) : l === "text" ? typeof h == "string" && Z(e, h) : l === "shine" ? typeof h == "number" && this.applyShine(e, h) : l === "opacity" ? (e.setAttribute("fill-opacity", String(h)), e.setAttribute("stroke-opacity", String(h))) : this.applyAttribute(e, l, h));
|
|
823
|
+
if (Object.keys(i).length > 0 || o) {
|
|
824
|
+
const l = this.buildCssTransformString(i, o);
|
|
825
|
+
e.style.transform = l, J(e);
|
|
768
826
|
}
|
|
769
|
-
if (Object.keys(
|
|
827
|
+
if (Object.keys(s).length > 0) {
|
|
770
828
|
const l = e.style;
|
|
771
|
-
l.transformBox = "fill-box", l.transformOrigin = `${
|
|
829
|
+
l.transformBox = "fill-box", l.transformOrigin = `${s.originX ?? 50}% ${s.originY ?? 50}%`;
|
|
772
830
|
}
|
|
773
831
|
if (Object.keys(a).length > 0) {
|
|
774
|
-
const l = a.clipTop ?? 0, h = a.clipRight ?? 0, f = a.clipBottom ?? 0,
|
|
775
|
-
e.style.clipPath = `inset(${l}% ${h}% ${f}% ${
|
|
832
|
+
const l = a.clipTop ?? 0, h = a.clipRight ?? 0, f = a.clipBottom ?? 0, m = a.clipLeft ?? 0;
|
|
833
|
+
e.style.clipPath = `inset(${l}% ${h}% ${f}% ${m}%)`;
|
|
776
834
|
}
|
|
777
835
|
if (c) {
|
|
778
|
-
const l =
|
|
836
|
+
const l = B(r);
|
|
779
837
|
l && (e.style.filter = l);
|
|
780
838
|
}
|
|
781
839
|
}
|
|
@@ -785,14 +843,14 @@ class ve {
|
|
|
785
843
|
buildCssTransformString(e, t = null) {
|
|
786
844
|
const i = [];
|
|
787
845
|
e.perspective !== void 0 && e.perspective > 0 && i.push(`perspective(${e.perspective}px)`);
|
|
788
|
-
const
|
|
789
|
-
e.z !== void 0 ? i.push(`translate3d(${
|
|
846
|
+
const o = e.motionPathX ?? e.x ?? e.translateX, s = e.motionPathY ?? e.y ?? e.translateY;
|
|
847
|
+
e.z !== void 0 ? i.push(`translate3d(${o ?? 0}px, ${s ?? 0}px, ${e.z}px)`) : (o !== void 0 || s !== void 0) && i.push(`translate(${o ?? 0}px, ${s ?? 0}px)`);
|
|
790
848
|
const a = e.motionPathRotate ?? e.rotate ?? e.rotateZ;
|
|
791
849
|
if (a !== void 0 && i.push(`rotate(${a}deg)`), e.rotateX !== void 0 && i.push(`rotateX(${e.rotateX}deg)`), e.rotateY !== void 0 && i.push(`rotateY(${e.rotateY}deg)`), t && i.push(t), e.scale !== void 0)
|
|
792
850
|
i.push(`scale(${e.scale})`);
|
|
793
851
|
else if (e.scaleX !== void 0 || e.scaleY !== void 0) {
|
|
794
|
-
const
|
|
795
|
-
i.push(`scale(${
|
|
852
|
+
const r = e.scaleX ?? 1, c = e.scaleY ?? 1;
|
|
853
|
+
i.push(`scale(${r}, ${c})`);
|
|
796
854
|
}
|
|
797
855
|
return e.skewX !== void 0 && i.push(`skewX(${e.skewX}deg)`), e.skewY !== void 0 && i.push(`skewY(${e.skewY}deg)`), i.join(" ");
|
|
798
856
|
}
|
|
@@ -805,29 +863,29 @@ class ve {
|
|
|
805
863
|
* gradient lives in the owner SVG's <defs> and is reused across frames.
|
|
806
864
|
*/
|
|
807
865
|
applyShine(e, t) {
|
|
808
|
-
const i = e.ownerSVGElement,
|
|
809
|
-
if (!i || !
|
|
810
|
-
const
|
|
811
|
-
|
|
812
|
-
const a =
|
|
813
|
-
let
|
|
814
|
-
|
|
815
|
-
let c =
|
|
816
|
-
for (l || (c = `tinyfly-shine-${Math.random().toString(36).slice(2, 9)}`,
|
|
817
|
-
for (const h of
|
|
818
|
-
const f =
|
|
866
|
+
const i = e.ownerSVGElement, o = e.ownerDocument;
|
|
867
|
+
if (!i || !o) return;
|
|
868
|
+
const s = e;
|
|
869
|
+
s.dataset.shineBase || (s.dataset.shineBase = e.getAttribute("fill") || "#000000");
|
|
870
|
+
const a = s.dataset.shineBase;
|
|
871
|
+
let r = i.querySelector("defs");
|
|
872
|
+
r || (r = o.createElementNS(S, "defs"), i.insertBefore(r, i.firstChild));
|
|
873
|
+
let c = s.dataset.shineGrad, l = c ? r.querySelector(`#${c}`) : null;
|
|
874
|
+
for (l || (c = `tinyfly-shine-${Math.random().toString(36).slice(2, 9)}`, s.dataset.shineGrad = c, l = o.createElementNS(S, "linearGradient"), l.setAttribute("id", c), r.appendChild(l)); l.firstChild; ) l.removeChild(l.firstChild);
|
|
875
|
+
for (const h of G(t, a)) {
|
|
876
|
+
const f = o.createElementNS(S, "stop");
|
|
819
877
|
f.setAttribute("offset", String(h.offset)), f.setAttribute("stop-color", h.color), l.appendChild(f);
|
|
820
878
|
}
|
|
821
879
|
e.setAttribute("fill", `url(#${c})`);
|
|
822
880
|
}
|
|
823
881
|
applyAttribute(e, t, i) {
|
|
824
|
-
let
|
|
825
|
-
|
|
826
|
-
const
|
|
827
|
-
e.setAttribute(
|
|
882
|
+
let o = t;
|
|
883
|
+
C[t] ? o = C[t] : he.has(t) && (o = t);
|
|
884
|
+
const s = Array.isArray(i) ? i.join(" ") : String(i);
|
|
885
|
+
e.setAttribute(o, s);
|
|
828
886
|
}
|
|
829
887
|
}
|
|
830
|
-
const
|
|
888
|
+
const de = `
|
|
831
889
|
attribute vec2 a_position;
|
|
832
890
|
attribute vec2 a_texCoord;
|
|
833
891
|
uniform mat4 u_matrix;
|
|
@@ -837,7 +895,7 @@ void main() {
|
|
|
837
895
|
gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);
|
|
838
896
|
v_texCoord = a_texCoord;
|
|
839
897
|
}
|
|
840
|
-
`,
|
|
898
|
+
`, pe = `
|
|
841
899
|
precision mediump float;
|
|
842
900
|
uniform vec4 u_color;
|
|
843
901
|
uniform sampler2D u_texture;
|
|
@@ -848,7 +906,7 @@ void main() {
|
|
|
848
906
|
vec4 color = u_useTexture ? texture2D(u_texture, v_texCoord) : u_color;
|
|
849
907
|
gl_FragColor = vec4(color.rgb, color.a * u_opacity);
|
|
850
908
|
}
|
|
851
|
-
`,
|
|
909
|
+
`, me = /* @__PURE__ */ new Set([
|
|
852
910
|
"x",
|
|
853
911
|
"y",
|
|
854
912
|
"width",
|
|
@@ -869,7 +927,7 @@ void main() {
|
|
|
869
927
|
"motionPathY",
|
|
870
928
|
"motionPathRotate"
|
|
871
929
|
]);
|
|
872
|
-
class
|
|
930
|
+
class ge {
|
|
873
931
|
gl;
|
|
874
932
|
program;
|
|
875
933
|
positionBuffer;
|
|
@@ -880,7 +938,7 @@ class be {
|
|
|
880
938
|
basePositions = /* @__PURE__ */ new Map();
|
|
881
939
|
locations;
|
|
882
940
|
constructor(e) {
|
|
883
|
-
this.gl = e, this.program =
|
|
941
|
+
this.gl = e, this.program = be(e, de, pe), this.locations = {
|
|
884
942
|
position: e.getAttribLocation(this.program, "a_position"),
|
|
885
943
|
texCoord: e.getAttribLocation(this.program, "a_texCoord"),
|
|
886
944
|
matrix: e.getUniformLocation(this.program, "u_matrix"),
|
|
@@ -888,7 +946,7 @@ class be {
|
|
|
888
946
|
texture: e.getUniformLocation(this.program, "u_texture"),
|
|
889
947
|
useTexture: e.getUniformLocation(this.program, "u_useTexture"),
|
|
890
948
|
opacity: e.getUniformLocation(this.program, "u_opacity")
|
|
891
|
-
}, this.positionBuffer =
|
|
949
|
+
}, this.positionBuffer = I(e, [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]), this.texCoordBuffer = I(e, [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]);
|
|
892
950
|
}
|
|
893
951
|
registerTarget(e, t) {
|
|
894
952
|
this.targets.set(e, t), this.basePositions.set(e, { x: t.x, y: t.y });
|
|
@@ -907,92 +965,92 @@ class be {
|
|
|
907
965
|
/** Apply engine state to the registered targets. */
|
|
908
966
|
applyState(e) {
|
|
909
967
|
for (const [t, i] of e.values) {
|
|
910
|
-
const
|
|
911
|
-
if (!
|
|
912
|
-
const
|
|
913
|
-
for (const [a,
|
|
914
|
-
this.applyProperty(
|
|
968
|
+
const o = this.targets.get(t);
|
|
969
|
+
if (!o) continue;
|
|
970
|
+
const s = this.basePositions.get(t) ?? { x: 0, y: 0 };
|
|
971
|
+
for (const [a, r] of i)
|
|
972
|
+
this.applyProperty(o, s, a, r);
|
|
915
973
|
}
|
|
916
974
|
}
|
|
917
|
-
applyProperty(e, t, i,
|
|
918
|
-
if (typeof
|
|
975
|
+
applyProperty(e, t, i, o) {
|
|
976
|
+
if (typeof o == "number") {
|
|
919
977
|
if (i === "x" || i === "motionPathX") {
|
|
920
|
-
e.x = t.x +
|
|
978
|
+
e.x = t.x + o;
|
|
921
979
|
return;
|
|
922
980
|
}
|
|
923
981
|
if (i === "y" || i === "motionPathY") {
|
|
924
|
-
e.y = t.y +
|
|
982
|
+
e.y = t.y + o;
|
|
925
983
|
return;
|
|
926
984
|
}
|
|
927
985
|
if (i === "rotateZ" || i === "motionPathRotate") {
|
|
928
|
-
e.rotate =
|
|
986
|
+
e.rotate = o;
|
|
929
987
|
return;
|
|
930
988
|
}
|
|
931
|
-
if (
|
|
932
|
-
e[i] =
|
|
989
|
+
if (me.has(i)) {
|
|
990
|
+
e[i] = o;
|
|
933
991
|
return;
|
|
934
992
|
}
|
|
935
993
|
}
|
|
936
|
-
typeof
|
|
994
|
+
typeof o == "string" && i === "fill" && (e.fill = o), i === "quaternion" && Array.isArray(o) && (e.quaternion = o);
|
|
937
995
|
}
|
|
938
996
|
/** Draw every registered target. */
|
|
939
997
|
render() {
|
|
940
998
|
const e = this.gl, { width: t, height: i } = e.canvas;
|
|
941
|
-
e.viewport(0, 0, t, i), e.clearColor(0, 0, 0, 0), e.clear(e.COLOR_BUFFER_BIT), e.enable(e.BLEND), e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), e.useProgram(this.program),
|
|
942
|
-
for (const [
|
|
943
|
-
this.drawTarget(
|
|
944
|
-
}
|
|
945
|
-
drawTarget(e, t, i,
|
|
946
|
-
const
|
|
947
|
-
if (t.backfaceVisibility === "hidden" &&
|
|
948
|
-
const a =
|
|
949
|
-
if (
|
|
950
|
-
|
|
999
|
+
e.viewport(0, 0, t, i), e.clearColor(0, 0, 0, 0), e.clear(e.COLOR_BUFFER_BIT), e.enable(e.BLEND), e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), e.useProgram(this.program), Y(e, this.positionBuffer, this.locations.position), Y(e, this.texCoordBuffer, this.locations.texCoord);
|
|
1000
|
+
for (const [o, s] of this.targets)
|
|
1001
|
+
this.drawTarget(o, s, t, i);
|
|
1002
|
+
}
|
|
1003
|
+
drawTarget(e, t, i, o) {
|
|
1004
|
+
const s = this.gl;
|
|
1005
|
+
if (t.backfaceVisibility === "hidden" && O(D(t))) return;
|
|
1006
|
+
const a = ye(t, i, o);
|
|
1007
|
+
if (s.uniformMatrix4fv(this.locations.matrix, !1, a), s.uniform1f(this.locations.opacity, t.opacity ?? 1), t.texture)
|
|
1008
|
+
s.bindTexture(s.TEXTURE_2D, this.textureFor(e, t.texture)), s.uniform1i(this.locations.useTexture, 1), s.uniform1i(this.locations.texture, 0);
|
|
951
1009
|
else {
|
|
952
|
-
|
|
953
|
-
const [
|
|
954
|
-
|
|
1010
|
+
s.uniform1i(this.locations.useTexture, 0);
|
|
1011
|
+
const [r, c, l] = we(t.fill ?? "#ffffff");
|
|
1012
|
+
s.uniform4f(this.locations.color, r, c, l, 1);
|
|
955
1013
|
}
|
|
956
|
-
|
|
1014
|
+
s.drawArrays(s.TRIANGLES, 0, 6);
|
|
957
1015
|
}
|
|
958
1016
|
textureFor(e, t) {
|
|
959
1017
|
const i = this.textures.get(e);
|
|
960
1018
|
if (i) return i;
|
|
961
|
-
const
|
|
962
|
-
return
|
|
1019
|
+
const o = this.gl, s = o.createTexture();
|
|
1020
|
+
return o.bindTexture(o.TEXTURE_2D, s), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_S, o.CLAMP_TO_EDGE), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_T, o.CLAMP_TO_EDGE), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR), o.texImage2D(o.TEXTURE_2D, 0, o.RGBA, o.RGBA, o.UNSIGNED_BYTE, t), this.textures.set(e, s), s;
|
|
963
1021
|
}
|
|
964
1022
|
/** Release GL resources. */
|
|
965
1023
|
destroy() {
|
|
966
1024
|
this.clearTargets(), this.gl.deleteProgram(this.program), this.gl.deleteBuffer(this.positionBuffer), this.gl.deleteBuffer(this.texCoordBuffer);
|
|
967
1025
|
}
|
|
968
1026
|
}
|
|
969
|
-
function
|
|
970
|
-
const i = (
|
|
1027
|
+
function ke(n, e, t) {
|
|
1028
|
+
const i = (n.scale ?? n.scaleX ?? 1) * n.width, o = (n.scale ?? n.scaleY ?? 1) * n.height, s = (n.originX ?? 50) / 100, a = (n.originY ?? 50) / 100, r = (n.rotate ?? 0) * Math.PI / 180, c = Math.cos(r), l = Math.sin(r), h = -s, f = -a, m = c * i, u = l * i, p = -l * o, d = c * o, y = n.x + m * h + p * f, w = n.y + u * h + d * f, v = 2 / e, P = -2 / t;
|
|
971
1029
|
return new Float32Array([
|
|
972
|
-
|
|
1030
|
+
m * v,
|
|
973
1031
|
u * P,
|
|
974
1032
|
0,
|
|
975
|
-
|
|
976
|
-
|
|
1033
|
+
p * v,
|
|
1034
|
+
d * P,
|
|
977
1035
|
0,
|
|
978
|
-
y *
|
|
1036
|
+
y * v - 1,
|
|
979
1037
|
w * P + 1,
|
|
980
1038
|
1
|
|
981
1039
|
]);
|
|
982
1040
|
}
|
|
983
|
-
function
|
|
984
|
-
const e = (
|
|
985
|
-
|
|
986
|
-
|
|
1041
|
+
function D(n) {
|
|
1042
|
+
const e = (n.originX ?? 50) / 100, t = (n.originY ?? 50) / 100, i = { x: n.x, y: n.y }, o = b.multiply(
|
|
1043
|
+
b.translation([n.x, n.y, 0]),
|
|
1044
|
+
b.multiply(b.scaling([n.width, n.height, 1]), b.translation([-e, -t, 0]))
|
|
987
1045
|
);
|
|
988
|
-
return
|
|
1046
|
+
return b.multiply(_(n, { x: 0, y: 0 }, i), o);
|
|
989
1047
|
}
|
|
990
|
-
function
|
|
1048
|
+
function ye(n, e, t) {
|
|
991
1049
|
const i = [2 / e, 0, 0, 0, 0, -2 / t, 0, 0, 0, 0, 0, 0, -1, 1, 0, 1];
|
|
992
|
-
return new Float32Array(
|
|
1050
|
+
return new Float32Array(b.multiply(i, D(n)));
|
|
993
1051
|
}
|
|
994
|
-
function
|
|
995
|
-
const e =
|
|
1052
|
+
function we(n) {
|
|
1053
|
+
const e = n.trim().replace("#", "");
|
|
996
1054
|
return e.length === 3 ? [
|
|
997
1055
|
Number.parseInt(e[0] + e[0], 16) / 255,
|
|
998
1056
|
Number.parseInt(e[1] + e[1], 16) / 255,
|
|
@@ -1003,51 +1061,53 @@ function fe(r) {
|
|
|
1003
1061
|
Number.parseInt(e.slice(4, 6), 16) / 255
|
|
1004
1062
|
] : [1, 1, 1];
|
|
1005
1063
|
}
|
|
1006
|
-
function
|
|
1007
|
-
const i =
|
|
1064
|
+
function be(n, e, t) {
|
|
1065
|
+
const i = n.createProgram();
|
|
1008
1066
|
if (!i) throw new Error("WebGLAdapter: could not create a program");
|
|
1009
|
-
if (
|
|
1010
|
-
throw new Error(`WebGLAdapter: program link failed — ${
|
|
1067
|
+
if (n.attachShader(i, $(n, n.VERTEX_SHADER, e)), n.attachShader(i, $(n, n.FRAGMENT_SHADER, t)), n.linkProgram(i), !n.getProgramParameter(i, n.LINK_STATUS))
|
|
1068
|
+
throw new Error(`WebGLAdapter: program link failed — ${n.getProgramInfoLog(i)}`);
|
|
1011
1069
|
return i;
|
|
1012
1070
|
}
|
|
1013
|
-
function
|
|
1014
|
-
const i =
|
|
1071
|
+
function $(n, e, t) {
|
|
1072
|
+
const i = n.createShader(e);
|
|
1015
1073
|
if (!i) throw new Error("WebGLAdapter: could not create a shader");
|
|
1016
|
-
if (
|
|
1017
|
-
throw new Error(`WebGLAdapter: shader compile failed — ${
|
|
1074
|
+
if (n.shaderSource(i, t), n.compileShader(i), !n.getShaderParameter(i, n.COMPILE_STATUS))
|
|
1075
|
+
throw new Error(`WebGLAdapter: shader compile failed — ${n.getShaderInfoLog(i)}`);
|
|
1018
1076
|
return i;
|
|
1019
1077
|
}
|
|
1020
|
-
function
|
|
1021
|
-
const t =
|
|
1078
|
+
function I(n, e) {
|
|
1079
|
+
const t = n.createBuffer();
|
|
1022
1080
|
if (!t) throw new Error("WebGLAdapter: could not create a buffer");
|
|
1023
|
-
return
|
|
1081
|
+
return n.bindBuffer(n.ARRAY_BUFFER, t), n.bufferData(n.ARRAY_BUFFER, new Float32Array(e), n.STATIC_DRAW), t;
|
|
1024
1082
|
}
|
|
1025
|
-
function
|
|
1026
|
-
t < 0 || (
|
|
1083
|
+
function Y(n, e, t) {
|
|
1084
|
+
t < 0 || (n.bindBuffer(n.ARRAY_BUFFER, e), n.enableVertexAttribArray(t), n.vertexAttribPointer(t, 2, n.FLOAT, !1, 0, 0));
|
|
1027
1085
|
}
|
|
1028
1086
|
export {
|
|
1029
1087
|
R as CanvasAdapter,
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1088
|
+
Ce as DOMAdapter,
|
|
1089
|
+
Ae as SVGAdapter,
|
|
1090
|
+
ge as WebGLAdapter,
|
|
1091
|
+
xe as applyBloom,
|
|
1092
|
+
Ie as boilFrame,
|
|
1093
|
+
X as boxBlur,
|
|
1094
|
+
re as brightPass,
|
|
1095
|
+
se as buildFlipTracks,
|
|
1096
|
+
g as canvasLike,
|
|
1097
|
+
M as drawOutline,
|
|
1098
|
+
Re as drawTrail,
|
|
1099
|
+
Me as flip,
|
|
1100
|
+
Se as isGradient,
|
|
1101
|
+
we as parseColor,
|
|
1102
|
+
te as partialPath,
|
|
1103
|
+
Ye as pathLength,
|
|
1045
1104
|
x as pathOutline,
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1105
|
+
_e as pointAlong,
|
|
1106
|
+
ke as quadMatrix,
|
|
1107
|
+
ye as quadMatrix3d,
|
|
1108
|
+
oe as recordFlipState,
|
|
1109
|
+
ne as rectOutline,
|
|
1110
|
+
Z as setTextContent,
|
|
1111
|
+
ie as sketchPen,
|
|
1112
|
+
le as trailQuads
|
|
1053
1113
|
};
|