Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 | 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 627x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 669x 669x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 21x 876x 856x 877x 877x 877x 877x 877x 877x 877x 81x 877x 638x 638x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 50x 50x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 10x 10x 2x 2x 10x 10x 1x 1x 10x 10x 1x 1x 10x 1x 1x 10x 1x 1x 10x 1x 1x 10x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 10x 21x 2x 2x 1x 1x 2x 2x 2x 2x 2x 21x 10x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 129x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 841x 738x 877x 877x 877x 61x 2x 2x 2x 59x 59x 59x 59x 59x 59x 59x 61x 61x 61x 61x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 58x 58x 61x 1x 1x 1x 61x 59x 59x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 3x 3x 3x 3x 14x 14x 3x 3x 1x 1x 1x 1x 1x 2x 877x 877x 877x 877x 870x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 127x 12x 12x 115x 877x 877x 14x 1x 1x 13x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 185x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 185x 185x 185x 185x 174x 174x 185x 877x 877x 877x 877x 877x 877x 4x 4x 4x 4x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 877x 877x 877x 10x 10x 877x 877x 877x 877x 876x 876x 877x 877x 877x 16x 16x 877x 877x 2x 2x 2x 2x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 876x 876x 876x 876x 124x 876x 876x 1637x 1637x 1637x 1637x 1637x 50x 1637x 3x 3x 2x 2x 2x 2x 2x 2x 3x 1637x 876x 876x 876x 876x 876x 869x 876x 876x 877x 877x 877x 877x 877x 877x 877x 877x 8x 8x 8x 8x 8x 8x 8x 8x 3x 3x 3x 3x 8x 8x 8x 8x 877x 877x 877x 877x 877x 877x 877x 877x 877x 3x 3x 3x 3x 3x 877x 877x 877x 877x 877x 877x 877x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 877x 877x 877x 877x 877x 877x 877x 1x 1x 1x 877x 877x 877x 877x 877x 877x 1x 1x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 5441x 877x 877x 877x 877x 877x 877x 4x 4x 877x 877x 877x 877x 877x 877x 3x 3x 877x 877x 877x 877x 877x 877x 14590x 14590x 877x 877x 877x 877x 877x 877x 877x 179x 7x 7x 179x 179x 877x 877x 877x 877x 877x 877x 877x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 3x 3x 6x 6x 6x 6x 6x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 877x 877x 877x 877x 877x 877x 3x 3x 1x 1x 1x 3x 3x 3x 877x 877x 877x 877x 877x 877x 877x 1x 1x 1x 1x 877x 877x 877x 877x 877x 877x 877x 877x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 877x 877x 877x 877x 877x 877x 877x 8x 8x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 19x 20x 16x 32x 32x 32x 37x 37x 37x 32x 16x 20x 4x 4x 19x 19x 19x 19x 1x 19x 18x 18x 19x 19x 19x 1x 1x 1x 18x 18x 19x 877x 877x 877x 877x 877x 877x 877x 877x 877x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 3x 3x 3x 3x 877x 877x 877x 877x 877x 877x 877x 877x 877x 5037x 5037x 877x 877x 877x 877x 877x 877x 877x 877x 877x 508x 508x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 792x 792x 877x 877x 877x 877x 877x 877x 791x 791x 877x 877x 877x 877x 877x 877x 792x 792x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 2242x 2242x 877x 877x 877x 877x 877x 877x 877x 5x 5x 877x 877x 877x 877x 877x 877x 877x 877x 877x 1249x 1249x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 312x 312x 312x 312x 312x 312x 312x 312x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 321x 3x 3x 3x 3x 3x 3x 3x 321x 321x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 5x 5x 18x 18x 18x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 8x 8x 8x 8x 85x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 1207x 1207x 1205x 1207x 1207x 1207x 1207x 1207x 1207x 1207x 1207x 1207x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 2707x 752x 752x 752x 752x 2707x 2707x 877x 877x 877x 877x 877x 1742x 799x 799x 799x 799x 799x 1739x 1742x 877x 877x 877x 877x 877x 1341x 742x 742x 742x 742x 742x 742x 742x 742x 742x 742x 742x 1341x 1341x 877x 877x 877x 877x 877x 1338x 742x 742x 742x 742x 742x 742x 742x 1338x 1338x 877x 877x 877x 877x 877x 6x 6x 877x 877x 877x 877x 877x 9x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 9x 9x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 1477x 49x 49x 49x 1428x 1462x 773x 773x 773x 773x 773x 773x 1428x 1428x 1477x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 60x 60x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 49x 49x 49x 49x 877x 877x 877x 877x 877x 877x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 64x 64x 112x 64x 64x 112x 112x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 48x 48x 48x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 79x 64x 64x 79x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 146x 64x 64x 64x 64x 64x 64x 146x 877x 877x 877x 877x 877x 1415x 1359x 1399x 1359x 1359x 1359x 1359x 1399x 347x 347x 1358x 1358x 1358x 1358x 1358x 1358x 1358x 1358x 1358x 1358x 1358x 1358x 1358x 1358x 1358x 1358x 1358x 1358x 1358x 1358x 1415x 178x 178x 1338x 1388x 343x 343x 343x 1337x 1337x 1337x 1337x 1337x 1337x 1415x 1322x 1322x 1415x 22x 4x 4x 4x 22x 3x 3x 15x 1399x 1359x 1359x 1359x 1415x 877x 877x 877x 877x 877x 877x 1359x 1359x 1359x 1359x 3x 3x 1359x 877x 877x 877x 877x 877x 877x 877x 877x 158x 158x 877x 877x 877x 877x 877x 877x 877x 33x 33x 877x 877x 877x 877x 877x 877x 877x 1521x 3x 3x 1518x 1521x 51x 51x 1467x 1467x 1279x 1279x 1467x 1521x 1x 1x 1466x 1466x 1466x 1466x 1466x 1466x 1466x 1520x 67x 67x 67x 1399x 1503x 682x 682x 682x 1521x 877x 877x 877x 877x 877x 877x 877x 2238x 2238x 2238x 2238x 2238x 2234x 2238x 2238x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 1518x 121x 121x 1397x 1453x 149x 149x 1248x 1518x 630x 630x 618x 618x 1518x 1518x 1518x 1518x 618x 618x 618x 618x 29x 29x 29x 29x 29x 618x 618x 567x 567x 567x 618x 618x 1197x 51x 51x 51x 567x 567x 1518x 877x 877x 877x 877x 877x 877x 877x 877x 877x 618x 618x 553x 553x 70x 40x 14x 14x 40x 51x 51x 618x 618x 618x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 15x 15x 15x 15x 15x 15x 15x 15x 15x 1x 1x 15x 15x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 638x 638x 638x 638x 636x 638x 3x 3x 635x 635x 635x 638x 525x 525x 525x 635x 638x 3x 3x 3x 635x 638x 877x 877x 877x 877x 877x 877x 877x 877x 528x 528x 528x 528x 528x 695x 695x 619x 619x 695x 528x 528x 14x 14x 528x 528x 877x 877x 877x 877x 877x 877x 877x 877x 840x 840x 840x 840x 840x 840x 840x 840x 840x 840x 840x 840x 840x 10x 10x 830x 830x 830x 830x 830x 830x 830x 830x 830x 86x 6x 6x 6x 6x 6x 6x 6x 84x 80x 80x 830x 830x 830x 830x 840x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 88x 88x 88x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 48x 48x 2x 2x 2x 48x 877x 877x 877x 877x 877x 877x 877x 877x 12x 12x 12x 12x 20x 20x 12x 12x 12x 12x 12x 12x 12x 12x 12x 17x 17x 12x 12x 12x 12x 12x 12x 12x 877x 877x 877x 877x 877x 877x 877x 1389x 1389x 1389x 1389x 1389x 29x 29x 29x 29x 29x 23x 23x 7x 29x 29x 29x 16x 16x 16x 16x 16x 16x 16x 16x 6x 6x 25x 6x 15x 10x 16x 10x 10x 16x 16x 29x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1389x 1389x 877x 877x 877x 877x 877x 877x 877x 1485x 1485x 1485x 1485x 1485x 1485x 103x 103x 103x 192x 192x 192x 192x 30x 30x 162x 162x 162x 73x 73x 1485x 1485x 877x 877x 877x 877x 877x 877x 889x 830x 830x 889x 877x 877x 877x 877x 877x 877x 877x 837x 837x 837x 837x 837x 837x 837x 837x 837x 77x 77x 77x 138x 138x 138x 138x 17x 17x 121x 121x 121x 60x 60x 60x 77x 60x 60x 60x 837x 837x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 6x 6x 6x 6x 6x 13x 7x 7x 13x 4x 4x 4x 13x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 11x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 25x 13x 13x 13x 3x 13x 13x 13x 13x 6x 6x 6x 6x 877x 877x 877x 877x 877x 877x 877x 36x 36x 36x 36x 36x 36x 28x 8x 8x 8x 8x 8x 8x 8x 28x 20x 20x 36x 36x 36x 36x 36x 36x 36x 36x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 23x 22x 22x 22x 22x 15x 15x 4x 22x 22x 22x 11x 11x 11x 11x 11x 11x 11x 22x 22x 22x 22x 22x 36x 36x 36x 877x 877x 877x 877x 877x 877x 504x 504x 504x 504x 504x 504x 504x 504x 877x 877x 877x 877x 877x 877x 546x 546x 546x 546x 546x 546x 469x 469x 546x 546x 546x 546x 877x 877x 877x 877x 877x 877x 358x 358x 355x 355x 355x 358x 3x 3x 3x 358x 877x 877x 877x 877x 877x 877x 877x 18x 18x 877x 877x 877x 877x 877x 877x 877x 1x 1x 877x 877x 877x 877x 877x 877x 355x 355x 355x 355x 355x 355x 335x 335x 355x 355x 355x 355x 302x 302x 355x 355x 355x 355x 301x 301x 301x 355x 355x 355x 355x 355x 355x 355x 39x 39x 39x 355x 355x 355x 355x 1x 2x 2x 1x 1x 355x 355x 355x 11x 11x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 355x 2x 2x 2x 2x 355x 355x 355x 355x 355x 355x 348x 348x 348x 348x 348x 348x 348x 348x 348x 348x 348x 348x 348x 348x 347x 347x 347x 347x 347x 347x 355x 1x 1x 355x 355x 355x 355x 355x 355x 355x 355x 355x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 125x 125x 125x 56x 13x 13x 56x 125x 125x 56x 56x 125x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 8x 6x 6x 8x 2x 1x 1x 1x 1x 8x 877x 877x 877x 877x 877x 877x 820x 120x 123x 118x 118x 123x 2x 702x 820x 877x 877x 877x 877x 877x 877x 877x 877x 877x 562x 562x 877x 877x 877x 877x 877x 877x 336x 336x 877x 877x 877x 877x 877x 877x 117x 117x 877x 877x 877x 877x 877x 877x 6x 6x 877x 877x 877x 877x 877x 877x 877x 5x 5x 877x 877x 877x 877x 877x 877x 503x 503x 877x 877x 877x 877x 877x 877x 840x 840x 840x 840x 7x 7x 840x 840x 6x 10x 10x 13x 1x 1x 7x 13x 12x 12x 12x 12x 12x 2x 2x 2x 2x 2x 2x 12x 12x 12x 44x 44x 6x 6x 6x 38x 44x 6x 6x 38x 38x 38x 44x 10x 10x 10x 38x 38x 12x 12x 12x 12x 12x 840x 877x 877x 877x 877x 877x 877x 877x 877x 44x 44x 44x 44x 94x 43x 43x 38x 38x 43x 56x 56x 6x 44x 877x 877x 877x 877x 877x 877x 877x 877x 877x 43x 43x 43x 43x 43x 43x 43x 43x 6x 43x 37x 37x 43x 877x 877x 877x 877x 877x 877x 877x 877x 877x 38x 32x 32x 4x 4x 28x 28x 6x 6x 30x 38x 38x 6x 38x 38x 38x 6x 30x 38x 877x 877x 877x 877x 877x 877x 840x 840x 840x 840x 6x 840x 840x 840x 5x 5x 5x 5x 5x 5x 5x 5x 840x 877x 877x 877x 877x 877x 877x 877x 10x 6x 6x 10x 10x 8x 8x 8x 10x 10x 877x 877x 877x 877x 877x 877x 877x 2x 2x 2x 2x 2x 2x 2x 877x 877x 877x 877x 877x 1454x 6x 10x 10x 10x 10x 6x 1454x 877x 877x 877x 877x 877x 1358x 7x 1358x 1358x 1358x 7x 1358x 1358x 7x 7x 11x 4x 4x 11x 7x 1358x 877x 877x 877x 877x 877x 877x 877x 877x 877x 6x 6x 6x 6x 6x 6x 6x 877x 877x 877x 877x 877x 877x 9594x 1582x 1582x 9594x 1264x 1264x 6748x 8181x 6532x 6532x 13724x 555x 555x 555x 555x 13724x 13724x 6532x 6748x 9594x 877x 877x 877x 877x 877x 877x 230x 230x 877x 877x 877x 877x 877x 877x 877x 2223x 2223x 31x 9x 31x 31x 2223x 2223x 2223x 237x 237x 2223x 2223x 246x 246x 246x 241x 246x 246x 246x 246x 246x 246x 246x 246x 246x 246x 246x 20x 2x 2x 18x 18x 18x 18x 18x 18x 246x 2223x 877x 877x 877x 877x 877x 877x 877x 877x 75x 75x 75x 75x 44x 24x 24x 24x 20x 20x 75x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 877x 45x 45x 45x 45x 60x 60x 4x 2x 2x 2x 2x 2x 4x 60x 60x 60x 60x 60x 16x 16x 60x 60x 18x 18x 18x 18x 18x 9x 9x 18x 18x 18x 18x 9x 9x 18x 51x 51x 51x 36x 36x 45x 24x 24x 24x 12x 15x 11x 11x 11x 11x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 45x 45x 45x 45x 45x 45x 877x 877x 877x 877x 877x 877x 877x 1386x 1386x 1386x 1386x 1386x 7x 7x 7x 7x 7x 7x 7x 1386x 877x 877x 877x 877x 877x 877x 877x 6x 6x 6x 6x 5x 2x 2x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x 6x 877x 877x 877x 877x 877x 877x 877x 16x 16x 16x 16x 16x 16x 1x 1x 16x 16x 16x 15x 15x 15x 15x 9x 9x 9x 15x 15x 15x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 16x 877x 877x 877x 877x 877x 877x 8x 8x 8x 8x 877x 877x 877x 877x 877x 877x 8x 8x 877x 877x 877x 877x 877x 877x 877x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 47x 9x 9x 47x 15x 15x 15x 15x 22x 14x 14x 22x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 10x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 13x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 34x 2x 2x 34x 16x 16x 16x 16x 16x 16x 34x 15x 15x 15x 15x 15x 15x 15x 17x 17x 17x 17x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 15x 17x 1x 1x 1x 1x 17x 15x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 22x 22x 22x 22x 15x 15x 15x 2x 2x 2x 4x 2x 2x 2x 2x 2x 2x 15x 15x 15x 15x 15x 15x 15x 47x 47x 15x 15x 15x 877x | import { ComputedRegistry } from '../reactive/createComputed.js';
import { styleMountManager } from './StyleMountManager.js';
import { EventBinder } from '../events/bindEvents.js';
import { EventExecutor, buildEventNode } from '../events/eventExecutor.js';
import { DynamicEvaluator } from '../security/evaluator.js';
import { LifecycleManager } from './lifecycle.js';
import { LIFECYCLE_HOOK_KEYS } from './lifecycleHooks.js';
import { ComponentScope } from './ComponentScope.js';
import { stampScope } from '../renderer/bindingScope.js';
import { syncControlValue } from '../renderer/controlValue.js';
import { DeadlockManager } from '../renderer/deadlockManager.js';
import { AvenxError, AvenxErrorCodes, formatMessage } from './AvenxError.js';
import { logger } from './AvenxLogger.js';
import { queueJob, queueFlushCallback, nextTick as schedulerNextTick } from '../reactive/scheduler.js';
import { TemplateInstance } from '../renderer/program/TemplateInstance.js';
import { isProgram } from '../../compiler/render/program.js';
import { AvenxWatcher, activeWatcher, isDebugReactivityEnabled, getPropertyPath, depMap } from '../reactive/watcher.js';
import { DisposalScope, runInScope } from '../reactive/scope.js';
import { Resource } from '../reactive/Resource.js';
import { ProxyHandlerFactory, RAW_SYMBOL, toRaw } from '../reactive/proxyHandler.js';
import { processBindDirectives, restoreScopedSlotInterpolations } from '../utils/templateUtils.js';
import { profile } from '../utils/profiler.js';
import { parseValidationRules, validateValue, getFieldName, updateValidationState } from '../validation/validator.js';
import { serializeSafe } from '../tooling/inspect.js';
import { requireStringRenderer, hasStringRenderer } from '../renderer/stringRenderer.js';
import { tracer } from '../trace/tracer.js';
import { TraceNodeType } from '../trace/schema.js';
import { traceDerived } from '../trace/derived.js';
/**
* Method names that collide with a real AvenxComponent instance method.
*
* An action or method with one of these names shadows framework machinery --
* `update` is the render method, `destroy` tears the component down -- so it is
* a genuine mistake and warns (AVX_W26).
* @type {string[]}
*/
export const RESERVED_INSTANCE_METHOD_KEYS = ['mount', 'unmount', 'update', 'destroy', 'scheduleUpdate'];
const TEMPLATE_EXCLUDED_IDENTIFIERS = new Set([
'state',
'props',
'styles',
'event',
'args',
'Math',
'console',
'JSON',
'window',
'document',
'Array',
'Object',
'String',
'Number',
'Boolean',
'Date',
'Error',
'Map',
'Set',
'Promise',
'true',
'false',
'null',
'undefined',
]);
/**
* Lifecycle hook names.
*
* These are the documented, supported way to define a hook: an
* `<action name="onMount">` is looked up by {@link AvenxComponent#triggerLifecycle}
* and run at the right moment. They are meant to be declared, so they do not
* warn -- unlike a collision with a reserved instance method.
* @type {string[]}
*/
export { LIFECYCLE_HOOK_KEYS } from './lifecycleHooks.js';
/**
* Every name the runtime treats specially: reserved instance methods and
* lifecycle hooks. Retained for callers that need the full set; the collision
* warning uses {@link RESERVED_INSTANCE_METHOD_KEYS} alone.
* @type {string[]}
*/
export const RESERVED_INSTANCE_KEYS = [...RESERVED_INSTANCE_METHOD_KEYS, ...LIFECYCLE_HOOK_KEYS];
const globalMixins = [];
let componentUid = 0;
/**
* Base class for all Avenx components.
* Manages state, reactivity, rendering, and lifecycle.
*/
export class AvenxComponent {
/** @type {Element|null} */
#element = null;
/** @type {string} */
#template = '';
/** @type {object} */
#methods = {};
/** @type {object} */
#bridges = {};
/**
* Values the component's module imported, keyed by their local name.
*
* Template expressions and action bodies are evaluated against a declared
* scope rather than by the JavaScript engine, so a module-level `import` is
* not visible to them by default. Before the bundler that was moot -- the
* compiler deleted every non-runtime import, so there was nothing to see.
* Now that an import resolves and ships, it has to be reachable from the code
* that asked for it, or the import is decoration.
*
* They sit at the bottom of the scope, below bridges, so nothing imported can
* shadow a `<state>` key, a computed value, an action or a bridge.
* @type {object}
*/
#imports = {};
/**
* Whether {@link AvenxComponent##imports} holds anything.
*
* Kept as a flag so building a scope costs no property enumeration, and so a
* component that imports nothing gets exactly the layers it had before.
* @type {boolean}
*/
#hasImports = false;
/** @type {ComputedRegistry} */
#computed;
/**
* Set of root state identifiers referenced by the template.
* null indicates constructs defeating static analysis, forcing unconditional updates.
* @type {Set<string>|null}
*/
#templateDeps = null;
/** @type {TemplateRenderer|null} */
#rendererInstance = null;
/** @type {DomPatcher|null} */
#patcherInstance = null;
/** @type {ListManager|null} */
#listManagerInstance = null;
/** @type {DeferManager|null} */
#deferManagerInstance = null;
/** @type {DeadlockManager|null} */
#deadlockManagerInstance = null;
/** @type {EventBinder} */
#eventBinder;
/** @type {EventExecutor} */
#eventExecutor;
/** @type {DynamicEvaluator} */
#evaluator;
/** @type {LifecycleManager} */
#lifecycle;
/** @type {boolean} */
#isMounted = false;
/** @type {boolean} */
#isUpdating = false;
/** @type {Set<string>} */
#evaluating = new Set();
/**
* Whether a render has completed, and therefore whether the render watcher's
* dependency set can be trusted to say what this component observes.
* @type {boolean}
*/
#hasRenderedOnce = false;
/** @type {object | null} */
#transcludedGroups = null;
/** @type {boolean} */
#updateQueued = false;
/**
* The names this component's state layer binds, cached.
*
* Invalidated by the state proxy whenever a root key is added or removed.
* Null means "not computed yet".
* @type {string[]|null}
*/
#scope = new ComponentScope(this);
/**
* The compiled render program, when the compiler produced one.
*
* Its presence is what selects the fine-grained renderer. A component whose
* template contains something the program runtime does not implement has no
* program and renders through the string path, unchanged.
* @type {object|null}
*/
#program = null;
/**
* This component's mounted copy of the program.
* @type {TemplateInstance|null}
*/
#templateInstance = null;
/**
* Why the compiled skeleton could not be prepared, when it could not: the
* failure reason the compiled template recorded ('no-dom' or
* 'marker-mismatch'). Carried into the string-renderer lookup so a fallback
* forced by an environment with no usable DOM reports AVX_R37 -- the
* environment -- rather than AVX_R34's mislinked bundle.
* @type {string|null}
*/
#skeletonFailure = null;
/**
* Set once the post-render notification is queued for this flush, so a
* component with 500 bindings fires `onUpdate` once rather than 500 times.
* @type {boolean}
*/
#postRenderQueued = false;
/**
* Set once `onBeforeUpdate` has fired for the flush in progress. Cleared when
* that flush's post-render notification runs.
* @type {boolean}
*/
#beforeRenderFired = false;
/** @type {Function} */
#updateJob = () => {
this.#updateQueued = false;
this.update();
};
/** @type {boolean} */
#isUnmounting = false;
/** @type {Promise<void>|null} */
#unmountPromise = null;
/** @type {boolean} */
#isUnmounted = false;
/** @type {Record<string, Element>} */
#refsCache = {};
/** @type {boolean} */
#refsDirty = false;
/** @type {boolean} */
#isBeforeMounting = false;
/** @type {Object<string, object>} */
#resources = {};
/** @type {Error|null} */
#componentError = null;
/** @type {Set<string>} */
#contracts = new Set();
/**
* @param {object} [initialState] - The initial state of the component.
* @param {object} [computed] - Computed properties definitions.
* @param {object} [bridges] - External bridges accessible to the component.
* @param {string} [template] - The HTML template string.
* @param {object} [methods] - Component methods.
* @param {object} [props] - Component properties.
* @param {object} [styles] - Component CSS variables.
* @param {object} [resources] - Reactive resources.
* @param {object} [options] - Component options and compiler contracts.
*/
constructor(
initialState = {},
computed = {},
bridges = {},
template = '',
methods = {},
props = {},
styles = {},
resources = {},
options = {},
) {
this.uid = componentUid++;
this.#updateJob.id = this.uid;
this.#updateJob.component = this;
if (options && options.contracts) {
this.#contracts = new Set(options.contracts);
} else if (Array.isArray(options)) {
this.#contracts = new Set(options);
} else if (options instanceof Set) {
this.#contracts = options;
}
// Actions the compiler saw declared `atomic`. Absent for every component
// that declares none, which is why the generated constructor omits the
// options argument entirely in that case.
const optionsObject = options && !Array.isArray(options) && !(options instanceof Set) ? options : null;
this.options = optionsObject || {};
if (this.options.templateDeps !== undefined) {
this.#templateDeps = this.options.templateDeps === null ? null : new Set(this.options.templateDeps);
} else if (typeof template === 'string' && template.trim()) {
this.#templateDeps = this.#extractTemplateDeps(template);
}
if (optionsObject && optionsObject.imports && typeof optionsObject.imports === 'object') {
this.#imports = optionsObject.imports;
this.#hasImports = true;
}
const atomicActions = options && !Array.isArray(options) && !(options instanceof Set) ? options.atomic : null;
// The render program travels in the same options object. Validating the
// shape rather than trusting it keeps a program produced by a different
// build -- restored from a cache, replayed from a trace fixture -- from
// reaching a renderer that would misread it; an unrecognised program means
// the string path, which is slower and always correct.
const compiledProgram = options && !Array.isArray(options) && !(options instanceof Set) ? options.program : null;
if (isProgram(compiledProgram)) {
this.#program = compiledProgram;
}
/** @type {AvenxComponent|null} */
this.$parent = null;
// Merge global mixins options
const mergedState = {};
const mergedComputed = {};
const mergedMethods = {};
const mergedProps = {};
const mergedStyles = {};
for (const mixin of globalMixins) {
const mixinState = typeof mixin.state === 'function' ? mixin.state.call(this) : mixin.state;
if (mixinState && typeof mixinState === 'object') {
Object.assign(mergedState, mixinState);
}
const mixinData = typeof mixin.data === 'function' ? mixin.data.call(this) : mixin.data;
if (mixinData && typeof mixinData === 'object') {
Object.assign(mergedState, mixinData);
}
if (mixin.computed && typeof mixin.computed === 'object') {
Object.assign(mergedComputed, mixin.computed);
}
if (mixin.methods && typeof mixin.methods === 'object') {
Object.assign(mergedMethods, mixin.methods);
}
if (mixin.props && typeof mixin.props === 'object') {
Object.assign(mergedProps, mixin.props);
}
if (mixin.styles && typeof mixin.styles === 'object') {
Object.assign(mergedStyles, mixin.styles);
}
}
Object.assign(mergedState, initialState);
Object.assign(mergedComputed, computed);
Object.assign(mergedMethods, methods);
Object.assign(mergedProps, props);
Object.assign(mergedStyles, styles);
this._mixinProps = {};
const reservedKeys = ['state', 'data', 'methods', 'computed', 'props', 'styles', ...LIFECYCLE_HOOK_KEYS];
for (const mixin of globalMixins) {
for (const key of Object.keys(mixin)) {
if (!reservedKeys.includes(key)) {
let value = mixin[key];
if (typeof value === 'function') {
value = value.bind(this);
}
if (!(key in this)) {
this[key] = value;
}
this._mixinProps[key] = value;
}
}
}
const isIsolated = this.#contracts.has('isolated');
this.#template = processBindDirectives(template);
this.#bridges = isIsolated ? {} : bridges;
this.#computed = new ComputedRegistry(mergedComputed);
this.#eventBinder = new EventBinder();
// The compiler attaches the closures it generated for this class. Read
// from the constructor rather than passed positionally, because a class
// compiled before expression generation existed simply has neither static
// and gets an evaluator with no table -- which behaves exactly as it did.
this.#evaluator = new DynamicEvaluator({
expressions: this.constructor.__axExprs,
statements: this.constructor.__axStmts,
indexedExpressions: this.constructor.__axProgramExprs,
indexedStatements: this.constructor.__axProgramStmts,
});
this.#lifecycle = new LifecycleManager();
/** @type {AvenxWatcher[]} */
this._watchers = [];
/**
* Owns teardown callbacks created while this component runs its own code
* (lifecycle hooks, actions, event handlers). Bridge subscriptions register
* here and are released in __performTeardown().
* @type {DisposalScope}
*/
this._scope = new DisposalScope(this.constructor.name);
this._stateHandler = new ProxyHandlerFactory({
computedKeys: this.#computed.keys(),
onChange: (key, target) => this.scheduleUpdate(key, target),
// The scope's state layer needs the set of names state binds. Computing
// it is `Object.keys()` over the whole state object, and a scope is built
// per expression evaluated -- so on a component with many state keys it
// was the largest single cost in an update, and it grew with the number
// of keys rather than with the change. Cached, and invalidated here,
// which is the only place the answer can change.
onKeysChanged: () => {
this.#scope.invalidateKeys();
},
// A component's onChange means "schedule a render", so it must not fire
// for a write nothing reads. Without this the per-key dependency graph is
// computed and then discarded: changing a state key no expression
// mentions re-rendered the whole component.
//
// Gated on having rendered at least once. Before the first render no
// expression has been evaluated, so every key would look unobserved and
// nothing would ever schedule.
onlyNotifyObserved: () => {
if (this.#isUnconditional()) return false;
return this.#hasRenderedOnce;
},
instance: this,
getComputedValue: (key) => {
if (this.#evaluating.has(key)) {
logger.warn(formatMessage(AvenxErrorCodes.COMPUTED_CIRCULAR_DEPENDENCY, key), this.$logContext);
return undefined;
}
this.#evaluating.add(key);
const definition = this.#computed.get(key);
try {
const value =
typeof definition === 'function'
? definition.call(this)
: this.#evaluator.evaluateExpression(definition, this.#createScope(), this.state);
if (tracer.on) {
// Reached only when the computed's watcher is dirty, so this is
// already a re-evaluation rather than a cached read. The watcher
// still holds the value it cached before going dirty, which is the
// honest "from" side of the change — and is what makes the first
// change after a recording starts reportable rather than silently
// absorbed as a baseline.
const watcher = this._stateHandler.computedWatchers.get(key);
traceDerived(
this,
{
name: key,
kind: 'computed',
owner: this.constructor.name,
expression: typeof definition === 'string' ? definition : undefined,
contracts: this.#contracts.size > 0 ? Array.from(this.#contracts) : undefined,
},
value,
watcher && watcher.value !== undefined ? { has: true, value: watcher.value } : undefined,
);
}
return value;
} catch (error) {
if (error && error.code === AvenxErrorCodes.STATE_MUTATION_IN_UPDATE) {
throw error;
}
logger.warn(
formatMessage(AvenxErrorCodes.COMPUTED_EVALUTION_FAILED, key, definition, error),
this.$logContext,
);
return undefined;
} finally {
this.#evaluating.delete(key);
}
},
});
const reactiveState = new Proxy(mergedState, this._stateHandler.create());
// Hand-written subclasses initialize state after `super()`; generated
// components pass their initial state directly to this constructor.
let canInitializeState = new.target !== AvenxComponent;
const subclassConstructorFrame = canInitializeState ? `at new ${new.target.name || '<anonymous>'}` : '';
Object.defineProperty(this, 'state', {
configurable: false,
enumerable: true,
get: () => reactiveState,
set: (value) => {
const stack = canInitializeState ? new Error().stack : '';
const isSubclassConstructorAssignment =
typeof stack === 'string' &&
stack.split('\n').some((line) => {
const frame = line.trim();
return frame === subclassConstructorFrame || frame.startsWith(`${subclassConstructorFrame} (`);
});
if (isSubclassConstructorAssignment && value && typeof value === 'object') {
canInitializeState = false;
Object.assign(mergedState, value);
this.#scope.invalidateKeys();
return;
}
throw new AvenxError(AvenxErrorCodes.STATE_DIRECT_REASSIGNMENT);
},
});
Promise.resolve().then(() => {
canInitializeState = false;
});
this._propsHandler = new ProxyHandlerFactory({
onChange: () => this.scheduleUpdate(),
});
this.props = new Proxy(mergedProps, this._propsHandler.create());
this._stylesHandler = new ProxyHandlerFactory({
onChange: () => this.scheduleUpdate(),
});
this.styles = new Proxy(mergedStyles, this._stylesHandler.create());
const actionThis = new Proxy(reactiveState, {
get: (target, key, receiver) => {
if (key === 'state') {
return reactiveState;
}
return Reflect.get(target, key, receiver);
},
set: (target, key, value, receiver) => {
if (key === 'state') {
throw new AvenxError(AvenxErrorCodes.STATE_DIRECT_REASSIGNMENT);
}
return Reflect.set(target, key, value, receiver);
},
});
this.#methods = this.#evaluator.createMethodMap(
mergedMethods,
(executableMethods) => this.#createScope(executableMethods),
() => actionThis,
{
owner: this.constructor.name,
kind: 'action',
contracts: Array.from(this.#contracts),
compiled: this.constructor.__axActions,
...(atomicActions ? { atomic: atomicActions } : {}),
},
);
for (const [name, fn] of Object.entries(this.#methods)) {
if (RESERVED_INSTANCE_METHOD_KEYS.includes(name)) {
logger.warn(
formatMessage(
AvenxErrorCodes.COMPONENT_METHOD_RESERVED_KEY_COLLISION,
name,
this.constructor && this.constructor.name !== 'AvenxComponent' && this.constructor.name !== 'Object'
? this.constructor.name
: 'Component',
),
this.$logContext,
);
}
// SFC transition actions replace the base class's empty hooks, while
// explicit subclass implementations retain their existing precedence.
const isDefaultHook = LIFECYCLE_HOOK_KEYS.includes(name) && this[name] === AvenxComponent.prototype[name];
if (isDefaultHook || !(name in this)) {
this[name] = fn;
}
}
const activeResources = typeof resources === 'object' && resources !== null ? resources : {};
// Ensure $resources object is initialized and available on the instance
this.$resources = this.$resources || {};
for (const [name, resDef] of Object.entries(activeResources)) {
const handler = typeof resDef === 'object' && resDef !== null ? resDef.handler : resDef;
const pollInterval = typeof resDef === 'object' && resDef !== null ? resDef.pollInterval : 0;
let handlerFn = typeof handler === 'function' ? handler : null;
if (!handlerFn) {
const cleanHandler =
typeof handler === 'string' && handler.trim().startsWith('return') ? handler : `return ${handler}`;
handlerFn = this.#evaluator.createMethodMap(
{ [name]: cleanHandler },
() => ({
...this.#createScope(),
setTimeout: typeof setTimeout !== 'undefined' ? setTimeout : undefined,
clearTimeout: typeof clearTimeout !== 'undefined' ? clearTimeout : undefined,
setInterval: typeof setInterval !== 'undefined' ? setInterval : undefined,
clearInterval: typeof clearInterval !== 'undefined' ? clearInterval : undefined,
fetch: typeof fetch !== 'undefined' ? fetch : undefined,
Promise: typeof Promise !== 'undefined' ? Promise : undefined,
}),
() => this.state,
{
owner: this.constructor.name,
kind: 'resource',
contracts: Array.from(this.#contracts),
compiled: this.constructor.__axResources,
},
)[name];
}
const resInstance = new Resource(name, handlerFn, this, { pollInterval });
this.#resources[name] = resInstance;
this.$resources[name] = resInstance; // Expose imperative controls and status accessors
Object.defineProperty(this, name, {
get: () => this.#resources[name].read(),
enumerable: true,
configurable: true,
});
}
// Process declarative watch options from mixins and initialState options
const mergedWatch = {};
for (const mixin of globalMixins) {
if (mixin.watch && typeof mixin.watch === 'object') {
Object.assign(mergedWatch, mixin.watch);
}
}
const optionWatch =
(initialState && typeof initialState === 'object' && initialState.watch && typeof initialState.watch === 'object'
? initialState.watch
: null) ||
(options && typeof options === 'object' && options.watch && typeof options.watch === 'object'
? options.watch
: null);
if (optionWatch) {
Object.assign(mergedWatch, optionWatch);
}
for (const [key, handler] of Object.entries(mergedWatch)) {
if (typeof handler === 'function') {
this.$watch(key, handler);
} else if (typeof handler === 'object' && handler !== null && typeof handler.handler === 'function') {
const { handler: fn, ...watchOpts } = handler;
this.$watch(key, fn, watchOpts);
} else if (typeof handler === 'string' && typeof this[handler] === 'function') {
this.$watch(key, this[handler]);
}
}
/**
* @type {boolean}
* @private
*/
this._isFirstRender = true;
this.#eventExecutor = new EventExecutor((source, event, slotScope) =>
this.#runEventHandler(source, event, slotScope),
);
this.#eventExecutor.validate = (el) => this.$validateElement(el);
if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV !== 'production') {
let initialized = false;
const originalProto = Object.getPrototypeOf(this);
const protoProxy = new Proxy(originalProto, {
getPrototypeOf(target) {
return target;
},
set(target, key, value, receiver) {
if (
initialized &&
typeof key === 'string' &&
!key.startsWith('$') &&
!key.startsWith('_') &&
key !== 'renderWatcher'
) {
const hasKey = key in receiver;
if (!hasKey) {
const compName = receiver.constructor?.name || 'Component';
logger.warn(
formatMessage(AvenxErrorCodes.COMPONENT_NON_REACTIVE_ASSIGNMENT, key, compName),
receiver.$logContext || { componentName: compName },
);
}
}
return Reflect.set(target, key, value, receiver);
},
});
Object.setPrototypeOf(this, protoProxy);
Promise.resolve().then(() => {
initialized = true;
});
}
}
/**
* Evaluates validation rules for an element and updates this.state.$validation.
* @param {Element} el - The element to validate.
* @returns {string[]} Validation errors for the field.
*/
$validateElement(el) {
if (!el || typeof el.getAttribute !== 'function' || !el.hasAttribute('data-ax-validate')) {
return [];
}
const ruleStr = el.getAttribute('data-ax-validate');
const rules = parseValidationRules(ruleStr);
const fieldName = getFieldName(el);
let value = el.value;
if (el.type === 'checkbox') {
value = el.checked;
}
let customMessages = {};
if (el.hasAttribute('data-ax-validate-messages')) {
try {
customMessages = JSON.parse(el.getAttribute('data-ax-validate-messages'));
} catch {
// Ignored
}
}
const errors = validateValue(value, rules, { state: this.state, customMessages });
updateValidationState(this.state, fieldName, errors);
return errors;
}
/**
* Programmatically registers a watcher on a reactive expression/function.
* @param {Function} getter - Evaluation function returning the value to watch.
* @param {Function} callback - Triggered when the value changes.
* @param {object} [options] - Config options.
* @returns {AvenxWatcher}
*/
watch(getter, callback, options = {}) {
const watcher = new AvenxWatcher(getter, callback, { ...options, component: this });
if (this.#isUnmounted) {
watcher.teardown();
return watcher;
}
this._watchers.push(watcher);
return watcher;
}
/**
* Trips a named deadlock boundary inside this component's DOM tree, rendering its fallback template.
* @param {string|null} [boundaryName] - Name of the deadlock boundary (or null for first boundary).
* @param {Error|object} [error] - Error context to pass to fallback template.
*/
$tripDeadlockBoundary(boundaryName = null, error = {}) {
if (!this.#element) return;
const boundaries = this.#deadlockManager.findBoundaries(this.#element);
for (const b of boundaries) {
const name = b.getAttribute('data-ax-deadlock-name');
if (!boundaryName || name === boundaryName) {
this.#deadlockManager.trip(b, error, this.#createScope());
return;
}
}
}
/**
* Trips a specific deadlock boundary container element inside this component.
* @param {Element} container - The deadlock boundary element.
* @param {Error|object} [error] - Error context to pass to fallback template.
*/
__tripBoundaryElement(container, error = {}) {
if (!container) return;
this.#deadlockManager.trip(container, error, this.#createScope());
}
/**
* Forwards an unhandled or propagated error to component error handling.
* @param {Error} error
*/
__handleError(error) {
this.#handleComponentError(error);
}
/**
* Resets a named deadlock boundary inside this component's DOM tree.
* @param {string|null} [boundaryName]
*/
$resetDeadlockBoundary(boundaryName = null) {
if (!this.#element) return;
const boundaries = this.#deadlockManager.findBoundaries(this.#element);
for (const b of boundaries) {
const name = b.getAttribute('data-ax-deadlock-name');
if (!boundaryName || name === boundaryName) {
this.#deadlockManager.reset(b);
return;
}
}
}
/**
* Returns component context metadata for diagnostic logging.
* @returns {{ componentName: string, fileName: string|null, component: AvenxComponent }}
*/
get $logContext() {
return {
componentName:
this.constructor && this.constructor.name !== 'AvenxComponent' && this.constructor.name !== 'Object'
? this.constructor.name
: this.name || 'Component',
fileName: this.__filename || (this.options && this.options.__filename) || null,
component: this,
exprLocations:
(this.options && this.options.exprLocations) ||
(this.constructor && this.constructor.__axExprLocations) ||
null,
template:
this.#template ||
(this.constructor && this.constructor.__template) ||
(this.constructor && this.constructor.__source) ||
null,
source:
(this.constructor && this.constructor.__source) ||
this.#template ||
null,
};
}
/**
* Whether the component is currently mounted in the DOM.
* @returns {boolean}
*/
get $isMounted() {
return this.#isMounted;
}
/**
* Whether the component has been unmounted.
* @returns {boolean}
*/
get $isUnmounted() {
return this.#isUnmounted;
}
/**
* Getter for the component's root element.
* @returns {Element|null}
*/
get $element() {
return this.#element;
}
/**
* Getter for component reference elements marked with data-ax-ref.
* Lazily resolves references if marked dirty.
* @returns {Record<string, Element>}
*/
get $refs() {
if (this.#refsDirty) {
this.#collectRefs();
}
return this.#refsCache;
}
/**
* Slot helpers for checking whether the parent provided content for a slot.
* Available after mount target setup populates `#transcludedGroups`.
* @returns {object}
*/
get $slots() {
const groups = this.#transcludedGroups;
return {
/**
* @param {string} [slotName] Named slot, or `default` / empty for the default slot.
* @returns {boolean}
*/
has(slotName = 'default') {
if (!groups) return false;
const name = !slotName || slotName === 'default' ? null : slotName;
if (!name) {
return Array.isArray(groups.default) && groups.default.length > 0;
}
const nodes = groups.named?.[name];
return Array.isArray(nodes) && nodes.length > 0;
},
};
}
/**
* Returns a diagnostic snapshot of the component for runtime debugging.
* Props and state are sanitized clones (safe to log, serialize, or diff);
* `element` is intentionally the live root element so it stays inspectable
* in browser devtools. Computed properties are listed by key only, so
* inspecting never evaluates them.
* @returns {{ componentName: string, props: object, state: object, computed: string[], slots: string[], element: Element|null }}
*/
$inspect() {
const groups = this.#transcludedGroups;
const slots = [
...(Array.isArray(groups?.default) && groups.default.length > 0 ? ['default'] : []),
...Object.keys(groups?.named || {}),
];
// Serialize the raw targets: enumerating the reactive proxies would
// evaluate computed properties as a side effect.
return {
componentName: this.$logContext.componentName,
props: serializeSafe(toRaw(this.props)),
state: serializeSafe(toRaw(this.state)),
computed: this.#computed.keys(),
slots,
element: this.$element,
};
}
/**
* KeepAlive invalidation API for clearing cached components.
* @returns {object}
*/
get $keepAlive() {
return {
clear: (componentName) => {
if (this.$app && typeof this.$app.clearKeepAliveCache === 'function') {
return this.$app.clearKeepAliveCache(componentName);
}
return false;
},
};
}
/**
* Helper method to clear cached KeepAlive component instances.
* @param {string} [pageName] - Optional component or page name to clear from cache.
* @returns {boolean} True if cache entries were evicted, false otherwise.
*/
clearKeepAliveCache(pageName) {
if (this.$app && typeof this.$app.clearKeepAliveCache === 'function') {
return this.$app.clearKeepAliveCache(pageName);
}
return false;
}
/**
* Emits a custom event up to parent components with unified bubble options.
* @param {string} eventName - Name of the event to emit.
* @param {object} [detail] - Event details payload.
* @param {object} [options] - Optional custom event options.
*/
emit(eventName, detail = {}, options = {}) {
if (typeof CustomEvent === 'undefined') {
return;
}
const event = new CustomEvent(eventName, {
detail,
bubbles: options.bubbles !== undefined ? options.bubbles : true,
cancelable: options.cancelable !== undefined ? options.cancelable : true,
...options,
});
if (this.$element) {
this.$element.dispatchEvent(event);
}
}
/**
* Emits a custom event to the parent component.
* @param {string} eventName - Name of the event to emit.
* @param {object} [detail] - Event details.
*/
$emit(eventName, detail = {}) {
this.emit(eventName, detail, { composed: true });
}
/**
* Reactively listens to changes in specific state values or getters.
* @param {string|Function|Array<string|Function>} source - State property key string, getter function, or array of sources.
* @param {Function} callback - Triggered when the value changes.
* @param {object} [options] - Config options.
* @param {boolean} [options.immediate] - Run callback immediately on watcher creation.
* @param {boolean} [options.deep] - Deeply watch nested properties.
* @returns {AvenxWatcher}
*/
$watch(source, callback, options = {}) {
const resolveSource = (src) => {
if (typeof src === 'string') {
return () => {
const segments = src.split('.');
let val = this.state;
for (const seg of segments) {
if (val === null || val === undefined) return undefined;
val = val[seg];
}
return val;
};
} else if (typeof src === 'function') {
return () => src.call(this);
} else {
throw new Error('source element must be a string or a function');
}
};
let getter;
if (Array.isArray(source)) {
getter = source.map((src) => resolveSource(src));
} else if (typeof source === 'string' || typeof source === 'function') {
getter = resolveSource(source);
} else {
throw new Error('source must be a string, function, or array of sources');
}
const watcher = new AvenxWatcher(getter, callback, { ...options, component: this });
if (this.#isUnmounted) {
watcher.teardown();
return watcher;
}
this._watchers.push(watcher);
return watcher;
}
/**
* Reactively runs an immediate effect hook that automatically tracks dependencies and re-runs on state mutation.
* Automatically registers the watcher in this._watchers and tears it down when the component unmounts.
* @param {Function} effect - Effect function to run immediately and track.
* @param {object} [options] - Config options.
* @returns {Function} Stop handle function () => watcher.teardown().
*/
$watchEffect(effect, options = {}) {
if (typeof effect !== 'function') {
throw new Error('effect must be a function');
}
const getter = () => effect.call(this);
const watcher = new AvenxWatcher(getter, null, options);
if (this.#isUnmounted) {
watcher.teardown();
const stop = () => watcher.teardown();
stop.watcher = watcher;
return stop;
}
this._watchers.push(watcher);
const stop = () => {
watcher.teardown();
const idx = this._watchers.indexOf(watcher);
if (idx !== -1) {
this._watchers.splice(idx, 1);
}
};
stop.watcher = watcher;
return stop;
}
/**
* Creates a scope object for expression evaluation.
* @param {object} [methods] - Methods to include in the scope.
* @param {object} [extras] - Additional variables to include.
* @returns {object} The combined scope.
* @private
*/
#createScope(methods = this.#methods, extras = null) {
return this.#scope.resolve(methods, extras && Object.keys(extras).length > 0 ? extras : null);
}
/**
* The names the component's computed values bind.
*
* Read by {@link ComponentScope}; a component's computed registry is private
* and the scope has no business reaching into it.
* @returns {string[]} Computed names.
*/
__computedKeys() {
return this.#computed.keys();
}
/**
* The component's executable actions.
* @returns {object} The action map.
*/
__methods() {
return this.#methods;
}
/**
* Whether the component declared the `isolated` contract.
* @returns {boolean} True when bridges are kept out of scope.
*/
__isIsolated() {
return this.#contracts.has('isolated');
}
/**
* The bridges this component can see.
* @returns {object} Bridges by name.
*/
__bridgeValues() {
return this.#bridges;
}
/**
* Whether the component's module bound any imports.
* @returns {boolean} True when there are imports in scope.
*/
__hasImports() {
return this.#hasImports;
}
/**
* The values the component's module imported.
* @returns {object} Imported values by local name.
*/
__importValues() {
return this.#imports;
}
/**
* The names of the component's declared resources.
* @returns {string[]} Resource names.
*/
__resourceNames() {
return this.#resources ? Object.keys(this.#resources) : [];
}
/**
* Reads a resource, suspending if it is still in flight.
* @param {string} name - The resource name.
* @returns {any} The resource's value.
*/
__readResource(name) {
return this.#resources[name].read();
}
/**
* Resolves an expression within the template.
* @param {string} expression - The expression to evaluate.
* @param {object} [extraScope] - Additional scope variables.
* @returns {any} The result of the evaluation.
* @private
*/
#resolveTemplateExpression(expression, extraScope = {}) {
return this.#evaluator.evaluateExpression(expression, this.#createScope(this.#methods, extraScope), this.state);
}
/**
* Evaluates one of the program's expressions by index.
*
* The scope is built the same way every other template expression's is, so a
* compiled binding sees the same names, the same bridges and the same tracer
* substitution point. Only the addressing changed.
* @param {number} index - The expression index the op carries.
* @param {object|null} [locals] - A block's local bindings, such as a loop item.
* @returns {any} The value.
* @private
*/
#evaluateProgram(index, locals = null) {
const scope = this.#createScope(this.#methods, locals || undefined);
// MIGRATION: a program emitted by the pre-IR compiler carries expression
// *source* on its ops rather than an index. Both shapes are executed here
// while the two compiler paths coexist. Remove this branch with the legacy
// renderer -- see lib/compiler/render/compileTemplate.js.
if (typeof index === 'string') {
return this.#evaluator.evaluateExpression(index, scope, this.state);
}
return this.#evaluator.evaluateIndexed(index, scope, this.state);
}
/**
* Observes the promise an action or hook returned, if it returned one.
*
* An action that fails asynchronously used to report to nobody: the promise
* it returned flowed back up through the dispatcher and was discarded, so
* the rejection escaped as an unhandled promise rejection -- no diagnostic,
* no logger entry, and the app's errorHandler was never called. A rejection
* is now routed through the same reporting a synchronous throw takes: the
* diagnostic for the dispatch path, then #reportError, which reaches
* onErrorCaptured hooks and the app error handler.
*
* The ORIGINAL promise is returned, not the one the handler creates, so a
* caller that awaited the dispatch still sees the rejection. Attaching the
* handler marks the promise handled, so a discarded rejection no longer
* escapes as an unhandled rejection. Reporting itself is guarded: a throw
* inside this handler would create a second, unhandled rejection.
* @param {any} result - Whatever the action or hook returned.
* @param {string} code - The diagnostic code (AVX_R09 for a handler, AVX_R12 for a hook).
* @param {any[]} messageArgs - The diagnostic's message arguments, before the error.
* @param {string} origin - The statement or hook name, for #reportError.
* @returns {any} The result, unchanged.
* @private
*/
#observeAsyncFailure(result, code, messageArgs, origin) {
if (result && typeof result.then === 'function') {
result.then(undefined, (error) => {
try {
logger.error(formatMessage(code, ...messageArgs, error), this.$logContext);
this.#reportError(error, origin, true);
} catch {
// Reporting must never turn one failure into a second, unhandled one.
}
});
}
return result;
}
/**
* Runs one of the program's event handlers by index.
* @param {number} index - The statement index the op carries.
* @param {Event} event - The DOM event.
* @param {object|null} [locals] - A block's local bindings.
* @returns {any} Whatever the handler returned.
* @private
*/
#runProgramStatement(index, event, locals = null) {
// A DOM event is the one thing in an Avenx application that genuinely
// starts a causal chain, so it opens the outermost trace node -- the same
// node EventExecutor opens for the string path, built by the same
// function, so a trace does not read differently depending on which
// renderer produced it.
//
// Everything replay needs (the event type, the target selector, a typed
// value, a checked flag, a key) comes from the event. Only the `handler`
// label comes from the source, which a development build supplies through
// __axProgramStmtSrc and a production build does not carry.
const label = this.constructor.__axProgramStmtSrc?.[index] ?? `handler #${index}`;
try {
const token = tracer.on ? tracer.enter(TraceNodeType.EVENT, buildEventNode(label, event)) : -1;
try {
// Subscriptions opened by a handler belong to this component, so the
// handler runs inside the component's disposal scope -- the same rule
// the string path's handler follows.
return this.#observeAsyncFailure(
runInScope(this._scope, () =>
this.#evaluator.executeIndexed(
index,
this.#createScope(this.#methods, { event, ...(locals || {}) }),
this.state,
),
),
AvenxErrorCodes.EVENT_HANDLER_ERROR,
[label],
label,
);
} finally {
if (token >= 0) {
tracer.leave(token);
}
}
} catch (error) {
logger.error(formatMessage(AvenxErrorCodes.EVENT_HANDLER_ERROR, label, error), this.$logContext);
this.#reportError(error, label, true);
return undefined;
}
}
/**
* Runs an event handler.
*
* The handler arrives as source. It used to be able to arrive as a function
* too -- `EventExecutor` pre-compiled every handler with `new Function` --
* and that branch ran the closure against `AvenxSandbox.createProxy`, the
* source-text sandbox the AST evaluator replaced. Removing the branch closes
* the last route from a template to that sandbox: every inline handler now
* goes through `executeStatement`, which parses first and only reaches for
* `new Function` when the body is genuinely a statement.
* @param {string} source - The handler body, as written in the template.
* @param {Event} event - The event object.
* @param {object|null} [slotScope] - Optional slot scope variables.
* @returns {any} The result of the execution.
* @private
*/
#runEventHandler(source, event, slotScope = null) {
try {
// Subscriptions opened by a handler belong to this component, so the
// handler runs inside the component's disposal scope.
return this.#observeAsyncFailure(
runInScope(this._scope, () =>
this.#evaluator.executeStatement(source, this.#createScope(this.#methods, { event, ...slotScope }), this.state),
),
AvenxErrorCodes.EVENT_HANDLER_ERROR,
[source],
source,
);
} catch (error) {
logger.error(formatMessage(AvenxErrorCodes.EVENT_HANDLER_ERROR, source, error), this.$logContext);
this.#reportError(error, source, true);
return undefined;
}
}
/**
* The compiled template this component renders.
*
* An internal seam, in the same family as `__setMountTarget`. Benchmarks and
* renderer tests need the exact string the compiler produced, and reaching it
* by recompiling the source would measure a reconstruction rather than what
* the component actually holds.
* @returns {string} The template source.
*/
__getTemplate() {
return this.#template;
}
/**
* Evaluates one template expression against this component's scope.
*
* Exposed for renderer benchmarks and tests, which need to price expression
* evaluation on its own rather than inferring it from a whole update.
* @param {string} expression - The expression source.
* @param {object} [extraScope] - Additional scope bindings.
* @returns {any} The value.
*/
__evaluate(expression, extraScope = {}) {
return this.#resolveTemplateExpression(expression, extraScope);
}
/**
* Builds one evaluation scope, without evaluating anything in it.
*
* Scope construction used to happen once per interpolation per render, which
* made it a hot path nobody could see. It is measurable from here.
* @returns {object} A fresh scope.
*/
__buildScope() {
return this.#createScope();
}
/**
* Renders the component template with current state.
* @returns {string} The rendered HTML string.
*/
render() {
const enableProfiling = !!(
this.$app?.enableProfiling ||
(typeof window !== 'undefined' && window.__avenx_enable_profiling)
);
return profile(enableProfiling, this.constructor.name, 'render', () => {
return this.#renderer.render(
this.#template,
(expression) => this.#resolveTemplateExpression(expression),
this.$logContext,
);
});
}
/**
* The string renderer and its satellites, built on first use.
*
* A component with a render program never touches any of them, and in a
* compiled application most components have one. Constructing five objects
* per instance -- one of which allocates a 500-entry LRU cache -- to serve a
* path that will not run is the kind of cost that is invisible per component
* and material per page.
*
* Exposed as getters under the original names, so every call site reads the
* same as it did and only the moment of construction moved.
* @returns {TemplateRenderer} The template renderer.
*/
get #renderer() {
if (!this.#rendererInstance) {
this.#rendererInstance = new (requireStringRenderer(this.constructor.name, this.#skeletonFailure).TemplateRenderer)({
logContext: this.$logContext,
});
}
return this.#rendererInstance;
}
/**
* @returns {DomPatcher} The DOM patcher.
*/
get #patcher() {
if (!this.#patcherInstance) {
this.#patcherInstance = new (requireStringRenderer(this.constructor.name, this.#skeletonFailure).DomPatcher)({
logContext: this.$logContext,
component: this,
});
}
return this.#patcherInstance;
}
/**
* @returns {ListManager} The list manager.
*/
get #listManager() {
if (!this.#listManagerInstance) {
this.#listManagerInstance = new (requireStringRenderer(this.constructor.name, this.#skeletonFailure).ListManager)(
this.#evaluator,
this.#renderer,
this.#eventBinder,
this.constructor.name,
{
logContext: this.$logContext,
component: this,
},
);
}
return this.#listManagerInstance;
}
/**
* @returns {DeferManager} The defer manager.
*/
get #deferManager() {
if (!this.#deferManagerInstance) {
this.#deferManagerInstance = new (requireStringRenderer(this.constructor.name, this.#skeletonFailure).DeferManager)(
this.#evaluator,
this.#renderer,
this.#eventBinder,
this.constructor.name,
);
}
return this.#deferManagerInstance;
}
/**
* @returns {DeadlockManager} The deadlock manager.
*/
get __deadlockManager() {
return this.#deadlockManager;
}
/**
* @returns {DeadlockManager} The deadlock manager.
*/
get #deadlockManager() {
if (!this.#deadlockManagerInstance) {
let renderer = null;
try {
renderer = this.#renderer;
} catch {
// String renderer may not be installed in headless environments.
}
this.#deadlockManagerInstance = new DeadlockManager(
this.#evaluator,
renderer,
this.#eventBinder,
this.constructor.name,
);
}
return this.#deadlockManagerInstance;
}
/**
* Renders the component.
*
* On the compiled path this builds the DOM once and hands ownership to the
* per-binding effects; afterwards it is only reached when something outside
* the reactive graph asks for a re-read. On the string path it evaluates the
* render watcher, which re-renders and re-patches the whole template.
*/
update() {
if (this.#program) {
this.#renderProgram();
return;
}
if (!this.renderWatcher) {
this.renderWatcher = new AvenxWatcher(
() => this.runUpdate(),
() => this.scheduleUpdate(),
{ lazy: true, name: `${this.constructor.name}#render` },
);
}
this.renderWatcher.evaluate();
}
/**
* Whether this component renders through a compiled program.
*
* Exposed for tests and diagnostics: "did this component take the fast path"
* is otherwise unanswerable from outside, and a performance property nobody
* can observe is a performance property nobody can defend.
* @returns {boolean} True when a render program is driving the DOM.
*/
get $compiled() {
return this.#program !== null;
}
/**
* Renders through the compiled program.
*
* On the first call this builds the DOM from the program's skeleton and
* creates one reactive effect per binding. After that the effects own the
* DOM: a state write wakes the bindings that read it and nothing else, and
* this method is only reached again when something *outside* the reactive
* graph asks for a re-read -- a settled resource, a forced update.
* @private
*/
#renderProgram() {
if (!this.#element) return;
if (this.#componentError) {
this.#handleComponentError(this.#componentError);
return;
}
this.#isUpdating = true;
try {
if (this.#templateInstance) {
if (this.#isMounted) {
this.#triggerLifecycle('onBeforeUpdate');
}
this.#templateInstance.refresh();
this.#afterProgramRender();
return;
}
const instance = new TemplateInstance(this.#program, {
program: this.#program,
app: this.$app,
component: this,
evaluate: (index, locals) => this.#evaluateProgram(index, locals),
runStatement: (index, event, locals) => this.#runProgramStatement(index, event, locals),
describeExpression: (index) => this.constructor.__axProgramExprSrc?.[index],
onSuspend: (promise) => this.#suspend(promise),
jobId: this.uid,
onRendered: () => this.#scheduleProgramPostRender(),
onChildProps: () => this.__onChildPropsChanged(),
onBeforeRender: () => this.#notifyProgramBeforeRender(),
});
if (!instance.usable) {
this.#skeletonFailure = instance.failureReason;
// The skeleton could not be prepared in this environment -- a DOM
// without <template>, or a parser that reshaped the tree past the
// compiler's markers. Drop to the string renderer permanently rather
// than binding against a tree that does not match the program.
logger.warn(
formatMessage(
AvenxErrorCodes.TEMPLATE_RENDER_ERROR,
'compiled template',
'compiled template could not be prepared; falling back to the string renderer',
this.constructor.name,
'',
),
this.$logContext,
);
this.#program = null;
this.#isUpdating = false;
this.update();
return;
}
if (this.#isMounted) {
this.#triggerLifecycle('onBeforeUpdate');
}
// Bindings run while the fragment is still detached, so the document
// never sees the skeleton with its values missing.
const fragment = instance.create();
this.#templateInstance = instance;
this.#element.innerHTML = '';
this.#element.appendChild(fragment);
// A `<select value="a">` written literally in the template is never
// touched by an op, and the HTML parser does not apply a `value`
// attribute to a select. Once, on creation, is enough.
this.#syncSelectElements();
// Slots compile now, so the compiled path has to transclude too. The
// fallback children are already in the tree at this point -- they came
// out of the skeleton -- so they are captured here, before `#fillSlots`
// empties the outlet to insert what the parent passed down. The string
// path recovers them by re-rendering the template and parsing the result;
// a compiled component has the nodes in hand and needs neither.
this.#captureSlotFallbacks();
this.#fillSlots();
// Set once rather than per update. `data-ax-ref` makes a template refuse
// to compile, so a compiled component has no refs to find -- but `$refs`
// collects lazily and this keeps the flag honest for anything that reads
// it, at the cost of one scan the first time somebody does.
this.#refsDirty = true;
// Events are delegated from this element and read `data-ax-event` off the
// DOM when one fires, so binding once at mount covers every handler the
// template declares. The string path re-binds on every update because it
// replaces nodes; a program never does.
this.#eventBinder.bind(this.#element, this.#eventExecutor);
this.#hasRenderedOnce = true;
this.#afterProgramRender();
} catch (error) {
if (error instanceof Promise) {
this.#suspend(error);
return;
}
if (error && error.code === AvenxErrorCodes.STATE_MUTATION_IN_UPDATE) {
throw error;
}
this.#handleComponentError(error);
} finally {
this.#isUpdating = false;
}
}
/**
* Runs the bookkeeping that follows any render on the program path.
* @private
*/
#afterProgramRender() {
this.#beforeRenderFired = false;
// Deliberately narrower than the string path's equivalent, because the
// compiler has already ruled several things out.
//
// `#validateFormElements` and `#collectRefs` each run a querySelectorAll
// over the whole component subtree. On the string path that is one scan per
// render and the render was already O(template). Here it would be the only
// O(template) work left in an otherwise O(1) update -- and it would find
// nothing, because `data-ax-validate` and `data-ax-ref` both make a
// template refuse to compile. A component reaching this method cannot
// contain either.
//
// `<select value>` is likewise handled at the point of the write:
// `syncValueProperty` sets the property alongside the attribute, so there
// is nothing left to re-sync afterwards. The one case it does not cover --
// a *static* `value` on a select, which no op ever applies -- is synced
// once when the tree is created, not on every update.
if (this.#isMounted && typeof CustomEvent !== 'undefined' && this.#element?.dispatchEvent) {
this.#element.dispatchEvent(new CustomEvent('avenx:update'));
}
if (this.#isMounted) {
this.#triggerLifecycle('onUpdate');
}
this.__notifyInjectingChildren();
}
/**
* Called when a compiled prop for a child component changed value.
*
* A component does not own mount points -- {@link AvenxPage} does, for its
* whole subtree -- but a component's template can still carry them, and when
* its own props change it re-renders and writes new values onto its
* children's host elements. Discarding the notification here meant nothing
* reconciled those values onto the child *instances*, so a prop stopped
* propagating one level below the page:
*
* page -> Lvl1 (props updated) -> Lvl2 (host updated, instance stale)
*
* Every level below that kept its first value for the life of the page. The
* notification is therefore passed to whoever owns the mount points, which is
* the page at the top of `$parent`. The page coalesces it to one pass per
* flush, so a chain converges a level per flush rather than re-entering here.
* @returns {void}
*/
__onChildPropsChanged() {
const parent = this.$parent;
if (parent && typeof parent.__onChildPropsChanged === 'function') {
parent.__onChildPropsChanged();
}
}
/**
* Fires `onBeforeUpdate` once, before the first binding of a flush applies.
*
* On the string path there was one render per update, so the hook had an
* obvious place to sit. With per-binding effects there is no single render,
* and a component with 500 bindings must not fire the hook 500 times. The
* flag is cleared by the post-render callback, which runs after every job in
* the flush has drained.
* @private
*/
#notifyProgramBeforeRender() {
if (this.#beforeRenderFired || !this.#isMounted || this.#isUnmounted) return;
this.#beforeRenderFired = true;
this.#triggerLifecycle('onBeforeUpdate');
}
/**
* Queues the once-per-flush notification for a fine-grained update.
*
* Individual bindings write to the DOM independently, so there is no single
* moment that is "the update" any more. `onUpdate`, the `avenx:update` event
* and ref resolution still have to happen exactly once per flush, or a
* component with many bindings would fire them many times per tick and every
* lifecycle test in every application would start failing.
* @private
*/
#scheduleProgramPostRender() {
if (this.#postRenderQueued || this.#isUnmounted) return;
this.#postRenderQueued = true;
queueFlushCallback(() => {
this.#postRenderQueued = false;
if (this.#isUnmounted || !this.#element) {
this.#beforeRenderFired = false;
return;
}
this.#afterProgramRender();
});
}
/**
* Performs the actual update/render of the component.
*/
runUpdate() {
if (!this.#element) return;
if (this.#componentError) {
this.#handleComponentError(this.#componentError);
return;
}
this.#isUpdating = true;
try {
if (this.#isMounted) {
this.#triggerLifecycle('onBeforeUpdate');
}
this.__updateProvidedState();
this.#patcher.patch(
this.#element,
this.render(),
(expression, slotScope) => this.#resolveTemplateExpression(expression, slotScope),
this.$app,
);
// Fill slots with transcluded content.
this.#fillSlots();
this.#listManager.process(this.#element, this.#createScope(), this.state, this.$app);
this.#deferManager.process(this.#element, this.#createScope(), this.state, this.$app);
this.#eventBinder.bind(this.#element, this.#eventExecutor);
this.#refsDirty = true;
this.#syncSelectElements();
if (this.#isMounted && typeof CustomEvent !== 'undefined' && this.#element?.dispatchEvent) {
this.#element.dispatchEvent(new CustomEvent('avenx:update'));
}
if (this.#isMounted) {
this.#resolveRefs();
this.#triggerLifecycle('onUpdate');
}
this.__notifyInjectingChildren();
// Only a render that ran under the render watcher collected
// dependencies. runUpdate() can also be called directly, and after such
// a call the dependency set says nothing about what this component
// observes -- so filtering must stay off until a tracked render happens.
if (activeWatcher && activeWatcher === this.renderWatcher) {
this.#hasRenderedOnce = true;
}
} catch (error) {
if (error instanceof Promise) {
this.#suspend(error);
return;
}
if (error && error.code === AvenxErrorCodes.STATE_MUTATION_IN_UPDATE) {
throw error;
}
this.#handleComponentError(error);
} finally {
this.#isUpdating = false;
this.#validateFormElements();
}
}
/**
* Validates all form input elements in the component that have data-ax-validate.
* @private
*/
#validateFormElements() {
if (!this.$element || typeof this.$element.querySelectorAll !== 'function') return;
const elements = Array.from(this.$element.querySelectorAll('[data-ax-validate]'));
if (this.$element.hasAttribute && this.$element.hasAttribute('data-ax-validate')) {
elements.unshift(this.$element);
}
for (const el of elements) {
this.$validateElement(el);
}
}
/**
* Executes a callback (or resolves a Promise) after the current reactive
* update cycle has finished flushing pending DOM updates.
* @param {Function} [callback] - Optional callback to run after the flush.
* @returns {Promise<void>|void} A promise resolving after the flush, if no callback was given.
*/
$nextTick(callback) {
return schedulerNextTick(callback);
}
/**
* Alias for {@link AvenxComponent#$nextTick}.
* @param {Function} [callback] - Optional callback to run after the flush.
* @returns {Promise<void>|void}
*/
nextTick(callback) {
return this.$nextTick(callback);
}
/**
* Schedules an update to run asynchronously in a microtask.
* @param {string|symbol|Array<string|symbol>} [key] - Mutated property key.
* @param {object} [target] - Target object that changed.
*/
scheduleUpdate(key, target) {
if (this.#isUpdating) {
throw new AvenxError(AvenxErrorCodes.STATE_MUTATION_IN_UPDATE);
}
if (this.#shouldSkipUpdate(key, target)) {
return;
}
if (this.renderWatcher) {
this.renderWatcher.dirty = true;
}
if (this.#isBeforeMounting) {
return;
}
// On the program path there is no component-level render to schedule. The
// write that reached here has already woken the bindings that read it,
// through the same dependency graph this call was about to bypass, and
// queueing a whole-component update on top would undo the change: every
// write would re-evaluate every binding, which is what the string renderer
// did. The lifecycle notification is still owed, and is queued instead.
if (this.#templateInstance) {
this.#scheduleProgramPostRender();
return;
}
if (this.#updateQueued) return;
this.#updateQueued = true;
queueJob(this.#updateJob);
}
/**
* Whether this component unconditionally renders on any state mutation.
* @returns {boolean}
* @private
*/
#isUnconditional() {
return (
this.#contracts.has('unconditional') ||
this.#contracts.has('always-render') ||
Boolean(this.options?.unconditional) ||
Boolean(this.options?.alwaysRender) ||
this.#templateDeps === null
);
}
/**
* Determines whether an update should be skipped because the mutated key
* touches no dependency of the template or rendered computed properties.
* @param {string|symbol|Array<string|symbol>} [key] - Mutated property key.
* @param {object} [target] - Target object that changed.
* @returns {boolean} True if the update should be skipped.
* @private
*/
#shouldSkipUpdate(key, target) {
if (!this.#hasRenderedOnce) {
return false;
}
if (this.#isUnconditional()) {
return false;
}
if (key === undefined || key === null) {
return false;
}
const rawState = toRaw(this.state);
const keys = Array.isArray(key) ? key : [key];
let isRelevant = false;
for (const k of keys) {
if (typeof k === 'symbol') {
return false;
}
let rootKey = String(k);
if (target && target !== rawState) {
const propPath = getPropertyPath(target, k);
if (propPath) {
rootKey = propPath.split('.')[0];
}
}
if (this.#isKeyTemplateRelevant(rootKey)) {
isRelevant = true;
break;
}
}
if (!isRelevant) {
if (isDebugReactivityEnabled()) {
const rootKeyDesc = keys.map((k) => String(k)).join(', ');
console.log(
`[Avenx Debug] Skipped render for component "${this.constructor.name}" on unobserved key "${rootKeyDesc}"`
);
}
return true;
}
return false;
}
/**
* Checks whether a given state root key is relevant to the template
* (referenced directly or via a computed property rendered by the template).
* @param {string} rootKey - Root property key on state.
* @returns {boolean}
* @private
*/
#isKeyTemplateRelevant(rootKey) {
if (this.#templateDeps instanceof Set) {
if (this.#templateDeps.has(rootKey) || this.#templateDeps.has('state')) {
return true;
}
for (const compKey of this.#templateDeps) {
if (this.#computed.has(compKey) && this.#computedDependsOn(compKey, rootKey)) {
return true;
}
}
return false;
}
if (this.renderWatcher?.deps) {
for (const dep of this.renderWatcher.deps.values()) {
const depRoot = getPropertyPath(dep.target, dep.key).split('.')[0];
if (depRoot === rootKey) {
return true;
}
}
}
if (this.#templateInstance?.bindings) {
for (const binding of this.#templateInstance.bindings) {
if (binding.watcher?.deps) {
for (const dep of binding.watcher.deps.values()) {
const depRoot = getPropertyPath(dep.target, dep.key).split('.')[0];
if (depRoot === rootKey) {
return true;
}
}
}
}
}
for (const compKey of this.#computed.keys()) {
if (this.#computedDependsOn(compKey, rootKey)) {
if (this.#isComputedObservedByTemplate(compKey)) {
return true;
}
}
}
return false;
}
/**
* Checks whether a computed property depends on rootKey.
* @param {string} compKey
* @param {string} rootKey
* @param {Set<string>} [visited]
* @returns {boolean}
* @private
*/
#computedDependsOn(compKey, rootKey, visited = new Set()) {
if (visited.has(compKey)) return false;
visited.add(compKey);
const watcher = this._stateHandler?.computedWatchers?.get(compKey);
if (watcher?.deps) {
for (const dep of watcher.deps.values()) {
const depRoot = getPropertyPath(dep.target, dep.key).split('.')[0];
if (depRoot === rootKey) return true;
if (this.#computed.has(depRoot) && this.#computedDependsOn(depRoot, rootKey, visited)) {
return true;
}
}
}
const def = this.#computed.get(compKey);
if (typeof def === 'string') {
const ids = this.#extractIdentifiers(def);
if (ids.has(rootKey)) return true;
for (const id of ids) {
if (this.#computed.has(id) && this.#computedDependsOn(id, rootKey, visited)) {
return true;
}
}
}
return false;
}
/**
* Checks if a computed property is observed by the template.
* @param {string} compKey
* @returns {boolean}
* @private
*/
#isComputedObservedByTemplate(compKey) {
if (this.#templateDeps instanceof Set) {
return this.#templateDeps.has(compKey);
}
const rawState = toRaw(this.state);
const keysMap = depMap.get(rawState);
const watchers = keysMap?.get(compKey);
if (watchers) {
if (this.renderWatcher && watchers.has(this.renderWatcher)) return true;
if (this.#templateInstance?.bindings) {
for (const binding of this.#templateInstance.bindings) {
if (binding.watcher && watchers.has(binding.watcher)) return true;
}
}
}
return false;
}
/**
* Extracts template dependencies from template source string for uncompiled components.
* Returns null if dynamic/defeating constructs are detected.
* @param {string} template
* @returns {Set<string>|null}
* @private
*/
#extractTemplateDeps(template) {
if (typeof template !== 'string' || !template.trim()) {
return new Set();
}
if (
/:\[[^\]]+\]/.test(template) ||
/data-ax-html\s*=\s*["'][^"']+["']/.test(template) ||
/state\s*\[/.test(template)
) {
return null;
}
const deps = new Set();
const interpRegex = /\{\{([\s\S]*?)\}\}/g;
let match;
while ((match = interpRegex.exec(template)) !== null) {
const ids = this.#extractIdentifiers(match[1]);
for (const id of ids) deps.add(id);
}
const dirRegex = /:([a-zA-Z0-9_-]+)="([^"]*)"/g;
while ((match = dirRegex.exec(template)) !== null) {
const ids = this.#extractIdentifiers(match[2]);
for (const id of ids) deps.add(id);
}
return deps;
}
/**
* Extracts root identifiers from an expression string.
* @param {string} code
* @returns {Set<string>}
* @private
*/
#extractIdentifiers(code) {
const ids = new Set();
if (typeof code !== 'string') return ids;
const regex = /\b([A-Za-z_$][\w$]*)\b/g;
let match;
while ((match = regex.exec(code)) !== null) {
const id = match[1];
if (!TEMPLATE_EXCLUDED_IDENTIFIERS.has(id)) {
ids.add(id);
}
}
const statePropRegex = /state\.([A-Za-z_$][\w$]*)/g;
while ((match = statePropRegex.exec(code)) !== null) {
ids.add(match[1]);
}
return ids;
}
/**
* Internal method to set the mount target.
* @param {Element} target - The target element.
* @param {boolean} [isRestore] - Whether the component is being restored from keep-alive.
* @private
*/
__setMountTarget(target, isRestore = false) {
this.#element = target;
this.#isUnmounted = false;
// A component instance may be mounted again after teardown. Its disposal
// scope is single-use, so give the new lifetime a fresh one.
if (this._scope && this._scope.disposed) {
this._scope = new DisposalScope(this.constructor.name);
}
if (target) {
target.__avenx_comp_instance = this;
this.__initProvide();
this.__initInjection();
if (isRestore) {
return;
}
const children = Array.from(target.childNodes);
this.#transcludedGroups = {
default: [],
named: {},
};
children.forEach((child) => {
if (child.nodeType === 1 && child.hasAttribute('slot')) {
const name = child.getAttribute('slot');
if (!this.#transcludedGroups.named[name]) {
this.#transcludedGroups.named[name] = [];
}
this.#transcludedGroups.named[name].push(child);
} else {
this.#transcludedGroups.default.push(child);
}
});
target.innerHTML = '';
}
}
/**
* Resolves the current name of a slot element.
* Dynamic slot names are evaluated during template rendering, so the
* rendered name attribute contains the value used for transclusion.
* @param {Element} slotEl - The slot element.
* @returns {string|null} The resolved slot name.
* @private
*/
#resolveSlotName(slotEl) {
const name = slotEl.getAttribute('name');
return name && name.trim() ? name.trim() : null;
}
/**
* Records each slot's declared fallback children before anything fills it.
*
* Called once, from the compiled render path, while the skeleton's own
* children are still in the outlet. After `#fillSlots` has run, the outlet
* holds whatever the parent projected and the fallback is unrecoverable from
* the DOM -- which is why the string path has to re-render the template and
* parse the result to find it again.
* @private
*/
#captureSlotFallbacks() {
if (!this.#element) return;
for (const slotEl of this.#getOwnSlots()) {
if (slotEl.__avenxFallback) continue;
slotEl.__avenxFallback = Array.from(slotEl.childNodes).map((child) => child.cloneNode(true));
}
}
/**
* Retrieves the fallback children declared for a slot.
* @param {string|null} name - The name of the slot.
* @returns {Node[]} Cloned child nodes.
* @private
*/
#getDefaultSlotChildren(name) {
// A compiled component captured its fallbacks from the skeleton at mount,
// so the answer is already a list of nodes. The round trip below exists
// only for the string path, which has no other record of them.
const captured = this.#getOwnSlots().find((slotEl) => {
const slotName = this.#resolveSlotName(slotEl);
return (name ? slotName === name : !slotName) && slotEl.__avenxFallback;
});
if (captured) {
return captured.__avenxFallback.map((child) => child.cloneNode(true));
}
try {
const parser = new DOMParser();
const doc = parser.parseFromString(this.render(), 'text/html');
const rootDoc = doc.body || doc;
const defaultSlot = Array.from(rootDoc.querySelectorAll('slot')).find((s) => {
const sName = this.#resolveSlotName(s);
return name ? sName === name : !sName;
});
if (defaultSlot) {
return Array.from(defaultSlot.childNodes).map((child) => child.cloneNode(true));
}
} catch (e) {
logger.warn(
formatMessage(AvenxErrorCodes.COMPONENT_RESTORE_SLOT_CONTENT_FAILED, e.message || e),
this.$logContext,
);
}
return [];
}
/**
* Fills <slot> elements with transcluded child nodes.
* Supports both static and dynamically rendered slot names.
* @private
*/
#fillSlots() {
if (!this.#element || !this.#transcludedGroups) return;
const slots = this.#getOwnSlots();
slots.forEach((slotEl) => {
const name = this.#resolveSlotName(slotEl);
const nodes = name ? this.#transcludedGroups.named[name] || [] : this.#transcludedGroups.default || [];
const hasContent = nodes.some((node) => {
if (node.nodeType === 1 && node.nodeName !== '!--' && node.nodeName !== '#comment') return true;
if (node.nodeType === 3 && node.textContent.trim().length > 0) return true;
return false;
});
if (hasContent) {
slotEl.innerHTML = '';
const templateEl = nodes.find(
(node) =>
node.nodeType === 1 && node.tagName.toLowerCase() === 'template' && node.hasAttribute('data-slot-props'),
);
if (templateEl) {
const renderedNodes = this.#renderScopedSlot(slotEl, templateEl);
renderedNodes.forEach((node) => {
slotEl.appendChild(node);
});
} else {
nodes.forEach((node) => {
slotEl.appendChild(node);
});
}
slotEl.setAttribute('data-avenx-transcluded', 'true');
} else if (slotEl.hasAttribute('data-avenx-transcluded')) {
// Only when the outlet actually held projected content. Rebuilding it
// unconditionally replaced the fallback with *clones* of itself, and on
// the compiled path the bindings still pointed at the originals -- so a
// slot showing its fallback rendered once and then went stale, writing
// every later value into a detached node.
//
// When nothing was ever projected, the fallback in the outlet is the
// one the renderer produced and is already live. Leaving it alone is
// both cheaper and the only correct thing to do.
slotEl.removeAttribute('data-avenx-transcluded');
slotEl.innerHTML = '';
this.#getDefaultSlotChildren(name).forEach((child) => {
slotEl.appendChild(child);
});
}
});
}
/**
* Retrieves slot elements belonging to this component.
* @returns {Element[]}
* @private
*/
#getOwnSlots() {
if (!this.#element) return [];
const slots = this.#element.querySelectorAll('slot');
const root = this.#element;
return Array.from(slots).filter((slot) => {
let parent = slot.parentNode;
while (parent && parent !== root) {
if (
parent.hasAttribute &&
(parent.hasAttribute('data-avenx-comp') || parent.hasAttribute('data-avenx-comp-dynamic'))
) {
return false;
}
parent = parent.parentNode;
}
return true;
});
}
/**
* Resolves reference elements if marked dirty.
* @private
*/
#resolveRefs() {
if (this.#refsDirty) {
this.#collectRefs();
}
}
/**
* Collects elements marked with data-ax-ref that belong to this component.
* Elements inside nested component boundaries are excluded.
* @private
*/
#collectRefs() {
this.#refsCache = {};
this.#refsDirty = false;
if (!this.#element) return;
const refElements = this.#element.querySelectorAll('[data-ax-ref]');
const root = this.#element;
Array.from(refElements).forEach((element) => {
let parent = element.parentNode;
while (parent && parent !== root) {
if (
parent.hasAttribute &&
(parent.hasAttribute('data-avenx-comp') || parent.hasAttribute('data-avenx-comp-dynamic'))
) {
return;
}
parent = parent.parentNode;
}
const refName = element.getAttribute('data-ax-ref');
if (refName && refName.trim()) {
// Prefer the mounted component instance when present (Vue-like $refs behavior)
this.#refsCache[refName.trim()] = element.__avenx_comp_instance || element;
}
});
}
/**
* Renders the content of a scoped slot template using child-exposed properties
* merged into the parent component's evaluation scope.
* @param {Element} slotEl - The slot element.
* @param {Element} templateEl - The transcluded template element.
* @returns {Node[]} Array of rendered and tagged child nodes.
* @private
*/
#renderScopedSlot(slotEl, templateEl) {
const slotPropsName = templateEl.getAttribute('data-slot-props');
if (!slotPropsName) return [];
const exposedProps = {};
for (const attr of slotEl.attributes) {
if (attr.name.startsWith(':')) {
const propName = attr.name.slice(1);
exposedProps[propName] = this._evaluate(attr.value);
} else if (attr.name.startsWith('data-props-')) {
const propName = attr.name.slice('data-props-'.length);
exposedProps[propName] = this._evaluate(attr.value);
}
}
const extraScope = { [slotPropsName]: exposedProps };
// innerHTML encodes operators in text expressions. Restore one level only
// inside the placeholders, leaving literal markup and entity strings inert.
const templateHtml = restoreScopedSlotInterpolations(templateEl.innerHTML);
const parentComp = this.$parent || this;
const renderedHtml = this.#renderer.render(
templateHtml,
(expr) => {
return parentComp._evaluate(expr, extraScope);
},
parentComp.$logContext || this.$logContext,
);
const parser = new DOMParser();
const doc = parser.parseFromString(renderedHtml, 'text/html');
const nodes = Array.from((doc.body || doc).childNodes);
// Only the roots need stamping: resolution walks up from wherever a binding
// sits, so marking every descendant was redundant work proportional to the
// size of the slot's content.
nodes.forEach((node) => stampScope(node, extraScope));
nodes.forEach((node) => {
if (node.nodeType === 1) {
this.#patcher.applyDirectives(
node,
(expr) => {
return parentComp._evaluate(expr, extraScope);
},
this.$app,
);
}
});
return nodes;
}
/**
* Updates the transcluded content when the parent template updates.
* @param {NodeList|Array} virtualChildNodes - The new virtual transcluded nodes from parent.
* @private
*/
__updateTranscludedContent(virtualChildNodes) {
const grouped = {
default: [],
named: {},
};
Array.from(virtualChildNodes || []).forEach((node) => {
if (node.nodeType === 1 && node.hasAttribute('slot')) {
const name = node.getAttribute('slot');
if (!grouped.named[name]) {
grouped.named[name] = [];
}
grouped.named[name].push(node);
} else {
grouped.default.push(node);
}
});
this.#transcludedGroups = grouped;
if (this.#element) {
const slots = this.#getOwnSlots();
slots.forEach((slotEl) => {
const name = this.#resolveSlotName(slotEl);
const newChildren = name ? grouped.named[name] || [] : grouped.default || [];
const newSlotWrapper = slotEl.cloneNode(false);
const templateEl = newChildren.find(
(node) =>
node.nodeType === 1 && node.tagName.toLowerCase() === 'template' && node.hasAttribute('data-slot-props'),
);
let finalChildren = newChildren;
let isScoped = false;
if (templateEl) {
finalChildren = this.#renderScopedSlot(slotEl, templateEl);
isScoped = true;
}
if (isScoped) {
finalChildren.forEach((child) => {
newSlotWrapper.appendChild(child);
});
} else {
finalChildren.forEach((child) => {
newSlotWrapper.appendChild(child.cloneNode(true));
});
}
const hasContent = finalChildren.some((node) => {
if (node.nodeType === 1 && node.nodeName !== '!--' && node.nodeName !== '#comment') return true;
if (node.nodeType === 3 && node.textContent.trim().length > 0) return true;
return false;
});
if (hasContent) {
newSlotWrapper.setAttribute('data-avenx-transcluded', 'true');
} else {
newSlotWrapper.removeAttribute('data-avenx-transcluded');
this.#getDefaultSlotChildren(name).forEach((child) => {
newSlotWrapper.appendChild(child);
});
}
const slotEvaluator = (expr) => {
if (isScoped && templateEl) {
const slotPropsName = templateEl.getAttribute('data-slot-props');
const exposedProps = {};
for (const attr of slotEl.attributes) {
if (attr.name.startsWith(':')) {
const propName = attr.name.slice(1);
exposedProps[propName] = this._evaluate(attr.value);
} else if (attr.name.startsWith('data-props-')) {
const propName = attr.name.slice('data-props-'.length);
exposedProps[propName] = this._evaluate(attr.value);
}
}
const extraScope = { [slotPropsName]: exposedProps };
const parentComp = this.$parent || this;
return parentComp._evaluate(expr, extraScope);
}
return this.#resolveTemplateExpression(expr);
};
this.#patcher.patchElement(slotEl, newSlotWrapper, slotEvaluator, this.$app);
});
}
}
/**
* Internal method called before the component is mounted to the DOM.
* @private
*/
__beforeMount() {
this.#isBeforeMounting = true;
try {
this.#triggerLifecycle('onBeforeMount');
} catch (error) {
this.#reportError(error, '__beforeMount', true);
} finally {
this.#isBeforeMounting = false;
}
}
/**
* Internal method called after the component is mounted to the DOM.
* @private
*/
__afterMount() {
this.#isMounted = true;
try {
this.#resolveRefs();
if (typeof CustomEvent !== 'undefined' && this.#element?.dispatchEvent) {
this.#element.dispatchEvent(new CustomEvent('avenx:mount'));
}
this.#triggerLifecycle('onMount');
} catch (error) {
this.#reportError(error, '__afterMount', true);
}
}
/**
* Unmounts the component and triggers cleanup.
* @returns {Promise<void>|void}
*/
unmount() {
if (this.#isUnmounted) return;
if (this.#isUnmounting) return this.#unmountPromise;
this.#isUnmounting = true;
const res = this.#lifecycle.unmount(this);
if (res instanceof Promise) {
this.#unmountPromise = res;
return res;
}
}
/**
* Destroys/unmounts the component and performs teardown of watchers and resources.
* Alias for unmount().
* @returns {Promise<void>|void}
*/
destroy() {
return this.unmount();
}
/**
* Destroys/unmounts the component and performs teardown of watchers and resources.
* Alias for unmount().
* @returns {Promise<void>|void}
*/
$destroy() {
return this.unmount();
}
/**
* Performs the actual synchronous teardown and DOM clearing of the component.
* @private
*/
__performTeardown() {
try {
this.#eventBinder.unbind(this.#element);
this.#eventBinder.teardown();
this.#eventExecutor.teardown();
if (typeof CustomEvent !== 'undefined' && this.#element?.dispatchEvent) {
this.#element.dispatchEvent(new CustomEvent('avenx:unmount'));
}
this.#triggerLifecycle('onUnmount');
if (this.renderWatcher) {
this.renderWatcher.teardown();
}
// Releases <@defer> triggers (observers, timers, idle callbacks, listeners).
// The instance is dropped so a remount builds a fresh manager.
if (this.#deferManagerInstance) {
this.#deferManagerInstance.destroy();
this.#deferManagerInstance = null;
}
// Every binding holds a watcher that sits in the dependency set of the
// state it read. Left in place they keep this component, its DOM and its
// scope reachable for as long as that state exists -- a leak proportional
// to how finely the template was bound, which is exactly the wrong way
// round.
if (this.#templateInstance) {
this.#templateInstance.dispose();
this.#templateInstance = null;
}
this.#postRenderQueued = false;
this.#beforeRenderFired = false;
if (this._injectedAncestors) {
for (const { ancestor, key } of this._injectedAncestors) {
ancestor.__unregisterInjectingChild(key, this);
}
this._injectedAncestors = [];
}
if (this._watchers) {
for (const watcher of this._watchers) {
watcher.teardown();
}
this._watchers = [];
}
// Releases bridge subscriptions (and anything else scope-owned) opened
// by this component's hooks and handlers.
if (this._scope) {
this._scope.dispose();
}
if (this._stateHandler) {
this._stateHandler.teardown();
}
if (this._propsHandler) {
this._propsHandler.teardown();
}
if (this.#resources) {
for (const res of Object.values(this.#resources)) {
if (res && typeof res.teardown === 'function') {
res.teardown();
}
}
}
this.#refsCache = {};
this.#refsDirty = false;
if (this.#element) {
// Custom-directive `unmounted` hooks, and only those. The metadata they
// read -- `__avenx_directives` -- is written in exactly one place, the
// string renderer's attribute patch, so a bundle without that renderer
// has nothing here to trigger.
//
// Reaching for `#patcher` unconditionally therefore threw on every
// teardown in a fully compiled application, where the renderer is
// correctly absent. The throw was caught below and, until unhandled
// errors were reported, discarded -- so the rest of this block never
// ran: the instance stayed on the element, its content stayed in the
// document, and nothing said why. Skipping the call when there is
// provably nothing to call is both the fix and the honest description
// of the condition.
if (hasStringRenderer()) {
this.#patcher.triggerUnmounted(this.#element, this.$app);
}
delete this.#element.__avenx_comp_instance;
this.#element.innerHTML = '';
this.#element = null;
}
} catch (error) {
this.#reportError(error, '__performTeardown');
}
// Decrement runtime style reference count for this component class
styleMountManager.unmount(this.constructor);
this.#isMounted = false;
this.#isUnmounting = false;
this.#isUnmounted = true;
this.#unmountPromise = null;
}
/**
* Called before the component leaves the DOM.
* Can return a Promise to postpone DOM removal.
* @returns {Promise<void>|void}
*/
onBeforeLeave() {}
/**
* Called when the component is mounted to the DOM and enters.
*/
onEnter() {}
/**
* Called when the component is unmounted and leaves the DOM.
*/
onLeave() {}
/**
* Updates the component's props and triggers an update if they changed.
* @param {object} newProps - The new props to apply.
*/
setProps(newProps) {
const currentProps = this.props;
for (const key of Object.keys(newProps)) {
if (currentProps[key] !== newProps[key]) {
currentProps[key] = newProps[key];
}
}
for (const key of Object.keys(currentProps)) {
if (!(key in newProps)) {
delete currentProps[key];
}
}
}
/**
* The router this component's application initialised, if any.
*
* `this.$router.navigate(hash)` is how the routing documentation says to
* navigate from inside a component, and the routing guide documents
* `back()`, `forward()` and `go(delta)` on the same accessor -- but nothing
* in the runtime ever defined `$router`, so every one of those examples threw
* `Cannot read properties of undefined (reading 'navigate')`. The router was
* only reachable as `this.$app.router`, which no document mentions.
*
* Falls back to the active router registered on the window when the component
* has no `$app` -- a page mounted directly still has a router to talk to, and
* that is the same registry `$route` above reads.
* @returns {object|null} The router, or null when the application has none.
*/
get $router() {
if (this.$app && this.$app.router) {
return this.$app.router;
}
if (typeof window !== 'undefined' && window.__avenx_routers) {
for (const router of window.__avenx_routers) {
return router;
}
}
return null;
}
/**
* The current active route metadata.
* @returns {{hash: string, path: string, page: string, params: Record<string, any>, query: Record<string, string | boolean | number>}} The route details.
*/
get $route() {
if (typeof window !== 'undefined' && window.__avenx_routers) {
for (const router of window.__avenx_routers) {
if (router.currentRoute && router.currentRoute.hash) {
return router.currentRoute;
}
}
}
return { hash: '', path: '', page: '', params: {}, query: {}, meta: {} };
}
/**
* Evaluates an expression in the component's scope.
* @param {string} expression - The expression to evaluate.
* @param {object} [extraScope] - Additional scope variables.
* @returns {any} The result of the evaluation.
* @protected
*/
_evaluate(expression, extraScope = {}) {
return this.#evaluator.evaluateExpression(expression, this.#createScope(this.#methods, extraScope), this.state);
}
/**
* @returns {Element|null} The component's root element.
* @protected
*/
_getElement() {
return this.#element;
}
/**
* @returns {object} The bridges accessible to the component.
* @protected
*/
_getBridges() {
return this.#bridges;
}
/**
* Returns the set of active compiler contracts for this component.
* @returns {Set<string>}
*/
get contracts() {
return this.#contracts;
}
/**
* Retrieves the transcluded groups for this component.
* @returns {object} The transcluded groups.
* @protected
*/
_getTranscludedGroups() {
return this.#transcludedGroups;
}
/**
* Mounts the component to a target element.
* @param {Element|string} target - The target element or selector.
*/
mount(target) {
this.#lifecycle.mount(this, target);
}
/**
* Internal method to initialize injected properties from ancestors.
* @private
*/
__initInjection() {
const injectOption =
this.inject ||
(typeof this.constructor.inject === 'function' ? this.constructor.inject() : this.constructor.inject);
if (!injectOption) return;
let injectMap = {};
const resolvedOption = typeof injectOption === 'function' ? injectOption.call(this) : injectOption;
if (Array.isArray(resolvedOption)) {
for (const key of resolvedOption) {
injectMap[key] = key;
}
} else if (resolvedOption && typeof resolvedOption === 'object') {
injectMap = resolvedOption;
}
for (const [localKey, injectDef] of Object.entries(injectMap)) {
let provideKey = injectDef;
let defaultValue;
let hasDefault = false;
if (injectDef && typeof injectDef === 'object' && !Array.isArray(injectDef)) {
provideKey = injectDef.from != null ? injectDef.from : localKey;
if (Object.prototype.hasOwnProperty.call(injectDef, 'default')) {
hasDefault = true;
defaultValue = injectDef.default;
}
}
Object.defineProperty(this, localKey, {
get: () => {
const ancestor = this.#findAncestorProviding(provideKey);
if (!ancestor) {
if (hasDefault) {
return typeof defaultValue === 'function' ? defaultValue.call(this) : defaultValue;
}
logger.warn(formatMessage(AvenxErrorCodes.COMPONENT_INJECT_KEY_NOT_FOUND, provideKey), this.$logContext);
return undefined;
}
if (!this._injectedAncestors) {
this._injectedAncestors = [];
}
const alreadyRegistered = this._injectedAncestors.some(
(reg) => reg.ancestor === ancestor && reg.key === provideKey,
);
if (!alreadyRegistered) {
ancestor.__registerInjectingChild(provideKey, this);
this._injectedAncestors.push({ ancestor, key: provideKey });
}
return this.#getAncestorProvidedValue(ancestor, provideKey);
},
enumerable: true,
configurable: true,
});
}
}
/**
* Finds the nearest ancestor component that provides the specified key.
* @param {string} key - The provided key to search for.
* @returns {AvenxComponent|null} The ancestor component instance, or null.
* @private
*/
#findAncestorProviding(key) {
const el = this._getElement();
if (!el) return null;
let parentEl = el.parentNode;
while (parentEl) {
if (parentEl.__avenx_comp_instance) {
const comp = parentEl.__avenx_comp_instance;
if (this.#componentProvides(comp, key)) {
return comp;
}
}
parentEl = parentEl.parentNode;
}
return null;
}
/**
* Checks if a component provides the specified key.
* @param {AvenxComponent} comp - The component to check.
* @param {string} key - The provided key.
* @returns {boolean} True if the component provides the key.
* @private
*/
#componentProvides(comp, key) {
const provideOption =
comp.provide ||
(typeof comp.constructor.provide === 'function' ? comp.constructor.provide() : comp.constructor.provide);
if (!provideOption) return false;
const resolved = typeof provideOption === 'function' ? provideOption.call(comp) : provideOption;
if (Array.isArray(resolved)) {
return resolved.includes(key);
} else if (resolved && typeof resolved === 'object') {
return key in resolved;
}
return false;
}
/**
* Retrieves the provided value for a key from an ancestor component.
* @param {AvenxComponent} comp - The ancestor component instance.
* @param {string} key - The provided key.
* @returns {any} The value.
* @private
*/
#getAncestorProvidedValue(comp, key) {
if (comp._providedState && key in comp._providedState) {
const val = comp._providedState[key];
if (typeof val === 'function') {
return val;
}
return val;
}
const provideOption =
comp.provide ||
(typeof comp.constructor.provide === 'function' ? comp.constructor.provide() : comp.constructor.provide);
if (!provideOption) return undefined;
const resolved = typeof provideOption === 'function' ? provideOption.call(comp) : provideOption;
if (Array.isArray(resolved)) {
return comp._getScopeValue(key);
} else if (resolved && typeof resolved === 'object') {
const val = resolved[key];
if (typeof val === 'function') {
return val.bind(comp);
}
return val;
}
return undefined;
}
/**
* Internal method to initialize provided properties as a reactive proxy.
* @private
*/
__initProvide() {
const provideOption =
this.provide ||
(typeof this.constructor.provide === 'function' ? this.constructor.provide() : this.constructor.provide);
if (!provideOption) return;
const resolved = typeof provideOption === 'function' ? provideOption.call(this) : provideOption;
if (resolved && typeof resolved === 'object' && !Array.isArray(resolved)) {
// Create a reactive proxy of the provided object
const handlerFactory = new ProxyHandlerFactory({
onChange: () => {
this.__notifyInjectingChildren();
},
});
this._providedState = new Proxy(resolved, handlerFactory.create());
}
}
/**
* Registers a child component that is injecting a provided key.
* @param {string} key - The provided key.
* @param {AvenxComponent} child - The child component.
*/
__registerInjectingChild(key, child) {
if (!this._injectingChildren) {
this._injectingChildren = new Map();
}
let children = this._injectingChildren.get(key);
if (!children) {
children = new Set();
this._injectingChildren.set(key, children);
}
children.add(child);
}
/**
* Unregisters an injecting child component.
* @param {string} key - The provided key.
* @param {AvenxComponent} child - The child component.
*/
__unregisterInjectingChild(key, child) {
if (this._injectingChildren) {
const children = this._injectingChildren.get(key);
if (children) {
children.delete(child);
}
}
}
/**
* Notifies all registered injecting child components that a provided value has shifted.
*/
__notifyInjectingChildren() {
if (this._injectingChildren) {
for (const children of this._injectingChildren.values()) {
for (const child of children) {
child.scheduleUpdate();
}
}
}
}
/**
* Dynamically re-evaluates the provide option and updates providedState.
*/
__updateProvidedState() {
if (!this._providedState) return;
const provideOption =
this.provide ||
(typeof this.constructor.provide === 'function' ? this.constructor.provide() : this.constructor.provide);
if (!provideOption) return;
const resolved = typeof provideOption === 'function' ? provideOption.call(this) : provideOption;
if (resolved && typeof resolved === 'object' && !Array.isArray(resolved)) {
const rawProvided = this._providedState[RAW_SYMBOL] || this._providedState;
for (const [k, v] of Object.entries(resolved)) {
if (rawProvided[k] !== v) {
this._providedState[k] = v;
}
}
}
}
/**
* Retrieves a property or method from the component's scope.
* Used for array-based provide to resolve keys dynamically.
* @param {string} key - The key to retrieve.
* @returns {any} The value.
* @protected
*/
_getScopeValue(key) {
if (this.state && key in this.state) {
return this.state[key];
}
if (this.props && key in this.props) {
return this.props[key];
}
if (this.#methods && key in this.#methods) {
return this.#methods[key];
}
if (this.#bridges && key in this.#bridges) {
return this.#bridges[key];
}
if (key in this) {
return this[key];
}
return undefined;
}
/**
* Resolves the app instance associated with this component.
* @returns {AvenxApp|null}
*/
get $app() {
if (this._app) {
return this._app;
}
if (this.$parent) {
return this.$parent.$app;
}
const el = this.$element;
if (el) {
let parentEl = el.parentNode;
while (parentEl) {
if (parentEl.__avenx_comp_instance) {
const comp = parentEl.__avenx_comp_instance;
if (comp._app) return comp._app;
if (comp.$parent) {
const app = comp.$parent.$app;
if (app) return app;
}
}
parentEl = parentEl.parentNode;
}
}
return null;
}
/**
* Sets the app instance associated with this component.
* @param {AvenxApp} app - The app instance.
*/
set $app(app) {
this._app = app;
}
/**
* Invokes all registered lifecycle hooks for the specified event.
* @param {string} hookName - The name of the lifecycle hook.
* @private
*/
#triggerLifecycle(hookName) {
const hooks = [];
for (const mixin of globalMixins) {
if (mixin[hookName] && typeof mixin[hookName] === 'function') {
hooks.push(mixin[hookName].bind(this));
} else if (mixin.methods && mixin.methods[hookName] && typeof mixin.methods[hookName] === 'function') {
hooks.push(mixin.methods[hookName].bind(this));
}
}
const selfHook =
this.#methods[hookName] || (typeof this[hookName] === 'function' ? this[hookName].bind(this) : null);
if (selfHook) {
hooks.push(selfHook);
}
for (const hook of hooks) {
try {
const enableProfiling = !!(
this.$app?.enableProfiling ||
(typeof window !== 'undefined' && window.__avenx_enable_profiling)
);
// The hook's return value is observed, not discarded: a hook that
// returns a promise that rejects is reported through the same
// AVX_R12 + errorHandler path a synchronous throw takes.
this.#observeAsyncFailure(
profile(enableProfiling, this.constructor.name, hookName, () => runInScope(this._scope, hook)),
AvenxErrorCodes.LIFECYCLE_HOOK_ERROR,
[this.constructor.name, hookName],
hookName,
);
} catch (error) {
if (error && error.code === AvenxErrorCodes.STATE_MUTATION_IN_UPDATE) {
throw error;
}
logger.error(
formatMessage(AvenxErrorCodes.LIFECYCLE_HOOK_ERROR, this.constructor.name, hookName, error),
this.$logContext,
);
this.#reportError(error, hookName, true);
}
}
}
/**
* Finds the nearest enclosing component without changing template ownership.
* The page owns nested mount points, so $parent can skip intermediate hooks.
* @returns {AvenxComponent|null} The next component in the error path.
* @private
*/
#getErrorParent() {
// An application root has no component parent, even inside another app.
if (!this.$parent) return null;
let parentEl = this.#element?.parentNode;
while (parentEl) {
if (parentEl.__avenx_comp_instance) {
const parent = parentEl.__avenx_comp_instance;
return parent.$app === this.$app ? parent : this.$parent;
}
parentEl = parentEl.parentNode;
}
return this.$parent;
}
/**
* Reports an error to the global application error handler, if registered.
* If a parent component defines an onErrorCaptured hook, it is invoked first.
* If onErrorCaptured returns false, the error propagation is stopped.
*
* `logged` says whether the call site has already written the error to the
* log with a diagnostic of its own. Several have: a failing lifecycle hook is
* reported as AVX_R12 and a failing handler as AVX_R09, each naming the hook
* or the statement, which is more specific than anything this method knows.
* Those keep their message and are not reported a second time.
*
* The call sites that pass nothing are the ones where this method is the only
* thing standing between an error and silence -- a failed render above all.
* @param {Error} error - The error that occurred.
* @param {string} origin - Description of where the error occurred.
* @param {boolean} [logged] - Whether the caller already logged this error.
* @private
*/
#reportError(error, origin, logged = false) {
let current = this;
let currentError = error;
while (current) {
const hooks = [];
for (const mixin of globalMixins) {
if (mixin['onErrorCaptured'] && typeof mixin['onErrorCaptured'] === 'function') {
hooks.push(mixin['onErrorCaptured'].bind(current));
} else if (
mixin.methods &&
mixin.methods['onErrorCaptured'] &&
typeof mixin.methods['onErrorCaptured'] === 'function'
) {
hooks.push(mixin.methods['onErrorCaptured'].bind(current));
}
}
const selfHook =
current.#methods['onErrorCaptured'] ||
(typeof current['onErrorCaptured'] === 'function' ? current['onErrorCaptured'].bind(current) : null);
if (selfHook) {
hooks.push(selfHook);
}
if (hooks.length > 0) {
let stopPropagation = false;
for (const hook of hooks) {
try {
const result = hook(currentError, this, origin);
if (result === false) {
stopPropagation = true;
}
} catch (hookError) {
currentError = hookError;
origin = 'onErrorCaptured hook';
}
}
if (stopPropagation) {
return;
}
}
current = current.#getErrorParent();
}
const app = this.$app;
if (app && typeof app._handleError === 'function') {
app._handleError(currentError, this, origin, logged);
return;
}
if (logged) {
// The call site already said what happened, with a diagnostic more
// specific than this one.
return;
}
// No application is reachable -- a component mounted on its own, or one
// whose element is not in the document yet. `$app` walks the parent chain
// and then the DOM, so this is uncommon, but it used to be the second way
// an error could disappear: the chain above found no `onErrorCaptured`,
// there was nothing to hand the error to, and the method simply ended.
// Silence has to cost something, so it costs a report here as well.
logger.error(
formatMessage(
AvenxErrorCodes.COMPONENT_RENDER_ABORTED,
this.constructor?.name || 'component',
origin || 'render',
(currentError && (currentError.stack || currentError.message)) || String(currentError),
),
);
}
/**
* Syncs the value property of select elements to match their value attribute
* after child nodes and lists are fully patched/rendered.
* @private
*/
#syncSelectElements() {
if (!this.#element || typeof this.#element.querySelectorAll !== 'function') return;
const selects = this.#element.querySelectorAll('select') || [];
const isSelect = typeof this.#element.getAttribute === 'function' && this.#element.tagName === 'SELECT';
const allSelects = isSelect ? [this.#element, ...selects] : selects;
for (const select of allSelects) {
if (typeof select.getAttribute === 'function') {
const valueAttr = select.getAttribute('value');
if (valueAttr !== null) {
syncControlValue(select, valueAttr);
}
}
}
}
/**
* Suspends the component rendering and shows the fallback UI if available.
* @param {Promise<any>} promise
* @private
*/
#suspend(promise) {
if (!this.#element) return;
const fallbackMatch = this.#template.match(/<template data-ax-fallback[^>]*>([\s\S]*?)<\/template>/i);
if (!fallbackMatch) {
if (this.$parent) {
this.$parent.#suspend(promise);
}
return;
}
const fallbackHtml = fallbackMatch[1].replace(/\{%/g, '{{').replace(/%\}/g, '}}');
try {
const renderedFallback = this.#renderer.render(
fallbackHtml,
(expression) => this.#resolveTemplateExpression(expression),
this.$logContext,
);
this.#patcher.patch(
this.#element,
renderedFallback,
(expression, slotScope) => this.#resolveTemplateExpression(expression, slotScope),
this.$app,
);
this.#fillSlots();
this.#listManager.process(this.#element, this.#createScope(), this.state, this.$app);
this.#eventBinder.bind(this.#element, this.#eventExecutor);
} catch (error) {
if (error instanceof Promise) {
if (this.$parent) {
this.$parent.#suspend(error);
}
} else {
this.#handleComponentError(error);
}
}
promise.finally(() => {
this.update();
});
}
/**
* Handles component rendering errors using error boundaries.
* @param {Error} error
* @private
*/
#handleComponentError(error) {
if (!this.#element) return;
this.#componentError = error;
let errorAs = 'error';
const asMatch = this.#template.match(/data-ax-error-as="([^"]*)"/i);
if (asMatch) {
errorAs = asMatch[1];
}
const fallbackMatch = this.#template.match(/<template data-ax-error-fallback[^>]*>([\s\S]*?)<\/template>/i);
if (!fallbackMatch) {
// Only transfer rendering to an ancestor that has a fallback. Otherwise
// report from the failing child so its component hooks are not skipped.
let ancestor = this.#getErrorParent();
while (ancestor) {
if (/<template data-ax-error-fallback[^>]*>/i.test(ancestor.#template)) {
ancestor.#handleComponentError(error);
return;
}
ancestor = ancestor.#getErrorParent();
}
this.#reportError(error, 'runUpdate');
return;
}
const fallbackHtml = fallbackMatch[1].replace(/\{%/g, '{{').replace(/%\}/g, '}}');
const extraScope = { [errorAs]: error };
try {
const renderedFallback = this.#renderer.render(
fallbackHtml,
(expression) => this.#resolveTemplateExpression(expression, extraScope),
this.$logContext,
);
this.#patcher.patch(
this.#element,
renderedFallback,
(expression, slotScope) => this.#resolveTemplateExpression(expression, { ...extraScope, ...slotScope }),
this.$app,
);
this.#fillSlots();
this.#listManager.process(this.#element, this.#createScope(this.#methods, extraScope), this.state, this.$app);
this.#eventBinder.bind(this.#element, this.#eventExecutor);
} catch (e) {
if (this.$parent) {
this.$parent.#handleComponentError(e);
} else {
this.#reportError(e, 'ErrorBoundary');
}
}
}
/**
* Registers a global mixin.
* @param {object} mixin - The mixin definition.
*/
static mixin(mixin) {
if (mixin && typeof mixin === 'object') {
globalMixins.push(mixin);
}
}
/**
* Resets/clears the global mixins list.
* Useful for testing environments.
*/
static clearMixins() {
globalMixins.length = 0;
}
/**
* Helper method to programmatically create component subclasses without ES class boilerplate.
* @param {object} [options] - Component definition options.
* @returns {Function} The generated component subclass.
*/
static extend(options = {}) {
const SuperClass = this;
const parentOptions = SuperClass.__options || {};
const componentName =
options.name ||
(SuperClass.name && SuperClass.name !== 'AvenxComponent' ? `${SuperClass.name}Extended` : 'ExtendedComponent');
const reservedKeys = new Set([
'name',
'state',
'data',
'computed',
'template',
'methods',
'props',
'styles',
'resources',
'contracts',
'watch',
'provide',
'inject',
'options',
]);
const lifecycleHookNames = new Set(LIFECYCLE_HOOK_KEYS);
// Merge methods
const explicitMethods = {
...(parentOptions.methods || {}),
...(options.methods || {}),
};
// Extract top-level methods & lifecycle hooks
for (const [key, value] of Object.entries(options)) {
if (!reservedKeys.has(key) && typeof value === 'function') {
explicitMethods[key] = value;
}
}
// Separate regular methods (for #methods/super) and lifecycle hooks
const regularMethods = {};
for (const [key, fn] of Object.entries(explicitMethods)) {
if (!lifecycleHookNames.has(key)) {
regularMethods[key] = fn;
}
}
const finalComputed = {
...(parentOptions.computed || {}),
...(options.computed || {}),
};
const finalTemplate =
options.template !== undefined
? options.template
: parentOptions.template !== undefined
? parentOptions.template
: '';
const finalProps = {
...(parentOptions.props || {}),
...(options.props || {}),
};
const finalStyles = {
...(parentOptions.styles || {}),
...(options.styles || {}),
};
const finalResources = {
...(parentOptions.resources || {}),
...(options.resources || {}),
};
const finalWatch = {
...(parentOptions.watch || {}),
...(options.watch || {}),
};
const parentContracts = Array.isArray(parentOptions.contracts)
? parentOptions.contracts
: parentOptions.contracts instanceof Set
? Array.from(parentOptions.contracts)
: [];
const childContracts = Array.isArray(options.contracts)
? options.contracts
: options.contracts instanceof Set
? Array.from(options.contracts)
: [];
const finalContracts = Array.from(new Set([...parentContracts, ...childContracts]));
const finalOptions = {
...(parentOptions.options || {}),
...(options.options || {}),
contracts: finalContracts,
watch: finalWatch,
};
/**
* Resolves and clones initial state from a state/data definition.
* @param {object|Function} stateDef - The state definition.
* @returns {object} The resolved state object.
*/
function resolveState(stateDef) {
if (typeof stateDef === 'function') {
return stateDef();
}
if (stateDef && typeof stateDef === 'object') {
try {
if (typeof globalThis !== 'undefined' && typeof globalThis.structuredClone === 'function') {
return globalThis.structuredClone(stateDef);
}
return JSON.parse(JSON.stringify(stateDef));
} catch {
return { ...stateDef };
}
}
return {};
}
const ExtendedComponent = {
[componentName]: class extends SuperClass {
/**
* @param {...any} args - Constructor arguments.
*/
constructor(...args) {
let runtimeBridges = {};
let runtimeProps = {};
if (args.length >= 8) {
const [cState, cComputed, cBridges, cTemplate, cMethods, cProps, cStyles, cResources, cOptions] = args;
const parentDefState = resolveState(parentOptions.state || parentOptions.data);
const childDefState = resolveState(options.state || options.data);
const mergedState = { ...parentDefState, ...childDefState, ...(cState || {}) };
const mergedComputed = { ...finalComputed, ...(cComputed || {}) };
const mergedTemplate = cTemplate !== undefined ? cTemplate : finalTemplate;
const mergedMethods = { ...regularMethods, ...(cMethods || {}) };
const mergedProps = { ...finalProps, ...(cProps || {}) };
const mergedStyles = { ...finalStyles, ...(cStyles || {}) };
const mergedResources = { ...finalResources, ...(cResources || {}) };
const mergedOptions = { ...finalOptions, ...(cOptions || {}) };
super(
mergedState,
mergedComputed,
cBridges || {},
mergedTemplate,
mergedMethods,
mergedProps,
mergedStyles,
mergedResources,
mergedOptions,
);
return;
}
if (args.length === 1) {
if (args[0] && typeof args[0] === 'object') {
runtimeBridges = args[0];
runtimeProps = args[0];
}
} else if (args.length >= 2) {
runtimeBridges = args[0] || {};
runtimeProps = args[1] || {};
}
const parentDefState = resolveState(parentOptions.state || parentOptions.data);
const childDefState = resolveState(options.state || options.data);
const mergedState = { ...parentDefState, ...childDefState };
const mergedProps = { ...finalProps, ...runtimeProps };
super(
mergedState,
finalComputed,
runtimeBridges,
finalTemplate,
regularMethods,
mergedProps,
finalStyles,
finalResources,
finalOptions,
);
}
},
}[componentName];
Object.defineProperty(ExtendedComponent, 'name', {
value: componentName,
configurable: true,
});
ExtendedComponent.__isExtendedComponent = true;
ExtendedComponent.__options = {
name: componentName,
state: options.state || options.data || parentOptions.state || parentOptions.data,
computed: finalComputed,
methods: explicitMethods,
template: finalTemplate,
props: finalProps,
styles: finalStyles,
resources: finalResources,
watch: finalWatch,
contracts: finalContracts,
options: finalOptions,
provide: options.provide || parentOptions.provide,
inject: options.inject || parentOptions.inject,
};
// Attach all methods & lifecycle hooks to ExtendedComponent.prototype
for (const [name, fn] of Object.entries(explicitMethods)) {
if (typeof fn === 'function') {
ExtendedComponent.prototype[name] = fn;
}
}
// Attach computed getters to ExtendedComponent.prototype
for (const name of Object.keys(finalComputed)) {
if (!(name in ExtendedComponent.prototype)) {
Object.defineProperty(ExtendedComponent.prototype, name, {
get() {
return this.state ? this.state[name] : undefined;
},
configurable: true,
enumerable: true,
});
}
}
// Attach provide & inject
if (options.provide || parentOptions.provide) {
ExtendedComponent.prototype.provide = options.provide || parentOptions.provide;
}
if (options.inject || parentOptions.inject) {
ExtendedComponent.prototype.inject = options.inject || parentOptions.inject;
}
// Copy any custom non-function / extra properties from options to prototype
for (const [key, value] of Object.entries(options)) {
if (!reservedKeys.has(key) && typeof value !== 'function') {
ExtendedComponent.prototype[key] = value;
}
}
return ExtendedComponent;
}
}
|