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

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 (70) hide show
  1. package/dist/components/editor/empty-state.d.ts +14 -0
  2. package/dist/components/editor/empty-state.js +38 -0
  3. package/dist/components/editor/empty-state.js.map +1 -0
  4. package/dist/components/editor/json-attribute.d.ts +5 -0
  5. package/dist/components/editor/json-attribute.js +18 -0
  6. package/dist/components/editor/json-attribute.js.map +1 -0
  7. package/dist/components/editor/panel-fit.d.ts +20 -0
  8. package/dist/components/editor/panel-fit.js +60 -0
  9. package/dist/components/editor/panel-fit.js.map +1 -0
  10. package/dist/components/editor/styles.d.ts +2 -0
  11. package/dist/components/editor/styles.js +697 -0
  12. package/dist/components/editor/styles.js.map +1 -0
  13. package/dist/components/editor/toast.d.ts +8 -0
  14. package/dist/components/editor/toast.js +21 -0
  15. package/dist/components/editor/toast.js.map +1 -0
  16. package/dist/components/sealpixel-editor.d.ts +9 -44
  17. package/dist/components/sealpixel-editor.js +45 -888
  18. package/dist/components/sealpixel-editor.js.map +1 -1
  19. package/dist/components/sealpixel-stage.js +11 -2
  20. package/dist/components/sealpixel-stage.js.map +1 -1
  21. package/dist/controllers/history-shortcuts-controller.d.ts +18 -0
  22. package/dist/controllers/history-shortcuts-controller.js +68 -0
  23. package/dist/controllers/history-shortcuts-controller.js.map +1 -0
  24. package/dist/locales/de.js +16 -0
  25. package/dist/locales/de.js.map +1 -1
  26. package/dist/locales/en.js +16 -0
  27. package/dist/locales/en.js.map +1 -1
  28. package/dist/locales/es.js +16 -0
  29. package/dist/locales/es.js.map +1 -1
  30. package/dist/locales/fr.js +16 -0
  31. package/dist/locales/fr.js.map +1 -1
  32. package/dist/locales/ja.js +16 -0
  33. package/dist/locales/ja.js.map +1 -1
  34. package/dist/locales/pt.js +16 -0
  35. package/dist/locales/pt.js.map +1 -1
  36. package/dist/tools/annotate.d.ts +58 -0
  37. package/dist/tools/annotate.js +136 -12
  38. package/dist/tools/annotate.js.map +1 -1
  39. package/dist/tools/assist.d.ts +3 -0
  40. package/dist/tools/assist.js +44 -9
  41. package/dist/tools/assist.js.map +1 -1
  42. package/dist/tools/crop-mask.d.ts +2 -0
  43. package/dist/tools/crop-mask.js +11 -0
  44. package/dist/tools/crop-mask.js.map +1 -1
  45. package/dist/tools/crop.d.ts +9 -0
  46. package/dist/tools/crop.js +117 -48
  47. package/dist/tools/crop.js.map +1 -1
  48. package/dist/tools/filter.js +41 -19
  49. package/dist/tools/filter.js.map +1 -1
  50. package/dist/tools/finetune.js +10 -7
  51. package/dist/tools/finetune.js.map +1 -1
  52. package/dist/tools/frame.js +10 -10
  53. package/dist/tools/frame.js.map +1 -1
  54. package/dist/tools/instance-state.d.ts +8 -0
  55. package/dist/tools/instance-state.js +32 -0
  56. package/dist/tools/instance-state.js.map +1 -0
  57. package/dist/tools/keys.d.ts +95 -3
  58. package/dist/tools/keys.js +135 -2
  59. package/dist/tools/keys.js.map +1 -1
  60. package/dist/tools/redact.d.ts +18 -10
  61. package/dist/tools/redact.js +233 -35
  62. package/dist/tools/redact.js.map +1 -1
  63. package/dist/tools/region-transform.d.ts +23 -14
  64. package/dist/tools/region-transform.js +45 -32
  65. package/dist/tools/region-transform.js.map +1 -1
  66. package/dist/tools/resize.js +11 -9
  67. package/dist/tools/resize.js.map +1 -1
  68. package/dist/tools/sticker.js +7 -3
  69. package/dist/tools/sticker.js.map +1 -1
  70. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"assist.js","sourceRoot":"","sources":["../../src/tools/assist.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EACL,sBAAsB,EAItB,gBAAgB,EAChB,OAAO,EACP,sBAAsB,EAEtB,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE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E,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"]}
1
+ {"version":3,"file":"assist.js","sourceRoot":"","sources":["../../src/tools/assist.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EACL,sBAAsB,EAItB,gBAAgB,EAChB,UAAU,EACV,OAAO,EACP,aAAa,EACb,sBAAsB,EAEtB,WAAW,EACX,aAAa,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAiB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAsDjE,MAAM,CAAC,MAAM,YAAY,GAAgB;IACvC,SAAS,EAAE,IAAI;IACf,MAAM,EAAE,MAAM;IACd,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;CACb,CAAC;AAEF,IAAI,OAAO,GAAG,CAAC,CAAC;AAEhB,wEAAwE;AACxE,MAAM,UAAU,MAAM,CAAC,KAAkB,EAAE,MAAc;IACvD,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,QAAQ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EAAE,UAAU;wBAChB,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,KAAK,EAAE;wBAC5C,KAAK,EAAE,+BAA+B;wBACtC,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 padPolygon,\n padRect,\n polygonBounds,\n REDACT_DEFAULT_OPTIONS,\n type RedactOptions,\n toRedactAdd,\n usablePolygon,\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 /** A usable outline from the detector, moved together with `rect`. */\n polygon: [number, number][] | null;\n reason: string | null;\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) => {\n const polygon = usablePolygon(d);\n return {\n key: nextKey++,\n // The box of a usable polygon, so that a move keeps the polygon inside the image.\n rect: polygon ? polygonBounds(polygon) : d.rect,\n score: d.score,\n label: d.label,\n polygon,\n reason: typeof d.reason === 'string' && d.reason !== '' ? d.reason : null,\n decision: 'proposed' as const,\n };\n }),\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) => {\n if (s.key !== action.key) return s;\n const dx = action.rect.x - s.rect.x;\n const dy = action.rect.y - s.rect.y;\n // The rect is the polygon's box and stays in the image, so no point leaves it.\n const polygon = s.polygon?.map((p): [number, number] => [p[0] + dx, p[1] + dy]) ?? null;\n return { ...s, rect: action.rect, polygon };\n }),\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 // A polygon becomes a path region only when the redact options allow paths.\n const grown =\n item.polygon && redact.shapes.includes('path')\n ? padPolygon(item.polygon, opts.padding)\n : null;\n const op = grown\n ? toRedactAdd({ kind: 'path', points: grown }, redact, opId(), opts)\n : 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 const dx = rect.x - item.rect.x;\n const dy = rect.y - item.rect.y;\n const title = item.reason ? `${item.label}: ${item.reason}` : item.label;\n const dash = `${6 / zoom} ${4 / zoom}`;\n return svg`\n ${\n item.polygon\n ? svg`<polygon data-interactive data-suggestion=${item.key} data-shape=\"polygon\"\n points=${item.polygon.map((p) => `${(p[0] + dx) * W},${(p[1] + dy) * H}`).join(' ')}\n fill=\"rgba(91,141,239,0.15)\" stroke=\"var(--sealpixel-color-accent)\" stroke-width=${sw}\n stroke-dasharray=${dash} style=${opts.adjust ? 'cursor:move' : ''} @pointerdown=${down}><title>${title}</title></polygon>`\n : svg`<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=${dash} style=${opts.adjust ? 'cursor:move' : ''} @pointerdown=${down}><title>${title}</title></rect>`\n }\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')}: ${title}`,\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')}: ${title}`,\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,3 +26,5 @@ 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
+ /** The box around what the crop keeps, in image pixels; null for no crop. */
30
+ export declare function cropBox(c: CropLike | undefined, W: number, H: number): Rect | null;
@@ -72,4 +72,15 @@ export function cropClipPath(c, W, H) {
72
72
  : `${poly.map(([x, y], i) => `${i === 0 ? 'M' : 'L'}${x} ${y}`).join(' ')} Z`;
73
73
  return `path('${inner}')`;
74
74
  }
75
+ /** The box around what the crop keeps, in image pixels; null for no crop. */
76
+ export function cropBox(c, W, H) {
77
+ if (!c || isIdentityCrop(c) || !W || !H)
78
+ return null;
79
+ const poly = cropPolygon(c, W, H);
80
+ const xs = poly.map((p) => p[0]);
81
+ const ys = poly.map((p) => p[1]);
82
+ const x = Math.min(...xs);
83
+ const y = Math.min(...ys);
84
+ return { x, y, width: Math.max(...xs) - x, height: Math.max(...ys) - y };
85
+ }
75
86
  //# sourceMappingURL=crop-mask.js.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,CAA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,CAAC,CAAC,KAAK,KAAK,CAAC;QACb,CAAC,CAAC,MAAM,KAAK,CAAC,CACf,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAAC,CAAuB,EAAE,CAAS,EAAE,CAAS;IACxE,IAAI,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACrD,MAAM,IAAI,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAClC,MAAM,KAAK,GACT,CAAC,CAAC,IAAI,KAAK,QAAQ;QACjB,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC;QACnB,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,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"]}
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,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjD,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAClC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,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EAAE,CAAS,EAAE,CAAS;IACnE,IAAI,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACrD,MAAM,IAAI,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAClC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;IAC1B,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;IAC1B,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;AAC3E,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\n/** The box around what the crop keeps, in image pixels; null for no crop. */\nexport function cropBox(c: CropLike | undefined, W: number, H: number): Rect | null {\n if (!c || isIdentityCrop(c) || !W || !H) return null;\n const poly = cropPolygon(c, W, H);\n const xs = poly.map((p) => p[0]);\n const ys = poly.map((p) => p[1]);\n const x = Math.min(...xs);\n const y = Math.min(...ys);\n return { x, y, width: Math.max(...xs) - x, height: Math.max(...ys) - y };\n}\n"]}
@@ -7,4 +7,13 @@ export declare const cropTool: UiTool;
7
7
  * output pixels; `stageAspect` converts it into normalised units.
8
8
  */
9
9
  export declare function applyDrag(start: Rect, handle: Handle, dx: number, dy: number, aspect: number | null, stageAspect: number): Rect;
10
+ /**
11
+ * The largest centred square in source pixels. The circle reset sets the
12
+ * rotation to 0, so the rect is normalised to the source itself. The crop
13
+ * plugin's initial op writes the same rect.
14
+ */
15
+ export declare function centredSquare(source: {
16
+ width: number;
17
+ height: number;
18
+ }): Rect;
10
19
  export {};
@@ -3,6 +3,8 @@ import { html, nothing, svg } from 'lit';
3
3
  import { icons } from '../icons.js';
4
4
  import { constrainDrag, quarterTurn, splitDegrees, straighten } from './crop-rotation.js';
5
5
  import { opId } from './finetune.js';
6
+ import { toolState } from './instance-state.js';
7
+ import { announce, elementKeys } from './keys.js';
6
8
  /**
7
9
  * While the crop tool is active the preview shows the whole rotated image
8
10
  * (rect forced to full, resize cleared), and the gizmo draws the crop
@@ -25,50 +27,32 @@ function showFullRect(log) {
25
27
  ],
26
28
  };
27
29
  }
28
- const drag = {
29
- handle: 'move',
30
- start: { x: 0, y: 0, width: 1, height: 1 },
31
- sx: 0,
32
- sy: 0,
33
- live: null,
34
- };
35
30
  /**
36
31
  * How long the pointer has to be still after a change before the stage shows
37
32
  * the result. Long enough never to fire between two drags, short enough that
38
33
  * nobody waits for it.
39
34
  */
40
35
  const SETTLE_MS = 500;
41
- /**
42
- * The straightening the rotation slider showed last, in degrees. It breaks
43
- * the tie at exactly ±45°, where the split of the document's rotation into
44
- * quarter turns and straightening is not unique (see `splitDegrees`).
45
- */
46
- let shownFine = 0;
47
- /**
48
- * The crop is written to the log the moment a handle is released, but the
49
- * stage keeps showing the whole image, because a corner cannot be pulled
50
- * outwards through an edge that is off screen. Letting go therefore looks
51
- * exactly like doing nothing. After the pointer rests, the scrim closes over
52
- * what the crop removes and the gizmo fades, so what is left on the stage is
53
- * the picture that will come out. Touching the gizmo brings it all back.
54
- */
55
- const settle = {
56
- at: null,
57
- timer: null,
58
- touched: false,
59
- rect: null,
60
- };
61
- /**
62
- * Between a change of angle and the preview that shows it, the gizmo keeps
63
- * drawing the rect it drew on the preview still on the stage. The new rect is
64
- * normalised to another bounding box; drawn on the old preview it would show
65
- * at the wrong size for those frames and jump back when the render lands.
66
- * Cleared when a preview with another geometry arrives.
67
- */
68
- let drawn = null;
36
+ const createCropState = () => ({
37
+ drag: {
38
+ handle: 'move',
39
+ start: { x: 0, y: 0, width: 1, height: 1 },
40
+ sx: 0,
41
+ sy: 0,
42
+ live: null,
43
+ },
44
+ shownFine: 0,
45
+ settle: {
46
+ at: null,
47
+ timer: null,
48
+ touched: false,
49
+ rect: null,
50
+ },
51
+ drawn: null,
52
+ });
69
53
  /** Records the crop now in the log as the one this tool is showing. */
70
54
  function markRect(ctx) {
71
- settle.rect = ctx.session.getDocument().crop.rect;
55
+ toolState(ctx, createCropState).settle.rect = ctx.session.getDocument().crop.rect;
72
56
  }
73
57
  /** The preview clipped to the crop, in percentages of the canvas box. */
74
58
  function clipFor(rect, circle) {
@@ -85,6 +69,7 @@ function clipFor(rect, circle) {
85
69
  }
86
70
  const FULL_CLIP = 'polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%)';
87
71
  function unsettle(ctx) {
72
+ const { settle } = toolState(ctx, createCropState);
88
73
  if (settle.timer !== null)
89
74
  clearTimeout(settle.timer);
90
75
  settle.timer = null;
@@ -95,6 +80,7 @@ function unsettle(ctx) {
95
80
  }
96
81
  }
97
82
  function scheduleSettle(ctx) {
83
+ const { settle } = toolState(ctx, createCropState);
98
84
  if (settle.timer !== null)
99
85
  clearTimeout(settle.timer);
100
86
  settle.at = null;
@@ -116,6 +102,7 @@ export const cropTool = {
116
102
  icon: icons.crop,
117
103
  label: 'tool.crop',
118
104
  activate: (ctx) => {
105
+ const { settle } = toolState(ctx, createCropState);
119
106
  unsettle(ctx);
120
107
  markRect(ctx);
121
108
  settle.touched = false;
@@ -123,8 +110,10 @@ export const cropTool = {
123
110
  ctx.session.setPreviewTransform(showFullRect);
124
111
  },
125
112
  deactivate: (ctx) => {
113
+ const state = toolState(ctx, createCropState);
114
+ const { drag, settle } = state;
126
115
  drag.live = null;
127
- drawn = null;
116
+ state.drawn = null;
128
117
  settle.rect = null;
129
118
  unsettle(ctx);
130
119
  // The next preview is the real crop; nothing left to clip.
@@ -138,11 +127,12 @@ export const cropTool = {
138
127
  ctx.session.setPreviewTransform(null);
139
128
  },
140
129
  panel: (ctx) => {
130
+ const state = toolState(ctx, createCropState);
141
131
  const doc = ctx.document.crop;
142
132
  // The slider straightens within ±45°; the quarter turns stay with the
143
133
  // ±90° buttons, so the dial's whole width is one quarter of a turn.
144
- const { quarters, fine } = splitDegrees((doc.rotation * 180) / Math.PI, shownFine);
145
- shownFine = fine;
134
+ const { quarters, fine } = splitDegrees((doc.rotation * 180) / Math.PI, state.shownFine);
135
+ state.shownFine = fine;
146
136
  // A rotation, a flip or an aspect ratio is a change like a drag is: it
147
137
  // leaves the settled view first, so the surroundings are there to see what
148
138
  // swings into the frame, and settles into the result the same way after.
@@ -153,7 +143,7 @@ export const cropTool = {
153
143
  const set = (patch) => {
154
144
  unsettle(ctx);
155
145
  if ('rotation' in patch)
156
- drawn = { rect: doc.rect, geometry: ctx.stage.geometry };
146
+ state.drawn = { rect: doc.rect, geometry: ctx.stage.geometry };
157
147
  ctx.dispatch({ type: 'crop.set', id: opId(), ...patch });
158
148
  markRect(ctx);
159
149
  scheduleSettle(ctx);
@@ -174,7 +164,7 @@ export const cropTool = {
174
164
  rotation: 0,
175
165
  flipX: false,
176
166
  flipY: false,
177
- rect: { x: 0, y: 0, width: 1, height: 1 },
167
+ rect: src ? centredSquare(src) : { x: 0, y: 0, width: 1, height: 1 },
178
168
  aspect: 1,
179
169
  mask: 'circle',
180
170
  }
@@ -216,7 +206,7 @@ export const cropTool = {
216
206
  ctx.hint({ rotate: ((e.detail - fine) * Math.PI) / 180 });
217
207
  }}
218
208
  @commit=${(e) => {
219
- shownFine = e.detail;
209
+ state.shownFine = e.detail;
220
210
  const rotation = ((quarters * 90 + e.detail) * Math.PI) / 180;
221
211
  // The frame stays where it is and keeps its size; the image turns
222
212
  // behind it. See crop-rotation.ts for why the rect has to move.
@@ -256,6 +246,8 @@ export const cropTool = {
256
246
  `;
257
247
  },
258
248
  overlay: (ctx) => {
249
+ const state = toolState(ctx, createCropState);
250
+ const { drag, settle } = state;
259
251
  const doc = ctx.document.crop;
260
252
  // An undo, a redo or a time travel changes the crop without passing through
261
253
  // this tool, and the settled view does not follow on its own: the stage
@@ -267,11 +259,11 @@ export const cropTool = {
267
259
  unsettle(ctx);
268
260
  }
269
261
  const { width: W, height: H, zoom } = ctx.stage;
270
- if (drawn && drawn.geometry !== ctx.stage.geometry)
271
- drawn = null;
262
+ if (state.drawn && state.drawn.geometry !== ctx.stage.geometry)
263
+ state.drawn = null;
272
264
  if (!W || !H)
273
265
  return svg ``;
274
- const r = drag.live ?? drawn?.rect ?? doc.rect;
266
+ const r = drag.live ?? state.drawn?.rect ?? doc.rect;
275
267
  const x = r.x * W;
276
268
  const y = r.y * H;
277
269
  const w = r.width * W;
@@ -292,13 +284,14 @@ export const cropTool = {
292
284
  e.stopPropagation();
293
285
  e.preventDefault();
294
286
  unsettle(ctx);
295
- drawn = null;
287
+ state.drawn = null;
296
288
  const p = ctx.stage.toImage(e.clientX, e.clientY);
297
289
  drag.handle = handle;
298
290
  drag.start = doc.rect;
299
291
  drag.sx = p.x / W;
300
292
  drag.sy = p.y / H;
301
293
  drag.live = doc.rect;
294
+ drag.keys = false;
302
295
  const options = ctx.options('crop') ?? CROP_DEFAULT_OPTIONS;
303
296
  const src = ctx.state.source;
304
297
  const move = (ev) => {
@@ -330,6 +323,54 @@ export const cropTool = {
330
323
  window.addEventListener('pointerup', up);
331
324
  window.addEventListener('pointercancel', up);
332
325
  };
326
+ // The keys on a focused handle or on the frame drive the same live rect as
327
+ // a pointer drag, and the release writes one crop.set. The view does not
328
+ // settle afterwards: the focused handle would fade out under the focus.
329
+ const keysFor = (handle) => elementKeys(ctx.stage, {
330
+ select: () => unsettle(ctx),
331
+ move: (dx, dy) => {
332
+ if (drag.live && !drag.keys)
333
+ return;
334
+ unsettle(ctx);
335
+ state.drawn = null;
336
+ const base = drag.live ?? doc.rect;
337
+ const options = ctx.options('crop') ?? CROP_DEFAULT_OPTIONS;
338
+ const src = ctx.state.source;
339
+ const apply = (ddx, ddy) => applyDrag(base, handle, ddx, ddy, doc.aspect, W / H);
340
+ drag.keys = true;
341
+ drag.live =
342
+ options.outside === 'forbid' && doc.rotation !== 0 && src
343
+ ? constrainDrag(apply, dx, dy, doc.rotation, src)
344
+ : apply(dx, dy);
345
+ ctx.refresh();
346
+ },
347
+ commit: (e) => {
348
+ if (!drag.keys)
349
+ return;
350
+ const final = drag.live;
351
+ drag.live = null;
352
+ drag.keys = false;
353
+ if (final && !sameRect(final, doc.rect)) {
354
+ ctx.dispatch({ type: 'crop.set', id: opId(), rect: final });
355
+ settle.touched = true;
356
+ const size = cropSize(final, doc.rotation, ctx.state.source);
357
+ if (size)
358
+ announce(e.target, ctx.t('stage.size', size));
359
+ }
360
+ markRect(ctx);
361
+ ctx.refresh();
362
+ },
363
+ remove: () => { },
364
+ escape: () => {
365
+ if (!drag.keys)
366
+ return false;
367
+ drag.live = null;
368
+ drag.keys = false;
369
+ ctx.refresh();
370
+ return true;
371
+ },
372
+ });
373
+ const frameKeys = keysFor('move');
333
374
  const circleShape = (ctx.options('crop') ?? CROP_DEFAULT_OPTIONS).shape === 'circle' ||
334
375
  doc.mask === 'circle';
335
376
  const cx = x + w / 2;
@@ -359,9 +400,12 @@ export const cropTool = {
359
400
  pointer-events="none"
360
401
  />
361
402
  ${circleShape ? svg `<ellipse data-crop-shape="circle" cx=${cx} cy=${cy} rx=${w / 2} ry=${h / 2} fill="none" stroke="white" stroke-width=${sw} style=${gizmo} pointer-events="none" />` : nothing}
362
- <rect data-interactive data-handle="move" x=${x} y=${y} width=${w} height=${h} fill="transparent" stroke="white" stroke-width=${sw} style=${`cursor:move;transition:stroke-opacity ${ease};stroke-opacity:${shown ? 0 : 1}`} @pointerdown=${start('move')} />
403
+ <rect data-interactive data-handle="move" tabindex="0" role="button" aria-label=${ctx.t('crop.area')} @focus=${frameKeys.focus} @keydown=${frameKeys.keydown} @keyup=${frameKeys.keyup} @blur=${frameKeys.blur} x=${x} y=${y} width=${w} height=${h} fill="transparent" stroke="white" stroke-width=${sw} style=${`cursor:move;transition:stroke-opacity ${ease};stroke-opacity:${shown ? 0 : 1}`} @pointerdown=${start('move')} />
363
404
  <path d=${`M${x + w / 3} ${y}V${y + h}M${x + (2 * w) / 3} ${y}V${y + h}M${x} ${y + h / 3}H${x + w}M${x} ${y + (2 * h) / 3}H${x + w}`} stroke="rgba(255,255,255,0.35)" stroke-width=${sw / 1.5} fill="none" style=${gizmo} pointer-events="none" />
364
- ${handles.map((hd) => svg `<circle data-interactive data-handle=${hd.id} cx=${hd.cx} cy=${hd.cy} r=${hr} fill="white" stroke="var(--sealpixel-color-accent)" stroke-width=${sw} style=${`cursor:${cursorFor(hd.id)};transition:opacity ${ease};opacity:${shown ? 0 : 1}`} @pointerdown=${start(hd.id)} />`)}
405
+ ${handles.map((hd) => {
406
+ const k = keysFor(hd.id);
407
+ return svg `<circle data-interactive data-handle=${hd.id} tabindex="0" role="button" aria-label=${ctx.t(`handle.${hd.id}`)} @focus=${k.focus} @keydown=${k.keydown} @keyup=${k.keyup} @blur=${k.blur} cx=${hd.cx} cy=${hd.cy} r=${hr} fill="white" stroke="var(--sealpixel-color-accent)" stroke-width=${sw} style=${`cursor:${cursorFor(hd.id)};transition:opacity ${ease};opacity:${shown ? 0 : 1}`} @pointerdown=${start(hd.id)} />`;
408
+ })}
365
409
  `;
366
410
  },
367
411
  };
@@ -378,6 +422,20 @@ function cursorFor(h) {
378
422
  move: 'move',
379
423
  }[h];
380
424
  }
425
+ /**
426
+ * The output size of a crop rect in source pixels: the rect is normalised
427
+ * to the box around the turned source, as in `crop-mask.ts`.
428
+ */
429
+ function cropSize(rect, rotation, src) {
430
+ if (!src)
431
+ return null;
432
+ const sin = Math.abs(Math.sin(rotation));
433
+ const cos = Math.abs(Math.cos(rotation));
434
+ return {
435
+ width: Math.round(rect.width * (src.width * cos + src.height * sin)),
436
+ height: Math.round(rect.height * (src.width * sin + src.height * cos)),
437
+ };
438
+ }
381
439
  function sameRect(a, b) {
382
440
  return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
383
441
  }
@@ -439,6 +497,17 @@ function fitAspect(rect, aspect, ctx) {
439
497
  const stageAspect = W && H ? W / H : 1;
440
498
  return applyDrag({ ...rect }, 'se', 0, 0, aspect, stageAspect);
441
499
  }
500
+ /**
501
+ * The largest centred square in source pixels. The circle reset sets the
502
+ * rotation to 0, so the rect is normalised to the source itself. The crop
503
+ * plugin's initial op writes the same rect.
504
+ */
505
+ export function centredSquare(source) {
506
+ const side = Math.min(source.width, source.height);
507
+ const width = side / source.width;
508
+ const height = side / source.height;
509
+ return { x: (1 - width) / 2, y: (1 - height) / 2, width, height };
510
+ }
442
511
  function clamp(v, lo, hi) {
443
512
  return v < lo ? lo : v > hi ? hi : v;
444
513
  }