@longzai-intelligence-builder/css 0.2.11 → 0.2.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/dist/index.mjs +11 -941
- package/package.json +7 -4
package/dist/index.mjs
CHANGED
|
@@ -1,941 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
else if (options.target == null) cssTarget = topLevelTarget;
|
|
13
|
-
else cssTarget = expandBaselineTarget(resolveComma(toArray(options.target)));
|
|
14
|
-
return {
|
|
15
|
-
transformer: options.transformer ?? "lightningcss",
|
|
16
|
-
splitting: options.splitting ?? !!unbundle,
|
|
17
|
-
fileName: options.fileName ?? "style.css",
|
|
18
|
-
minify: options.minify ?? false,
|
|
19
|
-
inject: options.inject ?? false,
|
|
20
|
-
modules: options.modules === false ? false : options.modules ?? {},
|
|
21
|
-
target: cssTarget,
|
|
22
|
-
preprocessorOptions: options.preprocessorOptions,
|
|
23
|
-
lightningcss: options.lightningcss,
|
|
24
|
-
postcss: options.postcss
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/modules.ts
|
|
29
|
-
function modulesToEsm(modules) {
|
|
30
|
-
const lines = [];
|
|
31
|
-
let index = 0;
|
|
32
|
-
for (const [key, value] of Object.entries(modules)) {
|
|
33
|
-
if (key === "default") continue;
|
|
34
|
-
const binding = `_key${index++}`;
|
|
35
|
-
lines.push(`const ${binding} = ${JSON.stringify(value)};`, `export { ${binding} as ${JSON.stringify(key)} };`);
|
|
36
|
-
}
|
|
37
|
-
lines.push(`export default ${JSON.stringify(modules)};`);
|
|
38
|
-
return lines.join("\n");
|
|
39
|
-
}
|
|
40
|
-
function dashToCamel(str) {
|
|
41
|
-
return str.replaceAll(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
42
|
-
}
|
|
43
|
-
function applyLocalsConvention(modules, convention) {
|
|
44
|
-
const result = {};
|
|
45
|
-
for (const [key, value] of Object.entries(modules)) {
|
|
46
|
-
const camelized = dashToCamel(key);
|
|
47
|
-
switch (convention) {
|
|
48
|
-
case "camelCase":
|
|
49
|
-
result[key] = value;
|
|
50
|
-
if (camelized !== key) result[camelized] = value;
|
|
51
|
-
break;
|
|
52
|
-
case "camelCaseOnly":
|
|
53
|
-
result[camelized] = value;
|
|
54
|
-
break;
|
|
55
|
-
case "dashes":
|
|
56
|
-
result[key] = value;
|
|
57
|
-
if (key.includes("-")) result[camelized] = value;
|
|
58
|
-
break;
|
|
59
|
-
case "dashesOnly":
|
|
60
|
-
if (key.includes("-")) result[camelized] = value;
|
|
61
|
-
else result[key] = value;
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
function extractLightningCssModuleExports(exports) {
|
|
68
|
-
const modules = {};
|
|
69
|
-
const sortedEntries = Object.entries(exports).toSorted(([a], [b]) => a.localeCompare(b));
|
|
70
|
-
for (const [key, value] of sortedEntries) {
|
|
71
|
-
let name = value.name;
|
|
72
|
-
for (const c of value.composes) name += ` ${c.name}`;
|
|
73
|
-
modules[key] = name;
|
|
74
|
-
}
|
|
75
|
-
return modules;
|
|
76
|
-
}
|
|
77
|
-
//#endregion
|
|
78
|
-
//#region src/resolve.ts
|
|
79
|
-
let cssResolver;
|
|
80
|
-
let sassResolver;
|
|
81
|
-
function getCssResolver() {
|
|
82
|
-
return cssResolver ??= new ResolverFactory({ conditionNames: ["style", "default"] });
|
|
83
|
-
}
|
|
84
|
-
function getSassResolver() {
|
|
85
|
-
return sassResolver ??= new ResolverFactory({
|
|
86
|
-
conditionNames: [
|
|
87
|
-
"sass",
|
|
88
|
-
"style",
|
|
89
|
-
"default"
|
|
90
|
-
],
|
|
91
|
-
mainFields: [
|
|
92
|
-
"sass",
|
|
93
|
-
"style",
|
|
94
|
-
"main"
|
|
95
|
-
],
|
|
96
|
-
extensions: [
|
|
97
|
-
".scss",
|
|
98
|
-
".sass",
|
|
99
|
-
".css"
|
|
100
|
-
]
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
function resolveWithResolver(resolver, specifier, from) {
|
|
104
|
-
const dir = path.dirname(from);
|
|
105
|
-
const result = resolver.sync(dir, specifier);
|
|
106
|
-
if (result.error || !result.path) return;
|
|
107
|
-
return result.path;
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region src/utils.ts
|
|
111
|
-
const RE_CSS = /\.css$/;
|
|
112
|
-
const RE_INLINE = /[?&]inline\b/;
|
|
113
|
-
const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus)(?:$|\?)/;
|
|
114
|
-
const RE_CSS_INLINE = /\.(?:css|less|sass|scss|styl|stylus)\?(?:.*&)?inline\b/;
|
|
115
|
-
const CSS_MODULE_RE = /\.module\.(?:css|less|sass|scss|styl|stylus)(?:$|\?)/;
|
|
116
|
-
function toCssFileName(jsFileName) {
|
|
117
|
-
return jsFileName.replace(/(?:\.module)?(\.[cm]?js)$/, ".css");
|
|
118
|
-
}
|
|
119
|
-
function getCleanId(id) {
|
|
120
|
-
const queryIndex = id.indexOf("?");
|
|
121
|
-
return queryIndex === -1 ? id : id.slice(0, queryIndex);
|
|
122
|
-
}
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region src/preprocessors.ts
|
|
125
|
-
const PREPROCESSOR_LANGS = {
|
|
126
|
-
sass: "sass",
|
|
127
|
-
less: "less",
|
|
128
|
-
scss: "scss",
|
|
129
|
-
styl: "styl",
|
|
130
|
-
stylus: "stylus"
|
|
131
|
-
};
|
|
132
|
-
function getPreprocessorLang(filename) {
|
|
133
|
-
const ext = path.extname(filename).slice(1);
|
|
134
|
-
return PREPROCESSOR_LANGS[ext];
|
|
135
|
-
}
|
|
136
|
-
function getPreprocessorLangFromId(id) {
|
|
137
|
-
const match = CSS_LANGS_RE.exec(id);
|
|
138
|
-
if (!match) return;
|
|
139
|
-
return PREPROCESSOR_LANGS[match[1]];
|
|
140
|
-
}
|
|
141
|
-
function compilePreprocessor(lang, code, filename, options) {
|
|
142
|
-
switch (lang) {
|
|
143
|
-
case "scss":
|
|
144
|
-
case "sass": return compileSass(lang, code, filename, options);
|
|
145
|
-
case "less": return compileLess(code, filename, options);
|
|
146
|
-
case "styl":
|
|
147
|
-
case "stylus": return compileStylus(code, filename, options);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const cssUrlRE = /(?<!@import\s+)(?<=^|[^\w\-\u0080-\uFFFF])url\((\s*('[^']+'|"[^"]+")\s*|(?:\\.|[^'")\\])+)\)/;
|
|
151
|
-
const cssDataUriRE = /(?<=^|[^\w\-\u0080-\uFFFF])data-uri\((\s*('[^']+'|"[^"]+")\s*|[^'")]+)\)/;
|
|
152
|
-
const importCssRE = /@import\s+(?:url\()?('[^']+\.css'|"[^"]+\.css"|[^'"\s)]+\.css)/;
|
|
153
|
-
async function rebaseUrls(file, rootFile, ignoreUrl) {
|
|
154
|
-
file = path.resolve(file);
|
|
155
|
-
const fileDir = path.dirname(file);
|
|
156
|
-
const rootDir = path.dirname(rootFile);
|
|
157
|
-
if (fileDir === rootDir) return { file };
|
|
158
|
-
const content = await readFile(file, "utf8");
|
|
159
|
-
const hasUrls = cssUrlRE.test(content);
|
|
160
|
-
const hasDataUris = cssDataUriRE.test(content);
|
|
161
|
-
const hasImportCss = importCssRE.test(content);
|
|
162
|
-
if (!hasUrls && !hasDataUris && !hasImportCss) return { file };
|
|
163
|
-
let rebased;
|
|
164
|
-
const rebaseFn = (unquotedUrl, rawUrl) => {
|
|
165
|
-
if (ignoreUrl?.(unquotedUrl, rawUrl)) return false;
|
|
166
|
-
if (unquotedUrl[0] === "/") return unquotedUrl;
|
|
167
|
-
const absolute = path.resolve(fileDir, unquotedUrl);
|
|
168
|
-
return normalizePath(path.relative(rootDir, absolute));
|
|
169
|
-
};
|
|
170
|
-
if (hasImportCss) rebased = await rewriteImportCss(content, rebaseFn);
|
|
171
|
-
if (hasUrls) rebased = await rewriteCssUrls(rebased || content, rebaseFn);
|
|
172
|
-
if (hasDataUris) rebased = await rewriteCssDataUris(rebased || content, rebaseFn);
|
|
173
|
-
return {
|
|
174
|
-
file,
|
|
175
|
-
contents: rebased
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
async function asyncReplace(input, re, replacer) {
|
|
179
|
-
let match;
|
|
180
|
-
let remaining = input;
|
|
181
|
-
let rewritten = "";
|
|
182
|
-
while (match = re.exec(remaining)) {
|
|
183
|
-
rewritten += remaining.slice(0, match.index);
|
|
184
|
-
rewritten += await replacer(match);
|
|
185
|
-
remaining = remaining.slice(match.index + match[0].length);
|
|
186
|
-
}
|
|
187
|
-
rewritten += remaining;
|
|
188
|
-
return rewritten;
|
|
189
|
-
}
|
|
190
|
-
function rewriteCssUrls(css, replacer) {
|
|
191
|
-
return asyncReplace(css, cssUrlRE, async (match) => {
|
|
192
|
-
const [matched, rawUrl] = match;
|
|
193
|
-
return await doUrlReplace(rawUrl.trim(), matched, replacer);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
function rewriteCssDataUris(css, replacer) {
|
|
197
|
-
return asyncReplace(css, cssDataUriRE, async (match) => {
|
|
198
|
-
const [matched, rawUrl] = match;
|
|
199
|
-
return await doUrlReplace(rawUrl.trim(), matched, replacer, "data-uri");
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
function rewriteImportCss(css, replacer) {
|
|
203
|
-
return asyncReplace(css, importCssRE, async (match) => {
|
|
204
|
-
const [matched, rawUrl] = match;
|
|
205
|
-
return await doImportCSSReplace(rawUrl, matched, replacer);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
const externalRE = /^(?:[a-z]+:)?\/\//;
|
|
209
|
-
const dataUrlRE = /^\s*data:/i;
|
|
210
|
-
function skipUrlReplacer(unquotedUrl) {
|
|
211
|
-
return externalRE.test(unquotedUrl) || dataUrlRE.test(unquotedUrl) || unquotedUrl[0] === "#";
|
|
212
|
-
}
|
|
213
|
-
async function doUrlReplace(rawUrl, matched, replacer, funcName = "url") {
|
|
214
|
-
let wrap = "";
|
|
215
|
-
const first = rawUrl[0];
|
|
216
|
-
if (first === `"` || first === `'`) {
|
|
217
|
-
wrap = first;
|
|
218
|
-
rawUrl = rawUrl.slice(1, -1);
|
|
219
|
-
}
|
|
220
|
-
if (skipUrlReplacer(rawUrl)) return matched;
|
|
221
|
-
const newUrl = await replacer(rawUrl, matched);
|
|
222
|
-
if (typeof newUrl === "string") {
|
|
223
|
-
if (wrap === "" && newUrl !== encodeURI(newUrl)) wrap = "\"";
|
|
224
|
-
return `${funcName}(${wrap}${newUrl}${wrap})`;
|
|
225
|
-
}
|
|
226
|
-
return matched;
|
|
227
|
-
}
|
|
228
|
-
async function doImportCSSReplace(rawUrl, matched, replacer) {
|
|
229
|
-
let wrap = "";
|
|
230
|
-
const first = rawUrl[0];
|
|
231
|
-
if (first === `"` || first === `'`) {
|
|
232
|
-
wrap = first;
|
|
233
|
-
rawUrl = rawUrl.slice(1, -1);
|
|
234
|
-
}
|
|
235
|
-
const newUrl = await replacer(rawUrl, matched);
|
|
236
|
-
if (typeof newUrl === "string") return matched.replace(`${wrap}${rawUrl}${wrap}`, `${wrap}${newUrl}${wrap}`);
|
|
237
|
-
return matched;
|
|
238
|
-
}
|
|
239
|
-
function normalizePath(id) {
|
|
240
|
-
return id.replaceAll("\\", "/");
|
|
241
|
-
}
|
|
242
|
-
async function getSource(source, filename, additionalData, sep = "") {
|
|
243
|
-
if (!additionalData) return source;
|
|
244
|
-
if (typeof additionalData === "function") {
|
|
245
|
-
const newContent = await additionalData(source, filename);
|
|
246
|
-
if (typeof newContent === "string") return newContent;
|
|
247
|
-
return newContent.content;
|
|
248
|
-
}
|
|
249
|
-
return additionalData + sep + source;
|
|
250
|
-
}
|
|
251
|
-
async function compileSass(lang, code, filename, options) {
|
|
252
|
-
const sass = await loadSass();
|
|
253
|
-
const preprocessorOpts = options?.scss ?? options?.sass ?? {};
|
|
254
|
-
const data = await getSource(code, filename, preprocessorOpts.additionalData);
|
|
255
|
-
const { additionalData: _, ...sassOptions } = preprocessorOpts;
|
|
256
|
-
const skipRebaseUrls = (unquotedUrl, rawUrl) => {
|
|
257
|
-
if (!(rawUrl[0] === "\"" || rawUrl[0] === "'") && unquotedUrl[0] === "$") return true;
|
|
258
|
-
return unquotedUrl.startsWith("#{");
|
|
259
|
-
};
|
|
260
|
-
const internalImporter = {
|
|
261
|
-
async canonicalize(url, context) {
|
|
262
|
-
const resolved = await tryResolveScss(url, context.containingUrl ? fileURLToPath(context.containingUrl) : filename);
|
|
263
|
-
if (resolved) return pathToFileURL(resolved);
|
|
264
|
-
return null;
|
|
265
|
-
},
|
|
266
|
-
async load(canonicalUrl) {
|
|
267
|
-
const ext = path.extname(canonicalUrl.pathname);
|
|
268
|
-
let syntax = "scss";
|
|
269
|
-
if (ext === ".sass") syntax = "indented";
|
|
270
|
-
else if (ext === ".css") syntax = "css";
|
|
271
|
-
const result = await rebaseUrls(fileURLToPath(canonicalUrl), filename, skipRebaseUrls);
|
|
272
|
-
return {
|
|
273
|
-
contents: result.contents ?? await readFile(result.file, "utf8"),
|
|
274
|
-
syntax,
|
|
275
|
-
sourceMapUrl: canonicalUrl
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
const result = await (await loadSassCompiler(sass)).compileStringAsync(data, {
|
|
280
|
-
url: pathToFileURL(filename),
|
|
281
|
-
sourceMap: false,
|
|
282
|
-
syntax: lang === "sass" ? "indented" : "scss",
|
|
283
|
-
...sassOptions,
|
|
284
|
-
importers: [internalImporter, ...sassOptions.importers ?? []]
|
|
285
|
-
});
|
|
286
|
-
return {
|
|
287
|
-
code: result.css,
|
|
288
|
-
deps: result.loadedUrls.filter((url) => url.protocol === "file:").map((url) => fileURLToPath(url))
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
async function tryResolveScss(url, importer) {
|
|
292
|
-
const dir = path.dirname(importer);
|
|
293
|
-
const { existsSync } = await import("node:fs");
|
|
294
|
-
const extensions = [
|
|
295
|
-
".scss",
|
|
296
|
-
".sass",
|
|
297
|
-
".css"
|
|
298
|
-
];
|
|
299
|
-
const prefixes = ["", "_"];
|
|
300
|
-
if (extensions.some((ext) => url.endsWith(ext))) for (const prefix of prefixes) {
|
|
301
|
-
const file = path.resolve(dir, path.dirname(url), prefix + path.basename(url));
|
|
302
|
-
if (existsSync(file)) return file;
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
for (const ext of extensions) for (const prefix of prefixes) {
|
|
306
|
-
const file = path.resolve(dir, path.dirname(url), prefix + path.basename(url) + ext);
|
|
307
|
-
if (existsSync(file)) return file;
|
|
308
|
-
}
|
|
309
|
-
for (const ext of extensions) for (const prefix of prefixes) {
|
|
310
|
-
const file = path.resolve(dir, url, `${prefix}index${ext}`);
|
|
311
|
-
if (existsSync(file)) return file;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return resolveWithResolver(getSassResolver(), url, importer);
|
|
315
|
-
}
|
|
316
|
-
let _sass;
|
|
317
|
-
let _sassCompiler;
|
|
318
|
-
function loadSassCompiler(sass) {
|
|
319
|
-
if (!sass.initAsyncCompiler) return Promise.resolve(sass);
|
|
320
|
-
_sassCompiler ??= sass.initAsyncCompiler().catch((error) => {
|
|
321
|
-
_sassCompiler = void 0;
|
|
322
|
-
throw error;
|
|
323
|
-
});
|
|
324
|
-
return _sassCompiler;
|
|
325
|
-
}
|
|
326
|
-
async function disposeSassCompiler() {
|
|
327
|
-
const compilerPromise = _sassCompiler;
|
|
328
|
-
_sassCompiler = void 0;
|
|
329
|
-
await (await compilerPromise?.catch(() => void 0))?.dispose?.();
|
|
330
|
-
}
|
|
331
|
-
async function loadSass() {
|
|
332
|
-
if (_sass) return _sass;
|
|
333
|
-
try {
|
|
334
|
-
_sass = await import("sass-embedded");
|
|
335
|
-
return _sass;
|
|
336
|
-
} catch {
|
|
337
|
-
try {
|
|
338
|
-
_sass = await import("sass");
|
|
339
|
-
return _sass;
|
|
340
|
-
} catch {
|
|
341
|
-
throw new Error("Preprocessor dependency \"sass\" not found. Did you install it? Try `npm install -D sass`.");
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
async function compileLess(code, filename, options) {
|
|
346
|
-
const less = await loadLess();
|
|
347
|
-
const preprocessorOpts = options?.less ?? {};
|
|
348
|
-
const data = await getSource(code, filename, preprocessorOpts.additionalData);
|
|
349
|
-
const { additionalData: _, plugins = [], ...lessOptions } = preprocessorOpts;
|
|
350
|
-
const result = await less.render(data, {
|
|
351
|
-
paths: ["node_modules"],
|
|
352
|
-
...lessOptions,
|
|
353
|
-
filename,
|
|
354
|
-
plugins
|
|
355
|
-
});
|
|
356
|
-
return {
|
|
357
|
-
code: result.css,
|
|
358
|
-
deps: result.imports || []
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
let _less;
|
|
362
|
-
async function loadLess() {
|
|
363
|
-
if (_less) return _less;
|
|
364
|
-
try {
|
|
365
|
-
_less = (await import("less")).default;
|
|
366
|
-
return _less;
|
|
367
|
-
} catch {
|
|
368
|
-
throw new Error("Preprocessor dependency \"less\" not found. Did you install it? Try `npm install -D less`.");
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
async function compileStylus(code, filename, options) {
|
|
372
|
-
const stylus = await loadStylus();
|
|
373
|
-
const preprocessorOpts = options?.styl ?? options?.stylus ?? {};
|
|
374
|
-
const data = await getSource(code, filename, preprocessorOpts.additionalData, "\n");
|
|
375
|
-
const { additionalData: _, define, ...stylusOptions } = preprocessorOpts;
|
|
376
|
-
const ref = stylus(data, {
|
|
377
|
-
paths: ["node_modules"],
|
|
378
|
-
...stylusOptions,
|
|
379
|
-
filename
|
|
380
|
-
});
|
|
381
|
-
if (define) for (const key of Object.keys(define)) ref.define(key, define[key]);
|
|
382
|
-
return new Promise((resolve, reject) => {
|
|
383
|
-
ref.render((err, css) => {
|
|
384
|
-
if (err) reject(/* @__PURE__ */ new Error(`[stylus] ${err.message}`));
|
|
385
|
-
else resolve({
|
|
386
|
-
code: css,
|
|
387
|
-
deps: ref.deps()
|
|
388
|
-
});
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
let _stylus;
|
|
393
|
-
async function loadStylus() {
|
|
394
|
-
if (_stylus) return _stylus;
|
|
395
|
-
try {
|
|
396
|
-
_stylus = (await import("stylus")).default;
|
|
397
|
-
return _stylus;
|
|
398
|
-
} catch {
|
|
399
|
-
throw new Error("Preprocessor dependency \"stylus\" not found. Did you install it? Try `npm install -D stylus`.");
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
//#endregion
|
|
403
|
-
//#region src/lightningcss.ts
|
|
404
|
-
const encoder = new TextEncoder();
|
|
405
|
-
const decoder = new TextDecoder();
|
|
406
|
-
async function transformWithLightningCSS(code, filename, options) {
|
|
407
|
-
const targets = options.lightningcss?.targets ?? (options.target ? esbuildTargetToLightningCSS(options.target) : void 0);
|
|
408
|
-
if (!targets && !options.lightningcss && !options.minify && !options.cssModules) return { code };
|
|
409
|
-
const { transform } = await import("lightningcss");
|
|
410
|
-
const result = transform({
|
|
411
|
-
filename,
|
|
412
|
-
code: encoder.encode(code),
|
|
413
|
-
...options.lightningcss,
|
|
414
|
-
targets,
|
|
415
|
-
minify: options.minify,
|
|
416
|
-
cssModules: options.cssModules,
|
|
417
|
-
sourceMap: options.sourceMap,
|
|
418
|
-
inputSourceMap: options.inputSourceMap
|
|
419
|
-
});
|
|
420
|
-
return {
|
|
421
|
-
code: decoder.decode(result.code),
|
|
422
|
-
map: result.map ? decoder.decode(result.map) : void 0,
|
|
423
|
-
modules: result.exports ? extractLightningCssModuleExports(result.exports) : void 0
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
async function bundleWithLightningCSS(filename, options, code) {
|
|
427
|
-
const targets = options.lightningcss?.targets ?? (options.target ? esbuildTargetToLightningCSS(options.target) : void 0);
|
|
428
|
-
const deps = [];
|
|
429
|
-
const { bundleAsync } = await import("lightningcss");
|
|
430
|
-
const result = await bundleAsync({
|
|
431
|
-
filename,
|
|
432
|
-
...options.lightningcss,
|
|
433
|
-
targets,
|
|
434
|
-
minify: options.minify,
|
|
435
|
-
cssModules: options.cssModules,
|
|
436
|
-
sourceMap: options.sourceMap,
|
|
437
|
-
resolver: {
|
|
438
|
-
async read(filePath) {
|
|
439
|
-
let fileCode;
|
|
440
|
-
if (code != null && filePath === filename) fileCode = code;
|
|
441
|
-
else fileCode = readFileSync(filePath, "utf8");
|
|
442
|
-
const lang = getPreprocessorLang(filePath);
|
|
443
|
-
if (lang) {
|
|
444
|
-
const preprocessed = await compilePreprocessor(lang, fileCode, filePath, options.preprocessorOptions);
|
|
445
|
-
deps.push(...preprocessed.deps);
|
|
446
|
-
return preprocessed.code;
|
|
447
|
-
}
|
|
448
|
-
return fileCode;
|
|
449
|
-
},
|
|
450
|
-
resolve(specifier, from) {
|
|
451
|
-
const resolved = resolveWithResolver(getCssResolver(), specifier, from);
|
|
452
|
-
if (!resolved) {
|
|
453
|
-
options.logger.warn(`[@lzi-builder/css] Failed to resolve import '${specifier}' from '${from}'`);
|
|
454
|
-
return path.resolve(path.dirname(from), specifier);
|
|
455
|
-
}
|
|
456
|
-
return resolved;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
return {
|
|
461
|
-
code: decoder.decode(result.code),
|
|
462
|
-
deps,
|
|
463
|
-
map: result.map ? decoder.decode(result.map) : void 0,
|
|
464
|
-
modules: result.exports ? extractLightningCssModuleExports(result.exports) : void 0
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
const TARGET_REGEX = /([a-z]+)(\d+(?:\.\d+)*)/g;
|
|
468
|
-
const ESBUILD_LIGHTNINGCSS_MAPPING = {
|
|
469
|
-
chrome: "chrome",
|
|
470
|
-
edge: "edge",
|
|
471
|
-
firefox: "firefox",
|
|
472
|
-
ie: "ie",
|
|
473
|
-
ios: "ios_saf",
|
|
474
|
-
opera: "opera",
|
|
475
|
-
safari: "safari"
|
|
476
|
-
};
|
|
477
|
-
function parseVersion(version) {
|
|
478
|
-
const [major, minor = 0, patch = 0] = version.split("-", 1)[0].split(".").map((v) => Number.parseInt(v, 10));
|
|
479
|
-
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch)) return null;
|
|
480
|
-
return major << 16 | minor << 8 | patch;
|
|
481
|
-
}
|
|
482
|
-
function esbuildTargetToLightningCSS(target) {
|
|
483
|
-
let targets;
|
|
484
|
-
const matches = [...target.join(" ").toLowerCase().matchAll(TARGET_REGEX)];
|
|
485
|
-
for (const match of matches) {
|
|
486
|
-
const name = match[1];
|
|
487
|
-
const browser = ESBUILD_LIGHTNINGCSS_MAPPING[name];
|
|
488
|
-
if (!browser) continue;
|
|
489
|
-
const version = match[2];
|
|
490
|
-
const versionInt = parseVersion(version);
|
|
491
|
-
if (versionInt == null) continue;
|
|
492
|
-
targets = targets || {};
|
|
493
|
-
targets[browser] = versionInt;
|
|
494
|
-
}
|
|
495
|
-
return targets;
|
|
496
|
-
}
|
|
497
|
-
//#endregion
|
|
498
|
-
//#region src/pure-chunk.ts
|
|
499
|
-
/**
|
|
500
|
-
* Detect and remove "pure CSS chunks" — JS chunks that exist only because
|
|
501
|
-
* they imported CSS files. These chunks have no JS exports and all their
|
|
502
|
-
* modules are CSS. Following Vite's implementation.
|
|
503
|
-
*/
|
|
504
|
-
function removePureCssChunks(bundle, styles) {
|
|
505
|
-
const pureCssChunkNames = [];
|
|
506
|
-
for (const chunk of Object.values(bundle)) {
|
|
507
|
-
if (chunk.type !== "chunk" || chunk.exports.length || !chunk.moduleIds.length) continue;
|
|
508
|
-
if (chunk.moduleIds.every((id) => styles.has(id))) pureCssChunkNames.push(chunk.fileName);
|
|
509
|
-
}
|
|
510
|
-
const strictSet = new Set(pureCssChunkNames);
|
|
511
|
-
for (const chunk of Object.values(bundle)) {
|
|
512
|
-
if (chunk.type !== "chunk" || chunk.exports.length || chunk.isEntry || chunk.isDynamicEntry) continue;
|
|
513
|
-
if (strictSet.has(chunk.fileName)) continue;
|
|
514
|
-
if (chunk.moduleIds.some((id) => styles.has(id)) && isEmptyChunkCode$1(chunk.code)) pureCssChunkNames.push(chunk.fileName);
|
|
515
|
-
}
|
|
516
|
-
if (!pureCssChunkNames.length) return;
|
|
517
|
-
const replaceEmptyChunk = getEmptyChunkReplacer(pureCssChunkNames);
|
|
518
|
-
for (const chunk of Object.values(bundle)) {
|
|
519
|
-
if (chunk.type !== "chunk") continue;
|
|
520
|
-
let chunkImportsPureCssChunk = false;
|
|
521
|
-
chunk.imports = chunk.imports.filter((importFile) => {
|
|
522
|
-
if (pureCssChunkNames.includes(importFile)) {
|
|
523
|
-
chunkImportsPureCssChunk = true;
|
|
524
|
-
return false;
|
|
525
|
-
}
|
|
526
|
-
return true;
|
|
527
|
-
});
|
|
528
|
-
if (chunkImportsPureCssChunk) chunk.code = replaceEmptyChunk(chunk.code);
|
|
529
|
-
}
|
|
530
|
-
for (const fileName of pureCssChunkNames) {
|
|
531
|
-
delete bundle[fileName];
|
|
532
|
-
delete bundle[`${fileName}.map`];
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* Create a replacer function that replaces import statements for pure CSS
|
|
537
|
-
* chunks with block comments of the same length, preserving source map offsets.
|
|
538
|
-
*/
|
|
539
|
-
function getEmptyChunkReplacer(pureCssChunkNames) {
|
|
540
|
-
const emptyChunkFiles = pureCssChunkNames.map((file) => escapeRegex(path.basename(file))).join("|");
|
|
541
|
-
const emptyChunkRE = new RegExp(String.raw`\bimport\s*["'][^"']*(?:${emptyChunkFiles})["'];`, "g");
|
|
542
|
-
return (code) => code.replace(emptyChunkRE, (m) => {
|
|
543
|
-
return `/* empty css ${"".padEnd(m.length - 15)}*/`;
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
function escapeRegex(str) {
|
|
547
|
-
return str.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
|
|
548
|
-
}
|
|
549
|
-
function isEmptyChunkCode$1(code) {
|
|
550
|
-
return !code.replaceAll(/\/\*[\s\S]*?\*\//g, "").replaceAll(/\/\/[^\n]*/g, "").replaceAll(/\bexport\s*\{\s*\};?/g, "").replaceAll(/\bimport\s*["'][^"']*["'];?/g, "").trim();
|
|
551
|
-
}
|
|
552
|
-
//#endregion
|
|
553
|
-
//#region src/post.ts
|
|
554
|
-
function CssPostPlugin(config, styles) {
|
|
555
|
-
const collectedCSS = [];
|
|
556
|
-
async function finalizeCss(css) {
|
|
557
|
-
if (!config.minify) return css;
|
|
558
|
-
let code = (await transformWithLightningCSS(css, defaultCssBundleName, {
|
|
559
|
-
target: config.target,
|
|
560
|
-
lightningcss: config.lightningcss,
|
|
561
|
-
minify: true
|
|
562
|
-
})).code;
|
|
563
|
-
if (code.length && !code.endsWith("\n")) code += "\n";
|
|
564
|
-
return code;
|
|
565
|
-
}
|
|
566
|
-
return {
|
|
567
|
-
name: "lzi-builder:css-post",
|
|
568
|
-
renderChunk(_code, chunk) {
|
|
569
|
-
if (styles.size === 0) return;
|
|
570
|
-
if (config.splitting) return;
|
|
571
|
-
let chunkCSS = "";
|
|
572
|
-
for (const id of Object.keys(chunk.modules)) {
|
|
573
|
-
const code = styles.get(id);
|
|
574
|
-
if (code) chunkCSS += code;
|
|
575
|
-
}
|
|
576
|
-
if (!chunkCSS) return;
|
|
577
|
-
if (chunkCSS.length > 0 && !chunkCSS.endsWith("\n")) chunkCSS += "\n";
|
|
578
|
-
collectedCSS.push(chunkCSS);
|
|
579
|
-
},
|
|
580
|
-
async generateBundle(_outputOptions, bundle) {
|
|
581
|
-
if (config.splitting) for (const chunk of Object.values(bundle)) {
|
|
582
|
-
if (chunk.type !== "chunk") continue;
|
|
583
|
-
let chunkCSS = "";
|
|
584
|
-
for (const id of chunk.moduleIds) {
|
|
585
|
-
const code = styles.get(id);
|
|
586
|
-
if (code) chunkCSS += code;
|
|
587
|
-
}
|
|
588
|
-
if (!chunkCSS) continue;
|
|
589
|
-
if (!chunkCSS.endsWith("\n")) chunkCSS += "\n";
|
|
590
|
-
chunkCSS = await finalizeCss(chunkCSS);
|
|
591
|
-
const cssAssetFileName = toCssFileName(chunk.fileName);
|
|
592
|
-
this.emitFile({
|
|
593
|
-
type: "asset",
|
|
594
|
-
fileName: cssAssetFileName,
|
|
595
|
-
source: chunkCSS
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
else if (collectedCSS.length > 0) {
|
|
599
|
-
let allCSS = collectedCSS.join("");
|
|
600
|
-
if (allCSS) {
|
|
601
|
-
allCSS = await finalizeCss(allCSS);
|
|
602
|
-
this.emitFile({
|
|
603
|
-
type: "asset",
|
|
604
|
-
fileName: config.fileName,
|
|
605
|
-
source: allCSS,
|
|
606
|
-
originalFileName: defaultCssBundleName
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
collectedCSS.length = 0;
|
|
610
|
-
}
|
|
611
|
-
removePureCssChunks(bundle, styles);
|
|
612
|
-
}
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
//#endregion
|
|
616
|
-
//#region src/postcss.ts
|
|
617
|
-
const fileConfigCache = /* @__PURE__ */ new Map();
|
|
618
|
-
async function loadFileConfig(searchPath) {
|
|
619
|
-
const cached = fileConfigCache.get(searchPath);
|
|
620
|
-
if (cached !== void 0) return cached;
|
|
621
|
-
const promise = (async () => {
|
|
622
|
-
try {
|
|
623
|
-
const postcssrc = (await import("postcss-load-config")).default;
|
|
624
|
-
const result = await postcssrc({}, searchPath);
|
|
625
|
-
return {
|
|
626
|
-
options: result.options,
|
|
627
|
-
plugins: result.plugins
|
|
628
|
-
};
|
|
629
|
-
} catch (error) {
|
|
630
|
-
if (error.message?.includes("No PostCSS Config found")) return null;
|
|
631
|
-
throw error;
|
|
632
|
-
}
|
|
633
|
-
})();
|
|
634
|
-
fileConfigCache.set(searchPath, promise);
|
|
635
|
-
const result = await promise;
|
|
636
|
-
fileConfigCache.set(searchPath, result);
|
|
637
|
-
return result;
|
|
638
|
-
}
|
|
639
|
-
function resolvePostCSSConfig(postcssOption, cwd) {
|
|
640
|
-
if (typeof postcssOption === "object") {
|
|
641
|
-
const { plugins, ...options } = postcssOption;
|
|
642
|
-
return {
|
|
643
|
-
options,
|
|
644
|
-
plugins: plugins || []
|
|
645
|
-
};
|
|
646
|
-
}
|
|
647
|
-
return loadFileConfig(typeof postcssOption === "string" ? postcssOption : cwd);
|
|
648
|
-
}
|
|
649
|
-
async function processWithPostCSS$1(code, filename, postcssOption, cwd, injectImport, modulesOptions, sourceMap) {
|
|
650
|
-
const config = await resolvePostCSSConfig(postcssOption, cwd);
|
|
651
|
-
const plugins = [];
|
|
652
|
-
let modules;
|
|
653
|
-
if (modulesOptions?.isModule) {
|
|
654
|
-
const postcssModules = await importWithError("postcss-modules");
|
|
655
|
-
const { localsConvention: _, getJSON: userGetJSON, ...rest } = modulesOptions.config ?? {};
|
|
656
|
-
plugins.push((postcssModules.default ?? postcssModules)({
|
|
657
|
-
...rest,
|
|
658
|
-
getJSON(cssFileName, json, outputFileName) {
|
|
659
|
-
modules = json;
|
|
660
|
-
userGetJSON?.(cssFileName, json, outputFileName);
|
|
661
|
-
}
|
|
662
|
-
}));
|
|
663
|
-
}
|
|
664
|
-
if (injectImport) {
|
|
665
|
-
const postcssImport = await importWithError("postcss-import");
|
|
666
|
-
plugins.push((postcssImport.default ?? postcssImport)());
|
|
667
|
-
}
|
|
668
|
-
if (config) plugins.push(...config.plugins);
|
|
669
|
-
if (!plugins.length && !config?.options.parser) return {
|
|
670
|
-
code,
|
|
671
|
-
deps: []
|
|
672
|
-
};
|
|
673
|
-
const result = await (await importWithError("postcss")).default(plugins).process(code, {
|
|
674
|
-
...config?.options,
|
|
675
|
-
from: filename,
|
|
676
|
-
to: filename,
|
|
677
|
-
map: sourceMap ? {
|
|
678
|
-
inline: false,
|
|
679
|
-
annotation: false,
|
|
680
|
-
prev: false
|
|
681
|
-
} : void 0
|
|
682
|
-
});
|
|
683
|
-
const deps = [];
|
|
684
|
-
for (const message of result.messages) if (message.type === "dependency") deps.push(message.file);
|
|
685
|
-
else if (message.type === "dir-dependency") {
|
|
686
|
-
const { dir } = message;
|
|
687
|
-
if (typeof dir === "string") deps.push(dir);
|
|
688
|
-
}
|
|
689
|
-
return {
|
|
690
|
-
code: result.css,
|
|
691
|
-
deps,
|
|
692
|
-
map: result.map?.toString(),
|
|
693
|
-
modules
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
//#endregion
|
|
697
|
-
//#region src/plugin.ts
|
|
698
|
-
function shouldSkipTransform(id, cleanId) {
|
|
699
|
-
const isInline = RE_INLINE.test(id);
|
|
700
|
-
return id !== cleanId && !isInline && CSS_LANGS_RE.test(cleanId);
|
|
701
|
-
}
|
|
702
|
-
function CssPlugin(config, { logger }) {
|
|
703
|
-
const cssConfig = {
|
|
704
|
-
css: resolveCssOptions(config.css, config.target, config.unbundle),
|
|
705
|
-
cwd: config.cwd,
|
|
706
|
-
target: config.target,
|
|
707
|
-
sourceMap: Boolean(config.sourcemap)
|
|
708
|
-
};
|
|
709
|
-
const styles = /* @__PURE__ */ new Map();
|
|
710
|
-
const modulesMap = /* @__PURE__ */ new Map();
|
|
711
|
-
const cssCompilePlugin = {
|
|
712
|
-
name: "@lzi-builder/css",
|
|
713
|
-
buildStart() {
|
|
714
|
-
styles.clear();
|
|
715
|
-
modulesMap.clear();
|
|
716
|
-
},
|
|
717
|
-
closeBundle() {
|
|
718
|
-
if (!this.meta.watchMode) return disposeSassCompiler();
|
|
719
|
-
},
|
|
720
|
-
closeWatcher() {
|
|
721
|
-
return disposeSassCompiler();
|
|
722
|
-
},
|
|
723
|
-
resolveId: {
|
|
724
|
-
filter: { id: RE_CSS_INLINE },
|
|
725
|
-
async handler(source, ...args) {
|
|
726
|
-
const cleanSource = getCleanId(source);
|
|
727
|
-
const resolved = await this.resolve(cleanSource, ...args);
|
|
728
|
-
if (resolved) return {
|
|
729
|
-
...resolved,
|
|
730
|
-
id: `${resolved.id}?inline`
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
},
|
|
734
|
-
load: {
|
|
735
|
-
filter: { id: RE_CSS_INLINE },
|
|
736
|
-
async handler(id) {
|
|
737
|
-
const cleanId = getCleanId(id);
|
|
738
|
-
if (styles.has(id)) return;
|
|
739
|
-
const code = await readFile(cleanId, "utf8").catch(() => null);
|
|
740
|
-
if (code == null) return;
|
|
741
|
-
this.addWatchFile(cleanId);
|
|
742
|
-
return {
|
|
743
|
-
code,
|
|
744
|
-
moduleType: "js"
|
|
745
|
-
};
|
|
746
|
-
}
|
|
747
|
-
},
|
|
748
|
-
transform: {
|
|
749
|
-
filter: { id: CSS_LANGS_RE },
|
|
750
|
-
async handler(code, id) {
|
|
751
|
-
const cleanId = getCleanId(id);
|
|
752
|
-
if (shouldSkipTransform(id, cleanId)) return;
|
|
753
|
-
const isModule = !RE_INLINE.test(id) && cssConfig.css.modules !== false && CSS_MODULE_RE.test(id);
|
|
754
|
-
const deps = [];
|
|
755
|
-
let modules;
|
|
756
|
-
let map;
|
|
757
|
-
if (cssConfig.css.transformer === "lightningcss") {
|
|
758
|
-
const result = await processWithLightningCSS(code, id, cleanId, deps, cssConfig, logger, isModule);
|
|
759
|
-
code = result.code;
|
|
760
|
-
modules = result.modules;
|
|
761
|
-
map = result.map;
|
|
762
|
-
} else {
|
|
763
|
-
const result = await processWithPostCSS(code, id, cleanId, deps, cssConfig, isModule);
|
|
764
|
-
code = result.code;
|
|
765
|
-
modules = result.modules;
|
|
766
|
-
map = result.map;
|
|
767
|
-
}
|
|
768
|
-
for (const dep of deps) this.addWatchFile(dep);
|
|
769
|
-
if (code.length && !code.endsWith("\n")) code += "\n";
|
|
770
|
-
if (modules) {
|
|
771
|
-
const modulesConfig = typeof cssConfig.css.modules === "object" ? cssConfig.css.modules : void 0;
|
|
772
|
-
if (modulesConfig?.localsConvention) modules = applyLocalsConvention(modules, modulesConfig.localsConvention);
|
|
773
|
-
modulesConfig?.getJSON?.(cleanId, modules, cleanId);
|
|
774
|
-
modulesMap.set(id, modules);
|
|
775
|
-
}
|
|
776
|
-
return {
|
|
777
|
-
code,
|
|
778
|
-
map: map ?? null
|
|
779
|
-
};
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
};
|
|
783
|
-
const postPlugins = [{
|
|
784
|
-
name: "@lzi-builder/css:collect",
|
|
785
|
-
transform: {
|
|
786
|
-
filter: { id: CSS_LANGS_RE },
|
|
787
|
-
handler(code, id) {
|
|
788
|
-
if (shouldSkipTransform(id, getCleanId(id))) return;
|
|
789
|
-
const isInline = RE_INLINE.test(id);
|
|
790
|
-
const modules = modulesMap.get(id);
|
|
791
|
-
if (isInline) return {
|
|
792
|
-
code: `export default ${JSON.stringify(code)};`,
|
|
793
|
-
map: null,
|
|
794
|
-
moduleSideEffects: false,
|
|
795
|
-
moduleType: "js"
|
|
796
|
-
};
|
|
797
|
-
if (code.length) styles.set(id, code);
|
|
798
|
-
if (modules) return {
|
|
799
|
-
code: modulesToEsm(modules),
|
|
800
|
-
map: null,
|
|
801
|
-
moduleSideEffects: false,
|
|
802
|
-
moduleType: "js"
|
|
803
|
-
};
|
|
804
|
-
return {
|
|
805
|
-
code: "",
|
|
806
|
-
map: null,
|
|
807
|
-
moduleSideEffects: "no-treeshake",
|
|
808
|
-
moduleType: "js"
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
}];
|
|
813
|
-
if (cssConfig.css.inject) postPlugins.push({
|
|
814
|
-
name: "@lzi-builder/css:inject",
|
|
815
|
-
generateBundle(_outputOptions, bundle) {
|
|
816
|
-
const chunks = Object.values(bundle);
|
|
817
|
-
const pureCssChunks = /* @__PURE__ */ new Set();
|
|
818
|
-
for (const chunk of chunks) {
|
|
819
|
-
if (chunk.type !== "chunk" || chunk.exports.length || !chunk.moduleIds.length) continue;
|
|
820
|
-
if (chunk.moduleIds.every((id) => styles.has(id))) {
|
|
821
|
-
pureCssChunks.add(chunk.fileName);
|
|
822
|
-
continue;
|
|
823
|
-
}
|
|
824
|
-
if (!chunk.isEntry && !chunk.isDynamicEntry && chunk.moduleIds.some((id) => styles.has(id)) && isEmptyChunkCode(chunk.code)) pureCssChunks.add(chunk.fileName);
|
|
825
|
-
}
|
|
826
|
-
for (const chunk of chunks) {
|
|
827
|
-
if (chunk.type !== "chunk") continue;
|
|
828
|
-
if (pureCssChunks.has(chunk.fileName)) continue;
|
|
829
|
-
if (cssConfig.css.splitting) {
|
|
830
|
-
for (const imp of chunk.imports) {
|
|
831
|
-
if (!pureCssChunks.has(imp)) continue;
|
|
832
|
-
const basename = path.basename(imp);
|
|
833
|
-
const escaped = basename.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
|
|
834
|
-
const cssBasename = toCssFileName(basename);
|
|
835
|
-
const importRE = new RegExp(String.raw`(\bimport\s*["'][^"']*)${escaped}(["'];)`);
|
|
836
|
-
chunk.code = chunk.code.replace(importRE, `$1${cssBasename}$2`);
|
|
837
|
-
}
|
|
838
|
-
if (chunk.moduleIds.some((id) => styles.has(id))) {
|
|
839
|
-
const cssFile = toCssFileName(chunk.fileName);
|
|
840
|
-
const relativePath = path.posix.relative(path.posix.dirname(chunk.fileName), cssFile);
|
|
841
|
-
chunk.code = `import '${relativePath[0] === "." ? relativePath : `./${relativePath}`}';\n${chunk.code}`;
|
|
842
|
-
if (chunk.map) chunk.map.mappings = `;${chunk.map.mappings}`;
|
|
843
|
-
}
|
|
844
|
-
} else if (chunk.moduleIds.some((id) => styles.has(id)) || chunk.imports.some((imp) => pureCssChunks.has(imp))) {
|
|
845
|
-
const cssFile = cssConfig.css.fileName;
|
|
846
|
-
const relativePath = path.posix.relative(path.posix.dirname(chunk.fileName), cssFile);
|
|
847
|
-
chunk.code = `import '${relativePath[0] === "." ? relativePath : `./${relativePath}`}';\n${chunk.code}`;
|
|
848
|
-
if (chunk.map) chunk.map.mappings = `;${chunk.map.mappings}`;
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
});
|
|
853
|
-
postPlugins.push(CssPostPlugin(cssConfig.css, styles));
|
|
854
|
-
return {
|
|
855
|
-
pre: [cssCompilePlugin],
|
|
856
|
-
post: postPlugins
|
|
857
|
-
};
|
|
858
|
-
}
|
|
859
|
-
function resolveCssModulesConfig(modulesOptions, isModule, logger) {
|
|
860
|
-
if (!isModule) return void 0;
|
|
861
|
-
const config = typeof modulesOptions === "object" ? modulesOptions : void 0;
|
|
862
|
-
if (!config) return true;
|
|
863
|
-
const cssModulesConfig = {};
|
|
864
|
-
if (typeof config.generateScopedName === "string") cssModulesConfig.pattern = config.generateScopedName;
|
|
865
|
-
else if (typeof config.generateScopedName === "function") logger.warn("[@lzi-builder/css] `generateScopedName` as a function is not supported with `transformer: \"lightningcss\"`. Use a string pattern or switch to `transformer: \"postcss\"`.");
|
|
866
|
-
if (config.scopeBehaviour === "global") cssModulesConfig.pattern = "[local]";
|
|
867
|
-
return Object.keys(cssModulesConfig).length > 0 ? cssModulesConfig : true;
|
|
868
|
-
}
|
|
869
|
-
async function processWithLightningCSS(code, id, cleanId, deps, config, logger, isModule) {
|
|
870
|
-
const lang = getPreprocessorLangFromId(id);
|
|
871
|
-
const cssModules = resolveCssModulesConfig(config.css.modules, isModule, logger);
|
|
872
|
-
if (lang) {
|
|
873
|
-
const preResult = await compilePreprocessor(lang, code, cleanId, config.css.preprocessorOptions);
|
|
874
|
-
deps.push(...preResult.deps);
|
|
875
|
-
return transformWithLightningCSS(preResult.code, cleanId, {
|
|
876
|
-
target: config.css.target,
|
|
877
|
-
lightningcss: config.css.lightningcss,
|
|
878
|
-
minify: config.css.minify,
|
|
879
|
-
cssModules,
|
|
880
|
-
sourceMap: config.sourceMap
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
|
-
if (id !== cleanId && !RE_INLINE.test(id)) return transformWithLightningCSS(code, cleanId, {
|
|
884
|
-
target: config.css.target,
|
|
885
|
-
lightningcss: config.css.lightningcss,
|
|
886
|
-
minify: config.css.minify,
|
|
887
|
-
cssModules,
|
|
888
|
-
sourceMap: config.sourceMap
|
|
889
|
-
});
|
|
890
|
-
if (RE_CSS.test(cleanId)) {
|
|
891
|
-
const bundleResult = await bundleWithLightningCSS(cleanId, {
|
|
892
|
-
target: config.css.target,
|
|
893
|
-
lightningcss: config.css.lightningcss,
|
|
894
|
-
minify: config.css.minify,
|
|
895
|
-
cssModules,
|
|
896
|
-
preprocessorOptions: config.css.preprocessorOptions,
|
|
897
|
-
sourceMap: config.sourceMap,
|
|
898
|
-
logger
|
|
899
|
-
}, code);
|
|
900
|
-
deps.push(...bundleResult.deps);
|
|
901
|
-
return {
|
|
902
|
-
code: bundleResult.code,
|
|
903
|
-
map: bundleResult.map,
|
|
904
|
-
modules: bundleResult.modules
|
|
905
|
-
};
|
|
906
|
-
}
|
|
907
|
-
return { code: "" };
|
|
908
|
-
}
|
|
909
|
-
async function processWithPostCSS(code, id, cleanId, deps, config, isModule) {
|
|
910
|
-
const lang = getPreprocessorLangFromId(id);
|
|
911
|
-
if (lang) {
|
|
912
|
-
const preResult = await compilePreprocessor(lang, code, cleanId, config.css.preprocessorOptions);
|
|
913
|
-
code = preResult.code;
|
|
914
|
-
deps.push(...preResult.deps);
|
|
915
|
-
}
|
|
916
|
-
const modulesConfig = typeof config.css.modules === "object" ? config.css.modules : void 0;
|
|
917
|
-
const needInlineImport = code.includes("@import");
|
|
918
|
-
const postcssResult = await processWithPostCSS$1(code, cleanId, config.css.postcss, config.cwd, needInlineImport, isModule ? {
|
|
919
|
-
isModule: true,
|
|
920
|
-
config: modulesConfig
|
|
921
|
-
} : void 0, config.sourceMap);
|
|
922
|
-
code = postcssResult.code;
|
|
923
|
-
deps.push(...postcssResult.deps);
|
|
924
|
-
const transformResult = await transformWithLightningCSS(code, cleanId, {
|
|
925
|
-
target: config.css.target,
|
|
926
|
-
lightningcss: config.css.lightningcss,
|
|
927
|
-
minify: config.css.minify,
|
|
928
|
-
sourceMap: config.sourceMap,
|
|
929
|
-
inputSourceMap: postcssResult.map
|
|
930
|
-
});
|
|
931
|
-
return {
|
|
932
|
-
code: transformResult.code,
|
|
933
|
-
map: transformResult.map ?? postcssResult.map,
|
|
934
|
-
modules: postcssResult.modules
|
|
935
|
-
};
|
|
936
|
-
}
|
|
937
|
-
function isEmptyChunkCode(code) {
|
|
938
|
-
return !code.replaceAll(/\/\*[\s\S]*?\*\//g, "").replaceAll(/\/\/[^\n]*/g, "").replaceAll(/\bexport\s*\{\s*\};?/g, "").replaceAll(/\bimport\s*["'][^"']*["'];?/g, "").trim();
|
|
939
|
-
}
|
|
940
|
-
//#endregion
|
|
941
|
-
export { CssPlugin, resolveCssOptions };
|
|
1
|
+
import"node:module";import{expandBaselineTarget as e,importWithError as t,resolveComma as n,toArray as r}from"@longzai-intelligence-builder/core";import{readFile as i}from"node:fs/promises";import a from"node:path";import{readFileSync as o}from"node:fs";import{fileURLToPath as s,pathToFileURL as c}from"node:url";import{ResolverFactory as l}from"rolldown/experimental";const u=`style.css`;function d(t={},i,a){let o;return o=t.target===!1?void 0:t.target==null?i:e(n(r(t.target))),{transformer:t.transformer??`lightningcss`,splitting:t.splitting??!!a,fileName:t.fileName??`style.css`,minify:t.minify??!1,inject:t.inject??!1,modules:t.modules===!1?!1:t.modules??{},target:o,preprocessorOptions:t.preprocessorOptions,lightningcss:t.lightningcss,postcss:t.postcss}}function f(e){let t=[],n=0;for(let[r,i]of Object.entries(e)){if(r==="default")continue;let e=`_key${n++}`;t.push(`const ${e} = ${JSON.stringify(i)};`,`export { ${e} as ${JSON.stringify(r)} };`)}return t.push(`export default ${JSON.stringify(e)};`),t.join(`
|
|
2
|
+
`)}function p(e){return e.replaceAll(/-([a-z])/g,(e,t)=>t.toUpperCase())}function m(e,t){let n={};for(let[r,i]of Object.entries(e)){let e=p(r);switch(t){case`camelCase`:n[r]=i,e!==r&&(n[e]=i);break;case`camelCaseOnly`:n[e]=i;break;case`dashes`:n[r]=i,r.includes(`-`)&&(n[e]=i);break;case`dashesOnly`:r.includes(`-`)?n[e]=i:n[r]=i;break}}return n}function h(e){let t={},n=Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t));for(let[e,r]of n){let n=r.name;for(let e of r.composes)n+=` ${e.name}`;t[e]=n}return t}let g,ee;function _(){return g??=new l({conditionNames:[`style`,`default`]})}function v(){return ee??=new l({conditionNames:[`sass`,`style`,`default`],mainFields:[`sass`,`style`,`main`],extensions:[`.scss`,`.sass`,`.css`]})}function y(e,t,n){let r=a.dirname(n),i=e.sync(r,t);if(!(i.error||!i.path))return i.path}const te=/\.css$/,b=/[?&]inline\b/,x=/\.(css|less|sass|scss|styl|stylus)(?:$|\?)/,S=/\.(?:css|less|sass|scss|styl|stylus)\?(?:.*&)?inline\b/,C=/\.module\.(?:css|less|sass|scss|styl|stylus)(?:$|\?)/;function w(e){return e.replace(/(?:\.module)?(\.[cm]?js)$/,`.css`)}function T(e){let t=e.indexOf(`?`);return t===-1?e:e.slice(0,t)}const E={sass:`sass`,less:`less`,scss:`scss`,styl:`styl`,stylus:`stylus`};function D(e){let t=a.extname(e).slice(1);return E[t]}function O(e){let t=x.exec(e);if(t)return E[t[1]]}function k(e,t,n,r){switch(e){case`scss`:case`sass`:return R(e,t,n,r);case`less`:return G(t,n,r);case`styl`:case`stylus`:return ue(t,n,r)}}const A=/(?<!@import\s+)(?<=^|[^\w\-\u0080-\uFFFF])url\((\s*('[^']+'|"[^"]+")\s*|(?:\\.|[^'")\\])+)\)/,j=/(?<=^|[^\w\-\u0080-\uFFFF])data-uri\((\s*('[^']+'|"[^"]+")\s*|[^'")]+)\)/,M=/@import\s+(?:url\()?('[^']+\.css'|"[^"]+\.css"|[^'"\s)]+\.css)/;async function ne(e,t,n){e=a.resolve(e);let r=a.dirname(e),o=a.dirname(t);if(r===o)return{file:e};let s=await i(e,`utf8`),c=A.test(s),l=j.test(s),u=M.test(s);if(!c&&!l&&!u)return{file:e};let d,f=(e,t)=>{if(n?.(e,t))return!1;if(e[0]===`/`)return e;let i=a.resolve(r,e);return I(a.relative(o,i))};return u&&(d=await ae(s,f)),c&&(d=await re(d||s,f)),l&&(d=await ie(d||s,f)),{file:e,contents:d}}async function N(e,t,n){let r,i=e,a=``;for(;r=t.exec(i);)a+=i.slice(0,r.index),a+=await n(r),i=i.slice(r.index+r[0].length);return a+=i,a}function re(e,t){return N(e,A,async e=>{let[n,r]=e;return await P(r.trim(),n,t)})}function ie(e,t){return N(e,j,async e=>{let[n,r]=e;return await P(r.trim(),n,t,`data-uri`)})}function ae(e,t){return N(e,M,async e=>{let[n,r]=e;return await F(r,n,t)})}const oe=/^(?:[a-z]+:)?\/\//,se=/^\s*data:/i;function ce(e){return oe.test(e)||se.test(e)||e[0]===`#`}async function P(e,t,n,r=`url`){let i=``,a=e[0];if((a===`"`||a===`'`)&&(i=a,e=e.slice(1,-1)),ce(e))return t;let o=await n(e,t);return typeof o==`string`?(i===``&&o!==encodeURI(o)&&(i=`"`),`${r}(${i}${o}${i})`):t}async function F(e,t,n){let r=``,i=e[0];(i===`"`||i===`'`)&&(r=i,e=e.slice(1,-1));let a=await n(e,t);return typeof a==`string`?t.replace(`${r}${e}${r}`,`${r}${a}${r}`):t}function I(e){return e.replaceAll(`\\`,`/`)}async function L(e,t,n,r=``){if(!n)return e;if(typeof n==`function`){let r=await n(e,t);return typeof r==`string`?r:r.content}return n+r+e}async function R(e,t,n,r){let o=await W(),l=r?.scss??r?.sass??{},u=await L(t,n,l.additionalData),{additionalData:d,...f}=l,p=(e,t)=>t[0]!==`"`&&t[0]!==`'`&&e[0]===`$`||e.startsWith(`#{`),m={async canonicalize(e,t){let r=await z(e,t.containingUrl?s(t.containingUrl):n);return r?c(r):null},async load(e){let t=a.extname(e.pathname),r=`scss`;t===`.sass`?r=`indented`:t===`.css`&&(r=`css`);let o=await ne(s(e),n,p);return{contents:o.contents??await i(o.file,`utf8`),syntax:r,sourceMapUrl:e}}},h=await(await H(o)).compileStringAsync(u,{url:c(n),sourceMap:!1,syntax:e===`sass`?`indented`:`scss`,...f,importers:[m,...f.importers??[]]});return{code:h.css,deps:h.loadedUrls.filter(e=>e.protocol===`file:`).map(e=>s(e))}}async function z(e,t){let n=a.dirname(t),{existsSync:r}=await import(`node:fs`),i=[`.scss`,`.sass`,`.css`],o=[``,`_`];if(i.some(t=>e.endsWith(t)))for(let t of o){let i=a.resolve(n,a.dirname(e),t+a.basename(e));if(r(i))return i}else{for(let t of i)for(let i of o){let o=a.resolve(n,a.dirname(e),i+a.basename(e)+t);if(r(o))return o}for(let t of i)for(let i of o){let o=a.resolve(n,e,`${i}index${t}`);if(r(o))return o}}return y(v(),e,t)}let B,V;function H(e){return e.initAsyncCompiler?(V??=e.initAsyncCompiler().catch(e=>{throw V=void 0,e}),V):Promise.resolve(e)}async function U(){let e=V;V=void 0,await(await e?.catch(()=>void 0))?.dispose?.()}async function W(){if(B)return B;try{return B=await import(`sass-embedded`),B}catch{try{return B=await import(`sass`),B}catch{throw Error('Preprocessor dependency "sass" not found. Did you install it? Try `npm install -D sass`.')}}}async function G(e,t,n){let r=await le(),i=n?.less??{},a=await L(e,t,i.additionalData),{additionalData:o,plugins:s=[],...c}=i,l=await r.render(a,{paths:[`node_modules`],...c,filename:t,plugins:s});return{code:l.css,deps:l.imports||[]}}let K;async function le(){if(K)return K;try{return K=(await import(`less`)).default,K}catch{throw Error('Preprocessor dependency "less" not found. Did you install it? Try `npm install -D less`.')}}async function ue(e,t,n){let r=await de(),i=n?.styl??n?.stylus??{},a=await L(e,t,i.additionalData,`
|
|
3
|
+
`),{additionalData:o,define:s,...c}=i,l=r(a,{paths:[`node_modules`],...c,filename:t});if(s)for(let e of Object.keys(s))l.define(e,s[e]);return new Promise((e,t)=>{l.render((n,r)=>{n?t(Error(`[stylus] ${n.message}`)):e({code:r,deps:l.deps()})})})}let q;async function de(){if(q)return q;try{return q=(await import(`stylus`)).default,q}catch{throw Error('Preprocessor dependency "stylus" not found. Did you install it? Try `npm install -D stylus`.')}}const fe=new TextEncoder,J=new TextDecoder;async function Y(e,t,n){let r=n.lightningcss?.targets??(n.target?X(n.target):void 0);if(!r&&!n.lightningcss&&!n.minify&&!n.cssModules)return{code:e};let{transform:i}=await import(`lightningcss`),a=i({filename:t,code:fe.encode(e),...n.lightningcss,targets:r,minify:n.minify,cssModules:n.cssModules,sourceMap:n.sourceMap,inputSourceMap:n.inputSourceMap});return{code:J.decode(a.code),map:a.map?J.decode(a.map):void 0,modules:a.exports?h(a.exports):void 0}}async function pe(e,t,n){let r=t.lightningcss?.targets??(t.target?X(t.target):void 0),i=[],{bundleAsync:s}=await import(`lightningcss`),c=await s({filename:e,...t.lightningcss,targets:r,minify:t.minify,cssModules:t.cssModules,sourceMap:t.sourceMap,resolver:{async read(r){let a;a=n!=null&&r===e?n:o(r,`utf8`);let s=D(r);if(s){let e=await k(s,a,r,t.preprocessorOptions);return i.push(...e.deps),e.code}return a},resolve(e,n){return y(_(),e,n)||(t.logger.warn(`[@lzi-builder/css] Failed to resolve import '${e}' from '${n}'`),a.resolve(a.dirname(n),e))}}});return{code:J.decode(c.code),deps:i,map:c.map?J.decode(c.map):void 0,modules:c.exports?h(c.exports):void 0}}const me=/([a-z]+)(\d+(?:\.\d+)*)/g,he={chrome:`chrome`,edge:`edge`,firefox:`firefox`,ie:`ie`,ios:`ios_saf`,opera:`opera`,safari:`safari`};function ge(e){let[t,n=0,r=0]=e.split(`-`,1)[0].split(`.`).map(e=>Number.parseInt(e,10));return Number.isNaN(t)||Number.isNaN(n)||Number.isNaN(r)?null:t<<16|n<<8|r}function X(e){let t,n=[...e.join(` `).toLowerCase().matchAll(me)];for(let e of n){let n=e[1],r=he[n];if(!r)continue;let i=e[2],a=ge(i);a!=null&&(t||={},t[r]=a)}return t}function _e(e,t){let n=[];for(let r of Object.values(e))r.type!==`chunk`||r.exports.length||!r.moduleIds.length||r.moduleIds.every(e=>t.has(e))&&n.push(r.fileName);let r=new Set(n);for(let i of Object.values(e))i.type!==`chunk`||i.exports.length||i.isEntry||i.isDynamicEntry||r.has(i.fileName)||i.moduleIds.some(e=>t.has(e))&&be(i.code)&&n.push(i.fileName);if(!n.length)return;let i=ve(n);for(let t of Object.values(e)){if(t.type!==`chunk`)continue;let e=!1;t.imports=t.imports.filter(t=>n.includes(t)?(e=!0,!1):!0),e&&(t.code=i(t.code))}for(let t of n)delete e[t],delete e[`${t}.map`]}function ve(e){let t=e.map(e=>ye(a.basename(e))).join(`|`),n=new RegExp(String.raw`\bimport\s*["'][^"']*(?:${t})["'];`,`g`);return e=>e.replace(n,e=>`/* empty css ${``.padEnd(e.length-15)}*/`)}function ye(e){return e.replaceAll(/[.*+?^${}()|[\]\\]/g,String.raw`\$&`)}function be(e){return!e.replaceAll(/\/\*[\s\S]*?\*\//g,``).replaceAll(/\/\/[^\n]*/g,``).replaceAll(/\bexport\s*\{\s*\};?/g,``).replaceAll(/\bimport\s*["'][^"']*["'];?/g,``).trim()}function xe(e,t){let n=[];async function r(t){if(!e.minify)return t;let n=(await Y(t,u,{target:e.target,lightningcss:e.lightningcss,minify:!0})).code;return n.length&&!n.endsWith(`
|
|
4
|
+
`)&&(n+=`
|
|
5
|
+
`),n}return{name:`lzi-builder:css-post`,renderChunk(r,i){if(t.size===0||e.splitting)return;let a=``;for(let e of Object.keys(i.modules)){let n=t.get(e);n&&(a+=n)}a&&(a.length>0&&!a.endsWith(`
|
|
6
|
+
`)&&(a+=`
|
|
7
|
+
`),n.push(a))},async generateBundle(i,a){if(e.splitting)for(let e of Object.values(a)){if(e.type!==`chunk`)continue;let n=``;for(let r of e.moduleIds){let e=t.get(r);e&&(n+=e)}if(!n)continue;n.endsWith(`
|
|
8
|
+
`)||(n+=`
|
|
9
|
+
`),n=await r(n);let i=w(e.fileName);this.emitFile({type:`asset`,fileName:i,source:n})}else if(n.length>0){let t=n.join(``);t&&(t=await r(t),this.emitFile({type:`asset`,fileName:e.fileName,source:t,originalFileName:u})),n.length=0}_e(a,t)}}}const Z=new Map;async function Q(e){let t=Z.get(e);if(t!==void 0)return t;let n=(async()=>{try{let t=(await import(`postcss-load-config`)).default,n=await t({},e);return{options:n.options,plugins:n.plugins}}catch(e){if(e.message?.includes(`No PostCSS Config found`))return null;throw e}})();Z.set(e,n);let r=await n;return Z.set(e,r),r}function Se(e,t){if(typeof e==`object`){let{plugins:t,...n}=e;return{options:n,plugins:t||[]}}return Q(typeof e==`string`?e:t)}async function Ce(e,n,r,i,a,o,s){let c=await Se(r,i),l=[],u;if(o?.isModule){let e=await t(`postcss-modules`),{localsConvention:n,getJSON:r,...i}=o.config??{};l.push((e.default??e)({...i,getJSON(e,t,n){u=t,r?.(e,t,n)}}))}if(a){let e=await t(`postcss-import`);l.push((e.default??e)())}if(c&&l.push(...c.plugins),!l.length&&!c?.options.parser)return{code:e,deps:[]};let d=await(await t(`postcss`)).default(l).process(e,{...c?.options,from:n,to:n,map:s?{inline:!1,annotation:!1,prev:!1}:void 0}),f=[];for(let e of d.messages)if(e.type===`dependency`)f.push(e.file);else if(e.type===`dir-dependency`){let{dir:t}=e;typeof t==`string`&&f.push(t)}return{code:d.css,deps:f,map:d.map?.toString(),modules:u}}function $(e,t){let n=b.test(e);return e!==t&&!n&&x.test(t)}function we(e,{logger:t}){let n={css:d(e.css,e.target,e.unbundle),cwd:e.cwd,target:e.target,sourceMap:!!e.sourcemap},r=new Map,o=new Map,s={name:`@lzi-builder/css`,buildStart(){r.clear(),o.clear()},closeBundle(){if(!this.meta.watchMode)return U()},closeWatcher(){return U()},resolveId:{filter:{id:S},async handler(e,...t){let n=T(e),r=await this.resolve(n,...t);if(r)return{...r,id:`${r.id}?inline`}}},load:{filter:{id:S},async handler(e){let t=T(e);if(r.has(e))return;let n=await i(t,`utf8`).catch(()=>null);if(n!=null)return this.addWatchFile(t),{code:n,moduleType:`js`}}},transform:{filter:{id:x},async handler(e,r){let i=T(r);if($(r,i))return;let a=!b.test(r)&&n.css.modules!==!1&&C.test(r),s=[],c,l;if(n.css.transformer===`lightningcss`){let o=await Ee(e,r,i,s,n,t,a);e=o.code,c=o.modules,l=o.map}else{let t=await De(e,r,i,s,n,a);e=t.code,c=t.modules,l=t.map}for(let e of s)this.addWatchFile(e);if(e.length&&!e.endsWith(`
|
|
10
|
+
`)&&(e+=`
|
|
11
|
+
`),c){let e=typeof n.css.modules==`object`?n.css.modules:void 0;e?.localsConvention&&(c=m(c,e.localsConvention)),e?.getJSON?.(i,c,i),o.set(r,c)}return{code:e,map:l??null}}}},c=[{name:`@lzi-builder/css:collect`,transform:{filter:{id:x},handler(e,t){if($(t,T(t)))return;let n=b.test(t),i=o.get(t);return n?{code:`export default ${JSON.stringify(e)};`,map:null,moduleSideEffects:!1,moduleType:`js`}:(e.length&&r.set(t,e),i?{code:f(i),map:null,moduleSideEffects:!1,moduleType:`js`}:{code:``,map:null,moduleSideEffects:`no-treeshake`,moduleType:`js`})}}}];return n.css.inject&&c.push({name:`@lzi-builder/css:inject`,generateBundle(e,t){let i=Object.values(t),o=new Set;for(let e of i)if(!(e.type!==`chunk`||e.exports.length||!e.moduleIds.length)){if(e.moduleIds.every(e=>r.has(e))){o.add(e.fileName);continue}!e.isEntry&&!e.isDynamicEntry&&e.moduleIds.some(e=>r.has(e))&&Oe(e.code)&&o.add(e.fileName)}for(let e of i)if(e.type===`chunk`&&!o.has(e.fileName)){if(n.css.splitting){for(let t of e.imports){if(!o.has(t))continue;let n=a.basename(t),r=n.replaceAll(/[.*+?^${}()|[\]\\]/g,String.raw`\$&`),i=w(n),s=new RegExp(String.raw`(\bimport\s*["'][^"']*)${r}(["'];)`);e.code=e.code.replace(s,`$1${i}$2`)}if(e.moduleIds.some(e=>r.has(e))){let t=w(e.fileName),n=a.posix.relative(a.posix.dirname(e.fileName),t);e.code=`import '${n[0]===`.`?n:`./${n}`}';\n${e.code}`,e.map&&(e.map.mappings=`;${e.map.mappings}`)}}else if(e.moduleIds.some(e=>r.has(e))||e.imports.some(e=>o.has(e))){let t=n.css.fileName,r=a.posix.relative(a.posix.dirname(e.fileName),t);e.code=`import '${r[0]===`.`?r:`./${r}`}';\n${e.code}`,e.map&&(e.map.mappings=`;${e.map.mappings}`)}}}}),c.push(xe(n.css,r)),{pre:[s],post:c}}function Te(e,t,n){if(!t)return;let r=typeof e==`object`?e:void 0;if(!r)return!0;let i={};return typeof r.generateScopedName==`string`?i.pattern=r.generateScopedName:typeof r.generateScopedName==`function`&&n.warn('[@lzi-builder/css] `generateScopedName` as a function is not supported with `transformer: "lightningcss"`. Use a string pattern or switch to `transformer: "postcss"`.'),r.scopeBehaviour===`global`&&(i.pattern=`[local]`),Object.keys(i).length>0?i:!0}async function Ee(e,t,n,r,i,a,o){let s=O(t),c=Te(i.css.modules,o,a);if(s){let t=await k(s,e,n,i.css.preprocessorOptions);return r.push(...t.deps),Y(t.code,n,{target:i.css.target,lightningcss:i.css.lightningcss,minify:i.css.minify,cssModules:c,sourceMap:i.sourceMap})}if(t!==n&&!b.test(t))return Y(e,n,{target:i.css.target,lightningcss:i.css.lightningcss,minify:i.css.minify,cssModules:c,sourceMap:i.sourceMap});if(te.test(n)){let t=await pe(n,{target:i.css.target,lightningcss:i.css.lightningcss,minify:i.css.minify,cssModules:c,preprocessorOptions:i.css.preprocessorOptions,sourceMap:i.sourceMap,logger:a},e);return r.push(...t.deps),{code:t.code,map:t.map,modules:t.modules}}return{code:``}}async function De(e,t,n,r,i,a){let o=O(t);if(o){let t=await k(o,e,n,i.css.preprocessorOptions);e=t.code,r.push(...t.deps)}let s=typeof i.css.modules==`object`?i.css.modules:void 0,c=e.includes(`@import`),l=await Ce(e,n,i.css.postcss,i.cwd,c,a?{isModule:!0,config:s}:void 0,i.sourceMap);e=l.code,r.push(...l.deps);let u=await Y(e,n,{target:i.css.target,lightningcss:i.css.lightningcss,minify:i.css.minify,sourceMap:i.sourceMap,inputSourceMap:l.map});return{code:u.code,map:u.map??l.map,modules:l.modules}}function Oe(e){return!e.replaceAll(/\/\*[\s\S]*?\*\//g,``).replaceAll(/\/\/[^\n]*/g,``).replaceAll(/\bexport\s*\{\s*\};?/g,``).replaceAll(/\bimport\s*["'][^"']*["'];?/g,``).trim()}export{we as CssPlugin,d as resolveCssOptions};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-builder/css",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"exports": {
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
|
-
"build": "
|
|
19
|
-
"build:prod": "NODE_ENV=production
|
|
18
|
+
"build": "lzi-builder",
|
|
19
|
+
"build:prod": "NODE_ENV=production lzi-builder",
|
|
20
20
|
"prepublishOnly": "bun run build:prod",
|
|
21
21
|
"typecheck": "tsgo --noEmit",
|
|
22
22
|
"lint": "oxlint && oxfmt --check",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"rolldown": "^1.0.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@longzai-intelligence-builder/core": "0.2.
|
|
35
|
+
"@longzai-intelligence-builder/core": "0.2.13",
|
|
36
36
|
"postcss": "^8.4.0",
|
|
37
37
|
"postcss-import": "^16.0.0",
|
|
38
38
|
"postcss-modules": "^6.0.0",
|
|
@@ -55,5 +55,8 @@
|
|
|
55
55
|
"sass-embedded": {
|
|
56
56
|
"optional": true
|
|
57
57
|
}
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@longzai-intelligence-builder/esm": "0.2.13"
|
|
58
61
|
}
|
|
59
62
|
}
|