Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a7a3f9d82b | |||
| 895c2b23c7 | |||
| 50099012c6 | |||
| de2ad7cd3f | |||
| d7abb6a309 | |||
| 9fd91d9a59 | |||
| ba087233cb | |||
| 7c58d1f6f4 | |||
| d9ab298526 | |||
| 7b2496bfd7 |
@@ -1,5 +1,4 @@
|
|||||||
"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";
|
||||||
|
|
||||||
@@ -14,7 +13,6 @@ 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,7 +70,6 @@ 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({
|
||||||
@@ -79,7 +78,6 @@ export default function ExampleApp({
|
|||||||
customArgs,
|
customArgs,
|
||||||
children,
|
children,
|
||||||
excalidrawLib,
|
excalidrawLib,
|
||||||
showFadeDemo = false,
|
|
||||||
}: AppProps) {
|
}: AppProps) {
|
||||||
const {
|
const {
|
||||||
exportToCanvas,
|
exportToCanvas,
|
||||||
@@ -118,19 +116,6 @@ 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>;
|
||||||
@@ -193,8 +178,7 @@ export default function ExampleApp({
|
|||||||
const newElement = cloneElement(
|
const newElement = cloneElement(
|
||||||
Excalidraw,
|
Excalidraw,
|
||||||
{
|
{
|
||||||
onExcalidrawAPI: (api: ExcalidrawImperativeAPI | null) =>
|
excalidrawAPI: (api: ExcalidrawImperativeAPI) => setExcalidrawAPI(api),
|
||||||
setExcalidrawAPI(api),
|
|
||||||
initialData: initialStatePromiseRef.current.promise,
|
initialData: initialStatePromiseRef.current.promise,
|
||||||
onChange: (
|
onChange: (
|
||||||
elements: NonDeletedExcalidrawElement[],
|
elements: NonDeletedExcalidrawElement[],
|
||||||
@@ -224,10 +208,6 @@ 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 && (
|
||||||
@@ -684,229 +664,6 @@ 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,28 +2,6 @@ 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,
|
||||||
@@ -44,14 +22,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,
|
||||||
@@ -60,11 +38,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,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
pointFrom,
|
||||||
pointFromPair,
|
pointFromPair,
|
||||||
type GlobalPoint,
|
type GlobalPoint,
|
||||||
type LocalPoint,
|
type LocalPoint,
|
||||||
@@ -69,12 +70,12 @@ export const getGridPoint = (
|
|||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
gridSize: NullableGridSize,
|
gridSize: NullableGridSize,
|
||||||
): [number, number] => {
|
): GlobalPoint => {
|
||||||
if (gridSize) {
|
if (gridSize) {
|
||||||
return [
|
return pointFrom<GlobalPoint>(
|
||||||
Math.round(x / gridSize) * gridSize,
|
Math.round(x / gridSize) * gridSize,
|
||||||
Math.round(y / gridSize) * gridSize,
|
Math.round(y / gridSize) * gridSize,
|
||||||
];
|
);
|
||||||
}
|
}
|
||||||
return [x, y];
|
return pointFrom<GlobalPoint>(x, y);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
arrayToMap,
|
arrayToMap,
|
||||||
getFeatureFlag,
|
getFeatureFlag,
|
||||||
|
getGridPoint,
|
||||||
invariant,
|
invariant,
|
||||||
isTransparent,
|
isTransparent,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
@@ -22,7 +23,7 @@ import {
|
|||||||
} from "@excalidraw/math";
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
import type { LineSegment, LocalPoint, Radians } from "@excalidraw/math";
|
import type { LineSegment, LocalPoint, Radians } from "@excalidraw/math";
|
||||||
import type { AppState } from "@excalidraw/excalidraw/types";
|
import type { AppState, NullableGridSize } from "@excalidraw/excalidraw/types";
|
||||||
import type { MapEntry, Mutable } from "@excalidraw/common/utility-types";
|
import type { MapEntry, Mutable } from "@excalidraw/common/utility-types";
|
||||||
import type { Bounds } from "@excalidraw/common";
|
import type { Bounds } from "@excalidraw/common";
|
||||||
|
|
||||||
@@ -154,6 +155,7 @@ export const bindOrUnbindBindingElement = (
|
|||||||
altKey?: boolean;
|
altKey?: boolean;
|
||||||
angleLocked?: boolean;
|
angleLocked?: boolean;
|
||||||
initialBinding?: boolean;
|
initialBinding?: boolean;
|
||||||
|
gridSize?: NullableGridSize;
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
const { start, end } = getBindingStrategyForDraggingBindingElementEndpoints(
|
const { start, end } = getBindingStrategyForDraggingBindingElementEndpoints(
|
||||||
@@ -170,12 +172,16 @@ export const bindOrUnbindBindingElement = (
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const isMidpointSnappingEnabled =
|
||||||
|
appState.isMidpointSnappingEnabled && !appState.gridModeEnabled;
|
||||||
|
|
||||||
bindOrUnbindBindingElementEdge(
|
bindOrUnbindBindingElementEdge(
|
||||||
arrow,
|
arrow,
|
||||||
start,
|
start,
|
||||||
"start",
|
"start",
|
||||||
scene,
|
scene,
|
||||||
appState.isBindingEnabled,
|
appState.isBindingEnabled,
|
||||||
|
isMidpointSnappingEnabled,
|
||||||
);
|
);
|
||||||
bindOrUnbindBindingElementEdge(
|
bindOrUnbindBindingElementEdge(
|
||||||
arrow,
|
arrow,
|
||||||
@@ -183,6 +189,7 @@ export const bindOrUnbindBindingElement = (
|
|||||||
"end",
|
"end",
|
||||||
scene,
|
scene,
|
||||||
appState.isBindingEnabled,
|
appState.isBindingEnabled,
|
||||||
|
isMidpointSnappingEnabled,
|
||||||
);
|
);
|
||||||
if (start.focusPoint || end.focusPoint) {
|
if (start.focusPoint || end.focusPoint) {
|
||||||
// If the strategy dictates a focus point override, then
|
// If the strategy dictates a focus point override, then
|
||||||
@@ -227,6 +234,7 @@ const bindOrUnbindBindingElementEdge = (
|
|||||||
startOrEnd: "start" | "end",
|
startOrEnd: "start" | "end",
|
||||||
scene: Scene,
|
scene: Scene,
|
||||||
shouldSnapToOutline = true,
|
shouldSnapToOutline = true,
|
||||||
|
isMidpointSnappingEnabled = true,
|
||||||
): void => {
|
): void => {
|
||||||
if (mode === null) {
|
if (mode === null) {
|
||||||
// null means break the binding
|
// null means break the binding
|
||||||
@@ -240,6 +248,7 @@ const bindOrUnbindBindingElementEdge = (
|
|||||||
scene,
|
scene,
|
||||||
focusPoint,
|
focusPoint,
|
||||||
shouldSnapToOutline,
|
shouldSnapToOutline,
|
||||||
|
isMidpointSnappingEnabled,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -593,6 +602,7 @@ export const getBindingStrategyForDraggingBindingElementEndpoints = (
|
|||||||
finalize?: boolean;
|
finalize?: boolean;
|
||||||
initialBinding?: boolean;
|
initialBinding?: boolean;
|
||||||
zoom?: AppState["zoom"];
|
zoom?: AppState["zoom"];
|
||||||
|
gridSize?: NullableGridSize;
|
||||||
},
|
},
|
||||||
): { start: BindingStrategy; end: BindingStrategy } => {
|
): { start: BindingStrategy; end: BindingStrategy } => {
|
||||||
if (getFeatureFlag("COMPLEX_BINDINGS")) {
|
if (getFeatureFlag("COMPLEX_BINDINGS")) {
|
||||||
@@ -633,6 +643,7 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
|||||||
finalize?: boolean;
|
finalize?: boolean;
|
||||||
initialBinding?: boolean;
|
initialBinding?: boolean;
|
||||||
zoom?: AppState["zoom"];
|
zoom?: AppState["zoom"];
|
||||||
|
gridSize?: NullableGridSize;
|
||||||
},
|
},
|
||||||
): { start: BindingStrategy; end: BindingStrategy } => {
|
): { start: BindingStrategy; end: BindingStrategy } => {
|
||||||
const startIdx = 0;
|
const startIdx = 0;
|
||||||
@@ -695,7 +706,9 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
|||||||
elementsMap,
|
elementsMap,
|
||||||
);
|
);
|
||||||
const hit = getHoveredElementForBinding(
|
const hit = getHoveredElementForBinding(
|
||||||
globalPoint,
|
opts?.angleLocked || appState.gridModeEnabled
|
||||||
|
? pointFrom<GlobalPoint>(scenePointerX, scenePointerY)
|
||||||
|
: globalPoint,
|
||||||
elements,
|
elements,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
maxBindingDistance_simple(appState.zoom),
|
maxBindingDistance_simple(appState.zoom),
|
||||||
@@ -747,7 +760,11 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
|||||||
? globalPoint
|
? globalPoint
|
||||||
: // NOTE: Can only affect the start point because new arrows always drag the end point
|
: // NOTE: Can only affect the start point because new arrows always drag the end point
|
||||||
opts?.newArrow
|
opts?.newArrow
|
||||||
? appState.selectedLinearElement!.initialState.origin!
|
? getGridPoint(
|
||||||
|
appState.selectedLinearElement!.initialState.origin![0],
|
||||||
|
appState.selectedLinearElement!.initialState.origin![1],
|
||||||
|
opts.gridSize as NullableGridSize,
|
||||||
|
)
|
||||||
: LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
: LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
arrow,
|
arrow,
|
||||||
0,
|
0,
|
||||||
@@ -806,12 +823,27 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
|||||||
focusPoint:
|
focusPoint:
|
||||||
projectFixedPointOntoDiagonal(
|
projectFixedPointOntoDiagonal(
|
||||||
arrow,
|
arrow,
|
||||||
globalPoint,
|
opts?.angleLocked || appState.gridModeEnabled
|
||||||
|
? snapBoundPointToGrid(
|
||||||
|
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
||||||
|
hit,
|
||||||
|
elementsMap,
|
||||||
|
appState.gridSize as NullableGridSize,
|
||||||
|
arrow,
|
||||||
|
LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
|
arrow,
|
||||||
|
startDragged ? 1 : -2,
|
||||||
|
elementsMap,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: globalPoint,
|
||||||
hit,
|
hit,
|
||||||
startDragged ? "start" : "end",
|
startDragged ? "start" : "end",
|
||||||
elementsMap,
|
elementsMap,
|
||||||
appState.zoom,
|
appState.zoom,
|
||||||
appState.isMidpointSnappingEnabled,
|
appState.isMidpointSnappingEnabled &&
|
||||||
|
!opts?.angleLocked &&
|
||||||
|
!appState.gridModeEnabled,
|
||||||
) || globalPoint,
|
) || globalPoint,
|
||||||
}
|
}
|
||||||
: { mode: null };
|
: { mode: null };
|
||||||
@@ -856,7 +888,7 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
|
|||||||
startDragged ? "end" : "start",
|
startDragged ? "end" : "start",
|
||||||
elementsMap,
|
elementsMap,
|
||||||
appState.zoom,
|
appState.zoom,
|
||||||
appState.isMidpointSnappingEnabled,
|
false,
|
||||||
) || otherEndpoint,
|
) || otherEndpoint,
|
||||||
}
|
}
|
||||||
: { mode: undefined }
|
: { mode: undefined }
|
||||||
@@ -1021,6 +1053,7 @@ export const bindBindingElement = (
|
|||||||
scene: Scene,
|
scene: Scene,
|
||||||
focusPoint?: GlobalPoint,
|
focusPoint?: GlobalPoint,
|
||||||
shouldSnapToOutline = true,
|
shouldSnapToOutline = true,
|
||||||
|
isMidpointSnappingEnabled = true,
|
||||||
): void => {
|
): void => {
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
|
|
||||||
@@ -1036,6 +1069,7 @@ export const bindBindingElement = (
|
|||||||
startOrEnd,
|
startOrEnd,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
shouldSnapToOutline,
|
shouldSnapToOutline,
|
||||||
|
isMidpointSnappingEnabled,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@@ -1740,6 +1774,92 @@ const extractBinding = (
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Snaps a bound arrow endpoint to the grid on the axis parallel to the
|
||||||
|
* bindable element's side, while preserving the binding gap distance on the
|
||||||
|
* perpendicular axis. In other words, the grid axis closest to the side's
|
||||||
|
* perpendicular (normal) is used as the snap axis and the other axis is kept at
|
||||||
|
* the binding gap distance.
|
||||||
|
*/
|
||||||
|
const snapBoundPointToGrid = (
|
||||||
|
outlinePoint: GlobalPoint,
|
||||||
|
bindableElement: ExcalidrawBindableElement,
|
||||||
|
elementsMap: ElementsMap,
|
||||||
|
gridSize: NullableGridSize,
|
||||||
|
arrowElement: ExcalidrawArrowElement,
|
||||||
|
adjacentPoint?: GlobalPoint,
|
||||||
|
): GlobalPoint => {
|
||||||
|
if (!gridSize) {
|
||||||
|
return outlinePoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
const aabb = aabbForElement(bindableElement, elementsMap);
|
||||||
|
// For ellipses and diamonds use the arrow's incoming direction instead of
|
||||||
|
// the position-based heading, which can give the wrong axis when the
|
||||||
|
// outline point is near a cardinal zone or an angled diamond face.
|
||||||
|
const heading =
|
||||||
|
adjacentPoint &&
|
||||||
|
(bindableElement.type === "ellipse" || bindableElement.type === "diamond")
|
||||||
|
? vectorToHeading(vectorFromPoint(adjacentPoint, outlinePoint))
|
||||||
|
: headingForPointFromElement(bindableElement, aabb, outlinePoint);
|
||||||
|
|
||||||
|
const normalLocal = pointFrom<GlobalPoint>(heading[0], heading[1]);
|
||||||
|
const normalGlobal = pointRotateRads(
|
||||||
|
normalLocal,
|
||||||
|
pointFrom<GlobalPoint>(0, 0),
|
||||||
|
bindableElement.angle,
|
||||||
|
);
|
||||||
|
|
||||||
|
const bindingGap = getBindingGap(bindableElement, arrowElement);
|
||||||
|
const extent =
|
||||||
|
Math.max(bindableElement.width, bindableElement.height) + bindingGap * 2;
|
||||||
|
const center = getCenterForBounds(aabb);
|
||||||
|
|
||||||
|
const absNX = Math.abs(normalGlobal[0]);
|
||||||
|
const absNY = Math.abs(normalGlobal[1]);
|
||||||
|
if (absNX >= absNY) {
|
||||||
|
// Global X is closest to the perpendicular so snap Y, intersect horizontal line
|
||||||
|
const [, snappedY] = getGridPoint(
|
||||||
|
outlinePoint[0],
|
||||||
|
outlinePoint[1],
|
||||||
|
gridSize,
|
||||||
|
);
|
||||||
|
const intersector = lineSegment<GlobalPoint>(
|
||||||
|
pointFrom<GlobalPoint>(center[0] - extent, snappedY),
|
||||||
|
pointFrom<GlobalPoint>(center[0] + extent, snappedY),
|
||||||
|
);
|
||||||
|
const intersection = intersectElementWithLineSegment(
|
||||||
|
bindableElement,
|
||||||
|
elementsMap,
|
||||||
|
intersector,
|
||||||
|
bindingGap,
|
||||||
|
).sort(
|
||||||
|
(a, b) =>
|
||||||
|
pointDistanceSq(a, outlinePoint) - pointDistanceSq(b, outlinePoint),
|
||||||
|
)[0];
|
||||||
|
|
||||||
|
return intersection ?? pointFrom<GlobalPoint>(outlinePoint[0], snappedY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Global Y is closest to the perpendicular so snap X, intersect vertical line
|
||||||
|
const [snappedX] = getGridPoint(outlinePoint[0], outlinePoint[1], gridSize);
|
||||||
|
const intersector = lineSegment<GlobalPoint>(
|
||||||
|
pointFrom<GlobalPoint>(snappedX, center[1] - extent),
|
||||||
|
pointFrom<GlobalPoint>(snappedX, center[1] + extent),
|
||||||
|
);
|
||||||
|
const intersection = intersectElementWithLineSegment(
|
||||||
|
bindableElement,
|
||||||
|
elementsMap,
|
||||||
|
intersector,
|
||||||
|
bindingGap,
|
||||||
|
).sort(
|
||||||
|
(a, b) =>
|
||||||
|
pointDistanceSq(a, outlinePoint) - pointDistanceSq(b, outlinePoint),
|
||||||
|
)[0];
|
||||||
|
|
||||||
|
return intersection ?? pointFrom<GlobalPoint>(snappedX, outlinePoint[1]);
|
||||||
|
};
|
||||||
|
|
||||||
const elementArea = (element: ExcalidrawBindableElement) =>
|
const elementArea = (element: ExcalidrawBindableElement) =>
|
||||||
element.width * element.height;
|
element.width * element.height;
|
||||||
|
|
||||||
|
|||||||
@@ -359,6 +359,7 @@ export class LinearElementEditor {
|
|||||||
linearElementEditor,
|
linearElementEditor,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const angleLocked = shouldRotateWithDiscreteAngle(event);
|
||||||
LinearElementEditor.movePoints(
|
LinearElementEditor.movePoints(
|
||||||
element,
|
element,
|
||||||
app.scene,
|
app.scene,
|
||||||
@@ -370,7 +371,10 @@ export class LinearElementEditor {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
isBindingEnabled: app.state.isBindingEnabled,
|
isBindingEnabled: app.state.isBindingEnabled,
|
||||||
isMidpointSnappingEnabled: app.state.isMidpointSnappingEnabled,
|
isMidpointSnappingEnabled:
|
||||||
|
app.state.isMidpointSnappingEnabled &&
|
||||||
|
!angleLocked &&
|
||||||
|
!app.state.gridModeEnabled,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
// Set the suggested binding from the updates if available
|
// Set the suggested binding from the updates if available
|
||||||
@@ -427,7 +431,9 @@ export class LinearElementEditor {
|
|||||||
"start",
|
"start",
|
||||||
elementsMap,
|
elementsMap,
|
||||||
app.state.zoom,
|
app.state.zoom,
|
||||||
app.state.isMidpointSnappingEnabled,
|
app.state.isMidpointSnappingEnabled &&
|
||||||
|
!angleLocked &&
|
||||||
|
!app.state.gridModeEnabled,
|
||||||
)
|
)
|
||||||
: linearElementEditor.initialState.altFocusPoint,
|
: linearElementEditor.initialState.altFocusPoint,
|
||||||
},
|
},
|
||||||
@@ -554,6 +560,8 @@ export class LinearElementEditor {
|
|||||||
linearElementEditor,
|
linearElementEditor,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const angleLocked =
|
||||||
|
shouldRotateWithDiscreteAngle(event) && singlePointDragged;
|
||||||
LinearElementEditor.movePoints(
|
LinearElementEditor.movePoints(
|
||||||
element,
|
element,
|
||||||
app.scene,
|
app.scene,
|
||||||
@@ -565,7 +573,10 @@ export class LinearElementEditor {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
isBindingEnabled: app.state.isBindingEnabled,
|
isBindingEnabled: app.state.isBindingEnabled,
|
||||||
isMidpointSnappingEnabled: app.state.isMidpointSnappingEnabled,
|
isMidpointSnappingEnabled:
|
||||||
|
app.state.isMidpointSnappingEnabled &&
|
||||||
|
!angleLocked &&
|
||||||
|
!app.state.gridModeEnabled,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -661,7 +672,9 @@ export class LinearElementEditor {
|
|||||||
"start",
|
"start",
|
||||||
elementsMap,
|
elementsMap,
|
||||||
app.state.zoom,
|
app.state.zoom,
|
||||||
app.state.isMidpointSnappingEnabled,
|
app.state.isMidpointSnappingEnabled &&
|
||||||
|
!angleLocked &&
|
||||||
|
!app.state.gridModeEnabled,
|
||||||
)
|
)
|
||||||
: linearElementEditor.initialState.altFocusPoint,
|
: linearElementEditor.initialState.altFocusPoint,
|
||||||
},
|
},
|
||||||
@@ -2176,6 +2189,7 @@ const pointDraggingUpdates = (
|
|||||||
newArrow: !!app.state.newElement,
|
newArrow: !!app.state.newElement,
|
||||||
angleLocked,
|
angleLocked,
|
||||||
altKey,
|
altKey,
|
||||||
|
gridSize: app.getEffectiveGridSize(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import rough from "roughjs/bin/rough";
|
import rough from "roughjs/bin/rough";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
clamp,
|
|
||||||
type GlobalPoint,
|
type GlobalPoint,
|
||||||
isRightAngleRads,
|
isRightAngleRads,
|
||||||
lineSegment,
|
lineSegment,
|
||||||
@@ -106,62 +105,8 @@ 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,
|
||||||
@@ -170,8 +115,7 @@ 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) * resolveRenderOpacity(element, renderConfig)) /
|
(((containingFrame?.opacity ?? 100) * element.opacity) / 10000) *
|
||||||
10000) *
|
|
||||||
globalAlpha;
|
globalAlpha;
|
||||||
|
|
||||||
// if pending erasure, multiply again to combine further
|
// if pending erasure, multiply again to combine further
|
||||||
@@ -847,11 +791,8 @@ 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,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import { isInvisiblySmallElement } from "@excalidraw/element";
|
|||||||
|
|
||||||
import { CaptureUpdateAction } from "@excalidraw/element";
|
import { CaptureUpdateAction } from "@excalidraw/element";
|
||||||
|
|
||||||
import type { GlobalPoint, LocalPoint } from "@excalidraw/math";
|
import type { LocalPoint } from "@excalidraw/math";
|
||||||
import type {
|
import type {
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
ExcalidrawLinearElement,
|
ExcalidrawLinearElement,
|
||||||
@@ -93,32 +93,40 @@ export const actionFinalize = register<FormData>({
|
|||||||
? [element.points.length - 1] // New arrow creation
|
? [element.points.length - 1] // New arrow creation
|
||||||
: appState.selectedLinearElement.selectedPointsIndices;
|
: appState.selectedLinearElement.selectedPointsIndices;
|
||||||
|
|
||||||
|
const angleLocked = shouldRotateWithDiscreteAngle(event);
|
||||||
|
const effectiveGridSize = event[KEYS.CTRL_OR_CMD]
|
||||||
|
? null
|
||||||
|
: app.getEffectiveGridSize();
|
||||||
|
|
||||||
const draggedPoints: PointsPositionUpdates =
|
const draggedPoints: PointsPositionUpdates =
|
||||||
selectedPointsIndices.reduce((map, index) => {
|
selectedPointsIndices.reduce((map, index) => {
|
||||||
map.set(index, {
|
map.set(index, {
|
||||||
point: LinearElementEditor.pointFromAbsoluteCoords(
|
point: angleLocked
|
||||||
element,
|
? element.points[index]
|
||||||
pointFrom<GlobalPoint>(
|
: LinearElementEditor.createPointAt(
|
||||||
sceneCoords.x - linearElementEditor.pointerOffset.x,
|
element,
|
||||||
sceneCoords.y - linearElementEditor.pointerOffset.y,
|
elementsMap,
|
||||||
),
|
sceneCoords.x - linearElementEditor.pointerOffset.x,
|
||||||
elementsMap,
|
sceneCoords.y - linearElementEditor.pointerOffset.y,
|
||||||
),
|
effectiveGridSize,
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}, new Map()) ?? new Map();
|
}, new Map()) ?? new Map();
|
||||||
|
|
||||||
bindOrUnbindBindingElement(
|
bindOrUnbindBindingElement(
|
||||||
element,
|
element,
|
||||||
draggedPoints,
|
draggedPoints,
|
||||||
sceneCoords.x - linearElementEditor.pointerOffset.x,
|
sceneCoords.x,
|
||||||
sceneCoords.y - linearElementEditor.pointerOffset.y,
|
sceneCoords.y,
|
||||||
scene,
|
scene,
|
||||||
appState,
|
appState,
|
||||||
{
|
{
|
||||||
newArrow,
|
newArrow,
|
||||||
altKey: event.altKey,
|
altKey: event.altKey,
|
||||||
angleLocked: shouldRotateWithDiscreteAngle(event),
|
angleLocked,
|
||||||
|
gridSize: app.getEffectiveGridSize(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else if (isLineElement(element)) {
|
} else if (isLineElement(element)) {
|
||||||
|
|||||||
@@ -207,12 +207,10 @@ import {
|
|||||||
getLineHeightInPx,
|
getLineHeightInPx,
|
||||||
getApproxMinLineWidth,
|
getApproxMinLineWidth,
|
||||||
getApproxMinLineHeight,
|
getApproxMinLineHeight,
|
||||||
getMinTextElementWidth,
|
getMinTextElementWidth,
|
||||||
ShapeCache,
|
ShapeCache,
|
||||||
getRenderOpacity,
|
getRenderOpacity,
|
||||||
resolveRenderPositionOffset,
|
editGroupForSelectedElement,
|
||||||
resolveRenderOpacity,
|
|
||||||
editGroupForSelectedElement,
|
|
||||||
getElementsInGroup,
|
getElementsInGroup,
|
||||||
getSelectedGroupIdForElement,
|
getSelectedGroupIdForElement,
|
||||||
getSelectedGroupIds,
|
getSelectedGroupIds,
|
||||||
@@ -452,7 +450,6 @@ 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";
|
||||||
@@ -743,235 +740,6 @@ 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 = {
|
||||||
@@ -989,9 +757,6 @@ 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,
|
||||||
@@ -1969,10 +1734,6 @@ 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
|
||||||
@@ -1994,14 +1755,13 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
})}
|
})}
|
||||||
style={{
|
style={{
|
||||||
transform: isVisible
|
transform: isVisible
|
||||||
? `translate(${x + renderPositionOffset.x * this.state.zoom.value - this.state.offsetLeft}px, ${
|
? `translate(${x - this.state.offsetLeft}px, ${
|
||||||
y + renderPositionOffset.y * this.state.zoom.value - this.state.offsetTop
|
y - 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,
|
||||||
@@ -2591,9 +2351,6 @@ 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 && (
|
||||||
@@ -2616,9 +2373,6 @@ 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,
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -3452,7 +3206,6 @@ 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(() => {});
|
||||||
|
|
||||||
@@ -4865,98 +4618,6 @@ 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,
|
||||||
@@ -7602,14 +7263,16 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.state.activeTool.type === "arrow") {
|
// Set suggested binding if we're hovering with an arrow tool
|
||||||
|
// and not dragging out a new element
|
||||||
|
if (this.state.activeTool.type === "arrow" && !this.state.newElement) {
|
||||||
|
const scenePointer = pointFrom<GlobalPoint>(scenePointerX, scenePointerY);
|
||||||
const hit = getHoveredElementForBinding(
|
const hit = getHoveredElementForBinding(
|
||||||
pointFrom<GlobalPoint>(scenePointerX, scenePointerY),
|
scenePointer,
|
||||||
this.scene.getNonDeletedElements(),
|
this.scene.getNonDeletedElements(),
|
||||||
this.scene.getNonDeletedElementsMap(),
|
this.scene.getNonDeletedElementsMap(),
|
||||||
maxBindingDistance_simple(this.state.zoom),
|
maxBindingDistance_simple(this.state.zoom),
|
||||||
);
|
);
|
||||||
const scenePointer = pointFrom<GlobalPoint>(scenePointerX, scenePointerY);
|
|
||||||
const elementsMap = this.scene.getNonDeletedElementsMap();
|
const elementsMap = this.scene.getNonDeletedElementsMap();
|
||||||
if (hit && !isPointInElement(scenePointer, hit, elementsMap)) {
|
if (hit && !isPointInElement(scenePointer, hit, elementsMap)) {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|||||||
@@ -253,6 +253,7 @@ const getRelevantAppStateProps = (
|
|||||||
newElement: appState.newElement,
|
newElement: appState.newElement,
|
||||||
isBindingEnabled: appState.isBindingEnabled,
|
isBindingEnabled: appState.isBindingEnabled,
|
||||||
isMidpointSnappingEnabled: appState.isMidpointSnappingEnabled,
|
isMidpointSnappingEnabled: appState.isMidpointSnappingEnabled,
|
||||||
|
gridModeEnabled: appState.gridModeEnabled,
|
||||||
suggestedBinding: appState.suggestedBinding,
|
suggestedBinding: appState.suggestedBinding,
|
||||||
isRotating: appState.isRotating,
|
isRotating: appState.isRotating,
|
||||||
elementsToHighlight: appState.elementsToHighlight,
|
elementsToHighlight: appState.elementsToHighlight,
|
||||||
|
|||||||
@@ -99,7 +99,6 @@ const ExcalidrawBase = (props: ExcalidrawProps) => {
|
|||||||
children,
|
children,
|
||||||
validateEmbeddable,
|
validateEmbeddable,
|
||||||
renderEmbeddable,
|
renderEmbeddable,
|
||||||
resolveRenderOpacity,
|
|
||||||
aiEnabled,
|
aiEnabled,
|
||||||
showDeprecatedFonts,
|
showDeprecatedFonts,
|
||||||
renderScrollbars,
|
renderScrollbars,
|
||||||
@@ -218,7 +217,6 @@ 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}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
FRAME_STYLE,
|
FRAME_STYLE,
|
||||||
getFeatureFlag,
|
getFeatureFlag,
|
||||||
invariant,
|
invariant,
|
||||||
|
shouldRotateWithDiscreteAngle,
|
||||||
THEME,
|
THEME,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
@@ -229,6 +230,7 @@ const renderBindingHighlightForBindableElement_simple = (
|
|||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
appState: InteractiveCanvasAppState,
|
appState: InteractiveCanvasAppState,
|
||||||
pointerCoords: GlobalPoint | null,
|
pointerCoords: GlobalPoint | null,
|
||||||
|
angleLocked = false,
|
||||||
) => {
|
) => {
|
||||||
const enclosingFrame =
|
const enclosingFrame =
|
||||||
suggestedBinding.element.frameId &&
|
suggestedBinding.element.frameId &&
|
||||||
@@ -415,6 +417,8 @@ const renderBindingHighlightForBindableElement_simple = (
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
appState.isMidpointSnappingEnabled &&
|
appState.isMidpointSnappingEnabled &&
|
||||||
|
!appState.gridModeEnabled &&
|
||||||
|
!angleLocked &&
|
||||||
(isFrameLikeElement(suggestedBinding.element) ||
|
(isFrameLikeElement(suggestedBinding.element) ||
|
||||||
isBindableElement(suggestedBinding.element))
|
isBindableElement(suggestedBinding.element))
|
||||||
) {
|
) {
|
||||||
@@ -807,7 +811,12 @@ const renderBindingHighlightForBindableElement_complex = (
|
|||||||
|
|
||||||
context.restore();
|
context.restore();
|
||||||
|
|
||||||
if (appState.isMidpointSnappingEnabled) {
|
if (
|
||||||
|
appState.isMidpointSnappingEnabled &&
|
||||||
|
!appState.gridModeEnabled &&
|
||||||
|
(!app.lastPointerMoveEvent ||
|
||||||
|
!shouldRotateWithDiscreteAngle(app.lastPointerMoveEvent))
|
||||||
|
) {
|
||||||
// Draw midpoint indicators
|
// Draw midpoint indicators
|
||||||
context.save();
|
context.save();
|
||||||
context.translate(
|
context.translate(
|
||||||
@@ -920,12 +929,16 @@ const renderBindingHighlightForBindableElement = (
|
|||||||
app.lastPointerMoveCoords.y,
|
app.lastPointerMoveCoords.y,
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
|
const angleLocked =
|
||||||
|
!!app.lastPointerMoveEvent &&
|
||||||
|
shouldRotateWithDiscreteAngle(app.lastPointerMoveEvent);
|
||||||
renderBindingHighlightForBindableElement_simple(
|
renderBindingHighlightForBindableElement_simple(
|
||||||
context,
|
context,
|
||||||
suggestedBinding,
|
suggestedBinding,
|
||||||
allElementsMap,
|
allElementsMap,
|
||||||
appState,
|
appState,
|
||||||
pointerCoords,
|
pointerCoords,
|
||||||
|
angleLocked,
|
||||||
);
|
);
|
||||||
context.restore();
|
context.restore();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,16 +14,11 @@ import {
|
|||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
import {
|
import {
|
||||||
elementOverlapsWithFrame,
|
elementOverlapsWithFrame,
|
||||||
getContainingFrame,
|
|
||||||
getTargetFrame,
|
getTargetFrame,
|
||||||
shouldApplyFrameClip,
|
shouldApplyFrameClip,
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
import {
|
import { renderElement } from "@excalidraw/element";
|
||||||
getRenderElementWithPositionOverride,
|
|
||||||
getRenderOpacity,
|
|
||||||
renderElement,
|
|
||||||
} from "@excalidraw/element";
|
|
||||||
|
|
||||||
import { getElementAbsoluteCoords } from "@excalidraw/element";
|
import { getElementAbsoluteCoords } from "@excalidraw/element";
|
||||||
|
|
||||||
@@ -175,10 +170,7 @@ 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(
|
||||||
@@ -229,13 +221,7 @@ const renderLinkIcon = (
|
|||||||
|
|
||||||
linkCanvasCacheContext.restore();
|
linkCanvasCacheContext.restore();
|
||||||
}
|
}
|
||||||
context.globalAlpha = getRenderOpacity(
|
context.globalAlpha = element.opacity / 100;
|
||||||
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();
|
||||||
}
|
}
|
||||||
@@ -384,7 +370,7 @@ const _renderStaticScene = ({
|
|||||||
context.restore();
|
context.restore();
|
||||||
|
|
||||||
if (!isExporting) {
|
if (!isExporting) {
|
||||||
renderLinkIcon(element, context, appState, elementsMap, renderConfig);
|
renderLinkIcon(element, context, appState, elementsMap);
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(
|
console.error(
|
||||||
@@ -435,7 +421,7 @@ const _renderStaticScene = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!isExporting) {
|
if (!isExporting) {
|
||||||
renderLinkIcon(element, context, appState, elementsMap, renderConfig);
|
renderLinkIcon(element, context, appState, elementsMap);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// - when exporting the whole canvas, we DO NOT apply clipping
|
// - when exporting the whole canvas, we DO NOT apply clipping
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import type {
|
|||||||
AppClassProperties,
|
AppClassProperties,
|
||||||
AppState,
|
AppState,
|
||||||
EmbedsValidationStatus,
|
EmbedsValidationStatus,
|
||||||
RenderOpacityResolver,
|
|
||||||
ElementsPendingErasure,
|
ElementsPendingErasure,
|
||||||
InteractiveCanvasAppState,
|
InteractiveCanvasAppState,
|
||||||
StaticCanvasAppState,
|
StaticCanvasAppState,
|
||||||
@@ -38,13 +37,6 @@ 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 = {
|
||||||
|
|||||||
@@ -224,6 +224,7 @@ export type InteractiveCanvasAppState = Readonly<
|
|||||||
newElement: AppState["newElement"];
|
newElement: AppState["newElement"];
|
||||||
isBindingEnabled: AppState["isBindingEnabled"];
|
isBindingEnabled: AppState["isBindingEnabled"];
|
||||||
isMidpointSnappingEnabled: AppState["isMidpointSnappingEnabled"];
|
isMidpointSnappingEnabled: AppState["isMidpointSnappingEnabled"];
|
||||||
|
gridModeEnabled: AppState["gridModeEnabled"];
|
||||||
suggestedBinding: AppState["suggestedBinding"];
|
suggestedBinding: AppState["suggestedBinding"];
|
||||||
isRotating: AppState["isRotating"];
|
isRotating: AppState["isRotating"];
|
||||||
elementsToHighlight: AppState["elementsToHighlight"];
|
elementsToHighlight: AppState["elementsToHighlight"];
|
||||||
@@ -567,10 +568,6 @@ 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[],
|
||||||
@@ -686,7 +683,6 @@ 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;
|
||||||
@@ -850,6 +846,7 @@ export type AppClassProperties = {
|
|||||||
onStateChange: App["onStateChange"];
|
onStateChange: App["onStateChange"];
|
||||||
|
|
||||||
lastPointerMoveCoords: App["lastPointerMoveCoords"];
|
lastPointerMoveCoords: App["lastPointerMoveCoords"];
|
||||||
|
lastPointerMoveEvent: App["lastPointerMoveEvent"];
|
||||||
bindModeHandler: App["bindModeHandler"];
|
bindModeHandler: App["bindModeHandler"];
|
||||||
|
|
||||||
setAppState: App["setAppState"];
|
setAppState: App["setAppState"];
|
||||||
@@ -967,11 +964,6 @@ 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