@depup/svelte 5.53.3-depup.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 (386) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +41 -0
  3. package/action.d.ts +1 -0
  4. package/animate.d.ts +1 -0
  5. package/compiler/index.js +1 -0
  6. package/compiler/package.json +3 -0
  7. package/compiler.d.ts +1 -0
  8. package/easing.d.ts +1 -0
  9. package/elements.d.ts +2078 -0
  10. package/index.d.ts +1 -0
  11. package/legacy.d.ts +1 -0
  12. package/motion.d.ts +1 -0
  13. package/package.json +185 -0
  14. package/src/animate/index.js +78 -0
  15. package/src/attachments/index.js +113 -0
  16. package/src/compiler/errors.js +1719 -0
  17. package/src/compiler/index.js +198 -0
  18. package/src/compiler/legacy.js +637 -0
  19. package/src/compiler/migrate/index.js +1996 -0
  20. package/src/compiler/phases/1-parse/acorn.js +198 -0
  21. package/src/compiler/phases/1-parse/index.js +326 -0
  22. package/src/compiler/phases/1-parse/read/context.js +116 -0
  23. package/src/compiler/phases/1-parse/read/expression.js +93 -0
  24. package/src/compiler/phases/1-parse/read/options.js +263 -0
  25. package/src/compiler/phases/1-parse/read/script.js +97 -0
  26. package/src/compiler/phases/1-parse/read/style.js +637 -0
  27. package/src/compiler/phases/1-parse/remove_typescript_nodes.js +180 -0
  28. package/src/compiler/phases/1-parse/state/element.js +937 -0
  29. package/src/compiler/phases/1-parse/state/fragment.js +17 -0
  30. package/src/compiler/phases/1-parse/state/tag.js +751 -0
  31. package/src/compiler/phases/1-parse/state/text.js +23 -0
  32. package/src/compiler/phases/1-parse/utils/bracket.js +213 -0
  33. package/src/compiler/phases/1-parse/utils/create.js +16 -0
  34. package/src/compiler/phases/1-parse/utils/entities.js +2234 -0
  35. package/src/compiler/phases/1-parse/utils/fuzzymatch.js +281 -0
  36. package/src/compiler/phases/1-parse/utils/html.js +127 -0
  37. package/src/compiler/phases/2-analyze/css/css-analyze.js +331 -0
  38. package/src/compiler/phases/2-analyze/css/css-prune.js +1206 -0
  39. package/src/compiler/phases/2-analyze/css/css-warn.js +47 -0
  40. package/src/compiler/phases/2-analyze/css/utils.js +177 -0
  41. package/src/compiler/phases/2-analyze/index.js +1300 -0
  42. package/src/compiler/phases/2-analyze/utils/check_graph_for_cycles.js +47 -0
  43. package/src/compiler/phases/2-analyze/visitors/AnimateDirective.js +15 -0
  44. package/src/compiler/phases/2-analyze/visitors/ArrowFunctionExpression.js +11 -0
  45. package/src/compiler/phases/2-analyze/visitors/AssignmentExpression.js +31 -0
  46. package/src/compiler/phases/2-analyze/visitors/AttachTag.js +17 -0
  47. package/src/compiler/phases/2-analyze/visitors/Attribute.js +66 -0
  48. package/src/compiler/phases/2-analyze/visitors/AwaitBlock.js +48 -0
  49. package/src/compiler/phases/2-analyze/visitors/AwaitExpression.js +150 -0
  50. package/src/compiler/phases/2-analyze/visitors/BindDirective.js +280 -0
  51. package/src/compiler/phases/2-analyze/visitors/CallExpression.js +339 -0
  52. package/src/compiler/phases/2-analyze/visitors/ClassBody.js +156 -0
  53. package/src/compiler/phases/2-analyze/visitors/ClassDeclaration.js +25 -0
  54. package/src/compiler/phases/2-analyze/visitors/ClassDirective.js +13 -0
  55. package/src/compiler/phases/2-analyze/visitors/Component.js +26 -0
  56. package/src/compiler/phases/2-analyze/visitors/ConstTag.js +45 -0
  57. package/src/compiler/phases/2-analyze/visitors/DebugTag.js +15 -0
  58. package/src/compiler/phases/2-analyze/visitors/EachBlock.js +97 -0
  59. package/src/compiler/phases/2-analyze/visitors/ExportDefaultDeclaration.js +20 -0
  60. package/src/compiler/phases/2-analyze/visitors/ExportNamedDeclaration.js +70 -0
  61. package/src/compiler/phases/2-analyze/visitors/ExportSpecifier.js +30 -0
  62. package/src/compiler/phases/2-analyze/visitors/ExpressionStatement.js +38 -0
  63. package/src/compiler/phases/2-analyze/visitors/ExpressionTag.js +26 -0
  64. package/src/compiler/phases/2-analyze/visitors/Fragment.js +10 -0
  65. package/src/compiler/phases/2-analyze/visitors/FunctionDeclaration.js +16 -0
  66. package/src/compiler/phases/2-analyze/visitors/FunctionExpression.js +11 -0
  67. package/src/compiler/phases/2-analyze/visitors/HtmlTag.js +19 -0
  68. package/src/compiler/phases/2-analyze/visitors/Identifier.js +194 -0
  69. package/src/compiler/phases/2-analyze/visitors/IfBlock.js +46 -0
  70. package/src/compiler/phases/2-analyze/visitors/ImportDeclaration.js +31 -0
  71. package/src/compiler/phases/2-analyze/visitors/KeyBlock.js +21 -0
  72. package/src/compiler/phases/2-analyze/visitors/LabeledStatement.js +95 -0
  73. package/src/compiler/phases/2-analyze/visitors/LetDirective.js +24 -0
  74. package/src/compiler/phases/2-analyze/visitors/Literal.js +14 -0
  75. package/src/compiler/phases/2-analyze/visitors/MemberExpression.js +28 -0
  76. package/src/compiler/phases/2-analyze/visitors/NewExpression.js +17 -0
  77. package/src/compiler/phases/2-analyze/visitors/OnDirective.js +28 -0
  78. package/src/compiler/phases/2-analyze/visitors/PropertyDefinition.js +21 -0
  79. package/src/compiler/phases/2-analyze/visitors/RegularElement.js +240 -0
  80. package/src/compiler/phases/2-analyze/visitors/RenderTag.js +68 -0
  81. package/src/compiler/phases/2-analyze/visitors/SlotElement.js +42 -0
  82. package/src/compiler/phases/2-analyze/visitors/SnippetBlock.js +113 -0
  83. package/src/compiler/phases/2-analyze/visitors/SpreadAttribute.js +13 -0
  84. package/src/compiler/phases/2-analyze/visitors/SpreadElement.js +16 -0
  85. package/src/compiler/phases/2-analyze/visitors/StyleDirective.js +39 -0
  86. package/src/compiler/phases/2-analyze/visitors/SvelteBody.js +22 -0
  87. package/src/compiler/phases/2-analyze/visitors/SvelteBoundary.js +30 -0
  88. package/src/compiler/phases/2-analyze/visitors/SvelteComponent.js +18 -0
  89. package/src/compiler/phases/2-analyze/visitors/SvelteDocument.js +24 -0
  90. package/src/compiler/phases/2-analyze/visitors/SvelteElement.js +78 -0
  91. package/src/compiler/phases/2-analyze/visitors/SvelteFragment.js +27 -0
  92. package/src/compiler/phases/2-analyze/visitors/SvelteHead.js +18 -0
  93. package/src/compiler/phases/2-analyze/visitors/SvelteSelf.js +36 -0
  94. package/src/compiler/phases/2-analyze/visitors/SvelteWindow.js +24 -0
  95. package/src/compiler/phases/2-analyze/visitors/TaggedTemplateExpression.js +16 -0
  96. package/src/compiler/phases/2-analyze/visitors/TemplateElement.js +12 -0
  97. package/src/compiler/phases/2-analyze/visitors/Text.js +52 -0
  98. package/src/compiler/phases/2-analyze/visitors/TitleElement.js +21 -0
  99. package/src/compiler/phases/2-analyze/visitors/TransitionDirective.js +19 -0
  100. package/src/compiler/phases/2-analyze/visitors/UpdateExpression.js +29 -0
  101. package/src/compiler/phases/2-analyze/visitors/UseDirective.js +18 -0
  102. package/src/compiler/phases/2-analyze/visitors/VariableDeclarator.js +160 -0
  103. package/src/compiler/phases/2-analyze/visitors/shared/a11y/constants.js +334 -0
  104. package/src/compiler/phases/2-analyze/visitors/shared/a11y/index.js +981 -0
  105. package/src/compiler/phases/2-analyze/visitors/shared/attribute.js +125 -0
  106. package/src/compiler/phases/2-analyze/visitors/shared/component.js +177 -0
  107. package/src/compiler/phases/2-analyze/visitors/shared/element.js +160 -0
  108. package/src/compiler/phases/2-analyze/visitors/shared/fragment.js +15 -0
  109. package/src/compiler/phases/2-analyze/visitors/shared/function.js +24 -0
  110. package/src/compiler/phases/2-analyze/visitors/shared/snippets.js +17 -0
  111. package/src/compiler/phases/2-analyze/visitors/shared/special-element.js +16 -0
  112. package/src/compiler/phases/2-analyze/visitors/shared/utils.js +301 -0
  113. package/src/compiler/phases/3-transform/client/transform-client.js +719 -0
  114. package/src/compiler/phases/3-transform/client/transform-template/fix-attribute-casing.js +18 -0
  115. package/src/compiler/phases/3-transform/client/transform-template/index.js +67 -0
  116. package/src/compiler/phases/3-transform/client/transform-template/template.js +164 -0
  117. package/src/compiler/phases/3-transform/client/utils.js +181 -0
  118. package/src/compiler/phases/3-transform/client/visitors/AnimateDirective.js +38 -0
  119. package/src/compiler/phases/3-transform/client/visitors/ArrowFunctionExpression.js +11 -0
  120. package/src/compiler/phases/3-transform/client/visitors/AssignmentExpression.js +247 -0
  121. package/src/compiler/phases/3-transform/client/visitors/AttachTag.js +26 -0
  122. package/src/compiler/phases/3-transform/client/visitors/Attribute.js +14 -0
  123. package/src/compiler/phases/3-transform/client/visitors/AwaitBlock.js +124 -0
  124. package/src/compiler/phases/3-transform/client/visitors/AwaitExpression.js +25 -0
  125. package/src/compiler/phases/3-transform/client/visitors/BinaryExpression.js +34 -0
  126. package/src/compiler/phases/3-transform/client/visitors/BindDirective.js +290 -0
  127. package/src/compiler/phases/3-transform/client/visitors/BlockStatement.js +32 -0
  128. package/src/compiler/phases/3-transform/client/visitors/BreakStatement.js +20 -0
  129. package/src/compiler/phases/3-transform/client/visitors/CallExpression.js +136 -0
  130. package/src/compiler/phases/3-transform/client/visitors/ClassBody.js +111 -0
  131. package/src/compiler/phases/3-transform/client/visitors/Comment.js +11 -0
  132. package/src/compiler/phases/3-transform/client/visitors/Component.js +12 -0
  133. package/src/compiler/phases/3-transform/client/visitors/ConstTag.js +134 -0
  134. package/src/compiler/phases/3-transform/client/visitors/DebugTag.js +28 -0
  135. package/src/compiler/phases/3-transform/client/visitors/EachBlock.js +362 -0
  136. package/src/compiler/phases/3-transform/client/visitors/ExportNamedDeclaration.js +19 -0
  137. package/src/compiler/phases/3-transform/client/visitors/ExpressionStatement.js +20 -0
  138. package/src/compiler/phases/3-transform/client/visitors/ForOfStatement.js +25 -0
  139. package/src/compiler/phases/3-transform/client/visitors/Fragment.js +186 -0
  140. package/src/compiler/phases/3-transform/client/visitors/FunctionDeclaration.js +12 -0
  141. package/src/compiler/phases/3-transform/client/visitors/FunctionExpression.js +11 -0
  142. package/src/compiler/phases/3-transform/client/visitors/HtmlTag.js +53 -0
  143. package/src/compiler/phases/3-transform/client/visitors/Identifier.js +45 -0
  144. package/src/compiler/phases/3-transform/client/visitors/IfBlock.js +131 -0
  145. package/src/compiler/phases/3-transform/client/visitors/KeyBlock.js +45 -0
  146. package/src/compiler/phases/3-transform/client/visitors/LabeledStatement.js +64 -0
  147. package/src/compiler/phases/3-transform/client/visitors/LetDirective.js +55 -0
  148. package/src/compiler/phases/3-transform/client/visitors/MemberExpression.js +23 -0
  149. package/src/compiler/phases/3-transform/client/visitors/OnDirective.js +38 -0
  150. package/src/compiler/phases/3-transform/client/visitors/Program.js +153 -0
  151. package/src/compiler/phases/3-transform/client/visitors/RegularElement.js +725 -0
  152. package/src/compiler/phases/3-transform/client/visitors/RenderTag.js +95 -0
  153. package/src/compiler/phases/3-transform/client/visitors/SlotElement.js +94 -0
  154. package/src/compiler/phases/3-transform/client/visitors/SnippetBlock.js +94 -0
  155. package/src/compiler/phases/3-transform/client/visitors/SpreadAttribute.js +10 -0
  156. package/src/compiler/phases/3-transform/client/visitors/SvelteBody.js +11 -0
  157. package/src/compiler/phases/3-transform/client/visitors/SvelteBoundary.js +126 -0
  158. package/src/compiler/phases/3-transform/client/visitors/SvelteComponent.js +13 -0
  159. package/src/compiler/phases/3-transform/client/visitors/SvelteDocument.js +11 -0
  160. package/src/compiler/phases/3-transform/client/visitors/SvelteElement.js +161 -0
  161. package/src/compiler/phases/3-transform/client/visitors/SvelteFragment.js +17 -0
  162. package/src/compiler/phases/3-transform/client/visitors/SvelteHead.js +23 -0
  163. package/src/compiler/phases/3-transform/client/visitors/SvelteSelf.js +13 -0
  164. package/src/compiler/phases/3-transform/client/visitors/SvelteWindow.js +11 -0
  165. package/src/compiler/phases/3-transform/client/visitors/TitleElement.js +48 -0
  166. package/src/compiler/phases/3-transform/client/visitors/TransitionDirective.js +41 -0
  167. package/src/compiler/phases/3-transform/client/visitors/UpdateExpression.js +55 -0
  168. package/src/compiler/phases/3-transform/client/visitors/UseDirective.js +49 -0
  169. package/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js +422 -0
  170. package/src/compiler/phases/3-transform/client/visitors/shared/component.js +536 -0
  171. package/src/compiler/phases/3-transform/client/visitors/shared/declarations.js +53 -0
  172. package/src/compiler/phases/3-transform/client/visitors/shared/element.js +263 -0
  173. package/src/compiler/phases/3-transform/client/visitors/shared/events.js +180 -0
  174. package/src/compiler/phases/3-transform/client/visitors/shared/fragment.js +185 -0
  175. package/src/compiler/phases/3-transform/client/visitors/shared/function.js +17 -0
  176. package/src/compiler/phases/3-transform/client/visitors/shared/special_element.js +22 -0
  177. package/src/compiler/phases/3-transform/client/visitors/shared/utils.js +513 -0
  178. package/src/compiler/phases/3-transform/css/index.js +479 -0
  179. package/src/compiler/phases/3-transform/index.js +118 -0
  180. package/src/compiler/phases/3-transform/server/transform-server.js +428 -0
  181. package/src/compiler/phases/3-transform/server/visitors/AssignmentExpression.js +124 -0
  182. package/src/compiler/phases/3-transform/server/visitors/AwaitBlock.js +36 -0
  183. package/src/compiler/phases/3-transform/server/visitors/AwaitExpression.js +40 -0
  184. package/src/compiler/phases/3-transform/server/visitors/CallExpression.js +71 -0
  185. package/src/compiler/phases/3-transform/server/visitors/ClassBody.js +81 -0
  186. package/src/compiler/phases/3-transform/server/visitors/Component.js +13 -0
  187. package/src/compiler/phases/3-transform/server/visitors/ConstTag.js +49 -0
  188. package/src/compiler/phases/3-transform/server/visitors/DebugTag.js +24 -0
  189. package/src/compiler/phases/3-transform/server/visitors/EachBlock.js +76 -0
  190. package/src/compiler/phases/3-transform/server/visitors/ExpressionStatement.js +23 -0
  191. package/src/compiler/phases/3-transform/server/visitors/Fragment.js +53 -0
  192. package/src/compiler/phases/3-transform/server/visitors/HtmlTag.js +25 -0
  193. package/src/compiler/phases/3-transform/server/visitors/Identifier.js +24 -0
  194. package/src/compiler/phases/3-transform/server/visitors/IfBlock.js +48 -0
  195. package/src/compiler/phases/3-transform/server/visitors/KeyBlock.js +22 -0
  196. package/src/compiler/phases/3-transform/server/visitors/LabeledStatement.js +24 -0
  197. package/src/compiler/phases/3-transform/server/visitors/MemberExpression.js +19 -0
  198. package/src/compiler/phases/3-transform/server/visitors/Program.js +25 -0
  199. package/src/compiler/phases/3-transform/server/visitors/PropertyDefinition.js +37 -0
  200. package/src/compiler/phases/3-transform/server/visitors/RegularElement.js +216 -0
  201. package/src/compiler/phases/3-transform/server/visitors/RenderTag.js +45 -0
  202. package/src/compiler/phases/3-transform/server/visitors/SlotElement.js +68 -0
  203. package/src/compiler/phases/3-transform/server/visitors/SnippetBlock.js +29 -0
  204. package/src/compiler/phases/3-transform/server/visitors/SpreadAttribute.js +10 -0
  205. package/src/compiler/phases/3-transform/server/visitors/SvelteBoundary.js +139 -0
  206. package/src/compiler/phases/3-transform/server/visitors/SvelteComponent.js +12 -0
  207. package/src/compiler/phases/3-transform/server/visitors/SvelteElement.js +89 -0
  208. package/src/compiler/phases/3-transform/server/visitors/SvelteFragment.js +11 -0
  209. package/src/compiler/phases/3-transform/server/visitors/SvelteHead.js +25 -0
  210. package/src/compiler/phases/3-transform/server/visitors/SvelteSelf.js +12 -0
  211. package/src/compiler/phases/3-transform/server/visitors/TitleElement.js +21 -0
  212. package/src/compiler/phases/3-transform/server/visitors/UpdateExpression.js +35 -0
  213. package/src/compiler/phases/3-transform/server/visitors/VariableDeclaration.js +247 -0
  214. package/src/compiler/phases/3-transform/server/visitors/shared/component.js +359 -0
  215. package/src/compiler/phases/3-transform/server/visitors/shared/element.js +557 -0
  216. package/src/compiler/phases/3-transform/server/visitors/shared/utils.js +408 -0
  217. package/src/compiler/phases/3-transform/shared/assignments.js +92 -0
  218. package/src/compiler/phases/3-transform/shared/transform-async.js +114 -0
  219. package/src/compiler/phases/3-transform/utils.js +451 -0
  220. package/src/compiler/phases/bindings.js +227 -0
  221. package/src/compiler/phases/css.js +14 -0
  222. package/src/compiler/phases/nodes.js +258 -0
  223. package/src/compiler/phases/patterns.js +27 -0
  224. package/src/compiler/phases/scope.js +1432 -0
  225. package/src/compiler/preprocess/decode_sourcemap.js +96 -0
  226. package/src/compiler/preprocess/index.js +368 -0
  227. package/src/compiler/preprocess/replace_in_code.js +72 -0
  228. package/src/compiler/print/index.js +911 -0
  229. package/src/compiler/state.js +144 -0
  230. package/src/compiler/utils/assert.js +9 -0
  231. package/src/compiler/utils/ast.js +639 -0
  232. package/src/compiler/utils/builders.js +698 -0
  233. package/src/compiler/utils/compile_diagnostic.js +107 -0
  234. package/src/compiler/utils/extract_svelte_ignore.js +104 -0
  235. package/src/compiler/utils/mapped_code.js +454 -0
  236. package/src/compiler/utils/push_array.js +13 -0
  237. package/src/compiler/utils/sanitize_template_string.js +7 -0
  238. package/src/compiler/utils/slot.js +20 -0
  239. package/src/compiler/utils/string.js +9 -0
  240. package/src/compiler/validate-options.js +324 -0
  241. package/src/compiler/warnings.js +845 -0
  242. package/src/constants.js +66 -0
  243. package/src/easing/index.js +286 -0
  244. package/src/escaping.js +26 -0
  245. package/src/events/index.js +1 -0
  246. package/src/html-tree-validation.js +238 -0
  247. package/src/index-client.js +255 -0
  248. package/src/index-server.js +56 -0
  249. package/src/internal/client/constants.js +77 -0
  250. package/src/internal/client/context.js +258 -0
  251. package/src/internal/client/dev/assign.js +79 -0
  252. package/src/internal/client/dev/console-log.js +37 -0
  253. package/src/internal/client/dev/css.js +31 -0
  254. package/src/internal/client/dev/debug.js +500 -0
  255. package/src/internal/client/dev/elements.js +63 -0
  256. package/src/internal/client/dev/equality.js +101 -0
  257. package/src/internal/client/dev/hmr.js +89 -0
  258. package/src/internal/client/dev/inspect.js +72 -0
  259. package/src/internal/client/dev/legacy.js +25 -0
  260. package/src/internal/client/dev/ownership.js +81 -0
  261. package/src/internal/client/dev/tracing.js +162 -0
  262. package/src/internal/client/dev/validation.js +16 -0
  263. package/src/internal/client/dom/blocks/async.js +71 -0
  264. package/src/internal/client/dom/blocks/await.js +142 -0
  265. package/src/internal/client/dom/blocks/boundary.js +534 -0
  266. package/src/internal/client/dom/blocks/branches.js +227 -0
  267. package/src/internal/client/dom/blocks/css-props.js +28 -0
  268. package/src/internal/client/dom/blocks/each.js +723 -0
  269. package/src/internal/client/dom/blocks/html.js +128 -0
  270. package/src/internal/client/dom/blocks/if.js +82 -0
  271. package/src/internal/client/dom/blocks/key.js +40 -0
  272. package/src/internal/client/dom/blocks/slot.js +44 -0
  273. package/src/internal/client/dom/blocks/snippet.js +103 -0
  274. package/src/internal/client/dom/blocks/svelte-component.js +61 -0
  275. package/src/internal/client/dom/blocks/svelte-element.js +152 -0
  276. package/src/internal/client/dom/blocks/svelte-head.js +61 -0
  277. package/src/internal/client/dom/css.js +33 -0
  278. package/src/internal/client/dom/elements/actions.js +43 -0
  279. package/src/internal/client/dom/elements/attachments.js +33 -0
  280. package/src/internal/client/dom/elements/attributes.js +657 -0
  281. package/src/internal/client/dom/elements/bindings/document.js +17 -0
  282. package/src/internal/client/dom/elements/bindings/input.js +312 -0
  283. package/src/internal/client/dom/elements/bindings/media.js +233 -0
  284. package/src/internal/client/dom/elements/bindings/navigator.js +11 -0
  285. package/src/internal/client/dom/elements/bindings/props.js +22 -0
  286. package/src/internal/client/dom/elements/bindings/select.js +159 -0
  287. package/src/internal/client/dom/elements/bindings/shared.js +76 -0
  288. package/src/internal/client/dom/elements/bindings/size.js +107 -0
  289. package/src/internal/client/dom/elements/bindings/this.js +61 -0
  290. package/src/internal/client/dom/elements/bindings/universal.js +75 -0
  291. package/src/internal/client/dom/elements/bindings/window.js +66 -0
  292. package/src/internal/client/dom/elements/class.js +51 -0
  293. package/src/internal/client/dom/elements/custom-element.js +344 -0
  294. package/src/internal/client/dom/elements/customizable-select.js +99 -0
  295. package/src/internal/client/dom/elements/events.js +355 -0
  296. package/src/internal/client/dom/elements/misc.js +58 -0
  297. package/src/internal/client/dom/elements/style.js +57 -0
  298. package/src/internal/client/dom/elements/transitions.js +471 -0
  299. package/src/internal/client/dom/hydration.js +125 -0
  300. package/src/internal/client/dom/legacy/event-modifiers.js +127 -0
  301. package/src/internal/client/dom/legacy/lifecycle.js +82 -0
  302. package/src/internal/client/dom/legacy/misc.js +68 -0
  303. package/src/internal/client/dom/operations.js +293 -0
  304. package/src/internal/client/dom/reconciler.js +25 -0
  305. package/src/internal/client/dom/task.js +42 -0
  306. package/src/internal/client/dom/template.js +401 -0
  307. package/src/internal/client/error-handling.js +118 -0
  308. package/src/internal/client/errors.js +510 -0
  309. package/src/internal/client/hydratable.js +33 -0
  310. package/src/internal/client/index.js +183 -0
  311. package/src/internal/client/legacy.js +46 -0
  312. package/src/internal/client/loop.js +48 -0
  313. package/src/internal/client/proxy.js +432 -0
  314. package/src/internal/client/reactivity/async.js +306 -0
  315. package/src/internal/client/reactivity/batch.js +1057 -0
  316. package/src/internal/client/reactivity/deriveds.js +426 -0
  317. package/src/internal/client/reactivity/effects.js +718 -0
  318. package/src/internal/client/reactivity/equality.js +31 -0
  319. package/src/internal/client/reactivity/props.js +430 -0
  320. package/src/internal/client/reactivity/sources.js +370 -0
  321. package/src/internal/client/reactivity/status.js +25 -0
  322. package/src/internal/client/reactivity/store.js +203 -0
  323. package/src/internal/client/reactivity/utils.js +40 -0
  324. package/src/internal/client/render.js +335 -0
  325. package/src/internal/client/runtime.js +827 -0
  326. package/src/internal/client/timing.js +16 -0
  327. package/src/internal/client/validate.js +54 -0
  328. package/src/internal/client/warnings.js +271 -0
  329. package/src/internal/disclose-version.js +6 -0
  330. package/src/internal/flags/async.js +3 -0
  331. package/src/internal/flags/index.js +23 -0
  332. package/src/internal/flags/legacy.js +3 -0
  333. package/src/internal/flags/tracing.js +3 -0
  334. package/src/internal/index.js +5 -0
  335. package/src/internal/server/abort-signal.js +13 -0
  336. package/src/internal/server/blocks/html.js +11 -0
  337. package/src/internal/server/blocks/snippet.js +24 -0
  338. package/src/internal/server/context.js +132 -0
  339. package/src/internal/server/crypto.js +45 -0
  340. package/src/internal/server/dev.js +115 -0
  341. package/src/internal/server/errors.js +131 -0
  342. package/src/internal/server/hydratable.js +142 -0
  343. package/src/internal/server/hydration.js +6 -0
  344. package/src/internal/server/index.js +544 -0
  345. package/src/internal/server/render-context.js +86 -0
  346. package/src/internal/server/renderer.js +923 -0
  347. package/src/internal/server/warnings.js +29 -0
  348. package/src/internal/shared/attributes.js +225 -0
  349. package/src/internal/shared/clone.js +137 -0
  350. package/src/internal/shared/dev.js +65 -0
  351. package/src/internal/shared/errors.js +134 -0
  352. package/src/internal/shared/utils.js +144 -0
  353. package/src/internal/shared/validate.js +47 -0
  354. package/src/internal/shared/warnings.js +40 -0
  355. package/src/legacy/legacy-client.js +281 -0
  356. package/src/legacy/legacy-server.js +112 -0
  357. package/src/motion/index.js +32 -0
  358. package/src/motion/spring.js +369 -0
  359. package/src/motion/tweened.js +306 -0
  360. package/src/motion/utils.js +7 -0
  361. package/src/reactivity/create-subscriber.js +95 -0
  362. package/src/reactivity/date.js +118 -0
  363. package/src/reactivity/index-client.js +7 -0
  364. package/src/reactivity/index-server.js +23 -0
  365. package/src/reactivity/map.js +273 -0
  366. package/src/reactivity/media-query.js +55 -0
  367. package/src/reactivity/reactive-value.js +24 -0
  368. package/src/reactivity/set.js +213 -0
  369. package/src/reactivity/url-search-params.js +174 -0
  370. package/src/reactivity/url.js +205 -0
  371. package/src/reactivity/window/index.js +161 -0
  372. package/src/server/index.js +1 -0
  373. package/src/store/index-client.js +169 -0
  374. package/src/store/index-server.js +101 -0
  375. package/src/store/shared/index.js +209 -0
  376. package/src/store/utils.js +36 -0
  377. package/src/transition/index.js +300 -0
  378. package/src/utils.js +504 -0
  379. package/src/version.js +8 -0
  380. package/store.d.ts +1 -0
  381. package/svelte-html.d.ts +245 -0
  382. package/transition.d.ts +1 -0
  383. package/types/compiler/interfaces.d.ts +1 -0
  384. package/types/compiler/preprocess.d.ts +1 -0
  385. package/types/index.d.ts +3744 -0
  386. package/types/index.d.ts.map +280 -0
@@ -0,0 +1,544 @@
1
+ /** @import { ComponentType, SvelteComponent, Component } from 'svelte' */
2
+ /** @import { Csp, RenderOutput } from '#server' */
3
+ /** @import { Store } from '#shared' */
4
+ export { FILENAME, HMR } from '../../constants.js';
5
+ import { attr, clsx, to_class, to_style } from '../shared/attributes.js';
6
+ import { is_promise, noop } from '../shared/utils.js';
7
+ import { subscribe_to_store } from '../../store/utils.js';
8
+ import {
9
+ UNINITIALIZED,
10
+ ELEMENT_PRESERVE_ATTRIBUTE_CASE,
11
+ ELEMENT_IS_NAMESPACED,
12
+ ELEMENT_IS_INPUT
13
+ } from '../../constants.js';
14
+ import { escape_html } from '../../escaping.js';
15
+ import { DEV } from 'esm-env';
16
+ import { EMPTY_COMMENT, BLOCK_OPEN, BLOCK_OPEN_ELSE } from './hydration.js';
17
+ import { validate_store } from '../shared/validate.js';
18
+ import {
19
+ is_boolean_attribute,
20
+ is_raw_text_element,
21
+ is_void,
22
+ REGEX_VALID_TAG_NAME
23
+ } from '../../utils.js';
24
+ import { Renderer } from './renderer.js';
25
+ import * as e from './errors.js';
26
+ import { ssr_context } from './context.js';
27
+
28
+ // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
29
+ // https://infra.spec.whatwg.org/#noncharacter
30
+ const INVALID_ATTR_NAME_CHAR_REGEX =
31
+ /[\s'">/=\u{FDD0}-\u{FDEF}\u{FFFE}\u{FFFF}\u{1FFFE}\u{1FFFF}\u{2FFFE}\u{2FFFF}\u{3FFFE}\u{3FFFF}\u{4FFFE}\u{4FFFF}\u{5FFFE}\u{5FFFF}\u{6FFFE}\u{6FFFF}\u{7FFFE}\u{7FFFF}\u{8FFFE}\u{8FFFF}\u{9FFFE}\u{9FFFF}\u{AFFFE}\u{AFFFF}\u{BFFFE}\u{BFFFF}\u{CFFFE}\u{CFFFF}\u{DFFFE}\u{DFFFF}\u{EFFFE}\u{EFFFF}\u{FFFFE}\u{FFFFF}\u{10FFFE}\u{10FFFF}]/u;
32
+
33
+ /**
34
+ * @param {Renderer} renderer
35
+ * @param {string} tag
36
+ * @param {() => void} attributes_fn
37
+ * @param {() => void} children_fn
38
+ * @returns {void}
39
+ */
40
+ export function element(renderer, tag, attributes_fn = noop, children_fn = noop) {
41
+ renderer.push('<!---->');
42
+
43
+ if (tag) {
44
+ if (!REGEX_VALID_TAG_NAME.test(tag)) {
45
+ e.dynamic_element_invalid_tag(tag);
46
+ }
47
+ renderer.push(`<${tag}`);
48
+ attributes_fn();
49
+ renderer.push(`>`);
50
+
51
+ if (!is_void(tag)) {
52
+ children_fn();
53
+ if (!is_raw_text_element(tag)) {
54
+ renderer.push(EMPTY_COMMENT);
55
+ }
56
+ renderer.push(`</${tag}>`);
57
+ }
58
+ }
59
+
60
+ renderer.push('<!---->');
61
+ }
62
+
63
+ /**
64
+ * Only available on the server and when compiling with the `server` option.
65
+ * Takes a component and returns an object with `body` and `head` properties on it, which you can use to populate the HTML when server-rendering your app.
66
+ * @template {Record<string, any>} Props
67
+ * @param {Component<Props> | ComponentType<SvelteComponent<Props>>} component
68
+ * @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>; idPrefix?: string; csp?: Csp; transformError?: (error: unknown) => unknown }} [options]
69
+ * @returns {RenderOutput}
70
+ */
71
+ export function render(component, options = {}) {
72
+ if (options.csp?.hash && options.csp.nonce) {
73
+ e.invalid_csp();
74
+ }
75
+ return Renderer.render(/** @type {Component<Props>} */ (component), options);
76
+ }
77
+
78
+ /**
79
+ * @param {string} hash
80
+ * @param {Renderer} renderer
81
+ * @param {(renderer: Renderer) => Promise<void> | void} fn
82
+ * @returns {void}
83
+ */
84
+ export function head(hash, renderer, fn) {
85
+ renderer.head((renderer) => {
86
+ renderer.push(`<!--${hash}-->`);
87
+ renderer.child(fn);
88
+ renderer.push(EMPTY_COMMENT);
89
+ });
90
+ }
91
+
92
+ /**
93
+ * @param {Renderer} renderer
94
+ * @param {boolean} is_html
95
+ * @param {Record<string, string>} props
96
+ * @param {() => void} component
97
+ * @param {boolean} dynamic
98
+ * @returns {void}
99
+ */
100
+ export function css_props(renderer, is_html, props, component, dynamic = false) {
101
+ const styles = style_object_to_string(props);
102
+
103
+ if (is_html) {
104
+ renderer.push(`<svelte-css-wrapper style="display: contents; ${styles}">`);
105
+ } else {
106
+ renderer.push(`<g style="${styles}">`);
107
+ }
108
+
109
+ component();
110
+
111
+ if (!dynamic) {
112
+ renderer.push('<!---->');
113
+ }
114
+
115
+ if (is_html) {
116
+ renderer.push('</svelte-css-wrapper>');
117
+ } else {
118
+ renderer.push('</g>');
119
+ }
120
+ }
121
+
122
+ /**
123
+ * @param {Record<string, unknown>} attrs
124
+ * @param {string} [css_hash]
125
+ * @param {Record<string, boolean>} [classes]
126
+ * @param {Record<string, string>} [styles]
127
+ * @param {number} [flags]
128
+ * @returns {string}
129
+ */
130
+ export function attributes(attrs, css_hash, classes, styles, flags = 0) {
131
+ if (styles) {
132
+ attrs.style = to_style(attrs.style, styles);
133
+ }
134
+
135
+ if (attrs.class) {
136
+ attrs.class = clsx(attrs.class);
137
+ }
138
+
139
+ if (css_hash || classes) {
140
+ attrs.class = to_class(attrs.class, css_hash, classes);
141
+ }
142
+
143
+ let attr_str = '';
144
+ let name;
145
+
146
+ const is_html = (flags & ELEMENT_IS_NAMESPACED) === 0;
147
+ const lowercase = (flags & ELEMENT_PRESERVE_ATTRIBUTE_CASE) === 0;
148
+ const is_input = (flags & ELEMENT_IS_INPUT) !== 0;
149
+
150
+ for (name of Object.keys(attrs)) {
151
+ // omit functions, internal svelte properties and invalid attribute names
152
+ if (typeof attrs[name] === 'function') continue;
153
+ if (name[0] === '$' && name[1] === '$') continue; // faster than name.startsWith('$$')
154
+ if (INVALID_ATTR_NAME_CHAR_REGEX.test(name)) continue;
155
+
156
+ var value = attrs[name];
157
+
158
+ if (lowercase) {
159
+ name = name.toLowerCase();
160
+ }
161
+
162
+ // omit event handler attributes
163
+ if (name.length > 2 && name.startsWith('on')) continue;
164
+
165
+ if (is_input) {
166
+ if (name === 'defaultvalue' || name === 'defaultchecked') {
167
+ name = name === 'defaultvalue' ? 'value' : 'checked';
168
+ if (attrs[name]) continue;
169
+ }
170
+ }
171
+
172
+ attr_str += attr(name, value, is_html && is_boolean_attribute(name));
173
+ }
174
+
175
+ return attr_str;
176
+ }
177
+
178
+ /**
179
+ * @param {Record<string, unknown>[]} props
180
+ * @returns {Record<string, unknown>}
181
+ */
182
+ export function spread_props(props) {
183
+ /** @type {Record<string, unknown>} */
184
+ const merged_props = {};
185
+ let key;
186
+
187
+ for (let i = 0; i < props.length; i++) {
188
+ const obj = props[i];
189
+ if (obj == null) continue;
190
+ for (key of Object.keys(obj)) {
191
+ const desc = Object.getOwnPropertyDescriptor(obj, key);
192
+ if (desc) {
193
+ Object.defineProperty(merged_props, key, desc);
194
+ } else {
195
+ merged_props[key] = obj[key];
196
+ }
197
+ }
198
+ }
199
+ return merged_props;
200
+ }
201
+
202
+ /**
203
+ * @param {unknown} value
204
+ * @returns {string}
205
+ */
206
+ export function stringify(value) {
207
+ return typeof value === 'string' ? value : value == null ? '' : value + '';
208
+ }
209
+
210
+ /** @param {Record<string, string>} style_object */
211
+ function style_object_to_string(style_object) {
212
+ return Object.keys(style_object)
213
+ .filter(/** @param {any} key */ (key) => style_object[key] != null && style_object[key] !== '')
214
+ .map(/** @param {any} key */ (key) => `${key}: ${escape_html(style_object[key], true)};`)
215
+ .join(' ');
216
+ }
217
+
218
+ /**
219
+ * @param {any} value
220
+ * @param {string | undefined} [hash]
221
+ * @param {Record<string, boolean>} [directives]
222
+ */
223
+ export function attr_class(value, hash, directives) {
224
+ var result = to_class(value, hash, directives);
225
+ return result ? ` class="${escape_html(result, true)}"` : '';
226
+ }
227
+
228
+ /**
229
+ * @param {any} value
230
+ * @param {Record<string,any>|[Record<string,any>,Record<string,any>]} [directives]
231
+ */
232
+ export function attr_style(value, directives) {
233
+ var result = to_style(value, directives);
234
+ return result ? ` style="${escape_html(result, true)}"` : '';
235
+ }
236
+
237
+ /**
238
+ * @template V
239
+ * @param {Record<string, [any, any, any]>} store_values
240
+ * @param {string} store_name
241
+ * @param {Store<V> | null | undefined} store
242
+ * @returns {V}
243
+ */
244
+ export function store_get(store_values, store_name, store) {
245
+ if (DEV) {
246
+ validate_store(store, store_name.slice(1));
247
+ }
248
+
249
+ // it could be that someone eagerly updates the store in the instance script, so
250
+ // we should only reuse the store value in the template
251
+ if (store_name in store_values && store_values[store_name][0] === store) {
252
+ return store_values[store_name][2];
253
+ }
254
+
255
+ store_values[store_name]?.[1](); // if store was switched, unsubscribe from old store
256
+ store_values[store_name] = [store, null, undefined];
257
+ const unsub = subscribe_to_store(
258
+ store,
259
+ /** @param {any} v */ (v) => (store_values[store_name][2] = v)
260
+ );
261
+ store_values[store_name][1] = unsub;
262
+ return store_values[store_name][2];
263
+ }
264
+
265
+ /**
266
+ * Sets the new value of a store and returns that value.
267
+ * @template V
268
+ * @param {Store<V>} store
269
+ * @param {V} value
270
+ * @returns {V}
271
+ */
272
+ export function store_set(store, value) {
273
+ store.set(value);
274
+ return value;
275
+ }
276
+
277
+ /**
278
+ * Updates a store with a new value.
279
+ * @template V
280
+ * @param {Record<string, [any, any, any]>} store_values
281
+ * @param {string} store_name
282
+ * @param {Store<V>} store
283
+ * @param {any} expression
284
+ */
285
+ export function store_mutate(store_values, store_name, store, expression) {
286
+ store_set(store, store_get(store_values, store_name, store));
287
+ return expression;
288
+ }
289
+
290
+ /**
291
+ * @param {Record<string, [any, any, any]>} store_values
292
+ * @param {string} store_name
293
+ * @param {Store<number>} store
294
+ * @param {1 | -1} [d]
295
+ * @returns {number}
296
+ */
297
+ export function update_store(store_values, store_name, store, d = 1) {
298
+ let store_value = store_get(store_values, store_name, store);
299
+ store.set(store_value + d);
300
+ return store_value;
301
+ }
302
+
303
+ /**
304
+ * @param {Record<string, [any, any, any]>} store_values
305
+ * @param {string} store_name
306
+ * @param {Store<number>} store
307
+ * @param {1 | -1} [d]
308
+ * @returns {number}
309
+ */
310
+ export function update_store_pre(store_values, store_name, store, d = 1) {
311
+ const value = store_get(store_values, store_name, store) + d;
312
+ store.set(value);
313
+ return value;
314
+ }
315
+
316
+ /** @param {Record<string, [any, any, any]>} store_values */
317
+ export function unsubscribe_stores(store_values) {
318
+ for (const store_name of Object.keys(store_values)) {
319
+ store_values[store_name][1]();
320
+ }
321
+ }
322
+
323
+ /**
324
+ * @param {Renderer} renderer
325
+ * @param {Record<string, any>} $$props
326
+ * @param {string} name
327
+ * @param {Record<string, unknown>} slot_props
328
+ * @param {null | (() => void)} fallback_fn
329
+ * @returns {void}
330
+ */
331
+ export function slot(renderer, $$props, name, slot_props, fallback_fn) {
332
+ var slot_fn = $$props.$$slots?.[name];
333
+ // Interop: Can use snippets to fill slots
334
+ if (slot_fn === true) {
335
+ slot_fn = $$props[name === 'default' ? 'children' : name];
336
+ }
337
+
338
+ if (slot_fn !== undefined) {
339
+ slot_fn(renderer, slot_props);
340
+ } else {
341
+ fallback_fn?.();
342
+ }
343
+ }
344
+
345
+ /**
346
+ * @param {Record<string, unknown>} props
347
+ * @param {string[]} rest
348
+ * @returns {Record<string, unknown>}
349
+ */
350
+ export function rest_props(props, rest) {
351
+ /** @type {Record<string, unknown>} */
352
+ const rest_props = {};
353
+ let key;
354
+ for (key of Object.keys(props)) {
355
+ if (!rest.includes(key)) {
356
+ rest_props[key] = props[key];
357
+ }
358
+ }
359
+ return rest_props;
360
+ }
361
+
362
+ /**
363
+ * @param {Record<string, unknown>} props
364
+ * @returns {Record<string, unknown>}
365
+ */
366
+ export function sanitize_props(props) {
367
+ const { children, $$slots, ...sanitized } = props;
368
+ return sanitized;
369
+ }
370
+
371
+ /**
372
+ * @param {Record<string, any>} props
373
+ * @returns {Record<string, boolean>}
374
+ */
375
+ export function sanitize_slots(props) {
376
+ /** @type {Record<string, boolean>} */
377
+ const sanitized = {};
378
+ if (props.children) sanitized.default = true;
379
+ for (const key of Object.keys(props.$$slots || {})) {
380
+ sanitized[key] = true;
381
+ }
382
+ return sanitized;
383
+ }
384
+
385
+ /**
386
+ * Legacy mode: If the prop has a fallback and is bound in the
387
+ * parent component, propagate the fallback value upwards.
388
+ * @param {Record<string, unknown>} props_parent
389
+ * @param {Record<string, unknown>} props_now
390
+ */
391
+ export function bind_props(props_parent, props_now) {
392
+ for (const key of Object.keys(props_now)) {
393
+ const initial_value = props_parent[key];
394
+ const value = props_now[key];
395
+ if (
396
+ initial_value === undefined &&
397
+ value !== undefined &&
398
+ Object.getOwnPropertyDescriptor(props_parent, key)?.set
399
+ ) {
400
+ props_parent[key] = value;
401
+ }
402
+ }
403
+ }
404
+
405
+ /**
406
+ * @template V
407
+ * @param {Renderer} renderer
408
+ * @param {Promise<V>} promise
409
+ * @param {null | (() => void)} pending_fn
410
+ * @param {(value: V) => void} then_fn
411
+ * @returns {void}
412
+ */
413
+ function await_block(renderer, promise, pending_fn, then_fn) {
414
+ if (is_promise(promise)) {
415
+ renderer.push(BLOCK_OPEN);
416
+ promise.then(null, noop);
417
+ if (pending_fn !== null) {
418
+ pending_fn();
419
+ }
420
+ } else if (then_fn !== null) {
421
+ renderer.push(BLOCK_OPEN_ELSE);
422
+ then_fn(promise);
423
+ }
424
+ }
425
+
426
+ export { await_block as await };
427
+
428
+ /** @param {any} array_like_or_iterator */
429
+ export function ensure_array_like(array_like_or_iterator) {
430
+ if (array_like_or_iterator) {
431
+ return array_like_or_iterator.length !== undefined
432
+ ? array_like_or_iterator
433
+ : Array.from(array_like_or_iterator);
434
+ }
435
+ return [];
436
+ }
437
+
438
+ /**
439
+ * @template V
440
+ * @param {() => V} get_value
441
+ */
442
+ export function once(get_value) {
443
+ let value = /** @type {V} */ (UNINITIALIZED);
444
+ return () => {
445
+ if (value === UNINITIALIZED) {
446
+ value = get_value();
447
+ }
448
+ return value;
449
+ };
450
+ }
451
+
452
+ /**
453
+ * Create an unique ID
454
+ * @param {Renderer} renderer
455
+ * @returns {string}
456
+ */
457
+ export function props_id(renderer) {
458
+ const uid = renderer.global.uid();
459
+ renderer.push('<!--$' + uid + '-->');
460
+ return uid;
461
+ }
462
+
463
+ export { attr, clsx };
464
+
465
+ export { html } from './blocks/html.js';
466
+
467
+ export { save } from './context.js';
468
+
469
+ export { push_element, pop_element, validate_snippet_args } from './dev.js';
470
+
471
+ export { snapshot } from '../shared/clone.js';
472
+
473
+ export { fallback, to_array, exclude_from_object } from '../shared/utils.js';
474
+
475
+ export {
476
+ invalid_default_snippet,
477
+ validate_dynamic_element_tag,
478
+ validate_void_dynamic_element,
479
+ prevent_snippet_stringification
480
+ } from '../shared/validate.js';
481
+
482
+ export { escape_html as escape };
483
+
484
+ /**
485
+ * @template T
486
+ * @param {()=>T} fn
487
+ * @returns {(new_value?: T) => (T | void)}
488
+ */
489
+ export function derived(fn) {
490
+ // deriveds created during render are memoized,
491
+ // deriveds created outside (e.g. SvelteKit `page` stuff) are not
492
+ const get_value = ssr_context === null ? fn : once(fn);
493
+
494
+ /** @type {T | undefined} */
495
+ let updated_value;
496
+
497
+ return function (new_value) {
498
+ if (arguments.length === 0) {
499
+ return updated_value ?? get_value();
500
+ }
501
+
502
+ updated_value = new_value;
503
+ return updated_value;
504
+ };
505
+ }
506
+
507
+ /**
508
+ * @template {number | bigint} T
509
+ * @param {(value?: T) => T} derived
510
+ * @param {1 | -1} [d]
511
+ * @returns {T}
512
+ */
513
+ export function update_derived(derived, d = 1) {
514
+ const value = derived();
515
+ let increase = typeof value === 'bigint' ? BigInt(d) : d;
516
+ // for some reason TS is mad even if T is always number or bigint
517
+ derived(value + /** @type {*} */ (increase));
518
+ return value;
519
+ }
520
+
521
+ /**
522
+ * @template {number | bigint} T
523
+ * @param {(value?: T) => T} derived
524
+ * @param {1 | -1} [d]
525
+ * @returns {T}
526
+ */
527
+ export function update_derived_pre(derived, d = 1) {
528
+ const old_value = derived();
529
+ let increase = typeof old_value === 'bigint' ? BigInt(d) : d;
530
+ // for some reason TS is mad even if T is always number or bigint
531
+ const value = old_value + /** @type {*} */ (increase);
532
+ derived(value);
533
+ return value;
534
+ }
535
+
536
+ /**
537
+ * @template T
538
+ * @param {()=>T} fn
539
+ */
540
+ export function async_derived(fn) {
541
+ return Promise.resolve(fn()).then((value) => {
542
+ return () => value;
543
+ });
544
+ }
@@ -0,0 +1,86 @@
1
+ // @ts-ignore -- we don't include node types in the production build
2
+ /** @import { AsyncLocalStorage } from 'node:async_hooks' */
3
+ /** @import { RenderContext } from '#server' */
4
+
5
+ import { deferred, noop } from '../shared/utils.js';
6
+ import * as e from './errors.js';
7
+
8
+ /** @type {Promise<void> | null} */
9
+ let current_render = null;
10
+
11
+ /** @type {RenderContext | null} */
12
+ let context = null;
13
+
14
+ /** @returns {RenderContext} */
15
+ export function get_render_context() {
16
+ const store = context ?? als?.getStore();
17
+
18
+ if (!store) {
19
+ e.server_context_required();
20
+ }
21
+
22
+ return store;
23
+ }
24
+
25
+ /**
26
+ * @template T
27
+ * @param {() => Promise<T>} fn
28
+ * @returns {Promise<T>}
29
+ */
30
+ export async function with_render_context(fn) {
31
+ context = {
32
+ hydratable: {
33
+ lookup: new Map(),
34
+ comparisons: [],
35
+ unresolved_promises: new Map()
36
+ }
37
+ };
38
+
39
+ if (in_webcontainer()) {
40
+ const { promise, resolve } = deferred();
41
+ const previous_render = current_render;
42
+ current_render = promise;
43
+ await previous_render;
44
+ return fn().finally(resolve);
45
+ }
46
+
47
+ try {
48
+ if (als === null) {
49
+ e.async_local_storage_unavailable();
50
+ }
51
+ return als.run(context, fn);
52
+ } finally {
53
+ context = null;
54
+ }
55
+ }
56
+
57
+ /** @type {AsyncLocalStorage<RenderContext | null> | null} */
58
+ let als = null;
59
+ /** @type {Promise<void> | null} */
60
+ let als_import = null;
61
+
62
+ /**
63
+ *
64
+ * @returns {Promise<void>}
65
+ */
66
+ export function init_render_context() {
67
+ // It's important the right side of this assignment can run a maximum of one time
68
+ // otherwise it's possible for a very, very well-timed race condition to assign to `als`
69
+ // at the beginning of a render, and then another render to assign to it again, which causes
70
+ // the first render's second half to use a new instance of `als` which doesn't have its
71
+ // context anymore.
72
+ // @ts-ignore -- we don't include node types in the production build
73
+ als_import ??= import('node:async_hooks')
74
+ .then((hooks) => {
75
+ als = new hooks.AsyncLocalStorage();
76
+ })
77
+ .then(noop, noop);
78
+ return als_import;
79
+ }
80
+
81
+ // this has to be a function because rollup won't treeshake it if it's a constant
82
+ function in_webcontainer() {
83
+ // @ts-ignore -- this will fail when we run typecheck because we exclude node types
84
+ // eslint-disable-next-line n/prefer-global/process
85
+ return !!globalThis.process?.versions?.webcontainer;
86
+ }