@pi-r/chrome 0.11.0 → 0.11.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/index.js +41 -48
- package/package.json +5 -5
- package/types/squared.d.ts +1 -1
package/index.js
CHANGED
|
@@ -21,10 +21,8 @@ const CACHE_CONTENT = new Map();
|
|
|
21
21
|
const CACHE_FORMAT = new Map();
|
|
22
22
|
const CACHE_DATASET = {};
|
|
23
23
|
const CACHE_ATRULES = {};
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
return [grouping + '*', grouping + '+'];
|
|
27
|
-
})();
|
|
24
|
+
const PATTERN_STRING_SOME = '(?:\\s|' + dom_1.DomWriter.PATTERN_COMMENT + '|`[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}`)*';
|
|
25
|
+
const PATTERN_STRING_MANY = PATTERN_STRING_SOME.slice(0, -1) + '+';
|
|
28
26
|
const [REGEXP_NTHCHILD, REGEXP_NTHCHILD_UNSAFE, REGEXP_REPLACECSS] = (function () {
|
|
29
27
|
const parenthesis = '(?:,[^()]+(?=\\))|[^()]|\\([^()]*\\(+|\\([^()]*\\)|(?:\\)[^()]+)?\\)*?)+';
|
|
30
28
|
return [
|
|
@@ -53,14 +51,6 @@ const REGEXP_FONTFACE_UNSAFE = new RegExp(`(\\s*)@font-face\\s*{([^}]+)}` + dom_
|
|
|
53
51
|
const REGEXP_FONTFAMILY_UNSAFE = /\bfont-family\s*:([^;}]+)/i;
|
|
54
52
|
const REGEXP_KEYFRAMES_UNSAFE = /(\s*)@keyframes\s+([^{]+){/gi;
|
|
55
53
|
const REGEXP_PROPERTY_UNSAFE = /(\s*)@property\s+(--[^\s]+)\s*{/gi;
|
|
56
|
-
const REGEXP_OBJECT_NAME = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
|
|
57
|
-
const REGEXP_OBJECT_SUBSCRIPT = /\[\s*(["'])?(.+?)\1\s*\]/g;
|
|
58
|
-
const REGEXP_TEMPLATE_LEADING = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
|
|
59
|
-
const REGEXP_TEMPLATE_TRAILING = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
|
|
60
|
-
const REGEXP_URL = /(?:\b[Uu][Rr][Ll]\(|@import\s+(["'])|\b([Hh][Rr][Ee][Ff])\s*=)/g;
|
|
61
|
-
const REGEXP_URL_JS = /\bimport\(/g;
|
|
62
|
-
const REGEXP_URL_SVG = /(?:\b[Uu][Rr][Ll]\(|@import\s+(["'])|\b([Hh][Rr][Ee][Ff])\s*=)/g;
|
|
63
|
-
const REGEXP_IMAGESET = /\b(?:-webkit-)?image-set\(/gi;
|
|
64
54
|
const REGEXP_IMAGESET_URL = /(?:^|[^(])\s*("(\s*[^)][^"]*)"|'(\s*[^)][^"]*)')\s*(?:,|$|[^)][^,]*,?)/gd;
|
|
65
55
|
const REGEXP_SANITIZEALL = new RegExp(`(?:\\s+|\\b)data-(?:pathname|filename|intl-locales|(?:use|exclude)-[^=\\s]+)\\s*${dom_1.DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g');
|
|
66
56
|
function removeNamespace(name, source, newline, comments) {
|
|
@@ -80,16 +70,17 @@ function removeNamespace(name, source, newline, comments) {
|
|
|
80
70
|
return (0, types_1.isArray)(comments) ? source.replace(REGEXP_BLOCKEXCLUDE, (...capture) => getNewlineString(capture[1], capture[2], newline)) : source;
|
|
81
71
|
}
|
|
82
72
|
function getObjectValue(value, key) {
|
|
83
|
-
|
|
73
|
+
const objectName = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
|
|
74
|
+
const subscript = /\[\s*(["'])?(.+?)\1\s*\]/g;
|
|
84
75
|
let found = false, match;
|
|
85
|
-
while (match =
|
|
76
|
+
while (match = objectName.exec(key)) {
|
|
86
77
|
if ((0, types_1.isObject)(value)) {
|
|
87
78
|
value = value[match[1]];
|
|
88
79
|
const name = match[2];
|
|
89
80
|
if (name) {
|
|
90
|
-
|
|
81
|
+
subscript.lastIndex = 0;
|
|
91
82
|
let index;
|
|
92
|
-
while (index =
|
|
83
|
+
while (index = subscript.exec(name)) {
|
|
93
84
|
const quote = index[1];
|
|
94
85
|
const attr = quote ? index[2] : index[2].trim();
|
|
95
86
|
if (quote && (0, types_1.isObject)(value) || /^\d+$/.test(attr) && (typeof value === 'string' || (0, types_1.isObject)(value))) {
|
|
@@ -110,14 +101,14 @@ function getObjectValue(value, key) {
|
|
|
110
101
|
return found ? value : null;
|
|
111
102
|
}
|
|
112
103
|
function trimTemplate(value) {
|
|
113
|
-
|
|
104
|
+
const opening = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
|
|
105
|
+
const closing = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
|
|
114
106
|
let match;
|
|
115
|
-
while (match =
|
|
116
|
-
value = replaceMatch(match, value, 1,
|
|
107
|
+
while (match = opening.exec(value)) {
|
|
108
|
+
value = replaceMatch(match, value, 1, opening);
|
|
117
109
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
value = replaceMatch(match, value, 1, REGEXP_TEMPLATE_TRAILING);
|
|
110
|
+
while (match = closing.exec(value)) {
|
|
111
|
+
value = replaceMatch(match, value, 1, closing);
|
|
121
112
|
}
|
|
122
113
|
return value;
|
|
123
114
|
}
|
|
@@ -3561,27 +3552,25 @@ class ChromeDocument extends Document {
|
|
|
3561
3552
|
const baseHref = collectBaseUrl(importFile || file, this.baseUrl);
|
|
3562
3553
|
const isHtml = type === 'html';
|
|
3563
3554
|
const isJs = type === 'js';
|
|
3564
|
-
const
|
|
3565
|
-
pattern
|
|
3566
|
-
REGEXP_IMAGESET.lastIndex = 0;
|
|
3555
|
+
const imageSet = /\b(?:-webkit-)?image-set\(/gi;
|
|
3556
|
+
const pattern = isJs ? /\bimport\(/g : type === 'svg' ? /(?:\b[Uu][Rr][Ll]\(|@import\s+(["'])|\b([Hh][Rr][Ee][Ff])\s*=)/g : /(?:\b[Uu][Rr][Ll]\(|@import\s+(["'])|\b([Hh][Rr][Ee][Ff])\s*=)/g;
|
|
3567
3557
|
let length = source.length, modified = false, match;
|
|
3568
|
-
while (match =
|
|
3558
|
+
while (match = imageSet.exec(source)) {
|
|
3569
3559
|
const startIndex = match.index + match[0].length;
|
|
3570
3560
|
const endIndex = findClosingIndex(source, startIndex, '(');
|
|
3571
|
-
if (endIndex
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
modified
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
modified = false;
|
|
3561
|
+
if (endIndex !== -1) {
|
|
3562
|
+
REGEXP_IMAGESET_URL.lastIndex = 0;
|
|
3563
|
+
let content = source.substring(startIndex, endIndex), url;
|
|
3564
|
+
while (url = REGEXP_IMAGESET_URL.exec(content)) {
|
|
3565
|
+
const quote = url[2] ? '"' : "'";
|
|
3566
|
+
const [a, b] = url.indices[1];
|
|
3567
|
+
content = (0, util_1.spliceString)(content, a, b, `url(${quote + (url[2] || url[3]).trim() + quote})`, REGEXP_IMAGESET_URL);
|
|
3568
|
+
modified = true;
|
|
3569
|
+
}
|
|
3570
|
+
if (modified) {
|
|
3571
|
+
source = (0, util_1.spliceString)(source, startIndex, endIndex, content, imageSet);
|
|
3572
|
+
modified = false;
|
|
3573
|
+
}
|
|
3585
3574
|
}
|
|
3586
3575
|
}
|
|
3587
3576
|
while (match = pattern.exec(source)) {
|
|
@@ -3705,7 +3694,7 @@ class ChromeDocument extends Document {
|
|
|
3705
3694
|
if (quote) {
|
|
3706
3695
|
value = quote + value + quote;
|
|
3707
3696
|
}
|
|
3708
|
-
const revised = isJs ?
|
|
3697
|
+
const revised = isJs ? `import(${value + trailing})` : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
3709
3698
|
source = (0, util_1.spliceString)(source, startIndex, i + 1, revised, pattern);
|
|
3710
3699
|
length = source.length;
|
|
3711
3700
|
modified = true;
|
|
@@ -3715,7 +3704,7 @@ class ChromeDocument extends Document {
|
|
|
3715
3704
|
if (!quote) {
|
|
3716
3705
|
continue;
|
|
3717
3706
|
}
|
|
3718
|
-
const target = new RegExp(
|
|
3707
|
+
const target = new RegExp(`^\\s*(${quote}((?:[^${quote}]|(?<=\\\\)${quote})+)${quote})\\s*(,.+)$`).exec(content);
|
|
3719
3708
|
if (target) {
|
|
3720
3709
|
url = target[1].trim();
|
|
3721
3710
|
trailing = target[2].trim();
|
|
@@ -3741,7 +3730,11 @@ class ChromeDocument extends Document {
|
|
|
3741
3730
|
else if (baseHref.length > 0) {
|
|
3742
3731
|
let fullUrl, asset;
|
|
3743
3732
|
for (const parentUrl of baseHref) {
|
|
3744
|
-
asset = host.findAsset(fullUrl = Document.resolvePath(url, parentUrl), { replaced: true })
|
|
3733
|
+
asset = host.findAsset(fullUrl = Document.resolvePath(url, parentUrl), { replaced: true });
|
|
3734
|
+
if (!asset) {
|
|
3735
|
+
const assets = this.related.get(file);
|
|
3736
|
+
asset = assets && host.findAsset(fullUrl, { assets: Array.from(assets), replaced: true });
|
|
3737
|
+
}
|
|
3745
3738
|
if (asset) {
|
|
3746
3739
|
break;
|
|
3747
3740
|
}
|
|
@@ -3772,16 +3765,16 @@ class ChromeDocument extends Document {
|
|
|
3772
3765
|
revised = this.processUrl(host, file, this.removeServerRoot(revised), type, asset) || revised;
|
|
3773
3766
|
source = (0, util_1.spliceString)(source, k, l + 1, revised, pattern);
|
|
3774
3767
|
length = source.length;
|
|
3775
|
-
if (
|
|
3776
|
-
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
3777
|
-
asset.invalid = true;
|
|
3778
|
-
}
|
|
3779
|
-
else {
|
|
3768
|
+
if (file.watch) {
|
|
3780
3769
|
related.push(asset);
|
|
3781
3770
|
if (!(0, types_1.existsFlag)(asset.flags)) {
|
|
3782
3771
|
asset.flags |= 8;
|
|
3783
3772
|
}
|
|
3784
3773
|
}
|
|
3774
|
+
else if (asset.localUri) {
|
|
3775
|
+
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
3776
|
+
asset.invalid = true;
|
|
3777
|
+
}
|
|
3785
3778
|
modified = true;
|
|
3786
3779
|
continue;
|
|
3787
3780
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1",
|
|
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.5",
|
|
24
|
+
"@e-mc/core": "^0.13.5",
|
|
25
|
+
"@e-mc/document": "^0.13.5",
|
|
26
|
+
"@e-mc/types": "^0.13.5",
|
|
27
27
|
"image-size": "^2.0.2"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/types/squared.d.ts
CHANGED
|
@@ -91,7 +91,7 @@ export interface UnusedAtRule {
|
|
|
91
91
|
selector?: string;
|
|
92
92
|
media?: ConditionProperty;
|
|
93
93
|
supports?: ConditionProperty;
|
|
94
|
-
container?: CssConditionData & Partial<ConditionProperty>;
|
|
94
|
+
container?: Omit<CssConditionData, "conditionText"> & Partial<ConditionProperty>;
|
|
95
95
|
layer?: string[];
|
|
96
96
|
}
|
|
97
97
|
|