@hussmartinez/image-sdk 0.1.0 → 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/README.md +98 -9
- package/dist/assets/image/render.worker.js +1 -1
- package/dist/element.d.ts +32 -2
- package/dist/element.js +2 -2
- package/dist/index.d.ts +41 -3
- package/dist/index.js +1 -1
- package/dist/lazy/{inline-worker-BVCwAPZU.js → inline-worker-l_ynDNuS.js} +2 -2
- package/dist/lazy/{inline-worker-BVCwAPZU.js.map → inline-worker-l_ynDNuS.js.map} +1 -1
- package/dist/react.d.ts +85 -2
- package/dist/react.js +1 -1
- package/dist/shared/{core-cKo2m54U.js → core-BWNmXDlB.js} +271 -79
- package/dist/shared/core-BWNmXDlB.js.map +1 -0
- package/dist/shared/{editor-Dv5EU2YJ.js → editor-CJXEK6MY.js} +262 -75
- package/dist/shared/editor-CJXEK6MY.js.map +1 -0
- package/dist/styles.css +126 -19
- package/package.json +8 -7
- package/dist/shared/core-cKo2m54U.js.map +0 -1
- package/dist/shared/editor-Dv5EU2YJ.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SdkError, applyCommands, coreLimits, createErrorHelpers, createHistory, createStore, createWorkerClient, defineLimits, defineMessages, isSdkError, plural,
|
|
1
|
+
import { SdkError, applyCommands, coreLimits, createAssetsResolver, createErrorHelpers, createHistory, createStore, createWorkerClient, defineLimits, defineMessages, isSdkError, plural, sdkCoreMessages, withProcessingTime } from "@hussmartinez/sdk-core";
|
|
2
2
|
import { uiMessages } from "@hussmartinez/ui";
|
|
3
3
|
// src/core/errors/image-error.ts
|
|
4
4
|
var ImageError = class extends SdkError {
|
|
@@ -73,78 +73,200 @@ function checkOutputLimits(policy, size) {
|
|
|
73
73
|
policy.check("maxImageDimension", Math.max(size.width, size.height));
|
|
74
74
|
policy.check("maxImagePixels", size.width * size.height);
|
|
75
75
|
}
|
|
76
|
+
// src/adapters/worker-lifecycle.ts
|
|
77
|
+
function createWorkerLifecycle(clearSources, submitted) {
|
|
78
|
+
let current;
|
|
79
|
+
let sequence = 0;
|
|
80
|
+
let terminal = false;
|
|
81
|
+
let destroyed = false;
|
|
82
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
83
|
+
const invalidated = () => new ImageError("WORKER_TERMINATED", "Recreate the image engine before reopening the image.", { details: { reason: "engine-invalidated" } });
|
|
84
|
+
const check = (generation) => {
|
|
85
|
+
if (destroyed) throw new Error("The image engine has been destroyed.");
|
|
86
|
+
if (terminal || generation && (generation.closed || generation !== current)) throw invalidated();
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
check,
|
|
90
|
+
current: () => current,
|
|
91
|
+
getSnapshot: () => terminal,
|
|
92
|
+
subscribe(listener) {
|
|
93
|
+
const notify = () => listener();
|
|
94
|
+
listeners.add(notify);
|
|
95
|
+
return () => {
|
|
96
|
+
listeners.delete(notify);
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
destroy() {
|
|
100
|
+
destroyed = true;
|
|
101
|
+
listeners.clear();
|
|
102
|
+
clearSources();
|
|
103
|
+
},
|
|
104
|
+
wrap(worker) {
|
|
105
|
+
check();
|
|
106
|
+
const generation = {
|
|
107
|
+
number: ++sequence,
|
|
108
|
+
closed: false,
|
|
109
|
+
ownsResources: false
|
|
110
|
+
};
|
|
111
|
+
current = generation;
|
|
112
|
+
return {
|
|
113
|
+
postMessage(message, transfer) {
|
|
114
|
+
check(generation);
|
|
115
|
+
const call = message;
|
|
116
|
+
if (call?.type === "call" && (call.method === "register" || call.method === "attachCanvas")) generation.ownsResources = true;
|
|
117
|
+
if (call?.type === "call" && call.method === "register" && typeof call.input?.id === "string") submitted(call.input.id, generation);
|
|
118
|
+
worker.postMessage(message, transfer);
|
|
119
|
+
},
|
|
120
|
+
addEventListener(type, listener) {
|
|
121
|
+
worker.addEventListener(type, listener);
|
|
122
|
+
},
|
|
123
|
+
removeEventListener(type, listener) {
|
|
124
|
+
worker.removeEventListener(type, listener);
|
|
125
|
+
},
|
|
126
|
+
terminate() {
|
|
127
|
+
if (generation.closed) return;
|
|
128
|
+
generation.closed = true;
|
|
129
|
+
try {
|
|
130
|
+
if (current !== generation) return;
|
|
131
|
+
clearSources();
|
|
132
|
+
if (destroyed || !generation.ownsResources || terminal) return;
|
|
133
|
+
terminal = true;
|
|
134
|
+
const notified = [...listeners];
|
|
135
|
+
queueMicrotask(() => {
|
|
136
|
+
if (destroyed) return;
|
|
137
|
+
for (const listener of notified) {
|
|
138
|
+
if (!listeners.has(listener)) continue;
|
|
139
|
+
try {
|
|
140
|
+
listener();
|
|
141
|
+
} catch {}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
} finally {
|
|
145
|
+
worker.terminate();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function closeRejectedResult(value) {
|
|
153
|
+
if (value && typeof value === "object" && "close" in value && typeof value.close === "function") try {
|
|
154
|
+
value.close();
|
|
155
|
+
} catch {}
|
|
156
|
+
}
|
|
76
157
|
// src/adapters/image-engine.ts
|
|
77
158
|
var ENGINE_INTERNALS = Symbol("hm-image-engine");
|
|
78
159
|
function engineInternals(engine) {
|
|
79
160
|
return engine[ENGINE_INTERNALS];
|
|
80
161
|
}
|
|
81
162
|
function createImageEngine(options = {}) {
|
|
82
|
-
const
|
|
83
|
-
|
|
163
|
+
const asset = options.assetsUrl === void 0 ? void 0 : createAssetsResolver(options.assetsUrl);
|
|
164
|
+
let workerUrl;
|
|
84
165
|
return createEngine({
|
|
85
|
-
loadWorker:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
166
|
+
loadWorker: asset ? async () => () => {
|
|
167
|
+
workerUrl = asset("image/render.worker.js");
|
|
168
|
+
return new Worker(workerUrl, {
|
|
169
|
+
type: "module",
|
|
170
|
+
name: "hm-image-render"
|
|
171
|
+
});
|
|
172
|
+
} : async () => (await import("../lazy/inline-worker-l_ynDNuS.js")).createInlineWorker,
|
|
173
|
+
version: "0.3.0",
|
|
174
|
+
get asset() {
|
|
175
|
+
return workerUrl ?? "inline";
|
|
176
|
+
}
|
|
91
177
|
});
|
|
92
178
|
}
|
|
93
179
|
function createEngine(environment) {
|
|
94
180
|
let startWorker;
|
|
95
181
|
let destroyed = false;
|
|
96
|
-
const ids = /* @__PURE__ */ new
|
|
182
|
+
const ids = /* @__PURE__ */ new Map();
|
|
183
|
+
const lifecycle = createWorkerLifecycle(() => ids.clear(), (id, generation) => {
|
|
184
|
+
const reservation = ids.get(id);
|
|
185
|
+
if (reservation) reservation.generation = generation;
|
|
186
|
+
});
|
|
97
187
|
const client = createWorkerClient({
|
|
98
188
|
createWorker: () => {
|
|
99
189
|
if (!startWorker) throw new ImageError("WORKER_START_FAILED", "The render worker hasn't loaded.");
|
|
100
|
-
return startWorker();
|
|
190
|
+
return lifecycle.wrap(startWorker());
|
|
101
191
|
},
|
|
102
192
|
errorClasses: { ImageError },
|
|
103
193
|
idleTimeout: 0,
|
|
104
194
|
cancelTimeout: 3e4,
|
|
105
|
-
onCrash: () => ids.clear(),
|
|
106
195
|
packageVersion: environment.version,
|
|
107
|
-
workerAsset
|
|
196
|
+
get workerAsset() {
|
|
197
|
+
return environment.asset ?? "inline";
|
|
198
|
+
}
|
|
108
199
|
});
|
|
109
200
|
async function ready() {
|
|
110
201
|
if (destroyed) throw new Error("The image engine has been destroyed.");
|
|
111
202
|
startWorker ??= await environment.loadWorker();
|
|
112
203
|
}
|
|
113
|
-
async
|
|
114
|
-
|
|
204
|
+
const call = async (method, input, options) => {
|
|
205
|
+
lifecycle.check();
|
|
206
|
+
throwIfAborted(options?.signal);
|
|
207
|
+
await ready();
|
|
208
|
+
lifecycle.check();
|
|
209
|
+
const pending = client.call(method, input, options);
|
|
210
|
+
const generation = lifecycle.current();
|
|
211
|
+
const result = await pending.catch((error) => {
|
|
212
|
+
throw error instanceof TypeError ? error : asImageError(error);
|
|
213
|
+
});
|
|
214
|
+
try {
|
|
215
|
+
lifecycle.check(generation);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
closeRejectedResult(result);
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
return result;
|
|
221
|
+
};
|
|
222
|
+
const prepare = async () => {
|
|
223
|
+
lifecycle.check();
|
|
224
|
+
await ready();
|
|
225
|
+
lifecycle.check();
|
|
226
|
+
const pending = client.start();
|
|
227
|
+
const generation = lifecycle.current();
|
|
115
228
|
try {
|
|
116
|
-
await
|
|
117
|
-
return await work();
|
|
229
|
+
await pending;
|
|
118
230
|
} catch (error) {
|
|
119
|
-
if (error instanceof TypeError) throw error;
|
|
120
|
-
if (signal?.aborted) throw abortError(signal);
|
|
121
231
|
throw asImageError(error);
|
|
122
232
|
}
|
|
123
|
-
|
|
233
|
+
lifecycle.check(generation);
|
|
234
|
+
if (!generation) throw new Error("The worker did not create a generation.");
|
|
235
|
+
return generation;
|
|
236
|
+
};
|
|
124
237
|
const callOptions = (options) => options?.signal ? { signal: options.signal } : {};
|
|
125
238
|
return {
|
|
126
239
|
[ENGINE_INTERNALS]: {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
240
|
+
call,
|
|
241
|
+
prepare,
|
|
242
|
+
check: lifecycle.check,
|
|
243
|
+
getSnapshot: lifecycle.getSnapshot,
|
|
244
|
+
subscribe: lifecycle.subscribe,
|
|
245
|
+
has: (id) => ids.get(id)?.registered === true
|
|
132
246
|
},
|
|
133
247
|
probe(file, options) {
|
|
134
|
-
return
|
|
248
|
+
return call("probe", { file }, callOptions(options));
|
|
135
249
|
},
|
|
136
250
|
async register(id, file, probe, options) {
|
|
137
|
-
|
|
251
|
+
lifecycle.check();
|
|
138
252
|
if (ids.has(id)) throw new TypeError(`The source id "${id}" is already in use.`);
|
|
139
|
-
|
|
253
|
+
const reservation = {
|
|
254
|
+
registered: false,
|
|
255
|
+
released: false
|
|
256
|
+
};
|
|
257
|
+
ids.set(id, reservation);
|
|
140
258
|
try {
|
|
141
|
-
const size = await
|
|
259
|
+
const size = await call("register", {
|
|
142
260
|
id,
|
|
143
261
|
file,
|
|
144
262
|
probe,
|
|
145
263
|
limits: Object.fromEntries(PER_FILE_LIMITS.map((limit) => [limit, (options?.filePolicy ?? imageLimits.resolve()).limits[limit].maximum]))
|
|
146
|
-
}, callOptions(options))
|
|
264
|
+
}, callOptions(options));
|
|
265
|
+
lifecycle.check(reservation.generation);
|
|
266
|
+
if (reservation.released) throw new TypeError("The source was released during registration.");
|
|
267
|
+
reservation.registered = true;
|
|
147
268
|
options?.onProgress?.(1);
|
|
269
|
+
lifecycle.check(reservation.generation);
|
|
148
270
|
return {
|
|
149
271
|
id,
|
|
150
272
|
format: probe.format,
|
|
@@ -155,27 +277,35 @@ function createEngine(environment) {
|
|
|
155
277
|
decodedBytes: size.width * size.height * 4
|
|
156
278
|
};
|
|
157
279
|
} catch (error) {
|
|
158
|
-
ids.delete(id);
|
|
159
|
-
if (options?.signal?.aborted && !destroyed)
|
|
280
|
+
if (ids.get(id) === reservation) ids.delete(id);
|
|
281
|
+
if ((options?.signal?.aborted || reservation.released) && reservation.generation && !reservation.generation.closed && !destroyed && !lifecycle.getSnapshot()) call("release", { id }).catch(() => void 0);
|
|
160
282
|
throw error;
|
|
161
283
|
}
|
|
162
284
|
},
|
|
163
285
|
async thumbnail(id, maxSize, options) {
|
|
164
|
-
|
|
286
|
+
lifecycle.check();
|
|
287
|
+
if (!ids.get(id)?.registered) throw new TypeError(`There's no source with the id "${id}".`);
|
|
165
288
|
if (!(maxSize >= 1)) throw new RangeError("maxSize must be at least 1.");
|
|
166
|
-
return
|
|
289
|
+
return call("thumbnail", {
|
|
167
290
|
id,
|
|
168
291
|
maxSize
|
|
169
|
-
}, callOptions(options))
|
|
292
|
+
}, callOptions(options));
|
|
170
293
|
},
|
|
171
294
|
async release(id) {
|
|
172
|
-
|
|
173
|
-
|
|
295
|
+
const reservation = ids.get(id);
|
|
296
|
+
if (!reservation) return;
|
|
297
|
+
if (!reservation.registered) {
|
|
298
|
+
reservation.released = true;
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
ids.delete(id);
|
|
302
|
+
if (destroyed || lifecycle.getSnapshot() || reservation.generation?.closed) return;
|
|
303
|
+
await call("release", { id });
|
|
174
304
|
},
|
|
175
305
|
async destroy() {
|
|
176
306
|
if (destroyed) return;
|
|
177
307
|
destroyed = true;
|
|
178
|
-
|
|
308
|
+
lifecycle.destroy();
|
|
179
309
|
client.destroy();
|
|
180
310
|
}
|
|
181
311
|
};
|
|
@@ -198,21 +328,22 @@ function createImageProcessor(engine) {
|
|
|
198
328
|
if (format.type !== "png" && format.quality !== void 0) {
|
|
199
329
|
if (!(format.quality >= 0 && format.quality <= 1)) throw new RangeError("quality must be from 0 to 1.");
|
|
200
330
|
}
|
|
331
|
+
internals.check();
|
|
201
332
|
if (!internals.has(plan.base.source)) throw new TypeError(`There's no source with the id "${plan.base.source}".`);
|
|
202
333
|
const signal = options?.signal;
|
|
203
334
|
throwIfAborted(signal);
|
|
204
335
|
const policy = options?.filePolicy ?? imageLimits.resolve();
|
|
205
336
|
try {
|
|
206
|
-
const blob = await
|
|
337
|
+
const blob = await internals.call("export", {
|
|
207
338
|
plan,
|
|
208
339
|
format,
|
|
209
340
|
limits: Object.fromEntries(OUTPUT_LIMITS.map((limit) => [limit, policy.limits[limit].maximum]))
|
|
210
341
|
}, signal ? { signal } : {});
|
|
211
342
|
options?.onProgress?.(1);
|
|
343
|
+
internals.check();
|
|
212
344
|
return blob;
|
|
213
345
|
} catch (error) {
|
|
214
346
|
if (error instanceof TypeError) throw error;
|
|
215
|
-
if (signal?.aborted) throw abortError(signal);
|
|
216
347
|
throw asImageError(error);
|
|
217
348
|
}
|
|
218
349
|
},
|
|
@@ -281,17 +412,22 @@ function createImageRenderer(engine) {
|
|
|
281
412
|
const onAbort = () => controller.abort(request.signal?.reason);
|
|
282
413
|
request.signal?.addEventListener("abort", onAbort, { once: true });
|
|
283
414
|
inFlight = { controller };
|
|
284
|
-
internals.
|
|
415
|
+
internals.call("render", {
|
|
285
416
|
id,
|
|
286
417
|
plan: request.plan,
|
|
287
418
|
view: request.view,
|
|
288
419
|
limits: request.limits
|
|
289
|
-
}, { signal: controller.signal })
|
|
420
|
+
}, { signal: controller.signal }).then(() => {
|
|
421
|
+
try {
|
|
422
|
+
internals.check();
|
|
423
|
+
} catch (error) {
|
|
424
|
+
request.reject(error);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
290
427
|
drawn += 1;
|
|
291
428
|
request.resolve("drawn");
|
|
292
429
|
}, (error) => {
|
|
293
|
-
if (request.signal?.aborted) request.
|
|
294
|
-
else if (controller.signal.aborted) request.resolve("superseded");
|
|
430
|
+
if (!internals.getSnapshot() && controller.signal.aborted && !request.signal?.aborted && isImageError(error, "ABORTED")) request.resolve("superseded");
|
|
295
431
|
else request.reject(error instanceof TypeError ? error : asImageError(error));
|
|
296
432
|
}).finally(() => {
|
|
297
433
|
request.signal?.removeEventListener("abort", onAbort);
|
|
@@ -301,19 +437,28 @@ function createImageRenderer(engine) {
|
|
|
301
437
|
};
|
|
302
438
|
return {
|
|
303
439
|
[RENDERER_INTERNALS]: {
|
|
304
|
-
snapshot: async () =>
|
|
440
|
+
snapshot: async () => internals.call("snapshot", { id }),
|
|
305
441
|
drawn: () => drawn
|
|
306
442
|
},
|
|
307
443
|
async attach(canvas) {
|
|
308
444
|
if (destroyed) throw new Error("The image renderer has been destroyed.");
|
|
445
|
+
internals.check();
|
|
309
446
|
if (attached) throw new TypeError("The renderer already has a canvas.");
|
|
310
447
|
if (typeof canvas.transferControlToOffscreen !== "function") throw new ImageError("UNSUPPORTED_ENVIRONMENT", "This browser can't draw the preview in a worker.", { details: { feature: "transferControlToOffscreen" } });
|
|
311
|
-
const offscreen = canvas.transferControlToOffscreen();
|
|
312
448
|
try {
|
|
313
|
-
|
|
449
|
+
const generation = await internals.prepare();
|
|
450
|
+
internals.check(generation);
|
|
451
|
+
if (destroyed) throw new Error("The image renderer has been destroyed.");
|
|
452
|
+
const offscreen = canvas.transferControlToOffscreen();
|
|
453
|
+
await internals.call("attachCanvas", {
|
|
314
454
|
id,
|
|
315
455
|
canvas: offscreen
|
|
316
456
|
}, { transfer: true });
|
|
457
|
+
internals.check(generation);
|
|
458
|
+
if (destroyed) {
|
|
459
|
+
await internals.call("detachCanvas", { id });
|
|
460
|
+
throw new Error("The image renderer has been destroyed.");
|
|
461
|
+
}
|
|
317
462
|
attached = true;
|
|
318
463
|
} catch (error) {
|
|
319
464
|
throw asImageError(error);
|
|
@@ -321,6 +466,11 @@ function createImageRenderer(engine) {
|
|
|
321
466
|
},
|
|
322
467
|
render(plan, view, options) {
|
|
323
468
|
if (destroyed) return Promise.reject(/* @__PURE__ */ new Error("The image renderer has been destroyed."));
|
|
469
|
+
try {
|
|
470
|
+
internals.check();
|
|
471
|
+
} catch (error) {
|
|
472
|
+
return Promise.reject(error);
|
|
473
|
+
}
|
|
324
474
|
if (!attached) return Promise.reject(/* @__PURE__ */ new TypeError("Attach a canvas before rendering."));
|
|
325
475
|
if (!internals.has(plan.base.source)) return Promise.reject(/* @__PURE__ */ new TypeError(`There's no source with the id "${plan.base.source}".`));
|
|
326
476
|
const policy = options?.filePolicy ?? imageLimits.resolve();
|
|
@@ -349,11 +499,16 @@ function createImageRenderer(engine) {
|
|
|
349
499
|
async destroy() {
|
|
350
500
|
if (destroyed) return;
|
|
351
501
|
destroyed = true;
|
|
352
|
-
pending
|
|
502
|
+
if (pending) try {
|
|
503
|
+
internals.check();
|
|
504
|
+
pending.resolve("superseded");
|
|
505
|
+
} catch (error) {
|
|
506
|
+
pending.reject(error);
|
|
507
|
+
}
|
|
353
508
|
pending = void 0;
|
|
354
509
|
inFlight?.controller.abort(new DOMException("The renderer was destroyed.", "AbortError"));
|
|
355
|
-
if (attached) try {
|
|
356
|
-
await
|
|
510
|
+
if (attached && !internals.getSnapshot()) try {
|
|
511
|
+
await internals.call("detachCanvas", { id });
|
|
357
512
|
} catch {}
|
|
358
513
|
}
|
|
359
514
|
};
|
|
@@ -1040,13 +1195,13 @@ function createImageSession(options) {
|
|
|
1040
1195
|
let nextId = 0;
|
|
1041
1196
|
let destroyed = false;
|
|
1042
1197
|
const snapshot = () => ({
|
|
1043
|
-
status: plan !== null ? "ready" : opening > 0 ? "opening" : "empty",
|
|
1198
|
+
status: plan !== null ? "ready" : !destroyed && opening > 0 ? "opening" : "empty",
|
|
1044
1199
|
plan,
|
|
1045
1200
|
source,
|
|
1046
1201
|
canUndo: history.canUndo,
|
|
1047
1202
|
canRedo: history.canRedo,
|
|
1048
|
-
opening: opening > 0,
|
|
1049
|
-
exporting: exporting > 0,
|
|
1203
|
+
opening: !destroyed && opening > 0,
|
|
1204
|
+
exporting: !destroyed && exporting > 0,
|
|
1050
1205
|
warnings,
|
|
1051
1206
|
error
|
|
1052
1207
|
});
|
|
@@ -1132,7 +1287,6 @@ function createImageSession(options) {
|
|
|
1132
1287
|
subscribe: (listener) => store.subscribe(listener),
|
|
1133
1288
|
async open(file, openOptions = {}) {
|
|
1134
1289
|
assertAlive();
|
|
1135
|
-
const { signal } = openOptions;
|
|
1136
1290
|
opens += 1;
|
|
1137
1291
|
const ticket = opens;
|
|
1138
1292
|
nextId += 1;
|
|
@@ -1141,22 +1295,31 @@ function createImageSession(options) {
|
|
|
1141
1295
|
opening += 1;
|
|
1142
1296
|
publish();
|
|
1143
1297
|
try {
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1298
|
+
const { probe, near, info } = await withProcessingTime(policy, async (signal) => {
|
|
1299
|
+
throwIfAborted(signal);
|
|
1300
|
+
policy.check("maxFileSize", file.size);
|
|
1301
|
+
const probe = await engine.probe(file, { signal });
|
|
1302
|
+
throwIfAborted(signal);
|
|
1303
|
+
const near = checkSource(policy, file, probe);
|
|
1304
|
+
if (ticket !== opens) throw superseded();
|
|
1305
|
+
const info = await engine.register(id, file, probe, {
|
|
1306
|
+
filePolicy: policy,
|
|
1307
|
+
signal
|
|
1308
|
+
});
|
|
1309
|
+
registered = true;
|
|
1310
|
+
throwIfAborted(signal);
|
|
1311
|
+
return {
|
|
1312
|
+
probe,
|
|
1313
|
+
near,
|
|
1314
|
+
info
|
|
1315
|
+
};
|
|
1316
|
+
}, openOptions);
|
|
1155
1317
|
assertAlive();
|
|
1156
1318
|
if (ticket !== opens) throw superseded();
|
|
1157
1319
|
const previous = source;
|
|
1158
1320
|
source = {
|
|
1159
1321
|
...info,
|
|
1322
|
+
fileSize: file.size,
|
|
1160
1323
|
metadata: probe.metadata,
|
|
1161
1324
|
keepable: probe.keepable
|
|
1162
1325
|
};
|
|
@@ -1176,7 +1339,7 @@ function createImageSession(options) {
|
|
|
1176
1339
|
if (registered && source?.id !== id) await engine.release(id).catch(() => {});
|
|
1177
1340
|
const failure = isImageError(reason) ? reason : asImageError(reason);
|
|
1178
1341
|
const cancelled = failure.code === "ABORTED";
|
|
1179
|
-
if (!cancelled) fail(failure);
|
|
1342
|
+
if (!cancelled && !destroyed && ticket === opens) fail(failure);
|
|
1180
1343
|
emit({
|
|
1181
1344
|
type: "open",
|
|
1182
1345
|
outcome: cancelled ? "cancelled" : "failed",
|
|
@@ -1185,7 +1348,7 @@ function createImageSession(options) {
|
|
|
1185
1348
|
throw failure;
|
|
1186
1349
|
} finally {
|
|
1187
1350
|
opening -= 1;
|
|
1188
|
-
publish();
|
|
1351
|
+
if (!destroyed) publish();
|
|
1189
1352
|
}
|
|
1190
1353
|
},
|
|
1191
1354
|
execute: (input) => executeCommands(input),
|
|
@@ -1208,7 +1371,7 @@ function createImageSession(options) {
|
|
|
1208
1371
|
redo: () => replay("redo"),
|
|
1209
1372
|
async export(format, exportOptions = {}) {
|
|
1210
1373
|
assertAlive();
|
|
1211
|
-
const {
|
|
1374
|
+
const { onProgress } = exportOptions;
|
|
1212
1375
|
if (plan === null || source === null) throw new ImageError("INVALID_COMMAND", "There's nothing to export before a file is open.");
|
|
1213
1376
|
const started = generation;
|
|
1214
1377
|
const exported = plan;
|
|
@@ -1217,14 +1380,19 @@ function createImageSession(options) {
|
|
|
1217
1380
|
publish();
|
|
1218
1381
|
try {
|
|
1219
1382
|
const size = outputSize(exported.output, compositionSize(exported, from));
|
|
1220
|
-
const blob = await
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1383
|
+
const blob = await withProcessingTime(policy, async (signal) => {
|
|
1384
|
+
throwIfAborted(signal);
|
|
1385
|
+
const blob = await processor.export({
|
|
1386
|
+
plan: exported,
|
|
1387
|
+
format
|
|
1388
|
+
}, {
|
|
1389
|
+
filePolicy: policy,
|
|
1390
|
+
signal,
|
|
1391
|
+
...onProgress ? { onProgress } : {}
|
|
1392
|
+
});
|
|
1393
|
+
throwIfAborted(signal);
|
|
1394
|
+
return blob;
|
|
1395
|
+
}, exportOptions);
|
|
1228
1396
|
if (started !== generation || destroyed) throw new ImageError("ABORTED", "Another file was opened during the export.", { details: { reason: "superseded" } });
|
|
1229
1397
|
error = null;
|
|
1230
1398
|
emit({
|
|
@@ -1242,7 +1410,7 @@ function createImageSession(options) {
|
|
|
1242
1410
|
} catch (reason) {
|
|
1243
1411
|
const failure = isImageError(reason) ? reason : asImageError(reason);
|
|
1244
1412
|
const cancelled = failure.code === "ABORTED";
|
|
1245
|
-
if (!cancelled) fail(failure);
|
|
1413
|
+
if (!cancelled && !destroyed && started === generation) fail(failure);
|
|
1246
1414
|
emit({
|
|
1247
1415
|
type: "export",
|
|
1248
1416
|
outcome: cancelled ? "cancelled" : "failed",
|
|
@@ -1270,6 +1438,7 @@ function createImageSession(options) {
|
|
|
1270
1438
|
var imageMessages = /* @__PURE__ */ defineMessages({
|
|
1271
1439
|
...sdkCoreMessages,
|
|
1272
1440
|
...uiMessages,
|
|
1441
|
+
"editor.engineUnavailable": "Image processing stopped. Reload this page or reopen the editor, then choose the image again. Unsaved edits will be lost unless your application has saved them.",
|
|
1273
1442
|
"errors.INVALID_IMAGE": "This file isn't a valid image, or it's too damaged to open.",
|
|
1274
1443
|
"errors.UNSUPPORTED_FORMAT": "This image format isn't supported. Try converting the file to PNG or JPEG, then open it again.",
|
|
1275
1444
|
"errors.DECODE_FAILED": "This browser can't open this kind of image. Try another browser, or convert the file to PNG or JPEG.",
|
|
@@ -1350,6 +1519,28 @@ var imageMessages = /* @__PURE__ */ defineMessages({
|
|
|
1350
1519
|
"inspector.label": "Panels",
|
|
1351
1520
|
"inspector.adjust": "Adjust",
|
|
1352
1521
|
"inspector.filters": "Filters",
|
|
1522
|
+
"inspector.info": "Info",
|
|
1523
|
+
"notices.label": "Notices",
|
|
1524
|
+
"notices.dismiss": "Dismiss",
|
|
1525
|
+
"notices.colourProfile": "This image has a colour profile. Colours outside sRGB will be clipped in the exported file.",
|
|
1526
|
+
"info.panel": "Image info",
|
|
1527
|
+
"info.size": "Size",
|
|
1528
|
+
"info.sizeValue": "{width, number} × {height, number} pixels",
|
|
1529
|
+
"info.format": "Format",
|
|
1530
|
+
"info.formats.png": "PNG",
|
|
1531
|
+
"info.formats.jpeg": "JPEG",
|
|
1532
|
+
"info.formats.webp": "WebP",
|
|
1533
|
+
"info.formats.gif": "GIF",
|
|
1534
|
+
"info.formats.avif": "AVIF",
|
|
1535
|
+
"info.formats.heif": "HEIF",
|
|
1536
|
+
"info.formats.bmp": "BMP",
|
|
1537
|
+
"info.frames": "Frames",
|
|
1538
|
+
"info.fileSize": "File size",
|
|
1539
|
+
"info.fileSizeValue": "{size, fileSize}",
|
|
1540
|
+
"info.metadata": "Metadata in the file",
|
|
1541
|
+
"info.metadataNone": "None",
|
|
1542
|
+
"info.kept": "Kept on export",
|
|
1543
|
+
"info.keptNone": "Nothing",
|
|
1353
1544
|
"develop.panel": "Adjust",
|
|
1354
1545
|
"develop.temperature": "Temperature",
|
|
1355
1546
|
"develop.tint": "Tint",
|
|
@@ -1382,6 +1573,7 @@ var imageMessages = /* @__PURE__ */ defineMessages({
|
|
|
1382
1573
|
"export.formats.jpeg": "JPEG",
|
|
1383
1574
|
"export.formats.webp": "WebP",
|
|
1384
1575
|
"export.quality": "Quality",
|
|
1576
|
+
"export.qualityValue": "{quality, number}%",
|
|
1385
1577
|
"export.size": "Size",
|
|
1386
1578
|
"export.sizes.scale": "Scale",
|
|
1387
1579
|
"export.sizes.fit": "Fit in a box",
|
|
@@ -1415,6 +1607,6 @@ var imageMessages = /* @__PURE__ */ defineMessages({
|
|
|
1415
1607
|
"export.download": "Download",
|
|
1416
1608
|
"export.close": "Done"
|
|
1417
1609
|
});
|
|
1418
|
-
export {
|
|
1610
|
+
export { imageLimitDefinitions as $, onlyFields as A, createPlan as B, checkFilter as C, createImageReducer as D, checkOutput as E, DEVELOP_ADJUSTMENTS as F, placement as G, MAX_PIXEL_RATIO as H, FILTER_PRESETS as I, engineInternals as J, createImageProcessor as K, FULL_SIZE as L, MAX_METADATA_LENGTH as M, NO_METADATA as N, invalid as O, longerThan as P, checkOutputLimits as Q, NEUTRAL_DEVELOP as R, checkDevelop as S, checkOrientation as T, backingSize as U, createImageRenderer as V, fittedView as W, PER_FILE_LIMITS as X, OUTPUT_LIMITS as Y, checkFileLimits as Z, outputSize as _, compositionDeltaToSource as a, checkCrop as b, fitAspect as c, nudgeCropOnScreen as d, imageLimits as et, wholeCrop as f, orientedSize as g, cropRect as h, aspectRatio as i, EMPTY_KEEPABLE_METADATA as j, isRecord as k, handleInSource as l, compositionToSource as m, createImageSession as n, isImageError as nt, cropInComposition as o, compositionSize as p, createImageEngine as q, ASPECT_PRESETS as r, dragHandle as s, imageMessages as t, ImageError as tt, moveCrop as u, sourceToComposition as v, checkMetadata as w, checkCropInSource as x, Invalid as y, UPRIGHT as z };
|
|
1419
1611
|
|
|
1420
|
-
//# sourceMappingURL=core-
|
|
1612
|
+
//# sourceMappingURL=core-BWNmXDlB.js.map
|