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.
Files changed (105) hide show
  1. package/CHANGELOG-ch.md +203 -194
  2. package/CHANGELOG.md +203 -194
  3. package/CONTRIBUTING-ch.md +67 -67
  4. package/CONTRIBUTING.md +69 -69
  5. package/README-ch.md +157 -157
  6. package/README-en.md +184 -184
  7. package/README.md +184 -184
  8. package/SECURITY-ch.md +81 -81
  9. package/SECURITY.md +81 -81
  10. package/THIRD_PARTY_NOTICES.md +313 -209
  11. package/bin/reactive-md.mjs +39 -39
  12. package/cli/args.mjs +181 -181
  13. package/cli/assets.mjs +390 -390
  14. package/cli/build.mjs +268 -268
  15. package/cli/document.mjs +130 -130
  16. package/cli/errors.mjs +61 -61
  17. package/cli/fs-utils.mjs +133 -133
  18. package/cli/glob.mjs +203 -203
  19. package/cli/help.mjs +138 -138
  20. package/cli/lint.mjs +177 -177
  21. package/cli/main.mjs +55 -55
  22. package/cli/migrate.mjs +368 -368
  23. package/cli/package.mjs +210 -210
  24. package/dist-library/{authoring-DSC0VsNK.js → authoring-BEVyth5X.js} +1 -1
  25. package/dist-library/compiler-Cm3ppMxG.js +46044 -0
  26. package/dist-library/{react-Dk94rcOp.js → react-Bh7_oxZp.js} +20110 -20113
  27. package/dist-library/reactive-md-authoring.js +2 -2
  28. package/dist-library/reactive-md-print.css +284 -284
  29. package/dist-library/reactive-md-react-unstyled.js +1 -1
  30. package/dist-library/reactive-md-react.js +1 -1
  31. package/dist-library/reactive-md.css +1 -1
  32. package/dist-library/reactive-md.js +3 -3
  33. package/dist-library/{runtime-D8KbnCd0.js → runtime-DlFYQ4s_.js} +1 -1
  34. package/dist-library/types/local/math-display.d.ts +22 -23
  35. package/dist-library/types/local/math-view.d.ts +6 -7
  36. package/dist-standalone/reactive-md-standalone.css +1 -1
  37. package/dist-standalone/reactive-md-standalone.js +318 -62
  38. package/docs/compatibility/compatibility-ch.md +121 -119
  39. package/docs/compatibility/compatibility-en.md +121 -119
  40. package/docs/compatibility/source-versioning-ch.md +159 -159
  41. package/docs/compatibility/source-versioning-en.md +159 -159
  42. package/docs/development/component-development-ch.md +210 -210
  43. package/docs/development/component-development-en.md +210 -210
  44. package/docs/development/component-protocol-ch.md +747 -747
  45. package/docs/development/component-protocol-en.md +747 -747
  46. package/docs/development/performance-ch.md +76 -76
  47. package/docs/development/performance-en.md +76 -76
  48. package/docs/development/releasing-ch.md +108 -108
  49. package/docs/development/releasing-en.md +108 -108
  50. package/docs/integration/author-tools-ch.md +62 -62
  51. package/docs/integration/author-tools-en.md +62 -62
  52. package/docs/integration/shareable-export-ch.md +209 -209
  53. package/docs/integration/shareable-export-en.md +211 -211
  54. package/docs/reference/computations-formatting-ch.md +87 -87
  55. package/docs/reference/computations-formatting-en.md +87 -87
  56. package/docs/reference/constraints-collections-ch.md +84 -84
  57. package/docs/reference/constraints-collections-en.md +84 -84
  58. package/docs/reference/diagnostics-counting-ch.md +104 -104
  59. package/docs/reference/diagnostics-counting-en.md +104 -104
  60. package/docs/reference/local-components-v2-ch.md +138 -138
  61. package/docs/reference/local-components-v2-en.md +104 -104
  62. package/docs/reference/local-interaction-syntax-ch.md +515 -511
  63. package/docs/reference/local-interaction-syntax-en.md +511 -507
  64. package/docs/reference/theme-protocol-ch.md +107 -107
  65. package/docs/reference/theme-protocol-en.md +107 -107
  66. package/docs/releases/release-0.4.0-ch.md +89 -89
  67. package/docs/releases/release-0.4.0-en.md +89 -89
  68. package/docs/releases/release-0.4.1-ch.md +23 -23
  69. package/docs/releases/release-0.4.1-en.md +23 -23
  70. package/docs/releases/release-0.6.1-ch.md +27 -0
  71. package/docs/releases/release-0.6.1-en.md +27 -0
  72. package/examples/conformance/README.md +53 -53
  73. package/examples/conformance/component-protocol-1.json +482 -482
  74. package/examples/conformance/component-protocol-1.schema.json +76 -76
  75. package/examples/conformance/local-draft-1.json +50 -50
  76. package/examples/conformance/local-draft-2.json +212 -212
  77. package/examples/integration/README.md +47 -47
  78. package/examples/integration/core/index.mjs +32 -32
  79. package/examples/integration/worker/index.html +19 -19
  80. package/examples/integration/worker/main.js +61 -61
  81. package/examples/integration/worker/package.json +13 -13
  82. package/examples/integration/worker/worker.js +3 -3
  83. package/examples/local/README.md +74 -74
  84. package/examples/local/charts.reactive.md +73 -73
  85. package/examples/local/recipes/invoice-zh.reactive.md +36 -36
  86. package/examples/local/recipes/invoice.reactive.md +36 -36
  87. package/examples/local/recipes/workshop-zh.reactive.md +33 -33
  88. package/examples/local/recipes/workshop.reactive.md +33 -33
  89. package/examples/local/showcase/README.md +25 -25
  90. package/examples/local/showcase/explore.reactive.md +102 -102
  91. package/examples/local/showcase/flow.reactive.md +86 -86
  92. package/examples/local/showcase/forms.reactive.md +126 -126
  93. package/examples/local/showcase/functions.reactive.md +119 -119
  94. package/examples/local/showcase/layout.reactive.md +100 -100
  95. package/examples/local/showcase/statistics.reactive.md +108 -108
  96. package/examples/local/showcase/tasks.reactive.md +89 -89
  97. package/examples/local/showcase/zh/explore.reactive.md +102 -102
  98. package/examples/local/showcase/zh/flow.reactive.md +86 -86
  99. package/examples/local/showcase/zh/forms.reactive.md +126 -126
  100. package/examples/local/showcase/zh/functions.reactive.md +119 -119
  101. package/examples/local/showcase/zh/layout.reactive.md +100 -100
  102. package/examples/local/showcase/zh/statistics.reactive.md +108 -108
  103. package/examples/local/showcase/zh/tasks.reactive.md +89 -89
  104. package/package.json +152 -152
  105. package/dist-library/compiler-CRD88BMt.js +0 -24964
@@ -1,107 +1,107 @@
1
- # Reactive MD 主题协议
2
-
3
- 协议修订:`reactive-md-theme-1`。本功能从 `0.4.0` 起提供,当前版本 `0.6.0` 同时提供于 `latest` 与 `next`;现有外观作为内置 `default` 保留。
4
-
5
- ## 文档选择主题
6
-
7
- 在正文之前写一行声明:
8
-
9
- ```markdown
10
- <theme name="default">
11
-
12
- # 文档标题
13
- ```
14
-
15
- 也接受 `<theme name="default" />`。省略声明时使用 `default`。声明前允许空白、BOM 和注释;声明只允许出现一次,不能嵌入组件。`name` 是静态字符串,使用小写 kebab-case,首字符为字母,最多 64 个字符。声明不接受表达式或其他属性。
16
-
17
- 声明是文档元数据,不属于组块,不生成可见组件。编译结果的 `document.theme` 保存选择,`document.themeRange` 保存声明在原文中的位置;正文节点继续使用原始源码位置。代码围栏、行内代码、注释和转义中的示例保持字面含义。
18
-
19
- 无效声明产生 `local.theme.*` 警告并使用 `default`。重复声明不改变第一次的选择;正文之后或组件内的声明不影响主题。正常正文和控件继续工作。
20
-
21
- ## 宿主登记主题
22
-
23
- 主题由开发者提供 CSS 和登记信息。宿主先导入公共样式,再导入主题 CSS,并通过 `themes` 提供允许选择的主题:
24
-
25
- ```tsx
26
- import { LOCAL_THEME_PROTOCOL, type LocalThemeDefinition } from 'reactive-md';
27
- import { LocalReactiveDocument } from 'reactive-md/react';
28
- import 'reactive-md/styles.css';
29
- import './paper-theme.css';
30
-
31
- const paperTheme = {
32
- name: 'paper',
33
- protocol: LOCAL_THEME_PROTOCOL,
34
- colorSchemes: ['light', 'dark'],
35
- } as const satisfies LocalThemeDefinition;
36
-
37
- export function Article({ source }: { source: string }) {
38
- return <LocalReactiveDocument source={source} themes={[paperTheme]} colorScheme="auto" />;
39
- }
40
- ```
41
-
42
- 此示例说明登记方式;仓库仅内置 `default`,不提供 `paper` 的设计或 CSS。
43
-
44
- | 字段 | 要求 |
45
- | --- | --- |
46
- | `name` | 符合文档名称规则;`default` 保留;同一宿主列表中唯一 |
47
- | `protocol` | 必须为 `reactive-md-theme-1`,可使用 `LOCAL_THEME_PROTOCOL` |
48
- | `colorSchemes` | 必须同时包含 `light` 和 `dark` |
49
-
50
- 宿主负责加载 CSS;登记信息不触发下载或注入样式。文档按名称选择宿主允许的主题,不接受 CSS、样式地址或脚本。主题 CSS 属于宿主信任的代码,宿主负责审查其作用域和资源引用。
51
-
52
- 未知主题、所选名称重复、所选登记信息无效、协议不兼容或缺少深浅模式时,渲染器警告并回退到 `default`。纯核心宿主可调用 `resolveLocalTheme(name, themes, range?, source?)`,得到 `{ name, diagnostics }`。编译器只处理声明,不查询宿主的主题列表。
53
-
54
- ## 深浅模式与实例作用域
55
-
56
- 两个 React 组件均接受 `themes` 和 `colorScheme`。主题名称决定风格,`colorScheme` 决定该风格的深浅版本:
57
-
58
- | 值 | 行为 |
59
- | --- | --- |
60
- | `light` | 当前文档使用浅色,包括处于深色宿主中时 |
61
- | `dark` | 当前文档使用深色 |
62
- | `auto`(默认) | 读取最近祖先的显式模式,否则跟随系统偏好;服务端输出以浅色开始 |
63
-
64
- 祖先的显式模式支持 `data-color-scheme="light|dark"` 和已有的 `data-theme="light|dark"`。浏览器中祖先属性或系统偏好变化会更新文档。显式 `colorScheme` 优先。
65
-
66
- 渲染器在当前文档根节点输出:
67
-
68
- ```html
69
- <article class="md-document local-document"
70
- data-rmd-theme="paper"
71
- data-color-scheme="dark">
72
- ```
73
-
74
- 每个实例独立选择主题与模式。主题 CSS 的每条规则必须限制在该主题根节点及其后代,例如 `[data-rmd-theme="paper"][data-color-scheme="dark"]`。不得使用会影响宿主的全局 `body`、`:root` 或无作用域的元素规则。
75
-
76
- 改变 `themes` 或 `colorScheme` 不创建新运行时。`LocalReactiveDocument` 更换 `source` 时仍遵从既有规则,重新编译并创建运行时;宿主需要保留参数时可自行管理 `LocalDocumentView` 的文档和运行时。
77
-
78
- ## 共享样式变量
79
-
80
- 公共组件 CSS 提供结构、交互与默认样式。自定义主题继承完整的默认变量,按需覆盖;浅色和深色规则必须分别设计与验收。
81
-
82
- | 用途 | 公共变量 |
83
- | --- | --- |
84
- | 背景 | `--paper`、`--surface`、`--document-bg`(默认跟随 `--surface`)、`--surface-subtle`、`--surface-hover`、`--surface-active` |
85
- | 文字与边框 | `--ink`、`--ink-soft`、`--ink-muted`、`--line`、`--line-strong` |
86
- | 强调色 | `--accent`、`--accent-hover`、`--accent-soft`、`--accent-line` |
87
- | 状态 | `--info`、`--info-soft`、`--success`、`--success-soft`、`--success-line`、`--warning`、`--warning-soft`、`--warning-line`、`--danger`、`--danger-soft`、`--danger-line`、`--neutral-soft` |
88
- | 焦点 | `--focus`、`--focus-outline`、`--focus-ring` |
89
- | 数据与代码 | `--chart-1` 至 `--chart-8`、`--chart-grid`、`--chart-axis`、`--code-bg`、`--code-bg-deep`、`--code-ink` |
90
- | 字体 | `--font-sans`、`--font-mono`、`--text-xs` 至 `--text-xl`、`--text-2xl`、`--text-block-title`、`--text-block-subtitle` |
91
- | 行高与字重 | `--leading-tight`、`--leading-snug`、`--leading-normal`、`--leading-relaxed`、`--weight-regular`、`--weight-medium`、`--weight-semibold`、`--weight-bold` |
92
- | 间距 | `--space-1` 至 `--space-7`、`--field-gap` |
93
- | 圆角 | `--radius-control`、`--radius-card`、`--radius-panel`、`--radius-pill` |
94
- | 控件 | `--control-height-sm`、`--control-height`、`--control-height-lg`、`--control-padding-x`、`--control-padding-y`、`--disabled-opacity` |
95
- | 动效与阴影 | `--motion-fast`、`--motion-base`、`--motion-slow`、`--ease-standard`、`--shadow-sm`、`--shadow-md` |
96
-
97
- 已有 `--blue`、`--blue-deep`、`--blue-soft`、`--blue-line` 保留兼容;新主题优先使用强调色变量。组件的局部 `color` 属性覆盖对应局部颜色,其余样式继续使用主题。数据序列、状态提示等保留各自的语义颜色。
98
-
99
- ## 组件 CSS 与验收
100
-
101
- 主题可在共享变量之外覆盖现有 `.md-*`、`.local-*` 组件类。文档根类、组件外层类和语义状态属性是主题的样式接口;内部节点的排列不是扩展 API。主题规则遵守文档作用域,并在公共样式之后加载。使用足够明确的根节点与组件选择器覆盖基础规则,避免依赖 `!important`。
102
-
103
- 主题覆盖范围包括 Markdown 正文、表格、公式、输入控件、容器、反馈、图表与图解。新增组件必须读取共享变量并在 `default` 下可用;自定义主题未添加专门规则时继承公共样式。
104
-
105
- 符合本协议的主题必须在两种模式下检查全部组件,以及 hover、focus、active、disabled、错误与选中状态。保持键盘焦点可见、文字和控件可读、375px 布局可用,并遵守减少动态效果的系统偏好。改变字号或字体后应检查 SVG 图解的标签、节点和边界。
106
-
107
- 登记校验确认协议与模式声明;CSS 的实际覆盖、对比度和布局通过浏览器验收。验收应包含同页多主题隔离、显式浅色置于深色宿主、系统切换、状态保留和卸载清理。
1
+ # Reactive MD 主题协议
2
+
3
+ 协议修订:`reactive-md-theme-1`。本功能从 `0.4.0` 起提供,当前版本 `0.6.0` 同时提供于 `latest` 与 `next`;现有外观作为内置 `default` 保留。
4
+
5
+ ## 文档选择主题
6
+
7
+ 在正文之前写一行声明:
8
+
9
+ ```markdown
10
+ <theme name="default">
11
+
12
+ # 文档标题
13
+ ```
14
+
15
+ 也接受 `<theme name="default" />`。省略声明时使用 `default`。声明前允许空白、BOM 和注释;声明只允许出现一次,不能嵌入组件。`name` 是静态字符串,使用小写 kebab-case,首字符为字母,最多 64 个字符。声明不接受表达式或其他属性。
16
+
17
+ 声明是文档元数据,不属于组块,不生成可见组件。编译结果的 `document.theme` 保存选择,`document.themeRange` 保存声明在原文中的位置;正文节点继续使用原始源码位置。代码围栏、行内代码、注释和转义中的示例保持字面含义。
18
+
19
+ 无效声明产生 `local.theme.*` 警告并使用 `default`。重复声明不改变第一次的选择;正文之后或组件内的声明不影响主题。正常正文和控件继续工作。
20
+
21
+ ## 宿主登记主题
22
+
23
+ 主题由开发者提供 CSS 和登记信息。宿主先导入公共样式,再导入主题 CSS,并通过 `themes` 提供允许选择的主题:
24
+
25
+ ```tsx
26
+ import { LOCAL_THEME_PROTOCOL, type LocalThemeDefinition } from 'reactive-md';
27
+ import { LocalReactiveDocument } from 'reactive-md/react';
28
+ import 'reactive-md/styles.css';
29
+ import './paper-theme.css';
30
+
31
+ const paperTheme = {
32
+ name: 'paper',
33
+ protocol: LOCAL_THEME_PROTOCOL,
34
+ colorSchemes: ['light', 'dark'],
35
+ } as const satisfies LocalThemeDefinition;
36
+
37
+ export function Article({ source }: { source: string }) {
38
+ return <LocalReactiveDocument source={source} themes={[paperTheme]} colorScheme="auto" />;
39
+ }
40
+ ```
41
+
42
+ 此示例说明登记方式;仓库仅内置 `default`,不提供 `paper` 的设计或 CSS。
43
+
44
+ | 字段 | 要求 |
45
+ | --- | --- |
46
+ | `name` | 符合文档名称规则;`default` 保留;同一宿主列表中唯一 |
47
+ | `protocol` | 必须为 `reactive-md-theme-1`,可使用 `LOCAL_THEME_PROTOCOL` |
48
+ | `colorSchemes` | 必须同时包含 `light` 和 `dark` |
49
+
50
+ 宿主负责加载 CSS;登记信息不触发下载或注入样式。文档按名称选择宿主允许的主题,不接受 CSS、样式地址或脚本。主题 CSS 属于宿主信任的代码,宿主负责审查其作用域和资源引用。
51
+
52
+ 未知主题、所选名称重复、所选登记信息无效、协议不兼容或缺少深浅模式时,渲染器警告并回退到 `default`。纯核心宿主可调用 `resolveLocalTheme(name, themes, range?, source?)`,得到 `{ name, diagnostics }`。编译器只处理声明,不查询宿主的主题列表。
53
+
54
+ ## 深浅模式与实例作用域
55
+
56
+ 两个 React 组件均接受 `themes` 和 `colorScheme`。主题名称决定风格,`colorScheme` 决定该风格的深浅版本:
57
+
58
+ | 值 | 行为 |
59
+ | --- | --- |
60
+ | `light` | 当前文档使用浅色,包括处于深色宿主中时 |
61
+ | `dark` | 当前文档使用深色 |
62
+ | `auto`(默认) | 读取最近祖先的显式模式,否则跟随系统偏好;服务端输出以浅色开始 |
63
+
64
+ 祖先的显式模式支持 `data-color-scheme="light|dark"` 和已有的 `data-theme="light|dark"`。浏览器中祖先属性或系统偏好变化会更新文档。显式 `colorScheme` 优先。
65
+
66
+ 渲染器在当前文档根节点输出:
67
+
68
+ ```html
69
+ <article class="md-document local-document"
70
+ data-rmd-theme="paper"
71
+ data-color-scheme="dark">
72
+ ```
73
+
74
+ 每个实例独立选择主题与模式。主题 CSS 的每条规则必须限制在该主题根节点及其后代,例如 `[data-rmd-theme="paper"][data-color-scheme="dark"]`。不得使用会影响宿主的全局 `body`、`:root` 或无作用域的元素规则。
75
+
76
+ 改变 `themes` 或 `colorScheme` 不创建新运行时。`LocalReactiveDocument` 更换 `source` 时仍遵从既有规则,重新编译并创建运行时;宿主需要保留参数时可自行管理 `LocalDocumentView` 的文档和运行时。
77
+
78
+ ## 共享样式变量
79
+
80
+ 公共组件 CSS 提供结构、交互与默认样式。自定义主题继承完整的默认变量,按需覆盖;浅色和深色规则必须分别设计与验收。
81
+
82
+ | 用途 | 公共变量 |
83
+ | --- | --- |
84
+ | 背景 | `--paper`、`--surface`、`--document-bg`(默认跟随 `--surface`)、`--surface-subtle`、`--surface-hover`、`--surface-active` |
85
+ | 文字与边框 | `--ink`、`--ink-soft`、`--ink-muted`、`--line`、`--line-strong` |
86
+ | 强调色 | `--accent`、`--accent-hover`、`--accent-soft`、`--accent-line` |
87
+ | 状态 | `--info`、`--info-soft`、`--success`、`--success-soft`、`--success-line`、`--warning`、`--warning-soft`、`--warning-line`、`--danger`、`--danger-soft`、`--danger-line`、`--neutral-soft` |
88
+ | 焦点 | `--focus`、`--focus-outline`、`--focus-ring` |
89
+ | 数据与代码 | `--chart-1` 至 `--chart-8`、`--chart-grid`、`--chart-axis`、`--code-bg`、`--code-bg-deep`、`--code-ink` |
90
+ | 字体 | `--font-sans`、`--font-mono`、`--text-xs` 至 `--text-xl`、`--text-2xl`、`--text-block-title`、`--text-block-subtitle` |
91
+ | 行高与字重 | `--leading-tight`、`--leading-snug`、`--leading-normal`、`--leading-relaxed`、`--weight-regular`、`--weight-medium`、`--weight-semibold`、`--weight-bold` |
92
+ | 间距 | `--space-1` 至 `--space-7`、`--field-gap` |
93
+ | 圆角 | `--radius-control`、`--radius-card`、`--radius-panel`、`--radius-pill` |
94
+ | 控件 | `--control-height-sm`、`--control-height`、`--control-height-lg`、`--control-padding-x`、`--control-padding-y`、`--disabled-opacity` |
95
+ | 动效与阴影 | `--motion-fast`、`--motion-base`、`--motion-slow`、`--ease-standard`、`--shadow-sm`、`--shadow-md` |
96
+
97
+ 已有 `--blue`、`--blue-deep`、`--blue-soft`、`--blue-line` 保留兼容;新主题优先使用强调色变量。组件的局部 `color` 属性覆盖对应局部颜色,其余样式继续使用主题。数据序列、状态提示等保留各自的语义颜色。
98
+
99
+ ## 组件 CSS 与验收
100
+
101
+ 主题可在共享变量之外覆盖现有 `.md-*`、`.local-*` 组件类。文档根类、组件外层类和语义状态属性是主题的样式接口;内部节点的排列不是扩展 API。主题规则遵守文档作用域,并在公共样式之后加载。使用足够明确的根节点与组件选择器覆盖基础规则,避免依赖 `!important`。
102
+
103
+ 主题覆盖范围包括 Markdown 正文、表格、公式、输入控件、容器、反馈、图表与图解。新增组件必须读取共享变量并在 `default` 下可用;自定义主题未添加专门规则时继承公共样式。
104
+
105
+ 符合本协议的主题必须在两种模式下检查全部组件,以及 hover、focus、active、disabled、错误与选中状态。保持键盘焦点可见、文字和控件可读、375px 布局可用,并遵守减少动态效果的系统偏好。改变字号或字体后应检查 SVG 图解的标签、节点和边界。
106
+
107
+ 登记校验确认协议与模式声明;CSS 的实际覆盖、对比度和布局通过浏览器验收。验收应包含同页多主题隔离、显式浅色置于深色宿主、系统切换、状态保留和卸载清理。
@@ -1,107 +1,107 @@
1
- # Reactive MD theme protocol
2
-
3
- Protocol revision: `reactive-md-theme-1`. This feature was introduced in `0.4.0` and remains available in `0.6.0` on both `latest` and `next`. The built-in `default` preserves the existing appearance.
4
-
5
- ## Selecting a theme
6
-
7
- Place a declaration before the document body:
8
-
9
- ```markdown
10
- <theme name="default">
11
-
12
- # Document title
13
- ```
14
-
15
- `<theme name="default" />` is also accepted. Omission selects `default`. Whitespace, a BOM and comments may precede the declaration. Declare it once, outside components. The static `name` uses lowercase kebab-case, starts with a letter and has at most 64 characters. Expressions and additional attributes are invalid.
16
-
17
- The declaration is document metadata, does not count as a component and produces no visible element. Compilation stores `document.theme` and the original declaration's `document.themeRange`. Body nodes retain their original source positions. Fenced code, inline code, comments and escaped examples remain literal.
18
-
19
- Invalid declarations produce `local.theme.*` warnings and select `default`. Repeated declarations do not change the first selection. Late or nested declarations do not select a theme. Healthy body content and controls remain usable.
20
-
21
- ## Host registration
22
-
23
- A developer supplies CSS and registration metadata. Import the shared styles before the theme stylesheet, then pass the allowed themes to the renderer:
24
-
25
- ```tsx
26
- import { LOCAL_THEME_PROTOCOL, type LocalThemeDefinition } from 'reactive-md';
27
- import { LocalReactiveDocument } from 'reactive-md/react';
28
- import 'reactive-md/styles.css';
29
- import './paper-theme.css';
30
-
31
- const paperTheme = {
32
- name: 'paper',
33
- protocol: LOCAL_THEME_PROTOCOL,
34
- colorSchemes: ['light', 'dark'],
35
- } as const satisfies LocalThemeDefinition;
36
-
37
- export function Article({ source }: { source: string }) {
38
- return <LocalReactiveDocument source={source} themes={[paperTheme]} colorScheme="auto" />;
39
- }
40
- ```
41
-
42
- This demonstrates registration. The repository includes only `default`; it does not include a `paper` design or stylesheet.
43
-
44
- | Field | Requirement |
45
- | --- | --- |
46
- | `name` | Follows the document identifier rules; unique in the host list; `default` is reserved |
47
- | `protocol` | Must be `reactive-md-theme-1`; use `LOCAL_THEME_PROTOCOL` |
48
- | `colorSchemes` | Must include both `light` and `dark` |
49
-
50
- The host loads the CSS. Registration does not fetch or inject styles. Documents select a registered name and cannot provide CSS, stylesheet URLs or scripts. Theme CSS is trusted host code; the host reviews its scope and resource references.
51
-
52
- An unknown name, duplicate selected name, invalid selected registration, unsupported protocol or missing mode produces a renderer warning and falls back to `default`. Core-only hosts can call `resolveLocalTheme(name, themes, range?, source?)` to obtain `{ name, diagnostics }`. Compilation parses declarations independently of host registrations.
53
-
54
- ## Color schemes and instance scope
55
-
56
- Both React components accept `themes` and `colorScheme`. The theme selects the visual design; the color scheme selects its light or dark version:
57
-
58
- | Value | Behavior |
59
- | --- | --- |
60
- | `light` | Forces light mode for this document, including inside a dark host |
61
- | `dark` | Forces dark mode for this document |
62
- | `auto` (default) | Uses the nearest ancestor's explicit preference, then the system preference; server output starts in light mode |
63
-
64
- Ancestor preferences support `data-color-scheme="light|dark"` and the existing `data-theme="light|dark"`. Ancestor attribute changes and system preference changes update the document in the browser. An explicit local `colorScheme` takes precedence.
65
-
66
- The renderer exposes the resolved selection on its document root:
67
-
68
- ```html
69
- <article class="md-document local-document"
70
- data-rmd-theme="paper"
71
- data-color-scheme="dark">
72
- ```
73
-
74
- Each instance chooses independently. Every theme rule must be scoped to its named root or descendants, for example `[data-rmd-theme="paper"][data-color-scheme="dark"]`. Global `body`, `:root` and unscoped element rules must not affect the host.
75
-
76
- Changing `themes` or `colorScheme` does not create a runtime. Changing `LocalReactiveDocument.source` retains its existing behavior: recompilation and a new runtime. Hosts that retain parameters across source changes can manage `LocalDocumentView` and its runtime themselves.
77
-
78
- ## Shared style variables
79
-
80
- Shared component CSS supplies structure, interaction and defaults. Custom themes inherit a complete default variable set and override the values they need. Both light and dark variants must be designed and checked.
81
-
82
- | Purpose | Public variables |
83
- | --- | --- |
84
- | Surfaces | `--paper`, `--surface`, `--document-bg` (defaults to `--surface`), `--surface-subtle`, `--surface-hover`, `--surface-active` |
85
- | Text and borders | `--ink`, `--ink-soft`, `--ink-muted`, `--line`, `--line-strong` |
86
- | Accent | `--accent`, `--accent-hover`, `--accent-soft`, `--accent-line` |
87
- | Status | `--info`, `--info-soft`, `--success`, `--success-soft`, `--success-line`, `--warning`, `--warning-soft`, `--warning-line`, `--danger`, `--danger-soft`, `--danger-line`, `--neutral-soft` |
88
- | Focus | `--focus`, `--focus-outline`, `--focus-ring` |
89
- | Data and code | `--chart-1` through `--chart-8`, `--chart-grid`, `--chart-axis`, `--code-bg`, `--code-bg-deep`, `--code-ink` |
90
- | Fonts | `--font-sans`, `--font-mono`, `--text-xs` through `--text-xl`, `--text-2xl`, `--text-block-title`, `--text-block-subtitle` |
91
- | Line height and weight | `--leading-tight`, `--leading-snug`, `--leading-normal`, `--leading-relaxed`, `--weight-regular`, `--weight-medium`, `--weight-semibold`, `--weight-bold` |
92
- | Spacing | `--space-1` through `--space-7`, `--field-gap` |
93
- | Radius | `--radius-control`, `--radius-card`, `--radius-panel`, `--radius-pill` |
94
- | Controls | `--control-height-sm`, `--control-height`, `--control-height-lg`, `--control-padding-x`, `--control-padding-y`, `--disabled-opacity` |
95
- | Motion and elevation | `--motion-fast`, `--motion-base`, `--motion-slow`, `--ease-standard`, `--shadow-sm`, `--shadow-md` |
96
-
97
- Existing `--blue`, `--blue-deep`, `--blue-soft` and `--blue-line` remain compatible. New themes should use the accent variables. Explicit component `color` attributes override their corresponding local color; other properties continue to use the theme. Series and status colors retain their semantic roles.
98
-
99
- ## Component CSS and acceptance
100
-
101
- Themes can supplement variable overrides with existing `.md-*` and `.local-*` component classes. Root classes, component outer classes and semantic state attributes are styling interfaces; internal node ordering is not an extension API. Load scoped theme rules after the shared stylesheet, using sufficiently specific root and component selectors instead of relying on `!important`.
102
-
103
- Coverage includes Markdown, tables, formulas, controls, containers, feedback, charts and diagrams. New components must consume shared variables and work with `default`. Themes without dedicated rules for a new component inherit its shared styles.
104
-
105
- A conforming theme must check every component in both modes, including hover, focus, active, disabled, error and selection states. Preserve visible keyboard focus, readable text and controls, a usable 375px layout and reduced-motion preferences. Font changes require checking SVG diagram labels, nodes and bounds.
106
-
107
- Registration validates protocol and declared modes. Browser acceptance verifies CSS coverage, contrast and layout. Include multiple isolated themes, forced light inside a dark host, system preference changes, retained interaction state and unmount cleanup.
1
+ # Reactive MD theme protocol
2
+
3
+ Protocol revision: `reactive-md-theme-1`. This feature was introduced in `0.4.0` and remains available in `0.6.0` on both `latest` and `next`. The built-in `default` preserves the existing appearance.
4
+
5
+ ## Selecting a theme
6
+
7
+ Place a declaration before the document body:
8
+
9
+ ```markdown
10
+ <theme name="default">
11
+
12
+ # Document title
13
+ ```
14
+
15
+ `<theme name="default" />` is also accepted. Omission selects `default`. Whitespace, a BOM and comments may precede the declaration. Declare it once, outside components. The static `name` uses lowercase kebab-case, starts with a letter and has at most 64 characters. Expressions and additional attributes are invalid.
16
+
17
+ The declaration is document metadata, does not count as a component and produces no visible element. Compilation stores `document.theme` and the original declaration's `document.themeRange`. Body nodes retain their original source positions. Fenced code, inline code, comments and escaped examples remain literal.
18
+
19
+ Invalid declarations produce `local.theme.*` warnings and select `default`. Repeated declarations do not change the first selection. Late or nested declarations do not select a theme. Healthy body content and controls remain usable.
20
+
21
+ ## Host registration
22
+
23
+ A developer supplies CSS and registration metadata. Import the shared styles before the theme stylesheet, then pass the allowed themes to the renderer:
24
+
25
+ ```tsx
26
+ import { LOCAL_THEME_PROTOCOL, type LocalThemeDefinition } from 'reactive-md';
27
+ import { LocalReactiveDocument } from 'reactive-md/react';
28
+ import 'reactive-md/styles.css';
29
+ import './paper-theme.css';
30
+
31
+ const paperTheme = {
32
+ name: 'paper',
33
+ protocol: LOCAL_THEME_PROTOCOL,
34
+ colorSchemes: ['light', 'dark'],
35
+ } as const satisfies LocalThemeDefinition;
36
+
37
+ export function Article({ source }: { source: string }) {
38
+ return <LocalReactiveDocument source={source} themes={[paperTheme]} colorScheme="auto" />;
39
+ }
40
+ ```
41
+
42
+ This demonstrates registration. The repository includes only `default`; it does not include a `paper` design or stylesheet.
43
+
44
+ | Field | Requirement |
45
+ | --- | --- |
46
+ | `name` | Follows the document identifier rules; unique in the host list; `default` is reserved |
47
+ | `protocol` | Must be `reactive-md-theme-1`; use `LOCAL_THEME_PROTOCOL` |
48
+ | `colorSchemes` | Must include both `light` and `dark` |
49
+
50
+ The host loads the CSS. Registration does not fetch or inject styles. Documents select a registered name and cannot provide CSS, stylesheet URLs or scripts. Theme CSS is trusted host code; the host reviews its scope and resource references.
51
+
52
+ An unknown name, duplicate selected name, invalid selected registration, unsupported protocol or missing mode produces a renderer warning and falls back to `default`. Core-only hosts can call `resolveLocalTheme(name, themes, range?, source?)` to obtain `{ name, diagnostics }`. Compilation parses declarations independently of host registrations.
53
+
54
+ ## Color schemes and instance scope
55
+
56
+ Both React components accept `themes` and `colorScheme`. The theme selects the visual design; the color scheme selects its light or dark version:
57
+
58
+ | Value | Behavior |
59
+ | --- | --- |
60
+ | `light` | Forces light mode for this document, including inside a dark host |
61
+ | `dark` | Forces dark mode for this document |
62
+ | `auto` (default) | Uses the nearest ancestor's explicit preference, then the system preference; server output starts in light mode |
63
+
64
+ Ancestor preferences support `data-color-scheme="light|dark"` and the existing `data-theme="light|dark"`. Ancestor attribute changes and system preference changes update the document in the browser. An explicit local `colorScheme` takes precedence.
65
+
66
+ The renderer exposes the resolved selection on its document root:
67
+
68
+ ```html
69
+ <article class="md-document local-document"
70
+ data-rmd-theme="paper"
71
+ data-color-scheme="dark">
72
+ ```
73
+
74
+ Each instance chooses independently. Every theme rule must be scoped to its named root or descendants, for example `[data-rmd-theme="paper"][data-color-scheme="dark"]`. Global `body`, `:root` and unscoped element rules must not affect the host.
75
+
76
+ Changing `themes` or `colorScheme` does not create a runtime. Changing `LocalReactiveDocument.source` retains its existing behavior: recompilation and a new runtime. Hosts that retain parameters across source changes can manage `LocalDocumentView` and its runtime themselves.
77
+
78
+ ## Shared style variables
79
+
80
+ Shared component CSS supplies structure, interaction and defaults. Custom themes inherit a complete default variable set and override the values they need. Both light and dark variants must be designed and checked.
81
+
82
+ | Purpose | Public variables |
83
+ | --- | --- |
84
+ | Surfaces | `--paper`, `--surface`, `--document-bg` (defaults to `--surface`), `--surface-subtle`, `--surface-hover`, `--surface-active` |
85
+ | Text and borders | `--ink`, `--ink-soft`, `--ink-muted`, `--line`, `--line-strong` |
86
+ | Accent | `--accent`, `--accent-hover`, `--accent-soft`, `--accent-line` |
87
+ | Status | `--info`, `--info-soft`, `--success`, `--success-soft`, `--success-line`, `--warning`, `--warning-soft`, `--warning-line`, `--danger`, `--danger-soft`, `--danger-line`, `--neutral-soft` |
88
+ | Focus | `--focus`, `--focus-outline`, `--focus-ring` |
89
+ | Data and code | `--chart-1` through `--chart-8`, `--chart-grid`, `--chart-axis`, `--code-bg`, `--code-bg-deep`, `--code-ink` |
90
+ | Fonts | `--font-sans`, `--font-mono`, `--text-xs` through `--text-xl`, `--text-2xl`, `--text-block-title`, `--text-block-subtitle` |
91
+ | Line height and weight | `--leading-tight`, `--leading-snug`, `--leading-normal`, `--leading-relaxed`, `--weight-regular`, `--weight-medium`, `--weight-semibold`, `--weight-bold` |
92
+ | Spacing | `--space-1` through `--space-7`, `--field-gap` |
93
+ | Radius | `--radius-control`, `--radius-card`, `--radius-panel`, `--radius-pill` |
94
+ | Controls | `--control-height-sm`, `--control-height`, `--control-height-lg`, `--control-padding-x`, `--control-padding-y`, `--disabled-opacity` |
95
+ | Motion and elevation | `--motion-fast`, `--motion-base`, `--motion-slow`, `--ease-standard`, `--shadow-sm`, `--shadow-md` |
96
+
97
+ Existing `--blue`, `--blue-deep`, `--blue-soft` and `--blue-line` remain compatible. New themes should use the accent variables. Explicit component `color` attributes override their corresponding local color; other properties continue to use the theme. Series and status colors retain their semantic roles.
98
+
99
+ ## Component CSS and acceptance
100
+
101
+ Themes can supplement variable overrides with existing `.md-*` and `.local-*` component classes. Root classes, component outer classes and semantic state attributes are styling interfaces; internal node ordering is not an extension API. Load scoped theme rules after the shared stylesheet, using sufficiently specific root and component selectors instead of relying on `!important`.
102
+
103
+ Coverage includes Markdown, tables, formulas, controls, containers, feedback, charts and diagrams. New components must consume shared variables and work with `default`. Themes without dedicated rules for a new component inherit its shared styles.
104
+
105
+ A conforming theme must check every component in both modes, including hover, focus, active, disabled, error and selection states. Preserve visible keyboard focus, readable text and controls, a usable 375px layout and reduced-motion preferences. Font changes require checking SVG diagram labels, nodes and bounds.
106
+
107
+ Registration validates protocol and declared modes. Browser acceptance verifies CSS coverage, contrast and layout. Include multiple isolated themes, forced light inside a dark host, system preference changes, retained interaction state and unmount cleanup.