@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.
Files changed (244) hide show
  1. package/CHANGELOG.md +52 -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 +2672 -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 +70 -58
  100. package/dist/hydration-bridge.d.ts.map +1 -1
  101. package/dist/hydration-bridge.js +77 -66
  102. package/dist/hydration-bridge.js.map +1 -1
  103. package/dist/hydration.d.ts +54 -28
  104. package/dist/hydration.d.ts.map +1 -1
  105. package/dist/hydration.js +450 -463
  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 +603 -710
  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 +4041 -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 +196 -0
  220. package/src/hydration.ts +642 -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 +1160 -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
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
+ }