@algorisys/tinyfly 0.74.0 → 0.74.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/lib/addons/characters.js +100 -93
- package/lib/browser/tinyfly.iife.js +4 -4
- package/lib/browser/tinyfly.js +797 -790
- package/lib/browser/tinyfly.umd.js +4 -4
- package/lib/types/characters/stick-figure.d.ts +13 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -217,7 +217,7 @@ GSAP-shaped functions at the top level. Teaching embeds are included: add
|
|
|
217
217
|
itself.
|
|
218
218
|
|
|
219
219
|
```html
|
|
220
|
-
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.74.
|
|
220
|
+
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.74.1/cdn/tinyfly.iife.js"></script>
|
|
221
221
|
<script>
|
|
222
222
|
tinyfly.to('.box', { x: 200, rotate: 90, duration: 1, ease: 'power2.out' })
|
|
223
223
|
|
|
@@ -253,7 +253,7 @@ A teaching figure needs no code at all:
|
|
|
253
253
|
<script type="application/json" data-tinyfly-timeline>{ …timeline JSON with markers… }</script>
|
|
254
254
|
<figcaption>Appending to a full slice</figcaption>
|
|
255
255
|
</figure>
|
|
256
|
-
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.74.
|
|
256
|
+
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.74.1/cdn/tinyfly.iife.js" data-tinyfly-auto></script>
|
|
257
257
|
```
|
|
258
258
|
|
|
259
259
|
See [Teaching Animations](docs/teaching.md).
|
|
@@ -352,7 +352,7 @@ Without a build step, the player bundle puts the same functions on a `tinyfly` g
|
|
|
352
352
|
<div data-tinyfly="box" style="width: 60px; height: 60px; background: #4a9eff;"></div>
|
|
353
353
|
</div>
|
|
354
354
|
|
|
355
|
-
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.74.
|
|
355
|
+
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.74.1/cdn/tinyfly-player.iife.js"></script>
|
|
356
356
|
<script>
|
|
357
357
|
tinyfly.play('#animation', './animation.json', { loop: -1 })
|
|
358
358
|
</script>
|
|
@@ -461,7 +461,7 @@ Or skip the code entirely with declarative embeds (see [Teaching Animations](doc
|
|
|
461
461
|
<svg viewBox="0 0 720 200">…</svg>
|
|
462
462
|
<script type="application/json" data-tinyfly-timeline>{ …timeline JSON… }</script>
|
|
463
463
|
</figure>
|
|
464
|
-
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.74.
|
|
464
|
+
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.74.1/cdn/tinyfly-embed.iife.js" data-tinyfly-auto></script>
|
|
465
465
|
```
|
|
466
466
|
|
|
467
467
|
### Audio / Video Sync
|
package/lib/addons/characters.js
CHANGED
|
@@ -21,10 +21,10 @@ const k = {
|
|
|
21
21
|
lookX: 0,
|
|
22
22
|
lookY: 0
|
|
23
23
|
};
|
|
24
|
-
function p(
|
|
25
|
-
return { ...k, ...
|
|
24
|
+
function p(t) {
|
|
25
|
+
return { ...k, ...t };
|
|
26
26
|
}
|
|
27
|
-
const
|
|
27
|
+
const v = {
|
|
28
28
|
mouth: 0,
|
|
29
29
|
smile: 0,
|
|
30
30
|
mouthWidth: 1,
|
|
@@ -35,8 +35,8 @@ const W = {
|
|
|
35
35
|
browTilt: 0,
|
|
36
36
|
lookX: 0,
|
|
37
37
|
lookY: 0
|
|
38
|
-
}, a = (
|
|
39
|
-
neutral:
|
|
38
|
+
}, a = (t) => ({ ...v, ...t }), b = {
|
|
39
|
+
neutral: v,
|
|
40
40
|
happy: a({ smile: 0.9, leftBrow: 0.2, rightBrow: 0.2 }),
|
|
41
41
|
joyful: a({ mouth: 0.6, smile: 1, mouthWidth: 1.2, leftEye: 0, rightEye: 0, leftBrow: 0.4, rightBrow: 0.4 }),
|
|
42
42
|
sad: a({ smile: -0.8, leftEye: 0.8, rightEye: 0.8, browTilt: 0.9, leftBrow: -0.1, rightBrow: -0.1, lookY: 0.6 }),
|
|
@@ -55,10 +55,10 @@ const W = {
|
|
|
55
55
|
smug: a({ smile: 0.6, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.6, leftBrow: 0.1, rightBrow: 0.5, lookX: 0.5 }),
|
|
56
56
|
wink: a({ smile: 0.9, leftEye: 0, rightEye: 1, leftBrow: -0.2, rightBrow: 0.3 })
|
|
57
57
|
};
|
|
58
|
-
function
|
|
59
|
-
return { ...
|
|
58
|
+
function R(t, e) {
|
|
59
|
+
return { ...t, ...typeof e == "string" ? b[e] : e };
|
|
60
60
|
}
|
|
61
|
-
const
|
|
61
|
+
const A = {
|
|
62
62
|
rest: k,
|
|
63
63
|
wave: p({ rightShoulder: 135, rightElbow: 30, headTilt: 6, ...b.happy }),
|
|
64
64
|
cheer: p({ leftShoulder: 125, leftElbow: 20, rightShoulder: 125, rightElbow: 20, ...b.joyful }),
|
|
@@ -69,136 +69,143 @@ const X = {
|
|
|
69
69
|
handsOnHips: p({ leftShoulder: 45, leftElbow: -100, rightShoulder: 45, rightElbow: -100, leftHip: 14, rightHip: 14, smile: 0.8 }),
|
|
70
70
|
sad: p({ leftShoulder: 14, rightShoulder: 14, leftElbow: -4, rightElbow: -4, headTilt: -14, lean: -3, ...b.sad }),
|
|
71
71
|
surprised: p({ leftShoulder: 70, leftElbow: 60, rightShoulder: 70, rightElbow: 60, ...b.surprised })
|
|
72
|
-
},
|
|
73
|
-
function
|
|
74
|
-
const l = { ...
|
|
75
|
-
for (const h of
|
|
72
|
+
}, I = Object.keys(k);
|
|
73
|
+
function O(t, e, o) {
|
|
74
|
+
const l = { ...t };
|
|
75
|
+
for (const h of I) l[h] = t[h] + (e[h] - t[h]) * o;
|
|
76
76
|
return l;
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
const P = 24, _ = 40;
|
|
79
|
+
function F(t, e = k, o = 1) {
|
|
80
|
+
const l = Math.sin(t * Math.PI * 2) * o, h = Math.cos(t * Math.PI * 2) * o, u = (g) => g <= _ ? 22 * l : g;
|
|
80
81
|
return {
|
|
81
82
|
...e,
|
|
82
|
-
//
|
|
83
|
-
leftHip:
|
|
84
|
-
rightHip:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
// Left foot forward while swing > 0, right foot back; then the other way.
|
|
84
|
+
leftHip: -P * l,
|
|
85
|
+
rightHip: -P * l,
|
|
86
|
+
// The leg swinging forward lifts, its shin trailing backward (-x). A positive
|
|
87
|
+
// knee folds toward the centre, which is backward only for the right leg.
|
|
88
|
+
leftKnee: -30 * Math.max(0, h),
|
|
89
|
+
rightKnee: 30 * Math.max(0, -h),
|
|
90
|
+
// Arms swing against the legs: left arm back while the left foot is forward.
|
|
91
|
+
leftShoulder: u(e.leftShoulder),
|
|
92
|
+
rightShoulder: u(e.rightShoulder)
|
|
90
93
|
};
|
|
91
94
|
}
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
return e * t;
|
|
95
|
+
function U(t, e = 1) {
|
|
96
|
+
return 4 * ((Y + H) * t) * Math.sin(P * e * Math.PI / 180);
|
|
95
97
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
function K(t) {
|
|
99
|
+
const e = Math.abs(Math.sin(t / 65)), o = 0.55 + 0.45 * Math.sin(t / 310);
|
|
100
|
+
return e * o;
|
|
101
|
+
}
|
|
102
|
+
const C = 0.12, N = 0.1, L = 0.21, q = 0.19, Y = 0.24, H = 0.22, M = (t) => t * Math.PI / 180, G = (t, e) => ({ x: e * Math.sin(M(t)), y: Math.cos(M(t)) });
|
|
103
|
+
function j(t, e, o, l, h, u) {
|
|
104
|
+
const g = Math.max(1, u * 0.6), i = 0.12 * o, n = l - 0.12 * o, E = i + e.lookX * 0.08 * o, y = e.lookY * 0.07 * o, S = [
|
|
105
|
+
{ x: -0.34 * o, open: e.leftEye, brow: e.leftBrow, side: -1 },
|
|
106
|
+
{ x: 0.34 * o, open: e.rightEye, brow: e.rightBrow, side: 1 }
|
|
101
107
|
];
|
|
102
|
-
|
|
108
|
+
t.fillStyle = h, t.strokeStyle = h, t.lineWidth = g;
|
|
103
109
|
for (const s of S) {
|
|
104
110
|
const f = Math.max(0, s.open) * (1 - Math.min(1, Math.max(0, e.blink)));
|
|
105
111
|
if (f < 0.2) {
|
|
106
|
-
const T = e.smile > 0.5 ? -0.12 *
|
|
107
|
-
|
|
112
|
+
const T = e.smile > 0.5 ? -0.12 * o : 0.06 * o;
|
|
113
|
+
t.beginPath(), t.moveTo(s.x + i - 0.12 * o, n), t.quadraticCurveTo(s.x + i, n + T, s.x + i + 0.12 * o, n), t.stroke();
|
|
108
114
|
} else {
|
|
109
115
|
if (f > 1.2) {
|
|
110
|
-
const
|
|
111
|
-
|
|
116
|
+
const W = 0.13 * o * f;
|
|
117
|
+
t.beginPath(), t.ellipse(s.x + i, n, W * 0.85, W, 0, 0, Math.PI * 2), t.fillStyle = "#ffffff", t.fill(), t.stroke(), t.fillStyle = h;
|
|
112
118
|
}
|
|
113
|
-
const T = f > 1.2 ? 0.075 *
|
|
114
|
-
|
|
119
|
+
const T = f > 1.2 ? 0.075 * o : 0.1 * o;
|
|
120
|
+
t.beginPath(), t.ellipse(s.x + E, n + y, T, T * 1.1 * Math.min(f, 1), 0, 0, Math.PI * 2), t.fill();
|
|
115
121
|
}
|
|
116
|
-
const c =
|
|
117
|
-
|
|
122
|
+
const c = n - 0.3 * o - s.brow * 0.14 * o - Math.max(0, f - 1) * 0.12 * o, B = s.x + i - s.side * 0.13 * o, X = s.x + i + s.side * 0.13 * o;
|
|
123
|
+
t.beginPath(), t.moveTo(X, c), t.lineTo(B, c - e.browTilt * 0.1 * o), t.stroke();
|
|
118
124
|
}
|
|
119
|
-
const w = l + 0.4 *
|
|
120
|
-
if (
|
|
121
|
-
|
|
125
|
+
const w = l + 0.4 * o, m = 0.25 * o * Math.max(0.3, e.mouthWidth), d = Math.min(1, Math.max(0, e.mouth));
|
|
126
|
+
if (t.beginPath(), d <= 0.05) {
|
|
127
|
+
t.moveTo(i - m, w), t.quadraticCurveTo(i, w + e.smile * 0.25 * o, i + m, w), t.stroke();
|
|
122
128
|
return;
|
|
123
129
|
}
|
|
124
|
-
const
|
|
125
|
-
e.smile > 0.3 ? (
|
|
130
|
+
const r = 0.3 * o * d;
|
|
131
|
+
e.smile > 0.3 ? (t.moveTo(i - m, w - 0.05 * o), t.lineTo(i + m, w - 0.05 * o), t.quadraticCurveTo(i, w + r * 2, i - m, w - 0.05 * o)) : e.smile < -0.3 ? (t.moveTo(i - m, w + r * 0.6), t.lineTo(i + m, w + r * 0.6), t.quadraticCurveTo(i, w - r * 1.4, i - m, w + r * 0.6)) : t.ellipse(i, w, m * 0.8, r, 0, 0, Math.PI * 2), t.fill();
|
|
126
132
|
}
|
|
127
|
-
function
|
|
128
|
-
const l =
|
|
129
|
-
|
|
130
|
-
const E = (
|
|
131
|
-
const B =
|
|
132
|
-
return { x:
|
|
133
|
-
}, y = (...
|
|
134
|
-
|
|
135
|
-
for (const
|
|
136
|
-
|
|
133
|
+
function D(t, e, o = {}) {
|
|
134
|
+
const l = o.height ?? 300, h = o.color ?? "#1e293b", u = (o.facing ?? 1) < 0 ? -1 : 1, g = C * l, i = -0.46 * l, n = -0.76 * l;
|
|
135
|
+
t.save(), t.scale(u, 1), t.strokeStyle = h, t.lineWidth = o.lineWidth ?? l * 0.025, t.lineCap = "round", t.lineJoin = "round";
|
|
136
|
+
const E = (d, r, s, f, c) => {
|
|
137
|
+
const B = G(s, f);
|
|
138
|
+
return { x: d + B.x * c * l, y: r + B.y * c * l };
|
|
139
|
+
}, y = (...d) => {
|
|
140
|
+
t.beginPath(), t.moveTo(d[0].x, d[0].y);
|
|
141
|
+
for (const r of d.slice(1)) t.lineTo(r.x, r.y);
|
|
142
|
+
t.stroke();
|
|
137
143
|
};
|
|
138
|
-
for (const [
|
|
144
|
+
for (const [d, r, s] of [
|
|
139
145
|
[-1, e.leftHip, e.leftKnee],
|
|
140
146
|
[1, e.rightHip, e.rightKnee]
|
|
141
147
|
]) {
|
|
142
|
-
const f = E(0, i,
|
|
143
|
-
y({ x: 0, y: i }, f, E(f.x, f.y,
|
|
148
|
+
const f = E(0, i, r, d, Y);
|
|
149
|
+
y({ x: 0, y: i }, f, E(f.x, f.y, r - s, d, H));
|
|
144
150
|
}
|
|
145
|
-
|
|
146
|
-
const S =
|
|
147
|
-
for (const [
|
|
151
|
+
t.translate(0, i), t.rotate(M(e.lean)), t.translate(0, -i), y({ x: 0, y: i }, { x: 0, y: n });
|
|
152
|
+
const S = n + N * l;
|
|
153
|
+
for (const [d, r, s] of [
|
|
148
154
|
[-1, e.leftShoulder, e.leftElbow],
|
|
149
155
|
[1, e.rightShoulder, e.rightElbow]
|
|
150
156
|
]) {
|
|
151
|
-
const f = E(0, S,
|
|
152
|
-
y({ x: 0, y: S }, f, E(f.x, f.y,
|
|
157
|
+
const f = E(0, S, r, d, L);
|
|
158
|
+
y({ x: 0, y: S }, f, E(f.x, f.y, r + s, d, q));
|
|
153
159
|
}
|
|
154
|
-
|
|
155
|
-
const w = -
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
160
|
+
t.translate(0, n), t.rotate(M(e.headTilt));
|
|
161
|
+
const w = -g;
|
|
162
|
+
t.beginPath(), t.arc(0, w, g, 0, Math.PI * 2);
|
|
163
|
+
const m = o.headFill ?? "#ffffff";
|
|
164
|
+
m !== "none" && (t.fillStyle = m, t.fill()), t.stroke(), j(t, e, g, w, h, o.lineWidth ?? l * 0.025), t.restore(), o.label && (t.save(), t.fillStyle = h, t.font = o.labelFont ?? `700 ${Math.round(l * 0.11)}px sans-serif`, t.textAlign = "center", t.textBaseline = "bottom", t.fillText(o.label, 0, -l - 0.04 * l), t.restore());
|
|
159
165
|
}
|
|
160
|
-
function
|
|
161
|
-
const e =
|
|
166
|
+
function $(t) {
|
|
167
|
+
const e = t.style ?? {}, o = e.height ?? 300, l = o * 0.8, h = { ...p(t.pose ?? {}), walk: 0, walking: 0, talk: 0 };
|
|
162
168
|
return {
|
|
163
169
|
type: "custom",
|
|
164
|
-
x:
|
|
165
|
-
y:
|
|
170
|
+
x: t.x - l / 2,
|
|
171
|
+
y: t.y - o,
|
|
166
172
|
width: l,
|
|
167
|
-
height:
|
|
173
|
+
height: o,
|
|
168
174
|
props: { ...h },
|
|
169
|
-
draw(
|
|
170
|
-
const
|
|
171
|
-
let y =
|
|
172
|
-
|
|
175
|
+
draw(u, g, i) {
|
|
176
|
+
const n = g.props, E = { ...n };
|
|
177
|
+
let y = n.walking > 0 ? O(E, F(n.walk, E), n.walking) : E;
|
|
178
|
+
n.talk > 0 && (y = { ...y, mouth: Math.max(y.mouth, n.talk * K(i)) }), u.translate(l / 2, o), D(u, y, e);
|
|
173
179
|
}
|
|
174
180
|
};
|
|
175
181
|
}
|
|
176
|
-
function
|
|
177
|
-
const
|
|
182
|
+
function J(t, e) {
|
|
183
|
+
const o = [];
|
|
178
184
|
return e.forEach((l, h) => {
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
}),
|
|
182
|
-
id: `${
|
|
183
|
-
target:
|
|
185
|
+
const u = h === 0 ? k : o[h - 1], g = typeof l.pose == "string" ? A[l.pose] : { ...u, ...l.pose };
|
|
186
|
+
o.push(l.expression ? R(g, l.expression) : g);
|
|
187
|
+
}), I.filter((l) => o.some((h) => h[l] !== k[l])).map((l) => ({
|
|
188
|
+
id: `${t}-${l}`,
|
|
189
|
+
target: t,
|
|
184
190
|
property: l,
|
|
185
|
-
keyframes: e.map((h,
|
|
191
|
+
keyframes: e.map((h, u) => ({
|
|
186
192
|
time: h.time,
|
|
187
|
-
value:
|
|
193
|
+
value: o[u][l],
|
|
188
194
|
...h.easing ? { easing: h.easing } : {}
|
|
189
195
|
}))
|
|
190
196
|
}));
|
|
191
197
|
}
|
|
192
198
|
export {
|
|
193
199
|
b as EXPRESSIONS,
|
|
194
|
-
|
|
200
|
+
A as POSES,
|
|
195
201
|
k as REST_POSE,
|
|
196
|
-
|
|
197
|
-
|
|
202
|
+
O as blendPose,
|
|
203
|
+
D as drawStickFigure,
|
|
198
204
|
p as pose,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
K as
|
|
203
|
-
|
|
205
|
+
J as poseTracks,
|
|
206
|
+
$ as stickFigureTarget,
|
|
207
|
+
U as strideLength,
|
|
208
|
+
K as talkingMouth,
|
|
209
|
+
F as walkPose,
|
|
210
|
+
R as withExpression
|
|
204
211
|
};
|