sygnal 5.3.7 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (438) hide show
  1. package/CHANGELOG.md +646 -0
  2. package/README.md +77 -47
  3. package/dist/astro/client.cjs.js +33 -8114
  4. package/dist/astro/client.cjs.js.map +1 -0
  5. package/dist/astro/client.mjs +33 -8114
  6. package/dist/astro/client.mjs.map +1 -0
  7. package/dist/astro/index.cjs.js +1039 -9
  8. package/dist/astro/index.cjs.js.map +1 -0
  9. package/dist/astro/index.mjs +1038 -9
  10. package/dist/astro/index.mjs.map +1 -0
  11. package/dist/astro/server.cjs.js +3400 -166
  12. package/dist/astro/server.cjs.js.map +1 -0
  13. package/dist/astro/server.mjs +3400 -166
  14. package/dist/astro/server.mjs.map +1 -0
  15. package/dist/devtools.cjs.js +1431 -0
  16. package/dist/devtools.cjs.js.map +1 -0
  17. package/dist/devtools.esm.js +1419 -0
  18. package/dist/devtools.esm.js.map +1 -0
  19. package/dist/diagnostics.cjs.js +4033 -0
  20. package/dist/diagnostics.cjs.js.map +1 -0
  21. package/dist/diagnostics.esm.js +4003 -0
  22. package/dist/diagnostics.esm.js.map +1 -0
  23. package/dist/element.cjs.js +230 -0
  24. package/dist/element.cjs.js.map +1 -0
  25. package/dist/element.esm.js +228 -0
  26. package/dist/element.esm.js.map +1 -0
  27. package/dist/guide/accessibility.md +257 -0
  28. package/dist/guide/adapters.md +221 -0
  29. package/dist/guide/behaviors.md +312 -0
  30. package/dist/guide/browser-sources.md +203 -0
  31. package/dist/guide/drag-and-drop.md +342 -0
  32. package/dist/guide/element-commands.md +306 -0
  33. package/dist/guide/error-boundaries.md +169 -0
  34. package/dist/guide/forms-reference.md +381 -0
  35. package/dist/guide/forms.md +250 -0
  36. package/dist/guide/http.md +299 -0
  37. package/dist/guide/inputs.md +173 -0
  38. package/dist/guide/persistence.md +245 -0
  39. package/dist/guide/recipes/carousel.md +155 -0
  40. package/dist/guide/recipes/charts.md +177 -0
  41. package/dist/guide/recipes/code-editor.md +135 -0
  42. package/dist/guide/recipes/data-grid.md +155 -0
  43. package/dist/guide/recipes/data-table.md +196 -0
  44. package/dist/guide/recipes/i18n.md +222 -0
  45. package/dist/guide/recipes/icons.md +115 -0
  46. package/dist/guide/recipes/overview.md +33 -0
  47. package/dist/guide/recipes/rich-text.md +154 -0
  48. package/dist/guide/resources.md +471 -0
  49. package/dist/guide/ssr.md +255 -0
  50. package/dist/guide/timers.md +178 -0
  51. package/dist/guide/ui/accordion.md +93 -0
  52. package/dist/guide/ui/combobox.md +144 -0
  53. package/dist/guide/ui/dialog.md +124 -0
  54. package/dist/guide/ui/disclosure.md +60 -0
  55. package/dist/guide/ui/menu.md +125 -0
  56. package/dist/guide/ui/overview.md +166 -0
  57. package/dist/guide/ui/popover.md +101 -0
  58. package/dist/guide/ui/select.md +114 -0
  59. package/dist/guide/ui/tabs.md +161 -0
  60. package/dist/guide/ui/toaster.md +152 -0
  61. package/dist/guide/ui/tooltip.md +103 -0
  62. package/dist/guide/undo.md +178 -0
  63. package/dist/guide/virtual-collections.md +183 -0
  64. package/dist/guide/web-components.md +179 -0
  65. package/dist/guide/widgets.md +217 -0
  66. package/dist/index.cjs.js +15283 -6279
  67. package/dist/index.cjs.js.map +1 -0
  68. package/dist/index.d.ts +3739 -370
  69. package/dist/index.esm.js +15230 -6274
  70. package/dist/index.esm.js.map +1 -0
  71. package/dist/jsx-dev-runtime.cjs.js +27 -329
  72. package/dist/jsx-dev-runtime.cjs.js.map +1 -0
  73. package/dist/jsx-dev-runtime.esm.js +20 -322
  74. package/dist/jsx-dev-runtime.esm.js.map +1 -0
  75. package/dist/jsx-runtime.cjs.js +27 -329
  76. package/dist/jsx-runtime.cjs.js.map +1 -0
  77. package/dist/jsx-runtime.esm.js +20 -322
  78. package/dist/jsx-runtime.esm.js.map +1 -0
  79. package/dist/jsx.cjs.js +11 -309
  80. package/dist/jsx.cjs.js.map +1 -0
  81. package/dist/jsx.esm.js +9 -310
  82. package/dist/jsx.esm.js.map +1 -0
  83. package/dist/react.cjs.js +117 -0
  84. package/dist/react.cjs.js.map +1 -0
  85. package/dist/react.esm.js +115 -0
  86. package/dist/react.esm.js.map +1 -0
  87. package/dist/shims/globalthis.cjs +20 -0
  88. package/dist/sygnal.min.js +2 -1
  89. package/dist/sygnal.min.js.map +1 -0
  90. package/dist/ui-combobox.cjs.js +169 -0
  91. package/dist/ui-combobox.cjs.js.map +1 -0
  92. package/dist/ui-combobox.esm.js +148 -0
  93. package/dist/ui-combobox.esm.js.map +1 -0
  94. package/dist/ui-menu.cjs.js +87 -0
  95. package/dist/ui-menu.cjs.js.map +1 -0
  96. package/dist/ui-menu.esm.js +66 -0
  97. package/dist/ui-menu.esm.js.map +1 -0
  98. package/dist/ui-select.cjs.js +104 -0
  99. package/dist/ui-select.cjs.js.map +1 -0
  100. package/dist/ui-select.esm.js +83 -0
  101. package/dist/ui-select.esm.js.map +1 -0
  102. package/dist/ui.cjs.js +738 -0
  103. package/dist/ui.cjs.js.map +1 -0
  104. package/dist/ui.esm.js +727 -0
  105. package/dist/ui.esm.js.map +1 -0
  106. package/dist/vike/ClientOnly.cjs.js +5 -14
  107. package/dist/vike/ClientOnly.cjs.js.map +1 -0
  108. package/dist/vike/ClientOnly.mjs +5 -14
  109. package/dist/vike/ClientOnly.mjs.map +1 -0
  110. package/dist/vike/{+config.js → config/+config.js} +10 -1
  111. package/dist/vike/config/+config.js.map +1 -0
  112. package/dist/vike/config/package.json +6 -0
  113. package/dist/vike/onRenderClient.cjs.js +166 -95
  114. package/dist/vike/onRenderClient.cjs.js.map +1 -0
  115. package/dist/vike/onRenderClient.mjs +166 -95
  116. package/dist/vike/onRenderClient.mjs.map +1 -0
  117. package/dist/vike/onRenderHtml.cjs.js +60 -24
  118. package/dist/vike/onRenderHtml.cjs.js.map +1 -0
  119. package/dist/vike/onRenderHtml.mjs +61 -25
  120. package/dist/vike/onRenderHtml.mjs.map +1 -0
  121. package/dist/vite/plugin.cjs.js +926 -65
  122. package/dist/vite/plugin.cjs.js.map +1 -0
  123. package/dist/vite/plugin.mjs +925 -65
  124. package/dist/vite/plugin.mjs.map +1 -0
  125. package/dist/zag.cjs.js +408 -0
  126. package/dist/zag.cjs.js.map +1 -0
  127. package/dist/zag.esm.js +405 -0
  128. package/dist/zag.esm.js.map +1 -0
  129. package/llms.txt +313 -0
  130. package/package.json +109 -16
  131. package/src/astro/client.ts +40 -18
  132. package/src/astro/index.d.ts +48 -1
  133. package/src/astro/index.ts +106 -9
  134. package/src/astro/server.ts +11 -3
  135. package/src/collection.ts +6 -90
  136. package/src/core/actions.ts +134 -0
  137. package/src/core/cell.ts +202 -0
  138. package/src/core/debug.ts +23 -0
  139. package/src/core/define.ts +242 -0
  140. package/src/core/hooks.ts +314 -0
  141. package/src/core/hosts/collection.ts +325 -0
  142. package/src/core/hosts/switchable.ts +146 -0
  143. package/src/core/instance.ts +592 -0
  144. package/src/core/markers/clientonly.ts +13 -0
  145. package/src/core/markers/lazy.ts +40 -0
  146. package/src/core/markers/portal.ts +96 -0
  147. package/src/core/markers/suspense.ts +41 -0
  148. package/src/core/markers/transition.ts +70 -0
  149. package/src/core/registry.ts +25 -0
  150. package/src/core/runtime.ts +573 -0
  151. package/src/core/statics.ts +104 -0
  152. package/src/core/teardown.ts +60 -0
  153. package/src/core/view.ts +37 -0
  154. package/src/cycle/dom/DocumentDOMSource.ts +13 -8
  155. package/src/cycle/dom/ElementFinder.ts +7 -9
  156. package/src/cycle/dom/EventDelegator.ts +174 -223
  157. package/src/cycle/dom/IsolateModule.ts +65 -35
  158. package/src/cycle/dom/MainDOMSource.ts +13 -2
  159. package/src/cycle/dom/PriorityQueue.ts +4 -2
  160. package/src/cycle/dom/SymbolTree.ts +18 -47
  161. package/src/cycle/dom/classNameModule.ts +76 -0
  162. package/src/cycle/dom/controlledInputModule.ts +50 -0
  163. package/src/cycle/dom/enrichEventStream.ts +29 -45
  164. package/src/cycle/dom/fragment.ts +7 -0
  165. package/src/cycle/dom/isolate.ts +30 -27
  166. package/src/cycle/dom/makeDOMDriver.ts +115 -57
  167. package/src/cycle/dom/mockDOMSource.ts +83 -9
  168. package/src/cycle/dom/modules.ts +21 -4
  169. package/src/cycle/dom/propsModule.ts +65 -0
  170. package/src/cycle/dom/selectModule.ts +22 -17
  171. package/src/cycle/dom/snabbdom.ts +1 -6
  172. package/src/cycle/dom/thunk.ts +3 -0
  173. package/src/cycle/dom/utils.ts +98 -0
  174. package/src/cycle/dom/viewTransition.ts +43 -0
  175. package/src/cycle/state/StateSource.ts +20 -4
  176. package/src/cycle/state/objIsEqual.ts +50 -0
  177. package/src/cycle/state/types.ts +0 -10
  178. package/src/defineComponent.ts +34 -0
  179. package/src/devtools.d.ts +151 -0
  180. package/src/devtools.ts +34 -0
  181. package/src/element.d.ts +59 -0
  182. package/src/element.ts +235 -0
  183. package/src/extra/backoff.ts +9 -0
  184. package/src/extra/behaviors.ts +169 -0
  185. package/src/extra/browserSignals.ts +23 -0
  186. package/src/extra/browserSources.ts +326 -0
  187. package/src/extra/command.ts +3 -3
  188. package/src/extra/controls.ts +47 -0
  189. package/src/extra/copyAsTest.ts +286 -0
  190. package/src/extra/devtools.ts +109 -31
  191. package/src/extra/devtoolsActions.ts +379 -0
  192. package/src/extra/devtoolsHook.ts +9 -0
  193. package/src/extra/devtoolsNext.ts +83 -0
  194. package/src/extra/diagnostics/checks/actionLog.ts +108 -0
  195. package/src/extra/diagnostics/checks/behaviors.ts +49 -0
  196. package/src/extra/diagnostics/checks/browserSources.ts +96 -0
  197. package/src/extra/diagnostics/checks/collections.ts +67 -0
  198. package/src/extra/diagnostics/checks/controls.ts +148 -0
  199. package/src/extra/diagnostics/checks/dataset.ts +57 -0
  200. package/src/extra/diagnostics/checks/dom.ts +250 -0
  201. package/src/extra/diagnostics/checks/elementCommands.ts +175 -0
  202. package/src/extra/diagnostics/checks/events.ts +83 -0
  203. package/src/extra/diagnostics/checks/fetch.ts +135 -0
  204. package/src/extra/diagnostics/checks/forms.ts +163 -0
  205. package/src/extra/diagnostics/checks/index.ts +202 -0
  206. package/src/extra/diagnostics/checks/inspect.ts +427 -0
  207. package/src/extra/diagnostics/checks/next.ts +417 -0
  208. package/src/extra/diagnostics/checks/persist.ts +54 -0
  209. package/src/extra/diagnostics/checks/props.ts +56 -0
  210. package/src/extra/diagnostics/checks/public.d.ts +302 -0
  211. package/src/extra/diagnostics/checks/replies.ts +128 -0
  212. package/src/extra/diagnostics/checks/router.ts +100 -0
  213. package/src/extra/diagnostics/checks/rxjsHints.ts +88 -0
  214. package/src/extra/diagnostics/checks/shared.ts +203 -0
  215. package/src/extra/diagnostics/checks/shorthand.ts +115 -0
  216. package/src/extra/diagnostics/checks/sortable.ts +129 -0
  217. package/src/extra/diagnostics/checks/state.ts +148 -0
  218. package/src/extra/diagnostics/checks/statics.ts +48 -0
  219. package/src/extra/diagnostics/checks/strict.ts +55 -0
  220. package/src/extra/diagnostics/checks/timers.ts +80 -0
  221. package/src/extra/diagnostics/checks/viewTransitions.ts +47 -0
  222. package/src/extra/diagnostics/checks/virtual.ts +73 -0
  223. package/src/extra/diagnostics/checks/widgets.ts +109 -0
  224. package/src/extra/diagnostics/checks/wiring.ts +121 -0
  225. package/src/extra/diagnostics/codes.ts +477 -0
  226. package/src/extra/diagnostics/index.ts +353 -0
  227. package/src/extra/diagnostics/legacy.ts +76 -0
  228. package/src/extra/driverFactories.ts +172 -60
  229. package/src/extra/elementCommands.ts +53 -0
  230. package/src/extra/eventDriver.ts +4 -0
  231. package/src/extra/fetchDriver.ts +519 -0
  232. package/src/extra/flatten.ts +75 -0
  233. package/src/extra/focusWithin.ts +27 -0
  234. package/src/extra/form.ts +268 -0
  235. package/src/extra/formHelpers.ts +139 -0
  236. package/src/extra/head.ts +106 -0
  237. package/src/extra/hmr.ts +2 -3
  238. package/src/extra/owned.ts +24 -0
  239. package/src/extra/pager.ts +50 -0
  240. package/src/extra/persist.ts +133 -0
  241. package/src/extra/pwa.ts +1 -1
  242. package/src/extra/queryCache.ts +107 -0
  243. package/src/extra/reducers.ts +13 -6
  244. package/src/extra/reduxDevtools.ts +92 -0
  245. package/src/extra/replies.ts +54 -0
  246. package/src/extra/router.ts +323 -0
  247. package/src/extra/run.ts +94 -210
  248. package/src/extra/selection.ts +76 -0
  249. package/src/extra/socketDriver.ts +265 -0
  250. package/src/extra/sortable.ts +377 -0
  251. package/src/extra/ssr.ts +427 -160
  252. package/src/extra/standardSchema.ts +27 -0
  253. package/src/extra/testing.ts +3158 -190
  254. package/src/extra/timers.ts +95 -0
  255. package/src/extra/undo.ts +261 -0
  256. package/src/extra/viewTransitions.ts +38 -0
  257. package/src/extra/virtual.ts +513 -0
  258. package/src/extra/widget.ts +201 -0
  259. package/src/extra/xstreamExtras.ts +269 -0
  260. package/src/index.d.ts +3012 -87
  261. package/src/index.ts +32 -10
  262. package/src/jsx-runtime.ts +15 -1
  263. package/src/jsx.ts +2 -1
  264. package/src/lazy.ts +50 -7
  265. package/src/portal.ts +3 -1
  266. package/src/pragma/index.ts +262 -134
  267. package/src/react-peers.d.ts +5 -0
  268. package/src/react.d.ts +43 -0
  269. package/src/react.ts +110 -0
  270. package/src/shared.ts +48 -0
  271. package/src/slot.ts +1 -1
  272. package/src/suspense.ts +3 -1
  273. package/src/switchable.ts +6 -119
  274. package/src/transition.ts +3 -1
  275. package/src/ui/accordion.ts +64 -0
  276. package/src/ui/dialog.ts +129 -0
  277. package/src/ui/disclosure.ts +35 -0
  278. package/src/ui/popover.ts +45 -0
  279. package/src/ui/shared.ts +94 -0
  280. package/src/ui/tabs.ts +82 -0
  281. package/src/ui/toaster.ts +198 -0
  282. package/src/ui/tooltip.ts +70 -0
  283. package/src/ui/zag/combobox.ts +115 -0
  284. package/src/ui/zag/menu.ts +40 -0
  285. package/src/ui/zag/select.ts +54 -0
  286. package/src/ui/zag/shared.ts +43 -0
  287. package/src/ui-combobox.d.ts +20 -0
  288. package/src/ui-combobox.ts +6 -0
  289. package/src/ui-menu.d.ts +30 -0
  290. package/src/ui-menu.ts +6 -0
  291. package/src/ui-select.d.ts +17 -0
  292. package/src/ui-select.ts +6 -0
  293. package/src/ui-zag-types.d.ts +42 -0
  294. package/src/ui.d.ts +208 -0
  295. package/src/ui.ts +15 -0
  296. package/src/vike/+config.ts +9 -1
  297. package/src/vike/ClientOnly.ts +1 -1
  298. package/src/vike/onRenderClient.ts +144 -96
  299. package/src/vike/onRenderHtml.ts +69 -26
  300. package/src/vike/types.ts +27 -4
  301. package/src/vite/globalthis-shim.ts +18 -0
  302. package/src/vite/globalthis.ts +56 -0
  303. package/src/vite/plugin.d.ts +114 -2
  304. package/src/vite/plugin.ts +920 -56
  305. package/src/zag.d.ts +64 -0
  306. package/src/zag.ts +238 -0
  307. package/dist/astro/astro/client.d.ts +0 -5
  308. package/dist/astro/astro/index.d.ts +0 -16
  309. package/dist/astro/astro/server.d.ts +0 -12
  310. package/dist/astro/client.d.ts +0 -5
  311. package/dist/astro/client.esm.js +0 -4665
  312. package/dist/astro/collection.d.ts +0 -12
  313. package/dist/astro/component.d.ts +0 -22
  314. package/dist/astro/cycle/dom/BodyDOMSource.d.ts +0 -10
  315. package/dist/astro/cycle/dom/DOMSource.d.ts +0 -11
  316. package/dist/astro/cycle/dom/DocumentDOMSource.d.ts +0 -12
  317. package/dist/astro/cycle/dom/ElementFinder.d.ts +0 -8
  318. package/dist/astro/cycle/dom/EventDelegator.d.ts +0 -34
  319. package/dist/astro/cycle/dom/IsolateModule.d.ts +0 -23
  320. package/dist/astro/cycle/dom/MainDOMSource.d.ts +0 -32
  321. package/dist/astro/cycle/dom/PriorityQueue.d.ts +0 -7
  322. package/dist/astro/cycle/dom/ScopeChecker.d.ts +0 -9
  323. package/dist/astro/cycle/dom/SymbolTree.d.ts +0 -9
  324. package/dist/astro/cycle/dom/VNodeWrapper.d.ts +0 -8
  325. package/dist/astro/cycle/dom/enrichEventStream.d.ts +0 -24
  326. package/dist/astro/cycle/dom/fromEvent.d.ts +0 -6
  327. package/dist/astro/cycle/dom/index.d.ts +0 -8
  328. package/dist/astro/cycle/dom/isolate.d.ts +0 -9
  329. package/dist/astro/cycle/dom/makeDOMDriver.d.ts +0 -11
  330. package/dist/astro/cycle/dom/mockDOMSource.d.ts +0 -17
  331. package/dist/astro/cycle/dom/modules.d.ts +0 -5
  332. package/dist/astro/cycle/dom/snabbdom.d.ts +0 -22
  333. package/dist/astro/cycle/dom/styleModule.d.ts +0 -13
  334. package/dist/astro/cycle/dom/thunk.d.ts +0 -11
  335. package/dist/astro/cycle/dom/utils.d.ts +0 -8
  336. package/dist/astro/cycle/isolate/index.d.ts +0 -42
  337. package/dist/astro/cycle/run/adapt.d.ts +0 -6
  338. package/dist/astro/cycle/run/index.d.ts +0 -36
  339. package/dist/astro/cycle/run/internals.d.ts +0 -8
  340. package/dist/astro/cycle/run/types.d.ts +0 -49
  341. package/dist/astro/cycle/state/Collection.d.ts +0 -29
  342. package/dist/astro/cycle/state/StateSource.d.ts +0 -20
  343. package/dist/astro/cycle/state/index.d.ts +0 -5
  344. package/dist/astro/cycle/state/pickCombine.d.ts +0 -3
  345. package/dist/astro/cycle/state/pickMerge.d.ts +0 -3
  346. package/dist/astro/cycle/state/types.d.ts +0 -18
  347. package/dist/astro/cycle/state/withState.d.ts +0 -17
  348. package/dist/astro/extra/classes.d.ts +0 -7
  349. package/dist/astro/extra/devtools.d.ts +0 -78
  350. package/dist/astro/extra/dragDriver.d.ts +0 -20
  351. package/dist/astro/extra/driverFactories.d.ts +0 -12
  352. package/dist/astro/extra/eventDriver.d.ts +0 -9
  353. package/dist/astro/extra/exactState.d.ts +0 -1
  354. package/dist/astro/extra/hmr.d.ts +0 -17
  355. package/dist/astro/extra/logDriver.d.ts +0 -2
  356. package/dist/astro/extra/processDrag.d.ts +0 -19
  357. package/dist/astro/extra/processForm.d.ts +0 -15
  358. package/dist/astro/extra/run.d.ts +0 -13
  359. package/dist/astro/extra/xstreamCompat.d.ts +0 -5
  360. package/dist/astro/index.d.ts +0 -19
  361. package/dist/astro/index.esm.js +0 -27
  362. package/dist/astro/jsx-dev-runtime.d.ts +0 -1
  363. package/dist/astro/jsx-runtime.d.ts +0 -4
  364. package/dist/astro/jsx.d.ts +0 -2
  365. package/dist/astro/pragma/fn.d.ts +0 -7
  366. package/dist/astro/pragma/index.d.ts +0 -7
  367. package/dist/astro/pragma/is.d.ts +0 -10
  368. package/dist/astro/server.d.ts +0 -12
  369. package/dist/astro/server.esm.js +0 -25
  370. package/dist/astro/switchable.d.ts +0 -7
  371. package/dist/collection.d.ts +0 -12
  372. package/dist/component.d.ts +0 -22
  373. package/dist/cycle/dom/BodyDOMSource.d.ts +0 -10
  374. package/dist/cycle/dom/DOMSource.d.ts +0 -11
  375. package/dist/cycle/dom/DocumentDOMSource.d.ts +0 -12
  376. package/dist/cycle/dom/ElementFinder.d.ts +0 -8
  377. package/dist/cycle/dom/EventDelegator.d.ts +0 -34
  378. package/dist/cycle/dom/IsolateModule.d.ts +0 -23
  379. package/dist/cycle/dom/MainDOMSource.d.ts +0 -32
  380. package/dist/cycle/dom/PriorityQueue.d.ts +0 -7
  381. package/dist/cycle/dom/ScopeChecker.d.ts +0 -9
  382. package/dist/cycle/dom/SymbolTree.d.ts +0 -9
  383. package/dist/cycle/dom/VNodeWrapper.d.ts +0 -8
  384. package/dist/cycle/dom/enrichEventStream.d.ts +0 -24
  385. package/dist/cycle/dom/fromEvent.d.ts +0 -6
  386. package/dist/cycle/dom/index.d.ts +0 -8
  387. package/dist/cycle/dom/isolate.d.ts +0 -9
  388. package/dist/cycle/dom/makeDOMDriver.d.ts +0 -11
  389. package/dist/cycle/dom/mockDOMSource.d.ts +0 -17
  390. package/dist/cycle/dom/modules.d.ts +0 -5
  391. package/dist/cycle/dom/snabbdom.d.ts +0 -22
  392. package/dist/cycle/dom/styleModule.d.ts +0 -13
  393. package/dist/cycle/dom/thunk.d.ts +0 -11
  394. package/dist/cycle/dom/utils.d.ts +0 -8
  395. package/dist/cycle/isolate/index.d.ts +0 -42
  396. package/dist/cycle/run/adapt.d.ts +0 -6
  397. package/dist/cycle/run/index.d.ts +0 -36
  398. package/dist/cycle/run/internals.d.ts +0 -8
  399. package/dist/cycle/run/types.d.ts +0 -49
  400. package/dist/cycle/state/Collection.d.ts +0 -29
  401. package/dist/cycle/state/StateSource.d.ts +0 -20
  402. package/dist/cycle/state/index.d.ts +0 -5
  403. package/dist/cycle/state/pickCombine.d.ts +0 -3
  404. package/dist/cycle/state/pickMerge.d.ts +0 -3
  405. package/dist/cycle/state/types.d.ts +0 -18
  406. package/dist/cycle/state/withState.d.ts +0 -17
  407. package/dist/extra/classes.d.ts +0 -7
  408. package/dist/extra/devtools.d.ts +0 -78
  409. package/dist/extra/dragDriver.d.ts +0 -20
  410. package/dist/extra/driverFactories.d.ts +0 -12
  411. package/dist/extra/eventDriver.d.ts +0 -9
  412. package/dist/extra/exactState.d.ts +0 -1
  413. package/dist/extra/hmr.d.ts +0 -17
  414. package/dist/extra/logDriver.d.ts +0 -2
  415. package/dist/extra/processDrag.d.ts +0 -19
  416. package/dist/extra/processForm.d.ts +0 -15
  417. package/dist/extra/run.d.ts +0 -13
  418. package/dist/extra/xstreamCompat.d.ts +0 -5
  419. package/dist/jsx-dev-runtime.d.ts +0 -1
  420. package/dist/jsx-dev-runtime.js +0 -224
  421. package/dist/jsx-runtime.d.ts +0 -4
  422. package/dist/jsx-runtime.js +0 -224
  423. package/dist/jsx.d.ts +0 -2
  424. package/dist/pragma/fn.d.ts +0 -7
  425. package/dist/pragma/index.d.ts +0 -7
  426. package/dist/pragma/is.d.ts +0 -10
  427. package/dist/switchable.d.ts +0 -7
  428. package/dist/vike/+config.cjs.js +0 -65
  429. package/src/component.ts +0 -2256
  430. package/src/cycle/isolate/index.ts +0 -196
  431. package/src/cycle/run/index.ts +0 -151
  432. package/src/cycle/run/internals.ts +0 -143
  433. package/src/cycle/state/Collection.ts +0 -174
  434. package/src/cycle/state/index.ts +0 -5
  435. package/src/cycle/state/pickCombine.ts +0 -167
  436. package/src/cycle/state/pickMerge.ts +0 -122
  437. package/src/cycle/state/withState.ts +0 -47
  438. package/src/pragma/fn.ts +0 -55
@@ -1,25 +1,1054 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { createRequire } from 'node:module';
4
+ import { fileURLToPath, pathToFileURL } from 'node:url';
5
+
6
+ /**
7
+ * G-099: xstream does `require('globalthis').getPolyfill()`, which pulls the
8
+ * `globalthis` polyfill and its dependency chain (define-properties,
9
+ * get-intrinsic, object-keys, has-symbols, ...; ~4 KB gzip) into every app
10
+ * bundle. Every runtime Sygnal supports has a native `globalThis`, so
11
+ * `sygnal/vite` (and the sygnal/astro integration) alias the package to
12
+ * dist/shims/globalthis.cjs (src/vite/globalthis-shim.ts) unless
13
+ * `nativeGlobalThis: false`. A `resolve.alias`, not a resolveId hook: Vite's
14
+ * dependency pre-bundling only applies aliases.
15
+ */
16
+ // Node built-ins (this runs in Node). The package has no @types/node.
17
+ // @ts-ignore
18
+ /**
19
+ * Absolute path of the stub in the sygnal package this code belongs to (found
20
+ * by walking up from this file: dist/vite, dist/astro or src/vite), or
21
+ * undefined when it is missing (e.g. sygnal not built).
22
+ */
23
+ function globalThisShim() {
24
+ try {
25
+ let dir = path.dirname(fileURLToPath(import.meta.url));
26
+ while (dir !== path.dirname(dir)) {
27
+ const pkgFile = path.join(dir, 'package.json');
28
+ if (fs.existsSync(pkgFile) && JSON.parse(fs.readFileSync(pkgFile, 'utf8')).name === 'sygnal') {
29
+ const file = path.join(dir, 'dist', 'shims', 'globalthis.cjs');
30
+ return fs.existsSync(file) ? file : undefined;
31
+ }
32
+ dir = path.dirname(dir);
33
+ }
34
+ }
35
+ catch (_) { }
36
+ return undefined;
37
+ }
38
+ /**
39
+ * Whether a Vite `resolve.alias` value (object or array form) already maps
40
+ * `globalthis` (R2-7): the user's alias wins and the stub is not added.
41
+ */
42
+ function hasGlobalThisAlias(alias) {
43
+ if (!alias)
44
+ return false;
45
+ if (!Array.isArray(alias))
46
+ return Object.prototype.hasOwnProperty.call(alias, 'globalthis');
47
+ return alias.some((a) => a && (a.find instanceof RegExp ? a.find.test('globalthis') : a.find === 'globalthis'));
48
+ }
49
+ /**
50
+ * Vite `resolve.alias` entries for the stub (empty when it is missing, or
51
+ * when `userAlias` — the user's `resolve.alias` — already maps `globalthis`).
52
+ */
53
+ function globalThisAlias(userAlias) {
54
+ const shim = hasGlobalThisAlias(userAlias) ? undefined : globalThisShim();
55
+ return shim ? [{ find: /^globalthis$/, replacement: shim }] : [];
56
+ }
57
+
58
+ /**
59
+ * Sygnal Vite Plugin
60
+ *
61
+ * Auto-configures JSX, wires up HMR with state preservation and, in dev,
62
+ * turns on Sygnal's diagnostics (runtime checks and the static checker).
63
+ * Nothing it adds in dev reaches a production build.
64
+ *
65
+ * Usage:
66
+ * import sygnal from 'sygnal/vite'
67
+ * export default defineConfig({ plugins: [sygnal()] })
68
+ *
69
+ * What it does:
70
+ * 1. Configures the automatic JSX transform with sygnal as the import source:
71
+ * `oxc` (Vite 8), plus `esbuild` under Vite 7 and older
72
+ * 2. Detects files that call `run()` from sygnal and auto-injects HMR wiring.
73
+ * A module that calls `defineElement()` from 'sygnal/element' at the top level
74
+ * (and doesn't import run()) gets `if (import.meta.hot) import.meta.hot.accept()`
75
+ * appended: re-running it swaps the elements' component, keeping their state
76
+ * 3. Dev mode (`vite` / `vite dev` only; never `vite build`). Into every
77
+ * file that imports `run` from sygnal (including entries with manual HMR
78
+ * wiring or `disableHmr`) it inserts, on an existing line:
79
+ *
80
+ * if (globalThis.__SYGNAL_DEV__ === undefined) globalThis.__SYGNAL_DEV__ = true;
81
+ * import 'sygnal/diagnostics';import 'virtual:sygnal/dev';
82
+ *
83
+ * The flag turns on runtime diagnostics in 'warn' mode; 'sygnal/diagnostics'
84
+ * registers the runtime checks (SYG101-106, 201, 202, 301, 401, ...);
85
+ * 'virtual:sygnal/dev' logs static-check results in the browser console
86
+ * (see 5). With `diagnostics: { strict: true }` the snippet also sets
87
+ * `globalThis.__SYGNAL_STRICT__ = true` (same guard), which turns on the
88
+ * strict (SYG5xx) runtime checks of 'sygnal/diagnostics'. The snippet goes
89
+ * after any shebang line and directive prologue ('use strict',
90
+ * 'use client'); line numbers are unchanged and the transform returns a
91
+ * sourcemap. Opt out per app with `run(App, drivers, { diagnostics: 'off' })`
92
+ * or for the whole dev server with `sygnal({ diagnostics: 'off' })`.
93
+ * 4. `diagnostics` option. The runtime core only understands
94
+ * `__SYGNAL_DEV__ === true` ('warn'), so another mode or an ignore list
95
+ * is passed as run()'s own `diagnostics` option: imports of 'sygnal'
96
+ * from the entry files above resolve to a dev-only wrapper module
97
+ * ('\0sygnal-dev:runtime') that re-exports sygnal with a run() that adds
98
+ * `diagnostics: { mode, ignore }` unless the call sets `diagnostics`
99
+ * itself. With the default ('warn', no ignore list) there is no wrapper.
100
+ * 5. `check` option: runs sygnal-check (an optional dependency, loaded
101
+ * lazily from the project; `strict` defaults to `diagnostics.strict`)
102
+ * over `include` (default: the existing ones of src/, pages/ and
103
+ * renderer/, else the project root, with a notice) when the dev
104
+ * server starts and again after every source file change. Results go to
105
+ * the terminal in sygnal-check's format, and to the browser as a
106
+ * 'sygnal:check' HMR event that the dev client ('virtual:sygnal/dev')
107
+ * logs with console.warn (non-disruptive). The dev client asks for the
108
+ * current findings when the page loads ('sygnal:check:request'), and only
109
+ * that client is answered; after a source change the new findings go to
110
+ * every connected client, and only when they changed. Error-severity
111
+ * findings also open Vite's error overlay (`overlay: false`: never):
112
+ * SYG112, SYG124, SYG125, SYG128, SYG405 and the checker's other
113
+ * error-severity codes. The a11y lane SYG701-708 is a warning, also
114
+ * under `diagnostics.strict` (D144, amending D111); `check.a11y: 'error'`
115
+ * makes it an error (and opens the overlay). Without that opt-in a 7xx
116
+ * finding never opens the overlay, even from an older sygnal-check that
117
+ * reports it as an error under strict. Everything else is a warning or
118
+ * info and goes to the console. Warnings never use the overlay: while
119
+ * one is open Vite's client reloads the page on the next HMR update
120
+ * (`overlay: 'warn'` is treated as 'error', with a notice). The dev
121
+ * client closes a sygnal-check overlay before each update, and the
122
+ * server sends it again after the re-check, so it never causes a reload
123
+ * and doesn't go stale. A missing sygnal-check is skipped silently; a
124
+ * checker that throws only logs a warning.
125
+ * 6. Vitest (process.env.VITEST): appends the package's 'sygnal/diagnostics'
126
+ * ESM file to `test.setupFiles` (merged with a string or array value;
127
+ * not added twice), so renderComponent tests get the runtime checks.
128
+ * Its directory is added to the resolved `server.fs.allow` (G-050):
129
+ * in jsdom / happy-dom environments Vitest loads setup files through
130
+ * Vite's /@fs/ URLs, which a linked sygnal outside the workspace would
131
+ * otherwise fail. Opt out with `vitestSetup: false`. Under Vitest the transform adds
132
+ * nothing (no flags, HMR wiring, run() wrapper, dev client or checker):
133
+ * a __SYGNAL_DEV__ / __SYGNAL_STRICT__ flag set by one test file would
134
+ * leak into later test files of the same worker, and renderComponent()
135
+ * manages the diagnostics modes itself.
136
+ * 7. Vike and Astro (G-014): the app is started by sygnal's own client
137
+ * entry, which user code doesn't import. Client-side imports of
138
+ * 'sygnal/vike/onRenderClient' resolve to a dev wrapper that sets the
139
+ * flag and loads the checks first. That entry is excluded from
140
+ * pre-bundling in dev (B-020), so it shares the pages' core. Astro resolves its renderer entry on
141
+ * the server and the browser loads the file itself, so the same snippet
142
+ * is added to sygnal's 'astro/client' file by the transform. That file
143
+ * imports the public 'sygnal' entry (one shared core, B-019), so its
144
+ * 'sygnal' import gets the run() wrapper too: every `diagnostics` mode
145
+ * and ignore list works for islands. The sygnal/astro integration adds
146
+ * this plugin in `astro dev`.
147
+ * 8. `nativeGlobalThis` (G-099, default true): a `resolve.alias` from
148
+ * `globalthis` (xstream's `require('globalthis').getPolyfill()`) to the
149
+ * package's dist/shims/globalthis.cjs, which returns the native
150
+ * globalThis. Drops the polyfill chain (~4 KB gzip) from every bundle,
151
+ * in dev (including pre-bundling), build and Vitest. Dependencies left
152
+ * external (SSR, Vitest) still load the real package from Node. The
153
+ * sygnal/astro integration adds the same alias in `astro build`. Any
154
+ * dependency's `require('globalthis')` gets the stub; a `globalthis`
155
+ * entry in the user's own `resolve.alias` wins (R2-7).
156
+ * 9. `devtools` option (D77, default true): in dev the same files (run()
157
+ * importers, the Vike wrapper, the Astro client) also get
158
+ * `import 'sygnal/devtools';`, first, which installs the DevTools bridge
159
+ * (window.__SYGNAL_DEVTOOLS__) for the browser extension. Independent of
160
+ * `diagnostics` ('off' still injects it). Never in `vite build` or under
161
+ * Vitest: production builds carry no DevTools code. `devtools: false`
162
+ * injects nothing. PLAN-4 3-E: `devtools: { redux: true }` also calls
163
+ * connectReduxDevtools() (actions + state to the Redux DevTools extension).
164
+ *
165
+ * Why not Vite's `define`? Vite's dependency optimizer does not apply user
166
+ * `define` replacements to pre-bundled dependencies (only process.env.NODE_ENV),
167
+ * so a `define` would never reach sygnal's own code when sygnal is pre-bundled.
168
+ * Vite's client does copy `define` entries onto globalThis at runtime, but only
169
+ * when `/@vite/client` is loaded (not under SSR or Vitest, where it would also
170
+ * switch diagnostics on for every test run). Injecting the flag into the
171
+ * entry file that calls run() is deterministic and scoped to the dev app; it
172
+ * runs before run() is called, which is when the diagnostics mode is resolved.
173
+ *
174
+ * The HMR transform finds the pattern:
175
+ * import { run } from 'sygnal'
176
+ * import App from './App.jsx'
177
+ * run(App)
178
+ *
179
+ * And appends:
180
+ * if (import.meta.hot) {
181
+ * import.meta.hot.accept('./App.jsx', __sygnal.hmr)
182
+ * import.meta.hot.dispose(__sygnal.dispose)
183
+ * }
184
+ *
185
+ * HMR wiring is only added for a recognized top-level (column 0) run()
186
+ * statement whose result reference is actually defined (see RUN_CALL_RE). It
187
+ * is skipped — the dev flag is still injected — for any other shape (e.g.
188
+ * `app = run(App)`, nested or indented calls), for test files (*.test.*,
189
+ * *.spec.*) and under Vitest (process.env.VITEST).
190
+ */
191
+ // Node built-ins (the plugin runs in Node). The package has no @types/node.
192
+ // @ts-ignore
193
+ const nodeProcess = globalThis.process;
194
+ // Virtual modules (dev server only)
195
+ const DEV_CLIENT = 'virtual:sygnal/dev';
196
+ const DEV_CLIENT_ID = '\0' + DEV_CLIENT;
197
+ const RUNTIME_ID = '\0sygnal-dev:runtime';
198
+ const VIKE_CLIENT = 'sygnal/vike/onRenderClient';
199
+ const VIKE_CLIENT_ID = '\0sygnal-dev:vike-client';
200
+ const CHECK_EVENT = 'sygnal:check';
201
+ // Sent by the dev client when it loads: the server answers that client only
202
+ const CHECK_REQUEST = 'sygnal:check:request';
203
+ const OVERLAY_PLUGIN = 'sygnal-check';
204
+ // Register the runtime checks with the core that loaded last (see the Vike wrapper)
205
+ const REINSTALL_IMPORT = `import { installChecks as __sygnalInstallChecks } from 'sygnal/diagnostics';`;
206
+ const REINSTALL_CALL = 'try { __sygnalInstallChecks() } catch (e) { console.warn(e) }\n';
207
+ function sygnal(options = {}) {
208
+ const { disableJsx = false, disableHmr = false, vitestSetup = true, nativeGlobalThis = true } = options;
209
+ const diagnostics = normalizeDiagnostics(options.diagnostics);
210
+ const devOn = diagnostics.mode !== 'off';
211
+ // A mode other than the flag's 'warn', or an ignore list, needs run()'s option
212
+ const wrapRun = devOn && (diagnostics.mode !== 'warn' || diagnostics.ignore.length > 0);
213
+ let isServe = false;
214
+ let isVitest = false;
215
+ let root = nodeProcess.cwd();
216
+ // Files whose `import ... from 'sygnal'` resolves to the run() wrapper
217
+ const runtimeImporters = new Set();
218
+ // Statements run before the app starts: dev flag (+ strict flag)
219
+ const flags = DEV_FLAG + (diagnostics.strict ? STRICT_FLAG : '');
220
+ const devImports = `import 'sygnal/diagnostics';import '${DEV_CLIENT}';`;
221
+ // D77: the DevTools bridge, dev only. First, so the diagnostics entry finds it.
222
+ const devtoolsOn = options.devtools !== false;
223
+ const redux = typeof options.devtools == 'object' && !!options.devtools?.redux;
224
+ const devtoolsImport = !devtoolsOn ? ''
225
+ : redux ? `import { connectReduxDevtools as __sygnalReduxDevtools } from 'sygnal/devtools';__sygnalReduxDevtools();`
226
+ : `import 'sygnal/devtools';`;
227
+ // What a dev entry gets: DevTools, then (unless diagnostics are 'off') flags + checks
228
+ const devSnippet = devtoolsImport + (devOn ? flags + devImports : '');
229
+ const devInject = devOn || devtoolsOn;
230
+ let astroClient;
231
+ return {
232
+ name: 'vite-plugin-sygnal',
233
+ config(config, env) {
234
+ isServe = env.command === 'serve';
235
+ isVitest = !!nodeProcess?.env?.VITEST;
236
+ root = config?.root ? path.resolve(config.root) : nodeProcess.cwd();
237
+ const result = {
238
+ // Ensure sygnal is bundled for SSR rather than externalized.
239
+ // Without this, Node fails to resolve sygnal's exports from
240
+ // Vike's server chunks in production builds.
241
+ ssr: {
242
+ noExternal: ['sygnal'],
243
+ },
244
+ };
245
+ // G-099: xstream's `require('globalthis')` gets the native-globalThis
246
+ // stub. An alias (not resolveId) so it also applies to pre-bundling.
247
+ // R2-7: not when the user's config already aliases `globalthis`.
248
+ const alias = nativeGlobalThis ? globalThisAlias(config?.resolve?.alias) : [];
249
+ if (alias.length)
250
+ result.resolve = { alias };
251
+ if (!disableJsx) {
252
+ result.oxc = {
253
+ jsx: {
254
+ runtime: 'automatic',
255
+ importSource: 'sygnal',
256
+ },
257
+ };
258
+ // Vite 7 and older (Astro 6, Vitest on Vite 7) compile JSX with
259
+ // esbuild and ignore `oxc` (B-027); Vite 8 warns about `esbuild`
260
+ // from a plugin, so it is only set below Vite 8.
261
+ if (viteMajor(this, root) < 8) {
262
+ result.esbuild = { jsx: 'automatic', jsxImportSource: 'sygnal' };
263
+ }
264
+ // Vite 8's dependency scanner doesn't use the `oxc` options: without
265
+ // this it compiles JSX for React, fails to resolve
266
+ // react/jsx-dev-runtime and skips pre-bundling (a reload on first load).
267
+ if (isServe && !isVitest) {
268
+ result.optimizeDeps = { rolldownOptions: { transform: { jsx: { runtime: 'automatic', importSource: 'sygnal' } } } };
269
+ }
270
+ }
271
+ if (isVitest) {
272
+ if (vitestSetup) {
273
+ const setup = diagnosticsSetupFile(root);
274
+ const existing = [].concat(config?.test?.setupFiles || []);
275
+ const loaded = existing.some(f => typeof f === 'string' &&
276
+ (f === 'sygnal/diagnostics' || (!!setup && path.resolve(root, f) === setup)));
277
+ // Vite merges arrays (and a string with an array) by concatenation
278
+ if (setup && !loaded)
279
+ result.test = { setupFiles: [setup] };
280
+ }
281
+ }
282
+ else if (isServe && devInject && sygnalInNodeModules(root)) {
283
+ // The dependency scan reads the original sources, which don't import
284
+ // the checks (or DevTools) entry: pre-bundle it with sygnal so the first
285
+ // page load doesn't trigger a re-optimization. Only for an installed
286
+ // sygnal: a linked one is served from source, and pre-bundling the
287
+ // checks alone would give them their own copy of the core.
288
+ const include = [...(devtoolsOn ? ['sygnal/devtools'] : []), ...(devOn ? ['sygnal/diagnostics'] : [])];
289
+ result.optimizeDeps = { ...result.optimizeDeps, include };
290
+ }
291
+ // B-020: Vike adds its client entry 'sygnal/vike/onRenderClient' to
292
+ // optimizeDeps.include. With a linked sygnal, the pages' 'sygnal' is
293
+ // served from source while that pre-bundle inlines a second copy of the
294
+ // core. Unbundled, the entry's own `import 'sygnal'` resolves like the
295
+ // pages' imports (source when linked, the shared pre-bundle when
296
+ // installed): one core. Vike honours the exclude list.
297
+ // G-098: Vite doesn't discover the imports of an excluded dependency, so for an
298
+ // installed sygnal 'sygnal' is pre-bundled up front (pages that reach it only through
299
+ // the JSX runtime would otherwise get it, and its CommonJS xstream, unbundled).
300
+ if (isServe && !isVitest) {
301
+ const include = result.optimizeDeps?.include || [];
302
+ result.optimizeDeps = {
303
+ ...result.optimizeDeps,
304
+ exclude: [VIKE_CLIENT],
305
+ ...(sygnalInNodeModules(root) ? { include: [...include, 'sygnal'] } : {}),
306
+ };
307
+ }
308
+ return result;
309
+ },
310
+ configResolved(config) {
311
+ if (config?.root)
312
+ root = config.root;
313
+ // G-050: Vitest loads setup files by URL (/@fs/...) in browser-like
314
+ // environments (jsdom, happy-dom), and Vite refuses files outside
315
+ // server.fs.allow, which is the project's workspace by default. A linked
316
+ // (or hoisted) sygnal lives outside it, so allow its setup file's
317
+ // directory. The resolved list already holds Vite's defaults.
318
+ if (isVitest) {
319
+ const setup = diagnosticsSetupFile(root);
320
+ const allow = config?.server?.fs?.allow;
321
+ if (setup && Array.isArray(allow)) {
322
+ const dir = path.dirname(setup);
323
+ const inside = (base) => {
324
+ const rel = path.relative(path.resolve(base), dir);
325
+ return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
326
+ };
327
+ if (!allow.some(inside))
328
+ allow.push(dir);
329
+ }
330
+ }
331
+ },
332
+ resolveId: {
333
+ order: 'pre',
334
+ async handler(source, importer, opts) {
335
+ if (!isServe || isVitest)
336
+ return null;
337
+ if (source === DEV_CLIENT)
338
+ return DEV_CLIENT_ID;
339
+ if (source === 'sygnal' && importer && wrapRun && runtimeImporters.has(cleanId(importer))) {
340
+ return RUNTIME_ID;
341
+ }
342
+ if (source === VIKE_CLIENT && devInject && !opts?.ssr) {
343
+ if (importer !== VIKE_CLIENT_ID)
344
+ return VIKE_CLIENT_ID;
345
+ // The wrapper's own import of the real entry: resolve it normally.
346
+ // The real Vike client's run() then gets the run() wrapper too, when
347
+ // it is served unbundled (a pre-bundled copy stays in 'warn' mode).
348
+ const real = await this.resolve(source, importer, { ...opts, skipSelf: true });
349
+ if (real && wrapRun)
350
+ runtimeImporters.add(cleanId(real.id));
351
+ return real;
352
+ }
353
+ return null;
354
+ },
355
+ },
356
+ load(id) {
357
+ if (id === DEV_CLIENT_ID)
358
+ return devClientModule();
359
+ if (id === RUNTIME_ID)
360
+ return runtimeModule(diagnostics);
361
+ // The checks register again once the real entry has loaded: a
362
+ // pre-bundled copy of it can carry its own copy of the Sygnal core
363
+ // (e.g. with a linked sygnal), which then holds the diagnostics bridge.
364
+ if (id === VIKE_CLIENT_ID) {
365
+ if (!devOn)
366
+ return `${devtoolsImport}\nexport * from '${VIKE_CLIENT}';\n`;
367
+ return `${devtoolsImport}${devImports}${REINSTALL_IMPORT}\nexport * from '${VIKE_CLIENT}';\n${flags}\n${REINSTALL_CALL}`;
368
+ }
369
+ return null;
370
+ },
371
+ configureServer(server) {
372
+ if (isVitest || options.check === false)
373
+ return;
374
+ const checkOptions = typeof options.check === 'object' && options.check ? options.check : {};
375
+ // Deferred: the dev server doesn't wait for the first check
376
+ const checkDefaults = { strict: diagnostics.strict, ignore: diagnostics.ignore };
377
+ setTimeout(() => {
378
+ startChecker(server, root, checkOptions, checkDefaults, options.check !== undefined)
379
+ .catch(err => server?.config?.logger?.warn?.(`[sygnal] sygnal-check could not start: ${err?.message || err}`));
380
+ }, 0);
381
+ },
382
+ transform(code, id, opts) {
383
+ // SYG666 (PLAN-5 W-2): an adapter entry imported without its optional peers; every mode
384
+ const adapters = adapterImports(this, code, id);
385
+ if (adapters)
386
+ return checkPeers(this, adapters, id).then(() => devTransform.call(this, code, id, opts));
387
+ return devTransform.call(this, code, id, opts);
388
+ },
389
+ };
390
+ function devTransform(code, id, opts) {
391
+ if (!isServe)
392
+ return null;
393
+ // sygnal/astro/client (Astro islands): flags + checks first. It imports
394
+ // the public 'sygnal' entry (the app's core, B-019), which resolves to
395
+ // the run() wrapper when the diagnostics option needs it.
396
+ if (devInject && !isVitest && !opts?.ssr) {
397
+ astroClient = astroClient || astroClientFiles(root);
398
+ if (astroClient.has(cleanId(id))) {
399
+ if (wrapRun)
400
+ runtimeImporters.add(cleanId(id));
401
+ return withSourcemap(code, [[0, devSnippet]], '', id);
402
+ }
403
+ }
404
+ // Only transform JS/TS/JSX/TSX files
405
+ if (!/\.[jt]sx?$/.test(id))
406
+ return null;
407
+ // Skip node_modules
408
+ if (id.includes('node_modules'))
409
+ return null;
410
+ // Must import run from sygnal
411
+ if (!code.includes('sygnal'))
412
+ return null;
413
+ // Match against the code with comments blanked out (same offsets), so
414
+ // e.g. `// run(App)` or a commented-out import is never matched.
415
+ const noComments = blankOut(code, false);
416
+ // Find: import { run, ... } from 'sygnal'
417
+ const runImportRe = /import\s+\{[^}]*\brun\b[^}]*\}\s+from\s+['"]sygnal['"]/;
418
+ if (!runImportRe.test(noComments)) {
419
+ return disableHmr || isVitest ? null : elementHmr(code, noComments, id);
420
+ }
421
+ // Dev snippet: injected into every file that imports run() — also when
422
+ // HMR wiring below is skipped. Inserted after any shebang line and
423
+ // directive prologue, without adding a line. Nothing under Vitest: a
424
+ // global flag set by one test file would leak dev/strict mode into the
425
+ // later test files of the same worker; there the checks come from
426
+ // test.setupFiles and renderComponent() manages the modes.
427
+ const inserts = [];
428
+ if (devInject && !isVitest) {
429
+ inserts.push(flagInsertion(code, devSnippet));
430
+ if (wrapRun)
431
+ runtimeImporters.add(cleanId(id));
432
+ }
433
+ const done = (tail = '') => (inserts.length || tail ? withSourcemap(code, inserts, tail, id) : null);
434
+ // Skip HMR wiring if disabled, in tests, or already manually wired
435
+ if (disableHmr || isVitest || /\.(test|spec)\.[jt]sx?$/.test(id))
436
+ return done();
437
+ if (noComments.includes('import.meta.hot'))
438
+ return done();
439
+ // Strings and template literals blanked out too: a statement-level match only
440
+ const runCall = RUN_CALL_RE.exec(blankOut(code, true));
441
+ if (!runCall)
442
+ return done();
443
+ const [, binding, componentName] = runCall;
444
+ // Find the import path for this component
445
+ // Handles: import App from './App.jsx'
446
+ // import App from "./App"
447
+ const componentImportRe = new RegExp(`import\\s+${componentName.replace(/\$/g, '\\$')}\\s+from\\s+['"]([^'"]+)['"]`);
448
+ const componentImportMatch = noComments.match(componentImportRe);
449
+ if (!componentImportMatch)
450
+ return done();
451
+ const componentPath = componentImportMatch[1];
452
+ // Pattern 3: bare run(App, ...) — no result captured → const __sygnal = run(
453
+ if (!binding) {
454
+ inserts.push([runCall.index, 'const __sygnal = ']);
455
+ return done(hmrBlock(componentPath, '__sygnal.hmr', '__sygnal.dispose'));
456
+ }
457
+ // Pattern 2: const app = run(App, ...)
458
+ if (binding[0] !== '{') {
459
+ return done(hmrBlock(componentPath, `${binding}.hmr`, `${binding}.dispose`));
460
+ }
461
+ // Pattern 1: const { hmr, dispose, ... } = run(App, ...) — only when both
462
+ // are bound under their own names (a rename would leave them undefined)
463
+ const names = binding.slice(1, -1).split(',').map(s => s.trim());
464
+ if (names.includes('hmr') && names.includes('dispose')) {
465
+ return done(hmrBlock(componentPath, 'hmr', 'dispose'));
466
+ }
467
+ return done();
468
+ }
469
+ }
470
+ // PLAN-5 W-2 (D209): the adapter entries and the optional peer dependencies each one imports
471
+ // (the Zag packages pinned together: they depend on each other's exact versions)
472
+ const ZAG = '~1.45.0';
473
+ const ADAPTER_PEERS = {
474
+ react: ['react', 'react-dom'],
475
+ zag: ['@zag-js/vanilla'],
476
+ // D211: one subpath per Zag part, each needing only its own machine
477
+ 'ui/menu': ['@zag-js/vanilla', '@zag-js/menu'],
478
+ 'ui/select': ['@zag-js/vanilla', '@zag-js/select'],
479
+ 'ui/combobox': ['@zag-js/vanilla', '@zag-js/combobox'],
480
+ };
481
+ // G-440: a dynamic import's specifier may be a template literal without substitutions
482
+ const ADAPTER_RE = /(?:\bfrom|\bimport)\s*\(?\s*(['"`])sygnal\/(react|zag|ui\/(?:menu|select|combobox))\1/g;
483
+ const ADAPTER_ID = /^sygnal\/(react|zag|ui\/(?:menu|select|combobox))$/;
484
+ /**
485
+ * The adapter entries an app module imports (statically, dynamically or in a re-export), or null.
486
+ * G-415: real imports only. The module's AST from the plugin context's parse() (Vite and Rollup
487
+ * provide it; the code is plain JS by then); when there is none, or the code doesn't parse, a
488
+ * scan of the code with comments blanked whose `from` / `import` keyword isn't inside a string
489
+ * or template literal. A literal that mentions an entry (a docs snippet) is never an import.
490
+ */
491
+ function adapterImports(ctx, code, id) {
492
+ if (!code.includes('sygnal/') || id.includes('node_modules') || !/\.[cm]?[jt]sx?$/.test(cleanId(id)))
493
+ return null;
494
+ const noComments = blankOut(code, false);
495
+ if (!ADAPTER_RE.test(noComments))
496
+ return null;
497
+ ADAPTER_RE.lastIndex = 0;
498
+ const found = new Set();
499
+ let ast = null;
500
+ try {
501
+ ast = typeof ctx?.parse == 'function' ? ctx.parse(code) : null;
502
+ }
503
+ catch (_) { }
504
+ if (ast) {
505
+ const walk = (n) => {
506
+ if (!n || typeof n != 'object')
507
+ return;
508
+ if (Array.isArray(n))
509
+ return n.forEach(walk);
510
+ if (/^(Import|Export(Named|All))Declaration$|^ImportExpression$/.test(n.type)) {
511
+ // G-440: import(`sygnal/zag`): a template literal without substitutions is a known specifier
512
+ const src = n.source, q = src?.type == 'TemplateLiteral' && !src.expressions?.length ? src.quasis?.[0]?.value?.cooked : src?.value;
513
+ const m = ADAPTER_ID.exec(q ?? '');
514
+ if (m)
515
+ found.add(m[1]);
516
+ }
517
+ for (const k in n)
518
+ if (k != 'type' && typeof n[k] == 'object')
519
+ walk(n[k]);
520
+ };
521
+ walk(ast);
522
+ }
523
+ else {
524
+ // strings and templates blanked too: a keyword there is text, not an import
525
+ const noStrings = blankOut(code, true);
526
+ for (const m of noComments.matchAll(ADAPTER_RE)) {
527
+ if (noStrings.startsWith(m[0].slice(0, m[0][0] == 'f' ? 4 : 6), m.index))
528
+ found.add(m[2]);
529
+ }
530
+ }
531
+ return found.size ? [...found] : null;
532
+ }
533
+ /** SYG666: resolves each entry's peers from the importing module; reports the missing ones */
534
+ async function checkPeers(ctx, entries, id) {
535
+ for (const e of entries) {
536
+ const missing = [];
537
+ for (const peer of ADAPTER_PEERS[e]) {
538
+ let r = null;
539
+ try {
540
+ r = await ctx.resolve(peer, id, { skipSelf: true });
541
+ }
542
+ catch (_) { }
543
+ if (!r)
544
+ missing.push(peer);
545
+ }
546
+ if (!missing.length)
547
+ continue;
548
+ const install = missing.map(m => (m.startsWith('@zag-js/') ? `${m}@${ZAG}` : m)).join(' ');
549
+ ctx.error(`[Sygnal SYG666] 'sygnal/${e}' needs ${missing.join(', ')}, which ${missing.length > 1 ? "aren't" : "isn't"} installed: npm install ${install}.` +
550
+ (e == 'react' ? " (For Preact: alias react, react-dom and react-dom/client to preact/compat.)" : '') +
551
+ ' https://sygnal.js.org/reference/errors#syg666');
552
+ }
553
+ }
554
+ /**
555
+ * Major version of the running Vite: from the plugin context (this.meta,
556
+ * Vite 7+), else from the vite package the project resolves. Infinity when
557
+ * unknown (treated as Vite 8+: no `esbuild` option).
558
+ */
559
+ function viteMajor(ctx, root) {
560
+ const fromMeta = ctx?.meta?.viteVersion;
561
+ if (typeof fromMeta === 'string')
562
+ return parseInt(fromMeta, 10);
563
+ if (ctx?.meta?.rolldownVersion)
564
+ return 8;
565
+ try {
566
+ const req = createRequire(path.join(root, 'package.json'));
567
+ const v = JSON.parse(fs.readFileSync(req.resolve('vite/package.json'), 'utf8')).version;
568
+ const major = parseInt(v, 10);
569
+ if (major > 0)
570
+ return major;
571
+ }
572
+ catch (_) { }
573
+ return Infinity;
574
+ }
575
+ const MODES = ['off', 'collect', 'warn', 'error'];
576
+ function normalizeDiagnostics(value) {
577
+ const o = typeof value === 'string' ? { mode: value } : value || {};
578
+ const mode = o.mode === undefined ? 'warn' : o.mode;
579
+ if (!MODES.includes(mode)) {
580
+ throw new Error(`[vite-plugin-sygnal] diagnostics mode must be one of ${MODES.map(m => `'${m}'`).join(', ')}; got ${JSON.stringify(mode)}`);
581
+ }
582
+ return { mode, strict: !!o.strict, ignore: Array.isArray(o.ignore) ? o.ignore.map(String) : [] };
583
+ }
584
+ /** Module id without a query or hash. */
585
+ function cleanId(id) {
586
+ return id.replace(/[?#].*$/, '');
587
+ }
588
+ /** 'virtual:sygnal/dev': logs sygnal-check results in the browser console. */
589
+ function devClientModule() {
590
+ // Vite's client reloads the page on the first HMR update while an error
591
+ // overlay is open. A sygnal-check overlay is closed before each update (the
592
+ // server sends it again after the re-check), so it never causes a reload.
593
+ return `if (import.meta.hot) {
594
+ let shown = 0;
595
+ let ours = false;
596
+ const closeOurs = () => {
597
+ if (!ours || typeof document === 'undefined') return;
598
+ document.querySelectorAll('vite-error-overlay').forEach((n) => n.close ? n.close() : n.remove());
599
+ ours = false;
600
+ };
601
+ import.meta.hot.on('vite:error', (payload) => {
602
+ ours = !!(payload && payload.err && payload.err.plugin === '${OVERLAY_PLUGIN}');
603
+ });
604
+ import.meta.hot.on('vite:beforeUpdate', closeOurs);
605
+ import.meta.hot.on('${CHECK_EVENT}', (payload) => {
606
+ const list = (payload && payload.diagnostics) || [];
607
+ if (!list.some((d) => d.severity === 'error')) closeOurs();
608
+ if (!list.length) {
609
+ if (shown) console.info('[sygnal-check] all findings resolved');
610
+ shown = 0;
611
+ return;
612
+ }
613
+ shown = list.length;
614
+ for (const d of list) console[d.severity === 'error' ? 'error' : 'warn']('[sygnal-check] ' + d.text);
615
+ console.info('[sygnal-check] ' + payload.summary);
616
+ });
617
+ import.meta.hot.send('${CHECK_REQUEST}');
618
+ }
619
+ `;
620
+ }
621
+ /** '\0sygnal-dev:runtime': sygnal with a run() that adds the plugin's diagnostics option. */
622
+ function runtimeModule(d) {
623
+ const option = JSON.stringify({ mode: d.mode, ignore: d.ignore });
624
+ return `import { run as __run } from 'sygnal';
625
+ export * from 'sygnal';
626
+ export function run(app, drivers, options) {
627
+ if (options && options.diagnostics !== undefined) return __run(app, drivers, options);
628
+ return __run(app, drivers, Object.assign({}, options, { diagnostics: ${option} }));
629
+ }
630
+ `;
631
+ }
632
+ /** Directory of the 'sygnal' package the project resolves, or undefined. */
633
+ function sygnalPackageDir(root) {
634
+ try {
635
+ const req = createRequire(path.join(root, 'package.json'));
636
+ let dir = path.dirname(req.resolve('sygnal'));
637
+ while (dir !== path.dirname(dir)) {
638
+ const pkgFile = path.join(dir, 'package.json');
639
+ if (fs.existsSync(pkgFile) && JSON.parse(fs.readFileSync(pkgFile, 'utf8')).name === 'sygnal')
640
+ return dir;
641
+ dir = path.dirname(dir);
642
+ }
643
+ }
644
+ catch (_) { }
645
+ return undefined;
646
+ }
647
+ /** Real paths of sygnal's 'astro/client' ESM file. */
648
+ function astroClientFiles(root) {
649
+ const files = new Set();
650
+ const dir = sygnalPackageDir(root);
651
+ if (!dir)
652
+ return files;
653
+ try {
654
+ const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
655
+ const entry = pkg.exports?.['./astro/client'];
656
+ const rel = typeof entry === 'string' ? entry : entry?.import;
657
+ if (typeof rel !== 'string')
658
+ return files;
659
+ const file = path.resolve(dir, rel);
660
+ files.add(file.split(path.sep).join('/'));
661
+ files.add(fs.realpathSync(file).split(path.sep).join('/'));
662
+ }
663
+ catch (_) { }
664
+ return files;
665
+ }
666
+ function sygnalInNodeModules(root) {
667
+ const dir = sygnalPackageDir(root);
668
+ if (!dir)
669
+ return false;
670
+ try {
671
+ return fs.realpathSync(dir).split(path.sep).includes('node_modules');
672
+ }
673
+ catch (_) {
674
+ return false;
675
+ }
676
+ }
677
+ /**
678
+ * Absolute path of the ESM build of 'sygnal/diagnostics' (its "import"
679
+ * condition), so the checks share the core instance the tests import.
680
+ */
681
+ function diagnosticsSetupFile(root) {
682
+ const dir = sygnalPackageDir(root);
683
+ if (!dir)
684
+ return undefined;
685
+ try {
686
+ const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
687
+ const entry = pkg.exports?.['./diagnostics'];
688
+ const rel = typeof entry === 'string' ? entry : entry?.import?.default || entry?.import || entry?.default;
689
+ if (typeof rel !== 'string')
690
+ return undefined;
691
+ const file = path.resolve(dir, rel);
692
+ return fs.existsSync(file) ? file : undefined;
693
+ }
694
+ catch (_) {
695
+ return undefined;
696
+ }
697
+ }
698
+ /** Load sygnal-check from the project (optional dependency); undefined when it is missing. */
699
+ async function loadSygnalCheck(root) {
700
+ try {
701
+ const file = createRequire(path.join(root, 'package.json')).resolve('sygnal-check');
702
+ return await import(/* @vite-ignore */ pathToFileURL(file).href);
703
+ }
704
+ catch (_) { }
705
+ try {
706
+ const name = 'sygnal-check';
707
+ return await import(/* @vite-ignore */ name);
708
+ }
709
+ catch (_) {
710
+ return undefined;
711
+ }
712
+ }
713
+ const SOURCE_RE = /\.[cm]?[jt]sx?$/;
714
+ /** sygnal-check's one-line format: `file:line:col CODE [severity] Component: message (fix)` */
715
+ function formatLine(d) {
716
+ const where = d.file ? `${d.file}:${d.line}:${d.column}` : '<sygnal-check>';
717
+ const sev = d.severity === 'warn' ? '' : ` [${d.severity}]`;
718
+ return `${where} ${d.code}${sev} ${d.component ? d.component + ': ' : ''}${d.message}${d.fix ? ` (${d.fix})` : ''}`;
719
+ }
720
+ // Source directories checked by default, those that exist (Vike apps use
721
+ // pages/ and renderer/, often without src/)
722
+ const DEFAULT_INCLUDE = ['src', 'pages', 'renderer'];
723
+ /**
724
+ * What sygnal-check checks: `include` when given, else the existing default
725
+ * directories, else the project root (sygnal-check skips node_modules, dist
726
+ * and other build output). Logs one notice when the default finds no
727
+ * directory, or when none of the given paths exists, so an empty check is
728
+ * never a silent all-clear.
729
+ */
730
+ function checkInclude(root, include, notice) {
731
+ const exists = (p) => /[*?[{]/.test(p) || fs.existsSync(path.resolve(root, p));
732
+ if (include && include.length) {
733
+ if (!include.some(exists))
734
+ notice(`[sygnal] sygnal-check: none of check.include (${include.join(', ')}) exists under ${root}, so nothing is checked`);
735
+ return include;
736
+ }
737
+ const dirs = DEFAULT_INCLUDE.filter(exists);
738
+ if (dirs.length)
739
+ return dirs;
740
+ notice(`[sygnal] sygnal-check: no ${DEFAULT_INCLUDE.join('/, ')}/ directory under ${root}; checking the project root (set check.include to choose)`);
741
+ return ['.'];
742
+ }
743
+ /** Run sygnal-check now and after source changes; report to the terminal and the browser. */
744
+ async function startChecker(server, root, opts, defaults, explicit) {
745
+ const mod = await loadSygnalCheck(root);
746
+ const logger = server?.config?.logger || console;
747
+ if (!mod || typeof mod.check !== 'function') {
748
+ if (explicit)
749
+ logger.info('[sygnal] sygnal-check is not installed, so static checks are off (npm i -D sygnal-check)');
750
+ return;
751
+ }
752
+ const include = checkInclude(root, opts.include, (m) => logger.info(m));
753
+ const ignore = opts.ignore || defaults.ignore;
754
+ const strict = opts.strict === undefined ? defaults.strict : !!opts.strict;
755
+ // D144: the a11y lane is a warning unless asked for as an error, under strict too
756
+ const a11y = opts.a11y === 'error' ? 'error' : 'warn';
757
+ // Only error-severity findings open Vite's overlay: while an overlay is open
758
+ // Vite's client reloads the page on the first HMR update, so warnings stay
759
+ // in the terminal and the browser console. overlay: 'warn' is treated as
760
+ // 'error' (with a one-time notice).
761
+ if (opts.overlay === 'warn') {
762
+ logger.info("[sygnal] check.overlay: 'warn' is treated as 'error': warnings go to the browser console, not Vite's error overlay (an open overlay makes Vite reload the page on the next update)");
763
+ }
764
+ const overlay = opts.overlay !== false;
765
+ let lastKey;
766
+ let payload = null;
767
+ let overlayErr = null;
768
+ const event = () => ({ type: 'custom', event: CHECK_EVENT, data: payload });
769
+ const errorMessage = () => ({ type: 'error', err: overlayErr });
770
+ // Every connected client (after a source change). An error with no client
771
+ // connected would be buffered by Vite and shown on the next page load.
772
+ const broadcast = (findingsChanged) => {
773
+ const ws = server.ws;
774
+ if (!ws || typeof ws.send !== 'function')
775
+ return;
776
+ try {
777
+ if (findingsChanged && payload)
778
+ ws.send(event());
779
+ if (overlayErr && !(ws.clients && ws.clients.size === 0))
780
+ ws.send(errorMessage());
781
+ }
782
+ catch (_) { }
783
+ };
784
+ const run = (initial = false) => {
785
+ let diags;
786
+ try {
787
+ diags = mod.check(include, { cwd: root, strict, ignore, a11y });
788
+ }
789
+ catch (err) {
790
+ logger.warn(`[sygnal] sygnal-check failed: ${err?.message || err}`, { timestamp: true });
791
+ return;
792
+ }
793
+ // A sygnal-check from before D144 reports SYG7xx as errors under strict: keep them warnings
794
+ if (a11y !== 'error') {
795
+ diags = diags.map(d => d && d.severity === 'error' && /^SYG7\d\d$/.test(d.code) ? { ...d, severity: 'warn' } : d);
796
+ }
797
+ const shown = diags.filter(d => d.severity !== 'info');
798
+ const lines = shown.map(formatLine);
799
+ const key = lines.join('\n');
800
+ const changed = key !== lastKey;
801
+ if (changed) {
802
+ lastKey = key;
803
+ const text = typeof mod.formatDiagnostics === 'function'
804
+ ? mod.formatDiagnostics(diags)
805
+ : lines.concat(`sygnal-check: ${shown.length} finding(s)`).join('\n');
806
+ const summary = text.split('\n').pop() || '';
807
+ if (shown.length)
808
+ logger.warn(text, { timestamp: true });
809
+ else
810
+ logger.info(summary, { timestamp: true });
811
+ payload = {
812
+ summary,
813
+ diagnostics: shown.map((d, i) => ({ code: d.code, severity: d.severity, file: d.file, line: d.line, column: d.column, text: lines[i] })),
814
+ };
815
+ const forOverlay = overlay ? shown.filter(d => d.severity === 'error') : [];
816
+ const first = forOverlay[0];
817
+ overlayErr = first ? {
818
+ plugin: OVERLAY_PLUGIN,
819
+ message: forOverlay.map(formatLine).join('\n'),
820
+ stack: '',
821
+ id: path.resolve(root, first.file || ''),
822
+ loc: { file: path.resolve(root, first.file || ''), line: first.line, column: first.column },
823
+ } : null;
824
+ }
825
+ // The first check runs before any page is open; pages ask for the
826
+ // findings when they load (CHECK_REQUEST). After a change the overlay is
827
+ // sent again even when the findings are the same: the HMR update closed it.
828
+ if (!initial)
829
+ broadcast(changed);
830
+ };
831
+ run(true);
832
+ // A page that loads (or reloads) asks for the current findings: answer
833
+ // that client only, never every client.
834
+ try {
835
+ server.ws?.on?.(CHECK_REQUEST, (_data, client) => {
836
+ try {
837
+ if (payload)
838
+ client?.send?.(event());
839
+ if (overlayErr)
840
+ client?.send?.(errorMessage());
841
+ }
842
+ catch (_) { }
843
+ });
844
+ }
845
+ catch (_) { }
846
+ let timer;
847
+ const onChange = (file) => {
848
+ if (!SOURCE_RE.test(file) || file.split(/[\\/]/).includes('node_modules'))
849
+ return;
850
+ clearTimeout(timer);
851
+ timer = setTimeout(run, 100);
852
+ };
853
+ const watcher = server?.watcher;
854
+ if (watcher && typeof watcher.on === 'function') {
855
+ watcher.on('change', onChange);
856
+ watcher.on('add', onChange);
857
+ watcher.on('unlink', onChange);
858
+ }
859
+ try {
860
+ server.httpServer?.once?.('close', () => clearTimeout(timer));
861
+ }
862
+ catch (_) { }
863
+ }
864
+ const DEV_FLAG = 'if (globalThis.__SYGNAL_DEV__ === undefined) globalThis.__SYGNAL_DEV__ = true;';
865
+ const STRICT_FLAG = 'if (globalThis.__SYGNAL_STRICT__ === undefined) globalThis.__SYGNAL_STRICT__ = true;';
866
+ // A top-level (column 0) run(Component, ...) statement: bare, or declaring a
867
+ // new binding. Assignments to existing variables, nested calls and indented
868
+ // calls (e.g. inside a function or test callback) do not match (B-007). It is
869
+ // matched against the code with comments and strings blanked out.
870
+ const RUN_CALL_RE = /^(?:(?:const|let|var)\s+(\{[^}]*\}|[\w$]+)\s*=\s*)?run\s*\(\s*([A-Z][\w$]*)/m;
871
+ // Comments, string literals and template literals (a regex literal containing
872
+ // a quote or `//` can over-blank; that only ever skips HMR wiring).
873
+ const COMMENT_OR_STRING_RE = /\/\/[^\n]*|\/\*[\s\S]*?(?:\*\/|$)|(['"])(?:\\.|(?!\1)[^\\\n])*\1?|`(?:\\[\s\S]|[^\\`])*`?/g;
874
+ /** Replace comments (and, with `strings`, string/template literals) by spaces, keeping offsets and newlines. */
875
+ function blankOut(code, strings) {
876
+ return code.replace(COMMENT_OR_STRING_RE, m => !strings && m[0] !== '/' ? m : m.replace(/[^\n]/g, ' '));
877
+ }
878
+ // One directive ('use strict', "use client", ...) with any leading whitespace
879
+ // and comments. It must end with `;` (group 2) or at the end of its line.
880
+ const DIRECTIVE_RE = /(?:\s|\/\/[^\n]*|\/\*[\s\S]*?\*\/)*(['"])(?:\\.|(?!\1)[^\\\n])*\1(?:[ \t]*(;)|(?=[ \t]*(?:\/\/[^\n]*|\/\*[^\n]*?\*\/)?[ \t]*(?:\r?\n|$)))/y;
881
+ /** Insert `text` (the dev snippet) after a shebang line and the directive prologue. */
882
+ function flagInsertion(code, text) {
883
+ let at = code.startsWith('#!') ? (code.indexOf('\n') + 1 || code.length) : 0;
884
+ let semicolon = true;
885
+ DIRECTIVE_RE.lastIndex = at;
886
+ let m;
887
+ while ((m = DIRECTIVE_RE.exec(code))) {
888
+ at = DIRECTIVE_RE.lastIndex;
889
+ semicolon = !!m[2];
890
+ }
891
+ return [at, (semicolon ? '' : ';') + text];
892
+ }
893
+ const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
894
+ function vlq(n) {
895
+ let v = n < 0 ? (-n << 1) | 1 : n << 1;
896
+ let out = '';
897
+ do {
898
+ let digit = v & 31;
899
+ v >>>= 5;
900
+ if (v)
901
+ digit |= 32;
902
+ out += B64[digit];
903
+ } while (v);
904
+ return out;
905
+ }
906
+ /**
907
+ * Apply single-line insertions (at offsets in the original code) plus an
908
+ * appended tail, and build a v3 sourcemap without extra dependencies. No line
909
+ * is added before the tail, so every original line maps to itself; on a line
910
+ * with an insertion, the text after it maps back to its original column.
911
+ */
912
+ function withSourcemap(code, inserts, tail, id) {
913
+ inserts.sort((a, b) => a[0] - b[0]);
914
+ let out = '';
915
+ let last = 0;
916
+ for (const [at, text] of inserts) {
917
+ out += code.slice(last, at) + text;
918
+ last = at;
919
+ }
920
+ out += code.slice(last) + tail;
921
+ let offset = 0;
922
+ let k = 0;
923
+ let prevLine = 0;
924
+ let prevCol = 0;
925
+ const mappings = code.split('\n').map((line, i) => {
926
+ const segments = [[0, 0]]; // [generated column, original column]
927
+ let shift = 0;
928
+ while (k < inserts.length && inserts[k][0] <= offset + line.length) {
929
+ const col = inserts[k][0] - offset;
930
+ shift += inserts[k][1].length;
931
+ segments.push([col + shift, col]);
932
+ k++;
933
+ }
934
+ offset += line.length + 1;
935
+ let genCol = 0;
936
+ return segments.map(([gen, col]) => {
937
+ const seg = vlq(gen - genCol) + 'A' + vlq(i - prevLine) + vlq(col - prevCol);
938
+ genCol = gen;
939
+ prevLine = i;
940
+ prevCol = col;
941
+ return seg;
942
+ }).join(',');
943
+ }).join(';');
944
+ return {
945
+ code: out,
946
+ map: { version: 3, sources: [id], sourcesContent: [code], names: [], mappings },
947
+ };
948
+ }
949
+ // A top-level (column 0) defineElement(...) call, as a statement or a declaration's value
950
+ const DEFINE_ELEMENT_CALL_RE = /^(?:(?:export\s+)?(?:const|let|var)\s+[\w$]+\s*=\s*)?defineElement\s*\(/m;
951
+ const ELEMENT_IMPORT_RE = /import\s+\{[^}]*\bdefineElement\b[^}]*\}\s+from\s+['"]sygnal\/element['"]/;
952
+ /**
953
+ * PLAN-4 GS-13: a module that defines custom elements with 'sygnal/element' accepts its own
954
+ * hot updates. Re-running it calls defineElement again for the same tags, which swaps the
955
+ * component in every live element and keeps each one's state; an edited component module it
956
+ * imports reaches it the same way. Only for a top-level defineElement call, outside test
957
+ * files, when the module has no HMR code of its own and doesn't import run() (an entry's
958
+ * run() wiring decides there).
959
+ */
960
+ function elementHmr(code, noComments, id) {
961
+ if (/\.(test|spec)\.[jt]sx?$/.test(id))
962
+ return null;
963
+ if (!ELEMENT_IMPORT_RE.test(noComments) || noComments.includes('import.meta.hot'))
964
+ return null;
965
+ if (!DEFINE_ELEMENT_CALL_RE.test(blankOut(code, true)))
966
+ return null;
967
+ return withSourcemap(code, [], ELEMENT_HMR_BLOCK, id);
968
+ }
969
+ const ELEMENT_HMR_BLOCK = `
970
+ if (import.meta.hot) import.meta.hot.accept()
971
+ `;
972
+ function hmrBlock(componentPath, hmrRef, disposeRef) {
973
+ return `
974
+ if (import.meta.hot) {
975
+ import.meta.hot.accept('${componentPath}', ${hmrRef})
976
+ import.meta.hot.dispose(${disposeRef})
977
+ }
978
+ `;
979
+ }
980
+
1
981
  const SYGNAL_RENDERER_NAME = '@sygnal/astro';
2
- function sygnalAstroIntegration() {
982
+ // PLAN-4 GS-11 / D120: both island entries import this; it re-exports the default export of the
983
+ // module the `onError` option names (undefined without it)
984
+ const ON_ERROR_ID = 'virtual:sygnal/astro-on-error';
985
+ /** The Vite plugin serving ON_ERROR_ID; `file` is absolute (undefined: no hook) */
986
+ function onErrorPlugin(file) {
987
+ return {
988
+ name: 'sygnal:astro-on-error',
989
+ resolveId: (id) => id === ON_ERROR_ID ? '\0' + ON_ERROR_ID : undefined,
990
+ load: (id) => id === '\0' + ON_ERROR_ID
991
+ ? (file ? `export { default } from ${JSON.stringify(file)}` : 'export default undefined')
992
+ : undefined,
993
+ // Vite 6+ (Astro 6 renders in its own 'prerender' / 'ssr' environments): the island server
994
+ // entry imports the virtual module, so Vite must load it (not Node). `ssr.noExternal`
995
+ // below covers the 'ssr' environment and older Vite
996
+ configEnvironment: (name) => name === 'client' ? undefined : { resolve: { noExternal: ['sygnal'] } },
997
+ };
998
+ }
999
+ /** The project root as a directory path (Astro gives a file: URL) */
1000
+ const rootDir = (root) =>
1001
+ // @ts-ignore — Node's process
1002
+ !root ? process.cwd() : typeof root === 'string' ? root : fileURLToPath(root);
1003
+ function sygnalAstroIntegration(options = {}) {
3
1004
  return {
4
1005
  name: SYGNAL_RENDERER_NAME,
5
1006
  hooks: {
6
- 'astro:config:setup': ({ addRenderer, updateConfig }) => {
1007
+ 'astro:config:setup': ({ addRenderer, updateConfig, command, config }) => {
7
1008
  addRenderer({
8
1009
  name: SYGNAL_RENDERER_NAME,
9
1010
  clientEntrypoint: 'sygnal/astro/client',
10
1011
  serverEntrypoint: 'sygnal/astro/server',
11
1012
  });
12
- updateConfig({
13
- vite: {
14
- esbuild: {
15
- jsx: 'automatic',
16
- jsxImportSource: 'sygnal',
17
- },
1013
+ const vite = {
1014
+ esbuild: {
1015
+ jsx: 'automatic',
1016
+ jsxImportSource: 'sygnal',
18
1017
  },
19
- });
1018
+ // D120: the island entries import the virtual onError module, so they stay on Vite:
1019
+ // not pre-bundled with it, and not externalized (loaded by Node) during SSR
1020
+ optimizeDeps: { exclude: [ON_ERROR_ID] },
1021
+ ssr: { noExternal: ['sygnal'] },
1022
+ };
1023
+ const hook = options.onError ? path.resolve(rootDir(config?.root), options.onError) : undefined;
1024
+ // Dev mode (G-014): islands are started by sygnal/astro/client, which
1025
+ // user code never imports, so the sygnal Vite plugin wraps that entry
1026
+ // in dev to install DevTools, set the dev flag and load the runtime checks first. It
1027
+ // also runs sygnal-check. `astro build` only gets the `globalthis` alias.
1028
+ if (command === 'dev') {
1029
+ vite.plugins = [sygnal({
1030
+ disableJsx: true,
1031
+ disableHmr: true,
1032
+ vitestSetup: false,
1033
+ diagnostics: options.diagnostics,
1034
+ check: options.check,
1035
+ nativeGlobalThis: options.nativeGlobalThis,
1036
+ devtools: options.devtools,
1037
+ })];
1038
+ }
1039
+ else if (options.nativeGlobalThis !== false) {
1040
+ // G-099: the same `globalthis` alias the plugin adds in dev (R2-7: unless the
1041
+ // user's vite config already aliases `globalthis`)
1042
+ const alias = globalThisAlias(config?.vite?.resolve?.alias);
1043
+ if (alias.length)
1044
+ vite.resolve = { alias };
1045
+ }
1046
+ vite.plugins = [...(vite.plugins || []), onErrorPlugin(hook)];
1047
+ updateConfig({ vite });
20
1048
  },
21
1049
  },
22
1050
  };
23
1051
  }
24
1052
 
25
1053
  export { sygnalAstroIntegration as default };
1054
+ //# sourceMappingURL=index.mjs.map