@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.
- package/dist/components/editor/empty-state.d.ts +14 -0
- package/dist/components/editor/empty-state.js +38 -0
- package/dist/components/editor/empty-state.js.map +1 -0
- package/dist/components/editor/json-attribute.d.ts +5 -0
- package/dist/components/editor/json-attribute.js +18 -0
- package/dist/components/editor/json-attribute.js.map +1 -0
- package/dist/components/editor/panel-fit.d.ts +20 -0
- package/dist/components/editor/panel-fit.js +60 -0
- package/dist/components/editor/panel-fit.js.map +1 -0
- package/dist/components/editor/styles.d.ts +2 -0
- package/dist/components/editor/styles.js +697 -0
- package/dist/components/editor/styles.js.map +1 -0
- package/dist/components/editor/toast.d.ts +8 -0
- package/dist/components/editor/toast.js +21 -0
- package/dist/components/editor/toast.js.map +1 -0
- package/dist/components/sealpixel-editor.d.ts +9 -44
- package/dist/components/sealpixel-editor.js +45 -888
- package/dist/components/sealpixel-editor.js.map +1 -1
- package/dist/components/sealpixel-stage.js +11 -2
- package/dist/components/sealpixel-stage.js.map +1 -1
- package/dist/controllers/history-shortcuts-controller.d.ts +18 -0
- package/dist/controllers/history-shortcuts-controller.js +68 -0
- package/dist/controllers/history-shortcuts-controller.js.map +1 -0
- package/dist/locales/de.js +16 -0
- package/dist/locales/de.js.map +1 -1
- package/dist/locales/en.js +16 -0
- package/dist/locales/en.js.map +1 -1
- package/dist/locales/es.js +16 -0
- package/dist/locales/es.js.map +1 -1
- package/dist/locales/fr.js +16 -0
- package/dist/locales/fr.js.map +1 -1
- package/dist/locales/ja.js +16 -0
- package/dist/locales/ja.js.map +1 -1
- package/dist/locales/pt.js +16 -0
- package/dist/locales/pt.js.map +1 -1
- package/dist/tools/annotate.d.ts +58 -0
- package/dist/tools/annotate.js +136 -12
- package/dist/tools/annotate.js.map +1 -1
- package/dist/tools/assist.d.ts +3 -0
- package/dist/tools/assist.js +44 -9
- package/dist/tools/assist.js.map +1 -1
- package/dist/tools/crop-mask.d.ts +2 -0
- package/dist/tools/crop-mask.js +11 -0
- package/dist/tools/crop-mask.js.map +1 -1
- package/dist/tools/crop.d.ts +9 -0
- package/dist/tools/crop.js +117 -48
- package/dist/tools/crop.js.map +1 -1
- package/dist/tools/filter.js +41 -19
- package/dist/tools/filter.js.map +1 -1
- package/dist/tools/finetune.js +10 -7
- package/dist/tools/finetune.js.map +1 -1
- package/dist/tools/frame.js +10 -10
- package/dist/tools/frame.js.map +1 -1
- package/dist/tools/instance-state.d.ts +8 -0
- package/dist/tools/instance-state.js +32 -0
- package/dist/tools/instance-state.js.map +1 -0
- package/dist/tools/keys.d.ts +95 -3
- package/dist/tools/keys.js +135 -2
- package/dist/tools/keys.js.map +1 -1
- package/dist/tools/redact.d.ts +18 -10
- package/dist/tools/redact.js +233 -35
- package/dist/tools/redact.js.map +1 -1
- package/dist/tools/region-transform.d.ts +23 -14
- package/dist/tools/region-transform.js +45 -32
- package/dist/tools/region-transform.js.map +1 -1
- package/dist/tools/resize.js +11 -9
- package/dist/tools/resize.js.map +1 -1
- package/dist/tools/sticker.js +7 -3
- package/dist/tools/sticker.js.map +1 -1
- package/package.json +4 -4
package/dist/tools/crop.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crop.js","sourceRoot":"","sources":["../../src/tools/crop.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAoB,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAarC;;;;;GAKG;AACH,SAAS,YAA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AM,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACrC,MAAM,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtC,IAAI,GAAG,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IACjF,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,SAAS,CAAC,IAAU,EAAE,MAAc,EAAE,GAAkB;IAC/D,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC;IAC1C,MAAM,WAAW,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,OAAO,SAAS,CAAC,EAAE,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AACjE,CAAC;AAED,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, Geometry, Rect } from '@sealpixel/core';\nimport { CROP_DEFAULT_OPTIONS, type CropOptions, ORIGINAL_ASPECT } from '@sealpixel/plugins';\nimport { html, nothing, svg } from 'lit';\nimport { icons } from '../icons.js';\nimport type { UiTool, UiToolContext } from '../tool.js';\nimport { constrainDrag, quarterTurn, splitDegrees, straighten } from './crop-rotation.js';\nimport { opId } from './finetune.js';\n\ninterface CropDoc {\n mask?: 'none' | 'circle' | undefined;\n rotation: number;\n flipX: boolean;\n flipY: boolean;\n rect: Rect;\n aspect: number | null;\n}\n\ntype Handle = 'nw' | 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'move';\n\n/**\n * While the crop tool is active the preview shows the whole rotated image\n * (rect forced to full, resize cleared), and the gizmo draws the crop\n * rectangle on top. A resize with `cover` or `fill` would cut or stretch that\n * image, and the gizmo would map onto a box that is not the one it edits.\n */\nfunction showFullRect(log: EditLog): EditLog {\n return {\n ...log,\n ops: [\n ...log.ops,\n {\n type: 'crop.set',\n id: '__sealpixel_preview_rect__',\n rect: { x: 0, y: 0, width: 1, height: 1 },\n // The gizmo draws the round mask itself; the preview shows the unmasked pixels.\n mask: 'none',\n },\n { type: 'resize.clear', id: '__sealpixel_preview_resize__' },\n ],\n };\n}\n\nconst drag: { handle: Handle; start: Rect; sx: number; sy: number; live: Rect | null } = {\n handle: 'move',\n start: { x: 0, y: 0, width: 1, height: 1 },\n sx: 0,\n sy: 0,\n live: null,\n};\n\n/**\n * How long the pointer has to be still after a change before the stage shows\n * the result. Long enough never to fire between two drags, short enough that\n * nobody waits for it.\n */\nconst SETTLE_MS = 500;\n\n/**\n * The straightening the rotation slider showed last, in degrees. It breaks\n * the tie at exactly ±45°, where the split of the document's rotation into\n * quarter turns and straightening is not unique (see `splitDegrees`).\n */\nlet shownFine = 0;\n\n/**\n * The crop is written to the log the moment a handle is released, but the\n * stage keeps showing the whole image, because a corner cannot be pulled\n * outwards through an edge that is off screen. Letting go therefore looks\n * exactly like doing nothing. After the pointer rests, the scrim closes over\n * what the crop removes and the gizmo fades, so what is left on the stage is\n * the picture that will come out. Touching the gizmo brings it all back.\n */\nconst settle: {\n at: number | null;\n timer: ReturnType<typeof setTimeout> | null;\n /** Whether this visit to the tool actually changed the crop. */\n touched: boolean;\n /**\n * The crop this tool last wrote to the log, or read on activation. The\n * settled view — a clip on the stage and a gizmo faded out — lives here and\n * not in the log, so a crop that changes without passing through this tool\n * has to be noticed. Null while the tool is not active.\n */\n rect: Rect | null;\n} = {\n at: null,\n timer: null,\n touched: false,\n rect: null,\n};\n\n/**\n * Between a change of angle and the preview that shows it, the gizmo keeps\n * drawing the rect it drew on the preview still on the stage. The new rect is\n * normalised to another bounding box; drawn on the old preview it would show\n * at the wrong size for those frames and jump back when the render lands.\n * Cleared when a preview with another geometry arrives.\n */\nlet drawn: { rect: Rect; geometry: Geometry | null } | null = null;\n\n/** Records the crop now in the log as the one this tool is showing. */\nfunction markRect(ctx: UiToolContext): void {\n settle.rect = (ctx.session.getDocument() as unknown as { crop: CropDoc }).crop.rect;\n}\n\n/** The preview clipped to the crop, in percentages of the canvas box. */\nfunction clipFor(rect: Rect, circle: boolean): string {\n const l = rect.x * 100;\n const t = rect.y * 100;\n const r = (rect.x + rect.width) * 100;\n const b = (rect.y + rect.height) * 100;\n if (circle) {\n return `ellipse(${(rect.width / 2) * 100}% ${(rect.height / 2) * 100}% at ${(rect.x + rect.width / 2) * 100}% ${(rect.y + rect.height / 2) * 100}%)`;\n }\n // A polygon at both ends, so the clip animates; `inset(0)` would not\n // interpolate with it and the reveal would snap.\n return `polygon(${l}% ${t}%, ${r}% ${t}%, ${r}% ${b}%, ${l}% ${b}%)`;\n}\n\nconst FULL_CLIP = 'polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%)';\n\nfunction unsettle(ctx: UiToolContext): void {\n if (settle.timer !== null) clearTimeout(settle.timer);\n settle.timer = null;\n if (settle.at !== null) {\n settle.at = null;\n ctx.clipPreview(FULL_CLIP);\n ctx.refresh();\n }\n}\n\nfunction scheduleSettle(ctx: UiToolContext): void {\n if (settle.timer !== null) clearTimeout(settle.timer);\n settle.at = null;\n settle.touched = true;\n settle.timer = setTimeout(() => {\n settle.timer = null;\n settle.at = Date.now();\n // Fresh from the session: `ctx.document` is the snapshot from the render\n // that scheduled this, which is the state from before the commit.\n const doc = (ctx.session.getDocument() as unknown as { crop: CropDoc }).crop;\n const circle =\n (ctx.options<CropOptions>('crop') ?? CROP_DEFAULT_OPTIONS).shape === 'circle' ||\n doc.mask === 'circle';\n ctx.clipPreview(clipFor(doc.rect, circle));\n ctx.refresh();\n }, SETTLE_MS);\n}\n\nexport const cropTool: UiTool = {\n id: 'crop',\n icon: icons.crop,\n label: 'tool.crop',\n activate: (ctx) => {\n unsettle(ctx);\n markRect(ctx);\n settle.touched = false;\n ctx.clipPreview(FULL_CLIP);\n ctx.session.setPreviewTransform(showFullRect);\n },\n deactivate: (ctx) => {\n drag.live = null;\n drawn = null;\n settle.rect = null;\n unsettle(ctx);\n // The next preview is the real crop; nothing left to clip.\n ctx.clipPreview(null);\n // The image becomes the crop now, so ask for it to be seen happening — but\n // only if this visit changed it. Crop is often the tool an editor opens on,\n // and leaving one the user never touched should move nothing.\n if (settle.touched) ctx.animateNextView();\n settle.touched = false;\n ctx.session.setPreviewTransform(null);\n },\n panel: (ctx: UiToolContext) => {\n const doc = (ctx.document as unknown as { crop: CropDoc }).crop;\n // The slider straightens within ±45°; the quarter turns stay with the\n // ±90° buttons, so the dial's whole width is one quarter of a turn.\n const { quarters, fine } = splitDegrees((doc.rotation * 180) / Math.PI, shownFine);\n shownFine = fine;\n // A rotation, a flip or an aspect ratio is a change like a drag is: it\n // leaves the settled view first, so the surroundings are there to see what\n // swings into the frame, and settles into the result the same way after.\n // Nothing else opens the view for a panel change — the render-time guard\n // compares rectangles, and markRect below keeps this change from ever\n // looking like one; a rotation moves the content inside an unchanged\n // rectangle regardless.\n const set = (patch: Record<string, unknown>) => {\n unsettle(ctx);\n if ('rotation' in patch) drawn = { rect: doc.rect, geometry: ctx.stage.geometry };\n ctx.dispatch({ type: 'crop.set', id: opId(), ...patch });\n markRect(ctx);\n scheduleSettle(ctx);\n };\n const src = ctx.state.source;\n const original = src ? src.width / src.height : 1;\n const options = ctx.options<CropOptions>('crop') ?? CROP_DEFAULT_OPTIONS;\n const circle = options.shape === 'circle';\n // In circle mode a reset restores a full round crop instead of dropping the mask.\n const reset = () => {\n unsettle(ctx);\n // Marked after the dispatch below, so the identity crop this writes is\n // not mistaken for one that arrived from an undo.\n const dispatched = ctx.dispatch(\n circle\n ? {\n type: 'crop.set',\n id: opId(),\n rotation: 0,\n flipX: false,\n flipY: false,\n rect: { x: 0, y: 0, width: 1, height: 1 },\n aspect: 1,\n mask: 'circle',\n }\n : { type: 'crop.reset', id: opId() },\n );\n markRect(ctx);\n return dispatched;\n };\n const aspects: { key: string; value: number | null }[] = options.aspects.map((a) => ({\n key: a.label,\n value: a.value === ORIGINAL_ASPECT ? original : a.value,\n }));\n const aspectSelect = html`<select\n data-field=\"aspect\"\n aria-label=${ctx.t('crop.aspect')}\n @change=${(e: Event) => {\n const v = (e.target as HTMLSelectElement).value;\n const aspect = v === '' ? null : Number(v);\n set({ aspect, ...(aspect === null ? {} : { rect: fitAspect(doc.rect, aspect, ctx) }) });\n }}\n >\n ${aspects.map(\n (a) =>\n html`<option value=${a.value === null ? '' : String(a.value)} ?selected=${a.value === doc.aspect || (a.value !== null && doc.aspect !== null && Math.abs(a.value - doc.aspect) < 1e-6)}>\n ${a.key.startsWith('crop.') ? ctx.t(a.key) : a.key}\n </option>`,\n )}\n </select>`;\n return html`\n ${\n options.rotation\n ? html`<sealpixel-slider\n data-param=\"rotation\"\n .label=${ctx.t('crop.rotation')}\n .value=${Number(fine.toFixed(2))}\n .min=${-45}\n .max=${45}\n .step=${options.rotationStep}\n .format=${(v: number) => `${v.toFixed(1)}°`}\n @slide=${(e: CustomEvent<number>) => {\n // The first movement opens the surround; set() only runs on commit,\n // which is after the gesture, and the aiming is what needs the view.\n unsettle(ctx);\n ctx.hint({ rotate: ((e.detail - fine) * Math.PI) / 180 });\n }}\n @commit=${(e: CustomEvent<number>) => {\n shownFine = e.detail;\n const rotation = ((quarters * 90 + e.detail) * Math.PI) / 180;\n // The frame stays where it is and keeps its size; the image turns\n // behind it. See crop-rotation.ts for why the rect has to move.\n set({\n rotation,\n rect: src\n ? straighten(doc.rect, doc.rotation, rotation, src, options.outside === 'forbid')\n : doc.rect,\n });\n // The hint stays until the render with this rotation lands and the\n // stage drops it; clearing it here shows the old picture for the\n // frames in between. A refused commit renders nothing, so it clears.\n const now = (ctx.session.getDocument() as unknown as { crop: CropDoc }).crop.rotation;\n if (Math.abs(now - rotation) > 1e-9) ctx.hint(null);\n }}\n ></sealpixel-slider>`\n : nothing\n }\n <div class=\"row compact choice\">\n <div class=\"group\">\n ${\n options.rotation\n ? html`<sealpixel-button data-action=\"rotate-left\" .label=${'-90°'} @click=${() => set({ rotation: doc.rotation - Math.PI / 2, rect: quarterTurn(doc.rect, -1) })}>⟲ 90°</sealpixel-button>\n <sealpixel-button data-action=\"rotate-right\" .label=${'+90°'} @click=${() => set({ rotation: doc.rotation + Math.PI / 2, rect: quarterTurn(doc.rect, 1) })}>⟳ 90°</sealpixel-button>`\n : nothing\n }\n ${\n options.flip\n ? html`<sealpixel-button data-action=\"flip-x\" ?pressed=${doc.flipX} .label=${ctx.t('crop.flipX')} @click=${() => set({ flipX: !doc.flipX })}>⇋</sealpixel-button>\n <sealpixel-button data-action=\"flip-y\" ?pressed=${doc.flipY} .label=${ctx.t('crop.flipY')} @click=${() => set({ flipY: !doc.flipY })}>⇅</sealpixel-button>`\n : nothing\n }\n </div>\n ${circle ? nothing : aspectSelect}\n ${\n options.reset\n ? html`<sealpixel-button variant=\"ghost\" data-action=\"reset\" @click=${reset}>\n ${ctx.t('crop.reset')}\n </sealpixel-button>`\n : nothing\n }\n </div>\n `;\n },\n overlay: (ctx: UiToolContext) => {\n const doc = (ctx.document as unknown as { crop: CropDoc }).crop;\n // An undo, a redo or a time travel changes the crop without passing through\n // this tool, and the settled view does not follow on its own: the stage\n // would keep the clip of the crop that was just undone, with the gizmo\n // still faded out, so undo would look like it had done nothing at all.\n // Back to adjusting, which is what the user is doing after an undo.\n if (settle.rect && !drag.live && !sameRect(settle.rect, doc.rect)) {\n settle.rect = doc.rect;\n unsettle(ctx);\n }\n const { width: W, height: H, zoom } = ctx.stage;\n if (drawn && drawn.geometry !== ctx.stage.geometry) drawn = null;\n if (!W || !H) return svg``;\n const r = drag.live ?? drawn?.rect ?? doc.rect;\n const x = r.x * W;\n const y = r.y * H;\n const w = r.width * W;\n const h = r.height * H;\n const hr = 7 / zoom;\n const sw = 1.5 / zoom;\n const handles: { id: Handle; cx: number; cy: number }[] = [\n { id: 'nw', cx: x, cy: y },\n { id: 'n', cx: x + w / 2, cy: y },\n { id: 'ne', cx: x + w, cy: y },\n { id: 'e', cx: x + w, cy: y + h / 2 },\n { id: 'se', cx: x + w, cy: y + h },\n { id: 's', cx: x + w / 2, cy: y + h },\n { id: 'sw', cx: x, cy: y + h },\n { id: 'w', cx: x, cy: y + h / 2 },\n ];\n const start = (handle: Handle) => (e: PointerEvent) => {\n e.stopPropagation();\n e.preventDefault();\n unsettle(ctx);\n drawn = null;\n const p = ctx.stage.toImage(e.clientX, e.clientY);\n drag.handle = handle;\n drag.start = doc.rect;\n drag.sx = p.x / W;\n drag.sy = p.y / H;\n drag.live = doc.rect;\n const options = ctx.options<CropOptions>('crop') ?? CROP_DEFAULT_OPTIONS;\n const src = ctx.state.source;\n const move = (ev: PointerEvent) => {\n const q = ctx.stage.toImage(ev.clientX, ev.clientY);\n const apply = (dx: number, dy: number) =>\n applyDrag(drag.start, handle, dx, dy, doc.aspect, W / H);\n const dx = q.x / W - drag.sx;\n const dy = q.y / H - drag.sy;\n // At an angle the box is larger than the image; `forbid` keeps the\n // frame on the picture.\n drag.live =\n options.outside === 'forbid' && doc.rotation !== 0 && src\n ? constrainDrag(apply, dx, dy, doc.rotation, src)\n : apply(dx, dy);\n ctx.refresh();\n };\n const up = () => {\n window.removeEventListener('pointermove', move);\n window.removeEventListener('pointerup', up);\n window.removeEventListener('pointercancel', up);\n const final = drag.live;\n drag.live = null;\n if (final && !sameRect(final, doc.rect))\n ctx.dispatch({ type: 'crop.set', id: opId(), rect: final });\n markRect(ctx);\n scheduleSettle(ctx);\n ctx.refresh();\n };\n window.addEventListener('pointermove', move);\n window.addEventListener('pointerup', up);\n window.addEventListener('pointercancel', up);\n };\n const circleShape =\n (ctx.options<CropOptions>('crop') ?? CROP_DEFAULT_OPTIONS).shape === 'circle' ||\n doc.mask === 'circle';\n const cx = x + w / 2;\n const cy = y + h / 2;\n // Ellipse hole as two arcs so the evenodd path can carve it out.\n const hole = circleShape\n ? `M${cx - w / 2} ${cy}A${w / 2} ${h / 2} 0 1 0 ${cx + w / 2} ${cy}A${w / 2} ${h / 2} 0 1 0 ${cx - w / 2} ${cy}Z`\n : `M${x} ${y}H${x + w}V${y + h}H${x}Z`;\n // Settled: the preview is clipped to the crop and the gizmo goes, so what is\n // left on the stage is the picture that comes out, with the stage's own\n // backdrop around it rather than a painted stand-in. The scrim is only the\n // dim for adjusting and fades out with the rest.\n //\n // The transitions are inline, and the reduced-motion rule in the shared\n // base still overrides them, which leaves the same state change unanimated.\n const shown = settle.at !== null;\n const ease = 'var(--sealpixel-duration-slow, 320ms) var(--sealpixel-ease-out, ease-out)';\n const gizmo = `transition:opacity ${ease};opacity:${shown ? 0 : 1}`;\n return svg`\n <path\n data-crop-scrim\n d=${`M0 0H${W}V${H}H0Z ${hole}`}\n fill=\"var(--sealpixel-color-bg, #000)\"\n fill-opacity=${shown ? 0 : 0.5}\n fill-rule=\"evenodd\"\n style=${`transition:fill-opacity ${ease}`}\n pointer-events=\"none\"\n />\n ${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}\n <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')} />\n <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\" />\n ${handles.map(\n (hd) =>\n 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)} />`,\n )}\n `;\n },\n};\n\nfunction cursorFor(h: Handle): string {\n return {\n nw: 'nwse-resize',\n se: 'nwse-resize',\n ne: 'nesw-resize',\n sw: 'nesw-resize',\n n: 'ns-resize',\n s: 'ns-resize',\n e: 'ew-resize',\n w: 'ew-resize',\n move: 'move',\n }[h];\n}\n\nfunction sameRect(a: Rect, b: Rect): boolean {\n return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;\n}\n\nconst MIN = 0.02;\n\n/**\n * Applies a normalised drag delta to `start`. `aspect` is width/height in\n * output pixels; `stageAspect` converts it into normalised units.\n */\nexport function applyDrag(\n start: Rect,\n handle: Handle,\n dx: number,\n dy: number,\n aspect: number | null,\n stageAspect: number,\n): Rect {\n if (handle === 'move') {\n return {\n ...start,\n x: clamp(start.x + dx, 0, 1 - start.width),\n y: clamp(start.y + dy, 0, 1 - start.height),\n };\n }\n let x0 = start.x;\n let y0 = start.y;\n let x1 = start.x + start.width;\n let y1 = start.y + start.height;\n if (handle.includes('w')) x0 = clamp(x0 + dx, 0, x1 - MIN);\n if (handle.includes('e')) x1 = clamp(x1 + dx, x0 + MIN, 1);\n if (handle.includes('n')) y0 = clamp(y0 + dy, 0, y1 - MIN);\n if (handle.includes('s')) y1 = clamp(y1 + dy, y0 + MIN, 1);\n let rect = { x: x0, y: y0, width: x1 - x0, height: y1 - y0 };\n if (aspect !== null) {\n // normalised height for a given normalised width under this aspect\n const ratio = aspect / stageAspect; // width_n / height_n\n const anchorRight = handle.includes('w');\n const anchorBottom = handle.includes('n');\n const horizontal = handle === 'e' || handle === 'w';\n let w = rect.width;\n let h = rect.height;\n if (horizontal || (!['n', 's'].includes(handle) && Math.abs(dx) >= Math.abs(dy))) h = w / ratio;\n else w = h * ratio;\n // keep inside bounds\n if (w > 1) {\n w = 1;\n h = w / ratio;\n }\n if (h > 1) {\n h = 1;\n w = h * ratio;\n }\n const nx = anchorRight ? x1 - w : x0;\n const ny = anchorBottom ? y1 - h : y0;\n rect = { x: clamp(nx, 0, 1 - w), y: clamp(ny, 0, 1 - h), width: w, height: h };\n }\n return rect;\n}\n\nfunction fitAspect(rect: Rect, aspect: number, ctx: UiToolContext): Rect {\n const { width: W, height: H } = ctx.stage;\n const stageAspect = W && H ? W / H : 1;\n return applyDrag({ ...rect }, 'se', 0, 0, aspect, stageAspect);\n}\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":"crop.js","sourceRoot":"","sources":["../../src/tools/crop.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAoB,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;A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,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,OAAO,SAAS,CAAC,EAAE,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AACjE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAAyC;IACrE,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC;IAClC,MAAM,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AACpE,CAAC;AAED,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, Geometry, Rect } from '@sealpixel/core';\nimport { CROP_DEFAULT_OPTIONS, type CropOptions, ORIGINAL_ASPECT } from '@sealpixel/plugins';\nimport { html, nothing, svg } from 'lit';\nimport { icons } from '../icons.js';\nimport type { UiTool, UiToolContext } from '../tool.js';\nimport { constrainDrag, quarterTurn, splitDegrees, straighten } from './crop-rotation.js';\nimport { opId } from './finetune.js';\nimport { toolState } from './instance-state.js';\nimport { announce, elementKeys } from './keys.js';\n\ninterface CropDoc {\n mask?: 'none' | 'circle' | undefined;\n rotation: number;\n flipX: boolean;\n flipY: boolean;\n rect: Rect;\n aspect: number | null;\n}\n\ntype Handle = 'nw' | 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'move';\n\n/**\n * While the crop tool is active the preview shows the whole rotated image\n * (rect forced to full, resize cleared), and the gizmo draws the crop\n * rectangle on top. A resize with `cover` or `fill` would cut or stretch that\n * image, and the gizmo would map onto a box that is not the one it edits.\n */\nfunction showFullRect(log: EditLog): EditLog {\n return {\n ...log,\n ops: [\n ...log.ops,\n {\n type: 'crop.set',\n id: '__sealpixel_preview_rect__',\n rect: { x: 0, y: 0, width: 1, height: 1 },\n // The gizmo draws the round mask itself; the preview shows the unmasked pixels.\n mask: 'none',\n },\n { type: 'resize.clear', id: '__sealpixel_preview_resize__' },\n ],\n };\n}\n\n/**\n * How long the pointer has to be still after a change before the stage shows\n * the result. Long enough never to fire between two drags, short enough that\n * nobody waits for it.\n */\nconst SETTLE_MS = 500;\n\n/** Transient tool state, one per editor. */\ninterface CropState {\n /** A handle drag; `keys` when the keys on a focused handle drive it. */\n drag: { handle: Handle; start: Rect; sx: number; sy: number; live: Rect | null; keys?: boolean };\n /**\n * The straightening the rotation slider showed last, in degrees. It breaks\n * the tie at exactly ±45°, where the split of the document's rotation into\n * quarter turns and straightening is not unique (see `splitDegrees`).\n */\n shownFine: number;\n /**\n * The crop is written to the log the moment a handle is released, but the\n * stage keeps showing the whole image, because a corner cannot be pulled\n * outwards through an edge that is off screen. Letting go therefore looks\n * exactly like doing nothing. After the pointer rests, the scrim closes over\n * what the crop removes and the gizmo fades, so what is left on the stage is\n * the picture that will come out. Touching the gizmo brings it all back.\n */\n settle: {\n at: number | null;\n timer: ReturnType<typeof setTimeout> | null;\n /** Whether this visit to the tool actually changed the crop. */\n touched: boolean;\n /**\n * The crop this tool last wrote to the log, or read on activation. The\n * settled view — a clip on the stage and a gizmo faded out — lives here and\n * not in the log, so a crop that changes without passing through this tool\n * has to be noticed. Null while the tool is not active.\n */\n rect: Rect | null;\n };\n /**\n * Between a change of angle and the preview that shows it, the gizmo keeps\n * drawing the rect it drew on the preview still on the stage. The new rect is\n * normalised to another bounding box; drawn on the old preview it would show\n * at the wrong size for those frames and jump back when the render lands.\n * Cleared when a preview with another geometry arrives.\n */\n drawn: { rect: Rect; geometry: Geometry | null } | null;\n}\n\nconst createCropState = (): CropState => ({\n drag: {\n handle: 'move',\n start: { x: 0, y: 0, width: 1, height: 1 },\n sx: 0,\n sy: 0,\n live: null,\n },\n shownFine: 0,\n settle: {\n at: null,\n timer: null,\n touched: false,\n rect: null,\n },\n drawn: null,\n});\n\n/** Records the crop now in the log as the one this tool is showing. */\nfunction markRect(ctx: UiToolContext): void {\n toolState(ctx, createCropState).settle.rect = (\n ctx.session.getDocument() as unknown as { crop: CropDoc }\n ).crop.rect;\n}\n\n/** The preview clipped to the crop, in percentages of the canvas box. */\nfunction clipFor(rect: Rect, circle: boolean): string {\n const l = rect.x * 100;\n const t = rect.y * 100;\n const r = (rect.x + rect.width) * 100;\n const b = (rect.y + rect.height) * 100;\n if (circle) {\n return `ellipse(${(rect.width / 2) * 100}% ${(rect.height / 2) * 100}% at ${(rect.x + rect.width / 2) * 100}% ${(rect.y + rect.height / 2) * 100}%)`;\n }\n // A polygon at both ends, so the clip animates; `inset(0)` would not\n // interpolate with it and the reveal would snap.\n return `polygon(${l}% ${t}%, ${r}% ${t}%, ${r}% ${b}%, ${l}% ${b}%)`;\n}\n\nconst FULL_CLIP = 'polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%)';\n\nfunction unsettle(ctx: UiToolContext): void {\n const { settle } = toolState(ctx, createCropState);\n if (settle.timer !== null) clearTimeout(settle.timer);\n settle.timer = null;\n if (settle.at !== null) {\n settle.at = null;\n ctx.clipPreview(FULL_CLIP);\n ctx.refresh();\n }\n}\n\nfunction scheduleSettle(ctx: UiToolContext): void {\n const { settle } = toolState(ctx, createCropState);\n if (settle.timer !== null) clearTimeout(settle.timer);\n settle.at = null;\n settle.touched = true;\n settle.timer = setTimeout(() => {\n settle.timer = null;\n settle.at = Date.now();\n // Fresh from the session: `ctx.document` is the snapshot from the render\n // that scheduled this, which is the state from before the commit.\n const doc = (ctx.session.getDocument() as unknown as { crop: CropDoc }).crop;\n const circle =\n (ctx.options<CropOptions>('crop') ?? CROP_DEFAULT_OPTIONS).shape === 'circle' ||\n doc.mask === 'circle';\n ctx.clipPreview(clipFor(doc.rect, circle));\n ctx.refresh();\n }, SETTLE_MS);\n}\n\nexport const cropTool: UiTool = {\n id: 'crop',\n icon: icons.crop,\n label: 'tool.crop',\n activate: (ctx) => {\n const { settle } = toolState(ctx, createCropState);\n unsettle(ctx);\n markRect(ctx);\n settle.touched = false;\n ctx.clipPreview(FULL_CLIP);\n ctx.session.setPreviewTransform(showFullRect);\n },\n deactivate: (ctx) => {\n const state = toolState(ctx, createCropState);\n const { drag, settle } = state;\n drag.live = null;\n state.drawn = null;\n settle.rect = null;\n unsettle(ctx);\n // The next preview is the real crop; nothing left to clip.\n ctx.clipPreview(null);\n // The image becomes the crop now, so ask for it to be seen happening — but\n // only if this visit changed it. Crop is often the tool an editor opens on,\n // and leaving one the user never touched should move nothing.\n if (settle.touched) ctx.animateNextView();\n settle.touched = false;\n ctx.session.setPreviewTransform(null);\n },\n panel: (ctx: UiToolContext) => {\n const state = toolState(ctx, createCropState);\n const doc = (ctx.document as unknown as { crop: CropDoc }).crop;\n // The slider straightens within ±45°; the quarter turns stay with the\n // ±90° buttons, so the dial's whole width is one quarter of a turn.\n const { quarters, fine } = splitDegrees((doc.rotation * 180) / Math.PI, state.shownFine);\n state.shownFine = fine;\n // A rotation, a flip or an aspect ratio is a change like a drag is: it\n // leaves the settled view first, so the surroundings are there to see what\n // swings into the frame, and settles into the result the same way after.\n // Nothing else opens the view for a panel change — the render-time guard\n // compares rectangles, and markRect below keeps this change from ever\n // looking like one; a rotation moves the content inside an unchanged\n // rectangle regardless.\n const set = (patch: Record<string, unknown>) => {\n unsettle(ctx);\n if ('rotation' in patch) state.drawn = { rect: doc.rect, geometry: ctx.stage.geometry };\n ctx.dispatch({ type: 'crop.set', id: opId(), ...patch });\n markRect(ctx);\n scheduleSettle(ctx);\n };\n const src = ctx.state.source;\n const original = src ? src.width / src.height : 1;\n const options = ctx.options<CropOptions>('crop') ?? CROP_DEFAULT_OPTIONS;\n const circle = options.shape === 'circle';\n // In circle mode a reset restores a full round crop instead of dropping the mask.\n const reset = () => {\n unsettle(ctx);\n // Marked after the dispatch below, so the identity crop this writes is\n // not mistaken for one that arrived from an undo.\n const dispatched = ctx.dispatch(\n circle\n ? {\n type: 'crop.set',\n id: opId(),\n rotation: 0,\n flipX: false,\n flipY: false,\n rect: src ? centredSquare(src) : { x: 0, y: 0, width: 1, height: 1 },\n aspect: 1,\n mask: 'circle',\n }\n : { type: 'crop.reset', id: opId() },\n );\n markRect(ctx);\n return dispatched;\n };\n const aspects: { key: string; value: number | null }[] = options.aspects.map((a) => ({\n key: a.label,\n value: a.value === ORIGINAL_ASPECT ? original : a.value,\n }));\n const aspectSelect = html`<select\n data-field=\"aspect\"\n aria-label=${ctx.t('crop.aspect')}\n @change=${(e: Event) => {\n const v = (e.target as HTMLSelectElement).value;\n const aspect = v === '' ? null : Number(v);\n set({ aspect, ...(aspect === null ? {} : { rect: fitAspect(doc.rect, aspect, ctx) }) });\n }}\n >\n ${aspects.map(\n (a) =>\n html`<option value=${a.value === null ? '' : String(a.value)} ?selected=${a.value === doc.aspect || (a.value !== null && doc.aspect !== null && Math.abs(a.value - doc.aspect) < 1e-6)}>\n ${a.key.startsWith('crop.') ? ctx.t(a.key) : a.key}\n </option>`,\n )}\n </select>`;\n return html`\n ${\n options.rotation\n ? html`<sealpixel-slider\n data-param=\"rotation\"\n .label=${ctx.t('crop.rotation')}\n .value=${Number(fine.toFixed(2))}\n .min=${-45}\n .max=${45}\n .step=${options.rotationStep}\n .format=${(v: number) => `${v.toFixed(1)}°`}\n @slide=${(e: CustomEvent<number>) => {\n // The first movement opens the surround; set() only runs on commit,\n // which is after the gesture, and the aiming is what needs the view.\n unsettle(ctx);\n ctx.hint({ rotate: ((e.detail - fine) * Math.PI) / 180 });\n }}\n @commit=${(e: CustomEvent<number>) => {\n state.shownFine = e.detail;\n const rotation = ((quarters * 90 + e.detail) * Math.PI) / 180;\n // The frame stays where it is and keeps its size; the image turns\n // behind it. See crop-rotation.ts for why the rect has to move.\n set({\n rotation,\n rect: src\n ? straighten(doc.rect, doc.rotation, rotation, src, options.outside === 'forbid')\n : doc.rect,\n });\n // The hint stays until the render with this rotation lands and the\n // stage drops it; clearing it here shows the old picture for the\n // frames in between. A refused commit renders nothing, so it clears.\n const now = (ctx.session.getDocument() as unknown as { crop: CropDoc }).crop.rotation;\n if (Math.abs(now - rotation) > 1e-9) ctx.hint(null);\n }}\n ></sealpixel-slider>`\n : nothing\n }\n <div class=\"row compact choice\">\n <div class=\"group\">\n ${\n options.rotation\n ? html`<sealpixel-button data-action=\"rotate-left\" .label=${'-90°'} @click=${() => set({ rotation: doc.rotation - Math.PI / 2, rect: quarterTurn(doc.rect, -1) })}>⟲ 90°</sealpixel-button>\n <sealpixel-button data-action=\"rotate-right\" .label=${'+90°'} @click=${() => set({ rotation: doc.rotation + Math.PI / 2, rect: quarterTurn(doc.rect, 1) })}>⟳ 90°</sealpixel-button>`\n : nothing\n }\n ${\n options.flip\n ? html`<sealpixel-button data-action=\"flip-x\" ?pressed=${doc.flipX} .label=${ctx.t('crop.flipX')} @click=${() => set({ flipX: !doc.flipX })}>⇋</sealpixel-button>\n <sealpixel-button data-action=\"flip-y\" ?pressed=${doc.flipY} .label=${ctx.t('crop.flipY')} @click=${() => set({ flipY: !doc.flipY })}>⇅</sealpixel-button>`\n : nothing\n }\n </div>\n ${circle ? nothing : aspectSelect}\n ${\n options.reset\n ? html`<sealpixel-button variant=\"ghost\" data-action=\"reset\" @click=${reset}>\n ${ctx.t('crop.reset')}\n </sealpixel-button>`\n : nothing\n }\n </div>\n `;\n },\n overlay: (ctx: UiToolContext) => {\n const state = toolState(ctx, createCropState);\n const { drag, settle } = state;\n const doc = (ctx.document as unknown as { crop: CropDoc }).crop;\n // An undo, a redo or a time travel changes the crop without passing through\n // this tool, and the settled view does not follow on its own: the stage\n // would keep the clip of the crop that was just undone, with the gizmo\n // still faded out, so undo would look like it had done nothing at all.\n // Back to adjusting, which is what the user is doing after an undo.\n if (settle.rect && !drag.live && !sameRect(settle.rect, doc.rect)) {\n settle.rect = doc.rect;\n unsettle(ctx);\n }\n const { width: W, height: H, zoom } = ctx.stage;\n if (state.drawn && state.drawn.geometry !== ctx.stage.geometry) state.drawn = null;\n if (!W || !H) return svg``;\n const r = drag.live ?? state.drawn?.rect ?? doc.rect;\n const x = r.x * W;\n const y = r.y * H;\n const w = r.width * W;\n const h = r.height * H;\n const hr = 7 / zoom;\n const sw = 1.5 / zoom;\n const handles: { id: Handle; cx: number; cy: number }[] = [\n { id: 'nw', cx: x, cy: y },\n { id: 'n', cx: x + w / 2, cy: y },\n { id: 'ne', cx: x + w, cy: y },\n { id: 'e', cx: x + w, cy: y + h / 2 },\n { id: 'se', cx: x + w, cy: y + h },\n { id: 's', cx: x + w / 2, cy: y + h },\n { id: 'sw', cx: x, cy: y + h },\n { id: 'w', cx: x, cy: y + h / 2 },\n ];\n const start = (handle: Handle) => (e: PointerEvent) => {\n e.stopPropagation();\n e.preventDefault();\n unsettle(ctx);\n state.drawn = null;\n const p = ctx.stage.toImage(e.clientX, e.clientY);\n drag.handle = handle;\n drag.start = doc.rect;\n drag.sx = p.x / W;\n drag.sy = p.y / H;\n drag.live = doc.rect;\n drag.keys = false;\n const options = ctx.options<CropOptions>('crop') ?? CROP_DEFAULT_OPTIONS;\n const src = ctx.state.source;\n const move = (ev: PointerEvent) => {\n const q = ctx.stage.toImage(ev.clientX, ev.clientY);\n const apply = (dx: number, dy: number) =>\n applyDrag(drag.start, handle, dx, dy, doc.aspect, W / H);\n const dx = q.x / W - drag.sx;\n const dy = q.y / H - drag.sy;\n // At an angle the box is larger than the image; `forbid` keeps the\n // frame on the picture.\n drag.live =\n options.outside === 'forbid' && doc.rotation !== 0 && src\n ? constrainDrag(apply, dx, dy, doc.rotation, src)\n : apply(dx, dy);\n ctx.refresh();\n };\n const up = () => {\n window.removeEventListener('pointermove', move);\n window.removeEventListener('pointerup', up);\n window.removeEventListener('pointercancel', up);\n const final = drag.live;\n drag.live = null;\n if (final && !sameRect(final, doc.rect))\n ctx.dispatch({ type: 'crop.set', id: opId(), rect: final });\n markRect(ctx);\n scheduleSettle(ctx);\n ctx.refresh();\n };\n window.addEventListener('pointermove', move);\n window.addEventListener('pointerup', up);\n window.addEventListener('pointercancel', up);\n };\n // The keys on a focused handle or on the frame drive the same live rect as\n // a pointer drag, and the release writes one crop.set. The view does not\n // settle afterwards: the focused handle would fade out under the focus.\n const keysFor = (handle: Handle) =>\n elementKeys(ctx.stage, {\n select: () => unsettle(ctx),\n move: (dx, dy) => {\n if (drag.live && !drag.keys) return;\n unsettle(ctx);\n state.drawn = null;\n const base = drag.live ?? doc.rect;\n const options = ctx.options<CropOptions>('crop') ?? CROP_DEFAULT_OPTIONS;\n const src = ctx.state.source;\n const apply = (ddx: number, ddy: number) =>\n applyDrag(base, handle, ddx, ddy, doc.aspect, W / H);\n drag.keys = true;\n drag.live =\n options.outside === 'forbid' && doc.rotation !== 0 && src\n ? constrainDrag(apply, dx, dy, doc.rotation, src)\n : apply(dx, dy);\n ctx.refresh();\n },\n commit: (e) => {\n if (!drag.keys) return;\n const final = drag.live;\n drag.live = null;\n drag.keys = false;\n if (final && !sameRect(final, doc.rect)) {\n ctx.dispatch({ type: 'crop.set', id: opId(), rect: final });\n settle.touched = true;\n const size = cropSize(final, doc.rotation, ctx.state.source);\n if (size) announce(e.target as Element, ctx.t('stage.size', size));\n }\n markRect(ctx);\n ctx.refresh();\n },\n remove: () => {},\n escape: () => {\n if (!drag.keys) return false;\n drag.live = null;\n drag.keys = false;\n ctx.refresh();\n return true;\n },\n });\n const frameKeys = keysFor('move');\n const circleShape =\n (ctx.options<CropOptions>('crop') ?? CROP_DEFAULT_OPTIONS).shape === 'circle' ||\n doc.mask === 'circle';\n const cx = x + w / 2;\n const cy = y + h / 2;\n // Ellipse hole as two arcs so the evenodd path can carve it out.\n const hole = circleShape\n ? `M${cx - w / 2} ${cy}A${w / 2} ${h / 2} 0 1 0 ${cx + w / 2} ${cy}A${w / 2} ${h / 2} 0 1 0 ${cx - w / 2} ${cy}Z`\n : `M${x} ${y}H${x + w}V${y + h}H${x}Z`;\n // Settled: the preview is clipped to the crop and the gizmo goes, so what is\n // left on the stage is the picture that comes out, with the stage's own\n // backdrop around it rather than a painted stand-in. The scrim is only the\n // dim for adjusting and fades out with the rest.\n //\n // The transitions are inline, and the reduced-motion rule in the shared\n // base still overrides them, which leaves the same state change unanimated.\n const shown = settle.at !== null;\n const ease = 'var(--sealpixel-duration-slow, 320ms) var(--sealpixel-ease-out, ease-out)';\n const gizmo = `transition:opacity ${ease};opacity:${shown ? 0 : 1}`;\n return svg`\n <path\n data-crop-scrim\n d=${`M0 0H${W}V${H}H0Z ${hole}`}\n fill=\"var(--sealpixel-color-bg, #000)\"\n fill-opacity=${shown ? 0 : 0.5}\n fill-rule=\"evenodd\"\n style=${`transition:fill-opacity ${ease}`}\n pointer-events=\"none\"\n />\n ${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}\n <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')} />\n <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\" />\n ${handles.map((hd) => {\n const k = keysFor(hd.id);\n 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)} />`;\n })}\n `;\n },\n};\n\nfunction cursorFor(h: Handle): string {\n return {\n nw: 'nwse-resize',\n se: 'nwse-resize',\n ne: 'nesw-resize',\n sw: 'nesw-resize',\n n: 'ns-resize',\n s: 'ns-resize',\n e: 'ew-resize',\n w: 'ew-resize',\n move: 'move',\n }[h];\n}\n\n/**\n * The output size of a crop rect in source pixels: the rect is normalised\n * to the box around the turned source, as in `crop-mask.ts`.\n */\nfunction cropSize(\n rect: Rect,\n rotation: number,\n src: { width: number; height: number } | null | undefined,\n): { width: number; height: number } | null {\n if (!src) return null;\n const sin = Math.abs(Math.sin(rotation));\n const cos = Math.abs(Math.cos(rotation));\n return {\n width: Math.round(rect.width * (src.width * cos + src.height * sin)),\n height: Math.round(rect.height * (src.width * sin + src.height * cos)),\n };\n}\n\nfunction sameRect(a: Rect, b: Rect): boolean {\n return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;\n}\n\nconst MIN = 0.02;\n\n/**\n * Applies a normalised drag delta to `start`. `aspect` is width/height in\n * output pixels; `stageAspect` converts it into normalised units.\n */\nexport function applyDrag(\n start: Rect,\n handle: Handle,\n dx: number,\n dy: number,\n aspect: number | null,\n stageAspect: number,\n): Rect {\n if (handle === 'move') {\n return {\n ...start,\n x: clamp(start.x + dx, 0, 1 - start.width),\n y: clamp(start.y + dy, 0, 1 - start.height),\n };\n }\n let x0 = start.x;\n let y0 = start.y;\n let x1 = start.x + start.width;\n let y1 = start.y + start.height;\n if (handle.includes('w')) x0 = clamp(x0 + dx, 0, x1 - MIN);\n if (handle.includes('e')) x1 = clamp(x1 + dx, x0 + MIN, 1);\n if (handle.includes('n')) y0 = clamp(y0 + dy, 0, y1 - MIN);\n if (handle.includes('s')) y1 = clamp(y1 + dy, y0 + MIN, 1);\n let rect = { x: x0, y: y0, width: x1 - x0, height: y1 - y0 };\n if (aspect !== null) {\n // normalised height for a given normalised width under this aspect\n const ratio = aspect / stageAspect; // width_n / height_n\n const anchorRight = handle.includes('w');\n const anchorBottom = handle.includes('n');\n const horizontal = handle === 'e' || handle === 'w';\n let w = rect.width;\n let h = rect.height;\n if (horizontal || (!['n', 's'].includes(handle) && Math.abs(dx) >= Math.abs(dy))) h = w / ratio;\n else w = h * ratio;\n // keep inside bounds\n if (w > 1) {\n w = 1;\n h = w / ratio;\n }\n if (h > 1) {\n h = 1;\n w = h * ratio;\n }\n const nx = anchorRight ? x1 - w : x0;\n const ny = anchorBottom ? y1 - h : y0;\n rect = { x: clamp(nx, 0, 1 - w), y: clamp(ny, 0, 1 - h), width: w, height: h };\n }\n return rect;\n}\n\nfunction fitAspect(rect: Rect, aspect: number, ctx: UiToolContext): Rect {\n const { width: W, height: H } = ctx.stage;\n const stageAspect = W && H ? W / H : 1;\n return applyDrag({ ...rect }, 'se', 0, 0, aspect, stageAspect);\n}\n\n/**\n * The largest centred square in source pixels. The circle reset sets the\n * rotation to 0, so the rect is normalised to the source itself. The crop\n * plugin's initial op writes the same rect.\n */\nexport function centredSquare(source: { width: number; height: number }): Rect {\n const side = Math.min(source.width, source.height);\n const width = side / source.width;\n const height = side / source.height;\n return { x: (1 - width) / 2, y: (1 - height) / 2, width, height };\n}\n\nfunction clamp(v: number, lo: number, hi: number): number {\n return v < lo ? lo : v > hi ? hi : v;\n}\n"]}
|
package/dist/tools/filter.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { canonicalJson } from '@sealpixel/core';
|
|
1
|
+
import { canonicalJson, } from '@sealpixel/core';
|
|
2
2
|
import { FILTER_DEFAULT_OPTIONS, presetLabelKey, presetMatrix, presetName, } from '@sealpixel/plugins';
|
|
3
3
|
import { html, nothing } from 'lit';
|
|
4
4
|
import { icons } from '../icons.js';
|
|
5
5
|
import { opId } from './finetune.js';
|
|
6
|
+
import { toolState } from './instance-state.js';
|
|
6
7
|
/** Leaves the image as it is, so the "none" tile shows the real source. */
|
|
7
8
|
const IDENTITY = [
|
|
8
9
|
[1, 0, 0, 0, 0],
|
|
@@ -18,52 +19,72 @@ const sameMatrix = (a, b) => a !== null &&
|
|
|
18
19
|
* each preset through whichever preset is already chosen, so picking Sepia
|
|
19
20
|
* turned every other tile sepia too and "None" stopped meaning none.
|
|
20
21
|
*
|
|
21
|
-
* Keyed by the rest of the log, so a
|
|
22
|
-
* changing the filter does not.
|
|
22
|
+
* Keyed by the loaded source and the rest of the log, so a new image, a crop
|
|
23
|
+
* or a finetune invalidates it while changing the filter does not. Without the
|
|
24
|
+
* source in the key, a new image with the same log showed the old thumbnails.
|
|
23
25
|
*/
|
|
24
26
|
const withoutFilter = (log) => ({
|
|
25
27
|
...log,
|
|
26
28
|
ops: log.ops.filter((op) => !op.type.startsWith('filter.')),
|
|
27
29
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* A number per loaded source. The session sets a new source object on every
|
|
32
|
+
* load, so two images with the same id and no hash still get different keys.
|
|
33
|
+
*/
|
|
34
|
+
const loads = new WeakMap();
|
|
35
|
+
let lastLoad = 0;
|
|
36
|
+
const loadNumber = (source) => {
|
|
37
|
+
if (!source)
|
|
38
|
+
return 0;
|
|
39
|
+
let n = loads.get(source);
|
|
40
|
+
if (n === undefined) {
|
|
41
|
+
n = ++lastLoad;
|
|
42
|
+
loads.set(source, n);
|
|
43
|
+
}
|
|
44
|
+
return n;
|
|
45
|
+
};
|
|
46
|
+
const baseKey = (state) => `${loadNumber(state.source)}:${canonicalJson(withoutFilter(state.history.log).ops)}`;
|
|
47
|
+
const createFilterState = () => ({
|
|
48
|
+
base: null,
|
|
49
|
+
basePending: null,
|
|
50
|
+
thumbCache: new Map(),
|
|
51
|
+
});
|
|
31
52
|
/**
|
|
32
53
|
* Returns the unfiltered image for this log, rendering it once per key. While
|
|
33
54
|
* a render is in flight the caller gets nothing and the tiles stay flat; the
|
|
34
55
|
* refresh lands a moment later.
|
|
35
56
|
*/
|
|
36
57
|
function baseImage(ctx) {
|
|
58
|
+
const state = toolState(ctx, createFilterState);
|
|
37
59
|
const { log } = ctx.state.history;
|
|
38
|
-
const key = baseKey(
|
|
39
|
-
if (base?.key === key)
|
|
40
|
-
return base.image;
|
|
60
|
+
const key = baseKey(ctx.state);
|
|
61
|
+
if (state.base?.key === key)
|
|
62
|
+
return state.base.image;
|
|
41
63
|
// No filter in the log means the stage already shows the unfiltered image.
|
|
42
64
|
if (log.ops.every((op) => !op.type.startsWith('filter.'))) {
|
|
43
65
|
const image = ctx.state.preview?.image ?? null;
|
|
44
66
|
if (image)
|
|
45
|
-
base = { key, image };
|
|
67
|
+
state.base = { key, image };
|
|
46
68
|
return image;
|
|
47
69
|
}
|
|
48
|
-
if (basePending === key)
|
|
70
|
+
if (state.basePending === key)
|
|
49
71
|
return null;
|
|
50
|
-
basePending = key;
|
|
72
|
+
state.basePending = key;
|
|
51
73
|
ctx.session
|
|
52
74
|
.renderDetached(withoutFilter)
|
|
53
75
|
.then((image) => {
|
|
54
|
-
base = { key, image };
|
|
76
|
+
state.base = { key, image };
|
|
55
77
|
ctx.refresh();
|
|
56
78
|
})
|
|
57
79
|
.catch(() => { })
|
|
58
80
|
.finally(() => {
|
|
59
|
-
if (basePending === key)
|
|
60
|
-
basePending = null;
|
|
81
|
+
if (state.basePending === key)
|
|
82
|
+
state.basePending = null;
|
|
61
83
|
});
|
|
62
84
|
return null;
|
|
63
85
|
}
|
|
64
86
|
/** Thumbnails: the base image downsampled and pushed through a matrix. */
|
|
65
|
-
|
|
66
|
-
function thumbnail(image, version, name, matrix) {
|
|
87
|
+
function thumbnail(thumbCache, image, version, name, matrix) {
|
|
67
88
|
const key = `${version}:${name}`;
|
|
68
89
|
const hit = thumbCache.get(key);
|
|
69
90
|
if (hit)
|
|
@@ -130,7 +151,8 @@ export const filterTool = {
|
|
|
130
151
|
return literal ?? ctx.t(key);
|
|
131
152
|
};
|
|
132
153
|
const source = options.thumbnails ? baseImage(ctx) : null;
|
|
133
|
-
const
|
|
154
|
+
const { thumbCache } = toolState(ctx, createFilterState);
|
|
155
|
+
const sourceKey = source ? baseKey(ctx.state) : '';
|
|
134
156
|
// The untouched image sits in its own group. It is not one preset among
|
|
135
157
|
// the others; it is what every preset is being compared against, and a gap
|
|
136
158
|
// says that faster than a label can.
|
|
@@ -141,7 +163,7 @@ export const filterTool = {
|
|
|
141
163
|
.label=${text}
|
|
142
164
|
@click=${onClick}
|
|
143
165
|
>${source && matrix
|
|
144
|
-
? html `<img class="thumb" alt="" src=${thumbnail(source, sourceKey, name, matrix)} /><span>${text}</span>`
|
|
166
|
+
? html `<img class="thumb" alt="" src=${thumbnail(thumbCache, source, sourceKey, name, matrix)} /><span>${text}</span>`
|
|
145
167
|
: text}</sealpixel-button
|
|
146
168
|
>`;
|
|
147
169
|
return html `
|
package/dist/tools/filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/tools/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAiC,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EAEL,sBAAsB,EAEtB,cAAc,EACd,YAAY,EACZ,UAAU,GACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,KAAK,E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C","sourcesContent":["import { canonicalJson, type EditLog, type RgbaBuffer } from '@sealpixel/core';\nimport {\n type ColorMatrix,\n FILTER_DEFAULT_OPTIONS,\n type FilterOptions,\n presetLabelKey,\n presetMatrix,\n presetName,\n} from '@sealpixel/plugins';\nimport { html, nothing } from 'lit';\nimport { icons } from '../icons.js';\nimport type { UiTool, UiToolContext } from '../tool.js';\nimport { opId } from './finetune.js';\n\ninterface FilterDoc {\n preset: string | null;\n matrix: ColorMatrix | null;\n strength: number;\n}\n\n/** Leaves the image as it is, so the \"none\" tile shows the real source. */\nconst IDENTITY: ColorMatrix = [\n [1, 0, 0, 0, 0],\n [0, 1, 0, 0, 0],\n [0, 0, 1, 0, 0],\n [0, 0, 0, 1, 0],\n];\n\nconst sameMatrix = (a: ColorMatrix | null, b: ColorMatrix) =>\n a !== null &&\n a.every((row, i) => row.every((v, j) => Math.abs(v - (b[i] as number[])[j]!) < 1e-9));\n\n/**\n * The image every thumbnail is drawn from: the current log with the filter\n * taken out. Rendering the tiles from the stage preview instead would push\n * each preset through whichever preset is already chosen, so picking Sepia\n * turned every other tile sepia too and \"None\" stopped meaning none.\n *\n * Keyed by the rest of the log, so a crop or a finetune invalidates it while\n * changing the filter does not.\n */\nconst withoutFilter = (log: EditLog): EditLog => ({\n ...log,\n ops: log.ops.filter((op) => !op.type.startsWith('filter.')),\n});\n\nconst baseKey = (log: EditLog): string => canonicalJson(withoutFilter(log).ops);\n\nlet base: { key: string; image: RgbaBuffer } | null = null;\nlet basePending: string | null = null;\n\n/**\n * Returns the unfiltered image for this log, rendering it once per key. While\n * a render is in flight the caller gets nothing and the tiles stay flat; the\n * refresh lands a moment later.\n */\nfunction baseImage(ctx: UiToolContext): RgbaBuffer | null {\n const { log } = ctx.state.history;\n const key = baseKey(log);\n if (base?.key === key) return base.image;\n // No filter in the log means the stage already shows the unfiltered image.\n if (log.ops.every((op) => !op.type.startsWith('filter.'))) {\n const image = ctx.state.preview?.image ?? null;\n if (image) base = { key, image };\n return image;\n }\n if (basePending === key) return null;\n basePending = key;\n ctx.session\n .renderDetached(withoutFilter)\n .then((image) => {\n base = { key, image };\n ctx.refresh();\n })\n .catch(() => {})\n .finally(() => {\n if (basePending === key) basePending = null;\n });\n return null;\n}\n\n/** Thumbnails: the base image downsampled and pushed through a matrix. */\nconst thumbCache = new Map<string, string>();\nfunction thumbnail(image: RgbaBuffer, version: string, name: string, matrix: ColorMatrix): string {\n const key = `${version}:${name}`;\n const hit = thumbCache.get(key);\n if (hit) return hit;\n if (thumbCache.size > 64) thumbCache.clear();\n // Rendered wider than the tile so an 84 px thumbnail is not an upscale.\n const w = 96;\n const h = Math.max(1, Math.round((image.height / image.width) * w));\n const canvas = document.createElement('canvas');\n canvas.width = w;\n canvas.height = h;\n const ctx = canvas.getContext('2d');\n if (!ctx) return '';\n const out = ctx.createImageData(w, h);\n for (let y = 0; y < h; y++) {\n const sy = Math.floor((y / h) * image.height);\n for (let x = 0; x < w; x++) {\n const sx = Math.floor((x / w) * image.width);\n const si = (sy * image.width + sx) * 4;\n const r = image.data[si]! / 255;\n const g = image.data[si + 1]! / 255;\n const b = image.data[si + 2]! / 255;\n const a = image.data[si + 3]! / 255;\n const di = (y * w + x) * 4;\n for (let c = 0; c < 4; c++) {\n const m = matrix[c]!;\n const v = m[0]! * r + m[1]! * g + m[2]! * b + m[3]! * a + m[4]!;\n out.data[di + c] = Math.max(0, Math.min(255, Math.round(v * 255)));\n }\n }\n }\n ctx.putImageData(out, 0, 0);\n const url = canvas.toDataURL('image/png');\n thumbCache.set(key, url);\n return url;\n}\n\nexport const filterTool: UiTool = {\n id: 'filter',\n icon: icons.filter,\n label: 'tool.filter',\n panel: (ctx: UiToolContext) => {\n const doc = (ctx.document as unknown as { filter: FilterDoc }).filter;\n const options = ctx.options<FilterOptions>('filter') ?? FILTER_DEFAULT_OPTIONS;\n const strength = doc.preset === null ? options.defaultStrength : doc.strength;\n const select = (preset: string | null) => {\n if (preset === null) {\n ctx.dispatch({ type: 'filter.set', id: opId(), preset: null });\n return;\n }\n const option = options.presets.find((p) => presetName(p) === preset);\n if (!option) return;\n ctx.dispatch(\n typeof option === 'string'\n ? { type: 'filter.set', id: opId(), preset, strength }\n : { type: 'filter.set', id: opId(), preset: 'custom', matrix: option.matrix, strength },\n );\n };\n const pressed = (p: FilterOptions['presets'][number]) =>\n typeof p === 'string'\n ? doc.preset === p\n : doc.preset === 'custom' && sameMatrix(doc.matrix, p.matrix);\n const label = (p: FilterOptions['presets'][number]) => {\n const { key, literal } = presetLabelKey(p);\n return literal ?? ctx.t(key);\n };\n const source = options.thumbnails ? baseImage(ctx) : null;\n const sourceKey = source ? baseKey(ctx.state.history.log) : '';\n // The untouched image sits in its own group. It is not one preset among\n // the others; it is what every preset is being compared against, and a gap\n // says that faster than a label can.\n const tile = (\n name: string,\n text: string,\n isPressed: boolean,\n matrix: ColorMatrix | null,\n onClick: () => void,\n ) => html`<sealpixel-button\n variant=\"ghost\"\n data-preset=${name}\n ?pressed=${isPressed}\n .label=${text}\n @click=${onClick}\n >${\n source && matrix\n ? html`<img class=\"thumb\" alt=\"\" src=${thumbnail(source, sourceKey, name, matrix)} /><span>${text}</span>`\n : text\n }</sealpixel-button\n >`;\n return html`\n <div class=${source ? 'strip tiles choice' : 'strip choice'} role=\"group\" aria-label=${ctx.t('tool.filter')}>\n ${tile('none', ctx.t('filter.none'), doc.preset === null, IDENTITY, () => select(null))}\n <span class=\"divider\" aria-hidden=\"true\"></span>\n ${options.presets.map((p) =>\n tile(presetName(p), label(p), pressed(p), presetMatrix(p), () => select(presetName(p))),\n )}\n </div>\n ${\n options.strength\n ? html`<sealpixel-slider\n data-param=\"strength\"\n .label=${ctx.t('filter.strength')}\n .value=${doc.strength}\n .min=${options.strengthRange.min}\n .max=${options.strengthRange.max}\n .step=${options.strengthRange.step}\n ?disabled=${doc.preset === null}\n @commit=${(e: CustomEvent<number>) =>\n ctx.dispatch({\n type: 'filter.set',\n id: opId(),\n preset: doc.preset,\n ...(doc.preset === 'custom' && doc.matrix ? { matrix: doc.matrix } : {}),\n strength: e.detail,\n })}\n ></sealpixel-slider>`\n : nothing\n }\n `;\n },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/tools/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAKd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,sBAAsB,EAEtB,cAAc,EACd,YAAY,EACZ,UAAU,GACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAQhD,2EAA2E;AAC3E,MAAM,QAAQ,GAAgB;IAC5B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACf,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACf,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACf,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;CAChB,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,CAAqB,EAAE,CAAc,EAAE,EAAE,CAC3D,CAAC,KAAK,IAAI;IACV,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAI,CAAC,CAAC,CAAC,CAAc,CAAC,CAAC,CAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AAExF;;;;;;;;;GASG;AACH,MAAM,a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AAC,OACN;KACD,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import {\n canonicalJson,\n type EditLog,\n type RgbaBuffer,\n type SessionState,\n type SourceDescriptor,\n} from '@sealpixel/core';\nimport {\n type ColorMatrix,\n FILTER_DEFAULT_OPTIONS,\n type FilterOptions,\n presetLabelKey,\n presetMatrix,\n presetName,\n} from '@sealpixel/plugins';\nimport { html, nothing } from 'lit';\nimport { icons } from '../icons.js';\nimport type { UiTool, UiToolContext } from '../tool.js';\nimport { opId } from './finetune.js';\nimport { toolState } from './instance-state.js';\n\ninterface FilterDoc {\n preset: string | null;\n matrix: ColorMatrix | null;\n strength: number;\n}\n\n/** Leaves the image as it is, so the \"none\" tile shows the real source. */\nconst IDENTITY: ColorMatrix = [\n [1, 0, 0, 0, 0],\n [0, 1, 0, 0, 0],\n [0, 0, 1, 0, 0],\n [0, 0, 0, 1, 0],\n];\n\nconst sameMatrix = (a: ColorMatrix | null, b: ColorMatrix) =>\n a !== null &&\n a.every((row, i) => row.every((v, j) => Math.abs(v - (b[i] as number[])[j]!) < 1e-9));\n\n/**\n * The image every thumbnail is drawn from: the current log with the filter\n * taken out. Rendering the tiles from the stage preview instead would push\n * each preset through whichever preset is already chosen, so picking Sepia\n * turned every other tile sepia too and \"None\" stopped meaning none.\n *\n * Keyed by the loaded source and the rest of the log, so a new image, a crop\n * or a finetune invalidates it while changing the filter does not. Without the\n * source in the key, a new image with the same log showed the old thumbnails.\n */\nconst withoutFilter = (log: EditLog): EditLog => ({\n ...log,\n ops: log.ops.filter((op) => !op.type.startsWith('filter.')),\n});\n\n/**\n * A number per loaded source. The session sets a new source object on every\n * load, so two images with the same id and no hash still get different keys.\n */\nconst loads = new WeakMap<object, number>();\nlet lastLoad = 0;\nconst loadNumber = (source: SourceDescriptor | null): number => {\n if (!source) return 0;\n let n = loads.get(source);\n if (n === undefined) {\n n = ++lastLoad;\n loads.set(source, n);\n }\n return n;\n};\n\nconst baseKey = (state: SessionState): string =>\n `${loadNumber(state.source)}:${canonicalJson(withoutFilter(state.history.log).ops)}`;\n\n/** The base image, the key of the render in flight and the thumbnails, per editor. */\ninterface FilterState {\n base: { key: string; image: RgbaBuffer } | null;\n basePending: string | null;\n thumbCache: Map<string, string>;\n}\nconst createFilterState = (): FilterState => ({\n base: null,\n basePending: null,\n thumbCache: new Map(),\n});\n\n/**\n * Returns the unfiltered image for this log, rendering it once per key. While\n * a render is in flight the caller gets nothing and the tiles stay flat; the\n * refresh lands a moment later.\n */\nfunction baseImage(ctx: UiToolContext): RgbaBuffer | null {\n const state = toolState(ctx, createFilterState);\n const { log } = ctx.state.history;\n const key = baseKey(ctx.state);\n if (state.base?.key === key) return state.base.image;\n // No filter in the log means the stage already shows the unfiltered image.\n if (log.ops.every((op) => !op.type.startsWith('filter.'))) {\n const image = ctx.state.preview?.image ?? null;\n if (image) state.base = { key, image };\n return image;\n }\n if (state.basePending === key) return null;\n state.basePending = key;\n ctx.session\n .renderDetached(withoutFilter)\n .then((image) => {\n state.base = { key, image };\n ctx.refresh();\n })\n .catch(() => {})\n .finally(() => {\n if (state.basePending === key) state.basePending = null;\n });\n return null;\n}\n\n/** Thumbnails: the base image downsampled and pushed through a matrix. */\nfunction thumbnail(\n thumbCache: Map<string, string>,\n image: RgbaBuffer,\n version: string,\n name: string,\n matrix: ColorMatrix,\n): string {\n const key = `${version}:${name}`;\n const hit = thumbCache.get(key);\n if (hit) return hit;\n if (thumbCache.size > 64) thumbCache.clear();\n // Rendered wider than the tile so an 84 px thumbnail is not an upscale.\n const w = 96;\n const h = Math.max(1, Math.round((image.height / image.width) * w));\n const canvas = document.createElement('canvas');\n canvas.width = w;\n canvas.height = h;\n const ctx = canvas.getContext('2d');\n if (!ctx) return '';\n const out = ctx.createImageData(w, h);\n for (let y = 0; y < h; y++) {\n const sy = Math.floor((y / h) * image.height);\n for (let x = 0; x < w; x++) {\n const sx = Math.floor((x / w) * image.width);\n const si = (sy * image.width + sx) * 4;\n const r = image.data[si]! / 255;\n const g = image.data[si + 1]! / 255;\n const b = image.data[si + 2]! / 255;\n const a = image.data[si + 3]! / 255;\n const di = (y * w + x) * 4;\n for (let c = 0; c < 4; c++) {\n const m = matrix[c]!;\n const v = m[0]! * r + m[1]! * g + m[2]! * b + m[3]! * a + m[4]!;\n out.data[di + c] = Math.max(0, Math.min(255, Math.round(v * 255)));\n }\n }\n }\n ctx.putImageData(out, 0, 0);\n const url = canvas.toDataURL('image/png');\n thumbCache.set(key, url);\n return url;\n}\n\nexport const filterTool: UiTool = {\n id: 'filter',\n icon: icons.filter,\n label: 'tool.filter',\n panel: (ctx: UiToolContext) => {\n const doc = (ctx.document as unknown as { filter: FilterDoc }).filter;\n const options = ctx.options<FilterOptions>('filter') ?? FILTER_DEFAULT_OPTIONS;\n const strength = doc.preset === null ? options.defaultStrength : doc.strength;\n const select = (preset: string | null) => {\n if (preset === null) {\n ctx.dispatch({ type: 'filter.set', id: opId(), preset: null });\n return;\n }\n const option = options.presets.find((p) => presetName(p) === preset);\n if (!option) return;\n ctx.dispatch(\n typeof option === 'string'\n ? { type: 'filter.set', id: opId(), preset, strength }\n : { type: 'filter.set', id: opId(), preset: 'custom', matrix: option.matrix, strength },\n );\n };\n const pressed = (p: FilterOptions['presets'][number]) =>\n typeof p === 'string'\n ? doc.preset === p\n : doc.preset === 'custom' && sameMatrix(doc.matrix, p.matrix);\n const label = (p: FilterOptions['presets'][number]) => {\n const { key, literal } = presetLabelKey(p);\n return literal ?? ctx.t(key);\n };\n const source = options.thumbnails ? baseImage(ctx) : null;\n const { thumbCache } = toolState(ctx, createFilterState);\n const sourceKey = source ? baseKey(ctx.state) : '';\n // The untouched image sits in its own group. It is not one preset among\n // the others; it is what every preset is being compared against, and a gap\n // says that faster than a label can.\n const tile = (\n name: string,\n text: string,\n isPressed: boolean,\n matrix: ColorMatrix | null,\n onClick: () => void,\n ) => html`<sealpixel-button\n variant=\"ghost\"\n data-preset=${name}\n ?pressed=${isPressed}\n .label=${text}\n @click=${onClick}\n >${\n source && matrix\n ? html`<img class=\"thumb\" alt=\"\" src=${thumbnail(thumbCache, source, sourceKey, name, matrix)} /><span>${text}</span>`\n : text\n }</sealpixel-button\n >`;\n return html`\n <div class=${source ? 'strip tiles choice' : 'strip choice'} role=\"group\" aria-label=${ctx.t('tool.filter')}>\n ${tile('none', ctx.t('filter.none'), doc.preset === null, IDENTITY, () => select(null))}\n <span class=\"divider\" aria-hidden=\"true\"></span>\n ${options.presets.map((p) =>\n tile(presetName(p), label(p), pressed(p), presetMatrix(p), () => select(presetName(p))),\n )}\n </div>\n ${\n options.strength\n ? html`<sealpixel-slider\n data-param=\"strength\"\n .label=${ctx.t('filter.strength')}\n .value=${doc.strength}\n .min=${options.strengthRange.min}\n .max=${options.strengthRange.max}\n .step=${options.strengthRange.step}\n ?disabled=${doc.preset === null}\n @commit=${(e: CustomEvent<number>) =>\n ctx.dispatch({\n type: 'filter.set',\n id: opId(),\n preset: doc.preset,\n ...(doc.preset === 'custom' && doc.matrix ? { matrix: doc.matrix } : {}),\n strength: e.detail,\n })}\n ></sealpixel-slider>`\n : nothing\n }\n `;\n },\n};\n"]}
|
package/dist/tools/finetune.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FINETUNE_DEFAULT_OPTIONS, finetuneRange, } from '@sealpixel/plugins';
|
|
2
2
|
import { html, nothing } from 'lit';
|
|
3
3
|
import { icons } from '../icons.js';
|
|
4
|
+
import { toolState } from './instance-state.js';
|
|
4
5
|
const SLIDERS = [
|
|
5
6
|
{ key: 'brightness', min: -1, max: 1, step: 0.01 },
|
|
6
7
|
{ key: 'contrast', min: -1, max: 1, step: 0.01 },
|
|
@@ -23,8 +24,8 @@ export function finetuneCss(p) {
|
|
|
23
24
|
parts.push(`saturate(${1 + p.saturation})`);
|
|
24
25
|
return parts.join(' ');
|
|
25
26
|
}
|
|
26
|
-
/** The one parameter the bottom bar is showing. */
|
|
27
|
-
|
|
27
|
+
/** The one parameter the bottom bar is showing, per editor. */
|
|
28
|
+
const createFinetuneState = () => ({ selected: 'brightness' });
|
|
28
29
|
/** The value that means "untouched", which is also where the dial detents. */
|
|
29
30
|
const neutral = (key) => (key === 'gamma' ? 1 : 0);
|
|
30
31
|
export const finetuneTool = {
|
|
@@ -38,9 +39,11 @@ export const finetuneTool = {
|
|
|
38
39
|
key,
|
|
39
40
|
...finetuneRange(options, key),
|
|
40
41
|
}));
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const state = toolState(ctx, createFinetuneState);
|
|
43
|
+
if (!options.controls.includes(state.selected)) {
|
|
44
|
+
state.selected = options.controls[0] ?? 'brightness';
|
|
45
|
+
}
|
|
46
|
+
const active = sliders.find((s) => s.key === state.selected);
|
|
44
47
|
// One dial above the chips at every width. The bar is the same shape on a
|
|
45
48
|
// phone and on a desktop, so the control never moves between them, and a
|
|
46
49
|
// parameter the user has touched is marked so the stack stays readable
|
|
@@ -70,10 +73,10 @@ export const finetuneTool = {
|
|
|
70
73
|
${sliders.map((s) => html `<sealpixel-button
|
|
71
74
|
variant="ghost"
|
|
72
75
|
data-chip=${s.key}
|
|
73
|
-
?pressed=${s.key === selected}
|
|
76
|
+
?pressed=${s.key === state.selected}
|
|
74
77
|
.label=${ctx.t(`finetune.${s.key}`)}
|
|
75
78
|
@click=${() => {
|
|
76
|
-
selected = s.key;
|
|
79
|
+
state.selected = s.key;
|
|
77
80
|
ctx.refresh();
|
|
78
81
|
}}
|
|
79
82
|
>${ctx.t(`finetune.${s.key}`)}${doc[s.key] !== neutral(s.key) ? ' •' : ''}</sealpixel-button
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finetune.js","sourceRoot":"","sources":["../../src/tools/finetune.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EAGxB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM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AC,QAAQ,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["import {\n FINETUNE_DEFAULT_OPTIONS,\n type FinetuneControl,\n type FinetuneOptions,\n finetuneRange,\n} from '@sealpixel/plugins';\nimport { html, nothing } from 'lit';\nimport { icons } from '../icons.js';\nimport type { UiTool, UiToolContext } from '../tool.js';\nimport { toolState } from './instance-state.js';\n\ntype Params = {\n [K in\n | 'brightness'\n | 'contrast'\n | 'saturation'\n | 'exposure'\n | 'gamma'\n | 'clarity'\n | 'vignette']: number;\n};\n\nconst SLIDERS: { key: keyof Params; min: number; max: number; step: number }[] = [\n { key: 'brightness', min: -1, max: 1, step: 0.01 },\n { key: 'contrast', min: -1, max: 1, step: 0.01 },\n { key: 'saturation', min: -1, max: 1, step: 0.01 },\n { key: 'exposure', min: -3, max: 3, step: 0.01 },\n { key: 'gamma', min: 0.1, max: 4, step: 0.01 },\n { key: 'clarity', min: -1, max: 1, step: 0.01 },\n { key: 'vignette', min: -1, max: 1, step: 0.01 },\n];\n\n/** Cheap CSS approximation of the tonal parameters for tier-A previews. */\nexport function finetuneCss(p: Params): string {\n const parts: string[] = [];\n if (p.exposure !== 0) parts.push(`brightness(${2 ** p.exposure})`);\n if (p.brightness !== 0) parts.push(`brightness(${1 + p.brightness * 0.5})`);\n if (p.contrast !== 0) parts.push(`contrast(${1 + p.contrast})`);\n if (p.saturation !== 0) parts.push(`saturate(${1 + p.saturation})`);\n return parts.join(' ');\n}\n\n/** The one parameter the bottom bar is showing, per editor. */\nconst createFinetuneState = (): { selected: keyof Params } => ({ selected: 'brightness' });\n\n/** The value that means \"untouched\", which is also where the dial detents. */\nconst neutral = (key: keyof Params) => (key === 'gamma' ? 1 : 0);\n\nexport const finetuneTool: UiTool = {\n id: 'finetune',\n icon: icons.finetune,\n label: 'tool.finetune',\n panel: (ctx: UiToolContext) => {\n const doc = (ctx.document as unknown as { finetune: Params }).finetune;\n const options = ctx.options<FinetuneOptions>('finetune') ?? FINETUNE_DEFAULT_OPTIONS;\n const sliders = options.controls.map((key: FinetuneControl) => ({\n key,\n ...finetuneRange(options, key),\n }));\n const state = toolState(ctx, createFinetuneState);\n if (!options.controls.includes(state.selected)) {\n state.selected = options.controls[0] ?? 'brightness';\n }\n const active = sliders.find((s) => s.key === state.selected);\n // One dial above the chips at every width. The bar is the same shape on a\n // phone and on a desktop, so the control never moves between them, and a\n // parameter the user has touched is marked so the stack stays readable\n // while only one of them is on screen.\n return html`\n ${\n active\n ? html`<sealpixel-slider\n data-param=${active.key}\n .label=${ctx.t(`finetune.${active.key}`)}\n .value=${doc[active.key]}\n .min=${active.min}\n .max=${active.max}\n .step=${active.step}\n .detent=${neutral(active.key)}\n @slide=${(e: CustomEvent<number>) => ctx.hint({ filter: finetuneCss({ ...doc, [active.key]: e.detail }) })}\n @commit=${(e: CustomEvent<number>) => {\n ctx.hint(null);\n ctx.dispatch({\n type: 'finetune.set',\n id: opId(),\n params: { [active.key]: e.detail },\n });\n }}\n ></sealpixel-slider>`\n : nothing\n }\n <div class=\"strip chips choice\" role=\"group\" aria-label=${ctx.t('tool.finetune')}>\n ${sliders.map(\n (s) => html`<sealpixel-button\n variant=\"ghost\"\n data-chip=${s.key}\n ?pressed=${s.key === state.selected}\n .label=${ctx.t(`finetune.${s.key}`)}\n @click=${() => {\n state.selected = s.key;\n ctx.refresh();\n }}\n >${ctx.t(`finetune.${s.key}`)}${doc[s.key] !== neutral(s.key) ? ' •' : ''}</sealpixel-button\n >`,\n )}\n <span class=\"divider\" aria-hidden=\"true\"></span>\n <sealpixel-button\n variant=\"ghost\"\n data-action=\"reset\"\n .label=${ctx.t('finetune.reset')}\n @click=${() => ctx.dispatch({ type: 'finetune.reset', id: opId() })}\n >${ctx.t('finetune.reset')}</sealpixel-button\n >\n </div>\n `;\n },\n};\n\n/** Unique op id: time-ordered, collision-safe enough for a single client. */\nexport function opId(): string {\n const rnd = Math.random().toString(36).slice(2, 8);\n return `${Date.now().toString(36)}-${rnd}`;\n}\n"]}
|
package/dist/tools/frame.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FRAME_DEFAULT_OPTIONS } from '@sealpixel/plugins';
|
|
1
|
+
import { colorFromHex, FRAME_DEFAULT_OPTIONS } from '@sealpixel/plugins';
|
|
2
2
|
import { html, nothing } from 'lit';
|
|
3
3
|
import { icons } from '../icons.js';
|
|
4
4
|
import { opId } from './finetune.js';
|
|
@@ -7,12 +7,6 @@ const hex = (c) => `#${[c[0], c[1], c[2]]
|
|
|
7
7
|
.toString(16)
|
|
8
8
|
.padStart(2, '0'))
|
|
9
9
|
.join('')}`;
|
|
10
|
-
const fromHex = (h, a = 1) => [
|
|
11
|
-
Number.parseInt(h.slice(1, 3), 16) / 255,
|
|
12
|
-
Number.parseInt(h.slice(3, 5), 16) / 255,
|
|
13
|
-
Number.parseInt(h.slice(5, 7), 16) / 255,
|
|
14
|
-
a,
|
|
15
|
-
];
|
|
16
10
|
export const frameTool = {
|
|
17
11
|
id: 'frame',
|
|
18
12
|
icon: icons.frame,
|
|
@@ -24,7 +18,9 @@ export const frameTool = {
|
|
|
24
18
|
type: 'frame.set',
|
|
25
19
|
id: opId(),
|
|
26
20
|
// A new frame starts from the configured defaults, then applies the patch.
|
|
27
|
-
...(frame === null
|
|
21
|
+
...(frame === null
|
|
22
|
+
? { ...options.defaults, color: colorFromHex(options.defaults.color) }
|
|
23
|
+
: {}),
|
|
28
24
|
...patch,
|
|
29
25
|
});
|
|
30
26
|
const sourceMax = Math.max(8, Math.round(Math.min(ctx.state.source?.width ?? 400, ctx.state.source?.height ?? 400) / 4));
|
|
@@ -44,10 +40,14 @@ export const frameTool = {
|
|
|
44
40
|
<label class="field"><span>${ctx.t('frame.color')}</span>
|
|
45
41
|
${options.palette.length > 0
|
|
46
42
|
? html `<div class="swatches" role="group" aria-label=${ctx.t('frame.color')}>
|
|
47
|
-
${options.palette.map((h) => html `<button type="button" class="swatch" data-swatch=${h} style=${`background:${h}`} aria-label=${h} aria-pressed=${hex(frame.color) === h.slice(0, 7) ? 'true' : 'false'} @click=${() => set({ color:
|
|
43
|
+
${options.palette.map((h) => html `<button type="button" class="swatch" data-swatch=${h} style=${`background:${h}`} aria-label=${h} aria-pressed=${hex(frame.color) === h.slice(0, 7) ? 'true' : 'false'} @click=${() => set({ color: colorFromHex(h) })}></button>`)}
|
|
48
44
|
</div>`
|
|
49
45
|
: nothing}
|
|
50
|
-
|
|
46
|
+
${
|
|
47
|
+
// With enforce, the palette alone is the control: a free colour would be rejected.
|
|
48
|
+
!options.enforce || options.palette.length === 0
|
|
49
|
+
? html `<input data-field="color" type="color" .value=${hex(frame.color)} @change=${(e) => set({ color: colorFromHex(e.target.value) })} />`
|
|
50
|
+
: nothing}</label>
|
|
51
51
|
<sealpixel-stepper data-param="radius" .label=${ctx.t('frame.radius')} .value=${frame.radius} .min=${r.min} .max=${maxRadius} .step=${r.step} unit="px" @commit=${(e) => set({ radius: e.detail })}></sealpixel-stepper>
|
|
52
52
|
</div>`
|
|
53
53
|
: null}
|
package/dist/tools/frame.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frame.js","sourceRoot":"","sources":["../../src/tools/frame.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAqB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"frame.js","sourceRoot":"","sources":["../../src/tools/frame.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAqB,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAWrC,MAAM,GAAG,GAAG,CAAC,CAAQ,EAAE,EAAE,CACvB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAA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K,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC;yBAC/P;gBACP,CAAC,CAAC,OACN;gBACE;YACA,mFAAmF;YACnF,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;gBAC9C,CAAC,CAAC,IAAI,CAAA,iDAAiD,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,YAAY,CAAE,CAAC,CAAC,MAA2B,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK;gBACxK,CAAC,CAAC,OACN;4DAC8C,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,WAAW,KAAK,CAAC,MAAM,SAAS,CAAC,CAAC,GAAG,SAAS,SAAS,UAAU,CAAC,CAAC,IAAI,sBAAsB,CAAC,CAAsB,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;mBAChN;YACT,CAAC,CAAC,IACN;KACD,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import type { Color } from '@sealpixel/core';\nimport { colorFromHex, FRAME_DEFAULT_OPTIONS, type FrameOptions } from '@sealpixel/plugins';\nimport { html, nothing } from 'lit';\nimport { icons } from '../icons.js';\nimport type { UiTool, UiToolContext } from '../tool.js';\nimport { opId } from './finetune.js';\n\ninterface FrameDoc {\n frame: {\n style: 'solid' | 'inset' | 'polaroid';\n color: Color;\n thickness: number;\n radius: number;\n } | null;\n}\n\nconst hex = (c: Color) =>\n `#${[c[0], c[1], c[2]]\n .map((v) =>\n Math.round(v * 255)\n .toString(16)\n .padStart(2, '0'),\n )\n .join('')}`;\n\nexport const frameTool: UiTool = {\n id: 'frame',\n icon: icons.frame,\n label: 'tool.frame',\n panel: (ctx: UiToolContext) => {\n const frame = (ctx.document as unknown as { frame: FrameDoc }).frame.frame;\n const options = ctx.options<FrameOptions>('frame') ?? FRAME_DEFAULT_OPTIONS;\n const set = (patch: Record<string, unknown>) =>\n ctx.dispatch({\n type: 'frame.set',\n id: opId(),\n // A new frame starts from the configured defaults, then applies the patch.\n ...(frame === null\n ? { ...options.defaults, color: colorFromHex(options.defaults.color) }\n : {}),\n ...patch,\n });\n const sourceMax = Math.max(\n 8,\n Math.round(Math.min(ctx.state.source?.width ?? 400, ctx.state.source?.height ?? 400) / 4),\n );\n // Thickness is configuration (`defaults.thickness`); only the radius has a control.\n const r = options.radiusRange;\n const maxRadius = Math.min(r.max, sourceMax * 2);\n return html`\n <div class=\"row choice\" role=\"group\" aria-label=${ctx.t('frame.style')}>\n <div class=\"group\">\n <sealpixel-button data-style=\"none\" ?pressed=${frame === null} @click=${() => ctx.dispatch({ type: 'frame.clear', id: opId() })}>${ctx.t('frame.none')}</sealpixel-button>\n ${options.styles.map(\n (s) =>\n html`<sealpixel-button data-style=${s} ?pressed=${frame?.style === s} @click=${() => set({ style: s })}>${ctx.t(`frame.style.${s}`)}</sealpixel-button>`,\n )}\n </div>\n </div>\n ${\n frame\n ? html`\n <div class=\"rows\">\n <label class=\"field\"><span>${ctx.t('frame.color')}</span>\n ${\n options.palette.length > 0\n ? html`<div class=\"swatches\" role=\"group\" aria-label=${ctx.t('frame.color')}>\n ${options.palette.map((h) => html`<button type=\"button\" class=\"swatch\" data-swatch=${h} style=${`background:${h}`} aria-label=${h} aria-pressed=${hex(frame.color) === h.slice(0, 7) ? 'true' : 'false'} @click=${() => set({ color: colorFromHex(h) })}></button>`)}\n </div>`\n : nothing\n }\n ${\n // With enforce, the palette alone is the control: a free colour would be rejected.\n !options.enforce || options.palette.length === 0\n ? html`<input data-field=\"color\" type=\"color\" .value=${hex(frame.color)} @change=${(e: Event) => set({ color: colorFromHex((e.target as HTMLInputElement).value) })} />`\n : nothing\n }</label>\n <sealpixel-stepper data-param=\"radius\" .label=${ctx.t('frame.radius')} .value=${frame.radius} .min=${r.min} .max=${maxRadius} .step=${r.step} unit=\"px\" @commit=${(e: CustomEvent<number>) => set({ radius: e.detail })}></sealpixel-stepper>\n </div>`\n : null\n }\n `;\n },\n};\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UiToolContext } from '../tool.js';
|
|
2
|
+
/** Marks `ctx` as built by `owner`, so the tools keep their state for that owner. */
|
|
3
|
+
export declare function bindToolContext<C extends UiToolContext>(owner: object, ctx: C): C;
|
|
4
|
+
/**
|
|
5
|
+
* The tool state that `create` makes, once per owner of `ctx`. `create` is
|
|
6
|
+
* the key, so every tool passes the same module-level function on each call.
|
|
7
|
+
*/
|
|
8
|
+
export declare function toolState<S>(ctx: UiToolContext, create: () => S): S;
|