@pi-r/chrome 0.11.1 → 0.11.2
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/index.js +84 -86
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -28,7 +28,7 @@ const [REGEXP_NTHCHILD, REGEXP_NTHCHILD_UNSAFE, REGEXP_REPLACECSS] = (function (
|
|
|
28
28
|
return [
|
|
29
29
|
new RegExp(`\\(${PATTERN_STRING_SOME}([+-])?(?:(\\d*)[nN]|(0))?${PATTERN_STRING_SOME}([+-])?${PATTERN_STRING_SOME}(\\d*)(?:${PATTERN_STRING_MANY}[oO][fF]${PATTERN_STRING_MANY}(${parenthesis})${PATTERN_STRING_SOME}\\)|${PATTERN_STRING_SOME}\\))`, 'g'),
|
|
30
30
|
new RegExp(`\\(\\s*([+-])?(?:(\\d*)[nN]|(0))?\\s*([+-])?\\s*(\\d*)(?:\\s+[oO][fF]\\s+(${parenthesis})\\s*\\)|\\s*\\))`, 'g'),
|
|
31
|
-
new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')(\\s*layer(?:\\(([^)]
|
|
31
|
+
new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')(\\s*layer(?:\\(([^)]+)\\))?)?(?:\\s*supports\\((${parenthesis})\\))?(.*)$`)
|
|
32
32
|
];
|
|
33
33
|
})();
|
|
34
34
|
const REGEXP_SRCSETSIZE = /~\s*([\d.]+)\s*([wx])/i;
|
|
@@ -46,11 +46,11 @@ const REGEXP_FONTFACE = new RegExp(`(\\s*)@font-face${PATTERN_STRING_SOME}{([^}]
|
|
|
46
46
|
const REGEXP_FONTFAMILY = new RegExp(`\\bfont-family${PATTERN_STRING_SOME}:([^;}]+)`, 'i');
|
|
47
47
|
const REGEXP_KEYFRAMES = new RegExp(`(\\s*)@keyframes${PATTERN_STRING_MANY}([^{]+){`, 'gi');
|
|
48
48
|
const REGEXP_PROPERTY = new RegExp(`(\\s*)@property${PATTERN_STRING_MANY}(--[^\\s]+)${PATTERN_STRING_SOME}{`, 'gi');
|
|
49
|
-
const REGEXP_VARIABLES_UNSAFE = new RegExp(`(?<!style\\()(\\s*)(--[^\\s:]
|
|
49
|
+
const REGEXP_VARIABLES_UNSAFE = new RegExp(`(?<!style\\()(\\s*)(--[^\\s:]+)\\s*:[^;}]*([;}])` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'g');
|
|
50
50
|
const REGEXP_FONTFACE_UNSAFE = new RegExp(`(\\s*)@font-face\\s*{([^}]+)}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
|
|
51
51
|
const REGEXP_FONTFAMILY_UNSAFE = /\bfont-family\s*:([^;}]+)/i;
|
|
52
52
|
const REGEXP_KEYFRAMES_UNSAFE = /(\s*)@keyframes\s+([^{]+){/gi;
|
|
53
|
-
const REGEXP_PROPERTY_UNSAFE = /(\s*)@property\s+(
|
|
53
|
+
const REGEXP_PROPERTY_UNSAFE = /(\s*)@property\s+(--\S+)\s*{/gi;
|
|
54
54
|
const REGEXP_IMAGESET_URL = /(?:^|[^(])\s*("(\s*[^)][^"]*)"|'(\s*[^)][^"]*)')\s*(?:,|$|[^)][^,]*,?)/gd;
|
|
55
55
|
const REGEXP_SANITIZEALL = new RegExp(`(?:\\s+|\\b)data-(?:pathname|filename|intl-locales|(?:use|exclude)-[^=\\s]+)\\s*${dom_1.DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g');
|
|
56
56
|
function removeNamespace(name, source, newline, comments) {
|
|
@@ -1208,103 +1208,101 @@ class ChromeDocument extends Document {
|
|
|
1208
1208
|
}
|
|
1209
1209
|
resolveUri(file, source, trailing) {
|
|
1210
1210
|
const host = this.host;
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1211
|
+
switch (file.mimeType) {
|
|
1212
|
+
case "text/javascript":
|
|
1213
|
+
case "application/javascript":
|
|
1214
|
+
if (file.imports) {
|
|
1215
|
+
[[file.uri, source], [this.baseUrl, trailing]].forEach(([uri, code], index) => {
|
|
1216
|
+
let localFile;
|
|
1217
|
+
if (uri && code && (localFile = this.findSourceRoot(uri))) {
|
|
1218
|
+
const { exported, bundleId } = file;
|
|
1219
|
+
const bundleMain = !(0, types_1.isEmpty)(bundleId) && this.assets.find(item => item.bundleId === bundleId && item.bundleIndex === 0);
|
|
1220
|
+
let output;
|
|
1221
|
+
if ((index === 1 || exported) && Array.isArray(file.imports)) {
|
|
1222
|
+
output = this.resolveImports(file, code, bundleMain || file);
|
|
1223
|
+
}
|
|
1224
|
+
else if (index === 0 && !exported) {
|
|
1225
|
+
if (!Document.isDir(localFile)) {
|
|
1226
|
+
localFile = path.dirname(localFile);
|
|
1224
1227
|
}
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
const
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
if (asset) {
|
|
1243
|
-
const [relativeUrl, sameDir] = this.getSrcUrl(bundleMain || file, asset);
|
|
1244
|
-
if (relativeUrl) {
|
|
1245
|
-
output = (0, util_1.spliceString)(output, a, b, quote + (sameDir ? './' : '') + relativeUrl + quote, REGEXP_IMPORTMODULE);
|
|
1246
|
-
}
|
|
1228
|
+
output = code;
|
|
1229
|
+
let mainFile, pathname, match;
|
|
1230
|
+
const ignorePath = bundleMain && (mainFile = this.findSourceRoot(bundleMain.uri)) && (Document.isDir(mainFile) || (mainFile = path.dirname(mainFile))) && mainFile === localFile;
|
|
1231
|
+
while (match = REGEXP_IMPORTMODULE.exec(output)) {
|
|
1232
|
+
const type = match[3] || match[5];
|
|
1233
|
+
const idx = match[1] ? 1 : match[2] ? 2 : 4;
|
|
1234
|
+
const [a, b] = match.indices[idx];
|
|
1235
|
+
const from = (0, util_1.trimQuote)(match[idx]);
|
|
1236
|
+
const quote = output[a];
|
|
1237
|
+
const relative = /^\.{0,2}\//.test(from);
|
|
1238
|
+
if (type && /\btype\s*:\s*(["'`])(?:css|json)\1/.test(type)) {
|
|
1239
|
+
try {
|
|
1240
|
+
const asset = host.findAsset(relative ? new URL(from, uri) : from);
|
|
1241
|
+
if (asset) {
|
|
1242
|
+
const [relativeUrl, sameDir] = this.getSrcUrl(bundleMain || file, asset);
|
|
1243
|
+
if (relativeUrl) {
|
|
1244
|
+
output = (0, util_1.spliceString)(output, a, b, quote + (sameDir ? './' : '') + relativeUrl + quote, REGEXP_IMPORTMODULE);
|
|
1247
1245
|
}
|
|
1248
1246
|
}
|
|
1249
|
-
catch {
|
|
1250
|
-
}
|
|
1251
|
-
continue;
|
|
1252
1247
|
}
|
|
1253
|
-
|
|
1254
|
-
if (ignorePath) {
|
|
1255
|
-
continue;
|
|
1256
|
-
}
|
|
1257
|
-
pathname = path.join(localFile, from);
|
|
1248
|
+
catch {
|
|
1258
1249
|
}
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
pathname = asset.localUri;
|
|
1265
|
-
}
|
|
1266
|
-
if (pathname && Document.isPath(pathname)) {
|
|
1267
|
-
output = (0, util_1.spliceString)(output, a, b, quote + pathname + quote, REGEXP_IMPORTMODULE);
|
|
1250
|
+
continue;
|
|
1251
|
+
}
|
|
1252
|
+
if (relative) {
|
|
1253
|
+
if (ignorePath) {
|
|
1254
|
+
continue;
|
|
1268
1255
|
}
|
|
1256
|
+
pathname = path.join(localFile, from);
|
|
1269
1257
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1258
|
+
else if (!(pathname = this.findSourceRoot(from)) || !Document.isPath(pathname)) {
|
|
1259
|
+
const asset = host.findAsset(from);
|
|
1260
|
+
if (!asset || asset.invalid) {
|
|
1261
|
+
continue;
|
|
1262
|
+
}
|
|
1263
|
+
pathname = asset.localUri;
|
|
1275
1264
|
}
|
|
1276
|
-
|
|
1277
|
-
|
|
1265
|
+
if (pathname && Document.isPath(pathname)) {
|
|
1266
|
+
output = (0, util_1.spliceString)(output, a, b, quote + pathname + quote, REGEXP_IMPORTMODULE);
|
|
1278
1267
|
}
|
|
1279
1268
|
}
|
|
1269
|
+
REGEXP_IMPORTMODULE.lastIndex = 0;
|
|
1280
1270
|
}
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
if (!(0, types_1.isEmpty)(bundleId)) {
|
|
1288
|
-
for (const asset of this.assets) {
|
|
1289
|
-
if (asset.bundleIndex === 0 && asset.bundleId === bundleId) {
|
|
1290
|
-
const output = this.processUrl(host, file, source, 'css', asset);
|
|
1291
|
-
if (output) {
|
|
1292
|
-
source = output;
|
|
1293
|
-
file.modified = true;
|
|
1294
|
-
}
|
|
1295
|
-
break;
|
|
1271
|
+
if (output && output !== code) {
|
|
1272
|
+
if (index === 0) {
|
|
1273
|
+
source = output;
|
|
1274
|
+
}
|
|
1275
|
+
else {
|
|
1276
|
+
trailing = output;
|
|
1296
1277
|
}
|
|
1297
1278
|
}
|
|
1298
1279
|
}
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
break;
|
|
1283
|
+
case "text/css":
|
|
1284
|
+
if (file.editing) {
|
|
1285
|
+
const bundleId = file.bundleId;
|
|
1286
|
+
if (!(0, types_1.isEmpty)(bundleId)) {
|
|
1287
|
+
for (const asset of this.assets) {
|
|
1288
|
+
if (asset.bundleIndex === 0 && asset.bundleId === bundleId) {
|
|
1289
|
+
const output = this.processUrl(host, file, source, 'css', asset);
|
|
1290
|
+
if (output) {
|
|
1291
|
+
source = output;
|
|
1292
|
+
file.modified = true;
|
|
1293
|
+
}
|
|
1294
|
+
break;
|
|
1303
1295
|
}
|
|
1304
1296
|
}
|
|
1305
1297
|
}
|
|
1306
|
-
|
|
1307
|
-
|
|
1298
|
+
if (trailing && this.htmlFile) {
|
|
1299
|
+
const output = this.processUrl(host, file, trailing, 'css', this.htmlFile);
|
|
1300
|
+
if (output) {
|
|
1301
|
+
trailing = output;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
break;
|
|
1308
1306
|
}
|
|
1309
1307
|
return (trailing !== undefined ? [source, trailing] : source);
|
|
1310
1308
|
}
|
|
@@ -1371,7 +1369,7 @@ class ChromeDocument extends Document {
|
|
|
1371
1369
|
if (match) {
|
|
1372
1370
|
const layer = match[1];
|
|
1373
1371
|
const supports = match[3]?.trim();
|
|
1374
|
-
const query = match[4].trim();
|
|
1372
|
+
const query = match[4].trim().replace(/;+$/, '');
|
|
1375
1373
|
if (layer || supports || query) {
|
|
1376
1374
|
const newline = (0, util_1.getNewline)(source);
|
|
1377
1375
|
let result = supports ? `@supports (${supports}) {` + newline : '';
|
|
@@ -1379,8 +1377,8 @@ class ChromeDocument extends Document {
|
|
|
1379
1377
|
result += `@media ${query} {` + newline;
|
|
1380
1378
|
}
|
|
1381
1379
|
if (layer) {
|
|
1382
|
-
|
|
1383
|
-
result += '@layer ' + (name
|
|
1380
|
+
const name = match[2]?.trim();
|
|
1381
|
+
result += '@layer ' + (name ? name + ' ' : '') + `{${newline + source + newline}}` + (query ? newline + '}' : '');
|
|
1384
1382
|
}
|
|
1385
1383
|
else if (query) {
|
|
1386
1384
|
result += source + newline + '}';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "Chrome document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.13.
|
|
24
|
-
"@e-mc/core": "^0.13.
|
|
25
|
-
"@e-mc/document": "^0.13.
|
|
26
|
-
"@e-mc/types": "^0.13.
|
|
23
|
+
"@e-mc/cloud": "^0.13.9",
|
|
24
|
+
"@e-mc/core": "^0.13.9",
|
|
25
|
+
"@e-mc/document": "^0.13.9",
|
|
26
|
+
"@e-mc/types": "^0.13.9",
|
|
27
27
|
"image-size": "^2.0.2"
|
|
28
28
|
}
|
|
29
29
|
}
|