@guideai/react-native 0.3.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -20
- package/dist/GuideAIChat-CxyWFl_o.cjs +2493 -0
- package/dist/GuideAIChat-CxyWFl_o.cjs.map +1 -0
- package/dist/GuideAIChat-DOC4zx-a.js +2494 -0
- package/dist/GuideAIChat-DOC4zx-a.js.map +1 -0
- package/dist/index.cjs +19 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +68 -4
- package/dist/index.mjs +6 -7
- package/dist/index.mjs.map +1 -1
- package/dist/ui.cjs +22 -2029
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.d.ts +257 -4
- package/dist/ui.mjs +14 -2020
- package/dist/ui.mjs.map +1 -1
- package/dist/{setup-CkXajERE.js → useConversations-B_7km_uH.js} +975 -52
- package/dist/useConversations-B_7km_uH.js.map +1 -0
- package/dist/{setup-Bl0ZLz8B.cjs → useConversations-CTbQBTz-.cjs} +974 -51
- package/dist/useConversations-CTbQBTz-.cjs.map +1 -0
- package/dist/voice.cjs +466 -15
- package/dist/voice.cjs.map +1 -1
- package/dist/voice.d.ts +253 -7
- package/dist/voice.mjs +469 -17
- package/dist/voice.mjs.map +1 -1
- package/package.json +15 -10
- package/dist/setup-Bl0ZLz8B.cjs.map +0 -1
- package/dist/setup-CkXajERE.js.map +0 -1
- package/dist/useOnboarding-BAKQq8T_.js +0 -677
- package/dist/useOnboarding-BAKQq8T_.js.map +0 -1
- package/dist/useOnboarding-CFxofFst.cjs +0 -676
- package/dist/useOnboarding-CFxofFst.cjs.map +0 -1
package/dist/ui.cjs
CHANGED
|
@@ -3,2023 +3,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const reactNative = require("react-native");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const Svg = require("react-native-svg");
|
|
9
|
-
function parseInline(text) {
|
|
10
|
-
const spans = [];
|
|
11
|
-
const pattern = /(`[^`]+`)|(\*\*[^*]+\*\*)|(__[^_]+__)|(\*[^*\n]+\*)|(_[^_\n]+_)|(\[[^\]]+\]\([^)]+\))/g;
|
|
12
|
-
let cursor = 0;
|
|
13
|
-
let match;
|
|
14
|
-
while ((match = pattern.exec(text)) !== null) {
|
|
15
|
-
if (match.index > cursor) {
|
|
16
|
-
spans.push({ text: text.slice(cursor, match.index) });
|
|
17
|
-
}
|
|
18
|
-
const token = match[0];
|
|
19
|
-
if (token.startsWith("`")) {
|
|
20
|
-
spans.push({ text: token.slice(1, -1), code: true });
|
|
21
|
-
} else if (token.startsWith("**") || token.startsWith("__")) {
|
|
22
|
-
spans.push({ text: token.slice(2, -2), bold: true });
|
|
23
|
-
} else if (token.startsWith("[")) {
|
|
24
|
-
const split = token.indexOf("](");
|
|
25
|
-
spans.push({
|
|
26
|
-
text: token.slice(1, split),
|
|
27
|
-
href: token.slice(split + 2, -1)
|
|
28
|
-
});
|
|
29
|
-
} else {
|
|
30
|
-
spans.push({ text: token.slice(1, -1), italic: true });
|
|
31
|
-
}
|
|
32
|
-
cursor = match.index + token.length;
|
|
33
|
-
}
|
|
34
|
-
if (cursor < text.length) spans.push({ text: text.slice(cursor) });
|
|
35
|
-
return spans.length ? spans : [{ text }];
|
|
36
|
-
}
|
|
37
|
-
function tableCells(line) {
|
|
38
|
-
return line.replace(/^\s*\|/, "").replace(/\|\s*$/, "").split("|").map((cell) => parseInline(cell.trim()));
|
|
39
|
-
}
|
|
40
|
-
const TABLE_DIVIDER = /^\s*\|?[\s:-]*-[\s|:-]*\|?\s*$/;
|
|
41
|
-
function parseMarkdown(source) {
|
|
42
|
-
var _a, _b;
|
|
43
|
-
const blocks = [];
|
|
44
|
-
const lines = source.replace(/\r\n/g, "\n").split("\n");
|
|
45
|
-
let index = 0;
|
|
46
|
-
while (index < lines.length) {
|
|
47
|
-
const line = lines[index];
|
|
48
|
-
const trimmed = line.trim();
|
|
49
|
-
if (!trimmed) {
|
|
50
|
-
index += 1;
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
const fence = /^```(\w+)?/.exec(trimmed);
|
|
54
|
-
if (fence) {
|
|
55
|
-
const language = fence[1];
|
|
56
|
-
const body = [];
|
|
57
|
-
index += 1;
|
|
58
|
-
while (index < lines.length && !lines[index].trim().startsWith("```")) {
|
|
59
|
-
body.push(lines[index]);
|
|
60
|
-
index += 1;
|
|
61
|
-
}
|
|
62
|
-
index += 1;
|
|
63
|
-
blocks.push({ type: "code", text: body.join("\n"), language });
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (trimmed.includes("|") && index + 1 < lines.length && TABLE_DIVIDER.test(lines[index + 1])) {
|
|
67
|
-
const header = tableCells(trimmed);
|
|
68
|
-
const rows = [];
|
|
69
|
-
index += 2;
|
|
70
|
-
while (index < lines.length && lines[index].includes("|") && lines[index].trim()) {
|
|
71
|
-
rows.push(tableCells(lines[index]));
|
|
72
|
-
index += 1;
|
|
73
|
-
}
|
|
74
|
-
blocks.push({ type: "table", header, rows });
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
const heading = /^(#{1,6})\s+(.*)$/.exec(trimmed);
|
|
78
|
-
if (heading) {
|
|
79
|
-
const level = Math.min(heading[1].length, 3);
|
|
80
|
-
blocks.push({ type: "heading", level, spans: parseInline(heading[2]) });
|
|
81
|
-
index += 1;
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
if (/^(\*\s*){3,}$|^(-\s*){3,}$|^(_\s*){3,}$/.test(trimmed)) {
|
|
85
|
-
blocks.push({ type: "rule" });
|
|
86
|
-
index += 1;
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
const quote = /^>\s?(.*)$/.exec(trimmed);
|
|
90
|
-
if (quote) {
|
|
91
|
-
blocks.push({ type: "quote", spans: parseInline(quote[1]) });
|
|
92
|
-
index += 1;
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
const indent = (_b = (_a = /^(\s*)/.exec(line)) == null ? void 0 : _a[1].length) != null ? _b : 0;
|
|
96
|
-
const depth = Math.floor(indent / 2);
|
|
97
|
-
const bullet = /^[-*+]\s+(.*)$/.exec(trimmed);
|
|
98
|
-
if (bullet) {
|
|
99
|
-
blocks.push({ type: "bullet", spans: parseInline(bullet[1]), depth });
|
|
100
|
-
index += 1;
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
const ordered = /^(\d+)[.)]\s+(.*)$/.exec(trimmed);
|
|
104
|
-
if (ordered) {
|
|
105
|
-
blocks.push({
|
|
106
|
-
type: "ordered",
|
|
107
|
-
spans: parseInline(ordered[2]),
|
|
108
|
-
index: Number(ordered[1]),
|
|
109
|
-
depth
|
|
110
|
-
});
|
|
111
|
-
index += 1;
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
const paragraph = [trimmed];
|
|
115
|
-
index += 1;
|
|
116
|
-
while (index < lines.length) {
|
|
117
|
-
const nextLine = lines[index].trim();
|
|
118
|
-
if (!nextLine || /^(#{1,6})\s/.test(nextLine) || /^[-*+]\s/.test(nextLine) || /^\d+[.)]\s/.test(nextLine) || nextLine.startsWith("```") || nextLine.startsWith(">") || nextLine.includes("|")) break;
|
|
119
|
-
paragraph.push(nextLine);
|
|
120
|
-
index += 1;
|
|
121
|
-
}
|
|
122
|
-
blocks.push({ type: "paragraph", spans: parseInline(paragraph.join(" ")) });
|
|
123
|
-
}
|
|
124
|
-
return blocks;
|
|
125
|
-
}
|
|
126
|
-
function Spans({ spans, style, accentColor }) {
|
|
127
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: spans.map((span, index) => {
|
|
128
|
-
if (span.href) {
|
|
129
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
130
|
-
reactNative.Text,
|
|
131
|
-
{
|
|
132
|
-
style: [style, { color: accentColor, textDecorationLine: "underline" }],
|
|
133
|
-
onPress: () => {
|
|
134
|
-
void reactNative.Linking.openURL(span.href);
|
|
135
|
-
},
|
|
136
|
-
accessibilityRole: "link",
|
|
137
|
-
children: span.text
|
|
138
|
-
},
|
|
139
|
-
index
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
143
|
-
reactNative.Text,
|
|
144
|
-
{
|
|
145
|
-
style: [
|
|
146
|
-
style,
|
|
147
|
-
span.bold ? styles$4.bold : null,
|
|
148
|
-
span.italic ? styles$4.italic : null,
|
|
149
|
-
span.code ? styles$4.inlineCode : null
|
|
150
|
-
],
|
|
151
|
-
children: span.text
|
|
152
|
-
},
|
|
153
|
-
index
|
|
154
|
-
);
|
|
155
|
-
}) });
|
|
156
|
-
}
|
|
157
|
-
function Markdown({
|
|
158
|
-
children,
|
|
159
|
-
color = "#0f172a",
|
|
160
|
-
accentColor = "#2563eb",
|
|
161
|
-
fontSize = 15
|
|
162
|
-
}) {
|
|
163
|
-
const blocks = React.useMemo(() => parseMarkdown(children), [children]);
|
|
164
|
-
const body = { color, fontSize, lineHeight: fontSize * 1.45 };
|
|
165
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles$4.container, children: blocks.map((block, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
166
|
-
Block,
|
|
167
|
-
{
|
|
168
|
-
block,
|
|
169
|
-
body,
|
|
170
|
-
color,
|
|
171
|
-
accentColor,
|
|
172
|
-
fontSize
|
|
173
|
-
},
|
|
174
|
-
index
|
|
175
|
-
)) });
|
|
176
|
-
}
|
|
177
|
-
function Block({ block, body, color, accentColor, fontSize }) {
|
|
178
|
-
switch (block.type) {
|
|
179
|
-
case "heading": {
|
|
180
|
-
const sizes = { 1: fontSize + 6, 2: fontSize + 3, 3: fontSize + 1 };
|
|
181
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles$4.heading, { color, fontSize: sizes[block.level] }], children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
182
|
-
Spans,
|
|
183
|
-
{
|
|
184
|
-
spans: block.spans,
|
|
185
|
-
accentColor,
|
|
186
|
-
style: { color, fontSize: sizes[block.level], fontWeight: "700" }
|
|
187
|
-
}
|
|
188
|
-
) });
|
|
189
|
-
}
|
|
190
|
-
case "paragraph":
|
|
191
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles$4.paragraph, children: /* @__PURE__ */ jsxRuntime.jsx(Spans, { spans: block.spans, style: body, accentColor }) });
|
|
192
|
-
case "bullet":
|
|
193
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [styles$4.listRow, { marginLeft: block.depth * 14 }], children: [
|
|
194
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [body, { color: accentColor }], children: "•" }),
|
|
195
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles$4.listText, children: /* @__PURE__ */ jsxRuntime.jsx(Spans, { spans: block.spans, style: body, accentColor }) })
|
|
196
|
-
] });
|
|
197
|
-
case "ordered":
|
|
198
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [styles$4.listRow, { marginLeft: block.depth * 14 }], children: [
|
|
199
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.Text, { style: [body, { color: accentColor, fontVariant: ["tabular-nums"] }], children: [
|
|
200
|
-
block.index,
|
|
201
|
-
"."
|
|
202
|
-
] }),
|
|
203
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles$4.listText, children: /* @__PURE__ */ jsxRuntime.jsx(Spans, { spans: block.spans, style: body, accentColor }) })
|
|
204
|
-
] });
|
|
205
|
-
case "code":
|
|
206
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles$4.codeBlock, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles$4.codeText, { fontSize: fontSize - 2 }], children: block.text }) });
|
|
207
|
-
case "quote":
|
|
208
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles$4.quote, { borderLeftColor: accentColor }], children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
209
|
-
Spans,
|
|
210
|
-
{
|
|
211
|
-
spans: block.spans,
|
|
212
|
-
accentColor,
|
|
213
|
-
style: { ...body, color: "#475569", fontStyle: "italic" }
|
|
214
|
-
}
|
|
215
|
-
) }) });
|
|
216
|
-
case "rule":
|
|
217
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles$4.rule });
|
|
218
|
-
case "table": {
|
|
219
|
-
const columns = Math.max(block.header.length, ...block.rows.map((r) => r.length), 1);
|
|
220
|
-
const scrolls = columns > 3;
|
|
221
|
-
const table = /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [styles$4.table, scrolls ? { minWidth: columns * 116 } : null], children: [
|
|
222
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles$4.tableRow, styles$4.tableHeaderRow], children: block.header.map((cell, index) => /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles$4.tableCell, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
223
|
-
Spans,
|
|
224
|
-
{
|
|
225
|
-
spans: cell,
|
|
226
|
-
accentColor,
|
|
227
|
-
style: { ...body, fontWeight: "700", fontSize: fontSize - 1 }
|
|
228
|
-
}
|
|
229
|
-
) }) }, index)) }),
|
|
230
|
-
block.rows.map((row, rowIndex) => /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles$4.tableRow, children: row.map((cell, cellIndex) => /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles$4.tableCell, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
231
|
-
Spans,
|
|
232
|
-
{
|
|
233
|
-
spans: cell,
|
|
234
|
-
accentColor,
|
|
235
|
-
style: { ...body, fontSize: fontSize - 1 }
|
|
236
|
-
}
|
|
237
|
-
) }) }, cellIndex)) }, rowIndex))
|
|
238
|
-
] });
|
|
239
|
-
return scrolls ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
240
|
-
reactNative.ScrollView,
|
|
241
|
-
{
|
|
242
|
-
horizontal: true,
|
|
243
|
-
showsHorizontalScrollIndicator: false,
|
|
244
|
-
alwaysBounceHorizontal: false,
|
|
245
|
-
children: table
|
|
246
|
-
}
|
|
247
|
-
) : table;
|
|
248
|
-
}
|
|
249
|
-
default:
|
|
250
|
-
return null;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
const mono = { fontFamily: "Menlo" };
|
|
254
|
-
const styles$4 = reactNative.StyleSheet.create({
|
|
255
|
-
container: { gap: 6 },
|
|
256
|
-
heading: { fontWeight: "700", marginTop: 4 },
|
|
257
|
-
paragraph: {},
|
|
258
|
-
listRow: { flexDirection: "row", gap: 8, alignItems: "flex-start" },
|
|
259
|
-
listText: { flex: 1 },
|
|
260
|
-
bold: { fontWeight: "700" },
|
|
261
|
-
italic: { fontStyle: "italic" },
|
|
262
|
-
inlineCode: {
|
|
263
|
-
...mono,
|
|
264
|
-
backgroundColor: "rgba(100,116,139,0.14)",
|
|
265
|
-
color: "#0f172a"
|
|
266
|
-
},
|
|
267
|
-
codeBlock: {
|
|
268
|
-
backgroundColor: "#0f172a",
|
|
269
|
-
borderRadius: 10,
|
|
270
|
-
padding: 12,
|
|
271
|
-
marginVertical: 2
|
|
272
|
-
},
|
|
273
|
-
codeText: { ...mono, color: "#e2e8f0" },
|
|
274
|
-
quote: { borderLeftWidth: 3, paddingLeft: 10, paddingVertical: 2 },
|
|
275
|
-
rule: { height: reactNative.StyleSheet.hairlineWidth, backgroundColor: "#cbd5e1", marginVertical: 6 },
|
|
276
|
-
table: {
|
|
277
|
-
borderWidth: reactNative.StyleSheet.hairlineWidth,
|
|
278
|
-
borderColor: "#cbd5e1",
|
|
279
|
-
borderRadius: 8,
|
|
280
|
-
overflow: "hidden"
|
|
281
|
-
},
|
|
282
|
-
tableRow: {
|
|
283
|
-
flexDirection: "row",
|
|
284
|
-
borderBottomWidth: reactNative.StyleSheet.hairlineWidth,
|
|
285
|
-
borderBottomColor: "#e2e8f0"
|
|
286
|
-
},
|
|
287
|
-
tableHeaderRow: { backgroundColor: "rgba(100,116,139,0.10)" },
|
|
288
|
-
tableCell: { flex: 1, padding: 8 }
|
|
289
|
-
});
|
|
290
|
-
const STEP_GAP_MS = 450;
|
|
291
|
-
function readTime(text) {
|
|
292
|
-
const words = text.trim().split(/\s+/).filter(Boolean).length;
|
|
293
|
-
return Math.min(6500, Math.max(1500, words * 280));
|
|
294
|
-
}
|
|
295
|
-
const SPEEDS = [0.75, 1, 1.5, 2];
|
|
296
|
-
class Player {
|
|
297
|
-
constructor(steps, hooks, reducedMotion = false) {
|
|
298
|
-
var _a, _b, _c;
|
|
299
|
-
this.steps = steps;
|
|
300
|
-
this.hooks = hooks;
|
|
301
|
-
this.reducedMotion = reducedMotion;
|
|
302
|
-
this.state = "idle";
|
|
303
|
-
this.speed = 1;
|
|
304
|
-
this.stepIndex = -1;
|
|
305
|
-
this.opIndex = 0;
|
|
306
|
-
this.opElapsed = 0;
|
|
307
|
-
this.stepElapsed = 0;
|
|
308
|
-
this.holdElapsed = 0;
|
|
309
|
-
this.spoken = null;
|
|
310
|
-
this.narrationToken = 0;
|
|
311
|
-
this.frame = null;
|
|
312
|
-
this.last = 0;
|
|
313
|
-
this.requestFrame = (_a = hooks.requestFrame) != null ? _a : ((cb) => requestAnimationFrame(cb));
|
|
314
|
-
this.cancelFrame = (_b = hooks.cancelFrame) != null ? _b : ((id) => cancelAnimationFrame(id));
|
|
315
|
-
this.now = (_c = hooks.now) != null ? _c : (() => performance.now());
|
|
316
|
-
}
|
|
317
|
-
get current() {
|
|
318
|
-
return this.stepIndex;
|
|
319
|
-
}
|
|
320
|
-
get status() {
|
|
321
|
-
return this.state;
|
|
322
|
-
}
|
|
323
|
-
get rate() {
|
|
324
|
-
return this.speed;
|
|
325
|
-
}
|
|
326
|
-
setSpeed(speed) {
|
|
327
|
-
this.speed = Math.min(3, Math.max(0.25, speed));
|
|
328
|
-
}
|
|
329
|
-
play() {
|
|
330
|
-
if (this.state === "playing") return;
|
|
331
|
-
if (this.state === "done" || this.state === "idle") {
|
|
332
|
-
this.restart();
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
this.setState("playing");
|
|
336
|
-
this.schedule();
|
|
337
|
-
}
|
|
338
|
-
pause() {
|
|
339
|
-
if (this.state !== "playing") return;
|
|
340
|
-
this.setState("paused");
|
|
341
|
-
this.unschedule();
|
|
342
|
-
if (this.spoken === null) {
|
|
343
|
-
this.narrationToken += 1;
|
|
344
|
-
this.hooks.stopNarration();
|
|
345
|
-
this.spoken = false;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
replay() {
|
|
349
|
-
this.restart();
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Jump to step *index*, as a scrubber does: the board is rebuilt with every
|
|
353
|
-
* step before it already drawn, then playback carries on from there.
|
|
354
|
-
*/
|
|
355
|
-
seek(index) {
|
|
356
|
-
const target = Math.max(0, Math.min(this.steps.length - 1, Math.floor(index)));
|
|
357
|
-
this.unschedule();
|
|
358
|
-
this.narrationToken += 1;
|
|
359
|
-
this.hooks.stopNarration();
|
|
360
|
-
this.hooks.reset();
|
|
361
|
-
for (let i = 0; i < target; i += 1) {
|
|
362
|
-
const step = this.steps[i];
|
|
363
|
-
step.enter();
|
|
364
|
-
for (const op of step.ops) op.run(1);
|
|
365
|
-
}
|
|
366
|
-
this.stepIndex = -1;
|
|
367
|
-
this.setState("playing");
|
|
368
|
-
this.enterStep(target);
|
|
369
|
-
this.schedule();
|
|
370
|
-
}
|
|
371
|
-
/** Stop for good: no frames, no voice. */
|
|
372
|
-
destroy() {
|
|
373
|
-
this.unschedule();
|
|
374
|
-
this.narrationToken += 1;
|
|
375
|
-
this.hooks.stopNarration();
|
|
376
|
-
this.state = "done";
|
|
377
|
-
}
|
|
378
|
-
restart() {
|
|
379
|
-
this.unschedule();
|
|
380
|
-
this.narrationToken += 1;
|
|
381
|
-
this.hooks.stopNarration();
|
|
382
|
-
this.hooks.reset();
|
|
383
|
-
this.stepIndex = -1;
|
|
384
|
-
this.setState("playing");
|
|
385
|
-
this.enterStep(0);
|
|
386
|
-
this.schedule();
|
|
387
|
-
}
|
|
388
|
-
setState(state) {
|
|
389
|
-
var _a, _b;
|
|
390
|
-
if (this.state === state) return;
|
|
391
|
-
this.state = state;
|
|
392
|
-
(_b = (_a = this.hooks).onState) == null ? void 0 : _b.call(_a, state);
|
|
393
|
-
}
|
|
394
|
-
enterStep(index) {
|
|
395
|
-
var _a, _b;
|
|
396
|
-
const step = this.steps[index];
|
|
397
|
-
if (!step) {
|
|
398
|
-
this.unschedule();
|
|
399
|
-
this.setState("done");
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
this.stepIndex = index;
|
|
403
|
-
this.opIndex = 0;
|
|
404
|
-
this.opElapsed = 0;
|
|
405
|
-
this.stepElapsed = 0;
|
|
406
|
-
this.holdElapsed = 0;
|
|
407
|
-
this.spoken = null;
|
|
408
|
-
step.enter();
|
|
409
|
-
(_b = (_a = this.hooks).onStep) == null ? void 0 : _b.call(_a, index, step);
|
|
410
|
-
const token = ++this.narrationToken;
|
|
411
|
-
this.hooks.narrate(step.say).then(
|
|
412
|
-
(said) => {
|
|
413
|
-
if (token === this.narrationToken) this.spoken = said;
|
|
414
|
-
},
|
|
415
|
-
() => {
|
|
416
|
-
if (token === this.narrationToken) this.spoken = false;
|
|
417
|
-
}
|
|
418
|
-
);
|
|
419
|
-
if (this.reducedMotion) {
|
|
420
|
-
for (const op of step.ops) op.run(1);
|
|
421
|
-
this.opIndex = step.ops.length;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
schedule() {
|
|
425
|
-
if (this.frame !== null || this.state !== "playing") return;
|
|
426
|
-
this.last = this.now();
|
|
427
|
-
this.frame = this.requestFrame((t) => this.tick(t));
|
|
428
|
-
}
|
|
429
|
-
unschedule() {
|
|
430
|
-
if (this.frame !== null) this.cancelFrame(this.frame);
|
|
431
|
-
this.frame = null;
|
|
432
|
-
}
|
|
433
|
-
/** One frame. Public so tests can drive time by hand. */
|
|
434
|
-
tick(now) {
|
|
435
|
-
this.frame = null;
|
|
436
|
-
if (this.state !== "playing") return;
|
|
437
|
-
const dt = Math.max(0, Math.min(100, now - this.last)) * this.speed;
|
|
438
|
-
this.last = now;
|
|
439
|
-
this.advance(dt);
|
|
440
|
-
if (this.state === "playing") this.frame = this.requestFrame((t) => this.tick(t));
|
|
441
|
-
}
|
|
442
|
-
advance(dt) {
|
|
443
|
-
const step = this.steps[this.stepIndex];
|
|
444
|
-
if (!step) return;
|
|
445
|
-
this.stepElapsed += dt;
|
|
446
|
-
let left = dt;
|
|
447
|
-
while (this.opIndex < step.ops.length && left > 0) {
|
|
448
|
-
const op = step.ops[this.opIndex];
|
|
449
|
-
const remaining = op.duration - this.opElapsed;
|
|
450
|
-
if (op.duration <= 0 || left >= remaining) {
|
|
451
|
-
op.run(1);
|
|
452
|
-
left -= Math.max(0, remaining);
|
|
453
|
-
this.opIndex += 1;
|
|
454
|
-
this.opElapsed = 0;
|
|
455
|
-
} else {
|
|
456
|
-
this.opElapsed += left;
|
|
457
|
-
op.run(this.opElapsed / op.duration);
|
|
458
|
-
left = 0;
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
while (this.opIndex < step.ops.length && step.ops[this.opIndex].duration <= 0) {
|
|
462
|
-
step.ops[this.opIndex].run(1);
|
|
463
|
-
this.opIndex += 1;
|
|
464
|
-
}
|
|
465
|
-
if (this.opIndex < step.ops.length || this.spoken === null) return;
|
|
466
|
-
const hold = this.spoken ? 0 : readTime(step.say);
|
|
467
|
-
if (this.stepElapsed < hold) return;
|
|
468
|
-
this.holdElapsed += dt;
|
|
469
|
-
if (this.holdElapsed < STEP_GAP_MS) return;
|
|
470
|
-
this.enterStep(this.stepIndex + 1);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
const STORYBOARD_ICON_STROKES = {
|
|
474
|
-
phone: [
|
|
475
|
-
"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",
|
|
476
|
-
"M 43 13 L 57 13",
|
|
477
|
-
"M 41 88 L 59 88"
|
|
478
|
-
],
|
|
479
|
-
screen: [
|
|
480
|
-
"M 8 18 L 92 18 L 92 66 L 8 66 Z",
|
|
481
|
-
"M 42 66 L 38 84 L 62 84 L 58 66",
|
|
482
|
-
"M 30 84 L 70 84"
|
|
483
|
-
],
|
|
484
|
-
window: [
|
|
485
|
-
"M 6 16 L 94 16 L 94 84 L 6 84 Z",
|
|
486
|
-
"M 6 32 L 94 32",
|
|
487
|
-
"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"
|
|
488
|
-
],
|
|
489
|
-
video: [
|
|
490
|
-
"M 8 20 L 92 20 L 92 80 L 8 80 Z",
|
|
491
|
-
"M 20 20 L 20 80 M 80 20 L 80 80",
|
|
492
|
-
"M 42 40 L 64 50 L 42 60 Z"
|
|
493
|
-
],
|
|
494
|
-
play: [
|
|
495
|
-
"M 8 50 a 42 42 0 1 0 84 0 a 42 42 0 1 0 -84 0",
|
|
496
|
-
"M 40 32 L 70 50 L 40 68 Z"
|
|
497
|
-
],
|
|
498
|
-
input: [
|
|
499
|
-
"M 6 36 L 94 36 L 94 64 L 6 64 Z",
|
|
500
|
-
"M 18 43 L 18 57",
|
|
501
|
-
"M 28 50 L 66 50"
|
|
502
|
-
],
|
|
503
|
-
cursor: [
|
|
504
|
-
"M 24 12 L 24 74 L 39 60 L 49 82 L 60 77 L 50 56 L 70 55 Z"
|
|
505
|
-
],
|
|
506
|
-
document: [
|
|
507
|
-
"M 24 8 L 62 8 L 78 26 L 78 92 L 24 92 Z",
|
|
508
|
-
"M 62 8 L 62 26 L 78 26",
|
|
509
|
-
"M 36 44 L 66 44 M 36 58 L 66 58 M 36 72 L 54 72"
|
|
510
|
-
],
|
|
511
|
-
image: [
|
|
512
|
-
"M 10 20 L 90 20 L 90 80 L 10 80 Z",
|
|
513
|
-
"M 10 68 L 36 44 L 56 64 L 68 54 L 90 74",
|
|
514
|
-
"M 61 34 a 7 7 0 1 0 14 0 a 7 7 0 1 0 -14 0"
|
|
515
|
-
],
|
|
516
|
-
gear: [
|
|
517
|
-
"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",
|
|
518
|
-
"M 39 50 a 11 11 0 1 0 22 0 a 11 11 0 1 0 -22 0"
|
|
519
|
-
],
|
|
520
|
-
cloud: [
|
|
521
|
-
"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"
|
|
522
|
-
],
|
|
523
|
-
database: [
|
|
524
|
-
"M 18 24 a 32 10 0 1 0 64 0 a 32 10 0 1 0 -64 0",
|
|
525
|
-
"M 18 24 L 18 76 Q 18 88 50 88 Q 82 88 82 76 L 82 24",
|
|
526
|
-
"M 18 50 Q 18 62 50 62 Q 82 62 82 50"
|
|
527
|
-
],
|
|
528
|
-
user: [
|
|
529
|
-
"M 33 31 a 17 17 0 1 0 34 0 a 17 17 0 1 0 -34 0",
|
|
530
|
-
"M 16 88 Q 16 56 50 56 Q 84 56 84 88"
|
|
531
|
-
],
|
|
532
|
-
sparkle: [
|
|
533
|
-
"M 50 6 Q 56 40 90 50 Q 56 60 50 94 Q 44 60 10 50 Q 44 40 50 6 Z"
|
|
534
|
-
],
|
|
535
|
-
check: [
|
|
536
|
-
"M 16 54 L 40 78 L 86 22"
|
|
537
|
-
],
|
|
538
|
-
clock: [
|
|
539
|
-
"M 8 50 a 42 42 0 1 0 84 0 a 42 42 0 1 0 -84 0",
|
|
540
|
-
"M 50 26 L 50 52 L 70 62"
|
|
541
|
-
],
|
|
542
|
-
lock: [
|
|
543
|
-
"M 22 46 L 78 46 L 78 90 L 22 90 Z",
|
|
544
|
-
"M 34 46 L 34 30 Q 34 12 50 12 Q 66 12 66 30 L 66 46",
|
|
545
|
-
"M 50 62 L 50 74"
|
|
546
|
-
],
|
|
547
|
-
chat: [
|
|
548
|
-
"M 10 20 L 90 20 L 90 68 L 46 68 L 26 86 L 28 68 L 10 68 Z",
|
|
549
|
-
"M 28 38 L 72 38 M 28 52 L 60 52"
|
|
550
|
-
],
|
|
551
|
-
cross: [
|
|
552
|
-
"M 22 22 L 78 78",
|
|
553
|
-
"M 78 22 L 22 78"
|
|
554
|
-
],
|
|
555
|
-
server: [
|
|
556
|
-
"M 16 10 L 84 10 L 84 34 L 16 34 Z",
|
|
557
|
-
"M 16 38 L 84 38 L 84 62 L 16 62 Z",
|
|
558
|
-
"M 16 66 L 84 66 L 84 90 L 16 90 Z",
|
|
559
|
-
"M 26 22 L 32 22 M 26 50 L 32 50 M 26 78 L 32 78",
|
|
560
|
-
"M 54 22 L 74 22 M 54 50 L 74 50 M 54 78 L 74 78"
|
|
561
|
-
],
|
|
562
|
-
queue: [
|
|
563
|
-
"M 6 32 L 94 32 M 6 68 L 94 68",
|
|
564
|
-
"M 14 40 L 30 40 L 30 60 L 14 60 Z",
|
|
565
|
-
"M 38 40 L 54 40 L 54 60 L 38 60 Z",
|
|
566
|
-
"M 62 40 L 78 40 L 78 60 L 62 60 Z",
|
|
567
|
-
"M 82 50 L 94 50 M 88 44 L 94 50 L 88 56"
|
|
568
|
-
],
|
|
569
|
-
globe: [
|
|
570
|
-
"M 8 50 a 42 42 0 1 0 84 0 a 42 42 0 1 0 -84 0",
|
|
571
|
-
"M 50 8 Q 22 50 50 92 Q 78 50 50 8",
|
|
572
|
-
"M 8 50 L 92 50",
|
|
573
|
-
"M 16 28 L 84 28 M 16 72 L 84 72"
|
|
574
|
-
],
|
|
575
|
-
balancer: [
|
|
576
|
-
"M 36 8 L 64 8 L 64 30 L 36 30 Z",
|
|
577
|
-
"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",
|
|
578
|
-
"M 8 62 L 28 62 L 28 86 L 8 86 Z",
|
|
579
|
-
"M 40 62 L 60 62 L 60 86 L 40 86 Z",
|
|
580
|
-
"M 72 62 L 92 62 L 92 86 L 72 86 Z"
|
|
581
|
-
],
|
|
582
|
-
cache: [
|
|
583
|
-
"M 58 6 L 24 54 L 48 54 L 40 94 L 78 40 L 54 40 Z"
|
|
584
|
-
],
|
|
585
|
-
container: [
|
|
586
|
-
"M 50 8 L 88 28 L 88 72 L 50 92 L 12 72 L 12 28 Z",
|
|
587
|
-
"M 12 28 L 50 48 L 88 28",
|
|
588
|
-
"M 50 48 L 50 92"
|
|
589
|
-
]
|
|
590
|
-
};
|
|
591
|
-
function storyboardIconStrokes(icon) {
|
|
592
|
-
var _a;
|
|
593
|
-
return (_a = STORYBOARD_ICON_STROKES[icon]) != null ? _a : [];
|
|
594
|
-
}
|
|
595
|
-
const SHEET_W$1 = 1600;
|
|
596
|
-
const SHEET_H$1 = 1e3;
|
|
597
|
-
const sx = (x) => x * (SHEET_W$1 / 160);
|
|
598
|
-
const sy = (y) => y * (SHEET_H$1 / 100);
|
|
599
|
-
function seeded(seed) {
|
|
600
|
-
let s = seed >>> 0 || 1;
|
|
601
|
-
return () => {
|
|
602
|
-
s ^= s << 13;
|
|
603
|
-
s ^= s >>> 17;
|
|
604
|
-
s ^= s << 5;
|
|
605
|
-
return (s >>> 0) % 1e4 / 1e4;
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
function strokeLength(stroke) {
|
|
609
|
-
let length = 0;
|
|
610
|
-
for (let i = 1; i < stroke.length; i += 1) {
|
|
611
|
-
length += Math.hypot(stroke[i].x - stroke[i - 1].x, stroke[i].y - stroke[i - 1].y);
|
|
612
|
-
}
|
|
613
|
-
return length;
|
|
614
|
-
}
|
|
615
|
-
function totalLength(strokes) {
|
|
616
|
-
return strokes.reduce((sum, s) => sum + strokeLength(s), 0);
|
|
617
|
-
}
|
|
618
|
-
function bounds(strokes) {
|
|
619
|
-
let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
|
|
620
|
-
for (const s of strokes) for (const p of s) {
|
|
621
|
-
x0 = Math.min(x0, p.x);
|
|
622
|
-
y0 = Math.min(y0, p.y);
|
|
623
|
-
x1 = Math.max(x1, p.x);
|
|
624
|
-
y1 = Math.max(y1, p.y);
|
|
625
|
-
}
|
|
626
|
-
return Number.isFinite(x0) ? { x0, y0, x1, y1 } : null;
|
|
627
|
-
}
|
|
628
|
-
function handLine(a, b, rand, steps = 14) {
|
|
629
|
-
const length = Math.hypot(b.x - a.x, b.y - a.y) || 1;
|
|
630
|
-
const nx = -(b.y - a.y) / length;
|
|
631
|
-
const ny = (b.x - a.x) / length;
|
|
632
|
-
const bow = (rand() - 0.5) * Math.min(18, length * 0.04);
|
|
633
|
-
const out = [];
|
|
634
|
-
for (let i = 0; i <= steps; i += 1) {
|
|
635
|
-
const t = i / steps;
|
|
636
|
-
const lift = Math.sin(Math.PI * t) * bow + (rand() - 0.5) * 1.6;
|
|
637
|
-
out.push({ x: a.x + (b.x - a.x) * t + nx * lift, y: a.y + (b.y - a.y) * t + ny * lift });
|
|
638
|
-
}
|
|
639
|
-
return out;
|
|
640
|
-
}
|
|
641
|
-
function handEllipse(b, rand) {
|
|
642
|
-
const cx = sx(b[0] + b[2] / 2);
|
|
643
|
-
const cy = sy(b[1] + b[3] / 2);
|
|
644
|
-
const rx = sx(b[2]) / 2 + 8;
|
|
645
|
-
const ry = sy(b[3]) / 2 + 8;
|
|
646
|
-
const start = -Math.PI * (0.55 + rand() * 0.2);
|
|
647
|
-
const sweep = Math.PI * 2 * (1.06 + rand() * 0.05);
|
|
648
|
-
const out = [];
|
|
649
|
-
const n = 48;
|
|
650
|
-
for (let i = 0; i <= n; i += 1) {
|
|
651
|
-
const t = i / n;
|
|
652
|
-
const a = start + sweep * t;
|
|
653
|
-
const grow = 1 + (t - 0.5) * 0.06 + (rand() - 0.5) * 0.012;
|
|
654
|
-
out.push({ x: cx + Math.cos(a) * rx * grow, y: cy + Math.sin(a) * ry * grow });
|
|
655
|
-
}
|
|
656
|
-
return out;
|
|
657
|
-
}
|
|
658
|
-
function smooth(points, per = 8) {
|
|
659
|
-
if (points.length < 3) return points;
|
|
660
|
-
const out = [];
|
|
661
|
-
for (let i = 0; i < points.length - 1; i += 1) {
|
|
662
|
-
const p0 = points[Math.max(0, i - 1)];
|
|
663
|
-
const p1 = points[i];
|
|
664
|
-
const p2 = points[i + 1];
|
|
665
|
-
const p3 = points[Math.min(points.length - 1, i + 2)];
|
|
666
|
-
for (let j = 0; j < per; j += 1) {
|
|
667
|
-
const t = j / per;
|
|
668
|
-
const t2 = t * t;
|
|
669
|
-
const t3 = t2 * t;
|
|
670
|
-
out.push({
|
|
671
|
-
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),
|
|
672
|
-
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)
|
|
673
|
-
});
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
out.push(points[points.length - 1]);
|
|
677
|
-
return out;
|
|
678
|
-
}
|
|
679
|
-
function arrowHead(from, to, rand) {
|
|
680
|
-
const angle = Math.atan2(to.y - from.y, to.x - from.x);
|
|
681
|
-
const size = 26 + rand() * 6;
|
|
682
|
-
const spread = 0.45;
|
|
683
|
-
return [
|
|
684
|
-
{ x: to.x - size * Math.cos(angle - spread), y: to.y - size * Math.sin(angle - spread) },
|
|
685
|
-
to,
|
|
686
|
-
{ x: to.x - size * Math.cos(angle + spread), y: to.y - size * Math.sin(angle + spread) }
|
|
687
|
-
];
|
|
688
|
-
}
|
|
689
|
-
const corner = (b) => {
|
|
690
|
-
const x0 = sx(b[0]), y0 = sy(b[1]), x1 = sx(b[0] + b[2]), y1 = sy(b[1] + b[3]);
|
|
691
|
-
return [{ x: x0, y: y0 }, { x: x1, y: y0 }, { x: x1, y: y1 }, { x: x0, y: y1 }];
|
|
692
|
-
};
|
|
693
|
-
function handPoly(points, closed, rand) {
|
|
694
|
-
const corners = closed ? [...points, points[0]] : points;
|
|
695
|
-
const out = [];
|
|
696
|
-
for (let i = 1; i < corners.length; i += 1) {
|
|
697
|
-
const length = Math.hypot(corners[i].x - corners[i - 1].x, corners[i].y - corners[i - 1].y);
|
|
698
|
-
const segment = handLine(corners[i - 1], corners[i], rand, Math.max(6, Math.min(24, Math.round(length / 30))));
|
|
699
|
-
out.push(...i === 1 ? segment : segment.slice(1));
|
|
700
|
-
}
|
|
701
|
-
return out;
|
|
702
|
-
}
|
|
703
|
-
function handOval(b, rand) {
|
|
704
|
-
const cx = sx(b[0] + b[2] / 2);
|
|
705
|
-
const cy = sy(b[1] + b[3] / 2);
|
|
706
|
-
const rx = sx(b[2]) / 2;
|
|
707
|
-
const ry = sy(b[3]) / 2;
|
|
708
|
-
const start = -Math.PI * (0.6 + rand() * 0.2);
|
|
709
|
-
const sweep = Math.PI * 2 * (1.03 + rand() * 0.03);
|
|
710
|
-
const n = Math.max(32, Math.round((rx + ry) / 6));
|
|
711
|
-
const out = [];
|
|
712
|
-
for (let i = 0; i <= n; i += 1) {
|
|
713
|
-
const a = start + sweep * i / n;
|
|
714
|
-
const wobble = 1 + (rand() - 0.5) * 0.012;
|
|
715
|
-
out.push({ x: cx + Math.cos(a) * rx * wobble, y: cy + Math.sin(a) * ry * wobble });
|
|
716
|
-
}
|
|
717
|
-
return out;
|
|
718
|
-
}
|
|
719
|
-
const unit = (from, to) => {
|
|
720
|
-
const d = Math.hypot(to.x - from.x, to.y - from.y) || 1;
|
|
721
|
-
return { x: (to.x - from.x) / d, y: (to.y - from.y) / d };
|
|
722
|
-
};
|
|
723
|
-
function rightAngle(a, v, b, rand) {
|
|
724
|
-
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)));
|
|
725
|
-
const ua = unit(v, a);
|
|
726
|
-
const ub = unit(v, b);
|
|
727
|
-
const p1 = { x: v.x + ua.x * size, y: v.y + ua.y * size };
|
|
728
|
-
const p2 = { x: p1.x + ub.x * size, y: p1.y + ub.y * size };
|
|
729
|
-
const p3 = { x: v.x + ub.x * size, y: v.y + ub.y * size };
|
|
730
|
-
return handPoly([p1, p2, p3], false, rand);
|
|
731
|
-
}
|
|
732
|
-
function angleArc(a, v, b, rand) {
|
|
733
|
-
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)));
|
|
734
|
-
const from = Math.atan2(a.y - v.y, a.x - v.x);
|
|
735
|
-
let delta = Math.atan2(b.y - v.y, b.x - v.x) - from;
|
|
736
|
-
while (delta > Math.PI) delta -= 2 * Math.PI;
|
|
737
|
-
while (delta < -Math.PI) delta += 2 * Math.PI;
|
|
738
|
-
const n = 18;
|
|
739
|
-
const out = [];
|
|
740
|
-
for (let i = 0; i <= n; i += 1) {
|
|
741
|
-
const t = from + delta * i / n;
|
|
742
|
-
const rr = r * (1 + (rand() - 0.5) * 0.03);
|
|
743
|
-
out.push({ x: v.x + Math.cos(t) * rr, y: v.y + Math.sin(t) * rr });
|
|
744
|
-
}
|
|
745
|
-
return out;
|
|
746
|
-
}
|
|
747
|
-
function handDot(c) {
|
|
748
|
-
const out = [];
|
|
749
|
-
for (let i = 0; i <= 14; i += 1) {
|
|
750
|
-
const t = i / 14 * Math.PI * 4;
|
|
751
|
-
const r = 7 * (1 - i / 16);
|
|
752
|
-
out.push({ x: c.x + Math.cos(t) * r, y: c.y + Math.sin(t) * r });
|
|
753
|
-
}
|
|
754
|
-
return out;
|
|
755
|
-
}
|
|
756
|
-
function roughen(strokes, seed, amount = 2.2) {
|
|
757
|
-
const rand = seeded(seed);
|
|
758
|
-
return strokes.map((stroke) => {
|
|
759
|
-
let dx = 0;
|
|
760
|
-
let dy = 0;
|
|
761
|
-
return stroke.map((p) => {
|
|
762
|
-
dx = dx * 0.6 + (rand() - 0.5) * amount;
|
|
763
|
-
dy = dy * 0.6 + (rand() - 0.5) * amount;
|
|
764
|
-
return { x: p.x + dx, y: p.y + dy };
|
|
765
|
-
});
|
|
766
|
-
});
|
|
767
|
-
}
|
|
768
|
-
function inkStrokes(kind, geometry, seed) {
|
|
769
|
-
var _a, _b, _c;
|
|
770
|
-
const rand = seeded(seed);
|
|
771
|
-
const p = (q) => ({ x: sx(q[0]), y: sy(q[1]) });
|
|
772
|
-
const pts = (_b = (_a = geometry.pts) == null ? void 0 : _a.map(p)) != null ? _b : [];
|
|
773
|
-
switch (kind) {
|
|
774
|
-
case "line":
|
|
775
|
-
case "arrow": {
|
|
776
|
-
if (!geometry.at || geometry.at.length !== 2 || !geometry.to) return [];
|
|
777
|
-
const a = p(geometry.at);
|
|
778
|
-
const b2 = p(geometry.to);
|
|
779
|
-
const shaft = handLine(a, b2, rand);
|
|
780
|
-
return kind === "arrow" ? [shaft, arrowHead((_c = shaft[shaft.length - 2]) != null ? _c : a, b2, rand)] : [shaft];
|
|
781
|
-
}
|
|
782
|
-
case "free":
|
|
783
|
-
case "curve":
|
|
784
|
-
return pts.length >= 2 ? [smooth(pts)] : [];
|
|
785
|
-
case "poly":
|
|
786
|
-
return pts.length >= 2 ? [handPoly(pts, !!geometry.closed && pts.length > 2, rand)] : [];
|
|
787
|
-
case "corner":
|
|
788
|
-
return pts.length === 3 ? [rightAngle(pts[0], pts[1], pts[2], rand)] : [];
|
|
789
|
-
case "arc":
|
|
790
|
-
return pts.length === 3 ? [angleArc(pts[0], pts[1], pts[2], rand)] : [];
|
|
791
|
-
case "dot":
|
|
792
|
-
return geometry.at && geometry.at.length === 2 ? [handDot(p(geometry.at))] : [];
|
|
793
|
-
}
|
|
794
|
-
const b = geometry.at && geometry.at.length === 4 ? geometry.at : null;
|
|
795
|
-
if (!b) return [];
|
|
796
|
-
const [tl, tr, br, bl] = corner(b);
|
|
797
|
-
switch (kind) {
|
|
798
|
-
case "oval":
|
|
799
|
-
return [handOval(b, rand)];
|
|
800
|
-
case "circle":
|
|
801
|
-
return [handEllipse(b, rand)];
|
|
802
|
-
case "box":
|
|
803
|
-
return [handLine(tl, tr, rand, 10), handLine(tr, br, rand, 8), handLine(br, bl, rand, 10), handLine(bl, tl, rand, 8)];
|
|
804
|
-
case "underline": {
|
|
805
|
-
const y = br.y + 6;
|
|
806
|
-
return [handLine({ x: bl.x - 4, y }, { x: br.x + 4, y: y + (rand() - 0.5) * 6 }, rand, 18)];
|
|
807
|
-
}
|
|
808
|
-
case "cross":
|
|
809
|
-
return [handLine(tl, br, rand, 10), handLine(tr, bl, rand, 10)];
|
|
810
|
-
case "tick": {
|
|
811
|
-
const mid = { x: tl.x + (br.x - tl.x) * 0.38, y: br.y };
|
|
812
|
-
return [[...handLine({ x: tl.x, y: tl.y + (br.y - tl.y) * 0.55 }, mid, rand, 6), ...handLine(mid, tr, rand, 10).slice(1)]];
|
|
813
|
-
}
|
|
814
|
-
case "bracket": {
|
|
815
|
-
const x = tr.x;
|
|
816
|
-
const mid = (tr.y + br.y) / 2;
|
|
817
|
-
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)];
|
|
818
|
-
}
|
|
819
|
-
default:
|
|
820
|
-
return [];
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
const TOKEN = /([MmLlHhVvCcSsQqTtAaZz])|(-?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)/g;
|
|
824
|
-
function flattenPath(d, curveSteps = 8) {
|
|
825
|
-
var _a;
|
|
826
|
-
const tokens = [];
|
|
827
|
-
for (const m of d.matchAll(TOKEN)) tokens.push((_a = m[1]) != null ? _a : Number(m[2]));
|
|
828
|
-
const strokes = [];
|
|
829
|
-
let current = [];
|
|
830
|
-
let x = 0, y = 0, startX = 0, startY = 0;
|
|
831
|
-
let lastCtrl = null;
|
|
832
|
-
let lastQuad = null;
|
|
833
|
-
let cmd = "";
|
|
834
|
-
let i = 0;
|
|
835
|
-
const next = () => {
|
|
836
|
-
const v = tokens[i++];
|
|
837
|
-
return typeof v === "number" ? v : NaN;
|
|
838
|
-
};
|
|
839
|
-
const hasNumber = () => typeof tokens[i] === "number";
|
|
840
|
-
const push = (px, py) => {
|
|
841
|
-
current.push({ x: px, y: py });
|
|
842
|
-
};
|
|
843
|
-
const finish = () => {
|
|
844
|
-
if (current.length > 1) strokes.push(current);
|
|
845
|
-
current = [];
|
|
846
|
-
};
|
|
847
|
-
const cubic = (c1, c2, end) => {
|
|
848
|
-
const sx0 = x, sy0 = y;
|
|
849
|
-
for (let s = 1; s <= curveSteps; s += 1) {
|
|
850
|
-
const t = s / curveSteps;
|
|
851
|
-
const u = 1 - t;
|
|
852
|
-
push(
|
|
853
|
-
u * u * u * sx0 + 3 * u * u * t * c1.x + 3 * u * t * t * c2.x + t * t * t * end.x,
|
|
854
|
-
u * u * u * sy0 + 3 * u * u * t * c1.y + 3 * u * t * t * c2.y + t * t * t * end.y
|
|
855
|
-
);
|
|
856
|
-
}
|
|
857
|
-
x = end.x;
|
|
858
|
-
y = end.y;
|
|
859
|
-
};
|
|
860
|
-
const quad = (c, end) => {
|
|
861
|
-
const sx0 = x, sy0 = y;
|
|
862
|
-
for (let s = 1; s <= curveSteps; s += 1) {
|
|
863
|
-
const t = s / curveSteps;
|
|
864
|
-
const u = 1 - t;
|
|
865
|
-
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);
|
|
866
|
-
}
|
|
867
|
-
x = end.x;
|
|
868
|
-
y = end.y;
|
|
869
|
-
};
|
|
870
|
-
while (i < tokens.length) {
|
|
871
|
-
if (typeof tokens[i] === "string") cmd = tokens[i++];
|
|
872
|
-
else if (!cmd) {
|
|
873
|
-
i += 1;
|
|
874
|
-
continue;
|
|
875
|
-
}
|
|
876
|
-
const rel = cmd === cmd.toLowerCase();
|
|
877
|
-
const ox = rel ? x : 0;
|
|
878
|
-
const oy = rel ? y : 0;
|
|
879
|
-
switch (cmd.toUpperCase()) {
|
|
880
|
-
case "M": {
|
|
881
|
-
finish();
|
|
882
|
-
x = ox + next();
|
|
883
|
-
y = oy + next();
|
|
884
|
-
startX = x;
|
|
885
|
-
startY = y;
|
|
886
|
-
push(x, y);
|
|
887
|
-
cmd = rel ? "l" : "L";
|
|
888
|
-
lastCtrl = lastQuad = null;
|
|
889
|
-
break;
|
|
890
|
-
}
|
|
891
|
-
case "L":
|
|
892
|
-
x = ox + next();
|
|
893
|
-
y = oy + next();
|
|
894
|
-
push(x, y);
|
|
895
|
-
lastCtrl = lastQuad = null;
|
|
896
|
-
break;
|
|
897
|
-
case "H":
|
|
898
|
-
x = ox + next();
|
|
899
|
-
push(x, y);
|
|
900
|
-
lastCtrl = lastQuad = null;
|
|
901
|
-
break;
|
|
902
|
-
case "V":
|
|
903
|
-
y = oy + next();
|
|
904
|
-
push(x, y);
|
|
905
|
-
lastCtrl = lastQuad = null;
|
|
906
|
-
break;
|
|
907
|
-
case "C": {
|
|
908
|
-
const c1 = { x: ox + next(), y: oy + next() };
|
|
909
|
-
const c2 = { x: ox + next(), y: oy + next() };
|
|
910
|
-
const end = { x: ox + next(), y: oy + next() };
|
|
911
|
-
cubic(c1, c2, end);
|
|
912
|
-
lastCtrl = c2;
|
|
913
|
-
lastQuad = null;
|
|
914
|
-
break;
|
|
915
|
-
}
|
|
916
|
-
case "S": {
|
|
917
|
-
const c1 = lastCtrl ? { x: 2 * x - lastCtrl.x, y: 2 * y - lastCtrl.y } : { x, y };
|
|
918
|
-
const c2 = { x: ox + next(), y: oy + next() };
|
|
919
|
-
const end = { x: ox + next(), y: oy + next() };
|
|
920
|
-
cubic(c1, c2, end);
|
|
921
|
-
lastCtrl = c2;
|
|
922
|
-
lastQuad = null;
|
|
923
|
-
break;
|
|
924
|
-
}
|
|
925
|
-
case "Q": {
|
|
926
|
-
const c = { x: ox + next(), y: oy + next() };
|
|
927
|
-
const end = { x: ox + next(), y: oy + next() };
|
|
928
|
-
quad(c, end);
|
|
929
|
-
lastQuad = c;
|
|
930
|
-
lastCtrl = null;
|
|
931
|
-
break;
|
|
932
|
-
}
|
|
933
|
-
case "T": {
|
|
934
|
-
const c = lastQuad ? { x: 2 * x - lastQuad.x, y: 2 * y - lastQuad.y } : { x, y };
|
|
935
|
-
const end = { x: ox + next(), y: oy + next() };
|
|
936
|
-
quad(c, end);
|
|
937
|
-
lastQuad = c;
|
|
938
|
-
lastCtrl = null;
|
|
939
|
-
break;
|
|
940
|
-
}
|
|
941
|
-
case "A": {
|
|
942
|
-
const rx = next(), ry = next(), rotation = next(), large = next(), sweep = next();
|
|
943
|
-
const end = { x: ox + next(), y: oy + next() };
|
|
944
|
-
for (const p of arcPoints({ x, y }, end, rx, ry, rotation, large !== 0, sweep !== 0, curveSteps * 2)) push(p.x, p.y);
|
|
945
|
-
x = end.x;
|
|
946
|
-
y = end.y;
|
|
947
|
-
lastCtrl = lastQuad = null;
|
|
948
|
-
break;
|
|
949
|
-
}
|
|
950
|
-
case "Z":
|
|
951
|
-
push(startX, startY);
|
|
952
|
-
x = startX;
|
|
953
|
-
y = startY;
|
|
954
|
-
finish();
|
|
955
|
-
current = [{ x, y }];
|
|
956
|
-
lastCtrl = lastQuad = null;
|
|
957
|
-
if (hasNumber()) cmd = rel ? "l" : "L";
|
|
958
|
-
else cmd = "";
|
|
959
|
-
break;
|
|
960
|
-
default:
|
|
961
|
-
i += 1;
|
|
962
|
-
}
|
|
963
|
-
if (Number.isNaN(x) || Number.isNaN(y)) return strokes;
|
|
964
|
-
}
|
|
965
|
-
finish();
|
|
966
|
-
return strokes;
|
|
967
|
-
}
|
|
968
|
-
function arcPoints(from, to, rx, ry, degrees, large, sweep, steps) {
|
|
969
|
-
if (!rx || !ry || from.x === to.x && from.y === to.y) return [to];
|
|
970
|
-
const phi = degrees * Math.PI / 180;
|
|
971
|
-
const cos = Math.cos(phi), sin = Math.sin(phi);
|
|
972
|
-
const dx = (from.x - to.x) / 2, dy = (from.y - to.y) / 2;
|
|
973
|
-
const x1 = cos * dx + sin * dy, y1 = -sin * dx + cos * dy;
|
|
974
|
-
let rxa = Math.abs(rx), rya = Math.abs(ry);
|
|
975
|
-
const scale = x1 * x1 / (rxa * rxa) + y1 * y1 / (rya * rya);
|
|
976
|
-
if (scale > 1) {
|
|
977
|
-
rxa *= Math.sqrt(scale);
|
|
978
|
-
rya *= Math.sqrt(scale);
|
|
979
|
-
}
|
|
980
|
-
const num = rxa * rxa * rya * rya - rxa * rxa * y1 * y1 - rya * rya * x1 * x1;
|
|
981
|
-
const den = rxa * rxa * y1 * y1 + rya * rya * x1 * x1;
|
|
982
|
-
const k = (large === sweep ? -1 : 1) * Math.sqrt(Math.max(0, num / den));
|
|
983
|
-
const cx1 = k * rxa * y1 / rya, cy1 = -k * rya * x1 / rxa;
|
|
984
|
-
const cx = cos * cx1 - sin * cy1 + (from.x + to.x) / 2;
|
|
985
|
-
const cy = sin * cx1 + cos * cy1 + (from.y + to.y) / 2;
|
|
986
|
-
const angle = (ux, uy, vx, vy) => Math.atan2(ux * vy - uy * vx, ux * vx + uy * vy);
|
|
987
|
-
const start = angle(1, 0, (x1 - cx1) / rxa, (y1 - cy1) / rya);
|
|
988
|
-
let delta = angle((x1 - cx1) / rxa, (y1 - cy1) / rya, (-x1 - cx1) / rxa, (-y1 - cy1) / rya);
|
|
989
|
-
if (!sweep && delta > 0) delta -= 2 * Math.PI;
|
|
990
|
-
if (sweep && delta < 0) delta += 2 * Math.PI;
|
|
991
|
-
const out = [];
|
|
992
|
-
for (let i = 1; i <= steps; i += 1) {
|
|
993
|
-
const t = start + delta * i / steps;
|
|
994
|
-
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 });
|
|
995
|
-
}
|
|
996
|
-
out[out.length - 1] = to;
|
|
997
|
-
return out;
|
|
998
|
-
}
|
|
999
|
-
function parseTransform(transform) {
|
|
1000
|
-
const t = /translate\(\s*(-?[\d.]+)(?:[\s,]+(-?[\d.]+))?/.exec(transform);
|
|
1001
|
-
const s = /scale\(\s*(-?[\d.]+)(?:[\s,]+(-?[\d.]+))?/.exec(transform);
|
|
1002
|
-
const kx = s ? Number(s[1]) : 1;
|
|
1003
|
-
return {
|
|
1004
|
-
tx: t ? Number(t[1]) : 0,
|
|
1005
|
-
ty: t && t[2] !== void 0 ? Number(t[2]) : 0,
|
|
1006
|
-
kx,
|
|
1007
|
-
ky: s && s[2] !== void 0 ? Number(s[2]) : kx
|
|
1008
|
-
};
|
|
1009
|
-
}
|
|
1010
|
-
function fit(strokes, viewBox, transform, b) {
|
|
1011
|
-
const [vx, vy, vw, vh] = viewBox.split(/[\s,]+/).map(Number);
|
|
1012
|
-
const w = vw > 0 ? vw : 100;
|
|
1013
|
-
const h = vh > 0 ? vh : 100;
|
|
1014
|
-
const { tx, ty, kx, ky } = parseTransform(transform);
|
|
1015
|
-
const bx = sx(b[0]), by = sy(b[1]), bw = sx(b[2]), bh = sy(b[3]);
|
|
1016
|
-
const k = Math.min(bw / w, bh / h);
|
|
1017
|
-
const offX = bx + (bw - w * k) / 2;
|
|
1018
|
-
const offY = by + (bh - h * k) / 2;
|
|
1019
|
-
return strokes.map((stroke) => stroke.map((p) => ({
|
|
1020
|
-
x: offX + (tx + kx * p.x - (vx || 0)) * k,
|
|
1021
|
-
y: offY + (ty + ky * p.y - (vy || 0)) * k
|
|
1022
|
-
})));
|
|
1023
|
-
}
|
|
1024
|
-
function artStrokes(ink, b, seed = 1) {
|
|
1025
|
-
if ("icon" in ink) {
|
|
1026
|
-
const paths = storyboardIconStrokes(ink.icon);
|
|
1027
|
-
return roughen(fit(paths.flatMap((d) => flattenPath(d, 14)), "0 0 100 100", "", b), seed);
|
|
1028
|
-
}
|
|
1029
|
-
return fit(ink.contours.flatMap((d) => flattenPath(d, 6)), ink.view_box, ink.transform, b);
|
|
1030
|
-
}
|
|
1031
|
-
function pointAlong(strokes, length) {
|
|
1032
|
-
let left = length;
|
|
1033
|
-
for (const s of strokes) {
|
|
1034
|
-
for (let i = 1; i < s.length; i += 1) {
|
|
1035
|
-
const seg = Math.hypot(s[i].x - s[i - 1].x, s[i].y - s[i - 1].y);
|
|
1036
|
-
if (left <= seg) {
|
|
1037
|
-
const t = seg ? left / seg : 1;
|
|
1038
|
-
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 };
|
|
1039
|
-
}
|
|
1040
|
-
left -= seg;
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
const last = strokes[strokes.length - 1];
|
|
1044
|
-
return last ? last[last.length - 1] : null;
|
|
1045
|
-
}
|
|
1046
|
-
const INK = { ink: "#1f2937", blue: "#2563eb", red: "#dc2626", green: "#059669" };
|
|
1047
|
-
const MARKER = "rgba(250, 204, 21, 0.42)";
|
|
1048
|
-
const TEXT_SIZE = { s: 2.3, m: 3.1, l: 4.3 };
|
|
1049
|
-
const TRAVEL_MS = 200;
|
|
1050
|
-
class BoardModel {
|
|
1051
|
-
constructor(options) {
|
|
1052
|
-
this.options = options;
|
|
1053
|
-
this.inks = [];
|
|
1054
|
-
this.words = [];
|
|
1055
|
-
this.pen = null;
|
|
1056
|
-
this.caption = "";
|
|
1057
|
-
this.step = -1;
|
|
1058
|
-
this.player = null;
|
|
1059
|
-
this.scene = null;
|
|
1060
|
-
this.nextKey = 1;
|
|
1061
|
-
}
|
|
1062
|
-
snapshot() {
|
|
1063
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1064
|
-
return {
|
|
1065
|
-
inks: this.inks,
|
|
1066
|
-
words: this.words,
|
|
1067
|
-
pen: this.pen,
|
|
1068
|
-
caption: this.caption,
|
|
1069
|
-
step: this.step,
|
|
1070
|
-
steps: (_b = (_a = this.scene) == null ? void 0 : _a.steps.length) != null ? _b : 0,
|
|
1071
|
-
state: (_d = (_c = this.player) == null ? void 0 : _c.status) != null ? _d : "idle",
|
|
1072
|
-
title: (_f = (_e = this.scene) == null ? void 0 : _e.title) != null ? _f : "",
|
|
1073
|
-
sample: (_h = (_g = this.scene) == null ? void 0 : _g.sample) != null ? _h : false
|
|
1074
|
-
};
|
|
1075
|
-
}
|
|
1076
|
-
play(scene) {
|
|
1077
|
-
var _a, _b, _c, _d, _e;
|
|
1078
|
-
this.destroy();
|
|
1079
|
-
this.scene = scene;
|
|
1080
|
-
const steps = scene.steps.map((step, index) => this.buildStep(step, index));
|
|
1081
|
-
this.player = new Player(steps, {
|
|
1082
|
-
narrate: (_a = this.options.narrate) != null ? _a : (async () => false),
|
|
1083
|
-
stopNarration: () => {
|
|
1084
|
-
var _a2, _b2;
|
|
1085
|
-
return (_b2 = (_a2 = this.options).stopNarration) == null ? void 0 : _b2.call(_a2);
|
|
1086
|
-
},
|
|
1087
|
-
reset: () => this.wipe(),
|
|
1088
|
-
onStep: (index, step) => {
|
|
1089
|
-
this.step = index;
|
|
1090
|
-
this.caption = step.say;
|
|
1091
|
-
this.changed();
|
|
1092
|
-
},
|
|
1093
|
-
onState: () => this.changed(),
|
|
1094
|
-
requestFrame: (_b = this.options.requestFrame) != null ? _b : ((cb) => requestAnimationFrame(cb)),
|
|
1095
|
-
cancelFrame: (_c = this.options.cancelFrame) != null ? _c : ((id) => cancelAnimationFrame(id)),
|
|
1096
|
-
now: (_d = this.options.now) != null ? _d : (() => Date.now())
|
|
1097
|
-
}, (_e = this.options.reducedMotion) != null ? _e : false);
|
|
1098
|
-
this.player.play();
|
|
1099
|
-
}
|
|
1100
|
-
/** Pause, or carry on from where it was. */
|
|
1101
|
-
toggle() {
|
|
1102
|
-
if (!this.player) return;
|
|
1103
|
-
if (this.player.status === "playing") this.player.pause();
|
|
1104
|
-
else this.player.play();
|
|
1105
|
-
}
|
|
1106
|
-
replay() {
|
|
1107
|
-
var _a;
|
|
1108
|
-
(_a = this.player) == null ? void 0 : _a.replay();
|
|
1109
|
-
}
|
|
1110
|
-
seek(step) {
|
|
1111
|
-
var _a;
|
|
1112
|
-
(_a = this.player) == null ? void 0 : _a.seek(step);
|
|
1113
|
-
}
|
|
1114
|
-
setSpeed(speed) {
|
|
1115
|
-
var _a;
|
|
1116
|
-
(_a = this.player) == null ? void 0 : _a.setSpeed(speed);
|
|
1117
|
-
}
|
|
1118
|
-
get speed() {
|
|
1119
|
-
var _a, _b;
|
|
1120
|
-
return (_b = (_a = this.player) == null ? void 0 : _a.rate) != null ? _b : 1;
|
|
1121
|
-
}
|
|
1122
|
-
/** Stop for good: no frames, nothing on the board. */
|
|
1123
|
-
destroy() {
|
|
1124
|
-
var _a;
|
|
1125
|
-
(_a = this.player) == null ? void 0 : _a.destroy();
|
|
1126
|
-
this.player = null;
|
|
1127
|
-
this.scene = null;
|
|
1128
|
-
this.wipe();
|
|
1129
|
-
this.step = -1;
|
|
1130
|
-
this.caption = "";
|
|
1131
|
-
}
|
|
1132
|
-
changed() {
|
|
1133
|
-
this.options.onChange();
|
|
1134
|
-
}
|
|
1135
|
-
wipe() {
|
|
1136
|
-
this.inks = [];
|
|
1137
|
-
this.words = [];
|
|
1138
|
-
this.pen = null;
|
|
1139
|
-
this.changed();
|
|
1140
|
-
}
|
|
1141
|
-
// ------------------------------------------------------------- steps → ops
|
|
1142
|
-
buildStep(step, index) {
|
|
1143
|
-
return {
|
|
1144
|
-
say: step.say,
|
|
1145
|
-
enter: () => {
|
|
1146
|
-
if (step.clear) this.wipe();
|
|
1147
|
-
},
|
|
1148
|
-
ops: step.draw.map((item, i) => this.opFor(item, index * 100 + i + 1))
|
|
1149
|
-
};
|
|
1150
|
-
}
|
|
1151
|
-
opFor(item, seed) {
|
|
1152
|
-
var _a;
|
|
1153
|
-
switch (item.kind) {
|
|
1154
|
-
case "ink":
|
|
1155
|
-
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);
|
|
1156
|
-
case "art": {
|
|
1157
|
-
const ink = (_a = this.scene) == null ? void 0 : _a.art[item.art];
|
|
1158
|
-
if (!ink) {
|
|
1159
|
-
const [x, y, w, h] = item.at;
|
|
1160
|
-
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 });
|
|
1161
|
-
}
|
|
1162
|
-
return this.inkOp(item.id, artStrokes(ink, item.at, seed), INK[item.tone], "icon" in ink ? 7 : 4, 1100, 4500, 2.6);
|
|
1163
|
-
}
|
|
1164
|
-
case "text":
|
|
1165
|
-
return this.textOp(item);
|
|
1166
|
-
case "table":
|
|
1167
|
-
return this.tableOp(item);
|
|
1168
|
-
case "mark":
|
|
1169
|
-
return this.markOp(item.mark);
|
|
1170
|
-
case "erase":
|
|
1171
|
-
return this.eraseOp(item.erase);
|
|
1172
|
-
default:
|
|
1173
|
-
return { duration: 0, run: () => void 0 };
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
inkOp(id, strokes, color, width, min, max, perMs, marker = false) {
|
|
1177
|
-
const length = totalLength(strokes);
|
|
1178
|
-
const duration = Math.min(max, Math.max(min, length / perMs)) + TRAVEL_MS;
|
|
1179
|
-
const share = TRAVEL_MS / duration;
|
|
1180
|
-
let obj = null;
|
|
1181
|
-
return {
|
|
1182
|
-
duration,
|
|
1183
|
-
run: (progress) => {
|
|
1184
|
-
var _a, _b;
|
|
1185
|
-
if (!obj) {
|
|
1186
|
-
obj = { key: this.nextKey++, id, strokes, length, color, width, marker, drawn: 0 };
|
|
1187
|
-
this.inks = [...this.inks, obj];
|
|
1188
|
-
}
|
|
1189
|
-
if (!length) return;
|
|
1190
|
-
const drawn = progress >= 1 ? 1 : Math.max(0, (progress - share) / (1 - share));
|
|
1191
|
-
obj.drawn = drawn;
|
|
1192
|
-
this.pen = drawn > 0 ? pointAlong(strokes, length * drawn) : (_b = (_a = strokes[0]) == null ? void 0 : _a[0]) != null ? _b : this.pen;
|
|
1193
|
-
this.changed();
|
|
1194
|
-
}
|
|
1195
|
-
};
|
|
1196
|
-
}
|
|
1197
|
-
textOp(item) {
|
|
1198
|
-
const duration = Math.min(2e3, Math.max(350, item.text.length * 60)) + TRAVEL_MS;
|
|
1199
|
-
let word = null;
|
|
1200
|
-
return {
|
|
1201
|
-
duration,
|
|
1202
|
-
run: (progress) => {
|
|
1203
|
-
if (!word) {
|
|
1204
|
-
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 };
|
|
1205
|
-
this.words = [...this.words, word];
|
|
1206
|
-
}
|
|
1207
|
-
word.shown = progress >= 1 ? 1 : Math.max(0, (progress * duration - TRAVEL_MS) / (duration - TRAVEL_MS));
|
|
1208
|
-
const height = TEXT_SIZE[item.size] / 100 * useOnboarding.BOARD_W;
|
|
1209
|
-
this.pen = { x: sx(item.at[0] + item.text.length * height * 0.55 * word.shown), y: sy(item.at[1]) };
|
|
1210
|
-
this.changed();
|
|
1211
|
-
}
|
|
1212
|
-
};
|
|
1213
|
-
}
|
|
1214
|
-
tableOp(item) {
|
|
1215
|
-
let table = null;
|
|
1216
|
-
return {
|
|
1217
|
-
duration: item.rows.length * 450 + TRAVEL_MS,
|
|
1218
|
-
run: (progress) => {
|
|
1219
|
-
if (!table) {
|
|
1220
|
-
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 };
|
|
1221
|
-
this.words = [...this.words, table];
|
|
1222
|
-
}
|
|
1223
|
-
table.rowsShown = progress >= 1 ? item.rows.length : Math.max(progress > 0 ? 1 : 0, Math.floor(progress * item.rows.length));
|
|
1224
|
-
this.pen = { x: sx(item.at[0] + item.at[2]), y: sy(item.at[1]) };
|
|
1225
|
-
this.changed();
|
|
1226
|
-
}
|
|
1227
|
-
};
|
|
1228
|
-
}
|
|
1229
|
-
markOp(id) {
|
|
1230
|
-
let done = false;
|
|
1231
|
-
return {
|
|
1232
|
-
duration: 650,
|
|
1233
|
-
run: () => {
|
|
1234
|
-
if (done) return;
|
|
1235
|
-
done = true;
|
|
1236
|
-
const word = this.words.find((w) => w.id === id);
|
|
1237
|
-
if (word) {
|
|
1238
|
-
word.marked = true;
|
|
1239
|
-
this.changed();
|
|
1240
|
-
return;
|
|
1241
|
-
}
|
|
1242
|
-
const ink = this.inks.find((obj) => obj.id === id && !obj.marker);
|
|
1243
|
-
const box = ink ? bounds(ink.strokes) : null;
|
|
1244
|
-
if (!box) return;
|
|
1245
|
-
const mid = (box.y0 + box.y1) / 2;
|
|
1246
|
-
const swipe = [{ x: box.x0 - 14, y: mid }, { x: box.x1 + 14, y: mid }];
|
|
1247
|
-
this.inks = [{
|
|
1248
|
-
key: this.nextKey++,
|
|
1249
|
-
strokes: [swipe],
|
|
1250
|
-
length: totalLength([swipe]),
|
|
1251
|
-
color: MARKER,
|
|
1252
|
-
width: Math.max(24, (box.y1 - box.y0) * 0.6),
|
|
1253
|
-
marker: true,
|
|
1254
|
-
drawn: 1
|
|
1255
|
-
}, ...this.inks];
|
|
1256
|
-
this.changed();
|
|
1257
|
-
}
|
|
1258
|
-
};
|
|
1259
|
-
}
|
|
1260
|
-
eraseOp(id) {
|
|
1261
|
-
return {
|
|
1262
|
-
duration: 350,
|
|
1263
|
-
run: (progress) => {
|
|
1264
|
-
if (progress < 1) return;
|
|
1265
|
-
this.words = this.words.filter((w) => w.id !== id);
|
|
1266
|
-
this.inks = this.inks.filter((obj) => obj.id !== id);
|
|
1267
|
-
this.changed();
|
|
1268
|
-
}
|
|
1269
|
-
};
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
function inkPath(strokes, length, upTo) {
|
|
1273
|
-
let left = length * upTo;
|
|
1274
|
-
const parts = [];
|
|
1275
|
-
for (const stroke of strokes) {
|
|
1276
|
-
if (left <= 0 || stroke.length < 2) break;
|
|
1277
|
-
let d = `M${stroke[0].x.toFixed(1)} ${stroke[0].y.toFixed(1)}`;
|
|
1278
|
-
for (let i = 1; i < stroke.length; i += 1) {
|
|
1279
|
-
const a = stroke[i - 1];
|
|
1280
|
-
const b = stroke[i];
|
|
1281
|
-
const seg = Math.hypot(b.x - a.x, b.y - a.y);
|
|
1282
|
-
if (seg >= left) {
|
|
1283
|
-
const t = seg ? left / seg : 1;
|
|
1284
|
-
d += `L${(a.x + (b.x - a.x) * t).toFixed(1)} ${(a.y + (b.y - a.y) * t).toFixed(1)}`;
|
|
1285
|
-
left = 0;
|
|
1286
|
-
break;
|
|
1287
|
-
}
|
|
1288
|
-
d += `L${b.x.toFixed(1)} ${b.y.toFixed(1)}`;
|
|
1289
|
-
left -= seg;
|
|
1290
|
-
}
|
|
1291
|
-
parts.push(d);
|
|
1292
|
-
}
|
|
1293
|
-
return parts.join("");
|
|
1294
|
-
}
|
|
1295
|
-
const darkTheme = {
|
|
1296
|
-
background: "#0B0713",
|
|
1297
|
-
surface: "rgba(255,255,255,0.06)",
|
|
1298
|
-
surfaceRaised: "#1C1626",
|
|
1299
|
-
text: "#F5F3FF",
|
|
1300
|
-
textMuted: "#8B85A0",
|
|
1301
|
-
accent: "#7C5CFF",
|
|
1302
|
-
onAccent: "#FFFFFF",
|
|
1303
|
-
userBubble: "#7C5CFF",
|
|
1304
|
-
onUserBubble: "#FFFFFF",
|
|
1305
|
-
error: "rgba(248,113,113,0.16)",
|
|
1306
|
-
border: "rgba(255,255,255,0.10)",
|
|
1307
|
-
radius: 22,
|
|
1308
|
-
fontSize: 15
|
|
1309
|
-
};
|
|
1310
|
-
const lightTheme = {
|
|
1311
|
-
background: "#FFFFFF",
|
|
1312
|
-
surface: "#F1F5F9",
|
|
1313
|
-
surfaceRaised: "#FFFFFF",
|
|
1314
|
-
text: "#0F172A",
|
|
1315
|
-
textMuted: "#64748B",
|
|
1316
|
-
accent: "#7C5CFF",
|
|
1317
|
-
onAccent: "#FFFFFF",
|
|
1318
|
-
userBubble: "#7C5CFF",
|
|
1319
|
-
onUserBubble: "#FFFFFF",
|
|
1320
|
-
error: "#FEE2E2",
|
|
1321
|
-
border: "#E2E8F0",
|
|
1322
|
-
radius: 22,
|
|
1323
|
-
fontSize: 15
|
|
1324
|
-
};
|
|
1325
|
-
function resolveTheme(overrides, base = lightTheme) {
|
|
1326
|
-
return overrides ? { ...base, ...overrides } : base;
|
|
1327
|
-
}
|
|
1328
|
-
const SHEET_W = 1600;
|
|
1329
|
-
const SHEET_H = 1e3;
|
|
1330
|
-
const HAND = reactNative.Platform.select({ ios: "Bradley Hand", android: "casual", default: void 0 });
|
|
1331
|
-
const PEN = "M0 0 L-5 -22 L22 -70 L32 -63 L5 -16 Z";
|
|
1332
|
-
function GuideAIWhiteboard({ theme: overrides }) {
|
|
1333
|
-
const theme = resolveTheme(overrides);
|
|
1334
|
-
const { state, close, retry } = useOnboarding.useWhiteboard();
|
|
1335
|
-
const [, repaint] = React.useReducer((n) => n + 1, 0);
|
|
1336
|
-
const [width, setWidth] = React.useState(0);
|
|
1337
|
-
const [expanded, setExpanded] = React.useState(false);
|
|
1338
|
-
const motion = React.useRef({ reduced: false });
|
|
1339
|
-
const model = React.useMemo(() => new BoardModel({
|
|
1340
|
-
onChange: () => repaint(),
|
|
1341
|
-
get reducedMotion() {
|
|
1342
|
-
return motion.current.reduced;
|
|
1343
|
-
}
|
|
1344
|
-
}), []);
|
|
1345
|
-
React.useEffect(() => {
|
|
1346
|
-
var _a, _b;
|
|
1347
|
-
void ((_b = (_a = reactNative.AccessibilityInfo).isReduceMotionEnabled) == null ? void 0 : _b.call(_a).then((on) => {
|
|
1348
|
-
motion.current.reduced = on;
|
|
1349
|
-
}, () => void 0));
|
|
1350
|
-
}, []);
|
|
1351
|
-
React.useEffect(() => {
|
|
1352
|
-
if (state.status === "playing" && state.scene) model.play(state.scene);
|
|
1353
|
-
else model.destroy();
|
|
1354
|
-
}, [model, state.status, state.scene]);
|
|
1355
|
-
React.useEffect(() => () => model.destroy(), [model]);
|
|
1356
|
-
if (state.status === "closed") return null;
|
|
1357
|
-
const board = model.snapshot();
|
|
1358
|
-
const height = width / (useOnboarding.BOARD_W / useOnboarding.BOARD_H);
|
|
1359
|
-
const unit2 = width / 100;
|
|
1360
|
-
const playing = board.state === "playing";
|
|
1361
|
-
const title = state.status === "playing" ? board.title : state.question;
|
|
1362
|
-
const shut = () => {
|
|
1363
|
-
model.destroy();
|
|
1364
|
-
close();
|
|
1365
|
-
};
|
|
1366
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { visible: true, transparent: true, animationType: "fade", onRequestClose: shut, supportedOrientations: ["portrait", "landscape"], children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles$3.backdrop, expanded ? styles$3.centre : null], pointerEvents: "box-none", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1367
|
-
reactNative.View,
|
|
1368
|
-
{
|
|
1369
|
-
style: [styles$3.card, { backgroundColor: theme.surfaceRaised, borderColor: theme.border, maxWidth: expanded ? 1040 : 540 }],
|
|
1370
|
-
accessibilityViewIsModal: true,
|
|
1371
|
-
accessibilityLabel: `Whiteboard: ${title}`,
|
|
1372
|
-
children: [
|
|
1373
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles$3.head, children: [
|
|
1374
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles$3.title, { color: theme.text }], numberOfLines: 1, children: title || "Whiteboard" }),
|
|
1375
|
-
board.sample && state.status === "playing" ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles$3.badge, accessibilityHint: "This board uses example numbers.", children: "Example" }) : null,
|
|
1376
|
-
/* @__PURE__ */ jsxRuntime.jsx(IconButton, { label: expanded ? "Collapse whiteboard" : "Expand whiteboard", glyph: expanded ? "⤡" : "⤢", color: theme.textMuted, onPress: () => setExpanded((v) => !v) }),
|
|
1377
|
-
/* @__PURE__ */ jsxRuntime.jsx(IconButton, { label: "Close whiteboard", glyph: "✕", color: theme.textMuted, onPress: shut })
|
|
1378
|
-
] }),
|
|
1379
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles$3.sheet, onLayout: (e) => setWidth(e.nativeEvent.layout.width), children: [
|
|
1380
|
-
width > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1381
|
-
/* @__PURE__ */ jsxRuntime.jsxs(Svg, { width, height, viewBox: `0 0 ${SHEET_W} ${SHEET_H}`, children: [
|
|
1382
|
-
board.inks.filter((obj) => obj.marker).map((obj) => /* @__PURE__ */ jsxRuntime.jsx(Ink, { obj }, obj.key)),
|
|
1383
|
-
board.inks.filter((obj) => !obj.marker).map((obj) => /* @__PURE__ */ jsxRuntime.jsx(Ink, { obj }, obj.key)),
|
|
1384
|
-
board.pen && playing && !motion.current.reduced ? /* @__PURE__ */ jsxRuntime.jsx(Svg.G, { transform: `translate(${board.pen.x.toFixed(1)} ${board.pen.y.toFixed(1)})`, children: /* @__PURE__ */ jsxRuntime.jsx(Svg.Path, { d: PEN, fill: "#fde68a", stroke: "#1f2937", strokeWidth: 3, strokeLinejoin: "round" }) }) : null
|
|
1385
|
-
] }),
|
|
1386
|
-
board.words.map((word) => /* @__PURE__ */ jsxRuntime.jsx(Word, { word, width, height, unit: unit2 }, word.key))
|
|
1387
|
-
] }) : null,
|
|
1388
|
-
state.status === "loading" ? /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles$3.status, accessibilityLiveRegion: "polite", children: [
|
|
1389
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.ActivityIndicator, { color: theme.accent }),
|
|
1390
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles$3.statusText, children: "Drawing your board…" })
|
|
1391
|
-
] }) : null,
|
|
1392
|
-
state.status === "error" ? /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles$3.status, accessibilityLiveRegion: "assertive", children: [
|
|
1393
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles$3.statusText, children: state.error }),
|
|
1394
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { accessibilityRole: "button", onPress: retry, style: [styles$3.retry, { backgroundColor: theme.accent }], children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: { color: theme.onAccent, fontWeight: "600" }, children: "Try again" }) })
|
|
1395
|
-
] }) : null
|
|
1396
|
-
] }),
|
|
1397
|
-
state.status === "playing" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1398
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles$3.caption, { color: theme.text }], accessibilityLiveRegion: "polite", children: board.caption }),
|
|
1399
|
-
board.steps > 1 ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles$3.track, accessibilityLabel: "Steps", children: Array.from({ length: board.steps }, (_, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1400
|
-
reactNative.Pressable,
|
|
1401
|
-
{
|
|
1402
|
-
accessibilityRole: "button",
|
|
1403
|
-
accessibilityLabel: `Go to step ${i + 1}`,
|
|
1404
|
-
accessibilityState: { selected: i === board.step },
|
|
1405
|
-
onPress: () => model.seek(i),
|
|
1406
|
-
hitSlop: 8,
|
|
1407
|
-
style: [styles$3.segment, { backgroundColor: i <= board.step ? theme.accent : theme.border }]
|
|
1408
|
-
},
|
|
1409
|
-
i
|
|
1410
|
-
)) }) : null,
|
|
1411
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles$3.bar, children: [
|
|
1412
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1413
|
-
IconButton,
|
|
1414
|
-
{
|
|
1415
|
-
label: playing ? "Pause" : board.state === "done" ? "Play again" : "Resume",
|
|
1416
|
-
glyph: playing ? "❚❚" : board.state === "done" ? "↻" : "▶",
|
|
1417
|
-
color: theme.text,
|
|
1418
|
-
onPress: () => model.toggle()
|
|
1419
|
-
}
|
|
1420
|
-
),
|
|
1421
|
-
/* @__PURE__ */ jsxRuntime.jsx(IconButton, { label: "Replay from the start", glyph: "↺", color: theme.text, onPress: () => model.replay() }),
|
|
1422
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles$3.step, { color: theme.textMuted }], children: board.step >= 0 ? `Step ${board.step + 1} of ${board.steps}` : "" }),
|
|
1423
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1424
|
-
reactNative.Pressable,
|
|
1425
|
-
{
|
|
1426
|
-
accessibilityRole: "button",
|
|
1427
|
-
accessibilityLabel: `Speed ${model.speed} times. Change speed`,
|
|
1428
|
-
onPress: () => {
|
|
1429
|
-
const at = SPEEDS.indexOf(model.speed);
|
|
1430
|
-
model.setSpeed(SPEEDS[(at + 1) % SPEEDS.length]);
|
|
1431
|
-
repaint();
|
|
1432
|
-
},
|
|
1433
|
-
style: [styles$3.speed, { borderColor: theme.border }],
|
|
1434
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.Text, { style: { color: theme.text, fontSize: 12 }, children: [
|
|
1435
|
-
model.speed,
|
|
1436
|
-
"×"
|
|
1437
|
-
] })
|
|
1438
|
-
}
|
|
1439
|
-
)
|
|
1440
|
-
] })
|
|
1441
|
-
] }) : null
|
|
1442
|
-
]
|
|
1443
|
-
}
|
|
1444
|
-
) }) });
|
|
1445
|
-
}
|
|
1446
|
-
function Ink({ obj }) {
|
|
1447
|
-
if (obj.drawn <= 0) return null;
|
|
1448
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1449
|
-
Svg.Path,
|
|
1450
|
-
{
|
|
1451
|
-
d: inkPath(obj.strokes, obj.length, obj.drawn),
|
|
1452
|
-
stroke: obj.color,
|
|
1453
|
-
strokeWidth: obj.width,
|
|
1454
|
-
fill: "none",
|
|
1455
|
-
strokeLinecap: "round",
|
|
1456
|
-
strokeLinejoin: "round"
|
|
1457
|
-
}
|
|
1458
|
-
);
|
|
1459
|
-
}
|
|
1460
|
-
function Word({ word, width, height, unit: unit2 }) {
|
|
1461
|
-
const left = word.at[0] / useOnboarding.BOARD_W * width;
|
|
1462
|
-
const top = word.at[1] / useOnboarding.BOARD_H * height;
|
|
1463
|
-
if (word.kind === "text") {
|
|
1464
|
-
const size2 = unit2 * TEXT_SIZE[word.size];
|
|
1465
|
-
const shown = word.text.slice(0, Math.ceil(word.text.length * word.shown));
|
|
1466
|
-
if (!shown) return null;
|
|
1467
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1468
|
-
reactNative.Text,
|
|
1469
|
-
{
|
|
1470
|
-
style: [styles$3.word, {
|
|
1471
|
-
left,
|
|
1472
|
-
top: top - size2 * 0.62,
|
|
1473
|
-
fontSize: size2,
|
|
1474
|
-
color: word.color,
|
|
1475
|
-
fontFamily: HAND,
|
|
1476
|
-
backgroundColor: word.marked ? MARKER : "transparent"
|
|
1477
|
-
}],
|
|
1478
|
-
accessibilityLabel: word.text,
|
|
1479
|
-
children: shown
|
|
1480
|
-
}
|
|
1481
|
-
);
|
|
1482
|
-
}
|
|
1483
|
-
if (word.rowsShown <= 0) return null;
|
|
1484
|
-
const size = unit2 * 2.2;
|
|
1485
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles$3.table, { left, top, width: word.at[2] / useOnboarding.BOARD_W * width, borderColor: word.color, backgroundColor: word.marked ? MARKER : "transparent" }], children: word.rows.slice(0, word.rowsShown).map((row, r) => /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles$3.row, children: row.map((cell, c) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1486
|
-
reactNative.Text,
|
|
1487
|
-
{
|
|
1488
|
-
style: [styles$3.cell, { fontSize: size, color: word.color, borderColor: word.color, fontFamily: HAND, fontWeight: r === 0 ? "700" : "400" }],
|
|
1489
|
-
children: cell
|
|
1490
|
-
},
|
|
1491
|
-
c
|
|
1492
|
-
)) }, r)) });
|
|
1493
|
-
}
|
|
1494
|
-
function IconButton({ label, glyph, color, onPress }) {
|
|
1495
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { accessibilityRole: "button", accessibilityLabel: label, onPress, hitSlop: 8, style: styles$3.icon, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: { color, fontSize: 16 }, children: glyph }) });
|
|
1496
|
-
}
|
|
1497
|
-
const styles$3 = reactNative.StyleSheet.create({
|
|
1498
|
-
backdrop: { flex: 1, justifyContent: "flex-end", alignItems: "center", padding: 12 },
|
|
1499
|
-
centre: { justifyContent: "center" },
|
|
1500
|
-
card: {
|
|
1501
|
-
width: "100%",
|
|
1502
|
-
borderRadius: 16,
|
|
1503
|
-
borderWidth: reactNative.StyleSheet.hairlineWidth,
|
|
1504
|
-
overflow: "hidden",
|
|
1505
|
-
shadowColor: "#0f172a",
|
|
1506
|
-
shadowOpacity: 0.25,
|
|
1507
|
-
shadowRadius: 24,
|
|
1508
|
-
shadowOffset: { width: 0, height: 12 },
|
|
1509
|
-
elevation: 12
|
|
1510
|
-
},
|
|
1511
|
-
head: { flexDirection: "row", alignItems: "center", paddingHorizontal: 12, paddingVertical: 8, gap: 6 },
|
|
1512
|
-
title: { flex: 1, fontSize: 14, fontWeight: "600" },
|
|
1513
|
-
badge: { fontSize: 11, fontWeight: "600", color: "#92400e", backgroundColor: "#fef3c7", borderRadius: 999, paddingHorizontal: 8, paddingVertical: 2, overflow: "hidden" },
|
|
1514
|
-
sheet: { width: "100%", aspectRatio: useOnboarding.BOARD_W / useOnboarding.BOARD_H, backgroundColor: "#fcfcfd" },
|
|
1515
|
-
status: { ...reactNative.StyleSheet.absoluteFillObject, alignItems: "center", justifyContent: "center", gap: 10, backgroundColor: "rgba(252,252,253,0.92)", padding: 16 },
|
|
1516
|
-
statusText: { color: "#475569", fontSize: 13, textAlign: "center" },
|
|
1517
|
-
retry: { paddingHorizontal: 14, paddingVertical: 8, borderRadius: 8 },
|
|
1518
|
-
caption: { paddingHorizontal: 14, paddingTop: 10, fontSize: 14, lineHeight: 20, minHeight: 46 },
|
|
1519
|
-
track: { flexDirection: "row", gap: 4, paddingHorizontal: 14, paddingTop: 4 },
|
|
1520
|
-
segment: { flex: 1, height: 6, borderRadius: 3 },
|
|
1521
|
-
bar: { flexDirection: "row", alignItems: "center", paddingHorizontal: 8, paddingVertical: 6, gap: 4 },
|
|
1522
|
-
step: { flex: 1, fontSize: 12, marginLeft: 4 },
|
|
1523
|
-
speed: { borderWidth: 1, borderRadius: 8, paddingHorizontal: 8, paddingVertical: 4 },
|
|
1524
|
-
icon: { width: 34, height: 34, alignItems: "center", justifyContent: "center" },
|
|
1525
|
-
word: { position: "absolute", fontWeight: "600" },
|
|
1526
|
-
table: { position: "absolute", borderWidth: 1.5 },
|
|
1527
|
-
row: { flexDirection: "row" },
|
|
1528
|
-
cell: { flex: 1, borderWidth: 0.75, paddingHorizontal: 6, paddingVertical: 3 }
|
|
1529
|
-
});
|
|
1530
|
-
function PersonIcon({ color }) {
|
|
1531
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles$2.iconWrap, children: [
|
|
1532
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles$2.iconBand, { borderColor: color }] }),
|
|
1533
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles$2.iconCup, styles$2.iconCupLeft, { backgroundColor: color }] }),
|
|
1534
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles$2.iconCup, styles$2.iconCupRight, { backgroundColor: color }] })
|
|
1535
|
-
] });
|
|
1536
|
-
}
|
|
1537
|
-
function Orb({ theme, active }) {
|
|
1538
|
-
const pulse = React.useRef(new reactNative.Animated.Value(0)).current;
|
|
1539
|
-
React.useEffect(() => {
|
|
1540
|
-
if (!active) {
|
|
1541
|
-
pulse.stopAnimation();
|
|
1542
|
-
reactNative.Animated.timing(pulse, { toValue: 0, duration: 240, useNativeDriver: true }).start();
|
|
1543
|
-
return;
|
|
1544
|
-
}
|
|
1545
|
-
const loop = reactNative.Animated.loop(
|
|
1546
|
-
reactNative.Animated.sequence([
|
|
1547
|
-
reactNative.Animated.timing(pulse, {
|
|
1548
|
-
toValue: 1,
|
|
1549
|
-
duration: 900,
|
|
1550
|
-
easing: reactNative.Easing.inOut(reactNative.Easing.quad),
|
|
1551
|
-
useNativeDriver: true
|
|
1552
|
-
}),
|
|
1553
|
-
reactNative.Animated.timing(pulse, {
|
|
1554
|
-
toValue: 0,
|
|
1555
|
-
duration: 900,
|
|
1556
|
-
easing: reactNative.Easing.inOut(reactNative.Easing.quad),
|
|
1557
|
-
useNativeDriver: true
|
|
1558
|
-
})
|
|
1559
|
-
])
|
|
1560
|
-
);
|
|
1561
|
-
loop.start();
|
|
1562
|
-
return () => loop.stop();
|
|
1563
|
-
}, [active, pulse]);
|
|
1564
|
-
const scale = pulse.interpolate({ inputRange: [0, 1], outputRange: [1, 1.18] });
|
|
1565
|
-
const glow = pulse.interpolate({ inputRange: [0, 1], outputRange: [0.35, 0.7] });
|
|
1566
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles$2.orbWrap, children: [
|
|
1567
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1568
|
-
reactNative.Animated.View,
|
|
1569
|
-
{
|
|
1570
|
-
style: [
|
|
1571
|
-
styles$2.orbGlow,
|
|
1572
|
-
{ backgroundColor: theme.accent, opacity: glow, transform: [{ scale }] }
|
|
1573
|
-
]
|
|
1574
|
-
}
|
|
1575
|
-
),
|
|
1576
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles$2.orbCore, { backgroundColor: theme.accent }] })
|
|
1577
|
-
] });
|
|
1578
|
-
}
|
|
1579
|
-
function Bubble$1({ message, theme, onTalkToHuman, onWhiteboard }) {
|
|
1580
|
-
if (message.role === "user") {
|
|
1581
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles$2.row, styles$2.rowUser], children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [
|
|
1582
|
-
styles$2.bubble,
|
|
1583
|
-
{ backgroundColor: theme.userBubble, borderRadius: theme.radius },
|
|
1584
|
-
message.error ? { backgroundColor: theme.error } : null
|
|
1585
|
-
], children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: {
|
|
1586
|
-
color: theme.onUserBubble,
|
|
1587
|
-
fontSize: theme.fontSize,
|
|
1588
|
-
lineHeight: theme.fontSize * 1.4
|
|
1589
|
-
}, children: message.content }) }) });
|
|
1590
|
-
}
|
|
1591
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles$2.row, styles$2.rowAssistant], children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [
|
|
1592
|
-
styles$2.assistantBody,
|
|
1593
|
-
message.error ? { backgroundColor: theme.error, borderRadius: theme.radius, padding: 12 } : null
|
|
1594
|
-
], children: [
|
|
1595
|
-
/* @__PURE__ */ jsxRuntime.jsx(Markdown, { color: theme.text, accentColor: theme.accent, fontSize: theme.fontSize, children: message.content }),
|
|
1596
|
-
onWhiteboard ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1597
|
-
reactNative.Pressable,
|
|
1598
|
-
{
|
|
1599
|
-
onPress: onWhiteboard,
|
|
1600
|
-
accessibilityRole: "button",
|
|
1601
|
-
accessibilityLabel: "Explain on whiteboard",
|
|
1602
|
-
style: [styles$2.errorAction, { borderColor: theme.accent }],
|
|
1603
|
-
hitSlop: 6,
|
|
1604
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles$2.humanText, { color: theme.accent, fontSize: theme.fontSize - 1 }], children: "✎ Explain on whiteboard" })
|
|
1605
|
-
}
|
|
1606
|
-
) : null,
|
|
1607
|
-
message.error && onTalkToHuman ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1608
|
-
reactNative.Pressable,
|
|
1609
|
-
{
|
|
1610
|
-
onPress: onTalkToHuman,
|
|
1611
|
-
accessibilityRole: "button",
|
|
1612
|
-
accessibilityLabel: "Talk to a person",
|
|
1613
|
-
style: [styles$2.errorAction, { borderColor: theme.accent }],
|
|
1614
|
-
hitSlop: 6,
|
|
1615
|
-
children: [
|
|
1616
|
-
/* @__PURE__ */ jsxRuntime.jsx(PersonIcon, { color: theme.accent }),
|
|
1617
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles$2.humanText, {
|
|
1618
|
-
color: theme.accent,
|
|
1619
|
-
fontSize: theme.fontSize - 1
|
|
1620
|
-
}], children: "Talk to a human" })
|
|
1621
|
-
]
|
|
1622
|
-
}
|
|
1623
|
-
) : null
|
|
1624
|
-
] }) });
|
|
1625
|
-
}
|
|
1626
|
-
function resolveTopInset(explicit) {
|
|
1627
|
-
var _a;
|
|
1628
|
-
if (explicit !== void 0) return explicit;
|
|
1629
|
-
if (reactNative.Platform.OS === "android") return (_a = reactNative.StatusBar.currentHeight) != null ? _a : 24;
|
|
1630
|
-
return 8;
|
|
1631
|
-
}
|
|
1632
|
-
function useHumanHandover(onTalkToHuman, available) {
|
|
1633
|
-
const [reachable, setReachable] = React.useState(false);
|
|
1634
|
-
React.useEffect(() => {
|
|
1635
|
-
if (!onTalkToHuman || available !== void 0) return;
|
|
1636
|
-
let cancelled = false;
|
|
1637
|
-
void (async () => {
|
|
1638
|
-
try {
|
|
1639
|
-
const { api } = setup.requireConfigured();
|
|
1640
|
-
const status = await api.get(
|
|
1641
|
-
setup.EP.supportStatus()
|
|
1642
|
-
);
|
|
1643
|
-
if (!cancelled) setReachable(!!(status == null ? void 0 : status.enabled));
|
|
1644
|
-
} catch {
|
|
1645
|
-
}
|
|
1646
|
-
})();
|
|
1647
|
-
return () => {
|
|
1648
|
-
cancelled = true;
|
|
1649
|
-
};
|
|
1650
|
-
}, [onTalkToHuman, available]);
|
|
1651
|
-
if (!onTalkToHuman) return false;
|
|
1652
|
-
return available != null ? available : reachable;
|
|
1653
|
-
}
|
|
1654
|
-
function GuideAIChat({
|
|
1655
|
-
theme: overrides,
|
|
1656
|
-
placeholder = "Ask me anything",
|
|
1657
|
-
greeting = "Ask me anything",
|
|
1658
|
-
emptyState,
|
|
1659
|
-
showMic = false,
|
|
1660
|
-
leadingAccessory,
|
|
1661
|
-
title,
|
|
1662
|
-
onClose,
|
|
1663
|
-
onTalkToHuman,
|
|
1664
|
-
humanHandoverAvailable,
|
|
1665
|
-
topInset
|
|
1666
|
-
}) {
|
|
1667
|
-
const { harness, debug } = setup.requireConfigured();
|
|
1668
|
-
const {
|
|
1669
|
-
messages,
|
|
1670
|
-
input,
|
|
1671
|
-
setInput,
|
|
1672
|
-
send,
|
|
1673
|
-
busy,
|
|
1674
|
-
canSend,
|
|
1675
|
-
status,
|
|
1676
|
-
typing,
|
|
1677
|
-
followUps,
|
|
1678
|
-
explainOnWhiteboard
|
|
1679
|
-
} = useOnboarding.useGuideAI({ harness, trace: debug });
|
|
1680
|
-
const theme = resolveTheme(overrides);
|
|
1681
|
-
const listRef = React.useRef(null);
|
|
1682
|
-
const showHuman = useHumanHandover(onTalkToHuman, humanHandoverAvailable);
|
|
1683
|
-
const { checklist, dismiss } = useOnboarding.useOnboarding();
|
|
1684
|
-
const nextSetupStep = checklist == null ? void 0 : checklist.steps.find((step) => step.state === "available");
|
|
1685
|
-
const headerTop = resolveTopInset(topInset);
|
|
1686
|
-
const submit = () => {
|
|
1687
|
-
void send();
|
|
1688
|
-
};
|
|
1689
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1690
|
-
reactNative.KeyboardAvoidingView,
|
|
1691
|
-
{
|
|
1692
|
-
style: [styles$2.container, { backgroundColor: theme.background }],
|
|
1693
|
-
behavior: reactNative.Platform.OS === "ios" ? "padding" : void 0,
|
|
1694
|
-
children: [
|
|
1695
|
-
title || onClose || showHuman ? /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [
|
|
1696
|
-
styles$2.header,
|
|
1697
|
-
{ borderBottomColor: theme.border, paddingTop: headerTop + 14 }
|
|
1698
|
-
], children: [
|
|
1699
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles$2.headerSide, children: title ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1700
|
-
reactNative.Text,
|
|
1701
|
-
{
|
|
1702
|
-
numberOfLines: 1,
|
|
1703
|
-
style: [styles$2.title, { color: theme.text, fontSize: theme.fontSize + 1 }],
|
|
1704
|
-
children: title
|
|
1705
|
-
}
|
|
1706
|
-
) : null }),
|
|
1707
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles$2.headerActions, children: [
|
|
1708
|
-
showHuman ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1709
|
-
reactNative.Pressable,
|
|
1710
|
-
{
|
|
1711
|
-
onPress: onTalkToHuman,
|
|
1712
|
-
accessibilityRole: "button",
|
|
1713
|
-
accessibilityLabel: "Talk to a person",
|
|
1714
|
-
style: [styles$2.human, {
|
|
1715
|
-
backgroundColor: theme.surface,
|
|
1716
|
-
borderColor: theme.border
|
|
1717
|
-
}],
|
|
1718
|
-
hitSlop: 8,
|
|
1719
|
-
children: [
|
|
1720
|
-
/* @__PURE__ */ jsxRuntime.jsx(PersonIcon, { color: theme.accent }),
|
|
1721
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles$2.humanText, {
|
|
1722
|
-
color: theme.accent,
|
|
1723
|
-
fontSize: theme.fontSize - 2
|
|
1724
|
-
}], children: "Talk to human" })
|
|
1725
|
-
]
|
|
1726
|
-
}
|
|
1727
|
-
) : null,
|
|
1728
|
-
onClose ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1729
|
-
reactNative.Pressable,
|
|
1730
|
-
{
|
|
1731
|
-
onPress: onClose,
|
|
1732
|
-
accessibilityRole: "button",
|
|
1733
|
-
accessibilityLabel: "Close assistant",
|
|
1734
|
-
style: [styles$2.close, { backgroundColor: theme.surface }],
|
|
1735
|
-
hitSlop: 10,
|
|
1736
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles$2.closeIcon, { color: theme.text }], children: "✕" })
|
|
1737
|
-
}
|
|
1738
|
-
) : null
|
|
1739
|
-
] })
|
|
1740
|
-
] }) : null,
|
|
1741
|
-
checklist && !checklist.completed && !checklist.dismissed ? /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: { margin: 14, padding: 14, borderRadius: 12, borderWidth: 1, borderColor: theme.border, backgroundColor: theme.surface }, accessibilityLabel: "Setup checklist", children: [
|
|
1742
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: { color: theme.text, fontWeight: "700", fontSize: theme.fontSize + 2 }, children: checklist.title }),
|
|
1743
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: { color: theme.textMuted, marginTop: 3 }, children: checklist.goal }),
|
|
1744
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.Text, { style: { color: theme.textMuted, marginTop: 8 }, children: [
|
|
1745
|
-
checklist.completed_required,
|
|
1746
|
-
" of ",
|
|
1747
|
-
checklist.total_required,
|
|
1748
|
-
" required steps complete"
|
|
1749
|
-
] }),
|
|
1750
|
-
checklist.steps.map((step) => /* @__PURE__ */ jsxRuntime.jsxs(reactNative.Text, { style: { color: step.state === "locked" ? theme.textMuted : theme.text, marginTop: 5 }, children: [
|
|
1751
|
-
step.state === "complete" ? "✓" : step.state === "locked" ? "–" : "○",
|
|
1752
|
-
" ",
|
|
1753
|
-
step.title
|
|
1754
|
-
] }, step.id)),
|
|
1755
|
-
nextSetupStep ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { accessibilityRole: "button", accessibilityLabel: `Help with ${nextSetupStep.title}`, onPress: () => void send(`Help me with ${nextSetupStep.title}`), style: { alignSelf: "flex-start", marginTop: 10, padding: 10, borderRadius: 8, backgroundColor: theme.accent }, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: { color: theme.onAccent, fontWeight: "600" }, children: "Continue setup" }) }) : null,
|
|
1756
|
-
checklist.allow_dismissal ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { accessibilityRole: "button", accessibilityLabel: "I don't need this setup", onPress: () => reactNative.Alert.alert("Stop showing setup?", "This checklist will not appear again on future visits.", [
|
|
1757
|
-
{ text: "Keep setup", style: "cancel" },
|
|
1758
|
-
{ text: "I don't need it", onPress: () => {
|
|
1759
|
-
void dismiss().catch(() => reactNative.Alert.alert("Could not dismiss setup", "Please try again."));
|
|
1760
|
-
} }
|
|
1761
|
-
]), style: { alignSelf: "flex-start", marginTop: 10, padding: 10 }, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: { color: theme.textMuted, textDecorationLine: "underline" }, children: "I don't need this setup" }) }) : null
|
|
1762
|
-
] }) : null,
|
|
1763
|
-
messages.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles$2.empty, children: emptyState != null ? emptyState : /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles$2.greetingRow, children: [
|
|
1764
|
-
/* @__PURE__ */ jsxRuntime.jsx(Orb, { theme, active: busy }),
|
|
1765
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [
|
|
1766
|
-
styles$2.greeting,
|
|
1767
|
-
{ color: theme.textMuted, fontSize: theme.fontSize + 3 }
|
|
1768
|
-
], children: greeting })
|
|
1769
|
-
] }) }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1770
|
-
reactNative.FlatList,
|
|
1771
|
-
{
|
|
1772
|
-
ref: listRef,
|
|
1773
|
-
data: messages,
|
|
1774
|
-
keyExtractor: (message) => message.id,
|
|
1775
|
-
renderItem: ({ item }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1776
|
-
Bubble$1,
|
|
1777
|
-
{
|
|
1778
|
-
message: item,
|
|
1779
|
-
theme,
|
|
1780
|
-
onTalkToHuman,
|
|
1781
|
-
onWhiteboard: item.whiteboard ? () => {
|
|
1782
|
-
void explainOnWhiteboard(item.id);
|
|
1783
|
-
} : void 0
|
|
1784
|
-
}
|
|
1785
|
-
),
|
|
1786
|
-
ListFooterComponent: typing || followUps.length ? /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles$2.footer, children: [
|
|
1787
|
-
typing ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: { color: theme.textMuted, fontSize: theme.fontSize }, children: "…" }) : null,
|
|
1788
|
-
followUps.map((label) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1789
|
-
reactNative.Pressable,
|
|
1790
|
-
{
|
|
1791
|
-
onPress: () => {
|
|
1792
|
-
void send(label);
|
|
1793
|
-
},
|
|
1794
|
-
accessibilityRole: "button",
|
|
1795
|
-
style: [styles$2.chip, { borderColor: theme.accent, borderRadius: theme.radius }],
|
|
1796
|
-
hitSlop: 4,
|
|
1797
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: { color: theme.accent, fontSize: theme.fontSize - 1 }, children: label })
|
|
1798
|
-
},
|
|
1799
|
-
label
|
|
1800
|
-
))
|
|
1801
|
-
] }) : null,
|
|
1802
|
-
contentContainerStyle: styles$2.list,
|
|
1803
|
-
onContentSizeChange: () => {
|
|
1804
|
-
var _a;
|
|
1805
|
-
return (_a = listRef.current) == null ? void 0 : _a.scrollToEnd({ animated: true });
|
|
1806
|
-
},
|
|
1807
|
-
keyboardShouldPersistTaps: "handled"
|
|
1808
|
-
}
|
|
1809
|
-
),
|
|
1810
|
-
status ? /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles$2.status, children: [
|
|
1811
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.ActivityIndicator, { size: "small", color: theme.accent }),
|
|
1812
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: { color: theme.textMuted, fontSize: theme.fontSize - 2 }, children: status })
|
|
1813
|
-
] }) : null,
|
|
1814
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles$2.composerRow, children: [
|
|
1815
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [
|
|
1816
|
-
styles$2.composer,
|
|
1817
|
-
{
|
|
1818
|
-
backgroundColor: theme.surface,
|
|
1819
|
-
borderRadius: theme.radius + 6,
|
|
1820
|
-
borderColor: theme.border
|
|
1821
|
-
}
|
|
1822
|
-
], children: [
|
|
1823
|
-
leadingAccessory ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles$2.leading, children: leadingAccessory }) : null,
|
|
1824
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1825
|
-
reactNative.TextInput,
|
|
1826
|
-
{
|
|
1827
|
-
style: [styles$2.input, { color: theme.text, fontSize: theme.fontSize }],
|
|
1828
|
-
value: input,
|
|
1829
|
-
onChangeText: setInput,
|
|
1830
|
-
placeholder: checklist && !checklist.completed && checklist.chat_policy === "setup_only" ? "Ask about your setup" : placeholder,
|
|
1831
|
-
placeholderTextColor: theme.textMuted,
|
|
1832
|
-
editable: !busy,
|
|
1833
|
-
onSubmitEditing: submit,
|
|
1834
|
-
returnKeyType: "send",
|
|
1835
|
-
multiline: true,
|
|
1836
|
-
accessibilityLabel: placeholder
|
|
1837
|
-
}
|
|
1838
|
-
),
|
|
1839
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1840
|
-
reactNative.Pressable,
|
|
1841
|
-
{
|
|
1842
|
-
onPress: submit,
|
|
1843
|
-
disabled: !canSend,
|
|
1844
|
-
accessibilityRole: "button",
|
|
1845
|
-
accessibilityLabel: "Send",
|
|
1846
|
-
style: [styles$2.send, { backgroundColor: canSend ? theme.accent : theme.border }],
|
|
1847
|
-
hitSlop: 6,
|
|
1848
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [
|
|
1849
|
-
styles$2.sendIcon,
|
|
1850
|
-
{ color: canSend ? theme.onAccent : theme.textMuted }
|
|
1851
|
-
], children: "↑" })
|
|
1852
|
-
}
|
|
1853
|
-
)
|
|
1854
|
-
] }),
|
|
1855
|
-
showMic ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1856
|
-
reactNative.Pressable,
|
|
1857
|
-
{
|
|
1858
|
-
accessibilityRole: "button",
|
|
1859
|
-
accessibilityLabel: "Voice input",
|
|
1860
|
-
style: [styles$2.mic, { backgroundColor: theme.surface, borderColor: theme.border }],
|
|
1861
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: { color: theme.textMuted, fontSize: 18 }, children: "🎤" })
|
|
1862
|
-
}
|
|
1863
|
-
) : null
|
|
1864
|
-
] }),
|
|
1865
|
-
/* @__PURE__ */ jsxRuntime.jsx(GuideAIWhiteboard, { theme: overrides })
|
|
1866
|
-
]
|
|
1867
|
-
}
|
|
1868
|
-
);
|
|
1869
|
-
}
|
|
1870
|
-
const styles$2 = reactNative.StyleSheet.create({
|
|
1871
|
-
container: { flex: 1 },
|
|
1872
|
-
header: {
|
|
1873
|
-
flexDirection: "row",
|
|
1874
|
-
alignItems: "center",
|
|
1875
|
-
justifyContent: "space-between",
|
|
1876
|
-
// paddingTop is set inline from the status-bar inset; only the
|
|
1877
|
-
// bottom half of the navbar's breathing room lives here.
|
|
1878
|
-
paddingHorizontal: 16,
|
|
1879
|
-
paddingBottom: 14,
|
|
1880
|
-
borderBottomWidth: reactNative.StyleSheet.hairlineWidth
|
|
1881
|
-
},
|
|
1882
|
-
headerSide: { flex: 1, minWidth: 0 },
|
|
1883
|
-
headerActions: { flexDirection: "row", alignItems: "center", gap: 8 },
|
|
1884
|
-
title: { fontWeight: "600" },
|
|
1885
|
-
human: {
|
|
1886
|
-
flexDirection: "row",
|
|
1887
|
-
alignItems: "center",
|
|
1888
|
-
gap: 6,
|
|
1889
|
-
paddingHorizontal: 10,
|
|
1890
|
-
paddingVertical: 6,
|
|
1891
|
-
borderRadius: 999,
|
|
1892
|
-
borderWidth: reactNative.StyleSheet.hairlineWidth
|
|
1893
|
-
},
|
|
1894
|
-
humanText: { fontWeight: "600" },
|
|
1895
|
-
errorAction: {
|
|
1896
|
-
flexDirection: "row",
|
|
1897
|
-
alignItems: "center",
|
|
1898
|
-
gap: 6,
|
|
1899
|
-
alignSelf: "flex-start",
|
|
1900
|
-
marginTop: 10,
|
|
1901
|
-
paddingHorizontal: 12,
|
|
1902
|
-
paddingVertical: 7,
|
|
1903
|
-
borderRadius: 999,
|
|
1904
|
-
borderWidth: reactNative.StyleSheet.hairlineWidth
|
|
1905
|
-
},
|
|
1906
|
-
iconWrap: { width: 14, height: 14, alignItems: "center", justifyContent: "center" },
|
|
1907
|
-
iconBand: {
|
|
1908
|
-
position: "absolute",
|
|
1909
|
-
top: 1,
|
|
1910
|
-
width: 12,
|
|
1911
|
-
height: 9,
|
|
1912
|
-
borderWidth: 1.6,
|
|
1913
|
-
borderBottomWidth: 0,
|
|
1914
|
-
borderTopLeftRadius: 6,
|
|
1915
|
-
borderTopRightRadius: 6
|
|
1916
|
-
},
|
|
1917
|
-
iconCup: { position: "absolute", bottom: 1, width: 3.5, height: 6, borderRadius: 1.5 },
|
|
1918
|
-
iconCupLeft: { left: 0 },
|
|
1919
|
-
iconCupRight: { right: 0 },
|
|
1920
|
-
close: {
|
|
1921
|
-
width: 32,
|
|
1922
|
-
height: 32,
|
|
1923
|
-
borderRadius: 16,
|
|
1924
|
-
alignItems: "center",
|
|
1925
|
-
justifyContent: "center"
|
|
1926
|
-
},
|
|
1927
|
-
closeIcon: { fontSize: 15, fontWeight: "600", lineHeight: 18 },
|
|
1928
|
-
list: { padding: 16, paddingBottom: 8, gap: 14 },
|
|
1929
|
-
empty: {
|
|
1930
|
-
// Centred, not pinned near the top: before the first message the
|
|
1931
|
-
// greeting is the only thing on screen, and hanging it under the
|
|
1932
|
-
// navbar leaves the rest of the display empty.
|
|
1933
|
-
flex: 1,
|
|
1934
|
-
alignItems: "center",
|
|
1935
|
-
justifyContent: "center",
|
|
1936
|
-
paddingHorizontal: 24,
|
|
1937
|
-
paddingBottom: 24
|
|
1938
|
-
},
|
|
1939
|
-
greetingRow: { flexDirection: "row", alignItems: "center", gap: 14 },
|
|
1940
|
-
greeting: { fontWeight: "400", textAlign: "center", flexShrink: 1 },
|
|
1941
|
-
orbWrap: { width: 34, height: 34, alignItems: "center", justifyContent: "center" },
|
|
1942
|
-
orbGlow: { position: "absolute", width: 34, height: 34, borderRadius: 17 },
|
|
1943
|
-
orbCore: { width: 20, height: 20, borderRadius: 10 },
|
|
1944
|
-
row: { flexDirection: "row" },
|
|
1945
|
-
rowUser: { justifyContent: "flex-end" },
|
|
1946
|
-
rowAssistant: { justifyContent: "flex-start" },
|
|
1947
|
-
// The user's bubble hugs its text: a three-word question drawn as a
|
|
1948
|
-
// full-width block reads as a paragraph, not a chat message. It is
|
|
1949
|
-
// capped at 80% so a long one still leaves the reply side legible.
|
|
1950
|
-
bubble: { maxWidth: "80%", paddingHorizontal: 16, paddingVertical: 11 },
|
|
1951
|
-
// The assistant's body does NOT hug its content, and that is the whole
|
|
1952
|
-
// point of `width` here rather than `maxWidth` alone.
|
|
1953
|
-
//
|
|
1954
|
-
// A View with only maxWidth shrink-wraps — React Native's equivalent of
|
|
1955
|
-
// width: fit-content. For a paragraph that looks fine, because the text
|
|
1956
|
-
// fills the measure anyway. For anything that lays itself out against
|
|
1957
|
-
// its parent — a table whose cells are `flex: 1`, a fenced code block,
|
|
1958
|
-
// a numbered list — the parent has collapsed to nothing by the time the
|
|
1959
|
-
// child is measured, so the table renders as an empty sliver and every
|
|
1960
|
-
// reply ends up a different width.
|
|
1961
|
-
//
|
|
1962
|
-
// Fixing it here rather than on the table keeps every block type
|
|
1963
|
-
// consistent: one column, the same measure for prose, code and tables.
|
|
1964
|
-
assistantBody: { width: "80%" },
|
|
1965
|
-
status: {
|
|
1966
|
-
flexDirection: "row",
|
|
1967
|
-
alignItems: "center",
|
|
1968
|
-
gap: 8,
|
|
1969
|
-
paddingHorizontal: 22,
|
|
1970
|
-
paddingBottom: 8
|
|
1971
|
-
},
|
|
1972
|
-
composerRow: {
|
|
1973
|
-
flexDirection: "row",
|
|
1974
|
-
alignItems: "flex-end",
|
|
1975
|
-
gap: 10,
|
|
1976
|
-
paddingHorizontal: 14,
|
|
1977
|
-
paddingBottom: reactNative.Platform.OS === "ios" ? 10 : 14,
|
|
1978
|
-
paddingTop: 4
|
|
1979
|
-
},
|
|
1980
|
-
composer: {
|
|
1981
|
-
flex: 1,
|
|
1982
|
-
flexDirection: "row",
|
|
1983
|
-
alignItems: "center",
|
|
1984
|
-
paddingLeft: 8,
|
|
1985
|
-
paddingRight: 6,
|
|
1986
|
-
paddingVertical: 6,
|
|
1987
|
-
borderWidth: reactNative.StyleSheet.hairlineWidth,
|
|
1988
|
-
gap: 6
|
|
1989
|
-
},
|
|
1990
|
-
leading: { paddingLeft: 4 },
|
|
1991
|
-
input: {
|
|
1992
|
-
flex: 1,
|
|
1993
|
-
paddingHorizontal: 8,
|
|
1994
|
-
paddingVertical: reactNative.Platform.OS === "ios" ? 8 : 4,
|
|
1995
|
-
maxHeight: 120
|
|
1996
|
-
},
|
|
1997
|
-
send: { width: 34, height: 34, borderRadius: 17, alignItems: "center", justifyContent: "center" },
|
|
1998
|
-
sendIcon: { fontSize: 17, fontWeight: "700", lineHeight: 20 },
|
|
1999
|
-
footer: {
|
|
2000
|
-
flexDirection: "row",
|
|
2001
|
-
flexWrap: "wrap",
|
|
2002
|
-
gap: 8,
|
|
2003
|
-
paddingTop: 4
|
|
2004
|
-
},
|
|
2005
|
-
chip: {
|
|
2006
|
-
borderWidth: 1,
|
|
2007
|
-
paddingHorizontal: 12,
|
|
2008
|
-
paddingVertical: 7
|
|
2009
|
-
},
|
|
2010
|
-
mic: {
|
|
2011
|
-
width: 46,
|
|
2012
|
-
height: 46,
|
|
2013
|
-
borderRadius: 23,
|
|
2014
|
-
alignItems: "center",
|
|
2015
|
-
justifyContent: "center",
|
|
2016
|
-
borderWidth: reactNative.StyleSheet.hairlineWidth
|
|
2017
|
-
}
|
|
2018
|
-
});
|
|
6
|
+
const GuideAIChat = require("./GuideAIChat-CxyWFl_o.cjs");
|
|
7
|
+
const useConversations = require("./useConversations-CTbQBTz-.cjs");
|
|
2019
8
|
const POLL_INTERVAL_MS = 3e3;
|
|
2020
9
|
const CONVERSATION_KEY = "guideai_support_conversation";
|
|
2021
10
|
function useStoredConversation() {
|
|
2022
|
-
const { runtime } =
|
|
11
|
+
const { runtime } = useConversations.requireConfigured();
|
|
2023
12
|
const [id, setId] = React.useState(() => {
|
|
2024
13
|
try {
|
|
2025
14
|
return runtime.storage.getItem(CONVERSATION_KEY);
|
|
@@ -2071,8 +60,8 @@ function GuideAISupportChat({
|
|
|
2071
60
|
openingContext
|
|
2072
61
|
}) {
|
|
2073
62
|
var _a;
|
|
2074
|
-
const { api } =
|
|
2075
|
-
const theme = resolveTheme(overrides);
|
|
63
|
+
const { api } = useConversations.requireConfigured();
|
|
64
|
+
const theme = GuideAIChat.resolveTheme(overrides);
|
|
2076
65
|
const headerTop = topInset != null ? topInset : reactNative.Platform.OS === "android" ? (_a = reactNative.StatusBar.currentHeight) != null ? _a : 24 : 8;
|
|
2077
66
|
const [conversationId, setConversationId] = useStoredConversation();
|
|
2078
67
|
const [messages, setMessages] = React.useState([]);
|
|
@@ -2093,7 +82,7 @@ function GuideAISupportChat({
|
|
|
2093
82
|
const poll = React.useCallback(async (id) => {
|
|
2094
83
|
var _a2;
|
|
2095
84
|
try {
|
|
2096
|
-
const path =
|
|
85
|
+
const path = useConversations.EP.supportMsgs(id);
|
|
2097
86
|
const result = await api.get(
|
|
2098
87
|
cursor.current ? `${path}?since=${encodeURIComponent(cursor.current)}` : path
|
|
2099
88
|
);
|
|
@@ -2126,7 +115,7 @@ function GuideAISupportChat({
|
|
|
2126
115
|
setFailed(false);
|
|
2127
116
|
try {
|
|
2128
117
|
const result = await api.post(
|
|
2129
|
-
|
|
118
|
+
useConversations.EP.supportConvs(),
|
|
2130
119
|
{
|
|
2131
120
|
message: openingContext ? `${text}
|
|
2132
121
|
|
|
@@ -2151,7 +140,7 @@ ${openingContext}` : text,
|
|
|
2151
140
|
setInput("");
|
|
2152
141
|
setBusy(true);
|
|
2153
142
|
try {
|
|
2154
|
-
await api.post(
|
|
143
|
+
await api.post(useConversations.EP.supportMsgs(conversationId), { body: text });
|
|
2155
144
|
await poll(conversationId);
|
|
2156
145
|
} catch {
|
|
2157
146
|
if (mounted.current) {
|
|
@@ -2554,10 +543,10 @@ function GuideAILauncher({
|
|
|
2554
543
|
}) {
|
|
2555
544
|
var _a, _b, _c;
|
|
2556
545
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
2557
|
-
const { checklist } =
|
|
546
|
+
const { checklist } = useConversations.useOnboarding();
|
|
2558
547
|
const autoOpenedFor = React.useRef(null);
|
|
2559
548
|
const [view, setView] = React.useState("assistant");
|
|
2560
|
-
const theme = resolveTheme(chatProps.theme);
|
|
549
|
+
const theme = GuideAIChat.resolveTheme(chatProps.theme);
|
|
2561
550
|
React.useEffect(() => {
|
|
2562
551
|
if (checklist && !checklist.completed && !checklist.dismissed && checklist.start_mode === "automatic" && autoOpenedFor.current !== checklist.id) {
|
|
2563
552
|
autoOpenedFor.current = checklist.id;
|
|
@@ -2690,7 +679,7 @@ function GuideAILauncher({
|
|
|
2690
679
|
onRequestClose: close,
|
|
2691
680
|
children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: { flex: 1, backgroundColor: theme.background }, children: [
|
|
2692
681
|
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: view === "assistant" ? styles.pane : styles.paneHidden, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2693
|
-
GuideAIChat,
|
|
682
|
+
GuideAIChat.GuideAIChat,
|
|
2694
683
|
{
|
|
2695
684
|
...chatProps,
|
|
2696
685
|
onClose: close,
|
|
@@ -2718,7 +707,7 @@ function GuideAIButton({
|
|
|
2718
707
|
size = 56
|
|
2719
708
|
}) {
|
|
2720
709
|
const { open } = useGuideAISheet();
|
|
2721
|
-
const theme = resolveTheme(overrides);
|
|
710
|
+
const theme = GuideAIChat.resolveTheme(overrides);
|
|
2722
711
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2723
712
|
reactNative.Pressable,
|
|
2724
713
|
{
|
|
@@ -2771,14 +760,18 @@ const styles = reactNative.StyleSheet.create({
|
|
|
2771
760
|
},
|
|
2772
761
|
nudgeText: { lineHeight: 19 }
|
|
2773
762
|
});
|
|
763
|
+
exports.DEFAULT_LANGUAGE_PICKER_LABELS = GuideAIChat.DEFAULT_LANGUAGE_PICKER_LABELS;
|
|
764
|
+
exports.DEFAULT_LIVE_VOICE_LABELS = GuideAIChat.DEFAULT_LIVE_VOICE_LABELS;
|
|
765
|
+
exports.GuideAIChat = GuideAIChat.GuideAIChat;
|
|
766
|
+
exports.GuideAILanguagePicker = GuideAIChat.GuideAILanguagePicker;
|
|
767
|
+
exports.GuideAILiveVoice = GuideAIChat.GuideAILiveVoice;
|
|
768
|
+
exports.GuideAIWhiteboard = GuideAIChat.GuideAIWhiteboard;
|
|
769
|
+
exports.Markdown = GuideAIChat.Markdown;
|
|
770
|
+
exports.darkTheme = GuideAIChat.darkTheme;
|
|
771
|
+
exports.lightTheme = GuideAIChat.lightTheme;
|
|
772
|
+
exports.resolveTheme = GuideAIChat.resolveTheme;
|
|
2774
773
|
exports.GuideAIButton = GuideAIButton;
|
|
2775
|
-
exports.GuideAIChat = GuideAIChat;
|
|
2776
774
|
exports.GuideAILauncher = GuideAILauncher;
|
|
2777
775
|
exports.GuideAISupportChat = GuideAISupportChat;
|
|
2778
|
-
exports.GuideAIWhiteboard = GuideAIWhiteboard;
|
|
2779
|
-
exports.Markdown = Markdown;
|
|
2780
|
-
exports.darkTheme = darkTheme;
|
|
2781
|
-
exports.lightTheme = lightTheme;
|
|
2782
|
-
exports.resolveTheme = resolveTheme;
|
|
2783
776
|
exports.useGuideAISheet = useGuideAISheet;
|
|
2784
777
|
//# sourceMappingURL=ui.cjs.map
|