@e-mc/document 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +4 -4
- package/package.json +4 -4
- package/parse/dom.d.ts +1 -1
- package/parse/index.d.ts +1 -1
- package/parse/{document.d.ts → types/index.d.ts} +7 -3
- package/transform/index.js +16 -5
- package/util.d.ts +1 -1
- package/util.js +22 -13
- package/android/document.d.ts +0 -66
- package/android/extensions/app/manifest/index.js +0 -186
- package/android/extensions/gradle/dependencies/index.js +0 -212
- package/android/extensions/gradle/settings/index.js +0 -82
- package/android/extensions/task/index.js +0 -110
- package/android/index.d.ts +0 -7
- package/android/index.js +0 -217
- package/android/template/AndroidManifest.xml +0 -23
- package/android/template/java/build.gradle +0 -39
- package/android/template/java/settings.gradle +0 -18
- package/android/template/java+kotlin/build.gradle +0 -44
- package/android/template/java+kotlin/settings.gradle +0 -18
- package/android/template/kotlin/build.gradle.kts +0 -46
- package/android/template/kotlin/settings.gradle.kts +0 -18
- package/chrome/document.d.ts +0 -119
- package/chrome/index.d.ts +0 -7
- package/chrome/index.js +0 -3545
package/chrome/index.js
DELETED
|
@@ -1,3545 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const asset_1 = require("../asset");
|
|
6
|
-
const util_1 = require("../util");
|
|
7
|
-
const types_1 = require("../../types");
|
|
8
|
-
const core_1 = require("../../core");
|
|
9
|
-
const index_1 = require("../index");
|
|
10
|
-
const cloud_1 = require("../../cloud");
|
|
11
|
-
const dom_1 = require("../parse/dom");
|
|
12
|
-
const transform_1 = require("../transform");
|
|
13
|
-
const CACHE_DBRESULT = new Map();
|
|
14
|
-
const CACHE_LOCALFILE = new Map();
|
|
15
|
-
const CACHE_DATASET = {};
|
|
16
|
-
const CACHE_ATRULES = {};
|
|
17
|
-
let CACHE_TOTAL = 0;
|
|
18
|
-
const REGEXP_SRCSETSIZE = /~\s*([\d.]+)\s*([wx])/i;
|
|
19
|
-
const REGEXP_TEMPLATECONDITIONAL = /(\n\s+)?\{\{if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)([\S\s]*?)(?:\s*\{\{else(?:\s+if\s+((?:[^}]|}(?!}))+?))?\}\}(\s*)([\S\s]*?)\s*)?\s*\{\{end\}\}/g;
|
|
20
|
-
const REGEXP_TEMPLATECOMPARISON = /\s*\(\s*(?:(eq|ne|lt|le|gt|ge)\s+)?("[^"]+"|'[^']+'|[^\s)]+)(?:\s+("[^"]+"|'[^']+'|[^\s)]+))?\s*\)/g;
|
|
21
|
-
const REGEXP_TEMPLATEMATCH = new RegExp(`^(?:(and|or|not)\\s+)?((?:${REGEXP_TEMPLATECOMPARISON.source})+)|(!|not\\s+)?([^\\s][\\S\\s]*)$`);
|
|
22
|
-
const REGEXP_IMPORTMODULE = /(?:(?:^|[\n;]+)\s*import\s+(?:("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')|.+?from\s+("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')(?:[ \t]+assert[ \t]+\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]+{|{[^}]+}|}[^}]+}|(?![{}])[^"'`])+)\})?)|\bimport\(\s*("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')\s*(?:,\s*\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]+{|{[^}]+}|}[^}]+}|(?![{}])[^"'`])+)\}\s*)?\))/g;
|
|
23
|
-
const REGEXP_BLOCKEXCLUDE = new RegExp(`(\\s*)<!--\\s*exclude\\s*:\\s*(?:start|end)\\s*-->` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
|
|
24
|
-
const [PATTERN_STRING_SOME, PATTERN_STRING_MANY] = (function () {
|
|
25
|
-
const pattern = '(?:\\s|' + dom_1.DomWriter.PATTERN_COMMENT + '|`[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}`)';
|
|
26
|
-
return [pattern + '*', pattern + '+'];
|
|
27
|
-
})();
|
|
28
|
-
const REGEXP_COMMENT = new RegExp(dom_1.DomWriter.PATTERN_COMMENT, 'g');
|
|
29
|
-
const REGEXP_CONTENT = new RegExp(`\\bcontent${PATTERN_STRING_SOME}:${PATTERN_STRING_SOME}(?:"[^"]*"|'[^']*')`, 'gi');
|
|
30
|
-
const REGEXP_STYLE = new RegExp(`(<style${dom_1.DomWriter.PATTERN_TAGOPEN}*>)([\\S\\s]*?)(<\\/style\\s*>)`, 'gi');
|
|
31
|
-
const REGEXP_VARIABLES = new RegExp(`(\\s*)(--[^\\s:]*)${PATTERN_STRING_SOME}:[^;}]*([;}])` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'g');
|
|
32
|
-
const REGEXP_FONTFACE = new RegExp(`(\\s*)@font-face${PATTERN_STRING_SOME}{([^}]+)}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
|
|
33
|
-
const REGEXP_FONTFAMILY = new RegExp(`font-family${PATTERN_STRING_SOME}:([^;}]+)`, 'i');
|
|
34
|
-
const REGEXP_KEYFRAMES = new RegExp(`(\\s*)@keyframes${PATTERN_STRING_MANY}([^{]+){`, 'gi');
|
|
35
|
-
const REGEXP_NTHCHILD = new RegExp(`\\(${PATTERN_STRING_SOME}([+-])?(?:(\\d*)[nN]|(0))${PATTERN_STRING_SOME}([+-])?${PATTERN_STRING_SOME}(\\d*)${PATTERN_STRING_SOME}\\)`, 'g');
|
|
36
|
-
const REGEXP_VARIABLES_UNSAFE = new RegExp(`(\\s*)(--[^\\s:]*)\\s*:[^;}]*([;}])` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'g');
|
|
37
|
-
const REGEXP_FONTFACE_UNSAFE = new RegExp(`(\\s*)@font-face\\s*{([^}]+)}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
|
|
38
|
-
const REGEXP_FONTFAMILY_UNSAFE = /font-family\s*:([^;}]+)/i;
|
|
39
|
-
const REGEXP_KEYFRAMES_UNSAFE = /(\s*)@keyframes\s+([^{]+){/gi;
|
|
40
|
-
const REGEXP_NTHCHILD_UNSAFE = /\(\s*([+-])?(?:(\d*)[nN]|(0))\s*([+-])?\s*(\d*)\s*\)/g;
|
|
41
|
-
function removeNamespace(name, source, newline, comments) {
|
|
42
|
-
if (source.indexOf('-' + name) !== -1) {
|
|
43
|
-
const dataset = CACHE_DATASET[name] || (CACHE_DATASET[name] = [
|
|
44
|
-
new RegExp(`(\\s*)<(script|style)(${dom_1.DomWriter.PATTERN_TAGOPEN}+)>[\\S\\s]*?<\\/\\2\\s*>` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi'),
|
|
45
|
-
new RegExp(`(\\s*)<link(${dom_1.DomWriter.PATTERN_TAGOPEN}+)>` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi'),
|
|
46
|
-
new RegExp(`\\s+data-${name}-[a-z-]+\\s*` + dom_1.DomWriter.PATTERN_ATTRVALUE, 'g'),
|
|
47
|
-
new RegExp(`data-${name}-file\\s*=\\s*(["'])?exclude\\1`),
|
|
48
|
-
new RegExp(`data-${name}-template\\s*` + dom_1.DomWriter.PATTERN_ATTRVALUE)
|
|
49
|
-
]);
|
|
50
|
-
source = source
|
|
51
|
-
.replace(dataset[0], (...capture) => dataset[3].test(capture[3]) || dataset[4].test(capture[3]) ? getNewlineString(capture[1], capture[7], newline) : capture[0])
|
|
52
|
-
.replace(dataset[1], (...capture) => dataset[3].test(capture[2]) ? getNewlineString(capture[1], capture[6], newline) : capture[0])
|
|
53
|
-
.replace(dataset[2], '');
|
|
54
|
-
}
|
|
55
|
-
return (0, types_1.isArray)(comments) ? source.replace(REGEXP_BLOCKEXCLUDE, (...capture) => getNewlineString(capture[1], capture[2], newline)) : source;
|
|
56
|
-
}
|
|
57
|
-
function getObjectValue(value, key) {
|
|
58
|
-
const pattern = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
|
|
59
|
-
let found, match;
|
|
60
|
-
while (match = pattern.exec(key)) {
|
|
61
|
-
if ((0, types_1.isObject)(value)) {
|
|
62
|
-
value = value[match[1]];
|
|
63
|
-
if (match[2]) {
|
|
64
|
-
const subscript = /\[\s*(["'])?(.+?)\1\s*\]/g;
|
|
65
|
-
let index;
|
|
66
|
-
while (index = subscript.exec(match[2])) {
|
|
67
|
-
const attr = index[1] ? index[2] : index[2].trim();
|
|
68
|
-
if (index[1] && (0, types_1.isObject)(value) || /^\d+$/.test(attr) && (typeof value === 'string' || (0, types_1.isObject)(value))) {
|
|
69
|
-
value = value[attr];
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (value !== undefined && value !== null) {
|
|
77
|
-
found = true;
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
return found ? value : null;
|
|
84
|
-
}
|
|
85
|
-
function trimTemplate(value) {
|
|
86
|
-
const leading = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
|
|
87
|
-
let match;
|
|
88
|
-
while (match = leading.exec(value)) {
|
|
89
|
-
value = replaceMatch(match, value, 1, leading);
|
|
90
|
-
}
|
|
91
|
-
const trailing = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
|
|
92
|
-
while (match = trailing.exec(value)) {
|
|
93
|
-
value = replaceMatch(match, value, 1, trailing);
|
|
94
|
-
}
|
|
95
|
-
return value;
|
|
96
|
-
}
|
|
97
|
-
function trimQuote(value) {
|
|
98
|
-
value = value.trim();
|
|
99
|
-
const first = value[0];
|
|
100
|
-
const last = value[value.length - 1];
|
|
101
|
-
return first === last && (first === '"' || first === "'") ? value.substring(1, value.length - 1).trim() : value;
|
|
102
|
-
}
|
|
103
|
-
function findClosingIndex(source, lastIndex) {
|
|
104
|
-
const pattern = /[{}]/g;
|
|
105
|
-
pattern.lastIndex = lastIndex;
|
|
106
|
-
let opened = 1, closed = 0, endIndex = -1, trailing = '', match;
|
|
107
|
-
while (match = pattern.exec(source)) {
|
|
108
|
-
if (match[0] === '{') {
|
|
109
|
-
++opened;
|
|
110
|
-
}
|
|
111
|
-
else if (++closed === opened) {
|
|
112
|
-
endIndex = match.index + 1;
|
|
113
|
-
let ch;
|
|
114
|
-
while (isSpace(ch = source[endIndex])) {
|
|
115
|
-
trailing += ch;
|
|
116
|
-
++endIndex;
|
|
117
|
-
if (ch === '\n') {
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return [endIndex, trailing];
|
|
125
|
-
}
|
|
126
|
-
function getPackageName(err, value) {
|
|
127
|
-
if (err instanceof Error && err.code === types_1.ERR_CODE.MODULE_NOT_FOUND) {
|
|
128
|
-
switch (value) {
|
|
129
|
-
case 'mongodb':
|
|
130
|
-
case 'redis':
|
|
131
|
-
return value;
|
|
132
|
-
case 'mysql':
|
|
133
|
-
return 'mysql2';
|
|
134
|
-
case 'postgres':
|
|
135
|
-
return 'pg';
|
|
136
|
-
case 'oracle':
|
|
137
|
-
return 'oracledb';
|
|
138
|
-
case 'mssql':
|
|
139
|
-
return 'tedious';
|
|
140
|
-
default:
|
|
141
|
-
return (0, util_1.getModuleName)(err);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
function getCacheItem(map, key) {
|
|
146
|
-
const result = map.get(key);
|
|
147
|
-
if (result) {
|
|
148
|
-
result[0] = Date.now();
|
|
149
|
-
return result[1];
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
function addCacheItem(map, key, data, timeout) {
|
|
153
|
-
if (!map.has(key)) {
|
|
154
|
-
++CACHE_TOTAL;
|
|
155
|
-
}
|
|
156
|
-
map.set(key, [
|
|
157
|
-
Date.now(),
|
|
158
|
-
data,
|
|
159
|
-
setTimeout(() => deleteCacheItem(map, key), timeout * 1000 /* TIME.S */)
|
|
160
|
-
]);
|
|
161
|
-
}
|
|
162
|
-
function deleteCacheItem(map, key) {
|
|
163
|
-
const item = map.get(key);
|
|
164
|
-
if (item) {
|
|
165
|
-
clearTimeout(item[2]);
|
|
166
|
-
map.delete(key);
|
|
167
|
-
--CACHE_TOTAL;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function spliceSource(source, startIndex, endIndex, pattern, leading = '', trailing = '', content = '') {
|
|
171
|
-
if (leading || trailing) {
|
|
172
|
-
content += getNewlineString(leading, trailing);
|
|
173
|
-
}
|
|
174
|
-
if (pattern && content) {
|
|
175
|
-
pattern.lastIndex = startIndex + content.length;
|
|
176
|
-
}
|
|
177
|
-
return spliceString(source, startIndex, endIndex, content);
|
|
178
|
-
}
|
|
179
|
-
function hasCondition(data, condition) {
|
|
180
|
-
if (!condition) {
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
let match = REGEXP_TEMPLATEMATCH.exec(condition.trim());
|
|
184
|
-
if (match) {
|
|
185
|
-
if (match[2]) {
|
|
186
|
-
const join = match[1];
|
|
187
|
-
const comparison = match[2];
|
|
188
|
-
const items = [];
|
|
189
|
-
while (match = REGEXP_TEMPLATECOMPARISON.exec(comparison)) {
|
|
190
|
-
if (items.length && !isSpace(match[0][0])) {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
items.push([match[1], match[2], match[3]]);
|
|
194
|
-
}
|
|
195
|
-
REGEXP_TEMPLATECOMPARISON.lastIndex = 0;
|
|
196
|
-
const length = items.length;
|
|
197
|
-
if (length > 1 && !join) {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
const parseArg = (value) => {
|
|
201
|
-
if (!isNaN(+value)) {
|
|
202
|
-
return +value;
|
|
203
|
-
}
|
|
204
|
-
if (match = /^(["'])([\S\s]*)\1$/.exec(value)) {
|
|
205
|
-
return match[2];
|
|
206
|
-
}
|
|
207
|
-
return getObjectValue(data, value);
|
|
208
|
-
};
|
|
209
|
-
for (let i = 0; i < length; ++i) {
|
|
210
|
-
const item = items[i];
|
|
211
|
-
const arg1 = item[1];
|
|
212
|
-
const arg2 = item[2];
|
|
213
|
-
let valid;
|
|
214
|
-
if (arg2) {
|
|
215
|
-
switch (item[0]) {
|
|
216
|
-
case 'eq':
|
|
217
|
-
valid = parseArg(arg1) == parseArg(arg2); // eslint-disable-line eqeqeq
|
|
218
|
-
break;
|
|
219
|
-
case 'ne':
|
|
220
|
-
valid = parseArg(arg1) != parseArg(arg2); // eslint-disable-line eqeqeq
|
|
221
|
-
break;
|
|
222
|
-
case 'lt':
|
|
223
|
-
valid = parseArg(arg1) < parseArg(arg2);
|
|
224
|
-
break;
|
|
225
|
-
case 'le':
|
|
226
|
-
valid = parseArg(arg1) <= parseArg(arg2);
|
|
227
|
-
break;
|
|
228
|
-
case 'gt':
|
|
229
|
-
valid = parseArg(arg1) > parseArg(arg2);
|
|
230
|
-
break;
|
|
231
|
-
case 'ge':
|
|
232
|
-
valid = parseArg(arg1) >= parseArg(arg2);
|
|
233
|
-
break;
|
|
234
|
-
default:
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
else if (item[0]) {
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
valid = isTruthy(data, arg1, false);
|
|
243
|
-
}
|
|
244
|
-
if (join === 'or') {
|
|
245
|
-
if (valid) {
|
|
246
|
-
return true;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
if (join === 'not') {
|
|
251
|
-
valid = !valid;
|
|
252
|
-
}
|
|
253
|
-
if (!valid) {
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return join === 'or' ? false : true;
|
|
259
|
-
}
|
|
260
|
-
if (match[7]) {
|
|
261
|
-
return isTruthy(data, match[7].trim(), match[6]);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
266
|
-
function isTruthy(data, attr, falsey) {
|
|
267
|
-
const value = getObjectValue(data, attr);
|
|
268
|
-
return falsey ? !value : !!value;
|
|
269
|
-
}
|
|
270
|
-
function hasSameOrigin(value, ...other) {
|
|
271
|
-
for (let url of other) {
|
|
272
|
-
if (!url) {
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
try {
|
|
276
|
-
if (typeof value === 'string') {
|
|
277
|
-
value = new URL(value);
|
|
278
|
-
}
|
|
279
|
-
if (typeof url === 'string') {
|
|
280
|
-
url = new URL(url);
|
|
281
|
-
}
|
|
282
|
-
if (value.origin === url.origin) {
|
|
283
|
-
return true;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
catch {
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return false;
|
|
290
|
-
}
|
|
291
|
-
function restoreSearchParams(value, prefix = '__sqd') {
|
|
292
|
-
if (value) {
|
|
293
|
-
if (value.indexOf(prefix) !== -1) {
|
|
294
|
-
const params = new URLSearchParams(value);
|
|
295
|
-
params.forEach((_, key) => key.startsWith(prefix) && params.delete(key));
|
|
296
|
-
if (value = params.toString()) {
|
|
297
|
-
return '?' + value;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
return value;
|
|
301
|
-
}
|
|
302
|
-
return '';
|
|
303
|
-
}
|
|
304
|
-
function getBaseURLs(asset, baseUrl) {
|
|
305
|
-
const result = [];
|
|
306
|
-
let parentUrl = asset ? asset.url || asset.uri : undefined;
|
|
307
|
-
try {
|
|
308
|
-
if (parentUrl) {
|
|
309
|
-
if (typeof parentUrl === 'string') {
|
|
310
|
-
parentUrl = new URL(parentUrl);
|
|
311
|
-
asset.url = parentUrl;
|
|
312
|
-
}
|
|
313
|
-
result.push(parentUrl);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
catch {
|
|
317
|
-
parentUrl = undefined;
|
|
318
|
-
}
|
|
319
|
-
if (baseUrl) {
|
|
320
|
-
const url = new URL(baseUrl);
|
|
321
|
-
if (!parentUrl) {
|
|
322
|
-
result.push(parentUrl = url);
|
|
323
|
-
}
|
|
324
|
-
else if (parentUrl.origin !== url.origin) {
|
|
325
|
-
result.push(new URL(parentUrl.href.replace(parentUrl.origin, url.origin)), url);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
return result;
|
|
329
|
-
}
|
|
330
|
-
function createHash(host, file, bufferMap) {
|
|
331
|
-
const hash = file.hash;
|
|
332
|
-
if (hash) {
|
|
333
|
-
try {
|
|
334
|
-
const localUri = file.localUri;
|
|
335
|
-
const buffer = localUri && bufferMap[localUri] || getBuffer(file);
|
|
336
|
-
if (buffer) {
|
|
337
|
-
const [algorithm, length] = (0, util_1.getHashData)(hash);
|
|
338
|
-
let value;
|
|
339
|
-
if (algorithm && (value = index_1.default.asHash(buffer, { algorithm, encoding: file.encoding }))) {
|
|
340
|
-
if (localUri) {
|
|
341
|
-
bufferMap[localUri] = buffer;
|
|
342
|
-
}
|
|
343
|
-
host.rename(file, (0, util_1.appendSuffix)(file.filename, length ? value.substring(0, length) : value));
|
|
344
|
-
return file.filename;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
throw (0, types_1.errorMessage)('hash', 'Source not found', file.filename);
|
|
348
|
-
}
|
|
349
|
-
catch (err) {
|
|
350
|
-
host.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, file.filename], err, 32 /* LOG_TYPE.FILE */);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
function getSrcURL(parent, file) {
|
|
355
|
-
const relativeUrl = file.relativeUrl || this.host.removeCwd(file.localUri) && getRelativeURL(file);
|
|
356
|
-
if (!relativeUrl) {
|
|
357
|
-
return [''];
|
|
358
|
-
}
|
|
359
|
-
if (parent.inlineContent) {
|
|
360
|
-
return [relativeUrl];
|
|
361
|
-
}
|
|
362
|
-
let parentDir = parent.pathname, assetDir = file.pathname;
|
|
363
|
-
if (!this.productionRelease) {
|
|
364
|
-
if (parent.moveTo) {
|
|
365
|
-
parentDir = joinPath(parent.moveTo, parentDir);
|
|
366
|
-
}
|
|
367
|
-
if (file.moveTo) {
|
|
368
|
-
assetDir = joinPath(file.moveTo, assetDir);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
if (parentDir === assetDir) {
|
|
372
|
-
return [file.filename, true];
|
|
373
|
-
}
|
|
374
|
-
const splitPath = (value) => value.split(/[\\/]/).filter(segment => segment.trim());
|
|
375
|
-
const prefix = splitPath(parentDir);
|
|
376
|
-
const suffix = splitPath(assetDir);
|
|
377
|
-
let found;
|
|
378
|
-
while (prefix.length && suffix.length && prefix[0] === suffix[0]) {
|
|
379
|
-
prefix.shift();
|
|
380
|
-
suffix.shift();
|
|
381
|
-
found = true;
|
|
382
|
-
}
|
|
383
|
-
return [found ? joinPath('../'.repeat(prefix.length), suffix.join('/'), file.filename) : '../'.repeat(prefix.length) + relativeUrl];
|
|
384
|
-
}
|
|
385
|
-
function transformURL(host, parent, type, source, importFile) {
|
|
386
|
-
const related = [];
|
|
387
|
-
const baseHref = getBaseURLs(importFile || parent, this.baseUrl);
|
|
388
|
-
const isHtml = type === 'html';
|
|
389
|
-
const isJs = type === 'js';
|
|
390
|
-
const pattern = isJs ? /\bimport\(/g : type === 'svg' ? /(?:\b[Uu][Rr][Ll]\(|@import\s+(["'])|\b([Hh][Rr][Ee][Ff])\s*=)/g : /\b[Uu][Rr][Ll]\(|@import\s+(["'])/g;
|
|
391
|
-
let length = source.length, modified, match;
|
|
392
|
-
while (match = pattern.exec(source)) {
|
|
393
|
-
const isText = !!match[1];
|
|
394
|
-
const isHref = !!match[2];
|
|
395
|
-
const isUrl = !isText && !isHref;
|
|
396
|
-
const startIndex = match.index;
|
|
397
|
-
let quote = match[1], content = '', trailing = '', closed = -1, i = startIndex + match[0].length;
|
|
398
|
-
for (let j = -1; i < length; ++i) {
|
|
399
|
-
const ch = source[i];
|
|
400
|
-
if (quote && ch === quote) {
|
|
401
|
-
if (!isText) {
|
|
402
|
-
content += ch;
|
|
403
|
-
}
|
|
404
|
-
if (isHref) {
|
|
405
|
-
break;
|
|
406
|
-
}
|
|
407
|
-
if (source[i - 1] !== '\\') {
|
|
408
|
-
if (isText) {
|
|
409
|
-
break;
|
|
410
|
-
}
|
|
411
|
-
if (closed === -1) {
|
|
412
|
-
closed = i + 1;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
j = i + 1;
|
|
416
|
-
continue;
|
|
417
|
-
}
|
|
418
|
-
if (!quote && (ch === '"' || ch === "'" || ch === '`' && isJs) && (isHref || !content.trim())) {
|
|
419
|
-
quote = ch;
|
|
420
|
-
}
|
|
421
|
-
else if (isHref && !quote && isSpace(ch) && content.trim()) {
|
|
422
|
-
break;
|
|
423
|
-
}
|
|
424
|
-
else if (ch === ')') {
|
|
425
|
-
if (isUrl) {
|
|
426
|
-
if (quote && closed !== -1 || !quote && (isJs || source[i - 1] !== '\\')) {
|
|
427
|
-
break;
|
|
428
|
-
}
|
|
429
|
-
j = i;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
else if (j !== -1 && (ch === '\n' ||
|
|
433
|
-
isText && (ch === ';' || ch === '{') ||
|
|
434
|
-
isHref && (ch === '=' || ch === '>') ||
|
|
435
|
-
isUrl && (ch === ';' ||
|
|
436
|
-
!isJs && (!isHtml && (ch === ':' && !isJs || ch === '}') ||
|
|
437
|
-
isHtml && (ch === '"' || ch === "'" || ch === ':' || ch === '>'))))) {
|
|
438
|
-
if (closed !== -1) {
|
|
439
|
-
i = closed;
|
|
440
|
-
}
|
|
441
|
-
else {
|
|
442
|
-
content = content.substring(0, i = j);
|
|
443
|
-
}
|
|
444
|
-
break;
|
|
445
|
-
}
|
|
446
|
-
if (closed === -1) {
|
|
447
|
-
content += ch;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
const setOutputURL = (value, asset) => {
|
|
451
|
-
if (!value) {
|
|
452
|
-
return;
|
|
453
|
-
}
|
|
454
|
-
if (asset) {
|
|
455
|
-
if (!asset.inlineBase64) {
|
|
456
|
-
if (host.Cloud?.getStorage('upload', asset.cloudStorage)) {
|
|
457
|
-
const inlineUrlCloud = asset.inlineUrlCloud || (asset.inlineUrlCloud = (0, types_1.generateUUID)());
|
|
458
|
-
(parent.inlineUrlCloudMap || (parent.inlineUrlCloudMap = {}))[inlineUrlCloud] = value;
|
|
459
|
-
value = inlineUrlCloud;
|
|
460
|
-
}
|
|
461
|
-
else if (asset.hash && this.productionRelease) {
|
|
462
|
-
const inlineUrl = asset.inlineUrl || (asset.inlineUrl = (0, types_1.generateUUID)());
|
|
463
|
-
(parent.inlineUrlMap || (parent.inlineUrlMap = {}))[inlineUrl] = value;
|
|
464
|
-
value = inlineUrl;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
const font = findFont(asset.format);
|
|
468
|
-
if (font) {
|
|
469
|
-
found: {
|
|
470
|
-
for (let k = i + 1; k < length; ++k) {
|
|
471
|
-
switch (source[k]) {
|
|
472
|
-
case ')': {
|
|
473
|
-
const component = source.substring(i + 1, k + 1);
|
|
474
|
-
const format = /\s+format\([^)]+\)$/i.exec(component);
|
|
475
|
-
if (format) {
|
|
476
|
-
trailing = component.replace(format[0], ` format("${font}")`);
|
|
477
|
-
i = k;
|
|
478
|
-
break found;
|
|
479
|
-
}
|
|
480
|
-
break;
|
|
481
|
-
}
|
|
482
|
-
case ',':
|
|
483
|
-
case ';':
|
|
484
|
-
case ':':
|
|
485
|
-
case '}':
|
|
486
|
-
break found;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
if (asset.initialValue && !asset.initialValue.cacheable) {
|
|
492
|
-
parent.flags |= 16 /* ASSET_FLAG.MODIFIED */;
|
|
493
|
-
}
|
|
494
|
-
related.push(asset);
|
|
495
|
-
}
|
|
496
|
-
if (!quote && !isHtml && !isJs) {
|
|
497
|
-
if (value.indexOf('"') === -1) {
|
|
498
|
-
quote = '"';
|
|
499
|
-
}
|
|
500
|
-
else if (value.indexOf("'") === -1) {
|
|
501
|
-
quote = "'";
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
if (isUrl) {
|
|
505
|
-
const index = value.indexOf('#');
|
|
506
|
-
if (index !== -1) {
|
|
507
|
-
value = value.substring(0, index);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
if (quote) {
|
|
511
|
-
value = quote + value + quote;
|
|
512
|
-
}
|
|
513
|
-
const revised = isJs ? 'import(' + value + trailing + ')' : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
514
|
-
source = spliceString(source, startIndex, i + 1, revised);
|
|
515
|
-
length = source.length;
|
|
516
|
-
pattern.lastIndex = startIndex + revised.length;
|
|
517
|
-
modified = true;
|
|
518
|
-
};
|
|
519
|
-
let url;
|
|
520
|
-
if (isJs) {
|
|
521
|
-
if (!quote) {
|
|
522
|
-
continue;
|
|
523
|
-
}
|
|
524
|
-
const file = new RegExp('^\\s*(' + quote + '((?:[^' + quote + ']|(?<=\\\\)' + quote + ')+)' + quote + ')\\s*(,.+)$').exec(content);
|
|
525
|
-
if (file) {
|
|
526
|
-
url = file[1].trim();
|
|
527
|
-
trailing = file[2].trim();
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
url = trimQuote(content);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
else {
|
|
534
|
-
url = trimQuote(content);
|
|
535
|
-
}
|
|
536
|
-
if (url.startsWith('data:')) {
|
|
537
|
-
const base64 = url.split(',')[1]?.trim();
|
|
538
|
-
if (base64) {
|
|
539
|
-
for (const item of this.assets) {
|
|
540
|
-
if (item.base64 === base64) {
|
|
541
|
-
setOutputURL(getSrcURL.call(this, parent, item)[0], item);
|
|
542
|
-
break;
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
else if (baseHref.length) {
|
|
548
|
-
let fullUrl, asset;
|
|
549
|
-
for (const parentUrl of baseHref) {
|
|
550
|
-
if (asset = host.findAsset(fullUrl = resolvePath(url, parentUrl), { replaced: true }) || (this.related.has(parent) ? host.findAsset(fullUrl, { assets: Array.from(this.related.get(parent)), replaced: true }) : undefined)) {
|
|
551
|
-
break;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
if (asset && asset !== importFile) {
|
|
555
|
-
if (!(0, util_1.hasValue)(asset.format, 'base64')) {
|
|
556
|
-
if (asset.bundleReplace) {
|
|
557
|
-
let k, valid;
|
|
558
|
-
if (!isText) {
|
|
559
|
-
let j = startIndex;
|
|
560
|
-
while (isSpace(source[--j])) { }
|
|
561
|
-
valid = source.substring(k = j - 6, j + 1) === '@import';
|
|
562
|
-
}
|
|
563
|
-
else {
|
|
564
|
-
k = startIndex;
|
|
565
|
-
valid = true;
|
|
566
|
-
}
|
|
567
|
-
if (valid) {
|
|
568
|
-
let l = i, revised = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
569
|
-
for (let ch; l < length; ++l) {
|
|
570
|
-
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
571
|
-
break;
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
const layer = this.replaceContent(revised, source.substring(k, l + 1), 'text/css');
|
|
575
|
-
if (layer) {
|
|
576
|
-
revised = layer;
|
|
577
|
-
}
|
|
578
|
-
source = spliceString(source, k, l + 1, revised = transformURL.call(this, host, parent, type, this.removeServerRoot(revised), asset) || revised);
|
|
579
|
-
length = source.length;
|
|
580
|
-
pattern.lastIndex = k + revised.length;
|
|
581
|
-
if (!parent.watch) {
|
|
582
|
-
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
583
|
-
asset.invalid = true;
|
|
584
|
-
}
|
|
585
|
-
else {
|
|
586
|
-
related.push(asset);
|
|
587
|
-
if (!(0, types_1.existsFlag)(asset.flags)) {
|
|
588
|
-
asset.flags |= 8 /* ASSET_FLAG.WATCH */;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
modified = true;
|
|
592
|
-
continue;
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
if (hasSameOrigin(asset.url || fullUrl, ...baseHref)) {
|
|
596
|
-
let sameDir;
|
|
597
|
-
[fullUrl, sameDir] = getSrcURL.call(this, parent, asset);
|
|
598
|
-
if (sameDir && isJs) {
|
|
599
|
-
fullUrl = './' + fullUrl;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
else {
|
|
603
|
-
const pathname = parent.pathname;
|
|
604
|
-
const count = pathname && pathname !== '/' && pathname !== '\\' ? pathname.split(/[\\/]/).length : 0;
|
|
605
|
-
fullUrl = (count ? '../'.repeat(count) : '') + asset.relativeUrl;
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
else if (!asset.invalid) {
|
|
609
|
-
fullUrl = asset.inlineBase64 || (asset.inlineBase64 = (0, types_1.generateUUID)());
|
|
610
|
-
}
|
|
611
|
-
if (url !== fullUrl) {
|
|
612
|
-
setOutputURL(fullUrl, asset);
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
else if (importFile && url !== fullUrl) {
|
|
616
|
-
setOutputURL(fullUrl);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
if (modified) {
|
|
621
|
-
if (related.length) {
|
|
622
|
-
const previous = this.related.get(parent);
|
|
623
|
-
if (previous) {
|
|
624
|
-
related.forEach(item => previous.add(item));
|
|
625
|
-
}
|
|
626
|
-
else {
|
|
627
|
-
this.related.set(parent, new Set(related));
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
return source;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
function getFormatUUID(attr, ext) {
|
|
634
|
-
const format = 'formatMap' in this ? this.formatMap : this.module.format;
|
|
635
|
-
let pattern;
|
|
636
|
-
if ((0, types_1.isObject)(format) && (0, types_1.isObject)(pattern = ext && ext in format ? format[ext] : format.uuid) && pattern[attr]) {
|
|
637
|
-
return (0, types_1.randomString)(pattern[attr], pattern.dictionary);
|
|
638
|
-
}
|
|
639
|
-
return (0, types_1.generateUUID)();
|
|
640
|
-
}
|
|
641
|
-
function setLocationUUID(data, file, ext) {
|
|
642
|
-
const { pathname, filename } = data;
|
|
643
|
-
const assignUUID = ChromeDocument.INTERNAL_ASSIGNUUID;
|
|
644
|
-
let index, modified;
|
|
645
|
-
if (filename) {
|
|
646
|
-
ext || (ext = path.extname(filename).substring(1));
|
|
647
|
-
if ((index = filename.indexOf(assignUUID)) !== -1) {
|
|
648
|
-
data.filename = spliceString(filename, index, index + assignUUID.length, getFormatUUID.call(this, 'filename', ext));
|
|
649
|
-
if (file) {
|
|
650
|
-
file.inlineFilename = data.filename;
|
|
651
|
-
}
|
|
652
|
-
modified = true;
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
if (pathname && (index = pathname.indexOf(assignUUID)) !== -1) {
|
|
656
|
-
data.pathname = spliceString(pathname, index, index + assignUUID.length, getFormatUUID.call(this, 'pathname', ext));
|
|
657
|
-
modified = true;
|
|
658
|
-
}
|
|
659
|
-
if (file && modified) {
|
|
660
|
-
(0, asset_1.setInitialValue)(file, false);
|
|
661
|
-
if (file.hash) {
|
|
662
|
-
delete file.hash;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
function transformOptions(file, mimeType, code, bundleContent) {
|
|
667
|
-
const { uri, localUri, exported } = file;
|
|
668
|
-
let metadata;
|
|
669
|
-
if (mimeType === 'text/css') {
|
|
670
|
-
metadata = { ...this.config, ...file.metadata };
|
|
671
|
-
}
|
|
672
|
-
else if (mimeType === 'text/html') {
|
|
673
|
-
metadata = { '__fromhtml__': true, ...this.config, ...file.metadata };
|
|
674
|
-
}
|
|
675
|
-
else {
|
|
676
|
-
metadata = file.metadata;
|
|
677
|
-
}
|
|
678
|
-
const [pathname, filename] = localUri ? [path.dirname(localUri), path.basename(localUri)] : ['', file.filename];
|
|
679
|
-
const options = { pathname, filename, mimeType, metadata, imported: !!file.imports && file.imported !== false };
|
|
680
|
-
const sourceFile = !exported && uri && this.findSourceRoot(uri);
|
|
681
|
-
if (sourceFile) {
|
|
682
|
-
if (isPath(sourceFile)) {
|
|
683
|
-
options.sourceFile = sourceFile;
|
|
684
|
-
}
|
|
685
|
-
options.sourceName = path.basename(sourceFile);
|
|
686
|
-
options.sourcesRelativeTo = path.dirname(sourceFile);
|
|
687
|
-
options.getMainFile = this.resolveSourceFile(file);
|
|
688
|
-
if (code) {
|
|
689
|
-
options.getSourceFiles = this.locateSourceFiles(file, code, bundleContent);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
if ((!this.productionRelease || this.productionIncremental) && !(0, types_1.modifiedFlag)(file.flags)) {
|
|
693
|
-
options.cacheData = { uri: !exported ? uri : undefined, etag: !file.modified ? file.etag : undefined, encoding: file.encoding };
|
|
694
|
-
}
|
|
695
|
-
return options;
|
|
696
|
-
}
|
|
697
|
-
function transformJs(host, file, output) {
|
|
698
|
-
const { sourceFiles, chunks, map } = output;
|
|
699
|
-
const localUri = file.localUri;
|
|
700
|
-
const emptySources = !!this.productionRelease;
|
|
701
|
-
let uri;
|
|
702
|
-
if (map && (uri = writeSourceMap(localUri, output, { hash: file.hash, emptySources, inlineMap: hasSourceMap(file.metadata, 'inline') }))) {
|
|
703
|
-
host.add(uri, file, types_1.FILE_TYPE.SOURCEMAP);
|
|
704
|
-
}
|
|
705
|
-
if (chunks) {
|
|
706
|
-
const elements = this.elements;
|
|
707
|
-
const localDir = path.dirname(localUri);
|
|
708
|
-
const relativeDir = joinPath(file.moveTo, file.pathname);
|
|
709
|
-
const element = file.element;
|
|
710
|
-
let order = 0, index, appending;
|
|
711
|
-
if (element) {
|
|
712
|
-
index = element.index;
|
|
713
|
-
for (const item of elements) {
|
|
714
|
-
const append = item.append;
|
|
715
|
-
if (append && !append.prepend && dom_1.DomWriter.isEqual(item, element, host.moduleName, true)) {
|
|
716
|
-
(appending || (appending = [])).push(append);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
for (const chunk of chunks) {
|
|
721
|
-
let chunkName = chunk.filename;
|
|
722
|
-
if (!chunkName) {
|
|
723
|
-
chunkName = getFormatUUID.call(this, 'filename', 'js') + path.extname(localUri);
|
|
724
|
-
chunk.entryPoint = true;
|
|
725
|
-
}
|
|
726
|
-
const chunkUri = path.join(localDir, chunkName);
|
|
727
|
-
if (chunk.map && (uri = writeSourceMap(chunkUri, chunk, { emptySources, inlineMap: hasSourceMap(file.metadata, 'inline') }))) {
|
|
728
|
-
host.add(uri, file, types_1.FILE_TYPE.SOURCEMAP);
|
|
729
|
-
}
|
|
730
|
-
try {
|
|
731
|
-
fs.writeFileSync(chunkUri, chunk.code);
|
|
732
|
-
host.add(chunkUri, file);
|
|
733
|
-
if (chunk.entryPoint) {
|
|
734
|
-
if (element) {
|
|
735
|
-
const attributes = { ...file.attributes, src: joinPath(relativeDir, chunkName) };
|
|
736
|
-
if (file.imports && file.imported !== false) {
|
|
737
|
-
attributes.type || (attributes.type = 'module');
|
|
738
|
-
}
|
|
739
|
-
elements.push({
|
|
740
|
-
...element,
|
|
741
|
-
attributes,
|
|
742
|
-
append: { tagName: 'script', tagCount: element.tagCount, nextSibling: dom_1.DomWriter.isIndex(index) ? index + 1 : undefined, order: ++order }
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
else {
|
|
746
|
-
this.writeFail(['Unable to create element entry point', path.basename(chunkUri)], (0, types_1.errorMessage)('js', 'Element not found', chunkUri), 4 /* LOG_TYPE.PROCESS */);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
catch (err) {
|
|
751
|
-
this.writeFail(["Unable to write file" /* ERR_MESSAGE.WRITE_FILE */, path.basename(chunkUri)], err, 32 /* LOG_TYPE.FILE */);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
appending?.forEach(item => item.order += order);
|
|
755
|
-
}
|
|
756
|
-
if ((0, types_1.isArray)(sourceFiles)) {
|
|
757
|
-
file.sourceFiles = sourceFiles;
|
|
758
|
-
}
|
|
759
|
-
file.modified = true;
|
|
760
|
-
return file.sourceUTF8 = output.code;
|
|
761
|
-
}
|
|
762
|
-
function replaceCss(file) {
|
|
763
|
-
const sanitize = (map) => {
|
|
764
|
-
for (const id in map) {
|
|
765
|
-
map[id] = this.removeServerRoot(map[id]).replace(/^\//, '');
|
|
766
|
-
}
|
|
767
|
-
};
|
|
768
|
-
if (file.inlineUrlMap) {
|
|
769
|
-
sanitize(file.inlineUrlMap);
|
|
770
|
-
}
|
|
771
|
-
if (file.inlineUrlCloudMap) {
|
|
772
|
-
sanitize(file.inlineUrlCloudMap);
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
function replaceHtml(source, { productionRelease, contentMap }, cssMap) {
|
|
776
|
-
for (const data of [cssMap, contentMap]) {
|
|
777
|
-
for (const id in data) {
|
|
778
|
-
source = source.replace(new RegExp((0, types_1.escapePattern)(id), 'g'), data[id]);
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
return productionRelease ? this.removeServerRoot(source) : source;
|
|
782
|
-
}
|
|
783
|
-
function isWatched(file) {
|
|
784
|
-
const { initialValue, format } = file;
|
|
785
|
-
if (file.imported || file.bundleReplace || file.inlineContent || file.inlineBase64 || this.replaced.includes(file) || initialValue && (file.inlineFilename !== initialValue.inlineFilename || file.pathname !== initialValue.pathname || initialValue.cacheable === false) || format && ((0, util_1.hasValue)(format, 'base64') || (0, util_1.hasValue)(format, 'woff') || (0, util_1.hasValue)(format, 'woff2'))) {
|
|
786
|
-
return true;
|
|
787
|
-
}
|
|
788
|
-
return false;
|
|
789
|
-
}
|
|
790
|
-
function loadLocalFile(item, pathname, cacheData, encoding, out) {
|
|
791
|
-
let content;
|
|
792
|
-
encoding = (0, types_1.getEncoding)(encoding);
|
|
793
|
-
if (out) {
|
|
794
|
-
content = fs.readFileSync(pathname, encoding);
|
|
795
|
-
out.content = content;
|
|
796
|
-
}
|
|
797
|
-
const ext = path.extname(pathname).substring(1).toLowerCase();
|
|
798
|
-
if (ext === 'cjs') {
|
|
799
|
-
return require(pathname);
|
|
800
|
-
}
|
|
801
|
-
content || (content = fs.readFileSync(pathname, encoding));
|
|
802
|
-
const result = this.tryParse(content, ext);
|
|
803
|
-
if (result !== undefined && result !== null) {
|
|
804
|
-
setCacheData.call(this, item, result, pathname, cacheData, true);
|
|
805
|
-
return result;
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
function setCacheData(item, data, dataKey, cacheData, template) {
|
|
809
|
-
if ((0, types_1.isObject)(data) || template) {
|
|
810
|
-
const cache = this.settingsOf(item.source, template && item.source !== 'local' ? 'local_file' : 'cache');
|
|
811
|
-
let timeout;
|
|
812
|
-
if (cache && (timeout = core_1.ClientDb.getTimeout(cache)) && timeout > 0) {
|
|
813
|
-
addCacheItem(template ? CACHE_LOCALFILE : CACHE_DBRESULT, dataKey, data, timeout);
|
|
814
|
-
}
|
|
815
|
-
else {
|
|
816
|
-
cacheData[dataKey] = data;
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
async function checkData(item, name, result, validate) {
|
|
821
|
-
let callback;
|
|
822
|
-
if (typeof name === 'string') {
|
|
823
|
-
const template = this.findDataValue(name) || name;
|
|
824
|
-
callback = this.hasEval('userconfig') ? index_1.default.parseFunction(template, this.hasEval('absolute')) : (0, types_1.asFunction)(template);
|
|
825
|
-
}
|
|
826
|
-
else {
|
|
827
|
-
callback = name;
|
|
828
|
-
name = '';
|
|
829
|
-
}
|
|
830
|
-
if (typeof callback === 'function') {
|
|
831
|
-
try {
|
|
832
|
-
let output;
|
|
833
|
-
// @ts-ignore
|
|
834
|
-
if (callback["__cjs__" /* INTERNAL.CJS */]) {
|
|
835
|
-
output = await callback(result, item);
|
|
836
|
-
}
|
|
837
|
-
else {
|
|
838
|
-
output = await callback.apply(index_1.default.enabled("node.process.inline" /* KEY_NAME.NODE_PROCESS_INLINE */) ? process : null, index_1.default.enabled("node.require.inline" /* KEY_NAME.NODE_REQUIRE_INLINE */) ? [result, item, require] : [result, item]);
|
|
839
|
-
}
|
|
840
|
-
if (validate(output)) {
|
|
841
|
-
return output;
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
catch (err) {
|
|
845
|
-
this.writeFail(["Unable to parse inline method" /* ERR_MESSAGE.INLINE_METHOD */, name], err);
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
const getNewlineString = dom_1.DomWriter.getNewlineString.bind(dom_1.DomWriter);
|
|
850
|
-
const isSpace = dom_1.DomWriter.isSpace.bind(dom_1.DomWriter);
|
|
851
|
-
const replaceMatch = dom_1.DomWriter.replaceMatch.bind(dom_1.DomWriter);
|
|
852
|
-
const joinPath = index_1.default.joinPath.bind(index_1.default);
|
|
853
|
-
const isPath = index_1.default.isPath.bind(index_1.default);
|
|
854
|
-
const writeSourceMap = index_1.default.writeSourceMap.bind(index_1.default);
|
|
855
|
-
const asString = index_1.default.asString.bind(index_1.default);
|
|
856
|
-
const resolvePath = index_1.default.resolvePath.bind(index_1.default);
|
|
857
|
-
const toPosix = index_1.default.toPosix.bind(index_1.default);
|
|
858
|
-
const isDir = index_1.default.isDir.bind(index_1.default);
|
|
859
|
-
const hasSourceMap = (metadata, value) => (0, types_1.isObject)(metadata) && metadata['__sourcemap__'] === value;
|
|
860
|
-
const isBundled = (value, main) => typeof value === 'number' && (value > 0 || main && value === 0);
|
|
861
|
-
const isFont = (value) => value === 'truetype' || value === 'opentype' || value === 'woff' || value === 'woff2';
|
|
862
|
-
const isImage = (value) => typeof value === 'string' && value.startsWith('image/') && value !== 'image/svg+xml';
|
|
863
|
-
const getBuffer = (item) => item.sourceUTF8 || item.buffer || (item.localUri && isPath(item.localUri) ? fs.readFileSync(item.localUri, item.encoding) : null);
|
|
864
|
-
const isRemoved = (item) => item.exclude === true || isBundled(item.bundleIndex);
|
|
865
|
-
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'));
|
|
866
|
-
const isIgnored = (item, exists) => item.invalid || (0, types_1.ignoreFlag)(item.flags) || !exists && (0, types_1.existsFlag)(item.flags);
|
|
867
|
-
const findFont = (value) => value && (Array.isArray(value) ? value : [value]).find(format => isFont(format));
|
|
868
|
-
const spliceString = (source, startIndex, endIndex, content) => source.substring(0, startIndex) + content + source.substring(endIndex);
|
|
869
|
-
const getEndIndex = (match) => match.index + match[0].length;
|
|
870
|
-
const getRelativeURL = (file) => joinPath(file.moveTo, file.pathname, file.inlineFilename || file.filename) + (!file.static ? restoreSearchParams(file.url?.search) : '');
|
|
871
|
-
const errorHtml = ({ tagName, tagIndex = -1 }) => (0, types_1.errorMessage)('html', 'Location did not resolve', tagName.toLowerCase() + (tagIndex >= 0 ? ': ' + tagIndex : ''));
|
|
872
|
-
const errorDataSource = (value, hint) => (0, types_1.errorMessage)('data-source', value, hint);
|
|
873
|
-
class ChromeDocument extends index_1.default {
|
|
874
|
-
constructor() {
|
|
875
|
-
super(...arguments);
|
|
876
|
-
this.config = {
|
|
877
|
-
usedVariables: undefined,
|
|
878
|
-
usedFontFace: undefined,
|
|
879
|
-
usedKeyframes: undefined,
|
|
880
|
-
unusedStyles: undefined,
|
|
881
|
-
unusedMedia: undefined,
|
|
882
|
-
unusedContainer: undefined,
|
|
883
|
-
unusedSupports: undefined,
|
|
884
|
-
unusedAtRules: undefined,
|
|
885
|
-
useOriginalHtmlPage: undefined,
|
|
886
|
-
useUnsafeHtmlReplace: undefined,
|
|
887
|
-
useUnsafeCssReplace: undefined,
|
|
888
|
-
stripCommentsAndCDATA: undefined,
|
|
889
|
-
normalizeHtmlOutput: undefined,
|
|
890
|
-
escapeReservedCharacters: undefined,
|
|
891
|
-
ignoreServerCodeBlocks: undefined
|
|
892
|
-
};
|
|
893
|
-
this.htmlFile = null;
|
|
894
|
-
this.cssFiles = [];
|
|
895
|
-
this.jsFiles = [];
|
|
896
|
-
this.svgFiles = [];
|
|
897
|
-
this.baseDirectory = '';
|
|
898
|
-
this.baseUrl = '';
|
|
899
|
-
this.productionRelease = false;
|
|
900
|
-
this.productionIncremental = false;
|
|
901
|
-
this.templateMap = {};
|
|
902
|
-
this.related = new Map();
|
|
903
|
-
this.replaced = [];
|
|
904
|
-
this._moduleName = 'chrome';
|
|
905
|
-
this._threadable = true;
|
|
906
|
-
this._elements = null;
|
|
907
|
-
this._idMap = Object.create(null);
|
|
908
|
-
this._editing = [];
|
|
909
|
-
this._selectorMap = {};
|
|
910
|
-
}
|
|
911
|
-
static async purgeMemory(percent = 1, limit = 0, parent) {
|
|
912
|
-
if (typeof limit === 'boolean') {
|
|
913
|
-
parent = limit;
|
|
914
|
-
limit = 0;
|
|
915
|
-
}
|
|
916
|
-
let result = 0;
|
|
917
|
-
if (limit === 0 || CACHE_TOTAL >= limit) {
|
|
918
|
-
if (percent >= 1) {
|
|
919
|
-
result += CACHE_DBRESULT.size + CACHE_LOCALFILE.size;
|
|
920
|
-
CACHE_DBRESULT.clear();
|
|
921
|
-
CACHE_LOCALFILE.clear();
|
|
922
|
-
CACHE_TOTAL = 0;
|
|
923
|
-
}
|
|
924
|
-
else if (percent > 0) {
|
|
925
|
-
const stored = [];
|
|
926
|
-
for (const map of [CACHE_DBRESULT, CACHE_LOCALFILE]) {
|
|
927
|
-
for (const [key, value] of map) {
|
|
928
|
-
stored.push([map, key, value[0]]);
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
stored.sort((a, b) => a[2] - b[2]);
|
|
932
|
-
result = Math.floor(stored.length * percent);
|
|
933
|
-
for (let i = 0; i < result; ++i) {
|
|
934
|
-
const [map, key] = stored[i];
|
|
935
|
-
deleteCacheItem(map, key);
|
|
936
|
-
}
|
|
937
|
-
CACHE_TOTAL = stored.length - result;
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
|
|
941
|
-
}
|
|
942
|
-
static async finalize(instance) {
|
|
943
|
-
if (instance.aborted) {
|
|
944
|
-
return Promise.reject((0, types_1.createAbortError)());
|
|
945
|
-
}
|
|
946
|
-
const productionRelease = instance.productionRelease;
|
|
947
|
-
const processing = { host: this, startTime: process.hrtime(), hashed: new Set(), contentMap: {}, bufferMap: {}, cacheMiss: [], productionRelease: productionRelease ? true : undefined };
|
|
948
|
-
const { Db: db, htmlFile, assets } = instance;
|
|
949
|
-
const outHtml = htmlFile && !isIgnored(htmlFile, true);
|
|
950
|
-
if (db && await db.commit()) {
|
|
951
|
-
db.writeTimeElapsed('DB', ["Transactions were committed" /* VAL_MESSAGE.COMMIT_TRANSACTION */, db.moduleName], processing.startTime, { ...index_1.default.LOG_STYLE_SUCCESS, type: 65536 /* LOG_TYPE.DB */ });
|
|
952
|
-
}
|
|
953
|
-
if (instance.dataSource.length === 0 && outHtml) {
|
|
954
|
-
const incremental = htmlFile.incremental ?? this.incremental;
|
|
955
|
-
if (incremental === 'etag' || incremental === 'exists') {
|
|
956
|
-
const fetched = this.fetchedAssets;
|
|
957
|
-
const isHtmlOnly = () => !fetched.find(item => item !== htmlFile && assets.includes(item));
|
|
958
|
-
if (!productionRelease || instance.productionIncremental && (isHtmlOnly() || !fetched.find(item => item.hash))) {
|
|
959
|
-
let hint = '';
|
|
960
|
-
switch (incremental) {
|
|
961
|
-
case 'etag': {
|
|
962
|
-
if (outHtml) {
|
|
963
|
-
const { etag, initialValue } = htmlFile;
|
|
964
|
-
let buffer;
|
|
965
|
-
if (!initialValue || !(etag && initialValue.etag === etag && (buffer = initialValue.buffer)) || fetched.find(item => item.bundleReplace && (!(0, types_1.isArray)(item.from) || item.from.includes('style')))) {
|
|
966
|
-
break;
|
|
967
|
-
}
|
|
968
|
-
try {
|
|
969
|
-
const { localUri, encoding } = htmlFile;
|
|
970
|
-
fs.writeFileSync(localUri, buffer, (0, types_1.getEncoding)(encoding));
|
|
971
|
-
htmlFile.buffer = buffer;
|
|
972
|
-
htmlFile.sourceUTF8 = undefined;
|
|
973
|
-
}
|
|
974
|
-
catch {
|
|
975
|
-
break;
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
const { jsFiles, cssFiles, svgFiles } = instance;
|
|
979
|
-
const copiedAssets = this.copiedAssets;
|
|
980
|
-
const wasModified = (item) => fetched.includes(item) || copiedAssets.includes(item) && (!(0, types_1.isEmpty)(item.bundleId) || !(0, types_1.isEmpty)(item.trailingContent));
|
|
981
|
-
const js = jsFiles.filter(item => item.imports || wasModified(item));
|
|
982
|
-
const css = cssFiles.filter(wasModified);
|
|
983
|
-
const svg = svgFiles.filter(wasModified);
|
|
984
|
-
if (js.length || css.length || svg.length) {
|
|
985
|
-
instance.jsFiles = js;
|
|
986
|
-
instance.cssFiles = css;
|
|
987
|
-
instance.svgFiles = svg;
|
|
988
|
-
await instance.applyTransforms(processing);
|
|
989
|
-
}
|
|
990
|
-
hint = assets.filter(item => item.etag).length + ' assets';
|
|
991
|
-
}
|
|
992
|
-
case 'exists':
|
|
993
|
-
if (hint || isHtmlOnly()) {
|
|
994
|
-
this.formatMessage(4 /* LOG_TYPE.PROCESS */, 'HTML', ['No changes detected', 'incremental: ' + incremental], hint, { ...index_1.default.LOG_STYLE_NOTICE, messageBgColor: 'bgWhite', messageColor: 'black' });
|
|
995
|
-
return super.finalize.call(this, instance);
|
|
996
|
-
}
|
|
997
|
-
break;
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
instance.setInlinedAttributes(processing);
|
|
1003
|
-
if (instance.editing.length) {
|
|
1004
|
-
await instance.applyTransforms(processing);
|
|
1005
|
-
if (instance.aborted) {
|
|
1006
|
-
return Promise.reject((0, types_1.createAbortError)());
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
if (productionRelease) {
|
|
1010
|
-
instance.setProductionAttributes(processing);
|
|
1011
|
-
}
|
|
1012
|
-
if (outHtml) {
|
|
1013
|
-
await instance.rewriteHtml(processing);
|
|
1014
|
-
}
|
|
1015
|
-
return this.aborted ? Promise.reject((0, types_1.createAbortError)()) : super.finalize.call(this, instance);
|
|
1016
|
-
}
|
|
1017
|
-
static async cleanup(instance) {
|
|
1018
|
-
if (instance.aborted) {
|
|
1019
|
-
return Promise.reject((0, types_1.createAbortError)());
|
|
1020
|
-
}
|
|
1021
|
-
if (this.Watch) {
|
|
1022
|
-
const related = instance.related;
|
|
1023
|
-
let includes;
|
|
1024
|
-
for (const asset of instance.assets) {
|
|
1025
|
-
if (asset.watch && (includes = related.get(asset))) {
|
|
1026
|
-
if (!(0, types_1.isPlainObject)(asset.watch)) {
|
|
1027
|
-
asset.watch = {};
|
|
1028
|
-
}
|
|
1029
|
-
const items = new Set((asset.watch.assets || []));
|
|
1030
|
-
(function recurse(children) {
|
|
1031
|
-
for (const item of children) {
|
|
1032
|
-
if (!items.has(item)) {
|
|
1033
|
-
if (isWatched.call(instance, item)) {
|
|
1034
|
-
item.flags |= 8 /* ASSET_FLAG.WATCH */;
|
|
1035
|
-
}
|
|
1036
|
-
items.add(item);
|
|
1037
|
-
const next = related.get(item);
|
|
1038
|
-
if (next) {
|
|
1039
|
-
recurse(next);
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
})(includes);
|
|
1044
|
-
asset.watch.assets = Array.from(items);
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
let productionRelease = instance.productionRelease;
|
|
1049
|
-
if ((0, types_1.isString)(productionRelease)) {
|
|
1050
|
-
if (path.isAbsolute(productionRelease = path.normalize(productionRelease)) && isDir(productionRelease)) {
|
|
1051
|
-
if (this.canWrite(productionRelease)) {
|
|
1052
|
-
const serverRoot = ChromeDocument.INTERNAL_SERVERROOT;
|
|
1053
|
-
const srcDir = path.join(this.baseDirectory, serverRoot);
|
|
1054
|
-
if (isDir(srcDir)) {
|
|
1055
|
-
const result = await index_1.default.copyDir(srcDir, productionRelease, !this.archiving);
|
|
1056
|
-
const failed = result.failed.map(value => this.removeCwd(value));
|
|
1057
|
-
for (const value of this.files) {
|
|
1058
|
-
if (value.startsWith(serverRoot)) {
|
|
1059
|
-
if (!failed.includes(value)) {
|
|
1060
|
-
this.delete(value);
|
|
1061
|
-
}
|
|
1062
|
-
else {
|
|
1063
|
-
instance.writeFail(["Unable to move file" /* ERR_MESSAGE.MOVE_FILE */, instance.moduleName], (0, types_1.errorMessage)('production', path.join(this.baseDirectory, value)), { fatal: true });
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
else {
|
|
1070
|
-
instance.writeFail(["Unable to write directory" /* ERR_MESSAGE.WRITE_DIRECTORY */, instance.moduleName], (0, types_1.errorMessage)('production', 'Access denied', productionRelease));
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
else {
|
|
1074
|
-
instance.writeFail(["Unable to read directory" /* ERR_MESSAGE.READ_DIRECTORY */, instance.moduleName], (0, types_1.errorMessage)('production', 'Invalid directory', productionRelease), 32 /* LOG_TYPE.FILE */);
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
static sanitizeAssets(assets, exclusions = []) {
|
|
1079
|
-
assets.forEach(item => {
|
|
1080
|
-
if ((0, types_1.ignoreFlag)(item.flags)) {
|
|
1081
|
-
return;
|
|
1082
|
-
}
|
|
1083
|
-
for (const attr in item) {
|
|
1084
|
-
switch (attr) {
|
|
1085
|
-
case 'relativeUrl':
|
|
1086
|
-
case 'srcSet':
|
|
1087
|
-
case 'inlineUrl':
|
|
1088
|
-
case 'inlineUrlMap':
|
|
1089
|
-
case 'inlineUrlCloud':
|
|
1090
|
-
case 'inlineUrlCloudMap':
|
|
1091
|
-
case 'inlineBase64':
|
|
1092
|
-
case 'modified':
|
|
1093
|
-
if (!exclusions.includes(attr)) {
|
|
1094
|
-
delete item[attr];
|
|
1095
|
-
}
|
|
1096
|
-
break;
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
});
|
|
1100
|
-
}
|
|
1101
|
-
init(assets, config) {
|
|
1102
|
-
assets.sort((a, b) => {
|
|
1103
|
-
if (!(0, types_1.isEmpty)(a.bundleId) && a.bundleId === b.bundleId) {
|
|
1104
|
-
return b.bundleIndex - a.bundleIndex;
|
|
1105
|
-
}
|
|
1106
|
-
return 0;
|
|
1107
|
-
});
|
|
1108
|
-
const cloud = [];
|
|
1109
|
-
for (const item of assets) {
|
|
1110
|
-
if ((0, types_1.ignoreFlag)(item.flags)) {
|
|
1111
|
-
continue;
|
|
1112
|
-
}
|
|
1113
|
-
if (item.trailingContent) {
|
|
1114
|
-
item.modified = true;
|
|
1115
|
-
}
|
|
1116
|
-
if (Array.isArray(item.cloudStorage)) {
|
|
1117
|
-
cloud.push(item.cloudStorage);
|
|
1118
|
-
}
|
|
1119
|
-
if (item.editing) {
|
|
1120
|
-
switch (item.mimeType) {
|
|
1121
|
-
case 'text/html':
|
|
1122
|
-
if (!this.htmlFile) {
|
|
1123
|
-
this.htmlFile = item;
|
|
1124
|
-
item.editing = true;
|
|
1125
|
-
this._editing.push(item);
|
|
1126
|
-
}
|
|
1127
|
-
else {
|
|
1128
|
-
item.editing = false;
|
|
1129
|
-
}
|
|
1130
|
-
item.mimeType = 'text/html';
|
|
1131
|
-
break;
|
|
1132
|
-
case 'text/css':
|
|
1133
|
-
this.cssFiles.push(item);
|
|
1134
|
-
this._editing.push(item);
|
|
1135
|
-
item.editing = true;
|
|
1136
|
-
item.mimeType = 'text/css';
|
|
1137
|
-
break;
|
|
1138
|
-
case 'text/javascript':
|
|
1139
|
-
case 'application/javascript':
|
|
1140
|
-
this.jsFiles.push(item);
|
|
1141
|
-
this._editing.push(item);
|
|
1142
|
-
item.editing = true;
|
|
1143
|
-
item.mimeType = 'application/javascript';
|
|
1144
|
-
break;
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
this.cssFiles.sort((a, b) => {
|
|
1149
|
-
if (a.bundleReplace) {
|
|
1150
|
-
return -1;
|
|
1151
|
-
}
|
|
1152
|
-
if (b.bundleReplace) {
|
|
1153
|
-
return 1;
|
|
1154
|
-
}
|
|
1155
|
-
return 0;
|
|
1156
|
-
});
|
|
1157
|
-
if (config) {
|
|
1158
|
-
const { useUnsafeReplace, baseUrl, productionRelease, productionIncremental, templateMap, imports, cache } = config;
|
|
1159
|
-
const target = this.config;
|
|
1160
|
-
for (const attr in config) {
|
|
1161
|
-
if (attr in target) {
|
|
1162
|
-
target[attr] = config[attr];
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
switch (useUnsafeReplace) {
|
|
1166
|
-
case 'html':
|
|
1167
|
-
target.useUnsafeHtmlReplace = true;
|
|
1168
|
-
break;
|
|
1169
|
-
case 'css':
|
|
1170
|
-
target.useUnsafeCssReplace = true;
|
|
1171
|
-
break;
|
|
1172
|
-
default:
|
|
1173
|
-
if (typeof useUnsafeReplace === 'boolean') {
|
|
1174
|
-
target.useUnsafeHtmlReplace = useUnsafeReplace;
|
|
1175
|
-
target.useUnsafeCssReplace = useUnsafeReplace;
|
|
1176
|
-
}
|
|
1177
|
-
else if ((0, types_1.isArray)(useUnsafeReplace)) {
|
|
1178
|
-
target.useUnsafeHtmlReplace = useUnsafeReplace.includes('html');
|
|
1179
|
-
target.useUnsafeCssReplace = useUnsafeReplace.includes('css');
|
|
1180
|
-
}
|
|
1181
|
-
break;
|
|
1182
|
-
}
|
|
1183
|
-
if (baseUrl) {
|
|
1184
|
-
try {
|
|
1185
|
-
const { origin, pathname } = new URL(this.baseUrl = baseUrl);
|
|
1186
|
-
this.baseDirectory = origin + pathname.substring(0, pathname.lastIndexOf('/') + 1);
|
|
1187
|
-
}
|
|
1188
|
-
catch {
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
if (productionRelease === true || (0, types_1.isString)(productionRelease)) {
|
|
1192
|
-
this.productionRelease = productionRelease;
|
|
1193
|
-
}
|
|
1194
|
-
if (productionIncremental) {
|
|
1195
|
-
this.productionIncremental = true;
|
|
1196
|
-
}
|
|
1197
|
-
if ((0, types_1.isObject)(templateMap)) {
|
|
1198
|
-
this.templateMap = templateMap;
|
|
1199
|
-
}
|
|
1200
|
-
this.imports = (0, types_1.isPlainObject)(imports) ? { ...this.module.imports, ...imports } : this.module.imports;
|
|
1201
|
-
if ((0, types_1.isObject)(cache) && 'transform' in cache) {
|
|
1202
|
-
this.customize({ transform: cache.transform });
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
super.init(assets, config);
|
|
1206
|
-
const mimeMap = this._mimeMap;
|
|
1207
|
-
if (mimeMap && 'format' in mimeMap) {
|
|
1208
|
-
const format = mimeMap.format;
|
|
1209
|
-
if ((0, types_1.isObject)(format)) {
|
|
1210
|
-
this.formatMap = 'pathname' in format || 'filename' in format || 'dictionary' in format ? { uuid: format } : format;
|
|
1211
|
-
}
|
|
1212
|
-
else {
|
|
1213
|
-
this.formatMap = undefined;
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
for (const storage of cloud) {
|
|
1217
|
-
for (const { service, upload, download } of storage) {
|
|
1218
|
-
if (upload) {
|
|
1219
|
-
setLocationUUID.call(this, upload, null, service);
|
|
1220
|
-
}
|
|
1221
|
-
if (download) {
|
|
1222
|
-
setLocationUUID.call(this, download, null, service);
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
return this;
|
|
1227
|
-
}
|
|
1228
|
-
findConfig(data, name, type) {
|
|
1229
|
-
if (type && this.hasEval('template')) {
|
|
1230
|
-
const settings = this.templateMap[type];
|
|
1231
|
-
for (const attr in settings) {
|
|
1232
|
-
const item = settings[attr];
|
|
1233
|
-
if ((0, types_1.isObject)(item) && name in item) {
|
|
1234
|
-
const options = this.loadConfig(item, name);
|
|
1235
|
-
if (options) {
|
|
1236
|
-
return [attr, options, this.loadConfig(item, name + '-output')];
|
|
1237
|
-
}
|
|
1238
|
-
break;
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
return super.findConfig(data, name, type);
|
|
1243
|
-
}
|
|
1244
|
-
forDb(item) {
|
|
1245
|
-
switch (item.source) {
|
|
1246
|
-
case 'cloud':
|
|
1247
|
-
case 'uri':
|
|
1248
|
-
case 'local':
|
|
1249
|
-
case 'export':
|
|
1250
|
-
return false;
|
|
1251
|
-
default:
|
|
1252
|
-
return !item.element;
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
restart() {
|
|
1256
|
-
ChromeDocument.sanitizeAssets(this.assets);
|
|
1257
|
-
this._elements = null;
|
|
1258
|
-
this._dataSource = null;
|
|
1259
|
-
}
|
|
1260
|
-
async using(data) {
|
|
1261
|
-
if (this.aborted) {
|
|
1262
|
-
return Promise.reject((0, types_1.createAbortError)());
|
|
1263
|
-
}
|
|
1264
|
-
const file = data.file;
|
|
1265
|
-
if (file.editing) {
|
|
1266
|
-
return;
|
|
1267
|
-
}
|
|
1268
|
-
const host = data.host;
|
|
1269
|
-
const productionRelease = this.productionRelease ? true : undefined;
|
|
1270
|
-
const { localUri, mimeType, format } = file;
|
|
1271
|
-
const hash = productionRelease && file.hash;
|
|
1272
|
-
switch (mimeType) {
|
|
1273
|
-
case 'text/html':
|
|
1274
|
-
if (format) {
|
|
1275
|
-
const output = await this.transform('html', host.getUTF8String(file, localUri), format, transformOptions.call(this, file, mimeType));
|
|
1276
|
-
if (output) {
|
|
1277
|
-
file.modified = true;
|
|
1278
|
-
file.sourceUTF8 = output.code;
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
break;
|
|
1282
|
-
case 'text/css':
|
|
1283
|
-
if (format) {
|
|
1284
|
-
const source = host.getUTF8String(file, localUri);
|
|
1285
|
-
const output = await this.transform('css', source, format, transformOptions.call(this, file, mimeType, source));
|
|
1286
|
-
if (output) {
|
|
1287
|
-
if (output.map) {
|
|
1288
|
-
const uri = writeSourceMap(localUri, output, { mimeType, hash, emptySources: productionRelease, inlineMap: hasSourceMap(file.metadata, 'inline') });
|
|
1289
|
-
if (uri) {
|
|
1290
|
-
host.add(uri, file, types_1.FILE_TYPE.SOURCEMAP);
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
file.modified = true;
|
|
1294
|
-
file.sourceUTF8 = output.code;
|
|
1295
|
-
}
|
|
1296
|
-
}
|
|
1297
|
-
break;
|
|
1298
|
-
case 'text/javascript':
|
|
1299
|
-
case 'application/javascript': {
|
|
1300
|
-
let source = host.getUTF8String(file, localUri);
|
|
1301
|
-
if (!(file.bundleIndex >= 0)) {
|
|
1302
|
-
source = host.setAssetContent(file, source);
|
|
1303
|
-
}
|
|
1304
|
-
const bundle = host.getAssetContent(file);
|
|
1305
|
-
if (bundle) {
|
|
1306
|
-
source += bundle;
|
|
1307
|
-
file.modified = true;
|
|
1308
|
-
}
|
|
1309
|
-
if (format) {
|
|
1310
|
-
const output = await this.transform('js', source, format, transformOptions.call(this, file, mimeType, source, host.contentToAppend.get(localUri)));
|
|
1311
|
-
if (output) {
|
|
1312
|
-
source = transformJs.call(this, host, file, output);
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
file.sourceUTF8 = source;
|
|
1316
|
-
break;
|
|
1317
|
-
}
|
|
1318
|
-
case 'image/svg+xml': {
|
|
1319
|
-
const source = host.getUTF8String(file, localUri);
|
|
1320
|
-
if (/\burl\(/i.test(source)) {
|
|
1321
|
-
file.editing = true;
|
|
1322
|
-
this.editing.push(file);
|
|
1323
|
-
this.svgFiles.push(file);
|
|
1324
|
-
}
|
|
1325
|
-
else if (format) {
|
|
1326
|
-
const output = await this.transform('html', source, format, transformOptions.call(this, file, mimeType, source));
|
|
1327
|
-
if (output) {
|
|
1328
|
-
file.modified = true;
|
|
1329
|
-
file.sourceUTF8 = output.code;
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
break;
|
|
1333
|
-
}
|
|
1334
|
-
case 'font/ttf':
|
|
1335
|
-
case 'font/otf':
|
|
1336
|
-
case 'font/woff':
|
|
1337
|
-
case 'font/woff2': {
|
|
1338
|
-
const setFormat = (type) => {
|
|
1339
|
-
if (Array.isArray(format)) {
|
|
1340
|
-
file.format = format.filter(value => !isFont(value));
|
|
1341
|
-
if (type) {
|
|
1342
|
-
file.format.push(type);
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
else {
|
|
1346
|
-
file.format = type;
|
|
1347
|
-
}
|
|
1348
|
-
};
|
|
1349
|
-
let to;
|
|
1350
|
-
if (mimeType.includes('woff')) {
|
|
1351
|
-
if ((0, util_1.hasValue)(format, 'truetype')) {
|
|
1352
|
-
to = 'ttf';
|
|
1353
|
-
}
|
|
1354
|
-
else if ((0, util_1.hasValue)(format, 'opentype')) {
|
|
1355
|
-
to = 'otf';
|
|
1356
|
-
}
|
|
1357
|
-
else {
|
|
1358
|
-
return;
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
else if ((0, util_1.hasValue)(format, 'woff')) {
|
|
1362
|
-
to = 'woff';
|
|
1363
|
-
}
|
|
1364
|
-
else if ((0, util_1.hasValue)(format, 'woff2')) {
|
|
1365
|
-
to = 'woff2';
|
|
1366
|
-
}
|
|
1367
|
-
else {
|
|
1368
|
-
return;
|
|
1369
|
-
}
|
|
1370
|
-
const instance = host.loadModule('compress');
|
|
1371
|
-
const buffer = host.getBuffer(file);
|
|
1372
|
-
if (instance && buffer) {
|
|
1373
|
-
await instance.tryFile(buffer, { format: to, filename: file.filename, etag: file.etag }, (err, result, ext) => {
|
|
1374
|
-
if (err) {
|
|
1375
|
-
setFormat();
|
|
1376
|
-
this.writeFail("Unable to compress file" /* ERR_MESSAGE.COMPRESS_FILE */, err, 8 /* LOG_TYPE.COMPRESS */);
|
|
1377
|
-
}
|
|
1378
|
-
else if (result) {
|
|
1379
|
-
if (ext) {
|
|
1380
|
-
setFormat(ext.startsWith('woff') ? ext : ext === 'otf' ? 'opentype' : 'truetype');
|
|
1381
|
-
}
|
|
1382
|
-
const output = (0, types_1.renameExt)(localUri, ext || (ext = to));
|
|
1383
|
-
file.mimeType = 'font/' + ext;
|
|
1384
|
-
fs.writeFile(output, result, error => {
|
|
1385
|
-
if (!error) {
|
|
1386
|
-
file.buffer = result;
|
|
1387
|
-
host.replace(file, output);
|
|
1388
|
-
}
|
|
1389
|
-
else {
|
|
1390
|
-
this.writeFail("Unable to write file" /* ERR_MESSAGE.WRITE_FILE */, error, 32 /* LOG_TYPE.FILE */);
|
|
1391
|
-
}
|
|
1392
|
-
});
|
|
1393
|
-
}
|
|
1394
|
-
});
|
|
1395
|
-
}
|
|
1396
|
-
break;
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
setLocalUri(file, replace) {
|
|
1401
|
-
if (replace) {
|
|
1402
|
-
let trailing = file.inlineFilename;
|
|
1403
|
-
if (trailing) {
|
|
1404
|
-
let index = trailing.indexOf('?');
|
|
1405
|
-
if (index !== -1 || (index = trailing.indexOf('#')) !== -1) {
|
|
1406
|
-
trailing = trailing.substring(index);
|
|
1407
|
-
}
|
|
1408
|
-
else {
|
|
1409
|
-
trailing = '';
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
else {
|
|
1413
|
-
trailing = '';
|
|
1414
|
-
}
|
|
1415
|
-
file.inlineFilename = file.filename + trailing;
|
|
1416
|
-
this.replaced.push(file);
|
|
1417
|
-
}
|
|
1418
|
-
else {
|
|
1419
|
-
setLocationUUID.call(this, file, file);
|
|
1420
|
-
}
|
|
1421
|
-
file.relativeUrl = getRelativeURL(file);
|
|
1422
|
-
}
|
|
1423
|
-
resolveUri(file, source, trailing) {
|
|
1424
|
-
const host = this.host;
|
|
1425
|
-
if (host) {
|
|
1426
|
-
switch (file.mimeType) {
|
|
1427
|
-
case 'text/javascript':
|
|
1428
|
-
case 'application/javascript':
|
|
1429
|
-
if (file.imports) {
|
|
1430
|
-
[[file.uri, source], [this.baseUrl, trailing]].forEach(([uri, code], index) => {
|
|
1431
|
-
let localFile;
|
|
1432
|
-
if (uri && code && (localFile = this.findSourceRoot(uri))) {
|
|
1433
|
-
const { exported, bundleId } = file;
|
|
1434
|
-
const bundleMain = !(0, types_1.isEmpty)(bundleId) && this.assets.find(item => item.bundleId === bundleId && item.bundleIndex === 0);
|
|
1435
|
-
let output;
|
|
1436
|
-
if ((index === 1 || exported) && Array.isArray(file.imports)) {
|
|
1437
|
-
output = this.resolveImports(file, code, bundleMain || file);
|
|
1438
|
-
}
|
|
1439
|
-
else if (index === 0 && !exported) {
|
|
1440
|
-
if (!isDir(localFile)) {
|
|
1441
|
-
localFile = path.dirname(localFile);
|
|
1442
|
-
}
|
|
1443
|
-
let mainFile, pathname, match;
|
|
1444
|
-
const ignorePath = bundleMain && (mainFile = this.findSourceRoot(bundleMain.uri)) && (isDir(mainFile) || (mainFile = path.dirname(mainFile))) && mainFile === localFile;
|
|
1445
|
-
while (match = REGEXP_IMPORTMODULE.exec(code)) {
|
|
1446
|
-
const value = match[1] || match[2] || match[4];
|
|
1447
|
-
const assert = match[3] || match[5];
|
|
1448
|
-
const from = trimQuote(value);
|
|
1449
|
-
const relative = /^\.{0,2}\//.test(from);
|
|
1450
|
-
if (assert && /\btype\s*:\s*(["'`])css\1/.test(assert)) {
|
|
1451
|
-
try {
|
|
1452
|
-
const asset = host.findAsset(relative ? new URL(from, uri) : from);
|
|
1453
|
-
if (asset) {
|
|
1454
|
-
const [relativeUrl, sameDir] = getSrcURL.call(this, bundleMain || file, asset);
|
|
1455
|
-
if (relativeUrl) {
|
|
1456
|
-
const quote = value[0];
|
|
1457
|
-
output = (output || code).replace(value, quote + (sameDir ? './' : '') + relativeUrl + quote);
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
1461
|
-
catch {
|
|
1462
|
-
}
|
|
1463
|
-
continue;
|
|
1464
|
-
}
|
|
1465
|
-
if (relative) {
|
|
1466
|
-
if (ignorePath) {
|
|
1467
|
-
continue;
|
|
1468
|
-
}
|
|
1469
|
-
pathname = path.join(localFile, from);
|
|
1470
|
-
}
|
|
1471
|
-
else if (!(pathname = this.findSourceRoot(from)) || !isPath(pathname)) {
|
|
1472
|
-
const asset = host.findAsset(from);
|
|
1473
|
-
if (asset && !asset.invalid) {
|
|
1474
|
-
pathname = asset.localUri;
|
|
1475
|
-
}
|
|
1476
|
-
else {
|
|
1477
|
-
continue;
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
if (pathname && isPath(pathname)) {
|
|
1481
|
-
const quote = value[0];
|
|
1482
|
-
output = (output || code).replace(value, quote + pathname + quote);
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
REGEXP_IMPORTMODULE.lastIndex = 0;
|
|
1486
|
-
}
|
|
1487
|
-
if (output) {
|
|
1488
|
-
if (index === 0) {
|
|
1489
|
-
source = output;
|
|
1490
|
-
}
|
|
1491
|
-
else {
|
|
1492
|
-
trailing = output;
|
|
1493
|
-
}
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
});
|
|
1497
|
-
}
|
|
1498
|
-
break;
|
|
1499
|
-
case 'text/css':
|
|
1500
|
-
if (file.editing) {
|
|
1501
|
-
const htmlFile = this.htmlFile;
|
|
1502
|
-
const bundleId = file.bundleId;
|
|
1503
|
-
if (!(0, types_1.isEmpty)(bundleId)) {
|
|
1504
|
-
for (const asset of this.assets) {
|
|
1505
|
-
if (asset.bundleIndex === 0 && asset.bundleId === bundleId) {
|
|
1506
|
-
const output = transformURL.call(this, host, file, 'css', source, asset);
|
|
1507
|
-
if (output) {
|
|
1508
|
-
source = output;
|
|
1509
|
-
file.modified = true;
|
|
1510
|
-
}
|
|
1511
|
-
break;
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
if (trailing && htmlFile) {
|
|
1516
|
-
const output = transformURL.call(this, host, file, 'css', trailing, htmlFile);
|
|
1517
|
-
if (output) {
|
|
1518
|
-
trailing = output;
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
break;
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
return (trailing !== undefined ? [source, trailing] : source);
|
|
1526
|
-
}
|
|
1527
|
-
resolveImports(file, code, baseFile) {
|
|
1528
|
-
var _a;
|
|
1529
|
-
if (!Array.isArray(file.imports)) {
|
|
1530
|
-
return;
|
|
1531
|
-
}
|
|
1532
|
-
let bundleMain, modified;
|
|
1533
|
-
if ((0, types_1.isPlainObject)(baseFile)) {
|
|
1534
|
-
bundleMain = baseFile;
|
|
1535
|
-
}
|
|
1536
|
-
else {
|
|
1537
|
-
const bundleId = file.bundleId;
|
|
1538
|
-
if (!(0, types_1.isEmpty)(bundleId)) {
|
|
1539
|
-
bundleMain = this.assets.find(item => item.bundleId === bundleId && item.bundleIndex === 0);
|
|
1540
|
-
}
|
|
1541
|
-
}
|
|
1542
|
-
const importMap = {};
|
|
1543
|
-
for (const item of file.imports) {
|
|
1544
|
-
(importMap[_a = item.placeholder] || (importMap[_a] = [])).push(item);
|
|
1545
|
-
}
|
|
1546
|
-
for (const placeholder in importMap) {
|
|
1547
|
-
const items = importMap[placeholder];
|
|
1548
|
-
for (let i = 0, length = items.length; i < length; ++i) {
|
|
1549
|
-
const index = code.indexOf(placeholder);
|
|
1550
|
-
if (index !== -1) {
|
|
1551
|
-
const { uri, original, type, dynamic } = items[i];
|
|
1552
|
-
let value;
|
|
1553
|
-
if (type === 'css') {
|
|
1554
|
-
const asset = this.host?.findAsset(uri);
|
|
1555
|
-
if (asset) {
|
|
1556
|
-
const [relativeUrl, sameDir] = getSrcURL.call(this, bundleMain || file, asset);
|
|
1557
|
-
if (relativeUrl) {
|
|
1558
|
-
value = (sameDir ? './' : '') + relativeUrl;
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
else if (!(dynamic && file.imported !== false)) {
|
|
1563
|
-
value = this.findSourceRoot(uri);
|
|
1564
|
-
}
|
|
1565
|
-
if (!value) {
|
|
1566
|
-
if (i < length - 1) {
|
|
1567
|
-
continue;
|
|
1568
|
-
}
|
|
1569
|
-
value = original;
|
|
1570
|
-
}
|
|
1571
|
-
code = spliceString(code, index, index + placeholder.length, value);
|
|
1572
|
-
modified = true;
|
|
1573
|
-
break;
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
}
|
|
1577
|
-
if (modified) {
|
|
1578
|
-
return code;
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
replaceContent(source, statement, mimeType) {
|
|
1582
|
-
switch (mimeType) {
|
|
1583
|
-
case 'text/css': {
|
|
1584
|
-
const match = /^@import\s+(?:url\((?:[^)]|(?<=\\)\))+\)|"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')(\s*layer(?:\(([^)]*)\)|\b))?(?:\s*supports\(((?:\([^(]+\(|\([^)]+\)|\)[^)]+\)|(?:(?!\))[^(])+|(?:(?!\()[^)])+)+)\))?(.*?);?$/.exec((typeof statement === 'string' ? statement : statement[0]).trim());
|
|
1585
|
-
if (match) {
|
|
1586
|
-
const layer = match[1];
|
|
1587
|
-
const supports = match[3]?.trim();
|
|
1588
|
-
const query = match[4].trim();
|
|
1589
|
-
if (layer || supports || query) {
|
|
1590
|
-
const newline = (0, util_1.getNewline)(source);
|
|
1591
|
-
let result = supports ? `@supports (${match[1].trim()}) {` + newline : '';
|
|
1592
|
-
if (query) {
|
|
1593
|
-
result += `@media ${query} {` + newline;
|
|
1594
|
-
}
|
|
1595
|
-
if (layer) {
|
|
1596
|
-
let name = match[2];
|
|
1597
|
-
result += '@layer ' + (name && (name = name.trim()) ? name + ' ' : '') + `{${newline + source + newline}}` + (query ? newline + '}' : '');
|
|
1598
|
-
}
|
|
1599
|
-
else if (query) {
|
|
1600
|
-
result += source + newline + '}';
|
|
1601
|
-
}
|
|
1602
|
-
if (supports) {
|
|
1603
|
-
result += newline + '}';
|
|
1604
|
-
}
|
|
1605
|
-
return result;
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
break;
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
removeServerRoot(value) {
|
|
1613
|
-
return value.replace(new RegExp('(\\.\\./)*' + (0, types_1.escapePattern)(ChromeDocument.INTERNAL_SERVERROOT), 'g'), '');
|
|
1614
|
-
}
|
|
1615
|
-
addCopy(data, saveAs) {
|
|
1616
|
-
if (data.command && this.host) {
|
|
1617
|
-
const match = REGEXP_SRCSETSIZE.exec(data.command);
|
|
1618
|
-
if (match) {
|
|
1619
|
-
return (0, types_1.renameExt)(this.host.getLocalUri(data), match[1] + match[2].toLowerCase() + '.' + saveAs);
|
|
1620
|
-
}
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
writeImage(data) {
|
|
1624
|
-
const { file, output, command } = data;
|
|
1625
|
-
if (output && command && file.element?.outerXml) {
|
|
1626
|
-
const match = REGEXP_SRCSETSIZE.exec(command);
|
|
1627
|
-
if (match) {
|
|
1628
|
-
(file.srcSet || (file.srcSet = [])).push(toPosix(data.baseDirectory ? output.substring(data.baseDirectory.length + 1) : output), match[1] + match[2].toLowerCase());
|
|
1629
|
-
file.modified = true;
|
|
1630
|
-
return true;
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
return false;
|
|
1634
|
-
}
|
|
1635
|
-
cloudInit({ instance }) {
|
|
1636
|
-
this._cloudUrlMap = Object.create(null);
|
|
1637
|
-
this._cloudUploaded = new Set();
|
|
1638
|
-
this._cloudEndpoint = null;
|
|
1639
|
-
if (this.htmlFile) {
|
|
1640
|
-
const endpoint = instance.getStorage('upload', this.htmlFile.cloudStorage)?.upload?.endpoint;
|
|
1641
|
-
if (endpoint) {
|
|
1642
|
-
this._cloudEndpoint = new RegExp((0, types_1.escapePattern)(toPosix(endpoint)) + '/', 'g');
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
cloudObject(state, file) {
|
|
1647
|
-
if (file.inlineUrlCloud) {
|
|
1648
|
-
this._cloudUrlMap[file.inlineUrlCloud] = file;
|
|
1649
|
-
}
|
|
1650
|
-
return this.editing.includes(file);
|
|
1651
|
-
}
|
|
1652
|
-
cloudUpload({ host }, file, url, active) {
|
|
1653
|
-
if (active) {
|
|
1654
|
-
const endpoint = this._cloudEndpoint;
|
|
1655
|
-
const inlineUrlCloud = file.inlineUrlCloud;
|
|
1656
|
-
const cloudUrl = endpoint ? url.replace(endpoint, '') : url;
|
|
1657
|
-
file.cloudUrl = cloudUrl;
|
|
1658
|
-
if (inlineUrlCloud) {
|
|
1659
|
-
const htmlFile = this.htmlFile;
|
|
1660
|
-
const pattern = new RegExp((0, types_1.escapePattern)(inlineUrlCloud), 'g');
|
|
1661
|
-
for (const item of this.editing) {
|
|
1662
|
-
if (item.inlineUrlCloudMap?.[inlineUrlCloud]) {
|
|
1663
|
-
const source = host.getUTF8String(item);
|
|
1664
|
-
const output = source.replace(pattern, endpoint && item !== htmlFile && cloudUrl.indexOf('/') !== -1 ? url : cloudUrl);
|
|
1665
|
-
if (source !== output) {
|
|
1666
|
-
item.sourceUTF8 = output;
|
|
1667
|
-
item.modified = true;
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
this._cloudUploaded.add(inlineUrlCloud);
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
return Promise.resolve(false);
|
|
1675
|
-
}
|
|
1676
|
-
async cloudFinalize(state) {
|
|
1677
|
-
if (this.aborted) {
|
|
1678
|
-
return Promise.reject((0, types_1.createAbortError)());
|
|
1679
|
-
}
|
|
1680
|
-
const { host, instance, localStorage } = state;
|
|
1681
|
-
const htmlFile = this.htmlFile;
|
|
1682
|
-
const tasks = [];
|
|
1683
|
-
const checkDocument = (item) => {
|
|
1684
|
-
if (item.inlineUrlCloudMap) {
|
|
1685
|
-
const source = host.getUTF8String(item);
|
|
1686
|
-
let output;
|
|
1687
|
-
for (const id in this._cloudUrlMap) {
|
|
1688
|
-
const inlineUrlCloud = item.inlineUrlCloudMap[id];
|
|
1689
|
-
if (inlineUrlCloud && !this._cloudUploaded.has(id)) {
|
|
1690
|
-
output = (output || source).replace(new RegExp((0, types_1.escapePattern)(id), 'g'), inlineUrlCloud);
|
|
1691
|
-
localStorage.delete(this._cloudUrlMap[id]);
|
|
1692
|
-
}
|
|
1693
|
-
}
|
|
1694
|
-
if (output && output !== source) {
|
|
1695
|
-
try {
|
|
1696
|
-
fs.writeFileSync(item.localUri, output, item.encoding || (item.encoding = 'utf-8'));
|
|
1697
|
-
item.sourceUTF8 = output;
|
|
1698
|
-
}
|
|
1699
|
-
catch (err) {
|
|
1700
|
-
host.writeFail(["Unable to write file" /* ERR_MESSAGE.WRITE_FILE */, path.basename(item.localUri)], err, 32 /* LOG_TYPE.FILE */);
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
};
|
|
1705
|
-
const mimeUsed = new Set();
|
|
1706
|
-
for (const files of [this.cssFiles, this.jsFiles, this.svgFiles]) {
|
|
1707
|
-
for (const item of files) {
|
|
1708
|
-
checkDocument(item);
|
|
1709
|
-
if (item.cloudStorage) {
|
|
1710
|
-
if (item.compress) {
|
|
1711
|
-
await host.compressFile(item);
|
|
1712
|
-
}
|
|
1713
|
-
const mimeType = item.mimeType;
|
|
1714
|
-
if (mimeType) {
|
|
1715
|
-
mimeUsed.add(mimeType);
|
|
1716
|
-
}
|
|
1717
|
-
tasks.push(...cloud_1.default.uploadAsset(state, item, mimeType));
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
if (tasks.length) {
|
|
1722
|
-
await Promise.all(tasks);
|
|
1723
|
-
if (this.aborted) {
|
|
1724
|
-
return Promise.reject((0, types_1.createAbortError)());
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
if (htmlFile) {
|
|
1728
|
-
checkDocument(htmlFile);
|
|
1729
|
-
const cloudStorage = htmlFile.cloudStorage;
|
|
1730
|
-
if ((0, types_1.isArray)(cloudStorage)) {
|
|
1731
|
-
for (const storage of cloudStorage) {
|
|
1732
|
-
if (instance.hasCredential('storage', storage)) {
|
|
1733
|
-
const { service, admin, bucket, upload } = storage;
|
|
1734
|
-
const website = admin?.configBucket?.website;
|
|
1735
|
-
if ((0, types_1.isPlainObject)(website) && bucket && upload) {
|
|
1736
|
-
let filename = joinPath(upload.pathname, upload.filename || path.basename(htmlFile.localUri));
|
|
1737
|
-
if (website.indexPage === true) {
|
|
1738
|
-
website.indexPage = filename;
|
|
1739
|
-
filename = '';
|
|
1740
|
-
}
|
|
1741
|
-
if (website.errorPage === true) {
|
|
1742
|
-
website.errorPage = filename;
|
|
1743
|
-
filename = '';
|
|
1744
|
-
}
|
|
1745
|
-
if (website.indexPath === true) {
|
|
1746
|
-
website.indexPath = filename;
|
|
1747
|
-
filename = '';
|
|
1748
|
-
}
|
|
1749
|
-
if (website.errorPath === true) {
|
|
1750
|
-
website.errorPath = filename;
|
|
1751
|
-
}
|
|
1752
|
-
instance.setBucketWebsite(service, instance.getCredential(storage), bucket, website);
|
|
1753
|
-
}
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
if (htmlFile.compress) {
|
|
1757
|
-
await host.compressFile(htmlFile);
|
|
1758
|
-
}
|
|
1759
|
-
return Promise.all(cloud_1.default.uploadAsset(state, htmlFile, 'text/html', true));
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
return [];
|
|
1763
|
-
}
|
|
1764
|
-
watchInit(watch, assets, sanitize) {
|
|
1765
|
-
if (watch.captured || watch.aborted) {
|
|
1766
|
-
return;
|
|
1767
|
-
}
|
|
1768
|
-
const main = watch.main;
|
|
1769
|
-
let result;
|
|
1770
|
-
if (main?.editing && main.mimeType === 'text/html') {
|
|
1771
|
-
const inlineUrlCloudMap = main.inlineUrlCloudMap || {};
|
|
1772
|
-
const using = [];
|
|
1773
|
-
let found;
|
|
1774
|
-
for (let i = 0, length = assets.length, current, upload; i < length; ++i) {
|
|
1775
|
-
const asset = assets[i];
|
|
1776
|
-
if (asset.element && isUnedited(asset)) {
|
|
1777
|
-
continue;
|
|
1778
|
-
}
|
|
1779
|
-
if (!found && (0, asset_1.isEqual)(main, asset)) {
|
|
1780
|
-
found = true;
|
|
1781
|
-
using.push(asset);
|
|
1782
|
-
}
|
|
1783
|
-
else if (isWatched.call(this, asset) ||
|
|
1784
|
-
(0, types_1.watchFlag)(asset.flags) ||
|
|
1785
|
-
asset.base64 && watch.related.find(item => (0, asset_1.isEqual)(item, asset)) ||
|
|
1786
|
-
(0, types_1.isArray)(asset.cloudStorage) && asset.cloudStorage.some(item => (upload = item.upload) && upload.active)) {
|
|
1787
|
-
using.push(asset);
|
|
1788
|
-
}
|
|
1789
|
-
else if (current = watch.assets.find(item => (0, asset_1.isEqual)(item, asset))) {
|
|
1790
|
-
const { inlineUrlCloud: inlineUrlCloud, initialValue = {} } = current;
|
|
1791
|
-
if (inlineUrlCloud && inlineUrlCloudMap[inlineUrlCloud] || path.join(initialValue.pathname || asset.pathname, initialValue.filename || asset.filename).indexOf(ChromeDocument.INTERNAL_ASSIGNUUID) !== -1) {
|
|
1792
|
-
using.push(asset);
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
}
|
|
1796
|
-
if (found) {
|
|
1797
|
-
result = { using };
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
if (sanitize) {
|
|
1801
|
-
ChromeDocument.sanitizeAssets(assets);
|
|
1802
|
-
}
|
|
1803
|
-
return result;
|
|
1804
|
-
}
|
|
1805
|
-
watchModified(watch, assets) {
|
|
1806
|
-
return (files, errors, status) => {
|
|
1807
|
-
if (!watch.server || watch.captured || watch.aborted) {
|
|
1808
|
-
return;
|
|
1809
|
-
}
|
|
1810
|
-
const asset = watch.bundleMain || watch.assets[0];
|
|
1811
|
-
const pathname = (asset.cloudUrl || asset.relativeUrl || '').split('?')[0];
|
|
1812
|
-
let next, value, search;
|
|
1813
|
-
if (assets && (next = assets.find(item => (0, asset_1.isEqual)(item, asset)))) {
|
|
1814
|
-
if (next.cloudUrl) {
|
|
1815
|
-
value = next.cloudUrl;
|
|
1816
|
-
asset.cloudUrl = value;
|
|
1817
|
-
}
|
|
1818
|
-
else if (next.relativeUrl) {
|
|
1819
|
-
value = next.relativeUrl;
|
|
1820
|
-
asset.relativeUrl = value;
|
|
1821
|
-
}
|
|
1822
|
-
if (next.url) {
|
|
1823
|
-
search = next.url.search;
|
|
1824
|
-
}
|
|
1825
|
-
}
|
|
1826
|
-
search ?? (search = restoreSearchParams(asset.url?.search));
|
|
1827
|
-
if (status) {
|
|
1828
|
-
status = status.filter(item => item.type >= types_1.STATUS_TYPE.FATAL && item.type <= types_1.STATUS_TYPE.WARN);
|
|
1829
|
-
}
|
|
1830
|
-
watch.send(types_1.WATCH_EVENT.MODIFIED, {
|
|
1831
|
-
action: pathname && watch.hot && !watch.main ? 'hot' : '',
|
|
1832
|
-
type: asset.mimeType,
|
|
1833
|
-
value,
|
|
1834
|
-
url: { pathname, search },
|
|
1835
|
-
errors,
|
|
1836
|
-
status
|
|
1837
|
-
});
|
|
1838
|
-
};
|
|
1839
|
-
}
|
|
1840
|
-
setElementSrc(file, element, value) {
|
|
1841
|
-
switch (element.tagName) {
|
|
1842
|
-
case 'a':
|
|
1843
|
-
case 'area':
|
|
1844
|
-
case 'base':
|
|
1845
|
-
case 'link':
|
|
1846
|
-
element.setAttribute('href', value);
|
|
1847
|
-
break;
|
|
1848
|
-
case 'image':
|
|
1849
|
-
case 'use':
|
|
1850
|
-
element.setAttribute(element.hasAttribute('xlink:href') ? 'xlink:href' : 'href', value);
|
|
1851
|
-
break;
|
|
1852
|
-
case 'object':
|
|
1853
|
-
element.setAttribute('data', value);
|
|
1854
|
-
break;
|
|
1855
|
-
case 'video':
|
|
1856
|
-
element.setAttribute('poster', value);
|
|
1857
|
-
break;
|
|
1858
|
-
case 'img':
|
|
1859
|
-
case 'source':
|
|
1860
|
-
if ((0, util_1.hasValue)(file.format, 'srcset')) {
|
|
1861
|
-
const srcset = element.getAttribute('srcset');
|
|
1862
|
-
if (srcset) {
|
|
1863
|
-
const htmlFile = this.htmlFile;
|
|
1864
|
-
const uri = toPosix(file.uri);
|
|
1865
|
-
const items = new Set([uri]);
|
|
1866
|
-
const baseHref = getBaseURLs(htmlFile, this.baseUrl);
|
|
1867
|
-
const sameOrigin = hasSameOrigin(file.url || uri, ...baseHref);
|
|
1868
|
-
if (sameOrigin) {
|
|
1869
|
-
const src = element.getAttribute('src');
|
|
1870
|
-
for (const baseUri of baseHref) {
|
|
1871
|
-
let url;
|
|
1872
|
-
if (src && uri === resolvePath(url = toPosix(src), baseUri)) {
|
|
1873
|
-
items.add(url);
|
|
1874
|
-
}
|
|
1875
|
-
items.add(uri.startsWith(this.baseDirectory) ? uri.substring(this.baseDirectory.length) : uri.replace(baseUri.origin, ''));
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
let current = srcset, match;
|
|
1879
|
-
for (const url of items) {
|
|
1880
|
-
const resolve = sameOrigin && !index_1.default.isURL(url);
|
|
1881
|
-
const pathname = url.split(/[\\/]/).map(seg => (0, types_1.escapePattern)(seg)).join('[\\\\/]');
|
|
1882
|
-
const pattern = new RegExp(`(,?\\s*)(${(resolve && url[0] !== '.' ? `(?:\\.\\.[\\\\/])*\\.\\.${pathname}|` : '') + pathname})(` + (url.indexOf('?') === -1 ? '(?:(?!,)(?:[^?]|$)[^,]*)|(?!\\?)[^,]*)' : '[^,]*)'), 'g');
|
|
1883
|
-
while (match = pattern.exec(current)) {
|
|
1884
|
-
const partial = match[2];
|
|
1885
|
-
if (!resolve || baseHref.some(baseUri => uri === resolvePath(partial, baseUri))) {
|
|
1886
|
-
current = replaceMatch(match, current, match[1] + value + match[3], pattern);
|
|
1887
|
-
}
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
element.setAttribute('srcset', current);
|
|
1891
|
-
}
|
|
1892
|
-
break;
|
|
1893
|
-
}
|
|
1894
|
-
default:
|
|
1895
|
-
element.setAttribute('src', value);
|
|
1896
|
-
break;
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
findDataValue(name) {
|
|
1900
|
-
if (this.hasEval('template')) {
|
|
1901
|
-
return this.templateMap.data?.[name];
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
setInlinedAttributes({ host, startTime, hashed, contentMap, bufferMap, productionRelease }) {
|
|
1905
|
-
const readBase64 = (item, uuid) => {
|
|
1906
|
-
if (!contentMap[uuid]) {
|
|
1907
|
-
try {
|
|
1908
|
-
contentMap[uuid] = `data:${item.mimeType};base64,${(item.buffer ? item.buffer.toString('base64') : fs.readFileSync(item.localUri, 'base64')).trim()}`;
|
|
1909
|
-
host.removeAsset(item);
|
|
1910
|
-
}
|
|
1911
|
-
catch (err) {
|
|
1912
|
-
this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, item.filename], err, { type: 32 /* LOG_TYPE.FILE */, startTime });
|
|
1913
|
-
return false;
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
return true;
|
|
1917
|
-
};
|
|
1918
|
-
for (const item of this.assets) {
|
|
1919
|
-
if (item.inlineBase64) {
|
|
1920
|
-
readBase64(item, item.inlineBase64);
|
|
1921
|
-
}
|
|
1922
|
-
else if (!item.invalid && (0, util_1.hasValue)(item.format, 'base64')) {
|
|
1923
|
-
const uuid = (0, types_1.generateUUID)();
|
|
1924
|
-
if (readBase64(item, uuid)) {
|
|
1925
|
-
item.inlineBase64 = uuid;
|
|
1926
|
-
}
|
|
1927
|
-
}
|
|
1928
|
-
if (productionRelease) {
|
|
1929
|
-
const { imported, inlineUrl: inlineUrl, inlineUrlCloud: inlineUrlCloud } = item;
|
|
1930
|
-
if (inlineUrl || inlineUrlCloud) {
|
|
1931
|
-
const filename = createHash(host, item, bufferMap);
|
|
1932
|
-
if (filename) {
|
|
1933
|
-
for (const hash of this.assets) {
|
|
1934
|
-
const url = inlineUrl ? hash.inlineUrlMap?.[inlineUrl] : hash.inlineUrlCloudMap?.[inlineUrlCloud];
|
|
1935
|
-
if (url) {
|
|
1936
|
-
const search = url.indexOf('?');
|
|
1937
|
-
const index = (search !== -1 ? url.substring(0, search) : url).lastIndexOf('/');
|
|
1938
|
-
let result = '';
|
|
1939
|
-
if (index !== -1) {
|
|
1940
|
-
result = url.substring(0, index + 1);
|
|
1941
|
-
}
|
|
1942
|
-
result += filename;
|
|
1943
|
-
if (search !== -1) {
|
|
1944
|
-
result += url.substring(search);
|
|
1945
|
-
}
|
|
1946
|
-
if (inlineUrl) {
|
|
1947
|
-
hash.inlineUrlMap[inlineUrl] = result;
|
|
1948
|
-
}
|
|
1949
|
-
else {
|
|
1950
|
-
hash.inlineUrlCloudMap[inlineUrlCloud] = result;
|
|
1951
|
-
}
|
|
1952
|
-
}
|
|
1953
|
-
}
|
|
1954
|
-
}
|
|
1955
|
-
hashed.add(item);
|
|
1956
|
-
}
|
|
1957
|
-
else if ((!item.editing || imported) && createHash(host, item, bufferMap)) {
|
|
1958
|
-
hashed.add(item);
|
|
1959
|
-
}
|
|
1960
|
-
}
|
|
1961
|
-
}
|
|
1962
|
-
}
|
|
1963
|
-
async applyTransforms(processing) {
|
|
1964
|
-
const { host, hashed, bufferMap, productionRelease } = processing;
|
|
1965
|
-
const sanitizeSource = (item, source) => {
|
|
1966
|
-
if (productionRelease) {
|
|
1967
|
-
replaceCss.call(this, item);
|
|
1968
|
-
}
|
|
1969
|
-
const output = replaceHtml.call(this, source, processing, item.inlineUrlMap);
|
|
1970
|
-
if (source !== output) {
|
|
1971
|
-
item.modified = true;
|
|
1972
|
-
return output;
|
|
1973
|
-
}
|
|
1974
|
-
return source;
|
|
1975
|
-
};
|
|
1976
|
-
const transforms = [];
|
|
1977
|
-
const tasks = [];
|
|
1978
|
-
for (const item of this.svgFiles) {
|
|
1979
|
-
if (isIgnored(item)) {
|
|
1980
|
-
continue;
|
|
1981
|
-
}
|
|
1982
|
-
let source = host.getUTF8String(item);
|
|
1983
|
-
const output = transformURL.call(this, host, item, 'svg', source);
|
|
1984
|
-
if (output) {
|
|
1985
|
-
source = output;
|
|
1986
|
-
item.modified = true;
|
|
1987
|
-
}
|
|
1988
|
-
source = sanitizeSource(item, source);
|
|
1989
|
-
if (item.format) {
|
|
1990
|
-
const result = await this.transform('html', source, item.format, transformOptions.call(this, item, 'image/svg+xml'));
|
|
1991
|
-
if (result) {
|
|
1992
|
-
item.modified = true;
|
|
1993
|
-
source = result.code;
|
|
1994
|
-
}
|
|
1995
|
-
}
|
|
1996
|
-
item.sourceUTF8 = source;
|
|
1997
|
-
if (productionRelease && !hashed.has(item) && createHash(host, item, bufferMap)) {
|
|
1998
|
-
hashed.add(item);
|
|
1999
|
-
}
|
|
2000
|
-
}
|
|
2001
|
-
for (const item of this.cssFiles) {
|
|
2002
|
-
if (isIgnored(item)) {
|
|
2003
|
-
continue;
|
|
2004
|
-
}
|
|
2005
|
-
let source = host.getUTF8String(item), output;
|
|
2006
|
-
if (!(item.bundleIndex >= 0)) {
|
|
2007
|
-
source = host.setAssetContent(item, source);
|
|
2008
|
-
}
|
|
2009
|
-
if ((output = host.getAssetContent(item, source)) && output !== source) {
|
|
2010
|
-
source = output;
|
|
2011
|
-
item.modified = true;
|
|
2012
|
-
}
|
|
2013
|
-
if (!item.preserve && (output = this.removeUnusedStyles(source))) {
|
|
2014
|
-
source = output;
|
|
2015
|
-
item.modified = true;
|
|
2016
|
-
}
|
|
2017
|
-
if (output = transformURL.call(this, host, item, 'css', source)) {
|
|
2018
|
-
source = output;
|
|
2019
|
-
item.modified = true;
|
|
2020
|
-
}
|
|
2021
|
-
source = sanitizeSource(item, source);
|
|
2022
|
-
item.sourceUTF8 = source;
|
|
2023
|
-
if (item.format) {
|
|
2024
|
-
transforms.push(item);
|
|
2025
|
-
tasks.push(this.transform('css', source, item.format, transformOptions.call(this, item, 'text/css', source, host.contentToAppend.get(item.localUri))));
|
|
2026
|
-
}
|
|
2027
|
-
}
|
|
2028
|
-
for (const item of this.jsFiles) {
|
|
2029
|
-
if (isIgnored(item)) {
|
|
2030
|
-
continue;
|
|
2031
|
-
}
|
|
2032
|
-
const { bundleIndex = -1, format } = item;
|
|
2033
|
-
let source = host.getUTF8String(item), output;
|
|
2034
|
-
if (!(bundleIndex >= 0)) {
|
|
2035
|
-
source = host.setAssetContent(item, source);
|
|
2036
|
-
}
|
|
2037
|
-
if ((output = host.getAssetContent(item, source)) && output !== source) {
|
|
2038
|
-
source = output;
|
|
2039
|
-
item.modified = true;
|
|
2040
|
-
}
|
|
2041
|
-
if (output = transformURL.call(this, host, item, 'js', source)) {
|
|
2042
|
-
source = output;
|
|
2043
|
-
item.modified = true;
|
|
2044
|
-
}
|
|
2045
|
-
source = sanitizeSource(item, source);
|
|
2046
|
-
item.sourceUTF8 = source;
|
|
2047
|
-
if (format) {
|
|
2048
|
-
transforms.push(item);
|
|
2049
|
-
tasks.push(this.transform('js', source, format, transformOptions.call(this, item, 'application/javascript', source, host.contentToAppend.get(item.localUri))));
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
return Promise.allSettled(tasks).then(items => {
|
|
2053
|
-
for (let i = 0, length = items.length, value; i < length; ++i) {
|
|
2054
|
-
const item = items[i];
|
|
2055
|
-
if (item.status === 'fulfilled' && (value = item.value)) {
|
|
2056
|
-
const target = transforms[i];
|
|
2057
|
-
if (value.type === 'css') {
|
|
2058
|
-
if (value.map && !target.bundleReplace) {
|
|
2059
|
-
const output = writeSourceMap(target.localUri, value, { mimeType: 'text/css', hash: productionRelease ? target.hash : undefined, emptySources: productionRelease, inlineMap: hasSourceMap(target.metadata, 'inline') });
|
|
2060
|
-
if (output) {
|
|
2061
|
-
host.add(output, target, types_1.FILE_TYPE.SOURCEMAP);
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
target.modified = true;
|
|
2065
|
-
target.sourceUTF8 = value.code;
|
|
2066
|
-
}
|
|
2067
|
-
else {
|
|
2068
|
-
transformJs.call(this, host, target, value);
|
|
2069
|
-
}
|
|
2070
|
-
}
|
|
2071
|
-
}
|
|
2072
|
-
});
|
|
2073
|
-
}
|
|
2074
|
-
async rewriteHtml(processing) {
|
|
2075
|
-
const { host, startTime, cacheMiss, productionRelease } = processing;
|
|
2076
|
-
const { moduleName, config } = this;
|
|
2077
|
-
const htmlFile = this.htmlFile;
|
|
2078
|
-
const localUri = htmlFile.localUri;
|
|
2079
|
-
this.formatMessage(4 /* LOG_TYPE.PROCESS */, 'HTML', ['Rewriting content...', path.dirname(localUri)]);
|
|
2080
|
-
let source = host.getUTF8String(htmlFile, localUri), output;
|
|
2081
|
-
const domBase = new dom_1.DomWriter(moduleName, source, this.elements, { normalize: config.normalizeHtmlOutput, stripComments: config.stripCommentsAndCDATA, ignoreTagGroup: config.ignoreServerCodeBlocks, escapeEntities: config.escapeReservedCharacters });
|
|
2082
|
-
if (config.useUnsafeHtmlReplace) {
|
|
2083
|
-
domBase.ignoreFlag(dom_1.IGNORE_FLAG.INTERIOR);
|
|
2084
|
-
}
|
|
2085
|
-
if (this.watching) {
|
|
2086
|
-
domBase.ignoreFlag(dom_1.IGNORE_FLAG.LOCATOR);
|
|
2087
|
-
}
|
|
2088
|
-
if ((0, types_1.isString)(config.useOriginalHtmlPage)) {
|
|
2089
|
-
domBase.ignoreTag(config.useOriginalHtmlPage);
|
|
2090
|
-
}
|
|
2091
|
-
if ((0, types_1.isArray)(config.ignoreServerCodeBlocks)) {
|
|
2092
|
-
domBase.ignoreTag(config.ignoreServerCodeBlocks);
|
|
2093
|
-
}
|
|
2094
|
-
if (productionRelease) {
|
|
2095
|
-
replaceCss.call(this, htmlFile);
|
|
2096
|
-
}
|
|
2097
|
-
await this.setElementAttributes(processing, domBase);
|
|
2098
|
-
await this.applyDataSource(processing, domBase);
|
|
2099
|
-
for (const item of this.assets) {
|
|
2100
|
-
if (item.element && isRemoved(item) && !(0, types_1.ignoreFlag)(item.flags)) {
|
|
2101
|
-
const domElement = new dom_1.HtmlElement(moduleName, item.element, item.attributes);
|
|
2102
|
-
domElement.remove = true;
|
|
2103
|
-
if (!domBase.write(domElement)) {
|
|
2104
|
-
this.writeFail('Unable to exclude HTML element', errorHtml(item.element), 4 /* LOG_TYPE.PROCESS */);
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
source = removeNamespace(moduleName, domBase.modified ? domBase.close() : source, domBase.newline, domBase.getComments());
|
|
2109
|
-
if (!htmlFile.preserve) {
|
|
2110
|
-
let match;
|
|
2111
|
-
while (match = REGEXP_STYLE.exec(source)) {
|
|
2112
|
-
if (output = this.removeUnusedStyles(match[5])) {
|
|
2113
|
-
source = replaceMatch(match, source, match[1] + output + match[6], REGEXP_STYLE);
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
REGEXP_STYLE.lastIndex = 0;
|
|
2117
|
-
}
|
|
2118
|
-
if (output = transformURL.call(this, host, htmlFile, 'html', source)) {
|
|
2119
|
-
source = output;
|
|
2120
|
-
}
|
|
2121
|
-
source = replaceHtml.call(this, source, processing, htmlFile.inlineUrlMap);
|
|
2122
|
-
if ((0, types_1.isString)(config.stripCommentsAndCDATA)) {
|
|
2123
|
-
source = dom_1.DomWriter.getCommentsAndCDATA(source, config.stripCommentsAndCDATA, true, true);
|
|
2124
|
-
}
|
|
2125
|
-
if (htmlFile.format) {
|
|
2126
|
-
const result = await this.transform('html', source, htmlFile.format, {
|
|
2127
|
-
pathname: path.dirname(localUri),
|
|
2128
|
-
filename: htmlFile.filename,
|
|
2129
|
-
mimeType: 'text/html',
|
|
2130
|
-
metadata: Object.assign({ '__fromhtml__': true, ...this.config }, htmlFile.metadata),
|
|
2131
|
-
cacheData: !productionRelease || this.productionIncremental ? { uri: htmlFile.uri, encoding: htmlFile.encoding } : undefined
|
|
2132
|
-
});
|
|
2133
|
-
if (result) {
|
|
2134
|
-
source = result.code;
|
|
2135
|
-
}
|
|
2136
|
-
}
|
|
2137
|
-
if (domBase.hasErrors()) {
|
|
2138
|
-
const timeStamp = Date.now();
|
|
2139
|
-
domBase.errors.forEach(err => this.addLog(types_1.STATUS_TYPE.WARN, 'dom-writer -> ' + err.message, timeStamp));
|
|
2140
|
-
}
|
|
2141
|
-
if (domBase.failCount > 0) {
|
|
2142
|
-
this.writeFail(['Unable to update document', moduleName], (0, types_1.errorMessage)('html', 'DOM rewrite failed', domBase.failCount + ' errors'), { type: 4 /* LOG_TYPE.PROCESS */, startTime });
|
|
2143
|
-
}
|
|
2144
|
-
else {
|
|
2145
|
-
this.writeTimeProcess('html', `dom-writer (${domBase.modifyCount} modified) -> ` + path.basename(localUri), startTime);
|
|
2146
|
-
if (cacheMiss.length) {
|
|
2147
|
-
const data = {};
|
|
2148
|
-
const message = [];
|
|
2149
|
-
cacheMiss.forEach(name => data[name] = (data[name] || 0) + 1);
|
|
2150
|
-
for (const name in data) {
|
|
2151
|
-
message.push(name + `(${data[name]})`);
|
|
2152
|
-
}
|
|
2153
|
-
this.formatMessage(65536 /* LOG_TYPE.DB */, 'DB', ['Cache statistics', cacheMiss.length + ' missed'], message.join(' - '), { ...index_1.default.LOG_STYLE_NOTICE, hintBold: true });
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
htmlFile.modified = true;
|
|
2157
|
-
htmlFile.sourceUTF8 = source;
|
|
2158
|
-
}
|
|
2159
|
-
async setElementAttributes({ host, startTime, productionRelease }, domBase) {
|
|
2160
|
-
var _a;
|
|
2161
|
-
const { moduleName, htmlFile } = this;
|
|
2162
|
-
const cloud = host.Cloud;
|
|
2163
|
-
const removeWatchReload = (item) => (0, types_1.isObject)(item.watch) && delete item.watch.reload;
|
|
2164
|
-
for (const item of this.assets) {
|
|
2165
|
-
const element = item.element;
|
|
2166
|
-
if (!element || element.removed || isRemoved(item) || isUnedited(item) || (0, types_1.ignoreFlag)(item.flags) && !(0, types_1.processFlag)(item.flags)) {
|
|
2167
|
-
continue;
|
|
2168
|
-
}
|
|
2169
|
-
const domElement = new dom_1.HtmlElement(moduleName, element, item.attributes);
|
|
2170
|
-
if (item.inlineContent) {
|
|
2171
|
-
let [innerXml, sourceMappingURL, inlineMap] = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(item).trim());
|
|
2172
|
-
if (sourceMappingURL && !inlineMap && item.localUri) {
|
|
2173
|
-
let mapUri = path.resolve(sourceMappingURL = decodeURIComponent(sourceMappingURL));
|
|
2174
|
-
if (!isPath(mapUri)) {
|
|
2175
|
-
mapUri = path.join(path.dirname(item.localUri), sourceMappingURL);
|
|
2176
|
-
}
|
|
2177
|
-
host.deleteFile(mapUri);
|
|
2178
|
-
}
|
|
2179
|
-
domElement.tagName = item.inlineContent;
|
|
2180
|
-
domElement.innerXml = innerXml;
|
|
2181
|
-
domElement.removeAttribute('src', 'href');
|
|
2182
|
-
}
|
|
2183
|
-
else {
|
|
2184
|
-
let uri = item.relativeUrl;
|
|
2185
|
-
if ((0, util_1.hasValue)(item.format, 'base64')) {
|
|
2186
|
-
if (item.invalid) {
|
|
2187
|
-
continue;
|
|
2188
|
-
}
|
|
2189
|
-
if (item.inlineBase64) {
|
|
2190
|
-
this.setElementSrc(item, domElement, item.inlineBase64);
|
|
2191
|
-
removeWatchReload(item);
|
|
2192
|
-
uri = '';
|
|
2193
|
-
}
|
|
2194
|
-
}
|
|
2195
|
-
if (uri && !(0, util_1.hasValue)(item.format, 'crossorigin') && item !== htmlFile) {
|
|
2196
|
-
if (cloud?.getStorage('upload', item.cloudStorage)) {
|
|
2197
|
-
const inlineUrlCloud = item.inlineUrlCloud || (item.inlineUrlCloud = (0, types_1.generateUUID)());
|
|
2198
|
-
((_a = htmlFile).inlineUrlCloudMap || (_a.inlineUrlCloudMap = {}))[inlineUrlCloud] = productionRelease ? this.removeServerRoot(uri) : uri;
|
|
2199
|
-
uri = inlineUrlCloud;
|
|
2200
|
-
}
|
|
2201
|
-
if (!(0, util_1.hasValue)(item.format, 'webbundle')) {
|
|
2202
|
-
const { bundleIndex, srcSet } = item;
|
|
2203
|
-
if (bundleIndex === 0 || bundleIndex === -1) {
|
|
2204
|
-
switch (element.tagName) {
|
|
2205
|
-
case 'style':
|
|
2206
|
-
domElement.tagName = 'link';
|
|
2207
|
-
case 'link':
|
|
2208
|
-
domElement.setAttribute('rel', 'stylesheet');
|
|
2209
|
-
break;
|
|
2210
|
-
}
|
|
2211
|
-
domElement.innerXml = '';
|
|
2212
|
-
}
|
|
2213
|
-
this.setElementSrc(item, domElement, uri);
|
|
2214
|
-
if (srcSet) {
|
|
2215
|
-
const length = srcSet.length;
|
|
2216
|
-
let src = domElement.getAttribute('srcset'), i = 0;
|
|
2217
|
-
while (i < length) {
|
|
2218
|
-
src += (src ? ', ' : '') + srcSet[i++] + ' ' + srcSet[i++];
|
|
2219
|
-
}
|
|
2220
|
-
domElement.setAttribute('srcset', src);
|
|
2221
|
-
}
|
|
2222
|
-
}
|
|
2223
|
-
}
|
|
2224
|
-
const detectWidth = domElement.getAttribute('width') === 'detect';
|
|
2225
|
-
const detectHeight = domElement.getAttribute('height') === 'detect';
|
|
2226
|
-
if (detectWidth || detectHeight) {
|
|
2227
|
-
let width = 0, height = 0, buffer = null;
|
|
2228
|
-
if (isImage(item.mimeType) && (buffer = host.getBuffer(item))) {
|
|
2229
|
-
let dimensions;
|
|
2230
|
-
try {
|
|
2231
|
-
dimensions = require('probe-image-size').sync(buffer);
|
|
2232
|
-
}
|
|
2233
|
-
catch {
|
|
2234
|
-
}
|
|
2235
|
-
if (dimensions) {
|
|
2236
|
-
({ width, height } = dimensions);
|
|
2237
|
-
}
|
|
2238
|
-
else {
|
|
2239
|
-
try {
|
|
2240
|
-
({ width, height } = (await require('jimp').read(buffer)).bitmap);
|
|
2241
|
-
}
|
|
2242
|
-
catch {
|
|
2243
|
-
const filename = item.localUri || item.filename;
|
|
2244
|
-
if (filename) {
|
|
2245
|
-
this.addLog(types_1.STATUS_TYPE.WARN, `Could not detect image size (${path.basename(filename)})`);
|
|
2246
|
-
}
|
|
2247
|
-
}
|
|
2248
|
-
}
|
|
2249
|
-
}
|
|
2250
|
-
if (detectWidth) {
|
|
2251
|
-
if (width > 0) {
|
|
2252
|
-
domElement.setAttribute('width', width.toString());
|
|
2253
|
-
}
|
|
2254
|
-
else {
|
|
2255
|
-
domElement.removeAttribute('width');
|
|
2256
|
-
}
|
|
2257
|
-
}
|
|
2258
|
-
if (detectHeight) {
|
|
2259
|
-
if (height > 0) {
|
|
2260
|
-
domElement.setAttribute('height', height.toString());
|
|
2261
|
-
}
|
|
2262
|
-
else {
|
|
2263
|
-
domElement.removeAttribute('height');
|
|
2264
|
-
}
|
|
2265
|
-
}
|
|
2266
|
-
}
|
|
2267
|
-
}
|
|
2268
|
-
if (!domBase.write(domElement)) {
|
|
2269
|
-
this.writeFail(item.inlineContent ? 'Inline tag replacement' : 'Element attribute replacement', errorHtml(element), { type: 4 /* LOG_TYPE.PROCESS */, startTime });
|
|
2270
|
-
delete item.inlineUrlCloud;
|
|
2271
|
-
}
|
|
2272
|
-
else if (item.inlineContent) {
|
|
2273
|
-
host.removeAsset(item);
|
|
2274
|
-
removeWatchReload(item);
|
|
2275
|
-
}
|
|
2276
|
-
}
|
|
2277
|
-
}
|
|
2278
|
-
async applyDataSource({ host, startTime, cacheMiss }, domBase) {
|
|
2279
|
-
if (this.dataSource.length === 0) {
|
|
2280
|
-
return;
|
|
2281
|
-
}
|
|
2282
|
-
const { moduleName, Db: db } = this;
|
|
2283
|
-
const cloud = host.Cloud;
|
|
2284
|
-
const sessionKey = (0, types_1.generateUUID)();
|
|
2285
|
-
const cacheData = Object.create(null);
|
|
2286
|
-
const dataItems = [];
|
|
2287
|
-
const displayItems = [];
|
|
2288
|
-
this.dataSource.forEach(item => item.type === 'display' ? displayItems.push(item) : dataItems.push(item));
|
|
2289
|
-
const removeElement = (item, element) => {
|
|
2290
|
-
if (item.removeEmpty || item.type === 'display') {
|
|
2291
|
-
(element || (element = new dom_1.HtmlElement(moduleName, item.element))).remove = true;
|
|
2292
|
-
if (!domBase.write(element)) {
|
|
2293
|
-
this.writeFail('Unable to remove element', errorHtml(item.element), { type: 4 /* LOG_TYPE.PROCESS */, startTime });
|
|
2294
|
-
}
|
|
2295
|
-
}
|
|
2296
|
-
};
|
|
2297
|
-
const errorCredential = (item, err) => {
|
|
2298
|
-
removeElement(item);
|
|
2299
|
-
const pkg = getPackageName(err, item.source);
|
|
2300
|
-
if (!(pkg && this.checkPackage(err, pkg))) {
|
|
2301
|
-
this.writeFail(["Invalid credentials" /* ERR_DB.CREDENTIALS */, item.source], err);
|
|
2302
|
-
}
|
|
2303
|
-
};
|
|
2304
|
-
const checkObject = (item, data) => {
|
|
2305
|
-
const { query, cascade } = item;
|
|
2306
|
-
if ((0, types_1.isString)(cascade)) {
|
|
2307
|
-
const result = data && (0, types_1.cascadeObject)(data, cascade, data);
|
|
2308
|
-
if (result !== data) {
|
|
2309
|
-
data = result;
|
|
2310
|
-
}
|
|
2311
|
-
else if (item.fallback !== undefined) {
|
|
2312
|
-
data = item.fallback;
|
|
2313
|
-
}
|
|
2314
|
-
else if (!(0, types_1.isString)(query)) {
|
|
2315
|
-
return null;
|
|
2316
|
-
}
|
|
2317
|
-
}
|
|
2318
|
-
if (data) {
|
|
2319
|
-
if ((0, types_1.isString)(query) && item.source !== 'mongodb') {
|
|
2320
|
-
const pkg = query[0] === '$' ? 'jsonpath' : 'jmespath';
|
|
2321
|
-
try {
|
|
2322
|
-
if (pkg === 'jsonpath') {
|
|
2323
|
-
data = require(pkg).query(data, query);
|
|
2324
|
-
}
|
|
2325
|
-
else {
|
|
2326
|
-
data = require(pkg).search(data, query);
|
|
2327
|
-
}
|
|
2328
|
-
}
|
|
2329
|
-
catch (err) {
|
|
2330
|
-
this.abort(item.source);
|
|
2331
|
-
this.checkPackage(err, pkg, ["Unable to filter results" /* ERR_DB.FILTER_QUERY */, item.source]);
|
|
2332
|
-
}
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
return Array.isArray(data) ? data : (0, types_1.isObject)(data) ? [data] : null;
|
|
2336
|
-
};
|
|
2337
|
-
const setElements = async (sourceSet) => {
|
|
2338
|
-
const batchMap = Object.create(null);
|
|
2339
|
-
const batchGroup = [];
|
|
2340
|
-
for (const item of sourceSet) {
|
|
2341
|
-
if (!item.element) {
|
|
2342
|
-
this.addLog(types_1.STATUS_TYPE.WARN, `Missing target element {${JSON.stringify(item)}}`);
|
|
2343
|
-
continue;
|
|
2344
|
-
}
|
|
2345
|
-
const type = item.source;
|
|
2346
|
-
switch (type) {
|
|
2347
|
-
case 'cloud': {
|
|
2348
|
-
const { service, credential } = item;
|
|
2349
|
-
if (cloud) {
|
|
2350
|
-
const key = service + '_' + (service === 'atlas' && item.uri || '') + '_' + asString(credential, true);
|
|
2351
|
-
(batchMap[key] || (batchMap[key] = [])).push(item);
|
|
2352
|
-
}
|
|
2353
|
-
else {
|
|
2354
|
-
errorCredential(item, (0, types_1.errorValue)("Cloud module not installed" /* ERR_CLOUD.MODULE_NOTFOUND */, service));
|
|
2355
|
-
}
|
|
2356
|
-
break;
|
|
2357
|
-
}
|
|
2358
|
-
case 'uri':
|
|
2359
|
-
case 'local':
|
|
2360
|
-
case 'export':
|
|
2361
|
-
batchGroup.push([item]);
|
|
2362
|
-
break;
|
|
2363
|
-
default:
|
|
2364
|
-
if (db?.hasSource(type)) {
|
|
2365
|
-
try {
|
|
2366
|
-
await db.setCredential(item);
|
|
2367
|
-
const credential = item.credential;
|
|
2368
|
-
let key;
|
|
2369
|
-
switch (type) {
|
|
2370
|
-
case 'mongodb':
|
|
2371
|
-
key = core_1.ClientDb.keyOfResult(item.uri || type, credential);
|
|
2372
|
-
break;
|
|
2373
|
-
case 'redis':
|
|
2374
|
-
key = credential && (key = core_1.ClientDb.keyOfResult(type, credential, true)) ? key : JSON.stringify(item.options.client);
|
|
2375
|
-
break;
|
|
2376
|
-
default:
|
|
2377
|
-
key = core_1.ClientDb.keyOfResult(type, credential);
|
|
2378
|
-
break;
|
|
2379
|
-
}
|
|
2380
|
-
(batchMap[key] || (batchMap[key] = [])).push(item);
|
|
2381
|
-
}
|
|
2382
|
-
catch (err) {
|
|
2383
|
-
errorCredential(item, err);
|
|
2384
|
-
}
|
|
2385
|
-
}
|
|
2386
|
-
else {
|
|
2387
|
-
errorCredential(item, (0, types_1.errorValue)(db ? "Database provider not found" /* ERR_DB.PROVIDER_NOTFOUND */ : "Db module not installed" /* ERR_DB.MODULE_NOTFOUND */, type));
|
|
2388
|
-
}
|
|
2389
|
-
break;
|
|
2390
|
-
}
|
|
2391
|
-
}
|
|
2392
|
-
for (const key in batchMap) {
|
|
2393
|
-
batchGroup.push(batchMap[key]);
|
|
2394
|
-
}
|
|
2395
|
-
return this.allSettled(batchGroup.map(batch => {
|
|
2396
|
-
return new Promise(async (resolve, reject) => {
|
|
2397
|
-
const errorRemove = (item, reason) => {
|
|
2398
|
-
removeElement(item);
|
|
2399
|
-
reject(reason);
|
|
2400
|
-
};
|
|
2401
|
-
const errorClient = (item, reason) => {
|
|
2402
|
-
removeElement(item);
|
|
2403
|
-
if (reason) {
|
|
2404
|
-
this.writeFail(["Unable to configure client" /* ERR_DB.CLIENT */, item.source], reason);
|
|
2405
|
-
}
|
|
2406
|
-
reject();
|
|
2407
|
-
};
|
|
2408
|
-
const length = batch.length;
|
|
2409
|
-
const current = batch[0];
|
|
2410
|
-
const type = current.source;
|
|
2411
|
-
let result = new Array(length);
|
|
2412
|
-
switch (type) {
|
|
2413
|
-
case 'cloud':
|
|
2414
|
-
result = await cloud.getDatabaseBatchRows(batch, true, sessionKey).catch(err => {
|
|
2415
|
-
this.abort(type);
|
|
2416
|
-
if (err instanceof Error) {
|
|
2417
|
-
cloud.addLog(this.aborted ? types_1.STATUS_TYPE.ERROR : types_1.STATUS_TYPE.WARN, err);
|
|
2418
|
-
}
|
|
2419
|
-
return [];
|
|
2420
|
-
});
|
|
2421
|
-
break;
|
|
2422
|
-
case 'uri':
|
|
2423
|
-
case 'local': {
|
|
2424
|
-
const { ignoreCache, encoding = 'utf-8', options } = current;
|
|
2425
|
-
let content, target, data, cacheKey;
|
|
2426
|
-
const addDownload = () => typeof content === 'string' && host.addDownload(Buffer.byteLength(content, encoding));
|
|
2427
|
-
if (type === 'local') {
|
|
2428
|
-
let location;
|
|
2429
|
-
({ pathname: target } = current);
|
|
2430
|
-
if (target && ((location = this.resolveDir('data', target)) || host.canRead(location = path.resolve(target), { ownPermissionOnly: true }))) {
|
|
2431
|
-
if (!ignoreCache && CACHE_DBRESULT.has(location)) {
|
|
2432
|
-
data = getCacheItem(CACHE_DBRESULT, location);
|
|
2433
|
-
}
|
|
2434
|
-
else {
|
|
2435
|
-
if (ignoreCache === 1) {
|
|
2436
|
-
CACHE_DBRESULT.delete(location);
|
|
2437
|
-
}
|
|
2438
|
-
if (!(data = cacheData[location])) {
|
|
2439
|
-
try {
|
|
2440
|
-
content = fs.readFileSync(location, encoding);
|
|
2441
|
-
cacheKey = location;
|
|
2442
|
-
addDownload();
|
|
2443
|
-
}
|
|
2444
|
-
catch (err) {
|
|
2445
|
-
this.abort(type);
|
|
2446
|
-
this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(location)], err, { type: 32 /* LOG_TYPE.FILE */, startTime });
|
|
2447
|
-
errorRemove(current);
|
|
2448
|
-
return;
|
|
2449
|
-
}
|
|
2450
|
-
}
|
|
2451
|
-
}
|
|
2452
|
-
}
|
|
2453
|
-
else {
|
|
2454
|
-
this.abort(type);
|
|
2455
|
-
errorRemove(current, target ? errorDataSource('Not found', target) : errorDataSource('Not defined - ' + (this.settings.directory?.data ? 'file' : 'directory'), type));
|
|
2456
|
-
return;
|
|
2457
|
-
}
|
|
2458
|
-
}
|
|
2459
|
-
else if (!(0, types_1.isString)(target = current.uri)) {
|
|
2460
|
-
this.abort(type);
|
|
2461
|
-
errorRemove(current, errorDataSource('Not defined', type));
|
|
2462
|
-
return;
|
|
2463
|
-
}
|
|
2464
|
-
else if (index_1.default.isURL(target, 'file')) {
|
|
2465
|
-
if (!ignoreCache && CACHE_DBRESULT.has(target)) {
|
|
2466
|
-
data = getCacheItem(CACHE_DBRESULT, target);
|
|
2467
|
-
}
|
|
2468
|
-
else {
|
|
2469
|
-
if (ignoreCache === 1) {
|
|
2470
|
-
CACHE_DBRESULT.delete(target);
|
|
2471
|
-
}
|
|
2472
|
-
if (!(data = cacheData[target])) {
|
|
2473
|
-
try {
|
|
2474
|
-
content = await host.fetchBuffer(target, { encoding });
|
|
2475
|
-
if (Buffer.isBuffer(content)) {
|
|
2476
|
-
content = content.toString('utf-8');
|
|
2477
|
-
}
|
|
2478
|
-
cacheKey = target;
|
|
2479
|
-
}
|
|
2480
|
-
catch (err) {
|
|
2481
|
-
this.abort(type);
|
|
2482
|
-
this.writeFail(["Unable to download file" /* ERR_MESSAGE.DOWNLOAD_FILE */, target], err, { type: 1024 /* LOG_TYPE.HTTP */, startTime });
|
|
2483
|
-
errorRemove(current);
|
|
2484
|
-
return;
|
|
2485
|
-
}
|
|
2486
|
-
}
|
|
2487
|
-
}
|
|
2488
|
-
}
|
|
2489
|
-
else {
|
|
2490
|
-
const pathname = index_1.default.resolveFile(target);
|
|
2491
|
-
if (!ignoreCache && CACHE_DBRESULT.has(pathname)) {
|
|
2492
|
-
data = getCacheItem(CACHE_DBRESULT, pathname);
|
|
2493
|
-
}
|
|
2494
|
-
else {
|
|
2495
|
-
if (ignoreCache === 1) {
|
|
2496
|
-
CACHE_DBRESULT.delete(pathname);
|
|
2497
|
-
}
|
|
2498
|
-
if (!(data = cacheData[pathname])) {
|
|
2499
|
-
if (!host.canRead(pathname, { ownPermissionOnly: true })) {
|
|
2500
|
-
this.abort(type);
|
|
2501
|
-
errorRemove(current, errorDataSource('Access denied', pathname));
|
|
2502
|
-
return;
|
|
2503
|
-
}
|
|
2504
|
-
try {
|
|
2505
|
-
content = fs.readFileSync(pathname, encoding);
|
|
2506
|
-
cacheKey = pathname;
|
|
2507
|
-
addDownload();
|
|
2508
|
-
}
|
|
2509
|
-
catch (err) {
|
|
2510
|
-
this.abort(type);
|
|
2511
|
-
this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(pathname)], err, { type: 32 /* LOG_TYPE.FILE */, startTime });
|
|
2512
|
-
errorRemove(current);
|
|
2513
|
-
return;
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
}
|
|
2517
|
-
}
|
|
2518
|
-
if ((0, types_1.isString)(content)) {
|
|
2519
|
-
const { format = path.extname(target).substring(1) } = current;
|
|
2520
|
-
try {
|
|
2521
|
-
data = this.tryParse(content, format, options);
|
|
2522
|
-
}
|
|
2523
|
-
catch (err) {
|
|
2524
|
-
this.abort(type);
|
|
2525
|
-
this.writeFail(['Unable to parse data source', format], err, { type: 4 /* LOG_TYPE.PROCESS */, startTime });
|
|
2526
|
-
errorRemove(current);
|
|
2527
|
-
return;
|
|
2528
|
-
}
|
|
2529
|
-
if (data && cacheKey) {
|
|
2530
|
-
setCacheData.call(this, current, data, cacheKey, cacheData);
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
if (!data) {
|
|
2534
|
-
this.abort(type);
|
|
2535
|
-
errorRemove(current, errorDataSource(content !== null ? 'Invalid response' : 'Empty response', target));
|
|
2536
|
-
return;
|
|
2537
|
-
}
|
|
2538
|
-
if ((result[0] = checkObject(current, data)) === null) {
|
|
2539
|
-
this.abort(type);
|
|
2540
|
-
errorRemove(current, errorDataSource('Invalid ' + (current.query ? 'query' : 'URI'), target));
|
|
2541
|
-
return;
|
|
2542
|
-
}
|
|
2543
|
-
if (this.settingsOf(type, 'coerce') === true) {
|
|
2544
|
-
(0, types_1.coerceObject)(result[0]);
|
|
2545
|
-
}
|
|
2546
|
-
break;
|
|
2547
|
-
}
|
|
2548
|
-
case 'export': {
|
|
2549
|
-
const ignoreCache = current.ignoreCache;
|
|
2550
|
-
const cacheKey = asString(current, true);
|
|
2551
|
-
if (!current.ignoreCache && CACHE_DBRESULT.has(cacheKey)) {
|
|
2552
|
-
result[0] = getCacheItem(CACHE_DBRESULT, cacheKey);
|
|
2553
|
-
}
|
|
2554
|
-
else {
|
|
2555
|
-
if (ignoreCache === 1) {
|
|
2556
|
-
CACHE_DBRESULT.delete(cacheKey);
|
|
2557
|
-
}
|
|
2558
|
-
if (cacheKey in cacheData) {
|
|
2559
|
-
result[0] = cacheData[cacheKey];
|
|
2560
|
-
}
|
|
2561
|
-
else {
|
|
2562
|
-
let { pathname, execute, params } = current, data, target, getData, hint;
|
|
2563
|
-
if (typeof execute === 'function') {
|
|
2564
|
-
target = execute;
|
|
2565
|
-
}
|
|
2566
|
-
else if (typeof pathname === 'function') {
|
|
2567
|
-
target = pathname;
|
|
2568
|
-
}
|
|
2569
|
-
else if ((0, types_1.isString)(pathname)) {
|
|
2570
|
-
if ((pathname = pathname.trim()).startsWith('npm:')) {
|
|
2571
|
-
target = pathname;
|
|
2572
|
-
hint = pathname;
|
|
2573
|
-
}
|
|
2574
|
-
else if ((target = this.resolveDir(type, pathname)) && (getData = core_1.ClientDb.parseFunction(target, true))) {
|
|
2575
|
-
hint = pathname;
|
|
2576
|
-
}
|
|
2577
|
-
else {
|
|
2578
|
-
target = undefined;
|
|
2579
|
-
}
|
|
2580
|
-
}
|
|
2581
|
-
if (!getData) {
|
|
2582
|
-
const { settings, encoding, persist = true } = current;
|
|
2583
|
-
if (!target) {
|
|
2584
|
-
target = settings && this.settings.export?.[settings] || pathname;
|
|
2585
|
-
}
|
|
2586
|
-
if (typeof target === 'function') {
|
|
2587
|
-
getData = target;
|
|
2588
|
-
hint = target.name;
|
|
2589
|
-
}
|
|
2590
|
-
else if ((0, types_1.isString)(target)) {
|
|
2591
|
-
getData = this.asSourceFile(target, { encoding, persist });
|
|
2592
|
-
hint = target;
|
|
2593
|
-
}
|
|
2594
|
-
}
|
|
2595
|
-
if (typeof getData !== 'function') {
|
|
2596
|
-
errorRemove(current, target ? errorDataSource('Not a function', hint) : errorDataSource('Not defined - pathname | settings', type));
|
|
2597
|
-
return;
|
|
2598
|
-
}
|
|
2599
|
-
try {
|
|
2600
|
-
if (params && this.settingsOf(type, 'coerce') === true) {
|
|
2601
|
-
(0, types_1.coerceObject)(params);
|
|
2602
|
-
}
|
|
2603
|
-
// @ts-ignore
|
|
2604
|
-
if (getData["__cjs__" /* INTERNAL.CJS */]) {
|
|
2605
|
-
data = await getData(params);
|
|
2606
|
-
}
|
|
2607
|
-
else {
|
|
2608
|
-
const thisArg = index_1.default.enabled("node.process.inline" /* KEY_NAME.NODE_PROCESS_INLINE */) ? process : null;
|
|
2609
|
-
const inline = index_1.default.enabled("node.require.inline" /* KEY_NAME.NODE_REQUIRE_INLINE */);
|
|
2610
|
-
const args = [params];
|
|
2611
|
-
if (getData.toString().startsWith('async')) {
|
|
2612
|
-
if (inline) {
|
|
2613
|
-
args.push(require);
|
|
2614
|
-
}
|
|
2615
|
-
data = await getData.apply(thisArg, args);
|
|
2616
|
-
}
|
|
2617
|
-
else {
|
|
2618
|
-
data = await new Promise(success => {
|
|
2619
|
-
args.push(success);
|
|
2620
|
-
if (inline) {
|
|
2621
|
-
args.push(require);
|
|
2622
|
-
}
|
|
2623
|
-
getData.apply(thisArg, args);
|
|
2624
|
-
});
|
|
2625
|
-
}
|
|
2626
|
-
}
|
|
2627
|
-
setCacheData.call(this, current, data, cacheKey, cacheData);
|
|
2628
|
-
}
|
|
2629
|
-
catch (err) {
|
|
2630
|
-
this.abort(type);
|
|
2631
|
-
this.writeFail(['Unable to retrieve data source', hint], err, { type: 4 /* LOG_TYPE.PROCESS */, startTime });
|
|
2632
|
-
errorRemove(current);
|
|
2633
|
-
return;
|
|
2634
|
-
}
|
|
2635
|
-
if ((result[0] = checkObject(current, data)) === null) {
|
|
2636
|
-
this.abort(type);
|
|
2637
|
-
errorRemove(current, errorDataSource('Invalid ' + (current.query ? 'query' : 'params'), hint));
|
|
2638
|
-
return;
|
|
2639
|
-
}
|
|
2640
|
-
}
|
|
2641
|
-
}
|
|
2642
|
-
break;
|
|
2643
|
-
}
|
|
2644
|
-
default:
|
|
2645
|
-
if (db?.hasSource(type)) {
|
|
2646
|
-
switch (type) {
|
|
2647
|
-
case 'mongodb':
|
|
2648
|
-
for (let j = 0; j < length; ++j) {
|
|
2649
|
-
const cmd = batch[j];
|
|
2650
|
-
cmd.cacheObjectKey = typeof cmd.cascade === 'string' ? cmd.cascade : '';
|
|
2651
|
-
}
|
|
2652
|
-
break;
|
|
2653
|
-
case 'redis':
|
|
2654
|
-
for (let j = 0; j < length; ++j) {
|
|
2655
|
-
const cmd = batch[j];
|
|
2656
|
-
const { search, key, query, cascade } = cmd;
|
|
2657
|
-
if ((0, types_1.isObject)(search) && typeof search.schema === 'string') {
|
|
2658
|
-
const pathname = this.resolveDir('schema', search.schema);
|
|
2659
|
-
if (pathname) {
|
|
2660
|
-
const ignoreCache = cmd.ignoreCache;
|
|
2661
|
-
if (!ignoreCache && CACHE_LOCALFILE.has(pathname)) {
|
|
2662
|
-
search.schema = getCacheItem(CACHE_LOCALFILE, pathname);
|
|
2663
|
-
}
|
|
2664
|
-
else {
|
|
2665
|
-
if (ignoreCache === 1) {
|
|
2666
|
-
CACHE_LOCALFILE.delete(pathname);
|
|
2667
|
-
}
|
|
2668
|
-
if (!(search.schema = cacheData[pathname])) {
|
|
2669
|
-
try {
|
|
2670
|
-
search.schema = loadLocalFile.call(this, current, pathname, cacheData, cmd.encoding);
|
|
2671
|
-
}
|
|
2672
|
-
catch (err) {
|
|
2673
|
-
this.writeFail(['Unable to parse document', path.basename(pathname)], err, { startTime });
|
|
2674
|
-
search.schema = undefined;
|
|
2675
|
-
}
|
|
2676
|
-
}
|
|
2677
|
-
}
|
|
2678
|
-
}
|
|
2679
|
-
else {
|
|
2680
|
-
search.schema = undefined;
|
|
2681
|
-
}
|
|
2682
|
-
}
|
|
2683
|
-
if (key) {
|
|
2684
|
-
cmd.cacheObjectKey = ((0, types_1.isString)(cascade) ? cascade : '') + '_' + ((0, types_1.isString)(query) ? query : '');
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
|
-
break;
|
|
2688
|
-
default:
|
|
2689
|
-
if (db.hasSource(type, db.sourceType.SQL)) {
|
|
2690
|
-
for (let j = 0; j < length; ++j) {
|
|
2691
|
-
const cmd = batch[j];
|
|
2692
|
-
const query = cmd.query;
|
|
2693
|
-
if (typeof query === 'string' && query.endsWith('.sql')) {
|
|
2694
|
-
const pathname = this.resolveDir('sql', query);
|
|
2695
|
-
try {
|
|
2696
|
-
if (pathname) {
|
|
2697
|
-
const ignoreCache = cmd.ignoreCache;
|
|
2698
|
-
if (!ignoreCache && CACHE_LOCALFILE.has(pathname)) {
|
|
2699
|
-
cmd.query = getCacheItem(CACHE_LOCALFILE, pathname);
|
|
2700
|
-
}
|
|
2701
|
-
else {
|
|
2702
|
-
if (ignoreCache === 1) {
|
|
2703
|
-
CACHE_LOCALFILE.delete(pathname);
|
|
2704
|
-
}
|
|
2705
|
-
if (!(cmd.query = cacheData[pathname])) {
|
|
2706
|
-
const out = { content: '' };
|
|
2707
|
-
try {
|
|
2708
|
-
cmd.query = loadLocalFile.call(this, current, pathname, cacheData, cmd.encoding, out);
|
|
2709
|
-
}
|
|
2710
|
-
catch {
|
|
2711
|
-
setCacheData.call(this, current, cmd.query = out.content, pathname, cacheData, true);
|
|
2712
|
-
}
|
|
2713
|
-
}
|
|
2714
|
-
}
|
|
2715
|
-
}
|
|
2716
|
-
else {
|
|
2717
|
-
throw (0, types_1.errorMessage)(type, "File not found" /* ERR_MESSAGE.NOTFOUND_FILE */, query);
|
|
2718
|
-
}
|
|
2719
|
-
}
|
|
2720
|
-
catch (err) {
|
|
2721
|
-
this.abort(type);
|
|
2722
|
-
this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, pathname ? path.basename(pathname) : query], err, { startTime });
|
|
2723
|
-
errorRemove(current);
|
|
2724
|
-
return;
|
|
2725
|
-
}
|
|
2726
|
-
}
|
|
2727
|
-
}
|
|
2728
|
-
}
|
|
2729
|
-
break;
|
|
2730
|
-
}
|
|
2731
|
-
try {
|
|
2732
|
-
let coerce, cache;
|
|
2733
|
-
if (type === 'mongodb' || type === 'redis') {
|
|
2734
|
-
coerce = this.settingsOf(type, 'coerce');
|
|
2735
|
-
cache = this.settingsOf(type, 'cache');
|
|
2736
|
-
}
|
|
2737
|
-
const errorQuery = (err, data, commandType) => {
|
|
2738
|
-
let message, aborting = true;
|
|
2739
|
-
if (db.hasSource(type, db.sourceType.DOCUMENT)) {
|
|
2740
|
-
message = (data.name ? data.name + ': ' : '') + (data.table || '');
|
|
2741
|
-
}
|
|
2742
|
-
else if (db.hasSource(type, db.sourceType.KEYVALUE)) {
|
|
2743
|
-
aborting = commandType !== db.commandType.UPDATE;
|
|
2744
|
-
message = asString(data.search || data.key);
|
|
2745
|
-
}
|
|
2746
|
-
else {
|
|
2747
|
-
const credential = data.credential;
|
|
2748
|
-
if ((0, types_1.isPlainObject)(credential)) {
|
|
2749
|
-
message = credential.database;
|
|
2750
|
-
}
|
|
2751
|
-
}
|
|
2752
|
-
if (data.willAbort) {
|
|
2753
|
-
this.abort();
|
|
2754
|
-
}
|
|
2755
|
-
else if (aborting) {
|
|
2756
|
-
this.abort(type);
|
|
2757
|
-
}
|
|
2758
|
-
if (err) {
|
|
2759
|
-
this.writeFail(["Unable to execute query" /* ERR_DB.EXEC_QUERY */, message || "Unknown" /* ERR_MESSAGE.UNKNOWN */], err, { type: 65536 /* LOG_TYPE.DB */, startTime });
|
|
2760
|
-
}
|
|
2761
|
-
return this.aborted;
|
|
2762
|
-
};
|
|
2763
|
-
const options = { coerce, cache, checkObject, sessionKey, connectOnce: length > 1, outCacheMiss: cacheMiss, errorQuery };
|
|
2764
|
-
result = await db.executeBatchQuery(batch, options, result);
|
|
2765
|
-
}
|
|
2766
|
-
catch (err) {
|
|
2767
|
-
this.abort(type);
|
|
2768
|
-
const pkg = getPackageName(err, type);
|
|
2769
|
-
errorClient(current, pkg && this.checkPackage(err, pkg) ? null : err);
|
|
2770
|
-
}
|
|
2771
|
-
break;
|
|
2772
|
-
}
|
|
2773
|
-
errorRemove(current, errorDataSource('Not found', type || "Unknown" /* ERR_MESSAGE.UNKNOWN */));
|
|
2774
|
-
return;
|
|
2775
|
-
}
|
|
2776
|
-
if (this.aborted) {
|
|
2777
|
-
resolve();
|
|
2778
|
-
return;
|
|
2779
|
-
}
|
|
2780
|
-
for (let i = 0, items; i < length; ++i) {
|
|
2781
|
-
const item = batch[i];
|
|
2782
|
-
const { index, limit, ignoreEmpty, postQuery, whenEmpty } = item;
|
|
2783
|
-
const empty = (items = result[i]) === null;
|
|
2784
|
-
if ((items || (items = [])).length === 0) {
|
|
2785
|
-
if (whenEmpty) {
|
|
2786
|
-
const data = await checkData.call(this, item, whenEmpty, items, row => Array.isArray(row));
|
|
2787
|
-
if (data) {
|
|
2788
|
-
items = data;
|
|
2789
|
-
item.transactionFail = false;
|
|
2790
|
-
}
|
|
2791
|
-
}
|
|
2792
|
-
if (ignoreEmpty && items.length === 0) {
|
|
2793
|
-
continue;
|
|
2794
|
-
}
|
|
2795
|
-
}
|
|
2796
|
-
if (index !== undefined) {
|
|
2797
|
-
const data = items[index];
|
|
2798
|
-
items = data ? [data] : [];
|
|
2799
|
-
}
|
|
2800
|
-
else if (limit !== undefined && limit > 0 && items.length > limit) {
|
|
2801
|
-
items = items.slice(0, limit);
|
|
2802
|
-
}
|
|
2803
|
-
if (postQuery) {
|
|
2804
|
-
const data = await checkData.call(this, item, postQuery, items = items.slice(0), row => Array.isArray(row));
|
|
2805
|
-
if (data) {
|
|
2806
|
-
items = data;
|
|
2807
|
-
}
|
|
2808
|
-
}
|
|
2809
|
-
if (items.length && !item.transactionFail) {
|
|
2810
|
-
const { element, preRender } = item;
|
|
2811
|
-
const domElement = new dom_1.HtmlElement(moduleName, element);
|
|
2812
|
-
let errors, value = '';
|
|
2813
|
-
const checkValue = async (name) => {
|
|
2814
|
-
const data = await checkData.call(this, item, name, value, row => typeof row === 'string');
|
|
2815
|
-
if (data) {
|
|
2816
|
-
value = data;
|
|
2817
|
-
}
|
|
2818
|
-
};
|
|
2819
|
-
const valueAsString = (data, joinString) => Array.isArray(data) && !data.some(child => typeof child === 'object') ? data.join(joinString) : asString(data);
|
|
2820
|
-
if (item.template) {
|
|
2821
|
-
const pathname = this.resolveDir('template', item.template);
|
|
2822
|
-
if (pathname) {
|
|
2823
|
-
const ignoreCache = item.ignoreCache;
|
|
2824
|
-
if (!ignoreCache && CACHE_LOCALFILE.has(pathname)) {
|
|
2825
|
-
item.value = getCacheItem(CACHE_LOCALFILE, pathname);
|
|
2826
|
-
}
|
|
2827
|
-
else {
|
|
2828
|
-
if (ignoreCache === 1) {
|
|
2829
|
-
CACHE_LOCALFILE.delete(pathname);
|
|
2830
|
-
}
|
|
2831
|
-
if (!(item.value = cacheData[pathname])) {
|
|
2832
|
-
try {
|
|
2833
|
-
item.value = fs.readFileSync(pathname, item.encoding || 'utf-8');
|
|
2834
|
-
setCacheData.call(this, item, item.value, pathname, cacheData, true);
|
|
2835
|
-
}
|
|
2836
|
-
catch (err) {
|
|
2837
|
-
this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(pathname)], err, { type: 32 /* LOG_TYPE.FILE */, startTime });
|
|
2838
|
-
errors = true;
|
|
2839
|
-
}
|
|
2840
|
-
}
|
|
2841
|
-
}
|
|
2842
|
-
}
|
|
2843
|
-
else {
|
|
2844
|
-
errors = true;
|
|
2845
|
-
}
|
|
2846
|
-
}
|
|
2847
|
-
invalid: {
|
|
2848
|
-
switch (item.type) {
|
|
2849
|
-
case 'text': {
|
|
2850
|
-
const template = item.value || item.dynamic && element.innerXml || element.textContent || domElement.innerXml;
|
|
2851
|
-
if (typeof template === 'string' && !domElement.tagVoid) {
|
|
2852
|
-
if (item.viewEngine) {
|
|
2853
|
-
const content = await this.parseTemplate(item.viewEngine, template, items);
|
|
2854
|
-
if (content === null) {
|
|
2855
|
-
++domBase.failCount;
|
|
2856
|
-
removeElement(item, domElement);
|
|
2857
|
-
if (length === 1) {
|
|
2858
|
-
resolve();
|
|
2859
|
-
return;
|
|
2860
|
-
}
|
|
2861
|
-
break invalid;
|
|
2862
|
-
}
|
|
2863
|
-
value = content;
|
|
2864
|
-
}
|
|
2865
|
-
else {
|
|
2866
|
-
for (let j = 0, match; j < items.length; ++j) {
|
|
2867
|
-
const row = items[j];
|
|
2868
|
-
if ((0, types_1.isPlainObject)(row)) {
|
|
2869
|
-
row['__index__'] ?? (row['__index__'] = j + 1);
|
|
2870
|
-
}
|
|
2871
|
-
let segment = template;
|
|
2872
|
-
while (match = REGEXP_TEMPLATECONDITIONAL.exec(segment)) {
|
|
2873
|
-
const col = hasCondition(row, match[2]) ? 4 : hasCondition(row, match[5]) ? 7 : -1;
|
|
2874
|
-
segment = replaceMatch(match, segment, match[col] ? (!match[1] || match[col - 1].indexOf('\n') !== -1 ? '' : match[1]) + match[col - 1] + match[col] : '', REGEXP_TEMPLATECONDITIONAL);
|
|
2875
|
-
}
|
|
2876
|
-
REGEXP_TEMPLATECONDITIONAL.lastIndex = 0;
|
|
2877
|
-
const literal = segment.trim();
|
|
2878
|
-
if (literal[0] === '`' && literal[literal.length - 1] === '`') {
|
|
2879
|
-
if (!this.hasEval('function')) {
|
|
2880
|
-
errors = (0, types_1.errorMessage)('eval', "Unsupported access" /* ERR_MESSAGE.UNSUPPORTED_ACCESS */, 'function');
|
|
2881
|
-
continue;
|
|
2882
|
-
}
|
|
2883
|
-
try {
|
|
2884
|
-
let content = new Function('return ' + literal + ';').call(row);
|
|
2885
|
-
if (segment[0] !== '`') {
|
|
2886
|
-
content = segment.substring(0, segment.indexOf('`')) + content;
|
|
2887
|
-
}
|
|
2888
|
-
if (segment[segment.length - 1] !== '`') {
|
|
2889
|
-
content += segment.substring(segment.lastIndexOf('`') + 1);
|
|
2890
|
-
}
|
|
2891
|
-
segment = content;
|
|
2892
|
-
}
|
|
2893
|
-
catch (err) {
|
|
2894
|
-
errors = err instanceof Error ? err : true;
|
|
2895
|
-
continue;
|
|
2896
|
-
}
|
|
2897
|
-
}
|
|
2898
|
-
else {
|
|
2899
|
-
const pattern = /\$\{\s*([^\s}]+)\s*\}/g;
|
|
2900
|
-
while (match = pattern.exec(segment)) {
|
|
2901
|
-
segment = replaceMatch(match, segment, match[1] === '__index__' && !(0, types_1.isObject)(row) ? (j + 1).toString() : valueAsString(getObjectValue(row, match[1]), ', '), pattern);
|
|
2902
|
-
}
|
|
2903
|
-
}
|
|
2904
|
-
value += trimTemplate(segment);
|
|
2905
|
-
}
|
|
2906
|
-
}
|
|
2907
|
-
if (preRender) {
|
|
2908
|
-
await checkValue(preRender);
|
|
2909
|
-
}
|
|
2910
|
-
domElement.innerXml = domBase.initOpts.normalize ? dom_1.DomWriter.normalize(value, { newline: domBase.newline, escapeEntities: domBase.initOpts.escapeEntities }) : value;
|
|
2911
|
-
}
|
|
2912
|
-
else {
|
|
2913
|
-
errors = true;
|
|
2914
|
-
}
|
|
2915
|
-
break;
|
|
2916
|
-
}
|
|
2917
|
-
case 'attribute': {
|
|
2918
|
-
const map = item.value;
|
|
2919
|
-
if ((0, types_1.isPlainObject)(map)) {
|
|
2920
|
-
for (const attr in map) {
|
|
2921
|
-
value = '';
|
|
2922
|
-
let segment = map[attr], valid;
|
|
2923
|
-
if (item.viewEngine) {
|
|
2924
|
-
if (!(0, types_1.isString)(segment)) {
|
|
2925
|
-
errors = true;
|
|
2926
|
-
continue;
|
|
2927
|
-
}
|
|
2928
|
-
const content = await this.parseTemplate(item.viewEngine, segment, items);
|
|
2929
|
-
if (content === null) {
|
|
2930
|
-
errors = true;
|
|
2931
|
-
continue;
|
|
2932
|
-
}
|
|
2933
|
-
value = content;
|
|
2934
|
-
valid = true;
|
|
2935
|
-
}
|
|
2936
|
-
else {
|
|
2937
|
-
if ((0, types_1.isString)(segment)) {
|
|
2938
|
-
segment = [segment];
|
|
2939
|
-
}
|
|
2940
|
-
else if (!(0, types_1.isArray)(segment)) {
|
|
2941
|
-
errors = true;
|
|
2942
|
-
continue;
|
|
2943
|
-
}
|
|
2944
|
-
let joinString = ' ', match;
|
|
2945
|
-
for (const row of items) {
|
|
2946
|
-
for (let seg of segment) {
|
|
2947
|
-
seg = seg.trim();
|
|
2948
|
-
if (seg[0] === ':' && (match = /^:join\(([\S\s]*)\)$/i.exec(seg))) {
|
|
2949
|
-
joinString = match[1];
|
|
2950
|
-
continue;
|
|
2951
|
-
}
|
|
2952
|
-
if (match = REGEXP_TEMPLATECONDITIONAL.exec(seg)) {
|
|
2953
|
-
seg = (hasCondition(row, match[2]) ? match[4] : hasCondition(row, match[5]) ? match[7] : '').trim();
|
|
2954
|
-
valid = true;
|
|
2955
|
-
}
|
|
2956
|
-
if (seg) {
|
|
2957
|
-
if (match = /^:text\(([\S\s]*)\)$/i.exec(seg)) {
|
|
2958
|
-
value += (value ? joinString : '') + match[1];
|
|
2959
|
-
valid = true;
|
|
2960
|
-
}
|
|
2961
|
-
else {
|
|
2962
|
-
const data = getObjectValue(row, seg);
|
|
2963
|
-
if (data !== null) {
|
|
2964
|
-
if (seg = valueAsString(data, joinString)) {
|
|
2965
|
-
value += (value ? joinString : '') + seg;
|
|
2966
|
-
}
|
|
2967
|
-
valid = true;
|
|
2968
|
-
}
|
|
2969
|
-
}
|
|
2970
|
-
}
|
|
2971
|
-
REGEXP_TEMPLATECONDITIONAL.lastIndex = 0;
|
|
2972
|
-
}
|
|
2973
|
-
}
|
|
2974
|
-
}
|
|
2975
|
-
if (valid) {
|
|
2976
|
-
if (preRender) {
|
|
2977
|
-
await checkValue(preRender);
|
|
2978
|
-
}
|
|
2979
|
-
domElement.setAttribute(attr, value);
|
|
2980
|
-
}
|
|
2981
|
-
else {
|
|
2982
|
-
errors = true;
|
|
2983
|
-
}
|
|
2984
|
-
}
|
|
2985
|
-
}
|
|
2986
|
-
else {
|
|
2987
|
-
errors = true;
|
|
2988
|
-
}
|
|
2989
|
-
break;
|
|
2990
|
-
}
|
|
2991
|
-
case 'display': {
|
|
2992
|
-
let template = item.value;
|
|
2993
|
-
if (template) {
|
|
2994
|
-
if (item.viewEngine) {
|
|
2995
|
-
errors = true;
|
|
2996
|
-
if ((0, types_1.isString)(template)) {
|
|
2997
|
-
const content = await this.parseTemplate(item.viewEngine, template, items);
|
|
2998
|
-
if (content !== null) {
|
|
2999
|
-
if ((0, types_1.isString)(content) && content.trim() === '') {
|
|
3000
|
-
domElement.remove = true;
|
|
3001
|
-
}
|
|
3002
|
-
errors = false;
|
|
3003
|
-
}
|
|
3004
|
-
}
|
|
3005
|
-
}
|
|
3006
|
-
else {
|
|
3007
|
-
if ((0, types_1.isString)(template)) {
|
|
3008
|
-
template = [template];
|
|
3009
|
-
}
|
|
3010
|
-
else if (!(0, types_1.isArray)(template)) {
|
|
3011
|
-
errors = true;
|
|
3012
|
-
continue;
|
|
3013
|
-
}
|
|
3014
|
-
let remove = true;
|
|
3015
|
-
complete: {
|
|
3016
|
-
const row = items[0];
|
|
3017
|
-
let condition = NaN;
|
|
3018
|
-
for (let seg of template) {
|
|
3019
|
-
switch ((seg = seg.trim()).toLowerCase()) {
|
|
3020
|
-
case ':is(and)':
|
|
3021
|
-
if (condition === 0) {
|
|
3022
|
-
remove = false;
|
|
3023
|
-
break complete;
|
|
3024
|
-
}
|
|
3025
|
-
condition = NaN;
|
|
3026
|
-
continue;
|
|
3027
|
-
case ':is(or)':
|
|
3028
|
-
if (isNaN(condition)) {
|
|
3029
|
-
condition = 0;
|
|
3030
|
-
}
|
|
3031
|
-
continue;
|
|
3032
|
-
default:
|
|
3033
|
-
if (condition > 0) {
|
|
3034
|
-
continue;
|
|
3035
|
-
}
|
|
3036
|
-
break;
|
|
3037
|
-
}
|
|
3038
|
-
const match = REGEXP_TEMPLATECONDITIONAL.exec(seg);
|
|
3039
|
-
if (match) {
|
|
3040
|
-
seg = (hasCondition(row, match[2]) ? match[4] : hasCondition(row, match[5]) ? match[7] : '').trim();
|
|
3041
|
-
}
|
|
3042
|
-
REGEXP_TEMPLATECONDITIONAL.lastIndex = 0;
|
|
3043
|
-
const sign = seg[0];
|
|
3044
|
-
if (sign === '+' || sign === '-') {
|
|
3045
|
-
seg = seg.substring(1);
|
|
3046
|
-
}
|
|
3047
|
-
const data = getObjectValue(row, seg);
|
|
3048
|
-
let keep = true;
|
|
3049
|
-
if (data === undefined || data === null) {
|
|
3050
|
-
if (sign !== '+') {
|
|
3051
|
-
keep = false;
|
|
3052
|
-
}
|
|
3053
|
-
}
|
|
3054
|
-
else if (sign === '+') {
|
|
3055
|
-
if (data) {
|
|
3056
|
-
keep = false;
|
|
3057
|
-
}
|
|
3058
|
-
}
|
|
3059
|
-
else if (sign === '-' && !data) {
|
|
3060
|
-
keep = false;
|
|
3061
|
-
}
|
|
3062
|
-
if (!isNaN(condition)) {
|
|
3063
|
-
if (!keep) {
|
|
3064
|
-
++condition;
|
|
3065
|
-
}
|
|
3066
|
-
}
|
|
3067
|
-
else if (keep) {
|
|
3068
|
-
remove = false;
|
|
3069
|
-
break;
|
|
3070
|
-
}
|
|
3071
|
-
}
|
|
3072
|
-
if (condition === 0) {
|
|
3073
|
-
remove = false;
|
|
3074
|
-
}
|
|
3075
|
-
}
|
|
3076
|
-
if (remove) {
|
|
3077
|
-
domElement.remove = true;
|
|
3078
|
-
}
|
|
3079
|
-
}
|
|
3080
|
-
if (errors && item.removeEmpty) {
|
|
3081
|
-
domElement.remove || (domElement.remove = true);
|
|
3082
|
-
}
|
|
3083
|
-
}
|
|
3084
|
-
if (!domElement.remove) {
|
|
3085
|
-
if (length === 1) {
|
|
3086
|
-
resolve();
|
|
3087
|
-
return;
|
|
3088
|
-
}
|
|
3089
|
-
break invalid;
|
|
3090
|
-
}
|
|
3091
|
-
break;
|
|
3092
|
-
}
|
|
3093
|
-
default:
|
|
3094
|
-
removeElement(item, domElement);
|
|
3095
|
-
if (length === 1) {
|
|
3096
|
-
reject(errorDataSource('Invalid action', item.type || "Unknown" /* ERR_MESSAGE.UNKNOWN */));
|
|
3097
|
-
return;
|
|
3098
|
-
}
|
|
3099
|
-
break invalid;
|
|
3100
|
-
}
|
|
3101
|
-
if (!domBase.write(domElement) || errors) {
|
|
3102
|
-
this.writeFail(item.type === 'display' ? domElement.remove ? errors ? 'Element was removed with errors' : 'Unable to remove element' : 'Unable to determine display conditional' : 'Unable to replace ' + item.type, errors instanceof Error ? errors : errorHtml(element), { type: 4 /* LOG_TYPE.PROCESS */, startTime });
|
|
3103
|
-
}
|
|
3104
|
-
}
|
|
3105
|
-
}
|
|
3106
|
-
else {
|
|
3107
|
-
if (!empty && item.type !== 'display' || item.transactionFail) {
|
|
3108
|
-
const emptyResponse = (value, service = item.source) => errorDataSource(service + ' -> Empty', value || "Unknown" /* ERR_MESSAGE.UNKNOWN */);
|
|
3109
|
-
switch (item.source) {
|
|
3110
|
-
case 'cloud': {
|
|
3111
|
-
const { service, table, id, query } = item;
|
|
3112
|
-
const queryString = (table ? 'table=' + table : '') + (id || query ? (table ? ';' : '') + (id ? 'id=' + id : 'query=' + asString(query)) : '');
|
|
3113
|
-
(cloud || this).formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to execute query" /* ERR_DB.EXEC_QUERY */, queryString], emptyResponse(queryString, service), { ...cloud_1.default.LOG_CLOUD_FAIL, startTime });
|
|
3114
|
-
break;
|
|
3115
|
-
}
|
|
3116
|
-
case 'uri': {
|
|
3117
|
-
const { uri, format = uri && path.extname(uri).substring(1) } = item;
|
|
3118
|
-
this.formatFail(4 /* LOG_TYPE.PROCESS */, format || 'URI', ['No records were found', uri], emptyResponse(uri), { startTime });
|
|
3119
|
-
break;
|
|
3120
|
-
}
|
|
3121
|
-
case 'local': {
|
|
3122
|
-
const { pathname, format = pathname && path.extname(pathname).substring(1) } = item;
|
|
3123
|
-
this.formatFail(4 /* LOG_TYPE.PROCESS */, format || 'LOCAL', ['No records were found', pathname], emptyResponse(pathname), { startTime });
|
|
3124
|
-
break;
|
|
3125
|
-
}
|
|
3126
|
-
case 'export': {
|
|
3127
|
-
const { pathname, settings, execute } = item;
|
|
3128
|
-
let target = execute || pathname || settings;
|
|
3129
|
-
if (typeof target === 'function') {
|
|
3130
|
-
target = target.name;
|
|
3131
|
-
}
|
|
3132
|
-
this.formatFail(4 /* LOG_TYPE.PROCESS */, 'EXPORT', ['No records were retrieved', target], emptyResponse(target), { startTime });
|
|
3133
|
-
break;
|
|
3134
|
-
}
|
|
3135
|
-
}
|
|
3136
|
-
}
|
|
3137
|
-
removeElement(item);
|
|
3138
|
-
}
|
|
3139
|
-
}
|
|
3140
|
-
resolve();
|
|
3141
|
-
});
|
|
3142
|
-
}), 'Element text or attribute replacement');
|
|
3143
|
-
};
|
|
3144
|
-
if (dataItems.length) {
|
|
3145
|
-
await setElements(dataItems);
|
|
3146
|
-
}
|
|
3147
|
-
if (displayItems.length) {
|
|
3148
|
-
await setElements(displayItems);
|
|
3149
|
-
}
|
|
3150
|
-
}
|
|
3151
|
-
setProductionAttributes({ host, hashed, bufferMap, startTime }) {
|
|
3152
|
-
for (const item of this.assets) {
|
|
3153
|
-
if (isIgnored(item, true)) {
|
|
3154
|
-
continue;
|
|
3155
|
-
}
|
|
3156
|
-
if (!hashed.has(item)) {
|
|
3157
|
-
createHash(host, item, bufferMap);
|
|
3158
|
-
}
|
|
3159
|
-
switch (item.element?.tagName.toLowerCase()) {
|
|
3160
|
-
case 'style':
|
|
3161
|
-
if (!item.content) {
|
|
3162
|
-
break;
|
|
3163
|
-
}
|
|
3164
|
-
case 'link':
|
|
3165
|
-
case 'script': {
|
|
3166
|
-
const attributes = item.attributes;
|
|
3167
|
-
if (attributes) {
|
|
3168
|
-
const algorithm = (0, types_1.isString)(attributes.integrity) ? attributes.integrity.trim().toLowerCase() : '';
|
|
3169
|
-
switch (algorithm) {
|
|
3170
|
-
case 'sha256':
|
|
3171
|
-
case 'sha384':
|
|
3172
|
-
case 'sha512':
|
|
3173
|
-
try {
|
|
3174
|
-
const data = getBuffer(item);
|
|
3175
|
-
let value;
|
|
3176
|
-
if (data && (value = index_1.default.asHash(data, { algorithm, encoding: item.encoding, digest: 'base64' }))) {
|
|
3177
|
-
attributes.integrity = algorithm + '-' + value;
|
|
3178
|
-
attributes.crossorigin || (attributes.crossorigin = 'anonymous');
|
|
3179
|
-
break;
|
|
3180
|
-
}
|
|
3181
|
-
throw (0, types_1.errorMessage)('hash', 'Source not found', item.filename);
|
|
3182
|
-
}
|
|
3183
|
-
catch (err) {
|
|
3184
|
-
this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, item.filename], err, { type: 32 /* LOG_TYPE.FILE */, startTime });
|
|
3185
|
-
}
|
|
3186
|
-
default:
|
|
3187
|
-
if (algorithm) {
|
|
3188
|
-
delete attributes.integrity;
|
|
3189
|
-
}
|
|
3190
|
-
break;
|
|
3191
|
-
}
|
|
3192
|
-
}
|
|
3193
|
-
break;
|
|
3194
|
-
}
|
|
3195
|
-
}
|
|
3196
|
-
}
|
|
3197
|
-
}
|
|
3198
|
-
removeUnusedStyles(source, { useUnsafeCssReplace, usedVariables, usedFontFace, usedKeyframes, unusedStyles, unusedMedia, unusedContainer, unusedSupports } = this.config) {
|
|
3199
|
-
var _a;
|
|
3200
|
-
if (!usedVariables && !usedFontFace && !usedKeyframes && !unusedStyles && !unusedMedia && !unusedContainer && !unusedSupports) {
|
|
3201
|
-
return;
|
|
3202
|
-
}
|
|
3203
|
-
const selectorMap = this._selectorMap;
|
|
3204
|
-
const replaceMap = [];
|
|
3205
|
-
const getStringSome = () => useUnsafeCssReplace ? '\\s*' : PATTERN_STRING_SOME;
|
|
3206
|
-
const getStringMany = () => useUnsafeCssReplace ? '\\s+' : PATTERN_STRING_MANY;
|
|
3207
|
-
let current = source, modified, checkEmpty, match;
|
|
3208
|
-
const parseSelector = (value) => {
|
|
3209
|
-
const items = [];
|
|
3210
|
-
const revised = value.replace(useUnsafeCssReplace ? REGEXP_NTHCHILD_UNSAFE : REGEXP_NTHCHILD, (...capture) => {
|
|
3211
|
-
return '`%' + (items.push('\\(' + getStringSome() + (capture[1] === '-' ? '\\x2d' : '\\x2b?') + (capture[2] || '[01]?') + (capture[3] === '0' ? !capture[1] && !capture[2] && !capture[4] && !capture[5] ? '[+-]?0[nN]?' : '0' : '[nN]') + getStringSome() + (capture[5] ? (capture[4] === '-' ? '\\x2d' : '\\x2b') + getStringSome() + capture[5] : `(?:[+-]${getStringSome()}0)?`) + getStringSome() + '\\)') - 1) + '`';
|
|
3212
|
-
});
|
|
3213
|
-
let selector = '';
|
|
3214
|
-
for (let i = 0, length = revised.length, casing = false, attr = false, quote = false; i < length; i++) {
|
|
3215
|
-
let ch = revised[i], space = 0;
|
|
3216
|
-
switch (ch) {
|
|
3217
|
-
case '.':
|
|
3218
|
-
case '#':
|
|
3219
|
-
if (!attr) {
|
|
3220
|
-
casing = true;
|
|
3221
|
-
}
|
|
3222
|
-
break;
|
|
3223
|
-
case '[':
|
|
3224
|
-
if (!quote) {
|
|
3225
|
-
attr = true;
|
|
3226
|
-
casing = false;
|
|
3227
|
-
space = 2;
|
|
3228
|
-
}
|
|
3229
|
-
break;
|
|
3230
|
-
case ']':
|
|
3231
|
-
if (!quote || attr && revised[i - 1] === '"' && revised[i - 2] === '\\') {
|
|
3232
|
-
if (quote) {
|
|
3233
|
-
selector = selector.substring(0, selector.length - 1) + '`%%%`';
|
|
3234
|
-
quote = false;
|
|
3235
|
-
}
|
|
3236
|
-
attr = false;
|
|
3237
|
-
casing = false;
|
|
3238
|
-
space = 1;
|
|
3239
|
-
}
|
|
3240
|
-
break;
|
|
3241
|
-
case '=':
|
|
3242
|
-
if (attr && !quote) {
|
|
3243
|
-
casing = true;
|
|
3244
|
-
space = 3;
|
|
3245
|
-
}
|
|
3246
|
-
break;
|
|
3247
|
-
case '\\':
|
|
3248
|
-
ch = '`%%%%`';
|
|
3249
|
-
break;
|
|
3250
|
-
case '"':
|
|
3251
|
-
if (attr) {
|
|
3252
|
-
if (!quote) {
|
|
3253
|
-
ch = '`%%%`';
|
|
3254
|
-
quote = true;
|
|
3255
|
-
}
|
|
3256
|
-
else if (revised[i - 1] !== '\\') {
|
|
3257
|
-
ch = '`%%%`';
|
|
3258
|
-
quote = false;
|
|
3259
|
-
casing = false;
|
|
3260
|
-
}
|
|
3261
|
-
}
|
|
3262
|
-
break;
|
|
3263
|
-
case '~':
|
|
3264
|
-
case '^':
|
|
3265
|
-
case '$':
|
|
3266
|
-
case '*':
|
|
3267
|
-
case '|':
|
|
3268
|
-
if (attr && !quote) {
|
|
3269
|
-
space = 1;
|
|
3270
|
-
}
|
|
3271
|
-
break;
|
|
3272
|
-
case ' ':
|
|
3273
|
-
if (attr && !quote) {
|
|
3274
|
-
ch = '`%%`';
|
|
3275
|
-
break;
|
|
3276
|
-
}
|
|
3277
|
-
case ':':
|
|
3278
|
-
case ',':
|
|
3279
|
-
if (!attr) {
|
|
3280
|
-
casing = false;
|
|
3281
|
-
}
|
|
3282
|
-
break;
|
|
3283
|
-
}
|
|
3284
|
-
selector += (space & 1 ? '`%%`' : '') + (!casing && ch >= 'a' && ch <= 'z' ? '`' + ch + ch.toUpperCase() + '`' : ch) + (space & 2 ? '`%%`' : '');
|
|
3285
|
-
}
|
|
3286
|
-
selector = (0, types_1.escapePattern)(selector)
|
|
3287
|
-
.replace(/\s*(>|~(?!=)|\\\+|\\\*(?!=)])\s*/g, (...capture) => getStringSome() + capture[1] + getStringSome())
|
|
3288
|
-
.replace(/`([a-z][A-Z]|%{2,4})`/g, (...capture) => {
|
|
3289
|
-
switch (capture[1]) {
|
|
3290
|
-
case '%%':
|
|
3291
|
-
return getStringSome();
|
|
3292
|
-
case '%%%':
|
|
3293
|
-
return `(?:["']|${getStringSome()})`;
|
|
3294
|
-
case '%%%%':
|
|
3295
|
-
return '\\\\{0,}';
|
|
3296
|
-
default:
|
|
3297
|
-
return `[${capture[1]}]`;
|
|
3298
|
-
}
|
|
3299
|
-
});
|
|
3300
|
-
for (let i = 0; i < items.length; ++i) {
|
|
3301
|
-
selector = selector.replace('`%' + i + '`', items[i]);
|
|
3302
|
-
}
|
|
3303
|
-
return selector.replace(/[ ]+/g, getStringMany()) + getStringSome();
|
|
3304
|
-
};
|
|
3305
|
-
const replaceUnunsed = (name, items) => {
|
|
3306
|
-
for (let value of items) {
|
|
3307
|
-
const key = name + '_' + (value = value.trim()) + (useUnsafeCssReplace ? '_1' : '');
|
|
3308
|
-
let [pattern] = selectorMap[key] || [], selector = '', rule;
|
|
3309
|
-
if (!pattern) {
|
|
3310
|
-
let flags = 'gi', revised;
|
|
3311
|
-
if (name === 'container') {
|
|
3312
|
-
for (let i = 0, length = value.length, casing = true; i < length; i++) {
|
|
3313
|
-
let ch = value[i];
|
|
3314
|
-
if (!casing) {
|
|
3315
|
-
ch = ch.toLowerCase();
|
|
3316
|
-
}
|
|
3317
|
-
else if (ch === '(') {
|
|
3318
|
-
casing = false;
|
|
3319
|
-
}
|
|
3320
|
-
if (casing || ch < 'a' || ch > 'z') {
|
|
3321
|
-
selector += value[i];
|
|
3322
|
-
if (selector.endsWith(' not ')) {
|
|
3323
|
-
selector = selector.replace(/ not $/, ' `nN``oO``tT` ');
|
|
3324
|
-
}
|
|
3325
|
-
}
|
|
3326
|
-
else {
|
|
3327
|
-
selector += '`' + ch + ch.toUpperCase() + '`';
|
|
3328
|
-
}
|
|
3329
|
-
}
|
|
3330
|
-
flags = 'g';
|
|
3331
|
-
}
|
|
3332
|
-
else if (name === 'supports' && /^selector\(/i.test(value)) {
|
|
3333
|
-
const startIndex = value.indexOf('(');
|
|
3334
|
-
const endIndex = value.lastIndexOf(')');
|
|
3335
|
-
if (startIndex !== -1 && endIndex !== -1) {
|
|
3336
|
-
selector = '[sS][eE][lL][eE][cC][tT][oO][rR]\\(' + getStringSome() + parseSelector(value.substring(startIndex + 1, endIndex)) + '\\)';
|
|
3337
|
-
flags = 'g';
|
|
3338
|
-
revised = true;
|
|
3339
|
-
}
|
|
3340
|
-
}
|
|
3341
|
-
if (!revised) {
|
|
3342
|
-
selector = (0, types_1.escapePattern)(selector || value)
|
|
3343
|
-
.replace(/\s*(\\[()])\s*/g, (...capture) => getStringSome() + capture[1] + getStringSome())
|
|
3344
|
-
.replace(/:\s+/g, getStringSome() + ':' + getStringSome())
|
|
3345
|
-
.replace(/\s+([<>/]|<=|>=|\\\*)\s+/g, (...capture) => getStringSome() + capture[1] + getStringSome())
|
|
3346
|
-
.replace(/[ ]+/g, getStringMany());
|
|
3347
|
-
if (flags === 'g') {
|
|
3348
|
-
selector = selector.replace(/`([a-z][A-Z])`/g, (...capture) => `[${capture[1]}]`);
|
|
3349
|
-
}
|
|
3350
|
-
}
|
|
3351
|
-
pattern = new RegExp('(\\s*)@' + (flags === 'g' ? name.split('').map(ch => `[${ch + ch.toUpperCase()}]`).join('') : name) + getStringMany() + selector + getStringSome() + '{', flags);
|
|
3352
|
-
}
|
|
3353
|
-
else {
|
|
3354
|
-
pattern.lastIndex = 0;
|
|
3355
|
-
}
|
|
3356
|
-
while (rule = pattern.exec(current)) {
|
|
3357
|
-
const [endIndex, trailing] = findClosingIndex(current, getEndIndex(rule));
|
|
3358
|
-
if (endIndex !== -1) {
|
|
3359
|
-
current = spliceSource(current, rule.index, endIndex, pattern, rule[1], trailing);
|
|
3360
|
-
(checkEmpty || (checkEmpty = {}))[name] = true;
|
|
3361
|
-
modified = true;
|
|
3362
|
-
}
|
|
3363
|
-
}
|
|
3364
|
-
if (selector) {
|
|
3365
|
-
selectorMap[key] = [pattern];
|
|
3366
|
-
}
|
|
3367
|
-
}
|
|
3368
|
-
};
|
|
3369
|
-
if (!useUnsafeCssReplace) {
|
|
3370
|
-
const replaceBracket = (pattern, opening) => {
|
|
3371
|
-
let bracket;
|
|
3372
|
-
while (bracket = pattern.exec(current)) {
|
|
3373
|
-
const segment = bracket[0];
|
|
3374
|
-
if (segment.indexOf('}') !== -1 || opening && segment.indexOf('{') !== -1) {
|
|
3375
|
-
const placeholder = '`' + (0, types_1.generateUUID)() + '`';
|
|
3376
|
-
replaceMap.push([placeholder, segment]);
|
|
3377
|
-
current = replaceMatch(bracket, current, placeholder, pattern);
|
|
3378
|
-
}
|
|
3379
|
-
}
|
|
3380
|
-
pattern.lastIndex = 0;
|
|
3381
|
-
};
|
|
3382
|
-
replaceBracket(REGEXP_COMMENT, true);
|
|
3383
|
-
replaceBracket(REGEXP_CONTENT, false);
|
|
3384
|
-
const values = (0, util_1.splitEnclosing)(current, /\burl/gi);
|
|
3385
|
-
for (let i = 0, length = values.length; i < length; ++i) {
|
|
3386
|
-
const seg = values[i];
|
|
3387
|
-
if (seg[seg.length - 1] === ')' && seg.indexOf('}') !== -1 && /^url\(/i.test(seg)) {
|
|
3388
|
-
replaceMap.push([values[i] = (0, types_1.generateUUID)(), seg]);
|
|
3389
|
-
}
|
|
3390
|
-
}
|
|
3391
|
-
if (replaceMap.length) {
|
|
3392
|
-
current = values.join('');
|
|
3393
|
-
}
|
|
3394
|
-
}
|
|
3395
|
-
if (unusedMedia) {
|
|
3396
|
-
replaceUnunsed('media', unusedMedia);
|
|
3397
|
-
}
|
|
3398
|
-
if (unusedSupports) {
|
|
3399
|
-
replaceUnunsed('supports', unusedSupports);
|
|
3400
|
-
}
|
|
3401
|
-
if (unusedContainer) {
|
|
3402
|
-
replaceUnunsed('container', unusedContainer);
|
|
3403
|
-
}
|
|
3404
|
-
if (unusedStyles) {
|
|
3405
|
-
for (const value of unusedStyles) {
|
|
3406
|
-
const key = value + (useUnsafeCssReplace ? '_1' : '');
|
|
3407
|
-
let [single, group] = selectorMap[key] || [], selector;
|
|
3408
|
-
if (!single || !group) {
|
|
3409
|
-
single = new RegExp(`(}|^)(${getStringSome()})(?<!@[^}]*)${selector = parseSelector(value)}\\{[^}]*\\}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'g');
|
|
3410
|
-
group = new RegExp(`((?:}|^)[^{]*?)((?:,${getStringSome()}|(?<!@[^}]*))${selector})(,[^{]*)?\\{`, 'g');
|
|
3411
|
-
}
|
|
3412
|
-
else {
|
|
3413
|
-
single.lastIndex = 0;
|
|
3414
|
-
group.lastIndex = 0;
|
|
3415
|
-
}
|
|
3416
|
-
while (match = single.exec(current)) {
|
|
3417
|
-
current = spliceSource(current, match.index, getEndIndex(match), single, match[2], match[3], match[1] || '');
|
|
3418
|
-
modified = true;
|
|
3419
|
-
}
|
|
3420
|
-
while (match = group.exec(current)) {
|
|
3421
|
-
const middle = match[2][0] === ',';
|
|
3422
|
-
const leading = middle ? match[1].trimEnd() : match[1];
|
|
3423
|
-
const trailing = match[3];
|
|
3424
|
-
const segment = trailing ? (!middle ? (!isSpace(leading[leading.length - 1]) ? ' ' : '') + trailing.substring(1).trimStart() : trailing).trimEnd() : '';
|
|
3425
|
-
current = replaceMatch(match, current, leading + segment + ' {');
|
|
3426
|
-
group.lastIndex = match.index;
|
|
3427
|
-
modified = true;
|
|
3428
|
-
}
|
|
3429
|
-
if (selector) {
|
|
3430
|
-
selectorMap[key] = [single, group];
|
|
3431
|
-
}
|
|
3432
|
-
}
|
|
3433
|
-
}
|
|
3434
|
-
if (usedVariables) {
|
|
3435
|
-
const pattern = useUnsafeCssReplace ? REGEXP_VARIABLES_UNSAFE : REGEXP_VARIABLES;
|
|
3436
|
-
while (match = pattern.exec(current)) {
|
|
3437
|
-
if (!usedVariables.includes(match[2])) {
|
|
3438
|
-
current = replaceMatch(match, current, match[3] === ';' ? getNewlineString(match[1], match[4]) : '', pattern);
|
|
3439
|
-
modified = true;
|
|
3440
|
-
}
|
|
3441
|
-
}
|
|
3442
|
-
pattern.lastIndex = 0;
|
|
3443
|
-
}
|
|
3444
|
-
if (usedFontFace) {
|
|
3445
|
-
const fontFace = useUnsafeCssReplace ? REGEXP_FONTFACE_UNSAFE : REGEXP_FONTFACE;
|
|
3446
|
-
const fontFamily = useUnsafeCssReplace ? REGEXP_FONTFAMILY_UNSAFE : REGEXP_FONTFAMILY;
|
|
3447
|
-
while (match = fontFace.exec(current)) {
|
|
3448
|
-
const font = fontFamily.exec(match[0]);
|
|
3449
|
-
if (font && !usedFontFace.includes(font[1].trim().replace(/^(["'])([\S\s]+)\1$/, (...content) => content[2]))) {
|
|
3450
|
-
current = spliceSource(current, match.index, getEndIndex(match), fontFace, match[1], match[3]);
|
|
3451
|
-
modified = true;
|
|
3452
|
-
}
|
|
3453
|
-
}
|
|
3454
|
-
fontFace.lastIndex = 0;
|
|
3455
|
-
}
|
|
3456
|
-
if (usedKeyframes) {
|
|
3457
|
-
const pattern = useUnsafeCssReplace ? REGEXP_KEYFRAMES_UNSAFE : REGEXP_KEYFRAMES;
|
|
3458
|
-
while (match = pattern.exec(current)) {
|
|
3459
|
-
if (!usedKeyframes.includes(match[2].trim())) {
|
|
3460
|
-
const [endIndex, trailing] = findClosingIndex(current, getEndIndex(match));
|
|
3461
|
-
if (endIndex !== -1) {
|
|
3462
|
-
current = spliceSource(current, match.index, endIndex, pattern, match[1], trailing);
|
|
3463
|
-
modified = true;
|
|
3464
|
-
}
|
|
3465
|
-
}
|
|
3466
|
-
}
|
|
3467
|
-
pattern.lastIndex = 0;
|
|
3468
|
-
}
|
|
3469
|
-
if (modified) {
|
|
3470
|
-
for (const name in checkEmpty) {
|
|
3471
|
-
const pattern = CACHE_ATRULES[_a = name + (useUnsafeCssReplace ? '_1' : '')] || (CACHE_ATRULES[_a] = new RegExp(`(\\s*)@${name}[^{]*{${getStringSome()}}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi'));
|
|
3472
|
-
while (match = pattern.exec(current)) {
|
|
3473
|
-
current = spliceSource(current, match.index, getEndIndex(match), pattern, match[1], match[2]);
|
|
3474
|
-
}
|
|
3475
|
-
pattern.lastIndex = 0;
|
|
3476
|
-
}
|
|
3477
|
-
if (replaceMap.length) {
|
|
3478
|
-
for (const [placeholder, content] of replaceMap.reverse()) {
|
|
3479
|
-
current = current.replace(placeholder, content);
|
|
3480
|
-
}
|
|
3481
|
-
}
|
|
3482
|
-
return current;
|
|
3483
|
-
}
|
|
3484
|
-
}
|
|
3485
|
-
get elements() {
|
|
3486
|
-
const result = this._elements;
|
|
3487
|
-
if (result) {
|
|
3488
|
-
return result;
|
|
3489
|
-
}
|
|
3490
|
-
const elements = new Set();
|
|
3491
|
-
const host = this.host;
|
|
3492
|
-
const restartable = host ? host.restartable || this.watching : false;
|
|
3493
|
-
const idMap = this._idMap;
|
|
3494
|
-
this.assets.forEach(item => {
|
|
3495
|
-
const { element, id, flags } = item;
|
|
3496
|
-
if (element) {
|
|
3497
|
-
if (restartable && id && !(0, types_1.cloneFlag)(flags)) {
|
|
3498
|
-
const backup = idMap[id];
|
|
3499
|
-
if (backup) {
|
|
3500
|
-
elements.add(item.element = (0, types_1.cloneObject)(backup, true));
|
|
3501
|
-
return;
|
|
3502
|
-
}
|
|
3503
|
-
idMap[id] = (0, types_1.cloneObject)(element, true);
|
|
3504
|
-
}
|
|
3505
|
-
elements.add(element);
|
|
3506
|
-
}
|
|
3507
|
-
});
|
|
3508
|
-
this.dataSource.forEach(item => elements.add(item.element));
|
|
3509
|
-
return this._elements = Array.from(elements);
|
|
3510
|
-
}
|
|
3511
|
-
get editing() {
|
|
3512
|
-
return this._editing;
|
|
3513
|
-
}
|
|
3514
|
-
set dataSource(value) {
|
|
3515
|
-
this._dataSource = value;
|
|
3516
|
-
}
|
|
3517
|
-
get dataSource() {
|
|
3518
|
-
const result = this._dataSource;
|
|
3519
|
-
if (result) {
|
|
3520
|
-
return result;
|
|
3521
|
-
}
|
|
3522
|
-
const host = this.host;
|
|
3523
|
-
if (host) {
|
|
3524
|
-
try {
|
|
3525
|
-
const items = host.getDataSourceItems(this);
|
|
3526
|
-
return this._dataSource = host.restartable || this.watching ? items.map(item => (0, types_1.cloneObject)(item, true)) : items;
|
|
3527
|
-
}
|
|
3528
|
-
catch {
|
|
3529
|
-
}
|
|
3530
|
-
}
|
|
3531
|
-
return [];
|
|
3532
|
-
}
|
|
3533
|
-
get settings() {
|
|
3534
|
-
var _a;
|
|
3535
|
-
return (_a = this.module).settings || (_a.settings = {});
|
|
3536
|
-
}
|
|
3537
|
-
}
|
|
3538
|
-
ChromeDocument.INTERNAL_ASSIGNUUID = '__assign__';
|
|
3539
|
-
ChromeDocument.INTERNAL_SERVERROOT = '__serverroot__';
|
|
3540
|
-
exports.default = ChromeDocument;
|
|
3541
|
-
|
|
3542
|
-
if (exports.default) {
|
|
3543
|
-
module.exports = exports.default;
|
|
3544
|
-
module.exports.default = exports.default;
|
|
3545
|
-
}
|