@solidjs/web 2.0.0-rc.14 → 2.0.0-rc.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +1 -1
  2. package/dist/server.dev.js +475 -591
  3. package/dist/server.js +459 -489
  4. package/dist/server.observe.js +459 -498
  5. package/dist/web.dev.js +206 -220
  6. package/dist/web.js +196 -208
  7. package/dist/web.observe.js +206 -213
  8. package/frames/dist/client.dev.js +664 -643
  9. package/frames/dist/client.js +593 -582
  10. package/frames/dist/client.observe.js +624 -589
  11. package/frames/dist/regions.js +43 -2
  12. package/frames/dist/server.dev.js +578 -450
  13. package/frames/dist/server.js +578 -397
  14. package/frames/dist/server.observe.js +578 -397
  15. package/frames/dist/trace.js +4 -1
  16. package/frames/dist/wire.js +371 -6
  17. package/package.json +13 -13
  18. package/serialization/dist/decode.js +11 -9
  19. package/serialization/dist/serialization.js +11 -9
  20. package/serialization/types/serializer-decode.d.ts +2 -2
  21. package/server-functions/dist/client.dev.js +5 -2
  22. package/server-functions/dist/client.js +3 -2
  23. package/server-functions/dist/client.observe.js +5 -2
  24. package/server-functions/dist/rich-args.js +33 -1
  25. package/server-functions/dist/server.dev.js +218 -35
  26. package/server-functions/dist/server.js +218 -35
  27. package/server-functions/dist/server.observe.js +218 -35
  28. package/skills/server-components/SKILL.md +74 -185
  29. package/types/client.d.ts +112 -10
  30. package/types/constants.d.ts +2 -1
  31. package/types/frames/assets-tier.d.ts +2 -2
  32. package/types/frames/client.d.ts +8 -3
  33. package/types/frames/frame-client.d.ts +121 -157
  34. package/types/frames/frame-morph.d.ts +28 -0
  35. package/types/frames/frame-sink.d.ts +13 -9
  36. package/types/frames/frame-transport.d.ts +30 -1
  37. package/types/frames/regions-tier.d.ts +15 -0
  38. package/types/frames/serializer-decode.d.ts +2 -2
  39. package/types/frames/server.d.ts +1 -53
  40. package/types/frames/wire-tier.d.ts +54 -1
  41. package/types/head.d.ts +1 -0
  42. package/types/index.d.ts +57 -50
  43. package/types/index.server.d.ts +3 -27
  44. package/types/jsx.d.ts +14 -17
  45. package/types/observe.d.ts +14 -7
  46. package/types/render.d.ts +3 -1
  47. package/types/response.d.ts +31 -8
  48. package/types/serializer-decode.d.ts +2 -2
  49. package/types/server-functions/argument-codec.d.ts +21 -0
  50. package/types/server-functions/client.d.ts +18 -5
  51. package/types/server-functions/server.d.ts +6 -2
  52. package/types/server-functions/shared.d.ts +19 -0
  53. package/types/server-mock.d.ts +9 -2
  54. package/types/server-observe.d.ts +3 -2
  55. package/types/server.d.ts +124 -67
  56. package/frames/dist/bind.dev.js +0 -326
  57. package/frames/dist/bind.js +0 -295
  58. package/types/frames/bind-tier.d.ts +0 -60
package/types/server.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { getOwner, createComponent, untrack, merge as mergeProps } from "solid-js";
2
- import { sharedConfig, ssrScope as scope } from "solid-js/internal";
2
+ import { ssrScope as scope } from "solid-js/internal";
3
+ import type { Owner } from "solid-js";
3
4
  import type { ServerErrorSite } from "solid-js/internal";
4
5
  import { effect, memo } from "./render.js";
5
6
  import { type TraceContext } from "./trace.js";
@@ -106,9 +107,9 @@ export type AssetResolverFn = (key: string) => ResolvedAssets | null | undefined
106
107
  * fallback reaches `script-src`. A nonce on a `useHead` tag's own props
107
108
  * always wins.
108
109
  *
109
- * Only `renderToString` / `renderToStream` take this shape. Surfaces that
110
- * emit one script (`HydrationScript`, `generateHydrationScript`,
111
- * `createSSRResponse`) take a string — project with `scriptNonce`.
110
+ * Surfaces that emit one script (`HydrationScript`,
111
+ * `generateHydrationScript`, `createSSRResponse`) take either shape and use
112
+ * its script half.
112
113
  */
113
114
  export type CSPNonce = string | {
114
115
  script: string | false;
@@ -203,8 +204,8 @@ export type { ServerFunction, ServerFunctionMetadata, ServerFunctionRPC } from "
203
204
  export interface SSRResponseOptions {
204
205
  /** Base head; the stub's status/headers win over it. */
205
206
  responseInit?: ResponseInit;
206
- /** Nonce carried by the post-flush `<script>` redirect fallback. */
207
- nonce?: string;
207
+ /** Nonce carried by the post-flush `<script>` redirect fallback (its script half). */
208
+ nonce?: CSPNonce;
208
209
  /** Rewrites each outgoing HTML chunk (entry script injection, ...). */
209
210
  transformChunk?: (chunk: string) => string;
210
211
  }
@@ -215,10 +216,7 @@ export interface SSRResponseOptions {
215
216
  */
216
217
  export type FetchMiddleware = (request: Request, next: (request?: Request) => Promise<Response>) => Response | Promise<Response>;
217
218
  export { createComponent, effect, memo, untrack, mergeProps, scope, getOwner };
218
- export { sharedConfig };
219
219
  export { DOMWithState, ChildProperties, DOMElements, SVGElements, MathMLElements, VoidElements, RawTextElements, Namespaces, DelegatedEvents } from "./constants.js";
220
- export declare function scriptNonce(nonce?: CSPNonce): string | undefined;
221
- export declare function styleNonce(nonce?: CSPNonce): string | undefined;
222
220
  export declare function useHead(tag: HeadTag | HeadTag[] | (() => HeadTag | HeadTag[])): void;
223
221
  export declare function renderToString<T>(fn: () => T, options?: {
224
222
  nonce?: CSPNonce;
@@ -266,7 +264,8 @@ export declare function renderToStream<T>(fn: () => T, options?: {
266
264
  * `<Errored>` fallback (`handling: "fallback"`), a rejected fragment
267
265
  * (`"client"`), a hydration value that would not serialize
268
266
  * (`"serialize"`) — and the one that fails the request (`"failed"`),
269
- * once per error, with where it was met. A one-argument listener still
267
+ * once per error per kind per request (per render outside one), with
268
+ * where it was met. A one-argument listener still
270
269
  * works; it hears them all — filter on `context.handling` for the
271
270
  * request-failing ones alone. Without a hook (here or ambient) a
272
271
  * failure that fails the request goes to `console.error`.
@@ -331,7 +330,7 @@ export declare function renderToStream<T>(fn: () => T, options?: {
331
330
  readonly readable: ReadableStream<Uint8Array>;
332
331
  };
333
332
  export declare function HydrationScript(props: {
334
- nonce?: string;
333
+ nonce?: CSPNonce;
335
334
  eventNames?: string[];
336
335
  }): JSX.Element;
337
336
  export declare function ssrGroup<T extends () => any[]>(fn: T, n: number): T;
@@ -349,12 +348,34 @@ export declare function ssrGroup<T extends () => any[]>(fn: T, n: number): T;
349
348
  * commit through the render core, and the response's end-latch sweep is
350
349
  * always the last one).
351
350
  */
352
- export declare function createLiveHoles(sink: any, scoped: any): {
351
+ export declare function createLiveHoles(sink: any, scoped: any, settled: any, errorScope: any): {
353
352
  suppressed: number;
354
353
  sweeping: boolean;
355
354
  parent: any;
356
- recordStamp: number;
357
355
  gateHit: boolean;
356
+ sweptOwners: boolean;
357
+ scope: any;
358
+ visit: any;
359
+ dry: boolean;
360
+ /**
361
+ * The id of a positional slot call: at render time (and on a retry,
362
+ * which renders) the render-positional id the proxy minted, `given`,
363
+ * kept for the call's position; on a sweep, the id that position had —
364
+ * or, for a position no render reached, `prop#~<scope>.<n>` (the `~`
365
+ * keeps it apart from render ids and `$key` ids, whose alphabet has
366
+ * none). Outside every hole, `given` as it is.
367
+ */
368
+ slotId(prop: any, given: any): any;
369
+ /** A slot occurrence reached by the evaluation in progress; `forget` runs
370
+ * once a re-evaluation of its hole no longer reaches it. */
371
+ seen(id: any, forget: any): void;
372
+ /**
373
+ * Enter a nested hole's scope on the path that resolves it unminted (a
374
+ * sweep's interior, a suppressed window): the same scope a first render
375
+ * gives it inside `content()`. Returns the scope to restore, or
376
+ * undefined when none was entered.
377
+ */
378
+ nest(hole: any): any;
358
379
  /**
359
380
  * Intercept a thunk content hole: resolve it, and — when the evaluation
360
381
  * proves re-runnable — mint an id, wrap the output in its marker pair,
@@ -370,8 +391,9 @@ export declare function createLiveHoles(sink: any, scoped: any): {
370
391
  mint(): number;
371
392
  /** Whether interception may arm at the current evaluation point —
372
393
  * `ssr()` asks before opening an attr capture (the `data-lha`
373
- * injection must not touch out-of-scope bytes; content holes are
374
- * gated inside `content()` itself). */
394
+ * injection must not touch out-of-scope bytes, nor address an element
395
+ * nothing can change; content holes are gated inside `content()`
396
+ * itself). */
375
397
  active(): boolean;
376
398
  /**
377
399
  * Register an element's attr-hole capture (built by `ssr()`'s in-tag
@@ -397,60 +419,39 @@ export declare function ssrStyle(value: string | {
397
419
  }): string;
398
420
  export declare function ssrStyleProperty(name: string, value: any): string;
399
421
  export declare function ssrStyleProperties(...entries: any[]): string;
400
- export declare function ssrElement(name: string, props: any | any[] | (() => any | any[]), children: any, needsId: boolean, skip?: (key: string) => boolean, attrs?: string | (() => string), claims?: () => Record<number, Record<string, unknown>>): {
422
+ export declare function ssrElement(name: string, props: any | any[] | (() => any | any[]), children: any, needsId: boolean, skip?: (key: string) => boolean, attrs?: string | (() => string)): {
401
423
  t: string;
402
424
  };
403
425
  export declare function ssrElementAttribute(key: string, value: any): string;
404
426
  export declare function ssrAttribute(key: string, value: any): string;
405
427
  export declare function ssrHydrationKey(): string;
406
- export declare const CLAIMS_STREAM = 1;
407
- export declare const CLAIMS_DOCUMENT = 2;
408
- /** The brand on a binding slot's stand-in for one property read. */
409
- export declare const SLOT_VALUE: unique symbol;
410
- /** Marker attribute prefix on a consuming element (`_s:class`, `_s:on:click`, `_s:ref`). */
411
- export declare const SLOT_MARKER = "_s:";
412
- /** Faces a stand-in can come from (`slotValue`'s `face`). */
413
- export declare const SLOT_FACE_STREAM = 0;
414
- export declare const SLOT_FACE_DATA = 1;
415
- export declare const SLOT_FACE_MARKUP = 2;
416
- export declare function isSlotValue(value: unknown): boolean;
417
428
  /**
418
- * A binding slot's stand-in for one property read. `face` says what the
419
- * occurrence's fill produced where this read happens: nothing (the stream
420
- * face never runs fills), a data object (the document face — `value` is
421
- * the t=0 value of `key`), or markup (the document face ran the fill and
422
- * it returned content — a read off it is a dev finding at the position).
423
- * The server has no value to compute with — on the stream face none at
424
- * all, on the document face only the t=0 one — so the ONLY thing a stand-in
425
- * can be is the whole value at one position. Every coercion the runtime can
426
- * see (a template literal, `+`, a comparison, an explicit `String()`) is a
427
- * dev finding, and it renders NOTHING on either face: the document face
428
- * never shows a t=0 value the stream face cannot reproduce, so a misuse is
429
- * visible on the first render rather than on the first refetch. Truthiness
430
- * (`if (row.done)`, `row.x && …`) has no hook and is the one misuse only
431
- * the rule can catch — a stand-in is an object and always truthy.
432
- * @internal Created by the slot proxies (frames server).
429
+ * A render's link handler (`setLinkClaim`): given an anchor's link-relevant
430
+ * attributes — `href`, and `target` / `rel` / `download` / `link` /
431
+ * `aria-current` when present, raw values as written — returns the extra
432
+ * attribute markup for the anchor, each attribute with its leading space
433
+ * (`" data-active"`, `' data-active aria-current="page"'`), or `""`.
434
+ * Synchronous and pure; the markup is the handler's own and is written
435
+ * verbatim.
436
+ * @internal
433
437
  */
434
- export declare function slotValue(occurrence: string, key: string, value: unknown, face: number): object;
438
+ export type LinkClaimHandler = (attrs: Readonly<Record<string, unknown>>) => string;
435
439
  /**
436
- * The compiled per-element hole for ref/onXxx positions on a server
437
- * intrinsic (behind the `serverComponents` compiler option):
438
- * `ctx.claims ? ssrClaim({ click: expr, ref: expr2 }) : ""`. The compiler
439
- * drops handler and ref expressions from plain SSR output, so this is
440
- * where a stand-in at one of those positions is seen. A server-local
441
- * function there can never run (the server has no client to run it on);
442
- * dev says so, inside the component barrier only. An element with a
443
- * handler position bound is an EVENT-SLOT consumer and carries the
444
- * replay-window stamp beside its markers (`eventSlotStamp`).
440
+ * Compiler-emitted hole after a candidate anchor's attributes in SSR output:
441
+ * the render's link handler's markup for the anchor (`setLinkClaim`), or
442
+ * `""` when the render has no handler. An author-written `aria-current`
443
+ * wins — the handler is not consulted for that anchor. Not for hand-written
444
+ * code.
445
+ * @internal
445
446
  */
446
- export declare function ssrClaim(map: Record<string, unknown>): string;
447
+ export declare function ssrLinkClaim(attrs: Readonly<Record<string, unknown>>): string;
447
448
  export declare function ssrSelectValues(): void;
448
449
  export declare function resolveSSRSelectValues(html: any): any;
449
450
  export declare function escape(s: any, attr?: boolean): any;
450
451
  export declare function getHydrationKey(): string | undefined;
451
452
  export declare function applyRef(r: ((element: any) => void) | ((element: any) => void)[], element: any): void;
452
453
  export declare function generateHydrationScript(options?: {
453
- nonce?: string;
454
+ nonce?: CSPNonce;
454
455
  eventNames?: string[];
455
456
  }): string;
456
457
  export declare function resolveSSRNode(node: any, result?: any, top?: boolean, nested?: boolean): any;
@@ -482,13 +483,20 @@ export interface ServerErrorContext extends Omit<ServerErrorSite, "event"> {
482
483
  }
483
484
  /**
484
485
  * The server error hook (see `configureServerErrors`): every failure the
485
- * server runtime handles or fails on, once per error object, with where it
486
- * was met. Return the value the client should receive in place of the error
487
- * — rendered into the fallback, serialized for hydration, sent as the RPC
488
- * error — or nothing for the default policy (a generic `Error` outside the
489
- * dev build, the error itself in it; `markSafeError` still passes through).
486
+ * server runtime handles or fails on, once per error object per `kind` per
487
+ * request (per render when no request is in scope — never once per
488
+ * process: an error object one request met and another meets again is
489
+ * heard by both), with where it was met. A direct server-function call that
490
+ * throws during SSR and the `<Errored>` that contains it are heard as both:
491
+ * `server-function` (the call failed), then `render` (the render fell back),
492
+ * so `kind: "render"` alone answers whether a render failed. Return the value the client should receive in
493
+ * place of the error — rendered into the fallback, serialized for
494
+ * hydration, sent as the RPC error — or nothing for the default policy (a
495
+ * generic `Error` outside the dev build, the error itself in it;
496
+ * `markSafeError` still passes through).
490
497
  * A returned value is taken as intended client-facing content and is not
491
- * sanitized again. Ignored for `handling: "failed"`, which has no wire.
498
+ * sanitized again. Ignored for `handling: "failed"`, which has no wire, and
499
+ * once an earlier kind's sight gave one: every road carries the first.
492
500
  *
493
501
  * One road a mapping does not reach: a rejected async source's serialized
494
502
  * rejection is encoded the moment the source rejects, ahead of the boundary
@@ -506,9 +514,10 @@ export interface ServerErrorsConfig {
506
514
  * `init()` makes to see every failure the runtime handles in production:
507
515
  * an `<Errored>` fallback rendered, a `<Loading>` fragment rejected, a
508
516
  * server-function throw (HTTP dispatch or an in-process call during SSR),
509
- * the failure that fails a request. Called once per error object, at first
510
- * sight, wherever the runtime met it; its return, when given, is the wire
511
- * value (see `ServerErrorHook`). A per-request hook — `renderToStream`'s
517
+ * the failure that fails a request. Called once per error object per kind
518
+ * per request (per render outside one), at first sight, wherever the runtime
519
+ * met it; its return, when given, is the wire value (see
520
+ * `ServerErrorHook`). A per-request hook — `renderToStream`'s
512
521
  * `onError`, the server-function handler's — overrides it for that
513
522
  * request. Registered on `globalThis` under a registered symbol, so a
514
523
  * bundled server build and an instrumented `--import`ed module share it.
@@ -529,8 +538,8 @@ export declare function configureServerErrors(config: ServerErrorsConfig): void;
529
538
  * function the runtime reports, such as a throw a framework's request
530
539
  * handler catches from its middleware. The ambient server error hook hears
531
540
  * it as `{ kind: "request", handling: "failed", event }`, once per error
532
- * object, and its return is ignored, as for every `handling: "failed"`. A
533
- * render failure is the render's: a synchronous throw out of
541
+ * object per request, and its return is ignored, as for every `handling:
542
+ * "failed"`. A render failure is the render's: a synchronous throw out of
534
543
  * `renderToString` or `renderToStream` was already heard as `kind:
535
544
  * "render"` before the caller caught it, so reporting it here adds nothing.
536
545
  * With no hook registered the failure goes to `console.error`, as a render
@@ -595,6 +604,39 @@ export type HydrationValue<T = unknown> = {
595
604
  * ```
596
605
  */
597
606
  export declare function getHydrationWriter(): HydrationWriter | undefined;
607
+ /**
608
+ * Sets the link handler of the render the caller belongs to — found through
609
+ * the caller's owner (component setup), else through the request scope when
610
+ * exactly one render is open for it — so every candidate anchor rendered
611
+ * from here on carries the handler's markup (`aria-current="page"`,
612
+ * `data-active`) in the server HTML. Returns `false` outside any render.
613
+ *
614
+ * Scoped to the render: concurrent renders never share a handler, and it is
615
+ * gone with the render. Set once per render, typically from a router's
616
+ * server render with its request's location; `undefined` clears it. Anchors
617
+ * serialized BEFORE the call (a document shell above the router) are not
618
+ * marked. Server components inline in the document render under the page's
619
+ * handler; a server component's own frame stream has none unless its render
620
+ * sets one.
621
+ *
622
+ * The first call with a handler writes the `links` hydration record once for
623
+ * the response (`hasServerLinkState()` on the client), the signal that the
624
+ * anchors' link state is the server's and can be trusted at hydration.
625
+ *
626
+ * @example
627
+ * ```ts
628
+ * // in <Router>'s server render
629
+ * setLinkClaim(attrs => matchLink(attrs, location) ? ' data-active aria-current="page"' : "");
630
+ * ```
631
+ * @internal
632
+ */
633
+ export declare function setLinkClaim(handler: LinkClaimHandler | undefined): boolean;
634
+ /**
635
+ * Server: `false`. The client reads the `links` hydration record a render
636
+ * with a link handler wrote (`setLinkClaim`); see the client entry.
637
+ * @internal
638
+ */
639
+ export declare function hasServerLinkState(): boolean;
598
640
  /** Server stub — the registry is the client's. See the client entry. */
599
641
  export declare function takeHydrationValue<T = unknown>(_key: string): HydrationValue<T> | undefined;
600
642
  /**
@@ -627,8 +669,23 @@ export declare function createSSRResponse(result: {
627
669
  }): void;
628
670
  }, event: RequestEvent | undefined, options?: SSRResponseOptions): Promise<Response>;
629
671
  export declare function composeMiddleware(middlewares: FetchMiddleware[]): (request: Request, next: (request?: Request) => Response | Promise<Response>) => Promise<Response>;
630
- export declare function registerElementClaim(handler: (element: Element) => void): () => void;
631
- export declare function claimElement<T extends Element>(node: T): T;
672
+ /**
673
+ * Options for `registerElementClaim` (see the client entry); inert on the server.
674
+ * @internal
675
+ */
676
+ export type ElementClaimOptions = {
677
+ /**
678
+ * Attribute names whose compiler-owned writes re-claim an already claimed
679
+ * element, as plain names (`href` covers `prop:href` and `xlink:href`).
680
+ * Defaults to `["href", "action"]`.
681
+ */
682
+ attributes?: readonly string[];
683
+ }; /**
684
+ * Server no-op: element claims are a client-only concern, but consumers may
685
+ * register isomorphically. Returns a no-op unregister function.
686
+ */
687
+ export declare function registerElementClaim(handler: (element: Element) => void, options?: ElementClaimOptions): () => void;
688
+ export declare function claimElement<T extends Element>(node: T, owner?: Owner | null): T;
632
689
  export declare function claimElementTree<T extends Node>(root: T): T;
633
690
  /** Server: `fn()`. No event is dispatched during SSR, so there is no interaction to join. */
634
691
  export declare function dispatchAsInteraction<T>(_e: Event, fn: () => T): T;
@@ -1,326 +0,0 @@
1
- import { DEV, OBSERVE, createSignal, untrack, createRenderEffect, onCleanup } from 'solid-js';
2
- import { assign, runHydrationEvents } from '@solidjs/web';
3
- import { sharedConfig } from 'solid-js/internal';
4
- import { isAsyncValue as isAsyncValue$1 } from '@solidjs/web/frames';
5
-
6
- const SLOT_MARKER = "_s:";
7
- const SLOT_TEXT = SLOT_MARKER + "t=";
8
- function isAsyncValue(v) {
9
- return v !== null && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
10
- }
11
- function shapeOf(v) {
12
- return v === null ? "null" : typeof Node === "function" && v instanceof Node ? "a DOM node" : Array.isArray(v) ? "an array" : isAsyncValue(v) ? "an async value" : typeof v;
13
- }
14
- function slotShapeFinding(data, message) {
15
- DEV.report(OBSERVE.diagnostics.emit({
16
- code: "BINDING_SLOT_POSITION",
17
- kind: "render",
18
- severity: "warn",
19
- message,
20
- data
21
- }, null));
22
- }
23
-
24
- function slotEntry(entry, pos) {
25
- const colon = entry.indexOf(":");
26
- if (colon < 1) return null;
27
- const eq = entry.indexOf("=", colon);
28
- return [entry.slice(0, colon), {
29
- pos,
30
- key: decodeURIComponent(eq === -1 ? entry.slice(colon + 1) : entry.slice(colon + 1, eq)),
31
- name: eq === -1 ? undefined : decodeURIComponent(entry.slice(eq + 1))
32
- }];
33
- }
34
- function consumersOf(elements, occurrence) {
35
- let consumers = elements.get(occurrence);
36
- if (consumers === undefined) elements.set(occurrence, consumers = []);
37
- return Array.isArray(consumers) ? consumers : null;
38
- }
39
- function text(start, elements) {
40
- const parsed = slotEntry(start.data.slice(SLOT_TEXT.length), "text");
41
- const consumers = parsed && consumersOf(elements, parsed[0]);
42
- if (!consumers) return;
43
- const element = start.parentNode;
44
- let consumer;
45
- for (let i = consumers.length; i-- && !consumer;) if (consumers[i].element === element) consumer = consumers[i];
46
- consumer || consumers.push(consumer = {
47
- element,
48
- positions: []
49
- });
50
- parsed[1].start = start;
51
- consumer.positions.push(parsed[1]);
52
- }
53
- function slotPositions(el) {
54
- const attrs = el.attributes;
55
- let out = null;
56
- for (let i = 0; i < attrs.length; i++) {
57
- const attr = attrs[i];
58
- if (!attr.name.startsWith(SLOT_MARKER)) continue;
59
- const pos = attr.name.slice(SLOT_MARKER.length);
60
- for (const entry of attr.value.split(",")) {
61
- const parsed = slotEntry(entry, pos);
62
- if (!parsed) continue;
63
- out || (out = Object.create(null));
64
- (out[parsed[0]] || (out[parsed[0]] = [])).push(parsed[1]);
65
- }
66
- }
67
- return out;
68
- }
69
- function positions(el, elements) {
70
- const byOccurrence = slotPositions(el);
71
- if (byOccurrence !== null) {
72
- for (const occurrence in byOccurrence) {
73
- const consumers = consumersOf(elements, occurrence);
74
- if (consumers) consumers.push({
75
- element: el,
76
- positions: byOccurrence[occurrence]
77
- });
78
- }
79
- }
80
- }
81
- function consumersEqual(a, b) {
82
- if (a.length !== b.length) return false;
83
- for (let i = 0; i < a.length; i++) {
84
- const x = a[i];
85
- const y = b[i];
86
- if (x.element !== y.element || x.positions.length !== y.positions.length) return false;
87
- for (let j = 0; j < x.positions.length; j++) {
88
- const p = x.positions[j];
89
- const q = y.positions[j];
90
- if (p.pos !== q.pos || p.key !== q.key || p.name !== q.name || p.start !== q.start) return false;
91
- }
92
- }
93
- return true;
94
- }
95
- const byFrame = new WeakMap();
96
- function occurrencesOf(frame) {
97
- let slots = byFrame.get(frame);
98
- if (!slots) byFrame.set(frame, slots = new Map());
99
- return slots;
100
- }
101
- function sync(frame, occurrence, consumers) {
102
- const slots = occurrencesOf(frame);
103
- const entry = slots.get(occurrence);
104
- if (!entry) slots.set(occurrence, {
105
- consumers,
106
- rebind: undefined
107
- });else if (!entry.consumers) entry.consumers = consumers;else if (!consumersEqual(entry.consumers, consumers)) {
108
- entry.consumers = consumers;
109
- entry.rebind && entry.rebind(consumers);
110
- }
111
- }
112
- function rebinder(frame, occurrence, fn) {
113
- const slots = occurrencesOf(frame);
114
- const entry = slots.get(occurrence);
115
- if (entry) entry.rebind = fn;else slots.set(occurrence, {
116
- consumers: undefined,
117
- rebind: fn
118
- });
119
- }
120
- function unmount(frame, occurrence) {
121
- byFrame.get(frame)?.delete(occurrence);
122
- }
123
- function owned(el) {
124
- const attrs = el.attributes;
125
- let out = null;
126
- for (let i = 0; i < attrs.length; i++) {
127
- const name = attrs[i].name;
128
- if (!name.startsWith(SLOT_MARKER)) continue;
129
- const pos = name.slice(SLOT_MARKER.length);
130
- if (pos === "ref" || pos.startsWith("on:")) continue;
131
- out || (out = {
132
- attrs: new Set(),
133
- class: null,
134
- style: null
135
- });
136
- if (pos !== "class" && pos !== "style") {
137
- out.attrs.add(pos);
138
- continue;
139
- }
140
- for (const entry of attrs[i].value.split(",")) {
141
- const eq = entry.indexOf("=");
142
- if (eq === -1) {
143
- out.attrs.add(pos);
144
- continue;
145
- }
146
- (out[pos] || (out[pos] = [])).push(decodeURIComponent(entry.slice(eq + 1)));
147
- }
148
- }
149
- return out;
150
- }
151
- function morphOwnedClass(oldEl, value, names) {
152
- const list = oldEl.classList;
153
- const set = new Set(value ? value.split(/\s+/) : []);
154
- set.delete("");
155
- for (const name of names) list.contains(name) ? set.add(name) : set.delete(name);
156
- const next = [...set].join(" ");
157
- if (next === (oldEl.getAttribute("class") || "")) return false;
158
- next ? oldEl.setAttribute("class", next) : oldEl.removeAttribute("class");
159
- return true;
160
- }
161
- function morphOwnedStyle(oldEl, value, names) {
162
- const style = oldEl.style;
163
- const saved = names.map(name => [name, style.getPropertyValue(name), style.getPropertyPriority(name)]);
164
- const before = oldEl.getAttribute("style");
165
- value ? oldEl.setAttribute("style", value) : oldEl.removeAttribute("style");
166
- for (const [name, v, priority] of saved) {
167
- v ? style.setProperty(name, v, priority) : style.removeProperty(name);
168
- }
169
- return oldEl.getAttribute("style") !== before;
170
- }
171
- function apply(oldEl, name, value, owned) {
172
- if (owned.attrs.has(name)) return false;
173
- if ((name === "class" || name === "style") && owned[name] !== null) {
174
- return name === "class" ? morphOwnedClass(oldEl, value, owned.class) : morphOwnedStyle(oldEl, value, owned.style);
175
- }
176
- return undefined;
177
- }
178
- const handlerOwners = new WeakMap();
179
- function bind(fill, args, ctx, label) {
180
- const [consumers, setConsumers] = createSignal(ctx.positions);
181
- ctx.onRebind(setConsumers);
182
- const raw = untrack(() => fill(args), label);
183
- const node = typeof Node === "function" && raw instanceof Node;
184
- const pending = isAsyncValue$1(raw);
185
- if ((raw == null || typeof raw !== "object" || Array.isArray(raw) || node || pending)) {
186
- const shape = shapeOf(raw);
187
- slotShapeFinding({
188
- reason: "fill-shape",
189
- occurrence: ctx.key,
190
- shape
191
- }, `[BINDING_SLOT_POSITION] The fill for \`${ctx.key}\` returned ${shape}; server markup reads ` + `its properties at bound positions, so it must return an object (\`{ done, onToggle, … }\`). ` + `Nothing binds.`);
192
- }
193
- const out = raw == null || typeof raw !== "object" || node || pending ? {} : raw;
194
- const token = {};
195
- const state = new WeakMap();
196
- let bound = new Set();
197
- createRenderEffect(() => consumers().map(valuesFor), writes => {
198
- const next = new Set();
199
- for (const {
200
- element,
201
- positions,
202
- values,
203
- texts
204
- } of writes) {
205
- next.add(element);
206
- write(element, positions, values);
207
- for (const [start, v, key] of texts) writeText(start, v, key);
208
- }
209
- for (const element of bound) if (!next.has(element)) release(element);
210
- bound = next;
211
- });
212
- onCleanup(() => {
213
- for (const element of bound) release(element);
214
- });
215
- function valuesFor({
216
- element,
217
- positions
218
- }) {
219
- const props = {};
220
- const texts = [];
221
- let classNames = null;
222
- let styleProps = null;
223
- for (const {
224
- pos,
225
- key,
226
- name,
227
- start
228
- } of positions) {
229
- if (pos === "ref" || pos.startsWith("on:")) continue;
230
- if (pos === "text") texts.push([start, out[key], key]);else if (pos === "class" || pos === "style") {
231
- if (name === undefined) props[pos] = out[key];else if (pos === "class") (classNames || (classNames = {}))[name] = !!out[key];else (styleProps || (styleProps = {}))[name] = out[key];
232
- } else props[pos] = out[key];
233
- }
234
- if (classNames !== null && !("class" in props)) props.class = classNames;
235
- if (styleProps !== null && !("style" in props)) props.style = styleProps;
236
- return {
237
- element,
238
- positions,
239
- values: props,
240
- texts
241
- };
242
- }
243
- function write(element, positions, props) {
244
- let st = state.get(element);
245
- if (!st) state.set(element, st = {
246
- prev: {},
247
- handlers: {},
248
- ref: undefined,
249
- refId: ""
250
- });
251
- const handlers = {};
252
- const refKeys = [];
253
- for (const {
254
- pos,
255
- key
256
- } of positions) {
257
- if (pos === "ref") refKeys.push(key);else if (pos.startsWith("on:")) handlers["on" + pos[3].toUpperCase() + pos.slice(4)] = key;
258
- }
259
- let owners = handlerOwners.get(element);
260
- if (!owners) handlerOwners.set(element, owners = {});
261
- let events = false;
262
- for (const prop in handlers) {
263
- events = true;
264
- const key = handlers[prop];
265
- let h = st.handlers[prop];
266
- if (h === undefined || h.key !== key) st.handlers[prop] = h = {
267
- key,
268
- value: untrack(() => out[key])
269
- };
270
- props[prop] = h.value;
271
- owners[prop] = token;
272
- }
273
- const clearing = {};
274
- for (const prop in st.handlers) {
275
- if (prop in handlers) continue;
276
- delete st.handlers[prop];
277
- if (owners[prop] === token) {
278
- delete owners[prop];
279
- clearing[prop] = true;
280
- }
281
- }
282
- if (refKeys.length) {
283
- const id = refKeys.join(",");
284
- if (st.refId !== id) {
285
- const refs = refKeys.map(k => untrack(() => out[k]));
286
- st.refId = id;
287
- st.ref = el => {
288
- for (const r of refs) typeof r === "function" && r(el);
289
- };
290
- }
291
- props.ref = st.ref;
292
- }
293
- for (const k in st.prev) {
294
- if (k in props || k === "ref" || k in clearing) continue;
295
- delete st.prev[k];
296
- }
297
- assign(element, props, true, st.prev);
298
- if (events && sharedConfig.completed && !sharedConfig.completed.has(element)) {
299
- sharedConfig.completed.add(element);
300
- runHydrationEvents();
301
- }
302
- }
303
- function release(element) {
304
- if (!state.has(element)) return;
305
- write(element, [], {});
306
- state.delete(element);
307
- }
308
- function writeText(start, v, key) {
309
- let s = "";
310
- if (typeof v === "string" || typeof v === "number") s = "" + v;else if (v != null && typeof v !== "boolean") {
311
- const shape = shapeOf(v);
312
- slotShapeFinding({
313
- reason: "text-shape",
314
- occurrence: ctx.key,
315
- key,
316
- shape
317
- }, `[BINDING_SLOT_POSITION] \`${key}\` of \`${ctx.key}\` is placed as text, but the fill ` + `returned ${shape} for it. A text position renders a string or number; markup belongs ` + `in a template slot. The text is cleared.`);
318
- }
319
- const n = start.nextSibling;
320
- if (n && n.nodeType === 3) {
321
- if (n.data !== s) n.data = s;
322
- } else if (s) start.after(s);
323
- }
324
- }
325
-
326
- export { apply, bind, owned, positions, rebinder, sync, text, unmount };