Files
workinf_Blender_Wasm/tools/web/build-offline-manual.mjs
mes123456 2c8449f422
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
feat(web): draggable floating panels and a non-hanging tutorial demo open
- add a shared useDraggablePanel hook (pointer capture, clamping, offset
  persistence in localStorage, double-click / button / menu reset) and use it
  for the tutorial step panel, the quick toolbar, the adjust-last-operation
  panel and the robot tool drawer
- quick toolbar drags out of the dock into a compact floating bar and can be
  folded; robot tool scrim is transparent and click-through so the 3D scene
  stays visible and usable while the tool is open
- 窗口 > 恢复默认面板位置 clears every stored panel offset
- fix a pre-existing hang: tutorial demo scene opens went through the
  "save current project?" prompt and waited forever; course demos now persist
  the current OPFS project like the dialog's 保存后继续 and continue
- PBR tutorial spec: demos must not auto-download .blend (OPFS-only rule)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-23 21:43:40 +08:00

68 lines
3.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* Build a self-contained offline copy of the Web Blender user manual.
*
* node tools/web/build-offline-manual.mjs [outputDir]
*
* The manual's search is client-side (`data-search` attributes) so no server
* is needed: rewriting the absolute paths to relative ones makes the page work
* from file://. Step images that the manual embeds from /tutorial/full/steps
* are copied alongside; links into the running app or the online course are
* neutralised because they cannot resolve offline.
*/
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
const source = path.join(repoRoot, "web/dist/manuals");
const output = path.resolve(process.argv[2] ?? path.join(repoRoot, "web/manual-offline"));
if (!fs.existsSync(path.join(source, "index.html"))) {
throw new Error(`manual source missing: ${source} (run the web build first)`);
}
if (output === source || output.startsWith(`${source}${path.sep}`)) throw new Error("refusing to build into the source directory");
fs.rmSync(output, { recursive: true, force: true });
fs.mkdirSync(output, { recursive: true });
fs.cpSync(source, output, { recursive: true });
let html = fs.readFileSync(path.join(output, "index.html"), "utf8");
const copied = new Set();
/* Local manual assets and step images referenced from the tutorial tree. */
/* Attributes are preceded by whitespace, not a quote: match the name and the
* opening quote only. */
html = html.replace(/\b(src|href)="\/manuals\//g, '$1="./');
html = html.replace(/\b(src|href)="\/tutorial\/full\/steps\/([^"]+)"/g, (match, name, file) => {
const from = path.join(repoRoot, "web/dist/tutorial/full/steps", file);
const to = path.join(output, "tutorial/full/steps", file);
if (fs.existsSync(from)) {
fs.mkdirSync(path.dirname(to), { recursive: true });
if (!copied.has(file)) { fs.copyFileSync(from, to); copied.add(file); }
}
return `${name}="./tutorial/full/steps/${file}"`;
});
/* Offline mode has no web app or online course to open. */
const before = html;
html = html.replace(/href="\/(?:\?ui=web|tutorial\/[^"]*)"/g, 'href="#" data-offline-link="unavailable" title="离线手册不含该在线页面"');
html = html.replace(/href="\/"/g, 'href="#" data-offline-link="unavailable" title="离线手册不含在线应用"');
if (html !== before) html = html.replace("<body", '<body data-offline="1"');
fs.writeFileSync(path.join(output, "index.html"), html);
const files = [];
const walk = (dir) => {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) walk(full);
else files.push(full);
}
};
walk(output);
const bytes = files.reduce((sum, file) => sum + fs.statSync(file).size, 0);
fs.writeFileSync(path.join(output, "OFFLINE.txt"),
`Web Blender 用户手册(离线版)\n\n双击 index.html 即可使用,无需联网或启动服务器。\n` +
`搜索框在页面顶部,支持章节全文过滤。\nPDF 手册位于本目录根下。\n\n构建来源:web/dist/manuals\n`);
console.log(`offline-manual-ok dir=${output} files=${files.length} bytes=${bytes}`);