reactive-md 0.6.1 → 0.8.0

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 (471) hide show
  1. package/CHANGELOG-ch.md +66 -0
  2. package/CHANGELOG.md +66 -0
  3. package/CONTRIBUTING-ch.md +6 -62
  4. package/CONTRIBUTING.md +5 -63
  5. package/README-ch.md +232 -67
  6. package/README-en.md +209 -71
  7. package/README.md +209 -71
  8. package/SECURITY-ch.md +3 -1
  9. package/SECURITY.md +3 -1
  10. package/THIRD_PARTY_NOTICES.md +1909 -87
  11. package/cli/args.mjs +33 -1
  12. package/cli/build.mjs +62 -1
  13. package/cli/check.mjs +444 -0
  14. package/cli/help.mjs +181 -3
  15. package/cli/init.mjs +1577 -0
  16. package/cli/main.mjs +11 -1
  17. package/cli/package-loader.mjs +41 -0
  18. package/dist-library/LocalDocumentView-6trX7xJc.js +97920 -0
  19. package/dist-library/{authoring-BEVyth5X.js → authoring-BsfSwQRm.js} +237 -209
  20. package/dist-library/compiler--ea2CKQF.js +61 -0
  21. package/dist-library/compiler-core-kPiH-gOV.js +11805 -0
  22. package/dist-library/component-state-Cq2K5gkS.js +490 -0
  23. package/dist-library/component-state-D_cw_EHe.js +54 -0
  24. package/dist-library/config-validation-DXTynAw7.js +3005 -0
  25. package/dist-library/default-components-Z_YMio5P.js +2346 -0
  26. package/dist-library/identity-MYJXKSkB.js +1443 -0
  27. package/dist-library/math-display-BJz4gbFc.js +24000 -0
  28. package/dist-library/math-sample-BGEW49zY.js +1124 -0
  29. package/dist-library/options-CX5m5n-J.js +115 -0
  30. package/dist-library/parser-standard-DlCk7sLo.js +10122 -0
  31. package/dist-library/props-DGlBk0e5.js +183 -0
  32. package/dist-library/react-ByOHunUW.js +122 -0
  33. package/dist-library/reactive-md-authoring.js +712 -1077
  34. package/dist-library/reactive-md-build.js +7966 -0
  35. package/dist-library/reactive-md-compiler-standard.js +33 -0
  36. package/dist-library/reactive-md-compiler.js +22 -0
  37. package/dist-library/reactive-md-default-packs.js +71 -0
  38. package/dist-library/reactive-md-default-preset.js +10 -0
  39. package/dist-library/reactive-md-export.js +111 -0
  40. package/dist-library/reactive-md-print.css +18 -3
  41. package/dist-library/reactive-md-react-runtime.js +251 -0
  42. package/dist-library/reactive-md-react-server.js +55 -0
  43. package/dist-library/reactive-md-react-unstyled.js +9 -1
  44. package/dist-library/reactive-md-react.js +9 -1
  45. package/dist-library/reactive-md-runtime-browser.js +51 -0
  46. package/dist-library/reactive-md-runtime.js +3 -0
  47. package/dist-library/reactive-md-sdk.js +6 -0
  48. package/dist-library/reactive-md-standalone-host.js +442 -0
  49. package/dist-library/reactive-md-testing-browser.js +523 -0
  50. package/dist-library/reactive-md-testing-react.js +221 -0
  51. package/dist-library/reactive-md-testing.js +638 -0
  52. package/dist-library/reactive-md-vite.js +959 -0
  53. package/dist-library/reactive-md.css +1 -1
  54. package/dist-library/reactive-md.js +1080 -795
  55. package/dist-library/registry-B9Jc3FVe.js +1174 -0
  56. package/dist-library/resources-BGt8mpDA.js +204 -0
  57. package/dist-library/runtime-C-sbfpOX.js +1157 -0
  58. package/dist-library/runtime-Dkq7ldyg.js +172 -0
  59. package/dist-library/schema-ZFufO8V0.js +39 -0
  60. package/dist-library/shareable-DDVL4Fi9.js +844 -0
  61. package/dist-library/types/authoring/catalog.d.ts +168 -0
  62. package/dist-library/types/authoring/conformance.d.ts +24 -0
  63. package/dist-library/types/{editor → authoring}/editor-i18n.d.ts +3 -24
  64. package/dist-library/types/authoring/extensions.d.ts +13 -0
  65. package/dist-library/types/authoring/index.d.ts +14 -11
  66. package/dist-library/types/authoring/insert.d.ts +16 -0
  67. package/dist-library/types/{editor → authoring}/native-components.d.ts +19 -2
  68. package/dist-library/types/authoring/templates.d.ts +65 -0
  69. package/dist-library/types/build/diagnostics.d.ts +8 -0
  70. package/dist-library/types/build/digest.d.ts +5 -0
  71. package/dist-library/types/build/entry.d.ts +9 -0
  72. package/dist-library/types/build/host.d.ts +36 -0
  73. package/dist-library/types/build/index.d.ts +99 -0
  74. package/dist-library/types/build/notices.d.ts +29 -0
  75. package/dist-library/types/build/resources.d.ts +60 -0
  76. package/dist-library/types/build/vite.d.ts +15 -0
  77. package/dist-library/types/compiler/index.d.ts +22 -0
  78. package/dist-library/types/compiler/result.d.ts +30 -0
  79. package/dist-library/types/compiler/standard.d.ts +16 -0
  80. package/dist-library/types/compiler/types.d.ts +69 -0
  81. package/dist-library/types/components/chart-motion.d.ts +12 -0
  82. package/dist-library/types/components/controls.d.ts +21 -0
  83. package/dist-library/types/{local → components}/data-table.d.ts +10 -24
  84. package/dist-library/types/components/default-chart-types.d.ts +22 -0
  85. package/dist-library/types/components/default-chart.d.ts +2 -0
  86. package/dist-library/types/components/default-preset.d.ts +10 -0
  87. package/dist-library/types/components/diagram-inspector.d.ts +24 -0
  88. package/dist-library/types/components/gallery.d.ts +6 -0
  89. package/dist-library/types/components/layout.d.ts +23 -0
  90. package/dist-library/types/components/mafs-plot-grid.d.ts +57 -0
  91. package/dist-library/types/components/mafs-visuals.d.ts +40 -0
  92. package/dist-library/types/components/numeric-sliders.d.ts +3 -0
  93. package/dist-library/types/components/uiarc/calendar/calendar.d.ts +26 -0
  94. package/dist-library/types/components/uiarc/date-picker/date-picker.d.ts +29 -0
  95. package/dist-library/types/components/uiarc/lib/motion-tokens.d.ts +2 -0
  96. package/dist-library/types/components/uiarc/lib/use-today.d.ts +2 -0
  97. package/dist-library/types/components/uiarc/motion-tokens.d.ts +60 -0
  98. package/dist-library/types/components/uiarc/rmd-motion.d.ts +12 -0
  99. package/dist-library/types/components/uiarc/select/select.d.ts +21 -0
  100. package/dist-library/types/components/uiarc/slider/slider.d.ts +53 -0
  101. package/dist-library/types/components/use-hydrated.d.ts +6 -0
  102. package/dist-library/types/components/visuals.d.ts +13 -0
  103. package/dist-library/types/export/component-state.d.ts +39 -0
  104. package/dist-library/types/export/index.d.ts +47 -0
  105. package/dist-library/types/export/requirements.d.ts +23 -0
  106. package/dist-library/types/export/resources.d.ts +8 -0
  107. package/dist-library/types/export/restoration.d.ts +52 -0
  108. package/dist-library/types/index.d.ts +1 -0
  109. package/dist-library/types/local/compilation/compiler-core.d.ts +16 -0
  110. package/dist-library/types/local/compilation/compiler-services.d.ts +64 -0
  111. package/dist-library/types/local/compilation/compiler-structure.d.ts +46 -0
  112. package/dist-library/types/local/compilation/compiler-values.d.ts +9 -0
  113. package/dist-library/types/local/compilation/compiler.d.ts +34 -0
  114. package/dist-library/types/local/compilation/component-kernel.d.ts +487 -0
  115. package/dist-library/types/local/{dependencies.d.ts → compilation/dependencies.d.ts} +4 -3
  116. package/dist-library/types/local/{diagnostics.d.ts → configuration/diagnostic-messages.d.ts} +193 -65
  117. package/dist-library/types/local/configuration/diagnostics.d.ts +58 -0
  118. package/dist-library/types/local/{limits.d.ts → configuration/limits.d.ts} +15 -2
  119. package/dist-library/types/local/configuration/options-core.d.ts +120 -0
  120. package/dist-library/types/local/configuration/options.d.ts +17 -0
  121. package/dist-library/types/local/configuration/portable-options.d.ts +3 -0
  122. package/dist-library/types/local/configuration/schema-core.d.ts +32 -0
  123. package/dist-library/types/local/configuration/schema.d.ts +12 -0
  124. package/dist-library/types/local/contracts/types.d.ts +519 -0
  125. package/dist-library/types/local/{version.d.ts → contracts/version.d.ts} +1 -1
  126. package/dist-library/types/local/{computations.d.ts → evaluation/computations.d.ts} +6 -3
  127. package/dist-library/types/local/{expression.d.ts → evaluation/expression.d.ts} +2 -2
  128. package/dist-library/types/local/{math-display.d.ts → evaluation/math-display.d.ts} +2 -16
  129. package/dist-library/types/local/evaluation/math-sample.d.ts +23 -0
  130. package/dist-library/types/local/evaluation/math.d.ts +73 -0
  131. package/dist-library/types/local/{validation.d.ts → evaluation/validation.d.ts} +1 -1
  132. package/dist-library/types/local/html/html-details.d.ts +16 -0
  133. package/dist-library/types/local/html/html-entities.d.ts +7 -0
  134. package/dist-library/types/local/html/html-policy.d.ts +43 -0
  135. package/dist-library/types/local/html/html-recovery.d.ts +16 -0
  136. package/dist-library/types/local/html/html-table-names.d.ts +9 -0
  137. package/dist-library/types/local/{html-table.d.ts → html/html-table.d.ts} +2 -6
  138. package/dist-library/types/local/{html.d.ts → html/html.d.ts} +1 -1
  139. package/dist-library/types/local/index.d.ts +31 -24
  140. package/dist-library/types/local/markdown/fast-markdown.d.ts +137 -0
  141. package/dist-library/types/local/{footnotes.d.ts → markdown/footnotes.d.ts} +1 -1
  142. package/dist-library/types/local/{heading-anchors.d.ts → markdown/heading-anchors.d.ts} +12 -2
  143. package/dist-library/types/local/markdown/markdown-blocks.d.ts +55 -0
  144. package/dist-library/types/local/markdown/markdown-structure.d.ts +3 -0
  145. package/dist-library/types/local/markdown/plain-paragraphs.d.ts +10 -0
  146. package/dist-library/types/local/parsing/lexical.d.ts +21 -0
  147. package/dist-library/types/local/parsing/parse-budget.d.ts +67 -0
  148. package/dist-library/types/local/parsing/parser-capabilities.d.ts +42 -0
  149. package/dist-library/types/local/parsing/parser-core.d.ts +65 -0
  150. package/dist-library/types/local/parsing/parser-standard.d.ts +7 -0
  151. package/dist-library/types/local/parsing/parser.d.ts +16 -0
  152. package/dist-library/types/local/parsing/rmd-recovery.d.ts +48 -0
  153. package/dist-library/types/local/{LocalDocumentView.d.ts → rendering/LocalDocumentView.d.ts} +67 -24
  154. package/dist-library/types/local/rendering/legacy-component-adapter.d.ts +36 -0
  155. package/dist-library/types/local/rendering/render-types.d.ts +57 -0
  156. package/dist-library/types/local/rendering/view-revision.d.ts +75 -0
  157. package/dist-library/types/local/{retention.d.ts → runtime/retention.d.ts} +1 -1
  158. package/dist-library/types/local/runtime/runtime.d.ts +34 -0
  159. package/dist-library/types/local/{state.d.ts → runtime/state.d.ts} +4 -4
  160. package/dist-library/types/local/session/compiler-cache.d.ts +44 -0
  161. package/dist-library/types/local/session/incremental.d.ts +48 -0
  162. package/dist-library/types/local/session/parse-session.d.ts +62 -0
  163. package/dist-library/types/local/session/row-reuse.d.ts +46 -0
  164. package/dist-library/types/local/{authoring.d.ts → source/authoring.d.ts} +11 -3
  165. package/dist-library/types/local/source/node-walk.d.ts +3 -0
  166. package/dist-library/types/local/source/source-context.d.ts +63 -0
  167. package/dist-library/types/local/{source-migration.d.ts → source/source-migration.d.ts} +2 -2
  168. package/dist-library/types/local/{i18n.d.ts → theme/i18n.d.ts} +2 -2
  169. package/dist-library/types/local/theme/theme-name.d.ts +3 -0
  170. package/dist-library/types/local/{theme.d.ts → theme/theme.d.ts} +3 -3
  171. package/dist-library/types/local/transport/compile-patch.d.ts +127 -0
  172. package/dist-library/types/local/{compiled-data.d.ts → transport/compiled-data.d.ts} +1 -1
  173. package/dist-library/types/local/transport/flat-compiled-data.d.ts +17 -0
  174. package/dist-library/types/local/transport/shared-data.d.ts +10 -0
  175. package/dist-library/types/local/transport/worker.d.ts +265 -0
  176. package/dist-library/types/local/widgets/visuals.d.ts +25 -0
  177. package/dist-library/types/presets/default-authoring.d.ts +50 -0
  178. package/dist-library/types/presets/default-components.d.ts +4 -0
  179. package/dist-library/types/presets/default-semantics.d.ts +8 -0
  180. package/dist-library/types/presets/default.d.ts +11 -0
  181. package/dist-library/types/presets/identity.d.ts +7 -0
  182. package/dist-library/types/presets/packs.d.ts +4 -0
  183. package/dist-library/types/react/component-api.d.ts +260 -0
  184. package/dist-library/types/react/component-primitives.d.ts +21 -0
  185. package/dist-library/types/react/component-utils.d.ts +125 -0
  186. package/dist-library/types/react/default-theme.d.ts +6 -0
  187. package/dist-library/types/react/field-validation.d.ts +11 -0
  188. package/dist-library/types/react/index.d.ts +17 -5
  189. package/dist-library/types/react/overflow-text-tooltip.d.ts +6 -0
  190. package/dist-library/types/react/package.d.ts +69 -0
  191. package/dist-library/types/react/runtime/common.d.ts +4 -0
  192. package/dist-library/types/react/runtime/index.d.ts +8 -0
  193. package/dist-library/types/react/runtime/useComponentState.d.ts +30 -0
  194. package/dist-library/types/react/runtime/useKeys.d.ts +16 -0
  195. package/dist-library/types/react/runtime/useSwipe.d.ts +27 -0
  196. package/dist-library/types/react/runtime/useTicker.d.ts +17 -0
  197. package/dist-library/types/react/sdk.d.ts +110 -0
  198. package/dist-library/types/react/server.d.ts +15 -0
  199. package/dist-library/types/react/tooltip-layer.d.ts +10 -0
  200. package/dist-library/types/react/use-draft-field.d.ts +17 -0
  201. package/dist-library/types/runtime-services/browser/index.d.ts +63 -0
  202. package/dist-library/types/runtime-services/component-state.d.ts +152 -0
  203. package/dist-library/types/runtime-services/identity.d.ts +41 -0
  204. package/dist-library/types/runtime-services/index.d.ts +10 -0
  205. package/dist-library/types/runtime-services/random.d.ts +42 -0
  206. package/dist-library/types/runtime-services/runtime.d.ts +51 -0
  207. package/dist-library/types/runtime-services/scheduler.d.ts +44 -0
  208. package/dist-library/types/sdk/assembly.d.ts +73 -0
  209. package/dist-library/types/sdk/compat-profile.d.ts +57 -0
  210. package/dist-library/types/sdk/compiler-config.d.ts +33 -0
  211. package/dist-library/types/sdk/config-validation.d.ts +33 -0
  212. package/dist-library/types/sdk/config.d.ts +35 -0
  213. package/dist-library/types/sdk/hash.d.ts +9 -0
  214. package/dist-library/types/sdk/index.d.ts +10 -0
  215. package/dist-library/types/sdk/manifest.d.ts +49 -0
  216. package/dist-library/types/sdk/pattern.d.ts +11 -0
  217. package/dist-library/types/sdk/preset-core.d.ts +11 -0
  218. package/dist-library/types/sdk/preset.d.ts +9 -0
  219. package/dist-library/types/sdk/props.d.ts +33 -0
  220. package/dist-library/types/sdk/registry-core.d.ts +16 -0
  221. package/dist-library/types/sdk/registry.d.ts +18 -0
  222. package/dist-library/types/sdk/theme.d.ts +73 -0
  223. package/dist-library/types/sdk/types.d.ts +221 -0
  224. package/dist-library/types/sdk/version.d.ts +49 -0
  225. package/dist-library/types/shareable.d.ts +29 -3
  226. package/dist-library/types/standalone/diagnostics.d.ts +16 -0
  227. package/dist-library/types/standalone/events.d.ts +4 -0
  228. package/dist-library/types/standalone/library.d.ts +6 -0
  229. package/dist-library/types/standalone/payload.d.ts +15 -0
  230. package/dist-library/types/standalone/prepare.d.ts +21 -0
  231. package/dist-library/types/standalone/session.d.ts +68 -0
  232. package/dist-library/types/standalone/version.d.ts +7 -0
  233. package/dist-library/types/testing/behavior.d.ts +19 -0
  234. package/dist-library/types/testing/browser.d.ts +126 -0
  235. package/dist-library/types/testing/cases.d.ts +16 -0
  236. package/dist-library/types/testing/index.d.ts +13 -0
  237. package/dist-library/types/testing/manifest.d.ts +10 -0
  238. package/dist-library/types/testing/react.d.ts +45 -0
  239. package/dist-library/types/testing/report.d.ts +20 -0
  240. package/dist-library/types/testing/types.d.ts +125 -0
  241. package/dist-library/types/testing/values.d.ts +22 -0
  242. package/dist-library/types/vite/client.d.ts +36 -0
  243. package/dist-library/types/vite/discovery.d.ts +51 -0
  244. package/dist-library/types/vite/index.d.ts +31 -0
  245. package/dist-library/types/vite/registration.d.ts +109 -0
  246. package/dist-library/types-BFCrMrg0.js +52 -0
  247. package/dist-library/validation-W-bmny-x.js +2253 -0
  248. package/dist-library/values-CIt8AjiU.js +134 -0
  249. package/dist-standalone/reactive-md-standalone.css +1 -1
  250. package/dist-standalone/reactive-md-standalone.js +591 -95
  251. package/docs/README-ch.md +90 -0
  252. package/docs/README.md +87 -81
  253. package/docs/compatibility/compatibility-ch.md +22 -14
  254. package/docs/compatibility/compatibility-en.md +22 -14
  255. package/docs/compatibility/source-versioning-ch.md +15 -12
  256. package/docs/compatibility/source-versioning-en.md +16 -13
  257. package/docs/development/component-development-ch.md +51 -195
  258. package/docs/development/component-development-en.md +51 -195
  259. package/docs/development/component-development-reference-ch.md +253 -0
  260. package/docs/development/component-development-reference-en.md +238 -0
  261. package/docs/development/component-protocol-ch.md +51 -50
  262. package/docs/development/component-protocol-en.md +52 -49
  263. package/docs/development/local-module-layout-ch.md +59 -0
  264. package/docs/development/local-module-layout-en.md +59 -0
  265. package/docs/development/performance-overview-ch.md +402 -0
  266. package/docs/development/performance-overview-en.md +402 -0
  267. package/docs/development/releasing-ch.md +8 -104
  268. package/docs/development/releasing-en.md +8 -104
  269. package/docs/guides/local-guide-ch.md +28 -9
  270. package/docs/guides/local-guide-en.md +31 -12
  271. package/docs/integration/author-tools-ch.md +4 -2
  272. package/docs/integration/author-tools-en.md +4 -2
  273. package/docs/integration/codemirror-ch.md +52 -0
  274. package/docs/integration/codemirror-en.md +29 -0
  275. package/docs/integration/compiler-ch.md +47 -0
  276. package/docs/integration/compiler-en.md +34 -0
  277. package/docs/integration/directory-discovery-ch.md +53 -0
  278. package/docs/integration/directory-discovery-en.md +31 -0
  279. package/docs/integration/editor-ch.md +48 -21
  280. package/docs/integration/editor-en.md +48 -21
  281. package/docs/integration/extension-sdk-ch.md +392 -0
  282. package/docs/integration/extension-sdk-en.md +377 -0
  283. package/docs/integration/local-integration-ch.md +63 -9
  284. package/docs/integration/local-integration-en.md +89 -13
  285. package/docs/integration/repository-split-ch.md +40 -0
  286. package/docs/integration/repository-split-en.md +23 -0
  287. package/docs/integration/shareable-export-ch.md +46 -2
  288. package/docs/integration/shareable-export-en.md +46 -2
  289. package/docs/reference/computations-formatting-ch.md +4 -2
  290. package/docs/reference/computations-formatting-en.md +4 -2
  291. package/docs/reference/constraints-collections-ch.md +21 -1
  292. package/docs/reference/constraints-collections-en.md +21 -1
  293. package/docs/reference/diagnostics-counting-ch.md +1 -1
  294. package/docs/reference/diagnostics-counting-en.md +1 -1
  295. package/docs/reference/html-compatibility-ch.md +4 -0
  296. package/docs/reference/html-compatibility-en.md +4 -0
  297. package/docs/reference/local-components-v2-ch.md +2 -0
  298. package/docs/reference/local-components-v2-en.md +2 -0
  299. package/docs/reference/local-interaction-syntax-ch.md +51 -15
  300. package/docs/reference/local-interaction-syntax-en.md +58 -14
  301. package/docs/reference/theme-protocol-ch.md +79 -7
  302. package/docs/reference/theme-protocol-en.md +79 -7
  303. package/docs/reference/tolerance-ch.md +64 -0
  304. package/docs/reference/tolerance-en.md +57 -0
  305. package/docs/releases/release-0.4.0-ch.md +2 -0
  306. package/docs/releases/release-0.4.0-en.md +2 -0
  307. package/docs/releases/release-0.4.1-ch.md +2 -0
  308. package/docs/releases/release-0.4.1-en.md +2 -0
  309. package/docs/releases/release-0.5.0-ch.md +2 -0
  310. package/docs/releases/release-0.5.0-en.md +2 -0
  311. package/docs/releases/release-0.5.1-ch.md +2 -0
  312. package/docs/releases/release-0.5.1-en.md +2 -0
  313. package/docs/releases/release-0.5.2-ch.md +2 -0
  314. package/docs/releases/release-0.5.2-en.md +2 -0
  315. package/docs/releases/release-0.5.3-ch.md +2 -0
  316. package/docs/releases/release-0.5.3-en.md +2 -0
  317. package/docs/releases/release-0.6.0-ch.md +2 -0
  318. package/docs/releases/release-0.6.0-en.md +2 -0
  319. package/docs/releases/release-0.6.1-ch.md +2 -0
  320. package/docs/releases/release-0.6.1-en.md +2 -0
  321. package/docs/releases/release-0.7.0-ch.md +86 -0
  322. package/docs/releases/release-0.7.0-en.md +86 -0
  323. package/docs/releases/release-0.8.0-ch.md +126 -0
  324. package/docs/releases/release-0.8.0-en.md +126 -0
  325. package/examples/component-package/LICENSE +21 -0
  326. package/examples/component-package/NOTICES.md +12 -0
  327. package/examples/component-package/README-ch.md +101 -0
  328. package/examples/component-package/README.md +133 -0
  329. package/examples/component-package/package.json +35 -0
  330. package/examples/component-package/sample/document.reactive.md +14 -0
  331. package/examples/component-package/scripts/build-export.mjs +44 -0
  332. package/examples/component-package/scripts/build.mjs +130 -0
  333. package/examples/component-package/scripts/verify.mjs +257 -0
  334. package/examples/component-package/src/assets/notice.svg +4 -0
  335. package/examples/component-package/src/component.css +40 -0
  336. package/examples/component-package/src/components.tsx +105 -0
  337. package/examples/component-package/src/harness.tsx +34 -0
  338. package/examples/component-package/src/manifests.ts +71 -0
  339. package/examples/component-package/src/node-entry.ts +18 -0
  340. package/examples/component-package/src/sample.ts +4 -0
  341. package/examples/component-package/src/theme.css +44 -0
  342. package/examples/component-package/src/theme.ts +22 -0
  343. package/examples/component-package/tsconfig.json +15 -0
  344. package/examples/conformance/README-ch.md +55 -0
  345. package/examples/conformance/README.md +2 -0
  346. package/examples/conformance/local-draft-3.json +296 -0
  347. package/examples/game-2048-package/LICENSE +21 -0
  348. package/examples/game-2048-package/NOTICES.md +11 -0
  349. package/examples/game-2048-package/README-ch.md +97 -0
  350. package/examples/game-2048-package/README.md +102 -0
  351. package/examples/game-2048-package/package.json +35 -0
  352. package/examples/game-2048-package/sample/document.reactive.md +17 -0
  353. package/examples/game-2048-package/scripts/build-export.mjs +44 -0
  354. package/examples/game-2048-package/scripts/build.mjs +130 -0
  355. package/examples/game-2048-package/scripts/verify.mjs +180 -0
  356. package/examples/game-2048-package/src/component.css +161 -0
  357. package/examples/game-2048-package/src/components.tsx +326 -0
  358. package/examples/game-2048-package/src/game-engine.ts +228 -0
  359. package/examples/game-2048-package/src/harness.tsx +34 -0
  360. package/examples/game-2048-package/src/manifest.ts +85 -0
  361. package/examples/game-2048-package/src/node-entry.ts +30 -0
  362. package/examples/game-2048-package/src/sample.ts +4 -0
  363. package/examples/game-2048-package/tsconfig.json +15 -0
  364. package/examples/integration/README-ch.md +63 -0
  365. package/examples/integration/README.md +17 -1
  366. package/examples/integration/extension-sdk/README-ch.md +24 -0
  367. package/examples/integration/extension-sdk/README.md +24 -0
  368. package/examples/integration/extension-sdk/advanced-standalone.ts +6 -0
  369. package/examples/integration/extension-sdk/advanced.tsx +101 -0
  370. package/examples/integration/extension-sdk/env.d.ts +2 -0
  371. package/examples/integration/extension-sdk/extensions.tsx +97 -0
  372. package/examples/integration/extension-sdk/index.html +3 -0
  373. package/examples/integration/extension-sdk/main.tsx +10 -0
  374. package/examples/integration/extension-sdk/package.json +6 -0
  375. package/examples/integration/extension-sdk/standalone.ts +7 -0
  376. package/examples/integration/extension-sdk/tsconfig.json +8 -0
  377. package/examples/integration/react-comprehensive/index.html +12 -0
  378. package/examples/integration/react-comprehensive/main.jsx +123 -0
  379. package/examples/integration/react-comprehensive/package.json +18 -0
  380. package/examples/local/README-ch.md +76 -0
  381. package/examples/local/README.md +4 -2
  382. package/examples/local/scenarios/blog-zh.reactive.md +71 -0
  383. package/examples/local/scenarios/blog.reactive.md +71 -0
  384. package/examples/local/scenarios/classroom-zh.reactive.md +97 -0
  385. package/examples/local/scenarios/classroom.reactive.md +97 -0
  386. package/examples/local/scenarios/proposal-zh.reactive.md +79 -0
  387. package/examples/local/scenarios/proposal.reactive.md +79 -0
  388. package/examples/local/scenarios/survey-zh.reactive.md +74 -0
  389. package/examples/local/scenarios/survey.reactive.md +74 -0
  390. package/examples/local/showcase/README-ch.md +22 -0
  391. package/examples/local/showcase/README.md +9 -3
  392. package/examples/local/showcase/features.reactive.md +637 -0
  393. package/examples/local/showcase/zh/features.reactive.md +637 -0
  394. package/examples/sci-fi-theme/README-ch.md +131 -0
  395. package/examples/sci-fi-theme/README.md +146 -0
  396. package/examples/sci-fi-theme/demo/demo.css +532 -0
  397. package/examples/sci-fi-theme/demo/document.reactive.md +185 -0
  398. package/examples/sci-fi-theme/demo/index.html +13 -0
  399. package/examples/sci-fi-theme/demo/main.tsx +180 -0
  400. package/examples/sci-fi-theme/docs/design-system-ch.md +245 -0
  401. package/examples/sci-fi-theme/docs/design-system.md +474 -0
  402. package/examples/sci-fi-theme/package.json +27 -0
  403. package/examples/sci-fi-theme/scripts/screenshot.mjs +98 -0
  404. package/examples/sci-fi-theme/src/components.css +1460 -0
  405. package/examples/sci-fi-theme/src/index.ts +6 -0
  406. package/examples/sci-fi-theme/src/sci-fi.css +5 -0
  407. package/examples/sci-fi-theme/src/theme.ts +37 -0
  408. package/examples/sci-fi-theme/src/tokens.css +408 -0
  409. package/examples/sci-fi-theme/tsconfig.json +20 -0
  410. package/examples/sci-fi-theme/vite.config.ts +24 -0
  411. package/examples/tetris-package/LICENSE +21 -0
  412. package/examples/tetris-package/NOTICES.md +11 -0
  413. package/examples/tetris-package/README-ch.md +91 -0
  414. package/examples/tetris-package/README.md +95 -0
  415. package/examples/tetris-package/package.json +35 -0
  416. package/examples/tetris-package/sample/document.reactive.md +16 -0
  417. package/examples/tetris-package/scripts/build-export.mjs +44 -0
  418. package/examples/tetris-package/scripts/build.mjs +130 -0
  419. package/examples/tetris-package/scripts/verify.mjs +173 -0
  420. package/examples/tetris-package/src/component.css +145 -0
  421. package/examples/tetris-package/src/components.tsx +334 -0
  422. package/examples/tetris-package/src/harness.tsx +34 -0
  423. package/examples/tetris-package/src/manifests.ts +93 -0
  424. package/examples/tetris-package/src/node-entry.ts +16 -0
  425. package/examples/tetris-package/src/sample.ts +4 -0
  426. package/examples/tetris-package/src/tetris-engine.ts +325 -0
  427. package/examples/tetris-package/tsconfig.json +15 -0
  428. package/package.json +98 -44
  429. package/dist-library/compiler-Cm3ppMxG.js +0 -46044
  430. package/dist-library/react-Bh7_oxZp.js +0 -59655
  431. package/dist-library/reactive-md-editor.css +0 -2
  432. package/dist-library/reactive-md-editor.js +0 -3853
  433. package/dist-library/runtime-DlFYQ4s_.js +0 -498
  434. package/dist-library/types/editor/ReactiveMarkdownEditor.d.ts +0 -7
  435. package/dist-library/types/editor/editor-toolbar.d.ts +0 -24
  436. package/dist-library/types/editor/editor-view-bar.d.ts +0 -11
  437. package/dist-library/types/editor/extended-native-components.d.ts +0 -58
  438. package/dist-library/types/editor/index.d.ts +0 -9
  439. package/dist-library/types/editor/locale.d.ts +0 -13
  440. package/dist-library/types/editor/source-authoring.d.ts +0 -59
  441. package/dist-library/types/editor/types.d.ts +0 -48
  442. package/dist-library/types/editor/use-gutter-metrics.d.ts +0 -5
  443. package/dist-library/types/editor/use-source-history.d.ts +0 -16
  444. package/dist-library/types/local/compiler.d.ts +0 -4
  445. package/dist-library/types/local/math.d.ts +0 -48
  446. package/dist-library/types/local/options.d.ts +0 -36
  447. package/dist-library/types/local/parser.d.ts +0 -13
  448. package/dist-library/types/local/render-types.d.ts +0 -27
  449. package/dist-library/types/local/runtime.d.ts +0 -2
  450. package/dist-library/types/local/schema.d.ts +0 -77
  451. package/dist-library/types/local/types.d.ts +0 -263
  452. package/dist-library/types/local/visuals.d.ts +0 -12
  453. package/dist-library/types/local/worker.d.ts +0 -98
  454. package/docs/development/performance-ch.md +0 -76
  455. package/docs/development/performance-en.md +0 -76
  456. /package/dist-library/types/{editor → authoring}/command-types.d.ts +0 -0
  457. /package/dist-library/types/{editor → authoring}/editor-commands.d.ts +0 -0
  458. /package/dist-library/types/local/{locale.d.ts → contracts/locale.d.ts} +0 -0
  459. /package/dist-library/types/local/{collection-functions.d.ts → evaluation/collection-functions.d.ts} +0 -0
  460. /package/dist-library/types/local/{data-functions.d.ts → evaluation/data-functions.d.ts} +0 -0
  461. /package/dist-library/types/local/{dates.d.ts → evaluation/dates.d.ts} +0 -0
  462. /package/dist-library/types/local/{formatting.d.ts → evaluation/formatting.d.ts} +0 -0
  463. /package/dist-library/types/local/{html-names.d.ts → html/html-names.d.ts} +0 -0
  464. /package/dist-library/types/local/{text-length.d.ts → source/text-length.d.ts} +0 -0
  465. /package/dist-library/types/local/{colors.d.ts → theme/colors.d.ts} +0 -0
  466. /package/dist-library/types/local/{code-block.d.ts → widgets/code-block.d.ts} +0 -0
  467. /package/dist-library/types/local/{code-languages.d.ts → widgets/code-languages.d.ts} +0 -0
  468. /package/dist-library/types/local/{diagram-layout.d.ts → widgets/diagram-layout.d.ts} +0 -0
  469. /package/dist-library/types/local/{image-view.d.ts → widgets/image-view.d.ts} +0 -0
  470. /package/dist-library/types/local/{math-view.d.ts → widgets/math-view.d.ts} +0 -0
  471. /package/dist-library/types/local/{table-surface.d.ts → widgets/table-surface.d.ts} +0 -0
@@ -1,3853 +0,0 @@
1
- import { createContext as e, forwardRef as t, memo as n, useCallback as r, useContext as i, useEffect as a, useId as o, useImperativeHandle as s, useLayoutEffect as c, useMemo as l, useRef as u, useState as d } from "react";
2
- import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
3
- import { analyzeLocalSource as h, completeLocalSource as ee, formatLocalSource as g, renameLocalBinding as te } from "reactive-md";
4
- // src/editor/extended-native-components.ts
5
- var _ = [
6
- {
7
- id: "jump",
8
- label: "Jump and anchor",
9
- description: "Link to a named position in this document.",
10
- group: "action",
11
- keywords: [
12
- "jump",
13
- "anchor",
14
- "navigation"
15
- ],
16
- template: "<jump to=\"{{bind:destination}}\" appearance=\"button\" color=\"#2563eb\">View results</jump>\n\n<anchor id=\"{{bind:destination}}\">\n\n{{selection:Results appear here.}}"
17
- },
18
- {
19
- id: "anchor",
20
- label: "Anchor",
21
- description: "Name a destination for document links.",
22
- group: "layout",
23
- keywords: [
24
- "anchor",
25
- "target",
26
- "destination"
27
- ],
28
- template: "<anchor id=\"{{bind:destination}}\">"
29
- },
30
- {
31
- id: "text",
32
- label: "Colored text",
33
- description: "Give selected words a foreground color.",
34
- group: "hint",
35
- keywords: [
36
- "text",
37
- "color",
38
- "foreground"
39
- ],
40
- inline: !0,
41
- template: "<text color=\"#a2273a\">{{selection:Important reminder}}</text>"
42
- },
43
- {
44
- id: "section",
45
- label: "Colored section",
46
- description: "Apply a shared text color to several paragraphs.",
47
- group: "layout",
48
- keywords: [
49
- "section",
50
- "color",
51
- "paragraph"
52
- ],
53
- template: "<section color=\"#45536f\">\n\n{{selection:Your paragraphs go here.}}\n\n</section>"
54
- },
55
- {
56
- id: "multi-select",
57
- label: "Multiple selection",
58
- description: "Choose up to two items and read their values.",
59
- group: "input",
60
- keywords: [
61
- "multiple",
62
- "select",
63
- "subjects",
64
- "checkbox"
65
- ],
66
- template: "<multi-select bind=\"{{bind:subjects}}\" label=\"Subjects\" max-selected=\"2\">\n<option value=\"math\">Math</option>\n<option value=\"physics\">Physics</option>\n<option value=\"chemistry\">Chemistry</option>\n</multi-select>"
67
- },
68
- {
69
- id: "range-slider",
70
- label: "Interval slider",
71
- description: "Choose the lower and upper bounds of an interval.",
72
- group: "input",
73
- keywords: [
74
- "range",
75
- "interval",
76
- "slider",
77
- "bounds"
78
- ],
79
- template: "<range-slider label=\"Interval\" bind-start=\"{{bind:low}}\" bind-end=\"{{bind:high}}\" initial-start=\"20\" initial-end=\"80\" min=\"0\" max=\"100\" step=\"1\">"
80
- },
81
- {
82
- id: "coordinate",
83
- label: "Coordinate point",
84
- description: "Drag a point or change its two coordinates.",
85
- group: "input",
86
- keywords: [
87
- "coordinate",
88
- "point",
89
- "drag",
90
- "geometry"
91
- ],
92
- template: "<coordinate label=\"Point\" bind-x=\"{{bind:px}}\" bind-y=\"{{bind:py}}\" initial-x=\"1\" initial-y=\"2\" x-min=\"-5\" x-max=\"5\" y-min=\"-5\" y-max=\"5\">"
93
- },
94
- {
95
- id: "quiz",
96
- label: "Practice question",
97
- description: "Check an answer and read a short explanation.",
98
- group: "action",
99
- keywords: [
100
- "quiz",
101
- "practice",
102
- "answer",
103
- "learn"
104
- ],
105
- template: "<quiz type=\"choice\" label=\"What is 2 + 3?\" answer=\"b\" explanation=\"The sum is 5.\">\n<option value=\"a\">4</option>\n<option value=\"b\">5</option>\n</quiz>"
106
- },
107
- {
108
- id: "steps",
109
- label: "Guided steps",
110
- description: "Read instructions one step at a time.",
111
- group: "layout",
112
- keywords: [
113
- "steps",
114
- "guide",
115
- "previous",
116
- "next"
117
- ],
118
- template: "<steps label=\"Learning path\" bind=\"{{bind:lesson}}\">\n<step label=\"Observe\">\nChange a parameter.\n</step>\n<step label=\"Practice\">\nCheck an answer.\n</step>\n</steps>"
119
- }
120
- ], v = {
121
- jump: {
122
- label: "跳转与锚点",
123
- description: "跳到当前文档中的指定位置。",
124
- keywords: [
125
- "跳转",
126
- "锚点",
127
- "导航"
128
- ],
129
- template: "<jump to=\"{{bind:destination}}\" appearance=\"button\" color=\"#2563eb\">查看结果</jump>\n\n<anchor id=\"{{bind:destination}}\">\n\n{{selection:结果显示在这里。}}"
130
- },
131
- anchor: {
132
- label: "锚点",
133
- description: "为文档内的跳转指定目标位置。",
134
- keywords: [
135
- "锚点",
136
- "目标",
137
- "位置"
138
- ],
139
- template: "<anchor id=\"{{bind:destination}}\">"
140
- },
141
- text: {
142
- label: "文字颜色",
143
- description: "为选中的局部文字指定颜色。",
144
- keywords: [
145
- "文字",
146
- "颜色",
147
- "前景"
148
- ],
149
- template: "<text color=\"#a2273a\">{{selection:重要提醒}}</text>"
150
- },
151
- section: {
152
- label: "正文颜色",
153
- description: "为一段或多段正文指定统一颜色。",
154
- keywords: [
155
- "正文",
156
- "段落",
157
- "颜色"
158
- ],
159
- template: "<section color=\"#45536f\">\n\n{{selection:在这里填写正文。}}\n\n</section>"
160
- },
161
- "multi-select": {
162
- label: "多选",
163
- description: "最多选择两个选项,公开选项值数组。",
164
- keywords: [
165
- "多选",
166
- "选项",
167
- "主题"
168
- ],
169
- template: "<multi-select bind=\"{{bind:subjects}}\" label=\"主题\" max-selected=\"2\">\n<option value=\"math\">数学</option>\n<option value=\"physics\">物理</option>\n<option value=\"chemistry\">化学</option>\n</multi-select>"
170
- },
171
- "range-slider": {
172
- label: "区间滑块",
173
- description: "同时选择区间的起点和终点。",
174
- keywords: [
175
- "区间",
176
- "滑块",
177
- "上下限"
178
- ],
179
- template: "<range-slider label=\"观察区间\" bind-start=\"{{bind:low}}\" bind-end=\"{{bind:high}}\" initial-start=\"20\" initial-end=\"80\" min=\"0\" max=\"100\" step=\"1\">"
180
- },
181
- coordinate: {
182
- label: "二维坐标",
183
- description: "拖动坐标点,或直接修改两个坐标。",
184
- keywords: [
185
- "坐标",
186
- "拖动",
187
- "几何"
188
- ],
189
- template: "<coordinate label=\"坐标点\" bind-x=\"{{bind:px}}\" bind-y=\"{{bind:py}}\" initial-x=\"1\" initial-y=\"2\" x-min=\"-5\" x-max=\"5\" y-min=\"-5\" y-max=\"5\">"
190
- },
191
- quiz: {
192
- label: "练习题",
193
- description: "检查答案并阅读简短解析。",
194
- keywords: [
195
- "练习",
196
- "题目",
197
- "答案"
198
- ],
199
- template: "<quiz type=\"choice\" label=\"2 + 3 等于多少?\" answer=\"b\" explanation=\"相加得到 5。\">\n<option value=\"a\">4</option>\n<option value=\"b\">5</option>\n</quiz>"
200
- },
201
- steps: {
202
- label: "分步阅读",
203
- description: "按顺序阅读说明,内置上一步和下一步。",
204
- keywords: [
205
- "步骤",
206
- "引导",
207
- "下一步"
208
- ],
209
- template: "<steps label=\"学习路线\" bind=\"{{bind:lesson}}\">\n<step label=\"观察\">\n调整参数。\n</step>\n<step label=\"练习\">\n检查答案。\n</step>\n</steps>"
210
- }
211
- }, ne = {
212
- en: {
213
- sourceLabel: "Reactive MD source",
214
- region: "Source editor",
215
- previewRegion: "Document preview",
216
- viewLabel: "Editor view",
217
- count: (e) => `${e} ${e === "1" ? "character" : "characters"}`,
218
- keyboardHint: "Press Esc, then Tab to reach the toolbar",
219
- edit: "Edit",
220
- split: "Split",
221
- preview: "Preview"
222
- },
223
- zh: {
224
- sourceLabel: "Reactive MD 源码",
225
- region: "源码编辑器",
226
- previewRegion: "文档预览",
227
- viewLabel: "编辑器视图",
228
- count: (e) => `${e} 字`,
229
- keyboardHint: "按 Esc 再 Tab 可到工具条",
230
- edit: "编辑",
231
- split: "并排",
232
- preview: "预览"
233
- }
234
- }, re = {
235
- en: {
236
- boldPlaceholder: "bold text",
237
- italicPlaceholder: "italic text",
238
- strikePlaceholder: "strikethrough text",
239
- inlineCodePlaceholder: "code",
240
- linkText: "link text",
241
- imageAlt: "example image",
242
- codeBlockPlaceholder: "Write code here",
243
- tableHeaders: [
244
- "Column 1",
245
- "Column 2",
246
- "Column 3"
247
- ],
248
- tableRows: [[
249
- "Example 1",
250
- "Example 2",
251
- "Example 3"
252
- ], [
253
- "Example 4",
254
- "Example 5",
255
- "Example 6"
256
- ]]
257
- },
258
- zh: {
259
- boldPlaceholder: "粗体文字",
260
- italicPlaceholder: "斜体文字",
261
- strikePlaceholder: "删除线文字",
262
- inlineCodePlaceholder: "代码",
263
- linkText: "链接文字",
264
- imageAlt: "示意图",
265
- codeBlockPlaceholder: "在这里写代码",
266
- tableHeaders: [
267
- "列 1",
268
- "列 2",
269
- "列 3"
270
- ],
271
- tableRows: [[
272
- "示例 1",
273
- "示例 2",
274
- "示例 3"
275
- ], [
276
- "示例 4",
277
- "示例 5",
278
- "示例 6"
279
- ]]
280
- }
281
- }, ie = {
282
- en: {
283
- toolbarLabel: "Document editing toolbar",
284
- headingLabels: [
285
- "Body",
286
- "Heading 1",
287
- "Heading 2",
288
- "Heading 3",
289
- "Heading 4",
290
- "Heading 5",
291
- "Heading 6"
292
- ],
293
- headingLevelLabel: (e) => `Heading level: ${e}`,
294
- headingMenuLabel: "Heading level",
295
- bold: "Bold",
296
- italic: "Italic",
297
- listLabel: "List",
298
- listLabelWithType: (e) => `List: ${e}`,
299
- listMenuLabel: "List",
300
- listLabels: {
301
- bullet: "Bullet list",
302
- ordered: "Numbered list",
303
- task: "Task list"
304
- },
305
- decreaseIndent: "Decrease indent",
306
- increaseIndent: "Increase indent",
307
- insertLink: "Insert link",
308
- insert: "Insert",
309
- insertMenuLabel: "Insert content",
310
- insertItems: {
311
- image: "Image",
312
- table: "Table",
313
- divider: "Divider",
314
- codeBlock: "Code block",
315
- inlineCode: "Inline code",
316
- strikethrough: "Strikethrough",
317
- quote: "Quote"
318
- },
319
- emoji: "Emoji",
320
- insertEmojiMenuLabel: "Insert emoji",
321
- insertEmojiLabel: (e) => `Insert emoji ${e}`,
322
- componentsTriggerLabel: "Insert native component",
323
- componentsLabel: "Components",
324
- componentsCompactLabel: "Add",
325
- nativeMenuLabel: "Insert native component",
326
- nativeTitle: "Insert component",
327
- closeNativeLabel: "Close component panel",
328
- searchPlaceholder: "Search components, descriptions or keywords",
329
- searchLabel: "Search native components",
330
- nativeListLabel: "Native component list",
331
- noMatchingComponents: "No matching components",
332
- inlineBadge: "Inline",
333
- historyLabel: "History and export",
334
- undo: "Undo",
335
- redo: "Redo",
336
- download: "Download document",
337
- more: "More",
338
- moreMenuLabel: "More actions",
339
- linkMenuItem: "Link"
340
- },
341
- zh: {
342
- toolbarLabel: "文档编辑工具栏",
343
- headingLabels: [
344
- "正文",
345
- "标题 1",
346
- "标题 2",
347
- "标题 3",
348
- "标题 4",
349
- "标题 5",
350
- "标题 6"
351
- ],
352
- headingLevelLabel: (e) => `标题级别:${e}`,
353
- headingMenuLabel: "标题级别",
354
- bold: "加粗",
355
- italic: "斜体",
356
- listLabel: "列表",
357
- listLabelWithType: (e) => `列表:${e}`,
358
- listMenuLabel: "列表",
359
- listLabels: {
360
- bullet: "无序列表",
361
- ordered: "有序列表",
362
- task: "任务列表"
363
- },
364
- decreaseIndent: "减少缩进",
365
- increaseIndent: "增加缩进",
366
- insertLink: "插入链接",
367
- insert: "插入",
368
- insertMenuLabel: "插入内容",
369
- insertItems: {
370
- image: "图片",
371
- table: "表格",
372
- divider: "分隔线",
373
- codeBlock: "代码块",
374
- inlineCode: "行内代码",
375
- strikethrough: "删除线",
376
- quote: "引用"
377
- },
378
- emoji: "表情",
379
- insertEmojiMenuLabel: "插入表情",
380
- insertEmojiLabel: (e) => `插入表情 ${e}`,
381
- componentsTriggerLabel: "插入原生组件",
382
- componentsLabel: "插入组件",
383
- componentsCompactLabel: "添加",
384
- nativeMenuLabel: "插入原生组件",
385
- nativeTitle: "插入组件",
386
- closeNativeLabel: "关闭组件面板",
387
- searchPlaceholder: "搜索组件、说明或关键词",
388
- searchLabel: "搜索原生组件",
389
- nativeListLabel: "原生组件列表",
390
- noMatchingComponents: "没有匹配的组件",
391
- inlineBadge: "行内",
392
- historyLabel: "历史与导出",
393
- undo: "撤销",
394
- redo: "重做",
395
- download: "下载文档",
396
- more: "更多",
397
- moreMenuLabel: "更多操作",
398
- linkMenuItem: "链接"
399
- }
400
- }, y = {
401
- en: {
402
- groups: {
403
- input: "Input controls",
404
- action: "Interactive tools",
405
- layout: "Content layout",
406
- data: "Data visualization",
407
- hint: "Feedback"
408
- },
409
- components: {}
410
- },
411
- zh: {
412
- groups: {
413
- input: "输入控件",
414
- action: "交互工具",
415
- layout: "内容组织",
416
- data: "数据可视化",
417
- hint: "提示反馈"
418
- },
419
- components: {
420
- ...v,
421
- slider: {
422
- label: "滑块",
423
- description: "拖动滑块在指定范围内选择一个数值。",
424
- keywords: [
425
- "滑块",
426
- "范围",
427
- "数值",
428
- "拖动",
429
- "滑动"
430
- ],
431
- template: "<slider bind=\"{{bind:amount}}\" label=\"数量\" initial=\"10\" min=\"0\" max=\"100\" step=\"1\">"
432
- },
433
- number: {
434
- label: "数字输入",
435
- description: "输入精确数字,可限制范围和步长。",
436
- keywords: [
437
- "数字",
438
- "数值",
439
- "输入",
440
- "步长",
441
- "数量"
442
- ],
443
- template: "<number bind=\"{{bind:quantity}}\" label=\"数量\" initial=\"1\" min=\"0\" max=\"100\" step=\"1\">"
444
- },
445
- input: {
446
- label: "单行文本",
447
- description: "输入姓名、标题等单行文本。",
448
- keywords: [
449
- "文本",
450
- "单行",
451
- "输入框",
452
- "名称",
453
- "输入"
454
- ],
455
- template: "<input bind=\"{{bind:name}}\" label=\"名称\" placeholder=\"请输入名称\">"
456
- },
457
- textarea: {
458
- label: "多行文本",
459
- description: "输入说明、备注等多行文字。",
460
- keywords: [
461
- "文本域",
462
- "多行",
463
- "说明",
464
- "备注",
465
- "详细"
466
- ],
467
- template: "<textarea bind=\"{{bind:message}}\" label=\"详细说明\" placeholder=\"请输入详细说明\" rows=\"4\">"
468
- },
469
- toggle: {
470
- label: "开关",
471
- description: "在开启与关闭之间切换一个布尔选项。",
472
- keywords: [
473
- "开关",
474
- "布尔",
475
- "启用",
476
- "切换",
477
- "选项"
478
- ],
479
- template: "<toggle bind=\"{{bind:enabled}}\" label=\"启用选项\">"
480
- },
481
- checkbox: {
482
- label: "复选框",
483
- description: "勾选或取消一个布尔选项。",
484
- keywords: [
485
- "复选",
486
- "勾选",
487
- "布尔",
488
- "确认",
489
- "选项"
490
- ],
491
- template: "<checkbox bind=\"{{bind:confirmed}}\" label=\"确认选项\">"
492
- },
493
- date: {
494
- label: "日期选择",
495
- description: "选择一个日期,未选择时为空字符串。",
496
- keywords: [
497
- "日期",
498
- "日历",
499
- "时间",
500
- "选择"
501
- ],
502
- template: "<date bind=\"{{bind:date}}\" label=\"选择日期\">"
503
- },
504
- choices: {
505
- label: "选项卡片",
506
- description: "从多个选项卡中选择一项。",
507
- keywords: [
508
- "选项",
509
- "选择",
510
- "卡片",
511
- "单选",
512
- "方案"
513
- ],
514
- template: "<choices bind=\"{{bind:plan}}\" label=\"选择方案\">\n<option value=\"basic\">基础版</option>\n<option value=\"pro\">专业版</option>\n</choices>"
515
- },
516
- counter: {
517
- label: "计数器",
518
- description: "通过加减按钮调整整数,并可一键重置。",
519
- keywords: [
520
- "计数",
521
- "加减",
522
- "整数",
523
- "调整",
524
- "重置"
525
- ],
526
- template: "<counter bind=\"{{bind:count}}\" label=\"计数\" initial=\"0\" min=\"0\" max=\"99\">"
527
- },
528
- timer: {
529
- label: "倒计时",
530
- description: "启动、暂停和重置一段专注计时。",
531
- keywords: [
532
- "计时",
533
- "倒计时",
534
- "专注",
535
- "秒",
536
- "暂停"
537
- ],
538
- template: "<timer bind=\"{{bind:remaining}}\" label=\"专注计时\" duration=\"60\">"
539
- },
540
- checklist: {
541
- label: "任务清单",
542
- description: "用可勾选的任务列表记录完成情况。",
543
- keywords: [
544
- "清单",
545
- "任务",
546
- "勾选",
547
- "待办",
548
- "完成"
549
- ],
550
- template: "<checklist bind=\"{{bind:done}}\" label=\"完成清单\">\n- [ ] 第一项任务\n- [ ] 第二项任务\n- [ ] 第三项任务\n</checklist>"
551
- },
552
- progress: {
553
- label: "进度条",
554
- description: "展示 0 到 100 之间的完成进度。",
555
- keywords: [
556
- "进度",
557
- "完成度",
558
- "进度条",
559
- "百分比"
560
- ],
561
- template: "<progress label=\"完成进度\" value=\"{{ 40 }}\">"
562
- },
563
- panel: {
564
- label: "参数面板",
565
- description: "把一组控件包进面板,并附带恢复默认按钮。",
566
- keywords: [
567
- "面板",
568
- "参数",
569
- "重置",
570
- "表单",
571
- "控件"
572
- ],
573
- template: "<panel title=\"参数面板\">\n{{selection:示例内容}}\n</panel>"
574
- },
575
- card: {
576
- label: "内容卡片",
577
- description: "用卡片组织一段独立内容。",
578
- keywords: [
579
- "卡片",
580
- "容器",
581
- "内容",
582
- "区块"
583
- ],
584
- template: "<card title=\"内容卡片\">\n{{selection:示例内容}}\n</card>"
585
- },
586
- if: {
587
- label: "条件区域",
588
- description: "只有条件为真时才显示其中内容。",
589
- keywords: [
590
- "条件",
591
- "判断",
592
- "显示",
593
- "当"
594
- ],
595
- template: "<if when=\"{{ {{select:true}} }}\">\n{{selection:示例内容}}\n</if>"
596
- },
597
- tabs: {
598
- label: "标签页",
599
- description: "把内容分到多个可切换的标签页中。",
600
- keywords: [
601
- "标签页",
602
- "切换",
603
- "分组",
604
- "选项卡"
605
- ],
606
- template: "<tabs label=\"内容标签页\">\n<tab label=\"标签一\">\n{{selection:示例内容}}\n</tab>\n\n<tab label=\"标签二\">\n第二个标签页的内容。\n</tab>\n</tabs>"
607
- },
608
- accordion: {
609
- label: "折叠面板",
610
- description: "把说明放进可展开和收起的条目。",
611
- keywords: [
612
- "折叠",
613
- "展开",
614
- "问答",
615
- "手风琴",
616
- "条目"
617
- ],
618
- template: "<accordion label=\"常见问题\">\n<disclosure label=\"问题一\">\n{{selection:示例内容}}\n</disclosure>\n\n<disclosure label=\"问题二\">\n第二个条目的说明。\n</disclosure>\n</accordion>"
619
- },
620
- chart: {
621
- label: "柱状图",
622
- description: "把 Markdown 表格转换成柱状图。",
623
- keywords: [
624
- "图表",
625
- "柱状图",
626
- "表格",
627
- "数据",
628
- "对比"
629
- ],
630
- template: "<chart kind=\"bar\" title=\"分类对比\" y-label=\"数值\">\n| 项目 | 数值 |\n| --- | ---: |\n| 项目甲 | 20 |\n| 项目乙 | 35 |\n</chart>"
631
- },
632
- table: {
633
- label: "增强表格",
634
- description: "带搜索、排序和分页的 Markdown 表格。",
635
- keywords: [
636
- "表格",
637
- "搜索",
638
- "排序",
639
- "分页",
640
- "数据"
641
- ],
642
- template: "<table label=\"数据表格\" page-size=\"5\">\n| 名称 | 分类 | 数值 |\n| --- | --- | ---: |\n| 项目甲 | 分类一 | 20 |\n| 项目乙 | 分类二 | 35 |\n</table>"
643
- },
644
- timeline: {
645
- label: "时间轴",
646
- description: "用表格展示任务的开始时间与时长。",
647
- keywords: [
648
- "时间轴",
649
- "计划",
650
- "时长",
651
- "日程",
652
- "任务"
653
- ],
654
- template: "<timeline title=\"任务时间轴\">\n| 事项 | 开始 | 时长 | 说明 |\n| --- | ---: | ---: | --- |\n| 准备 | 0 | 10 | 列出所需材料 |\n| 执行 | 10 | 20 | 完成主要内容 |\n| 检查 | 30 | 5 | 复核结果 |\n</timeline>"
655
- },
656
- diagram: {
657
- label: "交互图解",
658
- description: "用节点和连线展示流程,可点击查看说明。",
659
- keywords: [
660
- "图解",
661
- "流程",
662
- "节点",
663
- "连线",
664
- "关系图"
665
- ],
666
- template: "<diagram label=\"流程示意\">\n<node id=\"start\" label=\"开始\">\n流程起点。\n</node>\n\n<node id=\"process\" label=\"处理\">\n执行主要步骤。\n</node>\n\n<node id=\"end\" label=\"结束\">\n查看结果。\n</node>\n\n<edge from=\"start\" to=\"process\" label=\"进入\">\n<edge from=\"process\" to=\"end\" label=\"完成\">\n</diagram>"
667
- },
668
- plot: {
669
- label: "函数曲线",
670
- description: "用 LaTeX 公式绘制一条函数曲线。",
671
- keywords: [
672
- "曲线",
673
- "函数",
674
- "公式",
675
- "数学",
676
- "绘图"
677
- ],
678
- template: "<plot min=\"-5\" max=\"5\" label=\"函数曲线\">\n$$ y = x^2 $$\n</plot>"
679
- },
680
- alert: {
681
- label: "提示框",
682
- description: "用不同语气突出普通、成功或警告信息。",
683
- keywords: [
684
- "提示",
685
- "警告",
686
- "通知",
687
- "信息",
688
- "消息"
689
- ],
690
- template: "<alert tone=\"info\" title=\"提示\">\n{{selection:示例内容}}\n</alert>"
691
- },
692
- badge: {
693
- label: "徽标",
694
- description: "在句子里显示一个简短状态标记。",
695
- keywords: [
696
- "徽标",
697
- "标签",
698
- "状态",
699
- "行内",
700
- "标记"
701
- ],
702
- template: "<badge tone=\"success\">标签</badge>"
703
- },
704
- tooltip: {
705
- label: "行内提示",
706
- description: "为句中的词语附加悬停或聚焦说明。",
707
- keywords: [
708
- "提示",
709
- "悬停",
710
- "说明",
711
- "行内",
712
- "气泡"
713
- ],
714
- template: "<tooltip text=\"这里显示补充说明。\">悬停查看</tooltip>"
715
- }
716
- }
717
- }
718
- }, b = e("en");
719
- function x({ locale: e, children: t }) {
720
- return /* @__PURE__ */ p(b.Provider, {
721
- value: e,
722
- children: t
723
- });
724
- }
725
- function ae() {
726
- return i(b);
727
- }
728
- // src/editor/editor-commands.ts
729
- function S(e, t) {
730
- return typeof e != "number" || Number.isNaN(e) ? 0 : Math.min(Math.max(Math.trunc(e), 0), t);
731
- }
732
- function C(e, t) {
733
- let n = S(t.start, e.length), r = S(t.end, e.length);
734
- return n <= r ? {
735
- start: n,
736
- end: r
737
- } : {
738
- start: r,
739
- end: n
740
- };
741
- }
742
- function w(e) {
743
- return re[e] ?? re.en;
744
- }
745
- function T(e, t) {
746
- return t <= 0 ? 0 : e.lastIndexOf("\n", t - 1) + 1;
747
- }
748
- function E(e, t) {
749
- let n = T(e, t.start), r = t.end > t.start && e[t.end - 1] === "\n" ? t.end - 1 : t.end, i = e.indexOf("\n", r), a = i === -1 ? e.length : i, o = [], s = n;
750
- for (;;) {
751
- let t = e.indexOf("\n", s), n = t === -1 || t > a ? a : t;
752
- if (o.push({
753
- start: s,
754
- end: n,
755
- text: e.slice(s, n)
756
- }), n >= a) break;
757
- s = n + 1;
758
- }
759
- return o;
760
- }
761
- function D(e, t, n) {
762
- if (n.length === 0) return {
763
- value: e,
764
- selection: t
765
- };
766
- let r = [...n].sort((e, t) => e.start - t.start), i = 0, a = r.map((e) => {
767
- let t = e.start + i, n = i;
768
- return i += e.text.length - (e.end - e.start), {
769
- edit: e,
770
- newStart: t,
771
- deltaBefore: n
772
- };
773
- }), o = "", s = 0;
774
- for (let t of a) o += e.slice(s, t.edit.start), o += t.edit.text, s = t.edit.end;
775
- o += e.slice(s);
776
- let c = (e) => {
777
- for (let t of a) {
778
- let { edit: n, newStart: r, deltaBefore: i } = t;
779
- if (e < n.start) return e + i;
780
- if (e <= n.end) {
781
- let t = e - n.start, i = t <= n.oldPrefixLength ? n.newPrefixLength : t + (n.newPrefixLength - n.oldPrefixLength);
782
- return r + Math.min(Math.max(i, 0), n.text.length);
783
- }
784
- }
785
- return e + i;
786
- };
787
- return {
788
- value: o,
789
- selection: {
790
- start: c(t.start),
791
- end: c(t.end)
792
- }
793
- };
794
- }
795
- function O(e, t, n, r) {
796
- return t === e.text ? null : {
797
- start: e.start,
798
- end: e.end,
799
- text: t,
800
- oldPrefixLength: n,
801
- newPrefixLength: r
802
- };
803
- }
804
- function k(e, t, n, r) {
805
- return n === "*" ? r ? e[t.start - 1] !== "*" && e[t.end] !== "*" : e[t.start - n.length - 1] !== "*" && e[t.end + n.length] !== "*" : !0;
806
- }
807
- function A(e, t, n, r) {
808
- let i = C(e, t), a = n.length, { start: o, end: s } = i, c = e.slice(o, s);
809
- if (o !== s) {
810
- if (c.length >= a * 2 && c.startsWith(n) && c.endsWith(n) && (n !== "*" || !c.startsWith("**") && !c.endsWith("**")) && k(e, i, n, !0)) {
811
- let t = c.slice(a, c.length - a);
812
- return {
813
- value: e.slice(0, o) + t + e.slice(s),
814
- selection: {
815
- start: o,
816
- end: o + t.length
817
- }
818
- };
819
- }
820
- let t = o - a, r = s + a;
821
- return t >= 0 && r <= e.length && e.slice(t, o) === n && e.slice(s, r) === n && k(e, i, n, !1) ? {
822
- value: e.slice(0, t) + c + e.slice(r),
823
- selection: {
824
- start: t,
825
- end: t + c.length
826
- }
827
- } : {
828
- value: e.slice(0, o) + n + c + n + e.slice(s),
829
- selection: {
830
- start: o + a,
831
- end: s + a
832
- }
833
- };
834
- }
835
- let l = n + r + n;
836
- return {
837
- value: e.slice(0, o) + l + e.slice(s),
838
- selection: {
839
- start: o + a,
840
- end: o + a + r.length
841
- }
842
- };
843
- }
844
- function j(e, t, n = "en") {
845
- return A(e, t, "**", w(n).boldPlaceholder);
846
- }
847
- function M(e, t, n = "en") {
848
- return A(e, t, "*", w(n).italicPlaceholder);
849
- }
850
- function oe(e, t, n = "en") {
851
- return A(e, t, "~~", w(n).strikePlaceholder);
852
- }
853
- function N(e) {
854
- let t = 0;
855
- for (let n of e.match(/`+/g) ?? []) t = Math.max(t, n.length);
856
- return t;
857
- }
858
- function P(e, t, n) {
859
- let r = 0;
860
- for (; e[t] === "`";) r += 1, t += n;
861
- return r;
862
- }
863
- function se(e, t) {
864
- let { start: n, end: r } = t, i = e.slice(n, r), a = P(e, n - 1, -1), o = P(e, r, 1), s = a > 0 && a === o ? {
865
- run: a,
866
- padding: 0
867
- } : null, c = P(e, n - 2, -1), l = P(e, r + 1, 1), u = e[n - 1] === " " && e[r] === " " && c > 0 && c === l ? {
868
- run: c,
869
- padding: 1
870
- } : null, d = s ?? u;
871
- return !d || N(i) >= d.run ? null : d;
872
- }
873
- function ce(e, t, n = "en") {
874
- let r = C(e, t), { start: i, end: a } = r, o = e.slice(i, a);
875
- if (i === a) {
876
- let t = w(n).inlineCodePlaceholder, r = `\`${t}\``;
877
- return {
878
- value: e.slice(0, i) + r + e.slice(a),
879
- selection: {
880
- start: i + 1,
881
- end: i + 1 + t.length
882
- }
883
- };
884
- }
885
- let s = P(o, 0, 1), c = P(o, o.length - 1, -1);
886
- if (s > 0 && s === c && o.length >= s * 2 && N(o.slice(s, o.length - s)) < s) {
887
- let t = o.slice(s, o.length - s);
888
- return t.startsWith(" ") && t.endsWith(" ") && t.trim().length > 0 && (t = t.slice(1, -1)), {
889
- value: e.slice(0, i) + t + e.slice(a),
890
- selection: {
891
- start: i,
892
- end: i + t.length
893
- }
894
- };
895
- }
896
- let l = se(e, r);
897
- if (l) {
898
- let t = l.run + l.padding;
899
- return {
900
- value: e.slice(0, i - t) + o + e.slice(a + t),
901
- selection: {
902
- start: i - t,
903
- end: i - t + o.length
904
- }
905
- };
906
- }
907
- let u = "`".repeat(N(o) + 1), d = /^[` ]|[` ]$/.test(o) ? " " : "", f = u + d;
908
- return {
909
- value: e.slice(0, i) + f + o + d + u + e.slice(a),
910
- selection: {
911
- start: i + f.length,
912
- end: i + f.length + o.length
913
- }
914
- };
915
- }
916
- var le = /^(#{1,6})[ \t]+/;
917
- function F(e, t, n) {
918
- let r = C(e, t), i = [];
919
- for (let t of E(e, r)) {
920
- let e = le.exec(t.text), r = e ? e[0].length : 0;
921
- if (n === 0 && !e) continue;
922
- let a = t.text.slice(r), o = n === 0 ? "" : `${"#".repeat(n)} `, s = O(t, o + a, r, o.length);
923
- s && i.push(s);
924
- }
925
- return D(e, r, i);
926
- }
927
- var I = /^([ \t]*)([-*+] )/, L = /^([ \t]*)(\d+[.)] )/, R = /^([ \t]*)([-*+] \[[ xX]\] )/, z = /^([ \t]*)(> ?)/;
928
- function B(e, t) {
929
- let n = t.exec(e);
930
- if (!n) return null;
931
- let r = n[1] ?? "", i = n[2] ?? "";
932
- return {
933
- indent: r,
934
- prefix: i,
935
- prefixLength: r.length + i.length
936
- };
937
- }
938
- function ue(e) {
939
- let t = /^[ \t]*/.exec(e);
940
- return t ? t[0] : "";
941
- }
942
- function V(e, t, n, r) {
943
- let i = C(e, t), a = E(e, i), o = a.map((e) => n(e.text)), s = 0, c = !0;
944
- for (let e = 0; e < a.length; e += 1) {
945
- let t = a[e];
946
- (o[e] || t.text.trim().length > 0) && (s += 1, o[e] || (c = !1));
947
- }
948
- let l = s > 0 && c, u = [];
949
- for (let e = 0; e < a.length; e += 1) {
950
- let t = a[e], n = o[e] ?? null;
951
- if (l) {
952
- if (!n) continue;
953
- let e = O(t, n.indent + t.text.slice(n.prefixLength), n.prefixLength, n.indent.length);
954
- e && u.push(e);
955
- continue;
956
- }
957
- let i = n ? n.indent : ue(t.text), s = t.text.slice(n ? n.prefixLength : i.length), c = r(i, e + 1), d = O(t, i + c + s, n ? n.prefixLength : i.length, i.length + c.length);
958
- d && u.push(d);
959
- }
960
- return D(e, i, u);
961
- }
962
- function H(e, t) {
963
- return V(e, t, (e) => B(e, I), () => "- ");
964
- }
965
- function U(e, t) {
966
- return V(e, t, (e) => B(e, L), (e, t) => `${t}. `);
967
- }
968
- function W(e, t) {
969
- return V(e, t, (e) => B(e, R), () => "- [ ] ");
970
- }
971
- function G(e, t) {
972
- return V(e, t, (e) => B(e, z), () => "> ");
973
- }
974
- function de(e, t) {
975
- let n = C(e, t);
976
- return D(e, n, E(e, n).map((e) => ({
977
- start: e.start,
978
- end: e.end,
979
- text: ` ${e.text}`,
980
- oldPrefixLength: 0,
981
- newPrefixLength: 2
982
- })));
983
- }
984
- function K(e) {
985
- if (e.startsWith(" ")) return {
986
- text: e.slice(1),
987
- removed: 1
988
- };
989
- let t = 0;
990
- for (; t < 2 && e[t] === " ";) t += 1;
991
- return {
992
- text: e.slice(t),
993
- removed: t
994
- };
995
- }
996
- function q(e, t) {
997
- let n = C(e, t), r = [];
998
- for (let t of E(e, n)) {
999
- let e = K(t.text);
1000
- if (e.removed === 0) continue;
1001
- let n = O(t, e.text, e.removed, 0);
1002
- n && r.push(n);
1003
- }
1004
- return D(e, n, r);
1005
- }
1006
- function fe(e, t, n = "en") {
1007
- let { start: r, end: i } = C(e, t), a = e.slice(r, i), o = "https://example.com";
1008
- if (a.length > 0) {
1009
- let t = `[${a}](${o})`, n = r + 1 + a.length + 2;
1010
- return {
1011
- value: e.slice(0, r) + t + e.slice(i),
1012
- selection: {
1013
- start: n,
1014
- end: n + 19
1015
- }
1016
- };
1017
- }
1018
- let s = w(n).linkText, c = `[${s}](${o})`;
1019
- return {
1020
- value: e.slice(0, r) + c + e.slice(i),
1021
- selection: {
1022
- start: r + 1,
1023
- end: r + 1 + s.length
1024
- }
1025
- };
1026
- }
1027
- function pe(e, t, n = "en") {
1028
- let { start: r, end: i } = C(e, t), a = e.slice(r, i), o = "images/example.png";
1029
- if (a.length > 0) {
1030
- let t = `![${a}](${o})`, n = r + 2 + a.length + 2;
1031
- return {
1032
- value: e.slice(0, r) + t + e.slice(i),
1033
- selection: {
1034
- start: n,
1035
- end: n + 18
1036
- }
1037
- };
1038
- }
1039
- let s = w(n).imageAlt, c = `![${s}](${o})`;
1040
- return {
1041
- value: e.slice(0, r) + c + e.slice(i),
1042
- selection: {
1043
- start: r + 2,
1044
- end: r + 2 + s.length
1045
- }
1046
- };
1047
- }
1048
- function me(e, t, n = "en") {
1049
- let r = C(e, t), i = e.slice(r.start, r.end), a = i.length > 0 ? i : w(n).codeBlockPlaceholder, o = "`".repeat(Math.max(3, N(a) + 1)), s = `${o}text\n`;
1050
- return _e(e, r, `${s}${a}\n${o}`, {
1051
- start: s.length,
1052
- end: s.length + a.length
1053
- });
1054
- }
1055
- function he(e) {
1056
- return [
1057
- `| ${e.tableHeaders.join(" | ")} |`,
1058
- `| ${e.tableHeaders.map(() => "---").join(" | ")} |`,
1059
- ...e.tableRows.map((e) => `| ${e.join(" | ")} |`)
1060
- ].join("\n");
1061
- }
1062
- function ge(e, t) {
1063
- let n = T(e, t.start), r = e.slice(n, t.start), i = e.indexOf("\n", t.end), a = i === -1 ? e.length : i, o = e.slice(t.end, a), s = "";
1064
- if (/\S/.test(r)) s = "\n\n";
1065
- else if (n > 0) {
1066
- let t = T(e, n - 1);
1067
- /\S/.test(e.slice(t, n - 1)) && (s = "\n");
1068
- }
1069
- return {
1070
- prefix: s,
1071
- suffix: /\S/.test(o) ? "\n\n" : ""
1072
- };
1073
- }
1074
- function _e(e, t, n, r) {
1075
- let { prefix: i, suffix: a } = ge(e, t), o = t.start + i.length;
1076
- return {
1077
- value: e.slice(0, t.start) + i + n + a + e.slice(t.end),
1078
- selection: {
1079
- start: o + r.start,
1080
- end: o + r.end
1081
- }
1082
- };
1083
- }
1084
- function ve(e, t, n = "en") {
1085
- let r = C(e, t), i = w(n), a = he(i), o = i.tableRows[0][0], s = a.indexOf(o);
1086
- return _e(e, r, a, {
1087
- start: s,
1088
- end: s + o.length
1089
- });
1090
- }
1091
- function ye(e, t) {
1092
- return _e(e, C(e, t), "---", {
1093
- start: 3,
1094
- end: 3
1095
- });
1096
- }
1097
- function be(e, t, n) {
1098
- let r = C(e, t), i = r.start + n.length;
1099
- return {
1100
- value: e.slice(0, r.start) + n + e.slice(r.end),
1101
- selection: {
1102
- start: i,
1103
- end: i
1104
- }
1105
- };
1106
- }
1107
- var xe = /\{\{(selection(?::[^{}]*)?|caret|select:[^{}]*)\}\}/g;
1108
- function Se(e, t) {
1109
- let n = "", r = 0, i = null, a = null, o = null;
1110
- xe.lastIndex = 0;
1111
- for (let s = xe.exec(e); s; s = xe.exec(e)) {
1112
- let c = s.index;
1113
- n += e.slice(r, c), r = c + s[0].length;
1114
- let l = s[1] ?? "";
1115
- if (l === "selection") n += t;
1116
- else if (l.startsWith("selection:")) {
1117
- let e = l.slice(10);
1118
- if (t.length > 0) n += t;
1119
- else {
1120
- let t = n.length;
1121
- n += e, a ||= {
1122
- start: t,
1123
- end: n.length
1124
- };
1125
- }
1126
- } else if (l === "caret") o === null && (o = n.length);
1127
- else if (l.startsWith("select:")) {
1128
- let e = l.slice(7), t = n.length;
1129
- n += e, i ||= {
1130
- start: t,
1131
- end: n.length
1132
- };
1133
- } else n += s[0];
1134
- }
1135
- return n += e.slice(r), {
1136
- text: n,
1137
- select: i,
1138
- fallback: a,
1139
- caret: o
1140
- };
1141
- }
1142
- function Ce(e, t, n, r = {}) {
1143
- let i = C(e, t), a = Se(n, e.slice(i.start, i.end)), o = r.block === !0 && a.text.length > 0 ? ge(e, i) : {
1144
- prefix: "",
1145
- suffix: ""
1146
- }, s = i.start + o.prefix.length, c;
1147
- return c = a.select ? {
1148
- start: s + a.select.start,
1149
- end: s + a.select.end
1150
- } : a.fallback ? {
1151
- start: s + a.fallback.start,
1152
- end: s + a.fallback.end
1153
- } : a.caret === null ? {
1154
- start: s + a.text.length,
1155
- end: s + a.text.length
1156
- } : {
1157
- start: s + a.caret,
1158
- end: s + a.caret
1159
- }, {
1160
- value: e.slice(0, i.start) + o.prefix + a.text + o.suffix + e.slice(i.end),
1161
- selection: c
1162
- };
1163
- }
1164
- function we(e, t) {
1165
- let n = [], r = 0;
1166
- for (; r < e.length;) {
1167
- if (e[r] !== t) {
1168
- r += 1;
1169
- continue;
1170
- }
1171
- let i = r;
1172
- for (; e[r] === t;) r += 1;
1173
- n.push({
1174
- start: i,
1175
- end: r,
1176
- length: r - i
1177
- });
1178
- }
1179
- return n;
1180
- }
1181
- function Te(e, t) {
1182
- if (t === "inlineCode") return we(e, "`");
1183
- let n = we(e, t === "strike" ? "~" : "*");
1184
- return t === "italic" ? n.filter((e) => e.length % 2 == 1) : n.filter((e) => e.length >= 2);
1185
- }
1186
- function Ee(e, t, n) {
1187
- return e >= t ? !1 : n.some((r) => r.start === e && n.some((e) => e.end === t && e.length === r.length && e.start >= r.end));
1188
- }
1189
- function De(e, t, n) {
1190
- return e >= t ? !1 : n.some((r) => r.end === e && n.some((e) => e.start === t && e.length === r.length && e.start >= r.end));
1191
- }
1192
- function Oe(e, t) {
1193
- let n = 0;
1194
- for (; n < t.length;) {
1195
- let r = t[n], i = n + 1;
1196
- for (; i < t.length && t[i].length !== r.length;) i += 1;
1197
- let a = t[i];
1198
- if (!a) n += 1;
1199
- else {
1200
- if (e >= r.end && e <= a.start) return !0;
1201
- n = i + 1;
1202
- }
1203
- }
1204
- return !1;
1205
- }
1206
- function J(e, t, n, r) {
1207
- if (t.start !== t.end) {
1208
- let n = Te(e, r);
1209
- return Ee(t.start, t.end, n) || De(t.start, t.end, n);
1210
- }
1211
- return Oe(Math.min(Math.max(t.start - n.start, 0), n.text.length), Te(n.text, r).filter((e) => e.start >= Y(n.text)));
1212
- }
1213
- function Y(e) {
1214
- let t = 0;
1215
- for (;;) {
1216
- let n = e.slice(t), r = B(n, R) ?? B(n, I) ?? B(n, L) ?? B(n, z);
1217
- if (!r) return t;
1218
- t += r.prefixLength;
1219
- }
1220
- }
1221
- function ke(e) {
1222
- return B(e, R) ? "task" : B(e, I) ? "bullet" : B(e, L) ? "ordered" : null;
1223
- }
1224
- function Ae(e, t) {
1225
- let n = C(e, t), r = E(e, {
1226
- start: n.start,
1227
- end: n.start
1228
- })[0], i = r.text, a = le.exec(i);
1229
- return {
1230
- headingLevel: a ? a[1].length : 0,
1231
- bold: J(e, n, r, "bold"),
1232
- italic: J(e, n, r, "italic"),
1233
- strike: J(e, n, r, "strike"),
1234
- inlineCode: J(e, n, r, "inlineCode"),
1235
- list: ke(i),
1236
- quote: B(i, z) !== null
1237
- };
1238
- }
1239
- // src/editor/native-components.ts
1240
- var je = [
1241
- {
1242
- id: "input",
1243
- label: "Input controls"
1244
- },
1245
- {
1246
- id: "action",
1247
- label: "Interactive tools"
1248
- },
1249
- {
1250
- id: "layout",
1251
- label: "Content layout"
1252
- },
1253
- {
1254
- id: "data",
1255
- label: "Data visualization"
1256
- },
1257
- {
1258
- id: "hint",
1259
- label: "Feedback"
1260
- }
1261
- ], Me = [
1262
- ..._,
1263
- {
1264
- id: "slider",
1265
- label: "Slider",
1266
- description: "Drag the slider to choose a number within a range.",
1267
- group: "input",
1268
- keywords: [
1269
- "slider",
1270
- "range",
1271
- "number",
1272
- "drag",
1273
- "value"
1274
- ],
1275
- template: "<slider bind=\"{{bind:amount}}\" label=\"Amount\" initial=\"10\" min=\"0\" max=\"100\" step=\"1\">"
1276
- },
1277
- {
1278
- id: "number",
1279
- label: "Number input",
1280
- description: "Enter an exact number with an optional range and step.",
1281
- group: "input",
1282
- keywords: [
1283
- "number",
1284
- "numeric",
1285
- "input",
1286
- "step",
1287
- "quantity"
1288
- ],
1289
- template: "<number bind=\"{{bind:quantity}}\" label=\"Quantity\" initial=\"1\" min=\"0\" max=\"100\" step=\"1\">"
1290
- },
1291
- {
1292
- id: "input",
1293
- label: "Single-line text",
1294
- description: "Enter a name, title or other single-line text.",
1295
- group: "input",
1296
- keywords: [
1297
- "input",
1298
- "text",
1299
- "single-line",
1300
- "field",
1301
- "name"
1302
- ],
1303
- template: "<input bind=\"{{bind:name}}\" label=\"Name\" placeholder=\"Enter a name\">"
1304
- },
1305
- {
1306
- id: "textarea",
1307
- label: "Multi-line text",
1308
- description: "Enter notes, descriptions or other multi-line text.",
1309
- group: "input",
1310
- keywords: [
1311
- "textarea",
1312
- "text area",
1313
- "multi-line",
1314
- "notes",
1315
- "description"
1316
- ],
1317
- template: "<textarea bind=\"{{bind:message}}\" label=\"Details\" placeholder=\"Enter details\" rows=\"4\">"
1318
- },
1319
- {
1320
- id: "toggle",
1321
- label: "Toggle",
1322
- description: "Switch a boolean option on or off.",
1323
- group: "input",
1324
- keywords: [
1325
- "toggle",
1326
- "switch",
1327
- "boolean",
1328
- "enable",
1329
- "on"
1330
- ],
1331
- template: "<toggle bind=\"{{bind:enabled}}\" label=\"Enable option\">"
1332
- },
1333
- {
1334
- id: "checkbox",
1335
- label: "Checkbox",
1336
- description: "Check or uncheck a boolean option.",
1337
- group: "input",
1338
- keywords: [
1339
- "checkbox",
1340
- "check",
1341
- "boolean",
1342
- "confirm",
1343
- "option"
1344
- ],
1345
- template: "<checkbox bind=\"{{bind:confirmed}}\" label=\"Confirm option\">"
1346
- },
1347
- {
1348
- id: "date",
1349
- label: "Date picker",
1350
- description: "Pick a date; the value stays empty until one is chosen.",
1351
- group: "input",
1352
- keywords: [
1353
- "date",
1354
- "calendar",
1355
- "picker",
1356
- "day"
1357
- ],
1358
- template: "<date bind=\"{{bind:date}}\" label=\"Pick a date\">"
1359
- },
1360
- {
1361
- id: "choices",
1362
- label: "Choice cards",
1363
- description: "Pick one option from a set of cards.",
1364
- group: "input",
1365
- keywords: [
1366
- "choices",
1367
- "options",
1368
- "cards",
1369
- "select",
1370
- "radio"
1371
- ],
1372
- template: "<choices bind=\"{{bind:plan}}\" label=\"Choose a plan\">\n<option value=\"basic\">Basic</option>\n<option value=\"pro\">Pro</option>\n</choices>"
1373
- },
1374
- {
1375
- id: "counter",
1376
- label: "Counter",
1377
- description: "Adjust an integer with plus and minus buttons, then reset it in one click.",
1378
- group: "action",
1379
- keywords: [
1380
- "counter",
1381
- "count",
1382
- "plus",
1383
- "minus",
1384
- "integer"
1385
- ],
1386
- template: "<counter bind=\"{{bind:count}}\" label=\"Count\" initial=\"0\" min=\"0\" max=\"99\">"
1387
- },
1388
- {
1389
- id: "timer",
1390
- label: "Countdown timer",
1391
- description: "Start, pause and reset a focus timer.",
1392
- group: "action",
1393
- keywords: [
1394
- "timer",
1395
- "countdown",
1396
- "focus",
1397
- "seconds",
1398
- "pause"
1399
- ],
1400
- template: "<timer bind=\"{{bind:remaining}}\" label=\"Focus timer\" duration=\"60\">"
1401
- },
1402
- {
1403
- id: "checklist",
1404
- label: "Checklist",
1405
- description: "Track completion with a checkable task list.",
1406
- group: "action",
1407
- keywords: [
1408
- "checklist",
1409
- "tasks",
1410
- "todo",
1411
- "check",
1412
- "done"
1413
- ],
1414
- template: "<checklist bind=\"{{bind:done}}\" label=\"Task checklist\">\n- [ ] First task\n- [ ] Second task\n- [ ] Third task\n</checklist>"
1415
- },
1416
- {
1417
- id: "progress",
1418
- label: "Progress bar",
1419
- description: "Show completion from 0 to 100.",
1420
- group: "action",
1421
- keywords: [
1422
- "progress",
1423
- "completion",
1424
- "bar",
1425
- "percent"
1426
- ],
1427
- template: "<progress label=\"Progress\" value=\"{{ 40 }}\">"
1428
- },
1429
- {
1430
- id: "panel",
1431
- label: "Parameter panel",
1432
- description: "Group controls in a panel with a restore-defaults button.",
1433
- group: "layout",
1434
- keywords: [
1435
- "panel",
1436
- "parameters",
1437
- "reset",
1438
- "form",
1439
- "group"
1440
- ],
1441
- template: "<panel title=\"Parameters\">\n{{selection:Sample content}}\n</panel>"
1442
- },
1443
- {
1444
- id: "card",
1445
- label: "Content card",
1446
- description: "Organize a self-contained piece of content in a card.",
1447
- group: "layout",
1448
- keywords: [
1449
- "card",
1450
- "container",
1451
- "content",
1452
- "section"
1453
- ],
1454
- template: "<card title=\"Content card\">\n{{selection:Sample content}}\n</card>"
1455
- },
1456
- {
1457
- id: "if",
1458
- label: "Conditional section",
1459
- description: "Show the contents only when a condition is true.",
1460
- group: "layout",
1461
- keywords: [
1462
- "if",
1463
- "condition",
1464
- "when",
1465
- "show",
1466
- "visible"
1467
- ],
1468
- template: "<if when=\"{{ {{select:true}} }}\">\n{{selection:Sample content}}\n</if>"
1469
- },
1470
- {
1471
- id: "tabs",
1472
- label: "Tabs",
1473
- description: "Split content across switchable tabs.",
1474
- group: "layout",
1475
- keywords: [
1476
- "tabs",
1477
- "switch",
1478
- "sections",
1479
- "groups"
1480
- ],
1481
- template: "<tabs label=\"Content tabs\">\n<tab label=\"Tab one\">\n{{selection:Sample content}}\n</tab>\n\n<tab label=\"Tab two\">\nContent for the second tab.\n</tab>\n</tabs>"
1482
- },
1483
- {
1484
- id: "accordion",
1485
- label: "Accordion",
1486
- description: "Put notes into items that expand and collapse.",
1487
- group: "layout",
1488
- keywords: [
1489
- "accordion",
1490
- "collapse",
1491
- "expand",
1492
- "faq",
1493
- "disclosure"
1494
- ],
1495
- template: "<accordion label=\"FAQ\">\n<disclosure label=\"Question one\">\n{{selection:Sample content}}\n</disclosure>\n\n<disclosure label=\"Question two\">\nDetails for the second item.\n</disclosure>\n</accordion>"
1496
- },
1497
- {
1498
- id: "chart",
1499
- label: "Bar chart",
1500
- description: "Turn a Markdown table into a bar chart.",
1501
- group: "data",
1502
- keywords: [
1503
- "chart",
1504
- "bar",
1505
- "graph",
1506
- "table",
1507
- "data"
1508
- ],
1509
- template: "<chart kind=\"bar\" title=\"Category comparison\" y-label=\"Value\">\n| Item | Value |\n| --- | ---: |\n| Item A | 20 |\n| Item B | 35 |\n</chart>"
1510
- },
1511
- {
1512
- id: "table",
1513
- label: "Enhanced table",
1514
- description: "A Markdown table with search, sorting and paging.",
1515
- group: "data",
1516
- keywords: [
1517
- "table",
1518
- "search",
1519
- "sort",
1520
- "paging",
1521
- "data"
1522
- ],
1523
- template: "<table label=\"Data table\" page-size=\"5\">\n| Name | Category | Value |\n| --- | --- | ---: |\n| Item A | Category one | 20 |\n| Item B | Category two | 35 |\n</table>"
1524
- },
1525
- {
1526
- id: "timeline",
1527
- label: "Timeline",
1528
- description: "Show task start times and durations in a table.",
1529
- group: "data",
1530
- keywords: [
1531
- "timeline",
1532
- "schedule",
1533
- "plan",
1534
- "duration",
1535
- "gantt"
1536
- ],
1537
- template: "<timeline title=\"Task timeline\">\n| Task | Start | Duration | Notes |\n| --- | ---: | ---: | --- |\n| Prepare | 0 | 10 | List the materials |\n| Execute | 10 | 20 | Complete the main work |\n| Review | 30 | 5 | Check the results |\n</timeline>"
1538
- },
1539
- {
1540
- id: "diagram",
1541
- label: "Interactive diagram",
1542
- description: "Show a flow with nodes and edges; click a node to read its notes.",
1543
- group: "data",
1544
- keywords: [
1545
- "diagram",
1546
- "flow",
1547
- "node",
1548
- "edge",
1549
- "graph"
1550
- ],
1551
- template: "<diagram label=\"Flow overview\">\n<node id=\"start\" label=\"Start\">\nWhere the flow begins.\n</node>\n\n<node id=\"process\" label=\"Process\">\nPerform the main step.\n</node>\n\n<node id=\"end\" label=\"End\">\nReview the result.\n</node>\n\n<edge from=\"start\" to=\"process\" label=\"Proceed\">\n<edge from=\"process\" to=\"end\" label=\"Complete\">\n</diagram>"
1552
- },
1553
- {
1554
- id: "plot",
1555
- label: "Function plot",
1556
- description: "Plot a function curve from a LaTeX formula.",
1557
- group: "data",
1558
- keywords: [
1559
- "plot",
1560
- "curve",
1561
- "function",
1562
- "formula",
1563
- "latex",
1564
- "math"
1565
- ],
1566
- template: "<plot min=\"-5\" max=\"5\" label=\"Function plot\">\n$$ y = x^2 $$\n</plot>"
1567
- },
1568
- {
1569
- id: "alert",
1570
- label: "Alert",
1571
- description: "Highlight info, success or warning messages with different tones.",
1572
- group: "hint",
1573
- keywords: [
1574
- "alert",
1575
- "notice",
1576
- "warning",
1577
- "info",
1578
- "message"
1579
- ],
1580
- template: "<alert tone=\"info\" title=\"Notice\">\n{{selection:Sample content}}\n</alert>"
1581
- },
1582
- {
1583
- id: "badge",
1584
- label: "Badge",
1585
- description: "Show a short status marker inside a sentence.",
1586
- group: "hint",
1587
- keywords: [
1588
- "badge",
1589
- "label",
1590
- "status",
1591
- "inline",
1592
- "tag"
1593
- ],
1594
- inline: !0,
1595
- template: "<badge tone=\"success\">Badge</badge>"
1596
- },
1597
- {
1598
- id: "tooltip",
1599
- label: "Tooltip",
1600
- description: "Attach a hover or focus note to a word in a sentence.",
1601
- group: "hint",
1602
- keywords: [
1603
- "tooltip",
1604
- "hint",
1605
- "hover",
1606
- "focus",
1607
- "inline"
1608
- ],
1609
- inline: !0,
1610
- template: "<tooltip text=\"Extra details appear here.\">Hover to view</tooltip>"
1611
- }
1612
- ], Ne = /\{\{bind:([^{}]+)\}\}/g, Pe = /[A-Za-z_][A-Za-z0-9_]*/g;
1613
- function Fe(e, t) {
1614
- let n = [...e];
1615
- for (let e of t) {
1616
- let t = e.toLowerCase();
1617
- n.some((e) => e.toLowerCase() === t) || n.push(e);
1618
- }
1619
- return n;
1620
- }
1621
- var Ie = je.map((e) => ({
1622
- ...e,
1623
- label: y.zh.groups[e.id]
1624
- })), Le = Me.map((e) => ({
1625
- ...e,
1626
- keywords: Fe(e.keywords, y.zh.components[e.id]?.keywords ?? [])
1627
- })), Re = Me.map((e) => {
1628
- let t = y.zh.components[e.id];
1629
- return t ? {
1630
- ...e,
1631
- label: t.label,
1632
- description: t.description,
1633
- keywords: Fe(e.keywords, t.keywords),
1634
- template: t.template
1635
- } : e;
1636
- });
1637
- function ze(e = "en") {
1638
- return e === "zh" ? {
1639
- groups: Ie,
1640
- components: Re
1641
- } : {
1642
- groups: je,
1643
- components: Le
1644
- };
1645
- }
1646
- function Be(e) {
1647
- return new Set(e.match(Pe) ?? []);
1648
- }
1649
- function Ve(e) {
1650
- let t = e.trim().replace(/[^A-Za-z0-9_]/g, "_");
1651
- return t ? /^[0-9]/.test(t) ? `_${t}` : t : "value";
1652
- }
1653
- function He(e, t) {
1654
- if (!t.has(e)) return e;
1655
- let n = 2;
1656
- for (; t.has(`${e}${n}`);) n += 1;
1657
- return `${e}${n}`;
1658
- }
1659
- function Ue(e, t, n) {
1660
- let r = Be(t), i = /* @__PURE__ */ new Map();
1661
- return e.template.replace(Ne, (e, t) => {
1662
- let n = t.trim(), a = i.get(n);
1663
- if (a) return a;
1664
- let o = He(Ve(n), r);
1665
- return r.add(o), i.set(n, o), o;
1666
- });
1667
- }
1668
- // src/editor/editor-toolbar.tsx
1669
- var We = /* @__PURE__ */ "😀.😄.😁.😊.🙂.😉.😍.🤔.😎.😅.😂.🥳.👍.👎.👏.🙏.💡.✅.❌.⚠️.🔥.⭐.🎉.❤️.💬.📌.🚀.📈.📉.🧩.⚙️.🔍.📎.🗂️.🕒.✨".split("."), Ge = [
1670
- {
1671
- level: 0,
1672
- sample: "¶"
1673
- },
1674
- {
1675
- level: 1,
1676
- sample: "H1"
1677
- },
1678
- {
1679
- level: 2,
1680
- sample: "H2"
1681
- },
1682
- {
1683
- level: 3,
1684
- sample: "H3"
1685
- },
1686
- {
1687
- level: 4,
1688
- sample: "H4"
1689
- },
1690
- {
1691
- level: 5,
1692
- sample: "H5"
1693
- },
1694
- {
1695
- level: 6,
1696
- sample: "H6"
1697
- }
1698
- ], Ke = [
1699
- {
1700
- type: "bullet",
1701
- icon: "bulletList",
1702
- command: H
1703
- },
1704
- {
1705
- type: "ordered",
1706
- icon: "orderedList",
1707
- command: U
1708
- },
1709
- {
1710
- type: "task",
1711
- icon: "taskList",
1712
- command: W
1713
- }
1714
- ], qe = [{
1715
- labelKey: "decreaseIndent",
1716
- icon: "outdent",
1717
- command: q
1718
- }, {
1719
- labelKey: "increaseIndent",
1720
- icon: "indent",
1721
- command: de
1722
- }], Je = [
1723
- {
1724
- labelKey: "image",
1725
- icon: "image",
1726
- command: pe
1727
- },
1728
- {
1729
- labelKey: "table",
1730
- icon: "table",
1731
- command: ve
1732
- },
1733
- {
1734
- labelKey: "divider",
1735
- icon: "divider",
1736
- command: ye
1737
- },
1738
- {
1739
- labelKey: "codeBlock",
1740
- icon: "codeBlock",
1741
- command: me
1742
- },
1743
- {
1744
- labelKey: "inlineCode",
1745
- icon: "inlineCode",
1746
- command: ce
1747
- },
1748
- {
1749
- labelKey: "strikethrough",
1750
- icon: "strike",
1751
- command: oe
1752
- },
1753
- {
1754
- labelKey: "quote",
1755
- icon: "quote",
1756
- command: G
1757
- }
1758
- ], Ye = {
1759
- heading: 200,
1760
- list: 208,
1761
- insert: 216,
1762
- more: 188
1763
- }, Xe = {
1764
- headingLevel: 0,
1765
- bold: !1,
1766
- italic: !1,
1767
- strike: !1,
1768
- inlineCode: !1,
1769
- list: null,
1770
- quote: !1
1771
- }, Ze = {
1772
- smile: /* @__PURE__ */ m(f, { children: [
1773
- /* @__PURE__ */ p("circle", {
1774
- cx: "12",
1775
- cy: "12",
1776
- r: "8.4"
1777
- }),
1778
- /* @__PURE__ */ p("path", { d: "M8.6 14.1c.9 1.4 2 2.1 3.4 2.1s2.5-.7 3.4-2.1" }),
1779
- /* @__PURE__ */ p("path", { d: "M9.2 9.7h.01M14.8 9.7h.01" })
1780
- ] }),
1781
- link: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M10.1 13.9a3.8 3.8 0 0 0 5.4 0l2.4-2.4a3.8 3.8 0 0 0-5.4-5.4l-1.2 1.2" }), /* @__PURE__ */ p("path", { d: "M13.9 10.1a3.8 3.8 0 0 0-5.4 0l-2.4 2.4a3.8 3.8 0 0 0 5.4 5.4l1.2-1.2" })] }),
1782
- bulletList: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M9.5 6.5H20M9.5 12H20M9.5 17.5H20" }), /* @__PURE__ */ p("path", { d: "M4.5 6.5h.01M4.5 12h.01M4.5 17.5h.01" })] }),
1783
- orderedList: /* @__PURE__ */ m(f, { children: [
1784
- /* @__PURE__ */ p("path", { d: "M10.5 6.5H20M10.5 12H20M10.5 17.5H20" }),
1785
- /* @__PURE__ */ p("text", {
1786
- x: "2.9",
1787
- y: "8.6",
1788
- fill: "currentColor",
1789
- stroke: "none",
1790
- fontSize: "6.8",
1791
- fontWeight: "650",
1792
- fontFamily: "ui-sans-serif, system-ui, sans-serif",
1793
- children: "1"
1794
- }),
1795
- /* @__PURE__ */ p("text", {
1796
- x: "2.9",
1797
- y: "14.1",
1798
- fill: "currentColor",
1799
- stroke: "none",
1800
- fontSize: "6.8",
1801
- fontWeight: "650",
1802
- fontFamily: "ui-sans-serif, system-ui, sans-serif",
1803
- children: "2"
1804
- }),
1805
- /* @__PURE__ */ p("text", {
1806
- x: "2.9",
1807
- y: "19.6",
1808
- fill: "currentColor",
1809
- stroke: "none",
1810
- fontSize: "6.8",
1811
- fontWeight: "650",
1812
- fontFamily: "ui-sans-serif, system-ui, sans-serif",
1813
- children: "3"
1814
- })
1815
- ] }),
1816
- taskList: /* @__PURE__ */ m(f, { children: [
1817
- /* @__PURE__ */ p("rect", {
1818
- x: "3",
1819
- y: "4",
1820
- width: "5.6",
1821
- height: "5.6",
1822
- rx: "1.2"
1823
- }),
1824
- /* @__PURE__ */ p("path", { d: "M4.5 6.8l1 1 1.6-1.9" }),
1825
- /* @__PURE__ */ p("path", { d: "M12 6.8h8.4" }),
1826
- /* @__PURE__ */ p("path", {
1827
- d: "M3.4 13.9h5M3.4 17.4h5",
1828
- opacity: ".55"
1829
- }),
1830
- /* @__PURE__ */ p("path", {
1831
- d: "M12 13.9h8.4M12 17.4h8.4",
1832
- opacity: ".55"
1833
- })
1834
- ] }),
1835
- outdent: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M10 6.5H20M10 12H20M10 17.5H20" }), /* @__PURE__ */ p("path", { d: "M7.2 9l-3.4 3 3.4 3M4.2 12h7" })] }),
1836
- indent: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M10 6.5H20M10 12H20M10 17.5H20" }), /* @__PURE__ */ p("path", { d: "M3.8 9l3.4 3-3.4 3M3.2 12h7" })] }),
1837
- quote: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M10 8.2c-2.4.7-3.8 2.4-3.8 5.2V17H10v-4.2H7.5c0-1.5.7-2.6 2.5-3.2z" }), /* @__PURE__ */ p("path", { d: "M18.5 8.2c-2.4.7-3.8 2.4-3.8 5.2V17h3.8v-4.2h-2.5c0-1.5.7-2.6 2.5-3.2z" })] }),
1838
- divider: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M4 12h16" }), /* @__PURE__ */ p("path", {
1839
- d: "M7 7.5h10M7 16.5h10",
1840
- opacity: ".55"
1841
- })] }),
1842
- codeBlock: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("rect", {
1843
- x: "3",
1844
- y: "4.5",
1845
- width: "18",
1846
- height: "15",
1847
- rx: "2.4"
1848
- }), /* @__PURE__ */ p("path", { d: "M9.8 9.3l-2.7 2.7 2.7 2.7M14.2 9.3l2.7 2.7-2.7 2.7" })] }),
1849
- inlineCode: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M8.8 8.5L5 12l3.8 3.5M15.2 8.5L19 12l-3.8 3.5" }), /* @__PURE__ */ p("path", {
1850
- d: "M13.6 6.5l-3.2 11",
1851
- opacity: ".45"
1852
- })] }),
1853
- strike: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M4 12h16" }), /* @__PURE__ */ p("path", { d: "M16.7 7.4c-.7-1.2-2-1.9-3.7-1.9-2.3 0-3.9 1.1-3.9 2.8 0 1.5 1.1 2.3 3.7 3 2.8.8 4.2 1.7 4.2 3.5 0 2-1.7 3.2-4.3 3.2-2.1 0-3.6-.8-4.3-2.2" })] }),
1854
- image: /* @__PURE__ */ m(f, { children: [
1855
- /* @__PURE__ */ p("rect", {
1856
- x: "3",
1857
- y: "4.5",
1858
- width: "18",
1859
- height: "15",
1860
- rx: "2.4"
1861
- }),
1862
- /* @__PURE__ */ p("circle", {
1863
- cx: "8.4",
1864
- cy: "9.4",
1865
- r: "1.35"
1866
- }),
1867
- /* @__PURE__ */ p("path", { d: "M4.6 17.4l4.9-4.9 3.5 3.5 2.7-2.7 3.7 3.7" })
1868
- ] }),
1869
- table: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("rect", {
1870
- x: "3",
1871
- y: "4.5",
1872
- width: "18",
1873
- height: "15",
1874
- rx: "2.4"
1875
- }), /* @__PURE__ */ p("path", { d: "M3.4 9.7h17.2M9.7 9.2v10.2M14.9 9.2v10.2M9.2 14.5h11.4" })] }),
1876
- undo: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M5 12h9.2a4.3 4.3 0 0 1 0 8.6h-1.8" }), /* @__PURE__ */ p("path", { d: "M8.8 8.2L5 12l3.8 3.8" })] }),
1877
- redo: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M19 12h-9.2a4.3 4.3 0 0 0 0 8.6h1.8" }), /* @__PURE__ */ p("path", { d: "M15.2 8.2L19 12l-3.8 3.8" })] }),
1878
- download: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M12 4v10.5M8 10.8l4 3.7 4-3.7" }), /* @__PURE__ */ p("path", { d: "M4.5 17.5v2h15v-2" })] }),
1879
- chevron: /* @__PURE__ */ p("path", { d: "M7.5 9.7l4.5 4.5 4.5-4.5" }),
1880
- sparkle: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M11.2 4.2l1.5 4.3 4.3 1.5-4.3 1.5-1.5 4.3-1.5-4.3-4.3-1.5 4.3-1.5z" }), /* @__PURE__ */ p("path", { d: "M18.3 15.4v3.4M16.6 17.1h3.4" })] }),
1881
- search: /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("circle", {
1882
- cx: "10.6",
1883
- cy: "10.6",
1884
- r: "5.6"
1885
- }), /* @__PURE__ */ p("path", { d: "M14.8 14.8L20 20" })] }),
1886
- plus: /* @__PURE__ */ p("path", { d: "M12 5.2v13.6M5.2 12h13.6" }),
1887
- more: /* @__PURE__ */ m(f, { children: [
1888
- /* @__PURE__ */ p("circle", {
1889
- cx: "5.5",
1890
- cy: "12",
1891
- r: "1.1",
1892
- fill: "currentColor",
1893
- stroke: "none"
1894
- }),
1895
- /* @__PURE__ */ p("circle", {
1896
- cx: "12",
1897
- cy: "12",
1898
- r: "1.1",
1899
- fill: "currentColor",
1900
- stroke: "none"
1901
- }),
1902
- /* @__PURE__ */ p("circle", {
1903
- cx: "18.5",
1904
- cy: "12",
1905
- r: "1.1",
1906
- fill: "currentColor",
1907
- stroke: "none"
1908
- })
1909
- ] }),
1910
- close: /* @__PURE__ */ p("path", { d: "M6.5 6.5l11 11M17.5 6.5l-11 11" })
1911
- };
1912
- function X({ name: e, className: t }) {
1913
- return /* @__PURE__ */ p("svg", {
1914
- className: t ? `editor-toolbar-icon ${t}` : "editor-toolbar-icon",
1915
- viewBox: "0 0 24 24",
1916
- width: "18",
1917
- height: "18",
1918
- fill: "none",
1919
- stroke: "currentColor",
1920
- strokeWidth: "1.7",
1921
- strokeLinecap: "round",
1922
- strokeLinejoin: "round",
1923
- "aria-hidden": "true",
1924
- focusable: "false",
1925
- children: Ze[e]
1926
- });
1927
- }
1928
- function Z(e) {
1929
- e.preventDefault();
1930
- }
1931
- function Q({ toolbarId: e, label: t, tabStop: n, onFocus: r, onClick: i, children: a, className: o, disabled: s, expanded: c, popup: l, controls: u, pressed: d, active: f, onKeyDown: m }) {
1932
- return /* @__PURE__ */ p("button", {
1933
- type: "button",
1934
- "data-toolbar-item": "true",
1935
- "data-toolbar-id": e,
1936
- "data-tooltip": t,
1937
- className: `editor-toolbar-button${o ? ` ${o}` : ""}` + (f ? " is-active" : ""),
1938
- "aria-label": t,
1939
- "aria-pressed": d,
1940
- "aria-expanded": c,
1941
- "aria-haspopup": l,
1942
- "aria-controls": u,
1943
- disabled: s,
1944
- tabIndex: n ? 0 : -1,
1945
- onFocus: r,
1946
- onMouseDown: l ? void 0 : Z,
1947
- onClick: i,
1948
- onKeyDown: m,
1949
- children: a
1950
- });
1951
- }
1952
- function Qe(e) {
1953
- let t = e.current, n = t?.value ?? "", r = Math.max(0, Math.min(t?.selectionStart ?? 0, n.length)), i = Math.max(r, Math.min(t?.selectionEnd ?? 0, n.length));
1954
- return {
1955
- value: n,
1956
- selection: {
1957
- start: r,
1958
- end: i
1959
- },
1960
- selectedText: n.slice(r, i)
1961
- };
1962
- }
1963
- function $e(e, t) {
1964
- return !t || e.label.toLowerCase().includes(t) || e.description.toLowerCase().includes(t) || e.keywords.some((e) => e.toLowerCase().includes(t));
1965
- }
1966
- function et(e, t) {
1967
- return e.headingLevel === t.headingLevel && e.bold === t.bold && e.italic === t.italic && e.strike === t.strike && e.inlineCode === t.inlineCode && e.list === t.list && e.quote === t.quote;
1968
- }
1969
- function tt(e) {
1970
- return e ? Array.from(e.querySelectorAll("[data-toolbar-item]")).filter((e) => !e.disabled && e.getClientRects().length > 0) : [];
1971
- }
1972
- function nt(e) {
1973
- return e ? Array.from(e.querySelectorAll("[role=\"menuitem\"], [role=\"menuitemradio\"]")).filter((e) => !e.disabled && e.getClientRects().length > 0) : [];
1974
- }
1975
- function rt(e, t) {
1976
- let n = nt(t);
1977
- if (n.length === 0) return;
1978
- let r = document.activeElement, i = r ? n.indexOf(r) : -1, a = i;
1979
- switch (e.key) {
1980
- case "ArrowDown":
1981
- a = i < 0 ? 0 : (i + 1) % n.length;
1982
- break;
1983
- case "ArrowUp":
1984
- a = i < 0 ? n.length - 1 : (i - 1 + n.length) % n.length;
1985
- break;
1986
- case "Home":
1987
- a = 0;
1988
- break;
1989
- case "End":
1990
- a = n.length - 1;
1991
- break;
1992
- default: return;
1993
- }
1994
- e.preventDefault(), n[a]?.focus();
1995
- }
1996
- function it(e, t) {
1997
- if (!t) return;
1998
- let n = Array.from(t.querySelectorAll(".editor-toolbar-emoji"));
1999
- if (n.length === 0) return;
2000
- let r = document.activeElement, i = r ? n.indexOf(r) : -1;
2001
- if (i < 0) return;
2002
- let a = i;
2003
- switch (e.key) {
2004
- case "ArrowRight":
2005
- a = Math.min(i + 1, n.length - 1);
2006
- break;
2007
- case "ArrowLeft":
2008
- a = Math.max(i - 1, 0);
2009
- break;
2010
- case "ArrowDown":
2011
- a = Math.min(i + 8, n.length - 1);
2012
- break;
2013
- case "ArrowUp":
2014
- a = Math.max(i - 8, 0);
2015
- break;
2016
- case "Home":
2017
- a = 0;
2018
- break;
2019
- case "End":
2020
- a = n.length - 1;
2021
- break;
2022
- default: return;
2023
- }
2024
- e.preventDefault(), n[a]?.focus();
2025
- }
2026
- function at({ editorRef: e, onEdit: t, onUndo: n, onRedo: i, canUndo: s, canRedo: f, onExport: h, showExport: ee = !1, disabled: g = !1 }) {
2027
- let te = u(null), _ = u(null), v = u(null), ne = u(null), re = u(null), y = u(null), [b, x] = d(null), [S, C] = d("heading"), [w, T] = d(""), [E, D] = d(Xe), [O, k] = d(null), A = o(), oe = `${A}-emoji-menu`, N = `${A}-heading-menu`, P = `${A}-list-menu`, se = `${A}-insert-menu`, ce = `${A}-more-menu`, le = `${A}-native-menu`, I = ae(), L = ie[I], R = l(() => ze(I), [I]), z = Ge.map((e) => ({
2028
- ...e,
2029
- label: L.headingLabels[e.level]
2030
- })), B = Ke.map((e) => ({
2031
- ...e,
2032
- label: L.listLabels[e.type]
2033
- })), ue = qe.map((e) => ({
2034
- ...e,
2035
- label: L[e.labelKey]
2036
- })), V = Je.map((e) => ({
2037
- ...e,
2038
- label: L.insertItems[e.labelKey]
2039
- })), H = l(() => {
2040
- let e = w.trim().toLowerCase();
2041
- return R.groups.map((t) => ({
2042
- group: t,
2043
- components: R.components.filter((n) => n.group === t.id && $e(n, e))
2044
- })).filter((e) => e.components.length > 0);
2045
- }, [R, w]), U = r(() => {
2046
- let t = e.current;
2047
- if (!t) {
2048
- D(Xe);
2049
- return;
2050
- }
2051
- let n = Ae(t.value, {
2052
- start: t.selectionStart,
2053
- end: t.selectionEnd
2054
- });
2055
- D((e) => et(e, n) ? e : n);
2056
- }, [e]), W = r(() => {
2057
- y.current !== null && window.cancelAnimationFrame(y.current), y.current = window.requestAnimationFrame(() => {
2058
- y.current = null, U();
2059
- });
2060
- }, [U]);
2061
- a(() => {
2062
- let t = e.current;
2063
- if (!t) return;
2064
- let n = () => U(), r = [
2065
- "select",
2066
- "keyup",
2067
- "click",
2068
- "input",
2069
- "focus"
2070
- ];
2071
- for (let e of r) t.addEventListener(e, n);
2072
- let i = () => {
2073
- document.activeElement === t && U();
2074
- };
2075
- return document.addEventListener("selectionchange", i), U(), () => {
2076
- for (let e of r) t.removeEventListener(e, n);
2077
- document.removeEventListener("selectionchange", i);
2078
- };
2079
- }, [e, U]), a(() => () => {
2080
- y.current !== null && window.cancelAnimationFrame(y.current);
2081
- }, []);
2082
- let G = r((e) => {
2083
- let t = e === "emoji" ? "insert" : e === "native" ? "components" : e;
2084
- return te.current?.querySelector(`[data-toolbar-id="${t}"]`) ?? null;
2085
- }, []);
2086
- c(() => {
2087
- if (!b || b === "native" || b === "emoji") {
2088
- k(null);
2089
- return;
2090
- }
2091
- let e = window.matchMedia("(max-width: 640px)"), t = () => {
2092
- if (!e.matches) {
2093
- k(null);
2094
- return;
2095
- }
2096
- let t = G(b);
2097
- if (!t) return;
2098
- let n = t.getBoundingClientRect(), r = Ye[b] ?? 216, i = n.top - 6 - 8, a = window.innerHeight - n.bottom - 6 - 8, o = {};
2099
- i >= a ? (o.bottom = window.innerHeight - n.top + 6, o.top = "auto", o.maxHeight = Math.max(80, i)) : (o.top = n.bottom + 6, o.bottom = "auto", o.maxHeight = Math.max(80, a)), b === "heading" || b === "list" ? (o.left = Math.min(Math.max(8, n.left), window.innerWidth - 8 - r), o.right = "auto") : (o.right = Math.min(Math.max(8, window.innerWidth - n.right), window.innerWidth - 8 - r), o.left = "auto"), k(o);
2100
- };
2101
- return t(), e.addEventListener("change", t), window.addEventListener("resize", t), window.addEventListener("scroll", t, !0), () => {
2102
- e.removeEventListener("change", t), window.removeEventListener("resize", t), window.removeEventListener("scroll", t, !0);
2103
- };
2104
- }, [b, G]), a(() => {
2105
- if (!b) return;
2106
- let e = (e) => {
2107
- te.current && !te.current.contains(e.target) && x(null);
2108
- }, t = (e) => {
2109
- if (e.key !== "Escape") return;
2110
- e.preventDefault(), e.stopPropagation();
2111
- let t = b;
2112
- x(null), G(t)?.focus();
2113
- };
2114
- return document.addEventListener("pointerdown", e, !0), document.addEventListener("keydown", t, !0), () => {
2115
- document.removeEventListener("pointerdown", e, !0), document.removeEventListener("keydown", t, !0);
2116
- };
2117
- }, [b, G]), a(() => {
2118
- if (!b) return;
2119
- let e = re.current;
2120
- re.current = null;
2121
- let t = window.requestAnimationFrame(() => {
2122
- let t = _.current;
2123
- if (e) {
2124
- let n = nt(t);
2125
- (e === "first" ? n[0] : n[n.length - 1])?.focus();
2126
- } else b === "native" ? v.current?.focus() : b === "emoji" && nt(t)[0]?.focus();
2127
- });
2128
- return () => window.cancelAnimationFrame(t);
2129
- }, [b]);
2130
- let de = r(() => {
2131
- let e = tt(te.current);
2132
- e.length !== 0 && C((t) => e.some((e) => e.dataset.toolbarId === t) ? t : e[0]?.dataset.toolbarId ?? "heading");
2133
- }, []);
2134
- a(() => (de(), window.addEventListener("resize", de), () => window.removeEventListener("resize", de)), [de]), a(() => {
2135
- de();
2136
- }, [
2137
- b,
2138
- s,
2139
- f,
2140
- de
2141
- ]);
2142
- let K = r((e) => {
2143
- g || (x(null), t(e), W());
2144
- }, [
2145
- g,
2146
- t,
2147
- W
2148
- ]), q = (t) => {
2149
- if (g) return;
2150
- let { value: n, selection: r } = Qe(e);
2151
- K(t(n, r, I));
2152
- }, pe = (t) => {
2153
- if (g) return;
2154
- let { value: n, selection: r } = Qe(e);
2155
- K(F(n, r, t));
2156
- }, me = (t) => {
2157
- if (g) return;
2158
- let { value: n, selection: r } = Qe(e);
2159
- K(be(n, r, t));
2160
- }, he = (t) => {
2161
- if (g) return;
2162
- let { value: n, selection: r, selectedText: i } = Qe(e), a = Ue(t, n, i);
2163
- K(Ce(n, r, a, { block: !t.inline }));
2164
- }, ge = () => {
2165
- g || (x(null), n(), W());
2166
- }, _e = () => {
2167
- g || (x(null), i(), W());
2168
- }, ve = () => {
2169
- x(null), ee && h?.();
2170
- }, ye = (e) => {
2171
- x((t) => t === e ? null : e), e === "native" && T("");
2172
- }, xe = (e, t, n) => {
2173
- if (t.preventDefault(), e === "native" && T(""), b === e) {
2174
- let e = nt(_.current);
2175
- (n === "first" ? e[0] : e[e.length - 1])?.focus();
2176
- } else re.current = n, x(e);
2177
- }, Se = (e, t) => {
2178
- (t.key === "ArrowDown" || t.key === "ArrowUp") && xe(e, t, t.key === "ArrowDown" ? "first" : "last");
2179
- }, we = (e) => {
2180
- if (e.altKey || e.ctrlKey || e.metaKey || ![
2181
- "ArrowLeft",
2182
- "ArrowRight",
2183
- "Home",
2184
- "End"
2185
- ].includes(e.key)) return;
2186
- let t = e.target;
2187
- if (!(t instanceof HTMLElement)) return;
2188
- let n = t.closest("[data-toolbar-item]");
2189
- if (!n || n !== t) return;
2190
- let r = tt(te.current), i = r.indexOf(n);
2191
- if (i < 0) return;
2192
- let a = i;
2193
- switch (e.key) {
2194
- case "ArrowLeft":
2195
- a = (i - 1 + r.length) % r.length;
2196
- break;
2197
- case "ArrowRight":
2198
- a = (i + 1) % r.length;
2199
- break;
2200
- case "Home":
2201
- a = 0;
2202
- break;
2203
- case "End":
2204
- a = r.length - 1;
2205
- break;
2206
- default: return;
2207
- }
2208
- e.preventDefault(), b && x(null), r[a]?.focus();
2209
- }, Te = () => {
2210
- x(null), G("native")?.focus();
2211
- }, Ee = z.find((e) => e.level === E.headingLevel)?.label ?? L.headingLabels[0], De = E.headingLevel === 0 ? "¶" : `H${E.headingLevel}`, Oe = L.headingLevelLabel(Ee), J = E.list ? L.listLabels[E.list] : null, Y = J ? L.listLabelWithType(J) : L.listLabel, ke = E.list === "ordered" ? "orderedList" : E.list === "task" ? "taskList" : "bulletList";
2212
- return /* @__PURE__ */ m("div", {
2213
- className: `editor-toolbar${b ? " is-menu-open" : ""}`,
2214
- role: "toolbar",
2215
- "aria-label": L.toolbarLabel,
2216
- "aria-orientation": "horizontal",
2217
- "aria-disabled": g || void 0,
2218
- ref: te,
2219
- onKeyDown: we,
2220
- children: [
2221
- /* @__PURE__ */ m("div", {
2222
- className: "editor-toolbar-slot",
2223
- children: [/* @__PURE__ */ m(Q, {
2224
- toolbarId: "heading",
2225
- label: Oe,
2226
- className: "editor-toolbar-heading-trigger",
2227
- active: E.headingLevel > 0,
2228
- tabStop: S === "heading",
2229
- onFocus: () => C("heading"),
2230
- disabled: g,
2231
- popup: "menu",
2232
- expanded: b === "heading",
2233
- controls: N,
2234
- onClick: () => ye("heading"),
2235
- onKeyDown: (e) => Se("heading", e),
2236
- children: [
2237
- /* @__PURE__ */ p("span", {
2238
- className: "editor-toolbar-heading-label editor-toolbar-heading-label-full",
2239
- children: Ee
2240
- }),
2241
- /* @__PURE__ */ p("span", {
2242
- className: "editor-toolbar-heading-label editor-toolbar-heading-label-compact",
2243
- "aria-hidden": "true",
2244
- children: De
2245
- }),
2246
- /* @__PURE__ */ p(X, {
2247
- name: "chevron",
2248
- className: "editor-toolbar-chevron"
2249
- })
2250
- ]
2251
- }), b === "heading" ? /* @__PURE__ */ p("div", {
2252
- id: N,
2253
- ref: _,
2254
- className: "editor-toolbar-popover editor-toolbar-heading-menu",
2255
- role: "menu",
2256
- "aria-label": L.headingMenuLabel,
2257
- style: O ?? void 0,
2258
- onKeyDown: (e) => rt(e, _.current),
2259
- children: z.map((e) => /* @__PURE__ */ m("button", {
2260
- type: "button",
2261
- role: "menuitemradio",
2262
- "aria-checked": E.headingLevel === e.level,
2263
- tabIndex: -1,
2264
- className: "editor-toolbar-menu-item editor-toolbar-heading-item",
2265
- onMouseDown: Z,
2266
- onClick: () => pe(e.level),
2267
- children: [/* @__PURE__ */ p("span", {
2268
- className: `editor-toolbar-heading-sample is-level-${e.level}`,
2269
- "aria-hidden": "true",
2270
- children: e.sample
2271
- }), /* @__PURE__ */ p("span", { children: e.label })]
2272
- }, e.level))
2273
- }) : null]
2274
- }),
2275
- /* @__PURE__ */ p(Q, {
2276
- toolbarId: "bold",
2277
- label: L.bold,
2278
- tabStop: S === "bold",
2279
- onFocus: () => C("bold"),
2280
- disabled: g,
2281
- onClick: () => q(j),
2282
- pressed: E.bold,
2283
- active: E.bold,
2284
- children: /* @__PURE__ */ p("span", {
2285
- className: "editor-toolbar-glyph is-bold",
2286
- "aria-hidden": "true",
2287
- children: "B"
2288
- })
2289
- }),
2290
- /* @__PURE__ */ p(Q, {
2291
- toolbarId: "italic",
2292
- label: L.italic,
2293
- tabStop: S === "italic",
2294
- onFocus: () => C("italic"),
2295
- disabled: g,
2296
- onClick: () => q(M),
2297
- pressed: E.italic,
2298
- active: E.italic,
2299
- children: /* @__PURE__ */ p("span", {
2300
- className: "editor-toolbar-glyph is-italic",
2301
- "aria-hidden": "true",
2302
- children: "I"
2303
- })
2304
- }),
2305
- /* @__PURE__ */ m("div", {
2306
- className: "editor-toolbar-slot",
2307
- children: [/* @__PURE__ */ m(Q, {
2308
- toolbarId: "list",
2309
- label: Y,
2310
- className: "editor-toolbar-list-trigger",
2311
- tabStop: S === "list",
2312
- onFocus: () => C("list"),
2313
- disabled: g,
2314
- popup: "menu",
2315
- expanded: b === "list",
2316
- controls: P,
2317
- active: E.list !== null,
2318
- onClick: () => ye("list"),
2319
- onKeyDown: (e) => Se("list", e),
2320
- children: [/* @__PURE__ */ p(X, { name: ke }), /* @__PURE__ */ p(X, {
2321
- name: "chevron",
2322
- className: "editor-toolbar-chevron"
2323
- })]
2324
- }), b === "list" ? /* @__PURE__ */ m("div", {
2325
- id: P,
2326
- ref: _,
2327
- className: "editor-toolbar-popover editor-toolbar-list-menu",
2328
- role: "menu",
2329
- "aria-label": L.listMenuLabel,
2330
- style: O ?? void 0,
2331
- onKeyDown: (e) => rt(e, _.current),
2332
- children: [
2333
- B.map((e) => /* @__PURE__ */ m("button", {
2334
- type: "button",
2335
- role: "menuitemradio",
2336
- "aria-checked": E.list === e.type,
2337
- tabIndex: -1,
2338
- className: "editor-toolbar-menu-item editor-toolbar-list-item",
2339
- onMouseDown: Z,
2340
- onClick: () => q(e.command),
2341
- children: [/* @__PURE__ */ p(X, {
2342
- name: e.icon,
2343
- className: "editor-toolbar-menu-icon"
2344
- }), /* @__PURE__ */ p("span", { children: e.label })]
2345
- }, e.type)),
2346
- /* @__PURE__ */ p("div", {
2347
- className: "editor-toolbar-menu-divider",
2348
- role: "separator"
2349
- }),
2350
- ue.map((e) => /* @__PURE__ */ m("button", {
2351
- type: "button",
2352
- role: "menuitem",
2353
- tabIndex: -1,
2354
- className: "editor-toolbar-menu-item editor-toolbar-list-item",
2355
- onMouseDown: Z,
2356
- onClick: () => q(e.command),
2357
- children: [/* @__PURE__ */ p(X, {
2358
- name: e.icon,
2359
- className: "editor-toolbar-menu-icon"
2360
- }), /* @__PURE__ */ p("span", { children: e.label })]
2361
- }, e.labelKey))
2362
- ]
2363
- }) : null]
2364
- }),
2365
- /* @__PURE__ */ p(Q, {
2366
- toolbarId: "link",
2367
- label: L.insertLink,
2368
- className: "editor-toolbar-desktop-only",
2369
- tabStop: S === "link",
2370
- onFocus: () => C("link"),
2371
- disabled: g,
2372
- onClick: () => q(fe),
2373
- children: /* @__PURE__ */ p(X, { name: "link" })
2374
- }),
2375
- /* @__PURE__ */ m("div", {
2376
- className: "editor-toolbar-slot",
2377
- children: [
2378
- /* @__PURE__ */ m(Q, {
2379
- toolbarId: "insert",
2380
- label: L.insert,
2381
- className: "editor-toolbar-insert-trigger",
2382
- tabStop: S === "insert",
2383
- onFocus: () => C("insert"),
2384
- disabled: g,
2385
- popup: "menu",
2386
- expanded: b === "insert" || b === "emoji",
2387
- controls: b === "emoji" ? oe : se,
2388
- onClick: () => ye("insert"),
2389
- onKeyDown: (e) => Se("insert", e),
2390
- children: [
2391
- /* @__PURE__ */ p(X, { name: "plus" }),
2392
- /* @__PURE__ */ p("span", {
2393
- className: "editor-toolbar-insert-label",
2394
- children: L.insert
2395
- }),
2396
- /* @__PURE__ */ p(X, {
2397
- name: "chevron",
2398
- className: "editor-toolbar-chevron"
2399
- })
2400
- ]
2401
- }),
2402
- b === "insert" ? /* @__PURE__ */ m("div", {
2403
- id: se,
2404
- ref: _,
2405
- className: "editor-toolbar-popover editor-toolbar-insert-menu",
2406
- role: "menu",
2407
- "aria-label": L.insertMenuLabel,
2408
- style: O ?? void 0,
2409
- onKeyDown: (e) => rt(e, _.current),
2410
- children: [V.map((e) => /* @__PURE__ */ m("button", {
2411
- type: "button",
2412
- role: "menuitem",
2413
- tabIndex: -1,
2414
- className: "editor-toolbar-menu-item editor-toolbar-insert-item",
2415
- onMouseDown: Z,
2416
- onClick: () => q(e.command),
2417
- children: [/* @__PURE__ */ p(X, {
2418
- name: e.icon,
2419
- className: "editor-toolbar-menu-icon"
2420
- }), /* @__PURE__ */ p("span", { children: e.label })]
2421
- }, e.labelKey)), /* @__PURE__ */ m("button", {
2422
- type: "button",
2423
- role: "menuitem",
2424
- tabIndex: -1,
2425
- className: "editor-toolbar-menu-item editor-toolbar-insert-item",
2426
- onMouseDown: Z,
2427
- onClick: () => x("emoji"),
2428
- children: [/* @__PURE__ */ p(X, {
2429
- name: "smile",
2430
- className: "editor-toolbar-menu-icon"
2431
- }), /* @__PURE__ */ p("span", { children: L.emoji })]
2432
- })]
2433
- }) : null,
2434
- b === "emoji" ? /* @__PURE__ */ p("div", {
2435
- id: oe,
2436
- ref: _,
2437
- className: "editor-toolbar-popover editor-toolbar-emoji-menu",
2438
- role: "menu",
2439
- "aria-label": L.insertEmojiMenuLabel,
2440
- onKeyDown: (e) => it(e, ne.current),
2441
- children: /* @__PURE__ */ p("div", {
2442
- className: "editor-toolbar-emoji-grid",
2443
- ref: ne,
2444
- children: We.map((e) => /* @__PURE__ */ p("button", {
2445
- type: "button",
2446
- role: "menuitem",
2447
- tabIndex: -1,
2448
- className: "editor-toolbar-emoji",
2449
- "aria-label": L.insertEmojiLabel(e),
2450
- onMouseDown: Z,
2451
- onClick: () => me(e),
2452
- children: e
2453
- }, e))
2454
- })
2455
- }) : null
2456
- ]
2457
- }),
2458
- /* @__PURE__ */ m("div", {
2459
- className: "editor-toolbar-slot editor-toolbar-slot-native",
2460
- children: [/* @__PURE__ */ m(Q, {
2461
- toolbarId: "components",
2462
- label: L.componentsTriggerLabel,
2463
- className: "editor-toolbar-components-trigger",
2464
- tabStop: S === "components",
2465
- onFocus: () => C("components"),
2466
- disabled: g,
2467
- popup: "dialog",
2468
- expanded: b === "native",
2469
- controls: le,
2470
- onClick: () => ye("native"),
2471
- onKeyDown: (e) => Se("native", e),
2472
- children: [
2473
- /* @__PURE__ */ p(X, { name: "sparkle" }),
2474
- /* @__PURE__ */ p("span", {
2475
- className: "editor-toolbar-components-label editor-toolbar-components-label-full",
2476
- children: L.componentsLabel
2477
- }),
2478
- /* @__PURE__ */ p("span", {
2479
- className: "editor-toolbar-components-label editor-toolbar-components-label-compact",
2480
- children: L.componentsCompactLabel
2481
- })
2482
- ]
2483
- }), b === "native" ? /* @__PURE__ */ m("div", {
2484
- id: le,
2485
- ref: _,
2486
- className: "editor-toolbar-popover editor-toolbar-native-menu",
2487
- role: "dialog",
2488
- "aria-label": L.nativeMenuLabel,
2489
- onKeyDown: (e) => rt(e, _.current),
2490
- children: [
2491
- /* @__PURE__ */ m("div", {
2492
- className: "editor-toolbar-native-head",
2493
- children: [/* @__PURE__ */ p("span", {
2494
- className: "editor-toolbar-native-title",
2495
- children: L.nativeTitle
2496
- }), /* @__PURE__ */ p("button", {
2497
- type: "button",
2498
- className: "editor-toolbar-close",
2499
- "aria-label": L.closeNativeLabel,
2500
- onMouseDown: Z,
2501
- onClick: Te,
2502
- children: /* @__PURE__ */ p(X, { name: "close" })
2503
- })]
2504
- }),
2505
- /* @__PURE__ */ m("div", {
2506
- className: "editor-toolbar-search",
2507
- children: [/* @__PURE__ */ p(X, {
2508
- name: "search",
2509
- className: "editor-toolbar-search-icon"
2510
- }), /* @__PURE__ */ p("input", {
2511
- ref: v,
2512
- type: "search",
2513
- className: "editor-toolbar-search-input",
2514
- value: w,
2515
- placeholder: L.searchPlaceholder,
2516
- "aria-label": L.searchLabel,
2517
- autoComplete: "off",
2518
- spellCheck: !1,
2519
- onChange: (e) => T(e.target.value)
2520
- })]
2521
- }),
2522
- /* @__PURE__ */ p("div", {
2523
- className: "editor-toolbar-native-scroll",
2524
- role: "menu",
2525
- "aria-label": L.nativeListLabel,
2526
- children: H.length === 0 ? /* @__PURE__ */ p("p", {
2527
- className: "editor-toolbar-menu-empty",
2528
- children: L.noMatchingComponents
2529
- }) : H.map(({ group: e, components: t }) => /* @__PURE__ */ m("div", {
2530
- className: "editor-toolbar-native-group",
2531
- role: "group",
2532
- "aria-label": e.label,
2533
- children: [/* @__PURE__ */ p("div", {
2534
- className: "editor-toolbar-native-group-title",
2535
- "aria-hidden": "true",
2536
- children: e.label
2537
- }), t.map((e) => /* @__PURE__ */ m("button", {
2538
- type: "button",
2539
- role: "menuitem",
2540
- tabIndex: -1,
2541
- className: "editor-toolbar-native-item",
2542
- onMouseDown: Z,
2543
- onClick: () => he(e),
2544
- children: [/* @__PURE__ */ m("span", {
2545
- className: "editor-toolbar-native-copy",
2546
- children: [/* @__PURE__ */ m("span", {
2547
- className: "editor-toolbar-native-label",
2548
- children: [e.label, e.inline ? /* @__PURE__ */ p("span", {
2549
- className: "editor-toolbar-native-badge",
2550
- children: L.inlineBadge
2551
- }) : null]
2552
- }), /* @__PURE__ */ p("span", {
2553
- className: "editor-toolbar-native-description",
2554
- children: e.description
2555
- })]
2556
- }), /* @__PURE__ */ p(X, {
2557
- name: "plus",
2558
- className: "editor-toolbar-native-add"
2559
- })]
2560
- }, e.id))]
2561
- }, e.id))
2562
- })
2563
- ]
2564
- }) : null]
2565
- }),
2566
- /* @__PURE__ */ m("div", {
2567
- className: "editor-toolbar-history",
2568
- role: "group",
2569
- "aria-label": L.historyLabel,
2570
- children: [
2571
- /* @__PURE__ */ p(Q, {
2572
- toolbarId: "undo",
2573
- label: L.undo,
2574
- className: "editor-toolbar-desktop-only",
2575
- tabStop: S === "undo",
2576
- onFocus: () => C("undo"),
2577
- disabled: g || !s,
2578
- onClick: ge,
2579
- children: /* @__PURE__ */ p(X, { name: "undo" })
2580
- }),
2581
- /* @__PURE__ */ p(Q, {
2582
- toolbarId: "redo",
2583
- label: L.redo,
2584
- className: "editor-toolbar-desktop-only",
2585
- tabStop: S === "redo",
2586
- onFocus: () => C("redo"),
2587
- disabled: g || !f,
2588
- onClick: _e,
2589
- children: /* @__PURE__ */ p(X, { name: "redo" })
2590
- }),
2591
- ee ? /* @__PURE__ */ p(Q, {
2592
- toolbarId: "download",
2593
- label: L.download,
2594
- className: "editor-toolbar-desktop-only",
2595
- tabStop: S === "download",
2596
- onFocus: () => C("download"),
2597
- disabled: g,
2598
- onClick: ve,
2599
- children: /* @__PURE__ */ p(X, { name: "download" })
2600
- }) : null,
2601
- /* @__PURE__ */ m("div", {
2602
- className: "editor-toolbar-slot editor-toolbar-mobile-only",
2603
- children: [/* @__PURE__ */ p(Q, {
2604
- toolbarId: "more",
2605
- label: L.more,
2606
- className: "editor-toolbar-more-trigger",
2607
- tabStop: S === "more",
2608
- onFocus: () => C("more"),
2609
- disabled: g,
2610
- popup: "menu",
2611
- expanded: b === "more",
2612
- controls: ce,
2613
- onClick: () => ye("more"),
2614
- onKeyDown: (e) => Se("more", e),
2615
- children: /* @__PURE__ */ p(X, { name: "more" })
2616
- }), b === "more" ? /* @__PURE__ */ m("div", {
2617
- id: ce,
2618
- ref: _,
2619
- className: "editor-toolbar-popover editor-toolbar-more-menu",
2620
- role: "menu",
2621
- "aria-label": L.moreMenuLabel,
2622
- style: O ?? void 0,
2623
- onKeyDown: (e) => rt(e, _.current),
2624
- children: [
2625
- /* @__PURE__ */ m("button", {
2626
- type: "button",
2627
- role: "menuitem",
2628
- tabIndex: -1,
2629
- className: "editor-toolbar-menu-item editor-toolbar-more-item editor-toolbar-more-link",
2630
- onMouseDown: Z,
2631
- onClick: () => q(fe),
2632
- children: [/* @__PURE__ */ p(X, {
2633
- name: "link",
2634
- className: "editor-toolbar-menu-icon"
2635
- }), /* @__PURE__ */ p("span", { children: L.linkMenuItem })]
2636
- }),
2637
- /* @__PURE__ */ m("button", {
2638
- type: "button",
2639
- role: "menuitem",
2640
- tabIndex: -1,
2641
- className: "editor-toolbar-menu-item editor-toolbar-more-item",
2642
- disabled: !s,
2643
- onMouseDown: Z,
2644
- onClick: ge,
2645
- children: [/* @__PURE__ */ p(X, {
2646
- name: "undo",
2647
- className: "editor-toolbar-menu-icon"
2648
- }), /* @__PURE__ */ p("span", { children: L.undo })]
2649
- }),
2650
- /* @__PURE__ */ m("button", {
2651
- type: "button",
2652
- role: "menuitem",
2653
- tabIndex: -1,
2654
- className: "editor-toolbar-menu-item editor-toolbar-more-item",
2655
- disabled: !f,
2656
- onMouseDown: Z,
2657
- onClick: _e,
2658
- children: [/* @__PURE__ */ p(X, {
2659
- name: "redo",
2660
- className: "editor-toolbar-menu-icon"
2661
- }), /* @__PURE__ */ p("span", { children: L.redo })]
2662
- }),
2663
- ee ? /* @__PURE__ */ m("button", {
2664
- type: "button",
2665
- role: "menuitem",
2666
- tabIndex: -1,
2667
- className: "editor-toolbar-menu-item editor-toolbar-more-item",
2668
- onMouseDown: Z,
2669
- onClick: ve,
2670
- children: [/* @__PURE__ */ p(X, {
2671
- name: "download",
2672
- className: "editor-toolbar-menu-icon"
2673
- }), /* @__PURE__ */ p("span", { children: L.download })]
2674
- }) : null
2675
- ]
2676
- }) : null]
2677
- })
2678
- ]
2679
- })
2680
- ]
2681
- });
2682
- }
2683
- // src/editor/editor-view-bar.tsx
2684
- function ot({ source: e, mode: t, onModeChange: n, sourceId: r, previewId: i, hasPreview: a, allowSplit: o, toolbar: s }) {
2685
- let c = ae(), u = ne[c], d = l(() => Array.from(e).length, [e]);
2686
- return /* @__PURE__ */ m("div", {
2687
- className: "editor-status-bar",
2688
- role: "group",
2689
- "aria-label": u.viewLabel,
2690
- children: [
2691
- /* @__PURE__ */ p("span", {
2692
- className: "editor-status-count",
2693
- children: u.count(d.toLocaleString(c))
2694
- }),
2695
- /* @__PURE__ */ p("span", {
2696
- className: "editor-status-hint",
2697
- children: t !== "preview" && s ? u.keyboardHint : ""
2698
- }),
2699
- a ? /* @__PURE__ */ p("div", {
2700
- className: "editor-view-modes",
2701
- children: [
2702
- "edit",
2703
- "split",
2704
- "preview"
2705
- ].filter((e) => e !== "split" || o).map((e) => /* @__PURE__ */ m("button", {
2706
- type: "button",
2707
- "data-editor-view-option": e,
2708
- "aria-pressed": t === e,
2709
- "aria-controls": e === "edit" ? r : e === "preview" ? i : `${r} ${i}`,
2710
- onClick: () => n(e),
2711
- children: [/* @__PURE__ */ p("svg", {
2712
- viewBox: "0 0 24 24",
2713
- width: "18",
2714
- height: "18",
2715
- fill: "none",
2716
- stroke: "currentColor",
2717
- strokeWidth: "1.7",
2718
- strokeLinecap: "round",
2719
- strokeLinejoin: "round",
2720
- "aria-hidden": "true",
2721
- children: e === "edit" ? /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "m16 3 5 5-12 12-6 1 1-6Z" }), /* @__PURE__ */ p("path", { d: "m13 6 5 5" })] }) : e === "split" ? /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("rect", {
2722
- x: "3",
2723
- y: "4",
2724
- width: "18",
2725
- height: "16",
2726
- rx: "2"
2727
- }), /* @__PURE__ */ p("path", { d: "M12 4v16" })] }) : /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("path", { d: "M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z" }), /* @__PURE__ */ p("circle", {
2728
- cx: "12",
2729
- cy: "12",
2730
- r: "3"
2731
- })] })
2732
- }), /* @__PURE__ */ p("span", { children: u[e] })]
2733
- }, e))
2734
- }) : null
2735
- ]
2736
- });
2737
- }
2738
- // src/editor/source-authoring.tsx
2739
- var st = {
2740
- tokens: [],
2741
- bindings: [],
2742
- diagnostics: []
2743
- }, ct = {
2744
- tag: "tag",
2745
- attribute: "attribute",
2746
- string: "string",
2747
- expression: "expression",
2748
- binding: "binding",
2749
- markdown: "markdown",
2750
- math: "math",
2751
- code: "code",
2752
- comment: "comment"
2753
- };
2754
- function lt(e) {
2755
- let t = e.toLowerCase();
2756
- return ct[t] || (t.includes("tag") ? "tag" : t.includes("attr") ? "attribute" : t.includes("string") || t.includes("quote") ? "string" : t.includes("expr") || t.includes("interp") ? "expression" : t.includes("bind") ? "binding" : t.includes("math") || t.includes("latex") ? "math" : t.includes("code") || t.includes("fence") ? "code" : t.includes("comment") ? "comment" : t.includes("markdown") || t.includes("heading") || t.includes("emphasis") || t.includes("link") ? "markdown" : "plain");
2757
- }
2758
- function ut(e, t, n) {
2759
- return Math.min(Math.max(e, t), n);
2760
- }
2761
- function dt(e, t) {
2762
- let n = [], r = 0, i = [...t].sort((e, t) => e.range.start - t.range.start);
2763
- for (let t of i) {
2764
- let i = ut(Math.max(t.range.start, r), 0, e.length), a = ut(t.range.end, i, e.length);
2765
- r = a, a > i && n.push({
2766
- kind: t.kind,
2767
- range: {
2768
- start: i,
2769
- end: a
2770
- }
2771
- });
2772
- }
2773
- return n;
2774
- }
2775
- function ft(e, t = !0, n) {
2776
- return l(() => {
2777
- if (!t) return st;
2778
- try {
2779
- let t = h(e, n);
2780
- return {
2781
- tokens: dt(e, t.tokens),
2782
- bindings: t.bindings,
2783
- diagnostics: t.diagnostics
2784
- };
2785
- } catch {
2786
- return st;
2787
- }
2788
- }, [
2789
- e,
2790
- t,
2791
- n
2792
- ]);
2793
- }
2794
- function pt(e, t) {
2795
- let n = [], r = 0;
2796
- return t.forEach((t, i) => {
2797
- t.range.start > r && n.push(e.slice(r, t.range.start)), n.push(/* @__PURE__ */ p("span", {
2798
- className: `author-token author-token-${lt(t.kind)}`,
2799
- "data-token-kind": t.kind,
2800
- children: e.slice(t.range.start, t.range.end)
2801
- }, `${i}-${t.range.start}`)), r = t.range.end;
2802
- }), r < e.length && n.push(e.slice(r)), n;
2803
- }
2804
- var mt = n(function({ source: e, tokens: t, width: n, editorRef: r }) {
2805
- let i = u(null);
2806
- return a(() => {
2807
- let e = r.current, t = i.current;
2808
- if (!e || !t) return;
2809
- let n = 0, a = 0, o = NaN, s = NaN, c = () => {
2810
- let n = e.scrollTop, r = e.scrollLeft;
2811
- (n !== o || r !== s) && (o = n, s = r, t.style.transform = `translate3d(${-r}px, ${-n}px, 0)`);
2812
- }, l = () => {
2813
- n = 0, c(), a !== 0 && (n = window.requestAnimationFrame(l));
2814
- }, u = () => {
2815
- c(), a !== 0 && window.clearTimeout(a), a = window.setTimeout(() => {
2816
- a = 0, n !== 0 && (window.cancelAnimationFrame(n), n = 0);
2817
- }, 1e3), n === 0 && (n = window.requestAnimationFrame(l));
2818
- };
2819
- c();
2820
- let d = [
2821
- "scroll",
2822
- "wheel",
2823
- "touchstart",
2824
- "touchmove"
2825
- ];
2826
- for (let t of d) e.addEventListener(t, u, { passive: !0 });
2827
- return () => {
2828
- for (let t of d) e.removeEventListener(t, u);
2829
- a !== 0 && window.clearTimeout(a), n !== 0 && window.cancelAnimationFrame(n);
2830
- };
2831
- }, [r]), /* @__PURE__ */ p("div", {
2832
- className: "author-highlight",
2833
- "aria-hidden": "true",
2834
- style: n > 0 ? { width: `${n}px` } : void 0,
2835
- children: /* @__PURE__ */ p("div", {
2836
- className: "author-highlight-content",
2837
- ref: i,
2838
- children: pt(e, t)
2839
- })
2840
- });
2841
- }), ht = {
2842
- en: {
2843
- region: "Source authoring tools",
2844
- title: "Authoring",
2845
- format: "Format",
2846
- formatTitle: "Normalise spacing inside recognised Reactive MD tags",
2847
- suggestions: "Suggest",
2848
- suggestionsTitle: "Show tag, attribute and binding suggestions (Ctrl+Space)",
2849
- completionLabel: "Source suggestions",
2850
- completionEmpty: "No suggestions at this position.",
2851
- completionCount: (e) => `${e} suggestion${e === 1 ? "" : "s"}`,
2852
- kinds: {
2853
- tag: "Tag",
2854
- attribute: "Attribute",
2855
- binding: "Binding",
2856
- value: "Value"
2857
- },
2858
- bindingsLabel: "Bindings",
2859
- noBindings: "No bindings in this source.",
2860
- caretLabel: "At caret",
2861
- noBindingAtCaret: "Caret is not on a binding.",
2862
- declarationCount: (e) => `${e} declaration${e === 1 ? "" : "s"}`,
2863
- referenceCount: (e) => `${e} reference${e === 1 ? "" : "s"}`,
2864
- declaration: "Declaration",
2865
- reference: "Reference",
2866
- locateTitle: "Locate in editor",
2867
- renameLabel: "Rename selected binding",
2868
- renamePlaceholder: "New name",
2869
- renameAction: "Rename",
2870
- renameTitle: "Rename this binding everywhere it is declared or read",
2871
- renameHint: "Updates declarations, expressions and plot parameters. Literal text and display formulas keep their source.",
2872
- renameEmpty: "Enter a new name.",
2873
- renameSame: "The new name is the current name.",
2874
- renameDone: (e, t) => `Renamed ${e} to ${t}.`,
2875
- renameFailed: (e) => `Rename failed: ${e}`,
2876
- formatApplied: "Formatted as one undo step.",
2877
- formatUnchanged: "The source is already formatted.",
2878
- formatFailed: (e) => `Formatting failed: ${e}`,
2879
- typeLabel: "Type",
2880
- unknownType: "Unknown",
2881
- typeNames: {
2882
- string: "Text",
2883
- number: "Number",
2884
- boolean: "Boolean",
2885
- array: "List",
2886
- "number-array": "Number list",
2887
- null: "Null"
2888
- },
2889
- position: (e, t) => `Line ${e}:${t}`
2890
- },
2891
- zh: {
2892
- region: "源码作者工具",
2893
- title: "作者工具",
2894
- format: "格式化",
2895
- formatTitle: "整理已识别 Reactive MD 标签内的空白",
2896
- suggestions: "补全",
2897
- suggestionsTitle: "显示标签、属性与绑定建议(Ctrl+Space)",
2898
- completionLabel: "源码补全建议",
2899
- completionEmpty: "当前位置没有补全建议。",
2900
- completionCount: (e) => `${e} 条建议`,
2901
- kinds: {
2902
- tag: "标签",
2903
- attribute: "属性",
2904
- binding: "绑定",
2905
- value: "值"
2906
- },
2907
- bindingsLabel: "绑定",
2908
- noBindings: "源码中没有绑定。",
2909
- caretLabel: "光标位置",
2910
- noBindingAtCaret: "光标不在绑定上。",
2911
- declarationCount: (e) => `${e} 处声明`,
2912
- referenceCount: (e) => `${e} 处引用`,
2913
- declaration: "声明",
2914
- reference: "引用",
2915
- locateTitle: "在编辑器中定位",
2916
- renameLabel: "重命名选中绑定",
2917
- renamePlaceholder: "新名称",
2918
- renameAction: "重命名",
2919
- renameTitle: "重命名所有声明与引用位置",
2920
- renameHint: "修改绑定声明、表达式引用与绘图参数,保留普通文字和展示公式。",
2921
- renameEmpty: "请输入新名称。",
2922
- renameSame: "新名称与当前名称相同。",
2923
- renameDone: (e, t) => `已将 ${e} 重命名为 ${t}。`,
2924
- renameFailed: (e) => `重命名失败:${e}`,
2925
- formatApplied: "已格式化,可一步撤销。",
2926
- formatUnchanged: "源码无需格式化。",
2927
- formatFailed: (e) => `格式化失败:${e}`,
2928
- typeLabel: "类型",
2929
- unknownType: "未知",
2930
- typeNames: {
2931
- string: "文本",
2932
- number: "数字",
2933
- boolean: "布尔值",
2934
- array: "列表",
2935
- "number-array": "数字列表",
2936
- null: "空值"
2937
- },
2938
- position: (e, t) => `第 ${e} 行 ${t} 列`
2939
- }
2940
- };
2941
- function gt(e, t) {
2942
- return t >= e.start && t <= e.end;
2943
- }
2944
- function _t(e) {
2945
- return e.end - e.start;
2946
- }
2947
- function vt(e, t) {
2948
- let n = null, r = Infinity, i = (e, i, a) => {
2949
- if (!gt(i, t)) return;
2950
- let o = _t(i);
2951
- o >= r || (n = {
2952
- binding: e,
2953
- role: a
2954
- }, r = o);
2955
- };
2956
- for (let t of e) {
2957
- for (let e of t.declarations) i(t, e, "declaration");
2958
- for (let e of t.references) i(t, e, "reference");
2959
- }
2960
- return n;
2961
- }
2962
- function yt(e) {
2963
- let t = e.current;
2964
- if (!t) return {
2965
- start: 0,
2966
- end: 0
2967
- };
2968
- let n = t.value.length, r = ut(t.selectionStart, 0, n);
2969
- return {
2970
- start: r,
2971
- end: ut(t.selectionEnd, r, n)
2972
- };
2973
- }
2974
- function bt(e, t) {
2975
- let n = Math.min(e.length, t.length), r = 0;
2976
- for (; r < n && e[r] === t[r];) r += 1;
2977
- return r;
2978
- }
2979
- function xt(e, t, n) {
2980
- let r = Math.min(e.length, t.length) - n, i = 0;
2981
- for (; i < r && e[e.length - 1 - i] === t[t.length - 1 - i];) i += 1;
2982
- return i;
2983
- }
2984
- function St(e, t, n) {
2985
- let r = ut(n, 0, e.length), i = bt(e, t);
2986
- if (r <= i) return r;
2987
- let a = xt(e, t, i), o = e.length - a;
2988
- if (r >= o) return t.length - a + (r - o);
2989
- let s = o - i, c = t.length - a - i;
2990
- if (s <= 0) return t.length - a;
2991
- let l = (r - i) / s;
2992
- return Math.round(i + l * c);
2993
- }
2994
- function Ct(e, t) {
2995
- let n = 0;
2996
- for (let r of [...t].sort((e, t) => e.range.start - t.range.start)) {
2997
- if (e < r.range.start) break;
2998
- if (e > r.range.end) n += r.text.length - _t(r.range);
2999
- else return r.range.start + n + Math.min(e - r.range.start, r.text.length);
3000
- }
3001
- return e + n;
3002
- }
3003
- function wt(e) {
3004
- e.preventDefault();
3005
- }
3006
- function Tt(e) {
3007
- return e.isComposing === !0 || e.keyCode === 229;
3008
- }
3009
- function Et(e, t) {
3010
- let n = ut(t, 0, e.length), r = e.lastIndexOf("\n", n - 1) + 1;
3011
- return {
3012
- line: e.slice(0, n).split("\n").length,
3013
- column: n - r + 1
3014
- };
3015
- }
3016
- function Dt({ source: e, analysis: t, bindingDocument: n, compileOptions: i, editorRef: s, onEdit: c, onLocate: f, disabled: h = !1 }) {
3017
- let _ = ae(), v = ht[_], ne = o(), re = o(), ie = u(null), y = u(null), [b, x] = d(0), [S, C] = d(null), [w, T] = d(""), [E, D] = d(null), [O, k] = d(null), [A, j] = d(!1), [M, oe] = d([]), [N, P] = d(0), se = u(A), ce = u(M), le = u(N);
3018
- se.current = A, ce.current = M, le.current = N, a(() => {
3019
- let e = s.current;
3020
- if (!e) return;
3021
- let t = () => x(e.selectionStart);
3022
- t();
3023
- let n = [
3024
- "select",
3025
- "keyup",
3026
- "click",
3027
- "input",
3028
- "focus"
3029
- ];
3030
- for (let r of n) e.addEventListener(r, t);
3031
- return () => {
3032
- for (let r of n) e.removeEventListener(r, t);
3033
- };
3034
- }, [s]), a(() => {
3035
- j(!1);
3036
- }, [e]), a(() => {
3037
- k(null), D(null);
3038
- }, [_]);
3039
- let F = l(() => vt(t.bindings, b), [t.bindings, b]);
3040
- a(() => {
3041
- F && C(F.binding.name);
3042
- }, [F]);
3043
- let I = l(() => (S ? t.bindings.find((e) => e.name === S) : void 0) ?? t.bindings[0] ?? null, [t.bindings, S]);
3044
- a(() => {
3045
- T(""), D(null);
3046
- }, [I?.name]);
3047
- let L = I && n ? n.bindings[I.name]?.type ?? n.computations?.[I.name]?.type : void 0, R = F && n ? n.bindings[F.binding.name]?.type ?? n.computations?.[F.binding.name]?.type : void 0, z = R ? v.typeNames[R] ?? R : v.unknownType, B = L ? v.typeNames[L] ?? L : v.unknownType, ue = r(() => {
3048
- if (h) return;
3049
- let t = s.current, n = ut(t?.selectionStart ?? 0, 0, e.length), r = [];
3050
- try {
3051
- r = ee(e, n, i) ?? [];
3052
- } catch {
3053
- r = [];
3054
- }
3055
- oe(r), P(0), j(!0), k(null);
3056
- }, [
3057
- i,
3058
- h,
3059
- s,
3060
- e
3061
- ]), V = r((t) => {
3062
- if (h) return;
3063
- let n = ut(t.range.start, 0, e.length), r = ut(t.range.end, n, e.length), i = e.slice(0, n) + t.insertText + e.slice(r), a = n + t.insertText.length;
3064
- j(!1), c({
3065
- value: i,
3066
- selection: {
3067
- start: a,
3068
- end: a
3069
- }
3070
- });
3071
- }, [
3072
- h,
3073
- c,
3074
- e
3075
- ]);
3076
- a(() => {
3077
- let e = s.current;
3078
- if (!e) return;
3079
- let t = (e) => {
3080
- if (Tt(e)) return;
3081
- if (h) {
3082
- se.current && j(!1);
3083
- return;
3084
- }
3085
- let t = e.key;
3086
- if ((e.ctrlKey || e.metaKey) && !e.altKey && (t === " " || t === "Spacebar")) e.preventDefault(), e.stopPropagation(), ue();
3087
- else if (se.current) {
3088
- if (t === "ArrowDown" || t === "ArrowUp") {
3089
- e.preventDefault(), e.stopPropagation();
3090
- let n = ce.current.length;
3091
- P((e) => n === 0 ? 0 : (e + (t === "ArrowDown" ? 1 : -1) + n) % n);
3092
- } else if (t === "Enter") {
3093
- e.preventDefault(), e.stopPropagation();
3094
- let t = ce.current[le.current];
3095
- t ? V(t) : j(!1);
3096
- } else t === "Escape" && (e.preventDefault(), e.stopPropagation(), j(!1));
3097
- }
3098
- };
3099
- return e.addEventListener("keydown", t, !0), () => e.removeEventListener("keydown", t, !0);
3100
- }, [
3101
- V,
3102
- h,
3103
- s,
3104
- ue
3105
- ]), a(() => {
3106
- if (!A) return;
3107
- let e = (e) => {
3108
- ie.current?.contains(e.target) || j(!1);
3109
- }, t = (e) => {
3110
- e.key === "Escape" && !Tt(e) && j(!1);
3111
- };
3112
- return document.addEventListener("pointerdown", e, !0), document.addEventListener("keydown", t, !0), () => {
3113
- document.removeEventListener("pointerdown", e, !0), document.removeEventListener("keydown", t, !0);
3114
- };
3115
- }, [A]), a(() => {
3116
- A && y.current?.querySelector(`[data-completion-index="${N}"]`)?.scrollIntoView({ block: "nearest" });
3117
- }, [N, A]);
3118
- let H = () => {
3119
- if (h) return;
3120
- let t;
3121
- try {
3122
- t = g(e, i);
3123
- } catch (e) {
3124
- k(v.formatFailed(e instanceof Error ? e.message : String(e)));
3125
- return;
3126
- }
3127
- if (t === e) {
3128
- k(v.formatUnchanged);
3129
- return;
3130
- }
3131
- let n = yt(s);
3132
- c({
3133
- value: t,
3134
- selection: {
3135
- start: St(e, t, n.start),
3136
- end: St(e, t, n.end)
3137
- }
3138
- }), k(v.formatApplied);
3139
- }, U = () => {
3140
- if (h || !I) return;
3141
- let t = w.trim();
3142
- if (!t) D(v.renameEmpty);
3143
- else if (t === I.name) D(v.renameSame);
3144
- else try {
3145
- let n = te(e, I.name, t, i), r = yt(s);
3146
- c({
3147
- value: n.source,
3148
- selection: {
3149
- start: Ct(r.start, n.edits),
3150
- end: Ct(r.end, n.edits)
3151
- }
3152
- }), C(t), T(""), D(null), k(v.renameDone(I.name, t));
3153
- } catch (e) {
3154
- D(v.renameFailed(e instanceof Error ? e.message : String(e)));
3155
- }
3156
- }, W = M[N], G = I ? [...I.declarations.map((e, t) => ({
3157
- range: e,
3158
- role: "declaration",
3159
- index: t
3160
- })), ...I.references.map((e, t) => ({
3161
- range: e,
3162
- role: "reference",
3163
- index: t
3164
- }))] : [];
3165
- return /* @__PURE__ */ m("section", {
3166
- className: "source-authoring",
3167
- "aria-label": v.region,
3168
- ref: ie,
3169
- children: [
3170
- /* @__PURE__ */ m("div", {
3171
- className: "authoring-bar",
3172
- children: [/* @__PURE__ */ p("span", {
3173
- className: "authoring-title",
3174
- children: v.title
3175
- }), /* @__PURE__ */ m("div", {
3176
- className: "authoring-actions",
3177
- children: [/* @__PURE__ */ p("button", {
3178
- type: "button",
3179
- className: "authoring-button",
3180
- "data-authoring-action": "format",
3181
- title: v.formatTitle,
3182
- disabled: h,
3183
- onMouseDown: wt,
3184
- onClick: H,
3185
- children: v.format
3186
- }), /* @__PURE__ */ p("button", {
3187
- type: "button",
3188
- className: "authoring-button",
3189
- "data-authoring-action": "suggest",
3190
- title: v.suggestionsTitle,
3191
- "aria-expanded": A,
3192
- "aria-controls": re,
3193
- disabled: h,
3194
- onMouseDown: wt,
3195
- onClick: ue,
3196
- children: v.suggestions
3197
- })]
3198
- })]
3199
- }),
3200
- A ? /* @__PURE__ */ m("div", {
3201
- className: "authoring-completion",
3202
- "aria-label": v.completionLabel,
3203
- children: [
3204
- /* @__PURE__ */ m("div", {
3205
- className: "authoring-completion-head",
3206
- children: [/* @__PURE__ */ p("span", { children: v.completionLabel }), /* @__PURE__ */ p("span", {
3207
- className: "authoring-completion-count",
3208
- children: v.completionCount(M.length)
3209
- })]
3210
- }),
3211
- /* @__PURE__ */ p("div", {
3212
- id: re,
3213
- className: "authoring-completion-list",
3214
- role: "listbox",
3215
- "aria-label": v.completionLabel,
3216
- ref: y,
3217
- children: M.length === 0 ? /* @__PURE__ */ p("p", {
3218
- className: "authoring-empty",
3219
- children: v.completionEmpty
3220
- }) : M.map((e, t) => /* @__PURE__ */ m("button", {
3221
- type: "button",
3222
- role: "option",
3223
- "data-completion-index": t,
3224
- "aria-selected": t === N,
3225
- className: `authoring-completion-item${t === N ? " is-active" : ""}`,
3226
- onMouseDown: wt,
3227
- onMouseEnter: () => P(t),
3228
- onClick: () => V(e),
3229
- children: [
3230
- /* @__PURE__ */ p("span", {
3231
- className: `authoring-kind is-${e.kind}`,
3232
- children: v.kinds[e.kind] ?? e.kind
3233
- }),
3234
- /* @__PURE__ */ p("span", {
3235
- className: "authoring-completion-label",
3236
- children: e.label
3237
- }),
3238
- e.detail ? /* @__PURE__ */ p("span", {
3239
- className: "authoring-completion-detail",
3240
- children: e.detail
3241
- }) : null
3242
- ]
3243
- }, `${e.kind}-${e.range.start}-${e.range.end}-${t}`))
3244
- }),
3245
- /* @__PURE__ */ p("p", {
3246
- className: "reactive-md-editor-sr-only",
3247
- "aria-live": "polite",
3248
- children: W ? `${v.kinds[W.kind] ?? W.kind} ${W.label}` : ""
3249
- })
3250
- ]
3251
- }) : null,
3252
- /* @__PURE__ */ m("div", {
3253
- className: "authoring-body",
3254
- children: [
3255
- /* @__PURE__ */ m("p", {
3256
- className: "authoring-caret",
3257
- "data-binding-caret": F?.binding.name ?? "",
3258
- children: [/* @__PURE__ */ p("span", {
3259
- className: "authoring-label",
3260
- children: v.caretLabel
3261
- }), F ? /* @__PURE__ */ m("span", {
3262
- className: "authoring-caret-value",
3263
- children: [
3264
- /* @__PURE__ */ p("strong", { children: F.binding.name }),
3265
- /* @__PURE__ */ m("span", {
3266
- className: "authoring-type",
3267
- children: [
3268
- v.typeLabel,
3269
- ": ",
3270
- z
3271
- ]
3272
- }),
3273
- /* @__PURE__ */ p("span", { children: v.declarationCount(F.binding.declarations.length) }),
3274
- /* @__PURE__ */ p("span", { children: v.referenceCount(F.binding.references.length) })
3275
- ]
3276
- }) : /* @__PURE__ */ p("span", {
3277
- className: "authoring-muted",
3278
- children: v.noBindingAtCaret
3279
- })]
3280
- }),
3281
- /* @__PURE__ */ m("div", {
3282
- className: "authoring-row",
3283
- children: [/* @__PURE__ */ p("span", {
3284
- className: "authoring-label",
3285
- children: v.bindingsLabel
3286
- }), /* @__PURE__ */ p("div", {
3287
- className: "authoring-binding-list",
3288
- children: t.bindings.length === 0 ? /* @__PURE__ */ p("span", {
3289
- className: "authoring-muted",
3290
- children: v.noBindings
3291
- }) : t.bindings.map((e) => /* @__PURE__ */ m("button", {
3292
- type: "button",
3293
- "data-binding-name": e.name,
3294
- className: "authoring-binding-chip",
3295
- "aria-pressed": e.name === I?.name,
3296
- title: `${v.declarationCount(e.declarations.length)} · ${v.referenceCount(e.references.length)}`,
3297
- onClick: () => {
3298
- C(e.name), k(null);
3299
- },
3300
- children: [/* @__PURE__ */ p("span", { children: e.name }), /* @__PURE__ */ m("span", {
3301
- className: "authoring-binding-count",
3302
- children: [
3303
- e.declarations.length,
3304
- "/",
3305
- e.references.length
3306
- ]
3307
- })]
3308
- }, e.name))
3309
- })]
3310
- }),
3311
- I ? /* @__PURE__ */ m("div", {
3312
- className: "authoring-row",
3313
- children: [/* @__PURE__ */ m("span", {
3314
- className: "authoring-label",
3315
- children: [
3316
- I.name,
3317
- " · ",
3318
- v.typeLabel,
3319
- ": ",
3320
- B
3321
- ]
3322
- }), /* @__PURE__ */ p("div", {
3323
- className: "authoring-locations",
3324
- children: G.map(({ range: t, role: n, index: r }) => {
3325
- let i = Et(e, t.start);
3326
- return /* @__PURE__ */ m("button", {
3327
- type: "button",
3328
- className: `authoring-location is-${n}`,
3329
- "data-binding-location": n,
3330
- "data-start": t.start,
3331
- "data-end": t.end,
3332
- title: v.locateTitle,
3333
- onClick: () => {
3334
- C(I.name), f(t);
3335
- },
3336
- children: [/* @__PURE__ */ m("span", { children: [
3337
- n === "declaration" ? v.declaration : v.reference,
3338
- " ",
3339
- r + 1
3340
- ] }), /* @__PURE__ */ p("span", {
3341
- className: "authoring-location-position",
3342
- children: v.position(i.line, i.column)
3343
- })]
3344
- }, `${n}-${t.start}-${t.end}`);
3345
- })
3346
- })]
3347
- }) : null,
3348
- /* @__PURE__ */ m("div", {
3349
- className: "authoring-rename",
3350
- children: [
3351
- /* @__PURE__ */ p("label", {
3352
- className: "authoring-label",
3353
- htmlFor: ne,
3354
- children: v.renameLabel
3355
- }),
3356
- /* @__PURE__ */ m("div", {
3357
- className: "authoring-rename-row",
3358
- children: [/* @__PURE__ */ p("input", {
3359
- id: ne,
3360
- type: "text",
3361
- className: "authoring-rename-input",
3362
- "data-authoring-action": "rename-input",
3363
- value: w,
3364
- placeholder: v.renamePlaceholder,
3365
- autoComplete: "off",
3366
- spellCheck: !1,
3367
- disabled: h || !I,
3368
- onChange: (e) => {
3369
- T(e.target.value), D(null);
3370
- },
3371
- onKeyDown: (e) => {
3372
- e.key === "Enter" && Tt(e.nativeEvent) && e.preventDefault();
3373
- }
3374
- }), /* @__PURE__ */ p("button", {
3375
- type: "button",
3376
- className: "authoring-button authoring-primary",
3377
- "data-authoring-action": "rename",
3378
- disabled: h || !I,
3379
- onMouseDown: wt,
3380
- onClick: U,
3381
- title: v.renameTitle,
3382
- children: v.renameAction
3383
- })]
3384
- }),
3385
- E ? /* @__PURE__ */ p("p", {
3386
- className: "authoring-error",
3387
- role: "alert",
3388
- children: E
3389
- }) : null,
3390
- /* @__PURE__ */ p("p", {
3391
- className: "authoring-hint",
3392
- children: v.renameHint
3393
- })
3394
- ]
3395
- }),
3396
- O ? /* @__PURE__ */ p("p", {
3397
- className: "authoring-status",
3398
- "data-authoring-status": "true",
3399
- role: "status",
3400
- children: O
3401
- }) : null
3402
- ]
3403
- })
3404
- ]
3405
- });
3406
- }
3407
- // src/editor/use-gutter-metrics.ts
3408
- function Ot(e, t) {
3409
- return e.length === t.length && e.every((e, n) => Math.abs(e - t[n]) < .01);
3410
- }
3411
- function kt(e, t, n) {
3412
- let [r, i] = d(0), [o, s] = d([]), [l, u] = d(0);
3413
- return c(() => {
3414
- let e = n.current;
3415
- if (!e) return;
3416
- let t = () => i(e.clientWidth);
3417
- t();
3418
- let r = new ResizeObserver(t);
3419
- return r.observe(e), () => r.disconnect();
3420
- }, [n]), a(() => {
3421
- let e = !1;
3422
- return document.fonts?.ready.then(() => {
3423
- e || u((e) => e + 1);
3424
- }).catch(() => {}), () => {
3425
- e = !0;
3426
- };
3427
- }, []), c(() => {
3428
- let n = t.current;
3429
- if (!n || r === 0) return;
3430
- let i = Array.from(n.children);
3431
- if (i.length !== e.length) return;
3432
- let a = Number.parseFloat(window.getComputedStyle(n).lineHeight) || 22, o = i.map((e) => e.getBoundingClientRect().height || a);
3433
- s((e) => Ot(e, o) ? e : o);
3434
- }, [
3435
- e,
3436
- r,
3437
- l,
3438
- t
3439
- ]), {
3440
- width: r,
3441
- heights: o
3442
- };
3443
- }
3444
- // src/editor/use-source-history.ts
3445
- var At = 700, jt = 120, Mt = {
3446
- start: 0,
3447
- end: 0
3448
- };
3449
- function Nt(e, t = Mt, n = Date.now) {
3450
- let r = [{
3451
- value: e,
3452
- selection: t
3453
- }], i = 0, a = 0, o = !1;
3454
- return {
3455
- get canUndo() {
3456
- return i > 0;
3457
- },
3458
- get canRedo() {
3459
- return i < r.length - 1;
3460
- },
3461
- record: (e, t, s = "merge") => {
3462
- let c = r[i];
3463
- if (e === c.value && t.start === c.selection.start && t.end === c.selection.end) return;
3464
- let l = n();
3465
- s === "merge" && o && i > 0 && i === r.length - 1 && l - a < At ? r[i] = {
3466
- value: e,
3467
- selection: t
3468
- } : (r = r.slice(0, i + 1), r.push({
3469
- value: e,
3470
- selection: t
3471
- }), r.length > jt && r.shift(), i = r.length - 1), a = l, o = s === "merge";
3472
- },
3473
- undo: () => i <= 0 ? null : (--i, a = 0, o = !1, r[i]),
3474
- redo: () => i >= r.length - 1 ? null : (i += 1, a = 0, o = !1, r[i]),
3475
- reset: (e, t = Mt) => {
3476
- r = [{
3477
- value: e,
3478
- selection: t
3479
- }], i = 0, a = 0, o = !1;
3480
- }
3481
- };
3482
- }
3483
- function Pt(e, t = Mt) {
3484
- let n = u(null);
3485
- n.current ||= Nt(e, t);
3486
- let [, i] = d(0), a = r(() => i((e) => e + 1), []), o = r((e, t, r) => {
3487
- n.current.record(e, t, r), a();
3488
- }, [a]), s = r(() => {
3489
- let e = n.current.undo();
3490
- return a(), e;
3491
- }, [a]), c = r(() => {
3492
- let e = n.current.redo();
3493
- return a(), e;
3494
- }, [a]), l = r((e, t) => {
3495
- n.current.reset(e, t), a();
3496
- }, [a]);
3497
- return {
3498
- canUndo: n.current.canUndo,
3499
- canRedo: n.current.canRedo,
3500
- record: o,
3501
- undo: s,
3502
- redo: c,
3503
- reset: l
3504
- };
3505
- }
3506
- // src/editor/ReactiveMarkdownEditor.tsx
3507
- function $(e, t) {
3508
- return Number.isFinite(e) ? Math.min(Math.max(Math.trunc(e), 0), t) : 0;
3509
- }
3510
- function Ft(e) {
3511
- return typeof e == "number" ? `${e}px` : e;
3512
- }
3513
- function It(e, t) {
3514
- let n = $(t.start, e.length), r = $(t.end, e.length);
3515
- return n <= r ? {
3516
- start: n,
3517
- end: r
3518
- } : {
3519
- start: r,
3520
- end: n
3521
- };
3522
- }
3523
- function Lt(e, t) {
3524
- e && (e.current = t);
3525
- }
3526
- var Rt = t(function({ value: e, onChange: t, locale: n = "en", theme: i = "auto", preview: a, viewMode: f, defaultViewMode: h = "edit", onViewModeChange: ee, id: g, className: te, style: _, height: v = 560, minHeight: re = 280, placeholder: ie, ariaLabel: y, readOnly: b = !1, disabled: ae = !1, documentKey: S, diagnostics: C, compileOptions: w, document: T = null, toolbar: E = !0, authoring: D = !0, onExport: O, textareaRef: k }, A) {
3527
- let j = o(), M = g ?? `reactive-md-editor-${j.replace(/:/g, "")}`, oe = ne[n], N = u(null), [P, se] = d(!1);
3528
- c(() => {
3529
- let e = N.current;
3530
- if (!e) return;
3531
- let t = () => se(e.clientWidth <= 600);
3532
- if (t(), typeof ResizeObserver > "u") return window.addEventListener("resize", t), () => window.removeEventListener("resize", t);
3533
- let n = new ResizeObserver(t);
3534
- return n.observe(e), () => n.disconnect();
3535
- }, []);
3536
- let [ce, le] = d(h), F = a != null, I = F ? f ?? ce : "edit", L = P && I === "split" ? "edit" : I, R = (e) => {
3537
- f === void 0 && le(e), ee?.(e);
3538
- }, z = u(null), B = u(null), ue = u(null), V = u({
3539
- start: 0,
3540
- end: 0
3541
- }), H = u(null), U = u(e), W = u(S), G = u(!1), K = u(!1), q = u(e);
3542
- q.current = e;
3543
- let fe = b || ae, pe = u(fe);
3544
- pe.current = fe;
3545
- let [me, he] = d(!1), [ge, _e] = d(1), { canUndo: ve, canRedo: ye, record: be, undo: xe, redo: Se, reset: Ce } = Pt(e), we = r(() => {
3546
- V.current = {
3547
- start: 0,
3548
- end: 0
3549
- };
3550
- let e = z.current;
3551
- e && (e.setSelectionRange(0, 0), e.scrollTop = 0, e.scrollLeft = 0), B.current && (B.current.scrollTop = 0), _e(1);
3552
- }, []);
3553
- c(() => {
3554
- e !== U.current && (U.current = e, H.current = null, Ce(e), we());
3555
- }, [
3556
- e,
3557
- Ce,
3558
- we
3559
- ]), c(() => {
3560
- W.current !== S && (W.current = S, U.current = e, H.current = null, Ce(e), we());
3561
- }, [
3562
- S,
3563
- e,
3564
- Ce,
3565
- we
3566
- ]);
3567
- let Te = ft(e, D, w), Ee = l(() => e.split("\n"), [e]), De = kt(Ee, ue, z), Oe = l(() => {
3568
- let e = /* @__PURE__ */ new Set();
3569
- for (let t of C ?? []) Number.isInteger(t.line) && t.line > 0 && e.add(t.line);
3570
- return e;
3571
- }, [C]), J = r((e) => {
3572
- let t = e.value.length, n = $(e.selectionStart, t), r = $(e.selectionEnd, t);
3573
- V.current = {
3574
- start: n,
3575
- end: r
3576
- }, _e(e.value.slice(0, n).split("\n").length);
3577
- }, []), Y = r((e, n) => {
3578
- let r = e !== q.current;
3579
- q.current = e, U.current = e, n && r && (H.current = n), t(e);
3580
- }, [t]), ke = r((e) => {
3581
- pe.current || (be(e.value, e.selection, "separate"), Y(e.value, e.selection));
3582
- }, [Y, be]), Ae = r(() => {
3583
- if (pe.current) return;
3584
- let e = xe();
3585
- e && Y(e.value, e.selection);
3586
- }, [Y, xe]), je = r(() => {
3587
- if (pe.current) return;
3588
- let e = Se();
3589
- e && Y(e.value, e.selection);
3590
- }, [Y, Se]);
3591
- c(() => {
3592
- let t = H.current;
3593
- if (!t) return;
3594
- if (e !== U.current) {
3595
- H.current = null;
3596
- return;
3597
- }
3598
- H.current = null;
3599
- let n = z.current;
3600
- if (!n) return;
3601
- let r = It(n.value, t);
3602
- n.setSelectionRange(r.start, r.end), n.focus({ preventScroll: !0 }), V.current = r, _e(n.value.slice(0, r.start).split("\n").length);
3603
- }, [e]);
3604
- let Me = r((e) => {
3605
- let t = z.current;
3606
- if (t && (t.focus({ preventScroll: !0 }), e)) {
3607
- let n = It(t.value, e);
3608
- t.setSelectionRange(n.start, n.end), V.current = n, _e(t.value.slice(0, n.start).split("\n").length);
3609
- }
3610
- }, []), Ne = r((e) => {
3611
- let t = z.current;
3612
- if (!t) return;
3613
- let n = It(t.value, e);
3614
- Me(n);
3615
- let r = t.value.slice(0, n.start).split("\n").length, i = B.current, a = i?.children[r - 1];
3616
- if (i && a) {
3617
- let e = a.getBoundingClientRect().top - i.getBoundingClientRect().top + i.scrollTop;
3618
- t.scrollTop = Math.max(0, e - t.clientHeight / 3);
3619
- } else {
3620
- let e = window.getComputedStyle(t), n = Number.parseFloat(e.lineHeight) || 22;
3621
- t.scrollTop = Math.max(0, (r - 1) * n - t.clientHeight / 3);
3622
- }
3623
- i && (i.scrollTop = t.scrollTop);
3624
- }, [Me]);
3625
- s(A, () => ({
3626
- focus(e) {
3627
- Me(e);
3628
- },
3629
- selectRange(e) {
3630
- Me(e);
3631
- },
3632
- getSelection() {
3633
- let e = z.current;
3634
- if (!e) return V.current;
3635
- let t = e.value.length;
3636
- return {
3637
- start: $(e.selectionStart, t),
3638
- end: $(e.selectionEnd, t)
3639
- };
3640
- },
3641
- getTextarea() {
3642
- return z.current;
3643
- },
3644
- insertText(e) {
3645
- let t = z.current;
3646
- if (!t || pe.current) return;
3647
- let n = q.current, r = $(t.selectionStart, n.length), i = $(t.selectionEnd, n.length), a = n.slice(0, r) + e + n.slice(i), o = r + e.length;
3648
- ke({
3649
- value: a,
3650
- selection: {
3651
- start: o,
3652
- end: o
3653
- }
3654
- });
3655
- },
3656
- undo: Ae,
3657
- redo: je
3658
- }), [
3659
- Me,
3660
- ke,
3661
- Ae,
3662
- je
3663
- ]);
3664
- let Pe = r((e) => {
3665
- z.current = e, Lt(k, e);
3666
- }, [k]), Fe = (e) => {
3667
- if (pe.current) return;
3668
- let t = e.currentTarget, n = {
3669
- start: $(t.selectionStart, t.value.length),
3670
- end: $(t.selectionEnd, t.value.length)
3671
- };
3672
- be(t.value, n, "merge"), Y(t.value);
3673
- }, Ie = (e) => {
3674
- if (G.current || e.nativeEvent.isComposing) return;
3675
- if (e.key === "Escape") {
3676
- K.current = E;
3677
- return;
3678
- }
3679
- let t = K.current && e.key === "Tab" && !e.shiftKey;
3680
- if (K.current = !1, t) {
3681
- let t = z.current?.closest(".reactive-md-editor")?.querySelector(".editor-toolbar [tabindex=\"0\"]:not(:disabled)");
3682
- if (t) {
3683
- e.preventDefault(), t.focus({ preventScroll: !0 });
3684
- return;
3685
- }
3686
- }
3687
- if (pe.current) return;
3688
- let n = e.metaKey || e.ctrlKey, r = e.key.toLowerCase();
3689
- if (n && !e.altKey && r === "z") {
3690
- e.preventDefault(), e.shiftKey ? je() : Ae();
3691
- return;
3692
- }
3693
- if (n && !e.altKey && r === "y") {
3694
- e.preventDefault(), je();
3695
- return;
3696
- }
3697
- if (e.key !== "Tab" || e.shiftKey) return;
3698
- e.preventDefault();
3699
- let i = e.currentTarget, a = $(i.selectionStart, i.value.length), o = $(i.selectionEnd, i.value.length);
3700
- if (a !== o) {
3701
- ke(de(i.value, {
3702
- start: a,
3703
- end: o
3704
- }));
3705
- return;
3706
- }
3707
- let s = `${i.value.slice(0, a)} ${i.value.slice(o)}`, c = {
3708
- start: a + 2,
3709
- end: a + 2
3710
- };
3711
- be(s, c, "separate"), Y(s, c);
3712
- }, Le = () => {
3713
- K.current = !1, G.current = !0, he(!0);
3714
- }, Re = (e) => {
3715
- G.current = !1, he(!1), J(e.currentTarget);
3716
- }, ze = (e) => {
3717
- B.current && (B.current.scrollTop = e.currentTarget.scrollTop);
3718
- }, Be = E, Ve = `reactive-md-editor${te ? ` ${te}` : ""}`;
3719
- return /* @__PURE__ */ p(x, {
3720
- locale: n,
3721
- children: /* @__PURE__ */ m("div", {
3722
- className: Ve,
3723
- "data-editor-theme": i,
3724
- lang: n === "zh" ? "zh-CN" : "en",
3725
- style: _,
3726
- role: "group",
3727
- "aria-label": oe.region,
3728
- "aria-disabled": fe || void 0,
3729
- inert: ae || void 0,
3730
- children: [/* @__PURE__ */ m("div", {
3731
- className: "editor-frame",
3732
- ref: N,
3733
- "data-editor-view": L,
3734
- style: {
3735
- height: Ft(v),
3736
- minHeight: Ft(re)
3737
- },
3738
- children: [
3739
- Be ? /* @__PURE__ */ p(at, {
3740
- editorRef: z,
3741
- onEdit: ke,
3742
- onUndo: Ae,
3743
- onRedo: je,
3744
- canUndo: ve,
3745
- canRedo: ye,
3746
- onExport: O,
3747
- showExport: typeof O == "function",
3748
- disabled: fe
3749
- }) : null,
3750
- /* @__PURE__ */ p("label", {
3751
- className: "reactive-md-editor-sr-only",
3752
- htmlFor: M,
3753
- children: oe.sourceLabel
3754
- }),
3755
- /* @__PURE__ */ m("div", {
3756
- className: "editor-workspace",
3757
- "data-view": L,
3758
- children: [/* @__PURE__ */ m("div", {
3759
- id: `${M}-source`,
3760
- hidden: L === "preview",
3761
- className: `editor-shell${me ? " is-composing" : ""}`,
3762
- children: [
3763
- /* @__PURE__ */ p("div", {
3764
- className: "editor-gutter",
3765
- ref: B,
3766
- "aria-hidden": "true",
3767
- children: Ee.map((e, t) => {
3768
- let n = t + 1;
3769
- return /* @__PURE__ */ p("span", {
3770
- className: `gutter-line ${ge === n ? "is-active" : ""} ${Oe.has(n) ? "is-diagnostic" : ""}`,
3771
- style: De.heights[t] ? { height: `${De.heights[t]}px` } : void 0,
3772
- children: n
3773
- }, n);
3774
- })
3775
- }),
3776
- /* @__PURE__ */ m("div", {
3777
- className: "editor-input-wrap",
3778
- children: [/* @__PURE__ */ p(mt, {
3779
- source: e,
3780
- tokens: Te.tokens,
3781
- width: De.width,
3782
- editorRef: z
3783
- }), /* @__PURE__ */ p("textarea", {
3784
- id: M,
3785
- ref: Pe,
3786
- className: "editor-input",
3787
- value: e,
3788
- wrap: "soft",
3789
- spellCheck: !1,
3790
- autoCapitalize: "off",
3791
- autoCorrect: "off",
3792
- placeholder: ie,
3793
- "aria-label": y,
3794
- readOnly: b,
3795
- disabled: ae,
3796
- onScroll: ze,
3797
- onChange: Fe,
3798
- onKeyDown: Ie,
3799
- onBlur: () => {
3800
- K.current = !1;
3801
- },
3802
- onCompositionStart: Le,
3803
- onCompositionEnd: Re,
3804
- onSelect: (e) => J(e.currentTarget),
3805
- onKeyUp: (e) => J(e.currentTarget),
3806
- onClick: (e) => J(e.currentTarget)
3807
- })]
3808
- }),
3809
- /* @__PURE__ */ p("div", {
3810
- className: "editor-mirror",
3811
- ref: ue,
3812
- "aria-hidden": "true",
3813
- style: De.width ? { width: De.width } : void 0,
3814
- children: Ee.map((e, t) => /* @__PURE__ */ p("div", { children: e.replace(/\r$/, "") || "​" }, t))
3815
- })
3816
- ]
3817
- }), F ? /* @__PURE__ */ p("div", {
3818
- id: `${M}-preview`,
3819
- className: "editor-preview",
3820
- role: "region",
3821
- "aria-label": oe.previewRegion,
3822
- hidden: L === "edit",
3823
- children: a
3824
- }) : null]
3825
- }),
3826
- /* @__PURE__ */ p(ot, {
3827
- source: e,
3828
- mode: L,
3829
- onModeChange: R,
3830
- sourceId: `${M}-source`,
3831
- previewId: `${M}-preview`,
3832
- hasPreview: F,
3833
- allowSplit: !P,
3834
- toolbar: E && !fe
3835
- })
3836
- ]
3837
- }), D ? /* @__PURE__ */ p("div", {
3838
- hidden: L === "preview",
3839
- children: /* @__PURE__ */ p(Dt, {
3840
- source: e,
3841
- analysis: Te,
3842
- bindingDocument: T,
3843
- compileOptions: w,
3844
- editorRef: z,
3845
- onEdit: ke,
3846
- onLocate: Ne,
3847
- disabled: fe
3848
- })
3849
- }) : null]
3850
- })
3851
- });
3852
- });
3853
- export { Rt as ReactiveMarkdownEditor };