@zonsh/ui 0.2.0 → 0.4.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.
Files changed (180) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -13
  3. package/dist/components/alert-dialog.js +1 -1
  4. package/dist/components/ascii-field.d.ts +1 -1
  5. package/dist/components/bottom-nav.d.ts +86 -0
  6. package/dist/components/bottom-nav.js +175 -0
  7. package/dist/components/breadcrumb.d.ts +9 -0
  8. package/dist/components/breadcrumb.js +6 -1
  9. package/dist/components/button-group.d.ts +1 -1
  10. package/dist/components/button-group.js +2 -2
  11. package/dist/components/calendar.d.ts +1 -1
  12. package/dist/components/calendar.js +18 -3
  13. package/dist/components/carousel.d.ts +22 -3
  14. package/dist/components/carousel.js +25 -7
  15. package/dist/components/chart.d.ts +9 -0
  16. package/dist/components/chart.js +40 -3
  17. package/dist/components/code-block.d.ts +20 -10
  18. package/dist/components/code-block.js +54 -12
  19. package/dist/components/collapsible.js +2 -2
  20. package/dist/components/color-picker.d.ts +30 -8
  21. package/dist/components/color-picker.js +48 -27
  22. package/dist/components/combobox.d.ts +21 -3
  23. package/dist/components/combobox.js +79 -7
  24. package/dist/components/command.d.ts +23 -3
  25. package/dist/components/command.js +61 -16
  26. package/dist/components/conversation.d.ts +10 -1
  27. package/dist/components/conversation.js +14 -4
  28. package/dist/components/copy-button.d.ts +15 -6
  29. package/dist/components/copy-button.js +20 -5
  30. package/dist/components/data-table.d.ts +66 -6
  31. package/dist/components/data-table.js +376 -23
  32. package/dist/components/date-picker.d.ts +73 -4
  33. package/dist/components/date-picker.js +138 -7
  34. package/dist/components/dialog.d.ts +10 -1
  35. package/dist/components/dialog.js +6 -3
  36. package/dist/components/drawer.d.ts +10 -1
  37. package/dist/components/drawer.js +6 -3
  38. package/dist/components/feature-list.js +2 -2
  39. package/dist/components/field.d.ts +27 -8
  40. package/dist/components/field.js +49 -4
  41. package/dist/components/file-drop.d.ts +26 -4
  42. package/dist/components/file-drop.js +125 -64
  43. package/dist/components/filter-bar.d.ts +50 -3
  44. package/dist/components/filter-bar.js +71 -33
  45. package/dist/components/form.d.ts +4 -2
  46. package/dist/components/form.js +24 -2
  47. package/dist/components/graph.d.ts +41 -0
  48. package/dist/components/graph.js +84 -45
  49. package/dist/components/illustration.js +1 -1
  50. package/dist/components/input-group.d.ts +16 -5
  51. package/dist/components/input-group.js +35 -15
  52. package/dist/components/input.d.ts +2 -2
  53. package/dist/components/input.js +3 -3
  54. package/dist/components/kbd.d.ts +17 -0
  55. package/dist/components/kbd.js +8 -1
  56. package/dist/components/lightbox.d.ts +100 -0
  57. package/dist/components/lightbox.js +439 -0
  58. package/dist/components/locale.d.ts +44 -0
  59. package/dist/components/locale.js +37 -0
  60. package/dist/components/logo.js +1 -1
  61. package/dist/components/menu.js +3 -1
  62. package/dist/components/message.d.ts +3 -3
  63. package/dist/components/message.js +10 -7
  64. package/dist/components/meter.js +3 -1
  65. package/dist/components/money-input.d.ts +80 -0
  66. package/dist/components/money-input.js +253 -0
  67. package/dist/components/number-field.d.ts +21 -2
  68. package/dist/components/number-field.js +27 -16
  69. package/dist/components/otp-field.d.ts +14 -1
  70. package/dist/components/otp-field.js +10 -2
  71. package/dist/components/pagination.d.ts +13 -7
  72. package/dist/components/pagination.js +18 -7
  73. package/dist/components/pdf-viewer.d.ts +67 -2
  74. package/dist/components/pdf-viewer.js +88 -21
  75. package/dist/components/phone-input.d.ts +79 -0
  76. package/dist/components/phone-input.js +282 -0
  77. package/dist/components/popover.js +1 -1
  78. package/dist/components/progress.js +3 -1
  79. package/dist/components/prompt-input.d.ts +34 -9
  80. package/dist/components/prompt-input.js +28 -16
  81. package/dist/components/rating.d.ts +73 -0
  82. package/dist/components/rating.js +124 -0
  83. package/dist/components/reasoning.d.ts +16 -1
  84. package/dist/components/reasoning.js +10 -7
  85. package/dist/components/resizable.d.ts +10 -1
  86. package/dist/components/resizable.js +4 -1
  87. package/dist/components/response.d.ts +14 -3
  88. package/dist/components/response.js +36 -8
  89. package/dist/components/scroll-area.d.ts +1 -1
  90. package/dist/components/select.js +14 -3
  91. package/dist/components/separator.js +1 -1
  92. package/dist/components/sidebar.d.ts +20 -4
  93. package/dist/components/sidebar.js +34 -18
  94. package/dist/components/site-header.d.ts +46 -12
  95. package/dist/components/site-header.js +73 -19
  96. package/dist/components/slider.js +3 -1
  97. package/dist/components/sortable.d.ts +178 -0
  98. package/dist/components/sortable.js +1258 -0
  99. package/dist/components/sources.d.ts +17 -2
  100. package/dist/components/sources.js +11 -4
  101. package/dist/components/spinner.d.ts +13 -1
  102. package/dist/components/spinner.js +5 -2
  103. package/dist/components/stat.d.ts +91 -0
  104. package/dist/components/stat.js +141 -0
  105. package/dist/components/stepper.d.ts +71 -0
  106. package/dist/components/stepper.js +101 -0
  107. package/dist/components/switch.d.ts +2 -2
  108. package/dist/components/switch.js +2 -2
  109. package/dist/components/table.d.ts +12 -2
  110. package/dist/components/table.js +176 -39
  111. package/dist/components/tags-input.d.ts +18 -2
  112. package/dist/components/tags-input.js +65 -33
  113. package/dist/components/theme.d.ts +16 -2
  114. package/dist/components/theme.js +15 -7
  115. package/dist/components/time-field.d.ts +22 -3
  116. package/dist/components/time-field.js +19 -6
  117. package/dist/components/timeline.d.ts +18 -2
  118. package/dist/components/timeline.js +13 -4
  119. package/dist/components/tippy.d.ts +48 -0
  120. package/dist/components/tippy.js +648 -0
  121. package/dist/components/toast.d.ts +18 -2
  122. package/dist/components/toast.js +12 -3
  123. package/dist/components/tool-call.d.ts +19 -8
  124. package/dist/components/tool-call.js +18 -7
  125. package/dist/components/toolbar.js +6 -1
  126. package/dist/components/tour.d.ts +127 -0
  127. package/dist/components/tour.js +648 -0
  128. package/dist/components/tree.js +17 -4
  129. package/dist/components/video-player.d.ts +10 -2
  130. package/dist/components/video-player.js +73 -33
  131. package/dist/illustration.d.ts +2 -0
  132. package/dist/illustration.js +7 -0
  133. package/dist/index.d.ts +11 -3
  134. package/dist/index.js +11 -3
  135. package/dist/lib/code-highlight.d.ts +3 -16
  136. package/dist/lib/code-highlight.js +160 -10
  137. package/dist/lib/code-theme.js +3 -3
  138. package/dist/lib/digit-roll.js +8 -8
  139. package/dist/lib/field-errors.d.ts +28 -0
  140. package/dist/lib/field-errors.js +24 -0
  141. package/dist/lib/field-value.d.ts +13 -0
  142. package/dist/lib/field-value.js +44 -0
  143. package/dist/lib/graph-layout.js +11 -2
  144. package/dist/lib/money.d.ts +73 -0
  145. package/dist/lib/money.js +343 -0
  146. package/dist/lib/phone-countries.d.ts +1 -0
  147. package/dist/lib/phone-countries.js +281 -0
  148. package/dist/lib/phone.d.ts +90 -0
  149. package/dist/lib/phone.js +286 -0
  150. package/dist/lib/platform.d.ts +8 -3
  151. package/dist/lib/platform.js +13 -6
  152. package/dist/lib/row-index.d.ts +15 -0
  153. package/dist/lib/row-index.js +136 -0
  154. package/dist/lib/table-fit.js +23 -4
  155. package/dist/lib/theme-script.d.ts +15 -2
  156. package/dist/lib/theme-script.js +23 -3
  157. package/dist/lib/tippy/pixels.d.ts +47 -0
  158. package/dist/lib/tippy/pixels.js +187 -0
  159. package/dist/lib/tippy/sprite.d.ts +86 -0
  160. package/dist/lib/tippy/sprite.js +753 -0
  161. package/dist/messages/de.d.ts +12 -0
  162. package/dist/messages/de.js +326 -0
  163. package/dist/styles/expressive.css +20 -5
  164. package/dist/styles/index.css +3 -2
  165. package/dist/styles/material.css +7 -3
  166. package/dist/styles/parts/ai.css +2 -1
  167. package/dist/styles/parts/controls.css +62 -13
  168. package/dist/styles/parts/feedback.css +68 -1
  169. package/dist/styles/parts/foundations.css +1 -1
  170. package/dist/styles/parts/navigation.css +194 -2
  171. package/dist/styles/parts/overlays.css +7 -7
  172. package/dist/styles/tokens.css +12 -3
  173. package/dist/vite.d.ts +0 -50
  174. package/dist/vite.js +0 -100
  175. package/package.json +28 -33
  176. package/dist/components/code-highlight.d.ts +0 -13
  177. package/dist/components/code-highlight.js +0 -107
  178. package/dist/components/whiteboard.d.ts +0 -80
  179. package/dist/components/whiteboard.js +0 -389
  180. package/dist/styles/parts/whiteboard.css +0 -855
@@ -0,0 +1,753 @@
1
+ const TAU = Math.PI * 2;
2
+ /** Pixels to a unit. */
3
+ const K = 2;
4
+ /* The body: a circle with a hollow cut from it, set low enough to open between the horns. The
5
+ logo's hollow is 0.78 of the circle; Tippy's is 0.68, for a thicker back. */
6
+ const R = 13;
7
+ const MID = -11;
8
+ const HOLLOW_Y = MID + 0.334 * R;
9
+ const HOLLOW_R = 0.683 * R;
10
+ /** The horns' tips, either side: where it stands, and what it rocks on. */
11
+ const HORN = 6.5;
12
+ const SHOULDER_X = 12.5;
13
+ const SHOULDER_Y = -12;
14
+ const EYE_Y = -21;
15
+ const EYE_GAP = 6;
16
+ /** The mark the right way up: turned over, and leaning its own 14°. */
17
+ const MARK = Math.PI + 0.2443;
18
+ /** Every move Tippy plays here. */
19
+ export const TIPPY_MOVES = [
20
+ "idle",
21
+ "walk",
22
+ "run",
23
+ "jump",
24
+ "sit",
25
+ "wave",
26
+ "nod",
27
+ "shake",
28
+ "shrug",
29
+ "think",
30
+ "look",
31
+ "cheer",
32
+ "giggle",
33
+ "love",
34
+ "surprise",
35
+ "shy",
36
+ "error",
37
+ "success",
38
+ ];
39
+ /** How long one round of each move takes, in seconds (sit holds once it is down). */
40
+ export const MOVE_LENGTH = {
41
+ idle: 6,
42
+ walk: 0.6,
43
+ run: 0.4,
44
+ jump: 1.6,
45
+ sit: 1,
46
+ wave: 2.6,
47
+ nod: 2.2,
48
+ shake: 2.4,
49
+ shrug: 2.6,
50
+ think: 4,
51
+ look: 4.4,
52
+ cheer: 0.7,
53
+ giggle: 2,
54
+ love: 1.5,
55
+ surprise: 2.6,
56
+ shy: 4,
57
+ error: 3.6,
58
+ success: 2.6,
59
+ };
60
+ /** The moment of each move to show when it holds still (reduced motion): the move at its clearest. */
61
+ export const STILL = {
62
+ idle: 0,
63
+ walk: 0.15,
64
+ run: 0.1,
65
+ jump: 0.43,
66
+ sit: 1.2,
67
+ wave: 1.1,
68
+ nod: 0.11,
69
+ shake: 0.05,
70
+ shrug: 0.9,
71
+ think: 1,
72
+ look: 1,
73
+ cheer: 0.3,
74
+ giggle: 0.5,
75
+ love: 0.3,
76
+ surprise: 0.7,
77
+ shy: 1,
78
+ error: 0.8,
79
+ success: 0.9,
80
+ };
81
+ /* Its faces, as pixel pictures at 64: "a" in the darkest ink, "b" a glint in the lightest. The
82
+ eyes are the left eye; those marked `mirror` are flipped for the right. */
83
+ const EYES = {
84
+ open: { rows: [".aa.", "abaa", "aaaa", "aaaa", ".aa."] },
85
+ blink: { rows: ["aaaa"] },
86
+ closed: { rows: ["a..a", ".aa."] },
87
+ happy: { rows: [".aa.", "a..a", "a..a"] },
88
+ squeeze: { rows: ["a...", ".aa.", "...a", ".aa.", "a..."], mirror: true },
89
+ dizzy: { rows: ["a...a", ".a.a.", "..a..", ".a.a.", "a...a"] },
90
+ wide: { rows: [".aaa.", "abbaa", "abaaa", "aaaaa", "aaaaa", ".aaa."] },
91
+ heart: { rows: [".a.a.", "aaaaa", "aaaaa", ".aaa.", "..a.."] },
92
+ };
93
+ const MOUTHS = {
94
+ w: ["a.a.a", ".a.a."],
95
+ o: [".a.", "a.a", ".a."],
96
+ smile: ["a...a", ".aaa."],
97
+ };
98
+ /* ── Timing ─────────────────────────────────────────────────────────── */
99
+ const clamp01 = (x) => Math.max(0, Math.min(1, x));
100
+ const ramp = (t, a, b) => clamp01((t - a) / (b - a));
101
+ const lerp = (a, b, t) => a + (b - a) * t;
102
+ const easeOut = (t) => 1 - (1 - t) ** 3;
103
+ const easeIn = (t) => t ** 3;
104
+ const easeInOut = (t) => (t < 0.5 ? 4 * t ** 3 : 1 - (-2 * t + 2) ** 3 / 2);
105
+ /** Out past the end and back: about 1.1 at its furthest. */
106
+ const back = (t) => 1 + 2.70158 * (t - 1) ** 3 + 1.70158 * (t - 1) ** 2;
107
+ /** A spring let go `s` seconds ago from `by`, ringing down to 0. */
108
+ const spring = (s, by, hz = 2.6, damp = 7) => s < 0 ? 0 : by * Math.exp(-damp * s) * Math.cos(TAU * hz * s);
109
+ /** 0 up to 1 and back to 0 over a..b. */
110
+ const hump = (t, a, b) => t <= a || t >= b ? 0 : Math.sin((Math.PI * (t - a)) / (b - a));
111
+ /** The height of a hop `h` high from a to b. */
112
+ const hop = (t, a, b, h) => t <= a || t >= b ? 0 : 4 * h * ((t - a) / (b - a)) * (1 - (t - a) / (b - a));
113
+ /** A blink for a tenth of a second every `every` seconds. */
114
+ const blinks = (t, every = 3.3) => t % every > every - 0.1;
115
+ const rest = () => ({
116
+ x: 0,
117
+ y: 0,
118
+ dx: 0,
119
+ rot: 0,
120
+ px: 0,
121
+ py: 0,
122
+ cx: 0,
123
+ sx: 1,
124
+ sy: 1,
125
+ lift: 0,
126
+ look: 0,
127
+ eyeDy: 0,
128
+ blink: null,
129
+ eyes: null,
130
+ mouth: null,
131
+ blush: false,
132
+ mark: null,
133
+ markHop: 0,
134
+ armL: { ang: 0.45 },
135
+ armR: { ang: 0.45 },
136
+ behind: null,
137
+ front: null,
138
+ top: 0,
139
+ topX: 0,
140
+ });
141
+ /** A turn about a horn: the right one for a positive (clockwise) turn, the left for a negative. */
142
+ const onHorn = (P, rot) => {
143
+ P.rot = rot;
144
+ P.px = Math.sign(rot) * HORN;
145
+ P.py = 0;
146
+ P.cx = P.px;
147
+ };
148
+ /** A turn about the middle of the body. */
149
+ const onMid = (P, rot) => {
150
+ P.rot = rot;
151
+ P.px = 0;
152
+ P.py = MID;
153
+ P.cx = 0;
154
+ };
155
+ /** Squashed by `k` (negative stretches), keeping its volume. */
156
+ const squash = (P, k) => {
157
+ P.sy *= 1 - k;
158
+ P.sx *= 1 + 0.6 * k;
159
+ };
160
+ const breathe = (P, t, k = 0.02) => squash(P, k * Math.sin((TAU * t) / 2.6));
161
+ /** Where a point of the body is put by its pose. */
162
+ function place(P, x, y) {
163
+ const c = Math.cos(P.rot);
164
+ const s = Math.sin(P.rot);
165
+ const dx = x - P.px;
166
+ const dy = y - P.py;
167
+ const X = P.px + dx * c - dy * s;
168
+ const Y = P.py + dx * s + dy * c;
169
+ return [P.cx + (X - P.cx) * P.sx + P.x, Y * P.sy + P.y];
170
+ }
171
+ /* Its outline, in points round the outer circle; `solid` where the body is a pixel or more thick
172
+ there (so not the hair-thin tips of the horns). */
173
+ const RIM = Array.from({ length: 120 }, (_, i) => {
174
+ const a = (i / 120) * TAU;
175
+ const x = R * Math.cos(a);
176
+ const y = MID + R * Math.sin(a);
177
+ return { x, y, solid: Math.hypot(x, y - HOLLOW_Y) >= HOLLOW_R + 1 };
178
+ });
179
+ /** How low it stands when it stands: its lowest solid point, unturned. */
180
+ const STANDS = Math.max(...RIM.filter((p) => p.solid).map((p) => p.y));
181
+ /** Set the posed body back on the ground where it touches it, and note where its top is. */
182
+ function ground(P) {
183
+ let low = -Infinity;
184
+ let top = Infinity;
185
+ let topX = 0;
186
+ P.x = P.dx;
187
+ P.y = 0;
188
+ for (const p of RIM) {
189
+ const [x, y] = place(P, p.x, p.y);
190
+ if (p.solid && y > low)
191
+ low = y;
192
+ if (y < top) {
193
+ top = y;
194
+ topX = x;
195
+ }
196
+ }
197
+ P.y = Math.round((STANDS - low) * K) / K;
198
+ P.top = top + P.y;
199
+ P.topX = topX;
200
+ }
201
+ /** A puff of dust at (x, y), `k` 0..1 through its life. */
202
+ const puff = (g, x, y, k) => {
203
+ if (k < 1)
204
+ g.circle(x, y - k, 1.1 * (1 - k) + 0.2, 1);
205
+ };
206
+ /** A sign over its head, its foot at (x, y), at time t. */
207
+ function sign(g, mark, x, y, t) {
208
+ const c = g.c;
209
+ if (mark === "!") {
210
+ g.rect(x - 0.6, y - 7, 1.2, 4.2, 2);
211
+ g.rect(x - 0.6, y - 1.6, 1.2, 1.2, 2);
212
+ }
213
+ else if (mark === "?") {
214
+ g.color(2);
215
+ c.lineWidth = 1.1;
216
+ c.lineCap = "round";
217
+ c.beginPath();
218
+ c.arc(x, y - 5.2, 1.7, Math.PI * 1.05, Math.PI * 2.35);
219
+ c.lineTo(x, y - 2.8);
220
+ c.stroke();
221
+ g.rect(x - 0.55, y - 1.5, 1.1, 1.1, 2);
222
+ }
223
+ else if (mark === "check")
224
+ g.path([
225
+ [x - 3, y - 3.2],
226
+ [x - 1, y - 1.2],
227
+ [x + 3.2, y - 6],
228
+ ], 1.2, 2);
229
+ else if (mark === "cross") {
230
+ g.line(x - 2.4, y - 6, x + 2.4, y - 1, 1.2, 2);
231
+ g.line(x + 2.4, y - 6, x - 2.4, y - 1, 1.2, 2);
232
+ }
233
+ else if (mark === "heart") {
234
+ g.circle(x - 1.3, y - 4.3, 1.5, 2);
235
+ g.circle(x + 1.3, y - 4.3, 1.5, 2);
236
+ g.poly([
237
+ [x - 2.75, y - 4],
238
+ [x + 2.75, y - 4],
239
+ [x, y - 0.6],
240
+ ], 2);
241
+ }
242
+ else if (mark === "confetti")
243
+ for (let i = 0; i < 14; i++) {
244
+ const h = (i * 73 + 19) % 97;
245
+ const k = (t * 0.9 + h / 97) % 1;
246
+ const fx = x - 8 + ((h * 7) % 16) + Math.sin(k * 9 + i) * 0.8;
247
+ const fy = y - 13 + k * 13;
248
+ const flip = Math.floor(t * 10 + i) % 2;
249
+ g.rect(fx, fy, flip ? 1 : 0.5, flip ? 0.5 : 1, i % 2 ? 1 : 2);
250
+ }
251
+ }
252
+ /* ── The moves ──────────────────────────────────────────────────────── */
253
+ const MOVES = {
254
+ idle(P, t) {
255
+ const u = t % 6;
256
+ breathe(P, t);
257
+ P.look = u > 1.6 && u < 2.7 ? 1 : u > 3.9 && u < 4.9 ? -1 : 0;
258
+ // Its weight follows its eyes, a moment behind them.
259
+ const lean = 0.035 * (hump(u, 1.7, 2.9) - hump(u, 4.0, 5.1));
260
+ if (lean)
261
+ onHorn(P, lean);
262
+ P.blink = blinks(t + 1.2);
263
+ // Now and then a little bounce, pleased with itself.
264
+ if (u > 5.2) {
265
+ P.lift = hop(u, 5.25, 5.5, 1);
266
+ squash(P, u < 5.25 ? 0.04 : spring(u - 5.5, 0.05));
267
+ P.eyes = "happy";
268
+ P.mouth = "smile";
269
+ P.blink = false;
270
+ }
271
+ },
272
+ walk(P, t) {
273
+ // A waddle, horn to horn; each comes down with a bump.
274
+ const s = Math.sin((TAU * t) / 0.6);
275
+ onHorn(P, 0.13 * s);
276
+ squash(P, 0.05 * Math.max(0, 1 - Math.abs(s) * 4));
277
+ P.look = 1;
278
+ P.armL = { ang: 0.45 + 0.35 * s };
279
+ P.armR = { ang: 0.45 - 0.35 * s };
280
+ P.blink = blinks(t);
281
+ },
282
+ run(P, t) {
283
+ // Bounding: a hop each stride, leaning into it, landing squashed.
284
+ const s = Math.sin((TAU * t) / 0.4);
285
+ const air = Math.abs(s);
286
+ P.lift = 2.5 * air;
287
+ onHorn(P, 0.12 + 0.08 * s);
288
+ squash(P, 0.1 * Math.max(0, 1 - air * 3) - 0.04 * air);
289
+ P.look = 1;
290
+ P.armL = { ang: 0.9 + 0.6 * s };
291
+ P.armR = { ang: 0.9 - 0.6 * s };
292
+ P.mouth = "o";
293
+ const k = (t % 0.2) / 0.2;
294
+ P.behind = (g) => puff(g, -HORN - 2 - 3 * k, -1, k);
295
+ },
296
+ jump(P, t) {
297
+ const u = t % 1.6;
298
+ if (u < 0.2) {
299
+ // Down, gathering itself.
300
+ const q = easeOut(u / 0.2);
301
+ squash(P, 0.15 * q);
302
+ P.armL = P.armR = { ang: 0.45 - 0.35 * q };
303
+ }
304
+ else if (u < 0.66) {
305
+ // Up, stretched out of the crouch, round at the top, stretched again coming down.
306
+ const q = ramp(u, 0.2, 0.66);
307
+ P.lift = hop(u, 0.2, 0.66, 11);
308
+ squash(P, -0.12 * (1 - q) ** 2 - 0.05 * q * q);
309
+ P.armL = P.armR = { ang: 0.45 + 2.1 * Math.sin(Math.PI * q) };
310
+ P.eyeDy = q < 0.5 ? -1 : 0;
311
+ if (q > 0.25 && q < 0.75) {
312
+ P.eyes = "happy";
313
+ P.mouth = "o";
314
+ }
315
+ }
316
+ else {
317
+ // Landing hard, and ringing back up.
318
+ const s = u - 0.66;
319
+ squash(P, spring(s, 0.18, 2.4, 8));
320
+ P.armL = P.armR = { ang: 0.45 + spring(s, 0.8, 2.4, 8) };
321
+ if (s < 0.17)
322
+ P.eyes = "squeeze";
323
+ P.blink = s > 0.5 && s < 0.6;
324
+ if (s < 0.3)
325
+ P.front = (g) => {
326
+ const k = s / 0.3;
327
+ puff(g, -9 - 4 * k, -1, k);
328
+ puff(g, 9 + 4 * k, -1, k);
329
+ };
330
+ }
331
+ },
332
+ sit(P, t) {
333
+ // Down on to its back horn, past where it stops and back, then breathing there.
334
+ const q = ramp(t, 0.1, 0.5);
335
+ if (t < 0.1)
336
+ squash(P, 0.06 * easeOut(t / 0.1));
337
+ onHorn(P, -0.34 * back(q));
338
+ squash(P, spring(t - 0.5, 0.07, 2.2, 7));
339
+ if (t > 0.8)
340
+ breathe(P, t);
341
+ P.armL = P.armR = { ang: lerp(0.45, 0.05, easeOut(q)), len: 5 };
342
+ P.look = t % 7 > 4 && t % 7 < 5.5 ? 1 : 0;
343
+ P.blink = blinks(t);
344
+ },
345
+ wave(P, t) {
346
+ const u = t % 2.6;
347
+ const up = u < 0.3 ? back(u / 0.3) : u < 2.0 ? 1 : 1 - easeInOut(ramp(u, 2.0, 2.35));
348
+ const w = u > 0.3 && u < 2.0 ? Math.sin(TAU * 2.8 * (u - 0.3)) : 0;
349
+ P.armR = { ang: 0.45 + 2.0 * up + 0.45 * w, len: 7 };
350
+ // It leans away from the arm, and bobs with each wave.
351
+ onHorn(P, -0.04 * up);
352
+ squash(P, 0.03 * Math.abs(w) - 0.015 * up);
353
+ if (u > 0.3 && u < 2.0) {
354
+ P.eyes = "happy";
355
+ P.mouth = "smile";
356
+ }
357
+ else
358
+ P.blink = blinks(t);
359
+ },
360
+ nod(P, t) {
361
+ const u = t % 2.2;
362
+ const n = u < 0.9 ? Math.max(0, Math.sin((TAU * u) / 0.45)) : 0;
363
+ P.eyeDy = Math.round(n);
364
+ squash(P, 0.05 * n);
365
+ P.blink = blinks(t);
366
+ },
367
+ shake(P, t) {
368
+ const u = t % 2.4;
369
+ const s = u < 1.2 ? Math.sin(TAU * 2.5 * u) * (1 - u / 1.2) : 0;
370
+ onMid(P, 0.09 * s);
371
+ P.look = Math.abs(s) > 0.2 ? -Math.sign(s) : 0;
372
+ if (u < 1.0)
373
+ P.eyes = "squeeze";
374
+ },
375
+ shrug(P, t) {
376
+ const u = t % 2.6;
377
+ const up = u < 0.15 ? 0 : u < 0.4 ? back(ramp(u, 0.15, 0.4)) : u < 1.3 ? 1 : 1 - easeInOut(ramp(u, 1.3, 1.6));
378
+ squash(P, u < 0.15 ? 0.05 * easeOut(u / 0.15) : -0.04 * up);
379
+ // A sigh as the arms drop.
380
+ squash(P, spring(u - 1.6, 0.06));
381
+ P.armL = P.armR = { ang: 0.45 + 1.5 * up, len: 5 };
382
+ P.look = up > 0.5 ? -1 : 0;
383
+ P.eyeDy = up > 0.5 ? -1 : 0;
384
+ },
385
+ think(P, t, a) {
386
+ const u = t % 4;
387
+ const q = easeInOut(ramp(u, 0, 0.4));
388
+ onHorn(P, -0.07 * q);
389
+ // A hand up to its chin, tapping.
390
+ P.armR = { ang: 0.45 + 2.3 * q + (u > 0.5 ? 0.12 * Math.sin(TAU * 2 * u) : 0), len: 5 };
391
+ P.look = u > 0.3 ? -1 : 0;
392
+ P.eyeDy = u > 0.3 ? -1 : 0;
393
+ a.mark = u > 0.5 ? "?" : null;
394
+ P.markHop = hop(u, 0.5, 0.75, 2);
395
+ P.blink = blinks(t, 2.7);
396
+ },
397
+ look(P, t) {
398
+ const u = t % 4.4;
399
+ P.look = u < 0.2 ? 0 : u < 1.8 ? 1 : u < 2.2 ? 0 : u < 3.8 ? -1 : 0;
400
+ // The body follows the eyes a beat later, and overshoots.
401
+ const lean = 0.06 *
402
+ (back(ramp(u, 0.3, 0.7)) * (1 - ramp(u, 1.8, 2.1)) - back(ramp(u, 2.5, 2.9)) * (1 - ramp(u, 3.8, 4.1)));
403
+ if (lean)
404
+ onHorn(P, lean);
405
+ P.blink = u > 2.0 && u < 2.1;
406
+ },
407
+ cheer(P, t, a) {
408
+ const u = t % 0.7;
409
+ P.lift = hop(u, 0.1, 0.55, 5);
410
+ if (u < 0.1)
411
+ squash(P, 0.1 * easeOut(u / 0.1));
412
+ else if (u < 0.55)
413
+ squash(P, -0.06 * (1 - ramp(u, 0.1, 0.35)));
414
+ else
415
+ squash(P, spring(u - 0.55, 0.12, 3, 10));
416
+ const w = Math.sin(TAU * 3 * t);
417
+ P.armL = { ang: 2.5 + 0.3 * w, len: 6 };
418
+ P.armR = { ang: 2.5 - 0.3 * w, len: 6 };
419
+ P.eyes = "squeeze";
420
+ P.mouth = "w";
421
+ P.blush = true;
422
+ a.mark = "confetti";
423
+ },
424
+ // ── reactions
425
+ giggle(P, t) {
426
+ // Eyes screwed shut, shaking with it in little hops, a step every twelfth of a second.
427
+ const u = t % 2;
428
+ const n = Math.floor(u * 12);
429
+ const on = u < 1.4;
430
+ if (on) {
431
+ P.lift = n % 2;
432
+ onHorn(P, [0.04, -0.04, 0.03, -0.03][n % 4]);
433
+ squash(P, n % 2 ? -0.03 : 0.06);
434
+ }
435
+ else
436
+ squash(P, spring(u - 1.4, 0.06));
437
+ P.eyes = on ? "squeeze" : u < 1.65 ? "happy" : null;
438
+ P.mouth = u < 1.65 ? "w" : null;
439
+ P.blush = u < 1.75;
440
+ P.armL = P.armR = { ang: 1.2, len: 4 };
441
+ },
442
+ love(P, t, a) {
443
+ // Swaying, dreamy, blushing, a heart bobbing over it.
444
+ onHorn(P, 0.07 * Math.sin((TAU * t) / 1.5));
445
+ squash(P, 0.02 * Math.sin((TAU * t) / 0.75));
446
+ P.eyes = Math.sin((TAU * t) / 1.5) > 0.6 ? "heart" : "happy";
447
+ P.mouth = "smile";
448
+ P.blush = true;
449
+ P.armL = P.armR = { ang: 0.2, len: 5 };
450
+ a.mark = "heart";
451
+ P.markHop = 2 * Math.abs(Math.sin((TAU * t) / 1.5));
452
+ },
453
+ surprise(P, t, a) {
454
+ const u = t % 2.6;
455
+ if (u < 0.08)
456
+ squash(P, 0.06);
457
+ else if (u < 0.4) {
458
+ // Up and back with a start, stretched, arms flung up.
459
+ P.lift = hop(u, 0.08, 0.4, 5);
460
+ P.dx = -3 * easeOut(ramp(u, 0.08, 0.4));
461
+ squash(P, -0.1 * (1 - ramp(u, 0.08, 0.3)));
462
+ P.armL = P.armR = { ang: 2.5 };
463
+ }
464
+ else {
465
+ // Down hard, staring; it gets over it, and steps back to where it was.
466
+ P.dx = -3 * (1 - easeInOut(ramp(u, 1.6, 2.2)));
467
+ squash(P, spring(u - 0.4, 0.14));
468
+ P.armL = P.armR = { ang: lerp(2.5, 0.45, easeInOut(ramp(u, 0.9, 1.3))) };
469
+ }
470
+ P.eyes = u > 0.05 && u < 1.4 ? "wide" : null;
471
+ P.mouth = u > 0.05 && u < 1.2 ? "o" : null;
472
+ P.blink = u > 1.5 && u < 1.6;
473
+ a.mark = u > 0.08 && u < 1.2 ? "!" : null;
474
+ },
475
+ shy(P, t) {
476
+ const u = t % 4;
477
+ // It looks down and away, blushing, fidgeting; peeks back at you; and is too embarrassed.
478
+ const peek = u > 1.8 && u < 2.3;
479
+ const caught = u >= 2.3 && u < 2.8;
480
+ P.look = peek ? 0 : -1;
481
+ P.eyeDy = peek ? 0 : 1;
482
+ if (caught)
483
+ P.eyes = "squeeze";
484
+ P.blush = true;
485
+ onHorn(P, -0.05 + 0.03 * Math.sin((TAU * t) / 1.3));
486
+ if (caught)
487
+ squash(P, spring(u - 2.3, 0.07));
488
+ const fidget = 0.12 * Math.sin(TAU * 1.6 * t);
489
+ P.armL = { ang: 0.15 + fidget, len: 5 };
490
+ P.armR = { ang: 0.15 - fidget, len: 5 };
491
+ },
492
+ error(P, t, a) {
493
+ const u = t % 3.6;
494
+ if (u < 0.12) {
495
+ // A jolt.
496
+ a.jitter = [1, -1, 1][Math.floor(u * 24) % 3];
497
+ squash(P, -0.05);
498
+ P.eyes = "wide";
499
+ }
500
+ else if (u < 1.35) {
501
+ // It flips the right way up — the mark, exactly, which for Tippy is wrong — and shakes
502
+ // there, then falls back over.
503
+ const q = u < 0.4 ? easeOut(ramp(u, 0.12, 0.4)) : 1;
504
+ const back2 = u > 1.0 ? easeIn(ramp(u, 1.0, 1.35)) : 0;
505
+ onMid(P, -MARK * q - (TAU - MARK) * back2);
506
+ P.lift = hop(u, 0.12, 0.4, 5);
507
+ if (u >= 0.4 && u < 1.0) {
508
+ squash(P, spring(u - 0.4, 0.1));
509
+ a.jitter = Math.floor(u * 24) % 4 < 2 ? 1 : 0;
510
+ }
511
+ P.armL = P.armR = null;
512
+ P.eyes = "dizzy";
513
+ a.mark = u > 0.4 ? "cross" : null;
514
+ }
515
+ else {
516
+ // Slumped on a horn, eyes shut, arms hanging.
517
+ const s = u - 1.35;
518
+ onHorn(P, -0.12 * easeOut(ramp(s, 0, 0.3)));
519
+ squash(P, spring(s, 0.16, 2.2, 6) + 0.04);
520
+ P.blink = true;
521
+ P.armL = P.armR = { ang: 0.1, len: 6 };
522
+ a.mark = s < 1.2 ? "cross" : null;
523
+ }
524
+ },
525
+ success(P, t, a) {
526
+ const u = t % 2.6;
527
+ if (u < 0.15)
528
+ squash(P, 0.12 * easeOut(u / 0.15));
529
+ else if (u < 0.6)
530
+ squash(P, -0.08 * (1 - ramp(u, 0.15, 0.4)));
531
+ else
532
+ squash(P, spring(u - 0.6, 0.16, 2.6, 7));
533
+ // Then two little happy hops.
534
+ squash(P, spring(u - 1.45, 0.06) + spring(u - 1.75, 0.06));
535
+ P.lift = hop(u, 0.15, 0.6, 8) + hop(u, 1.2, 1.45, 2) + hop(u, 1.5, 1.75, 2);
536
+ const up = easeOut(ramp(u, 0.12, 0.3)) * (1 - easeInOut(ramp(u, 1.9, 2.2)));
537
+ P.armL = P.armR = { ang: 0.45 + 2.1 * up, len: 6 };
538
+ if (up > 0.5) {
539
+ P.eyes = u > 0.6 && u < 0.8 ? "squeeze" : "happy";
540
+ P.mouth = "w";
541
+ P.blush = true;
542
+ }
543
+ a.mark = u > 0.25 && u < 2.1 ? "check" : null;
544
+ },
545
+ };
546
+ /* ── From one move into the next ───────────────────────────────────── */
547
+ /*
548
+ * Moves don't cut into each other. When the move changes, the player says what Tippy was doing
549
+ * (`from`: the move, how far into it, and what that had come out of in turn), and over a third of a
550
+ * second the body goes from where the old move had it to where the new one wants it — its turn,
551
+ * squash, height, hands and gaze — with a dip of its weight as it changes, a blink to change face
552
+ * behind, and a hop if it has far to turn. So any move can follow any other.
553
+ */
554
+ const BLEND = 0.3;
555
+ const FAR_BLEND = 0.45;
556
+ /** A move by itself at t: posed, set on the ground, with its sign. */
557
+ function solo(move, t, a) {
558
+ const P = rest();
559
+ a.mark = null;
560
+ MOVES[move](P, t, a);
561
+ ground(P);
562
+ P.mark = a.mark;
563
+ return P;
564
+ }
565
+ /** Tippy in `move` at t seconds after it began, grown out of `from`. */
566
+ function posed(move, t, from, a) {
567
+ if (!from)
568
+ return solo(move, t, a);
569
+ // What it was doing, carried on as it was.
570
+ const was = (s) => posed(from.move, from.t + s, from.from, { mark: null, jitter: 0 });
571
+ const A0 = was(0);
572
+ const B0 = solo(move, 0, { mark: null, jitter: 0 });
573
+ const far = Math.abs(turnTo(A0.rot, B0.rot) - B0.rot) > 0.8;
574
+ const span = far ? FAR_BLEND : BLEND;
575
+ if (t >= span)
576
+ return solo(move, t, a);
577
+ const B = solo(move, t, a);
578
+ return blend(was(t), B, t, span, far);
579
+ }
580
+ /** `from` turned by whole turns to lie nearest `to`, so a blend goes the short way round. */
581
+ const turnTo = (from, to) => from + TAU * Math.round((to - from) / TAU);
582
+ /** The same body, turned about its middle: the pivot's push moved into dx. */
583
+ function centred(P) {
584
+ const c = Math.cos(P.rot);
585
+ const s = Math.sin(P.rot);
586
+ const oy = P.py - MID;
587
+ const shift = P.px - (P.px * c - oy * s);
588
+ return { rot: P.rot, dx: P.dx + shift * P.sx, cx: P.cx, sx: P.sx, sy: P.sy };
589
+ }
590
+ /** Where a hand is, in units on the stage. */
591
+ function hand(P, side, A) {
592
+ if (A.to)
593
+ return A.to;
594
+ const len = A.len ?? 6;
595
+ return place(P, side * (SHOULDER_X + Math.sin(A.ang) * len), SHOULDER_Y + Math.cos(A.ang) * len);
596
+ }
597
+ function armBetween(A, B, side, w) {
598
+ const a = side < 0 ? A.armL : A.armR;
599
+ const b = side < 0 ? B.armL : B.armR;
600
+ if (!a || !b)
601
+ return w < 0.5 ? a : b;
602
+ if (!a.to && !b.to)
603
+ return { ang: lerp(a.ang, b.ang, w), len: lerp(a.len ?? 6, b.len ?? 6, w) };
604
+ const ha = hand(A, side, a);
605
+ const hb = hand(B, side, b);
606
+ return { to: [lerp(ha[0], hb[0], w), lerp(ha[1], hb[1], w)], behind: (w < 0.5 ? a : b).behind };
607
+ }
608
+ const faceOf = (P) => [P.blink, String(P.eyes), P.mouth, P.blush].join();
609
+ /** From pose A into pose B, v seconds into a blend `span` long. */
610
+ function blend(A, B, v, span, far) {
611
+ const w = easeInOut(clamp01(v / span));
612
+ const a = centred(A);
613
+ const b = centred(B);
614
+ const P = rest();
615
+ P.px = 0;
616
+ P.py = MID;
617
+ P.rot = lerp(turnTo(a.rot, b.rot), b.rot, w);
618
+ P.dx = lerp(a.dx, b.dx, w);
619
+ P.cx = lerp(a.cx, b.cx, w);
620
+ P.sx = lerp(a.sx, b.sx, w);
621
+ P.sy = lerp(a.sy, b.sy, w);
622
+ P.lift = lerp(A.lift, B.lift, w);
623
+ P.look = lerp(A.look, B.look, w);
624
+ P.eyeDy = lerp(A.eyeDy, B.eyeDy, w);
625
+ // Its weight dips as it changes over, and if it has far to turn it hops round.
626
+ squash(P, 0.05 * hump(v, 0, 0.22));
627
+ if (far)
628
+ P.lift += hop(v, 0, span, 3);
629
+ // The face changes behind a blink.
630
+ const F = w < 0.5 ? A : B;
631
+ P.eyes = F.eyes;
632
+ P.blink = F.blink;
633
+ P.mouth = F.mouth;
634
+ P.blush = F.blush;
635
+ if (faceOf(A) !== faceOf(B) && v > span * 0.3 && v < span * 0.3 + 0.09)
636
+ P.blink = true;
637
+ P.mark = w > 0.6 ? B.mark : null;
638
+ P.markHop = B.markHop;
639
+ P.armL = armBetween(A, B, -1, w);
640
+ P.armR = armBetween(A, B, 1, w);
641
+ ground(P);
642
+ P.behind = B.behind;
643
+ P.front = B.front;
644
+ return P;
645
+ }
646
+ /** Frames a second Tippy is posed at: time is held to whole frames. */
647
+ export const FPS = 24;
648
+ /**
649
+ * Tippy in `move`, `t` seconds after it began (held to whole frames at 24 a second), grown out of
650
+ * `from`, facing `dir`.
651
+ */
652
+ export function poseTippy(move, t, from, dir = 1) {
653
+ const at = Math.floor(Math.max(0, t) * FPS) / FPS;
654
+ const a = { mark: null, jitter: 0 };
655
+ const body = posed(move, at, from, a);
656
+ return { body, lift: Math.round(body.lift * K), jitter: a.jitter * K, dir, t: at };
657
+ }
658
+ /** Draw a posed Tippy with the pen, its origin on the ground under its middle. */
659
+ function draw(g, pose) {
660
+ const P = pose.body;
661
+ const c = g.c;
662
+ const mitten = (x, y) => g.circle(x, y, 0.8, 2);
663
+ // An arm put somewhere: from where its shoulder is now to the hand.
664
+ const reach = (side, A, behind) => {
665
+ if (!A?.to || Boolean(A.behind) !== behind)
666
+ return;
667
+ const [x, y] = place(P, side * SHOULDER_X, SHOULDER_Y);
668
+ g.line(x, y, A.to[0], A.to[1], 1, 2);
669
+ mitten(A.to[0], A.to[1]);
670
+ };
671
+ // Behind it, then the body and the arms that turn with it: in units.
672
+ c.save();
673
+ c.scale(K, K);
674
+ P.behind?.(g);
675
+ reach(-1, P.armL, true);
676
+ reach(1, P.armR, true);
677
+ c.save();
678
+ c.translate(P.x, P.y);
679
+ c.translate(P.cx, 0);
680
+ c.scale(P.sx, P.sy);
681
+ c.translate(-P.cx, 0);
682
+ if (P.rot) {
683
+ c.translate(P.px, P.py);
684
+ c.rotate(P.rot);
685
+ c.translate(-P.px, -P.py);
686
+ }
687
+ // The body: the circle with its hollow cut out, as it falls inside the outer circle.
688
+ c.save();
689
+ c.beginPath();
690
+ c.arc(0, MID, R, 0, TAU);
691
+ c.clip();
692
+ c.beginPath();
693
+ c.rect(-R - 2, MID - R - 2, 2 * R + 4, 2 * R + 4);
694
+ c.moveTo(HOLLOW_R, HOLLOW_Y);
695
+ c.arc(0, HOLLOW_Y, HOLLOW_R, 0, TAU);
696
+ g.color(2);
697
+ c.fill("evenodd");
698
+ c.restore();
699
+ for (const [side, A] of [
700
+ [-1, P.armL],
701
+ [1, P.armR],
702
+ ]) {
703
+ if (!A || A.to)
704
+ continue;
705
+ const len = A.len ?? 6;
706
+ const ex = side * (SHOULDER_X + Math.sin(A.ang) * len);
707
+ const ey = SHOULDER_Y + Math.cos(A.ang) * len;
708
+ g.line(side * SHOULDER_X, SHOULDER_Y, ex, ey, 1, 2);
709
+ mitten(ex, ey);
710
+ }
711
+ c.restore();
712
+ c.restore();
713
+ // The face, in pixels: each part put where the pose takes it but kept square, however far over
714
+ // it is, so it stays crisp.
715
+ const eyeY = EYE_Y + Math.max(-1, Math.min(1, Math.round(P.eyeDy)));
716
+ const picture = (rows, x, y, flip = false) => g.bitmap(Math.round(x * K - rows[0].length / 2), Math.round(y * K - rows.length / 2), rows, 0, 2, flip);
717
+ for (const side of [-1, 1]) {
718
+ const [x, y] = place(P, side * (EYE_GAP / 2) + P.look, eyeY + 1);
719
+ const kind = P.blink ? "blink" : ((Array.isArray(P.eyes) ? P.eyes[side < 0 ? 0 : 1] : P.eyes) ?? "open");
720
+ const eye = EYES[kind] ?? EYES.open;
721
+ picture(eye.rows, x, y, Boolean(eye.mirror) && side > 0);
722
+ if (P.blush)
723
+ g.rect(Math.round((x + side * 3) * K) - 2, Math.round((y + 2) * K), 4, 2, 1);
724
+ }
725
+ if (P.mouth) {
726
+ const [x, y] = place(P, P.look * 0.5, eyeY + 3.5);
727
+ picture(MOUTHS[P.mouth], x, y);
728
+ }
729
+ // In front of it: hands put somewhere, dust, and a sign over its head. In units.
730
+ c.save();
731
+ c.scale(K, K);
732
+ reach(-1, P.armL, false);
733
+ reach(1, P.armR, false);
734
+ P.front?.(g);
735
+ if (P.mark) {
736
+ // Facing left, the whole picture is mirrored as it is put on the page: a sign is flipped back
737
+ // about its own middle, so a check or a ? still reads the right way round.
738
+ if (pose.dir < 0) {
739
+ c.translate(2 * P.topX, 0);
740
+ c.scale(-1, 1);
741
+ }
742
+ sign(g, P.mark, P.topX, P.top - 2 - P.markHop, pose.t);
743
+ }
744
+ c.restore();
745
+ }
746
+ /** Tippy for the pixel engine: its inks, darkest first, 64 pixels with room over it for a jump and its sign. */
747
+ export const TIPPY = {
748
+ palette: ["#0b0b0c", "#b4b4b8", "#f6f6f4"],
749
+ outline: "#0b0b0c",
750
+ size: 64,
751
+ headroom: 40,
752
+ draw,
753
+ };