chocola 1.3.11 → 1.4.1
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 +33 -17
- package/compiler/pipeline.js +2 -0
- package/package.json +1 -1
|
@@ -43,12 +43,12 @@ function scopeCss(cssString, cssId) {
|
|
|
43
43
|
.filter(Boolean);
|
|
44
44
|
const scopedHeader = selectors.length > 0
|
|
45
45
|
? selectors.map(sel => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
const s = sel.trim();
|
|
47
|
+
if (s.startsWith("." + cssId)) {
|
|
48
|
+
return s;
|
|
49
|
+
}
|
|
50
|
+
return `.${cssId} ${s}`;
|
|
51
|
+
}).join(", ")
|
|
52
52
|
: header;
|
|
53
53
|
out += scopedHeader + "{" + innerScoped + "}";
|
|
54
54
|
}
|
|
@@ -61,7 +61,6 @@ function scopeCss(cssString, cssId) {
|
|
|
61
61
|
return processBlock(cssString);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
65
64
|
function interpolateNode(node, ctxProxy) {
|
|
66
65
|
if (node.nodeType === 3) {
|
|
67
66
|
node.textContent = node.textContent.replace(/\{([^}]+)\}/g, (_, expr) => {
|
|
@@ -76,7 +75,6 @@ function interpolateNode(node, ctxProxy) {
|
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
|
|
80
78
|
/**
|
|
81
79
|
* Processes a single component element and inserts it into the DOM
|
|
82
80
|
* @param {Element} element
|
|
@@ -95,10 +93,16 @@ export function processComponentElement(
|
|
|
95
93
|
runtimeMap,
|
|
96
94
|
cssScopes,
|
|
97
95
|
cssScopesMap,
|
|
98
|
-
scopedStyles
|
|
96
|
+
scopedStyles,
|
|
97
|
+
renderChain = []
|
|
99
98
|
) {
|
|
100
99
|
const tagName = element.tagName.toLowerCase();
|
|
101
100
|
const compName = tagName + ".js";
|
|
101
|
+
const instance = loadedComponents.get(compName);
|
|
102
|
+
|
|
103
|
+
if (!instance || instance === undefined) return false;
|
|
104
|
+
if (renderChain && renderChain.includes(compName)) return false;
|
|
105
|
+
|
|
102
106
|
const ctx = extractContextFromElement(element);
|
|
103
107
|
const srcInnerHtml = element.innerHTML;
|
|
104
108
|
|
|
@@ -107,17 +111,21 @@ export function processComponentElement(
|
|
|
107
111
|
get(target, key) { return target[key]; }
|
|
108
112
|
});
|
|
109
113
|
|
|
110
|
-
const instance = loadedComponents.get(compName);
|
|
111
|
-
if (!instance || instance === undefined) return false;
|
|
112
|
-
|
|
113
114
|
if (instance.body) {
|
|
114
115
|
let body = instance.body;
|
|
115
116
|
|
|
116
117
|
const fragment = JSDOM.fragment(body);
|
|
118
|
+
|
|
119
|
+
const slotFragment = JSDOM.fragment(srcInnerHtml);
|
|
120
|
+
Array.from(fragment.querySelectorAll("slot")).forEach(slot => {
|
|
121
|
+
slot.replaceWith(slotFragment);
|
|
122
|
+
});
|
|
123
|
+
|
|
117
124
|
const children = Array.from(fragment.querySelectorAll("*"));
|
|
118
125
|
|
|
119
126
|
children.forEach(child => {
|
|
120
127
|
const reservedAttrs = ["if", "del-if"];
|
|
128
|
+
|
|
121
129
|
Array.from(child.attributes).forEach(attribute => {
|
|
122
130
|
if (!attribute || attribute === undefined) return;
|
|
123
131
|
if (reservedAttrs.includes(attribute.name)) return;
|
|
@@ -127,6 +135,19 @@ export function processComponentElement(
|
|
|
127
135
|
);
|
|
128
136
|
});
|
|
129
137
|
|
|
138
|
+
processComponentElement(
|
|
139
|
+
child,
|
|
140
|
+
loadedComponents,
|
|
141
|
+
runtimeChunks,
|
|
142
|
+
compIdColl,
|
|
143
|
+
letterState,
|
|
144
|
+
runtimeMap,
|
|
145
|
+
cssScopes,
|
|
146
|
+
cssScopesMap,
|
|
147
|
+
scopedStyles,
|
|
148
|
+
renderChain.concat(compName)
|
|
149
|
+
);
|
|
150
|
+
|
|
130
151
|
["if", "del-if"].forEach(statement => {
|
|
131
152
|
const statAtt = child.getAttribute(statement);
|
|
132
153
|
if (!statAtt) return;
|
|
@@ -184,11 +205,6 @@ export function processComponentElement(
|
|
|
184
205
|
}
|
|
185
206
|
}
|
|
186
207
|
|
|
187
|
-
const slotFragment = JSDOM.fragment(srcInnerHtml);
|
|
188
|
-
Array.from(fragment.querySelectorAll("slot")).forEach(slot => {
|
|
189
|
-
slot.replaceWith(slotFragment);
|
|
190
|
-
});
|
|
191
|
-
|
|
192
208
|
let style = instance.styles && instance.styles.toString();
|
|
193
209
|
if (style) {
|
|
194
210
|
let cssId = cssScopesMap && cssScopesMap.get(compName);
|
package/compiler/pipeline.js
CHANGED
|
@@ -103,6 +103,7 @@ export async function getSrcIndex(srcPath) {
|
|
|
103
103
|
export async function processStylesheet(link, rootDir, srcDir, outDirPath, fileIds) {
|
|
104
104
|
try {
|
|
105
105
|
const href = link.href;
|
|
106
|
+
if (href.startsWith("http://") || href.startsWith("https://")) return;
|
|
106
107
|
const stylesheetPath = path.join(rootDir, srcDir, href);
|
|
107
108
|
const css = await fs.readFile(stylesheetPath, { encoding: "utf8" });
|
|
108
109
|
const cssFileName = "css-" + genRandomId(fileIds, 6) + ".css";
|
|
@@ -233,6 +234,7 @@ export async function copyResources(rootDir, scopesCss, globalCss, srcDir, outDi
|
|
|
233
234
|
const cssAssets = [...getCssAssets(scopesCss), ...getCssAssets(globalCss)];
|
|
234
235
|
for (const assetPath of cssAssets) {
|
|
235
236
|
try {
|
|
237
|
+
if (assetPath.startsWith('http:') || assetPath.startsWith('https:')) continue;
|
|
236
238
|
const srcPath = path.join(rootDir, srcDir, assetPath);
|
|
237
239
|
const destPath = path.join(outDirPath, assetPath);
|
|
238
240
|
|