@viewfly/scoped-css 0.0.1-alpha.12 → 0.0.1-alpha.13
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/README.md +1 -1
- package/package.json +4 -8
- package/rollup.config.ts +0 -24
- package/src/css-modules.ts +0 -71
- package/src/public-api.ts +0 -1
- package/tsconfig.json +0 -37
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/scoped-css",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.1-alpha.13",
|
|
4
|
+
"description": "A library for supporting scoped style sheets in the Viewfly framework。",
|
|
5
5
|
"main": "./bundles/index.js",
|
|
6
6
|
"module": "./bundles/index.esm.js",
|
|
7
7
|
"typings": "./bundles/public-api.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"start": "webpack-dev-server",
|
|
10
|
-
"test": "cross-env env=test jest",
|
|
11
|
-
"test-c": "cross-env env=test jest --coverage",
|
|
12
9
|
"build:lib": "rimraf bundles && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
|
|
13
10
|
"publish:lib": "npm run build:lib && npm publish --access=public"
|
|
14
11
|
},
|
|
15
12
|
"license": "MIT",
|
|
16
13
|
"keywords": [],
|
|
17
14
|
"dependencies": {
|
|
18
|
-
"@viewfly/core": "^0.0.1-alpha.
|
|
15
|
+
"@viewfly/core": "^0.0.1-alpha.13"
|
|
19
16
|
},
|
|
20
17
|
"devDependencies": {
|
|
21
18
|
"@rollup/plugin-commonjs": "^23.0.2",
|
|
@@ -34,6 +31,5 @@
|
|
|
34
31
|
},
|
|
35
32
|
"bugs": {
|
|
36
33
|
"url": "https://github.com/viewfly/viewfly.git/issues"
|
|
37
|
-
}
|
|
38
|
-
"gitHead": "e5fdc69779bbfd6a1128b98a30d8732dbda7fcd3"
|
|
34
|
+
}
|
|
39
35
|
}
|
package/rollup.config.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import commonjs from '@rollup/plugin-commonjs'
|
|
2
|
-
import typescript from '@rollup/plugin-typescript'
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
input: 'src/public-api.ts',
|
|
6
|
-
output: [
|
|
7
|
-
{
|
|
8
|
-
file: './bundles/index.js',
|
|
9
|
-
format: 'cjs'
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
file: './bundles/index.esm.js',
|
|
13
|
-
format: 'esm'
|
|
14
|
-
}
|
|
15
|
-
],
|
|
16
|
-
plugins: [
|
|
17
|
-
commonjs(),
|
|
18
|
-
typescript({
|
|
19
|
-
compilerOptions: {
|
|
20
|
-
paths: {}
|
|
21
|
-
}
|
|
22
|
-
})
|
|
23
|
-
]
|
|
24
|
-
}
|
package/src/css-modules.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { JSXElement, ComponentSetup } from '@viewfly/core'
|
|
2
|
-
|
|
3
|
-
function cssNamesToArray(config: unknown) {
|
|
4
|
-
const classes: string[] = []
|
|
5
|
-
if (!config) {
|
|
6
|
-
return classes
|
|
7
|
-
}
|
|
8
|
-
if (typeof config === 'string') {
|
|
9
|
-
const items = config.match(/\S+/g)
|
|
10
|
-
return items || classes
|
|
11
|
-
} else if (Array.isArray(config)) {
|
|
12
|
-
for (const i of config) {
|
|
13
|
-
classes.push(...cssNamesToArray(i))
|
|
14
|
-
}
|
|
15
|
-
} else if (typeof config === 'object') {
|
|
16
|
-
if (config.toString !== Object.prototype.toString && !config.toString.toString().includes('[native code]')) {
|
|
17
|
-
classes.push(config.toString())
|
|
18
|
-
return classes
|
|
19
|
-
}
|
|
20
|
-
for (const key in config) {
|
|
21
|
-
if ({}.hasOwnProperty.call(config, key) && config[key]) {
|
|
22
|
-
classes.push(key)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return classes
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function replaceCSSClass(template, cssMap: Record<string, string>) {
|
|
30
|
-
if (template instanceof JSXElement) {
|
|
31
|
-
let { class: className, children } = template.props
|
|
32
|
-
const css = template.props.css
|
|
33
|
-
Reflect.deleteProperty(template.props, 'css')
|
|
34
|
-
const scopedClasses: string[] = []
|
|
35
|
-
cssNamesToArray(css).forEach(i => {
|
|
36
|
-
const klass = cssMap[i]
|
|
37
|
-
if (klass) {
|
|
38
|
-
scopedClasses.push(klass)
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
const c = scopedClasses.join(' ')
|
|
42
|
-
if (c) {
|
|
43
|
-
if (className) {
|
|
44
|
-
className += ' ' + c
|
|
45
|
-
} else {
|
|
46
|
-
className = c
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (className) {
|
|
50
|
-
template.props.class = className
|
|
51
|
-
}
|
|
52
|
-
if (Array.isArray(children)) {
|
|
53
|
-
children.forEach(child => {
|
|
54
|
-
replaceCSSClass(child, cssMap)
|
|
55
|
-
})
|
|
56
|
-
} else {
|
|
57
|
-
replaceCSSClass(children, cssMap)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function scopedCSS<T extends ComponentSetup>(css: Record<string, string>, factory: T): T {
|
|
63
|
-
return function (props: any) {
|
|
64
|
-
const componentRender = factory(props)
|
|
65
|
-
return function () {
|
|
66
|
-
const template = componentRender()
|
|
67
|
-
replaceCSSClass(template, css)
|
|
68
|
-
return template
|
|
69
|
-
}
|
|
70
|
-
} as T
|
|
71
|
-
}
|
package/src/public-api.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './css-modules'
|
package/tsconfig.json
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"declaration": true,
|
|
4
|
-
"useDefineForClassFields": false,
|
|
5
|
-
"emitDecoratorMetadata": true,
|
|
6
|
-
"experimentalDecorators": true,
|
|
7
|
-
"allowSyntheticDefaultImports": true,
|
|
8
|
-
"lib": [
|
|
9
|
-
"esnext",
|
|
10
|
-
"dom"
|
|
11
|
-
],
|
|
12
|
-
"target": "es6",
|
|
13
|
-
"strict": true,
|
|
14
|
-
"module": "es2020",
|
|
15
|
-
"moduleResolution": "node",
|
|
16
|
-
"inlineSourceMap": true,
|
|
17
|
-
"inlineSources": true,
|
|
18
|
-
"noImplicitAny": false,
|
|
19
|
-
"ignoreDeprecations": "5.0",
|
|
20
|
-
"suppressImplicitAnyIndexErrors": true,
|
|
21
|
-
"outDir": "bundles/",
|
|
22
|
-
"downlevelIteration": true,
|
|
23
|
-
"paths": {
|
|
24
|
-
"@viewfly/core": [
|
|
25
|
-
"../core/src/public-api.ts"
|
|
26
|
-
]
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
"include": [
|
|
30
|
-
"src"
|
|
31
|
-
],
|
|
32
|
-
"ts-node": {
|
|
33
|
-
"compilerOptions": {
|
|
34
|
-
"module": "CommonJS"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|