reactive-md 0.5.3 → 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 +195 -165
- package/CHANGELOG.md +195 -165
- package/CONTRIBUTING-ch.md +67 -62
- package/CONTRIBUTING.md +69 -64
- package/README-ch.md +157 -155
- package/README-en.md +184 -181
- package/README.md +184 -181
- package/SECURITY-ch.md +81 -81
- package/SECURITY.md +81 -81
- package/THIRD_PARTY_NOTICES.md +585 -1
- 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-DJJjKYg9.js → authoring-BEVyth5X.js} +58 -58
- package/dist-library/compiler-Cm3ppMxG.js +46044 -0
- package/dist-library/react-Bh7_oxZp.js +59655 -0
- package/dist-library/reactive-md-authoring.js +2 -2
- package/dist-library/reactive-md-editor.js +13 -0
- 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 +123 -123
- package/dist-library/{runtime-DXtle_6c.js → runtime-DlFYQ4s_.js} +151 -151
- package/dist-library/types/editor/types.d.ts +2 -0
- package/dist-library/types/local/code-block.d.ts +3 -1
- package/dist-library/types/local/code-languages.d.ts +7 -0
- package/dist-library/types/local/compiled-data.d.ts +6 -0
- package/dist-library/types/local/compiler.d.ts +1 -0
- package/dist-library/types/local/diagnostics.d.ts +31 -0
- package/dist-library/types/local/diagram-layout.d.ts +69 -0
- package/dist-library/types/local/html-names.d.ts +6 -0
- package/dist-library/types/local/html-table.d.ts +25 -0
- package/dist-library/types/local/math-display.d.ts +22 -22
- package/dist-library/types/local/math-view.d.ts +6 -7
- package/dist-library/types/local/table-surface.d.ts +10 -0
- package/dist-library/types/local/types.d.ts +2 -0
- package/dist-library/types/local/visuals.d.ts +9 -0
- package/dist-standalone/reactive-md-standalone.css +1 -1
- package/dist-standalone/reactive-md-standalone.js +331 -51
- package/docs/README.md +84 -0
- package/docs/{compatibility-ch.md → compatibility/compatibility-ch.md} +121 -109
- package/docs/{compatibility-en.md → compatibility/compatibility-en.md} +121 -109
- package/docs/{source-versioning-ch.md → compatibility/source-versioning-ch.md} +159 -159
- package/docs/{source-versioning-en.md → compatibility/source-versioning-en.md} +159 -159
- package/docs/{component-development-ch.md → development/component-development-ch.md} +210 -210
- package/docs/{component-development-en.md → development/component-development-en.md} +210 -210
- package/docs/{component-protocol-ch.md → development/component-protocol-ch.md} +747 -747
- package/docs/{component-protocol-en.md → development/component-protocol-en.md} +747 -747
- package/docs/{performance-ch.md → development/performance-ch.md} +76 -76
- package/docs/{performance-en.md → development/performance-en.md} +76 -76
- package/docs/{releasing-ch.md → development/releasing-ch.md} +108 -108
- package/docs/{releasing-en.md → development/releasing-en.md} +108 -108
- package/docs/guides/local-guide-ch.md +513 -0
- package/docs/guides/local-guide-en.md +513 -0
- package/docs/{author-tools-ch.md → integration/author-tools-ch.md} +57 -57
- package/docs/{author-tools-en.md → integration/author-tools-en.md} +57 -57
- package/docs/{editor-ch.md → integration/editor-ch.md} +7 -6
- package/docs/{editor-en.md → integration/editor-en.md} +7 -6
- package/docs/{local-integration-ch.md → integration/local-integration-ch.md} +33 -15
- package/docs/{local-integration-en.md → integration/local-integration-en.md} +33 -15
- package/docs/{shareable-export-ch.md → integration/shareable-export-ch.md} +221 -209
- package/docs/{shareable-export-en.md → integration/shareable-export-en.md} +223 -211
- package/docs/{computations-formatting-ch.md → reference/computations-formatting-ch.md} +87 -87
- package/docs/{computations-formatting-en.md → reference/computations-formatting-en.md} +87 -87
- package/docs/{constraints-collections-ch.md → reference/constraints-collections-ch.md} +84 -84
- package/docs/{constraints-collections-en.md → reference/constraints-collections-en.md} +84 -84
- package/docs/{diagnostics-counting-ch.md → reference/diagnostics-counting-ch.md} +104 -84
- package/docs/{diagnostics-counting-en.md → reference/diagnostics-counting-en.md} +104 -84
- package/docs/{html-compatibility-ch.md → reference/html-compatibility-ch.md} +42 -4
- package/docs/{html-compatibility-en.md → reference/html-compatibility-en.md} +42 -4
- package/docs/{local-components-v2-ch.md → reference/local-components-v2-ch.md} +138 -138
- package/docs/{local-components-v2-en.md → reference/local-components-v2-en.md} +104 -104
- package/docs/{local-interaction-syntax-ch.md → reference/local-interaction-syntax-ch.md} +515 -492
- package/docs/{local-interaction-syntax-en.md → reference/local-interaction-syntax-en.md} +511 -488
- package/docs/{theme-protocol-ch.md → reference/theme-protocol-ch.md} +107 -107
- package/docs/{theme-protocol-en.md → reference/theme-protocol-en.md} +107 -107
- package/docs/{release-0.4.0-ch.md → releases/release-0.4.0-ch.md} +89 -89
- package/docs/{release-0.4.0-en.md → releases/release-0.4.0-en.md} +89 -89
- package/docs/{release-0.4.1-ch.md → releases/release-0.4.1-ch.md} +23 -23
- package/docs/{release-0.4.1-en.md → releases/release-0.4.1-en.md} +23 -23
- package/docs/{release-0.5.0-ch.md → releases/release-0.5.0-ch.md} +4 -4
- package/docs/{release-0.5.0-en.md → releases/release-0.5.0-en.md} +4 -4
- package/docs/{release-0.5.1-ch.md → releases/release-0.5.1-ch.md} +4 -4
- package/docs/{release-0.5.1-en.md → releases/release-0.5.1-en.md} +4 -4
- package/docs/{release-0.5.2-ch.md → releases/release-0.5.2-ch.md} +3 -3
- package/docs/{release-0.5.2-en.md → releases/release-0.5.2-en.md} +3 -3
- package/docs/{release-0.5.3-ch.md → releases/release-0.5.3-ch.md} +1 -1
- package/docs/{release-0.5.3-en.md → releases/release-0.5.3-en.md} +1 -1
- package/docs/releases/release-0.6.0-ch.md +57 -0
- package/docs/releases/release-0.6.0-en.md +57 -0
- 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 -45
- 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/html-compat.reactive.md +19 -0
- 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 -145
- package/dist-library/compiler-UyPwGzJZ.js +0 -22109
- package/dist-library/react-fizgU3i8.js +0 -12764
- package/docs/local-guide-ch.md +0 -967
- package/docs/local-guide-en.md +0 -967
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,
|
|
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",
|
|
@@ -32,7 +32,7 @@ function p(e) {
|
|
|
32
32
|
return e !== void 0 && /\s/.test(e);
|
|
33
33
|
}
|
|
34
34
|
function m(e) {
|
|
35
|
-
return e.length > 0 && e.length <= c && s.test(e) && !
|
|
35
|
+
return e.length > 0 && e.length <= c && s.test(e) && !t.has(e);
|
|
36
36
|
}
|
|
37
37
|
function h(e) {
|
|
38
38
|
return {
|
|
@@ -221,45 +221,45 @@ function S(e, t) {
|
|
|
221
221
|
offsets: r
|
|
222
222
|
};
|
|
223
223
|
}
|
|
224
|
-
function C(e,
|
|
225
|
-
let
|
|
226
|
-
for (let a =
|
|
227
|
-
let
|
|
228
|
-
if (
|
|
229
|
-
let
|
|
230
|
-
for (a += 1; a <
|
|
224
|
+
function C(e, n, r) {
|
|
225
|
+
let i = [];
|
|
226
|
+
for (let a = n; a < r;) {
|
|
227
|
+
let n = e[a];
|
|
228
|
+
if (n === "\"" || n === "'") {
|
|
229
|
+
let t = n;
|
|
230
|
+
for (a += 1; a < r;) if (e[a] === "\\") a += 2;
|
|
231
231
|
else {
|
|
232
|
-
if (e[a] ===
|
|
232
|
+
if (e[a] === t) {
|
|
233
233
|
a += 1;
|
|
234
234
|
break;
|
|
235
235
|
}
|
|
236
236
|
a += 1;
|
|
237
237
|
}
|
|
238
238
|
} else {
|
|
239
|
-
if (/[0-9]/.test(
|
|
240
|
-
let t = /^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(a,
|
|
239
|
+
if (/[0-9]/.test(n) || n === "." && e[a + 1] !== void 0 && /[0-9]/.test(e[a + 1])) {
|
|
240
|
+
let t = /^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(a, r));
|
|
241
241
|
if (t) {
|
|
242
242
|
a += t[0].length;
|
|
243
243
|
continue;
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
|
-
if (d(
|
|
247
|
-
let
|
|
248
|
-
for (a += 1; a <
|
|
249
|
-
let o = e.slice(
|
|
250
|
-
for (; s <
|
|
251
|
-
if (e[s] === "(" || o === "true" || o === "false" || o === "null" || o === "pi" || o === "e" ||
|
|
252
|
-
|
|
246
|
+
if (d(n)) {
|
|
247
|
+
let n = a;
|
|
248
|
+
for (a += 1; a < r && f(e[a]);) a += 1;
|
|
249
|
+
let o = e.slice(n, a), s = a;
|
|
250
|
+
for (; s < r && p(e[s]);) s += 1;
|
|
251
|
+
if (e[s] === "(" || o === "true" || o === "false" || o === "null" || o === "pi" || o === "e" || t.has(o)) continue;
|
|
252
|
+
i.push({
|
|
253
253
|
name: o,
|
|
254
254
|
range: {
|
|
255
|
-
start:
|
|
255
|
+
start: n,
|
|
256
256
|
end: a
|
|
257
257
|
}
|
|
258
258
|
});
|
|
259
259
|
} else a += 1;
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
-
return
|
|
262
|
+
return i;
|
|
263
263
|
}
|
|
264
264
|
function w(e, t) {
|
|
265
265
|
return Object.hasOwn(e.props, t) ? t === "bind" || !!e.slots?.some((e) => e.bind === t) : !1;
|
|
@@ -309,26 +309,26 @@ function D(e, t) {
|
|
|
309
309
|
values: t.enum
|
|
310
310
|
}])) : void 0;
|
|
311
311
|
}
|
|
312
|
-
function O(e,
|
|
313
|
-
let
|
|
312
|
+
function O(e, t, n) {
|
|
313
|
+
let r = [], a = /* @__PURE__ */ new Map(), s = [], c = [], l = (t, n) => {
|
|
314
314
|
for (let r of C(e, t, n)) s.push(r);
|
|
315
315
|
}, u = (e, t) => {
|
|
316
316
|
let n = a.get(e);
|
|
317
317
|
n ? n.push(h(t)) : a.set(e, [h(t)]);
|
|
318
|
-
}, d = (t,
|
|
318
|
+
}, d = (t, i) => {
|
|
319
319
|
let a = y(e, t.range.start);
|
|
320
320
|
if (!a || a.closing) return;
|
|
321
|
-
|
|
321
|
+
r.push({
|
|
322
322
|
kind: "tag",
|
|
323
323
|
range: h(a.nameRange)
|
|
324
324
|
});
|
|
325
325
|
let c = o(t.name ?? ""), l = a.attrs.some((e) => e.name === "key");
|
|
326
326
|
for (let o of a.attrs) {
|
|
327
|
-
if (
|
|
327
|
+
if (r.push({
|
|
328
328
|
kind: "attribute",
|
|
329
329
|
range: h(o.nameRange)
|
|
330
330
|
}), !o.valueRange) continue;
|
|
331
|
-
let a = D(t.name ?? "",
|
|
331
|
+
let a = D(t.name ?? "", n)?.[o.name], d = c !== void 0 && w(c, o.name) && (t.name !== "table" && t.name !== "chart" || !!l), f = (t.name === "computed" || t.name === "const") && o.name === "name", p = e.slice(o.valueRange.start, o.valueRange.end), g = S(e, o.valueRange);
|
|
332
332
|
if (t.name === "validation" && o.name === "fields") {
|
|
333
333
|
for (let e of g.text.matchAll(/\S+/g)) {
|
|
334
334
|
if (!m(e[0])) continue;
|
|
@@ -339,7 +339,7 @@ function O(e, n, r) {
|
|
|
339
339
|
s.push({
|
|
340
340
|
name: e[0],
|
|
341
341
|
range: t
|
|
342
|
-
}),
|
|
342
|
+
}), r.push({
|
|
343
343
|
kind: "binding",
|
|
344
344
|
range: t
|
|
345
345
|
});
|
|
@@ -349,93 +349,93 @@ function O(e, n, r) {
|
|
|
349
349
|
let _ = a && !a.static ? x(g.text, 0, g.text.length) : [];
|
|
350
350
|
if (_.length > 0) {
|
|
351
351
|
let e = 0;
|
|
352
|
-
for (let
|
|
353
|
-
|
|
352
|
+
for (let n of _) {
|
|
353
|
+
n.start > e && r.push({
|
|
354
354
|
kind: "string",
|
|
355
355
|
range: {
|
|
356
356
|
start: g.offsets[e],
|
|
357
|
-
end: g.offsets[
|
|
357
|
+
end: g.offsets[n.start]
|
|
358
358
|
}
|
|
359
|
-
}),
|
|
359
|
+
}), r.push({
|
|
360
360
|
kind: "expression",
|
|
361
361
|
range: {
|
|
362
|
-
start: g.offsets[
|
|
363
|
-
end: g.offsets[
|
|
362
|
+
start: g.offsets[n.start],
|
|
363
|
+
end: g.offsets[n.end]
|
|
364
364
|
}
|
|
365
365
|
});
|
|
366
|
-
for (let e of C(g.text,
|
|
366
|
+
for (let e of C(g.text, n.innerStart, n.innerEnd)) ((i !== "data-table" || t.name !== "column") && (t.name !== "data-table" || o.name !== "key") || e.name !== "item" && e.name !== "index") && s.push({
|
|
367
367
|
name: e.name,
|
|
368
368
|
range: {
|
|
369
369
|
start: g.offsets[e.range.start],
|
|
370
370
|
end: g.offsets[e.range.end]
|
|
371
371
|
}
|
|
372
372
|
});
|
|
373
|
-
e =
|
|
373
|
+
e = n.end;
|
|
374
374
|
}
|
|
375
|
-
e < g.text.length &&
|
|
375
|
+
e < g.text.length && r.push({
|
|
376
376
|
kind: "string",
|
|
377
377
|
range: {
|
|
378
378
|
start: g.offsets[e],
|
|
379
379
|
end: o.valueRange.end
|
|
380
380
|
}
|
|
381
381
|
});
|
|
382
|
-
} else (d || f) && m(p) ? (
|
|
382
|
+
} else (d || f) && m(p) ? (r.push({
|
|
383
383
|
kind: "binding",
|
|
384
384
|
range: h(o.valueRange)
|
|
385
|
-
}), u(p, o.valueRange)) : o.valueRange.end > o.valueRange.start &&
|
|
385
|
+
}), u(p, o.valueRange)) : o.valueRange.end > o.valueRange.start && r.push({
|
|
386
386
|
kind: "string",
|
|
387
387
|
range: h(o.valueRange)
|
|
388
388
|
});
|
|
389
389
|
}
|
|
390
390
|
let d = b(e, t, a.end);
|
|
391
|
-
d &&
|
|
391
|
+
d && r.push({
|
|
392
392
|
kind: "tag",
|
|
393
393
|
range: h(d.nameRange)
|
|
394
394
|
});
|
|
395
|
-
}, f = (
|
|
396
|
-
for (let a of
|
|
397
|
-
if ((a.type === "component" || a.type === "hostComponent") && a.name) d(a,
|
|
398
|
-
else if (a.type === "interpolation")
|
|
395
|
+
}, f = (t, n) => {
|
|
396
|
+
for (let a of t) {
|
|
397
|
+
if ((a.type === "component" || a.type === "hostComponent") && a.name) d(a, n);
|
|
398
|
+
else if (a.type === "interpolation") r.push({
|
|
399
399
|
kind: "expression",
|
|
400
400
|
range: h(a.range)
|
|
401
401
|
}), l(a.range.start + 2, Math.max(a.range.start + 2, a.range.end - 2));
|
|
402
402
|
else if (a.type === "math" || a.type === "inlineMath") {
|
|
403
|
-
if (
|
|
403
|
+
if (r.push({
|
|
404
404
|
kind: "math",
|
|
405
405
|
range: h(a.range)
|
|
406
|
-
}),
|
|
407
|
-
let
|
|
406
|
+
}), n === "plot" && a.type === "math") {
|
|
407
|
+
let t = a.range.start + 2;
|
|
408
408
|
try {
|
|
409
|
-
for (let
|
|
409
|
+
for (let n of i(e.slice(t, a.range.end - 2))) {
|
|
410
410
|
let e = {
|
|
411
|
-
name:
|
|
411
|
+
name: n.name,
|
|
412
412
|
range: {
|
|
413
|
-
start:
|
|
414
|
-
end:
|
|
413
|
+
start: t + n.range.start,
|
|
414
|
+
end: t + n.range.end
|
|
415
415
|
}
|
|
416
416
|
};
|
|
417
417
|
s.push(e), c.push(e);
|
|
418
418
|
}
|
|
419
419
|
} catch {}
|
|
420
420
|
}
|
|
421
|
-
} else a.type === "code" || a.type === "inlineCode" ?
|
|
421
|
+
} else a.type === "code" || a.type === "inlineCode" ? r.push({
|
|
422
422
|
kind: "code",
|
|
423
423
|
range: h(a.range)
|
|
424
|
-
}) : a.type === "comment" &&
|
|
424
|
+
}) : a.type === "comment" && r.push({
|
|
425
425
|
kind: "comment",
|
|
426
426
|
range: h(a.range)
|
|
427
427
|
});
|
|
428
428
|
a.type !== "fallback" && a.children && f(a.children, a.name);
|
|
429
429
|
}
|
|
430
430
|
};
|
|
431
|
-
f(
|
|
432
|
-
for (let
|
|
431
|
+
f(t);
|
|
432
|
+
for (let n of E(e, t)) r.push({
|
|
433
433
|
kind: "comment",
|
|
434
|
-
range:
|
|
434
|
+
range: n
|
|
435
435
|
});
|
|
436
|
-
|
|
436
|
+
r.sort((e, t) => e.range.start - t.range.start || e.range.end - t.range.end);
|
|
437
437
|
let p = [];
|
|
438
|
-
for (let e of
|
|
438
|
+
for (let e of r) {
|
|
439
439
|
if (e.range.end <= e.range.start) continue;
|
|
440
440
|
let t = p[p.length - 1];
|
|
441
441
|
t && e.range.start < t.range.end || p.push(e);
|