@symbo.ls/init 2.10.25 → 2.10.41

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 (2) hide show
  1. package/index.js +33 -14
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -3,11 +3,12 @@
3
3
  import {
4
4
  set,
5
5
  getActiveConfig,
6
- getFontFaceString
6
+ getFontFaceString,
7
+ appendSVGSprite,
8
+ appendIconsSprite
7
9
  } from '@symbo.ls/scratch'
8
10
 
9
11
  import { isObject, deepMerge } from '@domql/utils'
10
- import { initDOMQLEmotion } from 'domql/packages/emotion'
11
12
 
12
13
  import { emotion as defaultEmotion } from '@symbo.ls/emotion'
13
14
  // import { setClassname } from 'css-in-props'
@@ -16,7 +17,7 @@ import DYNAMIC_JSON from './dynamic.json'
16
17
 
17
18
  const CONFIG = getActiveConfig()
18
19
 
19
- const prepareInit = (config = CONFIG, RC_FILE) => {
20
+ const mergeWithLocalFile = (config = CONFIG, RC_FILE) => {
20
21
  const rcfile = isObject(RC_FILE) ? RC_FILE : DYNAMIC_JSON || {}
21
22
  return deepMerge(config, rcfile)
22
23
  }
@@ -25,37 +26,55 @@ const SET_OPTIONS = {
25
26
  emotion: defaultEmotion,
26
27
  useVariable: true,
27
28
  useReset: true,
28
- initDOMQLDefine: true
29
+ useFontImport: true,
30
+ useIconSprite: true,
31
+ useSvgSprite: true
29
32
  }
30
33
 
31
34
  export const init = (config, RC_FILE, options = SET_OPTIONS) => {
32
- if (options.initDOMQLDefine) initDOMQLEmotion(options.emotion, options)
33
-
34
- const resultConfig = prepareInit(config, RC_FILE)
35
+ const resultConfig = mergeWithLocalFile(config, RC_FILE)
35
36
  const emotion = options.emotion || defaultEmotion
36
37
 
37
38
  const conf = set({
38
- verbose: false,
39
+ verbose: options.verbose,
39
40
  useReset: options.useReset,
41
+ useFontImport: options.useFontImport,
42
+ useVariable: options.useVariable,
43
+ useSvgSprite: options.useSvgSprite,
44
+ useIconSprite: options.useIconSprite,
40
45
  ...resultConfig
41
46
  }, { newConfig: options.newConfig })
42
47
 
43
48
  const FontFace = getFontFaceString(conf.FONT)
44
49
 
45
- emotion.injectGlobal(FontFace)
46
- if (options.useVariable) emotion.injectGlobal({ ':root': conf.CSS_VARS })
47
- if (options.useReset) emotion.injectGlobal(conf.RESET)
48
-
50
+ const useReset = conf.useReset
51
+ const useVariable = conf.useVariable
52
+ const useFontImport = conf.useFontImport
53
+ const useSvgSprite = conf.useSvgSprite
54
+ const hasSvgs = config.svg || config.SVG
55
+ const useIconSprite = conf.useIconSprite
56
+ const hasIcons = config.icons || config.ICONS
57
+
58
+ if (useFontImport) emotion.injectGlobal(FontFace)
59
+ if (useVariable) emotion.injectGlobal({ ':root': conf.CSS_VARS })
60
+ if (useReset) emotion.injectGlobal(conf.RESET)
61
+
62
+ if (hasSvgs) appendSVGSprite(hasSvgs, { document: options.document })
63
+ else if (useSvgSprite) appendSVGSprite(conf.SVG, { document: options.document })
64
+
65
+ if (hasIcons) appendIconsSprite(hasIcons, { document: options.document })
66
+ else if (useIconSprite) appendIconsSprite(conf.ICONS, { document: options.document })
67
+
49
68
  return conf
50
69
  }
51
70
 
52
71
  export const updateReset = (config, RC_FILE, options = { emotion: defaultEmotion }) => {
53
- const resultConfig = prepareInit(config, RC_FILE)
72
+ const resultConfig = mergeWithLocalFile(config, RC_FILE)
54
73
  const conf = set({
55
74
  verbose: false,
56
75
  ...resultConfig
57
76
  })
58
- options.emotion.injectGlobal({ ':root': conf.CSS_VARS })
77
+ options.emotion.injectGlobal({':root': conf.CSS_VARS })
59
78
  options.emotion.injectGlobal(conf.RESET)
60
79
  }
61
80
 
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@symbo.ls/init",
3
- "version": "2.10.25",
3
+ "version": "2.10.41",
4
4
  "license": "MIT",
5
- "gitHead": "891c18159d1045914b41f121474c6b707ac9db83",
5
+ "gitHead": "fe191d138564726ccb26fb5a6643c4d78709f0d3",
6
6
  "source": "index.js",
7
7
  "main": "index.js",
8
8
  "targets": {