@symbo.ls/scratch 0.3.4 → 0.3.7

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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@symbo.ls/scratch",
3
3
  "description": "Φ / CSS framework and methodology.",
4
4
  "author": "Symbols",
5
- "version": "0.3.4",
5
+ "version": "0.3.7",
6
6
  "files": [
7
7
  "src"
8
8
  ],
@@ -8,11 +8,15 @@ import {
8
8
  isObject,
9
9
  isString,
10
10
  isObjectLike,
11
- getColorShade,
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,20 @@ export const getColor = value => {
62
66
  if (rgb) {
63
67
  if (tone) {
64
68
  if (!val[tone]) {
65
- const toHex = rgbArrayToHex(rgb.split(', '))
66
- rgb = hexToRgbArray(getColorShade(toHex, tone)).join(', ')
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
+ const [r, g, b] = [...rgb.split(', ').map(v => parseFloat(v))]
74
+ const hsl = rgbToHSL(r, g, b)
75
+ const [h, s, l] = hsl
76
+ const newRgb = hslToRgb(h, s, parseFloat(tone) / 100 * 255)
77
+ rgb = newRgb
78
+ }
67
79
  val[tone] = { rgb, var: `${val.var}-${tone}` }
68
80
  } else rgb = val[tone].rgb
69
81
  }
70
- if (alpha) return `rgba(${val.rgb}, ${alpha})`
82
+ if (alpha) return `rgba(${rgb}, ${alpha})`
71
83
  return `rgb(${rgb})`
72
84
  } else return val.value
73
85
  }
@@ -202,9 +214,7 @@ const setFontFamily = (val, key) => {
202
214
  return { var: CSSvar, value: str, arr: value, type }
203
215
  }
204
216
 
205
- const setSameValue = (val, key) => {
206
- return val
207
- }
217
+ const setSameValue = (val, key) => val
208
218
 
209
219
  export const SETTERS = {
210
220
  color: setColor,
@@ -99,7 +99,7 @@ export const rgbToHex = (r, g, b) => {
99
99
  }
100
100
 
101
101
  export const rgbArrayToHex = ([r, g, b]) => {
102
- return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)
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,58 @@ 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
+ const a = Math.max(r, g, b); const n = a - Math.min(r, g, b); const f = (1 - Math.abs(a + a - n - 1))
163
+ const h = n && ((a == r) ? (g - b) / n : ((a == g) ? 2 + (b - r) / n : 4 + (r - g) / n))
164
+ return [60 * (h < 0 ? h + 6 : h), f ? n / f : 0, (a + a - n) / 2]
165
+ }
166
+
167
+ export const hslToRgb = (h, s, l,
168
+ a = s * Math.min(l, 1 - l),
169
+ f = (n, k = (n + h / 30) % 12) => l - a * Math.max(
170
+ Math.min(k - 3, 9 - k, 1), -1
171
+ )
172
+ ) => [f(0), f(8), f(4)]
173
+
122
174
  export const getColorShade = (col, amt) => {
123
175
  const num = parseInt(col, 16)
124
176
 
@@ -275,6 +327,7 @@ export const generateSequence = ({ type, base, ratio, range, subSequence, ...sta
275
327
  export const fallBack = ({ type, prop, val = 'A', prefix = '--font-size-' }) => {
276
328
  if (typeof val !== 'string') console.warn(prop, val, 'is not a string')
277
329
 
330
+ if (val === '-' || val === '') return ({ })
278
331
  if (val === 'auto') return ({ [prop]: val })
279
332
 
280
333
  // const startsWithLetterRegex = /^[a-zA-Z]/i