@vidact/runtime 0.2.0-beta.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 (197) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +50 -0
  4. package/dist/actions.d.ts +37 -0
  5. package/dist/actions.d.ts.map +1 -0
  6. package/dist/actions.js +295 -0
  7. package/dist/actions.js.map +1 -0
  8. package/dist/async.d.ts +22 -0
  9. package/dist/async.d.ts.map +1 -0
  10. package/dist/async.js +24 -0
  11. package/dist/async.js.map +1 -0
  12. package/dist/compiled/async-resource.d.ts +7 -0
  13. package/dist/compiled/async-resource.d.ts.map +1 -0
  14. package/dist/compiled/async-resource.js +89 -0
  15. package/dist/compiled/async-resource.js.map +1 -0
  16. package/dist/compiled/core.d.ts +183 -0
  17. package/dist/compiled/core.d.ts.map +1 -0
  18. package/dist/compiled/core.js +3170 -0
  19. package/dist/compiled/core.js.map +1 -0
  20. package/dist/compiled/types.d.ts +63 -0
  21. package/dist/compiled/types.d.ts.map +1 -0
  22. package/dist/compiled/types.js +7 -0
  23. package/dist/compiled/types.js.map +1 -0
  24. package/dist/compiled/validation.d.ts +2 -0
  25. package/dist/compiled/validation.d.ts.map +1 -0
  26. package/dist/compiled/validation.js +22 -0
  27. package/dist/compiled/validation.js.map +1 -0
  28. package/dist/component-spread.d.ts +6 -0
  29. package/dist/component-spread.d.ts.map +1 -0
  30. package/dist/component-spread.js +71 -0
  31. package/dist/component-spread.js.map +1 -0
  32. package/dist/concurrent.d.ts +26 -0
  33. package/dist/concurrent.d.ts.map +1 -0
  34. package/dist/concurrent.js +244 -0
  35. package/dist/concurrent.js.map +1 -0
  36. package/dist/direct-dom.d.ts +14 -0
  37. package/dist/direct-dom.d.ts.map +1 -0
  38. package/dist/direct-dom.js +239 -0
  39. package/dist/direct-dom.js.map +1 -0
  40. package/dist/dom/attributes.d.ts +7 -0
  41. package/dist/dom/attributes.d.ts.map +1 -0
  42. package/dist/dom/attributes.js +52 -0
  43. package/dist/dom/attributes.js.map +1 -0
  44. package/dist/dom/events.d.ts +3 -0
  45. package/dist/dom/events.d.ts.map +1 -0
  46. package/dist/dom/events.js +78 -0
  47. package/dist/dom/events.js.map +1 -0
  48. package/dist/dom/forms.d.ts +7 -0
  49. package/dist/dom/forms.d.ts.map +1 -0
  50. package/dist/dom/forms.js +217 -0
  51. package/dist/dom/forms.js.map +1 -0
  52. package/dist/dom/intrinsic.d.ts +19 -0
  53. package/dist/dom/intrinsic.d.ts.map +1 -0
  54. package/dist/dom/intrinsic.js +53 -0
  55. package/dist/dom/intrinsic.js.map +1 -0
  56. package/dist/dom/namespace.d.ts +3 -0
  57. package/dist/dom/namespace.d.ts.map +1 -0
  58. package/dist/dom/namespace.js +34 -0
  59. package/dist/dom/namespace.js.map +1 -0
  60. package/dist/dom/namespaces.d.ts +9 -0
  61. package/dist/dom/namespaces.d.ts.map +1 -0
  62. package/dist/dom/namespaces.js +14 -0
  63. package/dist/dom/namespaces.js.map +1 -0
  64. package/dist/dom/properties.d.ts +27 -0
  65. package/dist/dom/properties.d.ts.map +1 -0
  66. package/dist/dom/properties.js +333 -0
  67. package/dist/dom/properties.js.map +1 -0
  68. package/dist/dom/style-properties.d.ts +2 -0
  69. package/dist/dom/style-properties.d.ts.map +1 -0
  70. package/dist/dom/style-properties.js +47 -0
  71. package/dist/dom/style-properties.js.map +1 -0
  72. package/dist/dom/styles.d.ts +4 -0
  73. package/dist/dom/styles.d.ts.map +1 -0
  74. package/dist/dom/styles.js +77 -0
  75. package/dist/dom/styles.js.map +1 -0
  76. package/dist/dom-forms.d.ts +3 -0
  77. package/dist/dom-forms.d.ts.map +1 -0
  78. package/dist/dom-forms.js +17 -0
  79. package/dist/dom-forms.js.map +1 -0
  80. package/dist/dom-styles.d.ts +3 -0
  81. package/dist/dom-styles.d.ts.map +1 -0
  82. package/dist/dom-styles.js +11 -0
  83. package/dist/dom-styles.js.map +1 -0
  84. package/dist/env.d.ts +6 -0
  85. package/dist/framework-hydrate.d.ts +21 -0
  86. package/dist/framework-hydrate.d.ts.map +1 -0
  87. package/dist/framework-hydrate.js +165 -0
  88. package/dist/framework-hydrate.js.map +1 -0
  89. package/dist/framework-protocol.d.ts +33 -0
  90. package/dist/framework-protocol.d.ts.map +1 -0
  91. package/dist/framework-protocol.js +235 -0
  92. package/dist/framework-protocol.js.map +1 -0
  93. package/dist/framework.d.ts +39 -0
  94. package/dist/framework.d.ts.map +1 -0
  95. package/dist/framework.js +111 -0
  96. package/dist/framework.js.map +1 -0
  97. package/dist/hydrate.d.ts +9 -0
  98. package/dist/hydrate.d.ts.map +1 -0
  99. package/dist/hydrate.js +14 -0
  100. package/dist/hydrate.js.map +1 -0
  101. package/dist/hydration-bridge.d.ts +62 -0
  102. package/dist/hydration-bridge.d.ts.map +1 -0
  103. package/dist/hydration-bridge.js +95 -0
  104. package/dist/hydration-bridge.js.map +1 -0
  105. package/dist/hydration.d.ts +29 -0
  106. package/dist/hydration.d.ts.map +1 -0
  107. package/dist/hydration.js +489 -0
  108. package/dist/hydration.js.map +1 -0
  109. package/dist/index.d.ts +13 -0
  110. package/dist/index.d.ts.map +1 -0
  111. package/dist/index.js +13 -0
  112. package/dist/index.js.map +1 -0
  113. package/dist/indexed-list.d.ts +12 -0
  114. package/dist/indexed-list.d.ts.map +1 -0
  115. package/dist/indexed-list.js +10 -0
  116. package/dist/indexed-list.js.map +1 -0
  117. package/dist/jsx-runtime.d.ts +12 -0
  118. package/dist/jsx-runtime.d.ts.map +1 -0
  119. package/dist/jsx-runtime.js +27 -0
  120. package/dist/jsx-runtime.js.map +1 -0
  121. package/dist/keyed-list.d.ts +17 -0
  122. package/dist/keyed-list.d.ts.map +1 -0
  123. package/dist/keyed-list.js +180 -0
  124. package/dist/keyed-list.js.map +1 -0
  125. package/dist/metadata.d.ts +4 -0
  126. package/dist/metadata.d.ts.map +1 -0
  127. package/dist/metadata.js +187 -0
  128. package/dist/metadata.js.map +1 -0
  129. package/dist/nested-prop.d.ts +4 -0
  130. package/dist/nested-prop.d.ts.map +1 -0
  131. package/dist/nested-prop.js +18 -0
  132. package/dist/nested-prop.js.map +1 -0
  133. package/dist/profiling.d.ts +10 -0
  134. package/dist/profiling.d.ts.map +1 -0
  135. package/dist/profiling.js +21 -0
  136. package/dist/profiling.js.map +1 -0
  137. package/dist/protocol.d.ts +3 -0
  138. package/dist/protocol.d.ts.map +1 -0
  139. package/dist/protocol.js +7 -0
  140. package/dist/protocol.js.map +1 -0
  141. package/dist/raw-html.d.ts +3 -0
  142. package/dist/raw-html.d.ts.map +1 -0
  143. package/dist/raw-html.js +172 -0
  144. package/dist/raw-html.js.map +1 -0
  145. package/dist/ref.d.ts +6 -0
  146. package/dist/ref.d.ts.map +1 -0
  147. package/dist/ref.js +5 -0
  148. package/dist/ref.js.map +1 -0
  149. package/dist/renderable-protocol.d.ts +10 -0
  150. package/dist/renderable-protocol.d.ts.map +1 -0
  151. package/dist/renderable-protocol.js +12 -0
  152. package/dist/renderable-protocol.js.map +1 -0
  153. package/dist/renderable.d.ts +27 -0
  154. package/dist/renderable.d.ts.map +1 -0
  155. package/dist/renderable.js +147 -0
  156. package/dist/renderable.js.map +1 -0
  157. package/dist/retained-ui.d.ts +8 -0
  158. package/dist/retained-ui.d.ts.map +1 -0
  159. package/dist/retained-ui.js +12 -0
  160. package/dist/retained-ui.js.map +1 -0
  161. package/dist/root.d.ts +18 -0
  162. package/dist/root.d.ts.map +1 -0
  163. package/dist/root.js +94 -0
  164. package/dist/root.js.map +1 -0
  165. package/dist/scheduler.d.ts +10 -0
  166. package/dist/scheduler.d.ts.map +1 -0
  167. package/dist/scheduler.js +124 -0
  168. package/dist/scheduler.js.map +1 -0
  169. package/dist/server-framework.d.ts +52 -0
  170. package/dist/server-framework.d.ts.map +1 -0
  171. package/dist/server-framework.js +247 -0
  172. package/dist/server-framework.js.map +1 -0
  173. package/dist/server.d.ts +159 -0
  174. package/dist/server.d.ts.map +1 -0
  175. package/dist/server.js +793 -0
  176. package/dist/server.js.map +1 -0
  177. package/dist/shared/promise.d.ts +4 -0
  178. package/dist/shared/promise.d.ts.map +1 -0
  179. package/dist/shared/promise.js +23 -0
  180. package/dist/shared/promise.js.map +1 -0
  181. package/dist/source-mask.d.ts +7 -0
  182. package/dist/source-mask.d.ts.map +1 -0
  183. package/dist/source-mask.js +74 -0
  184. package/dist/source-mask.js.map +1 -0
  185. package/dist/spread.d.ts +3 -0
  186. package/dist/spread.d.ts.map +1 -0
  187. package/dist/spread.js +103 -0
  188. package/dist/spread.js.map +1 -0
  189. package/dist/state-slot.d.ts +18 -0
  190. package/dist/state-slot.d.ts.map +1 -0
  191. package/dist/state-slot.js +46 -0
  192. package/dist/state-slot.js.map +1 -0
  193. package/dist/testing.d.ts +7 -0
  194. package/dist/testing.d.ts.map +1 -0
  195. package/dist/testing.js +18 -0
  196. package/dist/testing.js.map +1 -0
  197. package/package.json +151 -0
package/dist/server.js ADDED
@@ -0,0 +1,793 @@
1
+ // oxlint-disable-next-line typescript/triple-slash-reference -- Include compiler feature defines.
2
+ /// <reference path="./env.d.ts" />
3
+ import { LINK_IDENTITY_PROPS, META_IDENTITY_PROPS, SERVER_BOOLEAN_ATTRIBUTES, VALID_ATTRIBUTE_NAME, serverHtmlAttributeName, } from './dom/attributes.js';
4
+ import { UNITLESS_STYLE_PROPERTIES } from './dom/style-properties.js';
5
+ import { isPromiseLike } from './shared/promise.js';
6
+ const SERVER_NODE = Symbol.for('vidact.v1.ServerNode');
7
+ const SERVER_NODE_KIND = Symbol.for('vidact.v1.ServerNodeKind');
8
+ const SERVER_CONTEXT = Symbol('Vidact.ServerContext');
9
+ const SERVER_ASYNC_RESOURCE = Symbol('Vidact.ServerAsyncResource');
10
+ const SERVER_SUSPENSION = Symbol('Vidact.ServerSuspension');
11
+ const SERVER_RENDERABLE = Symbol.for('vidact.v1.ServerRenderable');
12
+ export function createRenderable(input, construct) {
13
+ return {
14
+ props: input,
15
+ [SERVER_RENDERABLE]: { input, construct },
16
+ };
17
+ }
18
+ export function isRenderable(value) {
19
+ return (typeof value === 'object' &&
20
+ value !== null &&
21
+ Object.hasOwn(value, SERVER_RENDERABLE) &&
22
+ typeof value[SERVER_RENDERABLE]?.construct === 'function');
23
+ }
24
+ export function renderableToArray(value) {
25
+ if (!isRenderable(value))
26
+ throw new TypeError('expected a compiled server renderable');
27
+ return [value];
28
+ }
29
+ export function renderableMarker(value) {
30
+ if (!isRenderable(value))
31
+ throw new TypeError('expected a compiled server renderable');
32
+ return undefined;
33
+ }
34
+ export function cloneRenderable(value, overrides = {}) {
35
+ if (!isRenderable(value))
36
+ throw new TypeError('expected a compiled server renderable');
37
+ const renderable = value[SERVER_RENDERABLE];
38
+ return renderable.construct({ ...renderable.input, ...overrides });
39
+ }
40
+ export function cloneRenderableComponent(props) {
41
+ return cloneRenderable(props.value, props.overrides);
42
+ }
43
+ export function renderableProps(input) {
44
+ return Object.fromEntries(Object.entries(input).filter(([name]) => !['children', 'key', 'ref'].includes(name)));
45
+ }
46
+ export function renderableChildren(input) {
47
+ return input.children;
48
+ }
49
+ export function renderableRef(_input) {
50
+ return undefined;
51
+ }
52
+ export function forwardedRef(_props) {
53
+ return undefined;
54
+ }
55
+ export function dynamicIntrinsicComponent(props) {
56
+ if (typeof props.tag !== 'string') {
57
+ throw new TypeError('dynamic intrinsic construction requires a string tag');
58
+ }
59
+ const input = props.props;
60
+ return jsx(props.tag, {
61
+ ...renderableProps(input),
62
+ children: renderableChildren(input),
63
+ });
64
+ }
65
+ const VOID_ELEMENTS = new Set([
66
+ 'area',
67
+ 'base',
68
+ 'br',
69
+ 'col',
70
+ 'embed',
71
+ 'hr',
72
+ 'img',
73
+ 'input',
74
+ 'keygen',
75
+ 'link',
76
+ 'menuitem',
77
+ 'meta',
78
+ 'param',
79
+ 'source',
80
+ 'track',
81
+ 'wbr',
82
+ ]);
83
+ const HYDRATION_PREFIX = 'vidact:v1';
84
+ const UNSAFE_HTML = typeof __VIDACT_UNSAFE_HTML__ !== 'undefined' && __VIDACT_UNSAFE_HTML__;
85
+ let activeRender;
86
+ let activeFrameworkRender;
87
+ const serverBuiltins = new WeakSet();
88
+ serverBuiltins.add(dynamicIntrinsicComponent);
89
+ serverBuiltins.add(cloneRenderableComponent);
90
+ const serverPromiseResources = new WeakMap();
91
+ const FRAMEWORK_HEAD_PLACEHOLDER = '<!--vidact-framework:v1:head-->';
92
+ export const Fragment = Symbol('Vidact.ServerFragment');
93
+ /** @internal */
94
+ export function createServerFrameworkRenderContext(signal) {
95
+ return {
96
+ signal,
97
+ pending: new Set(),
98
+ cache: new Map(),
99
+ head: new Map(),
100
+ stylePrecedence: [],
101
+ sawHead: false,
102
+ };
103
+ }
104
+ /** @internal */
105
+ export function withServerFrameworkRenderContext(context, operation) {
106
+ const previous = activeFrameworkRender;
107
+ activeFrameworkRender = context;
108
+ try {
109
+ return operation();
110
+ }
111
+ finally {
112
+ activeFrameworkRender = previous;
113
+ }
114
+ }
115
+ export function cache(operation) {
116
+ return (...arguments_) => {
117
+ const context = activeFrameworkRender;
118
+ if (context === undefined)
119
+ return operation(...arguments_);
120
+ let entries = context.cache.get(operation);
121
+ if (entries === undefined) {
122
+ entries = [];
123
+ context.cache.set(operation, entries);
124
+ }
125
+ const existing = entries.find((entry) => entry.args.length === arguments_.length &&
126
+ entry.args.every((argument, index) => Object.is(argument, arguments_[index])));
127
+ if (existing !== undefined) {
128
+ if (existing.status === 'rejected')
129
+ throw existing.value;
130
+ return existing.value;
131
+ }
132
+ try {
133
+ const value = operation(...arguments_);
134
+ entries.push({ args: [...arguments_], status: 'fulfilled', value });
135
+ return value;
136
+ }
137
+ catch (error) {
138
+ entries.push({ args: [...arguments_], status: 'rejected', value: error });
139
+ throw error;
140
+ }
141
+ };
142
+ }
143
+ export function cacheSignal() {
144
+ return activeFrameworkRender?.signal ?? null;
145
+ }
146
+ export function preconnect(href, options = {}) {
147
+ registerResourceHint('preconnect', href, options);
148
+ }
149
+ export function prefetchDNS(href) {
150
+ registerResourceHint('dns-prefetch', href, {});
151
+ }
152
+ export function preload(href, options) {
153
+ registerResourceHint('preload', href, options);
154
+ }
155
+ export function preloadModule(href, options = {}) {
156
+ registerResourceHint('modulepreload', href, options);
157
+ }
158
+ export function preinit(href, options) {
159
+ if (options.as === 'style') {
160
+ registerHeadEntry(`style:${href}`, `<link rel="stylesheet" href="${escapeAttribute(href)}"${serializeHintOptions(options)}>`, `2:${options.precedence ?? 'default'}`);
161
+ return;
162
+ }
163
+ registerHeadEntry(`script:${href}`, `<script src="${escapeAttribute(href)}"${serializeHintOptions(options)}></script>`, '3:script');
164
+ }
165
+ export function preinitModule(href, options = {}) {
166
+ registerHeadEntry(`module:${href}`, `<script type="module" src="${escapeAttribute(href)}"${serializeHintOptions(options)}></script>`, '3:script');
167
+ }
168
+ export function jsx(type, props, _key) {
169
+ return createServerElement(type, props, false);
170
+ }
171
+ export function jsxs(type, props, _key) {
172
+ return createServerElement(type, props, true);
173
+ }
174
+ export function jsxDEV(type, props, _key, isStaticChildren = false) {
175
+ return createServerElement(type, props, isStaticChildren);
176
+ }
177
+ export function createElement(type, props, ...children) {
178
+ const nextProps = { ...props };
179
+ if (children.length === 1)
180
+ nextProps.children = children[0];
181
+ else if (children.length > 1)
182
+ nextProps.children = children;
183
+ return createServerElement(type, nextProps, children.length > 1);
184
+ }
185
+ /** @internal */
186
+ export function createServerHydrationBoundary(value, hostProps = {}) {
187
+ return serverNode((context) => {
188
+ const boundaryIndex = context.nextBoundary;
189
+ context.nextBoundary += 1;
190
+ const identifierPrefix = `${context.identifierPrefix}b${boundaryIndex}-`;
191
+ const boundaryContext = {
192
+ hydrationMarkers: true,
193
+ identifierPrefix,
194
+ nextBoundary: 0,
195
+ nextId: 0,
196
+ activityHidden: false,
197
+ };
198
+ const attributes = serializeAttributes({
199
+ ...hostProps,
200
+ 'data-vidact-identifier-prefix': identifierPrefix,
201
+ }, context.activityHidden);
202
+ return `<div${attributes}>${hydrationRange('r', serializeSlot(value, boundaryContext))}</div>`;
203
+ }, 'transparent');
204
+ }
205
+ function createServerElement(type, props, multipleChildren) {
206
+ if (type === Fragment) {
207
+ return serverNode((context) => Object.hasOwn(props ?? {}, 'children')
208
+ ? multipleChildren
209
+ ? serializeChildren(props?.children, context, true)
210
+ : serializeSlot(props?.children, context)
211
+ : '', 'transparent');
212
+ }
213
+ if (isRenderable(type)) {
214
+ return serverNode((context) => serializeSlot(cloneRenderable(type, props ?? {}), context), 'component');
215
+ }
216
+ if (typeof type === 'function') {
217
+ const builtin = serverBuiltins.has(type);
218
+ return serverNode((context) => {
219
+ const content = serializeSlot(type(props ?? {}), context);
220
+ return context.hydrationMarkers && !builtin ? hydrationRange('c', content) : content;
221
+ }, builtin ? 'transparent' : 'component');
222
+ }
223
+ if (!VALID_ATTRIBUTE_NAME.test(type))
224
+ throw new TypeError(`invalid server element name ${type}`);
225
+ return serverNode((context) => serializeIntrinsicElement(type, props, multipleChildren, context), 'intrinsic');
226
+ }
227
+ function serializeIntrinsicElement(type, props, multipleChildren, context) {
228
+ if (activeFrameworkRender !== undefined && isHoistableHeadElement(type, props)) {
229
+ const hydrationMarkers = context.hydrationMarkers;
230
+ context.hydrationMarkers = false;
231
+ try {
232
+ const html = serializeIntrinsicContents(type, props, multipleChildren, context);
233
+ registerHeadEntry(metadataKey(type, props), html, metadataPrecedence(type, props));
234
+ return '';
235
+ }
236
+ finally {
237
+ context.hydrationMarkers = hydrationMarkers;
238
+ }
239
+ }
240
+ return serializeIntrinsicContents(type, props, multipleChildren, context);
241
+ }
242
+ function serializeIntrinsicContents(type, props, multipleChildren, context) {
243
+ const hiddenByActivity = context.activityHidden;
244
+ const previousActivityHidden = context.activityHidden;
245
+ context.activityHidden = false;
246
+ try {
247
+ const attributes = serializeAttributes(props, hiddenByActivity);
248
+ if (VOID_ELEMENTS.has(type)) {
249
+ if (hasRenderableChild(props?.children) || readRawHtml(props) !== undefined) {
250
+ throw new TypeError(`${type} is a void element and cannot have children or raw HTML`);
251
+ }
252
+ return `<${type}${attributes}>`;
253
+ }
254
+ const rawHtml = readRawHtml(props);
255
+ if (rawHtml !== undefined && hasRenderableChild(props?.children)) {
256
+ throw new TypeError('cannot set both children and dangerouslySetInnerHTML');
257
+ }
258
+ const hasChildren = Object.hasOwn(props ?? {}, 'children');
259
+ const children = rawHtml === undefined
260
+ ? hasChildren
261
+ ? multipleChildren
262
+ ? serializeChildren(props?.children, context, !isRawTextElement(type))
263
+ : serializeSlot(props?.children, context, !isRawTextElement(type))
264
+ : ''
265
+ : context.hydrationMarkers
266
+ ? hydrationRange('h', assertSafeHydrationRawHtml(rawHtml))
267
+ : rawHtml;
268
+ if (type === 'head' && activeFrameworkRender !== undefined) {
269
+ activeFrameworkRender.sawHead = true;
270
+ return `<head${attributes}>${children}${FRAMEWORK_HEAD_PLACEHOLDER}</head>`;
271
+ }
272
+ return `<${type}${attributes}>${children}</${type}>`;
273
+ }
274
+ finally {
275
+ context.activityHidden = previousActivityHidden;
276
+ }
277
+ }
278
+ export function renderToString(value, options = {}) {
279
+ const previous = activeRender;
280
+ beginFrameworkRenderPass();
281
+ const context = {
282
+ hydrationMarkers: true,
283
+ identifierPrefix: options.identifierPrefix ?? '',
284
+ nextBoundary: 0,
285
+ nextId: 0,
286
+ activityHidden: false,
287
+ };
288
+ activeRender = context;
289
+ try {
290
+ const html = hydrationRange('r', serializeSlot(typeof value === 'function' ? value() : value, context));
291
+ return finalizeFrameworkHtml(html);
292
+ }
293
+ finally {
294
+ activeRender = previous;
295
+ }
296
+ }
297
+ export function renderToStaticMarkup(value, options = {}) {
298
+ const previous = activeRender;
299
+ beginFrameworkRenderPass();
300
+ const context = {
301
+ hydrationMarkers: false,
302
+ identifierPrefix: options.identifierPrefix ?? '',
303
+ nextBoundary: 0,
304
+ nextId: 0,
305
+ activityHidden: false,
306
+ };
307
+ activeRender = context;
308
+ try {
309
+ return finalizeFrameworkHtml(serializeChild(typeof value === 'function' ? value() : value, context));
310
+ }
311
+ finally {
312
+ activeRender = previous;
313
+ }
314
+ }
315
+ export function useState(initial) {
316
+ const value = typeof initial === 'function' ? initial() : initial;
317
+ return [value, serverDispatch];
318
+ }
319
+ export function useReducer(_reducer, initial, initialize) {
320
+ return [initialize === undefined ? initial : initialize(initial), serverDispatch];
321
+ }
322
+ export function startTransition(action) {
323
+ void action();
324
+ }
325
+ export function useTransition() {
326
+ return [false, startTransition];
327
+ }
328
+ export function useDeferredValue(value, _initialValue) {
329
+ return value;
330
+ }
331
+ export function flushSync(operation) {
332
+ return operation?.();
333
+ }
334
+ export function useActionState(_action, initialState, permalink) {
335
+ const dispatch = (_payload) => serverDispatch();
336
+ if (permalink !== undefined)
337
+ Object.defineProperty(dispatch, 'permalink', { value: permalink });
338
+ return [initialState, dispatch, false];
339
+ }
340
+ export function useOptimistic(passthrough, _reducer) {
341
+ return [passthrough, serverDispatch];
342
+ }
343
+ export function useFormStatus() {
344
+ return { pending: false, data: null, method: 'get', action: null };
345
+ }
346
+ export function useMemo(factory, _dependencies) {
347
+ return factory();
348
+ }
349
+ export function useCallback(callback, _dependencies) {
350
+ return callback;
351
+ }
352
+ export function useRef(initial) {
353
+ return { current: initial };
354
+ }
355
+ export function useEffect(_create, _dependencies) { }
356
+ export const useLayoutEffect = useEffect;
357
+ export const useInsertionEffect = useEffect;
358
+ export function useImperativeHandle(_ref, _create, _dependencies) { }
359
+ export function useEffectEvent(callback) {
360
+ return callback;
361
+ }
362
+ export function useSyncExternalStore(_subscribe, getSnapshot, getServerSnapshot) {
363
+ return (getServerSnapshot ?? getSnapshot)();
364
+ }
365
+ export function useId() {
366
+ const context = (activeRender ??= {
367
+ hydrationMarkers: true,
368
+ identifierPrefix: '',
369
+ nextBoundary: 0,
370
+ nextId: 0,
371
+ activityHidden: false,
372
+ });
373
+ const id = `:${context.identifierPrefix}r${context.nextId}:`;
374
+ context.nextId += 1;
375
+ return id;
376
+ }
377
+ export function createContext(defaultValue) {
378
+ let context;
379
+ const Provider = (props) => serverNode((renderContext) => {
380
+ context[SERVER_CONTEXT].stack.push(props.value);
381
+ try {
382
+ return serializeChild(props.children, renderContext);
383
+ }
384
+ finally {
385
+ context[SERVER_CONTEXT].stack.pop();
386
+ }
387
+ }, 'transparent');
388
+ context = { [SERVER_CONTEXT]: { defaultValue, stack: [] }, Provider };
389
+ serverBuiltins.add(Provider);
390
+ return context;
391
+ }
392
+ export function useContext(context) {
393
+ const state = context[SERVER_CONTEXT];
394
+ return state.stack.length === 0 ? state.defaultValue : state.stack.at(-1);
395
+ }
396
+ export function createResource(input) {
397
+ if (!isPromiseLike(input))
398
+ throw new TypeError('createResource requires a promise-like value');
399
+ const existing = serverPromiseResources.get(input);
400
+ if (existing !== undefined)
401
+ return existing;
402
+ let state = { status: 'pending' };
403
+ const resource = { promise: input };
404
+ Object.defineProperty(resource, SERVER_ASYNC_RESOURCE, { get: () => state });
405
+ serverPromiseResources.set(input, resource);
406
+ void Promise.resolve(input).then((value) => {
407
+ if (state.status === 'pending')
408
+ state = { status: 'fulfilled', value };
409
+ }, (reason) => {
410
+ if (state.status === 'pending')
411
+ state = { status: 'rejected', reason };
412
+ });
413
+ return resource;
414
+ }
415
+ export function use(input) {
416
+ if (isServerContext(input))
417
+ return useContext(input);
418
+ const resource = isServerAsyncResource(input) ? input : createResource(input);
419
+ const state = resource[SERVER_ASYNC_RESOURCE];
420
+ if (state.status === 'fulfilled')
421
+ return state.value;
422
+ if (state.status === 'rejected')
423
+ throw state.reason;
424
+ throw { [SERVER_SUSPENSION]: true, resource };
425
+ }
426
+ export function lazy(load) {
427
+ let resource;
428
+ return (props) => {
429
+ resource ??= createResource(load());
430
+ const module = use(resource);
431
+ if (typeof module?.default !== 'function') {
432
+ throw new TypeError('lazy loader must resolve to a default component export');
433
+ }
434
+ return module.default(props);
435
+ };
436
+ }
437
+ export function Suspense(props) {
438
+ const render = props.children;
439
+ const fallback = props.fallback;
440
+ if (typeof render !== 'function' || typeof fallback !== 'function') {
441
+ throw new TypeError('Suspense children and fallback must be compiler-generated render functions');
442
+ }
443
+ return serverNode((context) => {
444
+ try {
445
+ return serializeChild(render(), context);
446
+ }
447
+ catch (error) {
448
+ if (!isServerSuspension(error))
449
+ throw error;
450
+ activeFrameworkRender?.pending.add(error.resource.promise);
451
+ const pendingMarker = context.hydrationMarkers ? `<!--${HYDRATION_PREFIX}:p-->` : '';
452
+ return pendingMarker + serializeChild(fallback(), context);
453
+ }
454
+ }, 'transparent');
455
+ }
456
+ serverBuiltins.add(Suspense);
457
+ export function Activity(props) {
458
+ const render = props.children;
459
+ if (typeof render !== 'function') {
460
+ throw new TypeError('Activity children must be a compiler-generated render function');
461
+ }
462
+ if (props.mode !== 'visible' && props.mode !== 'hidden') {
463
+ throw new TypeError('Activity mode must be "visible" or "hidden"');
464
+ }
465
+ return serverNode((context) => {
466
+ const previousActivityHidden = context.activityHidden;
467
+ context.activityHidden = props.mode === 'hidden' || previousActivityHidden;
468
+ try {
469
+ return serializeChild(render(), context);
470
+ }
471
+ finally {
472
+ context.activityHidden = previousActivityHidden;
473
+ }
474
+ }, 'transparent');
475
+ }
476
+ serverBuiltins.add(Activity);
477
+ export function Profiler(props) {
478
+ const render = props.children;
479
+ if (typeof render !== 'function') {
480
+ throw new TypeError('Profiler children must be a compiler-generated render function');
481
+ }
482
+ if (typeof props.id !== 'string')
483
+ throw new TypeError('Profiler id must be a string');
484
+ if (typeof props.onRender !== 'function') {
485
+ throw new TypeError('Profiler onRender must be a function');
486
+ }
487
+ return render();
488
+ }
489
+ serverBuiltins.add(Profiler);
490
+ export function useDebugValue(_value, _format) { }
491
+ export function captureOwnerStack() {
492
+ return null;
493
+ }
494
+ export function createPortal(_children, _container) {
495
+ throw new Error('portals cannot be emitted by the server target; render portal content in the client root');
496
+ }
497
+ function serverNode(render, kind) {
498
+ return { [SERVER_NODE]: render, [SERVER_NODE_KIND]: kind };
499
+ }
500
+ function isServerNode(value) {
501
+ return typeof value === 'object' && value !== null && SERVER_NODE in value;
502
+ }
503
+ function isServerContext(value) {
504
+ return typeof value === 'object' && value !== null && SERVER_CONTEXT in value;
505
+ }
506
+ function isServerAsyncResource(value) {
507
+ return typeof value === 'object' && value !== null && SERVER_ASYNC_RESOURCE in value;
508
+ }
509
+ function isServerSuspension(value) {
510
+ return typeof value === 'object' && value !== null && SERVER_SUSPENSION in value;
511
+ }
512
+ function serializeChild(value, context, markScalar = true) {
513
+ if (value === null || value === undefined || typeof value === 'boolean') {
514
+ return context.hydrationMarkers && markScalar ? hydrationRange('t', '') : '';
515
+ }
516
+ if (isServerNode(value)) {
517
+ const content = value[SERVER_NODE](context);
518
+ return context.hydrationMarkers && value[SERVER_NODE_KIND] === 'intrinsic'
519
+ ? hydrationRange('s', content)
520
+ : content;
521
+ }
522
+ if (isRenderable(value))
523
+ return serializeChild(cloneRenderable(value), context, markScalar);
524
+ if (Array.isArray(value)) {
525
+ const content = value.map((child) => serializeChild(child, context, markScalar)).join('');
526
+ return context.hydrationMarkers ? hydrationRange('a', content) : content;
527
+ }
528
+ if (typeof value === 'object' || typeof value === 'function' || typeof value === 'symbol') {
529
+ throw new TypeError('unsupported server child value');
530
+ }
531
+ const content = escapeText(String(value));
532
+ if (context.activityHidden && content !== '') {
533
+ throw new TypeError('initially hidden Activity server children require a host element root');
534
+ }
535
+ return context.hydrationMarkers && markScalar ? hydrationRange('t', content) : content;
536
+ }
537
+ function hasRenderableChild(value) {
538
+ if (value === null || value === undefined || typeof value === 'boolean')
539
+ return false;
540
+ return !Array.isArray(value) || value.some(hasRenderableChild);
541
+ }
542
+ function serializeAttributes(props, hiddenByActivity = false) {
543
+ if (props === null)
544
+ return ' style="display:none!important"';
545
+ const attributes = Object.keys(props)
546
+ .toSorted()
547
+ .map((name) => name === 'style'
548
+ ? serializeStyleAttribute(props[name], hiddenByActivity)
549
+ : serializeAttribute(name, props[name]))
550
+ .join('');
551
+ return hiddenByActivity && !Object.hasOwn(props, 'style')
552
+ ? `${attributes} style="display:none!important"`
553
+ : attributes;
554
+ }
555
+ function serializeAttribute(name, value) {
556
+ if ((name === 'action' || name === 'formAction') &&
557
+ typeof value === 'function' &&
558
+ typeof Reflect.get(value, 'permalink') === 'string') {
559
+ return ` ${serverHtmlAttributeName(name)}="${escapeAttribute(Reflect.get(value, 'permalink'))}"`;
560
+ }
561
+ if (name === 'children' ||
562
+ name === 'dangerouslySetInnerHTML' ||
563
+ name === 'key' ||
564
+ name === 'precedence' ||
565
+ name === 'ref' ||
566
+ /^on/i.test(name) ||
567
+ value === null ||
568
+ value === undefined ||
569
+ typeof value === 'function' ||
570
+ typeof value === 'symbol') {
571
+ return '';
572
+ }
573
+ if (name === 'style')
574
+ return serializeStyleAttribute(value);
575
+ const normalizedName = serverHtmlAttributeName(name);
576
+ if (name.startsWith('data-') || name.startsWith('aria-')) {
577
+ return ` ${normalizedName}="${escapeAttribute(String(value))}"`;
578
+ }
579
+ if (SERVER_BOOLEAN_ATTRIBUTES.has(name))
580
+ return value ? ` ${normalizedName}=""` : '';
581
+ if (typeof value === 'boolean')
582
+ return '';
583
+ if (!VALID_ATTRIBUTE_NAME.test(normalizedName))
584
+ return '';
585
+ return ` ${normalizedName}="${escapeAttribute(String(value))}"`;
586
+ }
587
+ function beginFrameworkRenderPass() {
588
+ const framework = activeFrameworkRender;
589
+ if (framework === undefined)
590
+ return;
591
+ if (framework.signal.aborted)
592
+ throw frameworkAbortReason(framework.signal);
593
+ framework.pending.clear();
594
+ framework.head.clear();
595
+ framework.stylePrecedence.length = 0;
596
+ framework.sawHead = false;
597
+ }
598
+ function finalizeFrameworkHtml(html) {
599
+ const framework = activeFrameworkRender;
600
+ if (framework === undefined)
601
+ return html;
602
+ const head = [...framework.head.entries()]
603
+ .toSorted(([, left], [, right]) => compareHeadPrecedence(framework, left, right))
604
+ .map(([, entry]) => entry.html)
605
+ .join('');
606
+ if (framework.sawHead)
607
+ return html.replace(FRAMEWORK_HEAD_PLACEHOLDER, head);
608
+ if (head === '')
609
+ return html;
610
+ const htmlStart = html.indexOf('<html');
611
+ if (htmlStart !== -1) {
612
+ const htmlOpenEnd = html.indexOf('>', htmlStart);
613
+ if (htmlOpenEnd !== -1) {
614
+ return `${html.slice(0, htmlOpenEnd + 1)}<head>${head}</head>${html.slice(htmlOpenEnd + 1)}`;
615
+ }
616
+ }
617
+ return `<head>${head}</head>${html}`;
618
+ }
619
+ function isHoistableHeadElement(type, props) {
620
+ if (type === 'title' || type === 'meta')
621
+ return !hasOwnProp(props, 'itemProp');
622
+ if (type === 'link') {
623
+ if (['itemProp', 'onLoad', 'onError', 'disabled'].some((name) => hasOwnProp(props, name))) {
624
+ return false;
625
+ }
626
+ return props?.rel !== 'stylesheet' || typeof props.precedence === 'string';
627
+ }
628
+ if (type === 'style') {
629
+ return typeof props?.href === 'string' && typeof props.precedence === 'string';
630
+ }
631
+ return type === 'script' && props?.async === true && typeof props.src === 'string';
632
+ }
633
+ function hasOwnProp(props, name) {
634
+ return props !== null && Object.hasOwn(props, name);
635
+ }
636
+ function metadataKey(type, props) {
637
+ if (type === 'title')
638
+ return 'title';
639
+ if (type === 'meta') {
640
+ for (const name of META_IDENTITY_PROPS) {
641
+ const value = props?.[name];
642
+ if (value !== undefined)
643
+ return `meta:${name}:${String(value)}`;
644
+ }
645
+ }
646
+ if (type === 'link')
647
+ return `link:${LINK_IDENTITY_PROPS.map((name) => String(props?.[name] ?? '')).join(':')}`;
648
+ if (type === 'style')
649
+ return `style:${String(props?.href ?? '')}`;
650
+ if (type === 'script')
651
+ return `script:${String(props?.src ?? '')}`;
652
+ return `${type}:${JSON.stringify(props)}`;
653
+ }
654
+ function metadataPrecedence(type, props) {
655
+ if (type === 'style' || (type === 'link' && props?.rel === 'stylesheet')) {
656
+ return `2:${String(props?.precedence ?? 'default')}`;
657
+ }
658
+ if (type === 'script')
659
+ return '3:script';
660
+ return '1:metadata';
661
+ }
662
+ function registerResourceHint(relation, href, options) {
663
+ if (typeof href !== 'string' || href.length === 0)
664
+ throw new TypeError('resource href must be non-empty');
665
+ const as = 'as' in options && typeof options.as === 'string' ? ` as="${escapeAttribute(options.as)}"` : '';
666
+ registerHeadEntry(`hint:${relation}:${href}:${as}`, `<link rel="${relation}" href="${escapeAttribute(href)}"${as}${serializeHintOptions(options)}>`, '0:hint');
667
+ }
668
+ function registerHeadEntry(key, html, precedence) {
669
+ const framework = activeFrameworkRender;
670
+ if (framework === undefined)
671
+ return;
672
+ if (precedence.startsWith('2:')) {
673
+ const stylePrecedence = precedence.slice(2);
674
+ if (!framework.stylePrecedence.includes(stylePrecedence)) {
675
+ framework.stylePrecedence.push(stylePrecedence);
676
+ }
677
+ }
678
+ framework.head.set(key, { html, precedence });
679
+ }
680
+ function compareHeadPrecedence(framework, left, right) {
681
+ const leftRank = Number(left.precedence[0]);
682
+ const rightRank = Number(right.precedence[0]);
683
+ if (leftRank !== rightRank)
684
+ return leftRank - rightRank;
685
+ if (leftRank !== 2)
686
+ return 0;
687
+ return (framework.stylePrecedence.indexOf(left.precedence.slice(2)) -
688
+ framework.stylePrecedence.indexOf(right.precedence.slice(2)));
689
+ }
690
+ function serializeHintOptions(options) {
691
+ const attributes = [];
692
+ if (options.crossOrigin !== undefined) {
693
+ attributes.push(` crossorigin="${escapeAttribute(options.crossOrigin)}"`);
694
+ }
695
+ if ('fetchPriority' in options && options.fetchPriority !== undefined) {
696
+ attributes.push(` fetchpriority="${options.fetchPriority}"`);
697
+ }
698
+ if ('imageSizes' in options && options.imageSizes !== undefined) {
699
+ attributes.push(` imagesizes="${escapeAttribute(options.imageSizes)}"`);
700
+ }
701
+ if ('imageSrcSet' in options && options.imageSrcSet !== undefined) {
702
+ attributes.push(` imagesrcset="${escapeAttribute(options.imageSrcSet)}"`);
703
+ }
704
+ if ('integrity' in options && options.integrity !== undefined) {
705
+ attributes.push(` integrity="${escapeAttribute(options.integrity)}"`);
706
+ }
707
+ if ('nonce' in options && options.nonce !== undefined) {
708
+ attributes.push(` nonce="${escapeAttribute(options.nonce)}"`);
709
+ }
710
+ if ('referrerPolicy' in options && options.referrerPolicy !== undefined) {
711
+ attributes.push(` referrerpolicy="${escapeAttribute(options.referrerPolicy)}"`);
712
+ }
713
+ if ('type' in options && options.type !== undefined) {
714
+ attributes.push(` type="${escapeAttribute(options.type)}"`);
715
+ }
716
+ return attributes.join('');
717
+ }
718
+ function frameworkAbortReason(signal) {
719
+ return signal.reason ?? new DOMException('The operation was aborted', 'AbortError');
720
+ }
721
+ function serializeStyleAttribute(value, hiddenByActivity = false) {
722
+ if (typeof value === 'string') {
723
+ const separator = value === '' || value.endsWith(';') ? '' : ';';
724
+ const style = hiddenByActivity ? `${value}${separator}display:none!important` : value;
725
+ return style === '' ? '' : ` style="${escapeAttribute(style)}"`;
726
+ }
727
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
728
+ return hiddenByActivity ? ' style="display:none!important"' : '';
729
+ }
730
+ const declarations = Object.entries(value)
731
+ .toSorted(([left], [right]) => left.localeCompare(right))
732
+ .flatMap(([name, item]) => {
733
+ if (item === null || item === undefined || typeof item === 'boolean' || item === '')
734
+ return [];
735
+ const cssName = name.startsWith('--') ? name : camelToKebab(name);
736
+ const cssValue = typeof item === 'number' && item !== 0 && !UNITLESS_STYLE_PROPERTIES.has(name)
737
+ ? `${item}px`
738
+ : item;
739
+ return `${cssName}:${String(cssValue)}`;
740
+ });
741
+ if (hiddenByActivity)
742
+ declarations.push('display:none!important');
743
+ return declarations.length === 0 ? '' : ` style="${escapeAttribute(declarations.join(';'))}"`;
744
+ }
745
+ function camelToKebab(name) {
746
+ return name
747
+ .replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`)
748
+ .replace(/^ms-/, '-ms-');
749
+ }
750
+ function readRawHtml(props) {
751
+ const value = props?.dangerouslySetInnerHTML;
752
+ if (value === null || value === undefined)
753
+ return undefined;
754
+ if (!UNSAFE_HTML) {
755
+ throw new Error('dangerouslySetInnerHTML requires the unsafe-html compiler feature');
756
+ }
757
+ if (typeof value !== 'object' || !('__html' in value)) {
758
+ throw new TypeError('dangerouslySetInnerHTML must be an object with an __html property');
759
+ }
760
+ const html = Reflect.get(value, '__html');
761
+ return html === null || html === undefined ? '' : String(html);
762
+ }
763
+ function escapeText(value) {
764
+ return value.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');
765
+ }
766
+ function escapeAttribute(value) {
767
+ return escapeText(value).replaceAll('"', '&quot;').replaceAll("'", '&#x27;');
768
+ }
769
+ function serializeChildren(value, context, markScalar) {
770
+ return Array.isArray(value)
771
+ ? value.map((child) => serializeSlot(child, context, markScalar)).join('')
772
+ : serializeSlot(value, context, markScalar);
773
+ }
774
+ function serializeSlot(value, context, markScalar = true) {
775
+ const content = serializeChild(value, context, markScalar);
776
+ return context.hydrationMarkers ? hydrationRange('b', content) : content;
777
+ }
778
+ function hydrationRange(kind, content) {
779
+ return `<!--${HYDRATION_PREFIX}:${kind}-->${content}<!--/${HYDRATION_PREFIX}:${kind}-->`;
780
+ }
781
+ function assertSafeHydrationRawHtml(value) {
782
+ if (/<!--\/?vidact:v\d+:/i.test(value)) {
783
+ throw new Error('raw HTML cannot contain Vidact hydration marker syntax');
784
+ }
785
+ return value;
786
+ }
787
+ function isRawTextElement(type) {
788
+ return type === 'script' || type === 'style' || type === 'textarea' || type === 'title';
789
+ }
790
+ function serverDispatch() {
791
+ throw new Error('state dispatch is unavailable during server rendering');
792
+ }
793
+ //# sourceMappingURL=server.js.map