chocola 1.3.9 → 1.3.11
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/compiler/component-processor.js +56 -9
- package/compiler/index.js +0 -1
- package/compiler/pipeline.js +0 -2
- package/package.json +1 -1
|
@@ -5,18 +5,63 @@ import chalk from "chalk";
|
|
|
5
5
|
import beautify from "js-beautify";
|
|
6
6
|
|
|
7
7
|
function scopeCss(cssString, cssId) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
function findMatchingBrace(s, openIndex) {
|
|
9
|
+
let depth = 0;
|
|
10
|
+
for (let i = openIndex; i < s.length; i++) {
|
|
11
|
+
const ch = s[i];
|
|
12
|
+
if (ch === '{') depth++;
|
|
13
|
+
else if (ch === '}') {
|
|
14
|
+
depth--;
|
|
15
|
+
if (depth === 0) return i;
|
|
16
|
+
}
|
|
11
17
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
return s.length - 1;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function processBlock(str) {
|
|
22
|
+
str = str.replaceAll(":root", `.${cssId}`);
|
|
23
|
+
|
|
24
|
+
let out = "";
|
|
25
|
+
let i = 0;
|
|
26
|
+
while (i < str.length) {
|
|
27
|
+
const braceIndex = str.indexOf('{', i);
|
|
28
|
+
if (braceIndex === -1) {
|
|
29
|
+
out += str.slice(i);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
const header = str.substring(i, braceIndex);
|
|
33
|
+
const endBrace = findMatchingBrace(str, braceIndex);
|
|
34
|
+
const inner = str.substring(braceIndex + 1, endBrace);
|
|
35
|
+
const innerScoped = processBlock(inner);
|
|
36
|
+
|
|
37
|
+
if (header.trim().startsWith("@")) {
|
|
38
|
+
out += header + "{" + innerScoped + "}";
|
|
39
|
+
} else {
|
|
40
|
+
const selectors = header
|
|
41
|
+
.split(",")
|
|
42
|
+
.map(s => s.trim())
|
|
43
|
+
.filter(Boolean);
|
|
44
|
+
const scopedHeader = selectors.length > 0
|
|
45
|
+
? selectors.map(sel => {
|
|
46
|
+
const s = sel.trim();
|
|
47
|
+
if (s.startsWith("." + cssId)) {
|
|
48
|
+
return s;
|
|
49
|
+
}
|
|
50
|
+
return `.${cssId} ${s}`;
|
|
51
|
+
}).join(", ")
|
|
52
|
+
: header;
|
|
53
|
+
out += scopedHeader + "{" + innerScoped + "}";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
i = endBrace + 1;
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return processBlock(cssString);
|
|
18
62
|
}
|
|
19
63
|
|
|
64
|
+
|
|
20
65
|
function interpolateNode(node, ctxProxy) {
|
|
21
66
|
if (node.nodeType === 3) {
|
|
22
67
|
node.textContent = node.textContent.replace(/\{([^}]+)\}/g, (_, expr) => {
|
|
@@ -150,6 +195,8 @@ export function processComponentElement(
|
|
|
150
195
|
if (!cssId) {
|
|
151
196
|
cssId = genRandomId(cssScopes, 8, true);
|
|
152
197
|
cssScopesMap.set(compName, cssId);
|
|
198
|
+
}
|
|
199
|
+
if (fragment.firstChild && fragment.firstChild.nodeType === 1) {
|
|
153
200
|
fragment.firstChild.classList.add(cssId);
|
|
154
201
|
}
|
|
155
202
|
style = scopeCss(style, cssId);
|
package/compiler/index.js
CHANGED
|
@@ -141,7 +141,6 @@ export default async function runtime(rootDir, buildConfig) {
|
|
|
141
141
|
const { runtimeScript, scopesCss } = processAllComponents(appElements, loadedComponents);
|
|
142
142
|
const runtimeFilename = await generateRuntimeScript(runtimeScript, paths.outDir);
|
|
143
143
|
const globalCss = (await processAssets(doc, rootDir, config.srcDir, paths.outDir)).join("\n");
|
|
144
|
-
console.log(globalCss)
|
|
145
144
|
|
|
146
145
|
if (scopesCss) {
|
|
147
146
|
const fileName = "sc-" + genRandomId(null, 6) + ".css";
|
package/compiler/pipeline.js
CHANGED
|
@@ -230,9 +230,7 @@ export async function copyResources(rootDir, scopesCss, globalCss, srcDir, outDi
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
console.log(globalCss)
|
|
234
233
|
const cssAssets = [...getCssAssets(scopesCss), ...getCssAssets(globalCss)];
|
|
235
|
-
console.log(cssAssets)
|
|
236
234
|
for (const assetPath of cssAssets) {
|
|
237
235
|
try {
|
|
238
236
|
const srcPath = path.join(rootDir, srcDir, assetPath);
|