reactive-md 0.6.0 → 0.6.1
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/CHANGELOG-ch.md +203 -194
- package/CHANGELOG.md +203 -194
- package/CONTRIBUTING-ch.md +67 -67
- package/CONTRIBUTING.md +69 -69
- package/README-ch.md +157 -157
- package/README-en.md +184 -184
- package/README.md +184 -184
- package/SECURITY-ch.md +81 -81
- package/SECURITY.md +81 -81
- package/THIRD_PARTY_NOTICES.md +313 -209
- package/bin/reactive-md.mjs +39 -39
- package/cli/args.mjs +181 -181
- package/cli/assets.mjs +390 -390
- package/cli/build.mjs +268 -268
- package/cli/document.mjs +130 -130
- package/cli/errors.mjs +61 -61
- package/cli/fs-utils.mjs +133 -133
- package/cli/glob.mjs +203 -203
- package/cli/help.mjs +138 -138
- package/cli/lint.mjs +177 -177
- package/cli/main.mjs +55 -55
- package/cli/migrate.mjs +368 -368
- package/cli/package.mjs +210 -210
- package/dist-library/{authoring-DSC0VsNK.js → authoring-BEVyth5X.js} +1 -1
- package/dist-library/compiler-Cm3ppMxG.js +46044 -0
- package/dist-library/{react-Dk94rcOp.js → react-Bh7_oxZp.js} +20110 -20113
- package/dist-library/reactive-md-authoring.js +2 -2
- package/dist-library/reactive-md-print.css +284 -284
- package/dist-library/reactive-md-react-unstyled.js +1 -1
- package/dist-library/reactive-md-react.js +1 -1
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +3 -3
- package/dist-library/{runtime-D8KbnCd0.js → runtime-DlFYQ4s_.js} +1 -1
- package/dist-library/types/local/math-display.d.ts +22 -23
- package/dist-library/types/local/math-view.d.ts +6 -7
- package/dist-standalone/reactive-md-standalone.css +1 -1
- package/dist-standalone/reactive-md-standalone.js +318 -62
- package/docs/compatibility/compatibility-ch.md +121 -119
- package/docs/compatibility/compatibility-en.md +121 -119
- package/docs/compatibility/source-versioning-ch.md +159 -159
- package/docs/compatibility/source-versioning-en.md +159 -159
- package/docs/development/component-development-ch.md +210 -210
- package/docs/development/component-development-en.md +210 -210
- package/docs/development/component-protocol-ch.md +747 -747
- package/docs/development/component-protocol-en.md +747 -747
- package/docs/development/performance-ch.md +76 -76
- package/docs/development/performance-en.md +76 -76
- package/docs/development/releasing-ch.md +108 -108
- package/docs/development/releasing-en.md +108 -108
- package/docs/integration/author-tools-ch.md +62 -62
- package/docs/integration/author-tools-en.md +62 -62
- package/docs/integration/shareable-export-ch.md +209 -209
- package/docs/integration/shareable-export-en.md +211 -211
- package/docs/reference/computations-formatting-ch.md +87 -87
- package/docs/reference/computations-formatting-en.md +87 -87
- package/docs/reference/constraints-collections-ch.md +84 -84
- package/docs/reference/constraints-collections-en.md +84 -84
- package/docs/reference/diagnostics-counting-ch.md +104 -104
- package/docs/reference/diagnostics-counting-en.md +104 -104
- package/docs/reference/local-components-v2-ch.md +138 -138
- package/docs/reference/local-components-v2-en.md +104 -104
- package/docs/reference/local-interaction-syntax-ch.md +515 -511
- package/docs/reference/local-interaction-syntax-en.md +511 -507
- package/docs/reference/theme-protocol-ch.md +107 -107
- package/docs/reference/theme-protocol-en.md +107 -107
- package/docs/releases/release-0.4.0-ch.md +89 -89
- package/docs/releases/release-0.4.0-en.md +89 -89
- package/docs/releases/release-0.4.1-ch.md +23 -23
- package/docs/releases/release-0.4.1-en.md +23 -23
- package/docs/releases/release-0.6.1-ch.md +27 -0
- package/docs/releases/release-0.6.1-en.md +27 -0
- package/examples/conformance/README.md +53 -53
- package/examples/conformance/component-protocol-1.json +482 -482
- package/examples/conformance/component-protocol-1.schema.json +76 -76
- package/examples/conformance/local-draft-1.json +50 -50
- package/examples/conformance/local-draft-2.json +212 -212
- package/examples/integration/README.md +47 -47
- package/examples/integration/core/index.mjs +32 -32
- package/examples/integration/worker/index.html +19 -19
- package/examples/integration/worker/main.js +61 -61
- package/examples/integration/worker/package.json +13 -13
- package/examples/integration/worker/worker.js +3 -3
- package/examples/local/README.md +74 -74
- package/examples/local/charts.reactive.md +73 -73
- package/examples/local/recipes/invoice-zh.reactive.md +36 -36
- package/examples/local/recipes/invoice.reactive.md +36 -36
- package/examples/local/recipes/workshop-zh.reactive.md +33 -33
- package/examples/local/recipes/workshop.reactive.md +33 -33
- package/examples/local/showcase/README.md +25 -25
- package/examples/local/showcase/explore.reactive.md +102 -102
- package/examples/local/showcase/flow.reactive.md +86 -86
- package/examples/local/showcase/forms.reactive.md +126 -126
- package/examples/local/showcase/functions.reactive.md +119 -119
- package/examples/local/showcase/layout.reactive.md +100 -100
- package/examples/local/showcase/statistics.reactive.md +108 -108
- package/examples/local/showcase/tasks.reactive.md +89 -89
- package/examples/local/showcase/zh/explore.reactive.md +102 -102
- package/examples/local/showcase/zh/flow.reactive.md +86 -86
- package/examples/local/showcase/zh/forms.reactive.md +126 -126
- package/examples/local/showcase/zh/functions.reactive.md +119 -119
- package/examples/local/showcase/zh/layout.reactive.md +100 -100
- package/examples/local/showcase/zh/statistics.reactive.md +108 -108
- package/examples/local/showcase/zh/tasks.reactive.md +89 -89
- package/package.json +152 -152
- package/dist-library/compiler-CRD88BMt.js +0 -24964
package/cli/package.mjs
CHANGED
|
@@ -1,210 +1,210 @@
|
|
|
1
|
-
import { readFile, stat } from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import { CliError, EXIT, errorText } from './errors.mjs';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Artifact locations are always relative to the installed package root
|
|
8
|
-
* (bin/..), never the current working directory.
|
|
9
|
-
*/
|
|
10
|
-
export const ARTIFACTS = Object.freeze({
|
|
11
|
-
core: { relative: 'dist-library/reactive-md.js', label: 'core build' },
|
|
12
|
-
react: { relative: 'dist-library/reactive-md-react.js', label: 'React renderer build' },
|
|
13
|
-
css: { relative: 'dist-library/reactive-md.css', label: 'stylesheet build' },
|
|
14
|
-
printCss: { relative: 'dist-library/reactive-md-print.css', label: 'print stylesheet build' },
|
|
15
|
-
standalone: { relative: 'dist-standalone/reactive-md-standalone.js', label: 'standalone runtime build' },
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const BUILD_HINT = 'Run "npm run build" from a source checkout before building documents.';
|
|
19
|
-
|
|
20
|
-
/** @param {string} packageRoot @param {keyof typeof ARTIFACTS} key */
|
|
21
|
-
export function artifactPath(packageRoot, key) {
|
|
22
|
-
return path.join(packageRoot, ARTIFACTS[key].relative);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** @param {string} packageRoot */
|
|
26
|
-
export async function readPackageInfo(packageRoot) {
|
|
27
|
-
const file = path.join(packageRoot, 'package.json');
|
|
28
|
-
let text;
|
|
29
|
-
try {
|
|
30
|
-
text = await readFile(file, 'utf8');
|
|
31
|
-
} catch (error) {
|
|
32
|
-
throw new CliError(
|
|
33
|
-
`Cannot read package metadata at "${file}": ${errorText(error)}. Reinstall reactive-md.`,
|
|
34
|
-
EXIT.DOCUMENT,
|
|
35
|
-
{ cause: error },
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
let parsed;
|
|
39
|
-
try {
|
|
40
|
-
parsed = JSON.parse(text);
|
|
41
|
-
} catch (error) {
|
|
42
|
-
throw new CliError(
|
|
43
|
-
`Package metadata at "${file}" is not valid JSON: ${errorText(error)}. Reinstall reactive-md.`,
|
|
44
|
-
EXIT.DOCUMENT,
|
|
45
|
-
{ cause: error },
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
if (!parsed || typeof parsed !== 'object' || typeof parsed.version !== 'string' || parsed.version === '') {
|
|
49
|
-
throw new CliError(`Package metadata at "${file}" does not declare a version. Reinstall reactive-md.`, EXIT.DOCUMENT);
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
name: typeof parsed.name === 'string' ? parsed.name : 'reactive-md',
|
|
53
|
-
version: parsed.version,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** @param {string} packageRoot @param {keyof typeof ARTIFACTS} key */
|
|
58
|
-
export async function assertArtifact(packageRoot, key) {
|
|
59
|
-
const entry = ARTIFACTS[key];
|
|
60
|
-
const file = artifactPath(packageRoot, key);
|
|
61
|
-
let info;
|
|
62
|
-
try {
|
|
63
|
-
info = await stat(file);
|
|
64
|
-
} catch (error) {
|
|
65
|
-
throw new CliError(`Missing ${entry.label}: "${file}". ${BUILD_HINT}`, EXIT.DOCUMENT, { cause: error });
|
|
66
|
-
}
|
|
67
|
-
if (!info.isFile()) {
|
|
68
|
-
throw new CliError(`Missing ${entry.label}: "${file}" is not a regular file. ${BUILD_HINT}`, EXIT.DOCUMENT);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Import the core artifact and verify the exports this command needs.
|
|
74
|
-
* @param {string} packageRoot
|
|
75
|
-
* @param {string[]} requiredExports
|
|
76
|
-
*/
|
|
77
|
-
export async function loadCore(packageRoot, requiredExports = ['compileLocal']) {
|
|
78
|
-
await assertArtifact(packageRoot, 'core');
|
|
79
|
-
const file = artifactPath(packageRoot, 'core');
|
|
80
|
-
let module;
|
|
81
|
-
try {
|
|
82
|
-
module = await import(pathToFileURL(file).href);
|
|
83
|
-
} catch (error) {
|
|
84
|
-
throw new CliError(
|
|
85
|
-
`Cannot load the core build at "${file}": ${errorText(error)}. ${BUILD_HINT}`,
|
|
86
|
-
EXIT.DOCUMENT,
|
|
87
|
-
{ cause: error },
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
for (const name of requiredExports) {
|
|
91
|
-
if (typeof module?.[name] !== 'function') {
|
|
92
|
-
throw new CliError(
|
|
93
|
-
`The core build at "${file}" is missing the "${name}" export. ${BUILD_HINT}`,
|
|
94
|
-
EXIT.DOCUMENT,
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return module;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** @param {string} packageRoot @param {keyof typeof ARTIFACTS} key */
|
|
102
|
-
export async function readArtifactText(packageRoot, key) {
|
|
103
|
-
await assertArtifact(packageRoot, key);
|
|
104
|
-
const file = artifactPath(packageRoot, key);
|
|
105
|
-
try {
|
|
106
|
-
const text = await readFile(file, 'utf8');
|
|
107
|
-
if (text.trim() === '') {
|
|
108
|
-
throw new CliError(`The ${ARTIFACTS[key].label} at "${file}" is empty. ${BUILD_HINT}`, EXIT.DOCUMENT);
|
|
109
|
-
}
|
|
110
|
-
return text;
|
|
111
|
-
} catch (error) {
|
|
112
|
-
if (error instanceof CliError) throw error;
|
|
113
|
-
throw new CliError(
|
|
114
|
-
`Cannot read the ${ARTIFACTS[key].label} at "${file}": ${errorText(error)}. ${BUILD_HINT}`,
|
|
115
|
-
EXIT.DOCUMENT,
|
|
116
|
-
{ cause: error },
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Read the packaged notices file when present. The shareable shell escapes it;
|
|
123
|
-
* a source checkout without generated notices simply omits the section.
|
|
124
|
-
*
|
|
125
|
-
* @param {string} packageRoot
|
|
126
|
-
*/
|
|
127
|
-
export async function readNotices(packageRoot) {
|
|
128
|
-
try {
|
|
129
|
-
return await readFile(path.join(packageRoot, 'THIRD_PARTY_NOTICES.md'), 'utf8');
|
|
130
|
-
} catch {
|
|
131
|
-
return '';
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** @param {string} packageName @param {unknown} [error] */
|
|
136
|
-
function reactFailure(packageName, error) {
|
|
137
|
-
const detail = error === undefined ? '' : ` (${errorText(error)})`;
|
|
138
|
-
return new CliError(
|
|
139
|
-
`HTML builds need React 19 installed. Cannot load "${packageName}"${detail}. `
|
|
140
|
-
+ 'Install "react@^19" and "react-dom@^19" in the project that installs reactive-md.',
|
|
141
|
-
EXIT.DOCUMENT,
|
|
142
|
-
error === undefined ? undefined : { cause: error },
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Dynamically load React as an optional peer. Both interactive and static HTML
|
|
148
|
-
* builds server-render the document, so both need React 19.
|
|
149
|
-
*/
|
|
150
|
-
export async function loadReact() {
|
|
151
|
-
let reactModule;
|
|
152
|
-
try {
|
|
153
|
-
reactModule = await import('react');
|
|
154
|
-
} catch (error) {
|
|
155
|
-
throw reactFailure('react', error);
|
|
156
|
-
}
|
|
157
|
-
const React = reactModule?.default ?? reactModule;
|
|
158
|
-
const createElement = reactModule?.createElement ?? React?.createElement;
|
|
159
|
-
const version = reactModule?.version ?? React?.version;
|
|
160
|
-
if (typeof createElement !== 'function') {
|
|
161
|
-
throw reactFailure('react', new Error('the createElement export is missing'));
|
|
162
|
-
}
|
|
163
|
-
if (typeof version !== 'string' || !version.startsWith('19.')) {
|
|
164
|
-
throw new CliError(
|
|
165
|
-
`HTML builds need React 19 installed; found React ${version ?? 'unknown'}. `
|
|
166
|
-
+ 'Install "react@^19" and "react-dom@^19" in the project that installs reactive-md.',
|
|
167
|
-
EXIT.DOCUMENT,
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
let serverModule;
|
|
172
|
-
try {
|
|
173
|
-
serverModule = await import('react-dom/server');
|
|
174
|
-
} catch (error) {
|
|
175
|
-
throw reactFailure('react-dom/server', error);
|
|
176
|
-
}
|
|
177
|
-
const renderToString = serverModule?.renderToString ?? serverModule?.default?.renderToString;
|
|
178
|
-
if (typeof renderToString !== 'function') {
|
|
179
|
-
throw reactFailure('react-dom/server', new Error('the renderToString export is missing'));
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return { createElement, renderToString, version };
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Load the built React renderer. It is a package artifact, so failures point at
|
|
187
|
-
* the build rather than at the user's document.
|
|
188
|
-
* @param {string} packageRoot
|
|
189
|
-
*/
|
|
190
|
-
export async function loadReactRenderer(packageRoot) {
|
|
191
|
-
await assertArtifact(packageRoot, 'react');
|
|
192
|
-
const file = artifactPath(packageRoot, 'react');
|
|
193
|
-
let module;
|
|
194
|
-
try {
|
|
195
|
-
module = await import(pathToFileURL(file).href);
|
|
196
|
-
} catch (error) {
|
|
197
|
-
throw new CliError(
|
|
198
|
-
`Cannot load the React renderer build at "${file}": ${errorText(error)}. ${BUILD_HINT}`,
|
|
199
|
-
EXIT.DOCUMENT,
|
|
200
|
-
{ cause: error },
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
if (typeof module?.LocalDocumentView !== 'function') {
|
|
204
|
-
throw new CliError(
|
|
205
|
-
`The React renderer build at "${file}" is missing the "LocalDocumentView" export. ${BUILD_HINT}`,
|
|
206
|
-
EXIT.DOCUMENT,
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
return { LocalDocumentView: module.LocalDocumentView };
|
|
210
|
-
}
|
|
1
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { CliError, EXIT, errorText } from './errors.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Artifact locations are always relative to the installed package root
|
|
8
|
+
* (bin/..), never the current working directory.
|
|
9
|
+
*/
|
|
10
|
+
export const ARTIFACTS = Object.freeze({
|
|
11
|
+
core: { relative: 'dist-library/reactive-md.js', label: 'core build' },
|
|
12
|
+
react: { relative: 'dist-library/reactive-md-react.js', label: 'React renderer build' },
|
|
13
|
+
css: { relative: 'dist-library/reactive-md.css', label: 'stylesheet build' },
|
|
14
|
+
printCss: { relative: 'dist-library/reactive-md-print.css', label: 'print stylesheet build' },
|
|
15
|
+
standalone: { relative: 'dist-standalone/reactive-md-standalone.js', label: 'standalone runtime build' },
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const BUILD_HINT = 'Run "npm run build" from a source checkout before building documents.';
|
|
19
|
+
|
|
20
|
+
/** @param {string} packageRoot @param {keyof typeof ARTIFACTS} key */
|
|
21
|
+
export function artifactPath(packageRoot, key) {
|
|
22
|
+
return path.join(packageRoot, ARTIFACTS[key].relative);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @param {string} packageRoot */
|
|
26
|
+
export async function readPackageInfo(packageRoot) {
|
|
27
|
+
const file = path.join(packageRoot, 'package.json');
|
|
28
|
+
let text;
|
|
29
|
+
try {
|
|
30
|
+
text = await readFile(file, 'utf8');
|
|
31
|
+
} catch (error) {
|
|
32
|
+
throw new CliError(
|
|
33
|
+
`Cannot read package metadata at "${file}": ${errorText(error)}. Reinstall reactive-md.`,
|
|
34
|
+
EXIT.DOCUMENT,
|
|
35
|
+
{ cause: error },
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
let parsed;
|
|
39
|
+
try {
|
|
40
|
+
parsed = JSON.parse(text);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new CliError(
|
|
43
|
+
`Package metadata at "${file}" is not valid JSON: ${errorText(error)}. Reinstall reactive-md.`,
|
|
44
|
+
EXIT.DOCUMENT,
|
|
45
|
+
{ cause: error },
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
if (!parsed || typeof parsed !== 'object' || typeof parsed.version !== 'string' || parsed.version === '') {
|
|
49
|
+
throw new CliError(`Package metadata at "${file}" does not declare a version. Reinstall reactive-md.`, EXIT.DOCUMENT);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
name: typeof parsed.name === 'string' ? parsed.name : 'reactive-md',
|
|
53
|
+
version: parsed.version,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @param {string} packageRoot @param {keyof typeof ARTIFACTS} key */
|
|
58
|
+
export async function assertArtifact(packageRoot, key) {
|
|
59
|
+
const entry = ARTIFACTS[key];
|
|
60
|
+
const file = artifactPath(packageRoot, key);
|
|
61
|
+
let info;
|
|
62
|
+
try {
|
|
63
|
+
info = await stat(file);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
throw new CliError(`Missing ${entry.label}: "${file}". ${BUILD_HINT}`, EXIT.DOCUMENT, { cause: error });
|
|
66
|
+
}
|
|
67
|
+
if (!info.isFile()) {
|
|
68
|
+
throw new CliError(`Missing ${entry.label}: "${file}" is not a regular file. ${BUILD_HINT}`, EXIT.DOCUMENT);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Import the core artifact and verify the exports this command needs.
|
|
74
|
+
* @param {string} packageRoot
|
|
75
|
+
* @param {string[]} requiredExports
|
|
76
|
+
*/
|
|
77
|
+
export async function loadCore(packageRoot, requiredExports = ['compileLocal']) {
|
|
78
|
+
await assertArtifact(packageRoot, 'core');
|
|
79
|
+
const file = artifactPath(packageRoot, 'core');
|
|
80
|
+
let module;
|
|
81
|
+
try {
|
|
82
|
+
module = await import(pathToFileURL(file).href);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
throw new CliError(
|
|
85
|
+
`Cannot load the core build at "${file}": ${errorText(error)}. ${BUILD_HINT}`,
|
|
86
|
+
EXIT.DOCUMENT,
|
|
87
|
+
{ cause: error },
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
for (const name of requiredExports) {
|
|
91
|
+
if (typeof module?.[name] !== 'function') {
|
|
92
|
+
throw new CliError(
|
|
93
|
+
`The core build at "${file}" is missing the "${name}" export. ${BUILD_HINT}`,
|
|
94
|
+
EXIT.DOCUMENT,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return module;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** @param {string} packageRoot @param {keyof typeof ARTIFACTS} key */
|
|
102
|
+
export async function readArtifactText(packageRoot, key) {
|
|
103
|
+
await assertArtifact(packageRoot, key);
|
|
104
|
+
const file = artifactPath(packageRoot, key);
|
|
105
|
+
try {
|
|
106
|
+
const text = await readFile(file, 'utf8');
|
|
107
|
+
if (text.trim() === '') {
|
|
108
|
+
throw new CliError(`The ${ARTIFACTS[key].label} at "${file}" is empty. ${BUILD_HINT}`, EXIT.DOCUMENT);
|
|
109
|
+
}
|
|
110
|
+
return text;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (error instanceof CliError) throw error;
|
|
113
|
+
throw new CliError(
|
|
114
|
+
`Cannot read the ${ARTIFACTS[key].label} at "${file}": ${errorText(error)}. ${BUILD_HINT}`,
|
|
115
|
+
EXIT.DOCUMENT,
|
|
116
|
+
{ cause: error },
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Read the packaged notices file when present. The shareable shell escapes it;
|
|
123
|
+
* a source checkout without generated notices simply omits the section.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} packageRoot
|
|
126
|
+
*/
|
|
127
|
+
export async function readNotices(packageRoot) {
|
|
128
|
+
try {
|
|
129
|
+
return await readFile(path.join(packageRoot, 'THIRD_PARTY_NOTICES.md'), 'utf8');
|
|
130
|
+
} catch {
|
|
131
|
+
return '';
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** @param {string} packageName @param {unknown} [error] */
|
|
136
|
+
function reactFailure(packageName, error) {
|
|
137
|
+
const detail = error === undefined ? '' : ` (${errorText(error)})`;
|
|
138
|
+
return new CliError(
|
|
139
|
+
`HTML builds need React 19 installed. Cannot load "${packageName}"${detail}. `
|
|
140
|
+
+ 'Install "react@^19" and "react-dom@^19" in the project that installs reactive-md.',
|
|
141
|
+
EXIT.DOCUMENT,
|
|
142
|
+
error === undefined ? undefined : { cause: error },
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Dynamically load React as an optional peer. Both interactive and static HTML
|
|
148
|
+
* builds server-render the document, so both need React 19.
|
|
149
|
+
*/
|
|
150
|
+
export async function loadReact() {
|
|
151
|
+
let reactModule;
|
|
152
|
+
try {
|
|
153
|
+
reactModule = await import('react');
|
|
154
|
+
} catch (error) {
|
|
155
|
+
throw reactFailure('react', error);
|
|
156
|
+
}
|
|
157
|
+
const React = reactModule?.default ?? reactModule;
|
|
158
|
+
const createElement = reactModule?.createElement ?? React?.createElement;
|
|
159
|
+
const version = reactModule?.version ?? React?.version;
|
|
160
|
+
if (typeof createElement !== 'function') {
|
|
161
|
+
throw reactFailure('react', new Error('the createElement export is missing'));
|
|
162
|
+
}
|
|
163
|
+
if (typeof version !== 'string' || !version.startsWith('19.')) {
|
|
164
|
+
throw new CliError(
|
|
165
|
+
`HTML builds need React 19 installed; found React ${version ?? 'unknown'}. `
|
|
166
|
+
+ 'Install "react@^19" and "react-dom@^19" in the project that installs reactive-md.',
|
|
167
|
+
EXIT.DOCUMENT,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
let serverModule;
|
|
172
|
+
try {
|
|
173
|
+
serverModule = await import('react-dom/server');
|
|
174
|
+
} catch (error) {
|
|
175
|
+
throw reactFailure('react-dom/server', error);
|
|
176
|
+
}
|
|
177
|
+
const renderToString = serverModule?.renderToString ?? serverModule?.default?.renderToString;
|
|
178
|
+
if (typeof renderToString !== 'function') {
|
|
179
|
+
throw reactFailure('react-dom/server', new Error('the renderToString export is missing'));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return { createElement, renderToString, version };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Load the built React renderer. It is a package artifact, so failures point at
|
|
187
|
+
* the build rather than at the user's document.
|
|
188
|
+
* @param {string} packageRoot
|
|
189
|
+
*/
|
|
190
|
+
export async function loadReactRenderer(packageRoot) {
|
|
191
|
+
await assertArtifact(packageRoot, 'react');
|
|
192
|
+
const file = artifactPath(packageRoot, 'react');
|
|
193
|
+
let module;
|
|
194
|
+
try {
|
|
195
|
+
module = await import(pathToFileURL(file).href);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
throw new CliError(
|
|
198
|
+
`Cannot load the React renderer build at "${file}": ${errorText(error)}. ${BUILD_HINT}`,
|
|
199
|
+
EXIT.DOCUMENT,
|
|
200
|
+
{ cause: error },
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
if (typeof module?.LocalDocumentView !== 'function') {
|
|
204
|
+
throw new CliError(
|
|
205
|
+
`The React renderer build at "${file}" is missing the "LocalDocumentView" export. ${BUILD_HINT}`,
|
|
206
|
+
EXIT.DOCUMENT,
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
return { LocalDocumentView: module.LocalDocumentView };
|
|
210
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as e, X as t, d as n, m as r, q as i, t as a, w as o } from "./compiler-
|
|
1
|
+
import { S as e, X as t, d as n, m as r, q as i, t as a, w as o } from "./compiler-Cm3ppMxG.js";
|
|
2
2
|
// src/local/authoring.ts
|
|
3
3
|
var s = /^[A-Za-z_][A-Za-z0-9_]*$/, c = 128, l = /* @__PURE__ */ new Set([
|
|
4
4
|
"code",
|