@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.
- package/CHANGELOG.md +37 -0
- package/README.md +1 -1
- package/dist/actions.d.ts +32 -30
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +251 -266
- package/dist/actions.js.map +1 -1
- package/dist/async.d.ts +20 -17
- package/dist/async.d.ts.map +1 -1
- package/dist/async.js +18 -17
- package/dist/async.js.map +1 -1
- package/dist/compiled/async-resource.d.ts +9 -6
- package/dist/compiled/async-resource.d.ts.map +1 -1
- package/dist/compiled/async-resource.js +69 -77
- package/dist/compiled/async-resource.js.map +1 -1
- package/dist/compiled/core.d.ts +136 -147
- package/dist/compiled/core.d.ts.map +1 -1
- package/dist/compiled/core.js +2669 -2985
- package/dist/compiled/core.js.map +1 -1
- package/dist/compiled/types.d.ts +44 -56
- package/dist/compiled/types.d.ts.map +1 -1
- package/dist/compiled/types.js +10 -6
- package/dist/compiled/types.js.map +1 -1
- package/dist/compiled/validation.d.ts +4 -1
- package/dist/compiled/validation.d.ts.map +1 -1
- package/dist/compiled/validation.js +17 -20
- package/dist/compiled/validation.js.map +1 -1
- package/dist/component-spread.d.ts +5 -3
- package/dist/component-spread.d.ts.map +1 -1
- package/dist/component-spread.js +49 -67
- package/dist/component-spread.js.map +1 -1
- package/dist/concurrent.d.ts +20 -18
- package/dist/concurrent.d.ts.map +1 -1
- package/dist/concurrent.js +191 -210
- package/dist/concurrent.js.map +1 -1
- package/dist/direct-dom.d.ts +17 -12
- package/dist/direct-dom.d.ts.map +1 -1
- package/dist/direct-dom.js +187 -221
- package/dist/direct-dom.js.map +1 -1
- package/dist/dom/attributes.d.ts +9 -6
- package/dist/dom/attributes.d.ts.map +1 -1
- package/dist/dom/attributes.js +65 -47
- package/dist/dom/attributes.js.map +1 -1
- package/dist/dom/events.d.ts +5 -2
- package/dist/dom/events.d.ts.map +1 -1
- package/dist/dom/events.js +53 -65
- package/dist/dom/events.js.map +1 -1
- package/dist/dom/forms.d.ts +9 -6
- package/dist/dom/forms.d.ts.map +1 -1
- package/dist/dom/forms.js +152 -198
- package/dist/dom/forms.js.map +1 -1
- package/dist/dom/intrinsic.d.ts +17 -15
- package/dist/dom/intrinsic.d.ts.map +1 -1
- package/dist/dom/intrinsic.js +48 -50
- package/dist/dom/intrinsic.js.map +1 -1
- package/dist/dom/namespace.d.ts +4 -1
- package/dist/dom/namespace.d.ts.map +1 -1
- package/dist/dom/namespace.js +25 -28
- package/dist/dom/namespace.js.map +1 -1
- package/dist/dom/namespaces.d.ts +11 -8
- package/dist/dom/namespaces.d.ts.map +1 -1
- package/dist/dom/namespaces.js +14 -12
- package/dist/dom/namespaces.js.map +1 -1
- package/dist/dom/properties.d.ts +18 -16
- package/dist/dom/properties.d.ts.map +1 -1
- package/dist/dom/properties.js +273 -296
- package/dist/dom/properties.js.map +1 -1
- package/dist/dom/style-properties.d.ts +4 -1
- package/dist/dom/style-properties.d.ts.map +1 -1
- package/dist/dom/style-properties.js +49 -45
- package/dist/dom/style-properties.js.map +1 -1
- package/dist/dom/styles.d.ts +5 -2
- package/dist/dom/styles.d.ts.map +1 -1
- package/dist/dom/styles.js +47 -67
- package/dist/dom/styles.js.map +1 -1
- package/dist/dom-forms.d.ts +4 -1
- package/dist/dom-forms.d.ts.map +1 -1
- package/dist/dom-forms.js +16 -13
- package/dist/dom-forms.js.map +1 -1
- package/dist/dom-styles.d.ts +4 -1
- package/dist/dom-styles.d.ts.map +1 -1
- package/dist/dom-styles.js +10 -7
- package/dist/dom-styles.js.map +1 -1
- package/dist/framework-hydrate.d.ts +20 -17
- package/dist/framework-hydrate.d.ts.map +1 -1
- package/dist/framework-hydrate.js +128 -146
- package/dist/framework-hydrate.js.map +1 -1
- package/dist/framework-protocol.d.ts +27 -25
- package/dist/framework-protocol.d.ts.map +1 -1
- package/dist/framework-protocol.js +173 -211
- package/dist/framework-protocol.js.map +1 -1
- package/dist/framework.d.ts +34 -32
- package/dist/framework.d.ts.map +1 -1
- package/dist/framework.js +74 -93
- package/dist/framework.js.map +1 -1
- package/dist/hydrate.d.ts +11 -8
- package/dist/hydrate.d.ts.map +1 -1
- package/dist/hydrate.js +13 -9
- package/dist/hydrate.js.map +1 -1
- package/dist/hydration-bridge.d.ts +61 -58
- package/dist/hydration-bridge.d.ts.map +1 -1
- package/dist/hydration-bridge.js +67 -66
- package/dist/hydration-bridge.js.map +1 -1
- package/dist/hydration.d.ts +31 -28
- package/dist/hydration.d.ts.map +1 -1
- package/dist/hydration.js +376 -462
- package/dist/hydration.js.map +1 -1
- package/dist/index.d.ts +13 -13
- package/dist/index.js +11 -13
- package/dist/indexed-list.d.ts +8 -5
- package/dist/indexed-list.d.ts.map +1 -1
- package/dist/indexed-list.js +14 -7
- package/dist/indexed-list.js.map +1 -1
- package/dist/jsx-runtime.d.ts +10 -8
- package/dist/jsx-runtime.d.ts.map +1 -1
- package/dist/jsx-runtime.js +28 -23
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/keyed-list.d.ts +13 -14
- package/dist/keyed-list.d.ts.map +1 -1
- package/dist/keyed-list.js +132 -160
- package/dist/keyed-list.js.map +1 -1
- package/dist/metadata.d.ts +6 -3
- package/dist/metadata.d.ts.map +1 -1
- package/dist/metadata.js +131 -164
- package/dist/metadata.js.map +1 -1
- package/dist/nested-prop.d.ts +4 -2
- package/dist/nested-prop.d.ts.map +1 -1
- package/dist/nested-prop.js +17 -16
- package/dist/nested-prop.js.map +1 -1
- package/dist/profiling.d.ts +11 -8
- package/dist/profiling.d.ts.map +1 -1
- package/dist/profiling.js +17 -17
- package/dist/profiling.js.map +1 -1
- package/dist/protocol.d.ts +5 -2
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +8 -5
- package/dist/protocol.js.map +1 -1
- package/dist/raw-html.d.ts +5 -2
- package/dist/raw-html.d.ts.map +1 -1
- package/dist/raw-html.js +86 -146
- package/dist/raw-html.js.map +1 -1
- package/dist/ref.d.ts +8 -3
- package/dist/ref.d.ts.map +1 -1
- package/dist/ref.js +10 -2
- package/dist/ref.js.map +1 -1
- package/dist/renderable-protocol.d.ts +26 -8
- package/dist/renderable-protocol.d.ts.map +1 -1
- package/dist/renderable-protocol.js +30 -9
- package/dist/renderable-protocol.js.map +1 -1
- package/dist/renderable.d.ts +27 -22
- package/dist/renderable.d.ts.map +1 -1
- package/dist/renderable.js +141 -133
- package/dist/renderable.js.map +1 -1
- package/dist/retained-ui.d.ts +9 -6
- package/dist/retained-ui.d.ts.map +1 -1
- package/dist/retained-ui.js +12 -10
- package/dist/retained-ui.js.map +1 -1
- package/dist/root.d.ts +18 -15
- package/dist/root.d.ts.map +1 -1
- package/dist/root.js +73 -85
- package/dist/root.js.map +1 -1
- package/dist/scheduler.d.ts +10 -8
- package/dist/scheduler.d.ts.map +1 -1
- package/dist/scheduler.js +97 -105
- package/dist/scheduler.js.map +1 -1
- package/dist/server-framework.d.ts +45 -42
- package/dist/server-framework.d.ts.map +1 -1
- package/dist/server-framework.js +209 -217
- package/dist/server-framework.js.map +1 -1
- package/dist/server.d.ts +130 -128
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +592 -706
- package/dist/server.js.map +1 -1
- package/dist/shared/promise.d.ts +6 -3
- package/dist/shared/promise.d.ts.map +1 -1
- package/dist/shared/promise.js +21 -19
- package/dist/shared/promise.js.map +1 -1
- package/dist/source-mask.d.ts +9 -6
- package/dist/source-mask.d.ts.map +1 -1
- package/dist/source-mask.js +45 -63
- package/dist/source-mask.js.map +1 -1
- package/dist/spread.d.ts +5 -2
- package/dist/spread.d.ts.map +1 -1
- package/dist/spread.js +79 -99
- package/dist/spread.js.map +1 -1
- package/dist/state-slot.d.ts +18 -15
- package/dist/state-slot.d.ts.map +1 -1
- package/dist/state-slot.js +43 -42
- package/dist/state-slot.js.map +1 -1
- package/dist/testing.d.ts +9 -6
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +16 -12
- package/dist/testing.js.map +1 -1
- package/package.json +8 -7
- package/src/actions.ts +415 -0
- package/src/async.ts +78 -0
- package/src/compiled/async-resource.ts +113 -0
- package/src/compiled/core.ts +4026 -0
- package/src/compiled/types.ts +96 -0
- package/src/compiled/validation.ts +23 -0
- package/src/component-spread.ts +86 -0
- package/src/concurrent.ts +310 -0
- package/src/direct-dom.ts +365 -0
- package/src/dom/attributes.ts +55 -0
- package/src/dom/events.ts +93 -0
- package/src/dom/forms.ts +220 -0
- package/src/dom/intrinsic.ts +94 -0
- package/src/dom/namespace.ts +30 -0
- package/src/dom/namespaces.ts +14 -0
- package/src/dom/properties.ts +355 -0
- package/src/dom/style-properties.ts +46 -0
- package/src/dom/styles.ts +86 -0
- package/src/dom-forms.ts +23 -0
- package/src/dom-styles.ts +11 -0
- package/src/env.d.ts +6 -0
- package/src/framework-hydrate.ts +224 -0
- package/src/framework-protocol.ts +335 -0
- package/src/framework.ts +161 -0
- package/src/hydrate.ts +38 -0
- package/src/hydration-bridge.ts +183 -0
- package/src/hydration.ts +556 -0
- package/src/index.ts +92 -0
- package/src/indexed-list.ts +20 -0
- package/src/jsx-runtime.ts +55 -0
- package/src/keyed-list.ts +233 -0
- package/src/metadata.ts +212 -0
- package/src/nested-prop.ts +27 -0
- package/src/profiling.ts +43 -0
- package/src/protocol.ts +8 -0
- package/src/raw-html.ts +206 -0
- package/src/ref.ts +13 -0
- package/src/renderable-protocol.ts +63 -0
- package/src/renderable.ts +283 -0
- package/src/retained-ui.ts +19 -0
- package/src/root.ts +122 -0
- package/src/scheduler.ts +136 -0
- package/src/server-framework.ts +397 -0
- package/src/server.ts +1143 -0
- package/src/shared/promise.ts +28 -0
- package/src/source-mask.ts +83 -0
- package/src/spread.ts +131 -0
- package/src/state-slot.ts +76 -0
- package/src/testing.ts +27 -0
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/src/framework.ts
ADDED
|
@@ -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
|
+
}
|