@pi-r/chrome 0.3.5 → 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 +6 -6
- package/README.md +4 -6
- package/index.d.ts +6 -6
- package/index.js +118 -145
- package/package.json +28 -28
- package/types/index.d.ts +117 -118
- package/types/squared.d.ts +113 -113
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright
|
|
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
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
|
@@ -46,13 +46,9 @@ const REGEXP_VARIABLES_UNSAFE = new RegExp(`(\\s*)(--[^\\s:]*)\\s*:[^;}]*([;}])`
|
|
|
46
46
|
const REGEXP_FONTFACE_UNSAFE = new RegExp(`(\\s*)@font-face\\s*{([^}]+)}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
|
|
47
47
|
const REGEXP_FONTFAMILY_UNSAFE = /font-family\s*:([^;}]+)/i;
|
|
48
48
|
const REGEXP_KEYFRAMES_UNSAFE = /(\s*)@keyframes\s+([^{]+){/gi;
|
|
49
|
-
const REGEXP_OBJECT_NAME = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
|
|
50
|
-
const REGEXP_OBJECT_SUBSCRIPT = /\[\s*(["'])?(.+?)\1\s*\]/g;
|
|
51
|
-
const REGEXP_TEMPLATE_LEADING = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
|
|
52
|
-
const REGEXP_TEMPLATE_TRAILING = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
|
|
53
49
|
function removeNamespace(name, source, newline, comments) {
|
|
54
50
|
if (source.indexOf('-' + name) !== -1) {
|
|
55
|
-
const
|
|
51
|
+
const dataset = CACHE_DATASET[name] || (CACHE_DATASET[name] = [
|
|
56
52
|
new RegExp(`(\\s*)<(script|style)(${dom_1.DomWriter.PATTERN_TAGOPEN}+)>[\\S\\s]*?<\\/\\2\\s*>` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi'),
|
|
57
53
|
new RegExp(`(\\s*)<link(${dom_1.DomWriter.PATTERN_TAGOPEN}+)>` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi'),
|
|
58
54
|
new RegExp(`\\s+data-${name}-[a-z-]+\\s*` + dom_1.DomWriter.PATTERN_ATTRVALUE, 'g'),
|
|
@@ -60,26 +56,24 @@ function removeNamespace(name, source, newline, comments) {
|
|
|
60
56
|
new RegExp(`data-${name}-template\\s*` + dom_1.DomWriter.PATTERN_ATTRVALUE)
|
|
61
57
|
]);
|
|
62
58
|
source = source
|
|
63
|
-
.replace(
|
|
64
|
-
.replace(
|
|
65
|
-
.replace(
|
|
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], '');
|
|
66
62
|
}
|
|
67
63
|
return (0, types_1.isArray)(comments) ? source.replace(REGEXP_BLOCKEXCLUDE, (...capture) => getNewlineString(capture[1], capture[2], newline)) : source;
|
|
68
64
|
}
|
|
69
65
|
function getObjectValue(value, key) {
|
|
70
|
-
|
|
66
|
+
const pattern = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
|
|
71
67
|
let found, match;
|
|
72
|
-
while (match =
|
|
68
|
+
while (match = pattern.exec(key)) {
|
|
73
69
|
if ((0, types_1.isObject)(value)) {
|
|
74
70
|
value = value[match[1]];
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
REGEXP_OBJECT_SUBSCRIPT.lastIndex = 0;
|
|
71
|
+
if (match[2]) {
|
|
72
|
+
const subscript = /\[\s*(["'])?(.+?)\1\s*\]/g;
|
|
78
73
|
let index;
|
|
79
|
-
while (index =
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
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))) {
|
|
83
77
|
value = value[attr];
|
|
84
78
|
}
|
|
85
79
|
else {
|
|
@@ -97,14 +91,14 @@ function getObjectValue(value, key) {
|
|
|
97
91
|
return found ? value : null;
|
|
98
92
|
}
|
|
99
93
|
function trimTemplate(value) {
|
|
100
|
-
|
|
94
|
+
const leading = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
|
|
101
95
|
let match;
|
|
102
|
-
while (match =
|
|
103
|
-
value = replaceMatch(match, value, 1,
|
|
96
|
+
while (match = leading.exec(value)) {
|
|
97
|
+
value = replaceMatch(match, value, 1, leading);
|
|
104
98
|
}
|
|
105
|
-
|
|
106
|
-
while (match =
|
|
107
|
-
value = replaceMatch(match, value, 1,
|
|
99
|
+
const trailing = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
|
|
100
|
+
while (match = trailing.exec(value)) {
|
|
101
|
+
value = replaceMatch(match, value, 1, trailing);
|
|
108
102
|
}
|
|
109
103
|
return value;
|
|
110
104
|
}
|
|
@@ -182,15 +176,15 @@ function hasCondition(data, condition) {
|
|
|
182
176
|
}
|
|
183
177
|
let match = REGEXP_TEMPLATEMATCH.exec(condition.trim());
|
|
184
178
|
if (match) {
|
|
185
|
-
|
|
186
|
-
if (comparison) {
|
|
179
|
+
if (match[2]) {
|
|
187
180
|
const join = match[1];
|
|
181
|
+
const comparison = match[2];
|
|
188
182
|
const items = [];
|
|
189
183
|
while (match = REGEXP_TEMPLATECOMPARISON.exec(comparison)) {
|
|
190
184
|
if (items.length && !isSpace(match[0][0])) {
|
|
191
185
|
return false;
|
|
192
186
|
}
|
|
193
|
-
items.push([match[1], match[2], match[3]]);
|
|
187
|
+
items.push([match[1], trimQuote(match[2]), trimQuote(match[3])]);
|
|
194
188
|
}
|
|
195
189
|
REGEXP_TEMPLATECOMPARISON.lastIndex = 0;
|
|
196
190
|
const length = items.length;
|
|
@@ -289,14 +283,17 @@ function hasSameOrigin(value, ...other) {
|
|
|
289
283
|
return false;
|
|
290
284
|
}
|
|
291
285
|
function restoreSearchParams(value, prefix = '__sqd') {
|
|
292
|
-
if (
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
+
}
|
|
297
293
|
}
|
|
294
|
+
return value;
|
|
298
295
|
}
|
|
299
|
-
return
|
|
296
|
+
return '';
|
|
300
297
|
}
|
|
301
298
|
function getBaseURLs(asset, baseUrl) {
|
|
302
299
|
const result = [];
|
|
@@ -326,27 +323,26 @@ function getBaseURLs(asset, baseUrl) {
|
|
|
326
323
|
}
|
|
327
324
|
function createHash(host, file, bufferMap) {
|
|
328
325
|
const hash = file.hash;
|
|
329
|
-
if (
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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;
|
|
341
339
|
}
|
|
342
|
-
host.rename(file, (0, util_1.appendSuffix)(filename, length ? value.substring(0, length) : value));
|
|
343
|
-
return file.filename;
|
|
344
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);
|
|
345
345
|
}
|
|
346
|
-
throw (0, types_1.errorMessage)('hash', 'Source not found', filename);
|
|
347
|
-
}
|
|
348
|
-
catch (err) {
|
|
349
|
-
host.writeFail(["Unable to read file", filename], err, 32);
|
|
350
346
|
}
|
|
351
347
|
}
|
|
352
348
|
function getSrcURL(parent, file) {
|
|
@@ -668,7 +664,7 @@ function transformOptions(file, mimeType, code, bundleContent) {
|
|
|
668
664
|
const metadata = { userAgentData: this.userAgentData };
|
|
669
665
|
switch (mimeType) {
|
|
670
666
|
case 'text/html':
|
|
671
|
-
metadata
|
|
667
|
+
metadata['__fromhtml__'] = true;
|
|
672
668
|
case 'text/css':
|
|
673
669
|
Object.assign(metadata, this.config);
|
|
674
670
|
default:
|
|
@@ -767,12 +763,11 @@ function replaceCss(file) {
|
|
|
767
763
|
map[id] = this.removeServerRoot(map[id]);
|
|
768
764
|
}
|
|
769
765
|
};
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
sanitize(inlineUrlMap);
|
|
766
|
+
if (file.inlineUrlMap) {
|
|
767
|
+
sanitize(file.inlineUrlMap);
|
|
773
768
|
}
|
|
774
|
-
if (inlineUrlCloudMap) {
|
|
775
|
-
sanitize(inlineUrlCloudMap);
|
|
769
|
+
if (file.inlineUrlCloudMap) {
|
|
770
|
+
sanitize(file.inlineUrlCloudMap);
|
|
776
771
|
}
|
|
777
772
|
}
|
|
778
773
|
function replaceHtml(source, { productionRelease, contentMap }, cssMap) {
|
|
@@ -848,10 +843,6 @@ async function checkData(item, name, result, validate) {
|
|
|
848
843
|
}
|
|
849
844
|
}
|
|
850
845
|
}
|
|
851
|
-
function getBuffer(item) {
|
|
852
|
-
let localUri;
|
|
853
|
-
return item.sourceUTF8 || item.buffer || ((localUri = item.localUri) && isPath(localUri) ? fs.readFileSync(localUri, item.encoding) : null);
|
|
854
|
-
}
|
|
855
846
|
const getNewlineString = dom_1.DomWriter.getNewlineString.bind(dom_1.DomWriter);
|
|
856
847
|
const isSpace = dom_1.DomWriter.isSpace.bind(dom_1.DomWriter);
|
|
857
848
|
const replaceMatch = dom_1.DomWriter.replaceMatch.bind(dom_1.DomWriter);
|
|
@@ -862,10 +853,11 @@ const asString = Document.asString.bind(Document);
|
|
|
862
853
|
const resolvePath = Document.resolvePath.bind(Document);
|
|
863
854
|
const toPosix = Document.toPosix.bind(Document);
|
|
864
855
|
const isDir = Document.isDir.bind(Document);
|
|
865
|
-
const hasSourceMap = (metadata, value) => (0, types_1.isObject)(metadata) && metadata
|
|
856
|
+
const hasSourceMap = (metadata, value) => (0, types_1.isObject)(metadata) && metadata['__sourcemap__'] === value;
|
|
866
857
|
const isBundled = (value, main) => typeof value === 'number' && (value > 0 || main && value === 0);
|
|
867
858
|
const isFont = (value) => value === 'truetype' || value === 'opentype' || value === 'woff' || value === 'woff2';
|
|
868
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);
|
|
869
861
|
const isRemoved = (item) => item.exclude === true || isBundled(item.bundleIndex);
|
|
870
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'));
|
|
871
863
|
const isIgnored = (item, exists) => item.invalid || (0, types_1.ignoreFlag)(item.flags) || !exists && (0, types_1.existsFlag)(item.flags);
|
|
@@ -1081,16 +1073,15 @@ class ChromeDocument extends Document {
|
|
|
1081
1073
|
const items = new Set((asset.watch.assets || []));
|
|
1082
1074
|
(function recurse(children) {
|
|
1083
1075
|
for (const item of children) {
|
|
1084
|
-
if (items.has(item)) {
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
item
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
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
|
+
}
|
|
1094
1085
|
}
|
|
1095
1086
|
}
|
|
1096
1087
|
})(includes);
|
|
@@ -1099,37 +1090,34 @@ class ChromeDocument extends Document {
|
|
|
1099
1090
|
}
|
|
1100
1091
|
}
|
|
1101
1092
|
let productionRelease = instance.productionRelease;
|
|
1102
|
-
if (
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
}
|
|
1121
|
-
else {
|
|
1122
|
-
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
|
+
}
|
|
1123
1111
|
}
|
|
1124
1112
|
}
|
|
1113
|
+
else {
|
|
1114
|
+
instance.writeFail(["Unable to write directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Access denied', productionRelease));
|
|
1115
|
+
}
|
|
1125
1116
|
}
|
|
1126
1117
|
else {
|
|
1127
|
-
instance.writeFail(["Unable to
|
|
1118
|
+
instance.writeFail(["Unable to read directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Invalid directory', productionRelease), 32);
|
|
1128
1119
|
}
|
|
1129
1120
|
}
|
|
1130
|
-
else {
|
|
1131
|
-
instance.writeFail(["Unable to read directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Invalid directory', productionRelease), 32);
|
|
1132
|
-
}
|
|
1133
1121
|
}
|
|
1134
1122
|
static sanitizeAssets(assets, exclusions = []) {
|
|
1135
1123
|
assets.forEach(item => {
|
|
@@ -1210,7 +1198,6 @@ class ChromeDocument extends Document {
|
|
|
1210
1198
|
}
|
|
1211
1199
|
return 0;
|
|
1212
1200
|
});
|
|
1213
|
-
let imports;
|
|
1214
1201
|
if (config) {
|
|
1215
1202
|
const { useUnsafeReplace, baseUrl, productionRelease, productionIncremental, templateMap, userAgentData, cache } = config;
|
|
1216
1203
|
const target = this.config;
|
|
@@ -1257,37 +1244,25 @@ class ChromeDocument extends Document {
|
|
|
1257
1244
|
if ((0, types_1.isObject)(userAgentData)) {
|
|
1258
1245
|
this.userAgentData = userAgentData;
|
|
1259
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
|
+
}
|
|
1260
1251
|
if ((0, types_1.isObject)(cache) && 'transform' in cache) {
|
|
1261
1252
|
this.customize({ transform: cache.transform });
|
|
1262
1253
|
}
|
|
1263
|
-
if (!(0, types_1.isPlainObject)(imports = config.imports)) {
|
|
1264
|
-
imports = undefined;
|
|
1265
|
-
}
|
|
1266
1254
|
}
|
|
1267
1255
|
super.init(assets, config);
|
|
1268
1256
|
const mimeMap = this._mimeMap;
|
|
1269
|
-
if (mimeMap) {
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
imports = imports ? Object.assign(imported, imports) : imported;
|
|
1274
|
-
}
|
|
1275
|
-
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;
|
|
1276
1261
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
if ((0, types_1.isObject)(format)) {
|
|
1280
|
-
this.formatMap = 'pathname' in format || 'filename' in format || 'dictionary' in format ? { uuid: format } : format;
|
|
1281
|
-
}
|
|
1282
|
-
else {
|
|
1283
|
-
this.formatMap = undefined;
|
|
1284
|
-
}
|
|
1285
|
-
delete mimeMap.format;
|
|
1262
|
+
else {
|
|
1263
|
+
this.formatMap = undefined;
|
|
1286
1264
|
}
|
|
1287
1265
|
}
|
|
1288
|
-
if (imports) {
|
|
1289
|
-
this.imports = imports;
|
|
1290
|
-
}
|
|
1291
1266
|
for (const storage of cloud) {
|
|
1292
1267
|
for (const { service, upload, download } of storage) {
|
|
1293
1268
|
if (upload) {
|
|
@@ -1715,9 +1690,8 @@ class ChromeDocument extends Document {
|
|
|
1715
1690
|
this._cloudUrlMap = Object.create(null);
|
|
1716
1691
|
this._cloudUploaded = new Set();
|
|
1717
1692
|
this._cloudEndpoint = null;
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
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;
|
|
1721
1695
|
if (endpoint) {
|
|
1722
1696
|
this._cloudEndpoint = new RegExp((0, types_1.escapePattern)(toPosix(endpoint)) + '/', 'g');
|
|
1723
1697
|
}
|
|
@@ -1898,7 +1872,9 @@ class ChromeDocument extends Document {
|
|
|
1898
1872
|
}
|
|
1899
1873
|
}
|
|
1900
1874
|
search !== null && search !== void 0 ? search : (search = restoreSearchParams((_a = asset.url) === null || _a === void 0 ? void 0 : _a.search));
|
|
1901
|
-
|
|
1875
|
+
if (status) {
|
|
1876
|
+
status = status.filter(item => item.type >= types_1.STATUS_TYPE.FATAL && item.type <= types_1.STATUS_TYPE.WARN);
|
|
1877
|
+
}
|
|
1902
1878
|
watch.send(types_1.WATCH_EVENT.MODIFIED, {
|
|
1903
1879
|
action: pathname && watch.hot && !watch.main ? 'hot' : '',
|
|
1904
1880
|
type: asset.mimeType,
|
|
@@ -2075,9 +2051,8 @@ class ChromeDocument extends Document {
|
|
|
2075
2051
|
item.modified = true;
|
|
2076
2052
|
}
|
|
2077
2053
|
source = sanitizeSource(item, source);
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
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'));
|
|
2081
2056
|
if (result) {
|
|
2082
2057
|
item.modified = true;
|
|
2083
2058
|
source = result.code;
|
|
@@ -2187,12 +2162,11 @@ class ChromeDocument extends Document {
|
|
|
2187
2162
|
await this.setElementAttributes(processing, domBase);
|
|
2188
2163
|
await this.applyDataSource(processing, domBase);
|
|
2189
2164
|
for (const item of this.assets) {
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
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);
|
|
2193
2167
|
domElement.remove = true;
|
|
2194
2168
|
if (!domBase.write(domElement)) {
|
|
2195
|
-
this.writeFail('Unable to exclude HTML element', errorHtml(element), 4);
|
|
2169
|
+
this.writeFail('Unable to exclude HTML element', errorHtml(item.element), 4);
|
|
2196
2170
|
}
|
|
2197
2171
|
}
|
|
2198
2172
|
}
|
|
@@ -2213,15 +2187,13 @@ class ChromeDocument extends Document {
|
|
|
2213
2187
|
if ((0, types_1.isString)(config.stripCommentsAndCDATA)) {
|
|
2214
2188
|
source = dom_1.DomWriter.getCommentsAndCDATA(source, config.stripCommentsAndCDATA, true, true);
|
|
2215
2189
|
}
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
const { filename, uri, encoding, metadata } = htmlFile;
|
|
2219
|
-
const result = await this.transform('html', source, format, {
|
|
2190
|
+
if (htmlFile.format) {
|
|
2191
|
+
const result = await this.transform('html', source, htmlFile.format, {
|
|
2220
2192
|
pathname: path.dirname(localUri),
|
|
2221
|
-
filename,
|
|
2193
|
+
filename: htmlFile.filename,
|
|
2222
2194
|
mimeType: 'text/html',
|
|
2223
|
-
metadata: Object.assign({ '__fromhtml__': true, ...this.config }, metadata),
|
|
2224
|
-
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
|
|
2225
2197
|
});
|
|
2226
2198
|
if (result) {
|
|
2227
2199
|
source = result.code;
|
|
@@ -2255,12 +2227,12 @@ class ChromeDocument extends Document {
|
|
|
2255
2227
|
const cloud = host.Cloud;
|
|
2256
2228
|
const removeWatchReload = (item) => (0, types_1.isObject)(item.watch) && delete item.watch.reload;
|
|
2257
2229
|
for (const item of this.assets) {
|
|
2258
|
-
const
|
|
2230
|
+
const element = item.element;
|
|
2259
2231
|
if (!element || element.removed || isRemoved(item) || isUnedited(item) || (0, types_1.ignoreFlag)(item.flags) && !(0, types_1.processFlag)(item.flags)) {
|
|
2260
2232
|
continue;
|
|
2261
2233
|
}
|
|
2262
2234
|
const domElement = new dom_1.HtmlElement(moduleName, element, item.attributes);
|
|
2263
|
-
if (inlineContent) {
|
|
2235
|
+
if (item.inlineContent) {
|
|
2264
2236
|
let [innerXml, sourceMappingURL, inlineMap] = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(item).trim());
|
|
2265
2237
|
if (sourceMappingURL && !inlineMap && item.localUri) {
|
|
2266
2238
|
let mapUri = path.resolve(sourceMappingURL = decodeURIComponent(sourceMappingURL));
|
|
@@ -2269,7 +2241,7 @@ class ChromeDocument extends Document {
|
|
|
2269
2241
|
}
|
|
2270
2242
|
host.deleteFile(mapUri);
|
|
2271
2243
|
}
|
|
2272
|
-
domElement.tagName = inlineContent;
|
|
2244
|
+
domElement.tagName = item.inlineContent;
|
|
2273
2245
|
domElement.innerXml = innerXml;
|
|
2274
2246
|
domElement.removeAttribute('src', 'href');
|
|
2275
2247
|
}
|
|
@@ -2359,10 +2331,10 @@ class ChromeDocument extends Document {
|
|
|
2359
2331
|
}
|
|
2360
2332
|
}
|
|
2361
2333
|
if (!domBase.write(domElement)) {
|
|
2362
|
-
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 });
|
|
2363
2335
|
delete item.inlineUrlCloud;
|
|
2364
2336
|
}
|
|
2365
|
-
else if (inlineContent) {
|
|
2337
|
+
else if (item.inlineContent) {
|
|
2366
2338
|
host.removeAsset(item);
|
|
2367
2339
|
removeWatchReload(item);
|
|
2368
2340
|
}
|
|
@@ -2959,7 +2931,7 @@ class ChromeDocument extends Document {
|
|
|
2959
2931
|
for (let j = 0, match; j < items.length; ++j) {
|
|
2960
2932
|
const row = items[j];
|
|
2961
2933
|
if ((0, types_1.isPlainObject)(row)) {
|
|
2962
|
-
(_c = row
|
|
2934
|
+
(_c = row['__index__']) !== null && _c !== void 0 ? _c : (row['__index__'] = j + 1);
|
|
2963
2935
|
}
|
|
2964
2936
|
let segment = template;
|
|
2965
2937
|
while (match = REGEXP_TEMPLATECONDITIONAL.exec(segment)) {
|
|
@@ -3109,7 +3081,8 @@ class ChromeDocument extends Document {
|
|
|
3109
3081
|
const row = items[0];
|
|
3110
3082
|
let condition = NaN;
|
|
3111
3083
|
for (let seg of template) {
|
|
3112
|
-
|
|
3084
|
+
seg = seg.trim();
|
|
3085
|
+
switch (seg.toLowerCase()) {
|
|
3113
3086
|
case ':is(and)':
|
|
3114
3087
|
if (condition === 0) {
|
|
3115
3088
|
remove = false;
|
|
@@ -3302,7 +3275,7 @@ class ChromeDocument extends Document {
|
|
|
3302
3275
|
const parseSelector = (value) => {
|
|
3303
3276
|
const items = [];
|
|
3304
3277
|
const revised = value.replace(useUnsafeCssReplace ? REGEXP_NTHCHILD_UNSAFE : REGEXP_NTHCHILD, (...capture) => {
|
|
3305
|
-
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) + '`';
|
|
3306
3279
|
});
|
|
3307
3280
|
let selector = '';
|
|
3308
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
|
-
"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.
|
|
24
|
-
"@e-mc/core": "^0.6.
|
|
25
|
-
"@e-mc/document": "^0.6.
|
|
26
|
-
"@e-mc/types": "^0.6.
|
|
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
|
|
108
|
-
|
|
109
|
-
get dataSource(): DataSource[];
|
|
110
|
-
get elements(): XmlTagNode[];
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
}
|
package/types/squared.d.ts
CHANGED
|
@@ -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
|
}
|