@storybook/components 7.0.19 → 7.0.21
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 +6 -6
- package/scripts/writeCssScript.js +135 -0
- package/src/typings.d.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/components",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.21",
|
|
4
4
|
"description": "Core Storybook Components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook"
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"prep": "../../../scripts/prepare/bundle.ts"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@storybook/client-logger": "7.0.
|
|
51
|
+
"@storybook/client-logger": "7.0.21",
|
|
52
52
|
"@storybook/csf": "^0.1.0",
|
|
53
53
|
"@storybook/global": "^5.0.0",
|
|
54
|
-
"@storybook/theming": "7.0.
|
|
55
|
-
"@storybook/types": "7.0.
|
|
54
|
+
"@storybook/theming": "7.0.21",
|
|
55
|
+
"@storybook/types": "7.0.21",
|
|
56
56
|
"memoizerific": "^1.11.3",
|
|
57
57
|
"use-resize-observer": "^9.1.0",
|
|
58
58
|
"util-deprecate": "^1.0.2"
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
],
|
|
86
86
|
"platform": "neutral"
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
89
|
-
}
|
|
88
|
+
"gitHead": "9fb2573aa274f3f69d3358050e8df9c903e8245f"
|
|
89
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
/* eslint-disable no-param-reassign */
|
|
3
|
+
|
|
4
|
+
// This little script converts the overflowscrollbars CSS file into the css-in-js file
|
|
5
|
+
// it's normal you have to run prettier over the file after
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const { parse } = require('css');
|
|
9
|
+
const { isNaN } = require('@storybook/global');
|
|
10
|
+
|
|
11
|
+
const INPUT = require.resolve('overlayscrollbars/css/OverlayScrollbars.min.css');
|
|
12
|
+
const OUTPUT = `${__dirname}/../src/ScrollArea/ScrollAreaStyles.ts`;
|
|
13
|
+
const OPTIONS = { camelCase: true, numbers: true };
|
|
14
|
+
|
|
15
|
+
const read = (file) => {
|
|
16
|
+
return fs
|
|
17
|
+
.readFileSync(file)
|
|
18
|
+
.toString()
|
|
19
|
+
.replace(/(?:\r\n|\r|\n)/g, '');
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const convert = (css, opts) => {
|
|
23
|
+
const ast = parse(css, { source: css });
|
|
24
|
+
const obj = cssToObject(opts)(ast.stylesheet.rules);
|
|
25
|
+
return obj;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const cssToObject =
|
|
29
|
+
(opts) =>
|
|
30
|
+
(rules, result = {}) => {
|
|
31
|
+
rules.forEach((rule) => {
|
|
32
|
+
if (rule.type === 'media') {
|
|
33
|
+
const key = `@media ${rule.media}`;
|
|
34
|
+
const decs = cssToObject(opts)(rule.rules);
|
|
35
|
+
result[key] = decs;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (rule.type === 'keyframes') {
|
|
39
|
+
result.__keyframes = Object.assign(result.__keyframes || {}, { [camel(rule.name)]: rule });
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (rule.type === 'comment') {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const key = rule.selectors.filter((s) => !s.includes('.os-theme-none')).join(', ');
|
|
47
|
+
|
|
48
|
+
if (key.length) {
|
|
49
|
+
Object.assign(result, {
|
|
50
|
+
[key]: Object.assign(result[key] || {}, getDeclarations(rule.declarations, opts)),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return result;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const getDeclarations = (decs, opts = {}) => {
|
|
58
|
+
const result = decs
|
|
59
|
+
.filter((d) => {
|
|
60
|
+
const filtered = d.type === 'comment' || d.property.match(/^(?:-webkit-|-ms-|-moz-)/);
|
|
61
|
+
return !filtered;
|
|
62
|
+
})
|
|
63
|
+
.map((d) => ({
|
|
64
|
+
key: opts.camelCase ? camel(d.property) : d.property,
|
|
65
|
+
value: opts.numbers ? parsePx(d.value) : d.value,
|
|
66
|
+
}))
|
|
67
|
+
.reduce((a, b) => {
|
|
68
|
+
a[b.key] = b.value;
|
|
69
|
+
return a;
|
|
70
|
+
}, {});
|
|
71
|
+
return result;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const camel = (str) => str.replace(/(-[a-z])/g, (x) => x.toUpperCase()).replace(/-/g, '');
|
|
75
|
+
|
|
76
|
+
const parsePx = (val) => {
|
|
77
|
+
return /px$/.test(val) || val === '' || (val.match(/\d$/) && !isNaN(parseInt(val, 10)))
|
|
78
|
+
? parseFloat(val.replace(/px$/, ''))
|
|
79
|
+
: val;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
83
|
+
const { __keyframes, ...styles } = convert(read(INPUT), OPTIONS);
|
|
84
|
+
|
|
85
|
+
const stringifiedKeyFrames = Object.values(__keyframes)
|
|
86
|
+
.map((k) => {
|
|
87
|
+
return `const ${camel(k.name)} = keyframes\`${k.keyframes.reduce(
|
|
88
|
+
(acc, item) =>
|
|
89
|
+
`${acc}${k.position.source.substring(
|
|
90
|
+
item.position.start.column - 1,
|
|
91
|
+
item.position.end.column - 1
|
|
92
|
+
)}`,
|
|
93
|
+
''
|
|
94
|
+
)}\`;`;
|
|
95
|
+
})
|
|
96
|
+
.join('\n');
|
|
97
|
+
|
|
98
|
+
const stringifiedStyles = JSON.stringify(
|
|
99
|
+
Object.entries(styles).reduce((acc, [key, item]) => {
|
|
100
|
+
if (item.animationName && __keyframes[camel(item.animationName)]) {
|
|
101
|
+
item.animationName = camel(item.animationName);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (item.backgroundImage && item.backgroundImage.match(/^url/)) {
|
|
105
|
+
item.backgroundImage =
|
|
106
|
+
'linear-gradient(135deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0) 50%, rgba(0,0,0,0.4) 50%, rgba(0,0,0,0.4) 100%)';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
acc[key] = item;
|
|
110
|
+
return acc;
|
|
111
|
+
}, {}),
|
|
112
|
+
null,
|
|
113
|
+
2
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const stringifiedStylesWithReplacedKeyframes = Object.keys(__keyframes)
|
|
117
|
+
.reduce((acc, item) => {
|
|
118
|
+
// replace keyframes
|
|
119
|
+
return acc.replace(`"${item}"`, `\`\${${item}}\``);
|
|
120
|
+
}, stringifiedStyles)
|
|
121
|
+
.replace(/"([^\s]+)!important"/g, (f, p1) => {
|
|
122
|
+
// make "!important" rules work with TS
|
|
123
|
+
const v = parsePx(p1);
|
|
124
|
+
return `"${p1}!important" as any as ${JSON.stringify(v)}`;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const result = `
|
|
128
|
+
import { Theme, CSSObject, keyframes } from '@storybook/theming';
|
|
129
|
+
|
|
130
|
+
${stringifiedKeyFrames}
|
|
131
|
+
|
|
132
|
+
export const getScrollAreaStyles: (theme: Theme) => CSSObject = (theme: Theme) => (${stringifiedStylesWithReplacedKeyframes});
|
|
133
|
+
`;
|
|
134
|
+
|
|
135
|
+
fs.writeFileSync(OUTPUT, result);
|
package/src/typings.d.ts
ADDED