@pi-r/chrome 0.3.8 → 0.3.9

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