@vidact/runtime 0.2.0-beta.0 → 0.2.0-beta.5
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 +52 -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 +2672 -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 +70 -58
- package/dist/hydration-bridge.d.ts.map +1 -1
- package/dist/hydration-bridge.js +77 -66
- package/dist/hydration-bridge.js.map +1 -1
- package/dist/hydration.d.ts +54 -28
- package/dist/hydration.d.ts.map +1 -1
- package/dist/hydration.js +450 -463
- 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 +603 -710
- 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 +4041 -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 +196 -0
- package/src/hydration.ts +642 -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 +1160 -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/async.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// oxlint-disable-next-line typescript/triple-slash-reference -- Include compiler feature defines.
|
|
2
|
+
/// <reference path="./env.d.ts" />
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
createResource as createAsyncResource,
|
|
6
|
+
lazy as createLazyComponent,
|
|
7
|
+
useAsync,
|
|
8
|
+
} from './compiled/async-resource.ts'
|
|
9
|
+
import {
|
|
10
|
+
Suspense as createSuspenseComponent,
|
|
11
|
+
createCompiledAsync as createAsyncSlot,
|
|
12
|
+
suspense as createSuspenseBinding,
|
|
13
|
+
} from './compiled/core.ts'
|
|
14
|
+
import {
|
|
15
|
+
ASYNC_RESOURCE,
|
|
16
|
+
type AsyncResourceState,
|
|
17
|
+
type CompiledContext,
|
|
18
|
+
type CompiledRenderValue,
|
|
19
|
+
type CompiledRenderValue as LazyRenderValue,
|
|
20
|
+
type CompiledScope,
|
|
21
|
+
type StructuralBinding,
|
|
22
|
+
} from './compiled/types.ts'
|
|
23
|
+
import type { SourceMask } from './source-mask.ts'
|
|
24
|
+
import type { StateSlot } from './state-slot.ts'
|
|
25
|
+
|
|
26
|
+
export interface AsyncResource<Value> {
|
|
27
|
+
readonly [ASYNC_RESOURCE]: AsyncResourceState<Value>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ResourceOptions {
|
|
31
|
+
readonly cancel?: () => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface LazyModule<Props extends Record<string, unknown>> {
|
|
35
|
+
readonly default: (props: Props) => LazyRenderValue
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function createResource<Value>(
|
|
39
|
+
input: PromiseLike<Value>,
|
|
40
|
+
options: ResourceOptions = {},
|
|
41
|
+
): AsyncResource<Value> {
|
|
42
|
+
return createAsyncResource(input, options)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function use<Value>(
|
|
46
|
+
input: CompiledContext<Value> | AsyncResource<Value> | PromiseLike<Value>,
|
|
47
|
+
): Value {
|
|
48
|
+
return useAsync(input)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function lazy<Props extends Record<string, unknown>>(
|
|
52
|
+
load: () => PromiseLike<LazyModule<Props>>,
|
|
53
|
+
): (props: Props) => CompiledRenderValue {
|
|
54
|
+
return createLazyComponent(load)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function suspense(
|
|
58
|
+
render: () => CompiledRenderValue,
|
|
59
|
+
fallback: () => CompiledRenderValue,
|
|
60
|
+
): StructuralBinding {
|
|
61
|
+
return createSuspenseBinding(render, fallback)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function createCompiledAsync<Value>(
|
|
65
|
+
scope: CompiledScope,
|
|
66
|
+
reads: SourceMask,
|
|
67
|
+
writes: SourceMask,
|
|
68
|
+
evaluate: () => CompiledContext<Value> | AsyncResource<Value> | PromiseLike<Value>,
|
|
69
|
+
): StateSlot<Value> {
|
|
70
|
+
return createAsyncSlot(scope, reads, writes, evaluate)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function Suspense(props: {
|
|
74
|
+
readonly children?: (() => CompiledRenderValue) | readonly [() => CompiledRenderValue]
|
|
75
|
+
readonly fallback: () => CompiledRenderValue
|
|
76
|
+
}): StructuralBinding {
|
|
77
|
+
return createSuspenseComponent(props)
|
|
78
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { isPromiseLike } from '../shared/promise.ts'
|
|
2
|
+
import { DEV, isCompiledContext, useContext } from './core.ts'
|
|
3
|
+
import {
|
|
4
|
+
ASYNC_RESOURCE,
|
|
5
|
+
SUSPENSION,
|
|
6
|
+
type AsyncResource,
|
|
7
|
+
type AsyncResourceState,
|
|
8
|
+
type CompiledContext,
|
|
9
|
+
type CompiledRenderValue,
|
|
10
|
+
type LazyModule,
|
|
11
|
+
type ResourceOptions,
|
|
12
|
+
type Suspension,
|
|
13
|
+
} from './types.ts'
|
|
14
|
+
|
|
15
|
+
const noop = (): void => {}
|
|
16
|
+
const promiseResources = new WeakMap<object, AsyncResource<unknown>>()
|
|
17
|
+
|
|
18
|
+
export function createResource<Value>(
|
|
19
|
+
input: PromiseLike<Value>,
|
|
20
|
+
options: ResourceOptions = {},
|
|
21
|
+
): AsyncResource<Value> {
|
|
22
|
+
if (!isPromiseLike(input)) {
|
|
23
|
+
throw new TypeError(DEV ? 'createResource requires a promise-like value' : 'V029')
|
|
24
|
+
}
|
|
25
|
+
const existing = promiseResources.get(input as object) as AsyncResource<Value> | undefined
|
|
26
|
+
if (existing !== undefined) return existing
|
|
27
|
+
const state: AsyncResourceState<Value> = {
|
|
28
|
+
status: 'pending',
|
|
29
|
+
value: undefined,
|
|
30
|
+
reason: undefined,
|
|
31
|
+
listeners: new Set(),
|
|
32
|
+
cancel: options.cancel,
|
|
33
|
+
subscribers: 0,
|
|
34
|
+
}
|
|
35
|
+
const resource: AsyncResource<Value> = { [ASYNC_RESOURCE]: state }
|
|
36
|
+
promiseResources.set(input as object, resource as AsyncResource<unknown>)
|
|
37
|
+
void Promise.resolve(input).then(
|
|
38
|
+
(value) => settleResource(state, 'fulfilled', value),
|
|
39
|
+
(reason: unknown) => settleResource(state, 'rejected', reason),
|
|
40
|
+
)
|
|
41
|
+
return resource
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function useAsync<Value>(
|
|
45
|
+
input: CompiledContext<Value> | AsyncResource<Value> | PromiseLike<Value>,
|
|
46
|
+
): Value {
|
|
47
|
+
if (isCompiledContext<Value>(input)) return useContext(input)
|
|
48
|
+
return readResource(isAsyncResource<Value>(input) ? input : createResource(input))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function lazy<Props extends Record<string, unknown>>(
|
|
52
|
+
load: () => PromiseLike<LazyModule<Props>>,
|
|
53
|
+
): (props: Props) => CompiledRenderValue {
|
|
54
|
+
let resource: AsyncResource<LazyModule<Props>> | undefined
|
|
55
|
+
return (props) => {
|
|
56
|
+
resource ??= createResource(load())
|
|
57
|
+
const module = readResource(resource)
|
|
58
|
+
if (typeof module?.default !== 'function') {
|
|
59
|
+
throw new TypeError(DEV ? 'lazy loader must resolve to a default component export' : 'V030')
|
|
60
|
+
}
|
|
61
|
+
return module.default(props)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function isAsyncResource<Value>(value: unknown): value is AsyncResource<Value> {
|
|
66
|
+
return typeof value === 'object' && value !== null && ASYNC_RESOURCE in value
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function isSuspension(value: unknown): value is Suspension {
|
|
70
|
+
return typeof value === 'object' && value !== null && SUSPENSION in value
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function readResource<Value>(resource: AsyncResource<Value>): Value {
|
|
74
|
+
const state = resource[ASYNC_RESOURCE]
|
|
75
|
+
if (state.status === 'fulfilled') return state.value as Value
|
|
76
|
+
if (state.status === 'rejected') throw state.reason
|
|
77
|
+
throw { [SUSPENSION]: true, resource } satisfies Suspension
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function subscribeResource(
|
|
81
|
+
resource: AsyncResource<unknown>,
|
|
82
|
+
listener: () => void,
|
|
83
|
+
): () => void {
|
|
84
|
+
const state = resource[ASYNC_RESOURCE]
|
|
85
|
+
if (state.status !== 'pending') {
|
|
86
|
+
queueMicrotask(listener)
|
|
87
|
+
return noop
|
|
88
|
+
}
|
|
89
|
+
let active = true
|
|
90
|
+
state.subscribers += 1
|
|
91
|
+
state.listeners.add(listener)
|
|
92
|
+
return () => {
|
|
93
|
+
if (!active) return
|
|
94
|
+
active = false
|
|
95
|
+
if (state.listeners.delete(listener)) state.subscribers -= 1
|
|
96
|
+
if (state.status === 'pending' && state.subscribers === 0) state.cancel?.()
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function settleResource<Value>(
|
|
101
|
+
state: AsyncResourceState<Value>,
|
|
102
|
+
status: 'fulfilled' | 'rejected',
|
|
103
|
+
result: Value | unknown,
|
|
104
|
+
): void {
|
|
105
|
+
if (state.status !== 'pending') return
|
|
106
|
+
state.status = status
|
|
107
|
+
if (status === 'fulfilled') state.value = result as Value
|
|
108
|
+
else state.reason = result
|
|
109
|
+
const listeners = [...state.listeners]
|
|
110
|
+
state.listeners.clear()
|
|
111
|
+
state.subscribers = 0
|
|
112
|
+
for (const listener of listeners) listener()
|
|
113
|
+
}
|