@modern-js/plugin-styled-components 0.0.0-canary-20251127032505
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/CHANGELOG.md +10 -0
- package/LICENSE +21 -0
- package/dist/cjs/extender/stream.js +57 -0
- package/dist/cjs/extender/string.js +98 -0
- package/dist/cjs/index.js +71 -0
- package/dist/cjs/runtime.js +44 -0
- package/dist/cjs/styled.js +66 -0
- package/dist/esm/extender/stream.mjs +23 -0
- package/dist/esm/extender/string.mjs +61 -0
- package/dist/esm/index.mjs +34 -0
- package/dist/esm/runtime.mjs +10 -0
- package/dist/esm/styled.mjs +4 -0
- package/dist/esm-node/extender/stream.mjs +23 -0
- package/dist/esm-node/extender/string.mjs +61 -0
- package/dist/esm-node/index.mjs +34 -0
- package/dist/esm-node/runtime.mjs +10 -0
- package/dist/esm-node/styled.mjs +4 -0
- package/dist/types/extender/stream.d.ts +12 -0
- package/dist/types/extender/string.d.ts +24 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/runtime.d.ts +2 -0
- package/dist/types/styled.d.ts +3 -0
- package/package.json +89 -0
- package/rslib.config.ts +4 -0
- package/src/extender/stream.ts +30 -0
- package/src/extender/string.ts +39 -0
- package/src/index.ts +41 -0
- package/src/runtime.ts +16 -0
- package/src/styled.ts +5 -0
- package/tsconfig.json +9 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @modern-js/plugin-styled-components
|
|
2
|
+
|
|
3
|
+
## 0.0.0-canary-20251127032505
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3414a3e: feat: add plugin-styled-components
|
|
8
|
+
feat: 新增 styled-components 插件
|
|
9
|
+
- 9de9720: feat: add styled-components plugin options and fix docs
|
|
10
|
+
feat: styled-components 插件增加配置参数并修复相关文档
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Modern.js
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
StreamStyledExtender: ()=>StreamStyledExtender
|
|
28
|
+
});
|
|
29
|
+
const external_styled_components_namespaceObject = require("styled-components");
|
|
30
|
+
class StreamStyledExtender {
|
|
31
|
+
init(params) {
|
|
32
|
+
this.sheet = new external_styled_components_namespaceObject.ServerStyleSheet();
|
|
33
|
+
this.rootElement = this.sheet.collectStyles(params.rootElement);
|
|
34
|
+
this.forceStream2String = params.forceStream2String;
|
|
35
|
+
}
|
|
36
|
+
modifyRootElement(rootElement) {
|
|
37
|
+
return this.rootElement || rootElement;
|
|
38
|
+
}
|
|
39
|
+
getStyleTags() {
|
|
40
|
+
return this.forceStream2String && this.sheet ? this.sheet.getStyleTags() : '';
|
|
41
|
+
}
|
|
42
|
+
processStream(stream) {
|
|
43
|
+
return this.sheet ? this.sheet.interleaveWithNodeStream(stream) : stream;
|
|
44
|
+
}
|
|
45
|
+
constructor(){
|
|
46
|
+
this.sheet = null;
|
|
47
|
+
this.rootElement = null;
|
|
48
|
+
this.forceStream2String = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.StreamStyledExtender = __webpack_exports__.StreamStyledExtender;
|
|
52
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
53
|
+
"StreamStyledExtender"
|
|
54
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
55
|
+
Object.defineProperty(exports, '__esModule', {
|
|
56
|
+
value: true
|
|
57
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
StyledCollector: ()=>StyledCollector,
|
|
28
|
+
RenderLevel: ()=>string_RenderLevel
|
|
29
|
+
});
|
|
30
|
+
const external_styled_components_namespaceObject = require("styled-components");
|
|
31
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
32
|
+
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
33
|
+
}
|
|
34
|
+
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
35
|
+
if (descriptor.get) return descriptor.get.call(receiver);
|
|
36
|
+
return descriptor.value;
|
|
37
|
+
}
|
|
38
|
+
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
39
|
+
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
40
|
+
else {
|
|
41
|
+
if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
|
|
42
|
+
descriptor.value = value;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
46
|
+
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
47
|
+
return privateMap.get(receiver);
|
|
48
|
+
}
|
|
49
|
+
function _class_private_field_get(receiver, privateMap) {
|
|
50
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
51
|
+
return _class_apply_descriptor_get(receiver, descriptor);
|
|
52
|
+
}
|
|
53
|
+
function _class_private_field_init(obj, privateMap, value) {
|
|
54
|
+
_check_private_redeclaration(obj, privateMap);
|
|
55
|
+
privateMap.set(obj, value);
|
|
56
|
+
}
|
|
57
|
+
function _class_private_field_set(receiver, privateMap, value) {
|
|
58
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
59
|
+
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
var string_RenderLevel = /*#__PURE__*/ function(RenderLevel) {
|
|
63
|
+
RenderLevel[RenderLevel["CLIENT_RENDER"] = 0] = "CLIENT_RENDER";
|
|
64
|
+
RenderLevel[RenderLevel["SERVER_PREFETCH"] = 1] = "SERVER_PREFETCH";
|
|
65
|
+
RenderLevel[RenderLevel["SERVER_RENDER"] = 2] = "SERVER_RENDER";
|
|
66
|
+
return RenderLevel;
|
|
67
|
+
}({});
|
|
68
|
+
var _sheet = /*#__PURE__*/ new WeakMap(), _chunkSet = /*#__PURE__*/ new WeakMap();
|
|
69
|
+
class StyledCollector {
|
|
70
|
+
collect(comopnent) {
|
|
71
|
+
return _class_private_field_get(this, _sheet).collectStyles(comopnent);
|
|
72
|
+
}
|
|
73
|
+
effect() {
|
|
74
|
+
const css = _class_private_field_get(this, _sheet).getStyleTags();
|
|
75
|
+
_class_private_field_get(this, _chunkSet).cssChunk += css;
|
|
76
|
+
}
|
|
77
|
+
constructor(chunkSet){
|
|
78
|
+
_class_private_field_init(this, _sheet, {
|
|
79
|
+
writable: true,
|
|
80
|
+
value: void 0
|
|
81
|
+
});
|
|
82
|
+
_class_private_field_init(this, _chunkSet, {
|
|
83
|
+
writable: true,
|
|
84
|
+
value: void 0
|
|
85
|
+
});
|
|
86
|
+
_class_private_field_set(this, _sheet, new external_styled_components_namespaceObject.ServerStyleSheet());
|
|
87
|
+
_class_private_field_set(this, _chunkSet, chunkSet);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.RenderLevel = __webpack_exports__.RenderLevel;
|
|
91
|
+
exports.StyledCollector = __webpack_exports__.StyledCollector;
|
|
92
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
93
|
+
"RenderLevel",
|
|
94
|
+
"StyledCollector"
|
|
95
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
96
|
+
Object.defineProperty(exports, '__esModule', {
|
|
97
|
+
value: true
|
|
98
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
default: ()=>src,
|
|
28
|
+
styledComponentsPlugin: ()=>styledComponentsPlugin
|
|
29
|
+
});
|
|
30
|
+
const plugin_styled_components_namespaceObject = require("@rsbuild/plugin-styled-components");
|
|
31
|
+
const styledComponentsPlugin = (options)=>({
|
|
32
|
+
name: '@modern-js/plugin-styled-components',
|
|
33
|
+
setup (api) {
|
|
34
|
+
api.config(()=>({
|
|
35
|
+
builderPlugins: [
|
|
36
|
+
(0, plugin_styled_components_namespaceObject.pluginStyledComponents)({
|
|
37
|
+
...options,
|
|
38
|
+
topLevelImportPaths: [
|
|
39
|
+
'@modern-js/plugin-styled-components/styled'
|
|
40
|
+
]
|
|
41
|
+
})
|
|
42
|
+
],
|
|
43
|
+
resolve: {
|
|
44
|
+
alias: {
|
|
45
|
+
'styled-components': require.resolve('styled-components')
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
api._internalRuntimePlugins(async ({ entrypoint, plugins })=>{
|
|
50
|
+
plugins.push({
|
|
51
|
+
name: 'styledComponents',
|
|
52
|
+
path: '@modern-js/plugin-styled-components/runtime',
|
|
53
|
+
config: {}
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
entrypoint,
|
|
57
|
+
plugins
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const src = styledComponentsPlugin;
|
|
63
|
+
exports["default"] = __webpack_exports__["default"];
|
|
64
|
+
exports.styledComponentsPlugin = __webpack_exports__.styledComponentsPlugin;
|
|
65
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
66
|
+
"default",
|
|
67
|
+
"styledComponentsPlugin"
|
|
68
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
69
|
+
Object.defineProperty(exports, '__esModule', {
|
|
70
|
+
value: true
|
|
71
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
styledComponentsPlugin: ()=>styledComponentsPlugin
|
|
28
|
+
});
|
|
29
|
+
const stream_js_namespaceObject = require("./extender/stream.js");
|
|
30
|
+
const string_js_namespaceObject = require("./extender/string.js");
|
|
31
|
+
const styledComponentsPlugin = ()=>({
|
|
32
|
+
name: '@modern-js/plugin-styled-components',
|
|
33
|
+
setup (api) {
|
|
34
|
+
api.extendStringSSRCollectors(({ chunkSet })=>new string_js_namespaceObject.StyledCollector(chunkSet));
|
|
35
|
+
api.extendStreamSSR(()=>new stream_js_namespaceObject.StreamStyledExtender());
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
exports.styledComponentsPlugin = __webpack_exports__.styledComponentsPlugin;
|
|
39
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
40
|
+
"styledComponentsPlugin"
|
|
41
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
42
|
+
Object.defineProperty(exports, '__esModule', {
|
|
43
|
+
value: true
|
|
44
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"styled-components": function(module) {
|
|
4
|
+
module.exports = require("styled-components");
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
var __webpack_module_cache__ = {};
|
|
8
|
+
function __webpack_require__(moduleId) {
|
|
9
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
10
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
11
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
12
|
+
exports: {}
|
|
13
|
+
};
|
|
14
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
15
|
+
return module.exports;
|
|
16
|
+
}
|
|
17
|
+
(()=>{
|
|
18
|
+
__webpack_require__.n = (module)=>{
|
|
19
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
20
|
+
__webpack_require__.d(getter, {
|
|
21
|
+
a: getter
|
|
22
|
+
});
|
|
23
|
+
return getter;
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
(()=>{
|
|
27
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
28
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: definition[key]
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
34
|
+
(()=>{
|
|
35
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
36
|
+
})();
|
|
37
|
+
(()=>{
|
|
38
|
+
__webpack_require__.r = (exports1)=>{
|
|
39
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
40
|
+
value: 'Module'
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
43
|
+
value: true
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
var __webpack_exports__ = {};
|
|
48
|
+
(()=>{
|
|
49
|
+
__webpack_require__.r(__webpack_exports__);
|
|
50
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
51
|
+
default: ()=>__rspack_default_export
|
|
52
|
+
});
|
|
53
|
+
var styled_components__rspack_import_0 = __webpack_require__("styled-components");
|
|
54
|
+
var styled_components__rspack_import_0_default = /*#__PURE__*/ __webpack_require__.n(styled_components__rspack_import_0);
|
|
55
|
+
var __rspack_reexport = {};
|
|
56
|
+
for(const __rspack_import_key in styled_components__rspack_import_0)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>styled_components__rspack_import_0[__rspack_import_key];
|
|
57
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
58
|
+
const __rspack_default_export = styled_components__rspack_import_0_default();
|
|
59
|
+
})();
|
|
60
|
+
exports["default"] = __webpack_exports__["default"];
|
|
61
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
62
|
+
"default"
|
|
63
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
64
|
+
Object.defineProperty(exports, '__esModule', {
|
|
65
|
+
value: true
|
|
66
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ServerStyleSheet } from "styled-components";
|
|
2
|
+
class StreamStyledExtender {
|
|
3
|
+
init(params) {
|
|
4
|
+
this.sheet = new ServerStyleSheet();
|
|
5
|
+
this.rootElement = this.sheet.collectStyles(params.rootElement);
|
|
6
|
+
this.forceStream2String = params.forceStream2String;
|
|
7
|
+
}
|
|
8
|
+
modifyRootElement(rootElement) {
|
|
9
|
+
return this.rootElement || rootElement;
|
|
10
|
+
}
|
|
11
|
+
getStyleTags() {
|
|
12
|
+
return this.forceStream2String && this.sheet ? this.sheet.getStyleTags() : '';
|
|
13
|
+
}
|
|
14
|
+
processStream(stream) {
|
|
15
|
+
return this.sheet ? this.sheet.interleaveWithNodeStream(stream) : stream;
|
|
16
|
+
}
|
|
17
|
+
constructor(){
|
|
18
|
+
this.sheet = null;
|
|
19
|
+
this.rootElement = null;
|
|
20
|
+
this.forceStream2String = false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export { StreamStyledExtender };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ServerStyleSheet } from "styled-components";
|
|
2
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
3
|
+
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
4
|
+
}
|
|
5
|
+
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
6
|
+
if (descriptor.get) return descriptor.get.call(receiver);
|
|
7
|
+
return descriptor.value;
|
|
8
|
+
}
|
|
9
|
+
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
10
|
+
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
11
|
+
else {
|
|
12
|
+
if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
|
|
13
|
+
descriptor.value = value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
17
|
+
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
18
|
+
return privateMap.get(receiver);
|
|
19
|
+
}
|
|
20
|
+
function _class_private_field_get(receiver, privateMap) {
|
|
21
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
22
|
+
return _class_apply_descriptor_get(receiver, descriptor);
|
|
23
|
+
}
|
|
24
|
+
function _class_private_field_init(obj, privateMap, value) {
|
|
25
|
+
_check_private_redeclaration(obj, privateMap);
|
|
26
|
+
privateMap.set(obj, value);
|
|
27
|
+
}
|
|
28
|
+
function _class_private_field_set(receiver, privateMap, value) {
|
|
29
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
30
|
+
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
var string_RenderLevel = /*#__PURE__*/ function(RenderLevel) {
|
|
34
|
+
RenderLevel[RenderLevel["CLIENT_RENDER"] = 0] = "CLIENT_RENDER";
|
|
35
|
+
RenderLevel[RenderLevel["SERVER_PREFETCH"] = 1] = "SERVER_PREFETCH";
|
|
36
|
+
RenderLevel[RenderLevel["SERVER_RENDER"] = 2] = "SERVER_RENDER";
|
|
37
|
+
return RenderLevel;
|
|
38
|
+
}({});
|
|
39
|
+
var _sheet = /*#__PURE__*/ new WeakMap(), _chunkSet = /*#__PURE__*/ new WeakMap();
|
|
40
|
+
class StyledCollector {
|
|
41
|
+
collect(comopnent) {
|
|
42
|
+
return _class_private_field_get(this, _sheet).collectStyles(comopnent);
|
|
43
|
+
}
|
|
44
|
+
effect() {
|
|
45
|
+
const css = _class_private_field_get(this, _sheet).getStyleTags();
|
|
46
|
+
_class_private_field_get(this, _chunkSet).cssChunk += css;
|
|
47
|
+
}
|
|
48
|
+
constructor(chunkSet){
|
|
49
|
+
_class_private_field_init(this, _sheet, {
|
|
50
|
+
writable: true,
|
|
51
|
+
value: void 0
|
|
52
|
+
});
|
|
53
|
+
_class_private_field_init(this, _chunkSet, {
|
|
54
|
+
writable: true,
|
|
55
|
+
value: void 0
|
|
56
|
+
});
|
|
57
|
+
_class_private_field_set(this, _sheet, new ServerStyleSheet());
|
|
58
|
+
_class_private_field_set(this, _chunkSet, chunkSet);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export { string_RenderLevel as RenderLevel, StyledCollector };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { pluginStyledComponents } from "@rsbuild/plugin-styled-components";
|
|
2
|
+
const styledComponentsPlugin = (options)=>({
|
|
3
|
+
name: '@modern-js/plugin-styled-components',
|
|
4
|
+
setup (api) {
|
|
5
|
+
api.config(()=>({
|
|
6
|
+
builderPlugins: [
|
|
7
|
+
pluginStyledComponents({
|
|
8
|
+
...options,
|
|
9
|
+
topLevelImportPaths: [
|
|
10
|
+
'@modern-js/plugin-styled-components/styled'
|
|
11
|
+
]
|
|
12
|
+
})
|
|
13
|
+
],
|
|
14
|
+
resolve: {
|
|
15
|
+
alias: {
|
|
16
|
+
'styled-components': require.resolve('styled-components')
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}));
|
|
20
|
+
api._internalRuntimePlugins(async ({ entrypoint, plugins })=>{
|
|
21
|
+
plugins.push({
|
|
22
|
+
name: 'styledComponents',
|
|
23
|
+
path: '@modern-js/plugin-styled-components/runtime',
|
|
24
|
+
config: {}
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
entrypoint,
|
|
28
|
+
plugins
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const src = styledComponentsPlugin;
|
|
34
|
+
export { src as default, styledComponentsPlugin };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StreamStyledExtender } from "./extender/stream";
|
|
2
|
+
import { StyledCollector } from "./extender/string";
|
|
3
|
+
const styledComponentsPlugin = ()=>({
|
|
4
|
+
name: '@modern-js/plugin-styled-components',
|
|
5
|
+
setup (api) {
|
|
6
|
+
api.extendStringSSRCollectors(({ chunkSet })=>new StyledCollector(chunkSet));
|
|
7
|
+
api.extendStreamSSR(()=>new StreamStyledExtender());
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
export { styledComponentsPlugin };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ServerStyleSheet } from "styled-components";
|
|
2
|
+
class StreamStyledExtender {
|
|
3
|
+
init(params) {
|
|
4
|
+
this.sheet = new ServerStyleSheet();
|
|
5
|
+
this.rootElement = this.sheet.collectStyles(params.rootElement);
|
|
6
|
+
this.forceStream2String = params.forceStream2String;
|
|
7
|
+
}
|
|
8
|
+
modifyRootElement(rootElement) {
|
|
9
|
+
return this.rootElement || rootElement;
|
|
10
|
+
}
|
|
11
|
+
getStyleTags() {
|
|
12
|
+
return this.forceStream2String && this.sheet ? this.sheet.getStyleTags() : '';
|
|
13
|
+
}
|
|
14
|
+
processStream(stream) {
|
|
15
|
+
return this.sheet ? this.sheet.interleaveWithNodeStream(stream) : stream;
|
|
16
|
+
}
|
|
17
|
+
constructor(){
|
|
18
|
+
this.sheet = null;
|
|
19
|
+
this.rootElement = null;
|
|
20
|
+
this.forceStream2String = false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export { StreamStyledExtender };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ServerStyleSheet } from "styled-components";
|
|
2
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
3
|
+
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
4
|
+
}
|
|
5
|
+
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
6
|
+
if (descriptor.get) return descriptor.get.call(receiver);
|
|
7
|
+
return descriptor.value;
|
|
8
|
+
}
|
|
9
|
+
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
10
|
+
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
11
|
+
else {
|
|
12
|
+
if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
|
|
13
|
+
descriptor.value = value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
17
|
+
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
18
|
+
return privateMap.get(receiver);
|
|
19
|
+
}
|
|
20
|
+
function _class_private_field_get(receiver, privateMap) {
|
|
21
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
22
|
+
return _class_apply_descriptor_get(receiver, descriptor);
|
|
23
|
+
}
|
|
24
|
+
function _class_private_field_init(obj, privateMap, value) {
|
|
25
|
+
_check_private_redeclaration(obj, privateMap);
|
|
26
|
+
privateMap.set(obj, value);
|
|
27
|
+
}
|
|
28
|
+
function _class_private_field_set(receiver, privateMap, value) {
|
|
29
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
30
|
+
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
var string_RenderLevel = /*#__PURE__*/ function(RenderLevel) {
|
|
34
|
+
RenderLevel[RenderLevel["CLIENT_RENDER"] = 0] = "CLIENT_RENDER";
|
|
35
|
+
RenderLevel[RenderLevel["SERVER_PREFETCH"] = 1] = "SERVER_PREFETCH";
|
|
36
|
+
RenderLevel[RenderLevel["SERVER_RENDER"] = 2] = "SERVER_RENDER";
|
|
37
|
+
return RenderLevel;
|
|
38
|
+
}({});
|
|
39
|
+
var _sheet = /*#__PURE__*/ new WeakMap(), _chunkSet = /*#__PURE__*/ new WeakMap();
|
|
40
|
+
class StyledCollector {
|
|
41
|
+
collect(comopnent) {
|
|
42
|
+
return _class_private_field_get(this, _sheet).collectStyles(comopnent);
|
|
43
|
+
}
|
|
44
|
+
effect() {
|
|
45
|
+
const css = _class_private_field_get(this, _sheet).getStyleTags();
|
|
46
|
+
_class_private_field_get(this, _chunkSet).cssChunk += css;
|
|
47
|
+
}
|
|
48
|
+
constructor(chunkSet){
|
|
49
|
+
_class_private_field_init(this, _sheet, {
|
|
50
|
+
writable: true,
|
|
51
|
+
value: void 0
|
|
52
|
+
});
|
|
53
|
+
_class_private_field_init(this, _chunkSet, {
|
|
54
|
+
writable: true,
|
|
55
|
+
value: void 0
|
|
56
|
+
});
|
|
57
|
+
_class_private_field_set(this, _sheet, new ServerStyleSheet());
|
|
58
|
+
_class_private_field_set(this, _chunkSet, chunkSet);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export { string_RenderLevel as RenderLevel, StyledCollector };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { pluginStyledComponents } from "@rsbuild/plugin-styled-components";
|
|
2
|
+
const styledComponentsPlugin = (options)=>({
|
|
3
|
+
name: '@modern-js/plugin-styled-components',
|
|
4
|
+
setup (api) {
|
|
5
|
+
api.config(()=>({
|
|
6
|
+
builderPlugins: [
|
|
7
|
+
pluginStyledComponents({
|
|
8
|
+
...options,
|
|
9
|
+
topLevelImportPaths: [
|
|
10
|
+
'@modern-js/plugin-styled-components/styled'
|
|
11
|
+
]
|
|
12
|
+
})
|
|
13
|
+
],
|
|
14
|
+
resolve: {
|
|
15
|
+
alias: {
|
|
16
|
+
'styled-components': require.resolve('styled-components')
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}));
|
|
20
|
+
api._internalRuntimePlugins(async ({ entrypoint, plugins })=>{
|
|
21
|
+
plugins.push({
|
|
22
|
+
name: 'styledComponents',
|
|
23
|
+
path: '@modern-js/plugin-styled-components/runtime',
|
|
24
|
+
config: {}
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
entrypoint,
|
|
28
|
+
plugins
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const src = styledComponentsPlugin;
|
|
34
|
+
export { src as default, styledComponentsPlugin };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StreamStyledExtender } from "./extender/stream.mjs";
|
|
2
|
+
import { StyledCollector } from "./extender/string.mjs";
|
|
3
|
+
const styledComponentsPlugin = ()=>({
|
|
4
|
+
name: '@modern-js/plugin-styled-components',
|
|
5
|
+
setup (api) {
|
|
6
|
+
api.extendStringSSRCollectors(({ chunkSet })=>new StyledCollector(chunkSet));
|
|
7
|
+
api.extendStreamSSR(()=>new StreamStyledExtender());
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
export { styledComponentsPlugin };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class StreamStyledExtender {
|
|
2
|
+
private sheet;
|
|
3
|
+
private rootElement;
|
|
4
|
+
private forceStream2String;
|
|
5
|
+
init(params: {
|
|
6
|
+
rootElement: React.ReactElement;
|
|
7
|
+
forceStream2String: boolean;
|
|
8
|
+
}): void;
|
|
9
|
+
modifyRootElement(rootElement: React.ReactElement): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
10
|
+
getStyleTags(): any;
|
|
11
|
+
processStream(stream: NodeJS.ReadWriteStream): any;
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ServerStyleSheet } from 'styled-components';
|
|
2
|
+
export interface Collector {
|
|
3
|
+
collect?: (comopnent: React.ReactElement) => React.ReactElement;
|
|
4
|
+
effect: () => void | Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export declare enum RenderLevel {
|
|
7
|
+
CLIENT_RENDER = 0,
|
|
8
|
+
SERVER_PREFETCH = 1,
|
|
9
|
+
SERVER_RENDER = 2
|
|
10
|
+
}
|
|
11
|
+
export type ChunkSet = {
|
|
12
|
+
renderLevel: RenderLevel;
|
|
13
|
+
ssrScripts: string;
|
|
14
|
+
jsChunk: string;
|
|
15
|
+
cssChunk: string;
|
|
16
|
+
};
|
|
17
|
+
export declare class StyledCollector implements Collector {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(chunkSet: ChunkSet);
|
|
20
|
+
collect(comopnent: React.ReactElement): import("react").ReactElement<{
|
|
21
|
+
sheet: ServerStyleSheet;
|
|
22
|
+
}, string | import("react").JSXElementConstructor<any>>;
|
|
23
|
+
effect(): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AppTools, CliPlugin } from '@modern-js/app-tools';
|
|
2
|
+
import { type PluginStyledComponentsOptions } from '@rsbuild/plugin-styled-components';
|
|
3
|
+
export declare const styledComponentsPlugin: (options?: PluginStyledComponentsOptions) => CliPlugin<AppTools>;
|
|
4
|
+
export default styledComponentsPlugin;
|
package/package.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@modern-js/plugin-styled-components",
|
|
3
|
+
"description": "A Modern.js plugin for styled-components.",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"framework",
|
|
8
|
+
"modern",
|
|
9
|
+
"modern.js"
|
|
10
|
+
],
|
|
11
|
+
"version": "0.0.0-canary-20251127032505",
|
|
12
|
+
"jsnext:source": "./src/index.ts",
|
|
13
|
+
"types": "./src/index.ts",
|
|
14
|
+
"main": "./dist/cjs/index.js",
|
|
15
|
+
"module": "./dist/esm/index.mjs",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@swc/helpers": "^0.5.17",
|
|
18
|
+
"@rsbuild/plugin-styled-components": "1.5.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@rslib/core": "0.18.0",
|
|
22
|
+
"@types/styled-components": "^5.1.36",
|
|
23
|
+
"styled-components": "^5.3.1",
|
|
24
|
+
"@types/jest": "^29.5.14",
|
|
25
|
+
"@types/node": "^20",
|
|
26
|
+
"typescript": "^5.3.3",
|
|
27
|
+
"@modern-js/app-tools": "0.0.0-canary-20251127032505",
|
|
28
|
+
"@modern-js/rslib": "0.0.0-canary-20251127032505",
|
|
29
|
+
"@modern-js/runtime": "0.0.0-canary-20251127032505"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"styled-components": "^5.3.1"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"styled-components": {
|
|
36
|
+
"optional": true
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./dist/types/index.d.ts",
|
|
42
|
+
"jsnext:source": "./src/index.ts",
|
|
43
|
+
"node": {
|
|
44
|
+
"import": "./dist/esm-node/index.mjs",
|
|
45
|
+
"require": "./dist/cjs/index.js"
|
|
46
|
+
},
|
|
47
|
+
"default": "./dist/esm/index.mjs"
|
|
48
|
+
},
|
|
49
|
+
"./runtime": {
|
|
50
|
+
"types": "./dist/types/runtime.d.ts",
|
|
51
|
+
"jsnext:source": "./src/runtime.ts",
|
|
52
|
+
"node": {
|
|
53
|
+
"import": "./dist/esm-node/runtime.mjs",
|
|
54
|
+
"require": "./dist/cjs/runtime.js"
|
|
55
|
+
},
|
|
56
|
+
"default": "./dist/esm/runtime.mjs"
|
|
57
|
+
},
|
|
58
|
+
"./styled": {
|
|
59
|
+
"types": "./dist/types/styled.d.ts",
|
|
60
|
+
"jsnext:source": "./src/styled.ts",
|
|
61
|
+
"node": {
|
|
62
|
+
"import": "./dist/esm-node/styled.mjs",
|
|
63
|
+
"require": "./dist/cjs/styled.js"
|
|
64
|
+
},
|
|
65
|
+
"default": "./dist/esm/styled.mjs"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"typesVersions": {
|
|
69
|
+
"*": {
|
|
70
|
+
".": [
|
|
71
|
+
"./dist/types/index.d.ts"
|
|
72
|
+
],
|
|
73
|
+
"runtime": [
|
|
74
|
+
"./dist/types/runtime.d.ts"
|
|
75
|
+
],
|
|
76
|
+
"styled": [
|
|
77
|
+
"./dist/types/styled.d.ts"
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"publishConfig": {
|
|
82
|
+
"access": "public",
|
|
83
|
+
"registry": "https://registry.npmjs.org/"
|
|
84
|
+
},
|
|
85
|
+
"scripts": {
|
|
86
|
+
"dev": "rslib build --watch",
|
|
87
|
+
"build": "rslib build"
|
|
88
|
+
}
|
|
89
|
+
}
|
package/rslib.config.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ServerStyleSheet } from 'styled-components';
|
|
2
|
+
|
|
3
|
+
export class StreamStyledExtender {
|
|
4
|
+
private sheet: any | null = null;
|
|
5
|
+
private rootElement: React.ReactElement | null = null;
|
|
6
|
+
private forceStream2String = false;
|
|
7
|
+
|
|
8
|
+
init(params: {
|
|
9
|
+
rootElement: React.ReactElement;
|
|
10
|
+
forceStream2String: boolean;
|
|
11
|
+
}) {
|
|
12
|
+
this.sheet = new ServerStyleSheet();
|
|
13
|
+
this.rootElement = this.sheet.collectStyles(params.rootElement);
|
|
14
|
+
this.forceStream2String = params.forceStream2String;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
modifyRootElement(rootElement: React.ReactElement) {
|
|
18
|
+
return this.rootElement || rootElement;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getStyleTags() {
|
|
22
|
+
return this.forceStream2String && this.sheet
|
|
23
|
+
? this.sheet.getStyleTags()
|
|
24
|
+
: '';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
processStream(stream: NodeJS.ReadWriteStream) {
|
|
28
|
+
return this.sheet ? this.sheet.interleaveWithNodeStream(stream) : stream;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ServerStyleSheet } from 'styled-components';
|
|
2
|
+
|
|
3
|
+
export interface Collector {
|
|
4
|
+
collect?: (comopnent: React.ReactElement) => React.ReactElement;
|
|
5
|
+
effect: () => void | Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export enum RenderLevel {
|
|
9
|
+
CLIENT_RENDER = 0,
|
|
10
|
+
SERVER_PREFETCH = 1,
|
|
11
|
+
SERVER_RENDER = 2,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ChunkSet = {
|
|
15
|
+
renderLevel: RenderLevel;
|
|
16
|
+
ssrScripts: string;
|
|
17
|
+
jsChunk: string;
|
|
18
|
+
cssChunk: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export class StyledCollector implements Collector {
|
|
22
|
+
#sheet: ServerStyleSheet = new ServerStyleSheet();
|
|
23
|
+
|
|
24
|
+
#chunkSet: ChunkSet;
|
|
25
|
+
|
|
26
|
+
constructor(chunkSet: ChunkSet) {
|
|
27
|
+
this.#chunkSet = chunkSet;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
collect(comopnent: React.ReactElement) {
|
|
31
|
+
return this.#sheet.collectStyles(comopnent);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
effect() {
|
|
35
|
+
const css = this.#sheet.getStyleTags();
|
|
36
|
+
|
|
37
|
+
this.#chunkSet.cssChunk += css;
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AppTools, CliPlugin } from '@modern-js/app-tools';
|
|
2
|
+
import {
|
|
3
|
+
type PluginStyledComponentsOptions,
|
|
4
|
+
pluginStyledComponents,
|
|
5
|
+
} from '@rsbuild/plugin-styled-components';
|
|
6
|
+
|
|
7
|
+
export const styledComponentsPlugin = (
|
|
8
|
+
options?: PluginStyledComponentsOptions,
|
|
9
|
+
): CliPlugin<AppTools> => ({
|
|
10
|
+
name: '@modern-js/plugin-styled-components',
|
|
11
|
+
|
|
12
|
+
setup(api) {
|
|
13
|
+
api.config(() => {
|
|
14
|
+
return {
|
|
15
|
+
builderPlugins: [
|
|
16
|
+
pluginStyledComponents({
|
|
17
|
+
...options,
|
|
18
|
+
// https://github.com/styled-components/babel-plugin-styled-components/issues/287
|
|
19
|
+
topLevelImportPaths: ['@modern-js/plugin-styled-components/styled'],
|
|
20
|
+
}),
|
|
21
|
+
],
|
|
22
|
+
resolve: {
|
|
23
|
+
alias: {
|
|
24
|
+
'styled-components': require.resolve('styled-components'),
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
api._internalRuntimePlugins(async ({ entrypoint, plugins }) => {
|
|
31
|
+
plugins.push({
|
|
32
|
+
name: 'styledComponents',
|
|
33
|
+
path: '@modern-js/plugin-styled-components/runtime',
|
|
34
|
+
config: {},
|
|
35
|
+
});
|
|
36
|
+
return { entrypoint, plugins };
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export default styledComponentsPlugin;
|
package/src/runtime.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RuntimePlugin } from '@modern-js/runtime';
|
|
2
|
+
import { StreamStyledExtender } from './extender/stream';
|
|
3
|
+
import { StyledCollector } from './extender/string';
|
|
4
|
+
|
|
5
|
+
export const styledComponentsPlugin = (): RuntimePlugin => ({
|
|
6
|
+
name: '@modern-js/plugin-styled-components',
|
|
7
|
+
setup(api) {
|
|
8
|
+
api.extendStringSSRCollectors(({ chunkSet }) => {
|
|
9
|
+
return new StyledCollector(chunkSet);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
api.extendStreamSSR(() => {
|
|
13
|
+
return new StreamStyledExtender();
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
});
|
package/src/styled.ts
ADDED