@code-coaching/vuetiful 0.25.0 → 0.27.0
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 +47 -55
- package/dist/css/animations.css +2 -0
- package/{src → dist}/css/overrides/quasar.css +73 -58
- package/{src/styles → dist/css}/transitions/slide.css +6 -0
- package/dist/favicon.ico +0 -0
- package/dist/types/components/atoms/VAvatar.vue.d.ts +39 -90
- package/dist/types/components/atoms/VBadge.vue.d.ts +34 -21
- package/dist/types/components/atoms/VButton.vue.d.ts +42 -48
- package/dist/types/components/atoms/VChip.vue.d.ts +33 -21
- package/dist/types/components/atoms/VLightSwitch.vue.d.ts +5 -5
- package/dist/types/components/atoms/VRadio/VRadioDescription.vue.d.ts +7 -12
- package/dist/types/components/atoms/VRadio/VRadioGroup.vue.d.ts +53 -83
- package/dist/types/components/atoms/VRadio/VRadioItem.vue.d.ts +46 -12
- package/dist/types/components/atoms/VRadio/VRadioLabel.vue.d.ts +7 -12
- package/dist/types/components/atoms/VSwitch/VSwitch.vue.d.ts +51 -72
- package/dist/types/components/atoms/VSwitch/VSwitchDescription.vue.d.ts +32 -11
- package/dist/types/components/atoms/VSwitch/VSwitchGroup.vue.d.ts +32 -11
- package/dist/types/components/atoms/VSwitch/VSwitchLabel.vue.d.ts +33 -20
- package/dist/types/components/molecules/VAccordion/VAccordion.vue.d.ts +39 -28
- package/dist/types/components/molecules/VAccordion/VAccordionItem.vue.d.ts +35 -19
- package/dist/types/components/molecules/VAlert.vue.d.ts +50 -73
- package/dist/types/components/molecules/VCard/VCard.vue.d.ts +37 -48
- package/dist/types/components/molecules/VCard/VCardBody.vue.d.ts +33 -12
- package/dist/types/components/molecules/VCard/VCardFooter.vue.d.ts +36 -20
- package/dist/types/components/molecules/VCard/VCardHeader.vue.d.ts +36 -20
- package/dist/types/components/molecules/VCodeBlock.vue.d.ts +15 -16
- package/dist/types/components/molecules/VDrawer.vue.d.ts +13 -7
- package/dist/types/components/molecules/VListbox/VListbox.vue.d.ts +54 -132
- package/dist/types/components/molecules/VListbox/VListboxButton.vue.d.ts +22 -21
- package/dist/types/components/molecules/VListbox/VListboxItem.vue.d.ts +22 -19
- package/dist/types/components/molecules/VListbox/VListboxItems.vue.d.ts +19 -30
- package/dist/types/components/molecules/VListbox/VListboxLabel.vue.d.ts +7 -12
- package/dist/types/components/molecules/VPreview.vue.d.ts +57 -74
- package/dist/types/components/molecules/VRail/VRail.vue.d.ts +28 -13
- package/dist/types/components/molecules/VRail/VRailTile.vue.d.ts +49 -16
- package/dist/types/components/molecules/VShell.vue.d.ts +76 -44
- package/dist/types/components/molecules/VShellConfigurator.vue.d.ts +99 -0
- package/dist/types/components/molecules/VTabs/VTab.vue.d.ts +52 -20
- package/dist/types/components/molecules/VTabs/VTabPanel.vue.d.ts +8 -1
- package/dist/types/components/molecules/VTabs/VTabs.vue.d.ts +43 -101
- package/dist/types/components/molecules/Vuetiful.vue.d.ts +22 -0
- package/dist/types/components/molecules/index.d.ts +3 -4
- package/dist/types/directives/click-outside-group.d.ts +9 -0
- package/dist/types/directives/click-outside.d.ts +9 -0
- package/dist/types/directives/clipboard.d.ts +1 -1
- package/dist/types/directives/index.d.ts +3 -1
- package/dist/types/index.d.ts +1 -8
- package/dist/types/props/props.d.ts +1 -14
- package/dist/types/services/dark-mode.service.d.ts +1 -1
- package/dist/types/services/drawer.service.d.ts +3 -3
- package/dist/types/services/index.d.ts +2 -2
- package/dist/types/utils/id-generator.d.ts +1 -0
- package/dist/types/utils/index.d.ts +3 -4
- package/dist/types/utils/tailwind-merge.d.ts +1 -0
- package/dist/types/utils/theme/rocket.theme.d.ts +223 -0
- package/dist/types/utils/theme/theme-switcher.vue.d.ts +14 -5
- package/dist/types/utils/theme/theme.service.d.ts +6 -9
- package/dist/types/utils/theme/themes.d.ts +3 -39
- package/dist/types/utils/theme/vuetiful.theme.d.ts +224 -0
- package/dist/vuetiful.es.mjs +54837 -49494
- package/dist/vuetiful.umd.cjs +189 -0
- package/package.json +53 -37
- package/dist/style.css +0 -10
- package/dist/types/components/VBootstrap.vue.d.ts +0 -15
- package/dist/types/components/atoms/VAvatar.test.d.ts +0 -1
- package/dist/types/components/atoms/VBadge.test.d.ts +0 -1
- package/dist/types/components/atoms/VButton.test.d.ts +0 -1
- package/dist/types/components/atoms/VChip.test.d.ts +0 -1
- package/dist/types/components/atoms/VLightSwitch.test.d.ts +0 -1
- package/dist/types/components/atoms/VRadio/VRadioDescription.test.d.ts +0 -1
- package/dist/types/components/atoms/VRadio/VRadioGroup.test.d.ts +0 -1
- package/dist/types/components/atoms/VRadio/VRadioItem.test.d.ts +0 -1
- package/dist/types/components/atoms/VRadio/VRadioLabel.test.d.ts +0 -1
- package/dist/types/components/atoms/VSwitch/VSwitch.test.d.ts +0 -1
- package/dist/types/components/atoms/VSwitch/VSwitchDescription.test.d.ts +0 -1
- package/dist/types/components/atoms/VSwitch/VSwitchGroup.test.d.ts +0 -1
- package/dist/types/components/atoms/VSwitch/VSwitchLabel.test.d.ts +0 -1
- package/dist/types/components/molecules/VAccordion/VAccordion.test.d.ts +0 -1
- package/dist/types/components/molecules/VAccordion/VAccordionItem.test.d.ts +0 -1
- package/dist/types/components/molecules/VAlert.test.d.ts +0 -1
- package/dist/types/components/molecules/VCard/VCard.test.d.ts +0 -1
- package/dist/types/components/molecules/VCard/VCardBody.test.d.ts +0 -1
- package/dist/types/components/molecules/VCard/VCardFooter.test.d.ts +0 -1
- package/dist/types/components/molecules/VCard/VCardHeader.test.d.ts +0 -1
- package/dist/types/components/molecules/VCodeBlock.test.d.ts +0 -1
- package/dist/types/components/molecules/VDrawer.test.d.ts +0 -1
- package/dist/types/components/molecules/VListbox/VListbox.test.d.ts +0 -1
- package/dist/types/components/molecules/VListbox/VListboxButton.test.d.ts +0 -1
- package/dist/types/components/molecules/VListbox/VListboxItem.test.d.ts +0 -1
- package/dist/types/components/molecules/VListbox/VListboxItems.test.d.ts +0 -1
- package/dist/types/components/molecules/VListbox/VListboxLabel.test.d.ts +0 -1
- package/dist/types/components/molecules/VPreview.test.d.ts +0 -1
- package/dist/types/components/molecules/VRail/VRail.test.d.ts +0 -1
- package/dist/types/components/molecules/VRail/VRailTile.test.d.ts +0 -1
- package/dist/types/components/molecules/VShell.test.d.ts +0 -1
- package/dist/types/components/molecules/VTabs/VTab.test.d.ts +0 -1
- package/dist/types/components/molecules/VTabs/VTabPanel.test.d.ts +0 -1
- package/dist/types/components/molecules/VTabs/VTabs.test.d.ts +0 -1
- package/dist/types/directives/clipboard.test.d.ts +0 -1
- package/dist/types/services/dark-mode.service.test.d.ts +0 -1
- package/dist/types/services/drawer.service.test.d.ts +0 -1
- package/dist/types/services/highlight.service.test.d.ts +0 -1
- package/dist/types/services/rail.service.test.d.ts +0 -1
- package/dist/types/services/settings.service.test.d.ts +0 -1
- package/dist/types/types/index.d.ts +0 -54
- package/dist/types/types/tailwind.d.ts +0 -4
- package/dist/types/utils/colors/colors.service.d.ts +0 -69
- package/dist/types/utils/platform/platform.service.test.d.ts +0 -1
- package/dist/types/utils/theme/callback.test.d.ts +0 -1
- package/dist/types/utils/theme/remove.test.d.ts +0 -1
- package/dist/types/utils/theme/theme.service.test.d.ts +0 -1
- package/dist/vuetiful.umd.js +0 -99
- package/src/assets/fonts/myfont.woff +0 -0
- package/src/assets/main.css +0 -17
- package/src/components/VBootstrap.vue +0 -62
- package/src/components/atoms/VAvatar.test.ts +0 -175
- package/src/components/atoms/VAvatar.vue +0 -89
- package/src/components/atoms/VBadge.test.ts +0 -28
- package/src/components/atoms/VBadge.vue +0 -17
- package/src/components/atoms/VButton.test.ts +0 -180
- package/src/components/atoms/VButton.vue +0 -76
- package/src/components/atoms/VChip.test.ts +0 -33
- package/src/components/atoms/VChip.vue +0 -17
- package/src/components/atoms/VLightSwitch.test.ts +0 -69
- package/src/components/atoms/VLightSwitch.vue +0 -121
- package/src/components/atoms/VRadio/VRadioDescription.test.ts +0 -55
- package/src/components/atoms/VRadio/VRadioDescription.vue +0 -14
- package/src/components/atoms/VRadio/VRadioGroup.test.ts +0 -81
- package/src/components/atoms/VRadio/VRadioGroup.vue +0 -88
- package/src/components/atoms/VRadio/VRadioItem.test.ts +0 -183
- package/src/components/atoms/VRadio/VRadioItem.vue +0 -36
- package/src/components/atoms/VRadio/VRadioLabel.test.ts +0 -55
- package/src/components/atoms/VRadio/VRadioLabel.vue +0 -16
- package/src/components/atoms/VSwitch/VSwitch.test.ts +0 -100
- package/src/components/atoms/VSwitch/VSwitch.vue +0 -106
- package/src/components/atoms/VSwitch/VSwitchDescription.test.ts +0 -55
- package/src/components/atoms/VSwitch/VSwitchDescription.vue +0 -16
- package/src/components/atoms/VSwitch/VSwitchGroup.test.ts +0 -26
- package/src/components/atoms/VSwitch/VSwitchGroup.vue +0 -16
- package/src/components/atoms/VSwitch/VSwitchLabel.test.ts +0 -89
- package/src/components/atoms/VSwitch/VSwitchLabel.vue +0 -20
- package/src/components/atoms/index.ts +0 -31
- package/src/components/index.ts +0 -2
- package/src/components/molecules/VAccordion/VAccordion.test.ts +0 -27
- package/src/components/molecules/VAccordion/VAccordion.vue +0 -32
- package/src/components/molecules/VAccordion/VAccordionItem.test.ts +0 -134
- package/src/components/molecules/VAccordion/VAccordionItem.vue +0 -68
- package/src/components/molecules/VAlert.test.ts +0 -100
- package/src/components/molecules/VAlert.vue +0 -137
- package/src/components/molecules/VCard/VCard.test.ts +0 -47
- package/src/components/molecules/VCard/VCard.vue +0 -74
- package/src/components/molecules/VCard/VCardBody.test.ts +0 -39
- package/src/components/molecules/VCard/VCardBody.vue +0 -16
- package/src/components/molecules/VCard/VCardFooter.test.ts +0 -63
- package/src/components/molecules/VCard/VCardFooter.vue +0 -31
- package/src/components/molecules/VCard/VCardHeader.test.ts +0 -86
- package/src/components/molecules/VCard/VCardHeader.vue +0 -53
- package/src/components/molecules/VCodeBlock.test.ts +0 -133
- package/src/components/molecules/VCodeBlock.vue +0 -113
- package/src/components/molecules/VDrawer.test.ts +0 -14
- package/src/components/molecules/VDrawer.vue +0 -87
- package/src/components/molecules/VListbox/VListbox.test.ts +0 -146
- package/src/components/molecules/VListbox/VListbox.vue +0 -149
- package/src/components/molecules/VListbox/VListboxButton.test.ts +0 -66
- package/src/components/molecules/VListbox/VListboxButton.vue +0 -57
- package/src/components/molecules/VListbox/VListboxItem.test.ts +0 -51
- package/src/components/molecules/VListbox/VListboxItem.vue +0 -39
- package/src/components/molecules/VListbox/VListboxItems.test.ts +0 -44
- package/src/components/molecules/VListbox/VListboxItems.vue +0 -42
- package/src/components/molecules/VListbox/VListboxLabel.test.ts +0 -30
- package/src/components/molecules/VListbox/VListboxLabel.vue +0 -14
- package/src/components/molecules/VPreview.test.ts +0 -73
- package/src/components/molecules/VPreview.vue +0 -230
- package/src/components/molecules/VRail/VRail.test.ts +0 -14
- package/src/components/molecules/VRail/VRail.vue +0 -33
- package/src/components/molecules/VRail/VRailTile.test.ts +0 -97
- package/src/components/molecules/VRail/VRailTile.vue +0 -49
- package/src/components/molecules/VShell.test.ts +0 -14
- package/src/components/molecules/VShell.vue +0 -63
- package/src/components/molecules/VTabs/VTab.test.ts +0 -143
- package/src/components/molecules/VTabs/VTab.vue +0 -50
- package/src/components/molecules/VTabs/VTabPanel.test.ts +0 -24
- package/src/components/molecules/VTabs/VTabPanel.vue +0 -9
- package/src/components/molecules/VTabs/VTabs.test.ts +0 -92
- package/src/components/molecules/VTabs/VTabs.vue +0 -104
- package/src/components/molecules/index.ts +0 -51
- package/src/directives/clipboard.test.ts +0 -26
- package/src/directives/clipboard.ts +0 -9
- package/src/directives/index.ts +0 -3
- package/src/env.d.ts +0 -8
- package/src/index.ts +0 -21
- package/src/props/index.ts +0 -1
- package/src/props/props.ts +0 -62
- package/src/services/dark-mode.service.test.ts +0 -104
- package/src/services/dark-mode.service.ts +0 -75
- package/src/services/drawer.service.test.ts +0 -45
- package/src/services/drawer.service.ts +0 -46
- package/src/services/highlight.service.test.ts +0 -24
- package/src/services/highlight.service.ts +0 -19
- package/src/services/index.ts +0 -8
- package/src/services/rail.service.test.ts +0 -13
- package/src/services/rail.service.ts +0 -11
- package/src/services/settings.service.test.ts +0 -17
- package/src/services/settings.service.ts +0 -136
- package/src/styles/all.css +0 -24
- package/src/styles/core.css +0 -66
- package/src/styles/elements/alerts.css +0 -17
- package/src/styles/elements/badges.css +0 -31
- package/src/styles/elements/breadcrumbs.css +0 -26
- package/src/styles/elements/buttons.css +0 -103
- package/src/styles/elements/cards.css +0 -32
- package/src/styles/elements/chips.css +0 -22
- package/src/styles/elements/forms.css +0 -269
- package/src/styles/elements/lists.css +0 -48
- package/src/styles/elements/logo-clouds.css +0 -29
- package/src/styles/elements/modals.css +0 -15
- package/src/styles/elements/placeholders.css +0 -17
- package/src/styles/elements/popups.css +0 -16
- package/src/styles/elements/tables.css +0 -102
- package/src/styles/elements.css +0 -19
- package/src/styles/highlight-js.css +0 -116
- package/src/styles/tailwind.css +0 -16
- package/src/styles/transitions.css +0 -2
- package/src/styles/typography.css +0 -101
- package/src/styles/variants.css +0 -156
- package/src/tailwind/core.cjs +0 -37
- package/src/tailwind/generated/intellisense-classes.cjs +0 -558
- package/src/tailwind/intellisense.cjs +0 -21
- package/src/tailwind/settings.cjs +0 -20
- package/src/tailwind/theme/colors.cjs +0 -20
- package/src/tailwind/tokens/backgrounds.cjs +0 -48
- package/src/tailwind/tokens/border-radius.cjs +0 -21
- package/src/tailwind/tokens/borders.cjs +0 -24
- package/src/tailwind/tokens/fills.cjs +0 -20
- package/src/tailwind/tokens/rings.cjs +0 -50
- package/src/tailwind/tokens/text.cjs +0 -35
- package/src/tailwind/vuetiful.cjs +0 -19
- package/src/themes/theme-rocket.css +0 -119
- package/src/themes/theme-sahara.css +0 -128
- package/src/themes/theme-seafoam.css +0 -120
- package/src/themes/theme-seasonal.css +0 -115
- package/src/themes/theme-skeleton.css +0 -115
- package/src/themes/theme-vintage.css +0 -125
- package/src/themes/theme-vuetiful.css +0 -136
- package/src/types/index.ts +0 -59
- package/src/types/tailwind.ts +0 -7
- package/src/utils/colors/colors.service.ts +0 -293
- package/src/utils/index.ts +0 -8
- package/src/utils/platform/platform.service.test.ts +0 -19
- package/src/utils/platform/platform.service.ts +0 -8
- package/src/utils/theme/callback.test.ts +0 -28
- package/src/utils/theme/remove.test.ts +0 -27
- package/src/utils/theme/theme-switcher.vue +0 -74
- package/src/utils/theme/theme.service.test.ts +0 -269
- package/src/utils/theme/theme.service.ts +0 -173
- package/src/utils/theme/themes.ts +0 -282
- /package/{src/styles → dist/css}/transitions/fade.css +0 -0
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
// This file is taken from Skeleton - wrapped in a useColors composable function
|
|
2
|
-
type ContrastLevel = 'AA' | 'AAA';
|
|
3
|
-
type ContrastSize = 'small' | 'large';
|
|
4
|
-
|
|
5
|
-
export interface Report {
|
|
6
|
-
emoji: string;
|
|
7
|
-
note: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface PassReport {
|
|
11
|
-
textColor: string;
|
|
12
|
-
backgroundColor: string;
|
|
13
|
-
contrast: number;
|
|
14
|
-
report: Report;
|
|
15
|
-
smallAA: boolean;
|
|
16
|
-
smallAAA: boolean;
|
|
17
|
-
largeAA: boolean;
|
|
18
|
-
largeAAA: boolean;
|
|
19
|
-
fails: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type Palette = {
|
|
23
|
-
[key: number]: {
|
|
24
|
-
hex: string;
|
|
25
|
-
rgb: string;
|
|
26
|
-
on: string;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const semanticNames = ['primary', 'secondary', 'tertiary', 'success', 'warning', 'error', 'surface'] as const;
|
|
31
|
-
export type SemanticNames = (typeof semanticNames)[number];
|
|
32
|
-
export interface ColorSettings {
|
|
33
|
-
key: SemanticNames;
|
|
34
|
-
label: string;
|
|
35
|
-
hex: string;
|
|
36
|
-
rgb: string;
|
|
37
|
-
on: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
type Rgb = {
|
|
41
|
-
r: number;
|
|
42
|
-
g: number;
|
|
43
|
-
b: number;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const useColors = () => {
|
|
47
|
-
function hexToRgb(hex: string): Rgb | null {
|
|
48
|
-
const sanitizedHex = hex.replaceAll('##', '#');
|
|
49
|
-
const colorParts = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(sanitizedHex);
|
|
50
|
-
|
|
51
|
-
if (!colorParts) return null;
|
|
52
|
-
|
|
53
|
-
const [, r, g, b] = colorParts;
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
r: parseInt(r, 16),
|
|
57
|
-
g: parseInt(g, 16),
|
|
58
|
-
b: parseInt(b, 16),
|
|
59
|
-
} as Rgb;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function hexToTailwindRgbString(hex: string): string {
|
|
63
|
-
const sanitizedHex = hex.replaceAll('##', '#');
|
|
64
|
-
const colorParts = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(sanitizedHex);
|
|
65
|
-
|
|
66
|
-
if (!colorParts) return '(invalid)';
|
|
67
|
-
|
|
68
|
-
const [, r, g, b] = colorParts;
|
|
69
|
-
|
|
70
|
-
return `${parseInt(r, 16)} ${parseInt(g, 16)} ${parseInt(b, 16)}`;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function rgbToHex(r: number, g: number, b: number): string {
|
|
74
|
-
const toHex = (c: number) => `0${c.toString(16)}`.slice(-2);
|
|
75
|
-
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function generateA11yOnColor(hex: string): '255 255 255' | '0 0 0' {
|
|
79
|
-
const black = calculateRatio(hex, '#000000');
|
|
80
|
-
const white = calculateRatio(hex, '#FFFFFF');
|
|
81
|
-
return black < white ? '0 0 0' : '255 255 255';
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function lighten(hex: string, intensity: number): string {
|
|
85
|
-
const color = hexToRgb(`#${hex}`);
|
|
86
|
-
|
|
87
|
-
if (!color) return '';
|
|
88
|
-
|
|
89
|
-
const r = Math.round(color.r + (255 - color.r) * intensity);
|
|
90
|
-
const g = Math.round(color.g + (255 - color.g) * intensity);
|
|
91
|
-
const b = Math.round(color.b + (255 - color.b) * intensity);
|
|
92
|
-
|
|
93
|
-
return rgbToHex(r, g, b);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function darken(hex: string, intensity: number): string {
|
|
97
|
-
const color = hexToRgb(hex);
|
|
98
|
-
|
|
99
|
-
if (!color) return '';
|
|
100
|
-
|
|
101
|
-
const r = Math.round(color.r * intensity);
|
|
102
|
-
const g = Math.round(color.g * intensity);
|
|
103
|
-
const b = Math.round(color.b * intensity);
|
|
104
|
-
|
|
105
|
-
return rgbToHex(r, g, b);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function generatePalette(baseColor: string): Palette {
|
|
109
|
-
const hexValidation = new RegExp(/^#[0-9a-f]{6}$/i);
|
|
110
|
-
if (!hexValidation.test(baseColor)) baseColor = '#CCCCCC';
|
|
111
|
-
|
|
112
|
-
const hex500 = `#${baseColor}`.replace('##', '#');
|
|
113
|
-
|
|
114
|
-
const response: Palette = {
|
|
115
|
-
500: { hex: hex500, rgb: hexToTailwindRgbString(hex500), on: generateA11yOnColor(hex500) },
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const intensityMap: { [key: number]: number } = {
|
|
119
|
-
50: 0.85,
|
|
120
|
-
100: 0.8,
|
|
121
|
-
200: 0.75,
|
|
122
|
-
300: 0.6,
|
|
123
|
-
400: 0.3,
|
|
124
|
-
600: 0.9,
|
|
125
|
-
700: 0.75,
|
|
126
|
-
800: 0.6,
|
|
127
|
-
900: 0.49,
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
[50, 100, 200, 300, 400].forEach((level) => {
|
|
131
|
-
const hex = lighten(baseColor, intensityMap[level]);
|
|
132
|
-
response[level] = { hex, rgb: hexToTailwindRgbString(hex), on: generateA11yOnColor(hex) };
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
[600, 700, 800, 900].forEach((level) => {
|
|
136
|
-
const hex = darken(baseColor, intensityMap[level]);
|
|
137
|
-
response[level] = { hex, rgb: hexToTailwindRgbString(hex), on: generateA11yOnColor(hex) };
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
return response as Palette;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const contrastLevels: Record<
|
|
144
|
-
ContrastSize,
|
|
145
|
-
{
|
|
146
|
-
[key in ContrastLevel]: number;
|
|
147
|
-
}
|
|
148
|
-
> = {
|
|
149
|
-
/** For text that is less than 18pt */
|
|
150
|
-
small: {
|
|
151
|
-
AA: 1 / 4.5,
|
|
152
|
-
AAA: 1 / 7,
|
|
153
|
-
},
|
|
154
|
-
/** For text that is at or is larger than 18pt */
|
|
155
|
-
large: {
|
|
156
|
-
AA: 1 / 3,
|
|
157
|
-
AAA: 1 / 4.5,
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/** Takes the RGB and returns the luminance of it */
|
|
162
|
-
function getLuminance(r: Rgb): number;
|
|
163
|
-
function getLuminance(r: number, g: number, b: number): number;
|
|
164
|
-
function getLuminance(r: number | Rgb, g?: number, b?: number) {
|
|
165
|
-
const { _r, _g, _b } = typeof r === 'object' ? { _r: r.r, _g: r.g, _b: r.b } : { _r: r, _g: g, _b: b }; // I'm not really happy with this ternary, but it works
|
|
166
|
-
// we can't use !_r shorthand here because 0 is a valid value
|
|
167
|
-
if (_r === undefined || _g === undefined || _b === undefined) throw new Error('Invalid RGB value!');
|
|
168
|
-
const a = [_r, _g, _b].map(function (v) {
|
|
169
|
-
v /= 255;
|
|
170
|
-
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
|
|
171
|
-
});
|
|
172
|
-
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function destringRgb(rgbString: string): Rgb {
|
|
176
|
-
const rgb = rgbString.match(/(\d+),?\s*(\d+),?\s*(\d+)/); // matches "255, 255, 255" and "255 255 255"
|
|
177
|
-
if (!rgb) throw new Error('Invalid RGB string!');
|
|
178
|
-
return { r: parseInt(rgb[1], 10), g: parseInt(rgb[2], 10), b: parseInt(rgb[3], 10) };
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// overload to specify that when there is no returnType, it will always return Rgb
|
|
182
|
-
function handleStringColor(colorString: string): Rgb;
|
|
183
|
-
function handleStringColor(colorString: string, returnType: 'rgb'): Rgb;
|
|
184
|
-
function handleStringColor(colorString: string, returnType: 'hex'): string;
|
|
185
|
-
function handleStringColor(colorString: string, returnType?: 'hex' | 'rgb'): string | Rgb;
|
|
186
|
-
function handleStringColor(colorString: string, returnType: 'hex' | 'rgb' = 'rgb'): string | Rgb {
|
|
187
|
-
// if it's a css variable
|
|
188
|
-
if (colorString.includes('--')) {
|
|
189
|
-
colorString = colorString.replace(/var\(|\)/g, ''); // grab just the variable name
|
|
190
|
-
const cssVarHydrated = getComputedStyle(document.documentElement).getPropertyValue(colorString).trim();
|
|
191
|
-
return handleStringColor(cssVarHydrated, returnType);
|
|
192
|
-
}
|
|
193
|
-
// if it has spaces, it's an rgb string
|
|
194
|
-
if (colorString.includes(' ')) {
|
|
195
|
-
const rgb = destringRgb(colorString);
|
|
196
|
-
return returnType === 'hex' ? rgbToHex(rgb.r, rgb.g, rgb.b) : rgb;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// if it's a hex string
|
|
200
|
-
if (colorString.includes('#')) {
|
|
201
|
-
const rgb = hexToRgb(colorString);
|
|
202
|
-
if (!rgb) return '(invalid)';
|
|
203
|
-
return returnType === 'hex' ? colorString : rgb;
|
|
204
|
-
}
|
|
205
|
-
return colorString;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function calculateRatio(luminance1: string | number, luminance2: string | number) {
|
|
209
|
-
const lum1 = typeof luminance1 === 'string' ? getLuminance(handleStringColor(luminance1)) : luminance1;
|
|
210
|
-
const lum2 = typeof luminance2 === 'string' ? getLuminance(handleStringColor(luminance2)) : luminance2;
|
|
211
|
-
if (lum1 === undefined || lum2 === undefined) throw new Error('Luminance is undefined!');
|
|
212
|
-
return lum1 > lum2 ? (lum2 + 0.05) / (lum1 + 0.05) : (lum1 + 0.05) / (lum2 + 0.05);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function textPasses(textColor: string, backgroundColor: string, size: ContrastSize, level: ContrastLevel) {
|
|
216
|
-
const ratio = calculateRatio(textColor, backgroundColor);
|
|
217
|
-
return ratio <= contrastLevels[size][level];
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function hexValueIsValid(textColor: string) {
|
|
221
|
-
return /^#[0-9A-F]{6}$/i.test(textColor);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/** A catch-all function to give a report on what size and level a given combination achieves. */
|
|
225
|
-
function getPassReport(textColor: string, backgroundColor: string): PassReport {
|
|
226
|
-
const _textColor = handleStringColor(textColor, 'hex');
|
|
227
|
-
const _backgroundColor = handleStringColor(backgroundColor, 'hex');
|
|
228
|
-
const contrast = calculateRatio(_textColor, _backgroundColor);
|
|
229
|
-
const smallAA = textPasses(_textColor, _backgroundColor, 'small', 'AA');
|
|
230
|
-
const smallAAA = textPasses(_textColor, _backgroundColor, 'small', 'AAA');
|
|
231
|
-
const largeAA = textPasses(_textColor, _backgroundColor, 'large', 'AA');
|
|
232
|
-
const largeAAA = textPasses(_textColor, _backgroundColor, 'large', 'AAA');
|
|
233
|
-
const fails = !smallAA && !smallAAA && !largeAA && !largeAAA;
|
|
234
|
-
const AAAEmoji = '<i class="fa-solid fa-heart"></i>';
|
|
235
|
-
const AAEmoji = '<i class="fa-solid fa-star"></i>';
|
|
236
|
-
const largeAAEmoji = '<i class="fa-solid fa-star-half-stroke"></i>';
|
|
237
|
-
const failEmoji = '<i class="fa-solid fa-triangle-exclamation"></i>';
|
|
238
|
-
const report = {
|
|
239
|
-
emoji: smallAAA ? AAAEmoji : smallAA ? AAEmoji : largeAA ? largeAAEmoji : failEmoji,
|
|
240
|
-
note:
|
|
241
|
-
`${_textColor} and ${_backgroundColor} ` +
|
|
242
|
-
(smallAAA
|
|
243
|
-
? 'has great contrast!'
|
|
244
|
-
: smallAA
|
|
245
|
-
? 'is satisfactory for larger text'
|
|
246
|
-
: largeAA
|
|
247
|
-
? 'has poor contrast'
|
|
248
|
-
: 'fail contrast guidelines'),
|
|
249
|
-
};
|
|
250
|
-
return {
|
|
251
|
-
textColor: _textColor,
|
|
252
|
-
backgroundColor: _backgroundColor,
|
|
253
|
-
contrast,
|
|
254
|
-
report,
|
|
255
|
-
smallAA,
|
|
256
|
-
smallAAA,
|
|
257
|
-
largeAA,
|
|
258
|
-
largeAAA,
|
|
259
|
-
fails,
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const hexValuesAreValid = (colors: Array<ColorSettings>) => {
|
|
264
|
-
let valid = true;
|
|
265
|
-
colors?.forEach((color: ColorSettings) => {
|
|
266
|
-
valid = valid && hexValueIsValid(color.hex);
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
return valid;
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
return {
|
|
273
|
-
hexToRgb,
|
|
274
|
-
hexToTailwindRgbString,
|
|
275
|
-
rgbToHex,
|
|
276
|
-
generateA11yOnColor,
|
|
277
|
-
lighten,
|
|
278
|
-
darken,
|
|
279
|
-
generatePalette,
|
|
280
|
-
contrastLevels,
|
|
281
|
-
getLuminance,
|
|
282
|
-
destringRgb,
|
|
283
|
-
handleStringColor,
|
|
284
|
-
calculateRatio,
|
|
285
|
-
textPasses,
|
|
286
|
-
hexValueIsValid,
|
|
287
|
-
getPassReport,
|
|
288
|
-
hexValuesAreValid,
|
|
289
|
-
semanticNames
|
|
290
|
-
};
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
export { useColors };
|
package/src/utils/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ColorSettings, Palette, PassReport, Report, SemanticNames } from './colors/colors.service';
|
|
2
|
-
import { useColors } from './colors/colors.service';
|
|
3
|
-
import { usePlatform } from './platform/platform.service';
|
|
4
|
-
import ThemeSwitcher from './theme/theme-switcher.vue';
|
|
5
|
-
import { useTheme } from './theme/theme.service';
|
|
6
|
-
|
|
7
|
-
export { ThemeSwitcher, useColors, usePlatform, useTheme };
|
|
8
|
-
export type { ColorSettings, Palette, PassReport, Report, SemanticNames };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { describe, expect, vi, test } from 'vitest';
|
|
2
|
-
import { usePlatform } from './platform.service';
|
|
3
|
-
|
|
4
|
-
const matchMediaMock = (matches: boolean) => vi.fn(() => ({ matches, onchange: vi.fn() }));
|
|
5
|
-
|
|
6
|
-
describe('usePlatform', () => {
|
|
7
|
-
describe('isBrowser', () => {
|
|
8
|
-
test('should return true when window is defined', () => {
|
|
9
|
-
const { isBrowser } = usePlatform();
|
|
10
|
-
expect(isBrowser).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test('should return false when window is not defined', () => {
|
|
14
|
-
window = undefined as any;
|
|
15
|
-
const { isBrowser } = usePlatform();
|
|
16
|
-
expect(isBrowser).toBe(false);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { describe, expect, vi, test } from 'vitest';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* No clue why, but when this test is added to theme.service.test.ts, it fails.
|
|
5
|
-
* Running it in isolation works fine.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
describe('given there is a callback', () => {
|
|
9
|
-
test('should call the callback', async () => {
|
|
10
|
-
const { useTheme } = await import('./theme.service');
|
|
11
|
-
const { applyTheme, themes } = useTheme();
|
|
12
|
-
|
|
13
|
-
const callbackSpy = vi.fn();
|
|
14
|
-
const callbackFunction = () => {
|
|
15
|
-
callbackSpy();
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const newTheme = JSON.parse(JSON.stringify(themes[0]));
|
|
19
|
-
newTheme.name = 'new-theme';
|
|
20
|
-
applyTheme(newTheme, callbackFunction);
|
|
21
|
-
|
|
22
|
-
const link = document.querySelector('#vuetiful-theme') as HTMLLinkElement;
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
link.onload();
|
|
25
|
-
|
|
26
|
-
expect(callbackSpy).toHaveBeenCalled();
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { describe, expect, vi, test } from 'vitest';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* No clue why, but when this test is added to theme.service.test.ts, it fails.
|
|
5
|
-
* Running it in isolation works fine.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
describe('given there is no existing theme style tag', () => {
|
|
9
|
-
test('should create a new theme style tag', async () => {
|
|
10
|
-
const { useTheme } = await import('./theme.service');
|
|
11
|
-
const { applyTheme, themes } = useTheme();
|
|
12
|
-
|
|
13
|
-
const removeObject = { remove: () => {} };
|
|
14
|
-
const removeSpy = vi.spyOn(removeObject, 'remove');
|
|
15
|
-
vi.spyOn(window.document, 'getElementById').mockReturnValueOnce(removeObject as any);
|
|
16
|
-
|
|
17
|
-
const newTheme = JSON.parse(JSON.stringify(themes[0]));
|
|
18
|
-
newTheme.name = 'new-theme';
|
|
19
|
-
applyTheme(newTheme);
|
|
20
|
-
|
|
21
|
-
const link = document.querySelector('#vuetiful-theme') as HTMLLinkElement;
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
link.onload();
|
|
24
|
-
|
|
25
|
-
expect(removeSpy).toHaveBeenCalled();
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { CssClasses, useTheme, VButton, VLightSwitch } from '@/index';
|
|
3
|
-
import { ref } from 'vue';
|
|
4
|
-
|
|
5
|
-
defineProps({
|
|
6
|
-
background: {
|
|
7
|
-
type: String as () => CssClasses,
|
|
8
|
-
default: 'bg-surface-50-900-token',
|
|
9
|
-
},
|
|
10
|
-
text: {
|
|
11
|
-
type: String as () => CssClasses,
|
|
12
|
-
default: 'text-surface-900-50-token',
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
widthPopup: {
|
|
16
|
-
type: String as () => CssClasses,
|
|
17
|
-
default: 'w-60',
|
|
18
|
-
},
|
|
19
|
-
heightList: {
|
|
20
|
-
type: String as () => CssClasses,
|
|
21
|
-
default: 'max-h-64 lg:max-h-[500px]',
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
classButton: {
|
|
25
|
-
type: String as () => CssClasses,
|
|
26
|
-
default: '',
|
|
27
|
-
},
|
|
28
|
-
classList: {
|
|
29
|
-
type: String as () => CssClasses,
|
|
30
|
-
default: '',
|
|
31
|
-
},
|
|
32
|
-
classListItem: {
|
|
33
|
-
type: String as () => CssClasses,
|
|
34
|
-
default: '',
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const { applyTheme, themes, chosenTheme } = useTheme();
|
|
39
|
-
|
|
40
|
-
const showPopup = ref(false);
|
|
41
|
-
</script>
|
|
42
|
-
|
|
43
|
-
<template>
|
|
44
|
-
<div class="vuetiful-theme-switcher">
|
|
45
|
-
<v-button :class="`vuetiful-theme-switcher__button ${classButton}`" @click="showPopup = !showPopup">
|
|
46
|
-
Theme
|
|
47
|
-
</v-button>
|
|
48
|
-
|
|
49
|
-
<div
|
|
50
|
-
v-if="showPopup"
|
|
51
|
-
class="vuetiful-theme-switcher__popup absolute z-10 mt-1 space-y-4 p-4 shadow-xl rounded-container-token"
|
|
52
|
-
:class="`${background} ${text} ${widthPopup} ${classList}`"
|
|
53
|
-
>
|
|
54
|
-
<section class="flex items-center justify-between">
|
|
55
|
-
<div class="text-lg">Mode</div>
|
|
56
|
-
<v-light-switch />
|
|
57
|
-
</section>
|
|
58
|
-
<nav
|
|
59
|
-
class="vuetiful-theme-switcher__popup-list -m-4 flex flex-col gap-4 overflow-y-auto p-4"
|
|
60
|
-
:class="`${heightList} ${classList}`"
|
|
61
|
-
>
|
|
62
|
-
<v-button
|
|
63
|
-
class="vuetiful-theme-switcher__popup-list-item h-full w-full p-2 text-center capitalize hover:cursor-pointer"
|
|
64
|
-
v-for="(theme, index) in themes"
|
|
65
|
-
:class="`${classListItem} ${chosenTheme.name === theme.name ? 'variant-filled-surface' : ''}`"
|
|
66
|
-
:key="index"
|
|
67
|
-
@click="applyTheme(theme)"
|
|
68
|
-
>
|
|
69
|
-
{{ theme.name }}
|
|
70
|
-
</v-button>
|
|
71
|
-
</nav>
|
|
72
|
-
</div>
|
|
73
|
-
</div>
|
|
74
|
-
</template>
|