@pi-r/chrome 0.11.3 → 0.12.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/extensions/css/remove-unused/index.js +423 -0
- package/index.d.ts +1 -1
- package/index.js +418 -797
- package/package.json +5 -5
- package/types/index.d.ts +40 -11
- package/types/squared.d.ts +2 -1
- package/util.d.ts +20 -0
- package/util.js +49 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Chrome document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.
|
|
24
|
-
"@e-mc/core": "^0.
|
|
25
|
-
"@e-mc/document": "^0.
|
|
26
|
-
"@e-mc/types": "^0.
|
|
23
|
+
"@e-mc/cloud": "^0.14.0",
|
|
24
|
+
"@e-mc/core": "^0.14.0",
|
|
25
|
+
"@e-mc/document": "^0.14.0",
|
|
26
|
+
"@e-mc/types": "^0.14.0",
|
|
27
27
|
"image-size": "^2.0.2"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { LocationUri, XmlTagNode } from '@e-mc/types/lib/squared';
|
|
2
2
|
|
|
3
3
|
import type { DocumentConstructor, ICloud, IDocument, IFileManager } from '@e-mc/types/lib';
|
|
4
|
+
import type { IFileThread } from '@e-mc/types/lib/asset';
|
|
4
5
|
import type { DocumentAsset as IDocumentAsset } from '@e-mc/types/lib/document';
|
|
5
6
|
import type { LogTime } from '@e-mc/types/lib/logger';
|
|
6
7
|
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';
|
|
@@ -17,6 +18,18 @@ export const enum PROPERTIES {
|
|
|
17
18
|
SERVERROOT = '__serverroot__'
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
export const enum MIME {
|
|
22
|
+
HTML = 'text/html',
|
|
23
|
+
JS = 'application/javascript',
|
|
24
|
+
JS_TEXT = 'text/javascript',
|
|
25
|
+
CSS = 'text/css',
|
|
26
|
+
SVG = 'image/svg+xml',
|
|
27
|
+
TTF = 'font/ttf',
|
|
28
|
+
OTF = 'font/otf',
|
|
29
|
+
WOFF = 'font/woff',
|
|
30
|
+
WOFF2 = 'font/woff2'
|
|
31
|
+
}
|
|
32
|
+
|
|
20
33
|
interface DocumentDirectory extends IDocumentDirectory {
|
|
21
34
|
template?: string;
|
|
22
35
|
data?: string;
|
|
@@ -52,18 +65,30 @@ interface ChromeDocumentSettings extends IDocumentSettings<ChromeDocumentUserSet
|
|
|
52
65
|
|
|
53
66
|
type OutputType = "useUnsafeReplace" | "productionRelease" | "productionIncremental" | "serverRootMapping" | "sanitizeFramework" | "templateMap" | "userAgentData";
|
|
54
67
|
|
|
68
|
+
export interface ChromeExtensionOptions<T extends DocumentAsset = DocumentAsset> {
|
|
69
|
+
file?: T;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface ChromeExtensionCssOptions<T extends DocumentAsset = DocumentAsset> extends ChromeExtensionOptions<T> {
|
|
73
|
+
config: UserConfig;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type ChromeExtension<T extends DocumentAsset = DocumentAsset> = (source: string, options: ChromeExtensionOptions<T>) => Promise<string | undefined>;
|
|
77
|
+
export type ChromeExtensionCss<T extends DocumentAsset = DocumentAsset> = (source: string, options: ChromeExtensionCssOptions<T>) => Promise<string | undefined>;
|
|
78
|
+
|
|
55
79
|
export interface FormatUri extends Partial<LocationUri> {
|
|
56
80
|
dictionary?: string;
|
|
57
81
|
}
|
|
58
82
|
|
|
59
|
-
export interface
|
|
83
|
+
export interface DocumentFinalize<T extends IFileManager<U>, U extends DocumentAsset> {
|
|
60
84
|
readonly host: T;
|
|
61
85
|
readonly startTime: LogTime;
|
|
62
|
-
readonly hashed: Set<
|
|
86
|
+
readonly hashed: Set<U>;
|
|
63
87
|
readonly contentMap: StringMap;
|
|
64
88
|
readonly bufferMap: ObjectMap<Bufferable>;
|
|
65
89
|
readonly cacheMiss: string[];
|
|
66
90
|
readonly productionRelease: true | undefined;
|
|
91
|
+
getBuffer(item: U, localUri?: string): Bufferable | null;
|
|
67
92
|
}
|
|
68
93
|
|
|
69
94
|
export interface DocumentComponent<T = boolean> extends IDocumentComponent<T, T>, DocumentComponentExtended<T> {}
|
|
@@ -91,7 +116,7 @@ export interface UserConfig extends CssRuleData, Omit<DocumentOutput, OutputType
|
|
|
91
116
|
useUnsafeCssReplace?: boolean;
|
|
92
117
|
}
|
|
93
118
|
|
|
94
|
-
export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAsset
|
|
119
|
+
export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAsset, V extends ICloud = ICloud<T>> extends IDocument<T, U, DocumentModule, DocumentComponent, DocumentComponentOption, V>, Pick<DocumentOutput, OutputType> {
|
|
95
120
|
htmlFile: U | null;
|
|
96
121
|
cssFiles: U[];
|
|
97
122
|
jsFiles: U[];
|
|
@@ -101,16 +126,20 @@ export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAs
|
|
|
101
126
|
config: UserConfig;
|
|
102
127
|
related: Map<U, Set<U>>;
|
|
103
128
|
replaced: U[];
|
|
129
|
+
assets: U[];
|
|
104
130
|
formatMap?: ObjectMap<FormatUri>;
|
|
131
|
+
using(data: IFileThread): Promise<void>;
|
|
105
132
|
setElementSrc(file: U, element: IXmlElement, value: string): void;
|
|
106
133
|
findDataValue(name: string): string | undefined;
|
|
107
|
-
setInlinedAttributes(processing:
|
|
108
|
-
applyTransforms(processing:
|
|
109
|
-
rewriteHtml(processing:
|
|
110
|
-
setElementAttributes(processing:
|
|
111
|
-
applyDataSource(processing:
|
|
112
|
-
setProductionAttributes(processing:
|
|
113
|
-
|
|
134
|
+
setInlinedAttributes(processing: DocumentFinalize<T, U>): void;
|
|
135
|
+
applyTransforms(processing: DocumentFinalize<T, U>): Promise<void>;
|
|
136
|
+
rewriteHtml(processing: DocumentFinalize<T, U>): Promise<void>;
|
|
137
|
+
setElementAttributes(processing: DocumentFinalize<T, U>, domBase: IDomWriter): Promise<void>;
|
|
138
|
+
applyDataSource(processing: DocumentFinalize<T, U>, domBase: IDomWriter): Promise<void>;
|
|
139
|
+
setProductionAttributes(processing: DocumentFinalize<T, U>): void;
|
|
140
|
+
createHash(processing: DocumentFinalize<T, U>, file: U, hash: string): void;
|
|
141
|
+
transformJs(processing: DocumentFinalize<T, U>, file: U, source: string): Promise<string | undefined>;
|
|
142
|
+
transformCss(processing: DocumentFinalize<T, U>, file: U, source: string): Promise<string | undefined>;
|
|
114
143
|
removeServerRoot(value: string): string;
|
|
115
144
|
replaceContent(source: string, match: RegExpExecArray | string, mimeType?: string): string | undefined;
|
|
116
145
|
cloudInit(state: CloudScopeOrigin<T, U, V>): void;
|
|
@@ -127,7 +156,7 @@ export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAs
|
|
|
127
156
|
get settings(): ChromeDocumentSettings;
|
|
128
157
|
}
|
|
129
158
|
|
|
130
|
-
export interface ChromeDocumentConstructor<T extends IFileManager<U>, U extends DocumentAsset
|
|
159
|
+
export interface ChromeDocumentConstructor<T extends IFileManager<U>, U extends DocumentAsset> extends ConstructorDerived<DocumentConstructor<T, U>> {
|
|
131
160
|
INTERNAL_ASSIGNUUID: string;
|
|
132
161
|
INTERNAL_SERVERROOT: string;
|
|
133
162
|
readonly prototype: IChromeDocument<T, U>;
|
package/types/squared.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ export interface DocumentOutput {
|
|
|
47
47
|
serverRootMapping?: StringMap;
|
|
48
48
|
useOriginalHtmlPage?: boolean | string;
|
|
49
49
|
useUnsafeReplace?: ArrayOf<"html" | "css"> | boolean;
|
|
50
|
+
/** @deprecated */
|
|
50
51
|
useSessionCache?: boolean;
|
|
51
52
|
stripCommentsAndCDATA?: boolean | string;
|
|
52
53
|
normalizeHtmlOutput?: boolean | string;
|
|
@@ -60,7 +61,7 @@ export interface DocumentOutput {
|
|
|
60
61
|
|
|
61
62
|
export interface RequestData extends IRequestData<ChromeAsset>, Readonly<DocumentOutput>, Readonly<CssRuleData> {}
|
|
62
63
|
|
|
63
|
-
export interface ChromeAsset extends FileAsset, AttributeAction, ElementAction, MetadataAction
|
|
64
|
+
export interface ChromeAsset extends FileAsset, AttributeAction, ElementAction, MetadataAction, UploadAction, HashAction, ExcludeAction, ImportAction<ImportFrom[] | boolean>, FromAction, WorkerAction {
|
|
64
65
|
preserve?: boolean;
|
|
65
66
|
static?: boolean;
|
|
66
67
|
editing?: boolean;
|
package/util.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { spliceString, splitEnclosing } from '@e-mc/document/util';
|
|
2
|
+
|
|
3
|
+
interface ReplaceMatchOptions {
|
|
4
|
+
pattern?: RegExp;
|
|
5
|
+
trimLeading?: boolean;
|
|
6
|
+
trimTrailing?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const PATTERN_PARENTHESIS: string;
|
|
10
|
+
|
|
11
|
+
export function replaceMatch(match: RegExpMatchArray, source: string, pattern: RegExp): string;
|
|
12
|
+
export function replaceMatch(match: RegExpMatchArray, source: string, content: number | string, options: ReplaceMatchOptions): string;
|
|
13
|
+
export function replaceMatch(match: RegExpMatchArray, source: string, content?: number | string, pattern?: RegExp): string;
|
|
14
|
+
export function isSpace(ch: string): boolean;
|
|
15
|
+
export function getNewlineString(leading: string, trailing: string, newline?: string): string;
|
|
16
|
+
|
|
17
|
+
export function spliceSource(source: string, startIndex: number, endIndex: number, pattern: RegExp, leading?: string, trailing?: string, content?: string): string;
|
|
18
|
+
export function findClosingIndex<T extends "{" | "(", U extends T extends infer V ? V extends "{" ? [number, string] : number : never>(source: string, lastIndex: number, char: T): U;
|
|
19
|
+
|
|
20
|
+
export { spliceString, splitEnclosing };
|
package/util.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { DomWriter } = require('@e-mc/document/parse/dom');
|
|
4
|
+
const { spliceString, splitEnclosing } = require('@e-mc/document/util');
|
|
5
|
+
const isSpace = DomWriter.isSpace.bind(DomWriter);
|
|
6
|
+
const PATTERN_PARENTHESIS = '(?:,[^()]+(?=\\))|[^()]|\\([^()]*\\(+|\\([^()]*\\)|(?:\\)[^()]+)?\\)*?)+';
|
|
7
|
+
const replaceMatch = DomWriter.replaceMatch.bind(DomWriter);
|
|
8
|
+
const getNewlineString = DomWriter.getNewlineString.bind(DomWriter);
|
|
9
|
+
function spliceSource(source, startIndex, endIndex, pattern, leading = '', trailing = '', content = '') {
|
|
10
|
+
if (leading || trailing) {
|
|
11
|
+
content += getNewlineString(leading, trailing);
|
|
12
|
+
}
|
|
13
|
+
return spliceString(source, startIndex, endIndex, content, pattern);
|
|
14
|
+
}
|
|
15
|
+
function findClosingIndex(source, lastIndex, char) {
|
|
16
|
+
const pattern = char === '{' ? /[{}]/g : /[()]/g;
|
|
17
|
+
pattern.lastIndex = lastIndex;
|
|
18
|
+
let opened = 1, closed = 0, endIndex = -1, trailing = '', match;
|
|
19
|
+
while (match = pattern.exec(source)) {
|
|
20
|
+
if (match[0] === char) {
|
|
21
|
+
++opened;
|
|
22
|
+
}
|
|
23
|
+
else if (++closed === opened) {
|
|
24
|
+
if (char === '(') {
|
|
25
|
+
return match.index;
|
|
26
|
+
}
|
|
27
|
+
endIndex = match.index + 1;
|
|
28
|
+
let ch;
|
|
29
|
+
while (isSpace(ch = source[endIndex])) {
|
|
30
|
+
trailing += ch;
|
|
31
|
+
++endIndex;
|
|
32
|
+
if (ch === '\n') {
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return [endIndex, trailing];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.PATTERN_PARENTHESIS = PATTERN_PARENTHESIS;
|
|
43
|
+
exports.findClosingIndex = findClosingIndex;
|
|
44
|
+
exports.getNewlineString = getNewlineString;
|
|
45
|
+
exports.isSpace = isSpace;
|
|
46
|
+
exports.replaceMatch = replaceMatch;
|
|
47
|
+
exports.spliceSource = spliceSource;
|
|
48
|
+
exports.spliceString = spliceString;
|
|
49
|
+
exports.splitEnclosing = splitEnclosing;
|