@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.
- package/dist/components/GenericCanvasElement.js +15 -1
- package/dist/components/TopBar/ContextControls.js +1 -1
- package/dist/components/TopBar/modules/FloatingFontSizeControl.d.ts +3 -1
- package/dist/components/TopBar/modules/FloatingFontSizeControl.js +46 -4
- package/dist/components/kindRenderers.js +10 -1
- package/dist/hooks/useLiveFontSize.d.ts +6 -0
- package/dist/hooks/useLiveFontSize.js +26 -0
- package/dist/i18n/de.d.ts +1 -0
- package/dist/i18n/de.js +1 -0
- package/dist/i18n/en.js +1 -0
- package/dist/page/actions.js +8 -2
- package/dist/primitives/CanvasImage.js +86 -12
- package/dist/primitives/CanvasRichText.js +10 -5
- package/dist/primitives/CanvasText.d.ts +8 -1
- package/dist/primitives/CanvasText.js +25 -5
- package/dist/styles/compiled.css +1 -1
- package/dist/utils/cropGhost.d.ts +3 -2
- package/dist/utils/cropGhost.js +4 -3
- package/dist/utils/filteredPan.d.ts +22 -0
- package/dist/utils/filteredPan.js +36 -0
- package/package.json +1 -1
|
@@ -21,6 +21,7 @@ import { templateTextAlignOf } from '../utils/textAlign.js';
|
|
|
21
21
|
import { useCanvasEditorServices } from '../CanvasEditorProvider.js';
|
|
22
22
|
import { plainImageUrls } from '../hostServices.js';
|
|
23
23
|
import { CanvasText, CanvasImage, CanvasBackground } from '../primitives/index.js';
|
|
24
|
+
import { DEFAULT_TEXT_ANCHORS } from '../primitives/CanvasText.js';
|
|
24
25
|
import { canCropBackgroundPhoto, imageElementInteraction } from '../utils/backgroundPhotoCrop.js';
|
|
25
26
|
import { canvasImageSourceUrl } from '../utils/canvasImageSource.js';
|
|
26
27
|
import { imageRenderInputsAreEqual } from '../utils/imageElementComparison.js';
|
|
@@ -30,6 +31,16 @@ import { coverFitSlot, resolveColor, resolveImageElementBox, resolveValue, } fro
|
|
|
30
31
|
// `templateElementToEntry` braucht dieselbe Rechnung, und zwei Fassungen
|
|
31
32
|
// derselben Arithmetik driften auseinander.
|
|
32
33
|
import { isTemplateElementRotatable, templateRotationOf } from '../utils/templateRotation.js';
|
|
34
|
+
/**
|
|
35
|
+
* The handles of a template text. Side handles set the width as before. A corner scales the text
|
|
36
|
+
* only where its size persists (`fontSizeStateKey`); and where its position does not (a text that
|
|
37
|
+
* cannot turn), only the corner that keeps the top-left in place, so the text does not jump back.
|
|
38
|
+
*/
|
|
39
|
+
function templateTextAnchors(sizePersists, positionPersists) {
|
|
40
|
+
if (!sizePersists)
|
|
41
|
+
return ['middle-left', 'middle-right'];
|
|
42
|
+
return positionPersists ? DEFAULT_TEXT_ANCHORS : ['bottom-right', 'middle-left', 'middle-right'];
|
|
43
|
+
}
|
|
33
44
|
const MemoizedTextElement = memo(function MemoizedTextElement({ config, state, layout, selected, onSelect, onTextChange, onFontSizeChange, onPositionChange, onTemplateTransformEnd, onGeometryChange, onSnapChange, onSnapLinesChange, stageWidth, stageHeight, getSnapTargets, }) {
|
|
34
45
|
const text = assertAsString(state[config.textKey]);
|
|
35
46
|
const customFontSize = getOptionalStateValue(state, config.fontSizeStateKey);
|
|
@@ -61,7 +72,10 @@ const MemoizedTextElement = memo(function MemoizedTextElement({ config, state, l
|
|
|
61
72
|
const rotatable = isTemplateElementRotatable(config);
|
|
62
73
|
const rotation = rotatable ? templateRotationOf(state, config.id) : 0;
|
|
63
74
|
const handleTransformEnd = useCallback((newX, newY, _w, _sx, _sy, newRotation) => onTemplateTransformEnd(config.id, newX, newY, newRotation), [onTemplateTransformEnd, config.id]);
|
|
64
|
-
return (_jsx(CanvasText, { id: config.id, text: text, x: x, y: y, width: width, fontSize: fontSize, fontFamily: config.fontFamily, fontStyle: config.fontStyle, fill: fill, align: templateTextAlignOf(state, config.id) ?? config.align ?? 'left', lineHeight: config.lineHeight ?? 1.2, wrap: config.wrap ?? 'word', padding: padding, draggable: config.draggable ?? false, editable: config.editable ?? false, richText: config.richText ?? false, opacity: opacity, selected: selected, onSelect: handleSelect, onTextChange: handleTextChange, onFontSizeChange: handleFontSizeChange, stageWidth: stageWidth, stageHeight: stageHeight, onSnapChange: onSnapChange, getSnapTargets: getSnapTargets, onPositionChange: onPositionChange, onGeometryChange: onGeometryChange, onSnapLinesChange: onSnapLinesChange, rotation: rotation, transformConfig: {
|
|
75
|
+
return (_jsx(CanvasText, { id: config.id, text: text, x: x, y: y, width: width, fontSize: fontSize, fontFamily: config.fontFamily, fontStyle: config.fontStyle, fill: fill, align: templateTextAlignOf(state, config.id) ?? config.align ?? 'left', lineHeight: config.lineHeight ?? 1.2, wrap: config.wrap ?? 'word', padding: padding, draggable: config.draggable ?? false, editable: config.editable ?? false, richText: config.richText ?? false, opacity: opacity, selected: selected, onSelect: handleSelect, onTextChange: handleTextChange, onFontSizeChange: handleFontSizeChange, stageWidth: stageWidth, stageHeight: stageHeight, onSnapChange: onSnapChange, getSnapTargets: getSnapTargets, onPositionChange: onPositionChange, onGeometryChange: onGeometryChange, onSnapLinesChange: onSnapLinesChange, rotation: rotation, transformConfig: {
|
|
76
|
+
rotateEnabled: rotatable,
|
|
77
|
+
enabledAnchors: templateTextAnchors(config.fontSizeStateKey !== undefined, rotatable),
|
|
78
|
+
}, ...(rotatable ? { onTransformEnd: handleTransformEnd } : {}) }));
|
|
65
79
|
}, (prev, next) => {
|
|
66
80
|
// Custom comparison for optimal memoization
|
|
67
81
|
if (prev.config.id !== next.config.id)
|
|
@@ -197,7 +197,7 @@ export function ContextControls({ selectedElement, activeFloatingModule, canMove
|
|
|
197
197
|
}, onChange: (role) => handleFontRoleChange(activeFloatingModule.data.id, role) }, "fontrole"));
|
|
198
198
|
}
|
|
199
199
|
if (isText && activeFloatingModule) {
|
|
200
|
-
groups.push(_jsx(FloatingFontSizeControl, { fontSize: activeFloatingModule.data.fontSize ?? 16, onFontSizeChange: (size) => handlers.handleFontSizeChange(activeFloatingModule.data.id, size) }, "fontsize"));
|
|
200
|
+
groups.push(_jsx(FloatingFontSizeControl, { elementId: activeFloatingModule.data.id, fontSize: activeFloatingModule.data.fontSize ?? 16, onFontSizeChange: (size) => handlers.handleFontSizeChange(activeFloatingModule.data.id, size) }, "fontsize"));
|
|
201
201
|
}
|
|
202
202
|
// Die Schnitt-Gruppe steht bei der Schrift, nicht bei der Ausrichtung — wie
|
|
203
203
|
// in Canva, wo alles Typografische beieinanderliegt. Der Id-Vergleich hält
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
interface FloatingFontSizeControlProps {
|
|
3
|
+
/** The text the field belongs to: while a corner drag scales it, the field shows the live size. */
|
|
4
|
+
elementId: string;
|
|
3
5
|
fontSize: number;
|
|
4
6
|
onFontSizeChange: (size: number) => void;
|
|
5
7
|
}
|
|
6
|
-
export declare function FloatingFontSizeControl({ fontSize, onFontSizeChange, }: FloatingFontSizeControlProps): React.JSX.Element;
|
|
8
|
+
export declare function FloatingFontSizeControl({ elementId, fontSize: committedFontSize, onFontSizeChange, }: FloatingFontSizeControlProps): React.JSX.Element;
|
|
7
9
|
export {};
|
|
@@ -2,20 +2,62 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
3
|
import { TileCaption, useBarTiles } from '../barTiles.js';
|
|
4
4
|
import { useMessages } from '../../../i18n/messages.js';
|
|
5
|
+
import { useLiveFontSize } from '../../../hooks/useLiveFontSize.js';
|
|
6
|
+
import { useState } from 'react';
|
|
5
7
|
import { PiPlus, PiMinus } from 'react-icons/pi';
|
|
6
8
|
const fontBtn = 'touch-target size-7 rounded-md border-none bg-transparent cursor-pointer flex items-center justify-center text-[var(--editor-text-secondary)] transition-colors duration-150 hover:enabled:bg-[var(--editor-surface-hover)] hover:enabled:text-[var(--editor-active-fg)] disabled:opacity-30 disabled:cursor-not-allowed';
|
|
7
|
-
|
|
9
|
+
const MIN_FONT_SIZE = 2;
|
|
10
|
+
const MAX_FONT_SIZE = 800;
|
|
11
|
+
const clampFontSize = (size) => Math.min(MAX_FONT_SIZE, Math.max(MIN_FONT_SIZE, Math.round(size)));
|
|
12
|
+
export function FloatingFontSizeControl({ elementId, fontSize: committedFontSize, onFontSizeChange, }) {
|
|
13
|
+
// Subscribed here, not in the bar: a drag re-renders this field only, once per whole size step.
|
|
14
|
+
const liveFontSize = useLiveFontSize(elementId);
|
|
15
|
+
const fontSize = liveFontSize ?? committedFontSize;
|
|
8
16
|
const t = useMessages();
|
|
9
17
|
const tiles = useBarTiles();
|
|
18
|
+
// What is typed, while the field has focus; null shows the text's size (live during a corner drag).
|
|
19
|
+
const [draft, setDraft] = useState(null);
|
|
20
|
+
const apply = (size) => {
|
|
21
|
+
const next = clampFontSize(size);
|
|
22
|
+
if (next !== Math.round(fontSize))
|
|
23
|
+
onFontSizeChange(next);
|
|
24
|
+
};
|
|
25
|
+
const commitDraft = () => {
|
|
26
|
+
if (draft === null)
|
|
27
|
+
return;
|
|
28
|
+
const parsed = Number(draft.replace(',', '.'));
|
|
29
|
+
setDraft(null);
|
|
30
|
+
if (draft.trim() !== '' && Number.isFinite(parsed))
|
|
31
|
+
apply(parsed);
|
|
32
|
+
};
|
|
33
|
+
const handleKeyDown = (e) => {
|
|
34
|
+
if (e.key === 'Enter') {
|
|
35
|
+
commitDraft();
|
|
36
|
+
e.currentTarget.blur();
|
|
37
|
+
}
|
|
38
|
+
else if (e.key === 'Escape') {
|
|
39
|
+
setDraft(null);
|
|
40
|
+
e.currentTarget.blur();
|
|
41
|
+
}
|
|
42
|
+
else if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
const step = (e.shiftKey ? 10 : 1) * (e.key === 'ArrowUp' ? 1 : -1);
|
|
45
|
+
setDraft(null);
|
|
46
|
+
apply(fontSize + step);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
10
49
|
const handleIncrease = (e) => {
|
|
11
50
|
e.stopPropagation();
|
|
12
|
-
|
|
51
|
+
apply(fontSize + 2);
|
|
13
52
|
};
|
|
14
53
|
const handleDecrease = (e) => {
|
|
15
54
|
e.stopPropagation();
|
|
16
|
-
|
|
55
|
+
apply(fontSize - 2);
|
|
17
56
|
};
|
|
18
|
-
const stepper = (_jsxs("div", { className: "flex items-center h-[34px] shrink-0 rounded-lg border border-[var(--editor-border-strong)] px-0.5", children: [_jsx("button", { className: fontBtn, onClick: handleDecrease, title: t.topBar.fontSmaller, "aria-label": t.topBar.fontSmaller, type: "button", children: _jsx(PiMinus, { size: 10 }) }), _jsx("
|
|
57
|
+
const stepper = (_jsxs("div", { className: "flex items-center h-[34px] shrink-0 rounded-lg border border-[var(--editor-border-strong)] px-0.5", children: [_jsx("button", { className: fontBtn, onClick: handleDecrease, title: t.topBar.fontSmaller, "aria-label": t.topBar.fontSmaller, type: "button", children: _jsx(PiMinus, { size: 10 }) }), _jsx("input", { type: "text", inputMode: "numeric", "aria-label": t.topBar.fontSizeInput, title: t.topBar.fontSizeInput, value: draft ?? String(Math.round(fontSize)), onFocus: (e) => {
|
|
58
|
+
setDraft(String(Math.round(fontSize)));
|
|
59
|
+
e.currentTarget.select();
|
|
60
|
+
}, onChange: (e) => setDraft(e.target.value), onBlur: commitDraft, onKeyDown: handleKeyDown, onClick: (e) => e.stopPropagation(), className: "w-10 h-7 rounded-md border-none bg-transparent text-[13px] font-semibold text-[var(--editor-text)] text-center tabular-nums outline-none hover:bg-[var(--editor-surface-hover)] focus-visible:bg-[var(--editor-surface-hover)] focus-visible:ring-2 focus-visible:ring-[var(--editor-active-fg)]" }), _jsx("button", { className: fontBtn, onClick: handleIncrease, title: t.topBar.fontLarger, "aria-label": t.topBar.fontLarger, type: "button", children: _jsx(PiPlus, { size: 10 }) })] }));
|
|
19
61
|
if (!tiles)
|
|
20
62
|
return stepper;
|
|
21
63
|
return (_jsxs("div", { className: "flex flex-col items-center justify-end gap-1 h-14 pb-2 shrink-0", children: [stepper, _jsx(TileCaption, { decorative: true, children: t.topBar.tiles.fontSize })] }));
|
|
@@ -125,17 +125,26 @@ export const KIND_RENDERERS = {
|
|
|
125
125
|
const textItem = item.data;
|
|
126
126
|
if (!textItem)
|
|
127
127
|
return null;
|
|
128
|
+
let scaledSize = null;
|
|
128
129
|
return (_jsx(SelectableCanvasText, { elementId: textItem.id, id: textItem.id, text: shownText(textItem, ctx.pageNumber), x: textItem.x, y: textItem.y, width: textItem.width, fontSize: textItem.fontSize, fontFamily: textItem.fontFamily, fontStyle: textItem.fontStyle || 'normal', fontWeight: textItem.fontWeight, letterSpacing: textItem.letterSpacing, strikethrough: textItem.strikethrough, fill: textItem.fill, stroke: textItem.stroke, strokeWidth: textItem.strokeWidth, shadowColor: textItem.shadowColor, shadowBlur: textItem.shadowBlur, shadowOffsetX: textItem.shadowOffsetX, shadowOffsetY: textItem.shadowOffsetY, shadowOpacity: textItem.shadowOpacity, fillGradient: textItem.fillGradient, align: textItem.align ?? 'left', lineHeight: textItem.lineHeight, accent: effectiveAccent(textItem), marker: effectiveMarker(textItem), opacity: textItem.opacity ?? 1, rotation: textItem.rotation || 0, scaleX: textItem.scale || 1, scaleY: textItem.scale || 1, draggable: true, onSelect: () => handlers.handleElementSelect(textItem.id), onTextChange: (val) => handlers.handleAdditionalTextChange(textItem.id, { text: val }), onTextPreview: handlers.handleAdditionalTextPreview
|
|
129
130
|
? (draft) => handlers.handleAdditionalTextPreview?.(textItem.id, draft) ?? null
|
|
130
131
|
: undefined, onDragEnd: (x, y) => {
|
|
131
132
|
handlers.handleAdditionalTextChange(textItem.id, { x, y });
|
|
132
|
-
}, transformConfig: { rotateEnabled: true },
|
|
133
|
+
}, transformConfig: { rotateEnabled: true },
|
|
134
|
+
// A corner drag reports its size right before its box, in the same release: both go
|
|
135
|
+
// into one change, so the drag is one undo step and the size is set by hand.
|
|
136
|
+
onFontSizeChange: (size) => {
|
|
137
|
+
scaledSize = size;
|
|
138
|
+
}, onTransformEnd: (x, y, width, scaleX, _scaleY, rotation) => {
|
|
139
|
+
const fontSize = scaledSize;
|
|
140
|
+
scaledSize = null;
|
|
133
141
|
handlers.handleAdditionalTextChange(textItem.id, {
|
|
134
142
|
x,
|
|
135
143
|
y,
|
|
136
144
|
width,
|
|
137
145
|
scale: scaleX,
|
|
138
146
|
rotation,
|
|
147
|
+
...(fontSize === null ? {} : { fontSize }),
|
|
139
148
|
});
|
|
140
149
|
}, editable: textItem.counter === undefined, onSnapChange: handleSnapChange, onSnapLinesChange: setSnapLines, getSnapTargets: getSnapTargets, onGeometryChange: registerGeometry, stageWidth: stageWidth, stageHeight: stageHeight }, textItem.id));
|
|
141
150
|
},
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
/**
|
|
3
|
+
* The size a text is being scaled to by a corner handle, while the pointer is still down.
|
|
4
|
+
*
|
|
5
|
+
* A channel of its own, not a field of the canvas store: every page has its own store, and the
|
|
6
|
+
* size field sits in the shell's toolbar, outside all of them. Only the field subscribes, so a
|
|
7
|
+
* drag re-renders that one input — once per whole size step — and nothing else. The page itself
|
|
8
|
+
* is written once, on release.
|
|
9
|
+
*/
|
|
10
|
+
import { useSyncExternalStore } from 'react';
|
|
11
|
+
let live = null;
|
|
12
|
+
const listeners = new Set();
|
|
13
|
+
export function setLiveFontSize(next) {
|
|
14
|
+
if (next?.id === live?.id && next?.size === live?.size)
|
|
15
|
+
return;
|
|
16
|
+
live = next;
|
|
17
|
+
listeners.forEach((listener) => listener());
|
|
18
|
+
}
|
|
19
|
+
function subscribe(listener) {
|
|
20
|
+
listeners.add(listener);
|
|
21
|
+
return () => listeners.delete(listener);
|
|
22
|
+
}
|
|
23
|
+
/** The live size of `id` while one of its corners is dragged; null otherwise. */
|
|
24
|
+
export function useLiveFontSize(id) {
|
|
25
|
+
return useSyncExternalStore(subscribe, () => (live?.id === id ? live.size : null), () => null);
|
|
26
|
+
}
|
package/dist/i18n/de.d.ts
CHANGED
package/dist/i18n/de.js
CHANGED
package/dist/i18n/en.js
CHANGED
package/dist/page/actions.js
CHANGED
|
@@ -122,9 +122,15 @@ export function createPageActions(getState, setState, saveToHistory, debouncedSa
|
|
|
122
122
|
if (t.id !== id)
|
|
123
123
|
return t;
|
|
124
124
|
const next = { ...t, ...partial };
|
|
125
|
+
// A size set by hand fixes the size: the text leaves the prototype's fitting for
|
|
126
|
+
// good, so no later edit, font or brand change refits it over the person's choice.
|
|
127
|
+
if ('fontSize' in partial) {
|
|
128
|
+
const { maxFontSize: _fitted, ...fixed } = next;
|
|
129
|
+
return fixed;
|
|
130
|
+
}
|
|
125
131
|
// A committed text change refits a text with a prototype size: shrink as it grows,
|
|
126
|
-
// grow back as it shrinks.
|
|
127
|
-
if (!('text' in partial)
|
|
132
|
+
// grow back as it shrinks.
|
|
133
|
+
if (!('text' in partial))
|
|
128
134
|
return next;
|
|
129
135
|
return refitted(next, prev);
|
|
130
136
|
}),
|
|
@@ -23,13 +23,33 @@ import { panWindowPhoto, photoRectAround, visiblePart, windowInPhoto, zoomWindow
|
|
|
23
23
|
import { isGroupDrag } from '../utils/multiSelect.js';
|
|
24
24
|
import { ELEMENT_TRANSFORMER, normalizeRotation } from '../utils/orientation.js';
|
|
25
25
|
import { cacheFiltered, usePreviewCaptureRatio } from '../utils/filterCache.js';
|
|
26
|
-
import {
|
|
26
|
+
import { beginFilteredPan } from '../utils/filteredPan.js';
|
|
27
27
|
import { boxFrame, createBoxFrame, frameBounds, snapByBounds } from '../utils/snapping.js';
|
|
28
28
|
import { panStraightPhoto, STRAIGHT_DRAW_ATTR, straightDrawOf, straightenWindowPhoto, straightScaleCrop, straightSceneFunc, windowPhotoOfStraight, zoomStraightPhoto, } from '../utils/straighten.js';
|
|
29
29
|
import { CROP_GHOST_NAME, CROP_GHOST_OPACITY, cropGhostAttrs, cropGhostSource, placeCropGhost, } from '../utils/cropGhost.js';
|
|
30
30
|
import { getActiveImageFilters, imageFilterAttrs } from '../utils/imageFilters.js';
|
|
31
31
|
import { backgroundKeyCrop, cropKeyOf } from '../utils/keyboardCrop.js';
|
|
32
32
|
// Rahmen für Snap und Geometrie-Meldung, pro Aufruf neu beschrieben (synchron, ohne Allokation).
|
|
33
|
+
/** The pointer in `node`'s parent space — where Konva itself places a dragged node from. */
|
|
34
|
+
function pointerInParent(node) {
|
|
35
|
+
const pointer = node.getStage()?.getPointerPosition();
|
|
36
|
+
const parent = node.getParent();
|
|
37
|
+
if (!pointer || !parent)
|
|
38
|
+
return null;
|
|
39
|
+
return parent.getAbsoluteTransform().copy().invert().point(pointer);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* How far a pan has moved since its start. Taken from the pointer, not from the node: the pan puts
|
|
43
|
+
* the node back on its box after every move, and Konva fires `dragmove` without placing the node
|
|
44
|
+
* again when the pointer did not move (a resting mouse, a trackpad) — read from the node, that
|
|
45
|
+
* event is a pan of zero and the photo jumps back to where the drag began.
|
|
46
|
+
*/
|
|
47
|
+
function panDelta(node, pan) {
|
|
48
|
+
const at = pan.pointer && pointerInParent(node);
|
|
49
|
+
if (pan.pointer && at)
|
|
50
|
+
return [at.x - pan.pointer.x, at.y - pan.pointer.y];
|
|
51
|
+
return [node.x() - pan.part.x, node.y() - pan.part.y];
|
|
52
|
+
}
|
|
33
53
|
const dragFrame = createBoxFrame();
|
|
34
54
|
const DEFAULT_IMAGE_ANCHORS = [
|
|
35
55
|
'top-left',
|
|
@@ -41,8 +61,8 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
41
61
|
const locked = useIsItemLocked();
|
|
42
62
|
const imageRef = useRef(null);
|
|
43
63
|
const captureRatio = usePreviewCaptureRatio();
|
|
44
|
-
// Drag of a cover-fitted photo: the node under the pointer at drag start,
|
|
45
|
-
// (begradigt: die Lage des gedrehten Fotos).
|
|
64
|
+
// Drag of a cover-fitted photo: the node under the pointer at drag start, the pointer there (in
|
|
65
|
+
// the node's parent space), and the pan so far (begradigt: die Lage des gedrehten Fotos).
|
|
46
66
|
const panStartRef = useRef(null);
|
|
47
67
|
const adjustmentFilters = adjustments ? getActiveImageFilters(adjustments) : [];
|
|
48
68
|
const trRef = useRef(null);
|
|
@@ -150,6 +170,11 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
150
170
|
const nodeHeight = node.height() * node.scaleY();
|
|
151
171
|
snap.onDragEnd();
|
|
152
172
|
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
|
+
}
|
|
153
178
|
if (pan?.photo) {
|
|
154
179
|
// Begradigt: das Fenster behält seine Größe, seine Mitte ist die des gedrehten Fotos.
|
|
155
180
|
panStartRef.current = null;
|
|
@@ -178,7 +203,19 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
178
203
|
onGeometryChange(id, box.x, box.y, box.width, box.height);
|
|
179
204
|
}
|
|
180
205
|
}
|
|
181
|
-
}, [
|
|
206
|
+
}, [
|
|
207
|
+
id,
|
|
208
|
+
x,
|
|
209
|
+
y,
|
|
210
|
+
width,
|
|
211
|
+
height,
|
|
212
|
+
part,
|
|
213
|
+
onDragEnd,
|
|
214
|
+
onPositionChange,
|
|
215
|
+
onGeometryChange,
|
|
216
|
+
snap,
|
|
217
|
+
captureRatio,
|
|
218
|
+
]);
|
|
182
219
|
const clampToBounds = useCallback((posX, posY, nodeWidth, nodeHeight, nodeRotation) => {
|
|
183
220
|
if (!constrainToBounds || !stageWidth || !stageHeight) {
|
|
184
221
|
return { x: posX, y: posY };
|
|
@@ -222,7 +259,7 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
222
259
|
const pan = panStartRef.current;
|
|
223
260
|
if (pan && straight && natural && slot) {
|
|
224
261
|
// Der Knoten bleibt der Rahmen; das gedrehte Foto bewegt sich darin.
|
|
225
|
-
const moved = panStraightPhoto(straight, turnDeg, slot, node
|
|
262
|
+
const moved = panStraightPhoto(straight, turnDeg, slot, ...panDelta(node, pan));
|
|
226
263
|
node.position(slot);
|
|
227
264
|
if (turned) {
|
|
228
265
|
node.setAttr(STRAIGHT_DRAW_ATTR, straightDrawOf(moved, turnDeg, slot, mirror));
|
|
@@ -230,26 +267,24 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
230
267
|
else {
|
|
231
268
|
const next = visiblePart(natural, moved, slot, mirror);
|
|
232
269
|
if (next)
|
|
233
|
-
node.crop(next.crop);
|
|
270
|
+
(pan.filtered?.crop ?? node.crop.bind(node))(next.crop);
|
|
234
271
|
}
|
|
235
272
|
pan.photo = moved;
|
|
236
273
|
placeCropGhost(ghostRef.current, moved, mirror, turnDeg);
|
|
237
|
-
recacheNextFrame(node);
|
|
238
274
|
return;
|
|
239
275
|
}
|
|
240
276
|
if (pan && natural && slot) {
|
|
241
277
|
// The node stays the visible part; the photo moves under it.
|
|
242
|
-
const next = panWindowPhoto(natural, { x, y, width, height }, slot, node
|
|
278
|
+
const next = panWindowPhoto(natural, { x, y, width, height }, slot, ...panDelta(node, pan), mirror);
|
|
243
279
|
if (!next.part)
|
|
244
280
|
return;
|
|
245
281
|
node.position(next.part.box);
|
|
246
282
|
node.size(next.part.box);
|
|
247
|
-
node.crop(next.part.crop);
|
|
283
|
+
(pan.filtered?.crop ?? node.crop.bind(node))(next.part.crop);
|
|
248
284
|
pan.dx = next.dx;
|
|
249
285
|
pan.dy = next.dy;
|
|
250
286
|
// Ziehen und Zoomen ändern die Knoten direkt; das Restbild geht ohne React-Zustand mit.
|
|
251
287
|
placeCropGhost(ghostRef.current, photoRectAround(natural, { x: x + next.dx, y: y + next.dy, width, height }), mirror);
|
|
252
|
-
recacheNextFrame(node);
|
|
253
288
|
return;
|
|
254
289
|
}
|
|
255
290
|
const nodeWidth = node.width() * node.scaleX();
|
|
@@ -296,13 +331,52 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
296
331
|
width,
|
|
297
332
|
height,
|
|
298
333
|
]);
|
|
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]);
|
|
299
363
|
const handleDragStart = useCallback((e) => {
|
|
300
364
|
// In a group drag a cover-fitted image moves with the others; the background photo
|
|
301
365
|
// never joins one, outside Ausschnitt mode it is not draggable.
|
|
366
|
+
const node = e.target;
|
|
302
367
|
panStartRef.current =
|
|
303
|
-
part && !isGroupDrag(
|
|
368
|
+
part && !isGroupDrag(node)
|
|
369
|
+
? {
|
|
370
|
+
part: part.box,
|
|
371
|
+
pointer: pointerInParent(node),
|
|
372
|
+
dx: 0,
|
|
373
|
+
dy: 0,
|
|
374
|
+
photo: null,
|
|
375
|
+
filtered: startFilteredPan(node),
|
|
376
|
+
}
|
|
377
|
+
: null;
|
|
304
378
|
snap.onDragStart();
|
|
305
|
-
}, [part, snap]);
|
|
379
|
+
}, [part, snap, startFilteredPan]);
|
|
306
380
|
// Tastatur im Ausschnitt-Modus: dieselben Grenzen und dieselbe Übernahme wie Ziehen und Zoomen.
|
|
307
381
|
const keyCropRef = useRef(null);
|
|
308
382
|
useEffect(() => {
|
|
@@ -32,6 +32,7 @@ import { overlayBoxForNode, useCanvasTextEditor } from '../components/CanvasText
|
|
|
32
32
|
import { useFontGeneration } from '../hooks/useFontGeneration.js';
|
|
33
33
|
import { useGeometryReporter } from '../hooks/useGeometryReporter.js';
|
|
34
34
|
import { useSnapScheduler } from '../hooks/useSnapScheduler.js';
|
|
35
|
+
import { setLiveFontSize } from '../hooks/useLiveFontSize.js';
|
|
35
36
|
import { resolveFontFamily } from '../utils/fontAliases.js';
|
|
36
37
|
import { gradientFillProps } from '../utils/gradientFill.js';
|
|
37
38
|
import { markerBoxes } from '../utils/markerBoxes.js';
|
|
@@ -40,10 +41,9 @@ import { isGroupDrag } from '../utils/multiSelect.js';
|
|
|
40
41
|
import { ELEMENT_TRANSFORMER, normalizeRotation } from '../utils/orientation.js';
|
|
41
42
|
import { boxFrame, createBoxFrame, frameBounds, snapByBounds } from '../utils/snapping.js';
|
|
42
43
|
import { konvaFontStyle, runFont, runMeasurer } from '../utils/textUtils.js';
|
|
43
|
-
import { isWidthOnlyScale } from './CanvasText.js';
|
|
44
|
+
import { DEFAULT_TEXT_ANCHORS, isWidthOnlyScale, scaledFontSize, } from './CanvasText.js';
|
|
44
45
|
// Rahmen für Snap und Geometrie-Meldung, pro Aufruf neu beschrieben (synchron, ohne Allokation).
|
|
45
46
|
const dragFrame = createBoxFrame();
|
|
46
|
-
const DEFAULT_TEXT_ANCHORS = ['middle-left', 'middle-right'];
|
|
47
47
|
export function CanvasRichText({ id, text, x, y, width, fontSize = 24, fontFamily = 'Arial', fontStyle = 'normal', fontWeight, letterSpacing, strikethrough = false, fill = '#000000', rotation, opacity = 1, stroke, strokeWidth, shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY, shadowOpacity, fillGradient, align = 'left', accent = null, marker: templateMarker = null, lineHeight = 1.2, padding = 0, draggable = true, selected = false, editable = false, transformConfig, onSelect, onTextChange, onTextPreview, onDragEnd, onTransformEnd, onFontSizeChange, snapToCenter = true, stageWidth, stageHeight, onSnapChange, getSnapTargets, onPositionChange, onGeometryChange, onSnapLinesChange, }) {
|
|
48
48
|
const locked = useIsItemLocked();
|
|
49
49
|
const groupRef = useRef(null);
|
|
@@ -144,17 +144,22 @@ export function CanvasRichText({ id, text, x, y, width, fontSize = 24, fontFamil
|
|
|
144
144
|
const liveWidthRef = useRef(null);
|
|
145
145
|
const handleTransform = useCallback(() => {
|
|
146
146
|
const node = groupRef.current;
|
|
147
|
-
if (!node
|
|
147
|
+
if (!node)
|
|
148
|
+
return;
|
|
149
|
+
if (!isWidthOnlyScale(node)) {
|
|
150
|
+
setLiveFontSize({ id: id ?? '', size: scaledFontSize(fontSize, node.scaleY()) });
|
|
148
151
|
return;
|
|
152
|
+
}
|
|
149
153
|
const next = Math.max(1, (liveWidthRef.current ?? blockWidth) * node.scaleX());
|
|
150
154
|
node.scaleX(1);
|
|
151
155
|
liveWidthRef.current = next;
|
|
152
156
|
setLiveWidth(next);
|
|
153
|
-
}, [blockWidth]);
|
|
157
|
+
}, [id, fontSize, blockWidth]);
|
|
154
158
|
const handleTransformEnd = useCallback(() => {
|
|
155
159
|
const node = groupRef.current;
|
|
156
160
|
if (!node)
|
|
157
161
|
return;
|
|
162
|
+
setLiveFontSize(null);
|
|
158
163
|
const committedWidth = liveWidthRef.current;
|
|
159
164
|
if (committedWidth != null) {
|
|
160
165
|
liveWidthRef.current = null;
|
|
@@ -173,7 +178,7 @@ export function CanvasRichText({ id, text, x, y, width, fontSize = 24, fontFamil
|
|
|
173
178
|
if (scaleChanged) {
|
|
174
179
|
// Eine Gruppe trägt keine fontSize — anders als beim einfachen Textknoten
|
|
175
180
|
// wird sie aus der Prop und dem Maßstab gerechnet.
|
|
176
|
-
const newFontSize =
|
|
181
|
+
const newFontSize = scaledFontSize(fontSize, scaleY);
|
|
177
182
|
const newWidth = Math.round(blockWidth * scaleX);
|
|
178
183
|
onFontSizeChange?.(newFontSize);
|
|
179
184
|
onTransformEnd?.(node.x(), node.y(), newWidth, 1, 1, normalizeRotation(node.rotation()));
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { type GeometryReporter } from '../hooks/useGeometryReporter.js';
|
|
10
10
|
import { type GradientFill } from '../utils/gradientFill.js';
|
|
11
11
|
import type { FontWeight } from '../configs/types.js';
|
|
12
|
-
import type { TransformConfig } from '../types/editorTypes.js';
|
|
12
|
+
import type { TransformConfig, TransformAnchor } from '../types/editorTypes.js';
|
|
13
13
|
import type { SnapTarget, SnapLine } from '../utils/snapping.js';
|
|
14
14
|
import type { TextAccent, TextMarker } from '../utils/textUtils.js';
|
|
15
15
|
import type Konva from 'konva';
|
|
@@ -78,6 +78,13 @@ export interface CanvasTextProps {
|
|
|
78
78
|
onSnapLinesChange?: (lines: SnapLine[]) => void;
|
|
79
79
|
}
|
|
80
80
|
export declare const isWidthOnlyScale: (node: Konva.Node) => boolean;
|
|
81
|
+
/**
|
|
82
|
+
* A side handle sets the width (the text re-wraps), a corner handle scales the text: the font
|
|
83
|
+
* size follows the drag and is written on release.
|
|
84
|
+
*/
|
|
85
|
+
export declare const DEFAULT_TEXT_ANCHORS: TransformAnchor[];
|
|
86
|
+
/** The font size a corner drag at `scaleY` gives `fontSize`; the same rule on release and live. */
|
|
87
|
+
export declare const scaledFontSize: (fontSize: number, scaleY: number) => number;
|
|
81
88
|
/**
|
|
82
89
|
* Aufzählungen brauchen einen hängenden Einzug und Auszeichnung gemischte
|
|
83
90
|
* Schnitte — beides kennt ein einzelner Konva.Text nicht, das zeichnet
|
|
@@ -15,6 +15,7 @@ import { overlayBoxForNode, useCanvasTextEditor } from '../components/CanvasText
|
|
|
15
15
|
import { useGeometryReporter } from '../hooks/useGeometryReporter.js';
|
|
16
16
|
import { useFontGeneration } from '../hooks/useFontGeneration.js';
|
|
17
17
|
import { useSnapScheduler } from '../hooks/useSnapScheduler.js';
|
|
18
|
+
import { setLiveFontSize } from '../hooks/useLiveFontSize.js';
|
|
18
19
|
import { gradientFillProps } from '../utils/gradientFill.js';
|
|
19
20
|
import { isGroupDrag } from '../utils/multiSelect.js';
|
|
20
21
|
import { ELEMENT_TRANSFORMER, normalizeRotation } from '../utils/orientation.js';
|
|
@@ -26,7 +27,20 @@ import { CanvasRichText } from './CanvasRichText.js';
|
|
|
26
27
|
// Rahmen für Snap und Geometrie-Meldung, pro Aufruf neu beschrieben (synchron, ohne Allokation).
|
|
27
28
|
const dragFrame = createBoxFrame();
|
|
28
29
|
export const isWidthOnlyScale = (node) => Math.abs(node.scaleY() - 1) < 1e-3 && Math.abs(node.scaleX() - 1) >= 1e-3;
|
|
29
|
-
|
|
30
|
+
/**
|
|
31
|
+
* A side handle sets the width (the text re-wraps), a corner handle scales the text: the font
|
|
32
|
+
* size follows the drag and is written on release.
|
|
33
|
+
*/
|
|
34
|
+
export const DEFAULT_TEXT_ANCHORS = [
|
|
35
|
+
'top-left',
|
|
36
|
+
'top-right',
|
|
37
|
+
'bottom-left',
|
|
38
|
+
'bottom-right',
|
|
39
|
+
'middle-left',
|
|
40
|
+
'middle-right',
|
|
41
|
+
];
|
|
42
|
+
/** The font size a corner drag at `scaleY` gives `fontSize`; the same rule on release and live. */
|
|
43
|
+
export const scaledFontSize = (fontSize, scaleY) => Math.max(8, Math.round(fontSize * scaleY));
|
|
30
44
|
function CanvasTextInner({ id, text, x, y, width, fontSize = 24, fontFamily = 'Arial', fontStyle = 'normal', fontWeight, letterSpacing, strikethrough, fill = '#000000', rotation, scaleX, scaleY, stroke, strokeWidth, shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY, shadowOpacity, fillGradient, align = 'left', accent = null, marker = null, verticalAlign = 'top', lineHeight = 1.2, wrap = 'word', padding = 0, draggable = true, selected = false, editable = false, opacity = 1, transformConfig, onSelect, onDeselect, onTextChange, onTextPreview, onDragEnd, onTransformEnd, onFontSizeChange, snapToCenter = true, stageWidth, stageHeight, onSnapChange, getSnapTargets, onPositionChange, onGeometryChange, onSnapLinesChange, }) {
|
|
31
45
|
const locked = useIsItemLocked();
|
|
32
46
|
const textRef = useRef(null);
|
|
@@ -135,18 +149,24 @@ function CanvasTextInner({ id, text, x, y, width, fontSize = 24, fontFamily = 'A
|
|
|
135
149
|
}, [id, snapToCenter, stageWidth, stageHeight, getSnapTargets, snap]);
|
|
136
150
|
// A side handle only changes the width: turn that scale into width right
|
|
137
151
|
// away so the text re-wraps under the pointer instead of stretching and
|
|
138
|
-
// jumping on release. Corner handles keep scaling (font size on release)
|
|
152
|
+
// jumping on release. Corner handles keep scaling (font size on release);
|
|
153
|
+
// the size they reach is published live so the size field can follow.
|
|
139
154
|
const handleTransform = useCallback(() => {
|
|
140
155
|
const node = textRef.current;
|
|
141
|
-
if (!node
|
|
156
|
+
if (!node)
|
|
142
157
|
return;
|
|
158
|
+
if (!isWidthOnlyScale(node)) {
|
|
159
|
+
setLiveFontSize({ id: id ?? '', size: scaledFontSize(node.fontSize(), node.scaleY()) });
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
143
162
|
node.width(Math.max(1, node.width() * node.scaleX()));
|
|
144
163
|
node.scaleX(1);
|
|
145
|
-
}, []);
|
|
164
|
+
}, [id]);
|
|
146
165
|
const handleTransformEnd = useCallback(() => {
|
|
147
166
|
const node = textRef.current;
|
|
148
167
|
if (!node)
|
|
149
168
|
return;
|
|
169
|
+
setLiveFontSize(null);
|
|
150
170
|
const scaleX = node.scaleX();
|
|
151
171
|
const scaleY = node.scaleY();
|
|
152
172
|
const currentFontSize = node.fontSize();
|
|
@@ -157,7 +177,7 @@ function CanvasTextInner({ id, text, x, y, width, fontSize = 24, fontFamily = 'A
|
|
|
157
177
|
const scaleChanged = Math.abs(scaleX - 1) > SCALE_THRESHOLD || Math.abs(scaleY - 1) > SCALE_THRESHOLD;
|
|
158
178
|
if (scaleChanged) {
|
|
159
179
|
// Calculate new dimensions - scale both fontSize AND width
|
|
160
|
-
const newFontSize =
|
|
180
|
+
const newFontSize = scaledFontSize(currentFontSize, scaleY);
|
|
161
181
|
const newWidth = Math.round(currentWidth * scaleX);
|
|
162
182
|
// Reset scale and apply new dimensions
|
|
163
183
|
node.scale({ x: 1, y: 1 });
|