@symbo.ls/scratch 0.7.21 → 0.7.22
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/system/font.js +6 -2
- package/src/utils/font.js +14 -10
package/package.json
CHANGED
package/src/system/font.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
import { isObject } from '@domql/utils'
|
|
3
4
|
import { CONFIG, CSS_VARS } from '../factory' // eslint-disable-line
|
|
4
5
|
|
|
5
6
|
import {
|
|
6
7
|
getDefaultOrFirstKey,
|
|
7
|
-
getFontFaceEach
|
|
8
|
+
getFontFaceEach,
|
|
9
|
+
setCustomFontMedia
|
|
8
10
|
} from '../utils'
|
|
9
11
|
|
|
10
12
|
// const ENV = process.env.NODE_ENV
|
|
11
13
|
|
|
12
14
|
export const setFont = (val, key) => {
|
|
13
15
|
const CSSvar = `--font-${key}`
|
|
14
|
-
const fontFace =
|
|
16
|
+
const fontFace = isObject(val)
|
|
17
|
+
? setCustomFontMedia(key, val.url)
|
|
18
|
+
: getFontFaceEach(key, val)
|
|
15
19
|
return { var: CSSvar, value: val, fontFace }
|
|
16
20
|
}
|
|
17
21
|
|
package/src/utils/font.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
import { isObject } from '@domql/utils'
|
|
4
|
+
|
|
3
5
|
export const getDefaultOrFirstKey = (LIBRARY, key) => {
|
|
4
6
|
if (LIBRARY[key]) return LIBRARY[key].value
|
|
5
7
|
if (LIBRARY.default) return LIBRARY[LIBRARY.default].value
|
|
@@ -11,22 +13,22 @@ export const getFontFormat = url => url.split(/[#?]/)[0].split('.').pop().trim()
|
|
|
11
13
|
|
|
12
14
|
export const setInCustomFontMedia = str => `@font-face { ${str} }`
|
|
13
15
|
|
|
14
|
-
export const setCustomFont = (name,
|
|
16
|
+
export const setCustomFont = (name, url, weight) => `
|
|
15
17
|
font-family: '${name}';
|
|
16
18
|
font-style: normal;
|
|
17
|
-
font-weight: ${weight}
|
|
19
|
+
${weight && `font-weight: ${weight};`}
|
|
18
20
|
src: url('${url}') format('${getFontFormat(url)}');`
|
|
19
21
|
|
|
20
|
-
export const setCustomFontMedia = (name,
|
|
21
|
-
${setCustomFont(
|
|
22
|
+
export const setCustomFontMedia = (name, url, weight) => `@font-face {
|
|
23
|
+
${setCustomFont(name, url, weight)}
|
|
22
24
|
}`
|
|
23
25
|
// src: url('${url}') format('${getFontFormat(url)}');
|
|
24
26
|
|
|
25
|
-
export const getFontFaceEach = (name,
|
|
26
|
-
const keys = Object.keys(
|
|
27
|
+
export const getFontFaceEach = (name, weights) => {
|
|
28
|
+
const keys = Object.keys(weights)
|
|
27
29
|
return keys.map(key => {
|
|
28
|
-
const {
|
|
29
|
-
return setCustomFont(name,
|
|
30
|
+
const { url, fontWeight } = weights[key]
|
|
31
|
+
return setCustomFont(name, url, fontWeight)
|
|
30
32
|
})
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -35,8 +37,10 @@ export const getFontFace = LIBRARY => {
|
|
|
35
37
|
return keys.map(key => getFontFaceEach(key, LIBRARY[key].value))
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
export const getFontFaceEachString = (name,
|
|
39
|
-
|
|
40
|
+
export const getFontFaceEachString = (name, weights) => {
|
|
41
|
+
const isObj = isObject(weights)
|
|
42
|
+
if (isObj) return setCustomFontMedia(name, weights.url)
|
|
43
|
+
return getFontFaceEach(name, weights).map(setInCustomFontMedia)
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
export const getFontFaceString = LIBRARY => {
|