@pi-r/chrome 0.2.2 → 0.2.9

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 An Pham
1
+ Copyright 2020-24 Code Geass
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/README.md CHANGED
@@ -1,5 +1,7 @@
1
- ### @pi-r/chrome
1
+ # @pi-r/chrome
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever Josee + Nunnally
4
+
5
+ ## LICENSE
4
6
 
5
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,5 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  const path = require("path");
4
3
  const fs = require("fs");
5
4
  const asset_1 = require("@e-mc/document/asset");
@@ -25,6 +24,14 @@ const [PATTERN_STRING_SOME, PATTERN_STRING_MANY] = (function () {
25
24
  const pattern = '(?:\\s|' + dom_1.DomWriter.PATTERN_COMMENT + '|`[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}`)';
26
25
  return [pattern + '*', pattern + '+'];
27
26
  })();
27
+ const [REGEXP_NTHCHILD, REGEXP_NTHCHILD_UNSAFE, REGEXP_REPLACECSS] = (function () {
28
+ const parenthesis = '(?:,[^()]+(?=\\))|[^()]|\\([^()]*\\(+|\\([^()]*\\)|(?:\\)[^()]+)?\\)*?)+';
29
+ return [
30
+ new RegExp(`\\(${PATTERN_STRING_SOME}([+-])?(?:(\\d*)[nN]|(0))?${PATTERN_STRING_SOME}([+-])?${PATTERN_STRING_SOME}(\\d*)(?:${PATTERN_STRING_MANY}[oO][fF]${PATTERN_STRING_MANY}(${parenthesis})${PATTERN_STRING_SOME}\\)|${PATTERN_STRING_SOME}\\))`, 'g'),
31
+ new RegExp(`\\(\\s*([+-])?(?:(\\d*)[nN]|(0))?\\s*([+-])?\\s*(\\d*)(?:\\s+[oO][fF]\\s+(${parenthesis})\\s*\\)|\\s*\\))`, 'g'),
32
+ new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')(\\s*layer(?:\\(([^)]*)\\)|\\b))?(?:\\s*supports\\((${parenthesis})\\))?(.*?);?$`)
33
+ ];
34
+ })();
28
35
  const REGEXP_COMMENT = new RegExp(dom_1.DomWriter.PATTERN_COMMENT, 'g');
29
36
  const REGEXP_CONTENT = new RegExp(`\\bcontent${PATTERN_STRING_SOME}:${PATTERN_STRING_SOME}(?:"[^"]*"|'[^']*')`, 'gi');
30
37
  const REGEXP_STYLE = new RegExp(`(<style${dom_1.DomWriter.PATTERN_TAGOPEN}*>)([\\S\\s]*?)(<\\/style\\s*>)`, 'gi');
@@ -32,12 +39,10 @@ const REGEXP_VARIABLES = new RegExp(`(\\s*)(--[^\\s:]*)${PATTERN_STRING_SOME}:[^
32
39
  const REGEXP_FONTFACE = new RegExp(`(\\s*)@font-face${PATTERN_STRING_SOME}{([^}]+)}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
33
40
  const REGEXP_FONTFAMILY = new RegExp(`font-family${PATTERN_STRING_SOME}:([^;}]+)`, 'i');
34
41
  const REGEXP_KEYFRAMES = new RegExp(`(\\s*)@keyframes${PATTERN_STRING_MANY}([^{]+){`, 'gi');
35
- const REGEXP_NTHCHILD = new RegExp(`\\(${PATTERN_STRING_SOME}([+-])?(?:(\\d*)[nN]|(0))${PATTERN_STRING_SOME}([+-])?${PATTERN_STRING_SOME}(\\d*)${PATTERN_STRING_SOME}\\)`, 'g');
36
42
  const REGEXP_VARIABLES_UNSAFE = new RegExp(`(\\s*)(--[^\\s:]*)\\s*:[^;}]*([;}])` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'g');
37
43
  const REGEXP_FONTFACE_UNSAFE = new RegExp(`(\\s*)@font-face\\s*{([^}]+)}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
38
44
  const REGEXP_FONTFAMILY_UNSAFE = /font-family\s*:([^;}]+)/i;
39
45
  const REGEXP_KEYFRAMES_UNSAFE = /(\s*)@keyframes\s+([^{]+){/gi;
40
- const REGEXP_NTHCHILD_UNSAFE = /\(\s*([+-])?(?:(\d*)[nN]|(0))\s*([+-])?\s*(\d*)\s*\)/g;
41
46
  function removeNamespace(name, source, newline, comments) {
42
47
  if (source.indexOf('-' + name) !== -1) {
43
48
  const dataset = CACHE_DATASET[name] || (CACHE_DATASET[name] = [
@@ -123,23 +128,9 @@ function findClosingIndex(source, lastIndex) {
123
128
  }
124
129
  return [endIndex, trailing];
125
130
  }
126
- function getPackageName(err, value) {
131
+ function getPackageName(err) {
127
132
  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
- }
133
+ return (0, util_1.getModuleName)(err);
143
134
  }
144
135
  }
145
136
  function getCacheItem(map, key) {
@@ -156,7 +147,7 @@ function addCacheItem(map, key, data, timeout) {
156
147
  map.set(key, [
157
148
  Date.now(),
158
149
  data,
159
- setTimeout(() => deleteCacheItem(map, key), timeout * 1000 /* TIME.S */)
150
+ setTimeout(() => deleteCacheItem(map, key), timeout * 1000)
160
151
  ]);
161
152
  }
162
153
  function deleteCacheItem(map, key) {
@@ -214,10 +205,10 @@ function hasCondition(data, condition) {
214
205
  if (arg2) {
215
206
  switch (item[0]) {
216
207
  case 'eq':
217
- valid = parseArg(arg1) == parseArg(arg2); // eslint-disable-line eqeqeq
208
+ valid = parseArg(arg1) == parseArg(arg2);
218
209
  break;
219
210
  case 'ne':
220
- valid = parseArg(arg1) != parseArg(arg2); // eslint-disable-line eqeqeq
211
+ valid = parseArg(arg1) != parseArg(arg2);
221
212
  break;
222
213
  case 'lt':
223
214
  valid = parseArg(arg1) < parseArg(arg2);
@@ -347,7 +338,7 @@ function createHash(host, file, bufferMap) {
347
338
  throw (0, types_1.errorMessage)('hash', 'Source not found', file.filename);
348
339
  }
349
340
  catch (err) {
350
- host.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, file.filename], err, 32 /* LOG_TYPE.FILE */);
341
+ host.writeFail(["Unable to read file", file.filename], err, 32);
351
342
  }
352
343
  }
353
344
  }
@@ -489,7 +480,7 @@ function transformURL(host, parent, type, source, importFile) {
489
480
  }
490
481
  }
491
482
  if (asset.initialValue && !asset.initialValue.cacheable) {
492
- parent.flags |= 16 /* ASSET_FLAG.MODIFIED */;
483
+ parent.flags |= 16;
493
484
  }
494
485
  related.push(asset);
495
486
  }
@@ -585,7 +576,7 @@ function transformURL(host, parent, type, source, importFile) {
585
576
  else {
586
577
  related.push(asset);
587
578
  if (!(0, types_1.existsFlag)(asset.flags)) {
588
- asset.flags |= 8 /* ASSET_FLAG.WATCH */;
579
+ asset.flags |= 8;
589
580
  }
590
581
  }
591
582
  modified = true;
@@ -745,12 +736,12 @@ function transformJs(host, file, output) {
745
736
  });
746
737
  }
747
738
  else {
748
- this.writeFail(['Unable to create element entry point', path.basename(chunkUri)], (0, types_1.errorMessage)('js', 'Element not found', chunkUri), 4 /* LOG_TYPE.PROCESS */);
739
+ this.writeFail(['Unable to create element entry point', path.basename(chunkUri)], (0, types_1.errorMessage)('js', 'Element not found', chunkUri), 4);
749
740
  }
750
741
  }
751
742
  }
752
743
  catch (err) {
753
- this.writeFail(["Unable to write file" /* ERR_MESSAGE.WRITE_FILE */, path.basename(chunkUri)], err, 32 /* LOG_TYPE.FILE */);
744
+ this.writeFail(["Unable to write file", path.basename(chunkUri)], err, 32);
754
745
  }
755
746
  }
756
747
  appending?.forEach(item => item.order += order);
@@ -832,19 +823,18 @@ async function checkData(item, name, result, validate) {
832
823
  if (typeof callback === 'function') {
833
824
  try {
834
825
  let output;
835
- // @ts-ignore
836
- if (callback["__cjs__" /* INTERNAL.CJS */]) {
826
+ if (callback["__cjs__"]) {
837
827
  output = await callback(result, item);
838
828
  }
839
829
  else {
840
- output = await callback.apply(Document.enabled("node.process.inline" /* KEY_NAME.NODE_PROCESS_INLINE */) ? process : null, Document.enabled("node.require.inline" /* KEY_NAME.NODE_REQUIRE_INLINE */) ? [result, item, require] : [result, item]);
830
+ output = await callback.apply(Document.enabled("node.process.inline") ? process : null, Document.enabled("node.require.inline") ? [result, item, require] : [result, item]);
841
831
  }
842
832
  if (validate(output)) {
843
833
  return output;
844
834
  }
845
835
  }
846
836
  catch (err) {
847
- this.writeFail(["Unable to parse inline method" /* ERR_MESSAGE.INLINE_METHOD */, name], err);
837
+ this.writeFail(["Unable to parse inline method", name], err);
848
838
  }
849
839
  }
850
840
  }
@@ -872,7 +862,6 @@ const getEndIndex = (match) => match.index + match[0].length;
872
862
  const getRelativeURL = (file) => joinPath(file.moveTo, file.pathname, file.inlineFilename || file.filename) + (!file.static ? restoreSearchParams(file.url?.search) : '');
873
863
  const errorHtml = ({ tagName, tagIndex = -1 }) => (0, types_1.errorMessage)('html', 'Location did not resolve', tagName.toLowerCase() + (tagIndex >= 0 ? ': ' + tagIndex : ''));
874
864
  const errorDataSource = (value, hint) => (0, types_1.errorMessage)('data-source', value, hint);
875
- // @ts-ignore
876
865
  class ChromeDocument extends Document {
877
866
  constructor() {
878
867
  super(...arguments);
@@ -952,7 +941,7 @@ class ChromeDocument extends Document {
952
941
  const { Db: db, htmlFile, assets } = instance;
953
942
  const outHtml = htmlFile && !isIgnored(htmlFile, true);
954
943
  if (db && await db.commit()) {
955
- db.writeTimeElapsed('DB', ["Transactions were committed" /* VAL_MESSAGE.COMMIT_TRANSACTION */, db.moduleName], processing.startTime, { ...Document.LOG_STYLE_SUCCESS, type: 65536 /* LOG_TYPE.DB */ });
944
+ db.writeTimeElapsed('DB', ["Transactions were committed", db.moduleName], processing.startTime, { ...Document.LOG_STYLE_SUCCESS, type: 65536 });
956
945
  }
957
946
  if (instance.dataSource.length === 0 && outHtml) {
958
947
  const incremental = htmlFile.incremental ?? this.incremental;
@@ -995,7 +984,7 @@ class ChromeDocument extends Document {
995
984
  }
996
985
  case 'exists':
997
986
  if (hint || isHtmlOnly()) {
998
- this.formatMessage(4 /* LOG_TYPE.PROCESS */, 'HTML', ['No changes detected', 'incremental: ' + incremental], hint, { ...Document.LOG_STYLE_NOTICE, messageBgColor: 'bgWhite', messageColor: 'black' });
987
+ this.formatMessage(4, 'HTML', ['No changes detected', 'incremental: ' + incremental], hint, { ...Document.LOG_STYLE_NOTICE, messageBgColor: 'bgWhite', messageColor: 'black' });
999
988
  return super.finalize.call(this, instance);
1000
989
  }
1001
990
  break;
@@ -1035,7 +1024,7 @@ class ChromeDocument extends Document {
1035
1024
  for (const item of children) {
1036
1025
  if (!items.has(item)) {
1037
1026
  if (isWatched.call(instance, item)) {
1038
- item.flags |= 8 /* ASSET_FLAG.WATCH */;
1027
+ item.flags |= 8;
1039
1028
  }
1040
1029
  items.add(item);
1041
1030
  const next = related.get(item);
@@ -1064,18 +1053,18 @@ class ChromeDocument extends Document {
1064
1053
  this.delete(value);
1065
1054
  }
1066
1055
  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 });
1056
+ instance.writeFail(["Unable to move file", instance.moduleName], (0, types_1.errorMessage)('production', path.join(this.baseDirectory, value)), { fatal: true });
1068
1057
  }
1069
1058
  }
1070
1059
  }
1071
1060
  }
1072
1061
  }
1073
1062
  else {
1074
- instance.writeFail(["Unable to write directory" /* ERR_MESSAGE.WRITE_DIRECTORY */, instance.moduleName], (0, types_1.errorMessage)('production', 'Access denied', productionRelease));
1063
+ instance.writeFail(["Unable to write directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Access denied', productionRelease));
1075
1064
  }
1076
1065
  }
1077
1066
  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 */);
1067
+ instance.writeFail(["Unable to read directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Invalid directory', productionRelease), 32);
1079
1068
  }
1080
1069
  }
1081
1070
  }
@@ -1159,7 +1148,7 @@ class ChromeDocument extends Document {
1159
1148
  return 0;
1160
1149
  });
1161
1150
  if (config) {
1162
- const { useUnsafeReplace, baseUrl, productionRelease, productionIncremental, templateMap, userAgentData, imports, cache } = config;
1151
+ const { useUnsafeReplace, baseUrl, productionRelease, productionIncremental, templateMap, userAgentData, cache } = config;
1163
1152
  const target = this.config;
1164
1153
  for (const attr in config) {
1165
1154
  if (attr in target) {
@@ -1204,7 +1193,10 @@ class ChromeDocument extends Document {
1204
1193
  if ((0, types_1.isObject)(userAgentData)) {
1205
1194
  this.userAgentData = userAgentData;
1206
1195
  }
1207
- this.imports = (0, types_1.isPlainObject)(imports) ? { ...this.module.imports, ...imports } : this.module.imports;
1196
+ const imports = (0, types_1.isPlainObject)(config.imports) ? { ...this.module.imports, ...config.imports } : this.module.imports;
1197
+ if (imports) {
1198
+ this.imports = imports;
1199
+ }
1208
1200
  if ((0, types_1.isObject)(cache) && 'transform' in cache) {
1209
1201
  this.customize({ transform: cache.transform });
1210
1202
  }
@@ -1380,7 +1372,7 @@ class ChromeDocument extends Document {
1380
1372
  await instance.tryFile(buffer, { format: to, filename: file.filename, etag: file.etag }, (err, result, ext) => {
1381
1373
  if (err) {
1382
1374
  setFormat();
1383
- this.writeFail("Unable to compress file" /* ERR_MESSAGE.COMPRESS_FILE */, err, 8 /* LOG_TYPE.COMPRESS */);
1375
+ this.writeFail("Unable to compress file", err, 8);
1384
1376
  }
1385
1377
  else if (result) {
1386
1378
  if (ext) {
@@ -1394,7 +1386,7 @@ class ChromeDocument extends Document {
1394
1386
  host.replace(file, output);
1395
1387
  }
1396
1388
  else {
1397
- this.writeFail("Unable to write file" /* ERR_MESSAGE.WRITE_FILE */, error, 32 /* LOG_TYPE.FILE */);
1389
+ this.writeFail("Unable to write file", error, 32);
1398
1390
  }
1399
1391
  });
1400
1392
  }
@@ -1588,14 +1580,14 @@ class ChromeDocument extends Document {
1588
1580
  replaceContent(source, statement, mimeType) {
1589
1581
  switch (mimeType) {
1590
1582
  case 'text/css': {
1591
- const match = /^@import\s+(?:url\((?:[^)]|(?<=\\)\))+\)|"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')(\s*layer(?:\(([^)]*)\)|\b))?(?:\s*supports\(((?:\([^(]+\(|\([^)]+\)|\)[^)]+\)|(?:(?!\))[^(])+|(?:(?!\()[^)])+)+)\))?(.*?);?$/.exec((typeof statement === 'string' ? statement : statement[0]).trim());
1583
+ const match = REGEXP_REPLACECSS.exec((typeof statement === 'string' ? statement : statement[0]).trim());
1592
1584
  if (match) {
1593
1585
  const layer = match[1];
1594
1586
  const supports = match[3]?.trim();
1595
1587
  const query = match[4].trim();
1596
1588
  if (layer || supports || query) {
1597
1589
  const newline = (0, util_1.getNewline)(source);
1598
- let result = supports ? `@supports (${match[1].trim()}) {` + newline : '';
1590
+ let result = supports ? `@supports (${supports}) {` + newline : '';
1599
1591
  if (query) {
1600
1592
  result += `@media ${query} {` + newline;
1601
1593
  }
@@ -1703,7 +1695,7 @@ class ChromeDocument extends Document {
1703
1695
  item.sourceUTF8 = output;
1704
1696
  }
1705
1697
  catch (err) {
1706
- host.writeFail(["Unable to write file" /* ERR_MESSAGE.WRITE_FILE */, path.basename(item.localUri)], err, 32 /* LOG_TYPE.FILE */);
1698
+ host.writeFail(["Unable to write file", path.basename(item.localUri)], err, 32);
1707
1699
  }
1708
1700
  }
1709
1701
  }
@@ -1907,7 +1899,7 @@ class ChromeDocument extends Document {
1907
1899
  host.removeAsset(item);
1908
1900
  }
1909
1901
  catch (err) {
1910
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, item.filename], err, { type: 32 /* LOG_TYPE.FILE */, startTime });
1902
+ this.writeFail(["Unable to read file", item.filename], err, { type: 32, startTime });
1911
1903
  return false;
1912
1904
  }
1913
1905
  }
@@ -2089,7 +2081,7 @@ class ChromeDocument extends Document {
2089
2081
  const { moduleName, config } = this;
2090
2082
  const htmlFile = this.htmlFile;
2091
2083
  const localUri = htmlFile.localUri;
2092
- this.formatMessage(4 /* LOG_TYPE.PROCESS */, 'HTML', ['Rewriting content...', path.dirname(localUri)]);
2084
+ this.formatMessage(4, 'HTML', ['Rewriting content...', path.dirname(localUri)]);
2093
2085
  let source = host.getUTF8String(htmlFile, localUri), output;
2094
2086
  const domBase = new dom_1.DomWriter(moduleName, source, this.elements, { normalize: config.normalizeHtmlOutput, stripComments: config.stripCommentsAndCDATA, ignoreTagGroup: config.ignoreServerCodeBlocks, escapeEntities: config.escapeReservedCharacters });
2095
2087
  if (config.useUnsafeHtmlReplace) {
@@ -2114,7 +2106,7 @@ class ChromeDocument extends Document {
2114
2106
  const domElement = new dom_1.HtmlElement(moduleName, item.element, item.attributes);
2115
2107
  domElement.remove = true;
2116
2108
  if (!domBase.write(domElement)) {
2117
- this.writeFail('Unable to exclude HTML element', errorHtml(item.element), 4 /* LOG_TYPE.PROCESS */);
2109
+ this.writeFail('Unable to exclude HTML element', errorHtml(item.element), 4);
2118
2110
  }
2119
2111
  }
2120
2112
  }
@@ -2152,7 +2144,7 @@ class ChromeDocument extends Document {
2152
2144
  domBase.errors.forEach(err => this.addLog(types_1.STATUS_TYPE.WARN, 'dom-writer -> ' + err.message, timeStamp));
2153
2145
  }
2154
2146
  if (domBase.failCount > 0) {
2155
- this.writeFail(['Unable to update document', moduleName], (0, types_1.errorMessage)('html', 'DOM rewrite failed', domBase.failCount + ' errors'), { type: 4 /* LOG_TYPE.PROCESS */, startTime });
2147
+ this.writeFail(['Unable to update document', moduleName], (0, types_1.errorMessage)('html', 'DOM rewrite failed', domBase.failCount + ' errors'), { type: 4, startTime });
2156
2148
  }
2157
2149
  else {
2158
2150
  this.writeTimeProcess('html', `dom-writer (${domBase.modifyCount} modified) -> ` + path.basename(localUri), startTime);
@@ -2163,7 +2155,7 @@ class ChromeDocument extends Document {
2163
2155
  for (const name in data) {
2164
2156
  message.push(name + `(${data[name]})`);
2165
2157
  }
2166
- this.formatMessage(65536 /* LOG_TYPE.DB */, 'DB', ['Cache statistics', cacheMiss.length + ' missed'], message.join(' - '), { ...Document.LOG_STYLE_NOTICE, hintBold: true });
2158
+ this.formatMessage(65536, 'DB', ['Cache statistics', cacheMiss.length + ' missed'], message.join(' - '), { ...Document.LOG_STYLE_NOTICE, hintBold: true });
2167
2159
  }
2168
2160
  }
2169
2161
  htmlFile.modified = true;
@@ -2279,7 +2271,7 @@ class ChromeDocument extends Document {
2279
2271
  }
2280
2272
  }
2281
2273
  if (!domBase.write(domElement)) {
2282
- this.writeFail(item.inlineContent ? 'Inline tag replacement' : 'Element attribute replacement', errorHtml(element), { type: 4 /* LOG_TYPE.PROCESS */, startTime });
2274
+ this.writeFail(item.inlineContent ? 'Inline tag replacement' : 'Element attribute replacement', errorHtml(element), { type: 4, startTime });
2283
2275
  delete item.inlineUrlCloud;
2284
2276
  }
2285
2277
  else if (item.inlineContent) {
@@ -2303,15 +2295,15 @@ class ChromeDocument extends Document {
2303
2295
  if (item.removeEmpty || item.type === 'display') {
2304
2296
  (element || (element = new dom_1.HtmlElement(moduleName, item.element))).remove = true;
2305
2297
  if (!domBase.write(element)) {
2306
- this.writeFail('Unable to remove element', errorHtml(item.element), { type: 4 /* LOG_TYPE.PROCESS */, startTime });
2298
+ this.writeFail('Unable to remove element', errorHtml(item.element), { type: 4, startTime });
2307
2299
  }
2308
2300
  }
2309
2301
  };
2310
2302
  const errorCredential = (item, err) => {
2311
2303
  removeElement(item);
2312
- const pkg = getPackageName(err, item.source);
2304
+ const pkg = getPackageName(err);
2313
2305
  if (!(pkg && this.checkPackage(err, pkg))) {
2314
- this.writeFail(["Invalid credentials" /* ERR_DB.CREDENTIALS */, item.source], err);
2306
+ this.writeFail(["Invalid credentials", item.source], err);
2315
2307
  }
2316
2308
  };
2317
2309
  const checkObject = (item, data) => {
@@ -2341,7 +2333,7 @@ class ChromeDocument extends Document {
2341
2333
  }
2342
2334
  catch (err) {
2343
2335
  this.abort(item.source);
2344
- this.checkPackage(err, pkg, ["Unable to filter results" /* ERR_DB.FILTER_QUERY */, item.source]);
2336
+ this.checkPackage(err, pkg, ["Unable to filter results", item.source]);
2345
2337
  }
2346
2338
  }
2347
2339
  }
@@ -2364,7 +2356,7 @@ class ChromeDocument extends Document {
2364
2356
  (batchMap[key] || (batchMap[key] = [])).push(item);
2365
2357
  }
2366
2358
  else {
2367
- errorCredential(item, (0, types_1.errorValue)("Cloud module not installed" /* ERR_CLOUD.MODULE_NOTFOUND */, service));
2359
+ errorCredential(item, (0, types_1.errorValue)("Cloud module not installed", service));
2368
2360
  }
2369
2361
  break;
2370
2362
  }
@@ -2397,7 +2389,7 @@ class ChromeDocument extends Document {
2397
2389
  }
2398
2390
  }
2399
2391
  else {
2400
- errorCredential(item, (0, types_1.errorValue)(db ? "Database provider not found" /* ERR_DB.PROVIDER_NOTFOUND */ : "Db module not installed" /* ERR_DB.MODULE_NOTFOUND */, type));
2392
+ errorCredential(item, (0, types_1.errorValue)(db ? "Database provider not found" : "Db module not installed", type));
2401
2393
  }
2402
2394
  break;
2403
2395
  }
@@ -2414,7 +2406,7 @@ class ChromeDocument extends Document {
2414
2406
  const errorClient = (item, reason) => {
2415
2407
  removeElement(item);
2416
2408
  if (reason) {
2417
- this.writeFail(["Unable to configure client" /* ERR_DB.CLIENT */, item.source], reason);
2409
+ this.writeFail(["Unable to configure client", item.source], reason);
2418
2410
  }
2419
2411
  reject();
2420
2412
  };
@@ -2456,7 +2448,7 @@ class ChromeDocument extends Document {
2456
2448
  }
2457
2449
  catch (err) {
2458
2450
  this.abort(type);
2459
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(location)], err, { type: 32 /* LOG_TYPE.FILE */, startTime });
2451
+ this.writeFail(["Unable to read file", path.basename(location)], err, { type: 32, startTime });
2460
2452
  errorRemove(current);
2461
2453
  return;
2462
2454
  }
@@ -2492,7 +2484,7 @@ class ChromeDocument extends Document {
2492
2484
  }
2493
2485
  catch (err) {
2494
2486
  this.abort(type);
2495
- this.writeFail(["Unable to download file" /* ERR_MESSAGE.DOWNLOAD_FILE */, target], err, { type: 1024 /* LOG_TYPE.HTTP */, startTime });
2487
+ this.writeFail(["Unable to download file", target], err, { type: 1024, startTime });
2496
2488
  errorRemove(current);
2497
2489
  return;
2498
2490
  }
@@ -2521,7 +2513,7 @@ class ChromeDocument extends Document {
2521
2513
  }
2522
2514
  catch (err) {
2523
2515
  this.abort(type);
2524
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(pathname)], err, { type: 32 /* LOG_TYPE.FILE */, startTime });
2516
+ this.writeFail(["Unable to read file", path.basename(pathname)], err, { type: 32, startTime });
2525
2517
  errorRemove(current);
2526
2518
  return;
2527
2519
  }
@@ -2535,7 +2527,7 @@ class ChromeDocument extends Document {
2535
2527
  }
2536
2528
  catch (err) {
2537
2529
  this.abort(type);
2538
- this.writeFail(['Unable to parse data source', format], err, { type: 4 /* LOG_TYPE.PROCESS */, startTime });
2530
+ this.writeFail(['Unable to parse data source', format], err, { type: 4, startTime });
2539
2531
  errorRemove(current);
2540
2532
  return;
2541
2533
  }
@@ -2613,13 +2605,12 @@ class ChromeDocument extends Document {
2613
2605
  if (params && this.settingsOf(type, 'coerce') === true) {
2614
2606
  (0, types_1.coerceObject)(params);
2615
2607
  }
2616
- // @ts-ignore
2617
- if (getData["__cjs__" /* INTERNAL.CJS */]) {
2608
+ if (getData["__cjs__"]) {
2618
2609
  data = await getData(params);
2619
2610
  }
2620
2611
  else {
2621
- const thisArg = Document.enabled("node.process.inline" /* KEY_NAME.NODE_PROCESS_INLINE */) ? process : null;
2622
- const inline = Document.enabled("node.require.inline" /* KEY_NAME.NODE_REQUIRE_INLINE */);
2612
+ const thisArg = Document.enabled("node.process.inline") ? process : null;
2613
+ const inline = Document.enabled("node.require.inline");
2623
2614
  const args = [params];
2624
2615
  if (getData.toString().startsWith('async')) {
2625
2616
  if (inline) {
@@ -2641,7 +2632,7 @@ class ChromeDocument extends Document {
2641
2632
  }
2642
2633
  catch (err) {
2643
2634
  this.abort(type);
2644
- this.writeFail(['Unable to retrieve data source', hint], err, { type: 4 /* LOG_TYPE.PROCESS */, startTime });
2635
+ this.writeFail(['Unable to retrieve data source', hint], err, { type: 4, startTime });
2645
2636
  errorRemove(current);
2646
2637
  return;
2647
2638
  }
@@ -2727,12 +2718,12 @@ class ChromeDocument extends Document {
2727
2718
  }
2728
2719
  }
2729
2720
  else {
2730
- throw (0, types_1.errorMessage)(type, "File not found" /* ERR_MESSAGE.NOTFOUND_FILE */, query);
2721
+ throw (0, types_1.errorMessage)(type, "File not found", query);
2731
2722
  }
2732
2723
  }
2733
2724
  catch (err) {
2734
2725
  this.abort(type);
2735
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, pathname ? path.basename(pathname) : query], err, { startTime });
2726
+ this.writeFail(["Unable to read file", pathname ? path.basename(pathname) : query], err, { startTime });
2736
2727
  errorRemove(current);
2737
2728
  return;
2738
2729
  }
@@ -2769,7 +2760,7 @@ class ChromeDocument extends Document {
2769
2760
  this.abort(type);
2770
2761
  }
2771
2762
  if (err) {
2772
- this.writeFail(["Unable to execute query" /* ERR_DB.EXEC_QUERY */, message || "Unknown" /* ERR_MESSAGE.UNKNOWN */], err, { type: 65536 /* LOG_TYPE.DB */, startTime });
2763
+ this.writeFail(["Unable to execute query", message || "Unknown"], err, { type: 65536, startTime });
2773
2764
  }
2774
2765
  return this.aborted;
2775
2766
  };
@@ -2778,12 +2769,12 @@ class ChromeDocument extends Document {
2778
2769
  }
2779
2770
  catch (err) {
2780
2771
  this.abort(type);
2781
- const pkg = getPackageName(err, type);
2772
+ const pkg = getPackageName(err);
2782
2773
  errorClient(current, pkg && this.checkPackage(err, pkg) ? null : err);
2783
2774
  }
2784
2775
  break;
2785
2776
  }
2786
- errorRemove(current, errorDataSource('Not found', type || "Unknown" /* ERR_MESSAGE.UNKNOWN */));
2777
+ errorRemove(current, errorDataSource('Not found', type || "Unknown"));
2787
2778
  return;
2788
2779
  }
2789
2780
  if (this.aborted) {
@@ -2847,7 +2838,7 @@ class ChromeDocument extends Document {
2847
2838
  setCacheData.call(this, item, item.value, pathname, cacheData, true);
2848
2839
  }
2849
2840
  catch (err) {
2850
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(pathname)], err, { type: 32 /* LOG_TYPE.FILE */, startTime });
2841
+ this.writeFail(["Unable to read file", path.basename(pathname)], err, { type: 32, startTime });
2851
2842
  errors = true;
2852
2843
  }
2853
2844
  }
@@ -2890,7 +2881,7 @@ class ChromeDocument extends Document {
2890
2881
  const literal = segment.trim();
2891
2882
  if (literal[0] === '`' && literal[literal.length - 1] === '`') {
2892
2883
  if (!this.hasEval('function')) {
2893
- errors = (0, types_1.errorMessage)('eval', "Unsupported access" /* ERR_MESSAGE.UNSUPPORTED_ACCESS */, 'function');
2884
+ errors = (0, types_1.errorMessage)('eval', "Unsupported access", 'function');
2894
2885
  continue;
2895
2886
  }
2896
2887
  try {
@@ -3106,34 +3097,34 @@ class ChromeDocument extends Document {
3106
3097
  default:
3107
3098
  removeElement(item, domElement);
3108
3099
  if (length === 1) {
3109
- reject(errorDataSource('Invalid action', item.type || "Unknown" /* ERR_MESSAGE.UNKNOWN */));
3100
+ reject(errorDataSource('Invalid action', item.type || "Unknown"));
3110
3101
  return;
3111
3102
  }
3112
3103
  break invalid;
3113
3104
  }
3114
3105
  if (!domBase.write(domElement) || errors) {
3115
- this.writeFail(item.type === 'display' ? domElement.remove ? errors ? 'Element was removed with errors' : 'Unable to remove element' : 'Unable to determine display conditional' : 'Unable to replace ' + item.type, errors instanceof Error ? errors : errorHtml(element), { type: 4 /* LOG_TYPE.PROCESS */, startTime });
3106
+ this.writeFail(item.type === 'display' ? domElement.remove ? errors ? 'Element was removed with errors' : 'Unable to remove element' : 'Unable to determine display conditional' : 'Unable to replace ' + item.type, errors instanceof Error ? errors : errorHtml(element), { type: 4, startTime });
3116
3107
  }
3117
3108
  }
3118
3109
  }
3119
3110
  else {
3120
3111
  if (!empty && item.type !== 'display' || item.transactionFail) {
3121
- const emptyResponse = (value, service = item.source) => errorDataSource(service + ' -> Empty', value || "Unknown" /* ERR_MESSAGE.UNKNOWN */);
3112
+ const emptyResponse = (value, service = item.source) => errorDataSource(service + ' -> Empty', value || "Unknown");
3122
3113
  switch (item.source) {
3123
3114
  case 'cloud': {
3124
3115
  const { service, table, id, query } = item;
3125
3116
  const queryString = (table ? 'table=' + table : '') + (id || query ? (table ? ';' : '') + (id ? 'id=' + id : 'query=' + asString(query)) : '');
3126
- (cloud || this).formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to execute query" /* ERR_DB.EXEC_QUERY */, queryString], emptyResponse(queryString, service), { ...Cloud.LOG_CLOUD_FAIL, startTime });
3117
+ (cloud || this).formatFail(64, service, ["Unable to execute query", queryString], emptyResponse(queryString, service), { ...Cloud.LOG_CLOUD_FAIL, startTime });
3127
3118
  break;
3128
3119
  }
3129
3120
  case 'uri': {
3130
3121
  const { uri, format = uri && path.extname(uri).substring(1) } = item;
3131
- this.formatFail(4 /* LOG_TYPE.PROCESS */, format || 'URI', ['No records were found', uri], emptyResponse(uri), { startTime });
3122
+ this.formatFail(4, format || 'URI', ['No records were found', uri], emptyResponse(uri), { startTime });
3132
3123
  break;
3133
3124
  }
3134
3125
  case 'local': {
3135
3126
  const { pathname, format = pathname && path.extname(pathname).substring(1) } = item;
3136
- this.formatFail(4 /* LOG_TYPE.PROCESS */, format || 'LOCAL', ['No records were found', pathname], emptyResponse(pathname), { startTime });
3127
+ this.formatFail(4, format || 'LOCAL', ['No records were found', pathname], emptyResponse(pathname), { startTime });
3137
3128
  break;
3138
3129
  }
3139
3130
  case 'export': {
@@ -3142,7 +3133,7 @@ class ChromeDocument extends Document {
3142
3133
  if (typeof target === 'function') {
3143
3134
  target = target.name;
3144
3135
  }
3145
- this.formatFail(4 /* LOG_TYPE.PROCESS */, 'EXPORT', ['No records were retrieved', target], emptyResponse(target), { startTime });
3136
+ this.formatFail(4, 'EXPORT', ['No records were retrieved', target], emptyResponse(target), { startTime });
3146
3137
  break;
3147
3138
  }
3148
3139
  }
@@ -3194,7 +3185,7 @@ class ChromeDocument extends Document {
3194
3185
  throw (0, types_1.errorMessage)('hash', 'Source not found', item.filename);
3195
3186
  }
3196
3187
  catch (err) {
3197
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, item.filename], err, { type: 32 /* LOG_TYPE.FILE */, startTime });
3188
+ this.writeFail(["Unable to read file", item.filename], err, { type: 32, startTime });
3198
3189
  }
3199
3190
  default:
3200
3191
  if (algorithm) {
@@ -3221,7 +3212,7 @@ class ChromeDocument extends Document {
3221
3212
  const parseSelector = (value) => {
3222
3213
  const items = [];
3223
3214
  const revised = value.replace(useUnsafeCssReplace ? REGEXP_NTHCHILD_UNSAFE : REGEXP_NTHCHILD, (...capture) => {
3224
- return '`%' + (items.push('\\(' + getStringSome() + (capture[1] === '-' ? '\\x2d' : '\\x2b?') + (capture[2] || '[01]?') + (capture[3] === '0' ? !capture[1] && !capture[2] && !capture[4] && !capture[5] ? '[+-]?0[nN]?' : '0' : '[nN]') + getStringSome() + (capture[5] ? (capture[4] === '-' ? '\\x2d' : '\\x2b') + getStringSome() + capture[5] : `(?:[+-]${getStringSome()}0)?`) + getStringSome() + '\\)') - 1) + '`';
3215
+ return '`%' + (items.push('\\(' + getStringSome() + (capture[1] === '-' ? '\\x2d' : '\\x2b?') + (capture[2] || '[01]?') + (capture[3] === '0' ? !capture[1] && !capture[2] && !capture[4] && !capture[5] ? '[+-]?0[nN]?' : '0' : '[nN]') + getStringSome() + (capture[5] ? (capture[4] === '-' ? '\\x2d' : '\\x2b') + getStringSome() + capture[5] : `(?:[+-]${getStringSome()}0)?`) + (capture[6] ? getStringMany() + '[oO][fF]' + getStringMany() + capture[6].trim() : '') + getStringSome() + '\\)') - 1) + '`';
3225
3216
  });
3226
3217
  let selector = '';
3227
3218
  for (let i = 0, length = revised.length, casing = false, attr = false, quote = false; i < length; i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/chrome",
3
- "version": "0.2.2",
3
+ "version": "0.2.9",
4
4
  "description": "Chrome document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/anpham6/pi-r.git",
11
+ "url": "git+https://github.com/anpham6/pi-r.git",
12
12
  "directory": "src/module/chrome"
13
13
  },
14
14
  "keywords": [
@@ -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.3",
24
- "@e-mc/core": "^0.5.3",
25
- "@e-mc/document": "^0.5.3",
26
- "@e-mc/types": "^0.5.3"
23
+ "@e-mc/cloud": "^0.5.5",
24
+ "@e-mc/core": "^0.5.5",
25
+ "@e-mc/document": "^0.5.5",
26
+ "@e-mc/types": "^0.5.5"
27
27
  }
28
28
  }
package/types/index.d.ts CHANGED
@@ -91,12 +91,12 @@ export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAs
91
91
  formatMap?: ObjectMap<FormatUri>;
92
92
  setElementSrc(asset: U, element: IXmlElement, value: string): void;
93
93
  findDataValue(name: string): Undef<string>;
94
- setInlinedAttributes(processing: FinalizeProcessing<T>): void;
95
- applyTransforms(processing: FinalizeProcessing<T>): Promise<void>;
96
- rewriteHtml(processing: FinalizeProcessing<T>): Promise<void>;
97
- setElementAttributes(processing: FinalizeProcessing<T>, domBase: IDomWriter): Promise<void>;
98
- applyDataSource(processing: FinalizeProcessing<T>, domBase: IDomWriter): Promise<void>;
99
- setProductionAttributes(processing: FinalizeProcessing<T>): void;
94
+ setInlinedAttributes(processing: FinalizeProcessing<T, U>): void;
95
+ applyTransforms(processing: FinalizeProcessing<T, U>): Promise<void>;
96
+ rewriteHtml(processing: FinalizeProcessing<T, U>): Promise<void>;
97
+ setElementAttributes(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
98
+ applyDataSource(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
99
+ setProductionAttributes(processing: FinalizeProcessing<T, U>): void;
100
100
  removeUnusedStyles(source: string, options?: UserConfig): Undef<string>;
101
101
  removeServerRoot(value: string): string;
102
102
  replaceContent(source: string, match: RegExpExecArray | string, mimeType?: string): Undef<string>;
@@ -115,4 +115,4 @@ export interface ChromeDocumentConstructor<T extends IFileManager<U>, U extends
115
115
  INTERNAL_SERVERROOT: string;
116
116
  readonly prototype: IChromeDocument<T, U>;
117
117
  new(module?: DocumentModule, ...args: unknown[]): IChromeDocument<T, U>;
118
- }
118
+ }