@pi-r/chrome 0.2.14 → 0.2.15
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 +187 -185
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -375,9 +375,9 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
375
375
|
var _a;
|
|
376
376
|
const related = [];
|
|
377
377
|
const baseHref = getBaseURLs(importFile || parent, this.baseUrl);
|
|
378
|
-
const isHtml = type === 'html';
|
|
378
|
+
const isHtml = type === 'html' || type === 'svg';
|
|
379
379
|
const isJs = type === 'js';
|
|
380
|
-
const pattern = isJs ? /\bimport\(/g :
|
|
380
|
+
const pattern = isJs ? /\bimport\(/g : !isHtml ? /\burl\(|@import\s+(["'])/gi : /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi;
|
|
381
381
|
let length = source.length, modified, match;
|
|
382
382
|
while (match = pattern.exec(source)) {
|
|
383
383
|
const isText = !!match[1];
|
|
@@ -385,227 +385,229 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
385
385
|
const isUrl = !isText && !isHref;
|
|
386
386
|
const startIndex = match.index;
|
|
387
387
|
let quote = match[1], content = '', trailing = '', closed = -1, i = startIndex + match[0].length;
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
if (
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
if (source[i - 1] !== '\\') {
|
|
398
|
-
if (isText) {
|
|
388
|
+
pass: {
|
|
389
|
+
for (let j = -1; i < length; ++i) {
|
|
390
|
+
const ch = source[i];
|
|
391
|
+
if (quote && ch === quote) {
|
|
392
|
+
if (!isText) {
|
|
393
|
+
content += ch;
|
|
394
|
+
}
|
|
395
|
+
if (isHref) {
|
|
399
396
|
break;
|
|
400
397
|
}
|
|
401
|
-
if (
|
|
402
|
-
|
|
398
|
+
if (source[i - 1] !== '\\') {
|
|
399
|
+
if (isText) {
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
if (closed === -1) {
|
|
403
|
+
closed = i + 1;
|
|
404
|
+
}
|
|
403
405
|
}
|
|
406
|
+
j = i + 1;
|
|
407
|
+
continue;
|
|
404
408
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
break;
|
|
409
|
+
if (!quote && (ch === '"' || ch === "'" || ch === '`' && isJs) && (isHref || !content.trim())) {
|
|
410
|
+
quote = ch;
|
|
411
|
+
}
|
|
412
|
+
else if (isHref && (ch === '#' || !quote && isSpace(ch)) && content.trim()) {
|
|
413
|
+
break pass;
|
|
414
|
+
}
|
|
415
|
+
else if (ch === ')') {
|
|
416
|
+
if (isUrl) {
|
|
417
|
+
if (quote && closed !== -1 || !quote && (isJs || source[i - 1] !== '\\')) {
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
j = i;
|
|
418
421
|
}
|
|
419
|
-
j = i;
|
|
420
422
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
423
|
+
else if (j !== -1 && (ch === '\n' ||
|
|
424
|
+
isText && (ch === ';' || ch === '{') ||
|
|
425
|
+
isHref && (ch === '=' || ch === '>') ||
|
|
426
|
+
isUrl && (ch === ';' ||
|
|
427
|
+
!isJs && (!isHtml && (ch === ':' && !isJs || ch === '}') ||
|
|
428
|
+
isHtml && (ch === '"' || ch === "'" || ch === ':' || ch === '>'))))) {
|
|
429
|
+
if (closed !== -1) {
|
|
430
|
+
i = closed;
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
content = content.substring(0, i = j);
|
|
434
|
+
}
|
|
435
|
+
break;
|
|
430
436
|
}
|
|
431
|
-
|
|
432
|
-
content
|
|
437
|
+
if (closed === -1) {
|
|
438
|
+
content += ch;
|
|
433
439
|
}
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
436
|
-
if (closed === -1) {
|
|
437
|
-
content += ch;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
const setOutputURL = (value, asset) => {
|
|
441
|
-
var _a;
|
|
442
|
-
if (!value) {
|
|
443
|
-
return;
|
|
444
440
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
441
|
+
const setOutputURL = (value, asset) => {
|
|
442
|
+
var _a;
|
|
443
|
+
if (!value) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
if (asset) {
|
|
447
|
+
if (!asset.inlineBase64) {
|
|
448
|
+
if ((_a = host.Cloud) === null || _a === void 0 ? void 0 : _a.getStorage('upload', asset.cloudStorage)) {
|
|
449
|
+
const inlineUrlCloud = asset.inlineUrlCloud || (asset.inlineUrlCloud = (0, types_1.generateUUID)());
|
|
450
|
+
(parent.inlineUrlCloudMap || (parent.inlineUrlCloudMap = {}))[inlineUrlCloud] = value;
|
|
451
|
+
value = inlineUrlCloud;
|
|
452
|
+
}
|
|
453
|
+
else if (asset.hash && this.productionRelease) {
|
|
454
|
+
const inlineUrl = asset.inlineUrl || (asset.inlineUrl = (0, types_1.generateUUID)());
|
|
455
|
+
(parent.inlineUrlMap || (parent.inlineUrlMap = {}))[inlineUrl] = value;
|
|
456
|
+
value = inlineUrl;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
const font = findFont(asset.format);
|
|
460
|
+
if (font) {
|
|
461
|
+
found: {
|
|
462
|
+
for (let k = i + 1; k < length; ++k) {
|
|
463
|
+
switch (source[k]) {
|
|
464
|
+
case ')': {
|
|
465
|
+
const component = source.substring(i + 1, k + 1);
|
|
466
|
+
const format = /\s+format\([^)]+\)$/i.exec(component);
|
|
467
|
+
if (format) {
|
|
468
|
+
trailing = component.replace(format[0], ` format("${font}")`);
|
|
469
|
+
i = k;
|
|
470
|
+
break found;
|
|
471
|
+
}
|
|
472
|
+
break;
|
|
470
473
|
}
|
|
471
|
-
|
|
474
|
+
case ',':
|
|
475
|
+
case ';':
|
|
476
|
+
case ':':
|
|
477
|
+
case '}':
|
|
478
|
+
break found;
|
|
472
479
|
}
|
|
473
|
-
case ',':
|
|
474
|
-
case ';':
|
|
475
|
-
case ':':
|
|
476
|
-
case '}':
|
|
477
|
-
break found;
|
|
478
480
|
}
|
|
479
481
|
}
|
|
480
482
|
}
|
|
483
|
+
if (asset.initialValue && !asset.initialValue.cacheable) {
|
|
484
|
+
parent.flags |= 16;
|
|
485
|
+
}
|
|
486
|
+
related.push(asset);
|
|
481
487
|
}
|
|
482
|
-
if (
|
|
483
|
-
|
|
488
|
+
if (!quote && !isHtml && !isJs) {
|
|
489
|
+
if (value.indexOf('"') === -1) {
|
|
490
|
+
quote = '"';
|
|
491
|
+
}
|
|
492
|
+
else if (value.indexOf("'") === -1) {
|
|
493
|
+
quote = "'";
|
|
494
|
+
}
|
|
484
495
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
496
|
+
if (isUrl) {
|
|
497
|
+
const index = value.indexOf('#');
|
|
498
|
+
if (index !== -1) {
|
|
499
|
+
value = value.substring(0, index);
|
|
500
|
+
}
|
|
490
501
|
}
|
|
491
|
-
|
|
492
|
-
|
|
502
|
+
if (quote) {
|
|
503
|
+
value = quote + value + quote;
|
|
493
504
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
505
|
+
const revised = isJs ? 'import(' + value + trailing + ')' : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
506
|
+
source = spliceString(source, startIndex, i + 1, revised);
|
|
507
|
+
length = source.length;
|
|
508
|
+
pattern.lastIndex = startIndex + revised.length;
|
|
509
|
+
modified = true;
|
|
510
|
+
};
|
|
511
|
+
let url;
|
|
512
|
+
if (isJs) {
|
|
513
|
+
if (!quote) {
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
const file = new RegExp('^\\s*(' + quote + '((?:[^' + quote + ']|(?<=\\\\)' + quote + ')+)' + quote + ')\\s*(,.+)$').exec(content);
|
|
517
|
+
if (file) {
|
|
518
|
+
url = file[1].trim();
|
|
519
|
+
trailing = file[2].trim();
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
url = trimQuote(content);
|
|
499
523
|
}
|
|
500
|
-
}
|
|
501
|
-
if (quote) {
|
|
502
|
-
value = quote + value + quote;
|
|
503
|
-
}
|
|
504
|
-
const revised = isJs ? 'import(' + value + trailing + ')' : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
505
|
-
source = spliceString(source, startIndex, i + 1, revised);
|
|
506
|
-
length = source.length;
|
|
507
|
-
pattern.lastIndex = startIndex + revised.length;
|
|
508
|
-
modified = true;
|
|
509
|
-
};
|
|
510
|
-
let url;
|
|
511
|
-
if (isJs) {
|
|
512
|
-
if (!quote) {
|
|
513
|
-
continue;
|
|
514
|
-
}
|
|
515
|
-
const file = new RegExp('^\\s*(' + quote + '((?:[^' + quote + ']|(?<=\\\\)' + quote + ')+)' + quote + ')\\s*(,.+)$').exec(content);
|
|
516
|
-
if (file) {
|
|
517
|
-
url = file[1].trim();
|
|
518
|
-
trailing = file[2].trim();
|
|
519
524
|
}
|
|
520
525
|
else {
|
|
521
526
|
url = trimQuote(content);
|
|
522
527
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
if (item.base64 === base64) {
|
|
532
|
-
setOutputURL(getSrcURL.call(this, parent, item)[0], item);
|
|
533
|
-
break;
|
|
528
|
+
if (url.startsWith('data:')) {
|
|
529
|
+
const base64 = (_a = url.split(',')[1]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
530
|
+
if (base64) {
|
|
531
|
+
for (const item of this.assets) {
|
|
532
|
+
if (item.base64 === base64) {
|
|
533
|
+
setOutputURL(getSrcURL.call(this, parent, item)[0], item);
|
|
534
|
+
break;
|
|
535
|
+
}
|
|
534
536
|
}
|
|
535
537
|
}
|
|
536
538
|
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
539
|
+
else if (baseHref.length) {
|
|
540
|
+
let fullUrl, asset;
|
|
541
|
+
for (const parentUrl of baseHref) {
|
|
542
|
+
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)) {
|
|
543
|
+
break;
|
|
544
|
+
}
|
|
543
545
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
|
|
553
|
-
}
|
|
554
|
-
else {
|
|
555
|
-
k = startIndex;
|
|
556
|
-
valid = true;
|
|
557
|
-
}
|
|
558
|
-
if (valid) {
|
|
559
|
-
let l = i, revised = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
560
|
-
for (let ch; l < length; ++l) {
|
|
561
|
-
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
562
|
-
break;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
const layer = this.replaceContent(revised, source.substring(k, l + 1), 'text/css');
|
|
566
|
-
if (layer) {
|
|
567
|
-
revised = layer;
|
|
568
|
-
}
|
|
569
|
-
source = spliceString(source, k, l + 1, revised = transformURL.call(this, host, parent, type, this.removeServerRoot(revised), asset) || revised);
|
|
570
|
-
length = source.length;
|
|
571
|
-
pattern.lastIndex = k + revised.length;
|
|
572
|
-
if (!parent.watch) {
|
|
573
|
-
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
574
|
-
asset.invalid = true;
|
|
546
|
+
if (asset && asset !== importFile) {
|
|
547
|
+
if (!(0, util_1.hasValue)(asset.format, 'base64')) {
|
|
548
|
+
if (asset.bundleReplace) {
|
|
549
|
+
let k, valid;
|
|
550
|
+
if (!isText) {
|
|
551
|
+
let j = startIndex;
|
|
552
|
+
while (isSpace(source[--j])) { }
|
|
553
|
+
valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
|
|
575
554
|
}
|
|
576
555
|
else {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
556
|
+
k = startIndex;
|
|
557
|
+
valid = true;
|
|
558
|
+
}
|
|
559
|
+
if (valid) {
|
|
560
|
+
let l = i, revised = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
561
|
+
for (let ch; l < length; ++l) {
|
|
562
|
+
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
563
|
+
break;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
const layer = this.replaceContent(revised, source.substring(k, l + 1), 'text/css');
|
|
567
|
+
if (layer) {
|
|
568
|
+
revised = layer;
|
|
580
569
|
}
|
|
570
|
+
source = spliceString(source, k, l + 1, revised = transformURL.call(this, host, parent, type, this.removeServerRoot(revised), asset) || revised);
|
|
571
|
+
length = source.length;
|
|
572
|
+
pattern.lastIndex = k + revised.length;
|
|
573
|
+
if (!parent.watch) {
|
|
574
|
+
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
575
|
+
asset.invalid = true;
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
related.push(asset);
|
|
579
|
+
if (!(0, types_1.existsFlag)(asset.flags)) {
|
|
580
|
+
asset.flags |= 8;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
modified = true;
|
|
584
|
+
continue;
|
|
581
585
|
}
|
|
582
|
-
modified = true;
|
|
583
|
-
continue;
|
|
584
586
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
587
|
+
if (hasSameOrigin(asset.url || fullUrl, ...baseHref)) {
|
|
588
|
+
let sameDir;
|
|
589
|
+
[fullUrl, sameDir] = getSrcURL.call(this, parent, asset);
|
|
590
|
+
if (sameDir && isJs) {
|
|
591
|
+
fullUrl = './' + fullUrl;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
const pathname = parent.pathname;
|
|
596
|
+
const count = pathname && pathname !== '/' && pathname !== '\\' ? pathname.split(/[\\/]/).length : 0;
|
|
597
|
+
fullUrl = (count ? '../'.repeat(count) : '') + asset.relativeUrl;
|
|
591
598
|
}
|
|
592
599
|
}
|
|
593
|
-
else {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
600
|
+
else if (!asset.invalid) {
|
|
601
|
+
fullUrl = asset.inlineBase64 || (asset.inlineBase64 = (0, types_1.generateUUID)());
|
|
602
|
+
}
|
|
603
|
+
if (url !== fullUrl) {
|
|
604
|
+
setOutputURL(fullUrl, asset);
|
|
597
605
|
}
|
|
598
606
|
}
|
|
599
|
-
else if (
|
|
600
|
-
fullUrl
|
|
601
|
-
}
|
|
602
|
-
if (url !== fullUrl) {
|
|
603
|
-
setOutputURL(fullUrl, asset);
|
|
607
|
+
else if (importFile && url !== fullUrl) {
|
|
608
|
+
setOutputURL(fullUrl);
|
|
604
609
|
}
|
|
605
610
|
}
|
|
606
|
-
else if (importFile && url !== fullUrl) {
|
|
607
|
-
setOutputURL(fullUrl);
|
|
608
|
-
}
|
|
609
611
|
}
|
|
610
612
|
}
|
|
611
613
|
if (modified) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
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.5.
|
|
24
|
-
"@e-mc/core": "^0.5.
|
|
25
|
-
"@e-mc/document": "^0.5.
|
|
26
|
-
"@e-mc/types": "^0.5.
|
|
23
|
+
"@e-mc/cloud": "^0.5.23",
|
|
24
|
+
"@e-mc/core": "^0.5.23",
|
|
25
|
+
"@e-mc/document": "^0.5.23",
|
|
26
|
+
"@e-mc/types": "^0.5.23"
|
|
27
27
|
}
|
|
28
28
|
}
|