@ggraphic/editor 0.1.0-alpha.6 → 0.1.0-alpha.7

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.
@@ -58,6 +58,7 @@ export declare function paintCropGhosts(stage: Konva.Stage, canvas: HTMLCanvasEl
58
58
  * Einfärbung), einmal auf eine verkleinerte Kopie gerechnet statt per Cache
59
59
  * auf dem ganzen, oft vielfach gezoomten Restbild. Spiegeln bleibt außen vor:
60
60
  * das Restbild spiegelt über seine Skalierung. `displayedWidth` ist die Breite
61
- * des ganzen Fotos auf der Bühne; der Weichzeichner-Radius gilt dort.
61
+ * des ganzen Fotos auf der Bühne; der Weichzeichner-Radius gilt dort. `maxSide`
62
+ * begrenzt die längste Kante der Kopie (der Pan braucht Bildschirmauflösung).
62
63
  */
63
- export declare function cropGhostSource(image: HTMLImageElement, adjustments: ImageAdjustments | null, displayedWidth: number, color?: string | null): CanvasImageSource;
64
+ export declare function cropGhostSource(image: HTMLImageElement, adjustments: ImageAdjustments | null, displayedWidth: number, color?: string | null, maxSide?: number): CanvasImageSource;
@@ -172,9 +172,10 @@ const GHOST_SOURCE_SIDE = 1024;
172
172
  * Einfärbung), einmal auf eine verkleinerte Kopie gerechnet statt per Cache
173
173
  * auf dem ganzen, oft vielfach gezoomten Restbild. Spiegeln bleibt außen vor:
174
174
  * das Restbild spiegelt über seine Skalierung. `displayedWidth` ist die Breite
175
- * des ganzen Fotos auf der Bühne; der Weichzeichner-Radius gilt dort.
175
+ * des ganzen Fotos auf der Bühne; der Weichzeichner-Radius gilt dort. `maxSide`
176
+ * begrenzt die längste Kante der Kopie (der Pan braucht Bildschirmauflösung).
176
177
  */
177
- export function cropGhostSource(image, adjustments, displayedWidth, color = null) {
178
+ export function cropGhostSource(image, adjustments, displayedWidth, color = null, maxSide = GHOST_SOURCE_SIDE) {
178
179
  const look = adjustments ? { ...adjustments, flipX: false, flipY: false } : null;
179
180
  const filters = [
180
181
  ...(color ? [Konva.Filters.RGB] : []),
@@ -183,7 +184,7 @@ export function cropGhostSource(image, adjustments, displayedWidth, color = null
183
184
  const natural = { width: image.naturalWidth, height: image.naturalHeight };
184
185
  if (filters.length === 0 || !natural.width || !natural.height)
185
186
  return image;
186
- const scale = Math.min(1, GHOST_SOURCE_SIDE / Math.max(natural.width, natural.height));
187
+ const scale = Math.min(1, maxSide / Math.max(natural.width, natural.height));
187
188
  const width = Math.max(1, Math.round(natural.width * scale));
188
189
  const height = Math.max(1, Math.round(natural.height * scale));
189
190
  const canvas = document.createElement('canvas');
@@ -0,0 +1,22 @@
1
+ import type Konva from 'konva';
2
+ interface Rect {
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ height: number;
7
+ }
8
+ /** A pan of a filtered photo over its pre-filtered copy; `end` puts the photo and its filters back. */
9
+ export interface FilteredPan {
10
+ /** Sets a crop given in the photo's own pixels on the copy. */
11
+ crop: (crop: Rect) => void;
12
+ end: () => void;
13
+ }
14
+ /**
15
+ * Pans a filtered photo without filtering it again on every move. A filtered node draws from its
16
+ * cache, and a new crop needs a new cache: one pass of every filter over the bitmap per pointer
17
+ * move (#197). Instead the node shows `source` — the whole photo, filtered once at the resolution
18
+ * it is shown at — with its crop scaled to that copy, and no filters or cache. Null when `source`
19
+ * is the photo itself (nothing to filter).
20
+ */
21
+ export declare function beginFilteredPan(node: Konva.Image, source: CanvasImageSource, naturalWidth: number): FilteredPan | null;
22
+ export {};
@@ -0,0 +1,36 @@
1
+ const scaleRect = (r, s) => ({
2
+ x: r.x * s,
3
+ y: r.y * s,
4
+ width: r.width * s,
5
+ height: r.height * s,
6
+ });
7
+ /**
8
+ * Pans a filtered photo without filtering it again on every move. A filtered node draws from its
9
+ * cache, and a new crop needs a new cache: one pass of every filter over the bitmap per pointer
10
+ * move (#197). Instead the node shows `source` — the whole photo, filtered once at the resolution
11
+ * it is shown at — with its crop scaled to that copy, and no filters or cache. Null when `source`
12
+ * is the photo itself (nothing to filter).
13
+ */
14
+ export function beginFilteredPan(node, source, naturalWidth) {
15
+ const photo = node.image();
16
+ if (!photo || source === photo || !('width' in source))
17
+ return null;
18
+ const sourceWidth = Number(source.width);
19
+ if (!sourceWidth || !naturalWidth)
20
+ return null;
21
+ const s = sourceWidth / naturalWidth;
22
+ const filters = node.filters();
23
+ node.clearCache();
24
+ node.filters([]);
25
+ node.image(source);
26
+ node.crop(scaleRect(node.crop(), s));
27
+ return {
28
+ crop: (crop) => node.crop(scaleRect(crop, s)),
29
+ end: () => {
30
+ const crop = node.crop();
31
+ node.image(photo);
32
+ node.filters(filters);
33
+ node.crop(scaleRect(crop, 1 / s));
34
+ },
35
+ };
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ggraphic/editor",
3
- "version": "0.1.0-alpha.6",
3
+ "version": "0.1.0-alpha.7",
4
4
  "license": "AGPL-3.0-only",
5
5
  "repository": {
6
6
  "type": "git",