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