-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathindex.ts
1487 lines (1379 loc) · 41.1 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
import {
ArrayExt
} from '@lumino/algorithm';
/**
* The names of the supported HTML5 DOM element attributes.
*
* This list is not all-encompassing, rather it attempts to define the
* attribute names which are relevant for use in a virtual DOM context.
* If a standardized or widely supported name is missing, please open
* an issue to have it added.
*
* The attribute names were collected from the following sources:
* - https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
* - https://www.w3.org/TR/html5/index.html#attributes-1
* - https://html.spec.whatwg.org/multipage/indices.html#attributes-3
*/
export
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'
);
/**
* The names of the supported HTML5 CSS property names.
*
* If a standardized or widely supported name is missing, please open
* an issue to have it added.
*
* The property names were collected from the following sources:
* - TypeScript's `lib.dom.d.ts` file
*/
export
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'
);
/**
* A mapping of inline event name to event object type.
*
* This mapping is used to create the event listener properties for
* the virtual DOM element attributes object. If a standardized or
* widely supported name is missing, please open an issue to have it
* added.
*
* The event names were collected from the following sources:
* - TypeScript's `lib.dom.d.ts` file
* - https://www.w3.org/TR/html5/index.html#attributes-1
* - https://html.spec.whatwg.org/multipage/webappapis.html#idl-definitions
*/
export
type ElementEventMap = {
onabort: UIEvent;
onauxclick: MouseEvent;
onblur: FocusEvent;
oncanplay: Event;
oncanplaythrough: Event;
onchange: Event;
onclick: MouseEvent;
oncontextmenu: PointerEvent;
oncopy: ClipboardEvent;
oncuechange: Event;
oncut: ClipboardEvent;
ondblclick: MouseEvent;
ondrag: DragEvent;
ondragend: DragEvent;
ondragenter: DragEvent;
ondragexit: DragEvent;
ondragleave: DragEvent;
ondragover: DragEvent;
ondragstart: DragEvent;
ondrop: DragEvent;
ondurationchange: Event;
onemptied: Event;
onended: MediaStreamErrorEvent;
onerror: ErrorEvent;
onfocus: FocusEvent;
oninput: Event;
oninvalid: Event;
onkeydown: KeyboardEvent;
onkeypress: KeyboardEvent;
onkeyup: KeyboardEvent;
onload: Event;
onloadeddata: Event;
onloadedmetadata: Event;
onloadend: Event;
onloadstart: Event;
onmousedown: MouseEvent;
onmouseenter: MouseEvent;
onmouseleave: MouseEvent;
onmousemove: MouseEvent;
onmouseout: MouseEvent;
onmouseover: MouseEvent;
onmouseup: MouseEvent;
onmousewheel: WheelEvent;
onpaste: ClipboardEvent;
onpause: Event;
onplay: Event;
onplaying: Event;
onpointercancel: PointerEvent;
onpointerdown: PointerEvent;
onpointerenter: PointerEvent;
onpointerleave: PointerEvent;
onpointermove: PointerEvent;
onpointerout: PointerEvent;
onpointerover: PointerEvent;
onpointerup: PointerEvent;
onprogress: ProgressEvent;
onratechange: Event;
onreset: Event;
onscroll: UIEvent;
onseeked: Event;
onseeking: Event;
onselect: UIEvent;
onselectstart: Event;
onstalled: Event;
onsubmit: Event;
onsuspend: Event;
ontimeupdate: Event;
onvolumechange: Event;
onwaiting: Event;
};
/**
* An object which represents a dataset for a virtual DOM element.
*
* The names of the dataset properties will be automatically prefixed
* with `data-` before being added to the node, e.g. `{ thing: '12' }`
* will be rendered as `data-thing='12'` in the DOM element.
*
* Dataset property names should not contain spaces.
*/
export
type ElementDataset = {
readonly [name: string]: string;
};
/**
* The inline style for for a virtual DOM element.
*
* Style attributes use the JS camel-cased property names instead of
* the CSS hyphenated names for performance and security.
*/
export
type ElementInlineStyle = {
readonly [T in CSSPropertyNames]?: string;
};
/**
* The base attributes for a virtual element node.
*
* These are the attributes which are applied to a real DOM element via
* `element.setAttribute()`. The supported attribute names are defined
* by the `ElementAttrNames` type.
*
* Node attributes are specified using the lower-case HTML name instead
* of the camel-case JS name due to browser inconsistencies in handling
* the JS versions.
*/
export
type ElementBaseAttrs = {
readonly [T in ElementAttrNames]?: string;
};
/**
* The inline event listener attributes for a virtual element node.
*
* The supported listeners are defined by the `ElementEventMap` type.
*/
export
type ElementEventAttrs = {
readonly [T in keyof ElementEventMap]?: (this: HTMLElement, event: ElementEventMap[T]) => any;
};
/**
* The special-cased attributes for a virtual element node.
*/
export
type ElementSpecialAttrs = {
/**
* The key id for the virtual element node.
*
* If a node is given a key id, the generated DOM node will not be
* recreated during a rendering update if it only moves among its
* siblings in the render tree.
*
* In general, reordering child nodes will cause the nodes to be
* completely re-rendered. Keys allow this to be optimized away.
*
* If a key is provided, it must be unique among sibling nodes.
*/
readonly key?: string;
/**
* The JS-safe name for the HTML `class` attribute.
*/
readonly className?: string;
/**
* The JS-safe name for the HTML `for` attribute.
*/
readonly htmlFor?: string;
/**
* The dataset for the rendered DOM element.
*/
readonly dataset?: ElementDataset;
/**
* The inline style for the rendered DOM element.
*/
readonly style?: ElementInlineStyle;
};
/**
* The full set of attributes supported by a virtual element node.
*
* This is the combination of the base element attributes, the inline
* element event listeners, and the special element attributes.
*/
export
type ElementAttrs = (
ElementBaseAttrs &
ElementEventAttrs &
ElementSpecialAttrs
);
/**
* A virtual node which represents plain text content.
*
* #### Notes
* User code will not typically create a `VirtualText` node directly.
* Instead, the `h()` function will be used to create an element tree.
*/
export
class VirtualText {
/**
* The text content for the node.
*/
readonly content: string;
/**
* The type of the node.
*
* This value can be used as a type guard for discriminating the
* `VirtualNode` union type.
*/
readonly type: 'text' = 'text';
/**
* Construct a new virtual text node.
*
* @param content - The text content for the node.
*/
constructor(content: string) {
this.content = content;
}
}
/**
* A virtual node which represents an HTML element.
*
* #### Notes
* User code will not typically create a `VirtualElement` node directly.
* Instead, the `h()` function will be used to create an element tree.
*/
export
class VirtualElement {
/**
* The tag name for the element.
*/
readonly tag: string;
/**
* The attributes for the element.
*/
readonly attrs: ElementAttrs;
/**
* The children for the element.
*/
readonly children: ReadonlyArray<VirtualNode>;
/**
* The type of the node.
*
* This value can be used as a type guard for discriminating the
* `VirtualNode` union type.
*/
readonly type: 'element' = 'element';
/**
* Construct a new virtual element node.
*
* @param tag - The element tag name.
*
* @param attrs - The element attributes.
*
* @param children - The element children.
*/
constructor(tag: string, attrs: ElementAttrs, children: ReadonlyArray<VirtualNode>) {
this.tag = tag;
this.attrs = attrs;
this.children = children;
}
}
/**
* A "pass thru" virtual node whose children are managed by a render and an
* unrender callback. The intent of this flavor of virtual node is to make
* it easy to blend other kinds of virtualdom (eg React) into Phosphor's
* virtualdom.
*
* #### Notes
* User code will not typically create a `VirtualElementPass` node directly.
* Instead, the `hpass()` function will be used to create an element tree.
*/
export
class VirtualElementPass{
/**
* The type of the node.
*
* This value can be used as a type guard for discriminating the
* `VirtualNode` union type.
*/
readonly type: 'passthru' = 'passthru';
/**
* Construct a new virtual element pass thru node.
*
* @param tag - the tag of the parent element of this node. Once the parent
* element is rendered, it will be passed as an argument to
* renderer.render
*
* @param attrs - attributes that will assigned to the
* parent element
*
* @param renderer - an object with render and unrender
* functions, each of which should take a single argument of type
* HTMLElement and return nothing. If null, the parent element
* will be rendered barren without any children.
*/
constructor(readonly tag: string, readonly attrs: ElementAttrs, readonly renderer: VirtualElementPass.IRenderer | null) {}
render(host: HTMLElement): void {
// skip actual render if renderer is null
if (this.renderer) {
this.renderer.render(host);
}
}
unrender(host: HTMLElement): void {
// skip actual unrender if renderer is null
if (this.renderer) {
this.renderer.unrender(host);
}
}
}
/**
* The namespace for the VirtualElementPass class statics.
*/
export namespace VirtualElementPass {
export type IRenderer = {
render: (host: HTMLElement) => void,
unrender: (host: HTMLElement) => void
};
}
/**
* A type alias for a general virtual node.
*/
export
type VirtualNode = VirtualElement | VirtualElementPass | VirtualText;
/**
* Create a new virtual element node.
*
* @param tag - The tag name for the element.
*
* @param attrs - The attributes for the element, if any.
*
* @param children - The children for the element, if any.
*
* @returns A new virtual element node for the given parameters.
*
* #### Notes
* The children may be string literals, other virtual nodes, `null`, or
* an array of those things. Strings are converted into text nodes, and
* arrays are inlined as if the array contents were given as positional
* arguments. This makes it simple to build up an array of children by
* any desired means. `null` child values are simply ignored.
*
* A bound function for each HTML tag name is available as a static
* function attached to the `h()` function. E.g. `h('div', ...)` is
* equivalent to `h.div(...)`.
*/
export function h(tag: string, ...children: h.Child[]): VirtualElement;
export function h(tag: string, attrs: ElementAttrs, ...children: h.Child[]): VirtualElement;
export function h(tag: string): VirtualElement {
let attrs: ElementAttrs = {};
let children: VirtualNode[] = [];
for (let i = 1, n = arguments.length; i < n; ++i) {
let arg = arguments[i];
if (typeof arg === 'string') {
children.push(new VirtualText(arg));
} else if (arg instanceof VirtualText) {
children.push(arg);
} else if (arg instanceof VirtualElement) {
children.push(arg);
} else if (arg instanceof VirtualElementPass) {
children.push(arg);
} else if (arg instanceof Array) {
extend(children, arg);
} else if (i === 1 && arg && typeof arg === 'object') {
attrs = arg;
}
}
return new VirtualElement(tag, attrs, children);
function extend(array: VirtualNode[], values: h.Child[]): void {
for (let child of values) {
if (typeof child === 'string') {
array.push(new VirtualText(child));
} else if (child instanceof VirtualText) {
array.push(child);
} else if (child instanceof VirtualElement) {
array.push(child);
} else if (child instanceof VirtualElementPass) {
array.push(child);
}
}
}
}
/**
* The namespace for the `h` function statics.
*/
export
namespace h {
/**
* A type alias for the supported child argument types.
*/
export
type Child = (string | VirtualNode | null) | Array<string | VirtualNode | null>;
/**
* A bound factory function for a specific `h()` tag.
*/
export
interface IFactory {
(...children: Child[]): VirtualElement;
(attrs: ElementAttrs, ...children: Child[]): VirtualElement;
}
export const a: IFactory = h.bind(undefined, 'a');
export const abbr: IFactory = h.bind(undefined, 'abbr');
export const address: IFactory = h.bind(undefined, 'address');
export const area: IFactory = h.bind(undefined, 'area');
export const article: IFactory = h.bind(undefined, 'article');
export const aside: IFactory = h.bind(undefined, 'aside');
export const audio: IFactory = h.bind(undefined, 'audio');
export const b: IFactory = h.bind(undefined, 'b');
export const bdi: IFactory = h.bind(undefined, 'bdi');
export const bdo: IFactory = h.bind(undefined, 'bdo');
export const blockquote: IFactory = h.bind(undefined, 'blockquote');
export const br: IFactory = h.bind(undefined, 'br');
export const button: IFactory = h.bind(undefined, 'button');
export const canvas: IFactory = h.bind(undefined, 'canvas');
export const caption: IFactory = h.bind(undefined, 'caption');
export const cite: IFactory = h.bind(undefined, 'cite');
export const code: IFactory = h.bind(undefined, 'code');
export const col: IFactory = h.bind(undefined, 'col');
export const colgroup: IFactory = h.bind(undefined, 'colgroup');
export const data: IFactory = h.bind(undefined, 'data');
export const datalist: IFactory = h.bind(undefined, 'datalist');
export const dd: IFactory = h.bind(undefined, 'dd');
export const del: IFactory = h.bind(undefined, 'del');
export const dfn: IFactory = h.bind(undefined, 'dfn');
export const div: IFactory = h.bind(undefined, 'div');
export const dl: IFactory = h.bind(undefined, 'dl');
export const dt: IFactory = h.bind(undefined, 'dt');
export const em: IFactory = h.bind(undefined, 'em');
export const embed: IFactory = h.bind(undefined, 'embed');
export const fieldset: IFactory = h.bind(undefined, 'fieldset');
export const figcaption: IFactory = h.bind(undefined, 'figcaption');
export const figure: IFactory = h.bind(undefined, 'figure');
export const footer: IFactory = h.bind(undefined, 'footer');
export const form: IFactory = h.bind(undefined, 'form');
export const h1: IFactory = h.bind(undefined, 'h1');
export const h2: IFactory = h.bind(undefined, 'h2');
export const h3: IFactory = h.bind(undefined, 'h3');
export const h4: IFactory = h.bind(undefined, 'h4');
export const h5: IFactory = h.bind(undefined, 'h5');
export const h6: IFactory = h.bind(undefined, 'h6');
export const header: IFactory = h.bind(undefined, 'header');
export const hr: IFactory = h.bind(undefined, 'hr');
export const i: IFactory = h.bind(undefined, 'i');
export const iframe: IFactory = h.bind(undefined, 'iframe');
export const img: IFactory = h.bind(undefined, 'img');
export const input: IFactory = h.bind(undefined, 'input');
export const ins: IFactory = h.bind(undefined, 'ins');
export const kbd: IFactory = h.bind(undefined, 'kbd');
export const label: IFactory = h.bind(undefined, 'label');
export const legend: IFactory = h.bind(undefined, 'legend');
export const li: IFactory = h.bind(undefined, 'li');
export const main: IFactory = h.bind(undefined, 'main');
export const map: IFactory = h.bind(undefined, 'map');
export const mark: IFactory = h.bind(undefined, 'mark');
export const meter: IFactory = h.bind(undefined, 'meter');
export const nav: IFactory = h.bind(undefined, 'nav');
export const noscript: IFactory = h.bind(undefined, 'noscript');
export const object: IFactory = h.bind(undefined, 'object');
export const ol: IFactory = h.bind(undefined, 'ol');
export const optgroup: IFactory = h.bind(undefined, 'optgroup');
export const option: IFactory = h.bind(undefined, 'option');
export const output: IFactory = h.bind(undefined, 'output');
export const p: IFactory = h.bind(undefined, 'p');
export const param: IFactory = h.bind(undefined, 'param');
export const pre: IFactory = h.bind(undefined, 'pre');
export const progress: IFactory = h.bind(undefined, 'progress');
export const q: IFactory = h.bind(undefined, 'q');
export const rp: IFactory = h.bind(undefined, 'rp');
export const rt: IFactory = h.bind(undefined, 'rt');
export const ruby: IFactory = h.bind(undefined, 'ruby');
export const s: IFactory = h.bind(undefined, 's');
export const samp: IFactory = h.bind(undefined, 'samp');
export const section: IFactory = h.bind(undefined, 'section');
export const select: IFactory = h.bind(undefined, 'select');
export const small: IFactory = h.bind(undefined, 'small');
export const source: IFactory = h.bind(undefined, 'source');
export const span: IFactory = h.bind(undefined, 'span');
export const strong: IFactory = h.bind(undefined, 'strong');
export const sub: IFactory = h.bind(undefined, 'sub');
export const summary: IFactory = h.bind(undefined, 'summary');
export const sup: IFactory = h.bind(undefined, 'sup');
export const table: IFactory = h.bind(undefined, 'table');
export const tbody: IFactory = h.bind(undefined, 'tbody');
export const td: IFactory = h.bind(undefined, 'td');
export const textarea: IFactory = h.bind(undefined, 'textarea');
export const tfoot: IFactory = h.bind(undefined, 'tfoot');
export const th: IFactory = h.bind(undefined, 'th');
export const thead: IFactory = h.bind(undefined, 'thead');
export const time: IFactory = h.bind(undefined, 'time');
export const title: IFactory = h.bind(undefined, 'title');
export const tr: IFactory = h.bind(undefined, 'tr');
export const track: IFactory = h.bind(undefined, 'track');
export const u: IFactory = h.bind(undefined, 'u');
export const ul: IFactory = h.bind(undefined, 'ul');
export const var_: IFactory = h.bind(undefined, 'var');
export const video: IFactory = h.bind(undefined, 'video');