@pi-r/chrome 0.8.3 → 0.9.0

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,7 +1,7 @@
1
- Copyright 2024 An Pham
2
-
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
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright 2024 An Pham
2
+
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
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -4,4 +4,4 @@ https://e-mc.readthedocs.io/en/latest/document
4
4
 
5
5
  ### LICENSE
6
6
 
7
- MIT
7
+ MIT
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
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
- const path = require("path");
3
- const fs = require("fs");
4
- const crypto_1 = require("crypto");
5
- const core_1 = require("@e-mc/core");
2
+ const path = require("node:path");
3
+ const fs = require("node:fs");
4
+ const node_crypto_1 = require("node:crypto");
6
5
  const Cloud = require("@e-mc/cloud");
6
+ const core_1 = require("@e-mc/core");
7
+ const dom_1 = require("@e-mc/document/parse/dom");
7
8
  const types_1 = require("@e-mc/types");
8
9
  const asset_1 = require("@e-mc/document/asset");
9
10
  const util_1 = require("@e-mc/document/util");
10
- const dom_1 = require("@e-mc/document/parse/dom");
11
11
  const transform_1 = require("@e-mc/document/transform");
12
12
  const Document = require('@e-mc/document');
13
13
  const CACHE_DBRESULT = new Map();
@@ -212,10 +212,12 @@ function hasCondition(data, condition) {
212
212
  items.push([match[1], match[2], match[3]]);
213
213
  }
214
214
  REGEXP_TEMPLATECOMPARISON.lastIndex = 0;
215
- if (items.length > 1 && !join) {
215
+ const length = items.length;
216
+ if (length > 1 && !join) {
216
217
  return false;
217
218
  }
218
- for (const item of items) {
219
+ for (let i = 0; i < length; ++i) {
220
+ const item = items[i];
219
221
  const arg1 = item[1];
220
222
  const arg2 = item[2];
221
223
  let valid;
@@ -384,8 +386,8 @@ function getSrcURL(instance, parent, file) {
384
386
  if (parentDir === assetDir) {
385
387
  return [file.filename, true];
386
388
  }
387
- const prefix = splitPath(parentDir);
388
- const suffix = splitPath(assetDir);
389
+ const prefix = parentDir.split('/');
390
+ const suffix = assetDir.split('/');
389
391
  let found = false;
390
392
  while (prefix.length > 0 && suffix.length > 0 && prefix[0] === suffix[0]) {
391
393
  prefix.shift();
@@ -487,12 +489,12 @@ function transformURL(instance, host, parent, type, source, importFile) {
487
489
  if (asset) {
488
490
  if (!asset.inlineBase64) {
489
491
  if (host.Cloud?.getStorage('upload', asset.cloudStorage)) {
490
- const inlineUrlCloud = asset.inlineUrlCloud ||= (0, crypto_1.randomUUID)();
492
+ const inlineUrlCloud = asset.inlineUrlCloud ||= (0, node_crypto_1.randomUUID)();
491
493
  (parent.inlineUrlCloudMap ||= {})[inlineUrlCloud] = value;
492
494
  value = inlineUrlCloud;
493
495
  }
494
496
  else if (asset.hash && instance.productionRelease) {
495
- const inlineUrl = asset.inlineUrl ||= (0, crypto_1.randomUUID)();
497
+ const inlineUrl = asset.inlineUrl ||= (0, node_crypto_1.randomUUID)();
496
498
  (parent.inlineUrlMap ||= {})[inlineUrl] = value;
497
499
  value = inlineUrl;
498
500
  }
@@ -633,12 +635,12 @@ function transformURL(instance, host, parent, type, source, importFile) {
633
635
  }
634
636
  else {
635
637
  const pathname = parent.pathname;
636
- const count = pathname && pathname !== '/' && pathname !== '\\' ? pathname.split(/[\\/]/).length : 0;
638
+ const count = pathname && pathname !== '/' ? pathname.split('/').length : 0;
637
639
  fullUrl = (count ? '../'.repeat(count) : '') + asset.relativeUrl;
638
640
  }
639
641
  }
640
642
  else if (!asset.invalid) {
641
- fullUrl = asset.inlineBase64 ||= (0, crypto_1.randomUUID)();
643
+ fullUrl = asset.inlineBase64 ||= (0, node_crypto_1.randomUUID)();
642
644
  }
643
645
  if (url !== fullUrl) {
644
646
  setOutputURL(fullUrl, asset);
@@ -667,7 +669,7 @@ function transformURL(instance, host, parent, type, source, importFile) {
667
669
  function getFormatUUID(instance, attr, ext) {
668
670
  const format = 'formatMap' in instance ? instance.formatMap : instance.module.format;
669
671
  let pattern;
670
- return (0, types_1.isObject)(format) && (0, types_1.isObject)(pattern = ext && ext in format ? format[ext] : format.uuid) && pattern[attr] ? (0, types_1.randomString)(pattern[attr], pattern.dictionary) : (0, crypto_1.randomUUID)();
672
+ return (0, types_1.isObject)(format) && (0, types_1.isObject)(pattern = ext && ext in format ? format[ext] : format.uuid) && pattern[attr] ? (0, types_1.randomString)(pattern[attr], pattern.dictionary) : (0, node_crypto_1.randomUUID)();
671
673
  }
672
674
  function setLocationUUID(instance, data, file, ext) {
673
675
  const { pathname, filename } = data;
@@ -816,7 +818,7 @@ function replaceHtml(instance, source, { productionRelease, contentMap }, cssMap
816
818
  }
817
819
  function finalizeHtml(value, data) {
818
820
  for (const id in data) {
819
- value = value.replace(new RegExp((0, types_1.escapePattern)(id), 'g'), data[id]);
821
+ value = value.replace(new RegExp(escapePattern(id), 'g'), data[id]);
820
822
  }
821
823
  return value;
822
824
  }
@@ -905,12 +907,14 @@ function errorCredential(instance, domBase, item, err) {
905
907
  instance.writeFail(["Invalid credentials", item.source], err);
906
908
  }
907
909
  }
910
+ function escapePattern(value) {
911
+ return value.replace(/[-|\\{}()[\]^$+*?.]/g, capture => capture === '-' ? '\\x2d' : '\\' + capture);
912
+ }
908
913
  const isSpace = dom_1.DomWriter.isSpace.bind(dom_1.DomWriter);
909
914
  const replaceMatch = dom_1.DomWriter.replaceMatch.bind(dom_1.DomWriter);
910
915
  const getNewlineString = dom_1.DomWriter.getNewlineString.bind(dom_1.DomWriter);
911
916
  const getBuffer = (item, localUri) => item.sourceUTF8 || item.buffer || ((localUri ||= item.localUri) && Document.isPath(localUri) ? fs.readFileSync(localUri, item.encoding) : null);
912
917
  const hasSourceMap = (metadata, value) => (0, types_1.isObject)(metadata) && metadata.__sourcemap__ === value;
913
- const splitPath = (value) => value.split(/[\\/]/).filter(segment => segment.trim());
914
918
  const isBundled = (value, main) => typeof value === 'number' && (value > 0 || main && value === 0);
915
919
  const isFont = (value) => value === 'truetype' || value === 'opentype' || value === 'woff' || value === 'woff2';
916
920
  const isImage = (value) => typeof value === 'string' && value.startsWith('image/') && value !== "image/svg+xml";
@@ -1130,8 +1134,8 @@ class ChromeDocument extends Document {
1130
1134
  const serverRootMapping = instance.serverRootMapping;
1131
1135
  const mapped = [];
1132
1136
  for (const localDir in serverRootMapping) {
1133
- const subDir = serverRootMapping[localDir];
1134
- const destDir = validateDir(Document.normalizePath(/[\\/]$/.test(subDir) ? path.join(outputDir, subDir, localDir) : path.join(outputDir, subDir), true));
1137
+ const subDir = path.normalize(serverRootMapping[localDir]);
1138
+ const destDir = validateDir(Document.normalizePath(subDir.endsWith(path.sep) ? path.join(outputDir, subDir, localDir) : path.join(outputDir, subDir), true));
1135
1139
  if (destDir.startsWith(outputDir)) {
1136
1140
  if (this.canWrite(destDir)) {
1137
1141
  mapped.push([Document.normalizePath(localDir, true), destDir, 0]);
@@ -1847,7 +1851,7 @@ class ChromeDocument extends Document {
1847
1851
  }
1848
1852
  }
1849
1853
  removeServerRoot(value) {
1850
- return value.replace(new RegExp('(\\.\\./)*' + (0, types_1.escapePattern)(ChromeDocument.INTERNAL_SERVERROOT), 'g'), '');
1854
+ return value.replace(new RegExp('(\\.\\./)*' + escapePattern(ChromeDocument.INTERNAL_SERVERROOT), 'g'), '');
1851
1855
  }
1852
1856
  addCopy(data, saveAs) {
1853
1857
  if (data.command && this.host) {
@@ -1876,7 +1880,7 @@ class ChromeDocument extends Document {
1876
1880
  if (this.htmlFile) {
1877
1881
  const endpoint = instance.getStorage('upload', this.htmlFile.cloudStorage)?.upload?.endpoint;
1878
1882
  if (endpoint) {
1879
- this._cloudEndpoint = new RegExp((0, types_1.escapePattern)(Document.toPosix(endpoint)) + '/', 'g');
1883
+ this._cloudEndpoint = new RegExp(escapePattern(Document.toPosix(endpoint)) + '/', 'g');
1880
1884
  }
1881
1885
  }
1882
1886
  }
@@ -1893,7 +1897,7 @@ class ChromeDocument extends Document {
1893
1897
  const cloudUrl = endpoint ? url.replace(endpoint, '') : url;
1894
1898
  file.cloudUrl = cloudUrl;
1895
1899
  if (inlineUrlCloud) {
1896
- const pattern = new RegExp((0, types_1.escapePattern)(inlineUrlCloud), 'g');
1900
+ const pattern = new RegExp(escapePattern(inlineUrlCloud), 'g');
1897
1901
  for (const item of this.editing) {
1898
1902
  if (item.inlineUrlCloudMap?.[inlineUrlCloud]) {
1899
1903
  const source = host.getUTF8String(item);
@@ -1923,7 +1927,7 @@ class ChromeDocument extends Document {
1923
1927
  for (const id in this._cloudUrlMap) {
1924
1928
  const inlineUrlCloud = item.inlineUrlCloudMap[id];
1925
1929
  if (inlineUrlCloud && !this._cloudUploaded.has(id)) {
1926
- output = (output || source).replace(new RegExp((0, types_1.escapePattern)(id), 'g'), inlineUrlCloud);
1930
+ output = (output || source).replace(new RegExp(escapePattern(id), 'g'), inlineUrlCloud);
1927
1931
  state.localStorage.delete(this._cloudUrlMap[id]);
1928
1932
  }
1929
1933
  }
@@ -1999,7 +2003,7 @@ class ChromeDocument extends Document {
1999
2003
  const inlineUrlCloudMap = main.inlineUrlCloudMap || {};
2000
2004
  const using = [];
2001
2005
  let found = false;
2002
- for (let i = 0, length = assets.length, current, upload; i < length; ++i) {
2006
+ for (let i = 0, length = assets.length, current; i < length; ++i) {
2003
2007
  const asset = assets[i];
2004
2008
  if (asset.element && isUnedited(asset)) {
2005
2009
  continue;
@@ -2011,7 +2015,7 @@ class ChromeDocument extends Document {
2011
2015
  else if (isWatched(this, asset) ||
2012
2016
  (0, types_1.watchFlag)(asset.flags) ||
2013
2017
  asset.base64 && watch.related.find(item => (0, asset_1.isEqual)(item, asset)) ||
2014
- (0, types_1.isArray)(asset.cloudStorage) && asset.cloudStorage.some(item => (upload = item.upload) && upload.active)) {
2018
+ (0, types_1.isArray)(asset.cloudStorage) && asset.cloudStorage.some(item => item.upload?.active)) {
2015
2019
  using.push(asset);
2016
2020
  }
2017
2021
  else if (current = watch.assets.find(item => (0, asset_1.isEqual)(item, asset))) {
@@ -2104,8 +2108,8 @@ class ChromeDocument extends Document {
2104
2108
  let current = srcset, match;
2105
2109
  for (const url of items) {
2106
2110
  const resolve = sameOrigin && !Document.isURL(url);
2107
- const pathname = url.split(/[\\/]/).map(seg => (0, types_1.escapePattern)(seg)).join('[\\\\/]');
2108
- const pattern = new RegExp(`(,?\\s*)(${(resolve && !url.startsWith('.') ? `(?:\\.\\.[\\\\/])*\\.\\.${pathname}|` : '') + pathname})(` + (!url.includes('?') ? '(?:(?!,)(?:[^?]|$)[^,]*)|(?!\\?)[^,]*)' : '[^,]*)'), 'g');
2111
+ const pathname = url.split('/').map(seg => escapePattern(seg)).join('/');
2112
+ const pattern = new RegExp(`(,?\\s*)(${(resolve && !url.startsWith('.') ? `(?:\\.\\./)*\\.\\.${pathname}|` : '') + pathname})(` + (!url.includes('?') ? '(?:(?!,)(?:[^?]|$)[^,]*)|(?!\\?)[^,]*)' : '[^,]*)'), 'g');
2109
2113
  while (match = pattern.exec(current)) {
2110
2114
  const partial = match[2];
2111
2115
  if (!resolve || baseHref.some(baseUri => uri === Document.resolvePath(partial, baseUri))) {
@@ -2146,7 +2150,7 @@ class ChromeDocument extends Document {
2146
2150
  readBase64(item, item.inlineBase64);
2147
2151
  }
2148
2152
  else if (!item.invalid && (0, util_1.hasValue)(item.format, 'base64')) {
2149
- const uuid = (0, crypto_1.randomUUID)();
2153
+ const uuid = (0, node_crypto_1.randomUUID)();
2150
2154
  if (readBase64(item, uuid)) {
2151
2155
  item.inlineBase64 = uuid;
2152
2156
  }
@@ -2352,7 +2356,7 @@ class ChromeDocument extends Document {
2352
2356
  source = removeNamespace(moduleName, domBase.modified ? domBase.close() : source, domBase.newline, domBase.getComments());
2353
2357
  if (this.sanitizeFramework) {
2354
2358
  for (const name of this.sanitizeFramework) {
2355
- source = source.replace(name === '*' ? REGEXP_SANITIZEALL : new RegExp(`(?:\\s+|\\b)data-(?:${(0, types_1.escapePattern)(name)}-[^=\\s]+|.+?-${(0, types_1.escapePattern)(name)})\\s*${dom_1.DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g'), '');
2359
+ source = source.replace(name === '*' ? REGEXP_SANITIZEALL : new RegExp(`(?:\\s+|\\b)data-(?:${escapePattern(name)}-[^=\\s]+|.+?-${escapePattern(name)})\\s*${dom_1.DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g'), '');
2356
2360
  }
2357
2361
  }
2358
2362
  if (!htmlFile.preserve) {
@@ -2444,7 +2448,7 @@ class ChromeDocument extends Document {
2444
2448
  }
2445
2449
  if (uri && !(0, util_1.hasValue)(item.format, 'crossorigin') && item !== this.htmlFile) {
2446
2450
  if (host.Cloud?.getStorage('upload', item.cloudStorage)) {
2447
- const inlineUrlCloud = item.inlineUrlCloud ||= (0, crypto_1.randomUUID)();
2451
+ const inlineUrlCloud = item.inlineUrlCloud ||= (0, node_crypto_1.randomUUID)();
2448
2452
  (this.htmlFile.inlineUrlCloudMap ||= {})[inlineUrlCloud] = productionRelease ? this.removeServerRoot(uri) : uri;
2449
2453
  uri = inlineUrlCloud;
2450
2454
  }
@@ -2534,7 +2538,7 @@ class ChromeDocument extends Document {
2534
2538
  if (this.dataSource.length === 0) {
2535
2539
  return;
2536
2540
  }
2537
- const sessionKey = (0, crypto_1.randomUUID)();
2541
+ const sessionKey = (0, node_crypto_1.randomUUID)();
2538
2542
  const cacheData = Object.create(null);
2539
2543
  const dataItems = [];
2540
2544
  const displayItems = [];
@@ -2847,14 +2851,14 @@ class ChromeDocument extends Document {
2847
2851
  }
2848
2852
  }
2849
2853
  if (!getData) {
2850
- const { settings, encoding, persist = true } = current;
2854
+ const { settings, encoding } = current;
2851
2855
  target ||= settings && this.settings.export?.[settings] || pathname;
2852
2856
  if (typeof target === 'function') {
2853
2857
  getData = target;
2854
2858
  hint = target.name;
2855
2859
  }
2856
2860
  else if ((0, types_1.isString)(target)) {
2857
- getData = this.asSourceFile(target, { encoding, persist });
2861
+ getData = this.asSourceFile(target, { encoding });
2858
2862
  hint = target;
2859
2863
  }
2860
2864
  }
@@ -3473,7 +3477,7 @@ class ChromeDocument extends Document {
3473
3477
  const parseSelector = (value) => {
3474
3478
  const items = [];
3475
3479
  const revised = value.replace(useUnsafeCssReplace ? REGEXP_NTHCHILD_UNSAFE : REGEXP_NTHCHILD, (...capture) => {
3476
- return '`%' + (items.push('\\(' + stringSome + (capture[1] === '-' ? '\\x2d' : '\\x2b?') + (capture[2] || '[01]?') + (capture[3] === '0' ? !capture[1] && !capture[2] && !capture[4] && !capture[5] ? '[+-]?0[nN]?' : '0' : '[nN]') + stringSome + (capture[5] ? (capture[4] === '-' ? '\\x2d' : '\\x2b') + stringSome + capture[5] : `(?:[+-]${stringSome}0)?`) + (capture[6] ? stringMany + '[oO][fF]' + stringMany + capture[6].trim() : '') + stringSome + '\\)') - 1) + '`';
3480
+ return '`%' + (items.push('\\(' + stringSome + (capture[1] === '-' ? '\\x2d' : '\\x2b?') + (capture[2] || '[01]?') + (capture[3] === '0' ? !capture[1] && !capture[2] && !capture[4] && !capture[5] ? '[+-]?0[nN]?' : '0' : '[nN]?') + stringSome + (capture[5] ? (capture[4] === '-' ? '\\x2d' : '\\x2b?') + stringSome + capture[5] : `(?:[+-]${stringSome}0)?`) + (capture[6] ? stringMany + '[oO][fF]' + stringMany + capture[6].trim() : '') + stringSome + '\\)') - 1) + '`';
3477
3481
  });
3478
3482
  let selector = '';
3479
3483
  for (let i = 0, length = revised.length, casing = false, attr = false, quote = false; i < length; i++) {
@@ -3548,7 +3552,7 @@ class ChromeDocument extends Document {
3548
3552
  }
3549
3553
  selector += (space & 1 ? '`%%`' : '') + (!casing && ch >= 'a' && ch <= 'z' ? '`' + ch + ch.toUpperCase() + '`' : ch) + (space & 2 ? '`%%`' : '');
3550
3554
  }
3551
- selector = (0, types_1.escapePattern)(selector)
3555
+ selector = escapePattern(selector)
3552
3556
  .replace(/\s*(>|~(?!=)|\\\+|\\\*(?!=)])\s*/g, (...capture) => stringSome + capture[1] + stringSome)
3553
3557
  .replace(/`([a-z][A-Z]|%{2,4})`/g, (...capture) => {
3554
3558
  switch (capture[1]) {
@@ -3614,7 +3618,7 @@ class ChromeDocument extends Document {
3614
3618
  }
3615
3619
  }
3616
3620
  if (!revised) {
3617
- selector = (0, types_1.escapePattern)(selector || value)
3621
+ selector = escapePattern(selector || value)
3618
3622
  .replace(/\s*(\\[()])\s*/g, (...capture) => stringSome + capture[1] + stringSome)
3619
3623
  .replace(/:\s+/g, stringSome + ':' + stringSome)
3620
3624
  .replace(/\s+([<>/]|<=|>=|\\\*)\s+/g, (...capture) => stringSome + capture[1] + stringSome)
@@ -3631,7 +3635,7 @@ class ChromeDocument extends Document {
3631
3635
  }
3632
3636
  while (rule = pattern.exec(current)) {
3633
3637
  if (!nesting) {
3634
- const block = Array.from(current.substring(0, rule.index).matchAll(/{|}/g));
3638
+ const block = Array.from(current.substring(0, rule.index).matchAll(/[{}]/g));
3635
3639
  if (block.filter(open => open[0] === '{').length !== block.filter(close => close[0] === '}').length) {
3636
3640
  continue;
3637
3641
  }
@@ -3651,7 +3655,7 @@ class ChromeDocument extends Document {
3651
3655
  while (bracket = pattern.exec(current)) {
3652
3656
  const segment = bracket[0];
3653
3657
  if (/[{}]/.test(segment)) {
3654
- const placeholder = '`' + (0, crypto_1.randomUUID)() + '`';
3658
+ const placeholder = '`' + (0, node_crypto_1.randomUUID)() + '`';
3655
3659
  replaceMap.push([placeholder, segment]);
3656
3660
  current = replaceMatch(bracket, current, placeholder, pattern);
3657
3661
  }
@@ -3664,7 +3668,7 @@ class ChromeDocument extends Document {
3664
3668
  for (let i = 0, length = values.length; i < length; ++i) {
3665
3669
  const seg = values[i];
3666
3670
  if (/^url\([^{}]*[{}].*\)$/is.test(seg)) {
3667
- replaceMap.push([values[i] = (0, crypto_1.randomUUID)(), seg]);
3671
+ replaceMap.push([values[i] = (0, node_crypto_1.randomUUID)(), seg]);
3668
3672
  }
3669
3673
  }
3670
3674
  if (replaceMap.length > 0) {
@@ -3783,7 +3787,7 @@ class ChromeDocument extends Document {
3783
3787
  modified = true;
3784
3788
  return output + target.substring(index);
3785
3789
  }
3786
- return !child ? target : '';
3790
+ return child ? '' : target;
3787
3791
  })(current, false);
3788
3792
  }
3789
3793
  if (usedVariables) {
@@ -3849,9 +3853,8 @@ class ChromeDocument extends Document {
3849
3853
  }
3850
3854
  }
3851
3855
  get elements() {
3852
- const result = this._elements;
3853
- if (result) {
3854
- return result;
3856
+ if (this._elements) {
3857
+ return this._elements;
3855
3858
  }
3856
3859
  const elements = new Set();
3857
3860
  const host = this.host;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/chrome",
3
- "version": "0.8.3",
3
+ "version": "0.9.0",
4
4
  "description": "Chrome document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -14,16 +14,15 @@
14
14
  },
15
15
  "keywords": [
16
16
  "squared",
17
- "e-mc",
18
- "squared-functions"
17
+ "e-mc"
19
18
  ],
20
19
  "author": "An Pham <anpham6@gmail.com>",
21
20
  "license": "MIT",
22
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
23
22
  "dependencies": {
24
- "@e-mc/cloud": "^0.10.3",
25
- "@e-mc/core": "^0.10.3",
26
- "@e-mc/document": "^0.10.3",
27
- "@e-mc/types": "^0.10.3"
23
+ "@e-mc/cloud": "^0.11.0",
24
+ "@e-mc/core": "^0.11.0",
25
+ "@e-mc/document": "^0.11.0",
26
+ "@e-mc/types": "^0.11.0"
28
27
  }
29
28
  }
package/types/index.d.ts CHANGED
@@ -63,7 +63,7 @@ export interface FinalizeProcessing<T extends IFileManager<U>, U extends Documen
63
63
  readonly contentMap: StringMap;
64
64
  readonly bufferMap: ObjectMap<Bufferable>;
65
65
  readonly cacheMiss: string[];
66
- readonly productionRelease: Undef<true>;
66
+ readonly productionRelease: true | undefined;
67
67
  }
68
68
 
69
69
  export interface DocumentComponent<T = boolean> extends IDocumentComponent<T, T>, DocumentComponentExtended<T> {}
@@ -92,7 +92,7 @@ export interface UserConfig extends CssRuleData, Omit<DocumentOutput, OutputType
92
92
  }
93
93
 
94
94
  export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset, V extends ICloud = ICloud<T>> extends IDocument<T, U, DocumentModule, DocumentComponent, DocumentComponentOption, V>, Pick<DocumentOutput, OutputType> {
95
- htmlFile: Null<U>;
95
+ htmlFile: U | null;
96
96
  cssFiles: U[];
97
97
  jsFiles: U[];
98
98
  svgFiles: U[];
@@ -103,16 +103,16 @@ export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAs
103
103
  replaced: U[];
104
104
  formatMap?: ObjectMap<FormatUri>;
105
105
  setElementSrc(asset: U, element: IXmlElement, value: string): void;
106
- findDataValue(name: string): Undef<string>;
106
+ findDataValue(name: string): string | undefined;
107
107
  setInlinedAttributes(processing: FinalizeProcessing<T, U>): void;
108
108
  applyTransforms(processing: FinalizeProcessing<T, U>): Promise<void>;
109
109
  rewriteHtml(processing: FinalizeProcessing<T, U>): Promise<void>;
110
110
  setElementAttributes(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
111
111
  applyDataSource(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
112
112
  setProductionAttributes(processing: FinalizeProcessing<T, U>): void;
113
- removeUnusedStyles(source: string, options?: UserConfig): Undef<string>;
113
+ removeUnusedStyles(source: string, options?: UserConfig): string | undefined;
114
114
  removeServerRoot(value: string): string;
115
- replaceContent(source: string, match: RegExpExecArray | string, mimeType?: string): Undef<string>;
115
+ replaceContent(source: string, match: RegExpExecArray | string, mimeType?: string): string | undefined;
116
116
  cloudInit(state: CloudScopeOrigin<T, U, V>): void;
117
117
  cloudObject(state: CloudScopeOrigin<T, U, V>, file: U): boolean;
118
118
  cloudUpload(state: CloudScopeOrigin<T, U, V>, file: U, url: string, active: boolean): Promise<boolean>;
@@ -19,8 +19,8 @@ interface DataObject extends CascadeAction {
19
19
  }
20
20
 
21
21
  interface ScopeData {
22
- start: Null<string>;
23
- end: Null<string>;
22
+ start: string | null;
23
+ end: string | null;
24
24
  }
25
25
 
26
26
  interface ConditionProperty {
@@ -36,7 +36,7 @@ export interface UserAgentData {
36
36
  name: string;
37
37
  brand: string;
38
38
  browser: number;
39
- version: Null<number[]>;
39
+ version: number[] | null;
40
40
  majorVersion: number;
41
41
  mobile: boolean;
42
42
  }
@@ -53,17 +53,7 @@ export interface DocumentOutput {
53
53
  escapeReservedCharacters?: boolean;
54
54
  ignoreServerCodeBlocks?: string[];
55
55
  sanitizeFramework?: string[];
56
- webBundle?: {
57
- rootDirAlias?: string;
58
- baseUrl?: string;
59
- primaryUrl?: string;
60
- copyTo?: string;
61
- rewriteHtmlPage?: boolean | string;
62
- excludeHtmlPage?: boolean;
63
- excludeTransforms?: boolean;
64
- includeScopes?: string[];
65
- excludeScopes?: string[];
66
- };
56
+ webBundle?: unknown;
67
57
  templateMap?: TemplateMap;
68
58
  userAgentData?: Partial<UserAgentData>;
69
59
  }
@@ -109,7 +99,7 @@ export interface DataSource<T = string> extends IDataSource<T>, ElementAction {
109
99
  source: "cloud" | "json" | "uri" | "local" | "export" | DbSource;
110
100
  type?: "text" | "attribute" | "display";
111
101
  dynamic?: boolean;
112
- value?: ArrayOf<string> | AnyObject;
102
+ value?: string | string[] | AnyObject;
113
103
  template?: string;
114
104
  viewEngine?: ViewEngine | string;
115
105
  ignoreEmpty?: boolean;
@@ -144,5 +134,4 @@ export interface ExportDataSource extends DataSource, CascadeAction {
144
134
  pathname?: string;
145
135
  settings?: string;
146
136
  params?: unknown;
147
- persist?: boolean;
148
137
  }