@modern-js/plugin-tailwindcss 2.13.4 → 2.13.5-beta.0
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/dist/cjs/cli.js +4 -0
- package/dist/esm/cli.js +4 -0
- package/dist/esm-node/cli.js +4 -0
- package/dist/js/modern/cli.js +174 -0
- package/dist/js/modern/design-token/cli/index.js +110 -0
- package/dist/js/modern/design-token/index.js +5 -0
- package/dist/js/modern/design-token/postcss-plugin/index.js +18 -0
- package/dist/js/modern/design-token/runtime/index.js +6 -0
- package/dist/js/modern/design-token/runtime/plugin.js +66 -0
- package/dist/js/modern/index.js +4 -0
- package/dist/js/modern/tailwind.js +45 -0
- package/dist/js/modern/types.js +0 -0
- package/dist/js/modern/utils.js +86 -0
- package/dist/js/node/cli.js +190 -0
- package/dist/js/node/design-token/cli/index.js +125 -0
- package/dist/js/node/design-token/index.js +33 -0
- package/dist/js/node/design-token/postcss-plugin/index.js +39 -0
- package/dist/js/node/design-token/runtime/index.js +34 -0
- package/dist/js/node/design-token/runtime/plugin.js +94 -0
- package/dist/js/node/index.js +31 -0
- package/dist/js/node/tailwind.js +68 -0
- package/dist/js/node/types.js +15 -0
- package/dist/js/node/utils.js +119 -0
- package/dist/js/treeshaking/cli.js +268 -0
- package/dist/js/treeshaking/design-token/cli/index.js +118 -0
- package/dist/js/treeshaking/design-token/index.js +3 -0
- package/dist/js/treeshaking/design-token/postcss-plugin/index.js +17 -0
- package/dist/js/treeshaking/design-token/runtime/index.js +4 -0
- package/dist/js/treeshaking/design-token/runtime/plugin.js +78 -0
- package/dist/js/treeshaking/index.js +2 -0
- package/dist/js/treeshaking/tailwind.js +91 -0
- package/dist/js/treeshaking/types.js +1 -0
- package/dist/js/treeshaking/utils.js +194 -0
- package/package.json +4 -4
@@ -0,0 +1,119 @@
|
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
+
var __export = (target, all) => {
|
8
|
+
for (var name in all)
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
10
|
+
};
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
13
|
+
for (let key of __getOwnPropNames(from))
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
+
}
|
17
|
+
return to;
|
18
|
+
};
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
21
|
+
mod
|
22
|
+
));
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
24
|
+
var __async = (__this, __arguments, generator) => {
|
25
|
+
return new Promise((resolve, reject) => {
|
26
|
+
var fulfilled = (value) => {
|
27
|
+
try {
|
28
|
+
step(generator.next(value));
|
29
|
+
} catch (e) {
|
30
|
+
reject(e);
|
31
|
+
}
|
32
|
+
};
|
33
|
+
var rejected = (value) => {
|
34
|
+
try {
|
35
|
+
step(generator.throw(value));
|
36
|
+
} catch (e) {
|
37
|
+
reject(e);
|
38
|
+
}
|
39
|
+
};
|
40
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
41
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
42
|
+
});
|
43
|
+
};
|
44
|
+
var utils_exports = {};
|
45
|
+
__export(utils_exports, {
|
46
|
+
checkTwinMacroExist: () => checkTwinMacroExist,
|
47
|
+
getTailwindPath: () => getTailwindPath,
|
48
|
+
getTailwindVersion: () => getTailwindVersion,
|
49
|
+
getTwinMacroMajorVersion: () => getTwinMacroMajorVersion,
|
50
|
+
template: () => template
|
51
|
+
});
|
52
|
+
module.exports = __toCommonJS(utils_exports);
|
53
|
+
var import_path = __toESM(require("path"));
|
54
|
+
var import_utils = require("@modern-js/utils");
|
55
|
+
const template = (configPath) => `
|
56
|
+
function _interopRequireDefault(obj) {
|
57
|
+
return obj && obj.__esModule ? obj : { default: obj };
|
58
|
+
}
|
59
|
+
const modernConfig = _interopRequireDefault(require('${configPath}')).default;
|
60
|
+
|
61
|
+
const theme =
|
62
|
+
modernConfig && modernConfig.source && modernConfig.source.designSystem
|
63
|
+
? modernConfig.source.designSystem
|
64
|
+
: {};
|
65
|
+
const tailwindcss =
|
66
|
+
modernConfig && modernConfig.tools && modernConfig.tools.tailwindcss
|
67
|
+
? modernConfig.tools.tailwindcss
|
68
|
+
: {};
|
69
|
+
|
70
|
+
module.exports = {
|
71
|
+
theme,
|
72
|
+
...tailwindcss,
|
73
|
+
};
|
74
|
+
`;
|
75
|
+
const TWIN_MACRO_NAME = "twin.macro";
|
76
|
+
const checkTwinMacroExist = (appDirectory) => __async(void 0, null, function* () {
|
77
|
+
const packageJson = (yield import_utils.fs.readJSON(import_path.default.join(appDirectory, "package.json"), {
|
78
|
+
throws: false
|
79
|
+
})) || {};
|
80
|
+
return Boolean(
|
81
|
+
typeof packageJson.dependencies === "object" && packageJson.dependencies[TWIN_MACRO_NAME] || typeof packageJson.devDependencies === "object" && packageJson.devDependencies[TWIN_MACRO_NAME]
|
82
|
+
);
|
83
|
+
});
|
84
|
+
const getTwinMacroMajorVersion = (appDirectory) => {
|
85
|
+
try {
|
86
|
+
const pkgJsonPath = require.resolve(`${TWIN_MACRO_NAME}/package.json`, {
|
87
|
+
paths: [appDirectory]
|
88
|
+
});
|
89
|
+
const { version } = require(pkgJsonPath);
|
90
|
+
return Number(version.split(".")[0]);
|
91
|
+
} catch (err) {
|
92
|
+
return null;
|
93
|
+
}
|
94
|
+
};
|
95
|
+
function getTailwindPath(appDirectory) {
|
96
|
+
try {
|
97
|
+
return require.resolve("tailwindcss", { paths: [appDirectory, __dirname] });
|
98
|
+
} catch (err) {
|
99
|
+
return "tailwindcss";
|
100
|
+
}
|
101
|
+
}
|
102
|
+
function getTailwindVersion(appDirectory) {
|
103
|
+
try {
|
104
|
+
const packageJsonPath = require.resolve("tailwindcss/package.json", {
|
105
|
+
paths: [appDirectory, __dirname]
|
106
|
+
});
|
107
|
+
return require(packageJsonPath).version.split(".")[0];
|
108
|
+
} catch (err) {
|
109
|
+
return "3";
|
110
|
+
}
|
111
|
+
}
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
113
|
+
0 && (module.exports = {
|
114
|
+
checkTwinMacroExist,
|
115
|
+
getTailwindPath,
|
116
|
+
getTailwindVersion,
|
117
|
+
getTwinMacroMajorVersion,
|
118
|
+
template
|
119
|
+
});
|
@@ -0,0 +1,268 @@
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
2
|
+
try {
|
3
|
+
var info = gen[key](arg);
|
4
|
+
var value = info.value;
|
5
|
+
} catch (error) {
|
6
|
+
reject(error);
|
7
|
+
return;
|
8
|
+
}
|
9
|
+
if (info.done) {
|
10
|
+
resolve(value);
|
11
|
+
} else {
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
13
|
+
}
|
14
|
+
}
|
15
|
+
function _asyncToGenerator(fn) {
|
16
|
+
return function() {
|
17
|
+
var self = this, args = arguments;
|
18
|
+
return new Promise(function(resolve, reject) {
|
19
|
+
var gen = fn.apply(self, args);
|
20
|
+
function _next(value) {
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
22
|
+
}
|
23
|
+
function _throw(err) {
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
25
|
+
}
|
26
|
+
_next(undefined);
|
27
|
+
});
|
28
|
+
};
|
29
|
+
}
|
30
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
31
|
+
var f, y, t, g, _ = {
|
32
|
+
label: 0,
|
33
|
+
sent: function() {
|
34
|
+
if (t[0] & 1) throw t[1];
|
35
|
+
return t[1];
|
36
|
+
},
|
37
|
+
trys: [],
|
38
|
+
ops: []
|
39
|
+
};
|
40
|
+
return(g = {
|
41
|
+
next: verb(0),
|
42
|
+
"throw": verb(1),
|
43
|
+
"return": verb(2)
|
44
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
45
|
+
return this;
|
46
|
+
}), g);
|
47
|
+
function verb(n) {
|
48
|
+
return function(v) {
|
49
|
+
return step([
|
50
|
+
n,
|
51
|
+
v
|
52
|
+
]);
|
53
|
+
};
|
54
|
+
}
|
55
|
+
function step(op) {
|
56
|
+
if (f) throw new TypeError("Generator is already executing.");
|
57
|
+
while(_)try {
|
58
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
59
|
+
if (y = 0, t) op = [
|
60
|
+
op[0] & 2,
|
61
|
+
t.value
|
62
|
+
];
|
63
|
+
switch(op[0]){
|
64
|
+
case 0:
|
65
|
+
case 1:
|
66
|
+
t = op;
|
67
|
+
break;
|
68
|
+
case 4:
|
69
|
+
_.label++;
|
70
|
+
return {
|
71
|
+
value: op[1],
|
72
|
+
done: false
|
73
|
+
};
|
74
|
+
case 5:
|
75
|
+
_.label++;
|
76
|
+
y = op[1];
|
77
|
+
op = [
|
78
|
+
0
|
79
|
+
];
|
80
|
+
continue;
|
81
|
+
case 7:
|
82
|
+
op = _.ops.pop();
|
83
|
+
_.trys.pop();
|
84
|
+
continue;
|
85
|
+
default:
|
86
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
87
|
+
_ = 0;
|
88
|
+
continue;
|
89
|
+
}
|
90
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
91
|
+
_.label = op[1];
|
92
|
+
break;
|
93
|
+
}
|
94
|
+
if (op[0] === 6 && _.label < t[1]) {
|
95
|
+
_.label = t[1];
|
96
|
+
t = op;
|
97
|
+
break;
|
98
|
+
}
|
99
|
+
if (t && _.label < t[2]) {
|
100
|
+
_.label = t[2];
|
101
|
+
_.ops.push(op);
|
102
|
+
break;
|
103
|
+
}
|
104
|
+
if (t[2]) _.ops.pop();
|
105
|
+
_.trys.pop();
|
106
|
+
continue;
|
107
|
+
}
|
108
|
+
op = body.call(thisArg, _);
|
109
|
+
} catch (e) {
|
110
|
+
op = [
|
111
|
+
6,
|
112
|
+
e
|
113
|
+
];
|
114
|
+
y = 0;
|
115
|
+
} finally{
|
116
|
+
f = t = 0;
|
117
|
+
}
|
118
|
+
if (op[0] & 5) throw op[1];
|
119
|
+
return {
|
120
|
+
value: op[0] ? op[1] : void 0,
|
121
|
+
done: true
|
122
|
+
};
|
123
|
+
}
|
124
|
+
};
|
125
|
+
import path from "path";
|
126
|
+
import { PLUGIN_SCHEMAS, fs, CONFIG_CACHE_DIR, globby, nanoid, slash } from "@modern-js/utils";
|
127
|
+
import designTokenPlugin from "./design-token/cli";
|
128
|
+
import { getTailwindConfig } from "./tailwind";
|
129
|
+
import { template, checkTwinMacroExist, getTailwindPath, getTailwindVersion, getTwinMacroMajorVersion } from "./utils";
|
130
|
+
var supportCssInJsLibrary = "styled-components";
|
131
|
+
var getRandomTwConfigFileName = function(internalDirectory) {
|
132
|
+
return slash(path.join(internalDirectory, "tailwind.config.".concat(Date.now(), ".").concat(nanoid(), ".js")));
|
133
|
+
};
|
134
|
+
var cli_default = function() {
|
135
|
+
var pluginName = (arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
136
|
+
pluginName: "@modern-js/plugin-tailwindcss"
|
137
|
+
}).pluginName;
|
138
|
+
return {
|
139
|
+
name: "@modern-js/plugin-tailwindcss",
|
140
|
+
usePlugins: [
|
141
|
+
designTokenPlugin({
|
142
|
+
pluginName: pluginName
|
143
|
+
})
|
144
|
+
],
|
145
|
+
setup: function() {
|
146
|
+
var _ref = _asyncToGenerator(function(api) {
|
147
|
+
var _api_useAppContext, appDirectory, internalDirectory, internalTwConfigPath, haveTwinMacro, tailwindPath, tailwindVersion, defaultContent;
|
148
|
+
return __generator(this, function(_state) {
|
149
|
+
switch(_state.label){
|
150
|
+
case 0:
|
151
|
+
_api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, internalDirectory = _api_useAppContext.internalDirectory;
|
152
|
+
internalTwConfigPath = "";
|
153
|
+
return [
|
154
|
+
4,
|
155
|
+
checkTwinMacroExist(appDirectory)
|
156
|
+
];
|
157
|
+
case 1:
|
158
|
+
haveTwinMacro = _state.sent();
|
159
|
+
tailwindPath = getTailwindPath(appDirectory);
|
160
|
+
tailwindVersion = getTailwindVersion(appDirectory);
|
161
|
+
defaultContent = [
|
162
|
+
"./config/html/**/*.html",
|
163
|
+
"./config/html/**/*.ejs",
|
164
|
+
"./config/html/**/*.hbs",
|
165
|
+
"./src/**/*.js",
|
166
|
+
"./src/**/*.jsx",
|
167
|
+
"./src/**/*.ts",
|
168
|
+
"./src/**/*.tsx",
|
169
|
+
"./storybook/**/*"
|
170
|
+
];
|
171
|
+
return [
|
172
|
+
2,
|
173
|
+
{
|
174
|
+
prepare: function prepare() {
|
175
|
+
if (haveTwinMacro) {
|
176
|
+
var twinMajorVersion = getTwinMacroMajorVersion(appDirectory);
|
177
|
+
var useConfigPath = twinMajorVersion && twinMajorVersion < 3;
|
178
|
+
if (useConfigPath) {
|
179
|
+
internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
|
180
|
+
var globPattern = slash(path.join(appDirectory, CONFIG_CACHE_DIR, "*.cjs"));
|
181
|
+
var files = globby.sync(globPattern, {
|
182
|
+
absolute: true
|
183
|
+
});
|
184
|
+
if (files.length > 0) {
|
185
|
+
fs.writeFileSync(internalTwConfigPath, template(files[files.length - 1]), "utf-8");
|
186
|
+
}
|
187
|
+
}
|
188
|
+
}
|
189
|
+
},
|
190
|
+
validateSchema: function validateSchema() {
|
191
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-tailwindcss"];
|
192
|
+
},
|
193
|
+
config: function config() {
|
194
|
+
var tailwindConfig;
|
195
|
+
var initTailwindConfig = function() {
|
196
|
+
if (!tailwindConfig) {
|
197
|
+
var _modernConfig_tools, _modernConfig_source;
|
198
|
+
var modernConfig = api.useResolvedConfigContext();
|
199
|
+
tailwindConfig = getTailwindConfig(tailwindVersion, modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_tools = modernConfig.tools) === null || _modernConfig_tools === void 0 ? void 0 : _modernConfig_tools.tailwindcss, modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_source = modernConfig.source) === null || _modernConfig_source === void 0 ? void 0 : _modernConfig_source.designSystem, {
|
200
|
+
pureConfig: {
|
201
|
+
content: defaultContent
|
202
|
+
}
|
203
|
+
});
|
204
|
+
}
|
205
|
+
};
|
206
|
+
return {
|
207
|
+
tools: {
|
208
|
+
postcss: function(config) {
|
209
|
+
initTailwindConfig();
|
210
|
+
var tailwindPlugin = require(tailwindPath)(tailwindConfig);
|
211
|
+
if (Array.isArray(config.postcssOptions.plugins)) {
|
212
|
+
config.postcssOptions.plugins.push(tailwindPlugin);
|
213
|
+
} else {
|
214
|
+
config.postcssOptions.plugins = [
|
215
|
+
tailwindPlugin
|
216
|
+
];
|
217
|
+
}
|
218
|
+
},
|
219
|
+
babel: function babel(_, param) {
|
220
|
+
var addPlugins = param.addPlugins;
|
221
|
+
if (haveTwinMacro) {
|
222
|
+
initTailwindConfig();
|
223
|
+
addPlugins([
|
224
|
+
[
|
225
|
+
require.resolve("babel-plugin-macros"),
|
226
|
+
{
|
227
|
+
twin: {
|
228
|
+
preset: supportCssInJsLibrary,
|
229
|
+
config: internalTwConfigPath || tailwindConfig
|
230
|
+
}
|
231
|
+
}
|
232
|
+
]
|
233
|
+
]);
|
234
|
+
}
|
235
|
+
}
|
236
|
+
}
|
237
|
+
};
|
238
|
+
},
|
239
|
+
beforeBuildTask: function beforeBuildTask(config) {
|
240
|
+
var modernConfig = api.useResolvedConfigContext();
|
241
|
+
var designSystem = modernConfig.designSystem;
|
242
|
+
var tailwindConfig = getTailwindConfig(tailwindVersion, config.style.tailwindCss, designSystem, {
|
243
|
+
pureConfig: {
|
244
|
+
content: defaultContent
|
245
|
+
}
|
246
|
+
});
|
247
|
+
var tailwindPlugin = require(tailwindPath)(tailwindConfig);
|
248
|
+
if (Array.isArray(config.style.postcss.plugins)) {
|
249
|
+
config.style.postcss.plugins.push(tailwindPlugin);
|
250
|
+
} else {
|
251
|
+
config.style.postcss.plugins = [
|
252
|
+
tailwindPlugin
|
253
|
+
];
|
254
|
+
}
|
255
|
+
return config;
|
256
|
+
}
|
257
|
+
}
|
258
|
+
];
|
259
|
+
}
|
260
|
+
});
|
261
|
+
});
|
262
|
+
return function(api) {
|
263
|
+
return _ref.apply(this, arguments);
|
264
|
+
};
|
265
|
+
}()
|
266
|
+
};
|
267
|
+
};
|
268
|
+
export { cli_default as default, getRandomTwConfigFileName };
|
@@ -0,0 +1,118 @@
|
|
1
|
+
function _defineProperty(obj, key, value) {
|
2
|
+
if (key in obj) {
|
3
|
+
Object.defineProperty(obj, key, {
|
4
|
+
value: value,
|
5
|
+
enumerable: true,
|
6
|
+
configurable: true,
|
7
|
+
writable: true
|
8
|
+
});
|
9
|
+
} else {
|
10
|
+
obj[key] = value;
|
11
|
+
}
|
12
|
+
return obj;
|
13
|
+
}
|
14
|
+
function _objectSpread(target) {
|
15
|
+
for(var i = 1; i < arguments.length; i++){
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
17
|
+
var ownKeys = Object.keys(source);
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
19
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
21
|
+
}));
|
22
|
+
}
|
23
|
+
ownKeys.forEach(function(key) {
|
24
|
+
_defineProperty(target, key, source[key]);
|
25
|
+
});
|
26
|
+
}
|
27
|
+
return target;
|
28
|
+
}
|
29
|
+
import { lazyImport, PLUGIN_SCHEMAS, createRuntimeExportsUtils } from "@modern-js/utils";
|
30
|
+
var cli_default = function() {
|
31
|
+
var pluginName = (arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
32
|
+
pluginName: "@modern-js/plugin-tailwindcss"
|
33
|
+
}).pluginName;
|
34
|
+
return {
|
35
|
+
name: "@modern-js/plugin-design-token",
|
36
|
+
setup: function setup(api) {
|
37
|
+
var pluginsExportsUtils;
|
38
|
+
var resolveConfig = lazyImport("tailwindcss/resolveConfig", require);
|
39
|
+
var PLUGIN_IDENTIFIER = "designToken";
|
40
|
+
var getDesignTokens = function(designSystem) {
|
41
|
+
var tailwindcssConfig = {};
|
42
|
+
tailwindcssConfig.theme = designSystem ? _objectSpread({}, designSystem) : {};
|
43
|
+
if (!designSystem) {
|
44
|
+
tailwindcssConfig.presets = [];
|
45
|
+
}
|
46
|
+
if (designSystem) {
|
47
|
+
delete tailwindcssConfig.theme.supportStyledComponents;
|
48
|
+
}
|
49
|
+
return resolveConfig(tailwindcssConfig).theme || {};
|
50
|
+
};
|
51
|
+
return {
|
52
|
+
config: function config() {
|
53
|
+
var appContext = api.useAppContext();
|
54
|
+
pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "plugins");
|
55
|
+
return {
|
56
|
+
source: {
|
57
|
+
alias: {
|
58
|
+
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath()
|
59
|
+
}
|
60
|
+
},
|
61
|
+
tools: {}
|
62
|
+
};
|
63
|
+
},
|
64
|
+
modifyEntryImports: function modifyEntryImports(param) {
|
65
|
+
var entrypoint = param.entrypoint, imports = param.imports;
|
66
|
+
var _userConfig_source;
|
67
|
+
var userConfig = api.useResolvedConfigContext();
|
68
|
+
var _userConfig_source_designSystem;
|
69
|
+
var designSystem = (_userConfig_source_designSystem = (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.designSystem) !== null && _userConfig_source_designSystem !== void 0 ? _userConfig_source_designSystem : {};
|
70
|
+
if (typeof designSystem === "object" && designSystem.supportStyledComponents) {
|
71
|
+
var designTokens = getDesignTokens(userConfig.source.designSystem);
|
72
|
+
imports.push({
|
73
|
+
value: "@modern-js/runtime/plugins",
|
74
|
+
specifiers: [
|
75
|
+
{
|
76
|
+
imported: PLUGIN_IDENTIFIER
|
77
|
+
}
|
78
|
+
],
|
79
|
+
initialize: "\n const designTokens = ".concat(JSON.stringify(designTokens), ";\n ")
|
80
|
+
});
|
81
|
+
}
|
82
|
+
return {
|
83
|
+
entrypoint: entrypoint,
|
84
|
+
imports: imports
|
85
|
+
};
|
86
|
+
},
|
87
|
+
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(param) {
|
88
|
+
var entrypoint = param.entrypoint, plugins = param.plugins;
|
89
|
+
var _userConfig_source;
|
90
|
+
var userConfig = api.useResolvedConfigContext();
|
91
|
+
var _userConfig_source_designSystem;
|
92
|
+
var designSystem = (_userConfig_source_designSystem = (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.designSystem) !== null && _userConfig_source_designSystem !== void 0 ? _userConfig_source_designSystem : {};
|
93
|
+
var useSCThemeProvider = true;
|
94
|
+
if (designSystem) {
|
95
|
+
useSCThemeProvider = (designSystem === null || designSystem === void 0 ? void 0 : designSystem.supportStyledComponents) || false;
|
96
|
+
}
|
97
|
+
if (typeof designSystem === "object" && designSystem.supportStyledComponents) {
|
98
|
+
plugins.push({
|
99
|
+
name: PLUGIN_IDENTIFIER,
|
100
|
+
options: "{token: designTokens, useStyledComponentsThemeProvider: ".concat(useSCThemeProvider ? "true" : "false", ", useDesignTokenContext: false}")
|
101
|
+
});
|
102
|
+
}
|
103
|
+
return {
|
104
|
+
entrypoint: entrypoint,
|
105
|
+
plugins: plugins
|
106
|
+
};
|
107
|
+
},
|
108
|
+
validateSchema: function validateSchema() {
|
109
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-design-token"];
|
110
|
+
},
|
111
|
+
addRuntimeExports: function addRuntimeExports() {
|
112
|
+
pluginsExportsUtils.addExport("export { default as designToken } from '".concat(pluginName, "/runtime-design-token'"));
|
113
|
+
}
|
114
|
+
};
|
115
|
+
}
|
116
|
+
};
|
117
|
+
};
|
118
|
+
export { cli_default as default };
|
@@ -0,0 +1,17 @@
|
|
1
|
+
var postcss_plugin_default = function() {
|
2
|
+
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _ref_cssVarsHash = _ref.cssVarsHash, cssVarsHash = _ref_cssVarsHash === void 0 ? {} : _ref_cssVarsHash;
|
3
|
+
return {
|
4
|
+
postcssPlugin: "postcss-replace-css-vars",
|
5
|
+
Declaration: function Declaration(decl) {
|
6
|
+
if (decl.value && typeof decl.value === "string") {
|
7
|
+
decl.value = decl.value.replace(/--\S*/g, function(match) {
|
8
|
+
if (cssVarsHash[match]) {
|
9
|
+
return cssVarsHash[match];
|
10
|
+
}
|
11
|
+
return match;
|
12
|
+
});
|
13
|
+
}
|
14
|
+
}
|
15
|
+
};
|
16
|
+
};
|
17
|
+
export { postcss_plugin_default as default };
|
@@ -0,0 +1,78 @@
|
|
1
|
+
function _defineProperty(obj, key, value) {
|
2
|
+
if (key in obj) {
|
3
|
+
Object.defineProperty(obj, key, {
|
4
|
+
value: value,
|
5
|
+
enumerable: true,
|
6
|
+
configurable: true,
|
7
|
+
writable: true
|
8
|
+
});
|
9
|
+
} else {
|
10
|
+
obj[key] = value;
|
11
|
+
}
|
12
|
+
return obj;
|
13
|
+
}
|
14
|
+
function _objectSpread(target) {
|
15
|
+
for(var i = 1; i < arguments.length; i++){
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
17
|
+
var ownKeys = Object.keys(source);
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
19
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
21
|
+
}));
|
22
|
+
}
|
23
|
+
ownKeys.forEach(function(key) {
|
24
|
+
_defineProperty(target, key, source[key]);
|
25
|
+
});
|
26
|
+
}
|
27
|
+
return target;
|
28
|
+
}
|
29
|
+
import { jsx } from "react/jsx-runtime";
|
30
|
+
import hoistNonReactStatics from "hoist-non-react-statics";
|
31
|
+
import React, { useContext } from "react";
|
32
|
+
var DesignTokenContext = React.createContext({});
|
33
|
+
var useDesignTokens = function() {
|
34
|
+
return useContext(DesignTokenContext);
|
35
|
+
};
|
36
|
+
var plugin_default = function() {
|
37
|
+
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
38
|
+
return {
|
39
|
+
name: "@modern-js/plugin-design-token",
|
40
|
+
setup: function() {
|
41
|
+
return {
|
42
|
+
hoc: function hoc(param, next) {
|
43
|
+
var App = param.App;
|
44
|
+
var DesignTokenAppWrapper = function(props) {
|
45
|
+
var _options_token = options.token, token = _options_token === void 0 ? {} : _options_token, _options_useStyledComponentsThemeProvider = options.useStyledComponentsThemeProvider, useStyledComponentsThemeProvider = _options_useStyledComponentsThemeProvider === void 0 ? false : _options_useStyledComponentsThemeProvider, _options_useDesignTokenContext = options.useDesignTokenContext, useDesignTokenContext = _options_useDesignTokenContext === void 0 ? false : _options_useDesignTokenContext;
|
46
|
+
if (useStyledComponentsThemeProvider && useDesignTokenContext) {
|
47
|
+
var ThemeProvider = require("@modern-js/runtime/styled").ThemeProvider;
|
48
|
+
return /* @__PURE__ */ jsx(ThemeProvider, {
|
49
|
+
theme: token,
|
50
|
+
children: /* @__PURE__ */ jsx(DesignTokenContext.Provider, {
|
51
|
+
value: token,
|
52
|
+
children: /* @__PURE__ */ jsx(App, _objectSpread({}, props))
|
53
|
+
})
|
54
|
+
});
|
55
|
+
} else if (useStyledComponentsThemeProvider) {
|
56
|
+
var ThemeProvider1 = require("@modern-js/runtime/styled").ThemeProvider;
|
57
|
+
return /* @__PURE__ */ jsx(ThemeProvider1, {
|
58
|
+
theme: token,
|
59
|
+
children: /* @__PURE__ */ jsx(App, _objectSpread({}, props))
|
60
|
+
});
|
61
|
+
} else if (useDesignTokenContext) {
|
62
|
+
return /* @__PURE__ */ jsx(DesignTokenContext.Provider, {
|
63
|
+
value: token,
|
64
|
+
children: /* @__PURE__ */ jsx(App, _objectSpread({}, props))
|
65
|
+
});
|
66
|
+
} else {
|
67
|
+
return /* @__PURE__ */ jsx(App, _objectSpread({}, props));
|
68
|
+
}
|
69
|
+
};
|
70
|
+
return next({
|
71
|
+
App: hoistNonReactStatics(DesignTokenAppWrapper, App)
|
72
|
+
});
|
73
|
+
}
|
74
|
+
};
|
75
|
+
}
|
76
|
+
};
|
77
|
+
};
|
78
|
+
export { DesignTokenContext, plugin_default as default, useDesignTokens };
|