@shadow-js/core 0.1.0 → 1.0.1

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 +17 -0
  2. package/LICENSE +2 -2
  3. package/README.md +134 -331
  4. package/dist/dev/action.d.ts +34 -0
  5. package/dist/dev/action.js +89 -0
  6. package/dist/dev/action.js.map +1 -0
  7. package/dist/dev/cache.d.ts +33 -0
  8. package/dist/dev/cache.js +61 -0
  9. package/dist/dev/cache.js.map +1 -0
  10. package/dist/dev/context.d.ts +104 -0
  11. package/dist/dev/context.js +110 -0
  12. package/dist/dev/context.js.map +1 -0
  13. package/dist/dev/effect.d.ts +120 -0
  14. package/dist/dev/effect.js +110 -0
  15. package/dist/dev/effect.js.map +1 -0
  16. package/dist/dev/env.d.ts +27 -0
  17. package/dist/dev/env.js +30 -0
  18. package/dist/dev/env.js.map +1 -0
  19. package/dist/dev/events.d.ts +26 -0
  20. package/dist/dev/events.js +32 -0
  21. package/dist/dev/events.js.map +1 -0
  22. package/dist/dev/extend/index.d.ts +329 -0
  23. package/dist/dev/extend/index.js +316 -0
  24. package/dist/dev/extend/index.js.map +1 -0
  25. package/dist/dev/external-store.d.ts +58 -0
  26. package/dist/dev/external-store.js +59 -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 +211 -0
  31. package/dist/dev/internal/concurrency.js +631 -0
  32. package/dist/dev/internal/concurrency.js.map +1 -0
  33. package/dist/dev/internal/devtools.d.ts +69 -0
  34. package/dist/dev/internal/devtools.js +76 -0
  35. package/dist/dev/internal/devtools.js.map +1 -0
  36. package/dist/dev/internal/diagnostics.d.ts +88 -0
  37. package/dist/dev/internal/diagnostics.js +101 -0
  38. package/dist/dev/internal/diagnostics.js.map +1 -0
  39. package/dist/dev/internal/dispose.d.ts +26 -0
  40. package/dist/dev/internal/dispose.js +48 -0
  41. package/dist/dev/internal/dispose.js.map +1 -0
  42. package/dist/dev/internal/flags.js +10 -0
  43. package/dist/dev/internal/flags.js.map +1 -0
  44. package/dist/dev/internal/graph.d.ts +231 -0
  45. package/dist/dev/internal/graph.js +577 -0
  46. package/dist/dev/internal/graph.js.map +1 -0
  47. package/dist/dev/internal/hydration-flag.d.ts +31 -0
  48. package/dist/dev/internal/hydration-flag.js +45 -0
  49. package/dist/dev/internal/hydration-flag.js.map +1 -0
  50. package/dist/dev/internal/messages.d.ts +54 -0
  51. package/dist/dev/internal/messages.js +53 -0
  52. package/dist/dev/internal/messages.js.map +1 -0
  53. package/dist/dev/internal/owner.d.ts +140 -0
  54. package/dist/dev/internal/owner.js +289 -0
  55. package/dist/dev/internal/owner.js.map +1 -0
  56. package/dist/dev/internal/queue.js +45 -0
  57. package/dist/dev/internal/queue.js.map +1 -0
  58. package/dist/dev/internal/scheduler.d.ts +111 -0
  59. package/dist/dev/internal/scheduler.js +286 -0
  60. package/dist/dev/internal/scheduler.js.map +1 -0
  61. package/dist/dev/internal/state.d.ts +139 -0
  62. package/dist/dev/internal/state.js +27 -0
  63. package/dist/dev/internal/state.js.map +1 -0
  64. package/dist/dev/internal/suspension.d.ts +41 -0
  65. package/dist/dev/internal/suspension.js +44 -0
  66. package/dist/dev/internal/suspension.js.map +1 -0
  67. package/dist/dev/internal/types.d.ts +44 -0
  68. package/dist/dev/list.d.ts +91 -0
  69. package/dist/dev/list.js +281 -0
  70. package/dist/dev/list.js.map +1 -0
  71. package/dist/dev/memo.d.ts +58 -0
  72. package/dist/dev/memo.js +40 -0
  73. package/dist/dev/memo.js.map +1 -0
  74. package/dist/dev/optimistic.d.ts +24 -0
  75. package/dist/dev/optimistic.js +44 -0
  76. package/dist/dev/optimistic.js.map +1 -0
  77. package/dist/dev/ownership.d.ts +202 -0
  78. package/dist/dev/ownership.js +260 -0
  79. package/dist/dev/ownership.js.map +1 -0
  80. package/dist/dev/props.d.ts +132 -0
  81. package/dist/dev/props.js +281 -0
  82. package/dist/dev/props.js.map +1 -0
  83. package/dist/dev/reaction.d.ts +27 -0
  84. package/dist/dev/reaction.js +60 -0
  85. package/dist/dev/reaction.js.map +1 -0
  86. package/dist/dev/reducer.d.ts +39 -0
  87. package/dist/dev/reducer.js +38 -0
  88. package/dist/dev/reducer.js.map +1 -0
  89. package/dist/dev/refs.d.ts +50 -0
  90. package/dist/dev/refs.js +57 -0
  91. package/dist/dev/refs.js.map +1 -0
  92. package/dist/dev/resource.d.ts +133 -0
  93. package/dist/dev/resource.js +176 -0
  94. package/dist/dev/resource.js.map +1 -0
  95. package/dist/dev/selector.d.ts +32 -0
  96. package/dist/dev/selector.js +117 -0
  97. package/dist/dev/selector.js.map +1 -0
  98. package/dist/dev/signal.d.ts +40 -0
  99. package/dist/dev/signal.js +38 -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 +191 -0
  104. package/dist/dev/store/nodes.js.map +1 -0
  105. package/dist/dev/store/proxies.js +159 -0
  106. package/dist/dev/store/proxies.js.map +1 -0
  107. package/dist/dev/store/read.d.ts +37 -0
  108. package/dist/dev/store/read.js +71 -0
  109. package/dist/dev/store/read.js.map +1 -0
  110. package/dist/dev/store/reconcile.d.ts +71 -0
  111. package/dist/dev/store/reconcile.js +185 -0
  112. package/dist/dev/store/reconcile.js.map +1 -0
  113. package/dist/dev/store/types.d.ts +104 -0
  114. package/dist/dev/store/use-store.d.ts +58 -0
  115. package/dist/dev/store/use-store.js +167 -0
  116. package/dist/dev/store/use-store.js.map +1 -0
  117. package/dist/dev/suspense.d.ts +99 -0
  118. package/dist/dev/suspense.js +44 -0
  119. package/dist/dev/suspense.js.map +1 -0
  120. package/dist/dev/transitions.d.ts +75 -0
  121. package/dist/dev/transitions.js +100 -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 +89 -0
  284. package/dist/server-dev/action.js.map +1 -0
  285. package/dist/server-dev/cache.js +61 -0
  286. package/dist/server-dev/cache.js.map +1 -0
  287. package/dist/server-dev/context.js +107 -0
  288. package/dist/server-dev/context.js.map +1 -0
  289. package/dist/server-dev/effect.js +55 -0
  290. package/dist/server-dev/effect.js.map +1 -0
  291. package/dist/server-dev/env.js +30 -0
  292. package/dist/server-dev/env.js.map +1 -0
  293. package/dist/server-dev/events.js +32 -0
  294. package/dist/server-dev/events.js.map +1 -0
  295. package/dist/server-dev/extend/index.js +316 -0
  296. package/dist/server-dev/extend/index.js.map +1 -0
  297. package/dist/server-dev/external-store.js +45 -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 +632 -0
  301. package/dist/server-dev/internal/concurrency.js.map +1 -0
  302. package/dist/server-dev/internal/devtools.js +76 -0
  303. package/dist/server-dev/internal/devtools.js.map +1 -0
  304. package/dist/server-dev/internal/diagnostics.js +101 -0
  305. package/dist/server-dev/internal/diagnostics.js.map +1 -0
  306. package/dist/server-dev/internal/dispose.js +48 -0
  307. package/dist/server-dev/internal/dispose.js.map +1 -0
  308. package/dist/server-dev/internal/flags.js +10 -0
  309. package/dist/server-dev/internal/flags.js.map +1 -0
  310. package/dist/server-dev/internal/graph.js +577 -0
  311. package/dist/server-dev/internal/graph.js.map +1 -0
  312. package/dist/server-dev/internal/hydration-flag.js +45 -0
  313. package/dist/server-dev/internal/hydration-flag.js.map +1 -0
  314. package/dist/server-dev/internal/messages.js +53 -0
  315. package/dist/server-dev/internal/messages.js.map +1 -0
  316. package/dist/server-dev/internal/owner.js +289 -0
  317. package/dist/server-dev/internal/owner.js.map +1 -0
  318. package/dist/server-dev/internal/queue.js +45 -0
  319. package/dist/server-dev/internal/queue.js.map +1 -0
  320. package/dist/server-dev/internal/scheduler.js +286 -0
  321. package/dist/server-dev/internal/scheduler.js.map +1 -0
  322. package/dist/server-dev/internal/state.js +27 -0
  323. package/dist/server-dev/internal/state.js.map +1 -0
  324. package/dist/server-dev/internal/suspension.js +44 -0
  325. package/dist/server-dev/internal/suspension.js.map +1 -0
  326. package/dist/server-dev/list.js +281 -0
  327. package/dist/server-dev/list.js.map +1 -0
  328. package/dist/server-dev/memo.js +40 -0
  329. package/dist/server-dev/memo.js.map +1 -0
  330. package/dist/server-dev/optimistic.js +44 -0
  331. package/dist/server-dev/optimistic.js.map +1 -0
  332. package/dist/server-dev/ownership.js +260 -0
  333. package/dist/server-dev/ownership.js.map +1 -0
  334. package/dist/server-dev/props.js +281 -0
  335. package/dist/server-dev/props.js.map +1 -0
  336. package/dist/server-dev/reaction.js +60 -0
  337. package/dist/server-dev/reaction.js.map +1 -0
  338. package/dist/server-dev/reducer.js +38 -0
  339. package/dist/server-dev/reducer.js.map +1 -0
  340. package/dist/server-dev/refs.js +57 -0
  341. package/dist/server-dev/refs.js.map +1 -0
  342. package/dist/server-dev/resource.js +175 -0
  343. package/dist/server-dev/resource.js.map +1 -0
  344. package/dist/server-dev/selector.js +81 -0
  345. package/dist/server-dev/selector.js.map +1 -0
  346. package/dist/server-dev/signal.js +38 -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 +191 -0
  350. package/dist/server-dev/store/nodes.js.map +1 -0
  351. package/dist/server-dev/store/proxies.js +159 -0
  352. package/dist/server-dev/store/proxies.js.map +1 -0
  353. package/dist/server-dev/store/read.js +71 -0
  354. package/dist/server-dev/store/read.js.map +1 -0
  355. package/dist/server-dev/store/reconcile.js +185 -0
  356. package/dist/server-dev/store/reconcile.js.map +1 -0
  357. package/dist/server-dev/store/use-store.js +167 -0
  358. package/dist/server-dev/store/use-store.js.map +1 -0
  359. package/dist/server-dev/suspense.js +44 -0
  360. package/dist/server-dev/suspense.js.map +1 -0
  361. package/dist/server-dev/transitions.js +85 -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
package/dist/index.cjs DELETED
@@ -1,2000 +0,0 @@
1
- 'use strict';
2
-
3
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
4
- // src/runtime/lifecycle.ts
5
- var scopeStack = [];
6
- var compStartMap = /* @__PURE__ */ new WeakMap();
7
- function pushComponentScope() {
8
- const s = { cleanups: [] };
9
- scopeStack.push(s);
10
- return s;
11
- }
12
- function popComponentScope() {
13
- return scopeStack.pop() || null;
14
- }
15
- function getCurrentScope() {
16
- return scopeStack.length ? scopeStack[scopeStack.length - 1] : null;
17
- }
18
- function registerCleanup(fn) {
19
- const s = getCurrentScope();
20
- if (s) s.cleanups.push(fn);
21
- }
22
- function runCleanups(scope) {
23
- for (let i = scope.cleanups.length - 1; i >= 0; i--) {
24
- try {
25
- scope.cleanups[i]();
26
- } catch {
27
- }
28
- }
29
- scope.cleanups.length = 0;
30
- }
31
- function markComponentBoundary(start, end, scope) {
32
- compStartMap.set(start, { end, scope });
33
- }
34
- function disposeIfComponentStart(node) {
35
- if (!node || node.nodeType !== Node.COMMENT_NODE) return;
36
- const start = node;
37
- const entry = compStartMap.get(start);
38
- if (!entry) return;
39
- runCleanups(entry.scope);
40
- compStartMap.delete(start);
41
- }
42
- function deepDisposeNode(node) {
43
- if (node.nodeType === Node.COMMENT_NODE) {
44
- disposeIfComponentStart(node);
45
- }
46
- let child = node.firstChild || null;
47
- while (child) {
48
- const next = child.nextSibling;
49
- deepDisposeNode(child);
50
- child = next;
51
- }
52
- }
53
- function disposeBetween(start, end) {
54
- const parent = start.parentNode;
55
- if (!parent) return;
56
- let cur = start.nextSibling;
57
- while (cur && cur !== end) {
58
- const next = cur.nextSibling;
59
- deepDisposeNode(cur);
60
- parent.removeChild(cur);
61
- cur = next;
62
- }
63
- }
64
- function disposeAllChildren(parent) {
65
- let cur = parent.firstChild;
66
- while (cur) {
67
- const next = cur.nextSibling;
68
- deepDisposeNode(cur);
69
- parent.removeChild(cur);
70
- cur = next;
71
- }
72
- }
73
- function runInScope(scope, fn) {
74
- scopeStack.push(scope);
75
- try {
76
- return fn();
77
- } finally {
78
- scopeStack.pop();
79
- }
80
- }
81
-
82
- // src/errors.ts
83
- var ERRORS = {
84
- // --- render ---
85
- RENDER_CONTAINER_REQUIRED: () => new Error("Container element is required for rendering"),
86
- RENDER_INVALID_COMPONENT: () => new Error("Invalid component type. Must be a function or DOM element"),
87
- RENDER_INVALID_RETURN: () => new Error("Component must return a valid DOM element"),
88
- // --- portal ---
89
- PORTAL_MOUNT_REQUIRED: () => new Error("Portal: 'mount' element is required"),
90
- // --- for (each-only) ---
91
- FOR_CHILDREN_MUST_BE_FUNCTION: () => new Error("<For> requires function children."),
92
- FOR_EACH_REQUIRES_ARRAY: () => new Error("<For each> expects an array (or function returning an array)."),
93
- // --- show ---
94
- SHOW_INVALID_WHEN: () => new Error(
95
- "<Show> 'when' must be a boolean or a function returning a boolean."
96
- ),
97
- // --- switch ---
98
- SWITCH_NO_CHILDREN_OR_FALLBACK: () => new Error(
99
- "<Switch> requires at least one <Match when> child or a 'fallback'."
100
- ),
101
- // --- jsx ---
102
- JSX_INVALID_TAG: (tag) => new Error(
103
- `Invalid JSX tag: expected a string (intrinsic) or function component, received ${typeof tag}`
104
- ),
105
- // --- lazy ---
106
- LAZY_INVALID_EXPORT: () => new Error("Lazy component must have a default export or be a function"),
107
- LAZY_FAILED_AFTER_ATTEMPTS: (retries, reason) => {
108
- const msg = reason instanceof Error ? reason.message : String(reason);
109
- return new Error(
110
- `Failed to load lazy component after ${retries} attempts: ${msg}`
111
- );
112
- },
113
- // --- hooks ---
114
- HOOK_OUTSIDE_COMPONENT: (name) => new Error(`${name} must be called during a component's execution`),
115
- HOOK_INVALID_DEPS: (name) => new Error(`${name}: 'deps' must be an array of functions`),
116
- HOOK_INVALID_REDUCER: (name) => new Error(`${name}: 'reducer' must be a function`),
117
- HOOK_INVALID_ARGUMENT: (hook, argName, expected) => new Error(`${hook}: '${argName}' must be a ${expected}`)
118
- };
119
-
120
- // src/reactivity/hooks/useEffect.ts
121
- var __currentEffect = null;
122
- var __currentEffectDeps = null;
123
- var __effectStack = [];
124
- function useEffect(fn, deps) {
125
- if (typeof fn !== "function") {
126
- throw ERRORS.HOOK_INVALID_ARGUMENT("useEffect", "fn", "function");
127
- }
128
- if (deps !== void 0) {
129
- if (!Array.isArray(deps) || deps.some((d) => typeof d !== "function")) {
130
- throw ERRORS.HOOK_INVALID_DEPS("useEffect");
131
- }
132
- }
133
- let lastDepsValues = [];
134
- let isInitialized = false;
135
- let userCleanup = null;
136
- const runUserCleanup = () => {
137
- if (userCleanup) {
138
- try {
139
- userCleanup();
140
- } catch {
141
- }
142
- userCleanup = null;
143
- }
144
- };
145
- function hasDepChanged() {
146
- if (!deps) return true;
147
- const current = deps.map((dep) => dep());
148
- if (lastDepsValues.length !== current.length) {
149
- lastDepsValues = current;
150
- return true;
151
- }
152
- for (let i = 0; i < current.length; i++) {
153
- if (current[i] !== lastDepsValues[i]) {
154
- lastDepsValues = current;
155
- return true;
156
- }
157
- }
158
- return false;
159
- }
160
- let latestDepsSetsForAuto = /* @__PURE__ */ new Set();
161
- let latestDepsSetsForDep = /* @__PURE__ */ new Set();
162
- const unsubscribeSets = (sets, effectFn) => {
163
- sets.forEach((s) => s.delete(effectFn));
164
- };
165
- const execute = () => {
166
- if (!deps) {
167
- unsubscribeSets(latestDepsSetsForAuto, execute);
168
- }
169
- if (deps) {
170
- if (!isInitialized) {
171
- isInitialized = true;
172
- lastDepsValues = deps.map((dep) => dep());
173
- const ret = fn();
174
- if (typeof ret === "function") userCleanup = ret;
175
- } else if (hasDepChanged()) {
176
- runUserCleanup();
177
- const ret = fn();
178
- if (typeof ret === "function") userCleanup = ret;
179
- }
180
- } else {
181
- runUserCleanup();
182
- __currentEffect = execute;
183
- __effectStack.push(execute);
184
- __currentEffectDeps = /* @__PURE__ */ new Set();
185
- try {
186
- const ret = fn();
187
- if (typeof ret === "function") userCleanup = ret;
188
- } finally {
189
- latestDepsSetsForAuto = __currentEffectDeps;
190
- __currentEffectDeps = null;
191
- __effectStack.pop();
192
- __currentEffect = __effectStack[__effectStack.length - 1] || null;
193
- }
194
- }
195
- };
196
- if (deps) {
197
- const depEffect = () => {
198
- unsubscribeSets(latestDepsSetsForDep, depEffect);
199
- __currentEffect = depEffect;
200
- __effectStack.push(depEffect);
201
- __currentEffectDeps = /* @__PURE__ */ new Set();
202
- try {
203
- deps.forEach((dep) => dep());
204
- latestDepsSetsForDep = __currentEffectDeps;
205
- if (!isInitialized || hasDepChanged()) {
206
- execute();
207
- }
208
- } finally {
209
- __currentEffectDeps = null;
210
- __effectStack.pop();
211
- __currentEffect = __effectStack[__effectStack.length - 1] || null;
212
- }
213
- };
214
- depEffect();
215
- registerCleanup(() => {
216
- unsubscribeSets(latestDepsSetsForDep, depEffect);
217
- runUserCleanup();
218
- });
219
- return depEffect;
220
- } else {
221
- execute();
222
- registerCleanup(() => {
223
- unsubscribeSets(latestDepsSetsForAuto, execute);
224
- runUserCleanup();
225
- });
226
- return execute;
227
- }
228
- }
229
- function untrack(fn) {
230
- const prevEffect = __currentEffect;
231
- const prevDeps = __currentEffectDeps;
232
- __currentEffect = null;
233
- __currentEffectDeps = null;
234
- try {
235
- return fn();
236
- } finally {
237
- __currentEffect = prevEffect;
238
- __currentEffectDeps = prevDeps;
239
- }
240
- }
241
-
242
- // src/reactivity/scheduler.ts
243
- var pending = false;
244
- var queue = /* @__PURE__ */ new Set();
245
- function flush() {
246
- pending = false;
247
- const tasks = Array.from(queue);
248
- queue.clear();
249
- for (const fn of tasks) {
250
- try {
251
- fn();
252
- } catch {
253
- }
254
- }
255
- }
256
- function scheduleEffect(fn) {
257
- queue.add(fn);
258
- if (!pending) {
259
- pending = true;
260
- queueMicrotask(flush);
261
- }
262
- }
263
-
264
- // src/reactivity/hooks/useStore.ts
265
- function useStore(initialValue, opts) {
266
- var _a;
267
- let value = initialValue;
268
- const hot = typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) }) !== "undefined" ? undefined : null;
269
- if (opts?.hmrKey && hot?.data) {
270
- const bucket = (_a = hot.data).__shadowStores || (_a.__shadowStores = /* @__PURE__ */ Object.create(null));
271
- if (opts.hmrKey in bucket) {
272
- value = bucket[opts.hmrKey];
273
- }
274
- hot.accept?.();
275
- hot.dispose?.(() => {
276
- bucket[opts.hmrKey] = value;
277
- });
278
- }
279
- const subscribers = /* @__PURE__ */ new Set();
280
- const read = () => {
281
- if (__currentEffect) {
282
- subscribers.add(__currentEffect);
283
- }
284
- if (__currentEffectDeps) {
285
- __currentEffectDeps.add(subscribers);
286
- }
287
- return value;
288
- };
289
- const write = (newValue) => {
290
- value = typeof newValue === "function" ? newValue(value) : newValue;
291
- if (value !== newValue) {
292
- subscribers.forEach((effect) => scheduleEffect(effect));
293
- }
294
- };
295
- const store = (() => read());
296
- Object.defineProperty(store, "value", {
297
- get: read,
298
- set: write
299
- });
300
- store.__isStore = true;
301
- return [store, write];
302
- }
303
-
304
- // src/reactivity/hooks/useData.ts
305
- function useData(source, fetcher, deps) {
306
- if (fetcher !== void 0 && typeof fetcher !== "function") {
307
- throw ERRORS.HOOK_INVALID_ARGUMENT("useData", "fetcher", "function");
308
- }
309
- if (deps !== void 0) {
310
- if (!Array.isArray(deps) || deps.some((d) => typeof d !== "function")) {
311
- throw ERRORS.HOOK_INVALID_DEPS("useData");
312
- }
313
- }
314
- const getSource = typeof source === "function" ? source : () => source;
315
- const [state, setState] = useStore({
316
- data: void 0,
317
- loading: !!fetcher,
318
- error: null,
319
- lastSource: getSource(),
320
- initialized: false
321
- });
322
- let currentFetchId = 0;
323
- async function runFetch() {
324
- if (!fetcher) return;
325
- const fetchId = ++currentFetchId;
326
- const currentSource = getSource();
327
- setState({
328
- ...state(),
329
- loading: true,
330
- error: null
331
- });
332
- try {
333
- const result = await fetcher(currentSource);
334
- if (fetchId === currentFetchId) {
335
- setState({
336
- data: result,
337
- loading: false,
338
- error: null,
339
- lastSource: currentSource,
340
- initialized: true
341
- });
342
- }
343
- } catch (err) {
344
- if (fetchId === currentFetchId) {
345
- setState({
346
- ...state(),
347
- error: err,
348
- loading: false,
349
- lastSource: currentSource,
350
- initialized: true
351
- });
352
- }
353
- }
354
- }
355
- useEffect(
356
- () => {
357
- runFetch();
358
- },
359
- deps || [() => getSource()]
360
- );
361
- const data = (() => state().data);
362
- data.loading = () => state().loading;
363
- data.error = () => state().error;
364
- data.mutate = (value) => {
365
- const newValue = typeof value === "function" ? value(state().data) : value;
366
- setState({
367
- ...state(),
368
- data: newValue,
369
- loading: false,
370
- error: null,
371
- initialized: true
372
- });
373
- };
374
- data.refetch = async () => {
375
- await runFetch();
376
- };
377
- return data;
378
- }
379
-
380
- // src/reactivity/hooks/useId.ts
381
- var globalIdCounter = 0;
382
- function generateNextId() {
383
- globalIdCounter += 1;
384
- return String(globalIdCounter);
385
- }
386
- function useId() {
387
- const next = generateNextId();
388
- return `sfid-${next}`;
389
- }
390
-
391
- // src/reactivity/hooks/useMemo.ts
392
- function useMemo(fn) {
393
- if (typeof fn !== "function") {
394
- throw ERRORS.HOOK_INVALID_ARGUMENT("useMemo", "fn", "function");
395
- }
396
- const [get, set] = useStore(fn());
397
- useEffect(() => {
398
- set(fn());
399
- });
400
- return get;
401
- }
402
-
403
- // src/reactivity/hooks/useOptimistic.ts
404
- function isStore(value) {
405
- return typeof value === "function" && value.__isStore === true;
406
- }
407
- function useOptimistic(base, reducer) {
408
- if (reducer !== void 0 && typeof reducer !== "function") {
409
- throw ERRORS.HOOK_INVALID_REDUCER("useOptimistic");
410
- }
411
- const getBaseValue = () => isStore(base) ? base() : base;
412
- const [optimistic, setOptimistic] = useStore(getBaseValue());
413
- useEffect(() => {
414
- if (isStore(base)) {
415
- setOptimistic(base());
416
- }
417
- });
418
- const apply = (arg) => {
419
- if (reducer) {
420
- setOptimistic(reducer(optimistic(), arg));
421
- } else {
422
- setOptimistic(arg);
423
- }
424
- };
425
- return [optimistic, apply];
426
- }
427
-
428
- // src/reactivity/hooks/onMount.ts
429
- function onMount(fn) {
430
- if (typeof fn !== "function") {
431
- throw ERRORS.HOOK_INVALID_ARGUMENT("onMount", "fn", "function");
432
- }
433
- if (!getCurrentScope()) {
434
- throw ERRORS.HOOK_OUTSIDE_COMPONENT("onMount");
435
- }
436
- fn();
437
- }
438
-
439
- // src/reactivity/hooks/onCleanup.ts
440
- function onCleanup(fn) {
441
- if (typeof fn !== "function") {
442
- throw ERRORS.HOOK_INVALID_ARGUMENT("onCleanup", "fn", "function");
443
- }
444
- if (!getCurrentScope()) {
445
- throw ERRORS.HOOK_OUTSIDE_COMPONENT("onCleanup");
446
- }
447
- registerCleanup(fn);
448
- }
449
-
450
- // src/runtime/shared/isComponentThunk.ts
451
- function isComponentThunk(v) {
452
- return typeof v === "function" && v.__isComponent === true;
453
- }
454
-
455
- // src/runtime/Fragment.ts
456
- function createReactiveSection(parent, valueOrFunction) {
457
- const startComment = document.createComment("f-r-s");
458
- const endComment = document.createComment("f-r-e");
459
- parent.appendChild(startComment);
460
- parent.appendChild(endComment);
461
- const scope = pushComponentScope();
462
- markComponentBoundary(startComment, endComment, scope);
463
- const insertBeforeEnd = (end, content) => {
464
- const parentNode = startComment.parentNode;
465
- if (!parentNode) return;
466
- const insert = (v) => {
467
- if (v === null || v === void 0 || typeof v === "boolean") return;
468
- if (typeof v === "function") {
469
- try {
470
- if (isComponentThunk(v)) {
471
- parentNode.insertBefore(v(), end);
472
- } else {
473
- insert(v());
474
- }
475
- } catch {
476
- }
477
- return;
478
- }
479
- if (typeof v === "string" || typeof v === "number") {
480
- parentNode.insertBefore(document.createTextNode(String(v)), end);
481
- return;
482
- }
483
- if (Array.isArray(v)) {
484
- v.forEach((x) => insert(x));
485
- return;
486
- }
487
- if (typeof v === "object" && v !== null && "nodeType" in v) {
488
- parentNode.insertBefore(v, end);
489
- return;
490
- }
491
- parentNode.insertBefore(document.createTextNode(String(v)), end);
492
- };
493
- insert(content);
494
- };
495
- const update = () => {
496
- const parentNode = startComment.parentNode;
497
- if (!parentNode) return;
498
- const newContent = untrack(() => {
499
- let v = typeof valueOrFunction === "function" ? valueOrFunction() : valueOrFunction;
500
- try {
501
- if (typeof v === "function") v = v();
502
- } catch {
503
- }
504
- return v;
505
- });
506
- disposeBetween(startComment, endComment);
507
- insertBeforeEnd(endComment, newContent);
508
- };
509
- update();
510
- useEffect(update);
511
- popComponentScope();
512
- }
513
- function addToParent(parent, child) {
514
- if (child === null || child === void 0) return;
515
- if (typeof child === "object" && child !== null && "nodeType" in child) {
516
- parent.appendChild(child);
517
- return;
518
- }
519
- if (typeof child === "function") {
520
- createReactiveSection(parent, child);
521
- return;
522
- }
523
- if (typeof child === "string" || typeof child === "number") {
524
- parent.appendChild(document.createTextNode(String(child)));
525
- return;
526
- }
527
- if (typeof child === "boolean") return;
528
- const textNode = document.createTextNode(String(child));
529
- parent.appendChild(textNode);
530
- }
531
- function appendChild(parent, child) {
532
- if (Array.isArray(child)) {
533
- child.forEach((nested) => appendChild(parent, nested));
534
- } else {
535
- addToParent(parent, child);
536
- }
537
- }
538
- function Fragment({ children }) {
539
- const fragment = document.createDocumentFragment();
540
- if (children !== void 0) {
541
- appendChild(fragment, children);
542
- }
543
- return fragment;
544
- }
545
-
546
- // src/runtime/shared/warn.ts
547
- var DEV = typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) }) !== "undefined" && undefined && undefined?.DEV || typeof process !== "undefined" && process.env && true;
548
- function warn(condition, message) {
549
- if (DEV && !condition) {
550
- console.warn(`[ShadowJS] ${message}`);
551
- }
552
- }
553
-
554
- // src/runtime/For.ts
555
- function For(props) {
556
- const fragment = document.createDocumentFragment();
557
- const start = document.createComment("for-s");
558
- const end = document.createComment("for-e");
559
- fragment.appendChild(start);
560
- fragment.appendChild(end);
561
- if (typeof props.children !== "function") {
562
- throw ERRORS.FOR_CHILDREN_MUST_BE_FUNCTION();
563
- }
564
- const keyToBlock = /* @__PURE__ */ new Map();
565
- const objectIdentityToKey = /* @__PURE__ */ new WeakMap();
566
- let objectIdentityCounter = 0;
567
- const getParent = () => start.parentNode;
568
- const toNode2 = (value) => {
569
- if (value === null || value === void 0 || typeof value === "boolean") {
570
- return document.createComment("");
571
- }
572
- if (typeof value === "function") {
573
- try {
574
- if (isComponentThunk(value)) {
575
- return value();
576
- }
577
- return toNode2(value());
578
- } catch {
579
- return document.createComment("error");
580
- }
581
- }
582
- if (typeof value === "object" && value !== null && "nodeType" in value)
583
- return value;
584
- if (Array.isArray(value)) {
585
- const df = document.createDocumentFragment();
586
- value.forEach((v) => {
587
- const n = toNode2(v);
588
- if (n) df.appendChild(n);
589
- });
590
- return df;
591
- }
592
- return document.createTextNode(String(value));
593
- };
594
- const appendChild2 = (parent, child, before) => {
595
- if (Array.isArray(child)) {
596
- child.forEach((n) => appendChild2(parent, n, before));
597
- return;
598
- }
599
- if (child === null || child === void 0 || typeof child === "boolean")
600
- return;
601
- if (typeof child === "function") {
602
- try {
603
- if (isComponentThunk(child)) {
604
- parent.insertBefore(child(), before);
605
- } else {
606
- appendChild2(parent, child(), before);
607
- }
608
- } catch {
609
- parent.insertBefore(document.createComment("error"), before);
610
- }
611
- return;
612
- }
613
- if (typeof child === "object" && child !== null && "nodeType" in child) {
614
- parent.insertBefore(child, before);
615
- return;
616
- }
617
- parent.insertBefore(document.createTextNode(String(child)), before);
618
- };
619
- const createBlockAt = (before, content) => {
620
- const s = document.createComment("for-item-s");
621
- const e = document.createComment("for-item-e");
622
- const parent = getParent();
623
- if (!parent) return { start: s, end: e };
624
- parent.insertBefore(s, before);
625
- appendChild2(parent, content, before);
626
- parent.insertBefore(e, before);
627
- return { start: s, end: e };
628
- };
629
- const removeBlock = (block) => {
630
- const parent = getParent();
631
- if (!parent) return;
632
- disposeBetween(block.start, block.end);
633
- parent.removeChild(block.start);
634
- parent.removeChild(block.end);
635
- };
636
- const moveBlockBefore = (block, before) => {
637
- const parent = getParent();
638
- if (!parent) return;
639
- if (block.start === before) return;
640
- const afterEnd = block.end.nextSibling;
641
- let node = block.start;
642
- while (node && node !== afterEnd) {
643
- const next = node.nextSibling;
644
- parent.insertBefore(node, before);
645
- node = next;
646
- }
647
- };
648
- const defaultKey = (item, index) => {
649
- if (item && typeof item === "object") {
650
- let k = objectIdentityToKey.get(item);
651
- if (!k) {
652
- k = `o:${++objectIdentityCounter}`;
653
- objectIdentityToKey.set(item, k);
654
- }
655
- return k;
656
- }
657
- return `v:${String(item)}@${index}`;
658
- };
659
- const update = () => {
660
- const parent = getParent();
661
- if (!parent) return;
662
- const source = typeof props.each === "function" ? props.each() : props.each;
663
- if (!Array.isArray(source)) {
664
- throw ERRORS.FOR_EACH_REQUIRES_ARRAY();
665
- }
666
- const expectedKeys = [];
667
- for (let i = 0; i < source.length; i++) {
668
- expectedKeys.push(defaultKey(source[i], i));
669
- }
670
- const expectedSet = new Set(expectedKeys);
671
- for (const [k, block] of keyToBlock.entries()) {
672
- if (!expectedSet.has(k)) {
673
- removeBlock(block);
674
- keyToBlock.delete(k);
675
- }
676
- }
677
- const s = new Set(expectedKeys);
678
- warn(
679
- s.size === expectedKeys.length,
680
- "<For> detected duplicate keys. This can cause incorrect reordering."
681
- );
682
- let cursor = start.nextSibling;
683
- for (let i = 0; i < source.length; i++) {
684
- const item = source[i];
685
- const key = expectedKeys[i];
686
- const existing = keyToBlock.get(key);
687
- if (existing) {
688
- if (existing.start !== cursor) moveBlockBefore(existing, cursor);
689
- cursor = existing.end.nextSibling;
690
- } else {
691
- const content = props.children(item, i);
692
- const block = createBlockAt(cursor, toNode2(content));
693
- keyToBlock.set(key, block);
694
- cursor = block.end.nextSibling;
695
- }
696
- }
697
- };
698
- update();
699
- useEffect(update);
700
- return fragment;
701
- }
702
-
703
- // src/runtime/Show.ts
704
- function Show(props) {
705
- if (typeof props.when !== "boolean" && typeof props.when !== "function") {
706
- throw ERRORS.SHOW_INVALID_WHEN();
707
- }
708
- warn(
709
- props.children !== void 0 || props.fallback !== void 0,
710
- "<Show> has no children or fallback; renders empty content."
711
- );
712
- const fragment = document.createDocumentFragment();
713
- const start = document.createComment("show-s");
714
- const end = document.createComment("show-e");
715
- fragment.appendChild(start);
716
- fragment.appendChild(end);
717
- const getParent = () => start.parentNode;
718
- const toNode2 = (value) => {
719
- if (typeof value === "function") {
720
- try {
721
- if (isComponentThunk(value)) {
722
- return value();
723
- }
724
- return toNode2(value());
725
- } catch {
726
- return document.createComment("error");
727
- }
728
- }
729
- if (value === null || value === void 0 || typeof value === "boolean") {
730
- return document.createComment("");
731
- }
732
- if (typeof value === "object" && value !== null && "nodeType" in value)
733
- return value;
734
- if (Array.isArray(value)) {
735
- const df = document.createDocumentFragment();
736
- value.forEach((v) => df.appendChild(toNode2(v)));
737
- return df;
738
- }
739
- return document.createTextNode(String(value));
740
- };
741
- const detachBetween = () => {
742
- const parent = getParent();
743
- if (!parent) return [];
744
- const nodes = [];
745
- let cur = start.nextSibling;
746
- while (cur && cur !== end) {
747
- const next = cur.nextSibling;
748
- nodes.push(cur);
749
- parent.removeChild(cur);
750
- cur = next;
751
- }
752
- return nodes;
753
- };
754
- const insertNodes = (nodes) => {
755
- const parent = getParent();
756
- if (!parent) return;
757
- nodes.forEach((n) => parent.insertBefore(n, end));
758
- };
759
- const materialize = (content) => {
760
- const n = toNode2(content);
761
- if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
762
- const arr = [];
763
- let c = n.firstChild;
764
- while (c) {
765
- const next = c.nextSibling;
766
- arr.push(c);
767
- c = next;
768
- }
769
- return arr;
770
- }
771
- return [n];
772
- };
773
- let lastCond = null;
774
- let cachedTrueContent = null;
775
- let cachedFalseContent = null;
776
- const computeCond = () => {
777
- try {
778
- return typeof props.when === "function" ? props.when() : props.when;
779
- } catch {
780
- return false;
781
- }
782
- };
783
- const shouldUnmount = props.unmount === void 0 ? false : !!props.unmount;
784
- const update = () => {
785
- const parent = getParent();
786
- if (!parent) return;
787
- const cond = computeCond();
788
- const mat = (c) => untrack(() => materialize(c));
789
- if (lastCond === null) {
790
- lastCond = cond;
791
- if (cond) {
792
- insertNodes(mat(props.children));
793
- } else if (props.fallback !== void 0) {
794
- insertNodes(mat(props.fallback));
795
- }
796
- return;
797
- }
798
- if (cond === lastCond) return;
799
- if (shouldUnmount) {
800
- disposeBetween(start, end);
801
- if (cond) {
802
- insertNodes(mat(props.children));
803
- } else if (props.fallback !== void 0) {
804
- insertNodes(mat(props.fallback));
805
- }
806
- } else {
807
- disposeBetween(start, end);
808
- const detachedNodes = detachBetween();
809
- if (lastCond) {
810
- cachedTrueContent = detachedNodes;
811
- } else if (props.fallback !== void 0) {
812
- cachedFalseContent = detachedNodes;
813
- }
814
- let toInsert = [];
815
- if (cond) {
816
- toInsert = mat(cachedTrueContent || props.children);
817
- cachedTrueContent = null;
818
- } else if (props.fallback !== void 0) {
819
- toInsert = mat(cachedFalseContent || props.fallback);
820
- cachedFalseContent = null;
821
- }
822
- if (toInsert.length) insertNodes(toInsert);
823
- }
824
- lastCond = cond;
825
- };
826
- update();
827
- useEffect(update);
828
- return fragment;
829
- }
830
-
831
- // src/runtime/Switch.ts
832
- function Match() {
833
- return null;
834
- }
835
- function Switch(props) {
836
- const fragment = document.createDocumentFragment();
837
- const start = document.createComment("switch-s");
838
- const end = document.createComment("switch-e");
839
- fragment.appendChild(start);
840
- fragment.appendChild(end);
841
- const getParent = () => start.parentNode;
842
- const toNode2 = (value) => {
843
- if (typeof value === "function") {
844
- try {
845
- if (isComponentThunk(value)) {
846
- return value();
847
- }
848
- return toNode2(value());
849
- } catch {
850
- return document.createComment("error");
851
- }
852
- }
853
- if (value === null || value === void 0 || typeof value === "boolean") {
854
- return document.createComment("");
855
- }
856
- if (typeof value === "object" && value !== null && "nodeType" in value)
857
- return value;
858
- if (Array.isArray(value)) {
859
- const df = document.createDocumentFragment();
860
- value.forEach((v) => df.appendChild(toNode2(v)));
861
- return df;
862
- }
863
- return document.createTextNode(String(value));
864
- };
865
- const flatten = (children) => {
866
- if (children === null || children === void 0) return [];
867
- return Array.isArray(children) ? children.flatMap((c) => flatten(c)) : [children];
868
- };
869
- const isMatchMarker = (child) => child !== null && typeof child === "object" && ("__isMatch" in child && child.__isMatch === true || "type" in child && child.type === Match || "$$typeof" in child && "type" in child && child.type === Match);
870
- const update = () => {
871
- const parent = getParent();
872
- if (!parent) return;
873
- disposeBetween(start, end);
874
- const all = flatten(props.children);
875
- const hasMatch = all.some((c) => isMatchMarker(c));
876
- if (!hasMatch && props.fallback === void 0) {
877
- throw ERRORS.SWITCH_NO_CHILDREN_OR_FALLBACK();
878
- }
879
- for (const child of all) {
880
- if (isMatchMarker(child)) {
881
- let cond = false;
882
- try {
883
- const whenProp = child?.props?.when;
884
- cond = typeof whenProp === "function" ? whenProp() : Boolean(whenProp);
885
- } catch {
886
- cond = false;
887
- }
888
- if (cond) {
889
- const node = untrack(
890
- () => toNode2(
891
- child?.props?.children
892
- )
893
- );
894
- parent.insertBefore(node, end);
895
- return;
896
- }
897
- }
898
- }
899
- if (props.fallback !== void 0) {
900
- const node = untrack(() => toNode2(props.fallback));
901
- parent.insertBefore(node, end);
902
- }
903
- };
904
- update();
905
- useEffect(update);
906
- return fragment;
907
- }
908
-
909
- // src/runtime/Title.ts
910
- function Title(props) {
911
- const prevTitle = document.title;
912
- let lastSet = null;
913
- const toText = (v) => {
914
- if (v == null || typeof v === "boolean") return "";
915
- if (typeof v === "string" || typeof v === "number") return String(v);
916
- if (typeof v === "function") {
917
- if (isComponentThunk(v)) {
918
- warn(
919
- false,
920
- "<Title> children should be text; component children are ignored."
921
- );
922
- return "";
923
- }
924
- try {
925
- return toText(v());
926
- } catch {
927
- return "";
928
- }
929
- }
930
- if (Array.isArray(v)) {
931
- return v.map((x) => toText(x)).join("");
932
- }
933
- if (typeof v === "object" && v !== null && "nodeType" in v) {
934
- try {
935
- return v.textContent ?? "";
936
- } catch {
937
- return "";
938
- }
939
- }
940
- return String(v);
941
- };
942
- useEffect(() => {
943
- const next = toText(props.children);
944
- document.title = next;
945
- lastSet = next;
946
- });
947
- onCleanup(() => {
948
- if (lastSet !== null && document.title === lastSet) {
949
- document.title = prevTitle;
950
- }
951
- });
952
- return document.createDocumentFragment();
953
- }
954
-
955
- // src/runtime/jsx.ts
956
- var SVG_NS = "http://www.w3.org/2000/svg";
957
- var XLINK_NS = "http://www.w3.org/1999/xlink";
958
- var SVG_ONLY_TAGS = /* @__PURE__ */ new Set([
959
- "svg",
960
- "g",
961
- "path",
962
- "rect",
963
- "circle",
964
- "ellipse",
965
- "line",
966
- "polyline",
967
- "polygon",
968
- "text",
969
- "tspan",
970
- "textPath",
971
- "marker",
972
- "defs",
973
- "clipPath",
974
- "mask",
975
- "linearGradient",
976
- "radialGradient",
977
- "pattern",
978
- "stop",
979
- "filter",
980
- "feBlend",
981
- "feColorMatrix",
982
- "feComponentTransfer",
983
- "feComposite",
984
- "feConvolveMatrix",
985
- "feDiffuseLighting",
986
- "feDisplacementMap",
987
- "feDistantLight",
988
- "feDropShadow",
989
- "feFlood",
990
- "feFuncA",
991
- "feFuncB",
992
- "feFuncG",
993
- "feFuncR",
994
- "feGaussianBlur",
995
- "feImage",
996
- "feMerge",
997
- "feMergeNode",
998
- "feMorphology",
999
- "feOffset",
1000
- "fePointLight",
1001
- "feSpecularLighting",
1002
- "feSpotLight",
1003
- "feTile",
1004
- "feTurbulence",
1005
- "foreignObject",
1006
- "symbol",
1007
- "use",
1008
- "view",
1009
- "image",
1010
- "animate",
1011
- "animateTransform",
1012
- "animateMotion",
1013
- "mpath"
1014
- ]);
1015
- var BOOLEAN_ATTRS = /* @__PURE__ */ new Set([
1016
- "checked",
1017
- "disabled",
1018
- "selected",
1019
- "readonly",
1020
- "required",
1021
- "hidden",
1022
- "multiple",
1023
- "autofocus",
1024
- "autoplay",
1025
- "controls",
1026
- "loop",
1027
- "muted",
1028
- "open",
1029
- "playsinline",
1030
- "inert"
1031
- ]);
1032
- function appendContent(parent, before, value) {
1033
- const insert = (val) => {
1034
- if (val === null || val === void 0 || typeof val === "boolean") return;
1035
- if (typeof val === "function" && isComponentThunk(val)) {
1036
- try {
1037
- const node = val();
1038
- parent.insertBefore(node, before);
1039
- } catch {
1040
- }
1041
- return;
1042
- }
1043
- if (typeof val === "function") {
1044
- try {
1045
- insert(val());
1046
- } catch {
1047
- }
1048
- return;
1049
- }
1050
- if (typeof val === "object" && val !== null && "nodeType" in val) {
1051
- parent.insertBefore(val, before);
1052
- return;
1053
- }
1054
- if (Array.isArray(val)) {
1055
- val.forEach((x) => insert(x));
1056
- return;
1057
- }
1058
- parent.insertBefore(document.createTextNode(String(val)), before);
1059
- };
1060
- insert(value);
1061
- }
1062
- function createComponentThunk(tag, props, children) {
1063
- const thunk = /* @__PURE__ */ (() => {
1064
- return () => {
1065
- const scope = pushComponentScope();
1066
- const frag = document.createDocumentFragment();
1067
- const start = document.createComment("comp-s");
1068
- const end = document.createComment("comp-e");
1069
- frag.appendChild(start);
1070
- frag.appendChild(end);
1071
- markComponentBoundary(start, end, scope);
1072
- let result;
1073
- let threwThenable = null;
1074
- try {
1075
- result = tag({
1076
- ...props,
1077
- children
1078
- });
1079
- } catch (err) {
1080
- if (err && typeof err.then === "function") {
1081
- threwThenable = err;
1082
- } else {
1083
- popComponentScope();
1084
- throw err;
1085
- }
1086
- }
1087
- const parentAppendResolved = (resolved) => {
1088
- const parent2 = start.parentNode;
1089
- if (!parent2) return;
1090
- let nodeOrValue = resolved;
1091
- if (typeof resolved === "function" && !isComponentThunk(resolved)) {
1092
- nodeOrValue = runInScope(
1093
- scope,
1094
- () => resolved({
1095
- ...props,
1096
- children
1097
- })
1098
- );
1099
- }
1100
- appendContent(parent2, end, nodeOrValue);
1101
- };
1102
- if (result && typeof result.then === "function") {
1103
- result.then(
1104
- (r) => parentAppendResolved(r),
1105
- () => {
1106
- }
1107
- );
1108
- popComponentScope();
1109
- return frag;
1110
- }
1111
- if (threwThenable) {
1112
- threwThenable.then(
1113
- (r) => parentAppendResolved(r),
1114
- () => {
1115
- }
1116
- );
1117
- popComponentScope();
1118
- return frag;
1119
- }
1120
- const parent = frag;
1121
- appendContent(parent, end, result);
1122
- popComponentScope();
1123
- return frag;
1124
- };
1125
- })();
1126
- thunk.__isComponent = true;
1127
- return thunk;
1128
- }
1129
- var __collectingDeps = false;
1130
- function createReactiveSection2(parent, valueOrFunction) {
1131
- const start = document.createComment("r-s");
1132
- const end = document.createComment("r-e");
1133
- parent.appendChild(start);
1134
- parent.appendChild(end);
1135
- const regionScope = pushComponentScope();
1136
- markComponentBoundary(start, end, regionScope);
1137
- const update = () => {
1138
- const p = start.parentNode;
1139
- if (!p) return;
1140
- if (typeof valueOrFunction === "function") {
1141
- try {
1142
- __collectingDeps = true;
1143
- valueOrFunction();
1144
- } catch (err) {
1145
- if (!err || typeof err.then !== "function") ;
1146
- } finally {
1147
- __collectingDeps = false;
1148
- }
1149
- }
1150
- const next = untrack(() => {
1151
- let v = typeof valueOrFunction === "function" ? valueOrFunction() : valueOrFunction;
1152
- try {
1153
- if (typeof v === "function") v = v();
1154
- } catch {
1155
- }
1156
- return v;
1157
- });
1158
- disposeBetween(start, end);
1159
- untrack(() => appendContent(p, end, next));
1160
- };
1161
- update();
1162
- useEffect(update);
1163
- popComponentScope();
1164
- }
1165
- function applyProp(el, rawName, value, isSvg) {
1166
- if (rawName === "ref") return;
1167
- if (rawName.startsWith("on")) return;
1168
- const name = rawName === "className" ? "class" : rawName === "htmlFor" ? "for" : rawName;
1169
- if (typeof value === "function" && !value.__isStore) {
1170
- useEffect(() => {
1171
- setProp(el, name, value(), isSvg);
1172
- });
1173
- } else if (typeof value === "function" && value.__isStore) {
1174
- useEffect(() => {
1175
- setProp(el, name, value(), isSvg);
1176
- });
1177
- } else {
1178
- setProp(el, name, value, isSvg);
1179
- }
1180
- }
1181
- function setProp(el, name, value, isSvg) {
1182
- if (name === "dangerouslySetInnerHTML") {
1183
- const html = value && typeof value === "object" && value !== null ? String(value.__html ?? "") : "";
1184
- el.innerHTML = html;
1185
- return;
1186
- }
1187
- if (name === "class") {
1188
- if (value == null || value === false) {
1189
- if (isSvg) el.removeAttribute("class");
1190
- else el.className = "";
1191
- } else {
1192
- const next = Array.isArray(value) || value instanceof Set ? Array.from(value).join(" ") : String(value);
1193
- if (isSvg) el.setAttribute("class", next);
1194
- else el.className = next;
1195
- }
1196
- return;
1197
- }
1198
- if (name === "style") {
1199
- const style = el.style;
1200
- if (value == null || value === false) {
1201
- el.removeAttribute("style");
1202
- return;
1203
- }
1204
- if (typeof value === "string") {
1205
- style.cssText = value;
1206
- return;
1207
- }
1208
- if (typeof value === "object") {
1209
- for (const [k, v] of Object.entries(value)) {
1210
- style[k] = String(v);
1211
- }
1212
- return;
1213
- }
1214
- el.setAttribute("style", String(value));
1215
- return;
1216
- }
1217
- if (name === "value" && "value" in el) {
1218
- if (el.value !== (value ?? "")) {
1219
- el.value = String(value ?? "");
1220
- }
1221
- return;
1222
- }
1223
- if (name === "checked" && "checked" in el) {
1224
- el.checked = !!value;
1225
- return;
1226
- }
1227
- if (name === "selected" && "selected" in el) {
1228
- el.selected = !!value;
1229
- return;
1230
- }
1231
- if (name === "muted" && "muted" in el) {
1232
- el.muted = !!value;
1233
- return;
1234
- }
1235
- if (BOOLEAN_ATTRS.has(name)) {
1236
- if (value) {
1237
- el.setAttribute(name, "");
1238
- } else {
1239
- el.removeAttribute(name);
1240
- }
1241
- return;
1242
- }
1243
- if (name.startsWith("data-") || name.startsWith("aria-")) {
1244
- if (value == null || value === false) el.removeAttribute(name);
1245
- else el.setAttribute(name, String(value));
1246
- return;
1247
- }
1248
- if (name.startsWith("xlink:")) {
1249
- const local = name.slice(6);
1250
- if (value == null || value === false)
1251
- el.removeAttributeNS(XLINK_NS, local);
1252
- else el.setAttributeNS(XLINK_NS, name, String(value));
1253
- return;
1254
- }
1255
- if (value == null || value === false) {
1256
- el.removeAttribute(name);
1257
- } else {
1258
- el.setAttribute(name, String(value));
1259
- }
1260
- }
1261
- function createDomElement(tag) {
1262
- let t = tag;
1263
- let forceSvg = false;
1264
- if (t.startsWith("svg:")) {
1265
- forceSvg = true;
1266
- t = t.slice(4);
1267
- }
1268
- const isSvgTag = t === "svg" || SVG_ONLY_TAGS.has(t);
1269
- if (forceSvg || isSvgTag) {
1270
- return document.createElementNS(SVG_NS, t);
1271
- }
1272
- return document.createElement(t);
1273
- }
1274
- var __eventMap = /* @__PURE__ */ new WeakMap();
1275
- function getEventMap(el) {
1276
- let m = __eventMap.get(el);
1277
- if (!m) {
1278
- m = /* @__PURE__ */ new Map();
1279
- __eventMap.set(el, m);
1280
- }
1281
- return m;
1282
- }
1283
- function bindEvent(el, rawName, value) {
1284
- const eventName = rawName.toLowerCase().slice(2);
1285
- const map = getEventMap(el);
1286
- let binding = map.get(eventName);
1287
- if (!binding) {
1288
- const state = {
1289
- listener: (e) => {
1290
- if (state.handler) {
1291
- try {
1292
- state.handler(e);
1293
- } catch {
1294
- }
1295
- }
1296
- },
1297
- handler: null
1298
- };
1299
- el.addEventListener(eventName, state.listener);
1300
- map.set(eventName, state);
1301
- binding = state;
1302
- onCleanup(() => {
1303
- try {
1304
- el.removeEventListener(eventName, state.listener);
1305
- } catch {
1306
- }
1307
- map.delete(eventName);
1308
- });
1309
- }
1310
- if (typeof value === "function" && value.__isStore) {
1311
- useEffect(() => {
1312
- const next = value();
1313
- const rec = map.get(eventName);
1314
- rec.handler = typeof next === "function" ? next : null;
1315
- });
1316
- } else {
1317
- binding.handler = typeof value === "function" ? value : null;
1318
- }
1319
- }
1320
- var jsx = (tag, props = {}) => {
1321
- const { children, ...otherProps } = props || {};
1322
- if (tag === Match) {
1323
- return {
1324
- __isMatch: true,
1325
- type: Match,
1326
- props: { ...otherProps, children }
1327
- };
1328
- }
1329
- if (typeof tag === "function") {
1330
- if (__collectingDeps) {
1331
- const noop = (() => document.createComment("collect"));
1332
- noop.__isComponent = true;
1333
- return noop;
1334
- }
1335
- return createComponentThunk(
1336
- tag,
1337
- otherProps,
1338
- children
1339
- );
1340
- }
1341
- if (typeof tag !== "string") {
1342
- throw ERRORS.JSX_INVALID_TAG(tag);
1343
- }
1344
- const element = createDomElement(tag);
1345
- const isSvg = element.namespaceURI === SVG_NS;
1346
- Object.entries(otherProps).forEach(
1347
- ([rawName, rawValue]) => {
1348
- if (rawName === "ref") {
1349
- if (typeof rawValue === "function") {
1350
- try {
1351
- rawValue(element);
1352
- } catch {
1353
- }
1354
- } else if (rawValue && typeof rawValue === "object" && "current" in rawValue) {
1355
- try {
1356
- rawValue.current = element;
1357
- } catch {
1358
- }
1359
- }
1360
- return;
1361
- }
1362
- if (rawName.startsWith("on")) {
1363
- bindEvent(element, rawName, rawValue);
1364
- return;
1365
- }
1366
- applyProp(element, rawName, rawValue, isSvg);
1367
- }
1368
- );
1369
- if ("dangerouslySetInnerHTML" in otherProps && children !== void 0) {
1370
- warn(
1371
- false,
1372
- "Both children and dangerouslySetInnerHTML were provided. dangerouslySetInnerHTML will be used and children are ignored."
1373
- );
1374
- return element;
1375
- }
1376
- if (children !== void 0) {
1377
- if (typeof children === "function") {
1378
- createReactiveSection2(element, children);
1379
- } else if (Array.isArray(children)) {
1380
- children.forEach((c) => {
1381
- if (typeof c === "function") {
1382
- if (isComponentThunk(c)) {
1383
- try {
1384
- const node = c();
1385
- element.appendChild(node);
1386
- } catch {
1387
- }
1388
- } else {
1389
- createReactiveSection2(element, c);
1390
- }
1391
- } else if (c?.nodeType) {
1392
- element.appendChild(c);
1393
- } else if (c != null) {
1394
- element.appendChild(document.createTextNode(String(c)));
1395
- }
1396
- });
1397
- } else if (typeof children === "object" && children !== null && "nodeType" in children) {
1398
- element.appendChild(children);
1399
- } else if (children != null) {
1400
- element.appendChild(document.createTextNode(String(children)));
1401
- }
1402
- }
1403
- return element;
1404
- };
1405
- var jsxs = jsx;
1406
- var jsxDEV = jsx;
1407
-
1408
- // src/runtime/lazy.ts
1409
- function initInsertedTree(node) {
1410
- if (!node) return;
1411
- if (node.nodeType === Node.ELEMENT_NODE) {
1412
- node?.__shadow_init?.();
1413
- }
1414
- if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
1415
- let c = node.firstChild;
1416
- while (c) {
1417
- initInsertedTree(c);
1418
- c = c.nextSibling;
1419
- }
1420
- }
1421
- }
1422
- var componentCache = /* @__PURE__ */ new WeakMap();
1423
- var promiseCache = /* @__PURE__ */ new WeakMap();
1424
- function lazy(importFn, options = {}) {
1425
- const { retries = 3, retryDelay = 1e3 } = options;
1426
- const load = async (attemptsLeft) => {
1427
- try {
1428
- const module = await importFn();
1429
- let Component;
1430
- if (module && typeof module === "object" && module !== null && "default" in module && module.default !== void 0) {
1431
- Component = module.default;
1432
- } else if (module && typeof module === "function") {
1433
- Component = module;
1434
- } else {
1435
- throw ERRORS.LAZY_INVALID_EXPORT();
1436
- }
1437
- componentCache.set(importFn, Component);
1438
- } catch (err) {
1439
- if (attemptsLeft > 0) {
1440
- await new Promise((r) => setTimeout(r, retryDelay));
1441
- return load(attemptsLeft - 1);
1442
- }
1443
- throw ERRORS.LAZY_FAILED_AFTER_ATTEMPTS(retries, err);
1444
- }
1445
- };
1446
- return function LazyWrapper(props) {
1447
- if (componentCache.has(importFn)) {
1448
- const C = componentCache.get(importFn);
1449
- return typeof C === "function" ? jsx(C, props ?? {}) : C;
1450
- }
1451
- const frag = document.createDocumentFragment();
1452
- const start = document.createComment("lazy-s");
1453
- const end = document.createComment("lazy-e");
1454
- frag.appendChild(start);
1455
- frag.appendChild(end);
1456
- let p = promiseCache.get(importFn);
1457
- if (!p) {
1458
- p = load(retries);
1459
- promiseCache.set(importFn, p);
1460
- }
1461
- const meta = {
1462
- pending: true,
1463
- promise: p,
1464
- onResolve: /* @__PURE__ */ new Set()
1465
- };
1466
- frag.__shadow_lazy = meta;
1467
- p.then(
1468
- () => {
1469
- meta.pending = false;
1470
- const C = componentCache.get(importFn);
1471
- const parent = start.parentNode;
1472
- if (!parent) {
1473
- meta.onResolve.forEach((fn) => {
1474
- try {
1475
- fn();
1476
- } catch {
1477
- }
1478
- });
1479
- return;
1480
- }
1481
- disposeBetween(start, end);
1482
- let node = typeof C === "function" ? jsx(C, props ?? {}) : C;
1483
- if (typeof node === "function" && node.__isComponent) {
1484
- try {
1485
- node = node();
1486
- } catch {
1487
- }
1488
- }
1489
- untrack(() => {
1490
- if (node && typeof node === "object" && "nodeType" in node) {
1491
- parent.insertBefore(node, end);
1492
- initInsertedTree(node);
1493
- } else if (node !== null && node !== void 0) {
1494
- parent.insertBefore(document.createTextNode(String(node)), end);
1495
- }
1496
- });
1497
- meta.onResolve.forEach((fn) => {
1498
- try {
1499
- fn();
1500
- } catch {
1501
- }
1502
- });
1503
- meta.onResolve.clear();
1504
- },
1505
- () => {
1506
- }
1507
- );
1508
- return frag;
1509
- };
1510
- }
1511
-
1512
- // src/runtime/Portal.ts
1513
- function createReactiveSectionBetweenAnchors(anchorEnd, valueOrFunction) {
1514
- const anchorParent = anchorEnd.parentNode;
1515
- if (!anchorParent) return;
1516
- const startComment = document.createComment("p-r-s");
1517
- const endComment = document.createComment("p-r-e");
1518
- anchorParent.insertBefore(startComment, anchorEnd);
1519
- anchorParent.insertBefore(endComment, anchorEnd);
1520
- const insertBeforeEnd = (end, content) => {
1521
- const parentNode = startComment.parentNode;
1522
- if (!parentNode) return;
1523
- const insert = (v) => {
1524
- if (v === null || v === void 0 || typeof v === "boolean") return;
1525
- if (typeof v === "string" || typeof v === "number") {
1526
- parentNode.insertBefore(document.createTextNode(String(v)), end);
1527
- return;
1528
- }
1529
- if (Array.isArray(v)) {
1530
- v.forEach((x) => insert(x));
1531
- return;
1532
- }
1533
- if (typeof v === "object" && v !== null && "nodeType" in v) {
1534
- parentNode.insertBefore(v, end);
1535
- return;
1536
- }
1537
- parentNode.insertBefore(document.createTextNode(String(v)), end);
1538
- };
1539
- insert(content);
1540
- };
1541
- const update = () => {
1542
- const parentNode = startComment.parentNode;
1543
- if (!parentNode) return;
1544
- const newContent = untrack(
1545
- () => typeof valueOrFunction === "function" ? valueOrFunction() : valueOrFunction
1546
- );
1547
- disposeBetween(startComment, endComment);
1548
- untrack(() => insertBeforeEnd(endComment, newContent));
1549
- };
1550
- update();
1551
- useEffect(update);
1552
- }
1553
- function Portal(props) {
1554
- const { mount, children, ref } = props || {};
1555
- if (!mount) {
1556
- throw ERRORS.PORTAL_MOUNT_REQUIRED();
1557
- }
1558
- if (ref) {
1559
- if (typeof ref === "function") {
1560
- try {
1561
- ref(mount);
1562
- } catch {
1563
- }
1564
- } else if (ref && typeof ref === "object" && "current" in ref) {
1565
- try {
1566
- ref.current = mount;
1567
- } catch {
1568
- }
1569
- }
1570
- }
1571
- const startAnchor = document.createComment("p-s");
1572
- const endAnchor = document.createComment("p-e");
1573
- mount.appendChild(startAnchor);
1574
- mount.appendChild(endAnchor);
1575
- if (children !== void 0) {
1576
- createReactiveSectionBetweenAnchors(endAnchor, children);
1577
- }
1578
- onCleanup(() => {
1579
- const parent = startAnchor.parentNode;
1580
- if (!parent) return;
1581
- disposeBetween(startAnchor, endAnchor);
1582
- parent.removeChild(startAnchor);
1583
- parent.removeChild(endAnchor);
1584
- });
1585
- return document.createDocumentFragment();
1586
- }
1587
-
1588
- // src/runtime/Suspense.ts
1589
- function isThenable(value) {
1590
- return value !== null && typeof value === "object" && "then" in value && typeof value.then === "function";
1591
- }
1592
- function toNode(value) {
1593
- if (value === null || value === void 0) return null;
1594
- if (isComponentThunk(value)) {
1595
- try {
1596
- return value();
1597
- } catch {
1598
- return document.createComment("error");
1599
- }
1600
- }
1601
- if (typeof value === "object" && value !== null && "nodeType" in value)
1602
- return value;
1603
- if (Array.isArray(value)) {
1604
- const df = document.createDocumentFragment();
1605
- value.forEach((v) => {
1606
- const n = toNode(v);
1607
- if (n) df.appendChild(n);
1608
- });
1609
- return df;
1610
- }
1611
- if (typeof value === "function") {
1612
- try {
1613
- return toNode(value());
1614
- } catch {
1615
- return document.createComment("error");
1616
- }
1617
- }
1618
- if (typeof value === "string" || typeof value === "number") {
1619
- return document.createTextNode(String(value));
1620
- }
1621
- return document.createTextNode(String(value));
1622
- }
1623
- function isSuspenseFragmentNode(node) {
1624
- if (!node || typeof node !== "object" || !node.nodeType || node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE)
1625
- return false;
1626
- const df = node;
1627
- for (let i = 0; i < df.childNodes.length; i++) {
1628
- const n = df.childNodes[i];
1629
- if (n.nodeType === Node.COMMENT_NODE && n.textContent === "suspense-s") {
1630
- return true;
1631
- }
1632
- }
1633
- return false;
1634
- }
1635
- function getLazyMeta(node) {
1636
- if (node && typeof node === "object" && node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && node.__shadow_lazy && typeof node.__shadow_lazy === "object") {
1637
- return node.__shadow_lazy;
1638
- }
1639
- return null;
1640
- }
1641
- function Suspense(props) {
1642
- const { fallback, children } = props || {};
1643
- const fragment = document.createDocumentFragment();
1644
- const startComment = document.createComment("suspense-s");
1645
- const endComment = document.createComment("suspense-e");
1646
- fragment.appendChild(startComment);
1647
- fragment.appendChild(endComment);
1648
- const childrenArray = () => children === void 0 ? [] : Array.isArray(children) ? children : [children];
1649
- const clearBetween = () => {
1650
- disposeBetween(startComment, endComment);
1651
- };
1652
- let slots = [];
1653
- let anchors = null;
1654
- let fallbackVisible = false;
1655
- let stageOneCompleted = false;
1656
- const showFallback = () => {
1657
- const parent = startComment.parentNode;
1658
- if (!parent) return;
1659
- clearBetween();
1660
- if (fallback !== void 0) {
1661
- const node = toNode(
1662
- typeof fallback === "function" ? fallback() : fallback
1663
- );
1664
- if (node) parent.insertBefore(node, endComment);
1665
- }
1666
- fallbackVisible = true;
1667
- };
1668
- const ensureAnchors = () => {
1669
- if (anchors) return;
1670
- const parent = startComment.parentNode;
1671
- if (!parent) return;
1672
- const arr = childrenArray();
1673
- anchors = arr.map((_, i) => ({
1674
- start: document.createComment(`suspense-slot-s:${i}`),
1675
- end: document.createComment(`suspense-slot-e:${i}`)
1676
- }));
1677
- anchors.forEach((a) => {
1678
- parent.insertBefore(a.start, endComment);
1679
- parent.insertBefore(a.end, endComment);
1680
- });
1681
- };
1682
- const setSlotContent = (index, node) => {
1683
- if (!anchors) return;
1684
- const parent = startComment.parentNode;
1685
- if (!parent) return;
1686
- const a = anchors[index];
1687
- if (!a) return;
1688
- disposeBetween(a.start, a.end);
1689
- if (node) parent.insertBefore(node, a.end);
1690
- };
1691
- const maybeReveal = () => {
1692
- if (stageOneCompleted) return;
1693
- for (let i = 0; i < slots.length; i++) {
1694
- if (!slots[i].isNested && !slots[i].resolved) return;
1695
- }
1696
- stageOneCompleted = true;
1697
- const parent = startComment.parentNode;
1698
- if (!parent) return;
1699
- if (fallbackVisible) {
1700
- clearBetween();
1701
- fallbackVisible = false;
1702
- }
1703
- ensureAnchors();
1704
- for (let i = 0; i < slots.length; i++) {
1705
- if (!slots[i].isNested) {
1706
- setSlotContent(i, slots[i].node);
1707
- }
1708
- }
1709
- for (let i = 0; i < slots.length; i++) {
1710
- if (slots[i].isNested) {
1711
- setSlotContent(i, slots[i].node);
1712
- }
1713
- }
1714
- };
1715
- const inspectChild = (index, value) => {
1716
- const finish = (resolvedValue) => {
1717
- const node = toNode(resolvedValue);
1718
- slots[index].resolved = true;
1719
- slots[index].node = node;
1720
- maybeReveal();
1721
- };
1722
- if (isThenable(value)) {
1723
- slots[index].promise = value;
1724
- value.then(
1725
- (v) => finish(v),
1726
- () => finish(null)
1727
- // treat rejection as resolved-null to avoid deadlock
1728
- );
1729
- return;
1730
- }
1731
- const meta = getLazyMeta(value);
1732
- if (meta && meta.pending) {
1733
- slots[index].promise = meta.promise;
1734
- const onRes = () => finish(value);
1735
- meta.onResolve.add(onRes);
1736
- meta.promise.finally(() => {
1737
- meta.onResolve.delete(onRes);
1738
- });
1739
- return;
1740
- }
1741
- finish(value);
1742
- };
1743
- const process2 = () => {
1744
- const arr = childrenArray();
1745
- slots = arr.map((child) => {
1746
- let value = child;
1747
- let isNested = false;
1748
- if (typeof child === "function") {
1749
- try {
1750
- value = child();
1751
- } catch (err) {
1752
- if (isThenable(err)) value = err;
1753
- else throw err;
1754
- }
1755
- }
1756
- if (typeof value === "object" && value !== null && "nodeType" in value && isSuspenseFragmentNode(value)) {
1757
- isNested = true;
1758
- }
1759
- return {
1760
- isNested,
1761
- resolved: isNested ? true : false,
1762
- node: isNested ? value : null,
1763
- promise: null,
1764
- reactive: typeof child === "function" ? child : null
1765
- };
1766
- });
1767
- let hasPending = false;
1768
- arr.forEach((child, index) => {
1769
- let value = child;
1770
- if (typeof child === "function") {
1771
- try {
1772
- value = child();
1773
- } catch (err) {
1774
- if (isThenable(err)) value = err;
1775
- else throw err;
1776
- }
1777
- }
1778
- const meta = getLazyMeta(value);
1779
- if (!slots[index].isNested && isThenable(value) || !slots[index].isNested && meta && meta.pending) {
1780
- hasPending = true;
1781
- }
1782
- });
1783
- if (hasPending) {
1784
- showFallback();
1785
- }
1786
- arr.forEach((child, index) => {
1787
- if (slots[index].isNested) return;
1788
- let value = child;
1789
- if (typeof child === "function") {
1790
- try {
1791
- value = child();
1792
- } catch (err) {
1793
- if (isThenable(err)) value = err;
1794
- else throw err;
1795
- }
1796
- }
1797
- inspectChild(index, value);
1798
- });
1799
- maybeReveal();
1800
- slots.forEach((slot, index) => {
1801
- if (!slot.reactive) return;
1802
- useEffect(() => {
1803
- let v;
1804
- try {
1805
- v = slot.reactive();
1806
- } catch (err) {
1807
- if (isThenable(err)) {
1808
- err.then(() => {
1809
- try {
1810
- const next = slot.reactive();
1811
- if (isThenable(next)) {
1812
- next.then(
1813
- (r) => setSlotContent(
1814
- index,
1815
- untrack(() => toNode(r))
1816
- )
1817
- );
1818
- } else {
1819
- setSlotContent(
1820
- index,
1821
- untrack(() => toNode(next))
1822
- );
1823
- }
1824
- } catch {
1825
- }
1826
- });
1827
- return;
1828
- } else {
1829
- throw err;
1830
- }
1831
- }
1832
- if (isThenable(v)) {
1833
- v.then(
1834
- (r) => setSlotContent(
1835
- index,
1836
- untrack(() => toNode(r))
1837
- )
1838
- );
1839
- } else {
1840
- setSlotContent(
1841
- index,
1842
- untrack(() => toNode(v))
1843
- );
1844
- }
1845
- });
1846
- });
1847
- };
1848
- const checkConnected = () => {
1849
- if (startComment.isConnected) process2();
1850
- else setTimeout(checkConnected, 0);
1851
- };
1852
- checkConnected();
1853
- if (typeof children === "function") {
1854
- useEffect(() => {
1855
- if (startComment.isConnected) {
1856
- anchors = null;
1857
- fallbackVisible = false;
1858
- stageOneCompleted = false;
1859
- slots = [];
1860
- clearBetween();
1861
- process2();
1862
- }
1863
- });
1864
- }
1865
- return fragment;
1866
- }
1867
-
1868
- // src/runtime/ErrorBoundary.ts
1869
- function ErrorBoundary(props) {
1870
- const { fallback, children, onError } = props || {};
1871
- const fragment = document.createDocumentFragment();
1872
- const startComment = document.createComment("error-boundary-s");
1873
- const endComment = document.createComment("error-boundary-e");
1874
- fragment.appendChild(startComment);
1875
- fragment.appendChild(endComment);
1876
- let hasError = false;
1877
- let storedError = null;
1878
- const insertNode = (node) => {
1879
- const parent = startComment.parentNode;
1880
- if (!parent) return;
1881
- const insert = (v) => {
1882
- if (v === null || v === void 0 || typeof v === "boolean") return;
1883
- if (Array.isArray(v)) {
1884
- v.forEach((x) => insert(x));
1885
- return;
1886
- }
1887
- if (typeof v === "function") {
1888
- try {
1889
- if (isComponentThunk(v)) {
1890
- parent.insertBefore(v(), endComment);
1891
- } else {
1892
- insert(v());
1893
- }
1894
- } catch {
1895
- }
1896
- return;
1897
- }
1898
- if (typeof v === "string" || typeof v === "number") {
1899
- parent.insertBefore(document.createTextNode(String(v)), endComment);
1900
- return;
1901
- }
1902
- if (v && typeof v === "object" && "nodeType" in v) {
1903
- parent.insertBefore(v, endComment);
1904
- return;
1905
- }
1906
- parent.insertBefore(document.createTextNode(String(v)), endComment);
1907
- };
1908
- untrack(() => insert(node));
1909
- };
1910
- const render2 = () => {
1911
- disposeBetween(startComment, endComment);
1912
- if (hasError) {
1913
- const node = typeof fallback === "function" ? fallback(storedError) : fallback;
1914
- insertNode(node);
1915
- return;
1916
- }
1917
- try {
1918
- const content = typeof children === "function" ? children() : children;
1919
- insertNode(content);
1920
- } catch (error) {
1921
- hasError = true;
1922
- storedError = error;
1923
- try {
1924
- onError?.(error);
1925
- } catch {
1926
- }
1927
- const node = typeof fallback === "function" ? fallback(error) : fallback;
1928
- disposeBetween(startComment, endComment);
1929
- insertNode(node);
1930
- }
1931
- };
1932
- render2();
1933
- if (typeof children === "function") {
1934
- useEffect(() => {
1935
- if (!hasError) render2();
1936
- });
1937
- }
1938
- return fragment;
1939
- }
1940
-
1941
- // src/runtime/render.ts
1942
- function render(component, container) {
1943
- if (!container) {
1944
- throw ERRORS.RENDER_CONTAINER_REQUIRED();
1945
- }
1946
- disposeAllChildren(container);
1947
- container.innerHTML = "";
1948
- let element;
1949
- if (typeof component === "function") {
1950
- element = jsx(component, {});
1951
- if (typeof element === "function" && element.__isComponent) {
1952
- element = element();
1953
- }
1954
- } else if (typeof component === "object" && component !== null && "nodeType" in component) {
1955
- element = component;
1956
- } else {
1957
- throw ERRORS.RENDER_INVALID_COMPONENT();
1958
- }
1959
- if (typeof element === "object" && element !== null && "nodeType" in element) {
1960
- container.appendChild(element);
1961
- } else {
1962
- throw ERRORS.RENDER_INVALID_RETURN();
1963
- }
1964
- return element;
1965
- }
1966
-
1967
- // src/runtime/createElement.ts
1968
- function createElement(tag, props, ...children) {
1969
- const finalProps = { ...props || {} };
1970
- if (children.length > 0) {
1971
- finalProps.children = children.length === 1 ? children[0] : children;
1972
- }
1973
- return jsx(tag, finalProps);
1974
- }
1975
-
1976
- exports.ErrorBoundary = ErrorBoundary;
1977
- exports.For = For;
1978
- exports.Fragment = Fragment;
1979
- exports.Match = Match;
1980
- exports.Portal = Portal;
1981
- exports.Show = Show;
1982
- exports.Suspense = Suspense;
1983
- exports.Switch = Switch;
1984
- exports.Title = Title;
1985
- exports.createElement = createElement;
1986
- exports.jsx = jsx;
1987
- exports.jsxDEV = jsxDEV;
1988
- exports.jsxs = jsxs;
1989
- exports.lazy = lazy;
1990
- exports.onCleanup = onCleanup;
1991
- exports.onMount = onMount;
1992
- exports.render = render;
1993
- exports.useData = useData;
1994
- exports.useEffect = useEffect;
1995
- exports.useId = useId;
1996
- exports.useMemo = useMemo;
1997
- exports.useOptimistic = useOptimistic;
1998
- exports.useStore = useStore;
1999
- //# sourceMappingURL=index.cjs.map
2000
- //# sourceMappingURL=index.cjs.map