@pi-r/chrome 0.9.3 → 0.9.5
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 +24 -26
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -28,11 +28,11 @@ 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})\\))?(.*)$`, 'si')
|
|
32
32
|
];
|
|
33
33
|
})();
|
|
34
34
|
const REGEXP_SRCSETSIZE = /~\s*([\d.]+)\s*([wx])/i;
|
|
35
|
-
const REGEXP_TEMPLATECONDITIONAL = /(\n\s+)?\{\{if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)(
|
|
35
|
+
const REGEXP_TEMPLATECONDITIONAL = /(\n\s+)?\{\{if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)([\S\s]*?)(?:\s*\{\{else(?:\s+if\s+((?:[^}]|}(?!}))+?))?\}\}(\s*)([\S\s]*?)\s*)?\s*\{\{end\}\}/g;
|
|
36
36
|
const REGEXP_TEMPLATECOMPARISON = /\s*\(\s*(?:\b(eq|ne|lt|le|gt|ge)\s+)?("[^"]+"|'[^']+'|[^\s)]+)(?:\s+("[^"]+"|'[^']+'|[^\s)]+))?\s*\)/g;
|
|
37
37
|
const REGEXP_TEMPLATEMATCH = new RegExp(`^(?:\\b(and|or|not)\\s+)?((?:${REGEXP_TEMPLATECOMPARISON.source})+)|(!|not\\s+)?([^\\s][\\S\\s]*)$`);
|
|
38
38
|
const REGEXP_IMPORTMODULE = /(?:(?:^|[\n;]+)\s*import\s+(?:("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')|.+?from\s+("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')(?:[ \t]+(?:assert|with)[ \t]+\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\})?)|\bimport\(\s*("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')\s*(?:,\s*\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\}\s*)?\))/gd;
|
|
@@ -54,9 +54,9 @@ const REGEXP_OBJECT_NAME = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
|
|
|
54
54
|
const REGEXP_OBJECT_SUBSCRIPT = /\[\s*(["'])?(.+?)\1\s*\]/g;
|
|
55
55
|
const REGEXP_TEMPLATE_LEADING = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
|
|
56
56
|
const REGEXP_TEMPLATE_TRAILING = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
|
|
57
|
-
const REGEXP_URL = /(?:\
|
|
57
|
+
const REGEXP_URL = /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi;
|
|
58
58
|
const REGEXP_URL_JS = /\bimport\(/g;
|
|
59
|
-
const REGEXP_URL_SVG = /(?:\
|
|
59
|
+
const REGEXP_URL_SVG = /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi;
|
|
60
60
|
const REGEXP_IMAGESET = /\b(?:-webkit-)?image-set\(/gi;
|
|
61
61
|
const REGEXP_IMAGESET_URL = /(?:^|[^(])\s*("(\s*[^)][^"]*)"|'(\s*[^)][^"]*)')\s*(?:,|$|[^)][^,]*,?)/gd;
|
|
62
62
|
const REGEXP_SANITIZEALL = new RegExp(`(?:\\s+|\\b)data-(?:pathname|filename|intl-locales|(?:use|exclude)-[^=\\s]+)\\s*${dom_1.DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g');
|
|
@@ -189,10 +189,6 @@ function parseArg(data, value) {
|
|
|
189
189
|
if (!isNaN(n)) {
|
|
190
190
|
return n;
|
|
191
191
|
}
|
|
192
|
-
const match = /^(["'])(.*)\1$/s.exec(value);
|
|
193
|
-
if (match) {
|
|
194
|
-
return match[2];
|
|
195
|
-
}
|
|
196
192
|
return getObjectValue(data, value);
|
|
197
193
|
}
|
|
198
194
|
function hasCondition(data, condition) {
|
|
@@ -209,7 +205,7 @@ function hasCondition(data, condition) {
|
|
|
209
205
|
if (items.length > 0 && !isSpace(match[0][0])) {
|
|
210
206
|
return false;
|
|
211
207
|
}
|
|
212
|
-
items.push([match[1], trimQuote(match[2]), trimQuote(match[3])]);
|
|
208
|
+
items.push([match[1], trimQuote(match[2]), match[3] ? trimQuote(match[3]) : '']);
|
|
213
209
|
}
|
|
214
210
|
REGEXP_TEMPLATECOMPARISON.lastIndex = 0;
|
|
215
211
|
const length = items.length;
|
|
@@ -217,12 +213,10 @@ function hasCondition(data, condition) {
|
|
|
217
213
|
return false;
|
|
218
214
|
}
|
|
219
215
|
for (let i = 0; i < length; ++i) {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
const arg2 = item[2];
|
|
223
|
-
let valid;
|
|
216
|
+
const [cmp, arg1, arg2] = items[i];
|
|
217
|
+
let valid = false;
|
|
224
218
|
if (arg2) {
|
|
225
|
-
switch (
|
|
219
|
+
switch (cmp) {
|
|
226
220
|
case 'eq':
|
|
227
221
|
valid = parseArg(data, arg1) == parseArg(data, arg2);
|
|
228
222
|
break;
|
|
@@ -245,7 +239,7 @@ function hasCondition(data, condition) {
|
|
|
245
239
|
return false;
|
|
246
240
|
}
|
|
247
241
|
}
|
|
248
|
-
else if (
|
|
242
|
+
else if (cmp) {
|
|
249
243
|
return false;
|
|
250
244
|
}
|
|
251
245
|
else {
|
|
@@ -386,8 +380,12 @@ function getSrcURL(instance, parent, file) {
|
|
|
386
380
|
if (parentDir === assetDir) {
|
|
387
381
|
return [file.filename, true];
|
|
388
382
|
}
|
|
389
|
-
|
|
390
|
-
|
|
383
|
+
if (!parentDir) {
|
|
384
|
+
return [relativeUrl, false];
|
|
385
|
+
}
|
|
386
|
+
const splitPath = (value) => value.split(/\//).filter(seg => seg.trim());
|
|
387
|
+
const prefix = splitPath(parentDir);
|
|
388
|
+
const suffix = splitPath(assetDir);
|
|
391
389
|
let found = false;
|
|
392
390
|
while (prefix.length > 0 && suffix.length > 0 && prefix[0] === suffix[0]) {
|
|
393
391
|
prefix.shift();
|
|
@@ -592,7 +590,7 @@ function transformURL(instance, host, parent, type, source, importFile) {
|
|
|
592
590
|
if (!isText) {
|
|
593
591
|
let j = startIndex;
|
|
594
592
|
while (isSpace(source[--j])) { }
|
|
595
|
-
valid = source.substring(k = j - 6, j + 1) === '@import';
|
|
593
|
+
valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
|
|
596
594
|
}
|
|
597
595
|
else {
|
|
598
596
|
k = startIndex;
|
|
@@ -1823,7 +1821,7 @@ class ChromeDocument extends Document {
|
|
|
1823
1821
|
if (match) {
|
|
1824
1822
|
const layer = match[1];
|
|
1825
1823
|
const supports = match[3]?.trim();
|
|
1826
|
-
const query = match[4].trim();
|
|
1824
|
+
const query = match[4].trim().replace(/;+$/, '');
|
|
1827
1825
|
if (layer || supports || query) {
|
|
1828
1826
|
const newline = (0, util_1.getNewline)(source);
|
|
1829
1827
|
let result = supports ? `@supports (${supports}) {` + newline : '';
|
|
@@ -1831,8 +1829,8 @@ class ChromeDocument extends Document {
|
|
|
1831
1829
|
result += `@media ${query} {` + newline;
|
|
1832
1830
|
}
|
|
1833
1831
|
if (layer) {
|
|
1834
|
-
|
|
1835
|
-
result += '@layer ' + (name
|
|
1832
|
+
const name = match[2]?.replace(/\s+/g, '');
|
|
1833
|
+
result += '@layer ' + (name ? name.slice(1, -1) + ' ' : '') + `{${newline + source + newline}}` + (query ? newline + '}' : '');
|
|
1836
1834
|
}
|
|
1837
1835
|
else if (query) {
|
|
1838
1836
|
result += source + newline + '}';
|
|
@@ -3132,20 +3130,20 @@ class ChromeDocument extends Document {
|
|
|
3132
3130
|
}
|
|
3133
3131
|
REGEXP_TEMPLATECONDITIONAL.lastIndex = 0;
|
|
3134
3132
|
const literal = segment.trim();
|
|
3135
|
-
if (literal.
|
|
3133
|
+
if (literal.at(0) === '`' && literal.at(-1) === '`') {
|
|
3136
3134
|
if (!this.hasEval('function')) {
|
|
3137
3135
|
errors = (0, types_1.errorMessage)('eval', "Unsupported access", 'function');
|
|
3138
3136
|
continue;
|
|
3139
3137
|
}
|
|
3140
3138
|
try {
|
|
3141
|
-
let
|
|
3139
|
+
let unsafe = new Function('return ' + literal + ';').call(row);
|
|
3142
3140
|
if (!segment.startsWith('`')) {
|
|
3143
|
-
|
|
3141
|
+
unsafe = segment.substring(0, segment.indexOf('`')) + unsafe;
|
|
3144
3142
|
}
|
|
3145
3143
|
if (!segment.endsWith('`')) {
|
|
3146
|
-
|
|
3144
|
+
unsafe += segment.substring(segment.lastIndexOf('`') + 1);
|
|
3147
3145
|
}
|
|
3148
|
-
segment =
|
|
3146
|
+
segment = unsafe;
|
|
3149
3147
|
}
|
|
3150
3148
|
catch (err) {
|
|
3151
3149
|
errors = err instanceof Error ? err : true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "Chrome document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.11.
|
|
24
|
-
"@e-mc/core": "^0.11.
|
|
25
|
-
"@e-mc/document": "^0.11.
|
|
26
|
-
"@e-mc/types": "^0.11.
|
|
23
|
+
"@e-mc/cloud": "^0.11.17",
|
|
24
|
+
"@e-mc/core": "^0.11.17",
|
|
25
|
+
"@e-mc/document": "^0.11.17",
|
|
26
|
+
"@e-mc/types": "^0.11.17"
|
|
27
27
|
}
|
|
28
28
|
}
|