@viewfly/scoped-css 0.0.16 → 0.0.18
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/bundles/css-modules.d.ts +1 -9
- package/bundles/index.esm.js +12 -57
- package/bundles/index.js +11 -57
- package/package.json +3 -3
package/bundles/css-modules.d.ts
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
1
|
import { JSXInternal } from '@viewfly/core';
|
|
2
|
-
declare
|
|
3
|
-
namespace JSXInternal {
|
|
4
|
-
interface Attributes {
|
|
5
|
-
css?: JSXInternal.ClassNames;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export declare function getClassNames(config: JSXInternal.ClassNames, cssRecord: Record<string, string>): string;
|
|
10
|
-
export declare function withScopedCSS(css: Record<string, string>, render: () => JSXInternal.Element): () => JSXInternal.JSXChildNode;
|
|
2
|
+
export declare function withScopedCSS(cssNamespace: string | string[], render: () => JSXInternal.Element): () => JSXInternal.JSXChildNode;
|
package/bundles/index.esm.js
CHANGED
|
@@ -1,74 +1,29 @@
|
|
|
1
1
|
import { JSXElement, JSXComponent } from '@viewfly/core';
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
const classes = [];
|
|
5
|
-
if (!config) {
|
|
6
|
-
return classes;
|
|
7
|
-
}
|
|
8
|
-
if (typeof config === 'string') {
|
|
9
|
-
const items = config.match(/\S+/g);
|
|
10
|
-
return items || classes;
|
|
11
|
-
}
|
|
12
|
-
else if (Array.isArray(config)) {
|
|
13
|
-
for (const i of config) {
|
|
14
|
-
classes.push(...cssNamesToArray(i));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
else if (typeof config === 'object') {
|
|
18
|
-
if (config.toString !== Object.prototype.toString && !config.toString.toString().includes('[native code]')) {
|
|
19
|
-
classes.push(config.toString());
|
|
20
|
-
return classes;
|
|
21
|
-
}
|
|
22
|
-
for (const key in config) {
|
|
23
|
-
if ({}.hasOwnProperty.call(config, key) && config[key]) {
|
|
24
|
-
classes.push(key);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return classes;
|
|
29
|
-
}
|
|
30
|
-
function replaceCSSClass(template, cssMap) {
|
|
3
|
+
function addOnScopedKeys(template, cssNamespace) {
|
|
31
4
|
if (template instanceof JSXElement || template instanceof JSXComponent) {
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (className) {
|
|
38
|
-
className += ' ' + c;
|
|
5
|
+
const children = template.props.children;
|
|
6
|
+
const nameSpaces = Array.isArray(cssNamespace) ? cssNamespace : [cssNamespace];
|
|
7
|
+
nameSpaces.forEach(i => {
|
|
8
|
+
if (typeof i === 'string' && i) {
|
|
9
|
+
template.props[i] = '';
|
|
39
10
|
}
|
|
40
|
-
|
|
41
|
-
className = c;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (className) {
|
|
45
|
-
template.props.class = className;
|
|
46
|
-
}
|
|
11
|
+
});
|
|
47
12
|
if (Array.isArray(children)) {
|
|
48
13
|
children.forEach(child => {
|
|
49
|
-
|
|
14
|
+
addOnScopedKeys(child, cssNamespace);
|
|
50
15
|
});
|
|
51
16
|
}
|
|
52
17
|
else {
|
|
53
|
-
|
|
18
|
+
addOnScopedKeys(children, cssNamespace);
|
|
54
19
|
}
|
|
55
20
|
}
|
|
56
21
|
return template;
|
|
57
22
|
}
|
|
58
|
-
function
|
|
59
|
-
const scopedClasses = [];
|
|
60
|
-
cssNamesToArray(config).forEach(i => {
|
|
61
|
-
const klass = cssRecord[i];
|
|
62
|
-
if (klass) {
|
|
63
|
-
scopedClasses.push(klass);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return scopedClasses.join(' ');
|
|
67
|
-
}
|
|
68
|
-
function withScopedCSS(css, render) {
|
|
23
|
+
function withScopedCSS(cssNamespace, render) {
|
|
69
24
|
return function scopedCSS() {
|
|
70
|
-
return
|
|
25
|
+
return addOnScopedKeys(render(), cssNamespace);
|
|
71
26
|
};
|
|
72
27
|
}
|
|
73
28
|
|
|
74
|
-
export {
|
|
29
|
+
export { withScopedCSS };
|
package/bundles/index.js
CHANGED
|
@@ -2,76 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@viewfly/core');
|
|
4
4
|
|
|
5
|
-
function
|
|
6
|
-
const classes = [];
|
|
7
|
-
if (!config) {
|
|
8
|
-
return classes;
|
|
9
|
-
}
|
|
10
|
-
if (typeof config === 'string') {
|
|
11
|
-
const items = config.match(/\S+/g);
|
|
12
|
-
return items || classes;
|
|
13
|
-
}
|
|
14
|
-
else if (Array.isArray(config)) {
|
|
15
|
-
for (const i of config) {
|
|
16
|
-
classes.push(...cssNamesToArray(i));
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
else if (typeof config === 'object') {
|
|
20
|
-
if (config.toString !== Object.prototype.toString && !config.toString.toString().includes('[native code]')) {
|
|
21
|
-
classes.push(config.toString());
|
|
22
|
-
return classes;
|
|
23
|
-
}
|
|
24
|
-
for (const key in config) {
|
|
25
|
-
if ({}.hasOwnProperty.call(config, key) && config[key]) {
|
|
26
|
-
classes.push(key);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return classes;
|
|
31
|
-
}
|
|
32
|
-
function replaceCSSClass(template, cssMap) {
|
|
5
|
+
function addOnScopedKeys(template, cssNamespace) {
|
|
33
6
|
if (template instanceof core.JSXElement || template instanceof core.JSXComponent) {
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (className) {
|
|
40
|
-
className += ' ' + c;
|
|
7
|
+
const children = template.props.children;
|
|
8
|
+
const nameSpaces = Array.isArray(cssNamespace) ? cssNamespace : [cssNamespace];
|
|
9
|
+
nameSpaces.forEach(i => {
|
|
10
|
+
if (typeof i === 'string' && i) {
|
|
11
|
+
template.props[i] = '';
|
|
41
12
|
}
|
|
42
|
-
|
|
43
|
-
className = c;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (className) {
|
|
47
|
-
template.props.class = className;
|
|
48
|
-
}
|
|
13
|
+
});
|
|
49
14
|
if (Array.isArray(children)) {
|
|
50
15
|
children.forEach(child => {
|
|
51
|
-
|
|
16
|
+
addOnScopedKeys(child, cssNamespace);
|
|
52
17
|
});
|
|
53
18
|
}
|
|
54
19
|
else {
|
|
55
|
-
|
|
20
|
+
addOnScopedKeys(children, cssNamespace);
|
|
56
21
|
}
|
|
57
22
|
}
|
|
58
23
|
return template;
|
|
59
24
|
}
|
|
60
|
-
function
|
|
61
|
-
const scopedClasses = [];
|
|
62
|
-
cssNamesToArray(config).forEach(i => {
|
|
63
|
-
const klass = cssRecord[i];
|
|
64
|
-
if (klass) {
|
|
65
|
-
scopedClasses.push(klass);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
return scopedClasses.join(' ');
|
|
69
|
-
}
|
|
70
|
-
function withScopedCSS(css, render) {
|
|
25
|
+
function withScopedCSS(cssNamespace, render) {
|
|
71
26
|
return function scopedCSS() {
|
|
72
|
-
return
|
|
27
|
+
return addOnScopedKeys(render(), cssNamespace);
|
|
73
28
|
};
|
|
74
29
|
}
|
|
75
30
|
|
|
76
|
-
exports.getClassNames = getClassNames;
|
|
77
31
|
exports.withScopedCSS = withScopedCSS;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/scoped-css",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
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",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"keywords": [],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@viewfly/core": "^0.0.
|
|
15
|
+
"@viewfly/core": "^0.0.18"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@rollup/plugin-commonjs": "^25.0.3",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"bugs": {
|
|
33
33
|
"url": "https://github.com/viewfly/viewfly.git/issues"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "1cc6ec2decf3173792086553af0b3e171d49deae"
|
|
36
36
|
}
|