@symbo.ls/scratch 0.3.3 → 0.3.6
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 +21 -5
- package/src/reset.js +2 -0
- package/src/utils/index.js +54 -1
package/package.json
CHANGED
package/src/methods/set.js
CHANGED
|
@@ -8,11 +8,15 @@ 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
|
|
|
18
22
|
const ENV = process.env.NODE_ENV
|
|
@@ -62,12 +66,24 @@ export const getColor = value => {
|
|
|
62
66
|
if (rgb) {
|
|
63
67
|
if (tone) {
|
|
64
68
|
if (!val[tone]) {
|
|
65
|
-
const toHex = rgbArrayToHex(rgb.split(', '))
|
|
66
|
-
|
|
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
|
+
}
|
|
67
83
|
val[tone] = { rgb, var: `${val.var}-${tone}` }
|
|
68
84
|
} else rgb = val[tone].rgb
|
|
69
85
|
}
|
|
70
|
-
if (alpha) return `rgba(${
|
|
86
|
+
if (alpha) return `rgba(${rgb}, ${alpha})`
|
|
71
87
|
return `rgb(${rgb})`
|
|
72
88
|
} else return val.value
|
|
73
89
|
}
|
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
|
@@ -99,7 +99,7 @@ export const rgbToHex = (r, g, b) => {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
export const rgbArrayToHex = ([r, g, b]) => {
|
|
102
|
-
return
|
|
102
|
+
return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
export const hexToRgba = (hex, alpha = 1) => {
|
|
@@ -119,6 +119,59 @@ export const mixTwoRgb = (colorA, colorB, range = 0.5) => {
|
|
|
119
119
|
return `rgb(${arr})`
|
|
120
120
|
}
|
|
121
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
|
+
|
|
122
175
|
export const getColorShade = (col, amt) => {
|
|
123
176
|
const num = parseInt(col, 16)
|
|
124
177
|
|