@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,28 @@
1
+ //#region src/internal/state.ts
2
+ /**
3
+ * The runtime registers (R-CODE-4): the only module-level mutable state of core besides
4
+ * monotonic counters. Every write is paired with a `finally` restore (R-CODE-5).
5
+ */
6
+ const rt = {
7
+ owner: null,
8
+ listener: null,
9
+ running: null,
10
+ batchDepth: 0,
11
+ flushing: false,
12
+ recomputeDepth: 0,
13
+ disposing: 0,
14
+ uncaught: [],
15
+ inTransition: false,
16
+ hydrating: false,
17
+ hooks: null
18
+ };
19
+ let counter = 0;
20
+ /** Monotonic creation sequence; orders sibling effects (G-16). */
21
+ function nextSequence() {
22
+ counter += 1;
23
+ return counter;
24
+ }
25
+ //#endregion
26
+ export { nextSequence, rt };
27
+
28
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.js","names":[],"sources":["../../../src/internal/state.ts"],"sourcesContent":["import type { Computation } from \"./graph\";\nimport type { Owner } from \"./owner\";\n\n/**\n * A hold for a value a transition builds while its reads wait for data (a `Show` branch built during a\n * transition): the reads that wait count against this hold, not against the Suspense boundary around\n * the value, so the shown value stays until the hold settles. Created by `createTransitionHold`.\n * @since 1.0.0\n */\nexport interface TransitionHold {\n /** Runs `fn` with this hold as the Suspense boundary of the reads inside it. */\n run<T>(fn: () => T): T;\n /** Reads still waiting for data. */\n count(): number;\n /** True once a read in the hold was held (the value is then pending, not ready). */\n engaged(): boolean;\n /** Ends the hold without waking anything (the value is being dropped). */\n drop(): void;\n}\n\n/**\n * The choice a branch slot (Show, Switch) shows: its index, and what decides a rebuild. Renderers\n * extend it with what they need to build the branch.\n * @since 1.0.0\n */\nexport interface SlotChoice {\n /** Which branch is chosen: its position among the slot's branches, or the renderer's fallback index. */\n readonly index: number;\n /** True when the branch is rebuilt whenever `when` changes identity; false when only `index` counts. */\n readonly keyed: boolean;\n /** The condition value that selected the branch. */\n readonly when: unknown;\n}\n\n/**\n * The record of a branch's owner that its accessors read: the value and whether it is being torn down.\n * @since 1.0.0\n */\nexport interface SlotOwned {\n /** The index of the branch this record belongs to (see {@link SlotChoice.index}). */\n index: number;\n /** The latest condition value while the branch is shown; what its accessor returns during teardown. */\n value: unknown;\n /** True while the branch is torn down: its accessor then returns `value` instead of throwing. */\n disposing: boolean;\n}\n\n/**\n * A branch a slot shows, or builds during a transition. A branch without `dispose` is torn down by its memo.\n * @since 1.0.0\n */\nexport interface SlotBranch<C extends SlotChoice> {\n /** The choice the branch was built for. */\n readonly choice: C;\n /** The record its accessors read. */\n readonly owned: SlotOwned;\n /** What the branch produced: the value the slot's output returns while the branch is shown. */\n readonly result: unknown;\n /**\n * Tears the branch down. Set for the branches a transition built: they live under the holder, not\n * under the memo.\n * @default undefined (the slot's memo tears the branch down)\n */\n readonly dispose?: () => void;\n /**\n * The hold a transition built the branch under; null when none of its reads was held.\n * @default undefined (a memo-owned branch has no hold)\n */\n readonly hold?: TransitionHold | null;\n}\n\n/**\n * What a slot's output memo keeps: the branch on screen (its result is the value the output returns).\n * @since 1.0.0\n */\nexport interface SlotState<C extends SlotChoice> {\n /** The branch on screen, or undefined before the first build and while the memo rebuilds it. */\n live: SlotBranch<C> | undefined;\n}\n\n/**\n * The transition layer of one slot, from `transitionHooks()?.slotSwap(...)`: it keeps the shown\n * branch while a transition builds the next one (see `slotSwap` in concurrency.ts).\n * @since 1.0.0\n */\nexport interface SlotSwap<C extends SlotChoice> {\n /**\n * Runs one pass of the slot's memo for `choice`. True when a transition keeps the shown value. False\n * when the usual path follows: the branch on screen has been retired and `state.live` is cleared.\n */\n step(choice: C): boolean;\n}\n\n/**\n * The hold of one Suspense boundary: engaged by a transition read, released when its data arrived.\n * From `transitionHooks()?.boundaryHold()`.\n * @since 1.0.0\n */\nexport interface BoundaryHold {\n /** Engages the hold (a second call changes nothing) so the boundary keeps its content; returns true. */\n engage(): boolean;\n /** When engaged: wakes the readers that waited, then ends the hold. Otherwise does nothing. */\n release(): void;\n /** True while the hold is engaged. */\n holding(): boolean;\n}\n\n/**\n * The transition machinery the engine calls through `rt.hooks`: transition lanes, pauses (Activity)\n * and suspensions (Suspense holds). It is created by the first call of an API that needs it (see\n * concurrency.ts), so an application that never calls one of those APIs carries none of their code.\n * Renderers reach it through `transitionHooks()`.\n * @since 1.0.0\n */\nexport interface Hooks {\n /** The transition layer of one branch slot (see `slotSwap` in concurrency.ts). */\n slotSwap<C extends SlotChoice>(\n state: SlotState<C>,\n build: (choice: C, owned: SlotOwned, eager: boolean) => unknown,\n same: (a: C, b: C) => boolean,\n parent: Owner | null,\n ): SlotSwap<C>;\n /** A Suspense boundary's hold (see `boundaryHold` in concurrency.ts). */\n boundaryHold(): BoundaryHold;\n /** Queues an effect that is due in the transition lane, or parks it while its owner is paused. */\n place(effect: Computation, inLane: boolean): void;\n /** An urgent write reached an effect that waits in the lane or is parked: it moves to the urgent queue. */\n promote(effect: Computation): void;\n /** Forgets the lane queues (the flush loop guard). */\n clear(): void;\n /** Keeps `node` for a transition when `error` is a suspension; returns false for any other error. */\n suspend(node: Computation, error: unknown): boolean;\n /** The engine side of `holdReader`: throws the suspension sentinel when `tracker.hold()` is true. */\n holdReader(tracker: { hold?(): boolean }): void;\n /** The engine side of `startTransition` in the browser. */\n startTransition(fn: () => void): Promise<void>;\n /** The engine side of `beginHold`: counts one more Suspense hold. */\n beginHold(): void;\n /** The engine side of `endHold`: counts one hold less and settles the lane. */\n endHold(): void;\n /** The engine side of `wakeSuspended`. */\n wakeSuspended(): void;\n /** The engine side of `pauseOwner`. */\n pause(owner: Owner): void;\n /** The engine side of `resumeOwner`. */\n resume(owner: Owner): void;\n /** The engine side of `createTransitionHold`. */\n createHold(onSettled: () => void): TransitionHold;\n}\n\n/**\n * The runtime registers (R-CODE-4): the only module-level mutable state of core besides\n * monotonic counters. Every write is paired with a `finally` restore (R-CODE-5).\n */\nexport const rt: {\n /** Owner that adopts newly created nodes. */\n owner: Owner | null;\n /** Computation that records the signals it reads; null while untracked. */\n listener: Computation | null;\n /** Computation currently executing, tracked or not (used by the write-in-memo guard). */\n running: Computation | null;\n /** Nesting depth of batch()/flushSync() calls. */\n batchDepth: number;\n /** True while the flush loop is draining the effect queues. */\n flushing: boolean;\n /** Nesting depth of memo recomputation, used to switch to iterative pulls. */\n recomputeDepth: number;\n /** Nesting depth of disposals in progress; errors raised meanwhile are collected, not thrown. */\n disposing: number;\n /** Errors nobody handled during the current flush or disposal; rethrown once it completes. */\n uncaught: unknown[];\n /** True while a transition callback or a transition-lane run is active: writes made now join the lane. */\n inTransition: boolean;\n /** True while `hydrate()` claims server markup (useExternalStore reads its server snapshot). */\n hydrating: boolean;\n /** The transition machinery, or null until an API that needs it is first called. */\n hooks: Hooks | null;\n} = {\n owner: null,\n listener: null,\n running: null,\n batchDepth: 0,\n flushing: false,\n recomputeDepth: 0,\n disposing: 0,\n uncaught: [],\n inTransition: false,\n hydrating: false,\n hooks: null,\n};\n\nlet counter = 0;\n/** Monotonic creation sequence; orders sibling effects (G-16). */\nexport function nextSequence(): number {\n counter += 1;\n return counter;\n}\n"],"mappings":";;;;;AA0JA,MAAa,KAuBT;CACF,OAAO;CACP,UAAU;CACV,SAAS;CACT,YAAY;CACZ,UAAU;CACV,gBAAgB;CAChB,WAAW;CACX,UAAU,CAAC;CACX,cAAc;CACd,WAAW;CACX,OAAO;AACT;AAEA,IAAI,UAAU;;AAEd,SAAgB,eAAuB;CACrC,WAAW;CACX,OAAO;AACT"}
@@ -0,0 +1,43 @@
1
+ //#region src/internal/suspension.d.ts
2
+ /**
3
+ * The value a reader throws when a transition reads data that is still loading inside a Suspense
4
+ * boundary that is showing content. The reader keeps its previous value (a memo keeps its value, an
5
+ * effect leaves the DOM as it is) until the boundary releases it. A single frozen object: identity is
6
+ * the test, so user code cannot forge it. {@link holdReader} throws it for you; a custom primitive
7
+ * that catches errors must let it through, which {@link isSuspension} checks.
8
+ *
9
+ * @example
10
+ * import { SUSPENSION } from "@shadow-js/core/extend";
11
+ *
12
+ * function rethrowIfHeld(error: unknown): void {
13
+ * if (error === SUSPENSION) throw error; // not a failure: the boundary resumes the reader later
14
+ * }
15
+ * @see isSuspension
16
+ * @since 1.0.0
17
+ */
18
+ export declare const SUSPENSION: {
19
+ readonly suspended: true;
20
+ };
21
+ /**
22
+ * Tells whether a caught value is the suspension sentinel rather than an error. Use it in a custom
23
+ * primitive's `catch` so a transition's held read is passed on instead of being reported as a
24
+ * failure.
25
+ *
26
+ * @param value The caught value.
27
+ * @returns True when `value` is {@link SUSPENSION}.
28
+ * @example
29
+ * import { isSuspension } from "@shadow-js/core/extend";
30
+ *
31
+ * function attempt(run: () => void, onError: (error: unknown) => void): void {
32
+ * try {
33
+ * run();
34
+ * } catch (error) {
35
+ * if (isSuspension(error)) throw error;
36
+ * onError(error);
37
+ * }
38
+ * }
39
+ * @since 1.0.0
40
+ */
41
+ export declare function isSuspension(value: unknown): boolean;
42
+ //#endregion
43
+ //# sourceMappingURL=suspension.d.ts.map
@@ -0,0 +1,45 @@
1
+ //#region src/internal/suspension.ts
2
+ /**
3
+ * The value a reader throws when a transition reads data that is still loading inside a Suspense
4
+ * boundary that is showing content. The reader keeps its previous value (a memo keeps its value, an
5
+ * effect leaves the DOM as it is) until the boundary releases it. A single frozen object: identity is
6
+ * the test, so user code cannot forge it. {@link holdReader} throws it for you; a custom primitive
7
+ * that catches errors must let it through, which {@link isSuspension} checks.
8
+ *
9
+ * @example
10
+ * import { SUSPENSION } from "@shadow-js/core/extend";
11
+ *
12
+ * function rethrowIfHeld(error: unknown): void {
13
+ * if (error === SUSPENSION) throw error; // not a failure: the boundary resumes the reader later
14
+ * }
15
+ * @see isSuspension
16
+ * @since 1.0.0
17
+ */
18
+ const SUSPENSION = /* @__PURE__ */ Object.freeze({ suspended: true });
19
+ /**
20
+ * Tells whether a caught value is the suspension sentinel rather than an error. Use it in a custom
21
+ * primitive's `catch` so a transition's held read is passed on instead of being reported as a
22
+ * failure.
23
+ *
24
+ * @param value The caught value.
25
+ * @returns True when `value` is {@link SUSPENSION}.
26
+ * @example
27
+ * import { isSuspension } from "@shadow-js/core/extend";
28
+ *
29
+ * function attempt(run: () => void, onError: (error: unknown) => void): void {
30
+ * try {
31
+ * run();
32
+ * } catch (error) {
33
+ * if (isSuspension(error)) throw error;
34
+ * onError(error);
35
+ * }
36
+ * }
37
+ * @since 1.0.0
38
+ */
39
+ function isSuspension(value) {
40
+ return value === SUSPENSION;
41
+ }
42
+ //#endregion
43
+ export { SUSPENSION, isSuspension };
44
+
45
+ //# sourceMappingURL=suspension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suspension.js","names":[],"sources":["../../../src/internal/suspension.ts"],"sourcesContent":["/**\n * The value a reader throws when a transition reads data that is still loading inside a Suspense\n * boundary that is showing content. The reader keeps its previous value (a memo keeps its value, an\n * effect leaves the DOM as it is) until the boundary releases it. A single frozen object: identity is\n * the test, so user code cannot forge it. {@link holdReader} throws it for you; a custom primitive\n * that catches errors must let it through, which {@link isSuspension} checks.\n *\n * @example\n * import { SUSPENSION } from \"@shadow-js/core/extend\";\n *\n * function rethrowIfHeld(error: unknown): void {\n * if (error === SUSPENSION) throw error; // not a failure: the boundary resumes the reader later\n * }\n * @see isSuspension\n * @since 1.0.0\n */\nexport const SUSPENSION: { readonly suspended: true } = /* @__PURE__ */ Object.freeze({\n suspended: true as const,\n});\n\n/**\n * Tells whether a caught value is the suspension sentinel rather than an error. Use it in a custom\n * primitive's `catch` so a transition's held read is passed on instead of being reported as a\n * failure.\n *\n * @param value The caught value.\n * @returns True when `value` is {@link SUSPENSION}.\n * @example\n * import { isSuspension } from \"@shadow-js/core/extend\";\n *\n * function attempt(run: () => void, onError: (error: unknown) => void): void {\n * try {\n * run();\n * } catch (error) {\n * if (isSuspension(error)) throw error;\n * onError(error);\n * }\n * }\n * @since 1.0.0\n */\nexport function isSuspension(value: unknown): boolean {\n return value === SUSPENSION;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAa,aAA2D,uBAAO,OAAO,EACpF,WAAW,KACb,CAAC;;;;;;;;;;;;;;;;;;;;;AAsBD,SAAgB,aAAa,OAAyB;CACpD,OAAO,UAAU;AACnB"}
@@ -0,0 +1,46 @@
1
+ //#region src/internal/types.d.ts
2
+ /**
3
+ * A function that releases what an owner or an effect set up: a timer, a subscription, a listener.
4
+ * Register one with `onCleanup` (or `addCleanup` from `@shadow-js/core/extend`), or return one from
5
+ * an effect.
6
+ * @since 1.0.0
7
+ */
8
+ export type Cleanup = () => void;
9
+ /**
10
+ * A function that receives an error routed to an owner, as registered with `onError` or
11
+ * `catchError`. Throwing from it hands the new error to the next handler up the owner tree.
12
+ * @param error The thrown value; not necessarily an `Error`.
13
+ * @since 1.0.0
14
+ */
15
+ export type ErrorHandler = (error: unknown) => void;
16
+ /**
17
+ * A reactive read: calling it returns the current value, and subscribes the running effect or memo
18
+ * to it when one is listening.
19
+ * @since 1.0.0
20
+ */
21
+ export type Accessor<T> = () => T;
22
+ /**
23
+ * Any function type. {@link Setter} uses it to tell a value from an updater.
24
+ * @since 1.0.0
25
+ */
26
+ export type AnyFunction = (...args: never[]) => unknown;
27
+ /**
28
+ * The writer of a signal: it stores a value, or the result of an updater called with the previous
29
+ * value, and returns what it stored. Function values cannot be passed directly because they would be
30
+ * taken for updaters: wrap them, as in `set(() => fn)`.
31
+ * @since 1.0.0
32
+ */
33
+ export interface Setter<T> {
34
+ /** Stores `value` (not a function) and returns it. */
35
+ <U extends T>(value: Exclude<U, AnyFunction>): U;
36
+ /** Stores what `updater` returns for the previous value, and returns it. */
37
+ <U extends T>(updater: (prev: T) => U): U;
38
+ }
39
+ /**
40
+ * The equality that decides whether a write or a recomputation is a change: readers are notified
41
+ * only when it returns false. `false` instead of a function treats every write as a change.
42
+ * @since 1.0.0
43
+ */
44
+ export type Equals<T> = false | ((prev: T, next: T) => boolean);
45
+ //#endregion
46
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,93 @@
1
+ import { Accessor } from "./internal/types.js";
2
+ //#region src/list.d.ts
3
+ /**
4
+ * A list as the list primitives read it. `null`, `undefined` and `false` count as an empty list.
5
+ * @since 1.0.0
6
+ */
7
+ export type ListSource<T> = () => readonly T[] | null | undefined | false;
8
+ /**
9
+ * Maps each item of a list to a row that lives as long as the item does. Rows whose key survives
10
+ * an update keep their mapped value; new items get new rows; removed items have their rows disposed.
11
+ *
12
+ * Unkeyed: rows are matched by item reference, and `map` receives the item value. Equal primitives
13
+ * pair up in order of occurrence. The returned accessor is lazy and memoized: rows are created and
14
+ * disposed when it is read, so a list nobody reads keeps removed rows alive until the next read.
15
+ *
16
+ * @param list Source list. `null`, `undefined` and `false` are an empty list.
17
+ * @param map Runs once per new row, untracked, in the row's own root. `index()` follows the row.
18
+ * @param options `fallback` is shown while the list is empty. Undefined: an empty list maps to `[]`.
19
+ * @returns Accessor of the mapped rows, in the order of the input.
20
+ * @throws Nothing itself. Reading the accessor rethrows what `map` or a row cleanup threw; several
21
+ * errors at once arrive as one `AggregateError`.
22
+ * @example
23
+ * import { createRoot, mapArray, useSignal } from "@shadow-js/core";
24
+ *
25
+ * createRoot(() => {
26
+ * const [users] = useSignal([{ name: "Ada" }, { name: "Linus" }]);
27
+ * const names = mapArray(users, (user, index) => `${index() + 1}. ${user.name}`);
28
+ * console.log(names()); // ["1. Ada", "2. Linus"]
29
+ * });
30
+ * @see indexArray
31
+ * @since 1.0.0
32
+ */
33
+ export declare function mapArray<T, U>(list: ListSource<T>, map: (item: T, index: () => number) => U, options?: {
34
+ key?: undefined;
35
+ fallback?: () => U;
36
+ }): Accessor<U[]>;
37
+ /**
38
+ * Keyed form: rows are matched by `key(item)`. `map` receives an accessor, so a new object under
39
+ * the same key updates `item()` without re-creating the row. A duplicate key warns in dev and its
40
+ * later copies get fresh rows on every update (dev warning `EACH_KEY_DUPLICATE`, once). Keys
41
+ * compare like `Map` keys, so `NaN` matches `NaN`.
42
+ *
43
+ * @param list Source list. `null`, `undefined` and `false` are an empty list.
44
+ * @param map Runs once per new row, untracked, in the row's own root. `item()` and `index()` follow
45
+ * the row.
46
+ * @param options `key` identifies each item and runs untracked; `fallback` is shown while the list
47
+ * is empty.
48
+ * @returns Accessor of the mapped rows, in the order of the input.
49
+ * @throws Nothing itself. Reading the accessor rethrows what `map`, `key` or a row cleanup threw;
50
+ * several errors at once arrive as one `AggregateError`.
51
+ * @example
52
+ * import { createRoot, mapArray, useSignal } from "@shadow-js/core";
53
+ *
54
+ * createRoot(() => {
55
+ * const [todos] = useSignal([{ id: 1, title: "Write docs" }]);
56
+ * const rows = mapArray(todos, (todo) => `#${todo().id} ${todo().title}`, {
57
+ * key: (todo) => todo.id,
58
+ * });
59
+ * console.log(rows()); // ["#1 Write docs"]
60
+ * });
61
+ * @see indexArray
62
+ * @since 1.0.0
63
+ */
64
+ export declare function mapArray<T, U>(list: ListSource<T>, map: (item: () => T, index: () => number) => U, options: {
65
+ key: (item: T) => unknown;
66
+ fallback?: () => U;
67
+ }): Accessor<U[]>;
68
+ /**
69
+ * Maps each position of a list to a row. Rows are created and removed only when the length
70
+ * changes; the row at position `i` stays, and its `item()` accessor follows the value at `i`.
71
+ *
72
+ * @param list Source list. `null`, `undefined` and `false` are an empty list.
73
+ * @param map Runs once per position, untracked, in the row's own root.
74
+ * @param options `fallback` is shown while the list is empty. Undefined: an empty list maps to `[]`.
75
+ * @returns Accessor of the mapped rows, in the order of the input.
76
+ * @throws Nothing itself. Reading the accessor rethrows what `map` or a row cleanup threw; several
77
+ * errors at once arrive as one `AggregateError`.
78
+ * @example
79
+ * import { createRoot, indexArray, useSignal } from "@shadow-js/core";
80
+ *
81
+ * createRoot(() => {
82
+ * const [values] = useSignal(["a", "b"]);
83
+ * const cells = indexArray(values, (value, index) => `${index}: ${value()}`);
84
+ * console.log(cells()); // ["0: a", "1: b"]
85
+ * });
86
+ * @see mapArray
87
+ * @since 1.0.0
88
+ */
89
+ export declare function indexArray<T, U>(list: ListSource<T>, map: (item: () => T, index: number) => U, options?: {
90
+ fallback?: () => U;
91
+ }): Accessor<U[]>;
92
+ //#endregion
93
+ //# sourceMappingURL=list.d.ts.map
@@ -0,0 +1,282 @@
1
+ import { warn } from "./internal/diagnostics.js";
2
+ import { Owner } from "./internal/owner.js";
3
+ import { readSignal } from "./internal/graph.js";
4
+ import { createRoot, getOwner, onCleanup, runWithOwner, untrack } from "./ownership.js";
5
+ import { disposeTree } from "./internal/dispose.js";
6
+ import { createSignalNode, writeSignal } from "./extend/index.js";
7
+ import { useMemo } from "./memo.js";
8
+ //#region src/list.ts
9
+ /**
10
+ * One mapped row: its own root, its mapped value, and the signals behind `item()` and `index()`. The signals are created
11
+ * by the first read, so a row whose callback never reads its index (or, unkeyed, its item) allocates neither.
12
+ */
13
+ var Row = class {
14
+ /** Reuse key: the item itself (unkeyed), `key(item)` (keyed) or the position (indexed). */
15
+ key;
16
+ /** False for a later copy of a key in a keyed list. Such a row is never reused. */
17
+ first;
18
+ /** Item last written to the row. Kept as a plain field so an unchanged item skips the signal. */
19
+ item;
20
+ /** Index last written to the row. */
21
+ index;
22
+ value = void 0;
23
+ dispose = noop;
24
+ /** Created by the first `item()` read; null until then. */
25
+ itemNode = null;
26
+ /** Created by the first `index()` read; null until then. */
27
+ indexNode = null;
28
+ constructor(key, first, item, index) {
29
+ this.key = key;
30
+ this.first = first;
31
+ this.item = item;
32
+ this.index = index;
33
+ }
34
+ readItem() {
35
+ this.itemNode ??= createSignalNode(this.item, Object.is);
36
+ return readSignal(this.itemNode);
37
+ }
38
+ readIndex() {
39
+ this.indexNode ??= createSignalNode(this.index, Object.is);
40
+ return readSignal(this.indexNode);
41
+ }
42
+ /** List bookkeeping, not a user write: allowed while the list memo computes. */
43
+ setItem(next) {
44
+ this.item = next;
45
+ if (this.itemNode !== null) writeSignal(this.itemNode, next, { allowInMemo: true });
46
+ }
47
+ setIndex(next) {
48
+ this.index = next;
49
+ if (this.indexNode !== null) writeSignal(this.indexNode, next, { allowInMemo: true });
50
+ }
51
+ };
52
+ /** The dispose of a row whose root has not been made yet. */
53
+ function noop() {}
54
+ function mapArray(list, map, options) {
55
+ const keyOf = options?.key;
56
+ return listRows(list, keyOf === void 0 ? {
57
+ keyOf: (item) => item,
58
+ distinct: false
59
+ } : {
60
+ keyOf: (item) => keyOf(item),
61
+ distinct: true
62
+ }, (item, readItem, readIndex) => map(keyOf === void 0 ? item : readItem, readIndex), options?.fallback);
63
+ }
64
+ /**
65
+ * Maps each position of a list to a row. Rows are created and removed only when the length
66
+ * changes; the row at position `i` stays, and its `item()` accessor follows the value at `i`.
67
+ *
68
+ * @param list Source list. `null`, `undefined` and `false` are an empty list.
69
+ * @param map Runs once per position, untracked, in the row's own root.
70
+ * @param options `fallback` is shown while the list is empty. Undefined: an empty list maps to `[]`.
71
+ * @returns Accessor of the mapped rows, in the order of the input.
72
+ * @throws Nothing itself. Reading the accessor rethrows what `map` or a row cleanup threw; several
73
+ * errors at once arrive as one `AggregateError`.
74
+ * @example
75
+ * import { createRoot, indexArray, useSignal } from "@shadow-js/core";
76
+ *
77
+ * createRoot(() => {
78
+ * const [values] = useSignal(["a", "b"]);
79
+ * const cells = indexArray(values, (value, index) => `${index}: ${value()}`);
80
+ * console.log(cells()); // ["0: a", "1: b"]
81
+ * });
82
+ * @see mapArray
83
+ * @since 1.0.0
84
+ */
85
+ function indexArray(list, map, options) {
86
+ return listRows(list, {
87
+ keyOf: (_item, position) => position,
88
+ distinct: false
89
+ }, (_item, readItem, readIndex) => map(readItem, untrack(readIndex)), options?.fallback);
90
+ }
91
+ /**
92
+ * The shared engine. The memo tracks `list()` and reconciles the previous rows against the new
93
+ * items; each row is a child of a private holder owner, so the memo's own recomputation never
94
+ * disposes rows, and disposing the list's owner disposes the holder with every row in it.
95
+ */
96
+ function listRows(list, keying, build, fallback) {
97
+ const holder = new Owner(getOwner());
98
+ onCleanup(() => {
99
+ disposeTree(holder);
100
+ });
101
+ let rows = [];
102
+ let emptyFallback;
103
+ return useMemo(() => {
104
+ const source = listItems(list());
105
+ const items = Array.isArray(source) ? Array.prototype.slice.call(source) : source;
106
+ const entries = untrack(() => toEntries(items, keying));
107
+ const reuse = matchRows(rows, entries);
108
+ const created = [];
109
+ const staged = [];
110
+ let nextFallback;
111
+ try {
112
+ entries.forEach((entry, position) => {
113
+ const from = reuse[position] ?? -1;
114
+ const kept = from === -1 ? void 0 : rows[from];
115
+ if (kept !== void 0) {
116
+ staged.push({
117
+ row: kept,
118
+ item: entry.item,
119
+ position,
120
+ fresh: false
121
+ });
122
+ return;
123
+ }
124
+ const row = openRow(holder, entry.key, entry.first, entry.item, position, build);
125
+ created.push(row);
126
+ staged.push({
127
+ row,
128
+ item: entry.item,
129
+ position,
130
+ fresh: true
131
+ });
132
+ });
133
+ if (entries.length === 0 && fallback !== void 0) nextFallback = emptyFallback ?? openFallback(holder, fallback);
134
+ } catch (error) {
135
+ const failures = [];
136
+ for (const row of created) disposeCollecting(row.dispose, failures);
137
+ if (nextFallback !== void 0 && nextFallback !== emptyFallback) disposeCollecting(nextFallback.dispose, failures);
138
+ throw combineFailures(error, failures);
139
+ }
140
+ const failures = [];
141
+ const previousRows = rows;
142
+ const previousFallback = emptyFallback;
143
+ rows = staged.map((stage) => stage.row);
144
+ emptyFallback = nextFallback;
145
+ const kept = new Uint8Array(previousRows.length);
146
+ for (const from of reuse) if (from !== -1) kept[from] = 1;
147
+ previousRows.forEach((row, from) => {
148
+ if (kept[from] !== 1) disposeCollecting(row.dispose, failures);
149
+ });
150
+ if (previousFallback !== void 0 && previousFallback !== nextFallback) disposeCollecting(previousFallback.dispose, failures);
151
+ for (const stage of staged) {
152
+ if (stage.fresh) continue;
153
+ const row = stage.row;
154
+ if (row.index !== stage.position) row.setIndex(stage.position);
155
+ if (!Object.is(row.item, stage.item)) row.setItem(stage.item);
156
+ }
157
+ throwFailures(failures);
158
+ if (nextFallback !== void 0) return [nextFallback.value];
159
+ return rows.map((row) => row.value);
160
+ }, {
161
+ lazy: true,
162
+ allowWrites: true
163
+ });
164
+ }
165
+ /** Treats `null`, `undefined` and `false` as an empty list. */
166
+ function listItems(value) {
167
+ return value === null || value === void 0 || value === false ? [] : value;
168
+ }
169
+ /** Computes each item's reuse key. Keyed lists flag later copies of a key and warn once. */
170
+ function toEntries(items, keying) {
171
+ const entries = [];
172
+ const seen = /* @__PURE__ */ new Set();
173
+ let duplicate = false;
174
+ for (const [position, item] of items.entries()) {
175
+ const key = keying.keyOf(item, position);
176
+ let first = true;
177
+ if (keying.distinct) {
178
+ if (seen.has(key)) {
179
+ first = false;
180
+ duplicate = true;
181
+ } else seen.add(key);
182
+ }
183
+ entries.push({
184
+ item,
185
+ key,
186
+ first
187
+ });
188
+ }
189
+ if (duplicate) warn("EACH_KEY_DUPLICATE");
190
+ return entries;
191
+ }
192
+ /** Keys compare like `Map` keys: `NaN` matches `NaN`. */
193
+ function sameKey(a, b) {
194
+ return a === b || Number.isNaN(a) && Number.isNaN(b);
195
+ }
196
+ function canReuse(row, entry) {
197
+ return row !== void 0 && entry !== void 0 && row.first && entry.first && sameKey(row.key, entry.key);
198
+ }
199
+ /**
200
+ * Pairs each new position with the old row it reuses; -1 means a fresh row is needed. The prefix
201
+ * and suffix runs settle append, prepend, remove and swap at the ends in one step each. The middle
202
+ * is matched through a Map from key to the chain of old positions with that key (earliest first),
203
+ * so the whole pass is linear on average. Iterative throughout.
204
+ */
205
+ function matchRows(old, next) {
206
+ const m = old.length;
207
+ const n = next.length;
208
+ const reuse = new Int32Array(n).fill(-1);
209
+ let start = 0;
210
+ while (start < m && start < n && canReuse(old[start], next[start])) {
211
+ reuse[start] = start;
212
+ start += 1;
213
+ }
214
+ let oldEnd = m - 1;
215
+ let newEnd = n - 1;
216
+ while (oldEnd >= start && newEnd >= start && canReuse(old[oldEnd], next[newEnd])) {
217
+ reuse[newEnd] = oldEnd;
218
+ oldEnd -= 1;
219
+ newEnd -= 1;
220
+ }
221
+ if (start > oldEnd || start > newEnd) return reuse;
222
+ const heads = /* @__PURE__ */ new Map();
223
+ const chain = new Int32Array(m).fill(-1);
224
+ for (let i = oldEnd; i >= start; i -= 1) {
225
+ const row = old[i];
226
+ if (row === void 0 || !row.first) continue;
227
+ chain[i] = heads.get(row.key) ?? -1;
228
+ heads.set(row.key, i);
229
+ }
230
+ for (let j = start; j <= newEnd; j += 1) {
231
+ const entry = next[j];
232
+ if (entry === void 0 || !entry.first) continue;
233
+ const head = heads.get(entry.key);
234
+ if (head === void 0 || head === -1) continue;
235
+ reuse[j] = head;
236
+ heads.set(entry.key, chain[head] ?? -1);
237
+ }
238
+ return reuse;
239
+ }
240
+ /**
241
+ * Creates one row in its own root under the holder. The row exists before `build` runs, so a read of `item()` or
242
+ * `index()` during the build sees the final values. The root is detached from the memo on purpose.
243
+ */
244
+ function openRow(holder, key, first, item, index, build) {
245
+ const row = new Row(key, first, item, index);
246
+ const readItem = () => row.readItem();
247
+ const readIndex = () => row.readIndex();
248
+ runWithOwner(holder, () => createRoot((dispose) => {
249
+ row.dispose = dispose;
250
+ row.value = untrack(() => build(item, readItem, readIndex));
251
+ }));
252
+ return row;
253
+ }
254
+ /** Creates the empty-list row in its own root under the holder. */
255
+ function openFallback(holder, fallback) {
256
+ return runWithOwner(holder, () => createRoot((dispose) => ({
257
+ value: untrack(fallback),
258
+ dispose
259
+ })));
260
+ }
261
+ /** Disposes one row root. A throwing cleanup is collected so that the other rows still go. */
262
+ function disposeCollecting(dispose, failures) {
263
+ try {
264
+ dispose();
265
+ } catch (error) {
266
+ failures.push(error);
267
+ }
268
+ }
269
+ function combineFailures(primary, failures) {
270
+ if (failures.length === 0) return primary;
271
+ return new AggregateError([primary, ...failures], "Several errors were thrown while mapping a list.");
272
+ }
273
+ /** Rethrows the one disposal failure, or all of them together. */
274
+ function throwFailures(failures) {
275
+ if (failures.length === 0) return;
276
+ if (failures.length === 1) throw failures[0];
277
+ throw new AggregateError(failures, "Several errors were thrown while disposing list rows.");
278
+ }
279
+ //#endregion
280
+ export { indexArray, mapArray };
281
+
282
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.js","names":[],"sources":["../../src/list.ts"],"sourcesContent":["import {\n type Accessor,\n createSignalNode,\n disposeOwner,\n Owner,\n readSignal,\n type SignalNode,\n warn,\n writeSignal,\n} from \"./extend\";\nimport { useMemo } from \"./memo\";\nimport { createRoot, getOwner, onCleanup, runWithOwner, untrack } from \"./ownership\";\n\n/**\n * A list as the list primitives read it. `null`, `undefined` and `false` count as an empty list.\n * @since 1.0.0\n */\nexport type ListSource<T> = () => readonly T[] | null | undefined | false;\n\n/**\n * One mapped row: its own root, its mapped value, and the signals behind `item()` and `index()`. The signals are created\n * by the first read, so a row whose callback never reads its index (or, unkeyed, its item) allocates neither.\n */\nclass Row<T, U> {\n /** Reuse key: the item itself (unkeyed), `key(item)` (keyed) or the position (indexed). */\n readonly key: unknown;\n /** False for a later copy of a key in a keyed list. Such a row is never reused. */\n readonly first: boolean;\n /** Item last written to the row. Kept as a plain field so an unchanged item skips the signal. */\n item: T;\n /** Index last written to the row. */\n index: number;\n value: U = undefined as U;\n dispose: () => void = noop;\n /** Created by the first `item()` read; null until then. */\n private itemNode: SignalNode<T> | null = null;\n /** Created by the first `index()` read; null until then. */\n private indexNode: SignalNode<number> | null = null;\n\n constructor(key: unknown, first: boolean, item: T, index: number) {\n this.key = key;\n this.first = first;\n this.item = item;\n this.index = index;\n }\n\n readItem(): T {\n this.itemNode ??= createSignalNode(this.item, Object.is);\n return readSignal(this.itemNode);\n }\n\n readIndex(): number {\n this.indexNode ??= createSignalNode(this.index, Object.is);\n return readSignal(this.indexNode);\n }\n\n /** List bookkeeping, not a user write: allowed while the list memo computes. */\n setItem(next: T): void {\n this.item = next;\n if (this.itemNode !== null) writeSignal(this.itemNode, next, { allowInMemo: true });\n }\n\n setIndex(next: number): void {\n this.index = next;\n if (this.indexNode !== null) writeSignal(this.indexNode, next, { allowInMemo: true });\n }\n}\n\n/** The dispose of a row whose root has not been made yet. */\nfunction noop(): void {\n // Replaced by the root's own dispose before the row is used.\n}\n\n/** One incoming item of a list update, with the key it is matched by. */\ninterface Entry<T> {\n readonly item: T;\n readonly key: unknown;\n readonly first: boolean;\n}\n\n/** How incoming items are matched against the rows of the previous update. */\ninterface Keying<T> {\n /** Reuse key of the item at `position`. User code, so it runs untracked. */\n readonly keyOf: (item: T, position: number) => unknown;\n /** Keyed lists: only the first copy of a key may reuse a row. Otherwise copies pair up in order. */\n readonly distinct: boolean;\n}\n\n/** The row shown while the list is empty, in its own root. */\ninterface Fallback<U> {\n readonly value: U;\n readonly dispose: () => void;\n}\n\n/** A row chosen by one update, in output order. */\ninterface Staged<T, U> {\n readonly row: Row<T, U>;\n readonly item: T;\n readonly position: number;\n readonly fresh: boolean;\n}\n\n/**\n * Maps each item of a list to a row that lives as long as the item does. Rows whose key survives\n * an update keep their mapped value; new items get new rows; removed items have their rows disposed.\n *\n * Unkeyed: rows are matched by item reference, and `map` receives the item value. Equal primitives\n * pair up in order of occurrence. The returned accessor is lazy and memoized: rows are created and\n * disposed when it is read, so a list nobody reads keeps removed rows alive until the next read.\n *\n * @param list Source list. `null`, `undefined` and `false` are an empty list.\n * @param map Runs once per new row, untracked, in the row's own root. `index()` follows the row.\n * @param options `fallback` is shown while the list is empty. Undefined: an empty list maps to `[]`.\n * @returns Accessor of the mapped rows, in the order of the input.\n * @throws Nothing itself. Reading the accessor rethrows what `map` or a row cleanup threw; several\n * errors at once arrive as one `AggregateError`.\n * @example\n * import { createRoot, mapArray, useSignal } from \"@shadow-js/core\";\n *\n * createRoot(() => {\n * const [users] = useSignal([{ name: \"Ada\" }, { name: \"Linus\" }]);\n * const names = mapArray(users, (user, index) => `${index() + 1}. ${user.name}`);\n * console.log(names()); // [\"1. Ada\", \"2. Linus\"]\n * });\n * @see indexArray\n * @since 1.0.0\n */\nexport function mapArray<T, U>(\n list: ListSource<T>,\n map: (item: T, index: () => number) => U,\n options?: { key?: undefined; fallback?: () => U },\n): Accessor<U[]>;\n/**\n * Keyed form: rows are matched by `key(item)`. `map` receives an accessor, so a new object under\n * the same key updates `item()` without re-creating the row. A duplicate key warns in dev and its\n * later copies get fresh rows on every update (dev warning `EACH_KEY_DUPLICATE`, once). Keys\n * compare like `Map` keys, so `NaN` matches `NaN`.\n *\n * @param list Source list. `null`, `undefined` and `false` are an empty list.\n * @param map Runs once per new row, untracked, in the row's own root. `item()` and `index()` follow\n * the row.\n * @param options `key` identifies each item and runs untracked; `fallback` is shown while the list\n * is empty.\n * @returns Accessor of the mapped rows, in the order of the input.\n * @throws Nothing itself. Reading the accessor rethrows what `map`, `key` or a row cleanup threw;\n * several errors at once arrive as one `AggregateError`.\n * @example\n * import { createRoot, mapArray, useSignal } from \"@shadow-js/core\";\n *\n * createRoot(() => {\n * const [todos] = useSignal([{ id: 1, title: \"Write docs\" }]);\n * const rows = mapArray(todos, (todo) => `#${todo().id} ${todo().title}`, {\n * key: (todo) => todo.id,\n * });\n * console.log(rows()); // [\"#1 Write docs\"]\n * });\n * @see indexArray\n * @since 1.0.0\n */\nexport function mapArray<T, U>(\n list: ListSource<T>,\n map: (item: () => T, index: () => number) => U,\n options: { key: (item: T) => unknown; fallback?: () => U },\n): Accessor<U[]>;\nexport function mapArray<T, U>(\n list: ListSource<T>,\n map: (item: T | (() => T), index: () => number) => U,\n options?: { key?: ((item: T) => unknown) | undefined; fallback?: (() => U) | undefined },\n): Accessor<U[]> {\n const keyOf = options?.key;\n return listRows(\n list,\n keyOf === undefined\n ? { keyOf: (item: T) => item, distinct: false }\n : { keyOf: (item: T) => keyOf(item), distinct: true },\n (item, readItem, readIndex) => map(keyOf === undefined ? item : readItem, readIndex),\n options?.fallback,\n );\n}\n\n/**\n * Maps each position of a list to a row. Rows are created and removed only when the length\n * changes; the row at position `i` stays, and its `item()` accessor follows the value at `i`.\n *\n * @param list Source list. `null`, `undefined` and `false` are an empty list.\n * @param map Runs once per position, untracked, in the row's own root.\n * @param options `fallback` is shown while the list is empty. Undefined: an empty list maps to `[]`.\n * @returns Accessor of the mapped rows, in the order of the input.\n * @throws Nothing itself. Reading the accessor rethrows what `map` or a row cleanup threw; several\n * errors at once arrive as one `AggregateError`.\n * @example\n * import { createRoot, indexArray, useSignal } from \"@shadow-js/core\";\n *\n * createRoot(() => {\n * const [values] = useSignal([\"a\", \"b\"]);\n * const cells = indexArray(values, (value, index) => `${index}: ${value()}`);\n * console.log(cells()); // [\"0: a\", \"1: b\"]\n * });\n * @see mapArray\n * @since 1.0.0\n */\nexport function indexArray<T, U>(\n list: ListSource<T>,\n map: (item: () => T, index: number) => U,\n options?: { fallback?: () => U },\n): Accessor<U[]> {\n return listRows(\n list,\n { keyOf: (_item: T, position: number) => position, distinct: false },\n (_item, readItem, readIndex) => map(readItem, untrack(readIndex)),\n options?.fallback,\n );\n}\n\n/**\n * The shared engine. The memo tracks `list()` and reconciles the previous rows against the new\n * items; each row is a child of a private holder owner, so the memo's own recomputation never\n * disposes rows, and disposing the list's owner disposes the holder with every row in it.\n */\nfunction listRows<T, U>(\n list: ListSource<T>,\n keying: Keying<T>,\n build: (item: T, readItem: () => T, readIndex: () => number) => U,\n fallback: (() => U) | undefined,\n): Accessor<U[]> {\n const holder = new Owner(getOwner());\n onCleanup(() => {\n disposeOwner(holder);\n });\n let rows: Row<T, U>[] = [];\n let emptyFallback: Fallback<U> | undefined;\n return useMemo<U[]>(\n () => {\n // Reading the list's contents is tracked, so a store array (proxy) updates the list when an\n // item is pushed, removed or replaced; user key functions then run untracked.\n const source = listItems(list());\n const items: readonly unknown[] = Array.isArray(source)\n ? Array.prototype.slice.call(source)\n : source;\n const entries = untrack(() => toEntries(items as readonly never[], keying));\n const reuse = matchRows(rows, entries);\n const created: Row<T, U>[] = [];\n const staged: Staged<T, U>[] = [];\n let nextFallback: Fallback<U> | undefined;\n try {\n entries.forEach((entry, position) => {\n const from = reuse[position] ?? -1;\n const kept = from === -1 ? undefined : rows[from];\n if (kept !== undefined) {\n staged.push({ row: kept, item: entry.item, position, fresh: false });\n return;\n }\n const row = openRow(holder, entry.key, entry.first, entry.item, position, build);\n created.push(row);\n staged.push({ row, item: entry.item, position, fresh: true });\n });\n if (entries.length === 0 && fallback !== undefined) {\n nextFallback = emptyFallback ?? openFallback(holder, fallback);\n }\n } catch (error) {\n // Nothing above touched the previous state, so only the rows made in this pass go.\n const failures: unknown[] = [];\n for (const row of created) disposeCollecting(row.dispose, failures);\n if (nextFallback !== undefined && nextFallback !== emptyFallback) {\n disposeCollecting(nextFallback.dispose, failures);\n }\n throw combineFailures(error, failures);\n }\n\n // Commit. Writes to retained rows come last, after every creation has succeeded.\n const failures: unknown[] = [];\n const previousRows = rows;\n const previousFallback = emptyFallback;\n rows = staged.map((stage) => stage.row);\n emptyFallback = nextFallback;\n const kept = new Uint8Array(previousRows.length);\n for (const from of reuse) {\n if (from !== -1) kept[from] = 1;\n }\n previousRows.forEach((row, from) => {\n if (kept[from] !== 1) disposeCollecting(row.dispose, failures);\n });\n if (previousFallback !== undefined && previousFallback !== nextFallback) {\n disposeCollecting(previousFallback.dispose, failures);\n }\n for (const stage of staged) {\n if (stage.fresh) continue;\n const row = stage.row;\n if (row.index !== stage.position) row.setIndex(stage.position);\n if (!Object.is(row.item, stage.item)) row.setItem(stage.item);\n }\n throwFailures(failures);\n if (nextFallback !== undefined) return [nextFallback.value];\n return rows.map((row) => row.value);\n },\n // The row callbacks build children (components, refs, directives): setup may write signals.\n { lazy: true, allowWrites: true },\n );\n}\n\n/** Treats `null`, `undefined` and `false` as an empty list. */\nfunction listItems<T>(value: readonly T[] | null | undefined | false): readonly T[] {\n return value === null || value === undefined || value === false ? [] : value;\n}\n\n/** Computes each item's reuse key. Keyed lists flag later copies of a key and warn once. */\nfunction toEntries<T>(items: readonly T[], keying: Keying<T>): Entry<T>[] {\n const entries: Entry<T>[] = [];\n const seen = new Set<unknown>();\n let duplicate = false;\n for (const [position, item] of items.entries()) {\n const key = keying.keyOf(item, position);\n let first = true;\n if (keying.distinct) {\n if (seen.has(key)) {\n first = false;\n duplicate = true;\n } else {\n seen.add(key);\n }\n }\n entries.push({ item, key, first });\n }\n if (duplicate) warn(\"EACH_KEY_DUPLICATE\");\n return entries;\n}\n\n/** Keys compare like `Map` keys: `NaN` matches `NaN`. */\nfunction sameKey(a: unknown, b: unknown): boolean {\n return a === b || (Number.isNaN(a) && Number.isNaN(b));\n}\n\nfunction canReuse<T, U>(row: Row<T, U> | undefined, entry: Entry<T> | undefined): boolean {\n return (\n row !== undefined &&\n entry !== undefined &&\n row.first &&\n entry.first &&\n sameKey(row.key, entry.key)\n );\n}\n\n/**\n * Pairs each new position with the old row it reuses; -1 means a fresh row is needed. The prefix\n * and suffix runs settle append, prepend, remove and swap at the ends in one step each. The middle\n * is matched through a Map from key to the chain of old positions with that key (earliest first),\n * so the whole pass is linear on average. Iterative throughout.\n */\nfunction matchRows<T, U>(old: readonly Row<T, U>[], next: readonly Entry<T>[]): Int32Array {\n const m = old.length;\n const n = next.length;\n const reuse = new Int32Array(n).fill(-1);\n let start = 0;\n while (start < m && start < n && canReuse(old[start], next[start])) {\n reuse[start] = start;\n start += 1;\n }\n let oldEnd = m - 1;\n let newEnd = n - 1;\n while (oldEnd >= start && newEnd >= start && canReuse(old[oldEnd], next[newEnd])) {\n reuse[newEnd] = oldEnd;\n oldEnd -= 1;\n newEnd -= 1;\n }\n if (start > oldEnd || start > newEnd) return reuse;\n\n const heads = new Map<unknown, number>();\n const chain = new Int32Array(m).fill(-1);\n for (let i = oldEnd; i >= start; i -= 1) {\n const row = old[i];\n if (row === undefined || !row.first) continue;\n chain[i] = heads.get(row.key) ?? -1;\n heads.set(row.key, i);\n }\n for (let j = start; j <= newEnd; j += 1) {\n const entry = next[j];\n if (entry === undefined || !entry.first) continue;\n const head = heads.get(entry.key);\n if (head === undefined || head === -1) continue;\n reuse[j] = head;\n heads.set(entry.key, chain[head] ?? -1);\n }\n return reuse;\n}\n\n/**\n * Creates one row in its own root under the holder. The row exists before `build` runs, so a read of `item()` or\n * `index()` during the build sees the final values. The root is detached from the memo on purpose.\n */\nfunction openRow<T, U>(\n holder: Owner,\n key: unknown,\n first: boolean,\n item: T,\n index: number,\n build: (item: T, readItem: () => T, readIndex: () => number) => U,\n): Row<T, U> {\n const row = new Row<T, U>(key, first, item, index);\n const readItem = (): T => row.readItem();\n const readIndex = (): number => row.readIndex();\n runWithOwner(holder, () =>\n createRoot((dispose) => {\n row.dispose = dispose;\n row.value = untrack(() => build(item, readItem, readIndex));\n }),\n );\n return row;\n}\n\n/** Creates the empty-list row in its own root under the holder. */\nfunction openFallback<U>(holder: Owner, fallback: () => U): Fallback<U> {\n return runWithOwner(holder, () =>\n createRoot((dispose) => ({ value: untrack(fallback), dispose })),\n );\n}\n\n/** Disposes one row root. A throwing cleanup is collected so that the other rows still go. */\nfunction disposeCollecting(dispose: () => void, failures: unknown[]): void {\n try {\n dispose();\n } catch (error) {\n failures.push(error);\n }\n}\n\nfunction combineFailures(primary: unknown, failures: readonly unknown[]): unknown {\n if (failures.length === 0) return primary;\n return new AggregateError(\n [primary, ...failures],\n __DEV__ ? \"Several errors were thrown while mapping a list.\" : \"SHADOW_MAP_ERRORS\",\n );\n}\n\n/** Rethrows the one disposal failure, or all of them together. */\nfunction throwFailures(failures: readonly unknown[]): void {\n if (failures.length === 0) return;\n if (failures.length === 1) throw failures[0];\n throw new AggregateError(\n failures,\n __DEV__\n ? \"Several errors were thrown while disposing list rows.\"\n : \"SHADOW_LIST_DISPOSE_ERRORS\",\n );\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,IAAM,MAAN,MAAgB;;CAEd;;CAEA;;CAEA;;CAEA;CACA,QAAW,KAAA;CACX,UAAsB;;CAEtB,WAA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