@sixb/agent 0.2.4 → 0.2.6
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 +2 -2
- package/dist/agent-prompt.d.ts +13 -3
- package/dist/agent-prompt.d.ts.map +1 -1
- package/dist/artifacts/layout-check/layout-check.d.ts +21 -24
- package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -1
- package/dist/artifacts/publish-tool.d.ts.map +1 -1
- package/dist/background-commands.d.ts +2 -2
- package/dist/context-compaction.d.ts.map +1 -1
- package/dist/conversation-messages.d.ts +1 -1
- package/dist/conversation-messages.d.ts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11082 -9281
- package/dist/index.js.map +37 -33
- package/dist/login-shell.d.ts +18 -2
- package/dist/login-shell.d.ts.map +1 -1
- package/dist/model-adapters.d.ts +5 -2
- package/dist/model-adapters.d.ts.map +1 -1
- package/dist/model-lines.d.ts +1 -0
- package/dist/model-lines.d.ts.map +1 -1
- package/dist/run-agent-turn.d.ts +3 -14
- package/dist/run-agent-turn.d.ts.map +1 -1
- package/dist/run-conversation-turn.d.ts.map +1 -1
- package/dist/run-environment.d.ts.map +1 -1
- package/dist/run-sandbox.d.ts +11 -1
- package/dist/run-sandbox.d.ts.map +1 -1
- package/dist/run-subagent.d.ts.map +1 -1
- package/dist/sandbox-api-context.d.ts.map +1 -1
- package/dist/search-script.d.ts +7 -0
- package/dist/search-script.d.ts.map +1 -0
- package/dist/skills/built-in.d.ts.map +1 -1
- package/dist/subagent-tools.d.ts +11 -1
- package/dist/subagent-tools.d.ts.map +1 -1
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/glob.d.ts +41 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/grep.d.ts +64 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/model-spec.d.ts.map +1 -1
- package/dist/tools/sandbox-search.d.ts +26 -0
- package/dist/tools/sandbox-search.d.ts.map +1 -0
- package/dist/tools/search/command.d.ts +15 -0
- package/dist/tools/search/command.d.ts.map +1 -0
- package/dist/tools/search/gitignore.d.ts +28 -0
- package/dist/tools/search/gitignore.d.ts.map +1 -0
- package/dist/tools/search/glob.d.ts +15 -0
- package/dist/tools/search/glob.d.ts.map +1 -0
- package/dist/tools/search/main.d.ts +2 -0
- package/dist/tools/search/main.d.ts.map +1 -0
- package/dist/tools/search/match.d.ts +30 -0
- package/dist/tools/search/match.d.ts.map +1 -0
- package/dist/tools/search/pattern.d.ts +19 -0
- package/dist/tools/search/pattern.d.ts.map +1 -0
- package/dist/tools/search/read.d.ts +62 -0
- package/dist/tools/search/read.d.ts.map +1 -0
- package/dist/tools/search/request.d.ts +80 -0
- package/dist/tools/search/request.d.ts.map +1 -0
- package/dist/tools/search/search.d.ts +4 -0
- package/dist/tools/search/search.d.ts.map +1 -0
- package/dist/tools/search/walk.d.ts +43 -0
- package/dist/tools/search/walk.d.ts.map +1 -0
- package/dist/tools/tool-outputs.d.ts.map +1 -1
- package/dist/turn-inbox.d.ts +75 -0
- package/dist/turn-inbox.d.ts.map +1 -0
- package/package.json +7 -5
- package/src/agent-prompt.ts +63 -28
- package/src/agent-runtime/preflight.ts +1 -0
- package/src/artifacts/layout-check/check.cjs +176 -95
- package/src/artifacts/layout-check/layout-check.ts +118 -76
- package/src/artifacts/publish-tool.ts +48 -99
- package/src/background-commands.ts +8 -6
- package/src/context-compaction.ts +1 -0
- package/src/conversation-messages.ts +11 -4
- package/src/generated/search.mjs +985 -0
- package/src/index.ts +0 -1
- package/src/login-shell.ts +30 -3
- package/src/model-adapters.ts +23 -4
- package/src/model-lines.ts +1 -1
- package/src/run-agent-turn.ts +85 -129
- package/src/run-conversation-turn.ts +15 -6
- package/src/run-environment.ts +42 -11
- package/src/run-sandbox.ts +60 -1
- package/src/run-subagent.ts +9 -2
- package/src/sandbox-api-context.ts +10 -1
- package/src/search-script-assets.d.ts +5 -0
- package/src/search-script.ts +9 -0
- package/src/skills/built-in.ts +16 -0
- package/src/skills/sixb-artifacts/SKILL.md +7 -7
- package/src/skills/sixb-artifacts/canvas.md +3 -2
- package/src/skills/sixb-artifacts/document.md +92 -5
- package/src/skills/sixb-artifacts/examples/document/service-proposal/design.css +114 -0
- package/src/skills/sixb-artifacts/examples/document/service-proposal/document.html +159 -0
- package/src/skills/sixb-artifacts/examples/document/service-proposal/images/fieldwise.svg +1 -0
- package/src/skills/sixb-artifacts/examples/document/service-proposal/images/harbor-pine.svg +1 -0
- package/src/skills/sixb-artifacts/queries.md +2 -1
- package/src/subagent-tools.ts +23 -5
- package/src/tools/bash.ts +9 -10
- package/src/tools/glob.ts +124 -0
- package/src/tools/grep.ts +190 -0
- package/src/tools/model-spec.ts +4 -0
- package/src/tools/sandbox-search.ts +219 -0
- package/src/tools/search/command.ts +116 -0
- package/src/tools/search/gitignore.ts +101 -0
- package/src/tools/search/glob.ts +90 -0
- package/src/tools/search/main.ts +9 -0
- package/src/tools/search/match.ts +278 -0
- package/src/tools/search/pattern.ts +178 -0
- package/src/tools/search/read.ts +237 -0
- package/src/tools/search/request.ts +101 -0
- package/src/tools/search/search.ts +297 -0
- package/src/tools/search/walk.ts +145 -0
- package/src/tools/tool-outputs.ts +7 -2
- package/src/turn-inbox.ts +283 -0
- package/dist/artifacts/board-previews.d.ts +0 -41
- package/dist/artifacts/board-previews.d.ts.map +0 -1
- package/src/artifacts/board-previews.ts +0 -218
|
@@ -4,19 +4,22 @@
|
|
|
4
4
|
// slide is measured in each of its themes with the layout probe and screenshot in the first. A page
|
|
5
5
|
// loads at 1280px and at a phone's 390px, is measured whole in each theme, its top 4000px, and
|
|
6
6
|
// screenshot at each width. A canvas's boards load each at its own size, four at a time, measured
|
|
7
|
-
// as a page is and screenshot as boards/<id>.png;
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
7
|
+
// in each theme as a page is and screenshot in the first as boards/<id>.png; the pictures readers
|
|
8
|
+
// see are the render worker's to take. With overview.html, the whole canvas as it opens is
|
|
9
|
+
// screenshot as overview.png. A designed document loads as one sheet
|
|
10
|
+
// at its paper's width, and is measured whole, as a page is, but not for what only a screen has,
|
|
11
|
+
// small text and small controls; without paper, that sheet is screenshot as document.png. It is
|
|
12
|
+
// measured the same way at a phone's 390px, as the app shows it there, and screenshot as
|
|
13
|
+
// phone.png. With paper, it is then cut into its pages, each checked for what runs past its edge,
|
|
14
|
+
// and screenshot as page-NN.png. It writes one line of JSON:
|
|
15
|
+
// { layout, slides, pages?, problems, errors, screenshots, oversized, stalls, overview?, stopped? }
|
|
16
|
+
// or
|
|
14
17
|
// { skipped }.
|
|
15
18
|
//
|
|
16
19
|
// node check.cjs <directory> <output directory> <library directory> <deadline in ms> <layout>
|
|
17
20
|
//
|
|
18
|
-
// The library holds what the worker installs beside this script: deck.css, page.css,
|
|
19
|
-
// probe.js. The output directory holds entries.json, each page the check opens by its path, with
|
|
21
|
+
// The library holds what the worker installs beside this script: deck.css, page.css,
|
|
22
|
+
// document.css, runtime.js, probe.js. The output directory holds entries.json, each page the check opens by its path, with
|
|
20
23
|
// the kit and runtime in it; boards.json, a canvas's boards and their sizes; overview.html and
|
|
21
24
|
// overview.json, a canvas's page of itself and the window it opens in; files.json,
|
|
22
25
|
// the paths the version publishes: only those are served, since the reader gets only those; and
|
|
@@ -42,16 +45,25 @@ const DEADLINE_MS = Number(deadline) || 100_000
|
|
|
42
45
|
const STEP_MS = 10_000
|
|
43
46
|
const PROTOCOL = "sixb-frame/1"
|
|
44
47
|
/** The frame's own files, served from the library as the API serves them beside a version's. */
|
|
45
|
-
const FRAME_FILES = new Set([
|
|
48
|
+
const FRAME_FILES = new Set([
|
|
49
|
+
"/__sixb/deck.css",
|
|
50
|
+
"/__sixb/page.css",
|
|
51
|
+
"/__sixb/document.css",
|
|
52
|
+
"/__sixb/runtime.js",
|
|
53
|
+
])
|
|
46
54
|
/** Where the runtime reads a query when it is opened on its own. */
|
|
47
55
|
const QUERY_PATH = /^\/__sixb\/queries\/([a-z0-9][a-z0-9-]{0,63})\.json$/
|
|
56
|
+
/** A phone's screen, where pages and designed documents are checked too. */
|
|
57
|
+
const PHONE = { name: "phone", width: 390, height: 844 }
|
|
48
58
|
/** The widths a page is checked at: a laptop's, and a phone's. */
|
|
49
|
-
const VIEWS = [
|
|
50
|
-
{ name: "desktop", width: 1280, height: 800 },
|
|
51
|
-
{ name: "phone", width: 390, height: 844 },
|
|
52
|
-
]
|
|
59
|
+
const VIEWS = [{ name: "desktop", width: 1280, height: 800 }, PHONE]
|
|
53
60
|
/** How much of a page the check measures and shows, from its top. */
|
|
54
61
|
const PAGE_HEIGHT = 4000
|
|
62
|
+
/** How much of a designed document the check measures as one sheet, and how many pages it shoots. */
|
|
63
|
+
const DOCUMENT_HEIGHT = 16_000
|
|
64
|
+
const MAX_PAGES = 40
|
|
65
|
+
/** What the probe judges of a screen, which paper does not have. */
|
|
66
|
+
const SCREEN_ONLY = new Set(["small_text", "small_target"])
|
|
55
67
|
const TYPES = {
|
|
56
68
|
".html": "text/html; charset=utf-8",
|
|
57
69
|
".css": "text/css; charset=utf-8",
|
|
@@ -99,7 +111,7 @@ const PAGE_OPTIONS = {
|
|
|
99
111
|
deviceScaleFactor: 1,
|
|
100
112
|
reducedMotion: "reduce",
|
|
101
113
|
}
|
|
102
|
-
const NOUN = { canvas: "the canvas", page: "the page" }[layout] ?? "the deck"
|
|
114
|
+
const NOUN = { canvas: "the canvas", page: "the page", document: "the document" }[layout] ?? "the deck"
|
|
103
115
|
|
|
104
116
|
/** What the check has found so far, which a check that stops early reports. */
|
|
105
117
|
const found = {
|
|
@@ -108,10 +120,7 @@ const found = {
|
|
|
108
120
|
problems: [],
|
|
109
121
|
errors: [],
|
|
110
122
|
screenshots: [],
|
|
111
|
-
// A canvas's:
|
|
112
|
-
// answering, and the whole canvas as it opens.
|
|
113
|
-
previews: [],
|
|
114
|
-
unpictured: [],
|
|
123
|
+
// A canvas's: the boards that stopped answering, and the whole canvas as it opens.
|
|
115
124
|
// A canvas's boards whose page draws larger than the board shows.
|
|
116
125
|
oversized: [],
|
|
117
126
|
stalls: [],
|
|
@@ -128,7 +137,6 @@ const findings = () => ({
|
|
|
128
137
|
screenshots: [...found.screenshots].sort(
|
|
129
138
|
(left, right) => byBoard({ board: shotBoard(left) }, { board: shotBoard(right) })
|
|
130
139
|
),
|
|
131
|
-
previews: [...found.previews].sort(byBoard),
|
|
132
140
|
})
|
|
133
141
|
const shotBoard = (file) => path.basename(file, ".png")
|
|
134
142
|
|
|
@@ -235,10 +243,8 @@ function openTab(page, stepOf) {
|
|
|
235
243
|
/**
|
|
236
244
|
* A canvas's boards, each at its own size in each theme, a few at once. Each lane is a browser
|
|
237
245
|
* context of its own, so a board that stops answering costs only its lane, which goes on in a new
|
|
238
|
-
* one. A board's first theme is screenshot as boards/<id>.png
|
|
239
|
-
*
|
|
240
|
-
* boards/<id>.<theme>.png. Then the whole canvas as it opens, when overview.html says how. Returns
|
|
241
|
-
* whether a board stalled.
|
|
246
|
+
* one. A board's first theme is screenshot as boards/<id>.png. Then the whole canvas as it opens,
|
|
247
|
+
* when overview.html says how. Returns whether a board stalled.
|
|
242
248
|
*/
|
|
243
249
|
async function checkCanvas(browser, port, probe, themes) {
|
|
244
250
|
const boards = JSON.parse(fs.readFileSync(path.join(out, "boards.json"), "utf8"))
|
|
@@ -261,7 +267,6 @@ async function checkCanvas(browser, port, probe, themes) {
|
|
|
261
267
|
await tab.page.setViewportSize({ width: board.w, height: Math.min(board.h, PAGE_HEIGHT) })
|
|
262
268
|
await tab.load(`http://127.0.0.1:${port}/${board.file.split("/").map(encodeURIComponent).join("/")}`)
|
|
263
269
|
|
|
264
|
-
const pictures = []
|
|
265
270
|
for (const [index, name] of names.entries()) {
|
|
266
271
|
const step = tab.at(`board '${board.id}' in ${name} mode`)
|
|
267
272
|
await tab.send("theme", themes[name])
|
|
@@ -269,35 +274,15 @@ async function checkCanvas(browser, port, probe, themes) {
|
|
|
269
274
|
for (const problem of await within(step, tab.page.evaluate(`(${probe})("page")`))) {
|
|
270
275
|
found.problems.push({ ...problem, board: board.id, theme: name })
|
|
271
276
|
}
|
|
272
|
-
if (index
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
+
if (index > 0) continue
|
|
278
|
+
const page = await within(step, tab.page.evaluate(contentSize))
|
|
279
|
+
if (page.w > board.w + slack(board.w) || page.h > board.h + slack(board.h)) {
|
|
280
|
+
found.oversized.push({ board: board.id, w: board.w, h: board.h, page })
|
|
277
281
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const png = await tab.page.screenshot({ path: file, timeout: STEP_MS })
|
|
282
|
-
if (index === 0) found.screenshots.push(file)
|
|
283
|
-
if (!board.pictured || tab.failures.length > 0) continue
|
|
284
|
-
|
|
285
|
-
const small = path.join(out, "boards", `${board.id}.${name}.small.webp`)
|
|
286
|
-
await shrink(browser, png, board.smallWidth, small)
|
|
287
|
-
pictures.push(
|
|
288
|
-
{ board: board.id, theme: name, size: "full", path: file, bytes: png.length },
|
|
289
|
-
{ board: board.id, theme: name, size: "small", path: small, bytes: fs.statSync(small).size }
|
|
290
|
-
)
|
|
282
|
+
const file = path.join(out, "boards", `${board.id}.png`)
|
|
283
|
+
await tab.page.screenshot({ path: file, timeout: STEP_MS })
|
|
284
|
+
found.screenshots.push(file)
|
|
291
285
|
}
|
|
292
|
-
|
|
293
|
-
// A page that did not load whole is pictured broken, and its picture would stay: none is
|
|
294
|
-
// taken, and the board keeps its outline until it loads.
|
|
295
|
-
if (!board.pictured) return
|
|
296
|
-
if (tab.failures.length > 0) {
|
|
297
|
-
found.unpictured.push({ board: board.id, reason: tab.failures[0] })
|
|
298
|
-
return
|
|
299
|
-
}
|
|
300
|
-
found.previews.push(...pictures)
|
|
301
286
|
}
|
|
302
287
|
|
|
303
288
|
const lane = async () => {
|
|
@@ -325,49 +310,6 @@ async function checkCanvas(browser, port, probe, themes) {
|
|
|
325
310
|
return stalled
|
|
326
311
|
}
|
|
327
312
|
|
|
328
|
-
/** How a small picture's WebP is encoded: as sharp as text needs at its size, by eye. */
|
|
329
|
-
const SMALL_QUALITY = 0.85
|
|
330
|
-
/** A blank page where small pictures are encoded, apart from every board's scripts. */
|
|
331
|
-
let encoder
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* A board's screenshot at most `width` wide, its aspect kept, as WebP in `file`: what a canvas
|
|
335
|
-
* shows when it draws the board small. Encoded by the browser's own canvas.
|
|
336
|
-
*/
|
|
337
|
-
async function shrink(browser, png, width, file) {
|
|
338
|
-
encoder ??= within("the browser", browser.newContext()).then((context) =>
|
|
339
|
-
within("the browser", context.newPage())
|
|
340
|
-
)
|
|
341
|
-
const page = await encoder
|
|
342
|
-
const webp = await within(
|
|
343
|
-
"a small picture",
|
|
344
|
-
page.evaluate(
|
|
345
|
-
async ({ data, width, quality }) => {
|
|
346
|
-
const image = new Image()
|
|
347
|
-
image.src = `data:image/png;base64,${data}`
|
|
348
|
-
await image.decode()
|
|
349
|
-
const scale = Math.min(1, width / image.naturalWidth)
|
|
350
|
-
const canvas = document.createElement("canvas")
|
|
351
|
-
canvas.width = Math.max(1, Math.round(image.naturalWidth * scale))
|
|
352
|
-
canvas.height = Math.max(1, Math.round(image.naturalHeight * scale))
|
|
353
|
-
const context = canvas.getContext("2d")
|
|
354
|
-
context.imageSmoothingQuality = "high"
|
|
355
|
-
context.drawImage(image, 0, 0, canvas.width, canvas.height)
|
|
356
|
-
const blob = await new Promise((done) => canvas.toBlob(done, "image/webp", quality))
|
|
357
|
-
if (blob?.type !== "image/webp") throw new Error("this browser does not encode WebP")
|
|
358
|
-
const bytes = new Uint8Array(await blob.arrayBuffer())
|
|
359
|
-
let binary = ""
|
|
360
|
-
for (let at = 0; at < bytes.length; at += 0x8000) {
|
|
361
|
-
binary += String.fromCharCode(...bytes.subarray(at, at + 0x8000))
|
|
362
|
-
}
|
|
363
|
-
return btoa(binary)
|
|
364
|
-
},
|
|
365
|
-
{ data: png.toString("base64"), width, quality: SMALL_QUALITY }
|
|
366
|
-
)
|
|
367
|
-
)
|
|
368
|
-
fs.writeFileSync(file, Buffer.from(webp, "base64"))
|
|
369
|
-
}
|
|
370
|
-
|
|
371
313
|
/**
|
|
372
314
|
* overview.html, the whole canvas as the app opens it with each board its picture, screenshot
|
|
373
315
|
* as overview.png at the size overview.json gives. One that fails leaves the check as it is.
|
|
@@ -461,6 +403,10 @@ async function main() {
|
|
|
461
403
|
() => step
|
|
462
404
|
)
|
|
463
405
|
const { problems, screenshots } = found
|
|
406
|
+
if (layout === "document") {
|
|
407
|
+
await checkDocument({ page, load, settle, send }, port, probe, themes, (next) => (step = next))
|
|
408
|
+
return findings()
|
|
409
|
+
}
|
|
464
410
|
if (layout === "page") {
|
|
465
411
|
for (const view of VIEWS) {
|
|
466
412
|
step = `the page at ${view.width}px`
|
|
@@ -540,6 +486,141 @@ async function main() {
|
|
|
540
486
|
}
|
|
541
487
|
}
|
|
542
488
|
|
|
489
|
+
/**
|
|
490
|
+
* A designed document: as one sheet at its paper's width and at a phone's, measured whole up to its
|
|
491
|
+
* cut, then, with paper, as its pages, each checked for what runs past its edge and screenshot. In
|
|
492
|
+
* the first theme: the paper is white in any.
|
|
493
|
+
*/
|
|
494
|
+
async function checkDocument({ page, load, settle, send }, port, probe, themes, at) {
|
|
495
|
+
const { problems, screenshots } = found
|
|
496
|
+
const theme = Object.keys(themes)[0]
|
|
497
|
+
at(NOUN)
|
|
498
|
+
await page.setViewportSize({ width: 1280, height: 900 })
|
|
499
|
+
await load(`http://127.0.0.1:${port}/document.html`)
|
|
500
|
+
const paper = await within(
|
|
501
|
+
NOUN,
|
|
502
|
+
page.evaluate(() =>
|
|
503
|
+
(document.querySelector("script[data-sixb-paper]")?.getAttribute("data-sixb-paper") ?? "")
|
|
504
|
+
.split(" ")
|
|
505
|
+
.map(Number)
|
|
506
|
+
)
|
|
507
|
+
)
|
|
508
|
+
const sheet = paper[0] > 0 ? paper[0] : 0
|
|
509
|
+
// The sheet and the stage around it, wider than a phone's layout.
|
|
510
|
+
const width = Math.max(Math.ceil(sheet || 816) + 64, 760)
|
|
511
|
+
await page.setViewportSize({ width, height: 900 })
|
|
512
|
+
await send("theme", themes[theme])
|
|
513
|
+
await settle()
|
|
514
|
+
const height = await within(NOUN, page.evaluate(() => document.documentElement.scrollHeight))
|
|
515
|
+
await page.setViewportSize({ width, height: Math.max(900, Math.min(DOCUMENT_HEIGHT, height)) })
|
|
516
|
+
await settle()
|
|
517
|
+
for (const problem of await within(NOUN, page.evaluate(`(${probe})("page")`))) {
|
|
518
|
+
if (!SCREEN_ONLY.has(problem.code)) problems.push({ ...problem, theme })
|
|
519
|
+
}
|
|
520
|
+
if (!sheet) {
|
|
521
|
+
const file = path.join(out, "document.png")
|
|
522
|
+
await page.screenshot({ path: file, timeout: STEP_MS })
|
|
523
|
+
screenshots.push(file)
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// On a phone the app shows it as one sheet at the screen's width, where a fixed grid column
|
|
527
|
+
// or a wide table runs off the side.
|
|
528
|
+
at(`${NOUN} on a phone`)
|
|
529
|
+
await page.setViewportSize({ width: PHONE.width, height: PHONE.height })
|
|
530
|
+
await settle()
|
|
531
|
+
const tall = await within(NOUN, page.evaluate(() => document.documentElement.scrollHeight))
|
|
532
|
+
await page.setViewportSize({
|
|
533
|
+
width: PHONE.width,
|
|
534
|
+
height: Math.max(PHONE.height, Math.min(PAGE_HEIGHT, tall)),
|
|
535
|
+
})
|
|
536
|
+
await settle()
|
|
537
|
+
for (const problem of await within(NOUN, page.evaluate(`(${probe})("page")`))) {
|
|
538
|
+
if (!SCREEN_ONLY.has(problem.code)) problems.push({ ...problem, view: "phone", theme })
|
|
539
|
+
}
|
|
540
|
+
const phone = path.join(out, "phone.png")
|
|
541
|
+
await page.screenshot({ path: phone, timeout: STEP_MS })
|
|
542
|
+
screenshots.push(phone)
|
|
543
|
+
if (!sheet) return
|
|
544
|
+
|
|
545
|
+
at(`${NOUN}'s pages`)
|
|
546
|
+
await page.setViewportSize({ width, height: 1200 })
|
|
547
|
+
await load(`http://127.0.0.1:${port}/document.html?pages#sixb-pages`)
|
|
548
|
+
await send("theme", themes[theme])
|
|
549
|
+
await page.waitForSelector("html[data-sixb-pages]", { timeout: STEP_MS })
|
|
550
|
+
await settle()
|
|
551
|
+
found.pages = await within(
|
|
552
|
+
`${NOUN}'s pages`,
|
|
553
|
+
page.evaluate(() => Number(document.documentElement.dataset.sixbPages) || 0)
|
|
554
|
+
)
|
|
555
|
+
for (const problem of await within(`${NOUN}'s pages`, page.evaluate(pastPageEdges))) {
|
|
556
|
+
problems.push({ ...problem, theme })
|
|
557
|
+
}
|
|
558
|
+
const sheets = await page.$$(".sixb-paper")
|
|
559
|
+
for (const [index, each] of sheets.slice(0, MAX_PAGES).entries()) {
|
|
560
|
+
const file = path.join(out, `page-${String(index + 1).padStart(2, "0")}.png`)
|
|
561
|
+
// A sheet shows its page once it is in view.
|
|
562
|
+
await each.scrollIntoViewIfNeeded({ timeout: STEP_MS })
|
|
563
|
+
await each.waitForSelector(".sixb-flow", { state: "attached", timeout: STEP_MS })
|
|
564
|
+
await each.screenshot({ path: file, timeout: STEP_MS })
|
|
565
|
+
screenshots.push(file)
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* What runs past a page's content box, which cuts it off: on each page, each fragment of an element
|
|
571
|
+
* that sits on the page and reaches past its right or bottom edge, such as a table too wide or an
|
|
572
|
+
* image too tall for the page. Only the outermost of what nests: what it holds runs past with it,
|
|
573
|
+
* and the box that runs past is the one to fit. Run in the page, on the first sheet's flow, which
|
|
574
|
+
* lays out every page side by side, each its column.
|
|
575
|
+
*/
|
|
576
|
+
function pastPageEdges() {
|
|
577
|
+
const problems = []
|
|
578
|
+
const flow = document.querySelector(".sixb-paper .sixb-flow")
|
|
579
|
+
const box = flow?.parentElement?.getBoundingClientRect()
|
|
580
|
+
if (!flow || !box) return problems
|
|
581
|
+
// In CSS pixels, and as the sheets are zoomed to fit.
|
|
582
|
+
const style = getComputedStyle(flow)
|
|
583
|
+
const scale = box.width / Number.parseFloat(style.width) || 1
|
|
584
|
+
const stride = box.width + (Number.parseFloat(style.columnGap) || 0) * scale
|
|
585
|
+
const pages = new Map()
|
|
586
|
+
for (const element of flow.querySelectorAll("*")) {
|
|
587
|
+
for (const rect of element.getClientRects()) {
|
|
588
|
+
if (rect.width < 1 || rect.height < 1) continue
|
|
589
|
+
const index = Math.max(0, Math.floor((rect.left - box.left + 1) / stride))
|
|
590
|
+
const left = box.left + index * stride
|
|
591
|
+
if (rect.right > left + box.width + 1 || rect.bottom > box.bottom + 1) {
|
|
592
|
+
const past = pages.get(index) ?? []
|
|
593
|
+
pages.set(index, past)
|
|
594
|
+
past.push({ element, rect, left })
|
|
595
|
+
break
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
for (const [index, past] of [...pages].sort(([a], [b]) => a - b)) {
|
|
600
|
+
const outermost = past.filter(
|
|
601
|
+
({ element }) => !past.some((other) => other.element !== element && other.element.contains(element))
|
|
602
|
+
)
|
|
603
|
+
for (const { element, rect, left } of outermost.slice(0, 5)) {
|
|
604
|
+
const classes = Array.from(element.classList)
|
|
605
|
+
problems.push({
|
|
606
|
+
code: "outside",
|
|
607
|
+
page: index + 1,
|
|
608
|
+
rect: {
|
|
609
|
+
x: Math.round(rect.left - left),
|
|
610
|
+
y: Math.round(rect.top - box.top),
|
|
611
|
+
width: Math.round(rect.width),
|
|
612
|
+
height: Math.round(rect.height),
|
|
613
|
+
},
|
|
614
|
+
text:
|
|
615
|
+
(element.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 60) ||
|
|
616
|
+
element.tagName.toLowerCase(),
|
|
617
|
+
selector: `${element.tagName.toLowerCase()}${classes.length > 0 ? `.${classes.join(".")}` : ""}`,
|
|
618
|
+
})
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
return problems.slice(0, 30)
|
|
622
|
+
}
|
|
623
|
+
|
|
543
624
|
/**
|
|
544
625
|
* Text over a photo, which the probe cannot judge from styles: each text whose center sits over
|
|
545
626
|
* an image is hidden, the slide is shot without it, and the pixels under its box are read. The
|