chalk-talk 0.14.0 → 0.15.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 +1 -1
- package/assets/player.html +3 -3
- package/embed-mermaid.js +344 -344
- package/embed.js +5 -5
- package/kit/browser.mjs +21 -4
- package/kit/format.check.ts +1 -0
- package/kit/format.ts +4 -2
- package/kit/tools/gallery.mjs +6 -5
- package/markdown.js +1 -1
- package/mount.global.js +374 -374
- package/mount.js +1 -1
- package/package.json +1 -1
- package/player.js +4 -4
- package/scripts/browser.mjs +21 -4
- package/scripts/contract.mjs +26 -4
- package/scripts/mermaid.mjs +1 -1
- package/scripts/syntax.mjs +1 -0
package/scripts/browser.mjs
CHANGED
|
@@ -121,7 +121,7 @@ async function start(exe) {
|
|
|
121
121
|
|
|
122
122
|
/** Opens `file` at `#mode` (with `query`) in a tab of its own and returns what the page wrote, parsed — { error } when
|
|
123
123
|
* the page could not be opened or wrote nothing in `ms`. */
|
|
124
|
-
async function open(b, file, mode, query, ms) {
|
|
124
|
+
async function open(b, file, mode, query, ms, shot) {
|
|
125
125
|
const until = Date.now() + ms
|
|
126
126
|
let sessionId
|
|
127
127
|
// Every call waits at most until the page's time is up: a page busy forever does not hold the build.
|
|
@@ -133,8 +133,24 @@ async function open(b, file, mode, query, ms) {
|
|
|
133
133
|
const { targetId } = await ask('Target.createTarget', { url: 'about:blank' })
|
|
134
134
|
try {
|
|
135
135
|
;({ sessionId } = await ask('Target.attachToTarget', { targetId, flatten: true }))
|
|
136
|
-
|
|
136
|
+
if (shot) await ask('Emulation.setDeviceMetricsOverride', { width: shot.width, height: shot.height, deviceScaleFactor: 1, mobile: false })
|
|
137
|
+
if (shot?.scheme) await ask('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: shot.scheme }] })
|
|
138
|
+
const nav = await ask('Page.navigate', { url: `${pathToFileURL(file).href}${query ? `?${query}` : ''}${mode ? `#${mode}` : ''}` })
|
|
137
139
|
if (nav.errorText) return { error: `the page did not open (${nav.errorText})` }
|
|
140
|
+
// A picture of the page as it is once loaded, its fonts in and (when it says so) data-ready on the body.
|
|
141
|
+
if (shot) {
|
|
142
|
+
const ready = "document.readyState === 'complete' && document.fonts.status === 'loaded' && (document.body?.dataset.ready ?? '1') === '1'"
|
|
143
|
+
while (Date.now() < until) {
|
|
144
|
+
const r = await ask('Runtime.evaluate', { expression: ready, returnByValue: true })
|
|
145
|
+
if (r.result?.value === true) {
|
|
146
|
+
await pause(shot.settle ?? 400)
|
|
147
|
+
const { data } = await ask('Page.captureScreenshot', { format: 'png' })
|
|
148
|
+
return { png: `data:image/png;base64,${data}` }
|
|
149
|
+
}
|
|
150
|
+
await pause(50)
|
|
151
|
+
}
|
|
152
|
+
throw new BrowserFailed(`the page was not ready in ${Math.round(ms / 1000)} s`)
|
|
153
|
+
}
|
|
138
154
|
while (Date.now() < until) {
|
|
139
155
|
const r = await ask('Runtime.evaluate', { expression: `document.getElementById('chalk-${mode}')?.textContent ?? null`, returnByValue: true })
|
|
140
156
|
const text = r.result?.value
|
|
@@ -149,7 +165,8 @@ async function open(b, file, mode, query, ms) {
|
|
|
149
165
|
}
|
|
150
166
|
}
|
|
151
167
|
|
|
152
|
-
/** Runs `jobs` ({ file, mode, query }) in one browser
|
|
168
|
+
/** Runs `jobs` ({ file, mode, query, shot }) in one browser — `shot: { width, height }` answers with { png } (a
|
|
169
|
+
* picture of the page once loaded) instead of what the page wrote — and returns their results in order, with the browser used —
|
|
153
170
|
* `results` null when there is no browser at all. A browser that fails (does not start, stops, or a page gets no answer
|
|
154
171
|
* in `timeout` seconds) gives way to the next one, which runs every job again; when none works, each result is
|
|
155
172
|
* { error } naming what was tried. */
|
|
@@ -162,7 +179,7 @@ export async function runPages(jobs, { timeout = 20 } = {}) {
|
|
|
162
179
|
try {
|
|
163
180
|
b = await start(exe)
|
|
164
181
|
const results = []
|
|
165
|
-
for (const { file, mode, query = '' } of jobs) results.push(await open(b, file, mode, query, timeout * 1000))
|
|
182
|
+
for (const { file, mode = '', query = '', shot } of jobs) results.push(await open(b, file, mode, query, timeout * 1000, shot))
|
|
166
183
|
return { results, used: exe, tried }
|
|
167
184
|
} catch (e) {
|
|
168
185
|
tried.push(`${exe}: ${e instanceof BrowserFailed ? e.message : e.message.split('\n')[0]}`)
|
package/scripts/contract.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// GENERATED by tools/assets.mjs from the drawing engine v0.
|
|
1
|
+
// GENERATED by tools/assets.mjs from the drawing engine v0.255.0. Do not edit.
|
|
2
2
|
var WORDS = ["and", "or", "not"];
|
|
3
3
|
|
|
4
4
|
var PROP_NAMES = [
|
|
@@ -416,6 +416,7 @@ var hasFace = (name) => {
|
|
|
416
416
|
return !!key && key in HEADS;
|
|
417
417
|
};
|
|
418
418
|
|
|
419
|
+
var MOTIONS = ["spin", "drive", "steam", "talk", "pulse", "float"];
|
|
419
420
|
var MAX_DEFS = 8;
|
|
420
421
|
var MAX_DEF_SHAPES = 24;
|
|
421
422
|
function defaultValues(scene) {
|
|
@@ -453,7 +454,8 @@ var STEP_TYPES = [
|
|
|
453
454
|
"note",
|
|
454
455
|
"table",
|
|
455
456
|
"bars",
|
|
456
|
-
"chain"
|
|
457
|
+
"chain",
|
|
458
|
+
"animate"
|
|
457
459
|
];
|
|
458
460
|
var PLACEABLE = ["text", "prop", "card", "counter", "circle", "ellipse"];
|
|
459
461
|
var ARRANGEMENTS = ["row", "column", "grid", "chain"];
|
|
@@ -514,7 +516,7 @@ function validateStep(step2, name, ids, inside, inRow = false) {
|
|
|
514
516
|
for (const key of ["id", "say", "chapter"]) optionalText(step2[key], `${name}.${key}`);
|
|
515
517
|
if (step2.duration !== void 0) finite(step2.duration, `${name}.duration`, 0, 3e4);
|
|
516
518
|
if (step2.nudge !== void 0) {
|
|
517
|
-
if (["pause", "move", "link"].includes(step2.type)) throw new Error(`${name}.nudge: a ${step2.type} has no place of its own to move.`);
|
|
519
|
+
if (["pause", "move", "link", "animate"].includes(step2.type)) throw new Error(`${name}.nudge: a ${step2.type} has no place of its own to move.`);
|
|
518
520
|
if (!Array.isArray(step2.nudge) || step2.nudge.length !== 2) throw new Error(`${name}.nudge: use [dx, dy].`);
|
|
519
521
|
step2.nudge.forEach((v, k) => finite(v, `${name}.nudge[${k}]`, -900, 900));
|
|
520
522
|
}
|
|
@@ -645,6 +647,13 @@ function validateStep(step2, name, ids, inside, inRow = false) {
|
|
|
645
647
|
choice(step2.along, ["line", "curve"], `${name}.along`);
|
|
646
648
|
if (step2.ms !== void 0) finite(step2.ms, `${name}.ms`, 200, 5e3);
|
|
647
649
|
break;
|
|
650
|
+
case "animate":
|
|
651
|
+
text(step2.target, `${name}.target`);
|
|
652
|
+
if (!known(ids, String(step2.target))) throw new Error(`${name}.target: no earlier step has the id "${step2.target}".`);
|
|
653
|
+
choice(step2.effect, [...MOTIONS, "stop"], `${name}.effect`);
|
|
654
|
+
if (step2.effect === void 0) throw new Error(`${name}.effect: choose one of ${[...MOTIONS, "stop"].join(", ")}.`);
|
|
655
|
+
choice(step2.speed, ["slow", "fast"], `${name}.speed`);
|
|
656
|
+
break;
|
|
648
657
|
case "link":
|
|
649
658
|
for (const key of ["from", "to"]) {
|
|
650
659
|
text(step2[key], `${name}.${key}`);
|
|
@@ -1014,7 +1023,8 @@ var STEP_WORDS = /* @__PURE__ */ new Set([
|
|
|
1014
1023
|
"table",
|
|
1015
1024
|
"bars",
|
|
1016
1025
|
"json",
|
|
1017
|
-
"chain"
|
|
1026
|
+
"chain",
|
|
1027
|
+
"animate"
|
|
1018
1028
|
]);
|
|
1019
1029
|
var SIDES = { "right-of": "right", "left-of": "left", above: "above", below: "below" };
|
|
1020
1030
|
var STYLE = ["color", "fill", "roughness", "bowing", "fillStyle", "opacity"];
|
|
@@ -1195,6 +1205,16 @@ function step(line2, props) {
|
|
|
1195
1205
|
const inline = rest.slice(1);
|
|
1196
1206
|
return { type: "when", if: value(cond, no), steps: inline.length ? [step({ ...line2, tokens: inline, children: [] }, props)] : kids() };
|
|
1197
1207
|
}
|
|
1208
|
+
case "animate": {
|
|
1209
|
+
if (!rest[0] || !rest[1] || rest[1].includes("=")) throw new ChalkTextError(no, "write animate <id> spin|drive|steam|talk|pulse|float, or animate <id> stop.");
|
|
1210
|
+
const s = { type: "animate", target: rest[0], effect: rest[1] };
|
|
1211
|
+
for (const t of rest.slice(2)) {
|
|
1212
|
+
const [k, v] = t.split("=");
|
|
1213
|
+
if (k === "speed" && v) s.speed = v;
|
|
1214
|
+
else throw new ChalkTextError(no, `did not understand \xAB${t}\xBB (an animate takes speed=slow or speed=fast).`);
|
|
1215
|
+
}
|
|
1216
|
+
return s;
|
|
1217
|
+
}
|
|
1198
1218
|
case "move": {
|
|
1199
1219
|
if (rest[1] !== "to") throw new ChalkTextError(no, "write move <id> to x,y.");
|
|
1200
1220
|
return attrs(rest.slice(3), { type: "move", target: rest[0], to: point2(rest[2], no) }, no);
|
|
@@ -1462,6 +1482,8 @@ function printStep(s, props, indent) {
|
|
|
1462
1482
|
return line2(`${s.type} ${s.points.map(pt).join(" ")}`, ["points"]);
|
|
1463
1483
|
case "link":
|
|
1464
1484
|
return line2(`${s.from} -> ${s.to}${s.label !== void 0 ? ` ${q(s.label)}` : ""}`, ["from", "to", "label"]);
|
|
1485
|
+
case "animate":
|
|
1486
|
+
return [`${indent}animate ${s.target} ${s.effect}${s.speed ? ` speed=${s.speed}` : ""}`];
|
|
1465
1487
|
case "balloon":
|
|
1466
1488
|
return line2(`${s.to} ${s.kind === "thought" ? "thinks" : "says"} ${q(s.text)}`, ["to", "text", "kind"]);
|
|
1467
1489
|
case "counter":
|