xyc
2024-05-17 49b00a322eae2b9b95f04e41c174ef3b4940017c
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
(function () {
  'use strict';
 
  function _typeof(obj) {
    if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
      _typeof = function (obj) {
        return typeof obj;
      };
    } else {
      _typeof = function (obj) {
        return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
      };
    }
 
    return _typeof(obj);
  }
 
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
    try {
      var info = gen[key](arg);
      var value = info.value;
    } catch (error) {
      reject(error);
      return;
    }
 
    if (info.done) {
      resolve(value);
    } else {
      Promise.resolve(value).then(_next, _throw);
    }
  }
 
  function _asyncToGenerator(fn) {
    return function () {
      var self = this,
          args = arguments;
      return new Promise(function (resolve, reject) {
        var gen = fn.apply(self, args);
 
        function _next(value) {
          asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
        }
 
        function _throw(err) {
          asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
        }
 
        _next(undefined);
      });
    };
  }
 
  function _classCallCheck(instance, Constructor) {
    if (!(instance instanceof Constructor)) {
      throw new TypeError("Cannot call a class as a function");
    }
  }
 
  function _extends() {
    _extends = Object.assign || function (target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i];
 
        for (var key in source) {
          if (Object.prototype.hasOwnProperty.call(source, key)) {
            target[key] = source[key];
          }
        }
      }
 
      return target;
    };
 
    return _extends.apply(this, arguments);
  }
 
  function _inherits(subClass, superClass) {
    if (typeof superClass !== "function" && superClass !== null) {
      throw new TypeError("Super expression must either be null or a function");
    }
 
    subClass.prototype = Object.create(superClass && superClass.prototype, {
      constructor: {
        value: subClass,
        writable: true,
        configurable: true
      }
    });
    if (superClass) _setPrototypeOf(subClass, superClass);
  }
 
  function _getPrototypeOf(o) {
    _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
      return o.__proto__ || Object.getPrototypeOf(o);
    };
    return _getPrototypeOf(o);
  }
 
  function _setPrototypeOf(o, p) {
    _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
      o.__proto__ = p;
      return o;
    };
 
    return _setPrototypeOf(o, p);
  }
 
  function isNativeReflectConstruct() {
    if (typeof Reflect === "undefined" || !Reflect.construct) return false;
    if (Reflect.construct.sham) return false;
    if (typeof Proxy === "function") return true;
 
    try {
      Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
      return true;
    } catch (e) {
      return false;
    }
  }
 
  function _construct(Parent, args, Class) {
    if (isNativeReflectConstruct()) {
      _construct = Reflect.construct;
    } else {
      _construct = function _construct(Parent, args, Class) {
        var a = [null];
        a.push.apply(a, args);
        var Constructor = Function.bind.apply(Parent, a);
        var instance = new Constructor();
        if (Class) _setPrototypeOf(instance, Class.prototype);
        return instance;
      };
    }
 
    return _construct.apply(null, arguments);
  }
 
  function _isNativeFunction(fn) {
    return Function.toString.call(fn).indexOf("[native code]") !== -1;
  }
 
  function _wrapNativeSuper(Class) {
    var _cache = typeof Map === "function" ? new Map() : undefined;
 
    _wrapNativeSuper = function _wrapNativeSuper(Class) {
      if (Class === null || !_isNativeFunction(Class)) return Class;
 
      if (typeof Class !== "function") {
        throw new TypeError("Super expression must either be null or a function");
      }
 
      if (typeof _cache !== "undefined") {
        if (_cache.has(Class)) return _cache.get(Class);
 
        _cache.set(Class, Wrapper);
      }
 
      function Wrapper() {
        return _construct(Class, arguments, _getPrototypeOf(this).constructor);
      }
 
      Wrapper.prototype = Object.create(Class.prototype, {
        constructor: {
          value: Wrapper,
          enumerable: false,
          writable: true,
          configurable: true
        }
      });
      return _setPrototypeOf(Wrapper, Class);
    };
 
    return _wrapNativeSuper(Class);
  }
 
  function _assertThisInitialized(self) {
    if (self === void 0) {
      throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
    }
 
    return self;
  }
 
  function _possibleConstructorReturn(self, call) {
    if (call && (typeof call === "object" || typeof call === "function")) {
      return call;
    }
 
    return _assertThisInitialized(self);
  }
 
  function _slicedToArray(arr, i) {
    return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
  }
 
  function _toConsumableArray(arr) {
    return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
  }
 
  function _arrayWithoutHoles(arr) {
    if (Array.isArray(arr)) {
      for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
 
      return arr2;
    }
  }
 
  function _arrayWithHoles(arr) {
    if (Array.isArray(arr)) return arr;
  }
 
  function _iterableToArray(iter) {
    if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  }
 
  function _iterableToArrayLimit(arr, i) {
    var _arr = [];
    var _n = true;
    var _d = false;
    var _e = undefined;
 
    try {
      for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
        _arr.push(_s.value);
 
        if (i && _arr.length === i) break;
      }
    } catch (err) {
      _d = true;
      _e = err;
    } finally {
      try {
        if (!_n && _i["return"] != null) _i["return"]();
      } finally {
        if (_d) throw _e;
      }
    }
 
    return _arr;
  }
 
  function _nonIterableSpread() {
    throw new TypeError("Invalid attempt to spread non-iterable instance");
  }
 
  function _nonIterableRest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance");
  }
 
  function _typeof$1(obj) {
    if (typeof Symbol === "function" && _typeof(Symbol.iterator) === "symbol") {
      _typeof$1 = function _typeof$$1(obj) {
        return _typeof(obj);
      };
    } else {
      _typeof$1 = function _typeof$$1(obj) {
        return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof(obj);
      };
    }
 
    return _typeof$1(obj);
  }
 
  function _classCallCheck$1(instance, Constructor) {
    if (!(instance instanceof Constructor)) {
      throw new TypeError("Cannot call a class as a function");
    }
  }
 
  function _defineProperties$1(target, props) {
    for (var i = 0; i < props.length; i++) {
      var descriptor = props[i];
      descriptor.enumerable = descriptor.enumerable || false;
      descriptor.configurable = true;
      if ("value" in descriptor) descriptor.writable = true;
      Object.defineProperty(target, descriptor.key, descriptor);
    }
  }
 
  function _createClass$1(Constructor, protoProps, staticProps) {
    if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
    if (staticProps) _defineProperties$1(Constructor, staticProps);
    return Constructor;
  }
 
  function _inherits$1(subClass, superClass) {
    if (typeof superClass !== "function" && superClass !== null) {
      throw new TypeError("Super expression must either be null or a function");
    }
 
    subClass.prototype = Object.create(superClass && superClass.prototype, {
      constructor: {
        value: subClass,
        writable: true,
        configurable: true
      }
    });
    if (superClass) _setPrototypeOf$1(subClass, superClass);
  }
 
  function _getPrototypeOf$1(o) {
    _getPrototypeOf$1 = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf$$1(o) {
      return o.__proto__ || Object.getPrototypeOf(o);
    };
    return _getPrototypeOf$1(o);
  }
 
  function _setPrototypeOf$1(o, p) {
    _setPrototypeOf$1 = Object.setPrototypeOf || function _setPrototypeOf$$1(o, p) {
      o.__proto__ = p;
      return o;
    };
 
    return _setPrototypeOf$1(o, p);
  }
 
  function isNativeReflectConstruct$1() {
    if (typeof Reflect === "undefined" || !Reflect.construct) return false;
    if (Reflect.construct.sham) return false;
    if (typeof Proxy === "function") return true;
 
    try {
      Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
      return true;
    } catch (e) {
      return false;
    }
  }
 
  function _construct$1(Parent, args, Class) {
    if (isNativeReflectConstruct$1()) {
      _construct$1 = Reflect.construct;
    } else {
      _construct$1 = function _construct$$1(Parent, args, Class) {
        var a = [null];
        a.push.apply(a, args);
        var Constructor = Function.bind.apply(Parent, a);
        var instance = new Constructor();
        if (Class) _setPrototypeOf$1(instance, Class.prototype);
        return instance;
      };
    }
 
    return _construct$1.apply(null, arguments);
  }
 
  function _isNativeFunction$1(fn) {
    return Function.toString.call(fn).indexOf("[native code]") !== -1;
  }
 
  function _wrapNativeSuper$1(Class) {
    var _cache = typeof Map === "function" ? new Map() : undefined;
 
    _wrapNativeSuper$1 = function _wrapNativeSuper$$1(Class) {
      if (Class === null || !_isNativeFunction$1(Class)) return Class;
 
      if (typeof Class !== "function") {
        throw new TypeError("Super expression must either be null or a function");
      }
 
      if (typeof _cache !== "undefined") {
        if (_cache.has(Class)) return _cache.get(Class);
 
        _cache.set(Class, Wrapper);
      }
 
      function Wrapper() {
        return _construct$1(Class, arguments, _getPrototypeOf$1(this).constructor);
      }
 
      Wrapper.prototype = Object.create(Class.prototype, {
        constructor: {
          value: Wrapper,
          enumerable: false,
          writable: true,
          configurable: true
        }
      });
      return _setPrototypeOf$1(Wrapper, Class);
    };
 
    return _wrapNativeSuper$1(Class);
  }
 
  function _assertThisInitialized$1(self) {
    if (self === void 0) {
      throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
    }
 
    return self;
  }
 
  function _possibleConstructorReturn$1(self, call) {
    if (call && (_typeof(call) === "object" || typeof call === "function")) {
      return call;
    }
 
    return _assertThisInitialized$1(self);
  }
 
  function _superPropBase$1(object, property) {
    while (!Object.prototype.hasOwnProperty.call(object, property)) {
      object = _getPrototypeOf$1(object);
      if (object === null) break;
    }
 
    return object;
  }
 
  function _get$1(target, property, receiver) {
    if (typeof Reflect !== "undefined" && Reflect.get) {
      _get$1 = Reflect.get;
    } else {
      _get$1 = function _get$$1(target, property, receiver) {
        var base = _superPropBase$1(target, property);
 
        if (!base) return;
        var desc = Object.getOwnPropertyDescriptor(base, property);
 
        if (desc.get) {
          return desc.get.call(receiver);
        }
 
        return desc.value;
      };
    }
 
    return _get$1(target, property, receiver || target);
  }
 
  function _slicedToArray$1(arr, i) {
    return _arrayWithHoles$1(arr) || _iterableToArrayLimit$1(arr, i) || _nonIterableRest$1();
  }
 
  function _toConsumableArray$1(arr) {
    return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _nonIterableSpread$1();
  }
 
  function _arrayWithoutHoles$1(arr) {
    if (Array.isArray(arr)) {
      for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
        arr2[i] = arr[i];
      }
 
      return arr2;
    }
  }
 
  function _arrayWithHoles$1(arr) {
    if (Array.isArray(arr)) return arr;
  }
 
  function _iterableToArray$1(iter) {
    if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  }
 
  function _iterableToArrayLimit$1(arr, i) {
    var _arr = [];
    var _n = true;
    var _d = false;
    var _e = undefined;
 
    try {
      for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
        _arr.push(_s.value);
 
        if (i && _arr.length === i) break;
      }
    } catch (err) {
      _d = true;
      _e = err;
    } finally {
      try {
        if (!_n && _i["return"] != null) _i["return"]();
      } finally {
        if (_d) throw _e;
      }
    }
 
    return _arr;
  }
 
  function _nonIterableSpread$1() {
    throw new TypeError("Invalid attempt to spread non-iterable instance");
  }
 
  function _nonIterableRest$1() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance");
  }
  /*
  Possible todos:
  0. Add XSLT to JML-string stylesheet (or even vice versa)
  0. IE problem: Add JsonML code to handle name attribute (during element creation)
  0. Element-specific: IE object-param handling
 
  Todos inspired by JsonML: https://github.com/mckamey/jsonml/blob/master/jsonml-html.js
 
  0. duplicate attributes?
  0. expand ATTR_MAP
  0. equivalent of markup, to allow strings to be embedded within an object (e.g., {$value: '<div>id</div>'}); advantage over innerHTML in that it wouldn't need to work as the entire contents (nor destroy any existing content or handlers)
  0. More validation?
  0. JsonML DOM Level 0 listener
  0. Whitespace trimming?
 
  JsonML element-specific:
  0. table appending
  0. canHaveChildren necessary? (attempts to append to script and img)
 
  Other Todos:
  0. Note to self: Integrate research from other jml notes
  0. Allow Jamilih to be seeded with an existing element, so as to be able to add/modify attributes and children
  0. Allow array as single first argument
  0. Settle on whether need to use null as last argument to return array (or fragment) or other way to allow appending? Options object at end instead to indicate whether returning array, fragment, first element, etc.?
  0. Allow building of generic XML (pass configuration object)
  0. Allow building content internally as a string (though allowing DOM methods, etc.?)
  0. Support JsonML empty string element name to represent fragments?
  0. Redo browser testing of jml (including ensuring IE7 can work even if test framework can't work)
  */
 
 
  var win = typeof window !== 'undefined' && window;
  var doc = typeof document !== 'undefined' && document;
  var XmlSerializer = typeof XMLSerializer !== 'undefined' && XMLSerializer; // STATIC PROPERTIES
 
  var possibleOptions = ['$plugins', '$map' // Add any other options here
  ];
  var NS_HTML = 'http://www.w3.org/1999/xhtml',
      hyphenForCamelCase = /-([a-z])/g;
  var ATTR_MAP = {
    'readonly': 'readOnly'
  }; // We define separately from ATTR_DOM for clarity (and parity with JsonML) but no current need
  // We don't set attribute esp. for boolean atts as we want to allow setting of `undefined`
  //   (e.g., from an empty variable) on templates to have no effect
 
  var BOOL_ATTS = ['checked', 'defaultChecked', 'defaultSelected', 'disabled', 'indeterminate', 'open', // Dialog elements
  'readOnly', 'selected'];
  var ATTR_DOM = BOOL_ATTS.concat([// From JsonML
  'accessKey', // HTMLElement
  'async', 'autocapitalize', // HTMLElement
  'autofocus', 'contentEditable', // HTMLElement through ElementContentEditable
  'defaultValue', 'defer', 'draggable', // HTMLElement
  'formnovalidate', 'hidden', // HTMLElement
  'innerText', // HTMLElement
  'inputMode', // HTMLElement through ElementContentEditable
  'ismap', 'multiple', 'novalidate', 'pattern', 'required', 'spellcheck', // HTMLElement
  'translate', // HTMLElement
  'value', 'willvalidate']); // Todo: Add more to this as useful for templating
  //   to avoid setting through nullish value
 
  var NULLABLES = ['dir', // HTMLElement
  'lang', // HTMLElement
  'max', 'min', 'title' // HTMLElement
  ];
 
  var $ = function $(sel) {
    return doc.querySelector(sel);
  };
  /**
  * Retrieve the (lower-cased) HTML name of a node
  * @static
  * @param {Node} node The HTML node
  * @returns {String} The lower-cased node name
  */
 
 
  function _getHTMLNodeName(node) {
    return node.nodeName && node.nodeName.toLowerCase();
  }
  /**
  * Apply styles if this is a style tag
  * @static
  * @param {Node} node The element to check whether it is a style tag
  */
 
 
  function _applyAnyStylesheet(node) {
    if (!doc.createStyleSheet) {
      return;
    }
 
    if (_getHTMLNodeName(node) === 'style') {
      // IE
      var ss = doc.createStyleSheet(); // Create a stylesheet to actually do something useful
 
      ss.cssText = node.cssText; // We continue to add the style tag, however
    }
  }
  /**
   * Need this function for IE since options weren't otherwise getting added
   * @private
   * @static
   * @param {DOMElement} parent The parent to which to append the element
   * @param {DOMNode} child The element or other node to append to the parent
   */
 
 
  function _appendNode(parent, child) {
    var parentName = _getHTMLNodeName(parent);
 
    var childName = _getHTMLNodeName(child);
 
    if (doc.createStyleSheet) {
      if (parentName === 'script') {
        parent.text = child.nodeValue;
        return;
      }
 
      if (parentName === 'style') {
        parent.cssText = child.nodeValue; // This will not apply it--just make it available within the DOM cotents
 
        return;
      }
    }
 
    if (parentName === 'template') {
      parent.content.appendChild(child);
      return;
    }
 
    try {
      parent.appendChild(child); // IE9 is now ok with this
    } catch (e) {
      if (parentName === 'select' && childName === 'option') {
        try {
          // Since this is now DOM Level 4 standard behavior (and what IE7+ can handle), we try it first
          parent.add(child);
        } catch (err) {
          // DOM Level 2 did require a second argument, so we try it too just in case the user is using an older version of Firefox, etc.
          parent.add(child, null); // IE7 has a problem with this, but IE8+ is ok
        }
 
        return;
      }
 
      throw e;
    }
  }
  /**
   * Attach event in a cross-browser fashion
   * @static
   * @param {DOMElement} el DOM element to which to attach the event
   * @param {String} type The DOM event (without 'on') to attach to the element
   * @param {Function} handler The event handler to attach to the element
   * @param {Boolean} [capturing] Whether or not the event should be
   *                                                              capturing (W3C-browsers only); default is false; NOT IN USE
   */
 
 
  function _addEvent(el, type, handler, capturing) {
    el.addEventListener(type, handler, !!capturing);
  }
  /**
  * Creates a text node of the result of resolving an entity or character reference
  * @param {'entity'|'decimal'|'hexadecimal'} type Type of reference
  * @param {String} prefix Text to prefix immediately after the "&"
  * @param {String} arg The body of the reference
  * @returns {Text} The text node of the resolved reference
  */
 
 
  function _createSafeReference(type, prefix, arg) {
    // For security reasons related to innerHTML, we ensure this string only contains potential entity characters
    if (!arg.match(/^\w+$/)) {
      throw new TypeError('Bad ' + type);
    }
 
    var elContainer = doc.createElement('div'); // Todo: No workaround for XML?
 
    elContainer.innerHTML = '&' + prefix + arg + ';';
    return doc.createTextNode(elContainer.innerHTML);
  }
  /**
  * @param {String} n0 Whole expression match (including "-")
  * @param {String} n1 Lower-case letter match
  * @returns {String} Uppercased letter
  */
 
 
  function _upperCase(n0, n1) {
    return n1.toUpperCase();
  }
  /**
  * @private
  * @static
  */
 
 
  function _getType(item) {
    if (typeof item === 'string') {
      return 'string';
    }
 
    if (_typeof$1(item) === 'object') {
      if (item === null) {
        return 'null';
      }
 
      if (Array.isArray(item)) {
        return 'array';
      }
 
      if ('nodeType' in item) {
        if (item.nodeType === 1) {
          return 'element';
        }
 
        if (item.nodeType === 11) {
          return 'fragment';
        }
      }
 
      return 'object';
    }
 
    return undefined;
  }
  /**
  * @private
  * @static
  */
 
 
  function _fragReducer(frag, node) {
    frag.appendChild(node);
    return frag;
  }
  /**
  * @private
  * @static
  */
 
 
  function _replaceDefiner(xmlnsObj) {
    return function (n0) {
      var retStr = xmlnsObj[''] ? ' xmlns="' + xmlnsObj[''] + '"' : n0 || ''; // Preserve XHTML
 
      for (var ns in xmlnsObj) {
        if (xmlnsObj.hasOwnProperty(ns)) {
          if (ns !== '') {
            retStr += ' xmlns:' + ns + '="' + xmlnsObj[ns] + '"';
          }
        }
      }
 
      return retStr;
    };
  }
 
  function _optsOrUndefinedJML() {
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
 
    return jml.apply(void 0, _toConsumableArray$1(args[0] === undefined ? args.slice(1) : args));
  }
  /**
  * @private
  * @static
  */
 
 
  function _jmlSingleArg(arg) {
    return jml(arg);
  }
  /**
  * @private
  * @static
  */
 
 
  function _copyOrderedAtts(attArr) {
    var obj = {}; // Todo: Fix if allow prefixed attributes
 
    obj[attArr[0]] = attArr[1]; // array of ordered attribute-value arrays
 
    return obj;
  }
  /**
  * @private
  * @static
  */
 
 
  function _childrenToJML(node) {
    return function (childNodeJML, i) {
      var cn = node.childNodes[i];
      var j = Array.isArray(childNodeJML) ? jml.apply(void 0, _toConsumableArray$1(childNodeJML)) : jml(childNodeJML);
      cn.parentNode.replaceChild(j, cn);
    };
  }
  /**
  * @private
  * @static
  */
 
 
  function _appendJML(node) {
    return function (childJML) {
      node.appendChild(jml.apply(void 0, _toConsumableArray$1(childJML)));
    };
  }
  /**
  * @private
  * @static
  */
 
 
  function _appendJMLOrText(node) {
    return function (childJML) {
      if (typeof childJML === 'string') {
        node.appendChild(doc.createTextNode(childJML));
      } else {
        node.appendChild(jml.apply(void 0, _toConsumableArray$1(childJML)));
      }
    };
  }
  /**
  * @private
  * @static
  function _DOMfromJMLOrString (childNodeJML) {
      if (typeof childNodeJML === 'string') {
          return doc.createTextNode(childNodeJML);
      }
      return jml(...childNodeJML);
  }
  */
 
  /**
   * Creates an XHTML or HTML element (XHTML is preferred, but only in browsers that support);
   * Any element after element can be omitted, and any subsequent type or types added afterwards
   * @requires polyfill: Array.isArray
   * @requires polyfill: Array.prototype.reduce For returning a document fragment
   * @requires polyfill: Element.prototype.dataset For dataset functionality (Will not work in IE <= 7)
   * @param {String} el The element to create (by lower-case name)
   * @param {Object} [atts] Attributes to add with the key as the attribute name and value as the
   *                                               attribute value; important for IE where the input element's type cannot
   *                                               be added later after already added to the page
   * @param {DOMElement[]} [children] The optional children of this element (but raw DOM elements
   *                                                                      required to be specified within arrays since
   *                                                                      could not otherwise be distinguished from siblings being added)
   * @param {DOMElement} [parent] The optional parent to which to attach the element (always the last
   *                                                                  unless followed by null, in which case it is the second-to-last)
   * @param {null} [returning] Can use null to indicate an array of elements should be returned
   * @returns {DOMElement} The newly created (and possibly already appended) element or array of elements
   */
 
 
  var jml = function jml() {
    for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
      args[_key2] = arguments[_key2];
    }
 
    var elem = doc.createDocumentFragment();
 
    function _checkAtts(atts) {
      var att;
 
      for (att in atts) {
        if (!atts.hasOwnProperty(att)) {
          continue;
        }
 
        var attVal = atts[att];
        att = att in ATTR_MAP ? ATTR_MAP[att] : att;
 
        if (NULLABLES.includes(att)) {
          if (attVal != null) {
            elem[att] = attVal;
          }
 
          continue;
        } else if (ATTR_DOM.includes(att)) {
          elem[att] = attVal;
          continue;
        }
 
        switch (att) {
          /*
          Todos:
          0. JSON mode to prevent event addition
           0. {$xmlDocument: []} // doc.implementation.createDocument
           0. Accept array for any attribute with first item as prefix and second as value?
          0. {$: ['xhtml', 'div']} for prefixed elements
              case '$': // Element with prefix?
                  nodes[nodes.length] = elem = doc.createElementNS(attVal[0], attVal[1]);
                  break;
          */
          case '#':
            {
              // Document fragment
              nodes[nodes.length] = _optsOrUndefinedJML(opts, attVal);
              break;
            }
 
          case '$shadow':
            {
              var open = attVal.open,
                  closed = attVal.closed;
              var content = attVal.content,
                  template = attVal.template;
              var shadowRoot = elem.attachShadow({
                mode: closed || open === false ? 'closed' : 'open'
              });
 
              if (template) {
                if (Array.isArray(template)) {
                  if (_getType(template[0]) === 'object') {
                    // Has attributes
                    template = jml.apply(void 0, ['template'].concat(_toConsumableArray$1(template), [doc.body]));
                  } else {
                    // Array is for the children
                    template = jml('template', template, doc.body);
                  }
                } else if (typeof template === 'string') {
                  template = $(template);
                }
 
                jml(template.content.cloneNode(true), shadowRoot);
              } else {
                if (!content) {
                  content = open || closed;
                }
 
                if (content && typeof content !== 'boolean') {
                  if (Array.isArray(content)) {
                    jml({
                      '#': content
                    }, shadowRoot);
                  } else {
                    jml(content, shadowRoot);
                  }
                }
              }
 
              break;
            }
 
          case 'is':
            {
              // Not yet supported in browsers
              // Handled during element creation
              break;
            }
 
          case '$custom':
            {
              Object.assign(elem, attVal);
              break;
            }
 
          case '$define':
            {
              var _ret = function () {
                var localName = elem.localName.toLowerCase(); // Note: customized built-ins sadly not working yet
 
                var customizedBuiltIn = !localName.includes('-');
                var def = customizedBuiltIn ? elem.getAttribute('is') : localName;
 
                if (customElements.get(def)) {
                  return "break";
                }
 
                var getConstructor = function getConstructor(cb) {
                  var baseClass = options && options.extends ? doc.createElement(options.extends).constructor : customizedBuiltIn ? doc.createElement(localName).constructor : HTMLElement;
                  return cb ?
                  /*#__PURE__*/
                  function (_baseClass) {
                    _inherits$1(_class, _baseClass);
 
                    function _class() {
                      var _this;
 
                      _classCallCheck$1(this, _class);
 
                      _this = _possibleConstructorReturn$1(this, _getPrototypeOf$1(_class).call(this));
                      cb.call(_assertThisInitialized$1(_assertThisInitialized$1(_this)));
                      return _this;
                    }
 
                    return _class;
                  }(baseClass) :
                  /*#__PURE__*/
                  function (_baseClass2) {
                    _inherits$1(_class2, _baseClass2);
 
                    function _class2() {
                      _classCallCheck$1(this, _class2);
 
                      return _possibleConstructorReturn$1(this, _getPrototypeOf$1(_class2).apply(this, arguments));
                    }
 
                    return _class2;
                  }(baseClass);
                };
 
                var constructor = void 0,
                    options = void 0,
                    prototype = void 0;
 
                if (Array.isArray(attVal)) {
                  if (attVal.length <= 2) {
                    var _attVal = _slicedToArray$1(attVal, 2);
 
                    constructor = _attVal[0];
                    options = _attVal[1];
 
                    if (typeof options === 'string') {
                      options = {
                        extends: options
                      };
                    } else if (!options.hasOwnProperty('extends')) {
                      prototype = options;
                    }
 
                    if (_typeof$1(constructor) === 'object') {
                      prototype = constructor;
                      constructor = getConstructor();
                    }
                  } else {
                    var _attVal2 = _slicedToArray$1(attVal, 3);
 
                    constructor = _attVal2[0];
                    prototype = _attVal2[1];
                    options = _attVal2[2];
 
                    if (typeof options === 'string') {
                      options = {
                        extends: options
                      };
                    }
                  }
                } else if (typeof attVal === 'function') {
                  constructor = attVal;
                } else {
                  prototype = attVal;
                  constructor = getConstructor();
                }
 
                if (!constructor.toString().startsWith('class')) {
                  constructor = getConstructor(constructor);
                }
 
                if (!options && customizedBuiltIn) {
                  options = {
                    extends: localName
                  };
                }
 
                if (prototype) {
                  Object.assign(constructor.prototype, prototype);
                }
 
                customElements.define(def, constructor, customizedBuiltIn ? options : undefined);
                return "break";
              }();
 
              if (_ret === "break") break;
            }
 
          case '$symbol':
            {
              var _attVal3 = _slicedToArray$1(attVal, 2),
                  symbol = _attVal3[0],
                  func = _attVal3[1];
 
              if (typeof func === 'function') {
                var funcBound = func.bind(elem);
 
                if (typeof symbol === 'string') {
                  elem[Symbol.for(symbol)] = funcBound;
                } else {
                  elem[symbol] = funcBound;
                }
              } else {
                var obj = func;
                obj.elem = elem;
 
                if (typeof symbol === 'string') {
                  elem[Symbol.for(symbol)] = obj;
                } else {
                  elem[symbol] = obj;
                }
              }
 
              break;
            }
 
          case '$data':
            {
              setMap(attVal);
              break;
            }
 
          case '$attribute':
            {
              // Attribute node
              var node = attVal.length === 3 ? doc.createAttributeNS(attVal[0], attVal[1]) : doc.createAttribute(attVal[0]);
              node.value = attVal[attVal.length - 1];
              nodes[nodes.length] = node;
              break;
            }
 
          case '$text':
            {
              // Todo: Also allow as jml(['a text node']) (or should that become a fragment)?
              var _node = doc.createTextNode(attVal);
 
              nodes[nodes.length] = _node;
              break;
            }
 
          case '$document':
            {
              // Todo: Conditionally create XML document
              var _node2 = doc.implementation.createHTMLDocument();
 
              if (attVal.childNodes) {
                attVal.childNodes.forEach(_childrenToJML(_node2)); // Remove any extra nodes created by createHTMLDocument().
 
                var j = attVal.childNodes.length;
 
                while (_node2.childNodes[j]) {
                  var cn = _node2.childNodes[j];
                  cn.parentNode.removeChild(cn);
                  j++;
                }
              } else {
                if (attVal.$DOCTYPE) {
                  var dt = {
                    $DOCTYPE: attVal.$DOCTYPE
                  };
                  var doctype = jml(dt);
 
                  _node2.firstChild.replaceWith(doctype);
                }
 
                var html = _node2.childNodes[1];
                var head = html.childNodes[0];
                var _body = html.childNodes[1];
 
                if (attVal.title || attVal.head) {
                  var meta = doc.createElement('meta');
                  meta.setAttribute('charset', 'utf-8');
                  head.appendChild(meta);
                }
 
                if (attVal.title) {
                  _node2.title = attVal.title; // Appends after meta
                }
 
                if (attVal.head) {
                  attVal.head.forEach(_appendJML(head));
                }
 
                if (attVal.body) {
                  attVal.body.forEach(_appendJMLOrText(_body));
                }
              }
 
              nodes[nodes.length] = _node2;
              break;
            }
 
          case '$DOCTYPE':
            {
              /*
              // Todo:
              if (attVal.internalSubset) {
                  node = {};
              }
              else
              */
              var _node3 = void 0;
 
              if (attVal.entities || attVal.notations) {
                _node3 = {
                  name: attVal.name,
                  nodeName: attVal.name,
                  nodeValue: null,
                  nodeType: 10,
                  entities: attVal.entities.map(_jmlSingleArg),
                  notations: attVal.notations.map(_jmlSingleArg),
                  publicId: attVal.publicId,
                  systemId: attVal.systemId // internalSubset: // Todo
 
                };
              } else {
                _node3 = doc.implementation.createDocumentType(attVal.name, attVal.publicId || '', attVal.systemId || '');
              }
 
              nodes[nodes.length] = _node3;
              break;
            }
 
          case '$ENTITY':
            {
              /*
              // Todo: Should we auto-copy another node's properties/methods (like DocumentType) excluding or changing its non-entity node values?
              const node = {
                  nodeName: attVal.name,
                  nodeValue: null,
                  publicId: attVal.publicId,
                  systemId: attVal.systemId,
                  notationName: attVal.notationName,
                  nodeType: 6,
                  childNodes: attVal.childNodes.map(_DOMfromJMLOrString)
              };
              */
              break;
            }
 
          case '$NOTATION':
            {
              // Todo: We could add further properties/methods, but unlikely to be used as is.
              var _node4 = {
                nodeName: attVal[0],
                publicID: attVal[1],
                systemID: attVal[2],
                nodeValue: null,
                nodeType: 12
              };
              nodes[nodes.length] = _node4;
              break;
            }
 
          case '$on':
            {
              // Events
              for (var p2 in attVal) {
                if (attVal.hasOwnProperty(p2)) {
                  var val = attVal[p2];
 
                  if (typeof val === 'function') {
                    val = [val, false];
                  }
 
                  if (typeof val[0] === 'function') {
                    _addEvent(elem, p2, val[0], val[1]); // element, event name, handler, capturing
 
                  }
                }
              }
 
              break;
            }
 
          case 'className':
          case 'class':
            if (attVal != null) {
              elem.className = attVal;
            }
 
            break;
 
          case 'dataset':
            {
              var _ret2 = function () {
                // Map can be keyed with hyphenated or camel-cased properties
                var recurse = function recurse(attVal, startProp) {
                  var prop = '';
                  var pastInitialProp = startProp !== '';
                  Object.keys(attVal).forEach(function (key) {
                    var value = attVal[key];
 
                    if (pastInitialProp) {
                      prop = startProp + key.replace(hyphenForCamelCase, _upperCase).replace(/^([a-z])/, _upperCase);
                    } else {
                      prop = startProp + key.replace(hyphenForCamelCase, _upperCase);
                    }
 
                    if (value === null || _typeof$1(value) !== 'object') {
                      if (value != null) {
                        elem.dataset[prop] = value;
                      }
 
                      prop = startProp;
                      return;
                    }
 
                    recurse(value, prop);
                  });
                };
 
                recurse(attVal, '');
                return "break"; // Todo: Disable this by default unless configuration explicitly allows (for security)
              }();
 
              break;
            }
          // #if IS_REMOVE
          // Don't remove this `if` block (for sake of no-innerHTML build)
 
          case 'innerHTML':
            if (attVal != null) {
              elem.innerHTML = attVal;
            }
 
            break;
          // #endif
 
          case 'htmlFor':
          case 'for':
            if (elStr === 'label') {
              if (attVal != null) {
                elem.htmlFor = attVal;
              }
 
              break;
            }
 
            elem.setAttribute(att, attVal);
            break;
 
          case 'xmlns':
            // Already handled
            break;
 
          default:
            if (att.match(/^on/)) {
              elem[att] = attVal; // _addEvent(elem, att.slice(2), attVal, false); // This worked, but perhaps the user wishes only one event
 
              break;
            }
 
            if (att === 'style') {
              if (attVal == null) {
                break;
              }
 
              if (_typeof$1(attVal) === 'object') {
                for (var _p in attVal) {
                  if (attVal.hasOwnProperty(_p) && attVal[_p] != null) {
                    // Todo: Handle aggregate properties like "border"
                    if (_p === 'float') {
                      elem.style.cssFloat = attVal[_p];
                      elem.style.styleFloat = attVal[_p]; // Harmless though we could make conditional on older IE instead
                    } else {
                      elem.style[_p.replace(hyphenForCamelCase, _upperCase)] = attVal[_p];
                    }
                  }
                }
 
                break;
              } // setAttribute unfortunately erases any existing styles
 
 
              elem.setAttribute(att, attVal);
              /*
              // The following reorders which is troublesome for serialization, e.g., as used in our testing
              if (elem.style.cssText !== undefined) {
                  elem.style.cssText += attVal;
              } else { // Opera
                  elem.style += attVal;
              }
              */
 
              break;
            }
 
            var matchingPlugin = opts && opts.$plugins && opts.$plugins.find(function (p) {
              return p.name === att;
            });
 
            if (matchingPlugin) {
              matchingPlugin.set({
                element: elem,
                attribute: {
                  name: att,
                  value: attVal
                }
              });
              break;
            }
 
            elem.setAttribute(att, attVal);
            break;
        }
      }
    }
 
    var nodes = [];
    var elStr;
    var opts;
    var isRoot = false;
 
    if (_getType(args[0]) === 'object' && Object.keys(args[0]).some(function (key) {
      return possibleOptions.includes(key);
    })) {
      opts = args[0];
 
      if (opts.state !== 'child') {
        isRoot = true;
        opts.state = 'child';
      }
 
      if (opts.$map && !opts.$map.root && opts.$map.root !== false) {
        opts.$map = {
          root: opts.$map
        };
      }
 
      if ('$plugins' in opts) {
        if (!Array.isArray(opts.$plugins)) {
          throw new Error('$plugins must be an array');
        }
 
        opts.$plugins.forEach(function (pluginObj) {
          if (!pluginObj) {
            throw new TypeError('Plugin must be an object');
          }
 
          if (!pluginObj.name || !pluginObj.name.startsWith('$_')) {
            throw new TypeError('Plugin object name must be present and begin with `$_`');
          }
 
          if (typeof pluginObj.set !== 'function') {
            throw new TypeError('Plugin object must have a `set` method');
          }
        });
      }
 
      args = args.slice(1);
    }
 
    var argc = args.length;
    var defaultMap = opts && opts.$map && opts.$map.root;
 
    var setMap = function setMap(dataVal) {
      var map, obj; // Boolean indicating use of default map and object
 
      if (dataVal === true) {
        var _defaultMap = _slicedToArray$1(defaultMap, 2);
 
        map = _defaultMap[0];
        obj = _defaultMap[1];
      } else if (Array.isArray(dataVal)) {
        // Array of strings mapping to default
        if (typeof dataVal[0] === 'string') {
          dataVal.forEach(function (dVal) {
            setMap(opts.$map[dVal]);
          }); // Array of Map and non-map data object
        } else {
          map = dataVal[0] || defaultMap[0];
          obj = dataVal[1] || defaultMap[1];
        } // Map
 
      } else if (/^\[object (?:Weak)?Map\]$/.test([].toString.call(dataVal))) {
        map = dataVal;
        obj = defaultMap[1]; // Non-map data object
      } else {
        map = defaultMap[0];
        obj = dataVal;
      }
 
      map.set(elem, obj);
    };
 
    for (var i = 0; i < argc; i++) {
      var arg = args[i];
 
      switch (_getType(arg)) {
        case 'null':
          // null always indicates a place-holder (only needed for last argument if want array returned)
          if (i === argc - 1) {
            _applyAnyStylesheet(nodes[0]); // We have to execute any stylesheets even if not appending or otherwise IE will never apply them
            // Todo: Fix to allow application of stylesheets of style tags within fragments?
 
 
            return nodes.length <= 1 ? nodes[0] : nodes.reduce(_fragReducer, doc.createDocumentFragment()); // nodes;
          }
 
          break;
 
        case 'string':
          // Strings indicate elements
          switch (arg) {
            case '!':
              nodes[nodes.length] = doc.createComment(args[++i]);
              break;
 
            case '?':
              arg = args[++i];
              var procValue = args[++i];
              var val = procValue;
 
              if (_typeof$1(val) === 'object') {
                procValue = [];
 
                for (var p in val) {
                  if (val.hasOwnProperty(p)) {
                    procValue.push(p + '=' + '"' + // https://www.w3.org/TR/xml-stylesheet/#NT-PseudoAttValue
                    val[p].replace(/"/g, '&quot;') + '"');
                  }
                }
 
                procValue = procValue.join(' ');
              } // Firefox allows instructions with ">" in this method, but not if placed directly!
 
 
              try {
                nodes[nodes.length] = doc.createProcessingInstruction(arg, procValue);
              } catch (e) {
                // Getting NotSupportedError in IE, so we try to imitate a processing instruction with a comment
                // innerHTML didn't work
                // var elContainer = doc.createElement('div');
                // elContainer.innerHTML = '<?' + doc.createTextNode(arg + ' ' + procValue).nodeValue + '?>';
                // nodes[nodes.length] = elContainer.innerHTML;
                // Todo: any other way to resolve? Just use XML?
                nodes[nodes.length] = doc.createComment('?' + arg + ' ' + procValue + '?');
              }
 
              break;
            // Browsers don't support doc.createEntityReference, so we just use this as a convenience
 
            case '&':
              nodes[nodes.length] = _createSafeReference('entity', '', args[++i]);
              break;
 
            case '#':
              // // Decimal character reference - ['#', '01234'] // &#01234; // probably easier to use JavaScript Unicode escapes
              nodes[nodes.length] = _createSafeReference('decimal', arg, String(args[++i]));
              break;
 
            case '#x':
              // Hex character reference - ['#x', '123a'] // &#x123a; // probably easier to use JavaScript Unicode escapes
              nodes[nodes.length] = _createSafeReference('hexadecimal', arg, args[++i]);
              break;
 
            case '![':
              // '![', ['escaped <&> text'] // <![CDATA[escaped <&> text]]>
              // CDATA valid in XML only, so we'll just treat as text for mutual compatibility
              // Todo: config (or detection via some kind of doc.documentType property?) of whether in XML
              try {
                nodes[nodes.length] = doc.createCDATASection(args[++i]);
              } catch (e2) {
                nodes[nodes.length] = doc.createTextNode(args[i]); // i already incremented
              }
 
              break;
 
            case '':
              nodes[nodes.length] = doc.createDocumentFragment();
              break;
 
            default:
              {
                // An element
                elStr = arg;
                var _atts = args[i + 1]; // Todo: Fix this to depend on XML/config, not availability of methods
 
                if (_getType(_atts) === 'object' && _atts.is) {
                  var is = _atts.is;
 
                  if (doc.createElementNS) {
                    elem = doc.createElementNS(NS_HTML, elStr, {
                      is: is
                    });
                  } else {
                    elem = doc.createElement(elStr, {
                      is: is
                    });
                  }
                } else {
                  if (doc.createElementNS) {
                    elem = doc.createElementNS(NS_HTML, elStr);
                  } else {
                    elem = doc.createElement(elStr);
                  }
                }
 
                nodes[nodes.length] = elem; // Add to parent
 
                break;
              }
          }
 
          break;
 
        case 'object':
          // Non-DOM-element objects indicate attribute-value pairs
          var atts = arg;
 
          if (atts.xmlns !== undefined) {
            // We handle this here, as otherwise may lose events, etc.
            // As namespace of element already set as XHTML, we need to change the namespace
            // elem.setAttribute('xmlns', atts.xmlns); // Doesn't work
            // Can't set namespaceURI dynamically, renameNode() is not supported, and setAttribute() doesn't work to change the namespace, so we resort to this hack
            var replacer = void 0;
 
            if (_typeof$1(atts.xmlns) === 'object') {
              replacer = _replaceDefiner(atts.xmlns);
            } else {
              replacer = ' xmlns="' + atts.xmlns + '"';
            } // try {
            // Also fix DOMParser to work with text/html
 
 
            elem = nodes[nodes.length - 1] = new DOMParser().parseFromString(new XmlSerializer().serializeToString(elem) // Mozilla adds XHTML namespace
            .replace(' xmlns="' + NS_HTML + '"', replacer), 'application/xml').documentElement; // }catch(e) {alert(elem.outerHTML);throw e;}
          }
 
          var orderedArr = atts.$a ? atts.$a.map(_copyOrderedAtts) : [atts];
          orderedArr.forEach(_checkAtts);
          break;
 
        case 'fragment':
        case 'element':
          /*
          1) Last element always the parent (put null if don't want parent and want to return array) unless only atts and children (no other elements)
          2) Individual elements (DOM elements or sequences of string[/object/array]) get added to parent first-in, first-added
          */
          if (i === 0) {
            // Allow wrapping of element
            elem = arg;
          }
 
          if (i === argc - 1 || i === argc - 2 && args[i + 1] === null) {
            // parent
            var elsl = nodes.length;
 
            for (var k = 0; k < elsl; k++) {
              _appendNode(arg, nodes[k]);
            } // Todo: Apply stylesheets if any style tags were added elsewhere besides the first element?
 
 
            _applyAnyStylesheet(nodes[0]); // We have to execute any stylesheets even if not appending or otherwise IE will never apply them
 
          } else {
            nodes[nodes.length] = arg;
          }
 
          break;
 
        case 'array':
          // Arrays or arrays of arrays indicate child nodes
          var child = arg;
          var cl = child.length;
 
          for (var j = 0; j < cl; j++) {
            // Go through children array container to handle elements
            var childContent = child[j];
 
            var childContentType = _typeof$1(childContent);
 
            if (childContent === undefined) {
              throw String('Parent array:' + JSON.stringify(args) + '; child: ' + child + '; index:' + j);
            }
 
            switch (childContentType) {
              // Todo: determine whether null or function should have special handling or be converted to text
              case 'string':
              case 'number':
              case 'boolean':
                _appendNode(elem, doc.createTextNode(childContent));
 
                break;
 
              default:
                if (Array.isArray(childContent)) {
                  // Arrays representing child elements
                  _appendNode(elem, _optsOrUndefinedJML.apply(void 0, [opts].concat(_toConsumableArray$1(childContent))));
                } else if (childContent['#']) {
                  // Fragment
                  _appendNode(elem, _optsOrUndefinedJML(opts, childContent['#']));
                } else {
                  // Single DOM element children
                  _appendNode(elem, childContent);
                }
 
                break;
            }
          }
 
          break;
      }
    }
 
    var ret = nodes[0] || elem;
 
    if (opts && isRoot && opts.$map && opts.$map.root) {
      setMap(true);
    }
 
    return ret;
  };
  /**
  * Converts a DOM object or a string of HTML into a Jamilih object (or string)
  * @param {string|HTMLElement} [dom=document.documentElement] Defaults to converting the current document.
  * @param {object} [config={stringOutput:false}] Configuration object
  * @param {boolean} [config.stringOutput=false] Whether to output the Jamilih object as a string.
  * @returns {array|string} Array containing the elements which represent a Jamilih object, or,
                              if `stringOutput` is true, it will be the stringified version of
                              such an object
  */
 
 
  jml.toJML = function (dom, config) {
    config = config || {
      stringOutput: false
    };
 
    if (typeof dom === 'string') {
      dom = new DOMParser().parseFromString(dom, 'text/html'); // todo: Give option for XML once implemented and change JSDoc to allow for Element
    }
 
    var ret = [];
    var parent = ret;
    var parentIdx = 0;
 
    function invalidStateError() {
      // These are probably only necessary if working with text/html
      function DOMException() {
        return this;
      }
 
      {
        // INVALID_STATE_ERR per section 9.3 XHTML 5: http://www.w3.org/TR/html5/the-xhtml-syntax.html
        // Since we can't instantiate without this (at least in Mozilla), this mimicks at least (good idea?)
        var e = new DOMException();
        e.code = 11;
        throw e;
      }
    }
 
    function addExternalID(obj, node) {
      if (node.systemId.includes('"') && node.systemId.includes("'")) {
        invalidStateError();
      }
 
      var publicId = node.publicId;
      var systemId = node.systemId;
 
      if (systemId) {
        obj.systemId = systemId;
      }
 
      if (publicId) {
        obj.publicId = publicId;
      }
    }
 
    function set(val) {
      parent[parentIdx] = val;
      parentIdx++;
    }
 
    function setChildren() {
      set([]);
      parent = parent[parentIdx - 1];
      parentIdx = 0;
    }
 
    function setObj(prop1, prop2) {
      parent = parent[parentIdx - 1][prop1];
      parentIdx = 0;
 
      if (prop2) {
        parent = parent[prop2];
      }
    }
 
    function parseDOM(node, namespaces) {
      // namespaces = clone(namespaces) || {}; // Ensure we're working with a copy, so different levels in the hierarchy can treat it differently
 
      /*
      if ((node.prefix && node.prefix.includes(':')) || (node.localName && node.localName.includes(':'))) {
          invalidStateError();
      }
      */
      var type = 'nodeType' in node ? node.nodeType : null;
      namespaces = Object.assign({}, namespaces);
      var xmlChars = /([\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD]|[\uD800-\uDBFF][\uDC00-\uDFFF])*$/; // eslint-disable-line no-control-regex
 
      if ([2, 3, 4, 7, 8].includes(type) && !xmlChars.test(node.nodeValue)) {
        invalidStateError();
      }
 
      var children, start, tmpParent, tmpParentIdx;
 
      function setTemp() {
        tmpParent = parent;
        tmpParentIdx = parentIdx;
      }
 
      function resetTemp() {
        parent = tmpParent;
        parentIdx = tmpParentIdx;
        parentIdx++; // Increment index in parent container of this element
      }
 
      switch (type) {
        case 1:
          // ELEMENT
          setTemp();
          var nodeName = node.nodeName.toLowerCase(); // Todo: for XML, should not lower-case
 
          setChildren(); // Build child array since elements are, except at the top level, encapsulated in arrays
 
          set(nodeName);
          start = {};
          var hasNamespaceDeclaration = false;
 
          if (namespaces[node.prefix || ''] !== node.namespaceURI) {
            namespaces[node.prefix || ''] = node.namespaceURI;
 
            if (node.prefix) {
              start['xmlns:' + node.prefix] = node.namespaceURI;
            } else if (node.namespaceURI) {
              start.xmlns = node.namespaceURI;
            }
 
            hasNamespaceDeclaration = true;
          }
 
          if (node.attributes.length) {
            set(Array.from(node.attributes).reduce(function (obj, att) {
              obj[att.name] = att.value; // Attr.nodeName and Attr.nodeValue are deprecated as of DOM4 as Attr no longer inherits from Node, so we can safely use name and value
 
              return obj;
            }, start));
          } else if (hasNamespaceDeclaration) {
            set(start);
          }
 
          children = node.childNodes;
 
          if (children.length) {
            setChildren(); // Element children array container
 
            Array.from(children).forEach(function (childNode) {
              parseDOM(childNode, namespaces);
            });
          }
 
          resetTemp();
          break;
 
        case undefined: // Treat as attribute node until this is fixed: https://github.com/tmpvar/jsdom/issues/1641 / https://github.com/tmpvar/jsdom/pull/1822
 
        case 2:
          // ATTRIBUTE (should only get here if passing in an attribute node)
          set({
            $attribute: [node.namespaceURI, node.name, node.value]
          });
          break;
 
        case 3:
          // TEXT
          if (config.stripWhitespace && /^\s+$/.test(node.nodeValue)) {
            return;
          }
 
          set(node.nodeValue);
          break;
 
        case 4:
          // CDATA
          if (node.nodeValue.includes(']]' + '>')) {
            invalidStateError();
          }
 
          set(['![', node.nodeValue]);
          break;
 
        case 5:
          // ENTITY REFERENCE (probably not used in browsers since already resolved)
          set(['&', node.nodeName]);
          break;
 
        case 6:
          // ENTITY (would need to pass in directly)
          setTemp();
          start = {};
 
          if (node.xmlEncoding || node.xmlVersion) {
            // an external entity file?
            start.$ENTITY = {
              name: node.nodeName,
              version: node.xmlVersion,
              encoding: node.xmlEncoding
            };
          } else {
            start.$ENTITY = {
              name: node.nodeName
            };
 
            if (node.publicId || node.systemId) {
              // External Entity?
              addExternalID(start.$ENTITY, node);
 
              if (node.notationName) {
                start.$ENTITY.NDATA = node.notationName;
              }
            }
          }
 
          set(start);
          children = node.childNodes;
 
          if (children.length) {
            start.$ENTITY.childNodes = []; // Set position to $ENTITY's childNodes array children
 
            setObj('$ENTITY', 'childNodes');
            Array.from(children).forEach(function (childNode) {
              parseDOM(childNode, namespaces);
            });
          }
 
          resetTemp();
          break;
 
        case 7:
          // PROCESSING INSTRUCTION
          if (/^xml$/i.test(node.target)) {
            invalidStateError();
          }
 
          if (node.target.includes('?>')) {
            invalidStateError();
          }
 
          if (node.target.includes(':')) {
            invalidStateError();
          }
 
          if (node.data.includes('?>')) {
            invalidStateError();
          }
 
          set(['?', node.target, node.data]); // Todo: Could give option to attempt to convert value back into object if has pseudo-attributes
 
          break;
 
        case 8:
          // COMMENT
          if (node.nodeValue.includes('--') || node.nodeValue.length && node.nodeValue.lastIndexOf('-') === node.nodeValue.length - 1) {
            invalidStateError();
          }
 
          set(['!', node.nodeValue]);
          break;
 
        case 9:
          // DOCUMENT
          setTemp();
          var docObj = {
            $document: {
              childNodes: []
            }
          };
 
          if (config.xmlDeclaration) {
            docObj.$document.xmlDeclaration = {
              version: doc.xmlVersion,
              encoding: doc.xmlEncoding,
              standAlone: doc.xmlStandalone
            };
          }
 
          set(docObj); // doc.implementation.createHTMLDocument
          // Set position to fragment's array children
 
          setObj('$document', 'childNodes');
          children = node.childNodes;
 
          if (!children.length) {
            invalidStateError();
          } // set({$xmlDocument: []}); // doc.implementation.createDocument // Todo: use this conditionally
 
 
          Array.from(children).forEach(function (childNode) {
            // Can't just do documentElement as there may be doctype, comments, etc.
            // No need for setChildren, as we have already built the container array
            parseDOM(childNode, namespaces);
          });
          resetTemp();
          break;
 
        case 10:
          // DOCUMENT TYPE
          setTemp(); // Can create directly by doc.implementation.createDocumentType
 
          start = {
            $DOCTYPE: {
              name: node.name
            }
          };
 
          if (node.internalSubset) {
            start.internalSubset = node.internalSubset;
          }
 
          var pubIdChar = /^(\u0020|\u000D|\u000A|[a-zA-Z0-9]|[-'()+,./:=?;!*#@$_%])*$/; // eslint-disable-line no-control-regex
 
          if (!pubIdChar.test(node.publicId)) {
            invalidStateError();
          }
 
          addExternalID(start.$DOCTYPE, node); // Fit in internal subset along with entities?: probably don't need as these would only differ if from DTD, and we're not rebuilding the DTD
 
          set(start); // Auto-generate the internalSubset instead? Avoid entities/notations in favor of array to preserve order?
 
          var entities = node.entities; // Currently deprecated
 
          if (entities && entities.length) {
            start.$DOCTYPE.entities = [];
            setObj('$DOCTYPE', 'entities');
            Array.from(entities).forEach(function (entity) {
              parseDOM(entity, namespaces);
            }); // Reset for notations
 
            parent = tmpParent;
            parentIdx = tmpParentIdx + 1;
          }
 
          var notations = node.notations; // Currently deprecated
 
          if (notations && notations.length) {
            start.$DOCTYPE.notations = [];
            setObj('$DOCTYPE', 'notations');
            Array.from(notations).forEach(function (notation) {
              parseDOM(notation, namespaces);
            });
          }
 
          resetTemp();
          break;
 
        case 11:
          // DOCUMENT FRAGMENT
          setTemp();
          set({
            '#': []
          }); // Set position to fragment's array children
 
          setObj('#');
          children = node.childNodes;
          Array.from(children).forEach(function (childNode) {
            // No need for setChildren, as we have already built the container array
            parseDOM(childNode, namespaces);
          });
          resetTemp();
          break;
 
        case 12:
          // NOTATION
          start = {
            $NOTATION: {
              name: node.nodeName
            }
          };
          addExternalID(start.$NOTATION, node);
          set(start);
          break;
 
        default:
          throw new TypeError('Not an XML type');
      }
    }
 
    parseDOM(dom, {});
 
    if (config.stringOutput) {
      return JSON.stringify(ret[0]);
    }
 
    return ret[0];
  };
 
  jml.toJMLString = function (dom, config) {
    return jml.toJML(dom, Object.assign(config || {}, {
      stringOutput: true
    }));
  };
 
  jml.toDOM = function () {
    // Alias for jml()
    return jml.apply(void 0, arguments);
  };
 
  jml.toHTML = function () {
    // Todo: Replace this with version of jml() that directly builds a string
    var ret = jml.apply(void 0, arguments); // Todo: deal with serialization of properties like 'selected', 'checked', 'value', 'defaultValue', 'for', 'dataset', 'on*', 'style'! (i.e., need to build a string ourselves)
 
    return ret.outerHTML;
  };
 
  jml.toDOMString = function () {
    // Alias for jml.toHTML for parity with jml.toJMLString
    return jml.toHTML.apply(jml, arguments);
  };
 
  jml.toXML = function () {
    var ret = jml.apply(void 0, arguments);
    return new XmlSerializer().serializeToString(ret);
  };
 
  jml.toXMLDOMString = function () {
    // Alias for jml.toXML for parity with jml.toJMLString
    return jml.toXML.apply(jml, arguments);
  };
 
  var JamilihMap =
  /*#__PURE__*/
  function (_Map) {
    _inherits$1(JamilihMap, _Map);
 
    function JamilihMap() {
      _classCallCheck$1(this, JamilihMap);
 
      return _possibleConstructorReturn$1(this, _getPrototypeOf$1(JamilihMap).apply(this, arguments));
    }
 
    _createClass$1(JamilihMap, [{
      key: "get",
      value: function get$$1(elem) {
        elem = typeof elem === 'string' ? $(elem) : elem;
        return _get$1(_getPrototypeOf$1(JamilihMap.prototype), "get", this).call(this, elem);
      }
    }, {
      key: "set",
      value: function set(elem, value) {
        elem = typeof elem === 'string' ? $(elem) : elem;
        return _get$1(_getPrototypeOf$1(JamilihMap.prototype), "set", this).call(this, elem, value);
      }
    }, {
      key: "invoke",
      value: function invoke(elem, methodName) {
        var _this$get;
 
        elem = typeof elem === 'string' ? $(elem) : elem;
 
        for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
          args[_key3 - 2] = arguments[_key3];
        }
 
        return (_this$get = this.get(elem))[methodName].apply(_this$get, [elem].concat(args));
      }
    }]);
 
    return JamilihMap;
  }(_wrapNativeSuper$1(Map));
 
  var JamilihWeakMap =
  /*#__PURE__*/
  function (_WeakMap) {
    _inherits$1(JamilihWeakMap, _WeakMap);
 
    function JamilihWeakMap() {
      _classCallCheck$1(this, JamilihWeakMap);
 
      return _possibleConstructorReturn$1(this, _getPrototypeOf$1(JamilihWeakMap).apply(this, arguments));
    }
 
    _createClass$1(JamilihWeakMap, [{
      key: "get",
      value: function get$$1(elem) {
        elem = typeof elem === 'string' ? $(elem) : elem;
        return _get$1(_getPrototypeOf$1(JamilihWeakMap.prototype), "get", this).call(this, elem);
      }
    }, {
      key: "set",
      value: function set(elem, value) {
        elem = typeof elem === 'string' ? $(elem) : elem;
        return _get$1(_getPrototypeOf$1(JamilihWeakMap.prototype), "set", this).call(this, elem, value);
      }
    }, {
      key: "invoke",
      value: function invoke(elem, methodName) {
        var _this$get2;
 
        elem = typeof elem === 'string' ? $(elem) : elem;
 
        for (var _len4 = arguments.length, args = new Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) {
          args[_key4 - 2] = arguments[_key4];
        }
 
        return (_this$get2 = this.get(elem))[methodName].apply(_this$get2, [elem].concat(args));
      }
    }]);
 
    return JamilihWeakMap;
  }(_wrapNativeSuper$1(WeakMap));
 
  jml.Map = JamilihMap;
  jml.WeakMap = JamilihWeakMap;
 
  jml.weak = function (obj) {
    var map = new JamilihWeakMap();
 
    for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
      args[_key5 - 1] = arguments[_key5];
    }
 
    var elem = jml.apply(void 0, [{
      $map: [map, obj]
    }].concat(args));
    return [map, elem];
  };
 
  jml.strong = function (obj) {
    var map = new JamilihMap();
 
    for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
      args[_key6 - 1] = arguments[_key6];
    }
 
    var elem = jml.apply(void 0, [{
      $map: [map, obj]
    }].concat(args));
    return [map, elem];
  };
 
  jml.symbol = jml.sym = jml.for = function (elem, sym) {
    elem = typeof elem === 'string' ? $(elem) : elem;
    return elem[_typeof$1(sym) === 'symbol' ? sym : Symbol.for(sym)];
  };
 
  jml.command = function (elem, symOrMap, methodName) {
    elem = typeof elem === 'string' ? $(elem) : elem;
    var func;
 
    for (var _len7 = arguments.length, args = new Array(_len7 > 3 ? _len7 - 3 : 0), _key7 = 3; _key7 < _len7; _key7++) {
      args[_key7 - 3] = arguments[_key7];
    }
 
    if (['symbol', 'string'].includes(_typeof$1(symOrMap))) {
      var _func;
 
      func = jml.sym(elem, symOrMap);
 
      if (typeof func === 'function') {
        return func.apply(void 0, [methodName].concat(args)); // Already has `this` bound to `elem`
      }
 
      return (_func = func)[methodName].apply(_func, args);
    } else {
      var _func3;
 
      func = symOrMap.get(elem);
 
      if (typeof func === 'function') {
        var _func2;
 
        return (_func2 = func).call.apply(_func2, [elem, methodName].concat(args));
      }
 
      return (_func3 = func)[methodName].apply(_func3, [elem].concat(args));
    } // return func[methodName].call(elem, ...args);
 
  };
 
  jml.setWindow = function (wind) {
    win = wind;
  };
 
  jml.setDocument = function (docum) {
    doc = docum;
 
    if (docum && docum.body) {
      body = docum.body;
    }
  };
 
  jml.setXMLSerializer = function (xmls) {
    XmlSerializer = xmls;
  };
 
  jml.getWindow = function () {
    return win;
  };
 
  jml.getDocument = function () {
    return doc;
  };
 
  jml.getXMLSerializer = function () {
    return XmlSerializer;
  };
 
  var body = doc && doc.body;
  var nbsp = "\xA0"; // Very commonly needed in templates
 
  /**
   * ISC License
   *
   * Copyright (c) 2018, Andrea Giammarchi, @WebReflection
   *
   * Permission to use, copy, modify, and/or distribute this software for any
   * purpose with or without fee is hereby granted, provided that the above
   * copyright notice and this permission notice appear in all copies.
   *
   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
   * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
   * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
   * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
   * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
   * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
   * PERFORMANCE OF THIS SOFTWARE.
   */
  var QueryResult =
  /*#__PURE__*/
  function (_Array) {
    _inherits(QueryResult, _Array);
 
    function QueryResult() {
      _classCallCheck(this, QueryResult);
 
      return _possibleConstructorReturn(this, _getPrototypeOf(QueryResult).apply(this, arguments));
    }
 
    return QueryResult;
  }(_wrapNativeSuper(Array));
 
  var create = Object.create,
      defineProperty = Object.defineProperty;
  var AP = Array.prototype;
  var DOM_CONTENT_LOADED = 'DOMContentLoaded';
  var LOAD = 'load';
  var NO_TRANSPILER_ISSUES = new QueryResult() instanceof QueryResult;
  var QRP = QueryResult.prototype; // fixes methods returning non QueryResult
 
  /* istanbul ignore if */
 
  if (!NO_TRANSPILER_ISSUES) Object.getOwnPropertyNames(AP).forEach(function (name) {
    var desc = Object.getOwnPropertyDescriptor(AP, name);
 
    if (typeof desc.value === 'function') {
      var fn = desc.value;
 
      desc.value = function () {
        var result = fn.apply(this, arguments);
        return result instanceof Array ? patch(result) : result;
      };
    }
 
    defineProperty(QRP, name, desc);
  }); // fixes badly transpiled classes
 
  var patch = NO_TRANSPILER_ISSUES ? function (qr) {
    return qr;
  } :
  /* istanbul ignore next */
  function (qr) {
    var nqr = create(QRP);
    push.apply(nqr, slice(qr));
    return nqr;
  };
  var push = AP.push;
 
  var search = function search(list, el) {
    var nodes = [];
    var length = list.length;
 
    for (var i = 0; i < length; i++) {
      var css = list[i].trim();
 
      if (css.slice(-6) === ':first') {
        var node = el.querySelector(css.slice(0, -6));
        if (node) push.call(nodes, node);
      } else push.apply(nodes, slice(el.querySelectorAll(css)));
    }
 
    return _construct(QueryResult, nodes);
  };
 
  var slice = NO_TRANSPILER_ISSUES ? patch :
  /* istanbul ignore next */
  function (all) {
    // do not use slice.call(...) due old IE gotcha
    var nodes = [];
    var length = all.length;
 
    for (var i = 0; i < length; i++) {
      nodes[i] = all[i];
    }
 
    return nodes;
  }; // use function to avoid usage of Symbol.hasInstance
  // (broken in older browsers anyway)
 
  var $$1 = function $(CSS) {
    var parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
 
    switch (_typeof(CSS)) {
      case 'string':
        return patch(search(CSS.split(','), parent));
 
      case 'object':
        // needed to avoid iterator dance (breaks in older IEs)
        var nodes = [];
        var all = 'nodeType' in CSS || 'postMessage' in CSS ? [CSS] : CSS;
        push.apply(nodes, slice(all));
        return patch(_construct(QueryResult, nodes));
 
      case 'function':
        var $parent = $(parent);
        var $window = $(parent.defaultView);
        var handler = {
          handleEvent: function handleEvent(event) {
            $parent.off(DOM_CONTENT_LOADED, handler);
            $window.off(LOAD, handler);
            CSS(event);
          }
        };
        $parent.on(DOM_CONTENT_LOADED, handler);
        $window.on(LOAD, handler);
        var rs = parent.readyState;
        if (rs == 'complete' || rs != 'loading' && !parent.documentElement.doScroll) setTimeout(function () {
          return $parent.dispatch(DOM_CONTENT_LOADED);
        });
        return $;
    }
  };
 
  $$1.prototype = QRP;
 
  $$1.extend = function (key, value) {
    return defineProperty(QRP, key, {
      configurable: true,
      value: value
    }), $$1;
  }; // dropped usage of for-of to avoid broken iteration dance in older IEs
 
 
  $$1.extend('dispatch', function dispatch(type) {
    var init = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
    var event = new CustomEvent(type, init);
    var length = this.length;
 
    for (var i = 0; i < length; i++) {
      this[i].dispatchEvent(event);
    }
 
    return this;
  }).extend('off', function off(type, handler) {
    var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
    var length = this.length;
 
    for (var i = 0; i < length; i++) {
      this[i].removeEventListener(type, handler, options);
    }
 
    return this;
  }).extend('on', function on(type, handler) {
    var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
    var length = this.length;
 
    for (var i = 0; i < length; i++) {
      this[i].addEventListener(type, handler, options);
    }
 
    return this;
  });
 
  function _typeof$2(obj) {
    if (typeof Symbol === "function" && _typeof(Symbol.iterator) === "symbol") {
      _typeof$2 = function _typeof$$1(obj) {
        return _typeof(obj);
      };
    } else {
      _typeof$2 = function _typeof$$1(obj) {
        return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof(obj);
      };
    }
 
    return _typeof$2(obj);
  }
 
  function _slicedToArray$2(arr, i) {
    return _arrayWithHoles$2(arr) || _iterableToArrayLimit$2(arr, i) || _nonIterableRest$2();
  }
 
  function _toConsumableArray$2(arr) {
    return _arrayWithoutHoles$2(arr) || _iterableToArray$2(arr) || _nonIterableSpread$2();
  }
 
  function _arrayWithoutHoles$2(arr) {
    if (Array.isArray(arr)) {
      for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
        arr2[i] = arr[i];
      }
 
      return arr2;
    }
  }
 
  function _arrayWithHoles$2(arr) {
    if (Array.isArray(arr)) return arr;
  }
 
  function _iterableToArray$2(iter) {
    if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  }
 
  function _iterableToArrayLimit$2(arr, i) {
    var _arr = [];
    var _n = true;
    var _d = false;
    var _e = undefined;
 
    try {
      for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
        _arr.push(_s.value);
 
        if (i && _arr.length === i) break;
      }
    } catch (err) {
      _d = true;
      _e = err;
    } finally {
      try {
        if (!_n && _i["return"] != null) _i["return"]();
      } finally {
        if (_d) throw _e;
      }
    }
 
    return _arr;
  }
 
  function _nonIterableSpread$2() {
    throw new TypeError("Invalid attempt to spread non-iterable instance");
  }
 
  function _nonIterableRest$2() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance");
  }
 
  function convertToString(content, type) {
    switch (_typeof$2(content)) {
      case 'object':
        {
          if (!content) {
            throw new TypeError('Cannot supply `null`');
          }
 
          switch (content.nodeType) {
            case 1:
              {
                // ELEMENT
                return content.outerHTML;
              }
 
            case 3:
              {
                // TEXT
                return content.nodeValue;
              }
 
            case 11:
              {
                // DOCUMENT_FRAGMENT_NODE
                return _toConsumableArray$2(content.childNodes).reduce(function (s, node) {
                  return s + convertToString(node, type);
                }, '');
              }
 
            case undefined:
              {
                // Array of nodes, QueryResult objects
                // if (Array.isArray(content)) {
                if (typeof content.reduce === 'function') {
                  return content.reduce(function (s, node) {
                    return s + convertToString(node, type);
                  }, '');
                }
              }
          }
 
          return;
        }
 
      case 'string':
        {
          return content;
        }
 
      default:
        throw new TypeError('Bad content for ' + type + '; type: ' + _typeof$2(content));
    }
  }
 
  function convertToDOM(content, type, avoidClone) {
    switch (_typeof$2(content)) {
      case 'object':
        {
          if (!content) {
            throw new TypeError('Cannot supply `null`');
          }
 
          if ([1, // ELEMENT
          3, // TEXT
          11 // Document fragment
          ].includes(content.nodeType)) {
            return avoidClone ? content : content.cloneNode(true);
          }
 
          if (typeof content.reduce !== 'function') {
            throw new TypeError('Unrecognized type of object for conversion to DOM');
          } // Array of nodes, QueryResult objects
 
 
          return avoidClone ? content : content.map(function (node) {
            if (!node || !node.cloneNode) {
              // Allows for arrays of HTML strings
              return convertToDOM(node, type, false);
            }
 
            return node.cloneNode(true);
          });
        }
 
      case 'string':
        {
          var div = document.createElement('div');
          div.innerHTML = content;
          return div.firstElementChild || div.firstChild;
        }
 
      default:
        throw new TypeError('Bad content for ' + type + '; type: ' + _typeof$2(content));
    }
  }
 
  function insert(type) {
    return function () {
      var _this = this;
 
      for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }
 
      var cbOrContent = args[0];
 
      switch (_typeof$2(cbOrContent)) {
        case 'function':
          {
            this.forEach(function (node, i) {
              var ret = cbOrContent.call(_this, i, node.textContent);
              node[type](ret);
            });
            break;
          }
 
        default:
          {
            this.forEach(function (node, i, arr) {
              node[type].apply(node, _toConsumableArray$2(args.flatMap(function (content) {
                return convertToDOM(content, type, i === arr.length - 1);
              })));
            });
            break;
          }
      }
 
      return this;
    };
  }
 
  function insertText(type) {
    return function (cbOrContent) {
      var _this2 = this;
 
      switch (_typeof$2(cbOrContent)) {
        case 'function':
          {
            this.forEach(function (node, i) {
              var ret = cbOrContent.call(_this2, i, node[type]);
              node[type] = convertToString(ret, type);
            });
            break;
          }
 
        default:
          {
            this.forEach(function (node) {
              node[type] = convertToString(cbOrContent, type);
            });
            break;
          }
      }
 
      return this;
    };
  }
 
  var after = insert('after');
  var before = insert('before');
  var append = insert('append');
  var prepend = insert('prepend');
  var html = insertText('innerHTML');
  var text = insertText('textContent');
  /*
  // Todo:
  export const val = function (valueOrFunc) {
 
  };
  */
  // Given that these types require a selector engine and
  // in order to avoid the absence of optimization of `document.querySelectorAll`
  // for `:first-child` and different behavior in different contexts,
  // and to avoid making a mutual dependency with query-result,
  // exports of this type accept a QueryResult instance;
  // if selected without a second argument, we do default to
  //  `document.querySelectorAll`, however.
 
  var insertTo = function insertTo(method) {
    var $ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (sel) {
      return _toConsumableArray$2(document.querySelectorAll(sel));
    };
    var type = {
      appendTo: 'append',
      prependTo: 'prepend',
      insertAfter: 'after',
      insertBefore: 'before'
    }[method] || 'append';
    return function (target) {
      var toType = type + 'To';
      this.forEach(function (node, i, arr) {
        if (typeof target === 'string' && target.charAt(0) !== '<') {
          target = $(target);
        }
 
        target = Array.isArray(target) ? target : [target];
        node[type].apply(node, _toConsumableArray$2(target.flatMap(function (content) {
          return convertToDOM(content, toType, i === arr.length - 1);
        })));
      });
      return this;
    };
  }; // Todo: optional `withDataAndEvents` and `deepWithDataAndEvents` arguments?
 
 
  var clone = function clone() {
    return this.map(function (node) {
      // Still a QueryResult with such a map
      return node.cloneNode(true);
    });
  };
 
  var empty = function empty() {
    this.forEach(function (node) {
      node.textContent = '';
    });
  };
 
  var remove = function remove(selector) {
    if (selector) {
      this.forEach(function (node) {
        if (node.matches(selector)) {
          // Todo: Use query-result instead?
          node.remove();
        }
      });
    } else {
      this.forEach(function (node) {
        node.remove();
      });
    }
 
    return this;
  };
  /*
  // Todo:
  export const detach = function (selector) {
    // Should preserve attached data
    return remove(selector);
  };
  */
 
 
  var attr = function attr(attributeNameOrAtts, valueOrCb) {
    var _this3 = this;
 
    if (valueOrCb === undefined) {
      switch (_typeof$2(attributeNameOrAtts)) {
        case 'string':
          {
            return this[0].hasAttribute(attributeNameOrAtts) ? this[0].getAttribute(attributeNameOrAtts) : undefined;
          }
 
        case 'object':
          {
            if (attributeNameOrAtts) {
              this.forEach(function (node, i) {
                Object.entries(attributeNameOrAtts).forEach(function (_ref) {
                  var _ref2 = _slicedToArray$2(_ref, 2),
                      att = _ref2[0],
                      val = _ref2[1];
 
                  node.setAttribute(att, val);
                });
              });
              return this;
            }
          }
        // Fallthrough
 
        default:
          {
            throw new TypeError('Unexpected type for attribute name: ' + _typeof$2(attributeNameOrAtts));
          }
      }
    }
 
    switch (_typeof$2(valueOrCb)) {
      case 'function':
        {
          this.forEach(function (node, i) {
            var ret = valueOrCb.call(_this3, i, node.getAttribute(valueOrCb));
 
            if (ret === null) {
              node.removeAttribute(attributeNameOrAtts);
            } else {
              node.setAttribute(attributeNameOrAtts, ret);
            }
          });
          break;
        }
 
      case 'string':
        {
          this.forEach(function (node, i) {
            node.setAttribute(attributeNameOrAtts, valueOrCb);
          });
          break;
        }
 
      case 'object':
        {
          if (!valueOrCb) {
            // `null`
            return removeAttr.call(this, attributeNameOrAtts);
          }
        }
      // Fallthrough
 
      default:
        {
          throw new TypeError('Unexpected type for attribute name: ' + _typeof$2(attributeNameOrAtts));
        }
    }
 
    return this;
  };
 
  var removeAttr = function removeAttr(attributeName) {
    if (typeof attributeName !== 'string') {
      throw new TypeError('Unexpected type for attribute name: ' + _typeof$2(attributeName));
    }
 
    this.forEach(function (node) {
      node.removeAttribute(attributeName);
    });
  };
 
  function classAttManipulation(type) {
    return function (cbOrContent) {
      var _this4 = this;
 
      switch (_typeof$2(cbOrContent)) {
        case 'function':
          {
            this.forEach(function (node, i) {
              var _node$classList;
 
              var ret = cbOrContent.call(_this4, i, node.className);
 
              (_node$classList = node.classList)[type].apply(_node$classList, _toConsumableArray$2(ret.split(' ')));
            });
            break;
          }
 
        default:
          {
            if (type === 'remove' && !cbOrContent) {
              this.forEach(function (node) {
                node.className = '';
              });
              break;
            }
 
            this.forEach(function (node) {
              var _node$classList2;
 
              (_node$classList2 = node.classList)[type].apply(_node$classList2, _toConsumableArray$2(cbOrContent.split(' ')));
            });
            break;
          }
      }
 
      return this;
    };
  }
 
  var addClass = classAttManipulation('add');
  var removeClass = classAttManipulation('remove');
 
  var hasClass = function hasClass(className) {
    return this.some(function (node) {
      return node.classList.contains(className);
    });
  };
 
  var toggleClass = function toggleClass(classNameOrCb, state) {
    var _this5 = this;
 
    switch (typeof cbOrContent === "undefined" ? "undefined" : _typeof$2(cbOrContent)) {
      case 'function':
        {
          if (typeof state === 'boolean') {
            this.forEach(function (node, i) {
              var _node$classList3;
 
              var ret = classNameOrCb.call(_this5, i, node.className, state);
 
              (_node$classList3 = node.classList).toggle.apply(_node$classList3, _toConsumableArray$2(ret.split(' ')).concat([state]));
            });
          } else {
            this.forEach(function (node, i) {
              var _node$classList4;
 
              var ret = classNameOrCb.call(_this5, i, node.className, state);
 
              (_node$classList4 = node.classList).toggle.apply(_node$classList4, _toConsumableArray$2(ret.split(' ')));
            });
          }
 
          break;
        }
 
      case 'string':
        {
          if (typeof state === 'boolean') {
            this.forEach(function (node) {
              var _node$classList5;
 
              (_node$classList5 = node.classList).toggle.apply(_node$classList5, _toConsumableArray$2(classNameOrCb.split(' ')).concat([state]));
            });
          } else {
            this.forEach(function (node) {
              var _node$classList6;
 
              (_node$classList6 = node.classList).toggle.apply(_node$classList6, _toConsumableArray$2(classNameOrCb.split(' ')));
            });
          }
 
          break;
        }
    }
  };
 
  var methods = {
    after: after,
    before: before,
    append: append,
    prepend: prepend,
    html: html,
    text: text,
    clone: clone,
    empty: empty,
    remove: remove,
    // detach
    attr: attr,
    removeAttr: removeAttr,
    addClass: addClass,
    hasClass: hasClass,
    removeClass: removeClass,
    toggleClass: toggleClass
  };
 
  var manipulation = function manipulation($, jml) {
    ['after', 'before', 'append', 'prepend', 'html', 'text', 'clone', 'empty', 'remove', // 'detach'
    'attr', 'removeAttr', 'addClass', 'hasClass', 'removeClass', 'toggleClass'].forEach(function (method) {
      $.extend(method, methods[method]);
    });
    ['appendTo', 'prependTo', 'insertAfter', 'insertBefore'].forEach(function (method) {
      $.extend(method, insertTo(method, $));
    });
 
    if (jml) {
      $.extend('jml', function () {
        var _this6 = this;
 
        for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
          args[_key2] = arguments[_key2];
        }
 
        this.forEach(function (node) {
          while (node.hasChildNodes()) {
            node.firstChild.remove();
          }
 
          var n = jml.apply(void 0, args);
          return append.call(_this6, n);
        });
      });
    }
 
    return $;
  };
 
  manipulation($$1, jml);
  var baseAPIURL = 'https://openclipart.org/search/json/';
 
  function processResults(_x) {
    return _processResults.apply(this, arguments);
  }
 
  function _processResults() {
    _processResults = _asyncToGenerator(
    /*#__PURE__*/
    regeneratorRuntime.mark(function _callee3(url) {
      var queryLink, r, json, payload, _json$info, numResults, pages, currentPage, semiColonSep;
 
      return regeneratorRuntime.wrap(function _callee3$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              queryLink = function _ref4(query) {
                return ['a', {
                  href: 'javascript: void(0);',
                  dataset: {
                    value: query
                  },
                  $on: {
                    click: function click(e) {
                      e.preventDefault();
                      var value = this.dataset.value;
                      $$1('#query')[0].$set(value);
                      $$1('#openclipart')[0].$submit();
                    }
                  }
                }, [query]];
              };
 
              _context3.next = 3;
              return fetch(url);
 
            case 3:
              r = _context3.sent;
              _context3.next = 6;
              return r.json();
 
            case 6:
              json = _context3.sent;
              console.log('json', json);
 
              if (!(!json || json.msg !== 'success')) {
                _context3.next = 11;
                break;
              }
 
              alert('There was a problem downloading the results');
              return _context3.abrupt("return");
 
            case 11:
              payload = json.payload, _json$info = json.info, numResults = _json$info.results, pages = _json$info.pages, currentPage = _json$info.current_page; // $('#page')[0].value = currentPage;
              // $('#page')[0].max = pages;
              // Unused properties:
              // - `svg_filesize` always 0?
              // - `dimensions: {
              //      png_thumb: {width, height},
              //      png_full_lossy: {width, height}
              //    }` object of relevance?
              // - No need for `tags` with `tags_array`
              // - `svg`'s: `png_thumb`, `png_full_lossy`, `png_2400px`
 
              semiColonSep = '; ' + nbsp;
              $$1('#results').jml('div', [['span', ['Number of results: ', numResults]], semiColonSep, ['span', ['page ', currentPage, ' out of ', pages]]].concat(_toConsumableArray(payload.map(function (_ref3) {
                var title = _ref3.title,
                    description = _ref3.description,
                    id = _ref3.id,
                    uploader = _ref3.uploader,
                    created = _ref3.created,
                    svgURL = _ref3.svg.url,
                    detailLink = _ref3.detail_link,
                    tagsArray = _ref3.tags_array,
                    downloadedBy = _ref3.downloaded_by,
                    totalFavorites = _ref3.total_favorites;
                var imgHW = '100px';
                var colonSep = ': ' + nbsp;
                return ['div', [['button', {
                  style: 'margin-right: 8px; border: 2px solid black;',
                  dataset: {
                    id: id,
                    value: svgURL
                  },
                  $on: {
                    click: function () {
                      var _click = _asyncToGenerator(
                      /*#__PURE__*/
                      regeneratorRuntime.mark(function _callee2(e) {
                        var _this$dataset, svgURL, id, post, result, svg;
 
                        return regeneratorRuntime.wrap(function _callee2$(_context2) {
                          while (1) {
                            switch (_context2.prev = _context2.next) {
                              case 0:
                                e.preventDefault();
                                _this$dataset = this.dataset, svgURL = _this$dataset.value, id = _this$dataset.id;
                                console.log('this', id, svgURL);
 
                                post = function post(message) {
                                  // Todo: Make origin customizable as set by opening window
                                  // Todo: If dropping IE9, avoid stringifying
                                  window.parent.postMessage(JSON.stringify(_extends({
                                    namespace: 'imagelib'
                                  }, message)), '*');
                                }; // Send metadata (also indicates file is about to be sent)
 
 
                                post({
                                  name: title,
                                  id: svgURL
                                });
                                _context2.next = 7;
                                return fetch(svgURL);
 
                              case 7:
                                result = _context2.sent;
                                _context2.next = 10;
                                return result.text();
 
                              case 10:
                                svg = _context2.sent;
                                console.log('h', svgURL, svg);
                                post({
                                  href: svgURL,
                                  data: svg
                                });
 
                              case 13:
                              case "end":
                                return _context2.stop();
                            }
                          }
                        }, _callee2, this);
                      }));
 
                      return function click(_x2) {
                        return _click.apply(this, arguments);
                      };
                    }()
                  }
                }, [// If we wanted interactive versions despite security risk:
                // ['object', {data: svgURL, type: 'image/svg+xml'}]
                ['img', {
                  src: svgURL,
                  style: "width: ".concat(imgHW, "; height: ").concat(imgHW, ";")
                }]]], ['b', [title]], ' ', ['i', [description]], ' ', ['span', ['(ID: ', ['a', {
                  href: 'javascript: void(0);',
                  dataset: {
                    value: id
                  },
                  $on: {
                    click: function click(e) {
                      e.preventDefault();
                      var value = this.dataset.value;
                      $$1('#byids')[0].$set(value);
                      $$1('#openclipart')[0].$submit();
                    }
                  }
                }, [id]], ')']], ' ', ['i', [['a', {
                  href: detailLink,
                  target: '_blank'
                }, ['Details']]]], ['br'], ['span', [['u', ['Uploaded by']], colonSep, queryLink(uploader), semiColonSep]], ['span', [['u', ['Download count']], colonSep, downloadedBy, semiColonSep]], ['span', [['u', ['Times used as favorite']], colonSep, totalFavorites, semiColonSep]], ['span', [['u', ['Created date']], colonSep, created]], ['br'], ['u', ['Tags']], colonSep].concat(_toConsumableArray(tagsArray.map(function (tag) {
                  return ['span', [' ', queryLink(tag)]];
                })))];
              })), [['br'], ['br'], currentPage === 1 || pages <= 2 ? '' : ['span', [['a', {
                href: 'javascript: void(0);',
                $on: {
                  click: function click(e) {
                    e.preventDefault();
                    $$1('#page')[0].value = 1;
                    $$1('#openclipart')[0].$submit();
                  }
                }
              }, ['First']], ' ']], currentPage === 1 ? '' : ['span', [['a', {
                href: 'javascript: void(0);',
                $on: {
                  click: function click(e) {
                    e.preventDefault();
                    $$1('#page')[0].value = currentPage - 1;
                    $$1('#openclipart')[0].$submit();
                  }
                }
              }, ['Prev']], ' ']], currentPage === pages ? '' : ['span', [['a', {
                href: 'javascript: void(0);',
                $on: {
                  click: function click(e) {
                    e.preventDefault();
                    $$1('#page')[0].value = currentPage + 1;
                    $$1('#openclipart')[0].$submit();
                  }
                }
              }, ['Next']], ' ']], currentPage === pages || pages <= 2 ? '' : ['span', [['a', {
                href: 'javascript: void(0);',
                $on: {
                  click: function click(e) {
                    e.preventDefault();
                    $$1('#page')[0].value = pages;
                    $$1('#openclipart')[0].$submit();
                  }
                }
              }, ['Last']], ' ']]]));
 
            case 14:
            case "end":
              return _context3.stop();
          }
        }
      }, _callee3, this);
    }));
    return _processResults.apply(this, arguments);
  }
 
  jml('div', [['style', [".control {\n      padding-top: 10px;\n    }"]], ['form', {
    id: 'openclipart',
    $custom: {
      $submit: function () {
        var _$submit = _asyncToGenerator(
        /*#__PURE__*/
        regeneratorRuntime.mark(function _callee() {
          var url;
          return regeneratorRuntime.wrap(function _callee$(_context) {
            while (1) {
              switch (_context.prev = _context.next) {
                case 0:
                  url = new URL(baseAPIURL);
                  ['query', 'sort', 'amount', 'page', 'byids'].forEach(function (prop) {
                    var value = $$1('#' + prop)[0].value;
 
                    if (value) {
                      url.searchParams.set(prop, value);
                    }
                  });
                  _context.next = 4;
                  return processResults(url);
 
                case 4:
                case "end":
                  return _context.stop();
              }
            }
          }, _callee, this);
        }));
 
        return function $submit() {
          return _$submit.apply(this, arguments);
        };
      }()
    },
    $on: {
      submit: function submit(e) {
        e.preventDefault();
        this.$submit();
      }
    }
  }, [// Todo: i18nize
  ['fieldset', [['legend', ['Search terms']], ['div', {
    class: 'control'
  }, [['label', ['Query (Title, description, uploader, or tag): ', ['input', {
    id: 'query',
    name: 'query',
    placeholder: 'cat',
    $custom: {
      $set: function $set(value) {
        $$1('#byids')[0].value = '';
        this.value = value;
      }
    },
    $on: {
      change: function change() {
        $$1('#byids')[0].value = '';
      }
    }
  }]]]]], ['br'], ' OR ', ['br'], ['div', {
    class: 'control'
  }, [['label', ['IDs (single or comma-separated): ', ['input', {
    id: 'byids',
    name: 'ids',
    placeholder: '271380, 265741',
    $custom: {
      $set: function $set(value) {
        $$1('#query')[0].value = '';
        this.value = value;
      }
    },
    $on: {
      change: function change() {
        $$1('#query')[0].value = '';
      }
    }
  }]]]]]]], ['fieldset', [['legend', ['Configuring results']], ['div', {
    class: 'control'
  }, [['label', ['Sort by: ', ['select', {
    id: 'sort'
  }, [// Todo: i18nize first values
  ['Date', 'date'], ['Downloads', 'downloads'], ['Favorited', 'favorites']].map(function (_ref) {
    var _ref2 = _slicedToArray(_ref, 2),
        text$$1 = _ref2[0],
        _ref2$ = _ref2[1],
        value = _ref2$ === void 0 ? text$$1 : _ref2$;
 
    return ['option', {
      value: value
    }, [text$$1]];
  })]]]]], ['div', {
    class: 'control'
  }, [['label', ['Results per page: ', ['input', {
    id: 'amount',
    name: 'amount',
    value: 10,
    type: 'number',
    min: 1,
    max: 200,
    step: 1,
    pattern: '\\d+'
  }]]]]], ['div', {
    class: 'control'
  }, [['label', ['Page number: ', ['input', {
    // max: 1, // We'll change this based on available results
    id: 'page',
    name: 'page',
    value: 1,
    style: 'width: 40px;',
    type: 'number',
    min: 1,
    step: 1,
    pattern: '\\d+'
  }]]]]]]], ['div', {
    class: 'control'
  }, [['input', {
    type: 'submit'
  }]]]]], ['div', {
    id: 'results'
  }]], body);
 
}());