oxedyne/daimond/dev/shot_stage.mjs
1.4 KiB, 1 run
created by r2519314175:195, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | // shot_stage.mjs — the stage as the author will see it: the source, its pages, |
| 2 | // and the daimon, all at once. |
| 3 | import { open, shot } from './harness.mjs'; |
| 4 | |
| 5 | const MAIN = `#import "one.typ": one |
| 6 | #set page(width: 120mm, height: 160mm, margin: 12mm) |
| 7 | #set text(size: 10pt) |
| 8 | #set par(justify: true) |
| 9 | = The book |
| 10 | #one |
| 11 | `; |
| 12 | const ONE = `#let one = [ |
| 13 | == Chapter one |
| 14 | Alpha lorem ipsum dolor sit amet, consectetur adipiscing elit. |
| 15 | |
| 16 | #lorem(120) |
| 17 | ] |
| 18 | `; |
| 19 | |
| 20 | const s = await open({ name: 'stageshot', connect: false }); |
| 21 | const p = s.page; |
| 22 | await p.setViewportSize({ width: 1920, height: 1080 }); |
| 23 | await p.waitForTimeout(1000); |
| 24 | |
| 25 | const put = (path, text) => p.evaluate(async ({ path, text }) => { |
| 26 | const m = await import('/pkg/oxedyne_daimond.js'); |
| 27 | await m.write_file(path, text); |
| 28 | }, { path, text }); |
| 29 | await put('book/main.typ', MAIN); |
| 30 | await put('book/one.typ', ONE); |
| 31 | |
| 32 | await p.evaluate(() => window.DaimondDoc.show('book/main.typ')); |
| 33 | await p.waitForTimeout(1200); |
| 34 | await p.click('[data-act="compile"]', { force: true }); |
| 35 | const st = () => p.evaluate(() => window.DaimondTypstWatch.state()); |
| 36 | for (let i = 0; i < 80 && !(await st()).drawn; i++) await p.waitForTimeout(500); |
| 37 | await p.waitForTimeout(1500); |
| 38 | await shot(s, 'stage-source-and-pages'); |
| 39 | console.log(JSON.stringify(await p.evaluate(() => [...document.getElementById('stage').children] |
| 40 | .filter((k) => k.getClientRects().length) |
| 41 | .map((k) => (k.dataset.panel || 'handle') + ':' + Math.round(k.getBoundingClientRect().width))))); |
| 42 | await s.close(); |