reactive-md 0.3.1 → 0.4.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 +113 -0
- package/CHANGELOG.md +113 -53
- package/CONTRIBUTING-ch.md +62 -0
- package/CONTRIBUTING.md +64 -65
- package/LICENSE +21 -21
- package/README-ch.md +123 -0
- package/README-en.md +147 -0
- package/README.md +96 -38
- package/SECURITY-ch.md +80 -0
- package/SECURITY.md +58 -49
- package/THIRD_PARTY_NOTICES.md +85 -1
- package/bin/reactive-md.mjs +40 -0
- package/cli/args.mjs +181 -0
- package/cli/assets.mjs +390 -0
- package/cli/build.mjs +268 -0
- package/cli/document.mjs +130 -0
- package/cli/errors.mjs +61 -0
- package/cli/fs-utils.mjs +133 -0
- package/cli/glob.mjs +203 -0
- package/cli/help.mjs +138 -0
- package/cli/lint.mjs +177 -0
- package/cli/main.mjs +55 -0
- package/cli/migrate.mjs +368 -0
- package/cli/package.mjs +209 -0
- package/dist-library/reactive-md-react.js +3525 -1651
- package/dist-library/reactive-md.css +1 -1
- package/dist-library/reactive-md.js +1798 -4
- package/dist-library/runtime-D3QTVYaz.js +15410 -0
- package/dist-library/types/index.d.ts +1 -0
- package/dist-library/types/local/LocalDocumentView.d.ts +66 -3
- package/dist-library/types/local/authoring.d.ts +63 -0
- package/dist-library/types/local/collection-functions.d.ts +4 -0
- package/dist-library/types/local/colors.d.ts +2 -0
- package/dist-library/types/local/computations.d.ts +53 -0
- package/dist-library/types/local/data-functions.d.ts +22 -0
- package/dist-library/types/local/data-table.d.ts +65 -0
- package/dist-library/types/local/dates.d.ts +2 -0
- package/dist-library/types/local/dependencies.d.ts +31 -0
- package/dist-library/types/local/diagnostics.d.ts +1450 -0
- package/dist-library/types/local/expression.d.ts +13 -3
- package/dist-library/types/local/formatting.d.ts +41 -0
- package/dist-library/types/local/heading-anchors.d.ts +13 -2
- package/dist-library/types/local/i18n.d.ts +18 -0
- package/dist-library/types/local/index.d.ts +18 -1
- package/dist-library/types/local/limits.d.ts +32 -1
- package/dist-library/types/local/locale.d.ts +1 -0
- package/dist-library/types/local/math.d.ts +6 -1
- package/dist-library/types/local/parser.d.ts +10 -4
- package/dist-library/types/local/render-types.d.ts +5 -1
- package/dist-library/types/local/retention.d.ts +23 -0
- package/dist-library/types/local/schema.d.ts +25 -3
- package/dist-library/types/local/source-migration.d.ts +35 -0
- package/dist-library/types/local/state.d.ts +80 -0
- package/dist-library/types/local/text-length.d.ts +13 -0
- package/dist-library/types/local/theme.d.ts +30 -0
- package/dist-library/types/local/types.d.ts +112 -4
- package/dist-library/types/local/validation.d.ts +32 -0
- package/dist-library/types/local/version.d.ts +1 -1
- package/dist-library/types/local/worker.d.ts +82 -0
- package/dist-library/types/react/index.d.ts +4 -1
- package/dist-library/types/shareable.d.ts +64 -0
- package/dist-standalone/reactive-md-standalone.css +2 -0
- package/dist-standalone/reactive-md-standalone.js +57 -0
- package/docs/author-tools-ch.md +56 -0
- package/docs/author-tools-en.md +56 -0
- package/docs/compatibility-ch.md +103 -0
- package/docs/compatibility-en.md +103 -0
- package/docs/{component-development.md → component-development-ch.md} +210 -206
- package/docs/component-development-en.md +210 -0
- package/docs/{component-protocol.md → component-protocol-ch.md} +710 -685
- package/docs/component-protocol-en.md +710 -0
- package/docs/computations-formatting-ch.md +87 -0
- package/docs/computations-formatting-en.md +87 -0
- package/docs/constraints-collections-ch.md +84 -0
- package/docs/constraints-collections-en.md +84 -0
- package/docs/diagnostics-counting-ch.md +84 -0
- package/docs/diagnostics-counting-en.md +84 -0
- package/docs/local-components-v2-ch.md +138 -0
- package/docs/local-components-v2-en.md +104 -0
- package/docs/{local-guide.md → local-guide-ch.md} +28 -8
- package/docs/local-guide-en.md +961 -0
- package/docs/local-integration-ch.md +363 -0
- package/docs/local-integration-en.md +363 -0
- package/docs/{local-interaction-syntax.md → local-interaction-syntax-ch.md} +66 -20
- package/docs/local-interaction-syntax-en.md +483 -0
- package/docs/{performance.md → performance-ch.md} +12 -3
- package/docs/performance-en.md +76 -0
- package/docs/release-0.4.0-ch.md +89 -0
- package/docs/release-0.4.0-en.md +89 -0
- package/docs/release-0.4.1-ch.md +23 -0
- package/docs/release-0.4.1-en.md +23 -0
- package/docs/releasing-ch.md +101 -0
- package/docs/releasing-en.md +101 -0
- package/docs/shareable-export-ch.md +205 -0
- package/docs/shareable-export-en.md +207 -0
- package/docs/source-versioning-ch.md +159 -0
- package/docs/source-versioning-en.md +159 -0
- package/docs/theme-protocol-ch.md +107 -0
- package/docs/theme-protocol-en.md +107 -0
- package/examples/conformance/README.md +33 -31
- package/examples/conformance/component-protocol-1.json +482 -194
- package/examples/conformance/component-protocol-1.schema.json +76 -76
- package/examples/conformance/history/v0.3.1/catalog.reactive.md +20 -0
- package/examples/conformance/history/v0.3.1/charts.reactive.md +73 -0
- package/examples/conformance/history/v0.3.1/checklist.reactive.md +32 -0
- package/examples/conformance/history/v0.3.1/comparison.reactive.md +47 -0
- package/examples/conformance/history/v0.3.1/components.reactive.md +44 -0
- package/examples/conformance/history/v0.3.1/counter.reactive.md +7 -0
- package/examples/conformance/history/v0.3.1/diagnostics.reactive.md +54 -0
- package/examples/conformance/history/v0.3.1/diagram.reactive.md +44 -0
- package/examples/conformance/history/v0.3.1/gallery.reactive.md +61 -0
- package/examples/conformance/history/v0.3.1/local-draft-1.json +50 -0
- package/examples/conformance/history/v0.3.1/parameters.reactive.md +36 -0
- package/examples/conformance/history/v0.3.1/planning.reactive.md +24 -0
- package/examples/conformance/history/v0.3.1/pricing.reactive.md +20 -0
- package/examples/conformance/history/v0.3.1/provenance.json +72 -0
- package/examples/conformance/local-draft-2.json +212 -0
- package/examples/integration/README.md +45 -29
- package/examples/integration/core/index.mjs +32 -19
- package/examples/integration/core/package.json +7 -7
- package/examples/integration/react/index.html +12 -12
- package/examples/integration/react/main.jsx +21 -21
- package/examples/integration/react/package.json +9 -9
- package/examples/integration/worker/index.html +19 -0
- package/examples/integration/worker/main.js +61 -0
- package/examples/integration/worker/package.json +13 -0
- package/examples/integration/worker/worker.js +3 -0
- package/examples/local/README.md +64 -58
- package/examples/local/catalog.reactive.md +20 -20
- package/examples/local/charts.reactive.md +34 -34
- package/examples/local/checklist.reactive.md +32 -32
- package/examples/local/comparison.reactive.md +47 -47
- package/examples/local/components.reactive.md +44 -44
- package/examples/local/counter.reactive.md +7 -7
- package/examples/local/diagnostics.reactive.md +54 -54
- package/examples/local/diagram.reactive.md +44 -44
- package/examples/local/gallery.reactive.md +61 -61
- package/examples/local/parameters.reactive.md +36 -36
- package/examples/local/planning.reactive.md +24 -24
- package/examples/local/pricing.reactive.md +20 -20
- package/examples/local/recipes/invoice-zh.reactive.md +36 -0
- package/examples/local/recipes/invoice.reactive.md +36 -0
- package/examples/local/recipes/workshop-zh.reactive.md +33 -0
- package/examples/local/recipes/workshop.reactive.md +33 -0
- package/examples/local/showcase/README.md +25 -0
- package/examples/local/showcase/explore.reactive.md +102 -0
- package/examples/local/showcase/flow.reactive.md +86 -0
- package/examples/local/showcase/forms.reactive.md +126 -0
- package/examples/local/showcase/functions.reactive.md +119 -0
- package/examples/local/showcase/layout.reactive.md +100 -0
- package/examples/local/showcase/statistics.reactive.md +108 -0
- package/examples/local/showcase/tasks.reactive.md +89 -0
- package/examples/local/showcase/zh/explore.reactive.md +102 -0
- package/examples/local/showcase/zh/flow.reactive.md +86 -0
- package/examples/local/showcase/zh/forms.reactive.md +126 -0
- package/examples/local/showcase/zh/functions.reactive.md +119 -0
- package/examples/local/showcase/zh/layout.reactive.md +100 -0
- package/examples/local/showcase/zh/statistics.reactive.md +108 -0
- package/examples/local/showcase/zh/tasks.reactive.md +89 -0
- package/examples/local/zh/catalog.reactive.md +20 -0
- package/examples/local/zh/charts.reactive.md +73 -0
- package/examples/local/zh/checklist.reactive.md +32 -0
- package/examples/local/zh/comparison.reactive.md +47 -0
- package/examples/local/zh/components.reactive.md +44 -0
- package/examples/local/zh/counter.reactive.md +7 -0
- package/examples/local/zh/diagnostics.reactive.md +54 -0
- package/examples/local/zh/diagram.reactive.md +44 -0
- package/examples/local/zh/gallery.reactive.md +61 -0
- package/examples/local/zh/parameters.reactive.md +36 -0
- package/examples/local/zh/planning.reactive.md +24 -0
- package/examples/local/zh/pricing.reactive.md +20 -0
- package/package.json +91 -77
- package/README.en.md +0 -76
- package/dist-library/runtime-CPzMEMcW.js +0 -11111
- package/docs/compatibility.md +0 -68
- package/docs/local-integration.md +0 -218
- package/docs/releasing.md +0 -92
package/SECURITY.md
CHANGED
|
@@ -1,71 +1,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Security policy
|
|
2
2
|
|
|
3
|
-
Reactive MD
|
|
3
|
+
Reactive MD renders local interactive documents written by authors. When document content is untrusted input, the renderer, expressions and math evaluation all stay within the boundaries below. The host remains responsible for authorization, network policy and server-side data.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Supported versions
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Current maintenance covers the latest 0.x preview. Security fixes may ship in minor releases and are described in the [changelog](CHANGELOG.md) with impact and migration steps.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Threat boundary
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
The guarantees below are covered by compiler, runtime and renderer tests; capabilities not listed here are not promised.
|
|
12
12
|
|
|
13
|
-
###
|
|
13
|
+
### Document content
|
|
14
14
|
|
|
15
|
-
-
|
|
16
|
-
- React
|
|
17
|
-
-
|
|
18
|
-
- LaTeX
|
|
19
|
-
-
|
|
15
|
+
- Authors cannot execute scripts. `<script>`, raw HTML, `on-*` event attributes and author CSS are not part of `local-draft-2`; they are treated as syntax diagnostics or text, never executed as HTML.
|
|
16
|
+
- The React renderer does not call `dangerouslySetInnerHTML` and does not write document content into `innerHTML`.
|
|
17
|
+
- Expressions use their own parser and AST evaluator, with no `eval` or `new Function`, and no support for assignment, method calls, property access, prototype paths or imports. Expressions can only read parameters declared by the document and built-in functions.
|
|
18
|
+
- LaTeX is evaluated by a budget-limited parser and rendered as native MathML; the renderer does not execute macros, files, network or HTML entry points. Unknown commands are displayed as text.
|
|
19
|
+
- Expressions, templates, tables and charts do not make network requests; chart data must be written in the document.
|
|
20
20
|
|
|
21
|
-
###
|
|
21
|
+
### URLs and networking
|
|
22
22
|
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
- `
|
|
23
|
+
- All images are rejected by default, including relative paths and protocol-relative addresses, so loading the document itself triggers no image requests.
|
|
24
|
+
- Images load only when the host passes `urlPolicy` and the policy returns `true`. Images with a protocol still have that protocol checked first: only `http:` and `https:` are allowed. Relative addresses are decided by the policy. Addresses such as `javascript:` or dangerous `data:` URLs are rejected even if the policy allows them.
|
|
25
|
+
- Links allow relative addresses and `http:`, `https:`, `mailto:` and `tel:` by default; external HTTP links open in a new tab with `noopener noreferrer`. Dangerous protocols are always rejected.
|
|
26
|
+
- If the policy throws, the address is rejected. Images that are allowed to load use `referrerPolicy="no-referrer"`; same-origin images may still carry cookies, so image allowlists should avoid business APIs.
|
|
27
|
+
- A trusted `imageResolver` runs only after the image URL passes protocol checks and `urlPolicy`. It maps an accepted URL to host-controlled output; exported files use only verified `data:image/png|jpeg|gif|webp;base64` values, and links never reach it.
|
|
28
|
+
- `urlPolicy` is a URL allowlist, not server-side authorization. The host still needs to configure CSP, network egress, an image proxy or a sandboxed iframe (when authors are fully untrusted).
|
|
28
29
|
|
|
29
|
-
###
|
|
30
|
+
### Resource limits
|
|
30
31
|
|
|
31
|
-
`src/local/limits.ts`
|
|
32
|
+
`src/local/limits.ts` defines shared limits used by compilation, the runtime and visualizations:
|
|
32
33
|
|
|
33
|
-
|
|
|
34
|
+
| Limit | Value |
|
|
34
35
|
| --- | --- |
|
|
35
|
-
|
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
36
|
+
| Source per document | 1,000,000 characters |
|
|
37
|
+
| Syntax nodes created cumulatively during parsing | 10,000 by default, configured per call by the host |
|
|
38
|
+
| A single string value or template | 100,000 characters |
|
|
39
|
+
| A single array | 10,000 items |
|
|
40
|
+
| Total string length within an array | 100,000 characters |
|
|
41
|
+
| Email address | 254 characters, validated in linear time |
|
|
42
|
+
| Number of diagnostics | 100 |
|
|
43
|
+
| Text of a single diagnostic | 2,000 characters |
|
|
44
|
+
| Curves per plot component | 16 |
|
|
45
|
+
| Curve sample points requested by the whole document | 20,000 |
|
|
46
|
+
| Shared computation steps for plotting | 2,000,000 |
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
Writes over a limit are rejected and the runtime keeps the last valid state; compile-time overruns return diagnostics. Plotting and math evaluation also have their own depth, token and node budgets. Budgets bound the work for a single document; they do not replace host control over request size, concurrency and timeouts.
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
Hosts can adjust the syntax node budget for a single compilation with `compileLocal(source, { limits: { maxSyntaxNodes } })`; the value must be a positive safe integer. Document content cannot change this setting. When omitted, the default budget of 10,000 applies; raising the node budget does not change the source length, array, expression or plotting limits. The count covers every `LocalNode` created during parsing, including intermediate nodes that are not kept in the final tree.
|
|
50
51
|
|
|
51
|
-
###
|
|
52
|
+
### State and isolation
|
|
52
53
|
|
|
53
|
-
-
|
|
54
|
-
- `createLocalRuntime`
|
|
55
|
-
- `snapshot()`
|
|
56
|
-
- `disabled`
|
|
54
|
+
- Parameter state exists only in the memory of the current document instance. Each `LocalReactiveDocument` or `LocalDocumentView` instance is independent; disposal clears subscriptions, expression caches and timers.
|
|
55
|
+
- `createLocalRuntime` validates initial values and constraints on shared controls; `set` relies on the controls registered in the document, ignores forged node metadata from the caller, and commits atomically only when every shared control accepts the write.
|
|
56
|
+
- `snapshot()` returns a stable frozen snapshot, including frozen arrays; `get()` and `evaluate()` return array copies. State updates are committed through validated `set()` calls.
|
|
57
|
+
- `disabled` and `if` are display states only, not permission control. Business permissions and value validation must be enforced by the host when submitting to the server.
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
### Shareable HTML export
|
|
59
60
|
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
- 第三方依赖漏洞应同时报告给上游项目;本包只负责自身集成代码。
|
|
61
|
+
- `reactive-md-state/v1` stores only public binding names and serializable values. It excludes `@` internal bindings, revisions, node IDs, AST data, UI state and timers. Source digest, syntax, parameter set and every value are validated before import; unknown or conflicting keys reject the whole file.
|
|
62
|
+
- Interactive HTML embeds a fixed standalone runtime and a CSP with no network connections, frames, objects, base injection or form submission. Only inline styles/runtime and `data:` images are allowed. JSON, source, titles and notices are escaped for their HTML/script context.
|
|
63
|
+
- The CLI inlines only relative raster files that resolve inside the document directory or an explicit asset root. It rejects remote images, URL schemes, absolute paths, traversal, symlink escapes, SVG, forged formats and oversized assets. The demo export dialog disables HTML export when images are present.
|
|
64
|
+
- Static HTML contains no runtime script or auto-mount payload. Static-first hydration is covered only in the single-file Chromium/Edge path; it is not a general hydration or sandboxing guarantee. Use a sandboxed iframe for fully untrusted authors.
|
|
65
|
+
- Exporting current parameters is an explicit host/reader action. Treat the generated state file and HTML as potentially sensitive; choose initial values unless current values are intentionally meant to be shared.
|
|
66
66
|
|
|
67
|
-
##
|
|
67
|
+
## Host responsibilities
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
- Decide who may write, submit and share documents; limit request size, concurrency and execution time for untrusted authors. Compiling a 1,000,000-character document is still real CPU work.
|
|
70
|
+
- Configure `urlPolicy` for images and links; maintain CSP, network egress control and image allowlists.
|
|
71
|
+
- Revalidate form values, permissions and business constraints on the server; do not trust `disabled`, conditional visibility or client state inside the document.
|
|
72
|
+
- When persistence is needed, store the original `.reactive.md` source securely; runtime state and `LocalDocument` should not be treated as a persistence format.
|
|
73
|
+
- Before statically rendering untrusted documents on the server, assess the resource limits of the rendering process. General SSR hydration remains unverified; only the single-file static-first path has Chromium/Edge coverage. Hydration is not a security boundary.
|
|
74
|
+
- Report vulnerabilities in third-party dependencies upstream as well; this package is responsible only for its own integration code.
|
|
70
75
|
|
|
71
|
-
|
|
76
|
+
## Reporting vulnerabilities
|
|
77
|
+
|
|
78
|
+
The repository has GitHub private vulnerability reporting enabled. Submit affected versions, a minimal reproduction, expected impact and remediation suggestions through [Report a vulnerability](https://github.com/yao1145/ReactiveMD/security/advisories/new).
|
|
79
|
+
|
|
80
|
+
Use the private channel to report vulnerability details; remove exploit code, credentials, user data and information about affected deployments from public issues and PRs.
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Third-party notices
|
|
2
2
|
|
|
3
|
-
Reactive MD bundles its Markdown dependencies. This file preserves license texts for
|
|
3
|
+
Reactive MD bundles its Markdown dependencies. The standalone HTML runtime also bundles React, React DOM and scheduler. This file preserves license texts for those installed dependency trees, including supporting type packages. The library React entry uses host-provided React and React DOM peers.
|
|
4
4
|
|
|
5
5
|
Regenerate after dependency updates with `node scripts/generate-notices.mjs`.
|
|
6
6
|
|
|
@@ -1623,6 +1623,62 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
1623
1623
|
SOFTWARE.
|
|
1624
1624
|
```
|
|
1625
1625
|
|
|
1626
|
+
## react-dom@19.3.1
|
|
1627
|
+
|
|
1628
|
+
Declared license: MIT
|
|
1629
|
+
|
|
1630
|
+
```text
|
|
1631
|
+
MIT License
|
|
1632
|
+
|
|
1633
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1634
|
+
|
|
1635
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
1636
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
1637
|
+
in the Software without restriction, including without limitation the rights
|
|
1638
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
1639
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
1640
|
+
furnished to do so, subject to the following conditions:
|
|
1641
|
+
|
|
1642
|
+
The above copyright notice and this permission notice shall be included in all
|
|
1643
|
+
copies or substantial portions of the Software.
|
|
1644
|
+
|
|
1645
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
1646
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
1647
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
1648
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
1649
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
1650
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1651
|
+
SOFTWARE.
|
|
1652
|
+
```
|
|
1653
|
+
|
|
1654
|
+
## react@19.3.1
|
|
1655
|
+
|
|
1656
|
+
Declared license: MIT
|
|
1657
|
+
|
|
1658
|
+
```text
|
|
1659
|
+
MIT License
|
|
1660
|
+
|
|
1661
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1662
|
+
|
|
1663
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
1664
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
1665
|
+
in the Software without restriction, including without limitation the rights
|
|
1666
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
1667
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
1668
|
+
furnished to do so, subject to the following conditions:
|
|
1669
|
+
|
|
1670
|
+
The above copyright notice and this permission notice shall be included in all
|
|
1671
|
+
copies or substantial portions of the Software.
|
|
1672
|
+
|
|
1673
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
1674
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
1675
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
1676
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
1677
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
1678
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1679
|
+
SOFTWARE.
|
|
1680
|
+
```
|
|
1681
|
+
|
|
1626
1682
|
## remark-gfm@4.0.1
|
|
1627
1683
|
|
|
1628
1684
|
Declared license: MIT
|
|
@@ -1708,6 +1764,34 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
1708
1764
|
THE SOFTWARE.
|
|
1709
1765
|
```
|
|
1710
1766
|
|
|
1767
|
+
## scheduler@0.28.0
|
|
1768
|
+
|
|
1769
|
+
Declared license: MIT
|
|
1770
|
+
|
|
1771
|
+
```text
|
|
1772
|
+
MIT License
|
|
1773
|
+
|
|
1774
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1775
|
+
|
|
1776
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
1777
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
1778
|
+
in the Software without restriction, including without limitation the rights
|
|
1779
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
1780
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
1781
|
+
furnished to do so, subject to the following conditions:
|
|
1782
|
+
|
|
1783
|
+
The above copyright notice and this permission notice shall be included in all
|
|
1784
|
+
copies or substantial portions of the Software.
|
|
1785
|
+
|
|
1786
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
1787
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
1788
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
1789
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
1790
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
1791
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1792
|
+
SOFTWARE.
|
|
1793
|
+
```
|
|
1794
|
+
|
|
1711
1795
|
## trough@2.2.0
|
|
1712
1796
|
|
|
1713
1797
|
Declared license: MIT
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
* reactive-md command-line interface.
|
|
4
|
+
*
|
|
5
|
+
* Exit codes:
|
|
6
|
+
* 0 success
|
|
7
|
+
* 2 usage or argument error
|
|
8
|
+
* 3 document compile, render, React or build-artifact error
|
|
9
|
+
* 4 input or output file I/O error
|
|
10
|
+
* 5 asset or security policy error
|
|
11
|
+
*
|
|
12
|
+
* Build artifacts and the package metadata are located relative to this file's
|
|
13
|
+
* installed package root (bin/..), never the current working directory.
|
|
14
|
+
*/
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
import { CliError, EXIT } from '../cli/errors.mjs';
|
|
18
|
+
import { runCli } from '../cli/main.mjs';
|
|
19
|
+
|
|
20
|
+
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
21
|
+
const context = {
|
|
22
|
+
packageRoot,
|
|
23
|
+
stdout: process.stdout,
|
|
24
|
+
stderr: process.stderr,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
process.exitCode = await runCli(process.argv.slice(2), context);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (error instanceof CliError) {
|
|
31
|
+
if (!error.reported) {
|
|
32
|
+
context.stderr.write(`reactive-md: ${error.message}\n`);
|
|
33
|
+
}
|
|
34
|
+
process.exitCode = error.exitCode;
|
|
35
|
+
} else {
|
|
36
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
37
|
+
context.stderr.write(`reactive-md: unexpected error: ${message}\n`);
|
|
38
|
+
process.exitCode = EXIT.DOCUMENT;
|
|
39
|
+
}
|
|
40
|
+
}
|
package/cli/args.mjs
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { usageError } from './errors.mjs';
|
|
2
|
+
|
|
3
|
+
/** A local asset root may be a Windows drive path; it must never be a URL. */
|
|
4
|
+
function isUrlLike(value) {
|
|
5
|
+
const match = /^([a-z][a-z0-9+.-]*):/i.exec(value);
|
|
6
|
+
if (!match) return false;
|
|
7
|
+
// C:\docs and C:/docs are local drive paths, not URL schemes.
|
|
8
|
+
if (match[1].length === 1 && /^[a-z]:[\\/]/i.test(value)) return false;
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {string[]} argv
|
|
14
|
+
* @param {Map<string, {key: string, boolean?: boolean}>} spec
|
|
15
|
+
* @returns {{positionals: string[], options: Record<string, string | boolean>}}
|
|
16
|
+
*/
|
|
17
|
+
function parseOptions(argv, spec) {
|
|
18
|
+
const positionals = [];
|
|
19
|
+
const options = {};
|
|
20
|
+
let literal = false;
|
|
21
|
+
|
|
22
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
23
|
+
const token = argv[index];
|
|
24
|
+
if (literal) {
|
|
25
|
+
positionals.push(token);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (token === '--') {
|
|
29
|
+
literal = true;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (token === '-' || !token.startsWith('-')) {
|
|
33
|
+
positionals.push(token);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let name = token;
|
|
38
|
+
let inlineValue;
|
|
39
|
+
if (token.startsWith('--')) {
|
|
40
|
+
const equals = token.indexOf('=');
|
|
41
|
+
if (equals > 2) {
|
|
42
|
+
name = token.slice(0, equals);
|
|
43
|
+
inlineValue = token.slice(equals + 1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const entry = spec.get(name);
|
|
47
|
+
if (!entry) {
|
|
48
|
+
throw usageError(`Unknown option "${name}". Run "reactive-md build --help" or "reactive-md lint --help" for usage.`);
|
|
49
|
+
}
|
|
50
|
+
if (entry.boolean) {
|
|
51
|
+
if (inlineValue !== undefined) throw usageError(`Option "${name}" does not take a value.`);
|
|
52
|
+
options[entry.key] = true;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
let value = inlineValue;
|
|
56
|
+
if (value === undefined) {
|
|
57
|
+
if (index + 1 >= argv.length) throw usageError(`Option "${name}" requires a value.`);
|
|
58
|
+
value = argv[index + 1];
|
|
59
|
+
index += 1;
|
|
60
|
+
}
|
|
61
|
+
options[entry.key] = value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return { positionals, options };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @param {unknown} value */
|
|
68
|
+
function requireText(value, option) {
|
|
69
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
70
|
+
throw usageError(`Option "${option}" requires a non-empty value.`);
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** @param {unknown} value @param {string} option @param {readonly string[]} choices */
|
|
76
|
+
function choice(value, option, choices) {
|
|
77
|
+
const normalized = String(value).toLowerCase();
|
|
78
|
+
if (!choices.includes(normalized)) {
|
|
79
|
+
throw usageError(`Invalid value for "${option}": "${value}". Expected ${choices.join(' or ')}.`);
|
|
80
|
+
}
|
|
81
|
+
return normalized;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const BUILD_SPEC = new Map([
|
|
85
|
+
['-o', { key: 'output' }],
|
|
86
|
+
['--output', { key: 'output' }],
|
|
87
|
+
['--mode', { key: 'mode' }],
|
|
88
|
+
['--state-file', { key: 'stateFile' }],
|
|
89
|
+
['--assets', { key: 'assets' }],
|
|
90
|
+
['--asset-root', { key: 'assetRoot' }],
|
|
91
|
+
['--locale', { key: 'locale' }],
|
|
92
|
+
['--color-scheme', { key: 'colorScheme' }],
|
|
93
|
+
['--title', { key: 'title' }],
|
|
94
|
+
['--strict', { key: 'strict', boolean: true }],
|
|
95
|
+
['-h', { key: 'help', boolean: true }],
|
|
96
|
+
['--help', { key: 'help', boolean: true }],
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
const LINT_SPEC = new Map([
|
|
100
|
+
['--json', { key: 'json', boolean: true }],
|
|
101
|
+
['--strict', { key: 'strict', boolean: true }],
|
|
102
|
+
['-h', { key: 'help', boolean: true }],
|
|
103
|
+
['--help', { key: 'help', boolean: true }],
|
|
104
|
+
]);
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {string[]} argv
|
|
108
|
+
* @returns {{
|
|
109
|
+
* help: boolean, input?: string, output?: string, mode?: 'interactive'|'static',
|
|
110
|
+
* stateFile?: string, assets?: 'inline'|'omit', assetRoot?: string,
|
|
111
|
+
* locale?: 'en'|'zh', colorScheme?: 'auto'|'light'|'dark', title?: string,
|
|
112
|
+
* strict?: boolean
|
|
113
|
+
* }}
|
|
114
|
+
*/
|
|
115
|
+
export function parseBuildArgs(argv) {
|
|
116
|
+
const { positionals, options } = parseOptions(argv, BUILD_SPEC);
|
|
117
|
+
if (options.help) return { help: true };
|
|
118
|
+
|
|
119
|
+
if (positionals.length === 0) {
|
|
120
|
+
throw usageError('Missing input document. Usage: reactive-md build <doc.reactive.md> -o <doc.html>.');
|
|
121
|
+
}
|
|
122
|
+
if (positionals.length > 1) {
|
|
123
|
+
throw usageError(`Expected one input document, received ${positionals.length}: ${positionals.join(', ')}.`);
|
|
124
|
+
}
|
|
125
|
+
const input = requireText(positionals[0], 'input');
|
|
126
|
+
if (options.output === undefined) {
|
|
127
|
+
throw usageError('Missing required option "--output" (-o). Usage: reactive-md build <doc.reactive.md> -o <doc.html>.');
|
|
128
|
+
}
|
|
129
|
+
const output = requireText(options.output, '--output');
|
|
130
|
+
const mode = options.mode === undefined ? 'interactive' : choice(options.mode, '--mode', ['interactive', 'static']);
|
|
131
|
+
const assets = options.assets === undefined ? 'inline' : choice(options.assets, '--assets', ['inline', 'omit']);
|
|
132
|
+
const locale = options.locale === undefined ? 'en' : choice(options.locale, '--locale', ['en', 'zh']);
|
|
133
|
+
const colorScheme = options.colorScheme === undefined
|
|
134
|
+
? 'auto'
|
|
135
|
+
: choice(options.colorScheme, '--color-scheme', ['auto', 'light', 'dark']);
|
|
136
|
+
|
|
137
|
+
let stateFile;
|
|
138
|
+
if (options.stateFile !== undefined) stateFile = requireText(options.stateFile, '--state-file');
|
|
139
|
+
let assetRoot;
|
|
140
|
+
if (options.assetRoot !== undefined) {
|
|
141
|
+
assetRoot = requireText(options.assetRoot, '--asset-root');
|
|
142
|
+
if (isUrlLike(assetRoot)) {
|
|
143
|
+
throw usageError('Option "--asset-root" must be a local directory path; URLs are not supported.');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
help: false,
|
|
149
|
+
input,
|
|
150
|
+
output,
|
|
151
|
+
mode,
|
|
152
|
+
stateFile,
|
|
153
|
+
assets,
|
|
154
|
+
assetRoot,
|
|
155
|
+
locale,
|
|
156
|
+
colorScheme,
|
|
157
|
+
title: typeof options.title === 'string' ? options.title : undefined,
|
|
158
|
+
strict: options.strict === true,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @param {string[]} argv
|
|
164
|
+
* @returns {{help: boolean, inputs?: string[], json?: boolean, strict?: boolean}}
|
|
165
|
+
*/
|
|
166
|
+
export function parseLintArgs(argv) {
|
|
167
|
+
const { positionals, options } = parseOptions(argv, LINT_SPEC);
|
|
168
|
+
if (options.help) return { help: true };
|
|
169
|
+
if (positionals.length === 0) {
|
|
170
|
+
throw usageError('Missing lint inputs. Usage: reactive-md lint <files-or-dirs-or-globs...>.');
|
|
171
|
+
}
|
|
172
|
+
if (positionals.some((input) => input.trim() === '')) {
|
|
173
|
+
throw usageError('Lint input paths must not be empty.');
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
help: false,
|
|
177
|
+
inputs: positionals,
|
|
178
|
+
json: options.json === true,
|
|
179
|
+
strict: options.strict === true,
|
|
180
|
+
};
|
|
181
|
+
}
|