@vidact/runtime 0.2.0-beta.0 → 0.2.0-beta.4

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 (244) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +1 -1
  3. package/dist/actions.d.ts +32 -30
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +251 -266
  6. package/dist/actions.js.map +1 -1
  7. package/dist/async.d.ts +20 -17
  8. package/dist/async.d.ts.map +1 -1
  9. package/dist/async.js +18 -17
  10. package/dist/async.js.map +1 -1
  11. package/dist/compiled/async-resource.d.ts +9 -6
  12. package/dist/compiled/async-resource.d.ts.map +1 -1
  13. package/dist/compiled/async-resource.js +69 -77
  14. package/dist/compiled/async-resource.js.map +1 -1
  15. package/dist/compiled/core.d.ts +136 -147
  16. package/dist/compiled/core.d.ts.map +1 -1
  17. package/dist/compiled/core.js +2669 -2985
  18. package/dist/compiled/core.js.map +1 -1
  19. package/dist/compiled/types.d.ts +44 -56
  20. package/dist/compiled/types.d.ts.map +1 -1
  21. package/dist/compiled/types.js +10 -6
  22. package/dist/compiled/types.js.map +1 -1
  23. package/dist/compiled/validation.d.ts +4 -1
  24. package/dist/compiled/validation.d.ts.map +1 -1
  25. package/dist/compiled/validation.js +17 -20
  26. package/dist/compiled/validation.js.map +1 -1
  27. package/dist/component-spread.d.ts +5 -3
  28. package/dist/component-spread.d.ts.map +1 -1
  29. package/dist/component-spread.js +49 -67
  30. package/dist/component-spread.js.map +1 -1
  31. package/dist/concurrent.d.ts +20 -18
  32. package/dist/concurrent.d.ts.map +1 -1
  33. package/dist/concurrent.js +191 -210
  34. package/dist/concurrent.js.map +1 -1
  35. package/dist/direct-dom.d.ts +17 -12
  36. package/dist/direct-dom.d.ts.map +1 -1
  37. package/dist/direct-dom.js +187 -221
  38. package/dist/direct-dom.js.map +1 -1
  39. package/dist/dom/attributes.d.ts +9 -6
  40. package/dist/dom/attributes.d.ts.map +1 -1
  41. package/dist/dom/attributes.js +65 -47
  42. package/dist/dom/attributes.js.map +1 -1
  43. package/dist/dom/events.d.ts +5 -2
  44. package/dist/dom/events.d.ts.map +1 -1
  45. package/dist/dom/events.js +53 -65
  46. package/dist/dom/events.js.map +1 -1
  47. package/dist/dom/forms.d.ts +9 -6
  48. package/dist/dom/forms.d.ts.map +1 -1
  49. package/dist/dom/forms.js +152 -198
  50. package/dist/dom/forms.js.map +1 -1
  51. package/dist/dom/intrinsic.d.ts +17 -15
  52. package/dist/dom/intrinsic.d.ts.map +1 -1
  53. package/dist/dom/intrinsic.js +48 -50
  54. package/dist/dom/intrinsic.js.map +1 -1
  55. package/dist/dom/namespace.d.ts +4 -1
  56. package/dist/dom/namespace.d.ts.map +1 -1
  57. package/dist/dom/namespace.js +25 -28
  58. package/dist/dom/namespace.js.map +1 -1
  59. package/dist/dom/namespaces.d.ts +11 -8
  60. package/dist/dom/namespaces.d.ts.map +1 -1
  61. package/dist/dom/namespaces.js +14 -12
  62. package/dist/dom/namespaces.js.map +1 -1
  63. package/dist/dom/properties.d.ts +18 -16
  64. package/dist/dom/properties.d.ts.map +1 -1
  65. package/dist/dom/properties.js +273 -296
  66. package/dist/dom/properties.js.map +1 -1
  67. package/dist/dom/style-properties.d.ts +4 -1
  68. package/dist/dom/style-properties.d.ts.map +1 -1
  69. package/dist/dom/style-properties.js +49 -45
  70. package/dist/dom/style-properties.js.map +1 -1
  71. package/dist/dom/styles.d.ts +5 -2
  72. package/dist/dom/styles.d.ts.map +1 -1
  73. package/dist/dom/styles.js +47 -67
  74. package/dist/dom/styles.js.map +1 -1
  75. package/dist/dom-forms.d.ts +4 -1
  76. package/dist/dom-forms.d.ts.map +1 -1
  77. package/dist/dom-forms.js +16 -13
  78. package/dist/dom-forms.js.map +1 -1
  79. package/dist/dom-styles.d.ts +4 -1
  80. package/dist/dom-styles.d.ts.map +1 -1
  81. package/dist/dom-styles.js +10 -7
  82. package/dist/dom-styles.js.map +1 -1
  83. package/dist/framework-hydrate.d.ts +20 -17
  84. package/dist/framework-hydrate.d.ts.map +1 -1
  85. package/dist/framework-hydrate.js +128 -146
  86. package/dist/framework-hydrate.js.map +1 -1
  87. package/dist/framework-protocol.d.ts +27 -25
  88. package/dist/framework-protocol.d.ts.map +1 -1
  89. package/dist/framework-protocol.js +173 -211
  90. package/dist/framework-protocol.js.map +1 -1
  91. package/dist/framework.d.ts +34 -32
  92. package/dist/framework.d.ts.map +1 -1
  93. package/dist/framework.js +74 -93
  94. package/dist/framework.js.map +1 -1
  95. package/dist/hydrate.d.ts +11 -8
  96. package/dist/hydrate.d.ts.map +1 -1
  97. package/dist/hydrate.js +13 -9
  98. package/dist/hydrate.js.map +1 -1
  99. package/dist/hydration-bridge.d.ts +61 -58
  100. package/dist/hydration-bridge.d.ts.map +1 -1
  101. package/dist/hydration-bridge.js +67 -66
  102. package/dist/hydration-bridge.js.map +1 -1
  103. package/dist/hydration.d.ts +31 -28
  104. package/dist/hydration.d.ts.map +1 -1
  105. package/dist/hydration.js +376 -462
  106. package/dist/hydration.js.map +1 -1
  107. package/dist/index.d.ts +13 -13
  108. package/dist/index.js +11 -13
  109. package/dist/indexed-list.d.ts +8 -5
  110. package/dist/indexed-list.d.ts.map +1 -1
  111. package/dist/indexed-list.js +14 -7
  112. package/dist/indexed-list.js.map +1 -1
  113. package/dist/jsx-runtime.d.ts +10 -8
  114. package/dist/jsx-runtime.d.ts.map +1 -1
  115. package/dist/jsx-runtime.js +28 -23
  116. package/dist/jsx-runtime.js.map +1 -1
  117. package/dist/keyed-list.d.ts +13 -14
  118. package/dist/keyed-list.d.ts.map +1 -1
  119. package/dist/keyed-list.js +132 -160
  120. package/dist/keyed-list.js.map +1 -1
  121. package/dist/metadata.d.ts +6 -3
  122. package/dist/metadata.d.ts.map +1 -1
  123. package/dist/metadata.js +131 -164
  124. package/dist/metadata.js.map +1 -1
  125. package/dist/nested-prop.d.ts +4 -2
  126. package/dist/nested-prop.d.ts.map +1 -1
  127. package/dist/nested-prop.js +17 -16
  128. package/dist/nested-prop.js.map +1 -1
  129. package/dist/profiling.d.ts +11 -8
  130. package/dist/profiling.d.ts.map +1 -1
  131. package/dist/profiling.js +17 -17
  132. package/dist/profiling.js.map +1 -1
  133. package/dist/protocol.d.ts +5 -2
  134. package/dist/protocol.d.ts.map +1 -1
  135. package/dist/protocol.js +8 -5
  136. package/dist/protocol.js.map +1 -1
  137. package/dist/raw-html.d.ts +5 -2
  138. package/dist/raw-html.d.ts.map +1 -1
  139. package/dist/raw-html.js +86 -146
  140. package/dist/raw-html.js.map +1 -1
  141. package/dist/ref.d.ts +8 -3
  142. package/dist/ref.d.ts.map +1 -1
  143. package/dist/ref.js +10 -2
  144. package/dist/ref.js.map +1 -1
  145. package/dist/renderable-protocol.d.ts +26 -8
  146. package/dist/renderable-protocol.d.ts.map +1 -1
  147. package/dist/renderable-protocol.js +30 -9
  148. package/dist/renderable-protocol.js.map +1 -1
  149. package/dist/renderable.d.ts +27 -22
  150. package/dist/renderable.d.ts.map +1 -1
  151. package/dist/renderable.js +141 -133
  152. package/dist/renderable.js.map +1 -1
  153. package/dist/retained-ui.d.ts +9 -6
  154. package/dist/retained-ui.d.ts.map +1 -1
  155. package/dist/retained-ui.js +12 -10
  156. package/dist/retained-ui.js.map +1 -1
  157. package/dist/root.d.ts +18 -15
  158. package/dist/root.d.ts.map +1 -1
  159. package/dist/root.js +73 -85
  160. package/dist/root.js.map +1 -1
  161. package/dist/scheduler.d.ts +10 -8
  162. package/dist/scheduler.d.ts.map +1 -1
  163. package/dist/scheduler.js +97 -105
  164. package/dist/scheduler.js.map +1 -1
  165. package/dist/server-framework.d.ts +45 -42
  166. package/dist/server-framework.d.ts.map +1 -1
  167. package/dist/server-framework.js +209 -217
  168. package/dist/server-framework.js.map +1 -1
  169. package/dist/server.d.ts +130 -128
  170. package/dist/server.d.ts.map +1 -1
  171. package/dist/server.js +592 -706
  172. package/dist/server.js.map +1 -1
  173. package/dist/shared/promise.d.ts +6 -3
  174. package/dist/shared/promise.d.ts.map +1 -1
  175. package/dist/shared/promise.js +21 -19
  176. package/dist/shared/promise.js.map +1 -1
  177. package/dist/source-mask.d.ts +9 -6
  178. package/dist/source-mask.d.ts.map +1 -1
  179. package/dist/source-mask.js +45 -63
  180. package/dist/source-mask.js.map +1 -1
  181. package/dist/spread.d.ts +5 -2
  182. package/dist/spread.d.ts.map +1 -1
  183. package/dist/spread.js +79 -99
  184. package/dist/spread.js.map +1 -1
  185. package/dist/state-slot.d.ts +18 -15
  186. package/dist/state-slot.d.ts.map +1 -1
  187. package/dist/state-slot.js +43 -42
  188. package/dist/state-slot.js.map +1 -1
  189. package/dist/testing.d.ts +9 -6
  190. package/dist/testing.d.ts.map +1 -1
  191. package/dist/testing.js +16 -12
  192. package/dist/testing.js.map +1 -1
  193. package/package.json +8 -7
  194. package/src/actions.ts +415 -0
  195. package/src/async.ts +78 -0
  196. package/src/compiled/async-resource.ts +113 -0
  197. package/src/compiled/core.ts +4026 -0
  198. package/src/compiled/types.ts +96 -0
  199. package/src/compiled/validation.ts +23 -0
  200. package/src/component-spread.ts +86 -0
  201. package/src/concurrent.ts +310 -0
  202. package/src/direct-dom.ts +365 -0
  203. package/src/dom/attributes.ts +55 -0
  204. package/src/dom/events.ts +93 -0
  205. package/src/dom/forms.ts +220 -0
  206. package/src/dom/intrinsic.ts +94 -0
  207. package/src/dom/namespace.ts +30 -0
  208. package/src/dom/namespaces.ts +14 -0
  209. package/src/dom/properties.ts +355 -0
  210. package/src/dom/style-properties.ts +46 -0
  211. package/src/dom/styles.ts +86 -0
  212. package/src/dom-forms.ts +23 -0
  213. package/src/dom-styles.ts +11 -0
  214. package/src/env.d.ts +6 -0
  215. package/src/framework-hydrate.ts +224 -0
  216. package/src/framework-protocol.ts +335 -0
  217. package/src/framework.ts +161 -0
  218. package/src/hydrate.ts +38 -0
  219. package/src/hydration-bridge.ts +183 -0
  220. package/src/hydration.ts +556 -0
  221. package/src/index.ts +92 -0
  222. package/src/indexed-list.ts +20 -0
  223. package/src/jsx-runtime.ts +55 -0
  224. package/src/keyed-list.ts +233 -0
  225. package/src/metadata.ts +212 -0
  226. package/src/nested-prop.ts +27 -0
  227. package/src/profiling.ts +43 -0
  228. package/src/protocol.ts +8 -0
  229. package/src/raw-html.ts +206 -0
  230. package/src/ref.ts +13 -0
  231. package/src/renderable-protocol.ts +63 -0
  232. package/src/renderable.ts +283 -0
  233. package/src/retained-ui.ts +19 -0
  234. package/src/root.ts +122 -0
  235. package/src/scheduler.ts +136 -0
  236. package/src/server-framework.ts +397 -0
  237. package/src/server.ts +1143 -0
  238. package/src/shared/promise.ts +28 -0
  239. package/src/source-mask.ts +83 -0
  240. package/src/spread.ts +131 -0
  241. package/src/state-slot.ts +76 -0
  242. package/src/testing.ts +27 -0
  243. package/dist/index.d.ts.map +0 -1
  244. package/dist/index.js.map +0 -1
@@ -0,0 +1,161 @@
1
+ import type { CompiledComponentResult } from './compiled/types.ts'
2
+ import { installFrameworkMetadata } from './direct-dom.ts'
3
+ import type { FrameworkValue } from './framework-protocol.ts'
4
+ import {
5
+ hoistFrameworkMetadata,
6
+ installFrameworkMetadataPropRekeying,
7
+ isFrameworkMetadataElement,
8
+ } from './metadata.ts'
9
+
10
+ let metadataInstalled = false
11
+ const CLIENT_BOUNDARY_DEFINITION = Symbol('Vidact.ClientBoundaryDefinition')
12
+
13
+ export interface ClientBoundaryDefinition<Props = FrameworkValue, Prepared = unknown> {
14
+ readonly [CLIENT_BOUNDARY_DEFINITION]: true
15
+ readonly prepare?: (props: Props) => Prepared | PromiseLike<Prepared>
16
+ readonly render: (props: Props, prepared: Prepared) => CompiledComponentResult
17
+ }
18
+
19
+ export function defineClientBoundary<Props = FrameworkValue, Prepared = void>(
20
+ render: (props: Props, prepared: Prepared) => CompiledComponentResult,
21
+ prepare?: (props: Props) => Prepared | PromiseLike<Prepared>,
22
+ ): ClientBoundaryDefinition<Props, Prepared> {
23
+ return Object.freeze({
24
+ [CLIENT_BOUNDARY_DEFINITION]: true as const,
25
+ render,
26
+ ...(prepare === undefined ? {} : { prepare }),
27
+ })
28
+ }
29
+
30
+ export function isClientBoundaryDefinition(value: unknown): value is ClientBoundaryDefinition {
31
+ return (
32
+ typeof value === 'object' &&
33
+ value !== null &&
34
+ CLIENT_BOUNDARY_DEFINITION in value &&
35
+ typeof Reflect.get(value, 'render') === 'function'
36
+ )
37
+ }
38
+
39
+ /** @internal */
40
+ export function enableFrameworkMetadata(): void {
41
+ if (metadataInstalled) return
42
+ metadataInstalled = true
43
+ installFrameworkMetadataPropRekeying()
44
+ installFrameworkMetadata((element, props) =>
45
+ isFrameworkMetadataElement(element, props) ? hoistFrameworkMetadata(element) : element,
46
+ )
47
+ }
48
+
49
+ export interface ResourceHintOptions {
50
+ readonly crossOrigin?: '' | 'anonymous' | 'use-credentials'
51
+ }
52
+
53
+ export interface PreloadOptions extends ResourceHintOptions {
54
+ readonly as: string
55
+ readonly fetchPriority?: 'high' | 'low' | 'auto'
56
+ readonly imageSizes?: string
57
+ readonly imageSrcSet?: string
58
+ readonly integrity?: string
59
+ readonly nonce?: string
60
+ readonly referrerPolicy?: string
61
+ readonly type?: string
62
+ }
63
+
64
+ export interface PreinitOptions extends ResourceHintOptions {
65
+ readonly as: 'script' | 'style'
66
+ readonly precedence?: string
67
+ readonly integrity?: string
68
+ readonly nonce?: string
69
+ }
70
+
71
+ export function preconnect(href: string, options: ResourceHintOptions = {}): void {
72
+ appendLink('preconnect', href, options)
73
+ }
74
+
75
+ export function prefetchDNS(href: string): void {
76
+ appendLink('dns-prefetch', href, {})
77
+ }
78
+
79
+ export function preload(href: string, options: PreloadOptions): void {
80
+ appendLink('preload', href, options)
81
+ }
82
+
83
+ export function preloadModule(href: string, options: ResourceHintOptions = {}): void {
84
+ appendLink('modulepreload', href, options)
85
+ }
86
+
87
+ export function preinit(href: string, options: PreinitOptions): void {
88
+ assertHref(href)
89
+ if (options.as === 'style') {
90
+ if (document.head.querySelector(`link[rel="stylesheet"][href="${CSS.escape(href)}"]`)) return
91
+ const link = document.createElement('link')
92
+ link.rel = 'stylesheet'
93
+ link.href = href
94
+ if (options.precedence !== undefined) link.dataset.precedence = options.precedence
95
+ applyResourceOptions(link, options)
96
+ document.head.append(link)
97
+ return
98
+ }
99
+ if (document.head.querySelector(`script[src="${CSS.escape(href)}"]`)) return
100
+ const script = document.createElement('script')
101
+ script.src = href
102
+ applyResourceOptions(script, options)
103
+ document.head.append(script)
104
+ }
105
+
106
+ export function preinitModule(href: string, options: ResourceHintOptions = {}): void {
107
+ assertHref(href)
108
+ if (document.head.querySelector(`script[type="module"][src="${CSS.escape(href)}"]`)) return
109
+ const script = document.createElement('script')
110
+ script.type = 'module'
111
+ script.src = href
112
+ applyResourceOptions(script, options)
113
+ document.head.append(script)
114
+ }
115
+
116
+ function appendLink(
117
+ relation: string,
118
+ href: string,
119
+ options: ResourceHintOptions | PreloadOptions,
120
+ ): void {
121
+ assertHref(href)
122
+ const as = 'as' in options ? options.as : undefined
123
+ const selector = `link[rel="${CSS.escape(relation)}"][href="${CSS.escape(href)}"]${as === undefined ? '' : `[as="${CSS.escape(as)}"]`}`
124
+ if (document.head.querySelector(selector)) return
125
+ const link = document.createElement('link')
126
+ link.rel = relation
127
+ link.href = href
128
+ if (as !== undefined) link.as = as
129
+ applyResourceOptions(link, options)
130
+ document.head.append(link)
131
+ }
132
+
133
+ function applyResourceOptions(
134
+ element: HTMLLinkElement | HTMLScriptElement,
135
+ options: ResourceHintOptions | PreloadOptions | PreinitOptions,
136
+ ): void {
137
+ if (options.crossOrigin !== undefined) element.crossOrigin = options.crossOrigin
138
+ if ('integrity' in options && options.integrity !== undefined)
139
+ element.integrity = options.integrity
140
+ if ('nonce' in options && options.nonce !== undefined) element.nonce = options.nonce
141
+ if (element instanceof HTMLLinkElement) {
142
+ if ('fetchPriority' in options && options.fetchPriority !== undefined) {
143
+ element.fetchPriority = options.fetchPriority
144
+ }
145
+ if ('imageSizes' in options && options.imageSizes !== undefined) {
146
+ element.imageSizes = options.imageSizes
147
+ }
148
+ if ('imageSrcSet' in options && options.imageSrcSet !== undefined) {
149
+ element.imageSrcset = options.imageSrcSet
150
+ }
151
+ if ('referrerPolicy' in options && options.referrerPolicy !== undefined) {
152
+ element.referrerPolicy = options.referrerPolicy
153
+ }
154
+ if ('type' in options && options.type !== undefined) element.type = options.type
155
+ }
156
+ }
157
+
158
+ function assertHref(href: string): void {
159
+ if (typeof href !== 'string' || href.length === 0)
160
+ throw new TypeError('resource href must be non-empty')
161
+ }
package/src/hydrate.ts ADDED
@@ -0,0 +1,38 @@
1
+ import type { MountCompiledOptions } from './compiled/core.ts'
2
+ import type { CompiledComponentResult, CompiledRenderValue } from './compiled/types.ts'
3
+ import type { DirectComponent } from './direct-dom.ts'
4
+ import { installHydration } from './hydration.ts'
5
+ import { createReactElement, type CompiledRenderable } from './renderable.ts'
6
+ import {
7
+ hydrateHotRoot as createHotHydrationRoot,
8
+ hydrateRoot as createHydrationRoot,
9
+ type CompiledRoot,
10
+ type HotContext,
11
+ } from './root.ts'
12
+
13
+ installHydration()
14
+
15
+ export function createElement(
16
+ type: string | symbol | DirectComponent | CompiledRenderable,
17
+ props: Record<string, unknown> | null,
18
+ ...children: CompiledRenderValue[]
19
+ ): CompiledRenderable {
20
+ return createReactElement(type, props, ...children)
21
+ }
22
+
23
+ export function hydrateRoot(
24
+ host: ParentNode,
25
+ application: () => CompiledComponentResult,
26
+ options?: MountCompiledOptions,
27
+ ): CompiledRoot {
28
+ return createHydrationRoot(host, application, options)
29
+ }
30
+
31
+ export function hydrateHotRoot(
32
+ hot: HotContext,
33
+ host: ParentNode,
34
+ application: () => CompiledComponentResult,
35
+ options?: MountCompiledOptions,
36
+ ): CompiledRoot {
37
+ return createHotHydrationRoot(hot, host, application, options)
38
+ }
@@ -0,0 +1,183 @@
1
+ export type HydrationRange = readonly [start: Comment, end: Comment]
2
+
3
+ export interface HydrationOperations {
4
+ readonly begin: (host: ParentNode) => () => void
5
+ readonly finish: () => void
6
+ readonly rootMarkers: () => HydrationRange
7
+ readonly active: () => boolean
8
+ readonly createFragment: (children: readonly unknown[]) => DocumentFragment
9
+ readonly fragmentChildren: (fragment: DocumentFragment) => readonly unknown[] | undefined
10
+ readonly claimElement: (
11
+ localName: string,
12
+ namespace: string | null,
13
+ matches?: (element: Element) => boolean,
14
+ ) => Element | undefined
15
+ readonly noteStructuralParent: () => void
16
+ readonly claimComponentRange: () => HydrationRange | undefined
17
+ readonly withComponentRange: <Result>(range: HydrationRange, operation: () => Result) => Result
18
+ readonly withCursor: <Result>(parent: Node, value: Node | null, operation: () => Result) => Result
19
+ readonly claimNode: (parent: Node, node: Node) => boolean
20
+ readonly claimComponentMount: (parent: Node, start: Comment, end: Comment) => boolean
21
+ readonly claimText: (parent: Node, expected: string) => Text | null | undefined
22
+ readonly claimTextRange: (
23
+ parent: Node,
24
+ expected: string,
25
+ ) => readonly [start: Comment, end: Comment, text: Text | null] | undefined
26
+ readonly claimArrayRange: (parent: Node) => HydrationRange | undefined
27
+ readonly finishArrayRange: (parent: Node, end: Comment) => void
28
+ readonly claimSlotRange: (parent: Node) => HydrationRange | undefined
29
+ readonly borrowSlotRange: (parent: Node, current: boolean) => HydrationRange | undefined
30
+ readonly claimSuspenseFallback: (parent: Node) => Comment | undefined
31
+ readonly withoutHydration: <Result>(operation: () => Result) => Result
32
+ readonly withInsertion: <Result>(parent: Node, before: Node, operation: () => Result) => Result
33
+ readonly insertionPoint: () => readonly [parent: Node, before: Node] | undefined
34
+ readonly cursor: (parent: Node) => Node | null | undefined
35
+ readonly rangeParent: (start: Comment, end: Comment) => Node | undefined
36
+ }
37
+
38
+ export interface HydrationMismatchInfo {
39
+ readonly message: string
40
+ }
41
+
42
+ export class HydrationMismatch extends Error {
43
+ constructor(message: string) {
44
+ super(message)
45
+ this.name = 'HydrationMismatch'
46
+ }
47
+ }
48
+
49
+ let hydration: HydrationOperations | undefined
50
+
51
+ export function beginHydration(host: ParentNode): () => void {
52
+ if (hydration === undefined) throw new Error('hydrate runtime entry is not installed')
53
+ return hydration.begin(host)
54
+ }
55
+
56
+ export function finishHydration(): void {
57
+ hydration?.finish()
58
+ }
59
+
60
+ export function hydrationRootMarkers(): HydrationRange {
61
+ if (hydration === undefined) throw new Error('hydrate runtime entry is not installed')
62
+ return hydration.rootMarkers()
63
+ }
64
+
65
+ export function isHydrating(): boolean {
66
+ return hydration?.active() ?? false
67
+ }
68
+
69
+ export function createHydrationFragment(children: readonly unknown[]): DocumentFragment {
70
+ if (hydration === undefined) throw new Error('hydrate runtime entry is not installed')
71
+ return hydration.createFragment(children)
72
+ }
73
+
74
+ export function hydrationFragmentChildren(
75
+ fragment: DocumentFragment,
76
+ ): readonly unknown[] | undefined {
77
+ return hydration?.fragmentChildren(fragment)
78
+ }
79
+
80
+ export function claimHydrationElement(
81
+ localName: string,
82
+ namespace: string | null,
83
+ matches?: (element: Element) => boolean,
84
+ ): Element | undefined {
85
+ return hydration?.claimElement(localName, namespace, matches)
86
+ }
87
+
88
+ export function noteHydrationStructuralParent(): void {
89
+ hydration?.noteStructuralParent()
90
+ }
91
+
92
+ export function claimHydrationComponentRange(): HydrationRange | undefined {
93
+ return hydration?.claimComponentRange()
94
+ }
95
+
96
+ export function withHydrationComponentRange<Result>(
97
+ range: HydrationRange,
98
+ operation: () => Result,
99
+ ): Result {
100
+ return hydration === undefined ? operation() : hydration.withComponentRange(range, operation)
101
+ }
102
+
103
+ export function withHydrationCursor<Result>(
104
+ parent: Node,
105
+ value: Node | null,
106
+ operation: () => Result,
107
+ ): Result {
108
+ return hydration === undefined ? operation() : hydration.withCursor(parent, value, operation)
109
+ }
110
+
111
+ export function claimHydrationNode(parent: Node, node: Node): boolean {
112
+ return hydration?.claimNode(parent, node) ?? false
113
+ }
114
+
115
+ export function claimHydrationComponentMount(parent: Node, start: Comment, end: Comment): boolean {
116
+ return hydration?.claimComponentMount(parent, start, end) ?? false
117
+ }
118
+
119
+ export function claimHydrationText(parent: Node, expected: string): Text | null | undefined {
120
+ return hydration?.claimText(parent, expected)
121
+ }
122
+
123
+ export function claimHydrationTextRange(
124
+ parent: Node,
125
+ expected: string,
126
+ ): readonly [start: Comment, end: Comment, text: Text | null] | undefined {
127
+ return hydration?.claimTextRange(parent, expected)
128
+ }
129
+
130
+ export function claimHydrationArrayRange(parent: Node): HydrationRange | undefined {
131
+ return hydration?.claimArrayRange(parent)
132
+ }
133
+
134
+ export function finishHydrationArrayRange(parent: Node, end: Comment): void {
135
+ hydration?.finishArrayRange(parent, end)
136
+ }
137
+
138
+ export function claimHydrationSlotRange(parent: Node): HydrationRange | undefined {
139
+ return hydration?.claimSlotRange(parent)
140
+ }
141
+
142
+ export function borrowHydrationSlotRange(
143
+ parent: Node,
144
+ current: boolean,
145
+ ): HydrationRange | undefined {
146
+ return hydration?.borrowSlotRange(parent, current)
147
+ }
148
+
149
+ export function claimHydrationSuspenseFallback(parent: Node): Comment | undefined {
150
+ return hydration?.claimSuspenseFallback(parent)
151
+ }
152
+
153
+ export function withoutHydration<Result>(operation: () => Result): Result {
154
+ return hydration === undefined ? operation() : hydration.withoutHydration(operation)
155
+ }
156
+
157
+ export function withHydrationInsertion<Result>(
158
+ parent: Node,
159
+ before: Node,
160
+ operation: () => Result,
161
+ ): Result {
162
+ return hydration === undefined ? operation() : hydration.withInsertion(parent, before, operation)
163
+ }
164
+
165
+ export function hydrationInsertionPoint(): readonly [parent: Node, before: Node] | undefined {
166
+ return hydration?.insertionPoint()
167
+ }
168
+
169
+ export function hydrationCursor(parent: Node): Node | null | undefined {
170
+ return hydration?.cursor(parent)
171
+ }
172
+
173
+ export function hydrationRangeParent(start: Comment, end: Comment): Node | undefined {
174
+ return hydration?.rangeParent(start, end)
175
+ }
176
+
177
+ export function isHydrationMismatch(error: unknown): error is HydrationMismatch {
178
+ return error instanceof HydrationMismatch
179
+ }
180
+
181
+ export function installHydrationOperations(operations: HydrationOperations): void {
182
+ hydration = operations
183
+ }