Binding highlight rotation support + image support

This commit is contained in:
Mark Tolmacs
2025-08-27 15:43:48 +02:00
parent 80bd6cdd64
commit 571e4119ab
2 changed files with 21 additions and 10 deletions

View File

@@ -119,20 +119,21 @@ export class ShapeCache {
embedsValidationStatus: EmbedsValidationStatus; embedsValidationStatus: EmbedsValidationStatus;
}, },
) => { ) => {
const shape = generateElementShape( let shape =
element, (ShapeCache.get(element) as Drawable | null) ||
ShapeCache.rg, (ShapeCache.rg.rectangle(0, 0, element.width, element.height, {
renderConfig || { roughness: 0,
isExporting: false, strokeWidth: 2,
canvasBackgroundColor: COLOR_PALETTE.white, }) as Drawable);
embedsValidationStatus: null,
}, // Clone the shape from the cache
) as Drawable; shape = {
...shape,
};
shape.options.fill = "transparent"; shape.options.fill = "transparent";
shape.options.stroke = shape.options.stroke =
appState.theme === THEME.DARK ? "#035da1" : "#6abdfc"; appState.theme === THEME.DARK ? "#035da1" : "#6abdfc";
shape.options.strokeWidth = shape.options.strokeWidth * 1.1;
return shape; return shape;
}; };

View File

@@ -254,12 +254,22 @@ const renderBindingHighlight = (
appState: InteractiveCanvasAppState, appState: InteractiveCanvasAppState,
suggestedBinding: NonNullable<InteractiveCanvasAppState["suggestedBinding"]>, suggestedBinding: NonNullable<InteractiveCanvasAppState["suggestedBinding"]>,
) => { ) => {
const cx =
(suggestedBinding.x + suggestedBinding.width / 2 + appState.scrollX) *
window.devicePixelRatio;
const cy =
(suggestedBinding.y + suggestedBinding.height / 2 + appState.scrollY) *
window.devicePixelRatio;
context.save(); context.save();
context.translate(cx, cy);
context.rotate(suggestedBinding.angle);
context.translate(-cx, -cy);
context.translate( context.translate(
appState.scrollX + suggestedBinding.x, appState.scrollX + suggestedBinding.x,
appState.scrollY + suggestedBinding.y, appState.scrollY + suggestedBinding.y,
); );
context.scale(1 / window.devicePixelRatio, 1 / window.devicePixelRatio);
const drawable = ShapeCache.generateBindableElementHighlight( const drawable = ShapeCache.generateBindableElementHighlight(
suggestedBinding, suggestedBinding,