@dooc-dev/dooc 0.0.22 → 0.0.23
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/dist/client.global.js +1 -1
- package/dist/edit.global.js +269 -263
- package/dist/engine/compiler/check.js +17 -0
- package/dist/engine/compiler/export.js +18 -1
- package/dist/engine/compiler/files.js +13 -2
- package/dist/engine/compiler/manifest.js +4 -0
- package/dist/engine/compiler/skills.d.ts +10 -0
- package/dist/engine/compiler/skills.js +95 -0
- package/dist/engine/core/content-metadata.d.ts +7 -1
- package/dist/engine/core/content-metadata.js +52 -18
- package/dist/engine/core/files.d.ts +1 -0
- package/dist/engine/core/files.js +3 -0
- package/dist/frontend/document-application.d.ts +11 -2
- package/dist/frontend/document-application.js +356 -130
- package/dist/frontend/language-picker.js +1 -0
- package/dist/frontend/locales/eng.json +17 -1
- package/dist/frontend/locales/jpn.json +17 -1
- package/dist/frontend/locales/zho.json +17 -1
- package/dist/frontend/mcp-operations.js +57 -1
- package/dist/frontend/nav-focus.d.ts +1 -1
- package/dist/frontend/nav-focus.js +25 -2
- package/dist/frontend/nav-update.js +12 -0
- package/dist/frontend/page-jump.d.ts +3 -0
- package/dist/frontend/page-jump.js +130 -0
- package/dist/frontend/resource-download.d.ts +1 -1
- package/dist/frontend/resource-download.js +118 -28
- package/dist/frontend/resource-library.js +16 -7
- package/dist/frontend/search.js +18 -5
- package/dist/frontend/theme-picker.js +11 -0
- package/dist/manifest.global.js +349 -0
- package/dist/mcp-relay.mjs +71 -1
- package/dist/plugins.global.js +4 -4
- package/dist/server/assets.d.ts +1 -0
- package/dist/server/assets.js +4 -1
- package/dist/server/build-media.d.ts +6 -0
- package/dist/server/build-media.js +136 -0
- package/dist/server/build-output.d.ts +2 -1
- package/dist/server/build-output.js +32 -2
- package/dist/server/build-split.d.ts +15 -0
- package/dist/server/build-split.js +160 -0
- package/dist/server/build.d.ts +6 -1
- package/dist/server/build.js +37 -10
- package/dist/server/cli.js +20 -2
- package/dist/server/mcp.js +14 -1
- package/dist/server/serve.d.ts +21 -2
- package/dist/server/serve.js +26 -20
- package/dist/server/static-client.js +2 -1
- package/dist/server/workspace-server.d.ts +1 -1
- package/dist/server/workspace-server.js +24 -4
- package/dist/subformats.global.js +38 -38
- package/dist/ui.global.js +68 -68
- package/dist/workspace/client.d.ts +1 -1
- package/dist/workspace/client.js +22 -3
- package/dist/workspace/mcp-tools.js +32 -0
- package/dist/workspace/mcp.js +50 -1
- package/dist/workspace/protocol.d.ts +3 -0
- package/dist/workspace/server.d.ts +1 -1
- package/dist/workspace/server.js +14 -3
- package/dist/workspace/site-icon.js +17 -12
- package/dist/workspace/textfile.js +16 -4
- package/dist/workspace-mcp-worker.global.js +234 -119
- package/dist/workspace-reader-mcp-worker.global.js +234 -119
- package/dist/workspace-reader-worker.global.js +234 -119
- package/dist/workspace-worker.global.js +234 -119
- package/package.json +2 -2
package/dist/server/assets.d.ts
CHANGED
package/dist/server/assets.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
1
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
2
2
|
export const prebuilt = import.meta.url.endsWith(".js");
|
|
3
3
|
export const standalone = false;
|
|
4
4
|
export const packageVersion = JSON.parse(readFileSync(new URL(prebuilt ? "../../package.json" : "../../../package.json", import.meta.url), "utf8")).version;
|
|
@@ -6,3 +6,6 @@ export const readInstaller = () => readFileSync(new URL(prebuilt ? "../install.s
|
|
|
6
6
|
export const readReaderAsset = (name) => readFileSync(new URL(name.startsWith("fonts/")
|
|
7
7
|
? `./${name}`
|
|
8
8
|
: `${prebuilt ? ".." : "../../../dist"}/${name}`, import.meta.url));
|
|
9
|
+
export const readGraphAssets = () => new Map(readdirSync(new URL(`${prebuilt ? ".." : "../../../dist"}/graph/`, import.meta.url))
|
|
10
|
+
.filter((name) => name.endsWith(".js"))
|
|
11
|
+
.map((name) => [name, readReaderAsset(`graph/${name}`)]));
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
const run = promisify(execFile);
|
|
7
|
+
/** Optimize published previews only; source downloads retain their original bytes. */
|
|
8
|
+
export const compressMedia = async (data, mime) => {
|
|
9
|
+
const original = { data, mime };
|
|
10
|
+
const image = ["image/png", "image/jpeg", "image/webp"].includes(mime);
|
|
11
|
+
const video = ["video/mp4", "video/webm"].includes(mime);
|
|
12
|
+
if (!image && !video)
|
|
13
|
+
return {
|
|
14
|
+
...original,
|
|
15
|
+
warning: `No preview compressor for ${mime}; keeping original bytes`,
|
|
16
|
+
};
|
|
17
|
+
const directory = await mkdtemp(join(tmpdir(), "dooc-media-"));
|
|
18
|
+
try {
|
|
19
|
+
const input = join(directory, "input");
|
|
20
|
+
const output = join(directory, video ? "output.mp4" : "output.webp");
|
|
21
|
+
await writeFile(input, data);
|
|
22
|
+
// Force the declared container so disguised playlists cannot read other local files.
|
|
23
|
+
const demuxer = {
|
|
24
|
+
"image/png": "png_pipe",
|
|
25
|
+
"image/jpeg": "jpeg_pipe",
|
|
26
|
+
"image/webp": "webp_pipe",
|
|
27
|
+
"video/mp4": "mov",
|
|
28
|
+
"video/webm": "matroska",
|
|
29
|
+
}[mime];
|
|
30
|
+
if (!demuxer)
|
|
31
|
+
throw new Error(`Unsupported container: ${mime}`);
|
|
32
|
+
const { stdout } = await run("ffprobe", [
|
|
33
|
+
"-v",
|
|
34
|
+
"error",
|
|
35
|
+
"-protocol_whitelist",
|
|
36
|
+
"file",
|
|
37
|
+
"-f",
|
|
38
|
+
demuxer,
|
|
39
|
+
"-show_streams",
|
|
40
|
+
"-of",
|
|
41
|
+
"json",
|
|
42
|
+
input,
|
|
43
|
+
], { timeout: 30_000, maxBuffer: 1024 * 1024 });
|
|
44
|
+
const { streams } = JSON.parse(stdout);
|
|
45
|
+
const pictures = streams.filter((stream) => stream.codec_type === "video");
|
|
46
|
+
const sounds = streams.filter((stream) => stream.codec_type === "audio");
|
|
47
|
+
if (pictures.length !== 1 ||
|
|
48
|
+
sounds.length > (video ? 1 : 0) ||
|
|
49
|
+
streams.length !== pictures.length + sounds.length ||
|
|
50
|
+
sounds.some((stream) => (stream.channels ?? 0) > 2) ||
|
|
51
|
+
pictures.some((stream) => ["smpte2084", "arib-std-b67"].includes(stream.color_transfer ?? "")) ||
|
|
52
|
+
(image &&
|
|
53
|
+
(/10|12|16/.test(pictures[0]?.pix_fmt ?? "") ||
|
|
54
|
+
Number(pictures[0]?.nb_frames ?? 1) !== 1 ||
|
|
55
|
+
(mime === "image/png" && data.includes(Buffer.from("acTL"))) ||
|
|
56
|
+
(mime === "image/webp" && data.includes(Buffer.from("ANIM"))))) ||
|
|
57
|
+
(video && /a|10|12|16/.test(pictures[0]?.pix_fmt ?? "")))
|
|
58
|
+
return {
|
|
59
|
+
...original,
|
|
60
|
+
warning: `Unsupported animated image, high bit depth, HDR, video alpha or multiple media tracks (${mime}); keeping original bytes`,
|
|
61
|
+
};
|
|
62
|
+
await run("ffmpeg", [
|
|
63
|
+
"-nostdin",
|
|
64
|
+
"-v",
|
|
65
|
+
"error",
|
|
66
|
+
"-y",
|
|
67
|
+
"-protocol_whitelist",
|
|
68
|
+
"file",
|
|
69
|
+
"-f",
|
|
70
|
+
demuxer,
|
|
71
|
+
"-i",
|
|
72
|
+
input,
|
|
73
|
+
"-map",
|
|
74
|
+
"0:v:0",
|
|
75
|
+
"-threads",
|
|
76
|
+
"1",
|
|
77
|
+
...(video
|
|
78
|
+
? [
|
|
79
|
+
"-map",
|
|
80
|
+
"0:a:0?",
|
|
81
|
+
"-c:v",
|
|
82
|
+
"libx264",
|
|
83
|
+
"-crf",
|
|
84
|
+
"23",
|
|
85
|
+
"-preset",
|
|
86
|
+
"medium",
|
|
87
|
+
"-vf",
|
|
88
|
+
"pad=ceil(iw/2)*2:ceil(ih/2)*2",
|
|
89
|
+
"-pix_fmt",
|
|
90
|
+
"yuv420p",
|
|
91
|
+
"-c:a",
|
|
92
|
+
"aac",
|
|
93
|
+
"-b:a",
|
|
94
|
+
"128k",
|
|
95
|
+
"-movflags",
|
|
96
|
+
"+faststart",
|
|
97
|
+
]
|
|
98
|
+
: [
|
|
99
|
+
"-frames:v",
|
|
100
|
+
"1",
|
|
101
|
+
"-c:v",
|
|
102
|
+
"libwebp",
|
|
103
|
+
"-lossless",
|
|
104
|
+
mime === "image/png" ? "1" : "0",
|
|
105
|
+
"-quality",
|
|
106
|
+
"80",
|
|
107
|
+
]),
|
|
108
|
+
output,
|
|
109
|
+
], { timeout: 300_000, maxBuffer: 1024 * 1024 });
|
|
110
|
+
const compressed = await readFile(output);
|
|
111
|
+
if (!compressed.length)
|
|
112
|
+
throw new Error("Encoder produced an empty file");
|
|
113
|
+
const compatible = image ||
|
|
114
|
+
(mime === "video/mp4" &&
|
|
115
|
+
pictures[0]?.codec_name === "h264" &&
|
|
116
|
+
sounds.every((s) => s.codec_name === "aac")) ||
|
|
117
|
+
(mime === "video/webm" &&
|
|
118
|
+
["vp8", "vp9", "av1"].includes(pictures[0]?.codec_name ?? "") &&
|
|
119
|
+
sounds.every((s) => ["opus", "vorbis"].includes(s.codec_name)));
|
|
120
|
+
return compressed.length < data.length || !compatible
|
|
121
|
+
? { data: compressed, mime: video ? "video/mp4" : "image/webp" }
|
|
122
|
+
: original;
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
const detail = error instanceof Error
|
|
126
|
+
? error.message.split("\n").slice(0, 2).join(" ")
|
|
127
|
+
: String(error);
|
|
128
|
+
return {
|
|
129
|
+
...original,
|
|
130
|
+
warning: `Could not compress ${mime}: ${detail}. Install FFmpeg with libwebp/libx264/AAC support; keeping original bytes`,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
await rm(directory, { recursive: true, force: true });
|
|
135
|
+
}
|
|
136
|
+
};
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* so serving the HTML folder never exposes an archive. Named manifests get their own subfolder.
|
|
4
4
|
*/
|
|
5
5
|
export declare const outputFile: (root: string, format: "html" | "zip", directory?: string) => string;
|
|
6
|
-
/**
|
|
6
|
+
/** Publish immutable assets first, then atomically switch the entry point. */
|
|
7
7
|
export declare const writeBuildOutput: (path: string, bundle: {
|
|
8
8
|
data: string | Buffer;
|
|
9
|
+
files?: ReadonlyMap<string, Buffer>;
|
|
9
10
|
}) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mkdirSync, mkdtempSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { lstatSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync, } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { manifestFile } from "../engine/compiler/manifest.js";
|
|
4
4
|
/**
|
|
@@ -7,13 +7,43 @@ import { manifestFile } from "../engine/compiler/manifest.js";
|
|
|
7
7
|
*/
|
|
8
8
|
export const outputFile = (root, format, directory) => join(directory ??
|
|
9
9
|
join(root, format === "html" ? "build" : "dist", manifestFile(root).replace(/\.?dooc\.yaml$/, "")), format === "html" ? "index.html" : "bundle.zip");
|
|
10
|
-
/**
|
|
10
|
+
/** Publish immutable assets first, then atomically switch the entry point. */
|
|
11
11
|
export const writeBuildOutput = (path, bundle) => {
|
|
12
12
|
const directory = dirname(path);
|
|
13
|
+
for (const [name] of bundle.files ?? [])
|
|
14
|
+
if (!/^dooc-assets\/[a-zA-Z0-9_./-]+$/.test(name) ||
|
|
15
|
+
name.split("/").some((part) => ["", ".", ".."].includes(part)))
|
|
16
|
+
throw new Error(`Invalid build asset path: ${name}`);
|
|
13
17
|
mkdirSync(directory, { recursive: true });
|
|
14
18
|
const stage = mkdtempSync(join(directory, ".dooc-build-"));
|
|
15
19
|
try {
|
|
16
20
|
writeFileSync(join(stage, "artifact"), bundle.data);
|
|
21
|
+
const pending = [];
|
|
22
|
+
for (const [name, data] of bundle.files ?? []) {
|
|
23
|
+
const parts = name.split("/");
|
|
24
|
+
for (let i = 1; i < parts.length; i++) {
|
|
25
|
+
const parent = join(directory, ...parts.slice(0, i));
|
|
26
|
+
const stat = lstatSync(parent, { throwIfNoEntry: false });
|
|
27
|
+
if (stat && !stat.isDirectory())
|
|
28
|
+
throw new Error(`Build asset directory is not a regular directory: ${parent}`);
|
|
29
|
+
}
|
|
30
|
+
const target = join(directory, name);
|
|
31
|
+
const stat = lstatSync(target, { throwIfNoEntry: false });
|
|
32
|
+
if (stat) {
|
|
33
|
+
if (!stat.isFile() || !readFileSync(target).equals(data))
|
|
34
|
+
throw new Error(`Build asset conflicts with an existing file: ${target}`);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const staged = join(stage, name);
|
|
38
|
+
mkdirSync(dirname(staged), { recursive: true });
|
|
39
|
+
writeFileSync(staged, data);
|
|
40
|
+
pending.push(name);
|
|
41
|
+
}
|
|
42
|
+
for (const name of pending) {
|
|
43
|
+
const target = join(directory, name);
|
|
44
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
45
|
+
renameSync(join(stage, name), target);
|
|
46
|
+
}
|
|
17
47
|
renameSync(join(stage, "artifact"), path);
|
|
18
48
|
}
|
|
19
49
|
finally {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PublishOutput } from "../frontend/document-application.js";
|
|
2
|
+
export interface SplitBuildOptions {
|
|
3
|
+
split?: boolean;
|
|
4
|
+
compress?: boolean;
|
|
5
|
+
maxFileSize?: string | number;
|
|
6
|
+
maxBuildSize?: string | number;
|
|
7
|
+
warningsAsErrors?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const buildSize: (value: string | number | undefined, option: string) => number | undefined;
|
|
10
|
+
export declare const checkBuildSize: (files: ReadonlyMap<string, Buffer>, maxFileSize?: number, maxBuildSize?: number) => number;
|
|
11
|
+
export declare const splitBuild: (render: (output: PublishOutput) => string, options: SplitBuildOptions, fontSources?: readonly string[], graph?: ReadonlyMap<string, Buffer>) => Promise<{
|
|
12
|
+
data: string;
|
|
13
|
+
files: Map<string, Buffer>;
|
|
14
|
+
warnings: string[];
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { assetReferences } from "../engine/compiler/asset-references.js";
|
|
3
|
+
import { compressMedia } from "./build-media.js";
|
|
4
|
+
export const buildSize = (value, option) => {
|
|
5
|
+
if (value === undefined)
|
|
6
|
+
return undefined;
|
|
7
|
+
const match = typeof value === "string" &&
|
|
8
|
+
/^(\d+(?:\.\d+)?)\s*(B|KB|MB|GB|KiB|MiB|GiB)?$/i.exec(value.trim());
|
|
9
|
+
const units = {
|
|
10
|
+
b: 1,
|
|
11
|
+
kb: 1000,
|
|
12
|
+
mb: 1000 ** 2,
|
|
13
|
+
gb: 1000 ** 3,
|
|
14
|
+
kib: 1024,
|
|
15
|
+
mib: 1024 ** 2,
|
|
16
|
+
gib: 1024 ** 3,
|
|
17
|
+
};
|
|
18
|
+
const bytes = typeof value === "number"
|
|
19
|
+
? value
|
|
20
|
+
: match
|
|
21
|
+
? Number(match[1]) * (units[match[2]?.toLowerCase() ?? "b"] ?? 1)
|
|
22
|
+
: Number.NaN;
|
|
23
|
+
if (!Number.isSafeInteger(bytes) || bytes <= 0)
|
|
24
|
+
throw new Error(`${option} must be a positive byte count or size such as 25MiB or 100MB`);
|
|
25
|
+
return bytes;
|
|
26
|
+
};
|
|
27
|
+
export const checkBuildSize = (files, maxFileSize, maxBuildSize) => {
|
|
28
|
+
const errors = [];
|
|
29
|
+
let bytes = 0;
|
|
30
|
+
for (const [name, data] of files) {
|
|
31
|
+
bytes += data.length;
|
|
32
|
+
if (maxFileSize !== undefined && data.length > maxFileSize)
|
|
33
|
+
errors.push(`${name}: ${data.length} bytes exceeds --max-file-size (${maxFileSize} bytes)`);
|
|
34
|
+
}
|
|
35
|
+
if (maxBuildSize !== undefined && bytes > maxBuildSize)
|
|
36
|
+
errors.push(`Build: ${bytes} bytes exceeds --max-build-size (${maxBuildSize} bytes)`);
|
|
37
|
+
if (errors.length)
|
|
38
|
+
throw new Error(`${errors.join("\n")}\nTry --compress, reduce the resource size, split a large document, or increase the limit. No output was replaced.`);
|
|
39
|
+
return bytes;
|
|
40
|
+
};
|
|
41
|
+
const hash = (data) => createHash("sha256").update(data).digest("hex");
|
|
42
|
+
const extensions = {
|
|
43
|
+
"text/plain": "txt",
|
|
44
|
+
"text/css": "css",
|
|
45
|
+
"image/png": "png",
|
|
46
|
+
"image/jpeg": "jpg",
|
|
47
|
+
"image/webp": "webp",
|
|
48
|
+
"image/gif": "gif",
|
|
49
|
+
"image/avif": "avif",
|
|
50
|
+
"image/bmp": "bmp",
|
|
51
|
+
"video/mp4": "mp4",
|
|
52
|
+
"video/webm": "webm",
|
|
53
|
+
"audio/mpeg": "mp3",
|
|
54
|
+
"audio/ogg": "ogg",
|
|
55
|
+
"audio/wav": "wav",
|
|
56
|
+
"audio/mp4": "m4a",
|
|
57
|
+
"audio/webm": "webm",
|
|
58
|
+
"application/pdf": "pdf",
|
|
59
|
+
"font/woff2": "woff2",
|
|
60
|
+
"font/woff": "woff",
|
|
61
|
+
"font/ttf": "ttf",
|
|
62
|
+
"font/otf": "otf",
|
|
63
|
+
"application/font-woff": "woff",
|
|
64
|
+
"application/font-woff2": "woff2",
|
|
65
|
+
};
|
|
66
|
+
export const splitBuild = async (render, options, fontSources = [], graph = new Map()) => {
|
|
67
|
+
const files = new Map();
|
|
68
|
+
const sources = new Map();
|
|
69
|
+
const warnings = new Set();
|
|
70
|
+
const put = (data, extension) => {
|
|
71
|
+
const name = `dooc-assets/${hash(data)}.${extension}`;
|
|
72
|
+
files.set(name, Buffer.from(data));
|
|
73
|
+
return `./${name}`;
|
|
74
|
+
};
|
|
75
|
+
let graphEntry;
|
|
76
|
+
if (graph.size) {
|
|
77
|
+
const digest = createHash("sha256");
|
|
78
|
+
for (const [name, data] of [...graph].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))
|
|
79
|
+
digest.update(`${name}\0${data.length}\0`).update(data);
|
|
80
|
+
const directory = `dooc-assets/${digest.digest("hex")}`;
|
|
81
|
+
for (const [name, data] of graph)
|
|
82
|
+
files.set(`${directory}/${name}`, data);
|
|
83
|
+
graphEntry = `./${directory}/schema-graph-global.js`;
|
|
84
|
+
}
|
|
85
|
+
let html = render({
|
|
86
|
+
asset: (source, extension) => {
|
|
87
|
+
const url = `./dooc-assets/${hash(source)}.${extension}`;
|
|
88
|
+
sources.set(url, { source, extension });
|
|
89
|
+
return url;
|
|
90
|
+
},
|
|
91
|
+
graph: graphEntry,
|
|
92
|
+
});
|
|
93
|
+
const resources = new Map();
|
|
94
|
+
const resourceExtensions = new Map();
|
|
95
|
+
const collect = (url, embedded) => {
|
|
96
|
+
const key = `${embedded}:${url}`;
|
|
97
|
+
if (resources.has(key))
|
|
98
|
+
return url;
|
|
99
|
+
// shortcut: authored non-base64 data URLs stay inline; decode them if the compiler starts emitting them.
|
|
100
|
+
const match = /^data:([^,]*);base64,([^#]*)(#.*)?$/is.exec(url);
|
|
101
|
+
if (!match)
|
|
102
|
+
return url;
|
|
103
|
+
const mime = (match[1]?.split(";")[0] || "text/plain").toLowerCase();
|
|
104
|
+
// Keep active markup in its original isolated data URL context.
|
|
105
|
+
if (["text/html", "image/svg+xml", "text/javascript", "application/javascript"].includes(mime))
|
|
106
|
+
return url;
|
|
107
|
+
if (embedded && !extensions[mime]) {
|
|
108
|
+
if (options.compress)
|
|
109
|
+
warnings.add(`No preview compressor for ${mime}; keeping its inline MIME type`);
|
|
110
|
+
return url;
|
|
111
|
+
}
|
|
112
|
+
const data = Buffer.from(match[2] ?? "", "base64");
|
|
113
|
+
const digest = hash(data);
|
|
114
|
+
if (extensions[mime] || !resourceExtensions.has(digest))
|
|
115
|
+
resourceExtensions.set(digest, extensions[mime] ?? "bin");
|
|
116
|
+
resources.set(key, { embedded, data, mime, fragment: match[3] ?? "" });
|
|
117
|
+
return url;
|
|
118
|
+
};
|
|
119
|
+
assetReferences(html, "html", collect);
|
|
120
|
+
for (const { source, extension } of sources.values())
|
|
121
|
+
if (extension !== "js")
|
|
122
|
+
assetReferences(source, extension, collect);
|
|
123
|
+
for (const source of fontSources)
|
|
124
|
+
assetReferences(`a{src:${source}}`, "css", collect);
|
|
125
|
+
const replacements = new Map();
|
|
126
|
+
for (const [key, resource] of resources) {
|
|
127
|
+
const result = options.compress &&
|
|
128
|
+
resource.embedded &&
|
|
129
|
+
(/^(image|video|audio)\//.test(resource.mime) || resource.mime === "application/pdf")
|
|
130
|
+
? await compressMedia(resource.data, resource.mime)
|
|
131
|
+
: resource;
|
|
132
|
+
if ("warning" in result && result.warning)
|
|
133
|
+
warnings.add(`${hash(resource.data).slice(0, 12)}: ${result.warning}`);
|
|
134
|
+
const extension = resourceExtensions.get(hash(result.data)) ?? extensions[result.mime] ?? "bin";
|
|
135
|
+
replacements.set(key, put(result.data, extension) + resource.fragment);
|
|
136
|
+
}
|
|
137
|
+
const replace = (url, embedded) => replacements.get(`${embedded}:${url}`) ?? url;
|
|
138
|
+
html = assetReferences(html, "html", replace);
|
|
139
|
+
const fonts = fontSources.map((font) => [
|
|
140
|
+
JSON.stringify(font),
|
|
141
|
+
JSON.stringify(assetReferences(`a{src:${font}}`, "css", replace).slice(6, -1)),
|
|
142
|
+
]);
|
|
143
|
+
for (const [url, { source, extension }] of sources) {
|
|
144
|
+
let data = source;
|
|
145
|
+
if (extension === "js") {
|
|
146
|
+
for (const [before, after] of fonts)
|
|
147
|
+
data = data.replaceAll(before, after);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
data = assetReferences(source, extension, (url, embedded) => {
|
|
151
|
+
const next = replace(url, embedded);
|
|
152
|
+
return extension === "css" && next.startsWith("./dooc-assets/")
|
|
153
|
+
? next.slice("./dooc-assets/".length)
|
|
154
|
+
: next;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
html = html.replaceAll(`"${url}"`, `"${put(data, extension)}"`);
|
|
158
|
+
}
|
|
159
|
+
return { data: html, files, warnings: [...warnings] };
|
|
160
|
+
};
|
package/dist/server/build.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PluginTransport } from "../plugins/transport.js";
|
|
2
2
|
import { type PreviewSettings } from "../engine/core/previewers.js";
|
|
3
|
-
|
|
3
|
+
import { type SplitBuildOptions } from "./build-split.js";
|
|
4
|
+
export interface BuildOptions extends SplitBuildOptions {
|
|
4
5
|
format: "html" | "zip";
|
|
5
6
|
urlPreview?: "embed" | "network";
|
|
6
7
|
mode?: "static" | "live";
|
|
@@ -16,6 +17,10 @@ export interface BuildOptions {
|
|
|
16
17
|
}
|
|
17
18
|
export interface BuildResult {
|
|
18
19
|
data: string | Buffer;
|
|
20
|
+
/** Additional files relative to the HTML entry point's directory. */
|
|
21
|
+
files?: ReadonlyMap<string, Buffer>;
|
|
22
|
+
/** Actual bytes of the entry point and its unique output files. */
|
|
23
|
+
bytes?: number;
|
|
19
24
|
docs: number;
|
|
20
25
|
warnings?: string[];
|
|
21
26
|
version?: string;
|
package/dist/server/build.js
CHANGED
|
@@ -16,6 +16,7 @@ import { selectCodeGrammars } from "../engine/core/code-grammars.js";
|
|
|
16
16
|
import { parseVersionConfig } from "../engine/core/document-version.js";
|
|
17
17
|
import { parsePreviewSettings } from "../engine/core/previewers.js";
|
|
18
18
|
import { loadBuildPlugins, pluginSnapshot } from "./build-plugins.js";
|
|
19
|
+
import { buildSize, checkBuildSize, splitBuild } from "./build-split.js";
|
|
19
20
|
import { createDocumentVersions } from "./document-versions.js";
|
|
20
21
|
import { loadSiteLanguages } from "./languages.js";
|
|
21
22
|
import { loadReaderPlugins } from "./plugin-config.js";
|
|
@@ -25,6 +26,14 @@ export { writeBuildOutput } from "./build-output.js";
|
|
|
25
26
|
/** Build one artifact from the manifest and its managed content. */
|
|
26
27
|
export const buildBundle = async (root, options) => {
|
|
27
28
|
const format = options.format;
|
|
29
|
+
for (const key of ["split", "compress", "warningsAsErrors"])
|
|
30
|
+
if (options[key] !== undefined && typeof options[key] !== "boolean")
|
|
31
|
+
throw new Error(`${key} must be a boolean`);
|
|
32
|
+
const maxFileSize = buildSize(options.maxFileSize, "--max-file-size");
|
|
33
|
+
const maxBuildSize = buildSize(options.maxBuildSize, "--max-build-size");
|
|
34
|
+
const split = !!(options.split || options.compress || maxFileSize || maxBuildSize);
|
|
35
|
+
if (split && format !== "html")
|
|
36
|
+
throw new Error("Split builds, compression and size limits apply to HTML only");
|
|
28
37
|
if (options.download !== undefined && !["easy", "normal", "block"].includes(options.download))
|
|
29
38
|
throw new Error("download must be easy | normal | block");
|
|
30
39
|
if (options.download !== undefined && format !== "html")
|
|
@@ -127,7 +136,7 @@ export const buildBundle = async (root, options) => {
|
|
|
127
136
|
commitVersion: stored?.commit,
|
|
128
137
|
};
|
|
129
138
|
const config = await loadSiteLanguages(root);
|
|
130
|
-
const { bundleClient, publishHtml, siteFrom } = await import("./serve.js");
|
|
139
|
+
const { bundleClient, bundleGraph, publishHtml, siteFrom } = await import("./serve.js");
|
|
131
140
|
const linkable = new Set(filesSnapshot(root).files.map((file) => file.path));
|
|
132
141
|
const site = {
|
|
133
142
|
...siteFrom(compiled, config.languages, config),
|
|
@@ -149,16 +158,34 @@ export const buildBundle = async (root, options) => {
|
|
|
149
158
|
site.codeGrammars = selectCodeGrammars(site.codeGrammars ?? [], code.map((block) => block.lang ?? "text"));
|
|
150
159
|
const diagrams = blocks.some((block) => block.type === "schemaGraph" ||
|
|
151
160
|
(block.type === "code" && block.lang === "mermaid" && !block.unavailable));
|
|
152
|
-
const
|
|
153
|
-
?
|
|
154
|
-
|
|
155
|
-
blocks.some((block) => block.type === "
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
161
|
+
const [graphJs, codeJs, pluginJs, subformatJs] = await Promise.all([
|
|
162
|
+
diagrams && !split ? bundleClient("schema-graph-global.tsx") : "",
|
|
163
|
+
code.length ? bundleClient("code-highlight.ts") : "",
|
|
164
|
+
options.mode === "live" && blocks.some((block) => block.type === "external")
|
|
165
|
+
? bundleClient("published-plugins.ts")
|
|
166
|
+
: "",
|
|
167
|
+
compiled.docs.some((doc) => doc.subformat || doc.library) ||
|
|
168
|
+
blocks.some((block) => block.type === "code" && block.subformat)
|
|
169
|
+
? bundleClient("published-subformats.ts")
|
|
170
|
+
: "",
|
|
171
|
+
]);
|
|
172
|
+
const render = (output) => {
|
|
173
|
+
const html = publishHtml(site, graphJs, undefined, codeJs, options.mode === "live" ? "live" : urlPreview === "embed" ? "static" : "network", pluginJs, subformatJs, output);
|
|
174
|
+
return version
|
|
160
175
|
? html.replace("</head>", `<meta name="dooc-version" content="${version}">${revision ? `<meta name="dooc-revision" content="${revision}">` : ""}</head>`)
|
|
161
|
-
: html
|
|
176
|
+
: html;
|
|
177
|
+
};
|
|
178
|
+
const output = split
|
|
179
|
+
? await splitBuild(render, options, site.fonts.map((font) => font.source), diagrams ? await bundleGraph() : undefined)
|
|
180
|
+
: { data: render(), files: undefined, warnings: [] };
|
|
181
|
+
if (options.warningsAsErrors && output.warnings.length)
|
|
182
|
+
throw new Error(`Build warnings treated as errors:\n${output.warnings.join("\n")}`);
|
|
183
|
+
const bytes = split
|
|
184
|
+
? checkBuildSize(new Map([["index.html", Buffer.from(output.data)], ...(output.files ?? [])]), maxFileSize, maxBuildSize)
|
|
185
|
+
: Buffer.byteLength(output.data);
|
|
186
|
+
return {
|
|
187
|
+
...output,
|
|
188
|
+
bytes,
|
|
162
189
|
docs: compiled.docs.length,
|
|
163
190
|
version,
|
|
164
191
|
revision,
|
package/dist/server/cli.js
CHANGED
|
@@ -413,6 +413,11 @@ Report:
|
|
|
413
413
|
"reader-plugins": { type: "string" },
|
|
414
414
|
"source-url": { type: "string" },
|
|
415
415
|
download: { type: "string" },
|
|
416
|
+
split: { type: "boolean" },
|
|
417
|
+
compress: { type: "boolean" },
|
|
418
|
+
"max-file-size": { type: "string" },
|
|
419
|
+
"max-build-size": { type: "string" },
|
|
420
|
+
"warnings-as-errors": { type: "boolean" },
|
|
416
421
|
help: { type: "boolean", short: "h" },
|
|
417
422
|
},
|
|
418
423
|
});
|
|
@@ -438,10 +443,18 @@ options:
|
|
|
438
443
|
network preserve URL references without downloading them at build time
|
|
439
444
|
embed snapshot URL content and assets into the HTML
|
|
440
445
|
--reader-plugins <module> inject trusted build plugins
|
|
446
|
+
--split separate pages, JS, CSS and resources; serve over HTTP(S)
|
|
447
|
+
--compress optimize image/video previews using FFmpeg; implies --split
|
|
448
|
+
PNG: lossless WebP; JPEG/WebP/video: lossy; sources stay intact
|
|
449
|
+
--max-file-size <size> per-output-file byte limit, e.g. 25MiB; implies --split
|
|
450
|
+
--max-build-size <size> total unique output bytes, e.g. 100MiB; implies --split
|
|
451
|
+
no limits by default; includes HTML, JS, CSS and resources
|
|
452
|
+
--warnings-as-errors stop if a requested compressor is unsupported or unavailable
|
|
441
453
|
--help, -h show this help
|
|
442
454
|
|
|
443
455
|
Output:
|
|
444
|
-
|
|
456
|
+
Assets go in dooc-assets/ before the HTML entry point is replaced.
|
|
457
|
+
Older assets and unrelated files are preserved; use a fresh output folder for deployment.
|
|
445
458
|
Source files are never rewritten.
|
|
446
459
|
|
|
447
460
|
HTML modes:
|
|
@@ -522,12 +535,17 @@ URL handling:
|
|
|
522
535
|
pluginModule: values["reader-plugins"],
|
|
523
536
|
sourceUrl: values["source-url"],
|
|
524
537
|
download: values.download,
|
|
538
|
+
split: values.split,
|
|
539
|
+
compress: values.compress,
|
|
540
|
+
maxFileSize: values["max-file-size"],
|
|
541
|
+
maxBuildSize: values["max-build-size"],
|
|
542
|
+
warningsAsErrors: values["warnings-as-errors"],
|
|
525
543
|
});
|
|
526
544
|
writeBuildOutput(out, bundle);
|
|
527
545
|
bundle.commitVersion?.();
|
|
528
546
|
for (const warning of bundle.warnings ?? [])
|
|
529
547
|
console.warn(`Warning: ${warning}`);
|
|
530
|
-
console.log(`${out} — ${bundle.docs} docs${bundle.version ? `, version ${bundle.version}` : ""} (url_preview=${urlPreview})`);
|
|
548
|
+
console.log(`${out} — ${bundle.docs} docs${bundle.version ? `, version ${bundle.version}` : ""}${bundle.files ? `, ${bundle.files.size + 1} files, ${bundle.bytes} bytes` : ""} (url_preview=${urlPreview})`);
|
|
531
549
|
}
|
|
532
550
|
catch (error) {
|
|
533
551
|
fail(error instanceof Error ? error.message : String(error));
|
package/dist/server/mcp.js
CHANGED
|
@@ -30,6 +30,11 @@ export const createTools = (root, options = {}) => {
|
|
|
30
30
|
auth: a.auth,
|
|
31
31
|
sourceUrl: a.source_url,
|
|
32
32
|
download: a.download,
|
|
33
|
+
split: a.split,
|
|
34
|
+
compress: a.compress,
|
|
35
|
+
maxFileSize: a.max_file_size,
|
|
36
|
+
maxBuildSize: a.max_build_size,
|
|
37
|
+
warningsAsErrors: a.warnings_as_errors,
|
|
33
38
|
previews: options.previews,
|
|
34
39
|
});
|
|
35
40
|
const path = textfilePath(root, file);
|
|
@@ -38,7 +43,15 @@ export const createTools = (root, options = {}) => {
|
|
|
38
43
|
return {
|
|
39
44
|
file,
|
|
40
45
|
path,
|
|
41
|
-
bytes: Buffer.byteLength(bundle.data),
|
|
46
|
+
bytes: bundle.bytes ?? Buffer.byteLength(bundle.data),
|
|
47
|
+
...(bundle.files
|
|
48
|
+
? {
|
|
49
|
+
files: [...bundle.files].map(([file, data]) => ({
|
|
50
|
+
file,
|
|
51
|
+
bytes: data.length,
|
|
52
|
+
})),
|
|
53
|
+
}
|
|
54
|
+
: {}),
|
|
42
55
|
docs: bundle.docs,
|
|
43
56
|
...(bundle.version ? { version: bundle.version } : {}),
|
|
44
57
|
...(bundle.revision ? { revision: bundle.revision } : {}),
|
package/dist/server/serve.d.ts
CHANGED
|
@@ -26,11 +26,28 @@ export declare const siteFrom: ({ title, icon, iconVariants, docs, terms, figure
|
|
|
26
26
|
id: string;
|
|
27
27
|
name: string;
|
|
28
28
|
abs: string;
|
|
29
|
-
} | undefined, navGroupsHtml: (mode: ServeMode, site: import("../frontend/document-application.js").Site,
|
|
29
|
+
} | undefined, navGroupsHtml: (mode: ServeMode, site: Pick<import("../frontend/document-application.js").Site, "title" | "icon" | "subformats" | "workspace" | "contentLanguage"> & {
|
|
30
|
+
entries: {
|
|
31
|
+
id: string;
|
|
32
|
+
file: string;
|
|
33
|
+
name?: string | undefined;
|
|
34
|
+
icon?: string | undefined;
|
|
35
|
+
url?: string | undefined;
|
|
36
|
+
root?: boolean | undefined;
|
|
37
|
+
origin?: string | undefined;
|
|
38
|
+
subformat?: import("../engine/core/subformats.js").SubformatCollection | undefined;
|
|
39
|
+
library?: string | undefined;
|
|
40
|
+
parent?: string | undefined;
|
|
41
|
+
included?: boolean | undefined;
|
|
42
|
+
frontmatter: import("./index.js").Frontmatter | undefined;
|
|
43
|
+
sourceFile?: string | undefined;
|
|
44
|
+
translatedLanguages?: string[] | undefined;
|
|
45
|
+
}[];
|
|
46
|
+
}, currentId?: string, currentRes?: string) => string, textfilePreviewHtml: (site: import("../frontend/document-application.js").Site, file: string, source: string) => string, textfilePreviewErrors: (site: import("../frontend/document-application.js").Site, file: string, source: string) => string[], resourcesMain: (site: import("../frontend/document-application.js").Site, rest: string) => {
|
|
30
47
|
title: string;
|
|
31
48
|
main: string;
|
|
32
49
|
sourceFile?: string;
|
|
33
|
-
} | undefined, publishHtml: (site: import("../frontend/document-application.js").Site, graphJs: string, title?: string, codeJs?: string, mode?: "static" | "network" | "live", pluginJs?: string, subformatJs?: string) => string, languageFieldHtml: (defaultLang: string, language?: string, translatedLanguages?: readonly string[], declaredLanguages?: readonly string[]) => string, editorBoot: (entry: import("../frontend/document-application.js").Entry, site: import("../frontend/document-application.js").Site) => import("../frontend/document-application.js").EditorBoot, pageDataResponse: (site: import("../frontend/document-application.js").Site, path: unknown) => {
|
|
50
|
+
} | undefined, publishHtml: (site: import("../frontend/document-application.js").Site, graphJs: string, title?: string, codeJs?: string, mode?: "static" | "network" | "live", pluginJs?: string, subformatJs?: string, output?: import("../frontend/document-application.js").PublishOutput) => string, languageFieldHtml: (defaultLang: string, language?: string, translatedLanguages?: readonly string[], declaredLanguages?: readonly string[]) => string, editorBoot: (entry: import("../frontend/document-application.js").Entry, site: import("../frontend/document-application.js").Site) => import("../frontend/document-application.js").EditorBoot, pageDataResponse: (site: import("../frontend/document-application.js").Site, path: unknown) => {
|
|
34
51
|
status: number;
|
|
35
52
|
body: unknown;
|
|
36
53
|
};
|
|
@@ -47,6 +64,8 @@ export interface BundleCache {
|
|
|
47
64
|
export declare const createBundleCache: () => BundleCache;
|
|
48
65
|
/** Minified client bundle shared by local viewing and published HTML. */
|
|
49
66
|
export declare const bundleClient: (entry: string) => Promise<string>;
|
|
67
|
+
/** Shared ESM diagram chunks for local readers and split publications. */
|
|
68
|
+
export declare const bundleGraph: () => Promise<Map<string, Buffer>>;
|
|
50
69
|
export declare const startServer: (mode: ServeMode, port?: number, pluginModule?: string, startup?: {
|
|
51
70
|
open?: boolean;
|
|
52
71
|
file?: string;
|