@publisle/adapter-core 0.2.1 → 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/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 +6 -1
- 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/async.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { compilePublication as compile } from "./publication-core.js";
|
|
2
|
+
export { publicationReaderManifest } from "./publication-core.js";
|
|
3
|
+
/** Compile with math support loaded only when the document contains math. */
|
|
4
|
+
export declare function compilePublicationAsync(...args: Parameters<typeof compile>): Promise<ReturnType<typeof compile>>;
|
|
5
|
+
//# sourceMappingURL=async.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../src/async.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,IAAI,OAAO,EAAE,8BAA8B;AAEtE,OAAO,EAAE,yBAAyB,EAAE,8BAA8B;AAYlE,6EAA6E;AAC7E,wBAAsB,uBAAuB,CAC3C,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,GAClC,OAAO,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC,CAWrC"}
|
package/dist/async.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { compilePublication as compile } from "./publication-core.js";
|
|
2
|
+
import { installMathRenderer } from "./render-plan-core.js";
|
|
3
|
+
export { publicationReaderManifest } from "./publication-core.js";
|
|
4
|
+
let loading;
|
|
5
|
+
function containsMath(value) {
|
|
6
|
+
if (!value || typeof value !== "object")
|
|
7
|
+
return false;
|
|
8
|
+
if (Array.isArray(value))
|
|
9
|
+
return value.some(containsMath);
|
|
10
|
+
const object = value;
|
|
11
|
+
return (object["type"] === "math" ||
|
|
12
|
+
object["type"] === "publisle:math" ||
|
|
13
|
+
Object.values(object).some(containsMath));
|
|
14
|
+
}
|
|
15
|
+
/** Compile with math support loaded only when the document contains math. */
|
|
16
|
+
export async function compilePublicationAsync(...args) {
|
|
17
|
+
if (containsMath(args[0])) {
|
|
18
|
+
loading ??= import("katex")
|
|
19
|
+
.then(({ default: renderer }) => installMathRenderer(renderer))
|
|
20
|
+
.catch((error) => {
|
|
21
|
+
loading = undefined;
|
|
22
|
+
throw error;
|
|
23
|
+
});
|
|
24
|
+
await loading;
|
|
25
|
+
}
|
|
26
|
+
return compile(...args);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=async.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async.js","sourceRoot":"","sources":["../src/async.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,IAAI,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,IAAI,OAAkC,CAAC;AACvC,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,KAAgC,CAAC;IAChD,OAAO,CACL,MAAM,CAAC,MAAM,CAAC,KAAK,MAAM;QACzB,MAAM,CAAC,MAAM,CAAC,KAAK,eAAe;QAClC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CACzC,CAAC;AACJ,CAAC;AACD,6EAA6E;AAC7E,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,GAAG,IAAgC;IAEnC,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,MAAM,CAAC,OAAO,CAAC;aACxB,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;aAC9D,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YACxB,OAAO,GAAG,SAAS,CAAC;YACpB,MAAM,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;QACL,MAAM,OAAO,CAAC;IAChB,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Activation, Diagnostic, JsonValue, PreparedDocument, PublicationMetadata } from "@publisle/schema";
|
|
2
|
+
export { instantiatePublication, collectPublicationAssets, publicationAssetUrl, attachPublication, } from "./publication-runtime.js";
|
|
3
|
+
import type { AdapterCompilerOptions, RenderPlan } from "./types.js";
|
|
4
|
+
export declare const PUBLICATION_FORMAT: "publisle:publication";
|
|
5
|
+
export declare const PUBLICATION_FORMAT_VERSION: 1;
|
|
6
|
+
export declare const RENDERER_BUILD = "1";
|
|
7
|
+
export declare const DOCUMENT_STYLESHEET_ID = "publisle/document.css";
|
|
8
|
+
export declare const KATEX_STYLESHEET_ID = "publisle/katex.css";
|
|
9
|
+
export interface AssetReference {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ModuleReference {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
}
|
|
15
|
+
export interface PublishedIsland {
|
|
16
|
+
readonly key: string;
|
|
17
|
+
readonly implementation: string;
|
|
18
|
+
readonly activation: Activation;
|
|
19
|
+
readonly mode: "mount" | "hydrate";
|
|
20
|
+
readonly props: JsonValue;
|
|
21
|
+
}
|
|
22
|
+
export interface PublicationArtifact {
|
|
23
|
+
readonly provenance?: {
|
|
24
|
+
readonly sourceIdentity: string | null;
|
|
25
|
+
readonly semanticIdentity: string;
|
|
26
|
+
readonly contracts: readonly import("@publisle/schema").ContractDependency[];
|
|
27
|
+
readonly resources: import("@publisle/schema").ResourcePlan;
|
|
28
|
+
readonly configuration: JsonValue;
|
|
29
|
+
readonly reproducible: boolean;
|
|
30
|
+
readonly seed?: JsonValue;
|
|
31
|
+
readonly limitation?: string;
|
|
32
|
+
};
|
|
33
|
+
readonly diagnosticIdentity?: string;
|
|
34
|
+
readonly compatibility?: {
|
|
35
|
+
readonly islandInputVersion: 1;
|
|
36
|
+
readonly staticFidelity: "supported" | "fallback" | "unsupported";
|
|
37
|
+
};
|
|
38
|
+
readonly format: typeof PUBLICATION_FORMAT;
|
|
39
|
+
readonly formatVersion: typeof PUBLICATION_FORMAT_VERSION;
|
|
40
|
+
readonly identity: string;
|
|
41
|
+
readonly rendererBuild: string;
|
|
42
|
+
readonly html: string;
|
|
43
|
+
readonly styles: readonly AssetReference[];
|
|
44
|
+
readonly modules: readonly ModuleReference[];
|
|
45
|
+
readonly islands: readonly PublishedIsland[];
|
|
46
|
+
readonly metadata?: PublicationMetadata;
|
|
47
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
48
|
+
}
|
|
49
|
+
export interface PublicationCompilerOptions extends AdapterCompilerOptions {
|
|
50
|
+
/** Host pins for otherwise opaque renderer/compiler configuration. Never infer function source. */
|
|
51
|
+
readonly build?: {
|
|
52
|
+
readonly configuration: JsonValue;
|
|
53
|
+
readonly reproducible: boolean;
|
|
54
|
+
readonly seed?: JsonValue;
|
|
55
|
+
};
|
|
56
|
+
readonly styles?: "minimal" | "none";
|
|
57
|
+
}
|
|
58
|
+
export interface PublicationPlacement {
|
|
59
|
+
readonly instanceId: string;
|
|
60
|
+
readonly html: string;
|
|
61
|
+
}
|
|
62
|
+
/** Minimal browser attachment data; excludes HTML, source AST, resources and diagnostics. */
|
|
63
|
+
export type PublicationReaderManifest = Pick<PublicationArtifact, "format" | "formatVersion" | "identity" | "compatibility" | "islands">;
|
|
64
|
+
export declare function publicationReaderManifest(artifact: PublicationArtifact): PublicationReaderManifest;
|
|
65
|
+
export interface PublicationEnvironment {
|
|
66
|
+
readonly implementations?: Readonly<Record<string, () => Promise<unknown>>>;
|
|
67
|
+
readonly mount?: (module: unknown, target: HTMLElement, props: JsonValue, services: Readonly<Record<string, unknown>> | undefined) => unknown;
|
|
68
|
+
readonly unmount?: (instance: unknown) => void;
|
|
69
|
+
readonly services?: Readonly<Record<string, unknown>>;
|
|
70
|
+
readonly assetBase?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface PublicationHandle {
|
|
73
|
+
dispose(): void;
|
|
74
|
+
}
|
|
75
|
+
export declare function compilePublication(source: PreparedDocument | RenderPlan, options?: PublicationCompilerOptions): PublicationArtifact;
|
|
76
|
+
//# sourceMappingURL=publication-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publication-core.d.ts","sourceRoot":"","sources":["../src/publication-core.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,mBAAmB,EAEpB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACx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,QAAQ,GAAG,eAAe,GAAG,UAAU,GAAG,eAAe,GAAG,SAAS,CACtE,CAAC;AACF,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,mBAAmB,GAC5B,yBAAyB,CAU3B;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,eAAe,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5E,QAAQ,CAAC,KAAK,CAAC,EAAE,CACf,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,KACpD,OAAO,CAAC;IACb,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/C,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,IAAI,IAAI,CAAC;CACjB;AAuLD,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,gBAAgB,GAAG,UAAU,EACrC,OAAO,GAAE,0BAA+B,GACvC,mBAAmB,CA4BrB"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { sha256Hex } from "@publisle/core";
|
|
2
|
+
import { canonicalizeJson } from "@publisle/schema";
|
|
3
|
+
import { serializeNodes } from "./html.js";
|
|
4
|
+
export { instantiatePublication, collectPublicationAssets, publicationAssetUrl, attachPublication, } from "./publication-runtime.js";
|
|
5
|
+
import { createRenderPlan } from "./render-plan-core.js";
|
|
6
|
+
function escapeAttribute(value) {
|
|
7
|
+
return value
|
|
8
|
+
.replaceAll("&", "&")
|
|
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);
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=publication-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publication-core.js","sourceRoot":"","sources":["../src/publication-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AASpD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,KAAK;SACT,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;SACxB,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC;SACzB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AA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AE,mBAAmB,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,EACtE,MAAM,EACN,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,gBAAgB,CACzB,CAAC;AACJ,CAAC"}
|
package/dist/publication.d.ts
CHANGED
|
@@ -1,76 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
export declare
|
|
5
|
-
export declare const PUBLICATION_FORMAT_VERSION: 1;
|
|
6
|
-
export declare const RENDERER_BUILD = "1";
|
|
7
|
-
export declare const DOCUMENT_STYLESHEET_ID = "publisle/document.css";
|
|
8
|
-
export declare const KATEX_STYLESHEET_ID = "publisle/katex.css";
|
|
9
|
-
export interface AssetReference {
|
|
10
|
-
readonly id: string;
|
|
11
|
-
}
|
|
12
|
-
export interface ModuleReference {
|
|
13
|
-
readonly id: string;
|
|
14
|
-
}
|
|
15
|
-
export interface PublishedIsland {
|
|
16
|
-
readonly key: string;
|
|
17
|
-
readonly implementation: string;
|
|
18
|
-
readonly activation: Activation;
|
|
19
|
-
readonly mode: "mount" | "hydrate";
|
|
20
|
-
readonly props: JsonValue;
|
|
21
|
-
}
|
|
22
|
-
export interface PublicationArtifact {
|
|
23
|
-
readonly provenance?: {
|
|
24
|
-
readonly sourceIdentity: string | null;
|
|
25
|
-
readonly semanticIdentity: string;
|
|
26
|
-
readonly contracts: readonly import("@publisle/schema").ContractDependency[];
|
|
27
|
-
readonly resources: import("@publisle/schema").ResourcePlan;
|
|
28
|
-
readonly configuration: JsonValue;
|
|
29
|
-
readonly reproducible: boolean;
|
|
30
|
-
readonly seed?: JsonValue;
|
|
31
|
-
readonly limitation?: string;
|
|
32
|
-
};
|
|
33
|
-
readonly diagnosticIdentity?: string;
|
|
34
|
-
readonly compatibility?: {
|
|
35
|
-
readonly islandInputVersion: 1;
|
|
36
|
-
readonly staticFidelity: "supported" | "fallback" | "unsupported";
|
|
37
|
-
};
|
|
38
|
-
readonly format: typeof PUBLICATION_FORMAT;
|
|
39
|
-
readonly formatVersion: typeof PUBLICATION_FORMAT_VERSION;
|
|
40
|
-
readonly identity: string;
|
|
41
|
-
readonly rendererBuild: string;
|
|
42
|
-
readonly html: string;
|
|
43
|
-
readonly styles: readonly AssetReference[];
|
|
44
|
-
readonly modules: readonly ModuleReference[];
|
|
45
|
-
readonly islands: readonly PublishedIsland[];
|
|
46
|
-
readonly metadata?: PublicationMetadata;
|
|
47
|
-
readonly diagnostics: readonly Diagnostic[];
|
|
48
|
-
}
|
|
49
|
-
export interface PublicationCompilerOptions extends AdapterCompilerOptions {
|
|
50
|
-
/** Host pins for otherwise opaque renderer/compiler configuration. Never infer function source. */
|
|
51
|
-
readonly build?: {
|
|
52
|
-
readonly configuration: JsonValue;
|
|
53
|
-
readonly reproducible: boolean;
|
|
54
|
-
readonly seed?: JsonValue;
|
|
55
|
-
};
|
|
56
|
-
readonly styles?: "minimal" | "none";
|
|
57
|
-
}
|
|
58
|
-
export interface PublicationPlacement {
|
|
59
|
-
readonly instanceId: string;
|
|
60
|
-
readonly html: string;
|
|
61
|
-
}
|
|
62
|
-
/** Minimal browser attachment data; excludes HTML, source AST, resources and diagnostics. */
|
|
63
|
-
export type PublicationReaderManifest = Pick<PublicationArtifact, "format" | "formatVersion" | "identity" | "compatibility" | "islands">;
|
|
64
|
-
export declare function publicationReaderManifest(artifact: PublicationArtifact): PublicationReaderManifest;
|
|
65
|
-
export interface PublicationEnvironment {
|
|
66
|
-
readonly implementations?: Readonly<Record<string, () => Promise<unknown>>>;
|
|
67
|
-
readonly mount?: (module: unknown, target: HTMLElement, props: JsonValue, services: Readonly<Record<string, unknown>> | undefined) => unknown;
|
|
68
|
-
readonly unmount?: (instance: unknown) => void;
|
|
69
|
-
readonly services?: Readonly<Record<string, unknown>>;
|
|
70
|
-
readonly assetBase?: string;
|
|
71
|
-
}
|
|
72
|
-
export interface PublicationHandle {
|
|
73
|
-
dispose(): void;
|
|
74
|
-
}
|
|
75
|
-
export declare function compilePublication(source: PreparedDocument | RenderPlan, options?: PublicationCompilerOptions): PublicationArtifact;
|
|
1
|
+
import { compilePublication as compile } from "./publication-core.js";
|
|
2
|
+
export * from "./publication-core.js";
|
|
3
|
+
/** Synchronous compiler with bundled math support. */
|
|
4
|
+
export declare function compilePublication(...args: Parameters<typeof compile>): ReturnType<typeof compile>;
|
|
76
5
|
//# sourceMappingURL=publication.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publication.d.ts","sourceRoot":"","sources":["../src/publication.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"publication.d.ts","sourceRoot":"","sources":["../src/publication.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,IAAI,OAAO,EAAE,8BAA8B;AACtE,sCAAsC;AACtC,sDAAsD;AACtD,wBAAgB,kBAAkB,CAChC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,GAClC,UAAU,CAAC,OAAO,OAAO,CAAC,CAG5B"}
|
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
|