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,8 +1,18 @@
1
- import { F as e, J as t, K as n, M as r, N as i, P as a, Y as o, Z as s, _ as c, at as l, b as u, ct as d, d as f, f as p, ft as m, it as h, lt as g, m as _, n as ee, nt as v, ot as y, p as b, r as te, rt as ne, st as re, t as x, v as ie, y as ae } from "./compiler-Cm3ppMxG.js";
2
- import { i as oe, n as se, r as ce, t as le } from "./authoring-BEVyth5X.js";
3
- import { t as ue } from "./runtime-DlFYQ4s_.js";
4
- // src/local/source-migration.ts
5
- var de = /* @__PURE__ */ new Set([
1
+ import { _ as e, g as t, h as n, n as r, y as i } from "./compiler-core-kPiH-gOV.js";
2
+ import { $ as a, Q as o, S as s, et as c, it as l, nt as u, rt as d, tt as f } from "./config-validation-DXTynAw7.js";
3
+ import { Q as p, et as m, l as h, ot as g, w as _ } from "./validation-W-bmny-x.js";
4
+ import { S as v, b as y, d as b, x } from "./registry-B9Jc3FVe.js";
5
+ import { t as S } from "./options-CX5m5n-J.js";
6
+ import { t as ee } from "./compiler--ea2CKQF.js";
7
+ import { c as C } from "./schema-ZFufO8V0.js";
8
+ import { i as te, n as ne, r as re, t as w } from "./authoring-BsfSwQRm.js";
9
+ import { a as T, i as ie, n as ae, r as oe, t as se } from "./math-sample-BGEW49zY.js";
10
+ import { a as ce, i as le, n as ue, r as de, t as fe } from "./runtime-C-sbfpOX.js";
11
+ import { C as pe } from "./component-state-Cq2K5gkS.js";
12
+ import { _ as me, a as he, f as ge, g as _e, h as ve, i as ye, m as be, n as xe, p as Se, r as Ce, t as we, v as Te, y as Ee } from "./shareable-DDVL4Fi9.js";
13
+ import { t as De } from "./component-state-D_cw_EHe.js";
14
+ // src/local/source/source-migration.ts
15
+ var E = /* @__PURE__ */ new Set([
6
16
  "sum",
7
17
  "average",
8
18
  "minOf",
@@ -20,7 +30,7 @@ var de = /* @__PURE__ */ new Set([
20
30
  "slice",
21
31
  "dateCompare",
22
32
  "dateDiff"
23
- ]), fe = /* @__PURE__ */ new Set([
33
+ ]), Oe = /* @__PURE__ */ new Set([
24
34
  "jump",
25
35
  "anchor",
26
36
  "text",
@@ -35,107 +45,111 @@ var de = /* @__PURE__ */ new Set([
35
45
  "const",
36
46
  "validation",
37
47
  "data-table",
38
- "column"
39
- ]), pe = `<!-- reactive-md: ${r} -->`;
40
- function me(e) {
48
+ "column",
49
+ "external"
50
+ ]), ke = /* @__PURE__ */ new Set(["external"]), Ae = /* @__PURE__ */ new Set([
51
+ "local-draft-1",
52
+ "local-draft-2",
53
+ _
54
+ ]), D = `<!-- reactive-md: ${_} -->`;
55
+ function O(e) {
41
56
  let t = e.diagnostics.filter((t) => t.code.startsWith("local.version.") || t.code === "local.budget" || t.code === "local.parse" && !e.nodes.length), n = e.versionDeclaration?.version ?? null;
42
57
  return {
43
58
  declaredVersion: n,
44
- effectiveVersion: n ?? "local-draft-2",
59
+ effectiveVersion: n ?? "local-draft-3",
45
60
  supported: !t.some((e) => e.severity === "error"),
46
61
  range: e.versionDeclaration ? { ...e.versionDeclaration.range } : null,
47
62
  diagnostics: t
48
63
  };
49
64
  }
50
- function he(e) {
51
- return me(f(e));
65
+ function je(e) {
66
+ return O(C(e));
52
67
  }
53
- function ge(e, t, n, r, i = "error") {
54
- let a = re(t, r), o = e.slice(0, n.start), s = o.lastIndexOf("\n");
68
+ function Me(e, t, n, r, i = "error") {
69
+ let o = u(t, r), s = e.slice(0, n.start), c = s.lastIndexOf("\n");
55
70
  return {
56
71
  code: t,
57
72
  severity: i,
58
73
  range: { ...n },
59
- message: h(a),
60
- line: o.split("\n").length,
61
- column: n.start - s,
62
- messageKey: a.key,
63
- ...a.params ? { params: a.params } : {}
74
+ message: a(o),
75
+ line: s.split("\n").length,
76
+ column: n.start - c,
77
+ messageKey: o.key,
78
+ ...o.params ? { params: o.params } : {}
64
79
  };
65
80
  }
66
- function S(e, t = {}) {
67
- let n = f(e), i = me(n), a = typeof t == "object" && !!t && !Array.isArray(t), o = a ? t.fromVersion ?? i.effectiveVersion : i.effectiveVersion, s = typeof o == "string" ? o : "", c = {
81
+ function k(e, t = {}) {
82
+ let n = C(e), r = O(n), i = typeof t == "object" && !!t && !Array.isArray(t), a = i ? t.fromVersion ?? r.effectiveVersion : r.effectiveVersion, o = typeof a == "string" ? a : "", s = {
68
83
  ok: !1,
69
- fromVersion: s,
70
- toVersion: r,
71
- needsMigration: !n.versionDeclaration || s !== "local-draft-2",
72
- diagnostics: i.diagnostics.filter((e) => e.code !== "local.version.unsupported")
73
- }, l = {
74
- report: c,
84
+ fromVersion: o,
85
+ toVersion: _,
86
+ needsMigration: !n.versionDeclaration || o !== "local-draft-3",
87
+ diagnostics: r.diagnostics.filter((e) => e.code !== "local.version.unsupported")
88
+ }, c = {
89
+ report: s,
75
90
  declaration: n.versionDeclaration
76
91
  };
77
- if (typeof e != "string" || c.diagnostics.some((e) => e.severity === "error")) return l;
78
- let u = i.range ?? {
92
+ if (typeof e != "string" || s.diagnostics.some((e) => e.severity === "error")) return c;
93
+ let l = r.range ?? {
79
94
  start: 0,
80
95
  end: 0
81
- }, d = (e) => {
82
- if (c.diagnostics.length >= 100) {
96
+ }, u = (e) => {
97
+ if (s.diagnostics.length >= 100) {
83
98
  if (e.severity === "warning") return;
84
- let t = c.diagnostics.length - 1;
85
- for (; t >= 0 && c.diagnostics[t].severity !== "warning";) --t;
99
+ let t = s.diagnostics.length - 1;
100
+ for (; t >= 0 && s.diagnostics[t].severity !== "warning";) --t;
86
101
  if (t < 0) return;
87
- c.diagnostics.splice(t, 1);
102
+ s.diagnostics.splice(t, 1);
88
103
  }
89
- c.diagnostics.push(e);
90
- }, p = (t, n, r, i) => {
91
- d(ge(e, t, n, r, i));
104
+ s.diagnostics.push(e);
105
+ }, d = (t, n, r, i) => {
106
+ u(Me(e, t, n, r, i));
92
107
  };
93
- if (!a || typeof o != "string" || !["local-draft-1", "local-draft-2"].includes(s) || t.allowSemanticChanges !== void 0 && typeof t.allowSemanticChanges != "boolean" || t.fromVersion !== void 0 && i.declaredVersion !== null && s !== i.declaredVersion) return p("local.upgrade.from-version", u, {
94
- from: s,
95
- detail: "use local-draft-1 or local-draft-2 and match the source declaration"
96
- }), l;
97
- let m = n.versionDeclaration ? e.slice(0, u.start) + e.slice(u.start, u.end).replace(/[^\r\n]/g, " ") + e.slice(u.end) : e, h = n.versionDeclaration ? f(m) : n;
98
- if (s === "local-draft-1") {
99
- let e = (n) => {
100
- for (let r of n) {
101
- if (r.name && fe.has(r.name)) {
102
- p("local.upgrade.tag", r.range, { name: r.name });
103
- continue;
104
- }
105
- for (let e of [
106
- "bind",
107
- "bind-start",
108
- "bind-end",
109
- "bind-x",
110
- "bind-y"
111
- ]) {
112
- let t = r.attrs?.[e];
113
- t && de.has(t) && p("local.upgrade.reserved-binding", r.range, { name: t });
108
+ if (!i || typeof a != "string" || !Ae.has(o) || t.allowSemanticChanges !== void 0 && typeof t.allowSemanticChanges != "boolean" || t.fromVersion !== void 0 && r.declaredVersion !== null && o !== r.declaredVersion) return d("local.upgrade.from-version", l, {
109
+ from: o,
110
+ detail: "use local-draft-1, local-draft-2 or local-draft-3 and match the source declaration"
111
+ }), c;
112
+ let f = n.versionDeclaration ? e.slice(0, l.start) + e.slice(l.start, l.end).replace(/[^\r\n]/g, " ") + e.slice(l.end) : e, p = n.versionDeclaration ? C(f) : n;
113
+ if (o === "local-draft-1" || o === "local-draft-2") {
114
+ let e = o === "local-draft-1" ? Oe : ke, n = (r) => {
115
+ for (let i of r) if (i.name && e.has(i.name)) d("local.upgrade.tag", i.range, { name: i.name });
116
+ else {
117
+ if (o === "local-draft-1") {
118
+ for (let e of [
119
+ "bind",
120
+ "bind-start",
121
+ "bind-end",
122
+ "bind-x",
123
+ "bind-y"
124
+ ]) {
125
+ let t = i.attrs?.[e];
126
+ t && E.has(t) && d("local.upgrade.reserved-binding", i.range, { name: t });
127
+ }
128
+ (i.name === "input" || i.name === "textarea") && (i.attrs?.["max-length"] !== void 0 || Number(i.attrs?.["min-length"] ?? 0) > 0) && d("local.upgrade.text-length", i.range, void 0, t.allowSemanticChanges ? "warning" : "error");
129
+ let e = [...i.type === "interpolation" ? [i.value ?? ""] : [], ...Object.values(i.attrs ?? {}).flatMap((e) => [...e.matchAll(/\{\{([\s\S]*?)\}\}/g)].map((e) => e[1]))];
130
+ for (let t of e) {
131
+ let e = t.replace(/'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"/g, "");
132
+ (e.includes("[") || [...E].some((t) => RegExp(`\\b${t}\\s*\\(`).test(e))) && d("local.upgrade.expression", i.range);
133
+ }
114
134
  }
115
- (r.name === "input" || r.name === "textarea") && (r.attrs?.["max-length"] !== void 0 || Number(r.attrs?.["min-length"] ?? 0) > 0) && p("local.upgrade.text-length", r.range, void 0, t.allowSemanticChanges ? "warning" : "error");
116
- let n = [...r.type === "interpolation" ? [r.value ?? ""] : [], ...Object.values(r.attrs ?? {}).flatMap((e) => [...e.matchAll(/\{\{([\s\S]*?)\}\}/g)].map((e) => e[1]))];
117
- for (let e of n) {
118
- let t = e.replace(/'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"/g, "");
119
- (t.includes("[") || [...de].some((e) => RegExp(`\\b${e}\\s*\\(`).test(t))) && p("local.upgrade.expression", r.range);
120
- }
121
- r.type !== "fallback" && r.children && e(r.children);
135
+ i.type !== "fallback" && i.children && n(i.children);
122
136
  }
123
137
  };
124
- e(h.nodes);
138
+ n(p.nodes);
125
139
  }
126
- if (c.diagnostics.some((e) => e.severity === "error")) return l;
127
- let g = x(m);
128
- for (let e of g.diagnostics) d(e);
129
- return g.ok && (!n.versionDeclaration && c.diagnostics.length < 100 && p("local.upgrade.version-missing", {
140
+ if (s.diagnostics.some((e) => e.severity === "error")) return c;
141
+ let m = ee(f);
142
+ for (let e of m.diagnostics) u(e);
143
+ return m.ok && (!n.versionDeclaration && s.diagnostics.length < 100 && d("local.upgrade.version-missing", {
130
144
  start: +(e.charCodeAt(0) === 65279),
131
145
  end: +(e.charCodeAt(0) === 65279)
132
- }, { version: r }, "warning"), c.ok = !0), l;
146
+ }, { version: _ }, "warning"), s.ok = !0), c;
133
147
  }
134
- function _e(e, t) {
135
- return S(e, t).report;
148
+ function Ne(e, t) {
149
+ return k(e, t).report;
136
150
  }
137
- function ve(e, t) {
138
- let { report: n, declaration: r } = S(e, t), i = {
151
+ function Pe(e, t) {
152
+ let { report: n, declaration: r } = k(e, t), i = {
139
153
  ...n,
140
154
  source: e,
141
155
  changed: !1,
@@ -145,7 +159,7 @@ function ve(e, t) {
145
159
  let a = +(e.charCodeAt(0) === 65279), o = r?.range ?? {
146
160
  start: a,
147
161
  end: a
148
- }, s = e.includes("\r\n") ? "\r\n" : "\n", c = r ? pe : `${pe}${s}${s}`, l = e.slice(0, o.start) + c + e.slice(o.end);
162
+ }, s = e.includes("\r\n") ? "\r\n" : "\n", c = r ? D : `${D}${s}${s}`, l = e.slice(0, o.start) + c + e.slice(o.end);
149
163
  return {
150
164
  ...n,
151
165
  source: l,
@@ -156,525 +170,640 @@ function ve(e, t) {
156
170
  }]
157
171
  };
158
172
  }
159
- // src/local/state.ts
160
- var C = "reactive-md-state/v1", w = 1048576, ye = /^fnv1a32:[0-9a-f]{8}$/, be = 2166136261, xe = 16777619, Se = /* @__PURE__ */ new Set([
161
- "format",
162
- "syntax",
163
- "sourceDigest",
164
- "parameters",
165
- "generator"
166
- ]), Ce = /* @__PURE__ */ new Set(["name", "version"]), T = new TextEncoder();
167
- function E(e, t) {
168
- return {
169
- code: e,
170
- message: t.length > 2e3 ? `${t.slice(0, m - 1)}…` : t,
171
- severity: "error",
172
- range: {
173
- start: 0,
174
- end: 0
175
- },
176
- line: 1,
177
- column: 1
178
- };
173
+ // src/local/transport/compile-patch.ts
174
+ var A = "patch-v1", j = 1, Fe = 4096, M = [
175
+ "initialState",
176
+ "bindings",
177
+ "bindingSlots",
178
+ "computations",
179
+ "dependencies",
180
+ "tableShapes"
181
+ ];
182
+ function N(e) {
183
+ return typeof e == "object" && !!e && !Array.isArray(e);
179
184
  }
180
- function D(e, t, n) {
181
- e.length < 100 && e.push(E(t, n));
185
+ function P(e) {
186
+ return N(e) && typeof e.start == "number" && Number.isFinite(e.start) && typeof e.end == "number" && Number.isFinite(e.end);
182
187
  }
183
- function O(e) {
184
- return e instanceof Error ? e.message : String(e);
188
+ function F() {
189
+ throw TypeError("Invalid local compile result patch");
185
190
  }
186
- function k(e) {
187
- for (let t = 0; t < e.length; t += 1) {
188
- let n = e.charCodeAt(t);
189
- if (n >= 55296 && n <= 56319) {
190
- let n = e.charCodeAt(t + 1);
191
- if (n >= 56320 && n <= 57343) {
192
- t += 1;
193
- continue;
194
- }
195
- return !1;
196
- }
197
- if (n >= 56320 && n <= 57343) return !1;
191
+ function I(e, t) {
192
+ if (e === t) return !0;
193
+ if (typeof e != "object" || typeof t != "object" || e === null || t === null) return !1;
194
+ let n = Array.isArray(e);
195
+ if (n !== Array.isArray(t)) return !1;
196
+ if (n) {
197
+ let n = e, r = t;
198
+ if (n.length !== r.length) return !1;
199
+ for (let e = 0; e < n.length; e += 1) if (!I(n[e], r[e])) return !1;
200
+ return !0;
198
201
  }
202
+ let r = e, i = t, a = Object.keys(r);
203
+ if (a.length !== Object.keys(i).length) return !1;
204
+ for (let e of a) if (!Object.hasOwn(i, e) || !I(r[e], i[e])) return !1;
199
205
  return !0;
200
206
  }
201
- function A(e) {
202
- if (typeof e != "string") throw TypeError("localSourceDigest requires a source string.");
203
- let t = T.encode(e), n = be;
204
- for (let e = 0; e < t.length; e += 1) n ^= t[e], n = Math.imul(n, xe) >>> 0;
205
- return `fnv1a32:${n.toString(16).padStart(8, "0")}`;
207
+ function L(e) {
208
+ return r(e, !1);
206
209
  }
207
- function j(e) {
208
- if (typeof e == "string") return k(e) ? {
209
- ok: !0,
210
- value: e
211
- } : {
212
- ok: !1,
213
- message: "contains malformed Unicode."
214
- };
215
- if (typeof e == "number") return Number.isFinite(e) ? {
216
- ok: !0,
217
- value: e
218
- } : {
219
- ok: !1,
220
- message: "must be a finite number."
221
- };
222
- if (typeof e == "boolean" || e === null) return {
223
- ok: !0,
224
- value: e
225
- };
226
- if (Array.isArray(e)) {
227
- let t = [];
228
- for (let n = 0; n < e.length; n += 1) {
229
- let r = e[n];
230
- if (typeof r != "string") return {
231
- ok: !1,
232
- message: "must be an array of strings."
233
- };
234
- if (!k(r)) return {
235
- ok: !1,
236
- message: "contains malformed Unicode."
237
- };
238
- t.push(r);
239
- }
240
- return {
241
- ok: !0,
242
- value: Object.freeze(t)
243
- };
244
- }
210
+ function R(e, t) {
211
+ if (typeof e != "string" || typeof t != "string" || e === t) return null;
212
+ let n = Math.min(e.length, t.length), r = 0;
213
+ for (; r < n && e.charCodeAt(r) === t.charCodeAt(r);) r += 1;
214
+ let i = e.length, a = t.length;
215
+ for (; i > r && a > r && e.charCodeAt(i - 1) === t.charCodeAt(a - 1);) --i, --a;
245
216
  return {
246
- ok: !1,
247
- message: "must be a string, finite number, boolean, null or string array."
217
+ from: r,
218
+ to: i,
219
+ insert: t.slice(r, a)
248
220
  };
249
221
  }
250
- function M(e) {
251
- if (typeof e != "object" || !e || Array.isArray(e)) return !1;
252
- let t = Object.getPrototypeOf(e);
253
- return t === Object.prototype || t === null;
254
- }
255
- function N(e) {
256
- return Object.freeze(e.parameters), e.generator && Object.freeze(e.generator), Object.freeze(e);
222
+ function Ie(e) {
223
+ if (!N(e)) return null;
224
+ let { from: t, to: n, insert: r } = e;
225
+ return typeof t != "number" || !Number.isSafeInteger(t) || typeof n != "number" || !Number.isSafeInteger(n) || typeof r != "string" || t < 0 || n < t ? null : {
226
+ from: t,
227
+ to: n,
228
+ insert: r
229
+ };
257
230
  }
258
- function P(e) {
259
- if (!e || typeof e != "object" || Array.isArray(e)) throw TypeError("generator must be an object with string name and version.");
260
- if (typeof e.name != "string" || typeof e.version != "string") throw TypeError("generator must have string name and version.");
261
- if (!k(e.name) || !k(e.version)) throw TypeError("generator name and version must be well-formed Unicode strings.");
262
- return Object.freeze({
263
- name: e.name,
264
- version: e.version
265
- });
231
+ function Le(e, t) {
232
+ let n = Ie(t);
233
+ return n === null || typeof e != "string" || n.to > e.length ? null : e.slice(0, n.from) + n.insert + e.slice(n.to);
266
234
  }
267
- function F(e) {
268
- return typeof e == "string" ? `"${e.length > 48 ? `${e.slice(0, 48)}…` : e}"` : e === null ? "null" : Array.isArray(e) ? "an array" : typeof e;
235
+ function z(e) {
236
+ let t = {};
237
+ for (let [n, r] of Object.entries(e)) n !== "children" && (t[n] = r);
238
+ return t;
269
239
  }
270
- function I(e, t) {
271
- return e.length > t ? e.length : T.encode(e).byteLength;
240
+ function Re(e, t) {
241
+ let n = Object.keys(e).filter((e) => e !== "children"), r = Object.keys(t).filter((e) => e !== "children");
242
+ if (n.length !== r.length) return !1;
243
+ for (let r of n) if (!Object.hasOwn(t, r) || !I(e[r], t[r])) return !1;
244
+ return !0;
272
245
  }
273
- function we(e, t) {
274
- let n;
275
- try {
276
- let t = JSON.stringify(e);
277
- if (typeof t != "string") return null;
278
- n = t;
279
- } catch {
280
- return null;
281
- }
282
- return I(n, t);
246
+ function B(e) {
247
+ return e.children === void 0 ? void 0 : e.children.map((e) => e.id);
283
248
  }
284
- function Te(e) {
285
- if (e === void 0) return w;
286
- if (typeof e != "object" || !e) throw TypeError("parseLocalState options must be an object.");
287
- let { maxLength: t } = e;
288
- if (t === void 0) return w;
289
- if (typeof t != "number" || !Number.isSafeInteger(t) || t <= 0) throw RangeError("maxLength must be a finite positive integer.");
290
- return t;
249
+ function ze(e, t) {
250
+ let n = B(e), r = B(t);
251
+ if (n === void 0 || r === void 0) return n === r;
252
+ if (n.length !== r.length) return !1;
253
+ for (let e = 0; e < n.length; e += 1) if (n[e] !== r[e]) return !1;
254
+ return !0;
291
255
  }
292
- function L(e, t, n) {
293
- if (!e || e.syntax !== "local" || typeof e.source != "string") throw TypeError("createLocalStateFile requires a compiled local document.");
294
- if (!t || typeof t != "object" || Array.isArray(t)) throw TypeError("createLocalStateFile requires a state object.");
295
- let i = Object.keys(e.bindings).filter((e) => !e.startsWith("@")).sort(), a = new Set(i), o = /* @__PURE__ */ new Map();
296
- for (let n of Object.keys(t)) {
297
- if (Object.hasOwn(e.computations ?? {}, n)) continue;
298
- if (n.startsWith("@")) {
299
- if (!Object.hasOwn(e.bindings, n)) throw Error(`Cannot persist parameter "${n}": it is not a binding of this document.`);
300
- continue;
301
- }
302
- if (!a.has(n)) throw Error(`Cannot persist parameter "${n}": it is not a public binding of this document.`);
303
- let r = j(t[n]);
304
- if (!r.ok) throw TypeError(`Cannot persist parameter "${n}": the value ${r.message}`);
305
- o.set(n, r.value);
306
- }
307
- let s = {};
308
- for (let e of i) {
309
- if (!o.has(e)) throw Error(`Cannot persist the document: parameter "${e}" is missing from the supplied state.`);
310
- s[e] = o.get(e);
311
- }
312
- let c = {
313
- format: C,
314
- syntax: r,
315
- sourceDigest: A(e.source),
316
- parameters: s
317
- };
318
- return n !== void 0 && (c.generator = P(n)), N(c);
256
+ function Be(e, t) {
257
+ if (!Re(e, t) || !ze(e, t)) return !1;
258
+ if (!e.children || !t.children) return !0;
259
+ for (let n = 0; n < e.children.length; n += 1) if (!Be(e.children[n], t.children[n])) return !1;
260
+ return !0;
319
261
  }
320
- function Ee(e, t) {
321
- let n = [], i = (e, t) => D(n, e, t), a = e;
322
- if (typeof e == "string") {
323
- if (I(e, t) > t) return {
324
- ok: !1,
325
- diagnostics: [E("local.state.size", `The state payload exceeds the ${t}-byte limit.`)]
326
- };
327
- if (!k(e)) return {
328
- ok: !1,
329
- diagnostics: [E("local.state.utf", "The state payload contains malformed Unicode.")]
330
- };
331
- try {
332
- a = JSON.parse(e);
333
- } catch (e) {
334
- return {
335
- ok: !1,
336
- diagnostics: [E("local.state.json", `The state payload is not valid JSON: ${O(e)}`)]
337
- };
338
- }
262
+ function Ve(e, t) {
263
+ let n = Object.keys(e).filter((e) => e !== "children" && e !== "range"), r = Object.keys(t).filter((e) => e !== "children" && e !== "range");
264
+ if (n.length !== r.length) return null;
265
+ for (let r of n) if (!Object.hasOwn(t, r) || !I(e[r], t[r])) return null;
266
+ if (!P(e.range) || !P(t.range)) return null;
267
+ let i = e.range.start - t.range.start;
268
+ if (e.range.end !== t.range.end + i) return null;
269
+ let a = B(e), o = B(t);
270
+ if (a === void 0 || o === void 0) {
271
+ if (a !== o) return null;
339
272
  } else {
340
- let n = we(e, t);
341
- if (n === null) return {
342
- ok: !1,
343
- diagnostics: [E("local.state.shape", "The state payload must be a JSON object.")]
344
- };
345
- if (n > t) return {
346
- ok: !1,
347
- diagnostics: [E("local.state.size", `The state payload exceeds the ${t}-byte limit.`)]
348
- };
273
+ if (a.length !== o.length) return null;
274
+ for (let n = 0; n < a.length; n += 1) if (a[n] !== o[n] || Ve(e.children[n], t.children[n]) !== i) return null;
349
275
  }
350
- if (!M(a)) return {
351
- ok: !1,
352
- diagnostics: [E("local.state.shape", "The state payload must be a JSON object.")]
353
- };
354
- Object.getOwnPropertySymbols(a).length > 0 && i("local.state.shape", "The state payload cannot use symbol keys.");
355
- for (let e of Object.keys(a)) Se.has(e) || i("local.state.key", `Unknown top-level state key "${e}".`);
356
- let o = a.format;
357
- o !== "reactive-md-state/v1" && i("local.state.format", `Unsupported state format ${F(o)}; expected "${C}".`);
358
- let s = a.syntax;
359
- s !== "local-draft-2" && i("local.state.syntax", `Unsupported state syntax ${F(s)}; expected "${r}".`);
360
- let c = a.sourceDigest;
361
- typeof c == "string" && ye.test(c) || i("local.state.digest", "sourceDigest must match \"fnv1a32:\" followed by 8 lowercase hexadecimal digits.");
362
- let l = {}, u = a.parameters;
363
- if (!M(u)) i("local.state.parameters", "parameters must be a JSON object of public binding values.");
364
- else for (let e of Object.keys(u).sort()) {
365
- if (e === "__proto__") {
366
- i("local.state.parameter.prototype", "Parameter names cannot be \"__proto__\".");
367
- continue;
368
- }
369
- if (e.startsWith("@")) {
370
- i("local.state.parameter.internal", `Internal parameter "${e}" cannot be persisted.`);
371
- continue;
372
- }
373
- let t = j(u[e]);
374
- t.ok ? l[e] = t.value : i("local.state.parameter.value", `Parameter "${e}" ${t.message}`);
375
- }
376
- let d;
377
- if (Object.hasOwn(a, "generator")) {
378
- let e = a.generator;
379
- if (!M(e)) i("local.state.generator", "generator must be an object with string name and version.");
380
- else {
381
- for (let t of Object.keys(e)) Ce.has(t) || i("local.state.generator", `generator has unknown key "${t}".`);
382
- typeof e.name != "string" || typeof e.version != "string" ? i("local.state.generator", "generator must have string name and version.") : !k(e.name) || !k(e.version) ? i("local.state.utf", "generator contains malformed Unicode.") : d = Object.freeze({
383
- name: e.name,
384
- version: e.version
385
- });
386
- }
387
- }
388
- if (n.length) return {
389
- ok: !1,
390
- diagnostics: n
391
- };
392
- let f = {
393
- format: C,
394
- syntax: r,
395
- sourceDigest: c,
396
- parameters: l
397
- };
398
- return d && (f.generator = d), {
399
- ok: !0,
400
- file: N(f)
401
- };
276
+ return i;
402
277
  }
403
- function R(e, t) {
404
- let n = Te(t);
405
- try {
406
- return Ee(e, n);
407
- } catch (e) {
408
- return {
409
- ok: !1,
410
- diagnostics: [E("local.state.invalid", `Cannot read the local state: ${O(e)}`)]
411
- };
278
+ function He(e, t) {
279
+ let n = Object.keys(e).filter((e) => e !== "children" && e !== "range"), r = Object.keys(t).filter((e) => e !== "children" && e !== "range");
280
+ if (n.length !== r.length) return null;
281
+ for (let r of n) if (!Object.hasOwn(t, r) || !I(e[r], t[r])) return null;
282
+ if (!P(e.range) || !P(t.range)) return null;
283
+ let i = e.range.start - t.range.start;
284
+ return e.range.end === t.range.end + i ? i : null;
285
+ }
286
+ function Ue(e) {
287
+ let t = /* @__PURE__ */ new Map(), n = [...e].reverse();
288
+ for (; n.length > 0;) {
289
+ let e = n.pop();
290
+ if (t.set(e.id, e), e.children) for (let t = e.children.length - 1; t >= 0; --t) n.push(e.children[t]);
412
291
  }
292
+ return t;
413
293
  }
414
- function De(e) {
415
- let t = /* @__PURE__ */ new Map(), n = (e) => {
416
- for (let r of e) t.set(r.id, r), r.children && n(r.children);
417
- };
418
- return n(e.nodes), t;
419
- }
420
- function z(e) {
421
- let t = De(e), n = /* @__PURE__ */ new Map(), r = [];
422
- for (let [i, a] of Object.entries(e.bindingSlots ?? {})) {
423
- let e = t.get(i);
424
- if (!e) continue;
425
- let o = {
426
- node: e,
427
- slots: []
428
- };
429
- for (let [t, r] of Object.entries(a)) o.slots.push({
430
- slot: t,
431
- key: r
432
- }), r.startsWith("@") || n.set(r, {
433
- node: e,
434
- slot: t
294
+ function We(e, t, n, r) {
295
+ if (t !== void 0 && Be(e, t)) return;
296
+ if (t === void 0) {
297
+ r.push({
298
+ id: e.id,
299
+ node: e
435
300
  });
436
- o.slots.length && r.push(o);
301
+ return;
437
302
  }
438
- let i = [];
439
- for (let [r, a] of Object.entries(e.bindings)) {
440
- if (r.startsWith("@")) continue;
441
- let e = n.get(r);
442
- if (e) {
443
- i.push({
444
- key: r,
445
- binding: a,
446
- node: e.node,
447
- slot: e.slot
448
- });
449
- continue;
450
- }
451
- let o = a.owner && t.has(a.owner) ? a.owner : a.nodeIds.find((e) => t.has(e));
452
- i.push({
453
- key: r,
454
- binding: a,
455
- node: o ? t.get(o) : void 0
303
+ let i = Ve(e, t);
304
+ if (i !== null) {
305
+ i !== 0 && r.push({
306
+ id: e.id,
307
+ shift: i,
308
+ subtree: !0
456
309
  });
310
+ return;
457
311
  }
458
- return {
459
- plans: i,
460
- groups: r
461
- };
462
- }
463
- function B(e, t, n) {
464
- let r = [];
465
- for (let i of t.plans) i.slot === void 0 && Object.hasOwn(n, i.key) && (i.node ? Object.is(e.get(i.node), n[i.key]) || r.push(...e.set(i.node, n[i.key])) : r.push(E("local.state.document", `The document has no component for parameter "${i.key}".`)));
466
- for (let i of t.groups) {
467
- let t = {}, a = !1;
468
- for (let { slot: e, key: r } of i.slots) Object.hasOwn(n, r) && (t[e] = n[r], a = !0);
469
- a && r.push(...e.setMany(i.node, t));
312
+ let a = { id: e.id };
313
+ if (!Re(e, t)) {
314
+ let n = He(e, t);
315
+ n !== null && n !== 0 ? a.shift = n : a.data = z(e);
470
316
  }
471
- return r;
317
+ ze(e, t) || (a.children = e.children === void 0 ? null : e.children.map((e) => e.id));
318
+ let o = r.length;
319
+ if (e.children) for (let t of e.children) We(t, n.get(t.id), n, r);
320
+ Object.keys(a).length > 1 ? r.splice(o, 0, a) : r.length > o && r.splice(o, 0, { id: e.id });
321
+ }
322
+ function Ge(e, t) {
323
+ if (!N(e)) return { set: t };
324
+ let n = {}, r = [];
325
+ for (let [r, i] of Object.entries(t)) Object.hasOwn(e, r) && I(e[r], i) || (n[r] = i);
326
+ for (let n of Object.keys(e)) Object.hasOwn(t, n) || r.push(n);
327
+ return Object.keys(n).length === 0 && r.length === 0 ? null : {
328
+ ...Object.keys(n).length === 0 ? {} : { set: n },
329
+ ...r.length === 0 ? {} : { remove: r }
330
+ };
472
331
  }
473
- function Oe(e, t) {
474
- let n = e.snapshot(), r = {};
475
- for (let e of t) {
476
- let t = n.state[e];
477
- r[e] = Array.isArray(t) ? Object.freeze([...t]) : t;
332
+ var Ke = /* @__PURE__ */ new WeakMap();
333
+ function qe(e) {
334
+ let t = 2;
335
+ for (let n = 0; n < e.length; n++) {
336
+ let r = e.charCodeAt(n);
337
+ if (r === 34 || r === 92) t += 2;
338
+ else if (r < 32) t += r === 8 || r === 9 || r === 10 || r === 12 || r === 13 ? 2 : 6;
339
+ else if (r < 128) t++;
340
+ else if (r < 2048) t += 2;
341
+ else if (r >= 55296 && r <= 56319) {
342
+ let r = e.charCodeAt(n + 1);
343
+ r >= 56320 && r <= 57343 ? (t += 4, n++) : t += 6;
344
+ } else t += r >= 56320 && r <= 57343 ? 6 : 3;
478
345
  }
479
- return Object.freeze(r);
346
+ return t;
480
347
  }
481
- function V(e, t, n, i) {
482
- let a = R(t, i);
483
- if (!a.ok) return a;
484
- if (!e || e.syntax !== "local" || typeof e.source != "string" || !Array.isArray(e.nodes) || !e.bindings) return {
485
- ok: !1,
486
- diagnostics: [E("local.state.document", "resolveLocalState requires a compiled local document.")]
348
+ function V(e, t) {
349
+ if (e === null) return {
350
+ bytes: 4,
351
+ nodes: 0
487
352
  };
488
- if (a.file.syntax !== "local-draft-2") return {
489
- ok: !1,
490
- diagnostics: [E("local.state.syntax", `This state file uses syntax "${a.file.syntax}", but this build accepts "${r}".`)]
353
+ let n = typeof e;
354
+ if (n === "string") return {
355
+ bytes: qe(e),
356
+ nodes: 0
491
357
  };
492
- if (a.file.sourceDigest !== A(e.source)) return {
493
- ok: !1,
494
- diagnostics: [E("local.state.source", "This state file was created for a different document (source digest mismatch).")]
358
+ if (n === "number") return {
359
+ bytes: Number.isFinite(e) ? String(e).length : 4,
360
+ nodes: 0
495
361
  };
496
- let o = z(e), s = new Set(o.plans.map((e) => e.key)), c = [];
497
- for (let e of Object.keys(a.file.parameters)) s.has(e) || D(c, "local.state.parameter.unknown", `The state contains unknown parameter "${e}" for this document.`);
498
- for (let e of s) Object.hasOwn(a.file.parameters, e) || D(c, "local.state.parameter.missing", `The state is missing parameter "${e}".`);
499
- if (c.length) return {
500
- ok: !1,
501
- diagnostics: c
362
+ if (n === "boolean") return {
363
+ bytes: e === !0 ? 4 : 5,
364
+ nodes: 0
502
365
  };
503
- let l;
504
- try {
505
- l = ue(e);
506
- } catch (e) {
507
- return {
508
- ok: !1,
509
- diagnostics: [E("local.state.document", `Cannot validate this document: ${O(e)}`)]
510
- };
366
+ if (n !== "object") return {
367
+ bytes: 0,
368
+ nodes: 0
369
+ };
370
+ let r = e, i = Ke.get(r);
371
+ if (i !== void 0) return i;
372
+ if (t.has(r)) return {
373
+ bytes: 0,
374
+ nodes: 0
375
+ };
376
+ t.add(r);
377
+ let a, o = +!!et(e);
378
+ if (Array.isArray(e)) {
379
+ a = 2;
380
+ for (let n = 0; n < e.length; n += 1) {
381
+ n > 0 && (a += 1);
382
+ let r = V(e[n], t);
383
+ a += r.bytes || 4, o += r.nodes;
384
+ }
385
+ } else {
386
+ a = 2;
387
+ let e = 0;
388
+ for (let n in r) {
389
+ if (!Object.hasOwn(r, n)) continue;
390
+ let i = r[n];
391
+ if (i === void 0) continue;
392
+ e > 0 && (a += 1), e += 1, a += qe(n) + 1;
393
+ let s = V(i, t);
394
+ a += s.bytes, o += s.nodes;
395
+ }
511
396
  }
397
+ t.delete(r);
398
+ let s = {
399
+ bytes: a,
400
+ nodes: o
401
+ };
402
+ return Ke.set(r, s), s;
403
+ }
404
+ function Je(e, t) {
405
+ let n = e.document.nodes ?? [];
512
406
  try {
513
- if (n) {
514
- let e = B(l, o, n);
515
- if (e.length) return {
516
- ok: !1,
517
- diagnostics: e
518
- };
519
- }
520
- let e = B(l, o, a.file.parameters);
521
- if (e.length) return {
522
- ok: !1,
523
- diagnostics: e
407
+ let r = V(e, /* @__PURE__ */ new Set()), i = t.ok && typeof t.document.source == "string" ? t.document.source.length : 0;
408
+ if (r.bytes <= Math.max(i, Fe)) return {
409
+ patchBytes: r.bytes,
410
+ patchNodes: n.length,
411
+ preferFull: !1
524
412
  };
525
- let t = [...s].sort();
413
+ let a = V(t, /* @__PURE__ */ new Set()), o = 0;
414
+ for (let e of n) e.node === void 0 ? e.data !== void 0 && (o += 1) : o += V(e.node, /* @__PURE__ */ new Set()).nodes;
415
+ let s = r.bytes * j >= a.bytes, c = a.nodes > 0 && o * j >= a.nodes;
526
416
  return {
527
- ok: !0,
528
- file: a.file,
529
- state: Oe(l, t)
417
+ patchBytes: r.bytes,
418
+ fullBytes: a.bytes,
419
+ patchNodes: n.length,
420
+ fullNodes: a.nodes,
421
+ preferFull: s || c,
422
+ ...s ? { reason: "bytes" } : c ? { reason: "nodes" } : {}
530
423
  };
531
- } finally {
532
- l.dispose();
533
- }
534
- }
535
- function H(e, t, n) {
536
- try {
537
- return V(e, t, void 0, n);
538
- } catch (e) {
424
+ } catch {
539
425
  return {
540
- ok: !1,
541
- diagnostics: [E("local.state.invalid", `Cannot resolve the local state: ${O(e)}`)]
426
+ patchBytes: 0,
427
+ patchNodes: n.length,
428
+ preferFull: !1
542
429
  };
543
430
  }
544
431
  }
545
- function U(e, t, n) {
546
- let r;
547
- try {
548
- r = V(e.document, t, e.snapshot().state, n);
549
- } catch (e) {
550
- return [E("local.state.invalid", `Cannot apply the local state: ${O(e)}`)];
551
- }
552
- if (!r.ok) return r.diagnostics;
553
- let i = z(e.document);
554
- try {
555
- return B(e, i, r.state);
556
- } catch (e) {
557
- return [E("local.state.invalid", `Cannot apply the local state: ${O(e)}`)];
558
- }
432
+ function Ye(e, t) {
433
+ return Qe(e, t);
559
434
  }
560
- function ke(e, t) {
561
- return L(e.document, e.getParameters(), t);
435
+ function Xe(e, t) {
436
+ let n = Qe(e, t);
437
+ return n ? {
438
+ patch: n,
439
+ cost: Je(n, t)
440
+ } : null;
562
441
  }
563
- function Ae(e, t, n) {
564
- let r = R(t, n);
565
- return r.ok ? U(e, r.file, n) : r.diagnostics;
442
+ function Ze(e, t) {
443
+ let n = e.recoveries, r = t.recoveries;
444
+ return n === void 0 ? r === void 0 ? {} : { recoveries: r } : r !== void 0 && I(n, r) ? {} : { recoveries: r === void 0 ? null : r };
566
445
  }
567
- function je(e) {
568
- if (!e || typeof e != "object" || Array.isArray(e)) throw TypeError("serializeLocalState requires a state file.");
569
- if (!e.parameters || typeof e.parameters != "object" || Array.isArray(e.parameters)) throw TypeError("serializeLocalState requires an object of parameters.");
570
- let t = Object.create(null);
571
- for (let n of Object.keys(e.parameters).sort()) {
572
- if (n === "__proto__" || n.startsWith("@")) throw TypeError(`Cannot serialize parameter "${n}".`);
573
- let r = j(e.parameters[n]);
574
- if (!r.ok) throw TypeError(`Cannot serialize parameter "${n}": the value ${r.message}`);
575
- t[n] = r.value;
576
- }
577
- let n = {
578
- format: e.format,
579
- syntax: e.syntax,
580
- sourceDigest: e.sourceDigest,
581
- parameters: t
582
- };
583
- if (e.generator !== void 0) {
584
- let t = P(e.generator);
585
- n.generator = {
586
- name: t.name,
587
- version: t.version
446
+ function Qe(e, t) {
447
+ try {
448
+ if (!e.ok || !t.ok) return null;
449
+ let n = e.document, r = t.document;
450
+ if (!N(n) || !N(r)) return null;
451
+ let i = {};
452
+ if (typeof n.source == "string" && typeof r.source == "string") {
453
+ let e = R(n.source, r.source);
454
+ e !== null && (i.source = e);
455
+ } else if (n.source !== r.source) return null;
456
+ let a = [], o = {}, s = {}, c = new Set(M), l = /* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(r)]);
457
+ for (let e of l) {
458
+ if (e === "source" || e === "nodes" || c.has(e)) continue;
459
+ let t = Object.hasOwn(r, e) && r[e] !== void 0, i = Object.hasOwn(n, e) && n[e] !== void 0;
460
+ t ? i && I(n[e], r[e]) || (o[e] = r[e]) : i && a.push(e);
461
+ }
462
+ for (let e of M) {
463
+ let t = Object.hasOwn(r, e) && r[e] !== void 0, i = Object.hasOwn(n, e) && n[e] !== void 0, c = i ? n[e] : void 0, l = t ? r[e] : void 0;
464
+ if (!t) {
465
+ i && a.push(e);
466
+ continue;
467
+ }
468
+ if (!N(l)) {
469
+ i && I(c, l) || (o[e] = l);
470
+ continue;
471
+ }
472
+ if (!i) {
473
+ s[e] = { set: l };
474
+ continue;
475
+ }
476
+ if (!N(c)) {
477
+ o[e] = l;
478
+ continue;
479
+ }
480
+ let u = Ge(c, l);
481
+ u !== null && (s[e] = u);
482
+ }
483
+ let u = Array.isArray(n.nodes) ? n.nodes : [], d = Array.isArray(r.nodes) ? r.nodes : [], f = u.map((e) => e.id), p = d.map((e) => e.id), m = f.length !== p.length;
484
+ if (!m) {
485
+ for (let e = 0; e < f.length; e += 1) if (f[e] !== p[e]) {
486
+ m = !0;
487
+ break;
488
+ }
489
+ }
490
+ let h = [], g = Ue(u);
491
+ for (let e of d) We(e, g.get(e.id), g, h);
492
+ return m && (i.roots = p), h.length > 0 && (i.nodes = h), a.length > 0 && (i.removed = a), Object.keys(o).length > 0 && (i.values = o), Object.keys(s).length > 0 && (i.records = s), {
493
+ kind: "result-patch",
494
+ protocol: A,
495
+ document: i,
496
+ ...I(e.diagnostics, t.diagnostics) ? {} : { diagnostics: t.diagnostics },
497
+ ...Ze(e, t)
588
498
  };
499
+ } catch {
500
+ return null;
589
501
  }
590
- return JSON.stringify(n);
591
- }
592
- // src/local/retention.ts
593
- function Me(e) {
594
- let t = /* @__PURE__ */ new Map(), n = (e) => {
595
- for (let r of e) t.set(r.id, r), r.children && n(r.children);
596
- };
597
- return n(e.nodes), t;
598
502
  }
599
- function Ne(e, t, n) {
600
- let r = e.bindingSlots?.[t.id];
601
- return r !== void 0 && Object.values(r).includes(n);
602
- }
603
- function Pe(e) {
604
- let t = Me(e), n = /* @__PURE__ */ new Map();
605
- for (let [r, i] of Object.entries(e.bindings)) {
606
- let a = i.nodeIds.flatMap((e) => {
607
- let n = t.get(e);
608
- return n ? [n] : [];
609
- });
610
- if (!a.length || r.startsWith("@") || a.some((t) => t.attrs?.bind !== r && !Ne(e, t, r) || t.name === "timer" || t.name === "checklist")) continue;
611
- let o = a.flatMap((e) => Object.hasOwn(e.attrs ?? {}, "initial") ? [e.attrs.initial] : []).sort();
612
- n.set(r, {
613
- type: i.type,
614
- initialDefinition: JSON.stringify([i.initial, o])
615
- });
616
- }
617
- return n;
503
+ function $e(e, t) {
504
+ let n = z(e);
505
+ return P(n.range) || F(), n.range = {
506
+ start: n.range.start + t,
507
+ end: n.range.end + t
508
+ }, e.children && (n.children = e.children.map((e) => $e(e, t))), n;
618
509
  }
619
- function W(e, t) {
620
- return Object.freeze({
621
- name: e,
622
- reason: t
510
+ function et(e) {
511
+ return N(e) && typeof e.id == "string" && typeof e.type == "string" && P(e.range);
512
+ }
513
+ function tt(e, t) {
514
+ N(t) || F(), t.set !== void 0 && !N(t.set) && F(), t.remove !== void 0 && !Array.isArray(t.remove) && F();
515
+ let n = {};
516
+ if (N(e)) for (let [t, r] of Object.entries(e)) Object.defineProperty(n, t, {
517
+ value: r,
518
+ enumerable: !0,
519
+ configurable: !0,
520
+ writable: !0
521
+ });
522
+ else e !== void 0 && F();
523
+ if (t.set) for (let [e, r] of Object.entries(t.set)) Object.defineProperty(n, e, {
524
+ value: L(r),
525
+ enumerable: !0,
526
+ configurable: !0,
527
+ writable: !0
623
528
  });
529
+ if (t.remove) for (let e of t.remove) typeof e != "string" && F(), delete n[e];
530
+ return n;
624
531
  }
625
- function Fe(e) {
626
- let t = Pe(e.previous), n = Pe(e.next), r = {}, i = [], a = [];
627
- for (let o of Object.keys(e.state).sort()) {
628
- if (o.startsWith("@")) {
629
- a.push(W(o, "internal"));
630
- continue;
532
+ function nt(e, t) {
533
+ try {
534
+ if (!e.ok || !N(t) || t.kind !== "result-patch" || t.protocol !== "patch-v1") return null;
535
+ let n = t.document;
536
+ if (!N(n)) return null;
537
+ let r = e.document;
538
+ if (!N(r)) return null;
539
+ let i = {};
540
+ for (let [e, t] of Object.entries(r)) Object.defineProperty(i, e, {
541
+ value: t,
542
+ enumerable: !0,
543
+ configurable: !0,
544
+ writable: !0
545
+ });
546
+ if (n.removed !== void 0) {
547
+ if (!Array.isArray(n.removed)) return null;
548
+ for (let e of n.removed) {
549
+ if (typeof e != "string" || e === "nodes" || e === "source") return null;
550
+ delete i[e];
551
+ }
631
552
  }
632
- if (!Object.hasOwn(e.previous.bindings, o) || !Object.hasOwn(e.next.bindings, o)) {
633
- a.push(W(o, "unknown"));
634
- continue;
553
+ if (n.values !== void 0) {
554
+ if (!N(n.values)) return null;
555
+ for (let [e, t] of Object.entries(n.values)) {
556
+ if (e === "nodes" || e === "source") return null;
557
+ Object.defineProperty(i, e, {
558
+ value: L(t),
559
+ enumerable: !0,
560
+ configurable: !0,
561
+ writable: !0
562
+ });
563
+ }
635
564
  }
636
- let s = t.get(o), c = n.get(o);
637
- if (!s || !c) {
638
- a.push(W(o, "unretainable"));
639
- continue;
565
+ if (n.records !== void 0) {
566
+ if (!N(n.records)) return null;
567
+ for (let e of Object.keys(n.records)) {
568
+ if (!M.includes(e)) return null;
569
+ let t = n.records[e];
570
+ t !== void 0 && (i[e] = tt(r[e], t));
571
+ }
572
+ }
573
+ let a = typeof r.source == "string" ? r.source : null;
574
+ if (a === null) return null;
575
+ if (n.source !== void 0) {
576
+ let e = Ie(n.source);
577
+ if (e === null) return null;
578
+ let t = Le(a, e);
579
+ if (t === null) return null;
580
+ a = t;
581
+ }
582
+ i.source = a;
583
+ let o = Array.isArray(r.nodes) ? r.nodes : [], s = Ue(o), c = /* @__PURE__ */ new Map();
584
+ if (n.nodes !== void 0) {
585
+ if (!Array.isArray(n.nodes)) return null;
586
+ for (let e of n.nodes) {
587
+ if (!N(e) || typeof e.id != "string" || c.has(e.id)) return null;
588
+ c.set(e.id, e);
589
+ }
590
+ }
591
+ let l;
592
+ if (n.roots !== void 0) {
593
+ if (!Array.isArray(n.roots)) return null;
594
+ l = [];
595
+ for (let e of n.roots) {
596
+ if (typeof e != "string") return null;
597
+ l.push(e);
598
+ }
599
+ } else l = o.map((e) => e.id);
600
+ let u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Set(), f = (e) => {
601
+ let t = u.get(e);
602
+ if (t !== void 0) return t;
603
+ d.has(e) && F();
604
+ let n = c.get(e), r = s.get(e);
605
+ if (n === void 0) return r === void 0 && F(), u.set(e, r), r;
606
+ if (N(n) || F(), n.node !== void 0) {
607
+ (n.data !== void 0 || n.children !== void 0 || n.shift !== void 0 || n.subtree) && F(), et(n.node) && n.node.id === e || F();
608
+ let t = L(n.node);
609
+ return u.set(e, t), t;
610
+ }
611
+ r === void 0 && n.data === void 0 && F(), n.subtree !== void 0 && n.subtree !== !0 && F(), n.shift !== void 0 && !Number.isSafeInteger(n.shift) && F(), n.data !== void 0 && n.shift !== void 0 && F(), n.children !== void 0 && n.children !== null && (!Array.isArray(n.children) || n.children.some((e) => typeof e != "string")) && F(), d.add(e);
612
+ let i;
613
+ if (n.subtree === !0) (r === void 0 || n.shift === void 0 || n.data !== void 0 || n.children !== void 0) && F(), i = $e(r, n.shift);
614
+ else {
615
+ let t;
616
+ n.data === void 0 ? (r === void 0 && F(), t = z(r), n.shift !== void 0 && (P(t.range) || F(), t.range = {
617
+ start: t.range.start + n.shift,
618
+ end: t.range.end + n.shift
619
+ })) : (N(n.data) || F(), t = L(n.data), delete t.children, t.id !== e && F());
620
+ let a;
621
+ if (n.children !== void 0) a = n.children === null ? null : [...n.children];
622
+ else {
623
+ let e = r?.children;
624
+ a = e === void 0 ? void 0 : e.map((e) => e.id);
625
+ }
626
+ a === null ? delete t.children : a !== void 0 && (t.children = a.map(f)), i = t;
627
+ }
628
+ return d.delete(e), u.set(e, i), i;
629
+ }, p = l.map(f);
630
+ i.nodes = n.roots === void 0 && n.nodes === void 0 ? r.nodes : p;
631
+ let m = t.diagnostics === void 0 ? e.diagnostics : Array.isArray(t.diagnostics) ? L(t.diagnostics) : F();
632
+ if (t.recoveries !== void 0 && t.recoveries !== null && !Array.isArray(t.recoveries)) return null;
633
+ if (t.recoveries === null) return {
634
+ ok: !0,
635
+ document: i,
636
+ diagnostics: m
637
+ };
638
+ let h = t.recoveries === void 0 ? e.recoveries : L([...t.recoveries]);
639
+ return {
640
+ ok: !0,
641
+ document: i,
642
+ diagnostics: m,
643
+ ...h === void 0 ? {} : { recoveries: h }
644
+ };
645
+ } catch {
646
+ return null;
647
+ }
648
+ }
649
+ // src/local/transport/flat-compiled-data.ts
650
+ var H = "flat-v1";
651
+ function rt(e) {
652
+ if (!e.ok) return !1;
653
+ let t = e.document.nodes.map((e) => ({
654
+ node: e,
655
+ depth: 0
656
+ }));
657
+ for (; t.length;) {
658
+ let { node: e, depth: n } = t.pop();
659
+ if (n >= 100) return !0;
660
+ if (e.children) for (let r of e.children) t.push({
661
+ node: r,
662
+ depth: n + 1
663
+ });
664
+ }
665
+ return !1;
666
+ }
667
+ function it(e) {
668
+ let t = [], n = /* @__PURE__ */ new Map(), r = [], i = (e) => {
669
+ if (typeof e == "object" && e) {
670
+ let i = n.get(e);
671
+ if (i !== void 0) return i;
672
+ let a = t.length, o = Array.isArray(e) ? [
673
+ 1,
674
+ e.length,
675
+ []
676
+ ] : [2, []];
677
+ return n.set(e, a), t.push(o), r.push({
678
+ value: e,
679
+ record: o
680
+ }), a;
640
681
  }
641
- if (s.type !== c.type) {
642
- a.push(W(o, "type"));
682
+ if (e !== null && ![
683
+ "string",
684
+ "number",
685
+ "boolean",
686
+ "undefined"
687
+ ].includes(typeof e)) throw TypeError("Unsupported compiler wire value");
688
+ let i = t.length;
689
+ return t.push([0, e]), i;
690
+ };
691
+ for (i(e); r.length;) {
692
+ let { value: e, record: t } = r.pop(), n = t[0] === 1 ? t[2] : t[1];
693
+ for (let t of Object.keys(e)) n.push([t, i(e[t])]);
694
+ }
695
+ return {
696
+ version: H,
697
+ records: t
698
+ };
699
+ }
700
+ function at(e) {
701
+ if (!e || typeof e != "object") return null;
702
+ let t = e;
703
+ if (t.version !== "flat-v1" || !Array.isArray(t.records) || t.records.length === 0 || t.records.length > 2e6) return null;
704
+ let n = t.records, r = Array(n.length), i = Array(n.length), a = 0;
705
+ for (let e = 0; e < n.length; e++) {
706
+ let t = n[e];
707
+ if (!Array.isArray(t)) return null;
708
+ if (t[0] === 0) {
709
+ if (t.length !== 2 || t[1] !== null && ![
710
+ "string",
711
+ "number",
712
+ "boolean",
713
+ "undefined"
714
+ ].includes(typeof t[1])) return null;
715
+ r[e] = t[1], i[e] = [];
643
716
  continue;
644
717
  }
645
- if (s.initialDefinition !== c.initialDefinition) {
646
- a.push(W(o, "initial"));
718
+ let o = t[0] === 1;
719
+ if (!o && t[0] !== 2 || t.length !== (o ? 3 : 2) || o && (!Number.isSafeInteger(t[1]) || t[1] < 0 || t[1] > 1e6)) return null;
720
+ let s = o ? t[2] : t[1];
721
+ if (!Array.isArray(s)) return null;
722
+ let c = /* @__PURE__ */ new Set(), l = [];
723
+ for (let e of s) if (!Array.isArray(e) || e.length !== 2 || typeof e[0] != "string" || !Number.isSafeInteger(e[1]) || e[1] < 0 || e[1] >= n.length || c.has(e[0]) || o && (e[0] === "length" || !/^(0|[1-9][0-9]*)$/.test(e[0]) || Number(e[0]) >= t[1]) || (c.add(e[0]), l.push(e[1]), ++a > 4e6)) return null;
724
+ r[e] = o ? Array(t[1]) : {}, i[e] = l;
725
+ }
726
+ let o = new Uint8Array(n.length), s = [{
727
+ index: 0,
728
+ child: 0
729
+ }];
730
+ o[0] = 1;
731
+ let c = 1;
732
+ for (; s.length;) {
733
+ let e = s[s.length - 1], t = i[e.index];
734
+ if (e.child === t.length) {
735
+ o[e.index] = 2, s.pop();
647
736
  continue;
648
737
  }
649
- let l = e.state[o];
650
- r[o] = Array.isArray(l) ? Object.freeze([...l]) : l, i.push(o);
738
+ let n = t[e.child++];
739
+ if (o[n] === 1) return null;
740
+ o[n] === 0 && (o[n] = 1, c++, s.push({
741
+ index: n,
742
+ child: 0
743
+ }));
651
744
  }
652
- return Object.freeze({
653
- values: Object.freeze(r),
654
- retained: Object.freeze(i),
655
- dropped: Object.freeze(a)
656
- });
745
+ if (c !== n.length) return null;
746
+ for (let e = 0; e < n.length; e++) {
747
+ let t = n[e];
748
+ if (t[0] === 0) continue;
749
+ let i = t[0] === 1 ? t[2] : t[1];
750
+ for (let [t, n] of i) Object.defineProperty(r[e], t, {
751
+ value: r[n],
752
+ enumerable: !0,
753
+ writable: !0,
754
+ configurable: !0
755
+ });
756
+ }
757
+ return r[0];
758
+ }
759
+ // src/local/transport/worker.ts
760
+ var ot = 150, st = 200, ct = [
761
+ "maxSyntaxNodes",
762
+ "maxParseWork",
763
+ "maxMarkdownDepth"
764
+ ];
765
+ function U(e) {
766
+ return e instanceof Error ? e.message : String(e);
657
767
  }
658
- function Ie(e, t, n) {
659
- return Object.freeze({
660
- retained: Object.freeze([...e]),
661
- dropped: Object.freeze(t.map((e) => Object.freeze({ ...e }))),
662
- diagnostics: Object.freeze([...n])
663
- });
768
+ function W() {
769
+ return typeof performance < "u" ? performance.now() : Date.now();
664
770
  }
665
- function Le(e, t) {
666
- let n = Object.keys(t.values).sort();
667
- if (!e.setParameters(t.values).length) return Ie(n, t.dropped, []);
668
- let r = [], i = [...t.dropped], a = [];
669
- for (let o of n) {
670
- let n = e.setParameter(o, t.values[o]);
671
- n.length ? (i.push(W(o, "invalid")), a.push(...n)) : r.push(o);
771
+ function G(e) {
772
+ return Number.isFinite(e) ? Math.max(0, Math.round(e)) : 0;
773
+ }
774
+ function K(e, t, n) {
775
+ let r = {
776
+ tokens: [],
777
+ bindings: [],
778
+ diagnostics: []
779
+ };
780
+ if (n.ok && n.document.source !== e || !n.ok && n.diagnostics.some((e) => e.code.startsWith("local.budget") || e.code.startsWith("local.options."))) return r;
781
+ try {
782
+ return w(e, t, {
783
+ ...n.ok ? { document: n.document } : {},
784
+ diagnostics: !1
785
+ });
786
+ } catch {
787
+ return {
788
+ tokens: [],
789
+ bindings: [],
790
+ diagnostics: []
791
+ };
792
+ }
793
+ }
794
+ function lt(e, t) {
795
+ if (!e || typeof e != "object") return !1;
796
+ let n = e, r = (e) => e && Number.isSafeInteger(e.start) && Number.isSafeInteger(e.end) && e.start >= 0 && e.end >= e.start && e.end <= t;
797
+ if (!Array.isArray(n.tokens) || n.tokens.length > t + 1 || !Array.isArray(n.bindings) || n.bindings.length > t + 1 || !Array.isArray(n.diagnostics)) return !1;
798
+ let i = 0, a = 0;
799
+ for (let e of n.tokens) {
800
+ if (!e || typeof e.kind != "string" || !r(e.range) || e.range.start < i) return !1;
801
+ i = e.range.end;
672
802
  }
673
- return i.sort((e, t) => e.name < t.name ? -1 : +(e.name > t.name)), Ie(r, i, a);
803
+ for (let e of n.bindings) if (!e || typeof e.name != "string" || !Array.isArray(e.declarations) || !Array.isArray(e.references) || (a += e.declarations.length + e.references.length, a > t + 1 || !e.declarations.every(r) || !e.references.every(r))) return !1;
804
+ return !0;
674
805
  }
675
- // src/local/worker.ts
676
- var Re = 150;
677
- function ze(e) {
806
+ function ut(e) {
678
807
  return Array.isArray(e) ? e.length > 32 ? Array(33) : e.map((e) => {
679
808
  if (!e || typeof e != "object" || Array.isArray(e)) return e;
680
809
  let t = e, n = { ...t }, r = t.props;
@@ -691,22 +820,42 @@ function ze(e) {
691
820
  return n.props = i, n;
692
821
  }) : e;
693
822
  }
694
- function Be(e) {
823
+ function q(e) {
695
824
  if (e !== void 0) try {
696
825
  if (typeof e != "object" || !e || Array.isArray(e)) return e;
697
826
  let t = e, n = {};
698
- for (let e of p) Object.hasOwn(t, e) && (n[e] = t[e]);
699
- if (Object.hasOwn(t, "markdownBreaks") && (n.markdownBreaks = t.markdownBreaks), Object.hasOwn(t, "limits")) {
827
+ for (let e of h) Object.hasOwn(t, e) && (n[e] = t[e]);
828
+ if (Object.hasOwn(t, "markdownBreaks") && (n.markdownBreaks = t.markdownBreaks), Object.hasOwn(t, "strict") && (n.strict = t.strict), Object.hasOwn(t, "limits")) {
700
829
  let e = t.limits;
701
- n.limits = e && typeof e == "object" && !Array.isArray(e) && Object.hasOwn(e, "maxSyntaxNodes") ? { maxSyntaxNodes: e.maxSyntaxNodes } : e;
830
+ if (e && typeof e == "object" && !Array.isArray(e)) {
831
+ let t = {};
832
+ for (let n of ct) Object.hasOwn(e, n) && (t[n] = e[n]);
833
+ n.limits = t;
834
+ } else n.limits = e;
702
835
  }
703
- return Object.hasOwn(t, "hostComponents") && (n.hostComponents = ze(t.hostComponents)), n;
836
+ return Object.hasOwn(t, "hostComponents") && (n.hostComponents = ut(t.hostComponents)), Object.hasOwn(t, "config") && (n.config = b(t.config)), n;
704
837
  } catch {
705
838
  return e;
706
839
  }
707
840
  }
708
- function Ve(e) {
709
- let t = b(e);
841
+ function dt(e) {
842
+ try {
843
+ if (!e || typeof e != "object" || Array.isArray(e)) return "";
844
+ let t = e.limits;
845
+ if (!t || typeof t != "object" || Array.isArray(t)) return "";
846
+ let n = (e) => {
847
+ let n = t;
848
+ if (!Object.hasOwn(n, e) || n[e] === void 0) return "-";
849
+ let r = n[e];
850
+ return `${typeof r}:${String(r)}`;
851
+ };
852
+ return `:${n("maxParseWork")}:${n("maxMarkdownDepth")}`;
853
+ } catch {
854
+ return ":unreadable";
855
+ }
856
+ }
857
+ function ft(e) {
858
+ let t = S(e);
710
859
  if (t !== "invalid") return t;
711
860
  try {
712
861
  return `invalid:${JSON.stringify(e)}`;
@@ -714,29 +863,33 @@ function Ve(e) {
714
863
  return "invalid";
715
864
  }
716
865
  }
717
- function He(e, t) {
866
+ function J(e) {
867
+ return `${ft(e)}${dt(e)}`;
868
+ }
869
+ function pt(e, t) {
870
+ let n = q(t);
718
871
  return {
719
872
  source: e,
720
- options: Be(t),
721
- optionsKey: Ve(t)
873
+ options: n,
874
+ optionsKey: J(n),
875
+ scheduledAt: W()
722
876
  };
723
877
  }
724
- function G(e, t) {
878
+ function Y(e, t) {
725
879
  return e.source === t.source && e.optionsKey === t.optionsKey;
726
880
  }
727
- function K(e) {
728
- return e instanceof Error ? e.message : String(e);
881
+ function mt(e) {
882
+ if (!e || typeof e != "object") return !1;
883
+ let t = e;
884
+ return !(typeof t.ok != "boolean" || !Array.isArray(t.diagnostics) || t.ok && (!t.document || typeof t.document != "object"));
729
885
  }
730
- function q() {
731
- return typeof performance < "u" ? performance.now() : Date.now();
886
+ function ht(e) {
887
+ return e.ok && "patch" in e && e.patch !== void 0;
732
888
  }
733
- function J(e) {
734
- return Number.isFinite(e) ? Math.max(0, Math.round(e)) : 0;
735
- }
736
- function Y(e) {
889
+ function X(e) {
737
890
  return {
738
891
  code: "local.worker.compile",
739
- message: `Compilation failed: ${K(e)}`,
892
+ message: `Compilation failed: ${U(e)}`,
740
893
  severity: "error",
741
894
  range: {
742
895
  start: 0,
@@ -746,7 +899,7 @@ function Y(e) {
746
899
  column: 1
747
900
  };
748
901
  }
749
- var Ue = class {
902
+ var gt = class {
750
903
  options;
751
904
  delay;
752
905
  worker = null;
@@ -754,8 +907,12 @@ var Ue = class {
754
907
  queued = null;
755
908
  inFlight = null;
756
909
  nextId = 1;
910
+ nextRevision = 1;
757
911
  pending = !1;
912
+ fallbackSession = null;
758
913
  disposed = !1;
914
+ baseline = null;
915
+ patchState = "unknown";
759
916
  constructor(e) {
760
917
  this.options = e;
761
918
  let t = e.delay;
@@ -767,17 +924,20 @@ var Ue = class {
767
924
  this.handleWorkerFailure(t || "The compile worker encountered an error");
768
925
  }, t.onmessageerror = () => this.handleWorkerFailure("The compile worker could not deliver the compile result"), this.worker = t;
769
926
  } catch (t) {
770
- this.worker = null, e.onModeChange?.("fallback", `Could not start the compile worker: ${K(t)}`);
927
+ this.worker = null, e.onModeChange?.("fallback", `Could not start the compile worker: ${U(t)}`);
771
928
  }
772
929
  }
773
- schedule(e, t) {
774
- this.disposed || (this.queued = He(e, t), this.clearTimer(), this.timer = setTimeout(() => {
930
+ schedule(e, t, n) {
931
+ this.disposed || (this.queued = pt(e, t), n && typeof n.baseSource == "string" && $(n.edit) && n.edit.to <= n.baseSource.length && n.baseSource.slice(0, n.edit.from) + n.edit.insert + n.baseSource.slice(n.edit.to) === e && (this.queued.editHint = {
932
+ baseSource: n.baseSource,
933
+ edit: { ...n.edit }
934
+ }), this.clearTimer(), this.timer = setTimeout(() => {
775
935
  this.timer = null, this.drain();
776
936
  }, this.delay), this.setPending(!0));
777
937
  }
778
938
  dispose() {
779
939
  if (this.disposed) return;
780
- this.disposed = !0, this.clearTimer(), this.queued = null, this.inFlight = null;
940
+ this.disposed = !0, this.clearTimer(), this.queued = null, this.inFlight = null, this.resetProtocol();
781
941
  let e = this.worker;
782
942
  if (this.worker = null, e) {
783
943
  e.onmessage = null, e.onerror = null, e.onmessageerror = null;
@@ -785,7 +945,7 @@ var Ue = class {
785
945
  e.terminate();
786
946
  } catch {}
787
947
  }
788
- this.pending = !1;
948
+ this.pending = !1, this.fallbackSession?.dispose(), this.fallbackSession = null;
789
949
  }
790
950
  drain() {
791
951
  if (this.disposed || this.timer !== null || this.inFlight !== null) return;
@@ -798,75 +958,167 @@ var Ue = class {
798
958
  this.compileFallback(e);
799
959
  return;
800
960
  }
801
- let n = this.nextId++;
802
- this.inFlight = {
961
+ let n = this.nextId++, r = this.nextRevision++, i = W(), a = this.baseline, o = this.patchState === "enabled" && a !== null && a.optionsKey === e.optionsKey ? {
962
+ id: n,
963
+ protocol: A,
964
+ baseRevision: a.revision,
965
+ revision: r,
966
+ edit: e.editHint?.baseSource === a.source ? e.editHint.edit : R(a.source, e.source) ?? {
967
+ from: 0,
968
+ to: 0,
969
+ insert: ""
970
+ },
971
+ targetLength: e.source.length,
972
+ optionsKey: e.optionsKey
973
+ } : {
803
974
  id: n,
804
- job: e
975
+ source: e.source,
976
+ ...e.options === void 0 ? {} : { options: e.options },
977
+ protocol: A,
978
+ revision: r,
979
+ flatResults: H
805
980
  };
981
+ this.inFlight = {
982
+ id: n,
983
+ job: e,
984
+ startedAt: i,
985
+ revision: r
986
+ }, this.options.includeAuthorAnalysis && (o.includeAuthorAnalysis = !0);
806
987
  try {
807
- t.postMessage({
808
- id: n,
809
- source: e.source,
810
- ...e.options === void 0 ? {} : { options: e.options }
811
- });
988
+ t.postMessage(o);
812
989
  } catch (t) {
813
990
  this.inFlight = null;
814
- let n = `Could not send the source to the compile worker: ${K(t)}`, r = this.queued;
815
- if (r !== null && !G(r, e)) {
816
- this.degrade(n), this.finishRun();
991
+ let n = `Could not send the source to the compile worker: ${U(t)}`, r = this.queued;
992
+ if (r !== null && !Y(r, e)) {
993
+ this.resetProtocol(), this.degrade(n), this.finishRun();
817
994
  return;
818
995
  }
819
- r !== null && (this.queued = null, this.clearTimer()), this.degrade(n), this.compileFallback(e);
996
+ r !== null && (this.queued = null, this.clearTimer()), this.resetProtocol(), this.degrade(n), this.compileFallback(e);
820
997
  }
821
998
  }
822
999
  compileFallback(e) {
823
1000
  if (this.disposed) return;
824
- let t = q(), n;
1001
+ let t = W(), n;
825
1002
  try {
826
- let t = this.options.fallbackCompile ?? x;
1003
+ let t = this.options.fallbackCompile ?? ((e, t) => (this.fallbackSession ??= T(), this.fallbackSession.compile(e, t)));
827
1004
  n = e.options === void 0 ? t(e.source) : t(e.source, e.options);
828
1005
  } catch (e) {
829
1006
  n = {
830
1007
  ok: !1,
831
- diagnostics: [Y(e)]
1008
+ diagnostics: [X(e)]
832
1009
  };
833
1010
  }
834
1011
  this.deliver({
835
1012
  source: e.source,
836
1013
  result: n,
837
- duration: J(q() - t),
1014
+ duration: G(W() - t),
838
1015
  mode: "fallback",
839
- ...e.options === void 0 ? {} : { options: e.options }
1016
+ ...this.options.includeAuthorAnalysis ? { analysis: K(e.source, e.options, n) } : {},
1017
+ ...e.options === void 0 ? {} : { options: e.options },
1018
+ metrics: { queueMs: G(t - e.scheduledAt) }
840
1019
  }), this.finishRun();
841
1020
  }
842
1021
  receive(e) {
843
1022
  if (this.disposed) return;
844
1023
  let t = this.inFlight;
845
1024
  if (!t || !e || e.id !== t.id) return;
1025
+ let n, r = 0;
1026
+ if (e.ok && "flatResult" in e) {
1027
+ let t = W(), i = at(e.flatResult);
1028
+ r = G(W() - t), n = mt(i) ? {
1029
+ ...e,
1030
+ result: i
1031
+ } : {
1032
+ id: e.id,
1033
+ ok: !1,
1034
+ retryFull: !0,
1035
+ message: "Invalid flat compile result"
1036
+ };
1037
+ } else n = e;
846
1038
  this.inFlight = null;
847
- let n = t.job, r = this.queued;
848
- r !== null && !G(r, n) || (r !== null && (this.queued = null, this.clearTimer()), e.ok ? this.deliver({
849
- source: n.source,
850
- result: e.result,
851
- duration: J(e.duration),
852
- mode: "worker",
853
- ...n.options === void 0 ? {} : { options: n.options }
854
- }) : this.deliver({
855
- source: n.source,
1039
+ let i = t.job, a = G(W() - t.startedAt), o = G(t.startedAt - i.scheduledAt), s = null, c = r, l = null, u = "worker", d;
1040
+ if (n.ok) {
1041
+ if (ht(n)) {
1042
+ let e = W(), t = this.applyResponsePatch(i, n);
1043
+ c = G(W() - e), t !== null && (s = t, d = n.revision);
1044
+ } else {
1045
+ let e = n;
1046
+ mt(e.result) ? (s = e.result, d = typeof e.revision == "number" ? e.revision : void 0, e.protocol === "patch-v1" && typeof e.revision == "number" && Number.isSafeInteger(e.revision) ? (this.patchState = "enabled", this.baseline = e.result.ok ? {
1047
+ source: i.source,
1048
+ optionsKey: i.optionsKey,
1049
+ revision: e.revision,
1050
+ result: e.result
1051
+ } : null) : (this.patchState = "legacy", this.baseline = null)) : l = "The compile worker returned an invalid result";
1052
+ }
1053
+ } else n.retryFull !== !0 && (l = n.message);
1054
+ let f = this.queued, p = f !== null && !Y(f, i);
1055
+ f !== null && !p && (this.queued = null, this.clearTimer()), s === null ? l === null ? (p || !this.recoverWithFullResult(i)) && (p ? this.resetProtocol() : (this.patchState = "disabled", this.baseline = null, this.deliver({
1056
+ source: i.source,
856
1057
  result: {
857
1058
  ok: !1,
858
- diagnostics: [Y(e.message)]
1059
+ diagnostics: [X("The compile worker could not apply an incremental result patch")]
859
1060
  },
860
1061
  duration: 0,
861
- mode: "worker",
862
- ...n.options === void 0 ? {} : { options: n.options }
863
- })), this.finishRun();
1062
+ mode: u,
1063
+ ...i.options === void 0 ? {} : { options: i.options },
1064
+ metrics: {
1065
+ queueMs: o,
1066
+ roundTripMs: a,
1067
+ ...c > 0 ? { applyMs: c } : {}
1068
+ }
1069
+ })), this.finishRun()) : (p || this.deliver({
1070
+ source: i.source,
1071
+ result: {
1072
+ ok: !1,
1073
+ diagnostics: [X(l)]
1074
+ },
1075
+ duration: 0,
1076
+ mode: u,
1077
+ ...i.options === void 0 ? {} : { options: i.options },
1078
+ metrics: {
1079
+ queueMs: o,
1080
+ roundTripMs: a
1081
+ }
1082
+ }), this.finishRun()) : (p || this.deliver({
1083
+ source: i.source,
1084
+ result: s,
1085
+ duration: G(n.ok ? n.duration : 0),
1086
+ mode: u,
1087
+ ...n.ok && this.options.includeAuthorAnalysis && lt(n.analysis, i.source.length) ? { analysis: n.analysis } : {},
1088
+ ...i.options === void 0 ? {} : { options: i.options },
1089
+ metrics: {
1090
+ queueMs: o,
1091
+ roundTripMs: a,
1092
+ ...c > 0 ? { applyMs: c } : {},
1093
+ ...n.ok && n.metrics ? { worker: n.metrics } : {}
1094
+ },
1095
+ ...d === void 0 ? {} : { revision: d }
1096
+ }), this.finishRun());
1097
+ }
1098
+ applyResponsePatch(e, t) {
1099
+ let n = this.baseline;
1100
+ if (n === null || n.optionsKey !== e.optionsKey || !Number.isSafeInteger(t.revision) || t.revision <= n.revision || t.baseRevision !== n.revision || t.protocol !== "patch-v1") return null;
1101
+ let r = nt(n.result, t.patch);
1102
+ return r === null || !r.ok || r.document.source !== e.source ? null : (this.baseline = {
1103
+ source: e.source,
1104
+ optionsKey: e.optionsKey,
1105
+ revision: t.revision,
1106
+ result: r
1107
+ }, r);
1108
+ }
1109
+ recoverWithFullResult(e) {
1110
+ if (this.worker === null || (e.recovery ?? 0) >= 1) return !1;
1111
+ let t = this.queued;
1112
+ return t !== null && !Y(t, e) ? !1 : (t !== null && (this.queued = null, this.clearTimer()), this.resetProtocol(), this.compile({
1113
+ ...e,
1114
+ recovery: (e.recovery ?? 0) + 1
1115
+ }), !0);
864
1116
  }
865
1117
  handleWorkerFailure(e) {
866
1118
  if (this.disposed) return;
867
- this.degrade(e);
1119
+ this.resetProtocol(), this.degrade(e);
868
1120
  let t = this.inFlight;
869
- this.inFlight = null, t && (this.queued === null || G(this.queued, t.job)) && (this.queued !== null && (this.queued = null, this.clearTimer()), this.compileFallback(t.job)), this.finishRun();
1121
+ this.inFlight = null, t && (this.queued === null || Y(this.queued, t.job)) && (this.queued !== null && (this.queued = null, this.clearTimer()), this.compileFallback(t.job)), this.finishRun();
870
1122
  }
871
1123
  degrade(e) {
872
1124
  let t = this.worker;
@@ -878,11 +1130,19 @@ var Ue = class {
878
1130
  this.options.onModeChange?.("fallback", e);
879
1131
  }
880
1132
  }
1133
+ resetProtocol() {
1134
+ this.baseline = null, this.patchState = "unknown";
1135
+ }
881
1136
  finishRun() {
882
1137
  this.disposed || (this.drain(), !this.disposed && this.setPending(this.timer !== null || this.inFlight !== null || this.queued !== null));
883
1138
  }
884
1139
  deliver(e) {
885
- this.disposed || this.options.onResult(e);
1140
+ if (this.disposed) return;
1141
+ let t = this.baseline !== null && this.baseline.result === e.result, n = this.options.shareResults === !0 || !t ? e.result : L(e.result);
1142
+ this.options.onResult({
1143
+ ...e,
1144
+ result: n
1145
+ });
886
1146
  }
887
1147
  setPending(e) {
888
1148
  this.pending !== e && (this.pending = e, this.options.onPendingChange?.(e));
@@ -891,7 +1151,14 @@ var Ue = class {
891
1151
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
892
1152
  }
893
1153
  };
894
- function We(e, t, n) {
1154
+ function _t(e, t, n) {
1155
+ let r = e;
1156
+ return typeof r.compileShared == "function" ? r.compileShared(t, n) : e.compile(t, n);
1157
+ }
1158
+ function Z(e) {
1159
+ return e.stats;
1160
+ }
1161
+ function Q(e, t, n) {
895
1162
  try {
896
1163
  e.postMessage({
897
1164
  id: t,
@@ -900,218 +1167,236 @@ function We(e, t, n) {
900
1167
  });
901
1168
  } catch {}
902
1169
  }
903
- function Ge(e) {
904
- let t = e === void 0 ? globalThis : e;
905
- if (!t || typeof t.postMessage != "function") throw TypeError("startLocalCompileWorker requires a worker scope with postMessage");
906
- t.onmessage = (e) => {
907
- let n = e?.data;
908
- if (!n || typeof n.id != "number" || typeof n.source != "string") return;
909
- let r = q();
1170
+ function vt(e, t, n, r, i) {
1171
+ try {
1172
+ e.postMessage({
1173
+ id: t,
1174
+ ok: !1,
1175
+ message: n,
1176
+ retryFull: !0,
1177
+ code: r,
1178
+ ...i === void 0 ? {} : { revision: i }
1179
+ });
1180
+ } catch {}
1181
+ }
1182
+ function yt(e) {
1183
+ return !!e && typeof e == "object" && (e.control === "dispose" || e.control === "cancel-preparation");
1184
+ }
1185
+ function $(e) {
1186
+ if (!e || typeof e != "object") return !1;
1187
+ let t = e;
1188
+ return typeof t.from == "number" && Number.isSafeInteger(t.from) && typeof t.to == "number" && Number.isSafeInteger(t.to) && t.from >= 0 && t.to >= t.from && typeof t.insert == "string";
1189
+ }
1190
+ function bt(e, t = {}) {
1191
+ let n = e === void 0 ? globalThis : e;
1192
+ if (!n || typeof n.postMessage != "function") throw TypeError("startLocalCompileWorker requires a worker scope with postMessage");
1193
+ let r = t.createSession ? t.createSession() : T(), i = r, a = t.preparationDelay, o = typeof a == "number" && Number.isFinite(a) ? Math.max(0, a) : 200, s = typeof i.prepareAsync == "function", c = null, l = 0, u = !1, d = null, f = null, p = 0, m, h = () => {
1194
+ p += 1, f !== null && (f.aborted = !0, f = null), d !== null && (clearTimeout(d), d = null);
1195
+ }, g = () => new Promise((e) => {
1196
+ typeof setTimeout == "function" ? setTimeout(e, 0) : e();
1197
+ }), _ = async (e) => {
1198
+ if (u || e !== p) return;
1199
+ let t = i.prepareAsync;
1200
+ if (typeof t != "function") return;
1201
+ let n = { aborted: !1 };
1202
+ f = n;
1203
+ let r = W(), a = !1;
910
1204
  try {
911
- let e = n.options === void 0 ? x(n.source) : x(n.source, n.options), i = J(q() - r);
1205
+ a = await t.call(i, n, g);
1206
+ } catch {} finally {
1207
+ f === n && (f = null), a && !n.aborted && !u && e === p && (m = G(W() - r));
1208
+ }
1209
+ }, v = () => {
1210
+ if (u || !s) return;
1211
+ h();
1212
+ let e = p;
1213
+ d = setTimeout(() => {
1214
+ d = null, _(e);
1215
+ }, o);
1216
+ }, y = () => {
1217
+ if (!u) {
1218
+ u = !0, h();
912
1219
  try {
913
- t.postMessage({
914
- id: n.id,
915
- ok: !0,
916
- result: e,
917
- duration: i
918
- });
919
- } catch (e) {
920
- We(t, n.id, `Could not return the compile result: ${K(e)}`);
1220
+ r.dispose();
1221
+ } catch {}
1222
+ n.onmessage = null;
1223
+ }
1224
+ }, b = (e) => ({
1225
+ compileMs: e,
1226
+ ...m === void 0 ? {} : { preparationMs: m }
1227
+ }), x = (e) => {
1228
+ let t = typeof e == "number" && Number.isSafeInteger(e) && e > 0 ? e : null;
1229
+ return t === null ? l + 1 : t > l ? t : l + 1;
1230
+ }, S = (e, t, i, a, o = !1, s) => {
1231
+ let l = c;
1232
+ if (l === null) return !1;
1233
+ let u = G(i), d = s === void 0 ? b(u) : {
1234
+ ...b(u),
1235
+ ...s
1236
+ };
1237
+ try {
1238
+ let i = a ? {
1239
+ id: e,
1240
+ ok: !0,
1241
+ result: l.result,
1242
+ duration: u,
1243
+ incremental: Z(r),
1244
+ protocol: A,
1245
+ revision: t,
1246
+ metrics: d
1247
+ } : {
1248
+ id: e,
1249
+ ok: !0,
1250
+ result: l.result,
1251
+ duration: u,
1252
+ incremental: Z(r)
1253
+ };
1254
+ if (o && i.ok) {
1255
+ let e = W();
1256
+ i.analysis = K(l.source, l.options, l.result), i.metrics = {
1257
+ ...i.metrics,
1258
+ analysisMs: G(W() - e)
1259
+ };
921
1260
  }
922
- } catch (e) {
923
- We(t, n.id, K(e));
1261
+ if (l.deep && l.flatResults && i.ok) {
1262
+ let { result: e, ...t } = i, r = {
1263
+ ...t,
1264
+ flatResult: it(e)
1265
+ };
1266
+ n.postMessage(r);
1267
+ } else n.postMessage(i);
1268
+ return !0;
1269
+ } catch (t) {
1270
+ return Q(n, e, `Could not return the compile result: ${U(t)}`), !1;
924
1271
  }
925
1272
  };
926
- }
927
- // src/shareable.ts
928
- var Ke = "reactive-md-html/v1", qe = /^[A-Za-z][A-Za-z0-9_-]*$/, Je = /^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/, Ye = /^data:image\/(?:png|jpeg|gif|webp);base64,[A-Za-z0-9+/]+={0,2}$/, Xe = /[\u0000-\u001f\u007f-\u009f]/, Ze = 64, Qe = 41943040, $e = 4096;
929
- function X(e, t = !1) {
930
- let n = e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
931
- return t && (n = n.replace(/"/g, "&quot;").replace(/'/g, "&#39;")), n;
932
- }
933
- function et(e) {
934
- return e.replace(/<\/style/gi, "<\\/style");
935
- }
936
- function tt(e) {
937
- return e.replace(/<\/script/gi, "<\\/script").replace(/<!--/g, "<\\!--");
938
- }
939
- function Z(e) {
940
- return X(e, !0);
941
- }
942
- function nt(e) {
943
- let t = JSON.stringify(e);
944
- if (typeof t != "string") throw TypeError("Cannot serialize a non-JSON value for an inline script.");
945
- return t.replace(/[<>&\u2028\u2029]/g, (e) => {
946
- switch (e) {
947
- case "<": return "\\u003c";
948
- case ">": return "\\u003e";
949
- case "&": return "\\u0026";
950
- case "\u2028": return "\\u2028";
951
- default: return "\\u2029";
1273
+ return n.onmessage = (e) => {
1274
+ let t = e?.data;
1275
+ if (yt(t)) {
1276
+ t.control === "dispose" ? y() : h();
1277
+ return;
952
1278
  }
953
- });
954
- }
955
- function Q(e) {
956
- return Array.isArray(e) ? e.slice() : e;
957
- }
958
- function rt(e) {
959
- if (e === void 0) return;
960
- let t = _(e);
961
- if (!t.ok) throw TypeError(`createShareableHtml received invalid compileOptions: ${t.message}`);
962
- let n = {
963
- enableCss: t.html.enableCss,
964
- enableJavaScript: t.html.enableJavaScript,
965
- enableExtendedHtml: t.html.enableExtendedHtml,
966
- ...Object.hasOwn(e, "markdownBreaks") && e.markdownBreaks !== void 0 ? { markdownBreaks: t.markdownBreaks } : {}
967
- };
968
- return e.limits !== void 0 && e.limits.maxSyntaxNodes !== void 0 ? {
969
- ...n,
970
- limits: { maxSyntaxNodes: t.maxSyntaxNodes }
971
- } : n;
972
- }
973
- function it(t) {
974
- let n = [];
975
- for (let r of t.childNodes) {
976
- if (e.isElementNode(r)) {
977
- let t = r.tagName.toLowerCase();
978
- if (t === "script") continue;
979
- it(t === "template" ? e.getTemplateContent(r) : r);
1279
+ if (!t || typeof t.id != "number") return;
1280
+ if (typeof t.source == "string") {
1281
+ h();
1282
+ let e = t, i = q(e.options), a = J(i), o = e.protocol === A, s = x(e.revision), u = W();
1283
+ try {
1284
+ if (c !== null && c.optionsKey !== a) try {
1285
+ r.clear();
1286
+ } catch {}
1287
+ let t = _t(r, e.source, i), n = G(W() - u);
1288
+ l = s, c = {
1289
+ source: e.source,
1290
+ revision: s,
1291
+ options: i,
1292
+ optionsKey: a,
1293
+ result: t,
1294
+ deep: rt(t),
1295
+ flatResults: e.flatResults === H
1296
+ }, S(e.id, s, n, o, e.includeAuthorAnalysis === !0) && v();
1297
+ } catch (t) {
1298
+ Q(n, e.id, U(t));
1299
+ }
1300
+ return;
980
1301
  }
981
- n.push(r);
982
- }
983
- t.childNodes = n;
984
- }
985
- function $(t, n, r) {
986
- let i = !1;
987
- for (let a of t.childNodes) if (e.isElementNode(a)) {
988
- if (a.tagName.toLowerCase() === "iframe") {
989
- let e = a.attrs.filter((e) => {
990
- let t = e.name.toLowerCase();
991
- return t !== "srcdoc" && t !== "sandbox";
992
- });
993
- e.push({
994
- name: "srcdoc",
995
- value: n
996
- }), e.push({
997
- name: "sandbox",
998
- value: r
999
- }), a.attrs = e, i = !0;
1302
+ if (t.protocol !== "patch-v1") return;
1303
+ h();
1304
+ let i = t, a = c, o = (e, t) => {
1305
+ vt(n, i.id, e, t, a?.revision);
1306
+ };
1307
+ if (a === null) {
1308
+ o("No complete compile is available to patch", "stale-base");
1309
+ return;
1000
1310
  }
1001
- $(a, n, r) && (i = !0);
1002
- }
1003
- return i;
1004
- }
1005
- function at(e) {
1006
- let t = "";
1007
- for (let n of e.childNodes) t += a(n, { scriptingEnabled: !1 });
1008
- return t;
1009
- }
1010
- function ot(e, t, n) {
1011
- try {
1012
- let r = i(e, { scriptingEnabled: !1 });
1013
- if (it(r), $(r, t, n)) return at(r);
1014
- } catch {}
1015
- return `<div class="reactive-md-native-document"><iframe class="reactive-md-native-frame" title="Reactive MD document" sandbox="${X(n, !0)}" style="display:block;width:100%;min-height:60vh;border:0;background:#fff" srcdoc="${X(t, !0)}"></iframe></div>`;
1016
- }
1017
- function st(e, t) {
1018
- let n = t?.enableExtendedHtml === !0, r = t ? `frame-src about:${n ? " data: blob: http: https:" : ""}` : "frame-src 'none'", i = n ? "base-uri 'self' http: https:" : "base-uri 'none'", a = n ? "form-action http: https:" : "form-action 'none'";
1019
- return e ? `default-src 'none'; img-src data:; style-src 'unsafe-inline'; script-src 'unsafe-inline'; font-src data:; connect-src 'none'; media-src 'none'; object-src 'none'; ${r}; ${i}; ${a}` : `default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:; object-src 'none'; ${r}; ${i}; ${a}`;
1020
- }
1021
- function ct(e) {
1022
- if (e === void 0) return;
1023
- if (!e || typeof e != "object" || Array.isArray(e)) throw TypeError("images must be an object mapping relative URLs to data: image URLs.");
1024
- let t = Object.entries(e);
1025
- if (t.length > Ze) throw RangeError(`images cannot contain more than ${Ze} entries.`);
1026
- let n = 0;
1027
- for (let [e, r] of t) {
1028
- if (!e || e.length > $e || Xe.test(e) || e === "__proto__") throw TypeError("Every image key must be a bounded, control-free URL.");
1029
- if (typeof r != "string" || !Ye.test(r)) throw TypeError(`The image map for "${e}" must contain a base64 PNG, JPEG, GIF or WebP data URL.`);
1030
- if (n += r.length, n > Qe) throw RangeError("The embedded image map exceeds the 40 MiB budget.");
1031
- }
1032
- return Object.fromEntries(t);
1033
- }
1034
- function lt(e, t) {
1035
- let n = H(e, t);
1036
- if (!n.ok) return n;
1037
- let r = {};
1038
- for (let [t, i] of Object.entries(e.bindings)) r[t] = Object.hasOwn(n.state, t) ? {
1039
- ...i,
1040
- initial: Q(n.state[t])
1041
- } : i;
1042
- let i = { ...e.initialState };
1043
- for (let [e, t] of Object.entries(n.state)) i[e] = Q(t);
1044
- return {
1045
- ok: !0,
1046
- baseline: {
1047
- document: {
1048
- ...e,
1049
- bindings: r,
1050
- initialState: i
1051
- },
1052
- state: n.state
1311
+ if (typeof i.baseRevision != "number" || i.baseRevision !== a.revision) {
1312
+ o("The requested base revision is not current", "stale-base");
1313
+ return;
1314
+ }
1315
+ if (i.optionsKey !== void 0 && i.optionsKey !== a.optionsKey) {
1316
+ o("The options signature changed since the baseline", "options-mismatch");
1317
+ return;
1318
+ }
1319
+ if (!$(i.edit)) {
1320
+ o("The source edit is invalid", "invalid-edit");
1321
+ return;
1322
+ }
1323
+ let s = i.edit;
1324
+ if (s.to > a.source.length) {
1325
+ o("The source edit does not fit the baseline", "invalid-edit");
1326
+ return;
1327
+ }
1328
+ let u = a.source.slice(0, s.from) + s.insert + a.source.slice(s.to);
1329
+ if (typeof i.targetLength == "number" && u.length !== i.targetLength) {
1330
+ o("The source edit produced an unexpected length", "invalid-edit");
1331
+ return;
1332
+ }
1333
+ let d = x(i.revision), f = W();
1334
+ try {
1335
+ let e = _t(r, u, a.options), t = G(W() - f), o = a.revision, s = a.result;
1336
+ l = d, c = {
1337
+ source: u,
1338
+ revision: d,
1339
+ options: a.options,
1340
+ optionsKey: a.optionsKey,
1341
+ result: e,
1342
+ deep: rt(e),
1343
+ flatResults: a.flatResults
1344
+ };
1345
+ let p = null, h = 0;
1346
+ if (e.ok && s.ok && !c.deep && !a.deep) {
1347
+ let t = W();
1348
+ p = Xe(s, e), h = G(W() - t);
1349
+ }
1350
+ let g = p?.patch ?? null;
1351
+ if (g === null) {
1352
+ S(i.id, d, t, !0, i.includeAuthorAnalysis === !0) && v();
1353
+ return;
1354
+ }
1355
+ if (p !== null && p.cost.preferFull) {
1356
+ let e = p.cost, n = {
1357
+ patchEncodeMs: h,
1358
+ patchFallback: "cost",
1359
+ patchBytes: e.patchBytes,
1360
+ ...e.fullBytes === void 0 ? {} : { fullBytes: e.fullBytes }
1361
+ };
1362
+ S(i.id, d, t, !0, i.includeAuthorAnalysis === !0, n) && v();
1363
+ return;
1364
+ }
1365
+ let _ = {
1366
+ compileMs: t,
1367
+ patchEncodeMs: h,
1368
+ patchNodes: g.document.nodes?.length ?? 0,
1369
+ ...m === void 0 ? {} : { preparationMs: m }
1370
+ };
1371
+ try {
1372
+ let s = {
1373
+ id: i.id,
1374
+ ok: !0,
1375
+ protocol: A,
1376
+ baseRevision: o,
1377
+ revision: d,
1378
+ patch: g,
1379
+ duration: t,
1380
+ incremental: Z(r),
1381
+ metrics: _
1382
+ };
1383
+ if (i.includeAuthorAnalysis === !0) {
1384
+ let t = W();
1385
+ s.analysis = K(u, a.options, e), _.analysisMs = G(W() - t);
1386
+ }
1387
+ n.postMessage(s), v();
1388
+ } catch (e) {
1389
+ Q(n, i.id, `Could not return the compile result: ${U(e)}`);
1390
+ }
1391
+ } catch (e) {
1392
+ Q(n, i.id, U(e));
1393
+ }
1394
+ }, {
1395
+ dispose: y,
1396
+ cancelPreparation: h,
1397
+ get disposed() {
1398
+ return u;
1053
1399
  }
1054
1400
  };
1055
1401
  }
1056
- var ut = "\n:root { color-scheme: light; background: #f5f7fb; }\nhtml, body { margin: 0; }\nbody.reactive-md-export {\n min-height: 100vh;\n padding: clamp(16px, 4vw, 48px);\n background: #f5f7fb;\n color: #17233d;\n font-family: system-ui, -apple-system, \"Segoe UI\", sans-serif;\n}\n.reactive-md-export-root { max-width: 840px; margin: 0 auto; }\n@media print {\n :root, html, body.reactive-md-export { background: #fff !important; }\n body.reactive-md-export { min-height: 0; padding: 0 !important; }\n .reactive-md-export-root { max-width: none !important; margin: 0 !important; }\n}\n";
1057
- function dt(e) {
1058
- let t = e.targetId ?? "reactive-md-document";
1059
- if (!qe.test(t)) throw TypeError("targetId must start with a letter and contain only letters, digits, underscores or hyphens.");
1060
- let n = e.mode === "static" ? "static" : "interactive";
1061
- if (!e.staticMarkup.trim()) throw TypeError("createShareableHtml requires rendered document markup.");
1062
- if (!e.css.trim()) throw TypeError("createShareableHtml requires the document stylesheet.");
1063
- if (e.state.sourceDigest !== A(e.source)) throw Error("The state file does not belong to the exported source.");
1064
- if (n === "interactive" && !e.runtimeScript?.trim()) throw TypeError("Interactive HTML requires the standalone runtime script.");
1065
- let r = rt(e.compileOptions), i = _(r);
1066
- if (!i.ok) throw TypeError(`createShareableHtml received invalid compileOptions: ${i.message}`);
1067
- let a = i.htmlActive, o = e.staticMarkup;
1068
- if (a && (n === "static" || !i.html.enableJavaScript)) {
1069
- let t = {
1070
- enableCss: i.html.enableCss,
1071
- enableJavaScript: !1,
1072
- enableExtendedHtml: i.html.enableExtendedHtml
1073
- }, n = te(e.source, t, i.maxSyntaxNodes);
1074
- if (!n.markup) throw Error("The native HTML document could not be regenerated without author JavaScript.");
1075
- o = ot(e.staticMarkup, n.markup, ee(t));
1076
- }
1077
- let s = e.locale === "zh" ? "zh" : "en", c = s === "zh" ? "zh-CN" : "en", l = e.colorScheme === "light" || e.colorScheme === "dark" ? e.colorScheme : "auto", u = e.assets === "omit" ? "omit" : "inline", d = e.generator ?? {
1078
- name: "reactive-md",
1079
- version: "unknown"
1080
- }, f = ct(e.images), p = Number.isSafeInteger(e.imageCount) && (e.imageCount ?? 0) > 0 ? String(e.imageCount) : String(Object.keys(f ?? {}).length), m = n === "interactive", h = {
1081
- version: 1,
1082
- target: t,
1083
- source: e.source,
1084
- state: e.state,
1085
- locale: s,
1086
- colorScheme: l,
1087
- hydrate: !0,
1088
- ...r === void 0 ? {} : { compileOptions: r },
1089
- ...f ? { images: f } : {}
1090
- }, g = st(m, a ? i.html : void 0), v = m ? `<script type="application/reactive-md+json" data-reactive-md-auto>${nt(h)}<\/script>
1091
- <script>${tt(e.runtimeScript)}<\/script>` : "", y = e.notices?.trim() ? `<template id="reactive-md-notices"><pre>${X(e.notices)}</pre></template>` : "";
1092
- return `<!doctype html>
1093
- <html lang="${X(Je.test(c) ? c : "en", !0)}">
1094
- <head>
1095
- <meta charset="utf-8">
1096
- <meta name="viewport" content="width=device-width, initial-scale=1">
1097
- <meta name="referrer" content="no-referrer">
1098
- <meta http-equiv="Content-Security-Policy" content="${Z(g)}">
1099
- <meta name="generator" content="${Z(`${d.name} ${d.version}`)}">
1100
- <meta name="reactive-md-html-format" content="${Ke}">
1101
- <meta name="reactive-md-syntax" content="${Z(e.state.syntax)}">
1102
- <meta name="reactive-md-output" content="${n}">
1103
- <meta name="reactive-md-state" content="${Z(e.state.sourceDigest)}">
1104
- <meta name="reactive-md-images" content="${u}">
1105
- <meta name="reactive-md-image-count" content="${p}">
1106
- <title>${X(e.title || "Reactive MD document")}</title>
1107
- <style>${et(e.css)}${ut}</style>
1108
- </head>
1109
- <body class="reactive-md-export">
1110
- <div id="${t}" class="reactive-md-export-root">${o}</div>
1111
- ${v}
1112
- ${y}
1113
- </body>
1114
- </html>
1115
- `;
1116
- }
1117
- export { c as DEFAULT_LOCAL_THEME, Re as LOCAL_COMPILE_DELAY_MS, ne as LOCAL_DIAGNOSTIC_CODES, C as LOCAL_STATE_FORMAT, r as LOCAL_SYNTAX_VERSION, ie as LOCAL_THEME_PROTOCOL, Ue as LocalCompileScheduler, o as LocalExpressionError, Ke as SHAREABLE_HTML_FORMAT, le as analyzeLocalSource, U as applyLocalState, Le as applyLocalStateRetention, _e as checkLocalUpgrade, s as compileExpression, Y as compileFailureDiagnostic, n as compileLatex, x as compileLocal, se as completeLocalSource, v as countLocalCodePoints, ue as createLocalRuntime, L as createLocalStateFile, dt as createShareableHtml, ke as exportLocalState, l as formatLocalDiagnostic, ce as formatLocalSource, Ae as importLocalState, he as inspectLocalSourceVersion, y as isLocalDiagnosticCode, ae as isLocalThemeName, b as localCompileOptionsKey, d as localDiagnosticTemplate, g as localDiagnosticTemplateKeys, A as localSourceDigest, ve as migrateLocalSource, R as parseLocalState, Fe as planLocalStateRetention, oe as renameLocalBinding, H as resolveLocalState, lt as resolveLocalStateBaseline, u as resolveLocalTheme, t as samplePlot, nt as serializeForScript, je as serializeLocalState, Ge as startLocalCompileWorker };
1402
+ export { y as DEFAULT_LOCAL_THEME, ot as LOCAL_COMPILE_DELAY_MS, st as LOCAL_COMPILE_PREPARATION_DELAY_MS, o as LOCAL_DIAGNOSTIC_CODES, A as LOCAL_RESULT_PATCH_PROTOCOL, ge as LOCAL_STATE_FORMAT, _ as LOCAL_SYNTAX_VERSION, x as LOCAL_THEME_PROTOCOL, gt as LocalCompileScheduler, ie as LocalCompileSession, p as LocalExpressionError, we as SHAREABLE_HTML_FORMAT, xe as SHAREABLE_HTML_FORMAT_V2, w as analyzeLocalSource, nt as applyLocalResultPatch, Se as applyLocalState, le as applyLocalStateRetention, Le as applySourceEdit, Ne as checkLocalUpgrade, m as compileExpression, X as compileFailureDiagnostic, n as compileLatex, ee as compileLocal, t as compilePlotFormula, ne as completeLocalSource, g as countLocalCodePoints, T as createLocalCompileSession, fe as createLocalRuntime, be as createLocalStateFile, Ce as createShareableHtml, R as diffSourceEdit, Ye as encodeLocalResultPatch, ve as exportLocalState, c as formatLocalDiagnostic, re as formatLocalSource, e as implicitGridSize, _e as importLocalState, je as inspectLocalSourceVersion, f as isLocalDiagnosticCode, s as isLocalThemeName, S as localCompileOptionsKey, d as localDiagnosticTemplate, l as localDiagnosticTemplateKeys, pe as localSourceDigest, J as localWorkerOptionsKey, Pe as migrateLocalSource, ue as notifyLocalRuntime, me as parseLocalState, ce as planLocalStateRetention, i as plotFormulaKind, te as renameLocalBinding, De as resolveLocalComponentStateExport, Te as resolveLocalState, ye as resolveLocalStateBaseline, v as resolveLocalTheme, se as sampleImplicit, ae as sampleParametric, oe as samplePlot, he as serializeForScript, Ee as serializeLocalState, bt as startLocalCompileWorker, de as updateLocalRuntime };