@ggraphic/editor 0.1.0-alpha.7 → 0.1.0-alpha.8
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/hooks/useLookBitmap.d.ts +14 -0
- package/dist/hooks/useLookBitmap.js +65 -0
- package/dist/primitives/CanvasImage.js +19 -107
- package/dist/primitives/UserImagePrimitive.js +16 -57
- package/dist/utils/cropGhost.d.ts +1 -11
- package/dist/utils/cropGhost.js +4 -53
- package/dist/utils/filterCache.d.ts +4 -9
- package/dist/utils/filterCache.js +4 -20
- package/dist/utils/lookBitmap.d.ts +75 -0
- package/dist/utils/lookBitmap.js +267 -0
- package/dist/utils/straighten.d.ts +0 -3
- package/dist/utils/straighten.js +0 -25
- package/package.json +1 -1
- package/dist/utils/filteredPan.d.ts +0 -22
- package/dist/utils/filteredPan.js +0 -36
- package/dist/utils/recacheNextFrame.d.ts +0 -6
- package/dist/utils/recacheNextFrame.js +0 -15
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import type Konva from 'konva';
|
|
3
|
+
import type { ImageAdjustments } from '../utils/userImageUtils.js';
|
|
4
|
+
/**
|
|
5
|
+
* Hands the nodes in `refs` the look bitmap of `image` (`LOOK_IMAGE_ATTR`), the first node sizing
|
|
6
|
+
* it. Only a new photo, a new look or a larger draw makes a bitmap; a pan, zoom or crop does not.
|
|
7
|
+
* While the look changes (a slider drag) a small bitmap is shown at once and the full one once the
|
|
8
|
+
* look rests; a capture (`captureRatio` set) always gets the full one at once.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useLookBitmap(refs: readonly RefObject<Konva.Image | null>[], image: HTMLImageElement | null, adjustments: ImageAdjustments | null, color: string | null,
|
|
11
|
+
/** How wide the whole photo is drawn, in node units. */
|
|
12
|
+
photoWidth: number, captureRatio: number | null,
|
|
13
|
+
/** Changes when a node in `refs` mounts or unmounts (the dimmed rest of the photo). */
|
|
14
|
+
mounted?: unknown): void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { builtLookBitmap, LOOK_IMAGE_ATTR, LOOK_QUICK_AREA, lookBitmap, lookBitmapSize, lookKey, lookPixelRatio, } from '../utils/lookBitmap.js';
|
|
4
|
+
// A look change that rests this long gets its full-size bitmap. A slider commits about every
|
|
5
|
+
// 300 ms while it is dragged (measured 16.11.2026); a shorter wait built the full bitmap, ~55 ms
|
|
6
|
+
// for a 7 MP photo, between two commits of one drag.
|
|
7
|
+
const SETTLE_MS = 400;
|
|
8
|
+
/**
|
|
9
|
+
* Hands the nodes in `refs` the look bitmap of `image` (`LOOK_IMAGE_ATTR`), the first node sizing
|
|
10
|
+
* it. Only a new photo, a new look or a larger draw makes a bitmap; a pan, zoom or crop does not.
|
|
11
|
+
* While the look changes (a slider drag) a small bitmap is shown at once and the full one once the
|
|
12
|
+
* look rests; a capture (`captureRatio` set) always gets the full one at once.
|
|
13
|
+
*/
|
|
14
|
+
export function useLookBitmap(refs, image, adjustments, color,
|
|
15
|
+
/** How wide the whole photo is drawn, in node units. */
|
|
16
|
+
photoWidth, captureRatio,
|
|
17
|
+
/** Changes when a node in `refs` mounts or unmounts (the dimmed rest of the photo). */
|
|
18
|
+
mounted = null) {
|
|
19
|
+
const key = lookKey(adjustments, color);
|
|
20
|
+
const latest = useRef({ adjustments, color });
|
|
21
|
+
latest.current = { adjustments, color };
|
|
22
|
+
const shownKey = useRef(null);
|
|
23
|
+
const width = Math.round(photoWidth);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const main = refs[0]?.current;
|
|
26
|
+
if (!main || !image)
|
|
27
|
+
return undefined;
|
|
28
|
+
const apply = (source) => {
|
|
29
|
+
for (const ref of refs) {
|
|
30
|
+
const node = ref.current;
|
|
31
|
+
if (!node)
|
|
32
|
+
continue;
|
|
33
|
+
node.setAttr(LOOK_IMAGE_ATTR, source ?? undefined);
|
|
34
|
+
node.getLayer()?.batchDraw();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
if (key === null || width <= 0) {
|
|
38
|
+
shownKey.current = null;
|
|
39
|
+
apply(null);
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const natural = { width: image.naturalWidth, height: image.naturalHeight };
|
|
43
|
+
const size = lookBitmapSize(natural, width, lookPixelRatio(main, captureRatio));
|
|
44
|
+
const full = () => {
|
|
45
|
+
const { adjustments: look, color: tint } = latest.current;
|
|
46
|
+
apply(lookBitmap(image, look, tint, width, size));
|
|
47
|
+
};
|
|
48
|
+
const previous = shownKey.current;
|
|
49
|
+
shownKey.current = { image, key };
|
|
50
|
+
const changing = previous !== null && previous.image === image && previous.key !== key;
|
|
51
|
+
if (!changing ||
|
|
52
|
+
captureRatio !== null ||
|
|
53
|
+
size.width * size.height <= LOOK_QUICK_AREA ||
|
|
54
|
+
builtLookBitmap(image, key, size.width)) {
|
|
55
|
+
full();
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const { adjustments: look, color: tint } = latest.current;
|
|
59
|
+
apply(lookBitmap(image, look, tint, width, lookBitmapSize(natural, width, 1, LOOK_QUICK_AREA)));
|
|
60
|
+
const timer = setTimeout(full, SETTLE_MS);
|
|
61
|
+
return () => clearTimeout(timer);
|
|
62
|
+
// `refs` holds stable refs; `latest` carries the look the key stands for.
|
|
63
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
64
|
+
}, [image, key, width, captureRatio, mounted]);
|
|
65
|
+
}
|
|
@@ -1,33 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* CanvasImage - Draggable, transformable image layer
|
|
5
|
-
*
|
|
6
|
-
* Follows Konva best practices:
|
|
7
|
-
* - Visual scaling during transform (no React state)
|
|
8
|
-
* - Commit dimensions on transformEnd
|
|
9
|
-
* - Snapping to other elements and stage center
|
|
10
|
-
*
|
|
11
|
-
* Performance optimizations:
|
|
12
|
-
* - Uses refs for snap state during drag to avoid React re-renders
|
|
13
|
-
* - Throttled snap line updates via requestAnimationFrame
|
|
14
|
-
* - Single bounds calculation (removed from dragBoundFunc, only in handleDragMove)
|
|
15
|
-
*/
|
|
16
|
-
import Konva from 'konva';
|
|
17
|
-
import { useRef, useEffect, useCallback, useMemo, memo } from 'react';
|
|
2
|
+
import { useRef, useEffect, useCallback, memo } from 'react';
|
|
18
3
|
import { Image as KonvaImage, Transformer } from 'react-konva';
|
|
19
4
|
import { LOCKED_TRANSFORMER, useIsItemLocked } from '../components/canvasItemLock.js';
|
|
20
5
|
import { useGeometryReporter } from '../hooks/useGeometryReporter.js';
|
|
6
|
+
import { useLookBitmap } from '../hooks/useLookBitmap.js';
|
|
21
7
|
import { useSnapScheduler } from '../hooks/useSnapScheduler.js';
|
|
22
8
|
import { panWindowPhoto, photoRectAround, visiblePart, windowInPhoto, zoomWindow, } from '../utils/coverFit.js';
|
|
23
9
|
import { isGroupDrag } from '../utils/multiSelect.js';
|
|
10
|
+
import { usePreviewCaptureRatio } from '../utils/filterCache.js';
|
|
11
|
+
import { drawsLook, lookDrawAttrs, lookSceneFunc } from '../utils/lookBitmap.js';
|
|
24
12
|
import { ELEMENT_TRANSFORMER, normalizeRotation } from '../utils/orientation.js';
|
|
25
|
-
import { cacheFiltered, usePreviewCaptureRatio } from '../utils/filterCache.js';
|
|
26
|
-
import { beginFilteredPan } from '../utils/filteredPan.js';
|
|
27
13
|
import { boxFrame, createBoxFrame, frameBounds, snapByBounds } from '../utils/snapping.js';
|
|
28
|
-
import { panStraightPhoto, STRAIGHT_DRAW_ATTR, straightDrawOf, straightenWindowPhoto, straightScaleCrop,
|
|
29
|
-
import { CROP_GHOST_NAME, CROP_GHOST_OPACITY, cropGhostAttrs,
|
|
30
|
-
import { getActiveImageFilters, imageFilterAttrs } from '../utils/imageFilters.js';
|
|
14
|
+
import { panStraightPhoto, STRAIGHT_DRAW_ATTR, straightDrawOf, straightenWindowPhoto, straightScaleCrop, windowPhotoOfStraight, zoomStraightPhoto, } from '../utils/straighten.js';
|
|
15
|
+
import { CROP_GHOST_NAME, CROP_GHOST_OPACITY, cropGhostAttrs, placeCropGhost, } from '../utils/cropGhost.js';
|
|
31
16
|
import { backgroundKeyCrop, cropKeyOf } from '../utils/keyboardCrop.js';
|
|
32
17
|
// Rahmen für Snap und Geometrie-Meldung, pro Aufruf neu beschrieben (synchron, ohne Allokation).
|
|
33
18
|
/** The pointer in `node`'s parent space — where Konva itself places a dragged node from. */
|
|
@@ -64,7 +49,6 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
64
49
|
// Drag of a cover-fitted photo: the node under the pointer at drag start, the pointer there (in
|
|
65
50
|
// the node's parent space), and the pan so far (begradigt: die Lage des gedrehten Fotos).
|
|
66
51
|
const panStartRef = useRef(null);
|
|
67
|
-
const adjustmentFilters = adjustments ? getActiveImageFilters(adjustments) : [];
|
|
68
52
|
const trRef = useRef(null);
|
|
69
53
|
const ghostRef = useRef(null);
|
|
70
54
|
const snap = useSnapScheduler({
|
|
@@ -100,11 +84,14 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
100
84
|
: null;
|
|
101
85
|
// Begradigt dreht sich das Restbild samt gefilterter Kopie über `rotation` mit.
|
|
102
86
|
const ghostAttrs = ghost ? cropGhostAttrs(ghost, mirror, turnDeg) : null;
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
87
|
+
// The look is a bitmap made once per look (`useLookBitmap`); panning only moves the crop. The
|
|
88
|
+
// dimmed rest outside the frame shows the same bitmap (blur, B/W …).
|
|
89
|
+
const look = adjustments ?? null;
|
|
90
|
+
const drawLook = drawsLook(look, color ?? null);
|
|
91
|
+
const lookPhoto = natural
|
|
92
|
+
? (straight ?? photoRectAround(natural, { x, y, width, height }))
|
|
93
|
+
: null;
|
|
94
|
+
useLookBitmap([imageRef, ghostRef], image ?? null, look, color ?? null, lookPhoto?.width ?? width, captureRatio, !!ghost);
|
|
108
95
|
useEffect(() => {
|
|
109
96
|
if (selected && trRef.current && imageRef.current) {
|
|
110
97
|
trRef.current.nodes([imageRef.current]);
|
|
@@ -114,34 +101,6 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
114
101
|
trRef.current.nodes([]);
|
|
115
102
|
}
|
|
116
103
|
}, [selected]);
|
|
117
|
-
// Konva filters require the node to be cached first; without filters the
|
|
118
|
-
// cache is only an extra offscreen canvas redrawn on every change.
|
|
119
|
-
useEffect(() => {
|
|
120
|
-
const node = imageRef.current;
|
|
121
|
-
if (!node || !image)
|
|
122
|
-
return;
|
|
123
|
-
if (color || adjustmentFilters.length > 0) {
|
|
124
|
-
cacheFiltered(node, captureRatio);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
node.clearCache();
|
|
128
|
-
}
|
|
129
|
-
node.getLayer()?.batchDraw();
|
|
130
|
-
}, [
|
|
131
|
-
image,
|
|
132
|
-
width,
|
|
133
|
-
height,
|
|
134
|
-
part?.crop.x,
|
|
135
|
-
part?.crop.y,
|
|
136
|
-
draw?.x,
|
|
137
|
-
draw?.y,
|
|
138
|
-
draw?.width,
|
|
139
|
-
draw?.rotation,
|
|
140
|
-
color,
|
|
141
|
-
adjustments,
|
|
142
|
-
adjustmentFilters.length,
|
|
143
|
-
captureRatio,
|
|
144
|
-
]);
|
|
145
104
|
const handleTouchStart = useCallback((e) => {
|
|
146
105
|
const node = e.target;
|
|
147
106
|
if (touchDragNeedsSelection && !selected && draggable) {
|
|
@@ -170,11 +129,6 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
170
129
|
const nodeHeight = node.height() * node.scaleY();
|
|
171
130
|
snap.onDragEnd();
|
|
172
131
|
const pan = panStartRef.current;
|
|
173
|
-
if (pan?.filtered) {
|
|
174
|
-
// The photo and its filters come back before the store does: no unfiltered frame.
|
|
175
|
-
pan.filtered.end();
|
|
176
|
-
cacheFiltered(node, captureRatio);
|
|
177
|
-
}
|
|
178
132
|
if (pan?.photo) {
|
|
179
133
|
// Begradigt: das Fenster behält seine Größe, seine Mitte ist die des gedrehten Fotos.
|
|
180
134
|
panStartRef.current = null;
|
|
@@ -203,19 +157,7 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
203
157
|
onGeometryChange(id, box.x, box.y, box.width, box.height);
|
|
204
158
|
}
|
|
205
159
|
}
|
|
206
|
-
}, [
|
|
207
|
-
id,
|
|
208
|
-
x,
|
|
209
|
-
y,
|
|
210
|
-
width,
|
|
211
|
-
height,
|
|
212
|
-
part,
|
|
213
|
-
onDragEnd,
|
|
214
|
-
onPositionChange,
|
|
215
|
-
onGeometryChange,
|
|
216
|
-
snap,
|
|
217
|
-
captureRatio,
|
|
218
|
-
]);
|
|
160
|
+
}, [id, x, y, width, height, part, onDragEnd, onPositionChange, onGeometryChange, snap]);
|
|
219
161
|
const clampToBounds = useCallback((posX, posY, nodeWidth, nodeHeight, nodeRotation) => {
|
|
220
162
|
if (!constrainToBounds || !stageWidth || !stageHeight) {
|
|
221
163
|
return { x: posX, y: posY };
|
|
@@ -267,7 +209,7 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
267
209
|
else {
|
|
268
210
|
const next = visiblePart(natural, moved, slot, mirror);
|
|
269
211
|
if (next)
|
|
270
|
-
|
|
212
|
+
node.crop(next.crop);
|
|
271
213
|
}
|
|
272
214
|
pan.photo = moved;
|
|
273
215
|
placeCropGhost(ghostRef.current, moved, mirror, turnDeg);
|
|
@@ -280,7 +222,7 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
280
222
|
return;
|
|
281
223
|
node.position(next.part.box);
|
|
282
224
|
node.size(next.part.box);
|
|
283
|
-
|
|
225
|
+
node.crop(next.part.crop);
|
|
284
226
|
pan.dx = next.dx;
|
|
285
227
|
pan.dy = next.dy;
|
|
286
228
|
// Ziehen und Zoomen ändern die Knoten direkt; das Restbild geht ohne React-Zustand mit.
|
|
@@ -331,35 +273,6 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
331
273
|
width,
|
|
332
274
|
height,
|
|
333
275
|
]);
|
|
334
|
-
// A filtered photo pans over a copy filtered once, at the size it is shown (#197). The copy is
|
|
335
|
-
// made when Ausschnitt mode opens (and after a zoom), so the drag itself starts without a pause.
|
|
336
|
-
const panPhoto = natural ? (straight ?? photoRectAround(natural, { x, y, width, height })) : null;
|
|
337
|
-
const panPhotoWidth = panPhoto ? Math.round(panPhoto.width) : 0;
|
|
338
|
-
const filtered = !!color || adjustmentFilters.length > 0;
|
|
339
|
-
const panSourceRef = useRef(null);
|
|
340
|
-
const makePanSource = useCallback((node) => {
|
|
341
|
-
if (!image || !natural || !panPhotoWidth)
|
|
342
|
-
return null;
|
|
343
|
-
const shown = panPhotoWidth * node.getAbsoluteScale().x * Konva.pixelRatio;
|
|
344
|
-
const scale = Math.min(1, shown / natural.width);
|
|
345
|
-
const maxSide = Math.ceil(Math.max(natural.width, natural.height) * scale);
|
|
346
|
-
return cropGhostSource(image, adjustments ?? null, panPhotoWidth, color ?? null, maxSide);
|
|
347
|
-
},
|
|
348
|
-
// `natural` is a new object each render; its size comes with `image`.
|
|
349
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
350
|
-
[image, panPhotoWidth, adjustments, color]);
|
|
351
|
-
useEffect(() => {
|
|
352
|
-
const node = imageRef.current;
|
|
353
|
-
panSourceRef.current = cropping && filtered && node ? makePanSource(node) : null;
|
|
354
|
-
}, [cropping, filtered, makePanSource]);
|
|
355
|
-
const startFilteredPan = useCallback((node) => {
|
|
356
|
-
if (!natural || !node.isCached())
|
|
357
|
-
return null;
|
|
358
|
-
const source = panSourceRef.current ?? makePanSource(node);
|
|
359
|
-
return source ? beginFilteredPan(node, source, natural.width) : null;
|
|
360
|
-
},
|
|
361
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
362
|
-
[image, makePanSource]);
|
|
363
276
|
const handleDragStart = useCallback((e) => {
|
|
364
277
|
// In a group drag a cover-fitted image moves with the others; the background photo
|
|
365
278
|
// never joins one, outside Ausschnitt mode it is not draggable.
|
|
@@ -372,11 +285,10 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
372
285
|
dx: 0,
|
|
373
286
|
dy: 0,
|
|
374
287
|
photo: null,
|
|
375
|
-
filtered: startFilteredPan(node),
|
|
376
288
|
}
|
|
377
289
|
: null;
|
|
378
290
|
snap.onDragStart();
|
|
379
|
-
}, [part, snap
|
|
291
|
+
}, [part, snap]);
|
|
380
292
|
// Tastatur im Ausschnitt-Modus: dieselben Grenzen und dieselbe Übernahme wie Ziehen und Zoomen.
|
|
381
293
|
const keyCropRef = useRef(null);
|
|
382
294
|
useEffect(() => {
|
|
@@ -472,7 +384,7 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
472
384
|
if (!image)
|
|
473
385
|
return null;
|
|
474
386
|
const enabledAnchors = transformConfig?.enabledAnchors ?? DEFAULT_IMAGE_ANCHORS;
|
|
475
|
-
return (_jsxs(_Fragment, { children: [ghostAttrs &&
|
|
387
|
+
return (_jsxs(_Fragment, { children: [ghostAttrs && (_jsx(KonvaImage, { ref: ghostRef, name: `selection-chrome ${CROP_GHOST_NAME}`, image: image, sceneFunc: drawLook ? lookSceneFunc : undefined, opacity: CROP_GHOST_OPACITY, listening: false, ...ghostAttrs })), _jsx(KonvaImage, { ref: imageRef, id: id, image: image, x: part?.box.x ?? x, y: part?.box.y ?? y, width: part?.box.width ?? width, height: part?.box.height ?? height, rotation: coverFit ? 0 : rotation, crop: part?.crop, opacity: opacity, draggable: draggable && !locked, dragBoundFunc: dragBoundFunc, onMouseDown: onSelect, onTouchStart: handleTouchStart, onDblClick: onToggleCrop ?? undefined, onDblTap: onToggleCrop ?? undefined, onDragStart: handleDragStart, onDragEnd: handleDragEnd, onDragMove: handleDragMove, onTransform: handleTransform, onTransformEnd: handleTransformEnd, listening: listening, ...lookDrawAttrs(look), sceneFunc: drawLook || draw ? lookSceneFunc : undefined, ...(draw ? { [STRAIGHT_DRAW_ATTR]: draw } : {}) }), selected && (_jsx(Transformer, { ref: trRef, rotateEnabled: transformConfig?.rotateEnabled ?? false, keepRatio: transformConfig?.keepRatio ?? true, enabledAnchors: enabledAnchors, boundBoxFunc: (oldBox, newBox) => {
|
|
476
388
|
const minWidth = transformConfig?.bounds?.minWidth ?? 20;
|
|
477
389
|
const maxWidth = transformConfig?.bounds?.maxWidth ?? Infinity;
|
|
478
390
|
if (newBox.width < minWidth)
|
|
@@ -7,26 +7,26 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
7
7
|
* instead of pre-registered asset definitions. Uses the instance's
|
|
8
8
|
* width/height directly (already scaled during creation).
|
|
9
9
|
*/
|
|
10
|
-
import { useState, useEffect, useRef,
|
|
10
|
+
import { useState, useEffect, useRef, memo } from 'react';
|
|
11
11
|
import { Image, Group, Rect, Transformer, Circle, Line } from 'react-konva';
|
|
12
12
|
import { activeBrand } from '../brand/brandRegistry.js';
|
|
13
13
|
import { useDocumentBrand } from '../brand/documentBrand.js';
|
|
14
14
|
import { LOCKED_TRANSFORMER, useIsItemLocked } from '../components/canvasItemLock.js';
|
|
15
15
|
import { useAnnounce } from '../hooks/useAnnounce.js';
|
|
16
16
|
import { useBoxSnap } from '../hooks/useBoxSnap.js';
|
|
17
|
+
import { useLookBitmap } from '../hooks/useLookBitmap.js';
|
|
17
18
|
import { messages } from '../i18n/messages.js';
|
|
18
19
|
import { clampPan, covers, framedPhotoRect, panOfFramedPhoto, visiblePart, } from '../utils/coverFit.js';
|
|
19
20
|
import { cropAspectRatio, frameForAspect } from '../utils/cropAspect.js';
|
|
20
21
|
import { notchPx, traceNotch } from '../utils/notch.js';
|
|
21
22
|
import { ELEMENT_TRANSFORMER } from '../utils/orientation.js';
|
|
22
23
|
import { useImageRetry, useTrackPendingImage } from '../utils/pendingImages.js';
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import { clampPointToStraightPhoto, frameForAspectOnStraightPhoto, panOfStraightPhoto, panStraightPhoto, STRAIGHT_DRAW_ATTR, straightDrawOf, straightFramedPhoto, straightPhotoCovers, straightScaleCrop,
|
|
24
|
+
import { usePreviewCaptureRatio } from '../utils/filterCache.js';
|
|
25
|
+
import { drawsLook, lookDrawAttrs, lookSceneFunc } from '../utils/lookBitmap.js';
|
|
26
|
+
import { clampPointToStraightPhoto, frameForAspectOnStraightPhoto, panOfStraightPhoto, panStraightPhoto, STRAIGHT_DRAW_ATTR, straightDrawOf, straightFramedPhoto, straightPhotoCovers, straightScaleCrop, } from '../utils/straighten.js';
|
|
26
27
|
import { EXPORT_HIDDEN_NAME } from '../utils/captureStage.js';
|
|
27
28
|
import { touchAnchorStyleFunc } from '../utils/touchInput.js';
|
|
28
|
-
import { CROP_GHOST_NAME, CROP_GHOST_OPACITY, cropGhostAttrs
|
|
29
|
-
import { getActiveImageFilters, hasActiveImageFilters, imageFilterAttrs, } from '../utils/imageFilters.js';
|
|
29
|
+
import { CROP_GHOST_NAME, CROP_GHOST_OPACITY, cropGhostAttrs } from '../utils/cropGhost.js';
|
|
30
30
|
import { cropKeyOf, userImageKeyCrop } from '../utils/keyboardCrop.js';
|
|
31
31
|
import { hasCorners, sameCorners } from '../utils/cornerRadius.js';
|
|
32
32
|
import { photoPlaceholderLook } from '../utils/photoPlaceholder.js';
|
|
@@ -52,6 +52,7 @@ function UserImagePrimitiveInner({ userImage, isSelected, onSelect, onDragEnd, o
|
|
|
52
52
|
const cropTransformerRef = useRef(null);
|
|
53
53
|
const groupRef = useRef(null);
|
|
54
54
|
const imageRef = useRef(null);
|
|
55
|
+
const ghostRef = useRef(null);
|
|
55
56
|
const captureRatio = usePreviewCaptureRatio();
|
|
56
57
|
const transformerRef = useRef(null);
|
|
57
58
|
const [image, setImage] = useState(null);
|
|
@@ -119,50 +120,12 @@ function UserImagePrimitiveInner({ userImage, isSelected, onSelect, onDragEnd, o
|
|
|
119
120
|
if (!same)
|
|
120
121
|
onCropEnd?.(userImageCropUpdate(userImage, natural, photo, window));
|
|
121
122
|
}, [aspectActive, cropAspect, image, userImage, onCropEnd]);
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
cacheFiltered(node, captureRatio);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
node.clearCache();
|
|
132
|
-
}
|
|
133
|
-
node.getLayer()?.batchDraw();
|
|
134
|
-
}, [
|
|
135
|
-
image,
|
|
136
|
-
captureRatio,
|
|
137
|
-
userImage.width,
|
|
138
|
-
userImage.height,
|
|
139
|
-
userImage.blur,
|
|
140
|
-
userImage.brightness,
|
|
141
|
-
userImage.contrast,
|
|
142
|
-
userImage.saturation,
|
|
143
|
-
userImage.hue,
|
|
144
|
-
userImage.temperature,
|
|
145
|
-
userImage.grayscale,
|
|
146
|
-
userImage.sepia,
|
|
147
|
-
userImage.invert,
|
|
148
|
-
userImage.tint,
|
|
149
|
-
userImage.tintStrength,
|
|
150
|
-
userImage.duotoneLow,
|
|
151
|
-
userImage.duotoneHigh,
|
|
152
|
-
userImage.vignette,
|
|
153
|
-
userImage.flipX,
|
|
154
|
-
userImage.flipY,
|
|
155
|
-
userImage.fit,
|
|
156
|
-
userImage.cropZoom,
|
|
157
|
-
userImage.panX,
|
|
158
|
-
userImage.panY,
|
|
159
|
-
userImage.cropRotation,
|
|
160
|
-
userImage.mask,
|
|
161
|
-
]);
|
|
162
|
-
// Das Restbild trägt dieselbe Bearbeitung wie das Bild im Rahmen.
|
|
163
|
-
const ghostImage = useMemo(() => cropping && image
|
|
164
|
-
? cropGhostSource(image, userImage, userImage.width * (userImage.cropZoom ?? 1))
|
|
165
|
-
: null, [cropping, image, userImage]);
|
|
123
|
+
// The look is a bitmap made once per look (`useLookBitmap`); panning, zooming and the crop
|
|
124
|
+
// frame only move the crop. The dimmed rest of the photo shows the same bitmap.
|
|
125
|
+
const lookPhotoWidth = image && userImage.fit === 'cover'
|
|
126
|
+
? straightFramedPhoto({ width: image.naturalWidth, height: image.naturalHeight }, { width: userImage.width, height: userImage.height }, { x: 0, y: 0 }, userImage.cropZoom ?? 1, userImage.cropRotation ?? 0).width
|
|
127
|
+
: userImage.width;
|
|
128
|
+
useLookBitmap([imageRef, ghostRef], image, userImage, null, lookPhotoWidth, captureRatio, cropping);
|
|
166
129
|
const keyCropRef = useRef({ image, userImage, onCropEnd });
|
|
167
130
|
useEffect(() => {
|
|
168
131
|
keyCropRef.current = { image, userImage, onCropEnd };
|
|
@@ -243,7 +206,7 @@ function UserImagePrimitiveInner({ userImage, isSelected, onSelect, onDragEnd, o
|
|
|
243
206
|
const natural = { width: image.naturalWidth, height: image.naturalHeight };
|
|
244
207
|
const frame = { x: 0, y: 0, width, height };
|
|
245
208
|
const cover = userImage.fit === 'cover';
|
|
246
|
-
// Begradigt: das Foto dreht sich im Rahmen; Konvas `crop` kann das nicht, `
|
|
209
|
+
// Begradigt: das Foto dreht sich im Rahmen; Konvas `crop` kann das nicht, `lookSceneFunc` zeichnet.
|
|
247
210
|
const deg = cover ? (userImage.cropRotation ?? 0) : 0;
|
|
248
211
|
const turned = deg !== 0;
|
|
249
212
|
const keptPan = { x: userImage.panX ?? 0, y: userImage.panY ?? 0 };
|
|
@@ -286,7 +249,6 @@ function UserImagePrimitiveInner({ userImage, isSelected, onSelect, onDragEnd, o
|
|
|
286
249
|
node.position({ x: placed.x, y: placed.y });
|
|
287
250
|
if (imageRef.current) {
|
|
288
251
|
imageRef.current.setAttr(STRAIGHT_DRAW_ATTR, straightDrawOf(moved, deg, frame, mirror));
|
|
289
|
-
recacheNextFrame(imageRef.current);
|
|
290
252
|
}
|
|
291
253
|
return moved;
|
|
292
254
|
}
|
|
@@ -296,11 +258,10 @@ function UserImagePrimitiveInner({ userImage, isSelected, onSelect, onDragEnd, o
|
|
|
296
258
|
const part = visiblePart(natural, moved, frame, mirror);
|
|
297
259
|
if (part && imageRef.current) {
|
|
298
260
|
imageRef.current.crop(part.crop);
|
|
299
|
-
recacheNextFrame(imageRef.current);
|
|
300
261
|
}
|
|
301
262
|
return moved;
|
|
302
263
|
};
|
|
303
|
-
return (_jsxs(_Fragment, { children: [_jsxs(Group, { ref: groupRef, ...groupProps, draggable: draggable && !isCropping && !locked, onDblClick: () => !locked && onCroppingChange?.(!cropping), onDblTap: () => !locked && onCroppingChange?.(!cropping), children: [isCropping && photo && (_jsx(Image, { name: `selection-chrome ${CROP_GHOST_NAME}`, image:
|
|
264
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Group, { ref: groupRef, ...groupProps, draggable: draggable && !isCropping && !locked, onDblClick: () => !locked && onCroppingChange?.(!cropping), onDblTap: () => !locked && onCroppingChange?.(!cropping), children: [isCropping && photo && (_jsx(Image, { ref: ghostRef, name: `selection-chrome ${CROP_GHOST_NAME}`, image: image, sceneFunc: drawsLook(userImage, null) ? lookSceneFunc : undefined, ...(turned
|
|
304
265
|
? cropGhostAttrs(photo, mirror, deg)
|
|
305
266
|
: {
|
|
306
267
|
x: photo.x + ghostShift.x,
|
|
@@ -327,7 +288,7 @@ function UserImagePrimitiveInner({ userImage, isSelected, onSelect, onDragEnd, o
|
|
|
327
288
|
? panOfStraightPhoto(moved, deg, frame, keptPan)
|
|
328
289
|
: panOfFramedPhoto(moved, frame);
|
|
329
290
|
onCropEnd?.({ fit: 'cover', panX: pan.x, panY: pan.y });
|
|
330
|
-
} })), notchClipped(_jsx(Image, { ref: imageRef, name: USER_PHOTO_NODE_NAME, listening: !isCropping, image: image, width: width, height: height, crop: crop, cornerRadius: cornerRadius,
|
|
291
|
+
} })), notchClipped(_jsx(Image, { ref: imageRef, name: USER_PHOTO_NODE_NAME, listening: !isCropping, image: image, width: width, height: height, crop: crop, cornerRadius: cornerRadius, ...lookDrawAttrs(userImage), sceneFunc: draw || drawsLook(userImage, null) ? lookSceneFunc : undefined, shadowColor: userImage.shadowColor, shadowBlur: userImage.shadowBlur, shadowOffsetX: userImage.shadowOffsetX, shadowOffsetY: userImage.shadowOffsetY, shadowOpacity: userImage.shadowOpacity, ...(draw ? { [STRAIGHT_DRAW_ATTR]: draw } : {}) })), isCropping && (_jsxs(_Fragment, { children: [_jsx(Rect, { ref: cropFrameRef, name: "selection-chrome", width: width, height: height, listening: false, onTransform: (e) => {
|
|
331
292
|
e.cancelBubble = true;
|
|
332
293
|
const node = cropFrameRef.current;
|
|
333
294
|
const drawn = imageRef.current;
|
|
@@ -343,7 +304,6 @@ function UserImagePrimitiveInner({ userImage, isSelected, onSelect, onDragEnd, o
|
|
|
343
304
|
drawn.position(window);
|
|
344
305
|
drawn.size(window);
|
|
345
306
|
drawn.setAttr(STRAIGHT_DRAW_ATTR, straightDrawOf(photo, deg, window, mirror));
|
|
346
|
-
recacheNextFrame(drawn);
|
|
347
307
|
return;
|
|
348
308
|
}
|
|
349
309
|
const part = visiblePart(natural, photo, window, mirror);
|
|
@@ -351,7 +311,6 @@ function UserImagePrimitiveInner({ userImage, isSelected, onSelect, onDragEnd, o
|
|
|
351
311
|
drawn.position(part.box);
|
|
352
312
|
drawn.size(part.box);
|
|
353
313
|
drawn.crop(part.crop);
|
|
354
|
-
recacheNextFrame(drawn);
|
|
355
314
|
}
|
|
356
315
|
}, onTransformEnd: (e) => {
|
|
357
316
|
e.cancelBubble = true;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import Konva from 'konva';
|
|
2
|
-
import type { ImageAdjustments } from './userImageUtils.js';
|
|
1
|
+
import type Konva from 'konva';
|
|
3
2
|
import type { Mirror, Rect } from './coverFit.js';
|
|
4
3
|
/**
|
|
5
4
|
* Konva-Name des abgedunkelten ganzen Fotos im Zuschneide-Modus (Hintergrund
|
|
@@ -53,12 +52,3 @@ export declare function visibleContainerRect(container: HTMLElement): Rect | nul
|
|
|
53
52
|
* Ohne sichtbares Restbild wird `canvas` ausgeblendet.
|
|
54
53
|
*/
|
|
55
54
|
export declare function paintCropGhosts(stage: Konva.Stage, canvas: HTMLCanvasElement, visible?: Rect | null): void;
|
|
56
|
-
/**
|
|
57
|
-
* Die Bildquelle des Restbilds mit dem Look des Fotos („Bearbeiten"-Filter,
|
|
58
|
-
* Einfärbung), einmal auf eine verkleinerte Kopie gerechnet statt per Cache
|
|
59
|
-
* auf dem ganzen, oft vielfach gezoomten Restbild. Spiegeln bleibt außen vor:
|
|
60
|
-
* das Restbild spiegelt über seine Skalierung. `displayedWidth` ist die Breite
|
|
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).
|
|
63
|
-
*/
|
|
64
|
-
export declare function cropGhostSource(image: HTMLImageElement, adjustments: ImageAdjustments | null, displayedWidth: number, color?: string | null, maxSide?: number): CanvasImageSource;
|
package/dist/utils/cropGhost.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
-
import
|
|
3
|
-
import { getActiveImageFilters, imageFilterAttrs } from './imageFilters.js';
|
|
2
|
+
import { LOOK_IMAGE_ATTR } from './lookBitmap.js';
|
|
4
3
|
/**
|
|
5
4
|
* Konva-Name des abgedunkelten ganzen Fotos im Zuschneide-Modus (Hintergrund
|
|
6
5
|
* und eigene Bilder). Die Bühne endet an der Seite; was darüber hinausragt,
|
|
@@ -159,59 +158,11 @@ export function paintCropGhosts(stage, canvas, visible = null) {
|
|
|
159
158
|
ctx.setTransform(...toOverlay);
|
|
160
159
|
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
161
160
|
ctx.globalAlpha = node.getAbsoluteOpacity();
|
|
162
|
-
|
|
161
|
+
// The look bitmap, when the photo has one (`useLookBitmap`); the mirror is in the matrix.
|
|
162
|
+
const source = node.getAttr(LOOK_IMAGE_ATTR) ?? node.image();
|
|
163
|
+
ctx.drawImage(source, 0, 0, width, height);
|
|
163
164
|
}
|
|
164
165
|
ctx.setTransform(...toOverlay);
|
|
165
166
|
ctx.globalAlpha = 1;
|
|
166
167
|
ctx.clearRect(0, 0, stage.width(), stage.height());
|
|
167
168
|
}
|
|
168
|
-
// Längste Kante der gefilterten Restbild-Vorlage; abgedunkelt braucht es keine volle Auflösung.
|
|
169
|
-
const GHOST_SOURCE_SIDE = 1024;
|
|
170
|
-
/**
|
|
171
|
-
* Die Bildquelle des Restbilds mit dem Look des Fotos („Bearbeiten"-Filter,
|
|
172
|
-
* Einfärbung), einmal auf eine verkleinerte Kopie gerechnet statt per Cache
|
|
173
|
-
* auf dem ganzen, oft vielfach gezoomten Restbild. Spiegeln bleibt außen vor:
|
|
174
|
-
* das Restbild spiegelt über seine Skalierung. `displayedWidth` ist die Breite
|
|
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).
|
|
177
|
-
*/
|
|
178
|
-
export function cropGhostSource(image, adjustments, displayedWidth, color = null, maxSide = GHOST_SOURCE_SIDE) {
|
|
179
|
-
const look = adjustments ? { ...adjustments, flipX: false, flipY: false } : null;
|
|
180
|
-
const filters = [
|
|
181
|
-
...(color ? [Konva.Filters.RGB] : []),
|
|
182
|
-
...(look ? getActiveImageFilters(look) : []),
|
|
183
|
-
];
|
|
184
|
-
const natural = { width: image.naturalWidth, height: image.naturalHeight };
|
|
185
|
-
if (filters.length === 0 || !natural.width || !natural.height)
|
|
186
|
-
return image;
|
|
187
|
-
const scale = Math.min(1, maxSide / Math.max(natural.width, natural.height));
|
|
188
|
-
const width = Math.max(1, Math.round(natural.width * scale));
|
|
189
|
-
const height = Math.max(1, Math.round(natural.height * scale));
|
|
190
|
-
const canvas = document.createElement('canvas');
|
|
191
|
-
canvas.width = width;
|
|
192
|
-
canvas.height = height;
|
|
193
|
-
const ctx = canvas.getContext('2d');
|
|
194
|
-
if (!ctx)
|
|
195
|
-
return image;
|
|
196
|
-
ctx.drawImage(image, 0, 0, width, height);
|
|
197
|
-
// Die Filter lesen ihre Werte vom Knoten (`this`), wie in Konvas Cache.
|
|
198
|
-
const attrs = new Konva.Image({
|
|
199
|
-
image,
|
|
200
|
-
...(look ? imageFilterAttrs(look) : {}),
|
|
201
|
-
blurRadius: ((look?.blur ?? 0) * width) / Math.max(1, displayedWidth),
|
|
202
|
-
...(color
|
|
203
|
-
? {
|
|
204
|
-
red: parseInt(color.slice(1, 3), 16),
|
|
205
|
-
green: parseInt(color.slice(3, 5), 16),
|
|
206
|
-
blue: parseInt(color.slice(5, 7), 16),
|
|
207
|
-
}
|
|
208
|
-
: {}),
|
|
209
|
-
});
|
|
210
|
-
const data = ctx.getImageData(0, 0, width, height);
|
|
211
|
-
for (const filter of filters)
|
|
212
|
-
if (typeof filter === 'function')
|
|
213
|
-
filter.call(attrs, data);
|
|
214
|
-
ctx.putImageData(data, 0, 0);
|
|
215
|
-
attrs.destroy();
|
|
216
|
-
return canvas;
|
|
217
|
-
}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import Konva from 'konva';
|
|
2
1
|
/**
|
|
3
2
|
* On a canvas drawn only to be captured once (a gallery or page preview): the output pixels per
|
|
4
3
|
* page pixel of that capture. Null in the editor.
|
|
5
4
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* so a full-size capture (the render gate) stays sharp. The editor keeps the full cache, so
|
|
11
|
-
* zooming in stays sharp.
|
|
5
|
+
* A photo's look bitmap (`lookBitmap`) is sized from it: the editor filters at the device ratio,
|
|
6
|
+
* a preview at what it draws or captures, whichever is larger, so a full-size capture (the
|
|
7
|
+
* render gate) stays sharp. Filtering a preview at page size held one frame for 308 ms (a
|
|
8
|
+
* duotone photo at 4x CPU throttling, 01.11.2026).
|
|
12
9
|
*/
|
|
13
10
|
export declare const PreviewRenderContext: import("react").Context<number | null>;
|
|
14
11
|
export declare function usePreviewCaptureRatio(): number | null;
|
|
15
|
-
/** Caches a filtered node; on a preview at the resolution it is drawn or captured at. */
|
|
16
|
-
export declare function cacheFiltered(node: Konva.Node, captureRatio: number | null): void;
|
|
@@ -1,31 +1,15 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
-
import Konva from 'konva';
|
|
3
2
|
import { createContext, useContext } from 'react';
|
|
4
3
|
/**
|
|
5
4
|
* On a canvas drawn only to be captured once (a gallery or page preview): the output pixels per
|
|
6
5
|
* page pixel of that capture. Null in the editor.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* so a full-size capture (the render gate) stays sharp. The editor keeps the full cache, so
|
|
13
|
-
* zooming in stays sharp.
|
|
7
|
+
* A photo's look bitmap (`lookBitmap`) is sized from it: the editor filters at the device ratio,
|
|
8
|
+
* a preview at what it draws or captures, whichever is larger, so a full-size capture (the
|
|
9
|
+
* render gate) stays sharp. Filtering a preview at page size held one frame for 308 ms (a
|
|
10
|
+
* duotone photo at 4x CPU throttling, 01.11.2026).
|
|
14
11
|
*/
|
|
15
12
|
export const PreviewRenderContext = createContext(null);
|
|
16
13
|
export function usePreviewCaptureRatio() {
|
|
17
14
|
return useContext(PreviewRenderContext);
|
|
18
15
|
}
|
|
19
|
-
/** Caches a filtered node; on a preview at the resolution it is drawn or captured at. */
|
|
20
|
-
export function cacheFiltered(node, captureRatio) {
|
|
21
|
-
if (captureRatio === null) {
|
|
22
|
-
node.cache();
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const absolute = node.getAbsoluteScale().x;
|
|
26
|
-
// The stage carries the display scale; what remains is the node's scale within the page.
|
|
27
|
-
const withinPage = absolute / (node.getStage()?.scaleX() || 1);
|
|
28
|
-
node.cache({
|
|
29
|
-
pixelRatio: Math.max(absolute * Konva.pixelRatio, withinPage * captureRatio),
|
|
30
|
-
});
|
|
31
|
-
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The look of a photo ("Bearbeiten" adjustments, the background tint) as a bitmap made once per
|
|
3
|
+
* look, not as Konva filters run while drawing.
|
|
4
|
+
*
|
|
5
|
+
* A Konva filter runs over the node's cache, and the cache holds the drawn crop: every pan, zoom
|
|
6
|
+
* or crop-frame drag cleared it and ran every filter again, one full pass per pointer move (#197).
|
|
7
|
+
* Here the colour filters run once over the whole photo (`lookBitmap`), and the node draws that
|
|
8
|
+
* bitmap with its ordinary crop (`lookSceneFunc`); moving the crop costs a `drawImage`.
|
|
9
|
+
*
|
|
10
|
+
* Two parts of the look depend on the drawn frame, not the photo, and stay with the drawing:
|
|
11
|
+
* the flip mirrors the drawn frame (as the filter mirrored the cache, which the crop geometry
|
|
12
|
+
* relies on) and the vignette darkens towards the frame's edges. The node keeps the photo as its
|
|
13
|
+
* `image` and its crop in photo pixels, so geometry, hit area and print DPI read what they read.
|
|
14
|
+
*/
|
|
15
|
+
import Konva from 'konva';
|
|
16
|
+
import type { ImageAdjustments } from './userImageUtils.js';
|
|
17
|
+
/** Node attr holding the look bitmap the node draws instead of its `image`. */
|
|
18
|
+
export declare const LOOK_IMAGE_ATTR = "lookImage";
|
|
19
|
+
/**
|
|
20
|
+
* Largest look bitmap, in pixels: iOS WebKit silently drops a canvas above 16 777 216 px. A photo
|
|
21
|
+
* larger than that at the resolution asked for is filtered smaller.
|
|
22
|
+
*/
|
|
23
|
+
export declare const LOOK_MAX_AREA = 16777216;
|
|
24
|
+
/** Size of the quick bitmap shown while a look changes fast (a slider drag). */
|
|
25
|
+
export declare const LOOK_QUICK_AREA = 1500000;
|
|
26
|
+
/** What the colour filters read, as a key; null when the look has no colour filter. */
|
|
27
|
+
export declare function lookKey(adjustments: ImageAdjustments | null, color: string | null): string | null;
|
|
28
|
+
/** Whether the node must draw through `lookSceneFunc`: a colour filter, a flip or a vignette. */
|
|
29
|
+
export declare function drawsLook(adjustments: ImageAdjustments | null, color: string | null): boolean;
|
|
30
|
+
/** Node attrs `lookSceneFunc` reads: the flip and the vignette. */
|
|
31
|
+
export declare function lookDrawAttrs(adjustments: ImageAdjustments | null): {
|
|
32
|
+
flipX: boolean;
|
|
33
|
+
flipY: boolean;
|
|
34
|
+
vignette: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Device pixels per node unit the node is drawn at. The editor matches what Konva's own cache
|
|
38
|
+
* held (the device ratio, whatever the stage zoom); a preview draws at what it draws or captures,
|
|
39
|
+
* whichever is larger, so a full-size capture (the render gate) stays sharp.
|
|
40
|
+
*/
|
|
41
|
+
export declare function lookPixelRatio(node: Konva.Node, captureRatio: number | null): number;
|
|
42
|
+
/**
|
|
43
|
+
* Size of the bitmap of a photo drawn `photoWidth` node units wide at `pixelRatio`: never larger
|
|
44
|
+
* than the photo, nor than `maxArea`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function lookBitmapSize(natural: {
|
|
47
|
+
width: number;
|
|
48
|
+
height: number;
|
|
49
|
+
}, photoWidth: number, pixelRatio: number, maxArea?: number): {
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
};
|
|
53
|
+
/** An already built bitmap of this look at least `width` wide, if there is one. */
|
|
54
|
+
export declare function builtLookBitmap(image: HTMLImageElement, key: string, width: number): HTMLCanvasElement | null;
|
|
55
|
+
/**
|
|
56
|
+
* The photo with its colour filters applied, at least `size` (an equal or larger bitmap of the
|
|
57
|
+
* same look is reused), or the photo itself when the look has no colour filter. The blur radius
|
|
58
|
+
* is in node units, as on the node: `photoWidth` is how wide the whole photo is drawn.
|
|
59
|
+
*/
|
|
60
|
+
export declare function lookBitmap(image: HTMLImageElement, adjustments: ImageAdjustments | null, color: string | null, photoWidth: number, size: {
|
|
61
|
+
width: number;
|
|
62
|
+
height: number;
|
|
63
|
+
}): CanvasImageSource;
|
|
64
|
+
/**
|
|
65
|
+
* Darkens `ctx`'s pixels towards the edges of `width` × `height` by `strength`, the curve of the
|
|
66
|
+
* former vignette filter: k = 1 − strength·smoothstep(t), t = (r − 0.35) / 0.65, r the distance
|
|
67
|
+
* from the middle with the corners at 1. Black at alpha 1 − k drawn `source-atop` multiplies each
|
|
68
|
+
* pixel's colour by k and keeps its alpha, so a cut-out stays cut out.
|
|
69
|
+
*/
|
|
70
|
+
export declare function paintVignette(ctx: CanvasRenderingContext2D, width: number, height: number, strength: number): void;
|
|
71
|
+
/**
|
|
72
|
+
* Scene function of a photo with a look, and of a straightened one: the look bitmap with the
|
|
73
|
+
* node's crop, the flip, and the vignette over the drawn frame.
|
|
74
|
+
*/
|
|
75
|
+
export declare function lookSceneFunc(context: Konva.Context, shape: Konva.Shape): void;
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
/**
|
|
3
|
+
* The look of a photo ("Bearbeiten" adjustments, the background tint) as a bitmap made once per
|
|
4
|
+
* look, not as Konva filters run while drawing.
|
|
5
|
+
*
|
|
6
|
+
* A Konva filter runs over the node's cache, and the cache holds the drawn crop: every pan, zoom
|
|
7
|
+
* or crop-frame drag cleared it and ran every filter again, one full pass per pointer move (#197).
|
|
8
|
+
* Here the colour filters run once over the whole photo (`lookBitmap`), and the node draws that
|
|
9
|
+
* bitmap with its ordinary crop (`lookSceneFunc`); moving the crop costs a `drawImage`.
|
|
10
|
+
*
|
|
11
|
+
* Two parts of the look depend on the drawn frame, not the photo, and stay with the drawing:
|
|
12
|
+
* the flip mirrors the drawn frame (as the filter mirrored the cache, which the crop geometry
|
|
13
|
+
* relies on) and the vignette darkens towards the frame's edges. The node keeps the photo as its
|
|
14
|
+
* `image` and its crop in photo pixels, so geometry, hit area and print DPI read what they read.
|
|
15
|
+
*/
|
|
16
|
+
import Konva from 'konva';
|
|
17
|
+
import { cornersOf, hasCorners, traceRoundedRect } from './cornerRadius.js';
|
|
18
|
+
import { getActiveImageFilters, imageFilterAttrs } from './imageFilters.js';
|
|
19
|
+
import { STRAIGHT_DRAW_ATTR } from './straighten.js';
|
|
20
|
+
/** Node attr holding the look bitmap the node draws instead of its `image`. */
|
|
21
|
+
export const LOOK_IMAGE_ATTR = 'lookImage';
|
|
22
|
+
/**
|
|
23
|
+
* Largest look bitmap, in pixels: iOS WebKit silently drops a canvas above 16 777 216 px. A photo
|
|
24
|
+
* larger than that at the resolution asked for is filtered smaller.
|
|
25
|
+
*/
|
|
26
|
+
export const LOOK_MAX_AREA = 16_777_216;
|
|
27
|
+
/** Size of the quick bitmap shown while a look changes fast (a slider drag). */
|
|
28
|
+
export const LOOK_QUICK_AREA = 1_500_000;
|
|
29
|
+
/** The look without the frame-bound flip and vignette. */
|
|
30
|
+
function colourLook(adjustments) {
|
|
31
|
+
return adjustments ? { ...adjustments, flipX: false, flipY: false, vignette: 0 } : null;
|
|
32
|
+
}
|
|
33
|
+
/** The look's colour filters: everything but the flip and the vignette. */
|
|
34
|
+
function colourFilters(adjustments, color) {
|
|
35
|
+
const look = colourLook(adjustments);
|
|
36
|
+
return [...(color ? [Konva.Filters.RGB] : []), ...(look ? getActiveImageFilters(look) : [])];
|
|
37
|
+
}
|
|
38
|
+
/** What the colour filters read, as a key; null when the look has no colour filter. */
|
|
39
|
+
export function lookKey(adjustments, color) {
|
|
40
|
+
if (colourFilters(adjustments, color).length === 0)
|
|
41
|
+
return null;
|
|
42
|
+
const look = colourLook(adjustments);
|
|
43
|
+
return JSON.stringify([
|
|
44
|
+
color,
|
|
45
|
+
look && imageFilterAttrs(look),
|
|
46
|
+
// The switches put a filter in the list instead of setting an attr.
|
|
47
|
+
look && [!!look.grayscale, !!look.sepia, !!look.invert],
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
/** Whether the node must draw through `lookSceneFunc`: a colour filter, a flip or a vignette. */
|
|
51
|
+
export function drawsLook(adjustments, color) {
|
|
52
|
+
return (lookKey(adjustments, color) !== null ||
|
|
53
|
+
!!adjustments?.flipX ||
|
|
54
|
+
!!adjustments?.flipY ||
|
|
55
|
+
(adjustments?.vignette ?? 0) > 0);
|
|
56
|
+
}
|
|
57
|
+
/** Node attrs `lookSceneFunc` reads: the flip and the vignette. */
|
|
58
|
+
export function lookDrawAttrs(adjustments) {
|
|
59
|
+
return {
|
|
60
|
+
flipX: !!adjustments?.flipX,
|
|
61
|
+
flipY: !!adjustments?.flipY,
|
|
62
|
+
vignette: adjustments?.vignette ?? 0,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Device pixels per node unit the node is drawn at. The editor matches what Konva's own cache
|
|
67
|
+
* held (the device ratio, whatever the stage zoom); a preview draws at what it draws or captures,
|
|
68
|
+
* whichever is larger, so a full-size capture (the render gate) stays sharp.
|
|
69
|
+
*/
|
|
70
|
+
export function lookPixelRatio(node, captureRatio) {
|
|
71
|
+
if (captureRatio === null)
|
|
72
|
+
return Konva.pixelRatio;
|
|
73
|
+
const absolute = Math.abs(node.getAbsoluteScale().x);
|
|
74
|
+
// The stage carries the display scale; what remains is the node's scale within the page.
|
|
75
|
+
const withinPage = absolute / (node.getStage()?.scaleX() || 1);
|
|
76
|
+
return Math.max(absolute * Konva.pixelRatio, withinPage * captureRatio);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Size of the bitmap of a photo drawn `photoWidth` node units wide at `pixelRatio`: never larger
|
|
80
|
+
* than the photo, nor than `maxArea`.
|
|
81
|
+
*/
|
|
82
|
+
export function lookBitmapSize(natural, photoWidth, pixelRatio, maxArea = LOOK_MAX_AREA) {
|
|
83
|
+
const wanted = (photoWidth * pixelRatio) / natural.width;
|
|
84
|
+
const areaLimit = Math.sqrt(maxArea / (natural.width * natural.height));
|
|
85
|
+
const scale = Math.min(1, wanted, areaLimit);
|
|
86
|
+
return {
|
|
87
|
+
width: Math.max(1, Math.round(natural.width * scale)),
|
|
88
|
+
height: Math.max(1, Math.round(natural.height * scale)),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// Per photo the looks built last; the background, a framed photo and its dimmed rest share them.
|
|
92
|
+
const built = new WeakMap();
|
|
93
|
+
const KEPT_PER_IMAGE = 2;
|
|
94
|
+
/** An already built bitmap of this look at least `width` wide, if there is one. */
|
|
95
|
+
export function builtLookBitmap(image, key, width) {
|
|
96
|
+
return built.get(image)?.find((e) => e.key === key && e.bitmap.width >= width)?.bitmap ?? null;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The photo with its colour filters applied, at least `size` (an equal or larger bitmap of the
|
|
100
|
+
* same look is reused), or the photo itself when the look has no colour filter. The blur radius
|
|
101
|
+
* is in node units, as on the node: `photoWidth` is how wide the whole photo is drawn.
|
|
102
|
+
*/
|
|
103
|
+
export function lookBitmap(image, adjustments, color, photoWidth, size) {
|
|
104
|
+
const key = lookKey(adjustments, color);
|
|
105
|
+
if (key === null || !image.naturalWidth || !image.naturalHeight || photoWidth <= 0)
|
|
106
|
+
return image;
|
|
107
|
+
const hit = builtLookBitmap(image, key, size.width);
|
|
108
|
+
if (hit)
|
|
109
|
+
return hit;
|
|
110
|
+
const canvas = document.createElement('canvas');
|
|
111
|
+
canvas.width = size.width;
|
|
112
|
+
canvas.height = size.height;
|
|
113
|
+
const ctx = canvas.getContext('2d', { willReadFrequently: true });
|
|
114
|
+
if (!ctx)
|
|
115
|
+
return image;
|
|
116
|
+
ctx.drawImage(image, 0, 0, size.width, size.height);
|
|
117
|
+
// The filters read their values off a node (`this`), as in Konva's cache.
|
|
118
|
+
const look = colourLook(adjustments);
|
|
119
|
+
const attrs = new Konva.Image({
|
|
120
|
+
image,
|
|
121
|
+
...(look ? imageFilterAttrs(look) : {}),
|
|
122
|
+
...(color
|
|
123
|
+
? {
|
|
124
|
+
red: parseInt(color.slice(1, 3), 16),
|
|
125
|
+
green: parseInt(color.slice(3, 5), 16),
|
|
126
|
+
blue: parseInt(color.slice(5, 7), 16),
|
|
127
|
+
}
|
|
128
|
+
: {}),
|
|
129
|
+
});
|
|
130
|
+
const data = ctx.getImageData(0, 0, size.width, size.height);
|
|
131
|
+
// Konva scales the blur radius by the pixels per node unit it filters at.
|
|
132
|
+
const ratio = size.width / photoWidth;
|
|
133
|
+
for (const filter of colourFilters(adjustments, color)) {
|
|
134
|
+
if (typeof filter === 'function')
|
|
135
|
+
filter.call(attrs, data, ratio);
|
|
136
|
+
}
|
|
137
|
+
ctx.putImageData(data, 0, 0);
|
|
138
|
+
attrs.destroy();
|
|
139
|
+
const kept = (built.get(image) ?? []).filter((e) => e.key !== key);
|
|
140
|
+
built.set(image, [{ key, bitmap: canvas }, ...kept].slice(0, KEPT_PER_IMAGE));
|
|
141
|
+
return canvas;
|
|
142
|
+
}
|
|
143
|
+
/** The photo as Konva's image would draw it, from the look bitmap, flipped as the look says. */
|
|
144
|
+
function drawPhoto(ctx, shape, width, height) {
|
|
145
|
+
const photo = shape.getAttr('image');
|
|
146
|
+
if (!photo)
|
|
147
|
+
return;
|
|
148
|
+
const source = shape.getAttr(LOOK_IMAGE_ATTR) ?? photo;
|
|
149
|
+
const flipX = !!shape.getAttr('flipX');
|
|
150
|
+
const flipY = !!shape.getAttr('flipY');
|
|
151
|
+
ctx.save();
|
|
152
|
+
if (flipX || flipY) {
|
|
153
|
+
// The flip mirrors the drawn frame, corners and all, as the flip filter mirrored the cache.
|
|
154
|
+
ctx.translate(flipX ? width : 0, flipY ? height : 0);
|
|
155
|
+
ctx.scale(flipX ? -1 : 1, flipY ? -1 : 1);
|
|
156
|
+
}
|
|
157
|
+
const draw = shape.getAttr(STRAIGHT_DRAW_ATTR);
|
|
158
|
+
if (draw) {
|
|
159
|
+
// Begradigt: das ganze Foto gedreht im Rahmen, beschnitten auf den Rahmen.
|
|
160
|
+
const radius = shape.getAttr('cornerRadius');
|
|
161
|
+
ctx.beginPath();
|
|
162
|
+
if (hasCorners(radius))
|
|
163
|
+
traceRoundedRect(ctx, width, height, cornersOf(radius, width, height));
|
|
164
|
+
else
|
|
165
|
+
ctx.rect(0, 0, width, height);
|
|
166
|
+
ctx.closePath();
|
|
167
|
+
ctx.clip();
|
|
168
|
+
ctx.translate(draw.x, draw.y);
|
|
169
|
+
ctx.rotate((draw.rotation * Math.PI) / 180);
|
|
170
|
+
ctx.drawImage(source, -draw.width / 2, -draw.height / 2, draw.width, draw.height);
|
|
171
|
+
ctx.restore();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// As Konva.Image draws itself (no fill or stroke: photos carry neither).
|
|
175
|
+
const cornerRadius = shape.cornerRadius();
|
|
176
|
+
if (cornerRadius) {
|
|
177
|
+
ctx.beginPath();
|
|
178
|
+
Konva.Util.drawRoundedRectPath(ctx, width, height, cornerRadius);
|
|
179
|
+
ctx.closePath();
|
|
180
|
+
ctx.clip();
|
|
181
|
+
}
|
|
182
|
+
const cropWidth = shape.getAttr('cropWidth');
|
|
183
|
+
const cropHeight = shape.getAttr('cropHeight');
|
|
184
|
+
if (cropWidth && cropHeight) {
|
|
185
|
+
// The crop is in photo pixels; the bitmap may be smaller.
|
|
186
|
+
const s = Number(source.width) / (photo.naturalWidth || photo.width);
|
|
187
|
+
const cropX = shape.getAttr('cropX') ?? 0;
|
|
188
|
+
const cropY = shape.getAttr('cropY') ?? 0;
|
|
189
|
+
ctx.drawImage(source, cropX * s, cropY * s, cropWidth * s, cropHeight * s, 0, 0, width, height);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
ctx.drawImage(source, 0, 0, width, height);
|
|
193
|
+
}
|
|
194
|
+
ctx.restore();
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Darkens `ctx`'s pixels towards the edges of `width` × `height` by `strength`, the curve of the
|
|
198
|
+
* former vignette filter: k = 1 − strength·smoothstep(t), t = (r − 0.35) / 0.65, r the distance
|
|
199
|
+
* from the middle with the corners at 1. Black at alpha 1 − k drawn `source-atop` multiplies each
|
|
200
|
+
* pixel's colour by k and keeps its alpha, so a cut-out stays cut out.
|
|
201
|
+
*/
|
|
202
|
+
export function paintVignette(ctx, width, height, strength) {
|
|
203
|
+
// r = |(dx, dy)| / √2 with dx, dy ∈ [−1, 1]: in a box scaled to 2 × 2 a circle of radius √2.
|
|
204
|
+
ctx.save();
|
|
205
|
+
ctx.translate(width / 2, height / 2);
|
|
206
|
+
ctx.scale(width / 2, height / 2);
|
|
207
|
+
const gradient = ctx.createRadialGradient(0, 0, 0.35 * Math.SQRT2, 0, 0, Math.SQRT2);
|
|
208
|
+
const STOPS = 32;
|
|
209
|
+
for (let i = 0; i <= STOPS; i++) {
|
|
210
|
+
const t = i / STOPS;
|
|
211
|
+
gradient.addColorStop(t, `rgba(0,0,0,${strength * t * t * (3 - 2 * t)})`);
|
|
212
|
+
}
|
|
213
|
+
ctx.globalCompositeOperation = 'source-atop';
|
|
214
|
+
ctx.fillStyle = gradient;
|
|
215
|
+
ctx.fillRect(-1, -1, 2, 2);
|
|
216
|
+
ctx.restore();
|
|
217
|
+
}
|
|
218
|
+
// One reusable canvas per node for the vignette. A recording context gets a fresh one: a
|
|
219
|
+
// recorded `drawImage` keeps the canvas it was handed and reads it later.
|
|
220
|
+
const scratch = new WeakMap();
|
|
221
|
+
function vignetteCanvas(shape, reuse, width, height) {
|
|
222
|
+
let canvas = reuse ? scratch.get(shape) : undefined;
|
|
223
|
+
if (!canvas) {
|
|
224
|
+
canvas = document.createElement('canvas');
|
|
225
|
+
if (reuse)
|
|
226
|
+
scratch.set(shape, canvas);
|
|
227
|
+
}
|
|
228
|
+
if (canvas.width !== width || canvas.height !== height) {
|
|
229
|
+
canvas.width = width;
|
|
230
|
+
canvas.height = height;
|
|
231
|
+
}
|
|
232
|
+
return canvas;
|
|
233
|
+
}
|
|
234
|
+
// Longest side of the vignette canvas: the overlay limit, below what iOS WebKit drops.
|
|
235
|
+
const MAX_VIGNETTE_SIDE = 8192;
|
|
236
|
+
/**
|
|
237
|
+
* Scene function of a photo with a look, and of a straightened one: the look bitmap with the
|
|
238
|
+
* node's crop, the flip, and the vignette over the drawn frame.
|
|
239
|
+
*/
|
|
240
|
+
export function lookSceneFunc(context, shape) {
|
|
241
|
+
const width = shape.width();
|
|
242
|
+
const height = shape.height();
|
|
243
|
+
const vignette = Math.max(0, Math.min(1, Number(shape.getAttr('vignette')) || 0));
|
|
244
|
+
if (!vignette || width <= 0 || height <= 0) {
|
|
245
|
+
drawPhoto(context, shape, width, height);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
// The vignette may only darken the photo's own pixels: drawn apart, then put on the canvas.
|
|
249
|
+
const scale = Math.abs(shape.getAbsoluteScale().x) * context.canvas.getPixelRatio();
|
|
250
|
+
const pixelWidth = Math.max(1, Math.min(MAX_VIGNETTE_SIDE, Math.ceil(width * scale)));
|
|
251
|
+
const pixelHeight = Math.max(1, Math.min(MAX_VIGNETTE_SIDE, Math.ceil(height * scale)));
|
|
252
|
+
const native = typeof CanvasRenderingContext2D !== 'undefined' &&
|
|
253
|
+
context._context instanceof CanvasRenderingContext2D;
|
|
254
|
+
const canvas = vignetteCanvas(shape, native, pixelWidth, pixelHeight);
|
|
255
|
+
const ctx = canvas.getContext('2d');
|
|
256
|
+
if (!ctx) {
|
|
257
|
+
drawPhoto(context, shape, width, height);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
261
|
+
ctx.globalCompositeOperation = 'source-over';
|
|
262
|
+
ctx.clearRect(0, 0, pixelWidth, pixelHeight);
|
|
263
|
+
ctx.scale(pixelWidth / width, pixelHeight / height);
|
|
264
|
+
drawPhoto(ctx, shape, width, height);
|
|
265
|
+
paintVignette(ctx, width, height, vignette);
|
|
266
|
+
context.drawImage(canvas, 0, 0, width, height);
|
|
267
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type Mirror, type Rect, type Size } from './coverFit.js';
|
|
2
|
-
import type Konva from 'konva';
|
|
3
2
|
export declare const STRAIGHTEN_LIMIT = 45;
|
|
4
3
|
interface Point {
|
|
5
4
|
x: number;
|
|
@@ -42,8 +41,6 @@ export interface StraightDraw {
|
|
|
42
41
|
/** Der Flip-Filter spiegelt danach den Knoten; daher hier Lage gespiegelt, Winkel je Achse umgekehrt. */
|
|
43
42
|
export declare function straightDrawOf(photo: Rect, deg: number, box: Rect, mirror: Mirror | null): StraightDraw;
|
|
44
43
|
export declare const STRAIGHT_DRAW_ATTR = "straightDraw";
|
|
45
|
-
/** Konvas `crop` schneidet nur achsparallel aus; das gedrehte Foto zeichnet diese Funktion. */
|
|
46
|
-
export declare function straightSceneFunc(context: Konva.Context, shape: Konva.Shape): void;
|
|
47
44
|
/** Trägt nur den Maßstab: `printImageInfo` liest `cropWidth` für die Druck-DPI. */
|
|
48
45
|
export declare function straightScaleCrop(natural: Size, photo: Rect, box: Rect): Rect;
|
|
49
46
|
/** Ein neues Hintergrundfoto beginnt ungedreht; 0 statt Löschen hält ein gedreht verschobenes Fenster auf Deckung. */
|
package/dist/utils/straighten.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
2
|
// Begradigen. Gedrehte Fotos sind Rechtecke ihrer ungedrehten Lage, gedreht um die Mitte (Grad, wie Konva).
|
|
3
|
-
import { cornersOf, hasCorners, traceRoundedRect } from './cornerRadius.js';
|
|
4
3
|
import { coverPhotoRect, framedPhotoRect, panOfFramedPhoto, } from './coverFit.js';
|
|
5
4
|
export const STRAIGHTEN_LIMIT = 45;
|
|
6
5
|
export function clampStraighten(value) {
|
|
@@ -211,30 +210,6 @@ export function straightDrawOf(photo, deg, box, mirror) {
|
|
|
211
210
|
}
|
|
212
211
|
// Ziehen setzt das Attribut direkt, ohne React-Zustand.
|
|
213
212
|
export const STRAIGHT_DRAW_ATTR = 'straightDraw';
|
|
214
|
-
/** Konvas `crop` schneidet nur achsparallel aus; das gedrehte Foto zeichnet diese Funktion. */
|
|
215
|
-
export function straightSceneFunc(context, shape) {
|
|
216
|
-
const image = shape.getAttr('image');
|
|
217
|
-
const draw = shape.getAttr(STRAIGHT_DRAW_ATTR);
|
|
218
|
-
if (!image || !draw)
|
|
219
|
-
return;
|
|
220
|
-
const width = shape.width();
|
|
221
|
-
const height = shape.height();
|
|
222
|
-
const radius = shape.getAttr('cornerRadius');
|
|
223
|
-
context.save();
|
|
224
|
-
context.beginPath();
|
|
225
|
-
if (hasCorners(radius)) {
|
|
226
|
-
traceRoundedRect(context, width, height, cornersOf(radius, width, height));
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
context.rect(0, 0, width, height);
|
|
230
|
-
}
|
|
231
|
-
context.closePath();
|
|
232
|
-
context.clip();
|
|
233
|
-
context.translate(draw.x, draw.y);
|
|
234
|
-
context.rotate(radians(draw.rotation));
|
|
235
|
-
context.drawImage(image, -draw.width / 2, -draw.height / 2, draw.width, draw.height);
|
|
236
|
-
context.restore();
|
|
237
|
-
}
|
|
238
213
|
/** Trägt nur den Maßstab: `printImageInfo` liest `cropWidth` für die Druck-DPI. */
|
|
239
214
|
export function straightScaleCrop(natural, photo, box) {
|
|
240
215
|
const sx = natural.width / photo.width;
|
package/package.json
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type Konva from 'konva';
|
|
2
|
-
/**
|
|
3
|
-
* Re-caches a filtered node once per frame at most. A pan changes the crop on
|
|
4
|
-
* every pointer move, and each `cache()` re-runs every filter over the bitmap.
|
|
5
|
-
*/
|
|
6
|
-
export declare function recacheNextFrame(node: Konva.Node): void;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const pending = new WeakSet();
|
|
2
|
-
/**
|
|
3
|
-
* Re-caches a filtered node once per frame at most. A pan changes the crop on
|
|
4
|
-
* every pointer move, and each `cache()` re-runs every filter over the bitmap.
|
|
5
|
-
*/
|
|
6
|
-
export function recacheNextFrame(node) {
|
|
7
|
-
if (!node.isCached() || pending.has(node))
|
|
8
|
-
return;
|
|
9
|
-
pending.add(node);
|
|
10
|
-
requestAnimationFrame(() => {
|
|
11
|
-
pending.delete(node);
|
|
12
|
-
if (node.isCached())
|
|
13
|
-
node.cache();
|
|
14
|
-
});
|
|
15
|
-
}
|