reactive-md 0.9.0 → 0.9.2

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 (338) hide show
  1. package/CHANGELOG-ch.md +333 -306
  2. package/CHANGELOG.md +334 -307
  3. package/CONTRIBUTING-ch.md +22 -22
  4. package/CONTRIBUTING.md +22 -22
  5. package/README-ch.md +431 -431
  6. package/README-en.md +431 -431
  7. package/README.md +429 -429
  8. package/SECURITY-ch.md +83 -83
  9. package/SECURITY.md +83 -83
  10. package/THIRD_PARTY_NOTICES.md +111 -1
  11. package/bin/reactive-md.mjs +39 -39
  12. package/cli/args.mjs +263 -263
  13. package/cli/assets.mjs +395 -395
  14. package/cli/build.mjs +445 -444
  15. package/cli/check.mjs +444 -444
  16. package/cli/document.mjs +130 -130
  17. package/cli/errors.mjs +61 -61
  18. package/cli/fs-utils.mjs +133 -133
  19. package/cli/glob.mjs +203 -203
  20. package/cli/help.mjs +323 -323
  21. package/cli/init.mjs +1577 -1577
  22. package/cli/lint.mjs +177 -177
  23. package/cli/main.mjs +65 -65
  24. package/cli/migrate.mjs +368 -368
  25. package/cli/package-loader.mjs +41 -41
  26. package/cli/package.mjs +211 -211
  27. package/dist-library/{LocalDocumentView-K7Y-2bRJ.js → LocalDocumentView-BuqgJZEY.js} +11 -11
  28. package/dist-library/LocalDocumentViewCore-DXE0I0Qc.js +9830 -0
  29. package/dist-library/LocalReactiveDocumentCore-CWBe4Mm5.js +275 -0
  30. package/dist-library/{authoring-Co_TiE-P.js → authoring-Ci_KzJ0q.js} +87 -67
  31. package/dist-library/{compile-LhpTKqCR.js → compile-Dx6Uw3D9.js} +11 -11
  32. package/dist-library/{compiler-core-DTxY-qYz.js → compiler-core-DDDdvuLy.js} +2618 -1846
  33. package/dist-library/compiler-dxLPB9Ym.js +86 -0
  34. package/dist-library/{component-state-BBJ08vML.js → component-state-BRwvTV0d.js} +15 -14
  35. package/dist-library/component-state-CwKX_SN5.js +763 -0
  36. package/dist-library/{config-BUo-8O5C.js → config-DXLvctiZ.js} +68 -66
  37. package/dist-library/config-validation-D3D7Dy2J.js +586 -0
  38. package/dist-library/{controls-BWiLLtBO.js → controls-DoZyLCrV.js} +2434 -2410
  39. package/dist-library/{coordinate-BSl6enWV.js → coordinate-B1VFK9fd.js} +108 -107
  40. package/dist-library/{data-table-DfvytZKQ.js → data-table-8-3F15Jf.js} +69 -66
  41. package/dist-library/{default-components-BwQf0oP-.js → default-components-s21NevON.js} +29 -28
  42. package/dist-library/{display-lw3BT1TA.js → display-B_uutKkN.js} +1 -1
  43. package/dist-library/{config-validation-C5kJYk-J.js → document-theme-C8J6UyNO.js} +241 -731
  44. package/dist-library/export-CIAIPBov.js +370 -0
  45. package/dist-library/{gallery-B8kSt1oI.js → gallery-Dv1rOvL0.js} +151 -147
  46. package/dist-library/html-Cr4CBwAH.js +758 -0
  47. package/dist-library/identity-BUx0Q_-d.js +40 -0
  48. package/dist-library/{incremental-D_6vwAAE.js → incremental-9nx92u9c.js} +407 -143
  49. package/dist-library/layout-BBB2VF0S.js +562 -0
  50. package/dist-library/{mount-preset-C5s9ebEH.js → mount-preset-DMZ5wd3t.js} +3 -3
  51. package/dist-library/observability-4KqXhIEU.js +421 -0
  52. package/dist-library/observability-core-Bcu7vpnl.js +24 -0
  53. package/dist-library/options-BBp9IcHm.js +121 -0
  54. package/dist-library/{package-core-D0POW4Gd.js → package-core-K5xesGqy.js} +30 -29
  55. package/dist-library/{parser-standard-OToYcOBL.js → parser-standard-CBA1-hdG.js} +3332 -3840
  56. package/dist-library/{plugin-packs-B1XPWcFs.js → plugin-packs-Bh1HhLym.js} +3 -2
  57. package/dist-library/preset-core-DeZPA8IE.js +1298 -0
  58. package/dist-library/react-0DCh-Mar.js +7 -0
  59. package/dist-library/reactive-md-authoring.js +28 -30
  60. package/dist-library/reactive-md-build.js +99 -61
  61. package/dist-library/reactive-md-compiler-standard.js +10 -9
  62. package/dist-library/reactive-md-compiler.js +3 -3
  63. package/dist-library/reactive-md-default-packs.js +3 -2
  64. package/dist-library/reactive-md-default-preset.js +3 -2
  65. package/dist-library/reactive-md-export.js +4 -4
  66. package/dist-library/reactive-md-minimal-preset.js +2 -2
  67. package/dist-library/reactive-md-minimal-react-preset.js +3 -3
  68. package/dist-library/reactive-md-observability.js +4 -0
  69. package/dist-library/reactive-md-pdf.js +127 -3
  70. package/dist-library/reactive-md-plugin-chart.js +3 -3
  71. package/dist-library/reactive-md-plugin-data.js +5 -5
  72. package/dist-library/reactive-md-plugin-diagram.js +4 -4
  73. package/dist-library/reactive-md-plugin-forms.js +4 -4
  74. package/dist-library/reactive-md-plugin-gallery.js +3 -3
  75. package/dist-library/reactive-md-plugin-navigation.js +3 -3
  76. package/dist-library/reactive-md-plugin-network.js +119 -116
  77. package/dist-library/reactive-md-plugin-plot.js +4 -4
  78. package/dist-library/reactive-md-print.css +304 -304
  79. package/dist-library/reactive-md-react-minimal.js +4 -4
  80. package/dist-library/reactive-md-react-server.js +6 -6
  81. package/dist-library/reactive-md-react-unstyled.js +11 -12
  82. package/dist-library/reactive-md-react.js +11 -12
  83. package/dist-library/reactive-md-runtime-browser.js +2 -1
  84. package/dist-library/reactive-md-runtime.js +4 -3
  85. package/dist-library/reactive-md-sdk.js +8 -7
  86. package/dist-library/reactive-md-standalone-configured.js +2 -2
  87. package/dist-library/reactive-md-standalone-host.js +2 -2
  88. package/dist-library/reactive-md-testing-browser.js +2 -2
  89. package/dist-library/reactive-md-testing-react.js +6 -6
  90. package/dist-library/reactive-md-testing.js +5 -5
  91. package/dist-library/reactive-md.js +649 -373
  92. package/dist-library/{registry-05JiqmEp.js → registry-D6OGkOcX.js} +3 -3
  93. package/dist-library/{registry-core-Bbad9Bm2.js → registry-core-C9xOunaw.js} +1 -1
  94. package/dist-library/{resources-IeJomeUT.js → resources-B0x_w3s9.js} +71 -46
  95. package/dist-library/{runtime-B2fxeveq.js → runtime-BDnnimPA.js} +17 -16
  96. package/dist-library/{runtime-CuOyRe9f.js → runtime-BpQdZmFI.js} +269 -263
  97. package/dist-library/{schema-C-AeByPp.js → schema-BryM_VRW.js} +14 -14
  98. package/dist-library/{sdk-core-BJLJaVR5.js → sdk-core-ChslheKs.js} +499 -158
  99. package/dist-library/{session-core-BGka5D1J.js → session-core-dxQCJBNa.js} +171 -156
  100. package/dist-library/{shareable-jkGi2g6y.js → shareable-B8xMoGEa.js} +265 -297
  101. package/dist-library/types/authoring/catalog.d.ts +1 -2
  102. package/dist-library/types/build/diagnostics.d.ts +1 -1
  103. package/dist-library/types/components/shared/visual-frame.d.ts +6 -2
  104. package/dist-library/types/local/compilation/compiler-capabilities.d.ts +3 -0
  105. package/dist-library/types/local/compilation/compiler-core.d.ts +11 -3
  106. package/dist-library/types/local/compilation/compiler-services.d.ts +8 -4
  107. package/dist-library/types/local/compilation/compiler.d.ts +3 -3
  108. package/dist-library/types/local/compilation/session/incremental.d.ts +20 -5
  109. package/dist-library/types/local/compilation/streaming.d.ts +27 -0
  110. package/dist-library/types/local/configuration/capability-policy.d.ts +3 -0
  111. package/dist-library/types/local/configuration/diagnostic-messages.d.ts +48 -0
  112. package/dist-library/types/local/configuration/options-core.d.ts +1 -2
  113. package/dist-library/types/local/configuration/options.d.ts +1 -0
  114. package/dist-library/types/local/css/author-css.d.ts +66 -0
  115. package/dist-library/types/local/html/extended-fragment.d.ts +41 -0
  116. package/dist-library/types/local/html/html.d.ts +39 -3
  117. package/dist-library/types/local/index.d.ts +7 -1
  118. package/dist-library/types/local/observability-codes.d.ts +2 -0
  119. package/dist-library/types/local/observability-core.d.ts +25 -0
  120. package/dist-library/types/local/observability-messages.d.ts +6 -0
  121. package/dist-library/types/local/observability.d.ts +43 -0
  122. package/dist-library/types/local/parsing/author-markdown.d.ts +11 -0
  123. package/dist-library/types/local/parsing/parse-session.d.ts +2 -2
  124. package/dist-library/types/local/parsing/parser-convert.d.ts +2 -1
  125. package/dist-library/types/local/parsing/parser-core.d.ts +8 -1
  126. package/dist-library/types/local/parsing/parser-internals.d.ts +2 -1
  127. package/dist-library/types/local/parsing/parser.d.ts +2 -2
  128. package/dist-library/types/local/rendering/document/ExtendedHtmlFragment.d.ts +14 -0
  129. package/dist-library/types/local/rendering/document/LocalDocumentViewCore.d.ts +25 -1
  130. package/dist-library/types/local/rendering/document/LocalReactiveDocumentCore.d.ts +1 -1
  131. package/dist-library/types/local/rendering/document/use-author-script.d.ts +3 -0
  132. package/dist-library/types/local/rendering/document/view-render-context.d.ts +11 -1
  133. package/dist-library/types/local/runtime/author-script-protocol.d.ts +59 -0
  134. package/dist-library/types/local/transport/worker.d.ts +79 -5
  135. package/dist-library/types/local/types.d.ts +60 -16
  136. package/dist-library/types/observability.d.ts +7 -0
  137. package/dist-library/types/react/component-api.d.ts +10 -1
  138. package/dist-library/types/react/component-utils.d.ts +9 -1
  139. package/dist-library/types/react/sdk-core.d.ts +4 -1
  140. package/dist-library/types/shareable.d.ts +5 -4
  141. package/dist-library/types/standalone/prepare.d.ts +1 -1
  142. package/dist-library/types/standalone/session-core.d.ts +3 -2
  143. package/dist-library/{types-BFC5rzC4.js → types-Ib5kSScP.js} +1 -1
  144. package/dist-library/types-daDo2c_w.js +3 -0
  145. package/dist-library/{validation-BlDL2uD9.js → validation-B3RI0xOk.js} +218 -200
  146. package/dist-library/version-DAxuGOG2.js +147 -0
  147. package/dist-library/{visual-frame-G8PHoj1e.js → visual-frame-_rcd5HUv.js} +6 -5
  148. package/dist-library/{visuals-BkYRmYGO.js → visuals-DkDhNdEZ.js} +24191 -24190
  149. package/dist-standalone/reactive-md-standalone.js +124 -117
  150. package/docs/README-ch.md +101 -94
  151. package/docs/README.md +101 -94
  152. package/docs/compatibility/api-stability-ch.md +25 -0
  153. package/docs/compatibility/api-stability-en.md +25 -0
  154. package/docs/compatibility/compatibility-ch.md +146 -129
  155. package/docs/compatibility/compatibility-en.md +146 -129
  156. package/docs/compatibility/compatibility-manifest.schema.json +161 -0
  157. package/docs/compatibility/deprecation-ch.md +21 -0
  158. package/docs/compatibility/deprecation-en.md +21 -0
  159. package/docs/compatibility/source-versioning-ch.md +162 -162
  160. package/docs/compatibility/source-versioning-en.md +162 -162
  161. package/docs/compatibility/support-matrix-ch.md +108 -0
  162. package/docs/compatibility/support-matrix-en.md +108 -0
  163. package/docs/development/component-development-ch.md +66 -66
  164. package/docs/development/component-development-en.md +66 -66
  165. package/docs/development/component-development-reference-ch.md +253 -253
  166. package/docs/development/component-development-reference-en.md +238 -238
  167. package/docs/development/component-protocol-ch.md +748 -748
  168. package/docs/development/component-protocol-en.md +750 -750
  169. package/docs/development/extension-tutorial-ch.md +308 -308
  170. package/docs/development/extension-tutorial-en.md +308 -308
  171. package/docs/development/performance-overview-ch.md +422 -422
  172. package/docs/development/performance-overview-en.md +422 -422
  173. package/docs/guides/local-guide-ch.md +532 -532
  174. package/docs/guides/local-guide-en.md +532 -532
  175. package/docs/integration/author-tools-ch.md +64 -64
  176. package/docs/integration/author-tools-en.md +64 -64
  177. package/docs/integration/compiler-ch.md +49 -47
  178. package/docs/integration/compiler-en.md +36 -34
  179. package/docs/integration/directory-discovery-en.md +1 -1
  180. package/docs/integration/editor-ch.md +295 -295
  181. package/docs/integration/editor-en.md +303 -303
  182. package/docs/integration/extension-sdk-ch.md +394 -394
  183. package/docs/integration/extension-sdk-en.md +379 -379
  184. package/docs/integration/local-integration-ch.md +646 -524
  185. package/docs/integration/local-integration-en.md +662 -540
  186. package/docs/integration/shareable-export-ch.md +307 -305
  187. package/docs/integration/shareable-export-en.md +309 -307
  188. package/docs/reference/diagnostics-counting-ch.md +104 -104
  189. package/docs/reference/diagnostics-counting-en.md +104 -104
  190. package/docs/reference/html-compatibility-ch.md +93 -140
  191. package/docs/reference/html-compatibility-en.md +95 -140
  192. package/docs/reference/local-interaction-syntax-ch.md +724 -724
  193. package/docs/reference/local-interaction-syntax-en.md +722 -722
  194. package/docs/reference/public-api-ch.md +39 -7
  195. package/docs/reference/public-api-en.md +39 -7
  196. package/docs/reference/theme-protocol-ch.md +198 -198
  197. package/docs/reference/theme-protocol-en.md +217 -217
  198. package/docs/releases/release-0.4.0-ch.md +91 -91
  199. package/docs/releases/release-0.4.0-en.md +91 -91
  200. package/docs/releases/release-0.4.1-ch.md +25 -25
  201. package/docs/releases/release-0.4.1-en.md +25 -25
  202. package/docs/releases/release-0.5.0-ch.md +43 -43
  203. package/docs/releases/release-0.5.0-en.md +43 -43
  204. package/docs/releases/release-0.5.1-ch.md +41 -41
  205. package/docs/releases/release-0.5.1-en.md +41 -41
  206. package/docs/releases/release-0.5.2-ch.md +37 -37
  207. package/docs/releases/release-0.5.2-en.md +37 -37
  208. package/docs/releases/release-0.5.3-ch.md +26 -26
  209. package/docs/releases/release-0.5.3-en.md +26 -26
  210. package/docs/releases/release-0.6.0-ch.md +59 -59
  211. package/docs/releases/release-0.6.0-en.md +59 -59
  212. package/docs/releases/release-0.6.1-ch.md +29 -29
  213. package/docs/releases/release-0.6.1-en.md +29 -29
  214. package/docs/releases/release-0.7.0-ch.md +86 -86
  215. package/docs/releases/release-0.7.0-en.md +86 -86
  216. package/docs/releases/release-0.9.1-ch.md +29 -0
  217. package/docs/releases/release-0.9.1-en.md +29 -0
  218. package/docs/releases/release-0.9.2-ch.md +33 -0
  219. package/docs/releases/release-0.9.2-en.md +33 -0
  220. package/examples/component-package/README-ch.md +101 -101
  221. package/examples/component-package/README.md +133 -133
  222. package/examples/conformance/README-ch.md +55 -55
  223. package/examples/conformance/README.md +55 -55
  224. package/examples/conformance/component-protocol-1.json +482 -482
  225. package/examples/conformance/component-protocol-1.schema.json +76 -76
  226. package/examples/conformance/local-draft-1.json +50 -50
  227. package/examples/conformance/local-draft-2.json +212 -212
  228. package/examples/game-2048-package/LICENSE +21 -21
  229. package/examples/game-2048-package/NOTICES.md +11 -11
  230. package/examples/game-2048-package/README-ch.md +91 -91
  231. package/examples/game-2048-package/README.md +98 -98
  232. package/examples/game-2048-package/package.json +35 -35
  233. package/examples/game-2048-package/sample/document.reactive.md +17 -17
  234. package/examples/game-2048-package/scripts/build-export.mjs +44 -44
  235. package/examples/game-2048-package/scripts/build.mjs +130 -130
  236. package/examples/game-2048-package/scripts/verify.mjs +180 -180
  237. package/examples/game-2048-package/src/component.css +161 -161
  238. package/examples/game-2048-package/src/components.tsx +326 -326
  239. package/examples/game-2048-package/src/game-engine.ts +228 -228
  240. package/examples/game-2048-package/src/harness.tsx +34 -34
  241. package/examples/game-2048-package/src/manifest.ts +85 -85
  242. package/examples/game-2048-package/src/node-entry.ts +30 -30
  243. package/examples/game-2048-package/src/sample.ts +4 -4
  244. package/examples/game-2048-package/tsconfig.json +15 -15
  245. package/examples/integration/README-ch.md +82 -63
  246. package/examples/integration/README.md +82 -63
  247. package/examples/integration/core/index.mjs +32 -32
  248. package/examples/integration/extension-sdk/README-ch.md +24 -24
  249. package/examples/integration/extension-sdk/README.md +24 -24
  250. package/examples/integration/streaming/index.html +48 -0
  251. package/examples/integration/streaming/main.js +175 -0
  252. package/examples/integration/streaming/package.json +13 -0
  253. package/examples/integration/streaming/worker.js +3 -0
  254. package/examples/integration/worker/index.html +19 -19
  255. package/examples/integration/worker/main.js +61 -61
  256. package/examples/integration/worker/package.json +13 -13
  257. package/examples/integration/worker/worker.js +3 -3
  258. package/examples/local/README-ch.md +76 -76
  259. package/examples/local/README.md +76 -76
  260. package/examples/local/charts.reactive.md +73 -73
  261. package/examples/local/recipes/invoice-zh.reactive.md +36 -36
  262. package/examples/local/recipes/invoice.reactive.md +36 -36
  263. package/examples/local/recipes/workshop-zh.reactive.md +33 -33
  264. package/examples/local/recipes/workshop.reactive.md +33 -33
  265. package/examples/local/showcase/README-ch.md +22 -22
  266. package/examples/local/showcase/README.md +31 -31
  267. package/examples/local/showcase/explore.reactive.md +102 -102
  268. package/examples/local/showcase/flow.reactive.md +86 -86
  269. package/examples/local/showcase/forms.reactive.md +126 -126
  270. package/examples/local/showcase/functions.reactive.md +119 -119
  271. package/examples/local/showcase/layout.reactive.md +100 -100
  272. package/examples/local/showcase/statistics.reactive.md +108 -108
  273. package/examples/local/showcase/tasks.reactive.md +89 -89
  274. package/examples/local/showcase/zh/explore.reactive.md +102 -102
  275. package/examples/local/showcase/zh/flow.reactive.md +86 -86
  276. package/examples/local/showcase/zh/forms.reactive.md +126 -126
  277. package/examples/local/showcase/zh/functions.reactive.md +119 -119
  278. package/examples/local/showcase/zh/layout.reactive.md +100 -100
  279. package/examples/local/showcase/zh/statistics.reactive.md +108 -108
  280. package/examples/local/showcase/zh/tasks.reactive.md +89 -89
  281. package/examples/minimal-extension/README-ch.md +78 -78
  282. package/examples/minimal-extension/README.md +78 -78
  283. package/examples/minimal-extension/index.html +15 -15
  284. package/examples/minimal-extension/package.json +26 -26
  285. package/examples/minimal-extension/sample/document.reactive.md +10 -10
  286. package/examples/minimal-extension/scripts/build.mjs +32 -32
  287. package/examples/minimal-extension/scripts/export.mjs +72 -72
  288. package/examples/minimal-extension/scripts/test-node.mjs +75 -75
  289. package/examples/minimal-extension/src/extension.tsx +90 -90
  290. package/examples/minimal-extension/src/preview.tsx +12 -12
  291. package/examples/minimal-extension/src/source.ts +4 -4
  292. package/examples/minimal-extension/tsconfig.json +14 -14
  293. package/examples/sci-fi-theme/README-ch.md +133 -133
  294. package/examples/sci-fi-theme/README.md +148 -148
  295. package/examples/sci-fi-theme/demo/acceptance.reactive.md +454 -454
  296. package/examples/sci-fi-theme/demo/demo.css +638 -638
  297. package/examples/sci-fi-theme/demo/document.reactive.md +206 -206
  298. package/examples/sci-fi-theme/demo/index.html +13 -13
  299. package/examples/sci-fi-theme/demo/main.tsx +215 -215
  300. package/examples/sci-fi-theme/docs/design-system-ch.md +245 -245
  301. package/examples/sci-fi-theme/docs/design-system.md +474 -474
  302. package/examples/sci-fi-theme/package.json +28 -28
  303. package/examples/sci-fi-theme/scripts/screenshot.mjs +98 -98
  304. package/examples/sci-fi-theme/src/components.css +2370 -2370
  305. package/examples/sci-fi-theme/src/index.ts +6 -6
  306. package/examples/sci-fi-theme/src/notch.css +142 -142
  307. package/examples/sci-fi-theme/src/sci-fi.css +7 -7
  308. package/examples/sci-fi-theme/src/theme.ts +39 -39
  309. package/examples/sci-fi-theme/tsconfig.json +20 -20
  310. package/examples/sci-fi-theme/vite.config.ts +24 -24
  311. package/examples/tetris-package/LICENSE +21 -21
  312. package/examples/tetris-package/NOTICES.md +11 -11
  313. package/examples/tetris-package/README-ch.md +91 -91
  314. package/examples/tetris-package/README.md +95 -95
  315. package/examples/tetris-package/package.json +35 -35
  316. package/examples/tetris-package/sample/document.reactive.md +16 -16
  317. package/examples/tetris-package/scripts/build-export.mjs +44 -44
  318. package/examples/tetris-package/scripts/build.mjs +130 -130
  319. package/examples/tetris-package/scripts/verify.mjs +173 -173
  320. package/examples/tetris-package/src/component.css +145 -145
  321. package/examples/tetris-package/src/components.tsx +334 -334
  322. package/examples/tetris-package/src/harness.tsx +34 -34
  323. package/examples/tetris-package/src/manifests.ts +93 -93
  324. package/examples/tetris-package/src/node-entry.ts +16 -16
  325. package/examples/tetris-package/src/sample.ts +4 -4
  326. package/examples/tetris-package/src/tetris-engine.ts +325 -325
  327. package/examples/tetris-package/tsconfig.json +15 -15
  328. package/package.json +12 -1
  329. package/dist-library/LocalDocumentViewCore-BLG4hMuO.js +0 -9535
  330. package/dist-library/LocalReactiveDocumentCore-DVQ6WA9G.js +0 -259
  331. package/dist-library/compiler-DfGbQhyD.js +0 -62
  332. package/dist-library/component-state-BoLCGee4.js +0 -801
  333. package/dist-library/component-utils-BvHL8VGt.js +0 -298
  334. package/dist-library/export-C7IDW9ul.js +0 -311
  335. package/dist-library/layout-C22VjZh0.js +0 -542
  336. package/dist-library/options-CdSKOi7p.js +0 -116
  337. package/dist-library/preset-core-CKc5YXSM.js +0 -1443
  338. package/dist-library/react-LY5qsVeP.js +0 -7
@@ -1,21 +1,24 @@
1
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-C5kJYk-J.js";
3
- import { a as g, t as _ } from "./compile-LhpTKqCR.js";
4
- import { s as v } from "./compiler-core-DTxY-qYz.js";
5
- import { b as y, g as b } from "./validation-BlDL2uD9.js";
6
- import { c as x } from "./config-BUo-8O5C.js";
7
- import { t as S } from "./options-CdSKOi7p.js";
8
- import { t as ee } from "./compiler-DfGbQhyD.js";
9
- import { i as te, n as ne, r as re, t as C } from "./authoring-Co_TiE-P.js";
10
- import { c as w } from "./schema-C-AeByPp.js";
11
- import { n as T, t as ie } from "./incremental-D_6vwAAE.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-CuOyRe9f.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-jkGi2g6y.js";
16
- import { t as Oe } from "./component-state-BBJ08vML.js";
2
+ import { _ as i, a, c as o, d as s, i as c, l, m as u, n as d, o as f, p, r as m, s as h, t as g, u as _, v } from "./document-theme-C8J6UyNO.js";
3
+ import { a as y, t as b } from "./compile-Dx6Uw3D9.js";
4
+ import { d as x } from "./compiler-core-DDDdvuLy.js";
5
+ import { g as S } from "./validation-B3RI0xOk.js";
6
+ import { t as C } from "./types-daDo2c_w.js";
7
+ import { c as ee } from "./config-DXLvctiZ.js";
8
+ import { t as te } from "./options-BBp9IcHm.js";
9
+ import { n as w, r as T, t as ne } from "./observability-core-Bcu7vpnl.js";
10
+ import { t as re } from "./compiler-dxLPB9Ym.js";
11
+ import { i as ie, n as ae, r as oe, t as se } from "./authoring-Ci_KzJ0q.js";
12
+ import { c as E } from "./schema-BryM_VRW.js";
13
+ import { n as D, t as ce } from "./incremental-9nx92u9c.js";
14
+ import { a as le, i as ue, n as de, o as fe, r as pe } from "./runtime-BpQdZmFI.js";
15
+ import { i as me } from "./identity-BUx0Q_-d.js";
16
+ import { i as he, n as ge, r as _e, t as ve } from "./sample-bP4zHB3L.js";
17
+ import { _ as ye, a as be, f as xe, g as Se, h as Ce, i as we, m as Te, n as Ee, p as De, r as Oe, t as ke, v as Ae, y as je } from "./shareable-B8xMoGEa.js";
18
+ import { n as O, t as Me } from "./observability-4KqXhIEU.js";
19
+ import { t as Ne } from "./component-state-BRwvTV0d.js";
17
20
  // src/local/source/source-migration.ts
18
- var E = /* @__PURE__ */ new Set([
21
+ var Pe = /* @__PURE__ */ new Set([
19
22
  "sum",
20
23
  "average",
21
24
  "minOf",
@@ -33,7 +36,7 @@ var E = /* @__PURE__ */ new Set([
33
36
  "slice",
34
37
  "dateCompare",
35
38
  "dateDiff"
36
- ]), ke = /* @__PURE__ */ new Set([
39
+ ]), Fe = /* @__PURE__ */ new Set([
37
40
  "jump",
38
41
  "anchor",
39
42
  "text",
@@ -50,12 +53,12 @@ var E = /* @__PURE__ */ new Set([
50
53
  "data-table",
51
54
  "column",
52
55
  "external"
53
- ]), Ae = /* @__PURE__ */ new Set(["external"]), je = /* @__PURE__ */ new Set([
56
+ ]), Ie = /* @__PURE__ */ new Set(["external"]), Le = /* @__PURE__ */ new Set([
54
57
  "local-draft-1",
55
58
  "local-draft-2",
56
- y
57
- ]), Me = `<!-- reactive-md: ${y} -->`;
58
- function Ne(e) {
59
+ C
60
+ ]), Re = `<!-- reactive-md: ${C} -->`;
61
+ function ze(e) {
59
62
  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;
60
63
  return {
61
64
  declaredVersion: n,
@@ -65,27 +68,27 @@ function Ne(e) {
65
68
  diagnostics: t
66
69
  };
67
70
  }
68
- function Pe(e) {
69
- return Ne(w(e));
71
+ function Be(e) {
72
+ return ze(E(e));
70
73
  }
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");
74
+ function Ve(e, t, n, r, i = "error") {
75
+ let a = l(t, r), o = e.slice(0, n.start), s = o.lastIndexOf("\n");
73
76
  return {
74
77
  code: t,
75
78
  severity: i,
76
79
  range: { ...n },
77
- message: p(a),
80
+ message: f(a),
78
81
  line: o.split("\n").length,
79
82
  column: n.start - s,
80
83
  messageKey: a.key,
81
84
  ...a.params ? { params: a.params } : {}
82
85
  };
83
86
  }
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 = {
87
+ function He(e, t = {}) {
88
+ let n = E(e), r = ze(n), i = typeof t == "object" && !!t && !Array.isArray(t), a = i ? t.fromVersion ?? r.effectiveVersion : r.effectiveVersion, o = typeof a == "string" ? a : "", s = {
86
89
  ok: !1,
87
90
  fromVersion: o,
88
- toVersion: y,
91
+ toVersion: C,
89
92
  needsMigration: !n.versionDeclaration || o !== "local-draft-3",
90
93
  diagnostics: r.diagnostics.filter((e) => e.code !== "local.version.unsupported")
91
94
  }, c = {
@@ -106,15 +109,15 @@ function Ie(e, t = {}) {
106
109
  }
107
110
  s.diagnostics.push(e);
108
111
  }, d = (t, n, r, i) => {
109
- u(Fe(e, t, n, r, i));
112
+ u(Ve(e, t, n, r, i));
110
113
  };
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, {
114
+ if (!i || typeof a != "string" || !Le.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, {
112
115
  from: o,
113
116
  detail: "use local-draft-1, local-draft-2 or local-draft-3 and match the source declaration"
114
117
  }), c;
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;
118
+ 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 ? E(f) : n;
116
119
  if (o === "local-draft-1" || o === "local-draft-2") {
117
- let e = o === "local-draft-1" ? ke : Ae, n = (r) => {
120
+ let e = o === "local-draft-1" ? Fe : Ie, n = (r) => {
118
121
  for (let i of r) if (i.name && e.has(i.name)) d("local.upgrade.tag", i.range, { name: i.name });
119
122
  else {
120
123
  if (o === "local-draft-1") {
@@ -126,13 +129,13 @@ function Ie(e, t = {}) {
126
129
  "bind-y"
127
130
  ]) {
128
131
  let t = i.attrs?.[e];
129
- t && E.has(t) && d("local.upgrade.reserved-binding", i.range, { name: t });
132
+ t && Pe.has(t) && d("local.upgrade.reserved-binding", i.range, { name: t });
130
133
  }
131
134
  (i.name === "input" || i.name === "textarea") && (i.attrs?.["max-length"] !== void 0 || Number(i.attrs?.["min-length"] ?? 0) > 0) && d("local.upgrade.text-length", i.range, void 0, t.allowSemanticChanges ? "warning" : "error");
132
135
  let e = [...i.type === "interpolation" ? [i.value ?? ""] : [], ...Object.values(i.attrs ?? {}).flatMap((e) => [...e.matchAll(/\{\{([\s\S]*?)\}\}/g)].map((e) => e[1]))];
133
136
  for (let t of e) {
134
137
  let e = t.replace(/'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"/g, "");
135
- (e.includes("[") || [...E].some((t) => RegExp(`\\b${t}\\s*\\(`).test(e))) && d("local.upgrade.expression", i.range);
138
+ (e.includes("[") || [...Pe].some((t) => RegExp(`\\b${t}\\s*\\(`).test(e))) && d("local.upgrade.expression", i.range);
136
139
  }
137
140
  }
138
141
  i.type !== "fallback" && i.children && n(i.children);
@@ -141,18 +144,18 @@ function Ie(e, t = {}) {
141
144
  n(p.nodes);
142
145
  }
143
146
  if (s.diagnostics.some((e) => e.severity === "error")) return c;
144
- let m = ee(f);
147
+ let m = re(f);
145
148
  for (let e of m.diagnostics) u(e);
146
149
  return m.ok && (!n.versionDeclaration && s.diagnostics.length < 100 && d("local.upgrade.version-missing", {
147
150
  start: +(e.charCodeAt(0) === 65279),
148
151
  end: +(e.charCodeAt(0) === 65279)
149
- }, { version: y }, "warning"), s.ok = !0), c;
152
+ }, { version: C }, "warning"), s.ok = !0), c;
150
153
  }
151
- function Le(e, t) {
152
- return Ie(e, t).report;
154
+ function Ue(e, t) {
155
+ return He(e, t).report;
153
156
  }
154
- function Re(e, t) {
155
- let { report: n, declaration: r } = Ie(e, t), i = {
157
+ function We(e, t) {
158
+ let { report: n, declaration: r } = He(e, t), i = {
156
159
  ...n,
157
160
  source: e,
158
161
  changed: !1,
@@ -162,7 +165,7 @@ function Re(e, t) {
162
165
  let a = +(e.charCodeAt(0) === 65279), o = r?.range ?? {
163
166
  start: a,
164
167
  end: a
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);
168
+ }, s = e.includes("\r\n") ? "\r\n" : "\n", c = r ? Re : `${Re}${s}${s}`, l = e.slice(0, o.start) + c + e.slice(o.end);
166
169
  return {
167
170
  ...n,
168
171
  source: l,
@@ -174,7 +177,7 @@ function Re(e, t) {
174
177
  };
175
178
  }
176
179
  // src/local/transport/compile-patch.ts
177
- var D = "patch-v1", O = 1, ze = 4096, k = [
180
+ var k = "patch-v1", Ge = 1, Ke = 4096, A = [
178
181
  "initialState",
179
182
  "bindings",
180
183
  "bindingSlots",
@@ -182,16 +185,16 @@ var D = "patch-v1", O = 1, ze = 4096, k = [
182
185
  "dependencies",
183
186
  "tableShapes"
184
187
  ];
185
- function A(e) {
188
+ function j(e) {
186
189
  return typeof e == "object" && !!e && !Array.isArray(e);
187
190
  }
188
- function j(e) {
189
- return A(e) && typeof e.start == "number" && Number.isFinite(e.start) && typeof e.end == "number" && Number.isFinite(e.end);
191
+ function M(e) {
192
+ return j(e) && typeof e.start == "number" && Number.isFinite(e.start) && typeof e.end == "number" && Number.isFinite(e.end);
190
193
  }
191
- function M() {
194
+ function N() {
192
195
  throw TypeError("Invalid local compile result patch");
193
196
  }
194
- function N(e, t) {
197
+ function P(e, t) {
195
198
  if (e === t) return !0;
196
199
  if (typeof e != "object" || typeof t != "object" || e === null || t === null) return !1;
197
200
  let n = Array.isArray(e);
@@ -199,18 +202,18 @@ function N(e, t) {
199
202
  if (n) {
200
203
  let n = e, r = t;
201
204
  if (n.length !== r.length) return !1;
202
- for (let e = 0; e < n.length; e += 1) if (!N(n[e], r[e])) return !1;
205
+ for (let e = 0; e < n.length; e += 1) if (!P(n[e], r[e])) return !1;
203
206
  return !0;
204
207
  }
205
208
  let r = e, i = t, a = Object.keys(r);
206
209
  if (a.length !== Object.keys(i).length) return !1;
207
- for (let e of a) if (!Object.hasOwn(i, e) || !N(r[e], i[e])) return !1;
210
+ for (let e of a) if (!Object.hasOwn(i, e) || !P(r[e], i[e])) return !1;
208
211
  return !0;
209
212
  }
210
- function P(e) {
211
- return v(e, !1);
213
+ function F(e) {
214
+ return x(e, !1);
212
215
  }
213
- function F(e, t) {
216
+ function I(e, t) {
214
217
  if (typeof e != "string" || typeof t != "string" || e === t) return null;
215
218
  let n = Math.min(e.length, t.length), r = 0;
216
219
  for (; r < n && e.charCodeAt(r) === t.charCodeAt(r);) r += 1;
@@ -222,8 +225,8 @@ function F(e, t) {
222
225
  insert: t.slice(r, a)
223
226
  };
224
227
  }
225
- function Be(e) {
226
- if (!A(e)) return null;
228
+ function L(e) {
229
+ if (!j(e)) return null;
227
230
  let { from: t, to: n, insert: r } = e;
228
231
  return typeof t != "number" || !Number.isSafeInteger(t) || typeof n != "number" || !Number.isSafeInteger(n) || typeof r != "string" || t < 0 || n < t ? null : {
229
232
  from: t,
@@ -231,42 +234,42 @@ function Be(e) {
231
234
  insert: r
232
235
  };
233
236
  }
234
- function I(e, t) {
235
- let n = Be(t);
237
+ function qe(e, t) {
238
+ let n = L(t);
236
239
  return n === null || typeof e != "string" || n.to > e.length ? null : e.slice(0, n.from) + n.insert + e.slice(n.to);
237
240
  }
238
- function L(e) {
241
+ function R(e) {
239
242
  let t = {};
240
243
  for (let [n, r] of Object.entries(e)) n !== "children" && (t[n] = r);
241
244
  return t;
242
245
  }
243
- function R(e, t) {
246
+ function Je(e, t) {
244
247
  let n = Object.keys(e).filter((e) => e !== "children"), r = Object.keys(t).filter((e) => e !== "children");
245
248
  if (n.length !== r.length) return !1;
246
- for (let r of n) if (!Object.hasOwn(t, r) || !N(e[r], t[r])) return !1;
249
+ for (let r of n) if (!Object.hasOwn(t, r) || !P(e[r], t[r])) return !1;
247
250
  return !0;
248
251
  }
249
252
  function z(e) {
250
253
  return e.children === void 0 ? void 0 : e.children.map((e) => e.id);
251
254
  }
252
- function B(e, t) {
255
+ function Ye(e, t) {
253
256
  let n = z(e), r = z(t);
254
257
  if (n === void 0 || r === void 0) return n === r;
255
258
  if (n.length !== r.length) return !1;
256
259
  for (let e = 0; e < n.length; e += 1) if (n[e] !== r[e]) return !1;
257
260
  return !0;
258
261
  }
259
- function V(e, t) {
260
- if (!R(e, t) || !B(e, t)) return !1;
262
+ function Xe(e, t) {
263
+ if (!Je(e, t) || !Ye(e, t)) return !1;
261
264
  if (!e.children || !t.children) return !0;
262
- for (let n = 0; n < e.children.length; n += 1) if (!V(e.children[n], t.children[n])) return !1;
265
+ for (let n = 0; n < e.children.length; n += 1) if (!Xe(e.children[n], t.children[n])) return !1;
263
266
  return !0;
264
267
  }
265
- function Ve(e, t) {
268
+ function Ze(e, t) {
266
269
  let n = Object.keys(e).filter((e) => e !== "children" && e !== "range"), r = Object.keys(t).filter((e) => e !== "children" && e !== "range");
267
270
  if (n.length !== r.length) 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;
271
+ for (let r of n) if (!Object.hasOwn(t, r) || !P(e[r], t[r])) return null;
272
+ if (!M(e.range) || !M(t.range)) return null;
270
273
  let i = e.range.start - t.range.start;
271
274
  if (e.range.end !== t.range.end + i) return null;
272
275
  let a = z(e), o = z(t);
@@ -274,19 +277,19 @@ function Ve(e, t) {
274
277
  if (a !== o) return null;
275
278
  } else {
276
279
  if (a.length !== o.length) return null;
277
- for (let n = 0; n < a.length; n += 1) if (a[n] !== o[n] || Ve(e.children[n], t.children[n]) !== i) return null;
280
+ for (let n = 0; n < a.length; n += 1) if (a[n] !== o[n] || Ze(e.children[n], t.children[n]) !== i) return null;
278
281
  }
279
282
  return i;
280
283
  }
281
- function He(e, t) {
284
+ function Qe(e, t) {
282
285
  let n = Object.keys(e).filter((e) => e !== "children" && e !== "range"), r = Object.keys(t).filter((e) => e !== "children" && e !== "range");
283
286
  if (n.length !== r.length) 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;
287
+ for (let r of n) if (!Object.hasOwn(t, r) || !P(e[r], t[r])) return null;
288
+ if (!M(e.range) || !M(t.range)) return null;
286
289
  let i = e.range.start - t.range.start;
287
290
  return e.range.end === t.range.end + i ? i : null;
288
291
  }
289
- function Ue(e) {
292
+ function B(e) {
290
293
  let t = /* @__PURE__ */ new Map(), n = [...e].reverse();
291
294
  for (; n.length > 0;) {
292
295
  let e = n.pop();
@@ -294,8 +297,8 @@ function Ue(e) {
294
297
  }
295
298
  return t;
296
299
  }
297
- function We(e, t, n, r) {
298
- if (t !== void 0 && V(e, t)) return;
300
+ function $e(e, t, n, r) {
301
+ if (t !== void 0 && Xe(e, t)) return;
299
302
  if (t === void 0) {
300
303
  r.push({
301
304
  id: e.id,
@@ -303,7 +306,7 @@ function We(e, t, n, r) {
303
306
  });
304
307
  return;
305
308
  }
306
- let i = Ve(e, t);
309
+ let i = Ze(e, t);
307
310
  if (i !== null) {
308
311
  i !== 0 && r.push({
309
312
  id: e.id,
@@ -313,27 +316,27 @@ function We(e, t, n, r) {
313
316
  return;
314
317
  }
315
318
  let a = { id: e.id };
316
- if (!R(e, t)) {
317
- let n = He(e, t);
318
- n !== null && n !== 0 ? a.shift = n : a.data = L(e);
319
+ if (!Je(e, t)) {
320
+ let n = Qe(e, t);
321
+ n !== null && n !== 0 ? a.shift = n : a.data = R(e);
319
322
  }
320
- B(e, t) || (a.children = e.children === void 0 ? null : e.children.map((e) => e.id));
323
+ Ye(e, t) || (a.children = e.children === void 0 ? null : e.children.map((e) => e.id));
321
324
  let o = r.length;
322
- if (e.children) for (let t of e.children) We(t, n.get(t.id), n, r);
325
+ if (e.children) for (let t of e.children) $e(t, n.get(t.id), n, r);
323
326
  Object.keys(a).length > 1 ? r.splice(o, 0, a) : r.length > o && r.splice(o, 0, { id: e.id });
324
327
  }
325
- function Ge(e, t) {
326
- if (!A(e)) return { set: t };
328
+ function et(e, t) {
329
+ if (!j(e)) return { set: t };
327
330
  let n = {}, r = [];
328
- for (let [r, i] of Object.entries(t)) Object.hasOwn(e, r) && N(e[r], i) || (n[r] = i);
331
+ for (let [r, i] of Object.entries(t)) Object.hasOwn(e, r) && P(e[r], i) || (n[r] = i);
329
332
  for (let n of Object.keys(e)) Object.hasOwn(t, n) || r.push(n);
330
333
  return Object.keys(n).length === 0 && r.length === 0 ? null : {
331
334
  ...Object.keys(n).length === 0 ? {} : { set: n },
332
335
  ...r.length === 0 ? {} : { remove: r }
333
336
  };
334
337
  }
335
- var Ke = /* @__PURE__ */ new WeakMap();
336
- function qe(e) {
338
+ var tt = /* @__PURE__ */ new WeakMap();
339
+ function nt(e) {
337
340
  let t = 2;
338
341
  for (let n = 0; n < e.length; n++) {
339
342
  let r = e.charCodeAt(n);
@@ -348,14 +351,14 @@ function qe(e) {
348
351
  }
349
352
  return t;
350
353
  }
351
- function H(e, t) {
354
+ function V(e, t) {
352
355
  if (e === null) return {
353
356
  bytes: 4,
354
357
  nodes: 0
355
358
  };
356
359
  let n = typeof e;
357
360
  if (n === "string") return {
358
- bytes: qe(e),
361
+ bytes: nt(e),
359
362
  nodes: 0
360
363
  };
361
364
  if (n === "number") return {
@@ -370,19 +373,19 @@ function H(e, t) {
370
373
  bytes: 0,
371
374
  nodes: 0
372
375
  };
373
- let r = e, i = Ke.get(r);
376
+ let r = e, i = tt.get(r);
374
377
  if (i !== void 0) return i;
375
378
  if (t.has(r)) return {
376
379
  bytes: 0,
377
380
  nodes: 0
378
381
  };
379
382
  t.add(r);
380
- let a, o = +!!et(e);
383
+ let a, o = +!!lt(e);
381
384
  if (Array.isArray(e)) {
382
385
  a = 2;
383
386
  for (let n = 0; n < e.length; n += 1) {
384
387
  n > 0 && (a += 1);
385
- let r = H(e[n], t);
388
+ let r = V(e[n], t);
386
389
  a += r.bytes || 4, o += r.nodes;
387
390
  }
388
391
  } else {
@@ -392,8 +395,8 @@ function H(e, t) {
392
395
  if (!Object.hasOwn(r, n)) continue;
393
396
  let i = r[n];
394
397
  if (i === void 0) continue;
395
- e > 0 && (a += 1), e += 1, a += qe(n) + 1;
396
- let s = H(i, t);
398
+ e > 0 && (a += 1), e += 1, a += nt(n) + 1;
399
+ let s = V(i, t);
397
400
  a += s.bytes, o += s.nodes;
398
401
  }
399
402
  }
@@ -402,20 +405,20 @@ function H(e, t) {
402
405
  bytes: a,
403
406
  nodes: o
404
407
  };
405
- return Ke.set(r, s), s;
408
+ return tt.set(r, s), s;
406
409
  }
407
- function Je(e, t) {
410
+ function rt(e, t) {
408
411
  let n = e.document.nodes ?? [];
409
412
  try {
410
- let r = H(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 {
413
+ let r = V(e, /* @__PURE__ */ new Set()), i = t.ok && typeof t.document.source == "string" ? t.document.source.length : 0;
414
+ if (r.bytes <= Math.max(i, Ke)) return {
412
415
  patchBytes: r.bytes,
413
416
  patchNodes: n.length,
414
417
  preferFull: !1
415
418
  };
416
- let a = H(t, /* @__PURE__ */ new Set()), o = 0;
417
- for (let e of n) e.node === void 0 ? e.data !== void 0 && (o += 1) : o += H(e.node, /* @__PURE__ */ new Set()).nodes;
418
- let s = r.bytes * O >= a.bytes, c = a.nodes > 0 && o * O >= a.nodes;
419
+ let a = V(t, /* @__PURE__ */ new Set()), o = 0;
420
+ for (let e of n) e.node === void 0 ? e.data !== void 0 && (o += 1) : o += V(e.node, /* @__PURE__ */ new Set()).nodes;
421
+ let s = r.bytes * Ge >= a.bytes, c = a.nodes > 0 && o * Ge >= a.nodes;
419
422
  return {
420
423
  patchBytes: r.bytes,
421
424
  fullBytes: a.bytes,
@@ -432,55 +435,55 @@ function Je(e, t) {
432
435
  };
433
436
  }
434
437
  }
435
- function Ye(e, t) {
436
- return Qe(e, t);
438
+ function it(e, t) {
439
+ return st(e, t);
437
440
  }
438
- function Xe(e, t) {
439
- let n = Qe(e, t);
441
+ function at(e, t) {
442
+ let n = st(e, t);
440
443
  return n ? {
441
444
  patch: n,
442
- cost: Je(n, t)
445
+ cost: rt(n, t)
443
446
  } : null;
444
447
  }
445
- function Ze(e, t) {
448
+ function ot(e, t) {
446
449
  let n = e.recoveries, r = t.recoveries;
447
- return n === void 0 ? r === void 0 ? {} : { recoveries: r } : r !== void 0 && N(n, r) ? {} : { recoveries: r === void 0 ? null : r };
450
+ return n === void 0 ? r === void 0 ? {} : { recoveries: r } : r !== void 0 && P(n, r) ? {} : { recoveries: r === void 0 ? null : r };
448
451
  }
449
- function Qe(e, t) {
452
+ function st(e, t) {
450
453
  try {
451
454
  if (!e.ok || !t.ok) return null;
452
455
  let n = e.document, r = t.document;
453
- if (!A(n) || !A(r)) return null;
456
+ if (!j(n) || !j(r)) return null;
454
457
  let i = {};
455
458
  if (typeof n.source == "string" && typeof r.source == "string") {
456
- let e = F(n.source, r.source);
459
+ let e = I(n.source, r.source);
457
460
  e !== null && (i.source = e);
458
461
  } else if (n.source !== r.source) return null;
459
- let a = [], o = {}, s = {}, c = new Set(k), l = /* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(r)]);
462
+ let a = [], o = {}, s = {}, c = new Set(A), l = /* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(r)]);
460
463
  for (let e of l) {
461
464
  if (e === "source" || e === "nodes" || c.has(e)) continue;
462
465
  let t = Object.hasOwn(r, e) && r[e] !== void 0, i = Object.hasOwn(n, e) && n[e] !== void 0;
463
- t ? i && N(n[e], r[e]) || (o[e] = r[e]) : i && a.push(e);
466
+ t ? i && P(n[e], r[e]) || (o[e] = r[e]) : i && a.push(e);
464
467
  }
465
- for (let e of k) {
468
+ for (let e of A) {
466
469
  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;
467
470
  if (!t) {
468
471
  i && a.push(e);
469
472
  continue;
470
473
  }
471
- if (!A(l)) {
472
- i && N(c, l) || (o[e] = l);
474
+ if (!j(l)) {
475
+ i && P(c, l) || (o[e] = l);
473
476
  continue;
474
477
  }
475
478
  if (!i) {
476
479
  s[e] = { set: l };
477
480
  continue;
478
481
  }
479
- if (!A(c)) {
482
+ if (!j(c)) {
480
483
  o[e] = l;
481
484
  continue;
482
485
  }
483
- let u = Ge(c, l);
486
+ let u = et(c, l);
484
487
  u !== null && (s[e] = u);
485
488
  }
486
489
  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;
@@ -490,55 +493,55 @@ function Qe(e, t) {
490
493
  break;
491
494
  }
492
495
  }
493
- let h = [], g = Ue(u);
494
- for (let e of d) We(e, g.get(e.id), g, h);
496
+ let h = [], g = B(u);
497
+ for (let e of d) $e(e, g.get(e.id), g, h);
495
498
  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), {
496
499
  kind: "result-patch",
497
- protocol: D,
500
+ protocol: k,
498
501
  document: i,
499
- ...N(e.diagnostics, t.diagnostics) ? {} : { diagnostics: t.diagnostics },
500
- ...Ze(e, t)
502
+ ...P(e.diagnostics, t.diagnostics) ? {} : { diagnostics: t.diagnostics },
503
+ ...ot(e, t)
501
504
  };
502
505
  } catch {
503
506
  return null;
504
507
  }
505
508
  }
506
- function $e(e, t) {
507
- let n = L(e);
508
- return j(n.range) || M(), n.range = {
509
+ function ct(e, t) {
510
+ let n = R(e);
511
+ return M(n.range) || N(), n.range = {
509
512
  start: n.range.start + t,
510
513
  end: n.range.end + t
511
- }, e.children && (n.children = e.children.map((e) => $e(e, t))), n;
514
+ }, e.children && (n.children = e.children.map((e) => ct(e, t))), n;
512
515
  }
513
- function et(e) {
514
- return A(e) && typeof e.id == "string" && typeof e.type == "string" && j(e.range);
516
+ function lt(e) {
517
+ return j(e) && typeof e.id == "string" && typeof e.type == "string" && M(e.range);
515
518
  }
516
- function tt(e, t) {
517
- A(t) || M(), t.set !== void 0 && !A(t.set) && M(), t.remove !== void 0 && !Array.isArray(t.remove) && M();
519
+ function ut(e, t) {
520
+ j(t) || N(), t.set !== void 0 && !j(t.set) && N(), t.remove !== void 0 && !Array.isArray(t.remove) && N();
518
521
  let n = {};
519
- if (A(e)) for (let [t, r] of Object.entries(e)) Object.defineProperty(n, t, {
522
+ if (j(e)) for (let [t, r] of Object.entries(e)) Object.defineProperty(n, t, {
520
523
  value: r,
521
524
  enumerable: !0,
522
525
  configurable: !0,
523
526
  writable: !0
524
527
  });
525
- else e !== void 0 && M();
528
+ else e !== void 0 && N();
526
529
  if (t.set) for (let [e, r] of Object.entries(t.set)) Object.defineProperty(n, e, {
527
- value: P(r),
530
+ value: F(r),
528
531
  enumerable: !0,
529
532
  configurable: !0,
530
533
  writable: !0
531
534
  });
532
- if (t.remove) for (let e of t.remove) typeof e != "string" && M(), delete n[e];
535
+ if (t.remove) for (let e of t.remove) typeof e != "string" && N(), delete n[e];
533
536
  return n;
534
537
  }
535
- function nt(e, t) {
538
+ function dt(e, t) {
536
539
  try {
537
- if (!e.ok || !A(t) || t.kind !== "result-patch" || t.protocol !== "patch-v1") return null;
540
+ if (!e.ok || !j(t) || t.kind !== "result-patch" || t.protocol !== "patch-v1") return null;
538
541
  let n = t.document;
539
- if (!A(n)) return null;
542
+ if (!j(n)) return null;
540
543
  let r = e.document;
541
- if (!A(r)) return null;
544
+ if (!j(r)) return null;
542
545
  let i = {};
543
546
  for (let [e, t] of Object.entries(r)) Object.defineProperty(i, e, {
544
547
  value: t,
@@ -554,11 +557,11 @@ function nt(e, t) {
554
557
  }
555
558
  }
556
559
  if (n.values !== void 0) {
557
- if (!A(n.values)) return null;
560
+ if (!j(n.values)) return null;
558
561
  for (let [e, t] of Object.entries(n.values)) {
559
562
  if (e === "nodes" || e === "source") return null;
560
563
  Object.defineProperty(i, e, {
561
- value: P(t),
564
+ value: F(t),
562
565
  enumerable: !0,
563
566
  configurable: !0,
564
567
  writable: !0
@@ -566,28 +569,28 @@ function nt(e, t) {
566
569
  }
567
570
  }
568
571
  if (n.records !== void 0) {
569
- if (!A(n.records)) return null;
572
+ if (!j(n.records)) return null;
570
573
  for (let e of Object.keys(n.records)) {
571
- if (!k.includes(e)) return null;
574
+ if (!A.includes(e)) return null;
572
575
  let t = n.records[e];
573
- t !== void 0 && (i[e] = tt(r[e], t));
576
+ t !== void 0 && (i[e] = ut(r[e], t));
574
577
  }
575
578
  }
576
579
  let a = typeof r.source == "string" ? r.source : null;
577
580
  if (a === null) return null;
578
581
  if (n.source !== void 0) {
579
- let e = Be(n.source);
582
+ let e = L(n.source);
580
583
  if (e === null) return null;
581
- let t = I(a, e);
584
+ let t = qe(a, e);
582
585
  if (t === null) return null;
583
586
  a = t;
584
587
  }
585
588
  i.source = a;
586
- let o = Array.isArray(r.nodes) ? r.nodes : [], s = Ue(o), c = /* @__PURE__ */ new Map();
589
+ let o = Array.isArray(r.nodes) ? r.nodes : [], s = B(o), c = /* @__PURE__ */ new Map();
587
590
  if (n.nodes !== void 0) {
588
591
  if (!Array.isArray(n.nodes)) return null;
589
592
  for (let e of n.nodes) {
590
- if (!A(e) || typeof e.id != "string" || c.has(e.id)) return null;
593
+ if (!j(e) || typeof e.id != "string" || c.has(e.id)) return null;
591
594
  c.set(e.id, e);
592
595
  }
593
596
  }
@@ -603,23 +606,23 @@ function nt(e, t) {
603
606
  let u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Set(), f = (e) => {
604
607
  let t = u.get(e);
605
608
  if (t !== void 0) return t;
606
- d.has(e) && M();
609
+ d.has(e) && N();
607
610
  let n = c.get(e), r = s.get(e);
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(), et(n.node) && n.node.id === e || M();
611
- let t = P(n.node);
611
+ if (n === void 0) return r === void 0 && N(), u.set(e, r), r;
612
+ if (j(n) || N(), n.node !== void 0) {
613
+ (n.data !== void 0 || n.children !== void 0 || n.shift !== void 0 || n.subtree) && N(), lt(n.node) && n.node.id === e || N();
614
+ let t = F(n.node);
612
615
  return u.set(e, t), t;
613
616
  }
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);
617
+ r === void 0 && n.data === void 0 && N(), n.subtree !== void 0 && n.subtree !== !0 && N(), n.shift !== void 0 && !Number.isSafeInteger(n.shift) && N(), n.data !== void 0 && n.shift !== void 0 && N(), n.children !== void 0 && n.children !== null && (!Array.isArray(n.children) || n.children.some((e) => typeof e != "string")) && N(), d.add(e);
615
618
  let i;
616
- if (n.subtree === !0) (r === void 0 || n.shift === void 0 || n.data !== void 0 || n.children !== void 0) && M(), i = $e(r, n.shift);
619
+ if (n.subtree === !0) (r === void 0 || n.shift === void 0 || n.data !== void 0 || n.children !== void 0) && N(), i = ct(r, n.shift);
617
620
  else {
618
621
  let t;
619
- n.data === void 0 ? (r === void 0 && M(), t = L(r), n.shift !== void 0 && (j(t.range) || M(), t.range = {
622
+ n.data === void 0 ? (r === void 0 && N(), t = R(r), n.shift !== void 0 && (M(t.range) || N(), t.range = {
620
623
  start: t.range.start + n.shift,
621
624
  end: t.range.end + n.shift
622
- })) : (A(n.data) || M(), t = P(n.data), delete t.children, t.id !== e && M());
625
+ })) : (j(n.data) || N(), t = F(n.data), delete t.children, t.id !== e && N());
623
626
  let a;
624
627
  if (n.children !== void 0) a = n.children === null ? null : [...n.children];
625
628
  else {
@@ -631,27 +634,30 @@ function nt(e, t) {
631
634
  return d.delete(e), u.set(e, i), i;
632
635
  }, p = l.map(f);
633
636
  i.nodes = n.roots === void 0 && n.nodes === void 0 ? r.nodes : p;
634
- let m = t.diagnostics === void 0 ? e.diagnostics : Array.isArray(t.diagnostics) ? P(t.diagnostics) : M();
637
+ let m = t.diagnostics === void 0 ? e.diagnostics : Array.isArray(t.diagnostics) ? F(t.diagnostics) : N();
635
638
  if (t.recoveries !== void 0 && t.recoveries !== null && !Array.isArray(t.recoveries)) return null;
639
+ let h = e.status === void 0 ? {} : { status: e.status };
636
640
  if (t.recoveries === null) return {
637
641
  ok: !0,
638
642
  document: i,
639
- diagnostics: m
643
+ diagnostics: m,
644
+ ...h
640
645
  };
641
- let h = t.recoveries === void 0 ? e.recoveries : P([...t.recoveries]);
646
+ let g = t.recoveries === void 0 ? e.recoveries : F([...t.recoveries]);
642
647
  return {
643
648
  ok: !0,
644
649
  document: i,
645
650
  diagnostics: m,
646
- ...h === void 0 ? {} : { recoveries: h }
651
+ ...h,
652
+ ...g === void 0 ? {} : { recoveries: g }
647
653
  };
648
654
  } catch {
649
655
  return null;
650
656
  }
651
657
  }
652
658
  // src/local/transport/flat-compiled-data.ts
653
- var U = "flat-v1";
654
- function rt(e) {
659
+ var H = "flat-v1";
660
+ function ft(e) {
655
661
  if (!e.ok) return !1;
656
662
  let t = e.document.nodes.map((e) => ({
657
663
  node: e,
@@ -667,7 +673,7 @@ function rt(e) {
667
673
  }
668
674
  return !1;
669
675
  }
670
- function it(e) {
676
+ function pt(e) {
671
677
  let t = [], n = /* @__PURE__ */ new Map(), r = [], i = (e) => {
672
678
  if (typeof e == "object" && e) {
673
679
  let i = n.get(e);
@@ -696,11 +702,11 @@ function it(e) {
696
702
  for (let t of Object.keys(e)) n.push([t, i(e[t])]);
697
703
  }
698
704
  return {
699
- version: U,
705
+ version: H,
700
706
  records: t
701
707
  };
702
708
  }
703
- function at(e) {
709
+ function mt(e) {
704
710
  if (!e || typeof e != "object") return null;
705
711
  let t = e;
706
712
  if (t.version !== "flat-v1" || !Array.isArray(t.records) || t.records.length === 0 || t.records.length > 2e6) return null;
@@ -760,21 +766,21 @@ function at(e) {
760
766
  return r[0];
761
767
  }
762
768
  // src/local/transport/worker-job.ts
763
- var ot = 150, st = 200, ct = [
769
+ var ht = 150, gt = 200, _t = [
764
770
  "maxSyntaxNodes",
765
771
  "maxParseWork",
766
772
  "maxMarkdownDepth"
767
773
  ];
768
- function W(e) {
774
+ function U(e) {
769
775
  return e instanceof Error ? e.message : String(e);
770
776
  }
771
- function G() {
777
+ function W() {
772
778
  return typeof performance < "u" ? performance.now() : Date.now();
773
779
  }
774
- function K(e) {
780
+ function G(e) {
775
781
  return Number.isFinite(e) ? Math.max(0, Math.round(e)) : 0;
776
782
  }
777
- function q(e, t, n) {
783
+ function K(e, t, n) {
778
784
  let r = {
779
785
  tokens: [],
780
786
  bindings: [],
@@ -782,7 +788,7 @@ function q(e, t, n) {
782
788
  };
783
789
  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;
784
790
  try {
785
- return C(e, t, {
791
+ return se(e, t, {
786
792
  ...n.ok ? { document: n.document } : {},
787
793
  diagnostics: !1
788
794
  });
@@ -794,7 +800,7 @@ function q(e, t, n) {
794
800
  };
795
801
  }
796
802
  }
797
- function lt(e) {
803
+ function vt(e) {
798
804
  return Array.isArray(e) ? e.length > 32 ? Array(33) : e.map((e) => {
799
805
  if (!e || typeof e != "object" || Array.isArray(e)) return e;
800
806
  let t = e, n = { ...t }, r = t.props;
@@ -811,25 +817,25 @@ function lt(e) {
811
817
  return n.props = i, n;
812
818
  }) : e;
813
819
  }
814
- function ut(e) {
820
+ function yt(e) {
815
821
  if (e !== void 0) try {
816
822
  if (typeof e != "object" || !e || Array.isArray(e)) return e;
817
823
  let t = e, n = {};
818
- for (let e of b) Object.hasOwn(t, e) && (n[e] = t[e]);
819
- if (Object.hasOwn(t, "markdownBreaks") && (n.markdownBreaks = t.markdownBreaks), Object.hasOwn(t, "strict") && (n.strict = t.strict), Object.hasOwn(t, "limits")) {
824
+ for (let e of S) Object.hasOwn(t, e) && (n[e] = t[e]);
825
+ 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")) {
820
826
  let e = t.limits;
821
827
  if (e && typeof e == "object" && !Array.isArray(e)) {
822
828
  let t = {};
823
- for (let n of ct) Object.hasOwn(e, n) && (t[n] = e[n]);
829
+ for (let n of _t) Object.hasOwn(e, n) && (t[n] = e[n]);
824
830
  n.limits = t;
825
831
  } else n.limits = e;
826
832
  }
827
- return Object.hasOwn(t, "hostComponents") && (n.hostComponents = lt(t.hostComponents)), Object.hasOwn(t, "config") && (n.config = x(t.config)), n;
833
+ return Object.hasOwn(t, "hostComponents") && (n.hostComponents = vt(t.hostComponents)), Object.hasOwn(t, "config") && (n.config = ee(t.config)), n;
828
834
  } catch {
829
835
  return e;
830
836
  }
831
837
  }
832
- function dt(e) {
838
+ function bt(e) {
833
839
  try {
834
840
  if (!e || typeof e != "object" || Array.isArray(e)) return "";
835
841
  let t = e.limits;
@@ -845,8 +851,8 @@ function dt(e) {
845
851
  return ":unreadable";
846
852
  }
847
853
  }
848
- function ft(e) {
849
- let t = S(e);
854
+ function xt(e) {
855
+ let t = te(e);
850
856
  if (t !== "invalid") return t;
851
857
  try {
852
858
  return `invalid:${JSON.stringify(e)}`;
@@ -854,30 +860,43 @@ function ft(e) {
854
860
  return "invalid";
855
861
  }
856
862
  }
857
- function J(e) {
858
- return `${ft(e)}${dt(e)}`;
863
+ function q(e) {
864
+ return `${xt(e)}${bt(e)}`;
859
865
  }
860
866
  // src/local/transport/worker-handler.ts
861
- function pt(e, t, n) {
862
- let r = e;
863
- return typeof r.compileShared == "function" ? r.compileShared(t, n) : e.compile(t, n);
867
+ function St(e, t, n, r) {
868
+ let i = e;
869
+ return typeof i.compileShared == "function" ? i.compileShared(t, n, r) : e.compile(t, n, r);
870
+ }
871
+ function Ct(e) {
872
+ return e === "streaming" || e === "final";
864
873
  }
865
- function Y(e) {
874
+ function J(e) {
866
875
  return e.stats;
867
876
  }
868
- function X(e, t, n) {
877
+ function Y(e, t, n, r) {
869
878
  try {
870
879
  e.postMessage({
871
880
  id: t,
881
+ ...r?.traceId === void 0 ? {} : {
882
+ traceId: r.traceId,
883
+ requestId: r.requestId,
884
+ sourceRevision: r.sourceRevision
885
+ },
872
886
  ok: !1,
873
887
  message: n
874
888
  });
875
889
  } catch {}
876
890
  }
877
- function mt(e, t, n, r, i) {
891
+ function wt(e, t, n, r, i) {
878
892
  try {
879
893
  e.postMessage({
880
- id: t,
894
+ id: t.id,
895
+ ...t.traceId === void 0 ? {} : {
896
+ traceId: t.traceId,
897
+ requestId: t.requestId,
898
+ sourceRevision: t.sourceRevision
899
+ },
881
900
  ok: !1,
882
901
  message: n,
883
902
  retryFull: !0,
@@ -886,18 +905,18 @@ function mt(e, t, n, r, i) {
886
905
  });
887
906
  } catch {}
888
907
  }
889
- function ht(e) {
908
+ function Tt(e) {
890
909
  return !!e && typeof e == "object" && (e.control === "dispose" || e.control === "cancel-preparation");
891
910
  }
892
- function gt(e) {
911
+ function Et(e) {
893
912
  if (!e || typeof e != "object") return !1;
894
913
  let t = e;
895
914
  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";
896
915
  }
897
- function _t(e, t = {}) {
916
+ function Dt(e, t = {}) {
898
917
  let n = e === void 0 ? globalThis : e;
899
918
  if (!n || typeof n.postMessage != "function") throw TypeError("startLocalCompileWorker requires a worker scope with postMessage");
900
- 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 = () => {
919
+ let r = t.createSession ? t.createSession() : D(), 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 = () => {
901
920
  p += 1, f !== null && (f.aborted = !0, f = null), d !== null && (clearTimeout(d), d = null);
902
921
  }, g = () => new Promise((e) => {
903
922
  typeof setTimeout == "function" ? setTimeout(e, 0) : e();
@@ -907,11 +926,11 @@ function _t(e, t = {}) {
907
926
  if (typeof t != "function") return;
908
927
  let n = { aborted: !1 };
909
928
  f = n;
910
- let r = G(), a = !1;
929
+ let r = W(), a = !1;
911
930
  try {
912
931
  a = await t.call(i, n, g);
913
932
  } catch {} finally {
914
- f === n && (f = null), a && !n.aborted && !u && e === p && (m = K(G() - r));
933
+ f === n && (f = null), a && !n.aborted && !u && e === p && (m = G(W() - r));
915
934
  }
916
935
  }, v = () => {
917
936
  if (u || !s) return;
@@ -935,86 +954,113 @@ function _t(e, t = {}) {
935
954
  let t = typeof e == "number" && Number.isSafeInteger(e) && e > 0 ? e : null;
936
955
  return t === null ? l + 1 : t > l ? t : l + 1;
937
956
  }, S = (e, t, i, a, o = !1, s) => {
938
- let l = c;
939
- if (l === null) return !1;
940
- let u = K(i), d = s === void 0 ? b(u) : {
941
- ...b(u),
957
+ let { id: l, traceId: u, requestId: d, sourceRevision: f } = e, p = c;
958
+ if (p === null) return !1;
959
+ let m = G(i), h = s === void 0 ? b(m) : {
960
+ ...b(m),
942
961
  ...s
943
962
  };
944
963
  try {
945
- let i = a ? {
946
- id: e,
964
+ let e = a ? {
965
+ id: l,
966
+ ...u === void 0 ? {} : {
967
+ traceId: u,
968
+ requestId: d,
969
+ sourceRevision: f
970
+ },
947
971
  ok: !0,
948
- result: l.result,
949
- duration: u,
950
- incremental: Y(r),
951
- protocol: D,
972
+ result: p.result,
973
+ duration: m,
974
+ incremental: J(r),
975
+ ...p.sourcePhase === void 0 ? {} : { sourcePhase: p.sourcePhase },
976
+ protocol: k,
952
977
  revision: t,
953
- metrics: d
978
+ metrics: h
954
979
  } : {
955
- id: e,
980
+ id: l,
981
+ ...u === void 0 ? {} : {
982
+ traceId: u,
983
+ requestId: d,
984
+ sourceRevision: f
985
+ },
956
986
  ok: !0,
957
- result: l.result,
958
- duration: u,
959
- incremental: Y(r)
987
+ result: p.result,
988
+ duration: m,
989
+ incremental: J(r),
990
+ ...p.sourcePhase === void 0 ? {} : { sourcePhase: p.sourcePhase }
960
991
  };
961
- if (o && i.ok) {
962
- let e = G();
963
- i.analysis = q(l.source, l.options, l.result), i.metrics = {
964
- ...i.metrics,
965
- analysisMs: K(G() - e)
992
+ if (o && e.ok) {
993
+ let t = W();
994
+ e.analysis = K(p.source, p.options, p.result), e.metrics = {
995
+ ...e.metrics,
996
+ analysisMs: G(W() - t)
966
997
  };
967
998
  }
968
- if (l.deep && l.flatResults && i.ok) {
969
- let { result: e, ...t } = i, r = {
970
- ...t,
971
- flatResult: it(e)
999
+ if (p.deep && p.flatResults && e.ok) {
1000
+ let { result: t, ...r } = e, i = {
1001
+ ...r,
1002
+ flatResult: pt(t)
972
1003
  };
973
- n.postMessage(r);
974
- } else n.postMessage(i);
1004
+ n.postMessage(i);
1005
+ } else n.postMessage(e);
975
1006
  return !0;
976
- } catch (t) {
977
- return X(n, e, `Could not return the compile result: ${W(t)}`), !1;
1007
+ } catch (e) {
1008
+ return Y(n, l, `Could not return the compile result: ${U(e)}`, {
1009
+ traceId: u,
1010
+ requestId: d,
1011
+ sourceRevision: f
1012
+ }), !1;
978
1013
  }
979
1014
  };
980
1015
  return n.onmessage = (e) => {
981
1016
  let t = e?.data;
982
- if (ht(t)) {
1017
+ if (Tt(t)) {
983
1018
  t.control === "dispose" ? y() : h();
984
1019
  return;
985
1020
  }
986
1021
  if (!t || typeof t.id != "number") return;
987
1022
  if (typeof t.source == "string") {
1023
+ let e = t, i = yt(e.options), a = e.sourcePhase === void 0 ? i?.sourcePhase : e.sourcePhase;
1024
+ if (a !== void 0 && !Ct(a)) {
1025
+ Y(n, e.id, "The requested source phase is not supported: expected \"streaming\" or \"final\"", e);
1026
+ return;
1027
+ }
1028
+ let o = a;
988
1029
  h();
989
- let e = t, i = ut(e.options), a = J(i), o = e.protocol === D, s = x(e.revision), u = G();
1030
+ let s = q(i), u = e.protocol === k, d = x(e.revision), f = W();
990
1031
  try {
991
- if (c !== null && c.optionsKey !== a) try {
1032
+ if (c !== null && c.optionsKey !== s) try {
992
1033
  r.clear();
993
1034
  } catch {}
994
- let t = pt(r, e.source, i), n = K(G() - u);
995
- l = s, c = {
1035
+ let t = St(r, e.source, i, o), n = G(W() - f);
1036
+ l = d, c = {
996
1037
  source: e.source,
997
- revision: s,
1038
+ revision: d,
998
1039
  options: i,
999
- optionsKey: a,
1040
+ optionsKey: s,
1000
1041
  result: t,
1001
- deep: rt(t),
1002
- flatResults: e.flatResults === U
1003
- }, S(e.id, s, n, o, e.includeAuthorAnalysis === !0) && v();
1042
+ deep: ft(t),
1043
+ flatResults: e.flatResults === H,
1044
+ ...o === void 0 ? {} : { sourcePhase: o }
1045
+ }, S(e, d, n, u, e.includeAuthorAnalysis === !0) && v();
1004
1046
  } catch (t) {
1005
- X(n, e.id, W(t));
1047
+ Y(n, e.id, U(t), e);
1006
1048
  }
1007
1049
  return;
1008
1050
  }
1009
1051
  if (t.protocol !== "patch-v1") return;
1010
1052
  h();
1011
1053
  let i = t, a = c, o = (e, t) => {
1012
- mt(n, i.id, e, t, a?.revision);
1054
+ wt(n, i, e, t, a?.revision);
1013
1055
  };
1014
1056
  if (a === null) {
1015
1057
  o("No complete compile is available to patch", "stale-base");
1016
1058
  return;
1017
1059
  }
1060
+ if ((a.sourcePhase ?? "final") !== "final") {
1061
+ o("The baseline was compiled from a streaming snapshot", "phase-mismatch");
1062
+ return;
1063
+ }
1018
1064
  if (typeof i.baseRevision != "number" || i.baseRevision !== a.revision) {
1019
1065
  o("The requested base revision is not current", "stale-base");
1020
1066
  return;
@@ -1023,7 +1069,7 @@ function _t(e, t = {}) {
1023
1069
  o("The options signature changed since the baseline", "options-mismatch");
1024
1070
  return;
1025
1071
  }
1026
- if (!gt(i.edit)) {
1072
+ if (!Et(i.edit)) {
1027
1073
  o("The source edit is invalid", "invalid-edit");
1028
1074
  return;
1029
1075
  }
@@ -1037,26 +1083,27 @@ function _t(e, t = {}) {
1037
1083
  o("The source edit produced an unexpected length", "invalid-edit");
1038
1084
  return;
1039
1085
  }
1040
- let d = x(i.revision), f = G();
1086
+ let d = x(i.revision), f = W();
1041
1087
  try {
1042
- let e = pt(r, u, a.options), t = K(G() - f), o = a.revision, s = a.result;
1088
+ let e = St(r, u, a.options, a.sourcePhase), t = G(W() - f), o = a.revision, s = a.result;
1043
1089
  l = d, c = {
1044
1090
  source: u,
1045
1091
  revision: d,
1046
1092
  options: a.options,
1047
1093
  optionsKey: a.optionsKey,
1048
1094
  result: e,
1049
- deep: rt(e),
1050
- flatResults: a.flatResults
1095
+ deep: ft(e),
1096
+ flatResults: a.flatResults,
1097
+ ...a.sourcePhase === void 0 ? {} : { sourcePhase: a.sourcePhase }
1051
1098
  };
1052
1099
  let p = null, h = 0;
1053
1100
  if (e.ok && s.ok && !c.deep && !a.deep) {
1054
- let t = G();
1055
- p = Xe(s, e), h = K(G() - t);
1101
+ let t = W();
1102
+ p = at(s, e), h = G(W() - t);
1056
1103
  }
1057
1104
  let g = p?.patch ?? null;
1058
1105
  if (g === null) {
1059
- S(i.id, d, t, !0, i.includeAuthorAnalysis === !0) && v();
1106
+ S(i, d, t, !0, i.includeAuthorAnalysis === !0) && v();
1060
1107
  return;
1061
1108
  }
1062
1109
  if (p !== null && p.cost.preferFull) {
@@ -1066,7 +1113,7 @@ function _t(e, t = {}) {
1066
1113
  patchBytes: e.patchBytes,
1067
1114
  ...e.fullBytes === void 0 ? {} : { fullBytes: e.fullBytes }
1068
1115
  };
1069
- S(i.id, d, t, !0, i.includeAuthorAnalysis === !0, n) && v();
1116
+ S(i, d, t, !0, i.includeAuthorAnalysis === !0, n) && v();
1070
1117
  return;
1071
1118
  }
1072
1119
  let _ = {
@@ -1078,25 +1125,31 @@ function _t(e, t = {}) {
1078
1125
  try {
1079
1126
  let s = {
1080
1127
  id: i.id,
1128
+ ...i.traceId === void 0 ? {} : {
1129
+ traceId: i.traceId,
1130
+ requestId: i.requestId,
1131
+ sourceRevision: i.sourceRevision
1132
+ },
1081
1133
  ok: !0,
1082
- protocol: D,
1134
+ protocol: k,
1083
1135
  baseRevision: o,
1084
1136
  revision: d,
1085
1137
  patch: g,
1086
1138
  duration: t,
1087
- incremental: Y(r),
1139
+ incremental: J(r),
1140
+ ...a.sourcePhase === void 0 ? {} : { sourcePhase: a.sourcePhase },
1088
1141
  metrics: _
1089
1142
  };
1090
1143
  if (i.includeAuthorAnalysis === !0) {
1091
- let t = G();
1092
- s.analysis = q(u, a.options, e), _.analysisMs = K(G() - t);
1144
+ let t = W();
1145
+ s.analysis = K(u, a.options, e), _.analysisMs = G(W() - t);
1093
1146
  }
1094
1147
  n.postMessage(s), v();
1095
1148
  } catch (e) {
1096
- X(n, i.id, `Could not return the compile result: ${W(e)}`);
1149
+ Y(n, i.id, `Could not return the compile result: ${U(e)}`, i);
1097
1150
  }
1098
1151
  } catch (e) {
1099
- X(n, i.id, W(e));
1152
+ Y(n, i.id, U(e), i);
1100
1153
  }
1101
1154
  }, {
1102
1155
  dispose: y,
@@ -1107,7 +1160,7 @@ function _t(e, t = {}) {
1107
1160
  };
1108
1161
  }
1109
1162
  // src/local/transport/worker.ts
1110
- function vt(e, t) {
1163
+ function Ot(e, t) {
1111
1164
  if (!e || typeof e != "object") return !1;
1112
1165
  let n = e, r = (e) => e && Number.isSafeInteger(e.start) && Number.isSafeInteger(e.end) && e.start >= 0 && e.end >= e.start && e.end <= t;
1113
1166
  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;
@@ -1119,30 +1172,83 @@ function vt(e, t) {
1119
1172
  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;
1120
1173
  return !0;
1121
1174
  }
1122
- function yt(e, t) {
1123
- let n = ut(t);
1175
+ function kt(e, t, n) {
1176
+ let r = yt(t), i = n === void 0 ? At(t) : n, a = i === "streaming" || i === "final" ? i : void 0, o = i !== void 0 && a === void 0 ? i : void 0;
1124
1177
  return {
1125
1178
  source: e,
1126
- options: n,
1127
- optionsKey: J(n),
1128
- scheduledAt: G()
1179
+ options: r,
1180
+ optionsKey: q(r),
1181
+ scheduledAt: W(),
1182
+ sourcePhase: a === "streaming" ? "streaming" : "final",
1183
+ explicitPhase: i !== void 0,
1184
+ ...o === void 0 ? {} : { invalidPhase: o }
1185
+ };
1186
+ }
1187
+ function At(e) {
1188
+ try {
1189
+ return !e || typeof e != "object" || Array.isArray(e) ? void 0 : e.sourcePhase;
1190
+ } catch {
1191
+ return;
1192
+ }
1193
+ }
1194
+ function X(e, t) {
1195
+ return e.source === t.source && e.optionsKey === t.optionsKey && e.sourcePhase === t.sourcePhase && e.explicitPhase === t.explicitPhase && e.invalidPhase === t.invalidPhase;
1196
+ }
1197
+ function Z(e) {
1198
+ return e.sourcePhase === "streaming" || e.explicitPhase ? { sourcePhase: e.sourcePhase } : {};
1199
+ }
1200
+ function Q(e, t) {
1201
+ return e.explicitPhase ? {
1202
+ ok: !1,
1203
+ diagnostics: [t],
1204
+ status: "failed"
1205
+ } : {
1206
+ ok: !1,
1207
+ diagnostics: [t]
1129
1208
  };
1130
1209
  }
1131
- function Z(e, t) {
1132
- return e.source === t.source && e.optionsKey === t.optionsKey;
1210
+ function jt() {
1211
+ return {
1212
+ ok: !1,
1213
+ status: "failed",
1214
+ diagnostics: [{
1215
+ code: "local.options.invalid",
1216
+ message: "Compile option sourcePhase must be \"streaming\" or \"final\".",
1217
+ severity: "error",
1218
+ range: {
1219
+ start: 0,
1220
+ end: 0
1221
+ },
1222
+ line: 1,
1223
+ column: 1,
1224
+ messageKey: "local.options.invalid.source-phase",
1225
+ phase: "host",
1226
+ recoverable: !1
1227
+ }]
1228
+ };
1133
1229
  }
1134
- function Q(e) {
1230
+ function Mt(e) {
1135
1231
  if (!e || typeof e != "object") return !1;
1136
1232
  let t = e;
1137
1233
  return !(typeof t.ok != "boolean" || !Array.isArray(t.diagnostics) || t.ok && (!t.document || typeof t.document != "object"));
1138
1234
  }
1139
- function bt(e) {
1235
+ function Nt(e) {
1140
1236
  return e.ok && "patch" in e && e.patch !== void 0;
1141
1237
  }
1238
+ var Pt = 160;
1239
+ function Ft(e) {
1240
+ let t = U(e).trim();
1241
+ return t.length === 0 ? "" : t.length > Pt ? `${v(t, 159)}…` : t;
1242
+ }
1142
1243
  function $(e) {
1244
+ let t = Ft(e);
1143
1245
  return {
1144
1246
  code: "local.worker.compile",
1145
- message: `Compilation failed: ${W(e)}`,
1247
+ messageKey: t ? "local.worker.compile.detail" : "local.worker.compile",
1248
+ ...t ? { params: { detail: t } } : {},
1249
+ phase: "worker",
1250
+ recoverable: !1,
1251
+ message: t ? `Compilation failed: ${t}` : "Compilation failed",
1146
1252
  severity: "error",
1147
1253
  range: {
1148
1254
  start: 0,
@@ -1152,7 +1258,7 @@ function $(e) {
1152
1258
  column: 1
1153
1259
  };
1154
1260
  }
1155
- var xt = class {
1261
+ var It = class {
1156
1262
  options;
1157
1263
  delay;
1158
1264
  worker = null;
@@ -1161,11 +1267,18 @@ var xt = class {
1161
1267
  inFlight = null;
1162
1268
  nextId = 1;
1163
1269
  nextRevision = 1;
1270
+ nextSourceRevision = 1;
1271
+ currentSourceRevision = 0;
1164
1272
  pending = !1;
1165
1273
  fallbackSession = null;
1166
1274
  disposed = !1;
1275
+ timeout = null;
1276
+ requestContexts = /* @__PURE__ */ new Map();
1277
+ obsoleteRequestIds = /* @__PURE__ */ new Set();
1278
+ reportedStaleRequestIds = /* @__PURE__ */ new Set();
1167
1279
  baseline = null;
1168
1280
  patchState = "unknown";
1281
+ startupFailure = null;
1169
1282
  constructor(e) {
1170
1283
  this.options = e;
1171
1284
  let t = e.delay;
@@ -1177,20 +1290,26 @@ var xt = class {
1177
1290
  this.handleWorkerFailure(t || "The compile worker encountered an error");
1178
1291
  }, t.onmessageerror = () => this.handleWorkerFailure("The compile worker could not deliver the compile result"), this.worker = t;
1179
1292
  } catch (t) {
1180
- this.worker = null, e.onModeChange?.("fallback", `Could not start the compile worker: ${W(t)}`);
1293
+ this.worker = null, this.startupFailure = Ft(t), e.onModeChange?.("fallback", `Could not start the compile worker: ${U(t)}`);
1181
1294
  }
1182
1295
  }
1183
- schedule(e, t, n) {
1184
- this.disposed || (this.queued = yt(e, t), n && typeof n.baseSource == "string" && gt(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 = {
1296
+ schedule(e, t, n, r) {
1297
+ if (this.disposed) return;
1298
+ let i = {
1299
+ ...kt(e, t, r),
1300
+ sourceRevision: this.nextSourceRevision++,
1301
+ traceId: ne()
1302
+ };
1303
+ this.currentSourceRevision = i.sourceRevision, this.inFlight && !X(this.inFlight.job, i) && this.obsoleteRequestIds.add(this.inFlight.id), this.queued = i, n && typeof n.baseSource == "string" && Et(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 = {
1185
1304
  baseSource: n.baseSource,
1186
1305
  edit: { ...n.edit }
1187
- }), this.clearTimer(), this.timer = setTimeout(() => {
1306
+ }), this.clearTimer(), i.sourcePhase === "streaming" && (this.baseline = null), this.setPending(!0), i.sourcePhase === "streaming" || !i.explicitPhase ? this.timer = setTimeout(() => {
1188
1307
  this.timer = null, this.drain();
1189
- }, this.delay), this.setPending(!0));
1308
+ }, this.delay) : this.drain();
1190
1309
  }
1191
1310
  dispose() {
1192
1311
  if (this.disposed) return;
1193
- this.disposed = !0, this.clearTimer(), this.queued = null, this.inFlight = null, this.resetProtocol();
1312
+ this.disposed = !0, this.inFlight && (this.traceWorker(this.inFlight, "worker-cancel", { status: "disposed" }), this.obsoleteRequestIds.add(this.inFlight.id)), this.timeout !== null && clearTimeout(this.timeout), this.timeout = null, this.clearTimer(), this.queued = null, this.inFlight = null, this.resetProtocol();
1194
1313
  let e = this.worker;
1195
1314
  if (this.worker = null, e) {
1196
1315
  e.onmessage = null, e.onerror = null, e.onmessageerror = null;
@@ -1206,17 +1325,32 @@ var xt = class {
1206
1325
  e === null ? this.setPending(!1) : (this.queued = null, this.compile(e));
1207
1326
  }
1208
1327
  compile(e) {
1328
+ if (e.invalidPhase !== void 0) {
1329
+ this.deliver(e, {
1330
+ source: e.source,
1331
+ result: jt(),
1332
+ duration: 0,
1333
+ mode: this.worker === null ? "fallback" : "worker",
1334
+ ...e.options === void 0 ? {} : { options: e.options },
1335
+ metrics: { queueMs: G(W() - e.scheduledAt) }
1336
+ }), this.finishRun();
1337
+ return;
1338
+ }
1209
1339
  let t = this.worker;
1210
1340
  if (!t) {
1211
1341
  this.compileFallback(e);
1212
1342
  return;
1213
1343
  }
1214
- let n = this.nextId++, r = this.nextRevision++, i = G(), a = this.baseline, o = this.patchState === "enabled" && a !== null && a.optionsKey === e.optionsKey ? {
1344
+ e.sourcePhase === "streaming" && (this.baseline = null);
1345
+ let n = this.nextId++, r = this.nextRevision++, { traceId: i, sourceRevision: a } = e, o = W(), s = this.baseline, c = e.sourcePhase === "final" && this.patchState === "enabled" && s !== null && s.optionsKey === e.optionsKey ? {
1346
+ traceId: i,
1347
+ requestId: n,
1348
+ sourceRevision: a,
1215
1349
  id: n,
1216
- protocol: D,
1217
- baseRevision: a.revision,
1350
+ protocol: k,
1351
+ baseRevision: s.revision,
1218
1352
  revision: r,
1219
- edit: e.editHint?.baseSource === a.source ? e.editHint.edit : F(a.source, e.source) ?? {
1353
+ edit: e.editHint?.baseSource === s.source ? e.editHint.edit : I(s.source, e.source) ?? {
1220
1354
  from: 0,
1221
1355
  to: 0,
1222
1356
  insert: ""
@@ -1224,61 +1358,135 @@ var xt = class {
1224
1358
  targetLength: e.source.length,
1225
1359
  optionsKey: e.optionsKey
1226
1360
  } : {
1361
+ traceId: i,
1362
+ requestId: n,
1363
+ sourceRevision: a,
1227
1364
  id: n,
1228
1365
  source: e.source,
1229
1366
  ...e.options === void 0 ? {} : { options: e.options },
1230
- protocol: D,
1367
+ protocol: k,
1231
1368
  revision: r,
1232
- flatResults: U
1233
- };
1234
- this.inFlight = {
1369
+ flatResults: H,
1370
+ ...e.sourcePhase === "streaming" || e.explicitPhase ? { sourcePhase: e.sourcePhase } : {}
1371
+ }, l = {
1235
1372
  id: n,
1236
1373
  job: e,
1237
- startedAt: i,
1238
- revision: r
1239
- }, this.options.includeAuthorAnalysis && (o.includeAuthorAnalysis = !0);
1240
- try {
1241
- t.postMessage(o);
1242
- } catch (t) {
1243
- this.inFlight = null;
1244
- let n = `Could not send the source to the compile worker: ${W(t)}`, r = this.queued;
1245
- if (r !== null && !Z(r, e)) {
1246
- this.resetProtocol(), this.degrade(n), this.finishRun();
1247
- return;
1374
+ startedAt: o,
1375
+ revision: r,
1376
+ traceId: i,
1377
+ sourceRevision: a
1378
+ };
1379
+ this.inFlight = l;
1380
+ let u = this.options.timeoutMs, d = typeof u == "number" && Number.isFinite(u) && u > 0 ? Math.min(2147483647, Math.ceil(u)) : 3e4;
1381
+ for (this.requestContexts.set(n, {
1382
+ traceId: i,
1383
+ sourceRevision: a
1384
+ }); this.requestContexts.size > 128;) {
1385
+ let e = this.requestContexts.keys().next().value;
1386
+ if (e === void 0) break;
1387
+ this.requestContexts.delete(e), this.obsoleteRequestIds.delete(e), this.reportedStaleRequestIds.delete(e);
1388
+ }
1389
+ if (this.timeout = setTimeout(() => {
1390
+ if (this.inFlight?.id !== n) return;
1391
+ let e = {
1392
+ ...O("local.worker.timeout", {
1393
+ timeoutMs: d,
1394
+ requestId: n,
1395
+ sourceRevision: a
1396
+ }),
1397
+ phase: "worker"
1398
+ };
1399
+ this.obsoleteRequestIds.add(n), this.handleWorkerFailure(e.message, e);
1400
+ }, d), this.traceWorker(l, "worker-request"), !(this.disposed || this.inFlight !== l)) {
1401
+ this.options.includeAuthorAnalysis && (c.includeAuthorAnalysis = !0);
1402
+ try {
1403
+ t.postMessage(c);
1404
+ } catch (e) {
1405
+ this.obsoleteRequestIds.add(n), this.handleWorkerFailure(`Could not send the source to the compile worker: ${U(e)}`);
1248
1406
  }
1249
- r !== null && (this.queued = null, this.clearTimer()), this.resetProtocol(), this.degrade(n), this.compileFallback(e);
1250
1407
  }
1251
1408
  }
1252
1409
  compileFallback(e) {
1253
1410
  if (this.disposed) return;
1254
- let t = G(), n;
1411
+ e.sourcePhase === "streaming" && (this.baseline = null);
1412
+ let t = W(), { traceId: n, sourceRevision: r } = e;
1413
+ if (!this.isCurrentJob(e) || (T(this.options.observer, {
1414
+ type: "compile-start",
1415
+ traceId: n,
1416
+ sourceRevision: r,
1417
+ timestamp: Date.now(),
1418
+ status: "fallback"
1419
+ }), !this.isCurrentJob(e))) {
1420
+ this.finishRun();
1421
+ return;
1422
+ }
1423
+ let i;
1255
1424
  try {
1256
- let t = this.options.fallbackCompile ?? ((e, t) => (this.fallbackSession ??= T(), this.fallbackSession.compile(e, t)));
1257
- n = e.options === void 0 ? t(e.source) : t(e.source, e.options);
1258
- } catch (e) {
1259
- n = {
1260
- ok: !1,
1261
- diagnostics: [$(e)]
1262
- };
1425
+ let t = this.options.fallbackCompile ?? ((e, t, n) => (this.fallbackSession ??= D(), this.fallbackSession.compile(e, t, n)));
1426
+ i = e.explicitPhase ? t(e.source, e.options, e.sourcePhase) : e.options === void 0 ? t(e.source) : t(e.source, e.options);
1427
+ } catch (t) {
1428
+ i = Q(e, $(t));
1263
1429
  }
1264
- this.deliver({
1265
- source: e.source,
1266
- result: n,
1267
- duration: K(G() - t),
1268
- mode: "fallback",
1269
- ...this.options.includeAuthorAnalysis ? { analysis: q(e.source, e.options, n) } : {},
1270
- ...e.options === void 0 ? {} : { options: e.options },
1271
- metrics: { queueMs: K(t - e.scheduledAt) }
1272
- }), this.finishRun();
1430
+ let a = G(W() - t);
1431
+ if (!this.isCurrentJob(e)) this.finishRun();
1432
+ else {
1433
+ if (this.startupFailure !== null) {
1434
+ let t = this.startupFailure;
1435
+ if (this.startupFailure = null, T(this.options.observer, {
1436
+ type: "worker-error",
1437
+ traceId: n,
1438
+ sourceRevision: r,
1439
+ timestamp: Date.now(),
1440
+ status: "failed",
1441
+ code: "local.worker.startup",
1442
+ ...t ? { detail: t } : {}
1443
+ }), !this.isCurrentJob(e)) {
1444
+ this.finishRun();
1445
+ return;
1446
+ }
1447
+ }
1448
+ T(this.options.observer, {
1449
+ type: "compile-end",
1450
+ traceId: n,
1451
+ sourceRevision: r,
1452
+ timestamp: Date.now(),
1453
+ durationMs: a,
1454
+ status: i.ok ? "ok" : "failed"
1455
+ }), this.isCurrentJob(e) && this.deliver(e, {
1456
+ source: e.source,
1457
+ result: i,
1458
+ duration: a,
1459
+ mode: "fallback",
1460
+ ...this.options.includeAuthorAnalysis ? { analysis: K(e.source, e.options, i) } : {},
1461
+ ...e.options === void 0 ? {} : { options: e.options },
1462
+ ...Z(e),
1463
+ metrics: { queueMs: G(t - e.scheduledAt) }
1464
+ }), this.finishRun();
1465
+ }
1466
+ }
1467
+ isCurrentJob(e) {
1468
+ return !this.disposed && e.sourceRevision === this.currentSourceRevision;
1273
1469
  }
1274
1470
  receive(e) {
1275
1471
  if (this.disposed) return;
1276
1472
  let t = this.inFlight;
1277
- if (!t || !e || e.id !== t.id) return;
1473
+ if (!e) return;
1474
+ if (t && e.id === t.id && (e.requestId !== void 0 && e.requestId !== t.id || e.traceId !== void 0 && e.traceId !== t.traceId || e.sourceRevision !== void 0 && e.sourceRevision !== t.sourceRevision)) {
1475
+ this.reportStale(t.id, t.traceId, t.sourceRevision, this.queued?.sourceRevision), this.handleWorkerFailure("The compile worker returned a response with a mismatched request context.");
1476
+ return;
1477
+ }
1478
+ if (!t || e.id !== t.id) {
1479
+ if (Number.isSafeInteger(e.id) && e.id > 0 && this.obsoleteRequestIds.has(e.id)) {
1480
+ let t = this.requestContexts.get(e.id);
1481
+ t && this.reportStale(e.id, t.traceId, t.sourceRevision, this.queued?.sourceRevision);
1482
+ }
1483
+ return;
1484
+ }
1485
+ this.timeout !== null && clearTimeout(this.timeout), this.timeout = null;
1278
1486
  let n, r = 0;
1279
1487
  if (e.ok && "flatResult" in e) {
1280
- let t = G(), i = at(e.flatResult);
1281
- r = K(G() - t), n = Q(i) ? {
1488
+ let t = W(), i = mt(e.flatResult);
1489
+ r = G(W() - t), n = Mt(i) ? {
1282
1490
  ...e,
1283
1491
  result: i
1284
1492
  } : {
@@ -1289,14 +1497,14 @@ var xt = class {
1289
1497
  };
1290
1498
  } else n = e;
1291
1499
  this.inFlight = null;
1292
- let i = t.job, a = K(G() - t.startedAt), o = K(t.startedAt - i.scheduledAt), s = null, c = r, l = null, u = "worker", d;
1500
+ let i = t.job, a = G(W() - t.startedAt), o = G(t.startedAt - i.scheduledAt), s = null, c = r, l = null, u = "worker", d;
1293
1501
  if (n.ok) {
1294
- if (bt(n)) {
1295
- let e = G(), t = this.applyResponsePatch(i, n);
1296
- c = K(G() - e), t !== null && (s = t, d = n.revision);
1502
+ if (Nt(n)) {
1503
+ let e = W(), t = this.applyResponsePatch(i, n);
1504
+ c = G(W() - e), t !== null && (s = t, d = n.revision);
1297
1505
  } else {
1298
1506
  let e = n;
1299
- Q(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 ? {
1507
+ Mt(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 ? {
1300
1508
  source: i.source,
1301
1509
  optionsKey: i.optionsKey,
1302
1510
  revision: e.revision,
@@ -1304,74 +1512,108 @@ var xt = class {
1304
1512
  } : null) : (this.patchState = "legacy", this.baseline = null)) : l = "The compile worker returned an invalid result";
1305
1513
  }
1306
1514
  } else n.retryFull !== !0 && (l = n.message);
1307
- let f = this.queued, p = f !== null && !Z(f, i);
1308
- 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({
1309
- source: i.source,
1310
- result: {
1311
- ok: !1,
1312
- diagnostics: [$("The compile worker could not apply an incremental result patch")]
1313
- },
1314
- duration: 0,
1315
- mode: u,
1316
- ...i.options === void 0 ? {} : { options: i.options },
1317
- metrics: {
1318
- queueMs: o,
1319
- roundTripMs: a,
1320
- ...c > 0 ? { applyMs: c } : {}
1321
- }
1322
- })), this.finishRun()) : (p || this.deliver({
1323
- source: i.source,
1324
- result: {
1325
- ok: !1,
1326
- diagnostics: [$(l)]
1327
- },
1328
- duration: 0,
1329
- mode: u,
1330
- ...i.options === void 0 ? {} : { options: i.options },
1331
- metrics: {
1332
- queueMs: o,
1333
- roundTripMs: a
1515
+ let f = this.queued, p = f !== null && !X(f, i);
1516
+ if (l === null ? this.traceWorker(t, "worker-response", {
1517
+ durationMs: a,
1518
+ status: s ? s.ok ? "ok" : "failed" : l ? "failed" : "retry"
1519
+ }) : this.traceWorker(t, "worker-error", {
1520
+ durationMs: a,
1521
+ status: "failed",
1522
+ code: "local.worker.compile"
1523
+ }), !this.disposed) {
1524
+ if (p && (this.obsoleteRequestIds.add(t.id), this.reportStale(t.id, t.traceId, t.sourceRevision, f.sourceRevision)), f !== null && !p && this.queued === f && (this.queued = null, this.clearTimer(), this.currentSourceRevision = i.sourceRevision), s !== null) p || this.deliver(i, {
1525
+ source: i.source,
1526
+ result: s,
1527
+ duration: G(n.ok ? n.duration : 0),
1528
+ mode: u,
1529
+ ...n.ok && this.options.includeAuthorAnalysis && Ot(n.analysis, i.source.length) ? { analysis: n.analysis } : {},
1530
+ ...i.options === void 0 ? {} : { options: i.options },
1531
+ ...Z(i),
1532
+ metrics: {
1533
+ queueMs: o,
1534
+ roundTripMs: a,
1535
+ ...c > 0 ? { applyMs: c } : {},
1536
+ ...n.ok && n.metrics ? { worker: n.metrics } : {}
1537
+ },
1538
+ ...d === void 0 ? {} : { revision: d }
1539
+ }), this.finishRun();
1540
+ else if (l !== null) p || this.deliver(i, {
1541
+ source: i.source,
1542
+ result: Q(i, $(l)),
1543
+ duration: 0,
1544
+ mode: u,
1545
+ ...i.options === void 0 ? {} : { options: i.options },
1546
+ ...Z(i),
1547
+ metrics: {
1548
+ queueMs: o,
1549
+ roundTripMs: a
1550
+ }
1551
+ }), this.finishRun();
1552
+ else {
1553
+ if (p) this.inFlight === null && this.resetProtocol();
1554
+ else {
1555
+ let e = this.recoverWithFullResult(i);
1556
+ if (e === "dispatched") return;
1557
+ e !== "abandoned" && (this.patchState = "disabled", this.baseline = null, this.deliver(i, {
1558
+ source: i.source,
1559
+ result: Q(i, $("The compile worker could not apply an incremental result patch")),
1560
+ duration: 0,
1561
+ mode: u,
1562
+ ...i.options === void 0 ? {} : { options: i.options },
1563
+ ...Z(i),
1564
+ metrics: {
1565
+ queueMs: o,
1566
+ roundTripMs: a,
1567
+ ...c > 0 ? { applyMs: c } : {}
1568
+ }
1569
+ }));
1570
+ }
1571
+ this.finishRun();
1334
1572
  }
1335
- }), this.finishRun()) : (p || this.deliver({
1336
- source: i.source,
1337
- result: s,
1338
- duration: K(n.ok ? n.duration : 0),
1339
- mode: u,
1340
- ...n.ok && this.options.includeAuthorAnalysis && vt(n.analysis, i.source.length) ? { analysis: n.analysis } : {},
1341
- ...i.options === void 0 ? {} : { options: i.options },
1342
- metrics: {
1343
- queueMs: o,
1344
- roundTripMs: a,
1345
- ...c > 0 ? { applyMs: c } : {},
1346
- ...n.ok && n.metrics ? { worker: n.metrics } : {}
1347
- },
1348
- ...d === void 0 ? {} : { revision: d }
1349
- }), this.finishRun());
1573
+ }
1350
1574
  }
1351
1575
  applyResponsePatch(e, t) {
1576
+ if (e.sourcePhase !== "final") return null;
1352
1577
  let n = this.baseline;
1353
1578
  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;
1354
- let r = nt(n.result, t.patch);
1355
- return r === null || !r.ok || r.document.source !== e.source ? null : (this.baseline = {
1579
+ let r = dt(n.result, t.patch);
1580
+ if (r === null || !r.ok || r.document.source !== e.source) return null;
1581
+ let i;
1582
+ if (e.sourcePhase === "final" && e.explicitPhase) i = r.recoveries === void 0 ? {
1583
+ ...r,
1584
+ status: "valid"
1585
+ } : {
1586
+ ...r,
1587
+ status: "recovered"
1588
+ };
1589
+ else if (r.ok && r.status !== void 0) {
1590
+ let e = { ...r };
1591
+ delete e.status, i = e;
1592
+ } else i = r;
1593
+ return this.baseline = {
1356
1594
  source: e.source,
1357
1595
  optionsKey: e.optionsKey,
1358
1596
  revision: t.revision,
1359
- result: r
1360
- }, r);
1597
+ result: i
1598
+ }, i;
1361
1599
  }
1362
1600
  recoverWithFullResult(e) {
1363
- if (this.worker === null || (e.recovery ?? 0) >= 1) return !1;
1364
- let t = this.queued;
1365
- return t !== null && !Z(t, e) ? !1 : (t !== null && (this.queued = null, this.clearTimer()), this.resetProtocol(), this.compile({
1601
+ return this.worker === null || (e.recovery ?? 0) >= 1 ? "spent" : this.disposed || this.inFlight !== null || !this.isCurrentJob(e) ? "abandoned" : (this.resetProtocol(), this.compile({
1366
1602
  ...e,
1367
1603
  recovery: (e.recovery ?? 0) + 1
1368
- }), !0);
1604
+ }), "dispatched");
1369
1605
  }
1370
- handleWorkerFailure(e) {
1606
+ handleWorkerFailure(e, t = {
1607
+ ...O("local.worker.error"),
1608
+ recoverable: !0
1609
+ }) {
1371
1610
  if (this.disposed) return;
1372
- this.resetProtocol(), this.degrade(e);
1373
- let t = this.inFlight;
1374
- this.inFlight = null, t && (this.queued === null || Z(this.queued, t.job)) && (this.queued !== null && (this.queued = null, this.clearTimer()), this.compileFallback(t.job)), this.finishRun();
1611
+ this.timeout !== null && clearTimeout(this.timeout), this.timeout = null, this.resetProtocol();
1612
+ let n = this.inFlight;
1613
+ this.inFlight = null, n && this.obsoleteRequestIds.add(n.id), this.degrade(e), !this.disposed && (n && this.traceWorker(n, t.code === "local.worker.timeout" ? "worker-timeout" : "worker-error", {
1614
+ code: t.code,
1615
+ durationMs: G(W() - n.startedAt)
1616
+ }), !this.disposed && (w(this.options.observer, t), !this.disposed && (n && (this.queued === null || X(this.queued, n.job)) && (this.queued !== null && (this.queued = null, this.clearTimer(), this.currentSourceRevision = n.job.sourceRevision), this.compileFallback(n.job)), this.finishRun())));
1375
1617
  }
1376
1618
  degrade(e) {
1377
1619
  let t = this.worker;
@@ -1389,14 +1631,48 @@ var xt = class {
1389
1631
  finishRun() {
1390
1632
  this.disposed || (this.drain(), !this.disposed && this.setPending(this.timer !== null || this.inFlight !== null || this.queued !== null));
1391
1633
  }
1392
- deliver(e) {
1393
- if (this.disposed) return;
1394
- let t = this.baseline !== null && this.baseline.result === e.result, n = this.options.shareResults === !0 || !t ? e.result : P(e.result);
1395
- this.options.onResult({
1396
- ...e,
1397
- result: n
1634
+ deliver(e, t) {
1635
+ if (!this.isCurrentJob(e)) return;
1636
+ let n = this.baseline !== null && this.baseline.result === t.result, r = this.options.shareResults === !0 || !n ? t.result : F(t.result);
1637
+ for (let t of [...r.diagnostics, ...r.transientDiagnostics ?? []]) {
1638
+ if (!this.isCurrentJob(e)) return;
1639
+ w(this.options.observer, t);
1640
+ }
1641
+ this.isCurrentJob(e) && this.options.onResult({
1642
+ ...t,
1643
+ result: r
1644
+ });
1645
+ }
1646
+ traceWorker(e, t, n = {}) {
1647
+ T(this.options.observer, {
1648
+ type: t,
1649
+ traceId: e.traceId,
1650
+ requestId: e.id,
1651
+ sourceRevision: e.sourceRevision,
1652
+ timestamp: Date.now(),
1653
+ ...n
1398
1654
  });
1399
1655
  }
1656
+ reportStale(e, t, n, r) {
1657
+ if (this.disposed || this.reportedStaleRequestIds.has(e)) return;
1658
+ this.reportedStaleRequestIds.add(e);
1659
+ let i = "local.worker.stale-response", a = {
1660
+ ...O(i, {
1661
+ requestId: e,
1662
+ sourceRevision: n,
1663
+ ...r === void 0 ? {} : { currentRevision: r }
1664
+ }),
1665
+ phase: "worker"
1666
+ };
1667
+ T(this.options.observer, {
1668
+ type: "worker-stale-response",
1669
+ traceId: t,
1670
+ requestId: e,
1671
+ sourceRevision: n,
1672
+ timestamp: Date.now(),
1673
+ code: i
1674
+ }), !this.disposed && w(this.options.observer, a);
1675
+ }
1400
1676
  setPending(e) {
1401
1677
  this.pending !== e && (this.pending = e, this.options.onPendingChange?.(e));
1402
1678
  }
@@ -1404,4 +1680,4 @@ var xt = class {
1404
1680
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
1405
1681
  }
1406
1682
  };
1407
- export { h as DEFAULT_LOCAL_THEME, ot as LOCAL_COMPILE_DELAY_MS, st 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, xt as LocalCompileScheduler, ie as LocalCompileSession, g as LocalExpressionError, Te as SHAREABLE_HTML_FORMAT, Se as SHAREABLE_HTML_FORMAT_V2, C as analyzeLocalSource, nt as applyLocalResultPatch, Ce as applyLocalState, oe as applyLocalStateRetention, I 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, Ye 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, J 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, _t as startLocalCompileWorker, se as updateLocalRuntime };
1683
+ export { g as DEFAULT_LOCAL_THEME, ht as LOCAL_COMPILE_DELAY_MS, gt as LOCAL_COMPILE_PREPARATION_DELAY_MS, a as LOCAL_DIAGNOSTIC_CODES, p as LOCAL_OBSERVABILITY_MESSAGES, k as LOCAL_RESULT_PATCH_PROTOCOL, xe as LOCAL_STATE_FORMAT, C as LOCAL_SYNTAX_VERSION, d as LOCAL_THEME_PROTOCOL, It as LocalCompileScheduler, ce as LocalCompileSession, y as LocalExpressionError, ke as SHAREABLE_HTML_FORMAT, Ee as SHAREABLE_HTML_FORMAT_V2, se as analyzeLocalSource, dt as applyLocalResultPatch, De as applyLocalState, le as applyLocalStateRetention, qe as applySourceEdit, Ue as checkLocalUpgrade, b as compileExpression, $ as compileFailureDiagnostic, n as compileLatex, re as compileLocal, t as compilePlotFormula, ae as completeLocalSource, i as countLocalCodePoints, Me as createDiagnosticReport, D as createLocalCompileSession, O as createLocalObservabilityDiagnostic, de as createLocalRuntime, Te as createLocalStateFile, ne as createLocalTraceId, Oe as createShareableHtml, I as diffSourceEdit, w as emitLocalDiagnostic, T as emitLocalTrace, it as encodeLocalResultPatch, Ce as exportLocalState, h as formatLocalDiagnostic, oe as formatLocalSource, u as formatObservabilityMessage, e as implicitGridSize, Se as importLocalState, Be as inspectLocalSourceVersion, o as isLocalDiagnosticCode, m as isLocalThemeName, te as localCompileOptionsKey, _ as localDiagnosticTemplate, s as localDiagnosticTemplateKeys, me as localSourceDigest, q as localWorkerOptionsKey, We as migrateLocalSource, pe as notifyLocalRuntime, ye as parseLocalState, fe as planLocalStateRetention, r as plotFormulaKind, ie as renameLocalBinding, Ne as resolveLocalComponentStateExport, Ae as resolveLocalState, we as resolveLocalStateBaseline, c as resolveLocalTheme, ve as sampleImplicit, ge as sampleParametric, _e as samplePlot, he as samplePolar, be as serializeForScript, je as serializeLocalState, Dt as startLocalCompileWorker, ue as updateLocalRuntime };