@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.
@@ -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
- const DEFAULT_TEXT_ANCHORS = ['middle-left', 'middle-right'];
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 || !isWidthOnlyScale(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 = Math.max(8, Math.round(currentFontSize * scaleY));
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 });
@@ -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, useMemo, memo } from 'react';
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 { cacheFiltered, usePreviewCaptureRatio } from '../utils/filterCache.js';
24
- import { recacheNextFrame } from '../utils/recacheNextFrame.js';
25
- import { clampPointToStraightPhoto, frameForAspectOnStraightPhoto, panOfStraightPhoto, panStraightPhoto, STRAIGHT_DRAW_ATTR, straightDrawOf, straightFramedPhoto, straightPhotoCovers, straightScaleCrop, straightSceneFunc, } from '../utils/straighten.js';
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, cropGhostSource, } from '../utils/cropGhost.js';
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
- // Konva filters require the node to be cached first.
123
- useEffect(() => {
124
- const node = imageRef.current;
125
- if (!node || !image)
126
- return;
127
- if (hasActiveImageFilters(userImage)) {
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, `straightSceneFunc` zeichnet.
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: ghostImage ?? image, ...(turned
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, filters: getActiveImageFilters(userImage), ...imageFilterAttrs(userImage), shadowColor: userImage.shadowColor, shadowBlur: userImage.shadowBlur, shadowOffsetX: userImage.shadowOffsetX, shadowOffsetY: userImage.shadowOffsetY, shadowOpacity: userImage.shadowOpacity, ...(draw ? { sceneFunc: straightSceneFunc, [STRAIGHT_DRAW_ATTR]: draw } : {}) })), isCropping && (_jsxs(_Fragment, { children: [_jsx(Rect, { ref: cropFrameRef, name: "selection-chrome", width: width, height: height, listening: false, onTransform: (e) => {
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;