@pi-r/chrome 0.6.11 → 0.6.12
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 +188 -186
- 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*(?:,|$|[^)][^,]*,?)/g;
|
|
62
62
|
function removeNamespace(name, source, newline, comments) {
|
|
@@ -386,9 +386,9 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
386
386
|
var _a;
|
|
387
387
|
const related = [];
|
|
388
388
|
const baseHref = getBaseURLs(importFile || parent, this.baseUrl);
|
|
389
|
-
const isHtml = type === 'html';
|
|
389
|
+
const isHtml = type === 'html' || type === 'svg';
|
|
390
390
|
const isJs = type === 'js';
|
|
391
|
-
const pattern = isJs ? REGEXP_URL_JS :
|
|
391
|
+
const pattern = isJs ? REGEXP_URL_JS : !isHtml ? REGEXP_URL_CSS : REGEXP_URL;
|
|
392
392
|
pattern.lastIndex = 0;
|
|
393
393
|
REGEXP_IMAGESET.lastIndex = 0;
|
|
394
394
|
let length = source.length, modified, match;
|
|
@@ -417,227 +417,229 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
417
417
|
const isUrl = !isText && !isHref;
|
|
418
418
|
const startIndex = match.index;
|
|
419
419
|
let quote = match[1], content = '', trailing = '', closed = -1, i = startIndex + match[0].length;
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
if (
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
}
|
|
429
|
-
if (source[i - 1] !== '\\') {
|
|
430
|
-
if (isText) {
|
|
420
|
+
pass: {
|
|
421
|
+
for (let j = -1; i < length; ++i) {
|
|
422
|
+
const ch = source[i];
|
|
423
|
+
if (quote && ch === quote) {
|
|
424
|
+
if (!isText) {
|
|
425
|
+
content += ch;
|
|
426
|
+
}
|
|
427
|
+
if (isHref) {
|
|
431
428
|
break;
|
|
432
429
|
}
|
|
433
|
-
if (
|
|
434
|
-
|
|
430
|
+
if (source[i - 1] !== '\\') {
|
|
431
|
+
if (isText) {
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
if (closed === -1) {
|
|
435
|
+
closed = i + 1;
|
|
436
|
+
}
|
|
435
437
|
}
|
|
438
|
+
j = i + 1;
|
|
439
|
+
continue;
|
|
436
440
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
break;
|
|
441
|
+
if (!quote && (ch === '"' || ch === "'" || ch === '`' && isJs) && (isHref || !content.trim())) {
|
|
442
|
+
quote = ch;
|
|
443
|
+
}
|
|
444
|
+
else if (isHref && (ch === '#' || !quote && isSpace(ch)) && content.trim()) {
|
|
445
|
+
break pass;
|
|
446
|
+
}
|
|
447
|
+
else if (ch === ')') {
|
|
448
|
+
if (isUrl) {
|
|
449
|
+
if (quote && closed !== -1 || !quote && (isJs || source[i - 1] !== '\\')) {
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
j = i;
|
|
450
453
|
}
|
|
451
|
-
j = i;
|
|
452
454
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
455
|
+
else if (j !== -1 && (ch === '\n' ||
|
|
456
|
+
isText && (ch === ';' || ch === '{') ||
|
|
457
|
+
isHref && (ch === '=' || ch === '>') ||
|
|
458
|
+
isUrl && (ch === ';' ||
|
|
459
|
+
!isJs && (!isHtml && (ch === ':' && !isJs || ch === '}') ||
|
|
460
|
+
isHtml && (ch === '"' || ch === "'" || ch === ':' || ch === '>'))))) {
|
|
461
|
+
if (closed !== -1) {
|
|
462
|
+
i = closed;
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
content = content.substring(0, i = j);
|
|
466
|
+
}
|
|
467
|
+
break;
|
|
462
468
|
}
|
|
463
|
-
|
|
464
|
-
content
|
|
469
|
+
if (closed === -1) {
|
|
470
|
+
content += ch;
|
|
465
471
|
}
|
|
466
|
-
break;
|
|
467
|
-
}
|
|
468
|
-
if (closed === -1) {
|
|
469
|
-
content += ch;
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
const setOutputURL = (value, asset) => {
|
|
473
|
-
var _a;
|
|
474
|
-
if (!value) {
|
|
475
|
-
return;
|
|
476
472
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
473
|
+
const setOutputURL = (value, asset) => {
|
|
474
|
+
var _a;
|
|
475
|
+
if (!value) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
if (asset) {
|
|
479
|
+
if (!asset.inlineBase64) {
|
|
480
|
+
if ((_a = host.Cloud) === null || _a === void 0 ? void 0 : _a.getStorage('upload', asset.cloudStorage)) {
|
|
481
|
+
const inlineUrlCloud = asset.inlineUrlCloud || (asset.inlineUrlCloud = (0, types_1.generateUUID)());
|
|
482
|
+
(parent.inlineUrlCloudMap || (parent.inlineUrlCloudMap = {}))[inlineUrlCloud] = value;
|
|
483
|
+
value = inlineUrlCloud;
|
|
484
|
+
}
|
|
485
|
+
else if (asset.hash && this.productionRelease) {
|
|
486
|
+
const inlineUrl = asset.inlineUrl || (asset.inlineUrl = (0, types_1.generateUUID)());
|
|
487
|
+
(parent.inlineUrlMap || (parent.inlineUrlMap = {}))[inlineUrl] = value;
|
|
488
|
+
value = inlineUrl;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
const font = findFont(asset.format);
|
|
492
|
+
if (font) {
|
|
493
|
+
found: {
|
|
494
|
+
for (let k = i + 1; k < length; ++k) {
|
|
495
|
+
switch (source[k]) {
|
|
496
|
+
case ')': {
|
|
497
|
+
const component = source.substring(i + 1, k + 1);
|
|
498
|
+
const format = /\s+format\([^)]+\)$/i.exec(component);
|
|
499
|
+
if (format) {
|
|
500
|
+
trailing = component.replace(format[0], ` format("${font}")`);
|
|
501
|
+
i = k;
|
|
502
|
+
break found;
|
|
503
|
+
}
|
|
504
|
+
break;
|
|
502
505
|
}
|
|
503
|
-
|
|
506
|
+
case ',':
|
|
507
|
+
case ';':
|
|
508
|
+
case ':':
|
|
509
|
+
case '}':
|
|
510
|
+
break found;
|
|
504
511
|
}
|
|
505
|
-
case ',':
|
|
506
|
-
case ';':
|
|
507
|
-
case ':':
|
|
508
|
-
case '}':
|
|
509
|
-
break found;
|
|
510
512
|
}
|
|
511
513
|
}
|
|
512
514
|
}
|
|
515
|
+
if (asset.initialValue && !asset.initialValue.cacheable) {
|
|
516
|
+
parent.flags |= 16;
|
|
517
|
+
}
|
|
518
|
+
related.push(asset);
|
|
513
519
|
}
|
|
514
|
-
if (
|
|
515
|
-
|
|
520
|
+
if (!quote && !isHtml && !isJs) {
|
|
521
|
+
if (!value.includes('"')) {
|
|
522
|
+
quote = '"';
|
|
523
|
+
}
|
|
524
|
+
else if (!value.includes("'")) {
|
|
525
|
+
quote = "'";
|
|
526
|
+
}
|
|
516
527
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
528
|
+
if (isUrl) {
|
|
529
|
+
const index = value.indexOf('#');
|
|
530
|
+
if (index !== -1) {
|
|
531
|
+
value = value.substring(0, index);
|
|
532
|
+
}
|
|
522
533
|
}
|
|
523
|
-
|
|
524
|
-
|
|
534
|
+
if (quote) {
|
|
535
|
+
value = quote + value + quote;
|
|
525
536
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
537
|
+
const revised = isJs ? 'import(' + value + trailing + ')' : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
538
|
+
source = spliceString(source, startIndex, i + 1, revised);
|
|
539
|
+
length = source.length;
|
|
540
|
+
pattern.lastIndex = startIndex + revised.length;
|
|
541
|
+
modified = true;
|
|
542
|
+
};
|
|
543
|
+
let url;
|
|
544
|
+
if (isJs) {
|
|
545
|
+
if (!quote) {
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
const file = new RegExp('^\\s*(' + quote + '((?:[^' + quote + ']|(?<=\\\\)' + quote + ')+)' + quote + ')\\s*(,.+)$').exec(content);
|
|
549
|
+
if (file) {
|
|
550
|
+
url = file[1].trim();
|
|
551
|
+
trailing = file[2].trim();
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
url = trimQuote(content);
|
|
531
555
|
}
|
|
532
|
-
}
|
|
533
|
-
if (quote) {
|
|
534
|
-
value = quote + value + quote;
|
|
535
|
-
}
|
|
536
|
-
const revised = isJs ? 'import(' + value + trailing + ')' : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
537
|
-
source = spliceString(source, startIndex, i + 1, revised);
|
|
538
|
-
length = source.length;
|
|
539
|
-
pattern.lastIndex = startIndex + revised.length;
|
|
540
|
-
modified = true;
|
|
541
|
-
};
|
|
542
|
-
let url;
|
|
543
|
-
if (isJs) {
|
|
544
|
-
if (!quote) {
|
|
545
|
-
continue;
|
|
546
|
-
}
|
|
547
|
-
const file = new RegExp('^\\s*(' + quote + '((?:[^' + quote + ']|(?<=\\\\)' + quote + ')+)' + quote + ')\\s*(,.+)$').exec(content);
|
|
548
|
-
if (file) {
|
|
549
|
-
url = file[1].trim();
|
|
550
|
-
trailing = file[2].trim();
|
|
551
556
|
}
|
|
552
557
|
else {
|
|
553
558
|
url = trimQuote(content);
|
|
554
559
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
if (item.base64 === base64) {
|
|
564
|
-
setOutputURL(getSrcURL.call(this, parent, item)[0], item);
|
|
565
|
-
break;
|
|
560
|
+
if (url.startsWith('data:')) {
|
|
561
|
+
const base64 = (_a = url.split(',')[1]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
562
|
+
if (base64) {
|
|
563
|
+
for (const item of this.assets) {
|
|
564
|
+
if (item.base64 === base64) {
|
|
565
|
+
setOutputURL(getSrcURL.call(this, parent, item)[0], item);
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
566
568
|
}
|
|
567
569
|
}
|
|
568
570
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
571
|
+
else if (baseHref.length) {
|
|
572
|
+
let fullUrl, asset;
|
|
573
|
+
for (const parentUrl of baseHref) {
|
|
574
|
+
if (asset = host.findAsset(fullUrl = resolvePath(url, parentUrl), { replaced: true }) || (this.related.has(parent) ? host.findAsset(fullUrl, { assets: Array.from(this.related.get(parent)), replaced: true }) : undefined)) {
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
575
577
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
|
|
585
|
-
}
|
|
586
|
-
else {
|
|
587
|
-
k = startIndex;
|
|
588
|
-
valid = true;
|
|
589
|
-
}
|
|
590
|
-
if (valid) {
|
|
591
|
-
let l = i, revised = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
592
|
-
for (let ch; l < length; ++l) {
|
|
593
|
-
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
594
|
-
break;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
const layer = this.replaceContent(revised, source.substring(k, l + 1), 'text/css');
|
|
598
|
-
if (layer) {
|
|
599
|
-
revised = layer;
|
|
600
|
-
}
|
|
601
|
-
source = spliceString(source, k, l + 1, revised = transformURL.call(this, host, parent, type, this.removeServerRoot(revised), asset) || revised);
|
|
602
|
-
length = source.length;
|
|
603
|
-
pattern.lastIndex = k + revised.length;
|
|
604
|
-
if (!parent.watch) {
|
|
605
|
-
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
606
|
-
asset.invalid = true;
|
|
578
|
+
if (asset && asset !== importFile) {
|
|
579
|
+
if (!(0, util_1.hasValue)(asset.format, 'base64')) {
|
|
580
|
+
if (asset.bundleReplace) {
|
|
581
|
+
let k, valid;
|
|
582
|
+
if (!isText) {
|
|
583
|
+
let j = startIndex;
|
|
584
|
+
while (isSpace(source[--j])) { }
|
|
585
|
+
valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
|
|
607
586
|
}
|
|
608
587
|
else {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
588
|
+
k = startIndex;
|
|
589
|
+
valid = true;
|
|
590
|
+
}
|
|
591
|
+
if (valid) {
|
|
592
|
+
let l = i, revised = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
593
|
+
for (let ch; l < length; ++l) {
|
|
594
|
+
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
595
|
+
break;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
const layer = this.replaceContent(revised, source.substring(k, l + 1), 'text/css');
|
|
599
|
+
if (layer) {
|
|
600
|
+
revised = layer;
|
|
601
|
+
}
|
|
602
|
+
source = spliceString(source, k, l + 1, revised = transformURL.call(this, host, parent, type, this.removeServerRoot(revised), asset) || revised);
|
|
603
|
+
length = source.length;
|
|
604
|
+
pattern.lastIndex = k + revised.length;
|
|
605
|
+
if (!parent.watch) {
|
|
606
|
+
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
607
|
+
asset.invalid = true;
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
related.push(asset);
|
|
611
|
+
if (!(0, types_1.existsFlag)(asset.flags)) {
|
|
612
|
+
asset.flags |= 8;
|
|
613
|
+
}
|
|
612
614
|
}
|
|
615
|
+
modified = true;
|
|
616
|
+
continue;
|
|
613
617
|
}
|
|
614
|
-
modified = true;
|
|
615
|
-
continue;
|
|
616
618
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
619
|
+
if (hasSameOrigin(asset.url || fullUrl, ...baseHref)) {
|
|
620
|
+
let sameDir;
|
|
621
|
+
[fullUrl, sameDir] = getSrcURL.call(this, parent, asset);
|
|
622
|
+
if (sameDir && isJs) {
|
|
623
|
+
fullUrl = './' + fullUrl;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
const pathname = parent.pathname;
|
|
628
|
+
const count = pathname && pathname !== '/' && pathname !== '\\' ? pathname.split(/[\\/]/).length : 0;
|
|
629
|
+
fullUrl = (count ? '../'.repeat(count) : '') + asset.relativeUrl;
|
|
623
630
|
}
|
|
624
631
|
}
|
|
625
|
-
else {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
632
|
+
else if (!asset.invalid) {
|
|
633
|
+
fullUrl = asset.inlineBase64 || (asset.inlineBase64 = (0, types_1.generateUUID)());
|
|
634
|
+
}
|
|
635
|
+
if (url !== fullUrl) {
|
|
636
|
+
setOutputURL(fullUrl, asset);
|
|
629
637
|
}
|
|
630
638
|
}
|
|
631
|
-
else if (
|
|
632
|
-
fullUrl
|
|
633
|
-
}
|
|
634
|
-
if (url !== fullUrl) {
|
|
635
|
-
setOutputURL(fullUrl, asset);
|
|
639
|
+
else if (importFile && url !== fullUrl) {
|
|
640
|
+
setOutputURL(fullUrl);
|
|
636
641
|
}
|
|
637
642
|
}
|
|
638
|
-
else if (importFile && url !== fullUrl) {
|
|
639
|
-
setOutputURL(fullUrl);
|
|
640
|
-
}
|
|
641
643
|
}
|
|
642
644
|
}
|
|
643
645
|
if (modified) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.12",
|
|
4
4
|
"description": "Chrome document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -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.8.
|
|
24
|
-
"@e-mc/core": "^0.8.
|
|
25
|
-
"@e-mc/document": "^0.8.
|
|
26
|
-
"@e-mc/types": "^0.8.
|
|
23
|
+
"@e-mc/cloud": "^0.8.31",
|
|
24
|
+
"@e-mc/core": "^0.8.31",
|
|
25
|
+
"@e-mc/document": "^0.8.31",
|
|
26
|
+
"@e-mc/types": "^0.8.31"
|
|
27
27
|
}
|
|
28
28
|
}
|