reactive-md 0.9.1 → 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 (292) hide show
  1. package/CHANGELOG-ch.md +333 -319
  2. package/CHANGELOG.md +334 -320
  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/bin/reactive-md.mjs +39 -39
  11. package/cli/args.mjs +263 -263
  12. package/cli/assets.mjs +395 -395
  13. package/cli/build.mjs +445 -445
  14. package/cli/check.mjs +444 -444
  15. package/cli/document.mjs +130 -130
  16. package/cli/errors.mjs +61 -61
  17. package/cli/fs-utils.mjs +133 -133
  18. package/cli/glob.mjs +203 -203
  19. package/cli/help.mjs +323 -323
  20. package/cli/init.mjs +1577 -1577
  21. package/cli/lint.mjs +177 -177
  22. package/cli/main.mjs +65 -65
  23. package/cli/migrate.mjs +368 -368
  24. package/cli/package-loader.mjs +41 -41
  25. package/cli/package.mjs +211 -211
  26. package/dist-library/{LocalDocumentView-sthUP0ct.js → LocalDocumentView-BuqgJZEY.js} +11 -11
  27. package/dist-library/{LocalDocumentViewCore-GiWV3bey.js → LocalDocumentViewCore-DXE0I0Qc.js} +210 -209
  28. package/dist-library/{LocalReactiveDocumentCore-ZjQSGyHE.js → LocalReactiveDocumentCore-CWBe4Mm5.js} +8 -8
  29. package/dist-library/{authoring-Dsune4Hy.js → authoring-Ci_KzJ0q.js} +53 -53
  30. package/dist-library/{compile-wUv8KEge.js → compile-Dx6Uw3D9.js} +11 -11
  31. package/dist-library/{compiler-core-As_m-MNm.js → compiler-core-DDDdvuLy.js} +883 -818
  32. package/dist-library/compiler-dxLPB9Ym.js +86 -0
  33. package/dist-library/{component-state-C52ZFJGl.js → component-state-BRwvTV0d.js} +15 -14
  34. package/dist-library/component-state-CwKX_SN5.js +763 -0
  35. package/dist-library/{config-BadfhjdP.js → config-DXLvctiZ.js} +68 -66
  36. package/dist-library/config-validation-D3D7Dy2J.js +586 -0
  37. package/dist-library/{controls-CcT6n7k_.js → controls-DoZyLCrV.js} +3 -3
  38. package/dist-library/{coordinate-CWS9p5q_.js → coordinate-B1VFK9fd.js} +2 -2
  39. package/dist-library/{data-table-Bgccxd7h.js → data-table-8-3F15Jf.js} +3 -3
  40. package/dist-library/{default-components-BwQf0oP-.js → default-components-s21NevON.js} +29 -28
  41. package/dist-library/{display-B-VhqVND.js → display-B_uutKkN.js} +1 -1
  42. package/dist-library/{config-validation-F47AcE6o.js → document-theme-C8J6UyNO.js} +193 -731
  43. package/dist-library/{export-BqVmTXm8.js → export-CIAIPBov.js} +35 -34
  44. package/dist-library/{gallery-CY6mTx8i.js → gallery-Dv1rOvL0.js} +1 -1
  45. package/dist-library/{html-CNT4KD-2.js → html-Cr4CBwAH.js} +42 -41
  46. package/dist-library/identity-BUx0Q_-d.js +40 -0
  47. package/dist-library/{incremental-Dv0FSp_U.js → incremental-9nx92u9c.js} +12 -10
  48. package/dist-library/{layout-C0YlEPGr.js → layout-BBB2VF0S.js} +1 -1
  49. package/dist-library/{mount-preset-KxvtKgJb.js → mount-preset-DMZ5wd3t.js} +3 -3
  50. package/dist-library/observability-4KqXhIEU.js +421 -0
  51. package/dist-library/observability-core-Bcu7vpnl.js +24 -0
  52. package/dist-library/{options-1aDLK7JY.js → options-BBp9IcHm.js} +4 -4
  53. package/dist-library/{package-core-WFK1RhAZ.js → package-core-K5xesGqy.js} +30 -29
  54. package/dist-library/{parser-standard-Yuf3A_VI.js → parser-standard-CBA1-hdG.js} +352 -352
  55. package/dist-library/{plugin-packs-B1XPWcFs.js → plugin-packs-Bh1HhLym.js} +3 -2
  56. package/dist-library/preset-core-DeZPA8IE.js +1298 -0
  57. package/dist-library/react-0DCh-Mar.js +7 -0
  58. package/dist-library/reactive-md-authoring.js +19 -19
  59. package/dist-library/reactive-md-build.js +48 -10
  60. package/dist-library/reactive-md-compiler-standard.js +6 -6
  61. package/dist-library/reactive-md-compiler.js +3 -3
  62. package/dist-library/reactive-md-default-packs.js +3 -2
  63. package/dist-library/reactive-md-default-preset.js +3 -2
  64. package/dist-library/reactive-md-export.js +4 -4
  65. package/dist-library/reactive-md-minimal-preset.js +2 -2
  66. package/dist-library/reactive-md-minimal-react-preset.js +3 -3
  67. package/dist-library/reactive-md-observability.js +4 -0
  68. package/dist-library/reactive-md-plugin-chart.js +3 -3
  69. package/dist-library/reactive-md-plugin-data.js +5 -5
  70. package/dist-library/reactive-md-plugin-diagram.js +4 -4
  71. package/dist-library/reactive-md-plugin-forms.js +4 -4
  72. package/dist-library/reactive-md-plugin-gallery.js +3 -3
  73. package/dist-library/reactive-md-plugin-navigation.js +3 -3
  74. package/dist-library/reactive-md-plugin-network.js +4 -3
  75. package/dist-library/reactive-md-plugin-plot.js +4 -4
  76. package/dist-library/reactive-md-print.css +304 -304
  77. package/dist-library/reactive-md-react-minimal.js +4 -4
  78. package/dist-library/reactive-md-react-server.js +6 -6
  79. package/dist-library/reactive-md-react-unstyled.js +11 -11
  80. package/dist-library/reactive-md-react.js +11 -11
  81. package/dist-library/reactive-md-runtime-browser.js +2 -1
  82. package/dist-library/reactive-md-runtime.js +4 -3
  83. package/dist-library/reactive-md-sdk.js +8 -7
  84. package/dist-library/reactive-md-standalone-configured.js +2 -2
  85. package/dist-library/reactive-md-standalone-host.js +2 -2
  86. package/dist-library/reactive-md-testing-browser.js +2 -2
  87. package/dist-library/reactive-md-testing-react.js +6 -6
  88. package/dist-library/reactive-md-testing.js +5 -5
  89. package/dist-library/reactive-md.js +556 -367
  90. package/dist-library/{registry-B9NGct4d.js → registry-D6OGkOcX.js} +3 -3
  91. package/dist-library/{registry-core-Bbad9Bm2.js → registry-core-C9xOunaw.js} +1 -1
  92. package/dist-library/{resources-D2GDQS0p.js → resources-B0x_w3s9.js} +71 -46
  93. package/dist-library/{runtime-B2fxeveq.js → runtime-BDnnimPA.js} +17 -16
  94. package/dist-library/{runtime-kcA7bG7G.js → runtime-BpQdZmFI.js} +311 -305
  95. package/dist-library/{schema-BufhKUSM.js → schema-BryM_VRW.js} +14 -14
  96. package/dist-library/{sdk-core-BoJT1SIt.js → sdk-core-ChslheKs.js} +33 -32
  97. package/dist-library/{session-core-nmJHuR9c.js → session-core-dxQCJBNa.js} +15 -14
  98. package/dist-library/{shareable-DpbE-59H.js → shareable-B8xMoGEa.js} +179 -176
  99. package/dist-library/types/build/diagnostics.d.ts +1 -1
  100. package/dist-library/types/local/index.d.ts +6 -0
  101. package/dist-library/types/local/observability-codes.d.ts +2 -0
  102. package/dist-library/types/local/observability-core.d.ts +25 -0
  103. package/dist-library/types/local/observability-messages.d.ts +6 -0
  104. package/dist-library/types/local/observability.d.ts +43 -0
  105. package/dist-library/types/local/parsing/parser-internals.d.ts +2 -1
  106. package/dist-library/types/local/transport/worker.d.ts +52 -1
  107. package/dist-library/types/local/types.d.ts +8 -0
  108. package/dist-library/types/observability.d.ts +7 -0
  109. package/dist-library/{types-BeNtPqdY.js → types-Ib5kSScP.js} +1 -1
  110. package/dist-library/types-daDo2c_w.js +3 -0
  111. package/dist-library/{validation-BEBA_HvS.js → validation-B3RI0xOk.js} +251 -249
  112. package/dist-library/version-DAxuGOG2.js +147 -0
  113. package/dist-library/{visual-frame-CyV1FXzs.js → visual-frame-_rcd5HUv.js} +1 -1
  114. package/dist-library/{visuals-BZbZYA7w.js → visuals-DkDhNdEZ.js} +17 -17
  115. package/dist-standalone/reactive-md-standalone.js +118 -118
  116. package/docs/README-ch.md +101 -95
  117. package/docs/README.md +101 -95
  118. package/docs/compatibility/api-stability-ch.md +25 -0
  119. package/docs/compatibility/api-stability-en.md +25 -0
  120. package/docs/compatibility/compatibility-ch.md +146 -129
  121. package/docs/compatibility/compatibility-en.md +146 -129
  122. package/docs/compatibility/compatibility-manifest.schema.json +161 -0
  123. package/docs/compatibility/deprecation-ch.md +21 -0
  124. package/docs/compatibility/deprecation-en.md +21 -0
  125. package/docs/compatibility/source-versioning-ch.md +162 -162
  126. package/docs/compatibility/source-versioning-en.md +162 -162
  127. package/docs/compatibility/support-matrix-ch.md +108 -0
  128. package/docs/compatibility/support-matrix-en.md +108 -0
  129. package/docs/development/component-development-ch.md +66 -66
  130. package/docs/development/component-development-en.md +66 -66
  131. package/docs/development/component-development-reference-ch.md +253 -253
  132. package/docs/development/component-development-reference-en.md +238 -238
  133. package/docs/development/component-protocol-ch.md +748 -748
  134. package/docs/development/component-protocol-en.md +750 -750
  135. package/docs/development/extension-tutorial-ch.md +308 -308
  136. package/docs/development/extension-tutorial-en.md +308 -308
  137. package/docs/development/performance-overview-ch.md +422 -422
  138. package/docs/development/performance-overview-en.md +422 -422
  139. package/docs/guides/local-guide-ch.md +532 -532
  140. package/docs/guides/local-guide-en.md +532 -532
  141. package/docs/integration/author-tools-ch.md +64 -64
  142. package/docs/integration/author-tools-en.md +64 -64
  143. package/docs/integration/compiler-ch.md +49 -49
  144. package/docs/integration/compiler-en.md +36 -36
  145. package/docs/integration/directory-discovery-en.md +1 -1
  146. package/docs/integration/editor-ch.md +295 -295
  147. package/docs/integration/editor-en.md +303 -303
  148. package/docs/integration/extension-sdk-ch.md +394 -394
  149. package/docs/integration/extension-sdk-en.md +379 -379
  150. package/docs/integration/local-integration-ch.md +646 -646
  151. package/docs/integration/local-integration-en.md +662 -662
  152. package/docs/integration/shareable-export-ch.md +307 -307
  153. package/docs/integration/shareable-export-en.md +309 -309
  154. package/docs/reference/diagnostics-counting-ch.md +104 -104
  155. package/docs/reference/diagnostics-counting-en.md +104 -104
  156. package/docs/reference/html-compatibility-ch.md +93 -93
  157. package/docs/reference/html-compatibility-en.md +95 -95
  158. package/docs/reference/local-interaction-syntax-ch.md +724 -724
  159. package/docs/reference/local-interaction-syntax-en.md +722 -722
  160. package/docs/reference/public-api-ch.md +33 -4
  161. package/docs/reference/public-api-en.md +33 -4
  162. package/docs/reference/theme-protocol-ch.md +198 -198
  163. package/docs/reference/theme-protocol-en.md +217 -217
  164. package/docs/releases/release-0.4.0-ch.md +91 -91
  165. package/docs/releases/release-0.4.0-en.md +91 -91
  166. package/docs/releases/release-0.4.1-ch.md +25 -25
  167. package/docs/releases/release-0.4.1-en.md +25 -25
  168. package/docs/releases/release-0.5.0-ch.md +43 -43
  169. package/docs/releases/release-0.5.0-en.md +43 -43
  170. package/docs/releases/release-0.5.1-ch.md +41 -41
  171. package/docs/releases/release-0.5.1-en.md +41 -41
  172. package/docs/releases/release-0.5.2-ch.md +37 -37
  173. package/docs/releases/release-0.5.2-en.md +37 -37
  174. package/docs/releases/release-0.5.3-ch.md +26 -26
  175. package/docs/releases/release-0.5.3-en.md +26 -26
  176. package/docs/releases/release-0.6.0-ch.md +59 -59
  177. package/docs/releases/release-0.6.0-en.md +59 -59
  178. package/docs/releases/release-0.6.1-ch.md +29 -29
  179. package/docs/releases/release-0.6.1-en.md +29 -29
  180. package/docs/releases/release-0.7.0-ch.md +86 -86
  181. package/docs/releases/release-0.7.0-en.md +86 -86
  182. package/docs/releases/release-0.9.2-ch.md +33 -0
  183. package/docs/releases/release-0.9.2-en.md +33 -0
  184. package/examples/component-package/README-ch.md +101 -101
  185. package/examples/component-package/README.md +133 -133
  186. package/examples/conformance/README-ch.md +55 -55
  187. package/examples/conformance/README.md +55 -55
  188. package/examples/conformance/component-protocol-1.json +482 -482
  189. package/examples/conformance/component-protocol-1.schema.json +76 -76
  190. package/examples/conformance/local-draft-1.json +50 -50
  191. package/examples/conformance/local-draft-2.json +212 -212
  192. package/examples/game-2048-package/LICENSE +21 -21
  193. package/examples/game-2048-package/NOTICES.md +11 -11
  194. package/examples/game-2048-package/README-ch.md +91 -91
  195. package/examples/game-2048-package/README.md +98 -98
  196. package/examples/game-2048-package/package.json +35 -35
  197. package/examples/game-2048-package/sample/document.reactive.md +17 -17
  198. package/examples/game-2048-package/scripts/build-export.mjs +44 -44
  199. package/examples/game-2048-package/scripts/build.mjs +130 -130
  200. package/examples/game-2048-package/scripts/verify.mjs +180 -180
  201. package/examples/game-2048-package/src/component.css +161 -161
  202. package/examples/game-2048-package/src/components.tsx +326 -326
  203. package/examples/game-2048-package/src/game-engine.ts +228 -228
  204. package/examples/game-2048-package/src/harness.tsx +34 -34
  205. package/examples/game-2048-package/src/manifest.ts +85 -85
  206. package/examples/game-2048-package/src/node-entry.ts +30 -30
  207. package/examples/game-2048-package/src/sample.ts +4 -4
  208. package/examples/game-2048-package/tsconfig.json +15 -15
  209. package/examples/integration/README-ch.md +82 -82
  210. package/examples/integration/README.md +82 -82
  211. package/examples/integration/core/index.mjs +32 -32
  212. package/examples/integration/extension-sdk/README-ch.md +24 -24
  213. package/examples/integration/extension-sdk/README.md +24 -24
  214. package/examples/integration/worker/index.html +19 -19
  215. package/examples/integration/worker/main.js +61 -61
  216. package/examples/integration/worker/package.json +13 -13
  217. package/examples/integration/worker/worker.js +3 -3
  218. package/examples/local/README-ch.md +76 -76
  219. package/examples/local/README.md +76 -76
  220. package/examples/local/charts.reactive.md +73 -73
  221. package/examples/local/recipes/invoice-zh.reactive.md +36 -36
  222. package/examples/local/recipes/invoice.reactive.md +36 -36
  223. package/examples/local/recipes/workshop-zh.reactive.md +33 -33
  224. package/examples/local/recipes/workshop.reactive.md +33 -33
  225. package/examples/local/showcase/README-ch.md +22 -22
  226. package/examples/local/showcase/README.md +31 -31
  227. package/examples/local/showcase/explore.reactive.md +102 -102
  228. package/examples/local/showcase/flow.reactive.md +86 -86
  229. package/examples/local/showcase/forms.reactive.md +126 -126
  230. package/examples/local/showcase/functions.reactive.md +119 -119
  231. package/examples/local/showcase/layout.reactive.md +100 -100
  232. package/examples/local/showcase/statistics.reactive.md +108 -108
  233. package/examples/local/showcase/tasks.reactive.md +89 -89
  234. package/examples/local/showcase/zh/explore.reactive.md +102 -102
  235. package/examples/local/showcase/zh/flow.reactive.md +86 -86
  236. package/examples/local/showcase/zh/forms.reactive.md +126 -126
  237. package/examples/local/showcase/zh/functions.reactive.md +119 -119
  238. package/examples/local/showcase/zh/layout.reactive.md +100 -100
  239. package/examples/local/showcase/zh/statistics.reactive.md +108 -108
  240. package/examples/local/showcase/zh/tasks.reactive.md +89 -89
  241. package/examples/minimal-extension/README-ch.md +78 -78
  242. package/examples/minimal-extension/README.md +78 -78
  243. package/examples/minimal-extension/index.html +15 -15
  244. package/examples/minimal-extension/package.json +26 -26
  245. package/examples/minimal-extension/sample/document.reactive.md +10 -10
  246. package/examples/minimal-extension/scripts/build.mjs +32 -32
  247. package/examples/minimal-extension/scripts/export.mjs +72 -72
  248. package/examples/minimal-extension/scripts/test-node.mjs +75 -75
  249. package/examples/minimal-extension/src/extension.tsx +90 -90
  250. package/examples/minimal-extension/src/preview.tsx +12 -12
  251. package/examples/minimal-extension/src/source.ts +4 -4
  252. package/examples/minimal-extension/tsconfig.json +14 -14
  253. package/examples/sci-fi-theme/README-ch.md +133 -133
  254. package/examples/sci-fi-theme/README.md +148 -148
  255. package/examples/sci-fi-theme/demo/acceptance.reactive.md +454 -454
  256. package/examples/sci-fi-theme/demo/demo.css +638 -638
  257. package/examples/sci-fi-theme/demo/document.reactive.md +206 -206
  258. package/examples/sci-fi-theme/demo/index.html +13 -13
  259. package/examples/sci-fi-theme/demo/main.tsx +215 -215
  260. package/examples/sci-fi-theme/docs/design-system-ch.md +245 -245
  261. package/examples/sci-fi-theme/docs/design-system.md +474 -474
  262. package/examples/sci-fi-theme/package.json +28 -28
  263. package/examples/sci-fi-theme/scripts/screenshot.mjs +98 -98
  264. package/examples/sci-fi-theme/src/components.css +2370 -2370
  265. package/examples/sci-fi-theme/src/index.ts +6 -6
  266. package/examples/sci-fi-theme/src/notch.css +142 -142
  267. package/examples/sci-fi-theme/src/sci-fi.css +7 -7
  268. package/examples/sci-fi-theme/src/theme.ts +39 -39
  269. package/examples/sci-fi-theme/tsconfig.json +20 -20
  270. package/examples/sci-fi-theme/vite.config.ts +24 -24
  271. package/examples/tetris-package/LICENSE +21 -21
  272. package/examples/tetris-package/NOTICES.md +11 -11
  273. package/examples/tetris-package/README-ch.md +91 -91
  274. package/examples/tetris-package/README.md +95 -95
  275. package/examples/tetris-package/package.json +35 -35
  276. package/examples/tetris-package/sample/document.reactive.md +16 -16
  277. package/examples/tetris-package/scripts/build-export.mjs +44 -44
  278. package/examples/tetris-package/scripts/build.mjs +130 -130
  279. package/examples/tetris-package/scripts/verify.mjs +173 -173
  280. package/examples/tetris-package/src/component.css +145 -145
  281. package/examples/tetris-package/src/components.tsx +334 -334
  282. package/examples/tetris-package/src/harness.tsx +34 -34
  283. package/examples/tetris-package/src/manifests.ts +93 -93
  284. package/examples/tetris-package/src/node-entry.ts +16 -16
  285. package/examples/tetris-package/src/sample.ts +4 -4
  286. package/examples/tetris-package/src/tetris-engine.ts +325 -325
  287. package/examples/tetris-package/tsconfig.json +15 -15
  288. package/package.json +7 -1
  289. package/dist-library/compiler-eOfcinZs.js +0 -62
  290. package/dist-library/component-state-BoLCGee4.js +0 -801
  291. package/dist-library/preset-core-CKc5YXSM.js +0 -1443
  292. package/dist-library/react-D5iGiUdL.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-F47AcE6o.js";
3
- import { a as g, t as _ } from "./compile-wUv8KEge.js";
4
- import { d as v } from "./compiler-core-As_m-MNm.js";
5
- import { S as y, g as b } from "./validation-BEBA_HvS.js";
6
- import { c as x } from "./config-BadfhjdP.js";
7
- import { t as S } from "./options-1aDLK7JY.js";
8
- import { t as ee } from "./compiler-eOfcinZs.js";
9
- import { i as te, n as ne, r as re, t as C } from "./authoring-Dsune4Hy.js";
10
- import { c as w } from "./schema-BufhKUSM.js";
11
- import { n as T, t as ie } from "./incremental-Dv0FSp_U.js";
12
- import { C as ae } from "./component-state-BoLCGee4.js";
13
- import { a as oe, i as se, n as ce, o as le, r as ue } from "./runtime-kcA7bG7G.js";
14
- import { i as de, n as fe, r as pe, t as me } from "./sample-bP4zHB3L.js";
15
- import { _ as he, a as ge, f as _e, g as ve, h as ye, i as be, m as xe, n as Se, p as Ce, r as we, t as Te, v as Ee, y as De } from "./shareable-DpbE-59H.js";
16
- import { t as Oe } from "./component-state-C52ZFJGl.js";
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,62 +234,62 @@ function Be(e) {
231
234
  insert: r
232
235
  };
233
236
  }
234
- function Ve(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 I(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 L(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
- function R(e) {
252
+ function z(e) {
250
253
  return e.children === void 0 ? void 0 : e.children.map((e) => e.id);
251
254
  }
252
- function z(e, t) {
253
- let n = R(e), r = R(t);
255
+ function Ye(e, t) {
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 He(e, t) {
260
- if (!L(e, t) || !z(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 (!He(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 Ue(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
- let a = R(e), o = R(t);
275
+ let a = z(e), o = z(t);
273
276
  if (a === void 0 || o === void 0) {
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] || Ue(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 We(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 Ge(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 Ge(e) {
294
297
  }
295
298
  return t;
296
299
  }
297
- function Ke(e, t, n, r) {
298
- if (t !== void 0 && He(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 Ke(e, t, n, r) {
303
306
  });
304
307
  return;
305
308
  }
306
- let i = Ue(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 Ke(e, t, n, r) {
313
316
  return;
314
317
  }
315
318
  let a = { id: e.id };
316
- if (!L(e, t)) {
317
- let n = We(e, t);
318
- n !== null && n !== 0 ? a.shift = n : a.data = I(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
- z(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) Ke(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 qe(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 Je = /* @__PURE__ */ new WeakMap();
336
- function Ye(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 Ye(e) {
348
351
  }
349
352
  return t;
350
353
  }
351
- function B(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: Ye(e),
361
+ bytes: nt(e),
359
362
  nodes: 0
360
363
  };
361
364
  if (n === "number") return {
@@ -370,19 +373,19 @@ function B(e, t) {
370
373
  bytes: 0,
371
374
  nodes: 0
372
375
  };
373
- let r = e, i = Je.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 = +!!nt(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 = B(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 B(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 += Ye(n) + 1;
396
- let s = B(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 B(e, t) {
402
405
  bytes: a,
403
406
  nodes: o
404
407
  };
405
- return Je.set(r, s), s;
408
+ return tt.set(r, s), s;
406
409
  }
407
- function Xe(e, t) {
410
+ function rt(e, t) {
408
411
  let n = e.document.nodes ?? [];
409
412
  try {
410
- let r = B(e, /* @__PURE__ */ new Set()), i = t.ok && typeof t.document.source == "string" ? t.document.source.length : 0;
411
- if (r.bytes <= Math.max(i, ze)) return {
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 = B(t, /* @__PURE__ */ new Set()), o = 0;
417
- for (let e of n) e.node === void 0 ? e.data !== void 0 && (o += 1) : o += B(e.node, /* @__PURE__ */ new Set()).nodes;
418
- let s = r.bytes * O >= a.bytes, c = a.nodes > 0 && o * O >= a.nodes;
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 Xe(e, t) {
432
435
  };
433
436
  }
434
437
  }
435
- function Ze(e, t) {
436
- return et(e, t);
438
+ function it(e, t) {
439
+ return st(e, t);
437
440
  }
438
- function Qe(e, t) {
439
- let n = et(e, t);
441
+ function at(e, t) {
442
+ let n = st(e, t);
440
443
  return n ? {
441
444
  patch: n,
442
- cost: Xe(n, t)
445
+ cost: rt(n, t)
443
446
  } : null;
444
447
  }
445
- function $e(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 et(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 = qe(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 et(e, t) {
490
493
  break;
491
494
  }
492
495
  }
493
- let h = [], g = Ge(u);
494
- for (let e of d) Ke(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
- ...$e(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 tt(e, t) {
507
- let n = I(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) => tt(e, t))), n;
514
+ }, e.children && (n.children = e.children.map((e) => ct(e, t))), n;
512
515
  }
513
- function nt(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 rt(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 it(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 it(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 it(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] = rt(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 = Ve(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 = Ge(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 it(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(), nt(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 = tt(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 = I(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,7 +634,7 @@ function it(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;
636
639
  let h = e.status === void 0 ? {} : { status: e.status };
637
640
  if (t.recoveries === null) return {
@@ -640,7 +643,7 @@ function it(e, t) {
640
643
  diagnostics: m,
641
644
  ...h
642
645
  };
643
- let g = t.recoveries === void 0 ? e.recoveries : P([...t.recoveries]);
646
+ let g = t.recoveries === void 0 ? e.recoveries : F([...t.recoveries]);
644
647
  return {
645
648
  ok: !0,
646
649
  document: i,
@@ -653,8 +656,8 @@ function it(e, t) {
653
656
  }
654
657
  }
655
658
  // src/local/transport/flat-compiled-data.ts
656
- var V = "flat-v1";
657
- function at(e) {
659
+ var H = "flat-v1";
660
+ function ft(e) {
658
661
  if (!e.ok) return !1;
659
662
  let t = e.document.nodes.map((e) => ({
660
663
  node: e,
@@ -670,7 +673,7 @@ function at(e) {
670
673
  }
671
674
  return !1;
672
675
  }
673
- function ot(e) {
676
+ function pt(e) {
674
677
  let t = [], n = /* @__PURE__ */ new Map(), r = [], i = (e) => {
675
678
  if (typeof e == "object" && e) {
676
679
  let i = n.get(e);
@@ -699,11 +702,11 @@ function ot(e) {
699
702
  for (let t of Object.keys(e)) n.push([t, i(e[t])]);
700
703
  }
701
704
  return {
702
- version: V,
705
+ version: H,
703
706
  records: t
704
707
  };
705
708
  }
706
- function st(e) {
709
+ function mt(e) {
707
710
  if (!e || typeof e != "object") return null;
708
711
  let t = e;
709
712
  if (t.version !== "flat-v1" || !Array.isArray(t.records) || t.records.length === 0 || t.records.length > 2e6) return null;
@@ -763,21 +766,21 @@ function st(e) {
763
766
  return r[0];
764
767
  }
765
768
  // src/local/transport/worker-job.ts
766
- var ct = 150, lt = 200, ut = [
769
+ var ht = 150, gt = 200, _t = [
767
770
  "maxSyntaxNodes",
768
771
  "maxParseWork",
769
772
  "maxMarkdownDepth"
770
773
  ];
771
- function H(e) {
774
+ function U(e) {
772
775
  return e instanceof Error ? e.message : String(e);
773
776
  }
774
- function U() {
777
+ function W() {
775
778
  return typeof performance < "u" ? performance.now() : Date.now();
776
779
  }
777
- function W(e) {
780
+ function G(e) {
778
781
  return Number.isFinite(e) ? Math.max(0, Math.round(e)) : 0;
779
782
  }
780
- function G(e, t, n) {
783
+ function K(e, t, n) {
781
784
  let r = {
782
785
  tokens: [],
783
786
  bindings: [],
@@ -785,7 +788,7 @@ function G(e, t, n) {
785
788
  };
786
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;
787
790
  try {
788
- return C(e, t, {
791
+ return se(e, t, {
789
792
  ...n.ok ? { document: n.document } : {},
790
793
  diagnostics: !1
791
794
  });
@@ -797,7 +800,7 @@ function G(e, t, n) {
797
800
  };
798
801
  }
799
802
  }
800
- function dt(e) {
803
+ function vt(e) {
801
804
  return Array.isArray(e) ? e.length > 32 ? Array(33) : e.map((e) => {
802
805
  if (!e || typeof e != "object" || Array.isArray(e)) return e;
803
806
  let t = e, n = { ...t }, r = t.props;
@@ -814,25 +817,25 @@ function dt(e) {
814
817
  return n.props = i, n;
815
818
  }) : e;
816
819
  }
817
- function ft(e) {
820
+ function yt(e) {
818
821
  if (e !== void 0) try {
819
822
  if (typeof e != "object" || !e || Array.isArray(e)) return e;
820
823
  let t = e, n = {};
821
- for (let e of b) Object.hasOwn(t, e) && (n[e] = t[e]);
824
+ for (let e of S) Object.hasOwn(t, e) && (n[e] = t[e]);
822
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")) {
823
826
  let e = t.limits;
824
827
  if (e && typeof e == "object" && !Array.isArray(e)) {
825
828
  let t = {};
826
- for (let n of ut) Object.hasOwn(e, n) && (t[n] = e[n]);
829
+ for (let n of _t) Object.hasOwn(e, n) && (t[n] = e[n]);
827
830
  n.limits = t;
828
831
  } else n.limits = e;
829
832
  }
830
- return Object.hasOwn(t, "hostComponents") && (n.hostComponents = dt(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;
831
834
  } catch {
832
835
  return e;
833
836
  }
834
837
  }
835
- function pt(e) {
838
+ function bt(e) {
836
839
  try {
837
840
  if (!e || typeof e != "object" || Array.isArray(e)) return "";
838
841
  let t = e.limits;
@@ -848,8 +851,8 @@ function pt(e) {
848
851
  return ":unreadable";
849
852
  }
850
853
  }
851
- function mt(e) {
852
- let t = S(e);
854
+ function xt(e) {
855
+ let t = te(e);
853
856
  if (t !== "invalid") return t;
854
857
  try {
855
858
  return `invalid:${JSON.stringify(e)}`;
@@ -857,33 +860,43 @@ function mt(e) {
857
860
  return "invalid";
858
861
  }
859
862
  }
860
- function K(e) {
861
- return `${mt(e)}${pt(e)}`;
863
+ function q(e) {
864
+ return `${xt(e)}${bt(e)}`;
862
865
  }
863
866
  // src/local/transport/worker-handler.ts
864
- function ht(e, t, n, r) {
867
+ function St(e, t, n, r) {
865
868
  let i = e;
866
869
  return typeof i.compileShared == "function" ? i.compileShared(t, n, r) : e.compile(t, n, r);
867
870
  }
868
- function gt(e) {
871
+ function Ct(e) {
869
872
  return e === "streaming" || e === "final";
870
873
  }
871
- function q(e) {
874
+ function J(e) {
872
875
  return e.stats;
873
876
  }
874
- function J(e, t, n) {
877
+ function Y(e, t, n, r) {
875
878
  try {
876
879
  e.postMessage({
877
880
  id: t,
881
+ ...r?.traceId === void 0 ? {} : {
882
+ traceId: r.traceId,
883
+ requestId: r.requestId,
884
+ sourceRevision: r.sourceRevision
885
+ },
878
886
  ok: !1,
879
887
  message: n
880
888
  });
881
889
  } catch {}
882
890
  }
883
- function _t(e, t, n, r, i) {
891
+ function wt(e, t, n, r, i) {
884
892
  try {
885
893
  e.postMessage({
886
- id: t,
894
+ id: t.id,
895
+ ...t.traceId === void 0 ? {} : {
896
+ traceId: t.traceId,
897
+ requestId: t.requestId,
898
+ sourceRevision: t.sourceRevision
899
+ },
887
900
  ok: !1,
888
901
  message: n,
889
902
  retryFull: !0,
@@ -892,18 +905,18 @@ function _t(e, t, n, r, i) {
892
905
  });
893
906
  } catch {}
894
907
  }
895
- function vt(e) {
908
+ function Tt(e) {
896
909
  return !!e && typeof e == "object" && (e.control === "dispose" || e.control === "cancel-preparation");
897
910
  }
898
- function yt(e) {
911
+ function Et(e) {
899
912
  if (!e || typeof e != "object") return !1;
900
913
  let t = e;
901
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";
902
915
  }
903
- function bt(e, t = {}) {
916
+ function Dt(e, t = {}) {
904
917
  let n = e === void 0 ? globalThis : e;
905
918
  if (!n || typeof n.postMessage != "function") throw TypeError("startLocalCompileWorker requires a worker scope with postMessage");
906
- let r = t.createSession ? t.createSession() : T(), i = r, a = t.preparationDelay, o = typeof a == "number" && Number.isFinite(a) ? Math.max(0, a) : 200, s = typeof i.prepareAsync == "function", c = null, l = 0, u = !1, d = null, f = null, p = 0, m, h = () => {
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 = () => {
907
920
  p += 1, f !== null && (f.aborted = !0, f = null), d !== null && (clearTimeout(d), d = null);
908
921
  }, g = () => new Promise((e) => {
909
922
  typeof setTimeout == "function" ? setTimeout(e, 0) : e();
@@ -913,11 +926,11 @@ function bt(e, t = {}) {
913
926
  if (typeof t != "function") return;
914
927
  let n = { aborted: !1 };
915
928
  f = n;
916
- let r = U(), a = !1;
929
+ let r = W(), a = !1;
917
930
  try {
918
931
  a = await t.call(i, n, g);
919
932
  } catch {} finally {
920
- f === n && (f = null), a && !n.aborted && !u && e === p && (m = W(U() - r));
933
+ f === n && (f = null), a && !n.aborted && !u && e === p && (m = G(W() - r));
921
934
  }
922
935
  }, v = () => {
923
936
  if (u || !s) return;
@@ -941,90 +954,104 @@ function bt(e, t = {}) {
941
954
  let t = typeof e == "number" && Number.isSafeInteger(e) && e > 0 ? e : null;
942
955
  return t === null ? l + 1 : t > l ? t : l + 1;
943
956
  }, S = (e, t, i, a, o = !1, s) => {
944
- let l = c;
945
- if (l === null) return !1;
946
- let u = W(i), d = s === void 0 ? b(u) : {
947
- ...b(u),
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),
948
961
  ...s
949
962
  };
950
963
  try {
951
- let i = a ? {
952
- id: e,
964
+ let e = a ? {
965
+ id: l,
966
+ ...u === void 0 ? {} : {
967
+ traceId: u,
968
+ requestId: d,
969
+ sourceRevision: f
970
+ },
953
971
  ok: !0,
954
- result: l.result,
955
- duration: u,
956
- incremental: q(r),
957
- ...l.sourcePhase === void 0 ? {} : { sourcePhase: l.sourcePhase },
958
- protocol: D,
972
+ result: p.result,
973
+ duration: m,
974
+ incremental: J(r),
975
+ ...p.sourcePhase === void 0 ? {} : { sourcePhase: p.sourcePhase },
976
+ protocol: k,
959
977
  revision: t,
960
- metrics: d
978
+ metrics: h
961
979
  } : {
962
- id: e,
980
+ id: l,
981
+ ...u === void 0 ? {} : {
982
+ traceId: u,
983
+ requestId: d,
984
+ sourceRevision: f
985
+ },
963
986
  ok: !0,
964
- result: l.result,
965
- duration: u,
966
- incremental: q(r),
967
- ...l.sourcePhase === void 0 ? {} : { sourcePhase: l.sourcePhase }
987
+ result: p.result,
988
+ duration: m,
989
+ incremental: J(r),
990
+ ...p.sourcePhase === void 0 ? {} : { sourcePhase: p.sourcePhase }
968
991
  };
969
- if (o && i.ok) {
970
- let e = U();
971
- i.analysis = G(l.source, l.options, l.result), i.metrics = {
972
- ...i.metrics,
973
- analysisMs: W(U() - e)
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)
974
997
  };
975
998
  }
976
- if (l.deep && l.flatResults && i.ok) {
977
- let { result: e, ...t } = i, r = {
978
- ...t,
979
- flatResult: ot(e)
999
+ if (p.deep && p.flatResults && e.ok) {
1000
+ let { result: t, ...r } = e, i = {
1001
+ ...r,
1002
+ flatResult: pt(t)
980
1003
  };
981
- n.postMessage(r);
982
- } else n.postMessage(i);
1004
+ n.postMessage(i);
1005
+ } else n.postMessage(e);
983
1006
  return !0;
984
- } catch (t) {
985
- return J(n, e, `Could not return the compile result: ${H(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;
986
1013
  }
987
1014
  };
988
1015
  return n.onmessage = (e) => {
989
1016
  let t = e?.data;
990
- if (vt(t)) {
1017
+ if (Tt(t)) {
991
1018
  t.control === "dispose" ? y() : h();
992
1019
  return;
993
1020
  }
994
1021
  if (!t || typeof t.id != "number") return;
995
1022
  if (typeof t.source == "string") {
996
- let e = t, i = ft(e.options), a = e.sourcePhase === void 0 ? i?.sourcePhase : e.sourcePhase;
997
- if (a !== void 0 && !gt(a)) {
998
- J(n, e.id, "The requested source phase is not supported: expected \"streaming\" or \"final\"");
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);
999
1026
  return;
1000
1027
  }
1001
1028
  let o = a;
1002
1029
  h();
1003
- let s = K(i), u = e.protocol === D, d = x(e.revision), f = U();
1030
+ let s = q(i), u = e.protocol === k, d = x(e.revision), f = W();
1004
1031
  try {
1005
1032
  if (c !== null && c.optionsKey !== s) try {
1006
1033
  r.clear();
1007
1034
  } catch {}
1008
- let t = ht(r, e.source, i, o), n = W(U() - f);
1035
+ let t = St(r, e.source, i, o), n = G(W() - f);
1009
1036
  l = d, c = {
1010
1037
  source: e.source,
1011
1038
  revision: d,
1012
1039
  options: i,
1013
1040
  optionsKey: s,
1014
1041
  result: t,
1015
- deep: at(t),
1016
- flatResults: e.flatResults === V,
1042
+ deep: ft(t),
1043
+ flatResults: e.flatResults === H,
1017
1044
  ...o === void 0 ? {} : { sourcePhase: o }
1018
- }, S(e.id, d, n, u, e.includeAuthorAnalysis === !0) && v();
1045
+ }, S(e, d, n, u, e.includeAuthorAnalysis === !0) && v();
1019
1046
  } catch (t) {
1020
- J(n, e.id, H(t));
1047
+ Y(n, e.id, U(t), e);
1021
1048
  }
1022
1049
  return;
1023
1050
  }
1024
1051
  if (t.protocol !== "patch-v1") return;
1025
1052
  h();
1026
1053
  let i = t, a = c, o = (e, t) => {
1027
- _t(n, i.id, e, t, a?.revision);
1054
+ wt(n, i, e, t, a?.revision);
1028
1055
  };
1029
1056
  if (a === null) {
1030
1057
  o("No complete compile is available to patch", "stale-base");
@@ -1042,7 +1069,7 @@ function bt(e, t = {}) {
1042
1069
  o("The options signature changed since the baseline", "options-mismatch");
1043
1070
  return;
1044
1071
  }
1045
- if (!yt(i.edit)) {
1072
+ if (!Et(i.edit)) {
1046
1073
  o("The source edit is invalid", "invalid-edit");
1047
1074
  return;
1048
1075
  }
@@ -1056,27 +1083,27 @@ function bt(e, t = {}) {
1056
1083
  o("The source edit produced an unexpected length", "invalid-edit");
1057
1084
  return;
1058
1085
  }
1059
- let d = x(i.revision), f = U();
1086
+ let d = x(i.revision), f = W();
1060
1087
  try {
1061
- let e = ht(r, u, a.options, a.sourcePhase), t = W(U() - 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;
1062
1089
  l = d, c = {
1063
1090
  source: u,
1064
1091
  revision: d,
1065
1092
  options: a.options,
1066
1093
  optionsKey: a.optionsKey,
1067
1094
  result: e,
1068
- deep: at(e),
1095
+ deep: ft(e),
1069
1096
  flatResults: a.flatResults,
1070
1097
  ...a.sourcePhase === void 0 ? {} : { sourcePhase: a.sourcePhase }
1071
1098
  };
1072
1099
  let p = null, h = 0;
1073
1100
  if (e.ok && s.ok && !c.deep && !a.deep) {
1074
- let t = U();
1075
- p = Qe(s, e), h = W(U() - t);
1101
+ let t = W();
1102
+ p = at(s, e), h = G(W() - t);
1076
1103
  }
1077
1104
  let g = p?.patch ?? null;
1078
1105
  if (g === null) {
1079
- S(i.id, d, t, !0, i.includeAuthorAnalysis === !0) && v();
1106
+ S(i, d, t, !0, i.includeAuthorAnalysis === !0) && v();
1080
1107
  return;
1081
1108
  }
1082
1109
  if (p !== null && p.cost.preferFull) {
@@ -1086,7 +1113,7 @@ function bt(e, t = {}) {
1086
1113
  patchBytes: e.patchBytes,
1087
1114
  ...e.fullBytes === void 0 ? {} : { fullBytes: e.fullBytes }
1088
1115
  };
1089
- S(i.id, d, t, !0, i.includeAuthorAnalysis === !0, n) && v();
1116
+ S(i, d, t, !0, i.includeAuthorAnalysis === !0, n) && v();
1090
1117
  return;
1091
1118
  }
1092
1119
  let _ = {
@@ -1098,26 +1125,31 @@ function bt(e, t = {}) {
1098
1125
  try {
1099
1126
  let s = {
1100
1127
  id: i.id,
1128
+ ...i.traceId === void 0 ? {} : {
1129
+ traceId: i.traceId,
1130
+ requestId: i.requestId,
1131
+ sourceRevision: i.sourceRevision
1132
+ },
1101
1133
  ok: !0,
1102
- protocol: D,
1134
+ protocol: k,
1103
1135
  baseRevision: o,
1104
1136
  revision: d,
1105
1137
  patch: g,
1106
1138
  duration: t,
1107
- incremental: q(r),
1139
+ incremental: J(r),
1108
1140
  ...a.sourcePhase === void 0 ? {} : { sourcePhase: a.sourcePhase },
1109
1141
  metrics: _
1110
1142
  };
1111
1143
  if (i.includeAuthorAnalysis === !0) {
1112
- let t = U();
1113
- s.analysis = G(u, a.options, e), _.analysisMs = W(U() - t);
1144
+ let t = W();
1145
+ s.analysis = K(u, a.options, e), _.analysisMs = G(W() - t);
1114
1146
  }
1115
1147
  n.postMessage(s), v();
1116
1148
  } catch (e) {
1117
- J(n, i.id, `Could not return the compile result: ${H(e)}`);
1149
+ Y(n, i.id, `Could not return the compile result: ${U(e)}`, i);
1118
1150
  }
1119
1151
  } catch (e) {
1120
- J(n, i.id, H(e));
1152
+ Y(n, i.id, U(e), i);
1121
1153
  }
1122
1154
  }, {
1123
1155
  dispose: y,
@@ -1128,7 +1160,7 @@ function bt(e, t = {}) {
1128
1160
  };
1129
1161
  }
1130
1162
  // src/local/transport/worker.ts
1131
- function xt(e, t) {
1163
+ function Ot(e, t) {
1132
1164
  if (!e || typeof e != "object") return !1;
1133
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;
1134
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;
@@ -1140,32 +1172,32 @@ function xt(e, t) {
1140
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;
1141
1173
  return !0;
1142
1174
  }
1143
- function St(e, t, n) {
1144
- let r = ft(t), i = n === void 0 ? Ct(t) : n, a = i === "streaming" || i === "final" ? i : void 0, o = i !== void 0 && a === void 0 ? i : void 0;
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;
1145
1177
  return {
1146
1178
  source: e,
1147
1179
  options: r,
1148
- optionsKey: K(r),
1149
- scheduledAt: U(),
1180
+ optionsKey: q(r),
1181
+ scheduledAt: W(),
1150
1182
  sourcePhase: a === "streaming" ? "streaming" : "final",
1151
1183
  explicitPhase: i !== void 0,
1152
1184
  ...o === void 0 ? {} : { invalidPhase: o }
1153
1185
  };
1154
1186
  }
1155
- function Ct(e) {
1187
+ function At(e) {
1156
1188
  try {
1157
1189
  return !e || typeof e != "object" || Array.isArray(e) ? void 0 : e.sourcePhase;
1158
1190
  } catch {
1159
1191
  return;
1160
1192
  }
1161
1193
  }
1162
- function Y(e, t) {
1194
+ function X(e, t) {
1163
1195
  return e.source === t.source && e.optionsKey === t.optionsKey && e.sourcePhase === t.sourcePhase && e.explicitPhase === t.explicitPhase && e.invalidPhase === t.invalidPhase;
1164
1196
  }
1165
- function X(e) {
1197
+ function Z(e) {
1166
1198
  return e.sourcePhase === "streaming" || e.explicitPhase ? { sourcePhase: e.sourcePhase } : {};
1167
1199
  }
1168
- function Z(e, t) {
1200
+ function Q(e, t) {
1169
1201
  return e.explicitPhase ? {
1170
1202
  ok: !1,
1171
1203
  diagnostics: [t],
@@ -1175,7 +1207,7 @@ function Z(e, t) {
1175
1207
  diagnostics: [t]
1176
1208
  };
1177
1209
  }
1178
- function wt() {
1210
+ function jt() {
1179
1211
  return {
1180
1212
  ok: !1,
1181
1213
  status: "failed",
@@ -1189,22 +1221,34 @@ function wt() {
1189
1221
  },
1190
1222
  line: 1,
1191
1223
  column: 1,
1192
- messageKey: "local.options.invalid.source-phase"
1224
+ messageKey: "local.options.invalid.source-phase",
1225
+ phase: "host",
1226
+ recoverable: !1
1193
1227
  }]
1194
1228
  };
1195
1229
  }
1196
- function Q(e) {
1230
+ function Mt(e) {
1197
1231
  if (!e || typeof e != "object") return !1;
1198
1232
  let t = e;
1199
1233
  return !(typeof t.ok != "boolean" || !Array.isArray(t.diagnostics) || t.ok && (!t.document || typeof t.document != "object"));
1200
1234
  }
1201
- function Tt(e) {
1235
+ function Nt(e) {
1202
1236
  return e.ok && "patch" in e && e.patch !== void 0;
1203
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
+ }
1204
1243
  function $(e) {
1244
+ let t = Ft(e);
1205
1245
  return {
1206
1246
  code: "local.worker.compile",
1207
- message: `Compilation failed: ${H(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",
1208
1252
  severity: "error",
1209
1253
  range: {
1210
1254
  start: 0,
@@ -1214,7 +1258,7 @@ function $(e) {
1214
1258
  column: 1
1215
1259
  };
1216
1260
  }
1217
- var Et = class {
1261
+ var It = class {
1218
1262
  options;
1219
1263
  delay;
1220
1264
  worker = null;
@@ -1223,11 +1267,18 @@ var Et = class {
1223
1267
  inFlight = null;
1224
1268
  nextId = 1;
1225
1269
  nextRevision = 1;
1270
+ nextSourceRevision = 1;
1271
+ currentSourceRevision = 0;
1226
1272
  pending = !1;
1227
1273
  fallbackSession = null;
1228
1274
  disposed = !1;
1275
+ timeout = null;
1276
+ requestContexts = /* @__PURE__ */ new Map();
1277
+ obsoleteRequestIds = /* @__PURE__ */ new Set();
1278
+ reportedStaleRequestIds = /* @__PURE__ */ new Set();
1229
1279
  baseline = null;
1230
1280
  patchState = "unknown";
1281
+ startupFailure = null;
1231
1282
  constructor(e) {
1232
1283
  this.options = e;
1233
1284
  let t = e.delay;
@@ -1239,13 +1290,17 @@ var Et = class {
1239
1290
  this.handleWorkerFailure(t || "The compile worker encountered an error");
1240
1291
  }, t.onmessageerror = () => this.handleWorkerFailure("The compile worker could not deliver the compile result"), this.worker = t;
1241
1292
  } catch (t) {
1242
- this.worker = null, e.onModeChange?.("fallback", `Could not start the compile worker: ${H(t)}`);
1293
+ this.worker = null, this.startupFailure = Ft(t), e.onModeChange?.("fallback", `Could not start the compile worker: ${U(t)}`);
1243
1294
  }
1244
1295
  }
1245
1296
  schedule(e, t, n, r) {
1246
1297
  if (this.disposed) return;
1247
- let i = St(e, t, r);
1248
- this.queued = i, n && typeof n.baseSource == "string" && yt(n.edit) && n.edit.to <= n.baseSource.length && n.baseSource.slice(0, n.edit.from) + n.edit.insert + n.baseSource.slice(n.edit.to) === e && (this.queued.editHint = {
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 = {
1249
1304
  baseSource: n.baseSource,
1250
1305
  edit: { ...n.edit }
1251
1306
  }), this.clearTimer(), i.sourcePhase === "streaming" && (this.baseline = null), this.setPending(!0), i.sourcePhase === "streaming" || !i.explicitPhase ? this.timer = setTimeout(() => {
@@ -1254,7 +1309,7 @@ var Et = class {
1254
1309
  }
1255
1310
  dispose() {
1256
1311
  if (this.disposed) return;
1257
- 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();
1258
1313
  let e = this.worker;
1259
1314
  if (this.worker = null, e) {
1260
1315
  e.onmessage = null, e.onerror = null, e.onmessageerror = null;
@@ -1271,13 +1326,13 @@ var Et = class {
1271
1326
  }
1272
1327
  compile(e) {
1273
1328
  if (e.invalidPhase !== void 0) {
1274
- this.deliver({
1329
+ this.deliver(e, {
1275
1330
  source: e.source,
1276
- result: wt(),
1331
+ result: jt(),
1277
1332
  duration: 0,
1278
1333
  mode: this.worker === null ? "fallback" : "worker",
1279
1334
  ...e.options === void 0 ? {} : { options: e.options },
1280
- metrics: { queueMs: W(U() - e.scheduledAt) }
1335
+ metrics: { queueMs: G(W() - e.scheduledAt) }
1281
1336
  }), this.finishRun();
1282
1337
  return;
1283
1338
  }
@@ -1287,12 +1342,15 @@ var Et = class {
1287
1342
  return;
1288
1343
  }
1289
1344
  e.sourcePhase === "streaming" && (this.baseline = null);
1290
- let n = this.nextId++, r = this.nextRevision++, i = U(), a = this.baseline, o = e.sourcePhase === "final" && this.patchState === "enabled" && a !== null && a.optionsKey === e.optionsKey ? {
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,
1291
1349
  id: n,
1292
- protocol: D,
1293
- baseRevision: a.revision,
1350
+ protocol: k,
1351
+ baseRevision: s.revision,
1294
1352
  revision: r,
1295
- 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) ?? {
1296
1354
  from: 0,
1297
1355
  to: 0,
1298
1356
  insert: ""
@@ -1300,61 +1358,135 @@ var Et = class {
1300
1358
  targetLength: e.source.length,
1301
1359
  optionsKey: e.optionsKey
1302
1360
  } : {
1361
+ traceId: i,
1362
+ requestId: n,
1363
+ sourceRevision: a,
1303
1364
  id: n,
1304
1365
  source: e.source,
1305
1366
  ...e.options === void 0 ? {} : { options: e.options },
1306
- protocol: D,
1367
+ protocol: k,
1307
1368
  revision: r,
1308
- flatResults: V,
1369
+ flatResults: H,
1309
1370
  ...e.sourcePhase === "streaming" || e.explicitPhase ? { sourcePhase: e.sourcePhase } : {}
1310
- };
1311
- this.inFlight = {
1371
+ }, l = {
1312
1372
  id: n,
1313
1373
  job: e,
1314
- startedAt: i,
1315
- revision: r
1316
- }, this.options.includeAuthorAnalysis && (o.includeAuthorAnalysis = !0);
1317
- try {
1318
- t.postMessage(o);
1319
- } catch (t) {
1320
- this.inFlight = null;
1321
- let n = `Could not send the source to the compile worker: ${H(t)}`, r = this.queued;
1322
- if (r !== null && !Y(r, e)) {
1323
- this.resetProtocol(), this.degrade(n), this.finishRun();
1324
- 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)}`);
1325
1406
  }
1326
- r !== null && (this.queued = null, this.clearTimer()), this.resetProtocol(), this.degrade(n), this.compileFallback(e);
1327
1407
  }
1328
1408
  }
1329
1409
  compileFallback(e) {
1330
1410
  if (this.disposed) return;
1331
1411
  e.sourcePhase === "streaming" && (this.baseline = null);
1332
- let t = U(), n;
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;
1333
1424
  try {
1334
- let t = this.options.fallbackCompile ?? ((e, t, n) => (this.fallbackSession ??= T(), this.fallbackSession.compile(e, t, n)));
1335
- n = e.explicitPhase ? t(e.source, e.options, e.sourcePhase) : e.options === void 0 ? t(e.source) : t(e.source, e.options);
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);
1336
1427
  } catch (t) {
1337
- n = Z(e, $(t));
1428
+ i = Q(e, $(t));
1338
1429
  }
1339
- this.deliver({
1340
- source: e.source,
1341
- result: n,
1342
- duration: W(U() - t),
1343
- mode: "fallback",
1344
- ...this.options.includeAuthorAnalysis ? { analysis: G(e.source, e.options, n) } : {},
1345
- ...e.options === void 0 ? {} : { options: e.options },
1346
- ...X(e),
1347
- metrics: { queueMs: W(t - e.scheduledAt) }
1348
- }), 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;
1349
1469
  }
1350
1470
  receive(e) {
1351
1471
  if (this.disposed) return;
1352
1472
  let t = this.inFlight;
1353
- 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;
1354
1486
  let n, r = 0;
1355
1487
  if (e.ok && "flatResult" in e) {
1356
- let t = U(), i = st(e.flatResult);
1357
- r = W(U() - t), n = Q(i) ? {
1488
+ let t = W(), i = mt(e.flatResult);
1489
+ r = G(W() - t), n = Mt(i) ? {
1358
1490
  ...e,
1359
1491
  result: i
1360
1492
  } : {
@@ -1365,14 +1497,14 @@ var Et = class {
1365
1497
  };
1366
1498
  } else n = e;
1367
1499
  this.inFlight = null;
1368
- let i = t.job, a = W(U() - t.startedAt), o = W(t.startedAt - i.scheduledAt), s = null, c = r, l = null, u = "worker", d;
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;
1369
1501
  if (n.ok) {
1370
- if (Tt(n)) {
1371
- let e = U(), t = this.applyResponsePatch(i, n);
1372
- c = W(U() - e), t !== null && (s = t, d = n.revision);
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);
1373
1505
  } else {
1374
1506
  let e = n;
1375
- Q(e.result) ? (s = e.result, d = typeof e.revision == "number" ? e.revision : void 0, i.sourcePhase === "streaming" || e.sourcePhase === "streaming" ? this.baseline = null : e.protocol === "patch-v1" && typeof e.revision == "number" && Number.isSafeInteger(e.revision) ? (this.patchState = "enabled", this.baseline = e.result.ok ? {
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 ? {
1376
1508
  source: i.source,
1377
1509
  optionsKey: i.optionsKey,
1378
1510
  revision: e.revision,
@@ -1380,52 +1512,71 @@ var Et = class {
1380
1512
  } : null) : (this.patchState = "legacy", this.baseline = null)) : l = "The compile worker returned an invalid result";
1381
1513
  }
1382
1514
  } else n.retryFull !== !0 && (l = n.message);
1383
- let f = this.queued, p = f !== null && !Y(f, i);
1384
- f !== null && !p && (this.queued = null, this.clearTimer()), s === null ? l === null ? (p || !this.recoverWithFullResult(i)) && (p ? this.resetProtocol() : (this.patchState = "disabled", this.baseline = null, this.deliver({
1385
- source: i.source,
1386
- result: Z(i, $("The compile worker could not apply an incremental result patch")),
1387
- duration: 0,
1388
- mode: u,
1389
- ...i.options === void 0 ? {} : { options: i.options },
1390
- ...X(i),
1391
- metrics: {
1392
- queueMs: o,
1393
- roundTripMs: a,
1394
- ...c > 0 ? { applyMs: c } : {}
1395
- }
1396
- })), this.finishRun()) : (p || this.deliver({
1397
- source: i.source,
1398
- result: Z(i, $(l)),
1399
- duration: 0,
1400
- mode: u,
1401
- ...i.options === void 0 ? {} : { options: i.options },
1402
- ...X(i),
1403
- metrics: {
1404
- queueMs: o,
1405
- 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();
1406
1572
  }
1407
- }), this.finishRun()) : (p || this.deliver({
1408
- source: i.source,
1409
- result: s,
1410
- duration: W(n.ok ? n.duration : 0),
1411
- mode: u,
1412
- ...n.ok && this.options.includeAuthorAnalysis && xt(n.analysis, i.source.length) ? { analysis: n.analysis } : {},
1413
- ...i.options === void 0 ? {} : { options: i.options },
1414
- ...X(i),
1415
- metrics: {
1416
- queueMs: o,
1417
- roundTripMs: a,
1418
- ...c > 0 ? { applyMs: c } : {},
1419
- ...n.ok && n.metrics ? { worker: n.metrics } : {}
1420
- },
1421
- ...d === void 0 ? {} : { revision: d }
1422
- }), this.finishRun());
1573
+ }
1423
1574
  }
1424
1575
  applyResponsePatch(e, t) {
1425
1576
  if (e.sourcePhase !== "final") return null;
1426
1577
  let n = this.baseline;
1427
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;
1428
- let r = it(n.result, t.patch);
1579
+ let r = dt(n.result, t.patch);
1429
1580
  if (r === null || !r.ok || r.document.source !== e.source) return null;
1430
1581
  let i;
1431
1582
  if (e.sourcePhase === "final" && e.explicitPhase) i = r.recoveries === void 0 ? {
@@ -1447,18 +1598,22 @@ var Et = class {
1447
1598
  }, i;
1448
1599
  }
1449
1600
  recoverWithFullResult(e) {
1450
- if (this.worker === null || (e.recovery ?? 0) >= 1) return !1;
1451
- let t = this.queued;
1452
- return t !== null && !Y(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({
1453
1602
  ...e,
1454
1603
  recovery: (e.recovery ?? 0) + 1
1455
- }), !0);
1604
+ }), "dispatched");
1456
1605
  }
1457
- handleWorkerFailure(e) {
1606
+ handleWorkerFailure(e, t = {
1607
+ ...O("local.worker.error"),
1608
+ recoverable: !0
1609
+ }) {
1458
1610
  if (this.disposed) return;
1459
- this.resetProtocol(), this.degrade(e);
1460
- let t = this.inFlight;
1461
- this.inFlight = null, t && (this.queued === null || Y(this.queued, t.job)) && (this.queued !== null && (this.queued = null, this.clearTimer()), this.compileFallback(t.job)), this.finishRun();
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())));
1462
1617
  }
1463
1618
  degrade(e) {
1464
1619
  let t = this.worker;
@@ -1476,14 +1631,48 @@ var Et = class {
1476
1631
  finishRun() {
1477
1632
  this.disposed || (this.drain(), !this.disposed && this.setPending(this.timer !== null || this.inFlight !== null || this.queued !== null));
1478
1633
  }
1479
- deliver(e) {
1480
- if (this.disposed) return;
1481
- let t = this.baseline !== null && this.baseline.result === e.result, n = this.options.shareResults === !0 || !t ? e.result : P(e.result);
1482
- this.options.onResult({
1483
- ...e,
1484
- 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
1485
1654
  });
1486
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
+ }
1487
1676
  setPending(e) {
1488
1677
  this.pending !== e && (this.pending = e, this.options.onPendingChange?.(e));
1489
1678
  }
@@ -1491,4 +1680,4 @@ var Et = class {
1491
1680
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
1492
1681
  }
1493
1682
  };
1494
- export { h as DEFAULT_LOCAL_THEME, ct as LOCAL_COMPILE_DELAY_MS, lt as LOCAL_COMPILE_PREPARATION_DELAY_MS, i as LOCAL_DIAGNOSTIC_CODES, D as LOCAL_RESULT_PATCH_PROTOCOL, _e as LOCAL_STATE_FORMAT, y as LOCAL_SYNTAX_VERSION, f as LOCAL_THEME_PROTOCOL, Et as LocalCompileScheduler, ie as LocalCompileSession, g as LocalExpressionError, Te as SHAREABLE_HTML_FORMAT, Se as SHAREABLE_HTML_FORMAT_V2, C as analyzeLocalSource, it as applyLocalResultPatch, Ce as applyLocalState, oe as applyLocalStateRetention, Ve as applySourceEdit, Le as checkLocalUpgrade, _ as compileExpression, $ as compileFailureDiagnostic, n as compileLatex, ee as compileLocal, t as compilePlotFormula, ne as completeLocalSource, a as countLocalCodePoints, T as createLocalCompileSession, ce as createLocalRuntime, xe as createLocalStateFile, we as createShareableHtml, F as diffSourceEdit, Ze as encodeLocalResultPatch, ye as exportLocalState, l as formatLocalDiagnostic, re as formatLocalSource, e as implicitGridSize, ve as importLocalState, Pe as inspectLocalSourceVersion, u as isLocalDiagnosticCode, o as isLocalThemeName, S as localCompileOptionsKey, s as localDiagnosticTemplate, c as localDiagnosticTemplateKeys, ae as localSourceDigest, K as localWorkerOptionsKey, Re as migrateLocalSource, ue as notifyLocalRuntime, he as parseLocalState, le as planLocalStateRetention, r as plotFormulaKind, te as renameLocalBinding, Oe as resolveLocalComponentStateExport, Ee as resolveLocalState, be as resolveLocalStateBaseline, m as resolveLocalTheme, me as sampleImplicit, fe as sampleParametric, pe as samplePlot, de as samplePolar, ge as serializeForScript, De as serializeLocalState, bt as startLocalCompileWorker, se as updateLocalRuntime };
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 };