smbls 3.2.3 → 3.2.8
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/bin/smbls.js +2 -0
- package/dist/cjs/index.js +2 -3
- package/dist/cjs/src/createDomql.js +110 -0
- package/dist/cjs/src/define.js +38 -0
- package/dist/cjs/src/fetchOnCreate.js +54 -0
- package/dist/cjs/src/index.js +109 -0
- package/dist/cjs/src/init.js +127 -0
- package/dist/cjs/src/options.js +57 -0
- package/dist/cjs/src/prepare.js +296 -0
- package/dist/cjs/src/router.js +84 -0
- package/dist/cjs/src/syncExtend.js +70 -0
- package/dist/cjs/src/utilImports.js +35 -0
- package/dist/esm/index.js +2 -3
- package/dist/esm/src/createDomql.js +96 -0
- package/dist/esm/src/define.js +18 -0
- package/dist/esm/src/fetchOnCreate.js +34 -0
- package/dist/esm/src/index.js +78 -0
- package/dist/esm/src/init.js +103 -0
- package/dist/esm/src/options.js +37 -0
- package/dist/esm/src/prepare.js +273 -0
- package/dist/esm/src/router.js +64 -0
- package/dist/esm/src/syncExtend.js +50 -0
- package/dist/esm/src/utilImports.js +14 -0
- package/dist/iife/index.js +740 -0
- package/index.js +2 -6
- package/package.json +26 -15
- package/src/createDomql.js +107 -0
- package/src/define.js +22 -0
- package/src/fetchOnCreate.js +34 -0
- package/src/index.js +106 -0
- package/src/init.js +121 -0
- package/src/options.js +37 -0
- package/src/prepare.js +307 -0
- package/src/router.js +73 -0
- package/src/syncExtend.js +50 -0
- package/src/utilImports.js +10 -0
- package/dist/cjs/package.json +0 -4
package/index.js
CHANGED
|
@@ -2,14 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
export * from '@domql/utils'
|
|
4
4
|
export * from 'attrs-in-props'
|
|
5
|
-
export * from '@symbo.ls/create'
|
|
6
5
|
export * from 'css-in-props'
|
|
7
6
|
export * from '@symbo.ls/default-config'
|
|
8
7
|
export * from '@symbo.ls/emotion'
|
|
9
|
-
export * from '@symbo.ls/init'
|
|
10
8
|
export * from '@symbo.ls/scratch'
|
|
11
9
|
export * from '@symbo.ls/uikit'
|
|
12
|
-
export * from '@symbo.ls/utils'
|
|
13
|
-
|
|
14
|
-
// export * from '@symbo.ls/socket/client' // TODO: Check with @nikoloza
|
|
15
|
-
// export * from '@symbo.ls/sync' // TODO: add it soon
|
|
10
|
+
export * from '@symbo.ls/smbls-utils'
|
|
11
|
+
export * from './src/index.js'
|
package/package.json
CHANGED
|
@@ -1,35 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smbls",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "https://github.com/symbo-ls/smbls",
|
|
6
6
|
"gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"module": "index.js",
|
|
9
|
-
"main": "index.js",
|
|
10
|
-
"unpkg": "dist/iife/index.js",
|
|
11
|
-
"jsdelivr": "dist/iife/index.js",
|
|
8
|
+
"module": "./dist/esm/index.js",
|
|
9
|
+
"main": "./dist/cjs/index.js",
|
|
10
|
+
"unpkg": "./dist/iife/index.js",
|
|
11
|
+
"jsdelivr": "./dist/iife/index.js",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"import": "./dist/esm/index.js",
|
|
15
15
|
"require": "./dist/cjs/index.js",
|
|
16
|
+
"browser": "./dist/iife/index.js",
|
|
16
17
|
"default": "./dist/esm/index.js"
|
|
17
18
|
}
|
|
18
19
|
},
|
|
20
|
+
"bin": {
|
|
21
|
+
"smbls": "./bin/smbls.js"
|
|
22
|
+
},
|
|
19
23
|
"source": "index.js",
|
|
20
24
|
"files": [
|
|
25
|
+
"bin",
|
|
26
|
+
"dist",
|
|
21
27
|
"*.js",
|
|
22
|
-
"
|
|
28
|
+
"src"
|
|
23
29
|
],
|
|
24
30
|
"dependencies": {
|
|
31
|
+
"@symbo.ls/emotion": "^3.2.3",
|
|
32
|
+
"@domql/report": "^3.2.3",
|
|
33
|
+
"@domql/router": "^3.2.3",
|
|
34
|
+
"@domql/utils": "^3.2.3",
|
|
25
35
|
"@symbo.ls/cli": "^3.2.3",
|
|
26
|
-
"@symbo.ls/create": "^3.2.3",
|
|
27
36
|
"@symbo.ls/default-config": "^3.2.3",
|
|
28
|
-
"@symbo.ls/
|
|
37
|
+
"@symbo.ls/fetch": "^3.2.3",
|
|
29
38
|
"@symbo.ls/scratch": "^3.2.3",
|
|
30
39
|
"@symbo.ls/sync": "^3.2.3",
|
|
31
40
|
"@symbo.ls/uikit": "^3.2.3",
|
|
32
|
-
"@symbo.ls/utils": "^3.2.3",
|
|
41
|
+
"@symbo.ls/smbls-utils": "^3.2.3",
|
|
33
42
|
"attrs-in-props": "^3.2.3",
|
|
34
43
|
"css-in-props": "^3.2.3",
|
|
35
44
|
"domql": "^3.2.3"
|
|
@@ -37,10 +46,12 @@
|
|
|
37
46
|
"publishConfig": {},
|
|
38
47
|
"scripts": {
|
|
39
48
|
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
40
|
-
"build:esm": "
|
|
41
|
-
"build:cjs": "
|
|
42
|
-
"build
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
}
|
|
49
|
+
"build:esm": "cross-env NODE_ENV=$NODE_ENV esbuild *.js src/*.js --target=es2020 --format=esm --outdir=dist/esm --define:process.env.NODE_ENV=process.env.NODE_ENV",
|
|
50
|
+
"build:cjs": "cross-env NODE_ENV=$NODE_ENV esbuild *.js src/*.js --target=node18 --format=cjs --outdir=dist/cjs --define:process.env.NODE_ENV=process.env.NODE_ENV",
|
|
51
|
+
"build": "node ../../build/build.js",
|
|
52
|
+
"prepublish": "npm run build && npm run copy:package:cjs",
|
|
53
|
+
"build:iife": "cross-env NODE_ENV=$NODE_ENV esbuild index.js --bundle --target=es2020 --format=iife --global-name=Smbls --outfile=dist/iife/index.js --define:process.env.NODE_ENV=process.env.NODE_ENV --external:css-in-props --external:@symbo.ls/* --external:@domql/* --external:domql --external:attrs-in-props --external:*.json"
|
|
54
|
+
},
|
|
55
|
+
"browser": "./dist/iife/index.js",
|
|
56
|
+
"sideEffects": false
|
|
46
57
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import DOM from 'domql'
|
|
4
|
+
import * as uikit from '@symbo.ls/uikit'
|
|
5
|
+
import { CSS_PROPS_REGISTRY } from 'css-in-props'
|
|
6
|
+
|
|
7
|
+
import { isString, isNode, isObject } from '@domql/utils'
|
|
8
|
+
import { initAnimationFrame } from '@domql/element'
|
|
9
|
+
import { defaultDefine } from './define.js'
|
|
10
|
+
import { initRouter } from './router.js'
|
|
11
|
+
import {
|
|
12
|
+
initializeExtend,
|
|
13
|
+
initializeNotifications,
|
|
14
|
+
initializeSync
|
|
15
|
+
} from './syncExtend.js'
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
prepareComponents,
|
|
19
|
+
prepareDependencies,
|
|
20
|
+
prepareDesignSystem,
|
|
21
|
+
prepareWindow,
|
|
22
|
+
prepareRequire,
|
|
23
|
+
preparePages,
|
|
24
|
+
prepareState,
|
|
25
|
+
prepareUtils,
|
|
26
|
+
prepareMethods,
|
|
27
|
+
prepareSharedLibs,
|
|
28
|
+
PACKAGE_MANAGER_TO_CDN
|
|
29
|
+
} from './prepare.js'
|
|
30
|
+
|
|
31
|
+
export const prepareContext = async (app, context = {}) => {
|
|
32
|
+
const key = (context.key = context.key || (isString(app) ? app : 'smblsapp'))
|
|
33
|
+
context.define = context.define || defaultDefine
|
|
34
|
+
context.cssPropsRegistry = CSS_PROPS_REGISTRY
|
|
35
|
+
context.window = prepareWindow(context)
|
|
36
|
+
|
|
37
|
+
if (context.sharedLibraries && context.sharedLibraries.length) {
|
|
38
|
+
prepareSharedLibs(context)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const [scratcDesignSystem, emotion, registry] = prepareDesignSystem(
|
|
42
|
+
key,
|
|
43
|
+
context
|
|
44
|
+
)
|
|
45
|
+
context.designSystem = scratcDesignSystem
|
|
46
|
+
context.registry = registry
|
|
47
|
+
context.emotion = emotion
|
|
48
|
+
const state = prepareState(app, context)
|
|
49
|
+
context.state = state
|
|
50
|
+
context.pages = preparePages(app, context)
|
|
51
|
+
context.components = prepareComponents(context)
|
|
52
|
+
context.utils = prepareUtils(context)
|
|
53
|
+
if (PACKAGE_MANAGER_TO_CDN[context.packageManager]) {
|
|
54
|
+
context.dependencies = await prepareDependencies(context)
|
|
55
|
+
}
|
|
56
|
+
context.methods = prepareMethods(context)
|
|
57
|
+
context.routerOptions = initRouter(app, context)
|
|
58
|
+
context.defaultExtends = [uikit.Box]
|
|
59
|
+
context.snippets = context.snippets || {}
|
|
60
|
+
context.functions = context.functions || {}
|
|
61
|
+
return context
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const createDomqlElement = async (app, ctx) => {
|
|
65
|
+
if (!isObject(ctx)) ctx = {}
|
|
66
|
+
if (isNode(app)) {
|
|
67
|
+
app = {}
|
|
68
|
+
ctx.parent = app
|
|
69
|
+
} else if (isString(app)) {
|
|
70
|
+
app = {}
|
|
71
|
+
ctx.key = app
|
|
72
|
+
} else if (!isObject(app)) {
|
|
73
|
+
app = {}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
await prepareContext(app, ctx)
|
|
77
|
+
|
|
78
|
+
app.extends = initializeExtend(app, ctx)
|
|
79
|
+
app.routes = ctx.pages
|
|
80
|
+
app.state = ctx.state
|
|
81
|
+
app.context = ctx
|
|
82
|
+
app.data = app.data || {}
|
|
83
|
+
app.data.frameListeners = initAnimationFrame(ctx)
|
|
84
|
+
|
|
85
|
+
await prepareRequire(
|
|
86
|
+
{
|
|
87
|
+
functions: ctx.functions,
|
|
88
|
+
utils: ctx.utils,
|
|
89
|
+
snippets: ctx.snippets,
|
|
90
|
+
...ctx.files
|
|
91
|
+
},
|
|
92
|
+
ctx
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
initializeSync(app, ctx)
|
|
96
|
+
// initializeInspect(app, ctx)
|
|
97
|
+
initializeNotifications(app, ctx)
|
|
98
|
+
|
|
99
|
+
const parentNode = ctx.parent || ctx.document.body
|
|
100
|
+
const domqlCreate = (DOM.default && DOM.default.create) || DOM.create
|
|
101
|
+
const smblsApp = await domqlCreate(app, parentNode, ctx.key, {
|
|
102
|
+
verbose: ctx.verbose,
|
|
103
|
+
...ctx.domqlOptions
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
return smblsApp
|
|
107
|
+
}
|
package/src/define.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
export const defaultDefine = {
|
|
4
|
+
routes: param => param,
|
|
5
|
+
// deps: (param, el) => param || el.parent.deps,
|
|
6
|
+
|
|
7
|
+
$router: async (param, el) => {
|
|
8
|
+
if (!param) return
|
|
9
|
+
|
|
10
|
+
const obj = { tag: 'fragment', ...param }
|
|
11
|
+
|
|
12
|
+
const set = async () => {
|
|
13
|
+
await el.set(obj, { preventDefineUpdate: '$router' })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (el.props && el.props.lazyLoad) {
|
|
17
|
+
window.requestAnimationFrame(set)
|
|
18
|
+
} else await set()
|
|
19
|
+
|
|
20
|
+
return obj
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { isObject } from '@domql/utils'
|
|
4
|
+
import { fetchProject, fetchProjectAsync } from '@symbo.ls/fetch'
|
|
5
|
+
|
|
6
|
+
export const fetchSync = async (key, options) => {
|
|
7
|
+
if (key && options.editor) {
|
|
8
|
+
try {
|
|
9
|
+
if (!options.editor.async) await fetchProject(key, options)
|
|
10
|
+
} catch (e) {
|
|
11
|
+
console.error(e)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const fetchAsync = (app, key, options, callback) => {
|
|
17
|
+
if (key && options.editor) {
|
|
18
|
+
try {
|
|
19
|
+
if (options.editor.async) {
|
|
20
|
+
fetchProjectAsync(key, options, callback || ((data) => {
|
|
21
|
+
const designSystem = data.designSystem
|
|
22
|
+
if (isObject(designSystem)) {
|
|
23
|
+
options.utils.init(designSystem)
|
|
24
|
+
}
|
|
25
|
+
if (isObject(data.state)) {
|
|
26
|
+
app.state.set(data.state)
|
|
27
|
+
}
|
|
28
|
+
}))
|
|
29
|
+
}
|
|
30
|
+
} catch (e) {
|
|
31
|
+
console.error(e)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { deepMerge, isObject, isUndefined } from '@domql/utils'
|
|
4
|
+
|
|
5
|
+
import * as utils from './utilImports.js'
|
|
6
|
+
|
|
7
|
+
import { onpopstateRouter } from './router.js'
|
|
8
|
+
import { fetchAsync, fetchSync } from './fetchOnCreate.js'
|
|
9
|
+
|
|
10
|
+
import DEFAULT_CREATE_OPTIONS from './options.js'
|
|
11
|
+
import DYNAMIC_JSON from '../dynamic.json' with { type: 'json' }
|
|
12
|
+
import { createDomqlElement } from './createDomql.js'
|
|
13
|
+
|
|
14
|
+
const mergeWithLocalFile = (options, optionsExternalFile) =>
|
|
15
|
+
deepMerge(
|
|
16
|
+
options,
|
|
17
|
+
isObject(optionsExternalFile) ? optionsExternalFile : DYNAMIC_JSON || {}
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
export const create = (
|
|
21
|
+
App,
|
|
22
|
+
options = DEFAULT_CREATE_OPTIONS,
|
|
23
|
+
optionsExternalFile
|
|
24
|
+
) => {
|
|
25
|
+
const redefinedOptions = {
|
|
26
|
+
...DEFAULT_CREATE_OPTIONS,
|
|
27
|
+
...mergeWithLocalFile(options, optionsExternalFile)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const domqlApp = createDomqlElement(App, redefinedOptions).then((App) => {
|
|
31
|
+
onpopstateRouter(App, redefinedOptions)
|
|
32
|
+
|
|
33
|
+
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
34
|
+
redefinedOptions.on.create(
|
|
35
|
+
domqlApp,
|
|
36
|
+
domqlApp.state,
|
|
37
|
+
domqlApp.context,
|
|
38
|
+
redefinedOptions
|
|
39
|
+
)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
return domqlApp
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const createAsync = (
|
|
46
|
+
App,
|
|
47
|
+
options = DEFAULT_CREATE_OPTIONS,
|
|
48
|
+
optionsExternalFile
|
|
49
|
+
) => {
|
|
50
|
+
const domqlApp = create(App, options, optionsExternalFile)
|
|
51
|
+
|
|
52
|
+
const redefinedOptions = {
|
|
53
|
+
...DEFAULT_CREATE_OPTIONS,
|
|
54
|
+
...mergeWithLocalFile(options, optionsExternalFile)
|
|
55
|
+
}
|
|
56
|
+
const key = redefinedOptions.key
|
|
57
|
+
fetchAsync(domqlApp, key, { utils, ...redefinedOptions })
|
|
58
|
+
|
|
59
|
+
return domqlApp
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const createSync = async (
|
|
63
|
+
App,
|
|
64
|
+
options = DEFAULT_CREATE_OPTIONS,
|
|
65
|
+
optionsExternalFile
|
|
66
|
+
) => {
|
|
67
|
+
const redefinedOptions = {
|
|
68
|
+
...DEFAULT_CREATE_OPTIONS,
|
|
69
|
+
...mergeWithLocalFile(options, optionsExternalFile)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// const SYMBOLS_KEY = process.env.SYMBOLS_KEY
|
|
73
|
+
const key = options.key
|
|
74
|
+
await fetchSync(key, redefinedOptions)
|
|
75
|
+
|
|
76
|
+
const domqlApp = await createDomqlElement(App, redefinedOptions)
|
|
77
|
+
if (redefinedOptions.on && redefinedOptions.on.create)
|
|
78
|
+
await redefinedOptions.on.create(
|
|
79
|
+
domqlApp,
|
|
80
|
+
domqlApp.state,
|
|
81
|
+
domqlApp.context,
|
|
82
|
+
redefinedOptions
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
return domqlApp
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export const createSkeleton = (
|
|
89
|
+
App = {},
|
|
90
|
+
options = DEFAULT_CREATE_OPTIONS,
|
|
91
|
+
optionsExternalFile
|
|
92
|
+
) => {
|
|
93
|
+
return create(
|
|
94
|
+
{
|
|
95
|
+
deps: { isUndefined },
|
|
96
|
+
...App
|
|
97
|
+
},
|
|
98
|
+
deepMerge({ domqlOptions: { onlyResolveExtends: true } }, options),
|
|
99
|
+
optionsExternalFile
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default create
|
|
104
|
+
|
|
105
|
+
export * from './init.js'
|
|
106
|
+
export { DEFAULT_CONTEXT, DESIGN_SYSTEM_OPTIONS, ROUTER_OPTIONS } from './options.js'
|
package/src/init.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
set,
|
|
5
|
+
getActiveConfig,
|
|
6
|
+
getFontFaceString,
|
|
7
|
+
appendSVGSprite,
|
|
8
|
+
appendSvgIconsSprite
|
|
9
|
+
} from '@symbo.ls/scratch'
|
|
10
|
+
|
|
11
|
+
import { isObject, deepMerge, deepClone } from '@domql/utils'
|
|
12
|
+
|
|
13
|
+
import { emotion as defaultEmotion } from '@symbo.ls/emotion'
|
|
14
|
+
|
|
15
|
+
import DYNAMIC_JSON from '../dynamic.json' with { type: 'json' }
|
|
16
|
+
|
|
17
|
+
const CONFIG = getActiveConfig()
|
|
18
|
+
|
|
19
|
+
const mergeWithLocalFile = (config = CONFIG, options) => {
|
|
20
|
+
const rcfile = isObject(options.localFile)
|
|
21
|
+
? options.localFile
|
|
22
|
+
: DYNAMIC_JSON || {}
|
|
23
|
+
const clonedFile = deepClone(rcfile.designSystem || {})
|
|
24
|
+
return deepMerge(config, clonedFile)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const SET_OPTIONS = {
|
|
28
|
+
emotion: defaultEmotion,
|
|
29
|
+
useVariable: true,
|
|
30
|
+
useReset: true,
|
|
31
|
+
useFontImport: true,
|
|
32
|
+
useIconSprite: true,
|
|
33
|
+
useDocumentTheme: true,
|
|
34
|
+
useSvgSprite: true
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const init = (config, options = SET_OPTIONS) => {
|
|
38
|
+
const emotion = options.emotion || defaultEmotion
|
|
39
|
+
const resultConfig = mergeWithLocalFile(config || {}, options)
|
|
40
|
+
|
|
41
|
+
const conf = set(
|
|
42
|
+
{
|
|
43
|
+
verbose: options.verbose,
|
|
44
|
+
useReset: options.useReset,
|
|
45
|
+
useFontImport: options.useFontImport,
|
|
46
|
+
useVariable: options.useVariable,
|
|
47
|
+
useSvgSprite: options.useSvgSprite,
|
|
48
|
+
useDocumentTheme: options.useDocumentTheme,
|
|
49
|
+
useIconSprite: options.useIconSprite,
|
|
50
|
+
useDefaultConfig: options.useDefaultConfig,
|
|
51
|
+
globalTheme: options.globalTheme,
|
|
52
|
+
...resultConfig
|
|
53
|
+
},
|
|
54
|
+
{ newConfig: options.newConfig }
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
const FontFace = getFontFaceString(conf.FONT)
|
|
58
|
+
|
|
59
|
+
const useReset = conf.useReset
|
|
60
|
+
const useVariable = conf.useVariable
|
|
61
|
+
const useFontImport = conf.useFontImport
|
|
62
|
+
const useSvgSprite = conf.useSvgSprite
|
|
63
|
+
const hasSvgs = config.svg || config.SVG
|
|
64
|
+
const useIconSprite = conf.useIconSprite
|
|
65
|
+
const hasIcons = config.icons || config.ICONS
|
|
66
|
+
|
|
67
|
+
if (useFontImport) emotion.injectGlobal(FontFace)
|
|
68
|
+
if (useVariable) emotion.injectGlobal({ ':root': conf.CSS_VARS })
|
|
69
|
+
if (useReset) emotion.injectGlobal(conf.RESET)
|
|
70
|
+
|
|
71
|
+
// Register all ANIMATION entries as global @keyframes
|
|
72
|
+
if (conf.ANIMATION) {
|
|
73
|
+
const keyframesCSS = {}
|
|
74
|
+
for (const name in conf.ANIMATION) {
|
|
75
|
+
keyframesCSS[`@keyframes ${name}`] = conf.ANIMATION[name]
|
|
76
|
+
}
|
|
77
|
+
emotion.injectGlobal(keyframesCSS)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (hasSvgs) appendSVGSprite(hasSvgs, { document: options.document })
|
|
81
|
+
else if (useSvgSprite)
|
|
82
|
+
appendSVGSprite(conf.SVG, { document: options.document })
|
|
83
|
+
|
|
84
|
+
if (hasIcons) appendSvgIconsSprite(hasIcons, { document: options.document })
|
|
85
|
+
else if (useIconSprite)
|
|
86
|
+
appendSvgIconsSprite(conf.ICONS, { document: options.document })
|
|
87
|
+
|
|
88
|
+
return conf
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const UPDATE_OPTIONS = {
|
|
92
|
+
emotion: defaultEmotion
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const reinit = (config, options = UPDATE_OPTIONS) => {
|
|
96
|
+
const emotion = options.emotion || defaultEmotion
|
|
97
|
+
const resultConfig = mergeWithLocalFile(config || {}, options)
|
|
98
|
+
const conf = set({
|
|
99
|
+
verbose: false,
|
|
100
|
+
...resultConfig
|
|
101
|
+
})
|
|
102
|
+
if (!options.preventInject) {
|
|
103
|
+
emotion.injectGlobal({ ':root': conf.CSS_VARS })
|
|
104
|
+
emotion.injectGlobal(conf.RESET)
|
|
105
|
+
}
|
|
106
|
+
return conf
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const applyCSS = (styles, options = UPDATE_OPTIONS) => {
|
|
110
|
+
const emotion = options.emotion || defaultEmotion
|
|
111
|
+
emotion.injectGlobal(styles)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const updateVars = (config, options = UPDATE_OPTIONS) => {
|
|
115
|
+
const emotion = options.emotion || defaultEmotion
|
|
116
|
+
emotion.injectGlobal({ ':root': config.CSS_VARS })
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export const setClass = (props, options = UPDATE_OPTIONS) => {} // setClassname(props, options.emotion.css)
|
|
120
|
+
|
|
121
|
+
export { DYNAMIC_JSON }
|
package/src/options.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { defaultDefine } from './define.js'
|
|
4
|
+
import { version } from '../package.json' with { type: 'json' }
|
|
5
|
+
|
|
6
|
+
export const DESIGN_SYSTEM_OPTIONS = {
|
|
7
|
+
useReset: true,
|
|
8
|
+
useVariable: true,
|
|
9
|
+
useIconSprite: true,
|
|
10
|
+
useSvgSprite: true,
|
|
11
|
+
useDocumentTheme: true,
|
|
12
|
+
useDefaultIcons: true,
|
|
13
|
+
useFontImport: true,
|
|
14
|
+
useDefaultConfig: true
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const ROUTER_OPTIONS = {
|
|
18
|
+
initRouter: true,
|
|
19
|
+
popState: true,
|
|
20
|
+
injectRouterInLinkComponent: true
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const DEFAULT_CONTEXT = {
|
|
24
|
+
...DESIGN_SYSTEM_OPTIONS,
|
|
25
|
+
router: ROUTER_OPTIONS,
|
|
26
|
+
version
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const CREATE_OPTIONS = {
|
|
30
|
+
state: {},
|
|
31
|
+
pages: {},
|
|
32
|
+
components: {},
|
|
33
|
+
router: ROUTER_OPTIONS,
|
|
34
|
+
define: defaultDefine
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default CREATE_OPTIONS
|