@shadow-js/core 0.1.0 → 1.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 (387) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +2 -2
  3. package/README.md +134 -331
  4. package/dist/dev/action.d.ts +36 -0
  5. package/dist/dev/action.js +90 -0
  6. package/dist/dev/action.js.map +1 -0
  7. package/dist/dev/cache.d.ts +35 -0
  8. package/dist/dev/cache.js +62 -0
  9. package/dist/dev/cache.js.map +1 -0
  10. package/dist/dev/context.d.ts +106 -0
  11. package/dist/dev/context.js +111 -0
  12. package/dist/dev/context.js.map +1 -0
  13. package/dist/dev/effect.d.ts +122 -0
  14. package/dist/dev/effect.js +111 -0
  15. package/dist/dev/effect.js.map +1 -0
  16. package/dist/dev/env.d.ts +29 -0
  17. package/dist/dev/env.js +31 -0
  18. package/dist/dev/env.js.map +1 -0
  19. package/dist/dev/events.d.ts +28 -0
  20. package/dist/dev/events.js +33 -0
  21. package/dist/dev/events.js.map +1 -0
  22. package/dist/dev/extend/index.d.ts +331 -0
  23. package/dist/dev/extend/index.js +317 -0
  24. package/dist/dev/extend/index.js.map +1 -0
  25. package/dist/dev/external-store.d.ts +60 -0
  26. package/dist/dev/external-store.js +60 -0
  27. package/dist/dev/external-store.js.map +1 -0
  28. package/dist/dev/index.d.ts +29 -0
  29. package/dist/dev/index.js +26 -0
  30. package/dist/dev/internal/concurrency.d.ts +213 -0
  31. package/dist/dev/internal/concurrency.js +632 -0
  32. package/dist/dev/internal/concurrency.js.map +1 -0
  33. package/dist/dev/internal/devtools.d.ts +71 -0
  34. package/dist/dev/internal/devtools.js +77 -0
  35. package/dist/dev/internal/devtools.js.map +1 -0
  36. package/dist/dev/internal/diagnostics.d.ts +90 -0
  37. package/dist/dev/internal/diagnostics.js +102 -0
  38. package/dist/dev/internal/diagnostics.js.map +1 -0
  39. package/dist/dev/internal/dispose.d.ts +28 -0
  40. package/dist/dev/internal/dispose.js +49 -0
  41. package/dist/dev/internal/dispose.js.map +1 -0
  42. package/dist/dev/internal/flags.js +11 -0
  43. package/dist/dev/internal/flags.js.map +1 -0
  44. package/dist/dev/internal/graph.d.ts +233 -0
  45. package/dist/dev/internal/graph.js +578 -0
  46. package/dist/dev/internal/graph.js.map +1 -0
  47. package/dist/dev/internal/hydration-flag.d.ts +33 -0
  48. package/dist/dev/internal/hydration-flag.js +46 -0
  49. package/dist/dev/internal/hydration-flag.js.map +1 -0
  50. package/dist/dev/internal/messages.d.ts +56 -0
  51. package/dist/dev/internal/messages.js +54 -0
  52. package/dist/dev/internal/messages.js.map +1 -0
  53. package/dist/dev/internal/owner.d.ts +142 -0
  54. package/dist/dev/internal/owner.js +290 -0
  55. package/dist/dev/internal/owner.js.map +1 -0
  56. package/dist/dev/internal/queue.js +46 -0
  57. package/dist/dev/internal/queue.js.map +1 -0
  58. package/dist/dev/internal/scheduler.d.ts +113 -0
  59. package/dist/dev/internal/scheduler.js +287 -0
  60. package/dist/dev/internal/scheduler.js.map +1 -0
  61. package/dist/dev/internal/state.d.ts +141 -0
  62. package/dist/dev/internal/state.js +28 -0
  63. package/dist/dev/internal/state.js.map +1 -0
  64. package/dist/dev/internal/suspension.d.ts +43 -0
  65. package/dist/dev/internal/suspension.js +45 -0
  66. package/dist/dev/internal/suspension.js.map +1 -0
  67. package/dist/dev/internal/types.d.ts +46 -0
  68. package/dist/dev/list.d.ts +93 -0
  69. package/dist/dev/list.js +282 -0
  70. package/dist/dev/list.js.map +1 -0
  71. package/dist/dev/memo.d.ts +60 -0
  72. package/dist/dev/memo.js +41 -0
  73. package/dist/dev/memo.js.map +1 -0
  74. package/dist/dev/optimistic.d.ts +26 -0
  75. package/dist/dev/optimistic.js +45 -0
  76. package/dist/dev/optimistic.js.map +1 -0
  77. package/dist/dev/ownership.d.ts +204 -0
  78. package/dist/dev/ownership.js +261 -0
  79. package/dist/dev/ownership.js.map +1 -0
  80. package/dist/dev/props.d.ts +134 -0
  81. package/dist/dev/props.js +282 -0
  82. package/dist/dev/props.js.map +1 -0
  83. package/dist/dev/reaction.d.ts +29 -0
  84. package/dist/dev/reaction.js +61 -0
  85. package/dist/dev/reaction.js.map +1 -0
  86. package/dist/dev/reducer.d.ts +41 -0
  87. package/dist/dev/reducer.js +39 -0
  88. package/dist/dev/reducer.js.map +1 -0
  89. package/dist/dev/refs.d.ts +52 -0
  90. package/dist/dev/refs.js +58 -0
  91. package/dist/dev/refs.js.map +1 -0
  92. package/dist/dev/resource.d.ts +135 -0
  93. package/dist/dev/resource.js +177 -0
  94. package/dist/dev/resource.js.map +1 -0
  95. package/dist/dev/selector.d.ts +34 -0
  96. package/dist/dev/selector.js +118 -0
  97. package/dist/dev/selector.js.map +1 -0
  98. package/dist/dev/signal.d.ts +42 -0
  99. package/dist/dev/signal.js +39 -0
  100. package/dist/dev/signal.js.map +1 -0
  101. package/dist/dev/store/index.d.ts +5 -0
  102. package/dist/dev/store/index.js +4 -0
  103. package/dist/dev/store/nodes.js +192 -0
  104. package/dist/dev/store/nodes.js.map +1 -0
  105. package/dist/dev/store/proxies.js +160 -0
  106. package/dist/dev/store/proxies.js.map +1 -0
  107. package/dist/dev/store/read.d.ts +39 -0
  108. package/dist/dev/store/read.js +72 -0
  109. package/dist/dev/store/read.js.map +1 -0
  110. package/dist/dev/store/reconcile.d.ts +73 -0
  111. package/dist/dev/store/reconcile.js +186 -0
  112. package/dist/dev/store/reconcile.js.map +1 -0
  113. package/dist/dev/store/types.d.ts +106 -0
  114. package/dist/dev/store/use-store.d.ts +60 -0
  115. package/dist/dev/store/use-store.js +168 -0
  116. package/dist/dev/store/use-store.js.map +1 -0
  117. package/dist/dev/suspense.d.ts +101 -0
  118. package/dist/dev/suspense.js +45 -0
  119. package/dist/dev/suspense.js.map +1 -0
  120. package/dist/dev/transitions.d.ts +77 -0
  121. package/dist/dev/transitions.js +101 -0
  122. package/dist/dev/transitions.js.map +1 -0
  123. package/dist/prod/action.js +2 -0
  124. package/dist/prod/action.js.map +1 -0
  125. package/dist/prod/cache.js +2 -0
  126. package/dist/prod/cache.js.map +1 -0
  127. package/dist/prod/context.js +2 -0
  128. package/dist/prod/context.js.map +1 -0
  129. package/dist/prod/effect.js +2 -0
  130. package/dist/prod/effect.js.map +1 -0
  131. package/dist/prod/env.js +2 -0
  132. package/dist/prod/env.js.map +1 -0
  133. package/dist/prod/events.js +2 -0
  134. package/dist/prod/events.js.map +1 -0
  135. package/dist/prod/extend/index.js +2 -0
  136. package/dist/prod/extend/index.js.map +1 -0
  137. package/dist/prod/external-store.js +2 -0
  138. package/dist/prod/external-store.js.map +1 -0
  139. package/dist/prod/index.js +1 -0
  140. package/dist/prod/internal/concurrency.js +2 -0
  141. package/dist/prod/internal/concurrency.js.map +1 -0
  142. package/dist/prod/internal/devtools.js +2 -0
  143. package/dist/prod/internal/devtools.js.map +1 -0
  144. package/dist/prod/internal/diagnostics.js +2 -0
  145. package/dist/prod/internal/diagnostics.js.map +1 -0
  146. package/dist/prod/internal/dispose.js +2 -0
  147. package/dist/prod/internal/dispose.js.map +1 -0
  148. package/dist/prod/internal/flags.js +2 -0
  149. package/dist/prod/internal/flags.js.map +1 -0
  150. package/dist/prod/internal/graph.js +2 -0
  151. package/dist/prod/internal/graph.js.map +1 -0
  152. package/dist/prod/internal/hydration-flag.js +2 -0
  153. package/dist/prod/internal/hydration-flag.js.map +1 -0
  154. package/dist/prod/internal/messages.js +2 -0
  155. package/dist/prod/internal/messages.js.map +1 -0
  156. package/dist/prod/internal/owner.js +2 -0
  157. package/dist/prod/internal/owner.js.map +1 -0
  158. package/dist/prod/internal/queue.js +2 -0
  159. package/dist/prod/internal/queue.js.map +1 -0
  160. package/dist/prod/internal/scheduler.js +2 -0
  161. package/dist/prod/internal/scheduler.js.map +1 -0
  162. package/dist/prod/internal/state.js +2 -0
  163. package/dist/prod/internal/state.js.map +1 -0
  164. package/dist/prod/internal/suspension.js +2 -0
  165. package/dist/prod/internal/suspension.js.map +1 -0
  166. package/dist/prod/list.js +2 -0
  167. package/dist/prod/list.js.map +1 -0
  168. package/dist/prod/memo.js +2 -0
  169. package/dist/prod/memo.js.map +1 -0
  170. package/dist/prod/optimistic.js +2 -0
  171. package/dist/prod/optimistic.js.map +1 -0
  172. package/dist/prod/ownership.js +2 -0
  173. package/dist/prod/ownership.js.map +1 -0
  174. package/dist/prod/props.js +2 -0
  175. package/dist/prod/props.js.map +1 -0
  176. package/dist/prod/reaction.js +2 -0
  177. package/dist/prod/reaction.js.map +1 -0
  178. package/dist/prod/reducer.js +2 -0
  179. package/dist/prod/reducer.js.map +1 -0
  180. package/dist/prod/refs.js +2 -0
  181. package/dist/prod/refs.js.map +1 -0
  182. package/dist/prod/resource.js +2 -0
  183. package/dist/prod/resource.js.map +1 -0
  184. package/dist/prod/selector.js +2 -0
  185. package/dist/prod/selector.js.map +1 -0
  186. package/dist/prod/signal.js +2 -0
  187. package/dist/prod/signal.js.map +1 -0
  188. package/dist/prod/store/index.js +1 -0
  189. package/dist/prod/store/nodes.js +2 -0
  190. package/dist/prod/store/nodes.js.map +1 -0
  191. package/dist/prod/store/proxies.js +2 -0
  192. package/dist/prod/store/proxies.js.map +1 -0
  193. package/dist/prod/store/read.js +2 -0
  194. package/dist/prod/store/read.js.map +1 -0
  195. package/dist/prod/store/reconcile.js +2 -0
  196. package/dist/prod/store/reconcile.js.map +1 -0
  197. package/dist/prod/store/use-store.js +2 -0
  198. package/dist/prod/store/use-store.js.map +1 -0
  199. package/dist/prod/suspense.js +2 -0
  200. package/dist/prod/suspense.js.map +1 -0
  201. package/dist/prod/transitions.js +2 -0
  202. package/dist/prod/transitions.js.map +1 -0
  203. package/dist/server/action.js +2 -0
  204. package/dist/server/action.js.map +1 -0
  205. package/dist/server/cache.js +2 -0
  206. package/dist/server/cache.js.map +1 -0
  207. package/dist/server/context.js +2 -0
  208. package/dist/server/context.js.map +1 -0
  209. package/dist/server/effect.js +2 -0
  210. package/dist/server/effect.js.map +1 -0
  211. package/dist/server/env.js +2 -0
  212. package/dist/server/env.js.map +1 -0
  213. package/dist/server/events.js +2 -0
  214. package/dist/server/events.js.map +1 -0
  215. package/dist/server/extend/index.js +2 -0
  216. package/dist/server/extend/index.js.map +1 -0
  217. package/dist/server/external-store.js +2 -0
  218. package/dist/server/external-store.js.map +1 -0
  219. package/dist/server/index.js +1 -0
  220. package/dist/server/internal/concurrency.js +2 -0
  221. package/dist/server/internal/concurrency.js.map +1 -0
  222. package/dist/server/internal/devtools.js +2 -0
  223. package/dist/server/internal/devtools.js.map +1 -0
  224. package/dist/server/internal/diagnostics.js +2 -0
  225. package/dist/server/internal/diagnostics.js.map +1 -0
  226. package/dist/server/internal/dispose.js +2 -0
  227. package/dist/server/internal/dispose.js.map +1 -0
  228. package/dist/server/internal/flags.js +2 -0
  229. package/dist/server/internal/flags.js.map +1 -0
  230. package/dist/server/internal/graph.js +2 -0
  231. package/dist/server/internal/graph.js.map +1 -0
  232. package/dist/server/internal/hydration-flag.js +2 -0
  233. package/dist/server/internal/hydration-flag.js.map +1 -0
  234. package/dist/server/internal/messages.js +2 -0
  235. package/dist/server/internal/messages.js.map +1 -0
  236. package/dist/server/internal/owner.js +2 -0
  237. package/dist/server/internal/owner.js.map +1 -0
  238. package/dist/server/internal/queue.js +2 -0
  239. package/dist/server/internal/queue.js.map +1 -0
  240. package/dist/server/internal/scheduler.js +2 -0
  241. package/dist/server/internal/scheduler.js.map +1 -0
  242. package/dist/server/internal/state.js +2 -0
  243. package/dist/server/internal/state.js.map +1 -0
  244. package/dist/server/internal/suspension.js +2 -0
  245. package/dist/server/internal/suspension.js.map +1 -0
  246. package/dist/server/list.js +2 -0
  247. package/dist/server/list.js.map +1 -0
  248. package/dist/server/memo.js +2 -0
  249. package/dist/server/memo.js.map +1 -0
  250. package/dist/server/optimistic.js +2 -0
  251. package/dist/server/optimistic.js.map +1 -0
  252. package/dist/server/ownership.js +2 -0
  253. package/dist/server/ownership.js.map +1 -0
  254. package/dist/server/props.js +2 -0
  255. package/dist/server/props.js.map +1 -0
  256. package/dist/server/reaction.js +2 -0
  257. package/dist/server/reaction.js.map +1 -0
  258. package/dist/server/reducer.js +2 -0
  259. package/dist/server/reducer.js.map +1 -0
  260. package/dist/server/refs.js +2 -0
  261. package/dist/server/refs.js.map +1 -0
  262. package/dist/server/resource.js +2 -0
  263. package/dist/server/resource.js.map +1 -0
  264. package/dist/server/selector.js +2 -0
  265. package/dist/server/selector.js.map +1 -0
  266. package/dist/server/signal.js +2 -0
  267. package/dist/server/signal.js.map +1 -0
  268. package/dist/server/store/index.js +1 -0
  269. package/dist/server/store/nodes.js +2 -0
  270. package/dist/server/store/nodes.js.map +1 -0
  271. package/dist/server/store/proxies.js +2 -0
  272. package/dist/server/store/proxies.js.map +1 -0
  273. package/dist/server/store/read.js +2 -0
  274. package/dist/server/store/read.js.map +1 -0
  275. package/dist/server/store/reconcile.js +2 -0
  276. package/dist/server/store/reconcile.js.map +1 -0
  277. package/dist/server/store/use-store.js +2 -0
  278. package/dist/server/store/use-store.js.map +1 -0
  279. package/dist/server/suspense.js +2 -0
  280. package/dist/server/suspense.js.map +1 -0
  281. package/dist/server/transitions.js +2 -0
  282. package/dist/server/transitions.js.map +1 -0
  283. package/dist/server-dev/action.js +90 -0
  284. package/dist/server-dev/action.js.map +1 -0
  285. package/dist/server-dev/cache.js +62 -0
  286. package/dist/server-dev/cache.js.map +1 -0
  287. package/dist/server-dev/context.js +108 -0
  288. package/dist/server-dev/context.js.map +1 -0
  289. package/dist/server-dev/effect.js +56 -0
  290. package/dist/server-dev/effect.js.map +1 -0
  291. package/dist/server-dev/env.js +31 -0
  292. package/dist/server-dev/env.js.map +1 -0
  293. package/dist/server-dev/events.js +33 -0
  294. package/dist/server-dev/events.js.map +1 -0
  295. package/dist/server-dev/extend/index.js +317 -0
  296. package/dist/server-dev/extend/index.js.map +1 -0
  297. package/dist/server-dev/external-store.js +46 -0
  298. package/dist/server-dev/external-store.js.map +1 -0
  299. package/dist/server-dev/index.js +26 -0
  300. package/dist/server-dev/internal/concurrency.js +633 -0
  301. package/dist/server-dev/internal/concurrency.js.map +1 -0
  302. package/dist/server-dev/internal/devtools.js +77 -0
  303. package/dist/server-dev/internal/devtools.js.map +1 -0
  304. package/dist/server-dev/internal/diagnostics.js +102 -0
  305. package/dist/server-dev/internal/diagnostics.js.map +1 -0
  306. package/dist/server-dev/internal/dispose.js +49 -0
  307. package/dist/server-dev/internal/dispose.js.map +1 -0
  308. package/dist/server-dev/internal/flags.js +11 -0
  309. package/dist/server-dev/internal/flags.js.map +1 -0
  310. package/dist/server-dev/internal/graph.js +578 -0
  311. package/dist/server-dev/internal/graph.js.map +1 -0
  312. package/dist/server-dev/internal/hydration-flag.js +46 -0
  313. package/dist/server-dev/internal/hydration-flag.js.map +1 -0
  314. package/dist/server-dev/internal/messages.js +54 -0
  315. package/dist/server-dev/internal/messages.js.map +1 -0
  316. package/dist/server-dev/internal/owner.js +290 -0
  317. package/dist/server-dev/internal/owner.js.map +1 -0
  318. package/dist/server-dev/internal/queue.js +46 -0
  319. package/dist/server-dev/internal/queue.js.map +1 -0
  320. package/dist/server-dev/internal/scheduler.js +287 -0
  321. package/dist/server-dev/internal/scheduler.js.map +1 -0
  322. package/dist/server-dev/internal/state.js +28 -0
  323. package/dist/server-dev/internal/state.js.map +1 -0
  324. package/dist/server-dev/internal/suspension.js +45 -0
  325. package/dist/server-dev/internal/suspension.js.map +1 -0
  326. package/dist/server-dev/list.js +282 -0
  327. package/dist/server-dev/list.js.map +1 -0
  328. package/dist/server-dev/memo.js +41 -0
  329. package/dist/server-dev/memo.js.map +1 -0
  330. package/dist/server-dev/optimistic.js +45 -0
  331. package/dist/server-dev/optimistic.js.map +1 -0
  332. package/dist/server-dev/ownership.js +261 -0
  333. package/dist/server-dev/ownership.js.map +1 -0
  334. package/dist/server-dev/props.js +282 -0
  335. package/dist/server-dev/props.js.map +1 -0
  336. package/dist/server-dev/reaction.js +61 -0
  337. package/dist/server-dev/reaction.js.map +1 -0
  338. package/dist/server-dev/reducer.js +39 -0
  339. package/dist/server-dev/reducer.js.map +1 -0
  340. package/dist/server-dev/refs.js +58 -0
  341. package/dist/server-dev/refs.js.map +1 -0
  342. package/dist/server-dev/resource.js +176 -0
  343. package/dist/server-dev/resource.js.map +1 -0
  344. package/dist/server-dev/selector.js +82 -0
  345. package/dist/server-dev/selector.js.map +1 -0
  346. package/dist/server-dev/signal.js +39 -0
  347. package/dist/server-dev/signal.js.map +1 -0
  348. package/dist/server-dev/store/index.js +4 -0
  349. package/dist/server-dev/store/nodes.js +192 -0
  350. package/dist/server-dev/store/nodes.js.map +1 -0
  351. package/dist/server-dev/store/proxies.js +160 -0
  352. package/dist/server-dev/store/proxies.js.map +1 -0
  353. package/dist/server-dev/store/read.js +72 -0
  354. package/dist/server-dev/store/read.js.map +1 -0
  355. package/dist/server-dev/store/reconcile.js +186 -0
  356. package/dist/server-dev/store/reconcile.js.map +1 -0
  357. package/dist/server-dev/store/use-store.js +168 -0
  358. package/dist/server-dev/store/use-store.js.map +1 -0
  359. package/dist/server-dev/suspense.js +45 -0
  360. package/dist/server-dev/suspense.js.map +1 -0
  361. package/dist/server-dev/transitions.js +86 -0
  362. package/dist/server-dev/transitions.js.map +1 -0
  363. package/package.json +111 -50
  364. package/dist/chunk-6Y3CCWOY.js +0 -887
  365. package/dist/chunk-6Y3CCWOY.js.map +0 -1
  366. package/dist/chunk-B5FTYDUG.js +0 -3
  367. package/dist/chunk-B5FTYDUG.js.map +0 -1
  368. package/dist/index.cjs +0 -2000
  369. package/dist/index.cjs.map +0 -1
  370. package/dist/index.d.cts +0 -609
  371. package/dist/index.d.ts +0 -609
  372. package/dist/index.js +0 -1094
  373. package/dist/index.js.map +0 -1
  374. package/dist/jsx-Bugil6CJ.d.cts +0 -151
  375. package/dist/jsx-Bugil6CJ.d.ts +0 -151
  376. package/dist/jsx-dev-runtime.cjs +0 -742
  377. package/dist/jsx-dev-runtime.cjs.map +0 -1
  378. package/dist/jsx-dev-runtime.d.cts +0 -2
  379. package/dist/jsx-dev-runtime.d.ts +0 -2
  380. package/dist/jsx-dev-runtime.js +0 -4
  381. package/dist/jsx-dev-runtime.js.map +0 -1
  382. package/dist/jsx-runtime.cjs +0 -742
  383. package/dist/jsx-runtime.cjs.map +0 -1
  384. package/dist/jsx-runtime.d.cts +0 -36
  385. package/dist/jsx-runtime.d.ts +0 -36
  386. package/dist/jsx-runtime.js +0 -4
  387. package/dist/jsx-runtime.js.map +0 -1
@@ -0,0 +1,46 @@
1
+ import { rt } from "./state.js";
2
+ //#region src/internal/hydration-flag.ts
3
+ /**
4
+ * Tells whether the code runs while `hydrate()` claims server markup. Read it at creation in a hook
5
+ * whose first render must match the server, as `useExternalStore` does to read its server snapshot.
6
+ *
7
+ * @returns True inside {@link withHydration}, false otherwise.
8
+ * @example
9
+ * import { isHydrating } from "@shadow-js/core/extend";
10
+ *
11
+ * function initialWidth(serverWidth: number): number {
12
+ * return isHydrating() ? serverWidth : window.innerWidth;
13
+ * }
14
+ * @see withHydration
15
+ * @since 1.0.0
16
+ */
17
+ function isHydrating() {
18
+ return rt.hydrating;
19
+ }
20
+ /**
21
+ * Runs `fn` with the hydration flag set, so the hooks created inside see {@link isHydrating} return
22
+ * true, and restores the previous flag in `finally`. Renderers wrap their hydration pass in it (the
23
+ * `hydrate()` of `@shadow-js/web` does); application code does not need it.
24
+ *
25
+ * @param fn The hydration pass. A throw is rethrown after the flag is restored.
26
+ * @returns What `fn` returns.
27
+ * @example
28
+ * import { isHydrating, withHydration } from "@shadow-js/core/extend";
29
+ *
30
+ * const during = withHydration(() => isHydrating()); // true
31
+ * const after = isHydrating(); // false again
32
+ * @since 1.0.0
33
+ */
34
+ function withHydration(fn) {
35
+ const previous = rt.hydrating;
36
+ rt.hydrating = true;
37
+ try {
38
+ return fn();
39
+ } finally {
40
+ rt.hydrating = previous;
41
+ }
42
+ }
43
+ //#endregion
44
+ export { isHydrating, withHydration };
45
+
46
+ //# sourceMappingURL=hydration-flag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hydration-flag.js","names":[],"sources":["../../../src/internal/hydration-flag.ts"],"sourcesContent":["import { rt } from \"./state\";\n\n/**\n * Tells whether the code runs while `hydrate()` claims server markup. Read it at creation in a hook\n * whose first render must match the server, as `useExternalStore` does to read its server snapshot.\n *\n * @returns True inside {@link withHydration}, false otherwise.\n * @example\n * import { isHydrating } from \"@shadow-js/core/extend\";\n *\n * function initialWidth(serverWidth: number): number {\n * return isHydrating() ? serverWidth : window.innerWidth;\n * }\n * @see withHydration\n * @since 1.0.0\n */\nexport function isHydrating(): boolean {\n return rt.hydrating;\n}\n\n/**\n * Runs `fn` with the hydration flag set, so the hooks created inside see {@link isHydrating} return\n * true, and restores the previous flag in `finally`. Renderers wrap their hydration pass in it (the\n * `hydrate()` of `@shadow-js/web` does); application code does not need it.\n *\n * @param fn The hydration pass. A throw is rethrown after the flag is restored.\n * @returns What `fn` returns.\n * @example\n * import { isHydrating, withHydration } from \"@shadow-js/core/extend\";\n *\n * const during = withHydration(() => isHydrating()); // true\n * const after = isHydrating(); // false again\n * @since 1.0.0\n */\nexport function withHydration<T>(fn: () => T): T {\n const previous = rt.hydrating;\n rt.hydrating = true;\n try {\n return fn();\n } finally {\n rt.hydrating = previous;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,cAAuB;CACrC,OAAO,GAAG;AACZ;;;;;;;;;;;;;;;AAgBA,SAAgB,cAAiB,IAAgB;CAC/C,MAAM,WAAW,GAAG;CACpB,GAAG,YAAY;CACf,IAAI;EACF,OAAO,GAAG;CACZ,UAAU;EACR,GAAG,YAAY;CACjB;AACF"}
@@ -0,0 +1,54 @@
1
+ //#region src/internal/messages.ts
2
+ /**
3
+ * The diagnostic catalog: every code the runtime throws (as {@link ShadowError}) or warns with
4
+ * (through {@link warn}), mapped to its development text. Read it to show or match a diagnostic by
5
+ * code. {@link formatMessage} reads it only in development builds, so production bundles keep the
6
+ * code (`SHADOW_<CODE>`) and drop the text (R-CODE-8) unless your own code imports this object.
7
+ *
8
+ * @example
9
+ * import { MESSAGES, type MessageCode } from "@shadow-js/core/extend";
10
+ *
11
+ * function explain(code: MessageCode): string {
12
+ * return `${code}: ${MESSAGES[code]}`;
13
+ * }
14
+ * @see formatMessage
15
+ * @since 1.0.0
16
+ */
17
+ const MESSAGES = {
18
+ NO_OWNER_EFFECT: "An effect was created outside any owner, so it can never be disposed. Create it inside a component or createRoot().",
19
+ NO_OWNER_CLEANUP: "onCleanup() was called outside any owner, so the cleanup will never run.",
20
+ NO_OWNER_ERROR: "onError() was called outside any owner, so the handler can never be reached.",
21
+ WRITE_IN_MEMO: "A signal was written inside a useMemo() computation. Derive values from sources instead, or write from an effect.",
22
+ CYCLE_DETECTED: "A reactive cycle was detected: a computation read itself while it was running.",
23
+ INFINITE_LOOP: "Effects kept re-triggering each other for more than 1000 passes; the flush was aborted.",
24
+ FLUSH_IN_EFFECT: "flushSync() was called while a flush was already running; the call was ignored.",
25
+ RUN_WITH_DISPOSED_OWNER: "runWithOwner() was called with an owner that is already disposed; the callback ran without an owner.",
26
+ DUPLICATE_CORE: "More than one copy of @shadow-js/core is loaded. Signals created by one copy are invisible to the other.",
27
+ CONTEXT_MISSING: "useContext() found no provider and the context has no default value.",
28
+ NO_OWNER_ID: "useId() was called outside any owner; the id is not stable across server and client.",
29
+ EACH_KEY_DUPLICATE: "Duplicate key in a keyed list; later duplicates get fresh rows each update.",
30
+ EFFECT_DEPS_IGNORED: "useEffect(fn, [deps]) ignores the array and re-runs on any signal it reads; use useEffect(deps, fn)."
31
+ };
32
+ /**
33
+ * Turns a diagnostic code into the text the runtime throws or logs: the full sentence in development
34
+ * builds and only a stable code in production builds, so message strings never reach user bundles.
35
+ * Use it when a custom primitive reports a core diagnostic in its own way.
36
+ *
37
+ * @param code The diagnostic code.
38
+ * @returns `[shadow <CODE>] <text>` in development builds, `SHADOW_<CODE>` in production builds.
39
+ * @example
40
+ * import { formatMessage } from "@shadow-js/core/extend";
41
+ *
42
+ * const text = formatMessage("CONTEXT_MISSING");
43
+ * // development: "[shadow CONTEXT_MISSING] useContext() found no provider ..."
44
+ * // production: "SHADOW_CONTEXT_MISSING"
45
+ * @see MESSAGES
46
+ * @since 1.0.0
47
+ */
48
+ function formatMessage(code) {
49
+ return `[shadow ${code}] ${MESSAGES[code]}`;
50
+ }
51
+ //#endregion
52
+ export { MESSAGES, formatMessage };
53
+
54
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","names":[],"sources":["../../../src/internal/messages.ts"],"sourcesContent":["/**\n * The diagnostic catalog: every code the runtime throws (as {@link ShadowError}) or warns with\n * (through {@link warn}), mapped to its development text. Read it to show or match a diagnostic by\n * code. {@link formatMessage} reads it only in development builds, so production bundles keep the\n * code (`SHADOW_<CODE>`) and drop the text (R-CODE-8) unless your own code imports this object.\n *\n * @example\n * import { MESSAGES, type MessageCode } from \"@shadow-js/core/extend\";\n *\n * function explain(code: MessageCode): string {\n * return `${code}: ${MESSAGES[code]}`;\n * }\n * @see formatMessage\n * @since 1.0.0\n */\nexport const MESSAGES = {\n NO_OWNER_EFFECT:\n \"An effect was created outside any owner, so it can never be disposed. Create it inside a component or createRoot().\",\n NO_OWNER_CLEANUP: \"onCleanup() was called outside any owner, so the cleanup will never run.\",\n NO_OWNER_ERROR: \"onError() was called outside any owner, so the handler can never be reached.\",\n WRITE_IN_MEMO:\n \"A signal was written inside a useMemo() computation. Derive values from sources instead, or write from an effect.\",\n CYCLE_DETECTED: \"A reactive cycle was detected: a computation read itself while it was running.\",\n INFINITE_LOOP:\n \"Effects kept re-triggering each other for more than 1000 passes; the flush was aborted.\",\n FLUSH_IN_EFFECT:\n \"flushSync() was called while a flush was already running; the call was ignored.\",\n RUN_WITH_DISPOSED_OWNER:\n \"runWithOwner() was called with an owner that is already disposed; the callback ran without an owner.\",\n DUPLICATE_CORE:\n \"More than one copy of @shadow-js/core is loaded. Signals created by one copy are invisible to the other.\",\n CONTEXT_MISSING: \"useContext() found no provider and the context has no default value.\",\n NO_OWNER_ID:\n \"useId() was called outside any owner; the id is not stable across server and client.\",\n EACH_KEY_DUPLICATE: \"Duplicate key in a keyed list; later duplicates get fresh rows each update.\",\n EFFECT_DEPS_IGNORED:\n \"useEffect(fn, [deps]) ignores the array and re-runs on any signal it reads; use useEffect(deps, fn).\",\n} as const;\n\n/**\n * A diagnostic code: one key of {@link MESSAGES}, such as `\"WRITE_IN_MEMO\"`. {@link ShadowError}\n * carries one in its `code` field, and {@link warn} takes one.\n * @since 1.0.0\n */\nexport type MessageCode = keyof typeof MESSAGES;\n\n/**\n * Turns a diagnostic code into the text the runtime throws or logs: the full sentence in development\n * builds and only a stable code in production builds, so message strings never reach user bundles.\n * Use it when a custom primitive reports a core diagnostic in its own way.\n *\n * @param code The diagnostic code.\n * @returns `[shadow <CODE>] <text>` in development builds, `SHADOW_<CODE>` in production builds.\n * @example\n * import { formatMessage } from \"@shadow-js/core/extend\";\n *\n * const text = formatMessage(\"CONTEXT_MISSING\");\n * // development: \"[shadow CONTEXT_MISSING] useContext() found no provider ...\"\n * // production: \"SHADOW_CONTEXT_MISSING\"\n * @see MESSAGES\n * @since 1.0.0\n */\nexport function formatMessage(code: MessageCode): string {\n return __DEV__ ? `[shadow ${code}] ${MESSAGES[code]}` : `SHADOW_${code}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,MAAa,WAAW;CACtB,iBACE;CACF,kBAAkB;CAClB,gBAAgB;CAChB,eACE;CACF,gBAAgB;CAChB,eACE;CACF,iBACE;CACF,yBACE;CACF,gBACE;CACF,iBAAiB;CACjB,aACE;CACF,oBAAoB;CACpB,qBACE;AACJ;;;;;;;;;;;;;;;;;AAyBA,SAAgB,cAAc,MAA2B;CACvD,OAAiB,WAAW,KAAK,IAAI,SAAS;AAChD"}
@@ -0,0 +1,290 @@
1
+ import { DEVTOOLS_EVENT, report } from "./devtools.js";
2
+ import { rt } from "./state.js";
3
+ //#region src/internal/owner.ts
4
+ /**
5
+ * A node in the ownership tree: it owns the effects, memos and owners created under it, their
6
+ * cleanups and error handlers, and disposes them together. Create one with `createOwner` and end it
7
+ * with `disposeOwner`; the class is exported for `instanceof` checks and for reading its state.
8
+ * Computations (`ComputationNode`) are owners too. Children are a doubly linked list so detaching one
9
+ * is O(1); disposal walks the tree iteratively because its depth is user controlled (R-CODE-11).
10
+ *
11
+ * @example
12
+ * import { createOwner, disposeOwner, Owner } from "@shadow-js/core/extend";
13
+ *
14
+ * const owner = createOwner(null);
15
+ * console.log(owner instanceof Owner, owner.depth); // true 0
16
+ * disposeOwner(owner);
17
+ * console.log(owner.disposed); // true
18
+ * @see createOwner
19
+ * @see disposeOwner
20
+ * @since 1.0.0
21
+ */
22
+ var Owner = class Owner {
23
+ /** The owner this node was created under, or null for a root. Kept after disposal. */
24
+ parent;
25
+ /** The newest child that is still alive, or null when there is none. */
26
+ lastChild = null;
27
+ /** The next older sibling that is still alive, or null. */
28
+ prevSibling = null;
29
+ /** The next newer sibling that is still alive, or null. */
30
+ nextSibling = null;
31
+ /**
32
+ * The cleanups registered with `addCleanup` or `onCleanup`: null for none, a function for one, an
33
+ * array (oldest first) for several. Emptied when they run.
34
+ */
35
+ cleanups = null;
36
+ /** The context values this node sees: inherited from the parent at creation, null for a root. */
37
+ context;
38
+ /**
39
+ * The handlers registered with `onError` or `catchError`, oldest first (they are tried newest
40
+ * first), or null for none. A computation clears them before each run.
41
+ */
42
+ errorHandlers = null;
43
+ /** Number of children ever created; gives each child a stable index for useId(). */
44
+ childCount = 0;
45
+ /** Number of ids useId() has handed out from this owner. */
46
+ idCount = 0;
47
+ /** Position among the parent's children, assigned at creation. */
48
+ index;
49
+ /** Distance from the root: 0 for a root, the parent's depth plus one otherwise. */
50
+ depth;
51
+ /**
52
+ * The hydration-scope prefix of a component's owner, set by the renderer. When present, useId()
53
+ * builds the ids below it from this prefix instead of the owner path.
54
+ * @default undefined
55
+ */
56
+ idPrefix;
57
+ /** True once the node has been disposed. */
58
+ disposed = false;
59
+ /**
60
+ * While this returns true, user effects (and `onMount`) created below this owner wait: they do
61
+ * not run until it returns false for the first time. Suspense sets it so the effects of content
62
+ * that is still loading are held back. The read is tracked.
63
+ */
64
+ gate = null;
65
+ /**
66
+ * Number of pauses (Activity hidden) that cover this node. Inherited at creation, and changed for a
67
+ * whole subtree by `pauseOwner`/`resumeOwner`. Above zero, effects wait and memos keep their value.
68
+ */
69
+ pauses = 0;
70
+ /**
71
+ * Creates an owner and links it as the newest child of `parent`. It inherits the parent's context
72
+ * and pauses.
73
+ * @param parent The owner to attach to, or null for a root.
74
+ */
75
+ constructor(parent) {
76
+ this.parent = parent;
77
+ this.context = parent === null ? null : parent.context;
78
+ this.depth = parent === null ? 0 : parent.depth + 1;
79
+ this.pauses = parent === null ? 0 : parent.pauses;
80
+ if (parent === null) this.index = 0;
81
+ else {
82
+ this.index = parent.childCount;
83
+ parent.childCount += 1;
84
+ const last = parent.lastChild;
85
+ this.prevSibling = last;
86
+ if (last !== null) last.nextSibling = this;
87
+ parent.lastChild = this;
88
+ }
89
+ if (new.target === Owner) report(DEVTOOLS_EVENT.OWNER_CREATED, this, parent, parent === null ? "root" : "owner");
90
+ }
91
+ /** Tells devtools this node is gone. Computations override it with their own event. */
92
+ reportDisposed() {
93
+ report(DEVTOOLS_EVENT.OWNER_DISPOSED, this);
94
+ }
95
+ /** Hook for subclasses: release graph edges before the node is marked disposed. */
96
+ release() {}
97
+ /**
98
+ * Disposes this node only (children must already be gone).
99
+ * @internal
100
+ */
101
+ disposeSelf() {
102
+ if (this.disposed) return;
103
+ this.disposed = true;
104
+ const parent = this.parent;
105
+ if (parent !== null) {
106
+ const prev = this.prevSibling;
107
+ const next = this.nextSibling;
108
+ if (prev !== null) prev.nextSibling = next;
109
+ if (next !== null) next.prevSibling = prev;
110
+ else parent.lastChild = prev;
111
+ this.prevSibling = null;
112
+ this.nextSibling = null;
113
+ }
114
+ this.release();
115
+ this.reportDisposed();
116
+ this.runCleanups();
117
+ }
118
+ /**
119
+ * Runs own cleanups newest first, untracked, isolating failures.
120
+ * @internal
121
+ */
122
+ runCleanups() {
123
+ const cleanups = this.cleanups;
124
+ if (cleanups === null) return;
125
+ this.cleanups = null;
126
+ const previousOwner = rt.owner;
127
+ const previousListener = rt.listener;
128
+ rt.owner = null;
129
+ rt.listener = null;
130
+ try {
131
+ if (typeof cleanups === "function") runCleanup(cleanups, this);
132
+ else for (let i = cleanups.length - 1; i >= 0; i -= 1) {
133
+ const cleanup = cleanups[i];
134
+ if (cleanup !== void 0) runCleanup(cleanup, this);
135
+ }
136
+ } finally {
137
+ rt.owner = previousOwner;
138
+ rt.listener = previousListener;
139
+ }
140
+ }
141
+ };
142
+ function runCleanup(cleanup, owner) {
143
+ try {
144
+ cleanup();
145
+ } catch (error) {
146
+ handleError(error, owner);
147
+ }
148
+ }
149
+ /**
150
+ * Registers `cleanup` on an explicit owner. It runs when the owner is disposed or, when the owner is a
151
+ * computation, before its next run. Cleanups run newest first, untracked and with no current owner;
152
+ * one that throws goes to {@link handleError} for that owner and does not stop the others. Use it
153
+ * where `onCleanup` cannot be called: the owner is not the current one, or the code must not warn.
154
+ * Unlike `onCleanup`, nothing checks that the owner is still alive: a cleanup added to a disposed
155
+ * owner never runs.
156
+ *
157
+ * @param owner The owner whose disposal runs the cleanup.
158
+ * @param cleanup The function to run.
159
+ * @example
160
+ * import { addCleanup, currentOwner } from "@shadow-js/core/extend";
161
+ *
162
+ * export function useInterval(tick: () => void, ms: number): void {
163
+ * const owner = currentOwner();
164
+ * const timer = setInterval(tick, ms);
165
+ * if (owner !== null) addCleanup(owner, () => clearInterval(timer));
166
+ * }
167
+ * @see disposeOwner
168
+ * @since 1.0.0
169
+ */
170
+ function addCleanup(owner, cleanup) {
171
+ const existing = owner.cleanups;
172
+ if (existing === null) owner.cleanups = cleanup;
173
+ else if (typeof existing === "function") owner.cleanups = [existing, cleanup];
174
+ else existing.push(cleanup);
175
+ }
176
+ /**
177
+ * Disposes every child of `owner` (newest first), keeping `owner` itself alive.
178
+ * @internal
179
+ */
180
+ function disposeChildren(owner) {
181
+ for (;;) {
182
+ const child = owner.lastChild;
183
+ if (child === null) return;
184
+ disposeTree(child);
185
+ }
186
+ }
187
+ /** Rethrows what disposal collected once the outermost disposal is finished. */
188
+ function finishDisposal() {
189
+ rt.disposing -= 1;
190
+ if (rt.disposing > 0 || rt.flushing || rt.uncaught.length === 0) return;
191
+ const errors = rt.uncaught;
192
+ rt.uncaught = [];
193
+ if (errors.length === 1) throw errors[0];
194
+ throw new AggregateError(errors, "Several errors were thrown while disposing.");
195
+ }
196
+ /**
197
+ * Disposes `root` and everything below it: children first, then own cleanups, newest first.
198
+ * Iterative post-order walk: a leaf is disposed, which re-links its parent's `lastChild`
199
+ * to the previous sibling, so the loop naturally visits the remaining subtree. The public
200
+ * `disposeOwner` (dispose.ts) wraps it with the flush that follows.
201
+ * @internal
202
+ */
203
+ function disposeTree(root) {
204
+ rt.disposing += 1;
205
+ try {
206
+ let node = root;
207
+ for (;;) {
208
+ while (node.lastChild !== null) node = node.lastChild;
209
+ const parent = node.parent;
210
+ node.disposeSelf();
211
+ if (node === root || parent === null) break;
212
+ node = parent;
213
+ }
214
+ } finally {
215
+ finishDisposal();
216
+ }
217
+ }
218
+ /**
219
+ * Routes `error` to the nearest handler registered with `catchError` or `onError`, searching `from`
220
+ * and then its ancestors, newest handler first on each owner. Handlers run untracked and restore
221
+ * the caller's tracking even when they rethrow. Use it for errors that happen outside
222
+ * any computation (a rejected promise, an event callback), so they reach the same boundary as errors
223
+ * thrown during rendering. A handler that throws hands its own error to the next handler up the
224
+ * chain. With no handler left the error is uncaught: collected until the running flush or disposal
225
+ * ends (which then throws it), or thrown at once otherwise.
226
+ *
227
+ * @param error The thrown value.
228
+ * @param from The owner where the error happened. Null searches no handler: the error is uncaught.
229
+ * @throws The error (or the last error a handler threw) when no handler catches it and no flush or
230
+ * disposal is running.
231
+ * @example
232
+ * import { currentOwner, handleError } from "@shadow-js/core/extend";
233
+ *
234
+ * export function useSaveOnLoad(save: () => Promise<void>): void {
235
+ * const owner = currentOwner();
236
+ * save().catch((error: unknown) => handleError(error, owner));
237
+ * }
238
+ * @since 1.0.0
239
+ */
240
+ function handleError(error, from) {
241
+ report(DEVTOOLS_EVENT.ERROR, from, error, codeOf(error));
242
+ let current = error;
243
+ for (let owner = from; owner !== null; owner = owner.parent) {
244
+ const handlers = owner.errorHandlers;
245
+ if (handlers === null) continue;
246
+ for (let i = handlers.length - 1; i >= 0; i -= 1) {
247
+ const handler = handlers[i];
248
+ if (handler === void 0) continue;
249
+ const previousListener = rt.listener;
250
+ try {
251
+ rt.listener = null;
252
+ handler(current);
253
+ return;
254
+ } catch (next) {
255
+ current = next;
256
+ } finally {
257
+ rt.listener = previousListener;
258
+ }
259
+ }
260
+ }
261
+ reportUncaught(current);
262
+ }
263
+ /**
264
+ * True when `handleError(_, from)` would reach a handler registered by catchError()/onError().
265
+ * @internal
266
+ */
267
+ function hasErrorHandler(from) {
268
+ for (let owner = from; owner !== null; owner = owner.parent) {
269
+ const handlers = owner.errorHandlers;
270
+ if (handlers !== null && handlers.length > 0) return true;
271
+ }
272
+ return false;
273
+ }
274
+ /**
275
+ * The diagnostic code of a ShadowJS error, for devtools. Reads an own data property only: a getter on a thrown
276
+ * value would run user code inside the error path, and a throw there would replace the error being handled.
277
+ */
278
+ function codeOf(error) {
279
+ if (typeof error !== "object" || error === null) return void 0;
280
+ const descriptor = Object.getOwnPropertyDescriptor(error, "code");
281
+ return descriptor !== void 0 && "value" in descriptor ? descriptor.value : void 0;
282
+ }
283
+ function reportUncaught(error) {
284
+ if (rt.flushing || rt.disposing > 0) rt.uncaught.push(error);
285
+ else throw error;
286
+ }
287
+ //#endregion
288
+ export { Owner, addCleanup, disposeChildren, disposeTree, handleError, hasErrorHandler };
289
+
290
+ //# sourceMappingURL=owner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"owner.js","names":[],"sources":["../../../src/internal/owner.ts"],"sourcesContent":["import { DEVTOOLS_EVENT, report } from \"./devtools\";\nimport { rt } from \"./state\";\nimport type { Cleanup, ErrorHandler } from \"./types\";\n\n/**\n * The context values an owner sees, keyed by the symbol of each context. A provider creates a map\n * whose prototype is its parent's map, so a lookup is one property read and never walks owners.\n * @since 1.0.0\n */\nexport type ContextMap = Record<symbol, unknown>;\n\n/**\n * A node in the ownership tree: it owns the effects, memos and owners created under it, their\n * cleanups and error handlers, and disposes them together. Create one with `createOwner` and end it\n * with `disposeOwner`; the class is exported for `instanceof` checks and for reading its state.\n * Computations (`ComputationNode`) are owners too. Children are a doubly linked list so detaching one\n * is O(1); disposal walks the tree iteratively because its depth is user controlled (R-CODE-11).\n *\n * @example\n * import { createOwner, disposeOwner, Owner } from \"@shadow-js/core/extend\";\n *\n * const owner = createOwner(null);\n * console.log(owner instanceof Owner, owner.depth); // true 0\n * disposeOwner(owner);\n * console.log(owner.disposed); // true\n * @see createOwner\n * @see disposeOwner\n * @since 1.0.0\n */\nexport class Owner {\n /** The owner this node was created under, or null for a root. Kept after disposal. */\n parent: Owner | null;\n /** The newest child that is still alive, or null when there is none. */\n lastChild: Owner | null = null;\n /** The next older sibling that is still alive, or null. */\n prevSibling: Owner | null = null;\n /** The next newer sibling that is still alive, or null. */\n nextSibling: Owner | null = null;\n /**\n * The cleanups registered with `addCleanup` or `onCleanup`: null for none, a function for one, an\n * array (oldest first) for several. Emptied when they run.\n */\n cleanups: Cleanup | Cleanup[] | null = null;\n /** The context values this node sees: inherited from the parent at creation, null for a root. */\n context: ContextMap | null;\n /**\n * The handlers registered with `onError` or `catchError`, oldest first (they are tried newest\n * first), or null for none. A computation clears them before each run.\n */\n errorHandlers: ErrorHandler[] | null = null;\n /** Number of children ever created; gives each child a stable index for useId(). */\n childCount = 0;\n /** Number of ids useId() has handed out from this owner. */\n idCount = 0;\n /** Position among the parent's children, assigned at creation. */\n index: number;\n /** Distance from the root: 0 for a root, the parent's depth plus one otherwise. */\n depth: number;\n /**\n * The hydration-scope prefix of a component's owner, set by the renderer. When present, useId()\n * builds the ids below it from this prefix instead of the owner path.\n * @default undefined\n */\n idPrefix: string | undefined;\n /** True once the node has been disposed. */\n disposed = false;\n /**\n * While this returns true, user effects (and `onMount`) created below this owner wait: they do\n * not run until it returns false for the first time. Suspense sets it so the effects of content\n * that is still loading are held back. The read is tracked.\n */\n gate: (() => boolean) | null = null;\n /**\n * Number of pauses (Activity hidden) that cover this node. Inherited at creation, and changed for a\n * whole subtree by `pauseOwner`/`resumeOwner`. Above zero, effects wait and memos keep their value.\n */\n pauses = 0;\n\n /**\n * Creates an owner and links it as the newest child of `parent`. It inherits the parent's context\n * and pauses.\n * @param parent The owner to attach to, or null for a root.\n */\n constructor(parent: Owner | null) {\n this.parent = parent;\n this.context = parent === null ? null : parent.context;\n this.depth = parent === null ? 0 : parent.depth + 1;\n this.pauses = parent === null ? 0 : parent.pauses;\n if (parent === null) {\n this.index = 0;\n } else {\n this.index = parent.childCount;\n parent.childCount += 1;\n const last = parent.lastChild;\n this.prevSibling = last;\n if (last !== null) last.nextSibling = this;\n parent.lastChild = this;\n }\n // Computations report themselves (with their kind); plain owners and subclasses of it here.\n if (__DEV__ && new.target === Owner) {\n report(DEVTOOLS_EVENT.OWNER_CREATED, this, parent, parent === null ? \"root\" : \"owner\");\n }\n }\n\n /** Tells devtools this node is gone. Computations override it with their own event. */\n protected reportDisposed(): void {\n if (__DEV__) report(DEVTOOLS_EVENT.OWNER_DISPOSED, this);\n }\n\n /** Hook for subclasses: release graph edges before the node is marked disposed. */\n protected release(): void {\n // Plain owners hold no graph edges.\n }\n\n /**\n * Disposes this node only (children must already be gone).\n * @internal\n */\n disposeSelf(): void {\n if (this.disposed) return;\n this.disposed = true;\n // Detach first: a cleanup that throws must never leave a dead node in the tree (R-CODE-5).\n const parent = this.parent;\n if (parent !== null) {\n const prev = this.prevSibling;\n const next = this.nextSibling;\n if (prev !== null) prev.nextSibling = next;\n if (next !== null) next.prevSibling = prev;\n else parent.lastChild = prev;\n this.prevSibling = null;\n this.nextSibling = null;\n }\n this.release();\n this.reportDisposed();\n this.runCleanups();\n }\n\n /**\n * Runs own cleanups newest first, untracked, isolating failures.\n * @internal\n */\n runCleanups(): void {\n const cleanups = this.cleanups;\n if (cleanups === null) return;\n this.cleanups = null;\n const previousOwner = rt.owner;\n const previousListener = rt.listener;\n rt.owner = null;\n rt.listener = null;\n try {\n if (typeof cleanups === \"function\") {\n runCleanup(cleanups, this);\n } else {\n for (let i = cleanups.length - 1; i >= 0; i -= 1) {\n const cleanup = cleanups[i];\n if (cleanup !== undefined) runCleanup(cleanup, this);\n }\n }\n } finally {\n rt.owner = previousOwner;\n rt.listener = previousListener;\n }\n }\n}\n\nfunction runCleanup(cleanup: Cleanup, owner: Owner): void {\n try {\n cleanup();\n } catch (error) {\n handleError(error, owner);\n }\n}\n\n/**\n * Registers `cleanup` on an explicit owner. It runs when the owner is disposed or, when the owner is a\n * computation, before its next run. Cleanups run newest first, untracked and with no current owner;\n * one that throws goes to {@link handleError} for that owner and does not stop the others. Use it\n * where `onCleanup` cannot be called: the owner is not the current one, or the code must not warn.\n * Unlike `onCleanup`, nothing checks that the owner is still alive: a cleanup added to a disposed\n * owner never runs.\n *\n * @param owner The owner whose disposal runs the cleanup.\n * @param cleanup The function to run.\n * @example\n * import { addCleanup, currentOwner } from \"@shadow-js/core/extend\";\n *\n * export function useInterval(tick: () => void, ms: number): void {\n * const owner = currentOwner();\n * const timer = setInterval(tick, ms);\n * if (owner !== null) addCleanup(owner, () => clearInterval(timer));\n * }\n * @see disposeOwner\n * @since 1.0.0\n */\nexport function addCleanup(owner: Owner, cleanup: Cleanup): void {\n const existing = owner.cleanups;\n if (existing === null) owner.cleanups = cleanup;\n else if (typeof existing === \"function\") owner.cleanups = [existing, cleanup];\n else existing.push(cleanup);\n}\n\n/**\n * Disposes every child of `owner` (newest first), keeping `owner` itself alive.\n * @internal\n */\nexport function disposeChildren(owner: Owner): void {\n for (;;) {\n const child = owner.lastChild;\n if (child === null) return;\n disposeTree(child);\n }\n}\n\n/** Rethrows what disposal collected once the outermost disposal is finished. */\nfunction finishDisposal(): void {\n rt.disposing -= 1;\n if (rt.disposing > 0 || rt.flushing || rt.uncaught.length === 0) return;\n const errors = rt.uncaught;\n rt.uncaught = [];\n if (errors.length === 1) throw errors[0];\n throw new AggregateError(\n errors,\n __DEV__ ? \"Several errors were thrown while disposing.\" : \"SHADOW_DISPOSE_ERRORS\",\n );\n}\n\n/**\n * Disposes `root` and everything below it: children first, then own cleanups, newest first.\n * Iterative post-order walk: a leaf is disposed, which re-links its parent's `lastChild`\n * to the previous sibling, so the loop naturally visits the remaining subtree. The public\n * `disposeOwner` (dispose.ts) wraps it with the flush that follows.\n * @internal\n */\nexport function disposeTree(root: Owner): void {\n rt.disposing += 1;\n try {\n let node: Owner = root;\n for (;;) {\n while (node.lastChild !== null) node = node.lastChild;\n const parent: Owner | null = node.parent;\n node.disposeSelf();\n if (node === root || parent === null) break;\n node = parent;\n }\n } finally {\n finishDisposal();\n }\n}\n\n/**\n * Routes `error` to the nearest handler registered with `catchError` or `onError`, searching `from`\n * and then its ancestors, newest handler first on each owner. Handlers run untracked and restore\n * the caller's tracking even when they rethrow. Use it for errors that happen outside\n * any computation (a rejected promise, an event callback), so they reach the same boundary as errors\n * thrown during rendering. A handler that throws hands its own error to the next handler up the\n * chain. With no handler left the error is uncaught: collected until the running flush or disposal\n * ends (which then throws it), or thrown at once otherwise.\n *\n * @param error The thrown value.\n * @param from The owner where the error happened. Null searches no handler: the error is uncaught.\n * @throws The error (or the last error a handler threw) when no handler catches it and no flush or\n * disposal is running.\n * @example\n * import { currentOwner, handleError } from \"@shadow-js/core/extend\";\n *\n * export function useSaveOnLoad(save: () => Promise<void>): void {\n * const owner = currentOwner();\n * save().catch((error: unknown) => handleError(error, owner));\n * }\n * @since 1.0.0\n */\nexport function handleError(error: unknown, from: Owner | null): void {\n if (__DEV__) report(DEVTOOLS_EVENT.ERROR, from, error, codeOf(error));\n let current = error;\n for (let owner = from; owner !== null; owner = owner.parent) {\n const handlers = owner.errorHandlers;\n if (handlers === null) continue;\n for (let i = handlers.length - 1; i >= 0; i -= 1) {\n const handler = handlers[i];\n if (handler === undefined) continue;\n const previousListener = rt.listener;\n try {\n rt.listener = null;\n return void handler(current);\n } catch (next) {\n current = next;\n } finally {\n rt.listener = previousListener;\n }\n }\n }\n reportUncaught(current);\n}\n\n/**\n * True when `handleError(_, from)` would reach a handler registered by catchError()/onError().\n * @internal\n */\nexport function hasErrorHandler(from: Owner | null): boolean {\n for (let owner = from; owner !== null; owner = owner.parent) {\n const handlers = owner.errorHandlers;\n if (handlers !== null && handlers.length > 0) return true;\n }\n return false;\n}\n\n/**\n * The diagnostic code of a ShadowJS error, for devtools. Reads an own data property only: a getter on a thrown\n * value would run user code inside the error path, and a throw there would replace the error being handled.\n */\nfunction codeOf(error: unknown): unknown {\n if (typeof error !== \"object\" || error === null) return undefined;\n const descriptor = Object.getOwnPropertyDescriptor(error, \"code\");\n return descriptor !== undefined && \"value\" in descriptor ? descriptor.value : undefined;\n}\n\nfunction reportUncaught(error: unknown): void {\n if (rt.flushing || rt.disposing > 0) rt.uncaught.push(error);\n else throw error;\n}\n"],"mappings":"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"}
@@ -0,0 +1,46 @@
1
+ import { FLAG_PARKED, FLAG_TRANSITION } from "./flags.js";
2
+ import { rt } from "./state.js";
3
+ //#region src/internal/queue.ts
4
+ /** Urgent effects waiting for the next flush, split by phase (render effects run first). */
5
+ const renderQueue = [];
6
+ const userQueue = [];
7
+ /**
8
+ * Puts an effect where it belongs. `lane` says the write that marked it was a transition write;
9
+ * effects with FLAG_LANE always go to the lane. Lane and paused effects are handed to the transition
10
+ * hooks (their queues live there); everything else is queued here, with no hook involved.
11
+ */
12
+ function place(effect, lane) {
13
+ if ((effect.flags & 2) !== 0) return;
14
+ const inLane = lane || (effect.flags & 512) !== 0;
15
+ const hooks = rt.hooks;
16
+ if (hooks !== null && (inLane || effect.pauses > 0)) {
17
+ hooks.place(effect, inLane);
18
+ return;
19
+ }
20
+ effect.flags = effect.flags & ~(FLAG_PARKED | FLAG_TRANSITION) | 2;
21
+ if ((effect.flags & 16) !== 0) renderQueue.push(effect);
22
+ else userQueue.push(effect);
23
+ }
24
+ /** Queues an effect for the current write: a transition write joins the lane. */
25
+ function enqueue(effect) {
26
+ place(effect, rt.inTransition);
27
+ }
28
+ /** True when an urgent effect is waiting. */
29
+ function hasPending() {
30
+ return renderQueue.length > 0 || userQueue.length > 0;
31
+ }
32
+ /** Drops everything queued (used when a flush is aborted by the loop guard). */
33
+ function clearQueues() {
34
+ for (const queue of [renderQueue, userQueue]) {
35
+ for (const effect of queue) {
36
+ effect.flags &= ~(2 | FLAG_TRANSITION);
37
+ effect.state = 0;
38
+ }
39
+ queue.length = 0;
40
+ }
41
+ rt.hooks?.clear();
42
+ }
43
+ //#endregion
44
+ export { clearQueues, enqueue, hasPending, place, renderQueue, userQueue };
45
+
46
+ //# sourceMappingURL=queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.js","names":[],"sources":["../../../src/internal/queue.ts"],"sourcesContent":["import { CLEAN, FLAG_LANE, FLAG_PARKED, FLAG_QUEUED, FLAG_RENDER, FLAG_TRANSITION } from \"./flags\";\nimport type { Computation } from \"./graph\";\nimport { rt } from \"./state\";\n\n/** Urgent effects waiting for the next flush, split by phase (render effects run first). */\nexport const renderQueue: Computation[] = [];\nexport const userQueue: Computation[] = [];\n\n/**\n * Puts an effect where it belongs. `lane` says the write that marked it was a transition write;\n * effects with FLAG_LANE always go to the lane. Lane and paused effects are handed to the transition\n * hooks (their queues live there); everything else is queued here, with no hook involved.\n */\nexport function place(effect: Computation, lane: boolean): void {\n if ((effect.flags & FLAG_QUEUED) !== 0) return;\n const inLane = lane || (effect.flags & FLAG_LANE) !== 0;\n const hooks = rt.hooks;\n if (hooks !== null && (inLane || effect.pauses > 0)) {\n hooks.place(effect, inLane);\n return;\n }\n effect.flags = (effect.flags & ~(FLAG_PARKED | FLAG_TRANSITION)) | FLAG_QUEUED;\n if ((effect.flags & FLAG_RENDER) !== 0) renderQueue.push(effect);\n else userQueue.push(effect);\n}\n\n/** Queues an effect for the current write: a transition write joins the lane. */\nexport function enqueue(effect: Computation): void {\n place(effect, rt.inTransition);\n}\n\n/** True when an urgent effect is waiting. */\nexport function hasPending(): boolean {\n return renderQueue.length > 0 || userQueue.length > 0;\n}\n\n/** Drops everything queued (used when a flush is aborted by the loop guard). */\nexport function clearQueues(): void {\n for (const queue of [renderQueue, userQueue]) {\n for (const effect of queue) {\n effect.flags &= ~(FLAG_QUEUED | FLAG_TRANSITION);\n // Back to CLEAN so the next write can notify (and re-queue) this effect again.\n effect.state = CLEAN;\n }\n queue.length = 0;\n }\n rt.hooks?.clear();\n}\n"],"mappings":";;;;AAKA,MAAa,cAA6B,CAAC;AAC3C,MAAa,YAA2B,CAAC;;;;;;AAOzC,SAAgB,MAAM,QAAqB,MAAqB;CAC9D,KAAK,OAAO,QAAA,OAAyB,GAAG;CACxC,MAAM,SAAS,SAAS,OAAO,QAAA,SAAuB;CACtD,MAAM,QAAQ,GAAG;CACjB,IAAI,UAAU,SAAS,UAAU,OAAO,SAAS,IAAI;EACnD,MAAM,MAAM,QAAQ,MAAM;EAC1B;CACF;CACA,OAAO,QAAS,OAAO,QAAQ,EAAE,cAAc,mBAAA;CAC/C,KAAK,OAAO,QAAA,QAAyB,GAAG,YAAY,KAAK,MAAM;MAC1D,UAAU,KAAK,MAAM;AAC5B;;AAGA,SAAgB,QAAQ,QAA2B;CACjD,MAAM,QAAQ,GAAG,YAAY;AAC/B;;AAGA,SAAgB,aAAsB;CACpC,OAAO,YAAY,SAAS,KAAK,UAAU,SAAS;AACtD;;AAGA,SAAgB,cAAoB;CAClC,KAAK,MAAM,SAAS,CAAC,aAAa,SAAS,GAAG;EAC5C,KAAK,MAAM,UAAU,OAAO;GAC1B,OAAO,SAAS,EAAA,IAAgB;GAEhC,OAAO,QAAA;EACT;EACA,MAAM,SAAS;CACjB;CACA,GAAG,OAAO,MAAM;AAClB"}