@sealpixel/ui 1.0.0-rc.17 → 1.0.0-rc.18
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/sealpixel-button.js +1 -1
- package/dist/components/sealpixel-button.js.map +1 -1
- package/dist/components/sealpixel-editor.js +6 -6
- package/dist/components/sealpixel-editor.js.map +1 -1
- package/dist/components/sealpixel-nav.js +1 -1
- package/dist/components/sealpixel-nav.js.map +1 -1
- package/dist/components/sealpixel-slider.d.ts +12 -16
- package/dist/components/sealpixel-slider.js +64 -10
- package/dist/components/sealpixel-slider.js.map +1 -1
- package/dist/components/sealpixel-stage.js +13 -1
- package/dist/components/sealpixel-stage.js.map +1 -1
- package/dist/components/sealpixel-stepper.js +4 -4
- package/dist/components/sealpixel-stepper.js.map +1 -1
- package/dist/components/sealpixel-toolbar.js +3 -3
- package/dist/components/sealpixel-toolbar.js.map +1 -1
- package/dist/tools/crop-rotation.d.ts +12 -0
- package/dist/tools/crop-rotation.js +19 -0
- package/dist/tools/crop-rotation.js.map +1 -1
- package/dist/tools/crop.js +17 -7
- package/dist/tools/crop.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sealpixel-toolbar.js","sourceRoot":"","sources":["../../src/components/sealpixel-toolbar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGnC,0FAA0F;AAC1F,MAAM,OAAO,gBAAiB,SAAQ,UAAU;aAC9B,WAAM,GAAG;QACvB,IAAI;QACJ,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AC,EAAE,CAAC;YAClB,CAAC,CAAC,IAAI,CAAA,uDAAwD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAY,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;0CACvG,IAAI,CAAC,CAAC,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAW,EAAE,CAAC,SAAS;YAClG,CAAC,CAAC,OACN;;gCAEoB,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;kBAChC,CACX;WACI,CAAC;IACV,CAAC;IAEO,MAAM,CAAC,EAAU;QACvB,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAC9E,CAAC;IACJ,CAAC","sourcesContent":["import { css, html, LitElement, nothing } from 'lit';\nimport { base } from '../theme.js';\nimport type { UiTool } from '../tool.js';\n\n/** Tool switcher with roving tabindex. Horizontal on narrow layouts, vertical on wide. */\nexport class SealpixelToolbar extends LitElement {\n static override styles = [\n base,\n css`\n :host {\n display: flex;\n padding: 4px;\n background: var(--sealpixel-color-surface);\n border-top: 1px solid var(--sealpixel-color-border);\n overflow: auto;\n scrollbar-width: thin;\n /* Arrow keys move the roving tabindex; the scroll follows it smoothly. */\n scroll-behavior: smooth;\n }\n .tools {\n display: flex;\n gap: 4px;\n /* Centres when it fits, scrolls from the first button when it does not. */\n margin: auto;\n }\n :host([orientation='vertical']) {\n border-top: none;\n border-right: 1px solid var(--sealpixel-color-border);\n /* The rail has a fixed width: a long label truncates, it never scrolls sideways. */\n overflow-x: hidden;\n }\n :host([orientation='vertical']) .tools {\n flex-direction: column;\n margin: 0;\n width: 100%;\n min-width: 0;\n }\n :host([orientation='vertical']) button {\n width: 100%;\n min-width: 0;\n }\n /* A long label (German, for example) must not widen the horizontal bar. */\n :host(:not([orientation='vertical'])) button {\n max-inline-size: var(--sealpixel-toolbar-label-max, 88px);\n }\n button {\n min-width: var(--sealpixel-touch-target);\n min-height: calc(var(--sealpixel-touch-target) + 10px);\n border: 1px solid transparent;\n border-radius: var(--sealpixel-radius);\n background: transparent;\n color: var(--sealpixel-color-fg-muted);\n font: inherit;\n font-size: 11px;\n font-weight: 500;\n letter-spacing: 0.01em;\n cursor: pointer;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: 4px;\n padding: 6px 4px;\n max-width: 100%;\n transition:\n background var(--sealpixel-transition),\n color var(--sealpixel-transition);\n }\n button:hover {\n color: var(--sealpixel-color-fg);\n background: var(--sealpixel-color-surface-2);\n }\n button[aria-pressed='true'] {\n color: var(--sealpixel-color-accent);\n background: var(--sealpixel-color-accent-soft, var(--sealpixel-color-surface-2));\n }\n .icon {\n font-size: 20px;\n line-height: 1;\n width: 28px;\n height: 28px;\n display: grid;\n place-items: center;\n border-radius: 8px;\n /*\n * The filled pill is the one element that says which tool is open, so\n * it is the one that earns a spring. Colour and shadow ride the\n * standard curve underneath, otherwise the overshoot shows up as a\n * flash of accent at the edges.\n */\n transition:\n transform var(--sealpixel-duration) var(--sealpixel-ease-spring),\n background var(--sealpixel-duration) var(--sealpixel-ease),\n color var(--sealpixel-duration) var(--sealpixel-ease),\n box-shadow var(--sealpixel-duration) var(--sealpixel-ease);\n }\n button:hover .icon {\n transform: translateY(-1px);\n }\n button[aria-pressed='true'] .icon {\n background: var(--sealpixel-color-accent);\n color: var(--sealpixel-color-accent-fg);\n box-shadow: var(--sealpixel-shadow-sm, none);\n transform: none;\n }\n button:active .icon {\n transform: scale(0.92);\n transition-duration: var(--sealpixel-duration-fast);\n }\n .label {\n /*\n * A block as wide as the button, so the ellipsis applies in every\n * engine. It must not shrink: a flex item with overflow hidden may\n * collapse in the column and cut the descenders. The line height stays\n * inherited, because the host page sets it and the panel measures it.\n */\n display: block;\n box-sizing: border-box;\n width: 100%;\n flex: none;\n min-width: 0;\n max-width: 100%;\n text-align: center;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n /* A count over the icon's corner, notification style. Hidden at zero. */\n .icon-wrap {\n position: relative;\n }\n .badge {\n position: absolute;\n top: -6px;\n right: -10px;\n min-width: 16px;\n height: 16px;\n padding: 0 4px;\n box-sizing: border-box;\n border-radius: 999px;\n background: var(--sealpixel-color-accent);\n color: var(--sealpixel-color-accent-fg);\n font-size: 10px;\n line-height: 16px;\n font-weight: 600;\n font-variant-numeric: tabular-nums;\n text-align: center;\n pointer-events: none;\n }\n .sr-only {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip: rect(0 0 0 0);\n white-space: nowrap;\n }\n `,\n ];\n\n static override properties = {\n tools: { attribute: false },\n badges: { attribute: false },\n active: { type: String },\n orientation: { type: String, reflect: true },\n t: { attribute: false },\n };\n\n declare tools: UiTool[];\n /** Counts by tool id, shown as a bubble on the button; a missing or zero entry shows nothing. */\n declare badges: Record<string, number>;\n declare active: string | null;\n declare orientation: 'horizontal' | 'vertical';\n declare t: (key: string, params?: Record<string, string | number>) => string;\n\n constructor() {\n super();\n this.tools = [];\n this.badges = {};\n this.active = null;\n this.orientation = 'horizontal';\n this.t = (k) => k;\n }\n\n override render() {\n return html`<div class=\"tools\" role=\"toolbar\" aria-orientation=${this.orientation} @keydown=${this.onKeydown}>\n ${this.tools.map(\n (tool, i) => html`<button\n part=\"tool\"\n type=\"button\"\n data-tool=${tool.id}\n title=${this.t(tool.label)}\n aria-pressed=${this.active === tool.id ? 'true' : 'false'}\n tabindex=${this.active === tool.id || (this.active === null && i === 0) ? 0 : -1}\n @click=${() => this.select(tool.id)}\n >\n <span class=\"icon-wrap\">\n <span class=\"icon\" aria-hidden=\"true\">${tool.icon}</span>\n ${\n this.badges[tool.id]\n ? html`<span part=\"badge\" class=\"badge\" aria-hidden=\"true\">${(this.badges[tool.id] as number) > 99 ? '99+' : this.badges[tool.id]}</span>\n <span class=\"sr-only\">${this.t('tool.badge', { count: this.badges[tool.id] as number })}</span>`\n : nothing\n }\n </span>\n <span class=\"label\">${this.t(tool.label)}</span>\n </button>`,\n )}\n </div>`;\n }\n\n private select(id: string): void {\n this.dispatchEvent(\n new CustomEvent('tool-select', { detail: id, bubbles: true, composed: true }),\n );\n }\n\n private onKeydown = (e: KeyboardEvent) => {\n const keys =\n this.orientation === 'vertical' ? ['ArrowUp', 'ArrowDown'] : ['ArrowLeft', 'ArrowRight'];\n const dir = e.key === keys[0] ? -1 : e.key === keys[1] ? 1 : 0;\n if (dir === 0) return;\n e.preventDefault();\n const idx = Math.max(\n 0,\n this.tools.findIndex((t) => t.id === this.active),\n );\n const next = this.tools[(idx + dir + this.tools.length) % this.tools.length];\n if (next) {\n this.select(next.id);\n this.updateComplete.then(() =>\n (this.renderRoot.querySelector(`[data-tool=\"${next.id}\"]`) as HTMLElement | null)?.focus(),\n );\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sealpixel-toolbar.js","sourceRoot":"","sources":["../../src/components/sealpixel-toolbar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGnC,0FAA0F;AAC1F,MAAM,OAAO,gBAAiB,SAAQ,UAAU;aAC9B,WAAM,GAAG;QACvB,IAAI;QACJ,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAqJF;KACF,AAxJqB,CAwJpB;aAEc,eAAU,GAAG;QAC3B,KAAK,EAAE,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AAY,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;0CACvG,IAAI,CAAC,CAAC,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAW,EAAE,CAAC,SAAS;YAClG,CAAC,CAAC,OACN;;gCAEoB,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;kBAChC,CACX;WACI,CAAC;IACV,CAAC;IAEO,MAAM,CAAC,EAAU;QACvB,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAC9E,CAAC;IACJ,CAAC","sourcesContent":["import { css, html, LitElement, nothing } from 'lit';\nimport { base } from '../theme.js';\nimport type { UiTool } from '../tool.js';\n\n/** Tool switcher with roving tabindex. Horizontal on narrow layouts, vertical on wide. */\nexport class SealpixelToolbar extends LitElement {\n static override styles = [\n base,\n css`\n :host {\n display: flex;\n padding: 4px;\n background: var(--sealpixel-color-surface);\n border-top: 1px solid var(--sealpixel-color-border);\n overflow: auto;\n scrollbar-width: thin;\n /* Arrow keys move the roving tabindex; the scroll follows it smoothly. */\n scroll-behavior: smooth;\n }\n .tools {\n display: flex;\n gap: 4px;\n /* Centres when it fits, scrolls from the first button when it does not. */\n margin: auto;\n }\n :host([orientation='vertical']) {\n border-top: none;\n border-right: 1px solid var(--sealpixel-color-border);\n /* The rail has a fixed width: a long label truncates, it never scrolls sideways. */\n overflow-x: hidden;\n }\n :host([orientation='vertical']) .tools {\n flex-direction: column;\n margin: 0;\n width: 100%;\n min-width: 0;\n }\n :host([orientation='vertical']) button {\n width: 100%;\n min-width: 0;\n }\n /* A long label (German, for example) must not widen the horizontal bar. */\n :host(:not([orientation='vertical'])) button {\n max-inline-size: var(--sealpixel-toolbar-label-max, 88px);\n }\n button {\n min-width: var(--sealpixel-touch-target);\n min-height: calc(var(--sealpixel-touch-target) + 10px);\n border: 1px solid transparent;\n border-radius: var(--sealpixel-radius);\n background: transparent;\n color: var(--sealpixel-color-fg-muted);\n font: inherit;\n font-size: calc(var(--sealpixel-font-size) * 11 / 14);\n font-weight: 500;\n letter-spacing: 0.01em;\n cursor: pointer;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: 4px;\n padding: 6px 4px;\n max-width: 100%;\n transition:\n background var(--sealpixel-transition),\n color var(--sealpixel-transition);\n }\n button:hover {\n color: var(--sealpixel-color-fg);\n background: var(--sealpixel-color-surface-2);\n }\n button[aria-pressed='true'] {\n color: var(--sealpixel-color-accent);\n background: var(--sealpixel-color-accent-soft, var(--sealpixel-color-surface-2));\n }\n .icon {\n font-size: calc(var(--sealpixel-font-size) * 20 / 14);\n line-height: 1;\n width: 28px;\n height: 28px;\n display: grid;\n place-items: center;\n border-radius: 8px;\n /*\n * The filled pill is the one element that says which tool is open, so\n * it is the one that earns a spring. Colour and shadow ride the\n * standard curve underneath, otherwise the overshoot shows up as a\n * flash of accent at the edges.\n */\n transition:\n transform var(--sealpixel-duration) var(--sealpixel-ease-spring),\n background var(--sealpixel-duration) var(--sealpixel-ease),\n color var(--sealpixel-duration) var(--sealpixel-ease),\n box-shadow var(--sealpixel-duration) var(--sealpixel-ease);\n }\n button:hover .icon {\n transform: translateY(-1px);\n }\n button[aria-pressed='true'] .icon {\n background: var(--sealpixel-color-accent);\n color: var(--sealpixel-color-accent-fg);\n box-shadow: var(--sealpixel-shadow-sm, none);\n transform: none;\n }\n button:active .icon {\n transform: scale(0.92);\n transition-duration: var(--sealpixel-duration-fast);\n }\n .label {\n /*\n * A block as wide as the button, so the ellipsis applies in every\n * engine. It must not shrink: a flex item with overflow hidden may\n * collapse in the column and cut the descenders. The line height stays\n * inherited, because the host page sets it and the panel measures it.\n */\n display: block;\n box-sizing: border-box;\n width: 100%;\n flex: none;\n min-width: 0;\n max-width: 100%;\n text-align: center;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n /* A count over the icon's corner, notification style. Hidden at zero. */\n .icon-wrap {\n position: relative;\n }\n .badge {\n position: absolute;\n top: -6px;\n right: -10px;\n min-width: 16px;\n height: 16px;\n padding: 0 4px;\n box-sizing: border-box;\n border-radius: 999px;\n background: var(--sealpixel-color-accent);\n color: var(--sealpixel-color-accent-fg);\n font-size: calc(var(--sealpixel-font-size) * 10 / 14);\n line-height: 16px;\n font-weight: 600;\n font-variant-numeric: tabular-nums;\n text-align: center;\n pointer-events: none;\n }\n .sr-only {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip: rect(0 0 0 0);\n white-space: nowrap;\n }\n `,\n ];\n\n static override properties = {\n tools: { attribute: false },\n badges: { attribute: false },\n active: { type: String },\n orientation: { type: String, reflect: true },\n t: { attribute: false },\n };\n\n declare tools: UiTool[];\n /** Counts by tool id, shown as a bubble on the button; a missing or zero entry shows nothing. */\n declare badges: Record<string, number>;\n declare active: string | null;\n declare orientation: 'horizontal' | 'vertical';\n declare t: (key: string, params?: Record<string, string | number>) => string;\n\n constructor() {\n super();\n this.tools = [];\n this.badges = {};\n this.active = null;\n this.orientation = 'horizontal';\n this.t = (k) => k;\n }\n\n override render() {\n return html`<div class=\"tools\" role=\"toolbar\" aria-orientation=${this.orientation} @keydown=${this.onKeydown}>\n ${this.tools.map(\n (tool, i) => html`<button\n part=\"tool\"\n type=\"button\"\n data-tool=${tool.id}\n title=${this.t(tool.label)}\n aria-pressed=${this.active === tool.id ? 'true' : 'false'}\n tabindex=${this.active === tool.id || (this.active === null && i === 0) ? 0 : -1}\n @click=${() => this.select(tool.id)}\n >\n <span class=\"icon-wrap\">\n <span class=\"icon\" aria-hidden=\"true\">${tool.icon}</span>\n ${\n this.badges[tool.id]\n ? html`<span part=\"badge\" class=\"badge\" aria-hidden=\"true\">${(this.badges[tool.id] as number) > 99 ? '99+' : this.badges[tool.id]}</span>\n <span class=\"sr-only\">${this.t('tool.badge', { count: this.badges[tool.id] as number })}</span>`\n : nothing\n }\n </span>\n <span class=\"label\">${this.t(tool.label)}</span>\n </button>`,\n )}\n </div>`;\n }\n\n private select(id: string): void {\n this.dispatchEvent(\n new CustomEvent('tool-select', { detail: id, bubbles: true, composed: true }),\n );\n }\n\n private onKeydown = (e: KeyboardEvent) => {\n const keys =\n this.orientation === 'vertical' ? ['ArrowUp', 'ArrowDown'] : ['ArrowLeft', 'ArrowRight'];\n const dir = e.key === keys[0] ? -1 : e.key === keys[1] ? 1 : 0;\n if (dir === 0) return;\n e.preventDefault();\n const idx = Math.max(\n 0,\n this.tools.findIndex((t) => t.id === this.active),\n );\n const next = this.tools[(idx + dir + this.tools.length) % this.tools.length];\n if (next) {\n this.select(next.id);\n this.updateComplete.then(() =>\n (this.renderRoot.querySelector(`[data-tool=\"${next.id}\"]`) as HTMLElement | null)?.focus(),\n );\n }\n };\n}\n"]}
|
|
@@ -44,6 +44,18 @@ export declare function insideImage(rect: Rect, angle: number, image: Size, marg
|
|
|
44
44
|
* that starts outside is not held back: the user has to be able to bring it in.
|
|
45
45
|
*/
|
|
46
46
|
export declare function constrainDrag(apply: (dx: number, dy: number) => Rect, dx: number, dy: number, angle: number, image: Size, margin?: number): Rect;
|
|
47
|
+
/**
|
|
48
|
+
* The rotation in degrees split into whole quarter turns and the straightening
|
|
49
|
+
* that remains, which lies within ±45°. The slider shows the straightening
|
|
50
|
+
* only; the ±90° buttons own the quarters. Exactly ±45° belongs to two splits
|
|
51
|
+
* (a quarter less and +45°, or a quarter more and −45°), so `shown`, the
|
|
52
|
+
* straightening the slider showed last, breaks the tie: the slider stays at
|
|
53
|
+
* the end the user put it on instead of jumping to the other.
|
|
54
|
+
*/
|
|
55
|
+
export declare function splitDegrees(deg: number, shown?: number): {
|
|
56
|
+
quarters: number;
|
|
57
|
+
fine: number;
|
|
58
|
+
};
|
|
47
59
|
/**
|
|
48
60
|
* A quarter turn of the crop with the image. `dir` is +1 for clockwise. The
|
|
49
61
|
* box's normalised coordinates turn with it: clockwise, a point (u, v)
|
|
@@ -84,6 +84,25 @@ export function constrainDrag(apply, dx, dy, angle, image, margin = 1) {
|
|
|
84
84
|
? apply((t + alongX * (1 - t)) * dx, t * dy)
|
|
85
85
|
: apply(t * dx, (t + alongY * (1 - t)) * dy);
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* The rotation in degrees split into whole quarter turns and the straightening
|
|
89
|
+
* that remains, which lies within ±45°. The slider shows the straightening
|
|
90
|
+
* only; the ±90° buttons own the quarters. Exactly ±45° belongs to two splits
|
|
91
|
+
* (a quarter less and +45°, or a quarter more and −45°), so `shown`, the
|
|
92
|
+
* straightening the slider showed last, breaks the tie: the slider stays at
|
|
93
|
+
* the end the user put it on instead of jumping to the other.
|
|
94
|
+
*/
|
|
95
|
+
export function splitDegrees(deg, shown = 0) {
|
|
96
|
+
let quarters = Math.round(deg / 90);
|
|
97
|
+
let fine = deg - quarters * 90;
|
|
98
|
+
const atEnd = Math.abs(Math.abs(fine) - 45) < 1e-9;
|
|
99
|
+
if (atEnd && shown !== 0 && Math.sign(fine) !== Math.sign(shown)) {
|
|
100
|
+
fine = -fine;
|
|
101
|
+
quarters -= Math.sign(fine);
|
|
102
|
+
}
|
|
103
|
+
// `Math.round` of a small negative is −0; the sign carries nothing here.
|
|
104
|
+
return { quarters: quarters + 0, fine };
|
|
105
|
+
}
|
|
87
106
|
/**
|
|
88
107
|
* A quarter turn of the crop with the image. `dir` is +1 for clockwise. The
|
|
89
108
|
* box's normalised coordinates turn with it: clockwise, a point (u, v)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crop-rotation.js","sourceRoot":"","sources":["../../src/tools/crop-rotation.ts"],"names":[],"mappings":"AAyBA,4EAA4E;AAC5E,MAAM,UAAU,UAAU,CAAC,IAAU,EAAE,KAAa;IAClD,MAAM,CAAC,GAAG,I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AAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;AAChG,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":["/**\n * What the crop rectangle does when the angle changes.\n *\n * The crop rect is normalised to the bounding box of the *rotated* image, not\n * to the image (the core sizes the output as rect × rotated box). Left alone,\n * a rect therefore covers more pixels the further the image is turned, and a\n * rect that touches the box's edge takes in area outside the turned image.\n * The two functions here decide the rect a change of angle should write, so\n * the log still gets a plain `crop.set` with `rect` and `rotation`:\n *\n * - `straighten`: the slider. The frame stays where it is on the stage and\n * keeps its size in pixels while the image turns behind it; then it shrinks\n * about its centre, aspect kept, until every corner is inside the image.\n * - `quarterTurn`: the ±90° buttons. The crop turns with the image, so the\n * output is the previous output turned by a quarter.\n *\n * Positive angles turn clockwise on screen, as the core and CSS `rotate()` do.\n */\nimport type { Rect } from '@sealpixel/core';\n\nexport interface Size {\n width: number;\n height: number;\n}\n\n/** Bounding box of `size` rotated by `angle` radians, in the same units. */\nexport function rotatedBox(size: Size, angle: number): Size {\n const s = Math.abs(Math.sin(angle));\n const c = Math.abs(Math.cos(angle));\n return { width: size.width * c + size.height * s, height: size.width * s + size.height * c };\n}\n\n/**\n * The rect for a new angle: same frame on the stage, same size in pixels,\n * then — with `constrain` — fitted inside the turned image. `image` is the\n * source size in pixels; `margin` keeps the frame that far inside the image\n * edge, in pixels, so the anti-aliased border of the turned image never\n * enters the output.\n */\nexport function straighten(\n rect: Rect,\n from: number,\n to: number,\n image: Size,\n constrain = true,\n margin = 1,\n): Rect {\n const b0 = rotatedBox(image, from);\n const b1 = rotatedBox(image, to);\n // The frame in pixels: size, and centre offset from the box centre, which\n // is the image centre in both boxes.\n const pw = rect.width * b0.width;\n const ph = rect.height * b0.height;\n const ox = (rect.x + rect.width / 2) * b0.width - b0.width / 2;\n const oy = (rect.y + rect.height / 2) * b0.height - b0.height / 2;\n const frame = { x: ox, y: oy, width: pw, height: ph };\n const fitted = constrain ? fitInside(frame, to, image, margin) : frame;\n return {\n x: (b1.width / 2 + fitted.x - fitted.width / 2) / b1.width,\n y: (b1.height / 2 + fitted.y - fitted.height / 2) / b1.height,\n width: fitted.width / b1.width,\n height: fitted.height / b1.height,\n };\n}\n\n/**\n * True when every corner of `rect` (normalised to the box of the image turned\n * by `angle`) lies inside the turned image, `margin` pixels in.\n */\nexport function insideImage(rect: Rect, angle: number, image: Size, margin = 1): boolean {\n const b = rotatedBox(image, angle);\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n const lx = image.width / 2 - margin;\n const ly = image.height / 2 - margin;\n for (const [u, v] of [\n [rect.x, rect.y],\n [rect.x + rect.width, rect.y],\n [rect.x, rect.y + rect.height],\n [rect.x + rect.width, rect.y + rect.height],\n ]) {\n const x = (u as number) * b.width - b.width / 2;\n const y = (v as number) * b.height - b.height / 2;\n if (Math.abs(x * cos + y * sin) > lx + 1e-9 || Math.abs(-x * sin + y * cos) > ly + 1e-9)\n return false;\n }\n return true;\n}\n\n/**\n * A drag that cannot take the frame out of the turned image. `apply` maps a\n * delta to the rect a free drag would give. The largest share of the delta\n * that stays inside is taken; from there each axis is extended on its own, so\n * the frame slides along the image edge instead of sticking to it. A frame\n * that starts outside is not held back: the user has to be able to bring it in.\n */\nexport function constrainDrag(\n apply: (dx: number, dy: number) => Rect,\n dx: number,\n dy: number,\n angle: number,\n image: Size,\n margin = 1,\n): Rect {\n const ok = (r: Rect) => insideImage(r, angle, image, margin);\n const full = apply(dx, dy);\n if (ok(full) || !ok(apply(0, 0))) return full;\n // The largest t in [0, 1] for which f(t) is inside; f(0) is.\n const largest = (f: (t: number) => Rect) => {\n let lo = 0;\n let hi = 1;\n for (let i = 0; i < 16; i++) {\n const mid = (lo + hi) / 2;\n if (ok(f(mid))) lo = mid;\n else hi = mid;\n }\n return lo;\n };\n const t = largest((s) => apply(s * dx, s * dy));\n const alongX = largest((s) => apply((t + s * (1 - t)) * dx, t * dy));\n const alongY = largest((s) => apply(t * dx, (t + s * (1 - t)) * dy));\n return alongX >= alongY\n ? apply((t + alongX * (1 - t)) * dx, t * dy)\n : apply(t * dx, (t + alongY * (1 - t)) * dy);\n}\n\n/**\n * A quarter turn of the crop with the image. `dir` is +1 for clockwise. The\n * box's normalised coordinates turn with it: clockwise, a point (u, v)\n * becomes (1 − v, u).\n */\nexport function quarterTurn(rect: Rect, dir: 1 | -1): Rect {\n return dir === 1\n ? { x: 1 - (rect.y + rect.height), y: rect.x, width: rect.height, height: rect.width }\n : { x: rect.y, y: 1 - (rect.x + rect.width), width: rect.height, height: rect.width };\n}\n\n/**\n * A frame given as centre offset from the image centre and size, all in\n * pixels, moved and shrunk about its centre until it lies inside the image\n * turned by `angle`. Solved in the image's own frame: the four corners are\n * turned back by −angle and have to fall within ±width/2 and ±height/2.\n */\nfunction fitInside(\n frame: { x: number; y: number; width: number; height: number },\n angle: number,\n image: Size,\n margin: number,\n): { x: number; y: number; width: number; height: number } {\n const lx = Math.max(0, image.width / 2 - margin);\n const ly = Math.max(0, image.height / 2 - margin);\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n // Turn a screen offset back into the unturned image's frame.\n const back = (x: number, y: number) => ({ x: x * cos + y * sin, y: -x * sin + y * cos });\n const forth = (x: number, y: number) => ({ x: x * cos - y * sin, y: x * sin + y * cos });\n\n const hw = frame.width / 2;\n const hh = frame.height / 2;\n\n // The centre first. Inside the image, it stays and only the size gives —\n // the frame shrinks in place. Outside, no scale helps: the frame moves in\n // to where it fits whole, which is the image less the frame's own extent\n // in the image's frame.\n let a = back(frame.x, frame.y);\n if (Math.abs(a.x) > lx || Math.abs(a.y) > ly) {\n const ex = Math.abs(hw * cos) + Math.abs(hh * sin);\n const ey = Math.abs(hw * sin) + Math.abs(hh * cos);\n a = {\n x: clamp(a.x, -Math.max(0, lx - ex), Math.max(0, lx - ex)),\n y: clamp(a.y, -Math.max(0, ly - ey), Math.max(0, ly - ey)),\n };\n }\n const centre = forth(a.x, a.y);\n\n // Then the largest scale of the frame about that centre that keeps every\n // corner inside: each corner and axis is one linear bound on the scale.\n let scale = 1;\n for (const [sx, sy] of [\n [1, 1],\n [1, -1],\n [-1, 1],\n [-1, -1],\n ] as const) {\n const b = back(sx * hw, sy * hh);\n for (const [pos, off, limit] of [\n [a.x, b.x, lx],\n [a.y, b.y, ly],\n ] as const) {\n if (off > 1e-12) scale = Math.min(scale, (limit - pos) / off);\n else if (off < -1e-12) scale = Math.min(scale, (-limit - pos) / off);\n }\n }\n scale = Math.max(0, scale);\n return { x: centre.x, y: centre.y, width: frame.width * scale, height: frame.height * scale };\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-rotation.js","sourceRoot":"","sources":["../../src/tools/crop-rotation.ts"],"names":[],"mappings":"AAyBA,4EAA4E;AAC5E,MAAM,UAAU,UAAU,CAAC,IAAU,EAAE,KAAa;IAClD,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IACpC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IACpC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAA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AC,KAAK,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;iBACzD,IAAI,GAAG,GAAG,CAAC,KAAK;gBAAE,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IACD,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC3B,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;AAChG,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":["/**\n * What the crop rectangle does when the angle changes.\n *\n * The crop rect is normalised to the bounding box of the *rotated* image, not\n * to the image (the core sizes the output as rect × rotated box). Left alone,\n * a rect therefore covers more pixels the further the image is turned, and a\n * rect that touches the box's edge takes in area outside the turned image.\n * The two functions here decide the rect a change of angle should write, so\n * the log still gets a plain `crop.set` with `rect` and `rotation`:\n *\n * - `straighten`: the slider. The frame stays where it is on the stage and\n * keeps its size in pixels while the image turns behind it; then it shrinks\n * about its centre, aspect kept, until every corner is inside the image.\n * - `quarterTurn`: the ±90° buttons. The crop turns with the image, so the\n * output is the previous output turned by a quarter.\n *\n * Positive angles turn clockwise on screen, as the core and CSS `rotate()` do.\n */\nimport type { Rect } from '@sealpixel/core';\n\nexport interface Size {\n width: number;\n height: number;\n}\n\n/** Bounding box of `size` rotated by `angle` radians, in the same units. */\nexport function rotatedBox(size: Size, angle: number): Size {\n const s = Math.abs(Math.sin(angle));\n const c = Math.abs(Math.cos(angle));\n return { width: size.width * c + size.height * s, height: size.width * s + size.height * c };\n}\n\n/**\n * The rect for a new angle: same frame on the stage, same size in pixels,\n * then — with `constrain` — fitted inside the turned image. `image` is the\n * source size in pixels; `margin` keeps the frame that far inside the image\n * edge, in pixels, so the anti-aliased border of the turned image never\n * enters the output.\n */\nexport function straighten(\n rect: Rect,\n from: number,\n to: number,\n image: Size,\n constrain = true,\n margin = 1,\n): Rect {\n const b0 = rotatedBox(image, from);\n const b1 = rotatedBox(image, to);\n // The frame in pixels: size, and centre offset from the box centre, which\n // is the image centre in both boxes.\n const pw = rect.width * b0.width;\n const ph = rect.height * b0.height;\n const ox = (rect.x + rect.width / 2) * b0.width - b0.width / 2;\n const oy = (rect.y + rect.height / 2) * b0.height - b0.height / 2;\n const frame = { x: ox, y: oy, width: pw, height: ph };\n const fitted = constrain ? fitInside(frame, to, image, margin) : frame;\n return {\n x: (b1.width / 2 + fitted.x - fitted.width / 2) / b1.width,\n y: (b1.height / 2 + fitted.y - fitted.height / 2) / b1.height,\n width: fitted.width / b1.width,\n height: fitted.height / b1.height,\n };\n}\n\n/**\n * True when every corner of `rect` (normalised to the box of the image turned\n * by `angle`) lies inside the turned image, `margin` pixels in.\n */\nexport function insideImage(rect: Rect, angle: number, image: Size, margin = 1): boolean {\n const b = rotatedBox(image, angle);\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n const lx = image.width / 2 - margin;\n const ly = image.height / 2 - margin;\n for (const [u, v] of [\n [rect.x, rect.y],\n [rect.x + rect.width, rect.y],\n [rect.x, rect.y + rect.height],\n [rect.x + rect.width, rect.y + rect.height],\n ]) {\n const x = (u as number) * b.width - b.width / 2;\n const y = (v as number) * b.height - b.height / 2;\n if (Math.abs(x * cos + y * sin) > lx + 1e-9 || Math.abs(-x * sin + y * cos) > ly + 1e-9)\n return false;\n }\n return true;\n}\n\n/**\n * A drag that cannot take the frame out of the turned image. `apply` maps a\n * delta to the rect a free drag would give. The largest share of the delta\n * that stays inside is taken; from there each axis is extended on its own, so\n * the frame slides along the image edge instead of sticking to it. A frame\n * that starts outside is not held back: the user has to be able to bring it in.\n */\nexport function constrainDrag(\n apply: (dx: number, dy: number) => Rect,\n dx: number,\n dy: number,\n angle: number,\n image: Size,\n margin = 1,\n): Rect {\n const ok = (r: Rect) => insideImage(r, angle, image, margin);\n const full = apply(dx, dy);\n if (ok(full) || !ok(apply(0, 0))) return full;\n // The largest t in [0, 1] for which f(t) is inside; f(0) is.\n const largest = (f: (t: number) => Rect) => {\n let lo = 0;\n let hi = 1;\n for (let i = 0; i < 16; i++) {\n const mid = (lo + hi) / 2;\n if (ok(f(mid))) lo = mid;\n else hi = mid;\n }\n return lo;\n };\n const t = largest((s) => apply(s * dx, s * dy));\n const alongX = largest((s) => apply((t + s * (1 - t)) * dx, t * dy));\n const alongY = largest((s) => apply(t * dx, (t + s * (1 - t)) * dy));\n return alongX >= alongY\n ? apply((t + alongX * (1 - t)) * dx, t * dy)\n : apply(t * dx, (t + alongY * (1 - t)) * dy);\n}\n\n/**\n * The rotation in degrees split into whole quarter turns and the straightening\n * that remains, which lies within ±45°. The slider shows the straightening\n * only; the ±90° buttons own the quarters. Exactly ±45° belongs to two splits\n * (a quarter less and +45°, or a quarter more and −45°), so `shown`, the\n * straightening the slider showed last, breaks the tie: the slider stays at\n * the end the user put it on instead of jumping to the other.\n */\nexport function splitDegrees(deg: number, shown = 0): { quarters: number; fine: number } {\n let quarters = Math.round(deg / 90);\n let fine = deg - quarters * 90;\n const atEnd = Math.abs(Math.abs(fine) - 45) < 1e-9;\n if (atEnd && shown !== 0 && Math.sign(fine) !== Math.sign(shown)) {\n fine = -fine;\n quarters -= Math.sign(fine);\n }\n // `Math.round` of a small negative is −0; the sign carries nothing here.\n return { quarters: quarters + 0, fine };\n}\n\n/**\n * A quarter turn of the crop with the image. `dir` is +1 for clockwise. The\n * box's normalised coordinates turn with it: clockwise, a point (u, v)\n * becomes (1 − v, u).\n */\nexport function quarterTurn(rect: Rect, dir: 1 | -1): Rect {\n return dir === 1\n ? { x: 1 - (rect.y + rect.height), y: rect.x, width: rect.height, height: rect.width }\n : { x: rect.y, y: 1 - (rect.x + rect.width), width: rect.height, height: rect.width };\n}\n\n/**\n * A frame given as centre offset from the image centre and size, all in\n * pixels, moved and shrunk about its centre until it lies inside the image\n * turned by `angle`. Solved in the image's own frame: the four corners are\n * turned back by −angle and have to fall within ±width/2 and ±height/2.\n */\nfunction fitInside(\n frame: { x: number; y: number; width: number; height: number },\n angle: number,\n image: Size,\n margin: number,\n): { x: number; y: number; width: number; height: number } {\n const lx = Math.max(0, image.width / 2 - margin);\n const ly = Math.max(0, image.height / 2 - margin);\n const cos = Math.cos(angle);\n const sin = Math.sin(angle);\n // Turn a screen offset back into the unturned image's frame.\n const back = (x: number, y: number) => ({ x: x * cos + y * sin, y: -x * sin + y * cos });\n const forth = (x: number, y: number) => ({ x: x * cos - y * sin, y: x * sin + y * cos });\n\n const hw = frame.width / 2;\n const hh = frame.height / 2;\n\n // The centre first. Inside the image, it stays and only the size gives —\n // the frame shrinks in place. Outside, no scale helps: the frame moves in\n // to where it fits whole, which is the image less the frame's own extent\n // in the image's frame.\n let a = back(frame.x, frame.y);\n if (Math.abs(a.x) > lx || Math.abs(a.y) > ly) {\n const ex = Math.abs(hw * cos) + Math.abs(hh * sin);\n const ey = Math.abs(hw * sin) + Math.abs(hh * cos);\n a = {\n x: clamp(a.x, -Math.max(0, lx - ex), Math.max(0, lx - ex)),\n y: clamp(a.y, -Math.max(0, ly - ey), Math.max(0, ly - ey)),\n };\n }\n const centre = forth(a.x, a.y);\n\n // Then the largest scale of the frame about that centre that keeps every\n // corner inside: each corner and axis is one linear bound on the scale.\n let scale = 1;\n for (const [sx, sy] of [\n [1, 1],\n [1, -1],\n [-1, 1],\n [-1, -1],\n ] as const) {\n const b = back(sx * hw, sy * hh);\n for (const [pos, off, limit] of [\n [a.x, b.x, lx],\n [a.y, b.y, ly],\n ] as const) {\n if (off > 1e-12) scale = Math.min(scale, (limit - pos) / off);\n else if (off < -1e-12) scale = Math.min(scale, (-limit - pos) / off);\n }\n }\n scale = Math.max(0, scale);\n return { x: centre.x, y: centre.y, width: frame.width * scale, height: frame.height * scale };\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/crop.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CROP_DEFAULT_OPTIONS, ORIGINAL_ASPECT } from '@sealpixel/plugins';
|
|
2
2
|
import { html, nothing, svg } from 'lit';
|
|
3
3
|
import { icons } from '../icons.js';
|
|
4
|
-
import { constrainDrag, quarterTurn, straighten } from './crop-rotation.js';
|
|
4
|
+
import { constrainDrag, quarterTurn, splitDegrees, straighten } from './crop-rotation.js';
|
|
5
5
|
import { opId } from './finetune.js';
|
|
6
6
|
/**
|
|
7
7
|
* While the crop tool is active the preview shows the whole rotated image
|
|
@@ -38,6 +38,12 @@ const drag = {
|
|
|
38
38
|
* nobody waits for it.
|
|
39
39
|
*/
|
|
40
40
|
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;
|
|
41
47
|
/**
|
|
42
48
|
* The crop is written to the log the moment a handle is released, but the
|
|
43
49
|
* stage keeps showing the whole image, because a corner cannot be pulled
|
|
@@ -133,7 +139,10 @@ export const cropTool = {
|
|
|
133
139
|
},
|
|
134
140
|
panel: (ctx) => {
|
|
135
141
|
const doc = ctx.document.crop;
|
|
136
|
-
|
|
142
|
+
// The slider straightens within ±45°; the quarter turns stay with the
|
|
143
|
+
// ±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;
|
|
137
146
|
// A rotation, a flip or an aspect ratio is a change like a drag is: it
|
|
138
147
|
// leaves the settled view first, so the surroundings are there to see what
|
|
139
148
|
// swings into the frame, and settles into the result the same way after.
|
|
@@ -195,19 +204,20 @@ export const cropTool = {
|
|
|
195
204
|
? html `<sealpixel-slider
|
|
196
205
|
data-param="rotation"
|
|
197
206
|
.label=${ctx.t('crop.rotation')}
|
|
198
|
-
.value=${Number(
|
|
199
|
-
.min=${-
|
|
200
|
-
.max=${
|
|
207
|
+
.value=${Number(fine.toFixed(2))}
|
|
208
|
+
.min=${-45}
|
|
209
|
+
.max=${45}
|
|
201
210
|
.step=${options.rotationStep}
|
|
202
211
|
.format=${(v) => `${v.toFixed(1)}°`}
|
|
203
212
|
@slide=${(e) => {
|
|
204
213
|
// The first movement opens the surround; set() only runs on commit,
|
|
205
214
|
// which is after the gesture, and the aiming is what needs the view.
|
|
206
215
|
unsettle(ctx);
|
|
207
|
-
ctx.hint({ rotate: (e.detail * Math.PI) / 180
|
|
216
|
+
ctx.hint({ rotate: ((e.detail - fine) * Math.PI) / 180 });
|
|
208
217
|
}}
|
|
209
218
|
@commit=${(e) => {
|
|
210
|
-
|
|
219
|
+
shownFine = e.detail;
|
|
220
|
+
const rotation = ((quarters * 90 + e.detail) * Math.PI) / 180;
|
|
211
221
|
// The frame stays where it is and keeps its size; the image turns
|
|
212
222
|
// behind it. See crop-rotation.ts for why the rect has to move.
|
|
213
223
|
set({
|
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,MA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AAC,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, 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 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 const deg = (doc.rotation * 180) / Math.PI;\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(deg.toFixed(2))}\n .min=${-180}\n .max=${180}\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 * Math.PI) / 180 - doc.rotation });\n }}\n @commit=${(e: CustomEvent<number>) => {\n const rotation = (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;AAarC;;;;;GAKG;AACH,SAAS,YAAY,CAAC,GAAY;IAChC,OAAO;QACL,GAAG,GAAG;QACN,GAAG,EAAE;YACH,GAAG,GAAG,CAAC,GAAG;YACV;gBACE,IAAI,EAAE,UAAU;gBAChB,EAAE,EAAE,4BAA4B;gBAChC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;gBACzC,gFAAgF;gBAChF,IAAI,EAAE,MAAM;aACb;YACD,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,E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AC,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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealpixel/ui",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.18",
|
|
4
4
|
"description": "Default, themeable Sealpixel editor UI as Web Components (Lit). Optional: the core is headless.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"repository": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@sealpixel/core": "1.0.0-rc.15",
|
|
40
|
-
"@sealpixel/plugins": "1.0.0-rc.
|
|
40
|
+
"@sealpixel/plugins": "1.0.0-rc.18",
|
|
41
41
|
"lit": "^3.3.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|