@pi-r/chrome 0.7.3 → 0.8.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.d.ts +6 -6
- package/index.js +440 -315
- package/package.json +6 -5
- package/types/index.d.ts +10 -5
- package/types/squared.d.ts +12 -1
package/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const fs = require("fs");
|
|
4
|
-
const
|
|
5
|
-
const util_1 = require("@e-mc/document/util");
|
|
6
|
-
const types_1 = require("@e-mc/types");
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
7
5
|
const core_1 = require("@e-mc/core");
|
|
8
6
|
const Cloud = require("@e-mc/cloud");
|
|
7
|
+
const types_1 = require("@e-mc/types");
|
|
8
|
+
const asset_1 = require("@e-mc/document/asset");
|
|
9
|
+
const util_1 = require("@e-mc/document/util");
|
|
9
10
|
const dom_1 = require("@e-mc/document/parse/dom");
|
|
10
11
|
const transform_1 = require("@e-mc/document/transform");
|
|
11
12
|
const Document = require('@e-mc/document');
|
|
@@ -32,10 +33,10 @@ const [REGEXP_NTHCHILD, REGEXP_NTHCHILD_UNSAFE, REGEXP_REPLACECSS] = (function (
|
|
|
32
33
|
];
|
|
33
34
|
})();
|
|
34
35
|
const REGEXP_SRCSETSIZE = /~\s*([\d.]+)\s*([wx])/i;
|
|
35
|
-
const REGEXP_TEMPLATECONDITIONAL = /(\n\s+)?\{\{if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)(
|
|
36
|
+
const REGEXP_TEMPLATECONDITIONAL = /(\n\s+)?\{\{if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)(.*?)(?:\s*\{\{else(?:\s+if\s+((?:[^}]|}(?!}))+?))?\}\}(\s*)(.*?)\s*)?\s*\{\{end\}\}/gs;
|
|
36
37
|
const REGEXP_TEMPLATECOMPARISON = /\s*\(\s*(?:\b(eq|ne|lt|le|gt|ge)\s+)?("[^"]+"|'[^']+'|[^\s)]+)(?:\s+("[^"]+"|'[^']+'|[^\s)]+))?\s*\)/g;
|
|
37
38
|
const REGEXP_TEMPLATEMATCH = new RegExp(`^(?:\\b(and|or|not)\\s+)?((?:${REGEXP_TEMPLATECOMPARISON.source})+)|(!|not\\s+)?([^\\s][\\S\\s]*)$`);
|
|
38
|
-
const REGEXP_IMPORTMODULE = /(?:(?:^|[\n;]+)\s*import\s+(?:("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')|.+?from\s+("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')(?:[ \t]+assert[ \t]+\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\})?)|\bimport\(\s*("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')\s*(?:,\s*\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\}\s*)?\))/
|
|
39
|
+
const REGEXP_IMPORTMODULE = /(?:(?:^|[\n;]+)\s*import\s+(?:("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')|.+?from\s+("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')(?:[ \t]+assert[ \t]+\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\})?)|\bimport\(\s*("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')\s*(?:,\s*\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\}\s*)?\))/gd;
|
|
39
40
|
const REGEXP_BLOCKEXCLUDE = new RegExp(`(\\s*)<!--\\s*exclude\\s*:\\s*(?:start|end)\\s*-->` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
|
|
40
41
|
const REGEXP_COMMENT = new RegExp(dom_1.DomWriter.PATTERN_COMMENT, 'g');
|
|
41
42
|
const REGEXP_QUOTEDVALUE = new RegExp(`\\b(?:@import${PATTERN_STRING_MANY}|content${PATTERN_STRING_SOME}:${PATTERN_STRING_SOME})(?:"[^"]*"|'[^']*')`, 'gi');
|
|
@@ -58,7 +59,8 @@ const REGEXP_URL = /(?:\b[Uu][Rr][Ll]\(|@import\s+(["'])|\b([Hh][Rr][Ee][Ff])\s*
|
|
|
58
59
|
const REGEXP_URL_JS = /\bimport\(/g;
|
|
59
60
|
const REGEXP_URL_SVG = /(?:\b[Uu][Rr][Ll]\(|@import\s+(["'])|\b([Hh][Rr][Ee][Ff])\s*=)/g;
|
|
60
61
|
const REGEXP_IMAGESET = /\b(?:-webkit-)?image-set\(/gi;
|
|
61
|
-
const REGEXP_IMAGESET_URL = /(?:^|[^(])\s*("(\s*[^)][^"]*)"|'(\s*[^)][^"]*)')\s*(?:,|$|[^)][^,]*,?)/
|
|
62
|
+
const REGEXP_IMAGESET_URL = /(?:^|[^(])\s*("(\s*[^)][^"]*)"|'(\s*[^)][^"]*)')\s*(?:,|$|[^)][^,]*,?)/gd;
|
|
63
|
+
const REGEXP_SANITIZEALL = new RegExp(`(?:\\s+|\\b)data-(?:pathname|filename|intl-locales|(?:use|exclude)-[^=\\s]+)\\s*${dom_1.DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g');
|
|
62
64
|
function removeNamespace(name, source, newline, comments) {
|
|
63
65
|
if (source.includes('-' + name)) {
|
|
64
66
|
const [a, b, c, d, e] = CACHE_DATASET[name] ||= [
|
|
@@ -168,7 +170,9 @@ function addCacheItem(map, key, data, timeout) {
|
|
|
168
170
|
map.set(key, [
|
|
169
171
|
Date.now(),
|
|
170
172
|
data,
|
|
171
|
-
setTimeout(() =>
|
|
173
|
+
setTimeout(() => {
|
|
174
|
+
deleteCacheItem(map, key);
|
|
175
|
+
}, timeout * 1000)
|
|
172
176
|
]);
|
|
173
177
|
}
|
|
174
178
|
function deleteCacheItem(map, key) {
|
|
@@ -183,8 +187,17 @@ function spliceSource(source, startIndex, endIndex, pattern, leading = '', trail
|
|
|
183
187
|
if (leading || trailing) {
|
|
184
188
|
content += getNewlineString(leading, trailing);
|
|
185
189
|
}
|
|
186
|
-
|
|
187
|
-
|
|
190
|
+
return (0, util_1.spliceString)(source, startIndex, endIndex, content, pattern);
|
|
191
|
+
}
|
|
192
|
+
function parseArg(data, value) {
|
|
193
|
+
if (!isNaN(+value)) {
|
|
194
|
+
return +value;
|
|
195
|
+
}
|
|
196
|
+
const match = /^(["'])(.*)\1$/s.exec(value);
|
|
197
|
+
if (match) {
|
|
198
|
+
return match[2];
|
|
199
|
+
}
|
|
200
|
+
return getObjectValue(data, value);
|
|
188
201
|
}
|
|
189
202
|
function hasCondition(data, condition) {
|
|
190
203
|
if (!condition) {
|
|
@@ -197,7 +210,7 @@ function hasCondition(data, condition) {
|
|
|
197
210
|
const join = match[1];
|
|
198
211
|
const items = [];
|
|
199
212
|
while (match = REGEXP_TEMPLATECOMPARISON.exec(comparison)) {
|
|
200
|
-
if (items.length && !isSpace(match[0][0])) {
|
|
213
|
+
if (items.length > 0 && !isSpace(match[0][0])) {
|
|
201
214
|
return false;
|
|
202
215
|
}
|
|
203
216
|
items.push([match[1], match[2], match[3]]);
|
|
@@ -207,15 +220,6 @@ function hasCondition(data, condition) {
|
|
|
207
220
|
if (length > 1 && !join) {
|
|
208
221
|
return false;
|
|
209
222
|
}
|
|
210
|
-
const parseArg = (value) => {
|
|
211
|
-
if (!isNaN(+value)) {
|
|
212
|
-
return +value;
|
|
213
|
-
}
|
|
214
|
-
if (match = /^(["'])([\S\s]*)\1$/.exec(value)) {
|
|
215
|
-
return match[2];
|
|
216
|
-
}
|
|
217
|
-
return getObjectValue(data, value);
|
|
218
|
-
};
|
|
219
223
|
for (let i = 0; i < length; ++i) {
|
|
220
224
|
const item = items[i];
|
|
221
225
|
const arg1 = item[1];
|
|
@@ -224,22 +228,22 @@ function hasCondition(data, condition) {
|
|
|
224
228
|
if (arg2) {
|
|
225
229
|
switch (item[0]) {
|
|
226
230
|
case 'eq':
|
|
227
|
-
valid = parseArg(arg1) == parseArg(arg2);
|
|
231
|
+
valid = parseArg(data, arg1) == parseArg(data, arg2);
|
|
228
232
|
break;
|
|
229
233
|
case 'ne':
|
|
230
|
-
valid = parseArg(arg1) != parseArg(arg2);
|
|
234
|
+
valid = parseArg(data, arg1) != parseArg(data, arg2);
|
|
231
235
|
break;
|
|
232
236
|
case 'lt':
|
|
233
|
-
valid = parseArg(arg1) < parseArg(arg2);
|
|
237
|
+
valid = parseArg(data, arg1) < parseArg(data, arg2);
|
|
234
238
|
break;
|
|
235
239
|
case 'le':
|
|
236
|
-
valid = parseArg(arg1) <= parseArg(arg2);
|
|
240
|
+
valid = parseArg(data, arg1) <= parseArg(data, arg2);
|
|
237
241
|
break;
|
|
238
242
|
case 'gt':
|
|
239
|
-
valid = parseArg(arg1) > parseArg(arg2);
|
|
243
|
+
valid = parseArg(data, arg1) > parseArg(data, arg2);
|
|
240
244
|
break;
|
|
241
245
|
case 'ge':
|
|
242
|
-
valid = parseArg(arg1) >= parseArg(arg2);
|
|
246
|
+
valid = parseArg(data, arg1) >= parseArg(data, arg2);
|
|
243
247
|
break;
|
|
244
248
|
default:
|
|
245
249
|
return false;
|
|
@@ -300,7 +304,11 @@ function hasSameOrigin(value, ...other) {
|
|
|
300
304
|
function restoreSearchParams(value, prefix = '__sqd') {
|
|
301
305
|
if (value?.includes(prefix)) {
|
|
302
306
|
const params = new URLSearchParams(value);
|
|
303
|
-
params.forEach((_, key) =>
|
|
307
|
+
params.forEach((_, key) => {
|
|
308
|
+
if (key.startsWith(prefix)) {
|
|
309
|
+
params.delete(key);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
304
312
|
if (value = params.toString()) {
|
|
305
313
|
return '?' + value;
|
|
306
314
|
}
|
|
@@ -309,7 +317,7 @@ function restoreSearchParams(value, prefix = '__sqd') {
|
|
|
309
317
|
}
|
|
310
318
|
function getBaseURLs(asset, baseUrl) {
|
|
311
319
|
const result = [];
|
|
312
|
-
let parentUrl = asset ? asset.url || asset.uri :
|
|
320
|
+
let parentUrl = asset ? asset.url || asset.uri : null;
|
|
313
321
|
try {
|
|
314
322
|
if (parentUrl) {
|
|
315
323
|
if (typeof parentUrl === 'string') {
|
|
@@ -320,15 +328,18 @@ function getBaseURLs(asset, baseUrl) {
|
|
|
320
328
|
}
|
|
321
329
|
}
|
|
322
330
|
catch {
|
|
323
|
-
parentUrl =
|
|
331
|
+
parentUrl = null;
|
|
324
332
|
}
|
|
325
333
|
if (baseUrl) {
|
|
326
334
|
const url = new URL(baseUrl);
|
|
327
335
|
if (!parentUrl) {
|
|
328
336
|
result.push(parentUrl = url);
|
|
329
337
|
}
|
|
330
|
-
else
|
|
331
|
-
|
|
338
|
+
else {
|
|
339
|
+
const { href, origin } = parentUrl;
|
|
340
|
+
if (origin !== url.origin) {
|
|
341
|
+
result.push(new URL(href.replace(origin, url.origin)), url);
|
|
342
|
+
}
|
|
332
343
|
}
|
|
333
344
|
}
|
|
334
345
|
return result;
|
|
@@ -340,7 +351,7 @@ function createHash(host, file, hash, bufferMap) {
|
|
|
340
351
|
if (buffer) {
|
|
341
352
|
const [algorithm, length] = (0, util_1.getHashData)(hash);
|
|
342
353
|
let value;
|
|
343
|
-
if (algorithm && (value = Document.asHash(buffer,
|
|
354
|
+
if (algorithm && (value = Document.asHash(buffer, algorithm, { encoding: file.encoding }))) {
|
|
344
355
|
if (localUri) {
|
|
345
356
|
bufferMap[localUri] = buffer;
|
|
346
357
|
}
|
|
@@ -354,8 +365,8 @@ function createHash(host, file, hash, bufferMap) {
|
|
|
354
365
|
host.writeFail(["Unable to read file", filename], err, 32);
|
|
355
366
|
}
|
|
356
367
|
}
|
|
357
|
-
function getSrcURL(parent, file) {
|
|
358
|
-
const relativeUrl = file.relativeUrl ||
|
|
368
|
+
function getSrcURL(instance, parent, file) {
|
|
369
|
+
const relativeUrl = file.relativeUrl || instance.host.removeCwd(file.localUri) && getRelativeURL(file);
|
|
359
370
|
if (!relativeUrl) {
|
|
360
371
|
return [''];
|
|
361
372
|
}
|
|
@@ -363,12 +374,12 @@ function getSrcURL(parent, file) {
|
|
|
363
374
|
return [relativeUrl];
|
|
364
375
|
}
|
|
365
376
|
let parentDir = parent.pathname, assetDir = file.pathname;
|
|
366
|
-
if (!
|
|
377
|
+
if (!instance.productionRelease) {
|
|
367
378
|
if (parent.moveTo) {
|
|
368
|
-
parentDir = joinPath(parent.moveTo, parentDir);
|
|
379
|
+
parentDir = Document.joinPath(parent.moveTo, parentDir);
|
|
369
380
|
}
|
|
370
381
|
if (file.moveTo) {
|
|
371
|
-
assetDir = joinPath(file.moveTo, assetDir);
|
|
382
|
+
assetDir = Document.joinPath(file.moveTo, assetDir);
|
|
372
383
|
}
|
|
373
384
|
}
|
|
374
385
|
if (parentDir === assetDir) {
|
|
@@ -378,16 +389,16 @@ function getSrcURL(parent, file) {
|
|
|
378
389
|
const prefix = splitPath(parentDir);
|
|
379
390
|
const suffix = splitPath(assetDir);
|
|
380
391
|
let found;
|
|
381
|
-
while (prefix.length && suffix.length && prefix[0] === suffix[0]) {
|
|
392
|
+
while (prefix.length > 0 && suffix.length > 0 && prefix[0] === suffix[0]) {
|
|
382
393
|
prefix.shift();
|
|
383
394
|
suffix.shift();
|
|
384
395
|
found = true;
|
|
385
396
|
}
|
|
386
|
-
return [found ? joinPath('../'.repeat(prefix.length), suffix.join('/'), file.filename) : '../'.repeat(prefix.length) + relativeUrl];
|
|
397
|
+
return [found ? Document.joinPath('../'.repeat(prefix.length), suffix.join('/'), file.filename) : '../'.repeat(prefix.length) + relativeUrl];
|
|
387
398
|
}
|
|
388
|
-
function transformURL(host, parent, type, source, importFile) {
|
|
399
|
+
function transformURL(instance, host, parent, type, source, importFile) {
|
|
389
400
|
const related = [];
|
|
390
|
-
const baseHref = getBaseURLs(importFile || parent,
|
|
401
|
+
const baseHref = getBaseURLs(importFile || parent, instance.baseUrl);
|
|
391
402
|
const isHtml = type === 'html';
|
|
392
403
|
const isJs = type === 'js';
|
|
393
404
|
const pattern = isJs ? REGEXP_URL_JS : type === 'svg' ? REGEXP_URL_SVG : REGEXP_URL;
|
|
@@ -401,15 +412,15 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
401
412
|
continue;
|
|
402
413
|
}
|
|
403
414
|
REGEXP_IMAGESET_URL.lastIndex = 0;
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
while (url = REGEXP_IMAGESET_URL.exec(original)) {
|
|
415
|
+
let content = source.substring(startIndex, endIndex), url;
|
|
416
|
+
while (url = REGEXP_IMAGESET_URL.exec(content)) {
|
|
407
417
|
const quote = url[2] ? '"' : "'";
|
|
408
|
-
|
|
418
|
+
const [a, b] = url.indices[1];
|
|
419
|
+
content = (0, util_1.spliceString)(content, a, b, `url(${quote + (url[2] || url[3]).trim() + quote})`, REGEXP_IMAGESET_URL);
|
|
409
420
|
modified = true;
|
|
410
421
|
}
|
|
411
422
|
if (modified) {
|
|
412
|
-
source = spliceString(source, startIndex,
|
|
423
|
+
source = (0, util_1.spliceString)(source, startIndex, endIndex, content, REGEXP_IMAGESET);
|
|
413
424
|
modified = false;
|
|
414
425
|
}
|
|
415
426
|
}
|
|
@@ -478,12 +489,12 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
478
489
|
if (asset) {
|
|
479
490
|
if (!asset.inlineBase64) {
|
|
480
491
|
if (host.Cloud?.getStorage('upload', asset.cloudStorage)) {
|
|
481
|
-
const inlineUrlCloud = asset.inlineUrlCloud ||= (0,
|
|
492
|
+
const inlineUrlCloud = asset.inlineUrlCloud ||= (0, crypto_1.randomUUID)();
|
|
482
493
|
(parent.inlineUrlCloudMap ||= {})[inlineUrlCloud] = value;
|
|
483
494
|
value = inlineUrlCloud;
|
|
484
495
|
}
|
|
485
|
-
else if (asset.hash &&
|
|
486
|
-
const inlineUrl = asset.inlineUrl ||= (0,
|
|
496
|
+
else if (asset.hash && instance.productionRelease) {
|
|
497
|
+
const inlineUrl = asset.inlineUrl ||= (0, crypto_1.randomUUID)();
|
|
487
498
|
(parent.inlineUrlMap ||= {})[inlineUrl] = value;
|
|
488
499
|
value = inlineUrl;
|
|
489
500
|
}
|
|
@@ -535,9 +546,8 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
535
546
|
value = quote + value + quote;
|
|
536
547
|
}
|
|
537
548
|
const revised = isJs ? 'import(' + value + trailing + ')' : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
538
|
-
source = spliceString(source, startIndex, i + 1, revised);
|
|
549
|
+
source = (0, util_1.spliceString)(source, startIndex, i + 1, revised, pattern);
|
|
539
550
|
length = source.length;
|
|
540
|
-
pattern.lastIndex = startIndex + revised.length;
|
|
541
551
|
modified = true;
|
|
542
552
|
};
|
|
543
553
|
let url;
|
|
@@ -560,18 +570,18 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
560
570
|
if (url.startsWith('data:')) {
|
|
561
571
|
const base64 = url.split(',')[1]?.trim();
|
|
562
572
|
if (base64) {
|
|
563
|
-
for (const item of
|
|
573
|
+
for (const item of instance.assets) {
|
|
564
574
|
if (item.base64 === base64) {
|
|
565
|
-
setOutputURL(getSrcURL
|
|
575
|
+
setOutputURL(getSrcURL(instance, parent, item)[0], item);
|
|
566
576
|
break;
|
|
567
577
|
}
|
|
568
578
|
}
|
|
569
579
|
}
|
|
570
580
|
}
|
|
571
|
-
else if (baseHref.length) {
|
|
581
|
+
else if (baseHref.length > 0) {
|
|
572
582
|
let fullUrl, asset;
|
|
573
583
|
for (const parentUrl of baseHref) {
|
|
574
|
-
if (asset = host.findAsset(fullUrl = resolvePath(url, parentUrl), { replaced: true }) || (
|
|
584
|
+
if (asset = host.findAsset(fullUrl = Document.resolvePath(url, parentUrl), { replaced: true }) || (instance.related.has(parent) ? host.findAsset(fullUrl, { assets: Array.from(instance.related.get(parent)), replaced: true }) : undefined)) {
|
|
575
585
|
break;
|
|
576
586
|
}
|
|
577
587
|
}
|
|
@@ -595,13 +605,13 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
595
605
|
break;
|
|
596
606
|
}
|
|
597
607
|
}
|
|
598
|
-
const layer =
|
|
608
|
+
const layer = instance.replaceContent(revised, source.substring(k, l + 1), "text/css");
|
|
599
609
|
if (layer) {
|
|
600
610
|
revised = layer;
|
|
601
611
|
}
|
|
602
|
-
|
|
612
|
+
revised = transformURL(instance, host, parent, type, instance.removeServerRoot(revised), asset) || revised;
|
|
613
|
+
source = (0, util_1.spliceString)(source, k, l + 1, revised, pattern);
|
|
603
614
|
length = source.length;
|
|
604
|
-
pattern.lastIndex = k + revised.length;
|
|
605
615
|
if (!parent.watch) {
|
|
606
616
|
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
607
617
|
asset.invalid = true;
|
|
@@ -618,7 +628,7 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
618
628
|
}
|
|
619
629
|
if (hasSameOrigin(asset.url || fullUrl, ...baseHref)) {
|
|
620
630
|
let sameDir;
|
|
621
|
-
[fullUrl, sameDir] = getSrcURL
|
|
631
|
+
[fullUrl, sameDir] = getSrcURL(instance, parent, asset);
|
|
622
632
|
if (sameDir && isJs) {
|
|
623
633
|
fullUrl = './' + fullUrl;
|
|
624
634
|
}
|
|
@@ -630,7 +640,7 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
630
640
|
}
|
|
631
641
|
}
|
|
632
642
|
else if (!asset.invalid) {
|
|
633
|
-
fullUrl = asset.inlineBase64 ||= (0,
|
|
643
|
+
fullUrl = asset.inlineBase64 ||= (0, crypto_1.randomUUID)();
|
|
634
644
|
}
|
|
635
645
|
if (url !== fullUrl) {
|
|
636
646
|
setOutputURL(fullUrl, asset);
|
|
@@ -642,34 +652,33 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
642
652
|
}
|
|
643
653
|
}
|
|
644
654
|
if (modified) {
|
|
645
|
-
if (related.length) {
|
|
646
|
-
const previous =
|
|
655
|
+
if (related.length > 0) {
|
|
656
|
+
const previous = instance.related.get(parent);
|
|
647
657
|
if (previous) {
|
|
648
|
-
|
|
658
|
+
for (const item of related) {
|
|
659
|
+
previous.add(item);
|
|
660
|
+
}
|
|
649
661
|
}
|
|
650
662
|
else {
|
|
651
|
-
|
|
663
|
+
instance.related.set(parent, new Set(related));
|
|
652
664
|
}
|
|
653
665
|
}
|
|
654
666
|
return source;
|
|
655
667
|
}
|
|
656
668
|
}
|
|
657
|
-
function getFormatUUID(attr, ext) {
|
|
658
|
-
const format = 'formatMap' in
|
|
669
|
+
function getFormatUUID(instance, attr, ext) {
|
|
670
|
+
const format = 'formatMap' in instance ? instance.formatMap : instance.module.format;
|
|
659
671
|
let pattern;
|
|
660
|
-
|
|
661
|
-
return (0, types_1.randomString)(pattern[attr], pattern.dictionary);
|
|
662
|
-
}
|
|
663
|
-
return (0, types_1.generateUUID)();
|
|
672
|
+
return (0, types_1.isObject)(format) && (0, types_1.isObject)(pattern = ext && ext in format ? format[ext] : format.uuid) && pattern[attr] ? (0, types_1.randomString)(pattern[attr], pattern.dictionary) : (0, crypto_1.randomUUID)();
|
|
664
673
|
}
|
|
665
|
-
function setLocationUUID(data, file, ext) {
|
|
674
|
+
function setLocationUUID(instance, data, file, ext) {
|
|
666
675
|
const { pathname, filename } = data;
|
|
667
676
|
const assignUUID = ChromeDocument.INTERNAL_ASSIGNUUID;
|
|
668
677
|
let index, modified;
|
|
669
678
|
if (filename) {
|
|
670
679
|
ext ||= path.extname(filename).substring(1);
|
|
671
680
|
if ((index = filename.indexOf(assignUUID)) !== -1) {
|
|
672
|
-
data.filename = spliceString(filename, index, index + assignUUID.length, getFormatUUID
|
|
681
|
+
data.filename = (0, util_1.spliceString)(filename, index, index + assignUUID.length, getFormatUUID(instance, 'filename', ext));
|
|
673
682
|
if (file) {
|
|
674
683
|
file.inlineFilename = data.filename;
|
|
675
684
|
}
|
|
@@ -677,7 +686,7 @@ function setLocationUUID(data, file, ext) {
|
|
|
677
686
|
}
|
|
678
687
|
}
|
|
679
688
|
if (pathname && (index = pathname.indexOf(assignUUID)) !== -1) {
|
|
680
|
-
data.pathname = spliceString(pathname, index, index + assignUUID.length, getFormatUUID
|
|
689
|
+
data.pathname = (0, util_1.spliceString)(pathname, index, index + assignUUID.length, getFormatUUID(instance, 'pathname', ext));
|
|
681
690
|
modified = true;
|
|
682
691
|
}
|
|
683
692
|
if (file && modified) {
|
|
@@ -687,14 +696,14 @@ function setLocationUUID(data, file, ext) {
|
|
|
687
696
|
}
|
|
688
697
|
}
|
|
689
698
|
}
|
|
690
|
-
function transformOptions(file, mimeType, code, bundleContent) {
|
|
699
|
+
function transformOptions(instance, file, mimeType, code, bundleContent) {
|
|
691
700
|
const { uri, localUri, exported } = file;
|
|
692
|
-
const metadata = { userAgentData:
|
|
701
|
+
const metadata = { userAgentData: instance.userAgentData };
|
|
693
702
|
switch (mimeType) {
|
|
694
|
-
case
|
|
703
|
+
case "text/html":
|
|
695
704
|
metadata.__fromhtml__ = true;
|
|
696
|
-
case
|
|
697
|
-
Object.assign(metadata,
|
|
705
|
+
case "text/css":
|
|
706
|
+
Object.assign(metadata, instance.config);
|
|
698
707
|
default:
|
|
699
708
|
if ((0, types_1.isObject)(file.metadata)) {
|
|
700
709
|
Object.assign(metadata, file.metadata);
|
|
@@ -703,35 +712,35 @@ function transformOptions(file, mimeType, code, bundleContent) {
|
|
|
703
712
|
}
|
|
704
713
|
const [pathname, filename] = localUri ? [path.dirname(localUri), path.basename(localUri)] : ['', file.filename];
|
|
705
714
|
const options = { pathname, filename, mimeType, metadata, imported: !!file.imports && file.imported !== false };
|
|
706
|
-
const sourceFile = !exported && uri &&
|
|
715
|
+
const sourceFile = !exported && uri && instance.findSourceRoot(uri);
|
|
707
716
|
if (sourceFile) {
|
|
708
|
-
if (isPath(sourceFile)) {
|
|
717
|
+
if (Document.isPath(sourceFile)) {
|
|
709
718
|
options.sourceFile = sourceFile;
|
|
710
719
|
}
|
|
711
720
|
options.sourceName = path.basename(sourceFile);
|
|
712
721
|
options.sourcesRelativeTo = path.dirname(sourceFile);
|
|
713
|
-
options.getMainFile =
|
|
722
|
+
options.getMainFile = instance.resolveSourceFile(file);
|
|
714
723
|
if (code) {
|
|
715
|
-
options.getSourceFiles =
|
|
724
|
+
options.getSourceFiles = instance.locateSourceFiles(file, code, bundleContent);
|
|
716
725
|
}
|
|
717
726
|
}
|
|
718
|
-
if ((!
|
|
727
|
+
if ((!instance.productionRelease || instance.productionIncremental) && !(0, types_1.modifiedFlag)(file.flags)) {
|
|
719
728
|
options.cacheData = { uri: !exported ? uri : undefined, etag: !file.modified ? file.etag : undefined, encoding: file.encoding };
|
|
720
729
|
}
|
|
721
730
|
return options;
|
|
722
731
|
}
|
|
723
|
-
function transformJs(host, file, output) {
|
|
732
|
+
function transformJs(instance, host, file, output) {
|
|
724
733
|
const { sourceFiles, chunks, map } = output;
|
|
725
734
|
const localUri = file.localUri;
|
|
726
|
-
const emptySources = !!
|
|
735
|
+
const emptySources = !!instance.productionRelease;
|
|
727
736
|
let uri;
|
|
728
|
-
if (map && (uri = writeSourceMap(localUri, output, { hash: file.hash, emptySources, inlineMap: hasSourceMap(file.metadata, 'inline') }))) {
|
|
737
|
+
if (map && (uri = Document.writeSourceMap(localUri, output, { hash: file.hash, emptySources, inlineMap: hasSourceMap(file.metadata, 'inline') }))) {
|
|
729
738
|
host.add(uri, file, types_1.FILE_TYPE.SOURCEMAP);
|
|
730
739
|
}
|
|
731
740
|
if (chunks) {
|
|
732
|
-
const elements =
|
|
741
|
+
const elements = instance.elements;
|
|
733
742
|
const localDir = path.dirname(localUri);
|
|
734
|
-
const relativeDir = joinPath(file.moveTo, file.pathname);
|
|
743
|
+
const relativeDir = Document.joinPath(file.moveTo, file.pathname);
|
|
735
744
|
const element = file.element;
|
|
736
745
|
let order = 0, index, appending;
|
|
737
746
|
if (element) {
|
|
@@ -746,11 +755,11 @@ function transformJs(host, file, output) {
|
|
|
746
755
|
for (const chunk of chunks) {
|
|
747
756
|
let chunkName = chunk.filename;
|
|
748
757
|
if (!chunkName) {
|
|
749
|
-
chunkName = getFormatUUID
|
|
758
|
+
chunkName = getFormatUUID(instance, 'filename', 'js') + path.extname(localUri);
|
|
750
759
|
chunk.entryPoint = true;
|
|
751
760
|
}
|
|
752
761
|
const chunkUri = path.join(localDir, chunkName);
|
|
753
|
-
if (chunk.map && (uri = writeSourceMap(chunkUri, chunk, { emptySources, inlineMap: hasSourceMap(file.metadata, 'inline') }))) {
|
|
762
|
+
if (chunk.map && (uri = Document.writeSourceMap(chunkUri, chunk, { emptySources, inlineMap: hasSourceMap(file.metadata, 'inline') }))) {
|
|
754
763
|
host.add(uri, file, types_1.FILE_TYPE.SOURCEMAP);
|
|
755
764
|
}
|
|
756
765
|
try {
|
|
@@ -758,7 +767,7 @@ function transformJs(host, file, output) {
|
|
|
758
767
|
host.add(chunkUri, file);
|
|
759
768
|
if (chunk.entryPoint) {
|
|
760
769
|
if (element) {
|
|
761
|
-
const attributes = { ...file.attributes, src: joinPath(relativeDir, chunkName) };
|
|
770
|
+
const attributes = { ...file.attributes, src: Document.joinPath(relativeDir, chunkName) };
|
|
762
771
|
if (file.imports && file.imported !== false) {
|
|
763
772
|
attributes.type ||= 'module';
|
|
764
773
|
}
|
|
@@ -769,15 +778,17 @@ function transformJs(host, file, output) {
|
|
|
769
778
|
});
|
|
770
779
|
}
|
|
771
780
|
else {
|
|
772
|
-
|
|
781
|
+
instance.writeFail(['Unable to create script entry point', path.basename(chunkUri)], (0, types_1.errorMessage)('js', 'Element not found', chunkUri), 4);
|
|
773
782
|
}
|
|
774
783
|
}
|
|
775
784
|
}
|
|
776
785
|
catch (err) {
|
|
777
|
-
|
|
786
|
+
instance.writeFail(["Unable to write file", path.basename(chunkUri)], err, 32);
|
|
778
787
|
}
|
|
779
788
|
}
|
|
780
|
-
appending?.forEach(item =>
|
|
789
|
+
appending?.forEach(item => {
|
|
790
|
+
item.order += order;
|
|
791
|
+
});
|
|
781
792
|
}
|
|
782
793
|
if ((0, types_1.isArray)(sourceFiles)) {
|
|
783
794
|
file.sourceFiles = sourceFiles;
|
|
@@ -785,41 +796,40 @@ function transformJs(host, file, output) {
|
|
|
785
796
|
file.modified = true;
|
|
786
797
|
return file.sourceUTF8 = output.code;
|
|
787
798
|
}
|
|
788
|
-
function replaceCss(file) {
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
map[id] = this.removeServerRoot(map[id]);
|
|
792
|
-
}
|
|
793
|
-
};
|
|
794
|
-
const { inlineUrlMap, inlineUrlCloudMap } = file;
|
|
795
|
-
if (inlineUrlMap) {
|
|
796
|
-
sanitize(inlineUrlMap);
|
|
799
|
+
function replaceCss(instance, file) {
|
|
800
|
+
if (file.inlineUrlMap) {
|
|
801
|
+
sanitizeCss(instance, file.inlineUrlMap);
|
|
797
802
|
}
|
|
798
|
-
if (inlineUrlCloudMap) {
|
|
799
|
-
|
|
803
|
+
if (file.inlineUrlCloudMap) {
|
|
804
|
+
sanitizeCss(instance, file.inlineUrlCloudMap);
|
|
800
805
|
}
|
|
801
806
|
}
|
|
802
|
-
function
|
|
803
|
-
const
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
};
|
|
807
|
+
function sanitizeCss(instance, map) {
|
|
808
|
+
for (const id in map) {
|
|
809
|
+
map[id] = instance.removeServerRoot(map[id]);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
function replaceHtml(instance, source, { productionRelease, contentMap }, cssMap) {
|
|
809
813
|
if (cssMap) {
|
|
810
|
-
source =
|
|
814
|
+
source = finalizeHtml(source, cssMap);
|
|
811
815
|
}
|
|
812
|
-
source =
|
|
813
|
-
return productionRelease ?
|
|
816
|
+
source = finalizeHtml(source, contentMap);
|
|
817
|
+
return productionRelease ? instance.removeServerRoot(source) : source;
|
|
814
818
|
}
|
|
815
|
-
function
|
|
819
|
+
function finalizeHtml(value, data) {
|
|
820
|
+
for (const id in data) {
|
|
821
|
+
value = value.replace(new RegExp((0, types_1.escapePattern)(id), 'g'), data[id]);
|
|
822
|
+
}
|
|
823
|
+
return value;
|
|
824
|
+
}
|
|
825
|
+
function isWatched(instance, file) {
|
|
816
826
|
const { initialValue, format } = file;
|
|
817
|
-
if (file.imported || file.bundleReplace || file.inlineContent || file.inlineBase64 ||
|
|
827
|
+
if (file.imported || file.bundleReplace || file.inlineContent || file.inlineBase64 || instance.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'))) {
|
|
818
828
|
return true;
|
|
819
829
|
}
|
|
820
830
|
return false;
|
|
821
831
|
}
|
|
822
|
-
function loadLocalFile(item, pathname, cacheData, encoding, out) {
|
|
832
|
+
function loadLocalFile(instance, item, pathname, cacheData, encoding, out) {
|
|
823
833
|
let content;
|
|
824
834
|
encoding = (0, types_1.getEncoding)(encoding);
|
|
825
835
|
if (out) {
|
|
@@ -831,15 +841,15 @@ function loadLocalFile(item, pathname, cacheData, encoding, out) {
|
|
|
831
841
|
return require(pathname);
|
|
832
842
|
}
|
|
833
843
|
content ||= fs.readFileSync(pathname, encoding);
|
|
834
|
-
const result =
|
|
844
|
+
const result = instance.tryParse(content, ext);
|
|
835
845
|
if (result !== undefined && result !== null) {
|
|
836
|
-
setCacheData
|
|
846
|
+
setCacheData(instance, item, result, pathname, cacheData, true);
|
|
837
847
|
return result;
|
|
838
848
|
}
|
|
839
849
|
}
|
|
840
|
-
function setCacheData(item, data, dataKey, cacheData, template) {
|
|
850
|
+
function setCacheData(instance, item, data, dataKey, cacheData, template) {
|
|
841
851
|
if ((0, types_1.isObject)(data) || template) {
|
|
842
|
-
const cache =
|
|
852
|
+
const cache = instance.settingsOf(item.source, template && item.source !== 'local' ? 'local_file' : 'cache');
|
|
843
853
|
let timeout;
|
|
844
854
|
if (cache && (timeout = core_1.ClientDb.getTimeout(cache)) && timeout > 0) {
|
|
845
855
|
addCacheItem(template ? CACHE_LOCALFILE : CACHE_DBRESULT, dataKey, data, timeout);
|
|
@@ -849,11 +859,11 @@ function setCacheData(item, data, dataKey, cacheData, template) {
|
|
|
849
859
|
}
|
|
850
860
|
}
|
|
851
861
|
}
|
|
852
|
-
async function checkData(item, name, result, validate) {
|
|
862
|
+
async function checkData(instance, item, name, result, validate) {
|
|
853
863
|
let callback;
|
|
854
864
|
if (typeof name === 'string') {
|
|
855
|
-
const template =
|
|
856
|
-
callback =
|
|
865
|
+
const template = instance.findDataValue(name) || name;
|
|
866
|
+
callback = instance.hasEval('userconfig') ? Document.parseFunction(template, instance.hasEval('absolute')) : (0, types_1.asFunction)(template);
|
|
857
867
|
}
|
|
858
868
|
else {
|
|
859
869
|
callback = name;
|
|
@@ -873,32 +883,41 @@ async function checkData(item, name, result, validate) {
|
|
|
873
883
|
}
|
|
874
884
|
}
|
|
875
885
|
catch (err) {
|
|
876
|
-
|
|
886
|
+
instance.writeFail(["Unable to parse inline method", name], err);
|
|
877
887
|
}
|
|
878
888
|
}
|
|
879
889
|
}
|
|
880
|
-
|
|
890
|
+
function removeElement(instance, domBase, item, element) {
|
|
891
|
+
if (item.removeEmpty || item.type === 'display') {
|
|
892
|
+
(element ||= new dom_1.HtmlElement(instance.moduleName, item.element)).remove = true;
|
|
893
|
+
if (!domBase.write(element)) {
|
|
894
|
+
instance.writeFail('Unable to remove element', errorHtml(item.element), { type: 4 });
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
function errorCredential(instance, domBase, item, err) {
|
|
899
|
+
removeElement(instance, domBase, item);
|
|
900
|
+
const pkg = getPackageName(err);
|
|
901
|
+
if (!(pkg && instance.checkPackage(err, pkg))) {
|
|
902
|
+
instance.writeFail(["Invalid credentials", item.source], err);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
881
905
|
const isSpace = dom_1.DomWriter.isSpace.bind(dom_1.DomWriter);
|
|
882
906
|
const replaceMatch = dom_1.DomWriter.replaceMatch.bind(dom_1.DomWriter);
|
|
883
|
-
const
|
|
884
|
-
const
|
|
885
|
-
const writeSourceMap = Document.writeSourceMap.bind(Document);
|
|
886
|
-
const asString = Document.asString.bind(Document);
|
|
887
|
-
const resolvePath = Document.resolvePath.bind(Document);
|
|
888
|
-
const toPosix = Document.toPosix.bind(Document);
|
|
889
|
-
const isDir = Document.isDir.bind(Document);
|
|
890
|
-
const getBuffer = (item, localUri) => item.sourceUTF8 || item.buffer || ((localUri ||= item.localUri) && isPath(localUri) ? fs.readFileSync(localUri, item.encoding) : null);
|
|
907
|
+
const getNewlineString = dom_1.DomWriter.getNewlineString.bind(dom_1.DomWriter);
|
|
908
|
+
const getBuffer = (item, localUri) => item.sourceUTF8 || item.buffer || ((localUri ||= item.localUri) && Document.isPath(localUri) ? fs.readFileSync(localUri, item.encoding) : null);
|
|
891
909
|
const hasSourceMap = (metadata, value) => (0, types_1.isObject)(metadata) && metadata.__sourcemap__ === value;
|
|
892
910
|
const isBundled = (value, main) => typeof value === 'number' && (value > 0 || main && value === 0);
|
|
893
911
|
const isFont = (value) => value === 'truetype' || value === 'opentype' || value === 'woff' || value === 'woff2';
|
|
894
|
-
const isImage = (value) => typeof value === 'string' && value.startsWith('image/') && value !==
|
|
912
|
+
const isImage = (value) => typeof value === 'string' && value.startsWith('image/') && value !== "image/svg+xml";
|
|
895
913
|
const isRemoved = (item) => item.exclude === true || isBundled(item.bundleIndex);
|
|
896
914
|
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'));
|
|
897
915
|
const isIgnored = (item, exists) => item.invalid || (0, types_1.ignoreFlag)(item.flags) || !exists && (0, types_1.existsFlag)(item.flags);
|
|
898
916
|
const findFont = (value) => value && (Array.isArray(value) ? value : [value]).find(format => isFont(format));
|
|
899
|
-
const spliceString = (source, startIndex, endIndex, content) => source.substring(0, startIndex) + content + source.substring(endIndex);
|
|
900
917
|
const getEndIndex = (match) => match.index + match[0].length;
|
|
901
|
-
const getRelativeURL = (file) => joinPath(file.moveTo, file.pathname, file.inlineFilename || file.filename) + (!file.static ? restoreSearchParams(file.url?.search) : '');
|
|
918
|
+
const getRelativeURL = (file) => Document.joinPath(file.moveTo, file.pathname, file.inlineFilename || file.filename) + (!file.static ? restoreSearchParams(file.url?.search) : '');
|
|
919
|
+
const validateDir = (value) => path.isAbsolute(value) && Document.isDir(value) ? value : '';
|
|
920
|
+
const valueAsString = (value, delimiter) => Array.isArray(value) && !value.some(child => typeof child === 'object') ? value.join(delimiter) : Document.asString(value);
|
|
902
921
|
const errorHtml = ({ tagName, tagIndex = -1 }) => (0, types_1.errorMessage)('html', 'Location did not resolve', tagName.toLowerCase() + (tagIndex >= 0 ? ': ' + tagIndex : ''));
|
|
903
922
|
const errorDataSource = (value, hint) => (0, types_1.errorMessage)('data-source', value, hint);
|
|
904
923
|
const isHtmlOnly = (assets, items, htmlFile) => !items.find(item => item !== htmlFile && assets.includes(item));
|
|
@@ -964,7 +983,7 @@ class ChromeDocument extends Document {
|
|
|
964
983
|
if (outHtml) {
|
|
965
984
|
const { etag, initialValue } = htmlFile;
|
|
966
985
|
let buffer;
|
|
967
|
-
if (!initialValue || !(etag && initialValue.etag === etag && (buffer = initialValue.buffer)) || fetched.find(item => item !== htmlFile && item.etag && CACHE_ETAG.get(item.localUri) !== item.etag && (item.inlineContent || item.bundleReplace && (!
|
|
986
|
+
if (!initialValue || !(etag && initialValue.etag === etag && (buffer = initialValue.buffer)) || fetched.find(item => item !== htmlFile && item.etag && CACHE_ETAG.get(item.localUri) !== item.etag && (item.inlineContent || item.bundleReplace && (!Array.isArray(item.from) || item.from.includes('style'))))) {
|
|
968
987
|
const isValid = (item) => !!item.localUri && item !== htmlFile && !item.invalid;
|
|
969
988
|
for (const item of fetched) {
|
|
970
989
|
if (item.etag && !item.content && isValid(item)) {
|
|
@@ -1025,7 +1044,7 @@ class ChromeDocument extends Document {
|
|
|
1025
1044
|
const js = instance.jsFiles.filter(item => wasModified(item) || !!item.imports);
|
|
1026
1045
|
const css = instance.cssFiles.filter(wasModified);
|
|
1027
1046
|
const svg = instance.svgFiles.filter(wasModified);
|
|
1028
|
-
if (js.length || css.length || svg.length) {
|
|
1047
|
+
if (js.length > 0 || css.length > 0 || svg.length > 0) {
|
|
1029
1048
|
instance.jsFiles = js;
|
|
1030
1049
|
instance.cssFiles = css;
|
|
1031
1050
|
instance.svgFiles = svg;
|
|
@@ -1044,7 +1063,7 @@ class ChromeDocument extends Document {
|
|
|
1044
1063
|
}
|
|
1045
1064
|
}
|
|
1046
1065
|
instance.setInlinedAttributes(processing);
|
|
1047
|
-
if (instance.editing.length) {
|
|
1066
|
+
if (instance.editing.length > 0) {
|
|
1048
1067
|
await instance.applyTransforms(processing);
|
|
1049
1068
|
if (instance.aborted) {
|
|
1050
1069
|
return (0, types_1.createAbortError)(true);
|
|
@@ -1074,7 +1093,7 @@ class ChromeDocument extends Document {
|
|
|
1074
1093
|
(function recurse(children) {
|
|
1075
1094
|
for (const item of children) {
|
|
1076
1095
|
if (!items.has(item)) {
|
|
1077
|
-
if (isWatched
|
|
1096
|
+
if (isWatched(instance, item)) {
|
|
1078
1097
|
item.flags |= 8;
|
|
1079
1098
|
}
|
|
1080
1099
|
items.add(item);
|
|
@@ -1089,40 +1108,126 @@ class ChromeDocument extends Document {
|
|
|
1089
1108
|
}
|
|
1090
1109
|
}
|
|
1091
1110
|
}
|
|
1092
|
-
|
|
1111
|
+
const productionRelease = instance.productionRelease;
|
|
1093
1112
|
if ((0, types_1.isString)(productionRelease)) {
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1113
|
+
const errorDirectory = (value) => {
|
|
1114
|
+
instance.writeFail(["Unable to read directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Invalid directory', value), 32);
|
|
1115
|
+
};
|
|
1116
|
+
const errorAccess = (value) => {
|
|
1117
|
+
instance.writeFail(["Unable to write directory", instance.moduleName], (0, types_1.errorMessage)('production', "Unsupported access", value), 8192);
|
|
1118
|
+
};
|
|
1119
|
+
const errorMove = (err) => {
|
|
1120
|
+
instance.writeFail(["Unable to move file", instance.moduleName], err, { type: 32, fatal: true });
|
|
1121
|
+
};
|
|
1122
|
+
const outputDir = validateDir(productionRelease);
|
|
1123
|
+
if (outputDir) {
|
|
1124
|
+
if (this.canWrite(outputDir)) {
|
|
1125
|
+
const srcDir = path.join(this.baseDirectory, ChromeDocument.INTERNAL_SERVERROOT);
|
|
1126
|
+
if (Document.isDir(srcDir)) {
|
|
1127
|
+
const serverRootMapping = instance.serverRootMapping;
|
|
1128
|
+
const mapped = [];
|
|
1129
|
+
for (const localDir in serverRootMapping) {
|
|
1130
|
+
const subDir = serverRootMapping[localDir];
|
|
1131
|
+
const destDir = validateDir(Document.normalizePath(/[\\/]$/.test(subDir) ? path.join(outputDir, subDir, localDir) : path.join(outputDir, subDir), true));
|
|
1132
|
+
if (destDir.startsWith(outputDir)) {
|
|
1133
|
+
if (this.canWrite(destDir)) {
|
|
1134
|
+
mapped.push([Document.normalizePath(localDir, true), destDir, 0]);
|
|
1135
|
+
}
|
|
1136
|
+
else {
|
|
1137
|
+
errorAccess(localDir);
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
else {
|
|
1142
|
+
errorDirectory(localDir);
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
if (mapped.length > 0) {
|
|
1147
|
+
const emptyDir = new Set();
|
|
1148
|
+
for (const value of this.files) {
|
|
1149
|
+
if (value.startsWith(ChromeDocument.INTERNAL_SERVERROOT)) {
|
|
1150
|
+
const subDir = value.split(path.sep).slice(1);
|
|
1151
|
+
const start = subDir.length - 1;
|
|
1152
|
+
for (let i = start; i > 0; --i) {
|
|
1153
|
+
const localDir = subDir.slice(0, i).join(path.sep) + path.sep;
|
|
1154
|
+
const target = mapped.find(item => item[0] === localDir);
|
|
1155
|
+
if (target) {
|
|
1156
|
+
const src = path.join(this.baseDirectory, value);
|
|
1157
|
+
try {
|
|
1158
|
+
let destDir = target[1];
|
|
1159
|
+
if (i !== start && !Document.createDir(destDir = path.join(destDir, ...subDir.slice(i, start)))) {
|
|
1160
|
+
throw (0, types_1.errorMessage)('production', destDir, 'create');
|
|
1161
|
+
}
|
|
1162
|
+
const dest = path.join(destDir, subDir[subDir.length - 1]);
|
|
1163
|
+
Document.renameFile(src, dest);
|
|
1164
|
+
instance.addLog(types_1.STATUS_TYPE.INFO, `production: ${dest} (mapped)`, instance.moduleName, subDir.join(path.sep));
|
|
1165
|
+
emptyDir.add(path.dirname(src));
|
|
1166
|
+
if (i !== start) {
|
|
1167
|
+
for (let j = 0; j < i; ++j) {
|
|
1168
|
+
emptyDir.add(path.join(this.baseDirectory, ChromeDocument.INTERNAL_SERVERROOT, ...subDir.slice(0, j + 1)));
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
++target[2];
|
|
1172
|
+
}
|
|
1173
|
+
catch (err) {
|
|
1174
|
+
errorMove(err);
|
|
1175
|
+
if (Document.isPath(src)) {
|
|
1176
|
+
fs.unlink(src, error => {
|
|
1177
|
+
if (error) {
|
|
1178
|
+
instance.addLog(types_1.STATUS_TYPE.WARN, error);
|
|
1179
|
+
}
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
finally {
|
|
1184
|
+
this.delete(value);
|
|
1185
|
+
}
|
|
1186
|
+
break;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
for (const item of mapped) {
|
|
1192
|
+
if (item[2] === 0) {
|
|
1193
|
+
instance.addLog(types_1.STATUS_TYPE.INFO, `production: ${item[1]} (mapped: 0)`, instance.moduleName, item[0]);
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
for (const pathname of Array.from(emptyDir).sort((a, b) => b.length - a.length)) {
|
|
1197
|
+
try {
|
|
1198
|
+
fs.rmdirSync(pathname);
|
|
1199
|
+
}
|
|
1200
|
+
catch {
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
const result = await Document.copyDir(srcDir, outputDir, this.incremental !== 'staging');
|
|
1100
1205
|
const failed = result.failed.map(value => this.removeCwd(value));
|
|
1101
1206
|
for (const value of this.files) {
|
|
1102
|
-
if (value.startsWith(
|
|
1207
|
+
if (value.startsWith(ChromeDocument.INTERNAL_SERVERROOT)) {
|
|
1103
1208
|
if (!failed.includes(value)) {
|
|
1104
1209
|
this.delete(value);
|
|
1105
1210
|
}
|
|
1106
1211
|
else {
|
|
1107
|
-
|
|
1212
|
+
errorMove((0, types_1.errorMessage)('production', path.join(this.baseDirectory, value), 'move'));
|
|
1108
1213
|
}
|
|
1109
1214
|
}
|
|
1110
1215
|
}
|
|
1111
1216
|
}
|
|
1112
1217
|
}
|
|
1113
1218
|
else {
|
|
1114
|
-
|
|
1219
|
+
errorAccess(productionRelease);
|
|
1115
1220
|
}
|
|
1116
1221
|
}
|
|
1117
1222
|
else {
|
|
1118
|
-
|
|
1223
|
+
errorDirectory(productionRelease);
|
|
1119
1224
|
}
|
|
1120
1225
|
}
|
|
1121
1226
|
}
|
|
1122
1227
|
static sanitizeAssets(assets, exclusions = []) {
|
|
1123
|
-
|
|
1228
|
+
for (const item of assets) {
|
|
1124
1229
|
if ((0, types_1.ignoreFlag)(item.flags)) {
|
|
1125
|
-
|
|
1230
|
+
continue;
|
|
1126
1231
|
}
|
|
1127
1232
|
for (const attr in item) {
|
|
1128
1233
|
switch (attr) {
|
|
@@ -1140,7 +1245,8 @@ class ChromeDocument extends Document {
|
|
|
1140
1245
|
break;
|
|
1141
1246
|
}
|
|
1142
1247
|
}
|
|
1143
|
-
}
|
|
1248
|
+
}
|
|
1249
|
+
return assets;
|
|
1144
1250
|
}
|
|
1145
1251
|
config = {
|
|
1146
1252
|
usedVariables: undefined,
|
|
@@ -1169,6 +1275,8 @@ class ChromeDocument extends Document {
|
|
|
1169
1275
|
baseUrl = '';
|
|
1170
1276
|
productionRelease = false;
|
|
1171
1277
|
productionIncremental = false;
|
|
1278
|
+
serverRootMapping = undefined;
|
|
1279
|
+
sanitizeFramework = undefined;
|
|
1172
1280
|
templateMap = {};
|
|
1173
1281
|
userAgentData = {};
|
|
1174
1282
|
related = new Map();
|
|
@@ -1182,7 +1290,7 @@ class ChromeDocument extends Document {
|
|
|
1182
1290
|
_cloudUrlMap;
|
|
1183
1291
|
_cloudUploaded;
|
|
1184
1292
|
_cloudEndpoint;
|
|
1185
|
-
_idMap =
|
|
1293
|
+
_idMap = {};
|
|
1186
1294
|
_editing = [];
|
|
1187
1295
|
_queryMap = new Map();
|
|
1188
1296
|
_selectorMap = new Map();
|
|
@@ -1206,7 +1314,7 @@ class ChromeDocument extends Document {
|
|
|
1206
1314
|
}
|
|
1207
1315
|
if (item.editing) {
|
|
1208
1316
|
switch (item.mimeType) {
|
|
1209
|
-
case
|
|
1317
|
+
case "text/html":
|
|
1210
1318
|
if (!this.htmlFile) {
|
|
1211
1319
|
this.htmlFile = item;
|
|
1212
1320
|
item.editing = true;
|
|
@@ -1216,15 +1324,15 @@ class ChromeDocument extends Document {
|
|
|
1216
1324
|
item.editing = false;
|
|
1217
1325
|
}
|
|
1218
1326
|
break;
|
|
1219
|
-
case
|
|
1327
|
+
case "text/css":
|
|
1220
1328
|
this.cssFiles.push(item);
|
|
1221
1329
|
this._editing.push(item);
|
|
1222
1330
|
break;
|
|
1223
|
-
case
|
|
1224
|
-
|
|
1331
|
+
case "text/javascript":
|
|
1332
|
+
item.mimeType = "application/javascript";
|
|
1333
|
+
case "application/javascript":
|
|
1225
1334
|
this.jsFiles.push(item);
|
|
1226
1335
|
this._editing.push(item);
|
|
1227
|
-
item.mimeType = 'application/javascript';
|
|
1228
1336
|
break;
|
|
1229
1337
|
}
|
|
1230
1338
|
}
|
|
@@ -1240,7 +1348,7 @@ class ChromeDocument extends Document {
|
|
|
1240
1348
|
});
|
|
1241
1349
|
let imports;
|
|
1242
1350
|
if (config) {
|
|
1243
|
-
const { useUnsafeReplace, baseUrl, productionRelease, productionIncremental, templateMap, userAgentData, cache } = config;
|
|
1351
|
+
const { useUnsafeReplace, baseUrl, productionRelease, productionIncremental, serverRootMapping, templateMap, sanitizeFramework, userAgentData, cache } = config;
|
|
1244
1352
|
const target = this.config;
|
|
1245
1353
|
for (const attr in config) {
|
|
1246
1354
|
if (attr in target) {
|
|
@@ -1273,12 +1381,31 @@ class ChromeDocument extends Document {
|
|
|
1273
1381
|
catch {
|
|
1274
1382
|
}
|
|
1275
1383
|
}
|
|
1276
|
-
if (
|
|
1277
|
-
this.productionRelease = productionRelease;
|
|
1384
|
+
if ((0, types_1.isString)(productionRelease)) {
|
|
1385
|
+
this.productionRelease = Document.normalizePath(productionRelease, 2);
|
|
1386
|
+
const baseDir = Document.normalizePath(this.productionRelease, 1 | 2);
|
|
1387
|
+
let baseMap;
|
|
1388
|
+
found: {
|
|
1389
|
+
for (const map of [this.getUserSettings()?.server_root, this.settings.server_root]) {
|
|
1390
|
+
for (const pathname in map) {
|
|
1391
|
+
if (Document.normalizePath(pathname, 1 | 2) === baseDir && (0, types_1.isObject)(map[pathname])) {
|
|
1392
|
+
baseMap = map[pathname];
|
|
1393
|
+
break found;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
this.serverRootMapping = (0, types_1.isObject)(serverRootMapping) ? baseMap ? Object.assign(baseMap, serverRootMapping) : serverRootMapping : baseMap;
|
|
1399
|
+
}
|
|
1400
|
+
else if (productionRelease) {
|
|
1401
|
+
this.productionRelease = true;
|
|
1278
1402
|
}
|
|
1279
1403
|
if (productionIncremental) {
|
|
1280
1404
|
this.productionIncremental = true;
|
|
1281
1405
|
}
|
|
1406
|
+
if ((0, types_1.isArray)(sanitizeFramework)) {
|
|
1407
|
+
this.sanitizeFramework = sanitizeFramework;
|
|
1408
|
+
}
|
|
1282
1409
|
if ((0, types_1.isObject)(templateMap)) {
|
|
1283
1410
|
this.templateMap = templateMap;
|
|
1284
1411
|
}
|
|
@@ -1319,10 +1446,10 @@ class ChromeDocument extends Document {
|
|
|
1319
1446
|
for (const storage of cloud) {
|
|
1320
1447
|
for (const { service, upload, download } of storage) {
|
|
1321
1448
|
if (upload) {
|
|
1322
|
-
setLocationUUID
|
|
1449
|
+
setLocationUUID(this, upload, null, service);
|
|
1323
1450
|
}
|
|
1324
1451
|
if (download) {
|
|
1325
|
-
setLocationUUID
|
|
1452
|
+
setLocationUUID(this, download, null, service);
|
|
1326
1453
|
}
|
|
1327
1454
|
}
|
|
1328
1455
|
}
|
|
@@ -1374,22 +1501,22 @@ class ChromeDocument extends Document {
|
|
|
1374
1501
|
const { localUri, mimeType, format } = file;
|
|
1375
1502
|
const hash = productionRelease && file.hash;
|
|
1376
1503
|
switch (mimeType) {
|
|
1377
|
-
case
|
|
1504
|
+
case "text/html":
|
|
1378
1505
|
if (format) {
|
|
1379
|
-
const output = await this.transform('html', host.getUTF8String(file, localUri), format, transformOptions
|
|
1506
|
+
const output = await this.transform('html', host.getUTF8String(file, localUri), format, transformOptions(this, file, mimeType));
|
|
1380
1507
|
if (output) {
|
|
1381
1508
|
file.modified = true;
|
|
1382
1509
|
file.sourceUTF8 = output.code;
|
|
1383
1510
|
}
|
|
1384
1511
|
}
|
|
1385
1512
|
break;
|
|
1386
|
-
case
|
|
1513
|
+
case "text/css":
|
|
1387
1514
|
if (format) {
|
|
1388
1515
|
const source = host.getUTF8String(file, localUri);
|
|
1389
|
-
const output = await this.transform('css', source, format, transformOptions
|
|
1516
|
+
const output = await this.transform('css', source, format, transformOptions(this, file, mimeType, source));
|
|
1390
1517
|
if (output) {
|
|
1391
1518
|
if (output.map) {
|
|
1392
|
-
const uri = writeSourceMap(localUri, output, { mimeType, hash, emptySources: productionRelease, inlineMap: hasSourceMap(file.metadata, 'inline') });
|
|
1519
|
+
const uri = Document.writeSourceMap(localUri, output, { mimeType, hash, emptySources: productionRelease, inlineMap: hasSourceMap(file.metadata, 'inline') });
|
|
1393
1520
|
if (uri) {
|
|
1394
1521
|
host.add(uri, file, types_1.FILE_TYPE.SOURCEMAP);
|
|
1395
1522
|
}
|
|
@@ -1399,8 +1526,8 @@ class ChromeDocument extends Document {
|
|
|
1399
1526
|
}
|
|
1400
1527
|
}
|
|
1401
1528
|
break;
|
|
1402
|
-
case
|
|
1403
|
-
case
|
|
1529
|
+
case "text/javascript":
|
|
1530
|
+
case "application/javascript": {
|
|
1404
1531
|
let source = host.getUTF8String(file, localUri);
|
|
1405
1532
|
if (!(file.bundleIndex >= 0)) {
|
|
1406
1533
|
source = host.setAssetContent(file, source);
|
|
@@ -1411,15 +1538,15 @@ class ChromeDocument extends Document {
|
|
|
1411
1538
|
file.modified = true;
|
|
1412
1539
|
}
|
|
1413
1540
|
if (format) {
|
|
1414
|
-
const output = await this.transform('js', source, format, transformOptions
|
|
1541
|
+
const output = await this.transform('js', source, format, transformOptions(this, file, mimeType, source, host.contentToAppend.get(localUri)));
|
|
1415
1542
|
if (output) {
|
|
1416
|
-
source = transformJs
|
|
1543
|
+
source = transformJs(this, host, file, output);
|
|
1417
1544
|
}
|
|
1418
1545
|
}
|
|
1419
1546
|
file.sourceUTF8 = source;
|
|
1420
1547
|
break;
|
|
1421
1548
|
}
|
|
1422
|
-
case
|
|
1549
|
+
case "image/svg+xml": {
|
|
1423
1550
|
const source = host.getUTF8String(file, localUri);
|
|
1424
1551
|
if (/\burl\(/i.test(source)) {
|
|
1425
1552
|
file.editing = true;
|
|
@@ -1427,7 +1554,7 @@ class ChromeDocument extends Document {
|
|
|
1427
1554
|
this.svgFiles.push(file);
|
|
1428
1555
|
}
|
|
1429
1556
|
else if (format) {
|
|
1430
|
-
const output = await this.transform('html', source, format, transformOptions
|
|
1557
|
+
const output = await this.transform('html', source, format, transformOptions(this, file, mimeType, source));
|
|
1431
1558
|
if (output) {
|
|
1432
1559
|
file.modified = true;
|
|
1433
1560
|
file.sourceUTF8 = output.code;
|
|
@@ -1523,7 +1650,7 @@ class ChromeDocument extends Document {
|
|
|
1523
1650
|
this.replaced.push(file);
|
|
1524
1651
|
}
|
|
1525
1652
|
else {
|
|
1526
|
-
setLocationUUID
|
|
1653
|
+
setLocationUUID(this, file, file);
|
|
1527
1654
|
}
|
|
1528
1655
|
file.relativeUrl = getRelativeURL(file);
|
|
1529
1656
|
}
|
|
@@ -1531,8 +1658,8 @@ class ChromeDocument extends Document {
|
|
|
1531
1658
|
const host = this.host;
|
|
1532
1659
|
if (host) {
|
|
1533
1660
|
switch (file.mimeType) {
|
|
1534
|
-
case
|
|
1535
|
-
case
|
|
1661
|
+
case "text/javascript":
|
|
1662
|
+
case "application/javascript":
|
|
1536
1663
|
if (file.imports) {
|
|
1537
1664
|
[[file.uri, source], [this.baseUrl, trailing]].forEach(([uri, code], index) => {
|
|
1538
1665
|
let localFile;
|
|
@@ -1544,24 +1671,26 @@ class ChromeDocument extends Document {
|
|
|
1544
1671
|
output = this.resolveImports(file, code, bundleMain || file);
|
|
1545
1672
|
}
|
|
1546
1673
|
else if (index === 0 && !exported) {
|
|
1547
|
-
if (!isDir(localFile)) {
|
|
1674
|
+
if (!Document.isDir(localFile)) {
|
|
1548
1675
|
localFile = path.dirname(localFile);
|
|
1549
1676
|
}
|
|
1677
|
+
output = code;
|
|
1550
1678
|
let mainFile, pathname, match;
|
|
1551
|
-
const ignorePath = bundleMain && (mainFile = this.findSourceRoot(bundleMain.uri)) && (isDir(mainFile) || (mainFile = path.dirname(mainFile))) && mainFile === localFile;
|
|
1552
|
-
while (match = REGEXP_IMPORTMODULE.exec(
|
|
1553
|
-
const value = match[1] || match[2] || match[4];
|
|
1679
|
+
const ignorePath = bundleMain && (mainFile = this.findSourceRoot(bundleMain.uri)) && (Document.isDir(mainFile) || (mainFile = path.dirname(mainFile))) && mainFile === localFile;
|
|
1680
|
+
while (match = REGEXP_IMPORTMODULE.exec(output)) {
|
|
1554
1681
|
const assert = match[3] || match[5];
|
|
1555
|
-
const
|
|
1682
|
+
const idx = match[1] ? 1 : match[2] ? 2 : 4;
|
|
1683
|
+
const [a, b] = match.indices[idx];
|
|
1684
|
+
const from = trimQuote(match[idx]);
|
|
1685
|
+
const quote = output[a];
|
|
1556
1686
|
const relative = /^\.{0,2}\//.test(from);
|
|
1557
1687
|
if (assert && /\btype\s*:\s*(["'`])css\1/.test(assert)) {
|
|
1558
1688
|
try {
|
|
1559
1689
|
const asset = host.findAsset(relative ? new URL(from, uri) : from);
|
|
1560
1690
|
if (asset) {
|
|
1561
|
-
const [relativeUrl, sameDir] = getSrcURL
|
|
1691
|
+
const [relativeUrl, sameDir] = getSrcURL(this, bundleMain || file, asset);
|
|
1562
1692
|
if (relativeUrl) {
|
|
1563
|
-
|
|
1564
|
-
output = (output || code).replace(value, quote + (sameDir ? './' : '') + relativeUrl + quote);
|
|
1693
|
+
output = (0, util_1.spliceString)(output, a, b, quote + (sameDir ? './' : '') + relativeUrl + quote, REGEXP_IMPORTMODULE);
|
|
1565
1694
|
}
|
|
1566
1695
|
}
|
|
1567
1696
|
}
|
|
@@ -1575,23 +1704,20 @@ class ChromeDocument extends Document {
|
|
|
1575
1704
|
}
|
|
1576
1705
|
pathname = path.join(localFile, from);
|
|
1577
1706
|
}
|
|
1578
|
-
else if (!(pathname = this.findSourceRoot(from)) || !isPath(pathname)) {
|
|
1707
|
+
else if (!(pathname = this.findSourceRoot(from)) || !Document.isPath(pathname)) {
|
|
1579
1708
|
const asset = host.findAsset(from);
|
|
1580
|
-
if (asset
|
|
1581
|
-
pathname = asset.localUri;
|
|
1582
|
-
}
|
|
1583
|
-
else {
|
|
1709
|
+
if (!asset || asset.invalid) {
|
|
1584
1710
|
continue;
|
|
1585
1711
|
}
|
|
1712
|
+
pathname = asset.localUri;
|
|
1586
1713
|
}
|
|
1587
|
-
if (pathname && isPath(pathname)) {
|
|
1588
|
-
|
|
1589
|
-
output = (output || code).replace(value, quote + pathname + quote);
|
|
1714
|
+
if (pathname && Document.isPath(pathname)) {
|
|
1715
|
+
output = (0, util_1.spliceString)(output, a, b, quote + pathname + quote, REGEXP_IMPORTMODULE);
|
|
1590
1716
|
}
|
|
1591
1717
|
}
|
|
1592
1718
|
REGEXP_IMPORTMODULE.lastIndex = 0;
|
|
1593
1719
|
}
|
|
1594
|
-
if (output) {
|
|
1720
|
+
if (output && output !== code) {
|
|
1595
1721
|
if (index === 0) {
|
|
1596
1722
|
source = output;
|
|
1597
1723
|
}
|
|
@@ -1603,14 +1729,14 @@ class ChromeDocument extends Document {
|
|
|
1603
1729
|
});
|
|
1604
1730
|
}
|
|
1605
1731
|
break;
|
|
1606
|
-
case
|
|
1732
|
+
case "text/css":
|
|
1607
1733
|
if (file.editing) {
|
|
1608
1734
|
const htmlFile = this.htmlFile;
|
|
1609
1735
|
const bundleId = file.bundleId;
|
|
1610
1736
|
if (!(0, types_1.isEmpty)(bundleId)) {
|
|
1611
1737
|
for (const asset of this.assets) {
|
|
1612
1738
|
if (asset.bundleIndex === 0 && asset.bundleId === bundleId) {
|
|
1613
|
-
const output = transformURL
|
|
1739
|
+
const output = transformURL(this, host, file, 'css', source, asset);
|
|
1614
1740
|
if (output) {
|
|
1615
1741
|
source = output;
|
|
1616
1742
|
file.modified = true;
|
|
@@ -1620,7 +1746,7 @@ class ChromeDocument extends Document {
|
|
|
1620
1746
|
}
|
|
1621
1747
|
}
|
|
1622
1748
|
if (trailing && htmlFile) {
|
|
1623
|
-
const output = transformURL
|
|
1749
|
+
const output = transformURL(this, host, file, 'css', trailing, htmlFile);
|
|
1624
1750
|
if (output) {
|
|
1625
1751
|
trailing = output;
|
|
1626
1752
|
}
|
|
@@ -1661,7 +1787,7 @@ class ChromeDocument extends Document {
|
|
|
1661
1787
|
if (hosted) {
|
|
1662
1788
|
const asset = this.host?.findAsset(uri);
|
|
1663
1789
|
if (asset) {
|
|
1664
|
-
const [relativeUrl, sameDir] = getSrcURL
|
|
1790
|
+
const [relativeUrl, sameDir] = getSrcURL(this, bundleMain || file, asset);
|
|
1665
1791
|
if (relativeUrl) {
|
|
1666
1792
|
value = (sameDir ? './' : '') + relativeUrl;
|
|
1667
1793
|
}
|
|
@@ -1677,7 +1803,7 @@ class ChromeDocument extends Document {
|
|
|
1677
1803
|
}
|
|
1678
1804
|
value = found || original;
|
|
1679
1805
|
}
|
|
1680
|
-
code = spliceString(code, index, index + placeholder.length, value);
|
|
1806
|
+
code = (0, util_1.spliceString)(code, index, index + placeholder.length, value);
|
|
1681
1807
|
modified = true;
|
|
1682
1808
|
break;
|
|
1683
1809
|
}
|
|
@@ -1689,7 +1815,7 @@ class ChromeDocument extends Document {
|
|
|
1689
1815
|
}
|
|
1690
1816
|
replaceContent(source, statement, mimeType) {
|
|
1691
1817
|
switch (mimeType) {
|
|
1692
|
-
case
|
|
1818
|
+
case "text/css": {
|
|
1693
1819
|
const match = REGEXP_REPLACECSS.exec((typeof statement === 'string' ? statement : statement[0]).trim());
|
|
1694
1820
|
if (match) {
|
|
1695
1821
|
const layer = match[1];
|
|
@@ -1734,7 +1860,7 @@ class ChromeDocument extends Document {
|
|
|
1734
1860
|
if (output && command && file.element?.outerXml) {
|
|
1735
1861
|
const match = REGEXP_SRCSETSIZE.exec(command);
|
|
1736
1862
|
if (match) {
|
|
1737
|
-
(file.srcSet ||= []).push(toPosix(data.baseDirectory ? output.substring(data.baseDirectory.length + 1) : output), match[1] + match[2].toLowerCase());
|
|
1863
|
+
(file.srcSet ||= []).push(Document.toPosix(data.baseDirectory ? output.substring(data.baseDirectory.length + 1) : output), match[1] + match[2].toLowerCase());
|
|
1738
1864
|
file.modified = true;
|
|
1739
1865
|
return true;
|
|
1740
1866
|
}
|
|
@@ -1749,7 +1875,7 @@ class ChromeDocument extends Document {
|
|
|
1749
1875
|
if (htmlFile) {
|
|
1750
1876
|
const endpoint = instance.getStorage('upload', htmlFile.cloudStorage)?.upload?.endpoint;
|
|
1751
1877
|
if (endpoint) {
|
|
1752
|
-
this._cloudEndpoint = new RegExp((0, types_1.escapePattern)(toPosix(endpoint)) + '/', 'g');
|
|
1878
|
+
this._cloudEndpoint = new RegExp((0, types_1.escapePattern)(Document.toPosix(endpoint)) + '/', 'g');
|
|
1753
1879
|
}
|
|
1754
1880
|
}
|
|
1755
1881
|
}
|
|
@@ -1834,7 +1960,7 @@ class ChromeDocument extends Document {
|
|
|
1834
1960
|
const { admin, bucket, upload } = storage;
|
|
1835
1961
|
const website = admin?.configBucket?.website;
|
|
1836
1962
|
if ((0, types_1.isPlainObject)(website) && bucket && upload) {
|
|
1837
|
-
let filename = joinPath(upload.pathname, upload.filename || path.basename(htmlFile.localUri));
|
|
1963
|
+
let filename = Document.joinPath(upload.pathname, upload.filename || path.basename(htmlFile.localUri));
|
|
1838
1964
|
if (website.indexPage === true) {
|
|
1839
1965
|
website.indexPage = filename;
|
|
1840
1966
|
filename = '';
|
|
@@ -1850,14 +1976,14 @@ class ChromeDocument extends Document {
|
|
|
1850
1976
|
if (website.errorPath === true) {
|
|
1851
1977
|
website.errorPath = filename;
|
|
1852
1978
|
}
|
|
1853
|
-
instance.setBucketWebsite(storage.service, instance.getCredential(storage), bucket, website);
|
|
1979
|
+
void instance.setBucketWebsite(storage.service, instance.getCredential(storage), bucket, website);
|
|
1854
1980
|
}
|
|
1855
1981
|
}
|
|
1856
1982
|
}
|
|
1857
1983
|
if (htmlFile.compress) {
|
|
1858
1984
|
await host.compressFile(htmlFile);
|
|
1859
1985
|
}
|
|
1860
|
-
return Promise.all(Cloud.uploadAsset(state, htmlFile, { preferBuffer, contentType:
|
|
1986
|
+
return Promise.all(Cloud.uploadAsset(state, htmlFile, { preferBuffer, contentType: "text/html", ignoreProcess: true }));
|
|
1861
1987
|
}
|
|
1862
1988
|
}
|
|
1863
1989
|
return [];
|
|
@@ -1868,7 +1994,7 @@ class ChromeDocument extends Document {
|
|
|
1868
1994
|
}
|
|
1869
1995
|
const main = watch.main;
|
|
1870
1996
|
let result;
|
|
1871
|
-
if (main?.editing && main.mimeType ===
|
|
1997
|
+
if (main?.editing && main.mimeType === "text/html") {
|
|
1872
1998
|
const inlineUrlCloudMap = main.inlineUrlCloudMap || {};
|
|
1873
1999
|
const using = [];
|
|
1874
2000
|
let found;
|
|
@@ -1881,7 +2007,7 @@ class ChromeDocument extends Document {
|
|
|
1881
2007
|
found = true;
|
|
1882
2008
|
using.push(asset);
|
|
1883
2009
|
}
|
|
1884
|
-
else if (isWatched
|
|
2010
|
+
else if (isWatched(this, asset) ||
|
|
1885
2011
|
(0, types_1.watchFlag)(asset.flags) ||
|
|
1886
2012
|
asset.base64 && watch.related.find(item => (0, asset_1.isEqual)(item, asset)) ||
|
|
1887
2013
|
(0, types_1.isArray)(asset.cloudStorage) && asset.cloudStorage.some(item => (upload = item.upload) && upload.active)) {
|
|
@@ -1910,8 +2036,9 @@ class ChromeDocument extends Document {
|
|
|
1910
2036
|
}
|
|
1911
2037
|
const asset = watch.bundleMain || watch.assets[0];
|
|
1912
2038
|
const pathname = (asset.cloudUrl || asset.relativeUrl || '').split('?')[0];
|
|
1913
|
-
|
|
1914
|
-
|
|
2039
|
+
const next = assets?.find(item => (0, asset_1.isEqual)(item, asset));
|
|
2040
|
+
let value, search;
|
|
2041
|
+
if (next) {
|
|
1915
2042
|
if (next.cloudUrl) {
|
|
1916
2043
|
value = next.cloudUrl;
|
|
1917
2044
|
asset.cloudUrl = value;
|
|
@@ -1960,7 +2087,7 @@ class ChromeDocument extends Document {
|
|
|
1960
2087
|
const srcset = element.getAttribute('srcset');
|
|
1961
2088
|
if (srcset) {
|
|
1962
2089
|
const htmlFile = this.htmlFile;
|
|
1963
|
-
const uri = toPosix(file.uri);
|
|
2090
|
+
const uri = Document.toPosix(file.uri);
|
|
1964
2091
|
const items = new Set([uri]);
|
|
1965
2092
|
const baseHref = getBaseURLs(htmlFile, this.baseUrl);
|
|
1966
2093
|
const sameOrigin = hasSameOrigin(file.url || uri, ...baseHref);
|
|
@@ -1968,7 +2095,7 @@ class ChromeDocument extends Document {
|
|
|
1968
2095
|
const src = element.getAttribute('src');
|
|
1969
2096
|
for (const baseUri of baseHref) {
|
|
1970
2097
|
let url;
|
|
1971
|
-
if (src && uri === resolvePath(url = toPosix(src), baseUri)) {
|
|
2098
|
+
if (src && uri === Document.resolvePath(url = Document.toPosix(src), baseUri)) {
|
|
1972
2099
|
items.add(url);
|
|
1973
2100
|
}
|
|
1974
2101
|
items.add(uri.startsWith(this.baseDirectory) ? uri.substring(this.baseDirectory.length) : uri.replace(baseUri.origin, ''));
|
|
@@ -1981,7 +2108,7 @@ class ChromeDocument extends Document {
|
|
|
1981
2108
|
const pattern = new RegExp(`(,?\\s*)(${(resolve && !url.startsWith('.') ? `(?:\\.\\.[\\\\/])*\\.\\.${pathname}|` : '') + pathname})(` + (!url.includes('?') ? '(?:(?!,)(?:[^?]|$)[^,]*)|(?!\\?)[^,]*)' : '[^,]*)'), 'g');
|
|
1982
2109
|
while (match = pattern.exec(current)) {
|
|
1983
2110
|
const partial = match[2];
|
|
1984
|
-
if (!resolve || baseHref.some(baseUri => uri === resolvePath(partial, baseUri))) {
|
|
2111
|
+
if (!resolve || baseHref.some(baseUri => uri === Document.resolvePath(partial, baseUri))) {
|
|
1985
2112
|
current = replaceMatch(match, current, match[1] + value + match[3], pattern);
|
|
1986
2113
|
}
|
|
1987
2114
|
}
|
|
@@ -2019,7 +2146,7 @@ class ChromeDocument extends Document {
|
|
|
2019
2146
|
readBase64(item, item.inlineBase64);
|
|
2020
2147
|
}
|
|
2021
2148
|
else if (!item.invalid && (0, util_1.hasValue)(item.format, 'base64')) {
|
|
2022
|
-
const uuid = (0,
|
|
2149
|
+
const uuid = (0, crypto_1.randomUUID)();
|
|
2023
2150
|
if (readBase64(item, uuid)) {
|
|
2024
2151
|
item.inlineBase64 = uuid;
|
|
2025
2152
|
}
|
|
@@ -2063,9 +2190,9 @@ class ChromeDocument extends Document {
|
|
|
2063
2190
|
const { host, hashed, bufferMap, productionRelease } = processing;
|
|
2064
2191
|
const sanitizeSource = (item, source) => {
|
|
2065
2192
|
if (productionRelease) {
|
|
2066
|
-
replaceCss
|
|
2193
|
+
replaceCss(this, item);
|
|
2067
2194
|
}
|
|
2068
|
-
const output = replaceHtml
|
|
2195
|
+
const output = replaceHtml(this, source, processing, item.inlineUrlMap);
|
|
2069
2196
|
if (source !== output) {
|
|
2070
2197
|
item.modified = true;
|
|
2071
2198
|
return output;
|
|
@@ -2094,7 +2221,7 @@ class ChromeDocument extends Document {
|
|
|
2094
2221
|
continue;
|
|
2095
2222
|
}
|
|
2096
2223
|
let source = host.getUTF8String(item);
|
|
2097
|
-
const output = transformURL
|
|
2224
|
+
const output = transformURL(this, host, item, 'svg', source);
|
|
2098
2225
|
if (output) {
|
|
2099
2226
|
source = output;
|
|
2100
2227
|
item.modified = true;
|
|
@@ -2102,7 +2229,7 @@ class ChromeDocument extends Document {
|
|
|
2102
2229
|
source = sanitizeSource(item, source);
|
|
2103
2230
|
const format = item.format;
|
|
2104
2231
|
if (format) {
|
|
2105
|
-
const result = await this.transform('html', source, format, transformOptions
|
|
2232
|
+
const result = await this.transform('html', source, format, transformOptions(this, item, "image/svg+xml"));
|
|
2106
2233
|
if (result) {
|
|
2107
2234
|
item.modified = true;
|
|
2108
2235
|
source = result.code;
|
|
@@ -2129,7 +2256,7 @@ class ChromeDocument extends Document {
|
|
|
2129
2256
|
source = output;
|
|
2130
2257
|
item.modified = true;
|
|
2131
2258
|
}
|
|
2132
|
-
if (output = transformURL
|
|
2259
|
+
if (output = transformURL(this, host, item, 'css', source)) {
|
|
2133
2260
|
source = output;
|
|
2134
2261
|
item.modified = true;
|
|
2135
2262
|
}
|
|
@@ -2137,7 +2264,7 @@ class ChromeDocument extends Document {
|
|
|
2137
2264
|
item.sourceUTF8 = source;
|
|
2138
2265
|
if (item.format) {
|
|
2139
2266
|
transforms.push(item);
|
|
2140
|
-
tasks.push(this.transform('css', source, item.format, transformOptions
|
|
2267
|
+
tasks.push(this.transform('css', source, item.format, transformOptions(this, item, "text/css", source, host.contentToAppend.get(item.localUri))));
|
|
2141
2268
|
}
|
|
2142
2269
|
}
|
|
2143
2270
|
for (const item of this.jsFiles) {
|
|
@@ -2153,7 +2280,7 @@ class ChromeDocument extends Document {
|
|
|
2153
2280
|
source = output;
|
|
2154
2281
|
item.modified = true;
|
|
2155
2282
|
}
|
|
2156
|
-
if (output = transformURL
|
|
2283
|
+
if (output = transformURL(this, host, item, 'js', source)) {
|
|
2157
2284
|
source = output;
|
|
2158
2285
|
item.modified = true;
|
|
2159
2286
|
}
|
|
@@ -2161,7 +2288,7 @@ class ChromeDocument extends Document {
|
|
|
2161
2288
|
item.sourceUTF8 = source;
|
|
2162
2289
|
if (format) {
|
|
2163
2290
|
transforms.push(item);
|
|
2164
|
-
tasks.push(this.transform('js', source, format, transformOptions
|
|
2291
|
+
tasks.push(this.transform('js', source, format, transformOptions(this, item, "application/javascript", source, host.contentToAppend.get(item.localUri))));
|
|
2165
2292
|
}
|
|
2166
2293
|
}
|
|
2167
2294
|
return Promise.allSettled(tasks).then(items => {
|
|
@@ -2171,7 +2298,7 @@ class ChromeDocument extends Document {
|
|
|
2171
2298
|
const target = transforms[i];
|
|
2172
2299
|
if (value.type === 'css') {
|
|
2173
2300
|
if (value.map && !target.bundleReplace) {
|
|
2174
|
-
const output = writeSourceMap(target.localUri, value, { mimeType:
|
|
2301
|
+
const output = Document.writeSourceMap(target.localUri, value, { mimeType: "text/css", hash: productionRelease ? target.hash : undefined, emptySources: productionRelease, inlineMap: hasSourceMap(target.metadata, 'inline') });
|
|
2175
2302
|
if (output) {
|
|
2176
2303
|
host.add(output, target, types_1.FILE_TYPE.SOURCEMAP);
|
|
2177
2304
|
}
|
|
@@ -2180,7 +2307,7 @@ class ChromeDocument extends Document {
|
|
|
2180
2307
|
target.sourceUTF8 = value.code;
|
|
2181
2308
|
}
|
|
2182
2309
|
else {
|
|
2183
|
-
transformJs
|
|
2310
|
+
transformJs(this, host, target, value);
|
|
2184
2311
|
}
|
|
2185
2312
|
}
|
|
2186
2313
|
}
|
|
@@ -2207,7 +2334,7 @@ class ChromeDocument extends Document {
|
|
|
2207
2334
|
domBase.ignoreTag(config.ignoreServerCodeBlocks);
|
|
2208
2335
|
}
|
|
2209
2336
|
if (productionRelease) {
|
|
2210
|
-
replaceCss
|
|
2337
|
+
replaceCss(this, htmlFile);
|
|
2211
2338
|
}
|
|
2212
2339
|
await this.setElementAttributes(processing, domBase);
|
|
2213
2340
|
await this.applyDataSource(processing, domBase);
|
|
@@ -2222,6 +2349,11 @@ class ChromeDocument extends Document {
|
|
|
2222
2349
|
}
|
|
2223
2350
|
}
|
|
2224
2351
|
source = removeNamespace(moduleName, domBase.modified ? domBase.close() : source, domBase.newline, domBase.getComments());
|
|
2352
|
+
if (this.sanitizeFramework) {
|
|
2353
|
+
for (const name of this.sanitizeFramework) {
|
|
2354
|
+
source = source.replace(name === '*' ? REGEXP_SANITIZEALL : new RegExp(`(?:\\s+|\\b)data-(?:${(0, types_1.escapePattern)(name)}-[^=\\s]+|.+?-${(0, types_1.escapePattern)(name)})\\s*${dom_1.DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g'), '');
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2225
2357
|
if (!htmlFile.preserve) {
|
|
2226
2358
|
let match;
|
|
2227
2359
|
while (match = REGEXP_STYLE.exec(source)) {
|
|
@@ -2231,10 +2363,10 @@ class ChromeDocument extends Document {
|
|
|
2231
2363
|
}
|
|
2232
2364
|
REGEXP_STYLE.lastIndex = 0;
|
|
2233
2365
|
}
|
|
2234
|
-
if (output = transformURL
|
|
2366
|
+
if (output = transformURL(this, host, htmlFile, 'html', source)) {
|
|
2235
2367
|
source = output;
|
|
2236
2368
|
}
|
|
2237
|
-
source = replaceHtml
|
|
2369
|
+
source = replaceHtml(this, source, processing, htmlFile.inlineUrlMap);
|
|
2238
2370
|
if ((0, types_1.isString)(config.stripCommentsAndCDATA)) {
|
|
2239
2371
|
source = dom_1.DomWriter.getCommentsAndCDATA(source, config.stripCommentsAndCDATA, true, true);
|
|
2240
2372
|
}
|
|
@@ -2244,7 +2376,7 @@ class ChromeDocument extends Document {
|
|
|
2244
2376
|
const result = await this.transform('html', source, format, {
|
|
2245
2377
|
pathname: path.dirname(localUri),
|
|
2246
2378
|
filename,
|
|
2247
|
-
mimeType:
|
|
2379
|
+
mimeType: "text/html",
|
|
2248
2380
|
metadata: Object.assign({ '__fromhtml__': true, ...this.config }, metadata),
|
|
2249
2381
|
cacheData: !productionRelease || this.productionIncremental ? { uri, encoding } : undefined
|
|
2250
2382
|
});
|
|
@@ -2254,17 +2386,21 @@ class ChromeDocument extends Document {
|
|
|
2254
2386
|
}
|
|
2255
2387
|
if (domBase.hasErrors()) {
|
|
2256
2388
|
const timeStamp = Date.now();
|
|
2257
|
-
|
|
2389
|
+
for (const err of domBase.errors) {
|
|
2390
|
+
this.addLog(types_1.STATUS_TYPE.WARN, 'dom-writer: ' + err.message, timeStamp);
|
|
2391
|
+
}
|
|
2258
2392
|
}
|
|
2259
2393
|
if (domBase.failCount > 0) {
|
|
2260
2394
|
this.writeFail(['Unable to update document', moduleName], (0, types_1.errorMessage)('html', 'DOM rewrite failed', domBase.failCount + ' errors'), { type: 4, startTime });
|
|
2261
2395
|
}
|
|
2262
2396
|
else {
|
|
2263
|
-
this.writeTimeProcess('html', `dom-writer
|
|
2264
|
-
if (cacheMiss.length) {
|
|
2397
|
+
this.writeTimeProcess('html', `dom-writer: ${domBase.modifyCount} modified > ` + path.basename(localUri), startTime);
|
|
2398
|
+
if (cacheMiss.length > 0) {
|
|
2265
2399
|
const data = {};
|
|
2266
2400
|
const message = [];
|
|
2267
|
-
|
|
2401
|
+
for (const name of cacheMiss) {
|
|
2402
|
+
data[name] = (data[name] || 0) + 1;
|
|
2403
|
+
}
|
|
2268
2404
|
for (const name in data) {
|
|
2269
2405
|
message.push(name + `(${data[name]})`);
|
|
2270
2406
|
}
|
|
@@ -2288,7 +2424,7 @@ class ChromeDocument extends Document {
|
|
|
2288
2424
|
let [innerXml, sourceMappingURL, inlineMap] = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(item).trim());
|
|
2289
2425
|
if (sourceMappingURL && !inlineMap && item.localUri) {
|
|
2290
2426
|
let mapUri = path.resolve(sourceMappingURL = decodeURIComponent(sourceMappingURL));
|
|
2291
|
-
if (!isPath(mapUri)) {
|
|
2427
|
+
if (!Document.isPath(mapUri)) {
|
|
2292
2428
|
mapUri = path.join(path.dirname(item.localUri), sourceMappingURL);
|
|
2293
2429
|
}
|
|
2294
2430
|
host.deleteFile(mapUri);
|
|
@@ -2311,7 +2447,7 @@ class ChromeDocument extends Document {
|
|
|
2311
2447
|
}
|
|
2312
2448
|
if (uri && !(0, util_1.hasValue)(item.format, 'crossorigin') && item !== htmlFile) {
|
|
2313
2449
|
if (cloud?.getStorage('upload', item.cloudStorage)) {
|
|
2314
|
-
const inlineUrlCloud = item.inlineUrlCloud ||= (0,
|
|
2450
|
+
const inlineUrlCloud = item.inlineUrlCloud ||= (0, crypto_1.randomUUID)();
|
|
2315
2451
|
(htmlFile.inlineUrlCloudMap ||= {})[inlineUrlCloud] = productionRelease ? this.removeServerRoot(uri) : uri;
|
|
2316
2452
|
uri = inlineUrlCloud;
|
|
2317
2453
|
}
|
|
@@ -2342,7 +2478,9 @@ class ChromeDocument extends Document {
|
|
|
2342
2478
|
const detectHeight = domElement.getAttribute('height') === 'detect';
|
|
2343
2479
|
if (detectWidth || detectHeight) {
|
|
2344
2480
|
let width = 0, height = 0, buffer = null, packageName;
|
|
2345
|
-
const addLog = (dimension) =>
|
|
2481
|
+
const addLog = (dimension) => {
|
|
2482
|
+
this.addLog(types_1.STATUS_TYPE.WARN, 'Could not detect image ' + dimension, packageName || this.moduleName, item.localUri ? path.basename(item.localUri) : item.filename);
|
|
2483
|
+
};
|
|
2346
2484
|
if (isImage(item.mimeType) && (buffer = host.getBuffer(item))) {
|
|
2347
2485
|
try {
|
|
2348
2486
|
({ width, height } = require(packageName = 'image-size').imageSize(buffer));
|
|
@@ -2399,29 +2537,20 @@ class ChromeDocument extends Document {
|
|
|
2399
2537
|
if (this.dataSource.length === 0) {
|
|
2400
2538
|
return;
|
|
2401
2539
|
}
|
|
2402
|
-
const
|
|
2540
|
+
const db = this.Db;
|
|
2403
2541
|
const cloud = host.Cloud;
|
|
2404
|
-
const sessionKey = (0,
|
|
2542
|
+
const sessionKey = (0, crypto_1.randomUUID)();
|
|
2405
2543
|
const cacheData = Object.create(null);
|
|
2406
|
-
const coerceMap = {};
|
|
2407
2544
|
const dataItems = [];
|
|
2408
2545
|
const displayItems = [];
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
(element ||= new dom_1.HtmlElement(moduleName, item.element)).remove = true;
|
|
2413
|
-
if (!domBase.write(element)) {
|
|
2414
|
-
this.writeFail('Unable to remove element', errorHtml(item.element), { type: 4, startTime });
|
|
2415
|
-
}
|
|
2546
|
+
for (const item of this.dataSource) {
|
|
2547
|
+
if (item.type === 'display') {
|
|
2548
|
+
displayItems.push(item);
|
|
2416
2549
|
}
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
removeElement(item);
|
|
2420
|
-
const pkg = getPackageName(err);
|
|
2421
|
-
if (!(pkg && this.checkPackage(err, pkg))) {
|
|
2422
|
-
this.writeFail(["Invalid credentials", item.source], err);
|
|
2550
|
+
else {
|
|
2551
|
+
dataItems.push(item);
|
|
2423
2552
|
}
|
|
2424
|
-
}
|
|
2553
|
+
}
|
|
2425
2554
|
const checkObject = (item, data, type) => {
|
|
2426
2555
|
const { query, cascade } = item;
|
|
2427
2556
|
if ((0, types_1.isString)(cascade)) {
|
|
@@ -2452,7 +2581,7 @@ class ChromeDocument extends Document {
|
|
|
2452
2581
|
this.checkPackage(err, pkg, ["Unable to filter results", item.source]);
|
|
2453
2582
|
}
|
|
2454
2583
|
}
|
|
2455
|
-
if (type && !item.ignoreCoerce &&
|
|
2584
|
+
if (type && !item.ignoreCoerce && this.settingsOf(type, 'coerce') === true) {
|
|
2456
2585
|
(0, types_1.coerceObject)(data);
|
|
2457
2586
|
}
|
|
2458
2587
|
}
|
|
@@ -2463,7 +2592,7 @@ class ChromeDocument extends Document {
|
|
|
2463
2592
|
const batchGroup = [];
|
|
2464
2593
|
for (const item of sourceSet) {
|
|
2465
2594
|
if (!item.element) {
|
|
2466
|
-
this.addLog(types_1.STATUS_TYPE.WARN, `Missing target element {${JSON.stringify(item)}}`);
|
|
2595
|
+
this.addLog(types_1.STATUS_TYPE.WARN, `dom-writer: Missing target element {${JSON.stringify(item)}}`);
|
|
2467
2596
|
continue;
|
|
2468
2597
|
}
|
|
2469
2598
|
const type = item.source;
|
|
@@ -2471,11 +2600,11 @@ class ChromeDocument extends Document {
|
|
|
2471
2600
|
case 'cloud': {
|
|
2472
2601
|
const { service, credential } = item;
|
|
2473
2602
|
if (cloud) {
|
|
2474
|
-
const key = service + '_' + (service === 'atlas' && item.uri || '') + '_' + asString(credential, true);
|
|
2603
|
+
const key = service + '_' + (service === 'atlas' && item.uri || '') + '_' + Document.asString(credential, true);
|
|
2475
2604
|
(batchMap[key] ||= []).push(item);
|
|
2476
2605
|
}
|
|
2477
2606
|
else {
|
|
2478
|
-
errorCredential(item, (0, types_1.errorValue)("Cloud module not installed", service));
|
|
2607
|
+
errorCredential(this, domBase, item, (0, types_1.errorValue)("Cloud module not installed", service));
|
|
2479
2608
|
}
|
|
2480
2609
|
break;
|
|
2481
2610
|
}
|
|
@@ -2505,11 +2634,11 @@ class ChromeDocument extends Document {
|
|
|
2505
2634
|
(batchMap[key] ||= []).push(item);
|
|
2506
2635
|
}
|
|
2507
2636
|
catch (err) {
|
|
2508
|
-
errorCredential(item, err);
|
|
2637
|
+
errorCredential(this, domBase, item, err);
|
|
2509
2638
|
}
|
|
2510
2639
|
}
|
|
2511
2640
|
else {
|
|
2512
|
-
errorCredential(item, (0, types_1.errorValue)(db ? "Database provider not found" : "Db module not installed", type));
|
|
2641
|
+
errorCredential(this, domBase, item, (0, types_1.errorValue)(db ? "Database provider not found" : "Db module not installed", type));
|
|
2513
2642
|
}
|
|
2514
2643
|
break;
|
|
2515
2644
|
}
|
|
@@ -2520,11 +2649,11 @@ class ChromeDocument extends Document {
|
|
|
2520
2649
|
return this.allSettled(batchGroup.map(async (batch) => {
|
|
2521
2650
|
return new Promise(async (resolve, reject) => {
|
|
2522
2651
|
const errorRemove = (item, reason) => {
|
|
2523
|
-
removeElement(item);
|
|
2652
|
+
removeElement(this, domBase, item);
|
|
2524
2653
|
reject(reason);
|
|
2525
2654
|
};
|
|
2526
2655
|
const errorClient = (item, reason) => {
|
|
2527
|
-
removeElement(item);
|
|
2656
|
+
removeElement(this, domBase, item);
|
|
2528
2657
|
if (reason) {
|
|
2529
2658
|
this.writeFail(["Unable to configure client", item.source], reason);
|
|
2530
2659
|
}
|
|
@@ -2576,7 +2705,7 @@ class ChromeDocument extends Document {
|
|
|
2576
2705
|
}
|
|
2577
2706
|
catch (err) {
|
|
2578
2707
|
this.abort(type);
|
|
2579
|
-
this.writeFail(["Unable to read file", path.basename(location)], err,
|
|
2708
|
+
this.writeFail(["Unable to read file", path.basename(location)], err, 32);
|
|
2580
2709
|
errorRemove(current);
|
|
2581
2710
|
return;
|
|
2582
2711
|
}
|
|
@@ -2646,7 +2775,7 @@ class ChromeDocument extends Document {
|
|
|
2646
2775
|
}
|
|
2647
2776
|
catch (err) {
|
|
2648
2777
|
this.abort(type);
|
|
2649
|
-
this.writeFail(["Unable to read file", path.basename(pathname)], err,
|
|
2778
|
+
this.writeFail(["Unable to read file", path.basename(pathname)], err, 32);
|
|
2650
2779
|
errorRemove(current);
|
|
2651
2780
|
return;
|
|
2652
2781
|
}
|
|
@@ -2663,7 +2792,7 @@ class ChromeDocument extends Document {
|
|
|
2663
2792
|
}
|
|
2664
2793
|
catch (err) {
|
|
2665
2794
|
this.abort(type);
|
|
2666
|
-
this.writeFail(["Unable to parse inline object", format], err,
|
|
2795
|
+
this.writeFail(["Unable to parse inline object", format], err, 4);
|
|
2667
2796
|
errorRemove(current);
|
|
2668
2797
|
return;
|
|
2669
2798
|
}
|
|
@@ -2678,7 +2807,7 @@ class ChromeDocument extends Document {
|
|
|
2678
2807
|
return;
|
|
2679
2808
|
}
|
|
2680
2809
|
if (cacheKey) {
|
|
2681
|
-
setCacheData
|
|
2810
|
+
setCacheData(this, current, data, cacheKey, cacheData);
|
|
2682
2811
|
}
|
|
2683
2812
|
if ((result[0] = checkObject(current, data, type)) === null) {
|
|
2684
2813
|
this.abort(type);
|
|
@@ -2688,7 +2817,7 @@ class ChromeDocument extends Document {
|
|
|
2688
2817
|
break;
|
|
2689
2818
|
}
|
|
2690
2819
|
case 'export': {
|
|
2691
|
-
const cacheKey = asString(current, true);
|
|
2820
|
+
const cacheKey = Document.asString(current, true);
|
|
2692
2821
|
if (!current.ignoreCache && CACHE_DBRESULT.has(cacheKey)) {
|
|
2693
2822
|
result[0] = getCacheItem(CACHE_DBRESULT, cacheKey);
|
|
2694
2823
|
}
|
|
@@ -2713,7 +2842,7 @@ class ChromeDocument extends Document {
|
|
|
2713
2842
|
target = pathname;
|
|
2714
2843
|
hint = pathname;
|
|
2715
2844
|
}
|
|
2716
|
-
else if ((target = this.resolveDir(type, pathname)) && (getData =
|
|
2845
|
+
else if ((target = this.resolveDir(type, pathname)) && (getData = Document.parseFunction(target, true))) {
|
|
2717
2846
|
hint = pathname;
|
|
2718
2847
|
}
|
|
2719
2848
|
else {
|
|
@@ -2763,7 +2892,7 @@ class ChromeDocument extends Document {
|
|
|
2763
2892
|
});
|
|
2764
2893
|
}
|
|
2765
2894
|
}
|
|
2766
|
-
setCacheData
|
|
2895
|
+
setCacheData(this, current, data, cacheKey, cacheData);
|
|
2767
2896
|
}
|
|
2768
2897
|
catch (err) {
|
|
2769
2898
|
this.abort(type);
|
|
@@ -2808,10 +2937,10 @@ class ChromeDocument extends Document {
|
|
|
2808
2937
|
}
|
|
2809
2938
|
if (!(search.schema = cacheData[pathname])) {
|
|
2810
2939
|
try {
|
|
2811
|
-
search.schema = loadLocalFile
|
|
2940
|
+
search.schema = loadLocalFile(this, current, pathname, cacheData, cmd.encoding);
|
|
2812
2941
|
}
|
|
2813
2942
|
catch (err) {
|
|
2814
|
-
this.writeFail(['Unable to parse document', path.basename(pathname)], err instanceof Error ? errors = err : err,
|
|
2943
|
+
this.writeFail(['Unable to parse document', path.basename(pathname)], err instanceof Error ? errors = err : err, 32);
|
|
2815
2944
|
search.schema = undefined;
|
|
2816
2945
|
}
|
|
2817
2946
|
}
|
|
@@ -2845,10 +2974,10 @@ class ChromeDocument extends Document {
|
|
|
2845
2974
|
if (!(cmd.query = cacheData[pathname])) {
|
|
2846
2975
|
const out = { content: '' };
|
|
2847
2976
|
try {
|
|
2848
|
-
cmd.query = loadLocalFile
|
|
2977
|
+
cmd.query = loadLocalFile(this, current, pathname, cacheData, cmd.encoding, out);
|
|
2849
2978
|
}
|
|
2850
2979
|
catch {
|
|
2851
|
-
setCacheData
|
|
2980
|
+
setCacheData(this, current, cmd.query = out.content, pathname, cacheData, true);
|
|
2852
2981
|
}
|
|
2853
2982
|
}
|
|
2854
2983
|
}
|
|
@@ -2859,7 +2988,7 @@ class ChromeDocument extends Document {
|
|
|
2859
2988
|
}
|
|
2860
2989
|
catch (err) {
|
|
2861
2990
|
this.abort(type);
|
|
2862
|
-
this.writeFail(["Unable to read file", pathname ? path.basename(pathname) : query], err,
|
|
2991
|
+
this.writeFail(["Unable to read file", pathname ? path.basename(pathname) : query], err, 32);
|
|
2863
2992
|
errorRemove(current);
|
|
2864
2993
|
return;
|
|
2865
2994
|
}
|
|
@@ -2876,7 +3005,7 @@ class ChromeDocument extends Document {
|
|
|
2876
3005
|
}
|
|
2877
3006
|
else if (db.hasSource(type, db.sourceType.KEYVALUE)) {
|
|
2878
3007
|
aborting = commandType !== db.commandType.UPDATE;
|
|
2879
|
-
message = asString(data.search || data.key);
|
|
3008
|
+
message = Document.asString(data.search || data.key);
|
|
2880
3009
|
}
|
|
2881
3010
|
else {
|
|
2882
3011
|
const credential = data.credential;
|
|
@@ -2915,7 +3044,7 @@ class ChromeDocument extends Document {
|
|
|
2915
3044
|
const empty = (items = result[i]) === null;
|
|
2916
3045
|
if ((items ||= []).length === 0) {
|
|
2917
3046
|
if (whenEmpty) {
|
|
2918
|
-
const data = await checkData
|
|
3047
|
+
const data = await checkData(this, item, whenEmpty, items, row => Array.isArray(row));
|
|
2919
3048
|
if (data) {
|
|
2920
3049
|
items = data;
|
|
2921
3050
|
item.transactionFail = false;
|
|
@@ -2933,22 +3062,21 @@ class ChromeDocument extends Document {
|
|
|
2933
3062
|
items = items.slice(0, limit);
|
|
2934
3063
|
}
|
|
2935
3064
|
if (postQuery) {
|
|
2936
|
-
const data = await checkData
|
|
3065
|
+
const data = await checkData(this, item, postQuery, items = items.slice(0), row => Array.isArray(row));
|
|
2937
3066
|
if (data) {
|
|
2938
3067
|
items = data;
|
|
2939
3068
|
}
|
|
2940
3069
|
}
|
|
2941
|
-
if (items.length && !item.transactionFail) {
|
|
3070
|
+
if (items.length > 0 && !item.transactionFail) {
|
|
2942
3071
|
const { element, preRender } = item;
|
|
2943
|
-
const domElement = new dom_1.HtmlElement(moduleName, element);
|
|
3072
|
+
const domElement = new dom_1.HtmlElement(this.moduleName, element);
|
|
2944
3073
|
let value = '';
|
|
2945
3074
|
const checkValue = async (name) => {
|
|
2946
|
-
const data = await checkData
|
|
3075
|
+
const data = await checkData(this, item, name, value, row => typeof row === 'string');
|
|
2947
3076
|
if (data) {
|
|
2948
3077
|
value = data;
|
|
2949
3078
|
}
|
|
2950
3079
|
};
|
|
2951
|
-
const valueAsString = (data, joinString) => Array.isArray(data) && !data.some(child => typeof child === 'object') ? data.join(joinString) : asString(data);
|
|
2952
3080
|
if (item.template) {
|
|
2953
3081
|
const pathname = this.resolveDir('template', item.template);
|
|
2954
3082
|
if (pathname) {
|
|
@@ -2962,10 +3090,10 @@ class ChromeDocument extends Document {
|
|
|
2962
3090
|
if (!(item.value = cacheData[pathname])) {
|
|
2963
3091
|
try {
|
|
2964
3092
|
item.value = fs.readFileSync(pathname, item.encoding || 'utf-8');
|
|
2965
|
-
setCacheData
|
|
3093
|
+
setCacheData(this, item, item.value, pathname, cacheData, true);
|
|
2966
3094
|
}
|
|
2967
3095
|
catch (err) {
|
|
2968
|
-
this.writeFail(["Unable to read file", path.basename(pathname)], err,
|
|
3096
|
+
this.writeFail(["Unable to read file", path.basename(pathname)], err, 32);
|
|
2969
3097
|
errors = true;
|
|
2970
3098
|
}
|
|
2971
3099
|
}
|
|
@@ -2984,7 +3112,7 @@ class ChromeDocument extends Document {
|
|
|
2984
3112
|
const content = await this.parseTemplate(item.viewEngine, template, items);
|
|
2985
3113
|
if (content === null) {
|
|
2986
3114
|
++domBase.failCount;
|
|
2987
|
-
removeElement(item, domElement);
|
|
3115
|
+
removeElement(this, domBase, item, domElement);
|
|
2988
3116
|
if (length === 1) {
|
|
2989
3117
|
resolve();
|
|
2990
3118
|
return;
|
|
@@ -3012,7 +3140,7 @@ class ChromeDocument extends Document {
|
|
|
3012
3140
|
continue;
|
|
3013
3141
|
}
|
|
3014
3142
|
try {
|
|
3015
|
-
let content = new Function('return ' + literal + ';')
|
|
3143
|
+
let content = new Function('return ' + literal + ';')(row);
|
|
3016
3144
|
if (!segment.startsWith('`')) {
|
|
3017
3145
|
content = segment.substring(0, segment.indexOf('`')) + content;
|
|
3018
3146
|
}
|
|
@@ -3083,7 +3211,7 @@ class ChromeDocument extends Document {
|
|
|
3083
3211
|
for (const row of items) {
|
|
3084
3212
|
for (let seg of segment) {
|
|
3085
3213
|
seg = seg.trim();
|
|
3086
|
-
if (seg.startsWith(':') && (match = /^:join\((
|
|
3214
|
+
if (seg.startsWith(':') && (match = /^:join\((.*)\)$/is.exec(seg))) {
|
|
3087
3215
|
joinString = match[1];
|
|
3088
3216
|
continue;
|
|
3089
3217
|
}
|
|
@@ -3092,7 +3220,7 @@ class ChromeDocument extends Document {
|
|
|
3092
3220
|
valid = true;
|
|
3093
3221
|
}
|
|
3094
3222
|
if (seg) {
|
|
3095
|
-
if (match = /^:text\((
|
|
3223
|
+
if (match = /^:text\((.*)\)$/is.exec(seg)) {
|
|
3096
3224
|
value += (value ? joinString : '') + match[1];
|
|
3097
3225
|
valid = true;
|
|
3098
3226
|
}
|
|
@@ -3229,7 +3357,7 @@ class ChromeDocument extends Document {
|
|
|
3229
3357
|
break;
|
|
3230
3358
|
}
|
|
3231
3359
|
default:
|
|
3232
|
-
removeElement(item, domElement);
|
|
3360
|
+
removeElement(this, domBase, item, domElement);
|
|
3233
3361
|
if (length === 1) {
|
|
3234
3362
|
reject(errorDataSource('Invalid action', item.type || "Unknown"));
|
|
3235
3363
|
return;
|
|
@@ -3250,18 +3378,18 @@ class ChromeDocument extends Document {
|
|
|
3250
3378
|
switch (item.source) {
|
|
3251
3379
|
case 'cloud': {
|
|
3252
3380
|
const { service, table, id, query } = item;
|
|
3253
|
-
const queryString = (table ? 'table=' + table : '') + (id || query ? (table ? ';' : '') + (id ? 'id=' + id : 'query=' + asString(query)) : '');
|
|
3381
|
+
const queryString = (table ? 'table=' + table : '') + (id || query ? (table ? ';' : '') + (id ? 'id=' + id : 'query=' + Document.asString(query)) : '');
|
|
3254
3382
|
(cloud || this).formatFail(64, service, ["Unable to execute query", queryString], emptyResponse(queryString, service), { ...Cloud.LOG_CLOUD_FAIL, startTime });
|
|
3255
3383
|
break;
|
|
3256
3384
|
}
|
|
3257
3385
|
case 'uri': {
|
|
3258
3386
|
const { uri, format = uri && path.extname(uri).substring(1) } = item;
|
|
3259
|
-
this.formatFail(4, format || 'URI', ['No records were found', uri], emptyResponse(uri)
|
|
3387
|
+
this.formatFail(4, format || 'URI', ['No records were found', uri], emptyResponse(uri));
|
|
3260
3388
|
break;
|
|
3261
3389
|
}
|
|
3262
3390
|
case 'local': {
|
|
3263
3391
|
const { pathname, format = pathname && path.extname(pathname).substring(1) } = item;
|
|
3264
|
-
this.formatFail(4, format || 'LOCAL', ['No records were found', pathname], emptyResponse(pathname)
|
|
3392
|
+
this.formatFail(4, format || 'LOCAL', ['No records were found', pathname], emptyResponse(pathname));
|
|
3265
3393
|
break;
|
|
3266
3394
|
}
|
|
3267
3395
|
case 'export': {
|
|
@@ -3270,22 +3398,22 @@ class ChromeDocument extends Document {
|
|
|
3270
3398
|
if (typeof target === 'function') {
|
|
3271
3399
|
target = target.name;
|
|
3272
3400
|
}
|
|
3273
|
-
this.formatFail(4, 'EXPORT', ['No records were retrieved', target], emptyResponse(target)
|
|
3401
|
+
this.formatFail(4, 'EXPORT', ['No records were retrieved', target], emptyResponse(target));
|
|
3274
3402
|
break;
|
|
3275
3403
|
}
|
|
3276
3404
|
}
|
|
3277
3405
|
}
|
|
3278
|
-
removeElement(item);
|
|
3406
|
+
removeElement(this, domBase, item);
|
|
3279
3407
|
}
|
|
3280
3408
|
}
|
|
3281
3409
|
resolve();
|
|
3282
3410
|
});
|
|
3283
3411
|
}), 'Element text or attribute replacement');
|
|
3284
3412
|
};
|
|
3285
|
-
if (dataItems.length) {
|
|
3413
|
+
if (dataItems.length > 0) {
|
|
3286
3414
|
await setElements(dataItems);
|
|
3287
3415
|
}
|
|
3288
|
-
if (displayItems.length) {
|
|
3416
|
+
if (displayItems.length > 0) {
|
|
3289
3417
|
await setElements(displayItems);
|
|
3290
3418
|
}
|
|
3291
3419
|
}
|
|
@@ -3527,7 +3655,7 @@ class ChromeDocument extends Document {
|
|
|
3527
3655
|
while (bracket = pattern.exec(current)) {
|
|
3528
3656
|
const segment = bracket[0];
|
|
3529
3657
|
if (/[{}]/.test(segment)) {
|
|
3530
|
-
const placeholder = '`' + (0,
|
|
3658
|
+
const placeholder = '`' + (0, crypto_1.randomUUID)() + '`';
|
|
3531
3659
|
replaceMap.push([placeholder, segment]);
|
|
3532
3660
|
current = replaceMatch(bracket, current, placeholder, pattern);
|
|
3533
3661
|
}
|
|
@@ -3539,11 +3667,11 @@ class ChromeDocument extends Document {
|
|
|
3539
3667
|
const values = (0, util_1.splitEnclosing)(current, /\burl/gi);
|
|
3540
3668
|
for (let i = 0, length = values.length; i < length; ++i) {
|
|
3541
3669
|
const seg = values[i];
|
|
3542
|
-
if (/^url\([^{}]*[{}]
|
|
3543
|
-
replaceMap.push([values[i] = (0,
|
|
3670
|
+
if (/^url\([^{}]*[{}].*\)$/is.test(seg)) {
|
|
3671
|
+
replaceMap.push([values[i] = (0, crypto_1.randomUUID)(), seg]);
|
|
3544
3672
|
}
|
|
3545
3673
|
}
|
|
3546
|
-
if (replaceMap.length) {
|
|
3674
|
+
if (replaceMap.length > 0) {
|
|
3547
3675
|
current = values.join('');
|
|
3548
3676
|
}
|
|
3549
3677
|
}
|
|
@@ -3612,7 +3740,7 @@ class ChromeDocument extends Document {
|
|
|
3612
3740
|
invalid = 1;
|
|
3613
3741
|
break;
|
|
3614
3742
|
}
|
|
3615
|
-
|
|
3743
|
+
if (leading !== -1 && empty[1] === ';') {
|
|
3616
3744
|
content = target.substring(index, found).substring(0, leading).replace(/[^\n;]+$/, '');
|
|
3617
3745
|
invalid = 1;
|
|
3618
3746
|
break;
|
|
@@ -3688,7 +3816,7 @@ class ChromeDocument extends Document {
|
|
|
3688
3816
|
const fontFamily = useUnsafeCssReplace ? REGEXP_FONTFAMILY_UNSAFE : REGEXP_FONTFAMILY;
|
|
3689
3817
|
while (match = pattern.exec(current)) {
|
|
3690
3818
|
const font = fontFamily.exec(match[0]);
|
|
3691
|
-
if (font && !usedFontFace.includes(font[1].trim().replace(/^(["'])(
|
|
3819
|
+
if (font && !usedFontFace.includes(font[1].trim().replace(/^(["'])(.+)\1$/s, (...content) => content[2]))) {
|
|
3692
3820
|
current = spliceSource(current, match.index, getEndIndex(match), pattern, match[1], match[3]);
|
|
3693
3821
|
modified = true;
|
|
3694
3822
|
}
|
|
@@ -3716,7 +3844,7 @@ class ChromeDocument extends Document {
|
|
|
3716
3844
|
}
|
|
3717
3845
|
pattern.lastIndex = 0;
|
|
3718
3846
|
}
|
|
3719
|
-
if (replaceMap.length) {
|
|
3847
|
+
if (replaceMap.length > 0) {
|
|
3720
3848
|
for (const [placeholder, content] of replaceMap.reverse()) {
|
|
3721
3849
|
current = current.replace(placeholder, content);
|
|
3722
3850
|
}
|
|
@@ -3733,21 +3861,23 @@ class ChromeDocument extends Document {
|
|
|
3733
3861
|
const host = this.host;
|
|
3734
3862
|
const restartable = host ? host.restartable || this.watching : false;
|
|
3735
3863
|
const idMap = this._idMap;
|
|
3736
|
-
this.assets
|
|
3864
|
+
for (const item of this.assets) {
|
|
3737
3865
|
const { element, id, flags } = item;
|
|
3738
3866
|
if (element) {
|
|
3739
3867
|
if (restartable && id && !(0, types_1.cloneFlag)(flags)) {
|
|
3740
3868
|
const backup = idMap[id];
|
|
3741
3869
|
if (backup) {
|
|
3742
3870
|
elements.add(item.element = (0, types_1.cloneObject)(backup, true));
|
|
3743
|
-
|
|
3871
|
+
continue;
|
|
3744
3872
|
}
|
|
3745
3873
|
idMap[id] = (0, types_1.cloneObject)(element, true);
|
|
3746
3874
|
}
|
|
3747
3875
|
elements.add(element);
|
|
3748
3876
|
}
|
|
3749
|
-
}
|
|
3750
|
-
|
|
3877
|
+
}
|
|
3878
|
+
for (const item of this.dataSource) {
|
|
3879
|
+
elements.add(item.element);
|
|
3880
|
+
}
|
|
3751
3881
|
return this._elements = Array.from(elements);
|
|
3752
3882
|
}
|
|
3753
3883
|
get editing() {
|
|
@@ -3759,18 +3889,13 @@ class ChromeDocument extends Document {
|
|
|
3759
3889
|
}
|
|
3760
3890
|
}
|
|
3761
3891
|
get dataSource() {
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
return result;
|
|
3892
|
+
if (this._dataSource) {
|
|
3893
|
+
return this._dataSource;
|
|
3765
3894
|
}
|
|
3766
3895
|
const host = this.host;
|
|
3767
3896
|
if (host) {
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
return this._dataSource = host.restartable || this.watching ? items.map(item => (0, types_1.cloneObject)(item, true)) : items;
|
|
3771
|
-
}
|
|
3772
|
-
catch {
|
|
3773
|
-
}
|
|
3897
|
+
const items = host.getDataSourceItems(this);
|
|
3898
|
+
return this._dataSource = host.restartable || this.watching ? items.map(item => (0, types_1.cloneObject)(item, true)) : items;
|
|
3774
3899
|
}
|
|
3775
3900
|
return [];
|
|
3776
3901
|
}
|