@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.
Files changed (2) hide show
  1. package/index.js +187 -185
  2. 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 : type === 'svg' ? /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi : /\burl\(|@import\s+(["'])/gi;
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
- for (let j = -1; i < length; ++i) {
389
- const ch = source[i];
390
- if (quote && ch === quote) {
391
- if (!isText) {
392
- content += ch;
393
- }
394
- if (isHref) {
395
- break;
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 (closed === -1) {
402
- closed = i + 1;
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
- j = i + 1;
406
- continue;
407
- }
408
- if (!quote && (ch === '"' || ch === "'" || ch === '`' && isJs) && (isHref || !content.trim())) {
409
- quote = ch;
410
- }
411
- else if (isHref && !quote && isSpace(ch) && content.trim()) {
412
- break;
413
- }
414
- else if (ch === ')') {
415
- if (isUrl) {
416
- if (quote && closed !== -1 || !quote && (isJs || source[i - 1] !== '\\')) {
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
- else if (j !== -1 && (ch === '\n' ||
423
- isText && (ch === ';' || ch === '{') ||
424
- isHref && (ch === '=' || ch === '>') ||
425
- isUrl && (ch === ';' ||
426
- !isJs && (!isHtml && (ch === ':' && !isJs || ch === '}') ||
427
- isHtml && (ch === '"' || ch === "'" || ch === ':' || ch === '>'))))) {
428
- if (closed !== -1) {
429
- i = closed;
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
- else {
432
- content = content.substring(0, i = j);
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
- if (asset) {
446
- if (!asset.inlineBase64) {
447
- if ((_a = host.Cloud) === null || _a === void 0 ? void 0 : _a.getStorage('upload', asset.cloudStorage)) {
448
- const inlineUrlCloud = asset.inlineUrlCloud || (asset.inlineUrlCloud = (0, types_1.generateUUID)());
449
- (parent.inlineUrlCloudMap || (parent.inlineUrlCloudMap = {}))[inlineUrlCloud] = value;
450
- value = inlineUrlCloud;
451
- }
452
- else if (asset.hash && this.productionRelease) {
453
- const inlineUrl = asset.inlineUrl || (asset.inlineUrl = (0, types_1.generateUUID)());
454
- (parent.inlineUrlMap || (parent.inlineUrlMap = {}))[inlineUrl] = value;
455
- value = inlineUrl;
456
- }
457
- }
458
- const font = findFont(asset.format);
459
- if (font) {
460
- found: {
461
- for (let k = i + 1; k < length; ++k) {
462
- switch (source[k]) {
463
- case ')': {
464
- const component = source.substring(i + 1, k + 1);
465
- const format = /\s+format\([^)]+\)$/i.exec(component);
466
- if (format) {
467
- trailing = component.replace(format[0], ` format("${font}")`);
468
- i = k;
469
- break found;
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
- break;
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 (asset.initialValue && !asset.initialValue.cacheable) {
483
- parent.flags |= 16;
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
- related.push(asset);
486
- }
487
- if (!quote && !isHtml && !isJs) {
488
- if (value.indexOf('"') === -1) {
489
- quote = '"';
496
+ if (isUrl) {
497
+ const index = value.indexOf('#');
498
+ if (index !== -1) {
499
+ value = value.substring(0, index);
500
+ }
490
501
  }
491
- else if (value.indexOf("'") === -1) {
492
- quote = "'";
502
+ if (quote) {
503
+ value = quote + value + quote;
493
504
  }
494
- }
495
- if (isUrl) {
496
- const index = value.indexOf('#');
497
- if (index !== -1) {
498
- value = value.substring(0, index);
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
- else {
525
- url = trimQuote(content);
526
- }
527
- if (url.startsWith('data:')) {
528
- const base64 = (_a = url.split(',')[1]) === null || _a === void 0 ? void 0 : _a.trim();
529
- if (base64) {
530
- for (const item of this.assets) {
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
- else if (baseHref.length) {
539
- let fullUrl, asset;
540
- for (const parentUrl of baseHref) {
541
- 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)) {
542
- break;
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
- if (asset && asset !== importFile) {
546
- if (!(0, util_1.hasValue)(asset.format, 'base64')) {
547
- if (asset.bundleReplace) {
548
- let k, valid;
549
- if (!isText) {
550
- let j = startIndex;
551
- while (isSpace(source[--j])) { }
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
- related.push(asset);
578
- if (!(0, types_1.existsFlag)(asset.flags)) {
579
- asset.flags |= 8;
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
- if (hasSameOrigin(asset.url || fullUrl, ...baseHref)) {
587
- let sameDir;
588
- [fullUrl, sameDir] = getSrcURL.call(this, parent, asset);
589
- if (sameDir && isJs) {
590
- fullUrl = './' + fullUrl;
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
- const pathname = parent.pathname;
595
- const count = pathname && pathname !== '/' && pathname !== '\\' ? pathname.split(/[\\/]/).length : 0;
596
- fullUrl = (count ? '../'.repeat(count) : '') + asset.relativeUrl;
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 (!asset.invalid) {
600
- fullUrl = asset.inlineBase64 || (asset.inlineBase64 = (0, types_1.generateUUID)());
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.14",
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.21",
24
- "@e-mc/core": "^0.5.21",
25
- "@e-mc/document": "^0.5.21",
26
- "@e-mc/types": "^0.5.21"
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
  }