what-core 0.14.0 → 0.15.0

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 (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -38
  3. package/a11y.d.ts +128 -0
  4. package/data.d.ts +294 -0
  5. package/dist/a11y.js +510 -0
  6. package/dist/a11y.min.js +413 -0
  7. package/dist/actions.js +158 -0
  8. package/dist/actions.min.js +112 -0
  9. package/dist/animation.js +481 -0
  10. package/dist/animation.min.js +295 -0
  11. package/dist/async.js +180 -0
  12. package/dist/async.min.js +134 -0
  13. package/dist/components.js +577 -0
  14. package/dist/components.min.js +413 -0
  15. package/dist/data.js +1212 -0
  16. package/dist/data.min.js +918 -0
  17. package/dist/diagnostics.js +187 -0
  18. package/dist/diagnostics.min.js +134 -0
  19. package/dist/dom.js +796 -0
  20. package/dist/dom.min.js +603 -0
  21. package/dist/entries/a11y.js +43 -0
  22. package/dist/entries/a11y.min.js +43 -0
  23. package/dist/entries/data.js +29 -0
  24. package/dist/entries/data.min.js +29 -0
  25. package/dist/entries/dom.js +45 -0
  26. package/dist/entries/dom.min.js +45 -0
  27. package/dist/entries/form.js +31 -0
  28. package/dist/entries/form.min.js +31 -0
  29. package/dist/entries/internal.js +123 -0
  30. package/dist/entries/internal.min.js +123 -0
  31. package/dist/entries/motion.js +23 -0
  32. package/dist/entries/motion.min.js +23 -0
  33. package/dist/entries/ui.js +25 -0
  34. package/dist/entries/ui.min.js +25 -0
  35. package/dist/env.js +5 -0
  36. package/dist/env.min.js +5 -0
  37. package/dist/errors.js +1518 -0
  38. package/dist/errors.min.js +548 -0
  39. package/dist/form.js +936 -0
  40. package/dist/form.min.js +703 -0
  41. package/dist/guardrails.js +84 -0
  42. package/dist/guardrails.min.js +55 -0
  43. package/dist/h.js +232 -0
  44. package/dist/h.min.js +171 -0
  45. package/dist/head.js +241 -0
  46. package/dist/head.min.js +207 -0
  47. package/dist/helpers.js +126 -0
  48. package/dist/helpers.min.js +98 -0
  49. package/dist/hooks.js +255 -0
  50. package/dist/hooks.min.js +153 -0
  51. package/dist/hot.js +215 -0
  52. package/dist/hot.min.js +24 -0
  53. package/dist/hydration-data.js +495 -0
  54. package/dist/hydration-data.min.js +371 -0
  55. package/dist/import-changes.js +273 -0
  56. package/dist/import-changes.min.js +272 -0
  57. package/dist/index.js +95 -0
  58. package/dist/index.min.js +95 -227
  59. package/dist/jsx-dev-runtime.js +10 -0
  60. package/dist/jsx-dev-runtime.min.js +10 -1
  61. package/dist/jsx-runtime.js +27 -0
  62. package/dist/jsx-runtime.min.js +15 -1
  63. package/dist/live.js +54 -0
  64. package/dist/live.min.js +49 -0
  65. package/dist/markup-rules.js +250 -0
  66. package/dist/markup-rules.min.js +213 -0
  67. package/dist/reactive.js +3334 -0
  68. package/dist/reactive.min.js +2033 -0
  69. package/dist/render.js +4746 -0
  70. package/dist/render.min.js +2797 -1
  71. package/dist/scheduler.js +225 -0
  72. package/dist/scheduler.min.js +162 -0
  73. package/dist/selector.js +11 -0
  74. package/dist/selector.min.js +10 -0
  75. package/dist/server-context.js +148 -0
  76. package/dist/server-context.min.js +121 -0
  77. package/dist/skeleton.js +342 -0
  78. package/dist/skeleton.min.js +310 -0
  79. package/dist/store.js +72 -0
  80. package/dist/store.min.js +50 -0
  81. package/dist/testing.js +720 -0
  82. package/dist/testing.min.js +458 -1
  83. package/dist/vnode-adoption.js +19 -0
  84. package/dist/vnode-adoption.min.js +19 -0
  85. package/dist/vnode-renderer.js +61 -0
  86. package/dist/vnode-renderer.min.js +47 -0
  87. package/dom.d.ts +44 -0
  88. package/form.d.ts +218 -0
  89. package/hot.d.ts +35 -0
  90. package/index.d.ts +421 -736
  91. package/internal.d.ts +284 -0
  92. package/jsx-runtime.d.ts +160 -137
  93. package/markup-rules.d.ts +83 -0
  94. package/motion.d.ts +156 -0
  95. package/package.json +117 -3
  96. package/render.d.ts +278 -29
  97. package/src/a11y.js +64 -59
  98. package/src/actions.js +226 -0
  99. package/src/animation.js +105 -57
  100. package/src/async.js +259 -0
  101. package/src/components.js +495 -144
  102. package/src/data.js +1410 -1159
  103. package/src/diagnostics.js +263 -0
  104. package/src/dom.js +1159 -872
  105. package/src/entries/a11y.js +24 -0
  106. package/src/entries/data.js +17 -0
  107. package/src/entries/dom.js +29 -0
  108. package/src/entries/form.js +16 -0
  109. package/src/entries/internal.js +63 -0
  110. package/src/entries/motion.js +13 -0
  111. package/src/entries/ui.js +13 -0
  112. package/src/env-development.js +12 -0
  113. package/src/env.js +33 -0
  114. package/src/errors.js +1144 -168
  115. package/src/form.js +723 -225
  116. package/src/guardrails.js +38 -126
  117. package/src/h.js +227 -152
  118. package/src/head.js +189 -19
  119. package/src/helpers.js +47 -75
  120. package/src/hooks.js +233 -248
  121. package/src/hot.js +316 -0
  122. package/src/hydration-data.js +859 -16
  123. package/src/import-changes.js +156 -0
  124. package/src/index.js +38 -188
  125. package/src/jsx-dev-runtime.js +7 -14
  126. package/src/jsx-runtime.js +25 -9
  127. package/src/live.js +80 -0
  128. package/src/markup-rules.js +387 -0
  129. package/src/reactive.js +4400 -862
  130. package/src/render.js +6502 -2570
  131. package/src/scheduler.js +56 -21
  132. package/src/selector.js +31 -0
  133. package/src/server-context.js +252 -22
  134. package/src/skeleton.js +22 -12
  135. package/src/store.js +17 -31
  136. package/src/testing.js +389 -63
  137. package/src/vnode-adoption.js +48 -0
  138. package/src/vnode-renderer.js +114 -0
  139. package/testing.d.ts +81 -1
  140. package/ui.d.ts +20 -0
  141. package/dist/chunk-6YOUZ6T4.min.js +0 -1
  142. package/dist/chunk-FN6HXME3.min.js +0 -11
  143. package/dist/chunk-VKZY7JPN.min.js +0 -1
  144. package/src/agent-context.js +0 -127
  145. package/src/warnings.js +0 -193
package/jsx-runtime.d.ts CHANGED
@@ -21,50 +21,62 @@ export type Reactive<T> = T | null | undefined | (() => T | null | undefined);
21
21
  export function jsx(type: any, props: any, key?: any): VNode;
22
22
  export function jsxs(type: any, props: any, key?: any): VNode;
23
23
 
24
- type EventHandler<E extends Event = Event> = (event: E & { currentTarget: EventTarget & Element; target: Element }) => void;
24
+ /**
25
+ * A handler of DOM event `E` on an element of type `T`. `currentTarget` is the
26
+ * element the handler is on (an `<input>`'s handler reads
27
+ * `e.currentTarget.value` with no cast), as React types it; `target` is
28
+ * whatever element the event started at, which may be a descendant. Declared
29
+ * as a method so a handler for a narrower element still fits a wider one (a
30
+ * custom element's attributes, the index signature below).
31
+ */
32
+ type EventHandler<E extends Event = Event, T extends EventTarget = Element> = {
33
+ bivarianceHack(event: E & { currentTarget: EventTarget & T; target: Element }): void;
34
+ }['bivarianceHack'];
25
35
 
26
- interface WhatEventHandlers {
36
+ interface WhatEventHandlers<T extends EventTarget = Element> {
27
37
  // What lowercases the event name, so both spellings resolve to the same DOM event.
28
- onClick?: EventHandler<MouseEvent>;
29
- onclick?: EventHandler<MouseEvent>;
30
- onDblClick?: EventHandler<MouseEvent>;
31
- ondblclick?: EventHandler<MouseEvent>;
32
- onMouseDown?: EventHandler<MouseEvent>;
33
- onmousedown?: EventHandler<MouseEvent>;
34
- onMouseUp?: EventHandler<MouseEvent>;
35
- onmouseup?: EventHandler<MouseEvent>;
36
- onMouseEnter?: EventHandler<MouseEvent>;
37
- onmouseenter?: EventHandler<MouseEvent>;
38
- onMouseLeave?: EventHandler<MouseEvent>;
39
- onmouseleave?: EventHandler<MouseEvent>;
40
- onMouseMove?: EventHandler<MouseEvent>;
41
- onmousemove?: EventHandler<MouseEvent>;
42
- onInput?: EventHandler<InputEvent>;
43
- oninput?: EventHandler<InputEvent>;
44
- onChange?: EventHandler<Event>;
45
- onchange?: EventHandler<Event>;
46
- onSubmit?: EventHandler<SubmitEvent>;
47
- onsubmit?: EventHandler<SubmitEvent>;
48
- onReset?: EventHandler<Event>;
49
- onreset?: EventHandler<Event>;
50
- onKeyDown?: EventHandler<KeyboardEvent>;
51
- onkeydown?: EventHandler<KeyboardEvent>;
52
- onKeyUp?: EventHandler<KeyboardEvent>;
53
- onkeyup?: EventHandler<KeyboardEvent>;
54
- onKeyPress?: EventHandler<KeyboardEvent>;
55
- onkeypress?: EventHandler<KeyboardEvent>;
56
- onFocus?: EventHandler<FocusEvent>;
57
- onfocus?: EventHandler<FocusEvent>;
58
- onBlur?: EventHandler<FocusEvent>;
59
- onblur?: EventHandler<FocusEvent>;
60
- onScroll?: EventHandler<Event>;
61
- onscroll?: EventHandler<Event>;
38
+ onClick?: EventHandler<MouseEvent, T>;
39
+ onclick?: EventHandler<MouseEvent, T>;
40
+ onDblClick?: EventHandler<MouseEvent, T>;
41
+ /** React's name for the DOM's `dblclick`, the same event as `onDblClick`. */
42
+ onDoubleClick?: EventHandler<MouseEvent, T>;
43
+ ondblclick?: EventHandler<MouseEvent, T>;
44
+ onMouseDown?: EventHandler<MouseEvent, T>;
45
+ onmousedown?: EventHandler<MouseEvent, T>;
46
+ onMouseUp?: EventHandler<MouseEvent, T>;
47
+ onmouseup?: EventHandler<MouseEvent, T>;
48
+ onMouseEnter?: EventHandler<MouseEvent, T>;
49
+ onmouseenter?: EventHandler<MouseEvent, T>;
50
+ onMouseLeave?: EventHandler<MouseEvent, T>;
51
+ onmouseleave?: EventHandler<MouseEvent, T>;
52
+ onMouseMove?: EventHandler<MouseEvent, T>;
53
+ onmousemove?: EventHandler<MouseEvent, T>;
54
+ onInput?: EventHandler<InputEvent, T>;
55
+ oninput?: EventHandler<InputEvent, T>;
56
+ onChange?: EventHandler<Event, T>;
57
+ onchange?: EventHandler<Event, T>;
58
+ onSubmit?: EventHandler<SubmitEvent, T>;
59
+ onsubmit?: EventHandler<SubmitEvent, T>;
60
+ onReset?: EventHandler<Event, T>;
61
+ onreset?: EventHandler<Event, T>;
62
+ onKeyDown?: EventHandler<KeyboardEvent, T>;
63
+ onkeydown?: EventHandler<KeyboardEvent, T>;
64
+ onKeyUp?: EventHandler<KeyboardEvent, T>;
65
+ onkeyup?: EventHandler<KeyboardEvent, T>;
66
+ onKeyPress?: EventHandler<KeyboardEvent, T>;
67
+ onkeypress?: EventHandler<KeyboardEvent, T>;
68
+ onFocus?: EventHandler<FocusEvent, T>;
69
+ onfocus?: EventHandler<FocusEvent, T>;
70
+ onBlur?: EventHandler<FocusEvent, T>;
71
+ onblur?: EventHandler<FocusEvent, T>;
72
+ onScroll?: EventHandler<Event, T>;
73
+ onscroll?: EventHandler<Event, T>;
62
74
  }
63
75
 
64
- interface WhatHTMLAttributes extends WhatEventHandlers {
76
+ interface WhatHTMLAttributes<T extends EventTarget = Element> extends WhatEventHandlers<T> {
65
77
  children?: VNodeChild;
66
- /** Component-list reconciliation key. */
67
- key?: string | number;
78
+ /** A list row's key; outside a list, a new value builds the element again. A signal (`key={id}`) can change where the element is made once. */
79
+ key?: Reactive<string | number>;
68
80
  ref?: ((el: any) => void) | { current: any };
69
81
 
70
82
  class?: Reactive<string>;
@@ -89,7 +101,7 @@ interface WhatHTMLAttributes extends WhatEventHandlers {
89
101
  [attr: string]: any;
90
102
  }
91
103
 
92
- interface WhatInputAttributes extends WhatHTMLAttributes {
104
+ interface WhatInputAttributes extends WhatHTMLAttributes<HTMLInputElement> {
93
105
  type?: Reactive<string>;
94
106
  value?: Reactive<string | number>;
95
107
  checked?: Reactive<boolean>;
@@ -107,14 +119,14 @@ interface WhatInputAttributes extends WhatHTMLAttributes {
107
119
  autofocus?: Reactive<boolean>;
108
120
  }
109
121
 
110
- interface WhatAnchorAttributes extends WhatHTMLAttributes {
122
+ interface WhatAnchorAttributes extends WhatHTMLAttributes<HTMLAnchorElement> {
111
123
  href?: Reactive<string>;
112
124
  target?: Reactive<string>;
113
125
  rel?: Reactive<string>;
114
126
  download?: Reactive<string | boolean>;
115
127
  }
116
128
 
117
- interface WhatImgAttributes extends WhatHTMLAttributes {
129
+ interface WhatImgAttributes extends WhatHTMLAttributes<HTMLImageElement> {
118
130
  src?: Reactive<string>;
119
131
  srcset?: Reactive<string>;
120
132
  alt?: Reactive<string>;
@@ -124,7 +136,7 @@ interface WhatImgAttributes extends WhatHTMLAttributes {
124
136
  decoding?: Reactive<'async' | 'auto' | 'sync'>;
125
137
  }
126
138
 
127
- interface WhatButtonAttributes extends WhatHTMLAttributes {
139
+ interface WhatButtonAttributes extends WhatHTMLAttributes<HTMLButtonElement> {
128
140
  type?: Reactive<'button' | 'submit' | 'reset'>;
129
141
  disabled?: Reactive<boolean>;
130
142
  name?: Reactive<string>;
@@ -132,7 +144,7 @@ interface WhatButtonAttributes extends WhatHTMLAttributes {
132
144
  form?: Reactive<string>;
133
145
  }
134
146
 
135
- interface WhatFormAttributes extends WhatHTMLAttributes {
147
+ interface WhatFormAttributes extends WhatHTMLAttributes<HTMLFormElement> {
136
148
  action?: Reactive<string>;
137
149
  method?: Reactive<string>;
138
150
  enctype?: Reactive<string>;
@@ -140,18 +152,18 @@ interface WhatFormAttributes extends WhatHTMLAttributes {
140
152
  target?: Reactive<string>;
141
153
  }
142
154
 
143
- interface WhatLabelAttributes extends WhatHTMLAttributes {
155
+ interface WhatLabelAttributes extends WhatHTMLAttributes<HTMLLabelElement> {
144
156
  for?: Reactive<string>;
145
157
  htmlFor?: Reactive<string>;
146
158
  }
147
159
 
148
- interface WhatOptionAttributes extends WhatHTMLAttributes {
160
+ interface WhatOptionAttributes extends WhatHTMLAttributes<HTMLOptionElement> {
149
161
  value?: Reactive<string | number>;
150
162
  selected?: Reactive<boolean>;
151
163
  disabled?: Reactive<boolean>;
152
164
  }
153
165
 
154
- interface WhatSelectAttributes extends WhatHTMLAttributes {
166
+ interface WhatSelectAttributes extends WhatHTMLAttributes<HTMLSelectElement> {
155
167
  value?: Reactive<string | number>;
156
168
  name?: Reactive<string>;
157
169
  disabled?: Reactive<boolean>;
@@ -159,7 +171,7 @@ interface WhatSelectAttributes extends WhatHTMLAttributes {
159
171
  multiple?: Reactive<boolean>;
160
172
  }
161
173
 
162
- interface WhatTextareaAttributes extends WhatHTMLAttributes {
174
+ interface WhatTextareaAttributes extends WhatHTMLAttributes<HTMLTextAreaElement> {
163
175
  value?: Reactive<string>;
164
176
  placeholder?: Reactive<string>;
165
177
  rows?: Reactive<string | number>;
@@ -170,7 +182,7 @@ interface WhatTextareaAttributes extends WhatHTMLAttributes {
170
182
  name?: Reactive<string>;
171
183
  }
172
184
 
173
- interface WhatMediaAttributes extends WhatHTMLAttributes {
185
+ interface WhatMediaAttributes<T extends HTMLElement = HTMLMediaElement> extends WhatHTMLAttributes<T> {
174
186
  src?: Reactive<string>;
175
187
  controls?: Reactive<boolean>;
176
188
  autoplay?: Reactive<boolean>;
@@ -181,7 +193,7 @@ interface WhatMediaAttributes extends WhatHTMLAttributes {
181
193
  }
182
194
 
183
195
  // SVG (recharts and other chart libraries render through this).
184
- interface WhatSVGAttributes extends WhatHTMLAttributes {
196
+ interface WhatSVGAttributes<T extends SVGElement = SVGElement> extends WhatHTMLAttributes<T> {
185
197
  width?: Reactive<string | number>;
186
198
  height?: Reactive<string | number>;
187
199
  viewBox?: Reactive<string>;
@@ -198,19 +210,30 @@ interface WhatSVGAttributes extends WhatHTMLAttributes {
198
210
  }
199
211
 
200
212
  export namespace JSX {
201
- type Element = VNode;
213
+ /**
214
+ * Empty in a native app. An app that mixes native and React files
215
+ * (what-react's MIXED.md) references `what-react/mixed`, which adds React's
216
+ * element shape here: JSX inside a React component's tag is a React
217
+ * element, and fits a React component's `children: ReactNode`.
218
+ */
219
+ interface ForeignElement {}
220
+ /** Empty in a native app. `what-react/mixed` adds React components (functions returning ReactNode, forwardRef and memo objects, classes). */
221
+ interface ForeignComponents {}
222
+ type Element = VNode & ForeignElement;
202
223
  // TS 5.1+ checks component returns separately from the JSX expression type.
203
224
  // `never` accepts each component's own props without erasing JSX prop checks.
204
- type ElementType = string | ((props: never) => VNodeChild);
225
+ type ElementType = string | ((props: never) => VNodeChild) | ForeignComponents[keyof ForeignComponents];
205
226
  interface ElementChildrenAttribute {
206
227
  children: {};
207
228
  }
208
229
  interface IntrinsicAttributes {
209
- key?: string | number;
230
+ /** A row's key; <For key={(item) => item.id}> takes the function that gives it, which is handed the index too. */
231
+ key?: string | number | ((item: never, index: number) => unknown);
210
232
  }
211
233
 
212
234
  interface IntrinsicElements {
213
235
  // Element-specific typing (autocomplete for the props that matter most).
236
+ // Each element's event handlers see it as `e.currentTarget`.
214
237
  a: WhatAnchorAttributes;
215
238
  img: WhatImgAttributes;
216
239
  input: WhatInputAttributes;
@@ -220,95 +243,95 @@ export namespace JSX {
220
243
  option: WhatOptionAttributes;
221
244
  select: WhatSelectAttributes;
222
245
  textarea: WhatTextareaAttributes;
223
- video: WhatMediaAttributes;
224
- audio: WhatMediaAttributes;
225
- source: WhatMediaAttributes;
246
+ video: WhatMediaAttributes<HTMLVideoElement>;
247
+ audio: WhatMediaAttributes<HTMLAudioElement>;
248
+ source: WhatMediaAttributes<HTMLSourceElement>;
226
249
 
227
250
  // Structural / text / sectioning elements.
228
- div: WhatHTMLAttributes;
229
- span: WhatHTMLAttributes;
230
- p: WhatHTMLAttributes;
231
- section: WhatHTMLAttributes;
232
- article: WhatHTMLAttributes;
233
- header: WhatHTMLAttributes;
234
- footer: WhatHTMLAttributes;
235
- main: WhatHTMLAttributes;
236
- aside: WhatHTMLAttributes;
237
- nav: WhatHTMLAttributes;
238
- h1: WhatHTMLAttributes;
239
- h2: WhatHTMLAttributes;
240
- h3: WhatHTMLAttributes;
241
- h4: WhatHTMLAttributes;
242
- h5: WhatHTMLAttributes;
243
- h6: WhatHTMLAttributes;
244
- ul: WhatHTMLAttributes;
245
- ol: WhatHTMLAttributes;
246
- li: WhatHTMLAttributes;
247
- dl: WhatHTMLAttributes;
248
- dt: WhatHTMLAttributes;
249
- dd: WhatHTMLAttributes;
250
- table: WhatHTMLAttributes;
251
- thead: WhatHTMLAttributes;
252
- tbody: WhatHTMLAttributes;
253
- tfoot: WhatHTMLAttributes;
254
- tr: WhatHTMLAttributes;
255
- th: WhatHTMLAttributes;
256
- td: WhatHTMLAttributes;
257
- caption: WhatHTMLAttributes;
258
- colgroup: WhatHTMLAttributes;
259
- col: WhatHTMLAttributes;
260
- fieldset: WhatHTMLAttributes;
261
- legend: WhatHTMLAttributes;
262
- strong: WhatHTMLAttributes;
263
- em: WhatHTMLAttributes;
264
- b: WhatHTMLAttributes;
265
- i: WhatHTMLAttributes;
266
- u: WhatHTMLAttributes;
267
- small: WhatHTMLAttributes;
268
- mark: WhatHTMLAttributes;
269
- code: WhatHTMLAttributes;
270
- pre: WhatHTMLAttributes;
271
- kbd: WhatHTMLAttributes;
272
- blockquote: WhatHTMLAttributes;
273
- hr: WhatHTMLAttributes;
274
- br: WhatHTMLAttributes;
275
- figure: WhatHTMLAttributes;
276
- figcaption: WhatHTMLAttributes;
277
- details: WhatHTMLAttributes;
278
- summary: WhatHTMLAttributes;
279
- dialog: WhatHTMLAttributes;
280
- picture: WhatHTMLAttributes;
281
- iframe: WhatHTMLAttributes;
282
- canvas: WhatHTMLAttributes;
283
- template: WhatHTMLAttributes;
284
- slot: WhatHTMLAttributes;
285
- time: WhatHTMLAttributes;
286
- progress: WhatHTMLAttributes;
287
- meter: WhatHTMLAttributes;
288
- output: WhatHTMLAttributes;
289
- datalist: WhatHTMLAttributes;
290
- optgroup: WhatHTMLAttributes;
251
+ div: WhatHTMLAttributes<HTMLElementTagNameMap['div']>;
252
+ span: WhatHTMLAttributes<HTMLElementTagNameMap['span']>;
253
+ p: WhatHTMLAttributes<HTMLElementTagNameMap['p']>;
254
+ section: WhatHTMLAttributes<HTMLElementTagNameMap['section']>;
255
+ article: WhatHTMLAttributes<HTMLElementTagNameMap['article']>;
256
+ header: WhatHTMLAttributes<HTMLElementTagNameMap['header']>;
257
+ footer: WhatHTMLAttributes<HTMLElementTagNameMap['footer']>;
258
+ main: WhatHTMLAttributes<HTMLElementTagNameMap['main']>;
259
+ aside: WhatHTMLAttributes<HTMLElementTagNameMap['aside']>;
260
+ nav: WhatHTMLAttributes<HTMLElementTagNameMap['nav']>;
261
+ h1: WhatHTMLAttributes<HTMLElementTagNameMap['h1']>;
262
+ h2: WhatHTMLAttributes<HTMLElementTagNameMap['h2']>;
263
+ h3: WhatHTMLAttributes<HTMLElementTagNameMap['h3']>;
264
+ h4: WhatHTMLAttributes<HTMLElementTagNameMap['h4']>;
265
+ h5: WhatHTMLAttributes<HTMLElementTagNameMap['h5']>;
266
+ h6: WhatHTMLAttributes<HTMLElementTagNameMap['h6']>;
267
+ ul: WhatHTMLAttributes<HTMLElementTagNameMap['ul']>;
268
+ ol: WhatHTMLAttributes<HTMLElementTagNameMap['ol']>;
269
+ li: WhatHTMLAttributes<HTMLElementTagNameMap['li']>;
270
+ dl: WhatHTMLAttributes<HTMLElementTagNameMap['dl']>;
271
+ dt: WhatHTMLAttributes<HTMLElementTagNameMap['dt']>;
272
+ dd: WhatHTMLAttributes<HTMLElementTagNameMap['dd']>;
273
+ table: WhatHTMLAttributes<HTMLElementTagNameMap['table']>;
274
+ thead: WhatHTMLAttributes<HTMLElementTagNameMap['thead']>;
275
+ tbody: WhatHTMLAttributes<HTMLElementTagNameMap['tbody']>;
276
+ tfoot: WhatHTMLAttributes<HTMLElementTagNameMap['tfoot']>;
277
+ tr: WhatHTMLAttributes<HTMLElementTagNameMap['tr']>;
278
+ th: WhatHTMLAttributes<HTMLElementTagNameMap['th']>;
279
+ td: WhatHTMLAttributes<HTMLElementTagNameMap['td']>;
280
+ caption: WhatHTMLAttributes<HTMLElementTagNameMap['caption']>;
281
+ colgroup: WhatHTMLAttributes<HTMLElementTagNameMap['colgroup']>;
282
+ col: WhatHTMLAttributes<HTMLElementTagNameMap['col']>;
283
+ fieldset: WhatHTMLAttributes<HTMLElementTagNameMap['fieldset']>;
284
+ legend: WhatHTMLAttributes<HTMLElementTagNameMap['legend']>;
285
+ strong: WhatHTMLAttributes<HTMLElementTagNameMap['strong']>;
286
+ em: WhatHTMLAttributes<HTMLElementTagNameMap['em']>;
287
+ b: WhatHTMLAttributes<HTMLElementTagNameMap['b']>;
288
+ i: WhatHTMLAttributes<HTMLElementTagNameMap['i']>;
289
+ u: WhatHTMLAttributes<HTMLElementTagNameMap['u']>;
290
+ small: WhatHTMLAttributes<HTMLElementTagNameMap['small']>;
291
+ mark: WhatHTMLAttributes<HTMLElementTagNameMap['mark']>;
292
+ code: WhatHTMLAttributes<HTMLElementTagNameMap['code']>;
293
+ pre: WhatHTMLAttributes<HTMLElementTagNameMap['pre']>;
294
+ kbd: WhatHTMLAttributes<HTMLElementTagNameMap['kbd']>;
295
+ blockquote: WhatHTMLAttributes<HTMLElementTagNameMap['blockquote']>;
296
+ hr: WhatHTMLAttributes<HTMLElementTagNameMap['hr']>;
297
+ br: WhatHTMLAttributes<HTMLElementTagNameMap['br']>;
298
+ figure: WhatHTMLAttributes<HTMLElementTagNameMap['figure']>;
299
+ figcaption: WhatHTMLAttributes<HTMLElementTagNameMap['figcaption']>;
300
+ details: WhatHTMLAttributes<HTMLElementTagNameMap['details']>;
301
+ summary: WhatHTMLAttributes<HTMLElementTagNameMap['summary']>;
302
+ dialog: WhatHTMLAttributes<HTMLElementTagNameMap['dialog']>;
303
+ picture: WhatHTMLAttributes<HTMLElementTagNameMap['picture']>;
304
+ iframe: WhatHTMLAttributes<HTMLElementTagNameMap['iframe']>;
305
+ canvas: WhatHTMLAttributes<HTMLElementTagNameMap['canvas']>;
306
+ template: WhatHTMLAttributes<HTMLElementTagNameMap['template']>;
307
+ slot: WhatHTMLAttributes<HTMLElementTagNameMap['slot']>;
308
+ time: WhatHTMLAttributes<HTMLElementTagNameMap['time']>;
309
+ progress: WhatHTMLAttributes<HTMLElementTagNameMap['progress']>;
310
+ meter: WhatHTMLAttributes<HTMLElementTagNameMap['meter']>;
311
+ output: WhatHTMLAttributes<HTMLElementTagNameMap['output']>;
312
+ datalist: WhatHTMLAttributes<HTMLElementTagNameMap['datalist']>;
313
+ optgroup: WhatHTMLAttributes<HTMLElementTagNameMap['optgroup']>;
291
314
 
292
315
  // SVG.
293
- svg: WhatSVGAttributes;
294
- g: WhatSVGAttributes;
295
- path: WhatSVGAttributes;
296
- circle: WhatSVGAttributes;
297
- ellipse: WhatSVGAttributes;
298
- rect: WhatSVGAttributes;
299
- line: WhatSVGAttributes;
300
- polyline: WhatSVGAttributes;
301
- polygon: WhatSVGAttributes;
302
- text: WhatSVGAttributes;
303
- tspan: WhatSVGAttributes;
304
- defs: WhatSVGAttributes;
305
- linearGradient: WhatSVGAttributes;
306
- radialGradient: WhatSVGAttributes;
307
- stop: WhatSVGAttributes;
308
- clipPath: WhatSVGAttributes;
309
- use: WhatSVGAttributes;
316
+ svg: WhatSVGAttributes<SVGElementTagNameMap['svg']>;
317
+ g: WhatSVGAttributes<SVGElementTagNameMap['g']>;
318
+ path: WhatSVGAttributes<SVGElementTagNameMap['path']>;
319
+ circle: WhatSVGAttributes<SVGElementTagNameMap['circle']>;
320
+ ellipse: WhatSVGAttributes<SVGElementTagNameMap['ellipse']>;
321
+ rect: WhatSVGAttributes<SVGElementTagNameMap['rect']>;
322
+ line: WhatSVGAttributes<SVGElementTagNameMap['line']>;
323
+ polyline: WhatSVGAttributes<SVGElementTagNameMap['polyline']>;
324
+ polygon: WhatSVGAttributes<SVGElementTagNameMap['polygon']>;
325
+ text: WhatSVGAttributes<SVGElementTagNameMap['text']>;
326
+ tspan: WhatSVGAttributes<SVGElementTagNameMap['tspan']>;
327
+ defs: WhatSVGAttributes<SVGElementTagNameMap['defs']>;
328
+ linearGradient: WhatSVGAttributes<SVGElementTagNameMap['linearGradient']>;
329
+ radialGradient: WhatSVGAttributes<SVGElementTagNameMap['radialGradient']>;
330
+ stop: WhatSVGAttributes<SVGElementTagNameMap['stop']>;
331
+ clipPath: WhatSVGAttributes<SVGElementTagNameMap['clipPath']>;
332
+ use: WhatSVGAttributes<SVGElementTagNameMap['use']>;
310
333
 
311
- // Custom elements / web components remain valid.
334
+ // Custom elements / web components remain valid; their handlers see an Element.
312
335
  [tagName: string]: WhatHTMLAttributes;
313
336
  }
314
337
  }
@@ -0,0 +1,83 @@
1
+ // what-core/internal/markup-rules: the markup rules every renderer applies
2
+ // (src/markup-rules.js). what-server applies them to every value it renders,
3
+ // what-compiler to static markup when a module is compiled, and the client to
4
+ // every attribute it sets. Import-free. Not for applications, and not covered
5
+ // by semver.
6
+
7
+ /** A namespace: null for HTML, or SVG / MathML content ('foreign' when it is not known which). */
8
+ export type MarkupNamespace = 'svg' | 'math' | 'foreign' | null;
9
+
10
+ /** Attribute names that can be emitted verbatim. */
11
+ export const SAFE_ATTR_NAME: RegExp;
12
+ /** Tag names that can be emitted verbatim. */
13
+ export const SAFE_TAG_NAME: RegExp;
14
+ /** Attributes whose value is a URL, in lower case (the SVG animation values among them). */
15
+ export const URL_ATTRS: ReadonlySet<string>;
16
+ /** Whether `name`, in any case, holds a URL. */
17
+ export function isUrlAttr(name: string): boolean;
18
+ /** Whether a URL value (or an item of a `;`-separated list of them) uses a javascript:, vbscript: or data: scheme. */
19
+ export function isUnsafeUrl(value: unknown): boolean;
20
+ /** Props never applied, in lower case: srcdoc, outerhtml. */
21
+ export const REFUSED_ATTRS: ReadonlySet<string>;
22
+ /** Whether `name`, in any case, is never applied. */
23
+ export function isRefusedAttr(name: string): boolean;
24
+ /** innerHTML and dangerouslySetInnerHTML, which take { __html } only. */
25
+ export const INNER_HTML_PROPS: ReadonlySet<string>;
26
+ /** Prop names whose attribute is spelled differently (className -> class). */
27
+ export const ATTRIBUTE_ALIASES: ReadonlyMap<string, string>;
28
+ /** The attribute a prop name writes. */
29
+ export function attributeName(prop: string): string;
30
+ /** The attribute `prop` is written as in markup: a field default (`defaultValue`, `defaultChecked`, `defaultSelected`) is its content attribute. */
31
+ export function markupName(prop: string): string;
32
+ /** value, defaultValue, checked, defaultChecked: the props that hold a form field's state. */
33
+ export const FIELD_PROPS: ReadonlySet<string>;
34
+ /** input, textarea, select: the elements whose state those props hold. */
35
+ export const FIELD_TAGS: ReadonlySet<string>;
36
+ /** The <input> types whose `value` is an attribute (checkbox, radio, hidden and the buttons). */
37
+ export const ATTRIBUTE_VALUE_TYPES: ReadonlySet<string>;
38
+ /** `text` with ASCII whitespace stripped from both ends and collapsed: an <option>'s value from its text. */
39
+ export function stripAndCollapse(text: string): string;
40
+ /** One boolean per option value: whether the <select> value `value` selects that option. */
41
+ export function selectedOptions(values: readonly string[], value: unknown): boolean[];
42
+ /** role and aria-*. */
43
+ export function isAriaAttr(name: string): boolean;
44
+ /** aria-*, role and data-*: true and false are written out. */
45
+ export function isEnumeratedAttr(name: string): boolean;
46
+ /** HTML void elements. */
47
+ export const VOID_ELEMENTS: ReadonlySet<string>;
48
+ /** SVG elements whose children are parsed as HTML. */
49
+ export const SVG_HTML_INTEGRATION_POINTS: ReadonlySet<string>;
50
+ /** MathML token elements whose children are parsed as HTML. */
51
+ export const MATHML_TEXT_INTEGRATION_POINTS: ReadonlySet<string>;
52
+ /** MathML elements that stay MathML inside a token element. */
53
+ export const MATHML_IN_TEXT_POINTS: ReadonlySet<string>;
54
+ /** The annotation-xml encodings whose children are parsed as HTML. */
55
+ export const HTML_ENCODINGS: ReadonlySet<string>;
56
+ /** The namespace the children of `tag` are parsed in, given the namespace `tag` is in. */
57
+ export function childNamespace(ns: MarkupNamespace, tag: string, encoding?: unknown): MarkupNamespace;
58
+ /** Elements whose content the HTML parser reads as raw text: script, style. */
59
+ export const RAW_TEXT_ELEMENTS: ReadonlySet<string>;
60
+ /** <textarea> and <title>: text the parser decodes, with no markup (a comment there is text). */
61
+ export const TEXT_ONLY_ELEMENTS: ReadonlySet<string>;
62
+ /** <pre>, <textarea> and <listing>: the parser drops a newline right after their start tag. */
63
+ export const LEADING_NEWLINE_ELEMENTS: ReadonlySet<string>;
64
+ /** Whether raw text holds a sequence that could end its element. */
65
+ export function rawTextHazard(tag: string, text: string): boolean;
66
+ /** Raw text, encoded so it cannot end its element. */
67
+ export function encodeRawText(tag: string, text: string): string;
68
+ /** The content of a script or style holding `text`, written in namespace `ns`. */
69
+ export function rawTextContent(tag: string, text: string, ns: MarkupNamespace): string;
70
+ /** Text without `&` or `<`: the same in a raw-text element in every namespace. */
71
+ export function isNamespaceNeutralText(text: string): boolean;
72
+ /** Escapes `& < > " '` for HTML text and attribute values. */
73
+ export function escapeHtml(str: string): string;
74
+ /** A style object as CSS text: what-server's style attribute and what-framework/dom's style(). A declaration the client's CSSOM would refuse, and a null, undefined, boolean or empty value, is left out. */
75
+ export function styleText(style: Record<string, unknown>): string;
76
+ /** Whether `text` is one declaration's value in a conservative CSS grammar. */
77
+ export function oneDeclaration(text: string): boolean;
78
+ /** Values that are one declaration's value by their characters alone. */
79
+ export const PLAIN_CSS_VALUE: RegExp;
80
+ /** How many property names styleText remembers. */
81
+ export const CSS_NAME_CACHE_SIZE: number;
82
+ /** The property names styleText has written, by the name a style object gave. */
83
+ export const _cssNames: Map<string, string | null>;
package/motion.d.ts ADDED
@@ -0,0 +1,156 @@
1
+ // what-core/motion (what-framework/motion): springs, tweens, gestures and CSS transitions.
2
+ import type { Signal } from './index.js';
3
+
4
+ // --- Animation ---
5
+ //
6
+ // Every accessor below is a plain getter function, NOT a Signal: the objects
7
+ // these factories return expose reads through closures and offer writes as
8
+ // named methods (set/snap/setValue), so nothing here carries .set/.peek.
9
+ // spring() and tween() return two different objects, SpringValue and
10
+ // TweenValue.
11
+
12
+ export interface SpringConfig {
13
+ stiffness?: number;
14
+ damping?: number;
15
+ mass?: number;
16
+ precision?: number;
17
+ }
18
+
19
+ /** Physics-based value. `set()` retargets and animates; `snap()` jumps without animating. */
20
+ export interface SpringValue {
21
+ current(): number;
22
+ target(): number;
23
+ velocity(): number;
24
+ isAnimating(): boolean;
25
+ set(target: number): void;
26
+ stop(): void;
27
+ snap(value: number): void;
28
+ subscribe(fn: (value: number) => void): () => void;
29
+ }
30
+
31
+ export interface TweenConfig {
32
+ duration?: number;
33
+ easing?: (t: number) => number;
34
+ onUpdate?: (value: number, progress: number) => void;
35
+ onComplete?: () => void;
36
+ }
37
+
38
+ /**
39
+ * Easing-based interpolation from `from` to `to`. Starts immediately on
40
+ * creation and runs to completion, so it exposes `cancel()` rather than the
41
+ * spring's retargeting `set()`/`stop()`.
42
+ */
43
+ export interface TweenValue {
44
+ progress(): number;
45
+ value(): number;
46
+ isAnimating(): boolean;
47
+ cancel(): void;
48
+ subscribe(fn: (value: number) => void): () => void;
49
+ }
50
+
51
+ export function spring(initialValue: number, config?: SpringConfig): SpringValue;
52
+ /**
53
+ * Both endpoints are required and positional. This was declared as
54
+ * `tween(initialValue?, config?)` returning a SpringValue, so the documented
55
+ * call `tween(0, 100, { duration: 300 })` was a type error, while
56
+ * `tween(0).current()` type-checked and threw (`current` does not exist, and a
57
+ * missing `to` interpolates toward undefined).
58
+ */
59
+ export function tween(from: number, to: number, config?: TweenConfig): TweenValue;
60
+ export const easings: Record<string, (t: number) => number>;
61
+ /**
62
+ * Drives a 0..1 progress value over `duration`. Named useTween so that
63
+ * useTransition can mean what it means in React. One run at a time: start()
64
+ * stops the run in flight (its promise resolves, its callback does not run),
65
+ * and the owner going away stops it.
66
+ */
67
+ export function useTween(options?: { duration?: number; easing?: (t: number) => number }): {
68
+ isTransitioning: () => boolean;
69
+ progress: () => number;
70
+ start: (callback?: () => void) => Promise<void>;
71
+ };
72
+
73
+ /** Live gesture state. `startX`/`startY` are plain numbers rewritten in place at gesture start. */
74
+ export interface GestureState {
75
+ isDragging: Signal<boolean>;
76
+ startX: number;
77
+ startY: number;
78
+ currentX: Signal<number>;
79
+ currentY: Signal<number>;
80
+ deltaX: Signal<number>;
81
+ deltaY: Signal<number>;
82
+ velocity: Signal<GestureVelocity>;
83
+ }
84
+
85
+ export interface GestureVelocity {
86
+ x: number;
87
+ y: number;
88
+ }
89
+
90
+ /**
91
+ * `preventDefault` is why this cannot be a `Record<string, (payload) => void>`:
92
+ * it sits in the same object as the callbacks and is a boolean.
93
+ */
94
+ export interface GestureHandlers {
95
+ onDragStart?: (payload: { x: number; y: number }) => void;
96
+ onDrag?: (payload: {
97
+ x: number; y: number; deltaX: number; deltaY: number; velocity: GestureVelocity;
98
+ }) => void;
99
+ onDragEnd?: (payload: { deltaX: number; deltaY: number; velocity: GestureVelocity }) => void;
100
+ onPinch?: (payload: { scale: number; centerX: number; centerY: number }) => void;
101
+ onSwipe?: (payload: { direction: 'up' | 'down' | 'left' | 'right'; velocity: GestureVelocity }) => void;
102
+ onTap?: (payload: { x: number; y: number }) => void;
103
+ onLongPress?: (payload: { x: number; y: number }) => void;
104
+ /** Opt in to e.preventDefault() in the touch handlers (listeners become non-passive). */
105
+ preventDefault?: boolean;
106
+ }
107
+
108
+ /** Returns the gesture state. It was declared `void`, so the state was unreachable from TypeScript. */
109
+ export function useGesture(
110
+ ref: { current?: Element | null } | Element | (() => Element | null),
111
+ handlers?: GestureHandlers,
112
+ ): GestureState;
113
+
114
+ /** Handle for one running animation started by useAnimatedValue. */
115
+ export interface AnimationHandle {
116
+ stop: () => void;
117
+ }
118
+
119
+ /**
120
+ * Animations are started with spring()/timing(), each returning its own
121
+ * handle to stop. One runs at a time: starting one stops the one before, and
122
+ * the owner going away stops it.
123
+ */
124
+ export function useAnimatedValue(initialValue: number): {
125
+ value: () => number;
126
+ setValue: (value: number) => void;
127
+ spring: (toValue: number, config?: SpringConfig) => AnimationHandle;
128
+ timing: (toValue: number, config?: TweenConfig) => AnimationHandle;
129
+ interpolate: (inputRange: number[], outputRange: number[]) => () => number;
130
+ subscribe: (fn: (value: number) => void) => () => void;
131
+ };
132
+
133
+ export interface TransitionClasses {
134
+ enter: string;
135
+ enterActive: string;
136
+ enterDone: string;
137
+ exit: string;
138
+ exitActive: string;
139
+ exitDone: string;
140
+ }
141
+
142
+ /** Returns the six class NAMES for `name`, not a single string. */
143
+ export function createTransitionClasses(name: string): TransitionClasses;
144
+ /**
145
+ * Applies the enter/exit class sequence to an element and resolves when the
146
+ * transition is done. It was declared as a synchronous `(config) => object`.
147
+ */
148
+ export function cssTransition(
149
+ element: Element,
150
+ name: string,
151
+ type?: 'enter' | 'exit',
152
+ duration?: number,
153
+ ): Promise<void>;
154
+
155
+ /** Enter/leave classes for a CSS transition, as props to spread on the element. */
156
+ export function transitionClass(name: string, active: boolean): { class: string };