@e-mc/document 0.9.8 → 0.9.10
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 +10 -10
- package/README.md +196 -196
- package/asset.d.ts +7 -7
- package/asset.js +1 -1
- package/index.js +18 -20
- package/package.json +31 -31
- package/parse/dom.d.ts +8 -8
- package/parse/dom.js +2 -2
- package/parse/index.d.ts +8 -8
- package/parse/index.js +18 -23
- package/parse/types/index.d.ts +240 -240
- package/transform/index.js +2 -2
- package/util.d.ts +16 -16
- package/util.js +2 -2
package/LICENSE
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
-
|
|
5
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
-
|
|
7
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
+
|
|
11
11
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,197 +1,197 @@
|
|
|
1
|
-
# @e-mc/document
|
|
2
|
-
|
|
3
|
-
* NodeJS 16
|
|
4
|
-
* ES2020
|
|
5
|
-
|
|
6
|
-
## General Usage
|
|
7
|
-
|
|
8
|
-
* [Read the Docs](https://e-mc.readthedocs.io)
|
|
9
|
-
|
|
10
|
-
## Interface
|
|
11
|
-
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
import type { DataSource, ViewEngine } from "./squared";
|
|
16
|
-
|
|
17
|
-
import type { IFileManager, IScopeOrigin } from "./index";
|
|
18
|
-
import type { ExternalAsset, FileCommand, IFileThread, OutputFinalize } from "./asset";
|
|
19
|
-
import type { HostInitConfig, IClient } from "./core";
|
|
20
|
-
import type { AsSourceFileOptions, ConfigOrTransformer, CustomizeOptions, GenerateLintTableOptions, LintMessage, PluginConfig, SourceCode, SourceInput, SourceMap, SourceMapOptions, TransformAction, TransformCallback, TransformOutput, TransformResult, UpdateGradleOptions } from "./document";
|
|
21
|
-
import type { PostFinalizeCallback } from "./filemanager";
|
|
22
|
-
import type { LogComponent } from "./logger";
|
|
23
|
-
import type { DocumentComponent, DocumentComponentOption, DocumentModule } from "./settings";
|
|
24
|
-
import type { IFileGroup, WatchInitResult } from "./watch";
|
|
25
|
-
|
|
26
|
-
interface IDocument extends IClient<IFileManager, DocumentModule, TransformCallback<IFileManager, ExternalAsset>> {
|
|
27
|
-
Db: IDb | null;
|
|
28
|
-
assets: ExternalAsset[];
|
|
29
|
-
config: Record<string, any>;
|
|
30
|
-
init(assets: ExternalAsset[], config?: HostInitConfig): this;
|
|
31
|
-
customize(options?: CustomizeOptions): void;
|
|
32
|
-
findConfig(data: object, name: string, type?: string): PluginConfig;
|
|
33
|
-
loadConfig(data: object, name: string): ConfigOrTransformer | null | undefined;
|
|
34
|
-
asSourceFile(value: string, cache: boolean): unknown;
|
|
35
|
-
asSourceFile(value: string, options?: AsSourceFileOptions): unknown;
|
|
36
|
-
findVersion(name: string | string[], fallback?: string): string;
|
|
37
|
-
findSourceScope(uri: string, imports: Record<string, unknown>): Record<string, string | undefined>[];
|
|
38
|
-
findSourceRoot(uri: string, imports?: Record<string, string | undefined>): string | undefined;
|
|
39
|
-
resolveDir(name: string, ...paths: string[]): string | undefined;
|
|
40
|
-
locateSourceFiles(file: ExternalAsset, code?: string, bundleContent?: string[]): ((imports?: Record<string, string | undefined>) => SourceInput | undefined);
|
|
41
|
-
resolveSourceFile(file: ExternalAsset): ((code?: string, imports?: Record<string, string | undefined>) => SourceInput<string> | undefined);
|
|
42
|
-
tryParse(source: string, format: string, options?: Record<string | number | symbol, unknown>): unknown;
|
|
43
|
-
forDb(item: DataSource): boolean;
|
|
44
|
-
hasEval(name: string): boolean;
|
|
45
|
-
settingsOf(name: keyof DocumentComponent, option: keyof DocumentComponentOption): unknown;
|
|
46
|
-
parseTemplate(viewEngine: ViewEngine | string, template: string, data: unknown[]): Promise<string | null>;
|
|
47
|
-
transform(type: string, code: string, format: string | string[], options?: TransformOutput & TransformAction): Promise<TransformResult | void>;
|
|
48
|
-
abort(err: Error): void;
|
|
49
|
-
abort(name?: keyof DocumentComponent, reason?: unknown): void;
|
|
50
|
-
restart(): void;
|
|
51
|
-
using?(data: IFileThread): Promise<unknown>;
|
|
52
|
-
setLocalUri?(file: ExternalAsset, replace?: boolean): void;
|
|
53
|
-
resolveUri?(file: ExternalAsset, source: string): string;
|
|
54
|
-
resolveUri?(file: ExternalAsset, source: string, trailing: string): [string, string];
|
|
55
|
-
resolveImports?(file: ExternalAsset, code: string, baseFile?: string | ExternalAsset): string | undefined;
|
|
56
|
-
replaceContent?(source: string, statement: RegExpExecArray | string, mimeType?: string): string | undefined;
|
|
57
|
-
addCopy?(data: FileCommand<ExternalAsset>, saveAs: string, replace?: boolean): string | undefined;
|
|
58
|
-
writeImage?(output: OutputFinalize<ExternalAsset>): boolean;
|
|
59
|
-
cloudInit?(state: IScopeOrigin<IFileManager, ICloud>): void;
|
|
60
|
-
cloudObject?(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset): boolean;
|
|
61
|
-
cloudUpload?(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, url: string, active: boolean): Promise<boolean>;
|
|
62
|
-
cloudFinalize?(state: IScopeOrigin<IFileManager, ICloud>): Promise<unknown[]>;
|
|
63
|
-
watchInit?(watch: IFileGroup<ExternalAsset>, assets: ExternalAsset[], sanitize?: boolean): WatchInitResult | undefined;
|
|
64
|
-
watchModified?(watch: IFileGroup<ExternalAsset>, assets?: ExternalAsset[]): PostFinalizeCallback;
|
|
65
|
-
set dataSource(value: DataSource[]);
|
|
66
|
-
get dataSource(): DataSource[];
|
|
67
|
-
set imports(value);
|
|
68
|
-
get imports(): Record<string, string | undefined>;
|
|
69
|
-
get watching(): boolean;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
interface DocumentConstructor extends ModuleConstructor {
|
|
73
|
-
finalize(this: IFileManager, instance: IDocument): Promise<unknown>;
|
|
74
|
-
createSourceMap(code: string, remove: boolean): SourceMap;
|
|
75
|
-
createSourceMap(code: string, uri?: string, remove?: boolean): SourceMap;
|
|
76
|
-
writeSourceMap(uri: string, data: SourceCode, options?: SourceMapOptions): string | undefined;
|
|
77
|
-
updateGradle(source: string, namespaces: string[], value: string, upgrade: boolean): string;
|
|
78
|
-
updateGradle(source: string, namespaces: string[], value: string, options?: UpdateGradleOptions): string;
|
|
79
|
-
generateLintTable(messages: LintMessage[], options: GenerateLintTableOptions): LogComponent[];
|
|
80
|
-
cleanup?(this: IFileManager, instance: IDocument): Promise<unknown>;
|
|
81
|
-
sanitizeAssets?(assets: ExternalAsset[], exclusions?: ExternalAsset[]): ExternalAsset[];
|
|
82
|
-
readonly prototype: IDocument;
|
|
83
|
-
new(module?: DocumentModule, ...args: unknown[]): IDocument;
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## Settings
|
|
88
|
-
|
|
89
|
-
```typescript
|
|
90
|
-
import type { PermittedDirectories } from "./core";
|
|
91
|
-
import type { DbModule, DbSettings, DocumentComponentOptions, PurgeComponent } from "./settings";
|
|
92
|
-
|
|
93
|
-
interface DocumentModule {
|
|
94
|
-
// handler: "@pi-r/chrome";
|
|
95
|
-
extensions?: string[];
|
|
96
|
-
db?: DbModule<DbSettings>;
|
|
97
|
-
eval?: {
|
|
98
|
-
function?: boolean;
|
|
99
|
-
absolute?: boolean;
|
|
100
|
-
template?: boolean;
|
|
101
|
-
userconfig?: boolean;
|
|
102
|
-
};
|
|
103
|
-
format?: {
|
|
104
|
-
uuid?: {
|
|
105
|
-
dictionary?: string;
|
|
106
|
-
pathname?: string;
|
|
107
|
-
filename?: string;
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
imports?: StringMap;
|
|
111
|
-
settings?: {
|
|
112
|
-
broadcast_id?: string | string[];
|
|
113
|
-
users?: Record<string, {
|
|
114
|
-
extensions?: string[] | null;
|
|
115
|
-
imports?: StringMap;
|
|
116
|
-
imports_strict?: boolean;
|
|
117
|
-
pages?: unknown;
|
|
118
|
-
transform?: unknown;
|
|
119
|
-
view_engine?: unknown;
|
|
120
|
-
}>;
|
|
121
|
-
cache_dir?: string;
|
|
122
|
-
imports_strict?: boolean;
|
|
123
|
-
directory?: {
|
|
124
|
-
template?: string;
|
|
125
|
-
data?: string;
|
|
126
|
-
export?: string;
|
|
127
|
-
schema?: string;
|
|
128
|
-
package?: string;
|
|
129
|
-
};
|
|
130
|
-
purge?: PurgeComponent;
|
|
131
|
-
options?: DocumentComponentOptions<boolean | number>;
|
|
132
|
-
pages?: Record<string, Record<string, unknown>>;
|
|
133
|
-
transform?: {
|
|
134
|
-
html?: Record<string, Record<string, unknown>>;
|
|
135
|
-
css?: Record<string, Record<string, unknown>>;
|
|
136
|
-
js?: Record<string, Record<string, unknown>>;
|
|
137
|
-
};
|
|
138
|
-
view_engine?: Record<string, Record<string, unknown>>;
|
|
139
|
-
export?: Record<string, string | (...args: unknown[]) => unknown>;
|
|
140
|
-
};
|
|
141
|
-
permission?: PermittedDirectories;
|
|
142
|
-
}
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
### Example usage
|
|
146
|
-
|
|
147
|
-
```javascript
|
|
148
|
-
const Document = require("@e-mc/document"); // @pi-r/chrome
|
|
149
|
-
|
|
150
|
-
const assets = [
|
|
151
|
-
{ pathname: "output", filename: "image1.png", uri: "http://hostname/path/document1.png" },
|
|
152
|
-
{ pathname: "output", filename: "image2.png", uri: "http://hostname/path/document2.png" }
|
|
153
|
-
];
|
|
154
|
-
|
|
155
|
-
const instance = new Document({
|
|
156
|
-
eval: {
|
|
157
|
-
function: true,
|
|
158
|
-
template: true
|
|
159
|
-
},
|
|
160
|
-
imports: {
|
|
161
|
-
"http://hostname/path/": "build/"
|
|
162
|
-
},
|
|
163
|
-
settings: {
|
|
164
|
-
imports_strict: true,
|
|
165
|
-
users: {
|
|
166
|
-
"nodejs-001": {
|
|
167
|
-
imports_strict: false,
|
|
168
|
-
imports: {
|
|
169
|
-
"http://hostname/path": "build"
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
directory: {
|
|
174
|
-
template: "../chrome/template" // ../chrome/template/users/nodejs-001
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
// instance.host = new Host();
|
|
179
|
-
instance.init(assets);
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
NOTE: **@e-mc/document** is an abstract base class and cannot be instantiated. **Document** is more commonly called through [@pi-r/chrome](https://www.npmjs.com/package/@pi-r/chrome).
|
|
183
|
-
|
|
184
|
-
## References
|
|
185
|
-
|
|
186
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
187
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
188
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
189
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
190
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
191
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
192
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
193
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
194
|
-
|
|
195
|
-
## LICENSE
|
|
196
|
-
|
|
1
|
+
# @e-mc/document
|
|
2
|
+
|
|
3
|
+
* NodeJS 16
|
|
4
|
+
* ES2020
|
|
5
|
+
|
|
6
|
+
## General Usage
|
|
7
|
+
|
|
8
|
+
* [Read the Docs](https://e-mc.readthedocs.io)
|
|
9
|
+
|
|
10
|
+
## Interface
|
|
11
|
+
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.10/lib/index.d.ts)
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import type { DataSource, ViewEngine } from "./squared";
|
|
16
|
+
|
|
17
|
+
import type { IFileManager, IScopeOrigin } from "./index";
|
|
18
|
+
import type { ExternalAsset, FileCommand, IFileThread, OutputFinalize } from "./asset";
|
|
19
|
+
import type { HostInitConfig, IClient } from "./core";
|
|
20
|
+
import type { AsSourceFileOptions, ConfigOrTransformer, CustomizeOptions, GenerateLintTableOptions, LintMessage, PluginConfig, SourceCode, SourceInput, SourceMap, SourceMapOptions, TransformAction, TransformCallback, TransformOutput, TransformResult, UpdateGradleOptions } from "./document";
|
|
21
|
+
import type { PostFinalizeCallback } from "./filemanager";
|
|
22
|
+
import type { LogComponent } from "./logger";
|
|
23
|
+
import type { DocumentComponent, DocumentComponentOption, DocumentModule } from "./settings";
|
|
24
|
+
import type { IFileGroup, WatchInitResult } from "./watch";
|
|
25
|
+
|
|
26
|
+
interface IDocument extends IClient<IFileManager, DocumentModule, TransformCallback<IFileManager, ExternalAsset>> {
|
|
27
|
+
Db: IDb | null;
|
|
28
|
+
assets: ExternalAsset[];
|
|
29
|
+
config: Record<string, any>;
|
|
30
|
+
init(assets: ExternalAsset[], config?: HostInitConfig): this;
|
|
31
|
+
customize(options?: CustomizeOptions): void;
|
|
32
|
+
findConfig(data: object, name: string, type?: string): PluginConfig;
|
|
33
|
+
loadConfig(data: object, name: string): ConfigOrTransformer | null | undefined;
|
|
34
|
+
asSourceFile(value: string, cache: boolean): unknown;
|
|
35
|
+
asSourceFile(value: string, options?: AsSourceFileOptions): unknown;
|
|
36
|
+
findVersion(name: string | string[], fallback?: string): string;
|
|
37
|
+
findSourceScope(uri: string, imports: Record<string, unknown>): Record<string, string | undefined>[];
|
|
38
|
+
findSourceRoot(uri: string, imports?: Record<string, string | undefined>): string | undefined;
|
|
39
|
+
resolveDir(name: string, ...paths: string[]): string | undefined;
|
|
40
|
+
locateSourceFiles(file: ExternalAsset, code?: string, bundleContent?: string[]): ((imports?: Record<string, string | undefined>) => SourceInput | undefined);
|
|
41
|
+
resolveSourceFile(file: ExternalAsset): ((code?: string, imports?: Record<string, string | undefined>) => SourceInput<string> | undefined);
|
|
42
|
+
tryParse(source: string, format: string, options?: Record<string | number | symbol, unknown>): unknown;
|
|
43
|
+
forDb(item: DataSource): boolean;
|
|
44
|
+
hasEval(name: string): boolean;
|
|
45
|
+
settingsOf(name: keyof DocumentComponent, option: keyof DocumentComponentOption): unknown;
|
|
46
|
+
parseTemplate(viewEngine: ViewEngine | string, template: string, data: unknown[]): Promise<string | null>;
|
|
47
|
+
transform(type: string, code: string, format: string | string[], options?: TransformOutput & TransformAction): Promise<TransformResult | void>;
|
|
48
|
+
abort(err: Error): void;
|
|
49
|
+
abort(name?: keyof DocumentComponent, reason?: unknown): void;
|
|
50
|
+
restart(): void;
|
|
51
|
+
using?(data: IFileThread): Promise<unknown>;
|
|
52
|
+
setLocalUri?(file: ExternalAsset, replace?: boolean): void;
|
|
53
|
+
resolveUri?(file: ExternalAsset, source: string): string;
|
|
54
|
+
resolveUri?(file: ExternalAsset, source: string, trailing: string): [string, string];
|
|
55
|
+
resolveImports?(file: ExternalAsset, code: string, baseFile?: string | ExternalAsset): string | undefined;
|
|
56
|
+
replaceContent?(source: string, statement: RegExpExecArray | string, mimeType?: string): string | undefined;
|
|
57
|
+
addCopy?(data: FileCommand<ExternalAsset>, saveAs: string, replace?: boolean): string | undefined;
|
|
58
|
+
writeImage?(output: OutputFinalize<ExternalAsset>): boolean;
|
|
59
|
+
cloudInit?(state: IScopeOrigin<IFileManager, ICloud>): void;
|
|
60
|
+
cloudObject?(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset): boolean;
|
|
61
|
+
cloudUpload?(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, url: string, active: boolean): Promise<boolean>;
|
|
62
|
+
cloudFinalize?(state: IScopeOrigin<IFileManager, ICloud>): Promise<unknown[]>;
|
|
63
|
+
watchInit?(watch: IFileGroup<ExternalAsset>, assets: ExternalAsset[], sanitize?: boolean): WatchInitResult | undefined;
|
|
64
|
+
watchModified?(watch: IFileGroup<ExternalAsset>, assets?: ExternalAsset[]): PostFinalizeCallback;
|
|
65
|
+
set dataSource(value: DataSource[]);
|
|
66
|
+
get dataSource(): DataSource[];
|
|
67
|
+
set imports(value);
|
|
68
|
+
get imports(): Record<string, string | undefined>;
|
|
69
|
+
get watching(): boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface DocumentConstructor extends ModuleConstructor {
|
|
73
|
+
finalize(this: IFileManager, instance: IDocument): Promise<unknown>;
|
|
74
|
+
createSourceMap(code: string, remove: boolean): SourceMap;
|
|
75
|
+
createSourceMap(code: string, uri?: string, remove?: boolean): SourceMap;
|
|
76
|
+
writeSourceMap(uri: string, data: SourceCode, options?: SourceMapOptions): string | undefined;
|
|
77
|
+
updateGradle(source: string, namespaces: string[], value: string, upgrade: boolean): string;
|
|
78
|
+
updateGradle(source: string, namespaces: string[], value: string, options?: UpdateGradleOptions): string;
|
|
79
|
+
generateLintTable(messages: LintMessage[], options: GenerateLintTableOptions): LogComponent[];
|
|
80
|
+
cleanup?(this: IFileManager, instance: IDocument): Promise<unknown>;
|
|
81
|
+
sanitizeAssets?(assets: ExternalAsset[], exclusions?: ExternalAsset[]): ExternalAsset[];
|
|
82
|
+
readonly prototype: IDocument;
|
|
83
|
+
new(module?: DocumentModule, ...args: unknown[]): IDocument;
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Settings
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import type { PermittedDirectories } from "./core";
|
|
91
|
+
import type { DbModule, DbSettings, DocumentComponentOptions, PurgeComponent } from "./settings";
|
|
92
|
+
|
|
93
|
+
interface DocumentModule {
|
|
94
|
+
// handler: "@pi-r/chrome";
|
|
95
|
+
extensions?: string[];
|
|
96
|
+
db?: DbModule<DbSettings>;
|
|
97
|
+
eval?: {
|
|
98
|
+
function?: boolean;
|
|
99
|
+
absolute?: boolean;
|
|
100
|
+
template?: boolean;
|
|
101
|
+
userconfig?: boolean;
|
|
102
|
+
};
|
|
103
|
+
format?: {
|
|
104
|
+
uuid?: {
|
|
105
|
+
dictionary?: string;
|
|
106
|
+
pathname?: string;
|
|
107
|
+
filename?: string;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
imports?: StringMap;
|
|
111
|
+
settings?: {
|
|
112
|
+
broadcast_id?: string | string[];
|
|
113
|
+
users?: Record<string, {
|
|
114
|
+
extensions?: string[] | null;
|
|
115
|
+
imports?: StringMap;
|
|
116
|
+
imports_strict?: boolean;
|
|
117
|
+
pages?: unknown;
|
|
118
|
+
transform?: unknown;
|
|
119
|
+
view_engine?: unknown;
|
|
120
|
+
}>;
|
|
121
|
+
cache_dir?: string;
|
|
122
|
+
imports_strict?: boolean;
|
|
123
|
+
directory?: {
|
|
124
|
+
template?: string;
|
|
125
|
+
data?: string;
|
|
126
|
+
export?: string;
|
|
127
|
+
schema?: string;
|
|
128
|
+
package?: string;
|
|
129
|
+
};
|
|
130
|
+
purge?: PurgeComponent;
|
|
131
|
+
options?: DocumentComponentOptions<boolean | number>;
|
|
132
|
+
pages?: Record<string, Record<string, unknown>>;
|
|
133
|
+
transform?: {
|
|
134
|
+
html?: Record<string, Record<string, unknown>>;
|
|
135
|
+
css?: Record<string, Record<string, unknown>>;
|
|
136
|
+
js?: Record<string, Record<string, unknown>>;
|
|
137
|
+
};
|
|
138
|
+
view_engine?: Record<string, Record<string, unknown>>;
|
|
139
|
+
export?: Record<string, string | (...args: unknown[]) => unknown>;
|
|
140
|
+
};
|
|
141
|
+
permission?: PermittedDirectories;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Example usage
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
const Document = require("@e-mc/document"); // @pi-r/chrome
|
|
149
|
+
|
|
150
|
+
const assets = [
|
|
151
|
+
{ pathname: "output", filename: "image1.png", uri: "http://hostname/path/document1.png" },
|
|
152
|
+
{ pathname: "output", filename: "image2.png", uri: "http://hostname/path/document2.png" }
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
const instance = new Document({
|
|
156
|
+
eval: {
|
|
157
|
+
function: true,
|
|
158
|
+
template: true
|
|
159
|
+
},
|
|
160
|
+
imports: {
|
|
161
|
+
"http://hostname/path/": "build/"
|
|
162
|
+
},
|
|
163
|
+
settings: {
|
|
164
|
+
imports_strict: true,
|
|
165
|
+
users: {
|
|
166
|
+
"nodejs-001": {
|
|
167
|
+
imports_strict: false,
|
|
168
|
+
imports: {
|
|
169
|
+
"http://hostname/path": "build"
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
directory: {
|
|
174
|
+
template: "../chrome/template" // ../chrome/template/users/nodejs-001
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
// instance.host = new Host();
|
|
179
|
+
instance.init(assets);
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
NOTE: **@e-mc/document** is an abstract base class and cannot be instantiated. **Document** is more commonly called through [@pi-r/chrome](https://www.npmjs.com/package/@pi-r/chrome).
|
|
183
|
+
|
|
184
|
+
## References
|
|
185
|
+
|
|
186
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/squared.d.ts
|
|
187
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/asset.d.ts
|
|
188
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/core.d.ts
|
|
189
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/document.d.ts
|
|
190
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/filemanager.d.ts
|
|
191
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/logger.d.ts
|
|
192
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/settings.d.ts
|
|
193
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/watch.d.ts
|
|
194
|
+
|
|
195
|
+
## LICENSE
|
|
196
|
+
|
|
197
197
|
BSD 3-Clause
|
package/asset.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ExternalAsset, InitialValue } from '../types/lib/asset';
|
|
2
|
-
|
|
3
|
-
declare namespace asset {
|
|
4
|
-
function isEqual(item: ExternalAsset, other: ExternalAsset): boolean;
|
|
5
|
-
function setInitialValue(file: ExternalAsset, cacheable?: boolean): InitialValue;
|
|
6
|
-
}
|
|
7
|
-
|
|
1
|
+
import type { ExternalAsset, InitialValue } from '../types/lib/asset';
|
|
2
|
+
|
|
3
|
+
declare namespace asset {
|
|
4
|
+
function isEqual(item: ExternalAsset, other: ExternalAsset): boolean;
|
|
5
|
+
function setInitialValue(file: ExternalAsset, cacheable?: boolean): InitialValue;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
8
|
export = asset;
|
package/asset.js
CHANGED
|
@@ -5,6 +5,6 @@ function isEqual(item, other) {
|
|
|
5
5
|
}
|
|
6
6
|
exports.isEqual = isEqual;
|
|
7
7
|
function setInitialValue(file, cacheable = true) {
|
|
8
|
-
return file.initialValue
|
|
8
|
+
return file.initialValue ||= { pathname: file.pathname, filename: file.filename, mimeType: file.mimeType, localUri: file.localUri, inlineFilename: file.inlineFilename, cacheable };
|
|
9
9
|
}
|
|
10
10
|
exports.setInitialValue = setInitialValue;
|
package/index.js
CHANGED
|
@@ -158,7 +158,7 @@ class Document extends core_1.Client {
|
|
|
158
158
|
if (options) {
|
|
159
159
|
({ file, sourceRoot, sourceMappingURL, hash, inlineMap, emptySources, mimeType } = options);
|
|
160
160
|
}
|
|
161
|
-
file
|
|
161
|
+
file ||= path.basename(uri);
|
|
162
162
|
map.file = file;
|
|
163
163
|
if (sourceRoot) {
|
|
164
164
|
map.sourceRoot = sourceRoot;
|
|
@@ -251,7 +251,7 @@ class Document extends core_1.Client {
|
|
|
251
251
|
++i;
|
|
252
252
|
}
|
|
253
253
|
const newline = (0, util_1.getNewline)(source);
|
|
254
|
-
ident
|
|
254
|
+
ident ||= (0, util_1.getIndent)(source);
|
|
255
255
|
if (i === length) {
|
|
256
256
|
const sanitizeValue = (segment) => segment.replace(/["'()]/g, '').trim();
|
|
257
257
|
const pattern = new RegExp(`\\b${(0, types_1.escapePattern)(local[1])}\\b` + (local[2] ? '\\s*=\\s*' : '\\s*') + `("[^"]+"|'[^']+'|\\([^)]+\\)|[^\\s]+)?` + (addendum ? '[^\\r\\n]*' : '[^\\w\\r\\n]*'), 'g');
|
|
@@ -367,7 +367,6 @@ class Document extends core_1.Client {
|
|
|
367
367
|
}
|
|
368
368
|
restart() { }
|
|
369
369
|
init(assets, config) {
|
|
370
|
-
var _a;
|
|
371
370
|
let ignoreModules, ignoreExtensions;
|
|
372
371
|
if (config) {
|
|
373
372
|
let baseUrl;
|
|
@@ -427,7 +426,7 @@ class Document extends core_1.Client {
|
|
|
427
426
|
}
|
|
428
427
|
}
|
|
429
428
|
if (this.dataSource.length && !ignoreModules?.includes('db')) {
|
|
430
|
-
const db =
|
|
429
|
+
const db = this.module.db ||= {};
|
|
431
430
|
const handler = db.handler;
|
|
432
431
|
const database = this.dataSource.filter(this.forDb.bind(this));
|
|
433
432
|
let instance;
|
|
@@ -482,7 +481,7 @@ class Document extends core_1.Client {
|
|
|
482
481
|
}
|
|
483
482
|
abort(name, reason) {
|
|
484
483
|
if (name instanceof Error) {
|
|
485
|
-
reason
|
|
484
|
+
reason ||= name;
|
|
486
485
|
}
|
|
487
486
|
if (this.aborted || (0, types_1.isString)(name) && this.settingsOf(name, 'abort') !== true) {
|
|
488
487
|
return;
|
|
@@ -492,7 +491,7 @@ class Document extends core_1.Client {
|
|
|
492
491
|
customize(options) {
|
|
493
492
|
const transform = options.transform;
|
|
494
493
|
if (transform) {
|
|
495
|
-
const config = this._transformConfig
|
|
494
|
+
const config = this._transformConfig ||= { algorithm: undefined, etag: false, expires: 0, renew: false, limit: Infinity, exclude: {}, include: {} };
|
|
496
495
|
let enabled, algorithm, etag, expires, renew, limit, exclude, include;
|
|
497
496
|
if (transform === true || transform === 'etag') {
|
|
498
497
|
etag = true;
|
|
@@ -839,7 +838,7 @@ class Document extends core_1.Client {
|
|
|
839
838
|
if (item.bundleIndex === 0) {
|
|
840
839
|
const localUri = item.localUri;
|
|
841
840
|
try {
|
|
842
|
-
source = fs.readFileSync(localUri, file.encoding
|
|
841
|
+
source = fs.readFileSync(localUri, file.encoding ||= 'utf-8');
|
|
843
842
|
if (this.resolveUri && (0, types_1.isArray)(file.trailingContent)) {
|
|
844
843
|
let trailing;
|
|
845
844
|
[source, trailing] = this.resolveUri(file, source, (0, util_1.concatString)(file.trailingContent));
|
|
@@ -967,7 +966,7 @@ class Document extends core_1.Client {
|
|
|
967
966
|
}
|
|
968
967
|
}
|
|
969
968
|
const username = this.host?.username || '';
|
|
970
|
-
const cache = CACHE_TEMPLATE[name]
|
|
969
|
+
const cache = CACHE_TEMPLATE[name] ||= {};
|
|
971
970
|
const cacheKey = username + core_1.Client.asHash(template + (compile ? core_1.Client.asString(compile) : ''));
|
|
972
971
|
let result = '', render, valid;
|
|
973
972
|
if (!(render = cache[cacheKey])) {
|
|
@@ -979,7 +978,7 @@ class Document extends core_1.Client {
|
|
|
979
978
|
}
|
|
980
979
|
for (let i = 0, j = 0, row; i < length; ++i) {
|
|
981
980
|
if ((0, types_1.isPlainObject)(row = data[i])) {
|
|
982
|
-
row.__index__
|
|
981
|
+
row.__index__ ??= ++j;
|
|
983
982
|
if (output) {
|
|
984
983
|
row = { ...output, ...row };
|
|
985
984
|
}
|
|
@@ -1005,7 +1004,6 @@ class Document extends core_1.Client {
|
|
|
1005
1004
|
return null;
|
|
1006
1005
|
}
|
|
1007
1006
|
async transform(type, code, format, options = {}) {
|
|
1008
|
-
var _a, _b, _c;
|
|
1009
1007
|
let transform = this.settings.transform, data;
|
|
1010
1008
|
if (!(transform && (0, types_1.isObject)(data = transform[type]))) {
|
|
1011
1009
|
return;
|
|
@@ -1023,7 +1021,7 @@ class Document extends core_1.Client {
|
|
|
1023
1021
|
let result, cacheName;
|
|
1024
1022
|
formatKey = type + '_' + format + '_' + encoding + (username ? '_' + username : '') + core_1.Client.asString(options.external) + core_1.Client.asString(options.metadata);
|
|
1025
1023
|
if (config.etag && etag && uri) {
|
|
1026
|
-
const etagMap = CACHE_ETAG[
|
|
1024
|
+
const etagMap = CACHE_ETAG[this.moduleName] ||= {};
|
|
1027
1025
|
const stored = etagMap[uri];
|
|
1028
1026
|
if (stored) {
|
|
1029
1027
|
if (stored.etag !== etag) {
|
|
@@ -1039,7 +1037,7 @@ class Document extends core_1.Client {
|
|
|
1039
1037
|
if (algorithm) {
|
|
1040
1038
|
const limit = config.limit;
|
|
1041
1039
|
if ((limit === Infinity || limit > 0 && Buffer.byteLength(code, encoding) <= limit) && (hashKey = core_1.Client.asHash(code, { algorithm, encoding }))) {
|
|
1042
|
-
const hashMap = CACHE_HASH[
|
|
1040
|
+
const hashMap = CACHE_HASH[this.moduleName] ||= {};
|
|
1043
1041
|
const stored = hashMap[hashKey];
|
|
1044
1042
|
if (stored && (result = getTransformData(stored, formatKey, encoding))) {
|
|
1045
1043
|
resetTransform(config, hashMap, hashKey, stored);
|
|
@@ -1051,7 +1049,7 @@ class Document extends core_1.Client {
|
|
|
1051
1049
|
}
|
|
1052
1050
|
}
|
|
1053
1051
|
else if (uri) {
|
|
1054
|
-
const codeMap = CACHE_CODE[
|
|
1052
|
+
const codeMap = CACHE_CODE[this.moduleName] ||= {};
|
|
1055
1053
|
const stored = codeMap[uri];
|
|
1056
1054
|
if (stored) {
|
|
1057
1055
|
if (stored.code !== code) {
|
|
@@ -1075,7 +1073,7 @@ class Document extends core_1.Client {
|
|
|
1075
1073
|
if (cacheData) {
|
|
1076
1074
|
delete options.cacheData;
|
|
1077
1075
|
}
|
|
1078
|
-
const imports = transform.imports
|
|
1076
|
+
const imports = transform.imports ||= {};
|
|
1079
1077
|
const series = new transform_1.TransformSeries(type, code, options);
|
|
1080
1078
|
series.init(this, __dirname);
|
|
1081
1079
|
let valid, excluded, userData, userImports, ignoreCache, storedLog, sourceFiles;
|
|
@@ -1122,7 +1120,7 @@ class Document extends core_1.Client {
|
|
|
1122
1120
|
if (!baseSettings) {
|
|
1123
1121
|
excluded = !hasTransformType(config, type, name, cacheData);
|
|
1124
1122
|
}
|
|
1125
|
-
outputConfig
|
|
1123
|
+
outputConfig ||= {};
|
|
1126
1124
|
if (plugin && baseConfig) {
|
|
1127
1125
|
series.outputConfig = outputConfig;
|
|
1128
1126
|
const source = series.code;
|
|
@@ -1157,12 +1155,12 @@ class Document extends core_1.Client {
|
|
|
1157
1155
|
}
|
|
1158
1156
|
if ((0, types_1.isArray)(out.logAppend)) {
|
|
1159
1157
|
out.logAppend.forEach(log => this.addLog(log));
|
|
1160
|
-
(storedLog
|
|
1158
|
+
(storedLog ||= []).push(...out.logAppend);
|
|
1161
1159
|
bypassLog = true;
|
|
1162
1160
|
}
|
|
1163
1161
|
if ((0, types_1.isArray)(out.logQueued)) {
|
|
1164
1162
|
out.logQueued.forEach(log => this.writeLog(log, true));
|
|
1165
|
-
(storedLog
|
|
1163
|
+
(storedLog ||= []).push(...out.logQueued);
|
|
1166
1164
|
bypassLog = true;
|
|
1167
1165
|
}
|
|
1168
1166
|
if (i < length - 1) {
|
|
@@ -1218,7 +1216,7 @@ class Document extends core_1.Client {
|
|
|
1218
1216
|
context = this;
|
|
1219
1217
|
}
|
|
1220
1218
|
if (typeof transformer !== 'function') {
|
|
1221
|
-
transformer
|
|
1219
|
+
transformer &&= transformer.default;
|
|
1222
1220
|
if (typeof transformer !== 'function') {
|
|
1223
1221
|
throw (0, types_1.errorMessage)(plugin, pkg || name, 'Invalid function');
|
|
1224
1222
|
}
|
|
@@ -1329,7 +1327,7 @@ class Document extends core_1.Client {
|
|
|
1329
1327
|
get assets() {
|
|
1330
1328
|
if (this.host) {
|
|
1331
1329
|
try {
|
|
1332
|
-
return this._assets
|
|
1330
|
+
return this._assets ||= this.host.getDocumentAssets(this);
|
|
1333
1331
|
}
|
|
1334
1332
|
catch {
|
|
1335
1333
|
}
|
|
@@ -1342,7 +1340,7 @@ class Document extends core_1.Client {
|
|
|
1342
1340
|
get dataSource() {
|
|
1343
1341
|
if (this.host) {
|
|
1344
1342
|
try {
|
|
1345
|
-
return this._dataSource
|
|
1343
|
+
return this._dataSource ||= this.host.getDataSourceItems(this);
|
|
1346
1344
|
}
|
|
1347
1345
|
catch {
|
|
1348
1346
|
}
|