Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4330f3ec9d | ||
|
|
d5aad6202d | ||
|
|
db73e30eae | ||
|
|
f472af04a9 |
@@ -1,4 +1,5 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import * as excalidrawLib from "@excalidraw/excalidraw";
|
import * as excalidrawLib from "@excalidraw/excalidraw";
|
||||||
import { Excalidraw } from "@excalidraw/excalidraw";
|
import { Excalidraw } from "@excalidraw/excalidraw";
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ const ExcalidrawWrapper: React.FC = () => {
|
|||||||
appTitle={"Excalidraw with Nextjs Example"}
|
appTitle={"Excalidraw with Nextjs Example"}
|
||||||
useCustom={(api: any, args?: any[]) => {}}
|
useCustom={(api: any, args?: any[]) => {}}
|
||||||
excalidrawLib={excalidrawLib}
|
excalidrawLib={excalidrawLib}
|
||||||
|
showFadeDemo={true}
|
||||||
>
|
>
|
||||||
<Excalidraw />
|
<Excalidraw />
|
||||||
</App>
|
</App>
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ export interface AppProps {
|
|||||||
customArgs?: any[];
|
customArgs?: any[];
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
excalidrawLib: typeof TExcalidraw;
|
excalidrawLib: typeof TExcalidraw;
|
||||||
|
showFadeDemo?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ExampleApp({
|
export default function ExampleApp({
|
||||||
@@ -78,6 +79,7 @@ export default function ExampleApp({
|
|||||||
customArgs,
|
customArgs,
|
||||||
children,
|
children,
|
||||||
excalidrawLib,
|
excalidrawLib,
|
||||||
|
showFadeDemo = false,
|
||||||
}: AppProps) {
|
}: AppProps) {
|
||||||
const {
|
const {
|
||||||
exportToCanvas,
|
exportToCanvas,
|
||||||
@@ -116,6 +118,19 @@ export default function ExampleApp({
|
|||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
const [comment, setComment] = useState<Comment | null>(null);
|
const [comment, setComment] = useState<Comment | null>(null);
|
||||||
|
const [hideAllForFadeDemo, setHideAllForFadeDemo] = useState(false);
|
||||||
|
const [fadeDemoNextIndex, setFadeDemoNextIndex] = useState(0);
|
||||||
|
const [fadeDemoElementIds, setFadeDemoElementIds] = useState<string[]>([]);
|
||||||
|
const [demoAnimationType, setDemoAnimationType] = useState<"fade" | "fly">(
|
||||||
|
"fade",
|
||||||
|
);
|
||||||
|
const [demoAnimationDuration, setDemoAnimationDuration] = useState(500);
|
||||||
|
const [demoFlyFrom, setDemoFlyFrom] = useState<
|
||||||
|
"left" | "right" | "top" | "bottom"
|
||||||
|
>("left");
|
||||||
|
const [demoAnimationEasing, setDemoAnimationEasing] = useState<
|
||||||
|
"linear" | "easeOut" | "easeInOut"
|
||||||
|
>("easeOut");
|
||||||
|
|
||||||
const initialStatePromiseRef = useRef<{
|
const initialStatePromiseRef = useRef<{
|
||||||
promise: ResolvablePromise<ExcalidrawInitialDataState | null>;
|
promise: ResolvablePromise<ExcalidrawInitialDataState | null>;
|
||||||
@@ -178,7 +193,8 @@ export default function ExampleApp({
|
|||||||
const newElement = cloneElement(
|
const newElement = cloneElement(
|
||||||
Excalidraw,
|
Excalidraw,
|
||||||
{
|
{
|
||||||
excalidrawAPI: (api: ExcalidrawImperativeAPI) => setExcalidrawAPI(api),
|
onExcalidrawAPI: (api: ExcalidrawImperativeAPI | null) =>
|
||||||
|
setExcalidrawAPI(api),
|
||||||
initialData: initialStatePromiseRef.current.promise,
|
initialData: initialStatePromiseRef.current.promise,
|
||||||
onChange: (
|
onChange: (
|
||||||
elements: NonDeletedExcalidrawElement[],
|
elements: NonDeletedExcalidrawElement[],
|
||||||
@@ -208,6 +224,10 @@ export default function ExampleApp({
|
|||||||
onPointerDown,
|
onPointerDown,
|
||||||
onScrollChange: rerenderCommentIcons,
|
onScrollChange: rerenderCommentIcons,
|
||||||
validateEmbeddable: true,
|
validateEmbeddable: true,
|
||||||
|
resolveRenderOpacity: hideAllForFadeDemo
|
||||||
|
? (element: NonDeletedExcalidrawElement) =>
|
||||||
|
fadeDemoElementIds.includes(element.id) ? 0 : undefined
|
||||||
|
: undefined,
|
||||||
},
|
},
|
||||||
<>
|
<>
|
||||||
{excalidrawAPI && (
|
{excalidrawAPI && (
|
||||||
@@ -664,6 +684,229 @@ export default function ExampleApp({
|
|||||||
>
|
>
|
||||||
Reset Scene
|
Reset Scene
|
||||||
</button>
|
</button>
|
||||||
|
{showFadeDemo && (
|
||||||
|
<>
|
||||||
|
<label>
|
||||||
|
Animation type
|
||||||
|
<select
|
||||||
|
value={demoAnimationType}
|
||||||
|
onChange={(event) =>
|
||||||
|
setDemoAnimationType(
|
||||||
|
event.target.value as "fade" | "fly",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option value="fade">fade</option>
|
||||||
|
<option value="fly">fly</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
Duration
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
value={demoAnimationDuration}
|
||||||
|
onChange={(event) =>
|
||||||
|
setDemoAnimationDuration(Number(event.target.value) || 0)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
Easing
|
||||||
|
<select
|
||||||
|
value={demoAnimationEasing}
|
||||||
|
onChange={(event) =>
|
||||||
|
setDemoAnimationEasing(
|
||||||
|
event.target.value as "linear" | "easeOut" | "easeInOut",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option value="linear">linear</option>
|
||||||
|
<option value="easeOut">easeOut</option>
|
||||||
|
<option value="easeInOut">easeInOut</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
{demoAnimationType === "fly" && (
|
||||||
|
<label>
|
||||||
|
Fly from
|
||||||
|
<select
|
||||||
|
value={demoFlyFrom}
|
||||||
|
onChange={(event) =>
|
||||||
|
setDemoFlyFrom(
|
||||||
|
event.target.value as
|
||||||
|
| "left"
|
||||||
|
| "right"
|
||||||
|
| "top"
|
||||||
|
| "bottom",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option value="left">left</option>
|
||||||
|
<option value="right">right</option>
|
||||||
|
<option value="top">top</option>
|
||||||
|
<option value="bottom">bottom</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
)}
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
if (!excalidrawAPI) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setFadeDemoElementIds(
|
||||||
|
excalidrawAPI
|
||||||
|
.getSceneElements()
|
||||||
|
.map((element) => element.id),
|
||||||
|
);
|
||||||
|
excalidrawAPI.clearElementAnimationOverrides();
|
||||||
|
setHideAllForFadeDemo(true);
|
||||||
|
setFadeDemoNextIndex(0);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Hide every element
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
if (!excalidrawAPI || !hideAllForFadeDemo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const elements = excalidrawAPI
|
||||||
|
.getSceneElements()
|
||||||
|
.filter((element) =>
|
||||||
|
fadeDemoElementIds.includes(element.id),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!elements.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextIndex =
|
||||||
|
fadeDemoNextIndex >= elements.length
|
||||||
|
? 0
|
||||||
|
: fadeDemoNextIndex;
|
||||||
|
|
||||||
|
if (nextIndex === 0) {
|
||||||
|
excalidrawAPI.clearElementAnimationOverrides();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (demoAnimationType === "fly") {
|
||||||
|
excalidrawAPI.animateElements({
|
||||||
|
elements: [elements[nextIndex].id],
|
||||||
|
type: "fly",
|
||||||
|
from: demoFlyFrom,
|
||||||
|
duration: demoAnimationDuration,
|
||||||
|
phase: "in",
|
||||||
|
easing: demoAnimationEasing,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
excalidrawAPI.animateElements({
|
||||||
|
elements: [elements[nextIndex].id],
|
||||||
|
type: "fade",
|
||||||
|
duration: demoAnimationDuration,
|
||||||
|
phase: "in",
|
||||||
|
easing: demoAnimationEasing,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setFadeDemoNextIndex(nextIndex + 1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Animate in next element
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
if (!excalidrawAPI || !hideAllForFadeDemo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const elements = excalidrawAPI
|
||||||
|
.getSceneElements()
|
||||||
|
.filter((element) =>
|
||||||
|
fadeDemoElementIds.includes(element.id),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!elements.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (demoAnimationType === "fly") {
|
||||||
|
excalidrawAPI.animateElements({
|
||||||
|
elements,
|
||||||
|
type: "fly",
|
||||||
|
from: demoFlyFrom,
|
||||||
|
duration: demoAnimationDuration,
|
||||||
|
stagger: 120,
|
||||||
|
phase: "in",
|
||||||
|
easing: demoAnimationEasing,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
excalidrawAPI.animateElements({
|
||||||
|
elements,
|
||||||
|
type: "fade",
|
||||||
|
duration: demoAnimationDuration,
|
||||||
|
stagger: 120,
|
||||||
|
phase: "in",
|
||||||
|
easing: demoAnimationEasing,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setFadeDemoNextIndex(elements.length);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Animate in all
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
if (!excalidrawAPI || !hideAllForFadeDemo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const elements = excalidrawAPI
|
||||||
|
.getSceneElements()
|
||||||
|
.filter((element) =>
|
||||||
|
fadeDemoElementIds.includes(element.id),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!elements.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const prevIndex = Math.min(
|
||||||
|
fadeDemoNextIndex - 1,
|
||||||
|
elements.length - 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (prevIndex < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (demoAnimationType === "fly") {
|
||||||
|
excalidrawAPI.animateElements({
|
||||||
|
elements: [elements[prevIndex].id],
|
||||||
|
type: "fly",
|
||||||
|
from: demoFlyFrom,
|
||||||
|
duration: demoAnimationDuration,
|
||||||
|
phase: "out",
|
||||||
|
easing: demoAnimationEasing,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
excalidrawAPI.animateElements({
|
||||||
|
elements: [elements[prevIndex].id],
|
||||||
|
type: "fade",
|
||||||
|
duration: demoAnimationDuration,
|
||||||
|
phase: "out",
|
||||||
|
easing: demoAnimationEasing,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setFadeDemoNextIndex(prevIndex);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Animate out prev element
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const libraryItems: LibraryItems = [
|
const libraryItems: LibraryItems = [
|
||||||
|
|||||||
@@ -2,6 +2,28 @@ import type { ExcalidrawElementSkeleton } from "@excalidraw/excalidraw/element/t
|
|||||||
import type { FileId } from "@excalidraw/excalidraw/element/types";
|
import type { FileId } from "@excalidraw/excalidraw/element/types";
|
||||||
|
|
||||||
const elements: ExcalidrawElementSkeleton[] = [
|
const elements: ExcalidrawElementSkeleton[] = [
|
||||||
|
// {
|
||||||
|
// type: "arrow",
|
||||||
|
// x: 100,
|
||||||
|
// y: 500,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// type: "arrow",
|
||||||
|
// x: 250,
|
||||||
|
// y: 250,
|
||||||
|
// label: {
|
||||||
|
// text: "HELLO WORLD!!",
|
||||||
|
// },
|
||||||
|
// start: {
|
||||||
|
// type: "rectangle",
|
||||||
|
// // x: -100,
|
||||||
|
// },
|
||||||
|
// end: {
|
||||||
|
// type: "ellipse",
|
||||||
|
// // x: 300,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
|
||||||
{
|
{
|
||||||
type: "rectangle",
|
type: "rectangle",
|
||||||
x: 10,
|
x: 10,
|
||||||
@@ -22,14 +44,14 @@ const elements: ExcalidrawElementSkeleton[] = [
|
|||||||
},
|
},
|
||||||
id: "2",
|
id: "2",
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
type: "arrow",
|
// type: "arrow",
|
||||||
x: 100,
|
// x: 100,
|
||||||
y: 200,
|
// y: 200,
|
||||||
label: { text: "HELLO WORLD!!" },
|
// label: { text: "HELLO WORLD!!" },
|
||||||
start: { type: "rectangle" },
|
// start: { type: "rectangle" },
|
||||||
end: { type: "ellipse" },
|
// end: { type: "ellipse" },
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
type: "image",
|
type: "image",
|
||||||
x: 606.1042326312408,
|
x: 606.1042326312408,
|
||||||
@@ -38,11 +60,11 @@ const elements: ExcalidrawElementSkeleton[] = [
|
|||||||
height: 230,
|
height: 230,
|
||||||
fileId: "rocket" as FileId,
|
fileId: "rocket" as FileId,
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
type: "frame",
|
// type: "frame",
|
||||||
children: ["1", "2"],
|
// children: ["1", "2"],
|
||||||
name: "My frame",
|
// name: "My frame",
|
||||||
},
|
// },
|
||||||
];
|
];
|
||||||
export default {
|
export default {
|
||||||
elements,
|
elements,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
getBindingGap,
|
getBindingGap,
|
||||||
getGlobalFixedPointForBindableElement,
|
getGlobalFixedPointForBindableElement,
|
||||||
isBindingEnabled,
|
isBindingEnabled,
|
||||||
|
maxBindingDistance_simple,
|
||||||
unbindBindingElement,
|
unbindBindingElement,
|
||||||
updateBoundPoint,
|
updateBoundPoint,
|
||||||
} from "../binding";
|
} from "../binding";
|
||||||
@@ -19,7 +20,7 @@ import {
|
|||||||
isElbowArrow,
|
isElbowArrow,
|
||||||
} from "../typeChecks";
|
} from "../typeChecks";
|
||||||
import { LinearElementEditor } from "../linearElementEditor";
|
import { LinearElementEditor } from "../linearElementEditor";
|
||||||
import { getHoveredElementForBinding, hitElementItself } from "../collision";
|
import { getHoveredElementForFocusPoint, hitElementItself } from "../collision";
|
||||||
import { moveArrowAboveBindable } from "../zindex";
|
import { moveArrowAboveBindable } from "../zindex";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -91,7 +92,7 @@ export const isFocusPointVisible = (
|
|||||||
element: bindableElement,
|
element: bindableElement,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
point: focusPoint,
|
point: focusPoint,
|
||||||
threshold: getBindingGap(bindableElement),
|
threshold: getBindingGap(bindableElement, arrow),
|
||||||
overrideShouldTestInside: true,
|
overrideShouldTestInside: true,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -233,12 +234,12 @@ export const handleFocusPointDrag = (
|
|||||||
pointerCoords.y - offsetY,
|
pointerCoords.y - offsetY,
|
||||||
);
|
);
|
||||||
const bindingField = isStartBinding ? "startBinding" : "endBinding";
|
const bindingField = isStartBinding ? "startBinding" : "endBinding";
|
||||||
const hit = getHoveredElementForBinding(
|
const hit = getHoveredElementForFocusPoint(
|
||||||
arrow,
|
|
||||||
point,
|
point,
|
||||||
|
arrow,
|
||||||
scene.getNonDeletedElements(),
|
scene.getNonDeletedElements(),
|
||||||
elementsMap,
|
elementsMap,
|
||||||
appState.zoom,
|
maxBindingDistance_simple(appState.zoom),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Hovering a bindable element
|
// Hovering a bindable element
|
||||||
@@ -269,7 +270,6 @@ export const handleFocusPointDrag = (
|
|||||||
newMode || "orbit",
|
newMode || "orbit",
|
||||||
linearElementEditor.draggedFocusPointBinding,
|
linearElementEditor.draggedFocusPointBinding,
|
||||||
scene,
|
scene,
|
||||||
appState.zoom,
|
|
||||||
point,
|
point,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+134
-38
@@ -60,7 +60,6 @@ import { updateElbowArrowPoints } from "./elbowArrow";
|
|||||||
import {
|
import {
|
||||||
deconstructDiamondElement,
|
deconstructDiamondElement,
|
||||||
deconstructRectanguloidElement,
|
deconstructRectanguloidElement,
|
||||||
getSnapOutlineMidPoint,
|
|
||||||
projectFixedPointOntoDiagonal,
|
projectFixedPointOntoDiagonal,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
|
|
||||||
@@ -111,13 +110,18 @@ export type BindingStrategy =
|
|||||||
* IMPORTANT: currently must be > 0 (this also applies to the computed gap)
|
* IMPORTANT: currently must be > 0 (this also applies to the computed gap)
|
||||||
*/
|
*/
|
||||||
export const BASE_BINDING_GAP = 5;
|
export const BASE_BINDING_GAP = 5;
|
||||||
|
export const BASE_BINDING_GAP_ELBOW = 5;
|
||||||
export const BASE_ARROW_MIN_LENGTH = 10;
|
export const BASE_ARROW_MIN_LENGTH = 10;
|
||||||
export const FOCUS_POINT_SIZE = 10 / 1.5;
|
export const FOCUS_POINT_SIZE = 10 / 1.5;
|
||||||
|
|
||||||
export const getBindingGap = (
|
export const getBindingGap = (
|
||||||
bindTarget: ExcalidrawBindableElement,
|
bindTarget: ExcalidrawBindableElement,
|
||||||
|
opts: Pick<ExcalidrawArrowElement, "elbowed">,
|
||||||
): number => {
|
): number => {
|
||||||
return BASE_BINDING_GAP + bindTarget.strokeWidth / 2;
|
return (
|
||||||
|
(opts.elbowed ? BASE_BINDING_GAP_ELBOW : BASE_BINDING_GAP) +
|
||||||
|
bindTarget.strokeWidth / 2
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const maxBindingDistance_simple = (zoom?: AppState["zoom"]): number => {
|
export const maxBindingDistance_simple = (zoom?: AppState["zoom"]): number => {
|
||||||
@@ -171,7 +175,6 @@ export const bindOrUnbindBindingElement = (
|
|||||||
start,
|
start,
|
||||||
"start",
|
"start",
|
||||||
scene,
|
scene,
|
||||||
appState.zoom,
|
|
||||||
appState.isBindingEnabled,
|
appState.isBindingEnabled,
|
||||||
);
|
);
|
||||||
bindOrUnbindBindingElementEdge(
|
bindOrUnbindBindingElementEdge(
|
||||||
@@ -179,7 +182,6 @@ export const bindOrUnbindBindingElement = (
|
|||||||
end,
|
end,
|
||||||
"end",
|
"end",
|
||||||
scene,
|
scene,
|
||||||
appState.zoom,
|
|
||||||
appState.isBindingEnabled,
|
appState.isBindingEnabled,
|
||||||
);
|
);
|
||||||
if (start.focusPoint || end.focusPoint) {
|
if (start.focusPoint || end.focusPoint) {
|
||||||
@@ -224,7 +226,6 @@ const bindOrUnbindBindingElementEdge = (
|
|||||||
{ mode, element, focusPoint }: BindingStrategy,
|
{ mode, element, focusPoint }: BindingStrategy,
|
||||||
startOrEnd: "start" | "end",
|
startOrEnd: "start" | "end",
|
||||||
scene: Scene,
|
scene: Scene,
|
||||||
zoom: AppState["zoom"],
|
|
||||||
shouldSnapToOutline = true,
|
shouldSnapToOutline = true,
|
||||||
): void => {
|
): void => {
|
||||||
if (mode === null) {
|
if (mode === null) {
|
||||||
@@ -237,7 +238,6 @@ const bindOrUnbindBindingElementEdge = (
|
|||||||
mode,
|
mode,
|
||||||
startOrEnd,
|
startOrEnd,
|
||||||
scene,
|
scene,
|
||||||
zoom,
|
|
||||||
focusPoint,
|
focusPoint,
|
||||||
shouldSnapToOutline,
|
shouldSnapToOutline,
|
||||||
);
|
);
|
||||||
@@ -270,11 +270,10 @@ const bindingStrategyForElbowArrowEndpointDragging = (
|
|||||||
elementsMap,
|
elementsMap,
|
||||||
);
|
);
|
||||||
const hit = getHoveredElementForBinding(
|
const hit = getHoveredElementForBinding(
|
||||||
arrow,
|
|
||||||
globalPoint,
|
globalPoint,
|
||||||
elements,
|
elements,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
zoom,
|
maxBindingDistance_simple(zoom),
|
||||||
);
|
);
|
||||||
|
|
||||||
const current = hit
|
const current = hit
|
||||||
@@ -322,7 +321,7 @@ const bindingStrategyForNewSimpleArrowEndpointDragging = (
|
|||||||
draggingPoints.get(startDragged ? startIdx : endIdx)!.point,
|
draggingPoints.get(startDragged ? startIdx : endIdx)!.point,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
);
|
);
|
||||||
const hit = getHoveredElementForBinding(arrow, point, elements, elementsMap);
|
const hit = getHoveredElementForBinding(point, elements, elementsMap);
|
||||||
|
|
||||||
// With new arrows this handles the binding at arrow creation
|
// With new arrows this handles the binding at arrow creation
|
||||||
if (startDragged) {
|
if (startDragged) {
|
||||||
@@ -367,12 +366,7 @@ const bindingStrategyForNewSimpleArrowEndpointDragging = (
|
|||||||
// Check and handle nested shapes
|
// Check and handle nested shapes
|
||||||
if (hit && arrow.startBinding) {
|
if (hit && arrow.startBinding) {
|
||||||
const startBinding = arrow.startBinding;
|
const startBinding = arrow.startBinding;
|
||||||
const allHits = getAllHoveredElementAtPoint(
|
const allHits = getAllHoveredElementAtPoint(point, elements, elementsMap);
|
||||||
arrow,
|
|
||||||
point,
|
|
||||||
elements,
|
|
||||||
elementsMap,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (allHits.find((el) => el.id === startBinding.elementId)) {
|
if (allHits.find((el) => el.id === startBinding.elementId)) {
|
||||||
const otherElement = elementsMap.get(
|
const otherElement = elementsMap.get(
|
||||||
@@ -474,9 +468,9 @@ const bindingStrategyForSimpleArrowEndpointDragging_complex = (
|
|||||||
let other: BindingStrategy = { mode: undefined };
|
let other: BindingStrategy = { mode: undefined };
|
||||||
|
|
||||||
const isMultiPoint = arrow.points.length > 2;
|
const isMultiPoint = arrow.points.length > 2;
|
||||||
const hit = getHoveredElementForBinding(arrow, point, elements, elementsMap);
|
const hit = getHoveredElementForBinding(point, elements, elementsMap);
|
||||||
const isOverlapping = oppositeBinding
|
const isOverlapping = oppositeBinding
|
||||||
? getAllHoveredElementAtPoint(arrow, point, elements, elementsMap).some(
|
? getAllHoveredElementAtPoint(point, elements, elementsMap).some(
|
||||||
(el) => el.id === oppositeBinding.elementId,
|
(el) => el.id === oppositeBinding.elementId,
|
||||||
)
|
)
|
||||||
: false;
|
: false;
|
||||||
@@ -701,11 +695,10 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
|||||||
elementsMap,
|
elementsMap,
|
||||||
);
|
);
|
||||||
const hit = getHoveredElementForBinding(
|
const hit = getHoveredElementForBinding(
|
||||||
arrow,
|
|
||||||
globalPoint,
|
globalPoint,
|
||||||
elements,
|
elements,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
appState.zoom,
|
maxBindingDistance_simple(appState.zoom),
|
||||||
);
|
);
|
||||||
const pointInElement =
|
const pointInElement =
|
||||||
hit &&
|
hit &&
|
||||||
@@ -1026,7 +1019,6 @@ export const bindBindingElement = (
|
|||||||
mode: BindMode,
|
mode: BindMode,
|
||||||
startOrEnd: "start" | "end",
|
startOrEnd: "start" | "end",
|
||||||
scene: Scene,
|
scene: Scene,
|
||||||
zoom: AppState["zoom"],
|
|
||||||
focusPoint?: GlobalPoint,
|
focusPoint?: GlobalPoint,
|
||||||
shouldSnapToOutline = true,
|
shouldSnapToOutline = true,
|
||||||
): void => {
|
): void => {
|
||||||
@@ -1043,7 +1035,6 @@ export const bindBindingElement = (
|
|||||||
hoveredElement,
|
hoveredElement,
|
||||||
startOrEnd,
|
startOrEnd,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
zoom,
|
|
||||||
shouldSnapToOutline,
|
shouldSnapToOutline,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
@@ -1268,7 +1259,6 @@ const updateArrowBindings = (
|
|||||||
strategy[strategyName].mode,
|
strategy[strategyName].mode,
|
||||||
strategyName,
|
strategyName,
|
||||||
scene,
|
scene,
|
||||||
appState.zoom,
|
|
||||||
strategy[strategyName].focusPoint,
|
strategy[strategyName].focusPoint,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1378,7 +1368,6 @@ export const bindPointToSnapToElementOutline = (
|
|||||||
bindableElement: ExcalidrawBindableElement,
|
bindableElement: ExcalidrawBindableElement,
|
||||||
startOrEnd: "start" | "end",
|
startOrEnd: "start" | "end",
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
zoom: AppState["zoom"],
|
|
||||||
customIntersector?: LineSegment<GlobalPoint>,
|
customIntersector?: LineSegment<GlobalPoint>,
|
||||||
isMidpointSnappingEnabled = true,
|
isMidpointSnappingEnabled = true,
|
||||||
): GlobalPoint => {
|
): GlobalPoint => {
|
||||||
@@ -1411,7 +1400,7 @@ export const bindPointToSnapToElementOutline = (
|
|||||||
startOrEnd === "start" ? 1 : -2,
|
startOrEnd === "start" ? 1 : -2,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
);
|
);
|
||||||
const bindingGap = getBindingGap(bindableElement);
|
const bindingGap = getBindingGap(bindableElement, arrowElement);
|
||||||
const aabb = aabbForElement(bindableElement, elementsMap);
|
const aabb = aabbForElement(bindableElement, elementsMap);
|
||||||
const bindableCenter = getCenterForBounds(aabb);
|
const bindableCenter = getCenterForBounds(aabb);
|
||||||
|
|
||||||
@@ -1421,13 +1410,7 @@ export const bindPointToSnapToElementOutline = (
|
|||||||
headingForPointFromElement(bindableElement, aabb, point),
|
headingForPointFromElement(bindableElement, aabb, point),
|
||||||
);
|
);
|
||||||
const snapPoint = isMidpointSnappingEnabled
|
const snapPoint = isMidpointSnappingEnabled
|
||||||
? getSnapOutlineMidPoint(
|
? snapToMid(bindableElement, elementsMap, edgePoint, 0.05, arrowElement)
|
||||||
edgePoint,
|
|
||||||
bindableElement,
|
|
||||||
elementsMap,
|
|
||||||
zoom,
|
|
||||||
arrowElement,
|
|
||||||
)
|
|
||||||
: undefined;
|
: undefined;
|
||||||
const resolved = snapPoint || point;
|
const resolved = snapPoint || point;
|
||||||
const otherPoint = pointFrom<GlobalPoint>(
|
const otherPoint = pointFrom<GlobalPoint>(
|
||||||
@@ -1472,7 +1455,7 @@ export const bindPointToSnapToElementOutline = (
|
|||||||
bindableElement,
|
bindableElement,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
anotherIntersector,
|
anotherIntersector,
|
||||||
BASE_BINDING_GAP,
|
BASE_BINDING_GAP_ELBOW,
|
||||||
).sort(pointDistanceSq)[0];
|
).sort(pointDistanceSq)[0];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1531,7 +1514,7 @@ export const avoidRectangularCorner = (
|
|||||||
-bindTarget.angle as Radians,
|
-bindTarget.angle as Radians,
|
||||||
);
|
);
|
||||||
|
|
||||||
const bindingGap = getBindingGap(bindTarget);
|
const bindingGap = getBindingGap(bindTarget, arrowElement);
|
||||||
|
|
||||||
if (nonRotatedPoint[0] < bindTarget.x && nonRotatedPoint[1] < bindTarget.y) {
|
if (nonRotatedPoint[0] < bindTarget.x && nonRotatedPoint[1] < bindTarget.y) {
|
||||||
// Top left
|
// Top left
|
||||||
@@ -1609,6 +1592,121 @@ export const avoidRectangularCorner = (
|
|||||||
return p;
|
return p;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const snapToMid = (
|
||||||
|
bindTarget: ExcalidrawBindableElement,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
|
p: GlobalPoint,
|
||||||
|
tolerance: number = 0.05,
|
||||||
|
arrowElement?: ExcalidrawArrowElement,
|
||||||
|
): GlobalPoint | undefined => {
|
||||||
|
const { x, y, width, height, angle } = bindTarget;
|
||||||
|
const center = elementCenterPoint(bindTarget, elementsMap, -0.1, -0.1);
|
||||||
|
const nonRotated = pointRotateRads(p, center, -angle as Radians);
|
||||||
|
|
||||||
|
const bindingGap = arrowElement ? getBindingGap(bindTarget, arrowElement) : 0;
|
||||||
|
|
||||||
|
// snap-to-center point is adaptive to element size, but we don't want to go
|
||||||
|
// above and below certain px distance
|
||||||
|
const verticalThreshold = clamp(tolerance * height, 5, 80);
|
||||||
|
const horizontalThreshold = clamp(tolerance * width, 5, 80);
|
||||||
|
|
||||||
|
// Too close to the center makes it hard to resolve direction precisely
|
||||||
|
if (pointDistance(center, nonRotated) < bindingGap) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
nonRotated[0] <= x + width / 2 &&
|
||||||
|
nonRotated[1] > center[1] - verticalThreshold &&
|
||||||
|
nonRotated[1] < center[1] + verticalThreshold
|
||||||
|
) {
|
||||||
|
// LEFT
|
||||||
|
return pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(x - bindingGap, center[1]),
|
||||||
|
center,
|
||||||
|
angle,
|
||||||
|
);
|
||||||
|
} else if (
|
||||||
|
nonRotated[1] <= y + height / 2 &&
|
||||||
|
nonRotated[0] > center[0] - horizontalThreshold &&
|
||||||
|
nonRotated[0] < center[0] + horizontalThreshold
|
||||||
|
) {
|
||||||
|
// TOP
|
||||||
|
return pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(center[0], y - bindingGap),
|
||||||
|
center,
|
||||||
|
angle,
|
||||||
|
);
|
||||||
|
} else if (
|
||||||
|
nonRotated[0] >= x + width / 2 &&
|
||||||
|
nonRotated[1] > center[1] - verticalThreshold &&
|
||||||
|
nonRotated[1] < center[1] + verticalThreshold
|
||||||
|
) {
|
||||||
|
// RIGHT
|
||||||
|
return pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(x + width + bindingGap, center[1]),
|
||||||
|
center,
|
||||||
|
angle,
|
||||||
|
);
|
||||||
|
} else if (
|
||||||
|
nonRotated[1] >= y + height / 2 &&
|
||||||
|
nonRotated[0] > center[0] - horizontalThreshold &&
|
||||||
|
nonRotated[0] < center[0] + horizontalThreshold
|
||||||
|
) {
|
||||||
|
// DOWN
|
||||||
|
return pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(center[0], y + height + bindingGap),
|
||||||
|
center,
|
||||||
|
angle,
|
||||||
|
);
|
||||||
|
} else if (bindTarget.type === "diamond") {
|
||||||
|
const distance = bindingGap;
|
||||||
|
const topLeft = pointFrom<GlobalPoint>(
|
||||||
|
x + width / 4 - distance,
|
||||||
|
y + height / 4 - distance,
|
||||||
|
);
|
||||||
|
const topRight = pointFrom<GlobalPoint>(
|
||||||
|
x + (3 * width) / 4 + distance,
|
||||||
|
y + height / 4 - distance,
|
||||||
|
);
|
||||||
|
const bottomLeft = pointFrom<GlobalPoint>(
|
||||||
|
x + width / 4 - distance,
|
||||||
|
y + (3 * height) / 4 + distance,
|
||||||
|
);
|
||||||
|
const bottomRight = pointFrom<GlobalPoint>(
|
||||||
|
x + (3 * width) / 4 + distance,
|
||||||
|
y + (3 * height) / 4 + distance,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
pointDistance(topLeft, nonRotated) <
|
||||||
|
Math.max(horizontalThreshold, verticalThreshold)
|
||||||
|
) {
|
||||||
|
return pointRotateRads(topLeft, center, angle);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
pointDistance(topRight, nonRotated) <
|
||||||
|
Math.max(horizontalThreshold, verticalThreshold)
|
||||||
|
) {
|
||||||
|
return pointRotateRads(topRight, center, angle);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
pointDistance(bottomLeft, nonRotated) <
|
||||||
|
Math.max(horizontalThreshold, verticalThreshold)
|
||||||
|
) {
|
||||||
|
return pointRotateRads(bottomLeft, center, angle);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
pointDistance(bottomRight, nonRotated) <
|
||||||
|
Math.max(horizontalThreshold, verticalThreshold)
|
||||||
|
) {
|
||||||
|
return pointRotateRads(bottomRight, center, angle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
const extractBinding = (
|
const extractBinding = (
|
||||||
arrow: ExcalidrawArrowElement,
|
arrow: ExcalidrawArrowElement,
|
||||||
startOrEnd: "startBinding" | "endBinding",
|
startOrEnd: "startBinding" | "endBinding",
|
||||||
@@ -1709,7 +1807,7 @@ export const updateBoundPoint = (
|
|||||||
otherBindable,
|
otherBindable,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
intersector,
|
intersector,
|
||||||
getBindingGap(otherBindable),
|
getBindingGap(otherBindable, arrow),
|
||||||
).sort(
|
).sort(
|
||||||
(a, b) => pointDistanceSq(a, focusPoint) - pointDistanceSq(b, focusPoint),
|
(a, b) => pointDistanceSq(a, focusPoint) - pointDistanceSq(b, focusPoint),
|
||||||
)[0];
|
)[0];
|
||||||
@@ -1719,7 +1817,7 @@ export const updateBoundPoint = (
|
|||||||
bindableElement,
|
bindableElement,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
intersector,
|
intersector,
|
||||||
getBindingGap(bindableElement),
|
getBindingGap(bindableElement, arrow),
|
||||||
).sort(
|
).sort(
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
pointDistanceSq(a, otherFocusPointOrArrowPoint) -
|
pointDistanceSq(a, otherFocusPointOrArrowPoint) -
|
||||||
@@ -1747,7 +1845,7 @@ export const updateBoundPoint = (
|
|||||||
element: otherBindable,
|
element: otherBindable,
|
||||||
point: outlinePoint,
|
point: outlinePoint,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
threshold: getBindingGap(otherBindable),
|
threshold: getBindingGap(otherBindable, arrow),
|
||||||
overrideShouldTestInside: true,
|
overrideShouldTestInside: true,
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
@@ -1808,7 +1906,6 @@ export const calculateFixedPointForElbowArrowBinding = (
|
|||||||
hoveredElement: ExcalidrawBindableElement,
|
hoveredElement: ExcalidrawBindableElement,
|
||||||
startOrEnd: "start" | "end",
|
startOrEnd: "start" | "end",
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
zoom: AppState["zoom"],
|
|
||||||
shouldSnapToOutline = true,
|
shouldSnapToOutline = true,
|
||||||
isMidpointSnappingEnabled = true,
|
isMidpointSnappingEnabled = true,
|
||||||
): { fixedPoint: FixedPoint } => {
|
): { fixedPoint: FixedPoint } => {
|
||||||
@@ -1824,7 +1921,6 @@ export const calculateFixedPointForElbowArrowBinding = (
|
|||||||
hoveredElement,
|
hoveredElement,
|
||||||
startOrEnd,
|
startOrEnd,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
zoom,
|
|
||||||
undefined,
|
undefined,
|
||||||
isMidpointSnappingEnabled,
|
isMidpointSnappingEnabled,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import type {
|
|||||||
Radians,
|
Radians,
|
||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
import type { AppState, FrameNameBounds } from "@excalidraw/excalidraw/types";
|
import type { FrameNameBounds } from "@excalidraw/excalidraw/types";
|
||||||
|
|
||||||
import { isPathALoop } from "./utils";
|
import { isPathALoop } from "./utils";
|
||||||
import {
|
import {
|
||||||
@@ -59,12 +59,13 @@ import { LinearElementEditor } from "./linearElementEditor";
|
|||||||
|
|
||||||
import { distanceToElement } from "./distance";
|
import { distanceToElement } from "./distance";
|
||||||
|
|
||||||
import { getBindingGap, maxBindingDistance_simple } from "./binding";
|
import { getBindingGap } from "./binding";
|
||||||
|
|
||||||
import { hasBackground } from "./comparisons";
|
import { hasBackground } from "./comparisons";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ElementsMap,
|
ElementsMap,
|
||||||
|
ExcalidrawArrowElement,
|
||||||
ExcalidrawBindableElement,
|
ExcalidrawBindableElement,
|
||||||
ExcalidrawDiamondElement,
|
ExcalidrawDiamondElement,
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
@@ -253,20 +254,25 @@ export const hitElementBoundText = (
|
|||||||
return isPointInElement(point, boundTextElement, elementsMap);
|
return isPointInElement(point, boundTextElement, elementsMap);
|
||||||
};
|
};
|
||||||
|
|
||||||
const bindableElementBorderDistanceIfClose = (
|
const bindingBorderTest = (
|
||||||
element: NonDeleted<ExcalidrawBindableElement>,
|
element: NonDeleted<ExcalidrawBindableElement>,
|
||||||
point: GlobalPoint,
|
[x, y]: Readonly<GlobalPoint>,
|
||||||
elementsMap: ElementsMap,
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
tolerance: number = 0,
|
tolerance: number = 0,
|
||||||
) => {
|
): boolean => {
|
||||||
|
const p = pointFrom<GlobalPoint>(x, y);
|
||||||
|
const shouldTestInside =
|
||||||
|
// disable fullshape snapping for frame elements so we
|
||||||
|
// can bind to frame children
|
||||||
|
!isFrameLikeElement(element);
|
||||||
|
|
||||||
// PERF: Run a cheap test to see if the binding element
|
// PERF: Run a cheap test to see if the binding element
|
||||||
// is even close to the element
|
// is even close to the element
|
||||||
const [x, y] = point;
|
|
||||||
const t = Math.max(1, tolerance);
|
const t = Math.max(1, tolerance);
|
||||||
const bounds = [x - t, y - t, x + t, y + t] as Bounds;
|
const bounds = [x - t, y - t, x + t, y + t] as Bounds;
|
||||||
const elementBounds = getElementBounds(element, elementsMap);
|
const elementBounds = getElementBounds(element, elementsMap);
|
||||||
if (!doBoundsIntersect(bounds, elementBounds)) {
|
if (!doBoundsIntersect(bounds, elementBounds)) {
|
||||||
return -Infinity;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the element is inside a frame, we should clip the element
|
// If the element is inside a frame, we should clip the element
|
||||||
@@ -277,29 +283,33 @@ const bindableElementBorderDistanceIfClose = (
|
|||||||
enclosingFrame,
|
enclosingFrame,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
);
|
);
|
||||||
if (!pointInsideBounds(point, enclosingFrameBounds)) {
|
if (!pointInsideBounds(p, enclosingFrameBounds)) {
|
||||||
return -Infinity;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const distance = distanceToElement(element, elementsMap, point);
|
// Do the intersection test against the element since it's close enough
|
||||||
if (isPointInElement(point, element, elementsMap)) {
|
const intersections = intersectElementWithLineSegment(
|
||||||
return distance;
|
element,
|
||||||
}
|
elementsMap,
|
||||||
|
lineSegment(elementCenterPoint(element, elementsMap), p),
|
||||||
|
);
|
||||||
|
const distance = distanceToElement(element, elementsMap, p);
|
||||||
|
|
||||||
return distance > tolerance ? -Infinity : -distance;
|
return shouldTestInside
|
||||||
|
? intersections.length === 0 || distance <= tolerance
|
||||||
|
: intersections.length > 0 && distance <= t;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAllHoveredElementAtPoint = (
|
export const getAllHoveredElementAtPoint = (
|
||||||
arrow: { elbowed: boolean },
|
|
||||||
point: Readonly<GlobalPoint>,
|
point: Readonly<GlobalPoint>,
|
||||||
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
tolerance?: number,
|
tolerance?: number,
|
||||||
): NonDeleted<ExcalidrawBindableElement>[] => {
|
): NonDeleted<ExcalidrawBindableElement>[] => {
|
||||||
const candidateElements: NonDeleted<ExcalidrawBindableElement>[] = [];
|
const candidateElements: NonDeleted<ExcalidrawBindableElement>[] = [];
|
||||||
// We need to do hit testing from front (end of the array) to back (beginning of the array)
|
// We need to to hit testing from front (end of the array) to back (beginning of the array)
|
||||||
// because array is ordered from lower z-index to highest and we want element z-index
|
// because array is ordered from lower z-index to highest and we want element z-index
|
||||||
// with higher z-index
|
// with higher z-index
|
||||||
for (let index = elements.length - 1; index >= 0; --index) {
|
for (let index = elements.length - 1; index >= 0; --index) {
|
||||||
@@ -312,13 +322,7 @@ export const getAllHoveredElementAtPoint = (
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
isBindableElement(element, false) &&
|
isBindableElement(element, false) &&
|
||||||
hitElementItself({
|
bindingBorderTest(element, point, elementsMap, tolerance)
|
||||||
element,
|
|
||||||
point,
|
|
||||||
elementsMap,
|
|
||||||
threshold: tolerance ?? getBindingGap(element),
|
|
||||||
overrideShouldTestInside: true,
|
|
||||||
})
|
|
||||||
) {
|
) {
|
||||||
candidateElements.push(element);
|
candidateElements.push(element);
|
||||||
|
|
||||||
@@ -335,92 +339,82 @@ export const getAllHoveredElementAtPoint = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getHoveredElementForBinding = (
|
export const getHoveredElementForBinding = (
|
||||||
arrow: { elbowed: boolean },
|
|
||||||
point: Readonly<GlobalPoint>,
|
point: Readonly<GlobalPoint>,
|
||||||
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
zoom?: AppState["zoom"],
|
tolerance?: number,
|
||||||
): NonDeleted<ExcalidrawBindableElement> | null => {
|
): NonDeleted<ExcalidrawBindableElement> | null => {
|
||||||
type Candidate = {
|
const candidateElements = getAllHoveredElementAtPoint(
|
||||||
element: NonDeleted<ExcalidrawBindableElement>;
|
point,
|
||||||
distance: number;
|
elements,
|
||||||
overlapPercent?: number;
|
elementsMap,
|
||||||
relativeArea?: number;
|
tolerance,
|
||||||
};
|
);
|
||||||
|
|
||||||
const candidates: Candidate[] = [];
|
if (!candidateElements || candidateElements.length === 0) {
|
||||||
for (let index = elements.length - 1; index >= 0; --index) {
|
|
||||||
const element = elements[index];
|
|
||||||
|
|
||||||
if (!isBindableElement(element, false)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const maxDistance = maxBindingDistance_simple(zoom);
|
|
||||||
const distance = bindableElementBorderDistanceIfClose(
|
|
||||||
element,
|
|
||||||
point,
|
|
||||||
elementsMap,
|
|
||||||
maxDistance,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (distance > -maxDistance) {
|
|
||||||
candidates.push({ element, distance });
|
|
||||||
|
|
||||||
if (!isTransparent(element.backgroundColor) && distance >= 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (candidates.length === 0) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (candidates.length === 1) {
|
if (candidateElements.length === 1) {
|
||||||
return candidates[0].element;
|
return candidateElements[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
const closestElements = candidates.sort(
|
// Prefer smaller shapes
|
||||||
(a, b) => Math.abs(a.distance) - Math.abs(b.distance),
|
return candidateElements
|
||||||
);
|
.sort(
|
||||||
|
(a, b) => b.width ** 2 + b.height ** 2 - (a.width ** 2 + a.height ** 2),
|
||||||
|
)
|
||||||
|
.pop() as NonDeleted<ExcalidrawBindableElement>;
|
||||||
|
};
|
||||||
|
|
||||||
const candidate = closestElements[0];
|
export const getHoveredElementForFocusPoint = (
|
||||||
const [cx1, cy1, cx2, cy2] = getElementBounds(candidate.element, elementsMap);
|
point: GlobalPoint,
|
||||||
const candidateArea = Math.max(
|
arrow: ExcalidrawArrowElement,
|
||||||
0.00001,
|
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
||||||
Math.abs(cx2 - cx1) * Math.abs(cy2 - cy1),
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
);
|
tolerance?: number,
|
||||||
const overlaps = closestElements
|
): ExcalidrawBindableElement | null => {
|
||||||
.map((c) => {
|
const candidateElements: NonDeleted<ExcalidrawBindableElement>[] = [];
|
||||||
if (c.element === candidate.element) {
|
// We need to to hit testing from front (end of the array) to back (beginning of the array)
|
||||||
return { ...c, overlapPercent: 0, relativeArea: 1 };
|
// because array is ordered from lower z-index to highest and we want element z-index
|
||||||
}
|
// with higher z-index
|
||||||
|
for (let index = elements.length - 1; index >= 0; --index) {
|
||||||
|
const element = elements[index];
|
||||||
|
|
||||||
const [x1, y1, x2, y2] = getElementBounds(c.element, elementsMap);
|
invariant(
|
||||||
const overlapX1 = x1 > cx1 && x1 < cx2 ? x1 : cx1;
|
!element.isDeleted,
|
||||||
const overlapY1 = y1 > cy1 && y1 < cy2 ? y1 : cy1;
|
"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements",
|
||||||
const overlapX2 = x2 < cx2 && x2 > cx1 ? x2 : cx2;
|
);
|
||||||
const overlapY2 = y2 < cy2 && y2 > cy1 ? y2 : cy2;
|
|
||||||
const overlapWdith =
|
|
||||||
overlapX1 !== cx1 || overlapX2 !== cx2 ? overlapX2 - overlapX1 : 0;
|
|
||||||
const overlapHeight =
|
|
||||||
overlapY1 !== cy1 || overlapY2 !== cy2 ? overlapY2 - overlapY1 : 0;
|
|
||||||
const area = Math.max(0.00001, Math.abs(x2 - x1) * Math.abs(y2 - y1));
|
|
||||||
const overlapPercent = Math.abs(overlapHeight * overlapWdith) / area;
|
|
||||||
|
|
||||||
return {
|
if (
|
||||||
...c,
|
isBindableElement(element, false) &&
|
||||||
overlapPercent,
|
bindingBorderTest(element, point, elementsMap, tolerance)
|
||||||
relativeArea:
|
) {
|
||||||
overlapPercent === 0 ? 1 : Math.min(area / candidateArea, 1),
|
candidateElements.push(element);
|
||||||
};
|
}
|
||||||
})
|
}
|
||||||
.filter((c) => c.overlapPercent > 0.25 && c.relativeArea < 0.75);
|
|
||||||
|
|
||||||
return candidate.distance >= 0 && overlaps.length > 0
|
if (!candidateElements || candidateElements.length === 0) {
|
||||||
? overlaps[0].element
|
return null;
|
||||||
: candidate.element;
|
}
|
||||||
|
|
||||||
|
if (candidateElements.length === 1) {
|
||||||
|
return candidateElements[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
const distanceFilteredCandidateElements = candidateElements
|
||||||
|
// Resolve by distance
|
||||||
|
.filter(
|
||||||
|
(el) =>
|
||||||
|
distanceToElement(el, elementsMap, point) <= getBindingGap(el, arrow) ||
|
||||||
|
isPointInElement(point, el, elementsMap),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (distanceFilteredCandidateElements.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return distanceFilteredCandidateElements[0] as NonDeleted<ExcalidrawBindableElement>;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import { getPerfectElementSize } from "./sizeHelpers";
|
|||||||
import { getBoundTextElement } from "./textElement";
|
import { getBoundTextElement } from "./textElement";
|
||||||
import { getMinTextElementWidth } from "./textMeasurements";
|
import { getMinTextElementWidth } from "./textMeasurements";
|
||||||
import {
|
import {
|
||||||
isArrowElement as isBindingElement,
|
isArrowElement,
|
||||||
isElbowArrow,
|
isElbowArrow,
|
||||||
isFrameLikeElement,
|
isFrameLikeElement,
|
||||||
isImageElement,
|
isImageElement,
|
||||||
@@ -108,7 +108,19 @@ export const dragSelectedElements = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
elementsToUpdate.forEach((element) => {
|
elementsToUpdate.forEach((element) => {
|
||||||
if (!isBindingElement(element)) {
|
const isArrow = !isArrowElement(element);
|
||||||
|
const isStartBoundElementSelected =
|
||||||
|
isArrow ||
|
||||||
|
(element.startBinding
|
||||||
|
? elementsToUpdateIds.has(element.startBinding.elementId)
|
||||||
|
: false);
|
||||||
|
const isEndBoundElementSelected =
|
||||||
|
isArrow ||
|
||||||
|
(element.endBinding
|
||||||
|
? elementsToUpdateIds.has(element.endBinding.elementId)
|
||||||
|
: false);
|
||||||
|
|
||||||
|
if (!isArrowElement(element)) {
|
||||||
updateElementCoords(pointerDownState, element, scene, adjustedOffset);
|
updateElementCoords(pointerDownState, element, scene, adjustedOffset);
|
||||||
|
|
||||||
// skip arrow labels since we calculate its position during render
|
// skip arrow labels since we calculate its position during render
|
||||||
@@ -131,6 +143,7 @@ export const dragSelectedElements = (
|
|||||||
// NOTE: Add a little initial drag to the arrow dragging when the arrow
|
// NOTE: Add a little initial drag to the arrow dragging when the arrow
|
||||||
// is the single element being dragged to avoid accidentally unbinding
|
// is the single element being dragged to avoid accidentally unbinding
|
||||||
// the arrow when the user just wants to select it.
|
// the arrow when the user just wants to select it.
|
||||||
|
|
||||||
elementsToUpdate.size > 1 ||
|
elementsToUpdate.size > 1 ||
|
||||||
Math.max(Math.abs(adjustedOffset.x), Math.abs(adjustedOffset.y)) >
|
Math.max(Math.abs(adjustedOffset.x), Math.abs(adjustedOffset.y)) >
|
||||||
DRAGGING_THRESHOLD ||
|
DRAGGING_THRESHOLD ||
|
||||||
@@ -138,12 +151,9 @@ export const dragSelectedElements = (
|
|||||||
) {
|
) {
|
||||||
updateElementCoords(pointerDownState, element, scene, adjustedOffset);
|
updateElementCoords(pointerDownState, element, scene, adjustedOffset);
|
||||||
|
|
||||||
const shouldUnbindStart = element.startBinding
|
const shouldUnbindStart =
|
||||||
? !elementsToUpdateIds.has(element.startBinding.elementId)
|
element.startBinding && !isStartBoundElementSelected;
|
||||||
: true;
|
const shouldUnbindEnd = element.endBinding && !isEndBoundElementSelected;
|
||||||
const shouldUnbindEnd = element.endBinding
|
|
||||||
? !elementsToUpdateIds.has(element.endBinding.elementId)
|
|
||||||
: true;
|
|
||||||
if (shouldUnbindStart || shouldUnbindEnd) {
|
if (shouldUnbindStart || shouldUnbindEnd) {
|
||||||
// NOTE: Moving the bound arrow should unbind it, otherwise we would
|
// NOTE: Moving the bound arrow should unbind it, otherwise we would
|
||||||
// have weird situations, like 0 lenght arrow when the user moves
|
// have weird situations, like 0 lenght arrow when the user moves
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ import {
|
|||||||
getHeadingForElbowArrowSnap,
|
getHeadingForElbowArrowSnap,
|
||||||
getGlobalFixedPointForBindableElement,
|
getGlobalFixedPointForBindableElement,
|
||||||
getBindingGap,
|
getBindingGap,
|
||||||
BASE_BINDING_GAP,
|
maxBindingDistance_simple,
|
||||||
|
BASE_BINDING_GAP_ELBOW,
|
||||||
} from "./binding";
|
} from "./binding";
|
||||||
import { distanceToElement } from "./distance";
|
import { distanceToElement } from "./distance";
|
||||||
import {
|
import {
|
||||||
@@ -317,7 +318,6 @@ const handleSegmentRelease = (
|
|||||||
...rest
|
...rest
|
||||||
} = getElbowArrowData(
|
} = getElbowArrowData(
|
||||||
{
|
{
|
||||||
...arrow,
|
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
startBinding,
|
startBinding,
|
||||||
@@ -1041,7 +1041,6 @@ export const updateElbowArrowPoints = (
|
|||||||
...rest
|
...rest
|
||||||
} = getElbowArrowData(
|
} = getElbowArrowData(
|
||||||
{
|
{
|
||||||
...arrow,
|
|
||||||
x: arrow.x,
|
x: arrow.x,
|
||||||
y: arrow.y,
|
y: arrow.y,
|
||||||
startBinding,
|
startBinding,
|
||||||
@@ -1191,7 +1190,15 @@ export const updateElbowArrowPoints = (
|
|||||||
* - hoveredEndElement: The element being hovered over at the end point.
|
* - hoveredEndElement: The element being hovered over at the end point.
|
||||||
*/
|
*/
|
||||||
const getElbowArrowData = (
|
const getElbowArrowData = (
|
||||||
arrow: ExcalidrawElbowArrowElement,
|
arrow: {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
startBinding: FixedPointBinding | null;
|
||||||
|
endBinding: FixedPointBinding | null;
|
||||||
|
startArrowhead: Arrowhead | null;
|
||||||
|
endArrowhead: Arrowhead | null;
|
||||||
|
points: readonly LocalPoint[];
|
||||||
|
},
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
nextPoints: readonly LocalPoint[],
|
nextPoints: readonly LocalPoint[],
|
||||||
options?: {
|
options?: {
|
||||||
@@ -1216,7 +1223,6 @@ const getElbowArrowData = (
|
|||||||
const elements = Array.from(elementsMap.values());
|
const elements = Array.from(elementsMap.values());
|
||||||
hoveredStartElement =
|
hoveredStartElement =
|
||||||
getHoveredElement(
|
getHoveredElement(
|
||||||
arrow,
|
|
||||||
origStartGlobalPoint,
|
origStartGlobalPoint,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
elements,
|
elements,
|
||||||
@@ -1224,7 +1230,6 @@ const getElbowArrowData = (
|
|||||||
) || null;
|
) || null;
|
||||||
hoveredEndElement =
|
hoveredEndElement =
|
||||||
getHoveredElement(
|
getHoveredElement(
|
||||||
arrow,
|
|
||||||
origEndGlobalPoint,
|
origEndGlobalPoint,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
elements,
|
elements,
|
||||||
@@ -1251,7 +1256,6 @@ const getElbowArrowData = (
|
|||||||
"start",
|
"start",
|
||||||
arrow.startBinding?.fixedPoint,
|
arrow.startBinding?.fixedPoint,
|
||||||
origStartGlobalPoint,
|
origStartGlobalPoint,
|
||||||
options?.zoom || ({ value: 1 } as AppState["zoom"]),
|
|
||||||
hoveredStartElement,
|
hoveredStartElement,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
options?.isDragging,
|
options?.isDragging,
|
||||||
@@ -1269,7 +1273,6 @@ const getElbowArrowData = (
|
|||||||
"end",
|
"end",
|
||||||
arrow.endBinding?.fixedPoint,
|
arrow.endBinding?.fixedPoint,
|
||||||
origEndGlobalPoint,
|
origEndGlobalPoint,
|
||||||
options?.zoom || ({ value: 1 } as AppState["zoom"]),
|
|
||||||
hoveredEndElement,
|
hoveredEndElement,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
options?.isDragging,
|
options?.isDragging,
|
||||||
@@ -1311,8 +1314,8 @@ const getElbowArrowData = (
|
|||||||
offsetFromHeading(
|
offsetFromHeading(
|
||||||
startHeading,
|
startHeading,
|
||||||
arrow.startArrowhead
|
arrow.startArrowhead
|
||||||
? getBindingGap(hoveredStartElement) * 6
|
? getBindingGap(hoveredStartElement, { elbowed: true }) * 6
|
||||||
: getBindingGap(hoveredStartElement) * 2,
|
: getBindingGap(hoveredStartElement, { elbowed: true }) * 2,
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -1324,8 +1327,8 @@ const getElbowArrowData = (
|
|||||||
offsetFromHeading(
|
offsetFromHeading(
|
||||||
endHeading,
|
endHeading,
|
||||||
arrow.endArrowhead
|
arrow.endArrowhead
|
||||||
? getBindingGap(hoveredEndElement) * 6
|
? getBindingGap(hoveredEndElement, { elbowed: true }) * 6
|
||||||
: getBindingGap(hoveredEndElement) * 2,
|
: getBindingGap(hoveredEndElement, { elbowed: true }) * 2,
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -1372,8 +1375,8 @@ const getElbowArrowData = (
|
|||||||
? 0
|
? 0
|
||||||
: BASE_PADDING -
|
: BASE_PADDING -
|
||||||
(arrow.startArrowhead
|
(arrow.startArrowhead
|
||||||
? BASE_BINDING_GAP * 6
|
? BASE_BINDING_GAP_ELBOW * 6
|
||||||
: BASE_BINDING_GAP * 2),
|
: BASE_BINDING_GAP_ELBOW * 2),
|
||||||
BASE_PADDING,
|
BASE_PADDING,
|
||||||
),
|
),
|
||||||
boundsOverlap
|
boundsOverlap
|
||||||
@@ -1388,8 +1391,8 @@ const getElbowArrowData = (
|
|||||||
? 0
|
? 0
|
||||||
: BASE_PADDING -
|
: BASE_PADDING -
|
||||||
(arrow.endArrowhead
|
(arrow.endArrowhead
|
||||||
? BASE_BINDING_GAP * 6
|
? BASE_BINDING_GAP_ELBOW * 6
|
||||||
: BASE_BINDING_GAP * 2),
|
: BASE_BINDING_GAP_ELBOW * 2),
|
||||||
BASE_PADDING,
|
BASE_PADDING,
|
||||||
),
|
),
|
||||||
boundsOverlap,
|
boundsOverlap,
|
||||||
@@ -2215,7 +2218,6 @@ const getGlobalPoint = (
|
|||||||
startOrEnd: "start" | "end",
|
startOrEnd: "start" | "end",
|
||||||
fixedPointRatio: [number, number] | undefined | null,
|
fixedPointRatio: [number, number] | undefined | null,
|
||||||
initialPoint: GlobalPoint,
|
initialPoint: GlobalPoint,
|
||||||
zoom: AppState["zoom"],
|
|
||||||
element?: ExcalidrawBindableElement | null,
|
element?: ExcalidrawBindableElement | null,
|
||||||
elementsMap?: ElementsMap,
|
elementsMap?: ElementsMap,
|
||||||
isDragging?: boolean,
|
isDragging?: boolean,
|
||||||
@@ -2229,7 +2231,6 @@ const getGlobalPoint = (
|
|||||||
element,
|
element,
|
||||||
startOrEnd,
|
startOrEnd,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
zoom,
|
|
||||||
undefined,
|
undefined,
|
||||||
isMidpointSnappingEnabled,
|
isMidpointSnappingEnabled,
|
||||||
);
|
);
|
||||||
@@ -2278,18 +2279,16 @@ const getBindPointHeading = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
const getHoveredElement = (
|
const getHoveredElement = (
|
||||||
arrow: ExcalidrawElbowArrowElement,
|
|
||||||
origPoint: GlobalPoint,
|
origPoint: GlobalPoint,
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
||||||
zoom?: AppState["zoom"],
|
zoom?: AppState["zoom"],
|
||||||
) => {
|
) => {
|
||||||
return getHoveredElementForBinding(
|
return getHoveredElementForBinding(
|
||||||
arrow,
|
|
||||||
origPoint,
|
origPoint,
|
||||||
elements,
|
elements,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
zoom,
|
maxBindingDistance_simple(zoom),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -452,16 +452,8 @@ const createBindingArrow = (
|
|||||||
"orbit",
|
"orbit",
|
||||||
"start",
|
"start",
|
||||||
scene,
|
scene,
|
||||||
appState.zoom,
|
|
||||||
);
|
|
||||||
bindBindingElement(
|
|
||||||
bindingArrow,
|
|
||||||
endBindingElement,
|
|
||||||
"orbit",
|
|
||||||
"end",
|
|
||||||
scene,
|
|
||||||
appState.zoom,
|
|
||||||
);
|
);
|
||||||
|
bindBindingElement(bindingArrow, endBindingElement, "orbit", "end", scene);
|
||||||
|
|
||||||
const changedElements = new Map<string, OrderedExcalidrawElement>();
|
const changedElements = new Map<string, OrderedExcalidrawElement>();
|
||||||
changedElements.set(
|
changedElements.set(
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import {
|
|||||||
calculateFixedPointForNonElbowArrowBinding,
|
calculateFixedPointForNonElbowArrowBinding,
|
||||||
getBindingStrategyForDraggingBindingElementEndpoints,
|
getBindingStrategyForDraggingBindingElementEndpoints,
|
||||||
isBindingEnabled,
|
isBindingEnabled,
|
||||||
|
snapToMid,
|
||||||
updateBoundPoint,
|
updateBoundPoint,
|
||||||
} from "./binding";
|
} from "./binding";
|
||||||
import {
|
import {
|
||||||
@@ -343,7 +344,7 @@ export class LinearElementEditor {
|
|||||||
|
|
||||||
// Apply the point movement if needed
|
// Apply the point movement if needed
|
||||||
let suggestedBinding: AppState["suggestedBinding"] = null;
|
let suggestedBinding: AppState["suggestedBinding"] = null;
|
||||||
const { positions, updates, hit } = pointDraggingUpdates(
|
const { positions, updates } = pointDraggingUpdates(
|
||||||
[idx],
|
[idx],
|
||||||
deltaX,
|
deltaX,
|
||||||
deltaY,
|
deltaY,
|
||||||
@@ -381,20 +382,17 @@ export class LinearElementEditor {
|
|||||||
|
|
||||||
// Move the arrow over the bindable object in terms of z-index
|
// Move the arrow over the bindable object in terms of z-index
|
||||||
if (isBindingElement(element)) {
|
if (isBindingElement(element)) {
|
||||||
if (hit) {
|
moveArrowAboveBindable(
|
||||||
moveArrowAboveBindable(
|
LinearElementEditor.getPointGlobalCoordinates(
|
||||||
LinearElementEditor.getPointGlobalCoordinates(
|
|
||||||
element,
|
|
||||||
element.points[element.points.length - 1],
|
|
||||||
elementsMap,
|
|
||||||
),
|
|
||||||
element,
|
element,
|
||||||
elements,
|
element.points[element.points.length - 1],
|
||||||
elementsMap,
|
elementsMap,
|
||||||
app.scene,
|
),
|
||||||
hit,
|
element,
|
||||||
);
|
elements,
|
||||||
}
|
elementsMap,
|
||||||
|
app.scene,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PERF: Avoid state updates if not absolutely necessary
|
// PERF: Avoid state updates if not absolutely necessary
|
||||||
@@ -541,7 +539,7 @@ export class LinearElementEditor {
|
|||||||
|
|
||||||
// Apply the point movement if needed
|
// Apply the point movement if needed
|
||||||
let suggestedBinding: AppState["suggestedBinding"] = null;
|
let suggestedBinding: AppState["suggestedBinding"] = null;
|
||||||
const { positions, updates, hit } = pointDraggingUpdates(
|
const { positions, updates } = pointDraggingUpdates(
|
||||||
selectedPointsIndices,
|
selectedPointsIndices,
|
||||||
deltaX,
|
deltaX,
|
||||||
deltaY,
|
deltaY,
|
||||||
@@ -580,22 +578,19 @@ export class LinearElementEditor {
|
|||||||
|
|
||||||
// Move the arrow over the bindable object in terms of z-index
|
// Move the arrow over the bindable object in terms of z-index
|
||||||
if (isBindingElement(element) && startIsSelected !== endIsSelected) {
|
if (isBindingElement(element) && startIsSelected !== endIsSelected) {
|
||||||
if (hit) {
|
moveArrowAboveBindable(
|
||||||
moveArrowAboveBindable(
|
LinearElementEditor.getPointGlobalCoordinates(
|
||||||
LinearElementEditor.getPointGlobalCoordinates(
|
|
||||||
element,
|
|
||||||
startIsSelected
|
|
||||||
? element.points[0]
|
|
||||||
: element.points[element.points.length - 1],
|
|
||||||
elementsMap,
|
|
||||||
),
|
|
||||||
element,
|
element,
|
||||||
elements,
|
startIsSelected
|
||||||
|
? element.points[0]
|
||||||
|
: element.points[element.points.length - 1],
|
||||||
elementsMap,
|
elementsMap,
|
||||||
app.scene,
|
),
|
||||||
hit,
|
element,
|
||||||
);
|
elements,
|
||||||
}
|
elementsMap,
|
||||||
|
app.scene,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attached text might need to update if arrow dimensions change
|
// Attached text might need to update if arrow dimensions change
|
||||||
@@ -2141,7 +2136,6 @@ const pointDraggingUpdates = (
|
|||||||
): {
|
): {
|
||||||
positions: PointsPositionUpdates;
|
positions: PointsPositionUpdates;
|
||||||
updates?: PointMoveOtherUpdates;
|
updates?: PointMoveOtherUpdates;
|
||||||
hit?: ExcalidrawBindableElement | null;
|
|
||||||
} => {
|
} => {
|
||||||
const naiveDraggingPoints = new Map(
|
const naiveDraggingPoints = new Map(
|
||||||
selectedPointsIndices.map((pointIndex) => {
|
selectedPointsIndices.map((pointIndex) => {
|
||||||
@@ -2199,15 +2193,13 @@ const pointDraggingUpdates = (
|
|||||||
? {
|
? {
|
||||||
element: suggestedBindingElement,
|
element: suggestedBindingElement,
|
||||||
midPoint: app.state.isMidpointSnappingEnabled
|
midPoint: app.state.isMidpointSnappingEnabled
|
||||||
? getSnapOutlineMidPoint(
|
? snapToMid(
|
||||||
|
suggestedBindingElement,
|
||||||
|
elementsMap,
|
||||||
pointFrom<GlobalPoint>(
|
pointFrom<GlobalPoint>(
|
||||||
scenePointerX - linearElementEditor.pointerOffset.x,
|
scenePointerX - linearElementEditor.pointerOffset.x,
|
||||||
scenePointerY - linearElementEditor.pointerOffset.y,
|
scenePointerY - linearElementEditor.pointerOffset.y,
|
||||||
),
|
),
|
||||||
suggestedBindingElement,
|
|
||||||
elementsMap,
|
|
||||||
app.state.zoom,
|
|
||||||
element,
|
|
||||||
)
|
)
|
||||||
: undefined,
|
: undefined,
|
||||||
}
|
}
|
||||||
@@ -2314,7 +2306,6 @@ const pointDraggingUpdates = (
|
|||||||
start.element,
|
start.element,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
app.state.zoom,
|
app.state.zoom,
|
||||||
element,
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
@@ -2354,7 +2345,6 @@ const pointDraggingUpdates = (
|
|||||||
end.element,
|
end.element,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
app.state.zoom,
|
app.state.zoom,
|
||||||
element,
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
@@ -2507,7 +2497,6 @@ const pointDraggingUpdates = (
|
|||||||
];
|
];
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
hit: startIsDragged ? start.element : end.element,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import rough from "roughjs/bin/rough";
|
import rough from "roughjs/bin/rough";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
clamp,
|
||||||
type GlobalPoint,
|
type GlobalPoint,
|
||||||
isRightAngleRads,
|
isRightAngleRads,
|
||||||
lineSegment,
|
lineSegment,
|
||||||
@@ -105,8 +106,62 @@ const getCanvasPadding = (element: ExcalidrawElement) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const resolveRenderOpacity = (
|
||||||
|
element: ExcalidrawElement,
|
||||||
|
renderConfig: Pick<
|
||||||
|
StaticCanvasRenderConfig,
|
||||||
|
"elementOpacityOverrides" | "resolveRenderOpacity"
|
||||||
|
>,
|
||||||
|
) => {
|
||||||
|
const override = renderConfig.elementOpacityOverrides?.get(element.id);
|
||||||
|
|
||||||
|
if (override !== undefined) {
|
||||||
|
return clamp(override, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolvedOpacity = renderConfig.resolveRenderOpacity?.(
|
||||||
|
element as NonDeletedExcalidrawElement,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (resolvedOpacity !== undefined) {
|
||||||
|
return clamp(resolvedOpacity, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
return element.opacity;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const resolveRenderPositionOffset = (
|
||||||
|
element: ExcalidrawElement,
|
||||||
|
renderConfig: Pick<StaticCanvasRenderConfig, "elementPositionOverrides">,
|
||||||
|
) => {
|
||||||
|
return renderConfig.elementPositionOverrides?.get(element.id) ?? { x: 0, y: 0 };
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getRenderElementWithPositionOverride = <
|
||||||
|
TElement extends NonDeletedExcalidrawElement,
|
||||||
|
>(
|
||||||
|
element: TElement,
|
||||||
|
renderConfig: Pick<StaticCanvasRenderConfig, "elementPositionOverrides">,
|
||||||
|
): TElement => {
|
||||||
|
const positionOffset = resolveRenderPositionOffset(element, renderConfig);
|
||||||
|
|
||||||
|
if (positionOffset.x === 0 && positionOffset.y === 0) {
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...element,
|
||||||
|
x: element.x + positionOffset.x,
|
||||||
|
y: element.y + positionOffset.y,
|
||||||
|
} as TElement;
|
||||||
|
};
|
||||||
|
|
||||||
export const getRenderOpacity = (
|
export const getRenderOpacity = (
|
||||||
element: ExcalidrawElement,
|
element: ExcalidrawElement,
|
||||||
|
renderConfig: Pick<
|
||||||
|
StaticCanvasRenderConfig,
|
||||||
|
"elementOpacityOverrides" | "resolveRenderOpacity"
|
||||||
|
>,
|
||||||
containingFrame: ExcalidrawFrameLikeElement | null,
|
containingFrame: ExcalidrawFrameLikeElement | null,
|
||||||
elementsPendingErasure: ElementsPendingErasure,
|
elementsPendingErasure: ElementsPendingErasure,
|
||||||
pendingNodes: Readonly<PendingExcalidrawElements> | null,
|
pendingNodes: Readonly<PendingExcalidrawElements> | null,
|
||||||
@@ -115,7 +170,8 @@ export const getRenderOpacity = (
|
|||||||
// multiplying frame opacity with element opacity to combine them
|
// multiplying frame opacity with element opacity to combine them
|
||||||
// (e.g. frame 50% and element 50% opacity should result in 25% opacity)
|
// (e.g. frame 50% and element 50% opacity should result in 25% opacity)
|
||||||
let opacity =
|
let opacity =
|
||||||
(((containingFrame?.opacity ?? 100) * element.opacity) / 10000) *
|
(((containingFrame?.opacity ?? 100) * resolveRenderOpacity(element, renderConfig)) /
|
||||||
|
10000) *
|
||||||
globalAlpha;
|
globalAlpha;
|
||||||
|
|
||||||
// if pending erasure, multiply again to combine further
|
// if pending erasure, multiply again to combine further
|
||||||
@@ -791,8 +847,11 @@ export const renderElement = (
|
|||||||
!appState.selectedElementIds[element.id] &&
|
!appState.selectedElementIds[element.id] &&
|
||||||
!appState.hoveredElementIds[element.id];
|
!appState.hoveredElementIds[element.id];
|
||||||
|
|
||||||
|
element = getRenderElementWithPositionOverride(element, renderConfig);
|
||||||
|
|
||||||
context.globalAlpha = getRenderOpacity(
|
context.globalAlpha = getRenderOpacity(
|
||||||
element,
|
element,
|
||||||
|
renderConfig,
|
||||||
getContainingFrame(element, elementsMap),
|
getContainingFrame(element, elementsMap),
|
||||||
renderConfig.elementsPendingErasure,
|
renderConfig.elementsPendingErasure,
|
||||||
renderConfig.pendingFlowchartNodes,
|
renderConfig.pendingFlowchartNodes,
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import {
|
|||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import type { MarkOptional } from "@excalidraw/common/utility-types";
|
import type { MarkOptional } from "@excalidraw/common/utility-types";
|
||||||
import type { Zoom } from "@excalidraw/excalidraw/types";
|
|
||||||
|
|
||||||
import { bindBindingElement } from "./binding";
|
import { bindBindingElement } from "./binding";
|
||||||
import {
|
import {
|
||||||
@@ -249,7 +248,6 @@ const bindLinearElementToElement = (
|
|||||||
end: ValidLinearElement["end"],
|
end: ValidLinearElement["end"],
|
||||||
elementStore: ElementStore,
|
elementStore: ElementStore,
|
||||||
scene: Scene,
|
scene: Scene,
|
||||||
zoom: Zoom,
|
|
||||||
): {
|
): {
|
||||||
linearElement: ExcalidrawLinearElement;
|
linearElement: ExcalidrawLinearElement;
|
||||||
startBoundElement?: ExcalidrawElement;
|
startBoundElement?: ExcalidrawElement;
|
||||||
@@ -337,7 +335,6 @@ const bindLinearElementToElement = (
|
|||||||
"orbit",
|
"orbit",
|
||||||
"start",
|
"start",
|
||||||
scene,
|
scene,
|
||||||
zoom,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -414,7 +411,6 @@ const bindLinearElementToElement = (
|
|||||||
"orbit",
|
"orbit",
|
||||||
"end",
|
"end",
|
||||||
scene,
|
scene,
|
||||||
zoom,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -700,7 +696,6 @@ export const convertToExcalidrawElements = (
|
|||||||
originalEnd,
|
originalEnd,
|
||||||
elementStore,
|
elementStore,
|
||||||
scene,
|
scene,
|
||||||
{ value: 1 } as Zoom,
|
|
||||||
);
|
);
|
||||||
container = linearElement;
|
container = linearElement;
|
||||||
elementStore.add(linearElement);
|
elementStore.add(linearElement);
|
||||||
@@ -726,7 +721,6 @@ export const convertToExcalidrawElements = (
|
|||||||
end,
|
end,
|
||||||
elementStore,
|
elementStore,
|
||||||
scene,
|
scene,
|
||||||
{ value: 1 } as Zoom,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
elementStore.add(linearElement);
|
elementStore.add(linearElement);
|
||||||
|
|||||||
+53
-178
@@ -8,7 +8,6 @@ import {
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
bezierEquation,
|
bezierEquation,
|
||||||
clamp,
|
|
||||||
curve,
|
curve,
|
||||||
curveCatmullRomCubicApproxPoints,
|
curveCatmullRomCubicApproxPoints,
|
||||||
curveOffsetPoints,
|
curveOffsetPoints,
|
||||||
@@ -27,7 +26,7 @@ import {
|
|||||||
type GlobalPoint,
|
type GlobalPoint,
|
||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
import type { Curve, LineSegment, LocalPoint, Radians } from "@excalidraw/math";
|
import type { Curve, LineSegment, LocalPoint } from "@excalidraw/math";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
AppState,
|
AppState,
|
||||||
@@ -42,7 +41,7 @@ import { generateLinearCollisionShape } from "./shape";
|
|||||||
import { hitElementItself, isPointInElement } from "./collision";
|
import { hitElementItself, isPointInElement } from "./collision";
|
||||||
import { LinearElementEditor } from "./linearElementEditor";
|
import { LinearElementEditor } from "./linearElementEditor";
|
||||||
import { isRectangularElement } from "./typeChecks";
|
import { isRectangularElement } from "./typeChecks";
|
||||||
import { getBindingGap, maxBindingDistance_simple } from "./binding";
|
import { maxBindingDistance_simple } from "./binding";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getGlobalFixedPointForBindableElement,
|
getGlobalFixedPointForBindableElement,
|
||||||
@@ -588,193 +587,67 @@ const getDiagonalsForBindableElement = (
|
|||||||
return [diagonalOne, diagonalTwo];
|
return [diagonalOne, diagonalTwo];
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSnappedMidpointIndexForElbowArrow = (
|
export const getSnapOutlineMidPoint = (
|
||||||
element: ExcalidrawBindableElement,
|
|
||||||
point: GlobalPoint,
|
point: GlobalPoint,
|
||||||
center: GlobalPoint,
|
|
||||||
horizontalThreshold: number,
|
|
||||||
verticalThreshold: number,
|
|
||||||
) => {
|
|
||||||
const { x, y, width, height, angle } = element;
|
|
||||||
const nonRotated = pointRotateRads(point, center, -angle as Radians);
|
|
||||||
|
|
||||||
const bindingGap = getBindingGap(element);
|
|
||||||
|
|
||||||
if (pointDistance(center, nonRotated) < bindingGap) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
nonRotated[0] <= x + width / 2 &&
|
|
||||||
nonRotated[1] > center[1] - verticalThreshold &&
|
|
||||||
nonRotated[1] < center[1] + verticalThreshold
|
|
||||||
) {
|
|
||||||
return 2;
|
|
||||||
} else if (
|
|
||||||
nonRotated[1] <= y + height / 2 &&
|
|
||||||
nonRotated[0] > center[0] - horizontalThreshold &&
|
|
||||||
nonRotated[0] < center[0] + horizontalThreshold
|
|
||||||
) {
|
|
||||||
return 3;
|
|
||||||
} else if (
|
|
||||||
nonRotated[0] >= x + width / 2 &&
|
|
||||||
nonRotated[1] > center[1] - verticalThreshold &&
|
|
||||||
nonRotated[1] < center[1] + verticalThreshold
|
|
||||||
) {
|
|
||||||
return 0;
|
|
||||||
} else if (
|
|
||||||
nonRotated[1] >= y + height / 2 &&
|
|
||||||
nonRotated[0] > center[0] - horizontalThreshold &&
|
|
||||||
nonRotated[0] < center[0] + horizontalThreshold
|
|
||||||
) {
|
|
||||||
return 1;
|
|
||||||
} else if (element.type === "diamond") {
|
|
||||||
const distance = bindingGap;
|
|
||||||
const topLeft = pointFrom<GlobalPoint>(
|
|
||||||
x + width / 4 - distance,
|
|
||||||
y + height / 4 - distance,
|
|
||||||
);
|
|
||||||
const topRight = pointFrom<GlobalPoint>(
|
|
||||||
x + (3 * width) / 4 + distance,
|
|
||||||
y + height / 4 - distance,
|
|
||||||
);
|
|
||||||
const bottomLeft = pointFrom<GlobalPoint>(
|
|
||||||
x + width / 4 - distance,
|
|
||||||
y + (3 * height) / 4 + distance,
|
|
||||||
);
|
|
||||||
const bottomRight = pointFrom<GlobalPoint>(
|
|
||||||
x + (3 * width) / 4 + distance,
|
|
||||||
y + (3 * height) / 4 + distance,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
|
||||||
pointDistance(bottomLeft, nonRotated) <
|
|
||||||
Math.max(horizontalThreshold, verticalThreshold)
|
|
||||||
) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
pointDistance(bottomRight, nonRotated) <
|
|
||||||
Math.max(horizontalThreshold, verticalThreshold)
|
|
||||||
) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
pointDistance(topLeft, nonRotated) <
|
|
||||||
Math.max(horizontalThreshold, verticalThreshold)
|
|
||||||
) {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
pointDistance(topRight, nonRotated) <
|
|
||||||
Math.max(horizontalThreshold, verticalThreshold)
|
|
||||||
) {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getSnappedMidpointIndexForSimpleArrow = (
|
|
||||||
element: ExcalidrawBindableElement,
|
element: ExcalidrawBindableElement,
|
||||||
point: GlobalPoint,
|
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
horizontalThreshold: number,
|
zoom: AppState["zoom"],
|
||||||
verticalThreshold: number,
|
|
||||||
) => {
|
) => {
|
||||||
const baseMidpoints = getAllMidpoints(element, elementsMap);
|
const center = elementCenterPoint(element, elementsMap);
|
||||||
|
const sideMidpoints =
|
||||||
|
element.type === "diamond"
|
||||||
|
? getDiamondBaseCorners(element).map((curve) => {
|
||||||
|
const point = bezierEquation(curve, 0.5);
|
||||||
|
const rotatedPoint = pointRotateRads(point, center, element.angle);
|
||||||
|
|
||||||
for (let i = 0; i < baseMidpoints.length; i++) {
|
return pointFrom<GlobalPoint>(rotatedPoint[0], rotatedPoint[1]);
|
||||||
const threshold = i % 2 === 0 ? horizontalThreshold : verticalThreshold;
|
})
|
||||||
|
: [
|
||||||
if (
|
// RIGHT midpoint
|
||||||
pointDistance(baseMidpoints[i], point) <= threshold &&
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(
|
||||||
|
element.x + element.width,
|
||||||
|
element.y + element.height / 2,
|
||||||
|
),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
// BOTTOM midpoint
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(
|
||||||
|
element.x + element.width / 2,
|
||||||
|
element.y + element.height,
|
||||||
|
),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
// LEFT midpoint
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(element.x, element.y + element.height / 2),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
// TOP midpoint
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(element.x + element.width / 2, element.y),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
const candidate = sideMidpoints.find(
|
||||||
|
(midpoint) =>
|
||||||
|
pointDistance(point, midpoint) <=
|
||||||
|
maxBindingDistance_simple(zoom) + element.strokeWidth / 2 &&
|
||||||
!hitElementItself({
|
!hitElementItself({
|
||||||
point,
|
point,
|
||||||
element,
|
element,
|
||||||
threshold: 0,
|
threshold: 0,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
overrideShouldTestInside: true,
|
overrideShouldTestInside: true,
|
||||||
})
|
}),
|
||||||
) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getAllMidpoints = (
|
|
||||||
element: ExcalidrawBindableElement,
|
|
||||||
elementsMap: ElementsMap,
|
|
||||||
): GlobalPoint[] => {
|
|
||||||
const center = elementCenterPoint(element, elementsMap);
|
|
||||||
|
|
||||||
if (element.type === "diamond") {
|
|
||||||
return getDiamondBaseCorners(element).map((curve) =>
|
|
||||||
pointRotateRads(bezierEquation(curve, 0.5), center, element.angle),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
pointFrom(element.width, element.height / 2),
|
|
||||||
pointFrom(element.width / 2, element.height),
|
|
||||||
pointFrom(0, element.height / 2),
|
|
||||||
pointFrom(element.width / 2, 0),
|
|
||||||
].map(([x, y]) =>
|
|
||||||
pointRotateRads(
|
|
||||||
pointFrom<GlobalPoint>(element.x + x, element.y + y),
|
|
||||||
center,
|
|
||||||
element.angle,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
export const getSnapOutlineMidPoint = (
|
return candidate;
|
||||||
point: GlobalPoint,
|
|
||||||
element: ExcalidrawBindableElement,
|
|
||||||
elementsMap: ElementsMap,
|
|
||||||
zoom: AppState["zoom"],
|
|
||||||
arrow: { elbowed: boolean },
|
|
||||||
): GlobalPoint | undefined => {
|
|
||||||
const center = elementCenterPoint(element, elementsMap);
|
|
||||||
const baseMidpoints = getAllMidpoints(element, elementsMap);
|
|
||||||
const sideMidpoints =
|
|
||||||
element.type === "diamond"
|
|
||||||
? baseMidpoints.map((midpoint) => {
|
|
||||||
return pointFrom<GlobalPoint>(
|
|
||||||
midpoint[0] + (midpoint[0] - center[0]) * 0.1,
|
|
||||||
midpoint[1] + (midpoint[1] - center[1]) * 0.1,
|
|
||||||
);
|
|
||||||
})
|
|
||||||
: baseMidpoints;
|
|
||||||
|
|
||||||
const TOLERANCE = 0.05;
|
|
||||||
const maxDistance = maxBindingDistance_simple(zoom) + element.strokeWidth / 2;
|
|
||||||
const verticalThreshold = clamp(TOLERANCE * element.height, 5, maxDistance);
|
|
||||||
const horizontalThreshold = clamp(TOLERANCE * element.width, 5, maxDistance);
|
|
||||||
const idx = arrow.elbowed
|
|
||||||
? getSnappedMidpointIndexForElbowArrow(
|
|
||||||
element,
|
|
||||||
point,
|
|
||||||
center,
|
|
||||||
horizontalThreshold,
|
|
||||||
verticalThreshold,
|
|
||||||
)
|
|
||||||
: getSnappedMidpointIndexForSimpleArrow(
|
|
||||||
element,
|
|
||||||
point,
|
|
||||||
elementsMap,
|
|
||||||
horizontalThreshold,
|
|
||||||
verticalThreshold,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (idx === -1) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sideMidpoints[idx];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const projectFixedPointOntoDiagonal = (
|
export const projectFixedPointOntoDiagonal = (
|
||||||
@@ -787,6 +660,9 @@ export const projectFixedPointOntoDiagonal = (
|
|||||||
isMidpointSnappingEnabled: boolean = true,
|
isMidpointSnappingEnabled: boolean = true,
|
||||||
): GlobalPoint | null => {
|
): GlobalPoint | null => {
|
||||||
invariant(arrow.points.length >= 2, "Arrow must have at least two points");
|
invariant(arrow.points.length >= 2, "Arrow must have at least two points");
|
||||||
|
if (arrow.width < 3 && arrow.height < 3) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (isMidpointSnappingEnabled) {
|
if (isMidpointSnappingEnabled) {
|
||||||
const sideMidPoint = getSnapOutlineMidPoint(
|
const sideMidPoint = getSnapOutlineMidPoint(
|
||||||
@@ -794,7 +670,6 @@ export const projectFixedPointOntoDiagonal = (
|
|||||||
element,
|
element,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
zoom,
|
zoom,
|
||||||
arrow,
|
|
||||||
);
|
);
|
||||||
if (sideMidPoint) {
|
if (sideMidPoint) {
|
||||||
return sideMidPoint;
|
return sideMidPoint;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { getElementsInGroup } from "./groups";
|
|||||||
import { syncMovedIndices } from "./fractionalIndex";
|
import { syncMovedIndices } from "./fractionalIndex";
|
||||||
import { getSelectedElements } from "./selection";
|
import { getSelectedElements } from "./selection";
|
||||||
import { getBoundTextElement, getContainerElement } from "./textElement";
|
import { getBoundTextElement, getContainerElement } from "./textElement";
|
||||||
|
import { getHoveredElementForBinding } from "./collision";
|
||||||
|
|
||||||
import type { Scene } from "./Scene";
|
import type { Scene } from "./Scene";
|
||||||
import type {
|
import type {
|
||||||
@@ -155,8 +156,12 @@ export const moveArrowAboveBindable = (
|
|||||||
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
elements: readonly Ordered<NonDeletedExcalidrawElement>[],
|
||||||
elementsMap: NonDeletedSceneElementsMap,
|
elementsMap: NonDeletedSceneElementsMap,
|
||||||
scene: Scene,
|
scene: Scene,
|
||||||
hoveredElement: NonDeletedExcalidrawElement,
|
hit?: NonDeletedExcalidrawElement,
|
||||||
): readonly OrderedExcalidrawElement[] => {
|
): readonly OrderedExcalidrawElement[] => {
|
||||||
|
const hoveredElement = hit
|
||||||
|
? hit
|
||||||
|
: getHoveredElementForBinding(point, elements, elementsMap);
|
||||||
|
|
||||||
if (!hoveredElement) {
|
if (!hoveredElement) {
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import "@excalidraw/utils/test-utils";
|
|||||||
import { bindBindingElement } from "@excalidraw/element";
|
import { bindBindingElement } from "@excalidraw/element";
|
||||||
|
|
||||||
import type { LocalPoint } from "@excalidraw/math";
|
import type { LocalPoint } from "@excalidraw/math";
|
||||||
import type { Zoom } from "@excalidraw/excalidraw/types";
|
|
||||||
|
|
||||||
import { Scene } from "../src/Scene";
|
import { Scene } from "../src/Scene";
|
||||||
|
|
||||||
@@ -188,12 +187,8 @@ describe("elbow arrow routing", () => {
|
|||||||
}) as ExcalidrawElbowArrowElement;
|
}) as ExcalidrawElbowArrowElement;
|
||||||
API.setElements([rectangle1, rectangle2, arrow]);
|
API.setElements([rectangle1, rectangle2, arrow]);
|
||||||
|
|
||||||
bindBindingElement(arrow, rectangle1, "orbit", "start", h.scene, {
|
bindBindingElement(arrow, rectangle1, "orbit", "start", h.scene);
|
||||||
value: 1,
|
bindBindingElement(arrow, rectangle2, "orbit", "end", h.scene);
|
||||||
} as Zoom);
|
|
||||||
bindBindingElement(arrow, rectangle2, "orbit", "end", h.scene, {
|
|
||||||
value: 1,
|
|
||||||
} as Zoom);
|
|
||||||
|
|
||||||
expect(arrow.startBinding).not.toBe(null);
|
expect(arrow.startBinding).not.toBe(null);
|
||||||
expect(arrow.endBinding).not.toBe(null);
|
expect(arrow.endBinding).not.toBe(null);
|
||||||
|
|||||||
@@ -1897,7 +1897,6 @@ export const actionChangeArrowType = register<keyof typeof ARROW_TYPE>({
|
|||||||
startElement,
|
startElement,
|
||||||
"start",
|
"start",
|
||||||
elementsMap,
|
elementsMap,
|
||||||
appState.zoom,
|
|
||||||
appState.isBindingEnabled,
|
appState.isBindingEnabled,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
@@ -1912,7 +1911,6 @@ export const actionChangeArrowType = register<keyof typeof ARROW_TYPE>({
|
|||||||
endElement,
|
endElement,
|
||||||
"end",
|
"end",
|
||||||
elementsMap,
|
elementsMap,
|
||||||
appState.zoom,
|
|
||||||
appState.isBindingEnabled,
|
appState.isBindingEnabled,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
@@ -1945,7 +1943,6 @@ export const actionChangeArrowType = register<keyof typeof ARROW_TYPE>({
|
|||||||
appState.bindMode === "inside" ? "inside" : "orbit",
|
appState.bindMode === "inside" ? "inside" : "orbit",
|
||||||
"start",
|
"start",
|
||||||
app.scene,
|
app.scene,
|
||||||
appState.zoom,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1960,7 +1957,6 @@ export const actionChangeArrowType = register<keyof typeof ARROW_TYPE>({
|
|||||||
appState.bindMode === "inside" ? "inside" : "orbit",
|
appState.bindMode === "inside" ? "inside" : "orbit",
|
||||||
"end",
|
"end",
|
||||||
app.scene,
|
app.scene,
|
||||||
appState.zoom,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,10 +207,12 @@ import {
|
|||||||
getLineHeightInPx,
|
getLineHeightInPx,
|
||||||
getApproxMinLineWidth,
|
getApproxMinLineWidth,
|
||||||
getApproxMinLineHeight,
|
getApproxMinLineHeight,
|
||||||
getMinTextElementWidth,
|
getMinTextElementWidth,
|
||||||
ShapeCache,
|
ShapeCache,
|
||||||
getRenderOpacity,
|
getRenderOpacity,
|
||||||
editGroupForSelectedElement,
|
resolveRenderPositionOffset,
|
||||||
|
resolveRenderOpacity,
|
||||||
|
editGroupForSelectedElement,
|
||||||
getElementsInGroup,
|
getElementsInGroup,
|
||||||
getSelectedGroupIdForElement,
|
getSelectedGroupIdForElement,
|
||||||
getSelectedGroupIds,
|
getSelectedGroupIds,
|
||||||
@@ -248,6 +250,7 @@ import {
|
|||||||
getElementBounds,
|
getElementBounds,
|
||||||
doBoundsIntersect,
|
doBoundsIntersect,
|
||||||
isPointInElement,
|
isPointInElement,
|
||||||
|
maxBindingDistance_simple,
|
||||||
convertToExcalidrawElements,
|
convertToExcalidrawElements,
|
||||||
type ExcalidrawElementSkeleton,
|
type ExcalidrawElementSkeleton,
|
||||||
getSnapOutlineMidPoint,
|
getSnapOutlineMidPoint,
|
||||||
@@ -449,6 +452,7 @@ import { searchItemInFocusAtom } from "./SearchMenu";
|
|||||||
import { isSidebarDockedAtom } from "./Sidebar/Sidebar";
|
import { isSidebarDockedAtom } from "./Sidebar/Sidebar";
|
||||||
import { StaticCanvas, InteractiveCanvas } from "./canvases";
|
import { StaticCanvas, InteractiveCanvas } from "./canvases";
|
||||||
import NewElementCanvas from "./canvases/NewElementCanvas";
|
import NewElementCanvas from "./canvases/NewElementCanvas";
|
||||||
|
import { AnimationController } from "../renderer/animation";
|
||||||
import { isPointHittingLink } from "./hyperlink/helpers";
|
import { isPointHittingLink } from "./hyperlink/helpers";
|
||||||
import { MagicIcon, copyIcon, fullscreenIcon } from "./icons";
|
import { MagicIcon, copyIcon, fullscreenIcon } from "./icons";
|
||||||
import { AppStateObserver, type OnStateChange } from "./AppStateObserver";
|
import { AppStateObserver, type OnStateChange } from "./AppStateObserver";
|
||||||
@@ -739,6 +743,235 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
onRemoveEventListenersEmitter = new Emitter<[]>();
|
onRemoveEventListenersEmitter = new Emitter<[]>();
|
||||||
|
|
||||||
api: ExcalidrawImperativeAPI;
|
api: ExcalidrawImperativeAPI;
|
||||||
|
private renderAnimationVersion = 0;
|
||||||
|
private elementOpacityOverrides = new Map<string, number>();
|
||||||
|
private elementPositionOverrides = new Map<string, { x: number; y: number }>();
|
||||||
|
private elementAnimationStates = new Map<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
opacityFrom: number;
|
||||||
|
opacityTo: number;
|
||||||
|
positionFrom: { x: number; y: number };
|
||||||
|
positionTo: { x: number; y: number };
|
||||||
|
easing: "linear" | "easeOut" | "easeInOut";
|
||||||
|
duration: number;
|
||||||
|
delay: number;
|
||||||
|
elapsed: number;
|
||||||
|
}
|
||||||
|
>();
|
||||||
|
|
||||||
|
private getElementAnimationKey = () => `${this.id}:animate-element`;
|
||||||
|
|
||||||
|
private bumpRenderAnimationVersion = () => {
|
||||||
|
this.renderAnimationVersion++;
|
||||||
|
this.setState({});
|
||||||
|
};
|
||||||
|
|
||||||
|
private getRenderOpacityConfig = () => ({
|
||||||
|
elementOpacityOverrides: this.elementOpacityOverrides,
|
||||||
|
elementPositionOverrides: this.elementPositionOverrides,
|
||||||
|
resolveRenderOpacity: this.props.resolveRenderOpacity,
|
||||||
|
});
|
||||||
|
|
||||||
|
private getResolvedElementOpacity = (element: NonDeletedExcalidrawElement) => {
|
||||||
|
return resolveRenderOpacity(element, this.getRenderOpacityConfig());
|
||||||
|
};
|
||||||
|
|
||||||
|
private getElementVisibleOpacity = (element: NonDeletedExcalidrawElement) => {
|
||||||
|
return clamp(element.opacity, 0, 100);
|
||||||
|
};
|
||||||
|
|
||||||
|
private applyAnimationEasing = (
|
||||||
|
progress: number,
|
||||||
|
easing: "linear" | "easeOut" | "easeInOut",
|
||||||
|
) => {
|
||||||
|
switch (easing) {
|
||||||
|
case "linear":
|
||||||
|
return progress;
|
||||||
|
case "easeOut":
|
||||||
|
return easeOut(progress);
|
||||||
|
case "easeInOut":
|
||||||
|
return progress < 0.5
|
||||||
|
? 4 * progress * progress * progress
|
||||||
|
: 1 - Math.pow(-2 * progress + 2, 3) / 2;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private getFlyPositionOffset = (
|
||||||
|
element: NonDeletedExcalidrawElement,
|
||||||
|
from: "left" | "right" | "top" | "bottom",
|
||||||
|
) => {
|
||||||
|
const [x1, y1, x2, y2] = getElementAbsoluteCoords(
|
||||||
|
element,
|
||||||
|
this.scene.getNonDeletedElementsMap(),
|
||||||
|
);
|
||||||
|
const viewportWidth = this.state.width / this.state.zoom.value;
|
||||||
|
const viewportHeight = this.state.height / this.state.zoom.value;
|
||||||
|
const elementWidth = x2 - x1;
|
||||||
|
const elementHeight = y2 - y1;
|
||||||
|
|
||||||
|
switch (from) {
|
||||||
|
case "left":
|
||||||
|
return { x: -(Math.max(viewportWidth, elementWidth) + 64), y: 0 };
|
||||||
|
case "right":
|
||||||
|
return { x: Math.max(viewportWidth, elementWidth) + 64, y: 0 };
|
||||||
|
case "top":
|
||||||
|
return { x: 0, y: -(Math.max(viewportHeight, elementHeight) + 64) };
|
||||||
|
case "bottom":
|
||||||
|
return { x: 0, y: Math.max(viewportHeight, elementHeight) + 64 };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private animateElement = ({
|
||||||
|
id,
|
||||||
|
opacityFrom,
|
||||||
|
opacityTo,
|
||||||
|
positionFrom = { x: 0, y: 0 },
|
||||||
|
positionTo = { x: 0, y: 0 },
|
||||||
|
easing,
|
||||||
|
duration,
|
||||||
|
delay,
|
||||||
|
}: {
|
||||||
|
id: string;
|
||||||
|
opacityFrom: number;
|
||||||
|
opacityTo: number;
|
||||||
|
positionFrom?: { x: number; y: number };
|
||||||
|
positionTo?: { x: number; y: number };
|
||||||
|
easing: "linear" | "easeOut" | "easeInOut";
|
||||||
|
duration: number;
|
||||||
|
delay: number;
|
||||||
|
}) => {
|
||||||
|
const normalizedOpacityFrom = clamp(opacityFrom, 0, 100);
|
||||||
|
const normalizedOpacityTo = clamp(opacityTo, 0, 100);
|
||||||
|
const normalizedDuration = Math.max(duration, 0);
|
||||||
|
const normalizedDelay = Math.max(delay, 0);
|
||||||
|
|
||||||
|
this.elementOpacityOverrides.set(id, normalizedOpacityFrom);
|
||||||
|
|
||||||
|
if (positionFrom.x !== 0 || positionFrom.y !== 0) {
|
||||||
|
this.elementPositionOverrides.set(id, positionFrom);
|
||||||
|
} else {
|
||||||
|
this.elementPositionOverrides.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (normalizedDuration === 0 && normalizedDelay === 0) {
|
||||||
|
this.elementAnimationStates.delete(id);
|
||||||
|
this.elementOpacityOverrides.set(id, normalizedOpacityTo);
|
||||||
|
|
||||||
|
if (positionTo.x !== 0 || positionTo.y !== 0) {
|
||||||
|
this.elementPositionOverrides.set(id, positionTo);
|
||||||
|
} else {
|
||||||
|
this.elementPositionOverrides.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.bumpRenderAnimationVersion();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.elementAnimationStates.set(id, {
|
||||||
|
opacityFrom: normalizedOpacityFrom,
|
||||||
|
opacityTo: normalizedOpacityTo,
|
||||||
|
positionFrom,
|
||||||
|
positionTo,
|
||||||
|
easing,
|
||||||
|
duration: normalizedDuration,
|
||||||
|
delay: normalizedDelay,
|
||||||
|
elapsed: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.bumpRenderAnimationVersion();
|
||||||
|
this.syncElementAnimations();
|
||||||
|
};
|
||||||
|
|
||||||
|
private syncElementAnimations = () => {
|
||||||
|
const animationKey = this.getElementAnimationKey();
|
||||||
|
|
||||||
|
if (this.elementAnimationStates.size === 0) {
|
||||||
|
AnimationController.cancel(animationKey);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AnimationController.running(animationKey)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AnimationController.start(animationKey, ({ deltaTime }) => {
|
||||||
|
let shouldRerender = false;
|
||||||
|
|
||||||
|
for (const [id, animation] of this.elementAnimationStates) {
|
||||||
|
const element = this.scene.getNonDeletedElement(id);
|
||||||
|
|
||||||
|
if (!element) {
|
||||||
|
this.elementAnimationStates.delete(id);
|
||||||
|
shouldRerender =
|
||||||
|
this.elementOpacityOverrides.delete(id) || shouldRerender;
|
||||||
|
shouldRerender =
|
||||||
|
this.elementPositionOverrides.delete(id) || shouldRerender;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
animation.elapsed += deltaTime;
|
||||||
|
|
||||||
|
const progress =
|
||||||
|
animation.elapsed <= animation.delay
|
||||||
|
? 0
|
||||||
|
: animation.duration === 0
|
||||||
|
? 1
|
||||||
|
: Math.min(
|
||||||
|
(animation.elapsed - animation.delay) / animation.duration,
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
const easedProgress = this.applyAnimationEasing(
|
||||||
|
progress,
|
||||||
|
animation.easing,
|
||||||
|
);
|
||||||
|
|
||||||
|
const nextOpacity =
|
||||||
|
animation.opacityFrom +
|
||||||
|
(animation.opacityTo - animation.opacityFrom) * easedProgress;
|
||||||
|
const nextPosition = {
|
||||||
|
x:
|
||||||
|
animation.positionFrom.x +
|
||||||
|
(animation.positionTo.x - animation.positionFrom.x) * easedProgress,
|
||||||
|
y:
|
||||||
|
animation.positionFrom.y +
|
||||||
|
(animation.positionTo.y - animation.positionFrom.y) * easedProgress,
|
||||||
|
};
|
||||||
|
|
||||||
|
const clampedOpacity = clamp(nextOpacity, 0, 100);
|
||||||
|
|
||||||
|
if (this.elementOpacityOverrides.get(id) !== clampedOpacity) {
|
||||||
|
this.elementOpacityOverrides.set(id, clampedOpacity);
|
||||||
|
shouldRerender = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentPositionOverride =
|
||||||
|
this.elementPositionOverrides.get(id) ?? ({ x: 0, y: 0 } as const);
|
||||||
|
|
||||||
|
if (
|
||||||
|
currentPositionOverride.x !== nextPosition.x ||
|
||||||
|
currentPositionOverride.y !== nextPosition.y
|
||||||
|
) {
|
||||||
|
if (nextPosition.x === 0 && nextPosition.y === 0) {
|
||||||
|
this.elementPositionOverrides.delete(id);
|
||||||
|
} else {
|
||||||
|
this.elementPositionOverrides.set(id, nextPosition);
|
||||||
|
}
|
||||||
|
shouldRerender = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (animation.elapsed >= animation.delay + animation.duration) {
|
||||||
|
this.elementAnimationStates.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldRerender) {
|
||||||
|
this.bumpRenderAnimationVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.elementAnimationStates.size > 0 ? {} : undefined;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
private createExcalidrawAPI(): ExcalidrawImperativeAPI {
|
private createExcalidrawAPI(): ExcalidrawImperativeAPI {
|
||||||
const api: ExcalidrawImperativeAPI = {
|
const api: ExcalidrawImperativeAPI = {
|
||||||
@@ -756,6 +989,9 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
clear: this.resetHistory,
|
clear: this.resetHistory,
|
||||||
},
|
},
|
||||||
scrollToContent: this.scrollToContent,
|
scrollToContent: this.scrollToContent,
|
||||||
|
animateElements: this.animateElements,
|
||||||
|
cancelElementAnimation: this.cancelElementAnimation,
|
||||||
|
clearElementAnimationOverrides: this.clearElementAnimationOverrides,
|
||||||
getSceneElements: this.getSceneElements,
|
getSceneElements: this.getSceneElements,
|
||||||
getAppState: () => this.state,
|
getAppState: () => this.state,
|
||||||
getFiles: () => this.files,
|
getFiles: () => this.files,
|
||||||
@@ -933,20 +1169,14 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
"Missing last pointer move coords when changing bind skip mode for arrow start",
|
"Missing last pointer move coords when changing bind skip mode for arrow start",
|
||||||
);
|
);
|
||||||
const elementsMap = this.scene.getNonDeletedElementsMap();
|
const elementsMap = this.scene.getNonDeletedElementsMap();
|
||||||
const arrow = elementsMap.get(
|
const hoveredElement = getHoveredElementForBinding(
|
||||||
this.state.selectedLinearElement.elementId,
|
pointFrom<GlobalPoint>(
|
||||||
) as ExcalidrawArrowElement | undefined;
|
this.lastPointerMoveCoords.x,
|
||||||
const hoveredElement =
|
this.lastPointerMoveCoords.y,
|
||||||
arrow &&
|
),
|
||||||
getHoveredElementForBinding(
|
this.scene.getNonDeletedElements(),
|
||||||
arrow,
|
elementsMap,
|
||||||
pointFrom<GlobalPoint>(
|
);
|
||||||
this.lastPointerMoveCoords.x,
|
|
||||||
this.lastPointerMoveCoords.y,
|
|
||||||
),
|
|
||||||
this.scene.getNonDeletedElements(),
|
|
||||||
elementsMap,
|
|
||||||
);
|
|
||||||
const element = LinearElementEditor.getElement(
|
const element = LinearElementEditor.getElement(
|
||||||
this.state.selectedLinearElement.elementId,
|
this.state.selectedLinearElement.elementId,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
@@ -1076,7 +1306,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
const { x, y } = this.lastPointerMoveCoords;
|
const { x, y } = this.lastPointerMoveCoords;
|
||||||
const hoveredElement = getHoveredElementForBinding(
|
const hoveredElement = getHoveredElementForBinding(
|
||||||
arrow,
|
|
||||||
pointFrom<GlobalPoint>(x, y),
|
pointFrom<GlobalPoint>(x, y),
|
||||||
this.scene.getNonDeletedElements(),
|
this.scene.getNonDeletedElements(),
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this.scene.getNonDeletedElementsMap(),
|
||||||
@@ -1740,6 +1969,10 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
const isHovered =
|
const isHovered =
|
||||||
this.state.activeEmbeddable?.element === el &&
|
this.state.activeEmbeddable?.element === el &&
|
||||||
this.state.activeEmbeddable?.state === "hover";
|
this.state.activeEmbeddable?.state === "hover";
|
||||||
|
const renderPositionOffset = resolveRenderPositionOffset(
|
||||||
|
el,
|
||||||
|
this.getRenderOpacityConfig(),
|
||||||
|
);
|
||||||
|
|
||||||
// scale video embeds based on zoom (capped) so that smaller embeds
|
// scale video embeds based on zoom (capped) so that smaller embeds
|
||||||
// on canvas when zoomed are still of legible quality
|
// on canvas when zoomed are still of legible quality
|
||||||
@@ -1761,13 +1994,14 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
})}
|
})}
|
||||||
style={{
|
style={{
|
||||||
transform: isVisible
|
transform: isVisible
|
||||||
? `translate(${x - this.state.offsetLeft}px, ${
|
? `translate(${x + renderPositionOffset.x * this.state.zoom.value - this.state.offsetLeft}px, ${
|
||||||
y - this.state.offsetTop
|
y + renderPositionOffset.y * this.state.zoom.value - this.state.offsetTop
|
||||||
}px) scale(${scale})`
|
}px) scale(${scale})`
|
||||||
: "none",
|
: "none",
|
||||||
display: isVisible ? "block" : "none",
|
display: isVisible ? "block" : "none",
|
||||||
opacity: getRenderOpacity(
|
opacity: getRenderOpacity(
|
||||||
el,
|
el,
|
||||||
|
this.getRenderOpacityConfig(),
|
||||||
getContainingFrame(el, this.scene.getNonDeletedElementsMap()),
|
getContainingFrame(el, this.scene.getNonDeletedElementsMap()),
|
||||||
this.elementsPendingErasure,
|
this.elementsPendingErasure,
|
||||||
null,
|
null,
|
||||||
@@ -2357,6 +2591,9 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
pendingFlowchartNodes:
|
pendingFlowchartNodes:
|
||||||
this.flowChartCreator.pendingNodes,
|
this.flowChartCreator.pendingNodes,
|
||||||
theme: this.state.theme,
|
theme: this.state.theme,
|
||||||
|
...this.getRenderOpacityConfig(),
|
||||||
|
renderAnimationVersion:
|
||||||
|
this.renderAnimationVersion,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{newElementCanvasElement && (
|
{newElementCanvasElement && (
|
||||||
@@ -2379,6 +2616,9 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.elementsPendingErasure,
|
this.elementsPendingErasure,
|
||||||
pendingFlowchartNodes: null,
|
pendingFlowchartNodes: null,
|
||||||
theme: this.state.theme,
|
theme: this.state.theme,
|
||||||
|
...this.getRenderOpacityConfig(),
|
||||||
|
renderAnimationVersion:
|
||||||
|
this.renderAnimationVersion,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -3212,6 +3452,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.editorLifecycleEvents.emit("editor:unmount");
|
this.editorLifecycleEvents.emit("editor:unmount");
|
||||||
this.props.onUnmount?.();
|
this.props.onUnmount?.();
|
||||||
this.props.onExcalidrawAPI?.(null);
|
this.props.onExcalidrawAPI?.(null);
|
||||||
|
AnimationController.cancel(this.getElementAnimationKey());
|
||||||
|
|
||||||
(window as any).launchQueue?.setConsumer(() => {});
|
(window as any).launchQueue?.setConsumer(() => {});
|
||||||
|
|
||||||
@@ -4624,6 +4865,98 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public animateElements = ({
|
||||||
|
elements,
|
||||||
|
duration = 250,
|
||||||
|
delay = 0,
|
||||||
|
stagger = 0,
|
||||||
|
phase = "in",
|
||||||
|
easing,
|
||||||
|
...animation
|
||||||
|
}:
|
||||||
|
| {
|
||||||
|
elements: readonly (ExcalidrawElement | ExcalidrawElement["id"])[];
|
||||||
|
type: "fade";
|
||||||
|
duration?: number;
|
||||||
|
delay?: number;
|
||||||
|
stagger?: number;
|
||||||
|
phase?: "in" | "out";
|
||||||
|
easing?: "linear" | "easeOut" | "easeInOut";
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
elements: readonly (ExcalidrawElement | ExcalidrawElement["id"])[];
|
||||||
|
type: "fly";
|
||||||
|
from: "left" | "right" | "top" | "bottom";
|
||||||
|
duration?: number;
|
||||||
|
delay?: number;
|
||||||
|
stagger?: number;
|
||||||
|
phase?: "in" | "out";
|
||||||
|
easing?: "linear" | "easeOut" | "easeInOut";
|
||||||
|
}) => {
|
||||||
|
const normalizedDelay = Math.max(delay, 0);
|
||||||
|
const normalizedStagger = Math.max(stagger, 0);
|
||||||
|
|
||||||
|
elements.forEach((elementOrId, index) => {
|
||||||
|
const id = typeof elementOrId === "string" ? elementOrId : elementOrId.id;
|
||||||
|
const element = this.scene.getNonDeletedElement(id);
|
||||||
|
|
||||||
|
if (!element) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (animation.type === "fade") {
|
||||||
|
this.animateElement({
|
||||||
|
id,
|
||||||
|
opacityFrom:
|
||||||
|
phase === "in" ? 0 : this.getElementVisibleOpacity(element),
|
||||||
|
opacityTo:
|
||||||
|
phase === "in" ? this.getElementVisibleOpacity(element) : 0,
|
||||||
|
easing: easing ?? "easeInOut",
|
||||||
|
duration,
|
||||||
|
delay: normalizedDelay + index * normalizedStagger,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const flyOffset = this.getFlyPositionOffset(element, animation.from);
|
||||||
|
|
||||||
|
this.animateElement({
|
||||||
|
id,
|
||||||
|
opacityFrom: phase === "in" ? 0 : this.getElementVisibleOpacity(element),
|
||||||
|
opacityTo: phase === "in" ? this.getElementVisibleOpacity(element) : 0,
|
||||||
|
positionFrom: phase === "in" ? flyOffset : { x: 0, y: 0 },
|
||||||
|
positionTo: phase === "in" ? { x: 0, y: 0 } : flyOffset,
|
||||||
|
easing: easing ?? "easeOut",
|
||||||
|
duration,
|
||||||
|
delay: normalizedDelay + index * normalizedStagger,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
public cancelElementAnimation = (id: string) => {
|
||||||
|
if (!this.elementAnimationStates.delete(id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.syncElementAnimations();
|
||||||
|
};
|
||||||
|
|
||||||
|
public clearElementAnimationOverrides = () => {
|
||||||
|
if (
|
||||||
|
this.elementOpacityOverrides.size === 0 &&
|
||||||
|
this.elementPositionOverrides.size === 0 &&
|
||||||
|
this.elementAnimationStates.size === 0
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.elementAnimationStates.clear();
|
||||||
|
this.elementOpacityOverrides.clear();
|
||||||
|
this.elementPositionOverrides.clear();
|
||||||
|
this.syncElementAnimations();
|
||||||
|
this.bumpRenderAnimationVersion();
|
||||||
|
};
|
||||||
|
|
||||||
public applyDeltas = (
|
public applyDeltas = (
|
||||||
deltas: StoreDelta[],
|
deltas: StoreDelta[],
|
||||||
options?: ApplyToOptions,
|
options?: ApplyToOptions,
|
||||||
@@ -5383,6 +5716,12 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.state,
|
this.state,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const hoveredElement = getHoveredElementForBinding(
|
||||||
|
pointFrom<GlobalPoint>(scenePointer.x, scenePointer.y),
|
||||||
|
this.scene.getNonDeletedElements(),
|
||||||
|
this.scene.getNonDeletedElementsMap(),
|
||||||
|
);
|
||||||
|
|
||||||
if (this.state.selectedLinearElement) {
|
if (this.state.selectedLinearElement) {
|
||||||
const element = LinearElementEditor.getElement(
|
const element = LinearElementEditor.getElement(
|
||||||
this.state.selectedLinearElement.elementId,
|
this.state.selectedLinearElement.elementId,
|
||||||
@@ -5390,13 +5729,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (isBindingElement(element)) {
|
if (isBindingElement(element)) {
|
||||||
const hoveredElement = getHoveredElementForBinding(
|
|
||||||
element,
|
|
||||||
pointFrom<GlobalPoint>(scenePointer.x, scenePointer.y),
|
|
||||||
this.scene.getNonDeletedElements(),
|
|
||||||
this.scene.getNonDeletedElementsMap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
this.handleDelayedBindModeChange(element, hoveredElement);
|
this.handleDelayedBindModeChange(element, hoveredElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7083,11 +7415,10 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
);
|
);
|
||||||
const elementsMap = this.scene.getNonDeletedElementsMap();
|
const elementsMap = this.scene.getNonDeletedElementsMap();
|
||||||
const hoveredElement = getHoveredElementForBinding(
|
const hoveredElement = getHoveredElementForBinding(
|
||||||
{ elbowed: this.state.currentItemArrowType === ARROW_TYPE.elbow },
|
globalPoint,
|
||||||
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
|
||||||
this.scene.getNonDeletedElements(),
|
this.scene.getNonDeletedElements(),
|
||||||
elementsMap,
|
elementsMap,
|
||||||
this.state.zoom,
|
maxBindingDistance_simple(this.state.zoom),
|
||||||
);
|
);
|
||||||
if (hoveredElement) {
|
if (hoveredElement) {
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -7098,9 +7429,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
hoveredElement,
|
hoveredElement,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
this.state.zoom,
|
this.state.zoom,
|
||||||
{
|
|
||||||
elbowed: this.state.currentItemArrowType === ARROW_TYPE.elbow,
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -7126,11 +7454,10 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
isArrowElement(this.state.newElement) &&
|
isArrowElement(this.state.newElement) &&
|
||||||
isBindingEnabled(this.state) &&
|
isBindingEnabled(this.state) &&
|
||||||
getHoveredElementForBinding(
|
getHoveredElementForBinding(
|
||||||
this.state.newElement,
|
|
||||||
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
||||||
this.scene.getNonDeletedElements(),
|
this.scene.getNonDeletedElements(),
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this.scene.getNonDeletedElementsMap(),
|
||||||
this.state.zoom,
|
maxBindingDistance_simple(this.state.zoom),
|
||||||
);
|
);
|
||||||
if (hoveredElement) {
|
if (hoveredElement) {
|
||||||
this.actionManager.executeAction(actionFinalize, "ui", {
|
this.actionManager.executeAction(actionFinalize, "ui", {
|
||||||
@@ -7245,7 +7572,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
if (isSimpleArrow(multiElement)) {
|
if (isSimpleArrow(multiElement)) {
|
||||||
const hoveredElement = getHoveredElementForBinding(
|
const hoveredElement = getHoveredElementForBinding(
|
||||||
multiElement,
|
|
||||||
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
||||||
this.scene.getNonDeletedElements(),
|
this.scene.getNonDeletedElements(),
|
||||||
elementsMap,
|
elementsMap,
|
||||||
@@ -7278,11 +7604,10 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
if (this.state.activeTool.type === "arrow") {
|
if (this.state.activeTool.type === "arrow") {
|
||||||
const hit = getHoveredElementForBinding(
|
const hit = getHoveredElementForBinding(
|
||||||
{ elbowed: this.state.currentItemArrowType === ARROW_TYPE.elbow },
|
|
||||||
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
||||||
this.scene.getNonDeletedElements(),
|
this.scene.getNonDeletedElements(),
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this.scene.getNonDeletedElementsMap(),
|
||||||
this.state.zoom,
|
maxBindingDistance_simple(this.state.zoom),
|
||||||
);
|
);
|
||||||
const scenePointer = pointFrom<GlobalPoint>(scenePointerX, scenePointerY);
|
const scenePointer = pointFrom<GlobalPoint>(scenePointerX, scenePointerY);
|
||||||
const elementsMap = this.scene.getNonDeletedElementsMap();
|
const elementsMap = this.scene.getNonDeletedElementsMap();
|
||||||
@@ -7295,7 +7620,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
hit,
|
hit,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
this.state.zoom,
|
this.state.zoom,
|
||||||
{ elbowed: this.state.currentItemArrowType === ARROW_TYPE.elbow },
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -9282,7 +9606,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
const hoveredElementForBinding =
|
const hoveredElementForBinding =
|
||||||
isBindingEnabled(this.state) &&
|
isBindingEnabled(this.state) &&
|
||||||
getHoveredElementForBinding(
|
getHoveredElementForBinding(
|
||||||
{ elbowed: isElbowArrow(multiElement) },
|
|
||||||
pointFrom<GlobalPoint>(
|
pointFrom<GlobalPoint>(
|
||||||
this.lastPointerMoveCoords?.x ??
|
this.lastPointerMoveCoords?.x ??
|
||||||
rx + multiElement.points[multiElement.points.length - 1][0],
|
rx + multiElement.points[multiElement.points.length - 1][0],
|
||||||
@@ -9405,7 +9728,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
const elementsMap = this.scene.getNonDeletedElementsMap();
|
const elementsMap = this.scene.getNonDeletedElementsMap();
|
||||||
const boundElement = isBindingEnabled(this.state)
|
const boundElement = isBindingEnabled(this.state)
|
||||||
? getHoveredElementForBinding(
|
? getHoveredElementForBinding(
|
||||||
{ elbowed: this.state.currentItemArrowType === ARROW_TYPE.elbow },
|
|
||||||
point,
|
point,
|
||||||
this.scene.getNonDeletedElements(),
|
this.scene.getNonDeletedElements(),
|
||||||
elementsMap,
|
elementsMap,
|
||||||
@@ -9481,6 +9803,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
...prevState,
|
...prevState,
|
||||||
bindMode: "orbit",
|
bindMode: "orbit",
|
||||||
newElement: element,
|
newElement: element,
|
||||||
|
startBoundElement: boundElement,
|
||||||
suggestedBinding:
|
suggestedBinding:
|
||||||
boundElement && isBindingElement(element)
|
boundElement && isBindingElement(element)
|
||||||
? {
|
? {
|
||||||
@@ -9490,7 +9813,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
boundElement,
|
boundElement,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
this.state.zoom,
|
this.state.zoom,
|
||||||
element,
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
@@ -9887,16 +10209,16 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isBindingElement(element) && getFeatureFlag("COMPLEX_BINDINGS")) {
|
if (isBindingElement(element)) {
|
||||||
const hoveredElement = getHoveredElementForBinding(
|
const hoveredElement = getHoveredElementForBinding(
|
||||||
element,
|
|
||||||
pointFrom<GlobalPoint>(pointerCoords.x, pointerCoords.y),
|
pointFrom<GlobalPoint>(pointerCoords.x, pointerCoords.y),
|
||||||
this.scene.getNonDeletedElements(),
|
this.scene.getNonDeletedElements(),
|
||||||
elementsMap,
|
elementsMap,
|
||||||
this.state.zoom,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.handleDelayedBindModeChange(element, hoveredElement);
|
if (getFeatureFlag("COMPLEX_BINDINGS")) {
|
||||||
|
this.handleDelayedBindModeChange(element, hoveredElement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ const ExcalidrawBase = (props: ExcalidrawProps) => {
|
|||||||
children,
|
children,
|
||||||
validateEmbeddable,
|
validateEmbeddable,
|
||||||
renderEmbeddable,
|
renderEmbeddable,
|
||||||
|
resolveRenderOpacity,
|
||||||
aiEnabled,
|
aiEnabled,
|
||||||
showDeprecatedFonts,
|
showDeprecatedFonts,
|
||||||
renderScrollbars,
|
renderScrollbars,
|
||||||
@@ -217,6 +218,7 @@ const ExcalidrawBase = (props: ExcalidrawProps) => {
|
|||||||
onDuplicate={onDuplicate}
|
onDuplicate={onDuplicate}
|
||||||
validateEmbeddable={validateEmbeddable}
|
validateEmbeddable={validateEmbeddable}
|
||||||
renderEmbeddable={renderEmbeddable}
|
renderEmbeddable={renderEmbeddable}
|
||||||
|
resolveRenderOpacity={resolveRenderOpacity}
|
||||||
aiEnabled={aiEnabled !== false}
|
aiEnabled={aiEnabled !== false}
|
||||||
showDeprecatedFonts={showDeprecatedFonts}
|
showDeprecatedFonts={showDeprecatedFonts}
|
||||||
renderScrollbars={renderScrollbars}
|
renderScrollbars={renderScrollbars}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
type Radians,
|
type Radians,
|
||||||
bezierEquation,
|
bezierEquation,
|
||||||
pointRotateRads,
|
pointRotateRads,
|
||||||
|
pointDistance,
|
||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -23,12 +24,13 @@ import {
|
|||||||
deconstructDiamondElement,
|
deconstructDiamondElement,
|
||||||
deconstructRectanguloidElement,
|
deconstructRectanguloidElement,
|
||||||
elementCenterPoint,
|
elementCenterPoint,
|
||||||
getAllMidpoints,
|
getDiamondBaseCorners,
|
||||||
FOCUS_POINT_SIZE,
|
FOCUS_POINT_SIZE,
|
||||||
getOmitSidesForEditorInterface,
|
getOmitSidesForEditorInterface,
|
||||||
getTransformHandles,
|
getTransformHandles,
|
||||||
getTransformHandlesFromCoords,
|
getTransformHandlesFromCoords,
|
||||||
hasBoundingBox,
|
hasBoundingBox,
|
||||||
|
hitElementItself,
|
||||||
isArrowElement,
|
isArrowElement,
|
||||||
isBindableElement,
|
isBindableElement,
|
||||||
isElbowArrow,
|
isElbowArrow,
|
||||||
@@ -36,6 +38,7 @@ import {
|
|||||||
isImageElement,
|
isImageElement,
|
||||||
isLinearElement,
|
isLinearElement,
|
||||||
isLineElement,
|
isLineElement,
|
||||||
|
maxBindingDistance_simple,
|
||||||
isTextElement,
|
isTextElement,
|
||||||
LinearElementEditor,
|
LinearElementEditor,
|
||||||
getActiveTextElement,
|
getActiveTextElement,
|
||||||
@@ -410,42 +413,145 @@ const renderBindingHighlightForBindableElement_simple = (
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw midpoint indicators
|
|
||||||
if (
|
if (
|
||||||
appState.isMidpointSnappingEnabled &&
|
appState.isMidpointSnappingEnabled &&
|
||||||
(isFrameLikeElement(suggestedBinding.element) ||
|
(isFrameLikeElement(suggestedBinding.element) ||
|
||||||
isBindableElement(suggestedBinding.element))
|
isBindableElement(suggestedBinding.element))
|
||||||
) {
|
) {
|
||||||
context.save();
|
// Draw midpoint indicators
|
||||||
|
const linearElement = appState.selectedLinearElement;
|
||||||
|
const arrow =
|
||||||
|
linearElement?.elementId &&
|
||||||
|
LinearElementEditor.getElement(linearElement?.elementId, elementsMap);
|
||||||
|
const cursorIsInsideBindable =
|
||||||
|
pointerCoords &&
|
||||||
|
hitElementItself({
|
||||||
|
point: pointerCoords,
|
||||||
|
element: suggestedBinding.element,
|
||||||
|
elementsMap,
|
||||||
|
threshold: 0,
|
||||||
|
overrideShouldTestInside: true,
|
||||||
|
});
|
||||||
|
|
||||||
const midpointRadius = 4 / appState.zoom.value;
|
const isElbow =
|
||||||
|
(arrow && isElbowArrow(arrow)) ||
|
||||||
|
(appState.activeTool.type === "arrow" &&
|
||||||
|
appState.currentItemArrowType === "elbow");
|
||||||
|
|
||||||
// Render base midpoints
|
if (!cursorIsInsideBindable || isElbow) {
|
||||||
const midpoints = getAllMidpoints(suggestedBinding.element, elementsMap);
|
context.save();
|
||||||
for (const midpoint of midpoints) {
|
|
||||||
context.fillStyle =
|
const center = elementCenterPoint(suggestedBinding.element, elementsMap);
|
||||||
appState.theme === THEME.DARK
|
|
||||||
? `rgba(0, 0, 0, 0.8)`
|
let midpoints: GlobalPoint[];
|
||||||
: `rgba(65, 65, 65, 0.5)`;
|
if (suggestedBinding.element.type === "diamond") {
|
||||||
context.beginPath();
|
const center = elementCenterPoint(
|
||||||
context.arc(midpoint[0], midpoint[1], midpointRadius, 0, 2 * Math.PI);
|
suggestedBinding.element,
|
||||||
context.fill();
|
elementsMap,
|
||||||
|
);
|
||||||
|
midpoints = getDiamondBaseCorners(suggestedBinding.element).map(
|
||||||
|
(curve) => {
|
||||||
|
const point = bezierEquation(curve, 0.5);
|
||||||
|
const rotatedPoint = pointRotateRads(
|
||||||
|
point,
|
||||||
|
center,
|
||||||
|
suggestedBinding.element.angle,
|
||||||
|
);
|
||||||
|
|
||||||
|
return pointFrom<GlobalPoint>(rotatedPoint[0], rotatedPoint[1]);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const basePoints = [
|
||||||
|
{
|
||||||
|
x: suggestedBinding.element.width,
|
||||||
|
y: suggestedBinding.element.height / 2,
|
||||||
|
}, // RIGHT
|
||||||
|
{
|
||||||
|
x: suggestedBinding.element.width / 2,
|
||||||
|
y: suggestedBinding.element.height,
|
||||||
|
}, // BOTTOM
|
||||||
|
{ x: 0, y: suggestedBinding.element.height / 2 }, // LEFT
|
||||||
|
{ x: suggestedBinding.element.width / 2, y: 0 }, // TOP
|
||||||
|
];
|
||||||
|
midpoints = basePoints.map((point) => {
|
||||||
|
const globalPoint = pointFrom<GlobalPoint>(
|
||||||
|
point.x + suggestedBinding.element.x,
|
||||||
|
point.y + suggestedBinding.element.y,
|
||||||
|
);
|
||||||
|
const rotatedPoint = pointRotateRads(
|
||||||
|
globalPoint,
|
||||||
|
center,
|
||||||
|
suggestedBinding.element.angle,
|
||||||
|
);
|
||||||
|
return pointFrom<GlobalPoint>(rotatedPoint[0], rotatedPoint[1]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const hoveredMidpoint =
|
||||||
|
pointerCoords &&
|
||||||
|
midpoints.reduce(
|
||||||
|
(
|
||||||
|
closestIdx: {
|
||||||
|
idx: number;
|
||||||
|
distance: number;
|
||||||
|
},
|
||||||
|
point,
|
||||||
|
idx,
|
||||||
|
) => {
|
||||||
|
const distance = pointDistance(point, pointerCoords);
|
||||||
|
if (idx === -1 || distance < closestIdx.distance) {
|
||||||
|
return { idx, distance };
|
||||||
|
}
|
||||||
|
return closestIdx;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
idx: -1,
|
||||||
|
distance: Infinity,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const midpointRadius = 4 / appState.zoom.value;
|
||||||
|
const highlightThreshold =
|
||||||
|
maxBindingDistance_simple(appState.zoom) +
|
||||||
|
suggestedBinding.element.strokeWidth / 2;
|
||||||
|
|
||||||
|
midpoints.forEach((midpoint, idx) => {
|
||||||
|
const isHighlighted =
|
||||||
|
(!cursorIsInsideBindable || isElbow) &&
|
||||||
|
hoveredMidpoint?.idx === idx &&
|
||||||
|
hoveredMidpoint.distance <= highlightThreshold;
|
||||||
|
|
||||||
|
// also render midpoint if cursor close but not highlighted
|
||||||
|
// (for elbows, always show all points)
|
||||||
|
const isShown =
|
||||||
|
!isHighlighted &&
|
||||||
|
(isElbow ||
|
||||||
|
(idx === hoveredMidpoint?.idx &&
|
||||||
|
hoveredMidpoint.distance <= highlightThreshold * 2));
|
||||||
|
|
||||||
|
if (isHighlighted) {
|
||||||
|
context.fillStyle =
|
||||||
|
appState.theme === THEME.DARK
|
||||||
|
? `rgba(3, 93, 161, 1)`
|
||||||
|
: `rgba(106, 189, 252, 1)`;
|
||||||
|
|
||||||
|
context.beginPath();
|
||||||
|
context.arc(midpoint[0], midpoint[1], midpointRadius, 0, 2 * Math.PI);
|
||||||
|
context.fill();
|
||||||
|
} else if (isShown) {
|
||||||
|
context.fillStyle =
|
||||||
|
appState.theme === THEME.DARK
|
||||||
|
? `rgba(0, 0, 0, 0.8)`
|
||||||
|
: `rgba(65, 65, 65, 0.5)`;
|
||||||
|
context.beginPath();
|
||||||
|
context.arc(midpoint[0], midpoint[1], midpointRadius, 0, 2 * Math.PI);
|
||||||
|
context.fill();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
context.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the highlighted midpoint if any
|
|
||||||
const midpoint = appState.suggestedBinding?.midPoint;
|
|
||||||
if (midpoint) {
|
|
||||||
context.fillStyle =
|
|
||||||
appState.theme === THEME.DARK
|
|
||||||
? `rgba(3, 93, 161, 1)`
|
|
||||||
: `rgba(106, 189, 252, 1)`;
|
|
||||||
|
|
||||||
context.beginPath();
|
|
||||||
context.arc(midpoint[0], midpoint[1], midpointRadius, 0, 2 * Math.PI);
|
|
||||||
context.fill();
|
|
||||||
}
|
|
||||||
|
|
||||||
context.restore();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,16 @@ import {
|
|||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
import {
|
import {
|
||||||
elementOverlapsWithFrame,
|
elementOverlapsWithFrame,
|
||||||
|
getContainingFrame,
|
||||||
getTargetFrame,
|
getTargetFrame,
|
||||||
shouldApplyFrameClip,
|
shouldApplyFrameClip,
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
import { renderElement } from "@excalidraw/element";
|
import {
|
||||||
|
getRenderElementWithPositionOverride,
|
||||||
|
getRenderOpacity,
|
||||||
|
renderElement,
|
||||||
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
import { getElementAbsoluteCoords } from "@excalidraw/element";
|
import { getElementAbsoluteCoords } from "@excalidraw/element";
|
||||||
|
|
||||||
@@ -170,7 +175,10 @@ const renderLinkIcon = (
|
|||||||
context: CanvasRenderingContext2D,
|
context: CanvasRenderingContext2D,
|
||||||
appState: StaticCanvasAppState,
|
appState: StaticCanvasAppState,
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
|
renderConfig: StaticCanvasRenderConfig,
|
||||||
) => {
|
) => {
|
||||||
|
element = getRenderElementWithPositionOverride(element, renderConfig);
|
||||||
|
|
||||||
if (element.link && !appState.selectedElementIds[element.id]) {
|
if (element.link && !appState.selectedElementIds[element.id]) {
|
||||||
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element, elementsMap);
|
const [x1, y1, x2, y2] = getElementAbsoluteCoords(element, elementsMap);
|
||||||
const [x, y, width, height] = getLinkHandleFromCoords(
|
const [x, y, width, height] = getLinkHandleFromCoords(
|
||||||
@@ -221,7 +229,13 @@ const renderLinkIcon = (
|
|||||||
|
|
||||||
linkCanvasCacheContext.restore();
|
linkCanvasCacheContext.restore();
|
||||||
}
|
}
|
||||||
context.globalAlpha = element.opacity / 100;
|
context.globalAlpha = getRenderOpacity(
|
||||||
|
element,
|
||||||
|
renderConfig,
|
||||||
|
getContainingFrame(element, elementsMap),
|
||||||
|
renderConfig.elementsPendingErasure,
|
||||||
|
renderConfig.pendingFlowchartNodes,
|
||||||
|
);
|
||||||
context.drawImage(linkCanvas, x - centerX, y - centerY, width, height);
|
context.drawImage(linkCanvas, x - centerX, y - centerY, width, height);
|
||||||
context.restore();
|
context.restore();
|
||||||
}
|
}
|
||||||
@@ -370,7 +384,7 @@ const _renderStaticScene = ({
|
|||||||
context.restore();
|
context.restore();
|
||||||
|
|
||||||
if (!isExporting) {
|
if (!isExporting) {
|
||||||
renderLinkIcon(element, context, appState, elementsMap);
|
renderLinkIcon(element, context, appState, elementsMap, renderConfig);
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(
|
console.error(
|
||||||
@@ -421,7 +435,7 @@ const _renderStaticScene = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!isExporting) {
|
if (!isExporting) {
|
||||||
renderLinkIcon(element, context, appState, elementsMap);
|
renderLinkIcon(element, context, appState, elementsMap, renderConfig);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// - when exporting the whole canvas, we DO NOT apply clipping
|
// - when exporting the whole canvas, we DO NOT apply clipping
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import type {
|
|||||||
AppClassProperties,
|
AppClassProperties,
|
||||||
AppState,
|
AppState,
|
||||||
EmbedsValidationStatus,
|
EmbedsValidationStatus,
|
||||||
|
RenderOpacityResolver,
|
||||||
ElementsPendingErasure,
|
ElementsPendingErasure,
|
||||||
InteractiveCanvasAppState,
|
InteractiveCanvasAppState,
|
||||||
StaticCanvasAppState,
|
StaticCanvasAppState,
|
||||||
@@ -37,6 +38,13 @@ export type StaticCanvasRenderConfig = {
|
|||||||
elementsPendingErasure: ElementsPendingErasure;
|
elementsPendingErasure: ElementsPendingErasure;
|
||||||
pendingFlowchartNodes: PendingExcalidrawElements | null;
|
pendingFlowchartNodes: PendingExcalidrawElements | null;
|
||||||
theme: AppState["theme"];
|
theme: AppState["theme"];
|
||||||
|
resolveRenderOpacity?: RenderOpacityResolver;
|
||||||
|
elementOpacityOverrides?: ReadonlyMap<ExcalidrawElement["id"], number>;
|
||||||
|
elementPositionOverrides?: ReadonlyMap<
|
||||||
|
ExcalidrawElement["id"],
|
||||||
|
{ x: number; y: number }
|
||||||
|
>;
|
||||||
|
renderAnimationVersion?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SVGRenderConfig = {
|
export type SVGRenderConfig = {
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -731,6 +732,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -2275,6 +2277,40 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": {
|
||||||
|
"angle": 0,
|
||||||
|
"backgroundColor": "transparent",
|
||||||
|
"boundElements": [
|
||||||
|
{
|
||||||
|
"id": "id4",
|
||||||
|
"type": "arrow",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"customData": undefined,
|
||||||
|
"fillStyle": "solid",
|
||||||
|
"frameId": null,
|
||||||
|
"groupIds": [],
|
||||||
|
"height": 100,
|
||||||
|
"id": "id0",
|
||||||
|
"index": "a0",
|
||||||
|
"isDeleted": false,
|
||||||
|
"link": null,
|
||||||
|
"locked": false,
|
||||||
|
"opacity": 100,
|
||||||
|
"roughness": 1,
|
||||||
|
"roundness": null,
|
||||||
|
"seed": 1,
|
||||||
|
"strokeColor": "#1e1e1e",
|
||||||
|
"strokeStyle": "solid",
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"type": "rectangle",
|
||||||
|
"updated": 1,
|
||||||
|
"version": 3,
|
||||||
|
"versionNonce": 493213705,
|
||||||
|
"width": 100,
|
||||||
|
"x": -100,
|
||||||
|
"y": -50,
|
||||||
|
},
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -2374,7 +2410,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"endBinding": {
|
"endBinding": {
|
||||||
"elementId": "id1",
|
"elementId": "id1",
|
||||||
"fixedPoint": [
|
"fixedPoint": [
|
||||||
"0.50010",
|
0,
|
||||||
"0.50010",
|
"0.50010",
|
||||||
],
|
],
|
||||||
"mode": "orbit",
|
"mode": "orbit",
|
||||||
@@ -2382,7 +2418,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
"height": "399.26547",
|
"height": "439.20000",
|
||||||
"id": "id4",
|
"id": "id4",
|
||||||
"index": "a2",
|
"index": "a2",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
@@ -2396,8 +2432,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
0,
|
0,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"488.00000",
|
488,
|
||||||
"-399.26547",
|
"-439.20000",
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
"roughness": 1,
|
"roughness": 1,
|
||||||
@@ -2419,9 +2455,9 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"type": "arrow",
|
"type": "arrow",
|
||||||
"updated": 1,
|
"updated": 1,
|
||||||
"version": 11,
|
"version": 11,
|
||||||
"width": "488.00000",
|
"width": 488,
|
||||||
"x": 6,
|
"x": 6,
|
||||||
"y": "-4.89900",
|
"y": "-5.39000",
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -2542,7 +2578,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"endBinding": {
|
"endBinding": {
|
||||||
"elementId": "id1",
|
"elementId": "id1",
|
||||||
"fixedPoint": [
|
"fixedPoint": [
|
||||||
"0.50010",
|
0,
|
||||||
"0.50010",
|
"0.50010",
|
||||||
],
|
],
|
||||||
"mode": "orbit",
|
"mode": "orbit",
|
||||||
@@ -2550,7 +2586,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
"height": "399.26547",
|
"height": "439.20000",
|
||||||
"index": "a2",
|
"index": "a2",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"link": null,
|
"link": null,
|
||||||
@@ -2562,8 +2598,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
0,
|
0,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"488.00000",
|
488,
|
||||||
"-399.26547",
|
"-439.20000",
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
"roughness": 1,
|
"roughness": 1,
|
||||||
@@ -2584,9 +2620,9 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "arrow",
|
"type": "arrow",
|
||||||
"version": 11,
|
"version": 11,
|
||||||
"width": "488.00000",
|
"width": 488,
|
||||||
"x": 6,
|
"x": 6,
|
||||||
"y": "-4.89900",
|
"y": "-5.39000",
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"isDeleted": true,
|
"isDeleted": true,
|
||||||
@@ -7352,6 +7388,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -10323,6 +10360,7 @@ exports[`history > multiplayer undo/redo > should override remotely added points
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -16553,6 +16591,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -17301,6 +17340,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -17947,6 +17987,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -18591,6 +18632,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -19343,6 +19385,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -21560,6 +21603,7 @@ exports[`history > singleplayer undo/redo > should support linear element creati
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
|
|||||||
@@ -6243,6 +6243,7 @@ exports[`regression tests > draw every type of shape > [end of test] appState 1`
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -8691,6 +8692,7 @@ exports[`regression tests > key 5 selects arrow tool > [end of test] appState 1`
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -8923,6 +8925,7 @@ exports[`regression tests > key 6 selects line tool > [end of test] appState 1`]
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -9345,6 +9348,7 @@ exports[`regression tests > key a selects arrow tool > [end of test] appState 1`
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -9757,6 +9761,7 @@ exports[`regression tests > key l selects line tool > [end of test] appState 1`]
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
@@ -14514,6 +14519,7 @@ exports[`regression tests > undo/redo drawing an element > [end of test] appStat
|
|||||||
"showHyperlinkPopup": false,
|
"showHyperlinkPopup": false,
|
||||||
"showWelcomeScreen": true,
|
"showWelcomeScreen": true,
|
||||||
"snapLines": [],
|
"snapLines": [],
|
||||||
|
"startBoundElement": null,
|
||||||
"stats": {
|
"stats": {
|
||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
|
|||||||
@@ -5132,7 +5132,7 @@ describe("history", () => {
|
|||||||
}),
|
}),
|
||||||
endBinding: expect.objectContaining({
|
endBinding: expect.objectContaining({
|
||||||
elementId: rect2.id,
|
elementId: rect2.id,
|
||||||
fixedPoint: expect.arrayContaining([0.5001, 0.5001]),
|
fixedPoint: expect.arrayContaining([0, 0.5001]),
|
||||||
}),
|
}),
|
||||||
isDeleted: true,
|
isDeleted: true,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ import * as StaticScene from "../renderer/staticScene";
|
|||||||
import { UI, Pointer, Keyboard } from "./helpers/ui";
|
import { UI, Pointer, Keyboard } from "./helpers/ui";
|
||||||
import { render, fireEvent, act, unmountComponent } from "./test-utils";
|
import { render, fireEvent, act, unmountComponent } from "./test-utils";
|
||||||
|
|
||||||
import type { Zoom } from "../types";
|
|
||||||
|
|
||||||
unmountComponent();
|
unmountComponent();
|
||||||
|
|
||||||
const renderInteractiveScene = vi.spyOn(
|
const renderInteractiveScene = vi.spyOn(
|
||||||
@@ -90,7 +88,6 @@ describe("move element", () => {
|
|||||||
"orbit",
|
"orbit",
|
||||||
"start",
|
"start",
|
||||||
h.app.scene,
|
h.app.scene,
|
||||||
{ value: 1 } as Zoom,
|
|
||||||
);
|
);
|
||||||
bindBindingElement(
|
bindBindingElement(
|
||||||
arrow.get() as NonDeleted<ExcalidrawArrowElement>,
|
arrow.get() as NonDeleted<ExcalidrawArrowElement>,
|
||||||
@@ -98,7 +95,6 @@ describe("move element", () => {
|
|||||||
"orbit",
|
"orbit",
|
||||||
"end",
|
"end",
|
||||||
h.app.scene,
|
h.app.scene,
|
||||||
{ value: 1 } as Zoom,
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -115,13 +111,10 @@ describe("move element", () => {
|
|||||||
expect([rectA.x, rectA.y]).toEqual([0, 0]);
|
expect([rectA.x, rectA.y]).toEqual([0, 0]);
|
||||||
expect([rectB.x, rectB.y]).toEqual([200, 0]);
|
expect([rectB.x, rectB.y]).toEqual([200, 0]);
|
||||||
expect([[arrow.x, arrow.y]]).toCloselyEqualPoints(
|
expect([[arrow.x, arrow.y]]).toCloselyEqualPoints(
|
||||||
[[106, 56.011199999998695]],
|
[[106.00000000000001, 55.6867741935484]],
|
||||||
0,
|
|
||||||
);
|
|
||||||
expect([[arrow.width, arrow.height]]).toCloselyEqualPoints(
|
|
||||||
[[88, 88.01760000000121]],
|
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
expect([[arrow.width, arrow.height]]).toCloselyEqualPoints([[88, 88]], 0);
|
||||||
|
|
||||||
renderInteractiveScene.mockClear();
|
renderInteractiveScene.mockClear();
|
||||||
renderStaticScene.mockClear();
|
renderStaticScene.mockClear();
|
||||||
@@ -140,13 +133,10 @@ describe("move element", () => {
|
|||||||
expect([rectA.x, rectA.y]).toEqual([0, 0]);
|
expect([rectA.x, rectA.y]).toEqual([0, 0]);
|
||||||
expect([rectB.x, rectB.y]).toEqual([201, 2]);
|
expect([rectB.x, rectB.y]).toEqual([201, 2]);
|
||||||
expect([[arrow.x, arrow.y]]).toCloselyEqualPoints(
|
expect([[arrow.x, arrow.y]]).toCloselyEqualPoints(
|
||||||
[[106, 56.011199999998695]],
|
[[106, 55.6867741935484]],
|
||||||
0,
|
|
||||||
);
|
|
||||||
expect([[arrow.width, arrow.height]]).toCloselyEqualPoints(
|
|
||||||
[[89, 90.01760000000121]],
|
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
expect([[arrow.width, arrow.height]]).toCloselyEqualPoints([[89, 90]], 0);
|
||||||
|
|
||||||
h.elements.forEach((element) => expect(element).toMatchSnapshot());
|
h.elements.forEach((element) => expect(element).toMatchSnapshot());
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -567,6 +567,10 @@ export type OnExportProgress = {
|
|||||||
progress?: number;
|
progress?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type RenderOpacityResolver = (
|
||||||
|
element: NonDeletedExcalidrawElement,
|
||||||
|
) => ExcalidrawElement["opacity"] | undefined;
|
||||||
|
|
||||||
export interface ExcalidrawProps {
|
export interface ExcalidrawProps {
|
||||||
onChange?: (
|
onChange?: (
|
||||||
elements: readonly OrderedExcalidrawElement[],
|
elements: readonly OrderedExcalidrawElement[],
|
||||||
@@ -682,6 +686,7 @@ export interface ExcalidrawProps {
|
|||||||
element: NonDeleted<ExcalidrawEmbeddableElement>,
|
element: NonDeleted<ExcalidrawEmbeddableElement>,
|
||||||
appState: AppState,
|
appState: AppState,
|
||||||
) => JSX.Element | null;
|
) => JSX.Element | null;
|
||||||
|
resolveRenderOpacity?: RenderOpacityResolver;
|
||||||
aiEnabled?: boolean;
|
aiEnabled?: boolean;
|
||||||
showDeprecatedFonts?: boolean;
|
showDeprecatedFonts?: boolean;
|
||||||
renderScrollbars?: boolean;
|
renderScrollbars?: boolean;
|
||||||
@@ -962,6 +967,11 @@ export interface ExcalidrawImperativeAPI {
|
|||||||
getFiles: () => InstanceType<typeof App>["files"];
|
getFiles: () => InstanceType<typeof App>["files"];
|
||||||
getName: InstanceType<typeof App>["getName"];
|
getName: InstanceType<typeof App>["getName"];
|
||||||
scrollToContent: InstanceType<typeof App>["scrollToContent"];
|
scrollToContent: InstanceType<typeof App>["scrollToContent"];
|
||||||
|
animateElements: InstanceType<typeof App>["animateElements"];
|
||||||
|
cancelElementAnimation: InstanceType<typeof App>["cancelElementAnimation"];
|
||||||
|
clearElementAnimationOverrides: InstanceType<
|
||||||
|
typeof App
|
||||||
|
>["clearElementAnimationOverrides"];
|
||||||
registerAction: (action: Action) => void;
|
registerAction: (action: Action) => void;
|
||||||
refresh: InstanceType<typeof App>["refresh"];
|
refresh: InstanceType<typeof App>["refresh"];
|
||||||
setToast: InstanceType<typeof App>["setToast"];
|
setToast: InstanceType<typeof App>["setToast"];
|
||||||
|
|||||||
Reference in New Issue
Block a user