@ggraphic/editor 0.1.0-alpha.6 → 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/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/hooks/useLookBitmap.d.ts +14 -0
- package/dist/hooks/useLookBitmap.js +65 -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 +49 -63
- package/dist/primitives/CanvasRichText.js +10 -5
- package/dist/primitives/CanvasText.d.ts +8 -1
- package/dist/primitives/CanvasText.js +25 -5
- package/dist/primitives/UserImagePrimitive.js +16 -57
- package/dist/styles/compiled.css +1 -1
- package/dist/utils/cropGhost.d.ts +1 -10
- package/dist/utils/cropGhost.js +4 -52
- 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/recacheNextFrame.d.ts +0 -6
- package/dist/utils/recacheNextFrame.js +0 -15
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
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
|
}),
|
|
@@ -1,35 +1,40 @@
|
|
|
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 { recacheNextFrame } from '../utils/recacheNextFrame.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).
|
|
18
|
+
/** The pointer in `node`'s parent space — where Konva itself places a dragged node from. */
|
|
19
|
+
function pointerInParent(node) {
|
|
20
|
+
const pointer = node.getStage()?.getPointerPosition();
|
|
21
|
+
const parent = node.getParent();
|
|
22
|
+
if (!pointer || !parent)
|
|
23
|
+
return null;
|
|
24
|
+
return parent.getAbsoluteTransform().copy().invert().point(pointer);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* How far a pan has moved since its start. Taken from the pointer, not from the node: the pan puts
|
|
28
|
+
* the node back on its box after every move, and Konva fires `dragmove` without placing the node
|
|
29
|
+
* again when the pointer did not move (a resting mouse, a trackpad) — read from the node, that
|
|
30
|
+
* event is a pan of zero and the photo jumps back to where the drag began.
|
|
31
|
+
*/
|
|
32
|
+
function panDelta(node, pan) {
|
|
33
|
+
const at = pan.pointer && pointerInParent(node);
|
|
34
|
+
if (pan.pointer && at)
|
|
35
|
+
return [at.x - pan.pointer.x, at.y - pan.pointer.y];
|
|
36
|
+
return [node.x() - pan.part.x, node.y() - pan.part.y];
|
|
37
|
+
}
|
|
33
38
|
const dragFrame = createBoxFrame();
|
|
34
39
|
const DEFAULT_IMAGE_ANCHORS = [
|
|
35
40
|
'top-left',
|
|
@@ -41,10 +46,9 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
41
46
|
const locked = useIsItemLocked();
|
|
42
47
|
const imageRef = useRef(null);
|
|
43
48
|
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).
|
|
49
|
+
// Drag of a cover-fitted photo: the node under the pointer at drag start, the pointer there (in
|
|
50
|
+
// the node's parent space), and the pan so far (begradigt: die Lage des gedrehten Fotos).
|
|
46
51
|
const panStartRef = useRef(null);
|
|
47
|
-
const adjustmentFilters = adjustments ? getActiveImageFilters(adjustments) : [];
|
|
48
52
|
const trRef = useRef(null);
|
|
49
53
|
const ghostRef = useRef(null);
|
|
50
54
|
const snap = useSnapScheduler({
|
|
@@ -80,11 +84,14 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
80
84
|
: null;
|
|
81
85
|
// Begradigt dreht sich das Restbild samt gefilterter Kopie über `rotation` mit.
|
|
82
86
|
const ghostAttrs = ghost ? cropGhostAttrs(ghost, mirror, turnDeg) : null;
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
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);
|
|
88
95
|
useEffect(() => {
|
|
89
96
|
if (selected && trRef.current && imageRef.current) {
|
|
90
97
|
trRef.current.nodes([imageRef.current]);
|
|
@@ -94,34 +101,6 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
94
101
|
trRef.current.nodes([]);
|
|
95
102
|
}
|
|
96
103
|
}, [selected]);
|
|
97
|
-
// Konva filters require the node to be cached first; without filters the
|
|
98
|
-
// cache is only an extra offscreen canvas redrawn on every change.
|
|
99
|
-
useEffect(() => {
|
|
100
|
-
const node = imageRef.current;
|
|
101
|
-
if (!node || !image)
|
|
102
|
-
return;
|
|
103
|
-
if (color || adjustmentFilters.length > 0) {
|
|
104
|
-
cacheFiltered(node, captureRatio);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
node.clearCache();
|
|
108
|
-
}
|
|
109
|
-
node.getLayer()?.batchDraw();
|
|
110
|
-
}, [
|
|
111
|
-
image,
|
|
112
|
-
width,
|
|
113
|
-
height,
|
|
114
|
-
part?.crop.x,
|
|
115
|
-
part?.crop.y,
|
|
116
|
-
draw?.x,
|
|
117
|
-
draw?.y,
|
|
118
|
-
draw?.width,
|
|
119
|
-
draw?.rotation,
|
|
120
|
-
color,
|
|
121
|
-
adjustments,
|
|
122
|
-
adjustmentFilters.length,
|
|
123
|
-
captureRatio,
|
|
124
|
-
]);
|
|
125
104
|
const handleTouchStart = useCallback((e) => {
|
|
126
105
|
const node = e.target;
|
|
127
106
|
if (touchDragNeedsSelection && !selected && draggable) {
|
|
@@ -222,7 +201,7 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
222
201
|
const pan = panStartRef.current;
|
|
223
202
|
if (pan && straight && natural && slot) {
|
|
224
203
|
// Der Knoten bleibt der Rahmen; das gedrehte Foto bewegt sich darin.
|
|
225
|
-
const moved = panStraightPhoto(straight, turnDeg, slot, node
|
|
204
|
+
const moved = panStraightPhoto(straight, turnDeg, slot, ...panDelta(node, pan));
|
|
226
205
|
node.position(slot);
|
|
227
206
|
if (turned) {
|
|
228
207
|
node.setAttr(STRAIGHT_DRAW_ATTR, straightDrawOf(moved, turnDeg, slot, mirror));
|
|
@@ -234,12 +213,11 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
234
213
|
}
|
|
235
214
|
pan.photo = moved;
|
|
236
215
|
placeCropGhost(ghostRef.current, moved, mirror, turnDeg);
|
|
237
|
-
recacheNextFrame(node);
|
|
238
216
|
return;
|
|
239
217
|
}
|
|
240
218
|
if (pan && natural && slot) {
|
|
241
219
|
// The node stays the visible part; the photo moves under it.
|
|
242
|
-
const next = panWindowPhoto(natural, { x, y, width, height }, slot, node
|
|
220
|
+
const next = panWindowPhoto(natural, { x, y, width, height }, slot, ...panDelta(node, pan), mirror);
|
|
243
221
|
if (!next.part)
|
|
244
222
|
return;
|
|
245
223
|
node.position(next.part.box);
|
|
@@ -249,7 +227,6 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
249
227
|
pan.dy = next.dy;
|
|
250
228
|
// Ziehen und Zoomen ändern die Knoten direkt; das Restbild geht ohne React-Zustand mit.
|
|
251
229
|
placeCropGhost(ghostRef.current, photoRectAround(natural, { x: x + next.dx, y: y + next.dy, width, height }), mirror);
|
|
252
|
-
recacheNextFrame(node);
|
|
253
230
|
return;
|
|
254
231
|
}
|
|
255
232
|
const nodeWidth = node.width() * node.scaleX();
|
|
@@ -299,8 +276,17 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
299
276
|
const handleDragStart = useCallback((e) => {
|
|
300
277
|
// In a group drag a cover-fitted image moves with the others; the background photo
|
|
301
278
|
// never joins one, outside Ausschnitt mode it is not draggable.
|
|
279
|
+
const node = e.target;
|
|
302
280
|
panStartRef.current =
|
|
303
|
-
part && !isGroupDrag(
|
|
281
|
+
part && !isGroupDrag(node)
|
|
282
|
+
? {
|
|
283
|
+
part: part.box,
|
|
284
|
+
pointer: pointerInParent(node),
|
|
285
|
+
dx: 0,
|
|
286
|
+
dy: 0,
|
|
287
|
+
photo: null,
|
|
288
|
+
}
|
|
289
|
+
: null;
|
|
304
290
|
snap.onDragStart();
|
|
305
291
|
}, [part, snap]);
|
|
306
292
|
// Tastatur im Ausschnitt-Modus: dieselben Grenzen und dieselbe Übernahme wie Ziehen und Zoomen.
|
|
@@ -398,7 +384,7 @@ function CanvasImageInner({ id, image, x, y, width, height, rotation = 0, opacit
|
|
|
398
384
|
if (!image)
|
|
399
385
|
return null;
|
|
400
386
|
const enabledAnchors = transformConfig?.enabledAnchors ?? DEFAULT_IMAGE_ANCHORS;
|
|
401
|
-
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) => {
|
|
402
388
|
const minWidth = transformConfig?.bounds?.minWidth ?? 20;
|
|
403
389
|
const maxWidth = transformConfig?.bounds?.maxWidth ?? Infinity;
|
|
404
390
|
if (newBox.width < minWidth)
|
|
@@ -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
|