@dimina-kit/compiler 0.0.2-dev.20260718143821 → 0.0.2-dev.20260728065133

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.
Files changed (24) hide show
  1. package/dist/compile-core.browser.js +5130 -4282
  2. package/dist/compile-core.node-chunks/chunk-23PCGQQU.js +141 -0
  3. package/dist/compile-core.node-chunks/{chunk-QVEZ34FP.js → chunk-M62ZDT7T.js} +281 -21
  4. package/dist/compile-core.node-chunks/{chunk-6734LXNU.js → chunk-QYHGF3MS.js} +75 -4
  5. package/dist/compile-core.node-chunks/{logic-compiler-VJWEQMXZ.js → logic-compiler-AEZPY2MO.js} +26 -102
  6. package/dist/compile-core.node-chunks/style-compiler-4PHMBQIC.js +470 -0
  7. package/dist/compile-core.node-chunks/{view-compiler-3OUFRVZF.js → view-compiler-2SMUHAPD.js} +232 -109
  8. package/dist/compile-core.node.js +11 -6
  9. package/dist/pool.node-chunks/{chunk-7F3E2G42.js → chunk-CKQISGZS.js} +281 -21
  10. package/dist/pool.node-chunks/{chunk-DQNLDQGT.js → chunk-LGB3AH5C.js} +75 -4
  11. package/dist/pool.node-chunks/chunk-VHWKAXDL.js +141 -0
  12. package/dist/pool.node-chunks/{chunk-LKL7FBHG.js → chunk-WX4462A5.js} +11 -6
  13. package/dist/pool.node-chunks/{logic-compiler-HMMTJJWY.js → logic-compiler-P4T4OMTG.js} +26 -102
  14. package/dist/pool.node-chunks/style-compiler-W7EA2Y7R.js +470 -0
  15. package/dist/pool.node-chunks/{view-compiler-2VZMJ65O.js → view-compiler-2D7HPYIN.js} +232 -109
  16. package/dist/pool.node.js +2 -2
  17. package/dist/stage-worker.browser.js +5337 -4489
  18. package/dist/stage-worker.node.js +2 -2
  19. package/package.json +8 -7
  20. package/scripts/check-wasm-alignment.js +173 -0
  21. package/dist/compile-core.node-chunks/chunk-2VRS523Z.js +0 -8
  22. package/dist/compile-core.node-chunks/style-compiler-YWVITCJW.js +0 -288
  23. package/dist/pool.node-chunks/chunk-KLXXOLDF.js +0 -8
  24. package/dist/pool.node-chunks/style-compiler-VGVCLQ7X.js +0 -288
@@ -1,288 +0,0 @@
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-7F3E2G42.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, compiledPaths = /* @__PURE__ */ new Set()) {
83
- let result = "";
84
- const pendingModules = [module];
85
- while (pendingModules.length > 0) {
86
- const currentModule = pendingModules.pop();
87
- const currentPath = currentModule.path || currentModule.absolutePath;
88
- if (compiledPaths.has(currentPath)) {
89
- continue;
90
- }
91
- compiledPaths.add(currentPath);
92
- result += await enhanceCSS(currentModule) || "";
93
- const componentPaths = Object.values(currentModule.usingComponents || {});
94
- for (let index = componentPaths.length - 1; index >= 0; index--) {
95
- const componentModule = getComponent(componentPaths[index]);
96
- if (componentModule) {
97
- pendingModules.push(componentModule);
98
- }
99
- }
100
- }
101
- return result;
102
- }
103
- function boostExternalClassSelectors(cssCode, moduleId) {
104
- if (!moduleId || !cssCode) {
105
- return cssCode;
106
- }
107
- const scopeAttribute = `data-v-${moduleId}`;
108
- const externalScopeAttribute = "data-dd-external-class-scope";
109
- const ast = postcss.parse(cssCode);
110
- ast.walkRules((rule) => {
111
- if (!rule.selector.includes(`[${scopeAttribute}]`)) {
112
- return;
113
- }
114
- rule.selector = selectorParser((selectors) => {
115
- for (const selector of [...selectors.nodes]) {
116
- const boostedSelector = selector.clone();
117
- const scopeNodes = [];
118
- boostedSelector.walkAttributes((attribute) => {
119
- if (attribute.attribute === scopeAttribute) {
120
- scopeNodes.push(attribute);
121
- }
122
- });
123
- const targetScope = scopeNodes.at(-1);
124
- if (!targetScope) {
125
- continue;
126
- }
127
- targetScope.parent.insertAfter(targetScope, selectorParser.attribute({
128
- attribute: externalScopeAttribute,
129
- operator: "~=",
130
- quoteMark: '"',
131
- value: scopeAttribute
132
- }));
133
- selectors.append(boostedSelector);
134
- }
135
- }).processSync(rule.selector);
136
- });
137
- return ast.toResult().css;
138
- }
139
- async function enhanceCSS(module) {
140
- const absolutePath = module.absolutePath ? module.absolutePath : getAbsolutePath(module.path);
141
- if (!absolutePath) {
142
- return "";
143
- }
144
- const cacheKey = `${absolutePath}::${module.id || ""}`;
145
- const inputCSS = getContentByPath(absolutePath);
146
- if (!inputCSS) {
147
- return "";
148
- }
149
- if (compileRes.has(cacheKey)) {
150
- return compileRes.get(cacheKey);
151
- }
152
- let processedCSS = normalizeRootStyleImports(inputCSS);
153
- const ext = path.extname(absolutePath).toLowerCase();
154
- try {
155
- if (ext === ".less") {
156
- const result2 = await less.render(processedCSS, {
157
- filename: absolutePath,
158
- paths: [path.dirname(absolutePath), getWorkPath()]
159
- });
160
- processedCSS = result2.css;
161
- } else if (ext === ".scss" || ext === ".sass") {
162
- const result2 = sass.compileString(processedCSS, {
163
- loadPaths: [path.dirname(absolutePath), getWorkPath()],
164
- syntax: ext === ".sass" ? "indented" : "scss"
165
- });
166
- processedCSS = result2.css;
167
- }
168
- } catch (error) {
169
- console.error(`[style] \u9884\u5904\u7406\u5668\u7F16\u8BD1\u5931\u8D25 ${absolutePath}:`, error.message);
170
- processedCSS = inputCSS;
171
- }
172
- const fixedCSS = ensureImportSemicolons(processedCSS);
173
- let ast;
174
- try {
175
- ast = postcss.parse(fixedCSS);
176
- } catch (error) {
177
- console.error(`[style] PostCSS \u89E3\u6790\u5931\u8D25 ${absolutePath}:`, error.message);
178
- return "";
179
- }
180
- const promises = [];
181
- ast.walk(async (node) => {
182
- if (node.type === "atrule" && node.name === "import") {
183
- const str = node.params.replace(/^['"]|['"]$/g, "");
184
- const importFullPath = resolveStyleImportPath(absolutePath, str);
185
- node.remove();
186
- promises.push(buildCompileCss({ absolutePath: importFullPath, id: module.id }, /* @__PURE__ */ new Set()));
187
- } else if (node.type === "rule") {
188
- if (node.selector.includes("::v-deep")) {
189
- node.selector = node.selector.replace(/::v-deep\s+(\S[^{]*)/g, ":deep($1)");
190
- }
191
- if (node.selector.includes(":host")) {
192
- node.selector = processHostSelector(node.selector, module.id);
193
- }
194
- node.selector = selectorParser((selectors) => {
195
- selectors.walkTags((tag) => {
196
- if (tagWhiteList.includes(tag.value)) {
197
- tag.value = `.dd-${tag.value}`;
198
- }
199
- });
200
- }).processSync(node.selector);
201
- } else if (node.type === "comment") {
202
- node.remove();
203
- }
204
- });
205
- ast.walkDecls((decl) => {
206
- decl.value = normalizeCssUrlValue(decl.value, absolutePath);
207
- decl.value = transformRpx(decl.value);
208
- });
209
- const cssCode = ast.toResult().css;
210
- const moduleId = module.id;
211
- const scopedCode = compileStyle({
212
- source: cssCode,
213
- id: moduleId,
214
- scoped: !!moduleId
215
- }).code;
216
- const externalClassCode = boostExternalClassSelectors(scopedCode, moduleId);
217
- const res = await postcss([
218
- autoprefixer({ overrideBrowserslist: ["cover 99.5%"] }),
219
- cssnano()
220
- ]).process(externalClassCode, { from: void 0 });
221
- const importCss = (await Promise.all(promises)).filter(Boolean).join("");
222
- const result = importCss + res.css;
223
- compileRes.set(cacheKey, result);
224
- return result;
225
- }
226
- function normalizeCssUrlValue(value, absolutePath) {
227
- return value.replace(/url\(([^)]+)\)/g, (fullMatch, rawUrl) => {
228
- const cleanedUrl = rawUrl.trim().replace(/^['"]|['"]$/g, "");
229
- if (!cleanedUrl || cleanedUrl.startsWith("data:image")) {
230
- return fullMatch;
231
- }
232
- if (cleanedUrl.startsWith("//")) {
233
- return `url(https:${cleanedUrl})`;
234
- }
235
- if (/^(https?:|blob:|data:)/.test(cleanedUrl)) {
236
- return fullMatch;
237
- }
238
- const realSrc = collectAssets(getWorkPath(), absolutePath, cleanedUrl, getTargetPath(), getAppId());
239
- return `url(${realSrc})`;
240
- });
241
- }
242
- function getAbsolutePath(modulePath) {
243
- const workPath = getWorkPath();
244
- const src = modulePath.startsWith("/") ? modulePath : `/${modulePath}`;
245
- for (const ssType of getStyleExts()) {
246
- const ssFullPath = `${workPath}${src}${ssType}`;
247
- if (fs.existsSync(ssFullPath)) {
248
- return ssFullPath;
249
- }
250
- const indexSsFullPath = `${workPath}${src}/index${ssType}`;
251
- if (fs.existsSync(indexSsFullPath)) {
252
- return indexSsFullPath;
253
- }
254
- }
255
- }
256
- function resolveStyleImportPath(absolutePath, importPath, workPath = getWorkPath()) {
257
- if (importPath.startsWith("/")) {
258
- return path.join(workPath, importPath);
259
- }
260
- return path.resolve(path.dirname(absolutePath), importPath);
261
- }
262
- function normalizeRootStyleImports(source, workPath = getWorkPath()) {
263
- return source.replace(/(@import\s+(?:\(.*?\)\s*)?(?:url\()?['"])(\/[^'")]+)(['"]\)?)/g, (_, prefix, importPath, suffix) => {
264
- return `${prefix}${path.join(workPath, importPath)}${suffix}`;
265
- });
266
- }
267
- function ensureImportSemicolons(css) {
268
- return css.replace(/@import[^;\n]*$/gm, (match) => {
269
- return match.endsWith(";") ? match : `${match};`;
270
- });
271
- }
272
- function processHostSelector(selector, moduleId) {
273
- const hostSelector = `[data-dd-style-host~="${moduleId}"]`;
274
- return selector.replace(/:host\(([^)]+)\)/g, `${hostSelector}$1`).replace(/:host(?![\w-])/g, hostSelector);
275
- }
276
- function __resetStyleState() {
277
- compileRes.clear();
278
- }
279
- export {
280
- __resetStyleState,
281
- boostExternalClassSelectors,
282
- compileSS,
283
- ensureImportSemicolons,
284
- normalizeCssUrlValue,
285
- normalizeRootStyleImports,
286
- processHostSelector,
287
- resolveStyleImportPath
288
- };