@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 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.0/cdn/tinyfly.iife.js"></script>
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.0/cdn/tinyfly.iife.js" data-tinyfly-auto></script>
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.0/cdn/tinyfly-player.iife.js"></script>
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.0/cdn/tinyfly-embed.iife.js" data-tinyfly-auto></script>
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
@@ -21,10 +21,10 @@ const k = {
21
21
  lookX: 0,
22
22
  lookY: 0
23
23
  };
24
- function p(o) {
25
- return { ...k, ...o };
24
+ function p(t) {
25
+ return { ...k, ...t };
26
26
  }
27
- const W = {
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 = (o) => ({ ...W, ...o }), b = {
39
- neutral: W,
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 H(o, e) {
59
- return { ...o, ...typeof e == "string" ? b[e] : e };
58
+ function R(t, e) {
59
+ return { ...t, ...typeof e == "string" ? b[e] : e };
60
60
  }
61
- const X = {
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
- }, v = Object.keys(k);
73
- function I(o, e, t) {
74
- const l = { ...o };
75
- for (const h of v) l[h] = o[h] + (e[h] - o[h]) * t;
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
- function K(o, e = k, t = 1) {
79
- const l = Math.sin(o * Math.PI * 2), h = Math.cos(o * Math.PI * 2);
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
- // Legs scissor: one thigh swings the way the other swings back.
83
- leftHip: e.leftHip + 22 * l * t,
84
- rightHip: e.rightHip - 22 * l * t,
85
- leftKnee: e.leftKnee + 14 * Math.max(0, h) * t,
86
- rightKnee: e.rightKnee + 14 * Math.max(0, -h) * t,
87
- // Arms swing against the legs.
88
- leftShoulder: e.leftShoulder - 14 * l * t,
89
- rightShoulder: e.rightShoulder + 14 * l * t
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 O(o) {
93
- const e = Math.abs(Math.sin(o / 65)), t = 0.55 + 0.45 * Math.sin(o / 310);
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
- const R = 0.12, F = 0.1, A = 0.21, C = 0.19, _ = 0.24, q = 0.22, M = (o) => o * Math.PI / 180, j = (o, e) => ({ x: e * Math.sin(M(o)), y: Math.cos(M(o)) });
97
- function D(o, e, t, l, h, g) {
98
- const m = Math.max(1, g * 0.6), i = 0.12 * t, r = l - 0.12 * t, E = i + e.lookX * 0.08 * t, y = e.lookY * 0.07 * t, S = [
99
- { x: -0.34 * t, open: e.leftEye, brow: e.leftBrow, side: -1 },
100
- { x: 0.34 * t, open: e.rightEye, brow: e.rightBrow, side: 1 }
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
- o.fillStyle = h, o.strokeStyle = h, o.lineWidth = m;
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 * t : 0.06 * t;
107
- o.beginPath(), o.moveTo(s.x + i - 0.12 * t, r), o.quadraticCurveTo(s.x + i, r + T, s.x + i + 0.12 * t, r), o.stroke();
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 P = 0.13 * t * f;
111
- o.beginPath(), o.ellipse(s.x + i, r, P * 0.85, P, 0, 0, Math.PI * 2), o.fillStyle = "#ffffff", o.fill(), o.stroke(), o.fillStyle = h;
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 * t : 0.1 * t;
114
- o.beginPath(), o.ellipse(s.x + E, r + y, T, T * 1.1 * Math.min(f, 1), 0, 0, Math.PI * 2), o.fill();
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 = r - 0.3 * t - s.brow * 0.14 * t - Math.max(0, f - 1) * 0.12 * t, B = s.x + i - s.side * 0.13 * t, Y = s.x + i + s.side * 0.13 * t;
117
- o.beginPath(), o.moveTo(Y, c), o.lineTo(B, c - e.browTilt * 0.1 * t), o.stroke();
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 * t, d = 0.25 * t * Math.max(0.3, e.mouthWidth), u = Math.min(1, Math.max(0, e.mouth));
120
- if (o.beginPath(), u <= 0.05) {
121
- o.moveTo(i - d, w), o.quadraticCurveTo(i, w + e.smile * 0.25 * t, i + d, w), o.stroke();
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 n = 0.3 * t * u;
125
- e.smile > 0.3 ? (o.moveTo(i - d, w - 0.05 * t), o.lineTo(i + d, w - 0.05 * t), o.quadraticCurveTo(i, w + n * 2, i - d, w - 0.05 * t)) : e.smile < -0.3 ? (o.moveTo(i - d, w + n * 0.6), o.lineTo(i + d, w + n * 0.6), o.quadraticCurveTo(i, w - n * 1.4, i - d, w + n * 0.6)) : o.ellipse(i, w, d * 0.8, n, 0, 0, Math.PI * 2), o.fill();
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 N(o, e, t = {}) {
128
- const l = t.height ?? 300, h = t.color ?? "#1e293b", g = (t.facing ?? 1) < 0 ? -1 : 1, m = R * l, i = -0.46 * l, r = -0.76 * l;
129
- o.save(), o.scale(g, 1), o.strokeStyle = h, o.lineWidth = t.lineWidth ?? l * 0.025, o.lineCap = "round", o.lineJoin = "round";
130
- const E = (u, n, s, f, c) => {
131
- const B = j(s, f);
132
- return { x: u + B.x * c * l, y: n + B.y * c * l };
133
- }, y = (...u) => {
134
- o.beginPath(), o.moveTo(u[0].x, u[0].y);
135
- for (const n of u.slice(1)) o.lineTo(n.x, n.y);
136
- o.stroke();
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 [u, n, s] of [
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, n, u, _);
143
- y({ x: 0, y: i }, f, E(f.x, f.y, n - s, u, q));
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
- o.translate(0, i), o.rotate(M(e.lean)), o.translate(0, -i), y({ x: 0, y: i }, { x: 0, y: r });
146
- const S = r + F * l;
147
- for (const [u, n, s] of [
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, n, u, A);
152
- y({ x: 0, y: S }, f, E(f.x, f.y, n + s, u, C));
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
- o.translate(0, r), o.rotate(M(e.headTilt));
155
- const w = -m;
156
- o.beginPath(), o.arc(0, w, m, 0, Math.PI * 2);
157
- const d = t.headFill ?? "#ffffff";
158
- d !== "none" && (o.fillStyle = d, o.fill()), o.stroke(), D(o, e, m, w, h, t.lineWidth ?? l * 0.025), o.restore(), t.label && (o.save(), o.fillStyle = h, o.font = t.labelFont ?? `700 ${Math.round(l * 0.11)}px sans-serif`, o.textAlign = "center", o.textBaseline = "bottom", o.fillText(t.label, 0, -l - 0.04 * l), o.restore());
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 U(o) {
161
- const e = o.style ?? {}, t = e.height ?? 300, l = t * 0.8, h = { ...p(o.pose ?? {}), walk: 0, walking: 0, talk: 0 };
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: o.x - l / 2,
165
- y: o.y - t,
170
+ x: t.x - l / 2,
171
+ y: t.y - o,
166
172
  width: l,
167
- height: t,
173
+ height: o,
168
174
  props: { ...h },
169
- draw(g, m, i) {
170
- const r = m.props, E = { ...r };
171
- let y = r.walking > 0 ? I(E, K(r.walk, E), r.walking) : E;
172
- r.talk > 0 && (y = { ...y, mouth: Math.max(y.mouth, r.talk * O(i)) }), g.translate(l / 2, t), N(g, y, e);
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 $(o, e) {
177
- const t = [];
182
+ function J(t, e) {
183
+ const o = [];
178
184
  return e.forEach((l, h) => {
179
- const g = h === 0 ? k : t[h - 1], m = typeof l.pose == "string" ? X[l.pose] : { ...g, ...l.pose };
180
- t.push(l.expression ? H(m, l.expression) : m);
181
- }), v.filter((l) => t.some((h) => h[l] !== k[l])).map((l) => ({
182
- id: `${o}-${l}`,
183
- target: o,
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, g) => ({
191
+ keyframes: e.map((h, u) => ({
186
192
  time: h.time,
187
- value: t[g][l],
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
- X as POSES,
200
+ A as POSES,
195
201
  k as REST_POSE,
196
- I as blendPose,
197
- N as drawStickFigure,
202
+ O as blendPose,
203
+ D as drawStickFigure,
198
204
  p as pose,
199
- $ as poseTracks,
200
- U as stickFigureTarget,
201
- O as talkingMouth,
202
- K as walkPose,
203
- H as withExpression
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
  };