@publisle/adapter-core 0.2.0 → 0.2.2
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/LICENSE +1 -1
- package/README.md +4 -8
- package/dist/async.d.ts +5 -0
- package/dist/async.d.ts.map +1 -0
- package/dist/async.js +28 -0
- package/dist/async.js.map +1 -0
- package/dist/publication-core.d.ts +76 -0
- package/dist/publication-core.d.ts.map +1 -0
- package/dist/publication-core.js +202 -0
- package/dist/publication-core.js.map +1 -0
- package/dist/publication.d.ts +4 -75
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +8 -200
- package/dist/publication.js.map +1 -1
- package/dist/render-plan-core.d.ts +17 -0
- package/dist/render-plan-core.d.ts.map +1 -0
- package/dist/render-plan-core.js +981 -0
- package/dist/render-plan-core.js.map +1 -0
- package/dist/render-plan.d.ts +4 -14
- package/dist/render-plan.d.ts.map +1 -1
- package/dist/render-plan.js +6 -974
- package/dist/render-plan.js.map +1 -1
- package/package.json +13 -8
- package/src/async.ts +29 -0
- package/src/publication-core.ts +341 -0
- package/src/publication.ts +9 -339
- package/src/render-plan-core.ts +1426 -0
- package/src/render-plan.ts +10 -1416
package/dist/publication.js
CHANGED
|
@@ -1,202 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.replaceAll('"', """)
|
|
10
|
-
.replaceAll("<", "<");
|
|
11
|
-
}
|
|
12
|
-
export const PUBLICATION_FORMAT = "publisle:publication";
|
|
13
|
-
export const PUBLICATION_FORMAT_VERSION = 1;
|
|
14
|
-
export const RENDERER_BUILD = "1";
|
|
15
|
-
export const DOCUMENT_STYLESHEET_ID = "publisle/document.css";
|
|
16
|
-
export const KATEX_STYLESHEET_ID = "publisle/katex.css";
|
|
17
|
-
export function publicationReaderManifest(artifact) {
|
|
18
|
-
return {
|
|
19
|
-
format: artifact.format,
|
|
20
|
-
formatVersion: artifact.formatVersion,
|
|
21
|
-
identity: artifact.identity,
|
|
22
|
-
...(artifact.compatibility === undefined
|
|
23
|
-
? {}
|
|
24
|
-
: { compatibility: artifact.compatibility }),
|
|
25
|
-
islands: artifact.islands,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function isRenderPlan(source) {
|
|
29
|
-
return "nodes" in source && "document" in source;
|
|
30
|
-
}
|
|
31
|
-
function withIslandRenderers(document, options) {
|
|
32
|
-
const renderers = { ...(options.renderers ?? {}) };
|
|
33
|
-
for (const island of document.islands) {
|
|
34
|
-
renderers[island.blockType] ??= { module: island.blockType };
|
|
35
|
-
}
|
|
36
|
-
return { ...options, renderers };
|
|
37
|
-
}
|
|
38
|
-
function compilePlan(plan, styles, build, rawHtmlPlacement = "reject") {
|
|
39
|
-
const islands = [];
|
|
40
|
-
const diagnostics = [...plan.diagnostics];
|
|
41
|
-
let fidelity = "supported";
|
|
42
|
-
const substantive = (nodes) => nodes.some((node) => {
|
|
43
|
-
if (node.kind === "text")
|
|
44
|
-
return node.value.trim().length > 0;
|
|
45
|
-
if (node.kind === "raw")
|
|
46
|
-
return (node.value.replace(/<[^>]*>/gu, "").trim().length > 0 ||
|
|
47
|
-
/<(?:img|svg|video|audio)\b/iu.test(node.value));
|
|
48
|
-
if (node.kind === "element")
|
|
49
|
-
return (["img", "svg", "video", "audio", "iframe", "canvas"].includes(node.tag) || substantive(node.children));
|
|
50
|
-
return node.kind === "component"
|
|
51
|
-
? substantive(node.artifact ?? [])
|
|
52
|
-
: substantive(node.fallback);
|
|
53
|
-
});
|
|
54
|
-
const lower = (nodes) => nodes.flatMap((node) => {
|
|
55
|
-
if (node.kind === "raw" &&
|
|
56
|
-
/\b(?:id|for|headers|list|form|href|aria-labelledby|aria-describedby|aria-controls|aria-owns|aria-flowto|aria-activedescendant|aria-details|aria-errormessage)\s*=/iu.test(node.value)) {
|
|
57
|
-
diagnostics.push({
|
|
58
|
-
level: rawHtmlPlacement === "reject" ? "error" : "warning",
|
|
59
|
-
code: "raw-html-placement-unscoped",
|
|
60
|
-
message: "Authored trusted HTML IDs/references cannot be generically namespaced. Host must reject it or explicitly preserve it with placement restrictions.",
|
|
61
|
-
});
|
|
62
|
-
if (rawHtmlPlacement === "reject") {
|
|
63
|
-
fidelity = "unsupported";
|
|
64
|
-
return [];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (node.kind === "component") {
|
|
68
|
-
const replacement = node.artifact ?? [];
|
|
69
|
-
const supported = substantive(replacement);
|
|
70
|
-
if (!supported)
|
|
71
|
-
fidelity = "unsupported";
|
|
72
|
-
else if (fidelity !== "unsupported")
|
|
73
|
-
fidelity = "fallback";
|
|
74
|
-
diagnostics.push({
|
|
75
|
-
level: supported ? "warning" : "error",
|
|
76
|
-
code: supported
|
|
77
|
-
? "artifact-component-lowered"
|
|
78
|
-
: "unsupported-artifact-component",
|
|
79
|
-
message: supported
|
|
80
|
-
? "Artifact uses approved static lowering/authored fallback; native component fidelity is not implied."
|
|
81
|
-
: "Framework component has no static lowering or substantive authored fallback.",
|
|
82
|
-
...(node.blockId === undefined
|
|
83
|
-
? {}
|
|
84
|
-
: { blockId: node.blockId }),
|
|
85
|
-
});
|
|
86
|
-
return lower(replacement);
|
|
87
|
-
}
|
|
88
|
-
if (node.kind === "element")
|
|
89
|
-
return [{ ...node, children: lower(node.children) }];
|
|
90
|
-
if (node.kind === "island")
|
|
91
|
-
return [{ ...node, fallback: lower(node.fallback) }];
|
|
92
|
-
return [node];
|
|
93
|
-
});
|
|
94
|
-
const nodes = lower(plan.nodes);
|
|
95
|
-
const modules = [];
|
|
96
|
-
const seen = new Set();
|
|
97
|
-
const visit = (nodes) => {
|
|
98
|
-
for (const node of nodes) {
|
|
99
|
-
if (node.kind === "island") {
|
|
100
|
-
const block = plan.document.blocks.find((entry) => entry.id === node.blockId);
|
|
101
|
-
const implementation = node.implementation ?? block?.type ?? node.module;
|
|
102
|
-
islands.push({
|
|
103
|
-
key: node.blockId,
|
|
104
|
-
implementation,
|
|
105
|
-
activation: node.activation,
|
|
106
|
-
mode: "mount",
|
|
107
|
-
props: node.props,
|
|
108
|
-
});
|
|
109
|
-
if (!seen.has(implementation)) {
|
|
110
|
-
seen.add(implementation);
|
|
111
|
-
modules.push({ id: implementation });
|
|
112
|
-
}
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
if (node.kind === "element")
|
|
116
|
-
visit(node.children);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
visit(nodes);
|
|
120
|
-
const metadata = plan.metadata;
|
|
121
|
-
const language = metadata?.language;
|
|
122
|
-
const direction = metadata?.direction;
|
|
123
|
-
const root = [
|
|
124
|
-
'class="publisle-document"',
|
|
125
|
-
"data-publisle-root",
|
|
126
|
-
...(typeof language === "string" && language
|
|
127
|
-
? [`lang="${escapeAttribute(language)}"`]
|
|
128
|
-
: []),
|
|
129
|
-
...(direction === "ltr" || direction === "rtl" || direction === "auto"
|
|
130
|
-
? [`dir="${direction}"`]
|
|
131
|
-
: []),
|
|
132
|
-
].join(" ");
|
|
133
|
-
const html = `<div ${root}>${serializeNodes(nodes)}</div>`;
|
|
134
|
-
const hasMath = plan.document.blocks.some((block) => block.type === "publisle:math" ||
|
|
135
|
-
JSON.stringify(block.data).includes('"inlineMath"'));
|
|
136
|
-
const styleEntries = styles === "none"
|
|
137
|
-
? []
|
|
138
|
-
: [
|
|
139
|
-
{ id: DOCUMENT_STYLESHEET_ID },
|
|
140
|
-
...(hasMath ? [{ id: KATEX_STYLESHEET_ID }] : []),
|
|
141
|
-
];
|
|
142
|
-
const unsigned = {
|
|
143
|
-
format: PUBLICATION_FORMAT,
|
|
144
|
-
formatVersion: PUBLICATION_FORMAT_VERSION,
|
|
145
|
-
rendererBuild: RENDERER_BUILD,
|
|
146
|
-
html,
|
|
147
|
-
styles: styleEntries,
|
|
148
|
-
modules,
|
|
149
|
-
islands,
|
|
150
|
-
...(metadata === undefined ? {} : { metadata }),
|
|
151
|
-
compatibility: { islandInputVersion: 1, staticFidelity: fidelity },
|
|
152
|
-
provenance: {
|
|
153
|
-
sourceIdentity: plan.document.sourceIdentity ?? null,
|
|
154
|
-
semanticIdentity: plan.document.semanticIdentity ?? plan.document.cacheIdentity,
|
|
155
|
-
contracts: plan.document.dependencies ?? [],
|
|
156
|
-
resources: plan.document.resources,
|
|
157
|
-
configuration: build?.configuration ?? {
|
|
158
|
-
styles,
|
|
159
|
-
rendererBuild: RENDERER_BUILD,
|
|
160
|
-
},
|
|
161
|
-
reproducible: build?.reproducible ?? false,
|
|
162
|
-
...(build?.seed === undefined ? {} : { seed: build.seed }),
|
|
163
|
-
...(build === undefined
|
|
164
|
-
? {
|
|
165
|
-
limitation: "Host compiler/renderer configuration and nondeterministic inputs have not been pinned. No byte-reproduction claim.",
|
|
166
|
-
}
|
|
167
|
-
: {}),
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
const artifact = {
|
|
171
|
-
...unsigned,
|
|
172
|
-
diagnostics,
|
|
173
|
-
diagnosticIdentity: sha256Hex(canonicalizeJson(diagnostics)),
|
|
174
|
-
identity: sha256Hex(canonicalizeJson(unsigned)),
|
|
175
|
-
};
|
|
176
|
-
return artifact;
|
|
177
|
-
}
|
|
178
|
-
export function compilePublication(source, options = {}) {
|
|
179
|
-
const styles = options.styles ?? "minimal";
|
|
180
|
-
if (isRenderPlan(source))
|
|
181
|
-
return compilePlan(source, styles, options.build, options.rawHtmlPlacement);
|
|
182
|
-
const compilerOptions = {
|
|
183
|
-
...(options.citations === undefined
|
|
184
|
-
? {}
|
|
185
|
-
: { citations: options.citations }),
|
|
186
|
-
...(options.bibliography === undefined
|
|
187
|
-
? {}
|
|
188
|
-
: { bibliography: options.bibliography }),
|
|
189
|
-
...(options.renderers === undefined
|
|
190
|
-
? {}
|
|
191
|
-
: { renderers: options.renderers }),
|
|
192
|
-
...(options.rawHtml === undefined ? {} : { rawHtml: options.rawHtml }),
|
|
193
|
-
...(options.embedProviders === undefined
|
|
194
|
-
? {}
|
|
195
|
-
: { embedProviders: options.embedProviders }),
|
|
196
|
-
...(options.diagramRenderers === undefined
|
|
197
|
-
? {}
|
|
198
|
-
: { diagramRenderers: options.diagramRenderers }),
|
|
199
|
-
};
|
|
200
|
-
return compilePlan(createRenderPlan(source, withIslandRenderers(source, compilerOptions)), styles, options.build, options.rawHtmlPlacement);
|
|
1
|
+
import katex from "katex";
|
|
2
|
+
import { installMathRenderer } from "./render-plan-core.js";
|
|
3
|
+
import { compilePublication as compile } from "./publication-core.js";
|
|
4
|
+
export * from "./publication-core.js";
|
|
5
|
+
/** Synchronous compiler with bundled math support. */
|
|
6
|
+
export function compilePublication(...args) {
|
|
7
|
+
installMathRenderer(katex);
|
|
8
|
+
return compile(...args);
|
|
201
9
|
}
|
|
202
10
|
//# sourceMappingURL=publication.js.map
|
package/dist/publication.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publication.js","sourceRoot":"","sources":["../src/publication.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"publication.js","sourceRoot":"","sources":["../src/publication.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,IAAI,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACtE,cAAc,uBAAuB,CAAC;AACtC,sDAAsD;AACtD,MAAM,UAAU,kBAAkB,CAChC,GAAG,IAAgC;IAEnC,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC3B,OAAO,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type PreparedDocument } from "@publisle/schema";
|
|
2
|
+
/** Install the shared renderer after a host explicitly loads math support. */
|
|
3
|
+
export declare function installMathRenderer(renderer: typeof import("katex").default): void;
|
|
4
|
+
import type { AdapterCompilerOptions, RenderPlan } from "./types.js";
|
|
5
|
+
/** Stable identity for a citation cluster, independent of object property order. */
|
|
6
|
+
export declare function citationKey(cluster: {
|
|
7
|
+
readonly items: readonly {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly locator?: string;
|
|
10
|
+
readonly label?: string;
|
|
11
|
+
readonly suppressAuthor?: boolean;
|
|
12
|
+
}[];
|
|
13
|
+
readonly prefix?: string;
|
|
14
|
+
readonly suffix?: string;
|
|
15
|
+
}): string;
|
|
16
|
+
export declare function createRenderPlan(document: PreparedDocument, options?: AdapterCompilerOptions): RenderPlan;
|
|
17
|
+
//# sourceMappingURL=render-plan-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-plan-core.d.ts","sourceRoot":"","sources":["../src/render-plan-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,gBAAgB,EAMtB,MAAM,kBAAkB,CAAC;AAE1B,8EAA8E;AAC9E,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,cAAc,OAAO,EAAE,OAAO,GACvC,IAAI,CAEN;AAED,OAAO,KAAK,EACV,sBAAsB,EAGtB,UAAU,EACX,mBAAmB;AAWpB,oFAAoF;AACpF,wBAAgB,WAAW,CAAC,OAAO,EAAE;IACnC,QAAQ,CAAC,KAAK,EAAE,SAAS;QACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;KACnC,EAAE,CAAC;IACJ,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,GAAG,MAAM,CAWT;AAurCD,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,GAAE,sBAA2B,GACnC,UAAU,CA0BZ"}
|