@pi-r/chrome 0.5.3 → 0.5.4

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 Haruhi Suzumiya
1
+ Copyright 2024 An Pham
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
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
@@ -297,7 +297,7 @@ function hasSameOrigin(value, ...other) {
297
297
  return false;
298
298
  }
299
299
  function restoreSearchParams(value, prefix = '__sqd') {
300
- if (value?.indexOf(prefix) !== -1) {
300
+ if ((value === null || value === void 0 ? void 0 : value.indexOf(prefix)) !== -1) {
301
301
  const params = new URLSearchParams(value);
302
302
  params.forEach((_, key) => key.startsWith(prefix) && params.delete(key));
303
303
  if (value = params.toString()) {
@@ -385,6 +385,7 @@ function getSrcURL(parent, file) {
385
385
  return [found ? joinPath('../'.repeat(prefix.length), suffix.join('/'), file.filename) : '../'.repeat(prefix.length) + relativeUrl];
386
386
  }
387
387
  function transformURL(host, parent, type, source, importFile) {
388
+ var _a;
388
389
  const related = [];
389
390
  const baseHref = getBaseURLs(importFile || parent, this.baseUrl);
390
391
  const isHtml = type === 'html';
@@ -471,12 +472,13 @@ function transformURL(host, parent, type, source, importFile) {
471
472
  }
472
473
  }
473
474
  const setOutputURL = (value, asset) => {
475
+ var _a;
474
476
  if (!value) {
475
477
  return;
476
478
  }
477
479
  if (asset) {
478
480
  if (!asset.inlineBase64) {
479
- if (host.Cloud?.getStorage('upload', asset.cloudStorage)) {
481
+ if ((_a = host.Cloud) === null || _a === void 0 ? void 0 : _a.getStorage('upload', asset.cloudStorage)) {
480
482
  const inlineUrlCloud = asset.inlineUrlCloud || (asset.inlineUrlCloud = (0, types_1.generateUUID)());
481
483
  (parent.inlineUrlCloudMap || (parent.inlineUrlCloudMap = {}))[inlineUrlCloud] = value;
482
484
  value = inlineUrlCloud;
@@ -557,7 +559,7 @@ function transformURL(host, parent, type, source, importFile) {
557
559
  url = trimQuote(content);
558
560
  }
559
561
  if (url.startsWith('data:')) {
560
- const base64 = url.split(',')[1]?.trim();
562
+ const base64 = (_a = url.split(',')[1]) === null || _a === void 0 ? void 0 : _a.trim();
561
563
  if (base64) {
562
564
  for (const item of this.assets) {
563
565
  if (item.base64 === base64) {
@@ -776,7 +778,7 @@ function transformJs(host, file, output) {
776
778
  this.writeFail(["Unable to write file", path.basename(chunkUri)], err, 32);
777
779
  }
778
780
  }
779
- appending?.forEach(item => item.order += order);
781
+ appending === null || appending === void 0 ? void 0 : appending.forEach(item => item.order += order);
780
782
  }
781
783
  if ((0, types_1.isArray)(sourceFiles)) {
782
784
  file.sourceFiles = sourceFiles;
@@ -897,7 +899,7 @@ const isIgnored = (item, exists) => item.invalid || (0, types_1.ignoreFlag)(item
897
899
  const findFont = (value) => value && (Array.isArray(value) ? value : [value]).find(format => isFont(format));
898
900
  const spliceString = (source, startIndex, endIndex, content) => source.substring(0, startIndex) + content + source.substring(endIndex);
899
901
  const getEndIndex = (match) => match.index + match[0].length;
900
- const getRelativeURL = (file) => joinPath(file.moveTo, file.pathname, file.inlineFilename || file.filename) + (!file.static ? restoreSearchParams(file.url?.search) : '');
902
+ 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) : ''); };
901
903
  const errorHtml = ({ tagName, tagIndex = -1 }) => (0, types_1.errorMessage)('html', 'Location did not resolve', tagName.toLowerCase() + (tagIndex >= 0 ? ': ' + tagIndex : ''));
902
904
  const errorDataSource = (value, hint) => (0, types_1.errorMessage)('data-source', value, hint);
903
905
  class ChromeDocument extends Document {
@@ -975,6 +977,7 @@ class ChromeDocument extends Document {
975
977
  return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
976
978
  }
977
979
  static async finalize(instance) {
980
+ var _a;
978
981
  if (instance.aborted) {
979
982
  return Promise.reject((0, types_1.createAbortError)());
980
983
  }
@@ -986,7 +989,7 @@ class ChromeDocument extends Document {
986
989
  db.writeTimeElapsed('DB', ["Transactions were committed", db.moduleName], processing.startTime, { ...Document.LOG_STYLE_SUCCESS, type: 65536 });
987
990
  }
988
991
  if (instance.dataSource.length === 0 && outHtml) {
989
- const incremental = htmlFile.incremental ?? this.incremental;
992
+ const incremental = (_a = htmlFile.incremental) !== null && _a !== void 0 ? _a : this.incremental;
990
993
  if (incremental === 'etag' || incremental === 'exists') {
991
994
  const fetched = this.fetchedAssets;
992
995
  const isHtmlOnly = () => !fetched.find(item => item !== htmlFile && assets.includes(item));
@@ -1581,6 +1584,7 @@ class ChromeDocument extends Document {
1581
1584
  }
1582
1585
  resolveImports(file, code, baseFile) {
1583
1586
  var _a;
1587
+ var _b;
1584
1588
  if (!Array.isArray(file.imports)) {
1585
1589
  return;
1586
1590
  }
@@ -1596,7 +1600,7 @@ class ChromeDocument extends Document {
1596
1600
  }
1597
1601
  const importMap = {};
1598
1602
  for (const item of file.imports) {
1599
- (importMap[_a = item.placeholder] || (importMap[_a] = [])).push(item);
1603
+ (importMap[_b = item.placeholder] || (importMap[_b] = [])).push(item);
1600
1604
  }
1601
1605
  for (const placeholder in importMap) {
1602
1606
  const items = importMap[placeholder];
@@ -1608,7 +1612,7 @@ class ChromeDocument extends Document {
1608
1612
  const hosted = type === 'css';
1609
1613
  let value;
1610
1614
  if (hosted) {
1611
- const asset = this.host?.findAsset(uri);
1615
+ const asset = (_a = this.host) === null || _a === void 0 ? void 0 : _a.findAsset(uri);
1612
1616
  if (asset) {
1613
1617
  const [relativeUrl, sameDir] = getSrcURL.call(this, bundleMain || file, asset);
1614
1618
  if (relativeUrl) {
@@ -1637,12 +1641,13 @@ class ChromeDocument extends Document {
1637
1641
  }
1638
1642
  }
1639
1643
  replaceContent(source, statement, mimeType) {
1644
+ var _a;
1640
1645
  switch (mimeType) {
1641
1646
  case 'text/css': {
1642
1647
  const match = REGEXP_REPLACECSS.exec((typeof statement === 'string' ? statement : statement[0]).trim());
1643
1648
  if (match) {
1644
1649
  const layer = match[1];
1645
- const supports = match[3]?.trim();
1650
+ const supports = (_a = match[3]) === null || _a === void 0 ? void 0 : _a.trim();
1646
1651
  const query = match[4].trim();
1647
1652
  if (layer || supports || query) {
1648
1653
  const newline = (0, util_1.getNewline)(source);
@@ -1679,8 +1684,9 @@ class ChromeDocument extends Document {
1679
1684
  }
1680
1685
  }
1681
1686
  writeImage(data) {
1687
+ var _a;
1682
1688
  const { file, output, command } = data;
1683
- if (output && command && file.element?.outerXml) {
1689
+ if (output && command && ((_a = file.element) === null || _a === void 0 ? void 0 : _a.outerXml)) {
1684
1690
  const match = REGEXP_SRCSETSIZE.exec(command);
1685
1691
  if (match) {
1686
1692
  (file.srcSet || (file.srcSet = [])).push(toPosix(data.baseDirectory ? output.substring(data.baseDirectory.length + 1) : output), match[1] + match[2].toLowerCase());
@@ -1691,12 +1697,13 @@ class ChromeDocument extends Document {
1691
1697
  return false;
1692
1698
  }
1693
1699
  cloudInit({ instance }) {
1700
+ var _a, _b;
1694
1701
  this._cloudUrlMap = Object.create(null);
1695
1702
  this._cloudUploaded = new Set();
1696
1703
  this._cloudEndpoint = null;
1697
1704
  const htmlFile = this.htmlFile;
1698
1705
  if (htmlFile) {
1699
- const endpoint = instance.getStorage('upload', htmlFile.cloudStorage)?.upload?.endpoint;
1706
+ const endpoint = (_b = (_a = instance.getStorage('upload', htmlFile.cloudStorage)) === null || _a === void 0 ? void 0 : _a.upload) === null || _b === void 0 ? void 0 : _b.endpoint;
1700
1707
  if (endpoint) {
1701
1708
  this._cloudEndpoint = new RegExp((0, types_1.escapePattern)(toPosix(endpoint)) + '/', 'g');
1702
1709
  }
@@ -1709,6 +1716,7 @@ class ChromeDocument extends Document {
1709
1716
  return this.editing.includes(file);
1710
1717
  }
1711
1718
  cloudUpload({ host }, file, url, active) {
1719
+ var _a;
1712
1720
  if (active) {
1713
1721
  const endpoint = this._cloudEndpoint;
1714
1722
  const inlineUrlCloud = file.inlineUrlCloud;
@@ -1718,7 +1726,7 @@ class ChromeDocument extends Document {
1718
1726
  const htmlFile = this.htmlFile;
1719
1727
  const pattern = new RegExp((0, types_1.escapePattern)(inlineUrlCloud), 'g');
1720
1728
  for (const item of this.editing) {
1721
- if (item.inlineUrlCloudMap?.[inlineUrlCloud]) {
1729
+ if ((_a = item.inlineUrlCloudMap) === null || _a === void 0 ? void 0 : _a[inlineUrlCloud]) {
1722
1730
  const source = host.getUTF8String(item);
1723
1731
  const output = source.replace(pattern, endpoint && item !== htmlFile && cloudUrl.indexOf('/') !== -1 ? url : cloudUrl);
1724
1732
  if (source !== output) {
@@ -1733,6 +1741,7 @@ class ChromeDocument extends Document {
1733
1741
  return Promise.resolve(false);
1734
1742
  }
1735
1743
  async cloudFinalize(state) {
1744
+ var _a;
1736
1745
  if (this.aborted) {
1737
1746
  return Promise.reject((0, types_1.createAbortError)());
1738
1747
  }
@@ -1781,7 +1790,7 @@ class ChromeDocument extends Document {
1781
1790
  for (const storage of cloudStorage) {
1782
1791
  if (instance.hasCredential('storage', storage)) {
1783
1792
  const { service, admin, bucket, upload } = storage;
1784
- const website = admin?.configBucket?.website;
1793
+ const website = (_a = admin === null || admin === void 0 ? void 0 : admin.configBucket) === null || _a === void 0 ? void 0 : _a.website;
1785
1794
  if ((0, types_1.isPlainObject)(website) && bucket && upload) {
1786
1795
  let filename = joinPath(upload.pathname, upload.filename || path.basename(htmlFile.localUri));
1787
1796
  if (website.indexPage === true) {
@@ -1817,7 +1826,7 @@ class ChromeDocument extends Document {
1817
1826
  }
1818
1827
  const main = watch.main;
1819
1828
  let result;
1820
- if (main?.editing && main.mimeType === 'text/html') {
1829
+ if ((main === null || main === void 0 ? void 0 : main.editing) && main.mimeType === 'text/html') {
1821
1830
  const inlineUrlCloudMap = main.inlineUrlCloudMap || {};
1822
1831
  const using = [];
1823
1832
  let found;
@@ -1854,6 +1863,7 @@ class ChromeDocument extends Document {
1854
1863
  }
1855
1864
  watchModified(watch, assets) {
1856
1865
  return (files, errors, status) => {
1866
+ var _a;
1857
1867
  if (!watch.server || watch.captured || watch.aborted) {
1858
1868
  return;
1859
1869
  }
@@ -1873,7 +1883,7 @@ class ChromeDocument extends Document {
1873
1883
  search = next.url.search;
1874
1884
  }
1875
1885
  }
1876
- search ?? (search = restoreSearchParams(asset.url?.search));
1886
+ search !== null && search !== void 0 ? search : (search = restoreSearchParams((_a = asset.url) === null || _a === void 0 ? void 0 : _a.search));
1877
1887
  status && (status = status.filter(item => item.type >= types_1.STATUS_TYPE.FATAL && item.type <= types_1.STATUS_TYPE.WARN));
1878
1888
  watch.send(types_1.WATCH_EVENT.MODIFIED, {
1879
1889
  action: pathname && watch.hot && !watch.main ? 'hot' : '',
@@ -1945,11 +1955,13 @@ class ChromeDocument extends Document {
1945
1955
  }
1946
1956
  }
1947
1957
  findDataValue(name) {
1958
+ var _a;
1948
1959
  if (this.hasEval('template')) {
1949
- return this.templateMap.data?.[name];
1960
+ return (_a = this.templateMap.data) === null || _a === void 0 ? void 0 : _a[name];
1950
1961
  }
1951
1962
  }
1952
1963
  setInlinedAttributes({ host, startTime, hashed, contentMap, bufferMap, productionRelease }) {
1964
+ var _a, _b;
1953
1965
  const readBase64 = (item, uuid) => {
1954
1966
  if (!contentMap[uuid]) {
1955
1967
  try {
@@ -1979,7 +1991,7 @@ class ChromeDocument extends Document {
1979
1991
  const filename = hash && createHash(host, item, hash, bufferMap);
1980
1992
  if (filename) {
1981
1993
  for (const asset of this.assets) {
1982
- const url = inlineUrl ? asset.inlineUrlMap?.[inlineUrl] : asset.inlineUrlCloudMap?.[inlineUrlCloud];
1994
+ const url = inlineUrl ? (_a = asset.inlineUrlMap) === null || _a === void 0 ? void 0 : _a[inlineUrl] : (_b = asset.inlineUrlCloudMap) === null || _b === void 0 ? void 0 : _b[inlineUrlCloud];
1983
1995
  if (url) {
1984
1996
  const search = url.indexOf('?');
1985
1997
  const index = (search !== -1 ? url.substring(0, search) : url).lastIndexOf('/');
@@ -2027,10 +2039,10 @@ class ChromeDocument extends Document {
2027
2039
  const sortNested = (a, b) => {
2028
2040
  const { inlineUrlCloud: urlA, inlineUrlCloudMap: mapA } = a;
2029
2041
  const { inlineUrlCloud: urlB, inlineUrlCloudMap: mapB } = b;
2030
- if (urlA && mapB?.[urlA]) {
2042
+ if (urlA && (mapB === null || mapB === void 0 ? void 0 : mapB[urlA])) {
2031
2043
  return -1;
2032
2044
  }
2033
- if (urlB && mapA?.[urlB]) {
2045
+ if (urlB && (mapA === null || mapA === void 0 ? void 0 : mapA[urlB])) {
2034
2046
  return 1;
2035
2047
  }
2036
2048
  return 0;
@@ -2260,7 +2272,7 @@ class ChromeDocument extends Document {
2260
2272
  }
2261
2273
  }
2262
2274
  if (uri && !(0, util_1.hasValue)(item.format, 'crossorigin') && item !== htmlFile) {
2263
- if (cloud?.getStorage('upload', item.cloudStorage)) {
2275
+ if (cloud === null || cloud === void 0 ? void 0 : cloud.getStorage('upload', item.cloudStorage)) {
2264
2276
  const inlineUrlCloud = item.inlineUrlCloud || (item.inlineUrlCloud = (0, types_1.generateUUID)());
2265
2277
  ((_a = htmlFile).inlineUrlCloudMap || (_a.inlineUrlCloudMap = {}))[inlineUrlCloud] = productionRelease ? this.removeServerRoot(uri) : uri;
2266
2278
  uri = inlineUrlCloud;
@@ -2428,7 +2440,7 @@ class ChromeDocument extends Document {
2428
2440
  batchGroup.push([item]);
2429
2441
  break;
2430
2442
  default:
2431
- if (db?.hasSource(type)) {
2443
+ if (db === null || db === void 0 ? void 0 : db.hasSource(type)) {
2432
2444
  try {
2433
2445
  await db.setCredential(item);
2434
2446
  const credential = item.credential;
@@ -2461,6 +2473,7 @@ class ChromeDocument extends Document {
2461
2473
  }
2462
2474
  return this.allSettled(batchGroup.map(batch => {
2463
2475
  return new Promise(async (resolve, reject) => {
2476
+ var _a, _b, _c;
2464
2477
  const errorRemove = (item, reason) => {
2465
2478
  removeElement(item);
2466
2479
  reject(reason);
@@ -2519,7 +2532,7 @@ class ChromeDocument extends Document {
2519
2532
  }
2520
2533
  else {
2521
2534
  this.abort(type);
2522
- errorRemove(current, target ? errorDataSource('Not found', target) : errorDataSource('Not defined - ' + (this.settings.directory?.data ? 'file' : 'directory'), type));
2535
+ 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));
2523
2536
  return;
2524
2537
  }
2525
2538
  }
@@ -2647,7 +2660,7 @@ class ChromeDocument extends Document {
2647
2660
  }
2648
2661
  if (!getData) {
2649
2662
  const { settings, encoding, persist = true } = current;
2650
- target || (target = settings && this.settings.export?.[settings] || pathname);
2663
+ target || (target = settings && ((_b = this.settings.export) === null || _b === void 0 ? void 0 : _b[settings]) || pathname);
2651
2664
  if (typeof target === 'function') {
2652
2665
  getData = target;
2653
2666
  hint = target.name;
@@ -2706,7 +2719,7 @@ class ChromeDocument extends Document {
2706
2719
  break;
2707
2720
  }
2708
2721
  default:
2709
- if (db?.hasSource(type)) {
2722
+ if (db === null || db === void 0 ? void 0 : db.hasSource(type)) {
2710
2723
  switch (type) {
2711
2724
  case 'mongodb':
2712
2725
  for (let j = 0; j < length; ++j) {
@@ -2930,7 +2943,7 @@ class ChromeDocument extends Document {
2930
2943
  for (let j = 0, match; j < items.length; ++j) {
2931
2944
  const row = items[j];
2932
2945
  if ((0, types_1.isPlainObject)(row)) {
2933
- row.__index__ ?? (row.__index__ = j + 1);
2946
+ (_c = row.__index__) !== null && _c !== void 0 ? _c : (row.__index__ = j + 1);
2934
2947
  }
2935
2948
  let segment = template;
2936
2949
  while (match = REGEXP_TEMPLATECONDITIONAL.exec(segment)) {
@@ -3216,6 +3229,7 @@ class ChromeDocument extends Document {
3216
3229
  }
3217
3230
  }
3218
3231
  setProductionAttributes({ host, hashed, bufferMap, startTime }) {
3232
+ var _a;
3219
3233
  for (const item of this.assets) {
3220
3234
  if (isIgnored(item, true)) {
3221
3235
  continue;
@@ -3223,7 +3237,7 @@ class ChromeDocument extends Document {
3223
3237
  if (item.hash && !hashed.has(item)) {
3224
3238
  createHash(host, item, item.hash, bufferMap);
3225
3239
  }
3226
- switch (item.element?.tagName.toLowerCase()) {
3240
+ switch ((_a = item.element) === null || _a === void 0 ? void 0 : _a.tagName.toLowerCase()) {
3227
3241
  case 'style':
3228
3242
  if (!item.content) {
3229
3243
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/chrome",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
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.7.3",
24
- "@e-mc/core": "^0.7.3",
25
- "@e-mc/document": "^0.7.3",
26
- "@e-mc/types": "^0.7.3"
23
+ "@e-mc/cloud": "^0.7.5",
24
+ "@e-mc/core": "^0.7.5",
25
+ "@e-mc/document": "^0.7.5",
26
+ "@e-mc/types": "^0.7.5"
27
27
  }
28
28
  }