@bgub/fig 0.1.0-alpha.1 → 0.1.0-alpha.3
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 +44 -0
- package/dist/{element-BZ7r9ncY.d.ts → element-BVg1bKOz.d.ts} +4 -1
- package/dist/{hooks-QDRabULx.d.ts → hooks-B7BTQWiu.d.ts} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/internal.d.ts +6 -3
- package/dist/internal.js +2 -1
- package/dist/internal.js.map +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/payload-format-KTNaSI4h.js.map +1 -1
- package/dist/payload.d.ts +1 -1
- package/dist/payload.js +1 -1
- package/dist/{resource-kXeIR52S.js → resource-DskjKeuM.js} +28 -17
- package/dist/resource-DskjKeuM.js.map +1 -0
- package/dist-development/element-B7mCQIMi.js +314 -0
- package/dist-development/element-B7mCQIMi.js.map +1 -0
- package/dist-development/index.js +4 -0
- package/dist-development/internal.js +172 -0
- package/dist-development/internal.js.map +1 -0
- package/dist-development/jsx-runtime.js +23 -0
- package/dist-development/jsx-runtime.js.map +1 -0
- package/dist-development/payload-format-KTNaSI4h.js +366 -0
- package/dist-development/payload-format-KTNaSI4h.js.map +1 -0
- package/dist-development/payload.js +429 -0
- package/dist-development/payload.js.map +1 -0
- package/dist-development/resource-CP2OynG0.js +336 -0
- package/dist-development/resource-CP2OynG0.js.map +1 -0
- package/dist-development/transition-B4XiOWAj.js +750 -0
- package/dist-development/transition-B4XiOWAj.js.map +1 -0
- package/package.json +7 -1
- package/dist/resource-kXeIR52S.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
1
|
+
## @bgub/fig@0.1.0-alpha.3
|
|
2
|
+
|
|
3
|
+
### Let Fig's Vite integration own runtime configuration
|
|
4
|
+
|
|
5
|
+
The new `fig()` Vite integration defines Fig's development gate and installs
|
|
6
|
+
Fast Refresh. TanStack Start composes it automatically, so applications no
|
|
7
|
+
longer need to configure Fig's compile-time mode or SSR package bundling
|
|
8
|
+
themselves.
|
|
9
|
+
|
|
10
|
+
`@bgub/fig-vite` now uses the application's Fig DOM renderer as a peer instead
|
|
11
|
+
of installing a private renderer copy.
|
|
12
|
+
|
|
13
|
+
The development gate follows Vite's command rather than its mode: serving
|
|
14
|
+
enables development behavior, while builds—including `--mode development`—strip
|
|
15
|
+
it from production output.
|
|
16
|
+
|
|
17
|
+
Published npm packages now expose development artifacts through a Fig-owned
|
|
18
|
+
condition, allowing the Vite integration to enable diagnostics and Fast Refresh
|
|
19
|
+
for ordinary installs while explicit static overrides remain authoritative and
|
|
20
|
+
default production imports retain their previous dead-code elimination. A
|
|
21
|
+
static `false` override also disables Fast Refresh instrumentation.
|
|
22
|
+
|
|
23
|
+
## @bgub/fig@0.1.0-alpha.2
|
|
24
|
+
|
|
25
|
+
### Preload eligible host images during server rendering
|
|
26
|
+
|
|
27
|
+
HTML and Payload rendering now derive image preload assets from eager `<img>`
|
|
28
|
+
hosts. The hints share Fig's existing asset registry, dedupe against explicit
|
|
29
|
+
preloads, preserve responsive `srcset` and `sizes` selection, and arrive before
|
|
30
|
+
the content that depends on them.
|
|
31
|
+
|
|
32
|
+
The first ten distinct images receive early shell delivery without being
|
|
33
|
+
forced to high browser priority. Lazy, explicitly low-priority, data-URL,
|
|
34
|
+
`<picture>`, and `<noscript>` images remain untouched.
|
|
35
|
+
|
|
36
|
+
### Keep empty children and document assets hydration-safe
|
|
37
|
+
|
|
38
|
+
Empty string children now normalize away on both the server and client, so a
|
|
39
|
+
rendered empty token cannot force hydration to recover the root.
|
|
40
|
+
|
|
41
|
+
When full-document hydration does recover, declarative stylesheets, titles,
|
|
42
|
+
and metadata now acquire against the replacement head instead of disappearing
|
|
43
|
+
with the server document.
|
|
44
|
+
|
|
1
45
|
## @bgub/fig@0.1.0-alpha.1
|
|
2
46
|
|
|
3
47
|
### Asset descriptors use native names and preserve native ordering
|
|
@@ -121,8 +121,11 @@ interface PreloadResource extends ResourceBase {
|
|
|
121
121
|
as: string;
|
|
122
122
|
crossorigin?: CrossOrigin;
|
|
123
123
|
fetchpriority?: FetchPriority;
|
|
124
|
-
href
|
|
124
|
+
href?: string;
|
|
125
|
+
imagesizes?: string;
|
|
126
|
+
imagesrcset?: string;
|
|
125
127
|
kind: "preload";
|
|
128
|
+
referrerpolicy?: string;
|
|
126
129
|
type?: string;
|
|
127
130
|
}
|
|
128
131
|
interface ModulePreloadResource extends ResourceBase {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as FigNode, Gt as FigDataStore, Ht as DataStoreEntrySnapshot, It as DataRefreshResult, Jt as FigDataStoreHandle, Kt as FigDataStoreController, Lt as DataResource, N as Props, Rt as DataResourceKey, Vt as DataResourceLoader, Wt as FigDataHydrationEntry, Xt as FigDataStoreOptions, Yt as FigDataStoreHost, zt as DataResourceKeyInput } from "./element-
|
|
1
|
+
import { C as FigNode, Gt as FigDataStore, Ht as DataStoreEntrySnapshot, It as DataRefreshResult, Jt as FigDataStoreHandle, Kt as FigDataStoreController, Lt as DataResource, N as Props, Rt as DataResourceKey, Vt as DataResourceLoader, Wt as FigDataHydrationEntry, Xt as FigDataStoreOptions, Yt as FigDataStoreHost, zt as DataResourceKeyInput } from "./element-BVg1bKOz.js";
|
|
2
2
|
//#region src/context.d.ts
|
|
3
3
|
interface FigContext<T> {
|
|
4
4
|
(props: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { A as Fragment, At as preconnect, B as ViewTransitionPhase, Bt as DataResourceLoadContext, C as FigNode, Et as font, F as SuspenseProps, Ft as title, H as ViewTransitionSurface, I as ViewTransition, It as DataRefreshResult, Jt as FigDataStoreHandle, Kt as FigDataStoreController, L as ViewTransitionCallback, Lt as DataResource, M as LazyLoader, N as Props, Nt as script, O as FigViewTransition, Ot as meta, P as Suspense, Pt as stylesheet, Q as isValidElement, R as ViewTransitionClass, Rt as DataResourceKey, U as clientReference, V as ViewTransitionProps, Vt as DataResourceLoader, W as createElement, Wt as FigDataHydrationEntry, Xt as FigDataStoreOptions, _ as FigClientReference, _t as StylesheetResource, a as AwaitedFigNode, at as ClientReferenceAssets, c as ComponentType, ct as FigAssetResource, d as ErrorBoundaryProps, dt as MetaResource, et as lazy, f as ErrorInfo, ft as MetaResourceOptions, gt as ScriptResource, ht as PreloadResource, it as AssetsProps, j as Key, jt as preload, kt as modulepreload, l as ElementType, lt as FigAssetResourceList, mt as PreconnectResource, n as ActivityMode, o as ClientReferenceOptions, ot as CrossOrigin, pt as ModulePreloadResource, r as ActivityProps, s as ComponentProps, st as FetchPriority, t as Activity, tt as AssetResourceBlocking, u as ErrorBoundary, ut as FontResource, vt as TitleResource, w as FigPortal, wt as assets, y as FigElement, z as ViewTransitionEvent, zt as DataResourceKeyInput } from "./element-
|
|
2
|
-
import { $ as invalidateData, A as transition, B as createMixin, C as useStableEvent, E as useTransition, F as MixinFactory, I as MixinInput, J as createDataStore, L as MixinResult, N as MixinContext, O as TransitionOptions, P as MixinDescriptor, Q as ensureData, R as MixinType, S as useReactive, T as useSyncExternalStore, W as DataResourceOptions, Z as dataResource, _ as useBeforePaint, a as ExternalStoreSubscribe, at as readDataStore, b as useId, c as StartTransition, ct as FigContext, d as readContext, et as invalidateDataError, f as readData, g as useBeforeLayout, h as useActionState, i as EffectCallback, j as EmptyMixinValue, l as StateSetter, n as ActionStateRunner, nt as invalidateDataPrefix, ot as refreshData, p as readPromise, r as DependencyList, t as ActionStateAction, tt as invalidateDataKey, u as preloadData, ut as createContext, v as useCallback, w as useState, x as useMemo, y as useDeferredValue } from "./hooks-
|
|
1
|
+
import { A as Fragment, At as preconnect, B as ViewTransitionPhase, Bt as DataResourceLoadContext, C as FigNode, Et as font, F as SuspenseProps, Ft as title, H as ViewTransitionSurface, I as ViewTransition, It as DataRefreshResult, Jt as FigDataStoreHandle, Kt as FigDataStoreController, L as ViewTransitionCallback, Lt as DataResource, M as LazyLoader, N as Props, Nt as script, O as FigViewTransition, Ot as meta, P as Suspense, Pt as stylesheet, Q as isValidElement, R as ViewTransitionClass, Rt as DataResourceKey, U as clientReference, V as ViewTransitionProps, Vt as DataResourceLoader, W as createElement, Wt as FigDataHydrationEntry, Xt as FigDataStoreOptions, _ as FigClientReference, _t as StylesheetResource, a as AwaitedFigNode, at as ClientReferenceAssets, c as ComponentType, ct as FigAssetResource, d as ErrorBoundaryProps, dt as MetaResource, et as lazy, f as ErrorInfo, ft as MetaResourceOptions, gt as ScriptResource, ht as PreloadResource, it as AssetsProps, j as Key, jt as preload, kt as modulepreload, l as ElementType, lt as FigAssetResourceList, mt as PreconnectResource, n as ActivityMode, o as ClientReferenceOptions, ot as CrossOrigin, pt as ModulePreloadResource, r as ActivityProps, s as ComponentProps, st as FetchPriority, t as Activity, tt as AssetResourceBlocking, u as ErrorBoundary, ut as FontResource, vt as TitleResource, w as FigPortal, wt as assets, y as FigElement, z as ViewTransitionEvent, zt as DataResourceKeyInput } from "./element-BVg1bKOz.js";
|
|
2
|
+
import { $ as invalidateData, A as transition, B as createMixin, C as useStableEvent, E as useTransition, F as MixinFactory, I as MixinInput, J as createDataStore, L as MixinResult, N as MixinContext, O as TransitionOptions, P as MixinDescriptor, Q as ensureData, R as MixinType, S as useReactive, T as useSyncExternalStore, W as DataResourceOptions, Z as dataResource, _ as useBeforePaint, a as ExternalStoreSubscribe, at as readDataStore, b as useId, c as StartTransition, ct as FigContext, d as readContext, et as invalidateDataError, f as readData, g as useBeforeLayout, h as useActionState, i as EffectCallback, j as EmptyMixinValue, l as StateSetter, n as ActionStateRunner, nt as invalidateDataPrefix, ot as refreshData, p as readPromise, r as DependencyList, t as ActionStateAction, tt as invalidateDataKey, u as preloadData, ut as createContext, v as useCallback, w as useState, x as useMemo, y as useDeferredValue } from "./hooks-B7BTQWiu.js";
|
|
3
3
|
export { type ActionStateAction, type ActionStateRunner, Activity, type ActivityMode, type ActivityProps, type AssetResourceBlocking, type AssetsProps, type AwaitedFigNode, type ClientReferenceAssets, type ClientReferenceOptions, type ComponentProps, type ComponentType, type CrossOrigin, type DataRefreshResult, type DataResource, type DataResourceKey, type DataResourceKeyInput, type DataResourceLoadContext, type DataResourceLoader, type DataResourceOptions, type DependencyList, type EffectCallback, type ElementType, type EmptyMixinValue, ErrorBoundary, type ErrorBoundaryProps, type ErrorInfo, type ExternalStoreSubscribe, type FetchPriority, type FigAssetResource, type FigAssetResourceList, type FigClientReference, type FigContext, type FigDataHydrationEntry, type FigDataStoreController, type FigDataStoreHandle, type FigDataStoreOptions, type FigElement, type FigNode, type FigPortal, type FigViewTransition, type FontResource, Fragment, type Key, type LazyLoader, type MetaResource, type MetaResourceOptions, type MixinContext, type MixinDescriptor, type MixinFactory, type MixinInput, type MixinResult, type MixinType, type ModulePreloadResource, type PreconnectResource, type PreloadResource, type Props, type ScriptResource, type StartTransition, type StateSetter, type StylesheetResource, Suspense, type SuspenseProps, type TitleResource, type TransitionOptions, ViewTransition, type ViewTransitionCallback, type ViewTransitionClass, type ViewTransitionEvent, type ViewTransitionPhase, type ViewTransitionProps, type ViewTransitionSurface, assets, clientReference, createContext, createDataStore, createElement, createMixin, dataResource, ensureData, font, invalidateData, invalidateDataError, invalidateDataKey, invalidateDataPrefix, isValidElement, lazy, meta, modulepreload, preconnect, preload, preloadData, readContext, readData, readDataStore, readPromise, refreshData, script, stylesheet, title, transition, useActionState, useBeforeLayout, useBeforePaint, useCallback, useDeferredValue, useId, useMemo, useReactive, useStableEvent, useState, useSyncExternalStore, useTransition };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { c as ensureData, d as invalidateDataKey, f as invalidateDataPrefix, g as refreshData, h as readDataStore, i as createDataStore, l as invalidateData, n as transition, s as dataResource, u as invalidateDataError, y as createContext } from "./transition-CC4kjjrU.js";
|
|
2
2
|
import { B as useBeforePaint, E as lazy, F as readData, G as useReactive, H as useDeferredValue, I as readPromise, J as useSyncExternalStore, K as useStableEvent, N as preloadData, P as readContext, R as useActionState, U as useId, V as useCallback, W as useMemo, Y as useTransition, f as Fragment, g as createElement, h as clientReference, k as createMixin, m as ViewTransition, p as Suspense, q as useState, r as ErrorBoundary, t as Activity, w as isValidElement, z as useBeforeLayout } from "./element-DmbzNH0T.js";
|
|
3
|
-
import { _ as title, c as font, d as modulepreload, f as preconnect, g as stylesheet, h as script, o as assets, p as preload, u as meta } from "./resource-
|
|
3
|
+
import { _ as title, c as font, d as modulepreload, f as preconnect, g as stylesheet, h as script, o as assets, p as preload, u as meta } from "./resource-DskjKeuM.js";
|
|
4
4
|
export { Activity, ErrorBoundary, Fragment, Suspense, ViewTransition, assets, clientReference, createContext, createDataStore, createElement, createMixin, dataResource, ensureData, font, invalidateData, invalidateDataError, invalidateDataKey, invalidateDataPrefix, isValidElement, lazy, meta, modulepreload, preconnect, preload, preloadData, readContext, readData, readDataStore, readPromise, refreshData, script, stylesheet, title, transition, useActionState, useBeforeLayout, useBeforePaint, useCallback, useDeferredValue, useId, useMemo, useReactive, useStableEvent, useState, useSyncExternalStore, useTransition };
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as isViewTransition, $t as LoadContextHydrate, B as ViewTransitionPhase, Bt as DataResourceLoadContext, C as FigNode, Ct as assetResourceKey, D as FigSuspenseSymbol, Dt as isFigAssetResource, E as FigSuspense, F as SuspenseProps, G as createPortalNode, Gt as FigDataStore, H as ViewTransitionSurface, Ht as DataStoreEntrySnapshot, It as DataRefreshResult, J as isClientReference, Jt as FigDataStoreHandle, K as isActivity, Kt as FigDataStoreController, L as ViewTransitionCallback, Lt as DataResource, M as LazyLoader, Mt as preventAssetResourceHoist, N as Props, O as FigViewTransition, Qt as LoadContextCapabilities, R as ViewTransitionClass, Rt as DataResourceKey, S as FigErrorBoundarySymbol, St as assetResourceHostAttributes, T as FigPortalSymbol, Tt as clientReferenceAssets, Ut as FigDataEntryStatus, V as ViewTransitionProps, Wt as FigDataHydrationEntry, X as isPortal, Xt as FigDataStoreOptions, Y as isErrorBoundary, Yt as FigDataStoreHost, Z as isSuspense, Zt as LoadContextAttributeError, _ as FigClientReference, _t as StylesheetResource, a as AwaitedFigNode, an as setCurrentDataStore, at as ClientReferenceAssets, b as FigElementSymbol, bt as assetResourceFromHostAttributes, d as ErrorBoundaryProps, dt as MetaResource, en as dataResourceKeysForError, f as ErrorInfo, g as FigAssetsSymbol, gt as ScriptResource, h as FigAssets, ht as PreloadResource, i as Assets, in as resolveCurrentDataStore, j as Key, k as FigViewTransitionSymbol, l as ElementType, m as FigActivitySymbol, mt as PreconnectResource, nn as loadContextCapabilities, nt as AssetResourceDestination, o as ClientReferenceOptions, p as FigActivity, pt as ModulePreloadResource, q as isAssets, qt as FigDataStoreFactory, r as ActivityProps, rn as markDataResourceError, rt as AssetResourceHostAttribute, tn as defineLoadContextCapabilities, ut as FontResource, v as FigClientReferenceSymbol, vt as TitleResource, w as FigPortal, x as FigErrorBoundary, xt as assetResourceFromHostProps, y as FigElement, yt as assetResourceDestination, z as ViewTransitionEvent, zt as DataResourceKeyInput } from "./element-
|
|
2
|
-
import { D as TransitionHandler, G as DataStore, H as mixinSlot, J as createDataStore, K as DataStoreHost, M as FigMixinSymbol, O as TransitionOptions, U as resolveHostMix, V as markClientOnlyHostBehavior, X as currentDataStore, Y as createRendererDataStore, ct as FigContext, dt as isContext, it as normalizeDataResourceKey, k as setTransitionHandler, lt as FigContextSymbol, m as setCurrentDispatcher, o as RenderDispatcher, q as attachDataStore, rt as isDataStoreController, s as StableEventCallerArgs, st as runWithDataStore, z as clientOnlyHostBehavior } from "./hooks-
|
|
1
|
+
import { $ as isViewTransition, $t as LoadContextHydrate, B as ViewTransitionPhase, Bt as DataResourceLoadContext, C as FigNode, Ct as assetResourceKey, D as FigSuspenseSymbol, Dt as isFigAssetResource, E as FigSuspense, F as SuspenseProps, G as createPortalNode, Gt as FigDataStore, H as ViewTransitionSurface, Ht as DataStoreEntrySnapshot, It as DataRefreshResult, J as isClientReference, Jt as FigDataStoreHandle, K as isActivity, Kt as FigDataStoreController, L as ViewTransitionCallback, Lt as DataResource, M as LazyLoader, Mt as preventAssetResourceHoist, N as Props, O as FigViewTransition, Qt as LoadContextCapabilities, R as ViewTransitionClass, Rt as DataResourceKey, S as FigErrorBoundarySymbol, St as assetResourceHostAttributes, T as FigPortalSymbol, Tt as clientReferenceAssets, Ut as FigDataEntryStatus, V as ViewTransitionProps, Wt as FigDataHydrationEntry, X as isPortal, Xt as FigDataStoreOptions, Y as isErrorBoundary, Yt as FigDataStoreHost, Z as isSuspense, Zt as LoadContextAttributeError, _ as FigClientReference, _t as StylesheetResource, a as AwaitedFigNode, an as setCurrentDataStore, at as ClientReferenceAssets, b as FigElementSymbol, bt as assetResourceFromHostAttributes, d as ErrorBoundaryProps, dt as MetaResource, en as dataResourceKeysForError, f as ErrorInfo, g as FigAssetsSymbol, gt as ScriptResource, h as FigAssets, ht as PreloadResource, i as Assets, in as resolveCurrentDataStore, j as Key, k as FigViewTransitionSymbol, l as ElementType, m as FigActivitySymbol, mt as PreconnectResource, nn as loadContextCapabilities, nt as AssetResourceDestination, o as ClientReferenceOptions, p as FigActivity, pt as ModulePreloadResource, q as isAssets, qt as FigDataStoreFactory, r as ActivityProps, rn as markDataResourceError, rt as AssetResourceHostAttribute, tn as defineLoadContextCapabilities, ut as FontResource, v as FigClientReferenceSymbol, vt as TitleResource, w as FigPortal, x as FigErrorBoundary, xt as assetResourceFromHostProps, y as FigElement, yt as assetResourceDestination, z as ViewTransitionEvent, zt as DataResourceKeyInput } from "./element-BVg1bKOz.js";
|
|
2
|
+
import { D as TransitionHandler, G as DataStore, H as mixinSlot, J as createDataStore, K as DataStoreHost, M as FigMixinSymbol, O as TransitionOptions, U as resolveHostMix, V as markClientOnlyHostBehavior, X as currentDataStore, Y as createRendererDataStore, ct as FigContext, dt as isContext, it as normalizeDataResourceKey, k as setTransitionHandler, lt as FigContextSymbol, m as setCurrentDispatcher, o as RenderDispatcher, q as attachDataStore, rt as isDataStoreController, s as StableEventCallerArgs, st as runWithDataStore, z as clientOnlyHostBehavior } from "./hooks-B7BTQWiu.js";
|
|
3
3
|
//#region src/children.d.ts
|
|
4
4
|
type NormalizedChild = FigElement<any> | FigPortal<any> | PromiseLike<AwaitedFigNode> | string;
|
|
5
5
|
declare function collectChildren(node: FigNode): NormalizedChild[];
|
|
@@ -21,8 +21,11 @@ type SerializedAssetResource = {
|
|
|
21
21
|
as: string;
|
|
22
22
|
crossorigin?: PreloadResource["crossorigin"];
|
|
23
23
|
fetchpriority?: PreloadResource["fetchpriority"];
|
|
24
|
-
href
|
|
24
|
+
href?: string;
|
|
25
|
+
imagesizes?: PreloadResource["imagesizes"];
|
|
26
|
+
imagesrcset?: PreloadResource["imagesrcset"];
|
|
25
27
|
kind: "preload";
|
|
28
|
+
referrerpolicy?: PreloadResource["referrerpolicy"];
|
|
26
29
|
type?: string;
|
|
27
30
|
} | {
|
|
28
31
|
crossorigin?: ModulePreloadResource["crossorigin"];
|
package/dist/internal.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as runWithDataStore, a as createRendererDataStore, b as isContext, i as createDataStore, m as normalizeDataResourceKey, o as currentDataStore, p as isDataStoreController, r as attachDataStore, t as setTransitionHandler, v as FigContextSymbol } from "./transition-CC4kjjrU.js";
|
|
2
2
|
import { $ as loadContextCapabilities, A as markClientOnlyHostBehavior, C as isSuspense, D as FigMixinSymbol, L as setCurrentDispatcher, M as resolveHostMix, O as clientOnlyHostBehavior, S as isPortal, T as isViewTransition, X as dataResourceKeysForError, Z as defineLoadContextCapabilities, _ as createPortalNode, a as FigAssetsSymbol, b as isClientReference, c as FigErrorBoundarySymbol, d as FigViewTransitionSymbol, et as markDataResourceError, i as FigActivitySymbol, j as mixinSlot, l as FigPortalSymbol, n as Assets, nt as setCurrentDataStore, o as FigClientReferenceSymbol, s as FigElementSymbol, tt as resolveCurrentDataStore, u as FigSuspenseSymbol, v as isActivity, w as isValidElement, x as isErrorBoundary, y as isAssets } from "./element-DmbzNH0T.js";
|
|
3
|
-
import { a as assetResourceKey, b as trackThenable, i as assetResourceHostAttributes, l as isFigAssetResource, m as preventAssetResourceHoist, n as assetResourceFromHostAttributes, r as assetResourceFromHostProps, s as clientReferenceAssets, t as assetResourceDestination, v as isThenable, y as readThenable } from "./resource-
|
|
3
|
+
import { a as assetResourceKey, b as trackThenable, i as assetResourceHostAttributes, l as isFigAssetResource, m as preventAssetResourceHoist, n as assetResourceFromHostAttributes, r as assetResourceFromHostProps, s as clientReferenceAssets, t as assetResourceDestination, v as isThenable, y as readThenable } from "./resource-DskjKeuM.js";
|
|
4
4
|
import { _ as serializePayloadArray, b as serializePayloadSet, c as definePayloadGraphElement, d as encodePayloadValueWithGraph, g as rollbackPayloadGraph, h as jsonPayloadCodec, i as decodePayloadDataEntries, l as encodePayloadDataEntries, m as isPlainPayloadValue, n as checkpointPayloadGraph, o as decodePayloadValue, p as isPayloadSpecialModel, r as createPayloadGraphEncodeContext, t as assertPayloadCodecMatches, u as encodePayloadValue, v as serializePayloadMap, y as serializePayloadPlainObject } from "./payload-format-KTNaSI4h.js";
|
|
5
5
|
//#region src/children.ts
|
|
6
6
|
function collectChildren(node) {
|
|
@@ -29,6 +29,7 @@ function collectChild(node, children) {
|
|
|
29
29
|
throw invalidChildError(node);
|
|
30
30
|
}
|
|
31
31
|
function appendTextChild(children, text) {
|
|
32
|
+
if (text === "") return;
|
|
32
33
|
const previous = children.at(-1);
|
|
33
34
|
if (typeof previous === "string") children[children.length - 1] = `${previous}${text}`;
|
|
34
35
|
else children.push(text);
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","names":[],"sources":["../src/children.ts","../src/dom-nesting.ts","../src/suspense-protocol.ts"],"sourcesContent":["import {\n type AwaitedFigNode,\n type FigElement,\n type FigNode,\n type FigPortal,\n isPortal,\n isValidElement,\n} from \"./element.ts\";\nimport { isThenable } from \"./thenables.ts\";\n\n// What normalization leaves behind: arrays are flattened, null/undefined/\n// booleans are dropped, and numbers are stringified into (merged) text.\nexport type NormalizedChild =\n | FigElement<any>\n | FigPortal<any>\n | PromiseLike<AwaitedFigNode>\n | string;\n\n// Child normalization shared by the reconciler and the server renderer.\n// Adjacent text merging here MUST match on both sides: the server emits\n// merged text nodes into HTML, and hydration matches them against the\n// client's fiber children — divergence is a hydration mismatch.\nexport function collectChildren(node: FigNode): NormalizedChild[] {\n const children: NormalizedChild[] = [];\n collectChild(node, children);\n return children;\n}\n\nfunction collectChild(node: FigNode, children: NormalizedChild[]): void {\n if (Array.isArray(node)) {\n for (const child of node) collectChild(child, children);\n return;\n }\n\n if (node === null || node === undefined || typeof node === \"boolean\") return;\n\n if (typeof node === \"string\" || typeof node === \"number\") {\n appendTextChild(children, String(node));\n return;\n }\n\n if (isValidElement(node) || isPortal(node)) {\n children.push(node);\n return;\n }\n\n if (isThenable(node)) {\n children.push(node);\n return;\n }\n\n throw invalidChildError(node);\n}\n\nfunction appendTextChild(children: NormalizedChild[], text: string): void {\n const previous = children.at(-1);\n\n if (typeof previous === \"string\") {\n children[children.length - 1] = `${previous}${text}`;\n } else {\n children.push(text);\n }\n}\n\nexport function invalidChildError(value: unknown): Error {\n return new Error(\n `Invalid Fig child: ${describeInvalidChild(value)}. Render a string, number, element, promise, array, boolean, null, or undefined.`,\n );\n}\n\nexport function describeInvalidChild(value: unknown): string {\n if (typeof value !== \"object\" || value === null) return typeof value;\n\n const keys = Object.keys(value);\n return keys.length === 0 ? \"object\" : `object with keys ${keys.join(\", \")}`;\n}\n","const phrasingContainers = \"|a|button|p|\";\n\n// HTML parser auto-close rules are scoped: these tags reset the \"is there an\n// open <a>/<button>/<p>?\" checks, so e.g. <a><table><td><a> and\n// <p><button><div> parse without re-parenting and must not be flagged.\n// <button> additionally terminates button scope (the <p> auto-close check).\nconst scopeTerminators =\n \"|applet|caption|desc|foreignobject|html|marquee|object|table|td|template|th|title|\";\n\nconst pAutoClosingTags =\n \"|address|article|aside|blockquote|center|details|dialog|dir|div|dl|fieldset|figcaption|figure|footer|form|h1|h2|h3|h4|h5|h6|header|hgroup|hr|main|menu|nav|ol|p|pre|section|table|ul|\";\n\nconst headChildren =\n \"|base|basefont|bgsound|link|meta|title|noscript|noframes|script|style|template|\";\n\nconst specialTags =\n \"|address|applet|area|article|aside|base|basefont|bgsound|blockquote|body|br|button|caption|center|col|colgroup|dd|details|dir|div|dl|dt|embed|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hgroup|hr|html|iframe|img|input|keygen|li|link|listing|main|marquee|menu|meta|nav|noembed|noframes|noscript|object|ol|p|param|plaintext|pre|script|section|select|source|style|summary|table|tbody|td|template|textarea|tfoot|th|thead|title|tr|track|ul|wbr|xmp|mi|mo|mn|ms|mtext|annotation-xml|foreignobject|desc|\";\n\nexport function validateInstanceNesting(\n type: string,\n ancestors: readonly string[],\n): void {\n const child = normalizedTag(type);\n const parent =\n ancestors[0] === undefined ? null : normalizedTag(ancestors[0]);\n\n if (parent !== null && !validWithParent(child, parent)) {\n throw invalidNestingError(\n `<${child}> cannot be a child of <${parent}>.${hintFor(child, parent)}`,\n );\n }\n\n const invalidAncestor = invalidAncestorFor(child, ancestors);\n if (invalidAncestor !== null) {\n throw invalidNestingError(\n `<${child}> cannot appear inside <${invalidAncestor}>.`,\n );\n }\n}\n\nexport function validateTextNesting(\n text: string,\n ancestors: readonly string[],\n): void {\n // Whitespace-only text is inserted in place even inside tables (\"in table\n // text\" mode only foster-parents non-whitespace), so it is harmless.\n if (!/[^ \\t\\n\\r\\f]/.test(text)) return;\n\n const parent =\n ancestors[0] === undefined ? null : normalizedTag(ancestors[0]);\n if (parent === null || validTextWithParent(parent)) return;\n\n throw invalidNestingError(`text cannot be a child of <${parent}>.`);\n}\n\nfunction validWithParent(child: string, parent: string): boolean {\n switch (parent) {\n case \"select\":\n return (\n child === \"hr\" ||\n child === \"option\" ||\n child === \"optgroup\" ||\n child === \"script\" ||\n child === \"template\"\n );\n case \"optgroup\":\n return child === \"option\";\n case \"option\":\n return false;\n case \"tr\":\n return child === \"th\" || child === \"td\" || scriptLike(child);\n case \"tbody\":\n case \"thead\":\n case \"tfoot\":\n return child === \"tr\" || scriptLike(child);\n case \"colgroup\":\n return child === \"col\" || child === \"template\";\n case \"table\":\n return (\n child === \"caption\" ||\n child === \"colgroup\" ||\n child === \"tbody\" ||\n child === \"tfoot\" ||\n child === \"thead\" ||\n scriptLike(child)\n );\n case \"head\":\n return tagIn(headChildren, child);\n case \"html\":\n return child === \"head\" || child === \"body\";\n case \"frameset\":\n return child === \"frame\";\n }\n\n switch (child) {\n case \"caption\":\n case \"col\":\n case \"colgroup\":\n case \"tbody\":\n case \"tfoot\":\n case \"thead\":\n case \"tr\":\n return parent === \"template\";\n case \"td\":\n case \"th\":\n return parent === \"tr\" || parent === \"template\";\n case \"option\":\n return parent === \"datalist\" || parent === \"template\";\n case \"optgroup\":\n return parent === \"template\";\n case \"head\":\n case \"body\":\n case \"frameset\":\n return parent === \"html\" || parent === \"template\";\n case \"frame\":\n return parent === \"template\";\n case \"html\":\n return false;\n }\n\n return true;\n}\n\nfunction validTextWithParent(parent: string): boolean {\n // <option>, <select>, and <optgroup> reject element children, but the\n // parser inserts character tokens into them in place, so text is legal.\n return (\n parent === \"option\" ||\n parent === \"select\" ||\n parent === \"optgroup\" ||\n validWithParent(\"#text\", parent)\n );\n}\n\nfunction invalidAncestorFor(\n child: string,\n ancestors: readonly string[],\n): string | null {\n let inScope = true;\n let inButtonScope = true;\n let inListScope = true;\n let inTemplate = false;\n\n for (const ancestorType of ancestors) {\n const ancestor = normalizedTag(ancestorType);\n\n if (child === ancestor && tagIn(phrasingContainers, child)) {\n if (child === \"p\" ? inButtonScope : inScope) return ancestor;\n }\n if (inButtonScope && ancestor === \"p\" && tagIn(pAutoClosingTags, child)) {\n return ancestor;\n }\n if (inListScope && listItemAncestor(child, ancestor)) return ancestor;\n // The parser's form element pointer ignores scope but resets in templates.\n if (!inTemplate && ancestor === \"form\" && child === \"form\") return ancestor;\n\n if (tagIn(scopeTerminators, ancestor)) {\n if (ancestor === \"template\") inTemplate = true;\n inScope = false;\n inButtonScope = false;\n } else if (ancestor === \"button\") {\n inButtonScope = false;\n }\n // li/dd/dt auto-closing sees through phrasing/formatting wrappers and\n // address/div/p; other special elements terminate the parser walk.\n if (\n tagIn(specialTags, ancestor) &&\n ancestor !== \"address\" &&\n ancestor !== \"div\" &&\n ancestor !== \"p\"\n ) {\n inListScope = false;\n }\n }\n\n return null;\n}\n\nfunction listItemAncestor(child: string, ancestor: string): boolean {\n if (child === \"li\") return ancestor === \"li\";\n if (child === \"dd\" || child === \"dt\") {\n return ancestor === \"dd\" || ancestor === \"dt\";\n }\n return false;\n}\n\nfunction normalizedTag(type: string): string {\n return type.toLowerCase();\n}\n\nfunction scriptLike(tag: string): boolean {\n return tag === \"script\" || tag === \"style\" || tag === \"template\";\n}\n\nfunction hintFor(child: string, parent: string): string {\n if (parent === \"table\" && child === \"tr\") {\n return \" Add a <tbody>, <thead>, or <tfoot>.\";\n }\n\n return \"\";\n}\n\nfunction invalidNestingError(message: string): Error {\n return new Error(`Invalid DOM nesting: ${message}`);\n}\n\nfunction tagIn(tags: string, tag: string): boolean {\n return tags.includes(`|${tag}|`);\n}\n","// The Suspense streaming wire format shared by the server renderer (which\n// emits these markers as HTML comments and interpolates them into the inline\n// reveal script) and fig-dom (which parses them into dehydrated boundaries).\n// Changing any value is a protocol change: server output and client parsing\n// must move together.\n\nexport const SUSPENSE_MARKER_PREFIX = \"fig:suspense:\";\nexport const SUSPENSE_COMPLETED_MARKER = \"fig:suspense:completed\";\nexport const SUSPENSE_CLIENT_MARKER = \"fig:suspense:client\";\nexport const SUSPENSE_PENDING_PREFIX = \"fig:suspense:pending:\";\nexport const SUSPENSE_END_MARKER = \"/fig:suspense\";\n\n// The server emits a comment with exactly this data between adjacent text\n// writes that come from different normalized text children: the HTML parser\n// would otherwise merge them into one DOM text node while the client keeps\n// one text fiber each. fig-dom's hydration cursor skips only comments whose\n// data matches this value (fig:suspense markers use their own prefixes).\nexport const TEXT_SEPARATOR_DATA = \",\";\n\n// Hidden Activity content streams inside an inert template carrying this\n// attribute; the client treats such templates as dehydrated boundaries.\nexport const ACTIVITY_TEMPLATE_ATTRIBUTE = \"data-fig-activity\";\n\nexport const VIEW_TRANSITION_NAME_ATTRIBUTE = \"data-fig-vt-name\";\nexport const VIEW_TRANSITION_CLASS_ATTRIBUTE = \"data-fig-vt-class\";\n\n// Per-document mutex holding the currently running view transition. Client\n// commits and inline streaming reveals both wait on it before proceeding.\nexport const VIEW_TRANSITION_PENDING_PROPERTY = \"__figViewTransition\";\n// React's maximum suspended-commit wait, shared with streaming reveals so a\n// non-settling transition cannot hold either path indefinitely.\nexport const VIEW_TRANSITION_TIMEOUT_MS = 60_000;\n\n// Early-event capture: a tiny inline script at the top of a server-rendered\n// document queues replayable events that fire before the client bundle\n// executes. The first hydration root drains the queue, removes the capture\n// listeners, and replays claimed events through the standard replay path.\n// The event list must stay in sync with fig-dom's replayable set — a\n// discrete replay forces synchronous hydration of its target, which is what\n// makes pre-bundle clicks safe to honor.\nexport const HYDRATION_SKIP_ATTRIBUTE = \"data-fig-hydration-skip\";\nexport const EARLY_EVENT_QUEUE_PROPERTY = \"__figEarlyEvents\";\nexport const EARLY_EVENT_HANDLER_PROPERTY = \"__figEarlyEventHandler\";\nexport const REPLAYABLE_EVENT_TYPES = [\n \"click\",\n \"keydown\",\n \"keyup\",\n \"pointerdown\",\n \"pointerup\",\n] as const;\n"],"mappings":";;;;;AAsBA,SAAgB,gBAAgB,MAAkC;CAChE,MAAM,WAA8B,CAAC;CACrC,aAAa,MAAM,QAAQ;CAC3B,OAAO;AACT;AAEA,SAAS,aAAa,MAAe,UAAmC;CACtE,IAAI,MAAM,QAAQ,IAAI,GAAG;EACvB,KAAK,MAAM,SAAS,MAAM,aAAa,OAA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,KAAsB;CACjD,OAAO,KAAK,SAAS,IAAI,IAAI,EAAE;AACjC;;;AC1MA,MAAa,yBAAyB;AACtC,MAAa,4BAA4B;AACzC,MAAa,yBAAyB;AACtC,MAAa,0BAA0B;AACvC,MAAa,sBAAsB;AAOnC,MAAa,sBAAsB;AAInC,MAAa,8BAA8B;AAE3C,MAAa,iCAAiC;AAC9C,MAAa,kCAAkC;AAI/C,MAAa,mCAAmC;AAGhD,MAAa,6BAA6B;AAS1C,MAAa,2BAA2B;AACxC,MAAa,6BAA6B;AAC1C,MAAa,+BAA+B;AAC5C,MAAa,yBAAyB;CACpC;CACA;CACA;CACA;CACA;AACF"}
|
|
1
|
+
{"version":3,"file":"internal.js","names":[],"sources":["../src/children.ts","../src/dom-nesting.ts","../src/suspense-protocol.ts"],"sourcesContent":["import {\n type AwaitedFigNode,\n type FigElement,\n type FigNode,\n type FigPortal,\n isPortal,\n isValidElement,\n} from \"./element.ts\";\nimport { isThenable } from \"./thenables.ts\";\n\n// What normalization leaves behind: arrays are flattened, null/undefined/\n// booleans are dropped, and numbers are stringified into (merged) text.\nexport type NormalizedChild =\n | FigElement<any>\n | FigPortal<any>\n | PromiseLike<AwaitedFigNode>\n | string;\n\n// Child normalization shared by the reconciler and the server renderer.\n// Adjacent text merging here MUST match on both sides: the server emits\n// merged text nodes into HTML, and hydration matches them against the\n// client's fiber children — divergence is a hydration mismatch.\nexport function collectChildren(node: FigNode): NormalizedChild[] {\n const children: NormalizedChild[] = [];\n collectChild(node, children);\n return children;\n}\n\nfunction collectChild(node: FigNode, children: NormalizedChild[]): void {\n if (Array.isArray(node)) {\n for (const child of node) collectChild(child, children);\n return;\n }\n\n if (node === null || node === undefined || typeof node === \"boolean\") return;\n\n if (typeof node === \"string\" || typeof node === \"number\") {\n appendTextChild(children, String(node));\n return;\n }\n\n if (isValidElement(node) || isPortal(node)) {\n children.push(node);\n return;\n }\n\n if (isThenable(node)) {\n children.push(node);\n return;\n }\n\n throw invalidChildError(node);\n}\n\nfunction appendTextChild(children: NormalizedChild[], text: string): void {\n if (text === \"\") return;\n\n const previous = children.at(-1);\n\n if (typeof previous === \"string\") {\n children[children.length - 1] = `${previous}${text}`;\n } else {\n children.push(text);\n }\n}\n\nexport function invalidChildError(value: unknown): Error {\n return new Error(\n `Invalid Fig child: ${describeInvalidChild(value)}. Render a string, number, element, promise, array, boolean, null, or undefined.`,\n );\n}\n\nexport function describeInvalidChild(value: unknown): string {\n if (typeof value !== \"object\" || value === null) return typeof value;\n\n const keys = Object.keys(value);\n return keys.length === 0 ? \"object\" : `object with keys ${keys.join(\", \")}`;\n}\n","const phrasingContainers = \"|a|button|p|\";\n\n// HTML parser auto-close rules are scoped: these tags reset the \"is there an\n// open <a>/<button>/<p>?\" checks, so e.g. <a><table><td><a> and\n// <p><button><div> parse without re-parenting and must not be flagged.\n// <button> additionally terminates button scope (the <p> auto-close check).\nconst scopeTerminators =\n \"|applet|caption|desc|foreignobject|html|marquee|object|table|td|template|th|title|\";\n\nconst pAutoClosingTags =\n \"|address|article|aside|blockquote|center|details|dialog|dir|div|dl|fieldset|figcaption|figure|footer|form|h1|h2|h3|h4|h5|h6|header|hgroup|hr|main|menu|nav|ol|p|pre|section|table|ul|\";\n\nconst headChildren =\n \"|base|basefont|bgsound|link|meta|title|noscript|noframes|script|style|template|\";\n\nconst specialTags =\n \"|address|applet|area|article|aside|base|basefont|bgsound|blockquote|body|br|button|caption|center|col|colgroup|dd|details|dir|div|dl|dt|embed|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hgroup|hr|html|iframe|img|input|keygen|li|link|listing|main|marquee|menu|meta|nav|noembed|noframes|noscript|object|ol|p|param|plaintext|pre|script|section|select|source|style|summary|table|tbody|td|template|textarea|tfoot|th|thead|title|tr|track|ul|wbr|xmp|mi|mo|mn|ms|mtext|annotation-xml|foreignobject|desc|\";\n\nexport function validateInstanceNesting(\n type: string,\n ancestors: readonly string[],\n): void {\n const child = normalizedTag(type);\n const parent =\n ancestors[0] === undefined ? null : normalizedTag(ancestors[0]);\n\n if (parent !== null && !validWithParent(child, parent)) {\n throw invalidNestingError(\n `<${child}> cannot be a child of <${parent}>.${hintFor(child, parent)}`,\n );\n }\n\n const invalidAncestor = invalidAncestorFor(child, ancestors);\n if (invalidAncestor !== null) {\n throw invalidNestingError(\n `<${child}> cannot appear inside <${invalidAncestor}>.`,\n );\n }\n}\n\nexport function validateTextNesting(\n text: string,\n ancestors: readonly string[],\n): void {\n // Whitespace-only text is inserted in place even inside tables (\"in table\n // text\" mode only foster-parents non-whitespace), so it is harmless.\n if (!/[^ \\t\\n\\r\\f]/.test(text)) return;\n\n const parent =\n ancestors[0] === undefined ? null : normalizedTag(ancestors[0]);\n if (parent === null || validTextWithParent(parent)) return;\n\n throw invalidNestingError(`text cannot be a child of <${parent}>.`);\n}\n\nfunction validWithParent(child: string, parent: string): boolean {\n switch (parent) {\n case \"select\":\n return (\n child === \"hr\" ||\n child === \"option\" ||\n child === \"optgroup\" ||\n child === \"script\" ||\n child === \"template\"\n );\n case \"optgroup\":\n return child === \"option\";\n case \"option\":\n return false;\n case \"tr\":\n return child === \"th\" || child === \"td\" || scriptLike(child);\n case \"tbody\":\n case \"thead\":\n case \"tfoot\":\n return child === \"tr\" || scriptLike(child);\n case \"colgroup\":\n return child === \"col\" || child === \"template\";\n case \"table\":\n return (\n child === \"caption\" ||\n child === \"colgroup\" ||\n child === \"tbody\" ||\n child === \"tfoot\" ||\n child === \"thead\" ||\n scriptLike(child)\n );\n case \"head\":\n return tagIn(headChildren, child);\n case \"html\":\n return child === \"head\" || child === \"body\";\n case \"frameset\":\n return child === \"frame\";\n }\n\n switch (child) {\n case \"caption\":\n case \"col\":\n case \"colgroup\":\n case \"tbody\":\n case \"tfoot\":\n case \"thead\":\n case \"tr\":\n return parent === \"template\";\n case \"td\":\n case \"th\":\n return parent === \"tr\" || parent === \"template\";\n case \"option\":\n return parent === \"datalist\" || parent === \"template\";\n case \"optgroup\":\n return parent === \"template\";\n case \"head\":\n case \"body\":\n case \"frameset\":\n return parent === \"html\" || parent === \"template\";\n case \"frame\":\n return parent === \"template\";\n case \"html\":\n return false;\n }\n\n return true;\n}\n\nfunction validTextWithParent(parent: string): boolean {\n // <option>, <select>, and <optgroup> reject element children, but the\n // parser inserts character tokens into them in place, so text is legal.\n return (\n parent === \"option\" ||\n parent === \"select\" ||\n parent === \"optgroup\" ||\n validWithParent(\"#text\", parent)\n );\n}\n\nfunction invalidAncestorFor(\n child: string,\n ancestors: readonly string[],\n): string | null {\n let inScope = true;\n let inButtonScope = true;\n let inListScope = true;\n let inTemplate = false;\n\n for (const ancestorType of ancestors) {\n const ancestor = normalizedTag(ancestorType);\n\n if (child === ancestor && tagIn(phrasingContainers, child)) {\n if (child === \"p\" ? inButtonScope : inScope) return ancestor;\n }\n if (inButtonScope && ancestor === \"p\" && tagIn(pAutoClosingTags, child)) {\n return ancestor;\n }\n if (inListScope && listItemAncestor(child, ancestor)) return ancestor;\n // The parser's form element pointer ignores scope but resets in templates.\n if (!inTemplate && ancestor === \"form\" && child === \"form\") return ancestor;\n\n if (tagIn(scopeTerminators, ancestor)) {\n if (ancestor === \"template\") inTemplate = true;\n inScope = false;\n inButtonScope = false;\n } else if (ancestor === \"button\") {\n inButtonScope = false;\n }\n // li/dd/dt auto-closing sees through phrasing/formatting wrappers and\n // address/div/p; other special elements terminate the parser walk.\n if (\n tagIn(specialTags, ancestor) &&\n ancestor !== \"address\" &&\n ancestor !== \"div\" &&\n ancestor !== \"p\"\n ) {\n inListScope = false;\n }\n }\n\n return null;\n}\n\nfunction listItemAncestor(child: string, ancestor: string): boolean {\n if (child === \"li\") return ancestor === \"li\";\n if (child === \"dd\" || child === \"dt\") {\n return ancestor === \"dd\" || ancestor === \"dt\";\n }\n return false;\n}\n\nfunction normalizedTag(type: string): string {\n return type.toLowerCase();\n}\n\nfunction scriptLike(tag: string): boolean {\n return tag === \"script\" || tag === \"style\" || tag === \"template\";\n}\n\nfunction hintFor(child: string, parent: string): string {\n if (parent === \"table\" && child === \"tr\") {\n return \" Add a <tbody>, <thead>, or <tfoot>.\";\n }\n\n return \"\";\n}\n\nfunction invalidNestingError(message: string): Error {\n return new Error(`Invalid DOM nesting: ${message}`);\n}\n\nfunction tagIn(tags: string, tag: string): boolean {\n return tags.includes(`|${tag}|`);\n}\n","// The Suspense streaming wire format shared by the server renderer (which\n// emits these markers as HTML comments and interpolates them into the inline\n// reveal script) and fig-dom (which parses them into dehydrated boundaries).\n// Changing any value is a protocol change: server output and client parsing\n// must move together.\n\nexport const SUSPENSE_MARKER_PREFIX = \"fig:suspense:\";\nexport const SUSPENSE_COMPLETED_MARKER = \"fig:suspense:completed\";\nexport const SUSPENSE_CLIENT_MARKER = \"fig:suspense:client\";\nexport const SUSPENSE_PENDING_PREFIX = \"fig:suspense:pending:\";\nexport const SUSPENSE_END_MARKER = \"/fig:suspense\";\n\n// The server emits a comment with exactly this data between adjacent text\n// writes that come from different normalized text children: the HTML parser\n// would otherwise merge them into one DOM text node while the client keeps\n// one text fiber each. fig-dom's hydration cursor skips only comments whose\n// data matches this value (fig:suspense markers use their own prefixes).\nexport const TEXT_SEPARATOR_DATA = \",\";\n\n// Hidden Activity content streams inside an inert template carrying this\n// attribute; the client treats such templates as dehydrated boundaries.\nexport const ACTIVITY_TEMPLATE_ATTRIBUTE = \"data-fig-activity\";\n\nexport const VIEW_TRANSITION_NAME_ATTRIBUTE = \"data-fig-vt-name\";\nexport const VIEW_TRANSITION_CLASS_ATTRIBUTE = \"data-fig-vt-class\";\n\n// Per-document mutex holding the currently running view transition. Client\n// commits and inline streaming reveals both wait on it before proceeding.\nexport const VIEW_TRANSITION_PENDING_PROPERTY = \"__figViewTransition\";\n// React's maximum suspended-commit wait, shared with streaming reveals so a\n// non-settling transition cannot hold either path indefinitely.\nexport const VIEW_TRANSITION_TIMEOUT_MS = 60_000;\n\n// Early-event capture: a tiny inline script at the top of a server-rendered\n// document queues replayable events that fire before the client bundle\n// executes. The first hydration root drains the queue, removes the capture\n// listeners, and replays claimed events through the standard replay path.\n// The event list must stay in sync with fig-dom's replayable set — a\n// discrete replay forces synchronous hydration of its target, which is what\n// makes pre-bundle clicks safe to honor.\nexport const HYDRATION_SKIP_ATTRIBUTE = \"data-fig-hydration-skip\";\nexport const EARLY_EVENT_QUEUE_PROPERTY = \"__figEarlyEvents\";\nexport const EARLY_EVENT_HANDLER_PROPERTY = \"__figEarlyEventHandler\";\nexport const REPLAYABLE_EVENT_TYPES = [\n \"click\",\n \"keydown\",\n \"keyup\",\n \"pointerdown\",\n \"pointerup\",\n] as const;\n"],"mappings":";;;;;AAsBA,SAAgB,gBAAgB,MAAkC;CAChE,MAAM,WAA8B,CAAC;CACrC,aAAa,MAAM,QAAQ;CAC3B,OAAO;AACT;AAEA,SAAS,aAAa,MAAe,UAAmC;CACtE,IAAI,MAAM,QAAQ,IAAI,GAAG;EACvB,KAAK,MAAM,SAAS,MAAM,aAAa,OAAO,QAAQ;EACtD;CACF;CAEA,IAAI,SAAS,QAAQ,SAAS,KAAA,KAAa,OAAO,SAAS,WAAW;CAEtE,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU;EACxD,gBAAgB,UAAU,OAAO,IAAI,CAAC;EACtC;CACF;CAEA,IAAI,eAAe,IAAI,KAAK,SAAS,IAAI,GAAG;EAC1C,SAAS,KAAK,IAAI;EAClB;CACF;CAEA,IAAI,WAAW,IAAI,GAAG;EACpB,SAAS,KAAK,IAAI;EAClB;CACF;CAEA,MAAM,kBAAkB,IAAI;AAC9B;AAEA,SAAS,gBAAgB,UAA6B,MAAoB;CACxE,IAAI,SAAS,IAAI;CAEjB,MAAM,WAAW,SAAS,GAAG,EAAE;CAE/B,IAAI,OAAO,aAAa,UACtB,SAAS,SAAS,SAAS,KAAK,GAAG,WAAW;MAE9C,SAAS,KAAK,IAAI;AAEtB;AAEA,SAAgB,kBAAkB,OAAuB;CACvD,uBAAO,IAAI,MACT,sBAAsB,qBAAqB,KAAK,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gBAAgB;EAClB,OAAO,IAAI,aAAa,UACtB,gBAAgB;EAIlB,IACE,MAAM,aAAa,QAAQ,KAC3B,aAAa,aACb,aAAa,SACb,aAAa,KAEb,cAAc;CAElB;CAEA,OAAO;AACT;AAEA,SAAS,iBAAiB,OAAe,UAA2B;CAClE,IAAI,UAAU,MAAM,OAAO,aAAa;CACxC,IAAI,UAAU,QAAQ,UAAU,MAC9B,OAAO,aAAa,QAAQ,aAAa;CAE3C,OAAO;AACT;AAEA,SAAS,cAAc,MAAsB;CAC3C,OAAO,KAAK,YAAY;AAC1B;AAEA,SAAS,WAAW,KAAsB;CACxC,OAAO,QAAQ,YAAY,QAAQ,WAAW,QAAQ;AACxD;AAEA,SAAS,QAAQ,OAAe,QAAwB;CACtD,IAAI,WAAW,WAAW,UAAU,MAClC,OAAO;CAGT,OAAO;AACT;AAEA,SAAS,oBAAoB,SAAwB;CACnD,uBAAO,IAAI,MAAM,wBAAwB,SAAS;AACpD;AAEA,SAAS,MAAM,MAAc,KAAsB;CACjD,OAAO,KAAK,SAAS,IAAI,IAAI,EAAE;AACjC;;;AC1MA,MAAa,yBAAyB;AACtC,MAAa,4BAA4B;AACzC,MAAa,yBAAyB;AACtC,MAAa,0BAA0B;AACvC,MAAa,sBAAsB;AAOnC,MAAa,sBAAsB;AAInC,MAAa,8BAA8B;AAE3C,MAAa,iCAAiC;AAC9C,MAAa,kCAAkC;AAI/C,MAAa,mCAAmC;AAGhD,MAAa,6BAA6B;AAS1C,MAAa,2BAA2B;AACxC,MAAa,6BAA6B;AAC1C,MAAa,+BAA+B;AAC5C,MAAa,yBAAyB;CACpC;CACA;CACA;CACA;CACA;AACF"}
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as Fragment, C as FigNode, j as Key, l as ElementType, y as FigElement } from "./element-
|
|
1
|
+
import { A as Fragment, C as FigNode, j as Key, l as ElementType, y as FigElement } from "./element-BVg1bKOz.js";
|
|
2
2
|
//#region src/jsx-runtime.d.ts
|
|
3
3
|
type JSXProps = Record<string, unknown>;
|
|
4
4
|
declare function jsx(type: ElementType, props: JSXProps | null, key?: string | number): FigElement;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payload-format-KTNaSI4h.js","names":[],"sources":["../src/payload-format.ts"],"sourcesContent":["import type { FigDataHydrationEntry } from \"./data.ts\";\nimport type { Key } from \"./element.ts\";\nimport type {\n FontResource,\n MetaResource,\n ModulePreloadResource,\n PreconnectResource,\n PreloadResource,\n ScriptResource,\n StylesheetResource,\n TitleResource,\n} from \"./resource.ts\";\n\n// Asset resources represented as descriptor data. Optional fields stay optional\n// on the wire; omitted `undefined` values are part of the payload contract, not\n// a serializer implementation detail. Delivery assets prepare eagerly at row\n// arrival; document metadata stays attached to its owning decoded row until\n// that row commits.\nexport type SerializedAssetResource =\n | {\n crossorigin?: StylesheetResource[\"crossorigin\"];\n href: string;\n kind: \"stylesheet\";\n media?: string;\n precedence?: string;\n }\n | {\n as: string;\n crossorigin?: PreloadResource[\"crossorigin\"];\n fetchpriority?: PreloadResource[\"fetchpriority\"];\n href: string;\n kind: \"preload\";\n type?: string;\n }\n | {\n crossorigin?: ModulePreloadResource[\"crossorigin\"];\n fetchpriority?: ModulePreloadResource[\"fetchpriority\"];\n href: string;\n kind: \"modulepreload\";\n }\n | {\n async?: boolean;\n crossorigin?: ScriptResource[\"crossorigin\"];\n defer?: boolean;\n kind: \"script\";\n module?: boolean;\n src: string;\n }\n | {\n crossorigin?: FontResource[\"crossorigin\"];\n fetchpriority?: FontResource[\"fetchpriority\"];\n href: string;\n kind: \"font\";\n type: string;\n }\n | {\n crossorigin?: PreconnectResource[\"crossorigin\"];\n href: string;\n kind: \"preconnect\";\n }\n | {\n kind: \"title\";\n value: TitleResource[\"value\"];\n }\n | {\n charset?: MetaResource[\"charset\"];\n content?: MetaResource[\"content\"];\n \"http-equiv\"?: MetaResource[\"http-equiv\"];\n key?: string;\n kind: \"meta\";\n name?: MetaResource[\"name\"];\n property?: MetaResource[\"property\"];\n };\n\n/** The `error` row value under the server's `onError` contract. */\nexport interface PayloadErrorValue {\n digest?: string;\n message?: string;\n}\n\n/**\n * Semantic payload row before the internal codec turns it into bytes.\n */\nexport type PayloadRow =\n | { for?: number; tag: \"assets\"; value: SerializedAssetResource[] }\n | {\n id: number;\n tag: \"client\";\n value: {\n id: string;\n assets?: SerializedAssetResource[];\n exportName?: string;\n ssr?: true;\n };\n }\n | { tag: \"data\"; value: PayloadDataHydrationEntry[] }\n | { id: number; tag: \"error\"; value: PayloadErrorValue }\n | { id: number; tag: \"model\"; value: PayloadModel };\n\n/**\n * Transport-safe model value used inside internal payload rows. This is an\n * implementation format, not an application data format.\n */\nexport type PayloadModel =\n | null\n | boolean\n | number\n | string\n | PayloadModel[]\n | { [key: string]: PayloadModel }\n | PayloadElementModel\n | PayloadSpecialModel;\n\nexport type PayloadElementModel = {\n $fig: \"element\";\n id?: number;\n key: Key | null;\n props: PayloadModel;\n type: string | PayloadSpecialModel;\n};\n\nexport type PayloadSpecialModel =\n | { $fig: \"array\"; id: number; value: PayloadModel[] }\n | { $fig: \"bigint\"; value: string }\n | { $fig: \"client\"; id: number }\n | { $fig: \"date\"; value: string }\n | { $fig: \"fragment\" }\n | { $fig: \"lazy\"; id: number }\n | { $fig: \"map\"; entries: Array<[PayloadModel, PayloadModel]>; id: number }\n | { $fig: \"number\"; value: \"Infinity\" | \"-Infinity\" | \"-0\" | \"NaN\" }\n | { $fig: \"object\"; id?: number; value: Record<string, PayloadModel> }\n | { $fig: \"promise\"; id: number }\n | { $fig: \"ref\"; id: number }\n | { $fig: \"set\"; id: number; values: PayloadModel[] }\n | { $fig: \"symbol\"; key: string }\n | { $fig: \"suspense\" }\n | { $fig: \"undefined\" }\n | { $fig: \"view-transition\" };\n\nexport type PayloadValueSpecialModel = Extract<\n PayloadSpecialModel,\n {\n $fig:\n | \"array\"\n | \"bigint\"\n | \"date\"\n | \"map\"\n | \"number\"\n | \"object\"\n | \"ref\"\n | \"set\"\n | \"symbol\"\n | \"undefined\";\n }\n>;\n\nexport type PayloadDataHydrationEntry = Omit<FigDataHydrationEntry, \"value\"> & {\n value: PayloadModel;\n};\n\nexport interface PayloadCodec {\n /**\n * Opaque implementation id, e.g. \"json\" or \"binary\". Fig checks this id at\n * transport boundaries; the encoded byte layout is not a public contract.\n */\n readonly id: string;\n readonly contentType: string;\n /**\n * Creates a streaming row decoder. The decoder calls `onRow` for each\n * complete semantic row. If `onRow` throws, the decoder must propagate that\n * error; when it can already see more complete sibling rows in the same\n * input chunk, it should process those siblings before rethrowing so\n * notifications already implied by earlier rows are not lost.\n */\n createDecoder(onRow: (row: PayloadRow) => void): PayloadRowDecoder;\n encodeRow(row: PayloadRow): Uint8Array;\n}\n\nexport interface PayloadRowDecoder {\n decode(chunk: Uint8Array): void;\n flush(): void;\n}\n\nconst textEncoder = new TextEncoder();\n\n/**\n * Readable development-oriented codec: one JSON payload row per newline.\n */\nexport const jsonPayloadCodec: PayloadCodec = {\n id: \"json\",\n contentType: \"text/x-fig-payload; codec=json; charset=utf-8\",\n createDecoder(onRow) {\n return createJsonPayloadDecoder(onRow);\n },\n encodeRow(row) {\n return textEncoder.encode(`${JSON.stringify(row)}\\n`);\n },\n};\n\nfunction createJsonPayloadDecoder(\n onRow: (row: PayloadRow) => void,\n): PayloadRowDecoder {\n const decoder = new TextDecoder();\n let buffer = \"\";\n let searchStart = 0;\n\n function processBufferedLines(): void {\n let lineStart = 0;\n let firstError: unknown;\n\n for (;;) {\n const newlineIndex = buffer.indexOf(\"\\n\", searchStart);\n if (newlineIndex === -1) {\n searchStart = buffer.length;\n break;\n }\n try {\n processPayloadLine(buffer.slice(lineStart, newlineIndex), onRow);\n } catch (error) {\n firstError ??= error;\n }\n lineStart = newlineIndex + 1;\n searchStart = lineStart;\n }\n\n if (firstError !== undefined) {\n buffer = \"\";\n searchStart = 0;\n throw firstError;\n }\n if (lineStart > 0) {\n buffer = buffer.slice(lineStart);\n searchStart -= lineStart;\n }\n }\n\n return {\n decode(chunk) {\n buffer += decoder.decode(chunk, { stream: true });\n processBufferedLines();\n },\n flush() {\n buffer += decoder.decode();\n if (buffer.length > 0) {\n const line = buffer;\n buffer = \"\";\n searchStart = 0;\n processPayloadLine(line, onRow);\n }\n },\n };\n}\n\nfunction processPayloadLine(\n line: string,\n onRow: (row: PayloadRow) => void,\n): void {\n if (line.length > 0) onRow(JSON.parse(line) as PayloadRow);\n}\n\n/**\n * Extract the codec id from a payload content-type header, or null when the\n * header carries no codec parameter.\n */\nexport function payloadCodecIdFromContentType(\n contentTypeHeader: string,\n): string | null {\n const parts = contentTypeHeader.split(\";\").slice(1);\n for (const part of parts) {\n const [name, rawValue] = part.split(\"=\");\n if (name?.trim().toLowerCase() !== \"codec\") continue;\n const value = rawValue?.trim();\n if (value === undefined || value.length === 0) return null;\n return value.replace(/^\"|\"$/g, \"\");\n }\n return null;\n}\n\n/**\n * Throw when a response content-type declares a codec other than the one this\n * client decodes with. A missing header or codec parameter passes: transports\n * that strip content types stay usable, and mismatches still fail fast when\n * declared.\n */\nexport function assertPayloadCodecMatches(\n codec: PayloadCodec,\n contentTypeHeader: string | null,\n): void {\n if (contentTypeHeader === null) return;\n const received = payloadCodecIdFromContentType(contentTypeHeader);\n if (received === null || received === codec.id) return;\n throw new Error(\n `Payload codec mismatch: producer used \"${received}\" but this client expects \"${codec.id}\".`,\n );\n}\n\n/** Decode an `error` row value into a digest-carrying Error. */\nexport function errorFromPayloadValue(value: PayloadErrorValue): Error & {\n digest?: string;\n} {\n const error = new Error(value.message ?? \"The server render failed.\");\n return value.digest === undefined\n ? error\n : Object.assign(error, { digest: value.digest });\n}\n\nexport interface PayloadGraphEncodeContext {\n // Ids are dense and monotonic: id = position in `defined` + 1, so rollback\n // is popping the stack. A reverse id→object map would be redundant state.\n defined: object[];\n ids: WeakMap<object, number>;\n}\n\ninterface PayloadGraphDecodeContext {\n decodeChild: (model: PayloadModel) => unknown;\n refs: PayloadDecodeRefs;\n}\n\nfunction createPayloadGraphDecodeContext(): PayloadGraphDecodeContext {\n const refs = new Map<number, unknown>();\n const context: PayloadGraphDecodeContext = {\n decodeChild: (model) => decodeModelValue(model, context),\n refs: {\n define(id, create, fill) {\n const value = create();\n refs.set(id, value);\n fill(value);\n return value;\n },\n read(id) {\n if (!refs.has(id)) {\n throw new Error(`Payload referenced unknown object id ${id}.`);\n }\n return refs.get(id);\n },\n },\n };\n return context;\n}\n\nexport function createPayloadGraphEncodeContext(): PayloadGraphEncodeContext {\n return { defined: [], ids: new WeakMap() };\n}\n\nexport function isPlainPayloadValue(value: unknown): boolean {\n return (\n value === null ||\n value === undefined ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n typeof value === \"bigint\" ||\n typeof value === \"symbol\"\n );\n}\n\n/**\n * Encode ordinary data values into PayloadModel. Server component references\n * such as Fig elements, promises, and client references are handled by the\n * payload renderer before ordinary values reach this helper.\n */\nexport function encodePayloadValue(value: unknown): PayloadModel {\n return encodePayloadValueWithGraph(value, createPayloadGraphEncodeContext());\n}\n\nexport function encodePayloadValueWithGraph(\n value: unknown,\n graph: PayloadGraphEncodeContext,\n): PayloadModel {\n if (value === null) return null;\n if (value === undefined) return { $fig: \"undefined\" };\n\n if (typeof value === \"string\" || typeof value === \"boolean\") return value;\n if (typeof value === \"number\") return encodePayloadNumber(value);\n if (typeof value === \"bigint\") {\n return { $fig: \"bigint\", value: value.toString() };\n }\n if (typeof value === \"symbol\") {\n const key = Symbol.keyFor(value);\n if (key === undefined) {\n throw new Error(\"Only global Symbol.for symbols can be serialized.\");\n }\n return { $fig: \"symbol\", key };\n }\n if (typeof value === \"function\") {\n throw new Error(\"Functions cannot be serialized into the payload.\");\n }\n\n if (Array.isArray(value)) {\n return serializePayloadArray(\n value,\n graph,\n () => value,\n (item) => encodePayloadValueWithGraph(item, graph),\n );\n }\n if (value instanceof Date) {\n const json = value.toJSON();\n if (json === null) {\n throw new Error(\"Invalid Date values cannot be serialized.\");\n }\n return { $fig: \"date\", value: json };\n }\n if (value instanceof Map) {\n return serializePayloadMap(value, graph, ([key, item]) => [\n encodePayloadValueWithGraph(key, graph),\n encodePayloadValueWithGraph(item, graph),\n ]);\n }\n if (value instanceof Set) {\n return serializePayloadSet(value, graph, (item) =>\n encodePayloadValueWithGraph(item, graph),\n );\n }\n\n if (typeof value === \"object\" && value !== null) {\n return serializePayloadPlainObject(value, graph, (child) =>\n encodePayloadValueWithGraph(child, graph),\n );\n }\n\n throw new Error(`Cannot serialize ${typeof value} into the payload.`);\n}\n\nexport function serializePayloadMap(\n value: Map<unknown, unknown>,\n graph: PayloadGraphEncodeContext,\n encodeEntry: (entry: [unknown, unknown]) => [PayloadModel, PayloadModel],\n): PayloadModel {\n const existing = payloadGraphReference(graph, value);\n if (existing !== null) return existing;\n const id = definePayloadGraphObject(graph, value);\n const entries: Array<[PayloadModel, PayloadModel]> = [];\n for (const entry of value) entries.push(encodeEntry(entry));\n return { $fig: \"map\", id, entries };\n}\n\nexport function serializePayloadSet(\n value: Set<unknown>,\n graph: PayloadGraphEncodeContext,\n encodeItem: (value: unknown) => PayloadModel,\n): PayloadModel {\n const existing = payloadGraphReference(graph, value);\n if (existing !== null) return existing;\n const id = definePayloadGraphObject(graph, value);\n const values: PayloadModel[] = [];\n for (const item of value) values.push(encodeItem(item));\n return { $fig: \"set\", id, values };\n}\n\nfunction payloadGraphReference(\n graph: PayloadGraphEncodeContext,\n value: object,\n): PayloadSpecialModel | null {\n const id = graph.ids.get(value);\n return id === undefined ? null : { $fig: \"ref\", id };\n}\n\nfunction definePayloadGraphObject(\n graph: PayloadGraphEncodeContext,\n value: object,\n): number {\n graph.defined.push(value);\n const id = graph.defined.length;\n graph.ids.set(value, id);\n return id;\n}\n\nexport function checkpointPayloadGraph(\n graph: PayloadGraphEncodeContext,\n): number {\n return graph.defined.length;\n}\n\nexport function rollbackPayloadGraph(\n graph: PayloadGraphEncodeContext,\n checkpoint: number,\n): void {\n while (graph.defined.length > checkpoint) {\n graph.ids.delete(graph.defined.pop() as object);\n }\n}\n\nexport function definePayloadGraphElement(\n graph: PayloadGraphEncodeContext,\n value: object,\n): number | PayloadSpecialModel {\n const existing = payloadGraphReference(graph, value);\n if (existing !== null) return existing;\n return definePayloadGraphObject(graph, value);\n}\n\nexport function serializePayloadArray<T>(\n value: object,\n graph: PayloadGraphEncodeContext,\n entries: () => readonly T[],\n encodeChild: (value: T) => PayloadModel,\n): PayloadModel {\n const existing = payloadGraphReference(graph, value);\n if (existing !== null) return existing;\n const id = definePayloadGraphObject(graph, value);\n return { $fig: \"array\", id, value: entries().map(encodeChild) };\n}\n\nexport function serializePayloadPlainObject(\n value: object,\n graph: PayloadGraphEncodeContext,\n encodeChild: (value: unknown) => PayloadModel,\n): PayloadModel {\n const existing = payloadGraphReference(graph, value);\n if (existing !== null) return existing;\n const id = definePayloadGraphObject(graph, value);\n return {\n $fig: \"object\",\n id,\n value: encodePayloadRecord(plainPayloadObject(value), encodeChild),\n };\n}\n\nfunction plainPayloadObject(value: object): Record<string, unknown> {\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n throw new Error(\n `Cannot serialize ${prototype?.constructor?.name ?? \"object\"} into the payload.`,\n );\n }\n return value as Record<string, unknown>;\n}\n\nfunction encodePayloadRecord(\n record: Record<string, unknown>,\n encodeChild: (value: unknown) => PayloadModel,\n): Record<string, PayloadModel> {\n const encoded: Record<string, PayloadModel> = {};\n for (const [name, child] of Object.entries(record)) {\n encoded[name] = encodeChild(child);\n }\n return encoded;\n}\n\nfunction encodePayloadNumber(value: number): number | PayloadSpecialModel {\n if (Number.isNaN(value)) return { $fig: \"number\", value: \"NaN\" };\n if (value === Infinity) return { $fig: \"number\", value: \"Infinity\" };\n if (value === -Infinity) return { $fig: \"number\", value: \"-Infinity\" };\n if (Object.is(value, -0)) return { $fig: \"number\", value: \"-0\" };\n return value;\n}\n\n/** Decode values produced by encodePayloadValue. */\nexport function decodePayloadValue(model: PayloadModel): unknown {\n return decodeModelValue(model, createPayloadGraphDecodeContext());\n}\n\nfunction decodeModelValue(\n model: PayloadModel,\n graph: PayloadGraphDecodeContext,\n): unknown {\n if (model === null) return null;\n if (Array.isArray(model))\n return model.map((item) => decodeModelValue(item, graph));\n if (typeof model !== \"object\") return model;\n\n if (isPayloadValueSpecialModel(model)) {\n return decodePayloadValueTag(model, graph.refs, graph.decodeChild);\n }\n\n return decodePayloadRecord(model, graph.decodeChild);\n}\n\nexport function isPayloadValueSpecialModel(\n model: object,\n): model is PayloadValueSpecialModel {\n if (!(\"$fig\" in model)) return false;\n const tag = model.$fig;\n return (\n tag === \"bigint\" ||\n tag === \"array\" ||\n tag === \"date\" ||\n tag === \"map\" ||\n tag === \"number\" ||\n tag === \"object\" ||\n tag === \"ref\" ||\n tag === \"set\" ||\n tag === \"symbol\" ||\n tag === \"undefined\"\n );\n}\n\n// The ref-store seam shared by the two decode entry points: the value codec\n// registers into a per-call refs map, while the stream decoder registers into\n// its request-wide chunk-adjacent store (with rollback on failed fills).\nexport interface PayloadDecodeRefs {\n define<T>(id: number, create: () => T, fill: (value: T) => void): T;\n read(id: number): unknown;\n}\n\nexport function decodePayloadValueTag(\n model: PayloadValueSpecialModel,\n refs: PayloadDecodeRefs,\n decodeChild: (model: PayloadModel) => unknown,\n): unknown {\n switch (model.$fig) {\n case \"array\":\n return refs.define<unknown[]>(\n model.id,\n () => [],\n (value) => {\n for (const item of model.value) value.push(decodeChild(item));\n },\n );\n case \"bigint\":\n return BigInt(model.value);\n case \"date\":\n return new Date(model.value);\n case \"map\":\n return refs.define(\n model.id,\n () => new Map<unknown, unknown>(),\n (value) => {\n for (const [key, item] of model.entries) {\n value.set(decodeChild(key), decodeChild(item));\n }\n },\n );\n case \"number\":\n return decodePayloadNumber(model.value);\n case \"object\": {\n if (model.id === undefined) {\n return decodePayloadRecord(model.value, decodeChild);\n }\n return refs.define(\n model.id,\n () => ({}),\n (value) => {\n for (const [name, child] of Object.entries(model.value)) {\n definePayloadProperty(value, name, decodeChild(child));\n }\n },\n );\n }\n case \"ref\":\n return refs.read(model.id);\n case \"set\":\n return refs.define(\n model.id,\n () => new Set<unknown>(),\n (value) => {\n for (const item of model.values) value.add(decodeChild(item));\n },\n );\n case \"symbol\":\n return Symbol.for(model.key);\n case \"undefined\":\n return undefined;\n }\n}\n\nexport function decodePayloadRecord(\n value: Record<string, PayloadModel>,\n decodeChild: (model: PayloadModel) => unknown,\n): Record<string, unknown> {\n const decoded: Record<string, unknown> = {};\n for (const [name, child] of Object.entries(value)) {\n definePayloadProperty(decoded, name, decodeChild(child));\n }\n return decoded;\n}\n\n// \"__proto__\" must go through defineProperty so a hostile payload key defines\n// an own property instead of mutating the prototype chain via the setter\n// path; every other key gets the identical own data property from plain\n// assignment at a fraction of the cost (this is the decode inner loop).\nexport function definePayloadProperty(\n target: Record<string, unknown>,\n name: string,\n value: unknown,\n): void {\n if (name === \"__proto__\") {\n Object.defineProperty(target, name, {\n configurable: true,\n enumerable: true,\n value,\n writable: true,\n });\n return;\n }\n target[name] = value;\n}\n\nexport function decodePayloadNumber(\n value: \"Infinity\" | \"-Infinity\" | \"-0\" | \"NaN\",\n): number {\n switch (value) {\n case \"Infinity\":\n return Infinity;\n case \"-Infinity\":\n return -Infinity;\n case \"-0\":\n return -0;\n case \"NaN\":\n return NaN;\n }\n}\n\nexport function encodePayloadDataEntries(\n entries: readonly FigDataHydrationEntry[],\n): PayloadDataHydrationEntry[] {\n const graph = createPayloadGraphEncodeContext();\n return entries.map((entry) => ({\n ...entry,\n value: encodePayloadValueWithGraph(entry.value, graph),\n }));\n}\n\nexport function decodePayloadDataEntries(\n entries: readonly PayloadDataHydrationEntry[],\n): FigDataHydrationEntry[] {\n const graph = createPayloadGraphDecodeContext();\n return entries.map((entry) => ({\n ...entry,\n value: decodeModelValue(entry.value, graph),\n }));\n}\n\nexport function isPayloadSpecialModel(\n model: object,\n): model is PayloadElementModel | PayloadSpecialModel {\n if (!(\"$fig\" in model)) return false;\n\n switch (model.$fig) {\n case \"array\":\n case \"bigint\":\n case \"client\":\n case \"date\":\n case \"element\":\n case \"fragment\":\n case \"lazy\":\n case \"map\":\n case \"number\":\n case \"object\":\n case \"promise\":\n case \"ref\":\n case \"set\":\n case \"suspense\":\n case \"symbol\":\n case \"undefined\":\n case \"view-transition\":\n return true;\n default:\n return false;\n }\n}\n"],"mappings":";AAuLA,MAAM,cAAc,IAAI,YAAY;;;;AAKpC,MAAa,mBAAiC;CAC5C,IAAI;CACJ,aAAa;CACb,cAAc,OAAO;EACnB,OAAO,yBAAyB,KAAK;CACvC;CACA,UAAU,KAAK;EACb,OAAO,YAAY,OAAO,GAAG,KAAK,UAAU,GAAG,EAAE,GAAG;CACtD;AACF;AAEA,SAAS,yBACP,OACmB;CACnB,MAAM,UAAU,IAAI,YAAY;CAChC,IAAI,SAAS;CACb,IAAI,cAAc;CAElB,SAAS,uBAA6B;EACpC,IAAI,YAAY;EAChB,IAAI;EAEJ,SAAS;GACP,MAAM,eAAe,OAAO,QAAQ,MAAM,WAAW;GACrD,IAAI,iBAAiB,IAAI;IACvB,cAAc,OAAO;IACrB;GACF;GACA,IAAI;IACF,mBAAmB,OAAO,MAAM,WAAW,YAAY,GAAG,KAAK;GACjE,SAAS,OAAO;IACd,eAAe;GACjB;GACA,YAAY,eAAe;GAC3B,cAAc;EAChB;EAEA,IAAI,eAAe,KAAA,GAAW;GAC5B,SAAS;GACT,cAAc;GACd,MAAM;EACR;EACA,IAAI,YAAY,GAAG;GACjB,SAAS,OAAO,MAAM,SAAS;GAC/B,eAAe;EACjB;CACF;CAEA,OAAO;EACL,OAAO,OAAO;GACZ,UAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;GAChD,qBAAqB;EACvB;EACA,QAAQ;GACN,UAAU,QAAQ,OAAO;GACzB,IAAI,OAAO,SAAS,GAAG;IACrB,MAAM,OAAO;IACb,SAAS;IACT,cAAc;IACd,mBAAmB,M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W;EAC7B,GAAG;EACH,OAAO,iBAAiB,MAAM,OAAO,KAAK;CAC5C,EAAE;AACJ;AAEA,SAAgB,sBACd,OACoD;CACpD,IAAI,EAAE,UAAU,QAAQ,OAAO;CAE/B,QAAQ,MAAM,MAAd;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,mBACH,OAAO;EACT,SACE,OAAO;CACX;AACF"}
|
|
1
|
+
{"version":3,"file":"payload-format-KTNaSI4h.js","names":[],"sources":["../src/payload-format.ts"],"sourcesContent":["import type { FigDataHydrationEntry } from \"./data.ts\";\nimport type { Key } from \"./element.ts\";\nimport type {\n FontResource,\n MetaResource,\n ModulePreloadResource,\n PreconnectResource,\n PreloadResource,\n ScriptResource,\n StylesheetResource,\n TitleResource,\n} from \"./resource.ts\";\n\n// Asset resources represented as descriptor data. Optional fields stay optional\n// on the wire; omitted `undefined` values are part of the payload contract, not\n// a serializer implementation detail. Delivery assets prepare eagerly at row\n// arrival; document metadata stays attached to its owning decoded row until\n// that row commits.\nexport type SerializedAssetResource =\n | {\n crossorigin?: StylesheetResource[\"crossorigin\"];\n href: string;\n kind: \"stylesheet\";\n media?: string;\n precedence?: string;\n }\n | {\n as: string;\n crossorigin?: PreloadResource[\"crossorigin\"];\n fetchpriority?: PreloadResource[\"fetchpriority\"];\n href?: string;\n imagesizes?: PreloadResource[\"imagesizes\"];\n imagesrcset?: PreloadResource[\"imagesrcset\"];\n kind: \"preload\";\n referrerpolicy?: PreloadResource[\"referrerpolicy\"];\n type?: string;\n }\n | {\n crossorigin?: ModulePreloadResource[\"crossorigin\"];\n fetchpriority?: ModulePreloadResource[\"fetchpriority\"];\n href: string;\n kind: \"modulepreload\";\n }\n | {\n async?: boolean;\n crossorigin?: ScriptResource[\"crossorigin\"];\n defer?: boolean;\n kind: \"script\";\n module?: boolean;\n src: string;\n }\n | {\n crossorigin?: FontResource[\"crossorigin\"];\n fetchpriority?: FontResource[\"fetchpriority\"];\n href: string;\n kind: \"font\";\n type: string;\n }\n | {\n crossorigin?: PreconnectResource[\"crossorigin\"];\n href: string;\n kind: \"preconnect\";\n }\n | {\n kind: \"title\";\n value: TitleResource[\"value\"];\n }\n | {\n charset?: MetaResource[\"charset\"];\n content?: MetaResource[\"content\"];\n \"http-equiv\"?: MetaResource[\"http-equiv\"];\n key?: string;\n kind: \"meta\";\n name?: MetaResource[\"name\"];\n property?: MetaResource[\"property\"];\n };\n\n/** The `error` row value under the server's `onError` contract. */\nexport interface PayloadErrorValue {\n digest?: string;\n message?: string;\n}\n\n/**\n * Semantic payload row before the internal codec turns it into bytes.\n */\nexport type PayloadRow =\n | { for?: number; tag: \"assets\"; value: SerializedAssetResource[] }\n | {\n id: number;\n tag: \"client\";\n value: {\n id: string;\n assets?: SerializedAssetResource[];\n exportName?: string;\n ssr?: true;\n };\n }\n | { tag: \"data\"; value: PayloadDataHydrationEntry[] }\n | { id: number; tag: \"error\"; value: PayloadErrorValue }\n | { id: number; tag: \"model\"; value: PayloadModel };\n\n/**\n * Transport-safe model value used inside internal payload rows. This is an\n * implementation format, not an application data format.\n */\nexport type PayloadModel =\n | null\n | boolean\n | number\n | string\n | PayloadModel[]\n | { [key: string]: PayloadModel }\n | PayloadElementModel\n | PayloadSpecialModel;\n\nexport type PayloadElementModel = {\n $fig: \"element\";\n id?: number;\n key: Key | null;\n props: PayloadModel;\n type: string | PayloadSpecialModel;\n};\n\nexport type PayloadSpecialModel =\n | { $fig: \"array\"; id: number; value: PayloadModel[] }\n | { $fig: \"bigint\"; value: string }\n | { $fig: \"client\"; id: number }\n | { $fig: \"date\"; value: string }\n | { $fig: \"fragment\" }\n | { $fig: \"lazy\"; id: number }\n | { $fig: \"map\"; entries: Array<[PayloadModel, PayloadModel]>; id: number }\n | { $fig: \"number\"; value: \"Infinity\" | \"-Infinity\" | \"-0\" | \"NaN\" }\n | { $fig: \"object\"; id?: number; value: Record<string, PayloadModel> }\n | { $fig: \"promise\"; id: number }\n | { $fig: \"ref\"; id: number }\n | { $fig: \"set\"; id: number; values: PayloadModel[] }\n | { $fig: \"symbol\"; key: string }\n | { $fig: \"suspense\" }\n | { $fig: \"undefined\" }\n | { $fig: \"view-transition\" };\n\nexport type PayloadValueSpecialModel = Extract<\n PayloadSpecialModel,\n {\n $fig:\n | \"array\"\n | \"bigint\"\n | \"date\"\n | \"map\"\n | \"number\"\n | \"object\"\n | \"ref\"\n | \"set\"\n | \"symbol\"\n | \"undefined\";\n }\n>;\n\nexport type PayloadDataHydrationEntry = Omit<FigDataHydrationEntry, \"value\"> & {\n value: PayloadModel;\n};\n\nexport interface PayloadCodec {\n /**\n * Opaque implementation id, e.g. \"json\" or \"binary\". Fig checks this id at\n * transport boundaries; the encoded byte layout is not a public contract.\n */\n readonly id: string;\n readonly contentType: string;\n /**\n * Creates a streaming row decoder. The decoder calls `onRow` for each\n * complete semantic row. If `onRow` throws, the decoder must propagate that\n * error; when it can already see more complete sibling rows in the same\n * input chunk, it should process those siblings before rethrowing so\n * notifications already implied by earlier rows are not lost.\n */\n createDecoder(onRow: (row: PayloadRow) => void): PayloadRowDecoder;\n encodeRow(row: PayloadRow): Uint8Array;\n}\n\nexport interface PayloadRowDecoder {\n decode(chunk: Uint8Array): void;\n flush(): void;\n}\n\nconst textEncoder = new TextEncoder();\n\n/**\n * Readable development-oriented codec: one JSON payload row per newline.\n */\nexport const jsonPayloadCodec: PayloadCodec = {\n id: \"json\",\n contentType: \"text/x-fig-payload; codec=json; charset=utf-8\",\n createDecoder(onRow) {\n return createJsonPayloadDecoder(onRow);\n },\n encodeRow(row) {\n return textEncoder.encode(`${JSON.stringify(row)}\\n`);\n },\n};\n\nfunction createJsonPayloadDecoder(\n onRow: (row: PayloadRow) => void,\n): PayloadRowDecoder {\n const decoder = new TextDecoder();\n let buffer = \"\";\n let searchStart = 0;\n\n function processBufferedLines(): void {\n let lineStart = 0;\n let firstError: unknown;\n\n for (;;) {\n const newlineIndex = buffer.indexOf(\"\\n\", searchStart);\n if (newlineIndex === -1) {\n searchStart = buffer.length;\n break;\n }\n try {\n processPayloadLine(buffer.slice(lineStart, newlineIndex), onRow);\n } catch (error) {\n firstError ??= error;\n }\n lineStart = newlineIndex + 1;\n searchStart = lineStart;\n }\n\n if (firstError !== undefined) {\n buffer = \"\";\n searchStart = 0;\n throw firstError;\n }\n if (lineStart > 0) {\n buffer = buffer.slice(lineStart);\n searchStart -= lineStart;\n }\n }\n\n return {\n decode(chunk) {\n buffer += decoder.decode(chunk, { stream: true });\n processBufferedLines();\n },\n flush() {\n buffer += decoder.decode();\n if (buffer.length > 0) {\n const line = buffer;\n buffer = \"\";\n searchStart = 0;\n processPayloadLine(line, onRow);\n }\n },\n };\n}\n\nfunction processPayloadLine(\n line: string,\n onRow: (row: PayloadRow) => void,\n): void {\n if (line.length > 0) onRow(JSON.parse(line) as PayloadRow);\n}\n\n/**\n * Extract the codec id from a payload content-type header, or null when the\n * header carries no codec parameter.\n */\nexport function payloadCodecIdFromContentType(\n contentTypeHeader: string,\n): string | null {\n const parts = contentTypeHeader.split(\";\").slice(1);\n for (const part of parts) {\n const [name, rawValue] = part.split(\"=\");\n if (name?.trim().toLowerCase() !== \"codec\") continue;\n const value = rawValue?.trim();\n if (value === undefined || value.length === 0) return null;\n return value.replace(/^\"|\"$/g, \"\");\n }\n return null;\n}\n\n/**\n * Throw when a response content-type declares a codec other than the one this\n * client decodes with. A missing header or codec parameter passes: transports\n * that strip content types stay usable, and mismatches still fail fast when\n * declared.\n */\nexport function assertPayloadCodecMatches(\n codec: PayloadCodec,\n contentTypeHeader: string | null,\n): void {\n if (contentTypeHeader === null) return;\n const received = payloadCodecIdFromContentType(contentTypeHeader);\n if (received === null || received === codec.id) return;\n throw new Error(\n `Payload codec mismatch: producer used \"${received}\" but this client expects \"${codec.id}\".`,\n );\n}\n\n/** Decode an `error` row value into a digest-carrying Error. */\nexport function errorFromPayloadValue(value: PayloadErrorValue): Error & {\n digest?: string;\n} {\n const error = new Error(value.message ?? \"The server render failed.\");\n return value.digest === undefined\n ? error\n : Object.assign(error, { digest: value.digest });\n}\n\nexport interface PayloadGraphEncodeContext {\n // Ids are dense and monotonic: id = position in `defined` + 1, so rollback\n // is popping the stack. A reverse id→object map would be redundant state.\n defined: object[];\n ids: WeakMap<object, number>;\n}\n\ninterface PayloadGraphDecodeContext {\n decodeChild: (model: PayloadModel) => unknown;\n refs: PayloadDecodeRefs;\n}\n\nfunction createPayloadGraphDecodeContext(): PayloadGraphDecodeContext {\n const refs = new Map<number, unknown>();\n const context: PayloadGraphDecodeContext = {\n decodeChild: (model) => decodeModelValue(model, context),\n refs: {\n define(id, create, fill) {\n const value = create();\n refs.set(id, value);\n fill(value);\n return value;\n },\n read(id) {\n if (!refs.has(id)) {\n throw new Error(`Payload referenced unknown object id ${id}.`);\n }\n return refs.get(id);\n },\n },\n };\n return context;\n}\n\nexport function createPayloadGraphEncodeContext(): PayloadGraphEncodeContext {\n return { defined: [], ids: new WeakMap() };\n}\n\nexport function isPlainPayloadValue(value: unknown): boolean {\n return (\n value === null ||\n value === undefined ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n typeof value === \"bigint\" ||\n typeof value === \"symbol\"\n );\n}\n\n/**\n * Encode ordinary data values into PayloadModel. Server component references\n * such as Fig elements, promises, and client references are handled by the\n * payload renderer before ordinary values reach this helper.\n */\nexport function encodePayloadValue(value: unknown): PayloadModel {\n return encodePayloadValueWithGraph(value, createPayloadGraphEncodeContext());\n}\n\nexport function encodePayloadValueWithGraph(\n value: unknown,\n graph: PayloadGraphEncodeContext,\n): PayloadModel {\n if (value === null) return null;\n if (value === undefined) return { $fig: \"undefined\" };\n\n if (typeof value === \"string\" || typeof value === \"boolean\") return value;\n if (typeof value === \"number\") return encodePayloadNumber(value);\n if (typeof value === \"bigint\") {\n return { $fig: \"bigint\", value: value.toString() };\n }\n if (typeof value === \"symbol\") {\n const key = Symbol.keyFor(value);\n if (key === undefined) {\n throw new Error(\"Only global Symbol.for symbols can be serialized.\");\n }\n return { $fig: \"symbol\", key };\n }\n if (typeof value === \"function\") {\n throw new Error(\"Functions cannot be serialized into the payload.\");\n }\n\n if (Array.isArray(value)) {\n return serializePayloadArray(\n value,\n graph,\n () => value,\n (item) => encodePayloadValueWithGraph(item, graph),\n );\n }\n if (value instanceof Date) {\n const json = value.toJSON();\n if (json === null) {\n throw new Error(\"Invalid Date values cannot be serialized.\");\n }\n return { $fig: \"date\", value: json };\n }\n if (value instanceof Map) {\n return serializePayloadMap(value, graph, ([key, item]) => [\n encodePayloadValueWithGraph(key, graph),\n encodePayloadValueWithGraph(item, graph),\n ]);\n }\n if (value instanceof Set) {\n return serializePayloadSet(value, graph, (item) =>\n encodePayloadValueWithGraph(item, graph),\n );\n }\n\n if (typeof value === \"object\" && value !== null) {\n return serializePayloadPlainObject(value, graph, (child) =>\n encodePayloadValueWithGraph(child, graph),\n );\n }\n\n throw new Error(`Cannot serialize ${typeof value} into the payload.`);\n}\n\nexport function serializePayloadMap(\n value: Map<unknown, unknown>,\n graph: PayloadGraphEncodeContext,\n encodeEntry: (entry: [unknown, unknown]) => [PayloadModel, PayloadModel],\n): PayloadModel {\n const existing = payloadGraphReference(graph, value);\n if (existing !== null) return existing;\n const id = definePayloadGraphObject(graph, value);\n const entries: Array<[PayloadModel, PayloadModel]> = [];\n for (const entry of value) entries.push(encodeEntry(entry));\n return { $fig: \"map\", id, entries };\n}\n\nexport function serializePayloadSet(\n value: Set<unknown>,\n graph: PayloadGraphEncodeContext,\n encodeItem: (value: unknown) => PayloadModel,\n): PayloadModel {\n const existing = payloadGraphReference(graph, value);\n if (existing !== null) return existing;\n const id = definePayloadGraphObject(graph, value);\n const values: PayloadModel[] = [];\n for (const item of value) values.push(encodeItem(item));\n return { $fig: \"set\", id, values };\n}\n\nfunction payloadGraphReference(\n graph: PayloadGraphEncodeContext,\n value: object,\n): PayloadSpecialModel | null {\n const id = graph.ids.get(value);\n return id === undefined ? null : { $fig: \"ref\", id };\n}\n\nfunction definePayloadGraphObject(\n graph: PayloadGraphEncodeContext,\n value: object,\n): number {\n graph.defined.push(value);\n const id = graph.defined.length;\n graph.ids.set(value, id);\n return id;\n}\n\nexport function checkpointPayloadGraph(\n graph: PayloadGraphEncodeContext,\n): number {\n return graph.defined.length;\n}\n\nexport function rollbackPayloadGraph(\n graph: PayloadGraphEncodeContext,\n checkpoint: number,\n): void {\n while (graph.defined.length > checkpoint) {\n graph.ids.delete(graph.defined.pop() as object);\n }\n}\n\nexport function definePayloadGraphElement(\n graph: PayloadGraphEncodeContext,\n value: object,\n): number | PayloadSpecialModel {\n const existing = payloadGraphReference(graph, value);\n if (existing !== null) return existing;\n return definePayloadGraphObject(graph, value);\n}\n\nexport function serializePayloadArray<T>(\n value: object,\n graph: PayloadGraphEncodeContext,\n entries: () => readonly T[],\n encodeChild: (value: T) => PayloadModel,\n): PayloadModel {\n const existing = payloadGraphReference(graph, value);\n if (existing !== null) return existing;\n const id = definePayloadGraphObject(graph, value);\n return { $fig: \"array\", id, value: entries().map(encodeChild) };\n}\n\nexport function serializePayloadPlainObject(\n value: object,\n graph: PayloadGraphEncodeContext,\n encodeChild: (value: unknown) => PayloadModel,\n): PayloadModel {\n const existing = payloadGraphReference(graph, value);\n if (existing !== null) return existing;\n const id = definePayloadGraphObject(graph, value);\n return {\n $fig: \"object\",\n id,\n value: encodePayloadRecord(plainPayloadObject(value), encodeChild),\n };\n}\n\nfunction plainPayloadObject(value: object): Record<string, unknown> {\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n throw new Error(\n `Cannot serialize ${prototype?.constructor?.name ?? \"object\"} into the payload.`,\n );\n }\n return value as Record<string, unknown>;\n}\n\nfunction encodePayloadRecord(\n record: Record<string, unknown>,\n encodeChild: (value: unknown) => PayloadModel,\n): Record<string, PayloadModel> {\n const encoded: Record<string, PayloadModel> = {};\n for (const [name, child] of Object.entries(record)) {\n encoded[name] = encodeChild(child);\n }\n return encoded;\n}\n\nfunction encodePayloadNumber(value: number): number | PayloadSpecialModel {\n if (Number.isNaN(value)) return { $fig: \"number\", value: \"NaN\" };\n if (value === Infinity) return { $fig: \"number\", value: \"Infinity\" };\n if (value === -Infinity) return { $fig: \"number\", value: \"-Infinity\" };\n if (Object.is(value, -0)) return { $fig: \"number\", value: \"-0\" };\n return value;\n}\n\n/** Decode values produced by encodePayloadValue. */\nexport function decodePayloadValue(model: PayloadModel): unknown {\n return decodeModelValue(model, createPayloadGraphDecodeContext());\n}\n\nfunction decodeModelValue(\n model: PayloadModel,\n graph: PayloadGraphDecodeContext,\n): unknown {\n if (model === null) return null;\n if (Array.isArray(model))\n return model.map((item) => decodeModelValue(item, graph));\n if (typeof model !== \"object\") return model;\n\n if (isPayloadValueSpecialModel(model)) {\n return decodePayloadValueTag(model, graph.refs, graph.decodeChild);\n }\n\n return decodePayloadRecord(model, graph.decodeChild);\n}\n\nexport function isPayloadValueSpecialModel(\n model: object,\n): model is PayloadValueSpecialModel {\n if (!(\"$fig\" in model)) return false;\n const tag = model.$fig;\n return (\n tag === \"bigint\" ||\n tag === \"array\" ||\n tag === \"date\" ||\n tag === \"map\" ||\n tag === \"number\" ||\n tag === \"object\" ||\n tag === \"ref\" ||\n tag === \"set\" ||\n tag === \"symbol\" ||\n tag === \"undefined\"\n );\n}\n\n// The ref-store seam shared by the two decode entry points: the value codec\n// registers into a per-call refs map, while the stream decoder registers into\n// its request-wide chunk-adjacent store (with rollback on failed fills).\nexport interface PayloadDecodeRefs {\n define<T>(id: number, create: () => T, fill: (value: T) => void): T;\n read(id: number): unknown;\n}\n\nexport function decodePayloadValueTag(\n model: PayloadValueSpecialModel,\n refs: PayloadDecodeRefs,\n decodeChild: (model: PayloadModel) => unknown,\n): unknown {\n switch (model.$fig) {\n case \"array\":\n return refs.define<unknown[]>(\n model.id,\n () => [],\n (value) => {\n for (const item of model.value) value.push(decodeChild(item));\n },\n );\n case \"bigint\":\n return BigInt(model.value);\n case \"date\":\n return new Date(model.value);\n case \"map\":\n return refs.define(\n model.id,\n () => new Map<unknown, unknown>(),\n (value) => {\n for (const [key, item] of model.entries) {\n value.set(decodeChild(key), decodeChild(item));\n }\n },\n );\n case \"number\":\n return decodePayloadNumber(model.value);\n case \"object\": {\n if (model.id === undefined) {\n return decodePayloadRecord(model.value, decodeChild);\n }\n return refs.define(\n model.id,\n () => ({}),\n (value) => {\n for (const [name, child] of Object.entries(model.value)) {\n definePayloadProperty(value, name, decodeChild(child));\n }\n },\n );\n }\n case \"ref\":\n return refs.read(model.id);\n case \"set\":\n return refs.define(\n model.id,\n () => new Set<unknown>(),\n (value) => {\n for (const item of model.values) value.add(decodeChild(item));\n },\n );\n case \"symbol\":\n return Symbol.for(model.key);\n case \"undefined\":\n return undefined;\n }\n}\n\nexport function decodePayloadRecord(\n value: Record<string, PayloadModel>,\n decodeChild: (model: PayloadModel) => unknown,\n): Record<string, unknown> {\n const decoded: Record<string, unknown> = {};\n for (const [name, child] of Object.entries(value)) {\n definePayloadProperty(decoded, name, decodeChild(child));\n }\n return decoded;\n}\n\n// \"__proto__\" must go through defineProperty so a hostile payload key defines\n// an own property instead of mutating the prototype chain via the setter\n// path; every other key gets the identical own data property from plain\n// assignment at a fraction of the cost (this is the decode inner loop).\nexport function definePayloadProperty(\n target: Record<string, unknown>,\n name: string,\n value: unknown,\n): void {\n if (name === \"__proto__\") {\n Object.defineProperty(target, name, {\n configurable: true,\n enumerable: true,\n value,\n writable: true,\n });\n return;\n }\n target[name] = value;\n}\n\nexport function decodePayloadNumber(\n value: \"Infinity\" | \"-Infinity\" | \"-0\" | \"NaN\",\n): number {\n switch (value) {\n case \"Infinity\":\n return Infinity;\n case \"-Infinity\":\n return -Infinity;\n case \"-0\":\n return -0;\n case \"NaN\":\n return NaN;\n }\n}\n\nexport function encodePayloadDataEntries(\n entries: readonly FigDataHydrationEntry[],\n): PayloadDataHydrationEntry[] {\n const graph = createPayloadGraphEncodeContext();\n return entries.map((entry) => ({\n ...entry,\n value: encodePayloadValueWithGraph(entry.value, graph),\n }));\n}\n\nexport function decodePayloadDataEntries(\n entries: readonly PayloadDataHydrationEntry[],\n): FigDataHydrationEntry[] {\n const graph = createPayloadGraphDecodeContext();\n return entries.map((entry) => ({\n ...entry,\n value: decodeModelValue(entry.value, graph),\n }));\n}\n\nexport function isPayloadSpecialModel(\n model: object,\n): model is PayloadElementModel | PayloadSpecialModel {\n if (!(\"$fig\" in model)) return false;\n\n switch (model.$fig) {\n case \"array\":\n case \"bigint\":\n case \"client\":\n case \"date\":\n case \"element\":\n case \"fragment\":\n case \"lazy\":\n case \"map\":\n case \"number\":\n case \"object\":\n case \"promise\":\n case \"ref\":\n case \"set\":\n case \"suspense\":\n case \"symbol\":\n case \"undefined\":\n case \"view-transition\":\n return true;\n default:\n return false;\n }\n}\n"],"mappings":";AA0LA,MAAM,cAAc,IAAI,YAAY;;;;AAKpC,MAAa,mBAAiC;CAC5C,IAAI;CACJ,aAAa;CACb,cAAc,OAAO;EACnB,OAAO,yBAAyB,KAAK;CACvC;CACA,UAAU,KAAK;EACb,OAAO,YAAY,OAAO,GAAG,KAAK,UAAU,GAAG,EAAE,GAAG;CACtD;AACF;AAEA,SAAS,yBACP,OACmB;CACnB,MAAM,UAAU,IAAI,YAAY;CAChC,IAAI,SAAS;CACb,IAAI,cAAc;CAElB,SAAS,uBAA6B;EACpC,IAAI,YAAY;EAChB,IAAI;EAEJ,SAAS;GACP,MAAM,eAAe,OAAO,QAAQ,MAAM,WAAW;GACrD,IAAI,iBAAiB,IAAI;IACvB,cAAc,OAAO;IACrB;GACF;GACA,IAAI;IACF,mBAAmB,OAAO,MAAM,WAAW,YAAY,GAAG,KAAK;GACjE,SAAS,OAAO;IACd,eAAe;GACjB;GACA,YAAY,eAAe;GAC3B,cAAc;EAChB;EAEA,IAAI,eAAe,KAA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R,QAAQ,OAAR;EACE,KAAK,YACH,OAAO;EACT,KAAK,aACH,OAAO;EACT,KAAK,MACH,OAAO;EACT,KAAK,OACH,OAAO;CACX;AACF;AAEA,SAAgB,yBACd,SAC6B;CAC7B,MAAM,QAAQ,gCAAgC;CAC9C,OAAO,QAAQ,KAAK,WAAW;EAC7B,GAAG;EACH,OAAO,4BAA4B,MAAM,OAAO,KAAK;CACvD,EAAE;AACJ;AAEA,SAAgB,yBACd,SACyB;CACzB,MAAM,QAAQ,gCAAgC;CAC9C,OAAO,QAAQ,KAAK,WAAW;EAC7B,GAAG;EACH,OAAO,iBAAiB,MAAM,OAAO,KAAK;CAC5C,EAAE;AACJ;AAEA,SAAgB,sBACd,OACoD;CACpD,IAAI,EAAE,UAAU,QAAQ,OAAO;CAE/B,QAAQ,MAAM,MAAd;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,mBACH,OAAO;EACT,SACE,OAAO;CACX;AACF"}
|
package/dist/payload.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Wt as FigDataHydrationEntry, a as AwaitedFigNode, ct as FigAssetResource, l as ElementType } from "./element-
|
|
1
|
+
import { Wt as FigDataHydrationEntry, a as AwaitedFigNode, ct as FigAssetResource, l as ElementType } from "./element-BVg1bKOz.js";
|
|
2
2
|
//#region src/payload.d.ts
|
|
3
3
|
interface PayloadClientReference {
|
|
4
4
|
assets?: readonly FigAssetResource[];
|
package/dist/payload.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { I as readPromise, f as Fragment, g as createElement, m as ViewTransition, p as Suspense, s as FigElementSymbol } from "./element-DmbzNH0T.js";
|
|
2
|
-
import { b as trackThenable, l as isFigAssetResource, o as assets, t as assetResourceDestination, v as isThenable } from "./resource-
|
|
2
|
+
import { b as trackThenable, l as isFigAssetResource, o as assets, t as assetResourceDestination, v as isThenable } from "./resource-DskjKeuM.js";
|
|
3
3
|
import { a as decodePayloadRecord, f as errorFromPayloadValue, h as jsonPayloadCodec, i as decodePayloadDataEntries, p as isPayloadSpecialModel, s as decodePayloadValueTag } from "./payload-format-KTNaSI4h.js";
|
|
4
4
|
//#region src/payload.ts
|
|
5
5
|
const resolverEntries = /* @__PURE__ */ new WeakMap();
|
|
@@ -54,6 +54,7 @@ function preload(href, as, options = {}) {
|
|
|
54
54
|
...options,
|
|
55
55
|
as,
|
|
56
56
|
href,
|
|
57
|
+
imagesrcset: as === "image" ? options.imagesrcset || void 0 : void 0,
|
|
57
58
|
kind: "preload"
|
|
58
59
|
};
|
|
59
60
|
}
|
|
@@ -125,7 +126,10 @@ function assetResourceKey(resource) {
|
|
|
125
126
|
if (resource.key !== void 0) return `${resource.kind}:${resource.key}`;
|
|
126
127
|
switch (resource.kind) {
|
|
127
128
|
case "stylesheet": return `stylesheet:${resource.href}`;
|
|
128
|
-
case "preload":
|
|
129
|
+
case "preload": {
|
|
130
|
+
const imagesrcset = resource.imagesrcset || void 0;
|
|
131
|
+
return `preload:${resource.as}:${imagesrcset === void 0 ? resource.href ?? "" : `${imagesrcset}\n${resource.imagesizes ?? ""}`}`;
|
|
132
|
+
}
|
|
129
133
|
case "modulepreload": return `modulepreload:${resource.href}`;
|
|
130
134
|
case "script": return `script:${resource.src}`;
|
|
131
135
|
case "font": return `preload:font:${resource.href}`;
|
|
@@ -156,9 +160,11 @@ function assetResourceHostAttributes(resource) {
|
|
|
156
160
|
case "stylesheet":
|
|
157
161
|
pairs.push(["rel", "stylesheet"], ["href", resource.href], ["data-fig-resource-key", resource.key], ["data-precedence", resource.precedence], ["media", resource.media], ["crossorigin", resource.crossorigin]);
|
|
158
162
|
break;
|
|
159
|
-
case "preload":
|
|
160
|
-
|
|
163
|
+
case "preload": {
|
|
164
|
+
const imagesrcset = resource.imagesrcset || void 0;
|
|
165
|
+
pairs.push(["rel", "preload"], ["href", imagesrcset === void 0 ? resource.href : void 0], ["as", resource.as], ["data-fig-resource-key", resource.key], ["type", resource.type], ["crossorigin", resource.crossorigin], ["fetchpriority", resource.fetchpriority], ["imagesrcset", imagesrcset], ["imagesizes", resource.imagesizes], ["referrerpolicy", resource.referrerpolicy]);
|
|
161
166
|
break;
|
|
167
|
+
}
|
|
162
168
|
case "modulepreload":
|
|
163
169
|
pairs.push(["rel", "modulepreload"], ["href", resource.href], ["data-fig-resource-key", resource.key], ["crossorigin", resource.crossorigin], ["fetchpriority", resource.fetchpriority]);
|
|
164
170
|
break;
|
|
@@ -252,7 +258,24 @@ function hasBooleanAttribute(value) {
|
|
|
252
258
|
function linkResourceFromHost(prop) {
|
|
253
259
|
const rel = readProp(prop, "rel")?.toLowerCase();
|
|
254
260
|
const href = readProp(prop, "href");
|
|
255
|
-
if (rel === void 0 ||
|
|
261
|
+
if (rel === void 0 || readProp(prop, "itemprop") !== void 0) return null;
|
|
262
|
+
if (rel === "preload") {
|
|
263
|
+
const as = readProp(prop, "as");
|
|
264
|
+
const imagesrcset = as === "image" ? readProp(prop, "imagesrcset") || void 0 : void 0;
|
|
265
|
+
if (as === void 0 || href === void 0 && imagesrcset === void 0) return null;
|
|
266
|
+
return {
|
|
267
|
+
as,
|
|
268
|
+
crossorigin: readCrossorigin(prop),
|
|
269
|
+
fetchpriority: fetchpriorityProp(readProp(prop, "fetchpriority")),
|
|
270
|
+
href,
|
|
271
|
+
imagesizes: imagesrcset === void 0 ? void 0 : readProp(prop, "imagesizes"),
|
|
272
|
+
imagesrcset,
|
|
273
|
+
kind: "preload",
|
|
274
|
+
referrerpolicy: readProp(prop, "referrerpolicy"),
|
|
275
|
+
type: readProp(prop, "type")
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
if (href === void 0) return null;
|
|
256
279
|
if (rel === "stylesheet") return {
|
|
257
280
|
blocking: prop("blocking") === "none" ? "none" : void 0,
|
|
258
281
|
crossorigin: readCrossorigin(prop),
|
|
@@ -267,18 +290,6 @@ function linkResourceFromHost(prop) {
|
|
|
267
290
|
href,
|
|
268
291
|
kind: "modulepreload"
|
|
269
292
|
};
|
|
270
|
-
if (rel === "preload") {
|
|
271
|
-
const as = readProp(prop, "as");
|
|
272
|
-
if (as === void 0) return null;
|
|
273
|
-
return {
|
|
274
|
-
as,
|
|
275
|
-
crossorigin: readCrossorigin(prop),
|
|
276
|
-
fetchpriority: fetchpriorityProp(readProp(prop, "fetchpriority")),
|
|
277
|
-
href,
|
|
278
|
-
kind: "preload",
|
|
279
|
-
type: readProp(prop, "type")
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
293
|
if (rel === "preconnect") return {
|
|
283
294
|
crossorigin: readCrossorigin(prop),
|
|
284
295
|
href,
|
|
@@ -322,4 +333,4 @@ function metaResourceKey(resource) {
|
|
|
322
333
|
//#endregion
|
|
323
334
|
export { title as _, assetResourceKey as a, trackThenable as b, font as c, modulepreload as d, preconnect as f, stylesheet as g, script as h, assetResourceHostAttributes as i, isFigAssetResource as l, preventAssetResourceHoist as m, assetResourceFromHostAttributes as n, assets as o, preload as p, assetResourceFromHostProps as r, clientReferenceAssets as s, assetResourceDestination as t, meta as u, isThenable as v, readThenable as y };
|
|
324
335
|
|
|
325
|
-
//# sourceMappingURL=resource-
|
|
336
|
+
//# sourceMappingURL=resource-DskjKeuM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-DskjKeuM.js","names":[],"sources":["../src/thenables.ts","../src/resource.ts"],"sourcesContent":["export type Thenable<T = unknown> = PromiseLike<T> & object;\n\ntype ThenableRecord<T> =\n | { status: \"pending\" }\n | { status: \"fulfilled\"; value: T }\n | { status: \"rejected\"; reason: unknown };\n\n// One process-wide registry keyed by thenable identity: the reconciler's\n// readPromise, the server renderers' dispatchers, and preloaders all share\n// it, so suspend/settle semantics cannot drift between client and server.\nconst thenableRecords = new WeakMap<object, ThenableRecord<unknown>>();\n\nfunction recordFor<T>(thenable: PromiseLike<T>): ThenableRecord<T> {\n const key = thenable as Thenable<T>;\n let record = thenableRecords.get(key) as ThenableRecord<T> | undefined;\n\n if (record === undefined) {\n record = { status: \"pending\" };\n thenableRecords.set(key, record);\n thenable.then(\n (value) => {\n record = { status: \"fulfilled\", value };\n thenableRecords.set(key, record);\n },\n (reason: unknown) => {\n record = { reason, status: \"rejected\" };\n thenableRecords.set(key, record);\n },\n );\n }\n\n return record;\n}\n\n// Starts tracking without reading. Preloaders call this when they begin a\n// load so that a thenable settled before its first render read resolves\n// synchronously instead of suspending for one retry beat.\nexport function trackThenable<T>(thenable: PromiseLike<T>): void {\n recordFor(thenable);\n}\n\nexport function readThenable<T>(thenable: PromiseLike<T>): T {\n const record = recordFor(thenable);\n if (record.status === \"fulfilled\") return record.value;\n if (record.status === \"rejected\") throw record.reason;\n throw thenable;\n}\n\nexport function isThenable(value: unknown): value is Thenable {\n if (\n (typeof value !== \"object\" && typeof value !== \"function\") ||\n value === null\n ) {\n return false;\n }\n\n return \"then\" in value && typeof value.then === \"function\";\n}\n","import {\n Assets,\n createElement,\n type FigClientReference,\n type FigElement,\n type FigNode,\n type Props,\n} from \"./element.ts\";\nimport { isThenable, readThenable } from \"./thenables.ts\";\n\nconst PreventAssetResourceHoistSymbol = Symbol.for(\n \"fig.prevent-asset-resource-hoist\",\n);\ntype AssetResourceHostProps = Props & {\n [PreventAssetResourceHoistSymbol]?: true;\n};\n\nexport type AssetResourceBlocking = \"reveal\" | \"none\";\nexport type CrossOrigin = \"anonymous\" | \"use-credentials\" | \"\";\nexport type FetchPriority = \"high\" | \"low\" | \"auto\";\nexport type AssetResourceDestination = \"head\" | \"stream\";\n\nexport type FigAssetResource =\n | StylesheetResource\n | PreloadResource\n | ModulePreloadResource\n | ScriptResource\n | FontResource\n | PreconnectResource\n | TitleResource\n | MetaResource;\n\ninterface ResourceBase {\n key?: string;\n}\n\nexport interface StylesheetResource extends ResourceBase {\n blocking?: AssetResourceBlocking;\n crossorigin?: CrossOrigin;\n href: string;\n kind: \"stylesheet\";\n media?: string;\n precedence?: string;\n}\n\nexport interface PreloadResource extends ResourceBase {\n as: string;\n crossorigin?: CrossOrigin;\n fetchpriority?: FetchPriority;\n href?: string;\n imagesizes?: string;\n imagesrcset?: string;\n kind: \"preload\";\n referrerpolicy?: string;\n type?: string;\n}\n\nexport interface ModulePreloadResource extends ResourceBase {\n crossorigin?: CrossOrigin;\n fetchpriority?: FetchPriority;\n href: string;\n kind: \"modulepreload\";\n}\n\nexport interface ScriptResource extends ResourceBase {\n async?: boolean;\n crossorigin?: CrossOrigin;\n defer?: boolean;\n kind: \"script\";\n module?: boolean;\n src: string;\n}\n\nexport interface FontResource extends ResourceBase {\n crossorigin?: CrossOrigin;\n fetchpriority?: FetchPriority;\n href: string;\n kind: \"font\";\n type: string;\n}\n\nexport interface PreconnectResource extends ResourceBase {\n crossorigin?: CrossOrigin;\n href: string;\n kind: \"preconnect\";\n}\n\nexport interface TitleResource extends ResourceBase {\n kind: \"title\";\n value: string;\n}\n\ninterface MetaResourceBase extends ResourceBase {\n kind: \"meta\";\n}\n\ntype DistributiveOmit<Value, Key extends PropertyKey> = Value extends unknown\n ? Omit<Value, Key>\n : never;\n\nexport type MetaResource =\n | (MetaResourceBase & {\n charset: string;\n content?: never;\n \"http-equiv\"?: never;\n name?: never;\n property?: never;\n })\n | (MetaResourceBase & {\n charset?: never;\n content: string;\n \"http-equiv\"?: never;\n name: string;\n property?: never;\n })\n | (MetaResourceBase & {\n charset?: never;\n content: string;\n \"http-equiv\"?: never;\n name?: never;\n property: string;\n })\n | (MetaResourceBase & {\n charset?: never;\n content: string;\n \"http-equiv\": string;\n name?: never;\n property?: never;\n });\n\nexport type MetaResourceOptions = DistributiveOmit<MetaResource, \"kind\">;\n\nexport type FigAssetResourceList =\n | FigAssetResource\n | readonly FigAssetResource[];\n\n// Asset resources a client reference contributes when it renders. Eager for\n// hand-written lists; a thunk for bundler-manifest resolution that may not be\n// available until serialization time, or that maps paths differently per build.\nexport type ClientReferenceAssets =\n | FigAssetResourceList\n | (() => FigAssetResourceList);\n\nexport interface AssetsProps {\n assets: FigAssetResourceList;\n children?: FigNode;\n}\n\nexport function assets(\n value: FigAssetResourceList,\n children?: FigNode,\n): FigElement<AssetsProps> {\n return createElement(Assets, { assets: value }, children);\n}\n\nexport function stylesheet(\n href: string,\n options: Omit<StylesheetResource, \"href\" | \"kind\"> = {},\n): StylesheetResource {\n return { ...options, href, kind: \"stylesheet\" };\n}\n\nexport function preload(\n href: string,\n as: string,\n options: Omit<PreloadResource, \"as\" | \"href\" | \"kind\"> = {},\n): PreloadResource {\n return {\n ...options,\n as,\n href,\n imagesrcset: as === \"image\" ? options.imagesrcset || undefined : undefined,\n kind: \"preload\",\n };\n}\n\nexport function modulepreload(\n href: string,\n options: Omit<ModulePreloadResource, \"href\" | \"kind\"> = {},\n): ModulePreloadResource {\n return { ...options, href, kind: \"modulepreload\" };\n}\n\nexport function script(\n src: string,\n options: Omit<ScriptResource, \"kind\" | \"src\"> = {},\n): ScriptResource {\n return { ...options, kind: \"script\", src };\n}\n\nexport function font(\n href: string,\n type: string,\n options: Omit<FontResource, \"href\" | \"kind\" | \"type\"> = {},\n): FontResource {\n return { ...options, href, kind: \"font\", type };\n}\n\nexport function preconnect(\n href: string,\n options: Omit<PreconnectResource, \"href\" | \"kind\"> = {},\n): PreconnectResource {\n return { ...options, href, kind: \"preconnect\" };\n}\n\nexport function title(value: string): TitleResource {\n return { kind: \"title\", value };\n}\n\nexport function meta(options: MetaResourceOptions): MetaResource {\n return { ...options, kind: \"meta\" };\n}\n\nexport function isFigAssetResource(value: unknown): value is FigAssetResource {\n if (typeof value !== \"object\" || value === null || !(\"kind\" in value)) {\n return false;\n }\n\n switch (value.kind) {\n case \"stylesheet\":\n case \"preload\":\n case \"modulepreload\":\n case \"script\":\n case \"font\":\n case \"preconnect\":\n case \"title\":\n case \"meta\":\n return true;\n default:\n return false;\n }\n}\n\nexport function clientReferenceAssets(\n reference: FigClientReference,\n): readonly FigAssetResource[] {\n const value = reference.assets;\n if (value === undefined) return [];\n\n // Resolved on each call rather than memoized: a lazy resolver may read a\n // manifest that is not loaded until serialization, and a consumer that wants\n // to cache can do so against the stable reference identity.\n const list = typeof value === \"function\" ? value() : value;\n if (isFigAssetResource(list)) return [list];\n // A thunk that yields nothing (e.g. a missing manifest entry) normalizes to an\n // empty list rather than leaking a non-array through the readonly contract.\n return Array.isArray(list) ? list : [];\n}\n\nexport function assetResourceKey(resource: FigAssetResource): string {\n // A document carries a single <title>; collapse every title to one key even\n // when an author supplies an explicit key, so the singleton invariant cannot\n // be bypassed into emitting multiple <title> elements (invalid HTML).\n if (resource.kind === \"title\") return \"title\";\n\n // A font is serialized and inserted as <link rel=\"preload\" as=\"font\">, so an\n // explicit key must also live in the preload key space.\n if (resource.kind === \"font\" && resource.key !== undefined)\n return `preload:${resource.key}`;\n\n if (resource.key !== undefined) return `${resource.kind}:${resource.key}`;\n\n switch (resource.kind) {\n case \"stylesheet\":\n return `stylesheet:${resource.href}`;\n case \"preload\": {\n const imagesrcset = resource.imagesrcset || undefined;\n return `preload:${resource.as}:${\n imagesrcset === undefined\n ? (resource.href ?? \"\")\n : `${imagesrcset}\\n${resource.imagesizes ?? \"\"}`\n }`;\n }\n case \"modulepreload\":\n return `modulepreload:${resource.href}`;\n case \"script\":\n return `script:${resource.src}`;\n case \"font\":\n // A font is loaded as <link rel=\"preload\" as=\"font\">, so it must share the\n // preload-font key space across every package (SSR registry, payload record,\n // client insert) — otherwise a font() and an equivalent preload(href,\n // \"font\") would key separately and fail to dedupe.\n return `preload:font:${resource.href}`;\n case \"preconnect\":\n return `preconnect:${resource.href}`;\n case \"meta\":\n return metaResourceKey(resource);\n }\n}\n\nexport function assetResourceDestination(\n resource: FigAssetResource,\n): AssetResourceDestination {\n return resource.kind === \"title\" || resource.kind === \"meta\"\n ? \"head\"\n : \"stream\";\n}\n\nexport function assetResourceFromHostProps(\n type: string,\n props: Props,\n): FigAssetResource | null {\n if (\n (props as AssetResourceHostProps)[PreventAssetResourceHoistSymbol] === true\n ) {\n return null;\n }\n return resourceFromHost(type, (name) => props[name], props.children, true);\n}\n\nexport function preventAssetResourceHoist<P extends Props>(props: P): P {\n Object.defineProperty(props, PreventAssetResourceHoistSymbol, {\n enumerable: true,\n value: true,\n });\n return props;\n}\n\nexport function assetResourceFromHostAttributes(\n type: string,\n getAttribute: (name: string) => unknown,\n): FigAssetResource | null {\n return resourceFromHost(type, getAttribute, undefined, false);\n}\n\nexport type AssetResourceHostAttribute = readonly [\n name: string,\n value: string | true,\n];\n\n// Canonical attribute serialization for hoisted asset-resource elements,\n// shared by the server's registry writer and the client's head insertion so\n// the two renders cannot drift. `true` marks a boolean attribute (bare on\n// the server, empty-string in the DOM). Server-only attributes (id, nonce)\n// stay with the server writer; title/meta are written by their own paths.\nexport function assetResourceHostAttributes(\n resource: FigAssetResource,\n): AssetResourceHostAttribute[] {\n const pairs: Array<readonly [string, string | true | undefined]> = [];\n\n switch (resource.kind) {\n case \"stylesheet\":\n pairs.push(\n [\"rel\", \"stylesheet\"],\n [\"href\", resource.href],\n [\"data-fig-resource-key\", resource.key],\n [\"data-precedence\", resource.precedence],\n [\"media\", resource.media],\n [\"crossorigin\", resource.crossorigin],\n );\n break;\n case \"preload\": {\n const imagesrcset = resource.imagesrcset || undefined;\n pairs.push(\n [\"rel\", \"preload\"],\n [\"href\", imagesrcset === undefined ? resource.href : undefined],\n [\"as\", resource.as],\n [\"data-fig-resource-key\", resource.key],\n [\"type\", resource.type],\n [\"crossorigin\", resource.crossorigin],\n [\"fetchpriority\", resource.fetchpriority],\n [\"imagesrcset\", imagesrcset],\n [\"imagesizes\", resource.imagesizes],\n [\"referrerpolicy\", resource.referrerpolicy],\n );\n break;\n }\n case \"modulepreload\":\n pairs.push(\n [\"rel\", \"modulepreload\"],\n [\"href\", resource.href],\n [\"data-fig-resource-key\", resource.key],\n [\"crossorigin\", resource.crossorigin],\n [\"fetchpriority\", resource.fetchpriority],\n );\n break;\n case \"font\":\n pairs.push(\n [\"rel\", \"preload\"],\n [\"href\", resource.href],\n [\"as\", \"font\"],\n [\"data-fig-resource-key\", resource.key],\n [\"type\", resource.type],\n [\"crossorigin\", resource.crossorigin ?? \"anonymous\"],\n [\"fetchpriority\", resource.fetchpriority],\n );\n break;\n case \"preconnect\":\n pairs.push(\n [\"rel\", \"preconnect\"],\n [\"href\", resource.href],\n [\"data-fig-resource-key\", resource.key],\n [\"crossorigin\", resource.crossorigin],\n );\n break;\n case \"script\":\n pairs.push(\n [\"src\", resource.src],\n [\"type\", resource.module === true ? \"module\" : undefined],\n [\"data-fig-resource-key\", resource.key],\n // Hoisted scripts default to async, but an explicit defer opts into\n // ordered execution and must not be overridden (async wins over\n // defer in browsers).\n [\n \"async\",\n (resource.async ?? resource.defer !== true) ? true : undefined,\n ],\n [\"defer\", resource.defer === true ? true : undefined],\n [\"crossorigin\", resource.crossorigin],\n );\n break;\n case \"title\":\n case \"meta\":\n break;\n }\n\n return pairs.filter(\n (pair): pair is readonly [string, string | true] => pair[1] !== undefined,\n );\n}\n\nfunction resourceFromHost(\n type: string,\n prop: (name: string) => unknown,\n children?: FigNode,\n requireAsyncScript = false,\n): FigAssetResource | null {\n const withKey = (\n resource: FigAssetResource | null,\n ): FigAssetResource | null => {\n if (resource === null) return null;\n const key = readProp(prop, \"data-fig-resource-key\");\n return key === undefined ? resource : { ...resource, key };\n };\n\n switch (type.toLowerCase()) {\n case \"title\":\n if (readProp(prop, \"itemprop\") !== undefined) return null;\n return withKey({ kind: \"title\", value: textResourceValue(children) });\n case \"meta\":\n if (readProp(prop, \"itemprop\") !== undefined) return null;\n return withKey(metaResourceFromHost(prop));\n case \"link\":\n return withKey(linkResourceFromHost(prop));\n case \"script\": {\n const src = readProp(prop, \"src\");\n // A raw script keeps native placement and execution semantics unless the\n // author explicitly marks it async. Explicit script() descriptors remain\n // the opt-in path for hoisted defer, module, or synchronous scripts.\n const async = hasBooleanAttribute(prop(\"async\"));\n if (src === undefined || (requireAsyncScript && !async)) return null;\n return withKey({\n async,\n crossorigin: readCrossorigin(prop),\n defer: hasBooleanAttribute(prop(\"defer\")),\n kind: \"script\",\n module: prop(\"type\") === \"module\",\n src,\n });\n }\n default:\n return null;\n }\n}\n\nfunction metaResourceFromHost(\n prop: (name: string) => unknown,\n): MetaResource | null {\n const charset = readProp(prop, \"charset\");\n const httpEquiv = readProp(prop, \"http-equiv\");\n const name = readProp(prop, \"name\");\n const property = readProp(prop, \"property\");\n const identities = [charset, httpEquiv, name, property].filter(\n (value) => value !== undefined,\n );\n\n if (identities.length !== 1) return null;\n if (charset !== undefined) return { charset, kind: \"meta\" };\n\n const content = readProp(prop, \"content\");\n if (content === undefined) return null;\n if (httpEquiv !== undefined) {\n return { content, \"http-equiv\": httpEquiv, kind: \"meta\" };\n }\n if (name !== undefined) return { content, kind: \"meta\", name };\n if (property !== undefined) return { content, kind: \"meta\", property };\n return null;\n}\n\nfunction hasBooleanAttribute(value: unknown): boolean {\n return value !== undefined && value !== null && value !== false;\n}\n\nfunction linkResourceFromHost(\n prop: (name: string) => unknown,\n): FigAssetResource | null {\n const rel = readProp(prop, \"rel\")?.toLowerCase();\n const href = readProp(prop, \"href\");\n if (rel === undefined || readProp(prop, \"itemprop\") !== undefined) {\n return null;\n }\n\n if (rel === \"preload\") {\n const as = readProp(prop, \"as\");\n const imagesrcset =\n as === \"image\" ? readProp(prop, \"imagesrcset\") || undefined : undefined;\n if (as === undefined || (href === undefined && imagesrcset === undefined)) {\n return null;\n }\n return {\n as,\n crossorigin: readCrossorigin(prop),\n fetchpriority: fetchpriorityProp(readProp(prop, \"fetchpriority\")),\n href,\n imagesizes:\n imagesrcset === undefined ? undefined : readProp(prop, \"imagesizes\"),\n imagesrcset,\n kind: \"preload\",\n referrerpolicy: readProp(prop, \"referrerpolicy\"),\n type: readProp(prop, \"type\"),\n };\n }\n\n if (href === undefined) return null;\n\n if (rel === \"stylesheet\") {\n return {\n blocking: prop(\"blocking\") === \"none\" ? \"none\" : undefined,\n crossorigin: readCrossorigin(prop),\n href,\n kind: \"stylesheet\",\n media: readProp(prop, \"media\"),\n // Hoisted elements serialize the canonical data-precedence attribute;\n // host-rendered <link precedence> keeps the author-facing prop name.\n precedence: readProp(prop, \"precedence\", \"data-precedence\"),\n };\n }\n\n if (rel === \"modulepreload\") {\n return {\n crossorigin: readCrossorigin(prop),\n fetchpriority: fetchpriorityProp(readProp(prop, \"fetchpriority\")),\n href,\n kind: \"modulepreload\",\n };\n }\n\n if (rel === \"preconnect\") {\n return {\n crossorigin: readCrossorigin(prop),\n href,\n kind: \"preconnect\",\n };\n }\n\n return null;\n}\n\nfunction readProp(\n prop: (name: string) => unknown,\n ...names: string[]\n): string | undefined {\n for (const name of names) {\n const value = stringProp(prop(name));\n if (value !== undefined) return value;\n }\n\n return undefined;\n}\n\nfunction stringProp(value: unknown): string | undefined {\n if (value === undefined || value === null || value === false)\n return undefined;\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"bigint\" ||\n value === true\n ) {\n return String(value);\n }\n\n throw new Error(\n \"Resource host props must be serializable during server render.\",\n );\n}\n\nfunction readCrossorigin(\n prop: (name: string) => unknown,\n): CrossOrigin | undefined {\n return crossoriginProp(readProp(prop, \"crossorigin\"));\n}\n\nfunction crossoriginProp(value: unknown): CrossOrigin | undefined {\n return value === \"anonymous\" || value === \"use-credentials\" || value === \"\"\n ? value\n : undefined;\n}\n\nfunction fetchpriorityProp(value: unknown): FetchPriority | undefined {\n return value === \"high\" || value === \"low\" || value === \"auto\"\n ? value\n : undefined;\n}\n\nfunction textResourceValue(node: FigNode): string {\n if (node === null || node === undefined || typeof node === \"boolean\") {\n return \"\";\n }\n if (typeof node === \"string\" || typeof node === \"number\") return String(node);\n if (Array.isArray(node)) return node.map(textResourceValue).join(\"\");\n if (isThenable(node)) return textResourceValue(readThenable(node));\n\n throw new Error(\"<title> can only contain text during server render.\");\n}\n\nfunction metaResourceKey(resource: MetaResource): string {\n if (resource.charset !== undefined) return `meta:charset:${resource.charset}`;\n if (resource.name !== undefined) return `meta:name:${resource.name}`;\n if (resource.property !== undefined)\n return `meta:property:${resource.property}`;\n return `meta:http-equiv:${resource[\"http-equiv\"]}`;\n}\n"],"mappings":";;AAUA,MAAM,kCAAkB,IAAI,QAAyC;AAErE,SAAS,UAAa,UAA6C;CACjE,MAAM,MAAM;CACZ,IAAI,SAAS,gBAAgB,IAAI,GAAG;CAEpC,IAAI,WAAW,KAAA,GAAW;EACxB,SAAS,EAAE,QAAQ,UAAU;EAC7B,gBAAgB,IAAI,KAAK,MAAM;EAC/B,SAAS,MACN,UAAU;GACT,SAAS;IAAE,QAAQ;IAAa;GAAM;GACtC,gBAAgB,IAAI,KAAK,MAAM;EACjC,IACC,WAAoB;GACnB,SAAS;IAAE;IAAQ,QAAQ;GAAW;GACtC,gBAAgB,IAAI,KAAK,MAAM;EACjC,CACF;CACF;CAEA,OAAO;AACT;AAKA,SAAgB,cAAiB,UAAgC;CAC/D,UAAU,QAAQ;AACpB;AAEA,SAAgB,aAAgB,UAA6B;CAC3D,MAAM,SAAS,UAAU,QAAQ;CACjC,IAAI,OAAO,WAAW,aAAa,OAAO,OAAO;CACjD,IAAI,OAAO,WAAW,YAAY,MAAM,OAAO;CAC/C,MAAM;AACR;AAEA,SAAgB,WAAW,OAAmC;CAC5D,IACG,OAAO,UAAU,YAAY,OAAO,UAAU,cAC/C,UAAU,MAEV,OAAO;CAGT,OAAO,UAAU,SAAS,OAAO,MAAM,SAAS;AAClD;;;AC/CA,MAAM,kCAAkC,OAAO,IAC7C,kCACF;AAwIA,SAAgB,OACd,OACA,UACyB;CACzB,OAAO,cAAc,QAAQ,EAAE,QAAQ,MAAM,GAAG,QAAQ;AAC1D;AAEA,SAAgB,WACd,MACA,UAAqD,CAAC,GAClC;CACpB,OAAO;EAAE,GAAG;EAAS;EAAM,MAAM;CAAa;AAChD;AAEA,SAA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