@askrjs/themes 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/THEMING.md +6 -5
- package/dist/components/_internal/block-layout.d.ts +1 -0
- package/dist/components/_internal/block-layout.js +14 -11
- package/dist/components/_internal/block-layout.js.map +1 -1
- package/dist/components/_internal/classes.js +8 -1
- package/dist/components/_internal/classes.js.map +1 -1
- package/dist/components/_internal/jsx.js.map +1 -1
- package/dist/components/_internal/style.js +182 -28
- package/dist/components/_internal/style.js.map +1 -1
- package/dist/components/alert/alert.d.ts +1 -0
- package/dist/components/alert/alert.js.map +1 -1
- package/dist/components/alert/alert.types.d.ts +1 -0
- package/dist/components/aside/aside.d.ts +1 -0
- package/dist/components/aside/aside.js.map +1 -1
- package/dist/components/aspect-ratio/aspect-ratio.d.ts +1 -0
- package/dist/components/aspect-ratio/aspect-ratio.js.map +1 -1
- package/dist/components/aspect-ratio/aspect-ratio.types.d.ts +1 -0
- package/dist/components/badge/badge.d.ts +1 -0
- package/dist/components/badge/badge.js.map +1 -1
- package/dist/components/badge/badge.types.d.ts +1 -0
- package/dist/components/block/block.d.ts +1 -0
- package/dist/components/block/block.js +2 -2
- package/dist/components/block/block.js.map +1 -1
- package/dist/components/block/block.types.d.ts +1 -0
- package/dist/components/brand/brand.d.ts +1 -0
- package/dist/components/brand/brand.js +2 -2
- package/dist/components/brand/brand.js.map +1 -1
- package/dist/components/brand/brand.types.d.ts +1 -0
- package/dist/components/button-group/button-group.d.ts +1 -0
- package/dist/components/button-group/button-group.js.map +1 -1
- package/dist/components/button-group/button-group.types.d.ts +1 -0
- package/dist/components/card/card.d.ts +1 -0
- package/dist/components/card/card.js.map +1 -1
- package/dist/components/card/card.types.d.ts +1 -0
- package/dist/components/catalog.d.ts +1 -0
- package/dist/components/catalog.js +22 -13
- package/dist/components/catalog.js.map +1 -1
- package/dist/components/close/close.d.ts +1 -0
- package/dist/components/close/close.js.map +1 -1
- package/dist/components/container/container.d.ts +1 -0
- package/dist/components/container/container.js.map +1 -1
- package/dist/components/empty-state/empty-state.d.ts +1 -0
- package/dist/components/empty-state/empty-state.js.map +1 -1
- package/dist/components/field/field.d.ts +1 -0
- package/dist/components/field/field.js.map +1 -1
- package/dist/components/field/field.types.d.ts +1 -0
- package/dist/components/footer/footer.d.ts +1 -0
- package/dist/components/footer/footer.js.map +1 -1
- package/dist/components/footer/footer.types.d.ts +1 -0
- package/dist/components/grid/grid.d.ts +1 -0
- package/dist/components/grid/grid.js.map +1 -1
- package/dist/components/grid/grid.types.d.ts +1 -0
- package/dist/components/header/header.d.ts +1 -0
- package/dist/components/header/header.js.map +1 -1
- package/dist/components/input-group/input-group.d.ts +1 -0
- package/dist/components/input-group/input-group.js.map +1 -1
- package/dist/components/input-group/input-group.types.d.ts +1 -0
- package/dist/components/jsx-types.d.ts +12 -0
- package/dist/components/main/main.d.ts +1 -0
- package/dist/components/main/main.js.map +1 -1
- package/dist/components/nav/nav.d.ts +1 -0
- package/dist/components/nav/nav.js +6 -2
- package/dist/components/nav/nav.js.map +1 -1
- package/dist/components/nav/nav.types.d.ts +2 -0
- package/dist/components/navbar/navbar.d.ts +1 -0
- package/dist/components/navbar/navbar.js +15 -10
- package/dist/components/navbar/navbar.js.map +1 -1
- package/dist/components/overlays/dropdown-content.d.ts +1 -0
- package/dist/components/overlays/dropdown-content.js.map +1 -1
- package/dist/components/page/page.d.ts +1 -0
- package/dist/components/page/page.js.map +1 -1
- package/dist/components/page-header/page-header.d.ts +1 -0
- package/dist/components/page-header/page-header.js.map +1 -1
- package/dist/components/section/section.d.ts +1 -0
- package/dist/components/section/section.js.map +1 -1
- package/dist/components/separator/separator.d.ts +1 -0
- package/dist/components/separator/separator.js.map +1 -1
- package/dist/components/separator/separator.types.d.ts +1 -0
- package/dist/components/sidebar/index.d.ts +2 -2
- package/dist/components/sidebar/sidebar.d.ts +2 -1
- package/dist/components/sidebar/sidebar.js +39 -13
- package/dist/components/sidebar/sidebar.js.map +1 -1
- package/dist/components/sidebar/sidebar.types.d.ts +3 -1
- package/dist/components/skeleton/skeleton.d.ts +1 -0
- package/dist/components/skeleton/skeleton.js.map +1 -1
- package/dist/components/skeleton/skeleton.types.d.ts +1 -0
- package/dist/components/spinner/spinner.d.ts +1 -0
- package/dist/components/spinner/spinner.js.map +1 -1
- package/dist/components/stat/stat.d.ts +1 -0
- package/dist/components/stat/stat.js.map +1 -1
- package/dist/components/stat/stat.types.d.ts +1 -0
- package/dist/components/text/text.d.ts +1 -0
- package/dist/components/text/text.js.map +1 -1
- package/dist/components/text/text.types.d.ts +1 -0
- package/dist/components/theme/theme.d.ts +2 -0
- package/dist/components/theme/theme.js +32 -16
- package/dist/components/theme/theme.js.map +1 -1
- package/dist/components/toolbar/toolbar.d.ts +1 -0
- package/dist/components/toolbar/toolbar.js.map +1 -1
- package/dist/components.d.ts +6 -3
- package/dist/core.d.ts +2 -2
- package/dist/ssr.d.ts +18 -0
- package/dist/ssr.js +63 -0
- package/dist/ssr.js.map +1 -0
- package/dist/themes/default/index.css +36 -6
- package/package.json +7 -3
- package/src/components/_internal/block-layout.ts +27 -16
- package/src/components/_internal/classes.ts +15 -2
- package/src/components/_internal/jsx.ts +1 -1
- package/src/components/_internal/style.ts +241 -27
- package/src/components/alert/alert.tsx +1 -0
- package/src/components/alert/alert.types.ts +1 -0
- package/src/components/aside/aside.tsx +1 -0
- package/src/components/aspect-ratio/aspect-ratio.tsx +1 -0
- package/src/components/aspect-ratio/aspect-ratio.types.ts +1 -0
- package/src/components/badge/badge.tsx +1 -0
- package/src/components/badge/badge.types.ts +1 -0
- package/src/components/block/block.tsx +4 -1
- package/src/components/block/block.types.ts +1 -0
- package/src/components/brand/brand.tsx +6 -2
- package/src/components/brand/brand.types.ts +1 -0
- package/src/components/button-group/button-group.tsx +1 -0
- package/src/components/button-group/button-group.types.ts +1 -0
- package/src/components/card/card.tsx +1 -0
- package/src/components/card/card.types.ts +1 -0
- package/src/components/catalog.tsx +15 -4
- package/src/components/close/close.tsx +1 -0
- package/src/components/container/container.tsx +1 -0
- package/src/components/empty-state/empty-state.tsx +1 -0
- package/src/components/field/field.tsx +1 -0
- package/src/components/field/field.types.ts +1 -0
- package/src/components/footer/footer.tsx +1 -0
- package/src/components/footer/footer.types.ts +1 -0
- package/src/components/grid/grid.tsx +1 -0
- package/src/components/grid/grid.types.ts +1 -0
- package/src/components/header/header.tsx +1 -0
- package/src/components/input-group/input-group.tsx +1 -0
- package/src/components/input-group/input-group.types.ts +1 -0
- package/src/components/jsx-types.ts +16 -0
- package/src/components/main/main.tsx +1 -0
- package/src/components/nav/nav.tsx +16 -2
- package/src/components/nav/nav.types.ts +2 -0
- package/src/components/navbar/navbar.tsx +19 -8
- package/src/components/overlays/dropdown-content.tsx +1 -0
- package/src/components/page/page.tsx +1 -0
- package/src/components/page-header/page-header.tsx +1 -0
- package/src/components/section/section.tsx +1 -0
- package/src/components/separator/separator.tsx +1 -0
- package/src/components/separator/separator.types.ts +1 -0
- package/src/components/sidebar/index.ts +1 -0
- package/src/components/sidebar/sidebar.tsx +45 -20
- package/src/components/sidebar/sidebar.types.ts +3 -0
- package/src/components/skeleton/skeleton.tsx +1 -0
- package/src/components/skeleton/skeleton.types.ts +1 -0
- package/src/components/spinner/spinner.tsx +1 -0
- package/src/components/stat/stat.tsx +1 -0
- package/src/components/stat/stat.types.ts +1 -0
- package/src/components/text/text.tsx +1 -0
- package/src/components/text/text.types.ts +1 -0
- package/src/components/theme/theme.tsx +43 -12
- package/src/components/toolbar/toolbar.tsx +1 -0
- package/src/components.ts +9 -0
- package/src/ssr.ts +102 -0
- package/src/themes/default/styles/base/text.css +4 -4
- package/src/themes/default/styles/layout/layout.css +108 -0
- package/src/themes/default/styles/shell/navbar.css +4 -1
- package/src/themes/default/tokens.css +1 -1
- package/src/themes/presets/ginger.css +3 -3
- package/templates/theme/styles/base/text.css +4 -4
- package/templates/theme/styles/display/progress-circle.css +2 -0
- package/templates/theme/styles/forms/input-group.css +2 -1
- package/templates/theme/styles/layout/layout.css +108 -0
- package/templates/theme/styles/overlays/toast.css +11 -0
- package/templates/theme/styles/shell/navbar.css +4 -1
- package/templates/theme/styles/shell/sidebar.css +18 -1
- package/templates/theme/tokens.css +1 -1
|
@@ -160,7 +160,7 @@
|
|
|
160
160
|
--ak-dark-color-primary-hover: color-mix(in oklch, var(--ak-dark-color-primary) 90%, transparent);
|
|
161
161
|
--ak-dark-color-primary-active: color-mix(in oklch, var(--ak-dark-color-primary) 84%, black);
|
|
162
162
|
--ak-dark-color-primary-soft: oklch(26.9% 0 0);
|
|
163
|
-
--ak-dark-color-primary-ink: oklch(
|
|
163
|
+
--ak-dark-color-primary-ink: oklch(98.5% 0 0);
|
|
164
164
|
--ak-dark-color-text: oklch(98.5% 0 0);
|
|
165
165
|
--ak-dark-color-text-muted: oklch(70.8% 0 0);
|
|
166
166
|
--ak-dark-color-text-subtle: oklch(55.6% 0 0);
|
|
@@ -573,19 +573,19 @@
|
|
|
573
573
|
}
|
|
574
574
|
|
|
575
575
|
:where([data-slot="text"][data-tone="success"]) {
|
|
576
|
-
color: var(--ak-color-success);
|
|
576
|
+
color: var(--ak-color-success-ink);
|
|
577
577
|
}
|
|
578
578
|
|
|
579
579
|
:where([data-slot="text"][data-tone="warning"]) {
|
|
580
|
-
color: var(--ak-color-warning);
|
|
580
|
+
color: var(--ak-color-warning-ink);
|
|
581
581
|
}
|
|
582
582
|
|
|
583
583
|
:where([data-slot="text"][data-tone="danger"]) {
|
|
584
|
-
color: var(--ak-color-danger);
|
|
584
|
+
color: var(--ak-color-danger-ink);
|
|
585
585
|
}
|
|
586
586
|
|
|
587
587
|
:where([data-slot="text"][data-tone="info"]) {
|
|
588
|
-
color: var(--ak-color-info);
|
|
588
|
+
color: var(--ak-color-info-ink);
|
|
589
589
|
}
|
|
590
590
|
|
|
591
591
|
:where([data-slot="text"][data-weight="normal"]) {
|
|
@@ -678,10 +678,12 @@
|
|
|
678
678
|
--ak-flex-grow-sm: var(--ak-flex-grow-base);
|
|
679
679
|
--ak-flex-grow-md: var(--ak-flex-grow-sm);
|
|
680
680
|
--ak-flex-grow-lg: var(--ak-flex-grow-md);
|
|
681
|
+
--ak-flex-grow-xl: var(--ak-flex-grow-lg);
|
|
681
682
|
--ak-flex-shrink-base: 1;
|
|
682
683
|
--ak-flex-shrink-sm: var(--ak-flex-shrink-base);
|
|
683
684
|
--ak-flex-shrink-md: var(--ak-flex-shrink-sm);
|
|
684
685
|
--ak-flex-shrink-lg: var(--ak-flex-shrink-md);
|
|
686
|
+
--ak-flex-shrink-xl: var(--ak-flex-shrink-lg);
|
|
685
687
|
--ak-flex-basis-base: auto;
|
|
686
688
|
--ak-flex-basis-sm: var(--ak-flex-basis-base);
|
|
687
689
|
--ak-flex-basis-md: var(--ak-flex-basis-sm);
|
|
@@ -690,24 +692,32 @@
|
|
|
690
692
|
--ak-min-width-sm: var(--ak-min-width-base);
|
|
691
693
|
--ak-min-width-md: var(--ak-min-width-sm);
|
|
692
694
|
--ak-min-width-lg: var(--ak-min-width-md);
|
|
695
|
+
--ak-min-width-xl: var(--ak-min-width-lg);
|
|
693
696
|
--ak-max-width-base: none;
|
|
694
697
|
--ak-max-width-sm: var(--ak-max-width-base);
|
|
695
698
|
--ak-max-width-md: var(--ak-max-width-sm);
|
|
696
699
|
--ak-max-width-lg: var(--ak-max-width-md);
|
|
700
|
+
--ak-max-width-xl: var(--ak-max-width-lg);
|
|
697
701
|
--ak-width-base: auto;
|
|
698
702
|
--ak-width-sm: var(--ak-width-base);
|
|
699
703
|
--ak-width-md: var(--ak-width-sm);
|
|
700
704
|
--ak-width-lg: var(--ak-width-md);
|
|
705
|
+
--ak-width-xl: var(--ak-width-lg);
|
|
701
706
|
--ak-min-height-base: auto;
|
|
702
707
|
--ak-min-height-sm: var(--ak-min-height-base);
|
|
703
708
|
--ak-min-height-md: var(--ak-min-height-sm);
|
|
704
709
|
--ak-min-height-lg: var(--ak-min-height-md);
|
|
710
|
+
--ak-min-height-xl: var(--ak-min-height-lg);
|
|
705
711
|
--ak-max-height-base: none;
|
|
706
712
|
--ak-max-height-sm: var(--ak-max-height-base);
|
|
713
|
+
--ak-max-height-md: var(--ak-max-height-sm);
|
|
714
|
+
--ak-max-height-lg: var(--ak-max-height-md);
|
|
715
|
+
--ak-max-height-xl: var(--ak-max-height-lg);
|
|
707
716
|
--ak-height-base: auto;
|
|
708
717
|
--ak-height-sm: var(--ak-height-base);
|
|
709
718
|
--ak-height-md: var(--ak-height-sm);
|
|
710
719
|
--ak-height-lg: var(--ak-height-md);
|
|
720
|
+
--ak-height-xl: var(--ak-height-lg);
|
|
711
721
|
--ak-m-base: 0;
|
|
712
722
|
--ak-m-sm: var(--ak-m-base);
|
|
713
723
|
--ak-m-md: var(--ak-m-sm);
|
|
@@ -762,6 +772,12 @@
|
|
|
762
772
|
--ak-border-sm: var(--ak-border-base);
|
|
763
773
|
--ak-border-md: var(--ak-border-sm);
|
|
764
774
|
--ak-border-lg: var(--ak-border-md);
|
|
775
|
+
--ak-border-xl: var(--ak-border-lg);
|
|
776
|
+
--ak-border-top-base: var(--ak-border-base);
|
|
777
|
+
--ak-border-top-sm: var(--ak-border-top-base);
|
|
778
|
+
--ak-border-top-md: var(--ak-border-top-sm);
|
|
779
|
+
--ak-border-top-lg: var(--ak-border-top-md);
|
|
780
|
+
--ak-border-top-xl: var(--ak-border-top-lg);
|
|
765
781
|
--ak-border-bottom-base: var(--ak-border-base);
|
|
766
782
|
--ak-border-bottom-sm: var(--ak-border-bottom-base);
|
|
767
783
|
--ak-border-bottom-md: var(--ak-border-bottom-sm);
|
|
@@ -770,6 +786,7 @@
|
|
|
770
786
|
--ak-border-right-sm: var(--ak-border-right-base);
|
|
771
787
|
--ak-border-right-md: var(--ak-border-right-sm);
|
|
772
788
|
--ak-border-right-lg: var(--ak-border-right-md);
|
|
789
|
+
--ak-border-right-xl: var(--ak-border-right-lg);
|
|
773
790
|
--ak-border-radius-base: 0;
|
|
774
791
|
--ak-border-radius-sm: var(--ak-border-radius-base);
|
|
775
792
|
--ak-border-radius-md: var(--ak-border-radius-sm);
|
|
@@ -778,10 +795,12 @@
|
|
|
778
795
|
--ak-background-sm: var(--ak-background-base);
|
|
779
796
|
--ak-background-md: var(--ak-background-sm);
|
|
780
797
|
--ak-background-lg: var(--ak-background-md);
|
|
798
|
+
--ak-background-xl: var(--ak-background-lg);
|
|
781
799
|
--ak-box-shadow-base: none;
|
|
782
800
|
--ak-box-shadow-sm: var(--ak-box-shadow-base);
|
|
783
801
|
--ak-box-shadow-md: var(--ak-box-shadow-sm);
|
|
784
802
|
--ak-box-shadow-lg: var(--ak-box-shadow-md);
|
|
803
|
+
--ak-box-shadow-xl: var(--ak-box-shadow-lg);
|
|
785
804
|
box-sizing: border-box;
|
|
786
805
|
display: var(--ak-display-base, flex);
|
|
787
806
|
flex-direction: var(--ak-flex-direction-base, column);
|
|
@@ -815,6 +834,7 @@
|
|
|
815
834
|
overflow-x: var(--ak-overflow-x-base, var(--ak-overflow-base, visible));
|
|
816
835
|
overflow-y: var(--ak-overflow-y-base, var(--ak-overflow-base, visible));
|
|
817
836
|
border: var(--ak-border-base, 0 solid transparent);
|
|
837
|
+
border-top: var(--ak-border-top-base, var(--ak-border-base, 0 solid transparent));
|
|
818
838
|
border-bottom: var(--ak-border-bottom-base, var(--ak-border-base, 0 solid transparent));
|
|
819
839
|
border-right: var(--ak-border-right-base, var(--ak-border-base, 0 solid transparent));
|
|
820
840
|
border-radius: var(--ak-border-radius-base, 0);
|
|
@@ -856,6 +876,7 @@
|
|
|
856
876
|
overflow-x: var(--ak-overflow-x-sm, var(--ak-overflow-x-base, var(--ak-overflow-sm, var(--ak-overflow-base, visible))));
|
|
857
877
|
overflow-y: var(--ak-overflow-y-sm, var(--ak-overflow-y-base, var(--ak-overflow-sm, var(--ak-overflow-base, visible))));
|
|
858
878
|
border: var(--ak-border-sm, var(--ak-border-base, 0 solid transparent));
|
|
879
|
+
border-top: var(--ak-border-top-sm, var(--ak-border-top-base, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent))));
|
|
859
880
|
border-bottom: var(--ak-border-bottom-sm, var(--ak-border-bottom-base, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent))));
|
|
860
881
|
border-right: var(--ak-border-right-sm, var(--ak-border-right-base, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent))));
|
|
861
882
|
border-radius: var(--ak-border-radius-sm, var(--ak-border-radius-base, 0));
|
|
@@ -877,6 +898,7 @@
|
|
|
877
898
|
max-width: var(--ak-max-width-md, var(--ak-max-width-sm, var(--ak-max-width-base, none)));
|
|
878
899
|
width: var(--ak-width-md, var(--ak-width-sm, var(--ak-width-base, auto)));
|
|
879
900
|
min-height: var(--ak-min-height-md, var(--ak-min-height-sm, var(--ak-min-height-base, auto)));
|
|
901
|
+
max-height: var(--ak-max-height-md, var(--ak-max-height-sm, var(--ak-max-height-base, none)));
|
|
880
902
|
height: var(--ak-height-md, var(--ak-height-sm, var(--ak-height-base, auto)));
|
|
881
903
|
margin: var(--ak-m-md, var(--ak-m-sm, var(--ak-m-base, 0)));
|
|
882
904
|
margin-inline: var(--ak-mx-md, var(--ak-mx-sm, var(--ak-mx-base, var(--ak-m-md, var(--ak-m-sm, var(--ak-m-base, 0))))));
|
|
@@ -888,6 +910,7 @@
|
|
|
888
910
|
top: var(--ak-top-md, var(--ak-top-sm, var(--ak-top-base, auto)));
|
|
889
911
|
z-index: var(--ak-z-index-md, var(--ak-z-index-sm, var(--ak-z-index-base, auto)));
|
|
890
912
|
border: var(--ak-border-md, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent)));
|
|
913
|
+
border-top: var(--ak-border-top-md, var(--ak-border-top-sm, var(--ak-border-top-base, var(--ak-border-md, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent))))));
|
|
891
914
|
border-bottom: var(--ak-border-bottom-md, var(--ak-border-bottom-sm, var(--ak-border-bottom-base, var(--ak-border-md, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent))))));
|
|
892
915
|
border-right: var(--ak-border-right-md, var(--ak-border-right-sm, var(--ak-border-right-base, var(--ak-border-md, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent))))));
|
|
893
916
|
border-radius: var(--ak-border-radius-md, var(--ak-border-radius-sm, var(--ak-border-radius-base, 0)));
|
|
@@ -920,6 +943,7 @@
|
|
|
920
943
|
top: var(--ak-top-lg, var(--ak-top-md, var(--ak-top-sm, var(--ak-top-base, auto))));
|
|
921
944
|
z-index: var(--ak-z-index-lg, var(--ak-z-index-md, var(--ak-z-index-sm, var(--ak-z-index-base, auto))));
|
|
922
945
|
border: var(--ak-border-lg, var(--ak-border-md, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent))));
|
|
946
|
+
border-top: var(--ak-border-top-lg, var(--ak-border-top-md, var(--ak-border-top-sm, var(--ak-border-top-base, var(--ak-border-lg, var(--ak-border-md, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent))))))));
|
|
923
947
|
border-bottom: var(--ak-border-bottom-lg, var(--ak-border-bottom-md, var(--ak-border-bottom-sm, var(--ak-border-bottom-base, var(--ak-border-lg, var(--ak-border-md, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent))))))));
|
|
924
948
|
border-right: var(--ak-border-right-lg, var(--ak-border-right-md, var(--ak-border-right-sm, var(--ak-border-right-base, var(--ak-border-lg, var(--ak-border-md, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent))))))));
|
|
925
949
|
border-radius: var(--ak-border-radius-lg, var(--ak-border-radius-md, var(--ak-border-radius-sm, var(--ak-border-radius-base, 0))));
|
|
@@ -935,9 +959,14 @@
|
|
|
935
959
|
align-items: var(--ak-align-items-xl, var(--ak-align-items-lg, var(--ak-align-items-md, var(--ak-align-items-sm, var(--ak-align-items-base, stretch)))));
|
|
936
960
|
justify-content: var(--ak-justify-content-xl, var(--ak-justify-content-lg, var(--ak-justify-content-md, var(--ak-justify-content-sm, var(--ak-justify-content-base, flex-start)))));
|
|
937
961
|
gap: var(--ak-gap-xl, var(--ak-gap-lg, var(--ak-gap-md, var(--ak-gap-sm, var(--ak-gap-base, 0)))));
|
|
962
|
+
flex-grow: var(--ak-flex-grow-xl, var(--ak-flex-grow-lg, var(--ak-flex-grow-md, var(--ak-flex-grow-sm, var(--ak-flex-grow-base, 0)))));
|
|
963
|
+
flex-shrink: var(--ak-flex-shrink-xl, var(--ak-flex-shrink-lg, var(--ak-flex-shrink-md, var(--ak-flex-shrink-sm, var(--ak-flex-shrink-base, 1)))));
|
|
964
|
+
min-width: var(--ak-min-width-xl, var(--ak-min-width-lg, var(--ak-min-width-md, var(--ak-min-width-sm, var(--ak-min-width-base, 0)))));
|
|
938
965
|
width: var(--ak-width-xl, var(--ak-width-lg, var(--ak-width-md, var(--ak-width-sm, var(--ak-width-base, auto)))));
|
|
939
966
|
max-width: var(--ak-max-width-xl, var(--ak-max-width-lg, var(--ak-max-width-md, var(--ak-max-width-sm, var(--ak-max-width-base, none)))));
|
|
940
967
|
min-height: var(--ak-min-height-xl, var(--ak-min-height-lg, var(--ak-min-height-md, var(--ak-min-height-sm, var(--ak-min-height-base, auto)))));
|
|
968
|
+
max-height: var(--ak-max-height-xl, var(--ak-max-height-lg, var(--ak-max-height-md, var(--ak-max-height-sm, var(--ak-max-height-base, none)))));
|
|
969
|
+
height: var(--ak-height-xl, var(--ak-height-lg, var(--ak-height-md, var(--ak-height-sm, var(--ak-height-base, auto)))));
|
|
941
970
|
margin: var(--ak-m-xl, var(--ak-m-lg, var(--ak-m-md, var(--ak-m-sm, var(--ak-m-base, 0)))));
|
|
942
971
|
margin-inline: var(--ak-mx-xl, var(--ak-mx-lg, var(--ak-mx-md, var(--ak-mx-sm, var(--ak-mx-base, var(--ak-m-xl, var(--ak-m-lg, var(--ak-m-md, var(--ak-m-sm, var(--ak-m-base, 0))))))))));
|
|
943
972
|
margin-block: var(--ak-my-xl, var(--ak-my-lg, var(--ak-my-md, var(--ak-my-sm, var(--ak-my-base, var(--ak-m-xl, var(--ak-m-lg, var(--ak-m-md, var(--ak-m-sm, var(--ak-m-base, 0))))))))));
|
|
@@ -948,6 +977,7 @@
|
|
|
948
977
|
top: var(--ak-top-xl, var(--ak-top-lg, var(--ak-top-md, var(--ak-top-sm, var(--ak-top-base, auto)))));
|
|
949
978
|
z-index: var(--ak-z-index-xl, var(--ak-z-index-lg, var(--ak-z-index-md, var(--ak-z-index-sm, var(--ak-z-index-base, auto)))));
|
|
950
979
|
border: var(--ak-border-xl, var(--ak-border-lg, var(--ak-border-md, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent)))));
|
|
980
|
+
border-top: var(--ak-border-top-xl, var(--ak-border-top-lg, var(--ak-border-top-md, var(--ak-border-top-sm, var(--ak-border-top-base, var(--ak-border-xl, var(--ak-border-lg, var(--ak-border-md, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent))))))))));
|
|
951
981
|
border-bottom: var(--ak-border-bottom-xl, var(--ak-border-bottom-lg, var(--ak-border-bottom-md, var(--ak-border-bottom-sm, var(--ak-border-bottom-base, var(--ak-border-xl, var(--ak-border-lg, var(--ak-border-md, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent))))))))));
|
|
952
982
|
border-right: var(--ak-border-right-xl, var(--ak-border-right-lg, var(--ak-border-right-md, var(--ak-border-right-sm, var(--ak-border-right-base, var(--ak-border-xl, var(--ak-border-lg, var(--ak-border-md, var(--ak-border-sm, var(--ak-border-base, 0 solid transparent))))))))));
|
|
953
983
|
border-radius: var(--ak-border-radius-xl, var(--ak-border-radius-lg, var(--ak-border-radius-md, var(--ak-border-radius-sm, var(--ak-border-radius-base, 0)))));
|
|
@@ -1421,7 +1451,7 @@
|
|
|
1421
1451
|
display: inline-flex;
|
|
1422
1452
|
}
|
|
1423
1453
|
|
|
1424
|
-
:where([data-slot="navbar"][data-collapse-at]) :where([data-slot="navbar-collapse"][open] [data-slot="navbar-content"]) {
|
|
1454
|
+
:where([data-slot="navbar"][data-collapse-at]) :where([data-slot="navbar-collapse"] [data-slot="navbar-content"][data-state="open"], [data-slot="navbar-collapse"][open] [data-slot="navbar-content"]) {
|
|
1425
1455
|
display: flex;
|
|
1426
1456
|
}
|
|
1427
1457
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@askrjs/themes",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "Default theme tokens, styles, and component presets for Askr apps.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"askr",
|
|
@@ -54,6 +54,10 @@
|
|
|
54
54
|
"types": "./dist/theme.d.ts",
|
|
55
55
|
"import": "./dist/theme.js"
|
|
56
56
|
},
|
|
57
|
+
"./ssr": {
|
|
58
|
+
"types": "./dist/ssr.d.ts",
|
|
59
|
+
"import": "./dist/ssr.js"
|
|
60
|
+
},
|
|
57
61
|
"./accordion": {
|
|
58
62
|
"types": "./dist/components.d.ts",
|
|
59
63
|
"import": "./dist/components.js"
|
|
@@ -329,7 +333,7 @@
|
|
|
329
333
|
},
|
|
330
334
|
"devDependencies": {
|
|
331
335
|
"@askrjs/askr": ">=0.0.64 <0.1.0",
|
|
332
|
-
"@askrjs/ui": ">=0.0.
|
|
336
|
+
"@askrjs/ui": ">=0.0.13 <0.1.0",
|
|
333
337
|
"@askrjs/vite": ">=0.0.5 <0.1.0",
|
|
334
338
|
"@tsdown/css": "0.22.8",
|
|
335
339
|
"@types/node": "^26.0.0",
|
|
@@ -343,7 +347,7 @@
|
|
|
343
347
|
},
|
|
344
348
|
"peerDependencies": {
|
|
345
349
|
"@askrjs/askr": ">=0.0.64 <0.1.0",
|
|
346
|
-
"@askrjs/ui": ">=0.0.
|
|
350
|
+
"@askrjs/ui": ">=0.0.13 <0.1.0"
|
|
347
351
|
},
|
|
348
352
|
"engines": {
|
|
349
353
|
"node": ">=18"
|
|
@@ -66,6 +66,7 @@ export type BlockLayoutProps = {
|
|
|
66
66
|
zIndex?: ResponsiveValue<BlockZIndex>;
|
|
67
67
|
background?: ResponsiveValue<BlockBackground>;
|
|
68
68
|
border?: ResponsiveValue<boolean>;
|
|
69
|
+
borderTop?: ResponsiveValue<boolean>;
|
|
69
70
|
borderBottom?: ResponsiveValue<boolean>;
|
|
70
71
|
borderRight?: ResponsiveValue<boolean>;
|
|
71
72
|
radius?: ResponsiveValue<BlockRadius>;
|
|
@@ -163,6 +164,7 @@ const BLOCK_LAYOUT_KEYS = new Set<keyof BlockLayoutProps>([
|
|
|
163
164
|
"zIndex",
|
|
164
165
|
"background",
|
|
165
166
|
"border",
|
|
167
|
+
"borderTop",
|
|
166
168
|
"borderBottom",
|
|
167
169
|
"borderRight",
|
|
168
170
|
"radius",
|
|
@@ -202,7 +204,8 @@ function resolveSpaceValue(value: string | number): string | number {
|
|
|
202
204
|
return resolveTokenValue(value, SPACE_TOKEN_MAP);
|
|
203
205
|
}
|
|
204
206
|
|
|
205
|
-
function resolveSizeValue(value: string): string {
|
|
207
|
+
function resolveSizeValue(value: string, axis: "inline" | "block"): string {
|
|
208
|
+
if (value === "screen") return axis === "inline" ? "100dvw" : "100dvh";
|
|
206
209
|
return String(resolveTokenValue(value, SIZE_TOKEN_MAP));
|
|
207
210
|
}
|
|
208
211
|
|
|
@@ -289,31 +292,38 @@ export function applyBlockLayoutStyles(
|
|
|
289
292
|
setResponsiveVar(styles, "mx", props.marginX, resolveSpaceValue);
|
|
290
293
|
setResponsiveVar(styles, "my", props.marginY, resolveSpaceValue);
|
|
291
294
|
|
|
292
|
-
setResponsiveVar(styles, "width", props.width, resolveSizeValue);
|
|
293
|
-
setResponsiveVar(styles, "min-width", props.minWidth,
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
setResponsiveVar(styles, "
|
|
297
|
-
|
|
295
|
+
setResponsiveVar(styles, "width", props.width, (value) => resolveSizeValue(value, "inline"));
|
|
296
|
+
setResponsiveVar(styles, "min-width", props.minWidth, (value) =>
|
|
297
|
+
resolveSizeValue(value, "inline"),
|
|
298
|
+
);
|
|
299
|
+
setResponsiveVar(styles, "max-width", props.maxWidth, (value) =>
|
|
300
|
+
resolveSizeValue(value, "inline"),
|
|
301
|
+
);
|
|
302
|
+
setResponsiveVar(styles, "height", props.height, (value) => resolveSizeValue(value, "block"));
|
|
303
|
+
setResponsiveVar(styles, "min-height", props.minHeight, (value) =>
|
|
304
|
+
resolveSizeValue(value, "block"),
|
|
305
|
+
);
|
|
306
|
+
setResponsiveVar(styles, "max-height", props.maxHeight, (value) =>
|
|
307
|
+
resolveSizeValue(value, "block"),
|
|
308
|
+
);
|
|
298
309
|
|
|
299
310
|
if (props.rowFrom !== undefined) {
|
|
300
311
|
styles[`--ak-flex-direction-${props.rowFrom}`] = "row";
|
|
301
312
|
}
|
|
302
|
-
setResponsiveVar(styles, "flex-direction", props.direction, (value) => value);
|
|
303
|
-
setResponsiveVar(styles, "align-items", props.align, resolveAlignValue);
|
|
304
|
-
setResponsiveVar(styles, "justify-content", props.justify, resolveJustifyValue);
|
|
305
|
-
setResponsiveVar(styles, "gap", props.gap, resolveSpaceValue);
|
|
306
|
-
setResponsiveVar(styles, "flex-grow", props.grow, resolveFlexFlag);
|
|
307
|
-
setResponsiveVar(styles, "flex-shrink", props.shrink, resolveFlexFlag);
|
|
308
|
-
|
|
309
313
|
if (props.center !== undefined) {
|
|
310
314
|
setResponsiveVar(styles, "align-items", props.center, (value) =>
|
|
311
|
-
value ? "center" :
|
|
315
|
+
value ? "center" : "stretch",
|
|
312
316
|
);
|
|
313
317
|
setResponsiveVar(styles, "justify-content", props.center, (value) =>
|
|
314
|
-
value ? "center" :
|
|
318
|
+
value ? "center" : "flex-start",
|
|
315
319
|
);
|
|
316
320
|
}
|
|
321
|
+
setResponsiveVar(styles, "flex-direction", props.direction, (value) => value);
|
|
322
|
+
setResponsiveVar(styles, "align-items", props.align, resolveAlignValue);
|
|
323
|
+
setResponsiveVar(styles, "justify-content", props.justify, resolveJustifyValue);
|
|
324
|
+
setResponsiveVar(styles, "gap", props.gap, resolveSpaceValue);
|
|
325
|
+
setResponsiveVar(styles, "flex-grow", props.grow, resolveFlexFlag);
|
|
326
|
+
setResponsiveVar(styles, "flex-shrink", props.shrink, resolveFlexFlag);
|
|
317
327
|
|
|
318
328
|
if (props.sticky) {
|
|
319
329
|
styles["--ak-position-base"] = "sticky";
|
|
@@ -327,6 +337,7 @@ export function applyBlockLayoutStyles(
|
|
|
327
337
|
String(resolveTokenValue(value, BACKGROUND_TOKEN_MAP)),
|
|
328
338
|
);
|
|
329
339
|
setResponsiveVar(styles, "border", props.border, resolveBorderValue);
|
|
340
|
+
setResponsiveVar(styles, "border-top", props.borderTop, resolveBorderValue);
|
|
330
341
|
setResponsiveVar(styles, "border-bottom", props.borderBottom, resolveBorderValue);
|
|
331
342
|
setResponsiveVar(styles, "border-right", props.borderRight, resolveBorderValue);
|
|
332
343
|
setResponsiveVar(styles, "border-radius", props.radius, resolveRadiusValue);
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
export
|
|
2
|
-
const value = values.filter((item) => typeof item === "string" && item.trim()).join(" ");
|
|
1
|
+
export type ClassAccessor = () => string | undefined;
|
|
3
2
|
|
|
3
|
+
function readClassValue(value: unknown): string | undefined {
|
|
4
|
+
const resolved = typeof value === "function" ? (value as () => unknown)() : value;
|
|
5
|
+
return typeof resolved === "string" && resolved.trim() ? resolved.trim() : undefined;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function classes(...values: Array<unknown>): string | ClassAccessor | undefined {
|
|
9
|
+
if (values.some((value) => typeof value === "function")) {
|
|
10
|
+
return () => {
|
|
11
|
+
const value = values.map(readClassValue).filter(Boolean).join(" ");
|
|
12
|
+
return value || undefined;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const value = values.map(readClassValue).filter(Boolean).join(" ");
|
|
4
17
|
return value || undefined;
|
|
5
18
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JSXElement } from "@askrjs/askr/foundations";
|
|
2
|
-
import { jsx } from "@askrjs/askr/jsx-runtime";
|
|
2
|
+
import { jsx, type JSX } from "@askrjs/askr/jsx-runtime";
|
|
3
3
|
|
|
4
4
|
const renderIntrinsicElement = jsx as (type: string, props: Record<string, unknown>) => JSX.Element;
|
|
5
5
|
|
|
@@ -1,6 +1,108 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Askr from "@askrjs/askr";
|
|
2
2
|
|
|
3
3
|
const cssPropertyNameCache = new Map<string, string>();
|
|
4
|
+
const MAX_PROPERTY_CACHE = 256;
|
|
5
|
+
|
|
6
|
+
const CSS_UNSAFE_RE = /[{}<>\\]/;
|
|
7
|
+
const CSS_URI_SCHEME_RE = /(?:^|[\s(,])([a-z][a-z0-9+.-]*):/i;
|
|
8
|
+
const CSS_FUNCTION_NAME_RE = /([a-z-][a-z0-9-]*)\s*\(/gi;
|
|
9
|
+
const CSS_ALLOWED_FUNCTIONS = new Set([
|
|
10
|
+
"var",
|
|
11
|
+
"calc",
|
|
12
|
+
"min",
|
|
13
|
+
"max",
|
|
14
|
+
"clamp",
|
|
15
|
+
"rgb",
|
|
16
|
+
"rgba",
|
|
17
|
+
"hsl",
|
|
18
|
+
"hsla",
|
|
19
|
+
"lab",
|
|
20
|
+
"lch",
|
|
21
|
+
"oklab",
|
|
22
|
+
"oklch",
|
|
23
|
+
"color",
|
|
24
|
+
"color-mix",
|
|
25
|
+
"translate",
|
|
26
|
+
"translatex",
|
|
27
|
+
"translatey",
|
|
28
|
+
"translatez",
|
|
29
|
+
"scale",
|
|
30
|
+
"scalex",
|
|
31
|
+
"scaley",
|
|
32
|
+
"scalez",
|
|
33
|
+
"rotate",
|
|
34
|
+
"rotatex",
|
|
35
|
+
"rotatey",
|
|
36
|
+
"rotatez",
|
|
37
|
+
"skew",
|
|
38
|
+
"skewx",
|
|
39
|
+
"skewy",
|
|
40
|
+
"matrix",
|
|
41
|
+
"matrix3d",
|
|
42
|
+
"linear-gradient",
|
|
43
|
+
"radial-gradient",
|
|
44
|
+
"conic-gradient",
|
|
45
|
+
"repeating-linear-gradient",
|
|
46
|
+
"repeating-radial-gradient",
|
|
47
|
+
"repeating-conic-gradient",
|
|
48
|
+
"cubic-bezier",
|
|
49
|
+
"steps",
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
function isSafeCssPropertyName(name: string): boolean {
|
|
53
|
+
if (name.startsWith("--")) return /^--[a-zA-Z0-9_-]+$/.test(name);
|
|
54
|
+
return /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(name);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function isSafeCssValue(value: string): boolean {
|
|
58
|
+
if (CSS_UNSAFE_RE.test(value) || CSS_URI_SCHEME_RE.test(value)) return false;
|
|
59
|
+
|
|
60
|
+
for (const match of value.matchAll(CSS_FUNCTION_NAME_RE)) {
|
|
61
|
+
if (!CSS_ALLOWED_FUNCTIONS.has(match[1]!.toLowerCase())) return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function splitCssDeclarations(value: string): string[] {
|
|
68
|
+
const declarations: string[] = [];
|
|
69
|
+
let start = 0;
|
|
70
|
+
let depth = 0;
|
|
71
|
+
let quote: string | undefined;
|
|
72
|
+
|
|
73
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
74
|
+
const char = value[index]!;
|
|
75
|
+
if (quote) {
|
|
76
|
+
if (char === quote && value[index - 1] !== "\\") quote = undefined;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (char === '"' || char === "'") {
|
|
80
|
+
quote = char;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (char === "(") depth += 1;
|
|
84
|
+
if (char === ")" && depth > 0) depth -= 1;
|
|
85
|
+
if (char === ";" && depth === 0) {
|
|
86
|
+
declarations.push(value.slice(start, index));
|
|
87
|
+
start = index + 1;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
declarations.push(value.slice(start));
|
|
92
|
+
return declarations;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function serializeCssString(value: string): string {
|
|
96
|
+
const entries: Array<[string, string]> = [];
|
|
97
|
+
for (const candidate of splitCssDeclarations(value)) {
|
|
98
|
+
const separator = candidate.indexOf(":");
|
|
99
|
+
if (separator <= 0) continue;
|
|
100
|
+
const key = candidate.slice(0, separator).trim();
|
|
101
|
+
const cssValue = candidate.slice(separator + 1).trim();
|
|
102
|
+
if (key && cssValue) entries.push([key, cssValue]);
|
|
103
|
+
}
|
|
104
|
+
return serializeCssDeclarations(Object.fromEntries(entries));
|
|
105
|
+
}
|
|
4
106
|
|
|
5
107
|
function cssPropertyName(name: string): string {
|
|
6
108
|
let cached = cssPropertyNameCache.get(name);
|
|
@@ -20,7 +122,9 @@ function cssPropertyName(name: string): string {
|
|
|
20
122
|
}
|
|
21
123
|
}
|
|
22
124
|
|
|
23
|
-
cssPropertyNameCache.
|
|
125
|
+
if (cssPropertyNameCache.size < MAX_PROPERTY_CACHE) {
|
|
126
|
+
cssPropertyNameCache.set(name, result);
|
|
127
|
+
}
|
|
24
128
|
return result;
|
|
25
129
|
}
|
|
26
130
|
|
|
@@ -34,7 +138,17 @@ export function serializeCssDeclarations(styles: Record<string, unknown>): strin
|
|
|
34
138
|
continue;
|
|
35
139
|
}
|
|
36
140
|
|
|
37
|
-
const
|
|
141
|
+
const rawProperty = key.trim();
|
|
142
|
+
if (!isSafeCssPropertyName(rawProperty)) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const property = cssPropertyName(rawProperty).trim();
|
|
146
|
+
const cssValue = String(value).trim();
|
|
147
|
+
if (!cssValue || !isSafeCssValue(cssValue)) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const declaration = `${property}:${cssValue}`;
|
|
38
152
|
result = result ? `${result};${declaration}` : declaration;
|
|
39
153
|
}
|
|
40
154
|
|
|
@@ -59,16 +173,86 @@ export function mergeCssVar(style: unknown, name: string, value: string): string
|
|
|
59
173
|
|
|
60
174
|
const STYLE_REGISTRY_ATTR = "data-askr-style-registry";
|
|
61
175
|
const STYLE_CLASS_PREFIX = "ak-style-";
|
|
176
|
+
const MAX_STYLE_RULES = 512;
|
|
177
|
+
const MAX_SSR_STYLE_CACHE = 4096;
|
|
62
178
|
|
|
63
|
-
|
|
179
|
+
type StyleRule = {
|
|
180
|
+
className: string;
|
|
181
|
+
declarations: string;
|
|
182
|
+
rule: string;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const styleRulesByClass = new Map<string, StyleRule>();
|
|
64
186
|
type StyleRegistry = {
|
|
65
187
|
element: HTMLStyleElement;
|
|
66
|
-
|
|
188
|
+
ruleCount: number;
|
|
189
|
+
rules: Map<string, StyleRule>;
|
|
67
190
|
};
|
|
68
191
|
const registries = new WeakMap<Document, Map<string, StyleRegistry>>();
|
|
69
|
-
|
|
192
|
+
function countRegisteredRules(value: string | null): number {
|
|
193
|
+
return value?.match(/\.ak-style-[a-z0-9]+\{/g)?.length ?? 0;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function styleClassName(declarations: string): string {
|
|
197
|
+
let first = 0xdeadbeef ^ declarations.length;
|
|
198
|
+
let second = 0x41c6ce57 ^ declarations.length;
|
|
199
|
+
|
|
200
|
+
for (let index = 0; index < declarations.length; index += 1) {
|
|
201
|
+
const code = declarations.charCodeAt(index);
|
|
202
|
+
first = Math.imul(first ^ code, 2_654_435_761);
|
|
203
|
+
second = Math.imul(second ^ code, 1_597_334_677);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
first =
|
|
207
|
+
Math.imul(first ^ (first >>> 16), 2_246_822_507) ^
|
|
208
|
+
Math.imul(second ^ (second >>> 13), 3_266_489_909);
|
|
209
|
+
second =
|
|
210
|
+
Math.imul(second ^ (second >>> 16), 2_246_822_507) ^
|
|
211
|
+
Math.imul(first ^ (first >>> 13), 3_266_489_909);
|
|
212
|
+
|
|
213
|
+
return `${STYLE_CLASS_PREFIX}${(second >>> 0).toString(36)}${(first >>> 0).toString(36)}`;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function escapeStyleRawText(value: string): string {
|
|
217
|
+
return value.replace(/<\//g, "<\\/");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function styleRuleFor(declarations: string): StyleRule {
|
|
221
|
+
const className = styleClassName(declarations);
|
|
222
|
+
const existing = styleRulesByClass.get(className);
|
|
223
|
+
if (existing) {
|
|
224
|
+
if (existing.declarations !== declarations) {
|
|
225
|
+
throw new RangeError("Theme style class collision detected.");
|
|
226
|
+
}
|
|
227
|
+
return existing;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const entry = {
|
|
231
|
+
className,
|
|
232
|
+
declarations,
|
|
233
|
+
rule: `.${className}{${escapeStyleRawText(declarations)}}`,
|
|
234
|
+
};
|
|
235
|
+
return entry;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function rememberStyleRule(entry: StyleRule): void {
|
|
239
|
+
styleRulesByClass.delete(entry.className);
|
|
240
|
+
styleRulesByClass.set(entry.className, entry);
|
|
241
|
+
while (styleRulesByClass.size > MAX_SSR_STYLE_CACHE) {
|
|
242
|
+
const oldest = styleRulesByClass.keys().next().value;
|
|
243
|
+
if (oldest === undefined) break;
|
|
244
|
+
styleRulesByClass.delete(oldest);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
70
247
|
|
|
71
|
-
|
|
248
|
+
function registerSSRStyle(entry: StyleRule): void {
|
|
249
|
+
const register = (
|
|
250
|
+
Askr as typeof Askr & {
|
|
251
|
+
registerSSRStyle?: (id: string, cssText: string) => void;
|
|
252
|
+
}
|
|
253
|
+
).registerSSRStyle;
|
|
254
|
+
register?.(entry.className, entry.rule);
|
|
255
|
+
}
|
|
72
256
|
|
|
73
257
|
function ensureStyleRegistry(nonce: string | undefined): StyleRegistry | null {
|
|
74
258
|
if (typeof document === "undefined") return null;
|
|
@@ -81,17 +265,26 @@ function ensureStyleRegistry(nonce: string | undefined): StyleRegistry | null {
|
|
|
81
265
|
const current = documentRegistries.get(key);
|
|
82
266
|
if (current?.element.isConnected) return current;
|
|
83
267
|
|
|
84
|
-
const styleElement =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
268
|
+
const styleElement =
|
|
269
|
+
Array.from(document.querySelectorAll<HTMLStyleElement>(`style[${STYLE_REGISTRY_ATTR}]`)).find(
|
|
270
|
+
(element) => (element.nonce || undefined) === nonce,
|
|
271
|
+
) ?? document.createElement("style");
|
|
272
|
+
if (!styleElement.isConnected) {
|
|
273
|
+
styleElement.setAttribute(STYLE_REGISTRY_ATTR, "true");
|
|
274
|
+
if (nonce !== undefined) styleElement.nonce = nonce;
|
|
275
|
+
(document.head ?? document.documentElement).append(styleElement);
|
|
276
|
+
}
|
|
277
|
+
const registry: StyleRegistry = {
|
|
278
|
+
element: styleElement,
|
|
279
|
+
ruleCount: countRegisteredRules(styleElement.textContent),
|
|
280
|
+
rules: new Map(),
|
|
281
|
+
};
|
|
89
282
|
documentRegistries.set(key, registry);
|
|
90
283
|
return registry;
|
|
91
284
|
}
|
|
92
285
|
|
|
93
286
|
function normalizeDeclarations(declarations: string): string {
|
|
94
|
-
return declarations
|
|
287
|
+
return serializeCssString(declarations);
|
|
95
288
|
}
|
|
96
289
|
|
|
97
290
|
export function styleDeclarationsToClass(declarations: string | undefined): string | undefined {
|
|
@@ -100,27 +293,48 @@ export function styleDeclarationsToClass(declarations: string | undefined): stri
|
|
|
100
293
|
const normalized = normalizeDeclarations(declarations);
|
|
101
294
|
if (!normalized) return undefined;
|
|
102
295
|
|
|
103
|
-
const
|
|
296
|
+
const entry = styleRuleFor(normalized);
|
|
297
|
+
const nonce = Askr.cspNonce();
|
|
104
298
|
const registry = ensureStyleRegistry(nonce);
|
|
105
299
|
const registered = registry?.rules.get(normalized);
|
|
106
|
-
if (registered)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (className === undefined) {
|
|
110
|
-
className = `${STYLE_CLASS_PREFIX}${++nextStyleClassId}`;
|
|
111
|
-
styleClassCache.set(normalized, className);
|
|
300
|
+
if (registered) {
|
|
301
|
+
registerSSRStyle(registered);
|
|
302
|
+
return registered.className;
|
|
112
303
|
}
|
|
113
304
|
|
|
114
305
|
if (registry) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
306
|
+
if (!registry.rules.has(normalized) && !registry.element.textContent?.includes(entry.rule)) {
|
|
307
|
+
if (registry.ruleCount >= MAX_STYLE_RULES) {
|
|
308
|
+
throw new RangeError("Theme style registry capacity exceeded.");
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (!registry.element.textContent?.includes(entry.rule)) {
|
|
312
|
+
registry.element.append(entry.rule, "\n");
|
|
313
|
+
registry.ruleCount += 1;
|
|
314
|
+
}
|
|
315
|
+
registry.rules.set(normalized, entry);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
rememberStyleRule(entry);
|
|
319
|
+
registerSSRStyle(entry);
|
|
320
|
+
|
|
321
|
+
return entry.className;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export function styleRulesForHtml(html: string): string[] {
|
|
325
|
+
const rules = new Map<string, string>();
|
|
326
|
+
const classAttributePattern = /\sclass=(?:"([^"]*)"|'([^']*)')/g;
|
|
327
|
+
|
|
328
|
+
for (const attribute of html.matchAll(classAttributePattern)) {
|
|
329
|
+
const value = attribute[1] ?? attribute[2] ?? "";
|
|
330
|
+
for (const className of value.split(/\s+/)) {
|
|
331
|
+
const entry = styleRulesByClass.get(className);
|
|
332
|
+
if (entry) rules.set(className, entry.rule);
|
|
333
|
+
if (rules.size > MAX_STYLE_RULES) {
|
|
118
334
|
throw new RangeError("Theme style registry capacity exceeded.");
|
|
119
|
-
|
|
120
|
-
registry.rules.set(normalized, { className, rule });
|
|
121
|
-
styleElement.append(rule, "\n");
|
|
335
|
+
}
|
|
122
336
|
}
|
|
123
337
|
}
|
|
124
338
|
|
|
125
|
-
return
|
|
339
|
+
return Array.from(rules.values());
|
|
126
340
|
}
|