winduum 0.2.0-beta.9 → 0.2.2-next.1

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 (43) hide show
  1. package/dist/main-rgb.css +1 -1
  2. package/dist/main.css +1 -1
  3. package/dist/tailwind.css +1 -1
  4. package/package.json +11 -5
  5. package/src/base/config.css +37 -17
  6. package/src/base/default.css +8 -2
  7. package/src/base/theme/dark-rgb.css +1 -1
  8. package/src/base/theme/dark.css +1 -6
  9. package/src/base/theme/default-rgb.css +10 -5
  10. package/src/base/theme/default.css +16 -15
  11. package/src/components/dialog.css +1 -1
  12. package/src/ui/badge/default-rgb.css +3 -3
  13. package/src/ui/badge/default.css +4 -4
  14. package/src/ui/badge/index.css +0 -1
  15. package/src/ui/btn/default-rgb.css +3 -3
  16. package/src/ui/btn/default.css +6 -6
  17. package/src/ui/btn/gradient-bordered-rgb.css +1 -1
  18. package/src/ui/btn/gradient-bordered.css +1 -1
  19. package/src/ui/btn/index.css +0 -1
  20. package/src/ui/btn/loading.css +1 -1
  21. package/src/ui/btn/raised.css +1 -1
  22. package/src/ui/check-rgb.css +2 -3
  23. package/src/ui/check.css +3 -4
  24. package/src/ui/control/default-rgb.css +2 -2
  25. package/src/ui/control/default.css +3 -3
  26. package/src/ui/control/floating-focus.css +2 -0
  27. package/src/ui/control/floating.css +0 -1
  28. package/src/ui/control/index.css +0 -1
  29. package/src/ui/{control/group.css → group.css} +14 -7
  30. package/src/ui/image.css +1 -1
  31. package/src/ui/index.css +1 -0
  32. package/src/ui/link/default.css +2 -2
  33. package/src/ui/link/underlined.css +2 -1
  34. package/src/ui/notice.css +1 -2
  35. package/src/ui/switch-rgb.css +1 -1
  36. package/src/ui/switch.css +2 -2
  37. package/src/ui/text-rgb.css +2 -2
  38. package/src/ui/text.css +8 -8
  39. package/tailwind.config.cjs +1 -1
  40. package/utils/tailwind.cjs +109 -42
  41. package/utils/tailwind.js +107 -40
  42. package/src/ui/badge/group.css +0 -16
  43. package/src/ui/btn/group.css +0 -18
package/utils/tailwind.js CHANGED
@@ -1,19 +1,55 @@
1
1
  import plugin from 'tailwindcss/plugin'
2
+ import flattenColorPalette from 'tailwindcss/src/util/flattenColorPalette'
3
+ import toColorValue from 'tailwindcss/src/util/toColorValue'
4
+ import { parseColor, formatColor } from 'tailwindcss/src/util/color'
2
5
  import twColors from 'tailwindcss/colors'
3
6
  import lodash from 'lodash'
4
7
 
8
+ function withAlphaVariable ({ color, property, variable }) {
9
+ const properties = [].concat(property)
10
+ if (typeof color === 'function') {
11
+ return {
12
+ ...Object.fromEntries(
13
+ properties.map((p) => {
14
+ return [p, color({ opacityVariable: variable, opacityValue: `var(${variable}, 1)` })]
15
+ })
16
+ )
17
+ }
18
+ }
19
+
20
+ const parsed = parseColor(color)
21
+
22
+ if (parsed === null) {
23
+ return Object.fromEntries(properties.map((p) => [p, color]))
24
+ }
25
+
26
+ if (parsed.alpha !== undefined) {
27
+ // Has an alpha value, return color as-is
28
+ return Object.fromEntries(properties.map((p) => [p, color]))
29
+ }
30
+
31
+ return {
32
+ ...Object.fromEntries(
33
+ properties.map((p) => {
34
+ return [p, formatColor({ ...parsed, alpha: `var(${variable}, 1)` })]
35
+ })
36
+ )
37
+ }
38
+ }
39
+
5
40
  export const defaultConfig = {
6
41
  colors: [
7
- 'light', 'dark', 'primary',
8
- 'warning', 'error', 'info', 'success', 'accent', 'current',
9
- 'base', 'base-primary', 'base-secondary', 'base-tertiary',
42
+ 'primary', 'accent',
43
+ 'warning', 'error', 'info', 'success', 'light', 'dark',
44
+ 'main', 'main-primary', 'main-secondary', 'main-tertiary',
10
45
  'body', 'body-primary', 'body-secondary', 'body-tertiary'
11
46
  ],
12
47
  fontFamily: ['primary', 'secondary'],
13
48
  fontWeight: ['light', 'normal', 'medium', 'semibold', 'bold', 'extrabold'],
14
49
  zIndex: [10, 20, 30, 40, 50, 60],
15
- spacing: ['xs', 'sm', 'base', 'md', 'lg', 'xl', '2xl', '3xl', 'section'],
16
- borderRadius: ['xs', 'sm', 'base', 'md', 'lg', 'xl', '2xl', '3xl', 'full'],
50
+ fontSize: ['xs', 'sm', 'base', 'md', 'lg', 'xl', '2xl', '3xl', '3xl', '4xl', '5xl', '6xl', '7xl', '7xl', '8xl', '9xl'],
51
+ spacing: ['xs', 'sm', 'md', 'lg', 'xl', '2xl', '3xl', '4xl', '5xl', '6xl', 'section'],
52
+ borderRadius: ['xs', 'sm', 'base', 'md', 'lg', 'xl', '2xl', '3xl', '4xl', '5xl', '6xl', 'full'],
17
53
  animations: ['fade-in', 'fade-out', 'fade-in-down', 'fade-out-up', 'ripple', 'spin', 'move-indeterminate'],
18
54
  screens: {
19
55
  xs: '22.5em',
@@ -26,6 +62,9 @@ export const defaultConfig = {
26
62
  '4xl': '100em',
27
63
  xxl: '126em',
28
64
  '2xxl': '158em'
65
+ },
66
+ settings: {
67
+ rgbFallback: true
29
68
  }
30
69
  }
31
70
 
@@ -55,12 +94,11 @@ export const getTailwindColors = (twColors) => {
55
94
 
56
95
  export const tailwindColors = (colors = []) => {
57
96
  colors.forEach(name => {
58
- colors[name] = ({ opacityValue }) => {
59
- if (opacityValue === undefined) {
60
- return `rgb(var(--color-${name}-rgb))`
61
- }
62
- return `rgb(var(--color-${name}-rgb) / ${opacityValue})`
97
+ if (defaultConfig.settings.rgbFallback) {
98
+ colors[name + '-rgb'] = `rgb(var(--color-${name}-rgb) / <alpha-value>)`
63
99
  }
100
+
101
+ colors[name] = `color-mix(in sRGB, var(--color-${name}) calc(<alpha-value> * 100%), transparent)`
64
102
  })
65
103
 
66
104
  return colors
@@ -73,46 +111,42 @@ export const tailwindColorsAccent = (colors = []) => {
73
111
  if (Array.isArray(color)) {
74
112
  const rgb = hexToRgb(color[1])
75
113
 
76
- result[`.accent-${color[0]}`] = {
77
- '--color-accent-rgb': `${rgb[0]} ${rgb[1]} ${rgb[2]}`,
114
+ result[`.accent-${color[0]}`] = Object.assign(defaultConfig.settings.rgbFallback
115
+ ? {
116
+ '--color-accent-rgb': `${rgb[0]} ${rgb[1]} ${rgb[2]}`,
117
+ '--color-accent-current-rgb': `var(--color-${color}-current-rgb, var(--color-light-rgb))`
118
+ }
119
+ : {}, {
78
120
  '--color-accent': `rgb(${rgb[0]} ${rgb[1]} ${rgb[2]})`,
79
121
  '--color-accent-current': `var(--color-${color}-current, var(--color-light))`
80
- }
122
+ })
81
123
  } else {
82
- result[`.accent-${color}`] = {
83
- '--color-accent-rgb': `var(--color-${color}-rgb)`,
124
+ result[`.accent-${color}`] = Object.assign(defaultConfig.settings.rgbFallback
125
+ ? {
126
+ '--color-accent-rgb': `var(--color-${color}-rgb)`,
127
+ '--color-accent-current-rgb': `var(--color-${color}-current-rgb, var(--color-light-rgb))`
128
+ }
129
+ : {}, {
84
130
  '--color-accent': `var(--color-${color})`,
85
131
  '--color-accent-current': `var(--color-${color}-current, var(--color-light))`
86
- }
132
+ })
87
133
  }
88
134
  })
89
135
 
90
136
  return result
91
137
  }
92
138
 
93
- export const tailwindColorsCurrent = (colors = []) => {
94
- const result = {}
95
-
96
- colors.forEach(color => {
97
- if (Array.isArray(color)) {
98
- const rgb = hexToRgb(color[1])
99
-
100
- result[`.text-${color[0]}`] = {
101
- '--color-current': `${rgb[0]} ${rgb[1]} ${rgb[2]}`
102
- }
103
- } else {
104
- result[`.text-${color}`] = {
105
- '--color-current': `var(--color-${color})`
106
- }
107
- }
139
+ export const tailwindVariables = (type, variables = [], values = {}) => {
140
+ variables.forEach(name => {
141
+ values[name] = `var(--${type}-${name})`
108
142
  })
109
143
 
110
- return result
144
+ return values
111
145
  }
112
146
 
113
- export const tailwindVariables = (type, variables = [], values = {}) => {
147
+ export const tailwindVariablesFont = (type, variables = [], values = {}) => {
114
148
  variables.forEach(name => {
115
- values[name] = `var(--${type}-${name})`
149
+ values[name] = [`var(--${type}-${name})`, `calc(var(--${type}-${name}) + 0.5rem)`]
116
150
  })
117
151
 
118
152
  return values
@@ -133,17 +167,48 @@ export const tailwindAnimations = (values) => {
133
167
  export const createPlugin = (userConfig = {}) => {
134
168
  userConfig = lodash.merge(defaultConfig, userConfig)
135
169
 
136
- return plugin(({ addUtilities, theme, variants, e }) => {
170
+ return plugin(({ addUtilities, matchUtilities, theme, variants, e, corePlugins }) => {
137
171
  addUtilities(Object.assign(tailwindColorsAccent(getTailwindColors(twColors)), tailwindColorsAccent(userConfig.colors)))
138
- addUtilities(Object.assign(tailwindColorsCurrent(getTailwindColors(twColors)), tailwindColorsCurrent(userConfig.colors)))
172
+ matchUtilities(
173
+ {
174
+ text: (value, extra) => {
175
+ const matchValue = toColorValue(value).match(/var\((.*?)\)/)
176
+ const fallbackRgb = matchValue && matchValue[0].includes('-rgb')
177
+
178
+ const colorProperties = {}
179
+
180
+ if (fallbackRgb) {
181
+ colorProperties['--color-body-current-rgb'] = matchValue[0]
182
+ }
183
+
184
+ if (!corePlugins('textOpacity')) {
185
+ return {
186
+ ...colorProperties,
187
+ '--color-body-current': toColorValue(value),
188
+ color: toColorValue(value)
189
+ }
190
+ }
191
+
192
+ return {
193
+ ...colorProperties,
194
+ '--color-body-current': toColorValue(value),
195
+ ...withAlphaVariable({
196
+ color: value,
197
+ property: 'color',
198
+ variable: '--tw-text-opacity'
199
+ })
200
+ }
201
+ }
202
+ },
203
+ { values: flattenColorPalette(theme('textColor')), type: ['color', 'any'] }
204
+ )
139
205
  addUtilities(tailwindAnimations(userConfig.animations))
140
206
  addUtilities([
141
207
  Object.entries(theme('spacing')).map(([key, value]) => {
142
208
  return {
143
209
  [`.${e(`sq-${key}`)}`]: {
144
- '--sq': `${value}`,
145
- width: 'var(--sq)',
146
- height: 'var(--sq)'
210
+ width: value,
211
+ height: value
147
212
  }
148
213
  }
149
214
  })
@@ -151,11 +216,13 @@ export const createPlugin = (userConfig = {}) => {
151
216
  }, {
152
217
  corePlugins: {
153
218
  preflight: false,
154
- container: false
219
+ container: false,
220
+ textColor: false
155
221
  },
156
222
  theme: {
157
223
  extend: {
158
224
  colors: tailwindColors(userConfig.colors),
225
+ fontSize: tailwindVariablesFont('text', userConfig.fontSize),
159
226
  fontFamily: tailwindVariables('font', userConfig.fontFamily),
160
227
  fontWeight: tailwindVariables('font', userConfig.fontWeight),
161
228
  zIndex: tailwindVariables('z', userConfig.zIndex, {
@@ -1,16 +0,0 @@
1
- .ui-badge-group {
2
- display: flex;
3
-
4
- & :where(.ui-badge) {
5
- &:not(:first-child) {
6
- border-top-left-radius: 0;
7
- border-bottom-left-radius: 0;
8
- border-left: 0;
9
- }
10
-
11
- &:not(:last-child) {
12
- border-top-right-radius: 0;
13
- border-bottom-right-radius: 0;
14
- }
15
- }
16
- }
@@ -1,18 +0,0 @@
1
- .ui-btn-group {
2
- display: flex;
3
-
4
- & :where(.ui-btn) {
5
- --ui-btn-outline-offset: 0;
6
-
7
- &:not(:first-child) {
8
- border-top-left-radius: 0;
9
- border-bottom-left-radius: 0;
10
- border-left: 0;
11
- }
12
-
13
- &:not(:last-child) {
14
- border-top-right-radius: 0;
15
- border-bottom-right-radius: 0;
16
- }
17
- }
18
- }