// E01: interface tour, create a document, open the 27-model reference viewer. import fs from "node:fs"; import path from "node:path"; import { createSceneRunner } from "../../../carrier-course/lib/scene.mjs"; import { openLineReference, selectReferenceModel } from "../../lib/ui.mjs"; export async function run({ page, rec, script, stillsDir, rawDir }) { const scene = createSceneRunner({ rec, page, script }); const shot = name => rec.shot(stillsDir, name); const log = []; const logStep = entry => { log.push({ at: new Date().toISOString(), ...entry }); fs.writeFileSync(path.join(rawDir, "live-log.json"), `${JSON.stringify(log, null, 2)}\n`); }; const footer = () => page.locator('footer [role="status"]').textContent().catch(() => ""); const drag = async (locator, dx, dy) => { const box = await locator.boundingBox(); if (!box) return; const x = box.x + box.width / 2; const y = box.y + box.height / 2; await page.mouse.move(x, y); await page.mouse.down(); await page.mouse.move(x + dx, y + dy, { steps: 18 }); await page.mouse.up(); await page.waitForTimeout(400); }; await scene("S00", async () => { await shot("S00-title"); }); await scene("S01", async () => { await page.locator('nav[aria-label="Application menus"] details').filter({ hasText: "File" }).locator("summary").click(); await page.getByRole("button", { name: "新建 Document" }).click(); await page.waitForTimeout(2200); await page.evaluate(() => { for (const details of document.querySelectorAll('nav[aria-label="Application menus"] details[open]')) details.open = false; }); await page.waitForTimeout(250); await drag(page.locator('[aria-label="Imported native 3D view"]').first(), -120, -30); logStep({ step: "document", status: await footer(), labels: await page.locator(".fc-tree-text").count() }); await shot("S01-interface"); }); let info = ""; await scene("S02", async () => { const panel = await openLineReference(page); const select = panel.locator('select[aria-label="Reference model"]'); for (let attempt = 0; attempt < 60; attempt++) { await page.waitForTimeout(500); info = await panel.locator("footer").textContent().catch(() => ""); if (/个网格/.test(info ?? "")) break; } const options = await select.locator("option").allTextContents(); if (options.length !== 27) throw new Error(`expected 27 reference models, got ${options.length}`); logStep({ step: "reference", options: options.length, info }); await shot("S02-reference"); }); await scene("S03", async () => { const panel = page.getByRole("complementary", { name: "Line reference viewer" }); info = await selectReferenceModel(panel, page, "主控制柜", /1\.50 × 0\.74 × 0\.75/); logStep({ step: "cabinet", info }); if (!/1\.50 × 0\.74 × 0\.75/.test(info ?? "")) throw new Error(`cabinet dims mismatch: ${info}`); await drag(panel.locator("canvas"), 100, 30); await shot("S03-cabinet"); }); await scene("S04", async () => { const panel = page.getByRole("complementary", { name: "Line reference viewer" }); info = await selectReferenceModel(panel, page, "地面与地线", /4\.87 × 3\.67 × 0\.31/); logStep({ step: "ground", info }); if (!/4\.87 × 3\.67 × 0\.31/.test(info ?? "")) throw new Error(`ground dims mismatch: ${info}`); await shot("S04-units"); }); await scene("S05", async () => { fs.writeFileSync(path.join(rawDir, "E01-state.json"), `${JSON.stringify({ schema: "freecad-web-line-course/E01/state/v1", generatedAt: new Date().toISOString(), reference: "27 GLBs", viewer: info, log, }, null, 2)}\n`); await shot("S05-recap"); }); }