@u1f992/pdfdiff 0.2.2 → 0.3.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/.clang-format +3 -0
- package/LICENSE +68 -81
- package/dist/browser.js +239 -3109
- package/dist/browser.js.map +1 -1
- package/dist/cli-png-worker.d.ts.map +1 -1
- package/dist/cli-png-worker.js +0 -16
- package/dist/cli-png-worker.js.map +1 -1
- package/dist/cli.js +240 -3150
- package/dist/cli.js.map +1 -1
- package/dist/core.wasm +0 -0
- package/dist/decode.d.ts +9 -0
- package/dist/decode.d.ts.map +1 -0
- package/dist/diff.d.ts.map +1 -1
- package/dist/gs-wasm/gs.js +5821 -0
- package/dist/gs-wasm/gs.wasm +0 -0
- package/dist/gs-wasm/index.js +120 -0
- package/dist/gs-wasm/index.js.map +1 -0
- package/dist/gs-wasm/worker.js +764 -0
- package/dist/gs-wasm/worker.js.map +1 -0
- package/dist/image.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.html +1 -1
- package/dist/index.js +238 -3109
- package/dist/index.js.map +1 -1
- package/dist/iterable.d.ts.map +1 -1
- package/dist/jimp.d.ts +23 -1
- package/dist/jimp.d.ts.map +1 -1
- package/dist/pdf.d.ts +15 -4
- package/dist/pdf.d.ts.map +1 -1
- package/dist/perf.d.ts.map +1 -1
- package/dist/rgba-color.d.ts.map +1 -1
- package/dist/transferable.d.ts +6 -2
- package/dist/transferable.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/worker.d.ts +6 -8
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +70 -3311
- package/dist/worker.js.map +1 -1
- package/package.json +9 -4
- package/rollup.config.js +63 -5
- package/scripts/build-wasm.sh +32 -0
- package/src/browser.ts +9 -6
- package/src/cli-png-worker.ts +0 -17
- package/src/cli.ts +9 -23
- package/src/decode.ts +15 -0
- package/src/diff.ts +0 -17
- package/src/image.ts +1 -18
- package/src/index.html +1 -1
- package/src/index.test.ts +10 -18
- package/src/index.ts +163 -74
- package/src/iterable.test.ts +0 -17
- package/src/iterable.ts +0 -17
- package/src/jimp.ts +25 -7
- package/src/pdf.ts +98 -69
- package/src/perf.ts +0 -17
- package/src/rgba-color.test.ts +0 -17
- package/src/rgba-color.ts +0 -17
- package/src/transferable.ts +6 -21
- package/src/worker.ts +91 -87
- package/wasm/Makefile +34 -0
- package/wasm/bindings.cpp +76 -0
- package/wasm/core.c +176 -0
- package/wasm/core.h +69 -0
- package/dist/mupdf-wasm.wasm +0 -0
|
@@ -0,0 +1,764 @@
|
|
|
1
|
+
import Module from './gs.js';
|
|
2
|
+
|
|
3
|
+
function _mergeNamespaces(n, m) {
|
|
4
|
+
m.forEach(function (e) {
|
|
5
|
+
e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
|
|
6
|
+
if (k !== 'default' && !(k in n)) {
|
|
7
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
8
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return e[k]; }
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
return Object.freeze(n);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const STATUS_INPUT_REQUESTED = 1;
|
|
19
|
+
const STATUS_DATA_READY = 2;
|
|
20
|
+
const STATUS_FLUSH = 3;
|
|
21
|
+
|
|
22
|
+
function getDefaultExportFromCjs (x) {
|
|
23
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var pathBrowserify;
|
|
27
|
+
var hasRequiredPathBrowserify;
|
|
28
|
+
|
|
29
|
+
function requirePathBrowserify () {
|
|
30
|
+
if (hasRequiredPathBrowserify) return pathBrowserify;
|
|
31
|
+
hasRequiredPathBrowserify = 1;
|
|
32
|
+
|
|
33
|
+
function assertPath(path) {
|
|
34
|
+
if (typeof path !== 'string') {
|
|
35
|
+
throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Resolves . and .. elements in a path with directory names
|
|
40
|
+
function normalizeStringPosix(path, allowAboveRoot) {
|
|
41
|
+
var res = '';
|
|
42
|
+
var lastSegmentLength = 0;
|
|
43
|
+
var lastSlash = -1;
|
|
44
|
+
var dots = 0;
|
|
45
|
+
var code;
|
|
46
|
+
for (var i = 0; i <= path.length; ++i) {
|
|
47
|
+
if (i < path.length)
|
|
48
|
+
code = path.charCodeAt(i);
|
|
49
|
+
else if (code === 47 /*/*/)
|
|
50
|
+
break;
|
|
51
|
+
else
|
|
52
|
+
code = 47 /*/*/;
|
|
53
|
+
if (code === 47 /*/*/) {
|
|
54
|
+
if (lastSlash === i - 1 || dots === 1) ; else if (lastSlash !== i - 1 && dots === 2) {
|
|
55
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
|
|
56
|
+
if (res.length > 2) {
|
|
57
|
+
var lastSlashIndex = res.lastIndexOf('/');
|
|
58
|
+
if (lastSlashIndex !== res.length - 1) {
|
|
59
|
+
if (lastSlashIndex === -1) {
|
|
60
|
+
res = '';
|
|
61
|
+
lastSegmentLength = 0;
|
|
62
|
+
} else {
|
|
63
|
+
res = res.slice(0, lastSlashIndex);
|
|
64
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
|
|
65
|
+
}
|
|
66
|
+
lastSlash = i;
|
|
67
|
+
dots = 0;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
} else if (res.length === 2 || res.length === 1) {
|
|
71
|
+
res = '';
|
|
72
|
+
lastSegmentLength = 0;
|
|
73
|
+
lastSlash = i;
|
|
74
|
+
dots = 0;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (allowAboveRoot) {
|
|
79
|
+
if (res.length > 0)
|
|
80
|
+
res += '/..';
|
|
81
|
+
else
|
|
82
|
+
res = '..';
|
|
83
|
+
lastSegmentLength = 2;
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
if (res.length > 0)
|
|
87
|
+
res += '/' + path.slice(lastSlash + 1, i);
|
|
88
|
+
else
|
|
89
|
+
res = path.slice(lastSlash + 1, i);
|
|
90
|
+
lastSegmentLength = i - lastSlash - 1;
|
|
91
|
+
}
|
|
92
|
+
lastSlash = i;
|
|
93
|
+
dots = 0;
|
|
94
|
+
} else if (code === 46 /*.*/ && dots !== -1) {
|
|
95
|
+
++dots;
|
|
96
|
+
} else {
|
|
97
|
+
dots = -1;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return res;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function _format(sep, pathObject) {
|
|
104
|
+
var dir = pathObject.dir || pathObject.root;
|
|
105
|
+
var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
|
|
106
|
+
if (!dir) {
|
|
107
|
+
return base;
|
|
108
|
+
}
|
|
109
|
+
if (dir === pathObject.root) {
|
|
110
|
+
return dir + base;
|
|
111
|
+
}
|
|
112
|
+
return dir + sep + base;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
var posix = {
|
|
116
|
+
// path.resolve([from ...], to)
|
|
117
|
+
resolve: function resolve() {
|
|
118
|
+
var resolvedPath = '';
|
|
119
|
+
var resolvedAbsolute = false;
|
|
120
|
+
var cwd;
|
|
121
|
+
|
|
122
|
+
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
123
|
+
var path;
|
|
124
|
+
if (i >= 0)
|
|
125
|
+
path = arguments[i];
|
|
126
|
+
else {
|
|
127
|
+
if (cwd === undefined)
|
|
128
|
+
cwd = process.cwd();
|
|
129
|
+
path = cwd;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
assertPath(path);
|
|
133
|
+
|
|
134
|
+
// Skip empty entries
|
|
135
|
+
if (path.length === 0) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
resolvedPath = path + '/' + resolvedPath;
|
|
140
|
+
resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// At this point the path should be resolved to a full absolute path, but
|
|
144
|
+
// handle relative paths to be safe (might happen when process.cwd() fails)
|
|
145
|
+
|
|
146
|
+
// Normalize the path
|
|
147
|
+
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
|
|
148
|
+
|
|
149
|
+
if (resolvedAbsolute) {
|
|
150
|
+
if (resolvedPath.length > 0)
|
|
151
|
+
return '/' + resolvedPath;
|
|
152
|
+
else
|
|
153
|
+
return '/';
|
|
154
|
+
} else if (resolvedPath.length > 0) {
|
|
155
|
+
return resolvedPath;
|
|
156
|
+
} else {
|
|
157
|
+
return '.';
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
normalize: function normalize(path) {
|
|
162
|
+
assertPath(path);
|
|
163
|
+
|
|
164
|
+
if (path.length === 0) return '.';
|
|
165
|
+
|
|
166
|
+
var isAbsolute = path.charCodeAt(0) === 47 /*/*/;
|
|
167
|
+
var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/;
|
|
168
|
+
|
|
169
|
+
// Normalize the path
|
|
170
|
+
path = normalizeStringPosix(path, !isAbsolute);
|
|
171
|
+
|
|
172
|
+
if (path.length === 0 && !isAbsolute) path = '.';
|
|
173
|
+
if (path.length > 0 && trailingSeparator) path += '/';
|
|
174
|
+
|
|
175
|
+
if (isAbsolute) return '/' + path;
|
|
176
|
+
return path;
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
isAbsolute: function isAbsolute(path) {
|
|
180
|
+
assertPath(path);
|
|
181
|
+
return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
join: function join() {
|
|
185
|
+
if (arguments.length === 0)
|
|
186
|
+
return '.';
|
|
187
|
+
var joined;
|
|
188
|
+
for (var i = 0; i < arguments.length; ++i) {
|
|
189
|
+
var arg = arguments[i];
|
|
190
|
+
assertPath(arg);
|
|
191
|
+
if (arg.length > 0) {
|
|
192
|
+
if (joined === undefined)
|
|
193
|
+
joined = arg;
|
|
194
|
+
else
|
|
195
|
+
joined += '/' + arg;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (joined === undefined)
|
|
199
|
+
return '.';
|
|
200
|
+
return posix.normalize(joined);
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
relative: function relative(from, to) {
|
|
204
|
+
assertPath(from);
|
|
205
|
+
assertPath(to);
|
|
206
|
+
|
|
207
|
+
if (from === to) return '';
|
|
208
|
+
|
|
209
|
+
from = posix.resolve(from);
|
|
210
|
+
to = posix.resolve(to);
|
|
211
|
+
|
|
212
|
+
if (from === to) return '';
|
|
213
|
+
|
|
214
|
+
// Trim any leading backslashes
|
|
215
|
+
var fromStart = 1;
|
|
216
|
+
for (; fromStart < from.length; ++fromStart) {
|
|
217
|
+
if (from.charCodeAt(fromStart) !== 47 /*/*/)
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
var fromEnd = from.length;
|
|
221
|
+
var fromLen = fromEnd - fromStart;
|
|
222
|
+
|
|
223
|
+
// Trim any leading backslashes
|
|
224
|
+
var toStart = 1;
|
|
225
|
+
for (; toStart < to.length; ++toStart) {
|
|
226
|
+
if (to.charCodeAt(toStart) !== 47 /*/*/)
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
var toEnd = to.length;
|
|
230
|
+
var toLen = toEnd - toStart;
|
|
231
|
+
|
|
232
|
+
// Compare paths to find the longest common path from root
|
|
233
|
+
var length = fromLen < toLen ? fromLen : toLen;
|
|
234
|
+
var lastCommonSep = -1;
|
|
235
|
+
var i = 0;
|
|
236
|
+
for (; i <= length; ++i) {
|
|
237
|
+
if (i === length) {
|
|
238
|
+
if (toLen > length) {
|
|
239
|
+
if (to.charCodeAt(toStart + i) === 47 /*/*/) {
|
|
240
|
+
// We get here if `from` is the exact base path for `to`.
|
|
241
|
+
// For example: from='/foo/bar'; to='/foo/bar/baz'
|
|
242
|
+
return to.slice(toStart + i + 1);
|
|
243
|
+
} else if (i === 0) {
|
|
244
|
+
// We get here if `from` is the root
|
|
245
|
+
// For example: from='/'; to='/foo'
|
|
246
|
+
return to.slice(toStart + i);
|
|
247
|
+
}
|
|
248
|
+
} else if (fromLen > length) {
|
|
249
|
+
if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
|
|
250
|
+
// We get here if `to` is the exact base path for `from`.
|
|
251
|
+
// For example: from='/foo/bar/baz'; to='/foo/bar'
|
|
252
|
+
lastCommonSep = i;
|
|
253
|
+
} else if (i === 0) {
|
|
254
|
+
// We get here if `to` is the root.
|
|
255
|
+
// For example: from='/foo'; to='/'
|
|
256
|
+
lastCommonSep = 0;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
var fromCode = from.charCodeAt(fromStart + i);
|
|
262
|
+
var toCode = to.charCodeAt(toStart + i);
|
|
263
|
+
if (fromCode !== toCode)
|
|
264
|
+
break;
|
|
265
|
+
else if (fromCode === 47 /*/*/)
|
|
266
|
+
lastCommonSep = i;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
var out = '';
|
|
270
|
+
// Generate the relative path based on the path difference between `to`
|
|
271
|
+
// and `from`
|
|
272
|
+
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
273
|
+
if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) {
|
|
274
|
+
if (out.length === 0)
|
|
275
|
+
out += '..';
|
|
276
|
+
else
|
|
277
|
+
out += '/..';
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Lastly, append the rest of the destination (`to`) path that comes after
|
|
282
|
+
// the common path parts
|
|
283
|
+
if (out.length > 0)
|
|
284
|
+
return out + to.slice(toStart + lastCommonSep);
|
|
285
|
+
else {
|
|
286
|
+
toStart += lastCommonSep;
|
|
287
|
+
if (to.charCodeAt(toStart) === 47 /*/*/)
|
|
288
|
+
++toStart;
|
|
289
|
+
return to.slice(toStart);
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
_makeLong: function _makeLong(path) {
|
|
294
|
+
return path;
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
dirname: function dirname(path) {
|
|
298
|
+
assertPath(path);
|
|
299
|
+
if (path.length === 0) return '.';
|
|
300
|
+
var code = path.charCodeAt(0);
|
|
301
|
+
var hasRoot = code === 47 /*/*/;
|
|
302
|
+
var end = -1;
|
|
303
|
+
var matchedSlash = true;
|
|
304
|
+
for (var i = path.length - 1; i >= 1; --i) {
|
|
305
|
+
code = path.charCodeAt(i);
|
|
306
|
+
if (code === 47 /*/*/) {
|
|
307
|
+
if (!matchedSlash) {
|
|
308
|
+
end = i;
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
} else {
|
|
312
|
+
// We saw the first non-path separator
|
|
313
|
+
matchedSlash = false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (end === -1) return hasRoot ? '/' : '.';
|
|
318
|
+
if (hasRoot && end === 1) return '//';
|
|
319
|
+
return path.slice(0, end);
|
|
320
|
+
},
|
|
321
|
+
|
|
322
|
+
basename: function basename(path, ext) {
|
|
323
|
+
if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string');
|
|
324
|
+
assertPath(path);
|
|
325
|
+
|
|
326
|
+
var start = 0;
|
|
327
|
+
var end = -1;
|
|
328
|
+
var matchedSlash = true;
|
|
329
|
+
var i;
|
|
330
|
+
|
|
331
|
+
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
|
|
332
|
+
if (ext.length === path.length && ext === path) return '';
|
|
333
|
+
var extIdx = ext.length - 1;
|
|
334
|
+
var firstNonSlashEnd = -1;
|
|
335
|
+
for (i = path.length - 1; i >= 0; --i) {
|
|
336
|
+
var code = path.charCodeAt(i);
|
|
337
|
+
if (code === 47 /*/*/) {
|
|
338
|
+
// If we reached a path separator that was not part of a set of path
|
|
339
|
+
// separators at the end of the string, stop now
|
|
340
|
+
if (!matchedSlash) {
|
|
341
|
+
start = i + 1;
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
} else {
|
|
345
|
+
if (firstNonSlashEnd === -1) {
|
|
346
|
+
// We saw the first non-path separator, remember this index in case
|
|
347
|
+
// we need it if the extension ends up not matching
|
|
348
|
+
matchedSlash = false;
|
|
349
|
+
firstNonSlashEnd = i + 1;
|
|
350
|
+
}
|
|
351
|
+
if (extIdx >= 0) {
|
|
352
|
+
// Try to match the explicit extension
|
|
353
|
+
if (code === ext.charCodeAt(extIdx)) {
|
|
354
|
+
if (--extIdx === -1) {
|
|
355
|
+
// We matched the extension, so mark this as the end of our path
|
|
356
|
+
// component
|
|
357
|
+
end = i;
|
|
358
|
+
}
|
|
359
|
+
} else {
|
|
360
|
+
// Extension does not match, so our result is the entire path
|
|
361
|
+
// component
|
|
362
|
+
extIdx = -1;
|
|
363
|
+
end = firstNonSlashEnd;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;
|
|
370
|
+
return path.slice(start, end);
|
|
371
|
+
} else {
|
|
372
|
+
for (i = path.length - 1; i >= 0; --i) {
|
|
373
|
+
if (path.charCodeAt(i) === 47 /*/*/) {
|
|
374
|
+
// If we reached a path separator that was not part of a set of path
|
|
375
|
+
// separators at the end of the string, stop now
|
|
376
|
+
if (!matchedSlash) {
|
|
377
|
+
start = i + 1;
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
} else if (end === -1) {
|
|
381
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
382
|
+
// path component
|
|
383
|
+
matchedSlash = false;
|
|
384
|
+
end = i + 1;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (end === -1) return '';
|
|
389
|
+
return path.slice(start, end);
|
|
390
|
+
}
|
|
391
|
+
},
|
|
392
|
+
|
|
393
|
+
extname: function extname(path) {
|
|
394
|
+
assertPath(path);
|
|
395
|
+
var startDot = -1;
|
|
396
|
+
var startPart = 0;
|
|
397
|
+
var end = -1;
|
|
398
|
+
var matchedSlash = true;
|
|
399
|
+
// Track the state of characters (if any) we see before our first dot and
|
|
400
|
+
// after any path separator we find
|
|
401
|
+
var preDotState = 0;
|
|
402
|
+
for (var i = path.length - 1; i >= 0; --i) {
|
|
403
|
+
var code = path.charCodeAt(i);
|
|
404
|
+
if (code === 47 /*/*/) {
|
|
405
|
+
// If we reached a path separator that was not part of a set of path
|
|
406
|
+
// separators at the end of the string, stop now
|
|
407
|
+
if (!matchedSlash) {
|
|
408
|
+
startPart = i + 1;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
if (end === -1) {
|
|
414
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
415
|
+
// extension
|
|
416
|
+
matchedSlash = false;
|
|
417
|
+
end = i + 1;
|
|
418
|
+
}
|
|
419
|
+
if (code === 46 /*.*/) {
|
|
420
|
+
// If this is our first dot, mark it as the start of our extension
|
|
421
|
+
if (startDot === -1)
|
|
422
|
+
startDot = i;
|
|
423
|
+
else if (preDotState !== 1)
|
|
424
|
+
preDotState = 1;
|
|
425
|
+
} else if (startDot !== -1) {
|
|
426
|
+
// We saw a non-dot and non-path separator before our dot, so we should
|
|
427
|
+
// have a good chance at having a non-empty extension
|
|
428
|
+
preDotState = -1;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (startDot === -1 || end === -1 ||
|
|
433
|
+
// We saw a non-dot character immediately before the dot
|
|
434
|
+
preDotState === 0 ||
|
|
435
|
+
// The (right-most) trimmed path component is exactly '..'
|
|
436
|
+
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
437
|
+
return '';
|
|
438
|
+
}
|
|
439
|
+
return path.slice(startDot, end);
|
|
440
|
+
},
|
|
441
|
+
|
|
442
|
+
format: function format(pathObject) {
|
|
443
|
+
if (pathObject === null || typeof pathObject !== 'object') {
|
|
444
|
+
throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
|
|
445
|
+
}
|
|
446
|
+
return _format('/', pathObject);
|
|
447
|
+
},
|
|
448
|
+
|
|
449
|
+
parse: function parse(path) {
|
|
450
|
+
assertPath(path);
|
|
451
|
+
|
|
452
|
+
var ret = { root: '', dir: '', base: '', ext: '', name: '' };
|
|
453
|
+
if (path.length === 0) return ret;
|
|
454
|
+
var code = path.charCodeAt(0);
|
|
455
|
+
var isAbsolute = code === 47 /*/*/;
|
|
456
|
+
var start;
|
|
457
|
+
if (isAbsolute) {
|
|
458
|
+
ret.root = '/';
|
|
459
|
+
start = 1;
|
|
460
|
+
} else {
|
|
461
|
+
start = 0;
|
|
462
|
+
}
|
|
463
|
+
var startDot = -1;
|
|
464
|
+
var startPart = 0;
|
|
465
|
+
var end = -1;
|
|
466
|
+
var matchedSlash = true;
|
|
467
|
+
var i = path.length - 1;
|
|
468
|
+
|
|
469
|
+
// Track the state of characters (if any) we see before our first dot and
|
|
470
|
+
// after any path separator we find
|
|
471
|
+
var preDotState = 0;
|
|
472
|
+
|
|
473
|
+
// Get non-dir info
|
|
474
|
+
for (; i >= start; --i) {
|
|
475
|
+
code = path.charCodeAt(i);
|
|
476
|
+
if (code === 47 /*/*/) {
|
|
477
|
+
// If we reached a path separator that was not part of a set of path
|
|
478
|
+
// separators at the end of the string, stop now
|
|
479
|
+
if (!matchedSlash) {
|
|
480
|
+
startPart = i + 1;
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
if (end === -1) {
|
|
486
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
487
|
+
// extension
|
|
488
|
+
matchedSlash = false;
|
|
489
|
+
end = i + 1;
|
|
490
|
+
}
|
|
491
|
+
if (code === 46 /*.*/) {
|
|
492
|
+
// If this is our first dot, mark it as the start of our extension
|
|
493
|
+
if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;
|
|
494
|
+
} else if (startDot !== -1) {
|
|
495
|
+
// We saw a non-dot and non-path separator before our dot, so we should
|
|
496
|
+
// have a good chance at having a non-empty extension
|
|
497
|
+
preDotState = -1;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (startDot === -1 || end === -1 ||
|
|
502
|
+
// We saw a non-dot character immediately before the dot
|
|
503
|
+
preDotState === 0 ||
|
|
504
|
+
// The (right-most) trimmed path component is exactly '..'
|
|
505
|
+
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
506
|
+
if (end !== -1) {
|
|
507
|
+
if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);
|
|
508
|
+
}
|
|
509
|
+
} else {
|
|
510
|
+
if (startPart === 0 && isAbsolute) {
|
|
511
|
+
ret.name = path.slice(1, startDot);
|
|
512
|
+
ret.base = path.slice(1, end);
|
|
513
|
+
} else {
|
|
514
|
+
ret.name = path.slice(startPart, startDot);
|
|
515
|
+
ret.base = path.slice(startPart, end);
|
|
516
|
+
}
|
|
517
|
+
ret.ext = path.slice(startDot, end);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = '/';
|
|
521
|
+
|
|
522
|
+
return ret;
|
|
523
|
+
},
|
|
524
|
+
|
|
525
|
+
sep: '/',
|
|
526
|
+
delimiter: ':',
|
|
527
|
+
win32: null,
|
|
528
|
+
posix: null
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
posix.posix = posix;
|
|
532
|
+
|
|
533
|
+
pathBrowserify = posix;
|
|
534
|
+
return pathBrowserify;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
var pathBrowserifyExports = requirePathBrowserify();
|
|
538
|
+
var index = /*@__PURE__*/getDefaultExportFromCjs(pathBrowserifyExports);
|
|
539
|
+
|
|
540
|
+
var path = /*#__PURE__*/_mergeNamespaces({
|
|
541
|
+
__proto__: null,
|
|
542
|
+
default: index
|
|
543
|
+
}, [pathBrowserifyExports]);
|
|
544
|
+
|
|
545
|
+
// src/index.ts
|
|
546
|
+
function isString(val) {
|
|
547
|
+
return typeof val === "string";
|
|
548
|
+
}
|
|
549
|
+
function toUnix(p) {
|
|
550
|
+
p = p.replace(/\\/g, "/");
|
|
551
|
+
p = p.replace(/(?<!^)\/+/g, "/");
|
|
552
|
+
return p;
|
|
553
|
+
}
|
|
554
|
+
var upath = {};
|
|
555
|
+
for (const [propName, propValue] of Object.entries(path)) {
|
|
556
|
+
if (propName === "posix" || propName === "win32") {
|
|
557
|
+
upath[propName] = propValue;
|
|
558
|
+
} else if (typeof propValue === "function") {
|
|
559
|
+
upath[propName] = (...args) => {
|
|
560
|
+
const mapped = args.map((a) => isString(a) ? toUnix(a) : a);
|
|
561
|
+
const result = propValue.apply(path, mapped);
|
|
562
|
+
return isString(result) ? toUnix(result) : result;
|
|
563
|
+
};
|
|
564
|
+
} else {
|
|
565
|
+
upath[propName] = propValue;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
upath.sep = "/";
|
|
569
|
+
function isValidExt(ext, ignoreExts = [], maxSize) {
|
|
570
|
+
return !!ext && ext.length <= maxSize && !ignoreExts.map((e) => e && e[0] !== "." ? "." + e : e).includes(ext);
|
|
571
|
+
}
|
|
572
|
+
function normalizeSafe(p) {
|
|
573
|
+
p = toUnix(p);
|
|
574
|
+
let result = upath.normalize(p);
|
|
575
|
+
if (p.startsWith("./") && !result.startsWith("./") && !result.startsWith("..")) {
|
|
576
|
+
result = "./" + result;
|
|
577
|
+
} else if (p.startsWith("//") && !result.startsWith("//")) {
|
|
578
|
+
if (p.startsWith("//./")) {
|
|
579
|
+
result = "//." + result;
|
|
580
|
+
} else {
|
|
581
|
+
result = "/" + result;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return result;
|
|
585
|
+
}
|
|
586
|
+
function normalizeTrim(p) {
|
|
587
|
+
p = normalizeSafe(p);
|
|
588
|
+
if (p.endsWith("/") && p.length > 1) {
|
|
589
|
+
return p.slice(0, -1);
|
|
590
|
+
}
|
|
591
|
+
return p;
|
|
592
|
+
}
|
|
593
|
+
function joinSafe(...segments) {
|
|
594
|
+
const result = upath.join(...segments);
|
|
595
|
+
if (segments.length > 0) {
|
|
596
|
+
const p0 = toUnix(segments[0]);
|
|
597
|
+
if (p0.startsWith("./") && !result.startsWith("./") && !result.startsWith("..")) {
|
|
598
|
+
return "./" + result;
|
|
599
|
+
} else if (p0.startsWith("//") && !result.startsWith("//")) {
|
|
600
|
+
if (p0.startsWith("//./")) {
|
|
601
|
+
return "//." + result;
|
|
602
|
+
} else {
|
|
603
|
+
return "/" + result;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
return result;
|
|
608
|
+
}
|
|
609
|
+
function addExt(file, ext) {
|
|
610
|
+
if (!ext) return file;
|
|
611
|
+
if (ext[0] !== ".") ext = "." + ext;
|
|
612
|
+
return file + (file.endsWith(ext) ? "" : ext);
|
|
613
|
+
}
|
|
614
|
+
function trimExt(filename, ignoreExts, maxSize) {
|
|
615
|
+
const _maxSize = maxSize ?? 7;
|
|
616
|
+
const _ignoreExts = ignoreExts ?? [];
|
|
617
|
+
const oldExt = upath.extname(filename);
|
|
618
|
+
if (isValidExt(oldExt, _ignoreExts, _maxSize)) {
|
|
619
|
+
return filename.slice(0, filename.length - oldExt.length);
|
|
620
|
+
}
|
|
621
|
+
return filename;
|
|
622
|
+
}
|
|
623
|
+
function removeExt(filename, ext) {
|
|
624
|
+
if (!ext) return filename;
|
|
625
|
+
ext = ext[0] === "." ? ext : "." + ext;
|
|
626
|
+
if (upath.extname(filename) === ext) {
|
|
627
|
+
return trimExt(filename, [], ext.length);
|
|
628
|
+
}
|
|
629
|
+
return filename;
|
|
630
|
+
}
|
|
631
|
+
function changeExt(filename, ext, ignoreExts, maxSize) {
|
|
632
|
+
const _maxSize = maxSize ?? 7;
|
|
633
|
+
const _ignoreExts = ignoreExts ?? [];
|
|
634
|
+
const trimmed = trimExt(filename, _ignoreExts, _maxSize);
|
|
635
|
+
if (!ext) return trimmed;
|
|
636
|
+
return trimmed + (ext[0] === "." ? ext : "." + ext);
|
|
637
|
+
}
|
|
638
|
+
function defaultExt(filename, ext, ignoreExts, maxSize) {
|
|
639
|
+
const _maxSize = maxSize ?? 7;
|
|
640
|
+
const _ignoreExts = ignoreExts ?? [];
|
|
641
|
+
const oldExt = upath.extname(filename);
|
|
642
|
+
if (isValidExt(oldExt, _ignoreExts, _maxSize)) {
|
|
643
|
+
return filename;
|
|
644
|
+
}
|
|
645
|
+
return addExt(filename, ext);
|
|
646
|
+
}
|
|
647
|
+
var extraFunctions = {
|
|
648
|
+
toUnix,
|
|
649
|
+
normalizeSafe,
|
|
650
|
+
normalizeTrim,
|
|
651
|
+
joinSafe,
|
|
652
|
+
addExt,
|
|
653
|
+
trimExt,
|
|
654
|
+
removeExt,
|
|
655
|
+
changeExt,
|
|
656
|
+
defaultExt
|
|
657
|
+
};
|
|
658
|
+
for (const [name, fn] of Object.entries(extraFunctions)) {
|
|
659
|
+
if (upath[name] !== void 0) {
|
|
660
|
+
throw new Error(`path.${name} already exists.`);
|
|
661
|
+
}
|
|
662
|
+
upath[name] = fn;
|
|
663
|
+
}
|
|
664
|
+
upath.VERSION = "3.0.7";
|
|
665
|
+
upath.resolve;
|
|
666
|
+
upath.normalize;
|
|
667
|
+
upath.isAbsolute;
|
|
668
|
+
upath.join;
|
|
669
|
+
upath.relative;
|
|
670
|
+
upath.dirname;
|
|
671
|
+
upath.basename;
|
|
672
|
+
upath.extname;
|
|
673
|
+
upath.format;
|
|
674
|
+
upath.parse;
|
|
675
|
+
upath.toNamespacedPath;
|
|
676
|
+
upath.matchesGlob;
|
|
677
|
+
upath.sep;
|
|
678
|
+
upath.delimiter;
|
|
679
|
+
upath.posix;
|
|
680
|
+
upath.win32;
|
|
681
|
+
upath.VERSION;
|
|
682
|
+
var index_default = upath;
|
|
683
|
+
|
|
684
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
685
|
+
// @ts-ignore
|
|
686
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
687
|
+
let moduleInstance = null;
|
|
688
|
+
addEventListener("message", async (e) => {
|
|
689
|
+
const { type, data } = e.data;
|
|
690
|
+
switch (type) {
|
|
691
|
+
case "init":
|
|
692
|
+
moduleInstance = await Module({
|
|
693
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
694
|
+
preRun(mod) {
|
|
695
|
+
// https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.init
|
|
696
|
+
mod.FS.init((() => {
|
|
697
|
+
const sharedBuffer = data;
|
|
698
|
+
const statusArray = new Int32Array(sharedBuffer, 0, 1);
|
|
699
|
+
const dataArray = new Int32Array(sharedBuffer, 4, 1);
|
|
700
|
+
return () => {
|
|
701
|
+
Atomics.store(statusArray, 0, STATUS_INPUT_REQUESTED);
|
|
702
|
+
self.postMessage({ type: "stdin" });
|
|
703
|
+
Atomics.wait(statusArray, 0, STATUS_INPUT_REQUESTED);
|
|
704
|
+
const status = Atomics.load(statusArray, 0);
|
|
705
|
+
if (status === STATUS_DATA_READY) {
|
|
706
|
+
return Atomics.load(dataArray, 0);
|
|
707
|
+
}
|
|
708
|
+
else if (status === STATUS_FLUSH) {
|
|
709
|
+
return null;
|
|
710
|
+
}
|
|
711
|
+
return null;
|
|
712
|
+
};
|
|
713
|
+
})(), (charCode) => {
|
|
714
|
+
self.postMessage({
|
|
715
|
+
type: "stdout",
|
|
716
|
+
data: charCode,
|
|
717
|
+
});
|
|
718
|
+
}, (charCode) => {
|
|
719
|
+
self.postMessage({
|
|
720
|
+
type: "stderr",
|
|
721
|
+
data: charCode,
|
|
722
|
+
});
|
|
723
|
+
});
|
|
724
|
+
},
|
|
725
|
+
});
|
|
726
|
+
self.postMessage({ type: "ready" });
|
|
727
|
+
break;
|
|
728
|
+
case "start": {
|
|
729
|
+
const { args, inputFiles, outputFilePaths } = data;
|
|
730
|
+
for (const [filePath, content] of Object.entries(inputFiles)) {
|
|
731
|
+
const dirPath = index_default.dirname(filePath);
|
|
732
|
+
if (dirPath && dirPath !== ".") {
|
|
733
|
+
moduleInstance.FS.mkdirTree(dirPath);
|
|
734
|
+
}
|
|
735
|
+
moduleInstance.FS.writeFile(filePath, content);
|
|
736
|
+
}
|
|
737
|
+
for (const filePath of outputFilePaths) {
|
|
738
|
+
const dirPath = index_default.dirname(filePath);
|
|
739
|
+
if (dirPath && dirPath !== ".") {
|
|
740
|
+
moduleInstance.FS.mkdirTree(dirPath);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
const exitCode = moduleInstance.callMain(args);
|
|
744
|
+
const outputFiles = {};
|
|
745
|
+
const transferables = [];
|
|
746
|
+
for (const filePath of outputFilePaths) {
|
|
747
|
+
try {
|
|
748
|
+
const fileData = moduleInstance.FS.readFile(filePath);
|
|
749
|
+
outputFiles[filePath] = fileData;
|
|
750
|
+
transferables.push(fileData.buffer);
|
|
751
|
+
}
|
|
752
|
+
catch {
|
|
753
|
+
// File does not exist, skip
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
self.postMessage({
|
|
757
|
+
type: "complete",
|
|
758
|
+
data: { exitCode, outputFiles },
|
|
759
|
+
}, transferables);
|
|
760
|
+
break;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
//# sourceMappingURL=worker.js.map
|