@pi-r/chrome 0.3.3 → 0.3.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.
Files changed (3) hide show
  1. package/LICENSE +1 -1
  2. package/index.js +40 -26
  3. package/package.json +5 -5
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 Lisa Mishima
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.js CHANGED
@@ -286,7 +286,7 @@ function hasSameOrigin(value, ...other) {
286
286
  return false;
287
287
  }
288
288
  function restoreSearchParams(value, prefix = '__sqd') {
289
- if (value?.indexOf(prefix) !== -1) {
289
+ if ((value === null || value === void 0 ? void 0 : value.indexOf(prefix)) !== -1) {
290
290
  const params = new URLSearchParams(value);
291
291
  params.forEach((_, key) => key.startsWith(prefix) && params.delete(key));
292
292
  if (value = params.toString()) {
@@ -378,6 +378,7 @@ function getSrcURL(parent, file) {
378
378
  return [found ? joinPath('../'.repeat(prefix.length), suffix.join('/'), file.filename) : '../'.repeat(prefix.length) + relativeUrl];
379
379
  }
380
380
  function transformURL(host, parent, type, source, importFile) {
381
+ var _a;
381
382
  const related = [];
382
383
  const baseHref = getBaseURLs(importFile || parent, this.baseUrl);
383
384
  const isHtml = type === 'html';
@@ -443,12 +444,13 @@ function transformURL(host, parent, type, source, importFile) {
443
444
  }
444
445
  }
445
446
  const setOutputURL = (value, asset) => {
447
+ var _a;
446
448
  if (!value) {
447
449
  return;
448
450
  }
449
451
  if (asset) {
450
452
  if (!asset.inlineBase64) {
451
- if (host.Cloud?.getStorage('upload', asset.cloudStorage)) {
453
+ if ((_a = host.Cloud) === null || _a === void 0 ? void 0 : _a.getStorage('upload', asset.cloudStorage)) {
452
454
  const inlineUrlCloud = asset.inlineUrlCloud || (asset.inlineUrlCloud = (0, types_1.generateUUID)());
453
455
  (parent.inlineUrlCloudMap || (parent.inlineUrlCloudMap = {}))[inlineUrlCloud] = value;
454
456
  value = inlineUrlCloud;
@@ -529,7 +531,7 @@ function transformURL(host, parent, type, source, importFile) {
529
531
  url = trimQuote(content);
530
532
  }
531
533
  if (url.startsWith('data:')) {
532
- const base64 = url.split(',')[1]?.trim();
534
+ const base64 = (_a = url.split(',')[1]) === null || _a === void 0 ? void 0 : _a.trim();
533
535
  if (base64) {
534
536
  for (const item of this.assets) {
535
537
  if (item.base64 === base64) {
@@ -748,7 +750,7 @@ function transformJs(host, file, output) {
748
750
  this.writeFail(["Unable to write file", path.basename(chunkUri)], err, 32);
749
751
  }
750
752
  }
751
- appending?.forEach(item => item.order += order);
753
+ appending === null || appending === void 0 ? void 0 : appending.forEach(item => item.order += order);
752
754
  }
753
755
  if ((0, types_1.isArray)(sourceFiles)) {
754
756
  file.sourceFiles = sourceFiles;
@@ -867,7 +869,7 @@ const isIgnored = (item, exists) => item.invalid || (0, types_1.ignoreFlag)(item
867
869
  const findFont = (value) => value && (Array.isArray(value) ? value : [value]).find(format => isFont(format));
868
870
  const spliceString = (source, startIndex, endIndex, content) => source.substring(0, startIndex) + content + source.substring(endIndex);
869
871
  const getEndIndex = (match) => match.index + match[0].length;
870
- const getRelativeURL = (file) => joinPath(file.moveTo, file.pathname, file.inlineFilename || file.filename) + (!file.static ? restoreSearchParams(file.url?.search) : '');
872
+ 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) : ''); };
871
873
  const errorHtml = ({ tagName, tagIndex = -1 }) => (0, types_1.errorMessage)('html', 'Location did not resolve', tagName.toLowerCase() + (tagIndex >= 0 ? ': ' + tagIndex : ''));
872
874
  const errorDataSource = (value, hint) => (0, types_1.errorMessage)('data-source', value, hint);
873
875
  class ChromeDocument extends Document {
@@ -941,6 +943,7 @@ class ChromeDocument extends Document {
941
943
  return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
942
944
  }
943
945
  static async finalize(instance) {
946
+ var _a;
944
947
  if (instance.aborted) {
945
948
  return Promise.reject((0, types_1.createAbortError)());
946
949
  }
@@ -952,7 +955,7 @@ class ChromeDocument extends Document {
952
955
  db.writeTimeElapsed('DB', ["Transactions were committed", db.moduleName], processing.startTime, { ...Document.LOG_STYLE_SUCCESS, type: 65536 });
953
956
  }
954
957
  if (instance.dataSource.length === 0 && outHtml) {
955
- const incremental = htmlFile.incremental ?? this.incremental;
958
+ const incremental = (_a = htmlFile.incremental) !== null && _a !== void 0 ? _a : this.incremental;
956
959
  if (incremental === 'etag' || incremental === 'exists') {
957
960
  const fetched = this.fetchedAssets;
958
961
  const isHtmlOnly = () => !fetched.find(item => item !== htmlFile && assets.includes(item));
@@ -1550,6 +1553,7 @@ class ChromeDocument extends Document {
1550
1553
  }
1551
1554
  resolveImports(file, code, baseFile) {
1552
1555
  var _a;
1556
+ var _b;
1553
1557
  if (!Array.isArray(file.imports)) {
1554
1558
  return;
1555
1559
  }
@@ -1565,7 +1569,7 @@ class ChromeDocument extends Document {
1565
1569
  }
1566
1570
  const importMap = {};
1567
1571
  for (const item of file.imports) {
1568
- (importMap[_a = item.placeholder] || (importMap[_a] = [])).push(item);
1572
+ (importMap[_b = item.placeholder] || (importMap[_b] = [])).push(item);
1569
1573
  }
1570
1574
  for (const placeholder in importMap) {
1571
1575
  const items = importMap[placeholder];
@@ -1575,7 +1579,7 @@ class ChromeDocument extends Document {
1575
1579
  const { uri, original, type, dynamic } = items[i];
1576
1580
  let value;
1577
1581
  if (type === 'css') {
1578
- const asset = this.host?.findAsset(uri);
1582
+ const asset = (_a = this.host) === null || _a === void 0 ? void 0 : _a.findAsset(uri);
1579
1583
  if (asset) {
1580
1584
  const [relativeUrl, sameDir] = getSrcURL.call(this, bundleMain || file, asset);
1581
1585
  if (relativeUrl) {
@@ -1603,12 +1607,13 @@ class ChromeDocument extends Document {
1603
1607
  }
1604
1608
  }
1605
1609
  replaceContent(source, statement, mimeType) {
1610
+ var _a;
1606
1611
  switch (mimeType) {
1607
1612
  case 'text/css': {
1608
1613
  const match = REGEXP_REPLACECSS.exec((typeof statement === 'string' ? statement : statement[0]).trim());
1609
1614
  if (match) {
1610
1615
  const layer = match[1];
1611
- const supports = match[3]?.trim();
1616
+ const supports = (_a = match[3]) === null || _a === void 0 ? void 0 : _a.trim();
1612
1617
  const query = match[4].trim();
1613
1618
  if (layer || supports || query) {
1614
1619
  const newline = (0, util_1.getNewline)(source);
@@ -1645,8 +1650,9 @@ class ChromeDocument extends Document {
1645
1650
  }
1646
1651
  }
1647
1652
  writeImage(data) {
1653
+ var _a;
1648
1654
  const { file, output, command } = data;
1649
- if (output && command && file.element?.outerXml) {
1655
+ if (output && command && ((_a = file.element) === null || _a === void 0 ? void 0 : _a.outerXml)) {
1650
1656
  const match = REGEXP_SRCSETSIZE.exec(command);
1651
1657
  if (match) {
1652
1658
  (file.srcSet || (file.srcSet = [])).push(toPosix(data.baseDirectory ? output.substring(data.baseDirectory.length + 1) : output), match[1] + match[2].toLowerCase());
@@ -1657,12 +1663,13 @@ class ChromeDocument extends Document {
1657
1663
  return false;
1658
1664
  }
1659
1665
  cloudInit({ instance }) {
1666
+ var _a, _b;
1660
1667
  this._cloudUrlMap = Object.create(null);
1661
1668
  this._cloudUploaded = new Set();
1662
1669
  this._cloudEndpoint = null;
1663
1670
  const htmlFile = this.htmlFile;
1664
1671
  if (htmlFile) {
1665
- const endpoint = instance.getStorage('upload', htmlFile.cloudStorage)?.upload?.endpoint;
1672
+ 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;
1666
1673
  if (endpoint) {
1667
1674
  this._cloudEndpoint = new RegExp((0, types_1.escapePattern)(toPosix(endpoint)) + '/', 'g');
1668
1675
  }
@@ -1675,6 +1682,7 @@ class ChromeDocument extends Document {
1675
1682
  return this.editing.includes(file);
1676
1683
  }
1677
1684
  cloudUpload({ host }, file, url, active) {
1685
+ var _a;
1678
1686
  if (active) {
1679
1687
  const endpoint = this._cloudEndpoint;
1680
1688
  const inlineUrlCloud = file.inlineUrlCloud;
@@ -1684,7 +1692,7 @@ class ChromeDocument extends Document {
1684
1692
  const htmlFile = this.htmlFile;
1685
1693
  const pattern = new RegExp((0, types_1.escapePattern)(inlineUrlCloud), 'g');
1686
1694
  for (const item of this.editing) {
1687
- if (item.inlineUrlCloudMap?.[inlineUrlCloud]) {
1695
+ if ((_a = item.inlineUrlCloudMap) === null || _a === void 0 ? void 0 : _a[inlineUrlCloud]) {
1688
1696
  const source = host.getUTF8String(item);
1689
1697
  const output = source.replace(pattern, endpoint && item !== htmlFile && cloudUrl.indexOf('/') !== -1 ? url : cloudUrl);
1690
1698
  if (source !== output) {
@@ -1699,6 +1707,7 @@ class ChromeDocument extends Document {
1699
1707
  return Promise.resolve(false);
1700
1708
  }
1701
1709
  async cloudFinalize(state) {
1710
+ var _a;
1702
1711
  if (this.aborted) {
1703
1712
  return Promise.reject((0, types_1.createAbortError)());
1704
1713
  }
@@ -1747,7 +1756,7 @@ class ChromeDocument extends Document {
1747
1756
  for (const storage of cloudStorage) {
1748
1757
  if (instance.hasCredential('storage', storage)) {
1749
1758
  const { service, admin, bucket, upload } = storage;
1750
- const website = admin?.configBucket?.website;
1759
+ const website = (_a = admin === null || admin === void 0 ? void 0 : admin.configBucket) === null || _a === void 0 ? void 0 : _a.website;
1751
1760
  if ((0, types_1.isPlainObject)(website) && bucket && upload) {
1752
1761
  let filename = joinPath(upload.pathname, upload.filename || path.basename(htmlFile.localUri));
1753
1762
  if (website.indexPage === true) {
@@ -1783,7 +1792,7 @@ class ChromeDocument extends Document {
1783
1792
  }
1784
1793
  const main = watch.main;
1785
1794
  let result;
1786
- if (main?.editing && main.mimeType === 'text/html') {
1795
+ if ((main === null || main === void 0 ? void 0 : main.editing) && main.mimeType === 'text/html') {
1787
1796
  const inlineUrlCloudMap = main.inlineUrlCloudMap || {};
1788
1797
  const using = [];
1789
1798
  let found;
@@ -1820,6 +1829,7 @@ class ChromeDocument extends Document {
1820
1829
  }
1821
1830
  watchModified(watch, assets) {
1822
1831
  return (files, errors, status) => {
1832
+ var _a;
1823
1833
  if (!watch.server || watch.captured || watch.aborted) {
1824
1834
  return;
1825
1835
  }
@@ -1839,7 +1849,7 @@ class ChromeDocument extends Document {
1839
1849
  search = next.url.search;
1840
1850
  }
1841
1851
  }
1842
- search ?? (search = restoreSearchParams(asset.url?.search));
1852
+ search !== null && search !== void 0 ? search : (search = restoreSearchParams((_a = asset.url) === null || _a === void 0 ? void 0 : _a.search));
1843
1853
  status && (status = status.filter(item => item.type >= types_1.STATUS_TYPE.FATAL && item.type <= types_1.STATUS_TYPE.WARN));
1844
1854
  watch.send(types_1.WATCH_EVENT.MODIFIED, {
1845
1855
  action: pathname && watch.hot && !watch.main ? 'hot' : '',
@@ -1911,11 +1921,13 @@ class ChromeDocument extends Document {
1911
1921
  }
1912
1922
  }
1913
1923
  findDataValue(name) {
1924
+ var _a;
1914
1925
  if (this.hasEval('template')) {
1915
- return this.templateMap.data?.[name];
1926
+ return (_a = this.templateMap.data) === null || _a === void 0 ? void 0 : _a[name];
1916
1927
  }
1917
1928
  }
1918
1929
  setInlinedAttributes({ host, startTime, hashed, contentMap, bufferMap, productionRelease }) {
1930
+ var _a, _b;
1919
1931
  const readBase64 = (item, uuid) => {
1920
1932
  if (!contentMap[uuid]) {
1921
1933
  try {
@@ -1945,7 +1957,7 @@ class ChromeDocument extends Document {
1945
1957
  const filename = createHash(host, item, bufferMap);
1946
1958
  if (filename) {
1947
1959
  for (const hash of this.assets) {
1948
- const url = inlineUrl ? hash.inlineUrlMap?.[inlineUrl] : hash.inlineUrlCloudMap?.[inlineUrlCloud];
1960
+ 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];
1949
1961
  if (url) {
1950
1962
  const search = url.indexOf('?');
1951
1963
  const index = (search !== -1 ? url.substring(0, search) : url).lastIndexOf('/');
@@ -1993,10 +2005,10 @@ class ChromeDocument extends Document {
1993
2005
  const sortNested = (a, b) => {
1994
2006
  const { inlineUrlCloud: urlA, inlineUrlCloudMap: mapA } = a;
1995
2007
  const { inlineUrlCloud: urlB, inlineUrlCloudMap: mapB } = b;
1996
- if (urlA && mapB?.[urlA]) {
2008
+ if (urlA && (mapB === null || mapB === void 0 ? void 0 : mapB[urlA])) {
1997
2009
  return -1;
1998
2010
  }
1999
- if (urlB && mapA?.[urlB]) {
2011
+ if (urlB && (mapA === null || mapA === void 0 ? void 0 : mapA[urlB])) {
2000
2012
  return 1;
2001
2013
  }
2002
2014
  return 0;
@@ -2226,7 +2238,7 @@ class ChromeDocument extends Document {
2226
2238
  }
2227
2239
  }
2228
2240
  if (uri && !(0, util_1.hasValue)(item.format, 'crossorigin') && item !== htmlFile) {
2229
- if (cloud?.getStorage('upload', item.cloudStorage)) {
2241
+ if (cloud === null || cloud === void 0 ? void 0 : cloud.getStorage('upload', item.cloudStorage)) {
2230
2242
  const inlineUrlCloud = item.inlineUrlCloud || (item.inlineUrlCloud = (0, types_1.generateUUID)());
2231
2243
  ((_a = htmlFile).inlineUrlCloudMap || (_a.inlineUrlCloudMap = {}))[inlineUrlCloud] = productionRelease ? this.removeServerRoot(uri) : uri;
2232
2244
  uri = inlineUrlCloud;
@@ -2394,7 +2406,7 @@ class ChromeDocument extends Document {
2394
2406
  batchGroup.push([item]);
2395
2407
  break;
2396
2408
  default:
2397
- if (db?.hasSource(type)) {
2409
+ if (db === null || db === void 0 ? void 0 : db.hasSource(type)) {
2398
2410
  try {
2399
2411
  await db.setCredential(item);
2400
2412
  const credential = item.credential;
@@ -2427,6 +2439,7 @@ class ChromeDocument extends Document {
2427
2439
  }
2428
2440
  return this.allSettled(batchGroup.map(batch => {
2429
2441
  return new Promise(async (resolve, reject) => {
2442
+ var _a, _b, _c;
2430
2443
  const errorRemove = (item, reason) => {
2431
2444
  removeElement(item);
2432
2445
  reject(reason);
@@ -2485,7 +2498,7 @@ class ChromeDocument extends Document {
2485
2498
  }
2486
2499
  else {
2487
2500
  this.abort(type);
2488
- errorRemove(current, target ? errorDataSource('Not found', target) : errorDataSource('Not defined - ' + (this.settings.directory?.data ? 'file' : 'directory'), type));
2501
+ 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));
2489
2502
  return;
2490
2503
  }
2491
2504
  }
@@ -2614,7 +2627,7 @@ class ChromeDocument extends Document {
2614
2627
  if (!getData) {
2615
2628
  const { settings, encoding, persist = true } = current;
2616
2629
  if (!target) {
2617
- target = settings && this.settings.export?.[settings] || pathname;
2630
+ target = settings && ((_b = this.settings.export) === null || _b === void 0 ? void 0 : _b[settings]) || pathname;
2618
2631
  }
2619
2632
  if (typeof target === 'function') {
2620
2633
  getData = target;
@@ -2674,7 +2687,7 @@ class ChromeDocument extends Document {
2674
2687
  break;
2675
2688
  }
2676
2689
  default:
2677
- if (db?.hasSource(type)) {
2690
+ if (db === null || db === void 0 ? void 0 : db.hasSource(type)) {
2678
2691
  switch (type) {
2679
2692
  case 'mongodb':
2680
2693
  for (let j = 0; j < length; ++j) {
@@ -2898,7 +2911,7 @@ class ChromeDocument extends Document {
2898
2911
  for (let j = 0, match; j < items.length; ++j) {
2899
2912
  const row = items[j];
2900
2913
  if ((0, types_1.isPlainObject)(row)) {
2901
- row.__index__ ?? (row.__index__ = j + 1);
2914
+ (_c = row.__index__) !== null && _c !== void 0 ? _c : (row.__index__ = j + 1);
2902
2915
  }
2903
2916
  let segment = template;
2904
2917
  while (match = REGEXP_TEMPLATECONDITIONAL.exec(segment)) {
@@ -3181,6 +3194,7 @@ class ChromeDocument extends Document {
3181
3194
  }
3182
3195
  }
3183
3196
  setProductionAttributes({ host, hashed, bufferMap, startTime }) {
3197
+ var _a;
3184
3198
  for (const item of this.assets) {
3185
3199
  if (isIgnored(item, true)) {
3186
3200
  continue;
@@ -3188,7 +3202,7 @@ class ChromeDocument extends Document {
3188
3202
  if (!hashed.has(item)) {
3189
3203
  createHash(host, item, bufferMap);
3190
3204
  }
3191
- switch (item.element?.tagName.toLowerCase()) {
3205
+ switch ((_a = item.element) === null || _a === void 0 ? void 0 : _a.tagName.toLowerCase()) {
3192
3206
  case 'style':
3193
3207
  if (!item.content) {
3194
3208
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/chrome",
3
- "version": "0.3.3",
3
+ "version": "0.3.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.6.2",
24
- "@e-mc/core": "^0.6.2",
25
- "@e-mc/document": "^0.6.2",
26
- "@e-mc/types": "^0.6.2"
23
+ "@e-mc/cloud": "^0.6.3",
24
+ "@e-mc/core": "^0.6.3",
25
+ "@e-mc/document": "^0.6.3",
26
+ "@e-mc/types": "^0.6.3"
27
27
  }
28
28
  }