@pi-r/chrome 0.6.10 → 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.
Files changed (2) hide show
  1. package/index.js +188 -186
  2. 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 REGEXP_URL_SVG = /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi;
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 : type === 'svg' ? REGEXP_URL_SVG : REGEXP_URL;
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
- for (let j = -1; i < length; ++i) {
421
- const ch = source[i];
422
- if (quote && ch === quote) {
423
- if (!isText) {
424
- content += ch;
425
- }
426
- if (isHref) {
427
- break;
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 (closed === -1) {
434
- closed = i + 1;
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
- j = i + 1;
438
- continue;
439
- }
440
- if (!quote && (ch === '"' || ch === "'" || ch === '`' && isJs) && (isHref || !content.trim())) {
441
- quote = ch;
442
- }
443
- else if (isHref && !quote && isSpace(ch) && content.trim()) {
444
- break;
445
- }
446
- else if (ch === ')') {
447
- if (isUrl) {
448
- if (quote && closed !== -1 || !quote && (isJs || source[i - 1] !== '\\')) {
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
- else if (j !== -1 && (ch === '\n' ||
455
- isText && (ch === ';' || ch === '{') ||
456
- isHref && (ch === '=' || ch === '>') ||
457
- isUrl && (ch === ';' ||
458
- !isJs && (!isHtml && (ch === ':' && !isJs || ch === '}') ||
459
- isHtml && (ch === '"' || ch === "'" || ch === ':' || ch === '>'))))) {
460
- if (closed !== -1) {
461
- i = closed;
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
- else {
464
- content = content.substring(0, i = j);
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
- if (asset) {
478
- if (!asset.inlineBase64) {
479
- if ((_a = host.Cloud) === null || _a === void 0 ? void 0 : _a.getStorage('upload', asset.cloudStorage)) {
480
- const inlineUrlCloud = asset.inlineUrlCloud || (asset.inlineUrlCloud = (0, types_1.generateUUID)());
481
- (parent.inlineUrlCloudMap || (parent.inlineUrlCloudMap = {}))[inlineUrlCloud] = value;
482
- value = inlineUrlCloud;
483
- }
484
- else if (asset.hash && this.productionRelease) {
485
- const inlineUrl = asset.inlineUrl || (asset.inlineUrl = (0, types_1.generateUUID)());
486
- (parent.inlineUrlMap || (parent.inlineUrlMap = {}))[inlineUrl] = value;
487
- value = inlineUrl;
488
- }
489
- }
490
- const font = findFont(asset.format);
491
- if (font) {
492
- found: {
493
- for (let k = i + 1; k < length; ++k) {
494
- switch (source[k]) {
495
- case ')': {
496
- const component = source.substring(i + 1, k + 1);
497
- const format = /\s+format\([^)]+\)$/i.exec(component);
498
- if (format) {
499
- trailing = component.replace(format[0], ` format("${font}")`);
500
- i = k;
501
- break found;
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
- break;
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 (asset.initialValue && !asset.initialValue.cacheable) {
515
- parent.flags |= 16;
520
+ if (!quote && !isHtml && !isJs) {
521
+ if (!value.includes('"')) {
522
+ quote = '"';
523
+ }
524
+ else if (!value.includes("'")) {
525
+ quote = "'";
526
+ }
516
527
  }
517
- related.push(asset);
518
- }
519
- if (!quote && !isHtml && !isJs) {
520
- if (!value.includes('"')) {
521
- quote = '"';
528
+ if (isUrl) {
529
+ const index = value.indexOf('#');
530
+ if (index !== -1) {
531
+ value = value.substring(0, index);
532
+ }
522
533
  }
523
- else if (!value.includes("'")) {
524
- quote = "'";
534
+ if (quote) {
535
+ value = quote + value + quote;
525
536
  }
526
- }
527
- if (isUrl) {
528
- const index = value.indexOf('#');
529
- if (index !== -1) {
530
- value = value.substring(0, index);
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
- else {
557
- url = trimQuote(content);
558
- }
559
- if (url.startsWith('data:')) {
560
- const base64 = (_a = url.split(',')[1]) === null || _a === void 0 ? void 0 : _a.trim();
561
- if (base64) {
562
- for (const item of this.assets) {
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
- else if (baseHref.length) {
571
- let fullUrl, asset;
572
- for (const parentUrl of baseHref) {
573
- 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)) {
574
- break;
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
- if (asset && asset !== importFile) {
578
- if (!(0, util_1.hasValue)(asset.format, 'base64')) {
579
- if (asset.bundleReplace) {
580
- let k, valid;
581
- if (!isText) {
582
- let j = startIndex;
583
- while (isSpace(source[--j])) { }
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
- related.push(asset);
610
- if (!(0, types_1.existsFlag)(asset.flags)) {
611
- asset.flags |= 8;
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
- if (hasSameOrigin(asset.url || fullUrl, ...baseHref)) {
619
- let sameDir;
620
- [fullUrl, sameDir] = getSrcURL.call(this, parent, asset);
621
- if (sameDir && isJs) {
622
- fullUrl = './' + fullUrl;
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
- const pathname = parent.pathname;
627
- const count = pathname && pathname !== '/' && pathname !== '\\' ? pathname.split(/[\\/]/).length : 0;
628
- fullUrl = (count ? '../'.repeat(count) : '') + asset.relativeUrl;
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 (!asset.invalid) {
632
- fullUrl = asset.inlineBase64 || (asset.inlineBase64 = (0, types_1.generateUUID)());
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.10",
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.29",
24
- "@e-mc/core": "^0.8.29",
25
- "@e-mc/document": "^0.8.29",
26
- "@e-mc/types": "^0.8.29"
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
  }