@e-mc/document 0.3.2 → 0.4.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.
Files changed (7) hide show
  1. package/asset.js +11 -11
  2. package/index.js +1291 -1291
  3. package/package.json +4 -4
  4. package/parse/dom.js +256 -256
  5. package/parse/index.js +1452 -1452
  6. package/transform/index.js +321 -321
  7. package/util.js +203 -200
@@ -1,321 +1,321 @@
1
- "use strict";
2
- var _a, _b, _c, _d;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.SourceMap = exports.TransformSeries = void 0;
5
- const path = require("path");
6
- const types_1 = require("../../types");
7
- const core_1 = require("../../core");
8
- const kCode = Symbol('code');
9
- const kMap = Symbol('map');
10
- const kOut = Symbol('out');
11
- const kOptions = Symbol('options');
12
- const kSourceMap = Symbol('sourceMap');
13
- const kMetadata = Symbol('metadata');
14
- const kModulesDir = Symbol('modulesDir');
15
- const kUsername = Symbol('username');
16
- const kProductionRelease = Symbol('productionRelease');
17
- function parseMap(data, value) {
18
- let [mimeType, encoding] = data.split(';');
19
- if (!encoding && mimeType.indexOf('/') === -1) {
20
- encoding = mimeType;
21
- }
22
- return encoding.includes('base64') ? Buffer.from(value, 'base64').toString() : value;
23
- }
24
- function toJSON(data) {
25
- try {
26
- const output = JSON.parse(data);
27
- if (SourceMap.isRaw(output)) {
28
- return output;
29
- }
30
- }
31
- catch {
32
- }
33
- }
34
- class Out {
35
- reset() {
36
- this.sourceFiles = undefined;
37
- this.ignoreCache = undefined;
38
- this.messageAppend = undefined;
39
- this.logAppend = undefined;
40
- this.logQueued = undefined;
41
- }
42
- }
43
- class TransformSeries extends core_1.Module {
44
- constructor(type, code, options) {
45
- super();
46
- this.type = type;
47
- this.baseConfig = {};
48
- this.outputConfig = {};
49
- this.supplementChunks = [];
50
- this._threadable = true;
51
- this[_a] = {};
52
- this[_b] = '';
53
- this[_c] = '';
54
- this[kCode] = code;
55
- this[kOut] = new Out();
56
- this[kOptions] = options;
57
- this[kProductionRelease] = !!options.productionRelease;
58
- if (SourceMap.isRaw(options.sourceMap)) {
59
- const series = new SourceMap(code);
60
- series.map = options.sourceMap;
61
- this[kSourceMap] = series;
62
- }
63
- else {
64
- this[kSourceMap] = options.sourceMap instanceof SourceMap ? options.sourceMap : this.createSourceMap(code);
65
- }
66
- if (options.metadata) {
67
- this[kMetadata] = (0, types_1.isPlainObject)(options.metadata) ? { ...options.metadata } : options.metadata;
68
- }
69
- }
70
- reset() {
71
- super.reset();
72
- this.baseConfig = {};
73
- this.outputConfig = {};
74
- this.version = '';
75
- this.packageName = '';
76
- this[kOut].reset();
77
- }
78
- init(instance, dirname) {
79
- if (instance.hasOwnPermission()) {
80
- this.permission = core_1.Permission.clone(instance.permission, true);
81
- }
82
- this.abortable = instance.abortable;
83
- this._moduleName = instance.moduleName + ':transform:' + this.type;
84
- if (dirname) {
85
- this[kModulesDir] = dirname;
86
- }
87
- const host = instance.host;
88
- if (host) {
89
- host.retain(this);
90
- this[kUsername] = host.username;
91
- }
92
- core_1.AbortComponent.attach(instance, this.signal);
93
- return this;
94
- }
95
- createSourceMap(code) {
96
- return new SourceMap(code);
97
- }
98
- getMainFile(code, imports) {
99
- if (typeof this.options.getMainFile === 'function') {
100
- return this.options.getMainFile(code, imports);
101
- }
102
- }
103
- getSourceFiles(imports) {
104
- if (typeof this.options.getSourceFiles === 'function') {
105
- return this.options.getSourceFiles(imports);
106
- }
107
- }
108
- toBaseConfig(all = true) {
109
- const { outputConfig, external } = this;
110
- const baseConfig = this.baseConfig;
111
- if (outputConfig !== baseConfig) {
112
- Object.assign(baseConfig, outputConfig);
113
- }
114
- if (all && external) {
115
- Object.assign(baseConfig, external);
116
- }
117
- return baseConfig;
118
- }
119
- upgrade(context, dirname, name) {
120
- if (this.version === 'latest') {
121
- if (dirname && path.isAbsolute(dirname)) {
122
- const pathname = path.join(dirname, 'node_modules', name || this.packageName);
123
- if (core_1.Module.isPath(pathname)) {
124
- name = pathname;
125
- }
126
- else {
127
- dirname = '';
128
- }
129
- }
130
- try {
131
- return require(name || dirname || this.packageName);
132
- }
133
- catch {
134
- }
135
- }
136
- return context;
137
- }
138
- close(instance) {
139
- core_1.AbortComponent.detach(instance, this.signal);
140
- this.host?.release(this);
141
- }
142
- set code(value) {
143
- this[kCode] = value;
144
- }
145
- get code() {
146
- return this[kCode];
147
- }
148
- get sourceMap() {
149
- return this[kSourceMap];
150
- }
151
- get metadata() {
152
- return this[kMetadata];
153
- }
154
- get out() {
155
- return this[kOut];
156
- }
157
- get options() {
158
- return this[kOptions];
159
- }
160
- get productionRelease() {
161
- return this[kProductionRelease];
162
- }
163
- get imported() {
164
- return !!this.options.imported;
165
- }
166
- get pathname() {
167
- return this.options.pathname;
168
- }
169
- get filename() {
170
- return this.options.filename;
171
- }
172
- get sourceFile() {
173
- return this.options.sourceFile;
174
- }
175
- get sourceName() {
176
- return this.options.sourceName;
177
- }
178
- get sourcesRelativeTo() {
179
- return this.options.sourcesRelativeTo;
180
- }
181
- get mimeType() {
182
- return this.options.mimeType || '';
183
- }
184
- get external() {
185
- return this.options.external;
186
- }
187
- set version(value) {
188
- // @ts-ignore
189
- this.metadata['__version__'] = value;
190
- }
191
- get version() {
192
- // @ts-ignore
193
- return this.metadata['__version__'] || '';
194
- }
195
- set packageName(value) {
196
- // @ts-ignore
197
- this.metadata['__packagename__'] = value;
198
- this.version = 'latest';
199
- }
200
- get packageName() {
201
- // @ts-ignore
202
- return this.metadata['__packagename__'] || '';
203
- }
204
- get packageVersion() {
205
- const packageName = this.packageName;
206
- return packageName ? core_1.Module.getPackageVersion(packageName, this[kModulesDir]) : '0.0.0';
207
- }
208
- set host(value) {
209
- this._host = value;
210
- }
211
- get host() {
212
- return this._host;
213
- }
214
- get username() {
215
- return this[kUsername];
216
- }
217
- }
218
- exports.TransformSeries = TransformSeries;
219
- _a = kMetadata, _b = kModulesDir, _c = kUsername;
220
- class SourceMap {
221
- static findSourceMap(code, uri) {
222
- if (code || (code = uri && core_1.Module.readText(uri))) {
223
- const pattern = this.RE_SOURCE_MAPPING_URL;
224
- pattern.lastIndex = 0;
225
- let match;
226
- while (match = pattern.exec(code)) {
227
- const data = match[3];
228
- let map;
229
- if (data) {
230
- map = toJSON(parseMap(data, match[4]));
231
- }
232
- else if (uri) {
233
- const url = decodeURIComponent(match[4]);
234
- map = toJSON(core_1.Module.readText(path.isAbsolute(url) ? url : path.join(path.dirname(uri), url)));
235
- }
236
- if (map) {
237
- return map;
238
- }
239
- }
240
- }
241
- }
242
- static removeSourceMappingURL(value) {
243
- const pattern = this.RE_SOURCE_MAPPING_URL;
244
- pattern.lastIndex = 0;
245
- const match = pattern.exec(value);
246
- return match ? [value.substring(0, match.index) + value.substring(match.index + match[0].length), (match[3] || '') + match[4], match[3] && toJSON(parseMap(match[3], match[4])) || null] : [value];
247
- }
248
- static isRaw(map) {
249
- return (0, types_1.isObject)(map) && (0, types_1.isString)(map.mappings);
250
- }
251
- constructor(code, uri, remove) {
252
- this.output = new Map();
253
- this.sourceMappingURL = '';
254
- this[_d] = undefined;
255
- if (typeof uri === 'boolean') {
256
- remove = uri;
257
- uri = undefined;
258
- }
259
- let map;
260
- if (remove) {
261
- const items = SourceMap.removeSourceMappingURL(code);
262
- if (map = items[2]) {
263
- code = items[0];
264
- }
265
- }
266
- map || (map = SourceMap.findSourceMap(code, uri));
267
- if (SourceMap.isRaw(map)) {
268
- this.nextMap('unknown', code, map);
269
- }
270
- this[kCode] = code;
271
- this.code = code;
272
- }
273
- reset(restore) {
274
- if (restore) {
275
- this.code = this[kCode];
276
- }
277
- this.map = undefined;
278
- this.sourceMappingURL = '';
279
- this.output.clear();
280
- }
281
- nextMap(name, code, map, sourceMappingURL = '', emptySources) {
282
- if (!SourceMap.isRaw(map)) {
283
- try {
284
- map = JSON.parse(Buffer.isBuffer(map) ? map.toString('utf-8') : map.toString());
285
- }
286
- catch {
287
- }
288
- if (!SourceMap.isRaw(map)) {
289
- return false;
290
- }
291
- }
292
- if (emptySources) {
293
- map.sources = [""];
294
- }
295
- this.code = code;
296
- this.map = map;
297
- if (sourceMappingURL) {
298
- this.sourceMappingURL = sourceMappingURL;
299
- }
300
- let mapName = name, i = 0;
301
- while (this.output.has(mapName)) {
302
- mapName = name + '_' + ++i;
303
- }
304
- this.output.set(mapName, { code, map, sourceMappingURL });
305
- return true;
306
- }
307
- set map(value) {
308
- if (!value) {
309
- this[kMap] = undefined;
310
- }
311
- else if (SourceMap.isRaw(value)) {
312
- this[kMap] = value;
313
- }
314
- }
315
- get map() {
316
- return this[kMap];
317
- }
318
- }
319
- exports.SourceMap = SourceMap;
320
- _d = kMap;
321
- SourceMap.RE_SOURCE_MAPPING_URL = /(?:\r\n|\n)*(?:(\/\/)|(\/\*))\s*[#@][ ]+sourceMappingURL=(data:[^,]+,)?(\S+)\s*(\*\/)?\r?\n?/g;
1
+ "use strict";
2
+ var _a, _b, _c, _d;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.SourceMap = exports.TransformSeries = void 0;
5
+ const path = require("path");
6
+ const types_1 = require("../../types");
7
+ const core_1 = require("../../core");
8
+ const kCode = Symbol('code');
9
+ const kMap = Symbol('map');
10
+ const kOut = Symbol('out');
11
+ const kOptions = Symbol('options');
12
+ const kSourceMap = Symbol('sourceMap');
13
+ const kMetadata = Symbol('metadata');
14
+ const kModulesDir = Symbol('modulesDir');
15
+ const kUsername = Symbol('username');
16
+ const kProductionRelease = Symbol('productionRelease');
17
+ function parseMap(data, value) {
18
+ let [mimeType, encoding] = data.split(';');
19
+ if (!encoding && mimeType.indexOf('/') === -1) {
20
+ encoding = mimeType;
21
+ }
22
+ return encoding.includes('base64') ? Buffer.from(value, 'base64').toString() : value;
23
+ }
24
+ function toJSON(data) {
25
+ try {
26
+ const output = JSON.parse(data);
27
+ if (SourceMap.isRaw(output)) {
28
+ return output;
29
+ }
30
+ }
31
+ catch {
32
+ }
33
+ }
34
+ class Out {
35
+ reset() {
36
+ this.sourceFiles = undefined;
37
+ this.ignoreCache = undefined;
38
+ this.messageAppend = undefined;
39
+ this.logAppend = undefined;
40
+ this.logQueued = undefined;
41
+ }
42
+ }
43
+ class TransformSeries extends core_1.Module {
44
+ constructor(type, code, options) {
45
+ super();
46
+ this.type = type;
47
+ this.baseConfig = {};
48
+ this.outputConfig = {};
49
+ this.supplementChunks = [];
50
+ this._threadable = true;
51
+ this[_a] = {};
52
+ this[_b] = '';
53
+ this[_c] = '';
54
+ this[kCode] = code;
55
+ this[kOut] = new Out();
56
+ this[kOptions] = options;
57
+ this[kProductionRelease] = !!options.productionRelease;
58
+ if (SourceMap.isRaw(options.sourceMap)) {
59
+ const series = new SourceMap(code);
60
+ series.map = options.sourceMap;
61
+ this[kSourceMap] = series;
62
+ }
63
+ else {
64
+ this[kSourceMap] = options.sourceMap instanceof SourceMap ? options.sourceMap : this.createSourceMap(code);
65
+ }
66
+ if (options.metadata) {
67
+ this[kMetadata] = (0, types_1.isPlainObject)(options.metadata) ? { ...options.metadata } : options.metadata;
68
+ }
69
+ }
70
+ reset() {
71
+ super.reset();
72
+ this.baseConfig = {};
73
+ this.outputConfig = {};
74
+ this.version = '';
75
+ this.packageName = '';
76
+ this[kOut].reset();
77
+ }
78
+ init(instance, dirname) {
79
+ if (instance.hasOwnPermission()) {
80
+ this.permission = core_1.Permission.clone(instance.permission, true);
81
+ }
82
+ this.abortable = instance.abortable;
83
+ this._moduleName = instance.moduleName + ':transform:' + this.type;
84
+ if (dirname) {
85
+ this[kModulesDir] = dirname;
86
+ }
87
+ const host = instance.host;
88
+ if (host) {
89
+ host.retain(this);
90
+ this[kUsername] = host.username;
91
+ }
92
+ core_1.AbortComponent.attach(instance, this.signal);
93
+ return this;
94
+ }
95
+ createSourceMap(code) {
96
+ return new SourceMap(code);
97
+ }
98
+ getMainFile(code, imports) {
99
+ if (typeof this.options.getMainFile === 'function') {
100
+ return this.options.getMainFile(code, imports);
101
+ }
102
+ }
103
+ getSourceFiles(imports) {
104
+ if (typeof this.options.getSourceFiles === 'function') {
105
+ return this.options.getSourceFiles(imports);
106
+ }
107
+ }
108
+ toBaseConfig(all = true) {
109
+ const { outputConfig, external } = this;
110
+ const baseConfig = this.baseConfig;
111
+ if (outputConfig !== baseConfig) {
112
+ Object.assign(baseConfig, outputConfig);
113
+ }
114
+ if (all && external) {
115
+ Object.assign(baseConfig, external);
116
+ }
117
+ return baseConfig;
118
+ }
119
+ upgrade(context, dirname, name) {
120
+ if (this.version === 'latest') {
121
+ if (dirname && path.isAbsolute(dirname)) {
122
+ const pathname = path.join(dirname, 'node_modules', name || this.packageName);
123
+ if (core_1.Module.isPath(pathname)) {
124
+ name = pathname;
125
+ }
126
+ else {
127
+ dirname = '';
128
+ }
129
+ }
130
+ try {
131
+ return require(name || dirname || this.packageName);
132
+ }
133
+ catch {
134
+ }
135
+ }
136
+ return context;
137
+ }
138
+ close(instance) {
139
+ core_1.AbortComponent.detach(instance, this.signal);
140
+ this.host?.release(this);
141
+ }
142
+ set code(value) {
143
+ this[kCode] = value;
144
+ }
145
+ get code() {
146
+ return this[kCode];
147
+ }
148
+ get sourceMap() {
149
+ return this[kSourceMap];
150
+ }
151
+ get metadata() {
152
+ return this[kMetadata];
153
+ }
154
+ get out() {
155
+ return this[kOut];
156
+ }
157
+ get options() {
158
+ return this[kOptions];
159
+ }
160
+ get productionRelease() {
161
+ return this[kProductionRelease];
162
+ }
163
+ get imported() {
164
+ return !!this.options.imported;
165
+ }
166
+ get pathname() {
167
+ return this.options.pathname;
168
+ }
169
+ get filename() {
170
+ return this.options.filename;
171
+ }
172
+ get sourceFile() {
173
+ return this.options.sourceFile;
174
+ }
175
+ get sourceName() {
176
+ return this.options.sourceName;
177
+ }
178
+ get sourcesRelativeTo() {
179
+ return this.options.sourcesRelativeTo;
180
+ }
181
+ get mimeType() {
182
+ return this.options.mimeType || '';
183
+ }
184
+ get external() {
185
+ return this.options.external;
186
+ }
187
+ set version(value) {
188
+ // @ts-ignore
189
+ this.metadata['__version__'] = value;
190
+ }
191
+ get version() {
192
+ // @ts-ignore
193
+ return this.metadata['__version__'] || '';
194
+ }
195
+ set packageName(value) {
196
+ // @ts-ignore
197
+ this.metadata['__packagename__'] = value;
198
+ this.version = 'latest';
199
+ }
200
+ get packageName() {
201
+ // @ts-ignore
202
+ return this.metadata['__packagename__'] || '';
203
+ }
204
+ get packageVersion() {
205
+ const packageName = this.packageName;
206
+ return packageName ? core_1.Module.getPackageVersion(packageName, this[kModulesDir]) : '0.0.0';
207
+ }
208
+ set host(value) {
209
+ this._host = value;
210
+ }
211
+ get host() {
212
+ return this._host;
213
+ }
214
+ get username() {
215
+ return this[kUsername];
216
+ }
217
+ }
218
+ exports.TransformSeries = TransformSeries;
219
+ _a = kMetadata, _b = kModulesDir, _c = kUsername;
220
+ class SourceMap {
221
+ static findSourceMap(code, uri) {
222
+ if (code || (code = uri && core_1.Module.readText(uri))) {
223
+ const pattern = this.RE_SOURCE_MAPPING_URL;
224
+ pattern.lastIndex = 0;
225
+ let match;
226
+ while (match = pattern.exec(code)) {
227
+ const data = match[3];
228
+ let map;
229
+ if (data) {
230
+ map = toJSON(parseMap(data, match[4]));
231
+ }
232
+ else if (uri) {
233
+ const url = decodeURIComponent(match[4]);
234
+ map = toJSON(core_1.Module.readText(path.isAbsolute(url) ? url : path.join(path.dirname(uri), url)));
235
+ }
236
+ if (map) {
237
+ return map;
238
+ }
239
+ }
240
+ }
241
+ }
242
+ static removeSourceMappingURL(value) {
243
+ const pattern = this.RE_SOURCE_MAPPING_URL;
244
+ pattern.lastIndex = 0;
245
+ const match = pattern.exec(value);
246
+ return match ? [value.substring(0, match.index) + value.substring(match.index + match[0].length), (match[3] || '') + match[4], match[3] && toJSON(parseMap(match[3], match[4])) || null] : [value];
247
+ }
248
+ static isRaw(map) {
249
+ return (0, types_1.isObject)(map) && (0, types_1.isString)(map.mappings);
250
+ }
251
+ constructor(code, uri, remove) {
252
+ this.output = new Map();
253
+ this.sourceMappingURL = '';
254
+ this[_d] = undefined;
255
+ if (typeof uri === 'boolean') {
256
+ remove = uri;
257
+ uri = undefined;
258
+ }
259
+ let map;
260
+ if (remove) {
261
+ const items = SourceMap.removeSourceMappingURL(code);
262
+ if (map = items[2]) {
263
+ code = items[0];
264
+ }
265
+ }
266
+ map || (map = SourceMap.findSourceMap(code, uri));
267
+ if (SourceMap.isRaw(map)) {
268
+ this.nextMap('unknown', code, map);
269
+ }
270
+ this[kCode] = code;
271
+ this.code = code;
272
+ }
273
+ reset(restore) {
274
+ if (restore) {
275
+ this.code = this[kCode];
276
+ }
277
+ this.map = undefined;
278
+ this.sourceMappingURL = '';
279
+ this.output.clear();
280
+ }
281
+ nextMap(name, code, map, sourceMappingURL = '', emptySources) {
282
+ if (!SourceMap.isRaw(map)) {
283
+ try {
284
+ map = JSON.parse(Buffer.isBuffer(map) ? map.toString('utf-8') : map.toString());
285
+ }
286
+ catch {
287
+ }
288
+ if (!SourceMap.isRaw(map)) {
289
+ return false;
290
+ }
291
+ }
292
+ if (emptySources) {
293
+ map.sources = [""];
294
+ }
295
+ this.code = code;
296
+ this.map = map;
297
+ if (sourceMappingURL) {
298
+ this.sourceMappingURL = sourceMappingURL;
299
+ }
300
+ let mapName = name, i = 0;
301
+ while (this.output.has(mapName)) {
302
+ mapName = name + '_' + ++i;
303
+ }
304
+ this.output.set(mapName, { code, map, sourceMappingURL });
305
+ return true;
306
+ }
307
+ set map(value) {
308
+ if (!value) {
309
+ this[kMap] = undefined;
310
+ }
311
+ else if (SourceMap.isRaw(value)) {
312
+ this[kMap] = value;
313
+ }
314
+ }
315
+ get map() {
316
+ return this[kMap];
317
+ }
318
+ }
319
+ _d = kMap;
320
+ SourceMap.RE_SOURCE_MAPPING_URL = /(?:\r\n|\n)*(?:(\/\/)|(\/\*))\s*[#@][ ]+sourceMappingURL=(data:[^,]+,)?(\S+)\s*(\*\/)?\r?\n?/g;
321
+ exports.SourceMap = SourceMap;