@algorisys/tinyfly 0.74.0 → 0.75.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 +9 -6
- package/lib/addons/adapters.js +236 -121
- package/lib/addons/characters.js +323 -144
- package/lib/addons/{dom-adapter-ChrbtkLC.js → dom-adapter-CrNwoomd.js} +52 -52
- package/lib/addons/gsap-compat.js +1 -1
- package/lib/addons/sketch-CB6VNfnR.js +128 -0
- package/lib/browser/tinyfly.iife.js +4 -4
- package/lib/browser/tinyfly.js +3117 -2819
- package/lib/browser/tinyfly.umd.js +4 -4
- package/lib/cli/tools.js +2 -0
- package/lib/embed/tinyfly-embed.iife.js +4 -4
- package/lib/embed/tinyfly-embed.js +70 -70
- package/lib/headless/headless.js +300 -1
- package/lib/player/tinyfly-player.es.js +73 -73
- package/lib/player/tinyfly-player.iife.js +2 -2
- package/lib/player/tinyfly-player.umd.js +2 -2
- package/lib/types/adapters/canvas/canvas-adapter.d.ts +18 -0
- package/lib/types/adapters/canvas/index.d.ts +3 -0
- package/lib/types/adapters/canvas/outline.d.ts +26 -0
- package/lib/types/adapters/canvas/polyline.d.ts +12 -0
- package/lib/types/adapters/canvas/sketch.d.ts +54 -0
- package/lib/types/characters/erase.d.ts +31 -0
- package/lib/types/characters/hand.d.ts +81 -0
- package/lib/types/characters/index.d.ts +7 -1
- package/lib/types/characters/polyline.d.ts +12 -0
- package/lib/types/characters/sketch.d.ts +54 -0
- package/lib/types/characters/stick-figure.d.ts +42 -5
- package/package.json +1 -1
package/lib/addons/adapters.js
CHANGED
|
@@ -1,64 +1,113 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { D as
|
|
3
|
-
import { createTrack as
|
|
4
|
-
|
|
1
|
+
import { c as _, F as O, s as C, e as I } from "./dom-adapter-CrNwoomd.js";
|
|
2
|
+
import { D as ae } from "./dom-adapter-CrNwoomd.js";
|
|
3
|
+
import { createTrack as B, parsePath as L } from "@algorisys/tinyfly";
|
|
4
|
+
import { p as F, s as G } from "./sketch-CB6VNfnR.js";
|
|
5
|
+
import { b as le, c as he, a as fe } from "./sketch-CB6VNfnR.js";
|
|
6
|
+
function g(c) {
|
|
5
7
|
const e = /* @__PURE__ */ new Map();
|
|
6
|
-
for (const { name: t, element: i } of
|
|
7
|
-
e.set(t,
|
|
8
|
+
for (const { name: t, element: i } of c)
|
|
9
|
+
e.set(t, X(i));
|
|
8
10
|
return { measurements: e };
|
|
9
11
|
}
|
|
10
|
-
function
|
|
11
|
-
const i = t.duration ?? 600, o = t.easing ?? "ease-out", s = t.scale !== !1,
|
|
12
|
+
function U(c, e, t = {}) {
|
|
13
|
+
const i = t.duration ?? 600, o = t.easing ?? "ease-out", s = t.scale !== !1, a = t.idPrefix ?? "flip", n = [];
|
|
12
14
|
for (const { name: r, element: l } of e) {
|
|
13
|
-
const h =
|
|
15
|
+
const h = c.measurements.get(r);
|
|
14
16
|
if (!h) continue;
|
|
15
|
-
const f =
|
|
16
|
-
if ((
|
|
17
|
-
T(`${
|
|
18
|
-
T(`${
|
|
17
|
+
const f = X(l), p = h.left + h.width / 2 - (f.left + f.width / 2), u = h.top + h.height / 2 - (f.top + f.height / 2);
|
|
18
|
+
if ((p !== 0 || u !== 0) && n.push(
|
|
19
|
+
T(`${a}-${r}-x`, r, "x", p, 0, i, o),
|
|
20
|
+
T(`${a}-${r}-y`, r, "y", u, 0, i, o)
|
|
19
21
|
), s && f.width > 0 && f.height > 0) {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
+
const d = h.width / f.width, m = h.height / f.height;
|
|
23
|
+
d !== 1 && n.push(T(`${a}-${r}-sx`, r, "scaleX", d, 1, i, o)), m !== 1 && n.push(T(`${a}-${r}-sy`, r, "scaleY", m, 1, i, o));
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
return n;
|
|
25
27
|
}
|
|
26
|
-
function
|
|
27
|
-
const i =
|
|
28
|
-
return e(),
|
|
28
|
+
function te(c, e, t = {}) {
|
|
29
|
+
const i = g(c);
|
|
30
|
+
return e(), U(i, c, t);
|
|
29
31
|
}
|
|
30
|
-
function T(
|
|
31
|
-
return
|
|
32
|
-
id:
|
|
32
|
+
function T(c, e, t, i, o, s, a) {
|
|
33
|
+
return B({
|
|
34
|
+
id: c,
|
|
33
35
|
target: e,
|
|
34
36
|
property: t,
|
|
35
37
|
keyframes: [
|
|
36
38
|
{ time: 0, value: i },
|
|
37
|
-
{ time: s, value: o, easing:
|
|
39
|
+
{ time: s, value: o, easing: a }
|
|
38
40
|
]
|
|
39
41
|
});
|
|
40
42
|
}
|
|
41
|
-
function
|
|
42
|
-
const e =
|
|
43
|
+
function X(c) {
|
|
44
|
+
const e = c;
|
|
43
45
|
if (typeof e.getBoundingClientRect != "function")
|
|
44
46
|
return { left: 0, top: 0, width: 0, height: 0 };
|
|
45
47
|
const t = e.getBoundingClientRect();
|
|
46
48
|
return { left: t.left, top: t.top, width: t.width, height: t.height };
|
|
47
49
|
}
|
|
48
|
-
function
|
|
49
|
-
const i = t.highlight ?? "#ffffff", o = t.halfWidth ?? 0.12, s = -0.2 +
|
|
50
|
+
function Y(c, e, t = {}) {
|
|
51
|
+
const i = t.highlight ?? "#ffffff", o = t.halfWidth ?? 0.12, s = -0.2 + c * 1.4, a = [{ offset: 0, color: e }], n = [
|
|
50
52
|
{ offset: s - o, color: e },
|
|
51
53
|
{ offset: s, color: i },
|
|
52
54
|
{ offset: s + o, color: e }
|
|
53
55
|
];
|
|
54
56
|
for (const r of n)
|
|
55
|
-
r.offset > 0 && r.offset < 1 &&
|
|
56
|
-
return
|
|
57
|
+
r.offset > 0 && r.offset < 1 && a.push(r);
|
|
58
|
+
return a.push({ offset: 1, color: e }), a.sort((r, l) => r.offset - l.offset), a;
|
|
57
59
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
const x = 12;
|
|
61
|
+
function R(c) {
|
|
62
|
+
const e = [];
|
|
63
|
+
let t, i = -1;
|
|
64
|
+
for (const o of L(c).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
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
t = void 0;
|
|
70
|
+
const [s, a, n, r, l, h] = o.points, f = [];
|
|
71
|
+
for (let p = 0; p <= x; p++) {
|
|
72
|
+
const u = p / x, d = 1 - u;
|
|
73
|
+
f.push({
|
|
74
|
+
x: d * d * d * o.startX + 3 * d * d * u * s + 3 * d * u * u * n + u * u * u * l,
|
|
75
|
+
y: d * d * d * o.startY + 3 * d * d * u * a + 3 * d * u * u * r + u * u * u * h
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
e.push({ kind: "curve", points: f, length: o.length });
|
|
79
|
+
}
|
|
80
|
+
return e;
|
|
60
81
|
}
|
|
61
|
-
|
|
82
|
+
function D(c, e, t, i, o = 0) {
|
|
83
|
+
const s = Math.max(0, Math.min(o, t / 2, i / 2));
|
|
84
|
+
if (s === 0) return R(`M${c},${e} H${c + t} V${e + i} H${c} Z`);
|
|
85
|
+
const a = c + t, n = e + i;
|
|
86
|
+
return R(
|
|
87
|
+
`M${c + s},${e} H${a - s} A${s},${s} 0 0 1 ${a},${e + s} V${n - s} A${s},${s} 0 0 1 ${a - s},${n} H${c + s} A${s},${s} 0 0 1 ${c},${n - s} V${e + s} A${s},${s} 0 0 1 ${c + s},${e} Z`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
function S(c, e, t, i) {
|
|
91
|
+
const s = e.reduce((n, r) => n + r.length, 0) * Math.min(1, Math.max(0, t));
|
|
92
|
+
let a = 0;
|
|
93
|
+
i || c.beginPath();
|
|
94
|
+
for (const n of e) {
|
|
95
|
+
const r = n.length === 0 ? s >= a ? 1 : 0 : Math.min(1, Math.max(0, (s - a) / n.length));
|
|
96
|
+
if (a += n.length, i) {
|
|
97
|
+
n.kind === "curve" ? i.curve(n.points, r) : i.line(n.points, r);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (r <= 0) continue;
|
|
101
|
+
const l = F(n.points, r);
|
|
102
|
+
c.moveTo(l[0].x, l[0].y);
|
|
103
|
+
for (const h of l.slice(1)) c.lineTo(h.x, h.y);
|
|
104
|
+
}
|
|
105
|
+
i || c.stroke();
|
|
106
|
+
}
|
|
107
|
+
function ie(c) {
|
|
108
|
+
return typeof c == "object" && c !== null && "type" in c;
|
|
109
|
+
}
|
|
110
|
+
class v {
|
|
62
111
|
targets = /* @__PURE__ */ new Map();
|
|
63
112
|
targetOrder = [];
|
|
64
113
|
// Store animation offsets separately - these are applied via ctx.translate() during rendering
|
|
@@ -118,17 +167,17 @@ class R {
|
|
|
118
167
|
for (const [t, i] of e.values) {
|
|
119
168
|
const o = this.targets.get(t);
|
|
120
169
|
if (!o) continue;
|
|
121
|
-
const s = this.aliases.get(t) ?? t,
|
|
170
|
+
const s = this.aliases.get(t) ?? t, a = this.animationOffsets.get(s) ?? { x: 0, y: 0 };
|
|
122
171
|
for (const [n, r] of i)
|
|
123
|
-
if (
|
|
124
|
-
n === "x" || n === "motionPathX" ?
|
|
172
|
+
if (v.OFFSET_PROPERTIES.has(n) && typeof r == "number")
|
|
173
|
+
n === "x" || n === "motionPathX" ? a.x = r : (n === "y" || n === "motionPathY") && (a.y = r);
|
|
125
174
|
else if (o.type === "custom" && o.props && n in o.props)
|
|
126
175
|
o.props[n] = r;
|
|
127
176
|
else {
|
|
128
|
-
const l =
|
|
177
|
+
const l = v.PROPERTY_MAP[n] ?? n;
|
|
129
178
|
o[l] = r;
|
|
130
179
|
}
|
|
131
|
-
this.animationOffsets.set(s,
|
|
180
|
+
this.animationOffsets.set(s, a);
|
|
132
181
|
}
|
|
133
182
|
}
|
|
134
183
|
/**
|
|
@@ -154,19 +203,19 @@ class R {
|
|
|
154
203
|
*/
|
|
155
204
|
renderTarget(e, t, i) {
|
|
156
205
|
if (e.save(), (i.x !== 0 || i.y !== 0) && e.translate(i.x, i.y), t.opacity !== void 0 && (e.globalAlpha = t.opacity), 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) {
|
|
157
|
-
const
|
|
158
|
-
e.translate(
|
|
206
|
+
const a = this.getPivotX(t), n = this.getPivotY(t);
|
|
207
|
+
e.translate(a, n), t.rotate !== void 0 && e.rotate(t.rotate * Math.PI / 180);
|
|
159
208
|
let r = t.scaleX ?? 1, l = t.scaleY ?? 1;
|
|
160
209
|
if (t.rotateX !== void 0 && (l *= 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 || l !== 1) && e.scale(r, l), t.skewX !== void 0 || t.skewY !== void 0) {
|
|
161
210
|
const h = (t.skewX ?? 0) * Math.PI / 180, f = (t.skewY ?? 0) * Math.PI / 180;
|
|
162
211
|
e.transform(1, Math.tan(f), Math.tan(h), 1, 0, 0);
|
|
163
212
|
}
|
|
164
|
-
e.translate(-
|
|
213
|
+
e.translate(-a, -n);
|
|
165
214
|
}
|
|
166
215
|
t.fillStyle && (e.fillStyle = this.resolveFillStyle(e, t)), t.strokeStyle && (e.strokeStyle = t.strokeStyle), t.lineWidth !== void 0 && (e.lineWidth = t.lineWidth);
|
|
167
|
-
const s =
|
|
216
|
+
const s = _(t);
|
|
168
217
|
if (s && (e.filter = s), t.clipTop !== void 0 || t.clipRight !== void 0 || t.clipBottom !== void 0 || t.clipLeft !== void 0) {
|
|
169
|
-
const
|
|
218
|
+
const a = this.getTargetBounds(t), n = a.x + (t.clipLeft ?? 0) / 100 * a.width, r = a.x + a.width - (t.clipRight ?? 0) / 100 * a.width, l = a.y + (t.clipTop ?? 0) / 100 * a.height, h = a.y + a.height - (t.clipBottom ?? 0) / 100 * a.height;
|
|
170
219
|
e.beginPath(), e.rect(n, l, Math.max(0, r - n), Math.max(0, h - l)), e.clip();
|
|
171
220
|
}
|
|
172
221
|
switch (t.type) {
|
|
@@ -208,16 +257,16 @@ class R {
|
|
|
208
257
|
* Create a canvas linear gradient from a LinearGradient definition.
|
|
209
258
|
*/
|
|
210
259
|
createLinearGradient(e, t, i) {
|
|
211
|
-
const o = (t.angle - 90) * (Math.PI / 180), s = i.x + i.width / 2,
|
|
212
|
-
for (const
|
|
213
|
-
|
|
214
|
-
return
|
|
260
|
+
const o = (t.angle - 90) * (Math.PI / 180), s = i.x + i.width / 2, a = i.y + i.height / 2, n = Math.max(i.width, i.height), r = s - Math.cos(o) * n / 2, l = a - Math.sin(o) * n / 2, h = s + Math.cos(o) * n / 2, f = a + Math.sin(o) * n / 2, p = e.createLinearGradient(r, l, h, f);
|
|
261
|
+
for (const u of t.stops)
|
|
262
|
+
p.addColorStop(u.offset, u.color);
|
|
263
|
+
return p;
|
|
215
264
|
}
|
|
216
265
|
/**
|
|
217
266
|
* Create a canvas radial gradient from a RadialGradient definition.
|
|
218
267
|
*/
|
|
219
268
|
createRadialGradient(e, t, i) {
|
|
220
|
-
const o = i.x + i.width * t.centerX, s = i.y + i.height * t.centerY,
|
|
269
|
+
const o = i.x + i.width * t.centerX, s = i.y + i.height * t.centerY, a = Math.max(i.width, i.height) * t.radius, n = e.createRadialGradient(o, s, 0, o, s, a);
|
|
221
270
|
for (const r of t.stops)
|
|
222
271
|
n.addColorStop(r.offset, r.color);
|
|
223
272
|
return n;
|
|
@@ -251,23 +300,62 @@ class R {
|
|
|
251
300
|
return { x: e.x, y: e.y, width: 100, height: 100 };
|
|
252
301
|
}
|
|
253
302
|
}
|
|
303
|
+
/** Whether a shape is drawn stroke by stroke: sketched, or only partly drawn on. */
|
|
304
|
+
drawsOutline(e) {
|
|
305
|
+
return e.sketch !== void 0 || e.drawOn !== void 0 && e.drawOn < 1;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Draw a shape outline-first: the fill (clean) once the outline is complete,
|
|
309
|
+
* then the outline up to `drawOn`, in pencil strokes when sketched.
|
|
310
|
+
*/
|
|
311
|
+
renderOutlined(e, t, i, o) {
|
|
312
|
+
const s = Math.min(1, Math.max(0, t.drawOn ?? 1));
|
|
313
|
+
if (i && t.fillStyle && s >= 1 && i(), !t.strokeStyle || s <= 0) return;
|
|
314
|
+
const a = t.sketch ? G(e, t.sketch, this.time) : void 0;
|
|
315
|
+
a && (e.lineCap = t.lineCap ?? "round", e.lineJoin = t.lineJoin ?? "round"), o(s, a);
|
|
316
|
+
}
|
|
254
317
|
/**
|
|
255
318
|
* Render a rectangle.
|
|
256
319
|
*/
|
|
257
320
|
renderRect(e, t) {
|
|
321
|
+
if (this.drawsOutline(t)) {
|
|
322
|
+
const { x: i, y: o, width: s, height: a } = t;
|
|
323
|
+
return this.renderOutlined(
|
|
324
|
+
e,
|
|
325
|
+
t,
|
|
326
|
+
() => {
|
|
327
|
+
e.beginPath(), t.borderRadius && t.borderRadius > 0 ? this.roundRect(e, i, o, s, a, t.borderRadius) : e.rect(i, o, s, a), e.fill();
|
|
328
|
+
},
|
|
329
|
+
(n, r) => S(e, D(i, o, s, a, t.borderRadius), n, r)
|
|
330
|
+
);
|
|
331
|
+
}
|
|
258
332
|
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();
|
|
259
333
|
}
|
|
260
334
|
/**
|
|
261
335
|
* Draw a rounded rectangle path.
|
|
262
336
|
*/
|
|
263
|
-
roundRect(e, t, i, o, s,
|
|
264
|
-
const n = Math.min(
|
|
337
|
+
roundRect(e, t, i, o, s, a) {
|
|
338
|
+
const n = Math.min(a, o / 2, s / 2);
|
|
265
339
|
e.moveTo(t + n, i), e.lineTo(t + o - n, i), e.arcTo(t + o, i, t + o, i + n, n), e.lineTo(t + o, i + s - n), e.arcTo(t + o, i + s, t + o - n, i + s, n), e.lineTo(t + n, i + s), e.arcTo(t, i + s, t, i + s - n, n), e.lineTo(t, i + n), e.arcTo(t, i, t + n, i, n);
|
|
266
340
|
}
|
|
267
341
|
/**
|
|
268
342
|
* Render a circle.
|
|
269
343
|
*/
|
|
270
344
|
renderCircle(e, t) {
|
|
345
|
+
if (this.drawsOutline(t)) {
|
|
346
|
+
const { x: i, y: o, radius: s } = t;
|
|
347
|
+
return this.renderOutlined(
|
|
348
|
+
e,
|
|
349
|
+
t,
|
|
350
|
+
() => {
|
|
351
|
+
e.beginPath(), e.arc(i, o, s, 0, Math.PI * 2), e.fill();
|
|
352
|
+
},
|
|
353
|
+
(a, n) => {
|
|
354
|
+
if (n) return n.circle(i, o, s, a);
|
|
355
|
+
e.beginPath(), e.arc(i, o, s, -Math.PI / 2, -Math.PI / 2 + Math.PI * 2 * a), e.stroke();
|
|
356
|
+
}
|
|
357
|
+
);
|
|
358
|
+
}
|
|
271
359
|
e.beginPath(), e.arc(t.x, t.y, t.radius, 0, Math.PI * 2), t.fillStyle && e.fill(), t.strokeStyle && e.stroke(), e.closePath();
|
|
272
360
|
}
|
|
273
361
|
/**
|
|
@@ -277,8 +365,8 @@ class R {
|
|
|
277
365
|
const i = t.fontSize ?? 16, o = t.fontFamily ?? "sans-serif", s = t.fontWeight ?? 400;
|
|
278
366
|
if (e.font = `${s} ${i}px ${o}`, e.textAlign = t.textAlign ?? "left", e.textBaseline = t.textBaseline ?? "top", t.fillStyle) {
|
|
279
367
|
if (t.shine !== void 0 && typeof t.fillStyle == "string") {
|
|
280
|
-
const
|
|
281
|
-
for (const h of
|
|
368
|
+
const a = e.measureText(t.text).width, n = t.textAlign ?? "left", r = n === "center" ? t.x - a / 2 : n === "right" ? t.x - a : t.x, l = e.createLinearGradient(r, t.y, r + a, t.y);
|
|
369
|
+
for (const h of Y(t.shine, t.fillStyle))
|
|
282
370
|
l.addColorStop(h.offset, h.color);
|
|
283
371
|
e.fillStyle = l;
|
|
284
372
|
}
|
|
@@ -290,7 +378,19 @@ class R {
|
|
|
290
378
|
* Render a line.
|
|
291
379
|
*/
|
|
292
380
|
renderLine(e, t) {
|
|
293
|
-
t.lineCap && (e.lineCap = t.lineCap),
|
|
381
|
+
if (t.lineCap && (e.lineCap = t.lineCap), this.drawsOutline(t)) {
|
|
382
|
+
const i = [
|
|
383
|
+
{ x: t.x, y: t.y },
|
|
384
|
+
{ x: t.x2, y: t.y2 }
|
|
385
|
+
], o = Math.hypot(t.x2 - t.x, t.y2 - t.y);
|
|
386
|
+
return this.renderOutlined(
|
|
387
|
+
e,
|
|
388
|
+
t,
|
|
389
|
+
void 0,
|
|
390
|
+
(s, a) => S(e, [{ kind: "line", points: i, length: o }], s, a)
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
e.beginPath(), e.moveTo(t.x, t.y), e.lineTo(t.x2, t.y2), t.strokeStyle && e.stroke(), e.closePath();
|
|
294
394
|
}
|
|
295
395
|
/**
|
|
296
396
|
* Render an SVG path.
|
|
@@ -298,7 +398,14 @@ class R {
|
|
|
298
398
|
renderPath(e, t) {
|
|
299
399
|
t.lineCap && (e.lineCap = t.lineCap), t.lineJoin && (e.lineJoin = t.lineJoin);
|
|
300
400
|
const i = new Path2D(t.d);
|
|
301
|
-
e.translate(t.x, t.y),
|
|
401
|
+
if (e.translate(t.x, t.y), this.drawsOutline(t))
|
|
402
|
+
return this.renderOutlined(
|
|
403
|
+
e,
|
|
404
|
+
t,
|
|
405
|
+
() => e.fill(i),
|
|
406
|
+
(o, s) => S(e, R(t.d), o, s)
|
|
407
|
+
);
|
|
408
|
+
t.fillStyle && e.fill(i), t.strokeStyle && e.stroke(i);
|
|
302
409
|
}
|
|
303
410
|
/**
|
|
304
411
|
* Render an image.
|
|
@@ -306,13 +413,13 @@ class R {
|
|
|
306
413
|
renderImage(e, t) {
|
|
307
414
|
if (!t.image) return;
|
|
308
415
|
t.opacity !== void 0 && (e.globalAlpha = t.opacity);
|
|
309
|
-
const { x: i, y: o, width: s, height:
|
|
310
|
-
let
|
|
416
|
+
const { x: i, y: o, width: s, height: a } = t, n = t.objectFit ?? "fill", r = t.borderRadius ?? 0, l = t.image, h = l.naturalWidth || l.videoWidth || l.width || s, f = l.naturalHeight || l.videoHeight || l.height || a;
|
|
417
|
+
let p = i, u = o, d = s, m = a;
|
|
311
418
|
if (n !== "fill" && h > 0 && f > 0) {
|
|
312
|
-
const
|
|
313
|
-
|
|
419
|
+
const y = n === "cover" ? Math.max(s / h, a / f) : Math.min(s / h, a / f);
|
|
420
|
+
d = h * y, m = f * y, p = i + (s - d) / 2, u = o + (a - m) / 2;
|
|
314
421
|
}
|
|
315
|
-
e.save(), e.beginPath(), r > 0 && typeof e.roundRect == "function" ? e.roundRect(i, o, s,
|
|
422
|
+
e.save(), e.beginPath(), r > 0 && typeof e.roundRect == "function" ? e.roundRect(i, o, s, a, r) : e.rect(i, o, s, a), e.clip(), e.drawImage(t.image, p, u, d, m), e.restore();
|
|
316
423
|
}
|
|
317
424
|
/**
|
|
318
425
|
* Render a custom target by calling its draw function in local coordinates.
|
|
@@ -420,7 +527,7 @@ class R {
|
|
|
420
527
|
});
|
|
421
528
|
}
|
|
422
529
|
}
|
|
423
|
-
const
|
|
530
|
+
const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
|
|
424
531
|
"fill",
|
|
425
532
|
"stroke",
|
|
426
533
|
"d",
|
|
@@ -440,7 +547,7 @@ const P = "http://www.w3.org/2000/svg", L = /* @__PURE__ */ new Set([
|
|
|
440
547
|
"height",
|
|
441
548
|
"viewBox",
|
|
442
549
|
"preserveAspectRatio"
|
|
443
|
-
]),
|
|
550
|
+
]), k = {
|
|
444
551
|
strokeWidth: "stroke-width",
|
|
445
552
|
strokeLinecap: "stroke-linecap",
|
|
446
553
|
strokeLinejoin: "stroke-linejoin",
|
|
@@ -451,7 +558,7 @@ const P = "http://www.w3.org/2000/svg", L = /* @__PURE__ */ new Set([
|
|
|
451
558
|
strokeOpacity: "stroke-opacity",
|
|
452
559
|
borderRadius: "rx"
|
|
453
560
|
// Map CSS borderRadius to SVG rx
|
|
454
|
-
},
|
|
561
|
+
}, W = /* @__PURE__ */ new Set([
|
|
455
562
|
"x",
|
|
456
563
|
// Position x treated as translateX
|
|
457
564
|
"y",
|
|
@@ -470,8 +577,8 @@ const P = "http://www.w3.org/2000/svg", L = /* @__PURE__ */ new Set([
|
|
|
470
577
|
"motionPathX",
|
|
471
578
|
"motionPathY",
|
|
472
579
|
"motionPathRotate"
|
|
473
|
-
]),
|
|
474
|
-
class
|
|
580
|
+
]), H = /* @__PURE__ */ new Set(["clipTop", "clipRight", "clipBottom", "clipLeft"]);
|
|
581
|
+
class oe {
|
|
475
582
|
targets = /* @__PURE__ */ new Map();
|
|
476
583
|
/**
|
|
477
584
|
* Register an SVG element as an animation target.
|
|
@@ -510,13 +617,13 @@ class q {
|
|
|
510
617
|
* Apply properties to a single SVG element.
|
|
511
618
|
*/
|
|
512
619
|
applyProperties(e, t) {
|
|
513
|
-
const i = {}, o = {}, s = {},
|
|
620
|
+
const i = {}, o = {}, s = {}, a = {};
|
|
514
621
|
let n = !1;
|
|
515
622
|
for (const [r, l] of t)
|
|
516
|
-
|
|
623
|
+
r !== "drawOn" && (W.has(r) ? i[r] = l : r === "originX" || r === "originY" ? typeof l == "number" && (o[r] = l) : r === "perspective" ? typeof l == "number" && (i.perspective = l) : H.has(r) ? typeof l == "number" && (s[r] = l) : O.has(r) ? (a[r] = l, n = !0) : r === "text" ? typeof l == "string" && C(e, l) : r === "shine" ? typeof l == "number" && this.applyShine(e, l) : r === "opacity" ? (e.setAttribute("fill-opacity", String(l)), e.setAttribute("stroke-opacity", String(l))) : this.applyAttribute(e, r, l));
|
|
517
624
|
if (Object.keys(i).length > 0) {
|
|
518
625
|
const r = this.buildCssTransformString(i);
|
|
519
|
-
e.style.transform = r,
|
|
626
|
+
e.style.transform = r, I(e);
|
|
520
627
|
}
|
|
521
628
|
if (Object.keys(o).length > 0) {
|
|
522
629
|
const r = e.style;
|
|
@@ -527,7 +634,7 @@ class q {
|
|
|
527
634
|
e.style.clipPath = `inset(${r}% ${l}% ${h}% ${f}%)`;
|
|
528
635
|
}
|
|
529
636
|
if (n) {
|
|
530
|
-
const r =
|
|
637
|
+
const r = _(a);
|
|
531
638
|
r && (e.style.filter = r);
|
|
532
639
|
}
|
|
533
640
|
}
|
|
@@ -543,8 +650,8 @@ class q {
|
|
|
543
650
|
if (s !== void 0 && t.push(`rotate(${s}deg)`), e.rotateX !== void 0 && t.push(`rotateX(${e.rotateX}deg)`), e.rotateY !== void 0 && t.push(`rotateY(${e.rotateY}deg)`), e.scale !== void 0)
|
|
544
651
|
t.push(`scale(${e.scale})`);
|
|
545
652
|
else if (e.scaleX !== void 0 || e.scaleY !== void 0) {
|
|
546
|
-
const
|
|
547
|
-
t.push(`scale(${
|
|
653
|
+
const a = e.scaleX ?? 1, n = e.scaleY ?? 1;
|
|
654
|
+
t.push(`scale(${a}, ${n})`);
|
|
548
655
|
}
|
|
549
656
|
return e.skewX !== void 0 && t.push(`skewX(${e.skewX}deg)`), e.skewY !== void 0 && t.push(`skewY(${e.skewY}deg)`), t.join(" ");
|
|
550
657
|
}
|
|
@@ -561,25 +668,25 @@ class q {
|
|
|
561
668
|
if (!i || !o) return;
|
|
562
669
|
const s = e;
|
|
563
670
|
s.dataset.shineBase || (s.dataset.shineBase = e.getAttribute("fill") || "#000000");
|
|
564
|
-
const
|
|
671
|
+
const a = s.dataset.shineBase;
|
|
565
672
|
let n = i.querySelector("defs");
|
|
566
|
-
n || (n = o.createElementNS(
|
|
673
|
+
n || (n = o.createElementNS(b, "defs"), i.insertBefore(n, i.firstChild));
|
|
567
674
|
let r = s.dataset.shineGrad, l = r ? n.querySelector(`#${r}`) : null;
|
|
568
|
-
for (l || (r = `tinyfly-shine-${Math.random().toString(36).slice(2, 9)}`, s.dataset.shineGrad = r, l = o.createElementNS(
|
|
569
|
-
for (const h of
|
|
570
|
-
const f = o.createElementNS(
|
|
675
|
+
for (l || (r = `tinyfly-shine-${Math.random().toString(36).slice(2, 9)}`, s.dataset.shineGrad = r, l = o.createElementNS(b, "linearGradient"), l.setAttribute("id", r), n.appendChild(l)); l.firstChild; ) l.removeChild(l.firstChild);
|
|
676
|
+
for (const h of Y(t, a)) {
|
|
677
|
+
const f = o.createElementNS(b, "stop");
|
|
571
678
|
f.setAttribute("offset", String(h.offset)), f.setAttribute("stop-color", h.color), l.appendChild(f);
|
|
572
679
|
}
|
|
573
680
|
e.setAttribute("fill", `url(#${r})`);
|
|
574
681
|
}
|
|
575
682
|
applyAttribute(e, t, i) {
|
|
576
683
|
let o = t;
|
|
577
|
-
|
|
684
|
+
k[t] ? o = k[t] : N.has(t) && (o = t);
|
|
578
685
|
const s = Array.isArray(i) ? i.join(" ") : String(i);
|
|
579
686
|
e.setAttribute(o, s);
|
|
580
687
|
}
|
|
581
688
|
}
|
|
582
|
-
const
|
|
689
|
+
const V = `
|
|
583
690
|
attribute vec2 a_position;
|
|
584
691
|
attribute vec2 a_texCoord;
|
|
585
692
|
uniform mat3 u_matrix;
|
|
@@ -589,7 +696,7 @@ void main() {
|
|
|
589
696
|
gl_Position = vec4(position.xy, 0.0, 1.0);
|
|
590
697
|
v_texCoord = a_texCoord;
|
|
591
698
|
}
|
|
592
|
-
`,
|
|
699
|
+
`, j = `
|
|
593
700
|
precision mediump float;
|
|
594
701
|
uniform vec4 u_color;
|
|
595
702
|
uniform sampler2D u_texture;
|
|
@@ -600,7 +707,7 @@ void main() {
|
|
|
600
707
|
vec4 color = u_useTexture ? texture2D(u_texture, v_texCoord) : u_color;
|
|
601
708
|
gl_FragColor = vec4(color.rgb, color.a * u_opacity);
|
|
602
709
|
}
|
|
603
|
-
`,
|
|
710
|
+
`, z = /* @__PURE__ */ new Set([
|
|
604
711
|
"x",
|
|
605
712
|
"y",
|
|
606
713
|
"width",
|
|
@@ -617,7 +724,7 @@ void main() {
|
|
|
617
724
|
"motionPathY",
|
|
618
725
|
"motionPathRotate"
|
|
619
726
|
]);
|
|
620
|
-
class
|
|
727
|
+
class se {
|
|
621
728
|
gl;
|
|
622
729
|
program;
|
|
623
730
|
positionBuffer;
|
|
@@ -628,7 +735,7 @@ class J {
|
|
|
628
735
|
basePositions = /* @__PURE__ */ new Map();
|
|
629
736
|
locations;
|
|
630
737
|
constructor(e) {
|
|
631
|
-
this.gl = e, this.program =
|
|
738
|
+
this.gl = e, this.program = q(e, V, j), this.locations = {
|
|
632
739
|
position: e.getAttribLocation(this.program, "a_position"),
|
|
633
740
|
texCoord: e.getAttribLocation(this.program, "a_texCoord"),
|
|
634
741
|
matrix: e.getUniformLocation(this.program, "u_matrix"),
|
|
@@ -636,7 +743,7 @@ class J {
|
|
|
636
743
|
texture: e.getUniformLocation(this.program, "u_texture"),
|
|
637
744
|
useTexture: e.getUniformLocation(this.program, "u_useTexture"),
|
|
638
745
|
opacity: e.getUniformLocation(this.program, "u_opacity")
|
|
639
|
-
}, this.positionBuffer =
|
|
746
|
+
}, this.positionBuffer = E(e, [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]), this.texCoordBuffer = E(e, [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]);
|
|
640
747
|
}
|
|
641
748
|
registerTarget(e, t) {
|
|
642
749
|
this.targets.set(e, t), this.basePositions.set(e, { x: t.x, y: t.y });
|
|
@@ -658,8 +765,8 @@ class J {
|
|
|
658
765
|
const o = this.targets.get(t);
|
|
659
766
|
if (!o) continue;
|
|
660
767
|
const s = this.basePositions.get(t) ?? { x: 0, y: 0 };
|
|
661
|
-
for (const [
|
|
662
|
-
this.applyProperty(o, s,
|
|
768
|
+
for (const [a, n] of i)
|
|
769
|
+
this.applyProperty(o, s, a, n);
|
|
663
770
|
}
|
|
664
771
|
}
|
|
665
772
|
applyProperty(e, t, i, o) {
|
|
@@ -676,7 +783,7 @@ class J {
|
|
|
676
783
|
e.rotate = o;
|
|
677
784
|
return;
|
|
678
785
|
}
|
|
679
|
-
if (
|
|
786
|
+
if (z.has(i)) {
|
|
680
787
|
e[i] = o;
|
|
681
788
|
return;
|
|
682
789
|
}
|
|
@@ -686,17 +793,17 @@ class J {
|
|
|
686
793
|
/** Draw every registered target. */
|
|
687
794
|
render() {
|
|
688
795
|
const e = this.gl, { width: t, height: i } = e.canvas;
|
|
689
|
-
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),
|
|
796
|
+
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), M(e, this.positionBuffer, this.locations.position), M(e, this.texCoordBuffer, this.locations.texCoord);
|
|
690
797
|
for (const [o, s] of this.targets)
|
|
691
798
|
this.drawTarget(o, s, t, i);
|
|
692
799
|
}
|
|
693
800
|
drawTarget(e, t, i, o) {
|
|
694
|
-
const s = this.gl,
|
|
695
|
-
if (s.uniformMatrix3fv(this.locations.matrix, !1,
|
|
801
|
+
const s = this.gl, a = J(t, i, o);
|
|
802
|
+
if (s.uniformMatrix3fv(this.locations.matrix, !1, a), s.uniform1f(this.locations.opacity, t.opacity ?? 1), t.texture)
|
|
696
803
|
s.bindTexture(s.TEXTURE_2D, this.textureFor(e, t.texture)), s.uniform1i(this.locations.useTexture, 1), s.uniform1i(this.locations.texture, 0);
|
|
697
804
|
else {
|
|
698
805
|
s.uniform1i(this.locations.useTexture, 0);
|
|
699
|
-
const [n, r, l] =
|
|
806
|
+
const [n, r, l] = Z(t.fill ?? "#ffffff");
|
|
700
807
|
s.uniform4f(this.locations.color, n, r, l, 1);
|
|
701
808
|
}
|
|
702
809
|
s.drawArrays(s.TRIANGLES, 0, 6);
|
|
@@ -712,22 +819,22 @@ class J {
|
|
|
712
819
|
this.clearTargets(), this.gl.deleteProgram(this.program), this.gl.deleteBuffer(this.positionBuffer), this.gl.deleteBuffer(this.texCoordBuffer);
|
|
713
820
|
}
|
|
714
821
|
}
|
|
715
|
-
function
|
|
716
|
-
const i = (
|
|
822
|
+
function J(c, e, t) {
|
|
823
|
+
const i = (c.scale ?? c.scaleX ?? 1) * c.width, o = (c.scale ?? c.scaleY ?? 1) * c.height, s = (c.originX ?? 50) / 100, a = (c.originY ?? 50) / 100, n = (c.rotate ?? 0) * Math.PI / 180, r = Math.cos(n), l = Math.sin(n), h = -s, f = -a, p = r * i, u = l * i, d = -l * o, m = r * o, y = c.x + p * h + d * f, $ = c.y + u * h + m * f, w = 2 / e, P = -2 / t;
|
|
717
824
|
return new Float32Array([
|
|
718
|
-
|
|
719
|
-
|
|
825
|
+
p * w,
|
|
826
|
+
u * P,
|
|
720
827
|
0,
|
|
721
|
-
|
|
722
|
-
|
|
828
|
+
d * w,
|
|
829
|
+
m * P,
|
|
723
830
|
0,
|
|
724
|
-
|
|
725
|
-
|
|
831
|
+
y * w - 1,
|
|
832
|
+
$ * P + 1,
|
|
726
833
|
1
|
|
727
834
|
]);
|
|
728
835
|
}
|
|
729
|
-
function
|
|
730
|
-
const e =
|
|
836
|
+
function Z(c) {
|
|
837
|
+
const e = c.trim().replace("#", "");
|
|
731
838
|
return e.length === 3 ? [
|
|
732
839
|
Number.parseInt(e[0] + e[0], 16) / 255,
|
|
733
840
|
Number.parseInt(e[1] + e[1], 16) / 255,
|
|
@@ -738,38 +845,46 @@ function N(a) {
|
|
|
738
845
|
Number.parseInt(e.slice(4, 6), 16) / 255
|
|
739
846
|
] : [1, 1, 1];
|
|
740
847
|
}
|
|
741
|
-
function
|
|
742
|
-
const i =
|
|
848
|
+
function q(c, e, t) {
|
|
849
|
+
const i = c.createProgram();
|
|
743
850
|
if (!i) throw new Error("WebGLAdapter: could not create a program");
|
|
744
|
-
if (
|
|
745
|
-
throw new Error(`WebGLAdapter: program link failed — ${
|
|
851
|
+
if (c.attachShader(i, A(c, c.VERTEX_SHADER, e)), c.attachShader(i, A(c, c.FRAGMENT_SHADER, t)), c.linkProgram(i), !c.getProgramParameter(i, c.LINK_STATUS))
|
|
852
|
+
throw new Error(`WebGLAdapter: program link failed — ${c.getProgramInfoLog(i)}`);
|
|
746
853
|
return i;
|
|
747
854
|
}
|
|
748
|
-
function
|
|
749
|
-
const i =
|
|
855
|
+
function A(c, e, t) {
|
|
856
|
+
const i = c.createShader(e);
|
|
750
857
|
if (!i) throw new Error("WebGLAdapter: could not create a shader");
|
|
751
|
-
if (
|
|
752
|
-
throw new Error(`WebGLAdapter: shader compile failed — ${
|
|
858
|
+
if (c.shaderSource(i, t), c.compileShader(i), !c.getShaderParameter(i, c.COMPILE_STATUS))
|
|
859
|
+
throw new Error(`WebGLAdapter: shader compile failed — ${c.getShaderInfoLog(i)}`);
|
|
753
860
|
return i;
|
|
754
861
|
}
|
|
755
|
-
function
|
|
756
|
-
const t =
|
|
862
|
+
function E(c, e) {
|
|
863
|
+
const t = c.createBuffer();
|
|
757
864
|
if (!t) throw new Error("WebGLAdapter: could not create a buffer");
|
|
758
|
-
return
|
|
865
|
+
return c.bindBuffer(c.ARRAY_BUFFER, t), c.bufferData(c.ARRAY_BUFFER, new Float32Array(e), c.STATIC_DRAW), t;
|
|
759
866
|
}
|
|
760
|
-
function
|
|
761
|
-
t < 0 || (
|
|
867
|
+
function M(c, e, t) {
|
|
868
|
+
t < 0 || (c.bindBuffer(c.ARRAY_BUFFER, e), c.enableVertexAttribArray(t), c.vertexAttribPointer(t, 2, c.FLOAT, !1, 0, 0));
|
|
762
869
|
}
|
|
763
870
|
export {
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
871
|
+
v as CanvasAdapter,
|
|
872
|
+
ae as DOMAdapter,
|
|
873
|
+
oe as SVGAdapter,
|
|
874
|
+
se as WebGLAdapter,
|
|
875
|
+
le as boilFrame,
|
|
876
|
+
U as buildFlipTracks,
|
|
877
|
+
S as drawOutline,
|
|
878
|
+
te as flip,
|
|
879
|
+
ie as isGradient,
|
|
880
|
+
Z as parseColor,
|
|
881
|
+
F as partialPath,
|
|
882
|
+
he as pathLength,
|
|
883
|
+
R as pathOutline,
|
|
884
|
+
fe as pointAlong,
|
|
885
|
+
J as quadMatrix,
|
|
886
|
+
g as recordFlipState,
|
|
887
|
+
D as rectOutline,
|
|
888
|
+
C as setTextContent,
|
|
889
|
+
G as sketchPen
|
|
775
890
|
};
|