feat(workspace): integrate persisted canvas, element editing and session renewal
This commit is contained in:
@@ -5,8 +5,8 @@ export type ResizeDirection = "top" | "right" | "bottom" | "left" | "top-left" |
|
||||
export type NodeTransform = { position?: XYPosition; width?: number; height?: number; rotation?: number; fontSize?: number };
|
||||
export function nodeSize(node: CanvasNode) {
|
||||
return {
|
||||
width: node.width || Number(node.style?.width) || node.measured?.width || (node.data.kind === "icon" ? 80 : node.data.kind === "plain-text" ? 240 : 260),
|
||||
height: node.height || Number(node.style?.height) || node.measured?.height || (node.data.kind === "icon" ? 80 : node.data.kind === "plain-text" ? 72 : 200),
|
||||
width: node.width || Number(node.style?.width) || node.measured?.width || (node.data.kind === "frame" ? 640 : node.data.kind === "plain-image" ? 320 : node.data.kind === "icon" ? 80 : node.data.kind === "plain-text" ? 240 : 260),
|
||||
height: node.height || Number(node.style?.height) || node.measured?.height || (node.data.kind === "frame" ? 400 : node.data.kind === "plain-image" ? 240 : node.data.kind === "icon" ? 80 : node.data.kind === "plain-text" ? 72 : 200),
|
||||
};
|
||||
}
|
||||
export function normalizeRotation(angle: number) { return ((angle % 360) + 360) % 360; }
|
||||
@@ -33,7 +33,7 @@ export function resizeFromPointer(node: CanvasNode, direction: ResizeDirection,
|
||||
const horizontal = direction.includes("left") ? -1 : direction.includes("right") ? 1 : 0;
|
||||
const vertical = direction.includes("top") ? -1 : direction.includes("bottom") ? 1 : 0;
|
||||
const plain = node.data.kind === "plain-text";
|
||||
const icon = node.data.kind === "icon";
|
||||
const icon = node.data.kind === "icon" || node.data.kind === "plain-image";
|
||||
let nextWidth = Math.max(plain ? 60 : 140, Math.min(3000, width + horizontal * local.x));
|
||||
let nextHeight = Math.max(plain ? 24 : 100, Math.min(3000, height + vertical * local.y));
|
||||
if (icon) {
|
||||
@@ -51,3 +51,21 @@ export function resizeFromPointer(node: CanvasNode, direction: ResizeDirection,
|
||||
width: nextWidth, height: nextHeight,
|
||||
};
|
||||
}
|
||||
|
||||
export type ConnectorSide = "top" | "right" | "bottom" | "left";
|
||||
export type Connector = { point: XYPosition; normal: XYPosition };
|
||||
/** Attach to the card border itself, independent of the handle's hit area. */
|
||||
export function nodeConnector(node: CanvasNode, side: ConnectorSide): Connector {
|
||||
const { width, height } = nodeSize(node);
|
||||
const vectors = { top: { x: 0, y: -1 }, right: { x: 1, y: 0 }, bottom: { x: 0, y: 1 }, left: { x: -1, y: 0 } };
|
||||
const local = vectors[side];
|
||||
const angle = node.data.rotation || 0;
|
||||
const normal = rotateVector(local, angle);
|
||||
const offset = rotateVector({ x: local.x * width / 2, y: local.y * height / 2 }, angle);
|
||||
const center = nodeCenter(node);
|
||||
return { point: { x: center.x + offset.x, y: center.y + offset.y }, normal };
|
||||
}
|
||||
export function connectorBezier(from: Connector, to: Connector) {
|
||||
const reach = Math.min(240, Math.max(40, Math.hypot(to.point.x - from.point.x, to.point.y - from.point.y) * 0.4));
|
||||
return `M ${from.point.x},${from.point.y} C ${from.point.x + from.normal.x * reach},${from.point.y + from.normal.y * reach} ${to.point.x + to.normal.x * reach},${to.point.y + to.normal.y * reach} ${to.point.x},${to.point.y}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user