@d0paminedriven/fs 10.0.0 → 11.0.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/dist/docs/index.d.ts +119 -0
- package/dist/docs/index.js +1027 -0
- package/dist/extract/client.d.ts +54 -0
- package/dist/extract/client.js +118 -0
- package/dist/extract/index.d.ts +69 -0
- package/dist/extract/index.js +622 -0
- package/dist/fs/index.d.ts +19 -55
- package/dist/fs/index.js +88 -19
- package/dist/fs-atomic/index.d.ts +28 -36
- package/dist/fs-atomic/index.js +88 -13
- package/dist/fs-base/index.d.ts +105 -111
- package/dist/fs-base/index.js +188 -12
- package/dist/fs-core/index.d.ts +20 -24
- package/dist/fs-core/index.js +44 -16
- package/dist/fs-fetch/index.d.ts +48 -62
- package/dist/fs-fetch/index.js +146 -18
- package/dist/fs-size/index.d.ts +16 -28
- package/dist/fs-size/index.js +64 -15
- package/dist/fs-tmp/index.d.ts +179 -192
- package/dist/fs-tmp/index.js +321 -17
- package/dist/images/index.d.ts +447 -0
- package/dist/images/index.js +899 -0
- package/dist/images/workup.d.ts +30 -0
- package/dist/images/workup.js +317 -0
- package/dist/index.d.ts +20 -22
- package/dist/index.js +20 -64
- package/dist/ld/index.d.ts +15 -13
- package/dist/ld/index.js +56 -6
- package/dist/mime/index.d.ts +299 -294
- package/dist/mime/index.js +348 -13
- package/dist/mixins/index.d.ts +34 -0
- package/dist/mixins/index.js +54 -0
- package/dist/types/index.d.ts +279 -215
- package/dist/types/index.js +11 -6
- package/dist/types/stream.d.ts +6 -4
- package/dist/types/stream.js +1 -1
- package/dist/url/index.d.ts +15 -18
- package/dist/url/index.js +21 -8
- package/dist/utils/index.d.ts +19 -23
- package/dist/utils/index.js +82 -7
- package/package.json +33 -13
- package/dist/chunk-5CACVZVF.js +0 -386
- package/dist/chunk-5H6GE5AO.js +0 -14
- package/dist/chunk-7JQ56XIH.js +0 -187
- package/dist/chunk-7LOAFIZM.js +0 -77
- package/dist/chunk-7QVYU63E.js +0 -7
- package/dist/chunk-DNR5ZI2T.js +0 -75
- package/dist/chunk-L2QMQOEJ.js +0 -366
- package/dist/chunk-NJHN5OE3.js +0 -33
- package/dist/chunk-OHKRQJZH.js +0 -82
- package/dist/chunk-OT5JEQKW.js +0 -139
- package/dist/chunk-PATMSIQK.js +0 -367
- package/dist/chunk-PB5A7ZFD.js +0 -79
- package/dist/chunk-VDKUXJE7.js +0 -240
- package/dist/chunk-Y5QWE4EG.js +0 -1335
- package/dist/chunk-YRCJWFZD.js +0 -107
- package/dist/image/index.d.ts +0 -182
- package/dist/image/index.js +0 -13
- package/dist/image/workup.d.ts +0 -40
- package/dist/image/workup.js +0 -12
package/dist/chunk-5CACVZVF.js
DELETED
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MimeService
|
|
3
|
-
} from "./chunk-L2QMQOEJ.js";
|
|
4
|
-
import {
|
|
5
|
-
__name
|
|
6
|
-
} from "./chunk-7QVYU63E.js";
|
|
7
|
-
|
|
8
|
-
// src/image/workup.ts
|
|
9
|
-
var ImageServiceWorkup = class extends MimeService {
|
|
10
|
-
constructor(cwd) {
|
|
11
|
-
super();
|
|
12
|
-
this.cwd = cwd;
|
|
13
|
-
}
|
|
14
|
-
static {
|
|
15
|
-
__name(this, "ImageServiceWorkup");
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Read exactly N bytes from a stream, returning a Buffer
|
|
19
|
-
* Closes stream after reading or on error
|
|
20
|
-
*/
|
|
21
|
-
async readBytes(stream, bytes) {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
const chunks = Array.of();
|
|
24
|
-
let totalBytes = 0;
|
|
25
|
-
const cleanup = /* @__PURE__ */ __name(() => {
|
|
26
|
-
stream.removeAllListeners();
|
|
27
|
-
stream.destroy();
|
|
28
|
-
}, "cleanup");
|
|
29
|
-
stream.on("error", (err) => {
|
|
30
|
-
cleanup();
|
|
31
|
-
reject(err);
|
|
32
|
-
});
|
|
33
|
-
stream.on("data", (chunk) => {
|
|
34
|
-
const remaining = bytes - totalBytes;
|
|
35
|
-
if (chunk.length <= remaining) {
|
|
36
|
-
chunks.push(chunk);
|
|
37
|
-
totalBytes += chunk.length;
|
|
38
|
-
} else {
|
|
39
|
-
chunks.push(chunk.subarray(0, remaining));
|
|
40
|
-
totalBytes = bytes;
|
|
41
|
-
}
|
|
42
|
-
if (totalBytes >= bytes) {
|
|
43
|
-
cleanup();
|
|
44
|
-
resolve(Buffer.concat(chunks));
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
stream.on("end", () => {
|
|
48
|
-
cleanup();
|
|
49
|
-
resolve(Buffer.concat(chunks));
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
parseExif(buffer, app1Pos, app1Size) {
|
|
54
|
-
const segmentStart = app1Pos + 4;
|
|
55
|
-
const segmentEnd = app1Pos + 2 + app1Size;
|
|
56
|
-
if (segmentEnd - segmentStart < 16 || segmentEnd > buffer.length) {
|
|
57
|
-
return { orientation: null, dateTimeOriginal: null };
|
|
58
|
-
}
|
|
59
|
-
const headerEnd = Math.min(segmentStart + 6, segmentEnd, buffer.length);
|
|
60
|
-
if (headerEnd - segmentStart < 6) {
|
|
61
|
-
return { orientation: null, dateTimeOriginal: null };
|
|
62
|
-
}
|
|
63
|
-
const exifHeader = buffer.toString("ascii", segmentStart, headerEnd);
|
|
64
|
-
if (exifHeader !== "Exif\0\0") {
|
|
65
|
-
return { orientation: null, dateTimeOriginal: null };
|
|
66
|
-
}
|
|
67
|
-
const tiffStart = segmentStart + 6;
|
|
68
|
-
const tiffEnd = segmentEnd;
|
|
69
|
-
if (tiffEnd - tiffStart < 8) {
|
|
70
|
-
return { orientation: null, dateTimeOriginal: null };
|
|
71
|
-
}
|
|
72
|
-
const byteOrder = buffer.toString("ascii", tiffStart, tiffStart + 2);
|
|
73
|
-
const littleEndian = byteOrder === "II";
|
|
74
|
-
const bigEndian = byteOrder === "MM";
|
|
75
|
-
if (!littleEndian && !bigEndian) {
|
|
76
|
-
return { orientation: null, dateTimeOriginal: null };
|
|
77
|
-
}
|
|
78
|
-
const readUInt16 = /* @__PURE__ */ __name((pos) => {
|
|
79
|
-
if (pos < 0 || pos + 2 > tiffEnd || pos + 2 > buffer.length) return null;
|
|
80
|
-
return littleEndian ? buffer.readUInt16LE(pos) : buffer.readUInt16BE(pos);
|
|
81
|
-
}, "readUInt16");
|
|
82
|
-
const readUInt32 = /* @__PURE__ */ __name((pos) => {
|
|
83
|
-
if (pos < 0 || pos + 4 > tiffEnd || pos + 4 > buffer.length) return null;
|
|
84
|
-
return littleEndian ? buffer.readUInt32LE(pos) : buffer.readUInt32BE(pos);
|
|
85
|
-
}, "readUInt32");
|
|
86
|
-
const magic = readUInt16(tiffStart + 2);
|
|
87
|
-
if (magic !== 42) {
|
|
88
|
-
return { orientation: null, dateTimeOriginal: null };
|
|
89
|
-
}
|
|
90
|
-
const ifd0Offset = readUInt32(tiffStart + 4);
|
|
91
|
-
if (ifd0Offset === null || ifd0Offset < 8) {
|
|
92
|
-
return { orientation: null, dateTimeOriginal: null };
|
|
93
|
-
}
|
|
94
|
-
const ifd0Pos = tiffStart + ifd0Offset;
|
|
95
|
-
if (ifd0Pos + 2 > tiffEnd) {
|
|
96
|
-
return { orientation: null, dateTimeOriginal: null };
|
|
97
|
-
}
|
|
98
|
-
const numEntries = readUInt16(ifd0Pos);
|
|
99
|
-
if (numEntries === null || numEntries === 0 || numEntries > 500) {
|
|
100
|
-
return { orientation: null, dateTimeOriginal: null };
|
|
101
|
-
}
|
|
102
|
-
let orientation = null;
|
|
103
|
-
let dateTimeOriginal = null;
|
|
104
|
-
const ifdDataStart = ifd0Pos + 2;
|
|
105
|
-
const ifdDataEnd = ifdDataStart + numEntries * 12;
|
|
106
|
-
if (ifdDataEnd > tiffEnd) {
|
|
107
|
-
const maxEntries = Math.floor((tiffEnd - ifdDataStart) / 12);
|
|
108
|
-
if (maxEntries <= 0) {
|
|
109
|
-
return { orientation, dateTimeOriginal };
|
|
110
|
-
}
|
|
111
|
-
for (let i = 0; i < maxEntries; i++) {
|
|
112
|
-
const entryPos = ifdDataStart + i * 12;
|
|
113
|
-
const tag = readUInt16(entryPos);
|
|
114
|
-
const type = readUInt16(entryPos + 2);
|
|
115
|
-
const count = readUInt32(entryPos + 4);
|
|
116
|
-
if (tag === null || type === null || count === null) continue;
|
|
117
|
-
if (tag === 274 && type === 3 && count === 1) {
|
|
118
|
-
orientation = readUInt16(entryPos + 8);
|
|
119
|
-
if (orientation && (orientation < 1 || orientation > 8)) {
|
|
120
|
-
orientation = null;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (tag === 36867 && type === 2 && count === 20) {
|
|
124
|
-
const offset = readUInt32(entryPos + 8);
|
|
125
|
-
if (offset !== null) {
|
|
126
|
-
const stringPos = tiffStart + offset;
|
|
127
|
-
const stringEnd = stringPos + 19;
|
|
128
|
-
if (stringEnd <= tiffEnd && stringEnd <= buffer.length) {
|
|
129
|
-
try {
|
|
130
|
-
dateTimeOriginal = buffer.toString(
|
|
131
|
-
"ascii",
|
|
132
|
-
stringPos,
|
|
133
|
-
stringEnd
|
|
134
|
-
);
|
|
135
|
-
if (!/^\d{4}:\d{2}:\d{2} \d{2}:\d{2}:\d{2}/.test(dateTimeOriginal)) {
|
|
136
|
-
dateTimeOriginal = null;
|
|
137
|
-
}
|
|
138
|
-
} catch {
|
|
139
|
-
dateTimeOriginal = null;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
} else {
|
|
146
|
-
for (let i = 0; i < numEntries; i++) {
|
|
147
|
-
const entryPos = ifdDataStart + i * 12;
|
|
148
|
-
const tag = readUInt16(entryPos);
|
|
149
|
-
const type = readUInt16(entryPos + 2);
|
|
150
|
-
const count = readUInt32(entryPos + 4);
|
|
151
|
-
if (tag === null || type === null || count === null) continue;
|
|
152
|
-
if (tag === 274 && type === 3 && count === 1) {
|
|
153
|
-
orientation = readUInt16(entryPos + 8);
|
|
154
|
-
if (orientation && (orientation < 1 || orientation > 8)) {
|
|
155
|
-
orientation = null;
|
|
156
|
-
}
|
|
157
|
-
} else if (tag === 36867 && type === 2 && count === 20) {
|
|
158
|
-
const offset = readUInt32(entryPos + 8);
|
|
159
|
-
if (offset !== null) {
|
|
160
|
-
const stringPos = tiffStart + offset;
|
|
161
|
-
const stringEnd = stringPos + 19;
|
|
162
|
-
if (stringEnd <= tiffEnd && stringEnd <= buffer.length) {
|
|
163
|
-
try {
|
|
164
|
-
const extracted = buffer.toString(
|
|
165
|
-
"ascii",
|
|
166
|
-
stringPos,
|
|
167
|
-
stringEnd
|
|
168
|
-
);
|
|
169
|
-
if (/^\d{4}:\d{2}:\d{2} \d{2}:\d{2}:\d{2}/.test(extracted)) {
|
|
170
|
-
dateTimeOriginal = extracted;
|
|
171
|
-
}
|
|
172
|
-
} catch {
|
|
173
|
-
console.warn("invalid ascii data");
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return { orientation, dateTimeOriginal };
|
|
181
|
-
}
|
|
182
|
-
parseXmpFromAvif(buffer, meta, _ipco) {
|
|
183
|
-
const iinf = this.findBox(
|
|
184
|
-
buffer,
|
|
185
|
-
"iinf",
|
|
186
|
-
meta.pos + 4,
|
|
187
|
-
meta.pos + meta.size
|
|
188
|
-
);
|
|
189
|
-
if (!iinf) return null;
|
|
190
|
-
let pos = iinf.pos;
|
|
191
|
-
const version = buffer[pos++];
|
|
192
|
-
const itemCount = version === 0 ? buffer.readUInt16BE(pos) : buffer.readUInt32BE(pos);
|
|
193
|
-
pos += version === 0 ? 2 : 4;
|
|
194
|
-
let xmpItemId;
|
|
195
|
-
for (let i = 0; i < itemCount; i++) {
|
|
196
|
-
const infeStart = pos;
|
|
197
|
-
const infeSize = buffer.readUInt32BE(pos);
|
|
198
|
-
if (buffer.toString("ascii", pos + 4, pos + 8) !== "infe") break;
|
|
199
|
-
pos += 8;
|
|
200
|
-
const infeVersion = buffer?.[pos++];
|
|
201
|
-
if (!infeVersion) return null;
|
|
202
|
-
const itemId = infeVersion < 2 ? buffer.readUInt16BE(pos) : buffer.readUInt32BE(pos);
|
|
203
|
-
pos += infeVersion < 2 ? 2 : 4;
|
|
204
|
-
pos += 2;
|
|
205
|
-
const itemType = buffer.toString("ascii", pos, pos + 4);
|
|
206
|
-
pos += 4;
|
|
207
|
-
let nameEnd = pos;
|
|
208
|
-
while (buffer[nameEnd] !== 0 && nameEnd < infeStart + infeSize) nameEnd++;
|
|
209
|
-
pos = nameEnd + 1;
|
|
210
|
-
if (itemType === "mime") {
|
|
211
|
-
let ctEnd = pos;
|
|
212
|
-
while (buffer[ctEnd] !== 0 && ctEnd < infeStart + infeSize) ctEnd++;
|
|
213
|
-
const contentType = buffer.toString("ascii", pos, ctEnd);
|
|
214
|
-
if (contentType === "application/rdf+xml") {
|
|
215
|
-
xmpItemId = itemId;
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
pos = ctEnd + 1;
|
|
219
|
-
}
|
|
220
|
-
pos = infeStart + infeSize;
|
|
221
|
-
}
|
|
222
|
-
if (!xmpItemId) return null;
|
|
223
|
-
const iloc = this.findBox(
|
|
224
|
-
buffer,
|
|
225
|
-
"iloc",
|
|
226
|
-
meta.pos + 4,
|
|
227
|
-
meta.pos + meta.size
|
|
228
|
-
);
|
|
229
|
-
if (!iloc) return null;
|
|
230
|
-
pos = iloc.pos;
|
|
231
|
-
const ilocVersion = buffer[pos++];
|
|
232
|
-
const sizes = buffer?.[pos++];
|
|
233
|
-
if (!sizes) return null;
|
|
234
|
-
const offsetSize = sizes >> 4 & 15;
|
|
235
|
-
const lengthSize = sizes & 15;
|
|
236
|
-
let indexSize = 0;
|
|
237
|
-
if (ilocVersion === 1 || ilocVersion === 2) {
|
|
238
|
-
const indexSizes = buffer?.[pos++];
|
|
239
|
-
if (!indexSizes) return null;
|
|
240
|
-
indexSize = indexSizes >> 4 & 15;
|
|
241
|
-
}
|
|
242
|
-
if (!ilocVersion) return null;
|
|
243
|
-
const buffpos = buffer?.[pos++];
|
|
244
|
-
if (!buffpos) return null;
|
|
245
|
-
const baseOffsetSize = ilocVersion < 2 ? 0 : buffpos >> 4 & 15;
|
|
246
|
-
const itemCountIloc = ilocVersion < 2 ? buffer.readUInt16BE(pos) : buffer.readUInt32BE(pos);
|
|
247
|
-
pos += ilocVersion < 2 ? 2 : 4;
|
|
248
|
-
let xmpOffset = 0;
|
|
249
|
-
let xmpLength = 0;
|
|
250
|
-
for (let i = 0; i < itemCountIloc; i++) {
|
|
251
|
-
const curItemId = ilocVersion < 2 ? buffer.readUInt16BE(pos) : buffer.readUInt32BE(pos);
|
|
252
|
-
pos += ilocVersion < 2 ? 2 : 4;
|
|
253
|
-
if (curItemId !== xmpItemId) {
|
|
254
|
-
if (ilocVersion === 1 || ilocVersion === 2) pos += 2;
|
|
255
|
-
pos += 2;
|
|
256
|
-
pos += baseOffsetSize;
|
|
257
|
-
const extentCount2 = buffer.readUInt16BE(pos);
|
|
258
|
-
pos += 2;
|
|
259
|
-
for (let e = 0; e < extentCount2; e++) {
|
|
260
|
-
if (indexSize > 0) pos += indexSize;
|
|
261
|
-
pos += offsetSize + lengthSize;
|
|
262
|
-
}
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
if (ilocVersion === 1 || ilocVersion === 2) {
|
|
266
|
-
const constructionMethod = buffer.readUInt16BE(pos);
|
|
267
|
-
pos += 2;
|
|
268
|
-
if (constructionMethod !== 0) return null;
|
|
269
|
-
}
|
|
270
|
-
pos += 2;
|
|
271
|
-
const baseOffset = this.readVarSize(buffer, pos, baseOffsetSize);
|
|
272
|
-
pos += baseOffsetSize;
|
|
273
|
-
const extentCount = buffer.readUInt16BE(pos);
|
|
274
|
-
pos += 2;
|
|
275
|
-
if (extentCount !== 1) return null;
|
|
276
|
-
if (indexSize > 0) pos += indexSize;
|
|
277
|
-
const extentOffset = this.readVarSize(buffer, pos, offsetSize);
|
|
278
|
-
pos += offsetSize;
|
|
279
|
-
const extentLength = this.readVarSize(buffer, pos, lengthSize);
|
|
280
|
-
xmpOffset = baseOffset + extentOffset;
|
|
281
|
-
xmpLength = extentLength;
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
if (xmpOffset === 0 || xmpLength === 0 || xmpOffset + xmpLength > buffer.length)
|
|
285
|
-
return null;
|
|
286
|
-
return buffer.toString("utf8", xmpOffset, xmpOffset + xmpLength);
|
|
287
|
-
}
|
|
288
|
-
readVarSize(buffer, pos, size) {
|
|
289
|
-
if (size === 0) return 0;
|
|
290
|
-
if (size === 1 && buffer?.[pos]) return buffer?.[pos];
|
|
291
|
-
if (size === 2) return buffer.readUInt16BE(pos);
|
|
292
|
-
if (size === 3) {
|
|
293
|
-
const pos1 = buffer?.[pos + 1], pos2 = buffer?.[pos + 2];
|
|
294
|
-
if (buffer?.[pos] && pos1 && pos2) {
|
|
295
|
-
return buffer[pos] << 16 | pos1 << 8 | pos2;
|
|
296
|
-
}
|
|
297
|
-
throw new Error("Invalid var size");
|
|
298
|
-
}
|
|
299
|
-
if (size === 4) return buffer.readUInt32BE(pos);
|
|
300
|
-
if (size === 8) return Number(buffer.readBigUInt64BE(pos));
|
|
301
|
-
throw new Error("Invalid var size");
|
|
302
|
-
}
|
|
303
|
-
findBox(buffer, type, start = 0, end = buffer.length) {
|
|
304
|
-
let pos = start;
|
|
305
|
-
while (pos < end) {
|
|
306
|
-
let boxSize = buffer.readUInt32BE(pos);
|
|
307
|
-
const boxType = buffer.toString("ascii", pos + 4, pos + 8);
|
|
308
|
-
let hdrSize = 8;
|
|
309
|
-
if (boxSize === 1) {
|
|
310
|
-
boxSize = Number(buffer.readBigUInt64BE(pos + 8));
|
|
311
|
-
hdrSize = 16;
|
|
312
|
-
} else if (boxSize === 0) {
|
|
313
|
-
boxSize = end - pos;
|
|
314
|
-
}
|
|
315
|
-
if (boxType === type) {
|
|
316
|
-
return { pos: pos + hdrSize, size: boxSize - hdrSize };
|
|
317
|
-
}
|
|
318
|
-
pos += boxSize;
|
|
319
|
-
}
|
|
320
|
-
return null;
|
|
321
|
-
}
|
|
322
|
-
mapChrmToColorSpace(chrm, fallback) {
|
|
323
|
-
const tol = 100;
|
|
324
|
-
if (Math.abs(chrm.white_x - 31270) < tol && Math.abs(chrm.white_y - 32900) < tol && Math.abs(chrm.red_x - 64e3) < tol && Math.abs(chrm.red_y - 33e3) < tol && Math.abs(chrm.green_x - 3e4) < tol && Math.abs(chrm.green_y - 6e4) < tol && Math.abs(chrm.blue_x - 15e3) < tol && Math.abs(chrm.blue_y - 6e3) < tol)
|
|
325
|
-
return "srgb";
|
|
326
|
-
if (Math.abs(chrm.white_x - 31270) < tol && Math.abs(chrm.white_y - 32900) < tol && Math.abs(chrm.red_x - 64e3) < tol && Math.abs(chrm.red_y - 33e3) < tol && Math.abs(chrm.green_x - 21e3) < tol && Math.abs(chrm.green_y - 71e3) < tol && Math.abs(chrm.blue_x - 15e3) < tol && Math.abs(chrm.blue_y - 6e3) < tol)
|
|
327
|
-
return "adobe_rgb";
|
|
328
|
-
if (Math.abs(chrm.white_x - 31270) < tol && Math.abs(chrm.white_y - 32900) < tol && Math.abs(chrm.red_x - 68e3) < tol && Math.abs(chrm.red_y - 32e3) < tol && Math.abs(chrm.green_x - 26500) < tol && Math.abs(chrm.green_y - 69e3) < tol && Math.abs(chrm.blue_x - 15e3) < tol && Math.abs(chrm.blue_y - 6e3) < tol)
|
|
329
|
-
return "display_p3";
|
|
330
|
-
if (Math.abs(chrm.white_x - 34590) < tol && Math.abs(chrm.white_y - 35850) < tol && // D50 white point
|
|
331
|
-
Math.abs(chrm.red_x - 73470) < tol && Math.abs(chrm.red_y - 26530) < tol && Math.abs(chrm.green_x - 15960) < tol && Math.abs(chrm.green_y - 85040) < tol && Math.abs(chrm.blue_x - 3600) < tol && Math.abs(chrm.blue_y - 1e3) < tol)
|
|
332
|
-
return "prophoto_rgb";
|
|
333
|
-
if (Math.abs(chrm.white_x - 31270) < tol && Math.abs(chrm.white_y - 32900) < tol && Math.abs(chrm.red_x - 70800) < tol && Math.abs(chrm.red_y - 29200) < tol && Math.abs(chrm.green_x - 17e3) < tol && Math.abs(chrm.green_y - 79700) < tol && Math.abs(chrm.blue_x - 13100) < tol && Math.abs(chrm.blue_y - 4600) < tol)
|
|
334
|
-
return "rec2020";
|
|
335
|
-
return fallback;
|
|
336
|
-
}
|
|
337
|
-
xmpToColorSpaceWorkup(space, target) {
|
|
338
|
-
return `<photoshop:${target}>${space}</photoshop:${target}>`;
|
|
339
|
-
}
|
|
340
|
-
mapXmpToColorSpace(xmpText, fallback) {
|
|
341
|
-
const lower = xmpText.toLowerCase();
|
|
342
|
-
if (lower.includes(this.xmpToColorSpaceWorkup("srgb", "iccprofile")))
|
|
343
|
-
return "srgb";
|
|
344
|
-
if (lower.includes(
|
|
345
|
-
this.xmpToColorSpaceWorkup("adobe rgb (1998)", "iccprofile")
|
|
346
|
-
))
|
|
347
|
-
return "adobe_rgb";
|
|
348
|
-
if (lower.includes(this.xmpToColorSpaceWorkup("display p3", "iccprofile")))
|
|
349
|
-
return "display_p3";
|
|
350
|
-
if (lower.includes(this.xmpToColorSpaceWorkup("prophoto rgb", "iccprofile")))
|
|
351
|
-
return "prophoto_rgb";
|
|
352
|
-
if (lower.includes(this.xmpToColorSpaceWorkup("rgb", "colormode")) && lower.includes("adobe rgb"))
|
|
353
|
-
return "adobe_rgb";
|
|
354
|
-
if (lower.includes(this.xmpToColorSpaceWorkup("grayscale", "colormode")))
|
|
355
|
-
return "gray";
|
|
356
|
-
return fallback;
|
|
357
|
-
}
|
|
358
|
-
mapProfileToColorSpace(profileName, fallback) {
|
|
359
|
-
if (!profileName || profileName === "embedded" || profileName.toLowerCase().includes("icc profile"))
|
|
360
|
-
return fallback;
|
|
361
|
-
const lower = profileName.toLowerCase();
|
|
362
|
-
if (lower.includes("srgb") || lower.includes("iec61966") || lower.includes("srgb2014"))
|
|
363
|
-
return "srgb";
|
|
364
|
-
if (lower.includes("display p3") || lower.includes("display-p3") || lower.includes("dci-p3") || lower.includes("p3"))
|
|
365
|
-
return "display_p3";
|
|
366
|
-
if (lower.includes("adobe rgb") || lower.includes("adobergb") || lower.includes("adobe rgb (1998)"))
|
|
367
|
-
return "adobe_rgb";
|
|
368
|
-
if (lower.includes("prophoto rgb") || lower.includes("prophoto") || lower.includes("romm rgb") || lower.includes("romm") || lower.includes("iso 22028"))
|
|
369
|
-
return "prophoto_rgb";
|
|
370
|
-
if (lower.includes("rec2020") || lower.includes("bt.2020") || lower.includes("bt2020") || lower.includes("bt.2100") || lower.includes("itur_2100"))
|
|
371
|
-
return "rec2020";
|
|
372
|
-
if (lower.includes("rec709") || lower.includes("bt.709") || lower.includes("bt709"))
|
|
373
|
-
return "rec709";
|
|
374
|
-
if (lower.includes("cmyk")) return "cmyk";
|
|
375
|
-
if (lower.includes("lab")) return "lab";
|
|
376
|
-
if (lower.includes("xyz")) return "xyz";
|
|
377
|
-
if (lower.includes("gray") || lower.includes("grey") || lower.includes("monochrome") || lower.includes("gamma") || lower.includes("gamma 2.2") || lower.includes("dot gain"))
|
|
378
|
-
return "gray";
|
|
379
|
-
return fallback;
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
export {
|
|
384
|
-
ImageServiceWorkup
|
|
385
|
-
};
|
|
386
|
-
//# sourceMappingURL=chunk-5CACVZVF.js.map
|
package/dist/chunk-5H6GE5AO.js
DELETED
package/dist/chunk-7JQ56XIH.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FsTmp
|
|
3
|
-
} from "./chunk-PATMSIQK.js";
|
|
4
|
-
import {
|
|
5
|
-
__name
|
|
6
|
-
} from "./chunk-7QVYU63E.js";
|
|
7
|
-
|
|
8
|
-
// src/fs-fetch/index.ts
|
|
9
|
-
import fsSync from "fs";
|
|
10
|
-
import { relative } from "path";
|
|
11
|
-
var FsFetch = class extends FsTmp {
|
|
12
|
-
constructor(cwd) {
|
|
13
|
-
super(cwd ??= process.cwd());
|
|
14
|
-
this.cwd = cwd;
|
|
15
|
-
}
|
|
16
|
-
static {
|
|
17
|
-
__name(this, "FsFetch");
|
|
18
|
-
}
|
|
19
|
-
async assetToBuffer(path) {
|
|
20
|
-
const [fetcher] = await Promise.all([
|
|
21
|
-
fetch(path).then((t) => t.arrayBuffer())
|
|
22
|
-
]);
|
|
23
|
-
const mime = this.getMimeTypeForPath(path);
|
|
24
|
-
const b64encodedData = `data:${mime};base64, ${Buffer.from(fetcher).toString("base64")}`;
|
|
25
|
-
const extension = this.assetType(path) ?? "txt";
|
|
26
|
-
return {
|
|
27
|
-
b64encodedData,
|
|
28
|
-
extension
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
async assetToBufferView(path) {
|
|
32
|
-
const response = await fetch(path, { method: "GET" });
|
|
33
|
-
if (!response.ok) {
|
|
34
|
-
throw new Error(`Failed to fetch asset: ${response.statusText}`);
|
|
35
|
-
}
|
|
36
|
-
const reader = response.body?.getReader();
|
|
37
|
-
if (reader) {
|
|
38
|
-
const chunks = Array.of();
|
|
39
|
-
while (true) {
|
|
40
|
-
const { done, value } = await reader.read();
|
|
41
|
-
if (done) break;
|
|
42
|
-
if (value) chunks.push(value);
|
|
43
|
-
}
|
|
44
|
-
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
45
|
-
const completeBuffer = new Uint8Array(totalLength);
|
|
46
|
-
let offset = 0;
|
|
47
|
-
for (const chunk of chunks) {
|
|
48
|
-
completeBuffer.set(chunk, offset);
|
|
49
|
-
offset += chunk.length;
|
|
50
|
-
}
|
|
51
|
-
const mime = this.getMimeTypeForPath(path);
|
|
52
|
-
const b64encodedData = `data:${mime};base64, ${Buffer.from(completeBuffer).toString("base64")}`;
|
|
53
|
-
const extension = this.assetType(path);
|
|
54
|
-
return { b64encodedData, extension };
|
|
55
|
-
} else {
|
|
56
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
57
|
-
const mime = this.getMimeTypeForPath(path);
|
|
58
|
-
const b64encodedData = `data:${mime};base64, ${Buffer.from(arrayBuffer).toString("base64")}`;
|
|
59
|
-
const extension = this.assetType(path);
|
|
60
|
-
return { b64encodedData, extension };
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
*
|
|
65
|
-
* @param inputUrl remote url to fetch data from
|
|
66
|
-
* @param outputPath desired output path relative to the cwd
|
|
67
|
-
* @param useDetectedExtension optional, defaults to true
|
|
68
|
-
*
|
|
69
|
-
* if `useDetectedExtension` is false you must include the file extension in your output path →
|
|
70
|
-
*
|
|
71
|
-
* 🚫 'public/assets/image-1'
|
|
72
|
-
*
|
|
73
|
-
* ✅ 'public/assets/image-1.png'
|
|
74
|
-
*/
|
|
75
|
-
async fetchRemoteWriteLocal(inputUrl, outputPath, useDetectedExtension = true) {
|
|
76
|
-
try {
|
|
77
|
-
const result = await this.assetToBufferView(inputUrl);
|
|
78
|
-
const cleanData = this.cleanDataUrl(result.b64encodedData);
|
|
79
|
-
const formattedPath = useDetectedExtension ? `${outputPath}.${result.extension}` : outputPath;
|
|
80
|
-
if (/\./g.test(formattedPath) === false) {
|
|
81
|
-
throw new Error(
|
|
82
|
-
"either add false as the third argument in `fetchRemoteWriteLocal` (input, output, use-detected-file-extension) or provide an output path without a file extension"
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
|
|
86
|
-
} catch (err) {
|
|
87
|
-
return console.error(err);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
knownToBlockHead(inputUrl) {
|
|
91
|
-
if (inputUrl.startsWith("https://github.com")) {
|
|
92
|
-
return "GET";
|
|
93
|
-
} else if (inputUrl.startsWith("https://raw.githubusercontent.com")) {
|
|
94
|
-
return "GET";
|
|
95
|
-
} else {
|
|
96
|
-
return "HEAD";
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
*
|
|
101
|
-
* @param inputUrl remote url to fetch data from
|
|
102
|
-
* @param outputPath desired output path relative to the cwd
|
|
103
|
-
* @param useDetectedExtension optional, defaults to true
|
|
104
|
-
*
|
|
105
|
-
* if `useDetectedExtension` is false you must include the file extension in your output path →
|
|
106
|
-
*
|
|
107
|
-
* 🚫 'public/assets/image-1'
|
|
108
|
-
*
|
|
109
|
-
* ✅ 'public/assets/image-1.png'
|
|
110
|
-
*
|
|
111
|
-
* @description
|
|
112
|
-
* This method is designed for all files regardless of size, but especially for
|
|
113
|
-
* larger files that may not fit into memory (it intelligently determines the best approach on the fly)
|
|
114
|
-
* For files > 100 MB, it streams the data directly to disk instead of loading it all into memory
|
|
115
|
-
*/
|
|
116
|
-
async fetchRemoteWriteLocalLargeFiles(inputUrl, outputPathI, useDetectedExtension = true) {
|
|
117
|
-
if (!URL.canParse(inputUrl))
|
|
118
|
-
throw new Error(`invalid URL ${inputUrl} is unable to be parsed`);
|
|
119
|
-
try {
|
|
120
|
-
const [head, meta] = await Promise.all([
|
|
121
|
-
fetch(inputUrl, {
|
|
122
|
-
method: this.knownToBlockHead(inputUrl)
|
|
123
|
-
}),
|
|
124
|
-
this.extractRemote(inputUrl, 4096 * 48)
|
|
125
|
-
]);
|
|
126
|
-
let ct;
|
|
127
|
-
let ext;
|
|
128
|
-
let size;
|
|
129
|
-
const s = head.headers.get("Content-Type");
|
|
130
|
-
const cl = head.headers.get("content-length");
|
|
131
|
-
if (meta.contentType && meta.byteSize && meta.format) {
|
|
132
|
-
if (!s?.startsWith("image/") || !s?.startsWith("text") || !s?.startsWith("application")) {
|
|
133
|
-
ct = meta.contentType;
|
|
134
|
-
ext = this.toExtObj[s][0];
|
|
135
|
-
size = meta.byteSize;
|
|
136
|
-
} else {
|
|
137
|
-
ct = meta.contentType;
|
|
138
|
-
ext = meta.format;
|
|
139
|
-
size = meta.byteSize;
|
|
140
|
-
}
|
|
141
|
-
} else {
|
|
142
|
-
const assetTypeViaUrl = this.assetType(inputUrl);
|
|
143
|
-
ct = head.headers.get("Content-Type") ?? "application/octet-stream";
|
|
144
|
-
ext = typeof assetTypeViaUrl === "undefined" ? this.toExtObj[ct][0] : assetTypeViaUrl;
|
|
145
|
-
size = cl ? Number.parseInt(cl, 10) / (1024 * 1024) : 0;
|
|
146
|
-
}
|
|
147
|
-
const { unit, value } = this.autoFileSizeRaw(size);
|
|
148
|
-
console.log(
|
|
149
|
-
`fetchRemoteWriteLocalLargeFiles extracting a file of size ${value} ${unit}`
|
|
150
|
-
);
|
|
151
|
-
const formattedPath = useDetectedExtension ? `${outputPathI}.${ext}` : outputPathI;
|
|
152
|
-
this.generateDirIfDNE(this.pathHandler(formattedPath), {
|
|
153
|
-
recursive: true
|
|
154
|
-
});
|
|
155
|
-
const writeStream = fsSync.createWriteStream(
|
|
156
|
-
relative(this.cwd, formattedPath)
|
|
157
|
-
);
|
|
158
|
-
const res = await fetch(inputUrl);
|
|
159
|
-
if (!res.ok || !res.body) {
|
|
160
|
-
throw new Error(`Failed to fetch asset: ${res.statusText}`);
|
|
161
|
-
}
|
|
162
|
-
const { promise, reject, resolve } = Promise.withResolvers();
|
|
163
|
-
writeStream.on("finish", () => resolve({}));
|
|
164
|
-
writeStream.on("error", () => reject({}));
|
|
165
|
-
const reader = res.body.getReader();
|
|
166
|
-
const pump = /* @__PURE__ */ __name(async () => {
|
|
167
|
-
while (true) {
|
|
168
|
-
const { done, value: value2 } = await reader.read();
|
|
169
|
-
if (done) break;
|
|
170
|
-
writeStream.write(value2);
|
|
171
|
-
}
|
|
172
|
-
writeStream.end();
|
|
173
|
-
}, "pump");
|
|
174
|
-
await pump();
|
|
175
|
-
await promise.then(() => {
|
|
176
|
-
});
|
|
177
|
-
return;
|
|
178
|
-
} catch (err) {
|
|
179
|
-
console.error(`[fetchRemoteWriteLocalLargeFiles error]:`, err);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
export {
|
|
185
|
-
FsFetch
|
|
186
|
-
};
|
|
187
|
-
//# sourceMappingURL=chunk-7JQ56XIH.js.map
|
package/dist/chunk-7LOAFIZM.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FsFetch
|
|
3
|
-
} from "./chunk-7JQ56XIH.js";
|
|
4
|
-
import {
|
|
5
|
-
__name
|
|
6
|
-
} from "./chunk-7QVYU63E.js";
|
|
7
|
-
|
|
8
|
-
// src/fs/index.ts
|
|
9
|
-
import { resolve } from "path";
|
|
10
|
-
import sharp from "sharp";
|
|
11
|
-
var Fs = class extends FsFetch {
|
|
12
|
-
constructor(cwd) {
|
|
13
|
-
super(cwd ??= process.cwd());
|
|
14
|
-
this.cwd = cwd;
|
|
15
|
-
cwd ??= process.cwd();
|
|
16
|
-
}
|
|
17
|
-
static {
|
|
18
|
-
__name(this, "Fs");
|
|
19
|
-
}
|
|
20
|
-
async getImageSpecs(filePath, size = 4096 * 36) {
|
|
21
|
-
if (filePath.startsWith("https")) {
|
|
22
|
-
return await this.extractRemoteFs(filePath, size);
|
|
23
|
-
}
|
|
24
|
-
return await this.extractViaPath(filePath, size);
|
|
25
|
-
}
|
|
26
|
-
async getImageSpecsFlexi(target, size = 4096 * 36) {
|
|
27
|
-
if (Buffer.isBuffer(target)) {
|
|
28
|
-
return this.getImageSpecsWorkupFs(target, size);
|
|
29
|
-
} else {
|
|
30
|
-
return await this.getImageSpecs(target, size);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async getImageSpecsTmp(filepath, size = 4096 * 36) {
|
|
34
|
-
return this.extractViaPath(resolve(this.tmpDir, filepath), size);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Extract image metadata using streaming (only reads ~4KB)
|
|
38
|
-
* Much more memory efficient for large images
|
|
39
|
-
*/
|
|
40
|
-
async getImageSpecsStream(filePath, size = 4096 * 36) {
|
|
41
|
-
return this.extractFromPath(filePath, size);
|
|
42
|
-
}
|
|
43
|
-
async getImageSpecsStreamTmp(filePath) {
|
|
44
|
-
return this.extractFromPath(resolve(this.tmpDir, filePath));
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
*
|
|
48
|
-
* @access package-private
|
|
49
|
-
*
|
|
50
|
-
* work in progress, for internal package maintainer use only
|
|
51
|
-
*/
|
|
52
|
-
// USE fluent-ffmpeg for video/animated image transforms (apng, etc)
|
|
53
|
-
// https://www.npmjs.com/package/fluent-ffmpeg
|
|
54
|
-
// https://www.npmjs.com/package/@types/fluent-ffmpeg
|
|
55
|
-
async imageTransform({
|
|
56
|
-
format,
|
|
57
|
-
target,
|
|
58
|
-
quality = 80,
|
|
59
|
-
tint,
|
|
60
|
-
resize
|
|
61
|
-
}) {
|
|
62
|
-
if (tint && !resize) {
|
|
63
|
-
return await sharp(target).toFormat(format, { quality }).tint(tint).toBuffer();
|
|
64
|
-
} else if (!tint && resize) {
|
|
65
|
-
return await sharp(target).toFormat(format, { quality }).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
|
|
66
|
-
} else if (tint && resize) {
|
|
67
|
-
return await sharp(target).toFormat(format, { quality }).tint(tint).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
|
|
68
|
-
} else {
|
|
69
|
-
return await sharp(target).toFormat(format, { quality }).toBuffer();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export {
|
|
75
|
-
Fs
|
|
76
|
-
};
|
|
77
|
-
//# sourceMappingURL=chunk-7LOAFIZM.js.map
|