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