@sealpixel/core 1.0.0-rc.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 +3 -0
- package/dist/assets.d.ts +37 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +96 -0
- package/dist/assets.js.map +1 -0
- package/dist/canonical-json.d.ts +11 -0
- package/dist/canonical-json.d.ts.map +1 -0
- package/dist/canonical-json.js +48 -0
- package/dist/canonical-json.js.map +1 -0
- package/dist/compile.d.ts +30 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +64 -0
- package/dist/compile.js.map +1 -0
- package/dist/embedded.d.ts +13 -0
- package/dist/embedded.d.ts.map +1 -0
- package/dist/embedded.js +145 -0
- package/dist/embedded.js.map +1 -0
- package/dist/errors.d.ts +9 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +19 -0
- package/dist/errors.js.map +1 -0
- package/dist/external-kernel.d.ts +13 -0
- package/dist/external-kernel.d.ts.map +1 -0
- package/dist/external-kernel.js +68 -0
- package/dist/external-kernel.js.map +1 -0
- package/dist/generated/geometry.d.ts +33 -0
- package/dist/generated/geometry.d.ts.map +1 -0
- package/dist/generated/geometry.js +3 -0
- package/dist/generated/geometry.js.map +1 -0
- package/dist/generated/output.d.ts +40 -0
- package/dist/generated/output.d.ts.map +1 -0
- package/dist/generated/output.js +3 -0
- package/dist/generated/output.js.map +1 -0
- package/dist/generated/plan.d.ts +292 -0
- package/dist/generated/plan.d.ts.map +1 -0
- package/dist/generated/plan.js +3 -0
- package/dist/generated/plan.js.map +1 -0
- package/dist/history.d.ts +16 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +38 -0
- package/dist/history.js.map +1 -0
- package/dist/image-size.d.ts +12 -0
- package/dist/image-size.d.ts.map +1 -0
- package/dist/image-size.js +86 -0
- package/dist/image-size.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/inline-renderer.d.ts +28 -0
- package/dist/inline-renderer.d.ts.map +1 -0
- package/dist/inline-renderer.js +48 -0
- package/dist/inline-renderer.js.map +1 -0
- package/dist/options.d.ts +13 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +35 -0
- package/dist/options.js.map +1 -0
- package/dist/plan.d.ts +16 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +15 -0
- package/dist/plan.js.map +1 -0
- package/dist/plugin.d.ts +200 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +2 -0
- package/dist/plugin.js.map +1 -0
- package/dist/registry.d.ts +58 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +187 -0
- package/dist/registry.js.map +1 -0
- package/dist/render.d.ts +25 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +164 -0
- package/dist/render.js.map +1 -0
- package/dist/renderer-core.d.ts +82 -0
- package/dist/renderer-core.d.ts.map +1 -0
- package/dist/renderer-core.js +228 -0
- package/dist/renderer-core.js.map +1 -0
- package/dist/renderer.d.ts +29 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +2 -0
- package/dist/renderer.js.map +1 -0
- package/dist/session.d.ts +188 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +513 -0
- package/dist/session.js.map +1 -0
- package/dist/types.d.ts +114 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/worker-protocol.d.ts +100 -0
- package/dist/worker-protocol.d.ts.map +1 -0
- package/dist/worker-protocol.js +30 -0
- package/dist/worker-protocol.js.map +1 -0
- package/dist/worker-renderer.d.ts +35 -0
- package/dist/worker-renderer.d.ts.map +1 -0
- package/dist/worker-renderer.js +85 -0
- package/dist/worker-renderer.js.map +1 -0
- package/dist/worker.d.ts +23 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +81 -0
- package/dist/worker.js.map +1 -0
- package/package.json +45 -0
package/dist/session.js
ADDED
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import { webCryptoSha256, withAssets } from './assets.js';
|
|
2
|
+
import { compile } from './compile.js';
|
|
3
|
+
import { SealpixelError } from './errors.js';
|
|
4
|
+
import * as hist from './history.js';
|
|
5
|
+
import { readImageSize } from './image-size.js';
|
|
6
|
+
import { InlineRenderer } from './inline-renderer.js';
|
|
7
|
+
import { createRegistry } from './registry.js';
|
|
8
|
+
const EXT = {
|
|
9
|
+
'image/png': 'png',
|
|
10
|
+
'image/jpeg': 'jpg',
|
|
11
|
+
'image/webp': 'webp',
|
|
12
|
+
};
|
|
13
|
+
export function createEditorSession(options) {
|
|
14
|
+
const registry = createRegistry(options.plugins);
|
|
15
|
+
const maxClientMegapixels = options.limits?.maxClientMegapixels ?? 16;
|
|
16
|
+
const maxClientBytes = options.limits?.maxClientBytes ?? 20e6;
|
|
17
|
+
const renderer = options.renderer ??
|
|
18
|
+
new InlineRenderer({
|
|
19
|
+
plugins: options.plugins,
|
|
20
|
+
maxClientMegapixels,
|
|
21
|
+
proxyMaxSide: options.proxy?.maxSide ?? 2048,
|
|
22
|
+
});
|
|
23
|
+
// A renderer handed in by the host outlives this session: hosts reuse it across sessions.
|
|
24
|
+
const ownsRenderer = options.renderer === undefined;
|
|
25
|
+
const proxyStrategy = options.proxy?.strategy ?? 'auto';
|
|
26
|
+
const debounceMs = options.preview?.debounceMs ?? 80;
|
|
27
|
+
const previewEnabled = options.preview?.enabled ?? true;
|
|
28
|
+
const listeners = new Set();
|
|
29
|
+
let state = {
|
|
30
|
+
status: 'empty',
|
|
31
|
+
source: null,
|
|
32
|
+
resident: false,
|
|
33
|
+
history: hist.createHistory({
|
|
34
|
+
version: 1,
|
|
35
|
+
source: { id: '', width: 1, height: 1 },
|
|
36
|
+
plugins: registry.pluginVersions(),
|
|
37
|
+
ops: [],
|
|
38
|
+
}),
|
|
39
|
+
document: registry.initialDocument(),
|
|
40
|
+
version: 0,
|
|
41
|
+
preview: null,
|
|
42
|
+
previewPending: false,
|
|
43
|
+
error: null,
|
|
44
|
+
};
|
|
45
|
+
let previewTransform = null;
|
|
46
|
+
/** Original bytes, kept for server renders and the server proxy strategy. */
|
|
47
|
+
let originalBytes = null;
|
|
48
|
+
/** Bytes of assets added through `addAsset`, re-put after a renderer reload. */
|
|
49
|
+
const localAssets = new Map();
|
|
50
|
+
const resolver = options.assets
|
|
51
|
+
? {
|
|
52
|
+
declarations: () => options.assets?.declarations() ?? [],
|
|
53
|
+
resolve: async (id) => localAssets.get(id) ?? (await options.assets.resolve(id)),
|
|
54
|
+
}
|
|
55
|
+
: undefined;
|
|
56
|
+
let timer = null;
|
|
57
|
+
let inflight = null;
|
|
58
|
+
let idleResolvers = [];
|
|
59
|
+
let disposed = false;
|
|
60
|
+
const emit = () => {
|
|
61
|
+
for (const l of listeners)
|
|
62
|
+
l(state);
|
|
63
|
+
};
|
|
64
|
+
const set = (patch) => {
|
|
65
|
+
state = { ...state, ...patch };
|
|
66
|
+
emit();
|
|
67
|
+
};
|
|
68
|
+
const settleIdle = () => {
|
|
69
|
+
if (!state.previewPending && !timer && !inflight) {
|
|
70
|
+
const resolvers = idleResolvers;
|
|
71
|
+
idleResolvers = [];
|
|
72
|
+
for (const r of resolvers)
|
|
73
|
+
r();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const setHistory = (history) => {
|
|
77
|
+
if (history === state.history)
|
|
78
|
+
return;
|
|
79
|
+
set({
|
|
80
|
+
history,
|
|
81
|
+
document: compile(hist.current(history), registry),
|
|
82
|
+
version: state.version + 1,
|
|
83
|
+
});
|
|
84
|
+
schedulePreview();
|
|
85
|
+
};
|
|
86
|
+
function schedulePreview() {
|
|
87
|
+
if (!previewEnabled || state.status !== 'ready')
|
|
88
|
+
return;
|
|
89
|
+
if (timer)
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
set({ previewPending: true });
|
|
92
|
+
timer = setTimeout(() => {
|
|
93
|
+
timer = null;
|
|
94
|
+
void runPreview();
|
|
95
|
+
}, debounceMs);
|
|
96
|
+
}
|
|
97
|
+
async function runPreview() {
|
|
98
|
+
if (state.status !== 'ready') {
|
|
99
|
+
set({ previewPending: false });
|
|
100
|
+
settleIdle();
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
inflight?.controller.abort();
|
|
104
|
+
const version = state.version;
|
|
105
|
+
const controller = new AbortController();
|
|
106
|
+
inflight = { version, controller };
|
|
107
|
+
const base = hist.current(state.history);
|
|
108
|
+
const log = previewTransform ? previewTransform(base) : base;
|
|
109
|
+
try {
|
|
110
|
+
const [image, geometry, viewGeometry] = await Promise.all([
|
|
111
|
+
withAssets(() => renderer.render({ log, target: 'proxy', signal: controller.signal }), resolver, (id, bytes) => renderer.putAsset(id, bytes)),
|
|
112
|
+
// Geometry always describes the real output, even when a preview
|
|
113
|
+
// transform shows something else on the stage.
|
|
114
|
+
renderer.geometry({ log: base, target: 'proxy' }),
|
|
115
|
+
// The stage needs the geometry of what it shows to keep the view steady.
|
|
116
|
+
previewTransform ? renderer.geometry({ log, target: 'proxy' }) : null,
|
|
117
|
+
]);
|
|
118
|
+
if (disposed || controller.signal.aborted || version !== state.version)
|
|
119
|
+
return null;
|
|
120
|
+
const preview = { image, geometry, viewGeometry: viewGeometry ?? geometry, version };
|
|
121
|
+
inflight = null;
|
|
122
|
+
set({ preview, previewPending: false, error: null });
|
|
123
|
+
settleIdle();
|
|
124
|
+
return preview;
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
if (inflight?.controller === controller)
|
|
128
|
+
inflight = null;
|
|
129
|
+
const e = SealpixelError.from(error);
|
|
130
|
+
if (e.name === 'ABORTED' || version !== state.version)
|
|
131
|
+
return null;
|
|
132
|
+
set({ previewPending: false, error: e });
|
|
133
|
+
settleIdle();
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async function renderDetached(transform, options) {
|
|
138
|
+
if (state.status !== 'ready') {
|
|
139
|
+
throw new SealpixelError('NO_SOURCE', 'renderDetached needs a loaded image');
|
|
140
|
+
}
|
|
141
|
+
const log = transform(hist.current(state.history));
|
|
142
|
+
return withAssets(() => renderer.render({
|
|
143
|
+
log,
|
|
144
|
+
target: 'proxy',
|
|
145
|
+
...(options?.signal ? { signal: options.signal } : {}),
|
|
146
|
+
}), resolver, (id, bytes) => renderer.putAsset(id, bytes));
|
|
147
|
+
}
|
|
148
|
+
async function readBytes(source) {
|
|
149
|
+
if (source instanceof Uint8Array)
|
|
150
|
+
return { bytes: source, name: null };
|
|
151
|
+
if (source instanceof ArrayBuffer)
|
|
152
|
+
return { bytes: new Uint8Array(source), name: null };
|
|
153
|
+
if (typeof source === 'string') {
|
|
154
|
+
const res = await fetch(source);
|
|
155
|
+
if (!res.ok)
|
|
156
|
+
throw new SealpixelError('DECODE_FAILED', `${source}: HTTP ${res.status}`);
|
|
157
|
+
return {
|
|
158
|
+
bytes: new Uint8Array(await res.arrayBuffer()),
|
|
159
|
+
name: source.split('/').pop() ?? null,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const name = 'name' in source && typeof source.name === 'string' ? source.name : null;
|
|
163
|
+
return { bytes: new Uint8Array(await source.arrayBuffer()), name };
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Decodes client-side when the image is within the limits or the strategy
|
|
167
|
+
* says so; otherwise asks the server for a deterministic proxy.
|
|
168
|
+
*/
|
|
169
|
+
async function loadInto(bytes, id) {
|
|
170
|
+
const megapixels = estimateMegapixels(bytes);
|
|
171
|
+
const useServer = proxyStrategy === 'server' ||
|
|
172
|
+
(proxyStrategy === 'auto' &&
|
|
173
|
+
megapixels !== null &&
|
|
174
|
+
megapixels > maxClientMegapixels &&
|
|
175
|
+
options.server !== undefined);
|
|
176
|
+
if (useServer && options.server) {
|
|
177
|
+
const res = await serverFetch({
|
|
178
|
+
source: { kind: 'inline', base64: toBase64(bytes) },
|
|
179
|
+
mode: 'proxy',
|
|
180
|
+
proxyMaxSide: options.proxy?.maxSide ?? 2048,
|
|
181
|
+
sourceId: id,
|
|
182
|
+
});
|
|
183
|
+
const descriptor = JSON.parse(res.headers.get('x-sealpixel-descriptor') ?? '{}');
|
|
184
|
+
const proxyPng = new Uint8Array(await res.arrayBuffer());
|
|
185
|
+
return renderer.loadProxyEncoded(proxyPng, { ...descriptor, id });
|
|
186
|
+
}
|
|
187
|
+
return renderer.load(bytes, id);
|
|
188
|
+
}
|
|
189
|
+
async function serverFetch(body, endpoint = options.server?.endpoint) {
|
|
190
|
+
if (!endpoint)
|
|
191
|
+
throw new SealpixelError('NOT_CONFIGURED', 'no server endpoint configured');
|
|
192
|
+
const doFetch = options.server?.fetch ?? fetch;
|
|
193
|
+
const res = await doFetch(endpoint, {
|
|
194
|
+
method: 'POST',
|
|
195
|
+
headers: { 'content-type': 'application/json', ...(options.server?.headers ?? {}) },
|
|
196
|
+
body: JSON.stringify(body),
|
|
197
|
+
});
|
|
198
|
+
if (!res.ok) {
|
|
199
|
+
const detail = (await res
|
|
200
|
+
.json()
|
|
201
|
+
.catch(() => ({ error: 'SERVER_ERROR', message: `HTTP ${res.status}` })));
|
|
202
|
+
throw new SealpixelError(detail.error ?? 'SERVER_ERROR', String(detail.message ?? `HTTP ${res.status}`), detail.details);
|
|
203
|
+
}
|
|
204
|
+
return res;
|
|
205
|
+
}
|
|
206
|
+
function resolveSavedState(saved) {
|
|
207
|
+
const wrapped = saved;
|
|
208
|
+
const raw = wrapped && typeof wrapped === 'object' && 'log' in wrapped ? wrapped.log : saved;
|
|
209
|
+
const log = registry.parseEditLog(raw);
|
|
210
|
+
const index = typeof wrapped?.index === 'number' ? wrapped.index : undefined;
|
|
211
|
+
return { log, index };
|
|
212
|
+
}
|
|
213
|
+
const session = {
|
|
214
|
+
registry,
|
|
215
|
+
async load(source, loadOptions = {}) {
|
|
216
|
+
if (timer)
|
|
217
|
+
clearTimeout(timer);
|
|
218
|
+
timer = null;
|
|
219
|
+
inflight?.controller.abort();
|
|
220
|
+
inflight = null;
|
|
221
|
+
set({ status: 'loading', error: null, preview: null, previewPending: false });
|
|
222
|
+
try {
|
|
223
|
+
const { bytes, name } = await readBytes(source);
|
|
224
|
+
if (bytes.byteLength > maxClientBytes) {
|
|
225
|
+
throw new SealpixelError('TOO_LARGE', `${bytes.byteLength} bytes exceed the client limit of ${maxClientBytes}`);
|
|
226
|
+
}
|
|
227
|
+
const id = loadOptions.id ?? (name ? name.replace(/\.[^.]+$/, '') : 'image');
|
|
228
|
+
originalBytes = bytes;
|
|
229
|
+
const loaded = await loadInto(bytes, id);
|
|
230
|
+
const descriptor = loaded.descriptor;
|
|
231
|
+
let history;
|
|
232
|
+
if (loadOptions.editLog !== undefined) {
|
|
233
|
+
const { log, index } = resolveSavedState(loadOptions.editLog);
|
|
234
|
+
if (log.source.hash !== undefined && log.source.hash !== descriptor.hash) {
|
|
235
|
+
throw new SealpixelError('SOURCE_MISMATCH', 'the saved edit log belongs to a different image (hash differs)');
|
|
236
|
+
}
|
|
237
|
+
if (log.source.width !== descriptor.width || log.source.height !== descriptor.height) {
|
|
238
|
+
throw new SealpixelError('SOURCE_MISMATCH', `the saved edit log expects ${log.source.width}x${log.source.height}, image is ${descriptor.width}x${descriptor.height}`);
|
|
239
|
+
}
|
|
240
|
+
history = hist.createHistory({
|
|
241
|
+
...log,
|
|
242
|
+
source: {
|
|
243
|
+
...log.source,
|
|
244
|
+
hash: descriptor.hash ?? log.source.hash,
|
|
245
|
+
},
|
|
246
|
+
}, loadOptions.index ?? index ?? log.ops.length);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
history = hist.createHistory({
|
|
250
|
+
version: 1,
|
|
251
|
+
source: descriptor,
|
|
252
|
+
plugins: registry.pluginVersions(),
|
|
253
|
+
ops: [],
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
set({
|
|
257
|
+
status: 'ready',
|
|
258
|
+
source: descriptor,
|
|
259
|
+
resident: loaded.resident,
|
|
260
|
+
history,
|
|
261
|
+
document: compile(hist.current(history), registry),
|
|
262
|
+
version: state.version + 1,
|
|
263
|
+
preview: null,
|
|
264
|
+
error: null,
|
|
265
|
+
});
|
|
266
|
+
schedulePreview();
|
|
267
|
+
return descriptor;
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
const e = SealpixelError.from(error);
|
|
271
|
+
set({ status: state.source ? 'ready' : 'empty', error: e });
|
|
272
|
+
throw e;
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
dispatch(op) {
|
|
276
|
+
ensureReady();
|
|
277
|
+
const violation = state.source
|
|
278
|
+
? registry.validateOperation(op, state.document, state.source)
|
|
279
|
+
: null;
|
|
280
|
+
if (violation)
|
|
281
|
+
throw new SealpixelError('OPTION_VIOLATION', `${op.type}: ${violation}`);
|
|
282
|
+
setHistory(hist.dispatch(state.history, op));
|
|
283
|
+
},
|
|
284
|
+
undo() {
|
|
285
|
+
setHistory(hist.undo(state.history));
|
|
286
|
+
},
|
|
287
|
+
redo() {
|
|
288
|
+
setHistory(hist.redo(state.history));
|
|
289
|
+
},
|
|
290
|
+
timeTravel(index) {
|
|
291
|
+
setHistory(hist.timeTravel(state.history, index));
|
|
292
|
+
},
|
|
293
|
+
canUndo: () => hist.canUndo(state.history),
|
|
294
|
+
canRedo: () => hist.canRedo(state.history),
|
|
295
|
+
getState: () => state,
|
|
296
|
+
getEditLog: () => ({ log: state.history.log, index: state.history.index }),
|
|
297
|
+
getDocument: () => state.document,
|
|
298
|
+
subscribe(listener) {
|
|
299
|
+
listeners.add(listener);
|
|
300
|
+
return () => listeners.delete(listener);
|
|
301
|
+
},
|
|
302
|
+
async renderPreview() {
|
|
303
|
+
ensureReady();
|
|
304
|
+
if (timer)
|
|
305
|
+
clearTimeout(timer);
|
|
306
|
+
timer = null;
|
|
307
|
+
const result = await runPreview();
|
|
308
|
+
if (result)
|
|
309
|
+
return result;
|
|
310
|
+
if (state.preview && state.preview.version === state.version)
|
|
311
|
+
return state.preview;
|
|
312
|
+
throw state.error ?? new SealpixelError('ABORTED', 'preview superseded');
|
|
313
|
+
},
|
|
314
|
+
whenIdle() {
|
|
315
|
+
if (!state.previewPending && !timer && !inflight)
|
|
316
|
+
return Promise.resolve();
|
|
317
|
+
return new Promise((resolve) => idleResolvers.push(resolve));
|
|
318
|
+
},
|
|
319
|
+
setEditLog(saved, index) {
|
|
320
|
+
ensureReady();
|
|
321
|
+
const descriptor = state.source;
|
|
322
|
+
const resolved = resolveSavedState(saved);
|
|
323
|
+
const log = resolved.log;
|
|
324
|
+
if (log.source.hash !== undefined &&
|
|
325
|
+
descriptor.hash !== undefined &&
|
|
326
|
+
log.source.hash !== descriptor.hash) {
|
|
327
|
+
throw new SealpixelError('SOURCE_MISMATCH', 'the edit log belongs to a different image (hash differs)');
|
|
328
|
+
}
|
|
329
|
+
if (log.source.width !== descriptor.width || log.source.height !== descriptor.height) {
|
|
330
|
+
throw new SealpixelError('SOURCE_MISMATCH', 'the edit log has different source dimensions');
|
|
331
|
+
}
|
|
332
|
+
setHistory(hist.createHistory({ ...log, source: descriptor }, index ?? resolved.index ?? log.ops.length));
|
|
333
|
+
},
|
|
334
|
+
renderDetached,
|
|
335
|
+
setPreviewTransform(transform) {
|
|
336
|
+
previewTransform = transform;
|
|
337
|
+
set({ version: state.version + 1 });
|
|
338
|
+
schedulePreview();
|
|
339
|
+
},
|
|
340
|
+
async addAsset(bytes, assetOptions = {}) {
|
|
341
|
+
ensureReady();
|
|
342
|
+
const hash = await webCryptoSha256(bytes);
|
|
343
|
+
const declaration = {
|
|
344
|
+
id: assetOptions.id ?? `asset.${hash.slice(0, 16)}`,
|
|
345
|
+
hash,
|
|
346
|
+
...(assetOptions.url === undefined ? {} : { url: assetOptions.url }),
|
|
347
|
+
};
|
|
348
|
+
await renderer.putAsset(declaration.id, bytes);
|
|
349
|
+
localAssets.set(declaration.id, bytes);
|
|
350
|
+
const existing = state.history.log.assets ?? [];
|
|
351
|
+
if (!existing.some((a) => a.id === declaration.id)) {
|
|
352
|
+
const log = { ...state.history.log, assets: [...existing, declaration] };
|
|
353
|
+
set({ history: { ...state.history, log } });
|
|
354
|
+
}
|
|
355
|
+
return declaration;
|
|
356
|
+
},
|
|
357
|
+
async export(exportOptions) {
|
|
358
|
+
ensureReady();
|
|
359
|
+
if (!state.resident) {
|
|
360
|
+
throw new SealpixelError('NOT_RESIDENT', 'full-resolution pixels are not client-side; use requestServerRender');
|
|
361
|
+
}
|
|
362
|
+
const log = state.history.log;
|
|
363
|
+
const upTo = exportOptions.upTo ?? state.history.index;
|
|
364
|
+
const violations = registry.validateDocument(upTo === state.history.index ? state.document : compile(log, registry, upTo), log.source);
|
|
365
|
+
if (violations.length > 0) {
|
|
366
|
+
throw new SealpixelError('OPTION_VIOLATION', violations.map((v) => `${v.plugin}: ${v.message}`).join('; '), violations);
|
|
367
|
+
}
|
|
368
|
+
return renderer.export({
|
|
369
|
+
log,
|
|
370
|
+
output: exportOptions.output,
|
|
371
|
+
upTo,
|
|
372
|
+
...(exportOptions.embedEditLog === undefined
|
|
373
|
+
? {}
|
|
374
|
+
: { embedEditLog: exportOptions.embedEditLog }),
|
|
375
|
+
});
|
|
376
|
+
},
|
|
377
|
+
async download(downloadOptions = {}) {
|
|
378
|
+
ensureReady();
|
|
379
|
+
const output = downloadOptions.output ?? { format: 'image/png' };
|
|
380
|
+
const via = downloadOptions.via ?? 'auto';
|
|
381
|
+
const useServer = via === 'server' || (via === 'auto' && !state.resident);
|
|
382
|
+
const exportOptions = {
|
|
383
|
+
output,
|
|
384
|
+
...(downloadOptions.embedEditLog === undefined
|
|
385
|
+
? {}
|
|
386
|
+
: { embedEditLog: downloadOptions.embedEditLog }),
|
|
387
|
+
...(downloadOptions.upTo === undefined ? {} : { upTo: downloadOptions.upTo }),
|
|
388
|
+
};
|
|
389
|
+
const save = options.saveFile ?? browserSaveFile;
|
|
390
|
+
if (useServer) {
|
|
391
|
+
const result = await session.requestServerRender({
|
|
392
|
+
...exportOptions,
|
|
393
|
+
destination: 'response',
|
|
394
|
+
});
|
|
395
|
+
const filename = downloadOptions.filename ??
|
|
396
|
+
`${state.source?.id ?? 'image'}-${result.hash.slice(0, 8)}.${EXT[output.format]}`;
|
|
397
|
+
await save(result.bytes, filename, result.mimeType);
|
|
398
|
+
return { filename, result };
|
|
399
|
+
}
|
|
400
|
+
const result = await session.export(exportOptions);
|
|
401
|
+
const filename = downloadOptions.filename ??
|
|
402
|
+
`${state.source?.id ?? 'image'}-${result.hash.slice(0, 8)}.${EXT[output.format]}`;
|
|
403
|
+
await save(result.bytes, filename, result.mimeType);
|
|
404
|
+
return { filename, result };
|
|
405
|
+
},
|
|
406
|
+
async requestServerRender(renderOptions) {
|
|
407
|
+
ensureReady();
|
|
408
|
+
const endpoint = renderOptions.endpoint ?? options.server?.endpoint;
|
|
409
|
+
if (!endpoint)
|
|
410
|
+
throw new SealpixelError('NOT_CONFIGURED', 'no server endpoint configured');
|
|
411
|
+
const source = renderOptions.source ??
|
|
412
|
+
(originalBytes ? { kind: 'inline', base64: toBase64(originalBytes) } : null);
|
|
413
|
+
if (!source)
|
|
414
|
+
throw new SealpixelError('NO_SOURCE', 'original bytes are not available; pass a source reference');
|
|
415
|
+
const destination = renderOptions.destination ?? 'response';
|
|
416
|
+
const body = {
|
|
417
|
+
source,
|
|
418
|
+
editLog: state.history.log,
|
|
419
|
+
output: renderOptions.output,
|
|
420
|
+
upTo: renderOptions.upTo ?? state.history.index,
|
|
421
|
+
...(renderOptions.embedEditLog ? { embedEditLog: true } : {}),
|
|
422
|
+
destination: { kind: destination },
|
|
423
|
+
};
|
|
424
|
+
const res = await serverFetch(body, endpoint);
|
|
425
|
+
if (destination === 's3') {
|
|
426
|
+
const job = (await res.json());
|
|
427
|
+
return {
|
|
428
|
+
url: job.url,
|
|
429
|
+
objectKey: job.objectKey,
|
|
430
|
+
bucket: job.bucket,
|
|
431
|
+
hash: job.hash,
|
|
432
|
+
width: job.width,
|
|
433
|
+
height: job.height,
|
|
434
|
+
mimeType: job.mimeType,
|
|
435
|
+
cached: job.cached,
|
|
436
|
+
jobKey: job.key,
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
440
|
+
return {
|
|
441
|
+
bytes,
|
|
442
|
+
hash: res.headers.get('x-sealpixel-hash') ?? '',
|
|
443
|
+
width: state.preview?.geometry.logicalOut.width ?? 0,
|
|
444
|
+
height: state.preview?.geometry.logicalOut.height ?? 0,
|
|
445
|
+
mimeType: res.headers.get('content-type') ??
|
|
446
|
+
renderOptions.output.format,
|
|
447
|
+
cached: res.headers.get('x-sealpixel-cached') === 'true',
|
|
448
|
+
jobKey: res.headers.get('x-sealpixel-job') ?? '',
|
|
449
|
+
};
|
|
450
|
+
},
|
|
451
|
+
dispose() {
|
|
452
|
+
disposed = true;
|
|
453
|
+
if (timer)
|
|
454
|
+
clearTimeout(timer);
|
|
455
|
+
inflight?.controller.abort();
|
|
456
|
+
listeners.clear();
|
|
457
|
+
if (ownsRenderer)
|
|
458
|
+
renderer.dispose();
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
function ensureReady() {
|
|
462
|
+
if (state.status !== 'ready')
|
|
463
|
+
throw new SealpixelError('NO_SOURCE', 'load an image first');
|
|
464
|
+
}
|
|
465
|
+
return session;
|
|
466
|
+
}
|
|
467
|
+
/** Default `saveFile`: an `<a download>` click, with the share sheet as a fallback on iOS Safari. */
|
|
468
|
+
export async function browserSaveFile(bytes, filename, mimeType) {
|
|
469
|
+
if (typeof document === 'undefined' || typeof URL.createObjectURL !== 'function') {
|
|
470
|
+
throw new SealpixelError('DOWNLOAD_UNSUPPORTED', 'no DOM available; pass saveFile to createEditorSession');
|
|
471
|
+
}
|
|
472
|
+
const blob = new Blob([bytes], { type: mimeType });
|
|
473
|
+
const nav = navigator;
|
|
474
|
+
const isIOS = /iP(hone|ad|od)/.test(navigator.userAgent);
|
|
475
|
+
if (isIOS &&
|
|
476
|
+
typeof File !== 'undefined' &&
|
|
477
|
+
nav.canShare?.({ files: [new File([blob], filename, { type: mimeType })] })) {
|
|
478
|
+
await navigator.share({ files: [new File([blob], filename, { type: mimeType })] });
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const url = URL.createObjectURL(blob);
|
|
482
|
+
try {
|
|
483
|
+
const a = document.createElement('a');
|
|
484
|
+
a.href = url;
|
|
485
|
+
a.download = filename;
|
|
486
|
+
a.rel = 'noopener';
|
|
487
|
+
a.style.display = 'none';
|
|
488
|
+
document.body.appendChild(a);
|
|
489
|
+
a.click();
|
|
490
|
+
a.remove();
|
|
491
|
+
}
|
|
492
|
+
finally {
|
|
493
|
+
setTimeout(() => URL.revokeObjectURL(url), 10_000);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
function estimateMegapixels(bytes) {
|
|
497
|
+
try {
|
|
498
|
+
const { width, height } = readImageSize(bytes);
|
|
499
|
+
return (width * height) / 1e6;
|
|
500
|
+
}
|
|
501
|
+
catch {
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function toBase64(bytes) {
|
|
506
|
+
if (typeof Buffer !== 'undefined')
|
|
507
|
+
return Buffer.from(bytes).toString('base64');
|
|
508
|
+
let bin = '';
|
|
509
|
+
for (let i = 0; i < bytes.length; i += 0x8000)
|
|
510
|
+
bin += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
|
|
511
|
+
return btoa(bin);
|
|
512
|
+
}
|
|
513
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAMA,OAAO,EAAsB,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAA2B,MAAM,aAAa,CAAC;AACt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alised coordinate in 0..1. */
|
|
4
|
+
export type Unit = number;
|
|
5
|
+
/** Length in pixels of the logical, full-resolution stage. */
|
|
6
|
+
export type SourcePx = number;
|
|
7
|
+
export type Radians = number;
|
|
8
|
+
export interface Point {
|
|
9
|
+
x: Unit;
|
|
10
|
+
y: Unit;
|
|
11
|
+
}
|
|
12
|
+
export interface Rect {
|
|
13
|
+
x: Unit;
|
|
14
|
+
y: Unit;
|
|
15
|
+
width: Unit;
|
|
16
|
+
height: Unit;
|
|
17
|
+
}
|
|
18
|
+
/** sRGB colour with straight alpha, each channel 0..1. */
|
|
19
|
+
export type Color = [r: number, g: number, b: number, a: number];
|
|
20
|
+
/** Identity and logical dimensions of the original image after EXIF orientation. */
|
|
21
|
+
export interface SourceDescriptor {
|
|
22
|
+
id: string;
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
/** sha256 of the original bytes. The server verifies it before rendering. */
|
|
26
|
+
hash?: string;
|
|
27
|
+
mimeType?: string;
|
|
28
|
+
}
|
|
29
|
+
/** Augmented by plugins via `declare module '@sealpixel/core'`. */
|
|
30
|
+
export interface OperationRegistry {
|
|
31
|
+
}
|
|
32
|
+
export type OperationType = keyof OperationRegistry & string;
|
|
33
|
+
/**
|
|
34
|
+
* Union of every registered operation. Falls back to the bare base shape when
|
|
35
|
+
* no plugin has augmented the registry (for example inside `@sealpixel/core`'s
|
|
36
|
+
* own tests), so generic code can still read `type` and `id`.
|
|
37
|
+
*/
|
|
38
|
+
export type Operation = [OperationType] extends [never] ? OperationBase<string> : OperationRegistry[OperationType];
|
|
39
|
+
export interface OperationBase<T extends string> {
|
|
40
|
+
type: T;
|
|
41
|
+
/** Unique per log entry. Ignored by the renderer. */
|
|
42
|
+
id: string;
|
|
43
|
+
/** Wall-clock timestamp. Ignored by the renderer. */
|
|
44
|
+
at?: number | undefined;
|
|
45
|
+
}
|
|
46
|
+
/** The only state of an editing session. Serialisable as JSON. */
|
|
47
|
+
export interface EditLog {
|
|
48
|
+
version: 1;
|
|
49
|
+
source: SourceDescriptor;
|
|
50
|
+
/** Plugin id to plugin version, for migrations. */
|
|
51
|
+
plugins: Record<string, number>;
|
|
52
|
+
/**
|
|
53
|
+
* Assets the ops reference that are not declared by a plugin (for example
|
|
54
|
+
* an uploaded sticker). Hosts must make `url` reachable for other devices
|
|
55
|
+
* and the server.
|
|
56
|
+
*/
|
|
57
|
+
assets?: import('./plugin.js').AssetDeclaration[];
|
|
58
|
+
ops: Operation[];
|
|
59
|
+
}
|
|
60
|
+
/** Undo/redo position over an edit log: `ops[0..index)` is the current state. */
|
|
61
|
+
export interface History {
|
|
62
|
+
log: EditLog;
|
|
63
|
+
index: number;
|
|
64
|
+
}
|
|
65
|
+
export type OutputFormat = 'image/png' | 'image/jpeg' | 'image/webp';
|
|
66
|
+
export interface OutputOptions {
|
|
67
|
+
format: OutputFormat;
|
|
68
|
+
/** 0..1, lossy formats only. Default 0.9. */
|
|
69
|
+
quality?: number;
|
|
70
|
+
/** JPEG only. Default false. */
|
|
71
|
+
progressive?: boolean;
|
|
72
|
+
/** JPEG only. Default '4:2:0'. */
|
|
73
|
+
chromaSubsampling?: '4:2:0' | '4:4:4';
|
|
74
|
+
/** WebP only. V1 always encodes lossless. */
|
|
75
|
+
lossless?: boolean;
|
|
76
|
+
/** Opaque colour that alpha is flattened onto for JPEG, 0..255 each. Default white. */
|
|
77
|
+
background?: [r: number, g: number, b: number];
|
|
78
|
+
}
|
|
79
|
+
export interface RenderOptions {
|
|
80
|
+
output: OutputOptions;
|
|
81
|
+
/**
|
|
82
|
+
* `truth` (default) requires the buffer to have the logical source
|
|
83
|
+
* dimensions. `preview` accepts a proxy and scales lengths accordingly.
|
|
84
|
+
*/
|
|
85
|
+
mode?: 'truth' | 'preview';
|
|
86
|
+
/** Render only `ops[0..upTo)`. Defaults to all ops. */
|
|
87
|
+
upTo?: number;
|
|
88
|
+
signal?: AbortSignal;
|
|
89
|
+
/** Pre-loaded core. Servers pass this to reuse one instance across requests. */
|
|
90
|
+
wasm?: import('@sealpixel/wasm').SealpixelWasm;
|
|
91
|
+
/** Plugins that interpret the log's ops. Required when the log has ops. */
|
|
92
|
+
registry?: import('./registry.js').Registry;
|
|
93
|
+
/** Supplies fonts and images referenced by the log. */
|
|
94
|
+
assets?: import('./assets.js').AssetResolver;
|
|
95
|
+
/**
|
|
96
|
+
* Store `canonicalJson({ log, index })` in the file's metadata so it can be
|
|
97
|
+
* reopened with `readEmbeddedState`. Off by default: the log may contain
|
|
98
|
+
* text the user does not want to ship.
|
|
99
|
+
*/
|
|
100
|
+
embedEditLog?: boolean;
|
|
101
|
+
}
|
|
102
|
+
export interface RenderResult {
|
|
103
|
+
bytes: Uint8Array;
|
|
104
|
+
mimeType: OutputFormat;
|
|
105
|
+
width: number;
|
|
106
|
+
height: number;
|
|
107
|
+
/** sha256 of `bytes`, computed inside the core. */
|
|
108
|
+
hash: string;
|
|
109
|
+
/** Version of the core that produced the bytes. */
|
|
110
|
+
coreVersion: string;
|
|
111
|
+
timings: Record<string, number>;
|
|
112
|
+
}
|
|
113
|
+
export type RenderSource = Uint8Array | RgbaBuffer;
|
|
114
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE/E,qCAAqC;AACrC,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAC1B,8DAA8D;AAC9D,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC9B,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,IAAI,CAAC;IACR,CAAC,EAAE,IAAI,CAAC;CACT;AACD,MAAM,WAAW,IAA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