UNPKG

21.1 kBTypeScriptView Raw
1/**
2 * The names of the supported HTML5 DOM element attributes.
3 *
4 * This list is not all-encompassing, rather it attempts to define the
5 * attribute names which are relevant for use in a virtual DOM context.
6 * If a standardized or widely supported name is missing, please open
7 * an issue to have it added.
8 *
9 * The attribute names were collected from the following sources:
10 * - https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
11 * - https://www.w3.org/TR/html5/index.html#attributes-1
12 * - https://html.spec.whatwg.org/multipage/indices.html#attributes-3
13 */
14export declare type ElementAttrNames = ('abbr' | 'accept' | 'accept-charset' | 'accesskey' | 'action' | 'allowfullscreen' | 'alt' | 'autocomplete' | 'autofocus' | 'autoplay' | 'autosave' | 'checked' | 'cite' | 'cols' | 'colspan' | 'contenteditable' | 'controls' | 'coords' | 'crossorigin' | 'data' | 'datetime' | 'default' | 'dir' | 'dirname' | 'disabled' | 'download' | 'draggable' | 'dropzone' | 'enctype' | 'form' | 'formaction' | 'formenctype' | 'formmethod' | 'formnovalidate' | 'formtarget' | 'headers' | 'height' | 'hidden' | 'high' | 'href' | 'hreflang' | 'id' | 'inputmode' | 'integrity' | 'ismap' | 'kind' | 'label' | 'lang' | 'list' | 'loop' | 'low' | 'max' | 'maxlength' | 'media' | 'mediagroup' | 'method' | 'min' | 'minlength' | 'multiple' | 'muted' | 'name' | 'novalidate' | 'optimum' | 'pattern' | 'placeholder' | 'poster' | 'preload' | 'readonly' | 'rel' | 'required' | 'reversed' | 'rows' | 'rowspan' | 'sandbox' | 'scope' | 'selected' | 'shape' | 'size' | 'sizes' | 'span' | 'spellcheck' | 'src' | 'srcdoc' | 'srclang' | 'srcset' | 'start' | 'step' | 'tabindex' | 'target' | 'title' | 'type' | 'typemustmatch' | 'usemap' | 'value' | 'width' | 'wrap');
15/**
16 * The names of the supported HTML5 CSS property names.
17 *
18 * If a standardized or widely supported name is missing, please open
19 * an issue to have it added.
20 *
21 * The property names were collected from the following sources:
22 * - TypeScript's `lib.dom.d.ts` file
23 */
24export declare type CSSPropertyNames = ('alignContent' | 'alignItems' | 'alignSelf' | 'alignmentBaseline' | 'animation' | 'animationDelay' | 'animationDirection' | 'animationDuration' | 'animationFillMode' | 'animationIterationCount' | 'animationName' | 'animationPlayState' | 'animationTimingFunction' | 'backfaceVisibility' | 'background' | 'backgroundAttachment' | 'backgroundClip' | 'backgroundColor' | 'backgroundImage' | 'backgroundOrigin' | 'backgroundPosition' | 'backgroundPositionX' | 'backgroundPositionY' | 'backgroundRepeat' | 'backgroundSize' | 'baselineShift' | 'border' | 'borderBottom' | 'borderBottomColor' | 'borderBottomLeftRadius' | 'borderBottomRightRadius' | 'borderBottomStyle' | 'borderBottomWidth' | 'borderCollapse' | 'borderColor' | 'borderImage' | 'borderImageOutset' | 'borderImageRepeat' | 'borderImageSlice' | 'borderImageSource' | 'borderImageWidth' | 'borderLeft' | 'borderLeftColor' | 'borderLeftStyle' | 'borderLeftWidth' | 'borderRadius' | 'borderRight' | 'borderRightColor' | 'borderRightStyle' | 'borderRightWidth' | 'borderSpacing' | 'borderStyle' | 'borderTop' | 'borderTopColor' | 'borderTopLeftRadius' | 'borderTopRightRadius' | 'borderTopStyle' | 'borderTopWidth' | 'borderWidth' | 'bottom' | 'boxShadow' | 'boxSizing' | 'breakAfter' | 'breakBefore' | 'breakInside' | 'captionSide' | 'clear' | 'clip' | 'clipPath' | 'clipRule' | 'color' | 'colorInterpolationFilters' | 'columnCount' | 'columnFill' | 'columnGap' | 'columnRule' | 'columnRuleColor' | 'columnRuleStyle' | 'columnRuleWidth' | 'columnSpan' | 'columnWidth' | 'columns' | 'content' | 'counterIncrement' | 'counterReset' | 'cssFloat' | 'cssText' | 'cursor' | 'direction' | 'display' | 'dominantBaseline' | 'emptyCells' | 'enableBackground' | 'fill' | 'fillOpacity' | 'fillRule' | 'filter' | 'flex' | 'flexBasis' | 'flexDirection' | 'flexFlow' | 'flexGrow' | 'flexShrink' | 'flexWrap' | 'floodColor' | 'floodOpacity' | 'font' | 'fontFamily' | 'fontFeatureSettings' | 'fontSize' | 'fontSizeAdjust' | 'fontStretch' | 'fontStyle' | 'fontVariant' | 'fontWeight' | 'glyphOrientationHorizontal' | 'glyphOrientationVertical' | 'height' | 'imeMode' | 'justifyContent' | 'kerning' | 'left' | 'letterSpacing' | 'lightingColor' | 'lineHeight' | 'listStyle' | 'listStyleImage' | 'listStylePosition' | 'listStyleType' | 'margin' | 'marginBottom' | 'marginLeft' | 'marginRight' | 'marginTop' | 'marker' | 'markerEnd' | 'markerMid' | 'markerStart' | 'mask' | 'maxHeight' | 'maxWidth' | 'minHeight' | 'minWidth' | 'msContentZoomChaining' | 'msContentZoomLimit' | 'msContentZoomLimitMax' | 'msContentZoomLimitMin' | 'msContentZoomSnap' | 'msContentZoomSnapPoints' | 'msContentZoomSnapType' | 'msContentZooming' | 'msFlowFrom' | 'msFlowInto' | 'msFontFeatureSettings' | 'msGridColumn' | 'msGridColumnAlign' | 'msGridColumnSpan' | 'msGridColumns' | 'msGridRow' | 'msGridRowAlign' | 'msGridRowSpan' | 'msGridRows' | 'msHighContrastAdjust' | 'msHyphenateLimitChars' | 'msHyphenateLimitLines' | 'msHyphenateLimitZone' | 'msHyphens' | 'msImeAlign' | 'msOverflowStyle' | 'msScrollChaining' | 'msScrollLimit' | 'msScrollLimitXMax' | 'msScrollLimitXMin' | 'msScrollLimitYMax' | 'msScrollLimitYMin' | 'msScrollRails' | 'msScrollSnapPointsX' | 'msScrollSnapPointsY' | 'msScrollSnapType' | 'msScrollSnapX' | 'msScrollSnapY' | 'msScrollTranslation' | 'msTextCombineHorizontal' | 'msTextSizeAdjust' | 'msTouchAction' | 'msTouchSelect' | 'msUserSelect' | 'msWrapFlow' | 'msWrapMargin' | 'msWrapThrough' | 'opacity' | 'order' | 'orphans' | 'outline' | 'outlineColor' | 'outlineStyle' | 'outlineWidth' | 'overflow' | 'overflowX' | 'overflowY' | 'padding' | 'paddingBottom' | 'paddingLeft' | 'paddingRight' | 'paddingTop' | 'pageBreakAfter' | 'pageBreakBefore' | 'pageBreakInside' | 'perspective' | 'perspectiveOrigin' | 'pointerEvents' | 'position' | 'quotes' | 'resize' | 'right' | 'rubyAlign' | 'rubyOverhang' | 'rubyPosition' | 'stopColor' | 'stopOpacity' | 'stroke' | 'strokeDasharray' | 'strokeDashoffset' | 'strokeLinecap' | 'strokeLinejoin' | 'strokeMiterlimit' | 'strokeOpacity' | 'strokeWidth' | 'tableLayout' | 'textAlign' | 'textAlignLast' | 'textAnchor' | 'textDecoration' | 'textIndent' | 'textJustify' | 'textKashida' | 'textKashidaSpace' | 'textOverflow' | 'textShadow' | 'textTransform' | 'textUnderlinePosition' | 'top' | 'touchAction' | 'transform' | 'transformOrigin' | 'transformStyle' | 'transition' | 'transitionDelay' | 'transitionDuration' | 'transitionProperty' | 'transitionTimingFunction' | 'unicodeBidi' | 'verticalAlign' | 'visibility' | 'webkitAlignContent' | 'webkitAlignItems' | 'webkitAlignSelf' | 'webkitAnimation' | 'webkitAnimationDelay' | 'webkitAnimationDirection' | 'webkitAnimationDuration' | 'webkitAnimationFillMode' | 'webkitAnimationIterationCount' | 'webkitAnimationName' | 'webkitAnimationPlayState' | 'webkitAnimationTimingFunction' | 'webkitAppearance' | 'webkitBackfaceVisibility' | 'webkitBackgroundClip' | 'webkitBackgroundOrigin' | 'webkitBackgroundSize' | 'webkitBorderBottomLeftRadius' | 'webkitBorderBottomRightRadius' | 'webkitBorderImage' | 'webkitBorderRadius' | 'webkitBorderTopLeftRadius' | 'webkitBorderTopRightRadius' | 'webkitBoxAlign' | 'webkitBoxDirection' | 'webkitBoxFlex' | 'webkitBoxOrdinalGroup' | 'webkitBoxOrient' | 'webkitBoxPack' | 'webkitBoxSizing' | 'webkitColumnBreakAfter' | 'webkitColumnBreakBefore' | 'webkitColumnBreakInside' | 'webkitColumnCount' | 'webkitColumnGap' | 'webkitColumnRule' | 'webkitColumnRuleColor' | 'webkitColumnRuleStyle' | 'webkitColumnRuleWidth' | 'webkitColumnSpan' | 'webkitColumnWidth' | 'webkitColumns' | 'webkitFilter' | 'webkitFlex' | 'webkitFlexBasis' | 'webkitFlexDirection' | 'webkitFlexFlow' | 'webkitFlexGrow' | 'webkitFlexShrink' | 'webkitFlexWrap' | 'webkitJustifyContent' | 'webkitOrder' | 'webkitPerspective' | 'webkitPerspectiveOrigin' | 'webkitTapHighlightColor' | 'webkitTextFillColor' | 'webkitTextSizeAdjust' | 'webkitTransform' | 'webkitTransformOrigin' | 'webkitTransformStyle' | 'webkitTransition' | 'webkitTransitionDelay' | 'webkitTransitionDuration' | 'webkitTransitionProperty' | 'webkitTransitionTimingFunction' | 'webkitUserModify' | 'webkitUserSelect' | 'webkitWritingMode' | 'whiteSpace' | 'widows' | 'width' | 'wordBreak' | 'wordSpacing' | 'wordWrap' | 'writingMode' | 'zIndex' | 'zoom');
25/**
26 * A mapping of inline event name to event object type.
27 *
28 * This mapping is used to create the event listener properties for
29 * the virtual DOM element attributes object. If a standardized or
30 * widely supported name is missing, please open an issue to have it
31 * added.
32 *
33 * The event names were collected from the following sources:
34 * - TypeScript's `lib.dom.d.ts` file
35 * - https://www.w3.org/TR/html5/index.html#attributes-1
36 * - https://html.spec.whatwg.org/multipage/webappapis.html#idl-definitions
37 */
38export declare type ElementEventMap = {
39 onabort: UIEvent;
40 onauxclick: MouseEvent;
41 onblur: FocusEvent;
42 oncanplay: Event;
43 oncanplaythrough: Event;
44 onchange: Event;
45 onclick: MouseEvent;
46 oncontextmenu: PointerEvent;
47 oncopy: ClipboardEvent;
48 oncuechange: Event;
49 oncut: ClipboardEvent;
50 ondblclick: MouseEvent;
51 ondrag: DragEvent;
52 ondragend: DragEvent;
53 ondragenter: DragEvent;
54 ondragexit: DragEvent;
55 ondragleave: DragEvent;
56 ondragover: DragEvent;
57 ondragstart: DragEvent;
58 ondrop: DragEvent;
59 ondurationchange: Event;
60 onemptied: Event;
61 onended: MediaStreamErrorEvent;
62 onerror: ErrorEvent;
63 onfocus: FocusEvent;
64 oninput: Event;
65 oninvalid: Event;
66 onkeydown: KeyboardEvent;
67 onkeypress: KeyboardEvent;
68 onkeyup: KeyboardEvent;
69 onload: Event;
70 onloadeddata: Event;
71 onloadedmetadata: Event;
72 onloadend: Event;
73 onloadstart: Event;
74 onmousedown: MouseEvent;
75 onmouseenter: MouseEvent;
76 onmouseleave: MouseEvent;
77 onmousemove: MouseEvent;
78 onmouseout: MouseEvent;
79 onmouseover: MouseEvent;
80 onmouseup: MouseEvent;
81 onmousewheel: WheelEvent;
82 onpaste: ClipboardEvent;
83 onpause: Event;
84 onplay: Event;
85 onplaying: Event;
86 onpointercancel: PointerEvent;
87 onpointerdown: PointerEvent;
88 onpointerenter: PointerEvent;
89 onpointerleave: PointerEvent;
90 onpointermove: PointerEvent;
91 onpointerout: PointerEvent;
92 onpointerover: PointerEvent;
93 onpointerup: PointerEvent;
94 onprogress: ProgressEvent;
95 onratechange: Event;
96 onreset: Event;
97 onscroll: UIEvent;
98 onseeked: Event;
99 onseeking: Event;
100 onselect: UIEvent;
101 onselectstart: Event;
102 onstalled: Event;
103 onsubmit: Event;
104 onsuspend: Event;
105 ontimeupdate: Event;
106 onvolumechange: Event;
107 onwaiting: Event;
108};
109/**
110 * An object which represents a dataset for a virtual DOM element.
111 *
112 * The names of the dataset properties will be automatically prefixed
113 * with `data-` before being added to the node, e.g. `{ thing: '12' }`
114 * will be rendered as `data-thing='12'` in the DOM element.
115 *
116 * Dataset property names should not contain spaces.
117 */
118export declare type ElementDataset = {
119 readonly [name: string]: string;
120};
121/**
122 * The inline style for for a virtual DOM element.
123 *
124 * Style attributes use the JS camel-cased property names instead of
125 * the CSS hyphenated names for performance and security.
126 */
127export declare type ElementInlineStyle = {
128 readonly [T in CSSPropertyNames]?: string;
129};
130/**
131 * The base attributes for a virtual element node.
132 *
133 * These are the attributes which are applied to a real DOM element via
134 * `element.setAttribute()`. The supported attribute names are defined
135 * by the `ElementAttrNames` type.
136 *
137 * Node attributes are specified using the lower-case HTML name instead
138 * of the camel-case JS name due to browser inconsistencies in handling
139 * the JS versions.
140 */
141export declare type ElementBaseAttrs = {
142 readonly [T in ElementAttrNames]?: string;
143};
144/**
145 * The inline event listener attributes for a virtual element node.
146 *
147 * The supported listeners are defined by the `ElementEventMap` type.
148 */
149export declare type ElementEventAttrs = {
150 readonly [T in keyof ElementEventMap]?: (this: HTMLElement, event: ElementEventMap[T]) => any;
151};
152/**
153 * The special-cased attributes for a virtual element node.
154 */
155export declare type ElementSpecialAttrs = {
156 /**
157 * The key id for the virtual element node.
158 *
159 * If a node is given a key id, the generated DOM node will not be
160 * recreated during a rendering update if it only moves among its
161 * siblings in the render tree.
162 *
163 * In general, reordering child nodes will cause the nodes to be
164 * completely re-rendered. Keys allow this to be optimized away.
165 *
166 * If a key is provided, it must be unique among sibling nodes.
167 */
168 readonly key?: string;
169 /**
170 * The JS-safe name for the HTML `class` attribute.
171 */
172 readonly className?: string;
173 /**
174 * The JS-safe name for the HTML `for` attribute.
175 */
176 readonly htmlFor?: string;
177 /**
178 * The dataset for the rendered DOM element.
179 */
180 readonly dataset?: ElementDataset;
181 /**
182 * The inline style for the rendered DOM element.
183 */
184 readonly style?: ElementInlineStyle;
185};
186/**
187 * The full set of attributes supported by a virtual element node.
188 *
189 * This is the combination of the base element attributes, the inline
190 * element event listeners, and the special element attributes.
191 */
192export declare type ElementAttrs = (ElementBaseAttrs & ElementEventAttrs & ElementSpecialAttrs);
193/**
194 * A virtual node which represents plain text content.
195 *
196 * #### Notes
197 * User code will not typically create a `VirtualText` node directly.
198 * Instead, the `h()` function will be used to create an element tree.
199 */
200export declare class VirtualText {
201 /**
202 * The text content for the node.
203 */
204 readonly content: string;
205 /**
206 * The type of the node.
207 *
208 * This value can be used as a type guard for discriminating the
209 * `VirtualNode` union type.
210 */
211 readonly type: 'text';
212 /**
213 * Construct a new virtual text node.
214 *
215 * @param content - The text content for the node.
216 */
217 constructor(content: string);
218}
219/**
220 * A virtual node which represents an HTML element.
221 *
222 * #### Notes
223 * User code will not typically create a `VirtualElement` node directly.
224 * Instead, the `h()` function will be used to create an element tree.
225 */
226export declare class VirtualElement {
227 /**
228 * The tag name for the element.
229 */
230 readonly tag: string;
231 /**
232 * The attributes for the element.
233 */
234 readonly attrs: ElementAttrs;
235 /**
236 * The children for the element.
237 */
238 readonly children: ReadonlyArray<VirtualNode>;
239 /**
240 * The type of the node.
241 *
242 * This value can be used as a type guard for discriminating the
243 * `VirtualNode` union type.
244 */
245 readonly type: 'element';
246 /**
247 * Construct a new virtual element node.
248 *
249 * @param tag - The element tag name.
250 *
251 * @param attrs - The element attributes.
252 *
253 * @param children - The element children.
254 */
255 constructor(tag: string, attrs: ElementAttrs, children: ReadonlyArray<VirtualNode>);
256}
257/**
258 * A type alias for a general virtual node.
259 */
260export declare type VirtualNode = VirtualElement | VirtualText;
261/**
262 * Create a new virtual element node.
263 *
264 * @param tag - The tag name for the element.
265 *
266 * @param attrs - The attributes for the element, if any.
267 *
268 * @param children - The children for the element, if any.
269 *
270 * @returns A new virtual element node for the given parameters.
271 *
272 * #### Notes
273 * The children may be string literals, other virtual nodes, `null`, or
274 * an array of those things. Strings are converted into text nodes, and
275 * arrays are inlined as if the array contents were given as positional
276 * arguments. This makes it simple to build up an array of children by
277 * any desired means. `null` child values are simply ignored.
278 *
279 * A bound function for each HTML tag name is available as a static
280 * function attached to the `h()` function. E.g. `h('div', ...)` is
281 * equivalent to `h.div(...)`.
282 */
283export declare function h(tag: string, ...children: h.Child[]): VirtualElement;
284export declare function h(tag: string, attrs: ElementAttrs, ...children: h.Child[]): VirtualElement;
285/**
286 * The namespace for the `h` function statics.
287 */
288export declare namespace h {
289 /**
290 * A type alias for the supported child argument types.
291 */
292 type Child = (string | VirtualNode | null) | Array<string | VirtualNode | null>;
293 /**
294 * A bound factory function for a specific `h()` tag.
295 */
296 interface IFactory {
297 (...children: Child[]): VirtualElement;
298 (attrs: ElementAttrs, ...children: Child[]): VirtualElement;
299 }
300 const a: IFactory;
301 const abbr: IFactory;
302 const address: IFactory;
303 const area: IFactory;
304 const article: IFactory;
305 const aside: IFactory;
306 const audio: IFactory;
307 const b: IFactory;
308 const bdi: IFactory;
309 const bdo: IFactory;
310 const blockquote: IFactory;
311 const br: IFactory;
312 const button: IFactory;
313 const canvas: IFactory;
314 const caption: IFactory;
315 const cite: IFactory;
316 const code: IFactory;
317 const col: IFactory;
318 const colgroup: IFactory;
319 const data: IFactory;
320 const datalist: IFactory;
321 const dd: IFactory;
322 const del: IFactory;
323 const dfn: IFactory;
324 const div: IFactory;
325 const dl: IFactory;
326 const dt: IFactory;
327 const em: IFactory;
328 const embed: IFactory;
329 const fieldset: IFactory;
330 const figcaption: IFactory;
331 const figure: IFactory;
332 const footer: IFactory;
333 const form: IFactory;
334 const h1: IFactory;
335 const h2: IFactory;
336 const h3: IFactory;
337 const h4: IFactory;
338 const h5: IFactory;
339 const h6: IFactory;
340 const header: IFactory;
341 const hr: IFactory;
342 const i: IFactory;
343 const iframe: IFactory;
344 const img: IFactory;
345 const input: IFactory;
346 const ins: IFactory;
347 const kbd: IFactory;
348 const label: IFactory;
349 const legend: IFactory;
350 const li: IFactory;
351 const main: IFactory;
352 const map: IFactory;
353 const mark: IFactory;
354 const meter: IFactory;
355 const nav: IFactory;
356 const noscript: IFactory;
357 const object: IFactory;
358 const ol: IFactory;
359 const optgroup: IFactory;
360 const option: IFactory;
361 const output: IFactory;
362 const p: IFactory;
363 const param: IFactory;
364 const pre: IFactory;
365 const progress: IFactory;
366 const q: IFactory;
367 const rp: IFactory;
368 const rt: IFactory;
369 const ruby: IFactory;
370 const s: IFactory;
371 const samp: IFactory;
372 const section: IFactory;
373 const select: IFactory;
374 const small: IFactory;
375 const source: IFactory;
376 const span: IFactory;
377 const strong: IFactory;
378 const sub: IFactory;
379 const summary: IFactory;
380 const sup: IFactory;
381 const table: IFactory;
382 const tbody: IFactory;
383 const td: IFactory;
384 const textarea: IFactory;
385 const tfoot: IFactory;
386 const th: IFactory;
387 const thead: IFactory;
388 const time: IFactory;
389 const title: IFactory;
390 const tr: IFactory;
391 const track: IFactory;
392 const u: IFactory;
393 const ul: IFactory;
394 const var_: IFactory;
395 const video: IFactory;
396 const wbr: IFactory;
397}
398/**
399 * The namespace for the virtual DOM rendering functions.
400 */
401export declare namespace VirtualDOM {
402 /**
403 * Create a real DOM element from a virtual element node.
404 *
405 * @param node - The virtual element node to realize.
406 *
407 * @returns A new DOM element for the given virtual element node.
408 *
409 * #### Notes
410 * This creates a brand new *real* DOM element with a structure which
411 * matches the given virtual DOM node.
412 *
413 * If virtual diffing is desired, use the `render` function instead.
414 */
415 function realize(node: VirtualElement): HTMLElement;
416 /**
417 * Render virtual DOM content into a host element.
418 *
419 * @param content - The virtual DOM content to render.
420 *
421 * @param host - The host element for the rendered content.
422 *
423 * #### Notes
424 * This renders the delta from the previous rendering. It assumes that
425 * the content of the host element is not manipulated by external code.
426 *
427 * Providing `null` content will clear the rendering.
428 *
429 * Externally modifying the provided content or the host element will
430 * result in undefined rendering behavior.
431 */
432 function render(content: VirtualNode | ReadonlyArray<VirtualNode> | null, host: HTMLElement): void;
433}