@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,16 @@
1
+ /** @import { Raf } from '#client' */
2
+ import { noop } from '../shared/utils.js';
3
+
4
+ import { BROWSER } from 'esm-env';
5
+
6
+ const now = BROWSER ? () => performance.now() : () => Date.now();
7
+
8
+ /** @type {Raf} */
9
+ export const raf = {
10
+ // don't access requestAnimationFrame eagerly outside method
11
+ // this allows basic testing of user code without JSDOM
12
+ // bunder will eval and remove ternary when the user's app is built
13
+ tick: /** @param {any} _ */ (_) => (BROWSER ? requestAnimationFrame : noop)(_),
14
+ now: () => now(),
15
+ tasks: new Set()
16
+ };
@@ -0,0 +1,54 @@
1
+ /** @import { Blocker } from '#client' */
2
+ import { dev_current_component_function } from './context.js';
3
+ import { FILENAME } from '../../constants.js';
4
+ import { render_effect } from './reactivity/effects.js';
5
+ import * as w from './warnings.js';
6
+ import { capture_store_binding } from './reactivity/store.js';
7
+ import { run_after_blockers } from './reactivity/async.js';
8
+
9
+ /**
10
+ * @param {string} binding
11
+ * @param {Blocker[]} blockers
12
+ * @param {() => Record<string, any>} get_object
13
+ * @param {() => string} get_property
14
+ * @param {number} line
15
+ * @param {number} column
16
+ */
17
+ export function validate_binding(binding, blockers, get_object, get_property, line, column) {
18
+ run_after_blockers(blockers, () => {
19
+ var warned = false;
20
+
21
+ var filename = dev_current_component_function?.[FILENAME];
22
+
23
+ render_effect(() => {
24
+ if (warned) return;
25
+
26
+ var [object, is_store_sub] = capture_store_binding(get_object);
27
+
28
+ if (is_store_sub) return;
29
+
30
+ var property = get_property();
31
+
32
+ var ran = false;
33
+
34
+ // by making the (possibly false, but it would be an extreme edge case) assumption
35
+ // that a getter has a corresponding setter, we can determine if a property is
36
+ // reactive by seeing if this effect has dependencies
37
+ var effect = render_effect(() => {
38
+ if (ran) return;
39
+
40
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
41
+ object[property];
42
+ });
43
+
44
+ ran = true;
45
+
46
+ if (effect.deps === null) {
47
+ var location = `${filename}:${line}:${column}`;
48
+ w.binding_property_non_reactive(binding, location);
49
+
50
+ warned = true;
51
+ }
52
+ });
53
+ });
54
+ }
@@ -0,0 +1,271 @@
1
+ /* This file is generated by scripts/process-messages/index.js. Do not edit! */
2
+
3
+ import { DEV } from 'esm-env';
4
+
5
+ var bold = 'font-weight: bold';
6
+ var normal = 'font-weight: normal';
7
+
8
+ /**
9
+ * Assignment to `%property%` property (%location%) will evaluate to the right-hand side, not the value of `%property%` following the assignment. This may result in unexpected behaviour.
10
+ * @param {string} property
11
+ * @param {string} location
12
+ */
13
+ export function assignment_value_stale(property, location) {
14
+ if (DEV) {
15
+ console.warn(`%c[svelte] assignment_value_stale\n%cAssignment to \`${property}\` property (${location}) will evaluate to the right-hand side, not the value of \`${property}\` following the assignment. This may result in unexpected behaviour.\nhttps://svelte.dev/e/assignment_value_stale`, bold, normal);
16
+ } else {
17
+ console.warn(`https://svelte.dev/e/assignment_value_stale`);
18
+ }
19
+ }
20
+
21
+ /**
22
+ * Detected reactivity loss when reading `%name%`. This happens when state is read in an async function after an earlier `await`
23
+ * @param {string} name
24
+ */
25
+ export function await_reactivity_loss(name) {
26
+ if (DEV) {
27
+ console.warn(`%c[svelte] await_reactivity_loss\n%cDetected reactivity loss when reading \`${name}\`. This happens when state is read in an async function after an earlier \`await\`\nhttps://svelte.dev/e/await_reactivity_loss`, bold, normal);
28
+ } else {
29
+ console.warn(`https://svelte.dev/e/await_reactivity_loss`);
30
+ }
31
+ }
32
+
33
+ /**
34
+ * An async derived, `%name%` (%location%) was not read immediately after it resolved. This often indicates an unnecessary waterfall, which can slow down your app
35
+ * @param {string} name
36
+ * @param {string} location
37
+ */
38
+ export function await_waterfall(name, location) {
39
+ if (DEV) {
40
+ console.warn(`%c[svelte] await_waterfall\n%cAn async derived, \`${name}\` (${location}) was not read immediately after it resolved. This often indicates an unnecessary waterfall, which can slow down your app\nhttps://svelte.dev/e/await_waterfall`, bold, normal);
41
+ } else {
42
+ console.warn(`https://svelte.dev/e/await_waterfall`);
43
+ }
44
+ }
45
+
46
+ /**
47
+ * `%binding%` (%location%) is binding to a non-reactive property
48
+ * @param {string} binding
49
+ * @param {string | undefined | null} [location]
50
+ */
51
+ export function binding_property_non_reactive(binding, location) {
52
+ if (DEV) {
53
+ console.warn(
54
+ `%c[svelte] binding_property_non_reactive\n%c${location
55
+ ? `\`${binding}\` (${location}) is binding to a non-reactive property`
56
+ : `\`${binding}\` is binding to a non-reactive property`}\nhttps://svelte.dev/e/binding_property_non_reactive`,
57
+ bold,
58
+ normal
59
+ );
60
+ } else {
61
+ console.warn(`https://svelte.dev/e/binding_property_non_reactive`);
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Your `console.%method%` contained `$state` proxies. Consider using `$inspect(...)` or `$state.snapshot(...)` instead
67
+ * @param {string} method
68
+ */
69
+ export function console_log_state(method) {
70
+ if (DEV) {
71
+ console.warn(`%c[svelte] console_log_state\n%cYour \`console.${method}\` contained \`$state\` proxies. Consider using \`$inspect(...)\` or \`$state.snapshot(...)\` instead\nhttps://svelte.dev/e/console_log_state`, bold, normal);
72
+ } else {
73
+ console.warn(`https://svelte.dev/e/console_log_state`);
74
+ }
75
+ }
76
+
77
+ /**
78
+ * %handler% should be a function. Did you mean to %suggestion%?
79
+ * @param {string} handler
80
+ * @param {string} suggestion
81
+ */
82
+ export function event_handler_invalid(handler, suggestion) {
83
+ if (DEV) {
84
+ console.warn(`%c[svelte] event_handler_invalid\n%c${handler} should be a function. Did you mean to ${suggestion}?\nhttps://svelte.dev/e/event_handler_invalid`, bold, normal);
85
+ } else {
86
+ console.warn(`https://svelte.dev/e/event_handler_invalid`);
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Expected to find a hydratable with key `%key%` during hydration, but did not.
92
+ * @param {string} key
93
+ */
94
+ export function hydratable_missing_but_expected(key) {
95
+ if (DEV) {
96
+ console.warn(`%c[svelte] hydratable_missing_but_expected\n%cExpected to find a hydratable with key \`${key}\` during hydration, but did not.\nhttps://svelte.dev/e/hydratable_missing_but_expected`, bold, normal);
97
+ } else {
98
+ console.warn(`https://svelte.dev/e/hydratable_missing_but_expected`);
99
+ }
100
+ }
101
+
102
+ /**
103
+ * The `%attribute%` attribute on `%html%` changed its value between server and client renders. The client value, `%value%`, will be ignored in favour of the server value
104
+ * @param {string} attribute
105
+ * @param {string} html
106
+ * @param {string} value
107
+ */
108
+ export function hydration_attribute_changed(attribute, html, value) {
109
+ if (DEV) {
110
+ console.warn(`%c[svelte] hydration_attribute_changed\n%cThe \`${attribute}\` attribute on \`${html}\` changed its value between server and client renders. The client value, \`${value}\`, will be ignored in favour of the server value\nhttps://svelte.dev/e/hydration_attribute_changed`, bold, normal);
111
+ } else {
112
+ console.warn(`https://svelte.dev/e/hydration_attribute_changed`);
113
+ }
114
+ }
115
+
116
+ /**
117
+ * The value of an `{@html ...}` block %location% changed between server and client renders. The client value will be ignored in favour of the server value
118
+ * @param {string | undefined | null} [location]
119
+ */
120
+ export function hydration_html_changed(location) {
121
+ if (DEV) {
122
+ console.warn(
123
+ `%c[svelte] hydration_html_changed\n%c${location
124
+ ? `The value of an \`{@html ...}\` block ${location} changed between server and client renders. The client value will be ignored in favour of the server value`
125
+ : 'The value of an `{@html ...}` block changed between server and client renders. The client value will be ignored in favour of the server value'}\nhttps://svelte.dev/e/hydration_html_changed`,
126
+ bold,
127
+ normal
128
+ );
129
+ } else {
130
+ console.warn(`https://svelte.dev/e/hydration_html_changed`);
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Hydration failed because the initial UI does not match what was rendered on the server. The error occurred near %location%
136
+ * @param {string | undefined | null} [location]
137
+ */
138
+ export function hydration_mismatch(location) {
139
+ if (DEV) {
140
+ console.warn(
141
+ `%c[svelte] hydration_mismatch\n%c${location
142
+ ? `Hydration failed because the initial UI does not match what was rendered on the server. The error occurred near ${location}`
143
+ : 'Hydration failed because the initial UI does not match what was rendered on the server'}\nhttps://svelte.dev/e/hydration_mismatch`,
144
+ bold,
145
+ normal
146
+ );
147
+ } else {
148
+ console.warn(`https://svelte.dev/e/hydration_mismatch`);
149
+ }
150
+ }
151
+
152
+ /**
153
+ * The `render` function passed to `createRawSnippet` should return HTML for a single element
154
+ */
155
+ export function invalid_raw_snippet_render() {
156
+ if (DEV) {
157
+ console.warn(`%c[svelte] invalid_raw_snippet_render\n%cThe \`render\` function passed to \`createRawSnippet\` should return HTML for a single element\nhttps://svelte.dev/e/invalid_raw_snippet_render`, bold, normal);
158
+ } else {
159
+ console.warn(`https://svelte.dev/e/invalid_raw_snippet_render`);
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Detected a migrated `$:` reactive block in `%filename%` that both accesses and updates the same reactive value. This may cause recursive updates when converted to an `$effect`.
165
+ * @param {string} filename
166
+ */
167
+ export function legacy_recursive_reactive_block(filename) {
168
+ if (DEV) {
169
+ console.warn(`%c[svelte] legacy_recursive_reactive_block\n%cDetected a migrated \`$:\` reactive block in \`${filename}\` that both accesses and updates the same reactive value. This may cause recursive updates when converted to an \`$effect\`.\nhttps://svelte.dev/e/legacy_recursive_reactive_block`, bold, normal);
170
+ } else {
171
+ console.warn(`https://svelte.dev/e/legacy_recursive_reactive_block`);
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Tried to unmount a component that was not mounted
177
+ */
178
+ export function lifecycle_double_unmount() {
179
+ if (DEV) {
180
+ console.warn(`%c[svelte] lifecycle_double_unmount\n%cTried to unmount a component that was not mounted\nhttps://svelte.dev/e/lifecycle_double_unmount`, bold, normal);
181
+ } else {
182
+ console.warn(`https://svelte.dev/e/lifecycle_double_unmount`);
183
+ }
184
+ }
185
+
186
+ /**
187
+ * %parent% passed property `%prop%` to %child% with `bind:`, but its parent component %owner% did not declare `%prop%` as a binding. Consider creating a binding between %owner% and %parent% (e.g. `bind:%prop%={...}` instead of `%prop%={...}`)
188
+ * @param {string} parent
189
+ * @param {string} prop
190
+ * @param {string} child
191
+ * @param {string} owner
192
+ */
193
+ export function ownership_invalid_binding(parent, prop, child, owner) {
194
+ if (DEV) {
195
+ console.warn(`%c[svelte] ownership_invalid_binding\n%c${parent} passed property \`${prop}\` to ${child} with \`bind:\`, but its parent component ${owner} did not declare \`${prop}\` as a binding. Consider creating a binding between ${owner} and ${parent} (e.g. \`bind:${prop}={...}\` instead of \`${prop}={...}\`)\nhttps://svelte.dev/e/ownership_invalid_binding`, bold, normal);
196
+ } else {
197
+ console.warn(`https://svelte.dev/e/ownership_invalid_binding`);
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Mutating unbound props (`%name%`, at %location%) is strongly discouraged. Consider using `bind:%prop%={...}` in %parent% (or using a callback) instead
203
+ * @param {string} name
204
+ * @param {string} location
205
+ * @param {string} prop
206
+ * @param {string} parent
207
+ */
208
+ export function ownership_invalid_mutation(name, location, prop, parent) {
209
+ if (DEV) {
210
+ console.warn(`%c[svelte] ownership_invalid_mutation\n%cMutating unbound props (\`${name}\`, at ${location}) is strongly discouraged. Consider using \`bind:${prop}={...}\` in ${parent} (or using a callback) instead\nhttps://svelte.dev/e/ownership_invalid_mutation`, bold, normal);
211
+ } else {
212
+ console.warn(`https://svelte.dev/e/ownership_invalid_mutation`);
213
+ }
214
+ }
215
+
216
+ /**
217
+ * The `value` property of a `<select multiple>` element should be an array, but it received a non-array value. The selection will be kept as is.
218
+ */
219
+ export function select_multiple_invalid_value() {
220
+ if (DEV) {
221
+ console.warn(`%c[svelte] select_multiple_invalid_value\n%cThe \`value\` property of a \`<select multiple>\` element should be an array, but it received a non-array value. The selection will be kept as is.\nhttps://svelte.dev/e/select_multiple_invalid_value`, bold, normal);
222
+ } else {
223
+ console.warn(`https://svelte.dev/e/select_multiple_invalid_value`);
224
+ }
225
+ }
226
+
227
+ /**
228
+ * Reactive `$state(...)` proxies and the values they proxy have different identities. Because of this, comparisons with `%operator%` will produce unexpected results
229
+ * @param {string} operator
230
+ */
231
+ export function state_proxy_equality_mismatch(operator) {
232
+ if (DEV) {
233
+ console.warn(`%c[svelte] state_proxy_equality_mismatch\n%cReactive \`$state(...)\` proxies and the values they proxy have different identities. Because of this, comparisons with \`${operator}\` will produce unexpected results\nhttps://svelte.dev/e/state_proxy_equality_mismatch`, bold, normal);
234
+ } else {
235
+ console.warn(`https://svelte.dev/e/state_proxy_equality_mismatch`);
236
+ }
237
+ }
238
+
239
+ /**
240
+ * Tried to unmount a state proxy, rather than a component
241
+ */
242
+ export function state_proxy_unmount() {
243
+ if (DEV) {
244
+ console.warn(`%c[svelte] state_proxy_unmount\n%cTried to unmount a state proxy, rather than a component\nhttps://svelte.dev/e/state_proxy_unmount`, bold, normal);
245
+ } else {
246
+ console.warn(`https://svelte.dev/e/state_proxy_unmount`);
247
+ }
248
+ }
249
+
250
+ /**
251
+ * A `<svelte:boundary>` `reset` function only resets the boundary the first time it is called
252
+ */
253
+ export function svelte_boundary_reset_noop() {
254
+ if (DEV) {
255
+ console.warn(`%c[svelte] svelte_boundary_reset_noop\n%cA \`<svelte:boundary>\` \`reset\` function only resets the boundary the first time it is called\nhttps://svelte.dev/e/svelte_boundary_reset_noop`, bold, normal);
256
+ } else {
257
+ console.warn(`https://svelte.dev/e/svelte_boundary_reset_noop`);
258
+ }
259
+ }
260
+
261
+ /**
262
+ * The `slide` transition does not work correctly for elements with `display: %value%`
263
+ * @param {string} value
264
+ */
265
+ export function transition_slide_display(value) {
266
+ if (DEV) {
267
+ console.warn(`%c[svelte] transition_slide_display\n%cThe \`slide\` transition does not work correctly for elements with \`display: ${value}\`\nhttps://svelte.dev/e/transition_slide_display`, bold, normal);
268
+ } else {
269
+ console.warn(`https://svelte.dev/e/transition_slide_display`);
270
+ }
271
+ }
@@ -0,0 +1,6 @@
1
+ import { PUBLIC_VERSION } from '../version.js';
2
+
3
+ if (typeof window !== 'undefined') {
4
+ // @ts-expect-error
5
+ ((window.__svelte ??= {}).v ??= new Set()).add(PUBLIC_VERSION);
6
+ }
@@ -0,0 +1,3 @@
1
+ import { enable_async_mode_flag } from './index.js';
2
+
3
+ enable_async_mode_flag();
@@ -0,0 +1,23 @@
1
+ /** True if experimental.async=true */
2
+ export let async_mode_flag = false;
3
+ /** True if we're not certain that we only have Svelte 5 code in the compilation */
4
+ export let legacy_mode_flag = false;
5
+ /** True if $inspect.trace is used */
6
+ export let tracing_mode_flag = false;
7
+
8
+ export function enable_async_mode_flag() {
9
+ async_mode_flag = true;
10
+ }
11
+
12
+ /** ONLY USE THIS DURING TESTING */
13
+ export function disable_async_mode_flag() {
14
+ async_mode_flag = false;
15
+ }
16
+
17
+ export function enable_legacy_mode_flag() {
18
+ legacy_mode_flag = true;
19
+ }
20
+
21
+ export function enable_tracing_mode_flag() {
22
+ tracing_mode_flag = true;
23
+ }
@@ -0,0 +1,3 @@
1
+ import { enable_legacy_mode_flag } from './index.js';
2
+
3
+ enable_legacy_mode_flag();
@@ -0,0 +1,3 @@
1
+ import { enable_tracing_mode_flag } from './index.js';
2
+
3
+ enable_tracing_mode_flag();
@@ -0,0 +1,5 @@
1
+ // TODO we may, on a best-effort basis, reimplement some of the legacy private APIs here so that certain libraries continue to work. Those APIs will be marked as deprecated (and should noisily warn the user) and will be removed in a future version of Svelte.
2
+
3
+ throw new Error(
4
+ `Your application, or one of its dependencies, imported from 'svelte/internal', which was a private module used by Svelte 4 components that no longer exists in Svelte 5. It is not intended to be public API. If you're a library author and you used 'svelte/internal' deliberately, please raise an issue on https://github.com/sveltejs/svelte/issues detailing your use case.`
5
+ );
@@ -0,0 +1,13 @@
1
+ import { STALE_REACTION } from '#client/constants';
2
+
3
+ /** @type {AbortController | null} */
4
+ let controller = null;
5
+
6
+ export function abort() {
7
+ controller?.abort(STALE_REACTION);
8
+ controller = null;
9
+ }
10
+
11
+ export function getAbortSignal() {
12
+ return (controller ??= new AbortController()).signal;
13
+ }
@@ -0,0 +1,11 @@
1
+ import { DEV } from 'esm-env';
2
+ import { hash } from '../../../utils.js';
3
+
4
+ /**
5
+ * @param {string} value
6
+ */
7
+ export function html(value) {
8
+ var html = String(value ?? '');
9
+ var open = DEV ? `<!--${hash(html)}-->` : '<!---->';
10
+ return open + html + '<!---->';
11
+ }
@@ -0,0 +1,24 @@
1
+ /** @import { Snippet } from 'svelte' */
2
+ /** @import { Renderer } from '../renderer' */
3
+ /** @import { Getters } from '#shared' */
4
+
5
+ /**
6
+ * Create a snippet programmatically
7
+ * @template {unknown[]} Params
8
+ * @param {(...params: Getters<Params>) => {
9
+ * render: () => string
10
+ * setup?: (element: Element) => void | (() => void)
11
+ * }} fn
12
+ * @returns {Snippet<Params>}
13
+ */
14
+ export function createRawSnippet(fn) {
15
+ // @ts-expect-error the types are a lie
16
+ return (/** @type {Renderer} */ renderer, /** @type {Params} */ ...args) => {
17
+ var getters = /** @type {Getters<Params>} */ (args.map((value) => () => value));
18
+ renderer.push(
19
+ fn(...getters)
20
+ .render()
21
+ .trim()
22
+ );
23
+ };
24
+ }
@@ -0,0 +1,132 @@
1
+ /** @import { SSRContext } from '#server' */
2
+ import { DEV } from 'esm-env';
3
+ import * as e from './errors.js';
4
+
5
+ /** @type {SSRContext | null} */
6
+ export var ssr_context = null;
7
+
8
+ /** @param {SSRContext | null} v */
9
+ export function set_ssr_context(v) {
10
+ ssr_context = v;
11
+ }
12
+
13
+ /**
14
+ * @template T
15
+ * @returns {[() => T, (context: T) => T]}
16
+ * @since 5.40.0
17
+ */
18
+ export function createContext() {
19
+ const key = {};
20
+
21
+ return [
22
+ () => {
23
+ if (!hasContext(key)) {
24
+ e.missing_context();
25
+ }
26
+
27
+ return getContext(key);
28
+ },
29
+ (context) => setContext(key, context)
30
+ ];
31
+ }
32
+
33
+ /**
34
+ * @template T
35
+ * @param {any} key
36
+ * @returns {T}
37
+ */
38
+ export function getContext(key) {
39
+ const context_map = get_or_init_context_map('getContext');
40
+ const result = /** @type {T} */ (context_map.get(key));
41
+
42
+ return result;
43
+ }
44
+
45
+ /**
46
+ * @template T
47
+ * @param {any} key
48
+ * @param {T} context
49
+ * @returns {T}
50
+ */
51
+ export function setContext(key, context) {
52
+ get_or_init_context_map('setContext').set(key, context);
53
+ return context;
54
+ }
55
+
56
+ /**
57
+ * @param {any} key
58
+ * @returns {boolean}
59
+ */
60
+ export function hasContext(key) {
61
+ return get_or_init_context_map('hasContext').has(key);
62
+ }
63
+
64
+ /** @returns {Map<any, any>} */
65
+ export function getAllContexts() {
66
+ return get_or_init_context_map('getAllContexts');
67
+ }
68
+
69
+ /**
70
+ * @param {string} name
71
+ * @returns {Map<unknown, unknown>}
72
+ */
73
+ function get_or_init_context_map(name) {
74
+ if (ssr_context === null) {
75
+ e.lifecycle_outside_component(name);
76
+ }
77
+
78
+ return (ssr_context.c ??= new Map(get_parent_context(ssr_context) || undefined));
79
+ }
80
+
81
+ /**
82
+ * @param {Function} [fn]
83
+ */
84
+ export function push(fn) {
85
+ ssr_context = { p: ssr_context, c: null, r: null };
86
+
87
+ if (DEV) {
88
+ ssr_context.function = fn;
89
+ ssr_context.element = ssr_context.p?.element;
90
+ }
91
+ }
92
+
93
+ export function pop() {
94
+ ssr_context = /** @type {SSRContext} */ (ssr_context).p;
95
+ }
96
+
97
+ /**
98
+ * @param {SSRContext} ssr_context
99
+ * @returns {Map<unknown, unknown> | null}
100
+ */
101
+ function get_parent_context(ssr_context) {
102
+ let parent = ssr_context.p;
103
+
104
+ while (parent !== null) {
105
+ const context_map = parent.c;
106
+ if (context_map !== null) {
107
+ return context_map;
108
+ }
109
+ parent = parent.p;
110
+ }
111
+
112
+ return null;
113
+ }
114
+
115
+ /**
116
+ * Wraps an `await` expression in such a way that the component context that was
117
+ * active before the expression evaluated can be reapplied afterwards —
118
+ * `await a + b()` becomes `(await $.save(a))() + b()`, meaning `b()` will have access
119
+ * to the context of its component.
120
+ * @template T
121
+ * @param {Promise<T>} promise
122
+ * @returns {Promise<() => T>}
123
+ */
124
+ export async function save(promise) {
125
+ var previous_context = ssr_context;
126
+ var value = await promise;
127
+
128
+ return () => {
129
+ ssr_context = previous_context;
130
+ return value;
131
+ };
132
+ }
@@ -0,0 +1,45 @@
1
+ import { BROWSER } from 'esm-env';
2
+
3
+ let text_encoder;
4
+ // TODO - remove this and use global `crypto` when we drop Node 18
5
+ let crypto;
6
+
7
+ /** @param {string} module_name */
8
+ const obfuscated_import = (module_name) => import(/* @vite-ignore */ module_name);
9
+
10
+ /** @param {string} data */
11
+ export async function sha256(data) {
12
+ text_encoder ??= new TextEncoder();
13
+
14
+ // @ts-expect-error
15
+ crypto ??= globalThis.crypto?.subtle?.digest
16
+ ? globalThis.crypto
17
+ : // @ts-ignore - we don't install node types in the prod build
18
+ // don't use import('node:crypto') directly because static analysers will think we rely on node when we don't
19
+ (await obfuscated_import('node:crypto')).webcrypto;
20
+
21
+ const hash_buffer = await crypto.subtle.digest('SHA-256', text_encoder.encode(data));
22
+
23
+ return base64_encode(hash_buffer);
24
+ }
25
+
26
+ /**
27
+ * @param {Uint8Array} bytes
28
+ * @returns {string}
29
+ */
30
+ export function base64_encode(bytes) {
31
+ // Using `Buffer` is faster than iterating
32
+ // @ts-ignore
33
+ if (!BROWSER && globalThis.Buffer) {
34
+ // @ts-ignore
35
+ return globalThis.Buffer.from(bytes).toString('base64');
36
+ }
37
+
38
+ let binary = '';
39
+
40
+ for (let i = 0; i < bytes.length; i++) {
41
+ binary += String.fromCharCode(bytes[i]);
42
+ }
43
+
44
+ return btoa(binary);
45
+ }