@dimina-kit/compiler 0.0.2-dev.20260728080958 → 0.0.2-dev.20260728110120
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/compile-core.browser.js +14975 -16294
- package/dist/compile-core.node-chunks/chunk-2VRS523Z.js +8 -0
- package/dist/compile-core.node-chunks/chunk-LUD2P6RM.js +211 -0
- package/dist/compile-core.node-chunks/{chunk-M62ZDT7T.js → chunk-QJ34C5KK.js} +66 -542
- package/dist/compile-core.node-chunks/{logic-compiler-AEZPY2MO.js → logic-compiler-2SQFOFEO.js} +113 -37
- package/dist/compile-core.node-chunks/style-compiler-ZEJ3XLTS.js +277 -0
- package/dist/compile-core.node-chunks/{view-compiler-2SMUHAPD.js → view-compiler-WQNV7H5G.js} +161 -425
- package/dist/compile-core.node.js +6 -11
- package/dist/pool.node-chunks/{chunk-CKQISGZS.js → chunk-7FGOYOXU.js} +66 -542
- package/dist/pool.node-chunks/chunk-C7GEIDCP.js +211 -0
- package/dist/pool.node-chunks/chunk-KLXXOLDF.js +8 -0
- package/dist/pool.node-chunks/{chunk-WX4462A5.js → chunk-PDHO4Y56.js} +6 -11
- package/dist/pool.node-chunks/{logic-compiler-P4T4OMTG.js → logic-compiler-BODAINZQ.js} +113 -37
- package/dist/pool.node-chunks/style-compiler-TUNDVSR5.js +277 -0
- package/dist/pool.node-chunks/{view-compiler-2D7HPYIN.js → view-compiler-HOFFL63K.js} +161 -425
- package/dist/pool.node.js +2 -2
- package/dist/stage-worker.browser.js +2156 -3475
- package/dist/stage-worker.node.js +2 -2
- package/package.json +4 -4
- package/dist/compile-core.node-chunks/chunk-23PCGQQU.js +0 -141
- package/dist/compile-core.node-chunks/chunk-QYHGF3MS.js +0 -1601
- package/dist/compile-core.node-chunks/style-compiler-4PHMBQIC.js +0 -470
- package/dist/pool.node-chunks/chunk-LGB3AH5C.js +0 -1601
- package/dist/pool.node-chunks/chunk-VHWKAXDL.js +0 -141
- package/dist/pool.node-chunks/style-compiler-W7EA2Y7R.js +0 -470
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isMainThread,
|
|
3
|
+
parentPort
|
|
4
|
+
} from "./chunk-KLXXOLDF.js";
|
|
5
|
+
import {
|
|
6
|
+
collectAssets,
|
|
7
|
+
getAppId,
|
|
8
|
+
getComponent,
|
|
9
|
+
getContentByPath,
|
|
10
|
+
getStyleExts,
|
|
11
|
+
getTargetPath,
|
|
12
|
+
getWorkPath,
|
|
13
|
+
resetStoreInfo,
|
|
14
|
+
tagWhiteList,
|
|
15
|
+
transformRpx
|
|
16
|
+
} from "./chunk-7FGOYOXU.js";
|
|
17
|
+
|
|
18
|
+
// ../../dimina/fe/packages/compiler/src/core/style-compiler.js
|
|
19
|
+
import fs from "node:fs";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
import { compileStyle } from "@vue/compiler-sfc";
|
|
22
|
+
import autoprefixer from "autoprefixer";
|
|
23
|
+
import cssnano from "cssnano";
|
|
24
|
+
import less from "less";
|
|
25
|
+
import postcss from "postcss";
|
|
26
|
+
import selectorParser from "postcss-selector-parser";
|
|
27
|
+
import * as sass from "sass";
|
|
28
|
+
var compileRes = /* @__PURE__ */ new Map();
|
|
29
|
+
if (!isMainThread) {
|
|
30
|
+
parentPort.on("message", async ({ pages, storeInfo }) => {
|
|
31
|
+
try {
|
|
32
|
+
resetStoreInfo(storeInfo);
|
|
33
|
+
const progress = {
|
|
34
|
+
_completedTasks: 0,
|
|
35
|
+
get completedTasks() {
|
|
36
|
+
return this._completedTasks;
|
|
37
|
+
},
|
|
38
|
+
set completedTasks(value) {
|
|
39
|
+
this._completedTasks = value;
|
|
40
|
+
parentPort.postMessage({ completedTasks: this._completedTasks });
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
await compileSS(pages.mainPages, null, progress);
|
|
44
|
+
for (const [root, subPages] of Object.entries(pages.subPages)) {
|
|
45
|
+
await compileSS(subPages.info, root, progress);
|
|
46
|
+
}
|
|
47
|
+
compileRes.clear();
|
|
48
|
+
parentPort.postMessage({ success: true });
|
|
49
|
+
} catch (error) {
|
|
50
|
+
compileRes.clear();
|
|
51
|
+
parentPort.postMessage({
|
|
52
|
+
success: false,
|
|
53
|
+
error: {
|
|
54
|
+
message: error.message,
|
|
55
|
+
stack: error.stack,
|
|
56
|
+
name: error.name
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async function compileSS(pages, root, progress) {
|
|
63
|
+
for (const page of pages) {
|
|
64
|
+
const code = await buildCompileCss(page, [], /* @__PURE__ */ new Set()) || "";
|
|
65
|
+
const filename = `${page.path.replace(/\//g, "_")}`;
|
|
66
|
+
if (root) {
|
|
67
|
+
const subDir = `${getTargetPath()}/${root}`;
|
|
68
|
+
if (!fs.existsSync(subDir)) {
|
|
69
|
+
fs.mkdirSync(subDir, { recursive: true });
|
|
70
|
+
}
|
|
71
|
+
fs.writeFileSync(`${subDir}/${filename}.css`, code);
|
|
72
|
+
} else {
|
|
73
|
+
const mainDir = `${getTargetPath()}/main`;
|
|
74
|
+
if (!fs.existsSync(mainDir)) {
|
|
75
|
+
fs.mkdirSync(mainDir, { recursive: true });
|
|
76
|
+
}
|
|
77
|
+
fs.writeFileSync(`${mainDir}/${filename}.css`, code);
|
|
78
|
+
}
|
|
79
|
+
progress.completedTasks++;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function buildCompileCss(module, depthChain = [], compiledPaths = /* @__PURE__ */ new Set()) {
|
|
83
|
+
const currentPath = module.path || module.absolutePath;
|
|
84
|
+
if (depthChain.includes(currentPath)) {
|
|
85
|
+
console.warn("[style]", `\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
86
|
+
return "";
|
|
87
|
+
}
|
|
88
|
+
if (depthChain.length > 20) {
|
|
89
|
+
console.warn("[style]", `\u68C0\u6D4B\u5230\u6DF1\u5EA6\u4F9D\u8D56: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
90
|
+
return "";
|
|
91
|
+
}
|
|
92
|
+
if (compiledPaths.has(currentPath)) {
|
|
93
|
+
return "";
|
|
94
|
+
}
|
|
95
|
+
compiledPaths.add(currentPath);
|
|
96
|
+
depthChain = [...depthChain, currentPath];
|
|
97
|
+
let result = await enhanceCSS(module) || "";
|
|
98
|
+
if (module.usingComponents) {
|
|
99
|
+
for (const componentInfo of Object.values(module.usingComponents)) {
|
|
100
|
+
const componentModule = getComponent(componentInfo);
|
|
101
|
+
if (!componentModule) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
result += await buildCompileCss(componentModule, depthChain, compiledPaths) || "";
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
async function enhanceCSS(module) {
|
|
110
|
+
const absolutePath = module.absolutePath ? module.absolutePath : getAbsolutePath(module.path);
|
|
111
|
+
if (!absolutePath) {
|
|
112
|
+
return "";
|
|
113
|
+
}
|
|
114
|
+
const cacheKey = `${absolutePath}::${module.id || ""}`;
|
|
115
|
+
const inputCSS = getContentByPath(absolutePath);
|
|
116
|
+
if (!inputCSS) {
|
|
117
|
+
return "";
|
|
118
|
+
}
|
|
119
|
+
if (compileRes.has(cacheKey)) {
|
|
120
|
+
return compileRes.get(cacheKey);
|
|
121
|
+
}
|
|
122
|
+
let processedCSS = normalizeRootStyleImports(inputCSS);
|
|
123
|
+
const ext = path.extname(absolutePath).toLowerCase();
|
|
124
|
+
try {
|
|
125
|
+
if (ext === ".less") {
|
|
126
|
+
const result2 = await less.render(processedCSS, {
|
|
127
|
+
filename: absolutePath,
|
|
128
|
+
paths: [path.dirname(absolutePath), getWorkPath()]
|
|
129
|
+
});
|
|
130
|
+
processedCSS = result2.css;
|
|
131
|
+
} else if (ext === ".scss" || ext === ".sass") {
|
|
132
|
+
const result2 = sass.compileString(processedCSS, {
|
|
133
|
+
loadPaths: [path.dirname(absolutePath), getWorkPath()],
|
|
134
|
+
syntax: ext === ".sass" ? "indented" : "scss"
|
|
135
|
+
});
|
|
136
|
+
processedCSS = result2.css;
|
|
137
|
+
}
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error(`[style] \u9884\u5904\u7406\u5668\u7F16\u8BD1\u5931\u8D25 ${absolutePath}:`, error.message);
|
|
140
|
+
processedCSS = inputCSS;
|
|
141
|
+
}
|
|
142
|
+
const fixedCSS = ensureImportSemicolons(processedCSS);
|
|
143
|
+
let ast;
|
|
144
|
+
try {
|
|
145
|
+
ast = postcss.parse(fixedCSS);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error(`[style] PostCSS \u89E3\u6790\u5931\u8D25 ${absolutePath}:`, error.message);
|
|
148
|
+
return "";
|
|
149
|
+
}
|
|
150
|
+
const promises = [];
|
|
151
|
+
ast.walk(async (node) => {
|
|
152
|
+
if (node.type === "atrule" && node.name === "import") {
|
|
153
|
+
const str = node.params.replace(/^['"]|['"]$/g, "");
|
|
154
|
+
const importFullPath = resolveStyleImportPath(absolutePath, str);
|
|
155
|
+
node.remove();
|
|
156
|
+
promises.push(buildCompileCss({ absolutePath: importFullPath, id: module.id }, [], /* @__PURE__ */ new Set()));
|
|
157
|
+
} else if (node.type === "rule") {
|
|
158
|
+
if (node.selector.includes("::v-deep")) {
|
|
159
|
+
node.selector = node.selector.replace(/::v-deep\s+(\S[^{]*)/g, ":deep($1)");
|
|
160
|
+
}
|
|
161
|
+
if (node.selector.includes(":host")) {
|
|
162
|
+
node.selector = processHostSelector(node.selector, module.id);
|
|
163
|
+
}
|
|
164
|
+
node.selector = selectorParser((selectors) => {
|
|
165
|
+
selectors.walkTags((tag) => {
|
|
166
|
+
if (tagWhiteList.includes(tag.value)) {
|
|
167
|
+
tag.value = `.dd-${tag.value}`;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}).processSync(node.selector);
|
|
171
|
+
} else if (node.type === "comment") {
|
|
172
|
+
node.remove();
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
ast.walkDecls((decl) => {
|
|
176
|
+
decl.value = normalizeCssUrlValue(decl.value, absolutePath);
|
|
177
|
+
decl.value = transformRpx(decl.value);
|
|
178
|
+
});
|
|
179
|
+
const cssCode = ast.toResult().css;
|
|
180
|
+
const moduleId = module.id;
|
|
181
|
+
const scopedCode = compileStyle({
|
|
182
|
+
source: cssCode,
|
|
183
|
+
id: moduleId,
|
|
184
|
+
scoped: !!moduleId
|
|
185
|
+
}).code;
|
|
186
|
+
const cleanedCode = await removeBaseComponentScope(scopedCode, moduleId);
|
|
187
|
+
const res = await postcss([
|
|
188
|
+
autoprefixer({ overrideBrowserslist: ["cover 99.5%"] }),
|
|
189
|
+
cssnano()
|
|
190
|
+
]).process(cleanedCode, { from: void 0 });
|
|
191
|
+
const importCss = (await Promise.all(promises)).filter(Boolean).join("");
|
|
192
|
+
const result = importCss + res.css;
|
|
193
|
+
compileRes.set(cacheKey, result);
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
function normalizeCssUrlValue(value, absolutePath) {
|
|
197
|
+
return value.replace(/url\(([^)]+)\)/g, (fullMatch, rawUrl) => {
|
|
198
|
+
const cleanedUrl = rawUrl.trim().replace(/^['"]|['"]$/g, "");
|
|
199
|
+
if (!cleanedUrl || cleanedUrl.startsWith("data:image")) {
|
|
200
|
+
return fullMatch;
|
|
201
|
+
}
|
|
202
|
+
if (cleanedUrl.startsWith("//")) {
|
|
203
|
+
return `url(https:${cleanedUrl})`;
|
|
204
|
+
}
|
|
205
|
+
if (/^(https?:|blob:|data:)/.test(cleanedUrl)) {
|
|
206
|
+
return fullMatch;
|
|
207
|
+
}
|
|
208
|
+
const realSrc = collectAssets(getWorkPath(), absolutePath, cleanedUrl, getTargetPath(), getAppId());
|
|
209
|
+
return `url(${realSrc})`;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function getAbsolutePath(modulePath) {
|
|
213
|
+
const workPath = getWorkPath();
|
|
214
|
+
const src = modulePath.startsWith("/") ? modulePath : `/${modulePath}`;
|
|
215
|
+
for (const ssType of getStyleExts()) {
|
|
216
|
+
const ssFullPath = `${workPath}${src}${ssType}`;
|
|
217
|
+
if (fs.existsSync(ssFullPath)) {
|
|
218
|
+
return ssFullPath;
|
|
219
|
+
}
|
|
220
|
+
const indexSsFullPath = `${workPath}${src}/index${ssType}`;
|
|
221
|
+
if (fs.existsSync(indexSsFullPath)) {
|
|
222
|
+
return indexSsFullPath;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function resolveStyleImportPath(absolutePath, importPath, workPath = getWorkPath()) {
|
|
227
|
+
if (importPath.startsWith("/")) {
|
|
228
|
+
return path.join(workPath, importPath);
|
|
229
|
+
}
|
|
230
|
+
return path.resolve(path.dirname(absolutePath), importPath);
|
|
231
|
+
}
|
|
232
|
+
function normalizeRootStyleImports(source, workPath = getWorkPath()) {
|
|
233
|
+
return source.replace(/(@import\s+(?:\(.*?\)\s*)?(?:url\()?['"])(\/[^'")]+)(['"]\)?)/g, (_, prefix, importPath, suffix) => {
|
|
234
|
+
return `${prefix}${path.join(workPath, importPath)}${suffix}`;
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
async function removeBaseComponentScope(css, moduleId) {
|
|
238
|
+
if (!moduleId) return css;
|
|
239
|
+
const ast = postcss.parse(css);
|
|
240
|
+
const scopeAttrName = `data-v-${moduleId}`;
|
|
241
|
+
ast.walkRules((rule) => {
|
|
242
|
+
const hasBaseComponent = tagWhiteList.some(
|
|
243
|
+
(tag) => rule.selector.includes(`.dd-${tag}`)
|
|
244
|
+
);
|
|
245
|
+
if (hasBaseComponent && rule.selector.includes(scopeAttrName)) {
|
|
246
|
+
rule.selector = selectorParser((selectors) => {
|
|
247
|
+
selectors.walkAttributes((attr) => {
|
|
248
|
+
if (attr.attribute === scopeAttrName) {
|
|
249
|
+
attr.remove();
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}).processSync(rule.selector);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
return ast.toResult().css;
|
|
256
|
+
}
|
|
257
|
+
function ensureImportSemicolons(css) {
|
|
258
|
+
return css.replace(/@import[^;\n]*$/gm, (match) => {
|
|
259
|
+
return match.endsWith(";") ? match : `${match};`;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function processHostSelector(selector, moduleId) {
|
|
263
|
+
return selector.replace(/^:host$/, `[data-v-${moduleId}]`).replace(/:host\(([^)]+)\)/g, `[data-v-${moduleId}]$1`).replace(/:host\s+/g, `[data-v-${moduleId}] `).replace(/:host(?=\.|#|:)/g, `[data-v-${moduleId}]`);
|
|
264
|
+
}
|
|
265
|
+
function __resetStyleState() {
|
|
266
|
+
compileRes.clear();
|
|
267
|
+
}
|
|
268
|
+
export {
|
|
269
|
+
__resetStyleState,
|
|
270
|
+
compileSS,
|
|
271
|
+
ensureImportSemicolons,
|
|
272
|
+
normalizeCssUrlValue,
|
|
273
|
+
normalizeRootStyleImports,
|
|
274
|
+
processHostSelector,
|
|
275
|
+
removeBaseComponentScope,
|
|
276
|
+
resolveStyleImportPath
|
|
277
|
+
};
|