oxedyne/daimond/dev/probe_typstheader.mjs
3.4 KiB, 1 run
created by r2519314175:95, 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 | // probe_typstheader.mjs — what the Doc panel's header says while the live view is up. |
| 2 | // |
| 3 | // Not a verifier: it asserts nothing and prints what is on screen, so the two seams |
| 4 | // in `showDoc` and `syncLineNo` can be read off the real panel rather than reasoned |
| 5 | // about from the source. |
| 6 | // |
| 7 | // eval "$(bash dev/world.sh 13 --env)" |
| 8 | // node dev/probe_typstheader.mjs |
| 9 | import path from 'node:path'; |
| 10 | import { fileURLToPath } from 'node:url'; |
| 11 | import { open, scratch } from './harness.mjs'; |
| 12 | |
| 13 | const HERE = path.dirname(fileURLToPath(import.meta.url)); |
| 14 | const PROFILE = scratch('pw', 'typstheader'); |
| 15 | |
| 16 | const MAIN = `#set page(width: 120mm, height: 160mm, margin: 12mm) |
| 17 | #set text(size: 10pt) |
| 18 | = The book |
| 19 | #lorem(200) |
| 20 | #pagebreak() |
| 21 | #lorem(200) |
| 22 | `; |
| 23 | |
| 24 | const s = await open({ name: 'typstheader', profile: PROFILE }); |
| 25 | const { page } = s; |
| 26 | const sleep = (ms) => new Promise(r => setTimeout(r, ms)); |
| 27 | |
| 28 | const look = (tag) => page.evaluate((tag) => { |
| 29 | const d = (id) => { |
| 30 | const e = document.getElementById(id); |
| 31 | return e ? (getComputedStyle(e).display + '/' + (e.style.display || '(unset)')) : 'absent'; |
| 32 | }; |
| 33 | const w = window.DaimondTypstWatch ? window.DaimondTypstWatch.state() : null; |
| 34 | return { |
| 35 | tag, |
| 36 | name: (document.getElementById('doc-name') || {}).textContent, |
| 37 | lineno: d('doc-lineno'), |
| 38 | view: d('doc-view'), |
| 39 | embed: d('doc-embed'), |
| 40 | live: !!document.getElementById('typst-live'), |
| 41 | watch: w ? { mode: w.mode, path: w.path, drawn: w.drawn } : null, |
| 42 | }; |
| 43 | }, tag); |
| 44 | |
| 45 | try { |
| 46 | await page.waitForTimeout(1200); |
| 47 | await page.evaluate(async (text) => { |
| 48 | const m = await import('/pkg/oxedyne_daimond.js'); |
| 49 | await m.write_file('proj/main.typ', text); |
| 50 | await m.write_file('proj/notes.md', '# notes\n\nsome text\n'); |
| 51 | }, MAIN); |
| 52 | await page.setViewportSize({ width: 1600, height: 950 }); |
| 53 | |
| 54 | await page.evaluate(() => window.DaimondDoc.show('proj/main.typ')); |
| 55 | await page.waitForTimeout(1200); |
| 56 | console.log(JSON.stringify(await look('the .typ open in the editor'), null, 1)); |
| 57 | |
| 58 | await page.click('[data-act="compile"]', { force: true }); |
| 59 | await sleep(1500); |
| 60 | console.log(JSON.stringify(await look('just after Compile'), null, 1)); |
| 61 | |
| 62 | for (let i = 0; i < 60; i++) { |
| 63 | const w = await page.evaluate(() => window.DaimondTypstWatch.state()); |
| 64 | if (w.drawn) break; |
| 65 | await sleep(500); |
| 66 | } |
| 67 | await sleep(800); |
| 68 | console.log(JSON.stringify(await look('live view drawn'), null, 1)); |
| 69 | |
| 70 | // Closing the DOC PANEL (not the document) is what ends the watch: the poll |
| 71 | // finds the panel gone and calls `stop()`, which puts the text view back on |
| 72 | // display. Nothing re-asks the header what it should be offering. |
| 73 | await page.click('#panel-doc [data-close="doc"]', { force: true }); |
| 74 | await sleep(2500); |
| 75 | await page.evaluate(() => window.DaimondPanels.show('doc')); |
| 76 | await sleep(600); |
| 77 | console.log(JSON.stringify(await look('doc panel closed and reopened'), null, 1)); |
| 78 | |
| 79 | // A second file opened while the live view is up: the text view comes back and |
| 80 | // the live pages are still in the panel under it. |
| 81 | await page.evaluate(() => window.DaimondDoc.show('proj/main.typ')); |
| 82 | await sleep(1200); |
| 83 | await page.click('[data-act="compile"]', { force: true }); |
| 84 | for (let i = 0; i < 60; i++) { |
| 85 | const w = await page.evaluate(() => window.DaimondTypstWatch.state()); |
| 86 | if (w.drawn) break; |
| 87 | await sleep(500); |
| 88 | } |
| 89 | await sleep(800); |
| 90 | await page.evaluate(() => window.DaimondDoc.show('proj/notes.md')); |
| 91 | await sleep(1200); |
| 92 | console.log(JSON.stringify(await look('another file opened over the live view'), null, 1)); |
| 93 | } finally { |
| 94 | await s.close(); |
| 95 | } |