@pi-r/chrome 0.3.4 → 0.3.6

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
-
1
+ Copyright 2023 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
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
@@ -1,7 +1,5 @@
1
- # @pi-r/chrome
2
-
3
- PEP 402 - Forever
4
-
5
- ## LICENSE
6
-
1
+ # @pi-r/chrome
2
+
3
+ ## LICENSE
4
+
7
5
  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
@@ -11,6 +11,9 @@ const transform_1 = require("@e-mc/document/transform");
11
11
  const Document = require('@e-mc/document');
12
12
  const CACHE_DBRESULT = new Map();
13
13
  const CACHE_LOCALFILE = new Map();
14
+ const CACHE_ETAG = new Map();
15
+ const CACHE_CONTENT = new Map();
16
+ const CACHE_FORMAT = new Map();
14
17
  const CACHE_DATASET = {};
15
18
  const CACHE_ATRULES = {};
16
19
  let CACHE_TOTAL = 0;
@@ -43,13 +46,9 @@ const REGEXP_VARIABLES_UNSAFE = new RegExp(`(\\s*)(--[^\\s:]*)\\s*:[^;}]*([;}])`
43
46
  const REGEXP_FONTFACE_UNSAFE = new RegExp(`(\\s*)@font-face\\s*{([^}]+)}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
44
47
  const REGEXP_FONTFAMILY_UNSAFE = /font-family\s*:([^;}]+)/i;
45
48
  const REGEXP_KEYFRAMES_UNSAFE = /(\s*)@keyframes\s+([^{]+){/gi;
46
- const REGEXP_OBJECT_NAME = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
47
- const REGEXP_OBJECT_SUBSCRIPT = /\[\s*(["'])?(.+?)\1\s*\]/g;
48
- const REGEXP_TEMPLATE_LEADING = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
49
- const REGEXP_TEMPLATE_TRAILING = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
50
49
  function removeNamespace(name, source, newline, comments) {
51
50
  if (source.indexOf('-' + name) !== -1) {
52
- const [a, b, c, d, e] = CACHE_DATASET[name] || (CACHE_DATASET[name] = [
51
+ const dataset = CACHE_DATASET[name] || (CACHE_DATASET[name] = [
53
52
  new RegExp(`(\\s*)<(script|style)(${dom_1.DomWriter.PATTERN_TAGOPEN}+)>[\\S\\s]*?<\\/\\2\\s*>` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi'),
54
53
  new RegExp(`(\\s*)<link(${dom_1.DomWriter.PATTERN_TAGOPEN}+)>` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi'),
55
54
  new RegExp(`\\s+data-${name}-[a-z-]+\\s*` + dom_1.DomWriter.PATTERN_ATTRVALUE, 'g'),
@@ -57,26 +56,24 @@ function removeNamespace(name, source, newline, comments) {
57
56
  new RegExp(`data-${name}-template\\s*` + dom_1.DomWriter.PATTERN_ATTRVALUE)
58
57
  ]);
59
58
  source = source
60
- .replace(a, (...capture) => d.test(capture[3]) || e.test(capture[3]) ? getNewlineString(capture[1], capture[7], newline) : capture[0])
61
- .replace(b, (...capture) => d.test(capture[2]) ? getNewlineString(capture[1], capture[6], newline) : capture[0])
62
- .replace(c, '');
59
+ .replace(dataset[0], (...capture) => dataset[3].test(capture[3]) || dataset[4].test(capture[3]) ? getNewlineString(capture[1], capture[7], newline) : capture[0])
60
+ .replace(dataset[1], (...capture) => dataset[3].test(capture[2]) ? getNewlineString(capture[1], capture[6], newline) : capture[0])
61
+ .replace(dataset[2], '');
63
62
  }
64
63
  return (0, types_1.isArray)(comments) ? source.replace(REGEXP_BLOCKEXCLUDE, (...capture) => getNewlineString(capture[1], capture[2], newline)) : source;
65
64
  }
66
65
  function getObjectValue(value, key) {
67
- REGEXP_OBJECT_NAME.lastIndex = 0;
66
+ const pattern = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
68
67
  let found, match;
69
- while (match = REGEXP_OBJECT_NAME.exec(key)) {
68
+ while (match = pattern.exec(key)) {
70
69
  if ((0, types_1.isObject)(value)) {
71
70
  value = value[match[1]];
72
- const name = match[2];
73
- if (name) {
74
- REGEXP_OBJECT_SUBSCRIPT.lastIndex = 0;
71
+ if (match[2]) {
72
+ const subscript = /\[\s*(["'])?(.+?)\1\s*\]/g;
75
73
  let index;
76
- while (index = REGEXP_OBJECT_SUBSCRIPT.exec(name)) {
77
- const quote = index[1];
78
- const attr = quote ? index[2] : index[2].trim();
79
- if (quote && (0, types_1.isObject)(value) || /^\d+$/.test(attr) && (typeof value === 'string' || (0, types_1.isObject)(value))) {
74
+ while (index = subscript.exec(match[2])) {
75
+ const attr = index[1] ? index[2] : index[2].trim();
76
+ if (index[1] && (0, types_1.isObject)(value) || /^\d+$/.test(attr) && (typeof value === 'string' || (0, types_1.isObject)(value))) {
80
77
  value = value[attr];
81
78
  }
82
79
  else {
@@ -94,14 +91,14 @@ function getObjectValue(value, key) {
94
91
  return found ? value : null;
95
92
  }
96
93
  function trimTemplate(value) {
97
- REGEXP_TEMPLATE_LEADING.lastIndex = 0;
94
+ const leading = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
98
95
  let match;
99
- while (match = REGEXP_TEMPLATE_LEADING.exec(value)) {
100
- value = replaceMatch(match, value, 1, REGEXP_TEMPLATE_LEADING);
96
+ while (match = leading.exec(value)) {
97
+ value = replaceMatch(match, value, 1, leading);
101
98
  }
102
- REGEXP_TEMPLATE_TRAILING.lastIndex = 0;
103
- while (match = REGEXP_TEMPLATE_TRAILING.exec(value)) {
104
- value = replaceMatch(match, value, 1, REGEXP_TEMPLATE_TRAILING);
99
+ const trailing = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
100
+ while (match = trailing.exec(value)) {
101
+ value = replaceMatch(match, value, 1, trailing);
105
102
  }
106
103
  return value;
107
104
  }
@@ -179,15 +176,15 @@ function hasCondition(data, condition) {
179
176
  }
180
177
  let match = REGEXP_TEMPLATEMATCH.exec(condition.trim());
181
178
  if (match) {
182
- const comparison = match[2];
183
- if (comparison) {
179
+ if (match[2]) {
184
180
  const join = match[1];
181
+ const comparison = match[2];
185
182
  const items = [];
186
183
  while (match = REGEXP_TEMPLATECOMPARISON.exec(comparison)) {
187
184
  if (items.length && !isSpace(match[0][0])) {
188
185
  return false;
189
186
  }
190
- items.push([match[1], match[2], match[3]]);
187
+ items.push([match[1], trimQuote(match[2]), trimQuote(match[3])]);
191
188
  }
192
189
  REGEXP_TEMPLATECOMPARISON.lastIndex = 0;
193
190
  const length = items.length;
@@ -286,14 +283,17 @@ function hasSameOrigin(value, ...other) {
286
283
  return false;
287
284
  }
288
285
  function restoreSearchParams(value, prefix = '__sqd') {
289
- if ((value === null || value === void 0 ? void 0 : value.indexOf(prefix)) !== -1) {
290
- const params = new URLSearchParams(value);
291
- params.forEach((_, key) => key.startsWith(prefix) && params.delete(key));
292
- if (value = params.toString()) {
293
- return '?' + value;
286
+ if (value) {
287
+ if (value.indexOf(prefix) !== -1) {
288
+ const params = new URLSearchParams(value);
289
+ params.forEach((_, key) => key.startsWith(prefix) && params.delete(key));
290
+ if (value = params.toString()) {
291
+ return '?' + value;
292
+ }
294
293
  }
294
+ return value;
295
295
  }
296
- return value || '';
296
+ return '';
297
297
  }
298
298
  function getBaseURLs(asset, baseUrl) {
299
299
  const result = [];
@@ -323,27 +323,26 @@ function getBaseURLs(asset, baseUrl) {
323
323
  }
324
324
  function createHash(host, file, bufferMap) {
325
325
  const hash = file.hash;
326
- if (!hash) {
327
- return;
328
- }
329
- const { filename, localUri } = file;
330
- try {
331
- const buffer = localUri && bufferMap[localUri] || getBuffer(file);
332
- if (buffer) {
333
- const [algorithm, length] = (0, util_1.getHashData)(hash);
334
- let value;
335
- if (algorithm && (value = Document.asHash(buffer, { algorithm, encoding: file.encoding }))) {
336
- if (localUri) {
337
- bufferMap[localUri] = buffer;
326
+ if (hash) {
327
+ try {
328
+ const localUri = file.localUri;
329
+ const buffer = localUri && bufferMap[localUri] || getBuffer(file);
330
+ if (buffer) {
331
+ const [algorithm, length] = (0, util_1.getHashData)(hash);
332
+ let value;
333
+ if (algorithm && (value = Document.asHash(buffer, { algorithm, encoding: file.encoding }))) {
334
+ if (localUri) {
335
+ bufferMap[localUri] = buffer;
336
+ }
337
+ host.rename(file, (0, util_1.appendSuffix)(file.filename, length ? value.substring(0, length) : value));
338
+ return file.filename;
338
339
  }
339
- host.rename(file, (0, util_1.appendSuffix)(filename, length ? value.substring(0, length) : value));
340
- return file.filename;
341
340
  }
341
+ throw (0, types_1.errorMessage)('hash', 'Source not found', file.filename);
342
+ }
343
+ catch (err) {
344
+ host.writeFail(["Unable to read file", file.filename], err, 32);
342
345
  }
343
- throw (0, types_1.errorMessage)('hash', 'Source not found', filename);
344
- }
345
- catch (err) {
346
- host.writeFail(["Unable to read file", filename], err, 32);
347
346
  }
348
347
  }
349
348
  function getSrcURL(parent, file) {
@@ -665,7 +664,7 @@ function transformOptions(file, mimeType, code, bundleContent) {
665
664
  const metadata = { userAgentData: this.userAgentData };
666
665
  switch (mimeType) {
667
666
  case 'text/html':
668
- metadata.__fromhtml__ = true;
667
+ metadata['__fromhtml__'] = true;
669
668
  case 'text/css':
670
669
  Object.assign(metadata, this.config);
671
670
  default:
@@ -764,12 +763,11 @@ function replaceCss(file) {
764
763
  map[id] = this.removeServerRoot(map[id]);
765
764
  }
766
765
  };
767
- const { inlineUrlMap, inlineUrlCloudMap } = file;
768
- if (inlineUrlMap) {
769
- sanitize(inlineUrlMap);
766
+ if (file.inlineUrlMap) {
767
+ sanitize(file.inlineUrlMap);
770
768
  }
771
- if (inlineUrlCloudMap) {
772
- sanitize(inlineUrlCloudMap);
769
+ if (file.inlineUrlCloudMap) {
770
+ sanitize(file.inlineUrlCloudMap);
773
771
  }
774
772
  }
775
773
  function replaceHtml(source, { productionRelease, contentMap }, cssMap) {
@@ -845,10 +843,6 @@ async function checkData(item, name, result, validate) {
845
843
  }
846
844
  }
847
845
  }
848
- function getBuffer(item) {
849
- let localUri;
850
- return item.sourceUTF8 || item.buffer || ((localUri = item.localUri) && isPath(localUri) ? fs.readFileSync(localUri, item.encoding) : null);
851
- }
852
846
  const getNewlineString = dom_1.DomWriter.getNewlineString.bind(dom_1.DomWriter);
853
847
  const isSpace = dom_1.DomWriter.isSpace.bind(dom_1.DomWriter);
854
848
  const replaceMatch = dom_1.DomWriter.replaceMatch.bind(dom_1.DomWriter);
@@ -859,10 +853,11 @@ const asString = Document.asString.bind(Document);
859
853
  const resolvePath = Document.resolvePath.bind(Document);
860
854
  const toPosix = Document.toPosix.bind(Document);
861
855
  const isDir = Document.isDir.bind(Document);
862
- 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;
863
857
  const isBundled = (value, main) => typeof value === 'number' && (value > 0 || main && value === 0);
864
858
  const isFont = (value) => value === 'truetype' || value === 'opentype' || value === 'woff' || value === 'woff2';
865
859
  const isImage = (value) => typeof value === 'string' && value.startsWith('image/') && value !== 'image/svg+xml';
860
+ const getBuffer = (item) => item.sourceUTF8 || item.buffer || (item.localUri && isPath(item.localUri) ? fs.readFileSync(item.localUri, item.encoding) : null);
866
861
  const isRemoved = (item) => item.exclude === true || isBundled(item.bundleIndex);
867
862
  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
863
  const isIgnored = (item, exists) => item.invalid || (0, types_1.ignoreFlag)(item.flags) || !exists && (0, types_1.existsFlag)(item.flags);
@@ -939,6 +934,9 @@ class ChromeDocument extends Document {
939
934
  }
940
935
  CACHE_TOTAL = stored.length - result;
941
936
  }
937
+ CACHE_ETAG.clear();
938
+ CACHE_CONTENT.clear();
939
+ CACHE_FORMAT.clear();
942
940
  }
943
941
  return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
944
942
  }
@@ -966,12 +964,27 @@ class ChromeDocument extends Document {
966
964
  if (outHtml) {
967
965
  const { etag, initialValue } = htmlFile;
968
966
  let buffer;
969
- if (!initialValue || !(etag && initialValue.etag === etag && (buffer = initialValue.buffer)) || fetched.find(item => item.bundleReplace && (!(0, types_1.isArray)(item.from) || item.from.includes('style')))) {
967
+ if (!initialValue || !(etag && initialValue.etag === etag && (buffer = initialValue.buffer)) || fetched.find(item => item !== htmlFile && item.etag && CACHE_ETAG.get(item.localUri) !== item.etag && (item.inlineContent || item.bundleReplace && (!Array.isArray(item.from) || item.from.includes('style'))))) {
968
+ const isValid = (item) => !!item.localUri && item !== htmlFile && !item.invalid;
969
+ for (const item of fetched) {
970
+ if (item.etag && !item.content && isValid(item)) {
971
+ CACHE_ETAG.set(item.localUri, item.etag);
972
+ }
973
+ }
974
+ for (const item of instance.assets) {
975
+ if (isValid(item)) {
976
+ if (item.content) {
977
+ CACHE_CONTENT.set(item.localUri, item.content);
978
+ }
979
+ if (item.format) {
980
+ CACHE_FORMAT.set(item.localUri, item.format.toString());
981
+ }
982
+ }
983
+ }
970
984
  break;
971
985
  }
972
986
  try {
973
- const { localUri, encoding } = htmlFile;
974
- fs.writeFileSync(localUri, buffer, (0, types_1.getEncoding)(encoding));
987
+ fs.writeFileSync(htmlFile.localUri, buffer, (0, types_1.getEncoding)(htmlFile.encoding));
975
988
  htmlFile.buffer = buffer;
976
989
  htmlFile.sourceUTF8 = undefined;
977
990
  }
@@ -979,12 +992,39 @@ class ChromeDocument extends Document {
979
992
  break;
980
993
  }
981
994
  }
982
- const { jsFiles, cssFiles, svgFiles } = instance;
983
- const copiedAssets = this.copiedAssets;
984
- const wasModified = (item) => fetched.includes(item) || copiedAssets.includes(item) && (!(0, types_1.isEmpty)(item.bundleId) || !(0, types_1.isEmpty)(item.trailingContent));
985
- const js = jsFiles.filter(item => item.imports || wasModified(item));
986
- const css = cssFiles.filter(wasModified);
987
- const svg = svgFiles.filter(wasModified);
995
+ const wasModified = (item) => {
996
+ const localUri = item.localUri;
997
+ let result = fetched.includes(item) || Array.isArray(item.from) && item.from.includes('style');
998
+ if (localUri) {
999
+ if (item.etag && !item.content && !item.invalid) {
1000
+ CACHE_ETAG.set(localUri, item.etag);
1001
+ }
1002
+ else {
1003
+ CACHE_ETAG.delete(localUri);
1004
+ }
1005
+ if (!item.content || item.invalid) {
1006
+ CACHE_CONTENT.delete(localUri);
1007
+ }
1008
+ else if (CACHE_CONTENT.get(localUri) !== item.content || !item.inlineContent && !Document.isPath(localUri)) {
1009
+ CACHE_CONTENT.set(localUri, item.content);
1010
+ result = true;
1011
+ }
1012
+ if (!item.format || item.invalid) {
1013
+ CACHE_FORMAT.delete(localUri);
1014
+ }
1015
+ else {
1016
+ const format = item.format.toString();
1017
+ if (CACHE_FORMAT.get(localUri) !== format || !item.inlineContent && !Document.isPath(localUri)) {
1018
+ CACHE_FORMAT.set(localUri, format);
1019
+ result = true;
1020
+ }
1021
+ }
1022
+ }
1023
+ return result || this.copiedAssets.includes(item) && (!(0, types_1.isEmpty)(item.bundleId) || !(0, types_1.isEmpty)(item.trailingContent));
1024
+ };
1025
+ const js = instance.jsFiles.filter(item => wasModified(item) || !!item.imports);
1026
+ const css = instance.cssFiles.filter(wasModified);
1027
+ const svg = instance.svgFiles.filter(wasModified);
988
1028
  if (js.length || css.length || svg.length) {
989
1029
  instance.jsFiles = js;
990
1030
  instance.cssFiles = css;
@@ -1033,16 +1073,15 @@ class ChromeDocument extends Document {
1033
1073
  const items = new Set((asset.watch.assets || []));
1034
1074
  (function recurse(children) {
1035
1075
  for (const item of children) {
1036
- if (items.has(item)) {
1037
- continue;
1038
- }
1039
- if (isWatched.call(instance, item)) {
1040
- item.flags |= 8;
1041
- }
1042
- items.add(item);
1043
- const next = related.get(item);
1044
- if (next) {
1045
- recurse(next);
1076
+ if (!items.has(item)) {
1077
+ if (isWatched.call(instance, item)) {
1078
+ item.flags |= 8;
1079
+ }
1080
+ items.add(item);
1081
+ const next = related.get(item);
1082
+ if (next) {
1083
+ recurse(next);
1084
+ }
1046
1085
  }
1047
1086
  }
1048
1087
  })(includes);
@@ -1051,37 +1090,34 @@ class ChromeDocument extends Document {
1051
1090
  }
1052
1091
  }
1053
1092
  let productionRelease = instance.productionRelease;
1054
- if (!(0, types_1.isString)(productionRelease)) {
1055
- return;
1056
- }
1057
- if (path.isAbsolute(productionRelease = path.normalize(productionRelease)) && isDir(productionRelease)) {
1058
- if (this.canWrite(productionRelease)) {
1059
- const serverRoot = ChromeDocument.INTERNAL_SERVERROOT;
1060
- const srcDir = path.join(this.baseDirectory, serverRoot);
1061
- if (!isDir(srcDir)) {
1062
- return;
1063
- }
1064
- const result = await Document.copyDir(srcDir, productionRelease, this.incremental !== 'staging');
1065
- const failed = result.failed.map(value => this.removeCwd(value));
1066
- for (const value of this.files) {
1067
- if (!value.startsWith(serverRoot)) {
1068
- continue;
1069
- }
1070
- if (!failed.includes(value)) {
1071
- this.delete(value);
1072
- }
1073
- else {
1074
- instance.writeFail(["Unable to move file", instance.moduleName], (0, types_1.errorMessage)('production', path.join(this.baseDirectory, value)), { fatal: true });
1093
+ if ((0, types_1.isString)(productionRelease)) {
1094
+ if (path.isAbsolute(productionRelease = path.normalize(productionRelease)) && isDir(productionRelease)) {
1095
+ if (this.canWrite(productionRelease)) {
1096
+ const serverRoot = ChromeDocument.INTERNAL_SERVERROOT;
1097
+ const srcDir = path.join(this.baseDirectory, serverRoot);
1098
+ if (isDir(srcDir)) {
1099
+ const result = await Document.copyDir(srcDir, productionRelease, this.incremental !== 'staging');
1100
+ const failed = result.failed.map(value => this.removeCwd(value));
1101
+ for (const value of this.files) {
1102
+ if (value.startsWith(serverRoot)) {
1103
+ if (!failed.includes(value)) {
1104
+ this.delete(value);
1105
+ }
1106
+ else {
1107
+ instance.writeFail(["Unable to move file", instance.moduleName], (0, types_1.errorMessage)('production', path.join(this.baseDirectory, value)), { fatal: true });
1108
+ }
1109
+ }
1110
+ }
1075
1111
  }
1076
1112
  }
1113
+ else {
1114
+ instance.writeFail(["Unable to write directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Access denied', productionRelease));
1115
+ }
1077
1116
  }
1078
1117
  else {
1079
- instance.writeFail(["Unable to write directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Access denied', productionRelease));
1118
+ instance.writeFail(["Unable to read directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Invalid directory', productionRelease), 32);
1080
1119
  }
1081
1120
  }
1082
- else {
1083
- instance.writeFail(["Unable to read directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Invalid directory', productionRelease), 32);
1084
- }
1085
1121
  }
1086
1122
  static sanitizeAssets(assets, exclusions = []) {
1087
1123
  assets.forEach(item => {
@@ -1162,7 +1198,6 @@ class ChromeDocument extends Document {
1162
1198
  }
1163
1199
  return 0;
1164
1200
  });
1165
- let imports;
1166
1201
  if (config) {
1167
1202
  const { useUnsafeReplace, baseUrl, productionRelease, productionIncremental, templateMap, userAgentData, cache } = config;
1168
1203
  const target = this.config;
@@ -1209,37 +1244,25 @@ class ChromeDocument extends Document {
1209
1244
  if ((0, types_1.isObject)(userAgentData)) {
1210
1245
  this.userAgentData = userAgentData;
1211
1246
  }
1247
+ const imports = (0, types_1.isPlainObject)(config.imports) ? { ...this.module.imports, ...config.imports } : this.module.imports;
1248
+ if (imports) {
1249
+ this.imports = imports;
1250
+ }
1212
1251
  if ((0, types_1.isObject)(cache) && 'transform' in cache) {
1213
1252
  this.customize({ transform: cache.transform });
1214
1253
  }
1215
- if (!(0, types_1.isPlainObject)(imports = config.imports)) {
1216
- imports = undefined;
1217
- }
1218
1254
  }
1219
1255
  super.init(assets, config);
1220
1256
  const mimeMap = this._mimeMap;
1221
- if (mimeMap) {
1222
- if ('imports' in mimeMap) {
1223
- const imported = mimeMap.imports;
1224
- if ((0, types_1.isPlainObject)(imported)) {
1225
- imports = imports ? Object.assign(imported, imports) : imported;
1226
- }
1227
- delete mimeMap.imports;
1257
+ if (mimeMap && 'format' in mimeMap) {
1258
+ const format = mimeMap.format;
1259
+ if ((0, types_1.isObject)(format)) {
1260
+ this.formatMap = 'pathname' in format || 'filename' in format || 'dictionary' in format ? { uuid: format } : format;
1228
1261
  }
1229
- if ('format' in mimeMap) {
1230
- const format = mimeMap.format;
1231
- if ((0, types_1.isObject)(format)) {
1232
- this.formatMap = 'pathname' in format || 'filename' in format || 'dictionary' in format ? { uuid: format } : format;
1233
- }
1234
- else {
1235
- this.formatMap = undefined;
1236
- }
1237
- delete mimeMap.format;
1262
+ else {
1263
+ this.formatMap = undefined;
1238
1264
  }
1239
1265
  }
1240
- if (imports) {
1241
- this.imports = imports;
1242
- }
1243
1266
  for (const storage of cloud) {
1244
1267
  for (const { service, upload, download } of storage) {
1245
1268
  if (upload) {
@@ -1667,9 +1690,8 @@ class ChromeDocument extends Document {
1667
1690
  this._cloudUrlMap = Object.create(null);
1668
1691
  this._cloudUploaded = new Set();
1669
1692
  this._cloudEndpoint = null;
1670
- const htmlFile = this.htmlFile;
1671
- if (htmlFile) {
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;
1693
+ if (this.htmlFile) {
1694
+ const endpoint = (_b = (_a = instance.getStorage('upload', this.htmlFile.cloudStorage)) === null || _a === void 0 ? void 0 : _a.upload) === null || _b === void 0 ? void 0 : _b.endpoint;
1673
1695
  if (endpoint) {
1674
1696
  this._cloudEndpoint = new RegExp((0, types_1.escapePattern)(toPosix(endpoint)) + '/', 'g');
1675
1697
  }
@@ -1850,7 +1872,9 @@ class ChromeDocument extends Document {
1850
1872
  }
1851
1873
  }
1852
1874
  search !== null && search !== void 0 ? search : (search = restoreSearchParams((_a = asset.url) === null || _a === void 0 ? void 0 : _a.search));
1853
- status && (status = status.filter(item => item.type >= types_1.STATUS_TYPE.FATAL && item.type <= types_1.STATUS_TYPE.WARN));
1875
+ if (status) {
1876
+ status = status.filter(item => item.type >= types_1.STATUS_TYPE.FATAL && item.type <= types_1.STATUS_TYPE.WARN);
1877
+ }
1854
1878
  watch.send(types_1.WATCH_EVENT.MODIFIED, {
1855
1879
  action: pathname && watch.hot && !watch.main ? 'hot' : '',
1856
1880
  type: asset.mimeType,
@@ -2027,9 +2051,8 @@ class ChromeDocument extends Document {
2027
2051
  item.modified = true;
2028
2052
  }
2029
2053
  source = sanitizeSource(item, source);
2030
- const format = item.format;
2031
- if (format) {
2032
- const result = await this.transform('html', source, format, transformOptions.call(this, item, 'image/svg+xml'));
2054
+ if (item.format) {
2055
+ const result = await this.transform('html', source, item.format, transformOptions.call(this, item, 'image/svg+xml'));
2033
2056
  if (result) {
2034
2057
  item.modified = true;
2035
2058
  source = result.code;
@@ -2139,12 +2162,11 @@ class ChromeDocument extends Document {
2139
2162
  await this.setElementAttributes(processing, domBase);
2140
2163
  await this.applyDataSource(processing, domBase);
2141
2164
  for (const item of this.assets) {
2142
- const element = item.element;
2143
- if (element && isRemoved(item) && !(0, types_1.ignoreFlag)(item.flags)) {
2144
- const domElement = new dom_1.HtmlElement(moduleName, element, item.attributes);
2165
+ if (item.element && isRemoved(item) && !(0, types_1.ignoreFlag)(item.flags)) {
2166
+ const domElement = new dom_1.HtmlElement(moduleName, item.element, item.attributes);
2145
2167
  domElement.remove = true;
2146
2168
  if (!domBase.write(domElement)) {
2147
- this.writeFail('Unable to exclude HTML element', errorHtml(element), 4);
2169
+ this.writeFail('Unable to exclude HTML element', errorHtml(item.element), 4);
2148
2170
  }
2149
2171
  }
2150
2172
  }
@@ -2165,15 +2187,13 @@ class ChromeDocument extends Document {
2165
2187
  if ((0, types_1.isString)(config.stripCommentsAndCDATA)) {
2166
2188
  source = dom_1.DomWriter.getCommentsAndCDATA(source, config.stripCommentsAndCDATA, true, true);
2167
2189
  }
2168
- const format = htmlFile.format;
2169
- if (format) {
2170
- const { filename, uri, encoding, metadata } = htmlFile;
2171
- const result = await this.transform('html', source, format, {
2190
+ if (htmlFile.format) {
2191
+ const result = await this.transform('html', source, htmlFile.format, {
2172
2192
  pathname: path.dirname(localUri),
2173
- filename,
2193
+ filename: htmlFile.filename,
2174
2194
  mimeType: 'text/html',
2175
- metadata: Object.assign({ '__fromhtml__': true, ...this.config }, metadata),
2176
- cacheData: !productionRelease || this.productionIncremental ? { uri, encoding } : undefined
2195
+ metadata: Object.assign({ '__fromhtml__': true, ...this.config }, htmlFile.metadata),
2196
+ cacheData: !productionRelease || this.productionIncremental ? { uri: htmlFile.uri, encoding: htmlFile.encoding } : undefined
2177
2197
  });
2178
2198
  if (result) {
2179
2199
  source = result.code;
@@ -2207,12 +2227,12 @@ class ChromeDocument extends Document {
2207
2227
  const cloud = host.Cloud;
2208
2228
  const removeWatchReload = (item) => (0, types_1.isObject)(item.watch) && delete item.watch.reload;
2209
2229
  for (const item of this.assets) {
2210
- const { element, inlineContent } = item;
2230
+ const element = item.element;
2211
2231
  if (!element || element.removed || isRemoved(item) || isUnedited(item) || (0, types_1.ignoreFlag)(item.flags) && !(0, types_1.processFlag)(item.flags)) {
2212
2232
  continue;
2213
2233
  }
2214
2234
  const domElement = new dom_1.HtmlElement(moduleName, element, item.attributes);
2215
- if (inlineContent) {
2235
+ if (item.inlineContent) {
2216
2236
  let [innerXml, sourceMappingURL, inlineMap] = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(item).trim());
2217
2237
  if (sourceMappingURL && !inlineMap && item.localUri) {
2218
2238
  let mapUri = path.resolve(sourceMappingURL = decodeURIComponent(sourceMappingURL));
@@ -2221,7 +2241,7 @@ class ChromeDocument extends Document {
2221
2241
  }
2222
2242
  host.deleteFile(mapUri);
2223
2243
  }
2224
- domElement.tagName = inlineContent;
2244
+ domElement.tagName = item.inlineContent;
2225
2245
  domElement.innerXml = innerXml;
2226
2246
  domElement.removeAttribute('src', 'href');
2227
2247
  }
@@ -2311,10 +2331,10 @@ class ChromeDocument extends Document {
2311
2331
  }
2312
2332
  }
2313
2333
  if (!domBase.write(domElement)) {
2314
- this.writeFail(inlineContent ? 'Inline tag replacement' : 'Element attribute replacement', errorHtml(element), { type: 4, startTime });
2334
+ this.writeFail(item.inlineContent ? 'Inline tag replacement' : 'Element attribute replacement', errorHtml(element), { type: 4, startTime });
2315
2335
  delete item.inlineUrlCloud;
2316
2336
  }
2317
- else if (inlineContent) {
2337
+ else if (item.inlineContent) {
2318
2338
  host.removeAsset(item);
2319
2339
  removeWatchReload(item);
2320
2340
  }
@@ -2911,7 +2931,7 @@ class ChromeDocument extends Document {
2911
2931
  for (let j = 0, match; j < items.length; ++j) {
2912
2932
  const row = items[j];
2913
2933
  if ((0, types_1.isPlainObject)(row)) {
2914
- (_c = row.__index__) !== null && _c !== void 0 ? _c : (row.__index__ = j + 1);
2934
+ (_c = row['__index__']) !== null && _c !== void 0 ? _c : (row['__index__'] = j + 1);
2915
2935
  }
2916
2936
  let segment = template;
2917
2937
  while (match = REGEXP_TEMPLATECONDITIONAL.exec(segment)) {
@@ -3061,7 +3081,8 @@ class ChromeDocument extends Document {
3061
3081
  const row = items[0];
3062
3082
  let condition = NaN;
3063
3083
  for (let seg of template) {
3064
- switch ((seg = seg.trim()).toLowerCase()) {
3084
+ seg = seg.trim();
3085
+ switch (seg.toLowerCase()) {
3065
3086
  case ':is(and)':
3066
3087
  if (condition === 0) {
3067
3088
  remove = false;
@@ -3254,7 +3275,7 @@ class ChromeDocument extends Document {
3254
3275
  const parseSelector = (value) => {
3255
3276
  const items = [];
3256
3277
  const revised = value.replace(useUnsafeCssReplace ? REGEXP_NTHCHILD_UNSAFE : REGEXP_NTHCHILD, (...capture) => {
3257
- 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) + '`';
3278
+ 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) + '`';
3258
3279
  });
3259
3280
  let selector = '';
3260
3281
  for (let i = 0, length = revised.length, casing = false, attr = false, quote = false; i < length; i++) {
package/package.json CHANGED
@@ -1,28 +1,28 @@
1
- {
2
- "name": "@pi-r/chrome",
3
- "version": "0.3.4",
4
- "description": "Chrome document constructor for E-mc.",
5
- "main": "index.js",
6
- "publishConfig": {
7
- "access": "public"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/anpham6/pi-r.git",
12
- "directory": "src/module/chrome"
13
- },
14
- "keywords": [
15
- "squared",
16
- "e-mc",
17
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "MIT",
21
- "homepage": "https://github.com/anpham6/pi-r#readme",
22
- "dependencies": {
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
- }
28
- }
1
+ {
2
+ "name": "@pi-r/chrome",
3
+ "version": "0.3.6",
4
+ "description": "Chrome document constructor for E-mc.",
5
+ "main": "index.js",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/anpham6/pi-r.git",
12
+ "directory": "src/module/chrome"
13
+ },
14
+ "keywords": [
15
+ "squared",
16
+ "e-mc",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "MIT",
21
+ "homepage": "https://github.com/anpham6/pi-r#readme",
22
+ "dependencies": {
23
+ "@e-mc/cloud": "^0.6.16",
24
+ "@e-mc/core": "^0.6.16",
25
+ "@e-mc/document": "^0.6.16",
26
+ "@e-mc/types": "^0.6.16"
27
+ }
28
+ }
package/types/index.d.ts CHANGED
@@ -1,119 +1,118 @@
1
- import type { LocationUri, XmlTagNode } from '@e-mc/types/lib/squared';
2
-
3
- import type { DocumentConstructor, ICloud, IDocument, IFileManager } from '@e-mc/types/lib';
4
- import type { DocumentAsset as IDocumentAsset } from '@e-mc/types/lib/document';
5
- import type { LogTime } from '@e-mc/types/lib/logger';
6
- import type { DbSourceDataType, DocumentComponentOption, DocumentComponent as IDocumentComponent, DocumentComponentOptions as IDocumentComponentOptions, DocumentDirectory as IDocumentDirectory, DocumentEval as IDocumentEval, DocumentModule as IDocumentModule, DocumentSettings as IDocumentSettings } from '@e-mc/types/lib/settings';
7
-
8
- import type { CloudScopeOrigin } from '@e-mc/cloud/types';
9
- import type { IDomWriter, IXmlElement } from '@e-mc/document/parse/types';
10
-
11
- import type { ChromeAsset, CssRuleData, DataSource, DocumentOutput } from './squared';
12
-
13
- interface DocumentDirectory extends IDocumentDirectory {
14
- template?: string;
15
- data?: string;
16
- export?: string;
17
- schema?: string;
18
- sql?: string;
19
- }
20
-
21
- interface DocumentComponentExtended<T> extends DbSourceDataType<T> {
22
- uri?: T;
23
- local?: T;
24
- export?: T;
25
- }
26
-
27
- interface DocumentComponentOptions<T> extends IDocumentComponentOptions, DocumentComponentExtended<DocumentComponentOption<T>> {}
28
-
29
- interface DocumentEval extends IDocumentEval {
30
- template?: boolean;
31
- userconfig?: boolean;
32
- }
33
-
34
- interface ChromeDocumentSettings extends IDocumentSettings {
35
- directory?: DocumentDirectory;
36
- options?: DocumentComponentOptions<boolean | number>;
37
- export?: ObjectMap<string | FunctionType>;
38
- }
39
-
40
- type OutputType = "useUnsafeReplace" | "productionRelease" | "productionIncremental" | "templateMap" | "userAgentData";
41
-
42
- export interface FormatUri extends Partial<LocationUri> {
43
- dictionary?: string;
44
- }
45
-
46
- export interface FinalizeProcessing<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> {
47
- readonly host: T;
48
- readonly startTime: LogTime;
49
- readonly hashed: Set<DocumentAsset>;
50
- readonly contentMap: StringMap;
51
- readonly bufferMap: ObjectMap<BufferContent>;
52
- readonly cacheMiss: string[];
53
- readonly productionRelease: Undef<true>;
54
- }
55
-
56
- export interface DocumentComponent<T = boolean> extends IDocumentComponent<T, T>, DocumentComponentExtended<T> {}
57
-
58
- export interface DocumentModule extends IDocumentModule {
59
- eval?: DocumentEval;
60
- format?: PlainObject & { uuid?: FormatUri };
61
- settings?: ChromeDocumentSettings;
62
- }
63
-
64
- export interface DocumentAsset extends IDocumentAsset, ChromeAsset {
65
- relativeUrl?: string;
66
- inlineFilename?: string;
67
- srcSet?: string[];
68
- inlineUrl?: string;
69
- inlineUrlMap?: StringMap;
70
- inlineUrlCloud?: string;
71
- inlineUrlCloudMap?: StringMap;
72
- inlineBase64?: string;
73
- modified?: boolean;
74
- }
75
-
76
- export interface UserConfig extends CssRuleData, Omit<DocumentOutput, OutputType> {
77
- useUnsafeHtmlReplace?: boolean;
78
- useUnsafeCssReplace?: boolean;
79
- }
80
-
81
- 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> {
82
- htmlFile: Null<U>;
83
- cssFiles: U[];
84
- jsFiles: U[];
85
- svgFiles: U[];
86
- baseDirectory: string;
87
- baseUrl: string;
88
- config: UserConfig;
89
- related: Map<U, Set<U>>;
90
- replaced: U[];
91
- formatMap?: ObjectMap<FormatUri>;
92
- setElementSrc(asset: U, element: IXmlElement, value: string): void;
93
- findDataValue(name: string): Undef<string>;
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
- removeUnusedStyles(source: string, options?: UserConfig): Undef<string>;
101
- removeServerRoot(value: string): string;
102
- replaceContent(source: string, match: RegExpExecArray | string, mimeType?: string): Undef<string>;
103
- cloudInit(state: CloudScopeOrigin<T, U, V>): void;
104
- cloudObject(state: CloudScopeOrigin<T, U, V>, file: U): boolean;
105
- cloudUpload(state: CloudScopeOrigin<T, U, V>, file: U, url: string, active: boolean): Promise<boolean>;
106
- cloudFinalize(state: CloudScopeOrigin<T, U, V>): Promise<unknown[]>;
107
- get editing(): U[];
108
- set dataSource(value);
109
- get dataSource(): DataSource[];
110
- get elements(): XmlTagNode[];
111
- get settings(): ChromeDocumentSettings;
112
- }
113
-
114
- export interface ChromeDocumentConstructor<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> extends DocumentConstructor<T, U> {
115
- INTERNAL_ASSIGNUUID: string;
116
- INTERNAL_SERVERROOT: string;
117
- readonly prototype: IChromeDocument<T, U>;
118
- new(module?: DocumentModule, ...args: unknown[]): IChromeDocument<T, U>;
1
+ import type { LocationUri, XmlTagNode } from '@e-mc/types/lib/squared';
2
+
3
+ import type { DocumentConstructor, ICloud, IDocument, IFileManager } from '@e-mc/types/lib';
4
+ import type { DocumentAsset as IDocumentAsset } from '@e-mc/types/lib/document';
5
+ import type { LogTime } from '@e-mc/types/lib/logger';
6
+ import type { DbSourceDataType, DocumentComponentOption, DocumentComponent as IDocumentComponent, DocumentComponentOptions as IDocumentComponentOptions, DocumentDirectory as IDocumentDirectory, DocumentEval as IDocumentEval, DocumentModule as IDocumentModule, DocumentSettings as IDocumentSettings } from '@e-mc/types/lib/settings';
7
+
8
+ import type { CloudScopeOrigin } from '@e-mc/cloud/types';
9
+ import type { IDomWriter, IXmlElement } from '@e-mc/document/parse/types';
10
+
11
+ import type { ChromeAsset, CssRuleData, DataSource, DocumentOutput } from './squared';
12
+
13
+ interface DocumentDirectory extends IDocumentDirectory {
14
+ template?: string;
15
+ data?: string;
16
+ export?: string;
17
+ schema?: string;
18
+ sql?: string;
19
+ }
20
+
21
+ interface DocumentComponentExtended<T> extends DbSourceDataType<T> {
22
+ uri?: T;
23
+ local?: T;
24
+ export?: T;
25
+ }
26
+
27
+ interface DocumentComponentOptions<T> extends IDocumentComponentOptions, DocumentComponentExtended<DocumentComponentOption<T>> {}
28
+
29
+ interface DocumentEval extends IDocumentEval {
30
+ template?: boolean;
31
+ userconfig?: boolean;
32
+ }
33
+
34
+ interface ChromeDocumentSettings extends IDocumentSettings {
35
+ directory?: DocumentDirectory;
36
+ options?: DocumentComponentOptions<boolean | number>;
37
+ export?: ObjectMap<string | FunctionType>;
38
+ }
39
+
40
+ type OutputType = "useUnsafeReplace" | "productionRelease" | "productionIncremental" | "templateMap" | "userAgentData";
41
+
42
+ export interface FormatUri extends Partial<LocationUri> {
43
+ dictionary?: string;
44
+ }
45
+
46
+ export interface FinalizeProcessing<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> {
47
+ readonly host: T;
48
+ readonly startTime: LogTime;
49
+ readonly hashed: Set<DocumentAsset>;
50
+ readonly contentMap: StringMap;
51
+ readonly bufferMap: ObjectMap<BufferContent>;
52
+ readonly cacheMiss: string[];
53
+ readonly productionRelease: Undef<true>;
54
+ }
55
+
56
+ export interface DocumentComponent<T = boolean> extends IDocumentComponent<T, T>, DocumentComponentExtended<T> {}
57
+
58
+ export interface DocumentModule extends IDocumentModule {
59
+ eval?: DocumentEval;
60
+ format?: PlainObject & { uuid?: FormatUri };
61
+ settings?: ChromeDocumentSettings;
62
+ }
63
+
64
+ export interface DocumentAsset extends IDocumentAsset, ChromeAsset {
65
+ relativeUrl?: string;
66
+ inlineFilename?: string;
67
+ srcSet?: string[];
68
+ inlineUrl?: string;
69
+ inlineUrlMap?: StringMap;
70
+ inlineUrlCloud?: string;
71
+ inlineUrlCloudMap?: StringMap;
72
+ inlineBase64?: string;
73
+ modified?: boolean;
74
+ }
75
+
76
+ export interface UserConfig extends CssRuleData, Omit<DocumentOutput, OutputType> {
77
+ useUnsafeHtmlReplace?: boolean;
78
+ useUnsafeCssReplace?: boolean;
79
+ }
80
+
81
+ 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> {
82
+ htmlFile: Null<U>;
83
+ cssFiles: U[];
84
+ jsFiles: U[];
85
+ svgFiles: U[];
86
+ baseDirectory: string;
87
+ baseUrl: string;
88
+ config: UserConfig;
89
+ related: Map<U, Set<U>>;
90
+ replaced: U[];
91
+ formatMap?: ObjectMap<FormatUri>;
92
+ setElementSrc(asset: U, element: IXmlElement, value: string): void;
93
+ findDataValue(name: string): Undef<string>;
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
+ removeUnusedStyles(source: string, options?: UserConfig): Undef<string>;
101
+ removeServerRoot(value: string): string;
102
+ replaceContent(source: string, match: RegExpExecArray | string, mimeType?: string): Undef<string>;
103
+ cloudInit(state: CloudScopeOrigin<T, U, V>): void;
104
+ cloudObject(state: CloudScopeOrigin<T, U, V>, file: U): boolean;
105
+ cloudUpload(state: CloudScopeOrigin<T, U, V>, file: U, url: string, active: boolean): Promise<boolean>;
106
+ cloudFinalize(state: CloudScopeOrigin<T, U, V>): Promise<unknown[]>;
107
+ get settings(): ChromeDocumentSettings;
108
+ get editing(): U[];
109
+ get dataSource(): DataSource[];
110
+ get elements(): XmlTagNode[];
111
+ }
112
+
113
+ export interface ChromeDocumentConstructor<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> extends DocumentConstructor<T, U> {
114
+ INTERNAL_ASSIGNUUID: string;
115
+ INTERNAL_SERVERROOT: string;
116
+ readonly prototype: IChromeDocument<T, U>;
117
+ new(module?: DocumentModule, ...args: unknown[]): IChromeDocument<T, U>;
119
118
  }
@@ -1,114 +1,114 @@
1
- import type { AttributeAction, ConditionProperty, CssConditionData, ElementAction, ExcludeAction, FileAsset, FromAction, HashAction, DataSource as IDataSource, ImportAction, MetadataAction, ViewEngine, XmlTagNode } from '@e-mc/types/lib/squared';
2
-
3
- import type { UploadAction } from '@e-mc/types/lib/cloud';
4
- import type { CascadeAction, DbSource } from '@e-mc/types/lib/db';
5
- import type { RequestData as IRequestData } from '@e-mc/types/lib/node';
6
-
7
- interface ImportFrom {
8
- placeholder: string;
9
- original: string;
10
- uri: string;
11
- type?: string;
12
- dynamic?: boolean;
13
- }
14
-
15
- interface DataObject extends CascadeAction {
16
- format?: string;
17
- options?: PlainObject;
18
- }
19
-
20
- export interface UserAgentData {
21
- platform: string;
22
- brand: string;
23
- browser: number;
24
- version: Null<number[]>;
25
- }
26
-
27
- export interface DocumentOutput {
28
- productionRelease?: boolean | string;
29
- productionIncremental?: boolean;
30
- useOriginalHtmlPage?: boolean | string;
31
- useUnsafeReplace?: ArrayOf<"html" | "css"> | boolean;
32
- stripCommentsAndCDATA?: boolean | string;
33
- normalizeHtmlOutput?: boolean | string;
34
- escapeReservedCharacters?: boolean;
35
- ignoreServerCodeBlocks?: string[];
36
- webBundle?: {
37
- rootDirAlias?: string;
38
- baseUrl?: string;
39
- primaryUrl?: string;
40
- copyTo?: string;
41
- rewriteHtmlPage?: boolean | string;
42
- excludeHtmlPage?: boolean;
43
- excludeTransforms?: boolean;
44
- includeScopes?: string[];
45
- excludeScopes?: string[];
46
- };
47
- templateMap?: TemplateMap;
48
- userAgentData?: Partial<UserAgentData>;
49
- }
50
-
51
- export interface RequestData extends IRequestData<ChromeAsset>, Readonly<DocumentOutput>, Readonly<CssRuleData> {}
52
-
53
- export interface ChromeAsset extends FileAsset, AttributeAction, ElementAction, MetadataAction<PlainObject>, UploadAction, HashAction, ExcludeAction, ImportAction<ImportFrom[] | boolean>, FromAction {
54
- preserve?: boolean;
55
- static?: boolean;
56
- editing?: boolean;
57
- inlineContent?: string;
58
- originAddress?: boolean;
59
- }
60
-
61
- export interface TemplateMap extends PlainObject {
62
- html?: ObjectMap<StringMap>;
63
- js?: ObjectMap<StringMap>;
64
- css?: ObjectMap<StringMap>;
65
- data?: StringMap;
66
- }
67
-
68
- export interface CssRuleData {
69
- usedVariables?: string[];
70
- usedFontFace?: string[];
71
- usedKeyframes?: string[];
72
- unusedStyles?: string[];
73
- unusedMedia?: string[];
74
- unusedContainer?: string[];
75
- unusedSupports?: string[];
76
- unusedAtRules?: UnusedAtRule[];
77
- }
78
-
79
- export interface UnusedAtRule {
80
- selector?: string;
81
- media?: ConditionProperty;
82
- supports?: ConditionProperty;
83
- container?: CssConditionData & Partial<ConditionProperty>;
84
- layer?: string[];
85
- }
86
-
87
- export interface DataSource<T = string> extends IDataSource<T>, ElementAction {
88
- source: "cloud" | "uri" | "local" | "export" | DbSource;
89
- element?: XmlTagNode;
90
- type?: "text" | "attribute" | "display";
91
- dynamic?: boolean;
92
- value?: StringOfArray | ObjectMap<unknown>;
93
- template?: string;
94
- viewEngine?: ViewEngine | string;
95
- ignoreEmpty?: boolean;
96
- }
97
-
98
- export interface UriDataSource extends DataSource, DataObject {
99
- source: "uri";
100
- }
101
-
102
- export interface LocalDataSource extends DataSource, DataObject {
103
- source: "local";
104
- pathname?: string;
105
- }
106
-
107
- export interface ExportDataSource extends DataSource, CascadeAction {
108
- source: "export";
109
- execute?: FunctionType;
110
- pathname?: string;
111
- settings?: string;
112
- params?: unknown;
113
- persist?: boolean;
1
+ import type { AttributeAction, ConditionProperty, CssConditionData, ElementAction, ExcludeAction, FileAsset, FromAction, HashAction, DataSource as IDataSource, ImportAction, MetadataAction, ViewEngine, XmlTagNode } from '@e-mc/types/lib/squared';
2
+
3
+ import type { UploadAction } from '@e-mc/types/lib/cloud';
4
+ import type { CascadeAction, DbSource } from '@e-mc/types/lib/db';
5
+ import type { RequestData as IRequestData } from '@e-mc/types/lib/node';
6
+
7
+ interface ImportFrom {
8
+ placeholder: string;
9
+ original: string;
10
+ uri: string;
11
+ type?: string;
12
+ dynamic?: boolean;
13
+ }
14
+
15
+ interface DataObject extends CascadeAction {
16
+ format?: string;
17
+ options?: PlainObject;
18
+ }
19
+
20
+ export interface UserAgentData {
21
+ platform: string;
22
+ brand: string;
23
+ browser: number;
24
+ version: Null<number[]>;
25
+ }
26
+
27
+ export interface DocumentOutput {
28
+ productionRelease?: boolean | string;
29
+ productionIncremental?: boolean;
30
+ useOriginalHtmlPage?: boolean | string;
31
+ useUnsafeReplace?: ArrayOf<"html" | "css"> | boolean;
32
+ stripCommentsAndCDATA?: boolean | string;
33
+ normalizeHtmlOutput?: boolean | string;
34
+ escapeReservedCharacters?: boolean;
35
+ ignoreServerCodeBlocks?: string[];
36
+ webBundle?: {
37
+ rootDirAlias?: string;
38
+ baseUrl?: string;
39
+ primaryUrl?: string;
40
+ copyTo?: string;
41
+ rewriteHtmlPage?: boolean | string;
42
+ excludeHtmlPage?: boolean;
43
+ excludeTransforms?: boolean;
44
+ includeScopes?: string[];
45
+ excludeScopes?: string[];
46
+ };
47
+ templateMap?: TemplateMap;
48
+ userAgentData?: Partial<UserAgentData>;
49
+ }
50
+
51
+ export interface RequestData extends IRequestData<ChromeAsset>, Readonly<DocumentOutput>, Readonly<CssRuleData> {}
52
+
53
+ export interface ChromeAsset extends FileAsset, AttributeAction, ElementAction, MetadataAction<PlainObject>, UploadAction, HashAction, ExcludeAction, ImportAction<ImportFrom[] | boolean>, FromAction {
54
+ preserve?: boolean;
55
+ static?: boolean;
56
+ editing?: boolean;
57
+ inlineContent?: string;
58
+ originAddress?: boolean;
59
+ }
60
+
61
+ export interface TemplateMap extends PlainObject {
62
+ html?: ObjectMap<StringMap>;
63
+ js?: ObjectMap<StringMap>;
64
+ css?: ObjectMap<StringMap>;
65
+ data?: StringMap;
66
+ }
67
+
68
+ export interface CssRuleData {
69
+ usedVariables?: string[];
70
+ usedFontFace?: string[];
71
+ usedKeyframes?: string[];
72
+ unusedStyles?: string[];
73
+ unusedMedia?: string[];
74
+ unusedContainer?: string[];
75
+ unusedSupports?: string[];
76
+ unusedAtRules?: UnusedAtRule[];
77
+ }
78
+
79
+ export interface UnusedAtRule {
80
+ selector?: string;
81
+ media?: ConditionProperty;
82
+ supports?: ConditionProperty;
83
+ container?: CssConditionData & Partial<ConditionProperty>;
84
+ layer?: string[];
85
+ }
86
+
87
+ export interface DataSource<T = string> extends IDataSource<T>, ElementAction {
88
+ source: "cloud" | "uri" | "local" | "export" | DbSource;
89
+ element?: XmlTagNode;
90
+ type?: "text" | "attribute" | "display";
91
+ dynamic?: boolean;
92
+ value?: StringOfArray | ObjectMap<unknown>;
93
+ template?: string;
94
+ viewEngine?: ViewEngine | string;
95
+ ignoreEmpty?: boolean;
96
+ }
97
+
98
+ export interface UriDataSource extends DataSource, DataObject {
99
+ source: "uri";
100
+ }
101
+
102
+ export interface LocalDataSource extends DataSource, DataObject {
103
+ source: "local";
104
+ pathname?: string;
105
+ }
106
+
107
+ export interface ExportDataSource extends DataSource, CascadeAction {
108
+ source: "export";
109
+ execute?: FunctionType;
110
+ pathname?: string;
111
+ settings?: string;
112
+ params?: unknown;
113
+ persist?: boolean;
114
114
  }