@cudoment/cudoc 0.4.0 → 0.6.0
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 +4 -3
- package/dist/document.d.ts +36 -1
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +54 -3
- package/dist/document.js.map +1 -1
- package/dist/internal/core/mdx/imports.d.ts +21 -0
- package/dist/internal/core/mdx/imports.d.ts.map +1 -0
- package/dist/internal/core/mdx/imports.js +80 -0
- package/dist/internal/core/mdx/imports.js.map +1 -0
- package/dist/internal/core/mdx/index.d.ts +1 -0
- package/dist/internal/core/mdx/index.d.ts.map +1 -1
- package/dist/internal/core/mdx/index.js +1 -0
- package/dist/internal/core/mdx/index.js.map +1 -1
- package/dist/internal/core/query/sections.d.ts +6 -0
- package/dist/internal/core/query/sections.d.ts.map +1 -1
- package/dist/internal/core/query/sections.js +8 -2
- package/dist/internal/core/query/sections.js.map +1 -1
- package/dist/internal/transforms/table-column-layout/create-table.d.ts.map +1 -1
- package/dist/internal/transforms/table-column-layout/create-table.js +40 -17
- package/dist/internal/transforms/table-column-layout/create-table.js.map +1 -1
- package/dist/internal/transforms/table-column-layout/index.d.ts +32 -0
- package/dist/internal/transforms/table-column-layout/index.d.ts.map +1 -1
- package/dist/internal/transforms/table-column-layout/index.js +66 -0
- package/dist/internal/transforms/table-column-layout/index.js.map +1 -1
- package/dist/markdown.d.ts +8 -0
- package/dist/markdown.d.ts.map +1 -1
- package/dist/markdown.js +9 -1
- package/dist/markdown.js.map +1 -1
- package/dist/node/check.d.ts +12 -6
- package/dist/node/check.d.ts.map +1 -1
- package/dist/node/check.js +460 -79
- package/dist/node/check.js.map +1 -1
- package/dist/node/cli.js +2 -56
- package/dist/node/cli.js.map +1 -1
- package/dist/node/collect.d.ts +41 -0
- package/dist/node/collect.d.ts.map +1 -0
- package/dist/node/collect.js +351 -0
- package/dist/node/collect.js.map +1 -0
- package/dist/node/command.d.ts +23 -0
- package/dist/node/command.d.ts.map +1 -0
- package/dist/node/command.js +116 -0
- package/dist/node/command.js.map +1 -0
- package/dist/node/dataset.d.ts +14 -1
- package/dist/node/dataset.d.ts.map +1 -1
- package/dist/node/dataset.js +44 -5
- package/dist/node/dataset.js.map +1 -1
- package/dist/node/glob.d.ts +21 -0
- package/dist/node/glob.d.ts.map +1 -0
- package/dist/node/glob.js +61 -0
- package/dist/node/glob.js.map +1 -0
- package/dist/node/library.d.ts +76 -6
- package/dist/node/library.d.ts.map +1 -1
- package/dist/node/library.js +63 -137
- package/dist/node/library.js.map +1 -1
- package/dist/node/load-ast.d.ts.map +1 -1
- package/dist/node/load-ast.js +4 -1
- package/dist/node/load-ast.js.map +1 -1
- package/dist/node/local-target.d.ts +39 -8
- package/dist/node/local-target.d.ts.map +1 -1
- package/dist/node/local-target.js +94 -13
- package/dist/node/local-target.js.map +1 -1
- package/dist/node/prepare-embeds.d.ts +52 -3
- package/dist/node/prepare-embeds.d.ts.map +1 -1
- package/dist/node/prepare-embeds.js +134 -8
- package/dist/node/prepare-embeds.js.map +1 -1
- package/dist/node/references.d.ts +39 -0
- package/dist/node/references.d.ts.map +1 -0
- package/dist/node/references.js +101 -0
- package/dist/node/references.js.map +1 -0
- package/dist/node/replace.d.ts +65 -0
- package/dist/node/replace.d.ts.map +1 -0
- package/dist/node/replace.js +285 -0
- package/dist/node/replace.js.map +1 -0
- package/dist/node/resolve-embed.d.ts +79 -1
- package/dist/node/resolve-embed.d.ts.map +1 -1
- package/dist/node/resolve-embed.js +480 -143
- package/dist/node/resolve-embed.js.map +1 -1
- package/dist/node/roots.d.ts +78 -0
- package/dist/node/roots.d.ts.map +1 -0
- package/dist/node/roots.js +170 -0
- package/dist/node/roots.js.map +1 -0
- package/dist/node/storage.d.ts +21 -3
- package/dist/node/storage.d.ts.map +1 -1
- package/dist/node/storage.js +242 -20
- package/dist/node/storage.js.map +1 -1
- package/dist/node/watch.d.ts +86 -0
- package/dist/node/watch.d.ts.map +1 -0
- package/dist/node/watch.js +174 -0
- package/dist/node/watch.js.map +1 -0
- package/dist/paged.d.ts +34 -0
- package/dist/paged.d.ts.map +1 -0
- package/dist/paged.js +44 -0
- package/dist/paged.js.map +1 -0
- package/dist/render.d.ts +1 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +14 -0
- package/dist/render.js.map +1 -1
- package/dist/sections.d.ts.map +1 -1
- package/dist/sections.js +7 -3
- package/dist/sections.js.map +1 -1
- package/package.json +29 -16
- package/styles.css +5 -2
package/dist/node/library.js
CHANGED
|
@@ -1,145 +1,53 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { compileDocument } from "../markdown.js";
|
|
4
|
-
import { collectSections } from "../sections.js";
|
|
5
|
-
import { findHeadingByAnchorId, findSectionEnd, } from "../internal/core/query/sections.js";
|
|
6
|
-
import { buildExportedAst, resolveExportAstOptions } from "./export-ast.js";
|
|
7
3
|
import { validateAstContract } from "../internal/core/ast/validate.js";
|
|
8
|
-
import { hash,
|
|
4
|
+
import { hash, safePath, publishDirectory } from "./storage.js";
|
|
5
|
+
import { resolveRoots } from "./roots.js";
|
|
6
|
+
import { collectLibrary, collectLibraryAsync, LIBRARY_SCHEMA_VERSION, } from "./collect.js";
|
|
7
|
+
export { resolveRoots, documentIdOf, libraryPathOf, sourceFileOf, } from "./roots.js";
|
|
8
|
+
export { LIBRARY_SCHEMA_VERSION } from "./collect.js";
|
|
9
|
+
/**
|
|
10
|
+
* Compiles every document and publishes the library to `outDir`, replacing
|
|
11
|
+
* what was there in one step. Prepared embeds are not part of it: a separate
|
|
12
|
+
* `prepareEmbeds` adds `embeds.json`, and `collectDocuments` does both into
|
|
13
|
+
* one publication.
|
|
14
|
+
*/
|
|
15
|
+
export function buildDocuments(options) {
|
|
16
|
+
const collection = collectLibrary(options);
|
|
17
|
+
publishDirectory(collection.inputs, collection.outDir, collection.write);
|
|
18
|
+
return collection.library;
|
|
19
|
+
}
|
|
9
20
|
/** Collect async framework compilers before publishing or resolving any embeds. */
|
|
10
21
|
export async function buildDocumentsAsync(options) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const source = fs.readFileSync(filePath, "utf8");
|
|
15
|
-
const id = posix(path.relative(options.sourceRoot, filePath)).replace(/\.mdx?$/i, "");
|
|
16
|
-
const format = path.extname(filePath).toLowerCase() === ".mdx" ? "mdx" : "md";
|
|
17
|
-
compiled.set(id, {
|
|
18
|
-
source,
|
|
19
|
-
result: await compiler(source, {
|
|
20
|
-
id,
|
|
21
|
-
filePath,
|
|
22
|
-
options: { ...rest, format },
|
|
23
|
-
}),
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
const library = buildDocuments({
|
|
27
|
-
...rest,
|
|
28
|
-
compiler(source, context) {
|
|
29
|
-
const cached = compiled.get(context.id);
|
|
30
|
-
if (!cached || cached.source !== source)
|
|
31
|
-
throw new Error(`cudoc: source changed during collection: ${context.id}`);
|
|
32
|
-
return cached.result;
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
delete library.compiler;
|
|
36
|
-
library.asyncCompiler = compiler;
|
|
37
|
-
return library;
|
|
38
|
-
}
|
|
39
|
-
export function snapshotSource(text, tree, format) {
|
|
40
|
-
const sections = {};
|
|
41
|
-
for (const section of collectSections(tree)) {
|
|
42
|
-
const nodes = section.tree.children;
|
|
43
|
-
const location = findHeadingByAnchorId(tree, section.anchorId);
|
|
44
|
-
const siblings = location.parent.children;
|
|
45
|
-
const endIndex = findSectionEnd(location.parent, location.index, section.heading.depth);
|
|
46
|
-
const start = section.heading.position?.start.offset;
|
|
47
|
-
const end = siblings[endIndex]?.position?.start.offset ??
|
|
48
|
-
location.parent.position?.end.offset ??
|
|
49
|
-
text.length;
|
|
50
|
-
const ownEnd = siblings
|
|
51
|
-
.slice(location.index + 1, endIndex)
|
|
52
|
-
.find((n) => n.type === "heading")?.position?.start.offset ?? end;
|
|
53
|
-
if (start === undefined || end === undefined)
|
|
54
|
-
continue;
|
|
55
|
-
const dependencies = nodes
|
|
56
|
-
.filter((n) => ["definition", "footnoteDefinition"].includes(n.type) && n.position)
|
|
57
|
-
.map((n) => [n.position.start.offset, n.position.end.offset]);
|
|
58
|
-
sections[section.anchorId] = { start, end, ownEnd, dependencies };
|
|
59
|
-
}
|
|
60
|
-
return { text, hash: hash(text), format, sections };
|
|
22
|
+
const collection = await collectLibraryAsync(options);
|
|
23
|
+
publishDirectory(collection.inputs, collection.outDir, collection.write);
|
|
24
|
+
return collection.library;
|
|
61
25
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
: compileDocument(text, config);
|
|
83
|
-
for (const diagnostic of compiled.diagnostics)
|
|
84
|
-
process.stderr.write(`${sourcePath}:${diagnostic.position?.start.line ?? 1}: ${diagnostic.code}: ${diagnostic.message}\n`);
|
|
85
|
-
const source = snapshotSource(text, compiled.tree, format);
|
|
86
|
-
const tree = buildExportedAst(compiled.tree, resolveExportAstOptions());
|
|
87
|
-
documents.push({
|
|
88
|
-
id,
|
|
89
|
-
sourcePath,
|
|
90
|
-
route: routes[id] ?? `${routeBase.replace(/\/$/, "")}/${id}${routeSuffix}`,
|
|
91
|
-
tree,
|
|
92
|
-
source,
|
|
93
|
-
frontmatter: compiled.frontmatter,
|
|
94
|
-
});
|
|
26
|
+
const loaded = new Map();
|
|
27
|
+
/**
|
|
28
|
+
* Reads a published library back. `roots` restores where the documents live
|
|
29
|
+
* on disk, which replacement and asset resolution need; a single directory is
|
|
30
|
+
* the shorthand for one root at the top. The bases given have to be the ones
|
|
31
|
+
* the library was collected with, because ids were derived from them.
|
|
32
|
+
*/
|
|
33
|
+
export function loadLibrary(outDir = ".cudoc/documents", compiler, roots, options = {}) {
|
|
34
|
+
const manifestText = fs.readFileSync(path.join(outDir, "manifest.json"), "utf8");
|
|
35
|
+
const key = path.resolve(outDir);
|
|
36
|
+
const cached = options.cache ? loaded.get(key) : undefined;
|
|
37
|
+
if (cached && cached.manifest === manifestText) {
|
|
38
|
+
const resolved = roots === undefined
|
|
39
|
+
? undefined
|
|
40
|
+
: resolveLoadedRoots(roots, cached.library);
|
|
41
|
+
return {
|
|
42
|
+
...cached.library,
|
|
43
|
+
compiler,
|
|
44
|
+
...(resolved ? { roots: resolved } : {}),
|
|
45
|
+
};
|
|
95
46
|
}
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
routes,
|
|
101
|
-
compilerId: compilerId ?? "cudoc-markdown-v1",
|
|
102
|
-
}));
|
|
103
|
-
const urls = new Set();
|
|
104
|
-
for (const document of documents) {
|
|
105
|
-
if (!document.route.startsWith("/") ||
|
|
106
|
-
document.route.startsWith("//") ||
|
|
107
|
-
/[?#]/.test(document.route))
|
|
108
|
-
throw new Error(`cudoc: document route must be a root-relative pathname: ${document.route}`);
|
|
109
|
-
if (urls.has(document.route))
|
|
110
|
-
throw new Error(`cudoc: duplicate document route: ${document.route}`);
|
|
111
|
-
urls.add(document.route);
|
|
112
|
-
}
|
|
113
|
-
const library = {
|
|
114
|
-
documents,
|
|
115
|
-
options,
|
|
116
|
-
configuration,
|
|
117
|
-
compiler,
|
|
118
|
-
sourceRoot: path.resolve(sourceRoot),
|
|
119
|
-
};
|
|
120
|
-
publishDirectory(sourceRoot, outDir, (staging) => {
|
|
121
|
-
for (const doc of documents) {
|
|
122
|
-
writeJson(safePath(staging, `documents/${doc.id}.json`), doc.tree);
|
|
123
|
-
writeJson(safePath(staging, `sources/${doc.id}.json`), doc.source);
|
|
124
|
-
}
|
|
125
|
-
writeJson(path.join(staging, "manifest.json"), {
|
|
126
|
-
schemaVersion: 1,
|
|
127
|
-
configuration,
|
|
128
|
-
options,
|
|
129
|
-
compilerId,
|
|
130
|
-
documents: documents.map(({ tree, source, ...doc }) => ({
|
|
131
|
-
...doc,
|
|
132
|
-
hash: source.hash,
|
|
133
|
-
astHash: hash(JSON.stringify(tree)),
|
|
134
|
-
snapshotHash: hash(JSON.stringify(source)),
|
|
135
|
-
})),
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
return library;
|
|
139
|
-
}
|
|
140
|
-
export function loadLibrary(outDir = ".cudoc/documents", compiler, sourceRoot) {
|
|
141
|
-
const manifest = JSON.parse(fs.readFileSync(path.join(outDir, "manifest.json"), "utf8"));
|
|
142
|
-
if (manifest.schemaVersion !== 1 || !Array.isArray(manifest.documents))
|
|
47
|
+
const manifest = JSON.parse(manifestText);
|
|
48
|
+
if (manifest.schemaVersion !== LIBRARY_SCHEMA_VERSION ||
|
|
49
|
+
!Array.isArray(manifest.documents) ||
|
|
50
|
+
!Array.isArray(manifest.roots))
|
|
143
51
|
throw new Error("cudoc: incompatible document manifest; rebuild documents");
|
|
144
52
|
const documents = manifest.documents.map((entry) => {
|
|
145
53
|
const tree = JSON.parse(fs.readFileSync(safePath(outDir, `documents/${entry.id}.json`), "utf8"));
|
|
@@ -152,12 +60,30 @@ export function loadLibrary(outDir = ".cudoc/documents", compiler, sourceRoot) {
|
|
|
152
60
|
throw new Error(`cudoc: stored document hash mismatch: ${entry.id}`);
|
|
153
61
|
return { ...entry, tree, source };
|
|
154
62
|
});
|
|
155
|
-
|
|
63
|
+
const library = {
|
|
156
64
|
documents,
|
|
157
65
|
options: manifest.options,
|
|
158
66
|
configuration: manifest.configuration,
|
|
67
|
+
bases: manifest.roots.map((root) => root.base),
|
|
68
|
+
};
|
|
69
|
+
const resolved = roots === undefined ? undefined : resolveLoadedRoots(roots, library);
|
|
70
|
+
if (options.cache)
|
|
71
|
+
loaded.set(key, { manifest: manifestText, library });
|
|
72
|
+
return {
|
|
73
|
+
...library,
|
|
159
74
|
compiler,
|
|
160
|
-
|
|
75
|
+
...(resolved ? { roots: resolved } : {}),
|
|
161
76
|
};
|
|
162
77
|
}
|
|
78
|
+
/** The roots a caller gives a loaded library, checked against the bases it was collected with. */
|
|
79
|
+
function resolveLoadedRoots(roots, library) {
|
|
80
|
+
const resolved = resolveRoots(typeof roots === "string" ? { sourceRoot: roots } : { roots });
|
|
81
|
+
const stored = [...(library.bases ?? [])].sort();
|
|
82
|
+
const given = resolved.map((root) => root.base).sort();
|
|
83
|
+
if (JSON.stringify(stored) !== JSON.stringify(given))
|
|
84
|
+
throw new Error(`cudoc: roots do not match the library; it was collected with bases [${stored
|
|
85
|
+
.map((base) => JSON.stringify(base))
|
|
86
|
+
.join(", ")}]`);
|
|
87
|
+
return resolved;
|
|
88
|
+
}
|
|
163
89
|
//# sourceMappingURL=library.js.map
|
package/dist/node/library.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"library.js","sourceRoot":"","sources":["../../src/node/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"library.js","sourceRoot":"","sources":["../../src/node/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAK5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/D,OAAO,EAAE,YAAY,EAAsC,MAAM,YAAY,CAAA;AAC7E,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,cAAc,CAAA;AAGrB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,YAAY,GACb,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAA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AI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAA;IACtD,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;QAClD,MAAM,IAAI,KAAK,CACb,uEAAuE,MAAM;aAC1E,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;aACnC,IAAI,CAAC,IAAI,CAAC,GAAG,CACjB,CAAA;IACH,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-ast.d.ts","sourceRoot":"","sources":["../../src/node/load-ast.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAEL,KAAK,WAAW,EAEjB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAe,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"load-ast.d.ts","sourceRoot":"","sources":["../../src/node/load-ast.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAEL,KAAK,WAAW,EAEjB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAe,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAGrE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD;;;GAGG;AACH,eAAO,MAAM,OAAO,GAClB,cAAc,MAAM,EACpB,UAAS,cAAc,GAAG,WAAgB,KACzC,oBAYF,CAAA"}
|
package/dist/node/load-ast.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { resolvePathOptions, } from "./paths.js";
|
|
4
4
|
import { loadAstFile } from "./load-ast-file.js";
|
|
5
|
+
import { safePath } from "./storage.js";
|
|
5
6
|
export { loadAstFile } from "./load-ast-file.js";
|
|
6
7
|
/**
|
|
7
8
|
* Loads the document stored for a source-relative document path, such as
|
|
@@ -11,7 +12,9 @@ export const loadAst = (documentPath, options = {}) => {
|
|
|
11
12
|
const pathOptions = resolvePathOptions(options);
|
|
12
13
|
const projectRoot = pathOptions.cwd ?? process.cwd();
|
|
13
14
|
const normalized = documentPath.replace(/^[/\\]+/, "").replace(/\.json$/i, "");
|
|
14
|
-
|
|
15
|
+
// A document path names a file inside the output directory, never beside
|
|
16
|
+
// it: `../../secrets` is refused rather than read.
|
|
17
|
+
const filePath = safePath(path.join(projectRoot, pathOptions.outDir), `${normalized}.json`);
|
|
15
18
|
return loadAstFile(filePath, options);
|
|
16
19
|
};
|
|
17
20
|
//# sourceMappingURL=load-ast.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-ast.js","sourceRoot":"","sources":["../../src/node/load-ast.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EACL,kBAAkB,GAGnB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,WAAW,EAAuB,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"load-ast.js","sourceRoot":"","sources":["../../src/node/load-ast.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EACL,kBAAkB,GAGnB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,WAAW,EAAuB,MAAM,oBAAoB,CAAA;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGhD;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,YAAoB,EACpB,UAAwC,EAAE,EACpB,EAAE;IACxB,MAAM,WAAW,GAAwB,kBAAkB,CAAC,OAAO,CAAC,CAAA;IACpE,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAA;IACpD,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;IAC9E,yEAAyE;IACzE,mDAAmD;IACnD,MAAM,QAAQ,GAAG,QAAQ,CACvB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,EAC1C,GAAG,UAAU,OAAO,CACrB,CAAA;IAED,OAAO,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;AACvC,CAAC,CAAA"}
|
|
@@ -5,9 +5,14 @@
|
|
|
5
5
|
* it does not. Both go through here so a document cannot pass one and fail the
|
|
6
6
|
* other: a link the checker calls resolvable is a link the exporter can copy.
|
|
7
7
|
*/
|
|
8
|
+
import { type ResolvedRoot } from "./roots.js";
|
|
8
9
|
export type LocalTargetRoots = {
|
|
9
|
-
/**
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The roots documents were collected from. A document-relative path
|
|
12
|
+
* resolves in the library's own coordinates first, so it reaches a file
|
|
13
|
+
* under whichever root holds that library path.
|
|
14
|
+
*/
|
|
15
|
+
roots: readonly ResolvedRoot[];
|
|
11
16
|
/** Extra roots holding host assets, such as `public` or `static`. */
|
|
12
17
|
assetDirs?: string[];
|
|
13
18
|
/**
|
|
@@ -15,6 +20,12 @@ export type LocalTargetRoots = {
|
|
|
15
20
|
* routing. Defaults to identity for a site served from the domain root.
|
|
16
21
|
*/
|
|
17
22
|
withoutBase?: (pathname: string) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Root-relative path prefixes that another application serves on the same
|
|
25
|
+
* host, such as `/sdk`. A link into one is external: not checked, not
|
|
26
|
+
* copied, not rewritten.
|
|
27
|
+
*/
|
|
28
|
+
externalPaths?: string[];
|
|
18
29
|
};
|
|
19
30
|
export type LocalTarget = {
|
|
20
31
|
kind: "external";
|
|
@@ -29,15 +40,35 @@ export type LocalTarget = {
|
|
|
29
40
|
relative: string;
|
|
30
41
|
suffix: string;
|
|
31
42
|
};
|
|
43
|
+
/** A fragment, a scheme or a protocol-relative URL: nothing on this disk. */
|
|
44
|
+
export declare const externalUrl: (url: string) => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Whether a root-relative URL falls under one of the configured external
|
|
47
|
+
* prefixes. `/sdk` covers `/sdk` and `/sdk/…`, not `/sdk-tools`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function isExternalPath(url: string, prefixes: readonly string[] | undefined): boolean;
|
|
32
50
|
/**
|
|
33
51
|
* Resolves one URL against the document that carries it.
|
|
34
52
|
*
|
|
35
|
-
* A fragment, scheme or protocol-relative URL is external and left alone
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
53
|
+
* A fragment, scheme or protocol-relative URL is external and left alone, and
|
|
54
|
+
* so is a root-relative one under an external prefix. A document-relative
|
|
55
|
+
* path resolves against the library path of its document, and a root-relative
|
|
56
|
+
* one against the library itself; both then reach disk through the roots. A
|
|
57
|
+
* root-relative path is also tried against each asset directory, after the
|
|
58
|
+
* deployment base is removed. A path that escapes every root is reported as
|
|
59
|
+
* missing rather than resolved, so the caller names the link and its document
|
|
60
|
+
* instead of a traversal that means nothing to an author.
|
|
41
61
|
*/
|
|
42
62
|
export declare function resolveLocalTarget(url: string, documentSourcePath: string, roots: LocalTargetRoots): LocalTarget;
|
|
63
|
+
/**
|
|
64
|
+
* The candidates of a `srcset`, read as the HTML standard reads them: a URL
|
|
65
|
+
* runs to the next white space, so a comma inside it, as in a data URL,
|
|
66
|
+
* belongs to it, and commas the URL ends with are separators; the descriptors
|
|
67
|
+
* run to the next comma outside parentheses. Empty candidates, left by a
|
|
68
|
+
* stray comma, are skipped as browsers skip them.
|
|
69
|
+
*/
|
|
70
|
+
export declare const parseSrcSet: (value: string) => {
|
|
71
|
+
url: string;
|
|
72
|
+
descriptor: string;
|
|
73
|
+
}[];
|
|
43
74
|
//# sourceMappingURL=local-target.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-target.d.ts","sourceRoot":"","sources":["../../src/node/local-target.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"local-target.d.ts","sourceRoot":"","sources":["../../src/node/local-target.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAG9D,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;;OAIG;IACH,KAAK,EAAE,SAAS,YAAY,EAAE,CAAA;IAC9B,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAA;IAC1C;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACtE;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAWzD,6EAA6E;AAC7E,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,KAAG,OACK,CAAA;AAE/C;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GACtC,OAAO,CAUT;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,kBAAkB,EAAE,MAAM,EAC1B,KAAK,EAAE,gBAAgB,GACtB,WAAW,CAsCb;AAED;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GACtB,OAAO,MAAM,KACZ;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,EAwCrC,CAAA"}
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
import fs from "node:fs";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import { safePath } from "./storage.js";
|
|
11
|
+
import { candidateFiles } from "./roots.js";
|
|
12
|
+
import { EXTERNAL_URL, decodeComponent } from "./references.js";
|
|
11
13
|
/** `safePath`, but a path escaping its root is a non-match rather than a throw. */
|
|
12
14
|
const containedPath = (root, relative) => {
|
|
13
15
|
try {
|
|
@@ -17,36 +19,115 @@ const containedPath = (root, relative) => {
|
|
|
17
19
|
return undefined;
|
|
18
20
|
}
|
|
19
21
|
};
|
|
22
|
+
/** A fragment, a scheme or a protocol-relative URL: nothing on this disk. */
|
|
23
|
+
export const externalUrl = (url) => url.startsWith("#") || EXTERNAL_URL.test(url);
|
|
24
|
+
/**
|
|
25
|
+
* Whether a root-relative URL falls under one of the configured external
|
|
26
|
+
* prefixes. `/sdk` covers `/sdk` and `/sdk/…`, not `/sdk-tools`.
|
|
27
|
+
*/
|
|
28
|
+
export function isExternalPath(url, prefixes) {
|
|
29
|
+
if (!prefixes?.length || !url.startsWith("/") || url.startsWith("//"))
|
|
30
|
+
return false;
|
|
31
|
+
const pathname = url.match(/^[^?#]*/)[0];
|
|
32
|
+
return prefixes.some((prefix) => {
|
|
33
|
+
const clean = `/${prefix.replace(/^\/+|\/+$/g, "")}`;
|
|
34
|
+
return (clean !== "/" && (pathname === clean || pathname.startsWith(`${clean}/`)));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
20
37
|
/**
|
|
21
38
|
* Resolves one URL against the document that carries it.
|
|
22
39
|
*
|
|
23
|
-
* A fragment, scheme or protocol-relative URL is external and left alone
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
40
|
+
* A fragment, scheme or protocol-relative URL is external and left alone, and
|
|
41
|
+
* so is a root-relative one under an external prefix. A document-relative
|
|
42
|
+
* path resolves against the library path of its document, and a root-relative
|
|
43
|
+
* one against the library itself; both then reach disk through the roots. A
|
|
44
|
+
* root-relative path is also tried against each asset directory, after the
|
|
45
|
+
* deployment base is removed. A path that escapes every root is reported as
|
|
46
|
+
* missing rather than resolved, so the caller names the link and its document
|
|
47
|
+
* instead of a traversal that means nothing to an author.
|
|
29
48
|
*/
|
|
30
49
|
export function resolveLocalTarget(url, documentSourcePath, roots) {
|
|
31
|
-
if (
|
|
50
|
+
if (externalUrl(url) || isExternalPath(url, roots.externalPaths))
|
|
32
51
|
return { kind: "external", url };
|
|
33
52
|
const [, pathname, suffix] = url.match(/^([^?#]*)(.*)$/);
|
|
34
|
-
const decoded =
|
|
53
|
+
const decoded = decodeComponent(pathname);
|
|
35
54
|
const relative = path.posix.normalize(decoded.startsWith("/")
|
|
36
55
|
? decoded.slice(1)
|
|
37
56
|
: path.posix.join(path.posix.dirname(documentSourcePath), decoded));
|
|
38
57
|
const withoutBase = roots.withoutBase ?? ((value) => value);
|
|
39
58
|
const rootPath = withoutBase(decoded.startsWith("/") ? decoded : `/${relative}`).replace(/^\//, "");
|
|
40
59
|
const candidates = [
|
|
41
|
-
|
|
42
|
-
|
|
60
|
+
...candidateFiles(roots.roots, relative).map((source) => ({
|
|
61
|
+
relative,
|
|
62
|
+
source,
|
|
63
|
+
})),
|
|
64
|
+
...(roots.assetDirs ?? []).flatMap((root) => {
|
|
65
|
+
const source = containedPath(root, rootPath);
|
|
66
|
+
return source ? [{ relative: rootPath, source }] : [];
|
|
67
|
+
}),
|
|
43
68
|
];
|
|
44
69
|
for (const candidate of candidates) {
|
|
45
|
-
|
|
46
|
-
|
|
70
|
+
if (!fs.existsSync(candidate.source) ||
|
|
71
|
+
!fs.statSync(candidate.source).isFile())
|
|
47
72
|
continue;
|
|
48
|
-
return {
|
|
73
|
+
return {
|
|
74
|
+
kind: "resolved",
|
|
75
|
+
relative: candidate.relative,
|
|
76
|
+
source: candidate.source,
|
|
77
|
+
suffix,
|
|
78
|
+
};
|
|
49
79
|
}
|
|
50
80
|
return { kind: "missing", relative, suffix };
|
|
51
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* The candidates of a `srcset`, read as the HTML standard reads them: a URL
|
|
84
|
+
* runs to the next white space, so a comma inside it, as in a data URL,
|
|
85
|
+
* belongs to it, and commas the URL ends with are separators; the descriptors
|
|
86
|
+
* run to the next comma outside parentheses. Empty candidates, left by a
|
|
87
|
+
* stray comma, are skipped as browsers skip them.
|
|
88
|
+
*/
|
|
89
|
+
export const parseSrcSet = (value) => {
|
|
90
|
+
const candidates = [];
|
|
91
|
+
// ASCII white space only: a no-break or ideographic space is part of a URL.
|
|
92
|
+
const space = (character) => character === " " ||
|
|
93
|
+
character === "\t" ||
|
|
94
|
+
character === "\n" ||
|
|
95
|
+
character === "\f" ||
|
|
96
|
+
character === "\r";
|
|
97
|
+
let index = 0;
|
|
98
|
+
while (index < value.length) {
|
|
99
|
+
while (index < value.length &&
|
|
100
|
+
(space(value[index]) || value[index] === ","))
|
|
101
|
+
index++;
|
|
102
|
+
const start = index;
|
|
103
|
+
while (index < value.length && !space(value[index]))
|
|
104
|
+
index++;
|
|
105
|
+
let url = value.slice(start, index);
|
|
106
|
+
let descriptor = "";
|
|
107
|
+
if (url.endsWith(","))
|
|
108
|
+
url = url.replace(/,+$/, "");
|
|
109
|
+
else {
|
|
110
|
+
const from = index;
|
|
111
|
+
let inParens = false;
|
|
112
|
+
while (index < value.length) {
|
|
113
|
+
const character = value[index];
|
|
114
|
+
if (character === "(")
|
|
115
|
+
inParens = true;
|
|
116
|
+
else if (character === ")")
|
|
117
|
+
inParens = false;
|
|
118
|
+
else if (character === "," && !inParens)
|
|
119
|
+
break;
|
|
120
|
+
index++;
|
|
121
|
+
}
|
|
122
|
+
descriptor = value
|
|
123
|
+
.slice(from, index)
|
|
124
|
+
.split(/[\t\n\f\r ]+/)
|
|
125
|
+
.filter(Boolean)
|
|
126
|
+
.join(" ");
|
|
127
|
+
}
|
|
128
|
+
if (url)
|
|
129
|
+
candidates.push({ url, descriptor });
|
|
130
|
+
}
|
|
131
|
+
return candidates;
|
|
132
|
+
};
|
|
52
133
|
//# sourceMappingURL=local-target.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-target.js","sourceRoot":"","sources":["../../src/node/local-target.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"local-target.js","sourceRoot":"","sources":["../../src/node/local-target.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,cAAc,EAAqB,MAAM,YAAY,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AA6B/D,mFAAmF;AACnF,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,QAAgB,EAAE,EAAE;IACvD,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC,CAAA;AAED,6EAA6E;AAC7E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AI,QAAQ,GAAG,KAAK,CAAA;YACpB,OAAO,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;gBAC5B,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAE,CAAA;gBAC/B,IAAI,SAAS,KAAK,GAAG;oBAAE,QAAQ,GAAG,IAAI,CAAA;qBACjC,IAAI,SAAS,KAAK,GAAG;oBAAE,QAAQ,GAAG,KAAK,CAAA;qBACvC,IAAI,SAAS,KAAK,GAAG,IAAI,CAAC,QAAQ;oBAAE,MAAK;gBAC9C,KAAK,EAAE,CAAA;YACT,CAAC;YACD,UAAU,GAAG,KAAK;iBACf,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;iBAClB,KAAK,CAAC,cAAc,CAAC;iBACrB,MAAM,CAAC,OAAO,CAAC;iBACf,IAAI,CAAC,GAAG,CAAC,CAAA;QACd,CAAC;QACD,IAAI,GAAG;YAAE,UAAU,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAA;IAC/C,CAAC;IACD,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA"}
|
|
@@ -1,13 +1,62 @@
|
|
|
1
1
|
import type { Root } from "mdast";
|
|
2
2
|
import type { Library } from "./library.js";
|
|
3
3
|
export type PreparedEmbeds = {
|
|
4
|
-
schemaVersion:
|
|
4
|
+
schemaVersion: 2;
|
|
5
5
|
configuration: string;
|
|
6
6
|
sourceHashes: Record<string, string>;
|
|
7
7
|
blocks: Record<string, Root>;
|
|
8
|
+
/**
|
|
9
|
+
* The documents each block read, by block key: the sources named in its
|
|
10
|
+
* fence and in every embed nested in them. `["*"]` marks a block that ran
|
|
11
|
+
* an extractor, which may read anything.
|
|
12
|
+
*/
|
|
13
|
+
dependencies: Record<string, string[]>;
|
|
8
14
|
};
|
|
9
15
|
export declare const embedKey: (documentId: string, value: string, index: number) => string;
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
export type PrepareEmbedsOptions = {
|
|
17
|
+
/**
|
|
18
|
+
* The result of an earlier preparation. A block is taken from it unresolved
|
|
19
|
+
* when the configuration, the set of documents, the embedding document and
|
|
20
|
+
* every document the block depends on are unchanged.
|
|
21
|
+
*/
|
|
22
|
+
previous?: PreparedEmbeds;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Run after collection and before the host build. No asynchronous compiler is
|
|
26
|
+
* needed at render time.
|
|
27
|
+
*
|
|
28
|
+
* Every block is resolved before anything is written, so one pass names every
|
|
29
|
+
* embed that cannot be prepared, each with its document and block number: a
|
|
30
|
+
* single failure as an error whose `cause` is the resolver's, and several as
|
|
31
|
+
* one `AggregateError` whose message lists them. Nothing is written when any
|
|
32
|
+
* block fails.
|
|
33
|
+
*/
|
|
34
|
+
export declare function prepareEmbeds(library: Library, outDir?: string, options?: PrepareEmbedsOptions): Promise<PreparedEmbeds>;
|
|
35
|
+
/**
|
|
36
|
+
* Reads the prepared embeds a host compiles a page with, checked against the
|
|
37
|
+
* page's own source and against the library they were prepared from.
|
|
38
|
+
*
|
|
39
|
+
* A host asks once per page, or once per block, so the two files are parsed
|
|
40
|
+
* once and kept while neither changes on disk; publishing replaces both, so a
|
|
41
|
+
* new collection is read on the next call. The result is shared between
|
|
42
|
+
* calls: a caller copies a block before putting it in its own tree.
|
|
43
|
+
*/
|
|
12
44
|
export declare function readPreparedEmbeds(outDir: string, documentId: string, source: string): PreparedEmbeds;
|
|
45
|
+
/** The embedding document a host is compiling, as `expandPreparedEmbeds` needs it. */
|
|
46
|
+
export type PreparedTarget = {
|
|
47
|
+
/** Where the library and its `embeds.json` were published. */
|
|
48
|
+
outDir: string;
|
|
49
|
+
documentId: string;
|
|
50
|
+
/** The document's source as collected, which the preparation must match. */
|
|
51
|
+
source: string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Replaces every `cudoc-embed` fence in `tree` with its prepared block, in
|
|
55
|
+
* document order, the way a host build does. The tree is modified in place
|
|
56
|
+
* and returned. `target` is read when the first fence is met, so a document
|
|
57
|
+
* with no embeds needs no library at all; a function defers the work of
|
|
58
|
+
* finding it until then. `onBlock` sees each block's copy before it is
|
|
59
|
+
* spliced in.
|
|
60
|
+
*/
|
|
61
|
+
export declare function expandPreparedEmbeds(tree: Root, target: PreparedTarget | (() => PreparedTarget), onBlock?: (block: Root, documentId: string) => void): Root;
|
|
13
62
|
//# sourceMappingURL=prepare-embeds.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepare-embeds.d.ts","sourceRoot":"","sources":["../../src/node/prepare-embeds.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAG3C,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,CAAC,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"prepare-embeds.d.ts","sourceRoot":"","sources":["../../src/node/prepare-embeds.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAG3C,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,CAAC,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAC5B;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;CACvC,CAAA;AACD,eAAO,MAAM,QAAQ,GAAI,YAAY,M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