solid-js 2.0.0-beta.6 → 2.0.0-beta.8

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.
@@ -0,0 +1,92 @@
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
+ | Element;
35
+
36
+ /**
37
+ * Ergonomics widening for emitted `prop:*` value types:
38
+ *
39
+ * - general `string` → `string | number` (HTML coerces numbers)
40
+ * - string literal unions (`'on' | 'off'`) stay exact, so users still get autocomplete /
41
+ * narrowing
42
+ * - other types pass through unchanged
43
+ */
44
+ type WidenString<V> = string extends V ? string | number : V;
45
+ export type WidenPropValue<V> = [V] extends [string] ? WidenString<V> : V;
46
+
47
+ /**
48
+ * Structurally identical → `Y`; distinct → `N`. Used by `IsReadonlyKey` to detect
49
+ * readonly keys by comparing `Pick<T, K>` with `Readonly<Pick<T, K>>`.
50
+ */
51
+ export type IfEquals<A, B, Y = unknown, N = never> =
52
+ (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? Y : N;
53
+
54
+ /**
55
+ * True when `K` is readonly on `T`. Singleton-constant properties (e.g.
56
+ * `tagName: "INPUT"`, `nodeType: 1`) are always `readonly` in `lib.dom.d.ts`, so this
57
+ * single check covers both readonly and singleton-literal cases.
58
+ */
59
+ export type IsReadonlyKey<T, K extends keyof T> = IfEquals<
60
+ Pick<T, K>,
61
+ Readonly<Pick<T, K>>,
62
+ true,
63
+ false
64
+ >;
65
+
66
+ /**
67
+ * Resolves to the `prop:K` string literal when `K` is a writable, element-specific
68
+ * property suitable for a `prop:*` attribute; otherwise resolves to `never` so the
69
+ * key is filtered out of the resulting mapped type.
70
+ *
71
+ * Filters out:
72
+ *
73
+ * - base-class keys (via `SkipPropsFrom`)
74
+ * - aria-* keys (already typed via `AriaAttributes`)
75
+ * - readonly keys
76
+ * - keys whose value types fall outside `PropValue`
77
+ * - the generic `string` index signature (e.g. `HTMLFormElement[name: string]: any`),
78
+ * which would otherwise shadow every key with an `any`-typed `prop:*`
79
+ */
80
+ export type PropKey<T, K extends keyof T> = K extends keyof SkipPropsFrom
81
+ ? never
82
+ : K extends string
83
+ ? string extends K
84
+ ? never
85
+ : K extends `aria${string}`
86
+ ? never
87
+ : T[K] extends PropValue
88
+ ? IsReadonlyKey<T, K> extends true
89
+ ? never
90
+ : `prop:${K}`
91
+ : never
92
+ : never;