@guideai/react-native 0.1.0 → 0.3.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/dist/ui.mjs CHANGED
@@ -1,7 +1,9 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
- import React, { useRef, useState, useEffect, useCallback, useMemo, useContext, createContext } from "react";
3
- import { View, StyleSheet, Text, ScrollView, Linking, KeyboardAvoidingView, Pressable, Alert, FlatList, ActivityIndicator, TextInput, Platform, StatusBar, Animated, Easing, Dimensions, PanResponder, Modal } from "react-native";
4
- import { r as requireConfigured, b as useGuideAI, c as useOnboarding, E as EP } from "./useOnboarding-DhVtf0U2.js";
2
+ import React, { useReducer, useState, useRef, useMemo, useEffect, useCallback, useContext, createContext } from "react";
3
+ import { View, StyleSheet, Text, ScrollView, Linking, AccessibilityInfo, Modal, ActivityIndicator, Pressable, Platform, KeyboardAvoidingView, Alert, FlatList, TextInput, StatusBar, Animated, Easing, Dimensions, PanResponder } from "react-native";
4
+ import { r as requireConfigured, E as EP } from "./setup-CkXajERE.js";
5
+ import { B as BOARD_W, b as useWhiteboard, c as BOARD_H, u as useGuideAI, a as useOnboarding } from "./useOnboarding-BAKQq8T_.js";
6
+ import Svg, { G, Path } from "react-native-svg";
5
7
  function parseInline(text) {
6
8
  const spans = [];
7
9
  const pattern = /(`[^`]+`)|(\*\*[^*]+\*\*)|(__[^_]+__)|(\*[^*\n]+\*)|(_[^_\n]+_)|(\[[^\]]+\]\([^)]+\))/g;
@@ -140,9 +142,9 @@ function Spans({ spans, style, accentColor }) {
140
142
  {
141
143
  style: [
142
144
  style,
143
- span.bold ? styles$3.bold : null,
144
- span.italic ? styles$3.italic : null,
145
- span.code ? styles$3.inlineCode : null
145
+ span.bold ? styles$4.bold : null,
146
+ span.italic ? styles$4.italic : null,
147
+ span.code ? styles$4.inlineCode : null
146
148
  ],
147
149
  children: span.text
148
150
  },
@@ -158,7 +160,7 @@ function Markdown({
158
160
  }) {
159
161
  const blocks = React.useMemo(() => parseMarkdown(children), [children]);
160
162
  const body = { color, fontSize, lineHeight: fontSize * 1.45 };
161
- return /* @__PURE__ */ jsx(View, { style: styles$3.container, children: blocks.map((block, index) => /* @__PURE__ */ jsx(
163
+ return /* @__PURE__ */ jsx(View, { style: styles$4.container, children: blocks.map((block, index) => /* @__PURE__ */ jsx(
162
164
  Block,
163
165
  {
164
166
  block,
@@ -174,7 +176,7 @@ function Block({ block, body, color, accentColor, fontSize }) {
174
176
  switch (block.type) {
175
177
  case "heading": {
176
178
  const sizes = { 1: fontSize + 6, 2: fontSize + 3, 3: fontSize + 1 };
177
- return /* @__PURE__ */ jsx(Text, { style: [styles$3.heading, { color, fontSize: sizes[block.level] }], children: /* @__PURE__ */ jsx(
179
+ return /* @__PURE__ */ jsx(Text, { style: [styles$4.heading, { color, fontSize: sizes[block.level] }], children: /* @__PURE__ */ jsx(
178
180
  Spans,
179
181
  {
180
182
  spans: block.spans,
@@ -184,24 +186,24 @@ function Block({ block, body, color, accentColor, fontSize }) {
184
186
  ) });
185
187
  }
186
188
  case "paragraph":
187
- return /* @__PURE__ */ jsx(Text, { style: styles$3.paragraph, children: /* @__PURE__ */ jsx(Spans, { spans: block.spans, style: body, accentColor }) });
189
+ return /* @__PURE__ */ jsx(Text, { style: styles$4.paragraph, children: /* @__PURE__ */ jsx(Spans, { spans: block.spans, style: body, accentColor }) });
188
190
  case "bullet":
189
- return /* @__PURE__ */ jsxs(View, { style: [styles$3.listRow, { marginLeft: block.depth * 14 }], children: [
191
+ return /* @__PURE__ */ jsxs(View, { style: [styles$4.listRow, { marginLeft: block.depth * 14 }], children: [
190
192
  /* @__PURE__ */ jsx(Text, { style: [body, { color: accentColor }], children: "•" }),
191
- /* @__PURE__ */ jsx(Text, { style: styles$3.listText, children: /* @__PURE__ */ jsx(Spans, { spans: block.spans, style: body, accentColor }) })
193
+ /* @__PURE__ */ jsx(Text, { style: styles$4.listText, children: /* @__PURE__ */ jsx(Spans, { spans: block.spans, style: body, accentColor }) })
192
194
  ] });
193
195
  case "ordered":
194
- return /* @__PURE__ */ jsxs(View, { style: [styles$3.listRow, { marginLeft: block.depth * 14 }], children: [
196
+ return /* @__PURE__ */ jsxs(View, { style: [styles$4.listRow, { marginLeft: block.depth * 14 }], children: [
195
197
  /* @__PURE__ */ jsxs(Text, { style: [body, { color: accentColor, fontVariant: ["tabular-nums"] }], children: [
196
198
  block.index,
197
199
  "."
198
200
  ] }),
199
- /* @__PURE__ */ jsx(Text, { style: styles$3.listText, children: /* @__PURE__ */ jsx(Spans, { spans: block.spans, style: body, accentColor }) })
201
+ /* @__PURE__ */ jsx(Text, { style: styles$4.listText, children: /* @__PURE__ */ jsx(Spans, { spans: block.spans, style: body, accentColor }) })
200
202
  ] });
201
203
  case "code":
202
- return /* @__PURE__ */ jsx(View, { style: styles$3.codeBlock, children: /* @__PURE__ */ jsx(Text, { style: [styles$3.codeText, { fontSize: fontSize - 2 }], children: block.text }) });
204
+ return /* @__PURE__ */ jsx(View, { style: styles$4.codeBlock, children: /* @__PURE__ */ jsx(Text, { style: [styles$4.codeText, { fontSize: fontSize - 2 }], children: block.text }) });
203
205
  case "quote":
204
- return /* @__PURE__ */ jsx(View, { style: [styles$3.quote, { borderLeftColor: accentColor }], children: /* @__PURE__ */ jsx(Text, { children: /* @__PURE__ */ jsx(
206
+ return /* @__PURE__ */ jsx(View, { style: [styles$4.quote, { borderLeftColor: accentColor }], children: /* @__PURE__ */ jsx(Text, { children: /* @__PURE__ */ jsx(
205
207
  Spans,
206
208
  {
207
209
  spans: block.spans,
@@ -210,12 +212,12 @@ function Block({ block, body, color, accentColor, fontSize }) {
210
212
  }
211
213
  ) }) });
212
214
  case "rule":
213
- return /* @__PURE__ */ jsx(View, { style: styles$3.rule });
215
+ return /* @__PURE__ */ jsx(View, { style: styles$4.rule });
214
216
  case "table": {
215
217
  const columns = Math.max(block.header.length, ...block.rows.map((r) => r.length), 1);
216
218
  const scrolls = columns > 3;
217
- const table = /* @__PURE__ */ jsxs(View, { style: [styles$3.table, scrolls ? { minWidth: columns * 116 } : null], children: [
218
- /* @__PURE__ */ jsx(View, { style: [styles$3.tableRow, styles$3.tableHeaderRow], children: block.header.map((cell, index) => /* @__PURE__ */ jsx(View, { style: styles$3.tableCell, children: /* @__PURE__ */ jsx(Text, { children: /* @__PURE__ */ jsx(
219
+ const table = /* @__PURE__ */ jsxs(View, { style: [styles$4.table, scrolls ? { minWidth: columns * 116 } : null], children: [
220
+ /* @__PURE__ */ jsx(View, { style: [styles$4.tableRow, styles$4.tableHeaderRow], children: block.header.map((cell, index) => /* @__PURE__ */ jsx(View, { style: styles$4.tableCell, children: /* @__PURE__ */ jsx(Text, { children: /* @__PURE__ */ jsx(
219
221
  Spans,
220
222
  {
221
223
  spans: cell,
@@ -223,7 +225,7 @@ function Block({ block, body, color, accentColor, fontSize }) {
223
225
  style: { ...body, fontWeight: "700", fontSize: fontSize - 1 }
224
226
  }
225
227
  ) }) }, index)) }),
226
- block.rows.map((row, rowIndex) => /* @__PURE__ */ jsx(View, { style: styles$3.tableRow, children: row.map((cell, cellIndex) => /* @__PURE__ */ jsx(View, { style: styles$3.tableCell, children: /* @__PURE__ */ jsx(Text, { children: /* @__PURE__ */ jsx(
228
+ block.rows.map((row, rowIndex) => /* @__PURE__ */ jsx(View, { style: styles$4.tableRow, children: row.map((cell, cellIndex) => /* @__PURE__ */ jsx(View, { style: styles$4.tableCell, children: /* @__PURE__ */ jsx(Text, { children: /* @__PURE__ */ jsx(
227
229
  Spans,
228
230
  {
229
231
  spans: cell,
@@ -247,7 +249,7 @@ function Block({ block, body, color, accentColor, fontSize }) {
247
249
  }
248
250
  }
249
251
  const mono = { fontFamily: "Menlo" };
250
- const styles$3 = StyleSheet.create({
252
+ const styles$4 = StyleSheet.create({
251
253
  container: { gap: 6 },
252
254
  heading: { fontWeight: "700", marginTop: 4 },
253
255
  paragraph: {},
@@ -283,6 +285,1011 @@ const styles$3 = StyleSheet.create({
283
285
  tableHeaderRow: { backgroundColor: "rgba(100,116,139,0.10)" },
284
286
  tableCell: { flex: 1, padding: 8 }
285
287
  });
288
+ const STEP_GAP_MS = 450;
289
+ function readTime(text) {
290
+ const words = text.trim().split(/\s+/).filter(Boolean).length;
291
+ return Math.min(6500, Math.max(1500, words * 280));
292
+ }
293
+ const SPEEDS = [0.75, 1, 1.5, 2];
294
+ class Player {
295
+ constructor(steps, hooks, reducedMotion = false) {
296
+ var _a, _b, _c;
297
+ this.steps = steps;
298
+ this.hooks = hooks;
299
+ this.reducedMotion = reducedMotion;
300
+ this.state = "idle";
301
+ this.speed = 1;
302
+ this.stepIndex = -1;
303
+ this.opIndex = 0;
304
+ this.opElapsed = 0;
305
+ this.stepElapsed = 0;
306
+ this.holdElapsed = 0;
307
+ this.spoken = null;
308
+ this.narrationToken = 0;
309
+ this.frame = null;
310
+ this.last = 0;
311
+ this.requestFrame = (_a = hooks.requestFrame) != null ? _a : ((cb) => requestAnimationFrame(cb));
312
+ this.cancelFrame = (_b = hooks.cancelFrame) != null ? _b : ((id) => cancelAnimationFrame(id));
313
+ this.now = (_c = hooks.now) != null ? _c : (() => performance.now());
314
+ }
315
+ get current() {
316
+ return this.stepIndex;
317
+ }
318
+ get status() {
319
+ return this.state;
320
+ }
321
+ get rate() {
322
+ return this.speed;
323
+ }
324
+ setSpeed(speed) {
325
+ this.speed = Math.min(3, Math.max(0.25, speed));
326
+ }
327
+ play() {
328
+ if (this.state === "playing") return;
329
+ if (this.state === "done" || this.state === "idle") {
330
+ this.restart();
331
+ return;
332
+ }
333
+ this.setState("playing");
334
+ this.schedule();
335
+ }
336
+ pause() {
337
+ if (this.state !== "playing") return;
338
+ this.setState("paused");
339
+ this.unschedule();
340
+ if (this.spoken === null) {
341
+ this.narrationToken += 1;
342
+ this.hooks.stopNarration();
343
+ this.spoken = false;
344
+ }
345
+ }
346
+ replay() {
347
+ this.restart();
348
+ }
349
+ /**
350
+ * Jump to step *index*, as a scrubber does: the board is rebuilt with every
351
+ * step before it already drawn, then playback carries on from there.
352
+ */
353
+ seek(index) {
354
+ const target = Math.max(0, Math.min(this.steps.length - 1, Math.floor(index)));
355
+ this.unschedule();
356
+ this.narrationToken += 1;
357
+ this.hooks.stopNarration();
358
+ this.hooks.reset();
359
+ for (let i = 0; i < target; i += 1) {
360
+ const step = this.steps[i];
361
+ step.enter();
362
+ for (const op of step.ops) op.run(1);
363
+ }
364
+ this.stepIndex = -1;
365
+ this.setState("playing");
366
+ this.enterStep(target);
367
+ this.schedule();
368
+ }
369
+ /** Stop for good: no frames, no voice. */
370
+ destroy() {
371
+ this.unschedule();
372
+ this.narrationToken += 1;
373
+ this.hooks.stopNarration();
374
+ this.state = "done";
375
+ }
376
+ restart() {
377
+ this.unschedule();
378
+ this.narrationToken += 1;
379
+ this.hooks.stopNarration();
380
+ this.hooks.reset();
381
+ this.stepIndex = -1;
382
+ this.setState("playing");
383
+ this.enterStep(0);
384
+ this.schedule();
385
+ }
386
+ setState(state) {
387
+ var _a, _b;
388
+ if (this.state === state) return;
389
+ this.state = state;
390
+ (_b = (_a = this.hooks).onState) == null ? void 0 : _b.call(_a, state);
391
+ }
392
+ enterStep(index) {
393
+ var _a, _b;
394
+ const step = this.steps[index];
395
+ if (!step) {
396
+ this.unschedule();
397
+ this.setState("done");
398
+ return;
399
+ }
400
+ this.stepIndex = index;
401
+ this.opIndex = 0;
402
+ this.opElapsed = 0;
403
+ this.stepElapsed = 0;
404
+ this.holdElapsed = 0;
405
+ this.spoken = null;
406
+ step.enter();
407
+ (_b = (_a = this.hooks).onStep) == null ? void 0 : _b.call(_a, index, step);
408
+ const token = ++this.narrationToken;
409
+ this.hooks.narrate(step.say).then(
410
+ (said) => {
411
+ if (token === this.narrationToken) this.spoken = said;
412
+ },
413
+ () => {
414
+ if (token === this.narrationToken) this.spoken = false;
415
+ }
416
+ );
417
+ if (this.reducedMotion) {
418
+ for (const op of step.ops) op.run(1);
419
+ this.opIndex = step.ops.length;
420
+ }
421
+ }
422
+ schedule() {
423
+ if (this.frame !== null || this.state !== "playing") return;
424
+ this.last = this.now();
425
+ this.frame = this.requestFrame((t) => this.tick(t));
426
+ }
427
+ unschedule() {
428
+ if (this.frame !== null) this.cancelFrame(this.frame);
429
+ this.frame = null;
430
+ }
431
+ /** One frame. Public so tests can drive time by hand. */
432
+ tick(now) {
433
+ this.frame = null;
434
+ if (this.state !== "playing") return;
435
+ const dt = Math.max(0, Math.min(100, now - this.last)) * this.speed;
436
+ this.last = now;
437
+ this.advance(dt);
438
+ if (this.state === "playing") this.frame = this.requestFrame((t) => this.tick(t));
439
+ }
440
+ advance(dt) {
441
+ const step = this.steps[this.stepIndex];
442
+ if (!step) return;
443
+ this.stepElapsed += dt;
444
+ let left = dt;
445
+ while (this.opIndex < step.ops.length && left > 0) {
446
+ const op = step.ops[this.opIndex];
447
+ const remaining = op.duration - this.opElapsed;
448
+ if (op.duration <= 0 || left >= remaining) {
449
+ op.run(1);
450
+ left -= Math.max(0, remaining);
451
+ this.opIndex += 1;
452
+ this.opElapsed = 0;
453
+ } else {
454
+ this.opElapsed += left;
455
+ op.run(this.opElapsed / op.duration);
456
+ left = 0;
457
+ }
458
+ }
459
+ while (this.opIndex < step.ops.length && step.ops[this.opIndex].duration <= 0) {
460
+ step.ops[this.opIndex].run(1);
461
+ this.opIndex += 1;
462
+ }
463
+ if (this.opIndex < step.ops.length || this.spoken === null) return;
464
+ const hold = this.spoken ? 0 : readTime(step.say);
465
+ if (this.stepElapsed < hold) return;
466
+ this.holdElapsed += dt;
467
+ if (this.holdElapsed < STEP_GAP_MS) return;
468
+ this.enterStep(this.stepIndex + 1);
469
+ }
470
+ }
471
+ const STORYBOARD_ICON_STROKES = {
472
+ phone: [
473
+ "M 32 6 Q 24 6 24 14 L 24 86 Q 24 94 32 94 L 68 94 Q 76 94 76 86 L 76 14 Q 76 6 68 6 Z",
474
+ "M 43 13 L 57 13",
475
+ "M 41 88 L 59 88"
476
+ ],
477
+ screen: [
478
+ "M 8 18 L 92 18 L 92 66 L 8 66 Z",
479
+ "M 42 66 L 38 84 L 62 84 L 58 66",
480
+ "M 30 84 L 70 84"
481
+ ],
482
+ window: [
483
+ "M 6 16 L 94 16 L 94 84 L 6 84 Z",
484
+ "M 6 32 L 94 32",
485
+ "M 11 24 a 3 3 0 1 0 6 0 a 3 3 0 1 0 -6 0 M 23 24 a 3 3 0 1 0 6 0 a 3 3 0 1 0 -6 0 M 35 24 a 3 3 0 1 0 6 0 a 3 3 0 1 0 -6 0"
486
+ ],
487
+ video: [
488
+ "M 8 20 L 92 20 L 92 80 L 8 80 Z",
489
+ "M 20 20 L 20 80 M 80 20 L 80 80",
490
+ "M 42 40 L 64 50 L 42 60 Z"
491
+ ],
492
+ play: [
493
+ "M 8 50 a 42 42 0 1 0 84 0 a 42 42 0 1 0 -84 0",
494
+ "M 40 32 L 70 50 L 40 68 Z"
495
+ ],
496
+ input: [
497
+ "M 6 36 L 94 36 L 94 64 L 6 64 Z",
498
+ "M 18 43 L 18 57",
499
+ "M 28 50 L 66 50"
500
+ ],
501
+ cursor: [
502
+ "M 24 12 L 24 74 L 39 60 L 49 82 L 60 77 L 50 56 L 70 55 Z"
503
+ ],
504
+ document: [
505
+ "M 24 8 L 62 8 L 78 26 L 78 92 L 24 92 Z",
506
+ "M 62 8 L 62 26 L 78 26",
507
+ "M 36 44 L 66 44 M 36 58 L 66 58 M 36 72 L 54 72"
508
+ ],
509
+ image: [
510
+ "M 10 20 L 90 20 L 90 80 L 10 80 Z",
511
+ "M 10 68 L 36 44 L 56 64 L 68 54 L 90 74",
512
+ "M 61 34 a 7 7 0 1 0 14 0 a 7 7 0 1 0 -14 0"
513
+ ],
514
+ gear: [
515
+ "M 50.0 17.0 L 58.8 5.9 L 67.2 8.4 L 68.3 22.6 L 73.3 26.7 L 87.4 25.0 L 91.6 32.8 L 82.4 43.6 L 83.0 50.0 L 94.1 58.8 L 91.6 67.2 L 77.4 68.3 L 73.3 73.3 L 75.0 87.4 L 67.2 91.6 L 56.4 82.4 L 50.0 83.0 L 41.2 94.1 L 32.8 91.6 L 31.7 77.4 L 26.7 73.3 L 12.6 75.0 L 8.4 67.2 L 17.6 56.4 L 17.0 50.0 L 5.9 41.2 L 8.4 32.8 L 22.6 31.7 L 26.7 26.7 L 25.0 12.6 L 32.8 8.4 L 43.6 17.6 Z",
516
+ "M 39 50 a 11 11 0 1 0 22 0 a 11 11 0 1 0 -22 0"
517
+ ],
518
+ cloud: [
519
+ "M 28 74 Q 8 74 8 58 Q 8 44 24 42 Q 28 22 48 22 Q 68 22 72 42 Q 92 44 92 58 Q 92 74 74 74 Z"
520
+ ],
521
+ database: [
522
+ "M 18 24 a 32 10 0 1 0 64 0 a 32 10 0 1 0 -64 0",
523
+ "M 18 24 L 18 76 Q 18 88 50 88 Q 82 88 82 76 L 82 24",
524
+ "M 18 50 Q 18 62 50 62 Q 82 62 82 50"
525
+ ],
526
+ user: [
527
+ "M 33 31 a 17 17 0 1 0 34 0 a 17 17 0 1 0 -34 0",
528
+ "M 16 88 Q 16 56 50 56 Q 84 56 84 88"
529
+ ],
530
+ sparkle: [
531
+ "M 50 6 Q 56 40 90 50 Q 56 60 50 94 Q 44 60 10 50 Q 44 40 50 6 Z"
532
+ ],
533
+ check: [
534
+ "M 16 54 L 40 78 L 86 22"
535
+ ],
536
+ clock: [
537
+ "M 8 50 a 42 42 0 1 0 84 0 a 42 42 0 1 0 -84 0",
538
+ "M 50 26 L 50 52 L 70 62"
539
+ ],
540
+ lock: [
541
+ "M 22 46 L 78 46 L 78 90 L 22 90 Z",
542
+ "M 34 46 L 34 30 Q 34 12 50 12 Q 66 12 66 30 L 66 46",
543
+ "M 50 62 L 50 74"
544
+ ],
545
+ chat: [
546
+ "M 10 20 L 90 20 L 90 68 L 46 68 L 26 86 L 28 68 L 10 68 Z",
547
+ "M 28 38 L 72 38 M 28 52 L 60 52"
548
+ ],
549
+ cross: [
550
+ "M 22 22 L 78 78",
551
+ "M 78 22 L 22 78"
552
+ ],
553
+ server: [
554
+ "M 16 10 L 84 10 L 84 34 L 16 34 Z",
555
+ "M 16 38 L 84 38 L 84 62 L 16 62 Z",
556
+ "M 16 66 L 84 66 L 84 90 L 16 90 Z",
557
+ "M 26 22 L 32 22 M 26 50 L 32 50 M 26 78 L 32 78",
558
+ "M 54 22 L 74 22 M 54 50 L 74 50 M 54 78 L 74 78"
559
+ ],
560
+ queue: [
561
+ "M 6 32 L 94 32 M 6 68 L 94 68",
562
+ "M 14 40 L 30 40 L 30 60 L 14 60 Z",
563
+ "M 38 40 L 54 40 L 54 60 L 38 60 Z",
564
+ "M 62 40 L 78 40 L 78 60 L 62 60 Z",
565
+ "M 82 50 L 94 50 M 88 44 L 94 50 L 88 56"
566
+ ],
567
+ globe: [
568
+ "M 8 50 a 42 42 0 1 0 84 0 a 42 42 0 1 0 -84 0",
569
+ "M 50 8 Q 22 50 50 92 Q 78 50 50 8",
570
+ "M 8 50 L 92 50",
571
+ "M 16 28 L 84 28 M 16 72 L 84 72"
572
+ ],
573
+ balancer: [
574
+ "M 36 8 L 64 8 L 64 30 L 36 30 Z",
575
+ "M 50 30 L 50 46 M 18 46 L 82 46 M 18 46 L 18 62 M 50 46 L 50 62 M 82 46 L 82 62",
576
+ "M 8 62 L 28 62 L 28 86 L 8 86 Z",
577
+ "M 40 62 L 60 62 L 60 86 L 40 86 Z",
578
+ "M 72 62 L 92 62 L 92 86 L 72 86 Z"
579
+ ],
580
+ cache: [
581
+ "M 58 6 L 24 54 L 48 54 L 40 94 L 78 40 L 54 40 Z"
582
+ ],
583
+ container: [
584
+ "M 50 8 L 88 28 L 88 72 L 50 92 L 12 72 L 12 28 Z",
585
+ "M 12 28 L 50 48 L 88 28",
586
+ "M 50 48 L 50 92"
587
+ ]
588
+ };
589
+ function storyboardIconStrokes(icon) {
590
+ var _a;
591
+ return (_a = STORYBOARD_ICON_STROKES[icon]) != null ? _a : [];
592
+ }
593
+ const SHEET_W$1 = 1600;
594
+ const SHEET_H$1 = 1e3;
595
+ const sx = (x) => x * (SHEET_W$1 / 160);
596
+ const sy = (y) => y * (SHEET_H$1 / 100);
597
+ function seeded(seed) {
598
+ let s = seed >>> 0 || 1;
599
+ return () => {
600
+ s ^= s << 13;
601
+ s ^= s >>> 17;
602
+ s ^= s << 5;
603
+ return (s >>> 0) % 1e4 / 1e4;
604
+ };
605
+ }
606
+ function strokeLength(stroke) {
607
+ let length = 0;
608
+ for (let i = 1; i < stroke.length; i += 1) {
609
+ length += Math.hypot(stroke[i].x - stroke[i - 1].x, stroke[i].y - stroke[i - 1].y);
610
+ }
611
+ return length;
612
+ }
613
+ function totalLength(strokes) {
614
+ return strokes.reduce((sum, s) => sum + strokeLength(s), 0);
615
+ }
616
+ function bounds(strokes) {
617
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
618
+ for (const s of strokes) for (const p of s) {
619
+ x0 = Math.min(x0, p.x);
620
+ y0 = Math.min(y0, p.y);
621
+ x1 = Math.max(x1, p.x);
622
+ y1 = Math.max(y1, p.y);
623
+ }
624
+ return Number.isFinite(x0) ? { x0, y0, x1, y1 } : null;
625
+ }
626
+ function handLine(a, b, rand, steps = 14) {
627
+ const length = Math.hypot(b.x - a.x, b.y - a.y) || 1;
628
+ const nx = -(b.y - a.y) / length;
629
+ const ny = (b.x - a.x) / length;
630
+ const bow = (rand() - 0.5) * Math.min(18, length * 0.04);
631
+ const out = [];
632
+ for (let i = 0; i <= steps; i += 1) {
633
+ const t = i / steps;
634
+ const lift = Math.sin(Math.PI * t) * bow + (rand() - 0.5) * 1.6;
635
+ out.push({ x: a.x + (b.x - a.x) * t + nx * lift, y: a.y + (b.y - a.y) * t + ny * lift });
636
+ }
637
+ return out;
638
+ }
639
+ function handEllipse(b, rand) {
640
+ const cx = sx(b[0] + b[2] / 2);
641
+ const cy = sy(b[1] + b[3] / 2);
642
+ const rx = sx(b[2]) / 2 + 8;
643
+ const ry = sy(b[3]) / 2 + 8;
644
+ const start = -Math.PI * (0.55 + rand() * 0.2);
645
+ const sweep = Math.PI * 2 * (1.06 + rand() * 0.05);
646
+ const out = [];
647
+ const n = 48;
648
+ for (let i = 0; i <= n; i += 1) {
649
+ const t = i / n;
650
+ const a = start + sweep * t;
651
+ const grow = 1 + (t - 0.5) * 0.06 + (rand() - 0.5) * 0.012;
652
+ out.push({ x: cx + Math.cos(a) * rx * grow, y: cy + Math.sin(a) * ry * grow });
653
+ }
654
+ return out;
655
+ }
656
+ function smooth(points, per = 8) {
657
+ if (points.length < 3) return points;
658
+ const out = [];
659
+ for (let i = 0; i < points.length - 1; i += 1) {
660
+ const p0 = points[Math.max(0, i - 1)];
661
+ const p1 = points[i];
662
+ const p2 = points[i + 1];
663
+ const p3 = points[Math.min(points.length - 1, i + 2)];
664
+ for (let j = 0; j < per; j += 1) {
665
+ const t = j / per;
666
+ const t2 = t * t;
667
+ const t3 = t2 * t;
668
+ out.push({
669
+ x: 0.5 * (2 * p1.x + (-p0.x + p2.x) * t + (2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x) * t2 + (-p0.x + 3 * p1.x - 3 * p2.x + p3.x) * t3),
670
+ y: 0.5 * (2 * p1.y + (-p0.y + p2.y) * t + (2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y) * t2 + (-p0.y + 3 * p1.y - 3 * p2.y + p3.y) * t3)
671
+ });
672
+ }
673
+ }
674
+ out.push(points[points.length - 1]);
675
+ return out;
676
+ }
677
+ function arrowHead(from, to, rand) {
678
+ const angle = Math.atan2(to.y - from.y, to.x - from.x);
679
+ const size = 26 + rand() * 6;
680
+ const spread = 0.45;
681
+ return [
682
+ { x: to.x - size * Math.cos(angle - spread), y: to.y - size * Math.sin(angle - spread) },
683
+ to,
684
+ { x: to.x - size * Math.cos(angle + spread), y: to.y - size * Math.sin(angle + spread) }
685
+ ];
686
+ }
687
+ const corner = (b) => {
688
+ const x0 = sx(b[0]), y0 = sy(b[1]), x1 = sx(b[0] + b[2]), y1 = sy(b[1] + b[3]);
689
+ return [{ x: x0, y: y0 }, { x: x1, y: y0 }, { x: x1, y: y1 }, { x: x0, y: y1 }];
690
+ };
691
+ function handPoly(points, closed, rand) {
692
+ const corners = closed ? [...points, points[0]] : points;
693
+ const out = [];
694
+ for (let i = 1; i < corners.length; i += 1) {
695
+ const length = Math.hypot(corners[i].x - corners[i - 1].x, corners[i].y - corners[i - 1].y);
696
+ const segment = handLine(corners[i - 1], corners[i], rand, Math.max(6, Math.min(24, Math.round(length / 30))));
697
+ out.push(...i === 1 ? segment : segment.slice(1));
698
+ }
699
+ return out;
700
+ }
701
+ function handOval(b, rand) {
702
+ const cx = sx(b[0] + b[2] / 2);
703
+ const cy = sy(b[1] + b[3] / 2);
704
+ const rx = sx(b[2]) / 2;
705
+ const ry = sy(b[3]) / 2;
706
+ const start = -Math.PI * (0.6 + rand() * 0.2);
707
+ const sweep = Math.PI * 2 * (1.03 + rand() * 0.03);
708
+ const n = Math.max(32, Math.round((rx + ry) / 6));
709
+ const out = [];
710
+ for (let i = 0; i <= n; i += 1) {
711
+ const a = start + sweep * i / n;
712
+ const wobble = 1 + (rand() - 0.5) * 0.012;
713
+ out.push({ x: cx + Math.cos(a) * rx * wobble, y: cy + Math.sin(a) * ry * wobble });
714
+ }
715
+ return out;
716
+ }
717
+ const unit = (from, to) => {
718
+ const d = Math.hypot(to.x - from.x, to.y - from.y) || 1;
719
+ return { x: (to.x - from.x) / d, y: (to.y - from.y) / d };
720
+ };
721
+ function rightAngle(a, v, b, rand) {
722
+ const size = Math.min(44, 0.3 * Math.min(Math.hypot(a.x - v.x, a.y - v.y), Math.hypot(b.x - v.x, b.y - v.y)));
723
+ const ua = unit(v, a);
724
+ const ub = unit(v, b);
725
+ const p1 = { x: v.x + ua.x * size, y: v.y + ua.y * size };
726
+ const p2 = { x: p1.x + ub.x * size, y: p1.y + ub.y * size };
727
+ const p3 = { x: v.x + ub.x * size, y: v.y + ub.y * size };
728
+ return handPoly([p1, p2, p3], false, rand);
729
+ }
730
+ function angleArc(a, v, b, rand) {
731
+ const r = Math.min(70, 0.3 * Math.min(Math.hypot(a.x - v.x, a.y - v.y), Math.hypot(b.x - v.x, b.y - v.y)));
732
+ const from = Math.atan2(a.y - v.y, a.x - v.x);
733
+ let delta = Math.atan2(b.y - v.y, b.x - v.x) - from;
734
+ while (delta > Math.PI) delta -= 2 * Math.PI;
735
+ while (delta < -Math.PI) delta += 2 * Math.PI;
736
+ const n = 18;
737
+ const out = [];
738
+ for (let i = 0; i <= n; i += 1) {
739
+ const t = from + delta * i / n;
740
+ const rr = r * (1 + (rand() - 0.5) * 0.03);
741
+ out.push({ x: v.x + Math.cos(t) * rr, y: v.y + Math.sin(t) * rr });
742
+ }
743
+ return out;
744
+ }
745
+ function handDot(c) {
746
+ const out = [];
747
+ for (let i = 0; i <= 14; i += 1) {
748
+ const t = i / 14 * Math.PI * 4;
749
+ const r = 7 * (1 - i / 16);
750
+ out.push({ x: c.x + Math.cos(t) * r, y: c.y + Math.sin(t) * r });
751
+ }
752
+ return out;
753
+ }
754
+ function roughen(strokes, seed, amount = 2.2) {
755
+ const rand = seeded(seed);
756
+ return strokes.map((stroke) => {
757
+ let dx = 0;
758
+ let dy = 0;
759
+ return stroke.map((p) => {
760
+ dx = dx * 0.6 + (rand() - 0.5) * amount;
761
+ dy = dy * 0.6 + (rand() - 0.5) * amount;
762
+ return { x: p.x + dx, y: p.y + dy };
763
+ });
764
+ });
765
+ }
766
+ function inkStrokes(kind, geometry, seed) {
767
+ var _a, _b, _c;
768
+ const rand = seeded(seed);
769
+ const p = (q) => ({ x: sx(q[0]), y: sy(q[1]) });
770
+ const pts = (_b = (_a = geometry.pts) == null ? void 0 : _a.map(p)) != null ? _b : [];
771
+ switch (kind) {
772
+ case "line":
773
+ case "arrow": {
774
+ if (!geometry.at || geometry.at.length !== 2 || !geometry.to) return [];
775
+ const a = p(geometry.at);
776
+ const b2 = p(geometry.to);
777
+ const shaft = handLine(a, b2, rand);
778
+ return kind === "arrow" ? [shaft, arrowHead((_c = shaft[shaft.length - 2]) != null ? _c : a, b2, rand)] : [shaft];
779
+ }
780
+ case "free":
781
+ case "curve":
782
+ return pts.length >= 2 ? [smooth(pts)] : [];
783
+ case "poly":
784
+ return pts.length >= 2 ? [handPoly(pts, !!geometry.closed && pts.length > 2, rand)] : [];
785
+ case "corner":
786
+ return pts.length === 3 ? [rightAngle(pts[0], pts[1], pts[2], rand)] : [];
787
+ case "arc":
788
+ return pts.length === 3 ? [angleArc(pts[0], pts[1], pts[2], rand)] : [];
789
+ case "dot":
790
+ return geometry.at && geometry.at.length === 2 ? [handDot(p(geometry.at))] : [];
791
+ }
792
+ const b = geometry.at && geometry.at.length === 4 ? geometry.at : null;
793
+ if (!b) return [];
794
+ const [tl, tr, br, bl] = corner(b);
795
+ switch (kind) {
796
+ case "oval":
797
+ return [handOval(b, rand)];
798
+ case "circle":
799
+ return [handEllipse(b, rand)];
800
+ case "box":
801
+ return [handLine(tl, tr, rand, 10), handLine(tr, br, rand, 8), handLine(br, bl, rand, 10), handLine(bl, tl, rand, 8)];
802
+ case "underline": {
803
+ const y = br.y + 6;
804
+ return [handLine({ x: bl.x - 4, y }, { x: br.x + 4, y: y + (rand() - 0.5) * 6 }, rand, 18)];
805
+ }
806
+ case "cross":
807
+ return [handLine(tl, br, rand, 10), handLine(tr, bl, rand, 10)];
808
+ case "tick": {
809
+ const mid = { x: tl.x + (br.x - tl.x) * 0.38, y: br.y };
810
+ return [[...handLine({ x: tl.x, y: tl.y + (br.y - tl.y) * 0.55 }, mid, rand, 6), ...handLine(mid, tr, rand, 10).slice(1)]];
811
+ }
812
+ case "bracket": {
813
+ const x = tr.x;
814
+ const mid = (tr.y + br.y) / 2;
815
+ return [smooth([{ x: x - 14, y: tr.y }, { x, y: tr.y + 12 }, { x, y: mid - 12 }, { x: x + 14, y: mid }, { x, y: mid + 12 }, { x, y: br.y - 12 }, { x: x - 14, y: br.y }], 5)];
816
+ }
817
+ default:
818
+ return [];
819
+ }
820
+ }
821
+ const TOKEN = /([MmLlHhVvCcSsQqTtAaZz])|(-?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)/g;
822
+ function flattenPath(d, curveSteps = 8) {
823
+ var _a;
824
+ const tokens = [];
825
+ for (const m of d.matchAll(TOKEN)) tokens.push((_a = m[1]) != null ? _a : Number(m[2]));
826
+ const strokes = [];
827
+ let current = [];
828
+ let x = 0, y = 0, startX = 0, startY = 0;
829
+ let lastCtrl = null;
830
+ let lastQuad = null;
831
+ let cmd = "";
832
+ let i = 0;
833
+ const next = () => {
834
+ const v = tokens[i++];
835
+ return typeof v === "number" ? v : NaN;
836
+ };
837
+ const hasNumber = () => typeof tokens[i] === "number";
838
+ const push = (px, py) => {
839
+ current.push({ x: px, y: py });
840
+ };
841
+ const finish = () => {
842
+ if (current.length > 1) strokes.push(current);
843
+ current = [];
844
+ };
845
+ const cubic = (c1, c2, end) => {
846
+ const sx0 = x, sy0 = y;
847
+ for (let s = 1; s <= curveSteps; s += 1) {
848
+ const t = s / curveSteps;
849
+ const u = 1 - t;
850
+ push(
851
+ u * u * u * sx0 + 3 * u * u * t * c1.x + 3 * u * t * t * c2.x + t * t * t * end.x,
852
+ u * u * u * sy0 + 3 * u * u * t * c1.y + 3 * u * t * t * c2.y + t * t * t * end.y
853
+ );
854
+ }
855
+ x = end.x;
856
+ y = end.y;
857
+ };
858
+ const quad = (c, end) => {
859
+ const sx0 = x, sy0 = y;
860
+ for (let s = 1; s <= curveSteps; s += 1) {
861
+ const t = s / curveSteps;
862
+ const u = 1 - t;
863
+ push(u * u * sx0 + 2 * u * t * c.x + t * t * end.x, u * u * sy0 + 2 * u * t * c.y + t * t * end.y);
864
+ }
865
+ x = end.x;
866
+ y = end.y;
867
+ };
868
+ while (i < tokens.length) {
869
+ if (typeof tokens[i] === "string") cmd = tokens[i++];
870
+ else if (!cmd) {
871
+ i += 1;
872
+ continue;
873
+ }
874
+ const rel = cmd === cmd.toLowerCase();
875
+ const ox = rel ? x : 0;
876
+ const oy = rel ? y : 0;
877
+ switch (cmd.toUpperCase()) {
878
+ case "M": {
879
+ finish();
880
+ x = ox + next();
881
+ y = oy + next();
882
+ startX = x;
883
+ startY = y;
884
+ push(x, y);
885
+ cmd = rel ? "l" : "L";
886
+ lastCtrl = lastQuad = null;
887
+ break;
888
+ }
889
+ case "L":
890
+ x = ox + next();
891
+ y = oy + next();
892
+ push(x, y);
893
+ lastCtrl = lastQuad = null;
894
+ break;
895
+ case "H":
896
+ x = ox + next();
897
+ push(x, y);
898
+ lastCtrl = lastQuad = null;
899
+ break;
900
+ case "V":
901
+ y = oy + next();
902
+ push(x, y);
903
+ lastCtrl = lastQuad = null;
904
+ break;
905
+ case "C": {
906
+ const c1 = { x: ox + next(), y: oy + next() };
907
+ const c2 = { x: ox + next(), y: oy + next() };
908
+ const end = { x: ox + next(), y: oy + next() };
909
+ cubic(c1, c2, end);
910
+ lastCtrl = c2;
911
+ lastQuad = null;
912
+ break;
913
+ }
914
+ case "S": {
915
+ const c1 = lastCtrl ? { x: 2 * x - lastCtrl.x, y: 2 * y - lastCtrl.y } : { x, y };
916
+ const c2 = { x: ox + next(), y: oy + next() };
917
+ const end = { x: ox + next(), y: oy + next() };
918
+ cubic(c1, c2, end);
919
+ lastCtrl = c2;
920
+ lastQuad = null;
921
+ break;
922
+ }
923
+ case "Q": {
924
+ const c = { x: ox + next(), y: oy + next() };
925
+ const end = { x: ox + next(), y: oy + next() };
926
+ quad(c, end);
927
+ lastQuad = c;
928
+ lastCtrl = null;
929
+ break;
930
+ }
931
+ case "T": {
932
+ const c = lastQuad ? { x: 2 * x - lastQuad.x, y: 2 * y - lastQuad.y } : { x, y };
933
+ const end = { x: ox + next(), y: oy + next() };
934
+ quad(c, end);
935
+ lastQuad = c;
936
+ lastCtrl = null;
937
+ break;
938
+ }
939
+ case "A": {
940
+ const rx = next(), ry = next(), rotation = next(), large = next(), sweep = next();
941
+ const end = { x: ox + next(), y: oy + next() };
942
+ for (const p of arcPoints({ x, y }, end, rx, ry, rotation, large !== 0, sweep !== 0, curveSteps * 2)) push(p.x, p.y);
943
+ x = end.x;
944
+ y = end.y;
945
+ lastCtrl = lastQuad = null;
946
+ break;
947
+ }
948
+ case "Z":
949
+ push(startX, startY);
950
+ x = startX;
951
+ y = startY;
952
+ finish();
953
+ current = [{ x, y }];
954
+ lastCtrl = lastQuad = null;
955
+ if (hasNumber()) cmd = rel ? "l" : "L";
956
+ else cmd = "";
957
+ break;
958
+ default:
959
+ i += 1;
960
+ }
961
+ if (Number.isNaN(x) || Number.isNaN(y)) return strokes;
962
+ }
963
+ finish();
964
+ return strokes;
965
+ }
966
+ function arcPoints(from, to, rx, ry, degrees, large, sweep, steps) {
967
+ if (!rx || !ry || from.x === to.x && from.y === to.y) return [to];
968
+ const phi = degrees * Math.PI / 180;
969
+ const cos = Math.cos(phi), sin = Math.sin(phi);
970
+ const dx = (from.x - to.x) / 2, dy = (from.y - to.y) / 2;
971
+ const x1 = cos * dx + sin * dy, y1 = -sin * dx + cos * dy;
972
+ let rxa = Math.abs(rx), rya = Math.abs(ry);
973
+ const scale = x1 * x1 / (rxa * rxa) + y1 * y1 / (rya * rya);
974
+ if (scale > 1) {
975
+ rxa *= Math.sqrt(scale);
976
+ rya *= Math.sqrt(scale);
977
+ }
978
+ const num = rxa * rxa * rya * rya - rxa * rxa * y1 * y1 - rya * rya * x1 * x1;
979
+ const den = rxa * rxa * y1 * y1 + rya * rya * x1 * x1;
980
+ const k = (large === sweep ? -1 : 1) * Math.sqrt(Math.max(0, num / den));
981
+ const cx1 = k * rxa * y1 / rya, cy1 = -k * rya * x1 / rxa;
982
+ const cx = cos * cx1 - sin * cy1 + (from.x + to.x) / 2;
983
+ const cy = sin * cx1 + cos * cy1 + (from.y + to.y) / 2;
984
+ const angle = (ux, uy, vx, vy) => Math.atan2(ux * vy - uy * vx, ux * vx + uy * vy);
985
+ const start = angle(1, 0, (x1 - cx1) / rxa, (y1 - cy1) / rya);
986
+ let delta = angle((x1 - cx1) / rxa, (y1 - cy1) / rya, (-x1 - cx1) / rxa, (-y1 - cy1) / rya);
987
+ if (!sweep && delta > 0) delta -= 2 * Math.PI;
988
+ if (sweep && delta < 0) delta += 2 * Math.PI;
989
+ const out = [];
990
+ for (let i = 1; i <= steps; i += 1) {
991
+ const t = start + delta * i / steps;
992
+ out.push({ x: cx + rxa * Math.cos(t) * cos - rya * Math.sin(t) * sin, y: cy + rxa * Math.cos(t) * sin + rya * Math.sin(t) * cos });
993
+ }
994
+ out[out.length - 1] = to;
995
+ return out;
996
+ }
997
+ function parseTransform(transform) {
998
+ const t = /translate\(\s*(-?[\d.]+)(?:[\s,]+(-?[\d.]+))?/.exec(transform);
999
+ const s = /scale\(\s*(-?[\d.]+)(?:[\s,]+(-?[\d.]+))?/.exec(transform);
1000
+ const kx = s ? Number(s[1]) : 1;
1001
+ return {
1002
+ tx: t ? Number(t[1]) : 0,
1003
+ ty: t && t[2] !== void 0 ? Number(t[2]) : 0,
1004
+ kx,
1005
+ ky: s && s[2] !== void 0 ? Number(s[2]) : kx
1006
+ };
1007
+ }
1008
+ function fit(strokes, viewBox, transform, b) {
1009
+ const [vx, vy, vw, vh] = viewBox.split(/[\s,]+/).map(Number);
1010
+ const w = vw > 0 ? vw : 100;
1011
+ const h = vh > 0 ? vh : 100;
1012
+ const { tx, ty, kx, ky } = parseTransform(transform);
1013
+ const bx = sx(b[0]), by = sy(b[1]), bw = sx(b[2]), bh = sy(b[3]);
1014
+ const k = Math.min(bw / w, bh / h);
1015
+ const offX = bx + (bw - w * k) / 2;
1016
+ const offY = by + (bh - h * k) / 2;
1017
+ return strokes.map((stroke) => stroke.map((p) => ({
1018
+ x: offX + (tx + kx * p.x - (vx || 0)) * k,
1019
+ y: offY + (ty + ky * p.y - (vy || 0)) * k
1020
+ })));
1021
+ }
1022
+ function artStrokes(ink, b, seed = 1) {
1023
+ if ("icon" in ink) {
1024
+ const paths = storyboardIconStrokes(ink.icon);
1025
+ return roughen(fit(paths.flatMap((d) => flattenPath(d, 14)), "0 0 100 100", "", b), seed);
1026
+ }
1027
+ return fit(ink.contours.flatMap((d) => flattenPath(d, 6)), ink.view_box, ink.transform, b);
1028
+ }
1029
+ function pointAlong(strokes, length) {
1030
+ let left = length;
1031
+ for (const s of strokes) {
1032
+ for (let i = 1; i < s.length; i += 1) {
1033
+ const seg = Math.hypot(s[i].x - s[i - 1].x, s[i].y - s[i - 1].y);
1034
+ if (left <= seg) {
1035
+ const t = seg ? left / seg : 1;
1036
+ return { x: s[i - 1].x + (s[i].x - s[i - 1].x) * t, y: s[i - 1].y + (s[i].y - s[i - 1].y) * t };
1037
+ }
1038
+ left -= seg;
1039
+ }
1040
+ }
1041
+ const last = strokes[strokes.length - 1];
1042
+ return last ? last[last.length - 1] : null;
1043
+ }
1044
+ const INK = { ink: "#1f2937", blue: "#2563eb", red: "#dc2626", green: "#059669" };
1045
+ const MARKER = "rgba(250, 204, 21, 0.42)";
1046
+ const TEXT_SIZE = { s: 2.3, m: 3.1, l: 4.3 };
1047
+ const TRAVEL_MS = 200;
1048
+ class BoardModel {
1049
+ constructor(options) {
1050
+ this.options = options;
1051
+ this.inks = [];
1052
+ this.words = [];
1053
+ this.pen = null;
1054
+ this.caption = "";
1055
+ this.step = -1;
1056
+ this.player = null;
1057
+ this.scene = null;
1058
+ this.nextKey = 1;
1059
+ }
1060
+ snapshot() {
1061
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1062
+ return {
1063
+ inks: this.inks,
1064
+ words: this.words,
1065
+ pen: this.pen,
1066
+ caption: this.caption,
1067
+ step: this.step,
1068
+ steps: (_b = (_a = this.scene) == null ? void 0 : _a.steps.length) != null ? _b : 0,
1069
+ state: (_d = (_c = this.player) == null ? void 0 : _c.status) != null ? _d : "idle",
1070
+ title: (_f = (_e = this.scene) == null ? void 0 : _e.title) != null ? _f : "",
1071
+ sample: (_h = (_g = this.scene) == null ? void 0 : _g.sample) != null ? _h : false
1072
+ };
1073
+ }
1074
+ play(scene) {
1075
+ var _a, _b, _c, _d, _e;
1076
+ this.destroy();
1077
+ this.scene = scene;
1078
+ const steps = scene.steps.map((step, index) => this.buildStep(step, index));
1079
+ this.player = new Player(steps, {
1080
+ narrate: (_a = this.options.narrate) != null ? _a : (async () => false),
1081
+ stopNarration: () => {
1082
+ var _a2, _b2;
1083
+ return (_b2 = (_a2 = this.options).stopNarration) == null ? void 0 : _b2.call(_a2);
1084
+ },
1085
+ reset: () => this.wipe(),
1086
+ onStep: (index, step) => {
1087
+ this.step = index;
1088
+ this.caption = step.say;
1089
+ this.changed();
1090
+ },
1091
+ onState: () => this.changed(),
1092
+ requestFrame: (_b = this.options.requestFrame) != null ? _b : ((cb) => requestAnimationFrame(cb)),
1093
+ cancelFrame: (_c = this.options.cancelFrame) != null ? _c : ((id) => cancelAnimationFrame(id)),
1094
+ now: (_d = this.options.now) != null ? _d : (() => Date.now())
1095
+ }, (_e = this.options.reducedMotion) != null ? _e : false);
1096
+ this.player.play();
1097
+ }
1098
+ /** Pause, or carry on from where it was. */
1099
+ toggle() {
1100
+ if (!this.player) return;
1101
+ if (this.player.status === "playing") this.player.pause();
1102
+ else this.player.play();
1103
+ }
1104
+ replay() {
1105
+ var _a;
1106
+ (_a = this.player) == null ? void 0 : _a.replay();
1107
+ }
1108
+ seek(step) {
1109
+ var _a;
1110
+ (_a = this.player) == null ? void 0 : _a.seek(step);
1111
+ }
1112
+ setSpeed(speed) {
1113
+ var _a;
1114
+ (_a = this.player) == null ? void 0 : _a.setSpeed(speed);
1115
+ }
1116
+ get speed() {
1117
+ var _a, _b;
1118
+ return (_b = (_a = this.player) == null ? void 0 : _a.rate) != null ? _b : 1;
1119
+ }
1120
+ /** Stop for good: no frames, nothing on the board. */
1121
+ destroy() {
1122
+ var _a;
1123
+ (_a = this.player) == null ? void 0 : _a.destroy();
1124
+ this.player = null;
1125
+ this.scene = null;
1126
+ this.wipe();
1127
+ this.step = -1;
1128
+ this.caption = "";
1129
+ }
1130
+ changed() {
1131
+ this.options.onChange();
1132
+ }
1133
+ wipe() {
1134
+ this.inks = [];
1135
+ this.words = [];
1136
+ this.pen = null;
1137
+ this.changed();
1138
+ }
1139
+ // ------------------------------------------------------------- steps → ops
1140
+ buildStep(step, index) {
1141
+ return {
1142
+ say: step.say,
1143
+ enter: () => {
1144
+ if (step.clear) this.wipe();
1145
+ },
1146
+ ops: step.draw.map((item, i) => this.opFor(item, index * 100 + i + 1))
1147
+ };
1148
+ }
1149
+ opFor(item, seed) {
1150
+ var _a;
1151
+ switch (item.kind) {
1152
+ case "ink":
1153
+ return this.inkOp(item.id, inkStrokes(item.ink, item, seed), INK[item.tone], item.ink === "dot" ? 9 : 7, item.ink === "dot" ? 250 : 350, 2600, 1.1);
1154
+ case "art": {
1155
+ const ink = (_a = this.scene) == null ? void 0 : _a.art[item.art];
1156
+ if (!ink) {
1157
+ const [x, y, w, h] = item.at;
1158
+ return this.textOp({ kind: "text", id: item.id, text: item.art, at: [x + 1, y + h / 2], size: w < 15 ? "s" : "m", tone: item.tone });
1159
+ }
1160
+ return this.inkOp(item.id, artStrokes(ink, item.at, seed), INK[item.tone], "icon" in ink ? 7 : 4, 1100, 4500, 2.6);
1161
+ }
1162
+ case "text":
1163
+ return this.textOp(item);
1164
+ case "table":
1165
+ return this.tableOp(item);
1166
+ case "mark":
1167
+ return this.markOp(item.mark);
1168
+ case "erase":
1169
+ return this.eraseOp(item.erase);
1170
+ default:
1171
+ return { duration: 0, run: () => void 0 };
1172
+ }
1173
+ }
1174
+ inkOp(id, strokes, color, width, min, max, perMs, marker = false) {
1175
+ const length = totalLength(strokes);
1176
+ const duration = Math.min(max, Math.max(min, length / perMs)) + TRAVEL_MS;
1177
+ const share = TRAVEL_MS / duration;
1178
+ let obj = null;
1179
+ return {
1180
+ duration,
1181
+ run: (progress) => {
1182
+ var _a, _b;
1183
+ if (!obj) {
1184
+ obj = { key: this.nextKey++, id, strokes, length, color, width, marker, drawn: 0 };
1185
+ this.inks = [...this.inks, obj];
1186
+ }
1187
+ if (!length) return;
1188
+ const drawn = progress >= 1 ? 1 : Math.max(0, (progress - share) / (1 - share));
1189
+ obj.drawn = drawn;
1190
+ this.pen = drawn > 0 ? pointAlong(strokes, length * drawn) : (_b = (_a = strokes[0]) == null ? void 0 : _a[0]) != null ? _b : this.pen;
1191
+ this.changed();
1192
+ }
1193
+ };
1194
+ }
1195
+ textOp(item) {
1196
+ const duration = Math.min(2e3, Math.max(350, item.text.length * 60)) + TRAVEL_MS;
1197
+ let word = null;
1198
+ return {
1199
+ duration,
1200
+ run: (progress) => {
1201
+ if (!word) {
1202
+ word = { key: this.nextKey++, id: item.id, kind: "text", text: item.text, at: item.at, size: item.size, color: INK[item.tone], shown: 0, marked: false, gone: false };
1203
+ this.words = [...this.words, word];
1204
+ }
1205
+ word.shown = progress >= 1 ? 1 : Math.max(0, (progress * duration - TRAVEL_MS) / (duration - TRAVEL_MS));
1206
+ const height = TEXT_SIZE[item.size] / 100 * BOARD_W;
1207
+ this.pen = { x: sx(item.at[0] + item.text.length * height * 0.55 * word.shown), y: sy(item.at[1]) };
1208
+ this.changed();
1209
+ }
1210
+ };
1211
+ }
1212
+ tableOp(item) {
1213
+ let table = null;
1214
+ return {
1215
+ duration: item.rows.length * 450 + TRAVEL_MS,
1216
+ run: (progress) => {
1217
+ if (!table) {
1218
+ table = { key: this.nextKey++, id: item.id, kind: "table", rows: item.rows, at: item.at, color: INK[item.tone], rowsShown: 0, marked: false, gone: false };
1219
+ this.words = [...this.words, table];
1220
+ }
1221
+ table.rowsShown = progress >= 1 ? item.rows.length : Math.max(progress > 0 ? 1 : 0, Math.floor(progress * item.rows.length));
1222
+ this.pen = { x: sx(item.at[0] + item.at[2]), y: sy(item.at[1]) };
1223
+ this.changed();
1224
+ }
1225
+ };
1226
+ }
1227
+ markOp(id) {
1228
+ let done = false;
1229
+ return {
1230
+ duration: 650,
1231
+ run: () => {
1232
+ if (done) return;
1233
+ done = true;
1234
+ const word = this.words.find((w) => w.id === id);
1235
+ if (word) {
1236
+ word.marked = true;
1237
+ this.changed();
1238
+ return;
1239
+ }
1240
+ const ink = this.inks.find((obj) => obj.id === id && !obj.marker);
1241
+ const box = ink ? bounds(ink.strokes) : null;
1242
+ if (!box) return;
1243
+ const mid = (box.y0 + box.y1) / 2;
1244
+ const swipe = [{ x: box.x0 - 14, y: mid }, { x: box.x1 + 14, y: mid }];
1245
+ this.inks = [{
1246
+ key: this.nextKey++,
1247
+ strokes: [swipe],
1248
+ length: totalLength([swipe]),
1249
+ color: MARKER,
1250
+ width: Math.max(24, (box.y1 - box.y0) * 0.6),
1251
+ marker: true,
1252
+ drawn: 1
1253
+ }, ...this.inks];
1254
+ this.changed();
1255
+ }
1256
+ };
1257
+ }
1258
+ eraseOp(id) {
1259
+ return {
1260
+ duration: 350,
1261
+ run: (progress) => {
1262
+ if (progress < 1) return;
1263
+ this.words = this.words.filter((w) => w.id !== id);
1264
+ this.inks = this.inks.filter((obj) => obj.id !== id);
1265
+ this.changed();
1266
+ }
1267
+ };
1268
+ }
1269
+ }
1270
+ function inkPath(strokes, length, upTo) {
1271
+ let left = length * upTo;
1272
+ const parts = [];
1273
+ for (const stroke of strokes) {
1274
+ if (left <= 0 || stroke.length < 2) break;
1275
+ let d = `M${stroke[0].x.toFixed(1)} ${stroke[0].y.toFixed(1)}`;
1276
+ for (let i = 1; i < stroke.length; i += 1) {
1277
+ const a = stroke[i - 1];
1278
+ const b = stroke[i];
1279
+ const seg = Math.hypot(b.x - a.x, b.y - a.y);
1280
+ if (seg >= left) {
1281
+ const t = seg ? left / seg : 1;
1282
+ d += `L${(a.x + (b.x - a.x) * t).toFixed(1)} ${(a.y + (b.y - a.y) * t).toFixed(1)}`;
1283
+ left = 0;
1284
+ break;
1285
+ }
1286
+ d += `L${b.x.toFixed(1)} ${b.y.toFixed(1)}`;
1287
+ left -= seg;
1288
+ }
1289
+ parts.push(d);
1290
+ }
1291
+ return parts.join("");
1292
+ }
286
1293
  const darkTheme = {
287
1294
  background: "#0B0713",
288
1295
  surface: "rgba(255,255,255,0.06)",
@@ -316,6 +1323,208 @@ const lightTheme = {
316
1323
  function resolveTheme(overrides, base = lightTheme) {
317
1324
  return overrides ? { ...base, ...overrides } : base;
318
1325
  }
1326
+ const SHEET_W = 1600;
1327
+ const SHEET_H = 1e3;
1328
+ const HAND = Platform.select({ ios: "Bradley Hand", android: "casual", default: void 0 });
1329
+ const PEN = "M0 0 L-5 -22 L22 -70 L32 -63 L5 -16 Z";
1330
+ function GuideAIWhiteboard({ theme: overrides }) {
1331
+ const theme = resolveTheme(overrides);
1332
+ const { state, close, retry } = useWhiteboard();
1333
+ const [, repaint] = useReducer((n) => n + 1, 0);
1334
+ const [width, setWidth] = useState(0);
1335
+ const [expanded, setExpanded] = useState(false);
1336
+ const motion = useRef({ reduced: false });
1337
+ const model = useMemo(() => new BoardModel({
1338
+ onChange: () => repaint(),
1339
+ get reducedMotion() {
1340
+ return motion.current.reduced;
1341
+ }
1342
+ }), []);
1343
+ useEffect(() => {
1344
+ var _a, _b;
1345
+ void ((_b = (_a = AccessibilityInfo).isReduceMotionEnabled) == null ? void 0 : _b.call(_a).then((on) => {
1346
+ motion.current.reduced = on;
1347
+ }, () => void 0));
1348
+ }, []);
1349
+ useEffect(() => {
1350
+ if (state.status === "playing" && state.scene) model.play(state.scene);
1351
+ else model.destroy();
1352
+ }, [model, state.status, state.scene]);
1353
+ useEffect(() => () => model.destroy(), [model]);
1354
+ if (state.status === "closed") return null;
1355
+ const board = model.snapshot();
1356
+ const height = width / (BOARD_W / BOARD_H);
1357
+ const unit2 = width / 100;
1358
+ const playing = board.state === "playing";
1359
+ const title = state.status === "playing" ? board.title : state.question;
1360
+ const shut = () => {
1361
+ model.destroy();
1362
+ close();
1363
+ };
1364
+ return /* @__PURE__ */ jsx(Modal, { visible: true, transparent: true, animationType: "fade", onRequestClose: shut, supportedOrientations: ["portrait", "landscape"], children: /* @__PURE__ */ jsx(View, { style: [styles$3.backdrop, expanded ? styles$3.centre : null], pointerEvents: "box-none", children: /* @__PURE__ */ jsxs(
1365
+ View,
1366
+ {
1367
+ style: [styles$3.card, { backgroundColor: theme.surfaceRaised, borderColor: theme.border, maxWidth: expanded ? 1040 : 540 }],
1368
+ accessibilityViewIsModal: true,
1369
+ accessibilityLabel: `Whiteboard: ${title}`,
1370
+ children: [
1371
+ /* @__PURE__ */ jsxs(View, { style: styles$3.head, children: [
1372
+ /* @__PURE__ */ jsx(Text, { style: [styles$3.title, { color: theme.text }], numberOfLines: 1, children: title || "Whiteboard" }),
1373
+ board.sample && state.status === "playing" ? /* @__PURE__ */ jsx(Text, { style: styles$3.badge, accessibilityHint: "This board uses example numbers.", children: "Example" }) : null,
1374
+ /* @__PURE__ */ jsx(IconButton, { label: expanded ? "Collapse whiteboard" : "Expand whiteboard", glyph: expanded ? "⤡" : "⤢", color: theme.textMuted, onPress: () => setExpanded((v) => !v) }),
1375
+ /* @__PURE__ */ jsx(IconButton, { label: "Close whiteboard", glyph: "✕", color: theme.textMuted, onPress: shut })
1376
+ ] }),
1377
+ /* @__PURE__ */ jsxs(View, { style: styles$3.sheet, onLayout: (e) => setWidth(e.nativeEvent.layout.width), children: [
1378
+ width > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
1379
+ /* @__PURE__ */ jsxs(Svg, { width, height, viewBox: `0 0 ${SHEET_W} ${SHEET_H}`, children: [
1380
+ board.inks.filter((obj) => obj.marker).map((obj) => /* @__PURE__ */ jsx(Ink, { obj }, obj.key)),
1381
+ board.inks.filter((obj) => !obj.marker).map((obj) => /* @__PURE__ */ jsx(Ink, { obj }, obj.key)),
1382
+ board.pen && playing && !motion.current.reduced ? /* @__PURE__ */ jsx(G, { transform: `translate(${board.pen.x.toFixed(1)} ${board.pen.y.toFixed(1)})`, children: /* @__PURE__ */ jsx(Path, { d: PEN, fill: "#fde68a", stroke: "#1f2937", strokeWidth: 3, strokeLinejoin: "round" }) }) : null
1383
+ ] }),
1384
+ board.words.map((word) => /* @__PURE__ */ jsx(Word, { word, width, height, unit: unit2 }, word.key))
1385
+ ] }) : null,
1386
+ state.status === "loading" ? /* @__PURE__ */ jsxs(View, { style: styles$3.status, accessibilityLiveRegion: "polite", children: [
1387
+ /* @__PURE__ */ jsx(ActivityIndicator, { color: theme.accent }),
1388
+ /* @__PURE__ */ jsx(Text, { style: styles$3.statusText, children: "Drawing your board…" })
1389
+ ] }) : null,
1390
+ state.status === "error" ? /* @__PURE__ */ jsxs(View, { style: styles$3.status, accessibilityLiveRegion: "assertive", children: [
1391
+ /* @__PURE__ */ jsx(Text, { style: styles$3.statusText, children: state.error }),
1392
+ /* @__PURE__ */ jsx(Pressable, { accessibilityRole: "button", onPress: retry, style: [styles$3.retry, { backgroundColor: theme.accent }], children: /* @__PURE__ */ jsx(Text, { style: { color: theme.onAccent, fontWeight: "600" }, children: "Try again" }) })
1393
+ ] }) : null
1394
+ ] }),
1395
+ state.status === "playing" ? /* @__PURE__ */ jsxs(Fragment, { children: [
1396
+ /* @__PURE__ */ jsx(Text, { style: [styles$3.caption, { color: theme.text }], accessibilityLiveRegion: "polite", children: board.caption }),
1397
+ board.steps > 1 ? /* @__PURE__ */ jsx(View, { style: styles$3.track, accessibilityLabel: "Steps", children: Array.from({ length: board.steps }, (_, i) => /* @__PURE__ */ jsx(
1398
+ Pressable,
1399
+ {
1400
+ accessibilityRole: "button",
1401
+ accessibilityLabel: `Go to step ${i + 1}`,
1402
+ accessibilityState: { selected: i === board.step },
1403
+ onPress: () => model.seek(i),
1404
+ hitSlop: 8,
1405
+ style: [styles$3.segment, { backgroundColor: i <= board.step ? theme.accent : theme.border }]
1406
+ },
1407
+ i
1408
+ )) }) : null,
1409
+ /* @__PURE__ */ jsxs(View, { style: styles$3.bar, children: [
1410
+ /* @__PURE__ */ jsx(
1411
+ IconButton,
1412
+ {
1413
+ label: playing ? "Pause" : board.state === "done" ? "Play again" : "Resume",
1414
+ glyph: playing ? "❚❚" : board.state === "done" ? "↻" : "▶",
1415
+ color: theme.text,
1416
+ onPress: () => model.toggle()
1417
+ }
1418
+ ),
1419
+ /* @__PURE__ */ jsx(IconButton, { label: "Replay from the start", glyph: "↺", color: theme.text, onPress: () => model.replay() }),
1420
+ /* @__PURE__ */ jsx(Text, { style: [styles$3.step, { color: theme.textMuted }], children: board.step >= 0 ? `Step ${board.step + 1} of ${board.steps}` : "" }),
1421
+ /* @__PURE__ */ jsx(
1422
+ Pressable,
1423
+ {
1424
+ accessibilityRole: "button",
1425
+ accessibilityLabel: `Speed ${model.speed} times. Change speed`,
1426
+ onPress: () => {
1427
+ const at = SPEEDS.indexOf(model.speed);
1428
+ model.setSpeed(SPEEDS[(at + 1) % SPEEDS.length]);
1429
+ repaint();
1430
+ },
1431
+ style: [styles$3.speed, { borderColor: theme.border }],
1432
+ children: /* @__PURE__ */ jsxs(Text, { style: { color: theme.text, fontSize: 12 }, children: [
1433
+ model.speed,
1434
+ "×"
1435
+ ] })
1436
+ }
1437
+ )
1438
+ ] })
1439
+ ] }) : null
1440
+ ]
1441
+ }
1442
+ ) }) });
1443
+ }
1444
+ function Ink({ obj }) {
1445
+ if (obj.drawn <= 0) return null;
1446
+ return /* @__PURE__ */ jsx(
1447
+ Path,
1448
+ {
1449
+ d: inkPath(obj.strokes, obj.length, obj.drawn),
1450
+ stroke: obj.color,
1451
+ strokeWidth: obj.width,
1452
+ fill: "none",
1453
+ strokeLinecap: "round",
1454
+ strokeLinejoin: "round"
1455
+ }
1456
+ );
1457
+ }
1458
+ function Word({ word, width, height, unit: unit2 }) {
1459
+ const left = word.at[0] / BOARD_W * width;
1460
+ const top = word.at[1] / BOARD_H * height;
1461
+ if (word.kind === "text") {
1462
+ const size2 = unit2 * TEXT_SIZE[word.size];
1463
+ const shown = word.text.slice(0, Math.ceil(word.text.length * word.shown));
1464
+ if (!shown) return null;
1465
+ return /* @__PURE__ */ jsx(
1466
+ Text,
1467
+ {
1468
+ style: [styles$3.word, {
1469
+ left,
1470
+ top: top - size2 * 0.62,
1471
+ fontSize: size2,
1472
+ color: word.color,
1473
+ fontFamily: HAND,
1474
+ backgroundColor: word.marked ? MARKER : "transparent"
1475
+ }],
1476
+ accessibilityLabel: word.text,
1477
+ children: shown
1478
+ }
1479
+ );
1480
+ }
1481
+ if (word.rowsShown <= 0) return null;
1482
+ const size = unit2 * 2.2;
1483
+ return /* @__PURE__ */ jsx(View, { style: [styles$3.table, { left, top, width: word.at[2] / BOARD_W * width, borderColor: word.color, backgroundColor: word.marked ? MARKER : "transparent" }], children: word.rows.slice(0, word.rowsShown).map((row, r) => /* @__PURE__ */ jsx(View, { style: styles$3.row, children: row.map((cell, c) => /* @__PURE__ */ jsx(
1484
+ Text,
1485
+ {
1486
+ style: [styles$3.cell, { fontSize: size, color: word.color, borderColor: word.color, fontFamily: HAND, fontWeight: r === 0 ? "700" : "400" }],
1487
+ children: cell
1488
+ },
1489
+ c
1490
+ )) }, r)) });
1491
+ }
1492
+ function IconButton({ label, glyph, color, onPress }) {
1493
+ return /* @__PURE__ */ jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: label, onPress, hitSlop: 8, style: styles$3.icon, children: /* @__PURE__ */ jsx(Text, { style: { color, fontSize: 16 }, children: glyph }) });
1494
+ }
1495
+ const styles$3 = StyleSheet.create({
1496
+ backdrop: { flex: 1, justifyContent: "flex-end", alignItems: "center", padding: 12 },
1497
+ centre: { justifyContent: "center" },
1498
+ card: {
1499
+ width: "100%",
1500
+ borderRadius: 16,
1501
+ borderWidth: StyleSheet.hairlineWidth,
1502
+ overflow: "hidden",
1503
+ shadowColor: "#0f172a",
1504
+ shadowOpacity: 0.25,
1505
+ shadowRadius: 24,
1506
+ shadowOffset: { width: 0, height: 12 },
1507
+ elevation: 12
1508
+ },
1509
+ head: { flexDirection: "row", alignItems: "center", paddingHorizontal: 12, paddingVertical: 8, gap: 6 },
1510
+ title: { flex: 1, fontSize: 14, fontWeight: "600" },
1511
+ badge: { fontSize: 11, fontWeight: "600", color: "#92400e", backgroundColor: "#fef3c7", borderRadius: 999, paddingHorizontal: 8, paddingVertical: 2, overflow: "hidden" },
1512
+ sheet: { width: "100%", aspectRatio: BOARD_W / BOARD_H, backgroundColor: "#fcfcfd" },
1513
+ status: { ...StyleSheet.absoluteFillObject, alignItems: "center", justifyContent: "center", gap: 10, backgroundColor: "rgba(252,252,253,0.92)", padding: 16 },
1514
+ statusText: { color: "#475569", fontSize: 13, textAlign: "center" },
1515
+ retry: { paddingHorizontal: 14, paddingVertical: 8, borderRadius: 8 },
1516
+ caption: { paddingHorizontal: 14, paddingTop: 10, fontSize: 14, lineHeight: 20, minHeight: 46 },
1517
+ track: { flexDirection: "row", gap: 4, paddingHorizontal: 14, paddingTop: 4 },
1518
+ segment: { flex: 1, height: 6, borderRadius: 3 },
1519
+ bar: { flexDirection: "row", alignItems: "center", paddingHorizontal: 8, paddingVertical: 6, gap: 4 },
1520
+ step: { flex: 1, fontSize: 12, marginLeft: 4 },
1521
+ speed: { borderWidth: 1, borderRadius: 8, paddingHorizontal: 8, paddingVertical: 4 },
1522
+ icon: { width: 34, height: 34, alignItems: "center", justifyContent: "center" },
1523
+ word: { position: "absolute", fontWeight: "600" },
1524
+ table: { position: "absolute", borderWidth: 1.5 },
1525
+ row: { flexDirection: "row" },
1526
+ cell: { flex: 1, borderWidth: 0.75, paddingHorizontal: 6, paddingVertical: 3 }
1527
+ });
319
1528
  function PersonIcon({ color }) {
320
1529
  return /* @__PURE__ */ jsxs(View, { style: styles$2.iconWrap, children: [
321
1530
  /* @__PURE__ */ jsx(View, { style: [styles$2.iconBand, { borderColor: color }] }),
@@ -365,7 +1574,7 @@ function Orb({ theme, active }) {
365
1574
  /* @__PURE__ */ jsx(View, { style: [styles$2.orbCore, { backgroundColor: theme.accent }] })
366
1575
  ] });
367
1576
  }
368
- function Bubble$1({ message, theme, onTalkToHuman }) {
1577
+ function Bubble$1({ message, theme, onTalkToHuman, onWhiteboard }) {
369
1578
  if (message.role === "user") {
370
1579
  return /* @__PURE__ */ jsx(View, { style: [styles$2.row, styles$2.rowUser], children: /* @__PURE__ */ jsx(View, { style: [
371
1580
  styles$2.bubble,
@@ -381,10 +1590,18 @@ function Bubble$1({ message, theme, onTalkToHuman }) {
381
1590
  styles$2.assistantBody,
382
1591
  message.error ? { backgroundColor: theme.error, borderRadius: theme.radius, padding: 12 } : null
383
1592
  ], children: [
384
- message.content ? /* @__PURE__ */ jsx(Markdown, { color: theme.text, accentColor: theme.accent, fontSize: theme.fontSize, children: message.content }) : (
385
- // A streaming message with no text yet would be an empty box.
386
- /* @__PURE__ */ jsx(Text, { style: { color: theme.textMuted, fontSize: theme.fontSize }, children: message.streaming ? "…" : "" })
387
- ),
1593
+ /* @__PURE__ */ jsx(Markdown, { color: theme.text, accentColor: theme.accent, fontSize: theme.fontSize, children: message.content }),
1594
+ onWhiteboard ? /* @__PURE__ */ jsx(
1595
+ Pressable,
1596
+ {
1597
+ onPress: onWhiteboard,
1598
+ accessibilityRole: "button",
1599
+ accessibilityLabel: "Explain on whiteboard",
1600
+ style: [styles$2.errorAction, { borderColor: theme.accent }],
1601
+ hitSlop: 6,
1602
+ children: /* @__PURE__ */ jsx(Text, { style: [styles$2.humanText, { color: theme.accent, fontSize: theme.fontSize - 1 }], children: "✎ Explain on whiteboard" })
1603
+ }
1604
+ ) : null,
388
1605
  message.error && onTalkToHuman ? /* @__PURE__ */ jsxs(
389
1606
  Pressable,
390
1607
  {
@@ -453,7 +1670,10 @@ function GuideAIChat({
453
1670
  send,
454
1671
  busy,
455
1672
  canSend,
456
- status
1673
+ status,
1674
+ typing,
1675
+ followUps,
1676
+ explainOnWhiteboard
457
1677
  } = useGuideAI({ harness, trace: debug });
458
1678
  const theme = resolveTheme(overrides);
459
1679
  const listRef = useRef(null);
@@ -550,7 +1770,33 @@ function GuideAIChat({
550
1770
  ref: listRef,
551
1771
  data: messages,
552
1772
  keyExtractor: (message) => message.id,
553
- renderItem: ({ item }) => /* @__PURE__ */ jsx(Bubble$1, { message: item, theme, onTalkToHuman }),
1773
+ renderItem: ({ item }) => /* @__PURE__ */ jsx(
1774
+ Bubble$1,
1775
+ {
1776
+ message: item,
1777
+ theme,
1778
+ onTalkToHuman,
1779
+ onWhiteboard: item.whiteboard ? () => {
1780
+ void explainOnWhiteboard(item.id);
1781
+ } : void 0
1782
+ }
1783
+ ),
1784
+ ListFooterComponent: typing || followUps.length ? /* @__PURE__ */ jsxs(View, { style: styles$2.footer, children: [
1785
+ typing ? /* @__PURE__ */ jsx(Text, { style: { color: theme.textMuted, fontSize: theme.fontSize }, children: "…" }) : null,
1786
+ followUps.map((label) => /* @__PURE__ */ jsx(
1787
+ Pressable,
1788
+ {
1789
+ onPress: () => {
1790
+ void send(label);
1791
+ },
1792
+ accessibilityRole: "button",
1793
+ style: [styles$2.chip, { borderColor: theme.accent, borderRadius: theme.radius }],
1794
+ hitSlop: 4,
1795
+ children: /* @__PURE__ */ jsx(Text, { style: { color: theme.accent, fontSize: theme.fontSize - 1 }, children: label })
1796
+ },
1797
+ label
1798
+ ))
1799
+ ] }) : null,
554
1800
  contentContainerStyle: styles$2.list,
555
1801
  onContentSizeChange: () => {
556
1802
  var _a;
@@ -613,7 +1859,8 @@ function GuideAIChat({
613
1859
  children: /* @__PURE__ */ jsx(Text, { style: { color: theme.textMuted, fontSize: 18 }, children: "🎤" })
614
1860
  }
615
1861
  ) : null
616
- ] })
1862
+ ] }),
1863
+ /* @__PURE__ */ jsx(GuideAIWhiteboard, { theme: overrides })
617
1864
  ]
618
1865
  }
619
1866
  );
@@ -747,6 +1994,17 @@ const styles$2 = StyleSheet.create({
747
1994
  },
748
1995
  send: { width: 34, height: 34, borderRadius: 17, alignItems: "center", justifyContent: "center" },
749
1996
  sendIcon: { fontSize: 17, fontWeight: "700", lineHeight: 20 },
1997
+ footer: {
1998
+ flexDirection: "row",
1999
+ flexWrap: "wrap",
2000
+ gap: 8,
2001
+ paddingTop: 4
2002
+ },
2003
+ chip: {
2004
+ borderWidth: 1,
2005
+ paddingHorizontal: 12,
2006
+ paddingVertical: 7
2007
+ },
750
2008
  mic: {
751
2009
  width: 46,
752
2010
  height: 46,
@@ -1516,6 +2774,7 @@ export {
1516
2774
  GuideAIChat,
1517
2775
  GuideAILauncher,
1518
2776
  GuideAISupportChat,
2777
+ GuideAIWhiteboard,
1519
2778
  Markdown,
1520
2779
  darkTheme,
1521
2780
  lightTheme,