@shadow-js/web 0.0.0-stage → 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 (611) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +21 -0
  3. package/README.md +190 -2
  4. package/dist/dev/attributes.d.ts +90 -0
  5. package/dist/dev/attributes.js +196 -0
  6. package/dist/dev/attributes.js.map +1 -0
  7. package/dist/dev/autofocus.d.ts +32 -0
  8. package/dist/dev/autofocus.js +45 -0
  9. package/dist/dev/autofocus.js.map +1 -0
  10. package/dist/dev/class-style.d.ts +89 -0
  11. package/dist/dev/class-style.js +197 -0
  12. package/dist/dev/class-style.js.map +1 -0
  13. package/dist/dev/component.d.ts +23 -0
  14. package/dist/dev/component.js +42 -0
  15. package/dist/dev/component.js.map +1 -0
  16. package/dist/dev/control-flow/activity.d.ts +58 -0
  17. package/dist/dev/control-flow/activity.js +136 -0
  18. package/dist/dev/control-flow/activity.js.map +1 -0
  19. package/dist/dev/control-flow/branch.js +104 -0
  20. package/dist/dev/control-flow/branch.js.map +1 -0
  21. package/dist/dev/control-flow/client-only.d.ts +48 -0
  22. package/dist/dev/control-flow/client-only.js +50 -0
  23. package/dist/dev/control-flow/client-only.js.map +1 -0
  24. package/dist/dev/control-flow/dynamic.d.ts +82 -0
  25. package/dist/dev/control-flow/dynamic.js +134 -0
  26. package/dist/dev/control-flow/dynamic.js.map +1 -0
  27. package/dist/dev/control-flow/error-boundary.d.ts +72 -0
  28. package/dist/dev/control-flow/error-boundary.js +115 -0
  29. package/dist/dev/control-flow/error-boundary.js.map +1 -0
  30. package/dist/dev/control-flow/for.d.ts +80 -0
  31. package/dist/dev/control-flow/for.js +23 -0
  32. package/dist/dev/control-flow/for.js.map +1 -0
  33. package/dist/dev/control-flow/fragment.d.ts +38 -0
  34. package/dist/dev/control-flow/fragment.js +31 -0
  35. package/dist/dev/control-flow/fragment.js.map +1 -0
  36. package/dist/dev/control-flow/hot-link.js +64 -0
  37. package/dist/dev/control-flow/hot-link.js.map +1 -0
  38. package/dist/dev/control-flow/index-list.d.ts +48 -0
  39. package/dist/dev/control-flow/index-list.js +31 -0
  40. package/dist/dev/control-flow/index-list.js.map +1 -0
  41. package/dist/dev/control-flow/index.d.ts +15 -0
  42. package/dist/dev/control-flow/lazy.d.ts +58 -0
  43. package/dist/dev/control-flow/lazy.js +64 -0
  44. package/dist/dev/control-flow/lazy.js.map +1 -0
  45. package/dist/dev/control-flow/no-hydration.d.ts +39 -0
  46. package/dist/dev/control-flow/no-hydration.js +58 -0
  47. package/dist/dev/control-flow/no-hydration.js.map +1 -0
  48. package/dist/dev/control-flow/portal.d.ts +69 -0
  49. package/dist/dev/control-flow/portal.js +134 -0
  50. package/dist/dev/control-flow/portal.js.map +1 -0
  51. package/dist/dev/control-flow/root-errors.d.ts +25 -0
  52. package/dist/dev/control-flow/root-errors.js +33 -0
  53. package/dist/dev/control-flow/root-errors.js.map +1 -0
  54. package/dist/dev/control-flow/show.d.ts +101 -0
  55. package/dist/dev/control-flow/show.js +18 -0
  56. package/dist/dev/control-flow/show.js.map +1 -0
  57. package/dist/dev/control-flow/suspense-list.d.ts +65 -0
  58. package/dist/dev/control-flow/suspense-list.js +105 -0
  59. package/dist/dev/control-flow/suspense-list.js.map +1 -0
  60. package/dist/dev/control-flow/suspense.d.ts +53 -0
  61. package/dist/dev/control-flow/suspense.js +102 -0
  62. package/dist/dev/control-flow/suspense.js.map +1 -0
  63. package/dist/dev/control-flow/switch.d.ts +85 -0
  64. package/dist/dev/control-flow/switch.js +90 -0
  65. package/dist/dev/control-flow/switch.js.map +1 -0
  66. package/dist/dev/derived.d.ts +52 -0
  67. package/dist/dev/derived.js +34 -0
  68. package/dist/dev/derived.js.map +1 -0
  69. package/dist/dev/element.d.ts +40 -0
  70. package/dist/dev/element.js +105 -0
  71. package/dist/dev/element.js.map +1 -0
  72. package/dist/dev/events.d.ts +87 -0
  73. package/dist/dev/events.js +265 -0
  74. package/dist/dev/events.js.map +1 -0
  75. package/dist/dev/extend.d.ts +12 -0
  76. package/dist/dev/extend.js +12 -0
  77. package/dist/dev/head/components.d.ts +137 -0
  78. package/dist/dev/head/components.js +170 -0
  79. package/dist/dev/head/components.js.map +1 -0
  80. package/dist/dev/head/registry.js +68 -0
  81. package/dist/dev/head/registry.js.map +1 -0
  82. package/dist/dev/head/server-head.d.ts +54 -0
  83. package/dist/dev/head/server-head.js +76 -0
  84. package/dist/dev/head/server-head.js.map +1 -0
  85. package/dist/dev/head/sink.js +96 -0
  86. package/dist/dev/head/sink.js.map +1 -0
  87. package/dist/dev/head/use-head.d.ts +35 -0
  88. package/dist/dev/head/use-head.js +84 -0
  89. package/dist/dev/head/use-head.js.map +1 -0
  90. package/dist/dev/head/validate.d.ts +85 -0
  91. package/dist/dev/head/validate.js +268 -0
  92. package/dist/dev/head/validate.js.map +1 -0
  93. package/dist/dev/hmr.d.ts +82 -0
  94. package/dist/dev/hmr.js +124 -0
  95. package/dist/dev/hmr.js.map +1 -0
  96. package/dist/dev/hydration.d.ts +61 -0
  97. package/dist/dev/hydration.js +120 -0
  98. package/dist/dev/hydration.js.map +1 -0
  99. package/dist/dev/index.d.ts +45 -0
  100. package/dist/dev/index.js +34 -0
  101. package/dist/dev/insert.d.ts +97 -0
  102. package/dist/dev/insert.js +357 -0
  103. package/dist/dev/insert.js.map +1 -0
  104. package/dist/dev/internal/claim.d.ts +106 -0
  105. package/dist/dev/internal/claim.js +357 -0
  106. package/dist/dev/internal/claim.js.map +1 -0
  107. package/dist/dev/internal/css-units.js +26 -0
  108. package/dist/dev/internal/css-units.js.map +1 -0
  109. package/dist/dev/internal/diagnostics.d.ts +30 -0
  110. package/dist/dev/internal/diagnostics.js +38 -0
  111. package/dist/dev/internal/diagnostics.js.map +1 -0
  112. package/dist/dev/internal/early-events.js +76 -0
  113. package/dist/dev/internal/early-events.js.map +1 -0
  114. package/dist/dev/internal/hydration-hooks.d.ts +43 -0
  115. package/dist/dev/internal/hydration-hooks.js +27 -0
  116. package/dist/dev/internal/hydration-hooks.js.map +1 -0
  117. package/dist/dev/internal/hydration-scope.d.ts +131 -0
  118. package/dist/dev/internal/hydration-scope.js +156 -0
  119. package/dist/dev/internal/hydration-scope.js.map +1 -0
  120. package/dist/dev/internal/names.d.ts +33 -0
  121. package/dist/dev/internal/names.js +35 -0
  122. package/dist/dev/internal/names.js.map +1 -0
  123. package/dist/dev/internal/portal-context.d.ts +39 -0
  124. package/dist/dev/internal/portal-context.js +28 -0
  125. package/dist/dev/internal/portal-context.js.map +1 -0
  126. package/dist/dev/internal/react-names.js +116 -0
  127. package/dist/dev/internal/react-names.js.map +1 -0
  128. package/dist/dev/internal/reconcile.d.ts +40 -0
  129. package/dist/dev/internal/reconcile.js +122 -0
  130. package/dist/dev/internal/reconcile.js.map +1 -0
  131. package/dist/dev/internal/stream-context.d.ts +47 -0
  132. package/dist/dev/internal/stream-context.js +23 -0
  133. package/dist/dev/internal/stream-context.js.map +1 -0
  134. package/dist/dev/jsx/aria.d.ts +72 -0
  135. package/dist/dev/jsx/component.d.ts +89 -0
  136. package/dist/dev/jsx/events.d.ts +364 -0
  137. package/dist/dev/jsx/global.d.ts +211 -0
  138. package/dist/dev/jsx/html.d.ts +879 -0
  139. package/dist/dev/jsx/intrinsic.d.ts +59 -0
  140. package/dist/dev/jsx/mathml.d.ts +186 -0
  141. package/dist/dev/jsx/svg.d.ts +607 -0
  142. package/dist/dev/jsx/types.d.ts +176 -0
  143. package/dist/dev/jsx-dev-runtime.d.ts +10 -0
  144. package/dist/dev/jsx-dev-runtime.js +0 -0
  145. package/dist/dev/jsx-runtime.d.ts +94 -0
  146. package/dist/dev/jsx-runtime.js +0 -0
  147. package/dist/dev/reactive.d.ts +110 -0
  148. package/dist/dev/reactive.js +85 -0
  149. package/dist/dev/reactive.js.map +1 -0
  150. package/dist/dev/render.d.ts +36 -0
  151. package/dist/dev/render.js +52 -0
  152. package/dist/dev/render.js.map +1 -0
  153. package/dist/dev/resource-hints.d.ts +145 -0
  154. package/dist/dev/resource-hints.js +200 -0
  155. package/dist/dev/resource-hints.js.map +1 -0
  156. package/dist/dev/select-value.d.ts +24 -0
  157. package/dist/dev/select-value.js +51 -0
  158. package/dist/dev/select-value.js.map +1 -0
  159. package/dist/dev/server/attributes.d.ts +33 -0
  160. package/dist/dev/server/attributes.js +155 -0
  161. package/dist/dev/server/attributes.js.map +1 -0
  162. package/dist/dev/server/class-style.d.ts +46 -0
  163. package/dist/dev/server/class-style.js +173 -0
  164. package/dist/dev/server/class-style.js.map +1 -0
  165. package/dist/dev/server/component.d.ts +42 -0
  166. package/dist/dev/server/component.js +72 -0
  167. package/dist/dev/server/component.js.map +1 -0
  168. package/dist/dev/server/derived.d.ts +41 -0
  169. package/dist/dev/server/derived.js +26 -0
  170. package/dist/dev/server/derived.js.map +1 -0
  171. package/dist/dev/server/element.d.ts +89 -0
  172. package/dist/dev/server/element.js +216 -0
  173. package/dist/dev/server/element.js.map +1 -0
  174. package/dist/dev/server/errors.js +26 -0
  175. package/dist/dev/server/errors.js.map +1 -0
  176. package/dist/dev/server/escape.d.ts +30 -0
  177. package/dist/dev/server/escape.js +119 -0
  178. package/dist/dev/server/escape.js.map +1 -0
  179. package/dist/dev/server/form-controls.d.ts +50 -0
  180. package/dist/dev/server/form-controls.js +193 -0
  181. package/dist/dev/server/form-controls.js.map +1 -0
  182. package/dist/dev/server/hydration-script.d.ts +65 -0
  183. package/dist/dev/server/hydration-script.js +59 -0
  184. package/dist/dev/server/hydration-script.js.map +1 -0
  185. package/dist/dev/server/index.d.ts +16 -0
  186. package/dist/dev/server/index.js +16 -0
  187. package/dist/dev/server/node.d.ts +13 -0
  188. package/dist/dev/server/node.js +21 -0
  189. package/dist/dev/server/node.js.map +1 -0
  190. package/dist/dev/server/portals.d.ts +46 -0
  191. package/dist/dev/server/portals.js +99 -0
  192. package/dist/dev/server/portals.js.map +1 -0
  193. package/dist/dev/server/render.d.ts +129 -0
  194. package/dist/dev/server/render.js +256 -0
  195. package/dist/dev/server/render.js.map +1 -0
  196. package/dist/dev/server/serialize.d.ts +45 -0
  197. package/dist/dev/server/serialize.js +315 -0
  198. package/dist/dev/server/serialize.js.map +1 -0
  199. package/dist/dev/server/stream.d.ts +94 -0
  200. package/dist/dev/server/stream.js +235 -0
  201. package/dist/dev/server/stream.js.map +1 -0
  202. package/dist/dev/server.d.ts +16 -0
  203. package/dist/dev/server.js +16 -0
  204. package/dist/dev/spread.d.ts +49 -0
  205. package/dist/dev/spread.js +296 -0
  206. package/dist/dev/spread.js.map +1 -0
  207. package/dist/dev/template.d.ts +26 -0
  208. package/dist/dev/template.js +120 -0
  209. package/dist/dev/template.js.map +1 -0
  210. package/dist/dev/view-transition.d.ts +97 -0
  211. package/dist/dev/view-transition.js +121 -0
  212. package/dist/dev/view-transition.js.map +1 -0
  213. package/dist/prod/attributes.js +2 -0
  214. package/dist/prod/attributes.js.map +1 -0
  215. package/dist/prod/autofocus.js +2 -0
  216. package/dist/prod/autofocus.js.map +1 -0
  217. package/dist/prod/class-style.js +2 -0
  218. package/dist/prod/class-style.js.map +1 -0
  219. package/dist/prod/component.js +2 -0
  220. package/dist/prod/component.js.map +1 -0
  221. package/dist/prod/control-flow/activity.js +2 -0
  222. package/dist/prod/control-flow/activity.js.map +1 -0
  223. package/dist/prod/control-flow/branch.js +2 -0
  224. package/dist/prod/control-flow/branch.js.map +1 -0
  225. package/dist/prod/control-flow/client-only.js +2 -0
  226. package/dist/prod/control-flow/client-only.js.map +1 -0
  227. package/dist/prod/control-flow/dynamic.js +2 -0
  228. package/dist/prod/control-flow/dynamic.js.map +1 -0
  229. package/dist/prod/control-flow/error-boundary.js +2 -0
  230. package/dist/prod/control-flow/error-boundary.js.map +1 -0
  231. package/dist/prod/control-flow/for.js +2 -0
  232. package/dist/prod/control-flow/for.js.map +1 -0
  233. package/dist/prod/control-flow/fragment.js +2 -0
  234. package/dist/prod/control-flow/fragment.js.map +1 -0
  235. package/dist/prod/control-flow/hot-link.js +2 -0
  236. package/dist/prod/control-flow/hot-link.js.map +1 -0
  237. package/dist/prod/control-flow/index-list.js +2 -0
  238. package/dist/prod/control-flow/index-list.js.map +1 -0
  239. package/dist/prod/control-flow/lazy.js +2 -0
  240. package/dist/prod/control-flow/lazy.js.map +1 -0
  241. package/dist/prod/control-flow/no-hydration.js +2 -0
  242. package/dist/prod/control-flow/no-hydration.js.map +1 -0
  243. package/dist/prod/control-flow/portal.js +2 -0
  244. package/dist/prod/control-flow/portal.js.map +1 -0
  245. package/dist/prod/control-flow/root-errors.js +2 -0
  246. package/dist/prod/control-flow/root-errors.js.map +1 -0
  247. package/dist/prod/control-flow/show.js +2 -0
  248. package/dist/prod/control-flow/show.js.map +1 -0
  249. package/dist/prod/control-flow/suspense-list.js +2 -0
  250. package/dist/prod/control-flow/suspense-list.js.map +1 -0
  251. package/dist/prod/control-flow/suspense.js +2 -0
  252. package/dist/prod/control-flow/suspense.js.map +1 -0
  253. package/dist/prod/control-flow/switch.js +2 -0
  254. package/dist/prod/control-flow/switch.js.map +1 -0
  255. package/dist/prod/derived.js +2 -0
  256. package/dist/prod/derived.js.map +1 -0
  257. package/dist/prod/element.js +2 -0
  258. package/dist/prod/element.js.map +1 -0
  259. package/dist/prod/events.js +2 -0
  260. package/dist/prod/events.js.map +1 -0
  261. package/dist/prod/extend.js +1 -0
  262. package/dist/prod/head/components.js +2 -0
  263. package/dist/prod/head/components.js.map +1 -0
  264. package/dist/prod/head/registry.js +2 -0
  265. package/dist/prod/head/registry.js.map +1 -0
  266. package/dist/prod/head/server-head.js +2 -0
  267. package/dist/prod/head/server-head.js.map +1 -0
  268. package/dist/prod/head/sink.js +2 -0
  269. package/dist/prod/head/sink.js.map +1 -0
  270. package/dist/prod/head/use-head.js +2 -0
  271. package/dist/prod/head/use-head.js.map +1 -0
  272. package/dist/prod/head/validate.js +2 -0
  273. package/dist/prod/head/validate.js.map +1 -0
  274. package/dist/prod/hmr.js +2 -0
  275. package/dist/prod/hmr.js.map +1 -0
  276. package/dist/prod/hydration.js +2 -0
  277. package/dist/prod/hydration.js.map +1 -0
  278. package/dist/prod/index.js +1 -0
  279. package/dist/prod/insert.js +2 -0
  280. package/dist/prod/insert.js.map +1 -0
  281. package/dist/prod/internal/claim.js +2 -0
  282. package/dist/prod/internal/claim.js.map +1 -0
  283. package/dist/prod/internal/css-units.js +2 -0
  284. package/dist/prod/internal/css-units.js.map +1 -0
  285. package/dist/prod/internal/diagnostics.js +2 -0
  286. package/dist/prod/internal/diagnostics.js.map +1 -0
  287. package/dist/prod/internal/early-events.js +2 -0
  288. package/dist/prod/internal/early-events.js.map +1 -0
  289. package/dist/prod/internal/hydration-hooks.js +2 -0
  290. package/dist/prod/internal/hydration-hooks.js.map +1 -0
  291. package/dist/prod/internal/hydration-scope.js +2 -0
  292. package/dist/prod/internal/hydration-scope.js.map +1 -0
  293. package/dist/prod/internal/names.js +2 -0
  294. package/dist/prod/internal/names.js.map +1 -0
  295. package/dist/prod/internal/portal-context.js +2 -0
  296. package/dist/prod/internal/portal-context.js.map +1 -0
  297. package/dist/prod/internal/react-names.js +2 -0
  298. package/dist/prod/internal/react-names.js.map +1 -0
  299. package/dist/prod/internal/reconcile.js +2 -0
  300. package/dist/prod/internal/reconcile.js.map +1 -0
  301. package/dist/prod/internal/stream-context.js +2 -0
  302. package/dist/prod/internal/stream-context.js.map +1 -0
  303. package/dist/prod/jsx-dev-runtime.js +0 -0
  304. package/dist/prod/jsx-runtime.js +0 -0
  305. package/dist/prod/reactive.js +2 -0
  306. package/dist/prod/reactive.js.map +1 -0
  307. package/dist/prod/render.js +2 -0
  308. package/dist/prod/render.js.map +1 -0
  309. package/dist/prod/resource-hints.js +2 -0
  310. package/dist/prod/resource-hints.js.map +1 -0
  311. package/dist/prod/select-value.js +2 -0
  312. package/dist/prod/select-value.js.map +1 -0
  313. package/dist/prod/server/attributes.js +2 -0
  314. package/dist/prod/server/attributes.js.map +1 -0
  315. package/dist/prod/server/class-style.js +2 -0
  316. package/dist/prod/server/class-style.js.map +1 -0
  317. package/dist/prod/server/component.js +2 -0
  318. package/dist/prod/server/component.js.map +1 -0
  319. package/dist/prod/server/derived.js +2 -0
  320. package/dist/prod/server/derived.js.map +1 -0
  321. package/dist/prod/server/element.js +2 -0
  322. package/dist/prod/server/element.js.map +1 -0
  323. package/dist/prod/server/errors.js +2 -0
  324. package/dist/prod/server/errors.js.map +1 -0
  325. package/dist/prod/server/escape.js +2 -0
  326. package/dist/prod/server/escape.js.map +1 -0
  327. package/dist/prod/server/form-controls.js +3 -0
  328. package/dist/prod/server/form-controls.js.map +1 -0
  329. package/dist/prod/server/hydration-script.js +2 -0
  330. package/dist/prod/server/hydration-script.js.map +1 -0
  331. package/dist/prod/server/index.js +1 -0
  332. package/dist/prod/server/node.js +2 -0
  333. package/dist/prod/server/node.js.map +1 -0
  334. package/dist/prod/server/portals.js +2 -0
  335. package/dist/prod/server/portals.js.map +1 -0
  336. package/dist/prod/server/render.js +2 -0
  337. package/dist/prod/server/render.js.map +1 -0
  338. package/dist/prod/server/serialize.js +2 -0
  339. package/dist/prod/server/serialize.js.map +1 -0
  340. package/dist/prod/server/stream.js +2 -0
  341. package/dist/prod/server/stream.js.map +1 -0
  342. package/dist/prod/server.js +1 -0
  343. package/dist/prod/spread.js +2 -0
  344. package/dist/prod/spread.js.map +1 -0
  345. package/dist/prod/template.js +2 -0
  346. package/dist/prod/template.js.map +1 -0
  347. package/dist/prod/view-transition.js +2 -0
  348. package/dist/prod/view-transition.js.map +1 -0
  349. package/dist/server/attributes.js +2 -0
  350. package/dist/server/attributes.js.map +1 -0
  351. package/dist/server/autofocus.js +2 -0
  352. package/dist/server/autofocus.js.map +1 -0
  353. package/dist/server/class-style.js +2 -0
  354. package/dist/server/class-style.js.map +1 -0
  355. package/dist/server/component.js +2 -0
  356. package/dist/server/component.js.map +1 -0
  357. package/dist/server/control-flow/activity.js +2 -0
  358. package/dist/server/control-flow/activity.js.map +1 -0
  359. package/dist/server/control-flow/branch.js +2 -0
  360. package/dist/server/control-flow/branch.js.map +1 -0
  361. package/dist/server/control-flow/client-only.js +2 -0
  362. package/dist/server/control-flow/client-only.js.map +1 -0
  363. package/dist/server/control-flow/dynamic.js +2 -0
  364. package/dist/server/control-flow/dynamic.js.map +1 -0
  365. package/dist/server/control-flow/error-boundary.js +2 -0
  366. package/dist/server/control-flow/error-boundary.js.map +1 -0
  367. package/dist/server/control-flow/for.js +2 -0
  368. package/dist/server/control-flow/for.js.map +1 -0
  369. package/dist/server/control-flow/fragment.js +2 -0
  370. package/dist/server/control-flow/fragment.js.map +1 -0
  371. package/dist/server/control-flow/index-list.js +2 -0
  372. package/dist/server/control-flow/index-list.js.map +1 -0
  373. package/dist/server/control-flow/lazy.js +2 -0
  374. package/dist/server/control-flow/lazy.js.map +1 -0
  375. package/dist/server/control-flow/no-hydration.js +2 -0
  376. package/dist/server/control-flow/no-hydration.js.map +1 -0
  377. package/dist/server/control-flow/portal.js +2 -0
  378. package/dist/server/control-flow/portal.js.map +1 -0
  379. package/dist/server/control-flow/root-errors.js +2 -0
  380. package/dist/server/control-flow/root-errors.js.map +1 -0
  381. package/dist/server/control-flow/show.js +2 -0
  382. package/dist/server/control-flow/show.js.map +1 -0
  383. package/dist/server/control-flow/suspense-list.js +2 -0
  384. package/dist/server/control-flow/suspense-list.js.map +1 -0
  385. package/dist/server/control-flow/suspense.js +2 -0
  386. package/dist/server/control-flow/suspense.js.map +1 -0
  387. package/dist/server/control-flow/switch.js +2 -0
  388. package/dist/server/control-flow/switch.js.map +1 -0
  389. package/dist/server/derived.js +2 -0
  390. package/dist/server/derived.js.map +1 -0
  391. package/dist/server/element.js +2 -0
  392. package/dist/server/element.js.map +1 -0
  393. package/dist/server/events.js +2 -0
  394. package/dist/server/events.js.map +1 -0
  395. package/dist/server/extend.js +1 -0
  396. package/dist/server/head/components.js +2 -0
  397. package/dist/server/head/components.js.map +1 -0
  398. package/dist/server/head/registry.js +2 -0
  399. package/dist/server/head/registry.js.map +1 -0
  400. package/dist/server/head/server-head.js +2 -0
  401. package/dist/server/head/server-head.js.map +1 -0
  402. package/dist/server/head/sink.js +2 -0
  403. package/dist/server/head/sink.js.map +1 -0
  404. package/dist/server/head/use-head.js +2 -0
  405. package/dist/server/head/use-head.js.map +1 -0
  406. package/dist/server/head/validate.js +2 -0
  407. package/dist/server/head/validate.js.map +1 -0
  408. package/dist/server/hydration.js +2 -0
  409. package/dist/server/hydration.js.map +1 -0
  410. package/dist/server/index.js +1 -0
  411. package/dist/server/insert.js +2 -0
  412. package/dist/server/insert.js.map +1 -0
  413. package/dist/server/internal/claim.js +2 -0
  414. package/dist/server/internal/claim.js.map +1 -0
  415. package/dist/server/internal/css-units.js +2 -0
  416. package/dist/server/internal/css-units.js.map +1 -0
  417. package/dist/server/internal/diagnostics.js +2 -0
  418. package/dist/server/internal/diagnostics.js.map +1 -0
  419. package/dist/server/internal/early-events.js +2 -0
  420. package/dist/server/internal/early-events.js.map +1 -0
  421. package/dist/server/internal/hydration-hooks.js +2 -0
  422. package/dist/server/internal/hydration-hooks.js.map +1 -0
  423. package/dist/server/internal/hydration-scope.js +2 -0
  424. package/dist/server/internal/hydration-scope.js.map +1 -0
  425. package/dist/server/internal/names.js +2 -0
  426. package/dist/server/internal/names.js.map +1 -0
  427. package/dist/server/internal/portal-context.js +2 -0
  428. package/dist/server/internal/portal-context.js.map +1 -0
  429. package/dist/server/internal/react-names.js +2 -0
  430. package/dist/server/internal/react-names.js.map +1 -0
  431. package/dist/server/internal/reconcile.js +2 -0
  432. package/dist/server/internal/reconcile.js.map +1 -0
  433. package/dist/server/internal/stream-context.js +2 -0
  434. package/dist/server/internal/stream-context.js.map +1 -0
  435. package/dist/server/reactive.js +2 -0
  436. package/dist/server/reactive.js.map +1 -0
  437. package/dist/server/render.js +2 -0
  438. package/dist/server/render.js.map +1 -0
  439. package/dist/server/resource-hints.js +2 -0
  440. package/dist/server/resource-hints.js.map +1 -0
  441. package/dist/server/select-value.js +2 -0
  442. package/dist/server/select-value.js.map +1 -0
  443. package/dist/server/server/attributes.js +2 -0
  444. package/dist/server/server/attributes.js.map +1 -0
  445. package/dist/server/server/class-style.js +2 -0
  446. package/dist/server/server/class-style.js.map +1 -0
  447. package/dist/server/server/component.js +2 -0
  448. package/dist/server/server/component.js.map +1 -0
  449. package/dist/server/server/derived.js +2 -0
  450. package/dist/server/server/derived.js.map +1 -0
  451. package/dist/server/server/element.js +2 -0
  452. package/dist/server/server/element.js.map +1 -0
  453. package/dist/server/server/errors.js +2 -0
  454. package/dist/server/server/errors.js.map +1 -0
  455. package/dist/server/server/escape.js +2 -0
  456. package/dist/server/server/escape.js.map +1 -0
  457. package/dist/server/server/form-controls.js +3 -0
  458. package/dist/server/server/form-controls.js.map +1 -0
  459. package/dist/server/server/hydration-script.js +2 -0
  460. package/dist/server/server/hydration-script.js.map +1 -0
  461. package/dist/server/server/index.js +1 -0
  462. package/dist/server/server/node.js +2 -0
  463. package/dist/server/server/node.js.map +1 -0
  464. package/dist/server/server/portals.js +2 -0
  465. package/dist/server/server/portals.js.map +1 -0
  466. package/dist/server/server/render.js +2 -0
  467. package/dist/server/server/render.js.map +1 -0
  468. package/dist/server/server/serialize.js +2 -0
  469. package/dist/server/server/serialize.js.map +1 -0
  470. package/dist/server/server/stream.js +2 -0
  471. package/dist/server/server/stream.js.map +1 -0
  472. package/dist/server/server.js +1 -0
  473. package/dist/server/spread.js +2 -0
  474. package/dist/server/spread.js.map +1 -0
  475. package/dist/server/template.js +2 -0
  476. package/dist/server/template.js.map +1 -0
  477. package/dist/server/view-transition.js +2 -0
  478. package/dist/server/view-transition.js.map +1 -0
  479. package/dist/server-dev/attributes.js +196 -0
  480. package/dist/server-dev/attributes.js.map +1 -0
  481. package/dist/server-dev/autofocus.js +45 -0
  482. package/dist/server-dev/autofocus.js.map +1 -0
  483. package/dist/server-dev/class-style.js +197 -0
  484. package/dist/server-dev/class-style.js.map +1 -0
  485. package/dist/server-dev/component.js +42 -0
  486. package/dist/server-dev/component.js.map +1 -0
  487. package/dist/server-dev/control-flow/activity.js +41 -0
  488. package/dist/server-dev/control-flow/activity.js.map +1 -0
  489. package/dist/server-dev/control-flow/branch.js +104 -0
  490. package/dist/server-dev/control-flow/branch.js.map +1 -0
  491. package/dist/server-dev/control-flow/client-only.js +50 -0
  492. package/dist/server-dev/control-flow/client-only.js.map +1 -0
  493. package/dist/server-dev/control-flow/dynamic.js +106 -0
  494. package/dist/server-dev/control-flow/dynamic.js.map +1 -0
  495. package/dist/server-dev/control-flow/error-boundary.js +115 -0
  496. package/dist/server-dev/control-flow/error-boundary.js.map +1 -0
  497. package/dist/server-dev/control-flow/for.js +23 -0
  498. package/dist/server-dev/control-flow/for.js.map +1 -0
  499. package/dist/server-dev/control-flow/fragment.js +31 -0
  500. package/dist/server-dev/control-flow/fragment.js.map +1 -0
  501. package/dist/server-dev/control-flow/hot-link.js +57 -0
  502. package/dist/server-dev/control-flow/hot-link.js.map +1 -0
  503. package/dist/server-dev/control-flow/index-list.js +31 -0
  504. package/dist/server-dev/control-flow/index-list.js.map +1 -0
  505. package/dist/server-dev/control-flow/lazy.js +64 -0
  506. package/dist/server-dev/control-flow/lazy.js.map +1 -0
  507. package/dist/server-dev/control-flow/no-hydration.js +40 -0
  508. package/dist/server-dev/control-flow/no-hydration.js.map +1 -0
  509. package/dist/server-dev/control-flow/portal.js +134 -0
  510. package/dist/server-dev/control-flow/portal.js.map +1 -0
  511. package/dist/server-dev/control-flow/root-errors.js +33 -0
  512. package/dist/server-dev/control-flow/root-errors.js.map +1 -0
  513. package/dist/server-dev/control-flow/show.js +18 -0
  514. package/dist/server-dev/control-flow/show.js.map +1 -0
  515. package/dist/server-dev/control-flow/suspense-list.js +100 -0
  516. package/dist/server-dev/control-flow/suspense-list.js.map +1 -0
  517. package/dist/server-dev/control-flow/suspense.js +119 -0
  518. package/dist/server-dev/control-flow/suspense.js.map +1 -0
  519. package/dist/server-dev/control-flow/switch.js +90 -0
  520. package/dist/server-dev/control-flow/switch.js.map +1 -0
  521. package/dist/server-dev/derived.js +34 -0
  522. package/dist/server-dev/derived.js.map +1 -0
  523. package/dist/server-dev/element.js +66 -0
  524. package/dist/server-dev/element.js.map +1 -0
  525. package/dist/server-dev/events.js +265 -0
  526. package/dist/server-dev/events.js.map +1 -0
  527. package/dist/server-dev/extend.js +12 -0
  528. package/dist/server-dev/head/components.js +170 -0
  529. package/dist/server-dev/head/components.js.map +1 -0
  530. package/dist/server-dev/head/registry.js +68 -0
  531. package/dist/server-dev/head/registry.js.map +1 -0
  532. package/dist/server-dev/head/server-head.js +76 -0
  533. package/dist/server-dev/head/server-head.js.map +1 -0
  534. package/dist/server-dev/head/sink.js +96 -0
  535. package/dist/server-dev/head/sink.js.map +1 -0
  536. package/dist/server-dev/head/use-head.js +84 -0
  537. package/dist/server-dev/head/use-head.js.map +1 -0
  538. package/dist/server-dev/head/validate.js +268 -0
  539. package/dist/server-dev/head/validate.js.map +1 -0
  540. package/dist/server-dev/hydration.js +120 -0
  541. package/dist/server-dev/hydration.js.map +1 -0
  542. package/dist/server-dev/index.js +34 -0
  543. package/dist/server-dev/insert.js +357 -0
  544. package/dist/server-dev/insert.js.map +1 -0
  545. package/dist/server-dev/internal/claim.js +357 -0
  546. package/dist/server-dev/internal/claim.js.map +1 -0
  547. package/dist/server-dev/internal/css-units.js +26 -0
  548. package/dist/server-dev/internal/css-units.js.map +1 -0
  549. package/dist/server-dev/internal/diagnostics.js +38 -0
  550. package/dist/server-dev/internal/diagnostics.js.map +1 -0
  551. package/dist/server-dev/internal/early-events.js +76 -0
  552. package/dist/server-dev/internal/early-events.js.map +1 -0
  553. package/dist/server-dev/internal/hydration-hooks.js +27 -0
  554. package/dist/server-dev/internal/hydration-hooks.js.map +1 -0
  555. package/dist/server-dev/internal/hydration-scope.js +156 -0
  556. package/dist/server-dev/internal/hydration-scope.js.map +1 -0
  557. package/dist/server-dev/internal/names.js +35 -0
  558. package/dist/server-dev/internal/names.js.map +1 -0
  559. package/dist/server-dev/internal/portal-context.js +28 -0
  560. package/dist/server-dev/internal/portal-context.js.map +1 -0
  561. package/dist/server-dev/internal/react-names.js +116 -0
  562. package/dist/server-dev/internal/react-names.js.map +1 -0
  563. package/dist/server-dev/internal/reconcile.js +122 -0
  564. package/dist/server-dev/internal/reconcile.js.map +1 -0
  565. package/dist/server-dev/internal/stream-context.js +23 -0
  566. package/dist/server-dev/internal/stream-context.js.map +1 -0
  567. package/dist/server-dev/reactive.js +85 -0
  568. package/dist/server-dev/reactive.js.map +1 -0
  569. package/dist/server-dev/render.js +52 -0
  570. package/dist/server-dev/render.js.map +1 -0
  571. package/dist/server-dev/resource-hints.js +200 -0
  572. package/dist/server-dev/resource-hints.js.map +1 -0
  573. package/dist/server-dev/select-value.js +51 -0
  574. package/dist/server-dev/select-value.js.map +1 -0
  575. package/dist/server-dev/server/attributes.js +155 -0
  576. package/dist/server-dev/server/attributes.js.map +1 -0
  577. package/dist/server-dev/server/class-style.js +173 -0
  578. package/dist/server-dev/server/class-style.js.map +1 -0
  579. package/dist/server-dev/server/component.js +72 -0
  580. package/dist/server-dev/server/component.js.map +1 -0
  581. package/dist/server-dev/server/derived.js +26 -0
  582. package/dist/server-dev/server/derived.js.map +1 -0
  583. package/dist/server-dev/server/element.js +216 -0
  584. package/dist/server-dev/server/element.js.map +1 -0
  585. package/dist/server-dev/server/errors.js +26 -0
  586. package/dist/server-dev/server/errors.js.map +1 -0
  587. package/dist/server-dev/server/escape.js +119 -0
  588. package/dist/server-dev/server/escape.js.map +1 -0
  589. package/dist/server-dev/server/form-controls.js +193 -0
  590. package/dist/server-dev/server/form-controls.js.map +1 -0
  591. package/dist/server-dev/server/hydration-script.js +59 -0
  592. package/dist/server-dev/server/hydration-script.js.map +1 -0
  593. package/dist/server-dev/server/index.js +16 -0
  594. package/dist/server-dev/server/node.js +21 -0
  595. package/dist/server-dev/server/node.js.map +1 -0
  596. package/dist/server-dev/server/portals.js +99 -0
  597. package/dist/server-dev/server/portals.js.map +1 -0
  598. package/dist/server-dev/server/render.js +256 -0
  599. package/dist/server-dev/server/render.js.map +1 -0
  600. package/dist/server-dev/server/serialize.js +315 -0
  601. package/dist/server-dev/server/serialize.js.map +1 -0
  602. package/dist/server-dev/server/stream.js +235 -0
  603. package/dist/server-dev/server/stream.js.map +1 -0
  604. package/dist/server-dev/server.js +16 -0
  605. package/dist/server-dev/spread.js +296 -0
  606. package/dist/server-dev/spread.js.map +1 -0
  607. package/dist/server-dev/template.js +120 -0
  608. package/dist/server-dev/template.js.map +1 -0
  609. package/dist/server-dev/view-transition.js +90 -0
  610. package/dist/server-dev/view-transition.js.map +1 -0
  611. package/package.json +136 -4
package/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ ### Added
6
+
7
+ - DOM rendering, event bindings, reactive properties and composable control-flow components.
8
+ - Server rendering, streaming, hydration, serialization and document head management.
9
+ - Hydration preserves spread child nodes and static NoHydration regions.
10
+ - Fresh client roots mounted during hydration preserve the enclosing root's server nodes and key sequence.
11
+ - Streaming SSR releases abort listeners and timers, prevents rendering after cancellation, respects pre-aborted signals and keeps callbacks untracked.
12
+ - Held shells stop at exactly ten passes; every pass is disposed even when another pass's cleanup throws.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ShadowJS contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,191 @@
1
- # Temporary Holding Version
1
+ # @shadow-js/web
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The DOM renderer of ShadowJS: it mounts components, keeps text, attributes and child lists in sync
4
+ with signals, and provides control flow (`<Show>`, `<For>`, `<Suspense>` and more), document head
5
+ tags, server rendering and hydration. There is no virtual DOM: the compiler turns JSX into real DOM
6
+ operations (see [`@shadow-js/compiler`](../compiler/README.md)) and this package supplies the
7
+ runtime those operations call. The live DOM contains no comment nodes and no placeholder elements.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install @shadow-js/core @shadow-js/web
13
+ npm install -D @shadow-js/vite
14
+ ```
15
+
16
+ `@shadow-js/core` is a peer dependency. JSX needs the compiler, which the Vite plugin runs for
17
+ you. In `tsconfig.json`, point JSX at this package:
18
+
19
+ ```json
20
+ {
21
+ "compilerOptions": {
22
+ "jsx": "preserve",
23
+ "jsxImportSource": "@shadow-js/web"
24
+ }
25
+ }
26
+ ```
27
+
28
+ ShadowJS 1.0.0 is not on npm yet. Until it is published, install it from a local checkout of this
29
+ repository.
30
+
31
+ ## Example
32
+
33
+ A component is a function that runs once. `count()` inside JSX is a binding: when the signal
34
+ changes, only that text node is updated. `render` mounts a component into a container, flushes, and
35
+ returns a function that removes the output and disposes everything the component created.
36
+
37
+ ```tsx title="counter.tsx" run mount="Counter" text="Count: 0"
38
+ import { useStore } from "@shadow-js/core";
39
+
40
+ export function Counter() {
41
+ const [count, setCount] = useStore(0);
42
+
43
+ return (
44
+ <button type="button" onClick={() => setCount((n) => n + 1)}>
45
+ Count: {count()}
46
+ </button>
47
+ );
48
+ }
49
+ ```
50
+
51
+ Test it with [`@shadow-js/testing`](https://testing.shadowjs.net). `fireEvent` dispatches the click and
52
+ flushes, so the assertion sees the updated text.
53
+
54
+ ```tsx title="counter.test.tsx" test
55
+ import { fireEvent, render } from "@shadow-js/testing/dom";
56
+ import { describe, expect, it } from "vitest";
57
+ import { Counter } from "./counter";
58
+
59
+ describe("Counter", () => {
60
+ it("updates only its text when clicked", () => {
61
+ const view = render(() => <Counter />);
62
+ const button = view.getByRole("button");
63
+ const text = button.lastChild;
64
+
65
+ expect(button.textContent).toBe("Count: 0");
66
+ fireEvent.click(button);
67
+
68
+ expect(button.textContent).toBe("Count: 1");
69
+ expect(button.lastChild).toBe(text);
70
+ });
71
+ });
72
+ ```
73
+
74
+ ### Server rendering and hydration
75
+
76
+ `@shadow-js/web/server` renders the same component to a string. The compiler emits a server variant
77
+ of your JSX (`generate: "ssr"`, which the Vite plugin selects for SSR builds). Hydration keys
78
+ (`data-hk`) and `<!--[-->` region markers in the string let the browser claim the existing nodes
79
+ instead of rebuilding them; the markers are removed during hydration.
80
+
81
+ ```tsx title="server.tsx" run target="ssr" output='<button data-hk="0-0-0" type="button">Count: <!--[-->0<!--]--></button>'
82
+ import { renderToString } from "@shadow-js/web/server";
83
+ import { Counter } from "./counter";
84
+
85
+ console.log(renderToString(() => <Counter />));
86
+ ```
87
+
88
+ On the client, `hydrate` takes the same component call and the container that holds the server
89
+ markup. It returns a dispose function.
90
+
91
+ ```tsx title="entry-client.tsx" typecheck
92
+ import { hydrate } from "@shadow-js/web";
93
+ import { Counter } from "./counter";
94
+
95
+ const container = document.getElementById("app");
96
+ if (container === null) throw new Error("Missing #app element");
97
+
98
+ hydrate(() => <Counter />, container);
99
+ ```
100
+
101
+ Resources that loaded on the server are passed through `renderToStringAsync` (which returns
102
+ `{ html, data }`) and `hydrate(..., { data })`; `renderToStream` streams Suspense boundaries.
103
+ An already-aborted signal prevents the application from rendering. Completion, failure, timeout and
104
+ consumer cancellation release abort listeners, timers and render owners. Cancellation also stops a
105
+ held shell from rendering again when its data arrives. Shell callbacks and error reporters run
106
+ untracked. Held shells are limited to ten passes; invalid time budgets are refused synchronously.
107
+ If cleanup fails, every pass is still disposed before the error is surfaced; multiple cleanup
108
+ failures are combined in an `AggregateError`.
109
+
110
+ ## API
111
+
112
+ Entry `@shadow-js/web`. The exports are:
113
+
114
+ ### Mounting and hydration
115
+
116
+ | Export | Description |
117
+ | --- | --- |
118
+ | `render` | Mounts a component into a container, flushes, and returns a dispose function. |
119
+ | `hydrate` | Attaches the application to HTML the server rendered, claiming nodes by key. |
120
+
121
+ ### Control flow
122
+
123
+ | Export | Description |
124
+ | --- | --- |
125
+ | `Show` | Shows `children` while `when` is truthy, `fallback` otherwise. |
126
+ | `Switch`, `Match` | Shows the first `Match` whose `when` is truthy, or the fallback. |
127
+ | `For` | One row per item, matched by reference or by `key`; rows keep their identity when the list moves. |
128
+ | `Index` | One row per position. |
129
+ | `Dynamic` | Renders a component or a tag chosen at runtime. |
130
+ | `Portal` | Renders children into another part of the document, without a wrapper. |
131
+ | `Suspense` | Shows `fallback` while resources read inside it load for the first time. |
132
+ | `ErrorBoundary` | Renders `children`; shows a fallback when they throw, with a `reset`. |
133
+ | `lazy` | A component whose code is loaded on first render. |
134
+ | `Fragment` | A no-op wrapper that returns its children. |
135
+
136
+ ### Document head
137
+
138
+ | Export | Description |
139
+ | --- | --- |
140
+ | `Title`, `Meta`, `Link`, `Base`, `Style` | Components that register head tags for their lifetime. |
141
+ | `useHead` | Registers head tags for the lifetime of the current owner. |
142
+
143
+ ### Compiler targets and custom renderers
144
+
145
+ | Export | Description |
146
+ | --- | --- |
147
+ | `template`, `insert`, `anchor` | Clone static DOM once, insert reactive children, create text anchors. |
148
+ | `spread`, `use` | Apply a props object reactively; run refs and directives untracked. |
149
+ | `setAttribute`, `setAttributeNS`, `setBoolAttribute`, `className`, `classList`, `style`, `setStyleProperty` | Attribute, class and style writers with URL and name safety. |
150
+ | `addEventListener`, `delegateEvents` | Bind handlers; delegate common events to the document. |
151
+ | `createComponent`, `effect`, `memo`, `derived`, `mergeProps` | Helpers the compiled code imports. |
152
+
153
+ `isDev`, `isServer` and `mergeProps` are re-exported from `@shadow-js/core`. The package also
154
+ exports the `JSX` namespace and the component types `Component`, `ParentComponent`, `VoidComponent`,
155
+ `FlowComponent`, `ParentProps`, `ComponentProps`, `Ref`, `ClassValue` and `CSSProperties`.
156
+
157
+ ### Subpath entries
158
+
159
+ | Entry | Contents |
160
+ | --- | --- |
161
+ | `@shadow-js/web/server` | `renderToString`, `renderToStringAsync`, `renderToStream`, `serialize`, `deserialize`, and the helpers the compiler's server output calls (`ssr`, `escape`, `ssrAttribute`, `ssrClass`, `ssrStyle`, `ssrElement`, `ssrHydrationKey`, `ssrRaw`, `ssrSelectValue`, `ssrTextArea`). |
162
+ | `@shadow-js/web/jsx-runtime`, `@shadow-js/web/jsx-dev-runtime` | The `JSX` namespace for `jsxImportSource`; augment `CustomEvents` and `Directives` here. |
163
+ | `@shadow-js/web/extend` | The building blocks the built-ins use: `createRegion`, `bindRegion`, `reconcileNodes`, hydration scopes (`withScope`, `nextKey`, `claimElement`), `isUnsafeUrlAttribute`. |
164
+ | `@shadow-js/web/hmr` | The runtime of component-level hot updates, imported by code the compiler generates when its `hmr` option is on. Not called by application code. |
165
+
166
+ ## Status
167
+
168
+ The DOM runtime, control flow, the server renderer and hydration are tested, including the
169
+ server-to-client round trip. `Dynamic`, `Portal`, head tags and the JSX types are exported; the
170
+ type tests are in `packages/web/test-types`.
171
+
172
+ ## Links
173
+
174
+ - [`@shadow-js/core`](../core/README.md), [`@shadow-js/compiler`](../compiler/README.md), [`@shadow-js/vite`](../vite/README.md), [`@shadow-js/testing`](https://testing.shadowjs.net)
175
+
176
+ ## Dependencies
177
+
178
+ - Runtime: none.
179
+ - Peers: `@shadow-js/core` `^1.0.0`: the reactive primitives the renderer is built on.
180
+
181
+ ## Types
182
+
183
+ - Names from the root: `ComponentProps`, `Derived`, `derived`, `HydrateOptions`.
184
+ - Type tests in `test-types/` run with `npx tsc -p tsconfig.test-types.json`.
185
+
186
+ ## Support
187
+
188
+ - Node.js `>=22.12.0`. ESM only: use `import`; `require` is not supported.
189
+ - Browsers: current evergreen releases.
190
+ - Versioning: every `@shadow-js/*` package releases together at one version. Upgrade them as one set.
191
+ - Documentation: [ShadowJS documentation](https://shadowjs.net).
@@ -0,0 +1,90 @@
1
+ //#region src/attributes.d.ts
2
+ /**
3
+ * Reports whether writing `value` to the attribute `name` would run script: the URL check that
4
+ * {@link setAttribute}, the head registry and the server renderer share. Use it in a custom renderer
5
+ * before writing a URL that came from user data. URL attributes (`href`, `src`, `action`,
6
+ * `formaction`, `xlink:href`, `srcdoc`, `poster`, `data`) are unsafe when, after removing control
7
+ * characters, trimming and lowercasing, they start with `javascript:`, `data:text/html` or
8
+ * `vbscript:`. The SVG animation attributes `values`, `from`, `to` and `by` are checked the same way,
9
+ * each `;`-separated entry of `values` on its own.
10
+ *
11
+ * @param name Attribute name, in any case.
12
+ * @param value The text that would be written.
13
+ * @returns `true` when the value must not be written; `false` for every other attribute or value.
14
+ * @example
15
+ * import { isUnsafeUrlAttribute } from "@shadow-js/web/extend";
16
+ *
17
+ * isUnsafeUrlAttribute("href", " JavaScript:alert(1)"); // true
18
+ * isUnsafeUrlAttribute("href", "https://example.com"); // false
19
+ * isUnsafeUrlAttribute("title", "javascript:alert(1)"); // false: not a URL attribute
20
+ * @see setAttribute
21
+ * @since 1.0.0
22
+ */
23
+ export declare function isUnsafeUrlAttribute(name: string, value: string): boolean;
24
+ /**
25
+ * Sets or removes one attribute with the JSX value rules: the helper compiled templates call for a
26
+ * dynamic attribute, also usable on elements you create yourself. The DOM is touched only when the
27
+ * text changes. A URL attribute whose value would run script (see {@link isUnsafeUrlAttribute}) is
28
+ * left unchanged, and development builds warn once with `UNSAFE_URL_BLOCKED`.
29
+ *
30
+ * @param el Target element.
31
+ * @param name Attribute name. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.
32
+ * @param value `null`, `undefined` and `false` remove the attribute, except that `false` writes
33
+ * `"false"` for `aria-*`, `data-*`, `draggable`, `spellcheck` and `contenteditable`. `true` writes
34
+ * `""` (or `"true"` for those same names). Any other value is written as `String(value)`.
35
+ * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.
36
+ * @example
37
+ * import { setAttribute } from "@shadow-js/web";
38
+ *
39
+ * const link = document.createElement("a");
40
+ * setAttribute(link, "href", "https://example.com");
41
+ * setAttribute(link, "aria-hidden", false); // aria-hidden="false"
42
+ * setAttribute(link, "title", null); // removes title
43
+ * @see setBoolAttribute
44
+ * @see setAttributeNS
45
+ * @since 1.0.0
46
+ */
47
+ export declare function setAttribute(el: Element, name: string, value: unknown): void;
48
+ /**
49
+ * Sets or removes a namespaced attribute such as `xlink:href` or `xml:lang`, with the value rules
50
+ * and the URL check of {@link setAttribute}. Removal uses the local part of the name (`href` for
51
+ * `xlink:href`).
52
+ *
53
+ * @param el Target element.
54
+ * @param namespace Namespace URI. `""` means no namespace, which behaves exactly like
55
+ * {@link setAttribute}.
56
+ * @param name Qualified name (`prefix:local`). It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.
57
+ * @param value The value, with the same rules as {@link setAttribute}.
58
+ * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.
59
+ * @example
60
+ * import { setAttributeNS } from "@shadow-js/web";
61
+ *
62
+ * const XLINK = "http://www.w3.org/1999/xlink";
63
+ * const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
64
+ * setAttributeNS(use, XLINK, "xlink:href", "#icon-star");
65
+ * setAttributeNS(use, XLINK, "xlink:href", null); // removes it
66
+ * @see setAttribute
67
+ * @since 1.0.0
68
+ */
69
+ export declare function setAttributeNS(el: Element, namespace: string, name: string, value: unknown): void;
70
+ /**
71
+ * Sets or removes a presence (boolean) attribute such as `disabled` or `hidden`: the helper compiled
72
+ * templates call for the `bool:` prefix. A truthy value sets the attribute to `""`, a falsy value
73
+ * removes it; the DOM is touched only when presence changes. No URL check applies.
74
+ *
75
+ * @param el Target element.
76
+ * @param name Attribute name, such as `disabled`. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.
77
+ * @param value Any value: only its truthiness is read.
78
+ * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.
79
+ * @example
80
+ * import { setBoolAttribute } from "@shadow-js/web";
81
+ *
82
+ * const button = document.createElement("button");
83
+ * setBoolAttribute(button, "disabled", true); // disabled=""
84
+ * setBoolAttribute(button, "disabled", 0); // removed
85
+ * @see setAttribute
86
+ * @since 1.0.0
87
+ */
88
+ export declare function setBoolAttribute(el: Element, name: string, value: unknown): void;
89
+ //#endregion
90
+ //# sourceMappingURL=attributes.d.ts.map
@@ -0,0 +1,196 @@
1
+ import { invalidAttributeName, warnOnce } from "./internal/diagnostics.js";
2
+ //#region src/attributes.ts
3
+ /** Names that can appear in markup: an XML-name subset without `@` or whitespace. */
4
+ const ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_:.-]*$/;
5
+ /**
6
+ * Attributes whose value is a URL and therefore checked for script schemes. The SVG animation values
7
+ * (`animate`, `set`) are checked too: with `attributeName="href"` they write an `href` by animation.
8
+ */
9
+ const URL_ATTRIBUTES = /* @__PURE__ */ new Set([
10
+ "href",
11
+ "src",
12
+ "action",
13
+ "formaction",
14
+ "xlink:href",
15
+ "srcdoc",
16
+ "poster",
17
+ "data",
18
+ "values",
19
+ "from",
20
+ "to",
21
+ "by"
22
+ ]);
23
+ /** Enumerated attributes where `false` is a real value ("false") rather than an absence. */
24
+ const ENUMERATED_ATTRIBUTES = /* @__PURE__ */ new Set([
25
+ "draggable",
26
+ "spellcheck",
27
+ "contenteditable"
28
+ ]);
29
+ /** URL prefixes (after normalization) that are never written. */
30
+ const UNSAFE_URL_PREFIXES = [
31
+ "javascript:",
32
+ "data:text/html",
33
+ "vbscript:"
34
+ ];
35
+ /**
36
+ * Throws a TypeError unless `name` is a valid attribute name. Runs for every name, including the
37
+ * ones that come from spread, so no unvalidated name reaches `setAttribute`.
38
+ * @internal
39
+ */
40
+ function assertAttributeName(name) {
41
+ if (!ATTRIBUTE_NAME.test(name)) throw invalidAttributeName(name);
42
+ }
43
+ /** True for `aria-*`, `data-*` and the enumerated attributes: their boolean values are strings. */
44
+ function isStringValued(lowerName) {
45
+ return lowerName.startsWith("aria-") || lowerName.startsWith("data-") || ENUMERATED_ATTRIBUTES.has(lowerName);
46
+ }
47
+ /** Removes C0 and C1 control characters. Written as a loop so no control character appears in a regex. */
48
+ function stripControls(text) {
49
+ let kept = "";
50
+ for (const char of text) {
51
+ const code = char.charCodeAt(0);
52
+ if (code > 31 && (code < 127 || code > 159)) kept += char;
53
+ }
54
+ return kept;
55
+ }
56
+ /** True when the URL would run script: browsers ignore the controls and case that hide the scheme. */
57
+ function isUnsafeUrl(value) {
58
+ const normalized = stripControls(value).trim().toLowerCase();
59
+ return UNSAFE_URL_PREFIXES.some((prefix) => normalized.startsWith(prefix));
60
+ }
61
+ /**
62
+ * Reports whether writing `value` to the attribute `name` would run script: the URL check that
63
+ * {@link setAttribute}, the head registry and the server renderer share. Use it in a custom renderer
64
+ * before writing a URL that came from user data. URL attributes (`href`, `src`, `action`,
65
+ * `formaction`, `xlink:href`, `srcdoc`, `poster`, `data`) are unsafe when, after removing control
66
+ * characters, trimming and lowercasing, they start with `javascript:`, `data:text/html` or
67
+ * `vbscript:`. The SVG animation attributes `values`, `from`, `to` and `by` are checked the same way,
68
+ * each `;`-separated entry of `values` on its own.
69
+ *
70
+ * @param name Attribute name, in any case.
71
+ * @param value The text that would be written.
72
+ * @returns `true` when the value must not be written; `false` for every other attribute or value.
73
+ * @example
74
+ * import { isUnsafeUrlAttribute } from "@shadow-js/web/extend";
75
+ *
76
+ * isUnsafeUrlAttribute("href", " JavaScript:alert(1)"); // true
77
+ * isUnsafeUrlAttribute("href", "https://example.com"); // false
78
+ * isUnsafeUrlAttribute("title", "javascript:alert(1)"); // false: not a URL attribute
79
+ * @see setAttribute
80
+ * @since 1.0.0
81
+ */
82
+ function isUnsafeUrlAttribute(name, value) {
83
+ const lowerName = name.toLowerCase();
84
+ if (!URL_ATTRIBUTES.has(lowerName)) return false;
85
+ return lowerName === "values" ? value.split(";").some(isUnsafeUrl) : isUnsafeUrl(value);
86
+ }
87
+ /** Text to write for `value`, or null when the attribute must be removed. */
88
+ function attributeText(lowerName, value) {
89
+ if (value === null || value === void 0) return null;
90
+ if (value === false) return isStringValued(lowerName) ? "false" : null;
91
+ if (value === true) return isStringValued(lowerName) ? "true" : "";
92
+ return String(value);
93
+ }
94
+ /** The part of a qualified name after the prefix (`xlink:href` gives `href`). */
95
+ function localPart(qualified) {
96
+ const colon = qualified.indexOf(":");
97
+ return colon === -1 ? qualified : qualified.slice(colon + 1);
98
+ }
99
+ /** Writes or removes one attribute, applying the value rules and the URL check. */
100
+ function commit(el, namespace, qualified, value) {
101
+ const lowerName = qualified.toLowerCase();
102
+ const text = attributeText(lowerName, value);
103
+ if (text === null) {
104
+ if (namespace === null) el.removeAttribute(qualified);
105
+ else el.removeAttributeNS(namespace, localPart(qualified));
106
+ return;
107
+ }
108
+ if (isUnsafeUrlAttribute(lowerName, text)) {
109
+ warnOnce("UNSAFE_URL_BLOCKED", `Blocked a script URL in the "${qualified}" attribute.`);
110
+ return;
111
+ }
112
+ if (namespace === null) {
113
+ if (el.getAttribute(qualified) !== text) el.setAttribute(qualified, text);
114
+ } else if (el.getAttributeNS(namespace, localPart(qualified)) !== text) el.setAttributeNS(namespace, qualified, text);
115
+ }
116
+ /**
117
+ * Sets or removes one attribute with the JSX value rules: the helper compiled templates call for a
118
+ * dynamic attribute, also usable on elements you create yourself. The DOM is touched only when the
119
+ * text changes. A URL attribute whose value would run script (see {@link isUnsafeUrlAttribute}) is
120
+ * left unchanged, and development builds warn once with `UNSAFE_URL_BLOCKED`.
121
+ *
122
+ * @param el Target element.
123
+ * @param name Attribute name. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.
124
+ * @param value `null`, `undefined` and `false` remove the attribute, except that `false` writes
125
+ * `"false"` for `aria-*`, `data-*`, `draggable`, `spellcheck` and `contenteditable`. `true` writes
126
+ * `""` (or `"true"` for those same names). Any other value is written as `String(value)`.
127
+ * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.
128
+ * @example
129
+ * import { setAttribute } from "@shadow-js/web";
130
+ *
131
+ * const link = document.createElement("a");
132
+ * setAttribute(link, "href", "https://example.com");
133
+ * setAttribute(link, "aria-hidden", false); // aria-hidden="false"
134
+ * setAttribute(link, "title", null); // removes title
135
+ * @see setBoolAttribute
136
+ * @see setAttributeNS
137
+ * @since 1.0.0
138
+ */
139
+ function setAttribute(el, name, value) {
140
+ assertAttributeName(name);
141
+ commit(el, null, name, value);
142
+ }
143
+ /**
144
+ * Sets or removes a namespaced attribute such as `xlink:href` or `xml:lang`, with the value rules
145
+ * and the URL check of {@link setAttribute}. Removal uses the local part of the name (`href` for
146
+ * `xlink:href`).
147
+ *
148
+ * @param el Target element.
149
+ * @param namespace Namespace URI. `""` means no namespace, which behaves exactly like
150
+ * {@link setAttribute}.
151
+ * @param name Qualified name (`prefix:local`). It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.
152
+ * @param value The value, with the same rules as {@link setAttribute}.
153
+ * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.
154
+ * @example
155
+ * import { setAttributeNS } from "@shadow-js/web";
156
+ *
157
+ * const XLINK = "http://www.w3.org/1999/xlink";
158
+ * const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
159
+ * setAttributeNS(use, XLINK, "xlink:href", "#icon-star");
160
+ * setAttributeNS(use, XLINK, "xlink:href", null); // removes it
161
+ * @see setAttribute
162
+ * @since 1.0.0
163
+ */
164
+ function setAttributeNS(el, namespace, name, value) {
165
+ assertAttributeName(name);
166
+ commit(el, namespace === "" ? null : namespace, name, value);
167
+ }
168
+ /**
169
+ * Sets or removes a presence (boolean) attribute such as `disabled` or `hidden`: the helper compiled
170
+ * templates call for the `bool:` prefix. A truthy value sets the attribute to `""`, a falsy value
171
+ * removes it; the DOM is touched only when presence changes. No URL check applies.
172
+ *
173
+ * @param el Target element.
174
+ * @param name Attribute name, such as `disabled`. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.
175
+ * @param value Any value: only its truthiness is read.
176
+ * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.
177
+ * @example
178
+ * import { setBoolAttribute } from "@shadow-js/web";
179
+ *
180
+ * const button = document.createElement("button");
181
+ * setBoolAttribute(button, "disabled", true); // disabled=""
182
+ * setBoolAttribute(button, "disabled", 0); // removed
183
+ * @see setAttribute
184
+ * @since 1.0.0
185
+ */
186
+ function setBoolAttribute(el, name, value) {
187
+ assertAttributeName(name);
188
+ const present = el.hasAttribute(name);
189
+ if (value) {
190
+ if (!present) el.setAttribute(name, "");
191
+ } else if (present) el.removeAttribute(name);
192
+ }
193
+ //#endregion
194
+ export { assertAttributeName, isUnsafeUrlAttribute, setAttribute, setAttributeNS, setBoolAttribute };
195
+
196
+ //# sourceMappingURL=attributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.js","names":[],"sources":["../../src/attributes.ts"],"sourcesContent":["import { invalidAttributeName, warnOnce } from \"./internal/diagnostics\";\n\n/** Names that can appear in markup: an XML-name subset without `@` or whitespace. */\nconst ATTRIBUTE_NAME = /^[A-Za-z_:][A-Za-z0-9_:.-]*$/;\n\n/**\n * Attributes whose value is a URL and therefore checked for script schemes. The SVG animation values\n * (`animate`, `set`) are checked too: with `attributeName=\"href\"` they write an `href` by animation.\n */\nconst URL_ATTRIBUTES = new Set([\n \"href\",\n \"src\",\n \"action\",\n \"formaction\",\n \"xlink:href\",\n \"srcdoc\",\n \"poster\",\n \"data\",\n \"values\",\n \"from\",\n \"to\",\n \"by\",\n]);\n\n/** Enumerated attributes where `false` is a real value (\"false\") rather than an absence. */\nconst ENUMERATED_ATTRIBUTES = new Set([\"draggable\", \"spellcheck\", \"contenteditable\"]);\n\n/** URL prefixes (after normalization) that are never written. */\nconst UNSAFE_URL_PREFIXES = [\"javascript:\", \"data:text/html\", \"vbscript:\"];\n\n/**\n * Throws a TypeError unless `name` is a valid attribute name. Runs for every name, including the\n * ones that come from spread, so no unvalidated name reaches `setAttribute`.\n * @internal\n */\nexport function assertAttributeName(name: string): void {\n if (!ATTRIBUTE_NAME.test(name)) throw invalidAttributeName(name);\n}\n\n/** True for `aria-*`, `data-*` and the enumerated attributes: their boolean values are strings. */\nfunction isStringValued(lowerName: string): boolean {\n return (\n lowerName.startsWith(\"aria-\") ||\n lowerName.startsWith(\"data-\") ||\n ENUMERATED_ATTRIBUTES.has(lowerName)\n );\n}\n\n/** Removes C0 and C1 control characters. Written as a loop so no control character appears in a regex. */\nfunction stripControls(text: string): string {\n let kept = \"\";\n for (const char of text) {\n const code = char.charCodeAt(0);\n if (code > 0x1f && (code < 0x7f || code > 0x9f)) kept += char;\n }\n return kept;\n}\n\n/** True when the URL would run script: browsers ignore the controls and case that hide the scheme. */\nfunction isUnsafeUrl(value: string): boolean {\n const normalized = stripControls(value).trim().toLowerCase();\n return UNSAFE_URL_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n\n/**\n * Reports whether writing `value` to the attribute `name` would run script: the URL check that\n * {@link setAttribute}, the head registry and the server renderer share. Use it in a custom renderer\n * before writing a URL that came from user data. URL attributes (`href`, `src`, `action`,\n * `formaction`, `xlink:href`, `srcdoc`, `poster`, `data`) are unsafe when, after removing control\n * characters, trimming and lowercasing, they start with `javascript:`, `data:text/html` or\n * `vbscript:`. The SVG animation attributes `values`, `from`, `to` and `by` are checked the same way,\n * each `;`-separated entry of `values` on its own.\n *\n * @param name Attribute name, in any case.\n * @param value The text that would be written.\n * @returns `true` when the value must not be written; `false` for every other attribute or value.\n * @example\n * import { isUnsafeUrlAttribute } from \"@shadow-js/web/extend\";\n *\n * isUnsafeUrlAttribute(\"href\", \" JavaScript:alert(1)\"); // true\n * isUnsafeUrlAttribute(\"href\", \"https://example.com\"); // false\n * isUnsafeUrlAttribute(\"title\", \"javascript:alert(1)\"); // false: not a URL attribute\n * @see setAttribute\n * @since 1.0.0\n */\nexport function isUnsafeUrlAttribute(name: string, value: string): boolean {\n const lowerName = name.toLowerCase();\n if (!URL_ATTRIBUTES.has(lowerName)) return false;\n // `values` is a `;` list: every entry is a URL of its own.\n return lowerName === \"values\" ? value.split(\";\").some(isUnsafeUrl) : isUnsafeUrl(value);\n}\n\n/** Text to write for `value`, or null when the attribute must be removed. */\nfunction attributeText(lowerName: string, value: unknown): string | null {\n if (value === null || value === undefined) return null;\n if (value === false) return isStringValued(lowerName) ? \"false\" : null;\n if (value === true) return isStringValued(lowerName) ? \"true\" : \"\";\n return String(value);\n}\n\n/** The part of a qualified name after the prefix (`xlink:href` gives `href`). */\nfunction localPart(qualified: string): string {\n const colon = qualified.indexOf(\":\");\n return colon === -1 ? qualified : qualified.slice(colon + 1);\n}\n\n/** Writes or removes one attribute, applying the value rules and the URL check. */\nfunction commit(el: Element, namespace: string | null, qualified: string, value: unknown): void {\n const lowerName = qualified.toLowerCase();\n const text = attributeText(lowerName, value);\n if (text === null) {\n if (namespace === null) el.removeAttribute(qualified);\n else el.removeAttributeNS(namespace, localPart(qualified));\n return;\n }\n if (isUnsafeUrlAttribute(lowerName, text)) {\n warnOnce(\"UNSAFE_URL_BLOCKED\", `Blocked a script URL in the \"${qualified}\" attribute.`);\n return;\n }\n if (namespace === null) {\n if (el.getAttribute(qualified) !== text) el.setAttribute(qualified, text);\n } else if (el.getAttributeNS(namespace, localPart(qualified)) !== text) {\n el.setAttributeNS(namespace, qualified, text);\n }\n}\n\n/**\n * Sets or removes one attribute with the JSX value rules: the helper compiled templates call for a\n * dynamic attribute, also usable on elements you create yourself. The DOM is touched only when the\n * text changes. A URL attribute whose value would run script (see {@link isUnsafeUrlAttribute}) is\n * left unchanged, and development builds warn once with `UNSAFE_URL_BLOCKED`.\n *\n * @param el Target element.\n * @param name Attribute name. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.\n * @param value `null`, `undefined` and `false` remove the attribute, except that `false` writes\n * `\"false\"` for `aria-*`, `data-*`, `draggable`, `spellcheck` and `contenteditable`. `true` writes\n * `\"\"` (or `\"true\"` for those same names). Any other value is written as `String(value)`.\n * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.\n * @example\n * import { setAttribute } from \"@shadow-js/web\";\n *\n * const link = document.createElement(\"a\");\n * setAttribute(link, \"href\", \"https://example.com\");\n * setAttribute(link, \"aria-hidden\", false); // aria-hidden=\"false\"\n * setAttribute(link, \"title\", null); // removes title\n * @see setBoolAttribute\n * @see setAttributeNS\n * @since 1.0.0\n */\nexport function setAttribute(el: Element, name: string, value: unknown): void {\n assertAttributeName(name);\n commit(el, null, name, value);\n}\n\n/**\n * Sets or removes a namespaced attribute such as `xlink:href` or `xml:lang`, with the value rules\n * and the URL check of {@link setAttribute}. Removal uses the local part of the name (`href` for\n * `xlink:href`).\n *\n * @param el Target element.\n * @param namespace Namespace URI. `\"\"` means no namespace, which behaves exactly like\n * {@link setAttribute}.\n * @param name Qualified name (`prefix:local`). It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.\n * @param value The value, with the same rules as {@link setAttribute}.\n * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.\n * @example\n * import { setAttributeNS } from \"@shadow-js/web\";\n *\n * const XLINK = \"http://www.w3.org/1999/xlink\";\n * const use = document.createElementNS(\"http://www.w3.org/2000/svg\", \"use\");\n * setAttributeNS(use, XLINK, \"xlink:href\", \"#icon-star\");\n * setAttributeNS(use, XLINK, \"xlink:href\", null); // removes it\n * @see setAttribute\n * @since 1.0.0\n */\nexport function setAttributeNS(el: Element, namespace: string, name: string, value: unknown): void {\n assertAttributeName(name);\n commit(el, namespace === \"\" ? null : namespace, name, value);\n}\n\n/**\n * Sets or removes a presence (boolean) attribute such as `disabled` or `hidden`: the helper compiled\n * templates call for the `bool:` prefix. A truthy value sets the attribute to `\"\"`, a falsy value\n * removes it; the DOM is touched only when presence changes. No URL check applies.\n *\n * @param el Target element.\n * @param name Attribute name, such as `disabled`. It must match `[A-Za-z_:][A-Za-z0-9_:.-]*`.\n * @param value Any value: only its truthiness is read.\n * @throws TypeError `INVALID_ATTRIBUTE_NAME` when `name` is not a valid attribute name.\n * @example\n * import { setBoolAttribute } from \"@shadow-js/web\";\n *\n * const button = document.createElement(\"button\");\n * setBoolAttribute(button, \"disabled\", true); // disabled=\"\"\n * setBoolAttribute(button, \"disabled\", 0); // removed\n * @see setAttribute\n * @since 1.0.0\n */\nexport function setBoolAttribute(el: Element, name: string, value: unknown): void {\n assertAttributeName(name);\n const present = el.hasAttribute(name);\n if (value) {\n if (!present) el.setAttribute(name, \"\");\n } else if (present) {\n el.removeAttribute(name);\n }\n}\n"],"mappings":";;;AAGA,MAAM,iBAAiB;;;;;AAMvB,MAAM,iCAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,MAAM,wCAAwB,IAAI,IAAI;CAAC;CAAa;CAAc;AAAiB,CAAC;;AAGpF,MAAM,sBAAsB;CAAC;CAAe;CAAkB;AAAW;;;;;;AAOzE,SAAgB,oBAAoB,MAAoB;CACtD,IAAI,CAAC,eAAe,KAAK,IAAI,GAAG,MAAM,qBAAqB,IAAI;AACjE;;AAGA,SAAS,eAAe,WAA4B;CAClD,OACE,UAAU,WAAW,OAAO,KAC5B,UAAU,WAAW,OAAO,KAC5B,sBAAsB,IAAI,SAAS;AAEvC;;AAGA,SAAS,cAAc,MAAsB;CAC3C,IAAI,OAAO;CACX,KAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,OAAO,KAAK,WAAW,CAAC;EAC9B,IAAI,OAAO,OAAS,OAAO,OAAQ,OAAO,MAAO,QAAQ;CAC3D;CACA,OAAO;AACT;;AAGA,SAAS,YAAY,OAAwB;CAC3C,MAAM,aAAa,cAAc,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,YAAY;CAC3D,OAAO,oBAAoB,MAAM,WAAW,WAAW,WAAW,MAAM,CAAC;AAC3E;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,qBAAqB,MAAc,OAAwB;CACzE,MAAM,YAAY,KAAK,YAAY;CACnC,IAAI,CAAC,eAAe,IAAI,SAAS,GAAG,OAAO;CAE3C,OAAO,cAAc,WAAW,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,WAAW,IAAI,YAAY,KAAK;AACxF;;AAGA,SAAS,cAAc,WAAmB,OAA+B;CACvE,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;CAClD,IAAI,UAAU,OAAO,OAAO,eAAe,SAAS,IAAI,UAAU;CAClE,IAAI,UAAU,MAAM,OAAO,eAAe,SAAS,IAAI,SAAS;CAChE,OAAO,OAAO,KAAK;AACrB;;AAGA,SAAS,UAAU,WAA2B;CAC5C,MAAM,QAAQ,UAAU,QAAQ,GAAG;CACnC,OAAO,UAAU,KAAK,YAAY,UAAU,MAAM,QAAQ,CAAC;AAC7D;;AAGA,SAAS,OAAO,IAAa,WAA0B,WAAmB,OAAsB;CAC9F,MAAM,YAAY,UAAU,YAAY;CACxC,MAAM,OAAO,cAAc,WAAW,KAAK;CAC3C,IAAI,SAAS,MAAM;EACjB,IAAI,cAAc,MAAM,GAAG,gBAAgB,SAAS;OAC/C,GAAG,kBAAkB,WAAW,UAAU,SAAS,CAAC;EACzD;CACF;CACA,IAAI,qBAAqB,WAAW,IAAI,GAAG;EACzC,SAAS,sBAAsB,gCAAgC,UAAU,aAAa;EACtF;CACF;CACA,IAAI,cAAc,MACZ;MAAA,GAAG,aAAa,SAAS,MAAM,MAAM,GAAG,aAAa,WAAW,IAAI;CAAA,OACnE,IAAI,GAAG,eAAe,WAAW,UAAU,SAAS,CAAC,MAAM,MAChE,GAAG,eAAe,WAAW,WAAW,IAAI;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,aAAa,IAAa,MAAc,OAAsB;CAC5E,oBAAoB,IAAI;CACxB,OAAO,IAAI,MAAM,MAAM,KAAK;AAC9B;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,eAAe,IAAa,WAAmB,MAAc,OAAsB;CACjG,oBAAoB,IAAI;CACxB,OAAO,IAAI,cAAc,KAAK,OAAO,WAAW,MAAM,KAAK;AAC7D;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,iBAAiB,IAAa,MAAc,OAAsB;CAChF,oBAAoB,IAAI;CACxB,MAAM,UAAU,GAAG,aAAa,IAAI;CACpC,IAAI,OACE;MAAA,CAAC,SAAS,GAAG,aAAa,MAAM,EAAE;CAAA,OACjC,IAAI,SACT,GAAG,gBAAgB,IAAI;AAE3B"}
@@ -0,0 +1,32 @@
1
+ //#region src/autofocus.d.ts
2
+ /**
3
+ * Focuses an element written with `autoFocus` (React parity) once it is inserted into the document
4
+ * by a client render or update. The compiler calls this for an `autoFocus` attribute and for
5
+ * `autoFocus` keys of a spread, so an app that never uses `autoFocus` never reaches this code. Call it
6
+ * yourself only for elements you create by hand, inside an owner (a component or a root): the focus
7
+ * is requested with `onMount`, so development builds warn with `NO_OWNER_EFFECT` without one.
8
+ *
9
+ * The rules, which match React's for `autoFocus`:
10
+ * - Once per element: the focus is requested when the element is created, after the owner has been
11
+ * flushed. Moving the element later (a keyed reorder) does not focus it again.
12
+ * - An element that is not connected when its owner flushes (a detached root) is not focused.
13
+ * - During hydration the server markup already carries `autofocus`, so the element focuses only when
14
+ * nothing else has the focus (the document's active element is the body or null). A user's focus
15
+ * is never taken away by hydration.
16
+ *
17
+ * @param el The element. Only `HTMLElement` and `SVGElement` are focused; for any other element, and
18
+ * for one that cannot take focus, the call does nothing.
19
+ * @param enabled The `autoFocus` value: falsy values (`false`, `undefined`, `""`, `0`) do nothing.
20
+ * @example
21
+ * import { autoFocus, render } from "@shadow-js/web";
22
+ *
23
+ * render(() => {
24
+ * const input = document.createElement("input");
25
+ * autoFocus(input, true); // focused once the root has mounted it
26
+ * return input;
27
+ * }, document.body);
28
+ * @since 1.0.0
29
+ */
30
+ export declare function autoFocus(el: Element, enabled: unknown): void;
31
+ //#endregion
32
+ //# sourceMappingURL=autofocus.d.ts.map
@@ -0,0 +1,45 @@
1
+ import { onMount } from "@shadow-js/core";
2
+ import { isHydrating } from "@shadow-js/core/extend";
3
+ //#region src/autofocus.ts
4
+ /**
5
+ * Focuses an element written with `autoFocus` (React parity) once it is inserted into the document
6
+ * by a client render or update. The compiler calls this for an `autoFocus` attribute and for
7
+ * `autoFocus` keys of a spread, so an app that never uses `autoFocus` never reaches this code. Call it
8
+ * yourself only for elements you create by hand, inside an owner (a component or a root): the focus
9
+ * is requested with `onMount`, so development builds warn with `NO_OWNER_EFFECT` without one.
10
+ *
11
+ * The rules, which match React's for `autoFocus`:
12
+ * - Once per element: the focus is requested when the element is created, after the owner has been
13
+ * flushed. Moving the element later (a keyed reorder) does not focus it again.
14
+ * - An element that is not connected when its owner flushes (a detached root) is not focused.
15
+ * - During hydration the server markup already carries `autofocus`, so the element focuses only when
16
+ * nothing else has the focus (the document's active element is the body or null). A user's focus
17
+ * is never taken away by hydration.
18
+ *
19
+ * @param el The element. Only `HTMLElement` and `SVGElement` are focused; for any other element, and
20
+ * for one that cannot take focus, the call does nothing.
21
+ * @param enabled The `autoFocus` value: falsy values (`false`, `undefined`, `""`, `0`) do nothing.
22
+ * @example
23
+ * import { autoFocus, render } from "@shadow-js/web";
24
+ *
25
+ * render(() => {
26
+ * const input = document.createElement("input");
27
+ * autoFocus(input, true); // focused once the root has mounted it
28
+ * return input;
29
+ * }, document.body);
30
+ * @since 1.0.0
31
+ */
32
+ function autoFocus(el, enabled) {
33
+ if (!enabled) return;
34
+ const hydrating = isHydrating();
35
+ onMount(() => {
36
+ const doc = el.ownerDocument;
37
+ const active = doc.activeElement;
38
+ const free = !hydrating || active === null || active === doc.body;
39
+ if (el.isConnected && free && (el instanceof HTMLElement || el instanceof SVGElement)) el.focus();
40
+ });
41
+ }
42
+ //#endregion
43
+ export { autoFocus };
44
+
45
+ //# sourceMappingURL=autofocus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autofocus.js","names":[],"sources":["../../src/autofocus.ts"],"sourcesContent":["import { onMount } from \"@shadow-js/core\";\nimport { isHydrating } from \"@shadow-js/core/extend\";\n\n/**\n * Focuses an element written with `autoFocus` (React parity) once it is inserted into the document\n * by a client render or update. The compiler calls this for an `autoFocus` attribute and for\n * `autoFocus` keys of a spread, so an app that never uses `autoFocus` never reaches this code. Call it\n * yourself only for elements you create by hand, inside an owner (a component or a root): the focus\n * is requested with `onMount`, so development builds warn with `NO_OWNER_EFFECT` without one.\n *\n * The rules, which match React's for `autoFocus`:\n * - Once per element: the focus is requested when the element is created, after the owner has been\n * flushed. Moving the element later (a keyed reorder) does not focus it again.\n * - An element that is not connected when its owner flushes (a detached root) is not focused.\n * - During hydration the server markup already carries `autofocus`, so the element focuses only when\n * nothing else has the focus (the document's active element is the body or null). A user's focus\n * is never taken away by hydration.\n *\n * @param el The element. Only `HTMLElement` and `SVGElement` are focused; for any other element, and\n * for one that cannot take focus, the call does nothing.\n * @param enabled The `autoFocus` value: falsy values (`false`, `undefined`, `\"\"`, `0`) do nothing.\n * @example\n * import { autoFocus, render } from \"@shadow-js/web\";\n *\n * render(() => {\n * const input = document.createElement(\"input\");\n * autoFocus(input, true); // focused once the root has mounted it\n * return input;\n * }, document.body);\n * @since 1.0.0\n */\nexport function autoFocus(el: Element, enabled: unknown): void {\n if (!enabled) return;\n const hydrating = isHydrating();\n onMount(() => {\n const doc = el.ownerDocument;\n const active = doc.activeElement;\n // Hydration focuses only when nothing has the focus: the body or no element.\n const free = !hydrating || active === null || active === doc.body;\n if (el.isConnected && free && (el instanceof HTMLElement || el instanceof SVGElement)) {\n el.focus();\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,UAAU,IAAa,SAAwB;CAC7D,IAAI,CAAC,SAAS;CACd,MAAM,YAAY,YAAY;CAC9B,cAAc;EACZ,MAAM,MAAM,GAAG;EACf,MAAM,SAAS,IAAI;EAEnB,MAAM,OAAO,CAAC,aAAa,WAAW,QAAQ,WAAW,IAAI;EAC7D,IAAI,GAAG,eAAe,SAAS,cAAc,eAAe,cAAc,aACxE,GAAG,MAAM;CAEb,CAAC;AACH"}