@pi-r/chrome 0.8.2 → 0.9.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/LICENSE +7 -7
- package/README.md +7 -7
- package/index.d.ts +6 -6
- package/index.js +57 -55
- package/package.json +6 -7
- package/types/index.d.ts +131 -131
- package/types/squared.d.ts +136 -147
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
### @pi-r/chrome
|
|
2
|
-
|
|
3
|
-
https://e-mc.readthedocs.io/en/latest/document
|
|
4
|
-
|
|
5
|
-
### LICENSE
|
|
6
|
-
|
|
7
|
-
MIT
|
|
1
|
+
### @pi-r/chrome
|
|
2
|
+
|
|
3
|
+
https://e-mc.readthedocs.io/en/latest/document
|
|
4
|
+
|
|
5
|
+
### LICENSE
|
|
6
|
+
|
|
7
|
+
MIT
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { IFileManager } from '@e-mc/types/lib';
|
|
2
|
-
|
|
3
|
-
import type { ChromeDocumentConstructor, DocumentAsset } from './types';
|
|
4
|
-
|
|
5
|
-
declare const Chrome: ChromeDocumentConstructor<IFileManager<DocumentAsset>>;
|
|
6
|
-
|
|
1
|
+
import type { IFileManager } from '@e-mc/types/lib';
|
|
2
|
+
|
|
3
|
+
import type { ChromeDocumentConstructor, DocumentAsset } from './types';
|
|
4
|
+
|
|
5
|
+
declare const Chrome: ChromeDocumentConstructor<IFileManager<DocumentAsset>>;
|
|
6
|
+
|
|
7
7
|
export = Chrome;
|
package/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const
|
|
5
|
-
const core_1 = require("@e-mc/core");
|
|
2
|
+
const path = require("node:path");
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
5
|
const Cloud = require("@e-mc/cloud");
|
|
6
|
+
const core_1 = require("@e-mc/core");
|
|
7
|
+
const dom_1 = require("@e-mc/document/parse/dom");
|
|
7
8
|
const types_1 = require("@e-mc/types");
|
|
8
9
|
const asset_1 = require("@e-mc/document/asset");
|
|
9
10
|
const util_1 = require("@e-mc/document/util");
|
|
10
|
-
const dom_1 = require("@e-mc/document/parse/dom");
|
|
11
11
|
const transform_1 = require("@e-mc/document/transform");
|
|
12
12
|
const Document = require('@e-mc/document');
|
|
13
13
|
const CACHE_DBRESULT = new Map();
|
|
@@ -78,7 +78,7 @@ function removeNamespace(name, source, newline, comments) {
|
|
|
78
78
|
}
|
|
79
79
|
function getObjectValue(value, key) {
|
|
80
80
|
REGEXP_OBJECT_NAME.lastIndex = 0;
|
|
81
|
-
let found, match;
|
|
81
|
+
let found = false, match;
|
|
82
82
|
while (match = REGEXP_OBJECT_NAME.exec(key)) {
|
|
83
83
|
if ((0, types_1.isObject)(value)) {
|
|
84
84
|
value = value[match[1]];
|
|
@@ -185,8 +185,9 @@ function spliceSource(source, startIndex, endIndex, pattern, leading = '', trail
|
|
|
185
185
|
return (0, util_1.spliceString)(source, startIndex, endIndex, content, pattern);
|
|
186
186
|
}
|
|
187
187
|
function parseArg(data, value) {
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
const n = +value;
|
|
189
|
+
if (!isNaN(n)) {
|
|
190
|
+
return n;
|
|
190
191
|
}
|
|
191
192
|
const match = /^(["'])(.*)\1$/s.exec(value);
|
|
192
193
|
if (match) {
|
|
@@ -368,10 +369,10 @@ function createHash(host, file, hash, bufferMap) {
|
|
|
368
369
|
function getSrcURL(instance, parent, file) {
|
|
369
370
|
const relativeUrl = file.relativeUrl || instance.host.removeCwd(file.localUri) && getRelativeURL(file);
|
|
370
371
|
if (!relativeUrl) {
|
|
371
|
-
return [''];
|
|
372
|
+
return ['', false];
|
|
372
373
|
}
|
|
373
374
|
if (parent.inlineContent) {
|
|
374
|
-
return [relativeUrl];
|
|
375
|
+
return [relativeUrl, false];
|
|
375
376
|
}
|
|
376
377
|
let parentDir = parent.pathname, assetDir = file.pathname;
|
|
377
378
|
if (!instance.productionRelease) {
|
|
@@ -385,15 +386,15 @@ function getSrcURL(instance, parent, file) {
|
|
|
385
386
|
if (parentDir === assetDir) {
|
|
386
387
|
return [file.filename, true];
|
|
387
388
|
}
|
|
388
|
-
const prefix =
|
|
389
|
-
const suffix =
|
|
390
|
-
let found;
|
|
389
|
+
const prefix = parentDir.split('/');
|
|
390
|
+
const suffix = assetDir.split('/');
|
|
391
|
+
let found = false;
|
|
391
392
|
while (prefix.length > 0 && suffix.length > 0 && prefix[0] === suffix[0]) {
|
|
392
393
|
prefix.shift();
|
|
393
394
|
suffix.shift();
|
|
394
395
|
found = true;
|
|
395
396
|
}
|
|
396
|
-
return [found ? Document.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, false];
|
|
397
398
|
}
|
|
398
399
|
function transformURL(instance, host, parent, type, source, importFile) {
|
|
399
400
|
const related = [];
|
|
@@ -403,7 +404,7 @@ function transformURL(instance, host, parent, type, source, importFile) {
|
|
|
403
404
|
const pattern = isJs ? REGEXP_URL_JS : type === 'svg' ? REGEXP_URL_SVG : REGEXP_URL;
|
|
404
405
|
pattern.lastIndex = 0;
|
|
405
406
|
REGEXP_IMAGESET.lastIndex = 0;
|
|
406
|
-
let length = source.length, modified, match;
|
|
407
|
+
let length = source.length, modified = false, match;
|
|
407
408
|
while (match = REGEXP_IMAGESET.exec(source)) {
|
|
408
409
|
const startIndex = match.index + match[0].length;
|
|
409
410
|
const endIndex = findClosingIndex(source, startIndex, '(');
|
|
@@ -488,12 +489,12 @@ function transformURL(instance, host, parent, type, source, importFile) {
|
|
|
488
489
|
if (asset) {
|
|
489
490
|
if (!asset.inlineBase64) {
|
|
490
491
|
if (host.Cloud?.getStorage('upload', asset.cloudStorage)) {
|
|
491
|
-
const inlineUrlCloud = asset.inlineUrlCloud ||= (0,
|
|
492
|
+
const inlineUrlCloud = asset.inlineUrlCloud ||= (0, node_crypto_1.randomUUID)();
|
|
492
493
|
(parent.inlineUrlCloudMap ||= {})[inlineUrlCloud] = value;
|
|
493
494
|
value = inlineUrlCloud;
|
|
494
495
|
}
|
|
495
496
|
else if (asset.hash && instance.productionRelease) {
|
|
496
|
-
const inlineUrl = asset.inlineUrl ||= (0,
|
|
497
|
+
const inlineUrl = asset.inlineUrl ||= (0, node_crypto_1.randomUUID)();
|
|
497
498
|
(parent.inlineUrlMap ||= {})[inlineUrl] = value;
|
|
498
499
|
value = inlineUrl;
|
|
499
500
|
}
|
|
@@ -626,7 +627,7 @@ function transformURL(instance, host, parent, type, source, importFile) {
|
|
|
626
627
|
}
|
|
627
628
|
}
|
|
628
629
|
if (hasSameOrigin(asset.url || fullUrl, ...baseHref)) {
|
|
629
|
-
let sameDir;
|
|
630
|
+
let sameDir = false;
|
|
630
631
|
[fullUrl, sameDir] = getSrcURL(instance, parent, asset);
|
|
631
632
|
if (sameDir && isJs) {
|
|
632
633
|
fullUrl = './' + fullUrl;
|
|
@@ -634,12 +635,12 @@ function transformURL(instance, host, parent, type, source, importFile) {
|
|
|
634
635
|
}
|
|
635
636
|
else {
|
|
636
637
|
const pathname = parent.pathname;
|
|
637
|
-
const count = pathname && pathname !== '/'
|
|
638
|
+
const count = pathname && pathname !== '/' ? pathname.split('/').length : 0;
|
|
638
639
|
fullUrl = (count ? '../'.repeat(count) : '') + asset.relativeUrl;
|
|
639
640
|
}
|
|
640
641
|
}
|
|
641
642
|
else if (!asset.invalid) {
|
|
642
|
-
fullUrl = asset.inlineBase64 ||= (0,
|
|
643
|
+
fullUrl = asset.inlineBase64 ||= (0, node_crypto_1.randomUUID)();
|
|
643
644
|
}
|
|
644
645
|
if (url !== fullUrl) {
|
|
645
646
|
setOutputURL(fullUrl, asset);
|
|
@@ -668,12 +669,12 @@ function transformURL(instance, host, parent, type, source, importFile) {
|
|
|
668
669
|
function getFormatUUID(instance, attr, ext) {
|
|
669
670
|
const format = 'formatMap' in instance ? instance.formatMap : instance.module.format;
|
|
670
671
|
let pattern;
|
|
671
|
-
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,
|
|
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, node_crypto_1.randomUUID)();
|
|
672
673
|
}
|
|
673
674
|
function setLocationUUID(instance, data, file, ext) {
|
|
674
675
|
const { pathname, filename } = data;
|
|
675
676
|
const assignUUID = ChromeDocument.INTERNAL_ASSIGNUUID;
|
|
676
|
-
let index = 0, modified;
|
|
677
|
+
let index = 0, modified = false;
|
|
677
678
|
if (filename) {
|
|
678
679
|
ext ||= path.extname(filename).substring(1);
|
|
679
680
|
if ((index = filename.indexOf(assignUUID)) !== -1) {
|
|
@@ -817,7 +818,7 @@ function replaceHtml(instance, source, { productionRelease, contentMap }, cssMap
|
|
|
817
818
|
}
|
|
818
819
|
function finalizeHtml(value, data) {
|
|
819
820
|
for (const id in data) {
|
|
820
|
-
value = value.replace(new RegExp(
|
|
821
|
+
value = value.replace(new RegExp(escapePattern(id), 'g'), data[id]);
|
|
821
822
|
}
|
|
822
823
|
return value;
|
|
823
824
|
}
|
|
@@ -906,12 +907,14 @@ function errorCredential(instance, domBase, item, err) {
|
|
|
906
907
|
instance.writeFail(["Invalid credentials", item.source], err);
|
|
907
908
|
}
|
|
908
909
|
}
|
|
910
|
+
function escapePattern(value) {
|
|
911
|
+
return value.replace(/[-|\\{}()[\]^$+*?.]/g, capture => capture === '-' ? '\\x2d' : '\\' + capture);
|
|
912
|
+
}
|
|
909
913
|
const isSpace = dom_1.DomWriter.isSpace.bind(dom_1.DomWriter);
|
|
910
914
|
const replaceMatch = dom_1.DomWriter.replaceMatch.bind(dom_1.DomWriter);
|
|
911
915
|
const getNewlineString = dom_1.DomWriter.getNewlineString.bind(dom_1.DomWriter);
|
|
912
916
|
const getBuffer = (item, localUri) => item.sourceUTF8 || item.buffer || ((localUri ||= item.localUri) && Document.isPath(localUri) ? fs.readFileSync(localUri, item.encoding) : null);
|
|
913
917
|
const hasSourceMap = (metadata, value) => (0, types_1.isObject)(metadata) && metadata.__sourcemap__ === value;
|
|
914
|
-
const splitPath = (value) => value.split(/[\\/]/).filter(segment => segment.trim());
|
|
915
918
|
const isBundled = (value, main) => typeof value === 'number' && (value > 0 || main && value === 0);
|
|
916
919
|
const isFont = (value) => value === 'truetype' || value === 'opentype' || value === 'woff' || value === 'woff2';
|
|
917
920
|
const isImage = (value) => typeof value === 'string' && value.startsWith('image/') && value !== "image/svg+xml";
|
|
@@ -1131,8 +1134,8 @@ class ChromeDocument extends Document {
|
|
|
1131
1134
|
const serverRootMapping = instance.serverRootMapping;
|
|
1132
1135
|
const mapped = [];
|
|
1133
1136
|
for (const localDir in serverRootMapping) {
|
|
1134
|
-
const subDir = serverRootMapping[localDir];
|
|
1135
|
-
const destDir = validateDir(Document.normalizePath(
|
|
1137
|
+
const subDir = path.normalize(serverRootMapping[localDir]);
|
|
1138
|
+
const destDir = validateDir(Document.normalizePath(subDir.endsWith(path.sep) ? path.join(outputDir, subDir, localDir) : path.join(outputDir, subDir), true));
|
|
1136
1139
|
if (destDir.startsWith(outputDir)) {
|
|
1137
1140
|
if (this.canWrite(destDir)) {
|
|
1138
1141
|
mapped.push([Document.normalizePath(localDir, true), destDir, 0]);
|
|
@@ -1764,7 +1767,7 @@ class ChromeDocument extends Document {
|
|
|
1764
1767
|
if (!Array.isArray(file.imports)) {
|
|
1765
1768
|
return;
|
|
1766
1769
|
}
|
|
1767
|
-
let bundleMain, modified;
|
|
1770
|
+
let bundleMain, modified = false;
|
|
1768
1771
|
if ((0, types_1.isPlainObject)(baseFile)) {
|
|
1769
1772
|
bundleMain = baseFile;
|
|
1770
1773
|
}
|
|
@@ -1848,7 +1851,7 @@ class ChromeDocument extends Document {
|
|
|
1848
1851
|
}
|
|
1849
1852
|
}
|
|
1850
1853
|
removeServerRoot(value) {
|
|
1851
|
-
return value.replace(new RegExp('(\\.\\./)*' +
|
|
1854
|
+
return value.replace(new RegExp('(\\.\\./)*' + escapePattern(ChromeDocument.INTERNAL_SERVERROOT), 'g'), '');
|
|
1852
1855
|
}
|
|
1853
1856
|
addCopy(data, saveAs) {
|
|
1854
1857
|
if (data.command && this.host) {
|
|
@@ -1877,7 +1880,7 @@ class ChromeDocument extends Document {
|
|
|
1877
1880
|
if (this.htmlFile) {
|
|
1878
1881
|
const endpoint = instance.getStorage('upload', this.htmlFile.cloudStorage)?.upload?.endpoint;
|
|
1879
1882
|
if (endpoint) {
|
|
1880
|
-
this._cloudEndpoint = new RegExp(
|
|
1883
|
+
this._cloudEndpoint = new RegExp(escapePattern(Document.toPosix(endpoint)) + '/', 'g');
|
|
1881
1884
|
}
|
|
1882
1885
|
}
|
|
1883
1886
|
}
|
|
@@ -1894,7 +1897,7 @@ class ChromeDocument extends Document {
|
|
|
1894
1897
|
const cloudUrl = endpoint ? url.replace(endpoint, '') : url;
|
|
1895
1898
|
file.cloudUrl = cloudUrl;
|
|
1896
1899
|
if (inlineUrlCloud) {
|
|
1897
|
-
const pattern = new RegExp(
|
|
1900
|
+
const pattern = new RegExp(escapePattern(inlineUrlCloud), 'g');
|
|
1898
1901
|
for (const item of this.editing) {
|
|
1899
1902
|
if (item.inlineUrlCloudMap?.[inlineUrlCloud]) {
|
|
1900
1903
|
const source = host.getUTF8String(item);
|
|
@@ -1924,7 +1927,7 @@ class ChromeDocument extends Document {
|
|
|
1924
1927
|
for (const id in this._cloudUrlMap) {
|
|
1925
1928
|
const inlineUrlCloud = item.inlineUrlCloudMap[id];
|
|
1926
1929
|
if (inlineUrlCloud && !this._cloudUploaded.has(id)) {
|
|
1927
|
-
output = (output || source).replace(new RegExp(
|
|
1930
|
+
output = (output || source).replace(new RegExp(escapePattern(id), 'g'), inlineUrlCloud);
|
|
1928
1931
|
state.localStorage.delete(this._cloudUrlMap[id]);
|
|
1929
1932
|
}
|
|
1930
1933
|
}
|
|
@@ -1999,8 +2002,8 @@ class ChromeDocument extends Document {
|
|
|
1999
2002
|
if (main?.editing && main.mimeType === "text/html") {
|
|
2000
2003
|
const inlineUrlCloudMap = main.inlineUrlCloudMap || {};
|
|
2001
2004
|
const using = [];
|
|
2002
|
-
let found;
|
|
2003
|
-
for (let i = 0, length = assets.length, current
|
|
2005
|
+
let found = false;
|
|
2006
|
+
for (let i = 0, length = assets.length, current; i < length; ++i) {
|
|
2004
2007
|
const asset = assets[i];
|
|
2005
2008
|
if (asset.element && isUnedited(asset)) {
|
|
2006
2009
|
continue;
|
|
@@ -2012,7 +2015,7 @@ class ChromeDocument extends Document {
|
|
|
2012
2015
|
else if (isWatched(this, asset) ||
|
|
2013
2016
|
(0, types_1.watchFlag)(asset.flags) ||
|
|
2014
2017
|
asset.base64 && watch.related.find(item => (0, asset_1.isEqual)(item, asset)) ||
|
|
2015
|
-
(0, types_1.isArray)(asset.cloudStorage) && asset.cloudStorage.some(item =>
|
|
2018
|
+
(0, types_1.isArray)(asset.cloudStorage) && asset.cloudStorage.some(item => item.upload?.active)) {
|
|
2016
2019
|
using.push(asset);
|
|
2017
2020
|
}
|
|
2018
2021
|
else if (current = watch.assets.find(item => (0, asset_1.isEqual)(item, asset))) {
|
|
@@ -2105,8 +2108,8 @@ class ChromeDocument extends Document {
|
|
|
2105
2108
|
let current = srcset, match;
|
|
2106
2109
|
for (const url of items) {
|
|
2107
2110
|
const resolve = sameOrigin && !Document.isURL(url);
|
|
2108
|
-
const pathname = url.split(/
|
|
2109
|
-
const pattern = new RegExp(`(,?\\s*)(${(resolve && !url.startsWith('.') ? `(
|
|
2111
|
+
const pathname = url.split('/').map(seg => escapePattern(seg)).join('/');
|
|
2112
|
+
const pattern = new RegExp(`(,?\\s*)(${(resolve && !url.startsWith('.') ? `(?:\\.\\./)*\\.\\.${pathname}|` : '') + pathname})(` + (!url.includes('?') ? '(?:(?!,)(?:[^?]|$)[^,]*)|(?!\\?)[^,]*)' : '[^,]*)'), 'g');
|
|
2110
2113
|
while (match = pattern.exec(current)) {
|
|
2111
2114
|
const partial = match[2];
|
|
2112
2115
|
if (!resolve || baseHref.some(baseUri => uri === Document.resolvePath(partial, baseUri))) {
|
|
@@ -2147,7 +2150,7 @@ class ChromeDocument extends Document {
|
|
|
2147
2150
|
readBase64(item, item.inlineBase64);
|
|
2148
2151
|
}
|
|
2149
2152
|
else if (!item.invalid && (0, util_1.hasValue)(item.format, 'base64')) {
|
|
2150
|
-
const uuid = (0,
|
|
2153
|
+
const uuid = (0, node_crypto_1.randomUUID)();
|
|
2151
2154
|
if (readBase64(item, uuid)) {
|
|
2152
2155
|
item.inlineBase64 = uuid;
|
|
2153
2156
|
}
|
|
@@ -2353,7 +2356,7 @@ class ChromeDocument extends Document {
|
|
|
2353
2356
|
source = removeNamespace(moduleName, domBase.modified ? domBase.close() : source, domBase.newline, domBase.getComments());
|
|
2354
2357
|
if (this.sanitizeFramework) {
|
|
2355
2358
|
for (const name of this.sanitizeFramework) {
|
|
2356
|
-
source = source.replace(name === '*' ? REGEXP_SANITIZEALL : new RegExp(`(?:\\s+|\\b)data-(?:${
|
|
2359
|
+
source = source.replace(name === '*' ? REGEXP_SANITIZEALL : new RegExp(`(?:\\s+|\\b)data-(?:${escapePattern(name)}-[^=\\s]+|.+?-${escapePattern(name)})\\s*${dom_1.DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g'), '');
|
|
2357
2360
|
}
|
|
2358
2361
|
}
|
|
2359
2362
|
if (!htmlFile.preserve) {
|
|
@@ -2445,7 +2448,7 @@ class ChromeDocument extends Document {
|
|
|
2445
2448
|
}
|
|
2446
2449
|
if (uri && !(0, util_1.hasValue)(item.format, 'crossorigin') && item !== this.htmlFile) {
|
|
2447
2450
|
if (host.Cloud?.getStorage('upload', item.cloudStorage)) {
|
|
2448
|
-
const inlineUrlCloud = item.inlineUrlCloud ||= (0,
|
|
2451
|
+
const inlineUrlCloud = item.inlineUrlCloud ||= (0, node_crypto_1.randomUUID)();
|
|
2449
2452
|
(this.htmlFile.inlineUrlCloudMap ||= {})[inlineUrlCloud] = productionRelease ? this.removeServerRoot(uri) : uri;
|
|
2450
2453
|
uri = inlineUrlCloud;
|
|
2451
2454
|
}
|
|
@@ -2535,7 +2538,7 @@ class ChromeDocument extends Document {
|
|
|
2535
2538
|
if (this.dataSource.length === 0) {
|
|
2536
2539
|
return;
|
|
2537
2540
|
}
|
|
2538
|
-
const sessionKey = (0,
|
|
2541
|
+
const sessionKey = (0, node_crypto_1.randomUUID)();
|
|
2539
2542
|
const cacheData = Object.create(null);
|
|
2540
2543
|
const dataItems = [];
|
|
2541
2544
|
const displayItems = [];
|
|
@@ -2848,14 +2851,14 @@ class ChromeDocument extends Document {
|
|
|
2848
2851
|
}
|
|
2849
2852
|
}
|
|
2850
2853
|
if (!getData) {
|
|
2851
|
-
const { settings, encoding
|
|
2854
|
+
const { settings, encoding } = current;
|
|
2852
2855
|
target ||= settings && this.settings.export?.[settings] || pathname;
|
|
2853
2856
|
if (typeof target === 'function') {
|
|
2854
2857
|
getData = target;
|
|
2855
2858
|
hint = target.name;
|
|
2856
2859
|
}
|
|
2857
2860
|
else if ((0, types_1.isString)(target)) {
|
|
2858
|
-
getData = this.asSourceFile(target, { encoding
|
|
2861
|
+
getData = this.asSourceFile(target, { encoding });
|
|
2859
2862
|
hint = target;
|
|
2860
2863
|
}
|
|
2861
2864
|
}
|
|
@@ -3183,7 +3186,7 @@ class ChromeDocument extends Document {
|
|
|
3183
3186
|
if ((0, types_1.isPlainObject)(map)) {
|
|
3184
3187
|
for (const attr in map) {
|
|
3185
3188
|
value = '';
|
|
3186
|
-
let segment = map[attr], valid;
|
|
3189
|
+
let segment = map[attr], valid = false;
|
|
3187
3190
|
if (item.viewEngine) {
|
|
3188
3191
|
if (!(0, types_1.isString)(segment)) {
|
|
3189
3192
|
errors = true;
|
|
@@ -3470,11 +3473,11 @@ class ChromeDocument extends Document {
|
|
|
3470
3473
|
const selectorMap = useSessionCache ? CACHE_SELECTOR : this._selectorMap;
|
|
3471
3474
|
const [stringSome, stringMany] = useUnsafeCssReplace ? ['\\s*', '\\s+'] : [PATTERN_STRING_SOME, PATTERN_STRING_MANY];
|
|
3472
3475
|
const replaceMap = [];
|
|
3473
|
-
let current = source, modified, checkEmpty, match;
|
|
3476
|
+
let current = source, modified = false, checkEmpty, match;
|
|
3474
3477
|
const parseSelector = (value) => {
|
|
3475
3478
|
const items = [];
|
|
3476
3479
|
const revised = value.replace(useUnsafeCssReplace ? REGEXP_NTHCHILD_UNSAFE : REGEXP_NTHCHILD, (...capture) => {
|
|
3477
|
-
return '`%' + (items.push('\\(' + stringSome + (capture[1] === '-' ? '\\x2d' : '\\x2b?') + (capture[2] || '[01]?') + (capture[3] === '0' ? !capture[1] && !capture[2] && !capture[4] && !capture[5] ? '[+-]?0[nN]?' : '0' : '[nN]') + stringSome + (capture[5] ? (capture[4] === '-' ? '\\x2d' : '\\x2b') + stringSome + capture[5] : `(?:[+-]${stringSome}0)?`) + (capture[6] ? stringMany + '[oO][fF]' + stringMany + capture[6].trim() : '') + stringSome + '\\)') - 1) + '`';
|
|
3480
|
+
return '`%' + (items.push('\\(' + stringSome + (capture[1] === '-' ? '\\x2d' : '\\x2b?') + (capture[2] || '[01]?') + (capture[3] === '0' ? !capture[1] && !capture[2] && !capture[4] && !capture[5] ? '[+-]?0[nN]?' : '0' : '[nN]?') + stringSome + (capture[5] ? (capture[4] === '-' ? '\\x2d' : '\\x2b?') + stringSome + capture[5] : `(?:[+-]${stringSome}0)?`) + (capture[6] ? stringMany + '[oO][fF]' + stringMany + capture[6].trim() : '') + stringSome + '\\)') - 1) + '`';
|
|
3478
3481
|
});
|
|
3479
3482
|
let selector = '';
|
|
3480
3483
|
for (let i = 0, length = revised.length, casing = false, attr = false, quote = false; i < length; i++) {
|
|
@@ -3549,7 +3552,7 @@ class ChromeDocument extends Document {
|
|
|
3549
3552
|
}
|
|
3550
3553
|
selector += (space & 1 ? '`%%`' : '') + (!casing && ch >= 'a' && ch <= 'z' ? '`' + ch + ch.toUpperCase() + '`' : ch) + (space & 2 ? '`%%`' : '');
|
|
3551
3554
|
}
|
|
3552
|
-
selector =
|
|
3555
|
+
selector = escapePattern(selector)
|
|
3553
3556
|
.replace(/\s*(>|~(?!=)|\\\+|\\\*(?!=)])\s*/g, (...capture) => stringSome + capture[1] + stringSome)
|
|
3554
3557
|
.replace(/`([a-z][A-Z]|%{2,4})`/g, (...capture) => {
|
|
3555
3558
|
switch (capture[1]) {
|
|
@@ -3575,7 +3578,7 @@ class ChromeDocument extends Document {
|
|
|
3575
3578
|
const key = name + '_' + value + (increment === 2 && (valueTo = items[i + 1].trim()) ? '_' + valueTo : '') + (useUnsafeCssReplace ? '_1' : '');
|
|
3576
3579
|
let pattern = queryMap.get(key), rule;
|
|
3577
3580
|
if (!pattern) {
|
|
3578
|
-
let flags = 'gi', selector = '', revised;
|
|
3581
|
+
let flags = 'gi', selector = '', revised = false;
|
|
3579
3582
|
if (name === 'container') {
|
|
3580
3583
|
for (let j = 0, length = value.length, casing = true; j < length; j++) {
|
|
3581
3584
|
let ch = value[j];
|
|
@@ -3615,7 +3618,7 @@ class ChromeDocument extends Document {
|
|
|
3615
3618
|
}
|
|
3616
3619
|
}
|
|
3617
3620
|
if (!revised) {
|
|
3618
|
-
selector =
|
|
3621
|
+
selector = escapePattern(selector || value)
|
|
3619
3622
|
.replace(/\s*(\\[()])\s*/g, (...capture) => stringSome + capture[1] + stringSome)
|
|
3620
3623
|
.replace(/:\s+/g, stringSome + ':' + stringSome)
|
|
3621
3624
|
.replace(/\s+([<>/]|<=|>=|\\\*)\s+/g, (...capture) => stringSome + capture[1] + stringSome)
|
|
@@ -3632,7 +3635,7 @@ class ChromeDocument extends Document {
|
|
|
3632
3635
|
}
|
|
3633
3636
|
while (rule = pattern.exec(current)) {
|
|
3634
3637
|
if (!nesting) {
|
|
3635
|
-
const block = Array.from(current.substring(0, rule.index).matchAll(/{
|
|
3638
|
+
const block = Array.from(current.substring(0, rule.index).matchAll(/[{}]/g));
|
|
3636
3639
|
if (block.filter(open => open[0] === '{').length !== block.filter(close => close[0] === '}').length) {
|
|
3637
3640
|
continue;
|
|
3638
3641
|
}
|
|
@@ -3652,7 +3655,7 @@ class ChromeDocument extends Document {
|
|
|
3652
3655
|
while (bracket = pattern.exec(current)) {
|
|
3653
3656
|
const segment = bracket[0];
|
|
3654
3657
|
if (/[{}]/.test(segment)) {
|
|
3655
|
-
const placeholder = '`' + (0,
|
|
3658
|
+
const placeholder = '`' + (0, node_crypto_1.randomUUID)() + '`';
|
|
3656
3659
|
replaceMap.push([placeholder, segment]);
|
|
3657
3660
|
current = replaceMatch(bracket, current, placeholder, pattern);
|
|
3658
3661
|
}
|
|
@@ -3665,7 +3668,7 @@ class ChromeDocument extends Document {
|
|
|
3665
3668
|
for (let i = 0, length = values.length; i < length; ++i) {
|
|
3666
3669
|
const seg = values[i];
|
|
3667
3670
|
if (/^url\([^{}]*[{}].*\)$/is.test(seg)) {
|
|
3668
|
-
replaceMap.push([values[i] = (0,
|
|
3671
|
+
replaceMap.push([values[i] = (0, node_crypto_1.randomUUID)(), seg]);
|
|
3669
3672
|
}
|
|
3670
3673
|
}
|
|
3671
3674
|
if (replaceMap.length > 0) {
|
|
@@ -3784,7 +3787,7 @@ class ChromeDocument extends Document {
|
|
|
3784
3787
|
modified = true;
|
|
3785
3788
|
return output + target.substring(index);
|
|
3786
3789
|
}
|
|
3787
|
-
return
|
|
3790
|
+
return child ? '' : target;
|
|
3788
3791
|
})(current, false);
|
|
3789
3792
|
}
|
|
3790
3793
|
if (usedVariables) {
|
|
@@ -3850,9 +3853,8 @@ class ChromeDocument extends Document {
|
|
|
3850
3853
|
}
|
|
3851
3854
|
}
|
|
3852
3855
|
get elements() {
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
return result;
|
|
3856
|
+
if (this._elements) {
|
|
3857
|
+
return this._elements;
|
|
3856
3858
|
}
|
|
3857
3859
|
const elements = new Set();
|
|
3858
3860
|
const host = this.host;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Chrome document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -14,16 +14,15 @@
|
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"squared",
|
|
17
|
-
"e-mc"
|
|
18
|
-
"squared-functions"
|
|
17
|
+
"e-mc"
|
|
19
18
|
],
|
|
20
19
|
"author": "An Pham <anpham6@gmail.com>",
|
|
21
20
|
"license": "MIT",
|
|
22
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
22
|
"dependencies": {
|
|
24
|
-
"@e-mc/cloud": "^0.
|
|
25
|
-
"@e-mc/core": "^0.
|
|
26
|
-
"@e-mc/document": "^0.
|
|
27
|
-
"@e-mc/types": "^0.
|
|
23
|
+
"@e-mc/cloud": "^0.11.0",
|
|
24
|
+
"@e-mc/core": "^0.11.0",
|
|
25
|
+
"@e-mc/document": "^0.11.0",
|
|
26
|
+
"@e-mc/types": "^0.11.0"
|
|
28
27
|
}
|
|
29
28
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
import type { LocationUri, XmlTagNode } from '@e-mc/types/lib/squared';
|
|
2
|
-
|
|
3
|
-
import type { DocumentConstructor, ICloud, IDocument, IFileManager } from '@e-mc/types/lib';
|
|
4
|
-
import type { DocumentAsset as IDocumentAsset } from '@e-mc/types/lib/document';
|
|
5
|
-
import type { LogTime } from '@e-mc/types/lib/logger';
|
|
6
|
-
import type { DbSourceDataType, DocumentComponentOption, DocumentComponent as IDocumentComponent, DocumentComponentOptions as IDocumentComponentOptions, DocumentDirectory as IDocumentDirectory, DocumentEval as IDocumentEval, DocumentModule as IDocumentModule, DocumentSettings as IDocumentSettings, DocumentUserSettings as IDocumentUserSettings } from '@e-mc/types/lib/settings';
|
|
7
|
-
|
|
8
|
-
import type { CloudScopeOrigin } from '@e-mc/cloud/types';
|
|
9
|
-
import type { IDomWriter, IXmlElement } from '@e-mc/document/parse/types';
|
|
10
|
-
|
|
11
|
-
import type { ChromeAsset, CssRuleData, DataSource, DocumentOutput } from './squared';
|
|
12
|
-
|
|
13
|
-
export const enum PROPERTIES {
|
|
14
|
-
INDEX = '__index__',
|
|
15
|
-
FROM_HTML = '__fromhtml__',
|
|
16
|
-
ASSIGN = '__assign__',
|
|
17
|
-
SERVERROOT = '__serverroot__'
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface DocumentDirectory extends IDocumentDirectory {
|
|
21
|
-
template?: string;
|
|
22
|
-
data?: string;
|
|
23
|
-
export?: string;
|
|
24
|
-
schema?: string;
|
|
25
|
-
sql?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface DocumentComponentExtended<T> extends DbSourceDataType<T> {
|
|
29
|
-
uri?: T;
|
|
30
|
-
local?: T;
|
|
31
|
-
export?: T;
|
|
32
|
-
json?: T;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface DocumentComponentOptions<T> extends IDocumentComponentOptions, DocumentComponentExtended<DocumentComponentOption<T>> {}
|
|
36
|
-
|
|
37
|
-
interface DocumentEval extends IDocumentEval {
|
|
38
|
-
template?: boolean;
|
|
39
|
-
userconfig?: boolean;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface ChromeDocumentUserSettings extends IDocumentUserSettings {
|
|
43
|
-
server_root?: ObjectMap<StringMap>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface ChromeDocumentSettings extends IDocumentSettings<ChromeDocumentUserSettings> {
|
|
47
|
-
directory?: DocumentDirectory;
|
|
48
|
-
options?: DocumentComponentOptions<boolean | number>;
|
|
49
|
-
server_root?: ObjectMap<StringMap>;
|
|
50
|
-
export?: ObjectMap<string | FunctionType>;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
type OutputType = "useUnsafeReplace" | "productionRelease" | "productionIncremental" | "serverRootMapping" | "sanitizeFramework" | "templateMap" | "userAgentData";
|
|
54
|
-
|
|
55
|
-
export interface FormatUri extends Partial<LocationUri> {
|
|
56
|
-
dictionary?: string;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface FinalizeProcessing<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> {
|
|
60
|
-
readonly host: T;
|
|
61
|
-
readonly startTime: LogTime;
|
|
62
|
-
readonly hashed: Set<DocumentAsset>;
|
|
63
|
-
readonly contentMap: StringMap;
|
|
64
|
-
readonly bufferMap: ObjectMap<Bufferable>;
|
|
65
|
-
readonly cacheMiss: string[];
|
|
66
|
-
readonly productionRelease:
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface DocumentComponent<T = boolean> extends IDocumentComponent<T, T>, DocumentComponentExtended<T> {}
|
|
70
|
-
|
|
71
|
-
export interface DocumentModule extends IDocumentModule {
|
|
72
|
-
eval?: DocumentEval;
|
|
73
|
-
format?: PlainObject & { uuid?: FormatUri };
|
|
74
|
-
settings?: ChromeDocumentSettings;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface DocumentAsset extends IDocumentAsset, ChromeAsset {
|
|
78
|
-
relativeUrl?: string;
|
|
79
|
-
inlineFilename?: string;
|
|
80
|
-
srcSet?: string[];
|
|
81
|
-
inlineUrl?: string;
|
|
82
|
-
inlineUrlMap?: StringMap;
|
|
83
|
-
inlineUrlCloud?: string;
|
|
84
|
-
inlineUrlCloudMap?: StringMap;
|
|
85
|
-
inlineBase64?: string;
|
|
86
|
-
modified?: boolean;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface UserConfig extends CssRuleData, Omit<DocumentOutput, OutputType> {
|
|
90
|
-
useUnsafeHtmlReplace?: boolean;
|
|
91
|
-
useUnsafeCssReplace?: boolean;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset, V extends ICloud = ICloud<T>> extends IDocument<T, U, DocumentModule, DocumentComponent, DocumentComponentOption, V>, Pick<DocumentOutput, OutputType> {
|
|
95
|
-
htmlFile:
|
|
96
|
-
cssFiles: U[];
|
|
97
|
-
jsFiles: U[];
|
|
98
|
-
svgFiles: U[];
|
|
99
|
-
baseDirectory: string;
|
|
100
|
-
baseUrl: string;
|
|
101
|
-
config: UserConfig;
|
|
102
|
-
related: Map<U, Set<U>>;
|
|
103
|
-
replaced: U[];
|
|
104
|
-
formatMap?: ObjectMap<FormatUri>;
|
|
105
|
-
setElementSrc(asset: U, element: IXmlElement, value: string): void;
|
|
106
|
-
findDataValue(name: string):
|
|
107
|
-
setInlinedAttributes(processing: FinalizeProcessing<T, U>): void;
|
|
108
|
-
applyTransforms(processing: FinalizeProcessing<T, U>): Promise<void>;
|
|
109
|
-
rewriteHtml(processing: FinalizeProcessing<T, U>): Promise<void>;
|
|
110
|
-
setElementAttributes(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
|
|
111
|
-
applyDataSource(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
|
|
112
|
-
setProductionAttributes(processing: FinalizeProcessing<T, U>): void;
|
|
113
|
-
removeUnusedStyles(source: string, options?: UserConfig):
|
|
114
|
-
removeServerRoot(value: string): string;
|
|
115
|
-
replaceContent(source: string, match: RegExpExecArray | string, mimeType?: string):
|
|
116
|
-
cloudInit(state: CloudScopeOrigin<T, U, V>): void;
|
|
117
|
-
cloudObject(state: CloudScopeOrigin<T, U, V>, file: U): boolean;
|
|
118
|
-
cloudUpload(state: CloudScopeOrigin<T, U, V>, file: U, url: string, active: boolean): Promise<boolean>;
|
|
119
|
-
cloudFinalize(state: CloudScopeOrigin<T, U, V>): Promise<unknown[]>;
|
|
120
|
-
get editing(): U[];
|
|
121
|
-
set dataSource(value);
|
|
122
|
-
get dataSource(): DataSource[];
|
|
123
|
-
get elements(): XmlTagNode[];
|
|
124
|
-
get settings(): ChromeDocumentSettings;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export interface ChromeDocumentConstructor<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> extends ConstructorDerived<DocumentConstructor<T, U>> {
|
|
128
|
-
INTERNAL_ASSIGNUUID: string;
|
|
129
|
-
INTERNAL_SERVERROOT: string;
|
|
130
|
-
readonly prototype: IChromeDocument<T, U>;
|
|
131
|
-
new(module?: DocumentModule, ...args: unknown[]): IChromeDocument<T, U>;
|
|
1
|
+
import type { LocationUri, XmlTagNode } from '@e-mc/types/lib/squared';
|
|
2
|
+
|
|
3
|
+
import type { DocumentConstructor, ICloud, IDocument, IFileManager } from '@e-mc/types/lib';
|
|
4
|
+
import type { DocumentAsset as IDocumentAsset } from '@e-mc/types/lib/document';
|
|
5
|
+
import type { LogTime } from '@e-mc/types/lib/logger';
|
|
6
|
+
import type { DbSourceDataType, DocumentComponentOption, DocumentComponent as IDocumentComponent, DocumentComponentOptions as IDocumentComponentOptions, DocumentDirectory as IDocumentDirectory, DocumentEval as IDocumentEval, DocumentModule as IDocumentModule, DocumentSettings as IDocumentSettings, DocumentUserSettings as IDocumentUserSettings } from '@e-mc/types/lib/settings';
|
|
7
|
+
|
|
8
|
+
import type { CloudScopeOrigin } from '@e-mc/cloud/types';
|
|
9
|
+
import type { IDomWriter, IXmlElement } from '@e-mc/document/parse/types';
|
|
10
|
+
|
|
11
|
+
import type { ChromeAsset, CssRuleData, DataSource, DocumentOutput } from './squared';
|
|
12
|
+
|
|
13
|
+
export const enum PROPERTIES {
|
|
14
|
+
INDEX = '__index__',
|
|
15
|
+
FROM_HTML = '__fromhtml__',
|
|
16
|
+
ASSIGN = '__assign__',
|
|
17
|
+
SERVERROOT = '__serverroot__'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface DocumentDirectory extends IDocumentDirectory {
|
|
21
|
+
template?: string;
|
|
22
|
+
data?: string;
|
|
23
|
+
export?: string;
|
|
24
|
+
schema?: string;
|
|
25
|
+
sql?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface DocumentComponentExtended<T> extends DbSourceDataType<T> {
|
|
29
|
+
uri?: T;
|
|
30
|
+
local?: T;
|
|
31
|
+
export?: T;
|
|
32
|
+
json?: T;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface DocumentComponentOptions<T> extends IDocumentComponentOptions, DocumentComponentExtended<DocumentComponentOption<T>> {}
|
|
36
|
+
|
|
37
|
+
interface DocumentEval extends IDocumentEval {
|
|
38
|
+
template?: boolean;
|
|
39
|
+
userconfig?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface ChromeDocumentUserSettings extends IDocumentUserSettings {
|
|
43
|
+
server_root?: ObjectMap<StringMap>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface ChromeDocumentSettings extends IDocumentSettings<ChromeDocumentUserSettings> {
|
|
47
|
+
directory?: DocumentDirectory;
|
|
48
|
+
options?: DocumentComponentOptions<boolean | number>;
|
|
49
|
+
server_root?: ObjectMap<StringMap>;
|
|
50
|
+
export?: ObjectMap<string | FunctionType>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type OutputType = "useUnsafeReplace" | "productionRelease" | "productionIncremental" | "serverRootMapping" | "sanitizeFramework" | "templateMap" | "userAgentData";
|
|
54
|
+
|
|
55
|
+
export interface FormatUri extends Partial<LocationUri> {
|
|
56
|
+
dictionary?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface FinalizeProcessing<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> {
|
|
60
|
+
readonly host: T;
|
|
61
|
+
readonly startTime: LogTime;
|
|
62
|
+
readonly hashed: Set<DocumentAsset>;
|
|
63
|
+
readonly contentMap: StringMap;
|
|
64
|
+
readonly bufferMap: ObjectMap<Bufferable>;
|
|
65
|
+
readonly cacheMiss: string[];
|
|
66
|
+
readonly productionRelease: true | undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface DocumentComponent<T = boolean> extends IDocumentComponent<T, T>, DocumentComponentExtended<T> {}
|
|
70
|
+
|
|
71
|
+
export interface DocumentModule extends IDocumentModule {
|
|
72
|
+
eval?: DocumentEval;
|
|
73
|
+
format?: PlainObject & { uuid?: FormatUri };
|
|
74
|
+
settings?: ChromeDocumentSettings;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface DocumentAsset extends IDocumentAsset, ChromeAsset {
|
|
78
|
+
relativeUrl?: string;
|
|
79
|
+
inlineFilename?: string;
|
|
80
|
+
srcSet?: string[];
|
|
81
|
+
inlineUrl?: string;
|
|
82
|
+
inlineUrlMap?: StringMap;
|
|
83
|
+
inlineUrlCloud?: string;
|
|
84
|
+
inlineUrlCloudMap?: StringMap;
|
|
85
|
+
inlineBase64?: string;
|
|
86
|
+
modified?: boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface UserConfig extends CssRuleData, Omit<DocumentOutput, OutputType> {
|
|
90
|
+
useUnsafeHtmlReplace?: boolean;
|
|
91
|
+
useUnsafeCssReplace?: boolean;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset, V extends ICloud = ICloud<T>> extends IDocument<T, U, DocumentModule, DocumentComponent, DocumentComponentOption, V>, Pick<DocumentOutput, OutputType> {
|
|
95
|
+
htmlFile: U | null;
|
|
96
|
+
cssFiles: U[];
|
|
97
|
+
jsFiles: U[];
|
|
98
|
+
svgFiles: U[];
|
|
99
|
+
baseDirectory: string;
|
|
100
|
+
baseUrl: string;
|
|
101
|
+
config: UserConfig;
|
|
102
|
+
related: Map<U, Set<U>>;
|
|
103
|
+
replaced: U[];
|
|
104
|
+
formatMap?: ObjectMap<FormatUri>;
|
|
105
|
+
setElementSrc(asset: U, element: IXmlElement, value: string): void;
|
|
106
|
+
findDataValue(name: string): string | undefined;
|
|
107
|
+
setInlinedAttributes(processing: FinalizeProcessing<T, U>): void;
|
|
108
|
+
applyTransforms(processing: FinalizeProcessing<T, U>): Promise<void>;
|
|
109
|
+
rewriteHtml(processing: FinalizeProcessing<T, U>): Promise<void>;
|
|
110
|
+
setElementAttributes(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
|
|
111
|
+
applyDataSource(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
|
|
112
|
+
setProductionAttributes(processing: FinalizeProcessing<T, U>): void;
|
|
113
|
+
removeUnusedStyles(source: string, options?: UserConfig): string | undefined;
|
|
114
|
+
removeServerRoot(value: string): string;
|
|
115
|
+
replaceContent(source: string, match: RegExpExecArray | string, mimeType?: string): string | undefined;
|
|
116
|
+
cloudInit(state: CloudScopeOrigin<T, U, V>): void;
|
|
117
|
+
cloudObject(state: CloudScopeOrigin<T, U, V>, file: U): boolean;
|
|
118
|
+
cloudUpload(state: CloudScopeOrigin<T, U, V>, file: U, url: string, active: boolean): Promise<boolean>;
|
|
119
|
+
cloudFinalize(state: CloudScopeOrigin<T, U, V>): Promise<unknown[]>;
|
|
120
|
+
get editing(): U[];
|
|
121
|
+
set dataSource(value);
|
|
122
|
+
get dataSource(): DataSource[];
|
|
123
|
+
get elements(): XmlTagNode[];
|
|
124
|
+
get settings(): ChromeDocumentSettings;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface ChromeDocumentConstructor<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> extends ConstructorDerived<DocumentConstructor<T, U>> {
|
|
128
|
+
INTERNAL_ASSIGNUUID: string;
|
|
129
|
+
INTERNAL_SERVERROOT: string;
|
|
130
|
+
readonly prototype: IChromeDocument<T, U>;
|
|
131
|
+
new(module?: DocumentModule, ...args: unknown[]): IChromeDocument<T, U>;
|
|
132
132
|
}
|
package/types/squared.d.ts
CHANGED
|
@@ -1,148 +1,137 @@
|
|
|
1
|
-
import type { AttributeAction, ElementAction, ExcludeAction, FileAsset, FromAction, HashAction, DataSource as IDataSource, ImportAction, MetadataAction, ViewEngine } from '@e-mc/types/lib/squared';
|
|
2
|
-
|
|
3
|
-
import type { UploadAction } from '@e-mc/types/lib/cloud';
|
|
4
|
-
import type { CascadeAction, DbSource } from '@e-mc/types/lib/db';
|
|
5
|
-
import type { RequestData as IRequestData } from '@e-mc/types/lib/node';
|
|
6
|
-
import type { BufferFormat } from '@e-mc/types/lib/request';
|
|
7
|
-
|
|
8
|
-
interface ImportFrom {
|
|
9
|
-
placeholder: string;
|
|
10
|
-
original: string;
|
|
11
|
-
uri: string;
|
|
12
|
-
type?: string;
|
|
13
|
-
dynamic?: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface DataObject extends CascadeAction {
|
|
17
|
-
format?: BufferFormat;
|
|
18
|
-
options?: PlainObject;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface ScopeData {
|
|
22
|
-
start:
|
|
23
|
-
end:
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface ConditionProperty {
|
|
27
|
-
conditionText: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface CssConditionData extends ConditionProperty {
|
|
31
|
-
name?: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface UserAgentData {
|
|
35
|
-
platform: string;
|
|
36
|
-
name: string;
|
|
37
|
-
brand: string;
|
|
38
|
-
browser: number;
|
|
39
|
-
version:
|
|
40
|
-
majorVersion: number;
|
|
41
|
-
mobile: boolean;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface DocumentOutput {
|
|
45
|
-
productionRelease?: boolean | string;
|
|
46
|
-
productionIncremental?: boolean;
|
|
47
|
-
serverRootMapping?: StringMap;
|
|
48
|
-
useOriginalHtmlPage?: boolean | string;
|
|
49
|
-
useUnsafeReplace?: ArrayOf<"html" | "css"> | boolean;
|
|
50
|
-
useSessionCache?: boolean;
|
|
51
|
-
stripCommentsAndCDATA?: boolean | string;
|
|
52
|
-
normalizeHtmlOutput?: boolean | string;
|
|
53
|
-
escapeReservedCharacters?: boolean;
|
|
54
|
-
ignoreServerCodeBlocks?: string[];
|
|
55
|
-
sanitizeFramework?: string[];
|
|
56
|
-
webBundle?:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
type
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface
|
|
132
|
-
source: "
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
source: "json";
|
|
138
|
-
items?: unknown;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export interface ExportDataSource extends DataSource, CascadeAction {
|
|
142
|
-
source: "export";
|
|
143
|
-
execute?: FunctionType;
|
|
144
|
-
pathname?: string;
|
|
145
|
-
settings?: string;
|
|
146
|
-
params?: unknown;
|
|
147
|
-
persist?: boolean;
|
|
1
|
+
import type { AttributeAction, ElementAction, ExcludeAction, FileAsset, FromAction, HashAction, DataSource as IDataSource, ImportAction, MetadataAction, ViewEngine } from '@e-mc/types/lib/squared';
|
|
2
|
+
|
|
3
|
+
import type { UploadAction } from '@e-mc/types/lib/cloud';
|
|
4
|
+
import type { CascadeAction, DbSource } from '@e-mc/types/lib/db';
|
|
5
|
+
import type { RequestData as IRequestData } from '@e-mc/types/lib/node';
|
|
6
|
+
import type { BufferFormat } from '@e-mc/types/lib/request';
|
|
7
|
+
|
|
8
|
+
interface ImportFrom {
|
|
9
|
+
placeholder: string;
|
|
10
|
+
original: string;
|
|
11
|
+
uri: string;
|
|
12
|
+
type?: string;
|
|
13
|
+
dynamic?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface DataObject extends CascadeAction {
|
|
17
|
+
format?: BufferFormat;
|
|
18
|
+
options?: PlainObject;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface ScopeData {
|
|
22
|
+
start: string | null;
|
|
23
|
+
end: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface ConditionProperty {
|
|
27
|
+
conditionText: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface CssConditionData extends ConditionProperty {
|
|
31
|
+
name?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface UserAgentData {
|
|
35
|
+
platform: string;
|
|
36
|
+
name: string;
|
|
37
|
+
brand: string;
|
|
38
|
+
browser: number;
|
|
39
|
+
version: number[] | null;
|
|
40
|
+
majorVersion: number;
|
|
41
|
+
mobile: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface DocumentOutput {
|
|
45
|
+
productionRelease?: boolean | string;
|
|
46
|
+
productionIncremental?: boolean;
|
|
47
|
+
serverRootMapping?: StringMap;
|
|
48
|
+
useOriginalHtmlPage?: boolean | string;
|
|
49
|
+
useUnsafeReplace?: ArrayOf<"html" | "css"> | boolean;
|
|
50
|
+
useSessionCache?: boolean;
|
|
51
|
+
stripCommentsAndCDATA?: boolean | string;
|
|
52
|
+
normalizeHtmlOutput?: boolean | string;
|
|
53
|
+
escapeReservedCharacters?: boolean;
|
|
54
|
+
ignoreServerCodeBlocks?: string[];
|
|
55
|
+
sanitizeFramework?: string[];
|
|
56
|
+
webBundle?: unknown;
|
|
57
|
+
templateMap?: TemplateMap;
|
|
58
|
+
userAgentData?: Partial<UserAgentData>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface RequestData extends IRequestData<ChromeAsset>, Readonly<DocumentOutput>, Readonly<CssRuleData> {}
|
|
62
|
+
|
|
63
|
+
export interface ChromeAsset extends FileAsset, AttributeAction, ElementAction, MetadataAction<PlainObject>, UploadAction, HashAction, ExcludeAction, ImportAction<ImportFrom[] | boolean>, FromAction {
|
|
64
|
+
preserve?: boolean;
|
|
65
|
+
static?: boolean;
|
|
66
|
+
editing?: boolean;
|
|
67
|
+
inlineContent?: string;
|
|
68
|
+
originAddress?: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface TemplateMap extends PlainObject {
|
|
72
|
+
html?: ObjectMap<StringMap>;
|
|
73
|
+
js?: ObjectMap<StringMap>;
|
|
74
|
+
css?: ObjectMap<StringMap>;
|
|
75
|
+
data?: StringMap;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface CssRuleData {
|
|
79
|
+
usedVariables?: string[];
|
|
80
|
+
usedFontFace?: string[];
|
|
81
|
+
usedKeyframes?: string[];
|
|
82
|
+
unusedStyles?: string[];
|
|
83
|
+
unusedMedia?: string[];
|
|
84
|
+
unusedSupports?: string[];
|
|
85
|
+
unusedContainer?: string[];
|
|
86
|
+
unusedScope?: ScopeData[];
|
|
87
|
+
unusedAtRules?: UnusedAtRule[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface UnusedAtRule {
|
|
91
|
+
selector?: string;
|
|
92
|
+
media?: ConditionProperty;
|
|
93
|
+
supports?: ConditionProperty;
|
|
94
|
+
container?: CssConditionData & Partial<ConditionProperty>;
|
|
95
|
+
layer?: string[];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface DataSource<T = string> extends IDataSource<T>, ElementAction {
|
|
99
|
+
source: "cloud" | "json" | "uri" | "local" | "export" | DbSource;
|
|
100
|
+
type?: "text" | "attribute" | "display";
|
|
101
|
+
dynamic?: boolean;
|
|
102
|
+
value?: string | string[] | AnyObject;
|
|
103
|
+
template?: string;
|
|
104
|
+
viewEngine?: ViewEngine | string;
|
|
105
|
+
ignoreEmpty?: boolean;
|
|
106
|
+
ignoreCoerce?: boolean;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface TextDataSource extends DataSource {
|
|
110
|
+
type: "text";
|
|
111
|
+
leadingText?: string;
|
|
112
|
+
trailingText?: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface UriDataSource extends DataSource, DataObject {
|
|
116
|
+
source: "uri";
|
|
117
|
+
body?: unknown;
|
|
118
|
+
contentType?: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface LocalDataSource extends DataSource, DataObject {
|
|
122
|
+
source: "local";
|
|
123
|
+
pathname?: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface JSONDataSource extends DataSource, CascadeAction {
|
|
127
|
+
source: "json";
|
|
128
|
+
items?: unknown;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface ExportDataSource extends DataSource, CascadeAction {
|
|
132
|
+
source: "export";
|
|
133
|
+
execute?: FunctionType;
|
|
134
|
+
pathname?: string;
|
|
135
|
+
settings?: string;
|
|
136
|
+
params?: unknown;
|
|
148
137
|
}
|