@pi-r/chrome 0.6.7 → 0.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +6 -6
- package/README.md +9 -9
- package/index.d.ts +6 -6
- package/index.js +60 -11
- package/package.json +28 -28
- package/types/index.d.ts +126 -126
- package/types/squared.d.ts +128 -128
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
1
|
+
Copyright 2023 An Pham
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
7
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# @pi-r/chrome
|
|
2
|
-
|
|
3
|
-
## Documentation
|
|
4
|
-
|
|
5
|
-
- [E-mc](https://e-mc.readthedocs.io/en/latest/document/index.html)
|
|
6
|
-
- [squared](https://squared.readthedocs.io)
|
|
7
|
-
|
|
8
|
-
## LICENSE
|
|
9
|
-
|
|
1
|
+
# @pi-r/chrome
|
|
2
|
+
|
|
3
|
+
## Documentation
|
|
4
|
+
|
|
5
|
+
- [E-mc](https://e-mc.readthedocs.io/en/latest/document/index.html)
|
|
6
|
+
- [squared](https://squared.readthedocs.io)
|
|
7
|
+
|
|
8
|
+
## LICENSE
|
|
9
|
+
|
|
10
10
|
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
|
@@ -13,6 +13,9 @@ const CACHE_DBRESULT = new Map();
|
|
|
13
13
|
const CACHE_LOCALFILE = new Map();
|
|
14
14
|
const CACHE_QUERY = new Map();
|
|
15
15
|
const CACHE_SELECTOR = new Map();
|
|
16
|
+
const CACHE_ETAG = new Map();
|
|
17
|
+
const CACHE_CONTENT = new Map();
|
|
18
|
+
const CACHE_FORMAT = new Map();
|
|
16
19
|
const CACHE_DATASET = {};
|
|
17
20
|
const CACHE_ATRULES = {};
|
|
18
21
|
let CACHE_TOTAL = 0;
|
|
@@ -973,6 +976,9 @@ class ChromeDocument extends Document {
|
|
|
973
976
|
}
|
|
974
977
|
CACHE_QUERY.clear();
|
|
975
978
|
CACHE_SELECTOR.clear();
|
|
979
|
+
CACHE_ETAG.clear();
|
|
980
|
+
CACHE_CONTENT.clear();
|
|
981
|
+
CACHE_FORMAT.clear();
|
|
976
982
|
}
|
|
977
983
|
return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
|
|
978
984
|
}
|
|
@@ -1000,12 +1006,27 @@ class ChromeDocument extends Document {
|
|
|
1000
1006
|
if (outHtml) {
|
|
1001
1007
|
const { etag, initialValue } = htmlFile;
|
|
1002
1008
|
let buffer;
|
|
1003
|
-
if (!initialValue || !(etag && initialValue.etag === etag && (buffer = initialValue.buffer)) || fetched.find(item => item.
|
|
1009
|
+
if (!initialValue || !(etag && initialValue.etag === etag && (buffer = initialValue.buffer)) || fetched.find(item => item !== htmlFile && item.etag && CACHE_ETAG.get(item.localUri) !== item.etag && (item.inlineContent || item.bundleReplace && (!Array.isArray(item.from) || item.from.includes('style'))))) {
|
|
1010
|
+
const isValid = (item) => !!item.localUri && item !== htmlFile && !item.invalid;
|
|
1011
|
+
for (const item of fetched) {
|
|
1012
|
+
if (item.etag && !item.content && isValid(item)) {
|
|
1013
|
+
CACHE_ETAG.set(item.localUri, item.etag);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
for (const item of instance.assets) {
|
|
1017
|
+
if (isValid(item)) {
|
|
1018
|
+
if (item.content) {
|
|
1019
|
+
CACHE_CONTENT.set(item.localUri, item.content);
|
|
1020
|
+
}
|
|
1021
|
+
if (item.format) {
|
|
1022
|
+
CACHE_FORMAT.set(item.localUri, item.format.toString());
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1004
1026
|
break;
|
|
1005
1027
|
}
|
|
1006
1028
|
try {
|
|
1007
|
-
|
|
1008
|
-
fs.writeFileSync(localUri, buffer, (0, types_1.getEncoding)(encoding));
|
|
1029
|
+
fs.writeFileSync(htmlFile.localUri, buffer, (0, types_1.getEncoding)(htmlFile.encoding));
|
|
1009
1030
|
htmlFile.buffer = buffer;
|
|
1010
1031
|
htmlFile.sourceUTF8 = undefined;
|
|
1011
1032
|
}
|
|
@@ -1013,12 +1034,39 @@ class ChromeDocument extends Document {
|
|
|
1013
1034
|
break;
|
|
1014
1035
|
}
|
|
1015
1036
|
}
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1037
|
+
const wasModified = (item) => {
|
|
1038
|
+
const localUri = item.localUri;
|
|
1039
|
+
let result = fetched.includes(item) || Array.isArray(item.from) && item.from.includes('style');
|
|
1040
|
+
if (localUri) {
|
|
1041
|
+
if (item.etag && !item.content && !item.invalid) {
|
|
1042
|
+
CACHE_ETAG.set(localUri, item.etag);
|
|
1043
|
+
}
|
|
1044
|
+
else {
|
|
1045
|
+
CACHE_ETAG.delete(localUri);
|
|
1046
|
+
}
|
|
1047
|
+
if (!item.content || item.invalid) {
|
|
1048
|
+
CACHE_CONTENT.delete(localUri);
|
|
1049
|
+
}
|
|
1050
|
+
else if (CACHE_CONTENT.get(localUri) !== item.content || !item.inlineContent && !Document.isPath(localUri)) {
|
|
1051
|
+
CACHE_CONTENT.set(localUri, item.content);
|
|
1052
|
+
result = true;
|
|
1053
|
+
}
|
|
1054
|
+
if (!item.format || item.invalid) {
|
|
1055
|
+
CACHE_FORMAT.delete(localUri);
|
|
1056
|
+
}
|
|
1057
|
+
else {
|
|
1058
|
+
const format = item.format.toString();
|
|
1059
|
+
if (CACHE_FORMAT.get(localUri) !== format || !item.inlineContent && !Document.isPath(localUri)) {
|
|
1060
|
+
CACHE_FORMAT.set(localUri, format);
|
|
1061
|
+
result = true;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
return result || this.copiedAssets.includes(item) && (!(0, types_1.isEmpty)(item.bundleId) || !(0, types_1.isEmpty)(item.trailingContent));
|
|
1066
|
+
};
|
|
1067
|
+
const js = instance.jsFiles.filter(item => wasModified(item) || !!item.imports);
|
|
1068
|
+
const css = instance.cssFiles.filter(wasModified);
|
|
1069
|
+
const svg = instance.svgFiles.filter(wasModified);
|
|
1022
1070
|
if (js.length || css.length || svg.length) {
|
|
1023
1071
|
instance.jsFiles = js;
|
|
1024
1072
|
instance.cssFiles = css;
|
|
@@ -3130,7 +3178,8 @@ class ChromeDocument extends Document {
|
|
|
3130
3178
|
const row = items[0];
|
|
3131
3179
|
let condition = NaN;
|
|
3132
3180
|
for (let seg of template) {
|
|
3133
|
-
|
|
3181
|
+
seg = seg.trim();
|
|
3182
|
+
switch (seg.toLowerCase()) {
|
|
3134
3183
|
case ':is(and)':
|
|
3135
3184
|
if (condition === 0) {
|
|
3136
3185
|
remove = false;
|
|
@@ -3327,7 +3376,7 @@ class ChromeDocument extends Document {
|
|
|
3327
3376
|
const parseSelector = (value) => {
|
|
3328
3377
|
const items = [];
|
|
3329
3378
|
const revised = value.replace(useUnsafeCssReplace ? REGEXP_NTHCHILD_UNSAFE : REGEXP_NTHCHILD, (...capture) => {
|
|
3330
|
-
return '`%' + (items.push('\\(' + getStringSome() + (capture[1] === '-' ? '\\x2d' : '\\x2b?') + (capture[2] || '[01]?') + (capture[3] === '0' ? !capture[1] && !capture[2] && !capture[4] && !capture[5] ? '[+-]?0[nN]?' : '0' : '[nN]') + getStringSome() + (capture[5] ? (capture[4] === '-' ? '\\x2d' : '\\x2b') + getStringSome() + capture[5] : `(?:[+-]${getStringSome()}0)?`) + (capture[6] ? getStringMany() + '[oO][fF]' + getStringMany() + capture[6].trim() : '') + getStringSome() + '\\)') - 1) + '`';
|
|
3379
|
+
return '`%' + (items.push('\\(' + getStringSome() + (capture[1] === '-' ? '\\x2d' : '\\x2b?') + (capture[2] || '[01]?') + (capture[3] === '0' ? !capture[1] && !capture[2] && !capture[4] && !capture[5] ? '[+-]?0[nN]?' : '0' : '[nN]?') + getStringSome() + (capture[5] ? (capture[4] === '-' ? '\\x2d' : '\\x2b?') + getStringSome() + capture[5] : `(?:[+-]${getStringSome()}0)?`) + (capture[6] ? getStringMany() + '[oO][fF]' + getStringMany() + capture[6].trim() : '') + getStringSome() + '\\)') - 1) + '`';
|
|
3331
3380
|
});
|
|
3332
3381
|
let selector = '';
|
|
3333
3382
|
for (let i = 0, length = revised.length, casing = false, attr = false, quote = false; i < length; i++) {
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.6.
|
|
4
|
-
"description": "Chrome document constructor for E-mc.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
-
"directory": "src/module/chrome"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"squared",
|
|
16
|
-
"e-mc",
|
|
17
|
-
"squared-functions"
|
|
18
|
-
],
|
|
19
|
-
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.8.
|
|
24
|
-
"@e-mc/core": "^0.8.
|
|
25
|
-
"@e-mc/document": "^0.8.
|
|
26
|
-
"@e-mc/types": "^0.8.
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-r/chrome",
|
|
3
|
+
"version": "0.6.9",
|
|
4
|
+
"description": "Chrome document constructor for E-mc.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"directory": "src/module/chrome"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"squared",
|
|
16
|
+
"e-mc",
|
|
17
|
+
"squared-functions"
|
|
18
|
+
],
|
|
19
|
+
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@e-mc/cloud": "^0.8.24",
|
|
24
|
+
"@e-mc/core": "^0.8.24",
|
|
25
|
+
"@e-mc/document": "^0.8.24",
|
|
26
|
+
"@e-mc/types": "^0.8.24"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
import type { LocationUri, XmlTagNode } from '@e-mc/types/lib/squared';
|
|
2
|
-
|
|
3
|
-
import type { DocumentConstructor, ICloud, IDocument, IFileManager } from '@e-mc/types/lib';
|
|
4
|
-
import type { DocumentAsset as IDocumentAsset } from '@e-mc/types/lib/document';
|
|
5
|
-
import type { LogTime } from '@e-mc/types/lib/logger';
|
|
6
|
-
import type { DbSourceDataType, DocumentComponentOption, DocumentComponent as IDocumentComponent, DocumentComponentOptions as IDocumentComponentOptions, DocumentDirectory as IDocumentDirectory, DocumentEval as IDocumentEval, DocumentModule as IDocumentModule, DocumentSettings as IDocumentSettings } from '@e-mc/types/lib/settings';
|
|
7
|
-
|
|
8
|
-
import type { CloudScopeOrigin } from '@e-mc/cloud/types';
|
|
9
|
-
import type { IDomWriter, IXmlElement } from '@e-mc/document/parse/types';
|
|
10
|
-
|
|
11
|
-
import type { ChromeAsset, CssRuleData, DataSource, DocumentOutput } from './squared';
|
|
12
|
-
|
|
13
|
-
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
|
-
json?: T;
|
|
30
|
-
uri?: T;
|
|
31
|
-
local?: T;
|
|
32
|
-
export?: 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 ChromeDocumentSettings extends IDocumentSettings {
|
|
43
|
-
directory?: DocumentDirectory;
|
|
44
|
-
options?: DocumentComponentOptions<boolean | number>;
|
|
45
|
-
export?: ObjectMap<string | FunctionType>;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type OutputType = "useUnsafeReplace" | "productionRelease" | "productionIncremental" | "templateMap" | "userAgentData";
|
|
49
|
-
|
|
50
|
-
export interface FormatUri extends Partial<LocationUri> {
|
|
51
|
-
dictionary?: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface FinalizeProcessing<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> {
|
|
55
|
-
readonly host: T;
|
|
56
|
-
readonly startTime: LogTime;
|
|
57
|
-
readonly hashed: Set<DocumentAsset>;
|
|
58
|
-
readonly contentMap: StringMap;
|
|
59
|
-
readonly bufferMap: ObjectMap<BufferContent>;
|
|
60
|
-
readonly cacheMiss: string[];
|
|
61
|
-
readonly productionRelease: Undef<true>;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface DocumentComponent<T = boolean> extends IDocumentComponent<T, T>, DocumentComponentExtended<T> {}
|
|
65
|
-
|
|
66
|
-
export interface DocumentModule extends IDocumentModule {
|
|
67
|
-
eval?: DocumentEval;
|
|
68
|
-
format?: PlainObject & { uuid?: FormatUri };
|
|
69
|
-
settings?: ChromeDocumentSettings;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface DocumentAsset extends IDocumentAsset, ChromeAsset {
|
|
73
|
-
relativeUrl?: string;
|
|
74
|
-
inlineFilename?: string;
|
|
75
|
-
srcSet?: string[];
|
|
76
|
-
inlineUrl?: string;
|
|
77
|
-
inlineUrlMap?: StringMap;
|
|
78
|
-
inlineUrlCloud?: string;
|
|
79
|
-
inlineUrlCloudMap?: StringMap;
|
|
80
|
-
inlineBase64?: string;
|
|
81
|
-
modified?: boolean;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export interface UserConfig extends CssRuleData, Omit<DocumentOutput, OutputType> {
|
|
85
|
-
useUnsafeHtmlReplace?: boolean;
|
|
86
|
-
useUnsafeCssReplace?: boolean;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
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> {
|
|
90
|
-
htmlFile: Null<U>;
|
|
91
|
-
cssFiles: U[];
|
|
92
|
-
jsFiles: U[];
|
|
93
|
-
svgFiles: U[];
|
|
94
|
-
baseDirectory: string;
|
|
95
|
-
baseUrl: string;
|
|
96
|
-
config: UserConfig;
|
|
97
|
-
related: Map<U, Set<U>>;
|
|
98
|
-
replaced: U[];
|
|
99
|
-
formatMap?: ObjectMap<FormatUri>;
|
|
100
|
-
setElementSrc(asset: U, element: IXmlElement, value: string): void;
|
|
101
|
-
findDataValue(name: string): Undef<string>;
|
|
102
|
-
setInlinedAttributes(processing: FinalizeProcessing<T, U>): void;
|
|
103
|
-
applyTransforms(processing: FinalizeProcessing<T, U>): Promise<void>;
|
|
104
|
-
rewriteHtml(processing: FinalizeProcessing<T, U>): Promise<void>;
|
|
105
|
-
setElementAttributes(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
|
|
106
|
-
applyDataSource(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
|
|
107
|
-
setProductionAttributes(processing: FinalizeProcessing<T, U>): void;
|
|
108
|
-
removeUnusedStyles(source: string, options?: UserConfig): Undef<string>;
|
|
109
|
-
removeServerRoot(value: string): string;
|
|
110
|
-
replaceContent(source: string, match: RegExpExecArray | string, mimeType?: string): Undef<string>;
|
|
111
|
-
cloudInit(state: CloudScopeOrigin<T, U, V>): void;
|
|
112
|
-
cloudObject(state: CloudScopeOrigin<T, U, V>, file: U): boolean;
|
|
113
|
-
cloudUpload(state: CloudScopeOrigin<T, U, V>, file: U, url: string, active: boolean): Promise<boolean>;
|
|
114
|
-
cloudFinalize(state: CloudScopeOrigin<T, U, V>): Promise<unknown[]>;
|
|
115
|
-
get editing(): U[];
|
|
116
|
-
set dataSource(value);
|
|
117
|
-
get dataSource(): DataSource[];
|
|
118
|
-
get elements(): XmlTagNode[];
|
|
119
|
-
get settings(): ChromeDocumentSettings;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export interface ChromeDocumentConstructor<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> extends DocumentConstructor<T, U> {
|
|
123
|
-
INTERNAL_ASSIGNUUID: string;
|
|
124
|
-
INTERNAL_SERVERROOT: string;
|
|
125
|
-
readonly prototype: IChromeDocument<T, U>;
|
|
126
|
-
new(module?: DocumentModule, ...args: unknown[]): IChromeDocument<T, U>;
|
|
1
|
+
import type { LocationUri, XmlTagNode } from '@e-mc/types/lib/squared';
|
|
2
|
+
|
|
3
|
+
import type { DocumentConstructor, ICloud, IDocument, IFileManager } from '@e-mc/types/lib';
|
|
4
|
+
import type { DocumentAsset as IDocumentAsset } from '@e-mc/types/lib/document';
|
|
5
|
+
import type { LogTime } from '@e-mc/types/lib/logger';
|
|
6
|
+
import type { DbSourceDataType, DocumentComponentOption, DocumentComponent as IDocumentComponent, DocumentComponentOptions as IDocumentComponentOptions, DocumentDirectory as IDocumentDirectory, DocumentEval as IDocumentEval, DocumentModule as IDocumentModule, DocumentSettings as IDocumentSettings } from '@e-mc/types/lib/settings';
|
|
7
|
+
|
|
8
|
+
import type { CloudScopeOrigin } from '@e-mc/cloud/types';
|
|
9
|
+
import type { IDomWriter, IXmlElement } from '@e-mc/document/parse/types';
|
|
10
|
+
|
|
11
|
+
import type { ChromeAsset, CssRuleData, DataSource, DocumentOutput } from './squared';
|
|
12
|
+
|
|
13
|
+
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
|
+
json?: T;
|
|
30
|
+
uri?: T;
|
|
31
|
+
local?: T;
|
|
32
|
+
export?: 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 ChromeDocumentSettings extends IDocumentSettings {
|
|
43
|
+
directory?: DocumentDirectory;
|
|
44
|
+
options?: DocumentComponentOptions<boolean | number>;
|
|
45
|
+
export?: ObjectMap<string | FunctionType>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type OutputType = "useUnsafeReplace" | "productionRelease" | "productionIncremental" | "templateMap" | "userAgentData";
|
|
49
|
+
|
|
50
|
+
export interface FormatUri extends Partial<LocationUri> {
|
|
51
|
+
dictionary?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface FinalizeProcessing<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> {
|
|
55
|
+
readonly host: T;
|
|
56
|
+
readonly startTime: LogTime;
|
|
57
|
+
readonly hashed: Set<DocumentAsset>;
|
|
58
|
+
readonly contentMap: StringMap;
|
|
59
|
+
readonly bufferMap: ObjectMap<BufferContent>;
|
|
60
|
+
readonly cacheMiss: string[];
|
|
61
|
+
readonly productionRelease: Undef<true>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface DocumentComponent<T = boolean> extends IDocumentComponent<T, T>, DocumentComponentExtended<T> {}
|
|
65
|
+
|
|
66
|
+
export interface DocumentModule extends IDocumentModule {
|
|
67
|
+
eval?: DocumentEval;
|
|
68
|
+
format?: PlainObject & { uuid?: FormatUri };
|
|
69
|
+
settings?: ChromeDocumentSettings;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface DocumentAsset extends IDocumentAsset, ChromeAsset {
|
|
73
|
+
relativeUrl?: string;
|
|
74
|
+
inlineFilename?: string;
|
|
75
|
+
srcSet?: string[];
|
|
76
|
+
inlineUrl?: string;
|
|
77
|
+
inlineUrlMap?: StringMap;
|
|
78
|
+
inlineUrlCloud?: string;
|
|
79
|
+
inlineUrlCloudMap?: StringMap;
|
|
80
|
+
inlineBase64?: string;
|
|
81
|
+
modified?: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface UserConfig extends CssRuleData, Omit<DocumentOutput, OutputType> {
|
|
85
|
+
useUnsafeHtmlReplace?: boolean;
|
|
86
|
+
useUnsafeCssReplace?: boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
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> {
|
|
90
|
+
htmlFile: Null<U>;
|
|
91
|
+
cssFiles: U[];
|
|
92
|
+
jsFiles: U[];
|
|
93
|
+
svgFiles: U[];
|
|
94
|
+
baseDirectory: string;
|
|
95
|
+
baseUrl: string;
|
|
96
|
+
config: UserConfig;
|
|
97
|
+
related: Map<U, Set<U>>;
|
|
98
|
+
replaced: U[];
|
|
99
|
+
formatMap?: ObjectMap<FormatUri>;
|
|
100
|
+
setElementSrc(asset: U, element: IXmlElement, value: string): void;
|
|
101
|
+
findDataValue(name: string): Undef<string>;
|
|
102
|
+
setInlinedAttributes(processing: FinalizeProcessing<T, U>): void;
|
|
103
|
+
applyTransforms(processing: FinalizeProcessing<T, U>): Promise<void>;
|
|
104
|
+
rewriteHtml(processing: FinalizeProcessing<T, U>): Promise<void>;
|
|
105
|
+
setElementAttributes(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
|
|
106
|
+
applyDataSource(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
|
|
107
|
+
setProductionAttributes(processing: FinalizeProcessing<T, U>): void;
|
|
108
|
+
removeUnusedStyles(source: string, options?: UserConfig): Undef<string>;
|
|
109
|
+
removeServerRoot(value: string): string;
|
|
110
|
+
replaceContent(source: string, match: RegExpExecArray | string, mimeType?: string): Undef<string>;
|
|
111
|
+
cloudInit(state: CloudScopeOrigin<T, U, V>): void;
|
|
112
|
+
cloudObject(state: CloudScopeOrigin<T, U, V>, file: U): boolean;
|
|
113
|
+
cloudUpload(state: CloudScopeOrigin<T, U, V>, file: U, url: string, active: boolean): Promise<boolean>;
|
|
114
|
+
cloudFinalize(state: CloudScopeOrigin<T, U, V>): Promise<unknown[]>;
|
|
115
|
+
get editing(): U[];
|
|
116
|
+
set dataSource(value);
|
|
117
|
+
get dataSource(): DataSource[];
|
|
118
|
+
get elements(): XmlTagNode[];
|
|
119
|
+
get settings(): ChromeDocumentSettings;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface ChromeDocumentConstructor<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> extends DocumentConstructor<T, U> {
|
|
123
|
+
INTERNAL_ASSIGNUUID: string;
|
|
124
|
+
INTERNAL_SERVERROOT: string;
|
|
125
|
+
readonly prototype: IChromeDocument<T, U>;
|
|
126
|
+
new(module?: DocumentModule, ...args: unknown[]): IChromeDocument<T, U>;
|
|
127
127
|
}
|
package/types/squared.d.ts
CHANGED
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
import type { AttributeAction, ConditionProperty, CssConditionData, ElementAction, ExcludeAction, FileAsset, FromAction, HashAction, DataSource as IDataSource, ImportAction, MetadataAction, ViewEngine, XmlTagNode } from '@e-mc/types/lib/squared';
|
|
2
|
-
|
|
3
|
-
import type { UploadAction } from '@e-mc/types/lib/cloud';
|
|
4
|
-
import type { CascadeAction, DbSource } from '@e-mc/types/lib/db';
|
|
5
|
-
import type { RequestData as IRequestData } from '@e-mc/types/lib/node';
|
|
6
|
-
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
|
-
export interface UserAgentData {
|
|
22
|
-
platform: string;
|
|
23
|
-
brand: string;
|
|
24
|
-
browser: number;
|
|
25
|
-
version: Null<number[]>;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface DocumentOutput {
|
|
29
|
-
productionRelease?: boolean | string;
|
|
30
|
-
productionIncremental?: boolean;
|
|
31
|
-
useOriginalHtmlPage?: boolean | string;
|
|
32
|
-
useUnsafeReplace?: ArrayOf<"html" | "css"> | boolean;
|
|
33
|
-
useSessionCache?: boolean;
|
|
34
|
-
stripCommentsAndCDATA?: boolean | string;
|
|
35
|
-
normalizeHtmlOutput?: boolean | string;
|
|
36
|
-
escapeReservedCharacters?: boolean;
|
|
37
|
-
ignoreServerCodeBlocks?: string[];
|
|
38
|
-
webBundle?: {
|
|
39
|
-
rootDirAlias?: string;
|
|
40
|
-
baseUrl?: string;
|
|
41
|
-
primaryUrl?: string;
|
|
42
|
-
copyTo?: string;
|
|
43
|
-
rewriteHtmlPage?: boolean | string;
|
|
44
|
-
excludeHtmlPage?: boolean;
|
|
45
|
-
excludeTransforms?: boolean;
|
|
46
|
-
includeScopes?: string[];
|
|
47
|
-
excludeScopes?: string[];
|
|
48
|
-
};
|
|
49
|
-
templateMap?: TemplateMap;
|
|
50
|
-
userAgentData?: Partial<UserAgentData>;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface RequestData extends IRequestData<ChromeAsset>, Readonly<DocumentOutput>, Readonly<CssRuleData> {}
|
|
54
|
-
|
|
55
|
-
export interface ChromeAsset extends FileAsset, AttributeAction, ElementAction, MetadataAction<PlainObject>, UploadAction, HashAction, ExcludeAction, ImportAction<ImportFrom[] | boolean>, FromAction {
|
|
56
|
-
preserve?: boolean;
|
|
57
|
-
static?: boolean;
|
|
58
|
-
editing?: boolean;
|
|
59
|
-
inlineContent?: string;
|
|
60
|
-
originAddress?: boolean;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface TemplateMap extends PlainObject {
|
|
64
|
-
html?: ObjectMap<StringMap>;
|
|
65
|
-
js?: ObjectMap<StringMap>;
|
|
66
|
-
css?: ObjectMap<StringMap>;
|
|
67
|
-
data?: StringMap;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface CssRuleData {
|
|
71
|
-
usedVariables?: string[];
|
|
72
|
-
usedFontFace?: string[];
|
|
73
|
-
usedKeyframes?: string[];
|
|
74
|
-
unusedStyles?: string[];
|
|
75
|
-
unusedMedia?: string[];
|
|
76
|
-
unusedContainer?: string[];
|
|
77
|
-
unusedSupports?: string[];
|
|
78
|
-
unusedAtRules?: UnusedAtRule[];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface UnusedAtRule {
|
|
82
|
-
selector?: string;
|
|
83
|
-
media?: ConditionProperty;
|
|
84
|
-
supports?: ConditionProperty;
|
|
85
|
-
container?: CssConditionData & Partial<ConditionProperty>;
|
|
86
|
-
layer?: string[];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface DataSource<T = string> extends IDataSource<T>, ElementAction {
|
|
90
|
-
source: "cloud" | "json" | "uri" | "local" | "export" | DbSource;
|
|
91
|
-
element?: XmlTagNode;
|
|
92
|
-
type?: "text" | "attribute" | "display";
|
|
93
|
-
dynamic?: boolean;
|
|
94
|
-
value?: StringOfArray | ObjectMap<unknown>;
|
|
95
|
-
template?: string;
|
|
96
|
-
viewEngine?: ViewEngine | string;
|
|
97
|
-
ignoreEmpty?: boolean;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export interface TextDataSource extends DataSource {
|
|
101
|
-
type: "text";
|
|
102
|
-
leadingText?: string;
|
|
103
|
-
trailingText?: string;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export interface UriDataSource extends DataSource, DataObject {
|
|
107
|
-
source: "uri";
|
|
108
|
-
body?: unknown;
|
|
109
|
-
contentType?: string;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export interface LocalDataSource extends DataSource, DataObject {
|
|
113
|
-
source: "local";
|
|
114
|
-
pathname?: string;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export interface JSONDataSource extends DataSource, CascadeAction {
|
|
118
|
-
source: "json";
|
|
119
|
-
items?: unknown;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export interface ExportDataSource extends DataSource, CascadeAction {
|
|
123
|
-
source: "export";
|
|
124
|
-
execute?: FunctionType;
|
|
125
|
-
pathname?: string;
|
|
126
|
-
settings?: string;
|
|
127
|
-
params?: unknown;
|
|
128
|
-
persist?: boolean;
|
|
1
|
+
import type { AttributeAction, ConditionProperty, CssConditionData, ElementAction, ExcludeAction, FileAsset, FromAction, HashAction, DataSource as IDataSource, ImportAction, MetadataAction, ViewEngine, XmlTagNode } from '@e-mc/types/lib/squared';
|
|
2
|
+
|
|
3
|
+
import type { UploadAction } from '@e-mc/types/lib/cloud';
|
|
4
|
+
import type { CascadeAction, DbSource } from '@e-mc/types/lib/db';
|
|
5
|
+
import type { RequestData as IRequestData } from '@e-mc/types/lib/node';
|
|
6
|
+
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
|
+
export interface UserAgentData {
|
|
22
|
+
platform: string;
|
|
23
|
+
brand: string;
|
|
24
|
+
browser: number;
|
|
25
|
+
version: Null<number[]>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface DocumentOutput {
|
|
29
|
+
productionRelease?: boolean | string;
|
|
30
|
+
productionIncremental?: boolean;
|
|
31
|
+
useOriginalHtmlPage?: boolean | string;
|
|
32
|
+
useUnsafeReplace?: ArrayOf<"html" | "css"> | boolean;
|
|
33
|
+
useSessionCache?: boolean;
|
|
34
|
+
stripCommentsAndCDATA?: boolean | string;
|
|
35
|
+
normalizeHtmlOutput?: boolean | string;
|
|
36
|
+
escapeReservedCharacters?: boolean;
|
|
37
|
+
ignoreServerCodeBlocks?: string[];
|
|
38
|
+
webBundle?: {
|
|
39
|
+
rootDirAlias?: string;
|
|
40
|
+
baseUrl?: string;
|
|
41
|
+
primaryUrl?: string;
|
|
42
|
+
copyTo?: string;
|
|
43
|
+
rewriteHtmlPage?: boolean | string;
|
|
44
|
+
excludeHtmlPage?: boolean;
|
|
45
|
+
excludeTransforms?: boolean;
|
|
46
|
+
includeScopes?: string[];
|
|
47
|
+
excludeScopes?: string[];
|
|
48
|
+
};
|
|
49
|
+
templateMap?: TemplateMap;
|
|
50
|
+
userAgentData?: Partial<UserAgentData>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface RequestData extends IRequestData<ChromeAsset>, Readonly<DocumentOutput>, Readonly<CssRuleData> {}
|
|
54
|
+
|
|
55
|
+
export interface ChromeAsset extends FileAsset, AttributeAction, ElementAction, MetadataAction<PlainObject>, UploadAction, HashAction, ExcludeAction, ImportAction<ImportFrom[] | boolean>, FromAction {
|
|
56
|
+
preserve?: boolean;
|
|
57
|
+
static?: boolean;
|
|
58
|
+
editing?: boolean;
|
|
59
|
+
inlineContent?: string;
|
|
60
|
+
originAddress?: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface TemplateMap extends PlainObject {
|
|
64
|
+
html?: ObjectMap<StringMap>;
|
|
65
|
+
js?: ObjectMap<StringMap>;
|
|
66
|
+
css?: ObjectMap<StringMap>;
|
|
67
|
+
data?: StringMap;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface CssRuleData {
|
|
71
|
+
usedVariables?: string[];
|
|
72
|
+
usedFontFace?: string[];
|
|
73
|
+
usedKeyframes?: string[];
|
|
74
|
+
unusedStyles?: string[];
|
|
75
|
+
unusedMedia?: string[];
|
|
76
|
+
unusedContainer?: string[];
|
|
77
|
+
unusedSupports?: string[];
|
|
78
|
+
unusedAtRules?: UnusedAtRule[];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface UnusedAtRule {
|
|
82
|
+
selector?: string;
|
|
83
|
+
media?: ConditionProperty;
|
|
84
|
+
supports?: ConditionProperty;
|
|
85
|
+
container?: CssConditionData & Partial<ConditionProperty>;
|
|
86
|
+
layer?: string[];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface DataSource<T = string> extends IDataSource<T>, ElementAction {
|
|
90
|
+
source: "cloud" | "json" | "uri" | "local" | "export" | DbSource;
|
|
91
|
+
element?: XmlTagNode;
|
|
92
|
+
type?: "text" | "attribute" | "display";
|
|
93
|
+
dynamic?: boolean;
|
|
94
|
+
value?: StringOfArray | ObjectMap<unknown>;
|
|
95
|
+
template?: string;
|
|
96
|
+
viewEngine?: ViewEngine | string;
|
|
97
|
+
ignoreEmpty?: boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface TextDataSource extends DataSource {
|
|
101
|
+
type: "text";
|
|
102
|
+
leadingText?: string;
|
|
103
|
+
trailingText?: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface UriDataSource extends DataSource, DataObject {
|
|
107
|
+
source: "uri";
|
|
108
|
+
body?: unknown;
|
|
109
|
+
contentType?: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface LocalDataSource extends DataSource, DataObject {
|
|
113
|
+
source: "local";
|
|
114
|
+
pathname?: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface JSONDataSource extends DataSource, CascadeAction {
|
|
118
|
+
source: "json";
|
|
119
|
+
items?: unknown;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface ExportDataSource extends DataSource, CascadeAction {
|
|
123
|
+
source: "export";
|
|
124
|
+
execute?: FunctionType;
|
|
125
|
+
pathname?: string;
|
|
126
|
+
settings?: string;
|
|
127
|
+
params?: unknown;
|
|
128
|
+
persist?: boolean;
|
|
129
129
|
}
|