@pi-r/chrome 0.11.3 → 0.11.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 +197 -190
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -2443,13 +2443,15 @@ class ChromeDocument extends Document {
|
|
|
2443
2443
|
case 'mongodb':
|
|
2444
2444
|
for (let j = 0; j < length; ++j) {
|
|
2445
2445
|
const cmd = batch[j];
|
|
2446
|
-
|
|
2446
|
+
if (cmd.cascade) {
|
|
2447
|
+
cmd.cacheObjectKey ||= cmd.cascade;
|
|
2448
|
+
}
|
|
2447
2449
|
}
|
|
2448
2450
|
break;
|
|
2449
2451
|
case 'redis':
|
|
2450
2452
|
for (let j = 0; j < length; ++j) {
|
|
2451
2453
|
const cmd = batch[j];
|
|
2452
|
-
const
|
|
2454
|
+
const search = cmd.search;
|
|
2453
2455
|
if ((0, types_1.isObject)(search) && typeof search.schema === 'string') {
|
|
2454
2456
|
const pathname = this.resolveDir('schema', search.schema);
|
|
2455
2457
|
if (pathname) {
|
|
@@ -2476,8 +2478,11 @@ class ChromeDocument extends Document {
|
|
|
2476
2478
|
search.schema = undefined;
|
|
2477
2479
|
}
|
|
2478
2480
|
}
|
|
2479
|
-
if (key) {
|
|
2480
|
-
|
|
2481
|
+
if (cmd.key) {
|
|
2482
|
+
const { cascade, query } = cmd;
|
|
2483
|
+
if (cascade || query) {
|
|
2484
|
+
cmd.cacheObjectKey ||= (cascade ? cascade : '') + '_' + (query ? Document.asString(query, true) : '');
|
|
2485
|
+
}
|
|
2481
2486
|
}
|
|
2482
2487
|
}
|
|
2483
2488
|
break;
|
|
@@ -3542,10 +3547,10 @@ class ChromeDocument extends Document {
|
|
|
3542
3547
|
processUrl(host, file, source, type, importFile) {
|
|
3543
3548
|
const related = [];
|
|
3544
3549
|
const baseHref = collectBaseUrl(importFile || file, this.baseUrl);
|
|
3545
|
-
const isHtml = type === 'html';
|
|
3550
|
+
const isHtml = type === 'html' || type === 'svg';
|
|
3546
3551
|
const isJs = type === 'js';
|
|
3547
3552
|
const imageSet = /\b(?:-webkit-)?image-set\(/gi;
|
|
3548
|
-
const pattern = isJs ? /\b(?<!-)import\(/g :
|
|
3553
|
+
const pattern = isJs ? /\b(?<!-)import\(/g : !isHtml ? /(?:\b(?<!-)url\(|@import\s+(["']))/gi : /(?:\b(?<!-)url\(|@import\s+(["'])|\b(?<!-)(href)\s*=)/gi;
|
|
3549
3554
|
let length = source.length, modified = false, match;
|
|
3550
3555
|
while (match = imageSet.exec(source)) {
|
|
3551
3556
|
const startIndex = match.index + match[0].length;
|
|
@@ -3571,229 +3576,231 @@ class ChromeDocument extends Document {
|
|
|
3571
3576
|
const isUrl = !isText && !isHref;
|
|
3572
3577
|
const startIndex = match.index;
|
|
3573
3578
|
let quote = match[1], content = '', trailing = '', closed = -1, i = startIndex + match[0].length;
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
if (
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
}
|
|
3583
|
-
if (source[i - 1] !== '\\') {
|
|
3584
|
-
if (isText) {
|
|
3579
|
+
pass: {
|
|
3580
|
+
for (let j = -1; i < length; ++i) {
|
|
3581
|
+
const ch = source[i];
|
|
3582
|
+
if (quote && ch === quote) {
|
|
3583
|
+
if (!isText) {
|
|
3584
|
+
content += ch;
|
|
3585
|
+
}
|
|
3586
|
+
if (isHref) {
|
|
3585
3587
|
break;
|
|
3586
3588
|
}
|
|
3587
|
-
if (
|
|
3588
|
-
|
|
3589
|
+
if (source[i - 1] !== '\\') {
|
|
3590
|
+
if (isText) {
|
|
3591
|
+
break;
|
|
3592
|
+
}
|
|
3593
|
+
if (closed === -1) {
|
|
3594
|
+
closed = i + 1;
|
|
3595
|
+
}
|
|
3589
3596
|
}
|
|
3597
|
+
j = i + 1;
|
|
3598
|
+
continue;
|
|
3590
3599
|
}
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
break;
|
|
3600
|
+
if (!quote && (ch === '"' || ch === "'" || ch === '`' && isJs) && (isHref || !content.trim())) {
|
|
3601
|
+
quote = ch;
|
|
3602
|
+
}
|
|
3603
|
+
else if (isHref && (ch === '#' || !quote && isSpace(ch)) && content.trim()) {
|
|
3604
|
+
break pass;
|
|
3605
|
+
}
|
|
3606
|
+
else if (ch === ')') {
|
|
3607
|
+
if (isUrl) {
|
|
3608
|
+
if (quote && closed !== -1 || !quote && (isJs || source[i - 1] !== '\\')) {
|
|
3609
|
+
break;
|
|
3610
|
+
}
|
|
3611
|
+
j = i;
|
|
3604
3612
|
}
|
|
3605
|
-
j = i;
|
|
3606
3613
|
}
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3614
|
+
else if (j !== -1 && (ch === '\n' ||
|
|
3615
|
+
isText && (ch === ';' || ch === '{') ||
|
|
3616
|
+
isHref && (ch === '=' || ch === '>') ||
|
|
3617
|
+
isUrl && (ch === ';' ||
|
|
3618
|
+
!isJs && (!isHtml && (ch === ':' && !isJs || ch === '}') ||
|
|
3619
|
+
isHtml && (ch === '"' || ch === "'" || ch === ':' || ch === '>'))))) {
|
|
3620
|
+
if (closed !== -1) {
|
|
3621
|
+
i = closed;
|
|
3622
|
+
}
|
|
3623
|
+
else {
|
|
3624
|
+
content = content.substring(0, i = j);
|
|
3625
|
+
}
|
|
3626
|
+
break;
|
|
3616
3627
|
}
|
|
3617
|
-
|
|
3618
|
-
content
|
|
3628
|
+
if (closed === -1) {
|
|
3629
|
+
content += ch;
|
|
3619
3630
|
}
|
|
3620
|
-
break;
|
|
3621
|
-
}
|
|
3622
|
-
if (closed === -1) {
|
|
3623
|
-
content += ch;
|
|
3624
3631
|
}
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
}
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3632
|
+
const setOutputURL = (value, asset) => {
|
|
3633
|
+
if (!value) {
|
|
3634
|
+
return;
|
|
3635
|
+
}
|
|
3636
|
+
if (asset) {
|
|
3637
|
+
if (!asset.inlineBase64) {
|
|
3638
|
+
if (host.Cloud?.getStorage('upload', asset.cloudStorage)) {
|
|
3639
|
+
const inlineUrlCloud = asset.inlineUrlCloud ||= (0, node_crypto_1.randomUUID)();
|
|
3640
|
+
(file.inlineUrlCloudMap ||= {})[inlineUrlCloud] = value;
|
|
3641
|
+
value = inlineUrlCloud;
|
|
3642
|
+
}
|
|
3643
|
+
else if (asset.hash && this.productionRelease) {
|
|
3644
|
+
const inlineUrl = asset.inlineUrl ||= (0, node_crypto_1.randomUUID)();
|
|
3645
|
+
(file.inlineUrlMap ||= {})[inlineUrl] = value;
|
|
3646
|
+
value = inlineUrl;
|
|
3647
|
+
}
|
|
3648
|
+
}
|
|
3649
|
+
const font = findFont(asset.format);
|
|
3650
|
+
if (font) {
|
|
3651
|
+
found: {
|
|
3652
|
+
for (let k = i + 1; k < length; ++k) {
|
|
3653
|
+
switch (source[k]) {
|
|
3654
|
+
case ')': {
|
|
3655
|
+
const component = source.substring(i + 1, k + 1);
|
|
3656
|
+
const format = /\s+format\([^)]+\)$/i.exec(component);
|
|
3657
|
+
if (format) {
|
|
3658
|
+
trailing = component.replace(format[0], ` format("${font}")`);
|
|
3659
|
+
i = k;
|
|
3660
|
+
break found;
|
|
3661
|
+
}
|
|
3662
|
+
break;
|
|
3655
3663
|
}
|
|
3656
|
-
|
|
3664
|
+
case ',':
|
|
3665
|
+
case ';':
|
|
3666
|
+
case ':':
|
|
3667
|
+
case '}':
|
|
3668
|
+
break found;
|
|
3657
3669
|
}
|
|
3658
|
-
case ',':
|
|
3659
|
-
case ';':
|
|
3660
|
-
case ':':
|
|
3661
|
-
case '}':
|
|
3662
|
-
break found;
|
|
3663
3670
|
}
|
|
3664
3671
|
}
|
|
3665
3672
|
}
|
|
3673
|
+
if (asset.initialValue && !asset.initialValue.cacheable) {
|
|
3674
|
+
file.flags |= 16;
|
|
3675
|
+
}
|
|
3676
|
+
related.push(asset);
|
|
3666
3677
|
}
|
|
3667
|
-
if (
|
|
3668
|
-
|
|
3678
|
+
if (!quote && !isHtml && !isJs) {
|
|
3679
|
+
if (!value.includes('"')) {
|
|
3680
|
+
quote = '"';
|
|
3681
|
+
}
|
|
3682
|
+
else if (!value.includes("'")) {
|
|
3683
|
+
quote = "'";
|
|
3684
|
+
}
|
|
3669
3685
|
}
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3686
|
+
if (isUrl) {
|
|
3687
|
+
const index = value.indexOf('#');
|
|
3688
|
+
if (index !== -1) {
|
|
3689
|
+
value = value.substring(0, index);
|
|
3690
|
+
}
|
|
3675
3691
|
}
|
|
3676
|
-
|
|
3677
|
-
|
|
3692
|
+
if (quote) {
|
|
3693
|
+
value = quote + value + quote;
|
|
3678
3694
|
}
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3695
|
+
const revised = isJs ? `import(${value + trailing})` : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
3696
|
+
source = (0, util_1.spliceString)(source, startIndex, i + 1, revised, pattern);
|
|
3697
|
+
length = source.length;
|
|
3698
|
+
modified = true;
|
|
3699
|
+
};
|
|
3700
|
+
let url;
|
|
3701
|
+
if (isJs) {
|
|
3702
|
+
if (!quote) {
|
|
3703
|
+
continue;
|
|
3704
|
+
}
|
|
3705
|
+
const target = new RegExp(`^\\s*(${quote}((?:[^${quote}]|(?<=\\\\)${quote})+)${quote})\\s*(,.+)$`).exec(content);
|
|
3706
|
+
if (target) {
|
|
3707
|
+
url = target[1].trim();
|
|
3708
|
+
trailing = target[2].trim();
|
|
3709
|
+
}
|
|
3710
|
+
else {
|
|
3711
|
+
url = (0, util_1.trimQuote)(content);
|
|
3684
3712
|
}
|
|
3685
|
-
}
|
|
3686
|
-
if (quote) {
|
|
3687
|
-
value = quote + value + quote;
|
|
3688
|
-
}
|
|
3689
|
-
const revised = isJs ? `import(${value + trailing})` : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
3690
|
-
source = (0, util_1.spliceString)(source, startIndex, i + 1, revised, pattern);
|
|
3691
|
-
length = source.length;
|
|
3692
|
-
modified = true;
|
|
3693
|
-
};
|
|
3694
|
-
let url;
|
|
3695
|
-
if (isJs) {
|
|
3696
|
-
if (!quote) {
|
|
3697
|
-
continue;
|
|
3698
|
-
}
|
|
3699
|
-
const target = new RegExp(`^\\s*(${quote}((?:[^${quote}]|(?<=\\\\)${quote})+)${quote})\\s*(,.+)$`).exec(content);
|
|
3700
|
-
if (target) {
|
|
3701
|
-
url = target[1].trim();
|
|
3702
|
-
trailing = target[2].trim();
|
|
3703
3713
|
}
|
|
3704
3714
|
else {
|
|
3705
3715
|
url = (0, util_1.trimQuote)(content);
|
|
3706
3716
|
}
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
if (item.base64 === base64) {
|
|
3716
|
-
setOutputURL(this.getSrcUrl(file, item)[0], item);
|
|
3717
|
-
break;
|
|
3717
|
+
if (url.startsWith('data:')) {
|
|
3718
|
+
const base64 = url.split(',')[1]?.trim();
|
|
3719
|
+
if (base64) {
|
|
3720
|
+
for (const item of this.assets) {
|
|
3721
|
+
if (item.base64 === base64) {
|
|
3722
|
+
setOutputURL(this.getSrcUrl(file, item)[0], item);
|
|
3723
|
+
break;
|
|
3724
|
+
}
|
|
3718
3725
|
}
|
|
3719
3726
|
}
|
|
3720
3727
|
}
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3728
|
+
else if (baseHref.length > 0) {
|
|
3729
|
+
let fullUrl, asset;
|
|
3730
|
+
for (const parentUrl of baseHref) {
|
|
3731
|
+
asset = host.findAsset(fullUrl = Document.resolvePath(url, parentUrl), { replaced: true });
|
|
3732
|
+
if (!asset) {
|
|
3733
|
+
const assets = this.related.get(file);
|
|
3734
|
+
asset = assets && host.findAsset(fullUrl, { assets: Array.from(assets), replaced: true });
|
|
3735
|
+
}
|
|
3736
|
+
if (asset) {
|
|
3737
|
+
break;
|
|
3738
|
+
}
|
|
3732
3739
|
}
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
|
|
3742
|
-
}
|
|
3743
|
-
else {
|
|
3744
|
-
k = startIndex;
|
|
3745
|
-
}
|
|
3746
|
-
if (valid) {
|
|
3747
|
-
let l = i, revised = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
3748
|
-
for (let ch; l < length; ++l) {
|
|
3749
|
-
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
3750
|
-
break;
|
|
3751
|
-
}
|
|
3740
|
+
if (asset && asset !== importFile) {
|
|
3741
|
+
if (!(0, util_1.hasValue)(asset.format, 'base64')) {
|
|
3742
|
+
if (asset.bundleReplace) {
|
|
3743
|
+
let k = 0, valid = true;
|
|
3744
|
+
if (!isText) {
|
|
3745
|
+
let j = startIndex;
|
|
3746
|
+
while (isSpace(source[--j])) { }
|
|
3747
|
+
valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
|
|
3752
3748
|
}
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
revised = layer;
|
|
3749
|
+
else {
|
|
3750
|
+
k = startIndex;
|
|
3756
3751
|
}
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3752
|
+
if (valid) {
|
|
3753
|
+
let l = i, revised = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
3754
|
+
for (let ch; l < length; ++l) {
|
|
3755
|
+
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
3756
|
+
break;
|
|
3757
|
+
}
|
|
3758
|
+
}
|
|
3759
|
+
const layer = this.replaceContent(revised, source.substring(k, l + 1), "text/css");
|
|
3760
|
+
if (layer) {
|
|
3761
|
+
revised = layer;
|
|
3764
3762
|
}
|
|
3763
|
+
revised = this.processUrl(host, file, this.removeServerRoot(revised), type, asset) || revised;
|
|
3764
|
+
source = (0, util_1.spliceString)(source, k, l + 1, revised, pattern);
|
|
3765
|
+
length = source.length;
|
|
3766
|
+
if (file.watch) {
|
|
3767
|
+
related.push(asset);
|
|
3768
|
+
if (!(0, types_1.existsFlag)(asset.flags)) {
|
|
3769
|
+
asset.flags |= 8;
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
else if (asset.localUri) {
|
|
3773
|
+
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
3774
|
+
asset.invalid = true;
|
|
3775
|
+
}
|
|
3776
|
+
modified = true;
|
|
3777
|
+
continue;
|
|
3765
3778
|
}
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3779
|
+
}
|
|
3780
|
+
if (hasSameOrigin(asset.url || fullUrl, ...baseHref)) {
|
|
3781
|
+
let sameDir = false;
|
|
3782
|
+
[fullUrl, sameDir] = this.getSrcUrl(file, asset);
|
|
3783
|
+
if (sameDir && isJs) {
|
|
3784
|
+
fullUrl = './' + fullUrl;
|
|
3769
3785
|
}
|
|
3770
|
-
modified = true;
|
|
3771
|
-
continue;
|
|
3772
3786
|
}
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
if (sameDir && isJs) {
|
|
3778
|
-
fullUrl = './' + fullUrl;
|
|
3787
|
+
else {
|
|
3788
|
+
const pathname = file.pathname;
|
|
3789
|
+
const count = pathname && pathname !== '/' ? pathname.split('/').length : 0;
|
|
3790
|
+
fullUrl = (count ? '../'.repeat(count) : '') + asset.relativeUrl;
|
|
3779
3791
|
}
|
|
3780
3792
|
}
|
|
3781
|
-
else {
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3793
|
+
else if (!asset.invalid) {
|
|
3794
|
+
fullUrl = asset.inlineBase64 ||= (0, node_crypto_1.randomUUID)();
|
|
3795
|
+
}
|
|
3796
|
+
if (url !== fullUrl) {
|
|
3797
|
+
setOutputURL(fullUrl, asset);
|
|
3785
3798
|
}
|
|
3786
3799
|
}
|
|
3787
|
-
else if (
|
|
3788
|
-
fullUrl
|
|
3789
|
-
}
|
|
3790
|
-
if (url !== fullUrl) {
|
|
3791
|
-
setOutputURL(fullUrl, asset);
|
|
3800
|
+
else if (importFile && url !== fullUrl) {
|
|
3801
|
+
setOutputURL(fullUrl);
|
|
3792
3802
|
}
|
|
3793
3803
|
}
|
|
3794
|
-
else if (importFile && url !== fullUrl) {
|
|
3795
|
-
setOutputURL(fullUrl);
|
|
3796
|
-
}
|
|
3797
3804
|
}
|
|
3798
3805
|
}
|
|
3799
3806
|
if (modified) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.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.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.12",
|
|
24
|
+
"@e-mc/core": "^0.13.12",
|
|
25
|
+
"@e-mc/document": "^0.13.12",
|
|
26
|
+
"@e-mc/types": "^0.13.12",
|
|
27
27
|
"image-size": "^2.0.2"
|
|
28
28
|
}
|
|
29
29
|
}
|