@bgub/fig 0.1.0-alpha.7 → 0.1.1
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 +610 -0
- package/dist/{element-Od8CmsBL.d.ts → element-9MtOc5qb.d.ts} +113 -0
- package/dist/{element-wieeFL9f.js → element-mHDfizuh.js} +55 -1
- package/dist/element-mHDfizuh.js.map +1 -0
- package/dist/{hooks-BSqKOOez.d.ts → hooks-Bw3vbom7.d.ts} +63 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/internal.d.ts +45 -2
- package/dist/internal.js +24 -4
- package/dist/internal.js.map +1 -1
- package/dist/jsx-runtime.d.ts +4 -1
- package/dist/jsx-runtime.js +7 -1
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/{payload-format-Dgap54q-.js → payload-format-BbsvTG9V.js} +14 -1
- package/dist/payload-format-BbsvTG9V.js.map +1 -0
- package/dist/payload.d.ts +6 -1
- package/dist/payload.js +11 -8
- package/dist/payload.js.map +1 -1
- package/{dist-development/resource-Cp01PvqW.js → dist/resource-BJxS62H2.js} +23 -3
- package/dist/resource-BJxS62H2.js.map +1 -0
- package/dist/{transition-DBjQTorq.js → transition-WvgFiYNY.js} +23 -4
- package/dist/transition-WvgFiYNY.js.map +1 -0
- package/dist-development/{element-Bb5fLsPy.js → element-CVlfN_3_.js} +55 -1
- package/dist-development/element-CVlfN_3_.js.map +1 -0
- package/dist-development/index.js +3 -3
- package/dist-development/internal.js +24 -4
- package/dist-development/internal.js.map +1 -1
- package/dist-development/jsx-runtime.js +7 -1
- package/dist-development/jsx-runtime.js.map +1 -1
- package/dist-development/{payload-format-Dgap54q-.js → payload-format-BbsvTG9V.js} +14 -1
- package/dist-development/payload-format-BbsvTG9V.js.map +1 -0
- package/dist-development/payload.js +11 -8
- package/dist-development/payload.js.map +1 -1
- package/{dist/resource-BfNHyXun.js → dist-development/resource-Bhusybfq.js} +23 -3
- package/dist-development/resource-Bhusybfq.js.map +1 -0
- package/dist-development/{transition-CNVJyoT2.js → transition-BSxdDR9D.js} +23 -4
- package/dist-development/transition-BSxdDR9D.js.map +1 -0
- package/package.json +2 -2
- package/dist/element-wieeFL9f.js.map +0 -1
- package/dist/payload-format-Dgap54q-.js.map +0 -1
- package/dist/resource-BfNHyXun.js.map +0 -1
- package/dist/transition-DBjQTorq.js.map +0 -1
- package/dist-development/element-Bb5fLsPy.js.map +0 -1
- package/dist-development/payload-format-Dgap54q-.js.map +0 -1
- package/dist-development/resource-Cp01PvqW.js.map +0 -1
- package/dist-development/transition-CNVJyoT2.js.map +0 -1
|
@@ -114,12 +114,14 @@ function createPayloadGraphDecodeContext() {
|
|
|
114
114
|
};
|
|
115
115
|
return context;
|
|
116
116
|
}
|
|
117
|
+
/** Creates payload graph encode context. */
|
|
117
118
|
function createPayloadGraphEncodeContext() {
|
|
118
119
|
return {
|
|
119
120
|
defined: [],
|
|
120
121
|
ids: /* @__PURE__ */ new WeakMap()
|
|
121
122
|
};
|
|
122
123
|
}
|
|
124
|
+
/** Checks whether plain payload value. */
|
|
123
125
|
function isPlainPayloadValue(value) {
|
|
124
126
|
return value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || typeof value === "symbol";
|
|
125
127
|
}
|
|
@@ -131,6 +133,7 @@ function isPlainPayloadValue(value) {
|
|
|
131
133
|
function encodePayloadValue(value) {
|
|
132
134
|
return encodePayloadValueWithGraph(value, createPayloadGraphEncodeContext());
|
|
133
135
|
}
|
|
136
|
+
/** Encodes payload value with graph. */
|
|
134
137
|
function encodePayloadValueWithGraph(value, graph) {
|
|
135
138
|
if (value === null) return null;
|
|
136
139
|
if (value === void 0) return { $fig: "undefined" };
|
|
@@ -163,6 +166,7 @@ function encodePayloadValueWithGraph(value, graph) {
|
|
|
163
166
|
if (typeof value === "object" && value !== null) return serializePayloadPlainObject(value, graph, (child) => encodePayloadValueWithGraph(child, graph));
|
|
164
167
|
throw new Error(`Cannot serialize ${typeof value} into the payload.`);
|
|
165
168
|
}
|
|
169
|
+
/** Serializes payload map. */
|
|
166
170
|
function serializePayloadMap(value, graph, encodeEntry) {
|
|
167
171
|
const existing = payloadGraphReference(graph, value);
|
|
168
172
|
if (existing !== null) return existing;
|
|
@@ -175,6 +179,7 @@ function serializePayloadMap(value, graph, encodeEntry) {
|
|
|
175
179
|
entries
|
|
176
180
|
};
|
|
177
181
|
}
|
|
182
|
+
/** Serializes payload set. */
|
|
178
183
|
function serializePayloadSet(value, graph, encodeItem) {
|
|
179
184
|
const existing = payloadGraphReference(graph, value);
|
|
180
185
|
if (existing !== null) return existing;
|
|
@@ -200,17 +205,21 @@ function definePayloadGraphObject(graph, value) {
|
|
|
200
205
|
graph.ids.set(value, id);
|
|
201
206
|
return id;
|
|
202
207
|
}
|
|
208
|
+
/** Checkpoint payload graph. */
|
|
203
209
|
function checkpointPayloadGraph(graph) {
|
|
204
210
|
return graph.defined.length;
|
|
205
211
|
}
|
|
212
|
+
/** Rollback payload graph. */
|
|
206
213
|
function rollbackPayloadGraph(graph, checkpoint) {
|
|
207
214
|
while (graph.defined.length > checkpoint) graph.ids.delete(graph.defined.pop());
|
|
208
215
|
}
|
|
216
|
+
/** Define payload graph element. */
|
|
209
217
|
function definePayloadGraphElement(graph, value) {
|
|
210
218
|
const existing = payloadGraphReference(graph, value);
|
|
211
219
|
if (existing !== null) return existing;
|
|
212
220
|
return definePayloadGraphObject(graph, value);
|
|
213
221
|
}
|
|
222
|
+
/** Serializes payload array. */
|
|
214
223
|
function serializePayloadArray(value, graph, encodeChild) {
|
|
215
224
|
const existing = payloadGraphReference(graph, value);
|
|
216
225
|
if (existing !== null) return existing;
|
|
@@ -220,6 +229,7 @@ function serializePayloadArray(value, graph, encodeChild) {
|
|
|
220
229
|
value: value.map(encodeChild)
|
|
221
230
|
};
|
|
222
231
|
}
|
|
232
|
+
/** Serializes payload plain object. */
|
|
223
233
|
function serializePayloadPlainObject(value, graph, encodeChild) {
|
|
224
234
|
const existing = payloadGraphReference(graph, value);
|
|
225
235
|
if (existing !== null) return existing;
|
|
@@ -323,6 +333,7 @@ function decodePayloadNumber(value) {
|
|
|
323
333
|
case "NaN": return NaN;
|
|
324
334
|
}
|
|
325
335
|
}
|
|
336
|
+
/** Encodes payload data entries. */
|
|
326
337
|
function encodePayloadDataEntries(entries) {
|
|
327
338
|
const graph = createPayloadGraphEncodeContext();
|
|
328
339
|
return entries.map((entry) => ({
|
|
@@ -330,6 +341,7 @@ function encodePayloadDataEntries(entries) {
|
|
|
330
341
|
value: encodePayloadValueWithGraph(entry.value, graph)
|
|
331
342
|
}));
|
|
332
343
|
}
|
|
344
|
+
/** Decodes payload data entries. */
|
|
333
345
|
function decodePayloadDataEntries(entries) {
|
|
334
346
|
const graph = createPayloadGraphDecodeContext();
|
|
335
347
|
return entries.map((entry) => ({
|
|
@@ -337,6 +349,7 @@ function decodePayloadDataEntries(entries) {
|
|
|
337
349
|
value: decodeModelValue(entry.value, graph)
|
|
338
350
|
}));
|
|
339
351
|
}
|
|
352
|
+
/** Checks whether payload special model. */
|
|
340
353
|
function isPayloadSpecialModel(model) {
|
|
341
354
|
if (!("$fig" in model)) return false;
|
|
342
355
|
switch (model.$fig) {
|
|
@@ -363,4 +376,4 @@ function isPayloadSpecialModel(model) {
|
|
|
363
376
|
//#endregion
|
|
364
377
|
export { serializePayloadArray as _, decodePayloadRecord as a, serializePayloadSet as b, definePayloadGraphElement as c, encodePayloadValueWithGraph as d, errorFromPayloadValue as f, rollbackPayloadGraph as g, jsonPayloadCodec as h, decodePayloadDataEntries as i, encodePayloadDataEntries as l, isPlainPayloadValue as m, checkpointPayloadGraph as n, decodePayloadValue as o, isPayloadSpecialModel as p, createPayloadGraphEncodeContext as r, decodePayloadValueTag as s, assertPayloadCodecMatches as t, encodePayloadValue as u, serializePayloadMap as v, serializePayloadPlainObject as y };
|
|
365
378
|
|
|
366
|
-
//# sourceMappingURL=payload-format-
|
|
379
|
+
//# sourceMappingURL=payload-format-BbsvTG9V.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload-format-BbsvTG9V.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.\n/** Describes serialized asset resource. */\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\n/** Describes payload element model. */\nexport type PayloadElementModel = {\n $fig: \"element\";\n id?: number;\n key: Key | null;\n props: PayloadModel;\n type: string | PayloadSpecialModel;\n};\n\n/** Describes payload special model. */\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\n/** Describes payload data hydration entry. */\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\n/** Describes payload graph encode context. */\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\n/** Creates payload graph encode context. */\nexport function createPayloadGraphEncodeContext(): PayloadGraphEncodeContext {\n return { defined: [], ids: new WeakMap() };\n}\n\n/** Checks whether plain payload value. */\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\n/** Encodes payload value with graph. */\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(value, graph, (item) =>\n 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\n/** Serializes payload map. */\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\n/** Serializes payload set. */\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\n/** Checkpoint payload graph. */\nexport function checkpointPayloadGraph(\n graph: PayloadGraphEncodeContext,\n): number {\n return graph.defined.length;\n}\n\n/** Rollback payload graph. */\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\n/** Define payload graph element. */\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\n/** Serializes payload array. */\nexport function serializePayloadArray<T>(\n value: readonly T[],\n graph: PayloadGraphEncodeContext,\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: value.map(encodeChild) };\n}\n\n/** Serializes payload plain object. */\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\n/** Encodes payload data entries. */\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\n/** Decodes payload data entries. */\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\n/** Checks whether payload special model. */\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":";AA8LA,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,cA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OAAO;EACT,KAAK,aACH,OAAO;EACT,KAAK,MACH,OAAO;EACT,KAAK,OACH,OAAO;CACX;AACF;;AAGA,SAAgB,yBACd,SAC6B;CAC7B,MAAM,QAAQ,gCAAgC;CAC9C,OAAO,QAAQ,KAAK,WAAW;EAC7B,GAAG;EACH,OAAO,4BAA4B,MAAM,OAAO,KAAK;CACvD,EAAE;AACJ;;AAGA,SAAgB,yBACd,SACyB;CACzB,MAAM,QAAQ,gCAAgC;CAC9C,OAAO,QAAQ,KAAK,WAAW;EAC7B,GAAG;EACH,OAAO,iBAAiB,MAAM,OAAO,KAAK;CAC5C,EAAE;AACJ;;AAGA,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,8 +1,9 @@
|
|
|
1
|
-
import { L as readPromise, f as Fragment, g as createElement, m as ViewTransition, p as Suspense, s as FigElementSymbol } from "./element-
|
|
2
|
-
import { s as assets, t as assetResourceDestination, u as isFigAssetResource, x as trackThenable, y as isThenable } from "./resource-
|
|
3
|
-
import { a as decodePayloadRecord, f as errorFromPayloadValue, h as jsonPayloadCodec, i as decodePayloadDataEntries, p as isPayloadSpecialModel, s as decodePayloadValueTag } from "./payload-format-
|
|
1
|
+
import { L as readPromise, f as Fragment, g as createElement, m as ViewTransition, p as Suspense, s as FigElementSymbol } from "./element-CVlfN_3_.js";
|
|
2
|
+
import { s as assets, t as assetResourceDestination, u as isFigAssetResource, x as trackThenable, y as isThenable } from "./resource-Bhusybfq.js";
|
|
3
|
+
import { a as decodePayloadRecord, f as errorFromPayloadValue, h as jsonPayloadCodec, i as decodePayloadDataEntries, p as isPayloadSpecialModel, s as decodePayloadValueTag } from "./payload-format-BbsvTG9V.js";
|
|
4
4
|
//#region src/payload-client-reference.ts
|
|
5
5
|
const resolverEntries = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
/** Creates payload client reference resolver. */
|
|
6
7
|
function createPayloadClientReferenceResolver(resolve) {
|
|
7
8
|
const entries = /* @__PURE__ */ new Map();
|
|
8
9
|
const resolver = Object.assign((reference) => resolve(reference), {
|
|
@@ -157,11 +158,13 @@ var PayloadDecoder = class {
|
|
|
157
158
|
this.value = this.chunkPromise(this.getChunk(0));
|
|
158
159
|
this.ingest(stream, rowDecoder);
|
|
159
160
|
const signal = options.signal;
|
|
160
|
-
if (signal !== void 0)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
if (signal !== void 0) {
|
|
162
|
+
if (signal.aborted) this.abort(signal.reason);
|
|
163
|
+
else {
|
|
164
|
+
const onAbort = () => this.abort(signal.reason);
|
|
165
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
166
|
+
this.removeAbortListener = () => signal.removeEventListener("abort", onAbort);
|
|
167
|
+
}
|
|
165
168
|
}
|
|
166
169
|
}
|
|
167
170
|
abort(reason) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payload.js","names":["attachAssets","attachAssets"],"sources":["../src/payload-client-reference.ts","../src/payload.ts"],"sourcesContent":["import {\n createElement,\n type ElementType,\n type FigNode,\n type Props,\n} from \"./element.ts\";\nimport { readPromise } from \"./hooks.ts\";\nimport { assets as attachAssets, type FigAssetResource } from \"./resource.ts\";\nimport { isThenable, trackThenable } from \"./thenables.ts\";\n\nexport interface PayloadClientReference {\n assets?: readonly FigAssetResource[];\n exportName?: string;\n id: string;\n ssr?: boolean;\n}\n\nexport type ResolveClientReference = (\n reference: PayloadClientReference,\n) => ElementType<any> | PromiseLike<ElementType<any>> | undefined;\n\n/**\n * A caller-owned stateful resolver: a `ResolveClientReference` that also\n * owns component identity. Decodes given one (as `resolveClientReference`)\n * resolve every client reference to a single resolver-owned wrapper per\n * reference id, so re-decoding a payload updates islands in place instead\n * of remounting them. The caller owns the lifetime: drop entries when their\n * modules change (HMR) or the manifest swaps.\n */\nexport interface PayloadClientReferenceResolver {\n (\n reference: PayloadClientReference,\n ): ElementType<any> | PromiseLike<ElementType<any>> | undefined;\n clear(): void;\n delete(id: string): boolean;\n}\n\nconst resolverEntries = new WeakMap<\n ResolveClientReference,\n Map<string, ElementType<any>>\n>();\n\nexport function createPayloadClientReferenceResolver(\n resolve: ResolveClientReference,\n): PayloadClientReferenceResolver {\n const entries = new Map<string, ElementType<any>>();\n const resolver = Object.assign(\n (reference: PayloadClientReference) => resolve(reference),\n {\n clear: (): void => entries.clear(),\n delete: (id: string): boolean => entries.delete(id),\n },\n );\n resolverEntries.set(resolver, entries);\n return resolver;\n}\n\ninterface ElementDelivery {\n assets?: readonly FigAssetResource[];\n gate?: Promise<void>;\n}\n\n// Delivery belongs to the decoded element, not its stable component type. A\n// newer decode therefore cannot re-suspend an already-mounted island.\nconst elementDelivery = new WeakMap<Props, ElementDelivery>();\n\n/** Owns client-reference identity and per-decode delivery state. */\nexport class PayloadClientReferences {\n private readonly rows = new Map<number, ElementDelivery>();\n\n constructor(private readonly resolve?: ResolveClientReference) {}\n\n register(\n rowId: number,\n reference: PayloadClientReference,\n gate: Promise<void> | null,\n assets: readonly FigAssetResource[] | null,\n ): ElementType<any> {\n const hasDelivery = gate !== null || assets !== null;\n if (hasDelivery) {\n const delivery: ElementDelivery = {};\n if (gate !== null) delivery.gate = gate;\n if (assets !== null) delivery.assets = assets;\n this.rows.set(rowId, delivery);\n\n if (gate !== null) {\n void gate.then(() => {\n delete delivery.gate;\n if (delivery.assets === undefined) this.rows.delete(rowId);\n });\n }\n }\n\n return this.resolveComponent(reference, hasDelivery);\n }\n\n attach(rowId: number, props: Props): void {\n const delivery = this.rows.get(rowId);\n if (delivery !== undefined) elementDelivery.set(props, delivery);\n }\n\n private resolveComponent(\n reference: PayloadClientReference,\n hasDelivery: boolean,\n ): ElementType<any> {\n const entries =\n this.resolve === undefined\n ? undefined\n : resolverEntries.get(this.resolve);\n const existing = entries?.get(reference.id);\n if (existing !== undefined) return existing;\n\n let resolved: ReturnType<ResolveClientReference>;\n try {\n resolved = this.resolve?.(reference);\n } catch (error) {\n resolved = Promise.reject(error);\n }\n\n if (resolved === undefined) {\n // Never cache a missing manifest entry: a later decode may resolve it.\n return function PayloadUnresolvedClientComponent(): never {\n throw new Error(\n `Cannot render client reference \"${reference.id}\" because decodePayloadStream was not configured with a matching resolveClientReference.`,\n );\n };\n }\n\n // A direct synchronous component needs no wrapper when identity does not\n // need resolver ownership and this decode has no delivery state.\n if (entries === undefined && !isThenable(resolved) && !hasDelivery) {\n return resolved;\n }\n\n const component = clientReferenceWrapper(resolved, reference.id);\n entries?.set(reference.id, component);\n return component;\n }\n}\n\nfunction clientReferenceWrapper(\n resolved: ElementType<any> | PromiseLike<ElementType<any>>,\n referenceId: string,\n): ElementType<any> {\n let render: (props: Props) => FigNode;\n if (isThenable(resolved)) {\n const pending = Promise.resolve(resolved);\n trackThenable(pending);\n let type: ElementType<any> | null = null;\n render = (props) => {\n type ??= clientReferenceType(readPromise(pending), referenceId);\n return createElement(type, props);\n };\n } else {\n render = (props) => createElement(resolved, props);\n }\n\n function PayloadClientContent(content: {\n gate?: Promise<void>;\n props: Props;\n }): FigNode {\n if (content.gate !== undefined) readPromise(content.gate);\n return render(content.props);\n }\n\n return function PayloadClientComponent(props: Props): FigNode {\n const delivery = elementDelivery.get(props);\n const content = createElement(PayloadClientContent, {\n gate: delivery?.gate,\n props,\n });\n return delivery?.assets === undefined\n ? content\n : attachAssets(delivery.assets, content);\n };\n}\n\nfunction clientReferenceType(value: unknown, id: string): ElementType<any> {\n if (typeof value === \"function\") return value as ElementType<any>;\n throw new Error(`Client reference \"${id}\" did not resolve to a component.`);\n}\n","import type { FigDataHydrationEntry } from \"./data.ts\";\nimport {\n type AwaitedFigNode,\n createElement,\n type ElementType,\n FigElementSymbol,\n type FigNode,\n Fragment,\n type Key,\n type Props,\n Suspense,\n ViewTransition,\n} from \"./element.ts\";\nimport { readPromise } from \"./hooks.ts\";\nimport {\n createPayloadClientReferenceResolver,\n type PayloadClientReference,\n type PayloadClientReferenceResolver,\n PayloadClientReferences,\n type ResolveClientReference,\n} from \"./payload-client-reference.ts\";\nimport {\n decodePayloadDataEntries,\n decodePayloadRecord,\n decodePayloadValueTag,\n errorFromPayloadValue,\n isPayloadSpecialModel,\n jsonPayloadCodec,\n type PayloadDecodeRefs,\n type PayloadElementModel,\n type PayloadModel,\n type PayloadRow,\n type PayloadRowDecoder,\n type PayloadSpecialModel,\n type SerializedAssetResource,\n} from \"./payload-format.ts\";\nimport {\n assetResourceDestination,\n assets as attachAssets,\n type FigAssetResource,\n isFigAssetResource,\n} from \"./resource.ts\";\nimport { isThenable, trackThenable } from \"./thenables.ts\";\n\nexport {\n createPayloadClientReferenceResolver,\n type PayloadClientReference,\n type PayloadClientReferenceResolver,\n type ResolveClientReference,\n};\n\nexport type PayloadDecodeCompletion =\n | { status: \"aborted\" }\n | { status: \"complete\" }\n | { status: \"failed\"; error: unknown };\n\nexport interface PayloadDecodeOptions {\n /**\n * Receives decoded `data` rows for hydration into a data store. The\n * capability itself is expected to be generation-guarded and to ignore\n * entries after its caller loses authority.\n */\n hydrate?: (entries: readonly FigDataHydrationEntry[]) => void;\n /**\n * Observes every outlined hole rejection — an `error` row or a stream\n * failure stranding referenced rows, before or after the root fulfills.\n * Abort cancellation is excluded. Called once per rejected hole; the\n * observer is never awaited and cannot break decoding.\n */\n onHoleError?: (error: unknown) => unknown;\n /**\n * Observes the end of ingestion: called exactly once when the stream\n * settles as complete, failed, or aborted. Post-root failures reject the\n * holes they strand, but a failure with no pending slot is otherwise\n * invisible — this is the hook for reporting it. The callback is never\n * awaited, and its exceptions and rejections are swallowed, so an\n * observer cannot block or break decode teardown.\n */\n onStreamDone?: (result: PayloadDecodeCompletion) => unknown;\n /**\n * Called with delivery asset resources as soon as their rows arrive\n * (e.g. fig-dom's insertAssetResources). A returned promise gates the\n * reveal of only the content that declared a dependency on those assets;\n * gate settlement — fulfilled or rejected — releases the reveal, so a\n * failed asset never blocks content.\n */\n prepareAssets?: (\n assets: readonly FigAssetResource[],\n ) => void | PromiseLike<void>;\n /**\n * Retains delivery asset dependencies as `assets(...)` declarations on\n * their decoded owners. Document metadata is always retained because its\n * owner may mutate the document only when it commits. Server document\n * renderers enable this option to retain delivery assets too.\n */\n retainAssets?: boolean;\n /**\n * Resolves client-reference rows to components. A plain function keeps\n * identity per decode: gated and asynchronously resolved references decode\n * to per-decode wrappers and remount on re-decode. A stateful resolver\n * (created by `createPayloadClientReferenceResolver`) keeps every\n * resolvable reference's identity stable across the decodes sharing it.\n */\n resolveClientReference?: ResolveClientReference;\n signal?: AbortSignal;\n}\n\nclass PayloadDecodeAbortedError extends Error {\n constructor(reason?: unknown) {\n super(\n \"Payload decode aborted.\",\n reason === undefined ? undefined : { cause: reason },\n );\n this.name = \"PayloadDecodeAbortedError\";\n }\n}\n\n/**\n * Decode a payload row stream. The returned promise resolves with the\n * decoded root FigNode as soon as the root row decodes (and rejects only\n * when the stream fails before producing a root value, or with the root\n * row's own error); decoding continues in the background, filling outlined\n * holes as their rows arrive. Post-root failures reject the holes they\n * strand and report through `onStreamDone`. Aborting `options.signal`\n * ignores remaining rows and rejects unresolved holes with an internal\n * cancellation reason.\n */\nexport function decodePayloadStream(\n stream: ReadableStream<Uint8Array>,\n options: PayloadDecodeOptions = {},\n): Promise<AwaitedFigNode> {\n return new PayloadDecoder(stream, options).value;\n}\n\ntype DecodeChunk = {\n // The chunk's row has been ingested (decoded or rejected); reveal may still\n // be waiting on an asset gate. Truncation and abort reject only chunks\n // whose rows never arrived.\n arrived: boolean;\n // Materialized lazily: most rows settle synchronously at arrival and are\n // only ever read through result, so eagerly allocating a promise and\n // its controls per row would be waste.\n promise: Promise<unknown> | null;\n reject: ((reason: unknown) => void) | null;\n resolve: ((value: unknown) => void) | null;\n result:\n | { status: \"pending\" }\n | { status: \"fulfilled\"; value: unknown }\n | { status: \"rejected\"; error: unknown };\n};\n\ntype DecodingElement = {\n $$typeof: symbol;\n key: Key | null;\n props: Props;\n type: ElementType<any>;\n};\n\nconst noop = (): void => undefined;\n\nfunction notifyObserver<T>(\n observer: ((value: T) => unknown) | undefined,\n value: T,\n): void {\n try {\n const result = observer?.(value);\n if (isThenable(result)) void Promise.resolve(result).then(noop, noop);\n } catch {\n // Observers cannot break decode teardown or create unhandled rejections.\n }\n}\n\ninterface Deferred<T> {\n promise: Promise<T>;\n reject: (reason: unknown) => void;\n resolve: (value: T) => void;\n}\n\nfunction deferred<T>(): Deferred<T> {\n let resolve: Deferred<T>[\"resolve\"] = noop;\n let reject: Deferred<T>[\"reject\"] = noop;\n const promise = new Promise<T>((innerResolve, innerReject) => {\n resolve = innerResolve;\n reject = innerReject;\n });\n return { promise, reject, resolve };\n}\n\nfunction decodeAssetResources(\n serialized: readonly SerializedAssetResource[] | undefined,\n): FigAssetResource[] | null {\n if (serialized === undefined) return null;\n const assets = serialized.filter(isFigAssetResource);\n return assets.length === 0 ? null : assets;\n}\n\nclass PayloadDecoder {\n readonly value: Promise<AwaitedFigNode>;\n\n private readonly chunks = new Map<number, DecodeChunk>();\n private readonly objectRefs = new Map<number, unknown>();\n // Asset gates registered for a row id (assets rows carry `for`); consumed\n // when that row arrives.\n private readonly rowGates = new Map<number, Array<PromiseLike<void>>>();\n private readonly rowAssets = new Map<number, FigAssetResource[]>();\n private readonly clientReferences: PayloadClientReferences;\n private reader: ReadableStreamDefaultReader<Uint8Array> | null = null;\n private done = false;\n // Resolved on abort so arrived-but-gated chunks reveal instead of waiting\n // for asset gates that may never settle.\n private readonly gateRelease = deferred<void>();\n private removeAbortListener: () => void = noop;\n // One closure and one refs adapter reused across every decoded model, so\n // the per-node decode loop allocates only the decoded values themselves.\n private readonly decodeChild = (model: PayloadModel): unknown =>\n this.decodeModel(model);\n private readonly valueRefs: PayloadDecodeRefs = {\n define: (id, create, fill) => this.defineObjectRef(id, create, fill),\n read: (id) => {\n if (!this.objectRefs.has(id)) {\n throw new Error(`Payload referenced unknown object id ${id}.`);\n }\n return this.objectRefs.get(id);\n },\n };\n\n constructor(\n stream: ReadableStream<Uint8Array>,\n private readonly options: PayloadDecodeOptions,\n ) {\n this.clientReferences = new PayloadClientReferences(\n options.resolveClientReference,\n );\n const rowDecoder = jsonPayloadCodec.createDecoder((row) =>\n this.handleRow(row),\n );\n this.value = this.chunkPromise(this.getChunk(0)) as Promise<AwaitedFigNode>;\n\n void this.ingest(stream, rowDecoder);\n\n const signal = options.signal;\n if (signal !== undefined) {\n if (signal.aborted) {\n this.abort(signal.reason);\n } else {\n const onAbort = () => this.abort(signal.reason);\n signal.addEventListener(\"abort\", onAbort, { once: true });\n this.removeAbortListener = () =>\n signal.removeEventListener(\"abort\", onAbort);\n }\n }\n }\n\n abort(reason?: unknown): void {\n if (this.done) return;\n const error = new PayloadDecodeAbortedError(reason);\n this.gateRelease.resolve(undefined);\n void this.reader?.cancel(error).catch(noop);\n this.rejectUnresolved(error);\n this.settle({ status: \"aborted\" });\n }\n\n private async ingest(\n stream: ReadableStream<Uint8Array>,\n rowDecoder: PayloadRowDecoder,\n ): Promise<void> {\n const reader = stream.getReader();\n this.reader = reader;\n\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (this.done) return;\n if (done) break;\n rowDecoder.decode(value);\n }\n rowDecoder.flush();\n this.finishIngestion();\n } catch (error) {\n if (this.done) return;\n void reader.cancel(error).catch(noop);\n this.failIngestion(error);\n }\n }\n\n private finishIngestion(): void {\n for (const chunk of this.chunks.values()) {\n if (!chunk.arrived) {\n // The server closes the stream only after every outlined row has\n // been written, so any unresolved reference is truncation.\n this.failIngestion(\n new Error(\"Payload stream ended before all referenced rows arrived.\"),\n );\n return;\n }\n }\n this.settle({ status: \"complete\" });\n }\n\n private failIngestion(error: unknown): void {\n if (this.done) return;\n this.rejectUnresolved(error);\n this.settle({ status: \"failed\", error });\n }\n\n private rejectUnresolved(error: unknown): void {\n for (const [id, chunk] of this.chunks) {\n if (chunk.arrived) continue;\n chunk.arrived = true;\n this.rejectChunk(id, chunk, error);\n }\n }\n\n private settle(result: PayloadDecodeCompletion): void {\n if (this.done) return;\n this.done = true;\n this.removeAbortListener();\n notifyObserver(this.options.onStreamDone, result);\n }\n\n private handleRow(row: PayloadRow): void {\n if (this.done) return;\n\n switch (row.tag) {\n case \"model\": {\n const chunk = this.getChunk(row.id);\n let decoded = this.decodeModel(row.value);\n const retainedAssets = this.rowAssets.get(row.id);\n if (retainedAssets !== undefined) {\n this.rowAssets.delete(row.id);\n decoded = attachAssets(retainedAssets, decoded as FigNode);\n }\n chunk.arrived = true;\n const gates = this.rowGates.get(row.id);\n if (gates === undefined) {\n this.fulfillChunk(chunk, decoded);\n return;\n }\n this.rowGates.delete(row.id);\n void Promise.race([Promise.all(gates), this.gateRelease.promise]).then(\n () => this.fulfillChunk(chunk, decoded),\n );\n return;\n }\n case \"client\": {\n const chunk = this.getChunk(row.id);\n const reference: PayloadClientReference = { id: row.value.id };\n if (row.value.exportName !== undefined) {\n reference.exportName = row.value.exportName;\n }\n if (row.value.ssr === true) reference.ssr = true;\n const assets = decodeAssetResources(row.value.assets);\n if (assets !== null) {\n reference.assets = assets;\n }\n const retainedAssets = this.retainedAssets(assets);\n const gate = this.prepareAssets(assets);\n const component = this.clientReferences.register(\n row.id,\n reference,\n gate,\n retainedAssets,\n );\n chunk.arrived = true;\n this.fulfillChunk(chunk, component);\n return;\n }\n case \"error\": {\n const chunk = this.getChunk(row.id);\n chunk.arrived = true;\n // Reveal-gating a failure is pointless; drop any gates aimed here.\n this.rowGates.delete(row.id);\n this.rowAssets.delete(row.id);\n this.rejectChunk(row.id, chunk, errorFromPayloadValue(row.value));\n return;\n }\n case \"data\": {\n const hydrate = this.options.hydrate;\n if (hydrate === undefined) return;\n hydrate(decodePayloadDataEntries(row.value));\n return;\n }\n case \"assets\": {\n const decodedAssets = decodeAssetResources(row.value);\n const retainedAssets = this.retainedAssets(decodedAssets);\n if (retainedAssets !== null && row.for !== undefined) {\n const retained = this.rowAssets.get(row.for);\n if (retained === undefined)\n this.rowAssets.set(row.for, retainedAssets);\n else retained.push(...retainedAssets);\n }\n const gate = this.prepareAssets(decodedAssets);\n if (gate === null || row.for === undefined) return;\n const gates = this.rowGates.get(row.for);\n if (gates === undefined) this.rowGates.set(row.for, [gate]);\n else gates.push(gate);\n return;\n }\n }\n }\n\n // Never rejects and never blocks content on a failed asset: a rejected\n // prepareAssets result (or synchronous throw) settles the gate.\n private prepareAssets(\n assets: readonly FigAssetResource[] | null,\n ): Promise<void> | null {\n const prepare = this.options.prepareAssets;\n if (prepare === undefined || assets === null) return null;\n const delivery = assets.filter(\n (resource) => assetResourceDestination(resource) === \"stream\",\n );\n if (delivery.length === 0) return null;\n\n let result: void | PromiseLike<void>;\n try {\n result = prepare(delivery);\n } catch {\n return null;\n }\n if (!isThenable(result)) return null;\n const gate = Promise.resolve(result).then(noop, noop);\n trackThenable(gate);\n return gate;\n }\n\n private retainedAssets(\n assets: FigAssetResource[] | null,\n ): FigAssetResource[] | null {\n if (assets === null) return null;\n const retained =\n this.options.retainAssets === true\n ? assets\n : assets.filter(\n (resource) => assetResourceDestination(resource) === \"head\",\n );\n return retained.length === 0 ? null : retained;\n }\n\n private getChunk(id: number): DecodeChunk {\n const existing = this.chunks.get(id);\n if (existing !== undefined) return existing;\n\n const chunk: DecodeChunk = {\n arrived: false,\n promise: null,\n reject: null,\n resolve: null,\n result: { status: \"pending\" },\n };\n this.chunks.set(id, chunk);\n return chunk;\n }\n\n // Materializes (and registers with the thenable registry) on first access:\n // a settled chunk becomes an already-settled promise, a pending one gets\n // live resolvers that fulfillChunk/rejectChunk drive.\n private chunkPromise(chunk: DecodeChunk): Promise<unknown> {\n if (chunk.promise !== null) return chunk.promise;\n\n if (chunk.result.status === \"fulfilled\") {\n chunk.promise = Promise.resolve(chunk.result.value);\n } else if (chunk.result.status === \"rejected\") {\n chunk.promise = Promise.reject(chunk.result.error);\n // Holes nobody awaits must not become unhandled rejections; readers\n // still observe the stored error.\n void chunk.promise.catch(noop);\n } else {\n chunk.promise = new Promise((resolve, reject) => {\n chunk.resolve = resolve;\n chunk.reject = reject;\n });\n }\n trackThenable(chunk.promise);\n return chunk.promise;\n }\n\n private fulfillChunk(chunk: DecodeChunk, value: unknown): void {\n if (chunk.result.status !== \"pending\") return;\n chunk.result = { status: \"fulfilled\", value };\n chunk.resolve?.(value);\n chunk.resolve = null;\n chunk.reject = null;\n }\n\n private rejectChunk(id: number, chunk: DecodeChunk, error: unknown): void {\n if (chunk.result.status !== \"pending\") return;\n chunk.result = { error, status: \"rejected\" };\n if (chunk.reject !== null) {\n chunk.reject(error);\n void chunk.promise?.catch(noop);\n }\n chunk.resolve = null;\n chunk.reject = null;\n if (id !== 0 && !(error instanceof PayloadDecodeAbortedError)) {\n notifyObserver(this.options.onHoleError, error);\n }\n }\n\n readChunkForRender(id: number): unknown {\n const chunk = this.getChunk(id);\n if (chunk.result.status === \"rejected\") throw chunk.result.error;\n if (chunk.result.status === \"pending\")\n return readPromise(this.chunkPromise(chunk));\n return chunk.result.value;\n }\n\n private decodeModel(model: PayloadModel): unknown {\n if (model === null) return null;\n if (Array.isArray(model)) return model.map(this.decodeChild);\n if (typeof model !== \"object\") return model;\n\n if (isPayloadSpecialModel(model)) return this.decodeSpecialModel(model);\n\n return decodePayloadRecord(model, this.decodeChild);\n }\n\n private decodeSpecialModel(\n model: PayloadElementModel | PayloadSpecialModel,\n ): unknown {\n switch (model.$fig) {\n case \"element\": {\n if (model.id !== undefined) {\n return this.defineObjectRef(\n model.id,\n (): DecodingElement => ({\n $$typeof: FigElementSymbol,\n key: model.key,\n props: {},\n type: Fragment,\n }),\n (element) => {\n element.type = this.decodeElementType(model.type);\n const props = this.decodeModel(model.props) as Props;\n element.props = props;\n this.attachElementDelivery(model.type, props);\n },\n );\n }\n const type = this.decodeElementType(model.type);\n const props = this.decodeModel(model.props) as Props & {\n key?: Key | null;\n };\n if (model.key !== null) props.key = model.key;\n const element = createElement(type, props);\n // createElement copies props, so the gate keys the element's own\n // props object — the one the component will receive.\n this.attachElementDelivery(model.type, element.props);\n return element;\n }\n case \"client\": {\n const chunk = this.chunks.get(model.id);\n if (chunk === undefined || chunk.result.status !== \"fulfilled\") {\n throw new Error(\n `Payload model referenced client row ${model.id} before it arrived.`,\n );\n }\n return chunk.result.value;\n }\n case \"fragment\":\n return Fragment;\n case \"lazy\":\n // Materialize the hole's chunk now: abort and truncation reject\n // every unresolved chunk, which must include holes that decoded but\n // were never read.\n this.getChunk(model.id);\n return createElement(PayloadHole, { decode: this, id: model.id });\n case \"promise\":\n // Promise props are handed straight to consumers, so the promise\n // (and its thenable-registry tracking) materializes here.\n return this.chunkPromise(this.getChunk(model.id));\n case \"suspense\":\n return Suspense;\n case \"view-transition\":\n return ViewTransition;\n default:\n // Every remaining tag is an ordinary value tag; the shared codec\n // decoder handles it against this decode's request-wide ref store.\n return decodePayloadValueTag(model, this.valueRefs, this.decodeChild);\n }\n }\n\n private decodeElementType(\n type: string | PayloadSpecialModel,\n ): ElementType<any> {\n if (typeof type === \"string\") return type;\n return this.decodeSpecialModel(type) as ElementType<any>;\n }\n\n // A client-referencing element inherits its decode's unsettled row gate;\n // the reference wrapper reads it per element instance at render.\n private attachElementDelivery(\n typeModel: string | PayloadSpecialModel,\n props: Props,\n ): void {\n if (typeof typeModel === \"string\" || typeModel.$fig !== \"client\") return;\n this.clientReferences.attach(typeModel.id, props);\n }\n\n private defineObjectRef<T>(\n id: number,\n create: () => T,\n fill: (value: T) => void,\n ): T {\n if (this.objectRefs.has(id)) return this.objectRefs.get(id) as T;\n\n const value = create();\n this.objectRefs.set(id, value);\n try {\n fill(value);\n return value;\n } catch (error) {\n this.objectRefs.delete(id);\n throw error;\n }\n }\n}\n\nfunction PayloadHole(props: { decode: PayloadDecoder; id: number }): FigNode {\n return props.decode.readChunkForRender(props.id) as FigNode;\n}\n"],"mappings":";;;;AAqCA,MAAM,kCAAkB,IAAI,QAG1B;AAEF,SAAgB,qCACd,SACgC;CAChC,MAAM,0BAAU,IAAI,IAA8B;CAClD,MAAM,WAAW,OAAO,QACrB,cAAsC,QAAQ,SAAS,GACxD;EACE,aAAmB,QAAQ,MAAM;EACjC,SAAS,OAAwB,QAAQ,OAAO,EAAE;CACpD,CACF;CACA,gBAAgB,IAAI,UAAU,OAAO;CACrC,OAAO;AACT;AASA,MAAM,kCAAkB,IAAI,QAAgC;;AAG5D,IAAa,0BAAb,MAAqC;CAGN;CAF7B,uBAAwB,IAAI,IAA6B;CAEzD,YAAY,SAAmD;EAAlC,KAAA,UAAA;CAAmC;CAEhE,SACE,OACA,WACA,MACA,QACkB;EAClB,MAAM,cAAc,SAAS,QAAQ,WAAW;EAChD,IAAI,aAAa;GACf,MAAM,WAA4B,CAAC;GACnC,IAAI,SAAS,MAAM,SAAS,OAAO;GACnC,IAAI,WAAW,MAAM,SAAS,SAAS;GACvC,KAAK,KAAK,IAAI,OAAO,QAAQ;GAE7B,IAAI,SAAS,MACX,KAAU,WAAW;IACnB,OAAO,SAAS;IAChB,IAAI,SAAS,WAAW,KAAA,GAAW,KAAK,KAAK,OAAO,KAAK;GAC3D,CAAC;EAEL;EAEA,OAAO,KAAK,iBAAiB,WAAW,WAAW;CACrD;CAEA,OAAO,OAAe,OAAoB;EACxC,MAAM,WAAW,KAAK,KAAK,IAAI,KAAK;EACpC,IAAI,aAAa,KAAA,GAAW,gBAAgB,IAAI,OAAO,QAAQ;CACjE;CAEA,iBACE,WACA,aACkB;EAClB,MAAM,UACJ,KAAK,YAAY,KAAA,IACb,KAAA,IACA,gBAAgB,IAAI,KAAK,OAAO;EACtC,MAAM,WAAW,SAAS,IAAI,UAAU,EAAE;EAC1C,IAAI,aAAa,KAAA,GAAW,OAAO;EAEnC,IAAI;EAC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E;EAE1D,MAAM,QAAQ,OAAO;EACrB,KAAK,WAAW,IAAI,IAAI,KAAK;EAC7B,IAAI;GACF,KAAK,KAAK;GACV,OAAO;EACT,SAAS,OAAO;GACd,KAAK,WAAW,OAAO,EAAE;GACzB,MAAM;EACR;CACF;AACF;AAEA,SAAS,YAAY,OAAwD;CAC3E,OAAO,MAAM,OAAO,mBAAmB,MAAM,EAAE;AACjD"}
|
|
1
|
+
{"version":3,"file":"payload.js","names":["attachAssets","attachAssets"],"sources":["../src/payload-client-reference.ts","../src/payload.ts"],"sourcesContent":["import {\n createElement,\n type ElementType,\n type FigNode,\n type Props,\n} from \"./element.ts\";\nimport { readPromise } from \"./hooks.ts\";\nimport { assets as attachAssets, type FigAssetResource } from \"./resource.ts\";\nimport { isThenable, trackThenable } from \"./thenables.ts\";\n\n/** Describes payload client reference. */\nexport interface PayloadClientReference {\n assets?: readonly FigAssetResource[];\n exportName?: string;\n id: string;\n ssr?: boolean;\n}\n\n/** Describes resolve client reference. */\nexport type ResolveClientReference = (\n reference: PayloadClientReference,\n) => ElementType<any> | PromiseLike<ElementType<any>> | undefined;\n\n/**\n * A caller-owned stateful resolver: a `ResolveClientReference` that also\n * owns component identity. Decodes given one (as `resolveClientReference`)\n * resolve every client reference to a single resolver-owned wrapper per\n * reference id, so re-decoding a payload updates islands in place instead\n * of remounting them. The caller owns the lifetime: drop entries when their\n * modules change (HMR) or the manifest swaps.\n */\nexport interface PayloadClientReferenceResolver {\n (\n reference: PayloadClientReference,\n ): ElementType<any> | PromiseLike<ElementType<any>> | undefined;\n clear(): void;\n delete(id: string): boolean;\n}\n\nconst resolverEntries = new WeakMap<\n ResolveClientReference,\n Map<string, ElementType<any>>\n>();\n\n/** Creates payload client reference resolver. */\nexport function createPayloadClientReferenceResolver(\n resolve: ResolveClientReference,\n): PayloadClientReferenceResolver {\n const entries = new Map<string, ElementType<any>>();\n const resolver = Object.assign(\n (reference: PayloadClientReference) => resolve(reference),\n {\n clear: (): void => entries.clear(),\n delete: (id: string): boolean => entries.delete(id),\n },\n );\n resolverEntries.set(resolver, entries);\n return resolver;\n}\n\ninterface ElementDelivery {\n assets?: readonly FigAssetResource[];\n gate?: Promise<void>;\n}\n\n// Delivery belongs to the decoded element, not its stable component type. A\n// newer decode therefore cannot re-suspend an already-mounted island.\nconst elementDelivery = new WeakMap<Props, ElementDelivery>();\n\n/** Owns client-reference identity and per-decode delivery state. */\nexport class PayloadClientReferences {\n private readonly rows = new Map<number, ElementDelivery>();\n\n constructor(private readonly resolve?: ResolveClientReference) {}\n\n register(\n rowId: number,\n reference: PayloadClientReference,\n gate: Promise<void> | null,\n assets: readonly FigAssetResource[] | null,\n ): ElementType<any> {\n const hasDelivery = gate !== null || assets !== null;\n if (hasDelivery) {\n const delivery: ElementDelivery = {};\n if (gate !== null) delivery.gate = gate;\n if (assets !== null) delivery.assets = assets;\n this.rows.set(rowId, delivery);\n\n if (gate !== null) {\n void gate.then(() => {\n delete delivery.gate;\n if (delivery.assets === undefined) this.rows.delete(rowId);\n });\n }\n }\n\n return this.resolveComponent(reference, hasDelivery);\n }\n\n attach(rowId: number, props: Props): void {\n const delivery = this.rows.get(rowId);\n if (delivery !== undefined) elementDelivery.set(props, delivery);\n }\n\n private resolveComponent(\n reference: PayloadClientReference,\n hasDelivery: boolean,\n ): ElementType<any> {\n const entries =\n this.resolve === undefined\n ? undefined\n : resolverEntries.get(this.resolve);\n const existing = entries?.get(reference.id);\n if (existing !== undefined) return existing;\n\n let resolved: ReturnType<ResolveClientReference>;\n try {\n resolved = this.resolve?.(reference);\n } catch (error) {\n resolved = Promise.reject(error);\n }\n\n if (resolved === undefined) {\n // Never cache a missing manifest entry: a later decode may resolve it.\n return function PayloadUnresolvedClientComponent(): never {\n throw new Error(\n `Cannot render client reference \"${reference.id}\" because decodePayloadStream was not configured with a matching resolveClientReference.`,\n );\n };\n }\n\n // A direct synchronous component needs no wrapper when identity does not\n // need resolver ownership and this decode has no delivery state.\n if (entries === undefined && !isThenable(resolved) && !hasDelivery) {\n return resolved;\n }\n\n const component = clientReferenceWrapper(resolved, reference.id);\n entries?.set(reference.id, component);\n return component;\n }\n}\n\nfunction clientReferenceWrapper(\n resolved: ElementType<any> | PromiseLike<ElementType<any>>,\n referenceId: string,\n): ElementType<any> {\n let render: (props: Props) => FigNode;\n if (isThenable(resolved)) {\n const pending = Promise.resolve(resolved);\n trackThenable(pending);\n let type: ElementType<any> | null = null;\n render = (props) => {\n type ??= clientReferenceType(readPromise(pending), referenceId);\n return createElement(type, props);\n };\n } else {\n render = (props) => createElement(resolved, props);\n }\n\n function PayloadClientContent(content: {\n gate?: Promise<void>;\n props: Props;\n }): FigNode {\n if (content.gate !== undefined) readPromise(content.gate);\n return render(content.props);\n }\n\n return function PayloadClientComponent(props: Props): FigNode {\n const delivery = elementDelivery.get(props);\n const content = createElement(PayloadClientContent, {\n gate: delivery?.gate,\n props,\n });\n return delivery?.assets === undefined\n ? content\n : attachAssets(delivery.assets, content);\n };\n}\n\nfunction clientReferenceType(value: unknown, id: string): ElementType<any> {\n if (typeof value === \"function\") return value as ElementType<any>;\n throw new Error(`Client reference \"${id}\" did not resolve to a component.`);\n}\n","/**\n * Client-side decoding and reference types for Fig's server-component payload.\n *\n * @module\n */\nimport type { FigDataHydrationEntry } from \"./data.ts\";\nimport {\n type AwaitedFigNode,\n createElement,\n type ElementType,\n FigElementSymbol,\n type FigNode,\n Fragment,\n type Key,\n type Props,\n Suspense,\n ViewTransition,\n} from \"./element.ts\";\nimport { readPromise } from \"./hooks.ts\";\nimport {\n createPayloadClientReferenceResolver,\n type PayloadClientReference,\n type PayloadClientReferenceResolver,\n PayloadClientReferences,\n type ResolveClientReference,\n} from \"./payload-client-reference.ts\";\nimport {\n decodePayloadDataEntries,\n decodePayloadRecord,\n decodePayloadValueTag,\n errorFromPayloadValue,\n isPayloadSpecialModel,\n jsonPayloadCodec,\n type PayloadDecodeRefs,\n type PayloadElementModel,\n type PayloadModel,\n type PayloadRow,\n type PayloadRowDecoder,\n type PayloadSpecialModel,\n type SerializedAssetResource,\n} from \"./payload-format.ts\";\nimport {\n assetResourceDestination,\n assets as attachAssets,\n type FigAssetResource,\n isFigAssetResource,\n} from \"./resource.ts\";\nimport { isThenable, trackThenable } from \"./thenables.ts\";\n\nexport {\n createPayloadClientReferenceResolver,\n type PayloadClientReference,\n type PayloadClientReferenceResolver,\n type ResolveClientReference,\n};\n\n/** Describes payload decode completion. */\nexport type PayloadDecodeCompletion =\n | { status: \"aborted\" }\n | { status: \"complete\" }\n | { status: \"failed\"; error: unknown };\n\n/** Describes payload decode options. */\nexport interface PayloadDecodeOptions {\n /**\n * Receives decoded `data` rows for hydration into a data store. The\n * capability itself is expected to be generation-guarded and to ignore\n * entries after its caller loses authority.\n */\n hydrate?: (entries: readonly FigDataHydrationEntry[]) => void;\n /**\n * Observes every outlined hole rejection — an `error` row or a stream\n * failure stranding referenced rows, before or after the root fulfills.\n * Abort cancellation is excluded. Called once per rejected hole; the\n * observer is never awaited and cannot break decoding.\n */\n onHoleError?: (error: unknown) => unknown;\n /**\n * Observes the end of ingestion: called exactly once when the stream\n * settles as complete, failed, or aborted. Post-root failures reject the\n * holes they strand, but a failure with no pending slot is otherwise\n * invisible — this is the hook for reporting it. The callback is never\n * awaited, and its exceptions and rejections are swallowed, so an\n * observer cannot block or break decode teardown.\n */\n onStreamDone?: (result: PayloadDecodeCompletion) => unknown;\n /**\n * Called with delivery asset resources as soon as their rows arrive\n * (e.g. fig-dom's insertAssetResources). A returned promise gates the\n * reveal of only the content that declared a dependency on those assets;\n * gate settlement — fulfilled or rejected — releases the reveal, so a\n * failed asset never blocks content.\n */\n prepareAssets?: (\n assets: readonly FigAssetResource[],\n ) => void | PromiseLike<void>;\n /**\n * Retains delivery asset dependencies as `assets(...)` declarations on\n * their decoded owners. Document metadata is always retained because its\n * owner may mutate the document only when it commits. Server document\n * renderers enable this option to retain delivery assets too.\n */\n retainAssets?: boolean;\n /**\n * Resolves client-reference rows to components. A plain function keeps\n * identity per decode: gated and asynchronously resolved references decode\n * to per-decode wrappers and remount on re-decode. A stateful resolver\n * (created by `createPayloadClientReferenceResolver`) keeps every\n * resolvable reference's identity stable across the decodes sharing it.\n */\n resolveClientReference?: ResolveClientReference;\n signal?: AbortSignal;\n}\n\nclass PayloadDecodeAbortedError extends Error {\n constructor(reason?: unknown) {\n super(\n \"Payload decode aborted.\",\n reason === undefined ? undefined : { cause: reason },\n );\n this.name = \"PayloadDecodeAbortedError\";\n }\n}\n\n/**\n * Decode a payload row stream. The returned promise resolves with the\n * decoded root FigNode as soon as the root row decodes (and rejects only\n * when the stream fails before producing a root value, or with the root\n * row's own error); decoding continues in the background, filling outlined\n * holes as their rows arrive. Post-root failures reject the holes they\n * strand and report through `onStreamDone`. Aborting `options.signal`\n * ignores remaining rows and rejects unresolved holes with an internal\n * cancellation reason.\n */\nexport function decodePayloadStream(\n stream: ReadableStream<Uint8Array>,\n options: PayloadDecodeOptions = {},\n): Promise<AwaitedFigNode> {\n return new PayloadDecoder(stream, options).value;\n}\n\ntype DecodeChunk = {\n // The chunk's row has been ingested (decoded or rejected); reveal may still\n // be waiting on an asset gate. Truncation and abort reject only chunks\n // whose rows never arrived.\n arrived: boolean;\n // Materialized lazily: most rows settle synchronously at arrival and are\n // only ever read through result, so eagerly allocating a promise and\n // its controls per row would be waste.\n promise: Promise<unknown> | null;\n reject: ((reason: unknown) => void) | null;\n resolve: ((value: unknown) => void) | null;\n result:\n | { status: \"pending\" }\n | { status: \"fulfilled\"; value: unknown }\n | { status: \"rejected\"; error: unknown };\n};\n\ntype DecodingElement = {\n $$typeof: symbol;\n key: Key | null;\n props: Props;\n type: ElementType<any>;\n};\n\nconst noop = (): void => undefined;\n\nfunction notifyObserver<T>(\n observer: ((value: T) => unknown) | undefined,\n value: T,\n): void {\n try {\n const result = observer?.(value);\n if (isThenable(result)) void Promise.resolve(result).then(noop, noop);\n } catch {\n // Observers cannot break decode teardown or create unhandled rejections.\n }\n}\n\ninterface Deferred<T> {\n promise: Promise<T>;\n reject: (reason: unknown) => void;\n resolve: (value: T) => void;\n}\n\nfunction deferred<T>(): Deferred<T> {\n let resolve: Deferred<T>[\"resolve\"] = noop;\n let reject: Deferred<T>[\"reject\"] = noop;\n const promise = new Promise<T>((innerResolve, innerReject) => {\n resolve = innerResolve;\n reject = innerReject;\n });\n return { promise, reject, resolve };\n}\n\nfunction decodeAssetResources(\n serialized: readonly SerializedAssetResource[] | undefined,\n): FigAssetResource[] | null {\n if (serialized === undefined) return null;\n const assets = serialized.filter(isFigAssetResource);\n return assets.length === 0 ? null : assets;\n}\n\nclass PayloadDecoder {\n readonly value: Promise<AwaitedFigNode>;\n\n private readonly chunks = new Map<number, DecodeChunk>();\n private readonly objectRefs = new Map<number, unknown>();\n // Asset gates registered for a row id (assets rows carry `for`); consumed\n // when that row arrives.\n private readonly rowGates = new Map<number, Array<PromiseLike<void>>>();\n private readonly rowAssets = new Map<number, FigAssetResource[]>();\n private readonly clientReferences: PayloadClientReferences;\n private reader: ReadableStreamDefaultReader<Uint8Array> | null = null;\n private done = false;\n // Resolved on abort so arrived-but-gated chunks reveal instead of waiting\n // for asset gates that may never settle.\n private readonly gateRelease = deferred<void>();\n private removeAbortListener: () => void = noop;\n // One closure and one refs adapter reused across every decoded model, so\n // the per-node decode loop allocates only the decoded values themselves.\n private readonly decodeChild = (model: PayloadModel): unknown =>\n this.decodeModel(model);\n private readonly valueRefs: PayloadDecodeRefs = {\n define: (id, create, fill) => this.defineObjectRef(id, create, fill),\n read: (id) => {\n if (!this.objectRefs.has(id)) {\n throw new Error(`Payload referenced unknown object id ${id}.`);\n }\n return this.objectRefs.get(id);\n },\n };\n\n constructor(\n stream: ReadableStream<Uint8Array>,\n private readonly options: PayloadDecodeOptions,\n ) {\n this.clientReferences = new PayloadClientReferences(\n options.resolveClientReference,\n );\n const rowDecoder = jsonPayloadCodec.createDecoder((row) =>\n this.handleRow(row),\n );\n this.value = this.chunkPromise(this.getChunk(0)) as Promise<AwaitedFigNode>;\n\n void this.ingest(stream, rowDecoder);\n\n const signal = options.signal;\n if (signal !== undefined) {\n if (signal.aborted) {\n this.abort(signal.reason);\n } else {\n const onAbort = () => this.abort(signal.reason);\n signal.addEventListener(\"abort\", onAbort, { once: true });\n this.removeAbortListener = () =>\n signal.removeEventListener(\"abort\", onAbort);\n }\n }\n }\n\n abort(reason?: unknown): void {\n if (this.done) return;\n const error = new PayloadDecodeAbortedError(reason);\n this.gateRelease.resolve(undefined);\n void this.reader?.cancel(error).catch(noop);\n this.rejectUnresolved(error);\n this.settle({ status: \"aborted\" });\n }\n\n private async ingest(\n stream: ReadableStream<Uint8Array>,\n rowDecoder: PayloadRowDecoder,\n ): Promise<void> {\n const reader = stream.getReader();\n this.reader = reader;\n\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (this.done) return;\n if (done) break;\n rowDecoder.decode(value);\n }\n rowDecoder.flush();\n this.finishIngestion();\n } catch (error) {\n if (this.done) return;\n void reader.cancel(error).catch(noop);\n this.failIngestion(error);\n }\n }\n\n private finishIngestion(): void {\n for (const chunk of this.chunks.values()) {\n if (!chunk.arrived) {\n // The server closes the stream only after every outlined row has\n // been written, so any unresolved reference is truncation.\n this.failIngestion(\n new Error(\"Payload stream ended before all referenced rows arrived.\"),\n );\n return;\n }\n }\n this.settle({ status: \"complete\" });\n }\n\n private failIngestion(error: unknown): void {\n if (this.done) return;\n this.rejectUnresolved(error);\n this.settle({ status: \"failed\", error });\n }\n\n private rejectUnresolved(error: unknown): void {\n for (const [id, chunk] of this.chunks) {\n if (chunk.arrived) continue;\n chunk.arrived = true;\n this.rejectChunk(id, chunk, error);\n }\n }\n\n private settle(result: PayloadDecodeCompletion): void {\n if (this.done) return;\n this.done = true;\n this.removeAbortListener();\n notifyObserver(this.options.onStreamDone, result);\n }\n\n private handleRow(row: PayloadRow): void {\n if (this.done) return;\n\n switch (row.tag) {\n case \"model\": {\n const chunk = this.getChunk(row.id);\n let decoded = this.decodeModel(row.value);\n const retainedAssets = this.rowAssets.get(row.id);\n if (retainedAssets !== undefined) {\n this.rowAssets.delete(row.id);\n decoded = attachAssets(retainedAssets, decoded as FigNode);\n }\n chunk.arrived = true;\n const gates = this.rowGates.get(row.id);\n if (gates === undefined) {\n this.fulfillChunk(chunk, decoded);\n return;\n }\n this.rowGates.delete(row.id);\n void Promise.race([Promise.all(gates), this.gateRelease.promise]).then(\n () => this.fulfillChunk(chunk, decoded),\n );\n return;\n }\n case \"client\": {\n const chunk = this.getChunk(row.id);\n const reference: PayloadClientReference = { id: row.value.id };\n if (row.value.exportName !== undefined) {\n reference.exportName = row.value.exportName;\n }\n if (row.value.ssr === true) reference.ssr = true;\n const assets = decodeAssetResources(row.value.assets);\n if (assets !== null) {\n reference.assets = assets;\n }\n const retainedAssets = this.retainedAssets(assets);\n const gate = this.prepareAssets(assets);\n const component = this.clientReferences.register(\n row.id,\n reference,\n gate,\n retainedAssets,\n );\n chunk.arrived = true;\n this.fulfillChunk(chunk, component);\n return;\n }\n case \"error\": {\n const chunk = this.getChunk(row.id);\n chunk.arrived = true;\n // Reveal-gating a failure is pointless; drop any gates aimed here.\n this.rowGates.delete(row.id);\n this.rowAssets.delete(row.id);\n this.rejectChunk(row.id, chunk, errorFromPayloadValue(row.value));\n return;\n }\n case \"data\": {\n const hydrate = this.options.hydrate;\n if (hydrate === undefined) return;\n hydrate(decodePayloadDataEntries(row.value));\n return;\n }\n case \"assets\": {\n const decodedAssets = decodeAssetResources(row.value);\n const retainedAssets = this.retainedAssets(decodedAssets);\n if (retainedAssets !== null && row.for !== undefined) {\n const retained = this.rowAssets.get(row.for);\n if (retained === undefined)\n this.rowAssets.set(row.for, retainedAssets);\n else retained.push(...retainedAssets);\n }\n const gate = this.prepareAssets(decodedAssets);\n if (gate === null || row.for === undefined) return;\n const gates = this.rowGates.get(row.for);\n if (gates === undefined) this.rowGates.set(row.for, [gate]);\n else gates.push(gate);\n return;\n }\n }\n }\n\n // Never rejects and never blocks content on a failed asset: a rejected\n // prepareAssets result (or synchronous throw) settles the gate.\n private prepareAssets(\n assets: readonly FigAssetResource[] | null,\n ): Promise<void> | null {\n const prepare = this.options.prepareAssets;\n if (prepare === undefined || assets === null) return null;\n const delivery = assets.filter(\n (resource) => assetResourceDestination(resource) === \"stream\",\n );\n if (delivery.length === 0) return null;\n\n let result: void | PromiseLike<void>;\n try {\n result = prepare(delivery);\n } catch {\n return null;\n }\n if (!isThenable(result)) return null;\n const gate = Promise.resolve(result).then(noop, noop);\n trackThenable(gate);\n return gate;\n }\n\n private retainedAssets(\n assets: FigAssetResource[] | null,\n ): FigAssetResource[] | null {\n if (assets === null) return null;\n const retained =\n this.options.retainAssets === true\n ? assets\n : assets.filter(\n (resource) => assetResourceDestination(resource) === \"head\",\n );\n return retained.length === 0 ? null : retained;\n }\n\n private getChunk(id: number): DecodeChunk {\n const existing = this.chunks.get(id);\n if (existing !== undefined) return existing;\n\n const chunk: DecodeChunk = {\n arrived: false,\n promise: null,\n reject: null,\n resolve: null,\n result: { status: \"pending\" },\n };\n this.chunks.set(id, chunk);\n return chunk;\n }\n\n // Materializes (and registers with the thenable registry) on first access:\n // a settled chunk becomes an already-settled promise, a pending one gets\n // live resolvers that fulfillChunk/rejectChunk drive.\n private chunkPromise(chunk: DecodeChunk): Promise<unknown> {\n if (chunk.promise !== null) return chunk.promise;\n\n if (chunk.result.status === \"fulfilled\") {\n chunk.promise = Promise.resolve(chunk.result.value);\n } else if (chunk.result.status === \"rejected\") {\n chunk.promise = Promise.reject(chunk.result.error);\n // Holes nobody awaits must not become unhandled rejections; readers\n // still observe the stored error.\n void chunk.promise.catch(noop);\n } else {\n chunk.promise = new Promise((resolve, reject) => {\n chunk.resolve = resolve;\n chunk.reject = reject;\n });\n }\n trackThenable(chunk.promise);\n return chunk.promise;\n }\n\n private fulfillChunk(chunk: DecodeChunk, value: unknown): void {\n if (chunk.result.status !== \"pending\") return;\n chunk.result = { status: \"fulfilled\", value };\n chunk.resolve?.(value);\n chunk.resolve = null;\n chunk.reject = null;\n }\n\n private rejectChunk(id: number, chunk: DecodeChunk, error: unknown): void {\n if (chunk.result.status !== \"pending\") return;\n chunk.result = { error, status: \"rejected\" };\n if (chunk.reject !== null) {\n chunk.reject(error);\n void chunk.promise?.catch(noop);\n }\n chunk.resolve = null;\n chunk.reject = null;\n if (id !== 0 && !(error instanceof PayloadDecodeAbortedError)) {\n notifyObserver(this.options.onHoleError, error);\n }\n }\n\n readChunkForRender(id: number): unknown {\n const chunk = this.getChunk(id);\n if (chunk.result.status === \"rejected\") throw chunk.result.error;\n if (chunk.result.status === \"pending\")\n return readPromise(this.chunkPromise(chunk));\n return chunk.result.value;\n }\n\n private decodeModel(model: PayloadModel): unknown {\n if (model === null) return null;\n if (Array.isArray(model)) return model.map(this.decodeChild);\n if (typeof model !== \"object\") return model;\n\n if (isPayloadSpecialModel(model)) return this.decodeSpecialModel(model);\n\n return decodePayloadRecord(model, this.decodeChild);\n }\n\n private decodeSpecialModel(\n model: PayloadElementModel | PayloadSpecialModel,\n ): unknown {\n switch (model.$fig) {\n case \"element\": {\n if (model.id !== undefined) {\n return this.defineObjectRef(\n model.id,\n (): DecodingElement => ({\n $$typeof: FigElementSymbol,\n key: model.key,\n props: {},\n type: Fragment,\n }),\n (element) => {\n element.type = this.decodeElementType(model.type);\n const props = this.decodeModel(model.props) as Props;\n element.props = props;\n this.attachElementDelivery(model.type, props);\n },\n );\n }\n const type = this.decodeElementType(model.type);\n const props = this.decodeModel(model.props) as Props & {\n key?: Key | null;\n };\n if (model.key !== null) props.key = model.key;\n const element = createElement(type, props);\n // createElement copies props, so the gate keys the element's own\n // props object — the one the component will receive.\n this.attachElementDelivery(model.type, element.props);\n return element;\n }\n case \"client\": {\n const chunk = this.chunks.get(model.id);\n if (chunk === undefined || chunk.result.status !== \"fulfilled\") {\n throw new Error(\n `Payload model referenced client row ${model.id} before it arrived.`,\n );\n }\n return chunk.result.value;\n }\n case \"fragment\":\n return Fragment;\n case \"lazy\":\n // Materialize the hole's chunk now: abort and truncation reject\n // every unresolved chunk, which must include holes that decoded but\n // were never read.\n this.getChunk(model.id);\n return createElement(PayloadHole, { decode: this, id: model.id });\n case \"promise\":\n // Promise props are handed straight to consumers, so the promise\n // (and its thenable-registry tracking) materializes here.\n return this.chunkPromise(this.getChunk(model.id));\n case \"suspense\":\n return Suspense;\n case \"view-transition\":\n return ViewTransition;\n default:\n // Every remaining tag is an ordinary value tag; the shared codec\n // decoder handles it against this decode's request-wide ref store.\n return decodePayloadValueTag(model, this.valueRefs, this.decodeChild);\n }\n }\n\n private decodeElementType(\n type: string | PayloadSpecialModel,\n ): ElementType<any> {\n if (typeof type === \"string\") return type;\n return this.decodeSpecialModel(type) as ElementType<any>;\n }\n\n // A client-referencing element inherits its decode's unsettled row gate;\n // the reference wrapper reads it per element instance at render.\n private attachElementDelivery(\n typeModel: string | PayloadSpecialModel,\n props: Props,\n ): void {\n if (typeof typeModel === \"string\" || typeModel.$fig !== \"client\") return;\n this.clientReferences.attach(typeModel.id, props);\n }\n\n private defineObjectRef<T>(\n id: number,\n create: () => T,\n fill: (value: T) => void,\n ): T {\n if (this.objectRefs.has(id)) return this.objectRefs.get(id) as T;\n\n const value = create();\n this.objectRefs.set(id, value);\n try {\n fill(value);\n return value;\n } catch (error) {\n this.objectRefs.delete(id);\n throw error;\n }\n }\n}\n\nfunction PayloadHole(props: { decode: PayloadDecoder; id: number }): FigNode {\n return props.decode.readChunkForRender(props.id) as FigNode;\n}\n"],"mappings":";;;;AAuCA,MAAM,kCAAkB,IAAI,QAG1B;;AAGF,SAAgB,qCACd,SACgC;CAChC,MAAM,0BAAU,IAAI,IAA8B;CAClD,MAAM,WAAW,OAAO,QACrB,cAAsC,QAAQ,SAAS,GACxD;EACE,aAAmB,QAAQ,MAAM;EACjC,SAAS,OAAwB,QAAQ,OAAO,EAAE;CACpD,CACF;CACA,gBAAgB,IAAI,UAAU,OAAO;CACrC,OAAO;AACT;AASA,MAAM,kCAAkB,IAAI,QAAgC;;AAG5D,IAAa,0BA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AK;IACpD,OAAO;GACT;GACA,KAAK,UAAU;IACb,MAAM,QAAQ,KAAK,OAAO,IAAI,MAAM,EAAE;IACtC,IAAI,UAAU,KAAA,KAAa,MAAM,OAAO,WAAW,aACjD,MAAM,IAAI,MACR,uCAAuC,MAAM,GAAG,oBAClD;IAEF,OAAO,MAAM,OAAO;GACtB;GACA,KAAK,YACH,OAAO;GACT,KAAK;IAIH,KAAK,SAAS,MAAM,EAAE;IACtB,OAAO,cAAc,aAAa;KAAE,QAAQ;KAAM,IAAI,MAAM;IAAG,CAAC;GAClE,KAAK,WAGH,OAAO,KAAK,aAAa,KAAK,SAAS,MAAM,EAAE,CAAC;GAClD,KAAK,YACH,OAAO;GACT,KAAK,mBACH,OAAO;GACT,SAGE,OAAO,sBAAsB,OAAO,KAAK,WAAW,KAAK,WAAW;EACxE;CACF;CAEA,kBACE,MACkB;EAClB,IAAI,OAAO,SAAS,UAAU,OAAO;EACrC,OAAO,KAAK,mBAAmB,IAAI;CACrC;CAIA,sBACE,WACA,OACM;EACN,IAAI,OAAO,cAAc,YAAY,UAAU,SAAS,UAAU;EAClE,KAAK,iBAAiB,OAAO,UAAU,IAAI,KAAK;CAClD;CAEA,gBACE,IACA,QACA,MACG;EACH,IAAI,KAAK,WAAW,IAAI,EAAE,GAAG,OAAO,KAAK,WAAW,IAAI,EAAE;EAE1D,MAAM,QAAQ,OAAO;EACrB,KAAK,WAAW,IAAI,IAAI,KAAK;EAC7B,IAAI;GACF,KAAK,KAAK;GACV,OAAO;EACT,SAAS,OAAO;GACd,KAAK,WAAW,OAAO,EAAE;GACzB,MAAM;EACR;CACF;AACF;AAEA,SAAS,YAAY,OAAwD;CAC3E,OAAO,MAAM,OAAO,mBAAmB,MAAM,EAAE;AACjD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as createElement, n as Assets } from "./element-
|
|
1
|
+
import { g as createElement, n as Assets } from "./element-CVlfN_3_.js";
|
|
2
2
|
//#region src/thenables.ts
|
|
3
3
|
const thenableRecords = /* @__PURE__ */ new WeakMap();
|
|
4
4
|
function recordFor(thenable) {
|
|
@@ -23,15 +23,18 @@ function recordFor(thenable) {
|
|
|
23
23
|
}
|
|
24
24
|
return record;
|
|
25
25
|
}
|
|
26
|
+
/** Tracks thenable. */
|
|
26
27
|
function trackThenable(thenable) {
|
|
27
28
|
recordFor(thenable);
|
|
28
29
|
}
|
|
30
|
+
/** Reads thenable. */
|
|
29
31
|
function readThenable(thenable) {
|
|
30
32
|
const record = recordFor(thenable);
|
|
31
33
|
if (record.status === "fulfilled") return record.value;
|
|
32
34
|
if (record.status === "rejected") throw record.reason;
|
|
33
35
|
throw thenable;
|
|
34
36
|
}
|
|
37
|
+
/** Checks whether thenable. */
|
|
35
38
|
function isThenable(value) {
|
|
36
39
|
if (typeof value !== "object" && typeof value !== "function" || value === null) return false;
|
|
37
40
|
return "then" in value && typeof value.then === "function";
|
|
@@ -39,9 +42,11 @@ function isThenable(value) {
|
|
|
39
42
|
//#endregion
|
|
40
43
|
//#region src/resource.ts
|
|
41
44
|
const PreventAssetResourceHoistSymbol = Symbol.for("fig.prevent-asset-resource-hoist");
|
|
45
|
+
/** Assets. */
|
|
42
46
|
function assets(value, children) {
|
|
43
47
|
return createElement(Assets, { assets: value }, children);
|
|
44
48
|
}
|
|
49
|
+
/** Stylesheet. */
|
|
45
50
|
function stylesheet(href, options = {}) {
|
|
46
51
|
return {
|
|
47
52
|
...options,
|
|
@@ -49,6 +54,7 @@ function stylesheet(href, options = {}) {
|
|
|
49
54
|
kind: "stylesheet"
|
|
50
55
|
};
|
|
51
56
|
}
|
|
57
|
+
/** Preload. */
|
|
52
58
|
function preload(href, as, options = {}) {
|
|
53
59
|
return {
|
|
54
60
|
...options,
|
|
@@ -58,6 +64,7 @@ function preload(href, as, options = {}) {
|
|
|
58
64
|
kind: "preload"
|
|
59
65
|
};
|
|
60
66
|
}
|
|
67
|
+
/** Modulepreload. */
|
|
61
68
|
function modulepreload(href, options = {}) {
|
|
62
69
|
return {
|
|
63
70
|
...options,
|
|
@@ -65,6 +72,7 @@ function modulepreload(href, options = {}) {
|
|
|
65
72
|
kind: "modulepreload"
|
|
66
73
|
};
|
|
67
74
|
}
|
|
75
|
+
/** Script. */
|
|
68
76
|
function script(src, options = {}) {
|
|
69
77
|
return {
|
|
70
78
|
...options,
|
|
@@ -72,6 +80,7 @@ function script(src, options = {}) {
|
|
|
72
80
|
src
|
|
73
81
|
};
|
|
74
82
|
}
|
|
83
|
+
/** Font. */
|
|
75
84
|
function font(href, type, options = {}) {
|
|
76
85
|
return {
|
|
77
86
|
...options,
|
|
@@ -80,6 +89,7 @@ function font(href, type, options = {}) {
|
|
|
80
89
|
type
|
|
81
90
|
};
|
|
82
91
|
}
|
|
92
|
+
/** Preconnect. */
|
|
83
93
|
function preconnect(href, options = {}) {
|
|
84
94
|
return {
|
|
85
95
|
...options,
|
|
@@ -87,18 +97,21 @@ function preconnect(href, options = {}) {
|
|
|
87
97
|
kind: "preconnect"
|
|
88
98
|
};
|
|
89
99
|
}
|
|
100
|
+
/** Title. */
|
|
90
101
|
function title(value) {
|
|
91
102
|
return {
|
|
92
103
|
kind: "title",
|
|
93
104
|
value
|
|
94
105
|
};
|
|
95
106
|
}
|
|
107
|
+
/** Meta. */
|
|
96
108
|
function meta(options) {
|
|
97
109
|
return {
|
|
98
110
|
...options,
|
|
99
111
|
kind: "meta"
|
|
100
112
|
};
|
|
101
113
|
}
|
|
114
|
+
/** Checks whether Fig asset resource. */
|
|
102
115
|
function isFigAssetResource(value) {
|
|
103
116
|
if (typeof value !== "object" || value === null || !("kind" in value)) return false;
|
|
104
117
|
switch (value.kind) {
|
|
@@ -113,6 +126,7 @@ function isFigAssetResource(value) {
|
|
|
113
126
|
default: return false;
|
|
114
127
|
}
|
|
115
128
|
}
|
|
129
|
+
/** Client reference assets. */
|
|
116
130
|
function clientReferenceAssets(reference) {
|
|
117
131
|
const value = reference.assets;
|
|
118
132
|
if (value === void 0) return [];
|
|
@@ -120,6 +134,7 @@ function clientReferenceAssets(reference) {
|
|
|
120
134
|
if (isFigAssetResource(list)) return [list];
|
|
121
135
|
return Array.isArray(list) ? list : [];
|
|
122
136
|
}
|
|
137
|
+
/** Asset resource key. */
|
|
123
138
|
function assetResourceKey(resource) {
|
|
124
139
|
if (resource.kind === "title") return "title";
|
|
125
140
|
if (resource.kind === "font" && resource.key !== void 0) return `preload:${resource.key}`;
|
|
@@ -137,13 +152,16 @@ function assetResourceKey(resource) {
|
|
|
137
152
|
case "meta": return metaResourceKey(resource);
|
|
138
153
|
}
|
|
139
154
|
}
|
|
155
|
+
/** Asset resource destination. */
|
|
140
156
|
function assetResourceDestination(resource) {
|
|
141
157
|
return resource.kind === "title" || resource.kind === "meta" ? "head" : "stream";
|
|
142
158
|
}
|
|
159
|
+
/** Asset resource from host props. */
|
|
143
160
|
function assetResourceFromHostProps(type, props) {
|
|
144
161
|
if (props[PreventAssetResourceHoistSymbol] === true) return null;
|
|
145
162
|
return assetResourceFromHostValues(type, (name) => props[name], props.children, true);
|
|
146
163
|
}
|
|
164
|
+
/** Prevent asset resource hoist. */
|
|
147
165
|
function preventAssetResourceHoist(props) {
|
|
148
166
|
Object.defineProperty(props, PreventAssetResourceHoistSymbol, {
|
|
149
167
|
enumerable: true,
|
|
@@ -151,9 +169,11 @@ function preventAssetResourceHoist(props) {
|
|
|
151
169
|
});
|
|
152
170
|
return props;
|
|
153
171
|
}
|
|
172
|
+
/** Asset resource from host attributes. */
|
|
154
173
|
function assetResourceFromHostAttributes(type, getAttribute) {
|
|
155
174
|
return assetResourceFromHostValues(type, getAttribute, void 0, false);
|
|
156
175
|
}
|
|
176
|
+
/** Asset resource host props. */
|
|
157
177
|
function assetResourceHostProps(resource, props = {}) {
|
|
158
178
|
if (resource.kind === "title" || resource.kind === "meta") return props;
|
|
159
179
|
switch (resource.kind) {
|
|
@@ -208,10 +228,10 @@ function assetResourceHostProps(resource, props = {}) {
|
|
|
208
228
|
if (resource.async ?? resource.defer !== true) props.async = true;
|
|
209
229
|
if (resource.defer === true) props.defer = true;
|
|
210
230
|
if (resource.crossorigin !== void 0) props.crossorigin = resource.crossorigin;
|
|
211
|
-
break;
|
|
212
231
|
}
|
|
213
232
|
return props;
|
|
214
233
|
}
|
|
234
|
+
/** Asset resource from host values. */
|
|
215
235
|
function assetResourceFromHostValues(type, prop, children, requireAsyncScript = false) {
|
|
216
236
|
const withKey = (resource) => {
|
|
217
237
|
if (resource === null) return null;
|
|
@@ -363,4 +383,4 @@ function metaResourceKey(resource) {
|
|
|
363
383
|
//#endregion
|
|
364
384
|
export { stylesheet as _, assetResourceHostProps as a, readThenable as b, clientReferenceAssets as c, meta as d, modulepreload as f, script as g, preventAssetResourceHoist as h, assetResourceFromHostValues as i, font as l, preload as m, assetResourceFromHostAttributes as n, assetResourceKey as o, preconnect as p, assetResourceFromHostProps as r, assets as s, assetResourceDestination as t, isFigAssetResource as u, title as v, trackThenable as x, isThenable as y };
|
|
365
385
|
|
|
366
|
-
//# sourceMappingURL=resource-
|
|
386
|
+
//# sourceMappingURL=resource-Bhusybfq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-Bhusybfq.js","names":[],"sources":["../src/thenables.ts","../src/resource.ts"],"sourcesContent":["/** Describes thenable. */\nexport 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.\n/** Tracks thenable. */\nexport function trackThenable<T>(thenable: PromiseLike<T>): void {\n recordFor(thenable);\n}\n\n/** Reads thenable. */\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\n/** Checks whether thenable. */\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 PreventAssetResourceHostProps = Props & {\n [PreventAssetResourceHoistSymbol]?: true;\n};\n\n/** Describes asset resource blocking. */\nexport type AssetResourceBlocking = \"reveal\" | \"none\";\n/** Describes cross origin. */\nexport type CrossOrigin = \"anonymous\" | \"use-credentials\" | \"\";\n/** Describes fetch priority. */\nexport type FetchPriority = \"high\" | \"low\" | \"auto\";\n/** Describes asset resource destination. */\nexport type AssetResourceDestination = \"head\" | \"stream\";\n\n/** Describes Fig asset resource. */\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\n/** Describes stylesheet resource. */\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\n/** Describes preload resource. */\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\n/** Describes module preload resource. */\nexport interface ModulePreloadResource extends ResourceBase {\n crossorigin?: CrossOrigin;\n fetchpriority?: FetchPriority;\n href: string;\n kind: \"modulepreload\";\n}\n\n/** Describes script resource. */\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\n/** Describes font resource. */\nexport interface FontResource extends ResourceBase {\n crossorigin?: CrossOrigin;\n fetchpriority?: FetchPriority;\n href: string;\n kind: \"font\";\n type: string;\n}\n\n/** Describes preconnect resource. */\nexport interface PreconnectResource extends ResourceBase {\n crossorigin?: CrossOrigin;\n href: string;\n kind: \"preconnect\";\n}\n\n/** Describes title resource. */\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\n/** Describes meta resource. */\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\n/** Describes meta resource options. */\nexport type MetaResourceOptions = DistributiveOmit<MetaResource, \"kind\">;\n\n/** Describes Fig asset resource list. */\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.\n/** Describes client reference assets. */\nexport type ClientReferenceAssets =\n | FigAssetResourceList\n | (() => FigAssetResourceList);\n\n/** Describes assets props. */\nexport interface AssetsProps {\n assets: FigAssetResourceList;\n children?: FigNode;\n}\n\n/** Assets. */\nexport function assets(\n value: FigAssetResourceList,\n children?: FigNode,\n): FigElement<AssetsProps> {\n return createElement(Assets, { assets: value }, children);\n}\n\n/** Stylesheet. */\nexport function stylesheet(\n href: string,\n options: Omit<StylesheetResource, \"href\" | \"kind\"> = {},\n): StylesheetResource {\n return { ...options, href, kind: \"stylesheet\" };\n}\n\n/** Preload. */\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\n/** Modulepreload. */\nexport function modulepreload(\n href: string,\n options: Omit<ModulePreloadResource, \"href\" | \"kind\"> = {},\n): ModulePreloadResource {\n return { ...options, href, kind: \"modulepreload\" };\n}\n\n/** Script. */\nexport function script(\n src: string,\n options: Omit<ScriptResource, \"kind\" | \"src\"> = {},\n): ScriptResource {\n return { ...options, kind: \"script\", src };\n}\n\n/** Font. */\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\n/** Preconnect. */\nexport function preconnect(\n href: string,\n options: Omit<PreconnectResource, \"href\" | \"kind\"> = {},\n): PreconnectResource {\n return { ...options, href, kind: \"preconnect\" };\n}\n\n/** Title. */\nexport function title(value: string): TitleResource {\n return { kind: \"title\", value };\n}\n\n/** Meta. */\nexport function meta(options: MetaResourceOptions): MetaResource {\n return { ...options, kind: \"meta\" };\n}\n\n/** Checks whether Fig asset resource. */\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\n/** Client reference assets. */\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\n/** Asset resource key. */\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\n/** Asset resource destination. */\nexport function assetResourceDestination(\n resource: FigAssetResource,\n): AssetResourceDestination {\n return resource.kind === \"title\" || resource.kind === \"meta\"\n ? \"head\"\n : \"stream\";\n}\n\n/** Asset resource from host props. */\nexport function assetResourceFromHostProps(\n type: string,\n props: Props,\n): FigAssetResource | null {\n if (\n (props as PreventAssetResourceHostProps)[\n PreventAssetResourceHoistSymbol\n ] === true\n ) {\n return null;\n }\n return assetResourceFromHostValues(\n type,\n (name) => props[name],\n props.children,\n true,\n );\n}\n\n/** Prevent asset resource hoist. */\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\n/** Asset resource from host attributes. */\nexport function assetResourceFromHostAttributes(\n type: string,\n getAttribute: (name: string) => unknown,\n): FigAssetResource | null {\n return assetResourceFromHostValues(type, getAttribute, undefined, false);\n}\n\n/** Describes asset resource host props. */\nexport type AssetResourceHostProps = Record<string, string | true>;\n\n// Canonical host props for hoisted asset-resource elements, shared by the\n// server's registry writer and the client's head insertion so the two renders\n// cannot drift. `true` marks a boolean attribute (bare on the server,\n// empty-string in the DOM). Server-only attributes (id, nonce) stay with the\n// server writer; title/meta are written by their own paths.\n/** Asset resource host props. */\nexport function assetResourceHostProps(\n resource: FigAssetResource,\n props: AssetResourceHostProps = {},\n): AssetResourceHostProps {\n if (resource.kind === \"title\" || resource.kind === \"meta\") return props;\n\n switch (resource.kind) {\n case \"stylesheet\":\n props.rel = \"stylesheet\";\n props.href = resource.href;\n if (resource.key !== undefined) {\n props[\"data-fig-resource-key\"] = resource.key;\n }\n if (resource.precedence !== undefined) {\n props[\"data-precedence\"] = resource.precedence;\n }\n if (resource.media !== undefined) props.media = resource.media;\n if (resource.crossorigin !== undefined) {\n props.crossorigin = resource.crossorigin;\n }\n break;\n case \"preload\": {\n const imagesrcset = resource.imagesrcset || undefined;\n props.rel = \"preload\";\n if (imagesrcset === undefined && resource.href !== undefined) {\n props.href = resource.href;\n }\n props.as = resource.as;\n if (resource.key !== undefined) {\n props[\"data-fig-resource-key\"] = resource.key;\n }\n if (resource.type !== undefined) props.type = resource.type;\n if (resource.crossorigin !== undefined) {\n props.crossorigin = resource.crossorigin;\n }\n if (resource.fetchpriority !== undefined) {\n props.fetchpriority = resource.fetchpriority;\n }\n if (imagesrcset !== undefined) props.imagesrcset = imagesrcset;\n if (resource.imagesizes !== undefined) {\n props.imagesizes = resource.imagesizes;\n }\n if (resource.referrerpolicy !== undefined) {\n props.referrerpolicy = resource.referrerpolicy;\n }\n break;\n }\n case \"modulepreload\":\n props.rel = \"modulepreload\";\n props.href = resource.href;\n if (resource.key !== undefined) {\n props[\"data-fig-resource-key\"] = resource.key;\n }\n if (resource.crossorigin !== undefined) {\n props.crossorigin = resource.crossorigin;\n }\n if (resource.fetchpriority !== undefined) {\n props.fetchpriority = resource.fetchpriority;\n }\n break;\n case \"font\":\n props.rel = \"preload\";\n props.href = resource.href;\n props.as = \"font\";\n if (resource.key !== undefined) {\n props[\"data-fig-resource-key\"] = resource.key;\n }\n props.type = resource.type;\n props.crossorigin = resource.crossorigin ?? \"anonymous\";\n if (resource.fetchpriority !== undefined) {\n props.fetchpriority = resource.fetchpriority;\n }\n break;\n case \"preconnect\":\n props.rel = \"preconnect\";\n props.href = resource.href;\n if (resource.key !== undefined) {\n props[\"data-fig-resource-key\"] = resource.key;\n }\n if (resource.crossorigin !== undefined) {\n props.crossorigin = resource.crossorigin;\n }\n break;\n case \"script\":\n props.src = resource.src;\n if (resource.module === true) props.type = \"module\";\n if (resource.key !== undefined) {\n props[\"data-fig-resource-key\"] = resource.key;\n }\n // Hoisted scripts default to async, but an explicit defer opts into\n // ordered execution and must not be overridden (async wins over defer in\n // browsers).\n if (resource.async ?? resource.defer !== true) props.async = true;\n if (resource.defer === true) props.defer = true;\n if (resource.crossorigin !== undefined) {\n props.crossorigin = resource.crossorigin;\n }\n break;\n }\n return props;\n}\n\n/** Asset resource from host values. */\nexport function assetResourceFromHostValues(\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":";;AAWA,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,S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