@bgub/fig-dom 0.1.0-alpha.0 → 0.1.0-alpha.2

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 CHANGED
@@ -1,3 +1,435 @@
1
+ ## @bgub/fig-dom@0.1.0-alpha.2
2
+
3
+ ### Keep empty children and document assets hydration-safe
4
+
5
+ Empty string children now normalize away on both the server and client, so a
6
+ rendered empty token cannot force hydration to recover the root.
7
+
8
+ When full-document hydration does recover, declarative stylesheets, titles,
9
+ and metadata now acquire against the replacement head instead of disappearing
10
+ with the server document.
11
+
12
+ ## @bgub/fig-dom@0.1.0-alpha.1
13
+
14
+ ### Asset descriptors use native names and preserve native ordering
15
+
16
+ Client-inserted and host-rendered stylesheets now form precedence buckets in
17
+ the order each distinct precedence value is first discovered. A stylesheet
18
+ discovered later for an existing bucket is inserted before the following
19
+ bucket, keeping lazy and payload-delivered CSS in its intended cascade order.
20
+
21
+ Raw `<script>` elements now enter the asset registry only when explicitly
22
+ marked `async`. Non-async scripts retain their native document position and
23
+ execution semantics; explicit `script()` descriptors continue to support all
24
+ asset-delivery modes.
25
+
26
+ Asset descriptor options and serialized payload asset rows now use native HTML
27
+ attribute names: `crossorigin`, `fetchpriority`, and `http-equiv`. The previous
28
+ React-style `crossOrigin`, `fetchPriority`, and `httpEquiv` spellings are
29
+ removed.
30
+
31
+ Host resource resolution now receives the actual host parent and fixes
32
+ out-of-band placement once per fiber. SVG and MathML titles consequently stay
33
+ in their native namespace, while HTML titles carrying `itemprop` stay in-tree;
34
+ ordinary document titles continue to use the shared head registry.
35
+
36
+ ### Restore shadowed document metadata when its winner leaves
37
+
38
+ Client title and meta entries now keep stable per-fiber ownership claims. The
39
+ latest acquired live claim controls the single canonical DOM element; updates
40
+ to shadowed claims stay dormant, and removing the winner immediately restores
41
+ the latest remaining value.
42
+
43
+ Hoisted host and declarative asset lifecycle callbacks receive an opaque,
44
+ stable `AssetResourceOwner`. Hoisted updates own the complete canonical host
45
+ update, including text, so a shadowed fiber cannot overwrite registry state.
46
+
47
+ ### Stable client-reference identity across decodes
48
+
49
+ `@bgub/fig/payload` exposes `createPayloadClientReferenceResolver(resolve)`:
50
+ a caller-owned stateful resolver passed as the `resolveClientReference`
51
+ decode option. With one, every resolvable client reference decodes to one
52
+ resolver-owned wrapper per reference id across all decodes sharing the
53
+ resolver — gated, ungated, or asynchronously resolved — so re-decoding a
54
+ payload updates islands in place instead of remounting them. Reveal gates
55
+ ride the decoded element instances rather than the wrapper: each decode
56
+ gates exactly its own content, so a newer decode's pending assets never
57
+ re-suspend an island already on screen, while its new island instances
58
+ still wait for the stylesheets they declared. The caller owns the
59
+ resolver's lifetime; under fast refresh no manual invalidation is needed
60
+ (hot edits remap the latched resolution through component families, and
61
+ unaccepted updates full-reload), while `delete`/`clear` cover manifest
62
+ swaps without a reload. With a plain resolve function, gated and async
63
+ references keep their per-decode wrapper identity, now with the same
64
+ per-element gating.
65
+
66
+ `@bgub/fig-dom`'s `payloadDataLoader` accepts the stateful resolver through
67
+ its existing `resolveClientReference` option.
68
+
69
+ Framework adapters can retain one resolver across refreshes and navigations,
70
+ preventing asset-gated islands from remounting on every re-decode.
71
+
72
+ ### Publish metadata only with its visible owner
73
+
74
+ Title and meta resources now travel through Payload as owner-bound
75
+ declarations and update the document only when their decoded tree commits.
76
+ Pending or superseded refreshes keep the previous metadata visible.
77
+
78
+ Streaming HTML now treats Suspense fallbacks as metadata owners and reconciles
79
+ the completed visible metadata snapshot in the boundary reveal operation.
80
+ Partial segments and failed or abandoned primary work cannot mutate the head.
81
+
82
+ The obsolete `onAssetError` option and its asset-diagnostic types are removed:
83
+ late metadata is delivered with its owner instead of being dropped.
84
+
85
+ ### Recover full-document Suspense hydration mismatches
86
+
87
+ Full-document hydration now escalates a mismatch inside the document-level
88
+ Suspense boundary to root recovery, preserves the document doctype, and
89
+ rebuilds the document without reusing cleared insertion anchors.
90
+
91
+ ### Make `configureDomRefreshScheduler` internal
92
+
93
+ The `@bgub/fig-dom/refresh` subpath now exports only `scheduleRefresh`
94
+ and the `RefreshFamily`/`RefreshUpdate` types. The wiring setter was
95
+ called by exactly one place — fig-dom's own renderer, as a module side
96
+ effect — and HMR runtimes only ever needed `scheduleRefresh`. The
97
+ before-main-entry update buffering is unchanged and keeps living in a
98
+ single shared module, so pre-evaluation refreshes still replay once the
99
+ renderer configures itself.
100
+
101
+ ### Split fig-dom's oversized modules into focused ones
102
+
103
+ Internal restructuring with no API or behavior change. The host config and
104
+ renderer wiring move out of the package entry into `renderer.ts`; form
105
+ control value/checked/select handling, style application, the `on()` event
106
+ descriptor, and the propagation-state patching each get their own module.
107
+ Event slot attachment state is now a discriminated union instead of four
108
+ nullable fields.
109
+
110
+ ### Serialized components move to the data-resource model
111
+
112
+ Serialized trees are now ordinary data resources: servers return plain
113
+ Payload streams, and clients consume them through keyed `dataResource`
114
+ instances with `payloadDataLoader`. Refresh is `refreshData`, navigation can
115
+ select a new key, and back/forward navigations reuse cached entries. Commits
116
+ wait for the incoming Payload, island modules, and stylesheet gates.
117
+
118
+ Supporting API additions: `payloadDataLoader` accepts a `prepareAssets`
119
+ override (defaults to `insertAssetResources`), and `decodePayloadStream`
120
+ accepts an `onClientReference` observer for reference metadata.
121
+
122
+ ### Diagnose hoisted resource declassification
123
+
124
+ Development now throws when an update would turn a permanently hoisted host
125
+ fiber into an ordinary in-tree element, naming the affected asset and
126
+ explaining that changing placement requires a different Fig element key.
127
+ Production ignores the update instead of mutating a shared delivery asset or
128
+ overwriting the owner's last valid title or metadata claim.
129
+
130
+ ### Compose host behavior with mixins
131
+
132
+ Core now exports `createMixin()` and resolves render-time host behavior through
133
+ the `mix` prop. Mixins may contribute host props or nested mixins while keeping
134
+ the host type and subtree fixed. Explicit host props form the baseline; mixins
135
+ run in authoring order, and later results win.
136
+
137
+ DOM event listeners now use `mix={on(type, callback)}`. Migrate
138
+ `events={[on(type, callback)]}` to `mix={on(type, callback)}`; multiple or
139
+ conditional descriptors move into `mix={[...]}` and preserve positional
140
+ listener identity.
141
+
142
+ ### Keep `useId` stable through selective hydration
143
+
144
+ `useId` now follows one canonical server/hydration tree path through Suspense
145
+ and Activity. Dehydrated boundaries snapshot that path when they claim their
146
+ server marker, then restore it when hydration resumes, so client updates that
147
+ insert or move surrounding siblings cannot renumber ids already present in the
148
+ server HTML. Suspense's private Activity wrapper is transparent to the path.
149
+
150
+ Components mounted only on the client now receive ids from a separate
151
+ `fig-C-*` namespace. Those ids remain stable for the component lifetime and
152
+ cannot collide with ids reserved by server-rendered content that has not
153
+ hydrated yet.
154
+
155
+ ### Trim DOM renderer hot-path work
156
+
157
+ The DOM renderer now avoids transient collections while diffing host props,
158
+ updating event descriptors, and scanning document assets. Event routing keeps
159
+ root state in one container record, stores less per-listener metadata, and
160
+ builds dispatch paths in place. Host configuration callbacks whose signatures
161
+ already match now connect directly instead of paying forwarding closures.
162
+
163
+ Controlled single-select elements also keep their scalar value without
164
+ allocating a one-entry `Set`; multi-select values retain set lookup behavior.
165
+ These changes preserve the public API while reducing the production entry
166
+ bundle and allocation pressure during mount, update, dispatch, and teardown.
167
+
168
+ ### Payload exposes rendering and decoding, not its implementation
169
+
170
+ The payload packages now present two primary operations:
171
+ `renderToPayloadStream` on the server and `decodePayloadStream` in the
172
+ browser-safe core entry. Row/model types, value encoding, codec machinery,
173
+ content-type negotiation helpers, and framework document transports are
174
+ internal implementation details.
175
+
176
+ Client references use one `resolveClientReference(reference)` seam that may
177
+ return a component synchronously or asynchronously. It replaces the separate
178
+ load, resolve, and observation callbacks; reference metadata now includes its
179
+ stream-safe assets. The unused `load` field is also removed from
180
+ `clientReference(...)` declarations.
181
+
182
+ `payloadDataLoader` keeps only `request`, `resolveClientReference`, and the
183
+ optional `prepareAssets` override. Payload encoding is fixed internally rather
184
+ than exposed as a speculative custom-codec interface.
185
+
186
+ ### Make DOM View Transitions explicitly optional
187
+
188
+ `enableViewTransitions()` from `@bgub/fig-dom/view-transitions` explicitly
189
+ activates native DOM View Transitions, including after roots exist. Applications
190
+ that omit the optional entry exclude both the reconciler planner and browser
191
+ adapter from their bundles.
192
+
193
+ Renderer authors can install the optional View Transition planner through the
194
+ new single-owner commit-coordinator seam. Coordinator types preserve the host's
195
+ container and instance identities, while a private type-only contract keeps the
196
+ planner's fiber and root views aligned with the reconciler.
197
+
198
+ ### Make Payload trees directly renderable
199
+
200
+ `createPayloadComponent` now creates a props-typed component backed by Fig's
201
+ ordinary data store. Complete props form its cache identity by default through
202
+ a canonical encoding of Payload-compatible values, and the component works
203
+ with route loaders and the existing data-resource freshness APIs and explicit
204
+ store handles.
205
+
206
+ The lower-level `payloadDataLoader` and `PayloadDataLoaderOptions` exports have
207
+ been removed. Use `createPayloadComponent`, or `decodePayloadStream` when
208
+ managing the transport and data integration directly.
209
+
210
+ TanStack Start replaces `payloadResource({ key, render })` with
211
+ `createPayloadComponent({ key, load: serverPayload(render) })`. Its compiler
212
+ can extract a component imported from `.server.tsx`, while initial companion
213
+ streams, client references, and compiled asset dependencies keep their existing
214
+ transport behavior.
215
+
216
+ Payload component loaders receive the resolved resource `key` alongside
217
+ `signal`, so framework transports can register responses under the exact cache
218
+ entry without changing ordinary data loaders.
219
+
220
+ Default keys are canonical across plain-object property order, and Payload
221
+ components use their namespace as their DevTools label. TanStack Start renders
222
+ the supplied component inside the Payload renderer so root-level reads and
223
+ suspension work, and rejects uncompiled `serverPayload` calls before invoking
224
+ application code.
225
+
226
+ Payload rendering also rejects nesting one Payload component inside another in
227
+ development. Payload components are client-visible delivery boundaries;
228
+ compose ordinary server components inside them or mount separate Payload
229
+ components from the client tree to preserve independent refresh keys.
230
+
231
+ ### Generation-lifetime loader signals and `payloadDataLoader`
232
+
233
+ Data-resource loader signals now live as long as their load's generation,
234
+ not just the pending promise: the `{ signal }` a loader receives stays
235
+ unaborted after the value lands and aborts when the generation loses
236
+ authority — a newer load supersedes it, a server push hydrates over it, the
237
+ entry evicts, or the store is disposed. A rejected load's own signal aborts
238
+ on settlement, and `invalidateData` never aborts (marking stale does not
239
+ revoke authority). Loaders that stream into their value in the background —
240
+ payload decodes filling holes — tie that work to the signal; plain fetch
241
+ loaders are unaffected.
242
+
243
+ The load context also carries an internal, generation-guarded hydration
244
+ capability (symbol-keyed; read through `@bgub/fig/internal`) that hydrates
245
+ server-pushed `data` rows through the calling store only while the load is
246
+ authoritative, skipping rows that target the loading entry's own key.
247
+
248
+ New in `@bgub/fig-dom`: `payloadDataLoader({ request,
249
+ resolveClientReference?, prepareAssets? })` adapts a payload-stream
250
+ endpoint into an ordinary data-resource loader. It validates the response
251
+ (status, body, payload codec content-type; unusable bodies are cancelled),
252
+ wires `decodePayloadStream` to the generation-lifetime signal, hydrates
253
+ `data` rows through the store capability, inserts stream-discovered assets
254
+ with `insertAssetResources` (stylesheet gates delay only dependent reveal),
255
+ and resolves with the decoded root value — so `readData(postResource, slug)`
256
+ suspends like any read and returns renderable elements while streamed holes
257
+ keep filling in the background.
258
+
259
+ ### Move `createPortalNode` to `@bgub/fig/internal`
260
+
261
+ `createPortalNode` is the cross-package seam renderers wrap in their
262
+ container-typed `createPortal`; apps never call it directly. It now lives
263
+ on the internal entry with the other renderer protocol exports instead of
264
+ the app-facing main entry. Portal-creating apps keep using
265
+ `createPortal(children, container, key?)` from `@bgub/fig-dom`; the
266
+ `FigPortal` type stays on the main entry because it appears in public
267
+ signatures.
268
+
269
+ ### Promise-shaped payload decoder
270
+
271
+ `decodePayloadStream` now returns `Promise<FigNode>` directly — the root
272
+ value promise — instead of a `PayloadDecode` handle. Cancellation is
273
+ signal-only (`options.signal`, unchanged); the redundant `abort()` method is
274
+ gone. The `completion` promise is replaced by an `onStreamDone(result)`
275
+ decode option, called exactly once when ingestion settles as `complete`,
276
+ `failed`, or `aborted` — post-root failures that strand no pending hole
277
+ remain observable there. The callback is never awaited and its exceptions
278
+ and rejections are swallowed, so an observer — sync or async — cannot break
279
+ decode teardown or leak an unhandled rejection. The
280
+ `PayloadDecode` interface and its non-thenable caveat are deleted;
281
+ `PayloadDecodeCompletion` remains as the callback's result type.
282
+
283
+ `@bgub/fig-dom`'s `payloadDataLoader` migrates internally; its public API is
284
+ unchanged.
285
+
286
+ Also considered and declined: narrowing `ResolveClientReference` to an
287
+ opaque id. The reference's `exportName`/`ssr`/`assets` mirror the `client`
288
+ row's wire fields and are all load-bearing in framework document pipelines;
289
+ the rationale is recorded in `docs/concepts/payload.md`.
290
+
291
+ ### Promise-valued children render through Suspense
292
+
293
+ `FigNode` now accepts promises of nodes. Promise children occupy distinct,
294
+ host-transparent child slots, suspend through the nearest `Suspense`, and route
295
+ rejections or invalid resolved children through normal error handling.
296
+
297
+ HTML rendering retains exact promise children as independent streaming tasks,
298
+ while Payload uses node-validated promise rows that decode to the same child
299
+ shape. Payload-rendered async components are invoked once and retain their
300
+ component-scoped assets on the outlined row.
301
+
302
+ ### Tighten public component, loader, asset, and bind signatures
303
+
304
+ `@bgub/fig` now names the shared data loader contract as
305
+ `DataResourceLoader`, constrains lazy loaders to components, and exposes
306
+ `ComponentProps` so lazy wrappers preserve the loaded component's props
307
+ without exposing its implementation statics. Client-reference SSR
308
+ implementations stay aligned with the reference's props. Stable-event typing
309
+ now models the trailing lifecycle signal separately from caller arguments.
310
+
311
+ `meta()` descriptors now require exactly one valid metadata identity:
312
+ `charset`, `name` plus `content`, `property` plus `content`, or `http-equiv`
313
+ plus `content`. Raw meta elements that do not satisfy the same shape remain
314
+ ordinary host elements instead of entering the asset registry.
315
+
316
+ `@bgub/fig-dom` payload requests now receive the standard
317
+ `DataResourceLoadContext`, portals retain their DOM container type in the
318
+ returned `FigPortal`, and bind callbacks must return `undefined`; cleanup is
319
+ exclusively driven by their `AbortSignal`.
320
+
321
+ ### Move `act` to `@bgub/fig-reconciler/test-utils`
322
+
323
+ `act` is testing infrastructure, not renderer construction, so it moves
324
+ off the main entry onto a `./test-utils` subpath — the same shape as
325
+ `@bgub/fig-dom/test-utils`. DOM tests keep importing `act` from
326
+ `@bgub/fig-dom/test-utils`; renderer tests now import it from
327
+ `@bgub/fig-reconciler/test-utils`. Behavior is unchanged; the subpath
328
+ shares the scheduler instance with the main entry.
329
+
330
+ ### Attribute rejected payload holes to their data resource
331
+
332
+ Payload hole errors are attributed to the authoritative owning data-resource
333
+ generation. Error boundaries receive `dataResourceKeys`, and
334
+ `invalidateDataError` retires the broken fulfilled value before retrying so a
335
+ remounted boundary suspends on fresh content instead of immediately catching
336
+ the same rejected hole. `decodePayloadStream` also exposes an observational
337
+ `onHoleError` callback.
338
+
339
+ The load context's hydration capability now shares the same authority window:
340
+ a still-visible generation's `data` rows keep hydrating through a superseding
341
+ refresh's window instead of being dropped the moment the refresh starts.
342
+
343
+ ### Fix first-load styling and development client navigation
344
+
345
+ Keep TanStack Start's compiler-sensitive client modules out of Vite dependency
346
+ prebundling so client navigation uses the client server-function transport
347
+ instead of executing server-only context access in the browser. Preserve
348
+ browser-extension roots appended to document singletons during hydration so a
349
+ third-party node cannot trigger document replacement and remove stylesheets.
350
+
351
+ ### Preserve framework-managed asset placement
352
+
353
+ Framework adapters can now keep externally managed head and body tags in their
354
+ declared positions without exposing a DOM prop. TanStack Router uses this for
355
+ route-managed links, styles, and scripts while continuing to map title and meta
356
+ entries through Fig asset resources. Full-document hydration now ignores the
357
+ doctype and one shared marker identifies every server-owned node without a
358
+ client fiber. Declarative asset lists also gain a client commit lifecycle, so
359
+ route titles and metadata update during navigation.
360
+
361
+ ### Add Payload routes to the TanStack Start adapter
362
+
363
+ `@bgub/fig-tanstack-start/payload` now exposes `payloadResource`, which compiles
364
+ an inline render callback into a private server function and Fig-owned route
365
+ data resource. Applications supply the cache key and component tree without
366
+ authoring transport plumbing. The shared declaration can stay in one
367
+ `.payload.tsx` module; its render callback and render-only imports are omitted
368
+ from the browser build. The initial SSR response is embedded into the document
369
+ and adopted without refetching; client navigation and refresh use the same
370
+ resource request path. Payload data rows
371
+ hydrate the shared store, asset resources are retained on their owning server
372
+ segments or inserted through the browser registry, and client references retain
373
+ their resolver-defined identity. `decodePayloadStream` and `payloadDataLoader`
374
+ now expose `retainAssets` for server document renderers that need this delivery
375
+ path.
376
+
377
+ `@bgub/fig-tanstack-start/server` exposes the lower-level
378
+ `renderPayloadResponse` used by the generated TanStack server function; it
379
+ defaults its render abort signal to the incoming request, so a disconnected
380
+ client cancels the Payload render. Shell
381
+ HTML streams while outlined Suspense holes settle, and the completed initial
382
+ responses are embedded before TanStack starts full-document hydration. The Vite
383
+ adapter also publishes assets imported only by server modules into the client
384
+ build output. Fig Router links also consume TanStack's `viewTransition`
385
+ navigation option without forwarding it as an invalid attribute to the rendered
386
+ anchor, and derive active state from the resolved route instead of an in-flight
387
+ location.
388
+
389
+ ### Add the TanStack Start runtime adapter
390
+
391
+ `createDataStore` now creates a root-neutral Fig store that route loaders can
392
+ populate before a renderer exists. Server and client renderers adopt that exact
393
+ store, preserving one cache while attaching their lifecycle and scheduling.
394
+
395
+ The new TanStack Start runtime uses the store for route loading, server
396
+ rendering, Fig-owned document serialization, client deserialization, and
397
+ hydration. Route-managed head and script output maps through the Router adapter,
398
+ including Fig asset resources. The end-to-end contract verifies no initial
399
+ client refetch and exactly one reload after invalidation.
400
+
401
+ ### Share the text-separator protocol constant; small DOM cleanups
402
+
403
+ The `<!--,-->` text-separator comment the server writes between adjacent text
404
+ fibers was hardcoded independently by the server renderer and fig-dom's
405
+ hydration cursor. The comment data now lives in `@bgub/fig/internal` as
406
+ `TEXT_SEPARATOR_DATA`, next to the other streaming protocol constants, so the
407
+ two sides cannot drift. No wire change — the emitted markup is identical.
408
+
409
+ fig-dom also drops an unused internal `rootFor` helper, routes style clearing
410
+ through the shared `isEmptyPropValue` predicate, and simplifies a redundant
411
+ branch in select-value syncing. No behavior change.
412
+
413
+ ### Add typed View Transition scopes and abortable lifecycle events
414
+
415
+ `transition` and the `useTransition` starter now accept explicit transition
416
+ types, which Fig carries with the updates that reach each root and forwards to
417
+ the browser without leaking into unrelated commits.
418
+
419
+ `ViewTransition` adds one `onTransition(event, signal)` lifecycle callback for
420
+ enter, exit, share, and update phases. Events expose all participating surfaces
421
+ and the commit's transition types. Fig DOM's optional View Transition entry can
422
+ resolve those opaque surfaces into group, image-pair, old, and new pseudo
423
+ handles for animation and inspection; the signal aborts when the native
424
+ transition finishes.
425
+
426
+ ### Bound stalled view-transition waits
427
+
428
+ Transition-eligible commits and annotated streaming reveals now wait at most 60
429
+ seconds for a previous browser View Transition. If its completion promise never
430
+ settles, Fig releases the document mutex and proceeds with the latest work
431
+ instead of parking it forever.
432
+
1
433
  ## @bgub/fig-dom@0.1.0-alpha.0 (alpha)
2
434
 
3
435
  ### Initial alpha release
package/README.md CHANGED
@@ -23,6 +23,18 @@ bindings/events, and reports recoverable mismatches through
23
23
  `useSyncExternalStore` use their server snapshot during hydration, then subscribe
24
24
  and reconcile to the current client snapshot after commit.
25
25
 
26
+ For full-document rendering, pass the `Document` itself as the container. A
27
+ root-neutral data store can be populated before hydration and adopted without
28
+ copying its entries:
29
+
30
+ ```tsx
31
+ import { createDataStore } from "@bgub/fig";
32
+ import { hydrateRoot } from "@bgub/fig-dom";
33
+
34
+ const dataStore = createDataStore({ initialData });
35
+ hydrateRoot(document, <App />, { dataStore });
36
+ ```
37
+
26
38
  Suspense hydration is boundary-based: server Suspense markers stay
27
39
  dehydrated after the shell hydrates, then hydrate in background work or
28
40
  synchronously when an interaction lands inside that boundary. Pending
package/dist/act.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { act } from "@bgub/fig-reconciler";
1
+ import { act } from "@bgub/fig-reconciler/test-utils";
2
2
  export { act };
package/dist/act.js CHANGED
@@ -1 +1 @@
1
- import{act as e}from"@bgub/fig-reconciler";export{e as act};
1
+ import{act as e}from"@bgub/fig-reconciler/test-utils";export{e as act};
package/dist/index.d.ts CHANGED
@@ -1,22 +1,63 @@
1
- import { a as HostStyle, c as EventDescriptor, d as Bind, f as composeBind, i as HostProps, l as EventOptions, n as EmptyPropValue, o as Container, r as HostEvents, s as EventCallback, t as HostIntrinsicElements, u as on } from "./jsx-C3Y2wps3.js";
2
- import { FigAssetResource, FigNode, FigPortal, Key } from "@bgub/fig";
1
+ import { a as Bind, i as HostStyle, n as EmptyPropValue, o as composeBind, r as HostProps, t as HostIntrinsicElements } from "./jsx-C3owhMDw.js";
2
+ import { AwaitedFigNode, DataResource, DataResourceKey, DataResourceKeyInput, FigAssetResource, FigNode, FigPortal, Key, MixinDescriptor } from "@bgub/fig";
3
3
  import { FigRoot, FigRootOptions, RecoverableErrorInfo } from "@bgub/fig-reconciler";
4
+ import { PayloadDecodeOptions } from "@bgub/fig/payload";
5
+ //#region src/event-descriptor.d.ts
6
+ type EventOptions = Pick<AddEventListenerOptions, "capture" | "passive">;
7
+ type EventCallback<E extends Event = Event> = (event: E, signal: AbortSignal) => void;
8
+ /**
9
+ * Declares one native listener for an element's `mix` prop. Bubbling
10
+ * events follow the logical Fig tree through portals; non-bubbling events,
11
+ * including `focus` and `blur`, attach directly with native semantics.
12
+ */
13
+ declare function on<K extends keyof HTMLElementEventMap>(type: K, callback: EventCallback<HTMLElementEventMap[K]>, options?: EventOptions): MixinDescriptor;
14
+ declare function on<E extends Event = Event>(type: string, callback: EventCallback<E>, options?: EventOptions): MixinDescriptor;
15
+ //#endregion
16
+ //#region src/events.d.ts
17
+ type Container = Document | DocumentFragment | Element;
18
+ //#endregion
4
19
  //#region src/asset-resources.d.ts
5
20
  /**
6
- * Insert render-discovered asset resources (e.g. from a payload response's
7
- * `getAssetResources()`) into the document head, deduped against resources
8
- * already inserted by SSR, a host-rendered element, or an earlier call using
9
- * the same key semantics as host resources. Returns a promise that resolves once
10
- * every freshly inserted *critical* stylesheet has loaded or errored, so callers
11
- * can gate revealing the dependent content. Non-critical hints (preload,
12
- * preconnect, scripts, fonts, `blocking: "none"` stylesheets) never block.
21
+ * Inserts render-discovered asset resources into the document head. Returns a
22
+ * promise that settles when every newly discovered critical stylesheet loads
23
+ * or errors; hints, scripts, fonts, and non-blocking styles never gate reveal.
13
24
  */
14
25
  declare function insertAssetResources(resources: readonly FigAssetResource[]): Promise<void>;
15
26
  //#endregion
27
+ //#region src/payload-decoder.d.ts
28
+ type PayloadDecoderOptions = Pick<PayloadDecodeOptions, "prepareAssets" | "resolveClientReference" | "retainAssets">;
29
+ //#endregion
30
+ //#region src/payload-component.d.ts
31
+ type PayloadSource = Response | {
32
+ contentType: string;
33
+ stream: ReadableStream<Uint8Array>;
34
+ };
35
+ interface PayloadComponentLoadContext {
36
+ key: DataResourceKey;
37
+ signal: AbortSignal;
38
+ }
39
+ interface PayloadComponentLoader<TProps extends object> extends PayloadDecoderOptions {
40
+ (props: TProps, context: PayloadComponentLoadContext): PayloadSource | PromiseLike<PayloadSource>;
41
+ }
42
+ interface PayloadComponentOptions<TProps extends object> extends PayloadDecoderOptions {
43
+ cacheKey?: (props: TProps) => DataResourceKeyInput;
44
+ key: DataResourceKey;
45
+ load: PayloadComponentLoader<TProps>;
46
+ }
47
+ interface PayloadComponent<TProps extends object> extends DataResource<[TProps], AwaitedFigNode> {
48
+ (props: TProps & {
49
+ children?: FigNode;
50
+ }): FigNode;
51
+ }
52
+ /**
53
+ * Creates a renderable Payload tree backed by Fig's ordinary data store.
54
+ */
55
+ declare function createPayloadComponent<TProps extends object>(options: PayloadComponentOptions<TProps>): PayloadComponent<TProps>;
56
+ //#endregion
16
57
  //#region src/index.d.ts
17
58
  declare const flushSync: <T>(this: void, callback: () => T) => T;
18
59
  declare function createRoot(container: Container, options?: FigRootOptions): FigRoot;
19
60
  declare function hydrateRoot(container: Container, children: FigNode, options?: FigRootOptions): FigRoot;
20
- declare function createPortal(children: FigNode, container: Container, key?: Key | null): FigPortal;
61
+ declare function createPortal(children: FigNode, container: Container, key?: Key | null): FigPortal<Container>;
21
62
  //#endregion
22
- export { type Bind, type Container, type EmptyPropValue, type EventCallback, type EventDescriptor, type EventOptions, type FigRoot, type FigRootOptions, type HostEvents, type HostIntrinsicElements, type HostProps, type HostStyle, type RecoverableErrorInfo, composeBind, createPortal, createRoot, flushSync, hydrateRoot, insertAssetResources, on };
63
+ export { type Bind, type Container, type EmptyPropValue, type EventCallback, type EventOptions, type FigRoot, type FigRootOptions, type HostIntrinsicElements, type HostProps, type HostStyle, type PayloadComponent, type PayloadComponentLoadContext, type PayloadComponentLoader, type PayloadComponentOptions, type PayloadSource, type RecoverableErrorInfo, composeBind, createPayloadComponent, createPortal, createRoot, flushSync, hydrateRoot, insertAssetResources, on };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{configureDomRefreshScheduler as e}from"./refresh.js";import{createPortalNode as t}from"@bgub/fig";import{ACTIVITY_TEMPLATE_ATTRIBUTE as n,EARLY_EVENT_HANDLER_PROPERTY as r,EARLY_EVENT_QUEUE_PROPERTY as i,REPLAYABLE_EVENT_TYPES as a,SUSPENSE_CLIENT_MARKER as o,SUSPENSE_COMPLETED_MARKER as s,SUSPENSE_END_MARKER as c,SUSPENSE_PENDING_PREFIX as l,VIEW_TRANSITION_PENDING_PROPERTY as u,assetResourceFromHostAttributes as d,assetResourceFromHostProps as f,assetResourceHostAttributes as p,assetResourceKey as m,isFigAssetResource as ee}from"@bgub/fig/internal";import{createRenderer as te,runWithEventPriority as h}from"@bgub/fig-reconciler";function g(e,t){if(_(e)&&t(e),!(!(`childNodes`in e)||e.firstChild===null))for(let n of Array.from(e.childNodes))g(n,t)}function _(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===1}function v(e){return _(e)?`localName`in e&&typeof e.localName==`string`?e.localName.toLowerCase():`tagName`in e&&typeof e.tagName==`string`?e.tagName.toLowerCase():``:``}function ne(e){return!(`namespaceURI`in e)||e.namespaceURI===null||e.namespaceURI===`http://www.w3.org/1999/xhtml`}function y(e){return typeof e==`object`&&e&&`parentNode`in e?e.parentNode:null}function b(e){return e==null||e===!1}const x=new WeakMap,S=new WeakSet;function re(...e){let t=e.filter(e=>typeof e==`function`);return(e,n)=>{for(let r of t)r(e,n)}}function ie(e,t){let n=le(t),r=x.get(e);if(n===null){r!==void 0&&w(r),x.delete(e);return}if(r===void 0){let t={callback:n,controller:null,strictRan:!1};x.set(e,t),C(e,t)}else r.callback!==n&&(w(r),r.callback=n,C(e,r))}function ae(e){let t=x.get(e);t!==void 0&&C(e,t)}function oe(e){S.add(e);let t=x.get(e);t!==void 0&&w(t)}function se(e){S.delete(e);let t=x.get(e);t!==void 0&&C(e,t)}function ce(e){let t=x.get(e);t!==void 0&&(w(t),x.delete(e))}function C(e,t){t.controller!==null||e.parentNode===null||S.has(e)||(t.controller=new AbortController,t.callback(e,t.controller.signal))}function w(e){e.controller?.abort(),e.controller=null}function le(e){if(b(e))return null;if(typeof e==`function`)return e;throw Error(`The bind prop must be a function.`)}const ue=Symbol.for(`fig.event`),T=new WeakMap,E=new WeakMap,de=new WeakMap,D=[],fe=new Set([`beforeinput`,`blur`,`change`,`click`,`contextmenu`,`dblclick`,`focus`,`focusin`,`focusout`,`input`,`keydown`,`keyup`,`mousedown`,`mouseup`,`pointerdown`,`pointerup`,`submit`,`touchend`,`touchstart`]),pe=new Set(a),me=new Set([`drag`,`dragover`,`mousemove`,`pointermove`,`scroll`,`touchmove`,`wheel`]),he=new Set([...fe,...me,`mouseenter`,`mouseleave`]),ge=new Set(`abort.blur.cancel.canplay.canplaythrough.close.durationchange.emptied.encrypted.ended.error.focus.invalid.load.loadeddata.loadedmetadata.loadstart.mouseenter.mouseleave.pause.play.playing.pointerenter.pointerleave.progress.ratechange.resize.scroll.scrollend.seeked.seeking.stalled.suspend.timeupdate.toggle.volumechange.waiting`.split(`.`));let _e=e=>e();function ve(e){_e=e}function ye(e,t,n){let r=O(e);r.root=!0,n!==void 0&&(r.scope=n),t!==void 0&&(r.hydrate=t,Ne(e,r),xe(e))}const be=new WeakMap;function xe(e){let t=e.ownerDocument??e,n=be.get(t);if(n===void 0){let e=t[i];if(!Array.isArray(e))return;let o=t[r];if(typeof o==`function`&&typeof t.removeEventListener==`function`)for(let e of a)t.removeEventListener(e,o,!0);delete t[i],delete t[r],n=e,be.set(t,n)}let o=!1;for(let t=0;t<n.length;){let r=n[t];if(pe.has(r.type)&&z(e,r.target)){n.splice(t,1),Fe(e,r.type,r),o=!0;continue}t+=1}o&&queueMicrotask(j)}function Se(e){let t=E.get(e);if(t!==void 0){Ce(e);for(let n of t.listeners.values())e.removeEventListener(n.type,n.listener,{capture:n.capture});we(e),E.delete(e);for(let t=D.length-1;t>=0;--t)D[t].root===e&&D.splice(t,1)}}function Ce(e){let t=E.get(e);if(t!==void 0){t.hydrate=null;for(let[n,r]of t.hydrationListeners??[])e.removeEventListener(n,r,{capture:!0});t.hydrationListeners=null}}function we(e){for(let t of E.get(e)?.portals??[])we(t),A(t)}function O(e){let t=E.get(e);return t===void 0&&(t={hydrate:null,hydrationListeners:null,listeners:new Map,portalOwner:null,portals:null,root:!1,scope:null},E.set(e,t)),t}function Te(e,t,n){return{$$typeof:ue,type:e,callback:t,options:n}}function Ee(e,t){let n=Ue(e),r=Be(t,v(e)),i=null;for(let t=0;t<r.length;t+=1){let a=r[t];if(a===void 0){let e=n[t];e!==void 0&&(M(e),n[t]=void 0);continue}let o=rt(a.options),s=it(a.type,o),c=n[t];c===void 0?(i??=k(e),n[t]=je(e,i.root,i.listenerTarget,a,o,s)):c.key===s?c.callback!==a.callback&&(c.callback=a.callback):(i??=k(e),M(c),n[t]=je(e,i.root,i.listenerTarget,a,o,s))}for(let e=n.length-1;e>=r.length;--e){let t=n[e];t!==void 0&&M(t)}n.length=r.length}function De(e){let t=ke(e),n=B(e);for(let r of T.get(e)??[])r!==void 0&&We(e,t,n,r)}function Oe(e){for(let t of T.get(e)??[])t!==void 0&&M(t);T.delete(e)}function ke(e){return k(e).root}function k(e){let t=B(e);if(t===null)return{listenerTarget:null,root:null};let n=E.get(t);return{listenerTarget:t,root:n?.portalOwner?.root??(n?.root===!0?t:null)}}function Ae(e,t,n){let r=O(e),i=B(n)??t;if(r.portalOwner!==null){if(r.portalOwner.root===t&&r.portalOwner.parentTarget===i){r.portalOwner={logicalParent:n,parentTarget:i,root:t};return}A(e)}r.portalOwner={logicalParent:n,parentTarget:i,root:t};let a=O(i);(a.portals??=new Set).add(e);for(let n of a.listeners.values())I(t,e,n.type,n.capture,n.passive)}function A(e){let t=E.get(e),n=t?.portalOwner??null;if(t===void 0||n===null)return;t.portalOwner=null;let r=E.get(n.parentTarget);if(r!==void 0){r.portals?.delete(e);for(let t of r.listeners.keys())L(e,t)}}function j(){let e=new Set;for(let t=0;t<D.length;){let n=D[t];if(!z(n.listenerTarget??n.root,n.event.target)){D.splice(t,1);continue}if(Ie(n)===`blocked`){e.add(n.root),t+=1;continue}if(e.has(n.root)){t+=1;continue}D.splice(t,1),Le(n)}}function je(e,t,n,r,i,a){let o={key:a,type:r.type,callback:r.callback,options:i,controller:null,element:null,listener:null,listenerTarget:null,root:null};return We(e,t,n,o),o}function M(e){R(e),F(e)}function Me(e,t,n,r,i,a){let o=B(a.target);if(o!==t&&((o===null?null:E.get(o)??null)?.portalOwner?.root===e||!z(t,a.target))||Pe(e,n,a)===`blocked`)return;let s=N(e,t,n,r,i,a);s.length!==0&&et(a,!1,e=>P(s,a,e))}function Ne(e,t){if(t.hydrationListeners===null){t.hydrationListeners=[];for(let n of he){let r=t=>Pe(e,n,t);t.hydrationListeners.push([n,r]),e.addEventListener(n,r,{capture:!0,passive:at(n)})}}}function Pe(e,t,n){let r=E.get(e)?.hydrate??null;if(r===null)return`none`;let i=de.get(n),a=i?.get(e);if(a!==void 0)return a;let o=V(t),s=h(o,()=>r(n.target,o));return i===void 0&&(i=new WeakMap,de.set(n,i)),i.set(e,s),s===`blocked`&&pe.has(t)&&Fe(e,t,n),s}function Fe(e,t,n){D.push({event:n,listenerTarget:B(n.target),root:e,type:t})}function Ie(e){let t=E.get(e.root)?.hydrate??null;if(t===null)return`none`;let n=V(e.type);return h(n,()=>t(e.event.target,n))}function Le(e){let{event:t,root:n,type:r}=e,i=e.listenerTarget??e.root;et(t,!0,e=>{P(N(n,i,r,!0,null,t),t,e),!(e.immediateStopped||e.stopped)&&P(N(n,i,r,!1,null,t),t,e)})}function N(e,t,n,r,i,a){let o=Ze(e,t,a),s=[],c=r?-1:1;for(let t=r?o.length-1:0;t>=0&&t<o.length;t+=c){let a=o[t];for(let t of T.get(a)??[])t!==void 0&&(t.root!==e||t.type!==n||t.options.capture!==r||i!==null&&t.options.passive!==i||s.push({callback:t.callback,element:a,root:t.root,slot:t,type:t.type}))}return s}function P(e,t,n){let r=null;for(let i of e){if(n.immediateStopped)return;if(i.element!==r){if(r!==null&&n.stopped)return;r=i.element}try{Re(i,t)}finally{let e=i.slot;e.element===null&&e.listenerTarget===null&&F(e)}}}function Re(e,t){let n=e.slot;F(n),n.controller=new AbortController;let r=n.controller.signal;_e(()=>{ze(e.root,()=>h(V(e.type),()=>{$e(t,e.element,t=>{e.callback(t,r)})}))})}function ze(e,t){let n=e===null?null:E.get(e)?.scope??null;return n===null?t():n(t)}function F(e){e.controller?.abort(),e.controller=null}function Be(e,t){if(b(e))return[];if(Array.isArray(e)){let n=[];for(let r of e){if(b(r)){n.push(void 0);continue}He(r)||Ve(t),n.push(r)}return n}Ve(t)}function Ve(e){let t=e===``?`an element`:`<${e}>`;throw Error(`The events prop on ${t} must be an array of event descriptors created with on(type, callback).`)}function He(e){return typeof e==`object`&&!!e&&e.$$typeof===ue}function Ue(e){let t=T.get(e);return t===void 0&&(t=[],T.set(e,t)),t}function We(e,t,n,r){ot(r.type)?Ge(e,t,r):Ke(t,n,r)}function Ge(e,t,n){if(n.element===e){t!==null&&(n.root=t);return}R(n),n.element=e,n.root=t,n.listener=t=>{try{Re({callback:n.callback,element:e,root:n.root,slot:n,type:n.type},t)}finally{n.element===null&&n.listenerTarget===null&&F(n)}},e.addEventListener(n.type,n.listener,n.options)}function Ke(e,t,n){e===null||t===null||n.root===e&&n.listenerTarget===t||(R(n),n.root=e,n.listenerTarget=t,I(e,t,n.type,n.options.capture,n.options.passive))}function I(e,t,n,r,i){let a=Ye(t),o=`${n}:${r}:${i}`,s=a.get(o);if(s===void 0){s={capture:r,count:0,listener:a=>Me(e,t,n,r,i,a),passive:i,type:n},t.addEventListener(n,s.listener,{capture:r,passive:i}),a.set(o,s);for(let a of E.get(t)?.portals??[])I(e,a,n,r,i)}s.count+=1}function L(e,t){let n=E.get(e)?.listeners,r=n?.get(t);if(!(n===void 0||r===void 0)&&(--r.count,!(r.count>0))){e.removeEventListener(r.type,r.listener,{capture:r.capture}),n.delete(t);for(let n of E.get(e)?.portals??[])L(n,t)}}function R(e){qe(e),Je(e)}function qe(e){e.element===null||e.listener===null||(e.element.removeEventListener(e.type,e.listener,{capture:e.options.capture}),e.element=null,e.listener=null,e.root=null)}function Je(e){let t=e.listenerTarget;t!==null&&(e.root=null,e.listenerTarget=null,L(t,Xe(e)))}function Ye(e){return O(e).listeners}function Xe(e){return`${e.type}:${e.options.capture}:${e.options.passive}`}function Ze(e,t,n){let r=n.composedPath?.();if(r!==void 0){let n=r.indexOf(t);if(n!==-1)return[...r.slice(0,n).filter(_),...Qe(e,t)]}let i=[];for(let e=n.target;e!==t&&(_(e)&&i.push(e),e=y(e),e!==null););return[...i,...Qe(e,t)]}function Qe(e,t){let n=E.get(t)?.portalOwner??null;if(n===null||n.root!==e)return[];let r=[],i=n.logicalParent;for(;i!==null&&i!==e;){if(st(i)){let t=E.get(i)?.portalOwner??null;if(t!==null&&t.root===e){i=t.logicalParent;continue}}_(i)&&r.push(i),i=y(i)}return r}function z(e,t){for(let n=t;n!==null;){if(n===e)return!0;n=y(n)}return!1}function B(e){for(let t=e;t!==null;){if(st(t)){let e=E.get(t);if(e!==void 0&&(e.portalOwner!==null||e.root))return t}t=y(t)}return null}function $e(e,t,n){let r=Object.getOwnPropertyDescriptor(e,`currentTarget`),i=Reflect.defineProperty(e,"currentTarget",{configurable:!0,value:t});try{return n(e)}finally{i&&(r===void 0?delete e.currentTarget:Object.defineProperty(e,"currentTarget",r))}}function et(e,t,n){let r=e.cancelBubble===!0,i={immediateStopped:!1,stopped:!t&&r},a=nt(e,`stopPropagation`,()=>{i.stopped=!0}),o=nt(e,`stopImmediatePropagation`,()=>{i.stopped=!0,i.immediateStopped=!0}),s=tt(e,i);try{return n(i)}finally{s(),o(),a(),i.stopped&&(e.cancelBubble=!0)}}function tt(e,t){let n=Object.getOwnPropertyDescriptor(e,`cancelBubble`),r=Reflect.defineProperty(e,"cancelBubble",{configurable:!0,get:()=>t.stopped,set(e){e===!0&&(t.stopped=!0)}});return()=>{r&&(n===void 0?delete e.cancelBubble:Object.defineProperty(e,"cancelBubble",n))}}function nt(e,t,n){let r=Reflect.get(e,t);if(typeof r!=`function`)return()=>void 0;let i=Object.getOwnPropertyDescriptor(e,t),a=Reflect.defineProperty(e,t,{configurable:!0,value(){n(),r.call(e)}});return()=>{a&&(i===void 0?delete e[t]:Object.defineProperty(e,t,i))}}function rt(e={}){return{capture:e.capture===!0,passive:e.passive===!0}}function it(e,t){return`${e}:${t.capture}:${t.passive}`}function V(e){return fe.has(e)?`discrete`:me.has(e)?`continuous`:`default`}function at(e){return me.has(e)||e===`touchstart`||e===`touchend`}function ot(e){return ge.has(e)}function st(e){return typeof e==`object`&&!!e&&`addEventListener`in e&&`childNodes`in e}function ct(e){g(e,e=>{ae(e),De(e)})}function H(e){g(e,e=>{ce(e),Oe(e)})}const U=new WeakMap,lt=`http://www.w3.org/1999/xlink`;function W(e,t,n,r={}){let i=v(e),a=ne(e),o=new Set([...Object.keys(t),...Object.keys(n)]);for(let s of o){if(s===`events`){Ee(e,n[s]);continue}if(s===`bind`){ie(e,n[s]);continue}let o=t[s],c=n[s];if(s===`unsafeHTML`){if(r.hydrating===!0){gt(c);continue}o!==c&&ht(e,c);continue}if(!Nt(s)){if(jt(s)){dt(e,i,s,c,n,r);continue}o!==c&&(s===`style`?Tt(e,o,c):K(e,kt(s,a),c))}}_t(e,i,t,n,r),(i===`option`||i===`optgroup`)&&G(e)}function ut(e,t){W(e,{},t,{hydrating:!0})}function dt(e,t,n,r,i,a){if(t===`select`&&Mt(n))return;if(t===`option`&&n===`value`){K(e,`value`,pt(r));return}let o=a.initial===!0&&a.hydrating!==!0;if(n===`value`){if(b(r))return;ft(e,r,t,{live:!0})}else if(n===`defaultValue`)ft(e,r,t,{defaultValue:!0,live:o&&i.value===void 0});else if(n===`checked`){if(r===void 0)return;mt(e,r,{live:!0})}else n===`defaultChecked`&&mt(e,r,{defaultChecked:!0,live:o&&i.checked===void 0})}function ft(e,t,n,r){let i=n===`textarea`,a=pt(t);r.defaultValue===!0&&`defaultValue`in e&&(e.defaultValue=a??``),r.defaultValue===!0&&(i?e.textContent=a??``:K(e,`value`,a)),r.live===!0&&`value`in e?e.value!==(a??``)&&(e.value=a??``):r.live===!0&&a!==null&&K(e,`value`,a)}function pt(e){return b(e)?null:String(e)}function mt(e,t,n){let r=t===!0;n.defaultChecked===!0&&(`defaultChecked`in e&&(e.defaultChecked=r),K(e,`checked`,r)),n.live===!0&&`checked`in e?e.checked=r:n.live===!0&&K(e,`checked`,r)}function ht(e,t){let n=gt(t);`innerHTML`in e&&(e.innerHTML=n??``)}function gt(e){if(b(e))return null;if(typeof e==`string`)return e;throw Error(`The unsafeHTML prop must be a string.`)}function _t(e,t,n,r,i={}){if(t!==`select`)return;let a=r.value!==void 0,o=a?r.value:r.defaultValue;if(o==null||o===!1){U.delete(e);return}let s=!a&&i.hydrating===!0,c=U.get(e),l=!s&&(a||!a&&i.initial===!0),u={appliedDefault:c?.appliedDefault===!0||!a,applyDefaultToInsertedOptions:!s&&!a&&i.initial===!0,controlled:a,selectedValues:vt(o),value:o};U.set(e,u),l&&yt(e,u.selectedValues)}function G(e,t=!1){let n=xt(e);if(n===null)return;let r=U.get(n);r!==void 0&&(!r.controlled&&r.appliedDefault&&!t||!r.controlled&&t&&!r.applyDefaultToInsertedOptions||(yt(e,r.selectedValues),r.controlled||(r.appliedDefault=!0)))}function vt(e){return new Set(Array.isArray(e)?e.map(String):[String(e)])}function yt(e,t){if(v(e)===`option`){bt(e,t);return}St(e,e=>{bt(e,t)})}function bt(e,t){e.selected=t.has(Ct(e))}function xt(e){let t=e.parentNode;for(;t!==null;){if(_(t)&&v(t)===`select`)return t;t=t.parentNode}return null}function St(e,t){for(let n=e.firstChild;n!==null;){let e=n.nextSibling;_(n)&&(v(n)===`option`?t(n):St(n,t)),n=e}}function Ct(e){let t=wt(e,`value`);return t===null?(e.textContent??``).replace(/\s+/g,` `).trim():t}function wt(e,t){return e.getAttribute(t)}function Tt(e,t,n){let r=e.style;if(r===void 0)return;let i=Et(t),a=Et(n);for(let e of Object.keys(i))e in a||Ot(r,e);for(let[e,t]of Object.entries(a))t==null||t===!1?Ot(r,e):Dt(r,e,t)}function Et(e){return typeof e==`object`&&e?e:{}}function Dt(e,t,n){typeof n==`number`||typeof n==`bigint`||(t.startsWith(`--`)&&typeof e.setProperty==`function`?e.setProperty(t,String(n)):e[t]=n)}function Ot(e,t){t.startsWith(`--`)&&typeof e.removeProperty==`function`?e.removeProperty(t):e[t]=``}function kt(e,t){return t?e.toLowerCase():e}function K(e,t,n){if(b(n)){At(e,t);return}if(t===`xlink:href`){e.setAttributeNS(lt,t,String(n));return}e.setAttribute(t,String(n))}function At(e,t){if(t===`xlink:href`){e.removeAttributeNS(lt,`href`);return}e.removeAttribute(t)}function jt(e){return Mt(e)||e===`checked`||e===`defaultChecked`}function Mt(e){return e===`value`||e===`defaultValue`}function Nt(e){return e===`children`||e===`key`||e===`suppressHydrationWarning`||e===`unsafeHTML`||Pt(e)}function Pt(e){return/^on[A-Z]/.test(e)}const q=new WeakMap,J=new WeakMap;function Ft(e,t){let n=X(),r=f(e,t);if(n===null||r===null)return null;let i=m(r),a=Y(n),o=a.get(i),s=o?.element??Ut(n,i)??document.createElement(e);return o===void 0&&(a.set(i,{count:0,element:s,ready:null}),J.set(s,{key:i,kind:r.kind})),s}function It(e){let t=X();if(t===null)return e;let n=Y(t),r=J.get(e);if(r===void 0){let t=d(v(e),t=>e.getAttribute(t));if(t===null)return e;r={key:m(t),kind:t.kind},J.set(e,r)}let i=n.get(r.key);return i!==void 0&&i.element!==e?(i.count+=1,Lt(t,i.element)):(i===void 0?n.set(r.key,{count:1,element:e,ready:null}):i.count+=1,Lt(t,e))}function Lt(e,t){return t.parentNode!==e&&e.appendChild(t),ct(t),t}function Y(e){let t=q.get(e);return t===void 0&&(t=new Map,q.set(e,t)),t}function Rt(e){let t=X(),n=J.get(e);if(t===null||n===void 0)return;let r=q.get(t),i=r?.get(n.key);if(i===void 0||i.element!==e){if(Vt(r,e))return;J.delete(e),Bt(n.kind)&&zt(e);return}i.count>0&&--i.count,!(i.count>0)&&Bt(n.kind)&&(r?.delete(n.key),J.delete(e),zt(e))}function zt(e){H(e),e.parentNode?.removeChild(e)}function Bt(e){return e===`title`||e===`meta`}function Vt(e,t){if(e===void 0)return!1;for(let n of e.values())if(n.element===t)return!0;return!1}function Ht(e,t,n){let r=v(e),i=f(r,n),a=J.get(e),o=i===null?null:m(i);if(o===null||a===void 0||o===a.key)return W(e,t,n),e;Rt(e);let s=X(),c=s===null?void 0:Y(s).get(o),l=c!==void 0&&c.count>0?c.element:void 0,u=Ft(r,n)??e;return u===e?(W(e,t,n),e):(l!==u&&W(u,{},n),It(u))}function X(){return typeof document<`u`&&document.head!==void 0?document.head:null}function Ut(e,t){for(let n of Array.from(e.childNodes)){if(!_(n))continue;let e=d(n.localName,e=>n.getAttribute(e));if(e!==null&&m(e)===t)return n}return null}function Wt(e){let t=X();if(t===null)return Promise.resolve();let n=Y(t),r=[];for(let i of e){if(!ee(i)||i.kind===`title`||i.kind===`meta`)continue;let e=Gt(i),a=m(e),o=n.get(a)?.element,s=(o!==void 0&&o.parentNode===t?o:null)??Ut(t,a);if(s!==null){let t=n.get(a);t?.element!==s&&(t={count:1,element:s,ready:null},n.set(a,t),J.set(s,{key:a,kind:e.kind}));let i=qt(e,t,a,n);i!==null&&r.push(i);continue}let c=Xt(e),l={count:1,element:c,ready:null},u=Kt(e)?Yt(c).then(()=>{n.get(a)===l&&(l.ready=null)}):null;l.ready=u,n.set(a,l),J.set(c,{key:a,kind:e.kind}),t.appendChild(c),u!==null&&r.push(u)}return r.length===0?Promise.resolve():Promise.all(r).then(()=>void 0)}function Gt(e){return e.kind===`font`?{as:`font`,crossOrigin:e.crossOrigin??`anonymous`,fetchPriority:e.fetchPriority,href:e.href,key:e.key,kind:`preload`,type:e.type}:e}function Kt(e){return e.kind!==`stylesheet`||e.blocking===`none`?!1:e.media===void 0||e.media===``||typeof matchMedia!=`function`||matchMedia(e.media).matches}function qt(e,t,n,r){if(!Kt(e))return null;if(t.ready!==null)return t.ready;if(!Jt(t.element))return null;let i=Yt(t.element).then(()=>{r.get(n)===t&&(t.ready=null)});return t.ready=i,i}function Jt(e){return e.localName===`link`&&e.getAttribute(`rel`)===`stylesheet`&&`sheet`in e&&e.sheet===null}function Yt(e){return new Promise(t=>{let n=()=>{e.removeEventListener(`load`,n),e.removeEventListener(`error`,n),t()};e.addEventListener(`load`,n),e.addEventListener(`error`,n)})}function Xt(e){let t=document.createElement(e.kind===`script`?`script`:`link`);for(let[n,r]of p(e))t.setAttribute(n,r===!0?``:r);return t}function Zt(e){if(!Q(e))return null;let t=Z(e);return t===null?null:Qt(e,t)}function Qt(e,t){let n=$t(e);return n===null?null:{end:n,forceClientRender:!1,id:t.id,start:e,get error(){return en(e)},get status(){return Z(e)?.status??t.status}}}function Z(e){if(!Q(e))return null;if(e.data===s)return{id:null,status:`completed`};if(e.data===o)return{id:null,status:`client-rendered`};let t=e.data.startsWith(l)?e.data.slice(l.length):null;return t!==null&&t!==``?{id:t,status:`pending`}:null}function $t(e){let t=0;for(let n=e.nextSibling;n!==null;n=n.nextSibling)if(Q(n)){if(Z(n)!==null){t+=1;continue}if(n.data===c){if(t===0)return n;--t}}return null}function en(e){let t=e.nextSibling;return cn(t)?{digest:t.dataset.dgst,message:t.dataset.msg}:null}function tn(e){if(!ln(e))return null;for(let t=e;t!==null;t=t.parentNode){let e=0;for(let n=t.previousSibling;n!==null;n=n.previousSibling)if(Q(n)){if(n.data===c){e+=1;continue}if(Z(n)!==null){if(e===0)return n;--e}}}return null}function nn(e,t){if(!ln(e))return!1;let n=t.start.parentNode,r=t.end.parentNode;if(n===null&&r===null)return!1;for(let i=e;i!==null;i=i.parentNode){if(i===t.start||i===t.end)return!1;if(n!==null&&i.parentNode===n)return rn(i,t.start,t.end);if(r!==null&&r!==n&&i.parentNode===r)return an(i,t.end)}return!1}function rn(e,t,n){for(let r=e;r!==null;r=r.previousSibling){if(r===t)return!0;if(r===n)return!1}return!1}function an(e,t){for(let n=e;n!==null;n=n.nextSibling)if(n===t)return!0;return!1}function on(e){for(let t=e.start;t!==null;){let n=t.nextSibling;if(sn(t),t===e.end)return;t=n}}function sn(e){e.parentNode?.removeChild(e)}function Q(e){return typeof e==`object`&&!!e&&`data`in e&&`nodeType`in e&&e.nodeType===8}function cn(e){return typeof e==`object`&&!!e&&`dataset`in e}function ln(e){return typeof e==`object`&&!!e&&`parentNode`in e}function un(e,t,n,r){let i=vn(e),a=i.startViewTransition;if(typeof a!=`function`)return!1;let o=!1,s=!1,c=!1,l=null,d=null,f=()=>{t();try{let e=a.call(i,()=>{o=!0,d=n(),d.cancelRootSnapshot&&(l=dn(i))});e!==void 0&&(pn(i,e),fn(i,e,()=>d));let t=e?.finished??e?.ready,s=()=>l?.();t===void 0?(s(),r()):((e?.ready??t).then(r,r),t.then(s,s))}catch(e){if(l?.(),!o){s?(o=!0,n()):c=!0,r();return}if(r(),!s)throw e;setTimeout(()=>{throw e})}},p=i[u],m=p?.finished??p?.ready;return p!=null&&m!==void 0?(s=!0,m.then(f,f),`deferred`):(f(),c?!1:o?`committed`:`deferred`)}function dn(e){let t=e.documentElement;if(t===null)return()=>void 0;let n=t.style,r=n.viewTransitionName??``;return n.viewTransitionName=`none`,()=>{n.viewTransitionName=r,t.getAttribute(`style`)===``&&t.removeAttribute(`style`)}}function fn(e,t,n){let r=[],i=()=>{for(let e of r)try{e.cancel()}catch{}r.length=0},a=()=>{let t=n();if(t===null||t.canceledNames.length===0&&!t.cancelRootSnapshot)return;let i=e.documentElement;if(i===null||typeof i.animate!=`function`)return;let a=e=>{typeof e?.cancel==`function`&&r.push(e)},o=e=>{a(i.animate?.({opacity:[0,0],pointerEvents:[`none`,`none`]},{duration:0,fill:`forwards`,pseudoElement:`::view-transition-group(${e})`}))};try{for(let e of t.canceledNames)o(yn(e));t.cancelRootSnapshot&&(o(`root`),a(i.animate({height:[0,0],width:[0,0]},{duration:0,fill:`forwards`,pseudoElement:`::view-transition`})))}catch{}},o=t.ready??t.finished;o===void 0?a():o.then(a,()=>void 0);let s=t.finished??t.ready;s===void 0?i():s.then(i,i)}function pn(e,t){e[u]=t;let n=()=>{e[u]===t&&(e[u]=null)},r=t.finished??t.ready;r===void 0?n():r.then(n,n)}function mn(e,t){let n=vn(e)[u],r=n?.finished??n?.ready;return n==null||r===void 0?!1:(r.then(t,t),!0)}function hn(e){if(typeof e.getBoundingClientRect!=`function`)return null;let t=e.getBoundingClientRect(),n=e.ownerDocument?.defaultView??null,r=n===null||t.bottom>=0&&t.right>=0&&t.top<=n.innerHeight&&t.left<=n.innerWidth,i=!1;try{i=n?.getComputedStyle(e).position===`absolute`}catch{}return{absolutelyPositioned:i,height:t.height,inViewport:r,width:t.width,x:t.left,y:t.top}}function gn(e,t,n){let r=e.style;r.viewTransitionName=yn(t),n!==null&&(r.viewTransitionClass=n)}function _n(e,t){let n=e.style,r=t.style,i=r?.viewTransitionName??r?.[`view-transition-name`],a=r?.viewTransitionClass??r?.[`view-transition-class`];n.viewTransitionName=bn(i),n.viewTransitionClass=bn(a)}function vn(e){return`ownerDocument`in e&&e.ownerDocument!==null?e.ownerDocument:document}function yn(e){let t=globalThis.CSS?.escape;return t===void 0?e:t(e)}function bn(e){return typeof e==`string`||typeof e==`number`?String(e).trim():``}const $=te({createInstance:(e,t,n)=>kn(e,t,n),createTextInstance:e=>document.createTextNode(e),validateInstanceNesting:(e,t,n)=>{},validateTextNesting:(e,t)=>{},containerType:e=>_(e)?v(e):null,appendInitialChild:(e,t)=>{e.appendChild(t),_(t)&&Rn(t)&&G(t,!0)},finalizeInitialInstance:(e,t)=>W(e,{},t,{initial:!0}),setTextContent:(e,t)=>{e.textContent!==t&&(e.textContent=t)},getFirstHydratableChild:(e,t)=>jn(e,t),getNextHydratableSibling:e=>Mn(e.nextSibling),canHydrateInstance:(e,t,n)=>On(e,t,n),canHydrateTextInstance:(e,t,n)=>Ln(e)&&(n===!0||e.nodeValue===t),isHoistedInstance:(e,t)=>f(e,t)!==null,commitHoistedInstance:e=>It(e),removeHoistedInstance:e=>Rt(e),updateHoistedInstance:(e,t,n)=>Ht(e,t,n),shouldCommitUpdate:(e,t,n)=>zn(e,n),clearContainer:e=>{let t=e.firstChild;for(;t!==null;){let n=t.nextSibling;H(t),e.removeChild(t),t=n}queueMicrotask(j)},insertBefore:(e,t,n)=>{e.insertBefore(t,n),_(t)&&Rn(t)&&G(t),ct(t)},removeChild:(e,t)=>{H(t),e.removeChild(t)},commitTextUpdate:(e,t)=>{e.nodeValue!==t&&(e.nodeValue=t)},commitUpdate:(e,t,n)=>W(e,t,n),commitHydratedInstance:(e,t)=>ut(e,t),getActivityBoundary:e=>Dn(e)?e:null,getFirstActivityHydratable:e=>Mn(En(e).firstChild??null),commitHydratedActivityBoundary:e=>{let t=e.parentNode;if(t===null)return;let n=En(e);for(;n.firstChild!==null;)t.insertBefore(n.firstChild,e);t.removeChild(e)},hideInstance:e=>{oe(e),e.style.setProperty(`display`,`none`,`important`)},unhideInstance:(e,t)=>{let n=(t.style??{}).display;e.style.setProperty(`display`,typeof n==`string`?n:``),se(e)},hideTextInstance:e=>{e.nodeValue=``},unhideTextInstance:(e,t)=>{e.nodeValue!==t&&(e.nodeValue=t)},getSuspenseBoundary:e=>Zt(e),getEnclosingSuspenseBoundaryStart:e=>tn(e),isTargetWithinSuspenseBoundary:(e,t)=>nn(e,t),registerSuspenseBoundaryRetry:(e,t)=>{e.start.__figRetry=t},commitHydratedSuspenseBoundary:e=>{e.status===`completed`&&!e.forceClientRender?(sn(e.start),sn(e.end)):on(e),queueMicrotask(j)},removeDehydratedSuspenseBoundary:e=>{on(e),queueMicrotask(j)},completeRootHydration:e=>{Ce(e),queueMicrotask(j)},preparePortalContainer:(e,t,n)=>{Ae(e,t,n)},removePortalContainer:e=>{A(e)},viewTransition:{commit:un,apply:gn,restore:_n,measure:hn,suspend:mn}});ve($.batchedUpdates),e($.scheduleRefresh);const xn=$.flushSync;function Sn(e,t){let n=$.createRoot(e,t);return ye(e,void 0,e=>n.data.run(e)),wn(n,e)}function Cn(e,t,n){let r=$.hydrateRoot(e,t,n);return ye(e,(t,n)=>$.hydrateTarget(e,t,n),e=>r.data.run(e)),wn(r,e)}function wn(e,t){return{...e,unmount:()=>{e.unmount(),Se(t)}}}function Tn(e,n,r=null){return t(e,n,r)}function En(e){return`content`in e?e.content:e}function Dn(e){return v(e)===`template`&&`getAttribute`in e&&e.getAttribute(n)!==null}function On(e,t,n){return!_(e)||!(`setAttribute`in e)||v(e)!==t.toLowerCase()?!1:In(e,n)}function kn(e,t,n){let r=Ft(e,t);if(r!==null)return r;let i=An(e,n);return i===`http://www.w3.org/1999/xhtml`?document.createElement(e):document.createElementNS(i,e)}function An(e,t){let n=e.toLowerCase();return n===`svg`?`http://www.w3.org/2000/svg`:n===`math`?`http://www.w3.org/1998/Math/MathML`:`namespaceURI`in t&&v(t)!==`foreignobject`?t.namespaceURI??`http://www.w3.org/1999/xhtml`:`http://www.w3.org/1999/xhtml`}function jn(e,t){return t!==void 0&&Fn(t)!==null||v(e)===`textarea`&&t!==void 0&&Pn(t)?null:Mn(e.firstChild)}function Mn(e){let t=e;for(;t!==null&&Nn(t);)t=t.nextSibling;return t}function Nn(e){return`nodeType`in e&&e.nodeType===8&&e.data===`,`}function Pn(e){return e.value!==void 0||e.defaultValue!==void 0}function Fn(e){return b(e.unsafeHTML)?null:e.unsafeHTML}function In(e,t){let n=Fn(t);return n===null||typeof n!=`string`||`innerHTML`in e}function Ln(e){return`nodeType`in e&&e.nodeType!==3?!1:!(`setAttribute`in e)&&`nodeValue`in e}function Rn(e){let t=v(e);return t===`option`||t===`optgroup`}function zn(e,t){return(e===`input`||e===`textarea`||e===`select`)&&(t.value!==void 0||t.checked!==void 0)}export{re as composeBind,Tn as createPortal,Sn as createRoot,xn as flushSync,Cn as hydrateRoot,Wt as insertAssetResources,Te as on};
1
+ import{a as e,i as t,n,o as r,r as i,t as a}from"./renderer-HA5C4hQE.js";import{assertPayloadCodecMatches as o,createPortalNode as s,jsonPayloadCodec as c,loadContextCapabilities as l}from"@bgub/fig/internal";import{dataResource as u,readData as d}from"@bgub/fig";import{decodePayloadStream as f}from"@bgub/fig/payload";const p=()=>void 0;async function m(e,t,r={}){let{signal:i}=t;if(i.aborted)throw await e.body?.cancel().catch(p),h(i);if(!e.ok)throw await e.body?.cancel().catch(p),Error(`Payload request failed with status ${e.status}.`);let a=e.body;if(a===null)throw Error(`Payload response did not include a body.`);try{o(c,e.headers.get(`content-type`))}catch(e){throw await a.cancel().catch(p),e}let s=l(t);return f(a,{hydrate:s?.hydrate,onHoleError:s?.attributeError,onStreamDone:e=>{},prepareAssets:r.prepareAssets??(e=>n(e)),retainAssets:r.retainAssets,resolveClientReference:r.resolveClientReference,signal:i})}function h(e){return e.reason??Error(`Payload request aborted.`)}function g(e){let t=new WeakMap,n=1;function r(e){if(e===null)return null;if(e===void 0)return[`undefined`];if(typeof e==`string`||typeof e==`boolean`)return e;if(typeof e==`number`)return Number.isNaN(e)?[`number`,`NaN`]:e===1/0?[`number`,`Infinity`]:e===-1/0?[`number`,`-Infinity`]:Object.is(e,-0)?[`number`,`-0`]:e;if(typeof e==`bigint`)return[`bigint`,e.toString()];if(typeof e==`symbol`){let t=Symbol.keyFor(e);if(t===void 0)throw Error(`Only global Symbol.for symbols can be serialized.`);return[`symbol`,t]}if(typeof e==`function`)throw Error(`Functions cannot be serialized into the payload.`);if(e instanceof Date){let t=e.toJSON();if(t===null)throw Error(`Invalid Date values cannot be serialized.`);return[`date`,t]}let i=t.get(e);if(i!==void 0)return[`ref`,i];let a=n++;if(t.set(e,a),Array.isArray(e))return[`array`,a,e.map(r)];if(e instanceof Map)return[`map`,a,Array.from(e,([e,t])=>[r(e),r(t)])];if(e instanceof Set)return[`set`,a,Array.from(e,r)];let o=Object.getPrototypeOf(e);if(o!==Object.prototype&&o!==null)throw Error(`Cannot serialize ${o?.constructor?.name??`object`} into the payload.`);let s=e;return[`object`,a,Object.keys(s).sort().map(e=>[e,r(s[e])])]}return r(e)}function _(e){let t=t=>{let n=v(t);return[...e.key,e.cacheKey===void 0?n:e.cacheKey(t)]},n=u({debugArgs:e.cacheKey===void 0?void 0:v,key:t,load:async(n,r)=>{let i=await e.load(n,{key:l(r)?.key??t(n),signal:r.signal});return m(i instanceof Response?i:new Response(i.stream,{headers:{"content-type":i.contentType}}),r,{prepareAssets:e.prepareAssets??e.load.prepareAssets,resolveClientReference:e.resolveClientReference??e.load.resolveClientReference,retainAssets:e.retainAssets??e.load.retainAssets})}}),r=Object.assign(function(e){return y(e),d(r,e)},n);return Object.defineProperty(r,"displayName",{configurable:!0,value:`Payload(${e.key[0]})`}),r}function v(e){return y(e),g(e)}function y(e){if(Object.hasOwn(e,`children`))throw Error(`Payload components do not accept children.`)}const b=a.flushSync;function x(e,t){let n=a.createRoot(e,t);return i(e,{run:e=>n.data.run(e)}),w(n,e)}function S(e,t,n){let r=a.hydrateRoot(e,t,n);return i(e,{hydrate:(t,n)=>a.hydrateTarget(e,t,n),run:e=>r.data.run(e)}),w(r,e)}function C(e,t,n=null){return s(e,t,n)}function w(e,n){return{...e,unmount:()=>{e.unmount(),t(n)}}}export{r as composeBind,_ as createPayloadComponent,C as createPortal,x as createRoot,b as flushSync,S as hydrateRoot,n as insertAssetResources,e as on};
2
2
  //# sourceMappingURL=index.js.map