@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,66 @@
1
+ export const EACH_ITEM_REACTIVE = 1;
2
+ export const EACH_INDEX_REACTIVE = 1 << 1;
3
+ /** See EachBlock interface metadata.is_controlled for an explanation what this is */
4
+ export const EACH_IS_CONTROLLED = 1 << 2;
5
+ export const EACH_IS_ANIMATED = 1 << 3;
6
+ export const EACH_ITEM_IMMUTABLE = 1 << 4;
7
+
8
+ export const PROPS_IS_IMMUTABLE = 1;
9
+ export const PROPS_IS_RUNES = 1 << 1;
10
+ export const PROPS_IS_UPDATED = 1 << 2;
11
+ export const PROPS_IS_BINDABLE = 1 << 3;
12
+ export const PROPS_IS_LAZY_INITIAL = 1 << 4;
13
+
14
+ export const TRANSITION_IN = 1;
15
+ export const TRANSITION_OUT = 1 << 1;
16
+ export const TRANSITION_GLOBAL = 1 << 2;
17
+
18
+ export const TEMPLATE_FRAGMENT = 1;
19
+ export const TEMPLATE_USE_IMPORT_NODE = 1 << 1;
20
+ export const TEMPLATE_USE_SVG = 1 << 2;
21
+ export const TEMPLATE_USE_MATHML = 1 << 3;
22
+
23
+ export const HYDRATION_START = '[';
24
+ /** used to indicate that an `{:else}...` block was rendered */
25
+ export const HYDRATION_START_ELSE = '[!';
26
+ /** used to indicate that a boundary's `failed` snippet was rendered on the server */
27
+ export const HYDRATION_START_FAILED = '[?';
28
+ export const HYDRATION_END = ']';
29
+ export const HYDRATION_ERROR = {};
30
+
31
+ export const ELEMENT_IS_NAMESPACED = 1;
32
+ export const ELEMENT_PRESERVE_ATTRIBUTE_CASE = 1 << 1;
33
+ export const ELEMENT_IS_INPUT = 1 << 2;
34
+
35
+ export const UNINITIALIZED = Symbol();
36
+
37
+ // Dev-time component properties
38
+ export const FILENAME = Symbol('filename');
39
+ export const HMR = Symbol('hmr');
40
+
41
+ export const NAMESPACE_HTML = 'http://www.w3.org/1999/xhtml';
42
+ export const NAMESPACE_SVG = 'http://www.w3.org/2000/svg';
43
+ export const NAMESPACE_MATHML = 'http://www.w3.org/1998/Math/MathML';
44
+
45
+ // we use a list of ignorable runtime warnings because not every runtime warning
46
+ // can be ignored and we want to keep the validation for svelte-ignore in place
47
+ export const IGNORABLE_RUNTIME_WARNINGS = /** @type {const} */ ([
48
+ 'await_waterfall',
49
+ 'await_reactivity_loss',
50
+ 'state_snapshot_uncloneable',
51
+ 'binding_property_non_reactive',
52
+ 'hydration_attribute_changed',
53
+ 'hydration_html_changed',
54
+ 'ownership_invalid_binding',
55
+ 'ownership_invalid_mutation'
56
+ ]);
57
+
58
+ /**
59
+ * Whitespace inside one of these elements will not result in
60
+ * a whitespace node being created in any circumstances. (This
61
+ * list is almost certainly very incomplete)
62
+ * TODO this is currently unused
63
+ */
64
+ export const ELEMENTS_WITHOUT_TEXT = ['audio', 'datalist', 'dl', 'optgroup', 'select', 'video'];
65
+
66
+ export const ATTACHMENT_KEY = '@attach';
@@ -0,0 +1,286 @@
1
+ /*
2
+ Adapted from https://github.com/mattdesl
3
+ Distributed under MIT License https://github.com/mattdesl/eases/blob/master/LICENSE.md
4
+ */
5
+
6
+ /**
7
+ * @param {number} t
8
+ * @returns {number}
9
+ */
10
+ export function linear(t) {
11
+ return t;
12
+ }
13
+
14
+ /**
15
+ * @param {number} t
16
+ * @returns {number}
17
+ */
18
+ export function backInOut(t) {
19
+ const s = 1.70158 * 1.525;
20
+ if ((t *= 2) < 1) return 0.5 * (t * t * ((s + 1) * t - s));
21
+ return 0.5 * ((t -= 2) * t * ((s + 1) * t + s) + 2);
22
+ }
23
+
24
+ /**
25
+ * @param {number} t
26
+ * @returns {number}
27
+ */
28
+ export function backIn(t) {
29
+ const s = 1.70158;
30
+ return t * t * ((s + 1) * t - s);
31
+ }
32
+
33
+ /**
34
+ * @param {number} t
35
+ * @returns {number}
36
+ */
37
+ export function backOut(t) {
38
+ const s = 1.70158;
39
+ return --t * t * ((s + 1) * t + s) + 1;
40
+ }
41
+
42
+ /**
43
+ * @param {number} t
44
+ * @returns {number}
45
+ */
46
+ export function bounceOut(t) {
47
+ const a = 4.0 / 11.0;
48
+ const b = 8.0 / 11.0;
49
+ const c = 9.0 / 10.0;
50
+ const ca = 4356.0 / 361.0;
51
+ const cb = 35442.0 / 1805.0;
52
+ const cc = 16061.0 / 1805.0;
53
+ const t2 = t * t;
54
+ return t < a
55
+ ? 7.5625 * t2
56
+ : t < b
57
+ ? 9.075 * t2 - 9.9 * t + 3.4
58
+ : t < c
59
+ ? ca * t2 - cb * t + cc
60
+ : 10.8 * t * t - 20.52 * t + 10.72;
61
+ }
62
+
63
+ /**
64
+ * @param {number} t
65
+ * @returns {number}
66
+ */
67
+ export function bounceInOut(t) {
68
+ return t < 0.5 ? 0.5 * (1.0 - bounceOut(1.0 - t * 2.0)) : 0.5 * bounceOut(t * 2.0 - 1.0) + 0.5;
69
+ }
70
+
71
+ /**
72
+ * @param {number} t
73
+ * @returns {number}
74
+ */
75
+ export function bounceIn(t) {
76
+ return 1.0 - bounceOut(1.0 - t);
77
+ }
78
+
79
+ /**
80
+ * @param {number} t
81
+ * @returns {number}
82
+ */
83
+ export function circInOut(t) {
84
+ if ((t *= 2) < 1) return -0.5 * (Math.sqrt(1 - t * t) - 1);
85
+ return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1);
86
+ }
87
+
88
+ /**
89
+ * @param {number} t
90
+ * @returns {number}
91
+ */
92
+ export function circIn(t) {
93
+ return 1.0 - Math.sqrt(1.0 - t * t);
94
+ }
95
+
96
+ /**
97
+ * @param {number} t
98
+ * @returns {number}
99
+ */
100
+ export function circOut(t) {
101
+ return Math.sqrt(1 - --t * t);
102
+ }
103
+
104
+ /**
105
+ * @param {number} t
106
+ * @returns {number}
107
+ */
108
+ export function cubicInOut(t) {
109
+ return t < 0.5 ? 4.0 * t * t * t : 0.5 * Math.pow(2.0 * t - 2.0, 3.0) + 1.0;
110
+ }
111
+
112
+ /**
113
+ * @param {number} t
114
+ * @returns {number}
115
+ */
116
+ export function cubicIn(t) {
117
+ return t * t * t;
118
+ }
119
+
120
+ /**
121
+ * @param {number} t
122
+ * @returns {number}
123
+ */
124
+ export function cubicOut(t) {
125
+ const f = t - 1.0;
126
+ return f * f * f + 1.0;
127
+ }
128
+
129
+ /**
130
+ * @param {number} t
131
+ * @returns {number}
132
+ */
133
+ export function elasticInOut(t) {
134
+ return t < 0.5
135
+ ? 0.5 * Math.sin(((+13.0 * Math.PI) / 2) * 2.0 * t) * Math.pow(2.0, 10.0 * (2.0 * t - 1.0))
136
+ : 0.5 *
137
+ Math.sin(((-13.0 * Math.PI) / 2) * (2.0 * t - 1.0 + 1.0)) *
138
+ Math.pow(2.0, -10.0 * (2.0 * t - 1.0)) +
139
+ 1.0;
140
+ }
141
+
142
+ /**
143
+ * @param {number} t
144
+ * @returns {number}
145
+ */
146
+ export function elasticIn(t) {
147
+ return Math.sin((13.0 * t * Math.PI) / 2) * Math.pow(2.0, 10.0 * (t - 1.0));
148
+ }
149
+
150
+ /**
151
+ * @param {number} t
152
+ * @returns {number}
153
+ */
154
+ export function elasticOut(t) {
155
+ return Math.sin((-13.0 * (t + 1.0) * Math.PI) / 2) * Math.pow(2.0, -10.0 * t) + 1.0;
156
+ }
157
+
158
+ /**
159
+ * @param {number} t
160
+ * @returns {number}
161
+ */
162
+ export function expoInOut(t) {
163
+ return t === 0.0 || t === 1.0
164
+ ? t
165
+ : t < 0.5
166
+ ? +0.5 * Math.pow(2.0, 20.0 * t - 10.0)
167
+ : -0.5 * Math.pow(2.0, 10.0 - t * 20.0) + 1.0;
168
+ }
169
+
170
+ /**
171
+ * @param {number} t
172
+ * @returns {number}
173
+ */
174
+ export function expoIn(t) {
175
+ return t === 0.0 ? t : Math.pow(2.0, 10.0 * (t - 1.0));
176
+ }
177
+
178
+ /**
179
+ * @param {number} t
180
+ * @returns {number}
181
+ */
182
+ export function expoOut(t) {
183
+ return t === 1.0 ? t : 1.0 - Math.pow(2.0, -10.0 * t);
184
+ }
185
+
186
+ /**
187
+ * @param {number} t
188
+ * @returns {number}
189
+ */
190
+ export function quadInOut(t) {
191
+ t /= 0.5;
192
+ if (t < 1) return 0.5 * t * t;
193
+ t--;
194
+ return -0.5 * (t * (t - 2) - 1);
195
+ }
196
+
197
+ /**
198
+ * @param {number} t
199
+ * @returns {number}
200
+ */
201
+ export function quadIn(t) {
202
+ return t * t;
203
+ }
204
+
205
+ /**
206
+ * @param {number} t
207
+ * @returns {number}
208
+ */
209
+ export function quadOut(t) {
210
+ return -t * (t - 2.0);
211
+ }
212
+
213
+ /**
214
+ * @param {number} t
215
+ * @returns {number}
216
+ */
217
+ export function quartInOut(t) {
218
+ return t < 0.5 ? +8.0 * Math.pow(t, 4.0) : -8.0 * Math.pow(t - 1.0, 4.0) + 1.0;
219
+ }
220
+
221
+ /**
222
+ * @param {number} t
223
+ * @returns {number}
224
+ */
225
+ export function quartIn(t) {
226
+ return Math.pow(t, 4.0);
227
+ }
228
+
229
+ /**
230
+ * @param {number} t
231
+ * @returns {number}
232
+ */
233
+ export function quartOut(t) {
234
+ return Math.pow(t - 1.0, 3.0) * (1.0 - t) + 1.0;
235
+ }
236
+
237
+ /**
238
+ * @param {number} t
239
+ * @returns {number}
240
+ */
241
+ export function quintInOut(t) {
242
+ if ((t *= 2) < 1) return 0.5 * t * t * t * t * t;
243
+ return 0.5 * ((t -= 2) * t * t * t * t + 2);
244
+ }
245
+
246
+ /**
247
+ * @param {number} t
248
+ * @returns {number}
249
+ */
250
+ export function quintIn(t) {
251
+ return t * t * t * t * t;
252
+ }
253
+
254
+ /**
255
+ * @param {number} t
256
+ * @returns {number}
257
+ */
258
+ export function quintOut(t) {
259
+ return --t * t * t * t * t + 1;
260
+ }
261
+
262
+ /**
263
+ * @param {number} t
264
+ * @returns {number}
265
+ */
266
+ export function sineInOut(t) {
267
+ return -0.5 * (Math.cos(Math.PI * t) - 1);
268
+ }
269
+
270
+ /**
271
+ * @param {number} t
272
+ * @returns {number}
273
+ */
274
+ export function sineIn(t) {
275
+ const v = Math.cos(t * Math.PI * 0.5);
276
+ if (Math.abs(v) < 1e-14) return 1;
277
+ else return 1 - v;
278
+ }
279
+
280
+ /**
281
+ * @param {number} t
282
+ * @returns {number}
283
+ */
284
+ export function sineOut(t) {
285
+ return Math.sin((t * Math.PI) / 2);
286
+ }
@@ -0,0 +1,26 @@
1
+ const ATTR_REGEX = /[&"<]/g;
2
+ const CONTENT_REGEX = /[&<]/g;
3
+
4
+ /**
5
+ * @template V
6
+ * @param {V} value
7
+ * @param {boolean} [is_attr]
8
+ */
9
+ export function escape_html(value, is_attr) {
10
+ const str = String(value ?? '');
11
+
12
+ const pattern = is_attr ? ATTR_REGEX : CONTENT_REGEX;
13
+ pattern.lastIndex = 0;
14
+
15
+ let escaped = '';
16
+ let last = 0;
17
+
18
+ while (pattern.test(str)) {
19
+ const i = pattern.lastIndex - 1;
20
+ const ch = str[i];
21
+ escaped += str.substring(last, i) + (ch === '&' ? '&amp;' : ch === '"' ? '&quot;' : '&lt;');
22
+ last = i + 1;
23
+ }
24
+
25
+ return escaped + str.substring(last);
26
+ }
@@ -0,0 +1 @@
1
+ export { on } from '../internal/client/dom/elements/events.js';
@@ -0,0 +1,238 @@
1
+ /**
2
+ * Map of elements that have certain elements that are not allowed inside them, in the sense that they will auto-close the parent/ancestor element.
3
+ * Theoretically one could take advantage of it but most of the time it will just result in confusing behavior and break when SSR'd.
4
+ * There are more elements that are invalid inside other elements, but they're not auto-closed and so don't break SSR and are therefore not listed here.
5
+ * @type {Record<string, { direct: string[]} | { descendant: string[]; reset_by?: string[] }>}
6
+ */
7
+ const autoclosing_children = {
8
+ // based on http://developers.whatwg.org/syntax.html#syntax-tag-omission
9
+ li: { direct: ['li'] },
10
+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dt#technical_summary
11
+ dt: { descendant: ['dt', 'dd'], reset_by: ['dl'] },
12
+ dd: { descendant: ['dt', 'dd'], reset_by: ['dl'] },
13
+ p: {
14
+ descendant: [
15
+ 'address',
16
+ 'article',
17
+ 'aside',
18
+ 'blockquote',
19
+ 'div',
20
+ 'dl',
21
+ 'fieldset',
22
+ 'footer',
23
+ 'form',
24
+ 'h1',
25
+ 'h2',
26
+ 'h3',
27
+ 'h4',
28
+ 'h5',
29
+ 'h6',
30
+ 'header',
31
+ 'hgroup',
32
+ 'hr',
33
+ 'main',
34
+ 'menu',
35
+ 'nav',
36
+ 'ol',
37
+ 'p',
38
+ 'pre',
39
+ 'section',
40
+ 'table',
41
+ 'ul'
42
+ ]
43
+ },
44
+ rt: { descendant: ['rt', 'rp'] },
45
+ rp: { descendant: ['rt', 'rp'] },
46
+ optgroup: { descendant: ['optgroup'] },
47
+ option: { descendant: ['option', 'optgroup'] },
48
+ thead: { direct: ['tbody', 'tfoot'] },
49
+ tbody: { direct: ['tbody', 'tfoot'] },
50
+ tfoot: { direct: ['tbody'] },
51
+ tr: { direct: ['tr', 'tbody'] },
52
+ td: { direct: ['td', 'th', 'tr'] },
53
+ th: { direct: ['td', 'th', 'tr'] }
54
+ };
55
+
56
+ /**
57
+ * Returns true if the tag is either the last in the list of siblings and will be autoclosed,
58
+ * or not allowed inside the parent tag such that it will auto-close it. The latter results
59
+ * in the browser repairing the HTML, which will likely result in an error during hydration.
60
+ * @param {string} current
61
+ * @param {string} [next]
62
+ */
63
+ export function closing_tag_omitted(current, next) {
64
+ const disallowed = autoclosing_children[current];
65
+ if (disallowed) {
66
+ if (
67
+ !next ||
68
+ ('direct' in disallowed ? disallowed.direct : disallowed.descendant).includes(next)
69
+ ) {
70
+ return true;
71
+ }
72
+ }
73
+ return false;
74
+ }
75
+
76
+ /**
77
+ * Map of elements that have certain elements that are not allowed inside them, in the sense that the browser will somehow repair the HTML.
78
+ * There are more elements that are invalid inside other elements, but they're not repaired and so don't break SSR and are therefore not listed here.
79
+ * @type {Record<string, { direct: string[]} | { descendant: string[]; reset_by?: string[]; only?: string[] } | { only: string[] }>}
80
+ */
81
+ const disallowed_children = {
82
+ ...autoclosing_children,
83
+ // Strictly speaking, seeing an <option> doesn't mean we're in a <select>, but we assume it here
84
+ // option or optgroup does not have an `only` restriction because newer browsers support rich HTML content
85
+ // inside option elements. For older browsers, hydration will handle the mismatch.
86
+ form: { descendant: ['form'] },
87
+ a: { descendant: ['a'] },
88
+ button: { descendant: ['button'] },
89
+ h1: { descendant: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] },
90
+ h2: { descendant: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] },
91
+ h3: { descendant: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] },
92
+ h4: { descendant: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] },
93
+ h5: { descendant: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] },
94
+ h6: { descendant: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] },
95
+
96
+ // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intd
97
+ // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-incaption
98
+ // No special behavior since these rules fall back to "in body" mode for
99
+ // all except special table nodes which cause bad parsing behavior anyway.
100
+
101
+ // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intd
102
+ tr: { only: ['th', 'td', 'style', 'script', 'template'] },
103
+ // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intbody
104
+ tbody: { only: ['tr', 'style', 'script', 'template'] },
105
+ thead: { only: ['tr', 'style', 'script', 'template'] },
106
+ tfoot: { only: ['tr', 'style', 'script', 'template'] },
107
+ // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-incolgroup
108
+ colgroup: { only: ['col', 'template'] },
109
+ // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intable
110
+ table: {
111
+ only: ['caption', 'colgroup', 'tbody', 'thead', 'tfoot', 'style', 'script', 'template']
112
+ },
113
+ // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inhead
114
+ head: {
115
+ only: [
116
+ 'base',
117
+ 'basefont',
118
+ 'bgsound',
119
+ 'link',
120
+ 'meta',
121
+ 'title',
122
+ 'noscript',
123
+ 'noframes',
124
+ 'style',
125
+ 'script',
126
+ 'template'
127
+ ]
128
+ },
129
+ // https://html.spec.whatwg.org/multipage/semantics.html#the-html-element
130
+ html: { only: ['head', 'body', 'frameset'] },
131
+ frameset: { only: ['frame'] },
132
+ '#document': { only: ['html'] }
133
+ };
134
+
135
+ /**
136
+ * Returns an error message if the tag is not allowed inside the ancestor tag (which is grandparent and above) such that it will result
137
+ * in the browser repairing the HTML, which will likely result in an error during hydration.
138
+ * @param {string} child_tag
139
+ * @param {string[]} ancestors All nodes starting with the parent, up until the ancestor, which means two entries minimum
140
+ * @param {string} [child_loc]
141
+ * @param {string} [ancestor_loc]
142
+ * @returns {string | null}
143
+ */
144
+ export function is_tag_valid_with_ancestor(child_tag, ancestors, child_loc, ancestor_loc) {
145
+ if (child_tag.includes('-')) return null; // custom elements can be anything
146
+
147
+ const ancestor_tag = ancestors[ancestors.length - 1];
148
+ const disallowed = disallowed_children[ancestor_tag];
149
+ if (!disallowed) return null;
150
+
151
+ if ('reset_by' in disallowed && disallowed.reset_by) {
152
+ for (let i = ancestors.length - 2; i >= 0; i--) {
153
+ const ancestor = ancestors[i];
154
+ if (ancestor.includes('-')) return null; // custom elements can be anything
155
+
156
+ // A reset means that forbidden descendants are allowed again
157
+ if (disallowed.reset_by.includes(ancestors[i])) {
158
+ return null;
159
+ }
160
+ }
161
+ }
162
+
163
+ if ('descendant' in disallowed && disallowed.descendant.includes(child_tag)) {
164
+ const child = child_loc ? `\`<${child_tag}>\` (${child_loc})` : `\`<${child_tag}>\``;
165
+ const ancestor = ancestor_loc
166
+ ? `\`<${ancestor_tag}>\` (${ancestor_loc})`
167
+ : `\`<${ancestor_tag}>\``;
168
+
169
+ return `${child} cannot be a descendant of ${ancestor}`;
170
+ }
171
+
172
+ return null;
173
+ }
174
+
175
+ /**
176
+ * Returns an error message if the tag is not allowed inside the parent tag such that it will result
177
+ * in the browser repairing the HTML, which will likely result in an error during hydration.
178
+ * @param {string} child_tag
179
+ * @param {string} parent_tag
180
+ * @param {string} [child_loc]
181
+ * @param {string} [parent_loc]
182
+ * @returns {string | null}
183
+ */
184
+ export function is_tag_valid_with_parent(child_tag, parent_tag, child_loc, parent_loc) {
185
+ if (child_tag.includes('-') || parent_tag?.includes('-')) return null; // custom elements can be anything
186
+
187
+ if (parent_tag === 'template') return null; // no errors or warning should be thrown in immediate children of template tags
188
+
189
+ const disallowed = disallowed_children[parent_tag];
190
+
191
+ const child = child_loc ? `\`<${child_tag}>\` (${child_loc})` : `\`<${child_tag}>\``;
192
+ const parent = parent_loc ? `\`<${parent_tag}>\` (${parent_loc})` : `\`<${parent_tag}>\``;
193
+
194
+ if (disallowed) {
195
+ if ('direct' in disallowed && disallowed.direct.includes(child_tag)) {
196
+ return `${child} cannot be a direct child of ${parent}`;
197
+ }
198
+
199
+ if ('descendant' in disallowed && disallowed.descendant.includes(child_tag)) {
200
+ return `${child} cannot be a child of ${parent}`;
201
+ }
202
+
203
+ if ('only' in disallowed && disallowed.only) {
204
+ if (disallowed.only.includes(child_tag)) {
205
+ return null;
206
+ } else {
207
+ return `${child} cannot be a child of ${parent}. \`<${parent_tag}>\` only allows these children: ${disallowed.only.map((d) => `\`<${d}>\``).join(', ')}`;
208
+ }
209
+ }
210
+ }
211
+
212
+ // These tags are only valid with a few parents that have special child
213
+ // parsing rules - if we're down here, then none of those matched and
214
+ // so we allow it only if we don't know what the parent is, as all other
215
+ // cases are invalid (and we only get into this function if we know the parent).
216
+ switch (child_tag) {
217
+ case 'body':
218
+ case 'caption':
219
+ case 'col':
220
+ case 'colgroup':
221
+ case 'frameset':
222
+ case 'frame':
223
+ case 'head':
224
+ case 'html':
225
+ return `${child} cannot be a child of ${parent}`;
226
+ case 'thead':
227
+ case 'tbody':
228
+ case 'tfoot':
229
+ return `${child} must be the child of a \`<table>\`, not a ${parent}`;
230
+ case 'td':
231
+ case 'th':
232
+ return `${child} must be the child of a \`<tr>\`, not a ${parent}`;
233
+ case 'tr':
234
+ return `\`<tr>\` must be the child of a \`<thead>\`, \`<tbody>\`, or \`<tfoot>\`, not a ${parent}`;
235
+ }
236
+
237
+ return null;
238
+ }