@pi-r/chrome 0.2.1 → 0.3.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.
Files changed (3) hide show
  1. package/index.js +147 -130
  2. package/package.json +5 -5
  3. package/types/index.d.ts +2 -1
package/index.js CHANGED
@@ -38,9 +38,13 @@ const REGEXP_FONTFACE_UNSAFE = new RegExp(`(\\s*)@font-face\\s*{([^}]+)}` + dom_
38
38
  const REGEXP_FONTFAMILY_UNSAFE = /font-family\s*:([^;}]+)/i;
39
39
  const REGEXP_KEYFRAMES_UNSAFE = /(\s*)@keyframes\s+([^{]+){/gi;
40
40
  const REGEXP_NTHCHILD_UNSAFE = /\(\s*([+-])?(?:(\d*)[nN]|(0))\s*([+-])?\s*(\d*)\s*\)/g;
41
+ const REGEXP_OBJECT_NAME = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
42
+ const REGEXP_OBJECT_SUBSCRIPT = /\[\s*(["'])?(.+?)\1\s*\]/g;
43
+ const REGEXP_TEMPLATE_LEADING = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
44
+ const REGEXP_TEMPLATE_TRAILING = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
41
45
  function removeNamespace(name, source, newline, comments) {
42
46
  if (source.indexOf('-' + name) !== -1) {
43
- const dataset = CACHE_DATASET[name] || (CACHE_DATASET[name] = [
47
+ const [a, b, c, d, e] = CACHE_DATASET[name] || (CACHE_DATASET[name] = [
44
48
  new RegExp(`(\\s*)<(script|style)(${dom_1.DomWriter.PATTERN_TAGOPEN}+)>[\\S\\s]*?<\\/\\2\\s*>` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi'),
45
49
  new RegExp(`(\\s*)<link(${dom_1.DomWriter.PATTERN_TAGOPEN}+)>` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi'),
46
50
  new RegExp(`\\s+data-${name}-[a-z-]+\\s*` + dom_1.DomWriter.PATTERN_ATTRVALUE, 'g'),
@@ -48,24 +52,26 @@ function removeNamespace(name, source, newline, comments) {
48
52
  new RegExp(`data-${name}-template\\s*` + dom_1.DomWriter.PATTERN_ATTRVALUE)
49
53
  ]);
50
54
  source = source
51
- .replace(dataset[0], (...capture) => dataset[3].test(capture[3]) || dataset[4].test(capture[3]) ? getNewlineString(capture[1], capture[7], newline) : capture[0])
52
- .replace(dataset[1], (...capture) => dataset[3].test(capture[2]) ? getNewlineString(capture[1], capture[6], newline) : capture[0])
53
- .replace(dataset[2], '');
55
+ .replace(a, (...capture) => d.test(capture[3]) || e.test(capture[3]) ? getNewlineString(capture[1], capture[7], newline) : capture[0])
56
+ .replace(b, (...capture) => d.test(capture[2]) ? getNewlineString(capture[1], capture[6], newline) : capture[0])
57
+ .replace(c, '');
54
58
  }
55
59
  return (0, types_1.isArray)(comments) ? source.replace(REGEXP_BLOCKEXCLUDE, (...capture) => getNewlineString(capture[1], capture[2], newline)) : source;
56
60
  }
57
61
  function getObjectValue(value, key) {
58
- const pattern = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
62
+ REGEXP_OBJECT_NAME.lastIndex = 0;
59
63
  let found, match;
60
- while (match = pattern.exec(key)) {
64
+ while (match = REGEXP_OBJECT_NAME.exec(key)) {
61
65
  if ((0, types_1.isObject)(value)) {
62
66
  value = value[match[1]];
63
- if (match[2]) {
64
- const subscript = /\[\s*(["'])?(.+?)\1\s*\]/g;
67
+ const name = match[2];
68
+ if (name) {
69
+ REGEXP_OBJECT_SUBSCRIPT.lastIndex = 0;
65
70
  let index;
66
- while (index = subscript.exec(match[2])) {
67
- const attr = index[1] ? index[2] : index[2].trim();
68
- if (index[1] && (0, types_1.isObject)(value) || /^\d+$/.test(attr) && (typeof value === 'string' || (0, types_1.isObject)(value))) {
71
+ while (index = REGEXP_OBJECT_SUBSCRIPT.exec(name)) {
72
+ const quote = index[1];
73
+ const attr = quote ? index[2] : index[2].trim();
74
+ if (quote && (0, types_1.isObject)(value) || /^\d+$/.test(attr) && (typeof value === 'string' || (0, types_1.isObject)(value))) {
69
75
  value = value[attr];
70
76
  }
71
77
  else {
@@ -83,14 +89,14 @@ function getObjectValue(value, key) {
83
89
  return found ? value : null;
84
90
  }
85
91
  function trimTemplate(value) {
86
- const leading = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
92
+ REGEXP_TEMPLATE_LEADING.lastIndex = 0;
87
93
  let match;
88
- while (match = leading.exec(value)) {
89
- value = replaceMatch(match, value, 1, leading);
94
+ while (match = REGEXP_TEMPLATE_LEADING.exec(value)) {
95
+ value = replaceMatch(match, value, 1, REGEXP_TEMPLATE_LEADING);
90
96
  }
91
- const trailing = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
92
- while (match = trailing.exec(value)) {
93
- value = replaceMatch(match, value, 1, trailing);
97
+ REGEXP_TEMPLATE_TRAILING.lastIndex = 0;
98
+ while (match = REGEXP_TEMPLATE_TRAILING.exec(value)) {
99
+ value = replaceMatch(match, value, 1, REGEXP_TEMPLATE_TRAILING);
94
100
  }
95
101
  return value;
96
102
  }
@@ -123,23 +129,9 @@ function findClosingIndex(source, lastIndex) {
123
129
  }
124
130
  return [endIndex, trailing];
125
131
  }
126
- function getPackageName(err, value) {
132
+ function getPackageName(err) {
127
133
  if (err instanceof Error && err.code === types_1.ERR_CODE.MODULE_NOT_FOUND) {
128
- switch (value) {
129
- case 'mongodb':
130
- case 'redis':
131
- return value;
132
- case 'mysql':
133
- return 'mysql2';
134
- case 'postgres':
135
- return 'pg';
136
- case 'oracle':
137
- return 'oracledb';
138
- case 'mssql':
139
- return 'tedious';
140
- default:
141
- return (0, util_1.getModuleName)(err);
142
- }
134
+ return (0, util_1.getModuleName)(err);
143
135
  }
144
136
  }
145
137
  function getCacheItem(map, key) {
@@ -182,9 +174,9 @@ function hasCondition(data, condition) {
182
174
  }
183
175
  let match = REGEXP_TEMPLATEMATCH.exec(condition.trim());
184
176
  if (match) {
185
- if (match[2]) {
177
+ const comparison = match[2];
178
+ if (comparison) {
186
179
  const join = match[1];
187
- const comparison = match[2];
188
180
  const items = [];
189
181
  while (match = REGEXP_TEMPLATECOMPARISON.exec(comparison)) {
190
182
  if (items.length && !isSpace(match[0][0])) {
@@ -289,17 +281,14 @@ function hasSameOrigin(value, ...other) {
289
281
  return false;
290
282
  }
291
283
  function restoreSearchParams(value, prefix = '__sqd') {
292
- if (value) {
293
- if (value.indexOf(prefix) !== -1) {
294
- const params = new URLSearchParams(value);
295
- params.forEach((_, key) => key.startsWith(prefix) && params.delete(key));
296
- if (value = params.toString()) {
297
- return '?' + value;
298
- }
284
+ if (value?.indexOf(prefix) !== -1) {
285
+ const params = new URLSearchParams(value);
286
+ params.forEach((_, key) => key.startsWith(prefix) && params.delete(key));
287
+ if (value = params.toString()) {
288
+ return '?' + value;
299
289
  }
300
- return value;
301
290
  }
302
- return '';
291
+ return value || '';
303
292
  }
304
293
  function getBaseURLs(asset, baseUrl) {
305
294
  const result = [];
@@ -329,26 +318,27 @@ function getBaseURLs(asset, baseUrl) {
329
318
  }
330
319
  function createHash(host, file, bufferMap) {
331
320
  const hash = file.hash;
332
- if (hash) {
333
- try {
334
- const localUri = file.localUri;
335
- const buffer = localUri && bufferMap[localUri] || getBuffer(file);
336
- if (buffer) {
337
- const [algorithm, length] = (0, util_1.getHashData)(hash);
338
- let value;
339
- if (algorithm && (value = Document.asHash(buffer, { algorithm, encoding: file.encoding }))) {
340
- if (localUri) {
341
- bufferMap[localUri] = buffer;
342
- }
343
- host.rename(file, (0, util_1.appendSuffix)(file.filename, length ? value.substring(0, length) : value));
344
- return file.filename;
321
+ if (!hash) {
322
+ return;
323
+ }
324
+ const { filename, localUri } = file;
325
+ try {
326
+ const buffer = localUri && bufferMap[localUri] || getBuffer(file);
327
+ if (buffer) {
328
+ const [algorithm, length] = (0, util_1.getHashData)(hash);
329
+ let value;
330
+ if (algorithm && (value = Document.asHash(buffer, { algorithm, encoding: file.encoding }))) {
331
+ if (localUri) {
332
+ bufferMap[localUri] = buffer;
345
333
  }
334
+ host.rename(file, (0, util_1.appendSuffix)(filename, length ? value.substring(0, length) : value));
335
+ return file.filename;
346
336
  }
347
- throw (0, types_1.errorMessage)('hash', 'Source not found', file.filename);
348
- }
349
- catch (err) {
350
- host.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, file.filename], err, 32 /* LOG_TYPE.FILE */);
351
337
  }
338
+ throw (0, types_1.errorMessage)('hash', 'Source not found', filename);
339
+ }
340
+ catch (err) {
341
+ host.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, filename], err, 32 /* LOG_TYPE.FILE */);
352
342
  }
353
343
  }
354
344
  function getSrcURL(parent, file) {
@@ -668,7 +658,7 @@ function transformOptions(file, mimeType, code, bundleContent) {
668
658
  const metadata = { userAgentData: this.userAgentData };
669
659
  switch (mimeType) {
670
660
  case 'text/html':
671
- metadata['__fromhtml__'] = true;
661
+ metadata.__fromhtml__ = true;
672
662
  case 'text/css':
673
663
  Object.assign(metadata, this.config);
674
664
  default:
@@ -767,11 +757,12 @@ function replaceCss(file) {
767
757
  map[id] = this.removeServerRoot(map[id]);
768
758
  }
769
759
  };
770
- if (file.inlineUrlMap) {
771
- sanitize(file.inlineUrlMap);
760
+ const { inlineUrlMap, inlineUrlCloudMap } = file;
761
+ if (inlineUrlMap) {
762
+ sanitize(inlineUrlMap);
772
763
  }
773
- if (file.inlineUrlCloudMap) {
774
- sanitize(file.inlineUrlCloudMap);
764
+ if (inlineUrlCloudMap) {
765
+ sanitize(inlineUrlCloudMap);
775
766
  }
776
767
  }
777
768
  function replaceHtml(source, { productionRelease, contentMap }, cssMap) {
@@ -848,6 +839,10 @@ async function checkData(item, name, result, validate) {
848
839
  }
849
840
  }
850
841
  }
842
+ function getBuffer(item) {
843
+ let localUri;
844
+ return item.sourceUTF8 || item.buffer || ((localUri = item.localUri) && isPath(localUri) ? fs.readFileSync(localUri, item.encoding) : null);
845
+ }
851
846
  const getNewlineString = dom_1.DomWriter.getNewlineString.bind(dom_1.DomWriter);
852
847
  const isSpace = dom_1.DomWriter.isSpace.bind(dom_1.DomWriter);
853
848
  const replaceMatch = dom_1.DomWriter.replaceMatch.bind(dom_1.DomWriter);
@@ -858,11 +853,10 @@ const asString = Document.asString.bind(Document);
858
853
  const resolvePath = Document.resolvePath.bind(Document);
859
854
  const toPosix = Document.toPosix.bind(Document);
860
855
  const isDir = Document.isDir.bind(Document);
861
- const hasSourceMap = (metadata, value) => (0, types_1.isObject)(metadata) && metadata['__sourcemap__'] === value;
856
+ const hasSourceMap = (metadata, value) => (0, types_1.isObject)(metadata) && metadata.__sourcemap__ === value;
862
857
  const isBundled = (value, main) => typeof value === 'number' && (value > 0 || main && value === 0);
863
858
  const isFont = (value) => value === 'truetype' || value === 'opentype' || value === 'woff' || value === 'woff2';
864
859
  const isImage = (value) => typeof value === 'string' && value.startsWith('image/') && value !== 'image/svg+xml';
865
- const getBuffer = (item) => item.sourceUTF8 || item.buffer || (item.localUri && isPath(item.localUri) ? fs.readFileSync(item.localUri, item.encoding) : null);
866
860
  const isRemoved = (item) => item.exclude === true || isBundled(item.bundleIndex);
867
861
  const isUnedited = (item) => !item.attributes && !item.inlineContent && !item.srcSet && !item.element.dynamic && item.element.textContent === undefined && (!item.uri && !isBundled(item.bundleIndex, true) || (0, util_1.hasValue)(item.format, 'crossorigin'));
868
862
  const isIgnored = (item, exists) => item.invalid || (0, types_1.ignoreFlag)(item.flags) || !exists && (0, types_1.existsFlag)(item.flags);
@@ -1033,15 +1027,16 @@ class ChromeDocument extends Document {
1033
1027
  const items = new Set((asset.watch.assets || []));
1034
1028
  (function recurse(children) {
1035
1029
  for (const item of children) {
1036
- if (!items.has(item)) {
1037
- if (isWatched.call(instance, item)) {
1038
- item.flags |= 8 /* ASSET_FLAG.WATCH */;
1039
- }
1040
- items.add(item);
1041
- const next = related.get(item);
1042
- if (next) {
1043
- recurse(next);
1044
- }
1030
+ if (items.has(item)) {
1031
+ continue;
1032
+ }
1033
+ if (isWatched.call(instance, item)) {
1034
+ item.flags |= 8 /* ASSET_FLAG.WATCH */;
1035
+ }
1036
+ items.add(item);
1037
+ const next = related.get(item);
1038
+ if (next) {
1039
+ recurse(next);
1045
1040
  }
1046
1041
  }
1047
1042
  })(includes);
@@ -1050,34 +1045,37 @@ class ChromeDocument extends Document {
1050
1045
  }
1051
1046
  }
1052
1047
  let productionRelease = instance.productionRelease;
1053
- if ((0, types_1.isString)(productionRelease)) {
1054
- if (path.isAbsolute(productionRelease = path.normalize(productionRelease)) && isDir(productionRelease)) {
1055
- if (this.canWrite(productionRelease)) {
1056
- const serverRoot = ChromeDocument.INTERNAL_SERVERROOT;
1057
- const srcDir = path.join(this.baseDirectory, serverRoot);
1058
- if (isDir(srcDir)) {
1059
- const result = await Document.copyDir(srcDir, productionRelease, this.incremental !== 'staging');
1060
- const failed = result.failed.map(value => this.removeCwd(value));
1061
- for (const value of this.files) {
1062
- if (value.startsWith(serverRoot)) {
1063
- if (!failed.includes(value)) {
1064
- this.delete(value);
1065
- }
1066
- else {
1067
- instance.writeFail(["Unable to move file" /* ERR_MESSAGE.MOVE_FILE */, instance.moduleName], (0, types_1.errorMessage)('production', path.join(this.baseDirectory, value)), { fatal: true });
1068
- }
1069
- }
1070
- }
1071
- }
1048
+ if (!(0, types_1.isString)(productionRelease)) {
1049
+ return;
1050
+ }
1051
+ if (path.isAbsolute(productionRelease = path.normalize(productionRelease)) && isDir(productionRelease)) {
1052
+ if (this.canWrite(productionRelease)) {
1053
+ const serverRoot = ChromeDocument.INTERNAL_SERVERROOT;
1054
+ const srcDir = path.join(this.baseDirectory, serverRoot);
1055
+ if (!isDir(srcDir)) {
1056
+ return;
1072
1057
  }
1073
- else {
1074
- instance.writeFail(["Unable to write directory" /* ERR_MESSAGE.WRITE_DIRECTORY */, instance.moduleName], (0, types_1.errorMessage)('production', 'Access denied', productionRelease));
1058
+ const result = await Document.copyDir(srcDir, productionRelease, this.incremental !== 'staging');
1059
+ const failed = result.failed.map(value => this.removeCwd(value));
1060
+ for (const value of this.files) {
1061
+ if (!value.startsWith(serverRoot)) {
1062
+ continue;
1063
+ }
1064
+ if (!failed.includes(value)) {
1065
+ this.delete(value);
1066
+ }
1067
+ else {
1068
+ instance.writeFail(["Unable to move file" /* ERR_MESSAGE.MOVE_FILE */, instance.moduleName], (0, types_1.errorMessage)('production', path.join(this.baseDirectory, value)), { fatal: true });
1069
+ }
1075
1070
  }
1076
1071
  }
1077
1072
  else {
1078
- instance.writeFail(["Unable to read directory" /* ERR_MESSAGE.READ_DIRECTORY */, instance.moduleName], (0, types_1.errorMessage)('production', 'Invalid directory', productionRelease), 32 /* LOG_TYPE.FILE */);
1073
+ instance.writeFail(["Unable to write directory" /* ERR_MESSAGE.WRITE_DIRECTORY */, instance.moduleName], (0, types_1.errorMessage)('production', 'Access denied', productionRelease));
1079
1074
  }
1080
1075
  }
1076
+ else {
1077
+ instance.writeFail(["Unable to read directory" /* ERR_MESSAGE.READ_DIRECTORY */, instance.moduleName], (0, types_1.errorMessage)('production', 'Invalid directory', productionRelease), 32 /* LOG_TYPE.FILE */);
1078
+ }
1081
1079
  }
1082
1080
  static sanitizeAssets(assets, exclusions = []) {
1083
1081
  assets.forEach(item => {
@@ -1158,8 +1156,9 @@ class ChromeDocument extends Document {
1158
1156
  }
1159
1157
  return 0;
1160
1158
  });
1159
+ let imports;
1161
1160
  if (config) {
1162
- const { useUnsafeReplace, baseUrl, productionRelease, productionIncremental, templateMap, userAgentData, imports, cache } = config;
1161
+ const { useUnsafeReplace, baseUrl, productionRelease, productionIncremental, templateMap, userAgentData, cache } = config;
1163
1162
  const target = this.config;
1164
1163
  for (const attr in config) {
1165
1164
  if (attr in target) {
@@ -1204,22 +1203,37 @@ class ChromeDocument extends Document {
1204
1203
  if ((0, types_1.isObject)(userAgentData)) {
1205
1204
  this.userAgentData = userAgentData;
1206
1205
  }
1207
- this.imports = (0, types_1.isPlainObject)(imports) ? { ...this.module.imports, ...imports } : this.module.imports;
1208
1206
  if ((0, types_1.isObject)(cache) && 'transform' in cache) {
1209
1207
  this.customize({ transform: cache.transform });
1210
1208
  }
1209
+ if (!(0, types_1.isPlainObject)(imports = config.imports)) {
1210
+ imports = undefined;
1211
+ }
1211
1212
  }
1212
1213
  super.init(assets, config);
1213
1214
  const mimeMap = this._mimeMap;
1214
- if (mimeMap && 'format' in mimeMap) {
1215
- const format = mimeMap.format;
1216
- if ((0, types_1.isObject)(format)) {
1217
- this.formatMap = 'pathname' in format || 'filename' in format || 'dictionary' in format ? { uuid: format } : format;
1215
+ if (mimeMap) {
1216
+ if ('imports' in mimeMap) {
1217
+ const imported = mimeMap.imports;
1218
+ if ((0, types_1.isPlainObject)(imported)) {
1219
+ imports = imports ? Object.assign(imported, imports) : imported;
1220
+ }
1221
+ delete mimeMap.imports;
1218
1222
  }
1219
- else {
1220
- this.formatMap = undefined;
1223
+ if ('format' in mimeMap) {
1224
+ const format = mimeMap.format;
1225
+ if ((0, types_1.isObject)(format)) {
1226
+ this.formatMap = 'pathname' in format || 'filename' in format || 'dictionary' in format ? { uuid: format } : format;
1227
+ }
1228
+ else {
1229
+ this.formatMap = undefined;
1230
+ }
1231
+ delete mimeMap.format;
1221
1232
  }
1222
1233
  }
1234
+ if (imports) {
1235
+ this.imports = imports;
1236
+ }
1223
1237
  for (const storage of cloud) {
1224
1238
  for (const { service, upload, download } of storage) {
1225
1239
  if (upload) {
@@ -1643,8 +1657,9 @@ class ChromeDocument extends Document {
1643
1657
  this._cloudUrlMap = Object.create(null);
1644
1658
  this._cloudUploaded = new Set();
1645
1659
  this._cloudEndpoint = null;
1646
- if (this.htmlFile) {
1647
- const endpoint = instance.getStorage('upload', this.htmlFile.cloudStorage)?.upload?.endpoint;
1660
+ const htmlFile = this.htmlFile;
1661
+ if (htmlFile) {
1662
+ const endpoint = instance.getStorage('upload', htmlFile.cloudStorage)?.upload?.endpoint;
1648
1663
  if (endpoint) {
1649
1664
  this._cloudEndpoint = new RegExp((0, types_1.escapePattern)(toPosix(endpoint)) + '/', 'g');
1650
1665
  }
@@ -1822,9 +1837,7 @@ class ChromeDocument extends Document {
1822
1837
  }
1823
1838
  }
1824
1839
  search ?? (search = restoreSearchParams(asset.url?.search));
1825
- if (status) {
1826
- status = status.filter(item => item.type >= types_1.STATUS_TYPE.FATAL && item.type <= types_1.STATUS_TYPE.WARN);
1827
- }
1840
+ status && (status = status.filter(item => item.type >= types_1.STATUS_TYPE.FATAL && item.type <= types_1.STATUS_TYPE.WARN));
1828
1841
  watch.send(types_1.WATCH_EVENT.MODIFIED, {
1829
1842
  action: pathname && watch.hot && !watch.main ? 'hot' : '',
1830
1843
  type: asset.mimeType,
@@ -1999,8 +2012,9 @@ class ChromeDocument extends Document {
1999
2012
  item.modified = true;
2000
2013
  }
2001
2014
  source = sanitizeSource(item, source);
2002
- if (item.format) {
2003
- const result = await this.transform('html', source, item.format, transformOptions.call(this, item, 'image/svg+xml'));
2015
+ const format = item.format;
2016
+ if (format) {
2017
+ const result = await this.transform('html', source, format, transformOptions.call(this, item, 'image/svg+xml'));
2004
2018
  if (result) {
2005
2019
  item.modified = true;
2006
2020
  source = result.code;
@@ -2110,11 +2124,12 @@ class ChromeDocument extends Document {
2110
2124
  await this.setElementAttributes(processing, domBase);
2111
2125
  await this.applyDataSource(processing, domBase);
2112
2126
  for (const item of this.assets) {
2113
- if (item.element && isRemoved(item) && !(0, types_1.ignoreFlag)(item.flags)) {
2114
- const domElement = new dom_1.HtmlElement(moduleName, item.element, item.attributes);
2127
+ const element = item.element;
2128
+ if (element && isRemoved(item) && !(0, types_1.ignoreFlag)(item.flags)) {
2129
+ const domElement = new dom_1.HtmlElement(moduleName, element, item.attributes);
2115
2130
  domElement.remove = true;
2116
2131
  if (!domBase.write(domElement)) {
2117
- this.writeFail('Unable to exclude HTML element', errorHtml(item.element), 4 /* LOG_TYPE.PROCESS */);
2132
+ this.writeFail('Unable to exclude HTML element', errorHtml(element), 4 /* LOG_TYPE.PROCESS */);
2118
2133
  }
2119
2134
  }
2120
2135
  }
@@ -2135,13 +2150,15 @@ class ChromeDocument extends Document {
2135
2150
  if ((0, types_1.isString)(config.stripCommentsAndCDATA)) {
2136
2151
  source = dom_1.DomWriter.getCommentsAndCDATA(source, config.stripCommentsAndCDATA, true, true);
2137
2152
  }
2138
- if (htmlFile.format) {
2139
- const result = await this.transform('html', source, htmlFile.format, {
2153
+ const format = htmlFile.format;
2154
+ if (format) {
2155
+ const { filename, uri, encoding, metadata } = htmlFile;
2156
+ const result = await this.transform('html', source, format, {
2140
2157
  pathname: path.dirname(localUri),
2141
- filename: htmlFile.filename,
2158
+ filename,
2142
2159
  mimeType: 'text/html',
2143
- metadata: Object.assign({ '__fromhtml__': true, ...this.config }, htmlFile.metadata),
2144
- cacheData: !productionRelease || this.productionIncremental ? { uri: htmlFile.uri, encoding: htmlFile.encoding } : undefined
2160
+ metadata: Object.assign({ '__fromhtml__': true, ...this.config }, metadata),
2161
+ cacheData: !productionRelease || this.productionIncremental ? { uri, encoding } : undefined
2145
2162
  });
2146
2163
  if (result) {
2147
2164
  source = result.code;
@@ -2175,12 +2192,12 @@ class ChromeDocument extends Document {
2175
2192
  const cloud = host.Cloud;
2176
2193
  const removeWatchReload = (item) => (0, types_1.isObject)(item.watch) && delete item.watch.reload;
2177
2194
  for (const item of this.assets) {
2178
- const element = item.element;
2195
+ const { element, inlineContent } = item;
2179
2196
  if (!element || element.removed || isRemoved(item) || isUnedited(item) || (0, types_1.ignoreFlag)(item.flags) && !(0, types_1.processFlag)(item.flags)) {
2180
2197
  continue;
2181
2198
  }
2182
2199
  const domElement = new dom_1.HtmlElement(moduleName, element, item.attributes);
2183
- if (item.inlineContent) {
2200
+ if (inlineContent) {
2184
2201
  let [innerXml, sourceMappingURL, inlineMap] = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(item).trim());
2185
2202
  if (sourceMappingURL && !inlineMap && item.localUri) {
2186
2203
  let mapUri = path.resolve(sourceMappingURL = decodeURIComponent(sourceMappingURL));
@@ -2189,7 +2206,7 @@ class ChromeDocument extends Document {
2189
2206
  }
2190
2207
  host.deleteFile(mapUri);
2191
2208
  }
2192
- domElement.tagName = item.inlineContent;
2209
+ domElement.tagName = inlineContent;
2193
2210
  domElement.innerXml = innerXml;
2194
2211
  domElement.removeAttribute('src', 'href');
2195
2212
  }
@@ -2279,10 +2296,10 @@ class ChromeDocument extends Document {
2279
2296
  }
2280
2297
  }
2281
2298
  if (!domBase.write(domElement)) {
2282
- this.writeFail(item.inlineContent ? 'Inline tag replacement' : 'Element attribute replacement', errorHtml(element), { type: 4 /* LOG_TYPE.PROCESS */, startTime });
2299
+ this.writeFail(inlineContent ? 'Inline tag replacement' : 'Element attribute replacement', errorHtml(element), { type: 4 /* LOG_TYPE.PROCESS */, startTime });
2283
2300
  delete item.inlineUrlCloud;
2284
2301
  }
2285
- else if (item.inlineContent) {
2302
+ else if (inlineContent) {
2286
2303
  host.removeAsset(item);
2287
2304
  removeWatchReload(item);
2288
2305
  }
@@ -2309,7 +2326,7 @@ class ChromeDocument extends Document {
2309
2326
  };
2310
2327
  const errorCredential = (item, err) => {
2311
2328
  removeElement(item);
2312
- const pkg = getPackageName(err, item.source);
2329
+ const pkg = getPackageName(err);
2313
2330
  if (!(pkg && this.checkPackage(err, pkg))) {
2314
2331
  this.writeFail(["Invalid credentials" /* ERR_DB.CREDENTIALS */, item.source], err);
2315
2332
  }
@@ -2778,7 +2795,7 @@ class ChromeDocument extends Document {
2778
2795
  }
2779
2796
  catch (err) {
2780
2797
  this.abort(type);
2781
- const pkg = getPackageName(err, type);
2798
+ const pkg = getPackageName(err);
2782
2799
  errorClient(current, pkg && this.checkPackage(err, pkg) ? null : err);
2783
2800
  }
2784
2801
  break;
@@ -2879,7 +2896,7 @@ class ChromeDocument extends Document {
2879
2896
  for (let j = 0, match; j < items.length; ++j) {
2880
2897
  const row = items[j];
2881
2898
  if ((0, types_1.isPlainObject)(row)) {
2882
- row['__index__'] ?? (row['__index__'] = j + 1);
2899
+ row.__index__ ?? (row.__index__ = j + 1);
2883
2900
  }
2884
2901
  let segment = template;
2885
2902
  while (match = REGEXP_TEMPLATECONDITIONAL.exec(segment)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/chrome",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
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.2",
24
- "@e-mc/core": "^0.5.2",
25
- "@e-mc/document": "^0.5.2",
26
- "@e-mc/types": "^0.5.2"
23
+ "@e-mc/cloud": "^0.6.0",
24
+ "@e-mc/core": "^0.6.0",
25
+ "@e-mc/document": "^0.6.0",
26
+ "@e-mc/types": "^0.6.0"
27
27
  }
28
28
  }
package/types/index.d.ts CHANGED
@@ -104,10 +104,11 @@ export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAs
104
104
  cloudObject(state: CloudScopeOrigin<T, U, V>, file: U): boolean;
105
105
  cloudUpload(state: CloudScopeOrigin<T, U, V>, file: U, url: string, active: boolean): Promise<boolean>;
106
106
  cloudFinalize(state: CloudScopeOrigin<T, U, V>): Promise<unknown[]>;
107
- get settings(): ChromeDocumentSettings;
108
107
  get editing(): U[];
108
+ set dataSource(value);
109
109
  get dataSource(): DataSource[];
110
110
  get elements(): XmlTagNode[];
111
+ get settings(): ChromeDocumentSettings;
111
112
  }
112
113
 
113
114
  export interface ChromeDocumentConstructor<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> extends DocumentConstructor<T, U> {