@symbo.ls/scratch 0.3.2 → 0.3.5
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/package.json +1 -1
- package/src/methods/set.js +30 -8
- package/src/reset.js +2 -0
- package/src/utils/index.js +60 -2
package/package.json
CHANGED
package/src/methods/set.js
CHANGED
|
@@ -8,13 +8,19 @@ import {
|
|
|
8
8
|
isObject,
|
|
9
9
|
isString,
|
|
10
10
|
isObjectLike,
|
|
11
|
-
|
|
11
|
+
rgbToHSL,
|
|
12
12
|
hexToRgbArray,
|
|
13
13
|
rgbArrayToHex,
|
|
14
14
|
getDefaultOrFirstKey,
|
|
15
|
-
getFontFaceEach
|
|
15
|
+
getFontFaceEach,
|
|
16
|
+
hslToRgb,
|
|
17
|
+
getColorShade,
|
|
18
|
+
pSBC,
|
|
19
|
+
changeLightness
|
|
16
20
|
} from '../utils'
|
|
17
21
|
|
|
22
|
+
const ENV = process.env.NODE_ENV
|
|
23
|
+
|
|
18
24
|
const setColor = (val, key) => {
|
|
19
25
|
const [r, g, b, a = 1] = colorStringToRgbaArray(val.value || val)
|
|
20
26
|
const alpha = parseFloat(a.toFixed(2))
|
|
@@ -39,14 +45,17 @@ const setGradient = (val, key) => {
|
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
export const getColor = value => {
|
|
42
|
-
if (!isString(value))
|
|
48
|
+
if (!isString(value)) {
|
|
49
|
+
if (ENV === 'test' || ENV === 'development') console.warn(value, '- type for color is not valid')
|
|
50
|
+
return
|
|
51
|
+
}
|
|
43
52
|
|
|
44
53
|
const [name, alpha, tone] = isArray(value) ? value : value.split(' ')
|
|
45
54
|
const { COLOR, GRADIENT } = CONFIG
|
|
46
55
|
const val = COLOR[name] || GRADIENT[name]
|
|
47
56
|
|
|
48
57
|
if (!val) {
|
|
49
|
-
console.warn('Can\'t find color', name)
|
|
58
|
+
if (ENV === 'test' || ENV === 'development') console.warn('Can\'t find color', name)
|
|
50
59
|
return value
|
|
51
60
|
}
|
|
52
61
|
|
|
@@ -57,12 +66,24 @@ export const getColor = value => {
|
|
|
57
66
|
if (rgb) {
|
|
58
67
|
if (tone) {
|
|
59
68
|
if (!val[tone]) {
|
|
60
|
-
const toHex = rgbArrayToHex(rgb.split(', '))
|
|
61
|
-
|
|
69
|
+
const toHex = rgbArrayToHex(rgb.split(', ').map(v => parseFloat(v)))
|
|
70
|
+
if (tone.slice(0, 1) === '-' || tone.slice(0, 1) === '+') {
|
|
71
|
+
rgb = hexToRgbArray(getColorShade(toHex, parseFloat(tone))).join(', ')
|
|
72
|
+
} else {
|
|
73
|
+
console.log(rgb)
|
|
74
|
+
const [r, g, b] = [...rgb.split(', ').map(v => parseFloat(v))]
|
|
75
|
+
const hsl = rgbToHSL(r, g, b)
|
|
76
|
+
const [h, s, l] = hsl
|
|
77
|
+
console.log(h, s, l, tone)
|
|
78
|
+
const newRgb = hslToRgb(h, s, parseFloat(tone) / 100 * 255)
|
|
79
|
+
console.log(newRgb)
|
|
80
|
+
rgb = newRgb
|
|
81
|
+
console.log(rgb)
|
|
82
|
+
}
|
|
62
83
|
val[tone] = { rgb, var: `${val.var}-${tone}` }
|
|
63
84
|
} else rgb = val[tone].rgb
|
|
64
85
|
}
|
|
65
|
-
if (alpha) return `rgba(${
|
|
86
|
+
if (alpha) return `rgba(${rgb}, ${alpha})`
|
|
66
87
|
return `rgb(${rgb})`
|
|
67
88
|
} else return val.value
|
|
68
89
|
}
|
|
@@ -97,7 +118,8 @@ export const getTheme = value => {
|
|
|
97
118
|
if (state && state[subThemeName]) return getThemeValue(state[subThemeName])
|
|
98
119
|
} else if (isObject(value)) return setThemeValue(value)
|
|
99
120
|
else if (isString(value) && THEME[value]) return getThemeValue(THEME[value])
|
|
100
|
-
|
|
121
|
+
|
|
122
|
+
if (ENV === 'test' || ENV === 'development') console.warn('Can\'t find theme', value)
|
|
101
123
|
}
|
|
102
124
|
|
|
103
125
|
const setPrefersScheme = (theme, key, variant, themeValue) => {
|
package/src/reset.js
CHANGED
|
@@ -15,6 +15,8 @@ export const applyReset = (reset = {}) => deepMerge(merge(RESET, reset), {
|
|
|
15
15
|
left: '0',
|
|
16
16
|
margin: '0',
|
|
17
17
|
WebkitFontSmoothing: 'antialiased',
|
|
18
|
+
transform: 'translate3d(0, 0, 1px)',
|
|
19
|
+
scrollBehavior: 'smooth',
|
|
18
20
|
|
|
19
21
|
fontFamily: CONFIG.DOCUMENT.fontFamily,
|
|
20
22
|
|
package/src/utils/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { UNIT } from '../config'
|
|
4
4
|
|
|
5
|
+
const ENV = process.env.NODE_ENV
|
|
6
|
+
|
|
5
7
|
export const isString = arg => typeof arg === 'string'
|
|
6
8
|
|
|
7
9
|
export const isArray = arg => Array.isArray(arg)
|
|
@@ -97,7 +99,7 @@ export const rgbToHex = (r, g, b) => {
|
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
export const rgbArrayToHex = ([r, g, b]) => {
|
|
100
|
-
return
|
|
102
|
+
return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
export const hexToRgba = (hex, alpha = 1) => {
|
|
@@ -117,6 +119,59 @@ export const mixTwoRgb = (colorA, colorB, range = 0.5) => {
|
|
|
117
119
|
return `rgb(${arr})`
|
|
118
120
|
}
|
|
119
121
|
|
|
122
|
+
// export const rgbToHSL = (r, g, b) => {
|
|
123
|
+
// console.log(r, g, b)
|
|
124
|
+
// r /= 255
|
|
125
|
+
// g /= 255
|
|
126
|
+
// b /= 255
|
|
127
|
+
// const l = Math.max(r, g, b)
|
|
128
|
+
// const s = l - Math.min(r, g, b)
|
|
129
|
+
// const h = s
|
|
130
|
+
// ? l === r
|
|
131
|
+
// ? (g - b) / s
|
|
132
|
+
// : l === g
|
|
133
|
+
// ? 2 + (b - r) / s
|
|
134
|
+
// : 4 + (r - g) / s
|
|
135
|
+
// : 0
|
|
136
|
+
// return [
|
|
137
|
+
// 60 * h < 0 ? 60 * h + 360 : 60 * h,
|
|
138
|
+
// 100 * (s ? (l <= 0.5 ? s / (2 * l - s) : s / (2 - (2 * l - s))) : 0),
|
|
139
|
+
// (100 * (2 * l - s)) / 2
|
|
140
|
+
// ]
|
|
141
|
+
// }
|
|
142
|
+
|
|
143
|
+
// export const hslToRgb = (h, s, l) => {
|
|
144
|
+
// console.log(h, s, l)
|
|
145
|
+
// const a = s * Math.min(l, 1 - l)
|
|
146
|
+
// const f = (n, k = (n + h / 30) % 12) => l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1)
|
|
147
|
+
// return [f(0), f(8), f(4)].map(v => v * 1000)
|
|
148
|
+
// }
|
|
149
|
+
|
|
150
|
+
export const changeLightness = (delta, hsl) => {
|
|
151
|
+
const [hue, saturation, lightness] = hsl
|
|
152
|
+
|
|
153
|
+
const newLightness = Math.max(
|
|
154
|
+
0,
|
|
155
|
+
Math.min(100, lightness + parseFloat(delta))
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
return [hue, saturation, newLightness]
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export const rgbToHSL = (r, g, b) => {
|
|
162
|
+
console.log(r, g, b)
|
|
163
|
+
const a = Math.max(r, g, b); const n = a - Math.min(r, g, b); const f = (1 - Math.abs(a + a - n - 1))
|
|
164
|
+
const h = n && ((a == r) ? (g - b) / n : ((a == g) ? 2 + (b - r) / n : 4 + (r - g) / n))
|
|
165
|
+
return [60 * (h < 0 ? h + 6 : h), f ? n / f : 0, (a + a - n) / 2]
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export const hslToRgb = (h, s, l,
|
|
169
|
+
a = s * Math.min(l, 1 - l),
|
|
170
|
+
f = (n, k = (n + h / 30) % 12) => l - a * Math.max(
|
|
171
|
+
Math.min(k - 3, 9 - k, 1), -1
|
|
172
|
+
)
|
|
173
|
+
) => [f(0), f(8), f(4)]
|
|
174
|
+
|
|
120
175
|
export const getColorShade = (col, amt) => {
|
|
121
176
|
const num = parseInt(col, 16)
|
|
122
177
|
|
|
@@ -153,7 +208,10 @@ export const mixTwoRgba = (colorA, colorB, range = 0.5) => {
|
|
|
153
208
|
|
|
154
209
|
export const opacify = (color, opacity) => {
|
|
155
210
|
const arr = colorStringToRgbaArray(color)
|
|
156
|
-
if (!arr)
|
|
211
|
+
if (!arr) {
|
|
212
|
+
if (ENV === 'test' || ENV === 'development') console.warn(color + 'color is not rgba')
|
|
213
|
+
return
|
|
214
|
+
}
|
|
157
215
|
arr[3] = opacity
|
|
158
216
|
return `rgba(${arr})`
|
|
159
217
|
}
|