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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/LICENSE.md +2 -2
  2. package/README.md +1 -1
  3. package/dist/components/sealpixel-button.d.ts +0 -1
  4. package/dist/components/sealpixel-button.js +1 -1
  5. package/dist/components/sealpixel-button.js.map +1 -1
  6. package/dist/components/sealpixel-editor.d.ts +71 -20
  7. package/dist/components/sealpixel-editor.js +265 -57
  8. package/dist/components/sealpixel-editor.js.map +1 -1
  9. package/dist/components/sealpixel-nav.d.ts +0 -1
  10. package/dist/components/sealpixel-nav.js +1 -1
  11. package/dist/components/sealpixel-nav.js.map +1 -1
  12. package/dist/components/sealpixel-slider.d.ts +12 -17
  13. package/dist/components/sealpixel-slider.js +64 -10
  14. package/dist/components/sealpixel-slider.js.map +1 -1
  15. package/dist/components/sealpixel-stage.d.ts +17 -1
  16. package/dist/components/sealpixel-stage.js +57 -6
  17. package/dist/components/sealpixel-stage.js.map +1 -1
  18. package/dist/components/sealpixel-stepper.d.ts +0 -1
  19. package/dist/components/sealpixel-stepper.js +4 -4
  20. package/dist/components/sealpixel-stepper.js.map +1 -1
  21. package/dist/components/sealpixel-toolbar.d.ts +6 -2
  22. package/dist/components/sealpixel-toolbar.js +71 -5
  23. package/dist/components/sealpixel-toolbar.js.map +1 -1
  24. package/dist/controllers/gesture-controller.d.ts +5 -1
  25. package/dist/controllers/gesture-controller.js +24 -4
  26. package/dist/controllers/gesture-controller.js.map +1 -1
  27. package/dist/controllers/session-controller.d.ts +0 -1
  28. package/dist/controllers/session-controller.js +2 -0
  29. package/dist/controllers/session-controller.js.map +1 -1
  30. package/dist/define.d.ts +0 -1
  31. package/dist/define.js.map +1 -1
  32. package/dist/i18n.d.ts +0 -1
  33. package/dist/i18n.js.map +1 -1
  34. package/dist/icons.d.ts +1 -1
  35. package/dist/icons.js +1 -0
  36. package/dist/icons.js.map +1 -1
  37. package/dist/index.d.ts +1 -2
  38. package/dist/index.js +1 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/locales/de.d.ts +0 -1
  41. package/dist/locales/de.js +22 -0
  42. package/dist/locales/de.js.map +1 -1
  43. package/dist/locales/en.d.ts +0 -1
  44. package/dist/locales/en.js +22 -0
  45. package/dist/locales/en.js.map +1 -1
  46. package/dist/locales/es.d.ts +0 -1
  47. package/dist/locales/es.js +22 -0
  48. package/dist/locales/es.js.map +1 -1
  49. package/dist/locales/fr.d.ts +0 -1
  50. package/dist/locales/fr.js +22 -0
  51. package/dist/locales/fr.js.map +1 -1
  52. package/dist/locales/index.d.ts +0 -1
  53. package/dist/locales/index.js.map +1 -1
  54. package/dist/locales/ja.d.ts +0 -1
  55. package/dist/locales/ja.js +22 -0
  56. package/dist/locales/ja.js.map +1 -1
  57. package/dist/locales/pt.d.ts +0 -1
  58. package/dist/locales/pt.js +22 -0
  59. package/dist/locales/pt.js.map +1 -1
  60. package/dist/theme.d.ts +0 -1
  61. package/dist/theme.js.map +1 -1
  62. package/dist/tool.d.ts +12 -1
  63. package/dist/tool.js.map +1 -1
  64. package/dist/tools/annotate.d.ts +0 -1
  65. package/dist/tools/annotate.js +277 -28
  66. package/dist/tools/annotate.js.map +1 -1
  67. package/dist/tools/assist.d.ts +103 -0
  68. package/dist/tools/assist.js +361 -0
  69. package/dist/tools/assist.js.map +1 -0
  70. package/dist/tools/crop-mask.d.ts +0 -1
  71. package/dist/tools/crop-mask.js.map +1 -1
  72. package/dist/tools/crop-rotation.d.ts +64 -0
  73. package/dist/tools/crop-rotation.js +172 -0
  74. package/dist/tools/crop-rotation.js.map +1 -0
  75. package/dist/tools/crop.d.ts +0 -1
  76. package/dist/tools/crop.js +99 -15
  77. package/dist/tools/crop.js.map +1 -1
  78. package/dist/tools/delete-handle.d.ts +0 -1
  79. package/dist/tools/delete-handle.js +6 -0
  80. package/dist/tools/delete-handle.js.map +1 -1
  81. package/dist/tools/filter.d.ts +0 -1
  82. package/dist/tools/filter.js.map +1 -1
  83. package/dist/tools/finetune.d.ts +0 -1
  84. package/dist/tools/finetune.js.map +1 -1
  85. package/dist/tools/frame.d.ts +0 -1
  86. package/dist/tools/frame.js.map +1 -1
  87. package/dist/tools/handles.d.ts +26 -0
  88. package/dist/tools/handles.js +51 -0
  89. package/dist/tools/handles.js.map +1 -0
  90. package/dist/tools/index.d.ts +2 -2
  91. package/dist/tools/index.js +3 -1
  92. package/dist/tools/index.js.map +1 -1
  93. package/dist/tools/keys.d.ts +59 -0
  94. package/dist/tools/keys.js +120 -0
  95. package/dist/tools/keys.js.map +1 -0
  96. package/dist/tools/redact.d.ts +10 -1
  97. package/dist/tools/redact.js +176 -12
  98. package/dist/tools/redact.js.map +1 -1
  99. package/dist/tools/region-transform.d.ts +69 -0
  100. package/dist/tools/region-transform.js +192 -0
  101. package/dist/tools/region-transform.js.map +1 -0
  102. package/dist/tools/resize.d.ts +0 -1
  103. package/dist/tools/resize.js +19 -6
  104. package/dist/tools/resize.js.map +1 -1
  105. package/dist/tools/sticker.d.ts +0 -1
  106. package/dist/tools/sticker.js +57 -2
  107. package/dist/tools/sticker.js.map +1 -1
  108. package/dist/tools/watermark.d.ts +0 -1
  109. package/dist/tools/watermark.js.map +1 -1
  110. package/dist/view-mapping.d.ts +1 -2
  111. package/dist/view-mapping.js +1 -1
  112. package/dist/view-mapping.js.map +1 -1
  113. package/package.json +8 -8
  114. package/dist/components/sealpixel-button.d.ts.map +0 -1
  115. package/dist/components/sealpixel-editor.d.ts.map +0 -1
  116. package/dist/components/sealpixel-nav.d.ts.map +0 -1
  117. package/dist/components/sealpixel-slider.d.ts.map +0 -1
  118. package/dist/components/sealpixel-stage.d.ts.map +0 -1
  119. package/dist/components/sealpixel-stepper.d.ts.map +0 -1
  120. package/dist/components/sealpixel-toolbar.d.ts.map +0 -1
  121. package/dist/controllers/gesture-controller.d.ts.map +0 -1
  122. package/dist/controllers/session-controller.d.ts.map +0 -1
  123. package/dist/define.d.ts.map +0 -1
  124. package/dist/i18n.d.ts.map +0 -1
  125. package/dist/icons.d.ts.map +0 -1
  126. package/dist/index.d.ts.map +0 -1
  127. package/dist/locales/de.d.ts.map +0 -1
  128. package/dist/locales/en.d.ts.map +0 -1
  129. package/dist/locales/es.d.ts.map +0 -1
  130. package/dist/locales/fr.d.ts.map +0 -1
  131. package/dist/locales/index.d.ts.map +0 -1
  132. package/dist/locales/ja.d.ts.map +0 -1
  133. package/dist/locales/pt.d.ts.map +0 -1
  134. package/dist/theme.d.ts.map +0 -1
  135. package/dist/tool.d.ts.map +0 -1
  136. package/dist/tools/annotate.d.ts.map +0 -1
  137. package/dist/tools/crop-mask.d.ts.map +0 -1
  138. package/dist/tools/crop.d.ts.map +0 -1
  139. package/dist/tools/delete-handle.d.ts.map +0 -1
  140. package/dist/tools/filter.d.ts.map +0 -1
  141. package/dist/tools/finetune.d.ts.map +0 -1
  142. package/dist/tools/frame.d.ts.map +0 -1
  143. package/dist/tools/index.d.ts.map +0 -1
  144. package/dist/tools/redact.d.ts.map +0 -1
  145. package/dist/tools/resize.d.ts.map +0 -1
  146. package/dist/tools/sticker.d.ts.map +0 -1
  147. package/dist/tools/watermark.d.ts.map +0 -1
  148. package/dist/view-mapping.d.ts.map +0 -1
@@ -0,0 +1,172 @@
1
+ /** Bounding box of `size` rotated by `angle` radians, in the same units. */
2
+ export function rotatedBox(size, angle) {
3
+ const s = Math.abs(Math.sin(angle));
4
+ const c = Math.abs(Math.cos(angle));
5
+ return { width: size.width * c + size.height * s, height: size.width * s + size.height * c };
6
+ }
7
+ /**
8
+ * The rect for a new angle: same frame on the stage, same size in pixels,
9
+ * then — with `constrain` — fitted inside the turned image. `image` is the
10
+ * source size in pixels; `margin` keeps the frame that far inside the image
11
+ * edge, in pixels, so the anti-aliased border of the turned image never
12
+ * enters the output.
13
+ */
14
+ export function straighten(rect, from, to, image, constrain = true, margin = 1) {
15
+ const b0 = rotatedBox(image, from);
16
+ const b1 = rotatedBox(image, to);
17
+ // The frame in pixels: size, and centre offset from the box centre, which
18
+ // is the image centre in both boxes.
19
+ const pw = rect.width * b0.width;
20
+ const ph = rect.height * b0.height;
21
+ const ox = (rect.x + rect.width / 2) * b0.width - b0.width / 2;
22
+ const oy = (rect.y + rect.height / 2) * b0.height - b0.height / 2;
23
+ const frame = { x: ox, y: oy, width: pw, height: ph };
24
+ const fitted = constrain ? fitInside(frame, to, image, margin) : frame;
25
+ return {
26
+ x: (b1.width / 2 + fitted.x - fitted.width / 2) / b1.width,
27
+ y: (b1.height / 2 + fitted.y - fitted.height / 2) / b1.height,
28
+ width: fitted.width / b1.width,
29
+ height: fitted.height / b1.height,
30
+ };
31
+ }
32
+ /**
33
+ * True when every corner of `rect` (normalised to the box of the image turned
34
+ * by `angle`) lies inside the turned image, `margin` pixels in.
35
+ */
36
+ export function insideImage(rect, angle, image, margin = 1) {
37
+ const b = rotatedBox(image, angle);
38
+ const cos = Math.cos(angle);
39
+ const sin = Math.sin(angle);
40
+ const lx = image.width / 2 - margin;
41
+ const ly = image.height / 2 - margin;
42
+ for (const [u, v] of [
43
+ [rect.x, rect.y],
44
+ [rect.x + rect.width, rect.y],
45
+ [rect.x, rect.y + rect.height],
46
+ [rect.x + rect.width, rect.y + rect.height],
47
+ ]) {
48
+ const x = u * b.width - b.width / 2;
49
+ const y = v * b.height - b.height / 2;
50
+ if (Math.abs(x * cos + y * sin) > lx + 1e-9 || Math.abs(-x * sin + y * cos) > ly + 1e-9)
51
+ return false;
52
+ }
53
+ return true;
54
+ }
55
+ /**
56
+ * A drag that cannot take the frame out of the turned image. `apply` maps a
57
+ * delta to the rect a free drag would give. The largest share of the delta
58
+ * that stays inside is taken; from there each axis is extended on its own, so
59
+ * the frame slides along the image edge instead of sticking to it. A frame
60
+ * that starts outside is not held back: the user has to be able to bring it in.
61
+ */
62
+ export function constrainDrag(apply, dx, dy, angle, image, margin = 1) {
63
+ const ok = (r) => insideImage(r, angle, image, margin);
64
+ const full = apply(dx, dy);
65
+ if (ok(full) || !ok(apply(0, 0)))
66
+ return full;
67
+ // The largest t in [0, 1] for which f(t) is inside; f(0) is.
68
+ const largest = (f) => {
69
+ let lo = 0;
70
+ let hi = 1;
71
+ for (let i = 0; i < 16; i++) {
72
+ const mid = (lo + hi) / 2;
73
+ if (ok(f(mid)))
74
+ lo = mid;
75
+ else
76
+ hi = mid;
77
+ }
78
+ return lo;
79
+ };
80
+ const t = largest((s) => apply(s * dx, s * dy));
81
+ const alongX = largest((s) => apply((t + s * (1 - t)) * dx, t * dy));
82
+ const alongY = largest((s) => apply(t * dx, (t + s * (1 - t)) * dy));
83
+ return alongX >= alongY
84
+ ? apply((t + alongX * (1 - t)) * dx, t * dy)
85
+ : apply(t * dx, (t + alongY * (1 - t)) * dy);
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
+ }
106
+ /**
107
+ * A quarter turn of the crop with the image. `dir` is +1 for clockwise. The
108
+ * box's normalised coordinates turn with it: clockwise, a point (u, v)
109
+ * becomes (1 − v, u).
110
+ */
111
+ export function quarterTurn(rect, dir) {
112
+ return dir === 1
113
+ ? { x: 1 - (rect.y + rect.height), y: rect.x, width: rect.height, height: rect.width }
114
+ : { x: rect.y, y: 1 - (rect.x + rect.width), width: rect.height, height: rect.width };
115
+ }
116
+ /**
117
+ * A frame given as centre offset from the image centre and size, all in
118
+ * pixels, moved and shrunk about its centre until it lies inside the image
119
+ * turned by `angle`. Solved in the image's own frame: the four corners are
120
+ * turned back by −angle and have to fall within ±width/2 and ±height/2.
121
+ */
122
+ function fitInside(frame, angle, image, margin) {
123
+ const lx = Math.max(0, image.width / 2 - margin);
124
+ const ly = Math.max(0, image.height / 2 - margin);
125
+ const cos = Math.cos(angle);
126
+ const sin = Math.sin(angle);
127
+ // Turn a screen offset back into the unturned image's frame.
128
+ const back = (x, y) => ({ x: x * cos + y * sin, y: -x * sin + y * cos });
129
+ const forth = (x, y) => ({ x: x * cos - y * sin, y: x * sin + y * cos });
130
+ const hw = frame.width / 2;
131
+ const hh = frame.height / 2;
132
+ // The centre first. Inside the image, it stays and only the size gives —
133
+ // the frame shrinks in place. Outside, no scale helps: the frame moves in
134
+ // to where it fits whole, which is the image less the frame's own extent
135
+ // in the image's frame.
136
+ let a = back(frame.x, frame.y);
137
+ if (Math.abs(a.x) > lx || Math.abs(a.y) > ly) {
138
+ const ex = Math.abs(hw * cos) + Math.abs(hh * sin);
139
+ const ey = Math.abs(hw * sin) + Math.abs(hh * cos);
140
+ a = {
141
+ x: clamp(a.x, -Math.max(0, lx - ex), Math.max(0, lx - ex)),
142
+ y: clamp(a.y, -Math.max(0, ly - ey), Math.max(0, ly - ey)),
143
+ };
144
+ }
145
+ const centre = forth(a.x, a.y);
146
+ // Then the largest scale of the frame about that centre that keeps every
147
+ // corner inside: each corner and axis is one linear bound on the scale.
148
+ let scale = 1;
149
+ for (const [sx, sy] of [
150
+ [1, 1],
151
+ [1, -1],
152
+ [-1, 1],
153
+ [-1, -1],
154
+ ]) {
155
+ const b = back(sx * hw, sy * hh);
156
+ for (const [pos, off, limit] of [
157
+ [a.x, b.x, lx],
158
+ [a.y, b.y, ly],
159
+ ]) {
160
+ if (off > 1e-12)
161
+ scale = Math.min(scale, (limit - pos) / off);
162
+ else if (off < -1e-12)
163
+ scale = Math.min(scale, (-limit - pos) / off);
164
+ }
165
+ }
166
+ scale = Math.max(0, scale);
167
+ return { x: centre.x, y: centre.y, width: frame.width * scale, height: frame.height * scale };
168
+ }
169
+ function clamp(v, lo, hi) {
170
+ return v < lo ? lo : v > hi ? hi : v;
171
+ }
172
+ //# sourceMappingURL=crop-rotation.js.map
@@ -0,0 +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,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,EAAE,CAAC;AAC/F,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACxB,IAAU,EACV,IAAY,EACZ,EAAU,EACV,KAAW,EACX,SAAS,GAAG,IAAI,EAChB,MAAM,GAAG,CAAC;IAEV,MAAM,EAAE,GAAG,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnC,MAAM,EAAE,GAAG,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACjC,0EAA0E;IAC1E,qCAAqC;IACrC,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,KAAK,CAAC;IACjC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,GAAG,EAAE,CAA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AE,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"]}
@@ -8,4 +8,3 @@ export declare const cropTool: UiTool;
8
8
  */
9
9
  export declare function applyDrag(start: Rect, handle: Handle, dx: number, dy: number, aspect: number | null, stageAspect: number): Rect;
10
10
  export {};
11
- //# sourceMappingURL=crop.d.ts.map
@@ -1,10 +1,13 @@
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, splitDegrees, straighten } from './crop-rotation.js';
4
5
  import { opId } from './finetune.js';
5
6
  /**
6
7
  * While the crop tool is active the preview shows the whole rotated image
7
- * (rect forced to full), and the gizmo draws the crop rectangle on top.
8
+ * (rect forced to full, resize cleared), and the gizmo draws the crop
9
+ * rectangle on top. A resize with `cover` or `fill` would cut or stretch that
10
+ * image, and the gizmo would map onto a box that is not the one it edits.
8
11
  */
9
12
  function showFullRect(log) {
10
13
  return {
@@ -18,6 +21,7 @@ function showFullRect(log) {
18
21
  // The gizmo draws the round mask itself; the preview shows the unmasked pixels.
19
22
  mask: 'none',
20
23
  },
24
+ { type: 'resize.clear', id: '__sealpixel_preview_resize__' },
21
25
  ],
22
26
  };
23
27
  }
@@ -34,6 +38,12 @@ const drag = {
34
38
  * nobody waits for it.
35
39
  */
36
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;
37
47
  /**
38
48
  * The crop is written to the log the moment a handle is released, but the
39
49
  * stage keeps showing the whole image, because a corner cannot be pulled
@@ -46,7 +56,20 @@ const settle = {
46
56
  at: null,
47
57
  timer: null,
48
58
  touched: false,
59
+ rect: null,
49
60
  };
61
+ /**
62
+ * Between a change of angle and the preview that shows it, the gizmo keeps
63
+ * drawing the rect it drew on the preview still on the stage. The new rect is
64
+ * normalised to another bounding box; drawn on the old preview it would show
65
+ * at the wrong size for those frames and jump back when the render lands.
66
+ * Cleared when a preview with another geometry arrives.
67
+ */
68
+ let drawn = null;
69
+ /** Records the crop now in the log as the one this tool is showing. */
70
+ function markRect(ctx) {
71
+ settle.rect = ctx.session.getDocument().crop.rect;
72
+ }
50
73
  /** The preview clipped to the crop, in percentages of the canvas box. */
51
74
  function clipFor(rect, circle) {
52
75
  const l = rect.x * 100;
@@ -94,12 +117,15 @@ export const cropTool = {
94
117
  label: 'tool.crop',
95
118
  activate: (ctx) => {
96
119
  unsettle(ctx);
120
+ markRect(ctx);
97
121
  settle.touched = false;
98
122
  ctx.clipPreview(FULL_CLIP);
99
123
  ctx.session.setPreviewTransform(showFullRect);
100
124
  },
101
125
  deactivate: (ctx) => {
102
126
  drag.live = null;
127
+ drawn = null;
128
+ settle.rect = null;
103
129
  unsettle(ctx);
104
130
  // The next preview is the real crop; nothing left to clip.
105
131
  ctx.clipPreview(null);
@@ -113,11 +139,23 @@ export const cropTool = {
113
139
  },
114
140
  panel: (ctx) => {
115
141
  const doc = ctx.document.crop;
116
- const deg = (doc.rotation * 180) / Math.PI;
117
- // A rotation, a flip or an aspect ratio is a change like a drag is, so it
118
- // settles into the result the same way.
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;
146
+ // A rotation, a flip or an aspect ratio is a change like a drag is: it
147
+ // leaves the settled view first, so the surroundings are there to see what
148
+ // swings into the frame, and settles into the result the same way after.
149
+ // Nothing else opens the view for a panel change — the render-time guard
150
+ // compares rectangles, and markRect below keeps this change from ever
151
+ // looking like one; a rotation moves the content inside an unchanged
152
+ // rectangle regardless.
119
153
  const set = (patch) => {
154
+ unsettle(ctx);
155
+ if ('rotation' in patch)
156
+ drawn = { rect: doc.rect, geometry: ctx.stage.geometry };
120
157
  ctx.dispatch({ type: 'crop.set', id: opId(), ...patch });
158
+ markRect(ctx);
121
159
  scheduleSettle(ctx);
122
160
  };
123
161
  const src = ctx.state.source;
@@ -127,7 +165,9 @@ export const cropTool = {
127
165
  // In circle mode a reset restores a full round crop instead of dropping the mask.
128
166
  const reset = () => {
129
167
  unsettle(ctx);
130
- return ctx.dispatch(circle
168
+ // Marked after the dispatch below, so the identity crop this writes is
169
+ // not mistaken for one that arrived from an undo.
170
+ const dispatched = ctx.dispatch(circle
131
171
  ? {
132
172
  type: 'crop.set',
133
173
  id: opId(),
@@ -139,6 +179,8 @@ export const cropTool = {
139
179
  mask: 'circle',
140
180
  }
141
181
  : { type: 'crop.reset', id: opId() });
182
+ markRect(ctx);
183
+ return dispatched;
142
184
  };
143
185
  const aspects = options.aspects.map((a) => ({
144
186
  key: a.label,
@@ -162,23 +204,42 @@ export const cropTool = {
162
204
  ? html `<sealpixel-slider
163
205
  data-param="rotation"
164
206
  .label=${ctx.t('crop.rotation')}
165
- .value=${Number(deg.toFixed(2))}
166
- .min=${-180}
167
- .max=${180}
207
+ .value=${Number(fine.toFixed(2))}
208
+ .min=${-45}
209
+ .max=${45}
168
210
  .step=${options.rotationStep}
169
211
  .format=${(v) => `${v.toFixed(1)}°`}
170
- @slide=${(e) => ctx.hint({ transform: `rotate(${e.detail - deg}deg)` })}
212
+ @slide=${(e) => {
213
+ // The first movement opens the surround; set() only runs on commit,
214
+ // which is after the gesture, and the aiming is what needs the view.
215
+ unsettle(ctx);
216
+ ctx.hint({ rotate: ((e.detail - fine) * Math.PI) / 180 });
217
+ }}
171
218
  @commit=${(e) => {
172
- ctx.hint(null);
173
- set({ rotation: (e.detail * Math.PI) / 180 });
219
+ shownFine = e.detail;
220
+ const rotation = ((quarters * 90 + e.detail) * Math.PI) / 180;
221
+ // The frame stays where it is and keeps its size; the image turns
222
+ // behind it. See crop-rotation.ts for why the rect has to move.
223
+ set({
224
+ rotation,
225
+ rect: src
226
+ ? straighten(doc.rect, doc.rotation, rotation, src, options.outside === 'forbid')
227
+ : doc.rect,
228
+ });
229
+ // The hint stays until the render with this rotation lands and the
230
+ // stage drops it; clearing it here shows the old picture for the
231
+ // frames in between. A refused commit renders nothing, so it clears.
232
+ const now = ctx.session.getDocument().crop.rotation;
233
+ if (Math.abs(now - rotation) > 1e-9)
234
+ ctx.hint(null);
174
235
  }}
175
236
  ></sealpixel-slider>`
176
237
  : nothing}
177
238
  <div class="row compact choice">
178
239
  <div class="group">
179
240
  ${options.rotation
180
- ? html `<sealpixel-button data-action="rotate-left" .label=${'-90°'} @click=${() => set({ rotation: doc.rotation - Math.PI / 2 })}>⟲ 90°</sealpixel-button>
181
- <sealpixel-button data-action="rotate-right" .label=${'+90°'} @click=${() => set({ rotation: doc.rotation + Math.PI / 2 })}>⟳ 90°</sealpixel-button>`
241
+ ? 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>
242
+ <sealpixel-button data-action="rotate-right" .label=${'+90°'} @click=${() => set({ rotation: doc.rotation + Math.PI / 2, rect: quarterTurn(doc.rect, 1) })}>⟳ 90°</sealpixel-button>`
182
243
  : nothing}
183
244
  ${options.flip
184
245
  ? html `<sealpixel-button data-action="flip-x" ?pressed=${doc.flipX} .label=${ctx.t('crop.flipX')} @click=${() => set({ flipX: !doc.flipX })}>⇋</sealpixel-button>
@@ -196,10 +257,21 @@ export const cropTool = {
196
257
  },
197
258
  overlay: (ctx) => {
198
259
  const doc = ctx.document.crop;
260
+ // An undo, a redo or a time travel changes the crop without passing through
261
+ // this tool, and the settled view does not follow on its own: the stage
262
+ // would keep the clip of the crop that was just undone, with the gizmo
263
+ // still faded out, so undo would look like it had done nothing at all.
264
+ // Back to adjusting, which is what the user is doing after an undo.
265
+ if (settle.rect && !drag.live && !sameRect(settle.rect, doc.rect)) {
266
+ settle.rect = doc.rect;
267
+ unsettle(ctx);
268
+ }
199
269
  const { width: W, height: H, zoom } = ctx.stage;
270
+ if (drawn && drawn.geometry !== ctx.stage.geometry)
271
+ drawn = null;
200
272
  if (!W || !H)
201
273
  return svg ``;
202
- const r = drag.live ?? doc.rect;
274
+ const r = drag.live ?? drawn?.rect ?? doc.rect;
203
275
  const x = r.x * W;
204
276
  const y = r.y * H;
205
277
  const w = r.width * W;
@@ -220,15 +292,26 @@ export const cropTool = {
220
292
  e.stopPropagation();
221
293
  e.preventDefault();
222
294
  unsettle(ctx);
295
+ drawn = null;
223
296
  const p = ctx.stage.toImage(e.clientX, e.clientY);
224
297
  drag.handle = handle;
225
298
  drag.start = doc.rect;
226
299
  drag.sx = p.x / W;
227
300
  drag.sy = p.y / H;
228
301
  drag.live = doc.rect;
302
+ const options = ctx.options('crop') ?? CROP_DEFAULT_OPTIONS;
303
+ const src = ctx.state.source;
229
304
  const move = (ev) => {
230
305
  const q = ctx.stage.toImage(ev.clientX, ev.clientY);
231
- drag.live = applyDrag(drag.start, handle, q.x / W - drag.sx, q.y / H - drag.sy, doc.aspect, W / H);
306
+ const apply = (dx, dy) => applyDrag(drag.start, handle, dx, dy, doc.aspect, W / H);
307
+ const dx = q.x / W - drag.sx;
308
+ const dy = q.y / H - drag.sy;
309
+ // At an angle the box is larger than the image; `forbid` keeps the
310
+ // frame on the picture.
311
+ drag.live =
312
+ options.outside === 'forbid' && doc.rotation !== 0 && src
313
+ ? constrainDrag(apply, dx, dy, doc.rotation, src)
314
+ : apply(dx, dy);
232
315
  ctx.refresh();
233
316
  };
234
317
  const up = () => {
@@ -239,6 +322,7 @@ export const cropTool = {
239
322
  drag.live = null;
240
323
  if (final && !sameRect(final, doc.rect))
241
324
  ctx.dispatch({ type: 'crop.set', id: opId(), rect: final });
325
+ markRect(ctx);
242
326
  scheduleSettle(ctx);
243
327
  ctx.refresh();
244
328
  };
@@ -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;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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"]}
@@ -15,4 +15,3 @@ export declare function deleteHandle(box: Rect, stage: {
15
15
  export declare function pointsBox(points: readonly (readonly [number, number])[]): Rect;
16
16
  /** Normalized rect to image pixels. */
17
17
  export declare function toPx(r: Rect, W: number, H: number): Rect;
18
- //# sourceMappingURL=delete-handle.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import { svg } from 'lit';
2
2
  import { TRASH_PATH } from '../icons.js';
3
+ import { focusEditor } from './keys.js';
3
4
  /**
4
5
  * A trash button floating above a selected element, rendered inside a tool
5
6
  * overlay in image pixel coordinates. It is sized through `zoom`, so it stays
@@ -20,6 +21,11 @@ export function deleteHandle(box, stage, label, onDelete) {
20
21
  };
21
22
  const act = (e) => {
22
23
  e.stopPropagation();
24
+ // The button goes with the element: a keyboard press hands focus to the
25
+ // editor first, so Tab does not start over from the top of the page.
26
+ const g = e.currentTarget;
27
+ if (g.matches(':focus'))
28
+ focusEditor(g);
23
29
  onDelete();
24
30
  };
25
31
  return svg `<g data-interactive data-action="delete" role="button" tabindex="0" aria-label=${label}
@@ -1 +1 @@
1
- {"version":3,"file":"delete-handle.js","sourceRoot":"","sources":["../../src/tools/delete-handle.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,GAAG,EAAE,MAAM,KAAK,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,GAAS,EACT,KAAsD,EACtD,KAAa,EACb,QAAoB;IAEpB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC;IAC5C,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IACpB,MAAM,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAClD,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;IACzB,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC;QAAE,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACnE,MAAM,IAAI,GAAG,CAAC,CAAQ,EAAE,EAAE;QACxB,CAAC,CAAC,eAAe,EAAE,CAAC;QACpB,CAAC,CAAC,cAAc,EAAE,CAAC;IACrB,CAAC,CAAC;IACF,MAAM,GAAG,GAAG,CAAC,CAAQ,EAAE,EAAE;QACvB,CAAC,CAAC,eAAe,EAAE,CAAC;QACpB,QAAQ,EAAE,CAAC;IACb,CAAC,CAAC;IACF,OAAO,GAAG,CAAA,kFAAkF,KAAK;kBACjF,aAA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AAI,CAAC,GAAG,EAAE;YAAE,EAAE,GAAG,CAAC,CAAC;QACnB,IAAI,CAAC,GAAG,EAAE;YAAE,EAAE,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;AACrF,CAAC;AAED,uCAAuC;AACvC,MAAM,UAAU,IAAI,CAAC,CAAO,EAAE,CAAS,EAAE,CAAS;IAChD,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;AAC9E,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 { Rect } from '@sealpixel/core';\nimport { type SVGTemplateResult, svg } from 'lit';\nimport { TRASH_PATH } from '../icons.js';\nimport { focusEditor } from './keys.js';\n\n/**\n * A trash button floating above a selected element, rendered inside a tool\n * overlay in image pixel coordinates. It is sized through `zoom`, so it stays\n * 32 px on screen at every zoom level, and moves below the element when the\n * image edge leaves no room above. Enter and Space trigger it from the keyboard.\n */\nexport function deleteHandle(\n box: Rect,\n stage: { width: number; height: number; zoom: number },\n label: string,\n onDelete: () => void,\n): SVGTemplateResult {\n const { zoom, width: W, height: H } = stage;\n const r = 16 / zoom;\n const gap = 10 / zoom;\n const cx = clamp(box.x + box.width / 2, r, W - r);\n let cy = box.y - gap - r;\n if (cy - r < 0) cy = Math.min(box.y + box.height + gap + r, H - r);\n const stop = (e: Event) => {\n e.stopPropagation();\n e.preventDefault();\n };\n const act = (e: Event) => {\n e.stopPropagation();\n // The button goes with the element: a keyboard press hands focus to the\n // editor first, so Tab does not start over from the top of the page.\n const g = e.currentTarget as Element;\n if (g.matches(':focus')) focusEditor(g);\n onDelete();\n };\n return svg`<g data-interactive data-action=\"delete\" role=\"button\" tabindex=\"0\" aria-label=${label}\n transform=${`translate(${cx} ${cy})`} style=\"cursor:pointer\"\n @pointerdown=${stop} @click=${act}\n @keydown=${(e: KeyboardEvent) => {\n if (e.key === 'Enter' || e.key === ' ') act(e);\n }}>\n <circle r=${r} fill=\"var(--sealpixel-color-surface)\" stroke=\"var(--sealpixel-color-border)\" stroke-width=${1 / zoom} />\n <g transform=${`scale(${1 / zoom}) translate(-9 -9) scale(0.75)`} fill=\"none\" stroke=\"var(--sealpixel-color-danger)\" stroke-width=\"1.75\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=${TRASH_PATH} /></g>\n </g>`;\n}\n\n/** Axis-aligned box around normalized points. */\nexport function pointsBox(points: readonly (readonly [number, number])[]): Rect {\n let x0 = 1;\n let y0 = 1;\n let x1 = 0;\n let y1 = 0;\n for (const [x, y] of points) {\n if (x < x0) x0 = x;\n if (y < y0) y0 = y;\n if (x > x1) x1 = x;\n if (y > y1) y1 = y;\n }\n return { x: x0, y: y0, width: Math.max(0, x1 - x0), height: Math.max(0, y1 - y0) };\n}\n\n/** Normalized rect to image pixels. */\nexport function toPx(r: Rect, W: number, H: number): Rect {\n return { x: r.x * W, y: r.y * H, width: r.width * W, height: r.height * H };\n}\n\nfunction clamp(v: number, lo: number, hi: number): number {\n return v < lo ? lo : v > hi ? hi : v;\n}\n"]}
@@ -1,3 +1,2 @@
1
1
  import type { UiTool } from '../tool.js';
2
2
  export declare const filterTool: UiTool;
3
- //# sourceMappingURL=filter.d.ts.map