@pi-r/chrome 0.8.5 → 0.8.7
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 +195 -188
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -56,7 +56,7 @@ const REGEXP_TEMPLATE_LEADING = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
|
|
|
56
56
|
const REGEXP_TEMPLATE_TRAILING = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
|
|
57
57
|
const REGEXP_URL = /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi;
|
|
58
58
|
const REGEXP_URL_JS = /\bimport\(/g;
|
|
59
|
-
const
|
|
59
|
+
const REGEXP_URL_CSS = /(?:\burl\(|@import\s+(["']))/gi;
|
|
60
60
|
const REGEXP_IMAGESET = /\b(?:-webkit-)?image-set\(/gi;
|
|
61
61
|
const REGEXP_IMAGESET_URL = /(?:^|[^(])\s*("(\s*[^)][^"]*)"|'(\s*[^)][^"]*)')\s*(?:,|$|[^)][^,]*,?)/gd;
|
|
62
62
|
const REGEXP_SANITIZEALL = new RegExp(`(?:\\s+|\\b)data-(?:pathname|filename|intl-locales|(?:use|exclude)-[^=\\s]+)\\s*${dom_1.DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g');
|
|
@@ -393,9 +393,9 @@ function getSrcURL(instance, parent, file) {
|
|
|
393
393
|
function transformURL(instance, host, parent, type, source, importFile) {
|
|
394
394
|
const related = [];
|
|
395
395
|
const baseHref = getBaseURLs(importFile || parent, instance.baseUrl);
|
|
396
|
-
const isHtml = type === 'html';
|
|
396
|
+
const isHtml = type === 'html' || type === 'svg';
|
|
397
397
|
const isJs = type === 'js';
|
|
398
|
-
const pattern = isJs ? REGEXP_URL_JS :
|
|
398
|
+
const pattern = isJs ? REGEXP_URL_JS : !isHtml ? REGEXP_URL_CSS : REGEXP_URL;
|
|
399
399
|
pattern.lastIndex = 0;
|
|
400
400
|
REGEXP_IMAGESET.lastIndex = 0;
|
|
401
401
|
let length = source.length, modified = false, match;
|
|
@@ -424,225 +424,227 @@ function transformURL(instance, host, parent, type, source, importFile) {
|
|
|
424
424
|
const isUrl = !isText && !isHref;
|
|
425
425
|
const startIndex = match.index;
|
|
426
426
|
let quote = match[1], content = '', trailing = '', closed = -1, i = startIndex + match[0].length;
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
if (
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
if (source[i - 1] !== '\\') {
|
|
437
|
-
if (isText) {
|
|
427
|
+
pass: {
|
|
428
|
+
for (let j = -1; i < length; ++i) {
|
|
429
|
+
const ch = source[i];
|
|
430
|
+
if (quote && ch === quote) {
|
|
431
|
+
if (!isText) {
|
|
432
|
+
content += ch;
|
|
433
|
+
}
|
|
434
|
+
if (isHref) {
|
|
438
435
|
break;
|
|
439
436
|
}
|
|
440
|
-
if (
|
|
441
|
-
|
|
437
|
+
if (source[i - 1] !== '\\') {
|
|
438
|
+
if (isText) {
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
if (closed === -1) {
|
|
442
|
+
closed = i + 1;
|
|
443
|
+
}
|
|
442
444
|
}
|
|
445
|
+
j = i + 1;
|
|
446
|
+
continue;
|
|
443
447
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
break;
|
|
448
|
+
if (!quote && (ch === '"' || ch === "'" || ch === '`' && isJs) && (isHref || !content.trim())) {
|
|
449
|
+
quote = ch;
|
|
450
|
+
}
|
|
451
|
+
else if (isHref && (ch === '#' || !quote && isSpace(ch)) && content.trim()) {
|
|
452
|
+
break pass;
|
|
453
|
+
}
|
|
454
|
+
else if (ch === ')') {
|
|
455
|
+
if (isUrl) {
|
|
456
|
+
if (quote && closed !== -1 || !quote && (isJs || source[i - 1] !== '\\')) {
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
j = i;
|
|
457
460
|
}
|
|
458
|
-
j = i;
|
|
459
461
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
462
|
+
else if (j !== -1 && (ch === '\n' ||
|
|
463
|
+
isText && (ch === ';' || ch === '{') ||
|
|
464
|
+
isHref && (ch === '=' || ch === '>') ||
|
|
465
|
+
isUrl && (ch === ';' ||
|
|
466
|
+
!isJs && (!isHtml && (ch === ':' && !isJs || ch === '}') ||
|
|
467
|
+
isHtml && (ch === '"' || ch === "'" || ch === ':' || ch === '>'))))) {
|
|
468
|
+
if (closed !== -1) {
|
|
469
|
+
i = closed;
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
content = content.substring(0, i = j);
|
|
473
|
+
}
|
|
474
|
+
break;
|
|
469
475
|
}
|
|
470
|
-
|
|
471
|
-
content
|
|
476
|
+
if (closed === -1) {
|
|
477
|
+
content += ch;
|
|
472
478
|
}
|
|
473
|
-
break;
|
|
474
|
-
}
|
|
475
|
-
if (closed === -1) {
|
|
476
|
-
content += ch;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
const setOutputURL = (value, asset) => {
|
|
480
|
-
if (!value) {
|
|
481
|
-
return;
|
|
482
479
|
}
|
|
483
|
-
|
|
484
|
-
if (!
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
480
|
+
const setOutputURL = (value, asset) => {
|
|
481
|
+
if (!value) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
if (asset) {
|
|
485
|
+
if (!asset.inlineBase64) {
|
|
486
|
+
if (host.Cloud?.getStorage('upload', asset.cloudStorage)) {
|
|
487
|
+
const inlineUrlCloud = asset.inlineUrlCloud ||= (0, crypto_1.randomUUID)();
|
|
488
|
+
(parent.inlineUrlCloudMap ||= {})[inlineUrlCloud] = value;
|
|
489
|
+
value = inlineUrlCloud;
|
|
490
|
+
}
|
|
491
|
+
else if (asset.hash && instance.productionRelease) {
|
|
492
|
+
const inlineUrl = asset.inlineUrl ||= (0, crypto_1.randomUUID)();
|
|
493
|
+
(parent.inlineUrlMap ||= {})[inlineUrl] = value;
|
|
494
|
+
value = inlineUrl;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
const font = findFont(asset.format);
|
|
498
|
+
if (font) {
|
|
499
|
+
found: {
|
|
500
|
+
for (let k = i + 1; k < length; ++k) {
|
|
501
|
+
switch (source[k]) {
|
|
502
|
+
case ')': {
|
|
503
|
+
const component = source.substring(i + 1, k + 1);
|
|
504
|
+
const format = /\s+format\([^)]+\)$/i.exec(component);
|
|
505
|
+
if (format) {
|
|
506
|
+
trailing = component.replace(format[0], ` format("${font}")`);
|
|
507
|
+
i = k;
|
|
508
|
+
break found;
|
|
509
|
+
}
|
|
510
|
+
break;
|
|
508
511
|
}
|
|
509
|
-
|
|
512
|
+
case ',':
|
|
513
|
+
case ';':
|
|
514
|
+
case ':':
|
|
515
|
+
case '}':
|
|
516
|
+
break found;
|
|
510
517
|
}
|
|
511
|
-
case ',':
|
|
512
|
-
case ';':
|
|
513
|
-
case ':':
|
|
514
|
-
case '}':
|
|
515
|
-
break found;
|
|
516
518
|
}
|
|
517
519
|
}
|
|
518
520
|
}
|
|
521
|
+
if (asset.initialValue && !asset.initialValue.cacheable) {
|
|
522
|
+
parent.flags |= 16;
|
|
523
|
+
}
|
|
524
|
+
related.push(asset);
|
|
519
525
|
}
|
|
520
|
-
if (
|
|
521
|
-
|
|
526
|
+
if (!quote && !isHtml && !isJs) {
|
|
527
|
+
if (!value.includes('"')) {
|
|
528
|
+
quote = '"';
|
|
529
|
+
}
|
|
530
|
+
else if (!value.includes("'")) {
|
|
531
|
+
quote = "'";
|
|
532
|
+
}
|
|
522
533
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
534
|
+
if (isUrl) {
|
|
535
|
+
const index = value.indexOf('#');
|
|
536
|
+
if (index !== -1) {
|
|
537
|
+
value = value.substring(0, index);
|
|
538
|
+
}
|
|
528
539
|
}
|
|
529
|
-
|
|
530
|
-
|
|
540
|
+
if (quote) {
|
|
541
|
+
value = quote + value + quote;
|
|
531
542
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
543
|
+
const revised = isJs ? 'import(' + value + trailing + ')' : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
544
|
+
source = (0, util_1.spliceString)(source, startIndex, i + 1, revised, pattern);
|
|
545
|
+
length = source.length;
|
|
546
|
+
modified = true;
|
|
547
|
+
};
|
|
548
|
+
let url;
|
|
549
|
+
if (isJs) {
|
|
550
|
+
if (!quote) {
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
const file = new RegExp('^\\s*(' + quote + '((?:[^' + quote + ']|(?<=\\\\)' + quote + ')+)' + quote + ')\\s*(,.+)$').exec(content);
|
|
554
|
+
if (file) {
|
|
555
|
+
url = file[1].trim();
|
|
556
|
+
trailing = file[2].trim();
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
url = trimQuote(content);
|
|
537
560
|
}
|
|
538
|
-
}
|
|
539
|
-
if (quote) {
|
|
540
|
-
value = quote + value + quote;
|
|
541
|
-
}
|
|
542
|
-
const revised = isJs ? 'import(' + value + trailing + ')' : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
543
|
-
source = (0, util_1.spliceString)(source, startIndex, i + 1, revised, pattern);
|
|
544
|
-
length = source.length;
|
|
545
|
-
modified = true;
|
|
546
|
-
};
|
|
547
|
-
let url;
|
|
548
|
-
if (isJs) {
|
|
549
|
-
if (!quote) {
|
|
550
|
-
continue;
|
|
551
|
-
}
|
|
552
|
-
const file = new RegExp('^\\s*(' + quote + '((?:[^' + quote + ']|(?<=\\\\)' + quote + ')+)' + quote + ')\\s*(,.+)$').exec(content);
|
|
553
|
-
if (file) {
|
|
554
|
-
url = file[1].trim();
|
|
555
|
-
trailing = file[2].trim();
|
|
556
561
|
}
|
|
557
562
|
else {
|
|
558
563
|
url = trimQuote(content);
|
|
559
564
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
if (item.base64 === base64) {
|
|
569
|
-
setOutputURL(getSrcURL(instance, parent, item)[0], item);
|
|
570
|
-
break;
|
|
565
|
+
if (url.startsWith('data:')) {
|
|
566
|
+
const base64 = url.split(',')[1]?.trim();
|
|
567
|
+
if (base64) {
|
|
568
|
+
for (const item of instance.assets) {
|
|
569
|
+
if (item.base64 === base64) {
|
|
570
|
+
setOutputURL(getSrcURL(instance, parent, item)[0], item);
|
|
571
|
+
break;
|
|
572
|
+
}
|
|
571
573
|
}
|
|
572
574
|
}
|
|
573
575
|
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
576
|
+
else if (baseHref.length > 0) {
|
|
577
|
+
let fullUrl, asset;
|
|
578
|
+
for (const parentUrl of baseHref) {
|
|
579
|
+
if (asset = host.findAsset(fullUrl = Document.resolvePath(url, parentUrl), { replaced: true }) || (instance.related.has(parent) ? host.findAsset(fullUrl, { assets: Array.from(instance.related.get(parent)), replaced: true }) : undefined)) {
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
580
582
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
|
|
590
|
-
}
|
|
591
|
-
else {
|
|
592
|
-
k = startIndex;
|
|
593
|
-
valid = true;
|
|
594
|
-
}
|
|
595
|
-
if (valid) {
|
|
596
|
-
let l = i, revised = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
597
|
-
for (let ch; l < length; ++l) {
|
|
598
|
-
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
599
|
-
break;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
const layer = instance.replaceContent(revised, source.substring(k, l + 1), "text/css");
|
|
603
|
-
if (layer) {
|
|
604
|
-
revised = layer;
|
|
605
|
-
}
|
|
606
|
-
revised = transformURL(instance, host, parent, type, instance.removeServerRoot(revised), asset) || revised;
|
|
607
|
-
source = (0, util_1.spliceString)(source, k, l + 1, revised, pattern);
|
|
608
|
-
length = source.length;
|
|
609
|
-
if (!parent.watch) {
|
|
610
|
-
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
611
|
-
asset.invalid = true;
|
|
583
|
+
if (asset && asset !== importFile) {
|
|
584
|
+
if (!(0, util_1.hasValue)(asset.format, 'base64')) {
|
|
585
|
+
if (asset.bundleReplace) {
|
|
586
|
+
let k = 0, valid;
|
|
587
|
+
if (!isText) {
|
|
588
|
+
let j = startIndex;
|
|
589
|
+
while (isSpace(source[--j])) { }
|
|
590
|
+
valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
|
|
612
591
|
}
|
|
613
592
|
else {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
593
|
+
k = startIndex;
|
|
594
|
+
valid = true;
|
|
595
|
+
}
|
|
596
|
+
if (valid) {
|
|
597
|
+
let l = i, revised = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
598
|
+
for (let ch; l < length; ++l) {
|
|
599
|
+
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
600
|
+
break;
|
|
601
|
+
}
|
|
617
602
|
}
|
|
603
|
+
const layer = instance.replaceContent(revised, source.substring(k, l + 1), "text/css");
|
|
604
|
+
if (layer) {
|
|
605
|
+
revised = layer;
|
|
606
|
+
}
|
|
607
|
+
revised = transformURL(instance, host, parent, type, instance.removeServerRoot(revised), asset) || revised;
|
|
608
|
+
source = (0, util_1.spliceString)(source, k, l + 1, revised, pattern);
|
|
609
|
+
length = source.length;
|
|
610
|
+
if (!parent.watch) {
|
|
611
|
+
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
612
|
+
asset.invalid = true;
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
related.push(asset);
|
|
616
|
+
if (!(0, types_1.existsFlag)(asset.flags)) {
|
|
617
|
+
asset.flags |= 8;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
modified = true;
|
|
621
|
+
continue;
|
|
618
622
|
}
|
|
619
|
-
modified = true;
|
|
620
|
-
continue;
|
|
621
623
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
624
|
+
if (hasSameOrigin(asset.url || fullUrl, ...baseHref)) {
|
|
625
|
+
let sameDir = false;
|
|
626
|
+
[fullUrl, sameDir] = getSrcURL(instance, parent, asset);
|
|
627
|
+
if (sameDir && isJs) {
|
|
628
|
+
fullUrl = './' + fullUrl;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
const pathname = parent.pathname;
|
|
633
|
+
const count = pathname && pathname !== '/' && pathname !== '\\' ? pathname.split(/[\\/]/).length : 0;
|
|
634
|
+
fullUrl = (count ? '../'.repeat(count) : '') + asset.relativeUrl;
|
|
628
635
|
}
|
|
629
636
|
}
|
|
630
|
-
else {
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
637
|
+
else if (!asset.invalid) {
|
|
638
|
+
fullUrl = asset.inlineBase64 ||= (0, crypto_1.randomUUID)();
|
|
639
|
+
}
|
|
640
|
+
if (url !== fullUrl) {
|
|
641
|
+
setOutputURL(fullUrl, asset);
|
|
634
642
|
}
|
|
635
643
|
}
|
|
636
|
-
else if (
|
|
637
|
-
fullUrl
|
|
638
|
-
}
|
|
639
|
-
if (url !== fullUrl) {
|
|
640
|
-
setOutputURL(fullUrl, asset);
|
|
644
|
+
else if (importFile && url !== fullUrl) {
|
|
645
|
+
setOutputURL(fullUrl);
|
|
641
646
|
}
|
|
642
647
|
}
|
|
643
|
-
else if (importFile && url !== fullUrl) {
|
|
644
|
-
setOutputURL(fullUrl);
|
|
645
|
-
}
|
|
646
648
|
}
|
|
647
649
|
}
|
|
648
650
|
if (modified) {
|
|
@@ -2911,13 +2913,15 @@ class ChromeDocument extends Document {
|
|
|
2911
2913
|
case 'mongodb':
|
|
2912
2914
|
for (let j = 0; j < length; ++j) {
|
|
2913
2915
|
const cmd = batch[j];
|
|
2914
|
-
|
|
2916
|
+
if (cmd.cascade) {
|
|
2917
|
+
cmd.cacheObjectKey ||= cmd.cascade;
|
|
2918
|
+
}
|
|
2915
2919
|
}
|
|
2916
2920
|
break;
|
|
2917
2921
|
case 'redis':
|
|
2918
2922
|
for (let j = 0; j < length; ++j) {
|
|
2919
2923
|
const cmd = batch[j];
|
|
2920
|
-
const
|
|
2924
|
+
const search = cmd.search;
|
|
2921
2925
|
if ((0, types_1.isObject)(search) && typeof search.schema === 'string') {
|
|
2922
2926
|
const pathname = this.resolveDir('schema', search.schema);
|
|
2923
2927
|
if (pathname) {
|
|
@@ -2943,8 +2947,11 @@ class ChromeDocument extends Document {
|
|
|
2943
2947
|
search.schema = undefined;
|
|
2944
2948
|
}
|
|
2945
2949
|
}
|
|
2946
|
-
if (key) {
|
|
2947
|
-
|
|
2950
|
+
if (cmd.key) {
|
|
2951
|
+
const { cascade, query } = cmd;
|
|
2952
|
+
if (cascade || query) {
|
|
2953
|
+
cmd.cacheObjectKey ||= (cascade ? cascade : '') + '_' + (query ? Document.asString(query, true) : '');
|
|
2954
|
+
}
|
|
2948
2955
|
}
|
|
2949
2956
|
}
|
|
2950
2957
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.7",
|
|
4
4
|
"description": "Chrome document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@e-mc/cloud": "^0.10.
|
|
25
|
-
"@e-mc/core": "^0.10.
|
|
26
|
-
"@e-mc/document": "^0.10.
|
|
27
|
-
"@e-mc/types": "^0.10.
|
|
24
|
+
"@e-mc/cloud": "^0.10.22",
|
|
25
|
+
"@e-mc/core": "^0.10.22",
|
|
26
|
+
"@e-mc/document": "^0.10.22",
|
|
27
|
+
"@e-mc/types": "^0.10.22"
|
|
28
28
|
}
|
|
29
29
|
}
|