reactive-md 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (441) hide show
  1. package/CHANGELOG-ch.md +54 -4
  2. package/CHANGELOG.md +55 -4
  3. package/CONTRIBUTING-ch.md +13 -2
  4. package/CONTRIBUTING.md +13 -2
  5. package/README-ch.md +132 -23
  6. package/README-en.md +130 -21
  7. package/README.md +128 -21
  8. package/SECURITY-ch.md +3 -3
  9. package/SECURITY.md +3 -3
  10. package/THIRD_PARTY_NOTICES.md +111 -1
  11. package/cli/args.mjs +51 -1
  12. package/cli/assets.mjs +6 -1
  13. package/cli/build.mjs +125 -9
  14. package/cli/fs-utils.mjs +3 -3
  15. package/cli/help.mjs +12 -5
  16. package/cli/init.mjs +1 -1
  17. package/cli/package.mjs +1 -0
  18. package/dist-library/LocalDocumentView-sthUP0ct.js +109 -0
  19. package/dist-library/LocalDocumentViewCore-GiWV3bey.js +9829 -0
  20. package/dist-library/LocalReactiveDocumentCore-ZjQSGyHE.js +275 -0
  21. package/dist-library/{authoring-BsfSwQRm.js → authoring-Dsune4Hy.js} +240 -218
  22. package/dist-library/compile-wUv8KEge.js +1249 -0
  23. package/dist-library/{compiler-core-kPiH-gOV.js → compiler-core-As_m-MNm.js} +5372 -5559
  24. package/dist-library/compiler-eOfcinZs.js +62 -0
  25. package/dist-library/component-state-BoLCGee4.js +801 -0
  26. package/dist-library/{component-state-D_cw_EHe.js → component-state-C52ZFJGl.js} +2 -2
  27. package/dist-library/{registry-B9Jc3FVe.js → config-BadfhjdP.js} +374 -457
  28. package/dist-library/{config-validation-DXTynAw7.js → config-validation-F47AcE6o.js} +549 -751
  29. package/dist-library/controls-CcT6n7k_.js +6740 -0
  30. package/dist-library/coordinate-CWS9p5q_.js +293 -0
  31. package/dist-library/data-table-Bgccxd7h.js +296 -0
  32. package/dist-library/{default-components-Z_YMio5P.js → default-components-BwQf0oP-.js} +344 -334
  33. package/dist-library/{math-display-BJz4gbFc.js → display-B-VhqVND.js} +1299 -1299
  34. package/dist-library/export-BqVmTXm8.js +369 -0
  35. package/dist-library/gallery-CY6mTx8i.js +360 -0
  36. package/dist-library/html-CNT4KD-2.js +757 -0
  37. package/dist-library/{math-sample-BGEW49zY.js → incremental-Dv0FSp_U.js} +476 -394
  38. package/dist-library/latex-1w7aQgD5.js +928 -0
  39. package/dist-library/layout-C0YlEPGr.js +562 -0
  40. package/dist-library/mount-preset-KxvtKgJb.js +13 -0
  41. package/dist-library/options-1aDLK7JY.js +121 -0
  42. package/dist-library/{react-ByOHunUW.js → package-core-WFK1RhAZ.js} +49 -55
  43. package/dist-library/{parser-standard-DlCk7sLo.js → parser-standard-Yuf3A_VI.js} +6605 -7097
  44. package/dist-library/plugin-packs-B1XPWcFs.js +18 -0
  45. package/dist-library/{identity-MYJXKSkB.js → preset-core-CKc5YXSM.js} +31 -31
  46. package/dist-library/{props-DGlBk0e5.js → props-sJ8vk0cr.js} +1 -1
  47. package/dist-library/react-BbyAgeXc.js +6070 -0
  48. package/dist-library/react-D5iGiUdL.js +7 -0
  49. package/dist-library/reactive-md-authoring.js +222 -223
  50. package/dist-library/reactive-md-build.js +126 -72
  51. package/dist-library/reactive-md-compiler-standard.js +12 -10
  52. package/dist-library/reactive-md-compiler.js +3 -3
  53. package/dist-library/reactive-md-default-packs.js +2 -2
  54. package/dist-library/reactive-md-default-preset.js +4 -4
  55. package/dist-library/reactive-md-export-assets.js +57 -0
  56. package/dist-library/reactive-md-export.js +5 -111
  57. package/dist-library/reactive-md-minimal-preset.js +24 -0
  58. package/dist-library/reactive-md-minimal-react-preset.js +26 -0
  59. package/dist-library/reactive-md-minimal-styles.js +80 -0
  60. package/dist-library/reactive-md-minimal.css +2 -0
  61. package/dist-library/reactive-md-pdf.js +7582 -0
  62. package/dist-library/reactive-md-plugin-chart.js +13 -0
  63. package/dist-library/reactive-md-plugin-data.js +17 -0
  64. package/dist-library/reactive-md-plugin-diagram.js +18 -0
  65. package/dist-library/reactive-md-plugin-forms.js +18 -0
  66. package/dist-library/reactive-md-plugin-gallery.js +12 -0
  67. package/dist-library/reactive-md-plugin-navigation.js +15 -0
  68. package/dist-library/reactive-md-plugin-network.js +222 -0
  69. package/dist-library/reactive-md-plugin-plot.js +24 -0
  70. package/dist-library/reactive-md-print.css +5 -0
  71. package/dist-library/reactive-md-react-minimal.js +28 -0
  72. package/dist-library/reactive-md-react-server.js +34 -32
  73. package/dist-library/reactive-md-react-unstyled.js +14 -9
  74. package/dist-library/reactive-md-react.js +14 -9
  75. package/dist-library/reactive-md-runtime-browser.js +847 -15
  76. package/dist-library/reactive-md-runtime.js +3 -3
  77. package/dist-library/reactive-md-sdk.js +8 -6
  78. package/dist-library/reactive-md-standalone-configured.js +16 -0
  79. package/dist-library/reactive-md-standalone-host.js +9 -438
  80. package/dist-library/reactive-md-testing-browser.js +5 -4
  81. package/dist-library/reactive-md-testing-react.js +46 -44
  82. package/dist-library/reactive-md-testing.js +45 -44
  83. package/dist-library/reactive-md-vite.js +135 -37
  84. package/dist-library/reactive-md.css +1 -1
  85. package/dist-library/reactive-md.js +590 -498
  86. package/dist-library/registry-B9NGct4d.js +20 -0
  87. package/dist-library/registry-core-Bbad9Bm2.js +479 -0
  88. package/dist-library/{resources-BGt8mpDA.js → resources-D2GDQS0p.js} +45 -45
  89. package/dist-library/{runtime-Dkq7ldyg.js → runtime-B2fxeveq.js} +1 -1
  90. package/dist-library/runtime-kcA7bG7G.js +1282 -0
  91. package/dist-library/sample-bP4zHB3L.js +289 -0
  92. package/dist-library/{schema-ZFufO8V0.js → schema-BufhKUSM.js} +12 -11
  93. package/dist-library/sdk-core-BoJT1SIt.js +1166 -0
  94. package/dist-library/session-core-nmJHuR9c.js +452 -0
  95. package/dist-library/{shareable-DDVL4Fi9.js → shareable-DpbE-59H.js} +250 -283
  96. package/dist-library/tooltip-layer-HDLrSWs0.js +28 -0
  97. package/dist-library/types/authoring/catalog.d.ts +2 -3
  98. package/dist-library/types/authoring/editor-i18n.d.ts +1 -1
  99. package/dist-library/types/authoring/index.d.ts +1 -1
  100. package/dist-library/types/authoring/insert.d.ts +1 -1
  101. package/dist-library/types/authoring/templates.d.ts +2 -2
  102. package/dist-library/types/build/diagnostics.d.ts +1 -1
  103. package/dist-library/types/build/host.d.ts +1 -1
  104. package/dist-library/types/build/index.d.ts +1 -1
  105. package/dist-library/types/build/notices.d.ts +1 -1
  106. package/dist-library/types/build/resources.d.ts +1 -1
  107. package/dist-library/types/build/vite.d.ts +1 -1
  108. package/dist-library/types/compiler/index.d.ts +2 -2
  109. package/dist-library/types/compiler/result.d.ts +1 -1
  110. package/dist-library/types/compiler/standard.d.ts +2 -2
  111. package/dist-library/types/compiler/types.d.ts +1 -1
  112. package/dist-library/types/components/{controls.d.ts → controls/controls.d.ts} +2 -3
  113. package/dist-library/types/components/{numeric-sliders.d.ts → controls/numeric-sliders.d.ts} +1 -1
  114. package/dist-library/types/components/{gallery.d.ts → gallery/gallery.d.ts} +1 -1
  115. package/dist-library/types/components/{layout.d.ts → layout/layout.d.ts} +1 -1
  116. package/dist-library/types/components/minimal-preset.d.ts +2 -0
  117. package/dist-library/types/components/mount-preset.d.ts +4 -0
  118. package/dist-library/types/components/network/submit-button.d.ts +10 -0
  119. package/dist-library/types/components/plot/coordinate.d.ts +2 -0
  120. package/dist-library/types/components/plugins/chart.d.ts +2 -0
  121. package/dist-library/types/components/plugins/data.d.ts +2 -0
  122. package/dist-library/types/components/plugins/diagram.d.ts +2 -0
  123. package/dist-library/types/components/plugins/forms.d.ts +2 -0
  124. package/dist-library/types/components/plugins/gallery.d.ts +2 -0
  125. package/dist-library/types/components/plugins/navigation.d.ts +2 -0
  126. package/dist-library/types/components/plugins/network.d.ts +2 -0
  127. package/dist-library/types/components/plugins/plot.d.ts +2 -0
  128. package/dist-library/types/components/shared/visual-frame.d.ts +12 -0
  129. package/dist-library/types/components/{visuals.d.ts → shared/visuals.d.ts} +1 -7
  130. package/dist-library/types/components/{data-table.d.ts → table/data-table.d.ts} +2 -2
  131. package/dist-library/types/export/component-state.d.ts +1 -1
  132. package/dist-library/types/export/index.d.ts +2 -1
  133. package/dist-library/types/export/print-document.d.ts +18 -0
  134. package/dist-library/types/export/render-markup.d.ts +23 -0
  135. package/dist-library/types/export/requirements.d.ts +1 -1
  136. package/dist-library/types/export/resources.d.ts +1 -1
  137. package/dist-library/types/export/restoration.d.ts +1 -1
  138. package/dist-library/types/export-assets/index.d.ts +25 -0
  139. package/dist-library/types/local/compilation/compiler-attributes.d.ts +8 -0
  140. package/dist-library/types/local/compilation/compiler-bindings.d.ts +19 -0
  141. package/dist-library/types/local/compilation/compiler-capabilities.d.ts +3 -0
  142. package/dist-library/types/local/compilation/compiler-core.d.ts +11 -3
  143. package/dist-library/types/local/compilation/compiler-declarations.d.ts +32 -0
  144. package/dist-library/types/local/compilation/compiler-expressions.d.ts +32 -0
  145. package/dist-library/types/local/compilation/compiler-services.d.ts +62 -16
  146. package/dist-library/types/local/compilation/compiler-structure.d.ts +38 -3
  147. package/dist-library/types/local/compilation/compiler-tables.d.ts +30 -0
  148. package/dist-library/types/local/compilation/compiler-validation.d.ts +15 -0
  149. package/dist-library/types/local/compilation/compiler-values.d.ts +39 -1
  150. package/dist-library/types/local/compilation/compiler.d.ts +7 -14
  151. package/dist-library/types/local/compilation/dependencies.d.ts +1 -1
  152. package/dist-library/types/local/compilation/session/incremental.d.ts +75 -0
  153. package/dist-library/types/local/{session → compilation/session}/row-reuse.d.ts +1 -1
  154. package/dist-library/types/local/{session/compiler-cache.d.ts → compilation/session/semantic-cache.d.ts} +5 -19
  155. package/dist-library/types/local/compilation/streaming.d.ts +27 -0
  156. package/dist-library/types/local/configuration/capability-policy.d.ts +3 -0
  157. package/dist-library/types/local/{compilation → configuration}/component-kernel.d.ts +3 -79
  158. package/dist-library/types/local/configuration/diagnostic-messages.d.ts +1104 -1056
  159. package/dist-library/types/local/configuration/diagnostic-runtime-messages.d.ts +731 -0
  160. package/dist-library/types/local/configuration/diagnostics.d.ts +1 -1
  161. package/dist-library/types/local/configuration/kernel-value-rules.d.ts +66 -0
  162. package/dist-library/types/local/configuration/official-leaf-syntax.d.ts +24 -0
  163. package/dist-library/types/local/configuration/options-core.d.ts +5 -4
  164. package/dist-library/types/local/configuration/options.d.ts +2 -1
  165. package/dist-library/types/local/configuration/portable-options.d.ts +1 -1
  166. package/dist-library/types/local/configuration/schema-core.d.ts +1 -1
  167. package/dist-library/types/local/configuration/schema.d.ts +1 -1
  168. package/dist-library/types/local/css/author-css.d.ts +66 -0
  169. package/dist-library/types/local/evaluation/computations.d.ts +2 -2
  170. package/dist-library/types/local/evaluation/expression/compile.d.ts +30 -0
  171. package/dist-library/types/local/evaluation/expression/evaluation.d.ts +3 -0
  172. package/dist-library/types/local/evaluation/expression/inference.d.ts +4 -0
  173. package/dist-library/types/local/evaluation/expression/syntax.d.ts +72 -0
  174. package/dist-library/types/local/evaluation/expression/values.d.ts +56 -0
  175. package/dist-library/types/local/evaluation/{math-display.d.ts → math/display.d.ts} +2 -2
  176. package/dist-library/types/local/evaluation/math/evaluation.d.ts +10 -0
  177. package/dist-library/types/local/evaluation/{math.d.ts → math/latex.d.ts} +58 -17
  178. package/dist-library/types/local/evaluation/{math-sample.d.ts → math/sample.d.ts} +4 -2
  179. package/dist-library/types/local/evaluation/math/syntax.d.ts +72 -0
  180. package/dist-library/types/local/evaluation/validation.d.ts +1 -1
  181. package/dist-library/types/local/html/extended-fragment.d.ts +41 -0
  182. package/dist-library/types/local/html/html-details.d.ts +1 -1
  183. package/dist-library/types/local/html/html-entities.d.ts +11 -2
  184. package/dist-library/types/local/html/html-recovery.d.ts +1 -1
  185. package/dist-library/types/local/html/html-table.d.ts +1 -1
  186. package/dist-library/types/local/html/html.d.ts +40 -4
  187. package/dist-library/types/local/index.d.ts +14 -13
  188. package/dist-library/types/local/parsing/author-markdown.d.ts +11 -0
  189. package/dist-library/types/local/{markdown → parsing}/fast-markdown.d.ts +1 -1
  190. package/dist-library/types/local/{markdown → parsing}/footnotes.d.ts +1 -1
  191. package/dist-library/types/local/{markdown → parsing}/heading-anchors.d.ts +1 -1
  192. package/dist-library/types/local/parsing/html-attributes.d.ts +14 -0
  193. package/dist-library/types/local/parsing/parse-budget.d.ts +1 -1
  194. package/dist-library/types/local/{session → parsing}/parse-session.d.ts +5 -5
  195. package/dist-library/types/local/parsing/parser-capabilities.d.ts +7 -2
  196. package/dist-library/types/local/parsing/parser-convert.d.ts +26 -0
  197. package/dist-library/types/local/parsing/parser-core.d.ts +10 -4
  198. package/dist-library/types/local/parsing/parser-internals.d.ts +54 -0
  199. package/dist-library/types/local/parsing/parser-region.d.ts +46 -0
  200. package/dist-library/types/local/parsing/parser-standard.d.ts +3 -0
  201. package/dist-library/types/local/parsing/parser-tags.d.ts +108 -0
  202. package/dist-library/types/local/parsing/parser.d.ts +3 -3
  203. package/dist-library/types/local/{markdown → parsing}/plain-paragraphs.d.ts +1 -1
  204. package/dist-library/types/local/parsing/rmd-recovery.d.ts +1 -1
  205. package/dist-library/types/local/parsing/theme-declaration.d.ts +22 -0
  206. package/dist-library/types/local/rendering/document/ExtendedHtmlFragment.d.ts +14 -0
  207. package/dist-library/types/local/rendering/document/LocalDocumentView.d.ts +5 -0
  208. package/dist-library/types/local/rendering/{LocalDocumentView.d.ts → document/LocalDocumentViewCore.d.ts} +48 -9
  209. package/dist-library/types/local/rendering/document/LocalReactiveDocumentCore.d.ts +6 -0
  210. package/dist-library/types/local/rendering/document/render-nodes.d.ts +24 -0
  211. package/dist-library/types/local/rendering/document/use-author-script.d.ts +3 -0
  212. package/dist-library/types/local/rendering/document/use-color-scheme.d.ts +10 -0
  213. package/dist-library/types/local/rendering/document/validation-state.d.ts +31 -0
  214. package/dist-library/types/local/rendering/document/view-render-context.d.ts +146 -0
  215. package/dist-library/types/local/rendering/{view-revision.d.ts → document/view-revision.d.ts} +31 -4
  216. package/dist-library/types/local/rendering/render-types.d.ts +1 -1
  217. package/dist-library/types/local/{widgets/table-surface.d.ts → rendering/table/data-table.d.ts} +3 -0
  218. package/dist-library/types/local/rendering/table/table-numeric-columns.d.ts +7 -0
  219. package/dist-library/types/local/runtime/author-script-protocol.d.ts +59 -0
  220. package/dist-library/types/local/runtime/retention.d.ts +1 -1
  221. package/dist-library/types/local/runtime/runtime-document.d.ts +71 -0
  222. package/dist-library/types/local/runtime/runtime-migration.d.ts +19 -0
  223. package/dist-library/types/local/runtime/runtime-values.d.ts +39 -0
  224. package/dist-library/types/local/runtime/runtime.d.ts +4 -2
  225. package/dist-library/types/local/runtime/state.d.ts +1 -1
  226. package/dist-library/types/local/source/authoring-syntax.d.ts +48 -0
  227. package/dist-library/types/local/source/authoring.d.ts +1 -1
  228. package/dist-library/types/local/source/source-context.d.ts +23 -0
  229. package/dist-library/types/local/source/source-migration.d.ts +2 -2
  230. package/dist-library/types/local/transport/compile-patch.d.ts +1 -1
  231. package/dist-library/types/local/transport/flat-compiled-data.d.ts +1 -1
  232. package/dist-library/types/local/transport/shared-data.d.ts +1 -1
  233. package/dist-library/types/local/transport/worker-handler.d.ts +30 -0
  234. package/dist-library/types/local/transport/worker-job.d.ts +28 -0
  235. package/dist-library/types/local/transport/worker.d.ts +32 -46
  236. package/dist-library/types/local/{contracts/types.d.ts → types.d.ts} +78 -21
  237. package/dist-library/types/pdf.d.ts +22 -0
  238. package/dist-library/types/presets/identity.d.ts +1 -0
  239. package/dist-library/types/presets/minimal.d.ts +2 -0
  240. package/dist-library/types/presets/plugin-packs.d.ts +1 -0
  241. package/dist-library/types/react/component-api.d.ts +20 -4
  242. package/dist-library/types/react/component-primitives.d.ts +10 -10
  243. package/dist-library/types/react/component-utils.d.ts +9 -1
  244. package/dist-library/types/react/index.d.ts +6 -5
  245. package/dist-library/types/{local/theme/i18n.d.ts → react/localization.d.ts} +2 -2
  246. package/dist-library/types/react/minimal.d.ts +13 -0
  247. package/dist-library/types/react/package-core.d.ts +67 -0
  248. package/dist-library/types/react/package.d.ts +3 -67
  249. package/dist-library/types/react/runtime/common.d.ts +1 -1
  250. package/dist-library/types/react/sdk-core.d.ts +115 -0
  251. package/dist-library/types/react/sdk.d.ts +4 -110
  252. package/dist-library/types/react/server.d.ts +2 -2
  253. package/dist-library/types/react/use-draft-field.d.ts +5 -1
  254. package/dist-library/types/runtime-services/browser/duplex.d.ts +163 -0
  255. package/dist-library/types/runtime-services/browser/http-sse.d.ts +117 -0
  256. package/dist-library/types/runtime-services/browser/index.d.ts +2 -1
  257. package/dist-library/types/runtime-services/component-state.d.ts +1 -1
  258. package/dist-library/types/runtime-services/index.d.ts +2 -0
  259. package/dist-library/types/runtime-services/network.d.ts +86 -0
  260. package/dist-library/types/runtime-services/runtime.d.ts +1 -1
  261. package/dist-library/types/sdk/config.d.ts +1 -1
  262. package/dist-library/types/sdk/index.d.ts +1 -0
  263. package/dist-library/types/sdk/props.d.ts +1 -1
  264. package/dist-library/types/sdk/registry-core.d.ts +1 -1
  265. package/dist-library/types/sdk/theme.d.ts +5 -4
  266. package/dist-library/types/sdk/types.d.ts +2 -2
  267. package/dist-library/types/shareable.d.ts +6 -5
  268. package/dist-library/types/standalone/diagnostics.d.ts +1 -1
  269. package/dist-library/types/standalone/host.d.ts +5 -0
  270. package/dist-library/types/standalone/payload.d.ts +1 -1
  271. package/dist-library/types/standalone/prepare.d.ts +2 -2
  272. package/dist-library/types/standalone/session-core.d.ts +68 -0
  273. package/dist-library/types/standalone/session.d.ts +6 -68
  274. package/dist-library/types/themes/contract.d.ts +7 -0
  275. package/dist-library/types/{local/theme/theme.d.ts → themes/document-theme.d.ts} +4 -3
  276. package/dist-library/types/vite/client.d.ts +19 -0
  277. package/dist-library/types/vite/index.d.ts +18 -3
  278. package/dist-library/types/vite/registration.d.ts +2 -2
  279. package/dist-library/{types-BFCrMrg0.js → types-BeNtPqdY.js} +1 -1
  280. package/dist-library/validation-BEBA_HvS.js +1121 -0
  281. package/dist-library/visual-frame-CyV1FXzs.js +48 -0
  282. package/dist-library/visuals-B5KSafVk.js +3 -0
  283. package/dist-library/visuals-BZbZYA7w.js +72572 -0
  284. package/dist-standalone/reactive-md-standalone.css +1 -1
  285. package/dist-standalone/reactive-md-standalone.js +146 -137
  286. package/docs/README-ch.md +16 -11
  287. package/docs/README.md +16 -11
  288. package/docs/compatibility/compatibility-ch.md +8 -8
  289. package/docs/compatibility/compatibility-en.md +8 -8
  290. package/docs/compatibility/source-versioning-ch.md +1 -1
  291. package/docs/compatibility/source-versioning-en.md +1 -1
  292. package/docs/development/component-development-ch.md +2 -2
  293. package/docs/development/component-development-en.md +2 -2
  294. package/docs/development/component-development-reference-ch.md +4 -4
  295. package/docs/development/component-development-reference-en.md +4 -4
  296. package/docs/development/component-protocol-ch.md +14 -14
  297. package/docs/development/component-protocol-en.md +14 -14
  298. package/docs/development/extension-tutorial-ch.md +308 -0
  299. package/docs/development/extension-tutorial-en.md +308 -0
  300. package/docs/development/local-module-layout-ch.md +10 -50
  301. package/docs/development/local-module-layout-en.md +9 -49
  302. package/docs/development/performance-overview-ch.md +174 -154
  303. package/docs/development/performance-overview-en.md +174 -154
  304. package/docs/guides/local-guide-ch.md +2 -2
  305. package/docs/guides/local-guide-en.md +2 -2
  306. package/docs/integration/author-tools-ch.md +2 -2
  307. package/docs/integration/author-tools-en.md +2 -2
  308. package/docs/integration/compiler-ch.md +4 -2
  309. package/docs/integration/compiler-en.md +4 -2
  310. package/docs/integration/directory-discovery-ch.md +5 -1
  311. package/docs/integration/directory-discovery-en.md +5 -1
  312. package/docs/integration/editor-ch.md +35 -5
  313. package/docs/integration/editor-en.md +42 -4
  314. package/docs/integration/extension-sdk-ch.md +6 -4
  315. package/docs/integration/extension-sdk-en.md +6 -4
  316. package/docs/integration/local-integration-ch.md +201 -19
  317. package/docs/integration/local-integration-en.md +194 -18
  318. package/docs/integration/network-host-ch.md +75 -0
  319. package/docs/integration/network-host-en.md +75 -0
  320. package/docs/integration/shareable-export-ch.md +58 -16
  321. package/docs/integration/shareable-export-en.md +57 -15
  322. package/docs/reference/html-compatibility-ch.md +20 -67
  323. package/docs/reference/html-compatibility-en.md +19 -64
  324. package/docs/reference/local-interaction-syntax-ch.md +199 -26
  325. package/docs/reference/local-interaction-syntax-en.md +194 -27
  326. package/docs/reference/public-api-ch.md +416 -0
  327. package/docs/reference/public-api-en.md +416 -0
  328. package/docs/reference/theme-protocol-ch.md +27 -8
  329. package/docs/reference/theme-protocol-en.md +46 -8
  330. package/docs/releases/release-0.4.0-ch.md +2 -2
  331. package/docs/releases/release-0.4.0-en.md +2 -2
  332. package/docs/releases/release-0.8.0-ch.md +19 -3
  333. package/docs/releases/release-0.8.0-en.md +19 -3
  334. package/docs/releases/release-0.9.0-ch.md +44 -0
  335. package/docs/releases/release-0.9.0-en.md +44 -0
  336. package/docs/releases/release-0.9.1-ch.md +29 -0
  337. package/docs/releases/release-0.9.1-en.md +29 -0
  338. package/examples/component-package/README-ch.md +1 -1
  339. package/examples/component-package/README.md +1 -1
  340. package/examples/conformance/README-ch.md +3 -3
  341. package/examples/conformance/README.md +3 -3
  342. package/examples/game-2048-package/README-ch.md +3 -9
  343. package/examples/game-2048-package/README.md +8 -12
  344. package/examples/integration/README-ch.md +21 -2
  345. package/examples/integration/README.md +21 -2
  346. package/examples/integration/extension-sdk/README-ch.md +1 -1
  347. package/examples/integration/extension-sdk/README.md +1 -1
  348. package/examples/integration/streaming/index.html +48 -0
  349. package/examples/integration/streaming/main.js +175 -0
  350. package/examples/integration/streaming/package.json +13 -0
  351. package/examples/integration/streaming/worker.js +3 -0
  352. package/examples/local/README-ch.md +3 -3
  353. package/examples/local/README.md +2 -2
  354. package/examples/local/minimal-budget.reactive.md +48 -0
  355. package/examples/minimal-extension/README-ch.md +78 -0
  356. package/examples/minimal-extension/README.md +78 -0
  357. package/examples/minimal-extension/index.html +15 -0
  358. package/examples/minimal-extension/package.json +26 -0
  359. package/examples/minimal-extension/sample/document.reactive.md +10 -0
  360. package/examples/minimal-extension/scripts/build.mjs +32 -0
  361. package/examples/minimal-extension/scripts/export.mjs +72 -0
  362. package/examples/minimal-extension/scripts/test-node.mjs +75 -0
  363. package/examples/minimal-extension/src/extension.tsx +90 -0
  364. package/examples/minimal-extension/src/preview.tsx +12 -0
  365. package/examples/minimal-extension/src/source.ts +4 -0
  366. package/examples/minimal-extension/tsconfig.json +14 -0
  367. package/examples/network-survey/README.md +200 -0
  368. package/examples/network-survey/index.html +49 -0
  369. package/examples/network-survey/package.json +26 -0
  370. package/examples/network-survey/sample/document.reactive.md +51 -0
  371. package/examples/network-survey/src/components.tsx +325 -0
  372. package/examples/network-survey/src/host.ts +316 -0
  373. package/examples/network-survey/src/main.tsx +91 -0
  374. package/examples/network-survey/src/source.ts +1 -0
  375. package/examples/network-survey/tsconfig.json +26 -0
  376. package/examples/network-survey/vite.config.ts +227 -0
  377. package/examples/sci-fi-theme/README-ch.md +4 -2
  378. package/examples/sci-fi-theme/README.md +4 -2
  379. package/examples/sci-fi-theme/demo/acceptance.reactive.md +454 -0
  380. package/examples/sci-fi-theme/demo/demo.css +129 -23
  381. package/examples/sci-fi-theme/demo/document.reactive.md +27 -6
  382. package/examples/sci-fi-theme/demo/main.tsx +45 -10
  383. package/examples/sci-fi-theme/docs/design-system-ch.md +6 -6
  384. package/examples/sci-fi-theme/package.json +2 -1
  385. package/examples/sci-fi-theme/src/components.css +1064 -154
  386. package/examples/sci-fi-theme/src/notch.css +142 -0
  387. package/examples/sci-fi-theme/src/sci-fi.css +3 -1
  388. package/examples/sci-fi-theme/src/theme.ts +2 -0
  389. package/examples/sci-fi-theme/src/tokens.css +512 -408
  390. package/examples/tetris-package/README-ch.md +4 -4
  391. package/examples/tetris-package/README.md +4 -4
  392. package/package.json +70 -3
  393. package/dist-library/LocalDocumentView-6trX7xJc.js +0 -97920
  394. package/dist-library/compiler--ea2CKQF.js +0 -61
  395. package/dist-library/component-state-Cq2K5gkS.js +0 -490
  396. package/dist-library/options-CX5m5n-J.js +0 -115
  397. package/dist-library/runtime-C-sbfpOX.js +0 -1157
  398. package/dist-library/types/local/contracts/locale.d.ts +0 -1
  399. package/dist-library/types/local/contracts/version.d.ts +0 -2
  400. package/dist-library/types/local/evaluation/dates.d.ts +0 -2
  401. package/dist-library/types/local/evaluation/expression.d.ts +0 -47
  402. package/dist-library/types/local/markdown/markdown-structure.d.ts +0 -3
  403. package/dist-library/types/local/rendering/legacy-component-adapter.d.ts +0 -36
  404. package/dist-library/types/local/session/incremental.d.ts +0 -48
  405. package/dist-library/types/local/source/node-walk.d.ts +0 -3
  406. package/dist-library/types/local/source/text-length.d.ts +0 -13
  407. package/dist-library/types/local/theme/theme-name.d.ts +0 -3
  408. package/dist-library/types/local/widgets/visuals.d.ts +0 -25
  409. package/dist-library/types/react/default-theme.d.ts +0 -6
  410. package/dist-library/validation-W-bmny-x.js +0 -2253
  411. package/docs/development/releasing-ch.md +0 -12
  412. package/docs/development/releasing-en.md +0 -12
  413. package/docs/integration/codemirror-ch.md +0 -52
  414. package/docs/integration/codemirror-en.md +0 -29
  415. package/docs/integration/repository-split-ch.md +0 -40
  416. package/docs/integration/repository-split-en.md +0 -23
  417. package/docs/reference/computations-formatting-ch.md +0 -89
  418. package/docs/reference/computations-formatting-en.md +0 -89
  419. package/docs/reference/constraints-collections-ch.md +0 -104
  420. package/docs/reference/constraints-collections-en.md +0 -104
  421. package/docs/reference/local-components-v2-ch.md +0 -140
  422. package/docs/reference/local-components-v2-en.md +0 -106
  423. package/docs/reference/tolerance-ch.md +0 -64
  424. package/docs/reference/tolerance-en.md +0 -57
  425. /package/dist-library/types/components/{chart-motion.d.ts → chart/chart-motion.d.ts} +0 -0
  426. /package/dist-library/types/components/{default-chart-types.d.ts → chart/default-chart-types.d.ts} +0 -0
  427. /package/dist-library/types/components/{default-chart.d.ts → chart/default-chart.d.ts} +0 -0
  428. /package/dist-library/types/components/{diagram-inspector.d.ts → diagram/diagram-inspector.d.ts} +0 -0
  429. /package/dist-library/types/{local/widgets/diagram-layout.d.ts → components/diagram/layout.d.ts} +0 -0
  430. /package/dist-library/types/components/{mafs-plot-grid.d.ts → plot/mafs-plot-grid.d.ts} +0 -0
  431. /package/dist-library/types/components/{mafs-visuals.d.ts → plot/mafs-visuals.d.ts} +0 -0
  432. /package/dist-library/types/components/{use-hydrated.d.ts → shared/use-hydrated.d.ts} +0 -0
  433. /package/dist-library/types/local/{theme/colors.d.ts → configuration/color-values.d.ts} +0 -0
  434. /package/dist-library/types/local/evaluation/{collection-functions.d.ts → expression/collection-functions.d.ts} +0 -0
  435. /package/dist-library/types/local/evaluation/{data-functions.d.ts → expression/data-functions.d.ts} +0 -0
  436. /package/dist-library/types/local/evaluation/{formatting.d.ts → expression/formatting.d.ts} +0 -0
  437. /package/dist-library/types/local/{markdown → parsing}/markdown-blocks.d.ts +0 -0
  438. /package/dist-library/types/local/{widgets → rendering/code}/code-block.d.ts +0 -0
  439. /package/dist-library/types/local/{widgets → rendering/code}/code-languages.d.ts +0 -0
  440. /package/dist-library/types/local/{widgets → rendering/image}/image-view.d.ts +0 -0
  441. /package/dist-library/types/local/{widgets → rendering}/math-view.d.ts +0 -0
@@ -1,16 +1,19 @@
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";
1
+ import { a as e, i as t, r as n, s as r } from "./latex-1w7aQgD5.js";
2
+ import { A as i, B as a, C as o, F as s, I as c, M as l, N as u, P as d, S as f, j as p, w as m, x as h } from "./config-validation-F47AcE6o.js";
3
+ import { a as g, t as _ } from "./compile-wUv8KEge.js";
4
+ import { d as v } from "./compiler-core-As_m-MNm.js";
5
+ import { S as y, g as b } from "./validation-BEBA_HvS.js";
6
+ import { c as x } from "./config-BadfhjdP.js";
7
+ import { t as S } from "./options-1aDLK7JY.js";
8
+ import { t as ee } from "./compiler-eOfcinZs.js";
9
+ import { i as te, n as ne, r as re, t as C } from "./authoring-Dsune4Hy.js";
10
+ import { c as w } from "./schema-BufhKUSM.js";
11
+ import { n as T, t as ie } from "./incremental-Dv0FSp_U.js";
12
+ import { C as ae } from "./component-state-BoLCGee4.js";
13
+ import { a as oe, i as se, n as ce, o as le, r as ue } from "./runtime-kcA7bG7G.js";
14
+ import { i as de, n as fe, r as pe, t as me } from "./sample-bP4zHB3L.js";
15
+ import { _ as he, a as ge, f as _e, g as ve, h as ye, i as be, m as xe, n as Se, p as Ce, r as we, t as Te, v as Ee, y as De } from "./shareable-DpbE-59H.js";
16
+ import { t as Oe } from "./component-state-C52ZFJGl.js";
14
17
  // src/local/source/source-migration.ts
15
18
  var E = /* @__PURE__ */ new Set([
16
19
  "sum",
@@ -30,7 +33,7 @@ var E = /* @__PURE__ */ new Set([
30
33
  "slice",
31
34
  "dateCompare",
32
35
  "dateDiff"
33
- ]), Oe = /* @__PURE__ */ new Set([
36
+ ]), ke = /* @__PURE__ */ new Set([
34
37
  "jump",
35
38
  "anchor",
36
39
  "text",
@@ -47,12 +50,12 @@ var E = /* @__PURE__ */ new Set([
47
50
  "data-table",
48
51
  "column",
49
52
  "external"
50
- ]), ke = /* @__PURE__ */ new Set(["external"]), Ae = /* @__PURE__ */ new Set([
53
+ ]), Ae = /* @__PURE__ */ new Set(["external"]), je = /* @__PURE__ */ new Set([
51
54
  "local-draft-1",
52
55
  "local-draft-2",
53
- _
54
- ]), D = `<!-- reactive-md: ${_} -->`;
55
- function O(e) {
56
+ y
57
+ ]), Me = `<!-- reactive-md: ${y} -->`;
58
+ function Ne(e) {
56
59
  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;
57
60
  return {
58
61
  declaredVersion: n,
@@ -62,27 +65,27 @@ function O(e) {
62
65
  diagnostics: t
63
66
  };
64
67
  }
65
- function je(e) {
66
- return O(C(e));
68
+ function Pe(e) {
69
+ return Ne(w(e));
67
70
  }
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");
71
+ function Fe(e, t, n, r, i = "error") {
72
+ let a = d(t, r), o = e.slice(0, n.start), s = o.lastIndexOf("\n");
70
73
  return {
71
74
  code: t,
72
75
  severity: i,
73
76
  range: { ...n },
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 } : {}
77
+ message: p(a),
78
+ line: o.split("\n").length,
79
+ column: n.start - s,
80
+ messageKey: a.key,
81
+ ...a.params ? { params: a.params } : {}
79
82
  };
80
83
  }
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 = {
84
+ function Ie(e, t = {}) {
85
+ let n = w(e), r = Ne(n), i = typeof t == "object" && !!t && !Array.isArray(t), a = i ? t.fromVersion ?? r.effectiveVersion : r.effectiveVersion, o = typeof a == "string" ? a : "", s = {
83
86
  ok: !1,
84
87
  fromVersion: o,
85
- toVersion: _,
88
+ toVersion: y,
86
89
  needsMigration: !n.versionDeclaration || o !== "local-draft-3",
87
90
  diagnostics: r.diagnostics.filter((e) => e.code !== "local.version.unsupported")
88
91
  }, c = {
@@ -103,15 +106,15 @@ function k(e, t = {}) {
103
106
  }
104
107
  s.diagnostics.push(e);
105
108
  }, d = (t, n, r, i) => {
106
- u(Me(e, t, n, r, i));
109
+ u(Fe(e, t, n, r, i));
107
110
  };
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, {
111
+ if (!i || typeof a != "string" || !je.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
112
  from: o,
110
113
  detail: "use local-draft-1, local-draft-2 or local-draft-3 and match the source declaration"
111
114
  }), 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;
115
+ 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 ? w(f) : n;
113
116
  if (o === "local-draft-1" || o === "local-draft-2") {
114
- let e = o === "local-draft-1" ? Oe : ke, n = (r) => {
117
+ let e = o === "local-draft-1" ? ke : Ae, n = (r) => {
115
118
  for (let i of r) if (i.name && e.has(i.name)) d("local.upgrade.tag", i.range, { name: i.name });
116
119
  else {
117
120
  if (o === "local-draft-1") {
@@ -143,13 +146,13 @@ function k(e, t = {}) {
143
146
  return m.ok && (!n.versionDeclaration && s.diagnostics.length < 100 && d("local.upgrade.version-missing", {
144
147
  start: +(e.charCodeAt(0) === 65279),
145
148
  end: +(e.charCodeAt(0) === 65279)
146
- }, { version: _ }, "warning"), s.ok = !0), c;
149
+ }, { version: y }, "warning"), s.ok = !0), c;
147
150
  }
148
- function Ne(e, t) {
149
- return k(e, t).report;
151
+ function Le(e, t) {
152
+ return Ie(e, t).report;
150
153
  }
151
- function Pe(e, t) {
152
- let { report: n, declaration: r } = k(e, t), i = {
154
+ function Re(e, t) {
155
+ let { report: n, declaration: r } = Ie(e, t), i = {
153
156
  ...n,
154
157
  source: e,
155
158
  changed: !1,
@@ -159,7 +162,7 @@ function Pe(e, t) {
159
162
  let a = +(e.charCodeAt(0) === 65279), o = r?.range ?? {
160
163
  start: a,
161
164
  end: a
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);
165
+ }, s = e.includes("\r\n") ? "\r\n" : "\n", c = r ? Me : `${Me}${s}${s}`, l = e.slice(0, o.start) + c + e.slice(o.end);
163
166
  return {
164
167
  ...n,
165
168
  source: l,
@@ -171,7 +174,7 @@ function Pe(e, t) {
171
174
  };
172
175
  }
173
176
  // src/local/transport/compile-patch.ts
174
- var A = "patch-v1", j = 1, Fe = 4096, M = [
177
+ var D = "patch-v1", O = 1, ze = 4096, k = [
175
178
  "initialState",
176
179
  "bindings",
177
180
  "bindingSlots",
@@ -179,16 +182,16 @@ var A = "patch-v1", j = 1, Fe = 4096, M = [
179
182
  "dependencies",
180
183
  "tableShapes"
181
184
  ];
182
- function N(e) {
185
+ function A(e) {
183
186
  return typeof e == "object" && !!e && !Array.isArray(e);
184
187
  }
185
- function P(e) {
186
- return N(e) && typeof e.start == "number" && Number.isFinite(e.start) && typeof e.end == "number" && Number.isFinite(e.end);
188
+ function j(e) {
189
+ return A(e) && typeof e.start == "number" && Number.isFinite(e.start) && typeof e.end == "number" && Number.isFinite(e.end);
187
190
  }
188
- function F() {
191
+ function M() {
189
192
  throw TypeError("Invalid local compile result patch");
190
193
  }
191
- function I(e, t) {
194
+ function N(e, t) {
192
195
  if (e === t) return !0;
193
196
  if (typeof e != "object" || typeof t != "object" || e === null || t === null) return !1;
194
197
  let n = Array.isArray(e);
@@ -196,18 +199,18 @@ function I(e, t) {
196
199
  if (n) {
197
200
  let n = e, r = t;
198
201
  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;
202
+ for (let e = 0; e < n.length; e += 1) if (!N(n[e], r[e])) return !1;
200
203
  return !0;
201
204
  }
202
205
  let r = e, i = t, a = Object.keys(r);
203
206
  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;
207
+ for (let e of a) if (!Object.hasOwn(i, e) || !N(r[e], i[e])) return !1;
205
208
  return !0;
206
209
  }
207
- function L(e) {
208
- return r(e, !1);
210
+ function P(e) {
211
+ return v(e, !1);
209
212
  }
210
- function R(e, t) {
213
+ function F(e, t) {
211
214
  if (typeof e != "string" || typeof t != "string" || e === t) return null;
212
215
  let n = Math.min(e.length, t.length), r = 0;
213
216
  for (; r < n && e.charCodeAt(r) === t.charCodeAt(r);) r += 1;
@@ -219,8 +222,8 @@ function R(e, t) {
219
222
  insert: t.slice(r, a)
220
223
  };
221
224
  }
222
- function Ie(e) {
223
- if (!N(e)) return null;
225
+ function Be(e) {
226
+ if (!A(e)) return null;
224
227
  let { from: t, to: n, insert: r } = e;
225
228
  return typeof t != "number" || !Number.isSafeInteger(t) || typeof n != "number" || !Number.isSafeInteger(n) || typeof r != "string" || t < 0 || n < t ? null : {
226
229
  from: t,
@@ -228,62 +231,62 @@ function Ie(e) {
228
231
  insert: r
229
232
  };
230
233
  }
231
- function Le(e, t) {
232
- let n = Ie(t);
234
+ function Ve(e, t) {
235
+ let n = Be(t);
233
236
  return n === null || typeof e != "string" || n.to > e.length ? null : e.slice(0, n.from) + n.insert + e.slice(n.to);
234
237
  }
235
- function z(e) {
238
+ function I(e) {
236
239
  let t = {};
237
240
  for (let [n, r] of Object.entries(e)) n !== "children" && (t[n] = r);
238
241
  return t;
239
242
  }
240
- function Re(e, t) {
243
+ function L(e, t) {
241
244
  let n = Object.keys(e).filter((e) => e !== "children"), r = Object.keys(t).filter((e) => e !== "children");
242
245
  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;
246
+ for (let r of n) if (!Object.hasOwn(t, r) || !N(e[r], t[r])) return !1;
244
247
  return !0;
245
248
  }
246
- function B(e) {
249
+ function R(e) {
247
250
  return e.children === void 0 ? void 0 : e.children.map((e) => e.id);
248
251
  }
249
- function ze(e, t) {
250
- let n = B(e), r = B(t);
252
+ function z(e, t) {
253
+ let n = R(e), r = R(t);
251
254
  if (n === void 0 || r === void 0) return n === r;
252
255
  if (n.length !== r.length) return !1;
253
256
  for (let e = 0; e < n.length; e += 1) if (n[e] !== r[e]) return !1;
254
257
  return !0;
255
258
  }
256
- function Be(e, t) {
257
- if (!Re(e, t) || !ze(e, t)) return !1;
259
+ function He(e, t) {
260
+ if (!L(e, t) || !z(e, t)) return !1;
258
261
  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;
262
+ for (let n = 0; n < e.children.length; n += 1) if (!He(e.children[n], t.children[n])) return !1;
260
263
  return !0;
261
264
  }
262
- function Ve(e, t) {
265
+ function Ue(e, t) {
263
266
  let n = Object.keys(e).filter((e) => e !== "children" && e !== "range"), r = Object.keys(t).filter((e) => e !== "children" && e !== "range");
264
267
  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;
268
+ for (let r of n) if (!Object.hasOwn(t, r) || !N(e[r], t[r])) return null;
269
+ if (!j(e.range) || !j(t.range)) return null;
267
270
  let i = e.range.start - t.range.start;
268
271
  if (e.range.end !== t.range.end + i) return null;
269
- let a = B(e), o = B(t);
272
+ let a = R(e), o = R(t);
270
273
  if (a === void 0 || o === void 0) {
271
274
  if (a !== o) return null;
272
275
  } else {
273
276
  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;
277
+ for (let n = 0; n < a.length; n += 1) if (a[n] !== o[n] || Ue(e.children[n], t.children[n]) !== i) return null;
275
278
  }
276
279
  return i;
277
280
  }
278
- function He(e, t) {
281
+ function We(e, t) {
279
282
  let n = Object.keys(e).filter((e) => e !== "children" && e !== "range"), r = Object.keys(t).filter((e) => e !== "children" && e !== "range");
280
283
  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;
284
+ for (let r of n) if (!Object.hasOwn(t, r) || !N(e[r], t[r])) return null;
285
+ if (!j(e.range) || !j(t.range)) return null;
283
286
  let i = e.range.start - t.range.start;
284
287
  return e.range.end === t.range.end + i ? i : null;
285
288
  }
286
- function Ue(e) {
289
+ function Ge(e) {
287
290
  let t = /* @__PURE__ */ new Map(), n = [...e].reverse();
288
291
  for (; n.length > 0;) {
289
292
  let e = n.pop();
@@ -291,8 +294,8 @@ function Ue(e) {
291
294
  }
292
295
  return t;
293
296
  }
294
- function We(e, t, n, r) {
295
- if (t !== void 0 && Be(e, t)) return;
297
+ function Ke(e, t, n, r) {
298
+ if (t !== void 0 && He(e, t)) return;
296
299
  if (t === void 0) {
297
300
  r.push({
298
301
  id: e.id,
@@ -300,7 +303,7 @@ function We(e, t, n, r) {
300
303
  });
301
304
  return;
302
305
  }
303
- let i = Ve(e, t);
306
+ let i = Ue(e, t);
304
307
  if (i !== null) {
305
308
  i !== 0 && r.push({
306
309
  id: e.id,
@@ -310,27 +313,27 @@ function We(e, t, n, r) {
310
313
  return;
311
314
  }
312
315
  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);
316
+ if (!L(e, t)) {
317
+ let n = We(e, t);
318
+ n !== null && n !== 0 ? a.shift = n : a.data = I(e);
316
319
  }
317
- ze(e, t) || (a.children = e.children === void 0 ? null : e.children.map((e) => e.id));
320
+ z(e, t) || (a.children = e.children === void 0 ? null : e.children.map((e) => e.id));
318
321
  let o = r.length;
319
- if (e.children) for (let t of e.children) We(t, n.get(t.id), n, r);
322
+ if (e.children) for (let t of e.children) Ke(t, n.get(t.id), n, r);
320
323
  Object.keys(a).length > 1 ? r.splice(o, 0, a) : r.length > o && r.splice(o, 0, { id: e.id });
321
324
  }
322
- function Ge(e, t) {
323
- if (!N(e)) return { set: t };
325
+ function qe(e, t) {
326
+ if (!A(e)) return { set: t };
324
327
  let n = {}, r = [];
325
- for (let [r, i] of Object.entries(t)) Object.hasOwn(e, r) && I(e[r], i) || (n[r] = i);
328
+ for (let [r, i] of Object.entries(t)) Object.hasOwn(e, r) && N(e[r], i) || (n[r] = i);
326
329
  for (let n of Object.keys(e)) Object.hasOwn(t, n) || r.push(n);
327
330
  return Object.keys(n).length === 0 && r.length === 0 ? null : {
328
331
  ...Object.keys(n).length === 0 ? {} : { set: n },
329
332
  ...r.length === 0 ? {} : { remove: r }
330
333
  };
331
334
  }
332
- var Ke = /* @__PURE__ */ new WeakMap();
333
- function qe(e) {
335
+ var Je = /* @__PURE__ */ new WeakMap();
336
+ function Ye(e) {
334
337
  let t = 2;
335
338
  for (let n = 0; n < e.length; n++) {
336
339
  let r = e.charCodeAt(n);
@@ -345,14 +348,14 @@ function qe(e) {
345
348
  }
346
349
  return t;
347
350
  }
348
- function V(e, t) {
351
+ function B(e, t) {
349
352
  if (e === null) return {
350
353
  bytes: 4,
351
354
  nodes: 0
352
355
  };
353
356
  let n = typeof e;
354
357
  if (n === "string") return {
355
- bytes: qe(e),
358
+ bytes: Ye(e),
356
359
  nodes: 0
357
360
  };
358
361
  if (n === "number") return {
@@ -367,19 +370,19 @@ function V(e, t) {
367
370
  bytes: 0,
368
371
  nodes: 0
369
372
  };
370
- let r = e, i = Ke.get(r);
373
+ let r = e, i = Je.get(r);
371
374
  if (i !== void 0) return i;
372
375
  if (t.has(r)) return {
373
376
  bytes: 0,
374
377
  nodes: 0
375
378
  };
376
379
  t.add(r);
377
- let a, o = +!!et(e);
380
+ let a, o = +!!nt(e);
378
381
  if (Array.isArray(e)) {
379
382
  a = 2;
380
383
  for (let n = 0; n < e.length; n += 1) {
381
384
  n > 0 && (a += 1);
382
- let r = V(e[n], t);
385
+ let r = B(e[n], t);
383
386
  a += r.bytes || 4, o += r.nodes;
384
387
  }
385
388
  } else {
@@ -389,8 +392,8 @@ function V(e, t) {
389
392
  if (!Object.hasOwn(r, n)) continue;
390
393
  let i = r[n];
391
394
  if (i === void 0) continue;
392
- e > 0 && (a += 1), e += 1, a += qe(n) + 1;
393
- let s = V(i, t);
395
+ e > 0 && (a += 1), e += 1, a += Ye(n) + 1;
396
+ let s = B(i, t);
394
397
  a += s.bytes, o += s.nodes;
395
398
  }
396
399
  }
@@ -399,20 +402,20 @@ function V(e, t) {
399
402
  bytes: a,
400
403
  nodes: o
401
404
  };
402
- return Ke.set(r, s), s;
405
+ return Je.set(r, s), s;
403
406
  }
404
- function Je(e, t) {
407
+ function Xe(e, t) {
405
408
  let n = e.document.nodes ?? [];
406
409
  try {
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 {
410
+ let r = B(e, /* @__PURE__ */ new Set()), i = t.ok && typeof t.document.source == "string" ? t.document.source.length : 0;
411
+ if (r.bytes <= Math.max(i, ze)) return {
409
412
  patchBytes: r.bytes,
410
413
  patchNodes: n.length,
411
414
  preferFull: !1
412
415
  };
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;
416
+ let a = B(t, /* @__PURE__ */ new Set()), o = 0;
417
+ for (let e of n) e.node === void 0 ? e.data !== void 0 && (o += 1) : o += B(e.node, /* @__PURE__ */ new Set()).nodes;
418
+ let s = r.bytes * O >= a.bytes, c = a.nodes > 0 && o * O >= a.nodes;
416
419
  return {
417
420
  patchBytes: r.bytes,
418
421
  fullBytes: a.bytes,
@@ -429,55 +432,55 @@ function Je(e, t) {
429
432
  };
430
433
  }
431
434
  }
432
- function Ye(e, t) {
433
- return Qe(e, t);
435
+ function Ze(e, t) {
436
+ return et(e, t);
434
437
  }
435
- function Xe(e, t) {
436
- let n = Qe(e, t);
438
+ function Qe(e, t) {
439
+ let n = et(e, t);
437
440
  return n ? {
438
441
  patch: n,
439
- cost: Je(n, t)
442
+ cost: Xe(n, t)
440
443
  } : null;
441
444
  }
442
- function Ze(e, t) {
445
+ function $e(e, t) {
443
446
  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 };
447
+ return n === void 0 ? r === void 0 ? {} : { recoveries: r } : r !== void 0 && N(n, r) ? {} : { recoveries: r === void 0 ? null : r };
445
448
  }
446
- function Qe(e, t) {
449
+ function et(e, t) {
447
450
  try {
448
451
  if (!e.ok || !t.ok) return null;
449
452
  let n = e.document, r = t.document;
450
- if (!N(n) || !N(r)) return null;
453
+ if (!A(n) || !A(r)) return null;
451
454
  let i = {};
452
455
  if (typeof n.source == "string" && typeof r.source == "string") {
453
- let e = R(n.source, r.source);
456
+ let e = F(n.source, r.source);
454
457
  e !== null && (i.source = e);
455
458
  } 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)]);
459
+ let a = [], o = {}, s = {}, c = new Set(k), l = /* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(r)]);
457
460
  for (let e of l) {
458
461
  if (e === "source" || e === "nodes" || c.has(e)) continue;
459
462
  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);
463
+ t ? i && N(n[e], r[e]) || (o[e] = r[e]) : i && a.push(e);
461
464
  }
462
- for (let e of M) {
465
+ for (let e of k) {
463
466
  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
467
  if (!t) {
465
468
  i && a.push(e);
466
469
  continue;
467
470
  }
468
- if (!N(l)) {
469
- i && I(c, l) || (o[e] = l);
471
+ if (!A(l)) {
472
+ i && N(c, l) || (o[e] = l);
470
473
  continue;
471
474
  }
472
475
  if (!i) {
473
476
  s[e] = { set: l };
474
477
  continue;
475
478
  }
476
- if (!N(c)) {
479
+ if (!A(c)) {
477
480
  o[e] = l;
478
481
  continue;
479
482
  }
480
- let u = Ge(c, l);
483
+ let u = qe(c, l);
481
484
  u !== null && (s[e] = u);
482
485
  }
483
486
  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;
@@ -487,55 +490,55 @@ function Qe(e, t) {
487
490
  break;
488
491
  }
489
492
  }
490
- let h = [], g = Ue(u);
491
- for (let e of d) We(e, g.get(e.id), g, h);
493
+ let h = [], g = Ge(u);
494
+ for (let e of d) Ke(e, g.get(e.id), g, h);
492
495
  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
496
  kind: "result-patch",
494
- protocol: A,
497
+ protocol: D,
495
498
  document: i,
496
- ...I(e.diagnostics, t.diagnostics) ? {} : { diagnostics: t.diagnostics },
497
- ...Ze(e, t)
499
+ ...N(e.diagnostics, t.diagnostics) ? {} : { diagnostics: t.diagnostics },
500
+ ...$e(e, t)
498
501
  };
499
502
  } catch {
500
503
  return null;
501
504
  }
502
505
  }
503
- function $e(e, t) {
504
- let n = z(e);
505
- return P(n.range) || F(), n.range = {
506
+ function tt(e, t) {
507
+ let n = I(e);
508
+ return j(n.range) || M(), n.range = {
506
509
  start: n.range.start + t,
507
510
  end: n.range.end + t
508
- }, e.children && (n.children = e.children.map((e) => $e(e, t))), n;
511
+ }, e.children && (n.children = e.children.map((e) => tt(e, t))), n;
509
512
  }
510
- function et(e) {
511
- return N(e) && typeof e.id == "string" && typeof e.type == "string" && P(e.range);
513
+ function nt(e) {
514
+ return A(e) && typeof e.id == "string" && typeof e.type == "string" && j(e.range);
512
515
  }
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();
516
+ function rt(e, t) {
517
+ A(t) || M(), t.set !== void 0 && !A(t.set) && M(), t.remove !== void 0 && !Array.isArray(t.remove) && M();
515
518
  let n = {};
516
- if (N(e)) for (let [t, r] of Object.entries(e)) Object.defineProperty(n, t, {
519
+ if (A(e)) for (let [t, r] of Object.entries(e)) Object.defineProperty(n, t, {
517
520
  value: r,
518
521
  enumerable: !0,
519
522
  configurable: !0,
520
523
  writable: !0
521
524
  });
522
- else e !== void 0 && F();
525
+ else e !== void 0 && M();
523
526
  if (t.set) for (let [e, r] of Object.entries(t.set)) Object.defineProperty(n, e, {
524
- value: L(r),
527
+ value: P(r),
525
528
  enumerable: !0,
526
529
  configurable: !0,
527
530
  writable: !0
528
531
  });
529
- if (t.remove) for (let e of t.remove) typeof e != "string" && F(), delete n[e];
532
+ if (t.remove) for (let e of t.remove) typeof e != "string" && M(), delete n[e];
530
533
  return n;
531
534
  }
532
- function nt(e, t) {
535
+ function it(e, t) {
533
536
  try {
534
- if (!e.ok || !N(t) || t.kind !== "result-patch" || t.protocol !== "patch-v1") return null;
537
+ if (!e.ok || !A(t) || t.kind !== "result-patch" || t.protocol !== "patch-v1") return null;
535
538
  let n = t.document;
536
- if (!N(n)) return null;
539
+ if (!A(n)) return null;
537
540
  let r = e.document;
538
- if (!N(r)) return null;
541
+ if (!A(r)) return null;
539
542
  let i = {};
540
543
  for (let [e, t] of Object.entries(r)) Object.defineProperty(i, e, {
541
544
  value: t,
@@ -551,11 +554,11 @@ function nt(e, t) {
551
554
  }
552
555
  }
553
556
  if (n.values !== void 0) {
554
- if (!N(n.values)) return null;
557
+ if (!A(n.values)) return null;
555
558
  for (let [e, t] of Object.entries(n.values)) {
556
559
  if (e === "nodes" || e === "source") return null;
557
560
  Object.defineProperty(i, e, {
558
- value: L(t),
561
+ value: P(t),
559
562
  enumerable: !0,
560
563
  configurable: !0,
561
564
  writable: !0
@@ -563,28 +566,28 @@ function nt(e, t) {
563
566
  }
564
567
  }
565
568
  if (n.records !== void 0) {
566
- if (!N(n.records)) return null;
569
+ if (!A(n.records)) return null;
567
570
  for (let e of Object.keys(n.records)) {
568
- if (!M.includes(e)) return null;
571
+ if (!k.includes(e)) return null;
569
572
  let t = n.records[e];
570
- t !== void 0 && (i[e] = tt(r[e], t));
573
+ t !== void 0 && (i[e] = rt(r[e], t));
571
574
  }
572
575
  }
573
576
  let a = typeof r.source == "string" ? r.source : null;
574
577
  if (a === null) return null;
575
578
  if (n.source !== void 0) {
576
- let e = Ie(n.source);
579
+ let e = Be(n.source);
577
580
  if (e === null) return null;
578
- let t = Le(a, e);
581
+ let t = Ve(a, e);
579
582
  if (t === null) return null;
580
583
  a = t;
581
584
  }
582
585
  i.source = a;
583
- let o = Array.isArray(r.nodes) ? r.nodes : [], s = Ue(o), c = /* @__PURE__ */ new Map();
586
+ let o = Array.isArray(r.nodes) ? r.nodes : [], s = Ge(o), c = /* @__PURE__ */ new Map();
584
587
  if (n.nodes !== void 0) {
585
588
  if (!Array.isArray(n.nodes)) return null;
586
589
  for (let e of n.nodes) {
587
- if (!N(e) || typeof e.id != "string" || c.has(e.id)) return null;
590
+ if (!A(e) || typeof e.id != "string" || c.has(e.id)) return null;
588
591
  c.set(e.id, e);
589
592
  }
590
593
  }
@@ -600,23 +603,23 @@ function nt(e, t) {
600
603
  let u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Set(), f = (e) => {
601
604
  let t = u.get(e);
602
605
  if (t !== void 0) return t;
603
- d.has(e) && F();
606
+ d.has(e) && M();
604
607
  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);
608
+ if (n === void 0) return r === void 0 && M(), u.set(e, r), r;
609
+ if (A(n) || M(), n.node !== void 0) {
610
+ (n.data !== void 0 || n.children !== void 0 || n.shift !== void 0 || n.subtree) && M(), nt(n.node) && n.node.id === e || M();
611
+ let t = P(n.node);
609
612
  return u.set(e, t), t;
610
613
  }
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);
614
+ r === void 0 && n.data === void 0 && M(), n.subtree !== void 0 && n.subtree !== !0 && M(), n.shift !== void 0 && !Number.isSafeInteger(n.shift) && M(), n.data !== void 0 && n.shift !== void 0 && M(), n.children !== void 0 && n.children !== null && (!Array.isArray(n.children) || n.children.some((e) => typeof e != "string")) && M(), d.add(e);
612
615
  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);
616
+ if (n.subtree === !0) (r === void 0 || n.shift === void 0 || n.data !== void 0 || n.children !== void 0) && M(), i = tt(r, n.shift);
614
617
  else {
615
618
  let t;
616
- n.data === void 0 ? (r === void 0 && F(), t = z(r), n.shift !== void 0 && (P(t.range) || F(), t.range = {
619
+ n.data === void 0 ? (r === void 0 && M(), t = I(r), n.shift !== void 0 && (j(t.range) || M(), t.range = {
617
620
  start: t.range.start + n.shift,
618
621
  end: t.range.end + n.shift
619
- })) : (N(n.data) || F(), t = L(n.data), delete t.children, t.id !== e && F());
622
+ })) : (A(n.data) || M(), t = P(n.data), delete t.children, t.id !== e && M());
620
623
  let a;
621
624
  if (n.children !== void 0) a = n.children === null ? null : [...n.children];
622
625
  else {
@@ -628,27 +631,30 @@ function nt(e, t) {
628
631
  return d.delete(e), u.set(e, i), i;
629
632
  }, p = l.map(f);
630
633
  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();
634
+ let m = t.diagnostics === void 0 ? e.diagnostics : Array.isArray(t.diagnostics) ? P(t.diagnostics) : M();
632
635
  if (t.recoveries !== void 0 && t.recoveries !== null && !Array.isArray(t.recoveries)) return null;
636
+ let h = e.status === void 0 ? {} : { status: e.status };
633
637
  if (t.recoveries === null) return {
634
638
  ok: !0,
635
639
  document: i,
636
- diagnostics: m
640
+ diagnostics: m,
641
+ ...h
637
642
  };
638
- let h = t.recoveries === void 0 ? e.recoveries : L([...t.recoveries]);
643
+ let g = t.recoveries === void 0 ? e.recoveries : P([...t.recoveries]);
639
644
  return {
640
645
  ok: !0,
641
646
  document: i,
642
647
  diagnostics: m,
643
- ...h === void 0 ? {} : { recoveries: h }
648
+ ...h,
649
+ ...g === void 0 ? {} : { recoveries: g }
644
650
  };
645
651
  } catch {
646
652
  return null;
647
653
  }
648
654
  }
649
655
  // src/local/transport/flat-compiled-data.ts
650
- var H = "flat-v1";
651
- function rt(e) {
656
+ var V = "flat-v1";
657
+ function at(e) {
652
658
  if (!e.ok) return !1;
653
659
  let t = e.document.nodes.map((e) => ({
654
660
  node: e,
@@ -664,7 +670,7 @@ function rt(e) {
664
670
  }
665
671
  return !1;
666
672
  }
667
- function it(e) {
673
+ function ot(e) {
668
674
  let t = [], n = /* @__PURE__ */ new Map(), r = [], i = (e) => {
669
675
  if (typeof e == "object" && e) {
670
676
  let i = n.get(e);
@@ -693,11 +699,11 @@ function it(e) {
693
699
  for (let t of Object.keys(e)) n.push([t, i(e[t])]);
694
700
  }
695
701
  return {
696
- version: H,
702
+ version: V,
697
703
  records: t
698
704
  };
699
705
  }
700
- function at(e) {
706
+ function st(e) {
701
707
  if (!e || typeof e != "object") return null;
702
708
  let t = e;
703
709
  if (t.version !== "flat-v1" || !Array.isArray(t.records) || t.records.length === 0 || t.records.length > 2e6) return null;
@@ -756,22 +762,22 @@ function at(e) {
756
762
  }
757
763
  return r[0];
758
764
  }
759
- // src/local/transport/worker.ts
760
- var ot = 150, st = 200, ct = [
765
+ // src/local/transport/worker-job.ts
766
+ var ct = 150, lt = 200, ut = [
761
767
  "maxSyntaxNodes",
762
768
  "maxParseWork",
763
769
  "maxMarkdownDepth"
764
770
  ];
765
- function U(e) {
771
+ function H(e) {
766
772
  return e instanceof Error ? e.message : String(e);
767
773
  }
768
- function W() {
774
+ function U() {
769
775
  return typeof performance < "u" ? performance.now() : Date.now();
770
776
  }
771
- function G(e) {
777
+ function W(e) {
772
778
  return Number.isFinite(e) ? Math.max(0, Math.round(e)) : 0;
773
779
  }
774
- function K(e, t, n) {
780
+ function G(e, t, n) {
775
781
  let r = {
776
782
  tokens: [],
777
783
  bindings: [],
@@ -779,7 +785,7 @@ function K(e, t, n) {
779
785
  };
780
786
  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
787
  try {
782
- return w(e, t, {
788
+ return C(e, t, {
783
789
  ...n.ok ? { document: n.document } : {},
784
790
  diagnostics: !1
785
791
  });
@@ -791,19 +797,7 @@ function K(e, t, n) {
791
797
  };
792
798
  }
793
799
  }
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;
802
- }
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;
805
- }
806
- function ut(e) {
800
+ function dt(e) {
807
801
  return Array.isArray(e) ? e.length > 32 ? Array(33) : e.map((e) => {
808
802
  if (!e || typeof e != "object" || Array.isArray(e)) return e;
809
803
  let t = e, n = { ...t }, r = t.props;
@@ -820,25 +814,25 @@ function ut(e) {
820
814
  return n.props = i, n;
821
815
  }) : e;
822
816
  }
823
- function q(e) {
817
+ function ft(e) {
824
818
  if (e !== void 0) try {
825
819
  if (typeof e != "object" || !e || Array.isArray(e)) return e;
826
820
  let t = e, n = {};
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")) {
821
+ for (let e of b) Object.hasOwn(t, e) && (n[e] = t[e]);
822
+ if (Object.hasOwn(t, "markdownBreaks") && (n.markdownBreaks = t.markdownBreaks), Object.hasOwn(t, "sourcePhase") && (n.sourcePhase = t.sourcePhase), Object.hasOwn(t, "strict") && (n.strict = t.strict), Object.hasOwn(t, "limits")) {
829
823
  let e = t.limits;
830
824
  if (e && typeof e == "object" && !Array.isArray(e)) {
831
825
  let t = {};
832
- for (let n of ct) Object.hasOwn(e, n) && (t[n] = e[n]);
826
+ for (let n of ut) Object.hasOwn(e, n) && (t[n] = e[n]);
833
827
  n.limits = t;
834
828
  } else n.limits = e;
835
829
  }
836
- return Object.hasOwn(t, "hostComponents") && (n.hostComponents = ut(t.hostComponents)), Object.hasOwn(t, "config") && (n.config = b(t.config)), n;
830
+ return Object.hasOwn(t, "hostComponents") && (n.hostComponents = dt(t.hostComponents)), Object.hasOwn(t, "config") && (n.config = x(t.config)), n;
837
831
  } catch {
838
832
  return e;
839
833
  }
840
834
  }
841
- function dt(e) {
835
+ function pt(e) {
842
836
  try {
843
837
  if (!e || typeof e != "object" || Array.isArray(e)) return "";
844
838
  let t = e.limits;
@@ -854,7 +848,7 @@ function dt(e) {
854
848
  return ":unreadable";
855
849
  }
856
850
  }
857
- function ft(e) {
851
+ function mt(e) {
858
852
  let t = S(e);
859
853
  if (t !== "invalid") return t;
860
854
  try {
@@ -863,33 +857,354 @@ function ft(e) {
863
857
  return "invalid";
864
858
  }
865
859
  }
866
- function J(e) {
867
- return `${ft(e)}${dt(e)}`;
860
+ function K(e) {
861
+ return `${mt(e)}${pt(e)}`;
862
+ }
863
+ // src/local/transport/worker-handler.ts
864
+ function ht(e, t, n, r) {
865
+ let i = e;
866
+ return typeof i.compileShared == "function" ? i.compileShared(t, n, r) : e.compile(t, n, r);
867
+ }
868
+ function gt(e) {
869
+ return e === "streaming" || e === "final";
870
+ }
871
+ function q(e) {
872
+ return e.stats;
873
+ }
874
+ function J(e, t, n) {
875
+ try {
876
+ e.postMessage({
877
+ id: t,
878
+ ok: !1,
879
+ message: n
880
+ });
881
+ } catch {}
882
+ }
883
+ function _t(e, t, n, r, i) {
884
+ try {
885
+ e.postMessage({
886
+ id: t,
887
+ ok: !1,
888
+ message: n,
889
+ retryFull: !0,
890
+ code: r,
891
+ ...i === void 0 ? {} : { revision: i }
892
+ });
893
+ } catch {}
894
+ }
895
+ function vt(e) {
896
+ return !!e && typeof e == "object" && (e.control === "dispose" || e.control === "cancel-preparation");
897
+ }
898
+ function yt(e) {
899
+ if (!e || typeof e != "object") return !1;
900
+ let t = e;
901
+ 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";
902
+ }
903
+ function bt(e, t = {}) {
904
+ let n = e === void 0 ? globalThis : e;
905
+ if (!n || typeof n.postMessage != "function") throw TypeError("startLocalCompileWorker requires a worker scope with postMessage");
906
+ 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 = () => {
907
+ p += 1, f !== null && (f.aborted = !0, f = null), d !== null && (clearTimeout(d), d = null);
908
+ }, g = () => new Promise((e) => {
909
+ typeof setTimeout == "function" ? setTimeout(e, 0) : e();
910
+ }), _ = async (e) => {
911
+ if (u || e !== p) return;
912
+ let t = i.prepareAsync;
913
+ if (typeof t != "function") return;
914
+ let n = { aborted: !1 };
915
+ f = n;
916
+ let r = U(), a = !1;
917
+ try {
918
+ a = await t.call(i, n, g);
919
+ } catch {} finally {
920
+ f === n && (f = null), a && !n.aborted && !u && e === p && (m = W(U() - r));
921
+ }
922
+ }, v = () => {
923
+ if (u || !s) return;
924
+ h();
925
+ let e = p;
926
+ d = setTimeout(() => {
927
+ d = null, _(e);
928
+ }, o);
929
+ }, y = () => {
930
+ if (!u) {
931
+ u = !0, h();
932
+ try {
933
+ r.dispose();
934
+ } catch {}
935
+ n.onmessage = null;
936
+ }
937
+ }, b = (e) => ({
938
+ compileMs: e,
939
+ ...m === void 0 ? {} : { preparationMs: m }
940
+ }), x = (e) => {
941
+ let t = typeof e == "number" && Number.isSafeInteger(e) && e > 0 ? e : null;
942
+ return t === null ? l + 1 : t > l ? t : l + 1;
943
+ }, S = (e, t, i, a, o = !1, s) => {
944
+ let l = c;
945
+ if (l === null) return !1;
946
+ let u = W(i), d = s === void 0 ? b(u) : {
947
+ ...b(u),
948
+ ...s
949
+ };
950
+ try {
951
+ let i = a ? {
952
+ id: e,
953
+ ok: !0,
954
+ result: l.result,
955
+ duration: u,
956
+ incremental: q(r),
957
+ ...l.sourcePhase === void 0 ? {} : { sourcePhase: l.sourcePhase },
958
+ protocol: D,
959
+ revision: t,
960
+ metrics: d
961
+ } : {
962
+ id: e,
963
+ ok: !0,
964
+ result: l.result,
965
+ duration: u,
966
+ incremental: q(r),
967
+ ...l.sourcePhase === void 0 ? {} : { sourcePhase: l.sourcePhase }
968
+ };
969
+ if (o && i.ok) {
970
+ let e = U();
971
+ i.analysis = G(l.source, l.options, l.result), i.metrics = {
972
+ ...i.metrics,
973
+ analysisMs: W(U() - e)
974
+ };
975
+ }
976
+ if (l.deep && l.flatResults && i.ok) {
977
+ let { result: e, ...t } = i, r = {
978
+ ...t,
979
+ flatResult: ot(e)
980
+ };
981
+ n.postMessage(r);
982
+ } else n.postMessage(i);
983
+ return !0;
984
+ } catch (t) {
985
+ return J(n, e, `Could not return the compile result: ${H(t)}`), !1;
986
+ }
987
+ };
988
+ return n.onmessage = (e) => {
989
+ let t = e?.data;
990
+ if (vt(t)) {
991
+ t.control === "dispose" ? y() : h();
992
+ return;
993
+ }
994
+ if (!t || typeof t.id != "number") return;
995
+ if (typeof t.source == "string") {
996
+ let e = t, i = ft(e.options), a = e.sourcePhase === void 0 ? i?.sourcePhase : e.sourcePhase;
997
+ if (a !== void 0 && !gt(a)) {
998
+ J(n, e.id, "The requested source phase is not supported: expected \"streaming\" or \"final\"");
999
+ return;
1000
+ }
1001
+ let o = a;
1002
+ h();
1003
+ let s = K(i), u = e.protocol === D, d = x(e.revision), f = U();
1004
+ try {
1005
+ if (c !== null && c.optionsKey !== s) try {
1006
+ r.clear();
1007
+ } catch {}
1008
+ let t = ht(r, e.source, i, o), n = W(U() - f);
1009
+ l = d, c = {
1010
+ source: e.source,
1011
+ revision: d,
1012
+ options: i,
1013
+ optionsKey: s,
1014
+ result: t,
1015
+ deep: at(t),
1016
+ flatResults: e.flatResults === V,
1017
+ ...o === void 0 ? {} : { sourcePhase: o }
1018
+ }, S(e.id, d, n, u, e.includeAuthorAnalysis === !0) && v();
1019
+ } catch (t) {
1020
+ J(n, e.id, H(t));
1021
+ }
1022
+ return;
1023
+ }
1024
+ if (t.protocol !== "patch-v1") return;
1025
+ h();
1026
+ let i = t, a = c, o = (e, t) => {
1027
+ _t(n, i.id, e, t, a?.revision);
1028
+ };
1029
+ if (a === null) {
1030
+ o("No complete compile is available to patch", "stale-base");
1031
+ return;
1032
+ }
1033
+ if ((a.sourcePhase ?? "final") !== "final") {
1034
+ o("The baseline was compiled from a streaming snapshot", "phase-mismatch");
1035
+ return;
1036
+ }
1037
+ if (typeof i.baseRevision != "number" || i.baseRevision !== a.revision) {
1038
+ o("The requested base revision is not current", "stale-base");
1039
+ return;
1040
+ }
1041
+ if (i.optionsKey !== void 0 && i.optionsKey !== a.optionsKey) {
1042
+ o("The options signature changed since the baseline", "options-mismatch");
1043
+ return;
1044
+ }
1045
+ if (!yt(i.edit)) {
1046
+ o("The source edit is invalid", "invalid-edit");
1047
+ return;
1048
+ }
1049
+ let s = i.edit;
1050
+ if (s.to > a.source.length) {
1051
+ o("The source edit does not fit the baseline", "invalid-edit");
1052
+ return;
1053
+ }
1054
+ let u = a.source.slice(0, s.from) + s.insert + a.source.slice(s.to);
1055
+ if (typeof i.targetLength == "number" && u.length !== i.targetLength) {
1056
+ o("The source edit produced an unexpected length", "invalid-edit");
1057
+ return;
1058
+ }
1059
+ let d = x(i.revision), f = U();
1060
+ try {
1061
+ let e = ht(r, u, a.options, a.sourcePhase), t = W(U() - f), o = a.revision, s = a.result;
1062
+ l = d, c = {
1063
+ source: u,
1064
+ revision: d,
1065
+ options: a.options,
1066
+ optionsKey: a.optionsKey,
1067
+ result: e,
1068
+ deep: at(e),
1069
+ flatResults: a.flatResults,
1070
+ ...a.sourcePhase === void 0 ? {} : { sourcePhase: a.sourcePhase }
1071
+ };
1072
+ let p = null, h = 0;
1073
+ if (e.ok && s.ok && !c.deep && !a.deep) {
1074
+ let t = U();
1075
+ p = Qe(s, e), h = W(U() - t);
1076
+ }
1077
+ let g = p?.patch ?? null;
1078
+ if (g === null) {
1079
+ S(i.id, d, t, !0, i.includeAuthorAnalysis === !0) && v();
1080
+ return;
1081
+ }
1082
+ if (p !== null && p.cost.preferFull) {
1083
+ let e = p.cost, n = {
1084
+ patchEncodeMs: h,
1085
+ patchFallback: "cost",
1086
+ patchBytes: e.patchBytes,
1087
+ ...e.fullBytes === void 0 ? {} : { fullBytes: e.fullBytes }
1088
+ };
1089
+ S(i.id, d, t, !0, i.includeAuthorAnalysis === !0, n) && v();
1090
+ return;
1091
+ }
1092
+ let _ = {
1093
+ compileMs: t,
1094
+ patchEncodeMs: h,
1095
+ patchNodes: g.document.nodes?.length ?? 0,
1096
+ ...m === void 0 ? {} : { preparationMs: m }
1097
+ };
1098
+ try {
1099
+ let s = {
1100
+ id: i.id,
1101
+ ok: !0,
1102
+ protocol: D,
1103
+ baseRevision: o,
1104
+ revision: d,
1105
+ patch: g,
1106
+ duration: t,
1107
+ incremental: q(r),
1108
+ ...a.sourcePhase === void 0 ? {} : { sourcePhase: a.sourcePhase },
1109
+ metrics: _
1110
+ };
1111
+ if (i.includeAuthorAnalysis === !0) {
1112
+ let t = U();
1113
+ s.analysis = G(u, a.options, e), _.analysisMs = W(U() - t);
1114
+ }
1115
+ n.postMessage(s), v();
1116
+ } catch (e) {
1117
+ J(n, i.id, `Could not return the compile result: ${H(e)}`);
1118
+ }
1119
+ } catch (e) {
1120
+ J(n, i.id, H(e));
1121
+ }
1122
+ }, {
1123
+ dispose: y,
1124
+ cancelPreparation: h,
1125
+ get disposed() {
1126
+ return u;
1127
+ }
1128
+ };
1129
+ }
1130
+ // src/local/transport/worker.ts
1131
+ function xt(e, t) {
1132
+ if (!e || typeof e != "object") return !1;
1133
+ let n = e, r = (e) => e && Number.isSafeInteger(e.start) && Number.isSafeInteger(e.end) && e.start >= 0 && e.end >= e.start && e.end <= t;
1134
+ 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;
1135
+ let i = 0, a = 0;
1136
+ for (let e of n.tokens) {
1137
+ if (!e || typeof e.kind != "string" || !r(e.range) || e.range.start < i) return !1;
1138
+ i = e.range.end;
1139
+ }
1140
+ 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;
1141
+ return !0;
868
1142
  }
869
- function pt(e, t) {
870
- let n = q(t);
1143
+ function St(e, t, n) {
1144
+ let r = ft(t), i = n === void 0 ? Ct(t) : n, a = i === "streaming" || i === "final" ? i : void 0, o = i !== void 0 && a === void 0 ? i : void 0;
871
1145
  return {
872
1146
  source: e,
873
- options: n,
874
- optionsKey: J(n),
875
- scheduledAt: W()
1147
+ options: r,
1148
+ optionsKey: K(r),
1149
+ scheduledAt: U(),
1150
+ sourcePhase: a === "streaming" ? "streaming" : "final",
1151
+ explicitPhase: i !== void 0,
1152
+ ...o === void 0 ? {} : { invalidPhase: o }
876
1153
  };
877
1154
  }
1155
+ function Ct(e) {
1156
+ try {
1157
+ return !e || typeof e != "object" || Array.isArray(e) ? void 0 : e.sourcePhase;
1158
+ } catch {
1159
+ return;
1160
+ }
1161
+ }
878
1162
  function Y(e, t) {
879
- return e.source === t.source && e.optionsKey === t.optionsKey;
1163
+ return e.source === t.source && e.optionsKey === t.optionsKey && e.sourcePhase === t.sourcePhase && e.explicitPhase === t.explicitPhase && e.invalidPhase === t.invalidPhase;
880
1164
  }
881
- function mt(e) {
1165
+ function X(e) {
1166
+ return e.sourcePhase === "streaming" || e.explicitPhase ? { sourcePhase: e.sourcePhase } : {};
1167
+ }
1168
+ function Z(e, t) {
1169
+ return e.explicitPhase ? {
1170
+ ok: !1,
1171
+ diagnostics: [t],
1172
+ status: "failed"
1173
+ } : {
1174
+ ok: !1,
1175
+ diagnostics: [t]
1176
+ };
1177
+ }
1178
+ function wt() {
1179
+ return {
1180
+ ok: !1,
1181
+ status: "failed",
1182
+ diagnostics: [{
1183
+ code: "local.options.invalid",
1184
+ message: "Compile option sourcePhase must be \"streaming\" or \"final\".",
1185
+ severity: "error",
1186
+ range: {
1187
+ start: 0,
1188
+ end: 0
1189
+ },
1190
+ line: 1,
1191
+ column: 1,
1192
+ messageKey: "local.options.invalid.source-phase"
1193
+ }]
1194
+ };
1195
+ }
1196
+ function Q(e) {
882
1197
  if (!e || typeof e != "object") return !1;
883
1198
  let t = e;
884
1199
  return !(typeof t.ok != "boolean" || !Array.isArray(t.diagnostics) || t.ok && (!t.document || typeof t.document != "object"));
885
1200
  }
886
- function ht(e) {
1201
+ function Tt(e) {
887
1202
  return e.ok && "patch" in e && e.patch !== void 0;
888
1203
  }
889
- function X(e) {
1204
+ function $(e) {
890
1205
  return {
891
1206
  code: "local.worker.compile",
892
- message: `Compilation failed: ${U(e)}`,
1207
+ message: `Compilation failed: ${H(e)}`,
893
1208
  severity: "error",
894
1209
  range: {
895
1210
  start: 0,
@@ -899,7 +1214,7 @@ function X(e) {
899
1214
  column: 1
900
1215
  };
901
1216
  }
902
- var gt = class {
1217
+ var Et = class {
903
1218
  options;
904
1219
  delay;
905
1220
  worker = null;
@@ -924,16 +1239,18 @@ var gt = class {
924
1239
  this.handleWorkerFailure(t || "The compile worker encountered an error");
925
1240
  }, t.onmessageerror = () => this.handleWorkerFailure("The compile worker could not deliver the compile result"), this.worker = t;
926
1241
  } catch (t) {
927
- this.worker = null, e.onModeChange?.("fallback", `Could not start the compile worker: ${U(t)}`);
1242
+ this.worker = null, e.onModeChange?.("fallback", `Could not start the compile worker: ${H(t)}`);
928
1243
  }
929
1244
  }
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 = {
1245
+ schedule(e, t, n, r) {
1246
+ if (this.disposed) return;
1247
+ let i = St(e, t, r);
1248
+ this.queued = i, n && typeof n.baseSource == "string" && yt(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
1249
  baseSource: n.baseSource,
933
1250
  edit: { ...n.edit }
934
- }), this.clearTimer(), this.timer = setTimeout(() => {
1251
+ }), this.clearTimer(), i.sourcePhase === "streaming" && (this.baseline = null), this.setPending(!0), i.sourcePhase === "streaming" || !i.explicitPhase ? this.timer = setTimeout(() => {
935
1252
  this.timer = null, this.drain();
936
- }, this.delay), this.setPending(!0));
1253
+ }, this.delay) : this.drain();
937
1254
  }
938
1255
  dispose() {
939
1256
  if (this.disposed) return;
@@ -953,17 +1270,29 @@ var gt = class {
953
1270
  e === null ? this.setPending(!1) : (this.queued = null, this.compile(e));
954
1271
  }
955
1272
  compile(e) {
1273
+ if (e.invalidPhase !== void 0) {
1274
+ this.deliver({
1275
+ source: e.source,
1276
+ result: wt(),
1277
+ duration: 0,
1278
+ mode: this.worker === null ? "fallback" : "worker",
1279
+ ...e.options === void 0 ? {} : { options: e.options },
1280
+ metrics: { queueMs: W(U() - e.scheduledAt) }
1281
+ }), this.finishRun();
1282
+ return;
1283
+ }
956
1284
  let t = this.worker;
957
1285
  if (!t) {
958
1286
  this.compileFallback(e);
959
1287
  return;
960
1288
  }
961
- let n = this.nextId++, r = this.nextRevision++, i = W(), a = this.baseline, o = this.patchState === "enabled" && a !== null && a.optionsKey === e.optionsKey ? {
1289
+ e.sourcePhase === "streaming" && (this.baseline = null);
1290
+ let n = this.nextId++, r = this.nextRevision++, i = U(), a = this.baseline, o = e.sourcePhase === "final" && this.patchState === "enabled" && a !== null && a.optionsKey === e.optionsKey ? {
962
1291
  id: n,
963
- protocol: A,
1292
+ protocol: D,
964
1293
  baseRevision: a.revision,
965
1294
  revision: r,
966
- edit: e.editHint?.baseSource === a.source ? e.editHint.edit : R(a.source, e.source) ?? {
1295
+ edit: e.editHint?.baseSource === a.source ? e.editHint.edit : F(a.source, e.source) ?? {
967
1296
  from: 0,
968
1297
  to: 0,
969
1298
  insert: ""
@@ -974,9 +1303,10 @@ var gt = class {
974
1303
  id: n,
975
1304
  source: e.source,
976
1305
  ...e.options === void 0 ? {} : { options: e.options },
977
- protocol: A,
1306
+ protocol: D,
978
1307
  revision: r,
979
- flatResults: H
1308
+ flatResults: V,
1309
+ ...e.sourcePhase === "streaming" || e.explicitPhase ? { sourcePhase: e.sourcePhase } : {}
980
1310
  };
981
1311
  this.inFlight = {
982
1312
  id: n,
@@ -988,7 +1318,7 @@ var gt = class {
988
1318
  t.postMessage(o);
989
1319
  } catch (t) {
990
1320
  this.inFlight = null;
991
- let n = `Could not send the source to the compile worker: ${U(t)}`, r = this.queued;
1321
+ let n = `Could not send the source to the compile worker: ${H(t)}`, r = this.queued;
992
1322
  if (r !== null && !Y(r, e)) {
993
1323
  this.resetProtocol(), this.degrade(n), this.finishRun();
994
1324
  return;
@@ -998,24 +1328,23 @@ var gt = class {
998
1328
  }
999
1329
  compileFallback(e) {
1000
1330
  if (this.disposed) return;
1001
- let t = W(), n;
1331
+ e.sourcePhase === "streaming" && (this.baseline = null);
1332
+ let t = U(), n;
1002
1333
  try {
1003
- let t = this.options.fallbackCompile ?? ((e, t) => (this.fallbackSession ??= T(), this.fallbackSession.compile(e, t)));
1004
- n = e.options === void 0 ? t(e.source) : t(e.source, e.options);
1005
- } catch (e) {
1006
- n = {
1007
- ok: !1,
1008
- diagnostics: [X(e)]
1009
- };
1334
+ let t = this.options.fallbackCompile ?? ((e, t, n) => (this.fallbackSession ??= T(), this.fallbackSession.compile(e, t, n)));
1335
+ n = e.explicitPhase ? t(e.source, e.options, e.sourcePhase) : e.options === void 0 ? t(e.source) : t(e.source, e.options);
1336
+ } catch (t) {
1337
+ n = Z(e, $(t));
1010
1338
  }
1011
1339
  this.deliver({
1012
1340
  source: e.source,
1013
1341
  result: n,
1014
- duration: G(W() - t),
1342
+ duration: W(U() - t),
1015
1343
  mode: "fallback",
1016
- ...this.options.includeAuthorAnalysis ? { analysis: K(e.source, e.options, n) } : {},
1344
+ ...this.options.includeAuthorAnalysis ? { analysis: G(e.source, e.options, n) } : {},
1017
1345
  ...e.options === void 0 ? {} : { options: e.options },
1018
- metrics: { queueMs: G(t - e.scheduledAt) }
1346
+ ...X(e),
1347
+ metrics: { queueMs: W(t - e.scheduledAt) }
1019
1348
  }), this.finishRun();
1020
1349
  }
1021
1350
  receive(e) {
@@ -1024,8 +1353,8 @@ var gt = class {
1024
1353
  if (!t || !e || e.id !== t.id) return;
1025
1354
  let n, r = 0;
1026
1355
  if (e.ok && "flatResult" in e) {
1027
- let t = W(), i = at(e.flatResult);
1028
- r = G(W() - t), n = mt(i) ? {
1356
+ let t = U(), i = st(e.flatResult);
1357
+ r = W(U() - t), n = Q(i) ? {
1029
1358
  ...e,
1030
1359
  result: i
1031
1360
  } : {
@@ -1036,14 +1365,14 @@ var gt = class {
1036
1365
  };
1037
1366
  } else n = e;
1038
1367
  this.inFlight = null;
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;
1368
+ let i = t.job, a = W(U() - t.startedAt), o = W(t.startedAt - i.scheduledAt), s = null, c = r, l = null, u = "worker", d;
1040
1369
  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);
1370
+ if (Tt(n)) {
1371
+ let e = U(), t = this.applyResponsePatch(i, n);
1372
+ c = W(U() - e), t !== null && (s = t, d = n.revision);
1044
1373
  } else {
1045
1374
  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 ? {
1375
+ Q(e.result) ? (s = e.result, d = typeof e.revision == "number" ? e.revision : void 0, i.sourcePhase === "streaming" || e.sourcePhase === "streaming" ? this.baseline = null : e.protocol === "patch-v1" && typeof e.revision == "number" && Number.isSafeInteger(e.revision) ? (this.patchState = "enabled", this.baseline = e.result.ok ? {
1047
1376
  source: i.source,
1048
1377
  optionsKey: i.optionsKey,
1049
1378
  revision: e.revision,
@@ -1054,13 +1383,11 @@ var gt = class {
1054
1383
  let f = this.queued, p = f !== null && !Y(f, i);
1055
1384
  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
1385
  source: i.source,
1057
- result: {
1058
- ok: !1,
1059
- diagnostics: [X("The compile worker could not apply an incremental result patch")]
1060
- },
1386
+ result: Z(i, $("The compile worker could not apply an incremental result patch")),
1061
1387
  duration: 0,
1062
1388
  mode: u,
1063
1389
  ...i.options === void 0 ? {} : { options: i.options },
1390
+ ...X(i),
1064
1391
  metrics: {
1065
1392
  queueMs: o,
1066
1393
  roundTripMs: a,
@@ -1068,13 +1395,11 @@ var gt = class {
1068
1395
  }
1069
1396
  })), this.finishRun()) : (p || this.deliver({
1070
1397
  source: i.source,
1071
- result: {
1072
- ok: !1,
1073
- diagnostics: [X(l)]
1074
- },
1398
+ result: Z(i, $(l)),
1075
1399
  duration: 0,
1076
1400
  mode: u,
1077
1401
  ...i.options === void 0 ? {} : { options: i.options },
1402
+ ...X(i),
1078
1403
  metrics: {
1079
1404
  queueMs: o,
1080
1405
  roundTripMs: a
@@ -1082,10 +1407,11 @@ var gt = class {
1082
1407
  }), this.finishRun()) : (p || this.deliver({
1083
1408
  source: i.source,
1084
1409
  result: s,
1085
- duration: G(n.ok ? n.duration : 0),
1410
+ duration: W(n.ok ? n.duration : 0),
1086
1411
  mode: u,
1087
- ...n.ok && this.options.includeAuthorAnalysis && lt(n.analysis, i.source.length) ? { analysis: n.analysis } : {},
1412
+ ...n.ok && this.options.includeAuthorAnalysis && xt(n.analysis, i.source.length) ? { analysis: n.analysis } : {},
1088
1413
  ...i.options === void 0 ? {} : { options: i.options },
1414
+ ...X(i),
1089
1415
  metrics: {
1090
1416
  queueMs: o,
1091
1417
  roundTripMs: a,
@@ -1096,15 +1422,29 @@ var gt = class {
1096
1422
  }), this.finishRun());
1097
1423
  }
1098
1424
  applyResponsePatch(e, t) {
1425
+ if (e.sourcePhase !== "final") return null;
1099
1426
  let n = this.baseline;
1100
1427
  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 = {
1428
+ let r = it(n.result, t.patch);
1429
+ if (r === null || !r.ok || r.document.source !== e.source) return null;
1430
+ let i;
1431
+ if (e.sourcePhase === "final" && e.explicitPhase) i = r.recoveries === void 0 ? {
1432
+ ...r,
1433
+ status: "valid"
1434
+ } : {
1435
+ ...r,
1436
+ status: "recovered"
1437
+ };
1438
+ else if (r.ok && r.status !== void 0) {
1439
+ let e = { ...r };
1440
+ delete e.status, i = e;
1441
+ } else i = r;
1442
+ return this.baseline = {
1103
1443
  source: e.source,
1104
1444
  optionsKey: e.optionsKey,
1105
1445
  revision: t.revision,
1106
- result: r
1107
- }, r);
1446
+ result: i
1447
+ }, i;
1108
1448
  }
1109
1449
  recoverWithFullResult(e) {
1110
1450
  if (this.worker === null || (e.recovery ?? 0) >= 1) return !1;
@@ -1138,7 +1478,7 @@ var gt = class {
1138
1478
  }
1139
1479
  deliver(e) {
1140
1480
  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);
1481
+ let t = this.baseline !== null && this.baseline.result === e.result, n = this.options.shareResults === !0 || !t ? e.result : P(e.result);
1142
1482
  this.options.onResult({
1143
1483
  ...e,
1144
1484
  result: n
@@ -1151,252 +1491,4 @@ var gt = class {
1151
1491
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
1152
1492
  }
1153
1493
  };
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) {
1162
- try {
1163
- e.postMessage({
1164
- id: t,
1165
- ok: !1,
1166
- message: n
1167
- });
1168
- } catch {}
1169
- }
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;
1204
- try {
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();
1219
- try {
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
- };
1260
- }
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;
1271
- }
1272
- };
1273
- return n.onmessage = (e) => {
1274
- let t = e?.data;
1275
- if (yt(t)) {
1276
- t.control === "dispose" ? y() : h();
1277
- return;
1278
- }
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;
1301
- }
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;
1310
- }
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;
1399
- }
1400
- };
1401
- }
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 };
1494
+ export { h as DEFAULT_LOCAL_THEME, ct as LOCAL_COMPILE_DELAY_MS, lt as LOCAL_COMPILE_PREPARATION_DELAY_MS, i as LOCAL_DIAGNOSTIC_CODES, D as LOCAL_RESULT_PATCH_PROTOCOL, _e as LOCAL_STATE_FORMAT, y as LOCAL_SYNTAX_VERSION, f as LOCAL_THEME_PROTOCOL, Et as LocalCompileScheduler, ie as LocalCompileSession, g as LocalExpressionError, Te as SHAREABLE_HTML_FORMAT, Se as SHAREABLE_HTML_FORMAT_V2, C as analyzeLocalSource, it as applyLocalResultPatch, Ce as applyLocalState, oe as applyLocalStateRetention, Ve as applySourceEdit, Le as checkLocalUpgrade, _ as compileExpression, $ as compileFailureDiagnostic, n as compileLatex, ee as compileLocal, t as compilePlotFormula, ne as completeLocalSource, a as countLocalCodePoints, T as createLocalCompileSession, ce as createLocalRuntime, xe as createLocalStateFile, we as createShareableHtml, F as diffSourceEdit, Ze as encodeLocalResultPatch, ye as exportLocalState, l as formatLocalDiagnostic, re as formatLocalSource, e as implicitGridSize, ve as importLocalState, Pe as inspectLocalSourceVersion, u as isLocalDiagnosticCode, o as isLocalThemeName, S as localCompileOptionsKey, s as localDiagnosticTemplate, c as localDiagnosticTemplateKeys, ae as localSourceDigest, K as localWorkerOptionsKey, Re as migrateLocalSource, ue as notifyLocalRuntime, he as parseLocalState, le as planLocalStateRetention, r as plotFormulaKind, te as renameLocalBinding, Oe as resolveLocalComponentStateExport, Ee as resolveLocalState, be as resolveLocalStateBaseline, m as resolveLocalTheme, me as sampleImplicit, fe as sampleParametric, pe as samplePlot, de as samplePolar, ge as serializeForScript, De as serializeLocalState, bt as startLocalCompileWorker, se as updateLocalRuntime };