@pi-r/chrome 0.10.5 → 0.10.6
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 +186 -184
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -59,7 +59,7 @@ const REGEXP_TEMPLATE_LEADING = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
|
|
|
59
59
|
const REGEXP_TEMPLATE_TRAILING = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
|
|
60
60
|
const REGEXP_URL = /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi;
|
|
61
61
|
const REGEXP_URL_JS = /\bimport\(/g;
|
|
62
|
-
const
|
|
62
|
+
const REGEXP_URL_CSS = /(?:\burl\(|@import\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');
|
|
@@ -3560,9 +3560,9 @@ class ChromeDocument extends Document {
|
|
|
3560
3560
|
processUrl(host, file, source, type, importFile) {
|
|
3561
3561
|
const related = [];
|
|
3562
3562
|
const baseHref = collectBaseUrl(importFile || file, this.baseUrl);
|
|
3563
|
-
const isHtml = type === 'html';
|
|
3563
|
+
const isHtml = type === 'html' || type === 'svg';
|
|
3564
3564
|
const isJs = type === 'js';
|
|
3565
|
-
const pattern = isJs ? REGEXP_URL_JS :
|
|
3565
|
+
const pattern = isJs ? REGEXP_URL_JS : !isHtml ? REGEXP_URL_CSS : REGEXP_URL;
|
|
3566
3566
|
pattern.lastIndex = 0;
|
|
3567
3567
|
REGEXP_IMAGESET.lastIndex = 0;
|
|
3568
3568
|
let length = source.length, modified = false, match;
|
|
@@ -3591,225 +3591,227 @@ class ChromeDocument extends Document {
|
|
|
3591
3591
|
const isUrl = !isText && !isHref;
|
|
3592
3592
|
const startIndex = match.index;
|
|
3593
3593
|
let quote = match[1], content = '', trailing = '', closed = -1, i = startIndex + match[0].length;
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
if (
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
}
|
|
3603
|
-
if (source[i - 1] !== '\\') {
|
|
3604
|
-
if (isText) {
|
|
3594
|
+
pass: {
|
|
3595
|
+
for (let j = -1; i < length; ++i) {
|
|
3596
|
+
const ch = source[i];
|
|
3597
|
+
if (quote && ch === quote) {
|
|
3598
|
+
if (!isText) {
|
|
3599
|
+
content += ch;
|
|
3600
|
+
}
|
|
3601
|
+
if (isHref) {
|
|
3605
3602
|
break;
|
|
3606
3603
|
}
|
|
3607
|
-
if (
|
|
3608
|
-
|
|
3604
|
+
if (source[i - 1] !== '\\') {
|
|
3605
|
+
if (isText) {
|
|
3606
|
+
break;
|
|
3607
|
+
}
|
|
3608
|
+
if (closed === -1) {
|
|
3609
|
+
closed = i + 1;
|
|
3610
|
+
}
|
|
3609
3611
|
}
|
|
3612
|
+
j = i + 1;
|
|
3613
|
+
continue;
|
|
3610
3614
|
}
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
break;
|
|
3615
|
+
if (!quote && (ch === '"' || ch === "'" || ch === '`' && isJs) && (isHref || !content.trim())) {
|
|
3616
|
+
quote = ch;
|
|
3617
|
+
}
|
|
3618
|
+
else if (isHref && (ch === '#' || !quote && isSpace(ch)) && content.trim()) {
|
|
3619
|
+
break pass;
|
|
3620
|
+
}
|
|
3621
|
+
else if (ch === ')') {
|
|
3622
|
+
if (isUrl) {
|
|
3623
|
+
if (quote && closed !== -1 || !quote && (isJs || source[i - 1] !== '\\')) {
|
|
3624
|
+
break;
|
|
3625
|
+
}
|
|
3626
|
+
j = i;
|
|
3624
3627
|
}
|
|
3625
|
-
j = i;
|
|
3626
3628
|
}
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3629
|
+
else if (j !== -1 && (ch === '\n' ||
|
|
3630
|
+
isText && (ch === ';' || ch === '{') ||
|
|
3631
|
+
isHref && (ch === '=' || ch === '>') ||
|
|
3632
|
+
isUrl && (ch === ';' ||
|
|
3633
|
+
!isJs && (!isHtml && (ch === ':' && !isJs || ch === '}') ||
|
|
3634
|
+
isHtml && (ch === '"' || ch === "'" || ch === ':' || ch === '>'))))) {
|
|
3635
|
+
if (closed !== -1) {
|
|
3636
|
+
i = closed;
|
|
3637
|
+
}
|
|
3638
|
+
else {
|
|
3639
|
+
content = content.substring(0, i = j);
|
|
3640
|
+
}
|
|
3641
|
+
break;
|
|
3636
3642
|
}
|
|
3637
|
-
|
|
3638
|
-
content
|
|
3643
|
+
if (closed === -1) {
|
|
3644
|
+
content += ch;
|
|
3639
3645
|
}
|
|
3640
|
-
break;
|
|
3641
|
-
}
|
|
3642
|
-
if (closed === -1) {
|
|
3643
|
-
content += ch;
|
|
3644
|
-
}
|
|
3645
|
-
}
|
|
3646
|
-
const setOutputURL = (value, asset) => {
|
|
3647
|
-
if (!value) {
|
|
3648
|
-
return;
|
|
3649
3646
|
}
|
|
3650
|
-
|
|
3651
|
-
if (!
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3647
|
+
const setOutputURL = (value, asset) => {
|
|
3648
|
+
if (!value) {
|
|
3649
|
+
return;
|
|
3650
|
+
}
|
|
3651
|
+
if (asset) {
|
|
3652
|
+
if (!asset.inlineBase64) {
|
|
3653
|
+
if (host.Cloud?.getStorage('upload', asset.cloudStorage)) {
|
|
3654
|
+
const inlineUrlCloud = asset.inlineUrlCloud ||= (0, node_crypto_1.randomUUID)();
|
|
3655
|
+
(file.inlineUrlCloudMap ||= {})[inlineUrlCloud] = value;
|
|
3656
|
+
value = inlineUrlCloud;
|
|
3657
|
+
}
|
|
3658
|
+
else if (asset.hash && this.productionRelease) {
|
|
3659
|
+
const inlineUrl = asset.inlineUrl ||= (0, node_crypto_1.randomUUID)();
|
|
3660
|
+
(file.inlineUrlMap ||= {})[inlineUrl] = value;
|
|
3661
|
+
value = inlineUrl;
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
const font = findFont(asset.format);
|
|
3665
|
+
if (font) {
|
|
3666
|
+
found: {
|
|
3667
|
+
for (let k = i + 1; k < length; ++k) {
|
|
3668
|
+
switch (source[k]) {
|
|
3669
|
+
case ')': {
|
|
3670
|
+
const component = source.substring(i + 1, k + 1);
|
|
3671
|
+
const format = /\s+format\([^)]+\)$/i.exec(component);
|
|
3672
|
+
if (format) {
|
|
3673
|
+
trailing = component.replace(format[0], ` format("${font}")`);
|
|
3674
|
+
i = k;
|
|
3675
|
+
break found;
|
|
3676
|
+
}
|
|
3677
|
+
break;
|
|
3675
3678
|
}
|
|
3676
|
-
|
|
3679
|
+
case ',':
|
|
3680
|
+
case ';':
|
|
3681
|
+
case ':':
|
|
3682
|
+
case '}':
|
|
3683
|
+
break found;
|
|
3677
3684
|
}
|
|
3678
|
-
case ',':
|
|
3679
|
-
case ';':
|
|
3680
|
-
case ':':
|
|
3681
|
-
case '}':
|
|
3682
|
-
break found;
|
|
3683
3685
|
}
|
|
3684
3686
|
}
|
|
3685
3687
|
}
|
|
3688
|
+
if (asset.initialValue && !asset.initialValue.cacheable) {
|
|
3689
|
+
file.flags |= 16;
|
|
3690
|
+
}
|
|
3691
|
+
related.push(asset);
|
|
3686
3692
|
}
|
|
3687
|
-
if (
|
|
3688
|
-
|
|
3693
|
+
if (!quote && !isHtml && !isJs) {
|
|
3694
|
+
if (!value.includes('"')) {
|
|
3695
|
+
quote = '"';
|
|
3696
|
+
}
|
|
3697
|
+
else if (!value.includes("'")) {
|
|
3698
|
+
quote = "'";
|
|
3699
|
+
}
|
|
3689
3700
|
}
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3701
|
+
if (isUrl) {
|
|
3702
|
+
const index = value.indexOf('#');
|
|
3703
|
+
if (index !== -1) {
|
|
3704
|
+
value = value.substring(0, index);
|
|
3705
|
+
}
|
|
3695
3706
|
}
|
|
3696
|
-
|
|
3697
|
-
|
|
3707
|
+
if (quote) {
|
|
3708
|
+
value = quote + value + quote;
|
|
3698
3709
|
}
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3710
|
+
const revised = isJs ? 'import(' + value + trailing + ')' : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
3711
|
+
source = (0, util_1.spliceString)(source, startIndex, i + 1, revised, pattern);
|
|
3712
|
+
length = source.length;
|
|
3713
|
+
modified = true;
|
|
3714
|
+
};
|
|
3715
|
+
let url;
|
|
3716
|
+
if (isJs) {
|
|
3717
|
+
if (!quote) {
|
|
3718
|
+
continue;
|
|
3719
|
+
}
|
|
3720
|
+
const target = new RegExp('^\\s*(' + quote + '((?:[^' + quote + ']|(?<=\\\\)' + quote + ')+)' + quote + ')\\s*(,.+)$').exec(content);
|
|
3721
|
+
if (target) {
|
|
3722
|
+
url = target[1].trim();
|
|
3723
|
+
trailing = target[2].trim();
|
|
3724
|
+
}
|
|
3725
|
+
else {
|
|
3726
|
+
url = (0, util_1.trimQuote)(content);
|
|
3704
3727
|
}
|
|
3705
|
-
}
|
|
3706
|
-
if (quote) {
|
|
3707
|
-
value = quote + value + quote;
|
|
3708
|
-
}
|
|
3709
|
-
const revised = isJs ? 'import(' + value + trailing + ')' : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
3710
|
-
source = (0, util_1.spliceString)(source, startIndex, i + 1, revised, pattern);
|
|
3711
|
-
length = source.length;
|
|
3712
|
-
modified = true;
|
|
3713
|
-
};
|
|
3714
|
-
let url;
|
|
3715
|
-
if (isJs) {
|
|
3716
|
-
if (!quote) {
|
|
3717
|
-
continue;
|
|
3718
|
-
}
|
|
3719
|
-
const target = new RegExp('^\\s*(' + quote + '((?:[^' + quote + ']|(?<=\\\\)' + quote + ')+)' + quote + ')\\s*(,.+)$').exec(content);
|
|
3720
|
-
if (target) {
|
|
3721
|
-
url = target[1].trim();
|
|
3722
|
-
trailing = target[2].trim();
|
|
3723
3728
|
}
|
|
3724
3729
|
else {
|
|
3725
3730
|
url = (0, util_1.trimQuote)(content);
|
|
3726
3731
|
}
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
if (item.base64 === base64) {
|
|
3736
|
-
setOutputURL(getSrcUrl(this, file, item)[0], item);
|
|
3737
|
-
break;
|
|
3732
|
+
if (url.startsWith('data:')) {
|
|
3733
|
+
const base64 = url.split(',')[1]?.trim();
|
|
3734
|
+
if (base64) {
|
|
3735
|
+
for (const item of this.assets) {
|
|
3736
|
+
if (item.base64 === base64) {
|
|
3737
|
+
setOutputURL(getSrcUrl(this, file, item)[0], item);
|
|
3738
|
+
break;
|
|
3739
|
+
}
|
|
3738
3740
|
}
|
|
3739
3741
|
}
|
|
3740
3742
|
}
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3743
|
+
else if (baseHref.length > 0) {
|
|
3744
|
+
let fullUrl, asset;
|
|
3745
|
+
for (const parentUrl of baseHref) {
|
|
3746
|
+
asset = host.findAsset(fullUrl = Document.resolvePath(url, parentUrl), { replaced: true }) || (this.related.has(file) ? host.findAsset(fullUrl, { assets: Array.from(this.related.get(file)), replaced: true }) : undefined);
|
|
3747
|
+
if (asset) {
|
|
3748
|
+
break;
|
|
3749
|
+
}
|
|
3748
3750
|
}
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
|
|
3758
|
-
}
|
|
3759
|
-
else {
|
|
3760
|
-
k = startIndex;
|
|
3761
|
-
}
|
|
3762
|
-
if (valid) {
|
|
3763
|
-
let l = i, revised = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
3764
|
-
for (let ch; l < length; ++l) {
|
|
3765
|
-
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
3766
|
-
break;
|
|
3767
|
-
}
|
|
3768
|
-
}
|
|
3769
|
-
const layer = this.replaceContent(revised, source.substring(k, l + 1), "text/css");
|
|
3770
|
-
if (layer) {
|
|
3771
|
-
revised = layer;
|
|
3772
|
-
}
|
|
3773
|
-
revised = this.processUrl(host, file, this.removeServerRoot(revised), type, asset) || revised;
|
|
3774
|
-
source = (0, util_1.spliceString)(source, k, l + 1, revised, pattern);
|
|
3775
|
-
length = source.length;
|
|
3776
|
-
if (!file.watch) {
|
|
3777
|
-
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
3778
|
-
asset.invalid = true;
|
|
3751
|
+
if (asset && asset !== importFile) {
|
|
3752
|
+
if (!(0, util_1.hasValue)(asset.format, 'base64')) {
|
|
3753
|
+
if (asset.bundleReplace) {
|
|
3754
|
+
let k = 0, valid = true;
|
|
3755
|
+
if (!isText) {
|
|
3756
|
+
let j = startIndex;
|
|
3757
|
+
while (isSpace(source[--j])) { }
|
|
3758
|
+
valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
|
|
3779
3759
|
}
|
|
3780
3760
|
else {
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3761
|
+
k = startIndex;
|
|
3762
|
+
}
|
|
3763
|
+
if (valid) {
|
|
3764
|
+
let l = i, revised = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
3765
|
+
for (let ch; l < length; ++l) {
|
|
3766
|
+
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
3767
|
+
break;
|
|
3768
|
+
}
|
|
3784
3769
|
}
|
|
3770
|
+
const layer = this.replaceContent(revised, source.substring(k, l + 1), "text/css");
|
|
3771
|
+
if (layer) {
|
|
3772
|
+
revised = layer;
|
|
3773
|
+
}
|
|
3774
|
+
revised = this.processUrl(host, file, this.removeServerRoot(revised), type, asset) || revised;
|
|
3775
|
+
source = (0, util_1.spliceString)(source, k, l + 1, revised, pattern);
|
|
3776
|
+
length = source.length;
|
|
3777
|
+
if (!file.watch) {
|
|
3778
|
+
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
3779
|
+
asset.invalid = true;
|
|
3780
|
+
}
|
|
3781
|
+
else {
|
|
3782
|
+
related.push(asset);
|
|
3783
|
+
if (!(0, types_1.existsFlag)(asset.flags)) {
|
|
3784
|
+
asset.flags |= 8;
|
|
3785
|
+
}
|
|
3786
|
+
}
|
|
3787
|
+
modified = true;
|
|
3788
|
+
continue;
|
|
3785
3789
|
}
|
|
3786
|
-
modified = true;
|
|
3787
|
-
continue;
|
|
3788
3790
|
}
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3791
|
+
if (hasSameOrigin(asset.url || fullUrl, ...baseHref)) {
|
|
3792
|
+
let sameDir = false;
|
|
3793
|
+
[fullUrl, sameDir] = getSrcUrl(this, file, asset);
|
|
3794
|
+
if (sameDir && isJs) {
|
|
3795
|
+
fullUrl = './' + fullUrl;
|
|
3796
|
+
}
|
|
3797
|
+
}
|
|
3798
|
+
else {
|
|
3799
|
+
const pathname = file.pathname;
|
|
3800
|
+
const count = pathname && pathname !== '/' ? pathname.split('/').length : 0;
|
|
3801
|
+
fullUrl = (count ? '../'.repeat(count) : '') + asset.relativeUrl;
|
|
3795
3802
|
}
|
|
3796
3803
|
}
|
|
3797
|
-
else {
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3804
|
+
else if (!asset.invalid) {
|
|
3805
|
+
fullUrl = asset.inlineBase64 ||= (0, node_crypto_1.randomUUID)();
|
|
3806
|
+
}
|
|
3807
|
+
if (url !== fullUrl) {
|
|
3808
|
+
setOutputURL(fullUrl, asset);
|
|
3801
3809
|
}
|
|
3802
3810
|
}
|
|
3803
|
-
else if (
|
|
3804
|
-
fullUrl
|
|
3805
|
-
}
|
|
3806
|
-
if (url !== fullUrl) {
|
|
3807
|
-
setOutputURL(fullUrl, asset);
|
|
3811
|
+
else if (importFile && url !== fullUrl) {
|
|
3812
|
+
setOutputURL(fullUrl);
|
|
3808
3813
|
}
|
|
3809
3814
|
}
|
|
3810
|
-
else if (importFile && url !== fullUrl) {
|
|
3811
|
-
setOutputURL(fullUrl);
|
|
3812
|
-
}
|
|
3813
3815
|
}
|
|
3814
3816
|
}
|
|
3815
3817
|
if (modified) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.6",
|
|
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.18",
|
|
24
|
+
"@e-mc/core": "^0.12.18",
|
|
25
|
+
"@e-mc/document": "^0.12.18",
|
|
26
|
+
"@e-mc/types": "^0.12.18",
|
|
27
27
|
"image-size": "^2.0.2"
|
|
28
28
|
}
|
|
29
29
|
}
|