@solidjs/web 2.0.0-beta.3 → 2.0.0-beta.30

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 (73) hide show
  1. package/README.md +27 -4
  2. package/dist/dev.cjs +1211 -205
  3. package/dist/dev.js +1175 -199
  4. package/dist/server.cjs +1342 -234
  5. package/dist/server.js +1304 -231
  6. package/dist/web.cjs +1195 -196
  7. package/dist/web.js +1159 -190
  8. package/frames/dist/client.cjs +1746 -0
  9. package/frames/dist/client.dev.cjs +1759 -0
  10. package/frames/dist/client.dev.js +1747 -0
  11. package/frames/dist/client.js +1734 -0
  12. package/frames/dist/server.cjs +2426 -0
  13. package/frames/dist/server.js +2414 -0
  14. package/frames/package.json +30 -0
  15. package/package.json +287 -38
  16. package/serialization/dist/serialization.cjs +169 -0
  17. package/serialization/dist/serialization.js +159 -0
  18. package/serialization/package.json +20 -0
  19. package/serialization/types/index.d.ts +157 -0
  20. package/serialization/types-cjs/index.d.cts +157 -0
  21. package/serialization/types-cjs/package.json +3 -0
  22. package/server-functions/dist/client.cjs +613 -0
  23. package/server-functions/dist/client.js +585 -0
  24. package/server-functions/dist/server.cjs +904 -0
  25. package/server-functions/dist/server.js +875 -0
  26. package/server-functions/package.json +30 -0
  27. package/storage/package.json +8 -3
  28. package/storage/types/index.d.ts +26 -0
  29. package/storage/types-cjs/index.d.cts +28 -0
  30. package/storage/types-cjs/package.json +3 -0
  31. package/types/client.d.ts +125 -21
  32. package/types/core.d.ts +4 -3
  33. package/types/frames/client.d.ts +20 -0
  34. package/types/frames/frame-client.d.ts +270 -0
  35. package/types/frames/frame-sink.d.ts +168 -0
  36. package/types/frames/frame-transport.d.ts +196 -0
  37. package/types/frames/serializer.d.ts +157 -0
  38. package/types/frames/server.d.ts +30 -0
  39. package/types/index.d.ts +211 -26
  40. package/types/jsx-properties.d.ts +93 -0
  41. package/types/jsx.d.ts +4150 -1
  42. package/types/response.d.ts +129 -0
  43. package/types/serializer.d.ts +157 -0
  44. package/types/server-functions/client.d.ts +200 -0
  45. package/types/server-functions/flash.d.ts +38 -0
  46. package/types/server-functions/server.d.ts +490 -0
  47. package/types/server-functions/shared.d.ts +445 -0
  48. package/types/server-mock.d.ts +93 -0
  49. package/types/server.d.ts +221 -28
  50. package/types-cjs/client.d.cts +192 -0
  51. package/types-cjs/core.d.cts +4 -0
  52. package/types-cjs/frames/client.d.cts +20 -0
  53. package/types-cjs/frames/frame-client.d.cts +270 -0
  54. package/types-cjs/frames/frame-sink.d.cts +168 -0
  55. package/types-cjs/frames/frame-transport.d.cts +196 -0
  56. package/types-cjs/frames/serializer.d.cts +157 -0
  57. package/types-cjs/frames/server.d.cts +30 -0
  58. package/types-cjs/index.d.cts +231 -0
  59. package/types-cjs/jsx-properties.d.cts +93 -0
  60. package/types-cjs/jsx.d.cts +4150 -0
  61. package/types-cjs/package.json +3 -0
  62. package/types-cjs/response.d.cts +129 -0
  63. package/types-cjs/serializer.d.cts +157 -0
  64. package/types-cjs/server-functions/client.d.cts +200 -0
  65. package/types-cjs/server-functions/flash.d.cts +38 -0
  66. package/types-cjs/server-functions/server.d.cts +490 -0
  67. package/types-cjs/server-functions/shared.d.cts +445 -0
  68. package/types-cjs/server-mock.d.cts +165 -0
  69. package/types-cjs/server.d.cts +349 -0
  70. package/storage/types/src/client.d.ts +0 -1
  71. package/storage/types/src/index.d.ts +0 -46
  72. package/storage/types/src/server-mock.d.ts +0 -72
  73. package/storage/types/storage/src/index.d.ts +0 -2
@@ -0,0 +1,157 @@
1
+ import { Plugin, Serializer, SerovalNode } from "seroval";
2
+
3
+ /**
4
+ * Seroval's node shape — the intermediate representation `serializeJSON`
5
+ * emits and `createJSONDeserializer` consumes. Safe to `JSON.stringify`.
6
+ */
7
+ export type { SerovalNode };
8
+
9
+ /**
10
+ * A Seroval plugin usable with the web serializers — teaches the codec how
11
+ * to encode/decode a custom value type. Supply matching plugins on both
12
+ * peers of a transport.
13
+ */
14
+ export type SerializerPlugin = Plugin<any, any>;
15
+
16
+ /**
17
+ * Baseline plugin set for serializing web-platform values (AbortSignal,
18
+ * Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
19
+ * Applied by every serializer in this module; custom plugins compose ahead
20
+ * of it via `resolveSerializerPlugins`.
21
+ */
22
+ export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
23
+
24
+ /**
25
+ * Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
26
+ * first so they can shadow a default for values both would match. Returns a
27
+ * fresh array; the defaults are never mutated. Useful when handing a full
28
+ * plugin list to another serialization layer.
29
+ */
30
+ export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
31
+
32
+ /** Options for `createSerializer`. */
33
+ export interface WebSerializerOptions {
34
+ /** Name of the global object the emitted scripts write resolved values into. */
35
+ globalIdentifier: string;
36
+ /** Cross-reference scope id, for isolating multiple streams on one page. */
37
+ scopeId?: string;
38
+ /**
39
+ * Seroval feature bitflags to exclude from output. Defaults to disabling
40
+ * post-ES2017 features (AggregateError, BigInt typed arrays). Outside
41
+ * development, `Error.prototype.stack` is additionally stripped on top of
42
+ * any override — serialized stacks leak server paths to the client.
43
+ */
44
+ disabledFeatures?: number;
45
+ /** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
46
+ plugins?: SerializerPlugin[];
47
+ /** Receives each emitted script chunk. */
48
+ onData: (result: string) => void;
49
+ onError?: (error: unknown) => void;
50
+ /** Fires once all async values have settled. */
51
+ onDone?: () => void;
52
+ }
53
+
54
+ /**
55
+ * Creates a streaming Seroval serializer preconfigured with the web plugin
56
+ * set and the default feature policy. Emits JavaScript chunks (through
57
+ * `onData`) that reconstruct the values under `globalIdentifier` when
58
+ * evaluated — the script-injection form of serialization renderers build
59
+ * on. For a JSON-based wire codec (no eval on the receiving side), use
60
+ * `serializeJSON` / `createJSONDeserializer` instead.
61
+ */
62
+ export function createSerializer(options: WebSerializerOptions): Serializer;
63
+
64
+ /**
65
+ * Options for `createHydrationSerializer` — `WebSerializerOptions` minus
66
+ * the knobs hydration pins (`globalIdentifier`, `disabledFeatures`).
67
+ * @internal
68
+ */
69
+ export type HydrationSerializerOptions = Omit<
70
+ WebSerializerOptions,
71
+ "globalIdentifier" | "disabledFeatures"
72
+ >;
73
+
74
+ /**
75
+ * Renderer primitive — the serializer SSR uses for hydration output. Pins
76
+ * the hydration global (`_$HY.r`) and feature policy; only the wiring
77
+ * options (callbacks, scope, extra plugins) are configurable. Not meant
78
+ * for hand-written code — custom serialization should use
79
+ * `createSerializer` or the JSON codec.
80
+ * @internal
81
+ */
82
+ export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
83
+
84
+ /**
85
+ * Renderer primitive — returns the cross-reference bootstrap script SSR
86
+ * emits ahead of hydration data for a render scope. Not meant for
87
+ * hand-written code.
88
+ * @internal
89
+ */
90
+ export function getLocalHeaderScript(id?: string): string;
91
+
92
+ // ---- JSON codec (server function transports) ----
93
+
94
+ /**
95
+ * Options shared by both halves of the JSON codec. All of them must match
96
+ * on the serializing and deserializing peer or payloads will not
97
+ * round-trip — for server functions, set them once through the
98
+ * client/server `codec` config option.
99
+ */
100
+ export interface JSONCodecOptions {
101
+ /** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
102
+ plugins?: SerializerPlugin[];
103
+ /**
104
+ * Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
105
+ * (payloads may come from an untrusted peer). Must match on both peers.
106
+ * Outside development, the encoding side additionally strips
107
+ * `Error.prototype.stack` on top of any override — serialized stacks leak
108
+ * server paths to the client. Decoding stays permissive, so payloads from
109
+ * a development peer still round-trip.
110
+ */
111
+ disabledFeatures?: number;
112
+ /** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
113
+ depthLimit?: number;
114
+ }
115
+
116
+ /** Options for `serializeJSON`. */
117
+ export interface JSONSerializeOptions extends JSONCodecOptions {
118
+ /**
119
+ * Receives each serialized node; `initial` is true for the first chunk
120
+ * (the source value itself). Async values produce additional chunks as
121
+ * they resolve.
122
+ */
123
+ onParse: (node: SerovalNode, initial: boolean) => void;
124
+ onError?: (error: unknown) => void;
125
+ /** Fires once all async values have settled. */
126
+ onDone?: () => void;
127
+ }
128
+
129
+ /**
130
+ * Serializes `value` as SerovalNode chunks delivered through `onParse` —
131
+ * the encoding half of the eval-free JSON codec (RPC-style transports;
132
+ * the deserializing peer needs no script evaluation, so CSP-safe). Wire
133
+ * framing of the nodes is the transport's concern. Returns a cancel
134
+ * function that aborts pending async serialization.
135
+ */
136
+ export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
137
+
138
+ /**
139
+ * Creates the decoding counterpart of `serializeJSON`. Cross-references
140
+ * between chunks resolve through state shared across calls, so all chunks
141
+ * from one stream must go through the same deserializer instance. The first
142
+ * chunk's return value is the decoded source value; feeding later chunks
143
+ * settles the async values referenced inside it.
144
+ */
145
+ export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
146
+
147
+ /**
148
+ * A resident, response-scoped decode table over the keyed JSON codec: apply
149
+ * each frame `data` chunk with `apply`, resolve `{ $ref }` slot args with
150
+ * `resolve`. The frames client host wires one per response
151
+ * (`applyData: c => table.apply(c)`).
152
+ */
153
+ export interface JSONDataTable {
154
+ apply(chunk: { key?: string; node?: unknown; initial?: boolean }): void;
155
+ resolve<T = unknown>(ref: { $ref: string }): T;
156
+ }
157
+ export function createJSONDataTable(options?: JSONCodecOptions): JSONDataTable;
@@ -0,0 +1,30 @@
1
+ import type { Element as SolidElement } from "solid-js";
2
+ /**
3
+ * A client position in a server component: a prop the server renders (as JSX
4
+ * or by calling it) where client-owned markup belongs. `P` is the client
5
+ * component's own props, so a server component can reference the client
6
+ * component's type directly instead of restating it.
7
+ *
8
+ * Arguments are classified by VALUE, not by name — any prop may carry any of
9
+ * these:
10
+ *
11
+ * - primitives ride the chunk;
12
+ * - server JSX streams as a nested region (html once, never data);
13
+ * - anything else serializes as a data record.
14
+ *
15
+ * Async server JSX in an argument needs its own boundary: the region is
16
+ * emitted as one finished string, so a bare async read has no fallback to
17
+ * show and no fragment to reveal into.
18
+ *
19
+ * `$key` names the occurrence so client state follows an entity across
20
+ * responses rather than being positional — the slot-level analogue of `For`'s
21
+ * `keyed`, for when references can't carry identity because every response
22
+ * re-creates everything. It is occurrence identity, not client data: it is
23
+ * stripped before the client component sees its props. Positional identity is
24
+ * the right default; `$key` matters when a live list reorders.
25
+ */
26
+ export type Slot<P = {}> = (props: P & {
27
+ $key?: string | number;
28
+ }) => SolidElement;
29
+ export { renderToFrameStream, renderServerComponent, serverComponentResponse, frameTransformResult, frameTransformFlightResult, createFrameSink, frameTransformDirectResult, ServerComponentPlugin, SERVER_COMPONENT_BOOTSTRAP } from "./frame-sink.cjs";
30
+ export { FRAME_STREAM_HEADER, isFrameStreamResponse } from "./frame-transport.cjs";
@@ -0,0 +1,231 @@
1
+ import { hydrate as hydrateCore } from "./client.cjs";
2
+ import { Component } from "solid-js";
3
+ import type { JSX } from "./jsx.cjs";
4
+ export * from "./client.cjs";
5
+ export * from "./server-mock.cjs";
6
+ export * from "./response.cjs";
7
+ export type { JSX } from "./jsx.cjs";
8
+ export { For, Show, Switch, Match, Errored, Loading, Repeat, Reveal, NoHydration, Hydration } from "solid-js";
9
+ import { merge } from "solid-js";
10
+ /**
11
+ * Compiler-emitted prop-spread helper. The JSX transform (in
12
+ * `dom-expressions`) emits `mergeProps(...)` calls when compiling prop
13
+ * spreads on components — it is *not* a user-facing API. Application code
14
+ * should import `merge` from `solid-js` directly.
15
+ *
16
+ * @internal
17
+ */
18
+ export declare const mergeProps: typeof merge;
19
+ /**
20
+ * Build-time constant indicating whether code is running on the server. This
21
+ * client entry sets it to `false`; the matching server entry (`@solidjs/web`
22
+ * resolved through the `solid` server export condition) sets it to `true`.
23
+ *
24
+ * Bundlers can dead-code-eliminate branches gated on `isServer`, so guarding
25
+ * browser-only code with `if (!isServer) {…}` keeps it out of the SSR bundle
26
+ * entirely.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { isServer } from "@solidjs/web";
31
+ *
32
+ * if (!isServer) {
33
+ * // Browser-only: tree-shaken out of the SSR bundle.
34
+ * window.addEventListener("resize", onResize);
35
+ * }
36
+ * ```
37
+ */
38
+ export declare const isServer: boolean;
39
+ /**
40
+ * Build-time constant indicating whether code is running in a dev build.
41
+ * Replaced statically (`_SOLID_DEV_`) by the bundler integration, so guards
42
+ * like `if (isDev) {…}` are stripped from production builds.
43
+ *
44
+ * Use this to gate dev-only diagnostics, warnings, or expensive invariants
45
+ * that should never ship to production.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { isDev } from "@solidjs/web";
50
+ *
51
+ * if (isDev) {
52
+ * console.warn("debug-only path");
53
+ * }
54
+ * ```
55
+ */
56
+ export declare const isDev: boolean;
57
+ type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node;
58
+ export type IntrinsicElement = Extract<keyof JSX.IntrinsicElements, string>;
59
+ export type ValidComponent = IntrinsicElement | Component<any> | (string & {});
60
+ export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : Record<string, unknown>;
61
+ export type DynamicProps<T extends ValidComponent, P = ComponentProps<T>> = {
62
+ [K in keyof P]: P[K];
63
+ } & {
64
+ component: T | null | undefined | false;
65
+ };
66
+ /**
67
+ * Renders a component tree into a DOM element. Returns a dispose function
68
+ * that tears the tree down and cleans up reactive scopes when called.
69
+ *
70
+ * @example
71
+ * ```tsx
72
+ * import { render } from "@solidjs/web";
73
+ *
74
+ * const dispose = render(() => <App />, document.getElementById("root")!);
75
+ *
76
+ * // Later, to unmount:
77
+ * dispose();
78
+ * ```
79
+ *
80
+ * @remarks
81
+ * The top-level insert is queued via `insertOptions: { schedule: true }` so
82
+ * its initial DOM attach goes through the effect queue rather than executing
83
+ * inline. This lets the mount participate in transitions: if an uncaught
84
+ * async read surfaces during the initial render (no `Loading` ancestor
85
+ * absorbs it), the mount is held by the transition and attaches atomically
86
+ * once all pending settles. On the no-async happy path the tail `flush()`
87
+ * drains the queued callback so the attach is synchronous by the time
88
+ * `render()` returns. The dev enforcement window scopes
89
+ * `ASYNC_OUTSIDE_LOADING_BOUNDARY` to the initial mount only.
90
+ */
91
+ export declare function render(code: () => JSX.Element, element: MountableElement, init?: unknown, options?: {
92
+ renderId?: string;
93
+ }): () => void;
94
+ /**
95
+ * Resumes a server-rendered tree on the client, attaching event listeners
96
+ * and reactive bindings without reconstructing the DOM. Returns a `dispose`
97
+ * function that tears down reactive scopes (DOM nodes are left in place).
98
+ *
99
+ * Use this when the page HTML was produced by `renderToString`,
100
+ * `renderToStringAsync`, or `renderToStream`. For client-only apps, use
101
+ * `render` instead.
102
+ *
103
+ * Pass `options.renderId` to hydrate one of multiple roots emitted by a
104
+ * server render that used the same id.
105
+ *
106
+ * @example
107
+ * ```tsx
108
+ * import { hydrate } from "@solidjs/web";
109
+ *
110
+ * hydrate(() => <App />, document.getElementById("root")!);
111
+ * ```
112
+ */
113
+ export declare const hydrate: typeof hydrateCore;
114
+ /**
115
+ * Renders its children into a different part of the DOM (modal roots,
116
+ * tooltips, layers that need to escape an `overflow: hidden` ancestor).
117
+ *
118
+ * If `mount` is omitted, the portal attaches to `document.body`. The portal
119
+ * still participates in the parent's reactive scope and disposes when the
120
+ * parent does.
121
+ *
122
+ * Portals are client-only islands: the server renders nothing for them, and
123
+ * under hydration the children render fresh once hydration settles. Async
124
+ * read inside a portal therefore starts on the client — data that should be
125
+ * fetched on the server belongs above the portal (hoist the read, not the
126
+ * render), and async UI inside one wants its own `<Loading>` boundary.
127
+ *
128
+ * @example
129
+ * ```tsx
130
+ * <Portal mount={document.getElementById("modal-root")!}>
131
+ * <Dialog />
132
+ * </Portal>
133
+ * ```
134
+ *
135
+ * @description https://docs.solidjs.com/reference/components/portal
136
+ */
137
+ export declare function Portal(props: {
138
+ mount?: Element;
139
+ children: JSX.Element;
140
+ }): JSX.Element;
141
+ export declare function dynamic<T extends ValidComponent>(source: () => T | Promise<T> | null | undefined | false): Component<ComponentProps<T>>;
142
+ /**
143
+ * Renders an arbitrary custom or native component and forwards the other
144
+ * props. JSX form of `dynamic()` — same primitive, picked at the JSX site.
145
+ *
146
+ * @example
147
+ * ```tsx
148
+ * <Dynamic
149
+ * component={multiline() ? RichTextEditor : "input"}
150
+ * value={value()}
151
+ * onInput={onInput}
152
+ * />
153
+ * ```
154
+ *
155
+ * @description https://docs.solidjs.com/reference/components/dynamic
156
+ */
157
+ export declare function Dynamic<T extends ValidComponent>(props: DynamicProps<T>): JSX.Element;
158
+ /**
159
+ * Wraps a dynamically imported component so it renders only in the browser.
160
+ * The server renders `props.fallback` (and nothing else); the client shows
161
+ * the fallback until the import resolves and the tree has mounted, then
162
+ * swaps the real component in.
163
+ *
164
+ * Unlike `lazy()`, this avoids Suspense entirely and never server-renders
165
+ * the wrapped component — only the fallback — so the component participates
166
+ * in no hydration asset manifest and its code is guaranteed to never run on
167
+ * the server (safe for browser-only libraries touching `window`, DOM
168
+ * measurement, etc.). The mount gate keeps hydration safe: during hydration
169
+ * the fallback is rendered exactly as the server did, and the swap happens
170
+ * only after settle, so there is no mismatch.
171
+ *
172
+ * By default the import starts as soon as `clientOnly` is called (module
173
+ * load); pass `{ lazy: true }` to defer the import to the component's first
174
+ * render.
175
+ *
176
+ * @example
177
+ * ```tsx
178
+ * const Chart = clientOnly(() => import("./Chart.jsx"));
179
+ * // <Chart fallback={<div>Loading chart…</div>} data={data()} />
180
+ * ```
181
+ */
182
+ export declare function clientOnly<T extends Component<any>>(fn: () => Promise<{
183
+ default: T;
184
+ }>, options?: {
185
+ lazy?: boolean;
186
+ }, _moduleUrl?: string): Component<ComponentProps<T> & {
187
+ fallback?: JSX.Element;
188
+ }>;
189
+ /**
190
+ * Declares the HTTP response status (and optional status text) for the
191
+ * lifetime of the current reactive scope during SSR — call it bare in a
192
+ * component or reactive-scope body where the status is decided (a 404
193
+ * route, an error fallback). Client build: a no-op — the response head was
194
+ * sent long ago.
195
+ *
196
+ * Naming note — this is a scope-tied *declaration*, not a mutation: "while
197
+ * this reactive scope is live, the response has this status." Solid
198
+ * reserves `set*` verbs for event-time mutation; like
199
+ * `createSignal`/`onCleanup` this is called in scope bodies and un-declares
200
+ * on scope disposal.
201
+ *
202
+ * Retraction semantics (server): the write snapshots the previous
203
+ * `event.response` status at write time and restores it when the owning
204
+ * scope is disposed — so a boundary that errored, declared a status, and
205
+ * then recovered retracts its write instead of stomping a status a
206
+ * surviving part of the tree legitimately set. Once the integration marks
207
+ * the response head `committed` (head derived/sent), writes and
208
+ * retractions are no-ops.
209
+ */
210
+ export declare function httpStatus(_code: number, _text?: string): void;
211
+ /**
212
+ * Declares an HTTP response header (or with `append`, appends to one) for
213
+ * the lifetime of the current reactive scope during SSR — call it bare in a
214
+ * component or reactive-scope body. Client build: a no-op — the response
215
+ * head was sent long ago.
216
+ *
217
+ * Naming note — this is a scope-tied *declaration*, not a mutation: "while
218
+ * this reactive scope is live, the response has this header." Solid
219
+ * reserves `set*` verbs for event-time mutation; like
220
+ * `createSignal`/`onCleanup` this is called in scope bodies and un-declares
221
+ * on scope disposal.
222
+ *
223
+ * Retraction semantics (server): the header's prior value is snapshotted at
224
+ * write time and restored when the owning scope is disposed (deleted if
225
+ * there was none) — a boundary that errors or recovers retracts its writes.
226
+ * Once the integration marks the response head `committed` (head
227
+ * derived/sent), writes and retractions are no-ops.
228
+ */
229
+ export declare function httpHeader(_name: string, _value: string, _options?: {
230
+ append?: boolean;
231
+ }): void;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Shared type-level helpers used to derive `prop:*` attribute typings from
3
+ * DOM element interfaces (e.g. `HTMLInputElement`, `HTMLButtonElement`).
4
+ *
5
+ * The wrapping of each value (`FunctionMaybe<T>` in `jsx-h.d.ts` vs. the
6
+ * raw value in `jsx.d.ts`) is applied by each consumer when composing its
7
+ * own `Properties<T>` mapped type. That way this file stays identical in
8
+ * both reactive and non-reactive contexts and only needs to exist once.
9
+ *
10
+ * originally from
11
+ * @url https://github.com/potahtml/pota
12
+ */
13
+
14
+ /** Base-class properties shared by all elements — skipped from `prop:*`. */
15
+ export type SkipPropsFrom = HTMLUnknownElement & HTMLElement & Element & Node;
16
+
17
+ /**
18
+ * Value types allowed on a `prop:*`. Primitives plus the writable
19
+ * non-primitive DOM-object props worth exposing:
20
+ *
21
+ * - `HTMLMediaElement.srcObject`
22
+ * - `HTMLButtonElement.popoverTargetElement` / `commandForElement` (and the same via
23
+ * `PopoverTargetAttributes` mixin on `HTMLInputElement`)
24
+ */
25
+ export type PropValue =
26
+ | string
27
+ | number
28
+ | boolean
29
+ | null
30
+ | MediaStream
31
+ | MediaSource
32
+ | Blob
33
+ | File
34
+ | Date
35
+ | Element;
36
+
37
+ /**
38
+ * Ergonomics widening for emitted `prop:*` value types:
39
+ *
40
+ * - general `string` → `string | number` (HTML coerces numbers)
41
+ * - string literal unions (`'on' | 'off'`) stay exact, so users still get autocomplete /
42
+ * narrowing
43
+ * - other types pass through unchanged
44
+ */
45
+ type WidenString<V> = string extends V ? string | number : V;
46
+ export type WidenPropValue<V> = [V] extends [string] ? WidenString<V> : V;
47
+
48
+ /**
49
+ * Structurally identical → `Y`; distinct → `N`. Used by `IsReadonlyKey` to detect
50
+ * readonly keys by comparing `Pick<T, K>` with `Readonly<Pick<T, K>>`.
51
+ */
52
+ export type IfEquals<A, B, Y = unknown, N = never> =
53
+ (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? Y : N;
54
+
55
+ /**
56
+ * True when `K` is readonly on `T`. Singleton-constant properties (e.g.
57
+ * `tagName: "INPUT"`, `nodeType: 1`) are always `readonly` in `lib.dom.d.ts`, so this
58
+ * single check covers both readonly and singleton-literal cases.
59
+ */
60
+ export type IsReadonlyKey<T, K extends keyof T> = IfEquals<
61
+ Pick<T, K>,
62
+ Readonly<Pick<T, K>>,
63
+ true,
64
+ false
65
+ >;
66
+
67
+ /**
68
+ * Resolves to the `prop:K` string literal when `K` is a writable, element-specific
69
+ * property suitable for a `prop:*` attribute; otherwise resolves to `never` so the
70
+ * key is filtered out of the resulting mapped type.
71
+ *
72
+ * Filters out:
73
+ *
74
+ * - base-class keys (via `SkipPropsFrom`)
75
+ * - aria-* keys (already typed via `AriaAttributes`)
76
+ * - readonly keys
77
+ * - keys whose value types fall outside `PropValue`
78
+ * - the generic `string` index signature (e.g. `HTMLFormElement[name: string]: any`),
79
+ * which would otherwise shadow every key with an `any`-typed `prop:*`
80
+ */
81
+ export type PropKey<T, K extends keyof T> = K extends keyof SkipPropsFrom
82
+ ? never
83
+ : K extends string
84
+ ? string extends K
85
+ ? never
86
+ : K extends `aria${string}`
87
+ ? never
88
+ : T[K] extends PropValue
89
+ ? IsReadonlyKey<T, K> extends true
90
+ ? never
91
+ : `prop:${K}`
92
+ : never
93
+ : never;