vueless 0.0.696 → 0.0.698

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 (2) hide show
  1. package/package.json +1 -1
  2. package/utils/theme.ts +104 -59
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.696",
3
+ "version": "0.0.698",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
package/utils/theme.ts CHANGED
@@ -37,6 +37,19 @@ interface Colors extends DefaultColors {
37
37
  [key: string]: Partial<TailwindColorShades> | string;
38
38
  }
39
39
 
40
+ declare interface RootCSSVariableOptions {
41
+ colors: Colors;
42
+ brand: string;
43
+ gray: string;
44
+ ring: number;
45
+ ringOffset: number;
46
+ ringOffsetColorDark: string;
47
+ ringOffsetColorLight: string;
48
+ roundingSm: number;
49
+ rounding: number;
50
+ roundingLg: number;
51
+ }
52
+
40
53
  export function themeInit() {
41
54
  if (isSSR) return;
42
55
 
@@ -107,6 +120,28 @@ export function getSelectedGrayColor() {
107
120
  return (isCSR && localStorage.getItem("gray")) || undefined;
108
121
  }
109
122
 
123
+ export function convertHexInRgb(hex?: string) {
124
+ if (!hex) return;
125
+
126
+ const color = hex.replace(/#/g, "");
127
+
128
+ let r, g, b;
129
+
130
+ if (color.length === 6) {
131
+ r = parseInt(color.substring(0, 2), 16);
132
+ g = parseInt(color.substring(2, 4), 16);
133
+ b = parseInt(color.substring(4, 6), 16);
134
+ }
135
+
136
+ if (color.length === 3) {
137
+ r = parseInt(color.substring(0, 1).repeat(2), 16);
138
+ g = parseInt(color.substring(1, 2).repeat(2), 16);
139
+ b = parseInt(color.substring(2, 3).repeat(2), 16);
140
+ }
141
+
142
+ return color.length === 6 || color.length === 3 ? `${r}, ${g}, ${b}` : "";
143
+ }
144
+
110
145
  export function setTheme(config: Config = {}) {
111
146
  setColorMode(vuelessConfig.colorMode || config.colorMode || ColorMode.Light);
112
147
 
@@ -119,7 +154,7 @@ export function setTheme(config: Config = {}) {
119
154
  let brand: BrandColors =
120
155
  config.brand ?? getSelectedBrandColor() ?? vuelessConfig.brand ?? DEFAULT_BRAND_COLOR;
121
156
 
122
- const gray: GrayColors =
157
+ let gray: GrayColors =
123
158
  config.gray ?? getSelectedGrayColor() ?? vuelessConfig.gray ?? DEFAULT_GRAY_COLOR;
124
159
 
125
160
  const ring = config.ring ?? vuelessConfig.ring ?? DEFAULT_RING;
@@ -135,18 +170,6 @@ export function setTheme(config: Config = {}) {
135
170
  vuelessConfig.ringOffsetColorLight ??
136
171
  DEFAULT_RING_OFFSET_COLOR_LIGHT;
137
172
 
138
- const isDarkMode = isCSR && document.documentElement.classList.contains(DARK_MODE_SELECTOR);
139
- const defaultRingOffsetColor = isDarkMode ? ringOffsetColorDark : ringOffsetColorLight;
140
- const defaultBrandShade = isDarkMode ? 400 : 600;
141
- const defaultGrayShade = isDarkMode ? 400 : 600;
142
-
143
- isCSR && localStorage.setItem("brand", brand);
144
- isCSR && localStorage.setItem("gray", gray);
145
-
146
- if (brand === GRAYSCALE_COLOR) {
147
- brand = gray;
148
- }
149
-
150
173
  const colors: Colors = merge(
151
174
  TAILWIND_COLORS as Colors,
152
175
  tailwindConfig?.theme?.extend?.colors || {},
@@ -160,13 +183,81 @@ export function setTheme(config: Config = {}) {
160
183
  if (!isBrandColor) {
161
184
  // eslint-disable-next-line no-console
162
185
  console.warn(`The brand color '${brand}' is missing in your palette.`);
186
+
187
+ brand = DEFAULT_BRAND_COLOR;
163
188
  }
164
189
 
165
190
  if (!isGrayColor) {
166
191
  // eslint-disable-next-line no-console
167
192
  console.warn(`The gray color '${gray}' is missing in your palette.`);
193
+
194
+ gray = DEFAULT_GRAY_COLOR;
195
+ }
196
+
197
+ isCSR && localStorage.setItem("brand", brand);
198
+ isCSR && localStorage.setItem("gray", gray);
199
+
200
+ return setRootCSSVariables({
201
+ colors,
202
+ brand,
203
+ gray,
204
+ ring,
205
+ ringOffset,
206
+ ringOffsetColorDark,
207
+ ringOffsetColorLight,
208
+ roundingSm,
209
+ rounding,
210
+ roundingLg,
211
+ });
212
+ }
213
+
214
+ function getRoundings(sm?: number, md?: number, lg?: number) {
215
+ const rounding = Math.max(0, md ?? DEFAULT_ROUNDING);
216
+ let roundingSm = Math.max(0, rounding - ROUNDING_DECREMENT);
217
+ let roundingLg = Math.max(0, rounding + ROUNDING_INCREMENT);
218
+
219
+ if (rounding === ROUNDING_INCREMENT) {
220
+ roundingSm = ROUNDING_DECREMENT;
221
+ }
222
+
223
+ if (rounding === ROUNDING_DECREMENT) {
224
+ roundingSm = ROUNDING_INCREMENT - ROUNDING_DECREMENT;
225
+ }
226
+
227
+ if (rounding === 0) {
228
+ roundingLg = ROUNDING_INCREMENT - ROUNDING_DECREMENT;
229
+ }
230
+
231
+ return {
232
+ rounding,
233
+ roundingSm: sm === undefined ? roundingSm : Math.max(0, sm),
234
+ roundingLg: lg === undefined ? roundingLg : Math.max(0, lg),
235
+ };
236
+ }
237
+
238
+ function setRootCSSVariables(options: RootCSSVariableOptions) {
239
+ if (options.brand === GRAYSCALE_COLOR) {
240
+ options.brand = options.gray;
168
241
  }
169
242
 
243
+ const {
244
+ colors,
245
+ brand,
246
+ gray,
247
+ ring,
248
+ ringOffset,
249
+ ringOffsetColorDark,
250
+ ringOffsetColorLight,
251
+ roundingSm,
252
+ rounding,
253
+ roundingLg,
254
+ } = options;
255
+
256
+ const isDarkMode = isCSR && document.documentElement.classList.contains(DARK_MODE_SELECTOR);
257
+ const defaultRingOffsetColor = isDarkMode ? ringOffsetColorDark : ringOffsetColorLight;
258
+ const defaultBrandShade = isDarkMode ? 400 : 600;
259
+ const defaultGrayShade = isDarkMode ? 400 : 600;
260
+
170
261
  const variables: Partial<VuelessCssVariables> = {
171
262
  "--vl-rounding-sm": `${Number(roundingSm) / PX_IN_REM}rem`,
172
263
  "--vl-rounding": `${Number(rounding) / PX_IN_REM}rem`,
@@ -209,49 +300,3 @@ export function setTheme(config: Config = {}) {
209
300
 
210
301
  return rootVariables;
211
302
  }
212
-
213
- export function convertHexInRgb(hex?: string) {
214
- if (!hex) return;
215
-
216
- const color = hex.replace(/#/g, "");
217
-
218
- let r, g, b;
219
-
220
- if (color.length === 6) {
221
- r = parseInt(color.substring(0, 2), 16);
222
- g = parseInt(color.substring(2, 4), 16);
223
- b = parseInt(color.substring(4, 6), 16);
224
- }
225
-
226
- if (color.length === 3) {
227
- r = parseInt(color.substring(0, 1).repeat(2), 16);
228
- g = parseInt(color.substring(1, 2).repeat(2), 16);
229
- b = parseInt(color.substring(2, 3).repeat(2), 16);
230
- }
231
-
232
- return color.length === 6 || color.length === 3 ? `${r}, ${g}, ${b}` : "";
233
- }
234
-
235
- function getRoundings(sm?: number, md?: number, lg?: number) {
236
- const rounding = Math.max(0, md ?? DEFAULT_ROUNDING);
237
- let roundingSm = Math.max(0, rounding - ROUNDING_DECREMENT);
238
- let roundingLg = Math.max(0, rounding + ROUNDING_INCREMENT);
239
-
240
- if (rounding === ROUNDING_INCREMENT) {
241
- roundingSm = ROUNDING_DECREMENT;
242
- }
243
-
244
- if (rounding === ROUNDING_DECREMENT) {
245
- roundingSm = ROUNDING_INCREMENT - ROUNDING_DECREMENT;
246
- }
247
-
248
- if (rounding === 0) {
249
- roundingLg = ROUNDING_INCREMENT - ROUNDING_DECREMENT;
250
- }
251
-
252
- return {
253
- rounding,
254
- roundingSm: sm === undefined ? roundingSm : Math.max(0, sm),
255
- roundingLg: lg === undefined ? roundingLg : Math.max(0, lg),
256
- };
257
- }