@pi-r/chrome 0.10.3 → 0.10.4
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 +19 -25
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -30,12 +30,12 @@ const [REGEXP_NTHCHILD, REGEXP_NTHCHILD_UNSAFE, REGEXP_REPLACECSS] = (function (
|
|
|
30
30
|
return [
|
|
31
31
|
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'),
|
|
32
32
|
new RegExp(`\\(\\s*([+-])?(?:(\\d*)[nN]|(0))?\\s*([+-])?\\s*(\\d*)(?:\\s+[oO][fF]\\s+(${parenthesis})\\s*\\)|\\s*\\))`, 'g'),
|
|
33
|
-
new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')(\\s*layer(
|
|
33
|
+
new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')(\\s*layer(\\([^)]*\\))?)?(?:\\s*supports\\((${parenthesis})\\))?(.*)$`, 'si')
|
|
34
34
|
];
|
|
35
35
|
})();
|
|
36
36
|
const REGEXP_SRCSETSIZE = /~\s*([\d.]+)\s*([wx])/i;
|
|
37
|
-
const REGEXP_TEMPLATECONDITIONAL = /(\n\s+)?\{\{\s*if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)(
|
|
38
|
-
const REGEXP_TEMPLATEELSEIF = /\{\{\s*else if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)((
|
|
37
|
+
const REGEXP_TEMPLATECONDITIONAL = /(\n\s+)?\{\{\s*if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)([\S\s]*?)((?:\s*\{\{\s*else if\s+(?:(?:[^}]|}(?!}))+?)\}\}[\S\s]*?)*)(?:\s*\{\{\s*else\s*\}\}(\s*)([\S\s]*?))?\s*\{\{\s*end\s*\}\}/g;
|
|
38
|
+
const REGEXP_TEMPLATEELSEIF = /\{\{\s*else if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)((?:[\S\s](?!\{\{\s*else if))*)/g;
|
|
39
39
|
const REGEXP_TEMPLATECOMPARISON = /\s*\(\s*(?:(eq|ne|lt|le|gt|ge)\s+)?("[^"]+"|'[^']+'|[^\s)]+)(?:\s+("[^"]+"|'[^']+'|[^\s)]+))?\s*\)/g;
|
|
40
40
|
const REGEXP_TEMPLATEMATCH = new RegExp(`^(?:(and|or|not)\\s+)?((?:${REGEXP_TEMPLATECOMPARISON.source})+)|(!|not\\s+)?([^\\s][\\S\\s]*)$`);
|
|
41
41
|
const REGEXP_IMPORTMODULE = /(?:(?:^|[\n;]+)\s*import\s+(?:("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')|.+?from\s+("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')(?:[ \t]+with[ \t]+\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\})?)|\bimport\(\s*("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')\s*(?:,\s*\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\}\s*)?\))/gd;
|
|
@@ -57,9 +57,9 @@ const REGEXP_OBJECT_NAME = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
|
|
|
57
57
|
const REGEXP_OBJECT_SUBSCRIPT = /\[\s*(["'])?(.+?)\1\s*\]/g;
|
|
58
58
|
const REGEXP_TEMPLATE_LEADING = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
|
|
59
59
|
const REGEXP_TEMPLATE_TRAILING = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
|
|
60
|
-
const REGEXP_URL = /(?:\
|
|
60
|
+
const REGEXP_URL = /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi;
|
|
61
61
|
const REGEXP_URL_JS = /\bimport\(/g;
|
|
62
|
-
const REGEXP_URL_SVG = /(?:\
|
|
62
|
+
const REGEXP_URL_SVG = /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi;
|
|
63
63
|
const REGEXP_IMAGESET = /\b(?:-webkit-)?image-set\(/gi;
|
|
64
64
|
const REGEXP_IMAGESET_URL = /(?:^|[^(])\s*("(\s*[^)][^"]*)"|'(\s*[^)][^"]*)')\s*(?:,|$|[^)][^,]*,?)/gd;
|
|
65
65
|
const REGEXP_SANITIZEALL = new RegExp(`(?:\\s+|\\b)data-(?:pathname|filename|intl-locales|(?:use|exclude)-[^=\\s]+)\\s*${dom_1.DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g');
|
|
@@ -186,10 +186,6 @@ function parseArg(data, value) {
|
|
|
186
186
|
if (!isNaN(n)) {
|
|
187
187
|
return n;
|
|
188
188
|
}
|
|
189
|
-
const match = /^(["'])(.*)\1$/s.exec(value);
|
|
190
|
-
if (match) {
|
|
191
|
-
return match[2];
|
|
192
|
-
}
|
|
193
189
|
return getObjectValue(data, value);
|
|
194
190
|
}
|
|
195
191
|
function hasCondition(data, condition) {
|
|
@@ -206,7 +202,7 @@ function hasCondition(data, condition) {
|
|
|
206
202
|
if (items.length > 0 && !isSpace(match[0][0])) {
|
|
207
203
|
return false;
|
|
208
204
|
}
|
|
209
|
-
items.push([match[1], (0, util_1.trimQuote)(match[2]), (0, util_1.trimQuote)(match[3])]);
|
|
205
|
+
items.push([match[1], (0, util_1.trimQuote)(match[2]), match[3] ? (0, util_1.trimQuote)(match[3]) : '']);
|
|
210
206
|
}
|
|
211
207
|
REGEXP_TEMPLATECOMPARISON.lastIndex = 0;
|
|
212
208
|
const length = items.length;
|
|
@@ -214,12 +210,10 @@ function hasCondition(data, condition) {
|
|
|
214
210
|
return false;
|
|
215
211
|
}
|
|
216
212
|
for (let i = 0; i < length; ++i) {
|
|
217
|
-
const
|
|
218
|
-
const arg1 = item[1];
|
|
219
|
-
const arg2 = item[2];
|
|
213
|
+
const [cmp, arg1, arg2] = items[i];
|
|
220
214
|
let valid = false;
|
|
221
215
|
if (arg2) {
|
|
222
|
-
switch (
|
|
216
|
+
switch (cmp) {
|
|
223
217
|
case 'eq':
|
|
224
218
|
valid = parseArg(data, arg1) == parseArg(data, arg2);
|
|
225
219
|
break;
|
|
@@ -242,7 +236,7 @@ function hasCondition(data, condition) {
|
|
|
242
236
|
return false;
|
|
243
237
|
}
|
|
244
238
|
}
|
|
245
|
-
else if (
|
|
239
|
+
else if (cmp) {
|
|
246
240
|
return false;
|
|
247
241
|
}
|
|
248
242
|
else {
|
|
@@ -1414,7 +1408,7 @@ class ChromeDocument extends Document {
|
|
|
1414
1408
|
if (match) {
|
|
1415
1409
|
const layer = match[1];
|
|
1416
1410
|
const supports = match[3]?.trim();
|
|
1417
|
-
const query = match[4].trim();
|
|
1411
|
+
const query = match[4].trim().replace(/;+$/, '');
|
|
1418
1412
|
if (layer || supports || query) {
|
|
1419
1413
|
const newline = (0, util_1.getNewline)(source);
|
|
1420
1414
|
let result = supports ? `@supports (${supports}) {` + newline : '';
|
|
@@ -1422,8 +1416,8 @@ class ChromeDocument extends Document {
|
|
|
1422
1416
|
result += `@media ${query} {` + newline;
|
|
1423
1417
|
}
|
|
1424
1418
|
if (layer) {
|
|
1425
|
-
|
|
1426
|
-
result += '@layer ' + (name
|
|
1419
|
+
const name = match[2]?.replace(/\s+/g, '');
|
|
1420
|
+
result += '@layer ' + (name ? name.slice(1, -1) + ' ' : '') + `{${newline + source + newline}}` + (query ? newline + '}' : '');
|
|
1427
1421
|
}
|
|
1428
1422
|
else if (query) {
|
|
1429
1423
|
result += source + newline + '}';
|
|
@@ -2721,20 +2715,20 @@ class ChromeDocument extends Document {
|
|
|
2721
2715
|
segment = replaceMatch(match, segment, target[col] ? (!match[1] || target[col - 1].includes('\n') ? '' : match[1]) + target[col - 1] + target[col] : '', REGEXP_TEMPLATECONDITIONAL);
|
|
2722
2716
|
}
|
|
2723
2717
|
const literal = segment.trim();
|
|
2724
|
-
if (literal.
|
|
2718
|
+
if (literal.at(0) === '`' && literal.at(-1) === '`') {
|
|
2725
2719
|
if (!this.hasEval('function')) {
|
|
2726
2720
|
errors = (0, types_1.errorMessage)('eval', "Unsupported access", 'function');
|
|
2727
2721
|
continue;
|
|
2728
2722
|
}
|
|
2729
2723
|
try {
|
|
2730
|
-
let
|
|
2724
|
+
let unsafe = new Function('return ' + literal + ';').call(row);
|
|
2731
2725
|
if (!segment.startsWith('`')) {
|
|
2732
|
-
|
|
2726
|
+
unsafe = segment.substring(0, segment.indexOf('`')) + unsafe;
|
|
2733
2727
|
}
|
|
2734
2728
|
if (!segment.endsWith('`')) {
|
|
2735
|
-
|
|
2729
|
+
unsafe += segment.substring(segment.lastIndexOf('`') + 1);
|
|
2736
2730
|
}
|
|
2737
|
-
segment =
|
|
2731
|
+
segment = unsafe;
|
|
2738
2732
|
}
|
|
2739
2733
|
catch (err) {
|
|
2740
2734
|
errors = err instanceof Error ? err : true;
|
|
@@ -2968,7 +2962,7 @@ class ChromeDocument extends Document {
|
|
|
2968
2962
|
if (!empty && item.type !== 'display' || item.transactionFail) {
|
|
2969
2963
|
const emptyResponse = (value, service = item.source) => {
|
|
2970
2964
|
value ||= "Unknown";
|
|
2971
|
-
return errorDataSource(
|
|
2965
|
+
return errorDataSource(errors instanceof Error ? errors.message : service + ': Empty', value);
|
|
2972
2966
|
};
|
|
2973
2967
|
switch (item.source) {
|
|
2974
2968
|
case 'cloud': {
|
|
@@ -3755,7 +3749,7 @@ class ChromeDocument extends Document {
|
|
|
3755
3749
|
if (!isText) {
|
|
3756
3750
|
let j = startIndex;
|
|
3757
3751
|
while (isSpace(source[--j])) { }
|
|
3758
|
-
valid = source.substring(k = j - 6, j + 1) === '@import';
|
|
3752
|
+
valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
|
|
3759
3753
|
}
|
|
3760
3754
|
else {
|
|
3761
3755
|
k = startIndex;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
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.12.
|
|
24
|
-
"@e-mc/core": "^0.12.
|
|
25
|
-
"@e-mc/document": "^0.12.
|
|
26
|
-
"@e-mc/types": "^0.12.
|
|
23
|
+
"@e-mc/cloud": "^0.12.16",
|
|
24
|
+
"@e-mc/core": "^0.12.16",
|
|
25
|
+
"@e-mc/document": "^0.12.16",
|
|
26
|
+
"@e-mc/types": "^0.12.16",
|
|
27
27
|
"image-size": "^2.0.2"
|
|
28
28
|
}
|
|
29
29
|
}
|