@pi-r/chrome 0.2.10 → 0.2.11

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 (3) hide show
  1. package/index.d.ts +6 -6
  2. package/index.js +39 -25
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { IFileManager } from '@e-mc/types/lib';
2
-
3
- import type { ChromeDocumentConstructor, DocumentAsset } from './types';
4
-
5
- declare const Chrome: ChromeDocumentConstructor<IFileManager<DocumentAsset>>;
6
-
1
+ import type { IFileManager } from '@e-mc/types/lib';
2
+
3
+ import type { ChromeDocumentConstructor, DocumentAsset } from './types';
4
+
5
+ declare const Chrome: ChromeDocumentConstructor<IFileManager<DocumentAsset>>;
6
+
7
7
  export = Chrome;
package/index.js CHANGED
@@ -374,6 +374,7 @@ function getSrcURL(parent, file) {
374
374
  return [found ? joinPath('../'.repeat(prefix.length), suffix.join('/'), file.filename) : '../'.repeat(prefix.length) + relativeUrl];
375
375
  }
376
376
  function transformURL(host, parent, type, source, importFile) {
377
+ var _a;
377
378
  const related = [];
378
379
  const baseHref = getBaseURLs(importFile || parent, this.baseUrl);
379
380
  const isHtml = type === 'html';
@@ -439,12 +440,13 @@ function transformURL(host, parent, type, source, importFile) {
439
440
  }
440
441
  }
441
442
  const setOutputURL = (value, asset) => {
443
+ var _a;
442
444
  if (!value) {
443
445
  return;
444
446
  }
445
447
  if (asset) {
446
448
  if (!asset.inlineBase64) {
447
- if (host.Cloud?.getStorage('upload', asset.cloudStorage)) {
449
+ if ((_a = host.Cloud) === null || _a === void 0 ? void 0 : _a.getStorage('upload', asset.cloudStorage)) {
448
450
  const inlineUrlCloud = asset.inlineUrlCloud || (asset.inlineUrlCloud = (0, types_1.generateUUID)());
449
451
  (parent.inlineUrlCloudMap || (parent.inlineUrlCloudMap = {}))[inlineUrlCloud] = value;
450
452
  value = inlineUrlCloud;
@@ -525,7 +527,7 @@ function transformURL(host, parent, type, source, importFile) {
525
527
  url = trimQuote(content);
526
528
  }
527
529
  if (url.startsWith('data:')) {
528
- const base64 = url.split(',')[1]?.trim();
530
+ const base64 = (_a = url.split(',')[1]) === null || _a === void 0 ? void 0 : _a.trim();
529
531
  if (base64) {
530
532
  for (const item of this.assets) {
531
533
  if (item.base64 === base64) {
@@ -744,7 +746,7 @@ function transformJs(host, file, output) {
744
746
  this.writeFail(["Unable to write file", path.basename(chunkUri)], err, 32);
745
747
  }
746
748
  }
747
- appending?.forEach(item => item.order += order);
749
+ appending === null || appending === void 0 ? void 0 : appending.forEach(item => item.order += order);
748
750
  }
749
751
  if ((0, types_1.isArray)(sourceFiles)) {
750
752
  file.sourceFiles = sourceFiles;
@@ -859,7 +861,7 @@ const isIgnored = (item, exists) => item.invalid || (0, types_1.ignoreFlag)(item
859
861
  const findFont = (value) => value && (Array.isArray(value) ? value : [value]).find(format => isFont(format));
860
862
  const spliceString = (source, startIndex, endIndex, content) => source.substring(0, startIndex) + content + source.substring(endIndex);
861
863
  const getEndIndex = (match) => match.index + match[0].length;
862
- const getRelativeURL = (file) => joinPath(file.moveTo, file.pathname, file.inlineFilename || file.filename) + (!file.static ? restoreSearchParams(file.url?.search) : '');
864
+ const getRelativeURL = (file) => { var _a; return joinPath(file.moveTo, file.pathname, file.inlineFilename || file.filename) + (!file.static ? restoreSearchParams((_a = file.url) === null || _a === void 0 ? void 0 : _a.search) : ''); };
863
865
  const errorHtml = ({ tagName, tagIndex = -1 }) => (0, types_1.errorMessage)('html', 'Location did not resolve', tagName.toLowerCase() + (tagIndex >= 0 ? ': ' + tagIndex : ''));
864
866
  const errorDataSource = (value, hint) => (0, types_1.errorMessage)('data-source', value, hint);
865
867
  class ChromeDocument extends Document {
@@ -933,6 +935,7 @@ class ChromeDocument extends Document {
933
935
  return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
934
936
  }
935
937
  static async finalize(instance) {
938
+ var _a;
936
939
  if (instance.aborted) {
937
940
  return Promise.reject((0, types_1.createAbortError)());
938
941
  }
@@ -944,7 +947,7 @@ class ChromeDocument extends Document {
944
947
  db.writeTimeElapsed('DB', ["Transactions were committed", db.moduleName], processing.startTime, { ...Document.LOG_STYLE_SUCCESS, type: 65536 });
945
948
  }
946
949
  if (instance.dataSource.length === 0 && outHtml) {
947
- const incremental = htmlFile.incremental ?? this.incremental;
950
+ const incremental = (_a = htmlFile.incremental) !== null && _a !== void 0 ? _a : this.incremental;
948
951
  if (incremental === 'etag' || incremental === 'exists') {
949
952
  const fetched = this.fetchedAssets;
950
953
  const isHtmlOnly = () => !fetched.find(item => item !== htmlFile && assets.includes(item));
@@ -1525,6 +1528,7 @@ class ChromeDocument extends Document {
1525
1528
  }
1526
1529
  resolveImports(file, code, baseFile) {
1527
1530
  var _a;
1531
+ var _b;
1528
1532
  if (!Array.isArray(file.imports)) {
1529
1533
  return;
1530
1534
  }
@@ -1540,7 +1544,7 @@ class ChromeDocument extends Document {
1540
1544
  }
1541
1545
  const importMap = {};
1542
1546
  for (const item of file.imports) {
1543
- (importMap[_a = item.placeholder] || (importMap[_a] = [])).push(item);
1547
+ (importMap[_b = item.placeholder] || (importMap[_b] = [])).push(item);
1544
1548
  }
1545
1549
  for (const placeholder in importMap) {
1546
1550
  const items = importMap[placeholder];
@@ -1550,7 +1554,7 @@ class ChromeDocument extends Document {
1550
1554
  const { uri, original, type, dynamic } = items[i];
1551
1555
  let value;
1552
1556
  if (type === 'css') {
1553
- const asset = this.host?.findAsset(uri);
1557
+ const asset = (_a = this.host) === null || _a === void 0 ? void 0 : _a.findAsset(uri);
1554
1558
  if (asset) {
1555
1559
  const [relativeUrl, sameDir] = getSrcURL.call(this, bundleMain || file, asset);
1556
1560
  if (relativeUrl) {
@@ -1578,12 +1582,13 @@ class ChromeDocument extends Document {
1578
1582
  }
1579
1583
  }
1580
1584
  replaceContent(source, statement, mimeType) {
1585
+ var _a;
1581
1586
  switch (mimeType) {
1582
1587
  case 'text/css': {
1583
1588
  const match = REGEXP_REPLACECSS.exec((typeof statement === 'string' ? statement : statement[0]).trim());
1584
1589
  if (match) {
1585
1590
  const layer = match[1];
1586
- const supports = match[3]?.trim();
1591
+ const supports = (_a = match[3]) === null || _a === void 0 ? void 0 : _a.trim();
1587
1592
  const query = match[4].trim();
1588
1593
  if (layer || supports || query) {
1589
1594
  const newline = (0, util_1.getNewline)(source);
@@ -1620,8 +1625,9 @@ class ChromeDocument extends Document {
1620
1625
  }
1621
1626
  }
1622
1627
  writeImage(data) {
1628
+ var _a;
1623
1629
  const { file, output, command } = data;
1624
- if (output && command && file.element?.outerXml) {
1630
+ if (output && command && ((_a = file.element) === null || _a === void 0 ? void 0 : _a.outerXml)) {
1625
1631
  const match = REGEXP_SRCSETSIZE.exec(command);
1626
1632
  if (match) {
1627
1633
  (file.srcSet || (file.srcSet = [])).push(toPosix(data.baseDirectory ? output.substring(data.baseDirectory.length + 1) : output), match[1] + match[2].toLowerCase());
@@ -1632,11 +1638,12 @@ class ChromeDocument extends Document {
1632
1638
  return false;
1633
1639
  }
1634
1640
  cloudInit({ instance }) {
1641
+ var _a, _b;
1635
1642
  this._cloudUrlMap = Object.create(null);
1636
1643
  this._cloudUploaded = new Set();
1637
1644
  this._cloudEndpoint = null;
1638
1645
  if (this.htmlFile) {
1639
- const endpoint = instance.getStorage('upload', this.htmlFile.cloudStorage)?.upload?.endpoint;
1646
+ const endpoint = (_b = (_a = instance.getStorage('upload', this.htmlFile.cloudStorage)) === null || _a === void 0 ? void 0 : _a.upload) === null || _b === void 0 ? void 0 : _b.endpoint;
1640
1647
  if (endpoint) {
1641
1648
  this._cloudEndpoint = new RegExp((0, types_1.escapePattern)(toPosix(endpoint)) + '/', 'g');
1642
1649
  }
@@ -1649,6 +1656,7 @@ class ChromeDocument extends Document {
1649
1656
  return this.editing.includes(file);
1650
1657
  }
1651
1658
  cloudUpload({ host }, file, url, active) {
1659
+ var _a;
1652
1660
  if (active) {
1653
1661
  const endpoint = this._cloudEndpoint;
1654
1662
  const inlineUrlCloud = file.inlineUrlCloud;
@@ -1658,7 +1666,7 @@ class ChromeDocument extends Document {
1658
1666
  const htmlFile = this.htmlFile;
1659
1667
  const pattern = new RegExp((0, types_1.escapePattern)(inlineUrlCloud), 'g');
1660
1668
  for (const item of this.editing) {
1661
- if (item.inlineUrlCloudMap?.[inlineUrlCloud]) {
1669
+ if ((_a = item.inlineUrlCloudMap) === null || _a === void 0 ? void 0 : _a[inlineUrlCloud]) {
1662
1670
  const source = host.getUTF8String(item);
1663
1671
  const output = source.replace(pattern, endpoint && item !== htmlFile && cloudUrl.indexOf('/') !== -1 ? url : cloudUrl);
1664
1672
  if (source !== output) {
@@ -1673,6 +1681,7 @@ class ChromeDocument extends Document {
1673
1681
  return Promise.resolve(false);
1674
1682
  }
1675
1683
  async cloudFinalize(state) {
1684
+ var _a;
1676
1685
  if (this.aborted) {
1677
1686
  return Promise.reject((0, types_1.createAbortError)());
1678
1687
  }
@@ -1721,7 +1730,7 @@ class ChromeDocument extends Document {
1721
1730
  for (const storage of cloudStorage) {
1722
1731
  if (instance.hasCredential('storage', storage)) {
1723
1732
  const { service, admin, bucket, upload } = storage;
1724
- const website = admin?.configBucket?.website;
1733
+ const website = (_a = admin === null || admin === void 0 ? void 0 : admin.configBucket) === null || _a === void 0 ? void 0 : _a.website;
1725
1734
  if ((0, types_1.isPlainObject)(website) && bucket && upload) {
1726
1735
  let filename = joinPath(upload.pathname, upload.filename || path.basename(htmlFile.localUri));
1727
1736
  if (website.indexPage === true) {
@@ -1757,7 +1766,7 @@ class ChromeDocument extends Document {
1757
1766
  }
1758
1767
  const main = watch.main;
1759
1768
  let result;
1760
- if (main?.editing && main.mimeType === 'text/html') {
1769
+ if ((main === null || main === void 0 ? void 0 : main.editing) && main.mimeType === 'text/html') {
1761
1770
  const inlineUrlCloudMap = main.inlineUrlCloudMap || {};
1762
1771
  const using = [];
1763
1772
  let found;
@@ -1794,6 +1803,7 @@ class ChromeDocument extends Document {
1794
1803
  }
1795
1804
  watchModified(watch, assets) {
1796
1805
  return (files, errors, status) => {
1806
+ var _a;
1797
1807
  if (!watch.server || watch.captured || watch.aborted) {
1798
1808
  return;
1799
1809
  }
@@ -1813,7 +1823,7 @@ class ChromeDocument extends Document {
1813
1823
  search = next.url.search;
1814
1824
  }
1815
1825
  }
1816
- search ?? (search = restoreSearchParams(asset.url?.search));
1826
+ search !== null && search !== void 0 ? search : (search = restoreSearchParams((_a = asset.url) === null || _a === void 0 ? void 0 : _a.search));
1817
1827
  if (status) {
1818
1828
  status = status.filter(item => item.type >= types_1.STATUS_TYPE.FATAL && item.type <= types_1.STATUS_TYPE.WARN);
1819
1829
  }
@@ -1887,11 +1897,13 @@ class ChromeDocument extends Document {
1887
1897
  }
1888
1898
  }
1889
1899
  findDataValue(name) {
1900
+ var _a;
1890
1901
  if (this.hasEval('template')) {
1891
- return this.templateMap.data?.[name];
1902
+ return (_a = this.templateMap.data) === null || _a === void 0 ? void 0 : _a[name];
1892
1903
  }
1893
1904
  }
1894
1905
  setInlinedAttributes({ host, startTime, hashed, contentMap, bufferMap, productionRelease }) {
1906
+ var _a, _b;
1895
1907
  const readBase64 = (item, uuid) => {
1896
1908
  if (!contentMap[uuid]) {
1897
1909
  try {
@@ -1921,7 +1933,7 @@ class ChromeDocument extends Document {
1921
1933
  const filename = createHash(host, item, bufferMap);
1922
1934
  if (filename) {
1923
1935
  for (const hash of this.assets) {
1924
- const url = inlineUrl ? hash.inlineUrlMap?.[inlineUrl] : hash.inlineUrlCloudMap?.[inlineUrlCloud];
1936
+ const url = inlineUrl ? (_a = hash.inlineUrlMap) === null || _a === void 0 ? void 0 : _a[inlineUrl] : (_b = hash.inlineUrlCloudMap) === null || _b === void 0 ? void 0 : _b[inlineUrlCloud];
1925
1937
  if (url) {
1926
1938
  const search = url.indexOf('?');
1927
1939
  const index = (search !== -1 ? url.substring(0, search) : url).lastIndexOf('/');
@@ -1969,10 +1981,10 @@ class ChromeDocument extends Document {
1969
1981
  const sortNested = (a, b) => {
1970
1982
  const { inlineUrlCloud: urlA, inlineUrlCloudMap: mapA } = a;
1971
1983
  const { inlineUrlCloud: urlB, inlineUrlCloudMap: mapB } = b;
1972
- if (urlA && mapB?.[urlA]) {
1984
+ if (urlA && (mapB === null || mapB === void 0 ? void 0 : mapB[urlA])) {
1973
1985
  return -1;
1974
1986
  }
1975
- if (urlB && mapA?.[urlB]) {
1987
+ if (urlB && (mapA === null || mapA === void 0 ? void 0 : mapA[urlB])) {
1976
1988
  return 1;
1977
1989
  }
1978
1990
  return 0;
@@ -2198,7 +2210,7 @@ class ChromeDocument extends Document {
2198
2210
  }
2199
2211
  }
2200
2212
  if (uri && !(0, util_1.hasValue)(item.format, 'crossorigin') && item !== htmlFile) {
2201
- if (cloud?.getStorage('upload', item.cloudStorage)) {
2213
+ if (cloud === null || cloud === void 0 ? void 0 : cloud.getStorage('upload', item.cloudStorage)) {
2202
2214
  const inlineUrlCloud = item.inlineUrlCloud || (item.inlineUrlCloud = (0, types_1.generateUUID)());
2203
2215
  ((_a = htmlFile).inlineUrlCloudMap || (_a.inlineUrlCloudMap = {}))[inlineUrlCloud] = productionRelease ? this.removeServerRoot(uri) : uri;
2204
2216
  uri = inlineUrlCloud;
@@ -2366,7 +2378,7 @@ class ChromeDocument extends Document {
2366
2378
  batchGroup.push([item]);
2367
2379
  break;
2368
2380
  default:
2369
- if (db?.hasSource(type)) {
2381
+ if (db === null || db === void 0 ? void 0 : db.hasSource(type)) {
2370
2382
  try {
2371
2383
  await db.setCredential(item);
2372
2384
  const credential = item.credential;
@@ -2399,6 +2411,7 @@ class ChromeDocument extends Document {
2399
2411
  }
2400
2412
  return this.allSettled(batchGroup.map(batch => {
2401
2413
  return new Promise(async (resolve, reject) => {
2414
+ var _a, _b, _c;
2402
2415
  const errorRemove = (item, reason) => {
2403
2416
  removeElement(item);
2404
2417
  reject(reason);
@@ -2457,7 +2470,7 @@ class ChromeDocument extends Document {
2457
2470
  }
2458
2471
  else {
2459
2472
  this.abort(type);
2460
- errorRemove(current, target ? errorDataSource('Not found', target) : errorDataSource('Not defined - ' + (this.settings.directory?.data ? 'file' : 'directory'), type));
2473
+ errorRemove(current, target ? errorDataSource('Not found', target) : errorDataSource('Not defined - ' + (((_a = this.settings.directory) === null || _a === void 0 ? void 0 : _a.data) ? 'file' : 'directory'), type));
2461
2474
  return;
2462
2475
  }
2463
2476
  }
@@ -2586,7 +2599,7 @@ class ChromeDocument extends Document {
2586
2599
  if (!getData) {
2587
2600
  const { settings, encoding, persist = true } = current;
2588
2601
  if (!target) {
2589
- target = settings && this.settings.export?.[settings] || pathname;
2602
+ target = settings && ((_b = this.settings.export) === null || _b === void 0 ? void 0 : _b[settings]) || pathname;
2590
2603
  }
2591
2604
  if (typeof target === 'function') {
2592
2605
  getData = target;
@@ -2646,7 +2659,7 @@ class ChromeDocument extends Document {
2646
2659
  break;
2647
2660
  }
2648
2661
  default:
2649
- if (db?.hasSource(type)) {
2662
+ if (db === null || db === void 0 ? void 0 : db.hasSource(type)) {
2650
2663
  switch (type) {
2651
2664
  case 'mongodb':
2652
2665
  for (let j = 0; j < length; ++j) {
@@ -2870,7 +2883,7 @@ class ChromeDocument extends Document {
2870
2883
  for (let j = 0, match; j < items.length; ++j) {
2871
2884
  const row = items[j];
2872
2885
  if ((0, types_1.isPlainObject)(row)) {
2873
- row['__index__'] ?? (row['__index__'] = j + 1);
2886
+ (_c = row['__index__']) !== null && _c !== void 0 ? _c : (row['__index__'] = j + 1);
2874
2887
  }
2875
2888
  let segment = template;
2876
2889
  while (match = REGEXP_TEMPLATECONDITIONAL.exec(segment)) {
@@ -3153,6 +3166,7 @@ class ChromeDocument extends Document {
3153
3166
  }
3154
3167
  }
3155
3168
  setProductionAttributes({ host, hashed, bufferMap, startTime }) {
3169
+ var _a;
3156
3170
  for (const item of this.assets) {
3157
3171
  if (isIgnored(item, true)) {
3158
3172
  continue;
@@ -3160,7 +3174,7 @@ class ChromeDocument extends Document {
3160
3174
  if (!hashed.has(item)) {
3161
3175
  createHash(host, item, bufferMap);
3162
3176
  }
3163
- switch (item.element?.tagName.toLowerCase()) {
3177
+ switch ((_a = item.element) === null || _a === void 0 ? void 0 : _a.tagName.toLowerCase()) {
3164
3178
  case 'style':
3165
3179
  if (!item.content) {
3166
3180
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/chrome",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "description": "Chrome document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {