@pi-r/chrome 0.9.4 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +667 -610
- package/package.json +6 -5
- package/types/index.d.ts +4 -2
- package/types/squared.d.ts +2 -2
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const path = require("node:path");
|
|
3
3
|
const fs = require("node:fs");
|
|
4
4
|
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const image_size_1 = require("image-size");
|
|
5
6
|
const Cloud = require("@e-mc/cloud");
|
|
6
7
|
const core_1 = require("@e-mc/core");
|
|
7
8
|
const dom_1 = require("@e-mc/document/parse/dom");
|
|
@@ -10,6 +11,7 @@ const asset_1 = require("@e-mc/document/asset");
|
|
|
10
11
|
const util_1 = require("@e-mc/document/util");
|
|
11
12
|
const transform_1 = require("@e-mc/document/transform");
|
|
12
13
|
const Document = require('@e-mc/document');
|
|
14
|
+
const kChrome = Symbol.for('chrome:constructor');
|
|
13
15
|
const CACHE_DBRESULT = new Map();
|
|
14
16
|
const CACHE_LOCALFILE = new Map();
|
|
15
17
|
const CACHE_QUERY = new Map();
|
|
@@ -32,10 +34,11 @@ const [REGEXP_NTHCHILD, REGEXP_NTHCHILD_UNSAFE, REGEXP_REPLACECSS] = (function (
|
|
|
32
34
|
];
|
|
33
35
|
})();
|
|
34
36
|
const REGEXP_SRCSETSIZE = /~\s*([\d.]+)\s*([wx])/i;
|
|
35
|
-
const REGEXP_TEMPLATECONDITIONAL = /(\n\s+)?\{\{if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)(.*?)(?:\s*\{\{else
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
37
|
+
const REGEXP_TEMPLATECONDITIONAL = /(\n\s+)?\{\{\s*if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)(.*?)((?:\s*\{\{\s*else if\s+(?:(?:[^}]|}(?!}))+?)\}\}.*?)*)(?:\s*\{\{\s*else\s*\}\}(\s*)(.*?))?\s*\{\{\s*end\s*\}\}/gs;
|
|
38
|
+
const REGEXP_TEMPLATEELSEIF = /\{\{\s*else if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)((?:.(?!\{\{\s*else if))*)/gs;
|
|
39
|
+
const REGEXP_TEMPLATECOMPARISON = /\s*\(\s*(?:(eq|ne|lt|le|gt|ge)\s+)?("[^"]+"|'[^']+'|[^\s)]+)(?:\s+("[^"]+"|'[^']+'|[^\s)]+))?\s*\)/g;
|
|
40
|
+
const REGEXP_TEMPLATEMATCH = new RegExp(`^(?:(and|or|not)\\s+)?((?:${REGEXP_TEMPLATECOMPARISON.source})+)|(!|not\\s+)?([^\\s][\\S\\s]*)$`);
|
|
41
|
+
const REGEXP_IMPORTMODULE = /(?:(?:^|[\n;]+)\s*import\s+(?:("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')|.+?from\s+("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')(?:[ \t]+with[ \t]+\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\})?)|\bimport\(\s*("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')\s*(?:,\s*\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\}\s*)?\))/gd;
|
|
39
42
|
const REGEXP_BLOCKEXCLUDE = new RegExp(`(\\s*)<!--\\s*exclude\\s*:\\s*(?:start|end)\\s*-->` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
|
|
40
43
|
const REGEXP_COMMENT = new RegExp(dom_1.DomWriter.PATTERN_COMMENT, 'g');
|
|
41
44
|
const REGEXP_QUOTEDVALUE = new RegExp(`\\b(?:@import${PATTERN_STRING_MANY}|content${PATTERN_STRING_SOME}:${PATTERN_STRING_SOME})(?:"[^"]*"|'[^']*')`, 'gi');
|
|
@@ -118,12 +121,6 @@ function trimTemplate(value) {
|
|
|
118
121
|
}
|
|
119
122
|
return value;
|
|
120
123
|
}
|
|
121
|
-
function trimQuote(value) {
|
|
122
|
-
value = value.trim();
|
|
123
|
-
const first = value[0];
|
|
124
|
-
const last = value[value.length - 1];
|
|
125
|
-
return first === last && (first === '"' || first === "'") ? value.substring(1, value.length - 1).trim() : value;
|
|
126
|
-
}
|
|
127
124
|
function findClosingIndex(source, lastIndex, char) {
|
|
128
125
|
const pattern = char === '{' ? /[{}]/g : /[()]/g;
|
|
129
126
|
pattern.lastIndex = lastIndex;
|
|
@@ -209,7 +206,7 @@ function hasCondition(data, condition) {
|
|
|
209
206
|
if (items.length > 0 && !isSpace(match[0][0])) {
|
|
210
207
|
return false;
|
|
211
208
|
}
|
|
212
|
-
items.push([match[1], trimQuote(match[2]), trimQuote(match[3])]);
|
|
209
|
+
items.push([match[1], (0, util_1.trimQuote)(match[2]), (0, util_1.trimQuote)(match[3])]);
|
|
213
210
|
}
|
|
214
211
|
REGEXP_TEMPLATECOMPARISON.lastIndex = 0;
|
|
215
212
|
const length = items.length;
|
|
@@ -220,7 +217,7 @@ function hasCondition(data, condition) {
|
|
|
220
217
|
const item = items[i];
|
|
221
218
|
const arg1 = item[1];
|
|
222
219
|
const arg2 = item[2];
|
|
223
|
-
let valid;
|
|
220
|
+
let valid = false;
|
|
224
221
|
if (arg2) {
|
|
225
222
|
switch (item[0]) {
|
|
226
223
|
case 'eq':
|
|
@@ -265,7 +262,7 @@ function hasCondition(data, condition) {
|
|
|
265
262
|
}
|
|
266
263
|
}
|
|
267
264
|
}
|
|
268
|
-
return join
|
|
265
|
+
return join !== 'or';
|
|
269
266
|
}
|
|
270
267
|
if (match[7]) {
|
|
271
268
|
return isTruthy(data, match[7].trim(), match[6]);
|
|
@@ -273,6 +270,36 @@ function hasCondition(data, condition) {
|
|
|
273
270
|
}
|
|
274
271
|
return false;
|
|
275
272
|
}
|
|
273
|
+
function checkConditionBranch(data, value) {
|
|
274
|
+
REGEXP_TEMPLATEELSEIF.lastIndex = 0;
|
|
275
|
+
let match;
|
|
276
|
+
while (match = REGEXP_TEMPLATEELSEIF.exec(value)) {
|
|
277
|
+
if (hasCondition(data, match[1])) {
|
|
278
|
+
return match;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
function getConditionalValue(data, value) {
|
|
284
|
+
REGEXP_TEMPLATECONDITIONAL.lastIndex = 0;
|
|
285
|
+
const match = REGEXP_TEMPLATECONDITIONAL.exec(value);
|
|
286
|
+
if (match) {
|
|
287
|
+
let result, branch;
|
|
288
|
+
if (hasCondition(data, match[2])) {
|
|
289
|
+
result = match[4];
|
|
290
|
+
}
|
|
291
|
+
else if (match[5] && (branch = checkConditionBranch(data, match[5]))) {
|
|
292
|
+
result = branch[3];
|
|
293
|
+
}
|
|
294
|
+
else if (match[7]) {
|
|
295
|
+
result = match[7];
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
return result.trim();
|
|
301
|
+
}
|
|
302
|
+
}
|
|
276
303
|
function isTruthy(data, attr, falsey) {
|
|
277
304
|
const value = getObjectValue(data, attr);
|
|
278
305
|
return falsey ? !value : !!value;
|
|
@@ -316,7 +343,7 @@ function restoreSearchParams(value, prefix = '__sqd') {
|
|
|
316
343
|
}
|
|
317
344
|
return value || '';
|
|
318
345
|
}
|
|
319
|
-
function
|
|
346
|
+
function collectBaseUrl(asset, baseUrl) {
|
|
320
347
|
const result = [];
|
|
321
348
|
let parentUrl = asset ? asset.url || asset.uri : null;
|
|
322
349
|
try {
|
|
@@ -351,8 +378,8 @@ function createHash(host, file, hash, bufferMap) {
|
|
|
351
378
|
const buffer = localUri && bufferMap[localUri] || getBuffer(file, localUri);
|
|
352
379
|
if (buffer) {
|
|
353
380
|
const [algorithm, length] = (0, util_1.getHashData)(hash);
|
|
354
|
-
|
|
355
|
-
if (
|
|
381
|
+
const value = algorithm ? Document.asHash(buffer, algorithm, { encoding: file.encoding }) : '';
|
|
382
|
+
if (value) {
|
|
356
383
|
if (localUri) {
|
|
357
384
|
bufferMap[localUri] = buffer;
|
|
358
385
|
}
|
|
@@ -366,8 +393,8 @@ function createHash(host, file, hash, bufferMap) {
|
|
|
366
393
|
host.writeFail(["Unable to read file", filename], err, 32);
|
|
367
394
|
}
|
|
368
395
|
}
|
|
369
|
-
function
|
|
370
|
-
const relativeUrl = file.relativeUrl || instance.host.removeCwd(file.localUri) &&
|
|
396
|
+
function getSrcUrl(instance, parent, file) {
|
|
397
|
+
const relativeUrl = file.relativeUrl || instance.host.removeCwd(file.localUri) && getRelativeUrl(file);
|
|
371
398
|
if (!relativeUrl) {
|
|
372
399
|
return ['', false];
|
|
373
400
|
}
|
|
@@ -400,406 +427,6 @@ function getSrcURL(instance, parent, file) {
|
|
|
400
427
|
}
|
|
401
428
|
return [found ? Document.joinPath('../'.repeat(prefix.length), suffix.join('/'), file.filename) : '../'.repeat(prefix.length) + relativeUrl, false];
|
|
402
429
|
}
|
|
403
|
-
function transformURL(instance, host, parent, type, source, importFile) {
|
|
404
|
-
const related = [];
|
|
405
|
-
const baseHref = getBaseURLs(importFile || parent, instance.baseUrl);
|
|
406
|
-
const isHtml = type === 'html';
|
|
407
|
-
const isJs = type === 'js';
|
|
408
|
-
const pattern = isJs ? REGEXP_URL_JS : type === 'svg' ? REGEXP_URL_SVG : REGEXP_URL;
|
|
409
|
-
pattern.lastIndex = 0;
|
|
410
|
-
REGEXP_IMAGESET.lastIndex = 0;
|
|
411
|
-
let length = source.length, modified = false, match;
|
|
412
|
-
while (match = REGEXP_IMAGESET.exec(source)) {
|
|
413
|
-
const startIndex = match.index + match[0].length;
|
|
414
|
-
const endIndex = findClosingIndex(source, startIndex, '(');
|
|
415
|
-
if (endIndex === -1) {
|
|
416
|
-
continue;
|
|
417
|
-
}
|
|
418
|
-
REGEXP_IMAGESET_URL.lastIndex = 0;
|
|
419
|
-
let content = source.substring(startIndex, endIndex), url;
|
|
420
|
-
while (url = REGEXP_IMAGESET_URL.exec(content)) {
|
|
421
|
-
const quote = url[2] ? '"' : "'";
|
|
422
|
-
const [a, b] = url.indices[1];
|
|
423
|
-
content = (0, util_1.spliceString)(content, a, b, `url(${quote + (url[2] || url[3]).trim() + quote})`, REGEXP_IMAGESET_URL);
|
|
424
|
-
modified = true;
|
|
425
|
-
}
|
|
426
|
-
if (modified) {
|
|
427
|
-
source = (0, util_1.spliceString)(source, startIndex, endIndex, content, REGEXP_IMAGESET);
|
|
428
|
-
modified = false;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
while (match = pattern.exec(source)) {
|
|
432
|
-
const isText = !!match[1];
|
|
433
|
-
const isHref = !!match[2];
|
|
434
|
-
const isUrl = !isText && !isHref;
|
|
435
|
-
const startIndex = match.index;
|
|
436
|
-
let quote = match[1], content = '', trailing = '', closed = -1, i = startIndex + match[0].length;
|
|
437
|
-
for (let j = -1; i < length; ++i) {
|
|
438
|
-
const ch = source[i];
|
|
439
|
-
if (quote && ch === quote) {
|
|
440
|
-
if (!isText) {
|
|
441
|
-
content += ch;
|
|
442
|
-
}
|
|
443
|
-
if (isHref) {
|
|
444
|
-
break;
|
|
445
|
-
}
|
|
446
|
-
if (source[i - 1] !== '\\') {
|
|
447
|
-
if (isText) {
|
|
448
|
-
break;
|
|
449
|
-
}
|
|
450
|
-
if (closed === -1) {
|
|
451
|
-
closed = i + 1;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
j = i + 1;
|
|
455
|
-
continue;
|
|
456
|
-
}
|
|
457
|
-
if (!quote && (ch === '"' || ch === "'" || ch === '`' && isJs) && (isHref || !content.trim())) {
|
|
458
|
-
quote = ch;
|
|
459
|
-
}
|
|
460
|
-
else if (isHref && !quote && isSpace(ch) && content.trim()) {
|
|
461
|
-
break;
|
|
462
|
-
}
|
|
463
|
-
else if (ch === ')') {
|
|
464
|
-
if (isUrl) {
|
|
465
|
-
if (quote && closed !== -1 || !quote && (isJs || source[i - 1] !== '\\')) {
|
|
466
|
-
break;
|
|
467
|
-
}
|
|
468
|
-
j = i;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
else if (j !== -1 && (ch === '\n' ||
|
|
472
|
-
isText && (ch === ';' || ch === '{') ||
|
|
473
|
-
isHref && (ch === '=' || ch === '>') ||
|
|
474
|
-
isUrl && (ch === ';' ||
|
|
475
|
-
!isJs && (!isHtml && (ch === ':' && !isJs || ch === '}') ||
|
|
476
|
-
isHtml && (ch === '"' || ch === "'" || ch === ':' || ch === '>'))))) {
|
|
477
|
-
if (closed !== -1) {
|
|
478
|
-
i = closed;
|
|
479
|
-
}
|
|
480
|
-
else {
|
|
481
|
-
content = content.substring(0, i = j);
|
|
482
|
-
}
|
|
483
|
-
break;
|
|
484
|
-
}
|
|
485
|
-
if (closed === -1) {
|
|
486
|
-
content += ch;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
const setOutputURL = (value, asset) => {
|
|
490
|
-
if (!value) {
|
|
491
|
-
return;
|
|
492
|
-
}
|
|
493
|
-
if (asset) {
|
|
494
|
-
if (!asset.inlineBase64) {
|
|
495
|
-
if (host.Cloud?.getStorage('upload', asset.cloudStorage)) {
|
|
496
|
-
const inlineUrlCloud = asset.inlineUrlCloud ||= (0, node_crypto_1.randomUUID)();
|
|
497
|
-
(parent.inlineUrlCloudMap ||= {})[inlineUrlCloud] = value;
|
|
498
|
-
value = inlineUrlCloud;
|
|
499
|
-
}
|
|
500
|
-
else if (asset.hash && instance.productionRelease) {
|
|
501
|
-
const inlineUrl = asset.inlineUrl ||= (0, node_crypto_1.randomUUID)();
|
|
502
|
-
(parent.inlineUrlMap ||= {})[inlineUrl] = value;
|
|
503
|
-
value = inlineUrl;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
const font = findFont(asset.format);
|
|
507
|
-
if (font) {
|
|
508
|
-
found: {
|
|
509
|
-
for (let k = i + 1; k < length; ++k) {
|
|
510
|
-
switch (source[k]) {
|
|
511
|
-
case ')': {
|
|
512
|
-
const component = source.substring(i + 1, k + 1);
|
|
513
|
-
const format = /\s+format\([^)]+\)$/i.exec(component);
|
|
514
|
-
if (format) {
|
|
515
|
-
trailing = component.replace(format[0], ` format("${font}")`);
|
|
516
|
-
i = k;
|
|
517
|
-
break found;
|
|
518
|
-
}
|
|
519
|
-
break;
|
|
520
|
-
}
|
|
521
|
-
case ',':
|
|
522
|
-
case ';':
|
|
523
|
-
case ':':
|
|
524
|
-
case '}':
|
|
525
|
-
break found;
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
if (asset.initialValue && !asset.initialValue.cacheable) {
|
|
531
|
-
parent.flags |= 16;
|
|
532
|
-
}
|
|
533
|
-
related.push(asset);
|
|
534
|
-
}
|
|
535
|
-
if (!quote && !isHtml && !isJs) {
|
|
536
|
-
if (!value.includes('"')) {
|
|
537
|
-
quote = '"';
|
|
538
|
-
}
|
|
539
|
-
else if (!value.includes("'")) {
|
|
540
|
-
quote = "'";
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
if (isUrl) {
|
|
544
|
-
const index = value.indexOf('#');
|
|
545
|
-
if (index !== -1) {
|
|
546
|
-
value = value.substring(0, index);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
if (quote) {
|
|
550
|
-
value = quote + value + quote;
|
|
551
|
-
}
|
|
552
|
-
const revised = isJs ? 'import(' + value + trailing + ')' : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
553
|
-
source = (0, util_1.spliceString)(source, startIndex, i + 1, revised, pattern);
|
|
554
|
-
length = source.length;
|
|
555
|
-
modified = true;
|
|
556
|
-
};
|
|
557
|
-
let url;
|
|
558
|
-
if (isJs) {
|
|
559
|
-
if (!quote) {
|
|
560
|
-
continue;
|
|
561
|
-
}
|
|
562
|
-
const file = new RegExp('^\\s*(' + quote + '((?:[^' + quote + ']|(?<=\\\\)' + quote + ')+)' + quote + ')\\s*(,.+)$').exec(content);
|
|
563
|
-
if (file) {
|
|
564
|
-
url = file[1].trim();
|
|
565
|
-
trailing = file[2].trim();
|
|
566
|
-
}
|
|
567
|
-
else {
|
|
568
|
-
url = trimQuote(content);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
else {
|
|
572
|
-
url = trimQuote(content);
|
|
573
|
-
}
|
|
574
|
-
if (url.startsWith('data:')) {
|
|
575
|
-
const base64 = url.split(',')[1]?.trim();
|
|
576
|
-
if (base64) {
|
|
577
|
-
for (const item of instance.assets) {
|
|
578
|
-
if (item.base64 === base64) {
|
|
579
|
-
setOutputURL(getSrcURL(instance, parent, item)[0], item);
|
|
580
|
-
break;
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
else if (baseHref.length > 0) {
|
|
586
|
-
let fullUrl, asset;
|
|
587
|
-
for (const parentUrl of baseHref) {
|
|
588
|
-
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)) {
|
|
589
|
-
break;
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
if (asset && asset !== importFile) {
|
|
593
|
-
if (!(0, util_1.hasValue)(asset.format, 'base64')) {
|
|
594
|
-
if (asset.bundleReplace) {
|
|
595
|
-
let k = 0, valid;
|
|
596
|
-
if (!isText) {
|
|
597
|
-
let j = startIndex;
|
|
598
|
-
while (isSpace(source[--j])) { }
|
|
599
|
-
valid = source.substring(k = j - 6, j + 1) === '@import';
|
|
600
|
-
}
|
|
601
|
-
else {
|
|
602
|
-
k = startIndex;
|
|
603
|
-
valid = true;
|
|
604
|
-
}
|
|
605
|
-
if (valid) {
|
|
606
|
-
let l = i, revised = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
607
|
-
for (let ch; l < length; ++l) {
|
|
608
|
-
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
609
|
-
break;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
const layer = instance.replaceContent(revised, source.substring(k, l + 1), "text/css");
|
|
613
|
-
if (layer) {
|
|
614
|
-
revised = layer;
|
|
615
|
-
}
|
|
616
|
-
revised = transformURL(instance, host, parent, type, instance.removeServerRoot(revised), asset) || revised;
|
|
617
|
-
source = (0, util_1.spliceString)(source, k, l + 1, revised, pattern);
|
|
618
|
-
length = source.length;
|
|
619
|
-
if (!parent.watch) {
|
|
620
|
-
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
621
|
-
asset.invalid = true;
|
|
622
|
-
}
|
|
623
|
-
else {
|
|
624
|
-
related.push(asset);
|
|
625
|
-
if (!(0, types_1.existsFlag)(asset.flags)) {
|
|
626
|
-
asset.flags |= 8;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
modified = true;
|
|
630
|
-
continue;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
if (hasSameOrigin(asset.url || fullUrl, ...baseHref)) {
|
|
634
|
-
let sameDir = false;
|
|
635
|
-
[fullUrl, sameDir] = getSrcURL(instance, parent, asset);
|
|
636
|
-
if (sameDir && isJs) {
|
|
637
|
-
fullUrl = './' + fullUrl;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
else {
|
|
641
|
-
const pathname = parent.pathname;
|
|
642
|
-
const count = pathname && pathname !== '/' ? pathname.split('/').length : 0;
|
|
643
|
-
fullUrl = (count ? '../'.repeat(count) : '') + asset.relativeUrl;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
else if (!asset.invalid) {
|
|
647
|
-
fullUrl = asset.inlineBase64 ||= (0, node_crypto_1.randomUUID)();
|
|
648
|
-
}
|
|
649
|
-
if (url !== fullUrl) {
|
|
650
|
-
setOutputURL(fullUrl, asset);
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
else if (importFile && url !== fullUrl) {
|
|
654
|
-
setOutputURL(fullUrl);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
if (modified) {
|
|
659
|
-
if (related.length > 0) {
|
|
660
|
-
const previous = instance.related.get(parent);
|
|
661
|
-
if (previous) {
|
|
662
|
-
for (const item of related) {
|
|
663
|
-
previous.add(item);
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
else {
|
|
667
|
-
instance.related.set(parent, new Set(related));
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
return source;
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
function getFormatUUID(instance, attr, ext) {
|
|
674
|
-
const format = 'formatMap' in instance ? instance.formatMap : instance.module.format;
|
|
675
|
-
let pattern;
|
|
676
|
-
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, node_crypto_1.randomUUID)();
|
|
677
|
-
}
|
|
678
|
-
function setLocationUUID(instance, data, file, ext) {
|
|
679
|
-
const { pathname, filename } = data;
|
|
680
|
-
const assignUUID = ChromeDocument.INTERNAL_ASSIGNUUID;
|
|
681
|
-
let index = 0, modified = false;
|
|
682
|
-
if (filename) {
|
|
683
|
-
ext ||= path.extname(filename).substring(1);
|
|
684
|
-
if ((index = filename.indexOf(assignUUID)) !== -1) {
|
|
685
|
-
data.filename = (0, util_1.spliceString)(filename, index, index + assignUUID.length, getFormatUUID(instance, 'filename', ext));
|
|
686
|
-
if (file) {
|
|
687
|
-
file.inlineFilename = data.filename;
|
|
688
|
-
}
|
|
689
|
-
modified = true;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
if (pathname && (index = pathname.indexOf(assignUUID)) !== -1) {
|
|
693
|
-
data.pathname = (0, util_1.spliceString)(pathname, index, index + assignUUID.length, getFormatUUID(instance, 'pathname', ext));
|
|
694
|
-
modified = true;
|
|
695
|
-
}
|
|
696
|
-
if (file && modified) {
|
|
697
|
-
(0, asset_1.setInitialValue)(file, false);
|
|
698
|
-
if (file.hash) {
|
|
699
|
-
delete file.hash;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
function transformOptions(instance, file, mimeType, code, bundleContent) {
|
|
704
|
-
const { uri, localUri, exported } = file;
|
|
705
|
-
const metadata = { userAgentData: instance.userAgentData };
|
|
706
|
-
switch (mimeType) {
|
|
707
|
-
case "text/html":
|
|
708
|
-
metadata.__fromhtml__ = true;
|
|
709
|
-
case "text/css":
|
|
710
|
-
Object.assign(metadata, instance.config);
|
|
711
|
-
default:
|
|
712
|
-
if ((0, types_1.isObject)(file.metadata)) {
|
|
713
|
-
Object.assign(metadata, file.metadata);
|
|
714
|
-
}
|
|
715
|
-
break;
|
|
716
|
-
}
|
|
717
|
-
const [pathname, filename] = localUri ? [path.dirname(localUri), path.basename(localUri)] : ['', file.filename];
|
|
718
|
-
const options = { pathname, filename, mimeType, metadata, imported: !!file.imports && file.imported !== false };
|
|
719
|
-
const sourceFile = !exported && uri && instance.findSourceRoot(uri);
|
|
720
|
-
if (sourceFile) {
|
|
721
|
-
if (Document.isPath(sourceFile)) {
|
|
722
|
-
options.sourceFile = sourceFile;
|
|
723
|
-
}
|
|
724
|
-
options.sourceName = path.basename(sourceFile);
|
|
725
|
-
options.sourcesRelativeTo = path.dirname(sourceFile);
|
|
726
|
-
options.getMainFile = instance.resolveSourceFile(file);
|
|
727
|
-
if (code) {
|
|
728
|
-
options.getSourceFiles = instance.locateSourceFiles(file, code, bundleContent);
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
if ((!instance.productionRelease || instance.productionIncremental) && !(0, types_1.modifiedFlag)(file.flags)) {
|
|
732
|
-
options.cacheData = { uri: !exported ? uri : undefined, etag: !file.modified ? file.etag : undefined, encoding: file.encoding };
|
|
733
|
-
}
|
|
734
|
-
return options;
|
|
735
|
-
}
|
|
736
|
-
function transformJs(instance, host, file, output) {
|
|
737
|
-
const { sourceFiles, chunks, map } = output;
|
|
738
|
-
const localUri = file.localUri;
|
|
739
|
-
const emptySources = !!instance.productionRelease;
|
|
740
|
-
let uri;
|
|
741
|
-
if (map && (uri = Document.writeSourceMap(localUri, output, { hash: file.hash, emptySources, inlineMap: hasSourceMap(file.metadata, 'inline') }))) {
|
|
742
|
-
host.add(uri, file, types_1.FILE_TYPE.SOURCEMAP);
|
|
743
|
-
}
|
|
744
|
-
if (chunks) {
|
|
745
|
-
const elements = instance.elements;
|
|
746
|
-
const localDir = path.dirname(localUri);
|
|
747
|
-
const relativeDir = Document.joinPath(file.moveTo, file.pathname);
|
|
748
|
-
const element = file.element;
|
|
749
|
-
let order = 0, index, appending;
|
|
750
|
-
if (element) {
|
|
751
|
-
index = element.index;
|
|
752
|
-
for (const item of elements) {
|
|
753
|
-
const append = item.append;
|
|
754
|
-
if (append && !append.prepend && dom_1.DomWriter.isEqual(item, element, host.moduleName, true)) {
|
|
755
|
-
(appending ||= []).push(append);
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
for (const chunk of chunks) {
|
|
760
|
-
let chunkName = chunk.filename;
|
|
761
|
-
if (!chunkName) {
|
|
762
|
-
chunkName = getFormatUUID(instance, 'filename', 'js') + path.extname(localUri);
|
|
763
|
-
chunk.entryPoint = true;
|
|
764
|
-
}
|
|
765
|
-
const chunkUri = path.join(localDir, chunkName);
|
|
766
|
-
if (chunk.map && (uri = Document.writeSourceMap(chunkUri, chunk, { emptySources, inlineMap: hasSourceMap(file.metadata, 'inline') }))) {
|
|
767
|
-
host.add(uri, file, types_1.FILE_TYPE.SOURCEMAP);
|
|
768
|
-
}
|
|
769
|
-
try {
|
|
770
|
-
fs.writeFileSync(chunkUri, chunk.code);
|
|
771
|
-
host.add(chunkUri, file);
|
|
772
|
-
if (chunk.entryPoint) {
|
|
773
|
-
if (element) {
|
|
774
|
-
const attributes = { ...file.attributes, src: Document.joinPath(relativeDir, chunkName) };
|
|
775
|
-
if (file.imports && file.imported !== false) {
|
|
776
|
-
attributes.type ||= 'module';
|
|
777
|
-
}
|
|
778
|
-
elements.push({
|
|
779
|
-
...element,
|
|
780
|
-
attributes,
|
|
781
|
-
append: { tagName: 'script', tagCount: element.tagCount, nextSibling: dom_1.DomWriter.isIndex(index) ? index + 1 : undefined, order: ++order }
|
|
782
|
-
});
|
|
783
|
-
}
|
|
784
|
-
else {
|
|
785
|
-
instance.writeFail(['Unable to create script entry point', path.basename(chunkUri)], (0, types_1.errorMessage)('js', 'Element not found', chunkUri), 4);
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
catch (err) {
|
|
790
|
-
instance.writeFail(["Unable to write file", path.basename(chunkUri)], err, 32);
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
appending?.forEach(item => {
|
|
794
|
-
item.order += order;
|
|
795
|
-
});
|
|
796
|
-
}
|
|
797
|
-
if ((0, types_1.isArray)(sourceFiles)) {
|
|
798
|
-
file.sourceFiles = sourceFiles;
|
|
799
|
-
}
|
|
800
|
-
file.modified = true;
|
|
801
|
-
return file.sourceUTF8 = output.code;
|
|
802
|
-
}
|
|
803
430
|
function replaceCss(instance, file) {
|
|
804
431
|
if (file.inlineUrlMap) {
|
|
805
432
|
sanitizeCss(instance, file.inlineUrlMap);
|
|
@@ -826,74 +453,25 @@ function finalizeHtml(value, data) {
|
|
|
826
453
|
}
|
|
827
454
|
return value;
|
|
828
455
|
}
|
|
829
|
-
function
|
|
830
|
-
const { initialValue, format } = file;
|
|
831
|
-
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'))) {
|
|
832
|
-
return true;
|
|
833
|
-
}
|
|
834
|
-
return false;
|
|
835
|
-
}
|
|
836
|
-
function loadLocalFile(instance, item, pathname, cacheData, encoding, out) {
|
|
456
|
+
function loadLocalFile(instance, pathname, encoding, out) {
|
|
837
457
|
let content;
|
|
838
|
-
encoding = (0, types_1.getEncoding)(encoding);
|
|
839
458
|
if (out) {
|
|
840
|
-
content = fs.readFileSync(pathname, encoding);
|
|
459
|
+
content = fs.readFileSync(pathname, (0, types_1.getEncoding)(encoding));
|
|
841
460
|
out.content = content;
|
|
842
461
|
}
|
|
843
462
|
const ext = path.extname(pathname).substring(1).toLowerCase();
|
|
844
463
|
if (ext === 'cjs') {
|
|
845
464
|
return require(pathname);
|
|
846
465
|
}
|
|
847
|
-
content
|
|
848
|
-
const result = instance.tryParse(content, ext);
|
|
466
|
+
const result = instance.tryParse(content || fs.readFileSync(pathname, (0, types_1.getEncoding)(encoding)), ext);
|
|
849
467
|
if (result != null) {
|
|
850
|
-
setCacheData(instance, item, result, pathname, cacheData, true);
|
|
851
468
|
return result;
|
|
852
469
|
}
|
|
853
470
|
}
|
|
854
|
-
function setCacheData(instance, item, data, dataKey, cacheData, template) {
|
|
855
|
-
if ((0, types_1.isObject)(data) || template) {
|
|
856
|
-
const cache = instance.settingsOf(item.source, template && item.source !== 'local' ? 'local_file' : 'cache');
|
|
857
|
-
let timeout = 0;
|
|
858
|
-
if (cache && (timeout = core_1.ClientDb.getTimeout(cache)) && timeout > 0) {
|
|
859
|
-
addCacheItem(template ? CACHE_LOCALFILE : CACHE_DBRESULT, dataKey, data, timeout);
|
|
860
|
-
}
|
|
861
|
-
else {
|
|
862
|
-
cacheData[dataKey] = data;
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
async function checkData(instance, item, name, result, validate) {
|
|
867
|
-
let callback;
|
|
868
|
-
if (typeof name === 'string') {
|
|
869
|
-
const template = instance.findDataValue(name) || name;
|
|
870
|
-
callback = instance.hasEval('userconfig') ? Document.parseFunction(template, instance.hasEval('absolute')) : (0, types_1.asFunction)(template);
|
|
871
|
-
}
|
|
872
|
-
else {
|
|
873
|
-
callback = name;
|
|
874
|
-
name = '';
|
|
875
|
-
}
|
|
876
|
-
if (typeof callback === 'function') {
|
|
877
|
-
try {
|
|
878
|
-
let output;
|
|
879
|
-
if (callback["__cjs__"]) {
|
|
880
|
-
output = await callback(result, item);
|
|
881
|
-
}
|
|
882
|
-
else {
|
|
883
|
-
output = await callback.apply(Document.enabled("node.process.inline") ? process : null, Document.enabled("node.require.inline") ? [result, item, require] : [result, item]);
|
|
884
|
-
}
|
|
885
|
-
if (validate(output)) {
|
|
886
|
-
return output;
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
catch (err) {
|
|
890
|
-
instance.writeFail(["Unable to parse inline method", name], err);
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
471
|
function removeElement(instance, domBase, item, element) {
|
|
895
472
|
if (item.removeEmpty || item.type === 'display') {
|
|
896
|
-
|
|
473
|
+
element ||= new dom_1.HtmlElement(instance.moduleName, item.element);
|
|
474
|
+
element.remove = true;
|
|
897
475
|
if (!domBase.write(element)) {
|
|
898
476
|
instance.writeFail('Unable to remove element', errorHtml(item.element), { type: 4 });
|
|
899
477
|
}
|
|
@@ -907,9 +485,10 @@ function removeWatchReload(item) {
|
|
|
907
485
|
function errorCredential(instance, domBase, item, err) {
|
|
908
486
|
removeElement(instance, domBase, item);
|
|
909
487
|
const pkg = getPackageName(err);
|
|
910
|
-
if (
|
|
911
|
-
|
|
488
|
+
if (pkg && instance.checkPackage(err, pkg)) {
|
|
489
|
+
return;
|
|
912
490
|
}
|
|
491
|
+
instance.writeFail(["Invalid credentials", item.source], err);
|
|
913
492
|
}
|
|
914
493
|
const isSpace = dom_1.DomWriter.isSpace.bind(dom_1.DomWriter);
|
|
915
494
|
const replaceMatch = dom_1.DomWriter.replaceMatch.bind(dom_1.DomWriter);
|
|
@@ -924,13 +503,14 @@ const isUnedited = (item) => !item.attributes && !item.inlineContent && !item.sr
|
|
|
924
503
|
const isIgnored = (item, exists) => item.invalid || (0, types_1.ignoreFlag)(item.flags) || !exists && (0, types_1.existsFlag)(item.flags);
|
|
925
504
|
const findFont = (value) => value && (Array.isArray(value) ? value : [value]).find(format => isFont(format));
|
|
926
505
|
const getEndIndex = (match) => match.index + match[0].length;
|
|
927
|
-
const
|
|
506
|
+
const getRelativeUrl = (file) => Document.joinPath(file.moveTo, file.pathname, file.inlineFilename || file.filename) + (!file.static ? restoreSearchParams(file.url?.search) : '');
|
|
928
507
|
const validateDir = (value) => path.isAbsolute(value) && Document.isDir(value) ? value : '';
|
|
929
508
|
const valueAsString = (value, delimiter) => Array.isArray(value) && !value.some(child => typeof child === 'object') ? value.join(delimiter) : Document.asString(value);
|
|
930
|
-
const errorHtml = ({ tagName, tagIndex = -1 }) => (0, types_1.errorMessage)('
|
|
509
|
+
const errorHtml = ({ tagName, tagIndex = -1 }) => (0, types_1.errorMessage)('dom-writer', 'Location did not resolve', tagName.toLowerCase() + (tagIndex >= 0 ? ': ' + tagIndex : ''));
|
|
931
510
|
const errorDataSource = (value, hint) => (0, types_1.errorMessage)('data-source', value, hint);
|
|
932
511
|
const isHtmlOnly = (assets, items, htmlFile) => !items.find(item => item !== htmlFile && assets.includes(item));
|
|
933
512
|
class ChromeDocument extends Document {
|
|
513
|
+
static [kChrome] = true;
|
|
934
514
|
static INTERNAL_ASSIGNUUID = "__assign__";
|
|
935
515
|
static INTERNAL_SERVERROOT = "__serverroot__";
|
|
936
516
|
static async purgeMemory(percent = 1, limit = 0, parent) {
|
|
@@ -1101,7 +681,7 @@ class ChromeDocument extends Document {
|
|
|
1101
681
|
(function recurse(children) {
|
|
1102
682
|
for (const item of children) {
|
|
1103
683
|
if (!items.has(item)) {
|
|
1104
|
-
if (isWatched(
|
|
684
|
+
if (instance.isWatched(item)) {
|
|
1105
685
|
item.flags |= 8;
|
|
1106
686
|
}
|
|
1107
687
|
items.add(item);
|
|
@@ -1169,7 +749,7 @@ class ChromeDocument extends Document {
|
|
|
1169
749
|
}
|
|
1170
750
|
const dest = path.join(destDir, subDir[subDir.length - 1]);
|
|
1171
751
|
Document.renameFile(src, dest);
|
|
1172
|
-
instance.addLog(types_1.STATUS_TYPE.INFO, `production: ${dest} (mapped)`,
|
|
752
|
+
instance.addLog(types_1.STATUS_TYPE.INFO, `production: ${dest} (mapped)`, { source: subDir.join(path.sep) });
|
|
1173
753
|
emptyDir.add(path.dirname(src));
|
|
1174
754
|
if (i !== start) {
|
|
1175
755
|
for (let j = 0; j < i; ++j) {
|
|
@@ -1181,11 +761,7 @@ class ChromeDocument extends Document {
|
|
|
1181
761
|
catch (err) {
|
|
1182
762
|
errorMove(err);
|
|
1183
763
|
if (Document.isPath(src)) {
|
|
1184
|
-
fs.unlink(src,
|
|
1185
|
-
if (error) {
|
|
1186
|
-
instance.addLog(types_1.STATUS_TYPE.WARN, error);
|
|
1187
|
-
}
|
|
1188
|
-
});
|
|
764
|
+
fs.unlink(src, () => { });
|
|
1189
765
|
}
|
|
1190
766
|
}
|
|
1191
767
|
finally {
|
|
@@ -1198,7 +774,7 @@ class ChromeDocument extends Document {
|
|
|
1198
774
|
}
|
|
1199
775
|
for (const item of mapped) {
|
|
1200
776
|
if (item[2] === 0) {
|
|
1201
|
-
instance.addLog(types_1.STATUS_TYPE.INFO, `production: ${item[1]} (mapped: 0)`,
|
|
777
|
+
instance.addLog(types_1.STATUS_TYPE.INFO, `production: ${item[1]} (mapped: 0)`, { source: item[0] });
|
|
1202
778
|
}
|
|
1203
779
|
}
|
|
1204
780
|
for (const pathname of Array.from(emptyDir).sort((a, b) => b.length - a.length)) {
|
|
@@ -1294,6 +870,8 @@ class ChromeDocument extends Document {
|
|
|
1294
870
|
_threadable = true;
|
|
1295
871
|
_dataSource;
|
|
1296
872
|
_mimeMap;
|
|
873
|
+
_sessionKey = null;
|
|
874
|
+
_sessionData = Object.create(null);
|
|
1297
875
|
_elements = null;
|
|
1298
876
|
_cloudUrlMap;
|
|
1299
877
|
_cloudUploaded;
|
|
@@ -1454,10 +1032,10 @@ class ChromeDocument extends Document {
|
|
|
1454
1032
|
for (const storage of cloud) {
|
|
1455
1033
|
for (const { service, upload, download } of storage) {
|
|
1456
1034
|
if (upload) {
|
|
1457
|
-
|
|
1035
|
+
this.processLocation(upload, service);
|
|
1458
1036
|
}
|
|
1459
1037
|
if (download) {
|
|
1460
|
-
|
|
1038
|
+
this.processLocation(download, service);
|
|
1461
1039
|
}
|
|
1462
1040
|
}
|
|
1463
1041
|
}
|
|
@@ -1511,7 +1089,7 @@ class ChromeDocument extends Document {
|
|
|
1511
1089
|
switch (mimeType) {
|
|
1512
1090
|
case "text/html":
|
|
1513
1091
|
if (format) {
|
|
1514
|
-
const output = await this.transform('html', host.getUTF8String(file, localUri), format,
|
|
1092
|
+
const output = await this.transform('html', host.getUTF8String(file, localUri), format, this.createTransformOptions(host, file, mimeType));
|
|
1515
1093
|
if (output) {
|
|
1516
1094
|
file.modified = true;
|
|
1517
1095
|
file.sourceUTF8 = output.code;
|
|
@@ -1521,7 +1099,7 @@ class ChromeDocument extends Document {
|
|
|
1521
1099
|
case "text/css":
|
|
1522
1100
|
if (format) {
|
|
1523
1101
|
const source = host.getUTF8String(file, localUri);
|
|
1524
|
-
const output = await this.transform('css', source, format,
|
|
1102
|
+
const output = await this.transform('css', source, format, this.createTransformOptions(host, file, mimeType, source));
|
|
1525
1103
|
if (output) {
|
|
1526
1104
|
if (output.map) {
|
|
1527
1105
|
const uri = Document.writeSourceMap(localUri, output, { mimeType, hash, emptySources: productionRelease, inlineMap: hasSourceMap(file.metadata, 'inline') });
|
|
@@ -1546,9 +1124,9 @@ class ChromeDocument extends Document {
|
|
|
1546
1124
|
file.modified = true;
|
|
1547
1125
|
}
|
|
1548
1126
|
if (format) {
|
|
1549
|
-
const output = await this.transform('js', source, format,
|
|
1127
|
+
const output = await this.transform('js', source, format, this.createTransformOptions(host, file, mimeType, source));
|
|
1550
1128
|
if (output) {
|
|
1551
|
-
source =
|
|
1129
|
+
source = this.processJs(host, file, output);
|
|
1552
1130
|
}
|
|
1553
1131
|
}
|
|
1554
1132
|
file.sourceUTF8 = source;
|
|
@@ -1562,7 +1140,7 @@ class ChromeDocument extends Document {
|
|
|
1562
1140
|
this.svgFiles.push(file);
|
|
1563
1141
|
}
|
|
1564
1142
|
else if (format) {
|
|
1565
|
-
const output = await this.transform('html', source, format,
|
|
1143
|
+
const output = await this.transform('html', source, format, this.createTransformOptions(host, file, mimeType, source));
|
|
1566
1144
|
if (output) {
|
|
1567
1145
|
file.modified = true;
|
|
1568
1146
|
file.sourceUTF8 = output.code;
|
|
@@ -1570,10 +1148,10 @@ class ChromeDocument extends Document {
|
|
|
1570
1148
|
}
|
|
1571
1149
|
break;
|
|
1572
1150
|
}
|
|
1573
|
-
case
|
|
1574
|
-
case
|
|
1575
|
-
case
|
|
1576
|
-
case
|
|
1151
|
+
case "font/ttf":
|
|
1152
|
+
case "font/otf":
|
|
1153
|
+
case "font/woff":
|
|
1154
|
+
case "font/woff2": {
|
|
1577
1155
|
const setFormat = (type) => {
|
|
1578
1156
|
if (Array.isArray(format)) {
|
|
1579
1157
|
file.format = format.filter(value => !isFont(value));
|
|
@@ -1607,9 +1185,9 @@ class ChromeDocument extends Document {
|
|
|
1607
1185
|
return;
|
|
1608
1186
|
}
|
|
1609
1187
|
const instance = host.loadModule('compress');
|
|
1610
|
-
const buffer =
|
|
1188
|
+
const buffer = file.buffer || localUri;
|
|
1611
1189
|
if (instance && buffer) {
|
|
1612
|
-
const options = { format: to, filename: file.filename, etag: file.etag };
|
|
1190
|
+
const options = { format: to, filename: file.filename, etag: file.etag, worker: file.worker };
|
|
1613
1191
|
await instance.tryFile(buffer, options)
|
|
1614
1192
|
.then(result => {
|
|
1615
1193
|
if (result) {
|
|
@@ -1658,9 +1236,18 @@ class ChromeDocument extends Document {
|
|
|
1658
1236
|
this.replaced.push(file);
|
|
1659
1237
|
}
|
|
1660
1238
|
else {
|
|
1661
|
-
|
|
1239
|
+
const modified = this.processLocation(file, path.extname(file.filename).substring(1));
|
|
1240
|
+
if (modified.length > 0) {
|
|
1241
|
+
if (modified.includes('filename')) {
|
|
1242
|
+
file.inlineFilename = file.filename;
|
|
1243
|
+
}
|
|
1244
|
+
(0, asset_1.setInitialValue)(file, false);
|
|
1245
|
+
if (file.hash) {
|
|
1246
|
+
delete file.hash;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1662
1249
|
}
|
|
1663
|
-
file.relativeUrl =
|
|
1250
|
+
file.relativeUrl = getRelativeUrl(file);
|
|
1664
1251
|
}
|
|
1665
1252
|
resolveUri(file, source, trailing) {
|
|
1666
1253
|
const host = this.host;
|
|
@@ -1686,17 +1273,17 @@ class ChromeDocument extends Document {
|
|
|
1686
1273
|
let mainFile, pathname, match;
|
|
1687
1274
|
const ignorePath = bundleMain && (mainFile = this.findSourceRoot(bundleMain.uri)) && (Document.isDir(mainFile) || (mainFile = path.dirname(mainFile))) && mainFile === localFile;
|
|
1688
1275
|
while (match = REGEXP_IMPORTMODULE.exec(output)) {
|
|
1689
|
-
const
|
|
1276
|
+
const type = match[3] || match[5];
|
|
1690
1277
|
const idx = match[1] ? 1 : match[2] ? 2 : 4;
|
|
1691
1278
|
const [a, b] = match.indices[idx];
|
|
1692
|
-
const from = trimQuote(match[idx]);
|
|
1279
|
+
const from = (0, util_1.trimQuote)(match[idx]);
|
|
1693
1280
|
const quote = output[a];
|
|
1694
1281
|
const relative = /^\.{0,2}\//.test(from);
|
|
1695
|
-
if (
|
|
1282
|
+
if (type && /\btype\s*:\s*(["'`])(?:css|json)\1/.test(type)) {
|
|
1696
1283
|
try {
|
|
1697
1284
|
const asset = host.findAsset(relative ? new URL(from, uri) : from);
|
|
1698
1285
|
if (asset) {
|
|
1699
|
-
const [relativeUrl, sameDir] =
|
|
1286
|
+
const [relativeUrl, sameDir] = getSrcUrl(this, bundleMain || file, asset);
|
|
1700
1287
|
if (relativeUrl) {
|
|
1701
1288
|
output = (0, util_1.spliceString)(output, a, b, quote + (sameDir ? './' : '') + relativeUrl + quote, REGEXP_IMPORTMODULE);
|
|
1702
1289
|
}
|
|
@@ -1743,7 +1330,7 @@ class ChromeDocument extends Document {
|
|
|
1743
1330
|
if (!(0, types_1.isEmpty)(bundleId)) {
|
|
1744
1331
|
for (const asset of this.assets) {
|
|
1745
1332
|
if (asset.bundleIndex === 0 && asset.bundleId === bundleId) {
|
|
1746
|
-
const output =
|
|
1333
|
+
const output = this.processUrl(host, file, source, 'css', asset);
|
|
1747
1334
|
if (output) {
|
|
1748
1335
|
source = output;
|
|
1749
1336
|
file.modified = true;
|
|
@@ -1753,7 +1340,7 @@ class ChromeDocument extends Document {
|
|
|
1753
1340
|
}
|
|
1754
1341
|
}
|
|
1755
1342
|
if (trailing && this.htmlFile) {
|
|
1756
|
-
const output =
|
|
1343
|
+
const output = this.processUrl(host, file, trailing, 'css', this.htmlFile);
|
|
1757
1344
|
if (output) {
|
|
1758
1345
|
trailing = output;
|
|
1759
1346
|
}
|
|
@@ -1794,7 +1381,7 @@ class ChromeDocument extends Document {
|
|
|
1794
1381
|
if (hosted) {
|
|
1795
1382
|
const asset = this.host?.findAsset(uri);
|
|
1796
1383
|
if (asset) {
|
|
1797
|
-
const [relativeUrl, sameDir] =
|
|
1384
|
+
const [relativeUrl, sameDir] = getSrcUrl(this, bundleMain || file, asset);
|
|
1798
1385
|
if (relativeUrl) {
|
|
1799
1386
|
value = (sameDir ? './' : '') + relativeUrl;
|
|
1800
1387
|
}
|
|
@@ -1934,7 +1521,7 @@ class ChromeDocument extends Document {
|
|
|
1934
1521
|
}
|
|
1935
1522
|
if (output && output !== source) {
|
|
1936
1523
|
try {
|
|
1937
|
-
fs.writeFileSync(item.localUri, output, item.encoding ||= '
|
|
1524
|
+
fs.writeFileSync(item.localUri, output, item.encoding ||= 'utf8');
|
|
1938
1525
|
item.sourceUTF8 = output;
|
|
1939
1526
|
}
|
|
1940
1527
|
catch (err) {
|
|
@@ -2013,7 +1600,7 @@ class ChromeDocument extends Document {
|
|
|
2013
1600
|
found = true;
|
|
2014
1601
|
using.push(asset);
|
|
2015
1602
|
}
|
|
2016
|
-
else if (isWatched(
|
|
1603
|
+
else if (this.isWatched(asset) ||
|
|
2017
1604
|
(0, types_1.watchFlag)(asset.flags) ||
|
|
2018
1605
|
asset.base64 && watch.related.find(item => (0, asset_1.isEqual)(item, asset)) ||
|
|
2019
1606
|
(0, types_1.isArray)(asset.cloudStorage) && asset.cloudStorage.some(item => item.upload?.active)) {
|
|
@@ -2094,7 +1681,7 @@ class ChromeDocument extends Document {
|
|
|
2094
1681
|
if (srcset) {
|
|
2095
1682
|
const uri = Document.toPosix(file.uri);
|
|
2096
1683
|
const items = new Set([uri]);
|
|
2097
|
-
const baseHref =
|
|
1684
|
+
const baseHref = collectBaseUrl(this.htmlFile, this.baseUrl);
|
|
2098
1685
|
const sameOrigin = hasSameOrigin(file.url || uri, ...baseHref);
|
|
2099
1686
|
if (sameOrigin) {
|
|
2100
1687
|
const src = element.getAttribute('src');
|
|
@@ -2226,7 +1813,7 @@ class ChromeDocument extends Document {
|
|
|
2226
1813
|
continue;
|
|
2227
1814
|
}
|
|
2228
1815
|
let source = host.getUTF8String(item);
|
|
2229
|
-
const output =
|
|
1816
|
+
const output = this.processUrl(host, item, source, 'svg');
|
|
2230
1817
|
if (output) {
|
|
2231
1818
|
source = output;
|
|
2232
1819
|
item.modified = true;
|
|
@@ -2234,7 +1821,7 @@ class ChromeDocument extends Document {
|
|
|
2234
1821
|
source = sanitizeSource(item, source);
|
|
2235
1822
|
const format = item.format;
|
|
2236
1823
|
if (format) {
|
|
2237
|
-
const result = await this.transform('html', source, format,
|
|
1824
|
+
const result = await this.transform('html', source, format, this.createTransformOptions(host, item, "image/svg+xml"));
|
|
2238
1825
|
if (result) {
|
|
2239
1826
|
item.modified = true;
|
|
2240
1827
|
source = result.code;
|
|
@@ -2261,7 +1848,7 @@ class ChromeDocument extends Document {
|
|
|
2261
1848
|
source = output;
|
|
2262
1849
|
item.modified = true;
|
|
2263
1850
|
}
|
|
2264
|
-
if (output =
|
|
1851
|
+
if (output = this.processUrl(host, item, source, 'css')) {
|
|
2265
1852
|
source = output;
|
|
2266
1853
|
item.modified = true;
|
|
2267
1854
|
}
|
|
@@ -2269,7 +1856,7 @@ class ChromeDocument extends Document {
|
|
|
2269
1856
|
item.sourceUTF8 = source;
|
|
2270
1857
|
if (item.format) {
|
|
2271
1858
|
transforms.push(item);
|
|
2272
|
-
tasks.push(this.transform('css', source, item.format,
|
|
1859
|
+
tasks.push(this.transform('css', source, item.format, this.createTransformOptions(host, item, "text/css", source)));
|
|
2273
1860
|
}
|
|
2274
1861
|
}
|
|
2275
1862
|
for (const item of this.jsFiles) {
|
|
@@ -2285,7 +1872,7 @@ class ChromeDocument extends Document {
|
|
|
2285
1872
|
source = output;
|
|
2286
1873
|
item.modified = true;
|
|
2287
1874
|
}
|
|
2288
|
-
if (output =
|
|
1875
|
+
if (output = this.processUrl(host, item, source, 'js')) {
|
|
2289
1876
|
source = output;
|
|
2290
1877
|
item.modified = true;
|
|
2291
1878
|
}
|
|
@@ -2293,7 +1880,7 @@ class ChromeDocument extends Document {
|
|
|
2293
1880
|
item.sourceUTF8 = source;
|
|
2294
1881
|
if (format) {
|
|
2295
1882
|
transforms.push(item);
|
|
2296
|
-
tasks.push(this.transform('js', source, format,
|
|
1883
|
+
tasks.push(this.transform('js', source, format, this.createTransformOptions(host, item, "application/javascript", source)));
|
|
2297
1884
|
}
|
|
2298
1885
|
}
|
|
2299
1886
|
return Promise.allSettled(tasks).then(items => {
|
|
@@ -2313,7 +1900,7 @@ class ChromeDocument extends Document {
|
|
|
2313
1900
|
target.sourceUTF8 = value.code;
|
|
2314
1901
|
}
|
|
2315
1902
|
else {
|
|
2316
|
-
|
|
1903
|
+
this.processJs(host, target, value);
|
|
2317
1904
|
}
|
|
2318
1905
|
}
|
|
2319
1906
|
}
|
|
@@ -2369,7 +1956,7 @@ class ChromeDocument extends Document {
|
|
|
2369
1956
|
}
|
|
2370
1957
|
REGEXP_STYLE.lastIndex = 0;
|
|
2371
1958
|
}
|
|
2372
|
-
if (output =
|
|
1959
|
+
if (output = this.processUrl(host, htmlFile, source, 'html')) {
|
|
2373
1960
|
source = output;
|
|
2374
1961
|
}
|
|
2375
1962
|
source = replaceHtml(this, source, processing, htmlFile.inlineUrlMap);
|
|
@@ -2392,14 +1979,14 @@ class ChromeDocument extends Document {
|
|
|
2392
1979
|
if (domBase.hasErrors()) {
|
|
2393
1980
|
const timeStamp = Date.now();
|
|
2394
1981
|
for (const err of domBase.errors) {
|
|
2395
|
-
this.addLog(types_1.STATUS_TYPE.WARN, 'dom-writer
|
|
1982
|
+
this.addLog(types_1.STATUS_TYPE.WARN, err, { timeStamp, source: 'dom-writer' });
|
|
2396
1983
|
}
|
|
2397
1984
|
}
|
|
2398
1985
|
if (domBase.failCount > 0) {
|
|
2399
|
-
this.writeFail(['Unable to update document', moduleName], (0, types_1.errorMessage)('
|
|
1986
|
+
this.writeFail(['Unable to update document', moduleName], (0, types_1.errorMessage)('dom-writer', domBase.failCount + ' failed', domBase.modifyCount + ' modified'), { type: 4, startTime });
|
|
2400
1987
|
}
|
|
2401
1988
|
else {
|
|
2402
|
-
this.writeTimeProcess('html', `dom-writer: ${domBase.modifyCount} modified
|
|
1989
|
+
this.writeTimeProcess('html', `dom-writer: ${domBase.modifyCount} modified (${path.basename(localUri)})`, startTime);
|
|
2403
1990
|
if (cacheMiss.length > 0) {
|
|
2404
1991
|
const data = {};
|
|
2405
1992
|
const message = [];
|
|
@@ -2479,30 +2066,16 @@ class ChromeDocument extends Document {
|
|
|
2479
2066
|
const detectWidth = domElement.getAttribute('width') === 'detect';
|
|
2480
2067
|
const detectHeight = domElement.getAttribute('height') === 'detect';
|
|
2481
2068
|
if (detectWidth || detectHeight) {
|
|
2482
|
-
let width = 0, height = 0, buffer = null
|
|
2483
|
-
const addLog = (
|
|
2484
|
-
this.addLog(types_1.STATUS_TYPE.WARN, 'Could not detect image ' +
|
|
2069
|
+
let width = 0, height = 0, buffer = null;
|
|
2070
|
+
const addLog = (suffix, err) => {
|
|
2071
|
+
this.addLog(types_1.STATUS_TYPE.WARN, err instanceof Error ? err : 'Could not detect image ' + suffix, { source: item.localUri ? path.basename(item.localUri) : item.filename });
|
|
2485
2072
|
};
|
|
2486
2073
|
if (isImage(item.mimeType) && (buffer = host.getBuffer(item))) {
|
|
2487
2074
|
try {
|
|
2488
|
-
({ width, height } =
|
|
2075
|
+
({ width, height } = (0, image_size_1.imageSize)(buffer));
|
|
2489
2076
|
}
|
|
2490
|
-
catch {
|
|
2491
|
-
|
|
2492
|
-
const dimension = require(packageName = 'probe-image-size').sync(buffer);
|
|
2493
|
-
if (!dimension) {
|
|
2494
|
-
throw new Error("MIME not found");
|
|
2495
|
-
}
|
|
2496
|
-
({ width, height } = dimension);
|
|
2497
|
-
}
|
|
2498
|
-
catch {
|
|
2499
|
-
try {
|
|
2500
|
-
({ width, height } = (await require('jimp').read(buffer)).bitmap);
|
|
2501
|
-
}
|
|
2502
|
-
catch {
|
|
2503
|
-
}
|
|
2504
|
-
packageName = '';
|
|
2505
|
-
}
|
|
2077
|
+
catch (err) {
|
|
2078
|
+
addLog('from buffer', err);
|
|
2506
2079
|
}
|
|
2507
2080
|
}
|
|
2508
2081
|
if (detectWidth) {
|
|
@@ -2539,8 +2112,6 @@ class ChromeDocument extends Document {
|
|
|
2539
2112
|
if (this.dataSource.length === 0) {
|
|
2540
2113
|
return;
|
|
2541
2114
|
}
|
|
2542
|
-
const sessionKey = (0, node_crypto_1.randomUUID)();
|
|
2543
|
-
const cacheData = Object.create(null);
|
|
2544
2115
|
const dataItems = [];
|
|
2545
2116
|
const displayItems = [];
|
|
2546
2117
|
for (const item of this.dataSource) {
|
|
@@ -2552,33 +2123,38 @@ class ChromeDocument extends Document {
|
|
|
2552
2123
|
}
|
|
2553
2124
|
}
|
|
2554
2125
|
const checkObject = (item, data, type) => {
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
const result = data && (0, types_1.cascadeObject)(data, cascade, data);
|
|
2126
|
+
if (item.cascade) {
|
|
2127
|
+
const result = data && (0, types_1.cascadeObject)(data, item.cascade, data);
|
|
2558
2128
|
if (result !== data) {
|
|
2559
2129
|
data = result;
|
|
2560
2130
|
}
|
|
2561
2131
|
else if (item.fallback !== undefined) {
|
|
2562
2132
|
data = item.fallback;
|
|
2563
2133
|
}
|
|
2564
|
-
else if (!(0, types_1.isString)(query)) {
|
|
2134
|
+
else if (!(0, types_1.isString)(item.query)) {
|
|
2565
2135
|
return null;
|
|
2566
2136
|
}
|
|
2567
2137
|
}
|
|
2568
2138
|
if (data) {
|
|
2569
|
-
if ((0, types_1.isString)(
|
|
2570
|
-
const pkg = query.startsWith('$') ? 'jsonpath' : 'jmespath';
|
|
2139
|
+
if ((0, types_1.isString)(item.query)) {
|
|
2140
|
+
const pkg = item.query.startsWith('$') ? Document.checkSemVer('jsonpath-plus', 5) ? null : 'jsonpath' : 'jmespath';
|
|
2571
2141
|
try {
|
|
2572
|
-
if (pkg === '
|
|
2573
|
-
data = require(pkg).
|
|
2142
|
+
if (pkg === 'jmespath') {
|
|
2143
|
+
data = require(pkg).search(data, item.query);
|
|
2144
|
+
}
|
|
2145
|
+
else if (pkg === 'jsonpath') {
|
|
2146
|
+
data = require(pkg).query(data, item.query);
|
|
2574
2147
|
}
|
|
2575
2148
|
else {
|
|
2576
|
-
|
|
2149
|
+
const { JSONPath } = require('jsonpath-plus');
|
|
2150
|
+
data = JSONPath({ path: item.query, json: data });
|
|
2577
2151
|
}
|
|
2578
2152
|
}
|
|
2579
2153
|
catch (err) {
|
|
2580
2154
|
this.abort(item.source);
|
|
2581
|
-
|
|
2155
|
+
if (pkg) {
|
|
2156
|
+
this.checkPackage(err, pkg, ["Unable to filter results", item.source]);
|
|
2157
|
+
}
|
|
2582
2158
|
}
|
|
2583
2159
|
}
|
|
2584
2160
|
if (type && !item.ignoreCoerce && this.settingsOf(type, 'coerce') === true) {
|
|
@@ -2594,7 +2170,7 @@ class ChromeDocument extends Document {
|
|
|
2594
2170
|
const batchGroup = [];
|
|
2595
2171
|
for (const item of sourceSet) {
|
|
2596
2172
|
if (!item.element) {
|
|
2597
|
-
this.addLog(types_1.STATUS_TYPE.WARN, `
|
|
2173
|
+
this.addLog(types_1.STATUS_TYPE.WARN, `No target element {${JSON.stringify(item)}}`, { source: 'dom-writer' });
|
|
2598
2174
|
continue;
|
|
2599
2175
|
}
|
|
2600
2176
|
const type = item.source;
|
|
@@ -2667,10 +2243,10 @@ class ChromeDocument extends Document {
|
|
|
2667
2243
|
let result = new Array(length), errors;
|
|
2668
2244
|
switch (type) {
|
|
2669
2245
|
case 'cloud':
|
|
2670
|
-
result = await cloud.getDatabaseBatchRows(batch, true, sessionKey).catch((err) => {
|
|
2246
|
+
result = await cloud.getDatabaseBatchRows(batch, true, this.sessionKey).catch((err) => {
|
|
2671
2247
|
this.abort(type);
|
|
2672
2248
|
if (err instanceof Error) {
|
|
2673
|
-
cloud.addLog(this.aborted ? types_1.STATUS_TYPE.ERROR : types_1.STATUS_TYPE.WARN, errors = err);
|
|
2249
|
+
cloud.addLog(this.aborted ? types_1.STATUS_TYPE.ERROR : types_1.STATUS_TYPE.WARN, errors = err, { source: batch[0].service });
|
|
2674
2250
|
}
|
|
2675
2251
|
return [];
|
|
2676
2252
|
});
|
|
@@ -2684,7 +2260,7 @@ class ChromeDocument extends Document {
|
|
|
2684
2260
|
break;
|
|
2685
2261
|
case 'uri':
|
|
2686
2262
|
case 'local': {
|
|
2687
|
-
const encoding = current.encoding || '
|
|
2263
|
+
const encoding = current.encoding || 'utf8';
|
|
2688
2264
|
let content, target, data, cacheKey;
|
|
2689
2265
|
if (type === 'local') {
|
|
2690
2266
|
let location;
|
|
@@ -2700,7 +2276,7 @@ class ChromeDocument extends Document {
|
|
|
2700
2276
|
if (current.ignoreCache === 1) {
|
|
2701
2277
|
CACHE_DBRESULT.delete(location);
|
|
2702
2278
|
}
|
|
2703
|
-
if (!(data =
|
|
2279
|
+
if (!(data = this._sessionData[location])) {
|
|
2704
2280
|
try {
|
|
2705
2281
|
content = fs.readFileSync(location, encoding);
|
|
2706
2282
|
cacheKey = location;
|
|
@@ -2742,7 +2318,7 @@ class ChromeDocument extends Document {
|
|
|
2742
2318
|
if (current.ignoreCache === 1) {
|
|
2743
2319
|
CACHE_DBRESULT.delete(target);
|
|
2744
2320
|
}
|
|
2745
|
-
if (!(data =
|
|
2321
|
+
if (!(data = this._sessionData[target])) {
|
|
2746
2322
|
try {
|
|
2747
2323
|
content = await host.Request.get(target, { format, encoding });
|
|
2748
2324
|
cacheKey = target;
|
|
@@ -2765,7 +2341,7 @@ class ChromeDocument extends Document {
|
|
|
2765
2341
|
if (current.ignoreCache === 1) {
|
|
2766
2342
|
CACHE_DBRESULT.delete(pathname);
|
|
2767
2343
|
}
|
|
2768
|
-
if (!(data =
|
|
2344
|
+
if (!(data = this._sessionData[pathname])) {
|
|
2769
2345
|
if (!host.canRead(pathname, { ownPermissionOnly: true })) {
|
|
2770
2346
|
this.abort(type);
|
|
2771
2347
|
errorRemove(current, errorDataSource("Unsupported access", pathname));
|
|
@@ -2785,7 +2361,7 @@ class ChromeDocument extends Document {
|
|
|
2785
2361
|
}
|
|
2786
2362
|
}
|
|
2787
2363
|
if (Buffer.isBuffer(content)) {
|
|
2788
|
-
content = content.toString('
|
|
2364
|
+
content = content.toString('utf8');
|
|
2789
2365
|
}
|
|
2790
2366
|
if ((0, types_1.isString)(content)) {
|
|
2791
2367
|
const { format = path.extname(target).substring(1) } = current;
|
|
@@ -2809,7 +2385,7 @@ class ChromeDocument extends Document {
|
|
|
2809
2385
|
return;
|
|
2810
2386
|
}
|
|
2811
2387
|
if (cacheKey) {
|
|
2812
|
-
|
|
2388
|
+
this.addSessionData(current, cacheKey, data);
|
|
2813
2389
|
}
|
|
2814
2390
|
if ((result[0] = checkObject(current, data, type)) === null) {
|
|
2815
2391
|
this.abort(type);
|
|
@@ -2827,16 +2403,16 @@ class ChromeDocument extends Document {
|
|
|
2827
2403
|
if (current.ignoreCache === 1) {
|
|
2828
2404
|
CACHE_DBRESULT.delete(cacheKey);
|
|
2829
2405
|
}
|
|
2830
|
-
if (cacheKey in
|
|
2831
|
-
result[0] =
|
|
2406
|
+
if (cacheKey in this._sessionData) {
|
|
2407
|
+
result[0] = this._sessionData[cacheKey];
|
|
2832
2408
|
}
|
|
2833
2409
|
else {
|
|
2834
2410
|
const { pathname, execute, params } = current;
|
|
2835
2411
|
let data, target, getData, hint;
|
|
2836
|
-
if (
|
|
2412
|
+
if ((0, types_1.isFunction)(execute)) {
|
|
2837
2413
|
target = execute;
|
|
2838
2414
|
}
|
|
2839
|
-
else if (
|
|
2415
|
+
else if ((0, types_1.isFunction)(pathname)) {
|
|
2840
2416
|
target = pathname;
|
|
2841
2417
|
}
|
|
2842
2418
|
else if ((0, types_1.isString)(pathname)) {
|
|
@@ -2852,49 +2428,49 @@ class ChromeDocument extends Document {
|
|
|
2852
2428
|
}
|
|
2853
2429
|
}
|
|
2854
2430
|
if (!getData) {
|
|
2855
|
-
const
|
|
2431
|
+
const settings = current.settings;
|
|
2856
2432
|
target ||= settings && this.settings.export?.[settings] || pathname;
|
|
2857
|
-
if (
|
|
2433
|
+
if ((0, types_1.isFunction)(target)) {
|
|
2858
2434
|
getData = target;
|
|
2859
2435
|
hint = target.name;
|
|
2860
2436
|
}
|
|
2861
2437
|
else if ((0, types_1.isString)(target)) {
|
|
2862
|
-
getData = this.asSourceFile(target, { encoding });
|
|
2438
|
+
getData = this.asSourceFile(target, { encoding: current.encoding });
|
|
2863
2439
|
hint = target;
|
|
2864
2440
|
}
|
|
2865
2441
|
}
|
|
2866
|
-
if (
|
|
2867
|
-
errorRemove(current, target ? errorDataSource('Not a function', hint) : errorDataSource('Not defined - pathname
|
|
2442
|
+
if (!(0, types_1.isFunction)(getData)) {
|
|
2443
|
+
errorRemove(current, target ? errorDataSource('Not a function', hint) : errorDataSource('Not defined - pathname', type));
|
|
2868
2444
|
return;
|
|
2869
2445
|
}
|
|
2870
2446
|
try {
|
|
2871
2447
|
if (params && !current.ignoreCoerce && this.settingsOf(type, 'coerce') === true) {
|
|
2872
2448
|
(0, types_1.coerceObject)(params);
|
|
2873
2449
|
}
|
|
2874
|
-
if (getData
|
|
2450
|
+
if ((0, types_1.isFunction)(getData, true)) {
|
|
2875
2451
|
data = await getData(params);
|
|
2876
2452
|
}
|
|
2877
2453
|
else {
|
|
2878
2454
|
const thisArg = Document.enabled("node.process.inline") ? process : null;
|
|
2879
|
-
const inline = Document.enabled("node.require.inline");
|
|
2880
2455
|
const args = [params];
|
|
2881
|
-
|
|
2882
|
-
if (inline) {
|
|
2456
|
+
const addRequire = () => {
|
|
2457
|
+
if (Document.enabled("node.require.inline")) {
|
|
2883
2458
|
args.push(require);
|
|
2884
2459
|
}
|
|
2460
|
+
};
|
|
2461
|
+
if (getData.toString().startsWith('async')) {
|
|
2462
|
+
addRequire();
|
|
2885
2463
|
data = await getData.apply(thisArg, args);
|
|
2886
2464
|
}
|
|
2887
2465
|
else {
|
|
2888
2466
|
data = await new Promise(success => {
|
|
2889
2467
|
args.push(success);
|
|
2890
|
-
|
|
2891
|
-
args.push(require);
|
|
2892
|
-
}
|
|
2468
|
+
addRequire();
|
|
2893
2469
|
getData.apply(thisArg, args);
|
|
2894
2470
|
});
|
|
2895
2471
|
}
|
|
2896
2472
|
}
|
|
2897
|
-
|
|
2473
|
+
this.addSessionData(current, cacheKey, data);
|
|
2898
2474
|
}
|
|
2899
2475
|
catch (err) {
|
|
2900
2476
|
this.abort(type);
|
|
@@ -2937,9 +2513,10 @@ class ChromeDocument extends Document {
|
|
|
2937
2513
|
if (cmd.ignoreCache === 1) {
|
|
2938
2514
|
CACHE_LOCALFILE.delete(pathname);
|
|
2939
2515
|
}
|
|
2940
|
-
if (!(search.schema =
|
|
2516
|
+
if (!(search.schema = this._sessionData[pathname])) {
|
|
2941
2517
|
try {
|
|
2942
|
-
search.schema = loadLocalFile(this,
|
|
2518
|
+
search.schema = loadLocalFile(this, pathname, cmd.encoding);
|
|
2519
|
+
this.addSessionData(current, pathname, search.schema, { template: true });
|
|
2943
2520
|
}
|
|
2944
2521
|
catch (err) {
|
|
2945
2522
|
this.writeFail(['Unable to parse document', path.basename(pathname)], err instanceof Error ? errors = err : err, 32);
|
|
@@ -2973,14 +2550,15 @@ class ChromeDocument extends Document {
|
|
|
2973
2550
|
if (cmd.ignoreCache === 1) {
|
|
2974
2551
|
CACHE_LOCALFILE.delete(pathname);
|
|
2975
2552
|
}
|
|
2976
|
-
if (!(cmd.query =
|
|
2553
|
+
if (!(cmd.query = this._sessionData[pathname])) {
|
|
2977
2554
|
const out = { content: '' };
|
|
2978
2555
|
try {
|
|
2979
|
-
cmd.query = loadLocalFile(this,
|
|
2556
|
+
cmd.query = loadLocalFile(this, pathname, cmd.encoding, out);
|
|
2980
2557
|
}
|
|
2981
2558
|
catch {
|
|
2982
|
-
|
|
2559
|
+
cmd.query = out.content;
|
|
2983
2560
|
}
|
|
2561
|
+
this.addSessionData(current, pathname, cmd.query, { template: true });
|
|
2984
2562
|
}
|
|
2985
2563
|
}
|
|
2986
2564
|
}
|
|
@@ -3009,11 +2587,8 @@ class ChromeDocument extends Document {
|
|
|
3009
2587
|
aborting = commandType !== db.commandType.UPDATE;
|
|
3010
2588
|
message = Document.asString(data.search || data.key);
|
|
3011
2589
|
}
|
|
3012
|
-
else {
|
|
3013
|
-
|
|
3014
|
-
if ((0, types_1.isPlainObject)(credential)) {
|
|
3015
|
-
message = credential.database;
|
|
3016
|
-
}
|
|
2590
|
+
else if ((0, types_1.isObject)(data.credential)) {
|
|
2591
|
+
message = data.credential.database;
|
|
3017
2592
|
}
|
|
3018
2593
|
if (data.willAbort) {
|
|
3019
2594
|
this.abort(undefined, err);
|
|
@@ -3026,7 +2601,7 @@ class ChromeDocument extends Document {
|
|
|
3026
2601
|
}
|
|
3027
2602
|
return this.aborted;
|
|
3028
2603
|
};
|
|
3029
|
-
const options = { checkObject, sessionKey, connectOnce: length > 1, outCacheMiss: cacheMiss, errorQuery };
|
|
2604
|
+
const options = { checkObject, sessionKey: this.sessionKey, connectOnce: length > 1, outCacheMiss: cacheMiss, errorQuery };
|
|
3030
2605
|
result = await db.executeBatchQuery(batch, options, result);
|
|
3031
2606
|
}
|
|
3032
2607
|
catch (err) {
|
|
@@ -3046,7 +2621,7 @@ class ChromeDocument extends Document {
|
|
|
3046
2621
|
const empty = (items = result[i]) === null;
|
|
3047
2622
|
if ((items ||= []).length === 0) {
|
|
3048
2623
|
if (whenEmpty) {
|
|
3049
|
-
const data = await
|
|
2624
|
+
const data = await this.processData(item, items, whenEmpty, row => Array.isArray(row));
|
|
3050
2625
|
if (data) {
|
|
3051
2626
|
items = data;
|
|
3052
2627
|
item.transactionFail = false;
|
|
@@ -3064,7 +2639,7 @@ class ChromeDocument extends Document {
|
|
|
3064
2639
|
items = items.slice(0, limit);
|
|
3065
2640
|
}
|
|
3066
2641
|
if (postQuery) {
|
|
3067
|
-
const data = await
|
|
2642
|
+
const data = await this.processData(item, items = items.slice(0), postQuery, row => Array.isArray(row));
|
|
3068
2643
|
if (data) {
|
|
3069
2644
|
items = data;
|
|
3070
2645
|
}
|
|
@@ -3074,7 +2649,7 @@ class ChromeDocument extends Document {
|
|
|
3074
2649
|
const domElement = new dom_1.HtmlElement(this.moduleName, element);
|
|
3075
2650
|
let value = '';
|
|
3076
2651
|
const checkValue = async (name) => {
|
|
3077
|
-
const data = await
|
|
2652
|
+
const data = await this.processData(item, value, name, row => typeof row === 'string');
|
|
3078
2653
|
if (data) {
|
|
3079
2654
|
value = data;
|
|
3080
2655
|
}
|
|
@@ -3089,10 +2664,10 @@ class ChromeDocument extends Document {
|
|
|
3089
2664
|
if (item.ignoreCache === 1) {
|
|
3090
2665
|
CACHE_LOCALFILE.delete(pathname);
|
|
3091
2666
|
}
|
|
3092
|
-
if (!(item.value =
|
|
2667
|
+
if (!(item.value = this._sessionData[pathname])) {
|
|
3093
2668
|
try {
|
|
3094
|
-
item.value = fs.readFileSync(pathname, item.encoding || '
|
|
3095
|
-
|
|
2669
|
+
item.value = fs.readFileSync(pathname, item.encoding || 'utf8');
|
|
2670
|
+
this.addSessionData(item, item.value, pathname, { template: true });
|
|
3096
2671
|
}
|
|
3097
2672
|
catch (err) {
|
|
3098
2673
|
this.writeFail(["Unable to read file", path.basename(pathname)], err, 32);
|
|
@@ -3130,11 +2705,21 @@ class ChromeDocument extends Document {
|
|
|
3130
2705
|
row.__index__ ??= j + 1;
|
|
3131
2706
|
}
|
|
3132
2707
|
let segment = template;
|
|
2708
|
+
REGEXP_TEMPLATECONDITIONAL.lastIndex = 0;
|
|
3133
2709
|
while (match = REGEXP_TEMPLATECONDITIONAL.exec(segment)) {
|
|
3134
|
-
|
|
3135
|
-
|
|
2710
|
+
let col = -1, target = match, branch;
|
|
2711
|
+
if (hasCondition(row, match[2])) {
|
|
2712
|
+
col = 4;
|
|
2713
|
+
}
|
|
2714
|
+
else if (match[5] && (branch = checkConditionBranch(row, match[5]))) {
|
|
2715
|
+
target = branch;
|
|
2716
|
+
col = 3;
|
|
2717
|
+
}
|
|
2718
|
+
else if (match[7]) {
|
|
2719
|
+
col = 7;
|
|
2720
|
+
}
|
|
2721
|
+
segment = replaceMatch(match, segment, target[col] ? (!match[1] || target[col - 1].includes('\n') ? '' : match[1]) + target[col - 1] + target[col] : '', REGEXP_TEMPLATECONDITIONAL);
|
|
3136
2722
|
}
|
|
3137
|
-
REGEXP_TEMPLATECONDITIONAL.lastIndex = 0;
|
|
3138
2723
|
const literal = segment.trim();
|
|
3139
2724
|
if (literal.startsWith('`') && literal.endsWith('`')) {
|
|
3140
2725
|
if (!this.hasEval('function')) {
|
|
@@ -3212,15 +2797,19 @@ class ChromeDocument extends Document {
|
|
|
3212
2797
|
let joinString = ' ', match;
|
|
3213
2798
|
for (const row of items) {
|
|
3214
2799
|
for (let seg of segment) {
|
|
3215
|
-
seg = seg.trim()
|
|
3216
|
-
if (seg.startsWith(':') && (match = /^:join\((.*)\)$/is.exec(seg))) {
|
|
2800
|
+
if (match = /^:join\((.*)\)$/is.exec(seg = seg.trim())) {
|
|
3217
2801
|
joinString = match[1];
|
|
3218
2802
|
continue;
|
|
3219
2803
|
}
|
|
3220
|
-
|
|
3221
|
-
|
|
2804
|
+
const content = getConditionalValue(row, seg);
|
|
2805
|
+
if (typeof content === 'string') {
|
|
2806
|
+
seg = content;
|
|
3222
2807
|
valid = true;
|
|
3223
2808
|
}
|
|
2809
|
+
else if (content === null) {
|
|
2810
|
+
valid = true;
|
|
2811
|
+
continue;
|
|
2812
|
+
}
|
|
3224
2813
|
if (seg) {
|
|
3225
2814
|
if (match = /^:text\((.*)\)$/is.exec(seg)) {
|
|
3226
2815
|
value += (value ? joinString : '') + match[1];
|
|
@@ -3236,7 +2825,6 @@ class ChromeDocument extends Document {
|
|
|
3236
2825
|
}
|
|
3237
2826
|
}
|
|
3238
2827
|
}
|
|
3239
|
-
REGEXP_TEMPLATECONDITIONAL.lastIndex = 0;
|
|
3240
2828
|
}
|
|
3241
2829
|
}
|
|
3242
2830
|
}
|
|
@@ -3304,11 +2892,15 @@ class ChromeDocument extends Document {
|
|
|
3304
2892
|
}
|
|
3305
2893
|
break;
|
|
3306
2894
|
}
|
|
3307
|
-
const
|
|
3308
|
-
if (
|
|
3309
|
-
seg =
|
|
2895
|
+
const content = getConditionalValue(row, seg);
|
|
2896
|
+
if (typeof content === 'string') {
|
|
2897
|
+
seg = content;
|
|
2898
|
+
}
|
|
2899
|
+
else if (content === null) {
|
|
2900
|
+
remove = true;
|
|
2901
|
+
errors = 1;
|
|
2902
|
+
break;
|
|
3310
2903
|
}
|
|
3311
|
-
REGEXP_TEMPLATECONDITIONAL.lastIndex = 0;
|
|
3312
2904
|
const sign = seg[0];
|
|
3313
2905
|
if (sign === '+' || sign === '-') {
|
|
3314
2906
|
seg = seg.substring(1);
|
|
@@ -3368,7 +2960,7 @@ class ChromeDocument extends Document {
|
|
|
3368
2960
|
break invalid;
|
|
3369
2961
|
}
|
|
3370
2962
|
if (!domBase.write(domElement) || errors) {
|
|
3371
|
-
this.writeFail(item.type === 'display' ? domElement.remove ? errors ? 'Element was removed with errors' : 'Unable to remove element' : 'Unable to determine display conditional' : 'Unable to replace ' + item.type, errors instanceof Error ? errors : errorHtml(element), { type: 4, startTime });
|
|
2963
|
+
this.writeFail(item.type === 'display' ? domElement.remove && errors !== 1 ? errors ? 'Element was removed with errors' : 'Unable to remove element' : 'Unable to determine display conditional' : 'Unable to replace ' + item.type, errors instanceof Error ? errors : errorHtml(element), { type: 4, startTime });
|
|
3372
2964
|
}
|
|
3373
2965
|
}
|
|
3374
2966
|
}
|
|
@@ -3376,7 +2968,7 @@ class ChromeDocument extends Document {
|
|
|
3376
2968
|
if (!empty && item.type !== 'display' || item.transactionFail) {
|
|
3377
2969
|
const emptyResponse = (value, service = item.source) => {
|
|
3378
2970
|
value ||= "Unknown";
|
|
3379
|
-
return errors instanceof Error ?
|
|
2971
|
+
return errorDataSource(service + ': ' + (errors instanceof Error ? errors.message : 'Empty'), value);
|
|
3380
2972
|
};
|
|
3381
2973
|
switch (item.source) {
|
|
3382
2974
|
case 'cloud': {
|
|
@@ -3437,7 +3029,7 @@ class ChromeDocument extends Document {
|
|
|
3437
3029
|
case 'script': {
|
|
3438
3030
|
const attributes = item.attributes;
|
|
3439
3031
|
if (attributes) {
|
|
3440
|
-
const algorithm = (0, types_1.isString)(attributes.integrity) ? attributes.integrity.
|
|
3032
|
+
const algorithm = (0, types_1.isString)(attributes.integrity) ? attributes.integrity.toLowerCase() : '';
|
|
3441
3033
|
switch (algorithm) {
|
|
3442
3034
|
case 'sha256':
|
|
3443
3035
|
case 'sha384':
|
|
@@ -3854,6 +3446,468 @@ class ChromeDocument extends Document {
|
|
|
3854
3446
|
return current;
|
|
3855
3447
|
}
|
|
3856
3448
|
}
|
|
3449
|
+
isWatched(file) {
|
|
3450
|
+
const { initialValue, format } = file;
|
|
3451
|
+
return (file.imported ||
|
|
3452
|
+
file.bundleReplace ||
|
|
3453
|
+
file.inlineContent ||
|
|
3454
|
+
file.inlineBase64 ||
|
|
3455
|
+
this.replaced.includes(file) ||
|
|
3456
|
+
initialValue && (file.inlineFilename !== initialValue.inlineFilename || file.pathname !== initialValue.pathname || initialValue.cacheable === false) ||
|
|
3457
|
+
format && ((0, util_1.hasValue)(format, 'base64') || (0, util_1.hasValue)(format, 'woff') || (0, util_1.hasValue)(format, 'woff2')) ? true : false);
|
|
3458
|
+
}
|
|
3459
|
+
async processData(item, result, method, validate) {
|
|
3460
|
+
let callback;
|
|
3461
|
+
if (typeof method === 'string') {
|
|
3462
|
+
const template = this.findDataValue(method) || method;
|
|
3463
|
+
callback = this.hasEval('userconfig') ? Document.parseFunction(template, this.hasEval('absolute')) : (0, types_1.asFunction)(template);
|
|
3464
|
+
}
|
|
3465
|
+
else {
|
|
3466
|
+
callback = method;
|
|
3467
|
+
method = '';
|
|
3468
|
+
}
|
|
3469
|
+
if (typeof callback === 'function') {
|
|
3470
|
+
try {
|
|
3471
|
+
let output;
|
|
3472
|
+
if ((0, types_1.isFunction)(callback, true)) {
|
|
3473
|
+
output = await callback(result, item);
|
|
3474
|
+
}
|
|
3475
|
+
else {
|
|
3476
|
+
const thisArg = Document.enabled("node.process.inline") ? process : null;
|
|
3477
|
+
const args = [result, item];
|
|
3478
|
+
if (Document.enabled("node.require.inline")) {
|
|
3479
|
+
args.push(require);
|
|
3480
|
+
}
|
|
3481
|
+
output = await callback.apply(thisArg, args);
|
|
3482
|
+
}
|
|
3483
|
+
if (!validate || validate(output)) {
|
|
3484
|
+
return output;
|
|
3485
|
+
}
|
|
3486
|
+
}
|
|
3487
|
+
catch (err) {
|
|
3488
|
+
this.writeFail(["Unable to parse inline method", method], err);
|
|
3489
|
+
}
|
|
3490
|
+
}
|
|
3491
|
+
}
|
|
3492
|
+
processJs(host, file, output) {
|
|
3493
|
+
const writeSourceMap = (uri, data, hash) => {
|
|
3494
|
+
const value = Document.writeSourceMap(uri, data, { hash, emptySources: !!this.productionRelease, inlineMap: hasSourceMap(file.metadata, 'inline') });
|
|
3495
|
+
if (value) {
|
|
3496
|
+
host.add(value, file, types_1.FILE_TYPE.SOURCEMAP);
|
|
3497
|
+
}
|
|
3498
|
+
};
|
|
3499
|
+
if (output.map) {
|
|
3500
|
+
writeSourceMap(file.localUri, output, file.hash);
|
|
3501
|
+
}
|
|
3502
|
+
if (output.chunks) {
|
|
3503
|
+
const elements = this.elements;
|
|
3504
|
+
const localUri = file.localUri;
|
|
3505
|
+
const localDir = path.dirname(localUri);
|
|
3506
|
+
const relativeDir = Document.joinPath(file.moveTo, file.pathname);
|
|
3507
|
+
const element = file.element;
|
|
3508
|
+
let order = 0, appending;
|
|
3509
|
+
if (element) {
|
|
3510
|
+
for (const item of elements) {
|
|
3511
|
+
const append = item.append;
|
|
3512
|
+
if (append && !append.prepend && dom_1.DomWriter.isEqual(item, element, host.moduleName, true)) {
|
|
3513
|
+
(appending ||= []).push(append);
|
|
3514
|
+
}
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
for (const chunk of output.chunks) {
|
|
3518
|
+
let chunkName = chunk.filename;
|
|
3519
|
+
if (!chunkName) {
|
|
3520
|
+
chunkName = this.formatLocation('filename', 'js') + path.extname(localUri);
|
|
3521
|
+
chunk.entryPoint = true;
|
|
3522
|
+
}
|
|
3523
|
+
const chunkUri = path.join(localDir, chunkName);
|
|
3524
|
+
if (chunk.map) {
|
|
3525
|
+
writeSourceMap(chunkUri, chunk);
|
|
3526
|
+
}
|
|
3527
|
+
try {
|
|
3528
|
+
fs.writeFileSync(chunkUri, chunk.code);
|
|
3529
|
+
host.add(chunkUri, file);
|
|
3530
|
+
if (chunk.entryPoint) {
|
|
3531
|
+
if (element) {
|
|
3532
|
+
const attributes = { ...file.attributes, src: Document.joinPath(relativeDir, chunkName) };
|
|
3533
|
+
if (file.imports && file.imported !== false) {
|
|
3534
|
+
attributes.type ||= 'module';
|
|
3535
|
+
}
|
|
3536
|
+
elements.push({
|
|
3537
|
+
...element,
|
|
3538
|
+
attributes,
|
|
3539
|
+
append: { tagName: 'script', tagCount: element.tagCount, nextSibling: dom_1.DomWriter.isIndex(element.index) ? element.index + 1 : undefined, order: ++order }
|
|
3540
|
+
});
|
|
3541
|
+
}
|
|
3542
|
+
else {
|
|
3543
|
+
this.writeFail(['Unable to create entry point', path.basename(chunkUri)], (0, types_1.errorMessage)('js', 'Element not found', chunkUri), 4);
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
}
|
|
3547
|
+
catch (err) {
|
|
3548
|
+
this.writeFail(["Unable to write file", path.basename(chunkUri)], err, 32);
|
|
3549
|
+
}
|
|
3550
|
+
}
|
|
3551
|
+
appending?.forEach(item => {
|
|
3552
|
+
item.order += order;
|
|
3553
|
+
});
|
|
3554
|
+
}
|
|
3555
|
+
if ((0, types_1.isArray)(output.sourceFiles)) {
|
|
3556
|
+
file.sourceFiles = output.sourceFiles;
|
|
3557
|
+
}
|
|
3558
|
+
file.modified = true;
|
|
3559
|
+
return file.sourceUTF8 = output.code;
|
|
3560
|
+
}
|
|
3561
|
+
processUrl(host, file, source, type, importFile) {
|
|
3562
|
+
const related = [];
|
|
3563
|
+
const baseHref = collectBaseUrl(importFile || file, this.baseUrl);
|
|
3564
|
+
const isHtml = type === 'html';
|
|
3565
|
+
const isJs = type === 'js';
|
|
3566
|
+
const pattern = isJs ? REGEXP_URL_JS : type === 'svg' ? REGEXP_URL_SVG : REGEXP_URL;
|
|
3567
|
+
pattern.lastIndex = 0;
|
|
3568
|
+
REGEXP_IMAGESET.lastIndex = 0;
|
|
3569
|
+
let length = source.length, modified = false, match;
|
|
3570
|
+
while (match = REGEXP_IMAGESET.exec(source)) {
|
|
3571
|
+
const startIndex = match.index + match[0].length;
|
|
3572
|
+
const endIndex = findClosingIndex(source, startIndex, '(');
|
|
3573
|
+
if (endIndex === -1) {
|
|
3574
|
+
continue;
|
|
3575
|
+
}
|
|
3576
|
+
REGEXP_IMAGESET_URL.lastIndex = 0;
|
|
3577
|
+
let content = source.substring(startIndex, endIndex), url;
|
|
3578
|
+
while (url = REGEXP_IMAGESET_URL.exec(content)) {
|
|
3579
|
+
const quote = url[2] ? '"' : "'";
|
|
3580
|
+
const [a, b] = url.indices[1];
|
|
3581
|
+
content = (0, util_1.spliceString)(content, a, b, `url(${quote + (url[2] || url[3]).trim() + quote})`, REGEXP_IMAGESET_URL);
|
|
3582
|
+
modified = true;
|
|
3583
|
+
}
|
|
3584
|
+
if (modified) {
|
|
3585
|
+
source = (0, util_1.spliceString)(source, startIndex, endIndex, content, REGEXP_IMAGESET);
|
|
3586
|
+
modified = false;
|
|
3587
|
+
}
|
|
3588
|
+
}
|
|
3589
|
+
while (match = pattern.exec(source)) {
|
|
3590
|
+
const isText = !!match[1];
|
|
3591
|
+
const isHref = !!match[2];
|
|
3592
|
+
const isUrl = !isText && !isHref;
|
|
3593
|
+
const startIndex = match.index;
|
|
3594
|
+
let quote = match[1], content = '', trailing = '', closed = -1, i = startIndex + match[0].length;
|
|
3595
|
+
for (let j = -1; i < length; ++i) {
|
|
3596
|
+
const ch = source[i];
|
|
3597
|
+
if (quote && ch === quote) {
|
|
3598
|
+
if (!isText) {
|
|
3599
|
+
content += ch;
|
|
3600
|
+
}
|
|
3601
|
+
if (isHref) {
|
|
3602
|
+
break;
|
|
3603
|
+
}
|
|
3604
|
+
if (source[i - 1] !== '\\') {
|
|
3605
|
+
if (isText) {
|
|
3606
|
+
break;
|
|
3607
|
+
}
|
|
3608
|
+
if (closed === -1) {
|
|
3609
|
+
closed = i + 1;
|
|
3610
|
+
}
|
|
3611
|
+
}
|
|
3612
|
+
j = i + 1;
|
|
3613
|
+
continue;
|
|
3614
|
+
}
|
|
3615
|
+
if (!quote && (ch === '"' || ch === "'" || ch === '`' && isJs) && (isHref || !content.trim())) {
|
|
3616
|
+
quote = ch;
|
|
3617
|
+
}
|
|
3618
|
+
else if (isHref && !quote && isSpace(ch) && content.trim()) {
|
|
3619
|
+
break;
|
|
3620
|
+
}
|
|
3621
|
+
else if (ch === ')') {
|
|
3622
|
+
if (isUrl) {
|
|
3623
|
+
if (quote && closed !== -1 || !quote && (isJs || source[i - 1] !== '\\')) {
|
|
3624
|
+
break;
|
|
3625
|
+
}
|
|
3626
|
+
j = i;
|
|
3627
|
+
}
|
|
3628
|
+
}
|
|
3629
|
+
else if (j !== -1 && (ch === '\n' ||
|
|
3630
|
+
isText && (ch === ';' || ch === '{') ||
|
|
3631
|
+
isHref && (ch === '=' || ch === '>') ||
|
|
3632
|
+
isUrl && (ch === ';' ||
|
|
3633
|
+
!isJs && (!isHtml && (ch === ':' && !isJs || ch === '}') ||
|
|
3634
|
+
isHtml && (ch === '"' || ch === "'" || ch === ':' || ch === '>'))))) {
|
|
3635
|
+
if (closed !== -1) {
|
|
3636
|
+
i = closed;
|
|
3637
|
+
}
|
|
3638
|
+
else {
|
|
3639
|
+
content = content.substring(0, i = j);
|
|
3640
|
+
}
|
|
3641
|
+
break;
|
|
3642
|
+
}
|
|
3643
|
+
if (closed === -1) {
|
|
3644
|
+
content += ch;
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3647
|
+
const setOutputURL = (value, asset) => {
|
|
3648
|
+
if (!value) {
|
|
3649
|
+
return;
|
|
3650
|
+
}
|
|
3651
|
+
if (asset) {
|
|
3652
|
+
if (!asset.inlineBase64) {
|
|
3653
|
+
if (host.Cloud?.getStorage('upload', asset.cloudStorage)) {
|
|
3654
|
+
const inlineUrlCloud = asset.inlineUrlCloud ||= (0, node_crypto_1.randomUUID)();
|
|
3655
|
+
(file.inlineUrlCloudMap ||= {})[inlineUrlCloud] = value;
|
|
3656
|
+
value = inlineUrlCloud;
|
|
3657
|
+
}
|
|
3658
|
+
else if (asset.hash && this.productionRelease) {
|
|
3659
|
+
const inlineUrl = asset.inlineUrl ||= (0, node_crypto_1.randomUUID)();
|
|
3660
|
+
(file.inlineUrlMap ||= {})[inlineUrl] = value;
|
|
3661
|
+
value = inlineUrl;
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
const font = findFont(asset.format);
|
|
3665
|
+
if (font) {
|
|
3666
|
+
found: {
|
|
3667
|
+
for (let k = i + 1; k < length; ++k) {
|
|
3668
|
+
switch (source[k]) {
|
|
3669
|
+
case ')': {
|
|
3670
|
+
const component = source.substring(i + 1, k + 1);
|
|
3671
|
+
const format = /\s+format\([^)]+\)$/i.exec(component);
|
|
3672
|
+
if (format) {
|
|
3673
|
+
trailing = component.replace(format[0], ` format("${font}")`);
|
|
3674
|
+
i = k;
|
|
3675
|
+
break found;
|
|
3676
|
+
}
|
|
3677
|
+
break;
|
|
3678
|
+
}
|
|
3679
|
+
case ',':
|
|
3680
|
+
case ';':
|
|
3681
|
+
case ':':
|
|
3682
|
+
case '}':
|
|
3683
|
+
break found;
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
}
|
|
3687
|
+
}
|
|
3688
|
+
if (asset.initialValue && !asset.initialValue.cacheable) {
|
|
3689
|
+
file.flags |= 16;
|
|
3690
|
+
}
|
|
3691
|
+
related.push(asset);
|
|
3692
|
+
}
|
|
3693
|
+
if (!quote && !isHtml && !isJs) {
|
|
3694
|
+
if (!value.includes('"')) {
|
|
3695
|
+
quote = '"';
|
|
3696
|
+
}
|
|
3697
|
+
else if (!value.includes("'")) {
|
|
3698
|
+
quote = "'";
|
|
3699
|
+
}
|
|
3700
|
+
}
|
|
3701
|
+
if (isUrl) {
|
|
3702
|
+
const index = value.indexOf('#');
|
|
3703
|
+
if (index !== -1) {
|
|
3704
|
+
value = value.substring(0, index);
|
|
3705
|
+
}
|
|
3706
|
+
}
|
|
3707
|
+
if (quote) {
|
|
3708
|
+
value = quote + value + quote;
|
|
3709
|
+
}
|
|
3710
|
+
const revised = isJs ? 'import(' + value + trailing + ')' : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
3711
|
+
source = (0, util_1.spliceString)(source, startIndex, i + 1, revised, pattern);
|
|
3712
|
+
length = source.length;
|
|
3713
|
+
modified = true;
|
|
3714
|
+
};
|
|
3715
|
+
let url;
|
|
3716
|
+
if (isJs) {
|
|
3717
|
+
if (!quote) {
|
|
3718
|
+
continue;
|
|
3719
|
+
}
|
|
3720
|
+
const target = new RegExp('^\\s*(' + quote + '((?:[^' + quote + ']|(?<=\\\\)' + quote + ')+)' + quote + ')\\s*(,.+)$').exec(content);
|
|
3721
|
+
if (target) {
|
|
3722
|
+
url = target[1].trim();
|
|
3723
|
+
trailing = target[2].trim();
|
|
3724
|
+
}
|
|
3725
|
+
else {
|
|
3726
|
+
url = (0, util_1.trimQuote)(content);
|
|
3727
|
+
}
|
|
3728
|
+
}
|
|
3729
|
+
else {
|
|
3730
|
+
url = (0, util_1.trimQuote)(content);
|
|
3731
|
+
}
|
|
3732
|
+
if (url.startsWith('data:')) {
|
|
3733
|
+
const base64 = url.split(',')[1]?.trim();
|
|
3734
|
+
if (base64) {
|
|
3735
|
+
for (const item of this.assets) {
|
|
3736
|
+
if (item.base64 === base64) {
|
|
3737
|
+
setOutputURL(getSrcUrl(this, file, item)[0], item);
|
|
3738
|
+
break;
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
else if (baseHref.length > 0) {
|
|
3744
|
+
let fullUrl, asset;
|
|
3745
|
+
for (const parentUrl of baseHref) {
|
|
3746
|
+
asset = host.findAsset(fullUrl = Document.resolvePath(url, parentUrl), { replaced: true }) || (this.related.has(file) ? host.findAsset(fullUrl, { assets: Array.from(this.related.get(file)), replaced: true }) : undefined);
|
|
3747
|
+
if (asset) {
|
|
3748
|
+
break;
|
|
3749
|
+
}
|
|
3750
|
+
}
|
|
3751
|
+
if (asset && asset !== importFile) {
|
|
3752
|
+
if (!(0, util_1.hasValue)(asset.format, 'base64')) {
|
|
3753
|
+
if (asset.bundleReplace) {
|
|
3754
|
+
let k = 0, valid = true;
|
|
3755
|
+
if (!isText) {
|
|
3756
|
+
let j = startIndex;
|
|
3757
|
+
while (isSpace(source[--j])) { }
|
|
3758
|
+
valid = source.substring(k = j - 6, j + 1) === '@import';
|
|
3759
|
+
}
|
|
3760
|
+
else {
|
|
3761
|
+
k = startIndex;
|
|
3762
|
+
}
|
|
3763
|
+
if (valid) {
|
|
3764
|
+
let l = i, revised = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
3765
|
+
for (let ch; l < length; ++l) {
|
|
3766
|
+
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
3767
|
+
break;
|
|
3768
|
+
}
|
|
3769
|
+
}
|
|
3770
|
+
const layer = this.replaceContent(revised, source.substring(k, l + 1), "text/css");
|
|
3771
|
+
if (layer) {
|
|
3772
|
+
revised = layer;
|
|
3773
|
+
}
|
|
3774
|
+
revised = this.processUrl(host, file, this.removeServerRoot(revised), type, asset) || revised;
|
|
3775
|
+
source = (0, util_1.spliceString)(source, k, l + 1, revised, pattern);
|
|
3776
|
+
length = source.length;
|
|
3777
|
+
if (!file.watch) {
|
|
3778
|
+
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
3779
|
+
asset.invalid = true;
|
|
3780
|
+
}
|
|
3781
|
+
else {
|
|
3782
|
+
related.push(asset);
|
|
3783
|
+
if (!(0, types_1.existsFlag)(asset.flags)) {
|
|
3784
|
+
asset.flags |= 8;
|
|
3785
|
+
}
|
|
3786
|
+
}
|
|
3787
|
+
modified = true;
|
|
3788
|
+
continue;
|
|
3789
|
+
}
|
|
3790
|
+
}
|
|
3791
|
+
if (hasSameOrigin(asset.url || fullUrl, ...baseHref)) {
|
|
3792
|
+
let sameDir = false;
|
|
3793
|
+
[fullUrl, sameDir] = getSrcUrl(this, file, asset);
|
|
3794
|
+
if (sameDir && isJs) {
|
|
3795
|
+
fullUrl = './' + fullUrl;
|
|
3796
|
+
}
|
|
3797
|
+
}
|
|
3798
|
+
else {
|
|
3799
|
+
const pathname = file.pathname;
|
|
3800
|
+
const count = pathname && pathname !== '/' ? pathname.split('/').length : 0;
|
|
3801
|
+
fullUrl = (count ? '../'.repeat(count) : '') + asset.relativeUrl;
|
|
3802
|
+
}
|
|
3803
|
+
}
|
|
3804
|
+
else if (!asset.invalid) {
|
|
3805
|
+
fullUrl = asset.inlineBase64 ||= (0, node_crypto_1.randomUUID)();
|
|
3806
|
+
}
|
|
3807
|
+
if (url !== fullUrl) {
|
|
3808
|
+
setOutputURL(fullUrl, asset);
|
|
3809
|
+
}
|
|
3810
|
+
}
|
|
3811
|
+
else if (importFile && url !== fullUrl) {
|
|
3812
|
+
setOutputURL(fullUrl);
|
|
3813
|
+
}
|
|
3814
|
+
}
|
|
3815
|
+
}
|
|
3816
|
+
if (modified) {
|
|
3817
|
+
if (related.length > 0) {
|
|
3818
|
+
const previous = this.related.get(file);
|
|
3819
|
+
if (previous) {
|
|
3820
|
+
for (const item of related) {
|
|
3821
|
+
previous.add(item);
|
|
3822
|
+
}
|
|
3823
|
+
}
|
|
3824
|
+
else {
|
|
3825
|
+
this.related.set(file, new Set(related));
|
|
3826
|
+
}
|
|
3827
|
+
}
|
|
3828
|
+
return source;
|
|
3829
|
+
}
|
|
3830
|
+
}
|
|
3831
|
+
processLocation(target, nameExt) {
|
|
3832
|
+
const modified = [];
|
|
3833
|
+
const checkAttribute = (attr) => {
|
|
3834
|
+
const value = target[attr];
|
|
3835
|
+
if (value) {
|
|
3836
|
+
const index = value.indexOf(ChromeDocument.INTERNAL_ASSIGNUUID);
|
|
3837
|
+
if (index !== -1) {
|
|
3838
|
+
target[attr] = (0, util_1.spliceString)(value, index, index + ChromeDocument.INTERNAL_ASSIGNUUID.length, this.formatLocation(attr, nameExt));
|
|
3839
|
+
modified.push(attr);
|
|
3840
|
+
return true;
|
|
3841
|
+
}
|
|
3842
|
+
}
|
|
3843
|
+
return false;
|
|
3844
|
+
};
|
|
3845
|
+
checkAttribute('filename');
|
|
3846
|
+
checkAttribute('pathname');
|
|
3847
|
+
return modified;
|
|
3848
|
+
}
|
|
3849
|
+
formatLocation(attr, nameExt) {
|
|
3850
|
+
const format = this.formatMap || this.module.format;
|
|
3851
|
+
if ((0, types_1.isObject)(format)) {
|
|
3852
|
+
const pattern = nameExt && nameExt in format ? format[nameExt] : format.uuid;
|
|
3853
|
+
if ((0, types_1.isObject)(pattern) && (0, types_1.isString)(pattern[attr])) {
|
|
3854
|
+
return (0, types_1.randomString)(pattern[attr], pattern.dictionary);
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3857
|
+
return (0, node_crypto_1.randomUUID)();
|
|
3858
|
+
}
|
|
3859
|
+
createTransformOptions(host, file, mimeType, source = {}) {
|
|
3860
|
+
if (typeof source === 'string') {
|
|
3861
|
+
source = { code: source };
|
|
3862
|
+
}
|
|
3863
|
+
const metadata = { userAgentData: this.userAgentData };
|
|
3864
|
+
switch (mimeType) {
|
|
3865
|
+
case "text/html":
|
|
3866
|
+
metadata.__fromhtml__ = true;
|
|
3867
|
+
case "text/css":
|
|
3868
|
+
Object.assign(metadata, this.config);
|
|
3869
|
+
default:
|
|
3870
|
+
if ((0, types_1.isObject)(file.metadata)) {
|
|
3871
|
+
Object.assign(metadata, file.metadata);
|
|
3872
|
+
}
|
|
3873
|
+
break;
|
|
3874
|
+
}
|
|
3875
|
+
const { uri, localUri } = file;
|
|
3876
|
+
const [pathname, filename] = localUri ? [path.dirname(localUri), path.basename(localUri)] : ['', file.filename];
|
|
3877
|
+
const options = { pathname, filename, mimeType, metadata, imported: !!file.imports && file.imported !== false };
|
|
3878
|
+
const sourceFile = source.sourceFile || !file.exported && uri && this.findSourceRoot(uri);
|
|
3879
|
+
if (sourceFile) {
|
|
3880
|
+
if (Document.isPath(sourceFile)) {
|
|
3881
|
+
options.sourceFile = sourceFile;
|
|
3882
|
+
}
|
|
3883
|
+
options.sourceName = path.basename(sourceFile);
|
|
3884
|
+
options.sourcesRelativeTo = path.dirname(sourceFile);
|
|
3885
|
+
options.getMainFile = this.resolveSourceFile(file);
|
|
3886
|
+
if (source.code) {
|
|
3887
|
+
options.getSourceFiles = this.locateSourceFiles(file, source.code, source.contentFiles || (localUri ? host.contentToAppend.get(localUri) : undefined));
|
|
3888
|
+
}
|
|
3889
|
+
}
|
|
3890
|
+
if ((!this.productionRelease || this.productionIncremental) && !(0, types_1.modifiedFlag)(file.flags)) {
|
|
3891
|
+
options.cacheData = { uri: !file.exported ? uri : undefined, etag: !file.modified ? file.etag : undefined, encoding: file.encoding };
|
|
3892
|
+
}
|
|
3893
|
+
return options;
|
|
3894
|
+
}
|
|
3895
|
+
addSessionData(item, key, data, { timeout = 0, template = false } = {}) {
|
|
3896
|
+
if ((0, types_1.isObject)(data) || template && data != null) {
|
|
3897
|
+
if (timeout === 0) {
|
|
3898
|
+
const cache = this.settingsOf(item.source, template && item.source !== 'local' ? 'local_file' : 'cache');
|
|
3899
|
+
if (cache) {
|
|
3900
|
+
timeout = core_1.ClientDb.getTimeout(cache);
|
|
3901
|
+
}
|
|
3902
|
+
}
|
|
3903
|
+
if (timeout > 0) {
|
|
3904
|
+
addCacheItem(template ? CACHE_LOCALFILE : CACHE_DBRESULT, key, data, timeout);
|
|
3905
|
+
}
|
|
3906
|
+
else {
|
|
3907
|
+
this._sessionData[key] = data;
|
|
3908
|
+
}
|
|
3909
|
+
}
|
|
3910
|
+
}
|
|
3857
3911
|
get elements() {
|
|
3858
3912
|
if (this._elements) {
|
|
3859
3913
|
return this._elements;
|
|
@@ -3900,6 +3954,9 @@ class ChromeDocument extends Document {
|
|
|
3900
3954
|
}
|
|
3901
3955
|
return [];
|
|
3902
3956
|
}
|
|
3957
|
+
get sessionKey() {
|
|
3958
|
+
return this._sessionKey ||= (0, node_crypto_1.randomUUID)();
|
|
3959
|
+
}
|
|
3903
3960
|
get settings() {
|
|
3904
3961
|
return this.module.settings ||= {};
|
|
3905
3962
|
}
|