@sealpixel/ui 1.0.0-rc.2 → 1.0.0-rc.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/LICENSE.md +2 -2
  2. package/README.md +1 -1
  3. package/dist/components/sealpixel-button.d.ts +0 -1
  4. package/dist/components/sealpixel-button.js +1 -1
  5. package/dist/components/sealpixel-button.js.map +1 -1
  6. package/dist/components/sealpixel-editor.d.ts +71 -20
  7. package/dist/components/sealpixel-editor.js +265 -57
  8. package/dist/components/sealpixel-editor.js.map +1 -1
  9. package/dist/components/sealpixel-nav.d.ts +0 -1
  10. package/dist/components/sealpixel-nav.js +1 -1
  11. package/dist/components/sealpixel-nav.js.map +1 -1
  12. package/dist/components/sealpixel-slider.d.ts +12 -17
  13. package/dist/components/sealpixel-slider.js +64 -10
  14. package/dist/components/sealpixel-slider.js.map +1 -1
  15. package/dist/components/sealpixel-stage.d.ts +17 -1
  16. package/dist/components/sealpixel-stage.js +57 -6
  17. package/dist/components/sealpixel-stage.js.map +1 -1
  18. package/dist/components/sealpixel-stepper.d.ts +0 -1
  19. package/dist/components/sealpixel-stepper.js +4 -4
  20. package/dist/components/sealpixel-stepper.js.map +1 -1
  21. package/dist/components/sealpixel-toolbar.d.ts +6 -2
  22. package/dist/components/sealpixel-toolbar.js +71 -5
  23. package/dist/components/sealpixel-toolbar.js.map +1 -1
  24. package/dist/controllers/gesture-controller.d.ts +5 -1
  25. package/dist/controllers/gesture-controller.js +24 -4
  26. package/dist/controllers/gesture-controller.js.map +1 -1
  27. package/dist/controllers/session-controller.d.ts +0 -1
  28. package/dist/controllers/session-controller.js +2 -0
  29. package/dist/controllers/session-controller.js.map +1 -1
  30. package/dist/define.d.ts +0 -1
  31. package/dist/define.js.map +1 -1
  32. package/dist/i18n.d.ts +0 -1
  33. package/dist/i18n.js.map +1 -1
  34. package/dist/icons.d.ts +1 -1
  35. package/dist/icons.js +1 -0
  36. package/dist/icons.js.map +1 -1
  37. package/dist/index.d.ts +1 -2
  38. package/dist/index.js +1 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/locales/de.d.ts +0 -1
  41. package/dist/locales/de.js +22 -0
  42. package/dist/locales/de.js.map +1 -1
  43. package/dist/locales/en.d.ts +0 -1
  44. package/dist/locales/en.js +22 -0
  45. package/dist/locales/en.js.map +1 -1
  46. package/dist/locales/es.d.ts +0 -1
  47. package/dist/locales/es.js +22 -0
  48. package/dist/locales/es.js.map +1 -1
  49. package/dist/locales/fr.d.ts +0 -1
  50. package/dist/locales/fr.js +22 -0
  51. package/dist/locales/fr.js.map +1 -1
  52. package/dist/locales/index.d.ts +0 -1
  53. package/dist/locales/index.js.map +1 -1
  54. package/dist/locales/ja.d.ts +0 -1
  55. package/dist/locales/ja.js +22 -0
  56. package/dist/locales/ja.js.map +1 -1
  57. package/dist/locales/pt.d.ts +0 -1
  58. package/dist/locales/pt.js +22 -0
  59. package/dist/locales/pt.js.map +1 -1
  60. package/dist/theme.d.ts +0 -1
  61. package/dist/theme.js.map +1 -1
  62. package/dist/tool.d.ts +12 -1
  63. package/dist/tool.js.map +1 -1
  64. package/dist/tools/annotate.d.ts +0 -1
  65. package/dist/tools/annotate.js +277 -28
  66. package/dist/tools/annotate.js.map +1 -1
  67. package/dist/tools/assist.d.ts +103 -0
  68. package/dist/tools/assist.js +361 -0
  69. package/dist/tools/assist.js.map +1 -0
  70. package/dist/tools/crop-mask.d.ts +0 -1
  71. package/dist/tools/crop-mask.js.map +1 -1
  72. package/dist/tools/crop-rotation.d.ts +64 -0
  73. package/dist/tools/crop-rotation.js +172 -0
  74. package/dist/tools/crop-rotation.js.map +1 -0
  75. package/dist/tools/crop.d.ts +0 -1
  76. package/dist/tools/crop.js +99 -15
  77. package/dist/tools/crop.js.map +1 -1
  78. package/dist/tools/delete-handle.d.ts +0 -1
  79. package/dist/tools/delete-handle.js +6 -0
  80. package/dist/tools/delete-handle.js.map +1 -1
  81. package/dist/tools/filter.d.ts +0 -1
  82. package/dist/tools/filter.js.map +1 -1
  83. package/dist/tools/finetune.d.ts +0 -1
  84. package/dist/tools/finetune.js.map +1 -1
  85. package/dist/tools/frame.d.ts +0 -1
  86. package/dist/tools/frame.js.map +1 -1
  87. package/dist/tools/handles.d.ts +26 -0
  88. package/dist/tools/handles.js +51 -0
  89. package/dist/tools/handles.js.map +1 -0
  90. package/dist/tools/index.d.ts +2 -2
  91. package/dist/tools/index.js +3 -1
  92. package/dist/tools/index.js.map +1 -1
  93. package/dist/tools/keys.d.ts +59 -0
  94. package/dist/tools/keys.js +120 -0
  95. package/dist/tools/keys.js.map +1 -0
  96. package/dist/tools/redact.d.ts +10 -1
  97. package/dist/tools/redact.js +176 -12
  98. package/dist/tools/redact.js.map +1 -1
  99. package/dist/tools/region-transform.d.ts +69 -0
  100. package/dist/tools/region-transform.js +192 -0
  101. package/dist/tools/region-transform.js.map +1 -0
  102. package/dist/tools/resize.d.ts +0 -1
  103. package/dist/tools/resize.js +19 -6
  104. package/dist/tools/resize.js.map +1 -1
  105. package/dist/tools/sticker.d.ts +0 -1
  106. package/dist/tools/sticker.js +57 -2
  107. package/dist/tools/sticker.js.map +1 -1
  108. package/dist/tools/watermark.d.ts +0 -1
  109. package/dist/tools/watermark.js.map +1 -1
  110. package/dist/view-mapping.d.ts +1 -2
  111. package/dist/view-mapping.js +1 -1
  112. package/dist/view-mapping.js.map +1 -1
  113. package/package.json +8 -8
  114. package/dist/components/sealpixel-button.d.ts.map +0 -1
  115. package/dist/components/sealpixel-editor.d.ts.map +0 -1
  116. package/dist/components/sealpixel-nav.d.ts.map +0 -1
  117. package/dist/components/sealpixel-slider.d.ts.map +0 -1
  118. package/dist/components/sealpixel-stage.d.ts.map +0 -1
  119. package/dist/components/sealpixel-stepper.d.ts.map +0 -1
  120. package/dist/components/sealpixel-toolbar.d.ts.map +0 -1
  121. package/dist/controllers/gesture-controller.d.ts.map +0 -1
  122. package/dist/controllers/session-controller.d.ts.map +0 -1
  123. package/dist/define.d.ts.map +0 -1
  124. package/dist/i18n.d.ts.map +0 -1
  125. package/dist/icons.d.ts.map +0 -1
  126. package/dist/index.d.ts.map +0 -1
  127. package/dist/locales/de.d.ts.map +0 -1
  128. package/dist/locales/en.d.ts.map +0 -1
  129. package/dist/locales/es.d.ts.map +0 -1
  130. package/dist/locales/fr.d.ts.map +0 -1
  131. package/dist/locales/index.d.ts.map +0 -1
  132. package/dist/locales/ja.d.ts.map +0 -1
  133. package/dist/locales/pt.d.ts.map +0 -1
  134. package/dist/theme.d.ts.map +0 -1
  135. package/dist/tool.d.ts.map +0 -1
  136. package/dist/tools/annotate.d.ts.map +0 -1
  137. package/dist/tools/crop-mask.d.ts.map +0 -1
  138. package/dist/tools/crop.d.ts.map +0 -1
  139. package/dist/tools/delete-handle.d.ts.map +0 -1
  140. package/dist/tools/filter.d.ts.map +0 -1
  141. package/dist/tools/finetune.d.ts.map +0 -1
  142. package/dist/tools/frame.d.ts.map +0 -1
  143. package/dist/tools/index.d.ts.map +0 -1
  144. package/dist/tools/redact.d.ts.map +0 -1
  145. package/dist/tools/resize.d.ts.map +0 -1
  146. package/dist/tools/sticker.d.ts.map +0 -1
  147. package/dist/tools/watermark.d.ts.map +0 -1
  148. package/dist/view-mapping.d.ts.map +0 -1
@@ -0,0 +1,361 @@
1
+ import { SealpixelError } from '@sealpixel/core';
2
+ import { ASSIST_DEFAULT_OPTIONS, filterDetections, padRect, REDACT_DEFAULT_OPTIONS, toRedactAdd, } from '@sealpixel/plugins';
3
+ import { html, nothing, svg } from 'lit';
4
+ import { icons } from '../icons.js';
5
+ import { cropClipPath } from './crop-mask.js';
6
+ import { opId } from './finetune.js';
7
+ import { CHECK_PATH, CROSS_PATH, handleRow } from './handles.js';
8
+ export const initialState = {
9
+ sourceKey: null,
10
+ status: 'idle',
11
+ items: [],
12
+ error: null,
13
+ notice: null,
14
+ };
15
+ let nextKey = 1;
16
+ /** Pure: the whole suggestion lifecycle, testable without a browser. */
17
+ export function reduce(state, action) {
18
+ switch (action.type) {
19
+ case 'source':
20
+ return state.sourceKey === action.key
21
+ ? state
22
+ : { sourceKey: action.key, status: 'idle', items: [], error: null, notice: null };
23
+ case 'start':
24
+ return { ...state, status: 'loading', error: null, notice: null };
25
+ case 'detecting':
26
+ return { ...state, status: 'detecting' };
27
+ case 'results':
28
+ return {
29
+ ...state,
30
+ status: 'done',
31
+ items: action.detections.map((d) => ({ ...d, key: nextKey++, decision: 'proposed' })),
32
+ };
33
+ case 'fail':
34
+ return { ...state, status: 'error', error: action.message };
35
+ case 'cancel':
36
+ // A stopped detection leaves the last results, or nothing, so a later activation runs again.
37
+ return state.status === 'loading' || state.status === 'detecting'
38
+ ? { ...state, status: state.items.length > 0 ? 'done' : 'idle' }
39
+ : state;
40
+ case 'refuse':
41
+ return { ...state, notice: action.message };
42
+ case 'accept':
43
+ case 'reject': {
44
+ const decision = action.type === 'accept' ? 'accepted' : 'rejected';
45
+ return {
46
+ ...state,
47
+ notice: null,
48
+ items: state.items.map((s) => (s.key === action.key ? { ...s, decision } : s)),
49
+ };
50
+ }
51
+ case 'acceptAll':
52
+ case 'rejectAll': {
53
+ const decision = action.type === 'acceptAll' ? 'accepted' : 'rejected';
54
+ return {
55
+ ...state,
56
+ notice: null,
57
+ items: state.items.map((s) => (s.decision === 'proposed' ? { ...s, decision } : s)),
58
+ };
59
+ }
60
+ case 'move':
61
+ return {
62
+ ...state,
63
+ items: state.items.map((s) => (s.key === action.key ? { ...s, rect: action.rect } : s)),
64
+ };
65
+ }
66
+ }
67
+ export const proposed = (state) => state.items.filter((s) => s.decision === 'proposed');
68
+ /** Thrown into the detection when `timeoutMs` passes; its message is the panel's text. */
69
+ export class AssistTimeout extends Error {
70
+ constructor() {
71
+ super(...arguments);
72
+ this.name = 'ASSIST_TIMEOUT';
73
+ }
74
+ }
75
+ export function createAssistController(detector) {
76
+ let state = initialState;
77
+ let controller = null;
78
+ const set = (action, ctx) => {
79
+ state = reduce(state, action);
80
+ ctx.refresh();
81
+ };
82
+ const options = (ctx) => ctx.options('assist') ?? ASSIST_DEFAULT_OPTIONS;
83
+ const abort = () => {
84
+ if (!controller)
85
+ return;
86
+ controller.abort();
87
+ controller = null;
88
+ // The aborted run returns silently, so the status is reset here and not in its catch.
89
+ state = reduce(state, { type: 'cancel' });
90
+ };
91
+ const accept = (key, ctx) => {
92
+ const item = state.items.find((s) => s.key === key && s.decision === 'proposed');
93
+ if (!item)
94
+ return;
95
+ const opts = options(ctx);
96
+ const redact = ctx.options('redact') ?? REDACT_DEFAULT_OPTIONS;
97
+ const op = toRedactAdd(padRect(item.rect, opts.padding), redact, opId(), opts);
98
+ // Checked before the dispatch: the editor's dispatch reports a violation as a
99
+ // toast and returns, and the suggestion must not count as accepted then.
100
+ const source = ctx.state.source;
101
+ const violation = source
102
+ ? ctx.session.registry.validateOperation(op, ctx.session.getDocument(), source)
103
+ : null;
104
+ if (violation) {
105
+ set({ type: 'refuse', message: violation }, ctx);
106
+ return;
107
+ }
108
+ try {
109
+ ctx.dispatch(op);
110
+ }
111
+ catch (error) {
112
+ if (!(error instanceof SealpixelError && error.name === 'OPTION_VIOLATION'))
113
+ throw error;
114
+ set({ type: 'refuse', message: error.message }, ctx);
115
+ return;
116
+ }
117
+ set({ type: 'accept', key }, ctx);
118
+ };
119
+ return {
120
+ state: () => state,
121
+ options,
122
+ abort,
123
+ syncSource: (ctx) => {
124
+ const source = ctx.state.source;
125
+ const key = source ? (source.hash ?? source.id) : null;
126
+ if (key && key !== state.sourceKey) {
127
+ abort();
128
+ state = reduce(state, { type: 'source', key });
129
+ }
130
+ },
131
+ run: async (ctx) => {
132
+ abort();
133
+ const own = new AbortController();
134
+ controller = own;
135
+ const opts = options(ctx);
136
+ const timer = setTimeout(() => own.abort(new AssistTimeout(ctx.t('assist.timeout'))), opts.timeoutMs);
137
+ set({ type: 'start' }, ctx);
138
+ try {
139
+ // The unedited, uncropped working copy: what the redact regions are measured against.
140
+ const image = await ctx.session.renderDetached((log) => ({ ...log, ops: [] }), {
141
+ signal: own.signal,
142
+ });
143
+ own.signal.throwIfAborted();
144
+ set({ type: 'detecting' }, ctx);
145
+ // Raced against the signal: a detector that ignores it cannot outlast the timeout.
146
+ const found = await raceAbort(detector.detect(image, { signal: own.signal, options: opts }), own.signal);
147
+ own.signal.throwIfAborted();
148
+ set({ type: 'results', detections: filterDetections(found, opts) }, ctx);
149
+ if (opts.acceptAbove !== null) {
150
+ const threshold = opts.acceptAbove;
151
+ for (const item of proposed(state))
152
+ if (item.score >= threshold)
153
+ accept(item.key, ctx);
154
+ }
155
+ }
156
+ catch (error) {
157
+ // A timeout is our own abort and gets reported; any other abort is silent.
158
+ if (own.signal.aborted && !(own.signal.reason instanceof AssistTimeout))
159
+ return;
160
+ const reason = own.signal.reason instanceof AssistTimeout ? own.signal.reason : error;
161
+ set({ type: 'fail', message: reason.message }, ctx);
162
+ }
163
+ finally {
164
+ clearTimeout(timer);
165
+ if (controller === own)
166
+ controller = null;
167
+ }
168
+ },
169
+ accept,
170
+ reject: (key, ctx) => set({ type: 'reject', key }, ctx),
171
+ acceptAll: (ctx) => {
172
+ for (const item of proposed(state))
173
+ accept(item.key, ctx);
174
+ },
175
+ rejectAll: (ctx) => set({ type: 'rejectAll' }, ctx),
176
+ move: (key, rect, ctx) => set({ type: 'move', key, rect }, ctx),
177
+ };
178
+ }
179
+ /** Settles with `promise`, or rejects with the signal's reason as soon as it aborts. */
180
+ function raceAbort(promise, signal) {
181
+ if (signal.aborted)
182
+ return Promise.reject(signal.reason);
183
+ return new Promise((resolve, reject) => {
184
+ const onAbort = () => reject(signal.reason);
185
+ signal.addEventListener('abort', onAbort, { once: true });
186
+ promise.then(resolve, reject).finally(() => signal.removeEventListener('abort', onAbort));
187
+ });
188
+ }
189
+ /** Redact coordinates live in image space: show the image before crop and resize. */
190
+ function beforeCrop(log) {
191
+ return {
192
+ ...log,
193
+ ops: [
194
+ ...log.ops,
195
+ { type: 'crop.reset', id: '__sealpixel_preview_crop__' },
196
+ { type: 'resize.clear', id: '__sealpixel_preview_resize__' },
197
+ ],
198
+ };
199
+ }
200
+ function clipToCrop(ctx) {
201
+ const crop = ctx.session.getDocument().crop;
202
+ const preview = ctx.state.preview;
203
+ ctx.clipPreview(preview ? cropClipPath(crop, preview.image.width, preview.image.height) : null);
204
+ }
205
+ export function createAssistTool(detector) {
206
+ const c = createAssistController(detector);
207
+ let drag = null;
208
+ const busy = () => {
209
+ const s = c.state().status;
210
+ return s === 'loading' || s === 'detecting';
211
+ };
212
+ return {
213
+ id: 'assist',
214
+ icon: icons.assist,
215
+ label: 'tool.assist',
216
+ onSource: (ctx) => {
217
+ c.syncSource(ctx);
218
+ if (c.options(ctx).run === 'load' && c.state().status === 'idle')
219
+ void c.run(ctx);
220
+ },
221
+ badge: (ctx) => {
222
+ if (!c.options(ctx).badge || busy())
223
+ return null;
224
+ const n = proposed(c.state()).length;
225
+ return n > 0 ? n : null;
226
+ },
227
+ activate: (ctx) => {
228
+ c.syncSource(ctx);
229
+ clipToCrop(ctx);
230
+ ctx.session.setPreviewTransform(beforeCrop);
231
+ if (c.options(ctx).run === 'select' && c.state().status === 'idle')
232
+ void c.run(ctx);
233
+ },
234
+ deactivate: (ctx) => {
235
+ c.abort();
236
+ drag = null;
237
+ ctx.clipPreview(null);
238
+ ctx.session.setPreviewTransform(null);
239
+ },
240
+ panel: (ctx) => {
241
+ c.syncSource(ctx);
242
+ clipToCrop(ctx);
243
+ if (!ctx.session.registry.byId.has('redact')) {
244
+ return html `<p class="status" role="status">${ctx.t('assist.needsRedact')}</p>`;
245
+ }
246
+ const opts = c.options(ctx);
247
+ const state = c.state();
248
+ const open = proposed(state);
249
+ const text = state.notice
250
+ ? ctx.t('assist.refused', { message: state.notice })
251
+ : state.status === 'loading'
252
+ ? ctx.t('assist.loading')
253
+ : state.status === 'detecting'
254
+ ? ctx.t('assist.detecting')
255
+ : state.status === 'error'
256
+ ? ctx.t('assist.error', { message: state.error ?? '' })
257
+ : state.status === 'done'
258
+ ? open.length > 0
259
+ ? ctx.t('assist.found', { count: open.length })
260
+ : ctx.t('assist.none')
261
+ : '';
262
+ return html `
263
+ <div class="row" role="group" aria-label=${ctx.t('tool.assist')}>
264
+ <div class="group">
265
+ <sealpixel-button data-action="detect" ?disabled=${busy()} @click=${() => void c.run(ctx)}>${ctx.t('assist.detect')}</sealpixel-button>
266
+ ${opts.bulk && open.length > 0
267
+ ? html `<sealpixel-button data-action="accept-all" variant="primary" @click=${() => c.acceptAll(ctx)}>${ctx.t('assist.acceptAll')}</sealpixel-button>
268
+ <sealpixel-button data-action="reject-all" @click=${() => c.rejectAll(ctx)}>${ctx.t('assist.rejectAll')}</sealpixel-button>`
269
+ : nothing}
270
+ </div>
271
+ </div>
272
+ <p class="status" role="status" data-status=${state.status}>${text}</p>
273
+ `;
274
+ },
275
+ overlay: (ctx) => {
276
+ const { width: W, height: H, zoom } = ctx.stage;
277
+ if (!W || !H)
278
+ return svg ``;
279
+ const opts = c.options(ctx);
280
+ const sw = 1.5 / zoom;
281
+ const toN = (e) => {
282
+ const p = ctx.stage.toImage(e.clientX, e.clientY);
283
+ return [clamp01(p.x / W), clamp01(p.y / H)];
284
+ };
285
+ const shape = (item) => {
286
+ const rect = drag?.key === item.key ? drag.rect : item.rect;
287
+ // Press and move adjusts the proposal before accepting it.
288
+ const down = (e) => {
289
+ e.stopPropagation();
290
+ e.preventDefault();
291
+ if (!opts.adjust)
292
+ return;
293
+ const start = toN(e);
294
+ drag = { key: item.key, rect: item.rect };
295
+ const move = (ev) => {
296
+ if (!drag)
297
+ return;
298
+ const q = toN(ev);
299
+ drag.rect = translate(item.rect, q[0] - start[0], q[1] - start[1]);
300
+ ctx.refresh();
301
+ };
302
+ const up = () => {
303
+ window.removeEventListener('pointermove', move);
304
+ window.removeEventListener('pointerup', up);
305
+ window.removeEventListener('pointercancel', up);
306
+ const d = drag;
307
+ drag = null;
308
+ if (d)
309
+ c.move(item.key, d.rect, ctx);
310
+ else
311
+ ctx.refresh();
312
+ };
313
+ window.addEventListener('pointermove', move);
314
+ window.addEventListener('pointerup', up);
315
+ window.addEventListener('pointercancel', up);
316
+ };
317
+ const px = { x: rect.x * W, y: rect.y * H, width: rect.width * W, height: rect.height * H };
318
+ return svg `
319
+ <rect data-interactive data-suggestion=${item.key} x=${px.x} y=${px.y} width=${px.width} height=${px.height}
320
+ fill="rgba(91,141,239,0.15)" stroke="var(--sealpixel-color-accent)" stroke-width=${sw}
321
+ stroke-dasharray=${`${6 / zoom} ${4 / zoom}`} style=${opts.adjust ? 'cursor:move' : ''} @pointerdown=${down} />
322
+ ${opts.showScore
323
+ ? svg `<text x=${px.x + 4 / zoom} y=${px.y + px.height - 4 / zoom} font-size=${11 / zoom}
324
+ fill="var(--sealpixel-color-accent)" style="pointer-events:none;font-family:ui-monospace,monospace">${item.score.toFixed(2)}</text>`
325
+ : nothing}
326
+ ${handleRow(px, ctx.stage, [
327
+ {
328
+ path: CHECK_PATH,
329
+ label: ctx.t('assist.accept'),
330
+ color: 'var(--sealpixel-color-accent)',
331
+ action: 'accept',
332
+ onActivate: () => c.accept(item.key, ctx),
333
+ },
334
+ {
335
+ path: CROSS_PATH,
336
+ label: ctx.t('assist.reject'),
337
+ color: 'var(--sealpixel-color-danger)',
338
+ action: 'reject',
339
+ onActivate: () => c.reject(item.key, ctx),
340
+ },
341
+ ])}
342
+ `;
343
+ };
344
+ return svg `${proposed(c.state()).map(shape)}`;
345
+ },
346
+ };
347
+ }
348
+ function translate(rect, dx, dy) {
349
+ return {
350
+ ...rect,
351
+ x: clamp(rect.x + dx, 0, 1 - rect.width),
352
+ y: clamp(rect.y + dy, 0, 1 - rect.height),
353
+ };
354
+ }
355
+ function clamp01(v) {
356
+ return clamp(v, 0, 1);
357
+ }
358
+ function clamp(v, lo, hi) {
359
+ return v < lo ? lo : v > hi ? hi : v;
360
+ }
361
+ //# sourceMappingURL=assist.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assist.js","sourceRoot":"","sources":["../../src/tools/assist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,MAAM,EAAE,QAAQ;wBAChB,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC;qBAC1C;iBACF,CAAC;SACH,CAAC;YACJ,CAAC,CAAC;YACF,OAAO,GAAG,CAAA,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAChD,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,IAAU,EAAE,EAAU,EAAE,EAAU;IACnD,OAAO;QACL,GAAG,IAAI;QACP,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;QACxC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;KAC1C,CAAC;AACJ,CAAC;AACD,SAAS,OAAO,CAAC,CAAS;IACxB,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACxB,CAAC;AACD,SAAS,KAAK,CAAC,CAAS,EAAE,EAAU,EAAE,EAAU;IAC9C,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import { type EditLog, type Rect, SealpixelError } from '@sealpixel/core';\nimport {\n ASSIST_DEFAULT_OPTIONS,\n type AssistOptions,\n type Detection,\n type Detector,\n filterDetections,\n padRect,\n REDACT_DEFAULT_OPTIONS,\n type RedactOptions,\n toRedactAdd,\n} from '@sealpixel/plugins';\nimport { html, nothing, svg } from 'lit';\nimport { icons } from '../icons.js';\nimport type { UiTool, UiToolContext } from '../tool.js';\nimport { type CropLike, cropClipPath } from './crop-mask.js';\nimport { opId } from './finetune.js';\nimport { CHECK_PATH, CROSS_PATH, handleRow } from './handles.js';\n\n/**\n * The assist tool: runs a host-supplied detector on the unedited working copy, shows\n * the proposals as pending boxes, and turns an accepted one into an ordinary\n * `redact.add`. The proposals live in the controller, never in the edit log —\n * the log holds decisions, not guesses.\n *\n * The button appears only when a host registers `assistPlugin` and installs\n * the tool:\n *\n * editor.plugins = [...defaultPlugins, assistPlugin];\n * editor.tools = { assist: createAssistTool(detector) };\n */\n\nexport type Decision = 'proposed' | 'accepted' | 'rejected';\n\nexport interface Suggestion {\n key: number;\n rect: Rect;\n score: number;\n label: string;\n decision: Decision;\n}\n\nexport type Status = 'idle' | 'loading' | 'detecting' | 'done' | 'error';\n\nexport interface AssistState {\n /** Identifies the source the suggestions belong to. */\n sourceKey: string | null;\n status: Status;\n items: Suggestion[];\n error: string | null;\n /** Why the last accept dispatched nothing, for example a redact option that refuses it. */\n notice: string | null;\n}\n\nexport type Action =\n | { type: 'source'; key: string }\n | { type: 'start' }\n | { type: 'detecting' }\n | { type: 'results'; detections: Detection[] }\n | { type: 'fail'; message: string }\n | { type: 'cancel' }\n | { type: 'refuse'; message: string }\n | { type: 'accept'; key: number }\n | { type: 'reject'; key: number }\n | { type: 'acceptAll' }\n | { type: 'rejectAll' }\n | { type: 'move'; key: number; rect: Rect };\n\nexport const initialState: AssistState = {\n sourceKey: null,\n status: 'idle',\n items: [],\n error: null,\n notice: null,\n};\n\nlet nextKey = 1;\n\n/** Pure: the whole suggestion lifecycle, testable without a browser. */\nexport function reduce(state: AssistState, action: Action): AssistState {\n switch (action.type) {\n case 'source':\n return state.sourceKey === action.key\n ? state\n : { sourceKey: action.key, status: 'idle', items: [], error: null, notice: null };\n case 'start':\n return { ...state, status: 'loading', error: null, notice: null };\n case 'detecting':\n return { ...state, status: 'detecting' };\n case 'results':\n return {\n ...state,\n status: 'done',\n items: action.detections.map((d) => ({ ...d, key: nextKey++, decision: 'proposed' })),\n };\n case 'fail':\n return { ...state, status: 'error', error: action.message };\n case 'cancel':\n // A stopped detection leaves the last results, or nothing, so a later activation runs again.\n return state.status === 'loading' || state.status === 'detecting'\n ? { ...state, status: state.items.length > 0 ? 'done' : 'idle' }\n : state;\n case 'refuse':\n return { ...state, notice: action.message };\n case 'accept':\n case 'reject': {\n const decision: Decision = action.type === 'accept' ? 'accepted' : 'rejected';\n return {\n ...state,\n notice: null,\n items: state.items.map((s) => (s.key === action.key ? { ...s, decision } : s)),\n };\n }\n case 'acceptAll':\n case 'rejectAll': {\n const decision: Decision = action.type === 'acceptAll' ? 'accepted' : 'rejected';\n return {\n ...state,\n notice: null,\n items: state.items.map((s) => (s.decision === 'proposed' ? { ...s, decision } : s)),\n };\n }\n case 'move':\n return {\n ...state,\n items: state.items.map((s) => (s.key === action.key ? { ...s, rect: action.rect } : s)),\n };\n }\n}\n\nexport const proposed = (state: AssistState): Suggestion[] =>\n state.items.filter((s) => s.decision === 'proposed');\n\n/** Thrown into the detection when `timeoutMs` passes; its message is the panel's text. */\nexport class AssistTimeout extends Error {\n override readonly name = 'ASSIST_TIMEOUT';\n}\n\n/**\n * Everything the tool does that is not rendering. The UI tool is a thin skin\n * over this, and tests drive it directly.\n */\nexport interface AssistController {\n state(): AssistState;\n /** Forgets the suggestions when the source changed under the tool. */\n syncSource(ctx: UiToolContext): void;\n /**\n * Renders the unedited working copy, runs the detector, keeps what passes the\n * options, and accepts on its own what `acceptAbove` allows.\n */\n run(ctx: UiToolContext): Promise<void>;\n /**\n * Dispatches one `redact.add` for the suggestion and marks it accepted. When\n * the redact options refuse the operation, the suggestion stays proposed and\n * the state carries the reason as `notice`.\n */\n accept(key: number, ctx: UiToolContext): void;\n reject(key: number, ctx: UiToolContext): void;\n acceptAll(ctx: UiToolContext): void;\n rejectAll(ctx: UiToolContext): void;\n move(key: number, rect: Rect, ctx: UiToolContext): void;\n /** Stops a detection in flight and leaves the status as it was before the detection. */\n abort(): void;\n options(ctx: UiToolContext): AssistOptions;\n}\n\nexport function createAssistController(detector: Detector): AssistController {\n let state = initialState;\n let controller: AbortController | null = null;\n\n const set = (action: Action, ctx: UiToolContext) => {\n state = reduce(state, action);\n ctx.refresh();\n };\n const options = (ctx: UiToolContext): AssistOptions =>\n ctx.options<AssistOptions>('assist') ?? ASSIST_DEFAULT_OPTIONS;\n const abort = () => {\n if (!controller) return;\n controller.abort();\n controller = null;\n // The aborted run returns silently, so the status is reset here and not in its catch.\n state = reduce(state, { type: 'cancel' });\n };\n\n const accept = (key: number, ctx: UiToolContext) => {\n const item = state.items.find((s) => s.key === key && s.decision === 'proposed');\n if (!item) return;\n const opts = options(ctx);\n const redact = ctx.options<RedactOptions>('redact') ?? REDACT_DEFAULT_OPTIONS;\n const op = toRedactAdd(padRect(item.rect, opts.padding), redact, opId(), opts);\n // Checked before the dispatch: the editor's dispatch reports a violation as a\n // toast and returns, and the suggestion must not count as accepted then.\n const source = ctx.state.source;\n const violation = source\n ? ctx.session.registry.validateOperation(op, ctx.session.getDocument(), source)\n : null;\n if (violation) {\n set({ type: 'refuse', message: violation }, ctx);\n return;\n }\n try {\n ctx.dispatch(op);\n } catch (error) {\n if (!(error instanceof SealpixelError && error.name === 'OPTION_VIOLATION')) throw error;\n set({ type: 'refuse', message: error.message }, ctx);\n return;\n }\n set({ type: 'accept', key }, ctx);\n };\n\n return {\n state: () => state,\n options,\n abort,\n syncSource: (ctx) => {\n const source = ctx.state.source;\n const key = source ? (source.hash ?? source.id) : null;\n if (key && key !== state.sourceKey) {\n abort();\n state = reduce(state, { type: 'source', key });\n }\n },\n run: async (ctx) => {\n abort();\n const own = new AbortController();\n controller = own;\n const opts = options(ctx);\n const timer = setTimeout(\n () => own.abort(new AssistTimeout(ctx.t('assist.timeout'))),\n opts.timeoutMs,\n );\n set({ type: 'start' }, ctx);\n try {\n // The unedited, uncropped working copy: what the redact regions are measured against.\n const image = await ctx.session.renderDetached((log) => ({ ...log, ops: [] }), {\n signal: own.signal,\n });\n own.signal.throwIfAborted();\n set({ type: 'detecting' }, ctx);\n // Raced against the signal: a detector that ignores it cannot outlast the timeout.\n const found = await raceAbort(\n detector.detect(image, { signal: own.signal, options: opts }),\n own.signal,\n );\n own.signal.throwIfAborted();\n set({ type: 'results', detections: filterDetections(found, opts) }, ctx);\n if (opts.acceptAbove !== null) {\n const threshold = opts.acceptAbove;\n for (const item of proposed(state)) if (item.score >= threshold) accept(item.key, ctx);\n }\n } catch (error) {\n // A timeout is our own abort and gets reported; any other abort is silent.\n if (own.signal.aborted && !(own.signal.reason instanceof AssistTimeout)) return;\n const reason = own.signal.reason instanceof AssistTimeout ? own.signal.reason : error;\n set({ type: 'fail', message: (reason as Error).message }, ctx);\n } finally {\n clearTimeout(timer);\n if (controller === own) controller = null;\n }\n },\n accept,\n reject: (key, ctx) => set({ type: 'reject', key }, ctx),\n acceptAll: (ctx) => {\n for (const item of proposed(state)) accept(item.key, ctx);\n },\n rejectAll: (ctx) => set({ type: 'rejectAll' }, ctx),\n move: (key, rect, ctx) => set({ type: 'move', key, rect }, ctx),\n };\n}\n\n/** Settles with `promise`, or rejects with the signal's reason as soon as it aborts. */\nfunction raceAbort<T>(promise: Promise<T>, signal: AbortSignal): Promise<T> {\n if (signal.aborted) return Promise.reject(signal.reason);\n return new Promise<T>((resolve, reject) => {\n const onAbort = () => reject(signal.reason);\n signal.addEventListener('abort', onAbort, { once: true });\n promise.then(resolve, reject).finally(() => signal.removeEventListener('abort', onAbort));\n });\n}\n\n/** Redact coordinates live in image space: show the image before crop and resize. */\nfunction beforeCrop(log: EditLog): EditLog {\n return {\n ...log,\n ops: [\n ...log.ops,\n { type: 'crop.reset', id: '__sealpixel_preview_crop__' },\n { type: 'resize.clear', id: '__sealpixel_preview_resize__' },\n ],\n };\n}\n\nfunction clipToCrop(ctx: UiToolContext): void {\n const crop = (ctx.session.getDocument() as unknown as { crop?: CropLike }).crop;\n const preview = ctx.state.preview;\n ctx.clipPreview(preview ? cropClipPath(crop, preview.image.width, preview.image.height) : null);\n}\n\nexport function createAssistTool(detector: Detector): UiTool {\n const c = createAssistController(detector);\n let drag: { key: number; rect: Rect } | null = null;\n const busy = () => {\n const s = c.state().status;\n return s === 'loading' || s === 'detecting';\n };\n\n return {\n id: 'assist',\n icon: icons.assist,\n label: 'tool.assist',\n\n onSource: (ctx) => {\n c.syncSource(ctx);\n if (c.options(ctx).run === 'load' && c.state().status === 'idle') void c.run(ctx);\n },\n\n badge: (ctx) => {\n if (!c.options(ctx).badge || busy()) return null;\n const n = proposed(c.state()).length;\n return n > 0 ? n : null;\n },\n\n activate: (ctx) => {\n c.syncSource(ctx);\n clipToCrop(ctx);\n ctx.session.setPreviewTransform(beforeCrop);\n if (c.options(ctx).run === 'select' && c.state().status === 'idle') void c.run(ctx);\n },\n\n deactivate: (ctx) => {\n c.abort();\n drag = null;\n ctx.clipPreview(null);\n ctx.session.setPreviewTransform(null);\n },\n\n panel: (ctx) => {\n c.syncSource(ctx);\n clipToCrop(ctx);\n if (!ctx.session.registry.byId.has('redact')) {\n return html`<p class=\"status\" role=\"status\">${ctx.t('assist.needsRedact')}</p>`;\n }\n const opts = c.options(ctx);\n const state = c.state();\n const open = proposed(state);\n const text = state.notice\n ? ctx.t('assist.refused', { message: state.notice })\n : state.status === 'loading'\n ? ctx.t('assist.loading')\n : state.status === 'detecting'\n ? ctx.t('assist.detecting')\n : state.status === 'error'\n ? ctx.t('assist.error', { message: state.error ?? '' })\n : state.status === 'done'\n ? open.length > 0\n ? ctx.t('assist.found', { count: open.length })\n : ctx.t('assist.none')\n : '';\n return html`\n <div class=\"row\" role=\"group\" aria-label=${ctx.t('tool.assist')}>\n <div class=\"group\">\n <sealpixel-button data-action=\"detect\" ?disabled=${busy()} @click=${() => void c.run(ctx)}>${ctx.t('assist.detect')}</sealpixel-button>\n ${\n opts.bulk && open.length > 0\n ? html`<sealpixel-button data-action=\"accept-all\" variant=\"primary\" @click=${() => c.acceptAll(ctx)}>${ctx.t('assist.acceptAll')}</sealpixel-button>\n <sealpixel-button data-action=\"reject-all\" @click=${() => c.rejectAll(ctx)}>${ctx.t('assist.rejectAll')}</sealpixel-button>`\n : nothing\n }\n </div>\n </div>\n <p class=\"status\" role=\"status\" data-status=${state.status}>${text}</p>\n `;\n },\n\n overlay: (ctx) => {\n const { width: W, height: H, zoom } = ctx.stage;\n if (!W || !H) return svg``;\n const opts = c.options(ctx);\n const sw = 1.5 / zoom;\n const toN = (e: PointerEvent): [number, number] => {\n const p = ctx.stage.toImage(e.clientX, e.clientY);\n return [clamp01(p.x / W), clamp01(p.y / H)];\n };\n const shape = (item: Suggestion) => {\n const rect = drag?.key === item.key ? drag.rect : item.rect;\n // Press and move adjusts the proposal before accepting it.\n const down = (e: PointerEvent) => {\n e.stopPropagation();\n e.preventDefault();\n if (!opts.adjust) return;\n const start = toN(e);\n drag = { key: item.key, rect: item.rect };\n const move = (ev: PointerEvent) => {\n if (!drag) return;\n const q = toN(ev);\n drag.rect = translate(item.rect, q[0] - start[0], q[1] - start[1]);\n ctx.refresh();\n };\n const up = () => {\n window.removeEventListener('pointermove', move);\n window.removeEventListener('pointerup', up);\n window.removeEventListener('pointercancel', up);\n const d = drag;\n drag = null;\n if (d) c.move(item.key, d.rect, ctx);\n else ctx.refresh();\n };\n window.addEventListener('pointermove', move);\n window.addEventListener('pointerup', up);\n window.addEventListener('pointercancel', up);\n };\n const px = { x: rect.x * W, y: rect.y * H, width: rect.width * W, height: rect.height * H };\n return svg`\n <rect data-interactive data-suggestion=${item.key} x=${px.x} y=${px.y} width=${px.width} height=${px.height}\n fill=\"rgba(91,141,239,0.15)\" stroke=\"var(--sealpixel-color-accent)\" stroke-width=${sw}\n stroke-dasharray=${`${6 / zoom} ${4 / zoom}`} style=${opts.adjust ? 'cursor:move' : ''} @pointerdown=${down} />\n ${\n opts.showScore\n ? svg`<text x=${px.x + 4 / zoom} y=${px.y + px.height - 4 / zoom} font-size=${11 / zoom}\n fill=\"var(--sealpixel-color-accent)\" style=\"pointer-events:none;font-family:ui-monospace,monospace\">${item.score.toFixed(2)}</text>`\n : nothing\n }\n ${handleRow(px, ctx.stage, [\n {\n path: CHECK_PATH,\n label: ctx.t('assist.accept'),\n color: 'var(--sealpixel-color-accent)',\n action: 'accept',\n onActivate: () => c.accept(item.key, ctx),\n },\n {\n path: CROSS_PATH,\n label: ctx.t('assist.reject'),\n color: 'var(--sealpixel-color-danger)',\n action: 'reject',\n onActivate: () => c.reject(item.key, ctx),\n },\n ])}\n `;\n };\n return svg`${proposed(c.state()).map(shape)}`;\n },\n };\n}\n\nfunction translate(rect: Rect, dx: number, dy: number): Rect {\n return {\n ...rect,\n x: clamp(rect.x + dx, 0, 1 - rect.width),\n y: clamp(rect.y + dy, 0, 1 - rect.height),\n };\n}\nfunction clamp01(v: number): number {\n return clamp(v, 0, 1);\n}\nfunction clamp(v: number, lo: number, hi: number): number {\n return v < lo ? lo : v > hi ? hi : v;\n}\n"]}
@@ -26,4 +26,3 @@ export declare function isIdentityCrop(c: CropLike): boolean;
26
26
  * revealed.
27
27
  */
28
28
  export declare function cropClipPath(c: CropLike | undefined, W: number, H: number): string | null;
29
- //# sourceMappingURL=crop-mask.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"crop-mask.js","sourceRoot":"","sources":["../../src/tools/crop-mask.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,CAAW,EAAE,CAAS,EAAE,CAAS;IAC3D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjD,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,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AC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;IAClF,OAAO,SAAS,KAAK,IAAI,CAAC;AAC5B,CAAC","sourcesContent":["import type { Rect } from '@sealpixel/core';\n\nexport interface CropLike {\n mask?: 'none' | 'circle' | undefined;\n rotation: number;\n flipX: boolean;\n flipY: boolean;\n rect: Rect;\n}\n\n/**\n * The crop output mapped back into image pixels, as a polygon. Mirrors the\n * inverse affine in `crates/sealpixel-core/src/geometry.rs` (`crop_actual`):\n * out → bbox → centre → rotate(-r) → unflip → src.\n */\nexport function cropPolygon(c: CropLike, W: number, H: number): [number, number][] {\n const sin = Math.sin(c.rotation);\n const cos = Math.cos(c.rotation);\n const bw = W * Math.abs(cos) + H * Math.abs(sin);\n const bh = W * Math.abs(sin) + H * Math.abs(cos);\n const fx = c.flipX ? -1 : 1;\n const fy = c.flipY ? -1 : 1;\n const ox = c.rect.x * bw - bw / 2;\n const oy = c.rect.y * bh - bh / 2;\n const a = fx * cos;\n const b = fy * -sin;\n const cc = fx * sin;\n const d = fy * cos;\n const e = fx * (cos * ox + sin * oy) + W / 2;\n const f = fy * (-sin * ox + cos * oy) + H / 2;\n const outW = c.rect.width * bw;\n const outH = c.rect.height * bh;\n const map = (x: number, y: number): [number, number] => [a * x + cc * y + e, b * x + d * y + f];\n return [map(0, 0), map(outW, 0), map(outW, outH), map(0, outH)];\n}\n\n/** The ellipse inscribed in a (possibly rotated) rectangle given by its corners, as an SVG path. */\nfunction ellipsePath(p: [number, number][]): string {\n const [a, b, c, d] = p as [\n [number, number],\n [number, number],\n [number, number],\n [number, number],\n ];\n const cx = (a[0] + c[0]) / 2;\n const cy = (a[1] + c[1]) / 2;\n const rx = Math.hypot(b[0] - a[0], b[1] - a[1]) / 2;\n const ry = Math.hypot(d[0] - a[0], d[1] - a[1]) / 2;\n const rad = Math.atan2(b[1] - a[1], b[0] - a[0]);\n const angle = (rad * 180) / Math.PI;\n const ux = Math.cos(rad);\n const uy = Math.sin(rad);\n const sx = cx - rx * ux;\n const sy = cy - rx * uy;\n const ex = cx + rx * ux;\n const ey = cy + rx * uy;\n return `M${sx} ${sy}A${rx} ${ry} ${angle} 1 0 ${ex} ${ey}A${rx} ${ry} ${angle} 1 0 ${sx} ${sy}`;\n}\n\nexport function isIdentityCrop(c: CropLike): boolean {\n const r = c.rect;\n return (\n c.rotation === 0 &&\n !c.flipX &&\n !c.flipY &&\n (c.mask ?? 'none') === 'none' &&\n r.x === 0 &&\n r.y === 0 &&\n r.width === 1 &&\n r.height === 1\n );\n}\n\n/**\n * Tools that work in image space (redact, annotate) render the image before\n * crop and resize, because that is the space their shapes live in. This clips\n * the preview to what the crop keeps, so the user still sees the picture they\n * are working on rather than one with a border they already cut off.\n *\n * A `path()` clip in image pixels rather than a percentage polygon: the canvas\n * is sized in image pixels, so the numbers line up, and it is the only form\n * that can express a rotated crop or a circular one. It does not interpolate\n * with `polygon()`, which is fine here — this one is set on entry, not\n * revealed.\n */\nexport function cropClipPath(c: CropLike | undefined, W: number, H: number): string | null {\n if (!c || isIdentityCrop(c) || !W || !H) return null;\n const poly = cropPolygon(c, W, H);\n const inner =\n c.mask === 'circle'\n ? ellipsePath(poly)\n : `${poly.map(([x, y], i) => `${i === 0 ? 'M' : 'L'}${x} ${y}`).join(' ')} Z`;\n return `path('${inner}')`;\n}\n"]}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * What the crop rectangle does when the angle changes.
3
+ *
4
+ * The crop rect is normalised to the bounding box of the *rotated* image, not
5
+ * to the image (the core sizes the output as rect × rotated box). Left alone,
6
+ * a rect therefore covers more pixels the further the image is turned, and a
7
+ * rect that touches the box's edge takes in area outside the turned image.
8
+ * The two functions here decide the rect a change of angle should write, so
9
+ * the log still gets a plain `crop.set` with `rect` and `rotation`:
10
+ *
11
+ * - `straighten`: the slider. The frame stays where it is on the stage and
12
+ * keeps its size in pixels while the image turns behind it; then it shrinks
13
+ * about its centre, aspect kept, until every corner is inside the image.
14
+ * - `quarterTurn`: the ±90° buttons. The crop turns with the image, so the
15
+ * output is the previous output turned by a quarter.
16
+ *
17
+ * Positive angles turn clockwise on screen, as the core and CSS `rotate()` do.
18
+ */
19
+ import type { Rect } from '@sealpixel/core';
20
+ export interface Size {
21
+ width: number;
22
+ height: number;
23
+ }
24
+ /** Bounding box of `size` rotated by `angle` radians, in the same units. */
25
+ export declare function rotatedBox(size: Size, angle: number): Size;
26
+ /**
27
+ * The rect for a new angle: same frame on the stage, same size in pixels,
28
+ * then — with `constrain` — fitted inside the turned image. `image` is the
29
+ * source size in pixels; `margin` keeps the frame that far inside the image
30
+ * edge, in pixels, so the anti-aliased border of the turned image never
31
+ * enters the output.
32
+ */
33
+ export declare function straighten(rect: Rect, from: number, to: number, image: Size, constrain?: boolean, margin?: number): Rect;
34
+ /**
35
+ * True when every corner of `rect` (normalised to the box of the image turned
36
+ * by `angle`) lies inside the turned image, `margin` pixels in.
37
+ */
38
+ export declare function insideImage(rect: Rect, angle: number, image: Size, margin?: number): boolean;
39
+ /**
40
+ * A drag that cannot take the frame out of the turned image. `apply` maps a
41
+ * delta to the rect a free drag would give. The largest share of the delta
42
+ * that stays inside is taken; from there each axis is extended on its own, so
43
+ * the frame slides along the image edge instead of sticking to it. A frame
44
+ * that starts outside is not held back: the user has to be able to bring it in.
45
+ */
46
+ export declare function constrainDrag(apply: (dx: number, dy: number) => Rect, dx: number, dy: number, angle: number, image: Size, margin?: number): Rect;
47
+ /**
48
+ * The rotation in degrees split into whole quarter turns and the straightening
49
+ * that remains, which lies within ±45°. The slider shows the straightening
50
+ * only; the ±90° buttons own the quarters. Exactly ±45° belongs to two splits
51
+ * (a quarter less and +45°, or a quarter more and −45°), so `shown`, the
52
+ * straightening the slider showed last, breaks the tie: the slider stays at
53
+ * the end the user put it on instead of jumping to the other.
54
+ */
55
+ export declare function splitDegrees(deg: number, shown?: number): {
56
+ quarters: number;
57
+ fine: number;
58
+ };
59
+ /**
60
+ * A quarter turn of the crop with the image. `dir` is +1 for clockwise. The
61
+ * box's normalised coordinates turn with it: clockwise, a point (u, v)
62
+ * becomes (1 − v, u).
63
+ */
64
+ export declare function quarterTurn(rect: Rect, dir: 1 | -1): Rect;