@code-coaching/vuetiful 0.26.0 → 0.28.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.
Files changed (266) hide show
  1. package/README.md +47 -55
  2. package/dist/css/animations.css +2 -0
  3. package/{src → dist}/css/overrides/quasar.css +73 -58
  4. package/dist/css/transitions/fade.css +9 -0
  5. package/{src/styles → dist/css}/transitions/slide.css +0 -24
  6. package/dist/favicon.ico +0 -0
  7. package/dist/types/components/atoms/VAvatar.vue.d.ts +39 -90
  8. package/dist/types/components/atoms/VBadge.vue.d.ts +34 -21
  9. package/dist/types/components/atoms/VButton.vue.d.ts +42 -48
  10. package/dist/types/components/atoms/VChip.vue.d.ts +33 -21
  11. package/dist/types/components/atoms/VRadio/VRadioDescription.vue.d.ts +7 -12
  12. package/dist/types/components/atoms/VRadio/VRadioGroup.vue.d.ts +54 -83
  13. package/dist/types/components/atoms/VRadio/VRadioItem.vue.d.ts +46 -12
  14. package/dist/types/components/atoms/VRadio/VRadioLabel.vue.d.ts +7 -12
  15. package/dist/types/components/atoms/VSwitch/VSwitch.vue.d.ts +52 -73
  16. package/dist/types/components/atoms/VSwitch/VSwitchDescription.vue.d.ts +32 -11
  17. package/dist/types/components/atoms/VSwitch/VSwitchGroup.vue.d.ts +32 -11
  18. package/dist/types/components/atoms/VSwitch/VSwitchLabel.vue.d.ts +33 -20
  19. package/dist/types/components/atoms/index.d.ts +1 -2
  20. package/dist/types/components/molecules/VAccordion/VAccordion.vue.d.ts +39 -28
  21. package/dist/types/components/molecules/VAccordion/VAccordionItem.vue.d.ts +35 -19
  22. package/dist/types/components/molecules/VAlert.vue.d.ts +50 -73
  23. package/dist/types/components/molecules/VCard/VCard.vue.d.ts +37 -48
  24. package/dist/types/components/molecules/VCard/VCardBody.vue.d.ts +33 -12
  25. package/dist/types/components/molecules/VCard/VCardFooter.vue.d.ts +36 -20
  26. package/dist/types/components/molecules/VCard/VCardHeader.vue.d.ts +36 -20
  27. package/dist/types/components/molecules/VCodeBlock.vue.d.ts +15 -16
  28. package/dist/types/components/molecules/VDrawer.vue.d.ts +13 -7
  29. package/dist/types/components/molecules/VListbox/VListbox.vue.d.ts +54 -132
  30. package/dist/types/components/molecules/VListbox/VListboxButton.vue.d.ts +22 -21
  31. package/dist/types/components/molecules/VListbox/VListboxItem.vue.d.ts +22 -19
  32. package/dist/types/components/molecules/VListbox/VListboxItems.vue.d.ts +19 -30
  33. package/dist/types/components/molecules/VListbox/VListboxLabel.vue.d.ts +7 -12
  34. package/dist/types/components/molecules/VPreview.vue.d.ts +57 -74
  35. package/dist/types/components/molecules/VRail/VRail.vue.d.ts +28 -13
  36. package/dist/types/components/molecules/VRail/VRailTile.vue.d.ts +49 -16
  37. package/dist/types/components/molecules/VShell.vue.d.ts +76 -44
  38. package/dist/types/components/molecules/VShellConfigurator.vue.d.ts +99 -0
  39. package/dist/types/components/molecules/VTabs/VTab.vue.d.ts +52 -20
  40. package/dist/types/components/molecules/VTabs/VTabPanel.vue.d.ts +8 -1
  41. package/dist/types/components/molecules/VTabs/VTabs.vue.d.ts +43 -101
  42. package/dist/types/components/molecules/Vuetiful.vue.d.ts +22 -0
  43. package/dist/types/components/molecules/index.d.ts +3 -4
  44. package/dist/types/directives/click-outside-group.d.ts +1 -1
  45. package/dist/types/directives/click-outside.d.ts +1 -1
  46. package/dist/types/directives/clipboard.d.ts +1 -1
  47. package/dist/types/index.d.ts +1 -8
  48. package/dist/types/props/props.d.ts +1 -14
  49. package/dist/types/services/drawer.service.d.ts +2 -2
  50. package/dist/types/services/index.d.ts +3 -4
  51. package/dist/types/utils/id-generator.d.ts +1 -0
  52. package/dist/types/utils/index.d.ts +7 -5
  53. package/dist/types/utils/tailwind-merge.d.ts +1 -0
  54. package/dist/types/utils/theme/VLightSwitch.vue.d.ts +16 -0
  55. package/dist/types/utils/theme/VThemeSwitch.vue.d.ts +41 -0
  56. package/dist/types/{services → utils/theme}/dark-mode.service.d.ts +1 -1
  57. package/dist/types/utils/theme/rocket.theme.d.ts +223 -0
  58. package/dist/types/utils/theme/theme.service.d.ts +6 -9
  59. package/dist/types/utils/theme/themes.d.ts +3 -39
  60. package/dist/types/utils/theme/vuetiful.theme.d.ts +224 -0
  61. package/dist/vuetiful.es.mjs +54782 -49507
  62. package/dist/vuetiful.umd.cjs +189 -0
  63. package/package.json +53 -37
  64. package/dist/style.css +0 -10
  65. package/dist/types/components/VBootstrap.vue.d.ts +0 -15
  66. package/dist/types/components/atoms/VAvatar.test.d.ts +0 -1
  67. package/dist/types/components/atoms/VBadge.test.d.ts +0 -1
  68. package/dist/types/components/atoms/VButton.test.d.ts +0 -1
  69. package/dist/types/components/atoms/VChip.test.d.ts +0 -1
  70. package/dist/types/components/atoms/VLightSwitch.test.d.ts +0 -1
  71. package/dist/types/components/atoms/VLightSwitch.vue.d.ts +0 -95
  72. package/dist/types/components/atoms/VRadio/VRadioDescription.test.d.ts +0 -1
  73. package/dist/types/components/atoms/VRadio/VRadioGroup.test.d.ts +0 -1
  74. package/dist/types/components/atoms/VRadio/VRadioItem.test.d.ts +0 -1
  75. package/dist/types/components/atoms/VRadio/VRadioLabel.test.d.ts +0 -1
  76. package/dist/types/components/atoms/VSwitch/VSwitch.test.d.ts +0 -1
  77. package/dist/types/components/atoms/VSwitch/VSwitchDescription.test.d.ts +0 -1
  78. package/dist/types/components/atoms/VSwitch/VSwitchGroup.test.d.ts +0 -1
  79. package/dist/types/components/atoms/VSwitch/VSwitchLabel.test.d.ts +0 -1
  80. package/dist/types/components/molecules/VAccordion/VAccordion.test.d.ts +0 -1
  81. package/dist/types/components/molecules/VAccordion/VAccordionItem.test.d.ts +0 -1
  82. package/dist/types/components/molecules/VAlert.test.d.ts +0 -1
  83. package/dist/types/components/molecules/VCard/VCard.test.d.ts +0 -1
  84. package/dist/types/components/molecules/VCard/VCardBody.test.d.ts +0 -1
  85. package/dist/types/components/molecules/VCard/VCardFooter.test.d.ts +0 -1
  86. package/dist/types/components/molecules/VCard/VCardHeader.test.d.ts +0 -1
  87. package/dist/types/components/molecules/VCodeBlock.test.d.ts +0 -1
  88. package/dist/types/components/molecules/VDrawer.test.d.ts +0 -1
  89. package/dist/types/components/molecules/VListbox/VListbox.test.d.ts +0 -1
  90. package/dist/types/components/molecules/VListbox/VListboxButton.test.d.ts +0 -1
  91. package/dist/types/components/molecules/VListbox/VListboxItem.test.d.ts +0 -1
  92. package/dist/types/components/molecules/VListbox/VListboxItems.test.d.ts +0 -1
  93. package/dist/types/components/molecules/VListbox/VListboxLabel.test.d.ts +0 -1
  94. package/dist/types/components/molecules/VPreview.test.d.ts +0 -1
  95. package/dist/types/components/molecules/VRail/VRail.test.d.ts +0 -1
  96. package/dist/types/components/molecules/VRail/VRailTile.test.d.ts +0 -1
  97. package/dist/types/components/molecules/VShell.test.d.ts +0 -1
  98. package/dist/types/components/molecules/VTabs/VTab.test.d.ts +0 -1
  99. package/dist/types/components/molecules/VTabs/VTabPanel.test.d.ts +0 -1
  100. package/dist/types/components/molecules/VTabs/VTabs.test.d.ts +0 -1
  101. package/dist/types/directives/click-outside-group.test.d.ts +0 -1
  102. package/dist/types/directives/click-outside.test.d.ts +0 -1
  103. package/dist/types/directives/clipboard.test.d.ts +0 -1
  104. package/dist/types/services/dark-mode.service.test.d.ts +0 -1
  105. package/dist/types/services/drawer.service.test.d.ts +0 -1
  106. package/dist/types/services/highlight.service.test.d.ts +0 -1
  107. package/dist/types/services/rail.service.test.d.ts +0 -1
  108. package/dist/types/services/settings.service.test.d.ts +0 -1
  109. package/dist/types/types/index.d.ts +0 -54
  110. package/dist/types/types/tailwind.d.ts +0 -4
  111. package/dist/types/utils/colors/colors.service.d.ts +0 -69
  112. package/dist/types/utils/platform/platform.service.test.d.ts +0 -1
  113. package/dist/types/utils/theme/callback.test.d.ts +0 -1
  114. package/dist/types/utils/theme/remove.test.d.ts +0 -1
  115. package/dist/types/utils/theme/theme-switcher.vue.d.ts +0 -69
  116. package/dist/types/utils/theme/theme.service.test.d.ts +0 -1
  117. package/dist/vuetiful.umd.js +0 -99
  118. package/src/assets/fonts/myfont.woff +0 -0
  119. package/src/assets/main.css +0 -17
  120. package/src/components/VBootstrap.vue +0 -62
  121. package/src/components/atoms/VAvatar.test.ts +0 -175
  122. package/src/components/atoms/VAvatar.vue +0 -89
  123. package/src/components/atoms/VBadge.test.ts +0 -28
  124. package/src/components/atoms/VBadge.vue +0 -17
  125. package/src/components/atoms/VButton.test.ts +0 -180
  126. package/src/components/atoms/VButton.vue +0 -76
  127. package/src/components/atoms/VChip.test.ts +0 -33
  128. package/src/components/atoms/VChip.vue +0 -17
  129. package/src/components/atoms/VLightSwitch.test.ts +0 -69
  130. package/src/components/atoms/VLightSwitch.vue +0 -121
  131. package/src/components/atoms/VRadio/VRadioDescription.test.ts +0 -55
  132. package/src/components/atoms/VRadio/VRadioDescription.vue +0 -14
  133. package/src/components/atoms/VRadio/VRadioGroup.test.ts +0 -81
  134. package/src/components/atoms/VRadio/VRadioGroup.vue +0 -88
  135. package/src/components/atoms/VRadio/VRadioItem.test.ts +0 -183
  136. package/src/components/atoms/VRadio/VRadioItem.vue +0 -36
  137. package/src/components/atoms/VRadio/VRadioLabel.test.ts +0 -55
  138. package/src/components/atoms/VRadio/VRadioLabel.vue +0 -16
  139. package/src/components/atoms/VSwitch/VSwitch.test.ts +0 -100
  140. package/src/components/atoms/VSwitch/VSwitch.vue +0 -106
  141. package/src/components/atoms/VSwitch/VSwitchDescription.test.ts +0 -55
  142. package/src/components/atoms/VSwitch/VSwitchDescription.vue +0 -16
  143. package/src/components/atoms/VSwitch/VSwitchGroup.test.ts +0 -26
  144. package/src/components/atoms/VSwitch/VSwitchGroup.vue +0 -16
  145. package/src/components/atoms/VSwitch/VSwitchLabel.test.ts +0 -89
  146. package/src/components/atoms/VSwitch/VSwitchLabel.vue +0 -20
  147. package/src/components/atoms/index.ts +0 -31
  148. package/src/components/index.ts +0 -2
  149. package/src/components/molecules/VAccordion/VAccordion.test.ts +0 -27
  150. package/src/components/molecules/VAccordion/VAccordion.vue +0 -32
  151. package/src/components/molecules/VAccordion/VAccordionItem.test.ts +0 -134
  152. package/src/components/molecules/VAccordion/VAccordionItem.vue +0 -68
  153. package/src/components/molecules/VAlert.test.ts +0 -100
  154. package/src/components/molecules/VAlert.vue +0 -137
  155. package/src/components/molecules/VCard/VCard.test.ts +0 -47
  156. package/src/components/molecules/VCard/VCard.vue +0 -74
  157. package/src/components/molecules/VCard/VCardBody.test.ts +0 -39
  158. package/src/components/molecules/VCard/VCardBody.vue +0 -16
  159. package/src/components/molecules/VCard/VCardFooter.test.ts +0 -63
  160. package/src/components/molecules/VCard/VCardFooter.vue +0 -31
  161. package/src/components/molecules/VCard/VCardHeader.test.ts +0 -86
  162. package/src/components/molecules/VCard/VCardHeader.vue +0 -53
  163. package/src/components/molecules/VCodeBlock.test.ts +0 -133
  164. package/src/components/molecules/VCodeBlock.vue +0 -113
  165. package/src/components/molecules/VDrawer.test.ts +0 -14
  166. package/src/components/molecules/VDrawer.vue +0 -87
  167. package/src/components/molecules/VListbox/VListbox.test.ts +0 -146
  168. package/src/components/molecules/VListbox/VListbox.vue +0 -149
  169. package/src/components/molecules/VListbox/VListboxButton.test.ts +0 -66
  170. package/src/components/molecules/VListbox/VListboxButton.vue +0 -57
  171. package/src/components/molecules/VListbox/VListboxItem.test.ts +0 -51
  172. package/src/components/molecules/VListbox/VListboxItem.vue +0 -39
  173. package/src/components/molecules/VListbox/VListboxItems.test.ts +0 -44
  174. package/src/components/molecules/VListbox/VListboxItems.vue +0 -42
  175. package/src/components/molecules/VListbox/VListboxLabel.test.ts +0 -30
  176. package/src/components/molecules/VListbox/VListboxLabel.vue +0 -14
  177. package/src/components/molecules/VPreview.test.ts +0 -73
  178. package/src/components/molecules/VPreview.vue +0 -230
  179. package/src/components/molecules/VRail/VRail.test.ts +0 -14
  180. package/src/components/molecules/VRail/VRail.vue +0 -33
  181. package/src/components/molecules/VRail/VRailTile.test.ts +0 -97
  182. package/src/components/molecules/VRail/VRailTile.vue +0 -49
  183. package/src/components/molecules/VShell.test.ts +0 -14
  184. package/src/components/molecules/VShell.vue +0 -63
  185. package/src/components/molecules/VTabs/VTab.test.ts +0 -143
  186. package/src/components/molecules/VTabs/VTab.vue +0 -50
  187. package/src/components/molecules/VTabs/VTabPanel.test.ts +0 -24
  188. package/src/components/molecules/VTabs/VTabPanel.vue +0 -9
  189. package/src/components/molecules/VTabs/VTabs.test.ts +0 -92
  190. package/src/components/molecules/VTabs/VTabs.vue +0 -104
  191. package/src/components/molecules/index.ts +0 -51
  192. package/src/directives/click-outside-group.test.ts +0 -44
  193. package/src/directives/click-outside-group.ts +0 -39
  194. package/src/directives/click-outside.test.ts +0 -38
  195. package/src/directives/click-outside.ts +0 -28
  196. package/src/directives/clipboard.test.ts +0 -26
  197. package/src/directives/clipboard.ts +0 -9
  198. package/src/directives/index.ts +0 -5
  199. package/src/env.d.ts +0 -8
  200. package/src/index.ts +0 -21
  201. package/src/props/index.ts +0 -1
  202. package/src/props/props.ts +0 -62
  203. package/src/services/dark-mode.service.test.ts +0 -104
  204. package/src/services/dark-mode.service.ts +0 -75
  205. package/src/services/drawer.service.test.ts +0 -45
  206. package/src/services/drawer.service.ts +0 -46
  207. package/src/services/highlight.service.test.ts +0 -24
  208. package/src/services/highlight.service.ts +0 -19
  209. package/src/services/index.ts +0 -8
  210. package/src/services/rail.service.test.ts +0 -13
  211. package/src/services/rail.service.ts +0 -11
  212. package/src/services/settings.service.test.ts +0 -17
  213. package/src/services/settings.service.ts +0 -136
  214. package/src/styles/all.css +0 -24
  215. package/src/styles/core.css +0 -66
  216. package/src/styles/elements/alerts.css +0 -17
  217. package/src/styles/elements/badges.css +0 -31
  218. package/src/styles/elements/breadcrumbs.css +0 -26
  219. package/src/styles/elements/buttons.css +0 -103
  220. package/src/styles/elements/cards.css +0 -32
  221. package/src/styles/elements/chips.css +0 -22
  222. package/src/styles/elements/forms.css +0 -269
  223. package/src/styles/elements/lists.css +0 -48
  224. package/src/styles/elements/logo-clouds.css +0 -29
  225. package/src/styles/elements/modals.css +0 -15
  226. package/src/styles/elements/placeholders.css +0 -17
  227. package/src/styles/elements/popups.css +0 -16
  228. package/src/styles/elements/tables.css +0 -102
  229. package/src/styles/elements.css +0 -19
  230. package/src/styles/highlight-js.css +0 -116
  231. package/src/styles/tailwind.css +0 -16
  232. package/src/styles/transitions/fade.css +0 -14
  233. package/src/styles/transitions.css +0 -2
  234. package/src/styles/typography.css +0 -101
  235. package/src/styles/variants.css +0 -156
  236. package/src/tailwind/core.cjs +0 -37
  237. package/src/tailwind/generated/intellisense-classes.cjs +0 -558
  238. package/src/tailwind/intellisense.cjs +0 -21
  239. package/src/tailwind/settings.cjs +0 -20
  240. package/src/tailwind/theme/colors.cjs +0 -20
  241. package/src/tailwind/tokens/backgrounds.cjs +0 -48
  242. package/src/tailwind/tokens/border-radius.cjs +0 -21
  243. package/src/tailwind/tokens/borders.cjs +0 -24
  244. package/src/tailwind/tokens/fills.cjs +0 -20
  245. package/src/tailwind/tokens/rings.cjs +0 -50
  246. package/src/tailwind/tokens/text.cjs +0 -35
  247. package/src/tailwind/vuetiful.cjs +0 -19
  248. package/src/themes/theme-rocket.css +0 -119
  249. package/src/themes/theme-sahara.css +0 -128
  250. package/src/themes/theme-seafoam.css +0 -120
  251. package/src/themes/theme-seasonal.css +0 -115
  252. package/src/themes/theme-skeleton.css +0 -115
  253. package/src/themes/theme-vintage.css +0 -125
  254. package/src/themes/theme-vuetiful.css +0 -136
  255. package/src/types/index.ts +0 -59
  256. package/src/types/tailwind.ts +0 -7
  257. package/src/utils/colors/colors.service.ts +0 -293
  258. package/src/utils/index.ts +0 -8
  259. package/src/utils/platform/platform.service.test.ts +0 -19
  260. package/src/utils/platform/platform.service.ts +0 -8
  261. package/src/utils/theme/callback.test.ts +0 -28
  262. package/src/utils/theme/remove.test.ts +0 -27
  263. package/src/utils/theme/theme-switcher.vue +0 -78
  264. package/src/utils/theme/theme.service.test.ts +0 -269
  265. package/src/utils/theme/theme.service.ts +0 -173
  266. package/src/utils/theme/themes.ts +0 -282
@@ -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 };
@@ -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,8 +0,0 @@
1
- const usePlatform = () => {
2
- const isBrowser = typeof window !== 'undefined';
3
- return {
4
- isBrowser,
5
- };
6
- };
7
-
8
- export { usePlatform };
@@ -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,78 +0,0 @@
1
- <script setup lang="ts">
2
- import { CssClasses, VButton, VLightSwitch, useTheme, vClickOutsideGroup } 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
- v-click-outside-group="{
52
- elementsInGroup: ['.vuetiful-theme-switcher__button'],
53
- callback: () => (showPopup = false),
54
- }"
55
- class="vuetiful-theme-switcher__popup absolute z-10 mt-1 space-y-4 p-4 shadow-xl rounded-container-token"
56
- :class="`${background} ${text} ${widthPopup} ${classList}`"
57
- >
58
- <section class="flex items-center justify-between">
59
- <div class="text-lg">Mode</div>
60
- <v-light-switch />
61
- </section>
62
- <nav
63
- class="vuetiful-theme-switcher__popup-list -m-4 flex flex-col gap-4 overflow-y-auto p-4"
64
- :class="`${heightList} ${classList}`"
65
- >
66
- <v-button
67
- class="vuetiful-theme-switcher__popup-list-item h-full w-full p-2 text-center capitalize hover:cursor-pointer"
68
- v-for="(theme, index) in themes"
69
- :class="`${classListItem} ${chosenTheme.name === theme.name ? 'variant-filled-surface' : ''}`"
70
- :key="index"
71
- @click="applyTheme(theme)"
72
- >
73
- {{ theme.name }}
74
- </v-button>
75
- </nav>
76
- </div>
77
- </div>
78
- </template>